This commit is contained in:
laodaming 2023-07-20 18:18:36 +08:00
parent 10aa0d14f0
commit 532929a563
3 changed files with 5 additions and 2 deletions

View File

@ -6,4 +6,4 @@ type recommend_product int64
const PRODUCT_DETAIL_RECOMMEND_CATEGORY recommend_product = 1 const PRODUCT_DETAIL_RECOMMEND_CATEGORY recommend_product = 1
// 主页推荐产品 // 主页推荐产品
const HOME_PAGE_RECOMMEND_CATEGORY recommend_product = 1 const HOME_PAGE_RECOMMEND_CATEGORY recommend_product = 2

View File

@ -14,7 +14,7 @@ type GetRecommendProductListReq struct {
} }
func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) { func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) {
db := r.db.WithContext(req.Ctx).Select("p.*"). db := r.db.WithContext(req.Ctx).
Table("fs_product_recommend as r"). Table("fs_product_recommend as r").
Joins("inner join fs_product as p on r.product_id = p.id"). Joins("inner join fs_product as p on r.product_id = p.id").
Where("r.status = ? ", 1). Where("r.status = ? ", 1).
@ -25,6 +25,7 @@ func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProduc
if err = db.Limit(1).Count(&total).Error; err != nil { if err = db.Limit(1).Count(&total).Error; err != nil {
return nil, 0, err return nil, 0, err
} }
db = db.Select("p.*")
offset := (req.Page - 1) * req.Limit offset := (req.Page - 1) * req.Limit
err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error err = db.Offset(offset).Limit(req.Limit).Find(&resp).Error
return resp, total, err return resp, total, err

View File

@ -2,6 +2,7 @@ package logic
import ( import (
"errors" "errors"
"fmt"
"fusenapi/constants" "fusenapi/constants"
"fusenapi/model/gmodel" "fusenapi/model/gmodel"
"fusenapi/utils/auth" "fusenapi/utils/auth"
@ -62,6 +63,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
if len(recommendProductList) == 0 { if len(recommendProductList) == 0 {
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{}) return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
} }
fmt.Println(recommendProductList)
productIds := make([]int64, 0, len(recommendProductList)) productIds := make([]int64, 0, len(recommendProductList))
for _, product := range recommendProductList { for _, product := range recommendProductList {
productIds = append(productIds, product.Id) productIds = append(productIds, product.Id)