refactor(douyu): 统一活动查询与直播商品映射

- 收口斗鱼活动、商品、绑定信息和兑换资格查询
- 工作台改为复用统一客户端、快照与实时商品目录
- 补充活动查询与商品映射测试
This commit is contained in:
yml
2026-11-18 10:59:20 +08:00
parent 1ca768eba5
commit 0220ef995f
15 changed files with 711 additions and 303 deletions
+1
View File
@@ -35,6 +35,7 @@ export const douyuApi = {
getRechargeChannel: () => api.get<DouyuRechargeChannel, DouyuRechargeChannel>('/douyu/recharge-channel'),
updateConfig: (data: Partial<DouyuConfig>) => api.put<DouyuConfig, DouyuConfig>('/douyu/config', data),
listGoods: () => api.get<DouyuGoodsItem[], DouyuGoodsItem[]>('/douyu/goods'),
listLiveGoods: () => api.get<DouyuGoodsItem[], DouyuGoodsItem[]>('/douyu/goods/live'),
listEsportsGoods: () => api.get<DouyuGoodsItem[], DouyuGoodsItem[]>('/douyu/esports-goods'),
listPeaceGoods: () => api.get<DouyuXpdGoodsItem[], DouyuXpdGoodsItem[]>('/douyu/xpd-goods'),
createTasks: (data: DouyuTaskBatchRequest) =>
@@ -1,41 +1,9 @@
import { useCallback, useEffect, useState } from 'react';
import {
Alert,
Button,
Card,
Descriptions,
Drawer,
Empty,
Input,
InputNumber,
Modal,
QRCode,
Select,
Space,
Switch,
Table,
Tabs,
Tag,
Timeline,
Typography,
} from 'antd';
import {
CheckCircleOutlined,
CopyOutlined,
LinkOutlined,
QrcodeOutlined,
ReloadOutlined,
SyncOutlined,
UserSwitchOutlined,
} from '@ant-design/icons';
import { Alert, Button, Card, Descriptions, Drawer, Empty, Input, InputNumber, Modal, QRCode, Select, Space, Switch, Table, Tabs, Tag, Timeline, Typography } from 'antd';
import { CheckCircleOutlined, CopyOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SyncOutlined, UserSwitchOutlined } from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import { douyuApi, platformFulfillmentApi } from '../api/modules';
import type {
DouyuGoodsItem,
PlatformFulfillmentDetail,
PlatformFulfillmentMapping,
PlatformFulfillmentTask,
} from '../api/modules';
import type { DouyuGoodsItem, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentTask } from '../api/modules';
import { getErrorMessage } from '../utils/error';
import { message } from '../utils/antdMessage';
import { formatTime } from '../utils/time';
@@ -100,6 +68,7 @@ export default function PlatformFulfillmentPage() {
const [mappingPoints, setMappingPoints] = useState<number | null>(null);
const [mappingEnabled, setMappingEnabled] = useState(true);
const [goods, setGoods] = useState<DouyuGoodsItem[]>([]);
const [mappingGoodsLoading, setMappingGoodsLoading] = useState(false);
const [mappings, setMappings] = useState<PlatformFulfillmentMapping[]>([]);
const loadTasks = useCallback(async () => {
@@ -178,15 +147,35 @@ export default function PlatformFulfillmentPage() {
setMappingPoints(task?.requiredPoints ?? null);
setMappingEnabled(true);
setMappingOpen(true);
setMappingGoodsLoading(true);
try {
const [goodsRows, mappingRows] = await Promise.all([
douyuApi.listGoods(),
platformFulfillmentApi.listMappings(task?.internalSkuKey || ''),
]);
const [goodsRows, mappingRows] = await Promise.all([douyuApi.listLiveGoods(), platformFulfillmentApi.listMappings(task?.internalSkuKey || '')]);
setGoods(goodsRows);
setMappings(mappingRows);
if (goodsRows.length === 0) {
message.warning('斗鱼活动商品为空,请稍后刷新商品列表');
}
} catch (error) {
message.error(getErrorMessage(error));
} finally {
setMappingGoodsLoading(false);
}
};
const reloadMappingGoods = async () => {
setMappingGoodsLoading(true);
try {
const rows = await douyuApi.listLiveGoods();
setGoods(rows);
if (rows.length === 0) {
message.warning('斗鱼活动商品为空,请稍后重试');
} else {
message.success(`已加载 ${rows.length} 个斗鱼活动商品`);
}
} catch (error) {
message.error(getErrorMessage(error));
} finally {
setMappingGoodsLoading(false);
}
};
@@ -240,9 +229,7 @@ export default function PlatformFulfillmentPage() {
render: (_, task) => (
<Space direction="vertical" size={2}>
<Text>{task.commodityId || '未映射'}</Text>
<Text type="secondary">
{task.requiredPoints != null ? `${task.requiredPoints} 积分` : '价格未知'}
</Text>
<Text type="secondary">{task.requiredPoints != null ? `${task.requiredPoints} 积分` : '价格未知'}</Text>
</Space>
),
},
@@ -288,9 +275,7 @@ export default function PlatformFulfillmentPage() {
width: 150,
render: (_, task) => (
<Space direction="vertical" size={4}>
<Tag color={STATUS_COLORS[task.executionStatus] || 'default'}>
{statusLabel(task.executionStatus)}
</Tag>
<Tag color={STATUS_COLORS[task.executionStatus] || 'default'}>{statusLabel(task.executionStatus)}</Tag>
<Text type="secondary">兑换:{task.exchangeStatus}</Text>
</Space>
),
@@ -311,86 +296,36 @@ export default function PlatformFulfillmentPage() {
详情
</Button>
{task.executionStatus === 'pending_mapping' ? (
<Button
size="small"
type="primary"
icon={<LinkOutlined />}
disabled={!can('platform_fulfillment:admin')}
onClick={() => void openMapping(task)}
>
<Button size="small" type="primary" icon={<LinkOutlined />} disabled={!can('platform_fulfillment:admin')} onClick={() => void openMapping(task)}>
配置映射
</Button>
) : null}
{task.executionStatus === 'ready' ? (
<Button
size="small"
type="primary"
icon={<UserSwitchOutlined />}
onClick={() =>
void runTaskAction(() => platformFulfillmentApi.allocate(task.id))
}
>
<Button size="small" type="primary" icon={<UserSwitchOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.allocate(task.id))}>
自动选号
</Button>
) : null}
{task.executionStatus === 'allocated' ? (
<Button
size="small"
type="primary"
icon={<QrcodeOutlined />}
onClick={() =>
void runTaskAction(() => platformFulfillmentApi.startBinding(task.id))
}
>
<Button size="small" type="primary" icon={<QrcodeOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.startBinding(task.id))}>
生成二维码
</Button>
) : null}
{['waiting_bind', 'binding_confirming'].includes(task.executionStatus) ? (
<Button
size="small"
icon={<ReloadOutlined />}
onClick={() =>
void runTaskAction(() => platformFulfillmentApi.refreshBinding(task.id))
}
>
<Button size="small" icon={<ReloadOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.refreshBinding(task.id))}>
刷新绑定
</Button>
) : null}
{task.executionStatus === 'role_ready' ? (
<Button
size="small"
type="primary"
icon={<CheckCircleOutlined />}
onClick={() =>
void runTaskAction(() => platformFulfillmentApi.confirmBinding(task.id))
}
>
<Button size="small" type="primary" icon={<CheckCircleOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.confirmBinding(task.id))}>
确认绑定
</Button>
) : null}
{task.executionStatus === 'bound' ? (
<>
<Button
size="small"
icon={<SyncOutlined />}
onClick={() =>
void runTaskAction(() =>
platformFulfillmentApi.refreshEligibility(task.id),
)
}
>
<Button size="small" icon={<SyncOutlined />} onClick={() => void runTaskAction(() => platformFulfillmentApi.refreshEligibility(task.id))}>
刷新兑换资格
</Button>
<Button
size="small"
type="primary"
disabled={task.exchangeStatus !== 'eligible'}
onClick={() =>
void runTaskAction(() =>
platformFulfillmentApi.complete(task.id, '人工兑换完成'),
)
}
>
<Button size="small" type="primary" disabled={task.exchangeStatus !== 'eligible'} onClick={() => void runTaskAction(() => platformFulfillmentApi.complete(task.id, '人工兑换完成'))}>
完成
</Button>
</>
@@ -407,25 +342,9 @@ export default function PlatformFulfillmentPage() {
查看二维码
</Button>
) : null}
{selected.account ? (
<Button
onClick={() =>
void runTaskAction(() => platformFulfillmentApi.release(selected.id))
}
>
释放账号
</Button>
) : null}
{selected.executionStatus !== 'completed' &&
selected.executionStatus !== 'cancelled' ? (
<Button
danger
onClick={() =>
void runTaskAction(() =>
platformFulfillmentApi.cancel(selected.id, '运营取消'),
)
}
>
{selected.account ? <Button onClick={() => void runTaskAction(() => platformFulfillmentApi.release(selected.id))}>释放账号</Button> : null}
{selected.executionStatus !== 'completed' && selected.executionStatus !== 'cancelled' ? (
<Button danger onClick={() => void runTaskAction(() => platformFulfillmentApi.cancel(selected.id, '运营取消'))}>
取消
</Button>
) : null}
@@ -440,9 +359,7 @@ export default function PlatformFulfillmentPage() {
<Title level={4} style={{ margin: 0 }}>
直播账号履约工作台
</Title>
<Text type="secondary">
读取 order_site 人工订单,客户扫码绑定游戏角色,运营使用斗鱼账号人工兑换。
</Text>
<Text type="secondary">读取 order_site 人工订单,客户扫码绑定游戏角色,运营使用斗鱼账号人工兑换。</Text>
</div>
<Space wrap>
<Button icon={<LinkOutlined />} disabled={!can('platform_fulfillment:admin')} onClick={() => void openMapping()}>
@@ -500,21 +417,16 @@ export default function PlatformFulfillmentPage() {
/>
</Card>
<Drawer
open={Boolean(selectedId)}
width={760}
title={selected ? `履约详情 · ${selected.platformOrderId}` : '履约详情'}
onClose={() => setSelectedId(null)}
>
<Drawer open={Boolean(selectedId)} width={760} title={selected ? `履约详情 · ${selected.platformOrderId}` : '履约详情'} onClose={() => setSelectedId(null)}>
{detailLoading || !selected ? (
<Text type="secondary">加载中...</Text>
) : (
<Space direction="vertical" size={16} style={{ width: '100%' }}>
{selected.lastError ? (
<Alert type="warning" showIcon message={selected.lastError} />
) : null}
{selected.lastError ? <Alert type="warning" showIcon message={selected.lastError} /> : null}
<Descriptions bordered size="small" column={2}>
<Descriptions.Item label="商品" span={2}>{selected.skuName}</Descriptions.Item>
<Descriptions.Item label="商品" span={2}>
{selected.skuName}
</Descriptions.Item>
<Descriptions.Item label="内部 SKU">{selected.internalSkuKey || '-'}</Descriptions.Item>
<Descriptions.Item label="斗鱼商品">{selected.commodityId || '-'}</Descriptions.Item>
<Descriptions.Item label="订单金额">{money(selected.orderAmountFen)}</Descriptions.Item>
@@ -522,9 +434,7 @@ export default function PlatformFulfillmentPage() {
<Descriptions.Item label="执行状态">{statusLabel(selected.executionStatus)}</Descriptions.Item>
<Descriptions.Item label="绑定状态">{selected.bindingStatus}</Descriptions.Item>
<Descriptions.Item label="兑换状态">{selected.exchangeStatus}</Descriptions.Item>
<Descriptions.Item label="账号">
{selected.account?.nickname || selected.account?.username || '-'}
</Descriptions.Item>
<Descriptions.Item label="账号">{selected.account?.nickname || selected.account?.username || '-'}</Descriptions.Item>
</Descriptions>
<Card size="small" title="当前操作">
{actionButtons}
@@ -549,17 +459,10 @@ export default function PlatformFulfillmentPage() {
)}
</Drawer>
<Modal
open={qrOpen && Boolean(qrValue)}
title="客户扫码绑定游戏角色"
footer={null}
onCancel={() => setQrOpen(false)}
>
<Modal open={qrOpen && Boolean(qrValue)} title="客户扫码绑定游戏角色" footer={null} onCancel={() => setQrOpen(false)}>
<Space direction="vertical" align="center" style={{ width: '100%' }}>
{qrValue ? <QRCode value={qrValue} size={260} /> : null}
<Text type="secondary">
请客户使用对应游戏平台扫码。二维码只用于当前履约作业。
</Text>
<Text type="secondary">请客户使用对应游戏平台扫码。二维码只用于当前履约作业。</Text>
<Button
icon={<CopyOutlined />}
onClick={() => {
@@ -574,32 +477,28 @@ export default function PlatformFulfillmentPage() {
</Space>
</Modal>
<Modal
open={mappingOpen}
title="斗鱼商品映射"
width={760}
okText="保存映射"
onOk={() => void saveMapping()}
onCancel={() => setMappingOpen(false)}
>
<Modal open={mappingOpen} title="斗鱼商品映射" width={760} okText="保存映射" onOk={() => void saveMapping()} onCancel={() => setMappingOpen(false)}>
<Space direction="vertical" size={14} style={{ width: '100%' }}>
<Input
placeholder="内部 SKU,例如 套装-兔兔白日梦"
value={mappingSku}
onChange={(event) => setMappingSku(event.target.value)}
/>
<Select
showSearch
optionFilterProp="label"
placeholder="选择斗鱼精英宝典商品"
value={mappingGoodsId || undefined}
onChange={selectGoods}
options={goods.map((item) => ({
value: item.commodity_id,
label: `${item.name || item.commodity_id} · ${item.score ?? '-'} 积分`,
}))}
style={{ width: '100%' }}
/>
<Input placeholder="内部 SKU,例如 套装-兔兔白日梦" value={mappingSku} onChange={(event) => setMappingSku(event.target.value)} />
<Space.Compact style={{ width: '100%' }}>
<Select
showSearch
optionFilterProp="label"
loading={mappingGoodsLoading}
placeholder={mappingGoodsLoading ? '正在加载斗鱼活动商品…' : '选择斗鱼精英宝典商品'}
value={mappingGoodsId || undefined}
onChange={selectGoods}
options={goods.map((item) => ({
value: item.commodity_id,
label: `${item.name || item.commodity_id} · ${item.score ?? '-'} 积分`,
}))}
notFoundContent={mappingGoodsLoading ? null : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无活动商品" />}
style={{ flex: 1 }}
/>
<Button icon={<ReloadOutlined />} loading={mappingGoodsLoading} onClick={() => void reloadMappingGoods()}>
刷新商品
</Button>
</Space.Compact>
<Space>
<Text>所需积分</Text>
<InputNumber min={0} value={mappingPoints} onChange={(value) => setMappingPoints(value)} />
@@ -625,11 +524,7 @@ export default function PlatformFulfillmentPage() {
{
title: '状态',
dataIndex: 'enabled',
render: (value: boolean) => (
<Tag color={value ? 'green' : 'default'}>
{value ? '启用' : '停用'}
</Tag>
),
render: (value: boolean) => <Tag color={value ? 'green' : 'default'}>{value ? '启用' : '停用'}</Tag>,
},
]}
/>