From 76412c96ce770db56824426e8e2d127a48671276 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 25 Oct 2023 18:21:06 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_logic.go | 8 ++++++-- .../internal/logic/getrecommendproductlistlogic.go | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/model/gmodel/fs_product_logic.go b/model/gmodel/fs_product_logic.go index 1e7d87e9..e2e16e42 100755 --- a/model/gmodel/fs_product_logic.go +++ b/model/gmodel/fs_product_logic.go @@ -89,8 +89,12 @@ func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (r return resp, err } func (p *FsProductModel) GetIgnoreRandomProductList(ctx context.Context, limit int, notInProductIds []int64) (resp []FsProduct, err error) { - err = p.db.WithContext(ctx).Model(&FsProduct{}). - Where("`is_del` =? and `is_shelf` = ? and `id` not in(?)", 0, 1, notInProductIds).Order("RAND()").Limit(limit).Find(&resp).Error + db := p.db.WithContext(ctx).Model(&FsProduct{}). + Where("`is_del` =? and `is_shelf` = ? ", 0, 1) + if len(notInProductIds) > 0 { + db = db.Where("`id` not in(?)", notInProductIds) + } + err = db.Order("RAND()").Limit(limit).Find(&resp).Error return resp, err } func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (resp []FsProduct, err error) { diff --git a/server/product/internal/logic/getrecommendproductlistlogic.go b/server/product/internal/logic/getrecommendproductlistlogic.go index 013abab1..072b9164 100644 --- a/server/product/internal/logic/getrecommendproductlistlogic.go +++ b/server/product/internal/logic/getrecommendproductlistlogic.go @@ -3,6 +3,7 @@ package logic import ( "encoding/json" "errors" + "fmt" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" @@ -64,6 +65,7 @@ func (l *GetRecommendProductListLogic) GetRecommendProductList(req *types.GetRec recommendProductList = recommendProductList[:req.Num] } } + fmt.Println(recommendProductList) //资源id集合 resourceIds := make([]string, 0, 50) //需要填充时需要忽略的id