This commit is contained in:
laodaming 2023-08-17 18:19:15 +08:00
parent 68b125f5a6
commit f892a216d6
6 changed files with 16 additions and 9 deletions

View File

@ -4,11 +4,14 @@ import (
"context" "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 { if len(productIds) == 0 {
return return
} }
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1) 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 { if len(fields) != 0 {
db = db.Select(fields[0]) db = db.Select(fields[0])
} }

View File

@ -99,7 +99,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
} }
//获取模板 //获取模板
productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) productTemplateModel := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds) productTemplatesV2, err := productTemplateModel.FindAllByProductIds(l.ctx, productIds, "")
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")

View File

@ -90,7 +90,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方) productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方)
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表select 字段需要看查询的地方) productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表select 字段需要看查询的地方)
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
mapProductTemplate = make(map[int64]struct{}) //产品模板map mapProductTemplate = make(map[int64]int64) //产品模板map
) )
//携带产品 //携带产品
if req.WithProduct { if req.WithProduct {
@ -170,13 +170,14 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
} }
} }
//获取模板(只是获取产品product_id) //获取模板(只是获取产品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 { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
} }
//只存第一个
for _, v := range productTemplatesV2 { for _, v := range productTemplatesV2 {
mapProductTemplate[*v.ProductId] = struct{}{} mapProductTemplate[*v.ProductId] = v.Id
} }
//获取产品尺寸数量 //获取产品尺寸数量
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1) productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
@ -225,7 +226,7 @@ type dealWithTagMenuDataReq struct {
MapTagProp map[int64][]types.CoverDefaultItem MapTagProp map[int64][]types.CoverDefaultItem
ProductTagPropList []gmodel.FsProductTagProp ProductTagPropList []gmodel.FsProductTagProp
MapProductMinPrice map[int64]int64 MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{} MapProductTemplate map[int64]int64
MapProductSizeCount map[int64]int64 MapProductSizeCount map[int64]int64
MapTagLevel map[string]*types.TagItem MapTagLevel map[string]*types.TagItem
MapProductHaveOptionFitting map[int64]struct{} MapProductHaveOptionFitting map[int64]struct{}
@ -334,7 +335,7 @@ type getTagProductsReq struct {
ProductList []gmodel.FsProduct ProductList []gmodel.FsProduct
MapTagProp map[int64][]types.CoverDefaultItem MapTagProp map[int64][]types.CoverDefaultItem
MapProductMinPrice map[int64]int64 MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{} MapProductTemplate map[int64]int64
MapProductSizeCount map[int64]int64 MapProductSizeCount map[int64]int64
MapProductHaveOptionFitting map[int64]struct{} MapProductHaveOptionFitting map[int64]struct{}
Size uint32 Size uint32
@ -350,7 +351,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
continue continue
} }
minPrice, ok := req.MapProductMinPrice[productInfo.Id] minPrice, ok := req.MapProductMinPrice[productInfo.Id]
_, tmpOk := req.MapProductTemplate[productInfo.Id] templateId, tmpOk := req.MapProductTemplate[productInfo.Id]
//无最小价格则不显示 || 没有模板也不显示 //无最小价格则不显示 || 没有模板也不显示
if !ok || !tmpOk { if !ok || !tmpOk {
continue continue
@ -370,6 +371,7 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
Title: *productInfo.Title, Title: *productInfo.Title,
SizeNum: uint32(sizeNum), SizeNum: uint32(sizeNum),
CoverDefault: []types.CoverDefaultItem{}, CoverDefault: []types.CoverDefaultItem{},
DefaultTemplateId: templateId,
MinPrice: minPrice, MinPrice: minPrice,
HaveOptionalFitting: haveOptionalFitting, HaveOptionalFitting: haveOptionalFitting,
Recommended: *productInfo.IsRecommend > 0, Recommended: *productInfo.IsRecommend > 0,

View File

@ -130,7 +130,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
} }
} }
//获取模板(只是获取产品product_id) //获取模板(只是获取产品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 { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err") return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")

View File

@ -275,6 +275,7 @@ type TagProduct struct {
SizeNum uint32 `json:"size_num"` SizeNum uint32 `json:"size_num"`
MinPrice int64 `json:"min_price"` MinPrice int64 `json:"min_price"`
CoverDefault []CoverDefaultItem `json:"cover_default"` CoverDefault []CoverDefaultItem `json:"cover_default"`
DefaultTemplateId int64 `json:"default_template_id"`
HaveOptionalFitting bool `json:"have_optional_fitting"` HaveOptionalFitting bool `json:"have_optional_fitting"`
Recommended bool `json:"recommended"` Recommended bool `json:"recommended"`
} }

View File

@ -325,6 +325,7 @@ type TagProduct {
MinPrice int64 `json:"min_price"` MinPrice int64 `json:"min_price"`
//彩膜列表 //彩膜列表
CoverDefault []CoverDefaultItem `json:"cover_default"` CoverDefault []CoverDefaultItem `json:"cover_default"`
DefaultTemplateId int64 `json:"default_template_id"`
HaveOptionalFitting bool `json:"have_optional_fitting"` HaveOptionalFitting bool `json:"have_optional_fitting"`
Recommended bool `json:"recommended"` Recommended bool `json:"recommended"`
} }