deliveryman-api/app/core/utils.py
2025-02-06 22:35:19 +09:00

29 lines
928 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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}"