fix
This commit is contained in:
parent
efde0005f9
commit
0b5270f3b7
|
@ -173,6 +173,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
//map tag菜单
|
//map tag菜单
|
||||||
mapTagLevel := make(map[string]*types.TagItem)
|
mapTagLevel := make(map[string]*types.TagItem)
|
||||||
//处理tags数据
|
//处理tags数据
|
||||||
|
minLevel := 0 //层级最高层(即prefix层级路径最短)
|
||||||
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
|
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
|
||||||
TagList: tagList,
|
TagList: tagList,
|
||||||
WithProduct: req.WithProduct,
|
WithProduct: req.WithProduct,
|
||||||
|
@ -183,23 +184,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
MapTagLevel: mapTagLevel,
|
MapTagLevel: mapTagLevel,
|
||||||
MapProductHaveOptionFitting: mapProductHaveOptionFitting,
|
MapProductHaveOptionFitting: mapProductHaveOptionFitting,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
user: user,
|
User: user,
|
||||||
|
MinLevel: &minLevel,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
|
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||||
TotalCategoryProduct: len(productList),
|
TotalCategoryProduct: len(productList),
|
||||||
TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系
|
TagList: l.organizationLevelRelation(minLevel, mapTagLevel), //组装等级从属关系
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 排序推荐产品结构体
|
|
||||||
type sortRecommendProduct struct {
|
|
||||||
ProductId int64
|
|
||||||
Sort int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理tag菜单数据
|
// 处理tag菜单数据
|
||||||
type dealWithTagMenuDataReq struct {
|
type dealWithTagMenuDataReq struct {
|
||||||
TagList []gmodel.FsTags
|
TagList []gmodel.FsTags
|
||||||
|
@ -211,11 +207,17 @@ type dealWithTagMenuDataReq struct {
|
||||||
MapTagLevel map[string]*types.TagItem
|
MapTagLevel map[string]*types.TagItem
|
||||||
MapProductHaveOptionFitting map[int64]struct{}
|
MapProductHaveOptionFitting map[int64]struct{}
|
||||||
Size uint32
|
Size uint32
|
||||||
user gmodel.FsUser
|
User gmodel.FsUser
|
||||||
|
MinLevel *int //层级最小的
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error {
|
func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error {
|
||||||
for _, tagInfo := range req.TagList {
|
for _, tagInfo := range req.TagList {
|
||||||
|
prefixSlice := strings.Split(*tagInfo.LevelPrefix, "/")
|
||||||
|
lenLevel := len(prefixSlice)
|
||||||
|
if *req.MinLevel > lenLevel || *req.MinLevel == 0 {
|
||||||
|
*req.MinLevel = lenLevel
|
||||||
|
}
|
||||||
tagTem := types.TagItem{
|
tagTem := types.TagItem{
|
||||||
TagProductList: nil,
|
TagProductList: nil,
|
||||||
TypeName: *tagInfo.Title,
|
TypeName: *tagInfo.Title,
|
||||||
|
@ -238,7 +240,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
||||||
MapProductSizeCount: req.MapProductSizeCount,
|
MapProductSizeCount: req.MapProductSizeCount,
|
||||||
MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
|
MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
User: req.user,
|
User: req.User,
|
||||||
})
|
})
|
||||||
//赋值
|
//赋值
|
||||||
tagTem.TagProductList = productListRsp
|
tagTem.TagProductList = productListRsp
|
||||||
|
@ -250,15 +252,15 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组织等级从属关系
|
// 组织等级从属关系
|
||||||
func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[string]*types.TagItem) []types.TagItem {
|
func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagLevel map[string]*types.TagItem) []types.TagItem {
|
||||||
mapTop := make(map[string]struct{})
|
mapTop := make(map[string]struct{})
|
||||||
for prefix, tagItem := range mapTagLevel {
|
for prefix, tagItem := range mapTagLevel {
|
||||||
//最上级没有父级
|
prefixSlice := strings.Split(prefix, "/")
|
||||||
if !strings.Contains(prefix, "/") {
|
//存储最高等级
|
||||||
|
if len(prefixSlice) == minLevel {
|
||||||
mapTop[prefix] = struct{}{}
|
mapTop[prefix] = struct{}{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
prefixSlice := strings.Split(prefix, "/")
|
|
||||||
//有父级
|
//有父级
|
||||||
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
|
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
|
||||||
parent, ok := mapTagLevel[parentPrefix]
|
parent, ok := mapTagLevel[parentPrefix]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user