feat(fulfillment): 增加账号商品能力索引与生命周期事件

This commit is contained in:
yml
2026-11-18 19:30:59 +08:00
parent dc95d83b32
commit 667634a8df
35 changed files with 3076 additions and 82 deletions
+152 -3
View File
@@ -7,7 +7,7 @@ import type { TableProps } from 'antd';
import {
ArrowLeftOutlined, EditOutlined, ReloadOutlined, ThunderboltOutlined,
} from '@ant-design/icons';
import { accountApi, douyuApi, userApi, type AccountEventItem, type AccountOverview, type HighValueAssetState, type HighValueStatus, type UserInfo } from '../api/modules';
import { accountApi, douyuApi, userApi, type AccountCommodityState, type AccountEventItem, type AccountOverview, type HighValueAssetState, type HighValueStatus, type UserInfo } from '../api/modules';
import AccountOverviewPanel from './douyu-tasks/AccountOverviewPanel';
import { getErrorMessage } from '../utils/error';
import { message } from '../utils/antdMessage';
@@ -36,6 +36,14 @@ const EVENT_STYLE: Record<string, { label: string; color: string }> = {
assigned: { label: '分配', color: 'default' },
tag_changed: { label: '标签', color: 'default' },
remark_changed: { label: '备注', color: 'default' },
automation_changed: { label: '自动化开关', color: 'geekblue' },
task_started: { label: '任务创建', color: 'blue' },
task_succeeded: { label: '任务成功', color: 'green' },
task_failed: { label: '任务失败', color: 'red' },
task_stopped: { label: '任务停止', color: 'orange' },
query_completed: { label: '查询完成', color: 'blue' },
lease_acquired: { label: '账号占用', color: 'cyan' },
lease_released: { label: '账号释放', color: 'default' },
};
/** 事件粗分类(与后端 `account_events_service.CATEGORY_*` 对应)。 */
@@ -43,6 +51,7 @@ const CATEGORY_OPTIONS = [
{ value: 'lifecycle', label: '状态变迁' },
{ value: 'auth', label: '登录与 CK' },
{ value: 'business', label: '业务流水' },
{ value: 'activity', label: '查询与任务' },
{ value: 'ops', label: '人工操作' },
];
@@ -96,6 +105,21 @@ function eventTag(type: string) {
return <Tag color={style.color}>{style.label}</Tag>;
}
const COMMODITY_STATE: Record<string, { label: string; color: string }> = {
available: { label: '可兑换', color: 'green' },
limited: { label: '已达上限', color: 'orange' },
no_stock: { label: '无库存', color: 'default' },
not_open: { label: '未开放', color: 'gold' },
not_offered: { label: '本次未返回', color: 'default' },
expired: { label: '限时已结束', color: 'default' },
unknown: { label: '待确认', color: 'default' },
};
function commodityStateTag(value: string) {
const state = COMMODITY_STATE[value] ?? COMMODITY_STATE.unknown;
return <Tag color={state.color}>{state.label}</Tag>;
}
/** 金额展示:充值为正(绿色 ¥),兑换消耗为负(红色积分)。 */
function amountText(item: AccountEventItem) {
if (item.amount === null || item.amount === undefined) return null;
@@ -127,6 +151,9 @@ export default function AccountDetailPage() {
const [eventType, setEventType] = useState('');
const [category, setCategory] = useState('');
const [eventsLoading, setEventsLoading] = useState(false);
const [commodities, setCommodities] = useState<AccountCommodityState[]>([]);
const [commoditySummary, setCommoditySummary] = useState<Record<string, number>>({});
const [commoditiesLoading, setCommoditiesLoading] = useState(false);
const [tagDraft, setTagDraft] = useState('');
// 一键查询:向斗鱼实时查一次该账号的全部关键信息(异步任务 + 轮询结果)
const [ovLoading, setOvLoading] = useState(false);
@@ -150,6 +177,20 @@ export default function AccountDetailPage() {
return () => { alive = false; };
}, []);
const loadCommodities = useCallback(async () => {
if (!accountId) return;
setCommoditiesLoading(true);
try {
const data = await accountApi.commodities(accountId);
setCommodities(data.items);
setCommoditySummary(data.summary);
} catch (e: unknown) {
message.error(getErrorMessage(e));
} finally {
setCommoditiesLoading(false);
}
}, [accountId]);
// 一键查询:建一个只读聚合任务 → 轮询**账号自身**直到快照更新。
//
@@ -185,6 +226,7 @@ export default function AccountDetailPage() {
first = false;
if ((marker ?? '') !== before) {
setOverview(fresh);
void loadCommodities();
message.success('查询完成');
return;
}
@@ -195,7 +237,7 @@ export default function AccountDetailPage() {
} finally {
setOvLoading(false);
}
}, [id, overview?.overview_queried_at]);
}, [id, loadCommodities, overview?.overview_queried_at]);
const loadOverview = useCallback(async () => {
if (!accountId) return;
@@ -232,6 +274,10 @@ export default function AccountDetailPage() {
void loadOverview();
}, [loadOverview]);
useEffect(() => {
void loadCommodities();
}, [loadCommodities]);
useEffect(() => {
void loadEvents();
}, [loadEvents]);
@@ -267,6 +313,73 @@ export default function AccountDetailPage() {
},
];
const commodityColumns: TableProps<AccountCommodityState>['columns'] = [
{
title: '商品',
key: 'commodity',
width: 240,
render: (_value, row) => (
<Space direction="vertical" size={0}>
<Text strong>{row.commodity_name || row.commodity_id}</Text>
<Text type="secondary" style={{ fontSize: 12 }}>
{row.commodity_id}
</Text>
</Space>
),
},
{
title: '当前能力',
dataIndex: 'availability',
width: 110,
render: (value: string) => commodityStateTag(value),
},
{
title: '阻塞原因',
dataIndex: 'blocking_reason',
ellipsis: true,
render: (value: string) => value || <Text type="secondary">-</Text>,
},
{
title: '限时窗口',
width: 210,
render: (_value, row) =>
row.time_limited || row.available_from || row.available_until ? (
<Space direction="vertical" size={0}>
{row.time_limited && <Tag color="blue">限时兑换</Tag>}
<Text type="secondary" style={{ fontSize: 12 }}>
{formatTime(row.available_from)} ~ {formatTime(row.available_until)}
</Text>
</Space>
) : (
<Text type="secondary">长期</Text>
),
},
{
title: '近一年兑换',
width: 150,
render: (_value, row) => (
<Space direction="vertical" size={0}>
<span>{row.exchange_count_365d} 次</span>
<Text type="secondary" style={{ fontSize: 12 }}>
{row.last_exchange_at ? formatTime(row.last_exchange_at) : '无记录'}
</Text>
</Space>
),
},
{
title: '最后确认',
width: 170,
render: (_value, row) => (
<Space direction="vertical" size={0}>
<span>{formatTime(row.observed_at)}</span>
<Tag color={row.fresh ? 'green' : 'default'}>
{row.fresh ? '有效' : '需复查'}
</Tag>
</Space>
),
},
];
if (!accountId) {
return <Empty description="账号 ID 无效" />;
}
@@ -344,7 +457,7 @@ export default function AccountDetailPage() {
<Button icon={<ArrowLeftOutlined />} onClick={() => navigate('/accounts')}>
返回账号列表
</Button>
<Button icon={<ReloadOutlined />} onClick={() => { void loadOverview(); void loadEvents(); }}>
<Button icon={<ReloadOutlined />} onClick={() => { void loadOverview(); void loadEvents(); void loadCommodities(); }}>
刷新
</Button>
{status === 'disabled' || status === 'archived' ? (
@@ -660,6 +773,42 @@ export default function AccountDetailPage() {
</Text>
</Card>
<Card
size="small"
style={{ marginBottom: 12 }}
title={
<Space wrap>
<span>商品兑换能力</span>
<Text type="secondary" style={{ fontSize: 12, fontWeight: 'normal' }}>
可兑换 {commoditySummary.fresh_available ?? 0} / 共 {commoditySummary.total ?? 0}
</Text>
</Space>
}
extra={
<Button size="small" icon={<ReloadOutlined />} loading={commoditiesLoading} onClick={() => void loadCommodities()}>
刷新列表
</Button>
}
>
<Table<AccountCommodityState>
rowKey={(row) => `${row.scope}:${row.commodity_id}`}
columns={commodityColumns}
dataSource={commodities}
size="small"
loading={commoditiesLoading}
pagination={false}
scroll={{ x: 900, y: 320 }}
locale={{
emptyText: (
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description="尚未形成商品能力快照,请执行一键查询"
/>
),
}}
/>
</Card>
{/* ── 卡片 3:一键查询结果 ──────────────────────────
放在账号信息**下面** —— 它是补充信息(账号表里没有的两项),
不该压在最上面抢主视觉。 */}