From 6a912a145e1b1189c325a0601fbcfab060a23531 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Mon, 21 Aug 2023 10:21:02 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_template_v2_logic.go | 14 ++++++++++++++ .../internal/logic/gettagproductlistlogic.go | 11 +++++++++-- server/product/internal/types/types.go | 1 + server_api/product.api | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index d5364778..40e8a6bc 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -153,3 +153,17 @@ func (t *FsProductTemplateV2Model) GetListByProductAndTemplateTag(ctx context.Co err = db.Find(&resp).Error return resp, err } +func (t *FsProductTemplateV2Model) FindAllByProductIdsTemplateTag(ctx context.Context, productIds []int64, templateTag string, sort string, fields ...string) (resp []FsProductTemplateV2, err error) { + if len(productIds) == 0 { + return + } + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `template_tag` = ? and `is_del` = ? and `status` = ?", productIds, templateTag, 0, 1) + if sort != "" { + db = db.Order(sort) + } + if len(fields) != 0 { + db = db.Select(fields[0]) + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 8d51e6fa..3e7061fd 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -170,13 +170,20 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR } } //获取模板(只是获取产品product_id,id) - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id") + if req.TemplateTag != "" { //指定模板tag + productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdsTemplateTag(l.ctx, productIds, req.TemplateTag, "sort ASC", "product_id,id") + } else { //没指定模板tag + productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id") + } if err != nil { logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product templates") } //只存第一个 for _, v := range productTemplatesV2 { + if _, ok := mapProductTemplate[*v.ProductId]; ok { + continue + } mapProductTemplate[*v.ProductId] = v.Id } //获取产品尺寸数量 diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 7d511c6e..bc9c1135 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -249,6 +249,7 @@ type GetRecommandProductListRsp struct { type GetTagProductListReq struct { Cid int64 `form:"cid,optional"` //分类id Size uint32 `form:"size,optional"` //尺寸 + TemplateTag string `form:"template_tag,optional"` //模板标签 WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } diff --git a/server_api/product.api b/server_api/product.api index 8a6fdbf8..b479c9ef 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -301,6 +301,7 @@ type GetRecommandProductListRsp { type GetTagProductListReq { Cid int64 `form:"cid,optional"` //分类id Size uint32 `form:"size,optional"` //尺寸 + TemplateTag string `form:"template_tag,optional"` //模板标签 WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品 } type GetTagProductListRsp {