This commit is contained in:
laodaming 2023-06-19 14:47:54 +08:00
parent bbb1a845ad
commit 6a9650b9d1
7 changed files with 55 additions and 143 deletions

View File

@ -2,6 +2,13 @@ package gmodel
import "context"
func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp FsProduct, err error) {
err = p.db.Model(&FsProduct{}).Where("`id` = ? and `is_del` =? and `is_shelf` = ? and `status` =?", id, 0, 1, 1).First(&resp).Error
if err != nil {
return FsProduct{}, err
}
return resp, nil
}
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
if len(productIds) == 0 {
return

View File

@ -2,8 +2,17 @@ package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp FsProductModel3d, err error) {
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).Find(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductModel3d{}, err
}
return resp, nil
}
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3d, err error) {
if len(ids) == 0 {
return

View File

@ -7,7 +7,7 @@ import (
)
func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64) (resp FsProductSize, err error) {
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? and `status` = ?", id, 1).First(&resp).Error
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductSize{}, err
}

View File

@ -28,7 +28,7 @@ func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64
}
func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp FsProductTemplateV2, err error) {
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? and `is_del` = ? and `status` = ?", id, 0, 1).Find(&resp).Error
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? ", id).Find(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductTemplateV2{}, err
}

View File

@ -1,7 +1,6 @@
package logic
import (
"encoding/json"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
@ -65,11 +64,27 @@ func (l *GetProductDesignLogic) GetProductDesign(req *types.GetProductDesignReq,
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 {
//获取产品模型信息
productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn)
model3dInfo, err := productModel3dModel.FindOne(l.ctx, *designInfo.OptionalId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse design info")
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product 3D model info")
}
return resp.SetStatus(basic.CodeOK)
if model3dInfo.Id == 0 {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product 3D model info is not exists")
}
optionalId := *designInfo.OptionalId
if *model3dInfo.Status == 0 && *sizeInfo.Status == 1 && *productTemplateV2Info.Status == 1 && *productTemplateV2Info.IsDel == 0 {
optionalId = 0
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.GetProductDesignRsp{
ProductId: *designInfo.ProductId,
TemplateId: *designInfo.TemplateId,
MaterialId: *designInfo.MaterialId,
SizeId: *designInfo.SizeId,
OptionalId: optionalId,
Cover: *designInfo.Cover,
Info: *designInfo.Info,
})
}

View File

@ -97,79 +97,17 @@ type PriceObj struct {
}
type GetProductDesignReq struct {
Sn string `json:"sn"`
Sn string `form:"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"`
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 string `json:"info"`
}
type Response struct {

View File

@ -107,71 +107,14 @@ type PriceObj {
//获取保存的设计信息
type GetProductDesignReq {
Sn string `json:"sn"`
Sn string `form:"sn"`
}
type GetProductDesignRsp {
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 {
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 {
X int64 `json:"x"`
Y int64 `json:"y"`
Z int64 `json:"z"`
}
type DesignGroup {
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 {
Fill string `json:"fill"`
IfShow string `json:"ifShow"`
Content string `json:"content"`
}
type OptionalColor {
Color string `json:"color"`
Name string `json:"name"`
Default bool `json:"default"`
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 string `json:"info"`
}