fix
This commit is contained in:
@@ -74,14 +74,14 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *a
|
||||
}
|
||||
//获取价格列表
|
||||
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
||||
productPriceList, err := productPriceModel.GetPriceListBySizeIds(l.ctx, sizeIds)
|
||||
productPriceList, err := productPriceModel.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product proce list")
|
||||
}
|
||||
mapProductPrice := make(map[int64]gmodel.FsProductPrice)
|
||||
mapProductPrice := make(map[string]gmodel.FsProductPrice)
|
||||
for _, v := range productPriceList {
|
||||
mapProductPrice[*v.SizeId] = v
|
||||
mapProductPrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
|
||||
}
|
||||
//组装返回
|
||||
list := make([]types.GetSizeByProductRsp, 0, len(tagsList))
|
||||
@@ -103,7 +103,7 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *a
|
||||
}
|
||||
|
||||
// 第一层子层
|
||||
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
||||
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[string]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
||||
childrenList = make([]types.Children, 0, len(productList))
|
||||
for _, product := range productList {
|
||||
if *product.Type != tag.Id {
|
||||
@@ -126,14 +126,14 @@ func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productL
|
||||
}
|
||||
|
||||
// 第2层子层
|
||||
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
||||
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[string]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
||||
childrenObjList = make([]types.ChildrenObj, 0, len(productSizeList))
|
||||
for _, productSize := range productSizeList {
|
||||
if product.Id != *productSize.ProductId {
|
||||
continue
|
||||
}
|
||||
priceList := make([]types.PriceObj, 0, len(productSizeList))
|
||||
price, ok := mapProductPrice[productSize.Id]
|
||||
price, ok := mapProductPrice[fmt.Sprintf("%d_%d", *productSize.ProductId, productSize.Id)]
|
||||
//无对应尺寸价格
|
||||
if !ok {
|
||||
priceList = []types.PriceObj{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"` //尺寸名称
|
||||
|
||||
Reference in New Issue
Block a user