From e17dc4a273febb824fbce88c726e23b5dc62f776 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Fri, 29 May 2026 01:04:37 -0700 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20GET=20/v1/admin/promo/pri?= =?UTF-8?q?ce/list=20=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=20400?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端发 rule_id/subscribe_id (均可选), 后端 API 定义为 promo_rule_id (required), 直接返回 "PromoRuleId is a required field"。 对齐前端约定 (与 usage/list 命名一致): - API: promo_rule_id(required) → rule_id + subscribe_id, 均可选 - model.QueryPriceList: 改为接 PriceFilter, 按条件过滤 - 同步 fake mock 与校验测试签名 --- apis/admin/promo.api | 3 +- .../admin/promo/delete_not_found_test.go | 2 +- .../logic/admin/promo/getPriceListLogic.go | 8 ++++- .../logic/public/order/promoPricing_test.go | 2 +- internal/model/promo/model.go | 29 ++++++++++++++----- internal/types/promo_validation_test.go | 6 ++-- internal/types/types.go | 3 +- 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/apis/admin/promo.api b/apis/admin/promo.api index 3b9720e..ecf9575 100644 --- a/apis/admin/promo.api +++ b/apis/admin/promo.api @@ -52,9 +52,10 @@ type ( Items []PromoPriceItem `json:"items" validate:"required,min=1,dive"` } GetPromoPriceListRequest { - PromoRuleId int64 `form:"promo_rule_id" validate:"required,gt=0"` Page int64 `form:"page" validate:"required,gt=0"` Size int64 `form:"size" validate:"required,gt=0,lte=200"` + RuleId int64 `form:"rule_id,omitempty"` + SubscribeId int64 `form:"subscribe_id,omitempty"` } GetPromoPriceListResponse { Total int64 `json:"total"` diff --git a/internal/logic/admin/promo/delete_not_found_test.go b/internal/logic/admin/promo/delete_not_found_test.go index 8d79f28..add9eb1 100644 --- a/internal/logic/admin/promo/delete_not_found_test.go +++ b/internal/logic/admin/promo/delete_not_found_test.go @@ -54,7 +54,7 @@ func (fakePromoModel) DeletePrice(context.Context, int64) error { return nil } -func (fakePromoModel) QueryPriceList(context.Context, int64, int, int) (int64, []*promomodel.SubscribePromo, error) { +func (fakePromoModel) QueryPriceList(context.Context, promomodel.PriceFilter) (int64, []*promomodel.SubscribePromo, error) { return 0, nil, nil } diff --git a/internal/logic/admin/promo/getPriceListLogic.go b/internal/logic/admin/promo/getPriceListLogic.go index e02b043..ca817a9 100644 --- a/internal/logic/admin/promo/getPriceListLogic.go +++ b/internal/logic/admin/promo/getPriceListLogic.go @@ -3,6 +3,7 @@ package promo import ( "context" + promomodel "github.com/perfect-panel/server/internal/model/promo" "github.com/perfect-panel/server/internal/svc" "github.com/perfect-panel/server/internal/types" "github.com/perfect-panel/server/pkg/logger" @@ -25,7 +26,12 @@ func NewGetPriceListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetP } func (l *GetPriceListLogic) GetPriceList(req *types.GetPromoPriceListRequest) (*types.GetPromoPriceListResponse, error) { - total, list, err := l.svcCtx.PromoModel.QueryPriceList(l.ctx, req.PromoRuleId, int(req.Page), int(req.Size)) + total, list, err := l.svcCtx.PromoModel.QueryPriceList(l.ctx, promomodel.PriceFilter{ + Page: int(req.Page), + Size: int(req.Size), + RuleId: req.RuleId, + SubscribeId: req.SubscribeId, + }) if err != nil { l.Errorw("[GetPromoPriceList] Database Error", logger.Field("error", err.Error())) return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "get promo price list error: %v", err.Error()) diff --git a/internal/logic/public/order/promoPricing_test.go b/internal/logic/public/order/promoPricing_test.go index 5aa7a97..6e8a5b9 100644 --- a/internal/logic/public/order/promoPricing_test.go +++ b/internal/logic/public/order/promoPricing_test.go @@ -63,7 +63,7 @@ func (m *fakePromoModel) DeletePrice(context.Context, int64) error { return nil } -func (m *fakePromoModel) QueryPriceList(context.Context, int64, int, int) (int64, []*promo.SubscribePromo, error) { +func (m *fakePromoModel) QueryPriceList(context.Context, promo.PriceFilter) (int64, []*promo.SubscribePromo, error) { return 0, nil, nil } diff --git a/internal/model/promo/model.go b/internal/model/promo/model.go index 505f0c3..a9afb7e 100644 --- a/internal/model/promo/model.go +++ b/internal/model/promo/model.go @@ -24,7 +24,7 @@ type Model interface { UpsertPrices(ctx context.Context, ruleId int64, items []*SubscribePromo) error FindPrice(ctx context.Context, id int64) (*SubscribePromo, error) DeletePrice(ctx context.Context, id int64) error - QueryPriceList(ctx context.Context, ruleId int64, page, size int) (int64, []*SubscribePromo, error) + QueryPriceList(ctx context.Context, params PriceFilter) (int64, []*SubscribePromo, error) QueryUsageList(ctx context.Context, params UsageFilter) (int64, []*Usage, error) Transaction(ctx context.Context, fn func(db *gorm.DB) error) error } @@ -38,6 +38,13 @@ type UsageFilter struct { OrderNo string } +type PriceFilter struct { + Page int + Size int + RuleId int64 + SubscribeId int64 +} + type defaultPromoModel struct { db *gorm.DB } @@ -164,20 +171,26 @@ func (m *defaultPromoModel) DeletePrice(ctx context.Context, id int64) error { return m.db.WithContext(ctx).Delete(&SubscribePromo{}, id).Error } -func (m *defaultPromoModel) QueryPriceList(ctx context.Context, ruleId int64, page, size int) (int64, []*SubscribePromo, error) { - if page <= 0 { - page = 1 +func (m *defaultPromoModel) QueryPriceList(ctx context.Context, params PriceFilter) (int64, []*SubscribePromo, error) { + if params.Page <= 0 { + params.Page = 1 } - if size <= 0 { - size = 10 + if params.Size <= 0 { + params.Size = 10 } var total int64 var list []*SubscribePromo - db := m.db.WithContext(ctx).Model(&SubscribePromo{}).Where("promo_rule_id = ?", ruleId) + db := m.db.WithContext(ctx).Model(&SubscribePromo{}) + if params.RuleId > 0 { + db = db.Where("promo_rule_id = ?", params.RuleId) + } + if params.SubscribeId > 0 { + db = db.Where("subscribe_id = ?", params.SubscribeId) + } if err := db.Count(&total).Error; err != nil { return 0, nil, err } - err := db.Order("id DESC").Limit(size).Offset((page - 1) * size).Find(&list).Error + err := db.Order("id DESC").Limit(params.Size).Offset((params.Page - 1) * params.Size).Find(&list).Error return total, list, err } diff --git a/internal/types/promo_validation_test.go b/internal/types/promo_validation_test.go index afde7be..bfb58a9 100644 --- a/internal/types/promo_validation_test.go +++ b/internal/types/promo_validation_test.go @@ -34,9 +34,9 @@ func TestPromoListPageSizeLimit(t *testing.T) { { name: "price list", req: GetPromoPriceListRequest{ - PromoRuleId: 1, - Page: 1, - Size: 201, + RuleId: 1, + Page: 1, + Size: 201, }, }, { diff --git a/internal/types/types.go b/internal/types/types.go index 6b95be6..1ebe57c 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1436,9 +1436,10 @@ type GetPreSendEmailCountResponse struct { } type GetPromoPriceListRequest struct { - PromoRuleId int64 `form:"promo_rule_id" validate:"required,gt=0"` Page int64 `form:"page" validate:"required,gt=0"` Size int64 `form:"size" validate:"required,gt=0,lte=200"` + RuleId int64 `form:"rule_id,omitempty"` + SubscribeId int64 `form:"subscribe_id,omitempty"` } type GetPromoPriceListResponse struct {