From f8f774ca1c678cc082944fcc9290cf3851028944 Mon Sep 17 00:00:00 2001 From: chenlin Date: Tue, 17 Sep 2024 01:19:57 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E5=88=9B=E5=BB=BA=E7=A7=9F?= =?UTF-8?q?=E8=B5=81=E8=AE=A2=E5=8D=95=E6=97=B6=E5=BC=82=E5=B8=B8=E9=80=80?= =?UTF-8?q?=E5=87=BA=E5=AF=BC=E8=87=B4=E6=95=B0=E6=8D=AE=E5=BA=93=E6=AD=BB?= =?UTF-8?q?=E9=94=81=E9=97=AE=E9=A2=98=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/order.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/controller/order.go b/controller/order.go index 0cd36c9..3a09b60 100644 --- a/controller/order.go +++ b/controller/order.go @@ -289,11 +289,17 @@ func RentCardOrderCreate(c *gin.Context) { isRentCount, err := rentCard.IsHaveUnreturnedOrders(cardCount) //unreturnedOrders, err := model.IsHaveUnreturnedOrders(uc.Uid) // if err != nil { + if req.Price == 0 { + tx.Rollback() + } logger.Error("err:", err) RespJson(c, status.InternalServerError, nil) return } if isRentCount { + if req.Price == 0 { + tx.Rollback() + } logger.Error("unreturnedOrders") RespJson(c, status.HaveUnreturnedOrders, nil) return @@ -301,11 +307,17 @@ func RentCardOrderCreate(c *gin.Context) { online, err := model.IsGameCardListOnline(req.GameCardList) if err != nil { + if req.Price == 0 { + tx.Rollback() + } logger.Error("err:", err) RespJson(c, status.InternalServerError, nil) return } if !online { + if req.Price == 0 { + tx.Rollback() + } logger.Error("unreturnedOrders") RespJson(c, status.GoodsSoldOut, nil) return @@ -314,6 +326,9 @@ func RentCardOrderCreate(c *gin.Context) { store.ID = req.StoreId err = store.Info() if err != nil { + if req.Price == 0 { + tx.Rollback() + } logger.Error("store err:", err) RespJson(c, status.InternalServerError, nil) return @@ -345,6 +360,9 @@ func RentCardOrderCreate(c *gin.Context) { // OrderAscByID().Limit(1).One(&userCoupon) err = model.NewUserCouponQuerySet(model.DB).IDEq(req.UserCouponId).One(&userCoupon) if err != nil && err != model.RecordNotFound { + if req.Price == 0 { + tx.Rollback() + } logger.Error("user coupon err:", err) RespJson(c, status.InternalServerError, nil) return @@ -370,11 +388,17 @@ func RentCardOrderCreate(c *gin.Context) { //} stockEnough, err := model.IsCardGoodsStockEnough(req.GameCardList, req.StoreId) if err != nil { + if req.Price == 0 { + tx.Rollback() + } logger.Error("err:", err) RespJson(c, status.OrderStockOut, nil) return } if stockEnough { + if req.Price == 0 { + tx.Rollback() + } logger.Error("order stock out ") RespJson(c, status.OrderStockOut, nil) return @@ -420,7 +444,7 @@ func RentCardOrderCreate(c *gin.Context) { // RespJson(c, status.InternalServerError, nil) // return //} - err := model.GameCardGoodsInventoryReduction(req.GameCardList, req.StoreId, tx) + err = model.GameCardGoodsInventoryReduction(req.GameCardList, req.StoreId, tx) if err != nil { tx.Rollback() logger.Error("inventory reduction err:", err.Error())