优化订单号生成规则
This commit is contained in:
@@ -2,7 +2,6 @@ package order
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
@@ -1586,11 +1585,22 @@ func makeAccountSnapshot(account model.GameAccount) (datatypes.JSON, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newOrderNo() (string, 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 {
|
if _, err := rand.Read(buf); err != nil {
|
||||||
return "", err
|
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 {
|
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user