修复(#86): 排除永久订阅回归促销误判
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
type PromoResult struct {
|
||||
@@ -148,6 +149,12 @@ func evaluateInactiveUserPromo(
|
||||
err := db.WithContext(ctx).
|
||||
Model(&user.Subscribe{}).
|
||||
Where("user_id = ?", userID).
|
||||
Order(clause.OrderBy{
|
||||
Expression: clause.Expr{
|
||||
SQL: "CASE WHEN expire_time = ? THEN 0 ELSE 1 END",
|
||||
Vars: []interface{}{permanentSubscribeExpireTime()},
|
||||
},
|
||||
}).
|
||||
Order("expire_time DESC").
|
||||
Limit(1).
|
||||
Take(&lastSub).Error
|
||||
@@ -158,8 +165,19 @@ func evaluateInactiveUserPromo(
|
||||
return false, time.Time{}, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query promo inactive user subscription failed")
|
||||
}
|
||||
|
||||
threshold := now.AddDate(0, -params.InactiveMonths, 0)
|
||||
return lastSub.ExpireTime.Before(threshold) || lastSub.ExpireTime.Equal(threshold), ruleExpiresAt, nil
|
||||
return isInactivePromoEligible(lastSub.ExpireTime, now, params.InactiveMonths), ruleExpiresAt, nil
|
||||
}
|
||||
|
||||
func isInactivePromoEligible(expireTime time.Time, now time.Time, inactiveMonths int) bool {
|
||||
if expireTime.Equal(permanentSubscribeExpireTime()) {
|
||||
return false
|
||||
}
|
||||
threshold := now.AddDate(0, -inactiveMonths, 0)
|
||||
return expireTime.Before(threshold) || expireTime.Equal(threshold)
|
||||
}
|
||||
|
||||
func permanentSubscribeExpireTime() time.Time {
|
||||
return time.UnixMilli(0)
|
||||
}
|
||||
|
||||
func promoRuleExpiresAt(rule *promo.RuleWithPrice) time.Time {
|
||||
|
||||
Reference in New Issue
Block a user