fix
This commit is contained in:
parent
245122d049
commit
bd127a7884
2
go.mod
2
go.mod
@ -74,7 +74,7 @@ require (
|
|||||||
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
|
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
|
||||||
go.uber.org/automaxprocs v1.5.2 // indirect
|
go.uber.org/automaxprocs v1.5.2 // indirect
|
||||||
golang.org/x/net v0.12.0 // indirect
|
golang.org/x/net v0.12.0
|
||||||
golang.org/x/sys v0.10.0 // indirect
|
golang.org/x/sys v0.10.0 // indirect
|
||||||
golang.org/x/text v0.11.0
|
golang.org/x/text v0.11.0
|
||||||
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
|
||||||
|
@ -177,6 +177,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
mapProductSizeCount[v.ProductId] = v.Num
|
mapProductSizeCount[v.ProductId] = v.Num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//map tag菜单
|
||||||
mapTagLevel := make(map[string]*types.TagItem)
|
mapTagLevel := make(map[string]*types.TagItem)
|
||||||
minLevel := int64(0) //记录最小等级数字
|
minLevel := int64(0) //记录最小等级数字
|
||||||
for _, tagInfo := range tagList {
|
for _, tagInfo := range tagList {
|
||||||
@ -214,10 +215,35 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
User: user,
|
User: user,
|
||||||
})
|
})
|
||||||
|
//赋值
|
||||||
tagTem.TagProductList = productListRsp
|
tagTem.TagProductList = productListRsp
|
||||||
//获取推荐产品列表
|
//获取推荐产品列表
|
||||||
if tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" {
|
if tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" {
|
||||||
|
//上面解析过,这里就无需判断错误
|
||||||
|
recommendProductIds, _ := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct, ","))
|
||||||
|
//推荐产品的排序
|
||||||
|
recommendProductIdsSort, err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProductSort, ","))
|
||||||
|
if err != nil{
|
||||||
|
logx.Error(err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
recommendProductListRsp := l.getTagRecommendProducts(getTagRecommendProductsReq{
|
||||||
|
TagInfo: tagInfo,
|
||||||
|
ProductList: productList,
|
||||||
|
MapProduct: mapProduct,
|
||||||
|
MapProductMinPrice: mapProductMinPrice,
|
||||||
|
MapProductTemplate: mapProductTemplate,
|
||||||
|
MapProductSizeCount: mapProductSizeCount,
|
||||||
|
RecommendProductIds: recommendProductIds,
|
||||||
|
RecommendProductIdsSort: recommendProductIdsSort,
|
||||||
|
Size: req.Size,
|
||||||
|
User: user,
|
||||||
|
})
|
||||||
|
//赋值
|
||||||
|
tagTem.TagRecommendProductList = recommendProductListRsp
|
||||||
}
|
}
|
||||||
//加入分类
|
//加入分类
|
||||||
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||||
@ -235,7 +261,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
if parent, ok := mapTagLevel[parentPrefix]; ok {
|
if parent, ok := mapTagLevel[parentPrefix]; ok {
|
||||||
parent.ChildTagList = append(parent.ChildTagList, tagItem)
|
parent.ChildTagList = append(parent.ChildTagList, tagItem)
|
||||||
//排序
|
//排序
|
||||||
sort.Slice(parent.ChildTagList, func(i, j int) bool {
|
sort.SliceStable(parent.ChildTagList, func(i, j int) bool {
|
||||||
return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort
|
return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort
|
||||||
})
|
})
|
||||||
mapTagLevel[parentPrefix] = parent
|
mapTagLevel[parentPrefix] = parent
|
||||||
@ -250,7 +276,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
tagListRsp = append(tagListRsp, *v)
|
tagListRsp = append(tagListRsp, *v)
|
||||||
}
|
}
|
||||||
//排序
|
//排序
|
||||||
sort.Slice(tagListRsp, func(i, j int) bool {
|
sort.SliceStable(tagListRsp, func(i, j int) bool {
|
||||||
return tagListRsp[i].Sort < tagListRsp[j].Sort
|
return tagListRsp[i].Sort < tagListRsp[j].Sort
|
||||||
})
|
})
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||||
@ -258,7 +284,86 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
TagList: tagListRsp,
|
TagList: tagListRsp,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
//排序推荐产品结构体
|
||||||
|
type sortRecommendProduct struct {
|
||||||
|
ProductId int64
|
||||||
|
Sort int64
|
||||||
|
}
|
||||||
|
//获取tag推荐产品列表
|
||||||
|
type getTagRecommendProductsReq struct {
|
||||||
|
TagInfo gmodel.FsTags
|
||||||
|
ProductList []gmodel.FsProduct
|
||||||
|
MapProduct map[int64]int
|
||||||
|
MapProductMinPrice map[int64]int64
|
||||||
|
MapProductTemplate map[int64]struct{}
|
||||||
|
MapProductSizeCount map[int64]int64
|
||||||
|
RecommendProductIds []int64
|
||||||
|
RecommendProductIdsSort []int64
|
||||||
|
Size uint32
|
||||||
|
User gmodel.FsUser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetTagProductListLogic)getTagRecommendProducts(req getTagRecommendProductsReq)(productListRsp []types.TagProduct){
|
||||||
|
//排序
|
||||||
|
sortList := make([]sortRecommendProduct,0,len(req.RecommendProductIds))
|
||||||
|
for sortIndex,pid := range req.RecommendProductIds{
|
||||||
|
sortList = append(sortList,sortRecommendProduct{
|
||||||
|
ProductId: pid,
|
||||||
|
Sort: req.RecommendProductIdsSort[sortIndex],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
sort.SliceStable(sortList, func(i, j int) bool {
|
||||||
|
return sortList[i].Sort < sortList[j].Sort
|
||||||
|
})
|
||||||
|
productListRsp = make([]types.TagProduct,0,len(sortList))
|
||||||
|
for _,sortVal := range sortList{
|
||||||
|
productIndex,ok := req.MapProduct[sortVal.ProductId]
|
||||||
|
if !ok{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
productInfo := req.ProductList[productIndex]
|
||||||
|
minPrice, ok := req.MapProductMinPrice[productInfo.Id]
|
||||||
|
_, tmpOk := req.MapProductTemplate[productInfo.Id]
|
||||||
|
//无最小价格则不显示 || 没有模板也不显示
|
||||||
|
if !ok || !tmpOk {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sizeNum := int64(0)
|
||||||
|
if mapSizeNum, ok := req.MapProductSizeCount[productInfo.Id]; ok {
|
||||||
|
sizeNum = mapSizeNum
|
||||||
|
}
|
||||||
|
item := types.TagProduct{
|
||||||
|
ProductId: productInfo.Id,
|
||||||
|
Sn: *productInfo.Sn,
|
||||||
|
Title: *productInfo.Title,
|
||||||
|
Intro: *productInfo.Intro,
|
||||||
|
IsEnv: *productInfo.IsProtection,
|
||||||
|
IsMicro: *productInfo.IsMicrowave,
|
||||||
|
SizeNum: uint32(sizeNum),
|
||||||
|
MiniPrice: minPrice,
|
||||||
|
}
|
||||||
|
//千人千面处理
|
||||||
|
r := image.ThousandFaceImageFormatReq{
|
||||||
|
Size: int(req.Size),
|
||||||
|
IsThousandFace: 0,
|
||||||
|
Cover: *productInfo.Cover,
|
||||||
|
CoverImg: *productInfo.CoverImg,
|
||||||
|
CoverDefault: *productInfo.CoverImg,
|
||||||
|
ProductId: productInfo.Id,
|
||||||
|
UserId: req.User.Id,
|
||||||
|
}
|
||||||
|
if req.User.Id != 0 {
|
||||||
|
r.IsThousandFace = int(*req.User.IsThousandFace)
|
||||||
|
}
|
||||||
|
image.ThousandFaceImageFormat(&r)
|
||||||
|
item.Cover = r.Cover
|
||||||
|
item.CoverImg = r.CoverImg
|
||||||
|
item.CoverDefault = r.CoverDefault
|
||||||
|
//加入切片
|
||||||
|
productListRsp = append(productListRsp,item)
|
||||||
|
}
|
||||||
|
return productListRsp
|
||||||
|
}
|
||||||
// 获取对应tag的产品列表
|
// 获取对应tag的产品列表
|
||||||
type getTagProductsReq struct {
|
type getTagProductsReq struct {
|
||||||
TagId int64
|
TagId int64
|
||||||
|
@ -264,7 +264,7 @@ type TagItem struct {
|
|||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
Sort int64 `json:"sort"`
|
Sort int64 `json:"sort"`
|
||||||
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
|
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
|
||||||
TagRecommendProductList [][]TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
|
TagRecommendProductList []TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
|
||||||
ChildTagList []*TagItem `json:"child_tag_list"`
|
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ type TagItem {
|
|||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
Sort int64 `json:"sort"`
|
Sort int64 `json:"sort"`
|
||||||
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
|
TagProductList []TagProduct `json:"tag_product_list"` //分类下的产品
|
||||||
TagRecommendProductList [][]TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
|
TagRecommendProductList []TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
|
||||||
ChildTagList []*TagItem `json:"child_tag_list"`
|
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||||
}
|
}
|
||||||
type TagProduct {
|
type TagProduct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user