Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
16dbf3cb0d
|
@ -66,7 +66,7 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
})
|
||||
}
|
||||
}
|
||||
//尺寸列表[这里要处理数据中的title]
|
||||
//尺寸列表
|
||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByStatus(l.ctx, int64(constants.FAQ_STATUS_ON), 1, "id,title,capacity,cover,sort,parts_can_deleted")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
|
@ -93,10 +93,10 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")
|
||||
}
|
||||
model3dIds := make([]int64, 0, len(model3dList))
|
||||
mapModel3dWithSizeIdIndex := make(map[int64]int) //sizeid为key
|
||||
for k, v := range model3dList {
|
||||
mapModel3dWithSizeIdIndex := make(map[int64]gmodel.FsProductModel3d) //sizeid为key
|
||||
for _, v := range model3dList {
|
||||
model3dIds = append(model3dIds, v.Id)
|
||||
mapModel3dWithSizeIdIndex[*v.SizeId] = k
|
||||
mapModel3dWithSizeIdIndex[*v.SizeId] = v
|
||||
}
|
||||
//通过产品id和模型id获取模板信息
|
||||
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIdModelIds(l.ctx, model3dIds, productInfo.Id)
|
||||
|
@ -108,7 +108,7 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
mapTemplateModelId := make(map[int64]struct{})
|
||||
tagIds := make([]int64, 0, len(productTemplateList))
|
||||
for _, v := range productTemplateList {
|
||||
mapTemplateModelId[v.Id] = struct{}{}
|
||||
mapTemplateModelId[*v.ModelId] = struct{}{}
|
||||
if v.Tag != nil && *v.Tag != "" {
|
||||
tagId, err := strconv.ParseInt(*v.Tag, 10, 64)
|
||||
if err != nil {
|
||||
|
@ -121,21 +121,24 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
//过滤没有模板的尺寸数据
|
||||
sizeListRsp := make([]types.SizeItem, 0, len(sizeList))
|
||||
for _, v := range sizeList {
|
||||
model3dIndex, ok := mapModel3dWithSizeIdIndex[v.Id]
|
||||
model3dInfo, ok := mapModel3dWithSizeIdIndex[v.Id]
|
||||
if !ok {
|
||||
fmt.Println("没有模型:", v.Id)
|
||||
continue
|
||||
}
|
||||
if _, ok = mapTemplateModelId[model3dList[model3dIndex].Id]; !ok {
|
||||
if _, ok = mapTemplateModelId[model3dInfo.Id]; !ok {
|
||||
fmt.Println("没有模板:", v.Id)
|
||||
continue
|
||||
}
|
||||
fmt.Println("剩下的:", v.Id)
|
||||
var title types.SizeTitle
|
||||
if err = json.Unmarshal([]byte(*v.Title), &title); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse size info`s title")
|
||||
}
|
||||
var modelInfo map[string]interface{}
|
||||
if model3dList[model3dIndex].ModelInfo != nil && *model3dList[model3dIndex].ModelInfo != "" {
|
||||
if err = json.Unmarshal([]byte(*model3dList[model3dIndex].ModelInfo), &modelInfo); err != nil {
|
||||
if model3dInfo.ModelInfo != nil && *model3dInfo.ModelInfo != "" {
|
||||
if err = json.Unmarshal([]byte(*model3dInfo.ModelInfo), &modelInfo); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info")
|
||||
}
|
||||
|
@ -163,9 +166,9 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get tag list")
|
||||
}
|
||||
mapTag := make(map[string]int)
|
||||
for k, v := range tagList {
|
||||
mapTag[fmt.Sprintf("%d", v.Id)] = k
|
||||
mapTag := make(map[string]gmodel.FsTags)
|
||||
for _, v := range tagList {
|
||||
mapTag[fmt.Sprintf("%d", v.Id)] = v
|
||||
}
|
||||
//获取全部模型信息
|
||||
allModel3dList, err := l.svcCtx.AllModels.FsProductModel3d.GetAll(l.ctx)
|
||||
|
@ -173,11 +176,11 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get all 3d model list")
|
||||
}
|
||||
mapAllmodel3d := make(map[int64]int)
|
||||
mapAllmodel3d := make(map[int64]gmodel.FsProductModel3d)
|
||||
optionTemplateIds := make([]int64, 0, len(allModel3dList))
|
||||
lightIds := make([]int64, 0, len(allModel3dList))
|
||||
for k, v := range allModel3dList {
|
||||
mapAllmodel3d[v.Id] = k
|
||||
for _, v := range allModel3dList {
|
||||
mapAllmodel3d[v.Id] = v
|
||||
optionTemplateIds = append(optionTemplateIds, *v.OptionTemplate)
|
||||
lightIds = append(lightIds, *v.Light)
|
||||
}
|
||||
|
@ -187,9 +190,9 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get option template list")
|
||||
}
|
||||
mapOptionTemplate := make(map[int64]int)
|
||||
for k, v := range optionTemplateList {
|
||||
mapOptionTemplate[v.Id] = k
|
||||
mapOptionTemplate := make(map[int64]gmodel.FsProductTemplateV2)
|
||||
for _, v := range optionTemplateList {
|
||||
mapOptionTemplate[v.Id] = v
|
||||
}
|
||||
//获取灯光信息
|
||||
lightList, err := l.svcCtx.AllModels.FsProductModel3dLight.GetAllByIdsWithoutStatus(l.ctx, lightIds)
|
||||
|
@ -197,34 +200,33 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get light list")
|
||||
}
|
||||
mapLight := make(map[int64]int)
|
||||
for k, v := range lightList {
|
||||
mapLight[v.Id] = k
|
||||
mapLight := make(map[int64]gmodel.FsProductModel3dLight)
|
||||
for _, v := range lightList {
|
||||
mapLight[v.Id] = v
|
||||
}
|
||||
//材料尺寸模板
|
||||
mapMaterialSizeTmp := make(map[string][]interface{})
|
||||
//循环阶梯价计算
|
||||
type MaterialSizePrice struct {
|
||||
Items []interface{} `json:"items"`
|
||||
MinPrice string `json:"min_price"`
|
||||
MaxPrice string `json:"max_price"`
|
||||
MinPrice float64 `json:"min_price"`
|
||||
MaxPrice float64 `json:"max_price"`
|
||||
}
|
||||
mapMaterialSizePrice := make(map[string]*MaterialSizePrice)
|
||||
//循环处理组装模板信息
|
||||
for _, tmp := range productTemplateList {
|
||||
allModel3dIndex, ok := mapAllmodel3d[*tmp.ModelId]
|
||||
model3dInfo, ok := mapAllmodel3d[*tmp.ModelId]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
//如果是配件信息就跳过,不返回
|
||||
if *allModel3dList[allModel3dIndex].Tag == constants.TAG_PARTS {
|
||||
if *model3dInfo.Tag == constants.TAG_PARTS {
|
||||
continue
|
||||
}
|
||||
//未编辑模板信息的数据跳过
|
||||
if tmp.TemplateInfo == nil || *tmp.TemplateInfo == "" {
|
||||
continue
|
||||
}
|
||||
model3dInfo := allModel3dList[allModel3dIndex]
|
||||
//解码template info
|
||||
var templateInfoRsp map[string]interface{}
|
||||
if tmp.TemplateInfo != nil && *tmp.TemplateInfo != "" {
|
||||
|
@ -251,12 +253,12 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse model info")
|
||||
}
|
||||
}
|
||||
modelInfoRsp["id"] = allModel3dList[allModel3dIndex].Id
|
||||
modelInfoRsp["id"] = model3dInfo.Id
|
||||
//解码灯光数据
|
||||
var lightInfoRsp interface{}
|
||||
lightIndex, ok := mapLight[*model3dInfo.Light]
|
||||
if ok && lightList[lightIndex].Info != nil && *lightList[lightIndex].Info != "" {
|
||||
if err = json.Unmarshal([]byte(*lightList[lightIndex].Info), &lightInfoRsp); err != nil {
|
||||
lightInfo, ok := mapLight[*model3dInfo.Light]
|
||||
if ok && lightInfo.Info != nil && *lightInfo.Info != "" {
|
||||
if err = json.Unmarshal([]byte(*lightInfo.Info), &lightInfoRsp); err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse light info")
|
||||
}
|
||||
|
@ -270,17 +272,17 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
partListRsp := make([]interface{}, 0, len(modelPartIds))
|
||||
for _, partId := range modelPartIds {
|
||||
//判断配件信息是否正常
|
||||
key, ok := mapAllmodel3d[partId]
|
||||
if !ok || *allModel3dList[key].Status != 1 {
|
||||
temModelInfo, ok := mapAllmodel3d[partId]
|
||||
if !ok || *temModelInfo.Status != 1 {
|
||||
continue
|
||||
}
|
||||
var thisInfo map[string]interface{}
|
||||
temBytes, _ := json.Marshal(allModel3dList[key])
|
||||
temBytes, _ := json.Marshal(temModelInfo)
|
||||
_ = json.Unmarshal(temBytes, &thisInfo)
|
||||
thisInfo["material_img"] = ""
|
||||
if *allModel3dList[key].OptionTemplate != 0 {
|
||||
if optionTemplateIndex, ok := mapOptionTemplate[*allModel3dList[key].OptionTemplate]; ok {
|
||||
thisInfo["material_img"] = *optionTemplateList[optionTemplateIndex].MaterialImg
|
||||
if *temModelInfo.OptionTemplate != 0 {
|
||||
if optionTemplateInfo, ok := mapOptionTemplate[*temModelInfo.OptionTemplate]; ok {
|
||||
thisInfo["material_img"] = *optionTemplateInfo.MaterialImg
|
||||
}
|
||||
} else {
|
||||
tmpv2, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneByModelId(l.ctx, partId)
|
||||
|
@ -297,8 +299,8 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
partListRsp = append(partListRsp, thisInfo)
|
||||
}
|
||||
tagName := ""
|
||||
if tagIndex, ok := mapTag[*tmp.Tag]; ok {
|
||||
tagName = *tagList[tagIndex].Title
|
||||
if tagData, ok := mapTag[*tmp.Tag]; ok {
|
||||
tagName = *tagData.Title
|
||||
}
|
||||
//按照材质和尺寸来存放模板信息
|
||||
mapMaterialSizeTmpKey := l.getMapMaterialSizeTmpKey(*productInfo.MaterialIds, *model3dInfo.SizeId)
|
||||
|
@ -337,14 +339,18 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
for *priceItem.MinBuyNum < int64(stepNumSlice[lenStepNum-1]+5) {
|
||||
price := step_price.GetCentStepPrice(int(*priceItem.MinBuyNum), stepNumSlice, stepPriceSlice)
|
||||
mapMaterialSizePriceKey := l.getMapMaterialSizePriceKey(*priceItem.MaterialId, *priceItem.SizeId)
|
||||
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)
|
||||
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,
|
||||
})
|
||||
mapMaterialSizePrice[mapMaterialSizePriceKey].MinPrice = fmt.Sprintf("%.2f", float64(stepPriceSlice[lenStepPrice-1])/100)
|
||||
mapMaterialSizePrice[mapMaterialSizePriceKey].MaxPrice = fmt.Sprintf("%.2f", float64(stepPriceSlice[0])/100)
|
||||
mapMaterialSizePrice[mapMaterialSizePriceKey].MinPrice = minPrice
|
||||
mapMaterialSizePrice[mapMaterialSizePriceKey].MaxPrice = maxPrice
|
||||
} else {
|
||||
items := map[string]interface{}{
|
||||
"num": *priceItem.MinBuyNum,
|
||||
|
@ -353,8 +359,8 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
}
|
||||
mapMaterialSizePrice[mapMaterialSizePriceKey] = &MaterialSizePrice{
|
||||
Items: []interface{}{items},
|
||||
MinPrice: fmt.Sprintf("%.2f", float64(stepPriceSlice[lenStepPrice-1])/100),
|
||||
MaxPrice: fmt.Sprintf("%.2f", float64(stepPriceSlice[0])/100),
|
||||
MinPrice: minPrice,
|
||||
MaxPrice: maxPrice,
|
||||
}
|
||||
}
|
||||
*priceItem.MinBuyNum++
|
||||
|
@ -403,7 +409,7 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, useri
|
|||
Materials: materials,
|
||||
Sizes: sizeListRsp,
|
||||
Templates: mapMaterialSizeTmp,
|
||||
Price: mapMaterialSizePrice,
|
||||
Prices: mapMaterialSizePrice,
|
||||
LastDesign: lastDesign,
|
||||
RenderDesign: renderDesign,
|
||||
Colors: color_list.GetColor(),
|
||||
|
|
|
@ -121,7 +121,7 @@ type GetProductInfoRsp struct {
|
|||
Materials []MaterialItem `json:"materials"`
|
||||
Sizes []SizeItem `json:"sizes"`
|
||||
Templates interface{} `json:"templates"`
|
||||
Price interface{} `json:"price"`
|
||||
Prices interface{} `json:"prices"`
|
||||
LastDesign interface{} `json:"last_design"`
|
||||
RenderDesign interface{} `json:"render_design"`
|
||||
Colors interface{} `json:"colors"`
|
||||
|
|
|
@ -147,7 +147,7 @@ type GetProductInfoRsp {
|
|||
Materials []MaterialItem `json:"materials"`
|
||||
Sizes []SizeItem `json:"sizes"`
|
||||
Templates interface{} `json:"templates"`
|
||||
Price interface{} `json:"price"`
|
||||
Prices interface{} `json:"prices"`
|
||||
LastDesign interface{} `json:"last_design"`
|
||||
RenderDesign interface{} `json:"render_design"`
|
||||
Colors interface{} `json:"colors"`
|
||||
|
|
Loading…
Reference in New Issue
Block a user