diff --git a/server/inventory/internal/logic/takelogic.go b/server/inventory/internal/logic/takelogic.go index 799486e5..2abbceee 100644 --- a/server/inventory/internal/logic/takelogic.go +++ b/server/inventory/internal/logic/takelogic.go @@ -10,7 +10,7 @@ import ( "fusenapi/server/inventory/internal/types" "fusenapi/utils/auth" "fusenapi/utils/basic" - "fusenapi/utils/snow_id_generator" + "fusenapi/utils/id_generator" "gorm.io/gorm" "time" @@ -58,11 +58,7 @@ func (l *TakeLogic) Take(req *types.TakeReq, userinfo *auth.UserInfo) (resp *bas //提货单总单 addressInfoBytes, _ := json.Marshal(addressInfo) addressInfoJson := string(addressInfoBytes) - trackNum, err := snow_id_generator.GenSnowId() - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to gen trackNum") - } + trackNum := id_generator.GenPickUpTrackNum() status := int64(constants.STATUS_ORDERD) now := time.Now().Unix() pickUpData := gmodel.FsCloudPickUp{ @@ -73,7 +69,6 @@ func (l *TakeLogic) Take(req *types.TakeReq, userinfo *auth.UserInfo) (resp *bas Status: &status, Ctime: &now, } - //开启事务 //箱数验证 boxes := int64(0) //需要更新的库存信息 @@ -121,6 +116,9 @@ func (l *TakeLogic) Take(req *types.TakeReq, userinfo *auth.UserInfo) (resp *bas Ctime: &now, }) } + if boxes < 3 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "Take out more than three boxes") + } //事务处理数据 err = l.svcCtx.AllModels.FsCloudPickUp.SavePickUpWithTransaction(l.ctx, &pickUpData, stockUpdateList, pickUpDetailAddList) if err != nil { diff --git a/utils/id_generator/pickup_track_num.go b/utils/id_generator/pickup_track_num.go new file mode 100644 index 00000000..0e7d3037 --- /dev/null +++ b/utils/id_generator/pickup_track_num.go @@ -0,0 +1,13 @@ +package id_generator + +import ( + "fmt" + "math/rand" + "strings" + "time" +) + +func GenPickUpTrackNum() string { + a := fmt.Sprintf("%s%.8d", time.Now().Format("20060102150405.000"), rand.Intn(1000000)) + return strings.ReplaceAll(a, ".", "") +} diff --git a/utils/snow_id_generator/snowflake.go b/utils/snow_id_generator/snowflake.go deleted file mode 100644 index 465c9e21..00000000 --- a/utils/snow_id_generator/snowflake.go +++ /dev/null @@ -1,16 +0,0 @@ -package snow_id_generator - -import ( - "fmt" - "github.com/bwmarrin/snowflake" - "time" -) - -// 雪花算法生成id -func GenSnowId() (string, error) { - node, err := snowflake.NewNode(1) - if err != nil { - return "", err - } - return fmt.Sprintf("%s%s", time.Now().Format("20060102"), node.Generate().Base58()), nil -}