调整表结构

This commit is contained in:
2025-06-05 14:58:58 +08:00
parent fdf5152bd2
commit 77067adf33
83 changed files with 137 additions and 2662 deletions

52
utility/snowid/snowid.go Normal file
View File

@ -0,0 +1,52 @@
package snowid
import (
"context"
"fmt"
"github.com/bwmarrin/snowflake"
"github.com/gogf/gf/v2/frame/g"
"sync"
)
var (
once sync.Once
instance *snowClient
)
type snowClient struct {
node *snowflake.Node
}
func init() {
ctx := context.Background()
once.Do(func() {
instance = &snowClient{}
instance.node, _ = snowflake.NewNode(g.Config().MustGet(ctx, "snowId.workerId").Int64())
})
}
func GetSnowClient() *snowClient {
return instance
}
// GenerateMerchantCode 生成商户编号
func (c *snowClient) GenerateMerchantCode() (string, error) {
return c.generateCodeWithPrefix("M")
}
// GenerateStoreCode 生成门店编号
func (c *snowClient) GenerateStoreCode() (string, error) {
return c.generateCodeWithPrefix("S")
}
// GenerateUserCode 生成用户编号
func (c *snowClient) GenerateUserCode() (string, error) {
return c.generateCodeWithPrefix("U")
}
func (c *snowClient) generateCodeWithPrefix(prefix string) (string, error) {
if c.node == nil {
return "", fmt.Errorf("雪花节点未初始化")
}
id := c.node.Generate().Int64()
return fmt.Sprintf("%s%d", prefix, id), nil
}