feat(fulfillment): 展示可分配账号库存

This commit is contained in:
yml
2026-11-28 22:22:35 +08:00
parent 53626e4c2c
commit c51dec8a94
10 changed files with 550 additions and 20 deletions
@@ -2,6 +2,7 @@ import api from './client';
import type {
PlatformFulfillmentAllocationPolicy,
PlatformFulfillmentAllocationResult,
PlatformFulfillmentAccountAvailability,
PlatformFulfillmentDetail,
PlatformFulfillmentCollabSyncResult,
PlatformFulfillmentListResponse,
@@ -65,6 +66,13 @@ export const platformFulfillmentApi = {
'/platform-fulfillment/tasks',
{ params },
),
getAccountAvailability: (commodityIds: string[]) =>
api.get<
PlatformFulfillmentAccountAvailability,
PlatformFulfillmentAccountAvailability
>('/platform-fulfillment/account-availability', {
params: { commodity_ids: commodityIds.join(',') },
}),
sync: (limit = 100) =>
api.post<{ fetched: number; created: number; updated: number }, { fetched: number; created: number; updated: number }>(
'/platform-fulfillment/sync',
+15
View File
@@ -2580,6 +2580,21 @@ export interface PlatformFulfillmentAllocationPolicy {
bundleRules: PlatformFulfillmentBundleRule[];
}
export interface PlatformFulfillmentCommodityAvailability {
allocatable: number;
fullBundleAllocatable: number;
bundleCommodityCount: number;
roleCooldown: number;
leased: number;
activeCollab: number;
}
export interface PlatformFulfillmentAccountAvailability {
items: Record<string, PlatformFulfillmentCommodityAvailability>;
uniqueAllocatable: number;
updatedAt: string | null;
}
export interface PlatformFulfillmentSettings {
leaseDurationMinutes: number | null;
completedReleaseDelayMinutes: number | null;
@@ -6,7 +6,7 @@ import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Empty, Imag
import { ArrowDownOutlined, ArrowUpOutlined, CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DeleteOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, PlusOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import { douyuApi, platformFulfillmentApi } from '../api/modules';
import type { DouyuGoodsItem, DouyuTaskItem, PlatformFulfillmentBindingLog, PlatformFulfillmentBundleRule, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
import type { DouyuGoodsItem, DouyuTaskItem, PlatformFulfillmentAccountAvailability, PlatformFulfillmentBindingLog, PlatformFulfillmentBundleRule, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
import ExchangeResultImage from '../components/ExchangeResultImage';
import { copyImageToClipboard, fetchExchangeImageBlob, getExchangeImage, isExchangeTask } from '../utils/exchangeImage';
import { TASK_STATUS_COLORS, TASK_STATUS_LABELS, taskQrUrl } from './douyu-tasks/config';
@@ -584,6 +584,8 @@ export default function PlatformFulfillmentPage() {
const [pageSize, setPageSize] = useState(20);
const [rows, setRows] = useState<PlatformFulfillmentTask[]>([]);
const [total, setTotal] = useState(0);
const [accountAvailability, setAccountAvailability] = useState<PlatformFulfillmentAccountAvailability | null>(null);
const [accountAvailabilityLoading, setAccountAvailabilityLoading] = useState(false);
const [loading, setLoading] = useState(false);
const [syncing, setSyncing] = useState(false);
const [collabSyncing, setCollabSyncing] = useState(false);
@@ -681,12 +683,38 @@ export default function PlatformFulfillmentPage() {
});
setRows(result.items);
setTotal(result.pagination.total);
if (!can('platform_fulfillment:admin')) {
setAccountAvailability(null);
setAccountAvailabilityLoading(false);
} else {
const commodityIds = Array.from(
new Set(result.items.map((task) => task.commodityId.trim()).filter(Boolean)),
);
if (commodityIds.length === 0) {
setAccountAvailability({
items: {},
uniqueAllocatable: 0,
updatedAt: new Date().toISOString(),
});
setAccountAvailabilityLoading(false);
} else {
setAccountAvailabilityLoading(true);
try {
const availability = await platformFulfillmentApi.getAccountAvailability(commodityIds);
setAccountAvailability(availability);
} catch (error) {
if (!silent) message.error(getErrorMessage(error));
} finally {
setAccountAvailabilityLoading(false);
}
}
}
} catch (error) {
if (!silent) message.error(getErrorMessage(error));
} finally {
if (!silent) setLoading(false);
}
}, [keyword, page, pageSize, queueBucket, saleModeTab]);
}, [can, keyword, page, pageSize, queueBucket, saleModeTab]);
const loadDetail = useCallback(async (taskId: number, silent = false) => {
if (!silent) setDetailLoading(true);
@@ -1606,23 +1634,53 @@ export default function PlatformFulfillmentPage() {
title: '账号',
key: 'account',
width: 190,
render: (_, task) =>
task.account ? (
<Space direction="vertical" size={2}>
<Text>{task.account.nickname || task.account.username}</Text>
<Text type="secondary">
积分 {task.account.points ?? '-'} · 鱼翅 {task.account.goldBalance ?? '-'}
</Text>
<Text type="secondary">
租约 {task.lease ? '占用中' : '未占用'} · {task.lease ? leaseExpiresLabel(task.lease.expiresAt) : '-'}
</Text>
{task.sharedLeaseTaskIds?.length ? (
<Tag color="cyan">同角色共享 #{task.sharedLeaseTaskIds.join(', #')}</Tag>
render: (_, task) => {
if (task.account) {
return (
<Space direction="vertical" size={2}>
<Text>{task.account.nickname || task.account.username}</Text>
<Text type="secondary">
积分 {task.account.points ?? '-'} · 鱼翅 {task.account.goldBalance ?? '-'}
</Text>
<Text type="secondary">
租约 {task.lease ? '占用中' : '未占用'} · {task.lease ? leaseExpiresLabel(task.lease.expiresAt) : '-'}
</Text>
{task.sharedLeaseTaskIds?.length ? (
<Tag color="cyan">同角色共享 #{task.sharedLeaseTaskIds.join(', #')}</Tag>
) : null}
</Space>
);
}
const availability = accountAvailability?.items[task.commodityId];
const canViewAvailability = can('platform_fulfillment:admin');
return (
<Space direction="vertical" size={3}>
<Text type="secondary">未分配</Text>
{canViewAvailability && availability ? (
<>
<Space size={4} wrap>
<Tag color={availability.allocatable > 0 ? 'green' : 'red'}>
可用账号 {availability.allocatable}
</Tag>
{availability.bundleCommodityCount > 1 ? (
<Tag color={availability.fullBundleAllocatable > 0 ? 'cyan' : 'orange'}>
全资格 {availability.fullBundleAllocatable}
</Tag>
) : null}
</Space>
{availability.roleCooldown > 0 ||
availability.leased > 0 ||
availability.activeCollab > 0 ? (
<Text type="secondary" style={{ fontSize: 12 }}>
占用:冷却 {availability.roleCooldown} · 租约 {availability.leased} · 台账{' '}
{availability.activeCollab}
</Text>
) : null}
</>
) : null}
</Space>
) : (
<Text type="secondary">未分配</Text>
),
);
},
},
{
title: '用户角色绑定',
@@ -1978,6 +2036,21 @@ export default function PlatformFulfillmentPage() {
</Space>
) : null;
const pendingAllocationCount = rows.filter(
(task) =>
!task.account &&
task.commodityId &&
!['completed', 'cancelled'].includes(task.executionStatus),
).length;
const availabilityTagColor =
accountAvailability == null
? 'default'
: accountAvailability.uniqueAllocatable >= pendingAllocationCount
? 'green'
: accountAvailability.uniqueAllocatable > 0
? 'orange'
: 'red';
return (
<Space direction="vertical" size={16} style={{ width: '100%' }}>
<Card size="small">
@@ -1989,6 +2062,23 @@ export default function PlatformFulfillmentPage() {
<Text type="secondary">系统自动检测账号并选号;只有缺货、CK 异常或资格失败时转人工处理。客户扫码绑定后,运营可直接开通宝典、充值或兑换皮肤。</Text>
</div>
<Space wrap>
{can('platform_fulfillment:admin') ? (
<Tag
color={availabilityTagColor}
title={
accountAvailability?.updatedAt
? `库存更新时间:${formatTime(accountAvailability.updatedAt)}`
: undefined
}
>
当前页待分配 {pendingAllocationCount} · 可分配库存{' '}
{accountAvailability
? accountAvailability.uniqueAllocatable
: accountAvailabilityLoading
? '计算中'
: '-'}
</Tag>
) : null}
<Tag>进行中租约:{leaseDurationLabel(settings?.leaseDurationMinutes)}</Tag>
<Tag>订单起算:{settings?.orderMatchStartedAt ? formatTime(settings.orderMatchStartedAt) : '-'}</Tag>
<Button