fix
This commit is contained in:
parent
20a7149eb6
commit
e24fc4825c
@ -186,7 +186,46 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
}
|
}
|
||||||
//map tag菜单
|
//map tag菜单
|
||||||
mapTagLevel := make(map[string]*types.TagItem)
|
mapTagLevel := make(map[string]*types.TagItem)
|
||||||
for _, tagInfo := range tagList {
|
//处理tags数据
|
||||||
|
l.delWithTagMenuData(delWithTagMenuDataReq{
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||||
|
TotalCategory: len(mapTagLevel),
|
||||||
|
TagList: l.organizationLevelRelation(mapTagLevel),//组装等级从属关系
|
||||||
|
})
|
||||||
|
}
|
||||||
|
//排序推荐产品结构体
|
||||||
|
type sortRecommendProduct struct {
|
||||||
|
ProductId int64
|
||||||
|
Sort int64
|
||||||
|
}
|
||||||
|
//处理tag菜单数据
|
||||||
|
type delWithTagMenuDataReq 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
|
||||||
|
}
|
||||||
|
func (l *GetTagProductListLogic)delWithTagMenuData(req delWithTagMenuDataReq)error{
|
||||||
|
for _, tagInfo := range req.TagList {
|
||||||
tagTem := types.TagItem{
|
tagTem := types.TagItem{
|
||||||
TagProductList: nil,
|
TagProductList: nil,
|
||||||
TagRecommendProductList: nil,
|
TagRecommendProductList: nil,
|
||||||
@ -197,19 +236,19 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
Icon: *tagInfo.Icon,
|
Icon: *tagInfo.Icon,
|
||||||
Sort: *tagInfo.Sort,
|
Sort: *tagInfo.Sort,
|
||||||
Description: *tagInfo.Description,
|
Description: *tagInfo.Description,
|
||||||
ChildTagList: make([]*types.TagItem, 0, 100),
|
ChildTagList: make([]*types.TagItem, 0, 50),
|
||||||
}
|
}
|
||||||
//携带产品
|
//携带产品
|
||||||
if req.WithProduct {
|
if req.WithProduct {
|
||||||
//获取分类产品列表
|
//获取分类产品列表
|
||||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||||
TagId: tagInfo.Id,
|
TagId: tagInfo.Id,
|
||||||
ProductList: productList,
|
ProductList: req.ProductList,
|
||||||
MapProductMinPrice: mapProductMinPrice,
|
MapProductMinPrice: req.MapProductMinPrice,
|
||||||
MapProductTemplate: mapProductTemplate,
|
MapProductTemplate: req.MapProductTemplate,
|
||||||
MapProductSizeCount: mapProductSizeCount,
|
MapProductSizeCount: req.MapProductSizeCount,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
User: user,
|
User: req.user,
|
||||||
})
|
})
|
||||||
//赋值
|
//赋值
|
||||||
tagTem.TagProductList = productListRsp
|
tagTem.TagProductList = productListRsp
|
||||||
@ -225,35 +264,27 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if len(recommendProductIds) != len(recommendProductIdsSort){
|
if len(recommendProductIds) != len(recommendProductIdsSort){
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr,fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d",tagInfo.Id))
|
return errors.New(fmt.Sprintf("length of recommend product id is neq length of recommend sort,id= %d",tagInfo.Id))
|
||||||
}
|
}
|
||||||
recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{
|
recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{
|
||||||
TagInfo: tagInfo,
|
TagInfo: tagInfo,
|
||||||
ProductList: productList,
|
ProductList: req.ProductList,
|
||||||
MapProduct: mapProduct,
|
MapProduct: req.MapProduct,
|
||||||
MapProductMinPrice: mapProductMinPrice,
|
MapProductMinPrice: req.MapProductMinPrice,
|
||||||
MapProductTemplate: mapProductTemplate,
|
MapProductTemplate: req.MapProductTemplate,
|
||||||
MapProductSizeCount: mapProductSizeCount,
|
MapProductSizeCount: req.MapProductSizeCount,
|
||||||
RecommendProductIds: recommendProductIds,
|
RecommendProductIds: recommendProductIds,
|
||||||
RecommendProductIdsSort: recommendProductIdsSort,
|
RecommendProductIdsSort: recommendProductIdsSort,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
User: user,
|
User: req.user,
|
||||||
})
|
})
|
||||||
//赋值
|
//赋值
|
||||||
tagTem.TagRecommendProductList = recommendProductListRsp
|
tagTem.TagRecommendProductList = recommendProductListRsp
|
||||||
}
|
}
|
||||||
//加入分类
|
//加入分类
|
||||||
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
req.MapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
return nil
|
||||||
TotalCategory: len(mapTagLevel),
|
|
||||||
TagList: l.organizationLevelRelation(mapTagLevel),//组装等级从属关系
|
|
||||||
})
|
|
||||||
}
|
|
||||||
//排序推荐产品结构体
|
|
||||||
type sortRecommendProduct struct {
|
|
||||||
ProductId int64
|
|
||||||
Sort int64
|
|
||||||
}
|
}
|
||||||
//组织等级从属关系
|
//组织等级从属关系
|
||||||
func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string]*types.TagItem)[]types.TagItem{
|
func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string]*types.TagItem)[]types.TagItem{
|
||||||
@ -267,14 +298,16 @@ func (l *GetTagProductListLogic)organizationLevelRelation(mapTagLevel map[string
|
|||||||
prefixSlice := strings.Split(prefix, "/")
|
prefixSlice := strings.Split(prefix, "/")
|
||||||
//有父级
|
//有父级
|
||||||
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
|
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
|
||||||
if parent, ok := mapTagLevel[parentPrefix]; ok {
|
parent, ok := mapTagLevel[parentPrefix]
|
||||||
parent.ChildTagList = append(parent.ChildTagList, tagItem)
|
if !ok{
|
||||||
//排序
|
continue
|
||||||
sort.SliceStable(parent.ChildTagList, func(i, j int) bool {
|
|
||||||
return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort
|
|
||||||
})
|
|
||||||
mapTagLevel[parentPrefix] = parent
|
|
||||||
}
|
}
|
||||||
|
parent.ChildTagList = append(parent.ChildTagList, tagItem)
|
||||||
|
//排序
|
||||||
|
sort.SliceStable(parent.ChildTagList, func(i, j int) bool {
|
||||||
|
return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort
|
||||||
|
})
|
||||||
|
mapTagLevel[parentPrefix] = parent
|
||||||
}
|
}
|
||||||
//最终值提取最高级别那一层出来
|
//最终值提取最高级别那一层出来
|
||||||
rspList := make([]types.TagItem, 0, len(mapTagLevel))
|
rspList := make([]types.TagItem, 0, len(mapTagLevel))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user