From 245b12d69d518fae210a17fb29b0a80a836dc508 Mon Sep 17 00:00:00 2001 From: momo <1012651275@qq.com> Date: Mon, 27 Nov 2023 17:13:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E5=8D=95=E8=B0=83=E6=95=B4=E5=88=86?= =?UTF-8?q?=E5=B8=83=E5=BC=8F=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/internal/logic/createorderlogic.go | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index 64323b9e..0c5d0c61 100644 --- a/server/order/internal/logic/createorderlogic.go +++ b/server/order/internal/logic/createorderlogic.go @@ -46,19 +46,16 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth return resp.SetStatus(basic.CodeUnAuth) } - var lockKey string for _, v := range req.CartIds { - var vStr = strconv.Itoa(int(v)) - lockKey = lockKey + "|" + vStr - } - // 分布式锁--防止重复下单 - _, ok1 := lockMap.Load(lockKey) //获取锁 - - if ok1 { - return resp.SetStatusWithMessage(basic.CodeErrOrder, "create order failed, cannot place duplicate order") - } else { - lockMap.Store(lockKey, true) //加锁 - defer lockMap.Delete(lockKey) //释放锁 + var lockKey = strconv.Itoa(int(v)) + // 分布式锁--防止重复下单 + _, ok1 := lockMap.Load(lockKey) //获取锁 + if ok1 { + return resp.SetStatusWithMessage(basic.CodeErrOrder, "create order failed, cannot place duplicate order") + } else { + lockMap.Store(lockKey, true) //加锁 + defer lockMap.Delete(lockKey) //释放锁 + } } tPlus60Days := time.Now().AddDate(0, 0, 60).UTC()