391 lines
12 KiB
TypeScript
391 lines
12 KiB
TypeScript
import {
|
|
CopyOutlined,
|
|
LinkOutlined,
|
|
ReloadOutlined,
|
|
SyncOutlined,
|
|
ThunderboltOutlined,
|
|
} from '@ant-design/icons'
|
|
import {
|
|
Alert,
|
|
App,
|
|
Button,
|
|
Card,
|
|
Descriptions,
|
|
Drawer,
|
|
Input,
|
|
Select,
|
|
Space,
|
|
Tag,
|
|
Timeline,
|
|
Typography,
|
|
} from 'antd'
|
|
import type { TableColumnsType } from 'antd'
|
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
import { useState } from 'react'
|
|
|
|
import PageHeader from '@/components/admin/PageHeader'
|
|
import PercentTable from '@/components/common/PercentTable'
|
|
import {
|
|
fetchAdminDouyuFulfillmentDetail,
|
|
fetchAdminDouyuFulfillmentTasks,
|
|
refreshAdminDouyuBinding,
|
|
restartAdminDouyuBinding,
|
|
syncAdminDouyuFulfillmentTasks,
|
|
} from '@/services/admin'
|
|
import type { DouyuFulfillmentTask } from '@/types/douyu-fulfillment'
|
|
import { formatAdminDateTime } from '@/utils/admin-time'
|
|
|
|
const { Text } = Typography
|
|
|
|
const STATUS_LABELS: Record<string, string> = {
|
|
waiting_profile: '待客户填资料',
|
|
preparing: '准备账号',
|
|
qr_pending: '待扫码',
|
|
role_ready: '待确认角色',
|
|
bound: '角色已绑定',
|
|
waiting_operator: '待运营处理',
|
|
processing: '处理中',
|
|
completed: '已完成',
|
|
failed: '失败',
|
|
manual_required: '人工处理',
|
|
cancelled: '已取消',
|
|
}
|
|
|
|
const STATUS_COLORS: Record<string, string> = {
|
|
waiting_profile: 'blue',
|
|
preparing: 'gold',
|
|
qr_pending: 'cyan',
|
|
role_ready: 'orange',
|
|
bound: 'green',
|
|
waiting_operator: 'volcano',
|
|
processing: 'processing',
|
|
completed: 'success',
|
|
failed: 'error',
|
|
manual_required: 'warning',
|
|
cancelled: 'default',
|
|
}
|
|
|
|
const PLATFORM_LABELS: Record<string, string> = {
|
|
wechat: '微信',
|
|
qq: 'QQ',
|
|
}
|
|
|
|
const SYSTEM_LABELS: Record<string, string> = {
|
|
ios: '苹果',
|
|
android: '安卓',
|
|
}
|
|
|
|
export default function AdminDouyuFulfillmentPage() {
|
|
const { message } = App.useApp()
|
|
const queryClient = useQueryClient()
|
|
const [keyword, setKeyword] = useState('')
|
|
const [status, setStatus] = useState('')
|
|
const [page, setPage] = useState(1)
|
|
const [pageSize, setPageSize] = useState(20)
|
|
const [detailOrderNo, setDetailOrderNo] = useState('')
|
|
|
|
const listQuery = useQuery({
|
|
queryKey: ['admin-douyu-fulfillment', keyword, status, page, pageSize],
|
|
queryFn: () =>
|
|
fetchAdminDouyuFulfillmentTasks({
|
|
keyword: keyword.trim() || undefined,
|
|
status: status || undefined,
|
|
page,
|
|
pageSize,
|
|
}),
|
|
refetchInterval: 5000,
|
|
})
|
|
const detailQuery = useQuery({
|
|
queryKey: ['admin-douyu-fulfillment-detail', detailOrderNo],
|
|
queryFn: () => fetchAdminDouyuFulfillmentDetail(detailOrderNo),
|
|
enabled: Boolean(detailOrderNo),
|
|
refetchInterval: detailOrderNo ? 3000 : false,
|
|
})
|
|
|
|
const list = listQuery.data?.data.items || []
|
|
const pagination = listQuery.data?.data.pagination
|
|
const detail = detailQuery.data?.data
|
|
|
|
async function refreshAll() {
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({ queryKey: ['admin-douyu-fulfillment'] }),
|
|
detailOrderNo
|
|
? queryClient.invalidateQueries({
|
|
queryKey: ['admin-douyu-fulfillment-detail', detailOrderNo],
|
|
})
|
|
: Promise.resolve(),
|
|
])
|
|
}
|
|
|
|
const syncMutation = useMutation({
|
|
mutationFn: syncAdminDouyuFulfillmentTasks,
|
|
onSuccess: async (response) => {
|
|
message.success(`同步完成:新增 ${response.data.created},更新 ${response.data.updated}`)
|
|
await refreshAll()
|
|
},
|
|
onError: (error) => message.error(error instanceof Error ? error.message : '同步失败'),
|
|
})
|
|
const refreshMutation = useMutation({
|
|
mutationFn: refreshAdminDouyuBinding,
|
|
onSuccess: async () => {
|
|
message.success('绑定状态已刷新')
|
|
await refreshAll()
|
|
},
|
|
onError: (error) => message.error(error instanceof Error ? error.message : '刷新失败'),
|
|
})
|
|
const restartMutation = useMutation({
|
|
mutationFn: restartAdminDouyuBinding,
|
|
onSuccess: async () => {
|
|
message.success('已重新生成绑定二维码')
|
|
await refreshAll()
|
|
},
|
|
onError: (error) => message.error(error instanceof Error ? error.message : '重新生成失败'),
|
|
})
|
|
|
|
async function copyLink(task: DouyuFulfillmentTask) {
|
|
const url = `${window.location.origin}${task.linkPath}`
|
|
try {
|
|
await navigator.clipboard.writeText(url)
|
|
message.success('客户领取链接已复制')
|
|
} catch {
|
|
message.error('复制失败,请手动复制')
|
|
}
|
|
}
|
|
|
|
const columns: TableColumnsType<DouyuFulfillmentTask> = [
|
|
{
|
|
title: '订单 / 商品',
|
|
key: 'order',
|
|
width: 280,
|
|
render: (_, task) => (
|
|
<Space direction="vertical" size={2}>
|
|
<Text strong>{task.platform_order_id}</Text>
|
|
<Text>{task.product_name || task.sku_name || task.sku_code}</Text>
|
|
<Text type="secondary">订单项 #{task.order_item_id}</Text>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
title: '客户资料',
|
|
key: 'profile',
|
|
width: 220,
|
|
render: (_, task) =>
|
|
task.customer_role_name ? (
|
|
<Space direction="vertical" size={2}>
|
|
<Text strong>{task.customer_role_name}</Text>
|
|
<Text type="secondary">
|
|
{PLATFORM_LABELS[task.customer_platform] || '-'} ·{' '}
|
|
{SYSTEM_LABELS[task.customer_system] || '-'}
|
|
</Text>
|
|
</Space>
|
|
) : (
|
|
<Text type="secondary">待客户填写</Text>
|
|
),
|
|
},
|
|
{
|
|
title: '绑定角色',
|
|
key: 'boundRole',
|
|
width: 220,
|
|
render: (_, task) =>
|
|
task.bound_role_name ? (
|
|
<Space direction="vertical" size={2}>
|
|
<Text strong>{task.bound_role_name}</Text>
|
|
<Text type="secondary">
|
|
{[task.bound_area_name, task.bound_plat_name].filter(Boolean).join(' · ') || '-'}
|
|
</Text>
|
|
</Space>
|
|
) : (
|
|
<Text type="secondary">未识别</Text>
|
|
),
|
|
},
|
|
{
|
|
title: '状态',
|
|
dataIndex: 'status',
|
|
width: 140,
|
|
render: (value: string) => (
|
|
<Tag color={STATUS_COLORS[value] || 'default'}>{STATUS_LABELS[value] || value}</Tag>
|
|
),
|
|
},
|
|
{
|
|
title: '更新时间',
|
|
dataIndex: 'updated_at',
|
|
width: 165,
|
|
render: (value: string) => formatAdminDateTime(value),
|
|
},
|
|
{
|
|
title: '操作',
|
|
key: 'actions',
|
|
width: 360,
|
|
render: (_, task) => (
|
|
<Space wrap>
|
|
<Button size="small" onClick={() => setDetailOrderNo(task.platform_order_id)}>
|
|
详情
|
|
</Button>
|
|
<Button size="small" icon={<CopyOutlined />} onClick={() => void copyLink(task)}>
|
|
客户链接
|
|
</Button>
|
|
<Button
|
|
size="small"
|
|
icon={<ReloadOutlined />}
|
|
loading={refreshMutation.isPending}
|
|
onClick={() => refreshMutation.mutate(task.platform_order_id)}
|
|
>
|
|
刷新绑定
|
|
</Button>
|
|
</Space>
|
|
),
|
|
},
|
|
]
|
|
|
|
return (
|
|
<section className="page-stack">
|
|
<PageHeader
|
|
title="斗鱼领取工作台"
|
|
description="客户提交游戏资料并完成角色绑定;内部账号与兑换仍在直播账号履约工作台处理。"
|
|
/>
|
|
<Alert
|
|
type="info"
|
|
showIcon
|
|
message="客户领取链接格式"
|
|
description="域名/coll/d/订单号。客户资料和绑定状态会同步到 live-hub,但不会向客户展示 CK、积分或账号信息。"
|
|
/>
|
|
<Card size="small">
|
|
<Space wrap style={{ marginBottom: 16 }}>
|
|
<Input.Search
|
|
allowClear
|
|
placeholder="订单号 / 商品 / 角色名"
|
|
value={keyword}
|
|
onChange={(event) => {
|
|
setKeyword(event.target.value)
|
|
setPage(1)
|
|
}}
|
|
style={{ width: 300 }}
|
|
/>
|
|
<Select
|
|
allowClear
|
|
placeholder="全部状态"
|
|
value={status || undefined}
|
|
onChange={(value) => {
|
|
setStatus(value || '')
|
|
setPage(1)
|
|
}}
|
|
options={Object.entries(STATUS_LABELS).map(([value, label]) => ({
|
|
value,
|
|
label,
|
|
}))}
|
|
style={{ width: 160 }}
|
|
/>
|
|
<Button
|
|
type="primary"
|
|
icon={<SyncOutlined />}
|
|
loading={syncMutation.isPending}
|
|
onClick={() => syncMutation.mutate()}
|
|
>
|
|
同步斗鱼订单
|
|
</Button>
|
|
<Button icon={<ReloadOutlined />} onClick={() => void listQuery.refetch()}>
|
|
刷新
|
|
</Button>
|
|
</Space>
|
|
<PercentTable<DouyuFulfillmentTask>
|
|
rowKey="id"
|
|
loading={listQuery.isLoading}
|
|
columns={columns}
|
|
dataSource={list}
|
|
scroll={{ x: 1250 }}
|
|
pagination={{
|
|
current: pagination?.page || page,
|
|
pageSize: pagination?.pageSize || pageSize,
|
|
total: pagination?.total || 0,
|
|
showSizeChanger: true,
|
|
onChange: (nextPage, nextPageSize) => {
|
|
setPage(nextPage)
|
|
setPageSize(nextPageSize)
|
|
},
|
|
}}
|
|
/>
|
|
</Card>
|
|
|
|
<Drawer
|
|
open={Boolean(detailOrderNo)}
|
|
width="min(980px, 94vw)"
|
|
title={detail ? `斗鱼领取详情 · ${detail.task.platform_order_id}` : '斗鱼领取详情'}
|
|
onClose={() => setDetailOrderNo('')}
|
|
>
|
|
{detailQuery.isLoading || !detail ? (
|
|
<Text type="secondary">加载中...</Text>
|
|
) : (
|
|
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
|
<Alert
|
|
type={detail.comparison.matched ? 'success' : 'warning'}
|
|
showIcon
|
|
message={STATUS_LABELS[detail.task.status] || detail.task.status}
|
|
description={detail.comparison.message || detail.live.message}
|
|
/>
|
|
<Descriptions bordered size="small" column={2}>
|
|
<Descriptions.Item label="订单号" span={2}>
|
|
{detail.task.platform_order_id}
|
|
</Descriptions.Item>
|
|
<Descriptions.Item label="商品" span={2}>
|
|
{detail.task.product_name || detail.task.sku_name}
|
|
</Descriptions.Item>
|
|
<Descriptions.Item label="客户角色">
|
|
{detail.task.customer_role_name || '-'}
|
|
</Descriptions.Item>
|
|
<Descriptions.Item label="客户平台">
|
|
{PLATFORM_LABELS[detail.task.customer_platform] || '-'} ·{' '}
|
|
{SYSTEM_LABELS[detail.task.customer_system] || '-'}
|
|
</Descriptions.Item>
|
|
<Descriptions.Item label="平台角色">{detail.live.roleName || '-'}</Descriptions.Item>
|
|
<Descriptions.Item label="平台渠道">
|
|
{[detail.live.areaName, detail.live.platName].filter(Boolean).join(' · ') || '-'}
|
|
</Descriptions.Item>
|
|
<Descriptions.Item label="绑定阶段" span={2}>
|
|
{detail.task.binding_phase || '-'}
|
|
</Descriptions.Item>
|
|
</Descriptions>
|
|
<Space wrap>
|
|
<Button icon={<CopyOutlined />} onClick={() => void copyLink(detail.task)}>
|
|
复制客户链接
|
|
</Button>
|
|
<Button
|
|
icon={<ReloadOutlined />}
|
|
loading={refreshMutation.isPending}
|
|
onClick={() => refreshMutation.mutate(detail.task.platform_order_id)}
|
|
>
|
|
刷新绑定
|
|
</Button>
|
|
<Button
|
|
type="primary"
|
|
icon={<ThunderboltOutlined />}
|
|
loading={restartMutation.isPending}
|
|
onClick={() => restartMutation.mutate(detail.task.platform_order_id)}
|
|
>
|
|
重新生成二维码
|
|
</Button>
|
|
<Button icon={<LinkOutlined />} href={detail.linkPath} target="_blank">
|
|
打开客户页
|
|
</Button>
|
|
</Space>
|
|
<Card size="small" title="事件时间线">
|
|
<Timeline
|
|
items={detail.events.map((event) => ({
|
|
color: event.event_type.includes('failed') ? 'red' : 'blue',
|
|
children: (
|
|
<Space direction="vertical" size={2}>
|
|
<Text strong>{event.event_type}</Text>
|
|
<Text type="secondary">
|
|
{formatAdminDateTime(event.created_at)} · {event.actor_type}
|
|
</Text>
|
|
</Space>
|
|
),
|
|
}))}
|
|
/>
|
|
</Card>
|
|
</Space>
|
|
)}
|
|
</Drawer>
|
|
</section>
|
|
)
|
|
}
|