This commit is contained in:
laodaming
2023-09-15 16:30:01 +08:00
parent 668db55e6b
commit da8f88b3e6
7 changed files with 46 additions and 32 deletions

View File

@@ -69,7 +69,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
mapSize = make(map[int64]gmodel.FsProductSize)
mapModel = make(map[int64]gmodel.FsProductModel3d)
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
mapSizePrice = make(map[int64]gmodel.FsProductPrice)
mapSizePrice = make(map[string]gmodel.FsProductPrice)
mapProduct = make(map[int64]struct{})
)
//获取相关信息
err = l.GetRelationInfo(GetRelationInfoReq{
@@ -78,6 +79,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
MapModel: mapModel,
MapTemplate: mapTemplate,
MapSizePrice: mapSizePrice,
MapProduct: mapProduct,
})
if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
@@ -93,6 +95,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
MapTemplate: mapTemplate,
MapCartChange: mapCartChange,
MapSnapshot: mapSnapshot,
MapProduct: mapProduct,
})
if err != nil {
logx.Error("VerifyShoppingCartSnapshotDataChange err:", err.Error())
@@ -102,7 +105,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
list := make([]types.CartItem, 0, len(carts))
for _, cart := range carts {
snapShot := mapSnapshot[cart.Id]
sizePrice, ok := mapSizePrice[*cart.SizeId]
sizePrice, ok := mapSizePrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
if !ok {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s price info is not exists:%d", *cart.SizeId))
}
@@ -126,15 +129,12 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
//购买箱数
boxQuantity := int(math.Ceil(float64(*cart.PurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
//获取阶梯数量
stepQuantityList := make([]types.StepNumItem, 0, 10)
stepQuantityList := make([]int64, 0, 20)
tmpMinBuyNum := *sizePrice.MinBuyNum
for tmpMinBuyNum < (int64(stepNum[lenStepNum-1]) + 5) {
//阶梯数
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
stepQuantityList = append(stepQuantityList, types.StepNumItem{
PurchaseQuantity: tmpQuantity,
IsSelected: *cart.PurchaseQuantity == tmpQuantity,
})
stepQuantityList = append(stepQuantityList, tmpQuantity)
tmpMinBuyNum++
}
//根据数量获取阶梯价格中对应的价格
@@ -169,6 +169,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
Qrcode: snapShot.UserDiyInformation.Qrcode,
Slogan: snapShot.UserDiyInformation.Slogan,
},
PurchaseQuantity: *cart.PurchaseQuantity,
StepNum: stepQuantityList,
IsInvalid: false,
InvalidDescription: "",
@@ -197,7 +198,8 @@ type GetRelationInfoReq struct {
MapSize map[int64]gmodel.FsProductSize
MapModel map[int64]gmodel.FsProductModel3d
MapTemplate map[int64]gmodel.FsProductTemplateV2
MapSizePrice map[int64]gmodel.FsProductPrice
MapSizePrice map[string]gmodel.FsProductPrice
MapProduct map[int64]struct{}
}
func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
@@ -205,10 +207,21 @@ func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
templateIds := make([]int64, 0, lenCarts)
modelIds := make([]int64, 0, lenCarts) //模型 + 配件
sizeIds := make([]int64, 0, lenCarts)
productIds := make([]int64, 0, lenCarts)
for index := range req.Carts {
templateIds = append(templateIds, *req.Carts[index].TemplateId)
modelIds = append(modelIds, *req.Carts[index].ModelId, *req.Carts[index].FittingId)
sizeIds = append(sizeIds, *req.Carts[index].SizeId)
productIds = append(productIds, *req.Carts[index].ProductId)
}
//获取产品集合
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "", "id")
if err != nil {
logx.Error(err)
return errors.New("failed to get product list")
}
for _, v := range productList {
req.MapProduct[v.Id] = struct{}{}
}
//获取尺寸列表
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByIds(l.ctx, sizeIds, "")
@@ -238,13 +251,13 @@ func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
req.MapTemplate[v.Id] = v
}
//根据sizeid获取价格列表
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListBySizeIds(l.ctx, sizeIds)
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
if err != nil {
logx.Error(err)
return errors.New("failed to get cart`s product price list")
}
for _, v := range priceList {
req.MapSizePrice[*v.SizeId] = v
req.MapSizePrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
}
return nil
}

View File

@@ -50,16 +50,12 @@ type CartItem struct {
ItemPrice string `json:"item_price"` //单价
TotalPrice string `json:"total_price"` //单价X数量=总价
DiyInformation DiyInformation `json:"diy_information"` //diy信息
StepNum []StepNumItem `json:"step_num"` //阶梯数量
StepNum []int64 `json:"step_num"` //阶梯数量
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
IsInvalid bool `json:"is_invalid"` //是否无效
InvalidDescription string `json:"invalid_description"` //无效原因
}
type StepNumItem struct {
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
IsSelected bool `json:"is_selected"` //是否选中
}
type SizeInfo struct {
SizeId int64 `json:"size_id"` //尺寸id
Capacity string `json:"capacity"` //尺寸名称