修复(#75): 适配促销数量与永久订阅判定

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
2026-05-27 01:21:25 -07:00
parent 02b41e7a2c
commit 1c5f71cbfd
7 changed files with 136 additions and 38 deletions
+12 -8
View File
@@ -27,18 +27,22 @@ func NewModel(db *gorm.DB, _ *redis.Client) Model {
func (m *defaultPromoModel) QueryEligibleRules(ctx context.Context, subscribeId int64, quantity int64) ([]*RuleWithPrice, error) {
var list []*RuleWithPrice
err := m.db.WithContext(ctx).
Table("promo_rule AS pr").
Select("pr.*, sp.promo_price").
Joins("JOIN subscribe_promo AS sp ON sp.promo_rule_id = pr.id").
Where("sp.subscribe_id = ? AND sp.quantity = ? AND sp.promo_price > 0 AND pr.enabled = ?", subscribeId, quantity, true).
Where("pr.deleted_at IS NULL").
Order("pr.priority DESC").
Order("pr.id ASC").
err := m.eligibleRulesQuery(ctx, subscribeId, quantity).
Find(&list).Error
return list, err
}
func (m *defaultPromoModel) eligibleRulesQuery(ctx context.Context, subscribeId int64, quantity int64) *gorm.DB {
return m.db.WithContext(ctx).
Table("promo_rule AS pr").
Select("pr.*, sp.promo_price").
Joins("JOIN subscribe_promo AS sp ON sp.promo_rule_id = pr.id AND sp.quantity = ?", quantity).
Where("sp.subscribe_id = ? AND sp.promo_price > 0 AND pr.enabled = ?", subscribeId, true).
Where("pr.deleted_at IS NULL").
Order("pr.priority DESC").
Order("pr.id ASC")
}
func (m *defaultPromoModel) InsertUsage(ctx context.Context, data *Usage, tx ...*gorm.DB) error {
db := m.db.WithContext(ctx)
if len(tx) > 0 {