From 02f2e08329aefc60373d9a0b36fd49b9ba3272bb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 27 Sep 2023 14:05:26 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_model3d_logic.go | 19 ++++--- .../logic/getrecommandproductlistlogic.go | 5 +- .../internal/logic/gettagproductlistlogic.go | 50 +------------------ .../homepagerecommendproductlistlogic.go | 4 +- 4 files changed, 16 insertions(+), 62 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index e7449a84..bd53a467 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -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 } diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 3f0545d0..b65c3cb1 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -91,8 +91,9 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec recommendProductList = append(recommendProductList, v) } } - mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) - if err != nil { + //获取产品最低价 + mapProductMinPrice := make(map[int64]int64) + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price") } //获取产品标签相关属性 diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 10c61c59..fdc951e6 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -3,8 +3,6 @@ package logic import ( "encoding/json" "errors" - "fmt" - "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" @@ -230,51 +228,8 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn }) } //获取产品最低价格 - 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 { - 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 + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil { + return nil, errors.New("failed to get product min price") } //获取模板 productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") @@ -290,7 +245,6 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn req.MapProductTemplate[*v.ProductId] = v.Id } } - //获取产品尺寸数量 productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) if err != nil { diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index c5be671a..eeb5726b 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -112,8 +112,8 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty mapProductHaveOptionFitting[partList.ProductId] = struct{}{} } //获取产品最低价格 - mapProductMinPrice, err := l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds) - if err != nil { + mapProductMinPrice := make(map[int64]int64) + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price") } //获取模板(只是获取产品product_id)