feat(fulfillment): 增加事务 Outbox 同步履约状态
- 用事务 Outbox 和签名 Webhook 替换直接状态回调 - 增加 Outbox 投递 worker、重试与低频对账兜底 - 缓存客户领取页绑定状态并补充签名与迁移测试
This commit is contained in:
@@ -52,6 +52,13 @@ function systemLabel(value: string) {
|
||||
return '未填写'
|
||||
}
|
||||
|
||||
function formatRemainingTime(totalSeconds: number) {
|
||||
const seconds = Math.max(0, Math.ceil(totalSeconds))
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
const rest = seconds % 60
|
||||
return `${String(minutes).padStart(2, '0')}:${String(rest).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
export default function DouyuFulfillmentPage() {
|
||||
const { message } = App.useApp()
|
||||
const { orderNo = '' } = useParams<{ orderNo: string }>()
|
||||
@@ -65,7 +72,7 @@ export default function DouyuFulfillmentPage() {
|
||||
const [system, setSystem] = useState<DouyuCustomerSystem>('android')
|
||||
const [qrImage, setQrImage] = useState('')
|
||||
const [bindingQrExpanded, setBindingQrExpanded] = useState(false)
|
||||
const [nowMs, setNowMs] = useState(0)
|
||||
const [nowMs, setNowMs] = useState(() => Date.now())
|
||||
const autoStartRef = useRef('')
|
||||
|
||||
const applyData = useCallback((next: DouyuCustomerFulfillment) => {
|
||||
@@ -177,6 +184,16 @@ export default function DouyuFulfillmentPage() {
|
||||
if (!expiresAt || Number.isNaN(expiresAt)) return 0
|
||||
return Math.max(0, Math.floor((expiresAt - nowMs) / 1000))
|
||||
}, [live?.qrExpiresAt, nowMs])
|
||||
const qrExpired = Boolean(live?.qrUrl && live.qrExpiresAt && expiresInSeconds <= 0)
|
||||
const qrTotalSeconds = useMemo(() => {
|
||||
const generatedAt = live?.qrGeneratedAt ? Date.parse(live.qrGeneratedAt) : 0
|
||||
const expiresAt = live?.qrExpiresAt ? Date.parse(live.qrExpiresAt) : 0
|
||||
if (!generatedAt || !expiresAt || Number.isNaN(generatedAt) || Number.isNaN(expiresAt)) {
|
||||
return 600
|
||||
}
|
||||
return Math.max(1, Math.floor((expiresAt - generatedAt) / 1000))
|
||||
}, [live?.qrExpiresAt, live?.qrGeneratedAt])
|
||||
const qrProgressPercent = Math.max(0, Math.min(100, (expiresInSeconds / qrTotalSeconds) * 100))
|
||||
const canRevealBindingQr = Boolean(
|
||||
live?.qrUrl && (live.bindReadyForConfirm || live.bindConfirmed),
|
||||
)
|
||||
@@ -188,7 +205,19 @@ export default function DouyuFulfillmentPage() {
|
||||
? '角色绑定已完成,待客服处理。'
|
||||
: live?.bindReadyForConfirm
|
||||
? '已识别游戏角色,请核对并确认绑定。'
|
||||
: live?.message || '请使用微信扫描下方二维码,按提示选择和平精英角色。二维码仅用于本次订单。'
|
||||
: qrExpired
|
||||
? '当前二维码已过期,请刷新二维码后重新扫码。'
|
||||
: live?.issueCode === 'binding_failed'
|
||||
? '暂未识别到绑定角色,请继续使用当前二维码完成扫码。'
|
||||
: !live?.accountReady
|
||||
? '系统正在自动准备账号和二维码,请稍候,无需重复操作。'
|
||||
: live?.qrUrl
|
||||
? '必须使用微信扫码。请选择与资料一致的和平精英角色,QQ 扫码或其他方式无效。'
|
||||
: live?.message || '正在准备绑定二维码,请稍候。'
|
||||
const bindingStageTitle =
|
||||
task?.status === 'qr_pending' && live?.qrUrl
|
||||
? '必须使用微信扫码绑定'
|
||||
: STATUS_LABELS[task?.status || ''] || '等待处理'
|
||||
|
||||
async function submitProfile() {
|
||||
if (!roleName.trim()) {
|
||||
@@ -212,6 +241,10 @@ export default function DouyuFulfillmentPage() {
|
||||
}
|
||||
|
||||
async function startBinding(forceRefresh = false) {
|
||||
if (forceRefresh && !qrExpired) {
|
||||
message.info('二维码有效期内无需刷新')
|
||||
return
|
||||
}
|
||||
setBindingLoading(true)
|
||||
try {
|
||||
const response = await startDouyuBinding(orderNo, forceRefresh)
|
||||
@@ -295,7 +328,10 @@ export default function DouyuFulfillmentPage() {
|
||||
}
|
||||
|
||||
return (
|
||||
<CustomerFrame title="斗鱼精英宝典领取">
|
||||
<CustomerFrame
|
||||
title="斗鱼精英宝典领取"
|
||||
compact={Boolean(live?.qrUrl && !live.bindReadyForConfirm && !live.bindConfirmed)}
|
||||
>
|
||||
<OrderCard data={data} />
|
||||
|
||||
{needsProfile ? (
|
||||
@@ -353,9 +389,10 @@ export default function DouyuFulfillmentPage() {
|
||||
) : (
|
||||
<section className="customer-binding-stage">
|
||||
<Alert
|
||||
type={live?.bindConfirmed ? 'success' : 'info'}
|
||||
className={live?.qrUrl ? 'customer-douyu-binding-alert is-wechat' : undefined}
|
||||
type={qrExpired ? 'warning' : live?.bindConfirmed ? 'success' : 'info'}
|
||||
showIcon
|
||||
message={STATUS_LABELS[task.status] || '等待处理'}
|
||||
message={bindingStageTitle}
|
||||
description={bindingDescription}
|
||||
/>
|
||||
|
||||
@@ -370,17 +407,33 @@ export default function DouyuFulfillmentPage() {
|
||||
) : null}
|
||||
|
||||
{!live?.qrUrl && task.status !== 'completed' ? (
|
||||
<div className="customer-binding-qr-card">
|
||||
<div className="customer-binding-qr-card customer-douyu-preparing-card">
|
||||
<h3>游戏角色绑定二维码</h3>
|
||||
<div className="customer-binding-qr-code">
|
||||
<div className="customer-auth-qr-placeholder">
|
||||
<Spin />
|
||||
<span>正在准备绑定二维码...</span>
|
||||
<div className="customer-douyu-qr-main">
|
||||
<span className="customer-douyu-qr-rail" aria-hidden="true">
|
||||
必须使用微信扫码
|
||||
</span>
|
||||
<div className="customer-binding-qr-code">
|
||||
<div className="customer-douyu-qr-preparing">
|
||||
<div className="customer-douyu-qr-skeleton" aria-hidden="true" />
|
||||
<div className="customer-douyu-qr-preparing-copy">
|
||||
<Spin />
|
||||
<strong>正在生成二维码</strong>
|
||||
<span>系统会自动刷新,请稍候</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span className="customer-douyu-qr-rail" aria-hidden="true">
|
||||
必须使用微信扫码
|
||||
</span>
|
||||
</div>
|
||||
<p className="customer-binding-qr-hint">
|
||||
二维码准备完成后,必须使用微信扫码并选择游戏角色。
|
||||
</p>
|
||||
<Button
|
||||
block
|
||||
size="large"
|
||||
className="customer-douyu-preparing-button"
|
||||
loading={bindingLoading}
|
||||
onClick={() => void startBinding(false)}
|
||||
>
|
||||
@@ -392,43 +445,55 @@ export default function DouyuFulfillmentPage() {
|
||||
{live?.qrUrl && showBindingQr ? (
|
||||
<div className="customer-binding-qr-card">
|
||||
<h3>游戏角色绑定二维码</h3>
|
||||
<div className="customer-binding-qr-code">
|
||||
{qrImage ? (
|
||||
<Image src={qrImage} alt="和平精英角色绑定二维码" width="100%" preview={false} />
|
||||
) : (
|
||||
<div className="customer-auth-qr-placeholder">
|
||||
<Spin />
|
||||
<span>正在生成二维码图片...</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="customer-douyu-qr-main">
|
||||
<span className="customer-douyu-qr-rail" aria-hidden="true">
|
||||
必须使用微信扫码
|
||||
</span>
|
||||
<div className="customer-binding-qr-code">
|
||||
{qrImage ? (
|
||||
<Image
|
||||
src={qrImage}
|
||||
alt="和平精英角色绑定二维码"
|
||||
width="100%"
|
||||
preview={false}
|
||||
/>
|
||||
) : (
|
||||
<div className="customer-auth-qr-placeholder">
|
||||
<Spin />
|
||||
<span>正在生成二维码图片...</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<span className="customer-douyu-qr-rail" aria-hidden="true">
|
||||
必须使用微信扫码
|
||||
</span>
|
||||
</div>
|
||||
<p className="customer-binding-qr-hint">
|
||||
请使用微信扫码,并选择与资料一致的和平精英角色。
|
||||
必须使用微信扫码,并选择与资料一致的和平精英角色。
|
||||
</p>
|
||||
{expiresInSeconds > 0 ? (
|
||||
{qrExpired ? (
|
||||
<div className="customer-binding-qr-countdown is-expired">二维码已过期</div>
|
||||
) : (
|
||||
<div className="customer-binding-qr-countdown">
|
||||
二维码剩余 {Math.ceil(expiresInSeconds / 60)} 分钟
|
||||
二维码有效期剩余 {formatRemainingTime(expiresInSeconds)}
|
||||
</div>
|
||||
) : null}
|
||||
<Progress percent={Math.min(100, (expiresInSeconds / 600) * 100)} showInfo={false} />
|
||||
<div className="customer-binding-qr-actions">
|
||||
)}
|
||||
<Progress percent={qrProgressPercent} showInfo={false} />
|
||||
<div className="customer-binding-qr-actions is-single">
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
loading={bindingLoading}
|
||||
disabled={!qrExpired}
|
||||
onClick={() => void startBinding(true)}
|
||||
>
|
||||
刷新二维码
|
||||
</Button>
|
||||
<Button
|
||||
icon={<QrcodeOutlined />}
|
||||
loading={bindingLoading}
|
||||
onClick={() =>
|
||||
void pollDouyuBinding(orderNo).then((response) => applyData(response.data))
|
||||
}
|
||||
>
|
||||
刷新状态
|
||||
</Button>
|
||||
</div>
|
||||
<p className="customer-douyu-qr-refresh-note">
|
||||
{qrExpired
|
||||
? '二维码已过期,请刷新后重新扫码'
|
||||
: '二维码有效期内无需刷新,过期后可重新生成'}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -506,9 +571,17 @@ function ChoiceSwitch<T extends string>(input: {
|
||||
)
|
||||
}
|
||||
|
||||
function CustomerFrame({ title, children }: { title: string; children: ReactNode }) {
|
||||
function CustomerFrame({
|
||||
title,
|
||||
compact = false,
|
||||
children,
|
||||
}: {
|
||||
title: string
|
||||
compact?: boolean
|
||||
children: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="customer-auth-page is-huya is-douyu">
|
||||
<div className={`customer-auth-page is-huya is-douyu${compact ? ' is-compact' : ''}`}>
|
||||
<div className="customer-auth-shell">
|
||||
<header className="customer-auth-hero">
|
||||
<div className="customer-auth-brand">
|
||||
|
||||
Reference in New Issue
Block a user