|
|
|
|
@@ -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)
|
|
|
|
|
|