This commit is contained in:
laodaming 2023-07-20 15:27:17 +08:00
parent 9ff4468778
commit bf3d9f9631
4 changed files with 50 additions and 5 deletions

View File

@ -4,8 +4,11 @@ import (
"errors"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"gorm.io/gorm"
"sort"
"strings"
"context"
@ -51,13 +54,13 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
//需要填充时需要忽略的id
ignoreProductIds := make([]int64, 0, len(recommendList)+1)
ignoreProductIds = append(ignoreProductIds, productInfo.Id)
recommendProductIds := make([]int64, 0, len(recommendList))
productIds := make([]int64, 0, len(recommendList))
for _, v := range recommendList {
ignoreProductIds = append(ignoreProductIds, *v.ProductId)
recommendProductIds = append(recommendProductIds, *v.ProductId)
productIds = append(productIds, *v.ProductId)
}
//获取推荐产品列表
recommendProductList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "")
recommendProductList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "")
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeDbSqlErr, "failed to get recommend product list")
@ -77,7 +80,36 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
}
//合并列表
recommendProductList = append(recommendProductList, productList...)
for _, v := range productList {
productIds = append(productIds, v.Id)
recommendProductList = append(recommendProductList, v)
}
}
//查询产品价格
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, productIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list")
}
mapProductMinPrice := make(map[int64]int64)
for _, v := range priceList {
if v.StepPrice == nil || *v.StepPrice == "" {
continue
}
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*v.StepPrice, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse step price")
}
//正序排序
sort.Ints(stepPriceSlice)
if min, ok := mapProductMinPrice[*v.ProductId]; ok {
if min > int64(stepPriceSlice[0]) {
mapProductMinPrice[*v.ProductId] = int64(stepPriceSlice[0])
}
} else {
mapProductMinPrice[*v.ProductId] = int64(stepPriceSlice[0])
}
}
//获取用户信息(不用判断存在)
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
@ -105,6 +137,10 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
if _, ok := mapRecommend[v.Id]; ok {
isRecommend = 1
}
minPrice := int64(0)
if minVal, ok := mapProductMinPrice[v.Id]; ok {
minPrice = minVal
}
list = append(list, types.GetRecommandProductListRsp{
Id: v.Id,
Sn: *v.Sn,
@ -115,6 +151,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
CoverDefault: r.CoverDefault,
Intro: *v.Intro,
IsRecommend: isRecommend,
MinPrice: minPrice,
})
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)

View File

@ -143,8 +143,14 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
continue
}
sort.Ints(priceSlice)
if min, ok := mapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) {
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
} else {
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
}
//获取模板(只是获取产品product_id)
productTemplatesV2, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "product_id")
if err != nil {

View File

@ -243,6 +243,7 @@ type GetRecommandProductListRsp struct {
CoverDefault string `json:"cover_default"`
Intro string `json:"intro"`
IsRecommend int64 `json:"is_recommend"`
MinPrice int64 `json:"min_price"`
}
type GetTagProductListReq struct {

View File

@ -292,6 +292,7 @@ type GetRecommandProductListRsp {
CoverDefault string `json:"cover_default"`
Intro string `json:"intro"`
IsRecommend int64 `json:"is_recommend"`
MinPrice int64 `json:"min_price"`
}
//获取分类产品列表
type GetTagProductListReq {