fix
This commit is contained in:
parent
d466364385
commit
f09220cf2d
|
@ -73,7 +73,7 @@ func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (r
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (resp []*FsProduct, err error) {
|
func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (resp []FsProduct, err error) {
|
||||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
@ -74,67 +75,107 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
for _, v := range tagList {
|
for _, v := range tagList {
|
||||||
typeIds = append(typeIds, v.Id)
|
typeIds = append(typeIds, v.Id)
|
||||||
}
|
}
|
||||||
//查询符合的产品列表
|
var (
|
||||||
pIsDel := int64(0)
|
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||||
pStatus := int64(1)
|
recommendProductList []gmodel.FsProduct //tag推荐产品列表(select 字段需要看查询的地方)
|
||||||
pIsShelf := int64(1)
|
mapProduct = make(map[int64]int) //产品map
|
||||||
pReq := gmodel.GetProductListByParamsReq{
|
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
||||||
Type: typeIds,
|
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
||||||
IsDel: &pIsDel,
|
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方)
|
||||||
IsShelf: &pIsShelf,
|
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方)
|
||||||
Status: &pStatus,
|
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||||
OrderBy: "`sort` DESC",
|
mapProductTemplate = make(map[int64]struct{}) //产品模板map
|
||||||
}
|
)
|
||||||
//获取产品列表
|
//携带产品
|
||||||
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, pReq)
|
if req.WithProduct {
|
||||||
if err != nil {
|
//查询符合的产品列表
|
||||||
logx.Error(err)
|
pIsDel := int64(0)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
pStatus := int64(1)
|
||||||
}
|
pIsShelf := int64(1)
|
||||||
//提取产品ids
|
pReq := gmodel.GetProductListByParamsReq{
|
||||||
productIds := make([]int64, 0, len(productList))
|
Type: typeIds,
|
||||||
for _, v := range productList {
|
IsDel: &pIsDel,
|
||||||
productIds = append(productIds, v.Id)
|
IsShelf: &pIsShelf,
|
||||||
}
|
Status: &pStatus,
|
||||||
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
OrderBy: "`sort` DESC",
|
||||||
if err != nil {
|
}
|
||||||
logx.Error(err)
|
//获取产品列表
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
|
productList, err = l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, pReq)
|
||||||
}
|
|
||||||
//存储产品最小价格
|
|
||||||
mapProductMinPrice := make(map[int64]int64)
|
|
||||||
for _, v := range productPriceList {
|
|
||||||
priceStrSlic := strings.Split(v.Price, ",")
|
|
||||||
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||||
}
|
}
|
||||||
if len(priceSlice) == 0 {
|
//提取tag推荐产品
|
||||||
continue
|
allTagRecommendProductIds := make([]int64, 0, len(tagList)*5)
|
||||||
|
for _, v := range tagList {
|
||||||
|
if v.RecommendProduct == nil || *v.RecommendProduct == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sl, err := format.StrSlicToInt64Slice(strings.Split(*v.RecommendProductSort, ","))
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse recommend product ids,id=%d", v.Id))
|
||||||
|
}
|
||||||
|
allTagRecommendProductIds = append(allTagRecommendProductIds, sl...)
|
||||||
|
}
|
||||||
|
//获取推荐的产品列表
|
||||||
|
recommendProductList, err = l.svcCtx.AllModels.FsProduct.FindAllOnlyByIds(l.ctx, allTagRecommendProductIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag recommend products")
|
||||||
|
}
|
||||||
|
//提取产品ids
|
||||||
|
productIds := make([]int64, 0, len(productList))
|
||||||
|
for k, v := range productList {
|
||||||
|
productIds = append(productIds, v.Id)
|
||||||
|
mapProduct[v.Id] = k
|
||||||
|
}
|
||||||
|
//合并产品列表
|
||||||
|
for _, v := range recommendProductList {
|
||||||
|
//存在则不并入
|
||||||
|
if _, ok := mapProduct[v.Id]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
productList = append(productList, v)
|
||||||
|
mapProduct[v.Id] = len(productList) - 1
|
||||||
|
}
|
||||||
|
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
|
||||||
|
}
|
||||||
|
//存储产品最小价格
|
||||||
|
for _, v := range productPriceList {
|
||||||
|
priceStrSlic := strings.Split(v.Price, ",")
|
||||||
|
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||||
|
}
|
||||||
|
if len(priceSlice) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sort.Ints(priceSlice)
|
||||||
|
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||||
|
}
|
||||||
|
//获取模板(只是获取产品product_id)
|
||||||
|
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id")
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
||||||
|
}
|
||||||
|
for _, v := range productTemplatesV2 {
|
||||||
|
mapProductTemplate[*v.ProductId] = struct{}{}
|
||||||
|
}
|
||||||
|
//获取产品尺寸数量
|
||||||
|
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
|
||||||
|
}
|
||||||
|
for _, v := range productSizeCountList {
|
||||||
|
mapProductSizeCount[v.ProductId] = v.Num
|
||||||
}
|
}
|
||||||
sort.Ints(priceSlice)
|
|
||||||
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
|
||||||
}
|
|
||||||
//获取模板(只是获取产品product_id)
|
|
||||||
productTemplatesV2, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id")
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
|
||||||
}
|
|
||||||
mapProductTemplate := make(map[int64]struct{})
|
|
||||||
for _, v := range productTemplatesV2 {
|
|
||||||
mapProductTemplate[*v.ProductId] = struct{}{}
|
|
||||||
}
|
|
||||||
//获取产品尺寸数量
|
|
||||||
productSizeCountList, err := l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
|
||||||
if err != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
|
|
||||||
}
|
|
||||||
mapProductSizeCount := make(map[int64]int64)
|
|
||||||
for _, v := range productSizeCountList {
|
|
||||||
mapProductSizeCount[v.ProductId] = v.Num
|
|
||||||
}
|
}
|
||||||
mapTagLevel := make(map[string]*types.TagItem)
|
mapTagLevel := make(map[string]*types.TagItem)
|
||||||
minLevel := int64(0) //记录最小等级数字
|
minLevel := int64(0) //记录最小等级数字
|
||||||
|
@ -145,6 +186,24 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
if minLevel > *tagInfo.Level {
|
if minLevel > *tagInfo.Level {
|
||||||
minLevel = *tagInfo.Level
|
minLevel = *tagInfo.Level
|
||||||
}
|
}
|
||||||
|
tagTem := types.TagItem{
|
||||||
|
TagProductList: nil,
|
||||||
|
TagRecommendProductList: nil,
|
||||||
|
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),
|
||||||
|
}
|
||||||
|
//不携带产品
|
||||||
|
if !req.WithProduct {
|
||||||
|
//加入分类
|
||||||
|
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||||
|
continue
|
||||||
|
}
|
||||||
//获取分类产品列表
|
//获取分类产品列表
|
||||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||||
TagId: tagInfo.Id,
|
TagId: tagInfo.Id,
|
||||||
|
@ -155,19 +214,12 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
User: user,
|
User: user,
|
||||||
})
|
})
|
||||||
//加入分类
|
tagTem.TagProductList = productListRsp
|
||||||
tagTem := types.TagItem{
|
//获取推荐产品列表
|
||||||
TagProductList: productListRsp,
|
if tagInfo.RecommendProduct != nil && *tagInfo.RecommendProduct != "" {
|
||||||
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
|
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||||
}
|
}
|
||||||
//组装等级从属关系
|
//组装等级从属关系
|
||||||
|
|
|
@ -245,8 +245,9 @@ 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"` //不携带产品只返回菜单
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTagProductListRsp struct {
|
type GetTagProductListRsp struct {
|
||||||
|
@ -255,15 +256,16 @@ type GetTagProductListRsp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagItem struct {
|
type TagItem struct {
|
||||||
TypeName string `json:"type_name"`
|
TypeName string `json:"type_name"`
|
||||||
TypeId int64 `json:"type_id"`
|
TypeId int64 `json:"type_id"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Level int64 `json:"level"`
|
Level int64 `json:"level"`
|
||||||
LevelPrefix string `json:"level_prefix"`
|
LevelPrefix string `json:"level_prefix"`
|
||||||
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"` //分类下的产品
|
||||||
ChildTagList []*TagItem `json:"child_tag_list"`
|
TagRecommendProductList [][]TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
|
||||||
|
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagProduct struct {
|
type TagProduct struct {
|
||||||
|
|
|
@ -291,23 +291,25 @@ 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"` //不携带产品只返回菜单
|
||||||
}
|
}
|
||||||
type GetTagProductListRsp {
|
type GetTagProductListRsp {
|
||||||
TotalCategory int `json:"total_category"`
|
TotalCategory int `json:"total_category"`
|
||||||
TagList []TagItem `json:"tag_list"`
|
TagList []TagItem `json:"tag_list"`
|
||||||
}
|
}
|
||||||
type TagItem {
|
type TagItem {
|
||||||
TypeName string `json:"type_name"`
|
TypeName string `json:"type_name"`
|
||||||
TypeId int64 `json:"type_id"`
|
TypeId int64 `json:"type_id"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Level int64 `json:"level"`
|
Level int64 `json:"level"`
|
||||||
LevelPrefix string `json:"level_prefix"`
|
LevelPrefix string `json:"level_prefix"`
|
||||||
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"` //分类下的产品
|
||||||
ChildTagList []*TagItem `json:"child_tag_list"`
|
TagRecommendProductList [][]TagProduct `json:"tag_recommend_product_list"` //分类推荐产品
|
||||||
|
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||||
}
|
}
|
||||||
type TagProduct {
|
type TagProduct {
|
||||||
ProductId int64 `json:"product_id"`
|
ProductId int64 `json:"product_id"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user