22 lines
704 B
Python
22 lines
704 B
Python
import time
|
|
import random
|
|
from datetime import datetime
|
|
import uuid
|
|
|
|
|
|
def generate_id() -> str:
|
|
"""Generate a time-sortable unique ID (simplified ULID-style)."""
|
|
timestamp = int(time.time() * 1000)
|
|
randomness = random.randint(0, 0xFFFFFF)
|
|
return f"{timestamp:013x}{randomness:06x}"
|
|
|
|
|
|
def generate_order_no() -> str:
|
|
"""Generate a human-readable order number with yyyymmddhhmmss format."""
|
|
# 格式化为 yyyymmddhhmmss 格式的时间戳
|
|
now = datetime.now()
|
|
timestamp = now.strftime("%Y%m%d%H%M%S")
|
|
# 使用 UUID 的部分值来生成更可靠的随机数,防止并发冲突
|
|
random_part = uuid.uuid4().hex[:8].upper()
|
|
return f"MZZC{timestamp}{random_part}"
|