Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
5f3d6eb120
|
@ -64,13 +64,15 @@ func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTyp
|
||||||
func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
|
func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
|
||||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).
|
err = p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||||
Where("`is_del` =? and `is_shelf` = ?", 0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
Where("`is_del` =? and `is_shelf` = ?", 0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
||||||
if err != nil {
|
return resp,err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (resp []*FsProduct, err error) {
|
func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (resp []*FsProduct, err error) {
|
||||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context,ids []int64, limit int) (resp []FsProduct, err error) {
|
||||||
|
err = p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||||
|
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids,0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
||||||
|
return resp,err
|
||||||
|
}
|
78
server/product/internal/handler/otherproductlisthandler.go
Normal file
78
server/product/internal/handler/otherproductlisthandler.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 OtherProductListHandler(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.OtherProductListReq
|
||||||
|
// 如果端点有请求结构体,则使用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.NewOtherProductListLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.OtherProductList(&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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -47,6 +47,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/product/save-design",
|
Path: "/product/save-design",
|
||||||
Handler: SaveDesignHandler(serverCtx),
|
Handler: SaveDesignHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/product/other-list",
|
||||||
|
Handler: OtherProductListHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||||
IsEnv: *v.IsProtection,
|
IsEnv: *v.IsProtection,
|
||||||
IsMicro: *v.IsMicrowave,
|
IsMicro: *v.IsMicrowave,
|
||||||
SizeNum: uint32(sizeNum),
|
SizeNum: uint32(sizeNum),
|
||||||
MiniPrice: format.CentoDollar(minPrice),
|
MiniPrice: minPrice,
|
||||||
}
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
||||||
|
|
60
server/product/internal/logic/otherproductlistlogic.go
Normal file
60
server/product/internal/logic/otherproductlistlogic.go
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fusenapi/utils/auth"
|
||||||
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/image"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"fusenapi/server/product/internal/svc"
|
||||||
|
"fusenapi/server/product/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OtherProductListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOtherProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OtherProductListLogic {
|
||||||
|
return &OtherProductListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
|
}
|
||||||
|
if req.Num <= 0 {
|
||||||
|
req.Num = 4
|
||||||
|
}
|
||||||
|
if req.Size > 0{
|
||||||
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
|
}
|
||||||
|
tagInfo,err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx,req.Cid)
|
||||||
|
if err != nil{
|
||||||
|
if errors.Is(err,gorm.ErrRecordNotFound){
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr,"the tag info is not exists")
|
||||||
|
}
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get tage info")
|
||||||
|
}
|
||||||
|
if *tagInfo.Status != 1{
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"tage info is not available")
|
||||||
|
}
|
||||||
|
if tagInfo.RecommendProduct == nil || *tagInfo.RecommendProduct == "" {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK,"success")
|
||||||
|
}
|
||||||
|
//获取推荐产品信息
|
||||||
|
l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx,)
|
||||||
|
//TODO 明天再做
|
||||||
|
return resp.SetStatus(basic.CodeOK)
|
||||||
|
}
|
|
@ -28,17 +28,17 @@ type HrefUrl struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Items struct {
|
type Items struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Sn string `json:"sn"`
|
Sn string `json:"sn"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
Intro string `json:"intro"`
|
Intro string `json:"intro"`
|
||||||
CoverImg string `json:"cover_img"`
|
CoverImg string `json:"cover_img"`
|
||||||
IsEnv int64 `json:"isEnv"`
|
IsEnv int64 `json:"isEnv"`
|
||||||
IsMicro int64 `json:"isMicro"`
|
IsMicro int64 `json:"isMicro"`
|
||||||
SizeNum uint32 `json:"sizeNum"`
|
SizeNum uint32 `json:"sizeNum"`
|
||||||
MiniPrice float64 `json:"miniPrice"`
|
MiniPrice int64 `json:"miniPrice"`
|
||||||
CoverDefault string `json:"coverDefault"`
|
CoverDefault string `json:"coverDefault"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetSuccessRecommandReq struct {
|
type GetSuccessRecommandReq struct {
|
||||||
|
@ -215,6 +215,21 @@ type ColorFill struct {
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OtherProductListReq struct {
|
||||||
|
Cid int64 `json:"cid"`
|
||||||
|
Num int64 `json:"num"`
|
||||||
|
Size uint32 `json:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type OtherProductListRsp struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Cover string `json:"cover"`
|
||||||
|
CoverImg string `json:"cover_img"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
SkuId int64 `json:"sku_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ service product {
|
||||||
//保存设计信息
|
//保存设计信息
|
||||||
@handler SaveDesignHandler
|
@handler SaveDesignHandler
|
||||||
post /product/save-design(SaveDesignReq) returns (response);
|
post /product/save-design(SaveDesignReq) returns (response);
|
||||||
|
//其他产品推荐列表
|
||||||
|
@handler OtherProductListHandler
|
||||||
|
post /product/other-list (OtherProductListReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品列表
|
//获取产品列表
|
||||||
|
@ -53,17 +56,17 @@ type HrefUrl {
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
}
|
}
|
||||||
type Items {
|
type Items {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Sn string `json:"sn"`
|
Sn string `json:"sn"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
Intro string `json:"intro"`
|
Intro string `json:"intro"`
|
||||||
CoverImg string `json:"cover_img"`
|
CoverImg string `json:"cover_img"`
|
||||||
IsEnv int64 `json:"isEnv"`
|
IsEnv int64 `json:"isEnv"`
|
||||||
IsMicro int64 `json:"isMicro"`
|
IsMicro int64 `json:"isMicro"`
|
||||||
SizeNum uint32 `json:"sizeNum"`
|
SizeNum uint32 `json:"sizeNum"`
|
||||||
MiniPrice float64 `json:"miniPrice"`
|
MiniPrice int64 `json:"miniPrice"`
|
||||||
CoverDefault string `json:"coverDefault"`
|
CoverDefault string `json:"coverDefault"`
|
||||||
}
|
}
|
||||||
//获取成功后的推荐产品
|
//获取成功后的推荐产品
|
||||||
type GetSuccessRecommandReq {
|
type GetSuccessRecommandReq {
|
||||||
|
@ -222,4 +225,18 @@ type DesignLogo {
|
||||||
}
|
}
|
||||||
type ColorFill {
|
type ColorFill {
|
||||||
Fill string `json:"fill"`
|
Fill string `json:"fill"`
|
||||||
|
}
|
||||||
|
//其他产品推荐列表
|
||||||
|
type OtherProductListReq {
|
||||||
|
Cid int64 `json:"cid"`
|
||||||
|
Num int64 `json:"num"`
|
||||||
|
Size uint32 `json:"size"`
|
||||||
|
}
|
||||||
|
type OtherProductListRsp {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Cover string `json:"cover"`
|
||||||
|
CoverImg string `json:"cover_img"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
SkuId int64 `json:"sku_id"`
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user