diff --git a/server/product/internal/logic/getproductmodelslogic.go b/server/product/internal/logic/getproductmodelslogic.go index 0a25258d..4573ac57 100644 --- a/server/product/internal/logic/getproductmodelslogic.go +++ b/server/product/internal/logic/getproductmodelslogic.go @@ -78,6 +78,40 @@ func (l *GetProductModelsLogic) GetProductModels(req *types.GetProductModelsReq, for k, v := range lightList { mapLight[v.Id] = k } + //获取配件默认贴图 + fittingPublicTemplateIds := make([]int64, 0, len(modelList)) //绑定了公共模板 + fittingNotPublicIds := make([]int64, 0, len(modelList)) //没绑定公共模板 + for _, v := range modelList { + if *v.Tag != constants.TAG_PARTS { + continue + } + //配件绑定公共模板 + if *v.OptionTemplate > 0 { + fittingPublicTemplateIds = append(fittingPublicTemplateIds, *v.OptionTemplate) + } else { + fittingNotPublicIds = append(fittingNotPublicIds, v.Id) + } + } + //公共模板配件的模板列表 + fittingPublicTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByIds(l.ctx, fittingPublicTemplateIds, "id,model_id,material_img") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting templates!") + } + mapFittingPublicTemplate := make(map[int64]int) + for k, v := range fittingPublicTemplateList { + mapFittingPublicTemplate[v.Id] = k + } + //非公共模板配件的模板列表 + fittingNotPublicTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByFittingIds(l.ctx, fittingNotPublicIds) + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting templates!!") + } + mapFittingNotPublicTemplate := make(map[int64]int) + for k, v := range fittingNotPublicTemplateList { + mapFittingNotPublicTemplate[*v.ModelId] = k + } for _, v := range modelList { //模型设计信息 var modelDesignInfo interface{} @@ -98,13 +132,28 @@ func (l *GetProductModelsLogic) GetProductModels(req *types.GetProductModelsReq, } } } + fittingMaterialImage := "" + //配件有默认贴图 + if *v.Tag == constants.TAG_PARTS { + switch *v.OptionTemplate { + case 0: //没有绑定公共模板的配件 + if index, ok := mapFittingNotPublicTemplate[v.Id]; ok { + fittingMaterialImage = *fittingNotPublicTemplateList[index].MaterialImg + } + default: + if index, ok := mapFittingPublicTemplate[*v.OptionTemplate]; ok { + fittingMaterialImage = *fittingPublicTemplateList[index].MaterialImg + } + } + } mapProductModels[*v.ProductId] = append(mapProductModels[*v.ProductId], types.ModelItem{ - Id: v.Id, - Type: *v.Tag, - Title: *v.Title, - Name: *v.Name, - DesignInfo: modelDesignInfo, - LightInfo: lightDesignInfo, + Id: v.Id, + Type: *v.Tag, + Title: *v.Title, + Name: *v.Name, + MaterialImage: fittingMaterialImage, + DesignInfo: modelDesignInfo, + LightInfo: lightDesignInfo, }) } mapProductInfo := make(map[int64][]types.ModelItem) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index ce8c0175..ac2af14a 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -181,12 +181,13 @@ type ProductItem struct { } type ModelItem struct { - Id int64 `json:"id"` - Type int64 `json:"type"` //1模型 2配件 3场景 - Title string `json:"title"` - Name string `json:"name"` - DesignInfo interface{} `json:"design_info"` - LightInfo interface{} `json:"light_info"` + Id int64 `json:"id"` + Type int64 `json:"type"` //1模型 2配件 3场景 + Title string `json:"title"` + Name string `json:"name"` + MaterialImage string `json:"material_image"` //默认贴图 + DesignInfo interface{} `json:"design_info"` + LightInfo interface{} `json:"light_info"` } type Request struct { diff --git a/server_api/product.api b/server_api/product.api index 22ab024c..9df4b422 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -197,10 +197,11 @@ type ProductItem { ModelList []ModelItem `json:"model_list"` } type ModelItem { - Id int64 `json:"id"` - Type int64 `json:"type"` //1模型 2配件 3场景 - Title string `json:"title"` - Name string `json:"name"` - DesignInfo interface{} `json:"design_info"` - LightInfo interface{} `json:"light_info"` + Id int64 `json:"id"` + Type int64 `json:"type"` //1模型 2配件 3场景 + Title string `json:"title"` + Name string `json:"name"` + MaterialImage string `json:"material_image"` //默认贴图 + DesignInfo interface{} `json:"design_info"` + LightInfo interface{} `json:"light_info"` } \ No newline at end of file