abnormalFlow.mock.js
7.16 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import { mapAbnormalFlowDeclarationApproveResponse } from "./adapters/abnormalFlowDeclaration/mapAbnormalFlowDeclarationApproveResponse";
import { mapAbnormalFlowDeclarationDetailResponse } from "./adapters/abnormalFlowDeclaration/mapAbnormalFlowDeclarationDetailResponse";
function delay(result, ms = 300) {
return new Promise((resolve) => {
setTimeout(() => resolve(result), ms);
});
}
function delayReject(error, ms = 300) {
return new Promise((_, reject) => {
setTimeout(() => reject(error), ms);
});
}
function paginate(list, params = {}) {
const { currentPage = 1, pageSize = 10 } = params;
const start = (currentPage - 1) * pageSize;
return {
list: list.slice(start, start + pageSize),
total: list.length,
pageNum: currentPage,
pageSize,
};
}
function buildTradeFields(item) {
return {
tradeNo: item.tradeNo,
totalPrice: item.totalPrice,
notRefundedTotalPrice: item.notRefundedTotalPrice,
payDate: item.payDate,
payChannel: item.payChannel,
payType: item.payType,
posTrmNo: item.posTrmNo,
merchantName: item.merchantName,
yqMerchantName: item.yqMerchantName,
distributionStatus: item.distributionStatus,
refundStatus: item.refundStatus,
};
}
function buildListItem(item) {
const row = {
...buildTradeFields(item),
declarationId: item.declarationId,
declarationApprovalStatus: item.declarationApprovalStatus,
};
return row;
}
function createMockItem(config) {
return {
merchantId: config.merchantId || "44211349",
merchantName: config.merchantName || "深圳龙观汽车科技有限公司",
tradeNo: config.tradeNo,
totalPrice: config.totalPrice,
notRefundedTotalPrice: config.notRefundedTotalPrice,
payDate: config.payDate || "2026-05-03 21:10:12",
payChannel: config.payChannel || "微信支付",
payType: config.payType || "1",
posTrmNo: config.posTrmNo || "T00123456",
yqMerchantName: config.yqMerchantName || "深圳龙观园区店",
distributionStatus: config.distributionStatus || "1",
refundStatus: config.refundStatus || "0",
declarationId: config.declarationId,
declarationApprovalStatus: config.declarationApprovalStatus,
abnormalType: config.abnormalType || "1",
remark: config.remark || "客户已付款,系统暂未录单,请审批。",
createdBy: config.createdBy || "张三",
createdDate: config.createdDate || "2026-05-03 21:10:12",
voucherImageUrls: config.voucherImageUrls || [
"https://via.placeholder.com/120x120.png?text=voucher1",
],
approvalLogs: config.approvalLogs || [],
};
}
const mockDeclarationStore = [
createMockItem({
declarationId: 1001,
declarationApprovalStatus: 1,
tradeNo: "TX20260503001",
totalPrice: 1280,
notRefundedTotalPrice: 1280,
approvalLogs: [],
}),
createMockItem({
declarationId: 1002,
declarationApprovalStatus: 2,
tradeNo: "TX20260503002",
totalPrice: 2560,
notRefundedTotalPrice: 2000,
remark: "凭证不完整,区域经理驳回。",
approvalLogs: [
{
approvalStatus: "2",
operatorName: "李四",
createdDate: "2026-05-03 22:00:00",
remark: "请补充支付凭证后重新报备。",
approvalSource: "0",
},
],
}),
createMockItem({
declarationId: 1003,
declarationApprovalStatus: 3,
tradeNo: "TX20260503003",
totalPrice: 3680,
notRefundedTotalPrice: 3680,
remark: "客户通过微信线上已付款,但未在系统录单。",
approvalLogs: [
{
approvalStatus: "3",
operatorName: "李四",
createdDate: "2026-05-03 21:30:10",
remark: "情况属实,同意总部运营进一步审核。",
approvalSource: "0",
},
],
}),
createMockItem({
declarationId: 1004,
declarationApprovalStatus: 4,
tradeNo: "TX20260503004",
totalPrice: 980,
notRefundedTotalPrice: 980,
approvalLogs: [
{
approvalStatus: "3",
operatorName: "李四",
createdDate: "2026-05-03 21:30:10",
remark: "情况属实,同意总部运营进一步审核。",
approvalSource: "0",
},
{
approvalStatus: "4",
operatorName: "王五",
createdDate: "2026-05-04 10:00:00",
remark: "材料不完整,予以驳回。",
approvalSource: "1",
},
],
}),
createMockItem({
declarationId: 1005,
declarationApprovalStatus: 5,
tradeNo: "TX20260503005",
totalPrice: 5200,
notRefundedTotalPrice: 5200,
approvalLogs: [
{
approvalStatus: "3",
operatorName: "李四",
createdDate: "2026-05-03 21:30:10",
remark: "情况属实,同意总部运营进一步审核。",
approvalSource: "0",
},
{
approvalStatus: "5",
operatorName: "王五",
createdDate: "2026-05-04 10:00:00",
remark: "同意延期观察。",
approvalSource: "1",
},
],
}),
createMockItem({
declarationId: null,
declarationApprovalStatus: null,
tradeNo: "TX20260503006",
totalPrice: 1500,
notRefundedTotalPrice: 1500,
}),
createMockItem({
declarationId: null,
declarationApprovalStatus: null,
tradeNo: "TX20260503007",
totalPrice: 880,
notRefundedTotalPrice: 880,
}),
createMockItem({
declarationId: 1006,
declarationApprovalStatus: 3,
tradeNo: "TX20260503008",
totalPrice: 1999,
notRefundedTotalPrice: 1999,
abnormalType: "6",
remark: "支付金额与订单金额不一致。",
approvalLogs: [
{
approvalStatus: "3",
operatorName: "赵六",
createdDate: "2026-05-05 09:15:00",
remark: "已核实,转总部审批。",
approvalSource: "0",
},
],
}),
];
function findStoreItem(id) {
return mockDeclarationStore.find(
(item) => item.declarationId != null && String(item.declarationId) === String(id),
);
}
function filterList() {
// mock 不按路由 merchantId 过滤,避免与固定测试数据不一致导致空列表
return [...mockDeclarationStore];
}
export function mockAbnormalPaymentDetailPage(data = {}) {
const filtered = filterList(data);
const page = paginate(filtered.map(buildListItem), data);
return delay(page);
}
export function mockPcAbnormalFlowDeclarationDetail(data = {}) {
const item = findStoreItem(data.id);
if (!item) {
return delayReject(new Error("报备记录不存在"));
}
return delay(mapAbnormalFlowDeclarationDetailResponse({
tradeInfo: buildTradeFields(item),
declarationInfo: {
abnormalType: item.abnormalType,
remark: item.remark,
createdBy: item.createdBy,
createdDate: item.createdDate,
voucherImageUrls: item.voucherImageUrls,
},
approvalLogs: item.approvalLogs || [],
}));
}
export function mockApprovePcAbnormalFlowDeclaration(data = {}) {
const item = findStoreItem(data.id);
if (!item) {
return delayReject(new Error("报备记录不存在"));
}
const approvalStatus = String(data.approvalStatus);
item.declarationApprovalStatus = Number(approvalStatus);
if (!Array.isArray(item.approvalLogs)) {
item.approvalLogs = [];
}
item.approvalLogs.push({
approvalStatus,
operatorName: "总部运营",
createdDate: new Date().toISOString().slice(0, 19).replace("T", " "),
remark: data.remark || "",
approvalSource: "1",
});
return delay(mapAbnormalFlowDeclarationApproveResponse(true));
}