first commit
This commit is contained in:
20
common/uniqueid/sn.go
Normal file
20
common/uniqueid/sn.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package uniqueid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"znc-server/common/tool"
|
||||
)
|
||||
|
||||
// 生成sn单号
|
||||
type SnPrefix string
|
||||
|
||||
const (
|
||||
SN_PREFIX_HOMESTAY_ORDER SnPrefix = "HSO" //民宿订单前缀 znc-server_order/homestay_order
|
||||
SN_PREFIX_THIRD_PAYMENT SnPrefix = "PMT" //第三方支付流水记录前缀 znc-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))
|
||||
}
|
||||
7
common/uniqueid/sn_test.go
Normal file
7
common/uniqueid/sn_test.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package uniqueid
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGenSn(t *testing.T) {
|
||||
GenSn(SN_PREFIX_HOMESTAY_ORDER)
|
||||
}
|
||||
23
common/uniqueid/uniqueid.go
Normal file
23
common/uniqueid/uniqueid.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user