修复(#75): 修复永久订阅误判回归优惠
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -164,8 +164,16 @@ func evaluateInactiveUserPromo(
|
|||||||
return false, time.Time{}, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query promo inactive user subscription failed")
|
return false, time.Time{}, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query promo inactive user subscription failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return evaluateInactiveUserExpire(lastSub.ExpireTime, params, now), ruleExpiresAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func evaluateInactiveUserExpire(lastExpire time.Time, params promoRuleParams, now time.Time) bool {
|
||||||
|
if lastExpire.Equal(time.UnixMilli(0)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
threshold := now.AddDate(0, -params.InactiveMonths, 0)
|
threshold := now.AddDate(0, -params.InactiveMonths, 0)
|
||||||
return lastSub.ExpireTime.Before(threshold) || lastSub.ExpireTime.Equal(threshold), ruleExpiresAt, nil
|
return lastExpire.Before(threshold) || lastExpire.Equal(threshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
func promoRuleExpiresAt(rule *promo.RuleWithPrice) time.Time {
|
func promoRuleExpiresAt(rule *promo.RuleWithPrice) time.Time {
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEvaluateInactiveUserExpire(t *testing.T) {
|
||||||
|
now := time.Date(2026, 5, 27, 8, 0, 0, 0, time.UTC)
|
||||||
|
params := promoRuleParams{InactiveMonths: 3}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
lastExpire time.Time
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "permanent subscription is not inactive",
|
||||||
|
lastExpire: time.UnixMilli(0),
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "active subscription is not inactive",
|
||||||
|
lastExpire: now.Add(time.Hour),
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "expire at threshold is inactive",
|
||||||
|
lastExpire: now.AddDate(0, -3, 0),
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "expire before threshold is inactive",
|
||||||
|
lastExpire: now.AddDate(0, -3, -1),
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := evaluateInactiveUserExpire(tt.lastExpire, params, now); got != tt.want {
|
||||||
|
t.Fatalf("evaluateInactiveUserExpire() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user