This commit is contained in:
laodaming
2023-06-06 13:07:39 +08:00
parent 834a560451
commit 213665eb59
18 changed files with 335 additions and 99 deletions

View File

@@ -2,9 +2,16 @@ 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"
)
@@ -24,8 +31,9 @@ func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// 获取产品详情
func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response) {
loginInfo.UserId = 83
//校验前台登录情况
/*if loginInfo.UserId == 0 {
if loginInfo.UserId == 0 {
return &types.Response{Code: 402, Message: "please sign in"}
}
req.Pid = strings.Trim(req.Pid, " ")
@@ -44,12 +52,12 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
return &types.Response{Code: 510, Message: "product not found"}
}
//获取产品标签
tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
/*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)
@@ -69,8 +77,10 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
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)
@@ -80,9 +90,38 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
return &types.Response{Code: 510, Message: "failed to get templates"}
}
//获取模板包含的model_id
templateModelIds := make([]string, 0, len(templateV2List))
mapTemplateModelId := make(map[int64]struct{})
tagIds := make([]string, 0, len(templateV2List))
for _, v := range templateV2List {
templateModelIds = append(templateModelIds, fmt.Sprintf("%d", v.ModelId))
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
//组装材料
return &types.Response{}
}