fusenapi/server/product/internal/logic/getlastproductdesignlogic.go

110 lines
3.9 KiB
Go
Raw Normal View History

2023-07-19 02:48:52 +00:00
package logic
import (
"context"
"errors"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
2023-09-14 10:43:10 +00:00
2023-07-19 02:48:52 +00:00
"gorm.io/gorm"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetLastProductDesignLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetLastProductDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLastProductDesignLogic {
return &GetLastProductDesignLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetLastProductDesignLogic) GetLastProductDesign(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
if !userinfo.IsUser() {
2023-09-15 02:39:08 +00:00
return resp.SetStatusAddMessage(basic.CodeUnAuth, "please sign in")
2023-07-19 02:48:52 +00:00
}
//获取用户信息
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "user not found")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user info")
}
//若没打开了个性化渲染按钮
if *user.IsOpenRender != 1 {
return resp.SetStatusWithMessage(basic.CodeOK, "success:IsOpenRender switch is closed")
}
//查询用户最近下单成功的数据
2023-09-14 10:43:10 +00:00
// orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, user.Id, int64(constants.STATUS_NEW_NOT_PAY))
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of order is found")
// }
// logx.Error(err)
// return resp.SetStatusAddMessage(basic.CodeDbSqlErr, "failed to get your last order")
// }
2023-07-19 02:48:52 +00:00
//获取该订单相关设计信息
2023-09-14 10:43:10 +00:00
// orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order detail is not found")
// }
// logx.Error(err)
// return resp.SetStatusAddMessage(basic.CodeDbSqlErr, "failed to get order detail")
// }
// //获取设计模板详情便于获得design_id
// orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order detail template is not found")
// }
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get order detail template")
// }
2023-07-19 02:48:52 +00:00
//最后一次设计不存在,则不返回该设计相关数据
2023-09-14 10:43:10 +00:00
// if *orderDetailTemplate.DesignId <= 0 {
// return resp.SetStatusWithMessage(basic.CodeOK, "success:last design id is not set")
// }
2023-07-19 02:48:52 +00:00
//获取设计数据
2023-09-14 10:43:10 +00:00
// productDesign, err := l.svcCtx.AllModels.FsProductDesign.FindOne(l.ctx, *orderDetailTemplate.DesignId, user.Id)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product design is not found")
// }
// logx.Error(err)
// return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product design")
// }
// var info interface{}
// if productDesign.Info != nil && *productDesign.Info != "" {
// if err := json.Unmarshal([]byte(*productDesign.Info), &info); err != nil {
// logx.Error(err)
// return nil
// }
// }
// var logoColor interface{}
// if productDesign.LogoColor != nil && *productDesign.LogoColor != "" {
// if err := json.Unmarshal([]byte(*productDesign.LogoColor), &logoColor); err != nil {
// logx.Error(err)
// return nil
// }
// }
2023-07-19 02:48:52 +00:00
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetLastProductDesignRsp{
2023-09-14 10:43:10 +00:00
Id: 1,
OptionalId: 1,
SizeId: 1,
LogoColor: 1,
Info: nil,
2023-07-19 02:48:52 +00:00
})
}