This commit is contained in:
laodaming
2023-07-14 14:38:34 +08:00
parent 56a8b32d90
commit 86a2deacfb
3 changed files with 71 additions and 55 deletions

View File

@@ -1,11 +1,13 @@
package logic
import (
"errors"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"gorm.io/gorm"
"sort"
"strings"
@@ -37,20 +39,28 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
req.Size = image.GetCurrentSize(req.Size)
}
//查询用户信息(不用判断存在)
/*user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
}*/
}
//查询分类列表
tStatus := int64(1)
tReq := gmodel.GetAllTagByParamsReq{
Status: &tStatus,
OrderBy: "`sort` DESC",
Status: &tStatus,
OrderBy: "`sort` DESC",
WithChild: true, //需要子集
}
//传入分类id
if req.Cid > 0 {
tReq.Ids = []int64{req.Cid}
//获取该类行的levelprefix
tagData, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, req.Cid)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found")
}
}
tReq.LevelPrefixLeftLike = *tagData.LevelPrefix
}
tagList, err := l.svcCtx.AllModels.FsTags.GetAllTagByParams(l.ctx, tReq)
if err != nil {
@@ -81,12 +91,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
}
productLen := len(productList)
if productLen == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success")
}
//提取产品ids
productIds := make([]int64, 0, productLen)
productIds := make([]int64, 0, len(productList))
for _, v := range productList {
productIds = append(productIds, v.Id)
}
@@ -140,7 +146,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
minLevel = *tagInfo.Level
}
//获取分类产品列表
/*productListRsp := l.getTagProducts(getTagProductsReq{
productListRsp := l.getTagProducts(getTagProductsReq{
TagId: tagInfo.Id,
ProductList: productList,
MapProductMinPrice: mapProductMinPrice,
@@ -148,18 +154,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
MapProductSizeCount: mapProductSizeCount,
Size: req.Size,
User: user,
})*/
})
//加入分类
tagTem := types.TagItem{
//TagProductList: productListRsp,
TypeName: *tagInfo.Title,
TypeId: tagInfo.Id,
Level: *tagInfo.Level,
LevelPrefix: *tagInfo.LevelPrefix,
Icon: *tagInfo.Icon,
Sort: *tagInfo.Sort,
Description: *tagInfo.Description,
ChildTagList: make([]*types.TagItem, 0, 100),
TagProductList: productListRsp,
TypeName: *tagInfo.Title,
TypeId: tagInfo.Id,
Level: *tagInfo.Level,
LevelPrefix: *tagInfo.LevelPrefix,
Icon: *tagInfo.Icon,
Sort: *tagInfo.Sort,
Description: *tagInfo.Description,
ChildTagList: make([]*types.TagItem, 0, 100),
}
//当前tag保存入map
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem