Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
46430a1ce6
|
@ -6,8 +6,12 @@ func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct
|
|||
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string) (resp *FsProduct, err error) {
|
||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`sn` = ? ", sn).Take(&resp).Error
|
||||
func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...string) (resp *FsProduct, err error) {
|
||||
db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`sn` = ? ", sn)
|
||||
if len(fields) != 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
||||
|
@ -44,7 +48,7 @@ func (p *FsProductModel) GetProductListByIdsWithoutStatus(ctx context.Context, p
|
|||
}
|
||||
return
|
||||
}
|
||||
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
|
||||
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, page int, limit int, sort string) (resp []FsProduct, total int64, err error) {
|
||||
if len(productTypes) == 0 {
|
||||
return
|
||||
}
|
||||
|
@ -55,11 +59,13 @@ func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTyp
|
|||
case "sort-desc":
|
||||
db = db.Order("`sort` DESC")
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
return
|
||||
offset := (page - 1) * limit
|
||||
err = db.Offset(offset).Limit(limit).Find(&resp).Error
|
||||
return resp, total, err
|
||||
}
|
||||
func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
|
||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||
|
@ -83,3 +89,35 @@ func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context, ids []in
|
|||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
type GetProductListByParamsReq struct {
|
||||
Type []int64
|
||||
IsDel *int64
|
||||
IsShelf *int64
|
||||
Status *int64
|
||||
OrderBy string
|
||||
}
|
||||
|
||||
func (p *FsProductModel) GetProductListByParams(ctx context.Context, req GetProductListByParamsReq) (resp []FsProduct, err error) {
|
||||
db := p.db.WithContext(ctx).Model(&FsProduct{})
|
||||
if len(req.Type) > 0 {
|
||||
db = db.Where("`type` in (?)", req.Type)
|
||||
}
|
||||
if req.IsDel != nil {
|
||||
db = db.Where("`is_del` = ?", *req.IsDel)
|
||||
}
|
||||
if req.IsShelf != nil {
|
||||
db = db.Where("`is_shelf` = ?", *req.IsShelf)
|
||||
}
|
||||
if req.Status != nil {
|
||||
db = db.Where("`status` = ?", *req.Status)
|
||||
}
|
||||
switch req.OrderBy {
|
||||
case "":
|
||||
db = db.Order("`id` DESC")
|
||||
default:
|
||||
db = db.Order(req.OrderBy)
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
|
|
@ -60,11 +60,15 @@ func (d *FsProductModel3dModel) Get3dModelsByParam(ctx context.Context, req Get3
|
|||
func (d *FsProductModel3dModel) Update(ctx context.Context, id int64, data *FsProductModel3d) error {
|
||||
return d.db.WithContext(ctx).Where("`id` = ? ", id).Updates(&data).Error
|
||||
}
|
||||
func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64) (resp []FsProductModel3d, err error) {
|
||||
func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64, fields ...string) (resp []FsProductModel3d, err error) {
|
||||
if len(sizeIds) == 0 {
|
||||
return
|
||||
}
|
||||
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, tag).Find(&resp).Error
|
||||
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, tag)
|
||||
if len(fields) != 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (d *FsProductModel3dModel) GetAll(ctx context.Context) (resp []FsProductModel3d, err error) {
|
||||
|
|
|
@ -6,14 +6,18 @@ import "context"
|
|||
|
||||
type FindOneRenderDesignByParamsReq struct {
|
||||
ClientNo *string
|
||||
Sn *string
|
||||
UserId *int64
|
||||
SortType int
|
||||
OrderBy string
|
||||
Fields string
|
||||
Id *int
|
||||
}
|
||||
|
||||
func (r *FsProductRenderDesignModel) FindOneRenderDesignByParams(ctx context.Context, req FindOneRenderDesignByParamsReq) (resp *FsProductRenderDesign, err error) {
|
||||
db := r.db.WithContext(ctx).Model(&FsProductRenderDesign{})
|
||||
if req.Sn != nil {
|
||||
db = db.Where("`sn` = ?", *req.Sn)
|
||||
}
|
||||
if req.ClientNo != nil {
|
||||
db = db.Where("`client_no` = ?", *req.ClientNo)
|
||||
}
|
||||
|
@ -26,11 +30,11 @@ func (r *FsProductRenderDesignModel) FindOneRenderDesignByParams(ctx context.Con
|
|||
if req.Fields != "" {
|
||||
db = db.Select(req.Fields)
|
||||
}
|
||||
switch req.SortType {
|
||||
case 1: //id asc
|
||||
switch req.OrderBy {
|
||||
case "": //id asc
|
||||
db = db.Order("`id` ASC")
|
||||
case 2: //id desc
|
||||
db = db.Order("`id` DESC")
|
||||
default:
|
||||
db = db.Order(req.OrderBy)
|
||||
}
|
||||
err = db.Take(&resp).Error
|
||||
return resp, err
|
||||
|
|
|
@ -38,16 +38,19 @@ func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context, pr
|
|||
Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
||||
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, orderBy string, fields ...string) (resp []FsProductSize, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`product_id` in(?) and `status` = ?", productIds, 1)
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
db = db.Order("`sort` ASC")
|
||||
case "sort-desc":
|
||||
db = db.Order("`sort` DESC")
|
||||
if len(fields) != 0 {
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
switch orderBy {
|
||||
case "":
|
||||
db = db.Order("`id` ASC")
|
||||
default:
|
||||
db = db.Order(orderBy)
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
if err != nil {
|
||||
|
|
|
@ -7,12 +7,13 @@ import (
|
|||
// fs_tags 产品分类表
|
||||
type FsTags struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // ID
|
||||
LevelPrefix *string `gorm:"default:'';" json:"level_prefix"` //
|
||||
Title *string `gorm:"default:'';" json:"title"` // 标题
|
||||
Level *int64 `gorm:"default:0;" json:"level"` // 层级、分类 1 => 二维码分类
|
||||
ClickNum *int64 `gorm:"default:0;" json:"click_num"` // 点击次数
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序(从大到小)
|
||||
CreateAt *int64 `gorm:"default:0;" json:"create_at"` // 创建时间
|
||||
Icon *string `gorm:"default:'';" json:"icon"` //
|
||||
Icon *string `gorm:"default:'';" json:"icon"` // 标签图标
|
||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态 1:可用
|
||||
Description *string `gorm:"default:'';" json:"description"` // 介绍 Seo
|
||||
RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` //
|
||||
|
|
|
@ -29,3 +29,37 @@ func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTa
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
type GetAllTagByParamsReq struct {
|
||||
Ids []int64
|
||||
Status *int64
|
||||
OrderBy string
|
||||
LevelPrefixLeftLike string //右模糊
|
||||
WithChild bool //是否包含子层级
|
||||
}
|
||||
|
||||
func (t *FsTagsModel) GetAllTagByParams(ctx context.Context, req GetAllTagByParamsReq) (resp []FsTags, err error) {
|
||||
db := t.db.WithContext(ctx).Model(&FsTags{})
|
||||
if len(req.Ids) > 0 {
|
||||
db = db.Where("`id` in (?)", req.Ids)
|
||||
}
|
||||
if req.Status != nil {
|
||||
db = db.Where("`status` = ?", *req.Status)
|
||||
}
|
||||
if req.LevelPrefixLeftLike != "" {
|
||||
//查询子集
|
||||
if req.WithChild {
|
||||
db = db.Where("`level_prefix` like ?", req.LevelPrefixLeftLike+`%`)
|
||||
} else {
|
||||
db = db.Where("`level_prefix` = ?", req.LevelPrefixLeftLike+`%`)
|
||||
}
|
||||
}
|
||||
switch req.OrderBy {
|
||||
case "":
|
||||
db = db.Order("`id` DESC")
|
||||
default:
|
||||
db = db.Order(req.OrderBy)
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
|
78
server/product/internal/handler/getmodelbypidhandler.go
Normal file
78
server/product/internal/handler/getmodelbypidhandler.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/product/internal/logic"
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
)
|
||||
|
||||
func GetModelByPidHandler(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.GetModelByPidReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetModelByPidLogic(r.Context(), svcCtx)
|
||||
resp := l.GetModelByPid(&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)
|
||||
}
|
||||
}
|
||||
}
|
78
server/product/internal/handler/getpricebypidhandler.go
Normal file
78
server/product/internal/handler/getpricebypidhandler.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/product/internal/logic"
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
)
|
||||
|
||||
func GetPriceByPidHandler(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.GetPriceByPidReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetPriceByPidLogic(r.Context(), svcCtx)
|
||||
resp := l.GetPriceByPid(&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)
|
||||
}
|
||||
}
|
||||
}
|
78
server/product/internal/handler/getrenderdesignhandler.go
Normal file
78
server/product/internal/handler/getrenderdesignhandler.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/product/internal/logic"
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
)
|
||||
|
||||
func GetRenderDesignHandler(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.GetRenderDesignReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetRenderDesignLogic(r.Context(), svcCtx)
|
||||
resp := l.GetRenderDesign(&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)
|
||||
}
|
||||
}
|
||||
}
|
78
server/product/internal/handler/gettagproductlisthandler.go
Normal file
78
server/product/internal/handler/gettagproductlisthandler.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/product/internal/logic"
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
)
|
||||
|
||||
func GetTagProductListHandler(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.GetTagProductListReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetTagProductListLogic(r.Context(), svcCtx)
|
||||
resp := l.GetTagProductList(&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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -57,6 +57,26 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/product/recommand",
|
||||
Handler: GetRecommandProductListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/product/tag_product_list",
|
||||
Handler: GetTagProductListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/product/render_design",
|
||||
Handler: GetRenderDesignHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/product/get_model_by_pid",
|
||||
Handler: GetModelByPidHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/product/get_price_by_pid",
|
||||
Handler: GetPriceByPidHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
85
server/product/internal/logic/getmodelbypidlogic.go
Normal file
85
server/product/internal/logic/getmodelbypidlogic.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetModelByPidLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetModelByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetModelByPidLogic {
|
||||
return &GetModelByPidLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetModelByPidLogic) GetModelByPid(req *types.GetModelByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
req.Pid = strings.Trim(req.Pid, " ")
|
||||
if req.Pid == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
|
||||
}
|
||||
//获取产品信息(只是获取id)
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||
}
|
||||
//获取产品尺寸列表(只是获取id)
|
||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
||||
}
|
||||
if len(sizeList) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success:size list is empty", []interface{}{})
|
||||
}
|
||||
sizeIds := make([]int64, 0, len(sizeList))
|
||||
for _, v := range sizeList {
|
||||
sizeIds = append(sizeIds, v.Id)
|
||||
}
|
||||
//获取模型数据(只是获取model_info)
|
||||
model3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,model_info")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model list")
|
||||
}
|
||||
if len(model3dList) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success:model list is empty", []interface{}{})
|
||||
}
|
||||
//处理数据
|
||||
mapModel := make(map[int64]interface{})
|
||||
for _, v := range model3dList {
|
||||
if v.ModelInfo == nil || *v.ModelInfo == "" {
|
||||
mapModel[v.Id] = nil
|
||||
continue
|
||||
}
|
||||
var info interface{}
|
||||
if err = json.Unmarshal([]byte(*v.ModelInfo), &info); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info json")
|
||||
}
|
||||
mapModel[v.Id] = info
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapModel)
|
||||
}
|
78
server/product/internal/logic/getpricebypidlogic.go
Normal file
78
server/product/internal/logic/getpricebypidlogic.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPriceByPidLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetPriceByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPriceByPidLogic {
|
||||
return &GetPriceByPidLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
req.Pid = strings.Trim(req.Pid, " ")
|
||||
if req.Pid == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty")
|
||||
}
|
||||
//获取产品信息(只是获取id)
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||
}
|
||||
//查询产品价格
|
||||
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIds(l.ctx, []int64{productInfo.Id})
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get price list")
|
||||
}
|
||||
//处理价格信息
|
||||
mapRsp := make(map[string]interface{})
|
||||
for _, v := range priceList {
|
||||
mapKey := fmt.Sprintf("_%d", v.Id)
|
||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*v.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("failed to parse step num,price_id=%d", v.Id))
|
||||
}
|
||||
/*$price['step_num'] = explode(',', $price['step_num']);
|
||||
$price['step_price'] = explode(',', $price['step_price']);
|
||||
while ($price['min_buy_num'] < end($price['step_num']) + 5) {
|
||||
$outData["{$price['size_id']}"]['items'][] = [
|
||||
'num' => intval($price['min_buy_num']),
|
||||
'total_num' => $price['min_buy_num'] * $price['each_box_num'],
|
||||
'price' => ProductPriceService::getPrice($price['min_buy_num'], $price['step_num'], $price['step_price'])
|
||||
];
|
||||
$price['min_buy_num'] += 1;
|
||||
}
|
||||
|
||||
$outData["{$price['size_id']}"]['min_price'] = floatval(end($price['step_price']) / 100);
|
||||
$outData["{$price['size_id']}"]['max_price'] = floatval(reset($price['step_price']) / 100);*/
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
|
@ -123,14 +123,11 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
for _, v := range sizeList {
|
||||
model3dInfo, ok := mapModel3dWithSizeIdIndex[v.Id]
|
||||
if !ok {
|
||||
fmt.Println("没有模型:", v.Id)
|
||||
continue
|
||||
}
|
||||
if _, ok = mapTemplateModelId[model3dInfo.Id]; !ok {
|
||||
fmt.Println("没有模板:", v.Id)
|
||||
continue
|
||||
}
|
||||
fmt.Println("剩下的:", v.Id)
|
||||
var title types.SizeTitle
|
||||
if err = json.Unmarshal([]byte(*v.Title), &title); err != nil {
|
||||
logx.Error(err)
|
||||
|
@ -434,7 +431,7 @@ func (l *GetProductInfoLogic) getRenderDesign(clientNo string) interface{} {
|
|||
renderDesign, err := l.svcCtx.AllModels.FsProductRenderDesign.FindOneRenderDesignByParams(l.ctx, gmodel.FindOneRenderDesignByParamsReq{
|
||||
ClientNo: &clientNo,
|
||||
Fields: "id,info,material_id,optional_id,size_id,template_id",
|
||||
SortType: 2,
|
||||
OrderBy: "`id` DESC",
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"gorm.io/gorm"
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
@ -44,13 +45,14 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
|||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", demo)
|
||||
}
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
if req.Page <= 0 && req.Page > 10000 {
|
||||
req.Page = constants.DEFAULT_PAGE
|
||||
}
|
||||
//获取合适尺寸
|
||||
if req.Size > 0 {
|
||||
req.Size = image.GetCurrentSize(req.Size)
|
||||
}
|
||||
pageSize := constants.DEFAULT_PAGE_SIZE
|
||||
//查询用户信息(不用判断存在)
|
||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
|
||||
|
@ -60,7 +62,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
|||
}
|
||||
//查询符合的产品列表
|
||||
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||
productList, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, "sort-desc")
|
||||
productList, total, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, int(req.Page), pageSize, "sort-desc")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||
|
@ -172,6 +174,14 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
|||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{
|
||||
Ob: types.Ob{
|
||||
Items: itemList,
|
||||
}, TypeName: *tagInfo.Title, Description: *tagInfo.Description,
|
||||
Meta: types.Meta{
|
||||
TotalCount: total,
|
||||
PageCount: int64(math.Ceil(float64(total) / float64(pageSize))),
|
||||
CurrentPage: int(req.Page),
|
||||
PerPage: pageSize,
|
||||
},
|
||||
},
|
||||
TypeName: *tagInfo.Title,
|
||||
Description: *tagInfo.Description,
|
||||
})
|
||||
}
|
||||
|
|
73
server/product/internal/logic/getrenderdesignlogic.go
Normal file
73
server/product/internal/logic/getrenderdesignlogic.go
Normal file
|
@ -0,0 +1,73 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetRenderDesignLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetRenderDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRenderDesignLogic {
|
||||
return &GetRenderDesignLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetRenderDesignLogic) GetRenderDesign(req *types.GetRenderDesignReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
req.Sn = strings.Trim(req.Sn, " ")
|
||||
if req.Sn == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:sn is empty")
|
||||
}
|
||||
renderDesign, err := l.svcCtx.AllModels.FsProductRenderDesign.FindOneRenderDesignByParams(l.ctx, gmodel.FindOneRenderDesignByParamsReq{
|
||||
Sn: &req.Sn,
|
||||
Fields: "id,info,material_id,optional_id,size_id,template_id",
|
||||
OrderBy: "`id` DESC",
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "render design is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get render design info")
|
||||
}
|
||||
var color []string
|
||||
if renderDesign.LogoColor != nil && *renderDesign.LogoColor != "" {
|
||||
if err = json.Unmarshal([]byte(*renderDesign.LogoColor), &color); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse render logo color")
|
||||
}
|
||||
}
|
||||
var info interface{}
|
||||
if renderDesign.Info != nil && *renderDesign.Info != "" {
|
||||
if err = json.Unmarshal([]byte(*renderDesign.Info), &info); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse render design info")
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetRenderDesignRsp{
|
||||
Id: renderDesign.Id,
|
||||
Info: info,
|
||||
OptionalId: *renderDesign.OptionalId,
|
||||
SizeId: *renderDesign.SizeId,
|
||||
TemplateId: *renderDesign.TemplateId,
|
||||
LogoColor: color,
|
||||
})
|
||||
}
|
|
@ -63,7 +63,7 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(userinfo *auth.UserInfo) (resp
|
|||
productIds = append(productIds, v.Id)
|
||||
}
|
||||
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||
productSizeList, err := productSizeModel.GetAllByProductIds(l.ctx, productIds, "sort-desc")
|
||||
productSizeList, err := productSizeModel.GetAllByProductIds(l.ctx, productIds, "sort DESC")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
||||
|
|
270
server/product/internal/logic/gettagproductlistlogic.go
Normal file
270
server/product/internal/logic/gettagproductlistlogic.go
Normal file
|
@ -0,0 +1,270 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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 GetTagProductListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetTagProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTagProductListLogic {
|
||||
return &GetTagProductListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
//获取合适尺寸
|
||||
if req.Size > 0 {
|
||||
req.Size = image.GetCurrentSize(req.Size)
|
||||
}
|
||||
//查询用户信息(不用判断存在)
|
||||
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")
|
||||
}
|
||||
//查询分类列表
|
||||
tStatus := int64(1)
|
||||
tReq := gmodel.GetAllTagByParamsReq{
|
||||
Status: &tStatus,
|
||||
OrderBy: "`sort` DESC",
|
||||
WithChild: true, //需要子集
|
||||
}
|
||||
//传入分类id
|
||||
if req.Cid > 0 {
|
||||
//获取该类行的levelprefix
|
||||
tagData, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, req.Cid)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found")
|
||||
}
|
||||
}
|
||||
tReq.LevelPrefixLeftLike = *tagData.LevelPrefix
|
||||
}
|
||||
tagList, err := l.svcCtx.AllModels.FsTags.GetAllTagByParams(l.ctx, tReq)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag list")
|
||||
}
|
||||
if len(tagList) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
||||
}
|
||||
typeIds := make([]int64, 0, len(tagList))
|
||||
for _, v := range tagList {
|
||||
typeIds = append(typeIds, v.Id)
|
||||
}
|
||||
//查询符合的产品列表
|
||||
pIsDel := int64(0)
|
||||
pStatus := int64(1)
|
||||
pIsShelf := int64(1)
|
||||
pReq := gmodel.GetProductListByParamsReq{
|
||||
Type: typeIds,
|
||||
IsDel: &pIsDel,
|
||||
IsShelf: &pIsShelf,
|
||||
Status: &pStatus,
|
||||
OrderBy: "`sort` DESC",
|
||||
}
|
||||
//获取产品列表
|
||||
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByParams(l.ctx, pReq)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||
}
|
||||
//提取产品ids
|
||||
productIds := make([]int64, 0, len(productList))
|
||||
for _, v := range productList {
|
||||
productIds = append(productIds, v.Id)
|
||||
}
|
||||
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")
|
||||
}
|
||||
//存储产品最小价格
|
||||
mapProductMinPrice := make(map[int64]int64)
|
||||
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)
|
||||
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||
}
|
||||
//获取模板
|
||||
productTemplatesV2, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get product template_v2 err")
|
||||
}
|
||||
mapProductTemplate := make(map[int64]struct{})
|
||||
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")
|
||||
}
|
||||
mapProductSizeCount := make(map[int64]int64)
|
||||
for _, v := range productSizeCountList {
|
||||
mapProductSizeCount[v.ProductId] = v.Num
|
||||
}
|
||||
mapTagLevel := make(map[string]*types.TagItem)
|
||||
minLevel := int64(0) //记录最小等级数字
|
||||
for _, tagInfo := range tagList {
|
||||
if minLevel == 0 && *tagInfo.Level > 0 {
|
||||
minLevel = *tagInfo.Level
|
||||
}
|
||||
if minLevel > *tagInfo.Level {
|
||||
minLevel = *tagInfo.Level
|
||||
}
|
||||
//获取分类产品列表
|
||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||
TagId: tagInfo.Id,
|
||||
ProductList: productList,
|
||||
MapProductMinPrice: mapProductMinPrice,
|
||||
MapProductTemplate: mapProductTemplate,
|
||||
MapProductSizeCount: mapProductSizeCount,
|
||||
Size: req.Size,
|
||||
User: user,
|
||||
})
|
||||
//加入分类
|
||||
tagTem := types.TagItem{
|
||||
TagProductList: productListRsp,
|
||||
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, 100),
|
||||
}
|
||||
//当前tag保存入map
|
||||
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||
}
|
||||
//组装等级从属关系
|
||||
for prefix, tagItem := range mapTagLevel {
|
||||
prefix = strings.Trim(prefix, " ")
|
||||
//最上级没有父级
|
||||
if !strings.Contains(prefix, "/") {
|
||||
continue
|
||||
}
|
||||
prefixSlice := strings.Split(prefix, "/")
|
||||
//有父级
|
||||
parentPrefix := strings.Join(prefixSlice[:len(prefixSlice)-1], "/")
|
||||
if parent, ok := mapTagLevel[parentPrefix]; ok {
|
||||
parent.ChildTagList = append(parent.ChildTagList, tagItem)
|
||||
//排序
|
||||
sort.Slice(parent.ChildTagList, func(i, j int) bool {
|
||||
return parent.ChildTagList[i].Sort < parent.ChildTagList[j].Sort
|
||||
})
|
||||
mapTagLevel[parentPrefix] = parent
|
||||
}
|
||||
}
|
||||
//最终值提取最高级别那一层出来
|
||||
tagListRsp := make([]types.TagItem, 0, len(mapTagLevel))
|
||||
for _, v := range mapTagLevel {
|
||||
if v.Level != minLevel {
|
||||
continue
|
||||
}
|
||||
tagListRsp = append(tagListRsp, *v)
|
||||
}
|
||||
//排序
|
||||
sort.Slice(tagListRsp, func(i, j int) bool {
|
||||
return tagListRsp[i].Sort < tagListRsp[j].Sort
|
||||
})
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetTagProductListRsp{
|
||||
TotalCategory: len(mapTagLevel),
|
||||
TagList: tagListRsp,
|
||||
})
|
||||
}
|
||||
|
||||
// 获取对应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
|
||||
}
|
||||
|
||||
func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productListRsp []types.TagProduct) {
|
||||
//默认给50个容量
|
||||
productListRsp = make([]types.TagProduct, 0, 50)
|
||||
for _, productInfo := range req.ProductList {
|
||||
//不属于一个类型则跳过
|
||||
if *productInfo.Type != req.TagId {
|
||||
continue
|
||||
}
|
||||
minPrice, ok := req.MapProductMinPrice[productInfo.Id]
|
||||
_, tmpOk := req.MapProductTemplate[productInfo.Id]
|
||||
//无最小价格则不显示 || 没有模板也不显示
|
||||
if !ok || !tmpOk {
|
||||
continue
|
||||
}
|
||||
sizeNum := int64(0)
|
||||
if mapSizeNum, ok := req.MapProductSizeCount[productInfo.Id]; ok {
|
||||
sizeNum = mapSizeNum
|
||||
}
|
||||
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,
|
||||
}
|
||||
//千人千面处理
|
||||
r := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: 0,
|
||||
Cover: *productInfo.Cover,
|
||||
CoverImg: *productInfo.CoverImg,
|
||||
CoverDefault: *productInfo.CoverImg,
|
||||
ProductId: productInfo.Id,
|
||||
UserId: req.User.Id,
|
||||
}
|
||||
if req.User.Id != 0 {
|
||||
r.IsThousandFace = int(*req.User.IsThousandFace)
|
||||
}
|
||||
image.ThousandFaceImageFormat(&r)
|
||||
item.Cover = r.Cover
|
||||
item.CoverImg = r.CoverImg
|
||||
item.CoverDefault = r.CoverDefault
|
||||
//加入分类产品切片
|
||||
productListRsp = append(productListRsp, item)
|
||||
}
|
||||
return productListRsp
|
||||
}
|
|
@ -23,10 +23,6 @@ type Ob struct {
|
|||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
|
||||
type HrefUrl struct {
|
||||
Href string `json:"href"`
|
||||
}
|
||||
|
||||
type Items struct {
|
||||
Id int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
|
@ -248,6 +244,63 @@ type GetRecommandProductListRsp struct {
|
|||
Intro string `json:"intro"`
|
||||
}
|
||||
|
||||
type GetTagProductListReq struct {
|
||||
Cid int64 `form:"cid,optional"` //分类id
|
||||
Size uint32 `form:"size,optional"` //尺寸
|
||||
}
|
||||
|
||||
type GetTagProductListRsp struct {
|
||||
TotalCategory int `json:"total_category"`
|
||||
TagList []TagItem `json:"tag_list"`
|
||||
}
|
||||
|
||||
type TagItem struct {
|
||||
TypeName string `json:"type_name"`
|
||||
TypeId int64 `json:"type_id"`
|
||||
Description string `json:"description"`
|
||||
Level int64 `json:"level"`
|
||||
LevelPrefix string `json:"level_prefix"`
|
||||
Icon string `json:"icon"`
|
||||
Sort int64 `json:"sort"`
|
||||
TagProductList []TagProduct `json:"tag_product_list"`
|
||||
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type GetRenderDesignReq struct {
|
||||
Sn string `form:"sn"`
|
||||
}
|
||||
|
||||
type GetRenderDesignRsp struct {
|
||||
Id int64 `json:"id"`
|
||||
Info interface{} `json:"info"`
|
||||
OptionalId int64 `json:"optional_id"`
|
||||
SizeId int64 `json:"size_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
LogoColor []string `json:"logo_color"`
|
||||
}
|
||||
|
||||
type GetModelByPidReq struct {
|
||||
Pid string `form:"pid"` //实际上是产品sn
|
||||
}
|
||||
|
||||
type GetPriceByPidReq struct {
|
||||
Pid string `form:"pid"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,20 @@ service product {
|
|||
//获取详情页推荐产品列表
|
||||
@handler GetRecommandProductListHandler
|
||||
get /api/product/recommand (GetRecommandProductListReq) returns (response);
|
||||
//获取分类产品列表
|
||||
@handler GetTagProductListHandler
|
||||
get /api/product/tag_product_list(GetTagProductListReq) returns (response);
|
||||
//*********************产品详情分解接口开始***********************
|
||||
//获取云渲染设计方案信息
|
||||
@handler GetRenderDesignHandler
|
||||
get /api/product/render_design(GetRenderDesignReq) returns (response);
|
||||
//获取产品模型信息
|
||||
@handler GetModelByPidHandler
|
||||
get /api/product/get_model_by_pid(GetModelByPidReq) returns (response);
|
||||
//获取产品阶梯价格列表
|
||||
@handler GetPriceByPidHandler
|
||||
get /api/product/get_price_by_pid(GetPriceByPidReq) returns (response);
|
||||
//*********************产品详情分解接口结束***********************
|
||||
}
|
||||
|
||||
//获取产品列表
|
||||
|
@ -55,9 +69,6 @@ type Ob {
|
|||
Items []Items `json:"items"`
|
||||
Meta Meta `json:"_meta"`
|
||||
}
|
||||
type HrefUrl {
|
||||
Href string `json:"href"`
|
||||
}
|
||||
type Items {
|
||||
Id int64 `json:"id"`
|
||||
Sn string `json:"sn"`
|
||||
|
@ -259,4 +270,58 @@ type GetRecommandProductListRsp {
|
|||
CoverImg string `json:"cover_img"`
|
||||
CoverDefault string `json:"cover_default"`
|
||||
Intro string `json:"intro"`
|
||||
}
|
||||
//获取分类产品列表
|
||||
type GetTagProductListReq {
|
||||
Cid int64 `form:"cid,optional"` //分类id
|
||||
Size uint32 `form:"size,optional"` //尺寸
|
||||
}
|
||||
type GetTagProductListRsp {
|
||||
TotalCategory int `json:"total_category"`
|
||||
TagList []TagItem `json:"tag_list"`
|
||||
}
|
||||
type TagItem {
|
||||
TypeName string `json:"type_name"`
|
||||
TypeId int64 `json:"type_id"`
|
||||
Description string `json:"description"`
|
||||
Level int64 `json:"level"`
|
||||
LevelPrefix string `json:"level_prefix"`
|
||||
Icon string `json:"icon"`
|
||||
Sort int64 `json:"sort"`
|
||||
TagProductList []TagProduct `json:"tag_product_list"`
|
||||
ChildTagList []*TagItem `json:"child_tag_list"`
|
||||
}
|
||||
type TagProduct {
|
||||
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"`
|
||||
}
|
||||
//获取云渲染设计方案信息
|
||||
type GetRenderDesignReq {
|
||||
Sn string `form:"sn"`
|
||||
}
|
||||
type GetRenderDesignRsp {
|
||||
Id int64 `json:"id"`
|
||||
Info interface{} `json:"info"`
|
||||
OptionalId int64 `json:"optional_id"`
|
||||
SizeId int64 `json:"size_id"`
|
||||
TemplateId int64 `json:"template_id"`
|
||||
LogoColor []string `json:"logo_color"`
|
||||
}
|
||||
|
||||
//获取产品模型信息
|
||||
type GetModelByPidReq {
|
||||
Pid string `form:"pid"` //实际上是产品sn
|
||||
}
|
||||
//获取产品阶梯价格
|
||||
type GetPriceByPidReq {
|
||||
Pid string `form:"pid"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user