Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-06-21 12:22:18 +08:00
commit 4fb57e1c39
4 changed files with 118 additions and 84 deletions

View File

@ -8,23 +8,21 @@ func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp *Fs
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).Find(&resp).Error err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).Find(&resp).Error
return resp, err return resp, err
} }
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3d, err error) { func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3d, err error) {
if len(ids) == 0 { if len(ids) == 0 {
return return
} }
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ?", ids, 1)
if err != nil { if len(fields) > 0 {
return nil, err db = db.Select(fields[0])
} }
return err = db.Find(&resp).Error
return resp, err
} }
func (d *FsProductModel3dModel) GetAllByIdsTag(ctx context.Context, ids []int64, tag int64) (resp []FsProductModel3d, err error) { func (d *FsProductModel3dModel) GetAllByIdsTag(ctx context.Context, ids []int64, tag int64) (resp []FsProductModel3d, err error) {
if len(ids) == 0 { if len(ids) == 0 {
return return
} }
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ? and `tag` = ?", ids, 1, tag).Find(&resp).Error err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ? and `tag` = ?", ids, 1, tag).Find(&resp).Error
if err != nil { return resp, err
return nil, err
}
return
} }

View File

@ -20,6 +20,6 @@ func (pt *FsProductTemplateTagsModel) FindOne(ctx context.Context, id int64, fie
if len(fields) != 0 { if len(fields) != 0 {
db = db.Select(fields[0]) db = db.Select(fields[0])
} }
err = db.Take(resp).Error err = db.Take(&resp).Error
return resp, err return resp, err
} }

View File

@ -34,7 +34,6 @@ func NewGetTemplatevDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext)
} }
func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) { func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDetailReq, r *http.Request) (resp *basic.Response) {
//
authKey := r.Header.Get("Auth-Key") authKey := r.Header.Get("Auth-Key")
if authKey == "" { if authKey == "" {
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
@ -62,7 +61,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product model info is not exists") return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "product model info is not exists")
} }
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product model info") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product model info")
} }
//查询产品模板并检测数据完整 //查询产品模板并检测数据完整
productTemplatev2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) productTemplatev2Model := gmodel.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
@ -73,7 +72,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info is not exists") return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template info is not exists")
} }
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product template info") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template info")
} }
//获取模板标签 //获取模板标签
templateTagModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn) templateTagModel := gmodel.NewFsProductTemplateTagsModel(l.svcCtx.MysqlConn)
@ -88,10 +87,13 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag info is not exists") return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "template tag info is not exists")
} }
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product template tag info") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product template tag info")
} }
//配件ids //配件ids
partIds, err := format.StrSlicToIntSlice(strings.Split(*model3dInfo.PartList, ",")) partIds := make([]int64, 0, 10)
if *model3dInfo.PartList != "" {
partIds, err = format.StrSlicToInt64Slice(strings.Split(*model3dInfo.PartList, ","))
}
//灯光ids //灯光ids
var lightIds []int64 var lightIds []int64
if err = json.Unmarshal([]byte(*model3dInfo.LightList), &lightIds); err != nil { if err = json.Unmarshal([]byte(*model3dInfo.LightList), &lightIds); err != nil {
@ -103,70 +105,88 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta
model3dLightList, err := productModel3dLightModel.GetAllByIds(l.ctx, lightIds) model3dLightList, err := productModel3dLightModel.GetAllByIds(l.ctx, lightIds)
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product model light list") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product model light list")
} }
/* //组装灯光信息
lightListRsp := make([]*types.Light, 0, len(model3dLightList))
//产品模型数据解析model_info for _, v := range model3dLightList {
$productModel['model_info'] = $productModel['model_info'] ? json_decode($productModel['model_info']) : null; var info interface{}
if err = json.Unmarshal([]byte(*v.Info), &info); err != nil {
//产品模板数据解析template_info logx.Error(err)
if ($productTemplate) { return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse light info")
$productTemplate['template_info'] = $productTemplate['template_info'] ? json_decode($productTemplate['template_info']) : ''; }
} lightListRsp = append(lightListRsp, &types.Light{
//获取灯光列表 Id: v.Id,
$lightList = ProductModelLight::find()->where(['in', 'id', $lightListArr]) Info: info,
->select(['id', 'info']) })
->asArray()->all(); }
//产品模型数据解析model_info
//产品模型灯光数据解析 var productModelInfoRsp interface{}
foreach ($lightList as $key => $val) { if model3dInfo.ModelInfo != nil {
$lightList[$key]['info'] = json_decode($val['info'], true); if err = json.Unmarshal([]byte(*model3dInfo.ModelInfo), &productModelInfoRsp); err != nil {
} logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product 3d model info")
//查询使用该选项的模板 }
if ($partIds) { }
$optionModelInfo = ProductModel::find() //产品模板数据解析template_info
->where(['in', 'id', $partIds]) templateInfoRsp := make(map[string]interface{})
->select('id,model_info,option_template') if templatev2Info.TemplateInfo != nil {
->asArray() if err = json.Unmarshal([]byte(*templatev2Info.TemplateInfo), &templateInfoRsp); err != nil {
->all(); logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product v2 template info")
//公共模板数据 }
$optionIds = array_column($optionModelInfo, 'option_template'); }
$optionTemplates = ProductTemplateV2::find()->where(['in', 'id', $optionIds]) templateInfoRsp["tag"] = map[string]interface{}{
->asArray() "id": templateTagInfo.Id,
->all(); "title": *templateTagInfo.Title,
$optionTemplates = array_column($optionTemplates, null, 'id'); }
response := types.GetTemplatevDetailRsp{
//处理数据 ProductModelInfo: productModelInfoRsp,
$optionModelInfoArr = []; ProductTemplate: templateInfoRsp,
foreach ($optionModelInfo as $item => $row) { LightList: lightListRsp,
$rowInfo = json_decode($row['model_info'], true); OptionModelInfo: nil,
if (isset($optionTemplates[$row['option_template']])) { Tag: *model3dInfo.Tag,
$rowInfo['material_img'] = $optionTemplates[$row['option_template']]['material_img']; }
} //查询使用该选项的模板
$rowInfo['id'] = $row['id']; if len(partIds) > 0 {
$optionModelInfoArr[] = $rowInfo; model3dList, err := productModel3dModel.GetAllByIds(l.ctx, partIds, "id,model_info,option_template")
} if err != nil {
} logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")
//是否是公共模板 }
if ($productTemplate) { optionIds := make([]int64, 0, len(model3dList))
if ($productTemplate['is_public'] == 1) { for _, v := range model3dList {
$productTemplate['is_public'] = true; if v.OptionTemplate != nil {
} else { optionIds = append(optionIds, *v.OptionTemplate)
$productTemplate['is_public'] = false; }
} }
} //获取公共模板信息
optionTemplateList, err := productTemplatev2Model.FindAllByIds(l.ctx, optionIds)
//返回的数据组装 if err != nil {
return [ logx.Error(err)
'product_model_info' => $productModel['model_info'], return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product v2 template list")
'product_template' => $productTemplate ?? null, }
'light_list' => $lightList ?? [], mapOptionTemplate := make(map[int64]int)
'option_model_info' => $optionModelInfoArr ?? [], for k, v := range optionTemplateList {
'tag' => $productModel['tag'], mapOptionTemplate[v.Id] = k
];*/ }
return resp.SetStatus(basic.CodeOK) //处理数据
optionModelInfoList := make([]interface{}, 0, len(model3dList))
for _, v := range model3dList {
info := make(map[string]interface{})
if v.ModelInfo != nil {
if err = json.Unmarshal([]byte(*v.ModelInfo), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model info")
}
if optionTemplateIndex, ok := mapOptionTemplate[*v.OptionTemplate]; ok {
info["material_img"] = optionTemplateList[optionTemplateIndex].MaterialImg
}
info["id"] = v.Id
}
optionModelInfoList = append(optionModelInfoList, info)
}
response.OptionModelInfo = optionModelInfoList
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", response)
} }

View File

@ -6,16 +6,32 @@ import (
// 字符串切片转int切片 // 字符串切片转int切片
func StrSlicToIntSlice(input []string) ([]int, error) { func StrSlicToIntSlice(input []string) ([]int, error) {
priceSlic := make([]int, 0, len(input)) newSlic := make([]int, 0, len(input))
for _, p := range input { for _, p := range input {
if p == "" { if p == "" {
continue continue
} }
price, err := strconv.Atoi(p) val, err := strconv.Atoi(p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
priceSlic = append(priceSlic, price) newSlic = append(newSlic, val)
} }
return priceSlic, nil return newSlic, nil
}
// 字符串切片转int64切片
func StrSlicToInt64Slice(input []string) ([]int64, error) {
newSlic := make([]int64, 0, len(input))
for _, p := range input {
if p == "" {
continue
}
val, err := strconv.ParseInt(p, 10, 64)
if err != nil {
return nil, err
}
newSlic = append(newSlic, val)
}
return newSlic, nil
} }