This commit is contained in:
laodaming
2023-09-27 14:05:26 +08:00
parent 465bc5e62d
commit 02f2e08329
4 changed files with 16 additions and 62 deletions

View File

@@ -173,11 +173,11 @@ func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, prod
}
// 获取每个产品最低价格
func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64) (productMinPrice map[int64]int64, err error) {
func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productIds []int64, mapProductMinPrice map[int64]int64) error {
//获取产品模型价格列表
modelList, err := d.GetAllByProductIdsTags(ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
if err != nil {
return
return errors.New("failed to get model list")
}
mapModelMinPrice := make(map[int64]int64)
//每个模型/配件存储最小价格
@@ -185,23 +185,22 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI
switch *modelInfo.Tag {
case constants.TAG_MODEL: //模型
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
return errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
}
var stepPrice StepPriceJsonStruct
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
logx.Error(err)
return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
return errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
}
lenRange := len(stepPrice.PriceRange)
if lenRange == 0 {
return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
}
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
case constants.TAG_PARTS: //配件
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
}
}
productMinPrice = make(map[int64]int64)
//给产品存储最小价格
for _, v := range modelList {
if *v.Tag != constants.TAG_MODEL {
@@ -213,13 +212,13 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI
itemPrice += fittingPrice
}
}
if minPrice, ok := productMinPrice[*v.ProductId]; ok {
if minPrice, ok := mapProductMinPrice[*v.ProductId]; ok {
if itemPrice < minPrice {
productMinPrice[*v.ProductId] = itemPrice
mapProductMinPrice[*v.ProductId] = itemPrice
}
continue
}
productMinPrice[*v.ProductId] = itemPrice
mapProductMinPrice[*v.ProductId] = itemPrice
}
return productMinPrice, nil
return nil
}