refactor: 移除 Rock 发货处理中状态,新增异常派生筛选标记

- 新增迁移 028:历史 redeeming 回退为 bound,重建 pending 部分索引
- pending 语义改为 bound + redeem_requested_at 标记,不再写状态与状态日志
- 新增 anomaly 虚拟筛选项:基于状态日志派生异常标记,不改状态、不落库
- 状态列追加「⚠️ 异常」标签,统计新增 anomaly_stock
- 清理前后端 redeeming 相关分支与文案
This commit is contained in:
2026-11-14 15:40:19 +08:00
parent f0dea6a583
commit a9473990be
25 changed files with 620 additions and 219 deletions
+8 -3
View File
@@ -597,7 +597,6 @@ export interface RockStats {
available_stock: number;
using_stock: number;
bound_stock: number;
redeeming_stock?: number;
redeemed_stock: number;
mismatch_stock: number;
abnormal_stock: number;
@@ -605,7 +604,7 @@ export interface RockStats {
using_overdue_stock?: number;
using_danger_stock?: number;
bound_overdue_stock?: number;
redeeming_timeout_stock?: number;
anomaly_stock?: number;
auto_refresh_mismatch_enabled?: boolean;
upstream_points: number;
auto_delivery_enabled: boolean;
@@ -674,7 +673,7 @@ export interface RockTokenItem {
using_at?: string;
bound_at?: string;
redeemed_at?: string;
// 上游异步兑奖(pending)跟踪字段
// 上游异步兑奖(发货确认中)标记字段,不是状态
redeem_requested_at?: string;
redeem_checked_at?: string;
redeem_attempts?: number;
@@ -682,6 +681,12 @@ export interface RockTokenItem {
redeem_last_message?: string;
redeem_last_error?: string;
redeem_timeout_warned_at?: string;
// 异常标记(派生字段,来自历史流转,不改变主状态)
has_anomaly?: boolean;
anomaly_type?: string;
anomaly_reason?: string;
anomaly_at?: string;
anomaly_count?: number;
created_at: string;
updated_at?: string;
deleted_at?: string | null;
@@ -64,16 +64,6 @@ export function RockTokenFilterBar({
<Radio.Button value="available">可用</Radio.Button>
<Radio.Button value="using">使用中</Radio.Button>
<Radio.Button value="bound">已绑定</Radio.Button>
<Radio.Button value="redeeming">
<Badge
count={(stats?.redeeming_stock ?? 0) + (stats?.redeeming_timeout_stock ?? 0)}
offset={[6, -2]}
size="small"
style={{ backgroundColor: (stats?.redeeming_timeout_stock ?? 0) > 0 ? '#ef4444' : '#6366f1' }}
>
<span>发货处理中</span>
</Badge>
</Radio.Button>
<Radio.Button value="redeemed">已发货</Radio.Button>
<Radio.Button value="mismatch">
<Badge count={stats?.mismatch_stock ?? 0} offset={[6, -2]} size="small">
@@ -110,6 +100,17 @@ export function RockTokenFilterBar({
<span>绑定超时</span>
</Badge>
</Radio.Button>
{/* 异常放在最后:派生筛选,只看历史流转,不改变主状态 */}
<Radio.Button value="anomaly">
<Badge
count={stats?.anomaly_stock ?? 0}
offset={[6, -2]}
size="small"
style={{ backgroundColor: '#b91c1c' }}
>
<span>异常</span>
</Badge>
</Radio.Button>
</Radio.Group>
</div>
<Space size={10} style={{ flex: '0 0 auto', flexWrap: 'wrap' }}>
@@ -99,8 +99,6 @@ export function RockTokenTable({
message.warning(res.message || '上游绑定状态需要人工核对')
} else if (res.status === 'redeemed') {
message.success(res.message || '上游已发货,本地状态已同步为已交付')
} else if (res.status === 'redeeming') {
message.info(res.message || '上游仍未确认发货,保持发货处理中')
} else if (res.bound) {
const role = res.role_name || res.role_id || '-'
message.success(res.message || `刷新成功:上游已绑定「${role}」`)
@@ -28,7 +28,6 @@ const STATUS_LABELS: Record<string, string> = {
available: '可用库存',
using: '使用中',
bound: '已绑定',
redeeming: '发货处理中',
redeemed: '已发货',
mismatch: '绑定错误',
abnormal: '已上报失效',
@@ -36,7 +35,7 @@ const STATUS_LABELS: Record<string, string> = {
bound_overdue: '绑定超时',
}
const DANGEROUS_STATUSES = new Set(['using', 'bound', 'redeeming', 'mismatch'])
const DANGEROUS_STATUSES = new Set(['using', 'bound', 'mismatch'])
function statusLabel(status: string) {
return STATUS_LABELS[status] || status || '-'
@@ -50,8 +49,6 @@ function statusTagColor(status: string) {
return 'processing'
case 'bound':
return 'cyan'
case 'redeeming':
return 'geekblue'
case 'redeemed':
return 'purple'
case 'mismatch':
@@ -225,7 +222,7 @@ export function TokenDeleteModal({
<Text type="secondary"> · 其中可用库存 {available} 条</Text>
)}
{dangerous > 0 && (
<Text type="danger"> · 使用中/已绑定/发货处理中/绑定错误 {dangerous} 条</Text>
<Text type="danger"> · 使用中/已绑定/绑定错误 {dangerous} 条</Text>
)}
</div>
<div>
@@ -250,7 +247,7 @@ export function TokenDeleteModal({
showIcon
icon={<ExclamationCircleOutlined />}
message={`包含 ${dangerous} 条进行中的 Token`}
description="使用中/已绑定/发货处理中/绑定错误的 Token 与订单履约相关。删除后它们会从列表和统计中消失,可能导致客服排查困难;请确认这些订单已无需处理,或已经人工接管。"
description="使用中/已绑定/绑定错误的 Token 与订单履约相关。删除后它们会从列表和统计中消失,可能导致客服排查困难;请确认这些订单已无需处理,或已经人工接管。"
/>
)}
@@ -31,7 +31,6 @@ const STATUS_LABELS: Record<string, string> = {
available: '可用库存',
using: '使用中',
bound: '已绑定',
redeeming: '发货处理中',
redeemed: '已发货',
mismatch: '绑定错误',
abnormal: '已上报失效',
@@ -44,7 +43,6 @@ const STATUS_OPTIONS = [
{ value: 'available', label: '可用库存' },
{ value: 'using', label: '使用中' },
{ value: 'bound', label: '已绑定' },
{ value: 'redeeming', label: '发货处理中' },
{ value: 'redeemed', label: '已发货' },
{ value: 'mismatch', label: '绑定错误' },
{ value: 'abnormal', label: '已上报失效' },
@@ -52,7 +50,7 @@ const STATUS_OPTIONS = [
{ value: 'bound_overdue', label: '绑定超时' },
]
const DANGEROUS_STATUSES = new Set(['using', 'bound', 'redeeming', 'mismatch'])
const DANGEROUS_STATUSES = new Set(['using', 'bound', 'mismatch'])
const SKIP_REASONS: Record<string, string> = {
not_deleted: '已不在回收站',
@@ -72,8 +70,6 @@ function statusTagColor(status: string) {
return 'processing'
case 'bound':
return 'cyan'
case 'redeeming':
return 'geekblue'
case 'redeemed':
return 'purple'
case 'mismatch':
@@ -435,12 +435,11 @@ export function TokenStatusLogDrawer({
当前状态:{rockTokenStatusLabel(token.status)}
{token.assigned_order_no ? ` · 工单 ${token.assigned_order_no}` : ''}
</Text>
{token.status === 'redeeming' && (
<Text type="secondary" style={{ fontSize: 12 }}>
{token.redeem_last_message || '上游官方处理中,系统会自动确认发货结果'}
{token.redeem_requested_at
? ` · 提交于 ${formatDateTime(token.redeem_requested_at)}`
: ''}
{token.has_anomaly && (
<Text style={{ fontSize: 12, color: '#b91c1c' }}>
⚠️ 历史异常:{token.anomaly_type || '异常'}
{token.anomaly_count ? ` · 共 ${token.anomaly_count} 次` : ''}
{token.anomaly_at ? ` · 最近 ${formatDateTime(token.anomaly_at)}` : ''}
</Text>
)}
</Space>
+131 -105
View File
@@ -40,6 +40,45 @@ function serverElapsedDays(serverDays: number | undefined, at?: string): number
return elapsedDaysSince(at)
}
// 异常标记:独立小标签,不改变主状态。hover 展示最近一次异常原因与时间。
function AnomalyBadge({ record }: { record: RockTokenItem }) {
const reason = (record.anomaly_reason || '').trim()
const type = (record.anomaly_type || '').trim()
return (
<Tooltip
title={
<div style={{ maxWidth: 320, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}>
<div style={{ fontWeight: 600, marginBottom: 4 }}>
{type || '历史异常'}
{record.anomaly_count ? ` · 共 ${record.anomaly_count} 次` : ''}
</div>
{reason || '历史流转中出现过异常'}
{record.anomaly_at ? (
<div style={{ marginTop: 4, opacity: 0.8 }}>
最近:{formatDateTime(record.anomaly_at)}
</div>
) : null}
</div>
}
>
<Tag
style={{
margin: 0,
fontWeight: 600,
fontSize: 11,
padding: '0 6px',
color: '#b91c1c',
background: '#fff1f0',
border: '1px solid #ffa39e',
cursor: 'default',
}}
>
⚠️ 异常
</Tag>
</Tooltip>
)
}
// Token 主信息:编号/兑换码 与 包ID/提取码 上下两行展示,
// 两个复制按钮各自只复制兑换码 / 提取码,编号与包 ID 不参与复制。
export function TokenInfoCell({ record }: { record: RockTokenItem }) {
@@ -153,114 +192,106 @@ export function buildTokenColumns({
dataIndex: 'status',
width: 165,
render: (status, record) => {
switch (status) {
case 'available':
return (
<Tag color="success" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 可用库存
</Tag>
)
case 'using': {
const days = serverElapsedDays(record.using_days, record.using_at)
const usingOverdue = record.using_overdue ?? (days !== null && days >= usingWarnDays)
const usingDanger = record.using_danger ?? (days !== null && days >= usingDangerDays)
const displayDays = days === null ? 0 : floorDays(days)
if (usingDanger) {
const statusTag = (() => {
switch (status) {
case 'available':
return (
<Tag color="success" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 可用库存
</Tag>
)
case 'using': {
const days = serverElapsedDays(record.using_days, record.using_at)
const usingOverdue = record.using_overdue ?? (days !== null && days >= usingWarnDays)
const usingDanger = record.using_danger ?? (days !== null && days >= usingDangerDays)
const displayDays = days === null ? 0 : floorDays(days)
if (usingDanger) {
return (
<Tag
color="error"
style={{ fontWeight: 600, padding: '2px 8px', border: '1px solid #ff4d4f' }}
>
⚠️ 使用中超时 {displayDays.toFixed(1)} 天
</Tag>
)
}
if (usingOverdue) {
return (
<Tag color="warning" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 扫码使用中 · {displayDays.toFixed(1)} 天
</Tag>
)
}
return (
<Tag color="processing" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 扫码使用中
</Tag>
)
}
case 'bound': {
const boundDays = serverElapsedDays(record.bound_days, record.bound_at)
const boundOverdue =
record.bound_overdue ?? (boundDays !== null && boundDays >= boundWarnDays)
if (boundOverdue) {
const displayDays = boundDays === null ? 0 : floorDays(boundDays)
return (
<Tag
color="volcano"
style={{ fontWeight: 600, padding: '2px 8px', border: '1px solid #ff7a45' }}
>
⏱ 绑定超时 {displayDays.toFixed(1)} 天
</Tag>
)
}
return (
<Tag color="cyan" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 已授权绑定
</Tag>
)
}
case 'redeemed':
return (
<Tag color="purple" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 已交付发货
</Tag>
)
case 'mismatch':
return (
<Tag
color="error"
style={{ fontWeight: 600, padding: '2px 8px', border: '1px solid #ff4d4f' }}
>
⚠️ 使用中超时 {displayDays.toFixed(1)} 天
⚠️ 绑定错误 (阻断)
</Tag>
)
}
if (usingOverdue) {
return (
<Tag color="warning" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 扫码使用中 · {displayDays.toFixed(1)} 天
</Tag>
)
}
return (
<Tag color="processing" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 扫码使用中
</Tag>
)
}
case 'bound': {
const boundDays = serverElapsedDays(record.bound_days, record.bound_at)
const boundOverdue = record.bound_overdue ?? (boundDays !== null && boundDays >= boundWarnDays)
if (boundOverdue) {
const displayDays = boundDays === null ? 0 : floorDays(boundDays)
case 'abnormal':
return (
<Tag
color="volcano"
style={{ fontWeight: 600, padding: '2px 8px', border: '1px solid #ff7a45' }}
color="default"
style={{
fontWeight: 600,
padding: '2px 8px',
color: '#b91c1c',
background: '#fef2f2',
border: '1px solid #fca5a5',
}}
>
⏱ 绑定超时 {displayDays.toFixed(1)} 天
🚫 已上报失效
</Tag>
)
}
return (
<Tag color="cyan" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 已授权绑定
</Tag>
)
default:
return <Tag>{status}</Tag>
}
case 'redeeming': {
// pending 起点以 redeem_requested_at 为准,按分钟展示等待时长。
const pendingDays = elapsedDaysSince(record.redeem_requested_at)
const pendingMinutes = pendingDays === null ? null : Math.floor(pendingDays * 24 * 60)
const timeoutWarned = Boolean(record.redeem_timeout_warned_at)
return (
<Tooltip
title={
record.redeem_last_message ||
'上游官方处理中,系统会自动轮询确认发货结果'
}
>
<Tag
color={timeoutWarned ? 'volcano' : 'geekblue'}
style={{ fontWeight: 600, padding: '2px 8px' }}
>
{timeoutWarned
? `⏱ 发货确认超时${pendingMinutes !== null ? ` ${pendingMinutes} 分钟` : ''}`
: '⏳ 发货处理中'}
</Tag>
</Tooltip>
)
}
case 'redeemed':
return (
<Tag color="purple" style={{ fontWeight: 600, padding: '2px 8px' }}>
● 已交付发货
</Tag>
)
case 'mismatch':
return (
<Tag color="error" style={{ fontWeight: 600, padding: '2px 8px', border: '1px solid #ff4d4f' }}>
⚠️ 绑定错误 (阻断)
</Tag>
)
case 'abnormal':
return (
<Tag
color="default"
style={{
fontWeight: 600,
padding: '2px 8px',
color: '#b91c1c',
background: '#fef2f2',
border: '1px solid #fca5a5',
}}
>
🚫 已上报失效
</Tag>
)
default:
return <Tag>{status}</Tag>
}
})()
// 异常是独立标记:不替换主状态,只在后面追加一个小标签。
if (!record.has_anomaly) return statusTag
return (
<Space direction="vertical" size={4}>
{statusTag}
<AnomalyBadge record={record} />
</Space>
)
},
},
{
@@ -293,16 +324,11 @@ export function buildTokenColumns({
{usingDays !== null ? `(${floorDays(usingDays).toFixed(1)} 天)` : ''}
</div>
)}
{record.status === 'redeeming' && (
<div
style={{
fontSize: 11,
color: record.redeem_timeout_warned_at ? '#dc2626' : '#4338ca',
}}
>
<span>⏳ 提交发货: </span>
{formatDateTime(record.redeem_requested_at)}
{record.redeem_attempts ? `(已查询 ${record.redeem_attempts} 次)` : ''}
{record.anomaly_at && (
<div style={{ fontSize: 11, color: '#b91c1c' }}>
<span>⚠️ 异常: </span>
{formatDateTime(record.anomaly_at)}
{record.anomaly_type ? `(${record.anomaly_type})` : ''}
</div>
)}
{record.mismatch_at && (
-1
View File
@@ -10,7 +10,6 @@ export const ROCK_TOKEN_STATUS_LABELS: Record<string, string> = {
available: '可用库存',
using: '扫码使用中',
bound: '已授权绑定',
redeeming: '发货处理中',
redeemed: '已交付发货',
mismatch: '绑定错误',
abnormal: '已上报失效',