From c51a034a9ff3affc44a49e9b89ece91ef3aa2ce4 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 30 Oct 2023 15:03:00 +0800 Subject: [PATCH] fix --- .../internal/logic/gettagproductlistlogic.go | 37 ++++++++++++++++++- server/product/internal/types/types.go | 7 ++-- server_api/product.api | 7 ++-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index dd60beeb..5b62e928 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -7,6 +7,7 @@ import ( "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/format" "fusenapi/utils/s3url_to_s3id" "gorm.io/gorm" "sort" @@ -86,7 +87,33 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map mapProductTemplate = make(map[int64]int64) //产品模板map mapResourceMetadata = make(map[string]map[string]interface{}) //资源元数据 + merchantInfo *gmodel.FsMerchantCategory ) + //选了商家类型 + if req.MerchantType > 0 { + merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType) + } else { + //获取默认的那个 + merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindDefualtOne(l.ctx) + } + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeOK, "the merchant category is not exists", []interface{}{}) + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant category") + } + mapRecommendProduct := make(map[int64]struct{}) + if *merchantInfo.RecommendProduct != "" { + ids, err := format.StrSlicToInt64Slice(strings.Split(*merchantInfo.RecommendProduct, ",")) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to parse merchant recommend product") + } + for _, v := range ids { + mapRecommendProduct[v] = struct{}{} + } + } //携带产品 if req.WithProduct { productList, err = l.getProductRelationInfo(getProductRelationInfoReq{ @@ -115,6 +142,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR WithProduct: req.WithProduct, ProductList: productList, MapTagProduct: mapTagProduct, + MapRecommendProduct: mapRecommendProduct, MapTagProp: mapTagProp, MapProductMinPrice: mapProductMinPrice, MapProductTemplate: mapProductTemplate, @@ -265,6 +293,7 @@ type dealWithTagMenuDataReq struct { WithProduct bool ProductList []gmodel.FsProduct MapTagProduct map[int64]types.TagProduct + MapRecommendProduct map[int64]struct{} MapTagProp map[int64][]types.CoverDefaultItem ProductTagPropList []gmodel.FsProductTagProp MapProductMinPrice map[int64]int64 @@ -300,6 +329,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) TagId: tagInfo.Id, ProductList: req.ProductList, MapTagProp: req.MapTagProp, + MapRecommendProduct: req.MapRecommendProduct, MapProductMinPrice: req.MapProductMinPrice, MapProductTemplate: req.MapProductTemplate, MapProductSizeCount: req.MapProductSizeCount, @@ -386,6 +416,7 @@ type getTagProductsReq struct { TagId int64 ProductList []gmodel.FsProduct MapTagProp map[int64][]types.CoverDefaultItem + MapRecommendProduct map[int64]struct{} MapProductMinPrice map[int64]int64 MapProductTemplate map[int64]int64 MapProductSizeCount map[int64]int64 @@ -419,6 +450,10 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL if _, ok = req.MapProductHaveOptionFitting[productInfo.Id]; ok { haveOptionalFitting = true } + isRecommend := false + if _, ok = req.MapRecommendProduct[productInfo.Id]; ok { + isRecommend = true + } item := types.TagProduct{ Id: productInfo.Id, Sn: *productInfo.Sn, @@ -427,7 +462,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL CoverDefault: []types.CoverDefaultItem{}, MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, - Recommended: *productInfo.IsRecommend > 0, + Recommended: isRecommend, Cover: *productInfo.Cover, CoverMetadata: req.MapResourceMetadata[*productInfo.Cover], IsCustomization: *productInfo.IsCustomization, diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 3587d1b7..a8180123 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -29,9 +29,10 @@ type GetRecommandProductListRsp struct { } type GetTagProductListReq struct { - Cid int64 `form:"cid,optional"` //分类id - TemplateTag string `form:"template_tag,optional"` //模板标签 - WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 + Cid int64 `form:"cid,optional"` //分类id + MerchantType int64 `form:"merchant_type,optional"` //商户类型 + TemplateTag string `form:"template_tag,optional"` //模板标签 + WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp struct { diff --git a/server_api/product.api b/server_api/product.api index 03b27648..4d787558 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -72,9 +72,10 @@ type GetRecommandProductListRsp { } //获取分类产品列表 type GetTagProductListReq { - Cid int64 `form:"cid,optional"` //分类id - TemplateTag string `form:"template_tag,optional"` //模板标签 - WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 + Cid int64 `form:"cid,optional"` //分类id + MerchantType int64 `form:"merchant_type,optional"` //商户类型 + TemplateTag string `form:"template_tag,optional"` //模板标签 + WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp { TotalCategoryProduct int `json:"total_category_product"`