This commit is contained in:
laodaming
2023-06-06 15:01:13 +08:00
parent 213665eb59
commit cf3a02ae7e
12 changed files with 163 additions and 369 deletions

View File

@@ -1,39 +0,0 @@
package handler
import (
"errors"
"fusenapi/utils/auth"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"fusenapi/product/internal/logic"
"fusenapi/product/internal/svc"
"fusenapi/product/internal/types"
)
func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
//用户登录信息
userInfo := auth.CheckAuth(r)
var req types.GetProductInfoReq
if err := httpx.Parse(r, &req); err != nil {
httpx.OkJsonCtx(r.Context(), w, &types.Response{
Code: 510,
Message: "parameter error",
})
logx.Info(err)
return
}
l := logic.NewGetProductInfoLogic(r.Context(), svcCtx)
resp := l.GetProductInfo(&req, userInfo)
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)
}
}
}

View File

@@ -17,11 +17,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/product/list",
Handler: GetProductListHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/product/info",
Handler: GetProductInfoHandler(serverCtx),
},
},
)
}

View File

@@ -1,127 +0,0 @@
package logic
import (
"context"
"errors"
"fmt"
"fusenapi/model"
"fusenapi/product/internal/svc"
"fusenapi/product/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
type GetProductInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductInfoLogic {
return &GetProductInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 获取产品详情
func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response) {
loginInfo.UserId = 83
//校验前台登录情况
if loginInfo.UserId == 0 {
return &types.Response{Code: 402, Message: "please sign in"}
}
req.Pid = strings.Trim(req.Pid, " ")
req.ClientNo = strings.Trim(req.ClientNo, " ")
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//获取产品详情
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
productInfo, err := productModel.FindOneBySn(l.ctx, req.Pid)
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product info"}
}
if productInfo == nil {
return &types.Response{Code: 510, Message: "product not found"}
}
//获取产品标签
/*tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
tagInfo, err := tagModel.FindOne(l.ctx, productInfo.Type)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product tag"}
}*/
//获取产品尺寸列表
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
productSizeList, err := productSizeModel.FindAllByStatus(l.ctx, 1, 1)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product size list"}
}
sizeIds := make([]string, 0, len(productSizeList))
for _, v := range productSizeList {
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id))
}
//获取这些尺寸下的模型数据
productModel3dModel := model.NewFsProductModel3dModel(l.svcCtx.MysqlConn)
models, err := productModel3dModel.ListBySizeIdsTag(l.ctx, sizeIds, 1)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product models"}
}
modelIds := make([]string, 0, len(models))
optionTemplateIds := make([]string, 0, len(models))
for _, v := range models {
modelIds = append(modelIds, fmt.Sprintf("%d", v.Id))
optionTemplateIds = append(optionTemplateIds, fmt.Sprintf("%d", v.OptionTemplate.Int64))
}
//通过产品id和模型id获取模板信息
productTemplateV2Model := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
templateV2List, err := productTemplateV2Model.FindAllByModelIdsProduct(l.ctx, modelIds, productInfo.Id, 2)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get templates"}
}
//获取模板包含的model_id
mapTemplateModelId := make(map[int64]struct{})
tagIds := make([]string, 0, len(templateV2List))
for _, v := range templateV2List {
mapTemplateModelId[v.ModelId] = struct{}{}
tagIds = append(tagIds, v.Tag)
}
/*//获取模板分类类表
templateTagsModel := model.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn)
templateTags, err := templateTagsModel.ListByIds(l.ctx, tagIds)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get template tags"}
}
//TODO 组装sizes
sizesRsp := make([]types.Sizes, 0, len(productSizeList))
for _, v := range productSizeList {
//没有模型信息跳过
if _, ok := mapTemplateModelId[v.Id]; !ok {
continue
}
var title types.SizeTitle
if err = json.Unmarshal([]byte(v.Title), &title); err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "err title format"}
}
sizesRsp = append(sizesRsp, types.Sizes{
Id: v.Id,
Title: title,
Capacity: v.Capacity,
Cover: v.Cover.String,
})
}*/
//组装材料
return &types.Response{}
}

View File

@@ -56,108 +56,6 @@ type Items struct {
CoverDefault string `json:"coverDefault"`
}
type GetProductInfoReq struct {
Pid string `form:"pid"` //sn
Size uint32 `form:"size"` //图片尺寸
ClientNo string `form:"clientNo"` //页面标识
HaveCloudRendering bool `form:"haveCloudRendering"` //是否显示云渲染开关
}
type GetProductInfoRsp struct {
Id int64 `json:"id"`
Type int32 `json:"type"`
Title string `json:"title"`
IsEnv uint32 `json:"isEnv"`
IsMicro uint32 `json:"isMicro"`
Materials []Materials `json:"materials"`
Sizes []Sizes `json:"sizes"`
TypeName string `json:"typeName"`
Templates Templates `json:"templates"`
}
type Materials struct {
Id int64 `json:"id"`
Title string `json:"title"`
}
type Sizes struct {
Id int64 `json:"id"`
Title SizeTitle `json:"title"`
Capacity string `json:"capacity"`
Cover string `json:"cover"`
}
type SizeTitle struct {
Cm string `json:"cm"`
Inth string `json:"inth"`
}
type Templates struct {
Ob484 []Ob484 `json:"4_84"`
}
type Ob484 struct {
Id int64 `json:"id"`
Title string `json:"title"`
TemplateData TemplateData `json:"templateData"`
}
type TemplateData struct {
Id int64 `json:"id"`
Cover string `json:"cover"`
Material string `json:"material"`
MaterialList []Material `json:"materialList"`
}
type Material struct {
Id int64 `json:"id"`
Tag string `json:"tag"`
Title string `json:"title"`
Type string `json:"type"`
Text string `json:"text"`
Fill string `json:"fill"`
FontSize int `json:"fontSize"`
FontFamily string `json:"fontFamily"`
IfBr bool `json:"ifBr"`
IfShow bool `json:"ifShow"`
IfGroup bool `json:"ifGroup"`
MaxNum int `json:"maxNum"`
Rotation int `json:"rotation"`
Align string `json:"align"`
VerticalAlign string `json:"verticalAlign"`
Material string `json:"material"`
QRcodeType string `json:"qRcodeType"`
Width int `json:"width"`
Height int `json:"height"`
X int `json:"x"`
Y int `json:"y"`
Opacity int `json:"opacity"`
OptionalColor []OptionalColor `json:"optionalColor"`
ZIndex int `json:"zIndex"`
SvgPath string `json:"svgPath"`
Follow Follow `json:"follow"`
Group []string `json:"group"`
CameraStand CameraStand `json:"cameraStand"`
}
type CameraStand struct {
X int `json:"x"`
Y int `json:"y"`
Z int `json:"z"`
}
type Follow 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 string `json:"default"`
}
type Response struct {
Code int `json:"code"`
Message string `json:"msg"`