feat: support unlimited plan usage

This commit is contained in:
Zhang Minghan 2024-02-02 23:05:00 +08:00
parent ed14c5a9d6
commit b56dadce1a
8 changed files with 16 additions and 9 deletions

View File

@ -31,7 +31,8 @@ function SubscriptionUsage({ icon, name, usage }: UsageProps) {
</div> </div>
) : ( ) : (
<div className={`sub-value`}> <div className={`sub-value`}>
<p>{usage.used}</p> / <p> {usage.total} </p> <p>{usage.used}</p> /{" "}
<p> {usage.total === -1 ? "∞" : usage.total} </p>
</div> </div>
)} )}
</div> </div>

View File

@ -67,7 +67,9 @@ function PlanItem({ level }: PlanItemProps) {
{plan.items.map((item, index) => ( {plan.items.map((item, index) => (
<div key={index}> <div key={index}>
<SubscriptionIcon type={item.icon} className={`h-4 w-4 mr-1`} /> <SubscriptionIcon type={item.icon} className={`h-4 w-4 mr-1`} />
{t("sub.plan-usage", { name: item.name, times: item.value })} {item.value !== -1
? t("sub.plan-usage", { name: item.name, times: item.value })
: t("sub.plan-unlimited-usage", { name: item.name })}
<Tips> <Tips>
<div className={`api-tip text-center`}> <div className={`api-tip text-center`}>
<p>{t("sub.plan-tip")}</p> <p>{t("sub.plan-tip")}</p>

View File

@ -203,6 +203,7 @@
"plan-price": "{{money}} 元/月", "plan-price": "{{money}} 元/月",
"include-tax": "含税", "include-tax": "含税",
"plan-usage": "{{name}} 每月使用 {{times}} 次", "plan-usage": "{{name}} 每月使用 {{times}} 次",
"plan-unlimited-usage": "{{name}} 无限次使用",
"plan-tip": "可调用模型", "plan-tip": "可调用模型",
"enterprise": "企业版", "enterprise": "企业版",
"enterprise-service": "优先技术支持", "enterprise-service": "优先技术支持",

View File

@ -187,7 +187,8 @@
"migrate-failed-prompt": "Your subscription migration failed.", "migrate-failed-prompt": "Your subscription migration failed.",
"plan-usage": "{{name}} uses {{times}} times per month", "plan-usage": "{{name}} uses {{times}} times per month",
"plan-tip": "Callable Model", "plan-tip": "Callable Model",
"disable": "This site's subscription feature has been turned off" "disable": "This site's subscription feature has been turned off",
"plan-unlimited-usage": "{{name}} has unlimited uses"
}, },
"cancel": "Cancel", "cancel": "Cancel",
"confirm": "Confirm", "confirm": "Confirm",

View File

@ -187,7 +187,8 @@
"migrate-failed-prompt": "サブスクリプションの変更に失敗しました。", "migrate-failed-prompt": "サブスクリプションの変更に失敗しました。",
"plan-usage": "{{name}}は月に{{times}}回使用", "plan-usage": "{{name}}は月に{{times}}回使用",
"plan-tip": "呼び出し可能なモデル", "plan-tip": "呼び出し可能なモデル",
"disable": "このサイトのサブスクリプション機能はオフになっています" "disable": "このサイトのサブスクリプション機能はオフになっています",
"plan-unlimited-usage": "{{name}}は無制限に使用できます"
}, },
"cancel": "キャンセル", "cancel": "キャンセル",
"confirm": "確認", "confirm": "確認",

View File

@ -187,7 +187,8 @@
"migrate-failed-prompt": "Ваша подписка не удалась.", "migrate-failed-prompt": "Ваша подписка не удалась.",
"plan-usage": "{{name}} использует {{times}} раз в месяц", "plan-usage": "{{name}} использует {{times}} раз в месяц",
"plan-tip": "Вызываемая модель", "plan-tip": "Вызываемая модель",
"disable": "Функция подписки на этом сайте отключена" "disable": "Функция подписки на этом сайте отключена",
"plan-unlimited-usage": "{{name}} имеет неограниченное количество пользователей"
}, },
"cancel": "Отмена", "cancel": "Отмена",
"confirm": "Подтвердить", "confirm": "Подтвердить",

View File

@ -462,6 +462,8 @@ function PlanConfig() {
</p> </p>
<NumberInput <NumberInput
value={item.value} value={item.value}
min={-1}
acceptNegative={true}
onValueChange={(value: number) => { onValueChange={(value: number) => {
formDispatch({ formDispatch({
type: "set-item-value", type: "set-item-value",

View File

@ -225,10 +225,8 @@ func (p *PlanItem) IsExceeded(user globals.AuthLike, db *sql.DB, cache *redis.Cl
} }
func (p *PlanItem) Increase(user globals.AuthLike, cache *redis.Client) bool { func (p *PlanItem) Increase(user globals.AuthLike, cache *redis.Client) bool {
if p.Value == -1 { state := IncreaseSubscriptionUsage(cache, user, p.Id, p.Value)
return true return state || p.IsInfinity()
}
return IncreaseSubscriptionUsage(cache, user, p.Id, p.Value)
} }
func (p *PlanItem) Decrease(user globals.AuthLike, cache *redis.Client) bool { func (p *PlanItem) Decrease(user globals.AuthLike, cache *redis.Client) bool {