diff --git a/model/gmodel/fs_product_template_v2_logic.go b/model/gmodel/fs_product_template_v2_logic.go index dc8a1b02..d760f398 100755 --- a/model/gmodel/fs_product_template_v2_logic.go +++ b/model/gmodel/fs_product_template_v2_logic.go @@ -57,6 +57,9 @@ func (t *FsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelI return } db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `is_del` = ? and `status` = ?", modelIds, 0, 1) + if len(fields) != 0 { + db = db.Select(fields[0]) + } switch orderBy { case "": db = db.Order("id DESC") @@ -119,3 +122,20 @@ func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx cont Take(&resp).Error return resp, err } +func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Context, modelIds []int64, templateTag string, orderBy string, fields ...string) (resp []FsProductTemplateV2, err error) { + if len(modelIds) == 0 { + return + } + db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1) + if len(fields) != 0 { + db = db.Select(fields[0]) + } + switch orderBy { + case "": + db = db.Order("id DESC") + default: + db = db.Order(orderBy) + } + err = db.Find(&resp).Error + return resp, err +} diff --git a/server/product/internal/logic/gettemplatebypidlogic.go b/server/product/internal/logic/gettemplatebypidlogic.go index 2841173f..18ccb887 100644 --- a/server/product/internal/logic/gettemplatebypidlogic.go +++ b/server/product/internal/logic/gettemplatebypidlogic.go @@ -42,6 +42,9 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, if req.Size > 0 { req.Size = image.GetCurrentSize(req.Size) } + if req.ProductTemplateTagId <= 0 { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id") + } //获取产品信息(只是获取id) productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") if err != nil { @@ -51,7 +54,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") } - //获取尺寸ids(只获取) + //获取尺寸ids(只获取id) sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id") if err != nil { logx.Error(err) @@ -80,7 +83,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq, mapModel[v.Id] = k } //获取模板数据 - productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIds(l.ctx, modelIds, "sort DESC") + productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "sort DESC") if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product templates") diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index e7f7a0f2..cf94b40b 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -340,8 +340,9 @@ type GetSizeByPidRsp struct { } type GetTemplateByPidReq struct { - Pid string `form:"pid"` - Size uint32 `form:"size"` + Pid string `form:"pid"` + Size uint32 `form:"size"` + ProductTemplateTagId int64 `form:"product_template_tag_id"` } type GetFittingByPidReq struct { diff --git a/server_api/product.api b/server_api/product.api index 3d106261..b4aca200 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -385,8 +385,9 @@ type GetSizeByPidRsp { } //获取产品模板列表 type GetTemplateByPidReq { - Pid string `form:"pid"` - Size uint32 `form:"size"` + Pid string `form:"pid"` + Size uint32 `form:"size"` + ProductTemplateTagId int64 `form:"product_template_tag_id"` } //获取产品配件数据 type GetFittingByPidReq {