diff --git a/server/shopping-cart/internal/logic/calculatecartpricelogic.go b/server/shopping-cart/internal/logic/calculatecartpricelogic.go index 3f34b490..31a4b317 100644 --- a/server/shopping-cart/internal/logic/calculatecartpricelogic.go +++ b/server/shopping-cart/internal/logic/calculatecartpricelogic.go @@ -46,13 +46,13 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{CalculateResultList: []types.CalculateResultItem{}}) } cartIds := make([]int64, 0, len(req.CalculateList)) - mapCalculateQuantity := make(map[int64]int64) + mapCalculateQuantity := make(map[int64]types.CalculateItem) for _, v := range req.CalculateList { cartIds = append(cartIds, v.CartId) if v.PurchaseQuantity <= 0 { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "purchase quantity must grater than 0") } - mapCalculateQuantity[v.CartId] = v.PurchaseQuantity + mapCalculateQuantity[v.CartId] = v } //获取购物车列表 carts, _, err := l.svcCtx.AllModels.FsShoppingCart.GetAllCartsByParam(l.ctx, gmodel.GetAllCartsByParamReq{ @@ -128,7 +128,8 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri return errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *cart.ProductId, *cart.SizeId)) } //请求的数量 - reqPurchaseQuantity := mapCalculateQuantity[cart.Id] + reqPurchaseQuantity := mapCalculateQuantity[cart.Id].PurchaseQuantity + isSelected := mapCalculateQuantity[cart.Id].IsSelected //购买箱数 boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*sizePrice.EachBoxNum))) //根据数量获取阶梯价格中对应的价格 @@ -148,7 +149,10 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)), TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)), }) - subTotalPrice += totalPrice + //如果是选中则累加总价 + if isSelected { + subTotalPrice += totalPrice + } //更新购物车购买数量 err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, &gmodel.FsShoppingCart{ PurchaseQuantity: &reqPurchaseQuantity, diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index 1ed8b661..65041e67 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -95,6 +95,7 @@ type CalculateCartPriceReq struct { type CalculateItem struct { CartId int64 `json:"cart_id"` //购物车id PurchaseQuantity int64 `json:"purchase_quantity"` //数量 + IsSelected bool `json:"is_selected"` //是否是选中的,选中的会统计到总价中 } type CalculateCartPriceRsp struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 216bdfe2..0c076fa2 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -109,6 +109,7 @@ type CalculateCartPriceReq { type CalculateItem { CartId int64 `json:"cart_id"` //购物车id PurchaseQuantity int64 `json:"purchase_quantity"` //数量 + IsSelected bool `json:"is_selected"` //是否是选中的,选中的会统计到总价中 } type CalculateCartPriceRsp { SubTotalPrice string `json:"sub_total_price"`