fix
This commit is contained in:
parent
bd127a7884
commit
db15103c93
|
@ -86,25 +86,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||||
mapProductTemplate = make(map[int64]struct{}) //产品模板map
|
mapProductTemplate = make(map[int64]struct{}) //产品模板map
|
||||||
)
|
)
|
||||||
//携带产品
|
//携带推荐产品
|
||||||
if req.WithProduct {
|
if req.WithRecommendProduct{
|
||||||
//查询符合的产品列表
|
|
||||||
pIsDel := int64(0)
|
|
||||||
pStatus := int64(1)
|
|
||||||
pIsShelf := int64(1)
|
|
||||||
pReq := gmodel.GetProductListByParamsReq{
|
|
||||||
Type: typeIds,
|
|
||||||
IsDel: &pIsDel,
|
|
||||||
IsShelf: &pIsShelf,
|
|
||||||
Status: &pStatus,
|
|
||||||
OrderBy: "`sort` DESC",
|
|
||||||
}
|
|
||||||
//获取产品列表
|
|
||||||
productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, pReq)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
|
||||||
}
|
|
||||||
//提取tag推荐产品
|
//提取tag推荐产品
|
||||||
allTagRecommendProductIds := make([]int64, 0, len(tagList)*5)
|
allTagRecommendProductIds := make([]int64, 0, len(tagList)*5)
|
||||||
for _, v := range tagList {
|
for _, v := range tagList {
|
||||||
|
@ -124,6 +107,29 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag recommend products")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag recommend products")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//携带产品
|
||||||
|
if req.WithProduct {
|
||||||
|
//查询符合的产品列表
|
||||||
|
pIsDel := int64(0)
|
||||||
|
pStatus := int64(1)
|
||||||
|
pIsShelf := int64(1)
|
||||||
|
pReq := gmodel.GetProductListByParamsReq{
|
||||||
|
Type: typeIds,
|
||||||
|
IsDel: &pIsDel,
|
||||||
|
IsShelf: &pIsShelf,
|
||||||
|
Status: &pStatus,
|
||||||
|
OrderBy: "`sort` DESC",
|
||||||
|
}
|
||||||
|
//获取产品列表
|
||||||
|
productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, pReq)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//任意一个不为空
|
||||||
|
if len(productList) != 0 || len(recommendProductList) != 0{
|
||||||
//提取产品ids
|
//提取产品ids
|
||||||
productIds := make([]int64, 0, len(productList))
|
productIds := make([]int64, 0, len(productList))
|
||||||
for k, v := range productList {
|
for k, v := range productList {
|
||||||
|
@ -199,26 +205,23 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
Description: *tagInfo.Description,
|
Description: *tagInfo.Description,
|
||||||
ChildTagList: make([]*types.TagItem, 0, 100),
|
ChildTagList: make([]*types.TagItem, 0, 100),
|
||||||
}
|
}
|
||||||
//不携带产品
|
//携带产品
|
||||||
if !req.WithProduct {
|
if req.WithProduct {
|
||||||
//加入分类
|
//获取分类产品列表
|
||||||
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||||
continue
|
TagId: tagInfo.Id,
|
||||||
|
ProductList: productList,
|
||||||
|
MapProductMinPrice: mapProductMinPrice,
|
||||||
|
MapProductTemplate: mapProductTemplate,
|
||||||
|
MapProductSizeCount: mapProductSizeCount,
|
||||||
|
Size: req.Size,
|
||||||
|
User: user,
|
||||||
|
})
|
||||||
|
//赋值
|
||||||
|
tagTem.TagProductList = productListRsp
|
||||||
}
|
}
|
||||||
//获取分类产品列表
|
|
||||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
|
||||||
TagId: tagInfo.Id,
|
|
||||||
ProductList: productList,
|
|
||||||
MapProductMinPrice: mapProductMinPrice,
|
|
||||||
MapProductTemplate: mapProductTemplate,
|
|
||||||
MapProductSizeCount: mapProductSizeCount,
|
|
||||||
Size: req.Size,
|
|
||||||
User: user,
|
|
||||||
})
|
|
||||||
//赋值
|
|
||||||
tagTem.TagProductList = productListRsp
|
|
||||||
//获取推荐产品列表
|
//获取推荐产品列表
|
||||||
if tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" {
|
if req.WithRecommendProduct && tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" {
|
||||||
//上面解析过,这里就无需判断错误
|
//上面解析过,这里就无需判断错误
|
||||||
recommendProductIds, _ := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ","))
|
recommendProductIds, _ := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ","))
|
||||||
//推荐产品的排序
|
//推荐产品的排序
|
||||||
|
@ -249,10 +252,24 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||||
}
|
}
|
||||||
//组装等级从属关系
|
//组装等级从属关系
|
||||||
|
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||||
|
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{
|
||||||
|
mapTop := make(map[string]struct{})
|
||||||
for prefix, tagItem := range mapTagLevel {
|
for prefix, tagItem := range mapTagLevel {
|
||||||
prefix = strings.Trim(prefix, " ")
|
|
||||||
//最上级没有父级
|
//最上级没有父级
|
||||||
if !strings.Contains(prefix, "/") {
|
if !strings.Contains(prefix, "/") {
|
||||||
|
mapTop[prefix] = struct{}{}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
prefixSlice := strings.Split(prefix, "/")
|
prefixSlice := strings.Split(prefix, "/")
|
||||||
|
@ -268,26 +285,15 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//最终值提取最高级别那一层出来
|
//最终值提取最高级别那一层出来
|
||||||
tagListRsp := make([]types.TagItem, 0, len(mapTagLevel))
|
rspList := make([]types.TagItem, 0, len(mapTagLevel))
|
||||||
for _, v := range mapTagLevel {
|
for prefix, _ := range mapTop {
|
||||||
if v.Level != minLevel {
|
rspList = append(rspList,*mapTagLevel[prefix])
|
||||||
continue
|
|
||||||
}
|
|
||||||
tagListRsp = append(tagListRsp, *v)
|
|
||||||
}
|
}
|
||||||
//排序
|
//排序
|
||||||
sort.SliceStable(tagListRsp, func(i, j int) bool {
|
sort.SliceStable(rspList, func(i, j int) bool {
|
||||||
return tagListRsp[i].Sort < tagListRsp[j].Sort
|
return rspList[i].Sort < rspList[j].Sort
|
||||||
})
|
})
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
return rspList
|
||||||
TotalCategory: len(mapTagLevel),
|
|
||||||
TagList: tagListRsp,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
//排序推荐产品结构体
|
|
||||||
type sortRecommendProduct struct {
|
|
||||||
ProductId int64
|
|
||||||
Sort int64
|
|
||||||
}
|
}
|
||||||
//获取tag推荐产品列表
|
//获取tag推荐产品列表
|
||||||
type getTagRecommendProductsReq struct {
|
type getTagRecommendProductsReq struct {
|
||||||
|
|
|
@ -245,9 +245,10 @@ type GetRecommandProductListRsp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTagProductListReq struct {
|
type GetTagProductListReq struct {
|
||||||
Cid int64 `form:"cid,optional"` //分类id
|
Cid int64 `form:"cid,optional"` //分类id
|
||||||
Size uint32 `form:"size,optional"` //尺寸
|
Size uint32 `form:"size,optional"` //尺寸
|
||||||
WithProduct bool `form:"with_product,optional"` //不携带产品只返回菜单
|
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
|
||||||
|
WithRecommendProduct bool `form:"with_recommend_product"` //是否携带分类推荐产品
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTagProductListRsp struct {
|
type GetTagProductListRsp struct {
|
||||||
|
|
|
@ -291,9 +291,10 @@ type GetRecommandProductListRsp {
|
||||||
}
|
}
|
||||||
//获取分类产品列表
|
//获取分类产品列表
|
||||||
type GetTagProductListReq {
|
type GetTagProductListReq {
|
||||||
Cid int64 `form:"cid,optional"` //分类id
|
Cid int64 `form:"cid,optional"` //分类id
|
||||||
Size uint32 `form:"size,optional"` //尺寸
|
Size uint32 `form:"size,optional"` //尺寸
|
||||||
WithProduct bool `form:"with_product,optional"` //不携带产品只返回菜单
|
WithProduct bool `form:"with_product,optional"` //是否携带分类下的产品
|
||||||
|
WithRecommendProduct bool `form:"with_recommend_product"` //是否携带分类推荐产品
|
||||||
}
|
}
|
||||||
type GetTagProductListRsp {
|
type GetTagProductListRsp {
|
||||||
TotalCategory int `json:"total_category"`
|
TotalCategory int `json:"total_category"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user