Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
78
server/orders/internal/handler/getuserorderlisthandler.go
Normal file
78
server/orders/internal/handler/getuserorderlisthandler.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/orders/internal/logic"
|
||||
"fusenapi/server/orders/internal/svc"
|
||||
"fusenapi/server/orders/internal/types"
|
||||
)
|
||||
|
||||
func GetUserOrderListHandler(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.GetUserOrderListReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetUserOrderListLogic(r.Context(), svcCtx)
|
||||
resp := l.GetUserOrderList(&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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/api/order/detail",
|
||||
Handler: GetOrderDetailHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/order-list",
|
||||
Handler: GetUserOrderListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
146
server/orders/internal/logic/getuserorderlistlogic.go
Normal file
146
server/orders/internal/logic/getuserorderlistlogic.go
Normal file
@@ -0,0 +1,146 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"math"
|
||||
|
||||
"fusenapi/server/orders/internal/svc"
|
||||
"fusenapi/server/orders/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type GetUserOrderListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetUserOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserOrderListLogic {
|
||||
return &GetUserOrderListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetUserOrderListLogic) GetUserOrderList(req *types.GetUserOrderListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
orderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
rowBuilder := orderModel.RowSelectBuilder(nil)
|
||||
if userinfo == nil || userinfo.UserId == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
|
||||
// 查询条件
|
||||
var page = req.Page
|
||||
var pageSize = req.PageSize
|
||||
var listRes []*gmodel.FsOrderRel
|
||||
rowBuilder = rowBuilder.Where("user_id =?", userinfo.UserId).Where("status =?", req.Status)
|
||||
|
||||
// 查询总数
|
||||
total, err := orderModel.FindCount(l.ctx, rowBuilder, nil)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order info")
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
if total > 0 {
|
||||
rowBuilder = rowBuilder.Preload("FsOrderDetails", func(dbPreload *gorm.DB) *gorm.DB {
|
||||
return dbPreload.Table(orderDetailModel.TableName()).Preload("FsOrderDetailTemplateInfo").Preload("FsProductInfo")
|
||||
})
|
||||
listRes, err = orderModel.FindPageListByPage(l.ctx, rowBuilder, &page, &pageSize, nil, "")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order info")
|
||||
}
|
||||
listResLen := len(listRes)
|
||||
|
||||
var respList []types.Items
|
||||
if listResLen > 0 {
|
||||
// 数据处理
|
||||
for _, item := range listRes {
|
||||
var pbData types.Items
|
||||
pbData.ID = item.Id
|
||||
pbData.Sn = *item.Sn
|
||||
pbData.UserID = *item.UserId
|
||||
pbData.TotalAmount = *item.TotalAmount
|
||||
pbData.Ctime = format.TimeIntToFormat(*item.Ctime)
|
||||
pbData.Status = *item.Status
|
||||
pbData.DeliveryMethod = *item.DeliveryMethod
|
||||
pbData.TsTime = format.TimeToFormat(*item.TsTime)
|
||||
pbData.IsPayCompleted = *item.IsPayCompleted
|
||||
pbData.DeliverSn = *item.DeliverSn
|
||||
|
||||
var pcsBox int64
|
||||
var pcs int64
|
||||
var productList []*types.Product
|
||||
if len(item.FsOrderDetails) > 0 {
|
||||
for _, fsOrderDetailItem := range item.FsOrderDetails {
|
||||
fsOrderDetailBuyNum := *fsOrderDetailItem.FsOrderDetail.BuyNum
|
||||
fsOrderDetailEachBoxNum := *fsOrderDetailItem.FsOrderDetailTemplateInfo.EachBoxNum
|
||||
pcs = pcs + fsOrderDetailBuyNum
|
||||
pcsBoxNum := fsOrderDetailBuyNum / fsOrderDetailEachBoxNum
|
||||
var csBoxNumF int64
|
||||
if (fsOrderDetailBuyNum % fsOrderDetailEachBoxNum) > 0 {
|
||||
csBoxNumF = 1
|
||||
}
|
||||
pcsBox = pcsBox + pcsBoxNum + csBoxNumF
|
||||
|
||||
var product types.Product
|
||||
product.Cover = *fsOrderDetailItem.Cover
|
||||
product.Fitting = *fsOrderDetailItem.OptionalTitle
|
||||
product.OptionPrice = *fsOrderDetailItem.OptionPrice
|
||||
product.OrderDetailTemplateId = *fsOrderDetailItem.OrderDetailTemplateId
|
||||
product.OrderId = *fsOrderDetailItem.OrderId
|
||||
product.Pcs = fsOrderDetailBuyNum
|
||||
product.PcsBox = pcsBox
|
||||
product.Price = *fsOrderDetailItem.FsOrderDetail.Amount
|
||||
product.ProductId = *fsOrderDetailItem.OptionPrice
|
||||
//product.Size = *fsOrderDetailItem.FsProductInfo.s
|
||||
product.Title = *fsOrderDetailItem.FsProductInfo.Title
|
||||
|
||||
productList = append(productList, &product)
|
||||
}
|
||||
pbData.ProductList = productList
|
||||
}
|
||||
|
||||
pbData.PcsBox = pcsBox
|
||||
pbData.Pcs = pcs
|
||||
pbData.SurplusAt = *item.Ctime + constants.CANCLE_ORDER_EXPIRE
|
||||
pbData.LogisticsStatus = 1
|
||||
pbData.Deposit = *item.TotalAmount / 2
|
||||
pbData.Remaining = pbData.Deposit
|
||||
respList = append(respList, pbData)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetUserOrderListRsp{
|
||||
Items: respList,
|
||||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(pageSize))),
|
||||
CurrentPage: int(page),
|
||||
PerPage: int(pageSize),
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -76,6 +76,47 @@ type Deposit struct {
|
||||
TransNo string `json:"trans_no"`
|
||||
}
|
||||
|
||||
type GetUserOrderListReq struct {
|
||||
Page int64 `form:"page"` // 分页
|
||||
PageSize int64 `form:"page_size"` // 每页数量
|
||||
Status int64 `form:"status"` // 状态筛选
|
||||
Time int64 `form:"time"` // 时间筛选
|
||||
Total int64 `form:"total"` // 总数
|
||||
Size int64 `form:"size"` // 图片尺寸
|
||||
}
|
||||
|
||||
type GetUserOrderListRsp struct {
|
||||
Items []Items `json:"items"`
|
||||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
|
||||
type StatusTime struct {
|
||||
Key int `json:"key"`
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
type Items struct {
|
||||
ID int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
UserID int64 `json:"user_id"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
Ctime string `json:"ctime"`
|
||||
Status int64 `json:"status"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
TsTime string `json:"ts_time"`
|
||||
IsPayCompleted int64 `json:"is_pay_completed"`
|
||||
DeliverSn string `json:"deliver_sn"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
SurplusAt int64 `json:"surplus_at"`
|
||||
LogisticsStatus int64 `json:"logistics_status"`
|
||||
StatusTimes []*StatusTime `json:"status_times"`
|
||||
Deposit int64 `json:"deposit"`
|
||||
Remaining int64 `json:"remaining"`
|
||||
ProductList []*Product `json:"productList"`
|
||||
IsStop int64 `json:"is_stop"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
||||
7
server/orders/orders_test.go
Normal file
7
server/orders/orders_test.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
main()
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", demo)
|
||||
}
|
||||
if req.Page <= 0{
|
||||
if req.Page <= 0 {
|
||||
req.Page = constants.DEFAULT_PAGE
|
||||
}
|
||||
//获取合适尺寸
|
||||
|
||||
@@ -30,18 +30,54 @@ func NewGetRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceCon
|
||||
}
|
||||
|
||||
func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
req.Num = 8 //目前写死
|
||||
req.Num = 4 //写死4个
|
||||
if req.Size > 0 {
|
||||
req.Size = image.GetCurrentSize(req.Size)
|
||||
}
|
||||
//随机取产品列表
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx, int(req.Num))
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Sn)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "detail`s product is not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get detail product info")
|
||||
}
|
||||
//随机取产品列表(不包含详情产品)
|
||||
recommendList, err := l.svcCtx.AllModels.FsProductRecommend.GetIgnoreRandomRecommendProductList(l.ctx, int(req.Num), []int64{productInfo.Id})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend product list")
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend list")
|
||||
}
|
||||
if len(productList) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||
//需要填充时需要忽略的id
|
||||
ignoreProductIds := make([]int64, 0, len(recommendList)+1)
|
||||
ignoreProductIds = append(ignoreProductIds, productInfo.Id)
|
||||
recommendProductIds := make([]int64, 0, len(recommendList))
|
||||
for _, v := range recommendList {
|
||||
ignoreProductIds = append(ignoreProductIds, *v.ProductId)
|
||||
recommendProductIds = append(recommendProductIds, *v.ProductId)
|
||||
}
|
||||
//获取推荐产品列表
|
||||
recommendProductList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, recommendProductIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbSqlErr, "failed to get recommend product list")
|
||||
}
|
||||
//在合并之前记住推荐的产品
|
||||
mapRecommend := make(map[int64]struct{})
|
||||
for _, v := range recommendProductList {
|
||||
mapRecommend[v.Id] = struct{}{}
|
||||
}
|
||||
//小于请求的数量则需要从产品表中随机填补上
|
||||
lenRecommendProduct := len(recommendProductList)
|
||||
if lenRecommendProduct < int(req.Num) {
|
||||
appendNum := int(req.Num) - lenRecommendProduct
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetIgnoreRandomProductList(l.ctx, appendNum, ignoreProductIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product list")
|
||||
}
|
||||
//合并列表
|
||||
recommendProductList = append(recommendProductList, productList...)
|
||||
}
|
||||
//获取用户信息(不用判断存在)
|
||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||
@@ -49,8 +85,8 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user")
|
||||
}
|
||||
list := make([]types.GetRecommandProductListRsp, 0, len(productList))
|
||||
for _, v := range productList {
|
||||
list := make([]types.GetRecommandProductListRsp, 0, len(recommendProductList))
|
||||
for _, v := range recommendProductList {
|
||||
r := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: 0,
|
||||
@@ -63,7 +99,12 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||
if user.Id != 0 {
|
||||
r.IsThousandFace = int(*user.IsThousandFace)
|
||||
}
|
||||
//千人前面处理
|
||||
image.ThousandFaceImageFormat(&r)
|
||||
isRecommend := int64(0)
|
||||
if _, ok := mapRecommend[v.Id]; ok {
|
||||
isRecommend = 1
|
||||
}
|
||||
list = append(list, types.GetRecommandProductListRsp{
|
||||
Id: v.Id,
|
||||
Sn: *v.Sn,
|
||||
@@ -73,6 +114,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
|
||||
CoverImg: r.CoverImg,
|
||||
CoverDefault: r.CoverDefault,
|
||||
Intro: *v.Intro,
|
||||
IsRecommend: isRecommend,
|
||||
})
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
||||
|
||||
@@ -60,7 +60,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get tag info")
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
|
||||
}
|
||||
tReq.LevelPrefixLeftLike = *tagData.LevelPrefix
|
||||
}
|
||||
@@ -77,13 +77,15 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||
typeIds = append(typeIds, v.Id)
|
||||
}
|
||||
var (
|
||||
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||
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
|
||||
productList []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
|
||||
)
|
||||
//携带产品
|
||||
if req.WithProduct {
|
||||
@@ -104,9 +106,24 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||
}
|
||||
productIds := make([]int64,0,len(productList))
|
||||
for _,product := range productList{
|
||||
productIds = append(productIds,product.Id)
|
||||
productIds := make([]int64, 0, len(productList))
|
||||
for _, product := range productList {
|
||||
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)
|
||||
@@ -151,22 +168,23 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||
mapTagLevel := make(map[string]*types.TagItem)
|
||||
//处理tags数据
|
||||
if err = l.dealWithTagMenuData(dealWithTagMenuDataReq{
|
||||
TagList: tagList,
|
||||
WithProduct: req.WithProduct,
|
||||
ProductList: productList,
|
||||
MapProductMinPrice: mapProductMinPrice,
|
||||
MapProductTemplate: mapProductTemplate,
|
||||
MapProductSizeCount: mapProductSizeCount,
|
||||
MapTagLevel: mapTagLevel,
|
||||
Size: req.Size,
|
||||
user: user,
|
||||
TagList: tagList,
|
||||
WithProduct: req.WithProduct,
|
||||
ProductList: productList,
|
||||
MapProductMinPrice: mapProductMinPrice,
|
||||
MapProductTemplate: mapProductTemplate,
|
||||
MapProductSizeCount: mapProductSizeCount,
|
||||
MapTagLevel: mapTagLevel,
|
||||
MapProductHaveOptionFitting: mapProductHaveOptionFitting,
|
||||
Size: req.Size,
|
||||
user: user,
|
||||
}); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusAddMessage(basic.CodeServiceErr, "failed to deal with tag data")
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||
TotalCategoryProduct: len(productList),
|
||||
TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系
|
||||
TagList: l.organizationLevelRelation(mapTagLevel), //组装等级从属关系
|
||||
})
|
||||
}
|
||||
|
||||
@@ -178,41 +196,43 @@ type sortRecommendProduct struct {
|
||||
|
||||
// 处理tag菜单数据
|
||||
type dealWithTagMenuDataReq struct {
|
||||
TagList []gmodel.FsTags
|
||||
WithProduct bool
|
||||
ProductList []gmodel.FsProduct
|
||||
MapProductMinPrice map[int64]int64
|
||||
MapProductTemplate map[int64]struct{}
|
||||
MapProductSizeCount map[int64]int64
|
||||
MapTagLevel map[string]*types.TagItem
|
||||
Size uint32
|
||||
user gmodel.FsUser
|
||||
TagList []gmodel.FsTags
|
||||
WithProduct bool
|
||||
ProductList []gmodel.FsProduct
|
||||
MapProductMinPrice map[int64]int64
|
||||
MapProductTemplate map[int64]struct{}
|
||||
MapProductSizeCount map[int64]int64
|
||||
MapTagLevel map[string]*types.TagItem
|
||||
MapProductHaveOptionFitting map[int64]struct{}
|
||||
Size uint32
|
||||
user gmodel.FsUser
|
||||
}
|
||||
|
||||
func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq) error {
|
||||
for _, tagInfo := range req.TagList {
|
||||
tagTem := types.TagItem{
|
||||
TagProductList: nil,
|
||||
TypeName: *tagInfo.Title,
|
||||
TypeId: tagInfo.Id,
|
||||
Level: *tagInfo.Level,
|
||||
LevelPrefix: *tagInfo.LevelPrefix,
|
||||
Icon: *tagInfo.Icon,
|
||||
Sort: *tagInfo.Sort,
|
||||
Description: *tagInfo.Description,
|
||||
ChildTagList: make([]*types.TagItem, 0, 50),
|
||||
TagProductList: nil,
|
||||
TypeName: *tagInfo.Title,
|
||||
TypeId: tagInfo.Id,
|
||||
Level: *tagInfo.Level,
|
||||
LevelPrefix: *tagInfo.LevelPrefix,
|
||||
Icon: *tagInfo.Icon,
|
||||
Sort: *tagInfo.Sort,
|
||||
Description: *tagInfo.Description,
|
||||
ChildTagList: make([]*types.TagItem, 0, 50),
|
||||
}
|
||||
//携带产品
|
||||
if req.WithProduct {
|
||||
//获取分类产品列表
|
||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||
TagId: tagInfo.Id,
|
||||
ProductList: req.ProductList,
|
||||
MapProductMinPrice: req.MapProductMinPrice,
|
||||
MapProductTemplate: req.MapProductTemplate,
|
||||
MapProductSizeCount: req.MapProductSizeCount,
|
||||
Size: req.Size,
|
||||
User: req.user,
|
||||
TagId: tagInfo.Id,
|
||||
ProductList: req.ProductList,
|
||||
MapProductMinPrice: req.MapProductMinPrice,
|
||||
MapProductTemplate: req.MapProductTemplate,
|
||||
MapProductSizeCount: req.MapProductSizeCount,
|
||||
MapProductHaveOptionFitting: req.MapProductHaveOptionFitting,
|
||||
Size: req.Size,
|
||||
User: req.user,
|
||||
})
|
||||
//赋值
|
||||
tagTem.TagProductList = productListRsp
|
||||
@@ -257,15 +277,17 @@ func (l *GetTagProductListLogic) organizationLevelRelation(mapTagLevel map[strin
|
||||
})
|
||||
return rspList
|
||||
}
|
||||
|
||||
// 获取对应tag的产品列表
|
||||
type getTagProductsReq struct {
|
||||
TagId int64
|
||||
ProductList []gmodel.FsProduct
|
||||
MapProductMinPrice map[int64]int64
|
||||
MapProductTemplate map[int64]struct{}
|
||||
MapProductSizeCount map[int64]int64
|
||||
Size uint32
|
||||
User gmodel.FsUser
|
||||
TagId int64
|
||||
ProductList []gmodel.FsProduct
|
||||
MapProductMinPrice map[int64]int64
|
||||
MapProductTemplate map[int64]struct{}
|
||||
MapProductSizeCount map[int64]int64
|
||||
MapProductHaveOptionFitting map[int64]struct{}
|
||||
Size uint32
|
||||
User gmodel.FsUser
|
||||
}
|
||||
|
||||
func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productListRsp []types.TagProduct) {
|
||||
@@ -286,15 +308,21 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
||||
if mapSizeNum, ok := req.MapProductSizeCount[productInfo.Id]; ok {
|
||||
sizeNum = mapSizeNum
|
||||
}
|
||||
//有无可选配件
|
||||
haveOptionalFitting := false
|
||||
if _, ok = req.MapProductHaveOptionFitting[productInfo.Id]; ok {
|
||||
haveOptionalFitting = true
|
||||
}
|
||||
item := types.TagProduct{
|
||||
ProductId: productInfo.Id,
|
||||
Sn: *productInfo.Sn,
|
||||
Title: *productInfo.Title,
|
||||
Intro: *productInfo.Intro,
|
||||
IsEnv: *productInfo.IsProtection,
|
||||
IsMicro: *productInfo.IsMicrowave,
|
||||
SizeNum: uint32(sizeNum),
|
||||
MiniPrice: minPrice,
|
||||
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{
|
||||
|
||||
@@ -242,6 +242,7 @@ type GetRecommandProductListRsp struct {
|
||||
CoverImg string `json:"cover_img"`
|
||||
CoverDefault string `json:"cover_default"`
|
||||
Intro string `json:"intro"`
|
||||
IsRecommend int64 `json:"is_recommend"`
|
||||
}
|
||||
|
||||
type GetTagProductListReq struct {
|
||||
@@ -268,17 +269,18 @@ type TagItem struct {
|
||||
}
|
||||
|
||||
type TagProduct 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"`
|
||||
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 GetRenderDesignReq struct {
|
||||
|
||||
Reference in New Issue
Block a user