29 lines
928 B
Python
29 lines
928 B
Python
from datetime import datetime
|
||
import time
|
||
|
||
class CommonUtils:
|
||
"""订单工具类"""
|
||
|
||
@staticmethod
|
||
def generate_order_id(prefix: str) -> str:
|
||
"""
|
||
生成订单号
|
||
:param prefix: 订单前缀,如 M(商品订单)、P(支付订单)、D(配送订单)
|
||
:return: 15位订单号:前缀(1位) + 日期(8位) + 时间戳(6位)
|
||
"""
|
||
now = datetime.now()
|
||
date_str = now.strftime('%Y%m%d')
|
||
# 取时间戳后6位
|
||
timestamp = str(int(time.time() * 1000))[-6:]
|
||
return f"{prefix}{date_str}{timestamp}"
|
||
|
||
@staticmethod
|
||
def generate_verify_code() -> str:
|
||
"""
|
||
生成核销码
|
||
:return: 16位数字核销码:日期(8位) + 时间戳(8位)
|
||
"""
|
||
now = datetime.now()
|
||
date_str = now.strftime('%Y%m%d')
|
||
timestamp = str(int(time.time() * 1000))[-8:]
|
||
return f"{date_str}{timestamp}" |