feat(subscription): 支持调整订阅时长(延长/缩短)
- 将"延长订阅"功能改为"调整订阅",支持正数延长、负数缩短 - 后端验证:调整天数范围 -36500 到 36500,缩短后剩余天数必须 > 0 - 前端同步更新界面文案和验证逻辑 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -359,10 +359,10 @@
|
||||
<button
|
||||
v-if="row.status === 'active'"
|
||||
@click="handleExtend(row)"
|
||||
class="flex flex-col items-center gap-0.5 rounded-lg p-1.5 text-gray-500 transition-colors hover:bg-green-50 hover:text-green-600 dark:hover:bg-green-900/20 dark:hover:text-green-400"
|
||||
class="flex flex-col items-center gap-0.5 rounded-lg p-1.5 text-gray-500 transition-colors hover:bg-blue-50 hover:text-blue-600 dark:hover:bg-blue-900/20 dark:hover:text-blue-400"
|
||||
>
|
||||
<Icon name="clock" size="sm" />
|
||||
<span class="text-xs">{{ t('admin.subscriptions.extend') }}</span>
|
||||
<Icon name="calendar" size="sm" />
|
||||
<span class="text-xs">{{ t('admin.subscriptions.adjust') }}</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="row.status === 'active'"
|
||||
@@ -512,10 +512,10 @@
|
||||
</template>
|
||||
</BaseDialog>
|
||||
|
||||
<!-- Extend Subscription Modal -->
|
||||
<!-- Adjust Subscription Modal -->
|
||||
<BaseDialog
|
||||
:show="showExtendModal"
|
||||
:title="t('admin.subscriptions.extendSubscription')"
|
||||
:title="t('admin.subscriptions.adjustSubscription')"
|
||||
width="narrow"
|
||||
@close="closeExtendModal"
|
||||
>
|
||||
@@ -527,7 +527,7 @@
|
||||
>
|
||||
<div class="rounded-lg bg-gray-50 p-4 dark:bg-dark-700">
|
||||
<p class="text-sm text-gray-600 dark:text-gray-400">
|
||||
{{ t('admin.subscriptions.extendingFor') }}
|
||||
{{ t('admin.subscriptions.adjustingFor') }}
|
||||
<span class="font-medium text-gray-900 dark:text-white">{{
|
||||
extendingSubscription.user?.email
|
||||
}}</span>
|
||||
@@ -542,10 +542,25 @@
|
||||
}}
|
||||
</span>
|
||||
</p>
|
||||
<p v-if="extendingSubscription.expires_at" class="mt-1 text-sm text-gray-600 dark:text-gray-400">
|
||||
{{ t('admin.subscriptions.remainingDays') }}:
|
||||
<span class="font-medium text-gray-900 dark:text-white">
|
||||
{{ getDaysRemaining(extendingSubscription.expires_at) ?? 0 }}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="input-label">{{ t('admin.subscriptions.form.extendDays') }}</label>
|
||||
<input v-model.number="extendForm.days" type="number" min="1" required class="input" />
|
||||
<label class="input-label">{{ t('admin.subscriptions.form.adjustDays') }}</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
v-model.number="extendForm.days"
|
||||
type="number"
|
||||
required
|
||||
class="input text-center"
|
||||
:placeholder="t('admin.subscriptions.adjustDaysPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
<p class="input-hint">{{ t('admin.subscriptions.adjustHint') }}</p>
|
||||
</div>
|
||||
</form>
|
||||
<template #footer>
|
||||
@@ -559,7 +574,7 @@
|
||||
:disabled="submitting"
|
||||
class="btn btn-primary"
|
||||
>
|
||||
{{ submitting ? t('admin.subscriptions.extending') : t('admin.subscriptions.extend') }}
|
||||
{{ submitting ? t('admin.subscriptions.adjusting') : t('admin.subscriptions.adjust') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1000,17 +1015,27 @@ const closeExtendModal = () => {
|
||||
const handleExtendSubscription = async () => {
|
||||
if (!extendingSubscription.value) return
|
||||
|
||||
// 前端验证:调整后剩余天数必须 > 0
|
||||
if (extendingSubscription.value.expires_at) {
|
||||
const currentDaysRemaining = getDaysRemaining(extendingSubscription.value.expires_at) ?? 0
|
||||
const newDaysRemaining = currentDaysRemaining + extendForm.days
|
||||
if (newDaysRemaining <= 0) {
|
||||
appStore.showError(t('admin.subscriptions.adjustWouldExpire'))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await adminAPI.subscriptions.extend(extendingSubscription.value.id, {
|
||||
days: extendForm.days
|
||||
})
|
||||
appStore.showSuccess(t('admin.subscriptions.subscriptionExtended'))
|
||||
appStore.showSuccess(t('admin.subscriptions.subscriptionAdjusted'))
|
||||
closeExtendModal()
|
||||
loadSubscriptions()
|
||||
} catch (error: any) {
|
||||
appStore.showError(error.response?.data?.detail || t('admin.subscriptions.failedToExtend'))
|
||||
console.error('Error extending subscription:', error)
|
||||
appStore.showError(error.response?.data?.detail || t('admin.subscriptions.failedToAdjust'))
|
||||
console.error('Error adjusting subscription:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user