feat(fulfillment): 支持选号优先级、三皮肤联合资格捆绑与同角色共享租约
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import api from './client';
|
||||
import type {
|
||||
PlatformFulfillmentAllocationPolicy,
|
||||
PlatformFulfillmentAllocationResult,
|
||||
PlatformFulfillmentDetail,
|
||||
PlatformFulfillmentCollabSyncResult,
|
||||
@@ -34,6 +35,7 @@ export const platformFulfillmentApi = {
|
||||
presaleWaitingReleaseTtlMinutes: number | null;
|
||||
manualRequiredLeaseTtlMinutes: number | null;
|
||||
orderMatchStartedAt: string | null;
|
||||
allocationPolicy?: PlatformFulfillmentAllocationPolicy;
|
||||
}) =>
|
||||
api.put<PlatformFulfillmentSettings, PlatformFulfillmentSettings>(
|
||||
'/platform-fulfillment/settings',
|
||||
@@ -47,6 +49,7 @@ export const platformFulfillmentApi = {
|
||||
manual_required_lease_ttl_minutes:
|
||||
data.manualRequiredLeaseTtlMinutes,
|
||||
order_match_started_at: data.orderMatchStartedAt,
|
||||
allocation_policy: data.allocationPolicy,
|
||||
},
|
||||
),
|
||||
listTasks: (params: {
|
||||
|
||||
@@ -2559,6 +2559,21 @@ export interface PlatformFulfillmentAccount {
|
||||
roleChangeAvailableAt: string | null;
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentBundleRule {
|
||||
id: string;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
mode: 'require_all' | 'prefer_all';
|
||||
commodityIds: string[];
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentAllocationPolicy {
|
||||
sameRoleReuseEnabled: boolean;
|
||||
preserveBundlePool: boolean;
|
||||
priorityOrder: string[];
|
||||
bundleRules: PlatformFulfillmentBundleRule[];
|
||||
}
|
||||
|
||||
export interface PlatformFulfillmentSettings {
|
||||
leaseDurationMinutes: number | null;
|
||||
completedReleaseDelayMinutes: number | null;
|
||||
@@ -2566,6 +2581,7 @@ export interface PlatformFulfillmentSettings {
|
||||
presaleWaitingReleaseTtlMinutes: number | null;
|
||||
manualRequiredLeaseTtlMinutes: number | null;
|
||||
orderMatchStartedAt: string | null;
|
||||
allocationPolicy?: PlatformFulfillmentAllocationPolicy;
|
||||
updatedAt: string | null;
|
||||
}
|
||||
|
||||
@@ -2707,6 +2723,7 @@ export interface PlatformFulfillmentTask {
|
||||
} | null;
|
||||
account: PlatformFulfillmentAccount | null;
|
||||
lease: { id: number; status: string; expiresAt: string | null } | null;
|
||||
sharedLeaseTaskIds?: number[];
|
||||
bindTask: PlatformFulfillmentBindTask | null;
|
||||
bindingEvidence: PlatformFulfillmentBindingEvidence | null;
|
||||
customerProfile: PlatformFulfillmentCustomerProfile | null;
|
||||
|
||||
@@ -3,10 +3,10 @@ import { useNavigate } from 'react-router-dom';
|
||||
import dayjs from 'dayjs';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Empty, Image, Input, InputNumber, Modal, QRCode, Row, Segmented, Select, Space, Switch, Table, Tabs, Tag, Timeline, Typography } from 'antd';
|
||||
import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
|
||||
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, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
|
||||
import type { DouyuGoodsItem, DouyuTaskItem, 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';
|
||||
@@ -171,6 +171,7 @@ const EVENT_LABELS: Record<string, string> = {
|
||||
binding_confirmed: '履约绑定已确认',
|
||||
binding_manually_confirmed: '人工确认绑定',
|
||||
binding_reused_existing_pair: '复用同账号同角色',
|
||||
binding_reused_same_role_account: '同角色共享账号自动同步绑定',
|
||||
binding_sync_rejected: '忽略不匹配的绑定证据',
|
||||
binding_scanned_role_mismatch: '扫码角色与下单资料不一致',
|
||||
binding_verified: '斗鱼绑定复核通过',
|
||||
@@ -196,6 +197,7 @@ const EVENT_LABELS: Record<string, string> = {
|
||||
const ISSUE_LABELS: Record<string, string> = {
|
||||
mapping_missing: '商品映射缺失',
|
||||
no_eligible_account: '没有可分配账号',
|
||||
bundle_co_eligibility_missing: '没有同时可兑联合皮肤的账号',
|
||||
capability_cache_miss: '账号商品能力待补货',
|
||||
account_lease_conflict: '候选账号正被其他任务占用',
|
||||
account_pool_busy: '资格账号暂时全部占用',
|
||||
@@ -228,6 +230,36 @@ const DOUYU_ACTION_LABELS: Record<string, string> = {
|
||||
exchange_goods: '兑换订单皮肤',
|
||||
};
|
||||
|
||||
const DEFAULT_PRIORITY_ORDER = [
|
||||
'same_role_reuse',
|
||||
'bundle_match',
|
||||
'preserve_bundle_pool',
|
||||
'resource_ready',
|
||||
'points_asc',
|
||||
'ck_freshness',
|
||||
];
|
||||
|
||||
const PRIORITY_LABELS: Record<string, { label: string; desc: string }> = {
|
||||
same_role_reuse: { label: '同客户角色复用', desc: '同角色多单优先分配给已绑定的同一个斗鱼账号' },
|
||||
bundle_match: { label: '联合全资格匹配', desc: '命中捆绑商品时优先全量可兑账号' },
|
||||
preserve_bundle_pool: { label: '保留捆绑账号池', desc: '普通单尽量避开具备全捆绑资格的账号' },
|
||||
resource_ready: { label: '资源就绪度', desc: '优先已开通精英宝典且积分充足的账号' },
|
||||
points_asc: { label: '积分升序', desc: '尽量优先消耗积分贴近需求的账号' },
|
||||
ck_freshness: { label: 'CK 新鲜度', desc: '优先最近刚校验通过 CK 的账号' },
|
||||
};
|
||||
|
||||
const DEFAULT_BUNDLE_RULE: PlatformFulfillmentBundleRule = {
|
||||
id: 'presale_trio_2026_11',
|
||||
name: '怪诞乔克/冥河/雪国三皮肤全资格捆绑(临时)',
|
||||
enabled: true,
|
||||
mode: 'require_all',
|
||||
commodityIds: [
|
||||
'20260120QYOOB_bag412',
|
||||
'20260120QYOOB_bag413',
|
||||
'20260120QYOOB_bag414',
|
||||
],
|
||||
};
|
||||
|
||||
function statusLabel(value: string) {
|
||||
return STATUS_OPTIONS.find((item) => item.value === value)?.label || value;
|
||||
}
|
||||
@@ -342,7 +374,8 @@ function eventDescription(event: { eventType: string; detail: Record<string, unk
|
||||
}
|
||||
if (event.eventType === 'account_allocated') {
|
||||
const reasons = Array.isArray(detail.softReasons) ? detail.softReasons.map(String) : [];
|
||||
const base = `账号 ${String(detail.accountName || '-')},实时积分 ${String(detail.points ?? '-')}`;
|
||||
const reusedRole = detail.allocationStrategy === 'same_role_reuse';
|
||||
const base = `${reusedRole ? '复用同客户角色账号 ' : '账号 '}${String(detail.accountName || '-')},实时积分 ${String(detail.points ?? '-')}`;
|
||||
return reasons.length ? `${base};后续需要:${reasons.join('、')}` : `${base};可直接兑换`;
|
||||
}
|
||||
if (event.eventType === 'mapping_updated') {
|
||||
@@ -419,6 +452,9 @@ function eventDescription(event: { eventType: string; detail: Record<string, unk
|
||||
if (event.eventType === 'binding_reused_existing_pair') {
|
||||
return `本次扫码角色 ${String(detail.roleName || '-')} 与账号当前角色一致,直接复用`;
|
||||
}
|
||||
if (event.eventType === 'binding_reused_same_role_account') {
|
||||
return `同客户角色(${String(detail.roleName || '-')})共享账号已由任务 #${String(detail.sourceTaskId || '-')} 完成绑定,本单自动同步为待兑换`;
|
||||
}
|
||||
if (event.eventType === 'binding_account_locked_elsewhere') {
|
||||
return String(detail.message || '斗鱼账号 7 天内已绑定其他角色,请换号或等待');
|
||||
}
|
||||
@@ -588,6 +624,10 @@ export default function PlatformFulfillmentPage() {
|
||||
const [presaleWaitingReleaseTtl, setPresaleWaitingReleaseTtl] = useState<number | null>(null);
|
||||
const [manualRequiredLeaseTtl, setManualRequiredLeaseTtl] = useState<number | null>(null);
|
||||
const [orderMatchStartedAt, setOrderMatchStartedAt] = useState<Dayjs | null>(null);
|
||||
const [sameRoleReuseEnabled, setSameRoleReuseEnabled] = useState(true);
|
||||
const [preserveBundlePool, setPreserveBundlePool] = useState(true);
|
||||
const [priorityOrder, setPriorityOrder] = useState<string[]>(DEFAULT_PRIORITY_ORDER);
|
||||
const [bundleRules, setBundleRules] = useState<PlatformFulfillmentBundleRule[]>([DEFAULT_BUNDLE_RULE]);
|
||||
const [savingSettings, setSavingSettings] = useState(false);
|
||||
const [douyuActionLoading, setDouyuActionLoading] = useState('');
|
||||
const [douyuActionType, setDouyuActionType] = useState('');
|
||||
@@ -1330,9 +1370,95 @@ export default function PlatformFulfillmentPage() {
|
||||
setManualRequiredLeaseTtl(
|
||||
settings?.manualRequiredLeaseTtlMinutes ?? null,
|
||||
);
|
||||
const policy = settings?.allocationPolicy;
|
||||
setSameRoleReuseEnabled(policy?.sameRoleReuseEnabled ?? true);
|
||||
setPreserveBundlePool(policy?.preserveBundlePool ?? true);
|
||||
setPriorityOrder(
|
||||
policy?.priorityOrder?.length ? [...policy.priorityOrder] : [...DEFAULT_PRIORITY_ORDER],
|
||||
);
|
||||
setBundleRules(
|
||||
policy?.bundleRules
|
||||
? policy.bundleRules.map((rule) => ({
|
||||
...rule,
|
||||
commodityIds: [...rule.commodityIds],
|
||||
}))
|
||||
: [{ ...DEFAULT_BUNDLE_RULE, commodityIds: [...DEFAULT_BUNDLE_RULE.commodityIds] }],
|
||||
);
|
||||
setSettingsOpen(true);
|
||||
if (!goods.length || !mappings.length) {
|
||||
void Promise.all([
|
||||
goods.length ? Promise.resolve(goods) : douyuApi.listLiveGoods().catch(() => []),
|
||||
mappings.length
|
||||
? Promise.resolve(mappings)
|
||||
: platformFulfillmentApi.listMappings({ include_archived: false }).catch(() => []),
|
||||
]).then(([goodsRows, mappingRows]) => {
|
||||
if (goodsRows.length && !goods.length) setGoods(goodsRows);
|
||||
if (mappingRows.length && !mappings.length) setMappings(mappingRows);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const movePriorityItem = (index: number, direction: -1 | 1) => {
|
||||
const nextIndex = index + direction;
|
||||
if (nextIndex < 0 || nextIndex >= priorityOrder.length) return;
|
||||
setPriorityOrder((prev) => {
|
||||
const next = [...prev];
|
||||
const [item] = next.splice(index, 1);
|
||||
next.splice(nextIndex, 0, item);
|
||||
return next;
|
||||
});
|
||||
};
|
||||
|
||||
const addBundleRule = () => {
|
||||
const nextIndex = bundleRules.length + 1;
|
||||
setBundleRules((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: `bundle_rule_${Date.now()}_${nextIndex}`,
|
||||
name: `联合选号规则 ${nextIndex}`,
|
||||
enabled: true,
|
||||
mode: 'require_all',
|
||||
commodityIds: [],
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const updateBundleRule = (
|
||||
index: number,
|
||||
patch: Partial<PlatformFulfillmentBundleRule>,
|
||||
) => {
|
||||
setBundleRules((prev) =>
|
||||
prev.map((item, idx) => (idx === index ? { ...item, ...patch } : item)),
|
||||
);
|
||||
};
|
||||
|
||||
const removeBundleRule = (index: number) => {
|
||||
setBundleRules((prev) => prev.filter((_, idx) => idx !== index));
|
||||
};
|
||||
|
||||
const bundleCommodityOptions = (() => {
|
||||
const map = new Map<string, string>();
|
||||
for (const item of goods) {
|
||||
const id = String(item.commodity_id || '').trim();
|
||||
if (!id) continue;
|
||||
map.set(id, `${item.name || id}(${id})`);
|
||||
}
|
||||
for (const row of mappings) {
|
||||
const id = String(row.commodityId || '').trim();
|
||||
if (!id || map.has(id)) continue;
|
||||
map.set(id, `${row.goodsName || row.internalSkuKey || id}(${id})`);
|
||||
}
|
||||
for (const rule of bundleRules) {
|
||||
for (const rawId of rule.commodityIds) {
|
||||
const id = String(rawId || '').trim();
|
||||
if (id && !map.has(id)) {
|
||||
map.set(id, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(map.entries()).map(([value, label]) => ({ value, label }));
|
||||
})();
|
||||
|
||||
const saveLeaseSettings = async () => {
|
||||
const minutes =
|
||||
leaseDurationMode === 'unlimited'
|
||||
@@ -1357,6 +1483,16 @@ export default function PlatformFulfillmentPage() {
|
||||
presaleWaitingReleaseTtlMinutes: presaleWaitingReleaseTtl,
|
||||
manualRequiredLeaseTtlMinutes: manualRequiredLeaseTtl,
|
||||
orderMatchStartedAt: orderMatchStartedAt.toISOString(),
|
||||
allocationPolicy: {
|
||||
sameRoleReuseEnabled,
|
||||
preserveBundlePool,
|
||||
priorityOrder,
|
||||
bundleRules: bundleRules.map((rule) => ({
|
||||
...rule,
|
||||
name: rule.name.trim() || rule.id,
|
||||
commodityIds: rule.commodityIds.map((id) => id.trim()).filter(Boolean),
|
||||
})),
|
||||
},
|
||||
});
|
||||
setSettings(result);
|
||||
setSettingsOpen(false);
|
||||
@@ -1442,6 +1578,9 @@ export default function PlatformFulfillmentPage() {
|
||||
<Text type="secondary">
|
||||
租约 {task.lease ? '占用中' : '未占用'} · {task.lease ? leaseExpiresLabel(task.lease.expiresAt) : '-'}
|
||||
</Text>
|
||||
{task.sharedLeaseTaskIds?.length ? (
|
||||
<Tag color="cyan">同角色共享 #{task.sharedLeaseTaskIds.join(', #')}</Tag>
|
||||
) : null}
|
||||
</Space>
|
||||
) : (
|
||||
<Text type="secondary">未分配</Text>
|
||||
@@ -2156,7 +2295,12 @@ export default function PlatformFulfillmentPage() {
|
||||
{formatTime(selected.account.roleChangeAvailableAt) || '无冷却'}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="租约到期" span={2}>
|
||||
{selected.lease ? leaseExpiresLabel(selected.lease.expiresAt) : '-'}
|
||||
<Space size={8} wrap>
|
||||
<span>{selected.lease ? leaseExpiresLabel(selected.lease.expiresAt) : '-'}</span>
|
||||
{selected.sharedLeaseTaskIds?.length ? (
|
||||
<Tag color="cyan">同角色共享 #{selected.sharedLeaseTaskIds.join(', #')}</Tag>
|
||||
) : null}
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
) : (
|
||||
@@ -2729,7 +2873,8 @@ export default function PlatformFulfillmentPage() {
|
||||
|
||||
<Modal
|
||||
open={settingsOpen}
|
||||
title="履约同步与租约设置"
|
||||
title="履约同步、租约与自动选号策略"
|
||||
width={760}
|
||||
okText="保存设置"
|
||||
confirmLoading={savingSettings}
|
||||
onOk={() => void saveLeaseSettings()}
|
||||
@@ -2840,6 +2985,155 @@ export default function PlatformFulfillmentPage() {
|
||||
message="按任务状态应用租约策略"
|
||||
description="保存后会按每个任务当前状态重新计算租约,不会把所有预售、人工和进行中任务统一套用同一个 TTL。"
|
||||
/>
|
||||
<Card size="small" title="自动选号优先级与联合捆绑规则">
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Space align="center">
|
||||
<Switch
|
||||
checked={sameRoleReuseEnabled}
|
||||
onChange={setSameRoleReuseEnabled}
|
||||
/>
|
||||
<span>同客户角色多单复用同一斗鱼号</span>
|
||||
</Space>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Space align="center">
|
||||
<Switch
|
||||
checked={preserveBundlePool}
|
||||
onChange={setPreserveBundlePool}
|
||||
/>
|
||||
<span>普通单避开三皮肤全资格账号池</span>
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<div>
|
||||
<Text strong>选号优先级顺序(自上而下依次生效)</Text>
|
||||
<Space direction="vertical" size={6} style={{ width: '100%', marginTop: 8 }}>
|
||||
{priorityOrder.map((key, idx) => {
|
||||
const meta = PRIORITY_LABELS[key] || { label: key, desc: '' };
|
||||
return (
|
||||
<div
|
||||
key={key}
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: 8,
|
||||
padding: '6px 10px',
|
||||
border: '1px solid #f0f0f0',
|
||||
borderRadius: 6,
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<Text strong>{idx + 1}. {meta.label}</Text>
|
||||
{meta.desc ? (
|
||||
<Text type="secondary" style={{ marginLeft: 8, fontSize: 12 }}>
|
||||
{meta.desc}
|
||||
</Text>
|
||||
) : null}
|
||||
</div>
|
||||
<Space size={4}>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ArrowUpOutlined />}
|
||||
disabled={idx === 0}
|
||||
onClick={() => movePriorityItem(idx, -1)}
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ArrowDownOutlined />}
|
||||
disabled={idx === priorityOrder.length - 1}
|
||||
onClick={() => movePriorityItem(idx, 1)}
|
||||
/>
|
||||
</Space>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: 8,
|
||||
}}
|
||||
>
|
||||
<Text strong>商品全资格捆绑规则</Text>
|
||||
<Button size="small" icon={<PlusOutlined />} onClick={addBundleRule}>
|
||||
新增规则
|
||||
</Button>
|
||||
</div>
|
||||
{bundleRules.length === 0 ? (
|
||||
<Text type="secondary">暂无捆绑规则,所有商品按单品资格自由选号。</Text>
|
||||
) : (
|
||||
<Space direction="vertical" size={10} style={{ width: '100%' }}>
|
||||
{bundleRules.map((rule, idx) => (
|
||||
<Card
|
||||
key={rule.id}
|
||||
size="small"
|
||||
styles={{ body: { padding: 10 } }}
|
||||
title={
|
||||
<Space size={8}>
|
||||
<Switch
|
||||
size="small"
|
||||
checked={rule.enabled}
|
||||
onChange={(checked) => updateBundleRule(idx, { enabled: checked })}
|
||||
/>
|
||||
<Input
|
||||
size="small"
|
||||
value={rule.name}
|
||||
onChange={(e) => updateBundleRule(idx, { name: e.target.value })}
|
||||
placeholder="规则名称"
|
||||
style={{ width: 260 }}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
extra={
|
||||
<Space size={8}>
|
||||
<Select
|
||||
size="small"
|
||||
value={rule.mode}
|
||||
style={{ width: 150 }}
|
||||
onChange={(value) => updateBundleRule(idx, { mode: value })}
|
||||
options={[
|
||||
{ value: 'require_all', label: '必须全部可兑(强约束)' },
|
||||
{ value: 'prefer_all', label: '优先全部可兑(可降级)' },
|
||||
]}
|
||||
/>
|
||||
<Button
|
||||
size="small"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => removeBundleRule(idx)}
|
||||
/>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Select
|
||||
mode="tags"
|
||||
size="small"
|
||||
style={{ width: '100%' }}
|
||||
placeholder="选择或输入联合商品 commodityId(如 20260120QYOOB_bag412)"
|
||||
value={rule.commodityIds}
|
||||
onChange={(values) =>
|
||||
updateBundleRule(idx, {
|
||||
commodityIds: values.map((v) => String(v).trim()).filter(Boolean),
|
||||
})
|
||||
}
|
||||
options={bundleCommodityOptions}
|
||||
/>
|
||||
</Card>
|
||||
))}
|
||||
</Space>
|
||||
)}
|
||||
</div>
|
||||
</Space>
|
||||
</Card>
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user