diff --git a/model/fsproducttemplatev2model_gen.go b/model/fsproducttemplatev2model_gen.go index c6b7752a..c7e4ffac 100755 --- a/model/fsproducttemplatev2model_gen.go +++ b/model/fsproducttemplatev2model_gen.go @@ -27,7 +27,8 @@ type ( FindOne(ctx context.Context, id int64) (*FsProductTemplateV2, error) Update(ctx context.Context, data *FsProductTemplateV2) error Delete(ctx context.Context, id int64) error - FindAllByCondition(ctx context.Context, productIds []string, isDel int, status int) ([]FsProductTemplateV2, error) + FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) + FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) } defaultFsProductTemplateV2Model struct { @@ -93,9 +94,22 @@ func (m *defaultFsProductTemplateV2Model) Update(ctx context.Context, data *FsPr _, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.ModelId, data.Title, data.Name, data.CoverImg, data.TemplateInfo, data.MaterialImg, data.Sort, data.LogoWidth, data.LogoHeight, data.IsPublic, data.Status, data.Ctime, data.Tag, data.IsDel, data.Id) return err } -func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string, isDel int, status int) (resp []FsProductTemplateV2, err error) { +func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) { query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) - if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), isDel, status); err != nil { + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 0, 1); err != nil { + return nil, err + } + return +} +func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) { + query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `product_id` = ? and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) + switch sort { + case 1: + query = fmt.Sprintf("%s order by `sort` ASC") + case 2: + query = fmt.Sprintf("%s order by `sort` DESC") + } + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), productId, 0, 1); err != nil { return nil, err } return diff --git a/product/internal/logic/getproductinfologic.go b/product/internal/logic/getproductinfologic.go index 1090ae68..90d0fc72 100644 --- a/product/internal/logic/getproductinfologic.go +++ b/product/internal/logic/getproductinfologic.go @@ -75,6 +75,21 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login logx.Error(err) return &types.Response{Code: 510, Message: "failed to get product models"} } + modelIds := make([]string, 0, len(models)) + for _, v := range models { + modelIds = append(modelIds, fmt.Sprintf("%d", v.Id)) + } //通过产品id和模型id获取模板信息 + productTemplateV2Model := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) + templateV2List, err := productTemplateV2Model.FindAllByModelIdsProduct(l.ctx, modelIds, productInfo.Id, 2) + if err != nil { + logx.Error(err) + return &types.Response{Code: 510, Message: "failed to get templates"} + } + //获取模板包含的model_id + templateModelIds := make([]string, 0, len(templateV2List)) + for _, v := range templateV2List { + templateModelIds = append(templateModelIds, fmt.Sprintf("%d", v.ModelId)) + } return } diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index 6b437ac1..eb639d8c 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -106,7 +106,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login } //获取模板 productTemplateModel := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn) - productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds, 0, 1) + productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds) if err != nil { logx.Error(err) return &types.Response{Code: 510, Message: "get product template_v2 err"}