From 9342ab8c24de2fe9d0ec2fe9ee4f0a3fe53b565b Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 20 Sep 2023 11:17:00 +0800 Subject: [PATCH] 11 --- .../internal/logic/calculatecartpricelogic.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/shopping-cart/internal/logic/calculatecartpricelogic.go b/server/shopping-cart/internal/logic/calculatecartpricelogic.go index 31a4b317..4eb6b7c0 100644 --- a/server/shopping-cart/internal/logic/calculatecartpricelogic.go +++ b/server/shopping-cart/internal/logic/calculatecartpricelogic.go @@ -129,7 +129,10 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri } //请求的数量 reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity - isSelected := mapCalculateQuantity[cart.Id].IsSelected + isSelected := int64(0) + if mapCalculateQuantity[cart.Id].IsSelected { + isSelected = 1 + } //购买箱数 boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*sizePrice.EachBoxNum))) //根据数量获取阶梯价格中对应的价格 @@ -149,15 +152,16 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)), TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)), }) + updData := &gmodel.FsShoppingCart{ + PurchaseQuantity: &reqPurchaseQuantity, + } //如果是选中则累加总价 - if isSelected { + if isSelected == 1 { subTotalPrice += totalPrice + updData.IsSelected = &isSelected } //更新购物车购买数量 - err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, &gmodel.FsShoppingCart{ - PurchaseQuantity: &reqPurchaseQuantity, - }) - if err != nil { + if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil { logx.Error(err) return errors.New(fmt.Sprintf("failed to update cart`s purchase quantity:%d", cart.Id)) }