完善租客等级免押与积分管理

This commit is contained in:
yml2213
2026-07-26 18:07:10 +08:00
parent 379536e5c5
commit c594b543d1
24 changed files with 1296 additions and 178 deletions
@@ -5,6 +5,7 @@ import { Search } from '@element-plus/icons-vue'
import { computed, reactive, ref } from 'vue'
import {
adjustAdminUserGrowthPoints,
adjustAdminUserWallet,
fetchAdminUsers,
freezeAdminUser,
@@ -24,6 +25,7 @@ import AdminTablePagination from '../components/AdminTablePagination.vue'
const adminSession = useAdminSessionStore()
const canAdjustWallet = computed(() => adminSession.hasPermission('user:wallet_adjust'))
const canAdjustGrowthPoints = computed(() => adminSession.hasPermission('user:growth_points'))
const submitting = ref(false)
const activeUser = ref<AdminUserItem | null>(null)
@@ -31,9 +33,14 @@ const quotaUser = ref<AdminUserItem | null>(null)
const realnameUser = ref<AdminUserItem | null>(null)
const manualRealnameUser = ref<AdminUserItem | null>(null)
const walletUser = ref<AdminUserItem | null>(null)
const growthUser = ref<AdminUserItem | null>(null)
const freezeReason = ref('')
const revokeRealnameReason = ref('')
const quotaAmount = ref(0)
const growthForm = reactive({
targetPoints: 0,
reason: '',
})
const manualRealnameForm = reactive({
name: '',
idNo: '',
@@ -85,6 +92,12 @@ function openDepositQuota(row: AdminUserItem) {
quotaAmount.value = centToYuan(row.deposit_free_quota_cent)
}
function openGrowthPoints(row: AdminUserItem) {
growthUser.value = row
growthForm.targetPoints = Number(row.renter_growth_points || 0)
growthForm.reason = ''
}
function openWalletAdjust(row: AdminUserItem) {
walletUser.value = row
walletForm.direction = 'out'
@@ -98,7 +111,7 @@ async function handleSetDepositQuota() {
submitting.value = true
try {
await setAdminUserDepositFreeQuota(quotaUser.value.id, yuanToCent(quotaAmount.value))
ElMessage.success('免押额度已更新')
ElMessage.success('人工免押额度已更新')
quotaUser.value = null
await loadUsers()
} catch (error) {
@@ -108,6 +121,51 @@ async function handleSetDepositQuota() {
}
}
async function handleAdjustGrowthPoints() {
if (!growthUser.value) return
const targetPoints = Number(growthForm.targetPoints)
if (!Number.isInteger(targetPoints) || targetPoints < 0 || targetPoints > 1000000000) {
ElMessage.warning('目标积分必须是 0 到 10 亿之间的整数')
return
}
if (targetPoints === Number(growthUser.value.renter_growth_points || 0)) {
ElMessage.warning('目标积分与当前积分相同')
return
}
if (growthForm.reason.trim().length < 2) {
ElMessage.warning('请填写至少 2 个字的调整原因')
return
}
const direction = targetPoints > growthUser.value.renter_growth_points ? '提升' : '降低'
try {
await ElMessageBox.confirm(
`确认将用户 ${growthUser.value.phone || growthUser.value.id} 的成长积分从 ${growthUser.value.renter_growth_points} ${direction}至 ${targetPoints}?`,
'确认调整积分',
{
type: 'warning',
confirmButtonText: '确认调整',
cancelButtonText: '取消',
}
)
} catch {
return
}
submitting.value = true
try {
await adjustAdminUserGrowthPoints(growthUser.value.id, {
target_points: targetPoints,
reason: growthForm.reason.trim(),
})
ElMessage.success('成长积分已更新,等级已自动重新计算')
growthUser.value = null
await loadUsers()
} catch (error) {
ElMessage.error(readError(error, '调整成长积分失败'))
} finally {
submitting.value = false
}
}
async function handleFreeze() {
if (!activeUser.value) return
submitting.value = true
@@ -258,7 +316,7 @@ function moneyCent(value: number | string | undefined) {
<div class="page-header">
<p class="eyebrow">Users</p>
<h1>用户管理</h1>
<p>查看用户信息与钱包余额,处理冻结、实名与余额调账。</p>
<p>查看用户信息,处理成长积分、人工免押、实名与余额调账。</p>
</div>
<el-button @click="loadUsers">刷新</el-button>
</div>
@@ -314,7 +372,9 @@ function moneyCent(value: number | string | undefined) {
</el-table-column>
<el-table-column label="成长等级" width="100">
<template #default="{ row }">
<el-tag type="success" effect="light">{{ row.renter_growth_level_name || '普通' }}</el-tag>
<el-tag type="success" effect="light">{{
row.renter_growth_level_name || '普通'
}}</el-tag>
</template>
</el-table-column>
<el-table-column label="成长积分" width="100" align="right">
@@ -335,8 +395,16 @@ function moneyCent(value: number | string | undefined) {
</span>
</template>
</el-table-column>
<el-table-column label="免押额度" width="100" align="right">
<template #default="{ row }">¥{{ moneyCent(row.deposit_free_quota_cent) }}</template>
<el-table-column label="免押总额" width="150" align="right">
<template #default="{ row }">
<div class="quota-cell">
<strong>¥{{ moneyCent(row.deposit_free_effective_quota_cent) }}</strong>
<span>
等级 {{ moneyCent(row.deposit_free_level_quota_cent) }} + 人工
{{ moneyCent(row.deposit_free_manual_quota_cent) }}
</span>
</div>
</template>
</el-table-column>
<el-table-column label="剩余免押" width="100" align="right">
<template #default="{ row }">¥{{ moneyCent(row.deposit_free_remaining_cent) }}</template>
@@ -344,7 +412,7 @@ function moneyCent(value: number | string | undefined) {
<el-table-column label="注册时间" min-width="160">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
<el-table-column label="操作" width="320" fixed="right" align="right">
<el-table-column label="操作" width="360" fixed="right" align="right">
<template #default="{ row }">
<div class="table-actions">
<el-button
@@ -356,8 +424,17 @@ function moneyCent(value: number | string | undefined) {
>
余额
</el-button>
<el-button
v-if="canAdjustGrowthPoints"
text
type="primary"
size="small"
@click="openGrowthPoints(row)"
>
积分
</el-button>
<el-button text type="primary" size="small" @click="openDepositQuota(row)">
免押额度
人工免押
</el-button>
<el-button
v-if="row.realname_status !== 'verified'"
@@ -513,7 +590,7 @@ function moneyCent(value: number | string | undefined) {
<el-dialog
:model-value="!!quotaUser"
title="设置免押额度"
title="设置人工免押额度"
width="520px"
@update:model-value="quotaUser = null"
>
@@ -522,10 +599,15 @@ function moneyCent(value: number | string | undefined) {
<strong>{{ quotaUser.phone }}</strong> · {{ quotaUser.nickname }}
</p>
<p>
已占用 ¥{{ moneyCent(quotaUser.deposit_free_used_cent) }},剩余 ¥{{
moneyCent(quotaUser.deposit_free_remaining_cent)
等级额度 ¥{{ moneyCent(quotaUser.deposit_free_level_quota_cent) }},人工额度 ¥{{
moneyCent(quotaUser.deposit_free_manual_quota_cent)
}}
</p>
<div class="quota-summary">
<span>有效总额 ¥{{ moneyCent(quotaUser.deposit_free_effective_quota_cent) }}</span>
<span>已占用 ¥{{ moneyCent(quotaUser.deposit_free_used_cent) }}</span>
<strong>剩余 ¥{{ moneyCent(quotaUser.deposit_free_remaining_cent) }}</strong>
</div>
<el-input-number
v-model="quotaAmount"
class="full-control"
@@ -542,6 +624,52 @@ function moneyCent(value: number | string | undefined) {
</template>
</el-dialog>
<el-dialog
:model-value="!!growthUser"
title="调整成长积分"
width="540px"
@update:model-value="growthUser = null"
>
<div v-if="growthUser" class="dialog-body growth-dialog">
<p>
<strong>{{ growthUser.phone }}</strong> · {{ growthUser.nickname || '-' }} · 当前
{{ growthUser.renter_growth_level_name }}
</p>
<div class="growth-current">
<span>当前积分</span>
<strong>{{ growthUser.renter_growth_points }}</strong>
</div>
<el-form label-position="top" @submit.prevent>
<el-form-item label="目标积分">
<el-input-number
v-model="growthForm.targetPoints"
class="full-control"
:min="0"
:max="1000000000"
:step="100"
step-strictly
/>
</el-form-item>
<el-form-item label="调整原因(必填)">
<el-input
v-model="growthForm.reason"
type="textarea"
:rows="3"
maxlength="200"
show-word-limit
placeholder="例如:运营活动赠送或修正误发积分"
/>
</el-form-item>
</el-form>
</div>
<template #footer>
<el-button :disabled="submitting" @click="growthUser = null">取消</el-button>
<el-button type="primary" :loading="submitting" @click="handleAdjustGrowthPoints">
确认调整
</el-button>
</template>
</el-dialog>
<el-dialog
:model-value="!!walletUser"
title="余额管理"
@@ -655,6 +783,22 @@ function moneyCent(value: number | string | undefined) {
color: #c2410c;
}
.quota-cell {
display: grid;
gap: 2px;
}
.quota-cell strong {
color: #0f172a;
font-variant-numeric: tabular-nums;
}
.quota-cell span {
color: #64748b;
font-size: 11px;
line-height: 1.3;
}
.table-actions {
display: inline-flex;
flex-wrap: nowrap;
@@ -688,6 +832,43 @@ function moneyCent(value: number | string | undefined) {
gap: 14px;
}
.quota-summary {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
padding: 12px;
border: 1px solid #e5e7eb;
border-radius: 8px;
background: #f8fafc;
color: #64748b;
font-size: 13px;
}
.quota-summary strong {
color: #0f172a;
}
.growth-dialog {
gap: 16px;
}
.growth-current {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 14px;
border: 1px solid #e5e7eb;
border-radius: 8px;
background: #f8fafc;
color: #64748b;
}
.growth-current strong {
color: #0f172a;
font-size: 22px;
font-variant-numeric: tabular-nums;
}
.wallet-balance-cards {
display: grid;
grid-template-columns: 1fr 1fr;