refactor(fulfillment): 移除飞飞/乐玩通道,仅保留 affiliate_dash

新单只路由 affiliate_dash(未命中走 manual_dispatch);历史飞飞/乐玩任务保留只读 stub,避免订单重同步失败。同步清理 cloudtentacles 调度、Admin 写路径与相关 env。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-14 17:29:47 +08:00
co-authored by Cursor
parent 0cbcb89dd8
commit b3aad0044c
155 changed files with 661 additions and 23351 deletions
@@ -1,100 +0,0 @@
import { CheckCircleOutlined, ExclamationCircleOutlined, LinkOutlined } from '@ant-design/icons'
import { Alert, Button, Card, Typography } from 'antd'
import type { ClaimKuaishouFeifeiFlowInfo, ClaimOrderInfo, ClaimProductInfo } from '@/types/claim'
import type { ClaimSnapshot } from './claim-snapshot'
import { InfoTile, UidEditRow } from './claim-shared'
export function FeifeiClaimPanel({
feifei,
expectedUid,
order,
product,
taskLastError,
onOpen,
uidInput,
submittingUid,
onUidChange,
onResubmitUid,
}: {
feifei: ClaimKuaishouFeifeiFlowInfo
expectedUid: string
order: ClaimOrderInfo | null
product: ClaimProductInfo | null
taskLastError?: string
onOpen: () => void
uidInput: string
submittingUid: boolean
onUidChange: (value: string) => void
onResubmitUid: () => void
}) {
const openReady = Boolean(feifei.h5UrlWithUid || feifei.h5.rechargeUrl || feifei.h5.entryUrl)
return (
<Card className="claim-content-card">
<div className="claim-feifei-main">
<span className="claim-feifei-label">kuaishou-feifei</span>
<Typography.Title level={2}>第 2 步:打开领取链接</Typography.Title>
<p>{feifei.rechargeStatusLabel || '待领取'}</p>
</div>
<UidEditRow
uidInput={uidInput}
submitting={submittingUid}
onChange={onUidChange}
onSubmit={onResubmitUid}
/>
<div className="claim-info-grid">
<InfoTile label="填写 UID" value={expectedUid || '-'} />
<InfoTile label="订单号" value={order?.platformOrderId || '-'} />
<InfoTile label="平台单号" value={feifei.orderNo || feifei.platformOrderNo || '-'} />
<InfoTile label="领取商品" value={product?.title || '-'} />
</div>
<Alert type="info" showIcon message="将携带你填写的 UID 打开领取页,请确认游戏内角色一致。" />
<Button
type="primary"
size="large"
icon={<LinkOutlined />}
disabled={!openReady || !expectedUid}
onClick={onOpen}
block
style={{ marginTop: 16 }}
>
打开领取链接
</Button>
{taskLastError ? (
<Alert type="warning" showIcon message={taskLastError} style={{ marginTop: 12 }} />
) : null}
</Card>
)
}
export function FeifeiResultStep({ snapshot }: { snapshot: ClaimSnapshot }) {
return (
<Card className="claim-content-card">
<div className="claim-result-header">
{snapshot.resultVariant === 'warning' ? (
<ExclamationCircleOutlined className="claim-large-icon claim-icon-warning" />
) : (
<CheckCircleOutlined
className={`claim-large-icon claim-icon-${snapshot.resultVariant}`}
/>
)}
<div>
<Typography.Title level={2}>{snapshot.resultTitle}</Typography.Title>
<p className="claim-muted">{snapshot.resultDescription}</p>
</div>
</div>
<div className="claim-info-grid">
<InfoTile label="填写 UID" value={snapshot.expectedUid || '-'} />
<InfoTile label="状态" value={snapshot.feifei?.rechargeStatusLabel || '-'} />
<InfoTile label="订单号" value={snapshot.order?.platformOrderId || '-'} />
<InfoTile label="领取商品" value={snapshot.product?.title || '-'} />
</div>
</Card>
)
}
@@ -1,343 +0,0 @@
import {
CheckCircleOutlined,
ExclamationCircleOutlined,
LinkOutlined,
LoadingOutlined,
ReloadOutlined,
SwapOutlined,
} from '@ant-design/icons'
import { Alert, Button, Card, Space, Tooltip, Typography } from 'antd'
import type { ClaimProductInfo } from '@/types/claim'
import { formatAdminDateTime } from '@/utils/admin-time'
import type { ClaimSnapshot } from './claim-snapshot'
import { ClaimProductItems, InfoRow, InfoTile, UidEditRow } from './claim-shared'
export function KuaishouCloudClaimSteps({
snapshot,
qrCodeDataUrl,
refreshingRole,
confirmingRole,
rebindingRole,
redeeming,
onOpenBindUrl,
onRefreshRole,
onRebindRole,
onConfirmRole,
onConfirmRedeem,
uidInput,
submittingUid,
onUidChange,
onResubmitUid,
}: {
snapshot: ClaimSnapshot
qrCodeDataUrl: string
refreshingRole: boolean
confirmingRole: boolean
rebindingRole: boolean
redeeming: boolean
onOpenBindUrl: (useCurrentPage?: boolean) => void
onRefreshRole: () => void
onRebindRole: () => void
onConfirmRole: () => void
onConfirmRedeem: () => void
uidInput: string
submittingUid: boolean
onUidChange: (value: string) => void
onResubmitUid: () => void
}) {
if (!snapshot.flow) {
return null
}
if (snapshot.currentStep === 3) {
return (
<ClaimConfirmStep
roleName={snapshot.roleName}
roleId={snapshot.roleId}
expectedUid={snapshot.expectedUid}
product={snapshot.product}
redeeming={redeeming}
rebindingRole={rebindingRole}
onConfirmRedeem={onConfirmRedeem}
onRebindRole={onRebindRole}
/>
)
}
return (
<ClaimBindingStep
snapshot={snapshot}
qrCodeDataUrl={qrCodeDataUrl}
refreshingRole={refreshingRole}
confirmingRole={confirmingRole}
rebindingRole={rebindingRole}
redeeming={redeeming}
onOpenBindUrl={onOpenBindUrl}
onRefreshRole={onRefreshRole}
onRebindRole={onRebindRole}
onConfirmRole={onConfirmRole}
onConfirmRedeem={onConfirmRedeem}
uidInput={uidInput}
submittingUid={submittingUid}
onUidChange={onUidChange}
onResubmitUid={onResubmitUid}
/>
)
}
function ClaimBindingStep({
snapshot,
qrCodeDataUrl,
refreshingRole,
confirmingRole,
rebindingRole,
redeeming,
onOpenBindUrl,
onRefreshRole,
onRebindRole,
onConfirmRole,
onConfirmRedeem,
uidInput,
submittingUid,
onUidChange,
onResubmitUid,
}: {
snapshot: ClaimSnapshot
qrCodeDataUrl: string
refreshingRole: boolean
confirmingRole: boolean
rebindingRole: boolean
redeeming: boolean
onOpenBindUrl: (useCurrentPage?: boolean) => void
onRefreshRole: () => void
onRebindRole: () => void
onConfirmRole: () => void
onConfirmRedeem: () => void
uidInput: string
submittingUid: boolean
onUidChange: (value: string) => void
onResubmitUid: () => void
}) {
const flow = snapshot.flow
if (!flow) {
return null
}
return (
<Card className="claim-content-card claim-binding-card">
<Typography.Title level={2}>第 2 步:绑定角色</Typography.Title>
<p className="claim-muted">
请使用与 UID <strong>{snapshot.expectedUid || '-'}</strong> 对应的角色扫码绑定。
</p>
<UidEditRow
uidInput={uidInput}
submitting={submittingUid}
onChange={onUidChange}
onSubmit={onResubmitUid}
/>
{snapshot.isBindingPrepared && qrCodeDataUrl ? (
<div className="claim-qr-block">
<div className="claim-qr-guide-panel">
<div className="claim-scan-label claim-scan-label-left">Q区用Q扫</div>
<img src={qrCodeDataUrl} alt="绑定二维码" className="claim-qr-code" />
<div className="claim-scan-label claim-scan-label-right">V区用V扫</div>
<p className="claim-save-hint">长按保存相册进行扫码绑定</p>
</div>
<Button icon={<LinkOutlined />} onClick={() => onOpenBindUrl(false)}>
打开绑定链接
</Button>
</div>
) : (
<Alert
type="info"
showIcon
icon={<LoadingOutlined spin />}
message="系统正在准备绑定资源,请稍后自动刷新。"
/>
)}
<div className={snapshot.isUidMatched ? 'claim-role-panel' : 'claim-role-panel pending'}>
<InfoRow label="填写 UID" value={snapshot.expectedUid || '-'} />
<InfoRow label="当前角色" value={snapshot.roleName || '待识别'} />
<InfoRow label="角色 ID" value={snapshot.roleId || '-'} />
<InfoRow label="匹配状态" value={snapshot.isUidMatched ? '已匹配' : '未匹配'} />
</div>
{!snapshot.isUidMatched && snapshot.roleId ? (
<Alert
type="warning"
showIcon
message={`当前绑定角色 ID(${snapshot.roleId})与填写 UID(${snapshot.expectedUid})不一致,请换绑正确角色。`}
/>
) : null}
<Space size={12} wrap className="claim-action-row">
<Button
size="large"
icon={<ReloadOutlined />}
loading={refreshingRole}
onClick={onRefreshRole}
>
刷新角色信息
</Button>
<Tooltip title="角色绑定错误时,请点击「换绑角色」,然后重新扫码绑定正确的角色">
<span className="claim-action-tooltip-wrap">
<Button
size="large"
icon={<SwapOutlined />}
loading={rebindingRole}
disabled={confirmingRole || redeeming}
onClick={onRebindRole}
>
换绑角色
</Button>
</span>
</Tooltip>
{snapshot.isUidMatched ? (
<Button
type="primary"
size="large"
danger
icon={<CheckCircleOutlined />}
loading={redeeming}
disabled={rebindingRole}
onClick={onConfirmRedeem}
>
UID 已匹配,确认兑换
</Button>
) : (
<Tooltip title={snapshot.confirmRoleDisabledReason || undefined}>
<span className="claim-action-tooltip-wrap">
<Button
type="primary"
size="large"
icon={<CheckCircleOutlined />}
loading={confirmingRole}
disabled={Boolean(snapshot.confirmRoleDisabledReason)}
onClick={onConfirmRole}
>
刷新后重试匹配
</Button>
</span>
</Tooltip>
)}
</Space>
<div className="claim-meta-footer">
<span>最近刷新:{formatAdminDateTime(flow.role.refreshedAt)}</span>
<span>链接有效期:{formatAdminDateTime(flow.binding.bindExpiresAt)}</span>
</div>
</Card>
)
}
function ClaimConfirmStep({
roleName,
roleId,
expectedUid,
product,
redeeming,
rebindingRole,
onConfirmRedeem,
onRebindRole,
}: {
roleName: string
roleId: string
expectedUid: string
product: ClaimProductInfo | null
redeeming: boolean
rebindingRole: boolean
onConfirmRedeem: () => void
onRebindRole: () => void
}) {
return (
<Card className="claim-content-card">
<Typography.Title level={2}>第 3 步:确认兑换信息</Typography.Title>
<p className="claim-muted">请再次确认 UID 和商品信息,确认无误后再继续兑换。</p>
<div className="claim-info-grid">
<InfoTile label="填写 UID" value={expectedUid || '-'} />
<InfoTile label="角色名称" value={roleName || '-'} />
<InfoTile label="角色 ID" value={roleId || '-'} />
<InfoTile label="领取商品" value={product?.title || '-'} />
<InfoTile label="商品数量" value={String(product?.quantity || 0)} />
</div>
<ClaimProductItems product={product} />
<Alert type="warning" showIcon message="兑换后不可取消,也不可退货。" />
<Space size={12} wrap className="claim-action-row">
<Tooltip title="角色绑定错误时,请点击「换绑角色」,然后重新扫码绑定正确的角色">
<span className="claim-action-tooltip-wrap">
<Button
size="large"
icon={<SwapOutlined />}
loading={rebindingRole}
disabled={redeeming}
onClick={onRebindRole}
>
换绑角色
</Button>
</span>
</Tooltip>
<Button
type="primary"
size="large"
icon={<CheckCircleOutlined />}
loading={redeeming}
disabled={rebindingRole}
onClick={onConfirmRedeem}
>
确认兑换
</Button>
</Space>
</Card>
)
}
export function ClaimResultStep({ snapshot }: { snapshot: ClaimSnapshot }) {
const flow = snapshot.flow
return (
<Card className="claim-content-card">
<div className="claim-result-header">
{snapshot.resultVariant === 'warning' ? (
<ExclamationCircleOutlined className="claim-large-icon claim-icon-warning" />
) : (
<CheckCircleOutlined
className={`claim-large-icon claim-icon-${snapshot.resultVariant}`}
/>
)}
<div>
<Typography.Title level={2}>{snapshot.resultTitle}</Typography.Title>
<p className="claim-muted">{snapshot.resultDescription}</p>
</div>
</div>
<div className="claim-info-grid">
<InfoTile label="填写 UID" value={snapshot.expectedUid || '-'} />
<InfoTile label="结果时间" value={formatAdminDateTime(flow?.dispatch.dispatchAt || null)} />
<InfoTile label="领取商品" value={snapshot.product?.title || '-'} />
<InfoTile label="角色名称" value={snapshot.roleName || '-'} />
<InfoTile label="角色 ID" value={snapshot.roleId || '-'} />
<InfoTile label="订单号" value={snapshot.order?.platformOrderId || '-'} />
</div>
<ClaimProductItems product={snapshot.product} />
<Alert
type={snapshot.resultVariant}
showIcon
message={
snapshot.resultVariant === 'warning'
? '当前兑换未完成,客服会根据后台任务记录继续处理。'
: '客户侧操作已经完成,后续履约结果请以后台任务界面为准。'
}
/>
</Card>
)
}
+14 -195
View File
@@ -4,21 +4,16 @@ import QRCode from 'qrcode'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useParams } from 'react-router'
import { isFeedbackDismissed, showConfirm, showError, showSuccess } from '@/lib/feedback'
import { showError, showSuccess } from '@/lib/feedback'
import {
confirmKuaishouCloudClaimRole,
fetchClaimDetail,
rebindKuaishouCloudClaimRole,
redeemKuaishouCloudClaim,
submitAffiliateDashClaim,
submitClaimUid,
} from '@/services/claim'
import type { ClaimDetailData } from '@/types/claim'
import { AffiliateDashClaimPanel, AffiliateDashResultStep } from './ClaimAffiliateDashSteps'
import { FeifeiClaimPanel, FeifeiResultStep } from './ClaimFeifeiSteps'
import { ClaimHeaderCard } from './ClaimHeaderCard'
import { ClaimResultStep, KuaishouCloudClaimSteps } from './ClaimLewanSteps'
import { ClaimUidStep } from './ClaimUidStep'
import { resolveNextPollDelayMs, resolveRolePollDelayMs } from './claim-poll'
import { createClaimSnapshot, type ClaimSnapshot } from './claim-snapshot'
@@ -30,10 +25,6 @@ export default function ClaimPage() {
const [loading, setLoading] = useState(true)
const [submittingUid, setSubmittingUid] = useState(false)
const [uidInput, setUidInput] = useState('')
const [refreshingRole, setRefreshingRole] = useState(false)
const [confirmingRole, setConfirmingRole] = useState(false)
const [rebindingRole, setRebindingRole] = useState(false)
const [redeeming, setRedeeming] = useState(false)
const [submittingSubmit, setSubmittingSubmit] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const [detail, setDetail] = useState<ClaimDetailData | null>(null)
@@ -42,10 +33,7 @@ export default function ClaimPage() {
const pollTimerRef = useRef(0)
const rolePollBaselineRef = useRef({ roleKey: '', at: 0 })
const snapshot = useMemo(
() => createClaimSnapshot(detail, { rebindingRole }),
[detail, rebindingRole],
)
const snapshot = useMemo(() => createClaimSnapshot(detail), [detail])
const stopPolling = useCallback(() => {
if (pollTimerRef.current) {
@@ -83,13 +71,7 @@ export default function ClaimPage() {
if (expectedUid) {
setUidInput(expectedUid)
}
await generateQRCode(
String(
nextDetail.kuaishouCloudFulfillment?.binding.bindUrl ||
nextDetail.affiliateDash?.bindUrl ||
'',
).trim(),
)
await generateQRCode(String(nextDetail.affiliateDash?.bindUrl || '').trim())
},
[generateQRCode],
)
@@ -145,6 +127,9 @@ export default function ClaimPage() {
useEffect(() => {
stopPolling()
if (snapshot.channelOffline) {
return undefined
}
const delay = resolveNextPollDelay(snapshot)
if (!delay) {
return undefined
@@ -161,7 +146,6 @@ export default function ClaimPage() {
}, [loadDetail, resolveNextPollDelay, snapshot, stopPolling])
async function handleSubmitUid() {
// 防并发:提交中忽略重复触发(按钮 loading + 回车 Enter 都可能连续触发)
if (submittingUid) {
return
}
@@ -219,139 +203,6 @@ export default function ClaimPage() {
}
}
async function refreshRole() {
setRefreshingRole(true)
try {
const nextDetail = await loadDetail({ silent: true })
const nextSnapshot = createClaimSnapshot(nextDetail, { rebindingRole })
if (nextSnapshot.isUidMatched) {
showSuccess('角色信息已匹配,可确认兑换')
} else if (nextSnapshot.roleId) {
showError(
`当前绑定角色 ID(${nextSnapshot.roleId})与填写 UID(${nextSnapshot.expectedUid || '-'})不一致`,
)
} else if (nextDetail) {
showError(
nextSnapshot.flow?.role.errorMessage ||
'暂时还没有识别到角色信息,请完成绑定后稍等片刻再试',
)
}
} finally {
setRefreshingRole(false)
}
}
async function confirmRole() {
setConfirmingRole(true)
try {
const response = await confirmKuaishouCloudClaimRole(token)
await applyDetail(response.data)
showSuccess('角色已确认,进入下一步')
} catch (error) {
showError(error instanceof Error ? error.message : '确认角色失败')
} finally {
setConfirmingRole(false)
}
}
async function confirmRedeem() {
try {
await showConfirm('兑换后不可取消,也不可退货。请确认 UID 与商品信息完全正确。', '确认兑换', {
okText: '确认兑换',
okButtonProps: { danger: true },
})
} catch (error) {
if (!isFeedbackDismissed(error)) {
showError('确认弹窗已关闭')
}
return
}
setRedeeming(true)
try {
const response = await redeemKuaishouCloudClaim(token)
await applyDetail(response.data)
showSuccess('兑换请求已提交')
} catch (error) {
showError(error instanceof Error ? error.message : '兑换失败')
} finally {
setRedeeming(false)
}
}
async function rebindRole() {
try {
await showConfirm(
'换绑后当前绑定链接会失效,系统会退还当前虚拟号并生成新的绑定二维码。请使用你填写的 UID 对应角色重新绑定。',
'确认换绑角色',
{
okText: '确认换绑',
okButtonProps: { danger: true },
},
)
} catch (error) {
if (!isFeedbackDismissed(error)) {
showError('确认弹窗已关闭')
}
return
}
setRebindingRole(true)
try {
const response = await rebindKuaishouCloudClaimRole(token)
await applyDetail(response.data)
showSuccess('新的绑定二维码已生成,请重新绑定角色')
} catch (error) {
showError(error instanceof Error ? error.message : '换绑角色失败')
} finally {
setRebindingRole(false)
}
}
function openBindUrl(useCurrentPage = false) {
const bindUrl = String(
snapshot.flow?.binding.bindUrl || snapshot.affiliateDash?.bindUrl || '',
).trim()
if (!bindUrl) {
showError('绑定链接还没准备好,请稍后刷新')
return
}
if (useCurrentPage) {
window.location.assign(bindUrl)
return
}
window.open(bindUrl, '_blank', 'noopener,noreferrer')
}
function openFeifeiUrl(useCurrentPage = false) {
const url = String(
snapshot.feifei?.h5UrlWithUid ||
snapshot.feifei?.h5.rechargeUrl ||
snapshot.feifei?.h5.entryUrl ||
'',
).trim()
if (!snapshot.hasExpectedUid) {
showError('请先填写游戏 UID')
return
}
if (!url) {
showError('领取链接还没准备好,请稍后刷新')
return
}
if (useCurrentPage) {
window.location.assign(url)
return
}
window.open(url, '_blank', 'noopener,noreferrer')
}
return (
<main className="claim-page">
<ClaimHeaderCard
@@ -376,6 +227,11 @@ export default function ClaimPage() {
<Card className="claim-content-card claim-state-card">
<Empty description="流程数据不完整,请联系客服处理" />
</Card>
) : snapshot.channelOffline ? (
<Card className="claim-content-card claim-state-card">
<ExclamationCircleOutlined className="claim-large-icon claim-icon-error" />
<p>{snapshot.channelOfflineMessage || '该履约渠道已下线,无法继续领取'}</p>
</Card>
) : snapshot.currentStep === 1 ? (
<ClaimUidStep
uidInput={uidInput}
@@ -383,14 +239,8 @@ export default function ClaimPage() {
onChange={setUidInput}
onSubmit={() => void handleSubmitUid()}
/>
) : snapshot.hasRedeemResult ? (
snapshot.isFeifeiFlow ? (
<FeifeiResultStep snapshot={snapshot} />
) : snapshot.isAffiliateDashFlow ? (
<AffiliateDashResultStep snapshot={snapshot} />
) : (
<ClaimResultStep snapshot={snapshot} />
)
) : snapshot.hasRedeemResult && snapshot.isAffiliateDashFlow ? (
<AffiliateDashResultStep snapshot={snapshot} />
) : snapshot.isAffiliateDashFlow && snapshot.affiliateDash ? (
<AffiliateDashClaimPanel
affiliateDash={snapshot.affiliateDash}
@@ -404,40 +254,9 @@ export default function ClaimPage() {
onResubmitUid={() => void handleSubmitUid()}
onSubmit={() => void handleSubmitAffiliateDash()}
/>
) : snapshot.isFeifeiFlow && snapshot.feifei ? (
<FeifeiClaimPanel
feifei={snapshot.feifei}
expectedUid={snapshot.expectedUid}
order={snapshot.order}
product={snapshot.product}
taskLastError={snapshot.task?.lastError}
onOpen={() => openFeifeiUrl(false)}
uidInput={uidInput}
submittingUid={submittingUid}
onUidChange={setUidInput}
onResubmitUid={() => void handleSubmitUid()}
/>
) : snapshot.flow ? (
<KuaishouCloudClaimSteps
snapshot={snapshot}
qrCodeDataUrl={qrCodeDataUrl}
refreshingRole={refreshingRole}
confirmingRole={confirmingRole}
rebindingRole={rebindingRole}
redeeming={redeeming}
onOpenBindUrl={openBindUrl}
onRefreshRole={refreshRole}
onRebindRole={rebindRole}
onConfirmRole={confirmRole}
onConfirmRedeem={confirmRedeem}
uidInput={uidInput}
submittingUid={submittingUid}
onUidChange={setUidInput}
onResubmitUid={() => void handleSubmitUid()}
/>
) : (
<Card className="claim-content-card claim-state-card">
<Empty description="流程数据不完整,请联系客服处理" />
<Empty description="当前领取流程不可用,请联系客服处理" />
</Card>
)}
</main>
+35 -136
View File
@@ -2,25 +2,14 @@ import {
TASK_STATUS,
hasKuaishouCloudRedeemResultStatus,
isKuaishouCloudCompletedStatus,
isKuaishouCloudRoleConfirmedStatus,
normalizeTaskStatus,
} from '@/domain/task-status'
import type {
ClaimAffiliateDashFlowInfo,
ClaimDetailData,
ClaimKuaishouCloudFlowInfo,
ClaimKuaishouFeifeiFlowInfo,
} from '@/types/claim'
import type { ClaimAffiliateDashFlowInfo, ClaimDetailData } from '@/types/claim'
export type ResultVariant = 'success' | 'warning' | 'info'
export type ClaimSnapshot = ReturnType<typeof createClaimSnapshot>
export function createClaimSnapshot(
detail: ClaimDetailData | null,
options: { rebindingRole?: boolean } = {},
) {
const flow = detail?.kuaishouCloudFulfillment || null
const feifei = detail?.kuaishouFeifei || null
export function createClaimSnapshot(detail: ClaimDetailData | null) {
const affiliateDash = detail?.affiliateDash || null
const order = detail?.order || null
const orderItem = detail?.orderItem || null
@@ -30,9 +19,8 @@ export function createClaimSnapshot(
const expectedUid = String(claimIdentity?.expectedUid || '').trim()
const hasExpectedUid = Boolean(expectedUid || claimIdentity?.ready)
const roleName = flow?.role.name || flow?.binding.roleName || ''
const roleId = flow?.role.rid || flow?.binding.roleId || ''
const isFeifeiFlow = detail?.flowType === 'kuaishou_feifei'
const channelOffline = Boolean(detail?.channelOffline)
const channelOfflineMessage = String(detail?.channelOfflineMessage || '').trim()
const isAffiliateDashFlow = detail?.flowType === 'affiliate_dash'
const affiliateDashExpectedUid = String(
expectedUid || affiliateDash?.expectedGameAccount || affiliateDash?.gameAccount || '',
@@ -55,78 +43,45 @@ export function createClaimSnapshot(
const isAffiliateDashReadyToSubmit = Boolean(
isAffiliateDashBound && isAffiliateDashUidMatched && !isAffiliateDashBindMismatch,
)
const isBindUrlExpired = isDateExpired(flow?.binding.bindExpiresAt || '')
const isBindingPrepared =
flow?.binding.prepareStatus === 'ready' &&
Boolean(String(flow?.binding.bindUrl || '').trim()) &&
!isBindUrlExpired
const isBindingPreparing = flow?.binding.prepareStatus === 'pending'
const isRoleReady = Boolean(roleName || roleId)
const isUidMatched =
Boolean(expectedUid) && Boolean(roleId) && normalizeUid(expectedUid) === normalizeUid(roleId)
const confirmRoleDisabledReason = resolveConfirmRoleDisabledReason({
isBindingPrepared,
isRoleReady,
isUidMatched,
expectedUid,
roleId,
rebindingRole: Boolean(options.rebindingRole),
})
const isRoleConfirmed = isKuaishouCloudRoleConfirmedStatus(task?.status)
const isDispatched = String(flow?.dispatch.status || '').trim() === 'success'
const normalizedStatus = normalizeTaskStatus(task?.status)
const isRedeemFailed =
normalizedStatus === TASK_STATUS.MANUAL_REVIEW ||
normalizedStatus === TASK_STATUS.FAILED ||
normalizedStatus === TASK_STATUS.CLOSED ||
String(flow?.dispatch.status || '').trim() === 'failed' ||
(isFeifeiFlow && [40, 50].includes(Number(feifei?.rechargeStatus || 0))) ||
(isAffiliateDashFlow &&
['ship_failed', 'cancelled'].includes(String(affiliateDash?.orderStatus || '').trim()))
const isCompleted =
isKuaishouCloudCompletedStatus(task?.status) ||
(isFeifeiFlow && Number(feifei?.rechargeStatus || 0) === 30)
const isCompleted = isKuaishouCloudCompletedStatus(task?.status)
const hasRedeemResult =
isDispatched ||
hasKuaishouCloudRedeemResultStatus(task?.status) ||
(isFeifeiFlow && [30, 40, 50, 60].includes(Number(feifei?.rechargeStatus || 0))) ||
(isAffiliateDashFlow &&
['delivered', 'ship_failed', 'cancelled'].includes(
String(affiliateDash?.orderStatus || '').trim(),
))
const currentStep = resolveCurrentStep({
channelOffline,
hasExpectedUid,
hasRedeemResult,
isRoleConfirmed,
isFeifeiFlow,
isAffiliateDashFlow,
isAffiliateDashReadyToSubmit,
})
const progressText = resolveProgressText({
feifei,
isFeifeiFlow,
isAffiliateDashFlow,
channelOffline,
channelOfflineMessage,
affiliateDash,
isAffiliateDashFlow,
hasExpectedUid,
expectedUid,
hasRedeemResult,
isRoleConfirmed,
isBindingPrepared,
isUidMatched,
isAffiliateDashReadyToSubmit,
isAffiliateDashBindMismatch,
})
const resultTitle = resolveResultTitle({
isRedeemFailed,
isCompleted,
isDispatched,
isAffiliateDashFlow,
affiliateDash,
})
const resultDescription = resolveResultDescription({
detail,
flow,
feifei,
affiliateDash,
task,
isRedeemFailed,
@@ -134,13 +89,13 @@ export function createClaimSnapshot(
})
const resultVariant: ResultVariant = isRedeemFailed
? 'warning'
: isCompleted || isDispatched
: isCompleted
? 'success'
: 'info'
return {
flow,
feifei,
flow: null as null,
feifei: null as null,
affiliateDash,
order,
orderItem,
@@ -149,9 +104,11 @@ export function createClaimSnapshot(
claimIdentity,
expectedUid,
hasExpectedUid,
roleName,
roleId,
isFeifeiFlow,
channelOffline,
channelOfflineMessage,
roleName: '',
roleId: '',
isFeifeiFlow: false,
isAffiliateDashFlow,
affiliateDashExpectedUid,
affiliateDashBoundAccount,
@@ -159,14 +116,14 @@ export function createClaimSnapshot(
isAffiliateDashUidMatched,
isAffiliateDashBindMismatch,
isAffiliateDashReadyToSubmit,
isBindUrlExpired,
isBindingPrepared,
isBindingPreparing,
isRoleReady,
isUidMatched,
confirmRoleDisabledReason,
isRoleConfirmed,
isDispatched,
isBindUrlExpired: false,
isBindingPrepared: false,
isBindingPreparing: false,
isRoleReady: false,
isUidMatched: false,
confirmRoleDisabledReason: '',
isRoleConfirmed: false,
isDispatched: false,
isRedeemFailed,
isCompleted,
hasRedeemResult,
@@ -184,37 +141,16 @@ export function normalizeUid(value: unknown) {
.replace(/\s+/g, '')
}
function resolveConfirmRoleDisabledReason(options: {
isBindingPrepared: boolean
isRoleReady: boolean
isUidMatched: boolean
expectedUid: string
roleId: string
rebindingRole: boolean
}) {
if (!options.isBindingPrepared) {
return '绑定二维码还在准备中,请稍后自动刷新'
}
if (!options.isRoleReady) {
return '请先扫码绑定自己的角色,并刷新角色信息'
}
if (!options.isUidMatched) {
return `当前绑定角色 ID(${options.roleId || '-'})与填写 UID(${options.expectedUid || '-'})不一致`
}
if (options.rebindingRole) {
return '正在换绑角色,请稍候'
}
return ''
}
function resolveCurrentStep(options: {
channelOffline: boolean
hasExpectedUid: boolean
hasRedeemResult: boolean
isRoleConfirmed: boolean
isFeifeiFlow: boolean
isAffiliateDashFlow: boolean
isAffiliateDashReadyToSubmit: boolean
}) {
if (options.channelOffline) {
return 1
}
if (!options.hasExpectedUid) {
return 1
}
@@ -227,26 +163,22 @@ function resolveCurrentStep(options: {
}
return 3
}
if (!options.isFeifeiFlow && options.isRoleConfirmed) {
return 3
}
return 2
}
function resolveProgressText(options: {
feifei: ClaimKuaishouFeifeiFlowInfo | null
channelOffline: boolean
channelOfflineMessage: string
affiliateDash: ClaimAffiliateDashFlowInfo | null
isFeifeiFlow: boolean
isAffiliateDashFlow: boolean
hasExpectedUid: boolean
expectedUid: string
hasRedeemResult: boolean
isRoleConfirmed: boolean
isBindingPrepared: boolean
isUidMatched: boolean
isAffiliateDashReadyToSubmit: boolean
isAffiliateDashBindMismatch: boolean
}) {
if (options.channelOffline) {
return options.channelOfflineMessage || '该履约渠道已下线'
}
if (!options.hasExpectedUid) {
return '请填写游戏编号'
}
@@ -267,28 +199,12 @@ function resolveProgressText(options: {
}
return '已绑定,请提交发货'
}
if (options.isFeifeiFlow) {
return options.feifei?.rechargeStatusLabel || `UID ${options.expectedUid},请打开领取链接`
}
if (options.hasRedeemResult) {
return '兑换结果已生成'
}
if (options.isRoleConfirmed) {
return '角色已确认,等待兑换'
}
if (!options.isBindingPrepared) {
return '绑定链接准备中,请稍候'
}
if (options.isUidMatched) {
return 'UID 已匹配,请确认兑换'
}
return '请完成扫码绑定并匹配 UID'
return '当前领取流程不可用'
}
function resolveResultTitle(options: {
isRedeemFailed: boolean
isCompleted: boolean
isDispatched: boolean
isAffiliateDashFlow: boolean
affiliateDash: ClaimAffiliateDashFlowInfo | null
}) {
@@ -298,9 +214,6 @@ function resolveResultTitle(options: {
if (options.isCompleted) {
return '兑换成功'
}
if (options.isDispatched) {
return '兑换请求已提交'
}
if (options.isAffiliateDashFlow && options.affiliateDash?.orderStatus === 'delivered') {
return '发货已完成'
}
@@ -309,8 +222,6 @@ function resolveResultTitle(options: {
function resolveResultDescription(options: {
detail: ClaimDetailData | null
flow: ClaimKuaishouCloudFlowInfo | null
feifei: ClaimKuaishouFeifeiFlowInfo | null
affiliateDash: ClaimAffiliateDashFlowInfo | null
task: ClaimDetailData['task'] | null
isRedeemFailed: boolean
@@ -319,8 +230,6 @@ function resolveResultDescription(options: {
if (options.isRedeemFailed) {
const message = String(
options.task?.lastError ||
options.flow?.dispatch.errorMessage ||
options.feifei?.rechargeResultMessage ||
options.affiliateDash?.failureReason ||
options.detail?.result?.resultMessage ||
'',
@@ -338,13 +247,3 @@ function resolveResultDescription(options: {
return '你的兑换请求已经提交。后续结果会由系统保存在后台任务界面。'
}
function isDateExpired(value: string | null) {
const normalized = String(value || '').trim()
if (!normalized) {
return false
}
const expiresTime = Date.parse(normalized)
return Number.isFinite(expiresTime) && expiresTime <= Date.now()
}