This commit is contained in:
laodaming 2023-07-19 19:29:50 +08:00
parent 3ef96dab13
commit 31132364ad
3 changed files with 24 additions and 101 deletions

View File

@ -2,7 +2,6 @@ package logic
import (
"errors"
"fmt"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@ -79,8 +78,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
}
var (
productList []gmodel.FsProduct //产品列表select 字段需要看查询的地方)
recommendProductList []gmodel.FsProduct //tag推荐产品列表select 字段需要看查询的地方)
mapProduct = make(map[int64]int) //产品map
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表select 字段需要看查询的地方)
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表select 字段需要看查询的地方)
@ -88,28 +85,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
mapProductTemplate = make(map[int64]struct{}) //产品模板map
)
//携带推荐产品
if req.WithRecommendProduct {
//提取tag推荐产品
allTagRecommendProductIds := make([]int64, 0, len(tagList)*5)
for _, v := range tagList {
if v.RecommendProduct == nil || *v.RecommendProduct == "" {
continue
}
sl, err := format.StrSlicToInt64Slice(strings.Split(*v.RecommendProduct, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse recommend product ids,id=%d", v.Id))
}
allTagRecommendProductIds = append(allTagRecommendProductIds, sl...)
}
//获取推荐的产品列表
recommendProductList, err = l.svcCtx.AllModels.FsProduct.FindAllOnlyByIds(l.ctx, allTagRecommendProductIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag recommend products")
}
}
//携带产品
if req.WithProduct {
//查询符合的产品列表
@ -129,21 +104,6 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
}
}
//任意一个不为空
if len(productList) != 0 || len(recommendProductList) != 0 {
for k, v := range productList {
mapProduct[v.Id] = k
}
//合并产品列表
for _, v := range recommendProductList {
//存在则不并入
if _, ok := mapProduct[v.Id]; ok {
continue
}
productList = append(productList, v)
mapProduct[v.Id] = len(productList) - 1
}
productIds := make([]int64,0,len(productList))
for _,product := range productList{
productIds = append(productIds,product.Id)
@ -193,13 +153,11 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
TagList: tagList,
WithProduct: req.WithProduct,
WithRecommendProduct: req.WithRecommendProduct,
ProductList: productList,
MapProductMinPrice: mapProductMinPrice,
MapProductTemplate: mapProductTemplate,
MapProductSizeCount: mapProductSizeCount,
MapTagLevel: mapTagLevel,
MapProduct: mapProduct,
Size: req.Size,
user: user,
}); err != nil {
@ -222,13 +180,11 @@ type sortRecommendProduct struct {
type dealWithTagMenuDataReq struct {
TagList []gmodel.FsTags
WithProduct bool
WithRecommendProduct bool
ProductList []gmodel.FsProduct
MapProductMinPrice map[int64]int64
MapProductTemplate map[int64]struct{}
MapProductSizeCount map[int64]int64
MapTagLevel map[string]*types.TagItem
MapProduct map[int64]int
Size uint32
user gmodel.FsUser
}
@ -237,7 +193,6 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
for _, tagInfo := range req.TagList {
tagTem := types.TagItem{
TagProductList: nil,
TagRecommendProductList: nil,
TypeName: *tagInfo.Title,
TypeId: tagInfo.Id,
Level: *tagInfo.Level,
@ -262,34 +217,6 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
//赋值
tagTem.TagProductList = productListRsp
}
//获取推荐产品列表
if req.WithRecommendProduct && tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" {
//上面解析过,这里就无需判断错误
recommendProductIds, _ := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ","))
//推荐产品的排序
recommendProductIdsSort, err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProductSort, ","))
if err != nil {
logx.Error(err)
return nil
}
if len(recommendProductIds) != len(recommendProductIdsSort) {
return errors.New(fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d", tagInfo.Id))
}
recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{
TagInfo: tagInfo,
ProductList: req.ProductList,
MapProduct: req.MapProduct,
MapProductMinPrice: req.MapProductMinPrice,
MapProductTemplate: req.MapProductTemplate,
MapProductSizeCount: req.MapProductSizeCount,
RecommendProductIds: recommendProductIds,
RecommendProductIdsSort: recommendProductIdsSort,
Size: req.Size,
User: req.user,
})
//赋值
tagTem.TagRecommendProductList = recommendProductListRsp
}
//加入分类
req.MapTagLevel[*tagInfo.LevelPrefix] = &tagTem
}

View File

@ -245,10 +245,9 @@ type GetRecommandProductListRsp struct {
}
type GetTagProductListReq struct {
Cid int64 `form:"cid,optional"` //分类id
Size uint32 `form:"size,optional"` //尺寸
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
WithRecommendProduct bool `form:"with_recommend_product"` //是否携带分类推荐产品
Cid int64 `form:"cid,optional"` //分类id
Size uint32 `form:"size,optional"` //尺寸
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
}
type GetTagProductListRsp struct {
@ -257,16 +256,15 @@ type GetTagProductListRsp struct {
}
type TagItem struct {
TypeName string `json:"type_name"`
TypeId int64 `json:"type_id"`
Description string `json:"description"`
Level int64 `json:"level"`
LevelPrefix string `json:"level_prefix"`
Icon string `json:"icon"`
Sort int64 `json:"sort"`
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
TagRecommendProductList []TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
ChildTagList []*TagItem `json:"child_tag_list"`
TypeName string `json:"type_name"`
TypeId int64 `json:"type_id"`
Description string `json:"description"`
Level int64 `json:"level"`
LevelPrefix string `json:"level_prefix"`
Icon string `json:"icon"`
Sort int64 `json:"sort"`
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
ChildTagList []*TagItem `json:"child_tag_list"`
}
type TagProduct struct {

View File

@ -291,26 +291,24 @@ type GetRecommandProductListRsp {
}
//获取分类产品列表
type GetTagProductListReq {
Cid int64 `form:"cid,optional"` //分类id
Size uint32 `form:"size,optional"` //尺寸
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
WithRecommendProduct bool `form:"with_recommend_product"` //是否携带分类推荐产品
Cid int64 `form:"cid,optional"` //分类id
Size uint32 `form:"size,optional"` //尺寸
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
}
type GetTagProductListRsp {
TotalCategory int `json:"total_category"`
TagList []TagItem `json:"tag_list"`
}
type TagItem {
TypeName string `json:"type_name"`
TypeId int64 `json:"type_id"`
Description string `json:"description"`
Level int64 `json:"level"`
LevelPrefix string `json:"level_prefix"`
Icon string `json:"icon"`
Sort int64 `json:"sort"`
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
TagRecommendProductList []TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
ChildTagList []*TagItem `json:"child_tag_list"`
TypeName string `json:"type_name"`
TypeId int64 `json:"type_id"`
Description string `json:"description"`
Level int64 `json:"level"`
LevelPrefix string `json:"level_prefix"`
Icon string `json:"icon"`
Sort int64 `json:"sort"`
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
ChildTagList []*TagItem `json:"child_tag_list"`
}
type TagProduct {
ProductId int64 `json:"product_id"`