This commit is contained in:
laodaming
2023-11-24 16:51:46 +08:00
parent 4cacf2c16d
commit b72d1675e4
2 changed files with 56 additions and 4 deletions

View File

@@ -176,6 +176,57 @@ func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, prod
return resp, err
}
// 获取尺寸最低价格
func (d *FsProductModel3dModel) GetProductSizeMinPrice(modelList []FsProductModel3d, mapProductSizeMinPrice map[string]int64) error {
mapModelMinPrice := make(map[int64]int64)
//每个模型/配件存储最小价格
for _, modelInfo := range modelList {
switch *modelInfo.Tag {
case constants.TAG_MODEL: //模型
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
mapModelMinPrice[modelInfo.Id] = 0
continue
}
var stepPrice StepPriceJsonStruct
if err := json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
return fmt.Errorf("failed to parse model step price:%d", modelInfo.Id)
}
lenRange := len(stepPrice.PriceRange)
if lenRange == 0 {
mapModelMinPrice[modelInfo.Id] = 0
continue
}
sort.SliceStable(stepPrice.PriceRange, func(i, j int) bool {
return stepPrice.PriceRange[i].Price > stepPrice.PriceRange[j].Price
})
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
case constants.TAG_PARTS: //配件
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
}
}
//给产品存储最小价格
for _, v := range modelList {
if *v.Tag != constants.TAG_MODEL {
continue
}
itemPrice := mapModelMinPrice[v.Id]
if *v.PartId > 0 {
if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok {
itemPrice += fittingPrice
}
}
key := fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)
if minPrice, ok := mapProductSizeMinPrice[key]; ok {
if itemPrice < minPrice {
mapProductSizeMinPrice[key] = itemPrice
}
continue
}
mapProductSizeMinPrice[key] = itemPrice
}
return nil
}
// 获取每个产品最低价格
func (d *FsProductModel3dModel) GetProductMinPrice(modelList []FsProductModel3d, mapProductMinPrice map[int64]int64) error {
mapModelMinPrice := make(map[int64]int64)