Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
728aeb17e2
|
@ -4,3 +4,6 @@ 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 = 2
|
||||||
|
|
|
@ -87,13 +87,14 @@ func (o *FsOrderModel) FindPageListByPage(ctx context.Context, rowBuilder *gorm.
|
||||||
|
|
||||||
type FsOrderRel struct {
|
type FsOrderRel struct {
|
||||||
FsOrder
|
FsOrder
|
||||||
FsOrderDetails []FsOrderDetails `gorm:"foreignKey:order_id;references:id"`
|
FsOrderDetails []FsOrderDetails `gorm:"foreignKey:order_id;references:id"`
|
||||||
|
FsOrderAffiliateInfo FsOrderAffiliate `gorm:"foreignKey:order_id;references:id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FsOrderDetails struct {
|
type FsOrderDetails struct {
|
||||||
FsOrderDetail
|
FsOrderDetail
|
||||||
FsOrderDetailTemplateInfo FsOrderDetailTemplate `gorm:"foreignKey:id;references:order_detail_template_id"`
|
FsOrderDetailTemplateInfo FsOrderDetailTemplate `gorm:"foreignKey:id;references:order_detail_template_id"`
|
||||||
FsProductInfo FsProduct `gorm:"foreignKey:id;references:product_id"`
|
FsProductInfo FsProduct `gorm:"foreignKey:id;references:product_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
func (m *FsOrderModel) RowSelectBuilder(selectData []string) *gorm.DB {
|
||||||
|
|
|
@ -9,7 +9,7 @@ type FsProductRecommend struct {
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||||
ProductId *int64 `gorm:"unique_key;default:0;" json:"product_id"` // 产品ID
|
ProductId *int64 `gorm:"unique_key;default:0;" json:"product_id"` // 产品ID
|
||||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常
|
Status *int64 `gorm:"default:1;" json:"status"` // 状态 1正常 0不正常
|
||||||
Category *int64 `gorm:"default:1;" json:"category"` // 推荐类别1:详情推荐产品
|
Category *int64 `gorm:"default:1;" json:"category"` // 推荐类别1:详情推荐 2:列表页推荐
|
||||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||||
}
|
}
|
||||||
type FsProductRecommendModel struct {
|
type FsProductRecommendModel struct {
|
||||||
|
|
|
@ -10,31 +10,34 @@ type GetRecommendProductListReq struct {
|
||||||
Ctx context.Context
|
Ctx context.Context
|
||||||
Page int
|
Page int
|
||||||
Limit int
|
Limit int
|
||||||
OrderBy string
|
Category int64 // 0是全部
|
||||||
Category int64
|
|
||||||
Status *int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProductRecommend, total int64, err error) {
|
func (r *FsProductRecommendModel) GetRecommendProductList(req GetRecommendProductListReq) (resp []FsProduct, total int64, err error) {
|
||||||
db := r.db.WithContext(req.Ctx).Model(&FsProductRecommend{})
|
db := r.db.WithContext(req.Ctx).
|
||||||
if req.Status != nil {
|
Table("fs_product_recommend as r").
|
||||||
db = db.Where("`status` = ?", *req.Status)
|
Joins("inner join fs_product as p on r.product_id = p.id").
|
||||||
}
|
Where("r.status = ? ", 1).
|
||||||
|
Where("p.is_shelf = ? and p.is_del = ? and p.status = ?", 1, 0, 1)
|
||||||
if req.Category != 0 {
|
if req.Category != 0 {
|
||||||
db = db.Where("`category` = ?", req.Category)
|
db = db.Where("r.category = ?", req.Category)
|
||||||
}
|
|
||||||
if req.OrderBy != "" {
|
|
||||||
db = db.Order(req.OrderBy)
|
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
func (r *FsProductRecommendModel) GetIgnoreRandomRecommendProductList(ctx context.Context, limit int, category int64, idNotInt []int64) (resp []FsProductRecommend, err error) {
|
func (r *FsProductRecommendModel) GetIgnoreRandomRecommendProductList(ctx context.Context, limit int, category int64, idNotInt []int64) (resp []FsProduct, err error) {
|
||||||
err = r.db.WithContext(ctx).Model(&FsProductRecommend{}).Where("`product_id` not in(?) and `category` = ?", idNotInt, category).Order("RAND()").Limit(limit).Find(&resp).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
|
return resp, err
|
||||||
}
|
}
|
||||||
func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, category int64, data *FsProductRecommend) error {
|
func (r *FsProductRecommendModel) CreateOrUpdate(ctx context.Context, productId int64, category int64, data *FsProductRecommend) error {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"math"
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
@ -47,7 +48,11 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
|
||||||
var page = req.Page
|
var page = req.Page
|
||||||
var pageSize = req.PageSize
|
var pageSize = req.PageSize
|
||||||
var listRes []*gmodel.FsOrderRel
|
var listRes []*gmodel.FsOrderRel
|
||||||
rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId).Where("status =?", req.Status)
|
rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId)
|
||||||
|
|
||||||
|
if req.Status != -1 {
|
||||||
|
rowBuilder = rowBuilder.Where("status = ?", req.Status)
|
||||||
|
}
|
||||||
|
|
||||||
// 查询总数
|
// 查询总数
|
||||||
total, err := orderModel.FindCount(l.ctx, rowBuilder, nil)
|
total, err := orderModel.FindCount(l.ctx, rowBuilder, nil)
|
||||||
|
@ -61,7 +66,7 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
|
||||||
|
|
||||||
// 查询数据
|
// 查询数据
|
||||||
if total > 0 {
|
if total > 0 {
|
||||||
rowBuilder = rowBuilder.Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
|
rowBuilder = rowBuilder.Preload("FsOrderAffiliateInfo").Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
|
||||||
return dbPreload.Table(orderDetailModel.TableName()).Preload("FsOrderDetailTemplateInfo").Preload("FsProductInfo")
|
return dbPreload.Table(orderDetailModel.TableName()).Preload("FsOrderDetailTemplateInfo").Preload("FsProductInfo")
|
||||||
})
|
})
|
||||||
listRes, err = orderModel.FindPageListByPage(l.ctx, rowBuilder, &page, &pageSize, nil, "")
|
listRes, err = orderModel.FindPageListByPage(l.ctx, rowBuilder, &page, &pageSize, nil, "")
|
||||||
|
@ -125,9 +130,34 @@ func (l *UserOrderListLogic) UserOrderList(req *types.UserOrderListReq, userinfo
|
||||||
pbData.ProductList = productList
|
pbData.ProductList = productList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var surplusAt int64
|
||||||
|
surplusAt = (*item.Ctime + constants.CANCLE_ORDER_EXPIRE) - time.Now().Unix()
|
||||||
|
if surplusAt < 0 {
|
||||||
|
surplusAt = 0
|
||||||
|
}
|
||||||
|
//fsOrderAffiliateInfo := item.FsOrderAffiliateInfo
|
||||||
|
|
||||||
|
// 流程控制
|
||||||
|
// statusTime := make([]*types.StatusTime,8)
|
||||||
|
// statusTime[0] = &types.StatusTime{
|
||||||
|
// Key: 1,Time:*fsOrderAffiliateInfo.SureTime,
|
||||||
|
// }
|
||||||
|
// statusTime[1] = &types.StatusTime{
|
||||||
|
// Key: 1,Time:*ifsOrderAffiliateInfo.ProductTime,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// `sure_time` int(10) unsigned DEFAULT '0' COMMENT '确认时间',
|
||||||
|
// `product_time` int(10) unsigned DEFAULT '0' COMMENT '生产时间',
|
||||||
|
// `product_endtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '生成完成时间',
|
||||||
|
// `deliver_time` int(10) unsigned DEFAULT '0' COMMENT '发货时间',
|
||||||
|
// `ups_deliver_time` int(10) unsigned DEFAULT '0' COMMENT 'ups发货时间',
|
||||||
|
// `ups_time` int(10) unsigned DEFAULT '0' COMMENT 'UPS提货时间',
|
||||||
|
// `arrival_time` int(10) unsigned DEFAULT '0' COMMENT '到达云仓的时间',
|
||||||
|
// `recevie_time` int(10) unsigned DEFAULT '0' COMMENT '云仓收货时间',
|
||||||
|
|
||||||
pbData.PcsBox = pcsBox
|
pbData.PcsBox = pcsBox
|
||||||
pbData.Pcs = pcs
|
pbData.Pcs = pcs
|
||||||
pbData.SurplusAt = *item.Ctime + constants.CANCLE_ORDER_EXPIRE
|
pbData.SurplusAt = surplusAt
|
||||||
pbData.LogisticsStatus = 1
|
pbData.LogisticsStatus = 1
|
||||||
pbData.Deposit = *item.TotalAmount / 2
|
pbData.Deposit = *item.TotalAmount / 2
|
||||||
pbData.Remaining = pbData.Deposit
|
pbData.Remaining = pbData.Deposit
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fusenapi/server/product/internal/logic"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HomePageRecommendProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var (
|
||||||
|
// 定义错误变量
|
||||||
|
err error
|
||||||
|
// 定义用户信息变量
|
||||||
|
userinfo *auth.UserInfo
|
||||||
|
)
|
||||||
|
// 解析JWT token,并对空用户进行判断
|
||||||
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401,
|
||||||
|
Message: "unauthorized",
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
var req types.HomePageRecommendProductListReq
|
||||||
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 510,
|
||||||
|
Message: "parameter error",
|
||||||
|
})
|
||||||
|
logx.Info(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewHomePageRecommendProductListLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.HomePageRecommendProductList(&req, userinfo)
|
||||||
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
|
if resp != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
} else {
|
||||||
|
err := errors.New("server logic is error, resp must not be nil")
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
logx.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,11 +52,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/product/other-list",
|
Path: "/api/product/other-list",
|
||||||
Handler: OtherProductListHandler(serverCtx),
|
Handler: OtherProductListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/api/product/recommand",
|
|
||||||
Handler: GetRecommandProductListHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/api/product/tag_product_list",
|
Path: "/api/product/tag_product_list",
|
||||||
|
@ -107,6 +102,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/api/product/get_last_product_design",
|
Path: "/api/product/get_last_product_design",
|
||||||
Handler: GetLastProductDesignHandler(serverCtx),
|
Handler: GetLastProductDesignHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/product/recommand",
|
||||||
|
Handler: GetRecommandProductListHandler(serverCtx),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/product/home_page_recommend",
|
||||||
|
Handler: HomePageRecommendProductListHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,31 +47,23 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get detail product info")
|
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 {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend list")
|
||||||
}
|
}
|
||||||
//需要填充时需要忽略的id
|
//需要填充时需要忽略的id
|
||||||
ignoreProductIds := make([]int64, 0, len(recommendList)+1)
|
ignoreProductIds := make([]int64, 0, len(recommendProductList)+1)
|
||||||
ignoreProductIds = append(ignoreProductIds, productInfo.Id)
|
ignoreProductIds = append(ignoreProductIds, productInfo.Id)
|
||||||
productIds := make([]int64, 0, len(recommendList))
|
productIds := make([]int64, 0, len(recommendProductList))
|
||||||
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")
|
|
||||||
}
|
|
||||||
//在合并之前记住推荐的产品
|
//在合并之前记住推荐的产品
|
||||||
mapRecommend := make(map[int64]struct{})
|
mapRecommend := make(map[int64]struct{})
|
||||||
for _, v := range recommendProductList {
|
for _, v := range recommendProductList {
|
||||||
|
ignoreProductIds = append(ignoreProductIds, v.Id)
|
||||||
|
productIds = append(productIds, v.Id)
|
||||||
mapRecommend[v.Id] = struct{}{}
|
mapRecommend[v.Id] = struct{}{}
|
||||||
}
|
}
|
||||||
//小于请求的数量则需要从产品表中随机填补上
|
//小于请求的数量则需要从产品表中随机填补上(不包含上面的产品)
|
||||||
lenRecommendProduct := len(recommendProductList)
|
lenRecommendProduct := len(recommendProductList)
|
||||||
if lenRecommendProduct < int(req.Num) {
|
if lenRecommendProduct < int(req.Num) {
|
||||||
appendNum := int(req.Num) - lenRecommendProduct
|
appendNum := int(req.Num) - lenRecommendProduct
|
||||||
|
|
|
@ -0,0 +1,180 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/format"
|
||||||
|
"fusenapi/utils/image"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HomePageRecommendProductListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHomePageRecommendProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomePageRecommendProductListLogic {
|
||||||
|
return &HomePageRecommendProductListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *types.HomePageRecommendProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
//查询用户信息(不用判断存在)
|
||||||
|
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||||
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
|
}
|
||||||
|
var (
|
||||||
|
recommendProductList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||||
|
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
||||||
|
mapProductHaveOptionFitting = make(map[int64]struct{})
|
||||||
|
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
||||||
|
mapProductMinPrice = make(map[int64]int64) //产品最小价格map
|
||||||
|
productTemplatesV2 []gmodel.FsProductTemplateV2 //产品模板列表(select 字段需要看查询的地方)
|
||||||
|
productSizeCountList []gmodel.CountProductSizeByStatusRsp //产品尺寸数量列表(select 字段需要看查询的地方)
|
||||||
|
mapProductSizeCount = make(map[int64]int64) //产品尺寸数量map
|
||||||
|
mapProductTemplate = make(map[int64]struct{}) //产品模板map
|
||||||
|
)
|
||||||
|
//获取列表推荐产品
|
||||||
|
recommendProductList, _, err = l.svcCtx.AllModels.FsProductRecommend.GetRecommendProductList(gmodel.GetRecommendProductListReq{
|
||||||
|
Ctx: l.ctx,
|
||||||
|
Page: 1,
|
||||||
|
Limit: 500, //设置最大500
|
||||||
|
Category: int64(constants.HOME_PAGE_RECOMMEND_CATEGORY),
|
||||||
|
})
|
||||||
|
if len(recommendProductList) == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
||||||
|
}
|
||||||
|
fmt.Println(recommendProductList)
|
||||||
|
productIds := make([]int64, 0, len(recommendProductList))
|
||||||
|
for _, product := range recommendProductList {
|
||||||
|
productIds = append(productIds, product.Id)
|
||||||
|
}
|
||||||
|
//获取商品可选配件
|
||||||
|
productOptionalPartList, err = l.svcCtx.AllModels.FsProductModel3d.GetGroupPartListByProductIds(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product part list")
|
||||||
|
}
|
||||||
|
//存储有配件的map
|
||||||
|
for _, partList := range productOptionalPartList {
|
||||||
|
partList.PartList = strings.Trim(partList.PartList, " ")
|
||||||
|
partList.PartList = strings.Trim(partList.PartList, ",")
|
||||||
|
if partList.PartList == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
||||||
|
}
|
||||||
|
//获取产品价格列表
|
||||||
|
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
|
||||||
|
}
|
||||||
|
//存储产品最小价格
|
||||||
|
for _, v := range productPriceList {
|
||||||
|
priceStrSlic := strings.Split(v.Price, ",")
|
||||||
|
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||||
|
}
|
||||||
|
if len(priceSlice) == 0 {
|
||||||
|
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 {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
||||||
|
}
|
||||||
|
for _, v := range productTemplatesV2 {
|
||||||
|
mapProductTemplate[*v.ProductId] = struct{}{}
|
||||||
|
}
|
||||||
|
//获取产品尺寸数量
|
||||||
|
productSizeCountList, err = l.svcCtx.AllModels.FsProductSize.GetGroupProductSizeByStatus(l.ctx, productIds, 1)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product size count err")
|
||||||
|
}
|
||||||
|
for _, v := range productSizeCountList {
|
||||||
|
mapProductSizeCount[v.ProductId] = v.Num
|
||||||
|
}
|
||||||
|
//组装返回
|
||||||
|
listRsp := make([]types.HomePageRecommendProductListRsp, 0, len(recommendProductList))
|
||||||
|
for _, productInfo := range recommendProductList {
|
||||||
|
minPrice, ok := mapProductMinPrice[productInfo.Id]
|
||||||
|
_, tmpOk := mapProductTemplate[productInfo.Id]
|
||||||
|
//无最小价格则不显示 || 没有模板也不显示
|
||||||
|
if !ok || !tmpOk {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sizeNum := int64(0)
|
||||||
|
if mapSizeNum, ok := mapProductSizeCount[productInfo.Id]; ok {
|
||||||
|
sizeNum = mapSizeNum
|
||||||
|
}
|
||||||
|
//有无可选配件
|
||||||
|
haveOptionalFitting := false
|
||||||
|
if _, ok = mapProductHaveOptionFitting[productInfo.Id]; ok {
|
||||||
|
haveOptionalFitting = true
|
||||||
|
}
|
||||||
|
item := types.HomePageRecommendProductListRsp{
|
||||||
|
ProductId: productInfo.Id,
|
||||||
|
Sn: *productInfo.Sn,
|
||||||
|
Title: *productInfo.Title,
|
||||||
|
Intro: *productInfo.Intro,
|
||||||
|
IsEnv: *productInfo.IsProtection,
|
||||||
|
IsMicro: *productInfo.IsMicrowave,
|
||||||
|
SizeNum: uint32(sizeNum),
|
||||||
|
MiniPrice: minPrice,
|
||||||
|
HaveOptionalFitting: haveOptionalFitting,
|
||||||
|
}
|
||||||
|
//千人千面处理
|
||||||
|
r := image.ThousandFaceImageFormatReq{
|
||||||
|
Size: int(req.Size),
|
||||||
|
IsThousandFace: 0,
|
||||||
|
Cover: *productInfo.Cover,
|
||||||
|
CoverImg: *productInfo.CoverImg,
|
||||||
|
CoverDefault: *productInfo.CoverImg,
|
||||||
|
ProductId: productInfo.Id,
|
||||||
|
UserId: user.Id,
|
||||||
|
}
|
||||||
|
if user.Id != 0 {
|
||||||
|
r.IsThousandFace = int(*user.IsThousandFace)
|
||||||
|
}
|
||||||
|
image.ThousandFaceImageFormat(&r)
|
||||||
|
item.Cover = r.Cover
|
||||||
|
item.CoverImg = r.CoverImg
|
||||||
|
item.CoverDefault = r.CoverDefault
|
||||||
|
//加入分类产品切片
|
||||||
|
listRsp = append(listRsp, item)
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
|
||||||
|
}
|
|
@ -378,6 +378,25 @@ type GetLastProductDesignRsp struct {
|
||||||
Info interface{} `json:"info"`
|
Info interface{} `json:"info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HomePageRecommendProductListReq struct {
|
||||||
|
Size uint32 `form:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HomePageRecommendProductListRsp struct {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Cover string `json:"cover"`
|
||||||
|
Intro string `json:"intro"`
|
||||||
|
CoverImg string `json:"cover_img"`
|
||||||
|
IsEnv int64 `json:"is_env"`
|
||||||
|
IsMicro int64 `json:"is_micro"`
|
||||||
|
SizeNum uint32 `json:"size_num"`
|
||||||
|
MiniPrice int64 `json:"mini_price"`
|
||||||
|
CoverDefault string `json:"cover_default"`
|
||||||
|
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,9 @@ service product {
|
||||||
//获取详情页推荐产品列表
|
//获取详情页推荐产品列表
|
||||||
@handler GetRecommandProductListHandler
|
@handler GetRecommandProductListHandler
|
||||||
get /api/product/recommand (GetRecommandProductListReq) returns (response);
|
get /api/product/recommand (GetRecommandProductListReq) returns (response);
|
||||||
|
//获取列表页推荐产品列表
|
||||||
|
@handler HomePageRecommendProductListHandler
|
||||||
|
get /api/product/home_page_recommend (HomePageRecommendProductListReq) returns (response);
|
||||||
//*********************产品详情分解接口结束***********************
|
//*********************产品详情分解接口结束***********************
|
||||||
//*********************推荐产品接口开始××××××××××××××××××××××××××
|
//*********************推荐产品接口开始××××××××××××××××××××××××××
|
||||||
|
|
||||||
|
@ -418,3 +421,21 @@ type GetLastProductDesignRsp {
|
||||||
LogoColor interface{} `json:"logo_color"`
|
LogoColor interface{} `json:"logo_color"`
|
||||||
Info interface{} `json:"info"`
|
Info interface{} `json:"info"`
|
||||||
}
|
}
|
||||||
|
//获取列表页推荐产品(返回是这个维度数组)
|
||||||
|
type HomePageRecommendProductListReq {
|
||||||
|
Size uint32 `form:"size"`
|
||||||
|
}
|
||||||
|
type HomePageRecommendProductListRsp {
|
||||||
|
ProductId int64 `json:"product_id"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Cover string `json:"cover"`
|
||||||
|
Intro string `json:"intro"`
|
||||||
|
CoverImg string `json:"cover_img"`
|
||||||
|
IsEnv int64 `json:"is_env"`
|
||||||
|
IsMicro int64 `json:"is_micro"`
|
||||||
|
SizeNum uint32 `json:"size_num"`
|
||||||
|
MiniPrice int64 `json:"mini_price"`
|
||||||
|
CoverDefault string `json:"cover_default"`
|
||||||
|
HaveOptionalFitting bool `json:"have_optional_fitting"`
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user