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
+4
View File
@@ -1,5 +1,6 @@
import api from './client';
import type {
AccountCommodityStates,
AccountExchangeRecords,
AccountEventPage,
AccountItem,
@@ -113,6 +114,9 @@ export const accountApi = {
// 三个作用域的**官方**兑换记录(点列表那一格时按需拉取,不进列表响应)
exchangeRecords: (id: number) =>
api.get<AccountExchangeRecords, AccountExchangeRecords>(`/accounts/${id}/exchange-records`),
// 账号 × 商品当前能力索引(查询快照,带最后确认时间)
commodities: (id: number, params?: { scope?: string; availability?: string; limit?: number }) =>
api.get<AccountCommodityStates, AccountCommodityStates>(`/accounts/${id}/commodities`, { params }),
// 时间线(倒序分页),event_type 为空表示全部
events: (
id: number,
+47 -2
View File
@@ -160,12 +160,21 @@ export type AccountEventType =
| 'elite_opened'
| 'esports_opened'
| 'assigned'
| 'tag_changed';
| 'tag_changed'
| 'remark_changed'
| 'automation_changed'
| 'task_started'
| 'task_succeeded'
| 'task_failed'
| 'task_stopped'
| 'query_completed'
| 'lease_acquired'
| 'lease_released';
export interface AccountEventItem {
id: number;
event_type: AccountEventType | string;
/** 粗分类:lifecycle / auth / business / ops */
/** 粗分类:lifecycle / auth / business / activity / ops */
category?: string;
occurred_at: string;
title: string;
@@ -187,6 +196,41 @@ export interface AccountEventPage {
page_size: number;
}
export type AccountCommodityAvailability =
| 'available'
| 'limited'
| 'no_stock'
| 'not_open'
| 'not_offered'
| 'expired'
| 'unknown';
export interface AccountCommodityState {
commodity_id: string;
commodity_name: string;
scope: string;
availability: AccountCommodityAvailability;
blocking_reason: string;
raw_status: string;
time_limited: boolean;
available_from: string | null;
available_until: string | null;
schedule: Array<Record<string, unknown>>;
observed_at: string | null;
valid_until: string | null;
next_check_at: string | null;
last_exchange_at: string | null;
exchange_count_365d: number;
fresh: boolean;
source: string;
error_code: string;
}
export interface AccountCommodityStates {
items: AccountCommodityState[];
summary: Record<string, number>;
}
export interface AccountOverviewStats {
recharge_total: number;
exchange_count: number;
@@ -220,6 +264,7 @@ export interface AccountOverview {
points: number | null;
gold_balance: number | null;
exchange_balance: number | null;
commodity_capability?: Record<string, number>;
/** 积分到期时间(一键查询会刷新它) */
points_expire_at: string | null;
game_name: string;
+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:一键查询结果 ──────────────────────────
放在账号信息**下面** —— 它是补充信息(账号表里没有的两项),
不该压在最上面抢主视觉。 */}