status-rules.ts
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { WithdrawRow } from '@/api';
import { TRANSFER_STATUS, statusMeta } from '@/features/shared/dictionaries';
/**
* 提现批量动作的状态规则:一个动作能不能做,看的是记录的 status。
*
* 后端只给「这批行不行」(`...out.pay.amount` 回 `canApprove` / `canPay`),不点名是哪几条;
* 实测(2026-11-10)那个字段是判定值、与入参里同名字段无关(不带 / false / true 三种入参回同一个值),
* 所以点名必须用列表已有的 status 在这里算。
*/
/** 批量动作:审核、付款、驳回(生成批次的规则还没定,先不混进来)。 */
export type BatchAction = 'approve' | 'pay' | 'reject';
/** 待审核才可批量审核。 */
export const APPROVABLE = new Set(['0']);
/** 已审核、受理失败才可付款。 */
export const PAYABLE = new Set(['1', '6']);
/** 老系统只有这几个状态的提现单可以驳回(0 待审核、1 已审核、6 受理失败、8 签约中)。 */
export const REJECTABLE = new Set(['0', '1', '6', '8']);
/**
* 提示里要说的那句状态名,和上面的集合放在一起,避免文案与规则各说一套
* (老系统三句文案是三个说法:待审核 / 已审核或受理失败 / 能够驳回)。
*/
export const STATUS_REQUIREMENT: Record<BatchAction, string> = {
approve: '待审核',
pay: '已审核或受理失败',
reject: '待审核、已审核、受理失败或签约中',
};
const ALLOWED: Record<BatchAction, Set<string>> = {
approve: APPROVABLE,
pay: PAYABLE,
reject: REJECTABLE,
};
/**
* 点名状态不对的勾选行:`214(驳回)、213(驳回)`。
* 超过 8 条只列前 8 条并给出总数,避免提示长到读不完。
*/
export function wrongStatusRows(action: BatchAction, rows: WithdrawRow[]): string {
const allowed = ALLOWED[action];
const bad = rows.filter((row) => !allowed.has(String(row.status ?? '')));
const label = (row: WithdrawRow) =>
`${row.id ?? '—'}(${statusMeta(TRANSFER_STATUS, row.status)?.label ?? `状态 ${row.status}`})`;
const shown = bad.slice(0, 8).map(label).join('、');
return bad.length > 8 ? `${shown} 等 ${bad.length} 条` : shown;
}