feat(douyu): 支持外部协作单撤销并推荐账号
This commit is contained in:
@@ -221,6 +221,34 @@ export interface DouyuCollabAccountLookup {
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface DouyuCollabAccountCandidate {
|
||||
account_id: number;
|
||||
account_username: string;
|
||||
account_uid: string;
|
||||
account_nickname: string;
|
||||
ck_status: string;
|
||||
role_status: string;
|
||||
bind_game_role: string;
|
||||
role_change_available_at: string | null;
|
||||
points: number | null;
|
||||
elite_opened: boolean | null;
|
||||
match_type: 'empty' | 'rebind' | string;
|
||||
match_type_label: string;
|
||||
ready: boolean;
|
||||
reasons: string[];
|
||||
}
|
||||
|
||||
export interface DouyuCollabAccountRecommendation {
|
||||
order_id: number;
|
||||
gift_name: string;
|
||||
commodity_id: string;
|
||||
required_points: number | null;
|
||||
include_rebindable: boolean;
|
||||
scanned: number;
|
||||
candidates: DouyuCollabAccountCandidate[];
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface DouyuCollabOrderCreate {
|
||||
order_no: string;
|
||||
shop?: string;
|
||||
@@ -383,6 +411,25 @@ export const douyuCollabApi = {
|
||||
expected_version,
|
||||
takeover_platform_lease,
|
||||
}),
|
||||
unlinkAccount: (id: number, reason: string, expected_version?: number) =>
|
||||
api.post<DouyuCollabOrder, DouyuCollabOrder>(
|
||||
`/douyu/external-orders/${id}/account/unlink`,
|
||||
{ reason, expected_version },
|
||||
),
|
||||
recommendAccount: (
|
||||
id: number,
|
||||
data: {
|
||||
include_rebindable?: boolean;
|
||||
limit?: number;
|
||||
gift_name?: string;
|
||||
commodity_id?: string;
|
||||
required_points?: number | null;
|
||||
} = {},
|
||||
) =>
|
||||
api.post<DouyuCollabAccountRecommendation, DouyuCollabAccountRecommendation>(
|
||||
`/douyu/external-orders/${id}/account/recommend`,
|
||||
data,
|
||||
),
|
||||
verifyOrder: (id: number) =>
|
||||
api.post<{ order: DouyuCollabOrder; probe: DouyuCollabAccountLookup }, { order: DouyuCollabOrder; probe: DouyuCollabAccountLookup }>(
|
||||
`/douyu/external-orders/${id}/verify`,
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
CheckCircleOutlined,
|
||||
CopyOutlined,
|
||||
DeleteOutlined,
|
||||
DisconnectOutlined,
|
||||
EditOutlined,
|
||||
FormOutlined,
|
||||
GiftOutlined,
|
||||
@@ -40,6 +41,7 @@ import {
|
||||
LinkOutlined,
|
||||
PlusOutlined,
|
||||
ReloadOutlined,
|
||||
RobotOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SearchOutlined,
|
||||
ShopOutlined,
|
||||
@@ -47,6 +49,7 @@ import {
|
||||
TagOutlined,
|
||||
UndoOutlined,
|
||||
UserOutlined,
|
||||
UserSwitchOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import HuyaCollabHomeImageUploader from '../components/HuyaCollabHomeImageUploader';
|
||||
import DouyuCollabGiftModal from '../components/DouyuCollabGiftModal';
|
||||
@@ -54,7 +57,9 @@ import DouyuCollabShopModal from '../components/DouyuCollabShopModal';
|
||||
import DouyuCollabShopPicker from '../components/DouyuCollabShopPicker';
|
||||
import { douyuCollabApi } from '../api/modules';
|
||||
import type {
|
||||
DouyuCollabAccountCandidate,
|
||||
DouyuCollabAccountLookup,
|
||||
DouyuCollabAccountRecommendation,
|
||||
DouyuCollabCkExportResult,
|
||||
DouyuCollabGift,
|
||||
DouyuCollabGoods,
|
||||
@@ -211,6 +216,8 @@ export default function DouyuCollabPage() {
|
||||
const canEdit = can('douyu:collab:edit');
|
||||
const canManage = can('douyu:collab:manage');
|
||||
const canExportCk = can('douyu:collab:ck_export');
|
||||
const canReplaceAccount =
|
||||
canEdit && (user?.role === 'super_admin' || user?.role === 'operation');
|
||||
// 单行复制是一键带走凭据,和虎牙台账保持一致:只给超级管理员(后端再校验)
|
||||
const isAdmin = user?.role === 'super_admin';
|
||||
|
||||
@@ -256,6 +263,16 @@ export default function DouyuCollabPage() {
|
||||
const lookupSeq = useRef(0);
|
||||
const [lookupLoading, setLookupLoading] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [unlinkOpen, setUnlinkOpen] = useState(false);
|
||||
const [unlinkReason, setUnlinkReason] = useState('');
|
||||
const [unlinkBusy, setUnlinkBusy] = useState(false);
|
||||
const [recommendOpen, setRecommendOpen] = useState(false);
|
||||
const [recommendLoading, setRecommendLoading] = useState(false);
|
||||
const [recommendResult, setRecommendResult] =
|
||||
useState<DouyuCollabAccountRecommendation | null>(null);
|
||||
const [recommendIncludeRebindable, setRecommendIncludeRebindable] = useState(true);
|
||||
const [applyingCandidateId, setApplyingCandidateId] = useState<number | null>(null);
|
||||
const recommendSeq = useRef(0);
|
||||
|
||||
const [detail, setDetail] = useState<DouyuCollabOrder | null>(null);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
@@ -375,7 +392,9 @@ export default function DouyuCollabPage() {
|
||||
batchStatusOpen ||
|
||||
statusTarget ||
|
||||
ckExportOpen ||
|
||||
usernameExportOpen,
|
||||
usernameExportOpen ||
|
||||
unlinkOpen ||
|
||||
recommendOpen,
|
||||
);
|
||||
// 暂停后连 WebSocket 也不建:既不自动重拉,也不做断线兜底轮询。
|
||||
const realtimeSyncEnabled = canView && !realtimePaused;
|
||||
@@ -534,6 +553,10 @@ export default function DouyuCollabPage() {
|
||||
lookupSeq.current += 1;
|
||||
setLookup(null);
|
||||
setLookupLoading(false);
|
||||
recommendSeq.current += 1;
|
||||
setUnlinkOpen(false);
|
||||
setRecommendOpen(false);
|
||||
setRecommendResult(null);
|
||||
setCreateOpen(true);
|
||||
};
|
||||
|
||||
@@ -553,6 +576,10 @@ export default function DouyuCollabPage() {
|
||||
lookupSeq.current += 1;
|
||||
setLookup(null);
|
||||
setLookupLoading(false);
|
||||
recommendSeq.current += 1;
|
||||
setUnlinkOpen(false);
|
||||
setRecommendOpen(false);
|
||||
setRecommendResult(null);
|
||||
setCreateOpen(true);
|
||||
};
|
||||
|
||||
@@ -718,6 +745,104 @@ export default function DouyuCollabPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const openUnlinkAccount = () => {
|
||||
if (!editing || !form.account_username.trim()) return;
|
||||
setUnlinkReason('');
|
||||
setUnlinkOpen(true);
|
||||
};
|
||||
|
||||
const submitUnlinkAccount = async () => {
|
||||
if (!editing) return;
|
||||
const reason = unlinkReason.trim();
|
||||
if (!reason) {
|
||||
message.warning('请填写解除账号的原因');
|
||||
return;
|
||||
}
|
||||
setUnlinkBusy(true);
|
||||
try {
|
||||
const updated = await douyuCollabApi.unlinkAccount(
|
||||
editing.id,
|
||||
reason,
|
||||
editing.version,
|
||||
);
|
||||
setEditing(updated);
|
||||
setForm((previous) => ({ ...previous, account_username: '' }));
|
||||
lookupSeq.current += 1;
|
||||
setLookup(null);
|
||||
setUnlinkOpen(false);
|
||||
message.success('已解除账号关联,订单已回到待补资料');
|
||||
refreshAll();
|
||||
} catch (error) {
|
||||
message.error(getErrorMessage(error));
|
||||
} finally {
|
||||
setUnlinkBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadRecommendations = async (includeRebindable: boolean) => {
|
||||
if (!editing) return;
|
||||
const seq = ++recommendSeq.current;
|
||||
setRecommendLoading(true);
|
||||
try {
|
||||
const result = await douyuCollabApi.recommendAccount(editing.id, {
|
||||
include_rebindable: includeRebindable,
|
||||
limit: 5,
|
||||
gift_name: form.gift_name || undefined,
|
||||
commodity_id: form.commodity_id || undefined,
|
||||
required_points: form.required_points,
|
||||
});
|
||||
if (seq !== recommendSeq.current) return;
|
||||
setRecommendResult(result);
|
||||
} catch (error) {
|
||||
if (seq === recommendSeq.current) message.error(getErrorMessage(error));
|
||||
} finally {
|
||||
if (seq === recommendSeq.current) setRecommendLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openRecommendAccount = () => {
|
||||
if (!editing) return;
|
||||
setRecommendIncludeRebindable(true);
|
||||
setRecommendResult(null);
|
||||
setRecommendOpen(true);
|
||||
void loadRecommendations(true);
|
||||
};
|
||||
|
||||
const applyRecommendedAccount = async (
|
||||
candidate: DouyuCollabAccountCandidate,
|
||||
) => {
|
||||
if (!editing) return;
|
||||
setApplyingCandidateId(candidate.account_id);
|
||||
try {
|
||||
const updated = await douyuCollabApi.setAccount(
|
||||
editing.id,
|
||||
candidate.account_username,
|
||||
editing.version,
|
||||
);
|
||||
setEditing(updated);
|
||||
setForm((previous) => ({
|
||||
...previous,
|
||||
account_username: updated.account_username,
|
||||
}));
|
||||
lookupSeq.current += 1;
|
||||
setLookup(null);
|
||||
recommendSeq.current += 1;
|
||||
setRecommendOpen(false);
|
||||
setRecommendResult(null);
|
||||
message.success(`已绑定推荐账号 ${updated.account_username}`);
|
||||
refreshAll();
|
||||
} catch (error) {
|
||||
if (errorCodeOf(error) === 'account_lease_conflict') {
|
||||
message.warning('推荐账号刚刚被其他任务占用,请重新推荐');
|
||||
void loadRecommendations(recommendIncludeRebindable);
|
||||
} else {
|
||||
message.error(getErrorMessage(error));
|
||||
}
|
||||
} finally {
|
||||
setApplyingCandidateId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const verifyOrder = async (order: DouyuCollabOrder) => {
|
||||
try {
|
||||
message.loading({ content: '正在校验账号…', key: 'dy-collab-verify' });
|
||||
@@ -1447,6 +1572,15 @@ export default function DouyuCollabPage() {
|
||||
menu={{
|
||||
items: [
|
||||
{ key: 'edit', label: '编辑资料', icon: <EditOutlined /> },
|
||||
...(canReplaceAccount && row.status !== 'done'
|
||||
? [
|
||||
{
|
||||
key: 'account_replace',
|
||||
label: '换绑账号…',
|
||||
icon: <UserSwitchOutlined />,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{ key: 'status', label: '改状态…', icon: <CheckCircleOutlined /> },
|
||||
...(row.status === 'done'
|
||||
? [{ key: 'archive', label: '归档…', icon: <InboxOutlined /> }]
|
||||
@@ -1457,6 +1591,7 @@ export default function DouyuCollabPage() {
|
||||
],
|
||||
onClick: ({ key }) => {
|
||||
if (key === 'edit') openEdit(row);
|
||||
if (key === 'account_replace') openEdit(row);
|
||||
if (key === 'status') openStatus(row);
|
||||
if (key === 'archive') void archiveOrders(row);
|
||||
if (key === 'delete') deleteOrder(row);
|
||||
@@ -1995,6 +2130,30 @@ export default function DouyuCollabPage() {
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{editing &&
|
||||
canReplaceAccount &&
|
||||
editing.status !== 'done' &&
|
||||
editing.status !== 'void' && (
|
||||
<Space style={{ marginTop: 8 }} wrap>
|
||||
<Button
|
||||
danger
|
||||
icon={<DisconnectOutlined />}
|
||||
disabled={!form.account_username.trim()}
|
||||
onClick={openUnlinkAccount}
|
||||
>
|
||||
解除账号
|
||||
</Button>
|
||||
<Button
|
||||
icon={<RobotOutlined />}
|
||||
onClick={openRecommendAccount}
|
||||
>
|
||||
推荐账号
|
||||
</Button>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
解除不会删除内部账号;推荐结果确认后才会占用账号
|
||||
</Text>
|
||||
</Space>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Row gutter={16}>
|
||||
@@ -2078,6 +2237,137 @@ export default function DouyuCollabPage() {
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title={`解除账号:${editing?.order_no || ''}`}
|
||||
open={unlinkOpen}
|
||||
onCancel={() => setUnlinkOpen(false)}
|
||||
onOk={() => void submitUnlinkAccount()}
|
||||
confirmLoading={unlinkBusy}
|
||||
okText="确认解除"
|
||||
okButtonProps={{ danger: true }}
|
||||
destroyOnHidden
|
||||
>
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<Alert
|
||||
type="warning"
|
||||
showIcon
|
||||
message={`将解除账号「${form.account_username || '-'}」与本单的关联`}
|
||||
description="不会删除内部账号。账号身份、角色、鱼翅和积分快照会清空,订单回到待补资料;如果账号仍被履约任务或其他活动协作单占用,不会释放其租约。"
|
||||
/>
|
||||
<Input.TextArea
|
||||
rows={3}
|
||||
maxLength={256}
|
||||
value={unlinkReason}
|
||||
placeholder="填写解除原因,例如:账号已被履约单 6919748168831020505 使用"
|
||||
onChange={(event) => setUnlinkReason(event.target.value)}
|
||||
/>
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title={`推荐账号:${editing?.order_no || ''}`}
|
||||
open={recommendOpen}
|
||||
onCancel={() => setRecommendOpen(false)}
|
||||
width={760}
|
||||
footer={[
|
||||
<Button key="close" onClick={() => setRecommendOpen(false)}>
|
||||
关闭
|
||||
</Button>,
|
||||
<Button
|
||||
key="reload"
|
||||
icon={<ReloadOutlined />}
|
||||
loading={recommendLoading}
|
||||
onClick={() => void loadRecommendations(recommendIncludeRebindable)}
|
||||
>
|
||||
重新推荐
|
||||
</Button>,
|
||||
]}
|
||||
destroyOnHidden
|
||||
>
|
||||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||||
<Alert
|
||||
type="info"
|
||||
showIcon
|
||||
message="推荐结果不会预占账号"
|
||||
description="选择后会再次实时校验 CK、租约、活动协作单和换绑冷却。未绑定账号优先;关闭下方开关后只搜索未绑定账号。"
|
||||
/>
|
||||
<Space>
|
||||
<Switch
|
||||
checked={recommendIncludeRebindable}
|
||||
onChange={(checked) => {
|
||||
setRecommendIncludeRebindable(checked);
|
||||
void loadRecommendations(checked);
|
||||
}}
|
||||
/>
|
||||
<Text>包含已过换绑冷却的账号</Text>
|
||||
</Space>
|
||||
<Text type="secondary">
|
||||
礼包:{recommendResult?.gift_name || form.gift_name || '-'} · 需要{' '}
|
||||
{recommendResult?.required_points ?? form.required_points ?? '-'} 积分 · 已扫描{' '}
|
||||
{recommendResult?.scanned ?? 0} 个候选
|
||||
</Text>
|
||||
{recommendResult?.message && <Text>{recommendResult.message}</Text>}
|
||||
{recommendLoading ? (
|
||||
<Text type="secondary">正在实时检查账号 CK、角色和换绑状态…</Text>
|
||||
) : recommendResult?.candidates.length ? (
|
||||
recommendResult.candidates.map((candidate) => (
|
||||
<Card key={candidate.account_id} size="small">
|
||||
<Space direction="vertical" size={8} style={{ width: '100%' }}>
|
||||
<Space wrap>
|
||||
<Text strong>
|
||||
{candidate.account_nickname || candidate.account_username}
|
||||
</Text>
|
||||
<Tag color={candidate.match_type === 'empty' ? 'green' : 'blue'}>
|
||||
{candidate.match_type_label}
|
||||
</Tag>
|
||||
{candidate.ready ? (
|
||||
<Tag color="success">资格齐全</Tag>
|
||||
) : (
|
||||
<Tag color="orange">需后续处理</Tag>
|
||||
)}
|
||||
<Text type="secondary">账号 {candidate.account_username}</Text>
|
||||
{candidate.account_uid && (
|
||||
<Text type="secondary">UID {candidate.account_uid}</Text>
|
||||
)}
|
||||
</Space>
|
||||
<Space wrap>
|
||||
<Text>积分 {candidate.points ?? '-'}</Text>
|
||||
<Text>
|
||||
精英宝典{candidate.elite_opened === true ? '已开通' : '未开通'}
|
||||
</Text>
|
||||
{candidate.bind_game_role && (
|
||||
<Text>当前角色 {candidate.bind_game_role}</Text>
|
||||
)}
|
||||
</Space>
|
||||
<Space wrap>
|
||||
{candidate.reasons.map((reason) => (
|
||||
<Tag key={reason}>{reason}</Tag>
|
||||
))}
|
||||
</Space>
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
loading={applyingCandidateId === candidate.account_id}
|
||||
disabled={
|
||||
applyingCandidateId !== null &&
|
||||
applyingCandidateId !== candidate.account_id
|
||||
}
|
||||
onClick={() => void applyRecommendedAccount(candidate)}
|
||||
>
|
||||
使用此账号
|
||||
</Button>
|
||||
</Space>
|
||||
</Card>
|
||||
))
|
||||
) : (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description="当前没有找到可绑定账号"
|
||||
/>
|
||||
)}
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
title={
|
||||
batchStatusOpen
|
||||
|
||||
Reference in New Issue
Block a user