diff --git a/backend/internal/modules/order/repository.go b/backend/internal/modules/order/repository.go index db127a9..c674fc9 100644 --- a/backend/internal/modules/order/repository.go +++ b/backend/internal/modules/order/repository.go @@ -2,7 +2,6 @@ package order import ( "crypto/rand" - "encoding/hex" "encoding/json" "errors" "log" @@ -1586,11 +1585,22 @@ func makeAccountSnapshot(account model.GameAccount) (datatypes.JSON, error) { } func newOrderNo() (string, error) { - buf := make([]byte, 4) + // 生成格式:RO + YYYYMMDDHHMMSS + 3位随机数 + // 例如:RO20260603123456789 + now := time.Now() + + // 时间部分:年月日时分秒 (14位) + timeStr := now.Format("20060102150405") + + // 随机部分:3位数字 (000-999) + buf := make([]byte, 2) if _, err := rand.Read(buf); err != nil { return "", err } - return "RO" + strconv.FormatInt(time.Now().UnixNano(), 10) + hex.EncodeToString(buf), nil + // 将2字节转为0-999的数字 + randomNum := (int(buf[0])<<8 | int(buf[1])) % 1000 + + return "RO" + timeStr + strconv.Itoa(1000+randomNum)[1:], nil } func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error {