fix
This commit is contained in:
parent
2f5ce8dd77
commit
0e752e31fd
|
@ -18,7 +18,7 @@ func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProduc
|
|||
Table("fs_product_recommend as r").
|
||||
Joins("inner join fs_product as p on r.product_id = p.id").
|
||||
Where("r.status = ? ", 1).
|
||||
Where("and p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1)
|
||||
Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1)
|
||||
if req.Category != 0 {
|
||||
db = db.Where("r.category = ?", req.Category)
|
||||
}
|
||||
|
@ -29,10 +29,14 @@ func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProduc
|
|||
err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error
|
||||
return resp, total, err
|
||||
}
|
||||
func (r *FsProductRecommendModel) GetIgnoreRandomRecommendProductList(ctx context.Context, limit int, category int64, idNotInt []int64) (resp []FsProductRecommend, err error) {
|
||||
err = r.db.WithContext(ctx).Model(&FsProductRecommend{}).
|
||||
Where("`product_id` not in(?) and `category` = ? and `status` = ?", idNotInt, category, 1).
|
||||
Order("RAND()").Limit(limit).Find(&resp).Error
|
||||
func (r *FsProductRecommendModel) GetIgnoreRandomRecommendProductList(ctx context.Context, limit int, category int64, idNotInt []int64) (resp []FsProduct, err error) {
|
||||
err = r.db.WithContext(ctx).Debug().Select("p.*").
|
||||
Table("fs_product_recommend as r").
|
||||
Joins("inner join fs_product as p on r.product_id = p.id").
|
||||
Where("r.product_id not in (?)", idNotInt).
|
||||
Where("r.status = ? ", 1).
|
||||
Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1).
|
||||
Where("r.category = ?", category).Order("RAND()").Limit(limit).Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, category int64, data *FsProductRecommend) error {
|
||||
|
|
|
@ -47,24 +47,18 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
|||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get detail product info")
|
||||
}
|
||||
//随机取产品列表(不包含详情产品)
|
||||
recommendList, err := l.svcCtx.AllModels.FsProductRecommend.GetIgnoreRandomRecommendProductList(l.ctx, int(req.Num), int64(constants.PRODUCT_DETAIL_RECOMMEND_CATEGORY), []int64{productInfo.Id})
|
||||
recommendProductList, err := l.svcCtx.AllModels.FsProductRecommend.GetIgnoreRandomRecommendProductList(l.ctx, int(req.Num), int64(constants.PRODUCT_DETAIL_RECOMMEND_CATEGORY), []int64{productInfo.Id})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend list")
|
||||
}
|
||||
//需要填充时需要忽略的id
|
||||
ignoreProductIds := make([]int64, 0, len(recommendList)+1)
|
||||
ignoreProductIds := make([]int64, 0, len(recommendProductList)+1)
|
||||
ignoreProductIds = append(ignoreProductIds, productInfo.Id)
|
||||
productIds := make([]int64, 0, len(recommendList))
|
||||
for _, v := range recommendList {
|
||||
ignoreProductIds = append(ignoreProductIds, *v.ProductId)
|
||||
productIds = append(productIds, *v.ProductId)
|
||||
}
|
||||
//获取推荐产品列表
|
||||
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")
|
||||
productIds := make([]int64, 0, len(recommendProductList))
|
||||
for _, v := range recommendProductList {
|
||||
ignoreProductIds = append(ignoreProductIds, v.Id)
|
||||
productIds = append(productIds, v.Id)
|
||||
}
|
||||
//在合并之前记住推荐的产品
|
||||
mapRecommend := make(map[int64]struct{})
|
||||
|
|
Loading…
Reference in New Issue
Block a user