支持后台修改打手提现信息

This commit is contained in:
yml2213
2026-08-17 11:28:23 +08:00
parent ea5c2a4105
commit 77ed97fe1f
6 changed files with 317 additions and 1 deletions
@@ -21,12 +21,26 @@ import {
creditAdminWorkerWallet,
fetchAdminWorkerLevels,
fetchAdminWorkerUsers,
fetchAdminWorkerWithdrawalAccounts,
reviewAdminWorkerUser,
saveAdminWorkerWithdrawalAccount,
} from '@/services/admin'
import type { WorkerUser } from '@/types/worker-platform'
import ImageUpload from '@/components/files/ImageUpload'
import type {
AdminWorkerWithdrawalAccount,
UploadedFile,
WorkerUser,
} from '@/types/worker-platform'
import { ADMIN_DEFAULT_PAGE_SIZE, buildAdminTablePagination } from '@/utils/admin-pagination'
import { formatMoney, formatWorkerStatus } from './shared'
type WithdrawalAccountFormValues = {
accountChannel?: string
accountName?: string
accountNo?: string
wechatQrCodeImages?: UploadedFile[]
}
export default function WorkersPanel() {
const { message, modal } = App.useApp()
const queryClient = useQueryClient()
@@ -35,8 +49,14 @@ export default function WorkersPanel() {
const [pageSize, setPageSize] = useState(ADMIN_DEFAULT_PAGE_SIZE)
const [creditWorker, setCreditWorker] = useState<WorkerUser | null>(null)
const [levelWorker, setLevelWorker] = useState<WorkerUser | null>(null)
const [withdrawalAccountWorker, setWithdrawalAccountWorker] = useState<WorkerUser | null>(null)
const [withdrawalAccounts, setWithdrawalAccounts] = useState<AdminWorkerWithdrawalAccount[]>([])
const [loadingWithdrawalAccounts, setLoadingWithdrawalAccounts] = useState(false)
const [savingWithdrawalAccount, setSavingWithdrawalAccount] = useState(false)
const [creditForm] = Form.useForm()
const [levelForm] = Form.useForm<{ levelId?: number }>()
const [withdrawalAccountForm] = Form.useForm<WithdrawalAccountFormValues>()
const withdrawalAccountChannel = Form.useWatch('accountChannel', withdrawalAccountForm)
const workersQuery = useQuery({
queryKey: ['admin-worker-platform-workers', status, page, pageSize],
@@ -126,6 +146,62 @@ export default function WorkersPanel() {
}
}
async function openWithdrawalAccountModal(worker: WorkerUser) {
setWithdrawalAccountWorker(worker)
setWithdrawalAccounts([])
setLoadingWithdrawalAccounts(true)
try {
const response = await fetchAdminWorkerWithdrawalAccounts(worker.workerId)
const accounts = response.data.items
setWithdrawalAccounts(accounts)
setWithdrawalAccountFormValues('alipay', accounts)
} catch (error) {
message.error(error instanceof Error ? error.message : '读取提现信息失败')
setWithdrawalAccountWorker(null)
} finally {
setLoadingWithdrawalAccounts(false)
}
}
function setWithdrawalAccountFormValues(accountChannel: string, accounts = withdrawalAccounts) {
const account = accounts.find((item) => item.accountChannel === accountChannel)
withdrawalAccountForm.setFieldsValue({
accountChannel,
accountName: account?.accountName || '',
accountNo: account?.accountNo || '',
wechatQrCodeImages: account?.wechatQrCodeImage ? [account.wechatQrCodeImage] : [],
})
}
async function submitWithdrawalAccount(values: WithdrawalAccountFormValues) {
if (!withdrawalAccountWorker) return
const accountChannel = String(values.accountChannel || '')
setSavingWithdrawalAccount(true)
try {
const response = await saveAdminWorkerWithdrawalAccount(
withdrawalAccountWorker.workerId,
accountChannel,
{
accountName: String(values.accountName || '').trim(),
accountNo: String(values.accountNo || '').trim(),
wechatQrCodeImages: values.wechatQrCodeImages || [],
},
)
const account = response.data.account
const nextAccounts = [
...withdrawalAccounts.filter((item) => item.accountChannel !== account.accountChannel),
account,
]
setWithdrawalAccounts(nextAccounts)
setWithdrawalAccountFormValues(account.accountChannel, nextAccounts)
message.success('提现信息已保存')
} catch (error) {
message.error(error instanceof Error ? error.message : '保存提现信息失败')
} finally {
setSavingWithdrawalAccount(false)
}
}
const columns: TableColumnsType<WorkerUser> = [
{
title: '打手',
@@ -214,6 +290,7 @@ export default function WorkersPanel() {
</Button>
<Button onClick={() => setCreditWorker(row)}></Button>
<Button onClick={() => void openWithdrawalAccountModal(row)}></Button>
</Space>
),
},
@@ -267,6 +344,65 @@ export default function WorkersPanel() {
scroll={{ x: 1000 }}
/>
<Modal
title="编辑打手提现信息"
open={Boolean(withdrawalAccountWorker)}
confirmLoading={savingWithdrawalAccount}
onCancel={() => {
setWithdrawalAccountWorker(null)
setWithdrawalAccounts([])
withdrawalAccountForm.resetFields()
}}
onOk={() => withdrawalAccountForm.submit()}
destroyOnHidden
>
<Form form={withdrawalAccountForm} layout="vertical" onFinish={submitWithdrawalAccount}>
<Form.Item label="打手">
<Typography.Text>
{withdrawalAccountWorker?.displayName || withdrawalAccountWorker?.username || '-'}
</Typography.Text>
</Form.Item>
<Form.Item
label="提现方式"
name="accountChannel"
rules={[{ required: true, message: '请选择提现方式' }]}
>
<Select
loading={loadingWithdrawalAccounts}
options={[
{ value: 'alipay', label: '支付宝' },
{ value: 'wechat', label: '微信收款' },
]}
onChange={(accountChannel) => setWithdrawalAccountFormValues(accountChannel)}
/>
</Form.Item>
<Form.Item
label="收款人姓名"
name="accountName"
rules={[{ required: true, message: '请输入收款人姓名' }]}
>
<Input placeholder="请输入真实姓名" />
</Form.Item>
{withdrawalAccountChannel === 'wechat' ? (
<Form.Item
label="微信收款二维码"
name="wechatQrCodeImages"
rules={[{ required: true, message: '请上传微信收款二维码' }]}
>
<ImageUpload scene="admin-worker-withdrawal-wechat-qr" scope="admin" maxCount={1} />
</Form.Item>
) : (
<Form.Item
label="支付宝账号"
name="accountNo"
rules={[{ required: true, message: '请输入支付宝账号' }]}
>
<Input placeholder="请输入支付宝账号" />
</Form.Item>
)}
</Form>
</Modal>
<Modal
title="调整打手等级"
open={Boolean(levelWorker)}