divisionRuleAutoTest.js
1.93 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
49
50
51
52
53
54
55
56
/** autoFlag=Y 且 testFlag 严格为 N(未通过分账测试) */
export function isDivisionRuleAutoTestPending(item) {
return item && item.autoFlag == "Y" && item.testFlag == "N"
}
export function buildDivisionRuleAutosByChannelId(divisionRuleAutos) {
const map = {}
;(divisionRuleAutos || []).forEach((item) => {
if (item && item.paymentChannelId != null) {
map[item.paymentChannelId] = {
paymentChannelId: item.paymentChannelId,
autoFlag: item.autoFlag,
testFlag: item.testFlag
}
}
})
return map
}
/**
* 立即测试按钮:须已有 divisionRuleId,当前开启自动分账,且服务端(详情/保存回包)判定待测。
* 本地切换 autoFlag 不触发显示,避免后端尚未生成测算 id。
*/
export function shouldShowDivisionTestButton(
currentChannel,
serverChannelById,
divisionRuleId
) {
if (divisionRuleId == null || divisionRuleId === "") return false
if (!currentChannel || currentChannel.autoFlag != "Y") return false
const serverChannel =
serverChannelById && serverChannelById[currentChannel.paymentChannelId]
return isDivisionRuleAutoTestPending(serverChannel)
}
export function hasPendingDivisionRuleAutoTest(divisionRuleAutos) {
return (divisionRuleAutos || []).some(isDivisionRuleAutoTestPending)
}
export function findPendingDivisionRuleAutoTestIndices(divisionRuleAutos) {
return (divisionRuleAutos || [])
.map((item, index) => (isDivisionRuleAutoTestPending(item) ? index : -1))
.filter((i) => i >= 0)
}
/** 从 divisionRuleTest.get 的 divisionRuleTests 中匹配当前渠道 */
export function findDivisionRuleTestByChannelId(divisionRuleTests, paymentChannelId) {
if (!Array.isArray(divisionRuleTests) || paymentChannelId == null) return null
return (
divisionRuleTests.find(
(t) =>
t?.paymentChannelId == paymentChannelId
|| t?.divisionRuleTestItem?.paymentChannelId == paymentChannelId
) || null
)
}