下单调整分布式锁

This commit is contained in:
momo 2023-11-27 16:37:07 +08:00
parent 299031ac3f
commit 8d2867be57

View File

@ -6,7 +6,6 @@ import (
"fusenapi/service/repositories" "fusenapi/service/repositories"
"fusenapi/utils/auth" "fusenapi/utils/auth"
"fusenapi/utils/basic" "fusenapi/utils/basic"
"strconv"
"sync" "sync"
"time" "time"
@ -47,14 +46,14 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
return resp.SetStatus(basic.CodeUnAuth) return resp.SetStatus(basic.CodeUnAuth)
} }
var lockKey string // var lockKey string
for _, v := range req.CartIds { // for _, v := range req.CartIds {
var vStr = strconv.Itoa(int(v)) // var vStr = strconv.Itoa(int(v))
lockKey = lockKey + "|" + vStr // lockKey = lockKey + "|" + vStr
} // }
// 分布式锁--防止重复下单 // // 分布式锁--防止重复下单
LockWith(lockKey) //获取锁 // LockWith(lockKey) //获取锁
fmt.Println("获取到了锁") // fmt.Println("获取到了锁")
tPlus60Days := time.Now().AddDate(0, 0, 60).UTC() tPlus60Days := time.Now().AddDate(0, 0, 60).UTC()
res, err := l.svcCtx.Repositories.NewOrder.Create(l.ctx, &repositories.CreateReq{ res, err := l.svcCtx.Repositories.NewOrder.Create(l.ctx, &repositories.CreateReq{
@ -66,7 +65,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
DeliveryMethod: constants.DELIVERYMETHODDSCLOUDSTORE, DeliveryMethod: constants.DELIVERYMETHODDSCLOUDSTORE,
}) })
UnlockWith(lockKey) //释放锁 // UnlockWith(lockKey) //释放锁
if err != nil { if err != nil {
return resp.SetStatus(&res.ErrorCode) return resp.SetStatus(&res.ErrorCode)