fix
This commit is contained in:
parent
eedce6c2d7
commit
e1bc5fbe51
|
@ -48,6 +48,6 @@ func (o *FsOrderModel) FindOneAndCreateServiceContact(ctx context.Context, userI
|
|||
|
||||
// 获取用户最近下单成功的订单
|
||||
func (o *FsOrderModel) FindLastSuccessOneOrder(ctx context.Context, userId int64, statusGt int64) (order *FsOrder, err error) {
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `status` > ?", userId, statusGt).Order("id DESC").Find(&order).Error
|
||||
err = o.db.WithContext(ctx).Model(&FsOrder{}).Where("`user_id` = ? and `status` > ?", userId, statusGt).Order("id DESC").Take(&order).Error
|
||||
return order, err
|
||||
}
|
||||
|
|
|
@ -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 GetRenderSettingByPidHandler(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.GetRenderSettingByPidReq
|
||||
// 如果端点有请求结构体,则使用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.NewGetRenderSettingByPidLogic(r.Context(), svcCtx)
|
||||
resp := l.GetRenderSettingByPid(&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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -97,6 +97,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/product/get_light_by_pid",
|
||||
Handler: GetLightByPidHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/product/get_render_setting_by_pid",
|
||||
Handler: GetRenderSettingByPidHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
152
server/product/internal/logic/getrendersettingbypidlogic.go
Normal file
152
server/product/internal/logic/getrendersettingbypidlogic.go
Normal file
|
@ -0,0 +1,152 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/color_list"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetRenderSettingByPidLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetRenderSettingByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRenderSettingByPidLogic {
|
||||
return &GetRenderSettingByPidLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetRenderSettingByPidLogic) GetRenderSettingByPid(req *types.GetRenderSettingByPidReq, 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")
|
||||
}
|
||||
//获取产品信息
|
||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid)
|
||||
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")
|
||||
}
|
||||
//获取产品分类
|
||||
tagInfo, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, *productInfo.Type)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product tag is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
|
||||
}
|
||||
//是否低效果渲染
|
||||
isLowRendering := false
|
||||
//是否移除背景
|
||||
isRemoveBg := false
|
||||
//是否存在最新设计
|
||||
lastDesign := false
|
||||
//是否拥有云渲染设计方案
|
||||
renderDesign := false
|
||||
renderDesign, err = l.checkRenderDesign(req.ClientNo)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to checkRenderDesign")
|
||||
}
|
||||
if userinfo.UserId != 0 {
|
||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusAddMessage(basic.CodeDbRecordNotFoundErr, "user info is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user info")
|
||||
}
|
||||
isLowRendering = *user.IsLowRendering > 0
|
||||
isRemoveBg = *user.IsRemoveBg > 0
|
||||
lastDesign, err = l.checkLastDesignExists(user.Id)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to check if exists last design ")
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetRenderSettingByPidRsp{
|
||||
Id: productInfo.Id,
|
||||
Type: *productInfo.Type,
|
||||
Title: *productInfo.Title,
|
||||
IsEnv: *productInfo.IsProtection,
|
||||
IsMicro: *productInfo.IsMicrowave,
|
||||
TypeName: *tagInfo.Title,
|
||||
IsLowRendering: isLowRendering,
|
||||
IsRemoveBg: isRemoveBg,
|
||||
RenderDesign: renderDesign,
|
||||
LastDesign: lastDesign,
|
||||
Colors: color_list.GetColor(),
|
||||
})
|
||||
}
|
||||
|
||||
// 查询是否存在渲染设计
|
||||
func (l *GetRenderSettingByPidLogic) checkRenderDesign(clientNo string) (bool, error) {
|
||||
if clientNo == "" {
|
||||
return false, nil
|
||||
}
|
||||
renderDesign, err := l.svcCtx.AllModels.FsProductRenderDesign.FindOneRenderDesignByParams(l.ctx, gmodel.FindOneRenderDesignByParamsReq{
|
||||
ClientNo: &clientNo,
|
||||
Fields: "id,info,material_id,optional_id,size_id,template_id",
|
||||
OrderBy: "`id` DESC",
|
||||
})
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if renderDesign.Info != nil && *renderDesign.Info != "" {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 查询是否存在最新设计
|
||||
func (l *GetRenderSettingByPidLogic) checkLastDesignExists(userId int64) (bool, error) {
|
||||
//查询用户最近下单成功的数据
|
||||
orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userId, int64(constants.STATUS_NEW_NOT_PAY))
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
//获取该订单相关设计信息
|
||||
orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
//获取设计模板详情,便于获得design_id
|
||||
orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return *orderDetailTemplate.DesignId > 0, nil
|
||||
}
|
|
@ -347,6 +347,25 @@ type GetLightByPidReq struct {
|
|||
Pid string `form:"pid"`
|
||||
}
|
||||
|
||||
type GetRenderSettingByPidReq struct {
|
||||
Pid string `form:"pid"`
|
||||
ClientNo string `form:"client_no,optional"`
|
||||
}
|
||||
|
||||
type GetRenderSettingByPidRsp struct {
|
||||
Id int64 `json:"id"` //产品id
|
||||
Type int64 `json:"type"` //产品typeid
|
||||
Title string `json:"title"` //产品名称
|
||||
IsEnv int64 `json:"isEnv"` //产品标签之一
|
||||
IsMicro int64 `json:"isMicro"` //产品标签之一
|
||||
TypeName string `json:"typeName"` //产品类型名称
|
||||
IsLowRendering bool `json:"is_low_rendering"` //低质量画质渲染开关
|
||||
IsRemoveBg bool `json:"is_remove_bg"` //logo上传是否去背景
|
||||
RenderDesign bool `json:"render_design"` //是否拥有云渲染设计方案
|
||||
LastDesign bool `json:"last_lesign"` //是否拥有千人千面设计方案
|
||||
Colors interface{} `json:"colors"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,9 @@ service product {
|
|||
//获取产品灯光数据
|
||||
@handler GetLightByPidHandler
|
||||
get /api/product/get_light_by_pid(GetLightByPidReq) returns (response);
|
||||
//获取产品渲染设置
|
||||
@handler GetRenderSettingByPidHandler
|
||||
get /api/product/get_render_setting_by_pid(GetRenderSettingByPidReq) returns (response);
|
||||
//*********************产品详情分解接口结束***********************
|
||||
}
|
||||
|
||||
|
@ -378,4 +381,22 @@ type GetFittingByPidRsp {
|
|||
//获取产品灯光数据
|
||||
type GetLightByPidReq {
|
||||
Pid string `form:"pid"`
|
||||
}
|
||||
//获取产品渲染设置
|
||||
type GetRenderSettingByPidReq {
|
||||
Pid string `form:"pid"`
|
||||
ClientNo string `form:"client_no,optional"`
|
||||
}
|
||||
type GetRenderSettingByPidRsp {
|
||||
Id int64 `json:"id"` //产品id
|
||||
Type int64 `json:"type"` //产品typeid
|
||||
Title string `json:"title"` //产品名称
|
||||
IsEnv int64 `json:"isEnv"` //产品标签之一
|
||||
IsMicro int64 `json:"isMicro"` //产品标签之一
|
||||
TypeName string `json:"typeName"` //产品类型名称
|
||||
IsLowRendering bool `json:"is_low_rendering"` //低质量画质渲染开关
|
||||
IsRemoveBg bool `json:"is_remove_bg"` //logo上传是否去背景
|
||||
RenderDesign bool `json:"render_design"` //是否拥有云渲染设计方案
|
||||
LastDesign bool `json:"last_lesign"` //是否拥有千人千面设计方案
|
||||
Colors interface{} `json:"colors"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user