feat(fulfillment): 支持手动同步斗鱼外部单协作
This commit is contained in:
@@ -31,6 +31,12 @@ export interface DouyuCollabOrder {
|
||||
shop: string;
|
||||
owner_id: number | null;
|
||||
owner_name: string;
|
||||
source_type: string;
|
||||
source_task_id: number | null;
|
||||
source_order_id: string;
|
||||
source_order_item_id: string;
|
||||
source_platform_order_id: string;
|
||||
last_synced_at: string | null;
|
||||
account_id: number | null;
|
||||
account_username: string;
|
||||
account_uid: string;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import api from './client';
|
||||
import type {
|
||||
PlatformFulfillmentDetail,
|
||||
PlatformFulfillmentCollabSyncResult,
|
||||
PlatformFulfillmentListResponse,
|
||||
PlatformFulfillmentMapping,
|
||||
PlatformFulfillmentSettings,
|
||||
@@ -38,6 +39,11 @@ export const platformFulfillmentApi = {
|
||||
null,
|
||||
{ params: { limit } },
|
||||
),
|
||||
syncCollab: (taskIds: number[]) =>
|
||||
api.post<PlatformFulfillmentCollabSyncResult, PlatformFulfillmentCollabSyncResult>(
|
||||
'/platform-fulfillment/tasks/sync-collab',
|
||||
{ task_ids: taskIds },
|
||||
),
|
||||
getTask: (taskId: number) =>
|
||||
api.get<PlatformFulfillmentDetail, PlatformFulfillmentDetail>(
|
||||
`/platform-fulfillment/tasks/${taskId}`,
|
||||
|
||||
@@ -2213,6 +2213,12 @@ export interface PlatformFulfillmentTask {
|
||||
paidAt: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
collabOrder: {
|
||||
id: number;
|
||||
orderNo: string;
|
||||
status: string;
|
||||
lastSyncedAt: string | null;
|
||||
} | null;
|
||||
account: PlatformFulfillmentAccount | null;
|
||||
lease: { id: number; status: string; expiresAt: string | null } | null;
|
||||
bindTask: PlatformFulfillmentBindTask | null;
|
||||
@@ -2248,3 +2254,20 @@ export interface PlatformFulfillmentListResponse {
|
||||
items: PlatformFulfillmentTask[];
|
||||
pagination: { page: number; pageSize: number; total: number };
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentCollabSyncItem {
|
||||
taskId: number;
|
||||
action: 'created' | 'updated' | 'skipped' | 'failed';
|
||||
reason: string;
|
||||
collabOrderId: number | null;
|
||||
orderNo: string;
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentCollabSyncResult {
|
||||
requested: number;
|
||||
created: number;
|
||||
updated: number;
|
||||
skipped: number;
|
||||
failed: number;
|
||||
items: PlatformFulfillmentCollabSyncItem[];
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ const EVENT_STYLE: Record<string, { label: string; color: string }> = {
|
||||
task_stopped: { label: '任务停止', color: 'orange' },
|
||||
query_completed: { label: '查询完成', color: 'blue' },
|
||||
lease_acquired: { label: '账号占用', color: 'cyan' },
|
||||
collab_synced: { label: '外部协作同步', color: 'geekblue' },
|
||||
lease_released: { label: '账号释放', color: 'default' },
|
||||
};
|
||||
|
||||
|
||||
@@ -1089,6 +1089,9 @@ export default function DouyuCollabPage() {
|
||||
<Text strong copyable={{ text: value }}>
|
||||
{value}
|
||||
</Text>
|
||||
{row.source_type === 'platform_fulfillment' && (
|
||||
<Tag color="cyan">履约同步 · #{row.source_task_id}</Tag>
|
||||
)}
|
||||
{row.status === 'void' && <Tag color="error">已作废:{row.void_reason || '-'}</Tag>}
|
||||
</Space>
|
||||
),
|
||||
@@ -2218,6 +2221,19 @@ export default function DouyuCollabPage() {
|
||||
<Descriptions.Item label="状态">
|
||||
<Tag color={STATUS_META[detail.status]?.color}>{detail.status_label}</Tag>
|
||||
</Descriptions.Item>
|
||||
{detail.source_type === 'platform_fulfillment' ? (
|
||||
<>
|
||||
<Descriptions.Item label="履约任务">
|
||||
#{detail.source_task_id ?? '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="来源订单">
|
||||
{detail.source_platform_order_id || detail.source_order_id || '-'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="最近同步" span={2}>
|
||||
{detail.last_synced_at ? formatTime(detail.last_synced_at) : '-'}
|
||||
</Descriptions.Item>
|
||||
</>
|
||||
) : null}
|
||||
<Descriptions.Item label="斗鱼账号">{detail.account_username || '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="账号昵称">{detail.account_nickname || '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="绑定角色">{detail.bind_game_role || '-'}</Descriptions.Item>
|
||||
|
||||
@@ -43,6 +43,17 @@ const STATUS_COLORS: Record<string, string> = {
|
||||
cancelled: 'default',
|
||||
};
|
||||
|
||||
const COLLAB_STATUS_LABELS: Record<string, string> = {
|
||||
incomplete: '待补资料',
|
||||
to_recharge: '待充值',
|
||||
recharged: '已充值',
|
||||
scripted: '已上脚本',
|
||||
done: '抢购成功',
|
||||
points_error: '积分异常',
|
||||
failed: '抢购失败',
|
||||
void: '已作废',
|
||||
};
|
||||
|
||||
const BINDING_STATUS_LABELS: Record<string, string> = {
|
||||
not_started: '未开始',
|
||||
preparing: '准备中',
|
||||
@@ -121,6 +132,10 @@ function exchangeStatusLabel(value: string) {
|
||||
return EXCHANGE_STATUS_LABELS[value] || '未知状态';
|
||||
}
|
||||
|
||||
function collabStatusLabel(value: string) {
|
||||
return COLLAB_STATUS_LABELS[value] || value || '-';
|
||||
}
|
||||
|
||||
function issueLabel(value: string) {
|
||||
if (!value) return '-';
|
||||
return ISSUE_LABELS[value] || '其他处理事项';
|
||||
@@ -254,6 +269,8 @@ export default function PlatformFulfillmentPage() {
|
||||
const [total, setTotal] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [syncing, setSyncing] = useState(false);
|
||||
const [collabSyncing, setCollabSyncing] = useState(false);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
const [selectedId, setSelectedId] = useState<number | null>(null);
|
||||
const [detail, setDetail] = useState<PlatformFulfillmentDetail | null>(null);
|
||||
const [detailLoading, setDetailLoading] = useState(false);
|
||||
@@ -381,6 +398,50 @@ export default function PlatformFulfillmentPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const syncCollab = async () => {
|
||||
const taskIds = selectedRowKeys.map(Number).filter((value) => Number.isInteger(value));
|
||||
if (taskIds.length === 0) {
|
||||
message.warning('请先勾选要同步的履约任务');
|
||||
return;
|
||||
}
|
||||
setCollabSyncing(true);
|
||||
try {
|
||||
const result = await platformFulfillmentApi.syncCollab(taskIds);
|
||||
const summary = `外部协作同步完成:新增 ${result.created},更新 ${result.updated}`;
|
||||
if (result.failed || result.skipped) {
|
||||
message.warning(`${summary},跳过 ${result.skipped},失败 ${result.failed}`);
|
||||
const problems = result.items.filter(
|
||||
(item) => item.action === 'failed' || item.action === 'skipped',
|
||||
);
|
||||
Modal.warning({
|
||||
title: '部分履约任务未同步',
|
||||
width: 560,
|
||||
content: (
|
||||
<Space direction="vertical" size={4}>
|
||||
{problems.slice(0, 20).map((item) => (
|
||||
<Text key={`${item.taskId}-${item.action}`} type="secondary">
|
||||
#{item.taskId}:{item.reason || '未同步'}
|
||||
</Text>
|
||||
))}
|
||||
{problems.length > 20 ? (
|
||||
<Text type="secondary">另有 {problems.length - 20} 条未显示</Text>
|
||||
) : null}
|
||||
</Space>
|
||||
),
|
||||
});
|
||||
} else {
|
||||
message.success(summary);
|
||||
}
|
||||
setSelectedRowKeys([]);
|
||||
await loadTasks();
|
||||
if (selectedId) await loadDetail(selectedId, true);
|
||||
} catch (error) {
|
||||
message.error(getErrorMessage(error));
|
||||
} finally {
|
||||
setCollabSyncing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const runTaskAction = async (action: () => Promise<PlatformFulfillmentDetail>) => {
|
||||
try {
|
||||
const result = await action();
|
||||
@@ -669,6 +730,22 @@ export default function PlatformFulfillmentPage() {
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '外部协作',
|
||||
key: 'collab',
|
||||
width: 150,
|
||||
render: (_, task) =>
|
||||
task.collabOrder ? (
|
||||
<Space direction="vertical" size={2}>
|
||||
<Tag color={task.collabOrder.status === 'done' ? 'success' : 'blue'}>
|
||||
{collabStatusLabel(task.collabOrder.status)}
|
||||
</Tag>
|
||||
<Text copyable={{ text: task.collabOrder.orderNo }}>{task.collabOrder.orderNo}</Text>
|
||||
</Space>
|
||||
) : (
|
||||
<Text type="secondary">未同步</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updatedAt',
|
||||
@@ -778,6 +855,14 @@ export default function PlatformFulfillmentPage() {
|
||||
<Button icon={<LinkOutlined />} disabled={!can('platform_fulfillment:admin')} onClick={() => void openMapping()}>
|
||||
商品映射
|
||||
</Button>
|
||||
<Button
|
||||
icon={<LinkOutlined />}
|
||||
loading={collabSyncing}
|
||||
disabled={!can('platform_fulfillment:use') || selectedRowKeys.length === 0}
|
||||
onClick={() => void syncCollab()}
|
||||
>
|
||||
同步外部单协作{selectedRowKeys.length > 0 ? `(${selectedRowKeys.length})` : ''}
|
||||
</Button>
|
||||
<Button type="primary" loading={syncing} icon={<SyncOutlined />} onClick={() => void sync()}>
|
||||
同步待履约订单
|
||||
</Button>
|
||||
@@ -815,7 +900,11 @@ export default function PlatformFulfillmentPage() {
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
dataSource={rows}
|
||||
scroll={{ x: 1600 }}
|
||||
rowSelection={{
|
||||
selectedRowKeys,
|
||||
onChange: setSelectedRowKeys,
|
||||
}}
|
||||
scroll={{ x: 1900 }}
|
||||
pagination={{
|
||||
current: page,
|
||||
pageSize,
|
||||
@@ -891,6 +980,11 @@ export default function PlatformFulfillmentPage() {
|
||||
<Descriptions.Item label="所需积分">{selected.requiredPoints ?? '-'}</Descriptions.Item>
|
||||
<Descriptions.Item label="执行状态">{statusLabel(selected.executionStatus)}</Descriptions.Item>
|
||||
<Descriptions.Item label="绑定状态">{bindingStatusLabel(selected.bindingStatus)}</Descriptions.Item>
|
||||
<Descriptions.Item label="外部协作单" span={2}>
|
||||
{selected.collabOrder
|
||||
? `${selected.collabOrder.orderNo} · ${collabStatusLabel(selected.collabOrder.status)}`
|
||||
: '未同步'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="兑换状态">{exchangeStatusLabel(selected.exchangeStatus)}</Descriptions.Item>
|
||||
<Descriptions.Item label="处理提示">{issueLabel(selected.issueCode)}</Descriptions.Item>
|
||||
</Descriptions>
|
||||
|
||||
Reference in New Issue
Block a user