This commit is contained in:
laodaming
2023-06-19 12:23:02 +08:00
parent 56a3c05eae
commit bbb1a845ad
10 changed files with 244 additions and 15 deletions

View File

@@ -7,6 +7,6 @@ import (
type Config struct {
rest.RestConf
DataSource string
Auth types.Auth
SourceMysql string
Auth types.Auth
}

View File

@@ -12,6 +12,7 @@ import (
"fusenapi/server/product/internal/logic"
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
)
func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -52,8 +53,19 @@ func GetProductDesignHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
}
var req types.GetProductDesignReq
// 如果端点有请求结构体则使用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.NewGetProductDesignLogic(r.Context(), svcCtx)
resp := l.GetProductDesign(userinfo)
resp := l.GetProductDesign(&req, userinfo)
// 如果响应不为nil则使用httpx.OkJsonCtx方法返回JSON响应;
if resp != nil {
httpx.OkJsonCtx(r.Context(), w, resp)

View File

@@ -1,6 +1,8 @@
package logic
import (
"encoding/json"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@@ -26,9 +28,48 @@ func NewGetProductDesignLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
}
func (l *GetProductDesignLogic) GetProductDesign(, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
return resp.SetStatus(basic.CodeOK)
func (l *GetProductDesignLogic) GetProductDesign(req *types.GetProductDesignReq, userinfo *auth.UserInfo) (resp *basic.Response) {
if userinfo.GetIdType() != auth.IDTYPE_User {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
}
if req.Sn == "" {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required")
}
//获取设计数据
productDesignModel := gmodel.NewFsProductDesignModel(l.svcCtx.MysqlConn)
designInfo, err := productDesignModel.FindOneBySn(l.ctx, req.Sn, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get design info")
}
if designInfo.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "design info is not exists")
}
//获取产品尺寸信息
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
sizeInfo, err := productSizeModel.FindOne(l.ctx, *designInfo.SizeId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size info")
}
if sizeInfo.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "product size info is not exists")
}
//获取模板信息
productTemplateV2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
productTemplateV2Info, err := productTemplateV2Model.FindOne(l.ctx, *designInfo.TemplateId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get template info")
}
if productTemplateV2Info.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info is not exists")
}
//解析json
var info types.ProductDesignInfo
if err = json.Unmarshal([]byte(*designInfo.Info), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse design info")
}
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -96,6 +96,82 @@ type PriceObj struct {
Price float64 `json:"price"`
}
type GetProductDesignReq struct {
Sn string `json:"sn"`
}
type GetProductDesignRsp struct {
ProductId int64 `json:"product_id"`
TemplateId int64 `json:"template_id"`
MaterialId int64 `json:"material_id"`
SizeId int64 `json:"size_id"`
OptionalId int64 `json:"optional_id"`
Cover string `json:"cover"`
Info []ProductDesignInfo `json:"info"`
}
type ProductDesignInfo struct {
Id string `json:"id"`
Tag string `json:"tag"`
Title string `json:"title"`
Type string `json:"type"`
Text string `json:"text"`
Fill string `json:"fill"`
FontSize int64 `json:"fontSize"`
FontFamily string `json:"fontFamily"`
IfBr bool `json:"ifBr"`
IfShow bool `json:"ifShow"`
IfGroup bool `json:"ifGroup"`
MaxNum int64 `json:"maxNum"`
Rotation int64 `json:"rotation"`
Align string `json:"align"`
VerticalAlign string `json:"verticalAlign"`
Material string `json:"material"`
QRcodeType string `json:"QRcodeType"`
Width int64 `json:"width"`
Height int64 `json:"height"`
X int64 `json:"x"`
Y int64 `json:"y"`
Opacity int64 `json:"opacity"`
OptionalColor []OptionalColor `json:"optionalColor"`
ZIndex int64 `json:"zIndex"`
SvgPath string `json:"svgPath"`
MaterialName string `json:"materialName"`
MaterialTime string `json:"materialTime"`
Follow DesignFollow `json:"follow"`
Group []DesignGroup `json:"group"`
CameraStand CameraStand `json:"cameraStand"`
}
type CameraStand struct {
X int64 `json:"x"`
Y int64 `json:"y"`
Z int64 `json:"z"`
}
type DesignGroup struct {
Tag string `json:"tag"`
Text string `json:"text"`
Title string `json:"title"`
IfBr bool `json:"ifBr"`
IfGroupNoBr bool `json:"ifGroupNoBr"`
IfShow bool `json:"ifShow"`
MaxNum int64 `json:"maxNum"`
PaddingNum int64 `json:"paddingNum"`
}
type DesignFollow struct {
Fill string `json:"fill"`
IfShow string `json:"ifShow"`
Content string `json:"content"`
}
type OptionalColor struct {
Color string `json:"color"`
Name string `json:"name"`
Default bool `json:"default"`
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`