package util import ( "fmt" "strings" "time" "github.com/google/uuid" ) // NewOutTradeNo 生成全局唯一的商户订单号:-<时间>-<随机>,控制在 64 字符内。 // 例:yanmei-20260624153012-a1b2c3d4 func NewOutTradeNo(merchantCode string) string { code := merchantCode if len(code) > 16 { code = code[:16] } ts := time.Now().Format("20060102150405") suffix := strings.ReplaceAll(uuid.NewString(), "-", "")[:8] return fmt.Sprintf("%s-%s-%s", code, ts, suffix) }