first commit

This commit is contained in:
2025-09-21 18:27:25 +08:00
commit 02e1c4bd63
528 changed files with 55690 additions and 0 deletions

20
common/uniqueid/sn.go Normal file
View File

@@ -0,0 +1,20 @@
package uniqueid
import (
"fmt"
"time"
"hm-server/common/tool"
)
// 生成sn单号
type SnPrefix string
const (
SN_PREFIX_HOMESTAY_ORDER SnPrefix = "HSO" //民宿订单前缀 hm-server_order/homestay_order
SN_PREFIX_THIRD_PAYMENT SnPrefix = "PMT" //第三方支付流水记录前缀 hm-server_payment/third_payment
)
// 生成单号
func GenSn(snPrefix SnPrefix) string {
return fmt.Sprintf("%s%s%s", snPrefix, time.Now().Format("20060102150405"), tool.Krand(8, tool.KC_RAND_KIND_NUM))
}

View File

@@ -0,0 +1,7 @@
package uniqueid
import "testing"
func TestGenSn(t *testing.T) {
GenSn(SN_PREFIX_HOMESTAY_ORDER)
}

View File

@@ -0,0 +1,23 @@
package uniqueid
import (
"github.com/sony/sonyflake"
"github.com/zeromicro/go-zero/core/logx"
)
var flake *sonyflake.Sonyflake
func init() {
flake = sonyflake.NewSonyflake(sonyflake.Settings{})
}
func GenId() int64 {
id, err := flake.NextID()
if err != nil {
logx.Severef("flake NextID failed with %s \n", err)
panic(err)
}
return int64(id)
}