修复: GET /v1/admin/promo/price/list 字段不匹配导致 400
前端发 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 与校验测试签名
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user