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))
for _, v := range model3dLightList {
var info interface{}
if err = json.Unmarshal([]byte(*v.Info), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse light info")
}
lightListRsp = append(lightListRsp, &types.Light{
Id: v.Id,
Info: info,
})
} }
/*
//产品模型数据解析model_info //产品模型数据解析model_info
$productModel['model_info'] = $productModel['model_info'] ? json_decode($productModel['model_info']) : null; var productModelInfoRsp interface{}
if model3dInfo.ModelInfo != nil {
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")
}
}
//产品模板数据解析template_info //产品模板数据解析template_info
if ($productTemplate) { templateInfoRsp := make(map[string]interface{})
$productTemplate['template_info'] = $productTemplate['template_info'] ? json_decode($productTemplate['template_info']) : ''; if templatev2Info.TemplateInfo != nil {
if err = json.Unmarshal([]byte(*templatev2Info.TemplateInfo), &templateInfoRsp); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse product v2 template info")
} }
//获取灯光列表
$lightList = ProductModelLight::find()->where(['in', 'id', $lightListArr])
->select(['id', 'info'])
->asArray()->all();
//产品模型灯光数据解析
foreach ($lightList as $key => $val) {
$lightList[$key]['info'] = json_decode($val['info'], true);
} }
templateInfoRsp["tag"] = map[string]interface{}{
"id": templateTagInfo.Id,
"title": *templateTagInfo.Title,
}
response := types.GetTemplatevDetailRsp{
ProductModelInfo: productModelInfoRsp,
ProductTemplate: templateInfoRsp,
LightList: lightListRsp,
OptionModelInfo: nil,
Tag: *model3dInfo.Tag,
}
//查询使用该选项的模板 //查询使用该选项的模板
if ($partIds) { if len(partIds) > 0 {
$optionModelInfo = ProductModel::find() model3dList, err := productModel3dModel.GetAllByIds(l.ctx, partIds, "id,model_info,option_template")
->where(['in', 'id', $partIds]) if err != nil {
->select('id,model_info,option_template') logx.Error(err)
->asArray() return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")
->all(); }
optionIds := make([]int64, 0, len(model3dList))
//公共模板数据 for _, v := range model3dList {
$optionIds = array_column($optionModelInfo, 'option_template'); if v.OptionTemplate != nil {
$optionTemplates = ProductTemplateV2::find()->where(['in', 'id', $optionIds]) optionIds = append(optionIds, *v.OptionTemplate)
->asArray() }
->all(); }
$optionTemplates = array_column($optionTemplates, null, 'id'); //获取公共模板信息
optionTemplateList, err := productTemplatev2Model.FindAllByIds(l.ctx, optionIds)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product v2 template list")
}
mapOptionTemplate := make(map[int64]int)
for k, v := range optionTemplateList {
mapOptionTemplate[v.Id] = k
}
//处理数据 //处理数据
$optionModelInfoArr = []; optionModelInfoList := make([]interface{}, 0, len(model3dList))
foreach ($optionModelInfo as $item => $row) { for _, v := range model3dList {
$rowInfo = json_decode($row['model_info'], true); info := make(map[string]interface{})
if (isset($optionTemplates[$row['option_template']])) { if v.ModelInfo != nil {
$rowInfo['material_img'] = $optionTemplates[$row['option_template']]['material_img']; if err = json.Unmarshal([]byte(*v.ModelInfo), &info); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model info")
} }
$rowInfo['id'] = $row['id']; if optionTemplateIndex, ok := mapOptionTemplate[*v.OptionTemplate]; ok {
$optionModelInfoArr[] = $rowInfo; info["material_img"] = optionTemplateList[optionTemplateIndex].MaterialImg
} }
info["id"] = v.Id
} }
optionModelInfoList = append(optionModelInfoList, info)
//是否是公共模板
if ($productTemplate) {
if ($productTemplate['is_public'] == 1) {
$productTemplate['is_public'] = true;
} else {
$productTemplate['is_public'] = false;
} }
response.OptionModelInfo = optionModelInfoList
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", response)
//返回的数据组装
return [
'product_model_info' => $productModel['model_info'],
'product_template' => $productTemplate ?? null,
'light_list' => $lightList ?? [],
'option_model_info' => $optionModelInfoArr ?? [],
'tag' => $productModel['tag'],
];*/
return resp.SetStatus(basic.CodeOK)
} }

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
} }