From 05ec31212779fefe46acfe71297aab2e148437cf Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 19 Oct 2023 11:51:49 +0800 Subject: [PATCH] fix --- .../logic/getrecommandproductlistlogic.go | 62 +++++++++++++++---- server/product/internal/types/types.go | 28 +++++---- server_api/product.api | 28 +++++---- 3 files changed, 79 insertions(+), 39 deletions(-) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index 1a1cd03e..e63f5a22 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -90,6 +90,32 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec recommendProductList = append(recommendProductList, v) } } + //获取商品可选配件 + productOptionalPartList, err := l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product part list") + } + //存储有配件的map + mapProductHaveOptionFitting := make(map[int64]struct{}) + for _, partList := range productOptionalPartList { + partList.PartList = strings.Trim(partList.PartList, " ") + partList.PartList = strings.Trim(partList.PartList, ",") + if partList.PartList == "" { + continue + } + mapProductHaveOptionFitting[partList.ProductId] = struct{}{} + } + //获取产品尺寸数量 + productSizeCountList, err := l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get ") + } + mapProductSizeCount := make(map[int64]int64) + for _, v := range productSizeCountList { + mapProductSizeCount[v.ProductId] = v.Num + } //获取产品最低价 mapProductMinPrice := make(map[int64]int64) modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, []int64{productInfo.Id}, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,size_id,product_id,price,tag,part_id,step_price") @@ -142,20 +168,30 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec if minVal, ok := mapProductMinPrice[v.Id]; ok { minPrice = minVal } + sizeCount := int64(0) + if sc, ok := mapProductSizeCount[v.Id]; ok { + sizeCount = sc + } + haveOptionalFitting := int64(0) + if _, ok := mapProductHaveOptionFitting[v.Id]; ok { + haveOptionalFitting = 1 + } item := types.GetRecommandProductListRsp{ - Id: v.Id, - Sn: *v.Sn, - Title: *v.Title, - TitleCn: *v.TitleCn, - Cover: *v.Cover, - CoverMetadata: mapResourceMetadata[*v.Cover], - CoverImg: *v.CoverImg, - CoverImgMetadata: mapResourceMetadata[*v.CoverImg], - CoverDefault: []types.CoverDefaultItem{}, - Intro: *v.Intro, - Recommend: recommend, - MinPrice: minPrice, - IsCustomization: *v.IsCustomization, + Id: v.Id, + Sn: *v.Sn, + Title: *v.Title, + TitleCn: *v.TitleCn, + Cover: *v.Cover, + CoverMetadata: mapResourceMetadata[*v.Cover], + CoverImg: *v.CoverImg, + CoverImgMetadata: mapResourceMetadata[*v.CoverImg], + CoverDefault: []types.CoverDefaultItem{}, + Intro: *v.Intro, + Recommend: recommend, + MinPrice: minPrice, + IsCustomization: *v.IsCustomization, + SizeCount: sizeCount, + HaveOptionalFitting: haveOptionalFitting, } if _, ok := mapTagProp[productInfo.Id]; ok { item.CoverDefault = mapTagProp[productInfo.Id] diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index b3e58289..708237b8 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -11,19 +11,21 @@ type GetRecommandProductListReq struct { } type GetRecommandProductListRsp struct { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - TitleCn string `json:"title_cn"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - CoverImg string `json:"cover_img"` - CoverImgMetadata interface{} `json:"cover_img_metadata"` - CoverDefault []CoverDefaultItem `json:"cover_default"` - Intro string `json:"intro"` - Recommend bool `json:"recommend"` - MinPrice int64 `json:"min_price"` - IsCustomization int64 `json:"is_customization"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + TitleCn string `json:"title_cn"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + CoverImg string `json:"cover_img"` + CoverImgMetadata interface{} `json:"cover_img_metadata"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + Intro string `json:"intro"` + Recommend bool `json:"recommend"` + MinPrice int64 `json:"min_price"` + IsCustomization int64 `json:"is_customization"` + SizeCount int64 `json:"size_count"` + HaveOptionalFitting int64 `json:"have_optional_fitting"` } type GetTagProductListReq struct { diff --git a/server_api/product.api b/server_api/product.api index d43853e1..dc12487b 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -57,19 +57,21 @@ type GetRecommandProductListReq { ProductId int64 `form:"product_id"` } type GetRecommandProductListRsp { - Id int64 `json:"id"` - Sn string `json:"sn"` - Title string `json:"title"` - TitleCn string `json:"title_cn"` - Cover string `json:"cover"` - CoverMetadata interface{} `json:"cover_metadata"` - CoverImg string `json:"cover_img"` - CoverImgMetadata interface{} `json:"cover_img_metadata"` - CoverDefault []CoverDefaultItem `json:"cover_default"` - Intro string `json:"intro"` - Recommend bool `json:"recommend"` - MinPrice int64 `json:"min_price"` - IsCustomization int64 `json:"is_customization"` + Id int64 `json:"id"` + Sn string `json:"sn"` + Title string `json:"title"` + TitleCn string `json:"title_cn"` + Cover string `json:"cover"` + CoverMetadata interface{} `json:"cover_metadata"` + CoverImg string `json:"cover_img"` + CoverImgMetadata interface{} `json:"cover_img_metadata"` + CoverDefault []CoverDefaultItem `json:"cover_default"` + Intro string `json:"intro"` + Recommend bool `json:"recommend"` + MinPrice int64 `json:"min_price"` + IsCustomization int64 `json:"is_customization"` + SizeCount int64 `json:"size_count"` + HaveOptionalFitting int64 `json:"have_optional_fitting"` } //获取分类产品列表 type GetTagProductListReq {