From f892a216d6850fc02e3a8c0537dc7b678f40d2dd Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 17 Aug 2023 18:19:15 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_template_v2_logic.go | 5 ++++- .../product/internal/logic/getproductlistlogic.go | 2 +- .../internal/logic/gettagproductlistlogic.go | 14 ++++++++------ .../logic/homepagerecommendproductlistlogic.go | 2 +- server/product/internal/types/types.go | 1 + server_api/product.api | 1 + 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index 388041a0..cfae7d32 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -4,11 +4,14 @@ import ( "context" ) -func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64, fields ...string) (resp []FsProductTemplateV2, err error) { +func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64, 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 `is_del` = ? and `status` = ?", productIds, 0, 1) + if sort != "" { + db = db.Order(sort) + } if len(fields) != 0 { db = db.Select(fields[0]) } diff --git a/server/product/internal/logic/getproductlistlogic.go b/server/product/internal/logic/getproductlistlogic.go index f45b8418..d12bc4dd 100644 --- a/server/product/internal/logic/getproductlistlogic.go +++ b/server/product/internal/logic/getproductlistlogic.go @@ -99,7 +99,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri } //获取模板 productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds) + productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds, "") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index 6eed71ac..18a62e13 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -90,7 +90,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方) productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方) mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map - mapProductTemplate = make(map[int64]struct{}) //产品模板map + mapProductTemplate = make(map[int64]int64) //产品模板map ) //携带产品 if req.WithProduct { @@ -170,13 +170,14 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR } } //获取模板(只是获取产品product_id) - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id") + productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") } + //只存第一个 for _, v := range productTemplatesV2 { - mapProductTemplate[*v.ProductId] = struct{}{} + mapProductTemplate[*v.ProductId] = v.Id } //获取产品尺寸数量 productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) @@ -225,7 +226,7 @@ type dealWithTagMenuDataReq struct { MapTagProp map[int64][]types.CoverDefaultItem ProductTagPropList []gmodel.FsProductTagProp MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} + MapProductTemplate map[int64]int64 MapProductSizeCount map[int64]int64 MapTagLevel map[string]*types.TagItem MapProductHaveOptionFitting map[int64]struct{} @@ -334,7 +335,7 @@ type getTagProductsReq struct { ProductList []gmodel.FsProduct MapTagProp map[int64][]types.CoverDefaultItem MapProductMinPrice map[int64]int64 - MapProductTemplate map[int64]struct{} + MapProductTemplate map[int64]int64 MapProductSizeCount map[int64]int64 MapProductHaveOptionFitting map[int64]struct{} Size uint32 @@ -350,7 +351,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL continue } minPrice, ok := req.MapProductMinPrice[productInfo.Id] - _, tmpOk := req.MapProductTemplate[productInfo.Id] + templateId, tmpOk := req.MapProductTemplate[productInfo.Id] //无最小价格则不显示 || 没有模板也不显示 if !ok || !tmpOk { continue @@ -370,6 +371,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL Title: *productInfo.Title, SizeNum: uint32(sizeNum), CoverDefault: []types.CoverDefaultItem{}, + DefaultTemplateId: templateId, MinPrice: minPrice, HaveOptionalFitting: haveOptionalFitting, Recommended: *productInfo.IsRecommend > 0, diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index 6d449757..9c70f5ca 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -130,7 +130,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty } } //获取模板(只是获取产品product_id) - productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id") + productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "", "product_id") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 6adf44d2..ac643648 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -275,6 +275,7 @@ type TagProduct struct { SizeNum uint32 `json:"size_num"` MinPrice int64 `json:"min_price"` CoverDefault []CoverDefaultItem `json:"cover_default"` + DefaultTemplateId int64 `json:"default_template_id"` HaveOptionalFitting bool `json:"have_optional_fitting"` Recommended bool `json:"recommended"` } diff --git a/server_api/product.api b/server_api/product.api index 9e8626c5..abc24c02 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -325,6 +325,7 @@ type TagProduct { MinPrice int64 `json:"min_price"` //彩膜列表 CoverDefault []CoverDefaultItem `json:"cover_default"` + DefaultTemplateId int64 `json:"default_template_id"` HaveOptionalFitting bool `json:"have_optional_fitting"` Recommended bool `json:"recommended"` }