添加购物车新增灯光信息保存

This commit is contained in:
laodaming 2023-09-20 11:02:46 +08:00
parent 86c39263be
commit d8707e3a4a
3 changed files with 10 additions and 4 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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"`