This commit is contained in:
laodaming
2023-10-17 16:19:44 +08:00
parent 0c5a5a466f
commit c79a1aab49
4 changed files with 37 additions and 8 deletions

View File

@@ -159,6 +159,12 @@ func (l *GetProductDetailLogic) GetProductDetail(req *types.GetProductDetailReq,
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
}
//获取默认渲染的尺寸
defaultSize, err := l.getRenderDefaultSize(req.ProductId, req.TemplateTag)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default size")
}
//整理返回
rspSizeList := make([]types.SizeInfo, 0, len(sizeList))
for _, sizeInfo := range sizeList {
@@ -266,8 +272,13 @@ func (l *GetProductDetailLogic) GetProductDetail(req *types.GetProductDetailReq,
}
}
isDefaultSize := int64(0)
if sizeInfo.Id == defaultSize {
isDefaultSize = 1
}
rspSizeList = append(rspSizeList, types.SizeInfo{
Id: sizeInfo.Id,
IsDefault: isDefaultSize,
Title: sizeTitle,
Capacity: *sizeInfo.Capacity,
PartsCanDeleted: *sizeInfo.PartsCanDeleted,
@@ -294,10 +305,30 @@ func (l *GetProductDetailLogic) GetProductDetail(req *types.GetProductDetailReq,
})
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *GetProductDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }
// 获取列表页默认渲染的尺寸(同列表页)
func (l *GetProductDetailLogic) getRenderDefaultSize(productId int64, templateTag string) (sizeId int64, err error) {
//获取模板
productTemplate, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(l.ctx, productId, templateTag, "sort ASC", "model_id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return 0, errors.New("找不到对应开启云渲染模板")
}
logx.Error(err)
return 0, errors.New("获取对应开启云渲染模板失败")
}
//根据模板找到模型
model3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *productTemplate.ModelId, "size_id")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return 0, errors.New("找不到对应模型")
}
logx.Error(err)
return 0, errors.New("获取对应模型失败")
}
return *model3d.SizeId, nil
}
// 获取对应模板标签颜色信息
func (l *GetProductDetailLogic) GetTemplateTagColor(req *types.GetProductDetailReq, userinfo *auth.UserInfo) (resp types.TemplateTagColorInfo, err error) {
if req.SelectColorIndex < 0 {
return types.TemplateTagColorInfo{}, errors.New("param selected_color_index is invalid")