mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-18 14:47:26 +00:00
✨ chore: Improve subscription billing fallback and UI states
Add a lightweight active-subscription check to skip subscription pre-consume when none exist, reducing unnecessary transactions and locks. In the subscription UI, disable subscription-first options when no active plan is available, show the effective fallback to wallet with a clear notice, and distinguish “invalidated” from “expired” states. Update i18n strings across supported locales to reflect the new messages and status labels.
This commit is contained in:
@@ -666,6 +666,22 @@ func GetAllActiveUserSubscriptions(userId int) ([]SubscriptionSummary, error) {
|
||||
return buildSubscriptionSummaries(subs), nil
|
||||
}
|
||||
|
||||
// HasActiveUserSubscription returns whether the user has any active subscription.
|
||||
// This is a lightweight existence check to avoid heavy pre-consume transactions.
|
||||
func HasActiveUserSubscription(userId int) (bool, error) {
|
||||
if userId <= 0 {
|
||||
return false, errors.New("invalid userId")
|
||||
}
|
||||
now := common.GetTimestamp()
|
||||
var count int64
|
||||
if err := DB.Model(&UserSubscription{}).
|
||||
Where("user_id = ? AND status = ? AND end_time > ?", userId, "active", now).
|
||||
Count(&count).Error; err != nil {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// GetAllUserSubscriptions returns all subscriptions (active and expired) for a user.
|
||||
func GetAllUserSubscriptions(userId int) ([]SubscriptionSummary, error) {
|
||||
if userId <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user