fusenapi/server/product/internal/logic/getproductinfologic.go

536 lines
19 KiB
Go
Raw Normal View History

2023-07-04 08:48:56 +00:00
package logic
import (
2023-07-05 08:03:16 +00:00
"context"
2023-07-06 09:43:07 +00:00
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
2023-07-04 08:48:56 +00:00
"fusenapi/utils/auth"
"fusenapi/utils/basic"
2023-07-06 09:43:07 +00:00
"fusenapi/utils/color_list"
2023-07-11 10:37:36 +00:00
"fusenapi/utils/encryption_decryption"
2023-07-06 09:43:07 +00:00
"fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/step_price"
"strconv"
"strings"
2023-07-04 08:48:56 +00:00
2023-09-14 10:43:10 +00:00
"gorm.io/gorm"
2023-07-04 08:48:56 +00:00
"fusenapi/server/product/internal/svc"
"fusenapi/server/product/internal/types"
"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, userinfo *auth.UserInfo) (resp *basic.Response) {
//获取产品信息
2023-07-06 09:43:07 +00:00
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid)
2023-07-04 08:48:56 +00:00
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
materialIdSlice, err := format.StrSlicToInt64Slice(strings.Split(*productInfo.MaterialIds, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product material Id list")
}
//材料列表
2023-07-06 09:43:07 +00:00
materials := make([]types.MaterialItem, 0, len(materialIdSlice))
2023-07-04 08:48:56 +00:00
for _, v := range materialIdSlice {
if title, ok := constants.MAP_MATERIAL[v]; ok {
2023-07-06 09:43:07 +00:00
materials = append(materials, types.MaterialItem{
2023-07-04 08:48:56 +00:00
Id: v,
Title: title,
})
}
}
2023-07-12 03:46:46 +00:00
//尺寸列表
2023-07-05 11:00:33 +00:00
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByStatus(l.ctx, int64(constants.FAQ_STATUS_ON), 1, "id,title,capacity,cover,sort,parts_can_deleted")
2023-07-04 08:48:56 +00:00
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product size list")
}
sizeIds := make([]int64, 0, len(sizeList))
for _, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
}
//获取产品标签
tagInfo, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, *productInfo.Type)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "tag info is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag info")
}
typeName := *tagInfo.Title
//获取该尺寸下的模型数据
model3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")
}
model3dIds := make([]int64, 0, len(model3dList))
2023-07-12 03:46:46 +00:00
mapModel3dWithSizeIdIndex := make(map[int64]gmodel.FsProductModel3d) //sizeid为key
for _, v := range model3dList {
2023-07-04 08:48:56 +00:00
model3dIds = append(model3dIds, v.Id)
2023-07-12 03:46:46 +00:00
mapModel3dWithSizeIdIndex[*v.SizeId] = v
2023-07-04 08:48:56 +00:00
}
//通过产品id和模型id获取模板信息
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdModelIds(l.ctx, model3dIds, productInfo.Id)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template list")
}
//获取模板包含的model_id
mapTemplateModelId := make(map[int64]struct{})
tagIds := make([]int64, 0, len(productTemplateList))
for _, v := range productTemplateList {
2023-07-12 03:46:46 +00:00
mapTemplateModelId[*v.ModelId] = struct{}{}
2023-08-17 03:11:58 +00:00
if v.TemplateTag != nil && *v.TemplateTag != "" {
tagId, err := strconv.ParseInt(*v.TemplateTag, 10, 64)
2023-07-04 08:48:56 +00:00
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "tag is not a number")
}
tagIds = append(tagIds, tagId)
}
}
//过滤没有模板的尺寸数据
sizeListRsp := make([]types.SizeItem, 0, len(sizeList))
for _, v := range sizeList {
2023-07-12 03:46:46 +00:00
model3dInfo, ok := mapModel3dWithSizeIdIndex[v.Id]
2023-07-04 08:48:56 +00:00
if !ok {
continue
}
2023-07-12 03:46:46 +00:00
if _, ok = mapTemplateModelId[model3dInfo.Id]; !ok {
2023-07-04 08:48:56 +00:00
continue
}
var title types.SizeTitle
if err = json.Unmarshal([]byte(*v.Title), &title); err != nil {
logx.Error(err)
2023-07-11 09:45:34 +00:00
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse size info`s title")
2023-07-04 08:48:56 +00:00
}
var modelInfo map[string]interface{}
2023-07-12 03:46:46 +00:00
if model3dInfo.ModelInfo != nil && *model3dInfo.ModelInfo != "" {
if err = json.Unmarshal([]byte(*model3dInfo.ModelInfo), &modelInfo); err != nil {
2023-07-11 09:45:34 +00:00
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info")
}
2023-07-04 08:48:56 +00:00
}
cover := ""
2023-07-06 09:43:07 +00:00
if modelInfo["cover"] != nil && modelInfo["cover"].(string) != "" {
2023-07-04 08:48:56 +00:00
cover = modelInfo["cover"].(string)
if req.Size >= 200 {
2023-07-06 09:43:07 +00:00
coverArr := strings.Split(modelInfo["cover"].(string), ".")
2023-07-04 08:48:56 +00:00
cover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1])
}
}
sizeListRsp = append(sizeListRsp, types.SizeItem{
Id: v.Id,
Title: title,
Capacity: *v.Capacity,
Cover: cover,
Sort: *v.Sort,
PartsCanDeleted: *v.PartsCanDeleted > 0,
})
}
//获取标签列表
tagList, err := l.svcCtx.AllModels.FsTags.GetAllByIdsWithoutStatus(l.ctx, tagIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag list")
}
2023-07-12 03:46:46 +00:00
mapTag := make(map[string]gmodel.FsTags)
for _, v := range tagList {
mapTag[fmt.Sprintf("%d", v.Id)] = v
2023-07-06 09:43:07 +00:00
}
2023-07-04 08:48:56 +00:00
//获取全部模型信息
allModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAll(l.ctx)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get all 3d model list")
}
2023-07-12 03:46:46 +00:00
mapAllmodel3d := make(map[int64]gmodel.FsProductModel3d)
2023-07-04 08:48:56 +00:00
optionTemplateIds := make([]int64, 0, len(allModel3dList))
lightIds := make([]int64, 0, len(allModel3dList))
2023-07-12 03:46:46 +00:00
for _, v := range allModel3dList {
mapAllmodel3d[v.Id] = v
2023-07-04 08:48:56 +00:00
optionTemplateIds = append(optionTemplateIds, *v.OptionTemplate)
lightIds = append(lightIds, *v.Light)
}
//获取公共模板信息
optionTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIdsWithoutStatus(l.ctx, optionTemplateIds, "id,material_img")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get option template list")
}
2023-07-12 03:46:46 +00:00
mapOptionTemplate := make(map[int64]gmodel.FsProductTemplateV2)
for _, v := range optionTemplateList {
mapOptionTemplate[v.Id] = v
2023-07-04 08:48:56 +00:00
}
//获取灯光信息
lightList, err := l.svcCtx.AllModels.FsProductModel3dLight.GetAllByIdsWithoutStatus(l.ctx, lightIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get light list")
}
2023-07-12 03:46:46 +00:00
mapLight := make(map[int64]gmodel.FsProductModel3dLight)
for _, v := range lightList {
mapLight[v.Id] = v
2023-07-04 08:48:56 +00:00
}
2023-07-06 09:43:07 +00:00
//材料尺寸模板
mapMaterialSizeTmp := make(map[string][]interface{})
//循环阶梯价计算
type MaterialSizePrice struct {
Items []interface{} `json:"items"`
2023-07-12 02:40:11 +00:00
MinPrice float64 `json:"min_price"`
MaxPrice float64 `json:"max_price"`
2023-07-06 09:43:07 +00:00
}
mapMaterialSizePrice := make(map[string]*MaterialSizePrice)
2023-07-04 08:48:56 +00:00
//循环处理组装模板信息
2023-07-06 09:43:07 +00:00
for _, tmp := range productTemplateList {
2023-07-12 03:46:46 +00:00
model3dInfo, ok := mapAllmodel3d[*tmp.ModelId]
2023-07-04 08:48:56 +00:00
if !ok {
continue
}
//如果是配件信息就跳过,不返回
2023-07-12 03:46:46 +00:00
if *model3dInfo.Tag == constants.TAG_PARTS {
2023-07-04 08:48:56 +00:00
continue
}
//未编辑模板信息的数据跳过
2023-07-06 09:43:07 +00:00
if tmp.TemplateInfo == nil || *tmp.TemplateInfo == "" {
2023-07-04 08:48:56 +00:00
continue
}
//解码template info
2023-07-06 09:43:07 +00:00
var templateInfoRsp map[string]interface{}
2023-07-11 09:45:34 +00:00
if tmp.TemplateInfo != nil && *tmp.TemplateInfo != "" {
if err = json.Unmarshal([]byte(*tmp.TemplateInfo), &templateInfoRsp); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse template info")
}
2023-07-04 08:48:56 +00:00
}
2023-07-06 09:43:07 +00:00
if templateInfoRsp["cover"] != nil && templateInfoRsp["cover"].(string) != "" {
cover := templateInfoRsp["cover"].(string)
2023-07-04 08:48:56 +00:00
if req.Size >= 200 {
2023-07-06 09:43:07 +00:00
coverArr := strings.Split(templateInfoRsp["cover"].(string), ".")
2023-07-04 08:48:56 +00:00
cover = fmt.Sprintf("%s_%d.%s", coverArr[0], req.Size, coverArr[1])
}
2023-07-06 09:43:07 +00:00
templateInfoRsp["cover"] = cover
delete(templateInfoRsp, "isPublic")
delete(templateInfoRsp, "name")
2023-07-04 08:48:56 +00:00
}
//解码模型数据
2023-07-06 09:43:07 +00:00
var modelInfoRsp map[string]interface{}
2023-07-11 09:45:34 +00:00
if model3dInfo.ModelInfo != nil && *model3dInfo.ModelInfo != "" {
if err = json.Unmarshal([]byte(*model3dInfo.ModelInfo), &modelInfoRsp); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info")
}
2023-07-04 08:48:56 +00:00
}
2023-07-12 03:46:46 +00:00
modelInfoRsp["id"] = model3dInfo.Id
2023-07-04 08:48:56 +00:00
//解码灯光数据
2023-07-06 09:43:07 +00:00
var lightInfoRsp interface{}
2023-07-12 03:46:46 +00:00
lightInfo, ok := mapLight[*model3dInfo.Light]
if ok && lightInfo.Info != nil && *lightInfo.Info != "" {
if err = json.Unmarshal([]byte(*lightInfo.Info), &lightInfoRsp); err != nil {
2023-07-04 08:48:56 +00:00
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse light info")
}
}
//配件备选项
modelPartIds, err := format.StrSlicToInt64Slice(strings.Split(*model3dInfo.PartList, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse 3d model`s part_list")
}
2023-07-06 09:43:07 +00:00
partListRsp := make([]interface{}, 0, len(modelPartIds))
2023-07-04 08:48:56 +00:00
for _, partId := range modelPartIds {
//判断配件信息是否正常
2023-07-12 03:46:46 +00:00
temModelInfo, ok := mapAllmodel3d[partId]
if !ok || *temModelInfo.Status != 1 {
2023-07-04 08:48:56 +00:00
continue
}
2023-07-04 09:17:37 +00:00
var thisInfo map[string]interface{}
2023-07-12 03:46:46 +00:00
temBytes, _ := json.Marshal(temModelInfo)
2023-07-04 09:17:37 +00:00
_ = json.Unmarshal(temBytes, &thisInfo)
2023-07-06 09:43:07 +00:00
thisInfo["material_img"] = ""
2023-07-12 03:46:46 +00:00
if *temModelInfo.OptionTemplate != 0 {
if optionTemplateInfo, ok := mapOptionTemplate[*temModelInfo.OptionTemplate]; ok {
thisInfo["material_img"] = *optionTemplateInfo.MaterialImg
2023-07-06 09:43:07 +00:00
}
} else {
tmpv2, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneByModelId(l.ctx, partId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
2023-07-04 08:48:56 +00:00
2023-07-06 09:43:07 +00:00
} else {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template")
}
}
thisInfo["material_img"] = *tmpv2.MaterialImg
}
partListRsp = append(partListRsp, thisInfo)
}
tagName := ""
2023-08-17 03:11:58 +00:00
if tagData, ok := mapTag[*tmp.TemplateTag]; ok {
2023-07-12 03:46:46 +00:00
tagName = *tagData.Title
2023-07-06 09:43:07 +00:00
}
//按照材质和尺寸来存放模板信息
mapMaterialSizeTmpKey := l.getMapMaterialSizeTmpKey(*productInfo.MaterialIds, *model3dInfo.SizeId)
mapMaterialSizeTmp[mapMaterialSizeTmpKey] = append(mapMaterialSizeTmp[mapMaterialSizeTmpKey], map[string]interface{}{
"id": tmp.Id,
"title": *tmp.Title,
"templateData": templateInfoRsp,
"modelData": modelInfoRsp,
"lightData": lightInfoRsp,
"partList": partListRsp,
"tag_name": tagName,
})
}
//产品价格查询
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetAllByProductIdStatus(l.ctx, productInfo.Id, 1)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product price list")
}
for _, priceItem := range productPriceList {
stepNumSlice, err := format.StrSlicToIntSlice(strings.Split(*priceItem.StepNum, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "split step num err")
}
stepPriceSlice, err := format.StrSlicToIntSlice(strings.Split(*priceItem.StepPrice, ","))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "split step price err")
}
lenStepNum := len(stepNumSlice)
lenStepPrice := len(stepPriceSlice)
if lenStepNum == 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "count of step num is empty")
}
for *priceItem.MinBuyNum < int64(stepNumSlice[lenStepNum-1]+5) {
price := step_price.GetCentStepPrice(int(*priceItem.MinBuyNum), stepNumSlice, stepPriceSlice)
mapMaterialSizePriceKey := l.getMapMaterialSizePriceKey(*priceItem.MaterialId, *priceItem.SizeId)
2023-07-12 02:40:11 +00:00
minPriceStr := fmt.Sprintf("%.2f", float64(stepPriceSlice[lenStepPrice-1])/100)
minPrice, _ := strconv.ParseFloat(minPriceStr, 64)
maxPriceStr := fmt.Sprintf("%.2f", float64(stepPriceSlice[0])/100)
maxPrice, _ := strconv.ParseFloat(maxPriceStr, 64)
2023-07-06 09:43:07 +00:00
if _, ok := mapMaterialSizePrice[mapMaterialSizePriceKey]; ok {
mapMaterialSizePrice[mapMaterialSizePriceKey].Items = append(mapMaterialSizePrice[mapMaterialSizePriceKey].Items, map[string]interface{}{
"num": *priceItem.MinBuyNum,
"total_num": *priceItem.MinBuyNum * (*priceItem.EachBoxNum),
"price": price,
})
2023-07-12 02:40:11 +00:00
mapMaterialSizePrice[mapMaterialSizePriceKey].MinPrice = minPrice
mapMaterialSizePrice[mapMaterialSizePriceKey].MaxPrice = maxPrice
2023-07-06 09:43:07 +00:00
} else {
items := map[string]interface{}{
"num": *priceItem.MinBuyNum,
"total_num": *priceItem.MinBuyNum * (*priceItem.EachBoxNum),
"price": price,
}
mapMaterialSizePrice[mapMaterialSizePriceKey] = &MaterialSizePrice{
Items: []interface{}{items},
2023-07-12 02:40:11 +00:00
MinPrice: minPrice,
MaxPrice: maxPrice,
2023-07-06 09:43:07 +00:00
}
}
*priceItem.MinBuyNum++
}
}
isLowRendering := false
isRemoveBg := false
var lastDesign interface{}
if userinfo.UserId != 0 {
//获取用户信息
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user info not found")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get user info")
}
2023-09-26 05:23:49 +00:00
isLowRendering = true
isRemoveBg = true
2023-07-06 09:43:07 +00:00
lastDesign = l.getLastDesign(user)
}
var renderDesign interface{}
if req.HaveCloudRendering == true {
renderDesign = l.getRenderDesign(req.ClientNo)
}
2023-07-11 10:37:36 +00:00
//查询是否是加密的(不太合理)
encryptWebsetting, err := l.svcCtx.AllModels.FsWebSet.FindValueByKey(l.ctx, "is_encrypt")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "web setting is_encrypt is not exists")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get web setting")
}
//不加密
rspData := types.GetProductInfoRsp{
2023-07-06 09:43:07 +00:00
Id: productInfo.Id,
Type: *productInfo.Type,
Title: *productInfo.Title,
IsEnv: *productInfo.IsProtection,
IsMicro: *productInfo.IsMicrowave,
TypeName: typeName,
IsLowRendering: isLowRendering,
IsRemoveBg: isRemoveBg,
Materials: materials,
Sizes: sizeListRsp,
Templates: mapMaterialSizeTmp,
2023-07-12 03:46:46 +00:00
Prices: mapMaterialSizePrice,
2023-07-06 09:43:07 +00:00
LastDesign: lastDesign,
RenderDesign: renderDesign,
Colors: color_list.GetColor(),
2023-07-11 10:37:36 +00:00
}
if encryptWebsetting.Value == nil || *encryptWebsetting.Value == "0" {
return resp.SetStatusWithMessage(basic.CodeOK, "success", rspData)
}
bytesData, _ := json.Marshal(rspData)
enData, err := encryption_decryption.CBCEncrypt(string(bytesData))
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to encryption response data")
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", enData)
2023-07-06 09:43:07 +00:00
}
2023-07-04 08:48:56 +00:00
2023-07-06 09:43:07 +00:00
// 获取渲染设计
func (l *GetProductInfoLogic) getRenderDesign(clientNo string) interface{} {
if clientNo == "" {
return nil
}
renderDesign, err := l.svcCtx.AllModels.FsProductRenderDesign.FindOneRenderDesignByParams(l.ctx, gmodel.FindOneRenderDesignByParamsReq{
ClientNo: &clientNo,
Fields: "id,info,material_id,optional_id,size_id,template_id",
2023-07-14 07:57:27 +00:00
OrderBy: "`id` DESC",
2023-07-06 09:43:07 +00:00
})
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}
logx.Error(err)
return nil
}
var info interface{}
if renderDesign.Info != nil && *renderDesign.Info != "" {
if err = json.Unmarshal([]byte(*renderDesign.Info), &info); err != nil {
logx.Error(err)
return nil
}
}
return map[string]interface{}{
"id": renderDesign.Id,
"info": info,
"material_id": *renderDesign.MaterialId,
"optional_id": *renderDesign.OptionalId,
"size_id": *renderDesign.SizeId,
"template_id": *renderDesign.TemplateId,
}
}
2023-07-04 08:48:56 +00:00
2023-07-06 09:43:07 +00:00
// 获取用户最新设计
func (l *GetProductInfoLogic) getLastDesign(userInfo gmodel.FsUser) interface{} {
//查询用户最近下单成功的数据
2023-09-14 10:43:10 +00:00
// orderInfo, err := l.svcCtx.AllModels.FsOrder.FindLastSuccessOneOrder(l.ctx, userInfo.Id, int64(constants.STATUS_NEW_NOT_PAY))
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return nil
// }
// logx.Error(err)
// return nil
// }
2023-07-06 09:43:07 +00:00
//获取该订单相关设计信息
2023-09-14 10:43:10 +00:00
// orderDetail, err := l.svcCtx.AllModels.FsOrderDetail.GetOneOrderDetailByOrderId(l.ctx, orderInfo.Id)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return nil
// }
// logx.Error(err)
// return nil
// }
// //获取设计模板详情便于获得design_id
// orderDetailTemplate, err := l.svcCtx.AllModels.FsOrderDetailTemplate.FindOne(l.ctx, *orderDetail.OrderDetailTemplateId)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return nil
// }
// logx.Error(err)
// return nil
// }
2023-07-06 09:43:07 +00:00
//若没打开了个性化渲染按钮或者最后一次设计不存在,则不返回该设计相关数据
2023-09-14 10:43:10 +00:00
// if *userInfo.IsOpenRender != 1 || *orderDetailTemplate.DesignId <= 0 {
// return nil
// }
// //获取设计数据
// productDesign, err := l.svcCtx.AllModels.FsProductDesign.FindOne(l.ctx, *orderDetailTemplate.DesignId, userInfo.Id)
// if err != nil {
// if errors.Is(err, gorm.ErrRecordNotFound) {
// return nil
// }
// logx.Error(err)
// return nil
// }
// var info interface{}
// if productDesign.Info != nil && *productDesign.Info != "" {
// if err := json.Unmarshal([]byte(*productDesign.Info), &info); err != nil {
// logx.Error(err)
// return nil
// }
// }
// var logoColor interface{}
// if productDesign.LogoColor != nil && *productDesign.LogoColor != "" {
// if err := json.Unmarshal([]byte(*productDesign.LogoColor), &logoColor); err != nil {
// logx.Error(err)
// return nil
// }
// }
2023-07-06 09:43:07 +00:00
return map[string]interface{}{
2023-09-14 10:43:10 +00:00
"id": 1,
"info": 1,
"logo_color": 1,
"material_id": 1,
"optional_id": 1,
"size_id": 1,
2023-07-06 09:43:07 +00:00
}
}
2023-07-04 08:48:56 +00:00
2023-07-06 09:43:07 +00:00
// 获取按照材料跟尺寸分类的模板map key
func (l *GetProductInfoLogic) getMapMaterialSizeTmpKey(materialIds string, sizeId int64) string {
return fmt.Sprintf("%s_%d", materialIds, sizeId)
}
2023-07-04 08:48:56 +00:00
2023-07-06 09:43:07 +00:00
// 获取按照材料跟尺寸分类的价格map key
func (l *GetProductInfoLogic) getMapMaterialSizePriceKey(materialId int64, sizeId int64) string {
return fmt.Sprintf("%d_%d", materialId, sizeId)
2023-07-04 08:48:56 +00:00
}