From 788dbd325ee74f8dd5e384bf1bf8d05a68a1387d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 11:57:10 +0800 Subject: [PATCH] fix --- .../internal/logic/gettagproductlistlogic.go | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 5107c10e..10c61c59 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -3,6 +3,8 @@ package logic import ( "encoding/json" "errors" + "fmt" + "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -228,9 +230,51 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn }) } //获取产品最低价格 - req.MapProductMinPrice, err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) + modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price") if err != nil { - return nil, err + logx.Error(err) + return nil, errors.New("failed to get model list") + } + mapModelMinPrice := make(map[int64]int64) + //每个模型/配件存储最小价格 + for _, modelInfo := range modelList { + 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)) + } + var stepPrice gmodel.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)) + } + lenRange := len(stepPrice.PriceRange) + if lenRange == 0 { + return nil, 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 + } + } + //给产品存储最小价格 + 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 + } + } + if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok { + if itemPrice < minPrice { + req.MapProductMinPrice[*v.ProductId] = itemPrice + } + continue + } + req.MapProductMinPrice[*v.ProductId] = itemPrice } //获取模板 productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")