This commit is contained in:
laodaming 2023-07-21 16:14:42 +08:00
parent efde0005f9
commit 0b5270f3b7

View File

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