mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 10:54:00 +00:00
✨ feat(subscription): add quota reset periods and admin configuration
- Add reset period fields on subscription plans and user items - Apply automatic quota resets during pre-consume based on plan schedule - Expose reset-period configuration in the admin plan editor - Display reset cadence in subscription cards and purchase modal - Validate custom reset seconds on plan create/update
This commit is contained in:
@@ -32,6 +32,18 @@ func normalizeBillingPreference(pref string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeQuotaResetPeriod(period string) string {
|
||||
switch strings.TrimSpace(period) {
|
||||
case model.SubscriptionResetDaily,
|
||||
model.SubscriptionResetWeekly,
|
||||
model.SubscriptionResetMonthly,
|
||||
model.SubscriptionResetCustom:
|
||||
return strings.TrimSpace(period)
|
||||
default:
|
||||
return model.SubscriptionResetNever
|
||||
}
|
||||
}
|
||||
|
||||
// ---- User APIs ----
|
||||
|
||||
func GetSubscriptionPlans(c *gin.Context) {
|
||||
@@ -143,6 +155,11 @@ func AdminCreateSubscriptionPlan(c *gin.Context) {
|
||||
if req.Plan.DurationValue <= 0 && req.Plan.DurationUnit != model.SubscriptionDurationCustom {
|
||||
req.Plan.DurationValue = 1
|
||||
}
|
||||
req.Plan.QuotaResetPeriod = normalizeQuotaResetPeriod(req.Plan.QuotaResetPeriod)
|
||||
if req.Plan.QuotaResetPeriod == model.SubscriptionResetCustom && req.Plan.QuotaResetCustomSeconds <= 0 {
|
||||
common.ApiErrorMsg(c, "自定义重置周期需大于0秒")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Items) == 0 {
|
||||
common.ApiErrorMsg(c, "套餐至少需要配置一个模型权益")
|
||||
@@ -203,6 +220,11 @@ func AdminUpdateSubscriptionPlan(c *gin.Context) {
|
||||
if req.Plan.DurationValue <= 0 && req.Plan.DurationUnit != model.SubscriptionDurationCustom {
|
||||
req.Plan.DurationValue = 1
|
||||
}
|
||||
req.Plan.QuotaResetPeriod = normalizeQuotaResetPeriod(req.Plan.QuotaResetPeriod)
|
||||
if req.Plan.QuotaResetPeriod == model.SubscriptionResetCustom && req.Plan.QuotaResetCustomSeconds <= 0 {
|
||||
common.ApiErrorMsg(c, "自定义重置周期需大于0秒")
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Items) == 0 {
|
||||
common.ApiErrorMsg(c, "套餐至少需要配置一个模型权益")
|
||||
|
||||
Reference in New Issue
Block a user