first commit

This commit is contained in:
Blizzard
2026-02-27 13:54:01 +08:00
commit fc585fa4df
127 changed files with 18548 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package uniqueid
import (
"fmt"
"time"
)
func GenOrderNo() string {
/*
支付宝订单号示例:1217752501201407033233368028
分析可能格式:
- 前14位:时间戳(年月日时分秒)20250112 151420
- 中间6位:商户/业务标识
- 最后8位:随机数或序列号
*/
now := time.Now()
// 时间部分:年月日时分秒
timePart := now.Format("20060102150405") // 14位
// 业务标识:机器ID + 进程ID + 随机数
machineID := 1
pid := now.Nanosecond() % 1000
businessPart := fmt.Sprintf("%02d%03d%01d", machineID, pid, now.Second()%10) // 6位
// 随机部分:纳秒取模
random1 := fmt.Sprintf("%04d", now.Nanosecond()%10000)
random2 := fmt.Sprintf("%04d", (now.Nanosecond()/10000)%10000)
return timePart + businessPart + random1 + random2
}