Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop

This commit is contained in:
momo 2023-11-24 17:02:49 +08:00
commit aa3aa3ce62
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)

View File

@ -3,6 +3,7 @@ package logic
import (
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
@ -162,9 +163,9 @@ func (l *GetProductDetailLogic) GetProductDetail(req *types.GetProductDetailReq,
for k, v := range templateList {
mapModelIdKeyTemplate[*v.ModelId] = k
}
//记录产品最低价
mapProductMinPrice := make(map[int64]int64)
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(modelList, mapProductMinPrice); err != nil {
//记录产品尺寸最低价
mapProductSizeMinPrice := make(map[string]int64)
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductSizeMinPrice(modelList, mapProductSizeMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
}
@ -184,7 +185,7 @@ func (l *GetProductDetailLogic) GetProductDetail(req *types.GetProductDetailReq,
}
//尺寸下最低价
minPrice := ""
if price, ok := mapProductMinPrice[*sizeInfo.ProductId]; ok {
if price, ok := mapProductSizeMinPrice[fmt.Sprintf("%d_%d", *sizeInfo.ProductId, sizeInfo.Id)]; ok {
minPrice = format.CentitoDollar(price, 3)
}
var modelInfoRsp types.ModelInfo