fix
This commit is contained in:
parent
406d62a894
commit
98c5727c7e
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -29,6 +29,7 @@ type CountProductSizeByStatusRsp struct {
|
|||||||
ProductId int64 `json:"product_id"`
|
ProductId int64 `json:"product_id"`
|
||||||
Num int64 `json:"num"`
|
Num int64 `json:"num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context, productIds []int64, status int) (resp []CountProductSizeByStatusRsp, err error) {
|
func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context, productIds []int64, status int) (resp []CountProductSizeByStatusRsp, err error) {
|
||||||
err = s.db.WithContext(ctx).Model(&FsProductSize{}).
|
err = s.db.WithContext(ctx).Model(&FsProductSize{}).
|
||||||
Select("product_id,count(*) as num").
|
Select("product_id,count(*) as num").
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -80,6 +80,7 @@ type GetProductTemplateListByParamsReq struct {
|
|||||||
Fields string
|
Fields string
|
||||||
Status *int64
|
Status *int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Context, req GetProductTemplateListByParamsReq) (resp []FsProductTemplateV2, err error) {
|
func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Context, req GetProductTemplateListByParamsReq) (resp []FsProductTemplateV2, err error) {
|
||||||
if len(req.ProductIds) == 0 {
|
if len(req.ProductIds) == 0 {
|
||||||
return
|
return
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -1,2 +1,3 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
@ -2,10 +2,12 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fusenapi/server/home-user-auth/internal/svc"
|
"fusenapi/server/home-user-auth/internal/svc"
|
||||||
"fusenapi/server/home-user-auth/internal/types"
|
"fusenapi/server/home-user-auth/internal/types"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
@ -35,6 +37,9 @@ func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.Us
|
|||||||
|
|
||||||
user, err := m.FindUserById(l.ctx, userinfo.UserId)
|
user, err := m.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user is not exists")
|
||||||
|
}
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeServiceErr)
|
return resp.SetStatus(basic.CodeServiceErr)
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ func (l *GetOrderInvoiceLogic) GetOrderInvoice(req *types.GetOrderInvoiceReq, us
|
|||||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
|
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user not found")
|
||||||
|
}
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
||||||
}
|
}
|
||||||
if user.Id == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user not found")
|
|
||||||
}
|
|
||||||
if req.Sn == "" {
|
if req.Sn == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
|
||||||
}
|
}
|
||||||
|
@ -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 GetRecommandProductListHandler(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.GetRecommandProductListReq
|
||||||
|
// 如果端点有请求结构体,则使用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.NewGetRecommandProductListLogic(r.Context(), svcCtx)
|
||||||
|
resp := l.GetRecommandProductList(&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,6 +52,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/product/other-list",
|
Path: "/product/other-list",
|
||||||
Handler: OtherProductListHandler(serverCtx),
|
Handler: OtherProductListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/product/recommand",
|
||||||
|
Handler: GetRecommandProductListHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,6 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||||||
|
|
||||||
// 获取产品列表
|
// 获取产品列表
|
||||||
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
|
||||||
}
|
|
||||||
//如果是demo
|
//如果是demo
|
||||||
if req.IsDemo == 1 {
|
if req.IsDemo == 1 {
|
||||||
var demo types.GetProductListRsp
|
var demo types.GetProductListRsp
|
||||||
@ -54,16 +51,13 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
|||||||
if req.Size > 0 {
|
if req.Size > 0 {
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
}
|
}
|
||||||
//查询用户信息
|
//查询用户信息(不用判断存在)
|
||||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
userInfo, err := userModel.FindUserById(l.ctx, userinfo.UserId)
|
user, err := userModel.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
}
|
}
|
||||||
if userInfo.Id == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "user not exists")
|
|
||||||
}
|
|
||||||
//查询符合的产品列表
|
//查询符合的产品列表
|
||||||
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||||
productList, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, "sort-desc")
|
productList, err := productModel.GetProductListByTypeIds(l.ctx, []int64{req.Cid}, "sort-desc")
|
||||||
@ -157,19 +151,22 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
|||||||
MiniPrice: minPrice,
|
MiniPrice: minPrice,
|
||||||
}
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: int(*userInfo.IsThousandFace),
|
IsThousandFace: 0,
|
||||||
Cover: *v.Cover,
|
Cover: *v.Cover,
|
||||||
CoverImg: *v.CoverImg,
|
CoverImg: *v.CoverImg,
|
||||||
CoverDefault: *v.CoverImg,
|
CoverDefault: *v.CoverImg,
|
||||||
ProductId: v.Id,
|
ProductId: v.Id,
|
||||||
UserInfo: userInfo,
|
UserId: user.Id,
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
if user.Id != 0 {
|
||||||
item.Cover = thousandFaceImageFormatReq.Cover
|
r.IsThousandFace = int(*user.IsThousandFace)
|
||||||
item.CoverImg = thousandFaceImageFormatReq.CoverImg
|
}
|
||||||
item.CoverDefault = thousandFaceImageFormatReq.CoverDefault
|
image.ThousandFaceImageFormat(&r)
|
||||||
|
item.Cover = r.Cover
|
||||||
|
item.CoverImg = r.CoverImg
|
||||||
|
item.CoverDefault = r.CoverDefault
|
||||||
itemList = append(itemList, item)
|
itemList = append(itemList, item)
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductListRsp{
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
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 GetRecommandProductListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetRecommandProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommandProductListLogic {
|
||||||
|
return &GetRecommandProductListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRecommandProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
req.Num = 8 //目前写死
|
||||||
|
if req.Size > 0 {
|
||||||
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
|
}
|
||||||
|
//随机取产品列表
|
||||||
|
productList, err := l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx, int(req.Num))
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get random recommend product list")
|
||||||
|
}
|
||||||
|
if len(productList) == 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
||||||
|
}
|
||||||
|
//获取用户信息(不用判断存在)
|
||||||
|
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.CodeDbSqlErr, "failed to get user")
|
||||||
|
}
|
||||||
|
list := make([]types.GetRecommandProductListRsp, 0, len(productList))
|
||||||
|
for _, v := range productList {
|
||||||
|
r := image.ThousandFaceImageFormatReq{
|
||||||
|
Size: int(req.Size),
|
||||||
|
IsThousandFace: 0,
|
||||||
|
Cover: *v.Cover,
|
||||||
|
CoverImg: *v.CoverImg,
|
||||||
|
CoverDefault: *v.Cover,
|
||||||
|
ProductId: v.Id,
|
||||||
|
UserId: userinfo.UserId,
|
||||||
|
}
|
||||||
|
if user.Id != 0 {
|
||||||
|
r.IsThousandFace = int(*user.IsThousandFace)
|
||||||
|
}
|
||||||
|
image.ThousandFaceImageFormat(&r)
|
||||||
|
list = append(list, types.GetRecommandProductListRsp{
|
||||||
|
Id: v.Id,
|
||||||
|
Sn: *v.Sn,
|
||||||
|
Title: *v.Title,
|
||||||
|
TitleCn: *v.TitleCn,
|
||||||
|
Cover: r.Cover,
|
||||||
|
CoverImg: r.CoverImg,
|
||||||
|
CoverDefault: r.CoverDefault,
|
||||||
|
Intro: *v.Intro,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
||||||
|
}
|
@ -2,6 +2,7 @@ package logic
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
@ -9,6 +10,7 @@ import (
|
|||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSuccessRecommandLogic struct {
|
type GetSuccessRecommandLogic struct {
|
||||||
@ -33,13 +35,10 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
|||||||
//获取用户信息
|
//获取用户信息
|
||||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||||
user, err := userModel.FindUserById(l.ctx, userInfo.UserId)
|
user, err := userModel.FindUserById(l.ctx, userInfo.UserId)
|
||||||
if err != nil {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
||||||
}
|
}
|
||||||
if user.Id == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "failed to get user info")
|
|
||||||
}
|
|
||||||
if req.Num == 0 || req.Num > 500 {
|
if req.Num == 0 || req.Num > 500 {
|
||||||
req.Num = 8
|
req.Num = 8
|
||||||
}
|
}
|
||||||
@ -66,19 +65,22 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
|||||||
SkuId: 0, //???????
|
SkuId: 0, //???????
|
||||||
}
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: int(*user.IsThousandFace),
|
IsThousandFace: 0,
|
||||||
Cover: *v.Cover,
|
Cover: *v.Cover,
|
||||||
CoverImg: *v.CoverImg,
|
CoverImg: *v.CoverImg,
|
||||||
CoverDefault: *v.CoverImg,
|
CoverDefault: *v.CoverImg,
|
||||||
ProductId: v.Id,
|
ProductId: v.Id,
|
||||||
UserInfo: user,
|
UserId: user.Id,
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
if user.Id > 0 {
|
||||||
data.Cover = thousandFaceImageFormatReq.Cover
|
r.IsThousandFace = int(*user.IsThousandFace)
|
||||||
data.CoverImg = thousandFaceImageFormatReq.CoverImg
|
}
|
||||||
data.CoverDefault = thousandFaceImageFormatReq.CoverDefault
|
image.ThousandFaceImageFormat(&r)
|
||||||
|
data.Cover = r.Cover
|
||||||
|
data.CoverImg = r.CoverImg
|
||||||
|
data.CoverDefault = r.CoverDefault
|
||||||
list = append(list, data)
|
list = append(list, data)
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", list)
|
||||||
|
@ -32,9 +32,6 @@ func NewOtherProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
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 > 100 {
|
if req.Num <= 0 || req.Num > 100 {
|
||||||
req.Num = 4
|
req.Num = 4
|
||||||
}
|
}
|
||||||
@ -43,10 +40,7 @@ func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq,
|
|||||||
}
|
}
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
if errors.Is(err,gorm.ErrRecordNotFound){
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth,"user not exists")
|
|
||||||
}
|
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user info")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user info")
|
||||||
}
|
}
|
||||||
@ -81,12 +75,15 @@ func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq,
|
|||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
r := &image.ThousandFaceImageFormatReq{
|
r := &image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: int(*user.IsThousandFace),
|
IsThousandFace: 0,
|
||||||
Cover: v.Cover,
|
Cover: v.Cover,
|
||||||
CoverImg: v.CoverImg,
|
CoverImg: v.CoverImg,
|
||||||
CoverDefault: "",
|
CoverDefault: "",
|
||||||
ProductId: v.Id,
|
ProductId: v.Id,
|
||||||
UserInfo: user,
|
UserId: user.Id,
|
||||||
|
}
|
||||||
|
if user.Id > 0 {
|
||||||
|
r.IsThousandFace = int(*user.IsThousandFace)
|
||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(r)
|
image.ThousandFaceImageFormat(r)
|
||||||
v.Cover = r.Cover
|
v.Cover = r.Cover
|
||||||
|
@ -231,6 +231,23 @@ type OtherProductListRsp struct {
|
|||||||
SkuId int64 `json:"sku_id"`
|
SkuId int64 `json:"sku_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetRecommandProductListReq struct {
|
||||||
|
Size uint32 `form:"size"`
|
||||||
|
Num int64 `form:"num"`
|
||||||
|
Sn string `form:"sn"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetRecommandProductListRsp struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
TitleCn string `json:"title_cn"`
|
||||||
|
Cover string `json:"cover"`
|
||||||
|
CoverImg string `json:"cover_img"`
|
||||||
|
CoverDefault string `json:"cover_default"`
|
||||||
|
Intro string `json:"intro"`
|
||||||
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ service product {
|
|||||||
//获取产品列表
|
//获取产品列表
|
||||||
@handler GetProductListHandler
|
@handler GetProductListHandler
|
||||||
get /product/list(GetProductListReq) returns (response);
|
get /product/list(GetProductListReq) returns (response);
|
||||||
//获取成功后的推荐产品
|
//获取支付成功后推荐产品
|
||||||
@handler GetSuccessRecommandHandler
|
@handler GetSuccessRecommandHandler
|
||||||
get /product/success-recommand (GetSuccessRecommandReq) returns (response);
|
get /product/success-recommand (GetSuccessRecommandReq) returns (response);
|
||||||
//获取分类下的产品以及尺寸
|
//获取分类下的产品以及尺寸
|
||||||
@ -34,6 +34,9 @@ service product {
|
|||||||
//其他产品推荐列表
|
//其他产品推荐列表
|
||||||
@handler OtherProductListHandler
|
@handler OtherProductListHandler
|
||||||
get /product/other-list (OtherProductListReq) returns (response);
|
get /product/other-list (OtherProductListReq) returns (response);
|
||||||
|
//获取详情页推荐产品列表
|
||||||
|
@handler GetRecommandProductListHandler
|
||||||
|
get /product/recommand (GetRecommandProductListReq) returns (response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取产品列表
|
//获取产品列表
|
||||||
@ -68,7 +71,7 @@ type Items {
|
|||||||
MiniPrice int64 `json:"miniPrice"`
|
MiniPrice int64 `json:"miniPrice"`
|
||||||
CoverDefault string `json:"coverDefault"`
|
CoverDefault string `json:"coverDefault"`
|
||||||
}
|
}
|
||||||
//获取成功后的推荐产品
|
//获取支付成功后推荐产品
|
||||||
type GetSuccessRecommandReq {
|
type GetSuccessRecommandReq {
|
||||||
Num uint32 `form:"num"`
|
Num uint32 `form:"num"`
|
||||||
Size uint32 `form:"size"`
|
Size uint32 `form:"size"`
|
||||||
@ -241,3 +244,19 @@ type OtherProductListRsp {
|
|||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
SkuId int64 `json:"sku_id"`
|
SkuId int64 `json:"sku_id"`
|
||||||
}
|
}
|
||||||
|
//获取详情页推荐产品列表
|
||||||
|
type GetRecommandProductListReq {
|
||||||
|
Size uint32 `form:"size"`
|
||||||
|
Num int64 `form:"num"`
|
||||||
|
Sn string `form:"sn"`
|
||||||
|
}
|
||||||
|
type GetRecommandProductListRsp {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Sn string `json:"sn"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
TitleCn string `json:"title_cn"`
|
||||||
|
Cover string `json:"cover"`
|
||||||
|
CoverImg string `json:"cover_img"`
|
||||||
|
CoverDefault string `json:"cover_default"`
|
||||||
|
Intro string `json:"intro"`
|
||||||
|
}
|
@ -3,7 +3,6 @@ package image
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model/gmodel"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -41,7 +40,7 @@ type ThousandFaceImageFormatReq struct {
|
|||||||
CoverImg string
|
CoverImg string
|
||||||
CoverDefault string
|
CoverDefault string
|
||||||
ProductId int64
|
ProductId int64
|
||||||
UserInfo gmodel.FsUser
|
UserId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
||||||
@ -61,7 +60,7 @@ func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
|||||||
req.Cover = ""
|
req.Cover = ""
|
||||||
req.CoverDefault = req.CoverImg
|
req.CoverDefault = req.CoverImg
|
||||||
if req.Size >= 200 && len(coverSlice) >= 2 && len(coverImgSlice) >= 2 {
|
if req.Size >= 200 && len(coverSlice) >= 2 && len(coverImgSlice) >= 2 {
|
||||||
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserInfo.Id, req.UserInfo.Id, req.ProductId, time.Now().Unix())
|
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserId, req.UserId, req.ProductId, time.Now().Unix())
|
||||||
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user