@pisell/pisellos 0.0.194 → 0.0.196
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Payment/index.d.ts +45 -0
- package/dist/modules/Payment/index.js +782 -525
- package/dist/modules/Payment/types.d.ts +2 -0
- package/lib/modules/Payment/index.d.ts +45 -0
- package/lib/modules/Payment/index.js +159 -6
- package/lib/modules/Payment/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -28,6 +28,7 @@ import { EftposPaymentImpl } from "./eftpos";
|
|
|
28
28
|
import { WalletPaymentImpl } from "./wallet";
|
|
29
29
|
import { Decimal } from 'decimal.js';
|
|
30
30
|
export * from "./types";
|
|
31
|
+
export { generateRequestUniqueId };
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* 格式化金额为保留两位小数的字符串
|
|
@@ -42,6 +43,25 @@ function formatAmount(amount) {
|
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
/**
|
|
47
|
+
* 生成请求唯一ID
|
|
48
|
+
* 格式: 年月日时分秒毫秒+4位随机数
|
|
49
|
+
* 示例: 20241201143025123456
|
|
50
|
+
*/
|
|
51
|
+
function generateRequestUniqueId() {
|
|
52
|
+
var now = new Date();
|
|
53
|
+
var year = now.getFullYear();
|
|
54
|
+
var month = String(now.getMonth() + 1).padStart(2, '0');
|
|
55
|
+
var day = String(now.getDate()).padStart(2, '0');
|
|
56
|
+
var hour = String(now.getHours()).padStart(2, '0');
|
|
57
|
+
var minute = String(now.getMinutes()).padStart(2, '0');
|
|
58
|
+
var second = String(now.getSeconds()).padStart(2, '0');
|
|
59
|
+
var millisecond = String(now.getMilliseconds()).padStart(3, '0');
|
|
60
|
+
var randomDigits = Math.floor(Math.random() * 9000) + 1000; // 1000-9999的4位随机数
|
|
61
|
+
|
|
62
|
+
return "".concat(year).concat(month).concat(day).concat(hour).concat(minute).concat(second).concat(millisecond).concat(randomDigits);
|
|
63
|
+
}
|
|
64
|
+
|
|
45
65
|
/**
|
|
46
66
|
* 支付模块实现
|
|
47
67
|
*
|
|
@@ -219,19 +239,46 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
219
239
|
key: "registerNetworkHandlers",
|
|
220
240
|
value: function registerNetworkHandlers() {
|
|
221
241
|
var _this2 = this;
|
|
222
|
-
var network = this.app.
|
|
242
|
+
var network = this.app.plugins.get('network');
|
|
223
243
|
this.logInfo('Registering network status listener');
|
|
224
|
-
network === null || network === void 0 || network.addListener('networkStatusChange', function (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
244
|
+
network === null || network === void 0 || network.addListener('networkStatusChange', /*#__PURE__*/function () {
|
|
245
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(status) {
|
|
246
|
+
var requeuedCount;
|
|
247
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
248
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
249
|
+
case 0:
|
|
250
|
+
console.log('网络状态:', status.connected);
|
|
251
|
+
_this2.logInfo('Network status changed', {
|
|
252
|
+
connected: status.connected,
|
|
253
|
+
previousStatus: status.previousStatus
|
|
254
|
+
});
|
|
255
|
+
if (!status.connected) {
|
|
256
|
+
_context2.next = 10;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
_this2.logInfo('Network reconnected - triggering payment sync queue');
|
|
260
|
+
// this.runPaymentSyncQueue();
|
|
261
|
+
// 1. 先检查并重新排队未同步订单,然后执行队列
|
|
262
|
+
_context2.next = 6;
|
|
263
|
+
return _this2.recheckAndRequeueUnsyncedOrders();
|
|
264
|
+
case 6:
|
|
265
|
+
requeuedCount = _context2.sent;
|
|
266
|
+
if (!(requeuedCount > 0)) {
|
|
267
|
+
_context2.next = 10;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
_context2.next = 10;
|
|
271
|
+
return _this2.runPaymentSyncQueue();
|
|
272
|
+
case 10:
|
|
273
|
+
case "end":
|
|
274
|
+
return _context2.stop();
|
|
275
|
+
}
|
|
276
|
+
}, _callee2);
|
|
277
|
+
}));
|
|
278
|
+
return function (_x3) {
|
|
279
|
+
return _ref.apply(this, arguments);
|
|
280
|
+
};
|
|
281
|
+
}());
|
|
235
282
|
}
|
|
236
283
|
|
|
237
284
|
/**
|
|
@@ -240,96 +287,96 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
240
287
|
}, {
|
|
241
288
|
key: "getPayMethodListAsync",
|
|
242
289
|
value: (function () {
|
|
243
|
-
var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
290
|
+
var _getPayMethodListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
244
291
|
var cachedMethods, hasCache, response, payMethods, _iterator, _step, method;
|
|
245
|
-
return _regeneratorRuntime().wrap(function
|
|
246
|
-
while (1) switch (
|
|
292
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
293
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
247
294
|
case 0:
|
|
248
295
|
this.logInfo('Starting getPayMethodListAsync');
|
|
249
|
-
|
|
296
|
+
_context3.prev = 1;
|
|
250
297
|
// 先尝试从 IndexDB 获取缓存
|
|
251
298
|
cachedMethods = [];
|
|
252
|
-
|
|
253
|
-
|
|
299
|
+
_context3.prev = 3;
|
|
300
|
+
_context3.next = 6;
|
|
254
301
|
return this.dbManager.getAll('pay_method');
|
|
255
302
|
case 6:
|
|
256
|
-
cachedMethods =
|
|
257
|
-
|
|
303
|
+
cachedMethods = _context3.sent;
|
|
304
|
+
_context3.next = 12;
|
|
258
305
|
break;
|
|
259
306
|
case 9:
|
|
260
|
-
|
|
261
|
-
|
|
307
|
+
_context3.prev = 9;
|
|
308
|
+
_context3.t0 = _context3["catch"](3);
|
|
262
309
|
console.warn('[PaymentModule] pay_method 表不存在,将从服务器获取数据');
|
|
263
310
|
case 12:
|
|
264
311
|
// 如果有缓存,先返回缓存数据
|
|
265
312
|
hasCache = cachedMethods.length > 0;
|
|
266
313
|
if (!hasCache) {
|
|
267
|
-
|
|
314
|
+
_context3.next = 16;
|
|
268
315
|
break;
|
|
269
316
|
}
|
|
270
317
|
// 后台异步获取最新数据
|
|
271
318
|
this.refreshPaymentMethodsInBackground(cachedMethods);
|
|
272
|
-
return
|
|
319
|
+
return _context3.abrupt("return", cachedMethods);
|
|
273
320
|
case 16:
|
|
274
|
-
|
|
321
|
+
_context3.next = 18;
|
|
275
322
|
return this.request.get('/pay/custom-payment/available');
|
|
276
323
|
case 18:
|
|
277
|
-
response =
|
|
324
|
+
response = _context3.sent;
|
|
278
325
|
payMethods = response.data || []; // 尝试缓存到 IndexDB
|
|
279
|
-
|
|
326
|
+
_context3.prev = 20;
|
|
280
327
|
_iterator = _createForOfIteratorHelper(payMethods);
|
|
281
|
-
|
|
328
|
+
_context3.prev = 22;
|
|
282
329
|
_iterator.s();
|
|
283
330
|
case 24:
|
|
284
331
|
if ((_step = _iterator.n()).done) {
|
|
285
|
-
|
|
332
|
+
_context3.next = 30;
|
|
286
333
|
break;
|
|
287
334
|
}
|
|
288
335
|
method = _step.value;
|
|
289
|
-
|
|
336
|
+
_context3.next = 28;
|
|
290
337
|
return this.dbManager.update('pay_method', method);
|
|
291
338
|
case 28:
|
|
292
|
-
|
|
339
|
+
_context3.next = 24;
|
|
293
340
|
break;
|
|
294
341
|
case 30:
|
|
295
|
-
|
|
342
|
+
_context3.next = 35;
|
|
296
343
|
break;
|
|
297
344
|
case 32:
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
_iterator.e(
|
|
345
|
+
_context3.prev = 32;
|
|
346
|
+
_context3.t1 = _context3["catch"](22);
|
|
347
|
+
_iterator.e(_context3.t1);
|
|
301
348
|
case 35:
|
|
302
|
-
|
|
349
|
+
_context3.prev = 35;
|
|
303
350
|
_iterator.f();
|
|
304
|
-
return
|
|
351
|
+
return _context3.finish(35);
|
|
305
352
|
case 38:
|
|
306
|
-
|
|
353
|
+
_context3.next = 43;
|
|
307
354
|
break;
|
|
308
355
|
case 40:
|
|
309
|
-
|
|
310
|
-
|
|
356
|
+
_context3.prev = 40;
|
|
357
|
+
_context3.t2 = _context3["catch"](20);
|
|
311
358
|
console.warn('[PaymentModule] 无法缓存支付方式,pay_method 表不存在');
|
|
312
359
|
case 43:
|
|
313
|
-
|
|
360
|
+
_context3.next = 45;
|
|
314
361
|
return this.core.effects.emit(PaymentHooks.OnPaymentMethodsLoaded, payMethods);
|
|
315
362
|
case 45:
|
|
316
363
|
this.logInfo('getPayMethodListAsync completed successfully', {
|
|
317
364
|
methodCount: payMethods.length,
|
|
318
365
|
hasCache: cachedMethods.length > 0
|
|
319
366
|
});
|
|
320
|
-
return
|
|
367
|
+
return _context3.abrupt("return", payMethods);
|
|
321
368
|
case 49:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
console.error('[PaymentModule] 获取支付方式列表失败',
|
|
325
|
-
this.logError('getPayMethodListAsync failed',
|
|
369
|
+
_context3.prev = 49;
|
|
370
|
+
_context3.t3 = _context3["catch"](1);
|
|
371
|
+
console.error('[PaymentModule] 获取支付方式列表失败', _context3.t3);
|
|
372
|
+
this.logError('getPayMethodListAsync failed', _context3.t3);
|
|
326
373
|
// 如果所有操作都失败,返回空数组
|
|
327
|
-
return
|
|
374
|
+
return _context3.abrupt("return", []);
|
|
328
375
|
case 54:
|
|
329
376
|
case "end":
|
|
330
|
-
return
|
|
377
|
+
return _context3.stop();
|
|
331
378
|
}
|
|
332
|
-
},
|
|
379
|
+
}, _callee3, this, [[1, 49], [3, 9], [20, 40], [22, 32, 35, 38]]);
|
|
333
380
|
}));
|
|
334
381
|
function getPayMethodListAsync() {
|
|
335
382
|
return _getPayMethodListAsync.apply(this, arguments);
|
|
@@ -343,26 +390,26 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
343
390
|
}, {
|
|
344
391
|
key: "refreshPaymentMethodsInBackground",
|
|
345
392
|
value: (function () {
|
|
346
|
-
var _refreshPaymentMethodsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
393
|
+
var _refreshPaymentMethodsInBackground = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(cachedMethods) {
|
|
347
394
|
var response, newPayMethods, hasChanges, _iterator2, _step2, method, _iterator3, _step3, _method, eventData;
|
|
348
|
-
return _regeneratorRuntime().wrap(function
|
|
349
|
-
while (1) switch (
|
|
395
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
396
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
350
397
|
case 0:
|
|
351
398
|
this.logInfo('Starting refreshPaymentMethodsInBackground', {
|
|
352
399
|
cachedMethodsCount: cachedMethods.length
|
|
353
400
|
});
|
|
354
|
-
|
|
401
|
+
_context4.prev = 1;
|
|
355
402
|
console.log('[PaymentModule] 后台刷新支付方式列表...');
|
|
356
403
|
|
|
357
404
|
// 从服务器获取最新数据
|
|
358
|
-
|
|
405
|
+
_context4.next = 5;
|
|
359
406
|
return this.request.get('/pay/custom-payment/available');
|
|
360
407
|
case 5:
|
|
361
|
-
response =
|
|
408
|
+
response = _context4.sent;
|
|
362
409
|
newPayMethods = response.data || []; // 检查是否有变化
|
|
363
410
|
hasChanges = this.hasPaymentMethodsChanged(cachedMethods, newPayMethods);
|
|
364
411
|
if (!hasChanges) {
|
|
365
|
-
|
|
412
|
+
_context4.next = 56;
|
|
366
413
|
break;
|
|
367
414
|
}
|
|
368
415
|
console.log('[PaymentModule] 支付方式列表已更新');
|
|
@@ -372,94 +419,94 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
372
419
|
});
|
|
373
420
|
|
|
374
421
|
// 更新缓存
|
|
375
|
-
|
|
422
|
+
_context4.prev = 11;
|
|
376
423
|
// 先清除旧数据
|
|
377
424
|
_iterator2 = _createForOfIteratorHelper(cachedMethods);
|
|
378
|
-
|
|
425
|
+
_context4.prev = 13;
|
|
379
426
|
_iterator2.s();
|
|
380
427
|
case 15:
|
|
381
428
|
if ((_step2 = _iterator2.n()).done) {
|
|
382
|
-
|
|
429
|
+
_context4.next = 21;
|
|
383
430
|
break;
|
|
384
431
|
}
|
|
385
432
|
method = _step2.value;
|
|
386
|
-
|
|
433
|
+
_context4.next = 19;
|
|
387
434
|
return this.dbManager.delete('pay_method', method.id);
|
|
388
435
|
case 19:
|
|
389
|
-
|
|
436
|
+
_context4.next = 15;
|
|
390
437
|
break;
|
|
391
438
|
case 21:
|
|
392
|
-
|
|
439
|
+
_context4.next = 26;
|
|
393
440
|
break;
|
|
394
441
|
case 23:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
_iterator2.e(
|
|
442
|
+
_context4.prev = 23;
|
|
443
|
+
_context4.t0 = _context4["catch"](13);
|
|
444
|
+
_iterator2.e(_context4.t0);
|
|
398
445
|
case 26:
|
|
399
|
-
|
|
446
|
+
_context4.prev = 26;
|
|
400
447
|
_iterator2.f();
|
|
401
|
-
return
|
|
448
|
+
return _context4.finish(26);
|
|
402
449
|
case 29:
|
|
403
450
|
// 添加新数据
|
|
404
451
|
_iterator3 = _createForOfIteratorHelper(newPayMethods);
|
|
405
|
-
|
|
452
|
+
_context4.prev = 30;
|
|
406
453
|
_iterator3.s();
|
|
407
454
|
case 32:
|
|
408
455
|
if ((_step3 = _iterator3.n()).done) {
|
|
409
|
-
|
|
456
|
+
_context4.next = 38;
|
|
410
457
|
break;
|
|
411
458
|
}
|
|
412
459
|
_method = _step3.value;
|
|
413
|
-
|
|
460
|
+
_context4.next = 36;
|
|
414
461
|
return this.dbManager.update('pay_method', _method);
|
|
415
462
|
case 36:
|
|
416
|
-
|
|
463
|
+
_context4.next = 32;
|
|
417
464
|
break;
|
|
418
465
|
case 38:
|
|
419
|
-
|
|
466
|
+
_context4.next = 43;
|
|
420
467
|
break;
|
|
421
468
|
case 40:
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
_iterator3.e(
|
|
469
|
+
_context4.prev = 40;
|
|
470
|
+
_context4.t1 = _context4["catch"](30);
|
|
471
|
+
_iterator3.e(_context4.t1);
|
|
425
472
|
case 43:
|
|
426
|
-
|
|
473
|
+
_context4.prev = 43;
|
|
427
474
|
_iterator3.f();
|
|
428
|
-
return
|
|
475
|
+
return _context4.finish(43);
|
|
429
476
|
case 46:
|
|
430
|
-
|
|
477
|
+
_context4.next = 51;
|
|
431
478
|
break;
|
|
432
479
|
case 48:
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
console.warn('[PaymentModule] 无法更新支付方式缓存',
|
|
480
|
+
_context4.prev = 48;
|
|
481
|
+
_context4.t2 = _context4["catch"](11);
|
|
482
|
+
console.warn('[PaymentModule] 无法更新支付方式缓存', _context4.t2);
|
|
436
483
|
case 51:
|
|
437
484
|
// 通知外部支付方式已变化
|
|
438
485
|
eventData = {
|
|
439
486
|
oldMethods: cachedMethods,
|
|
440
487
|
newMethods: newPayMethods
|
|
441
488
|
};
|
|
442
|
-
|
|
489
|
+
_context4.next = 54;
|
|
443
490
|
return this.core.effects.emit(PaymentHooks.OnPaymentMethodsChanged, eventData);
|
|
444
491
|
case 54:
|
|
445
|
-
|
|
492
|
+
_context4.next = 57;
|
|
446
493
|
break;
|
|
447
494
|
case 56:
|
|
448
495
|
console.log('[PaymentModule] 支付方式列表无变化');
|
|
449
496
|
case 57:
|
|
450
|
-
|
|
497
|
+
_context4.next = 62;
|
|
451
498
|
break;
|
|
452
499
|
case 59:
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
console.error('[PaymentModule] 后台刷新支付方式失败',
|
|
500
|
+
_context4.prev = 59;
|
|
501
|
+
_context4.t3 = _context4["catch"](1);
|
|
502
|
+
console.error('[PaymentModule] 后台刷新支付方式失败', _context4.t3);
|
|
456
503
|
case 62:
|
|
457
504
|
case "end":
|
|
458
|
-
return
|
|
505
|
+
return _context4.stop();
|
|
459
506
|
}
|
|
460
|
-
},
|
|
507
|
+
}, _callee4, this, [[1, 59], [11, 48], [13, 23, 26, 29], [30, 40, 43, 46]]);
|
|
461
508
|
}));
|
|
462
|
-
function refreshPaymentMethodsInBackground(
|
|
509
|
+
function refreshPaymentMethodsInBackground(_x4) {
|
|
463
510
|
return _refreshPaymentMethodsInBackground.apply(this, arguments);
|
|
464
511
|
}
|
|
465
512
|
return refreshPaymentMethodsInBackground;
|
|
@@ -510,25 +557,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
510
557
|
}, {
|
|
511
558
|
key: "getOrderListAsync",
|
|
512
559
|
value: (function () {
|
|
513
|
-
var _getOrderListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
514
|
-
return _regeneratorRuntime().wrap(function
|
|
515
|
-
while (1) switch (
|
|
560
|
+
var _getOrderListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
561
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
562
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
516
563
|
case 0:
|
|
517
|
-
|
|
518
|
-
|
|
564
|
+
_context5.prev = 0;
|
|
565
|
+
_context5.next = 3;
|
|
519
566
|
return this.dbManager.getAll('order');
|
|
520
567
|
case 3:
|
|
521
|
-
return
|
|
568
|
+
return _context5.abrupt("return", _context5.sent);
|
|
522
569
|
case 6:
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
console.error('[PaymentModule] 获取订单列表失败',
|
|
526
|
-
return
|
|
570
|
+
_context5.prev = 6;
|
|
571
|
+
_context5.t0 = _context5["catch"](0);
|
|
572
|
+
console.error('[PaymentModule] 获取订单列表失败', _context5.t0);
|
|
573
|
+
return _context5.abrupt("return", []);
|
|
527
574
|
case 10:
|
|
528
575
|
case "end":
|
|
529
|
-
return
|
|
576
|
+
return _context5.stop();
|
|
530
577
|
}
|
|
531
|
-
},
|
|
578
|
+
}, _callee5, this, [[0, 6]]);
|
|
532
579
|
}));
|
|
533
580
|
function getOrderListAsync() {
|
|
534
581
|
return _getOrderListAsync.apply(this, arguments);
|
|
@@ -542,27 +589,27 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
542
589
|
}, {
|
|
543
590
|
key: "getOrderByUuidAsync",
|
|
544
591
|
value: (function () {
|
|
545
|
-
var _getOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
546
|
-
return _regeneratorRuntime().wrap(function
|
|
547
|
-
while (1) switch (
|
|
592
|
+
var _getOrderByUuidAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(orderUuid) {
|
|
593
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
594
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
548
595
|
case 0:
|
|
549
|
-
|
|
550
|
-
|
|
596
|
+
_context6.prev = 0;
|
|
597
|
+
_context6.next = 3;
|
|
551
598
|
return this.dbManager.get('order', orderUuid);
|
|
552
599
|
case 3:
|
|
553
|
-
return
|
|
600
|
+
return _context6.abrupt("return", _context6.sent);
|
|
554
601
|
case 6:
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
console.error('[PaymentModule] 获取订单失败',
|
|
558
|
-
return
|
|
602
|
+
_context6.prev = 6;
|
|
603
|
+
_context6.t0 = _context6["catch"](0);
|
|
604
|
+
console.error('[PaymentModule] 获取订单失败', _context6.t0);
|
|
605
|
+
return _context6.abrupt("return", null);
|
|
559
606
|
case 10:
|
|
560
607
|
case "end":
|
|
561
|
-
return
|
|
608
|
+
return _context6.stop();
|
|
562
609
|
}
|
|
563
|
-
},
|
|
610
|
+
}, _callee6, this, [[0, 6]]);
|
|
564
611
|
}));
|
|
565
|
-
function getOrderByUuidAsync(
|
|
612
|
+
function getOrderByUuidAsync(_x5) {
|
|
566
613
|
return _getOrderByUuidAsync.apply(this, arguments);
|
|
567
614
|
}
|
|
568
615
|
return getOrderByUuidAsync;
|
|
@@ -574,25 +621,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
574
621
|
}, {
|
|
575
622
|
key: "pushOrderAsync",
|
|
576
623
|
value: (function () {
|
|
577
|
-
var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
624
|
+
var _pushOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
|
|
578
625
|
var existingOrders, existingOrder, originalOrder, newOrder;
|
|
579
|
-
return _regeneratorRuntime().wrap(function
|
|
580
|
-
while (1) switch (
|
|
626
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
627
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
581
628
|
case 0:
|
|
582
629
|
this.logInfo('Starting pushOrderAsync', {
|
|
583
630
|
orderId: params.order_info.order_id,
|
|
584
631
|
totalAmount: params.order_info.total_amount
|
|
585
632
|
});
|
|
586
|
-
|
|
587
|
-
|
|
633
|
+
_context7.prev = 1;
|
|
634
|
+
_context7.next = 4;
|
|
588
635
|
return this.dbManager.getAll('order');
|
|
589
636
|
case 4:
|
|
590
|
-
existingOrders =
|
|
637
|
+
existingOrders = _context7.sent;
|
|
591
638
|
existingOrder = existingOrders.find(function (order) {
|
|
592
639
|
return order.id === params.order_info.order_id;
|
|
593
640
|
});
|
|
594
641
|
if (!existingOrder) {
|
|
595
|
-
|
|
642
|
+
_context7.next = 21;
|
|
596
643
|
break;
|
|
597
644
|
}
|
|
598
645
|
// 如果存在相同 order_id 的订单,更新该订单的 order_info
|
|
@@ -605,20 +652,20 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
605
652
|
this.recalculateOrderAmount(existingOrder);
|
|
606
653
|
|
|
607
654
|
// 更新到数据库
|
|
608
|
-
|
|
655
|
+
_context7.next = 14;
|
|
609
656
|
return this.dbManager.update('order', existingOrder);
|
|
610
657
|
case 14:
|
|
611
|
-
|
|
658
|
+
_context7.next = 16;
|
|
612
659
|
return this.core.effects.emit(PaymentHooks.OnOrderUpdated, existingOrder);
|
|
613
660
|
case 16:
|
|
614
|
-
|
|
661
|
+
_context7.next = 18;
|
|
615
662
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
616
663
|
action: 'update',
|
|
617
664
|
order: existingOrder,
|
|
618
665
|
originalOrder: originalOrder
|
|
619
666
|
});
|
|
620
667
|
case 18:
|
|
621
|
-
return
|
|
668
|
+
return _context7.abrupt("return", existingOrder);
|
|
622
669
|
case 21:
|
|
623
670
|
// 如果不存在相同 order_id 的订单,创建新订单
|
|
624
671
|
newOrder = {
|
|
@@ -632,13 +679,13 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
632
679
|
expect_amount: params.order_info.total_amount,
|
|
633
680
|
tax_fee: '0.00'
|
|
634
681
|
};
|
|
635
|
-
|
|
682
|
+
_context7.next = 24;
|
|
636
683
|
return this.dbManager.add('order', newOrder);
|
|
637
684
|
case 24:
|
|
638
|
-
|
|
685
|
+
_context7.next = 26;
|
|
639
686
|
return this.core.effects.emit(PaymentHooks.OnOrderAdded, newOrder);
|
|
640
687
|
case 26:
|
|
641
|
-
|
|
688
|
+
_context7.next = 28;
|
|
642
689
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
643
690
|
action: 'add',
|
|
644
691
|
order: newOrder
|
|
@@ -648,25 +695,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
648
695
|
orderUuid: newOrder.uuid,
|
|
649
696
|
orderId: newOrder.id
|
|
650
697
|
});
|
|
651
|
-
return
|
|
698
|
+
return _context7.abrupt("return", newOrder);
|
|
652
699
|
case 30:
|
|
653
|
-
|
|
700
|
+
_context7.next = 37;
|
|
654
701
|
break;
|
|
655
702
|
case 32:
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
console.error('[PaymentModule] 添加订单失败',
|
|
659
|
-
this.logError('pushOrderAsync failed',
|
|
703
|
+
_context7.prev = 32;
|
|
704
|
+
_context7.t0 = _context7["catch"](1);
|
|
705
|
+
console.error('[PaymentModule] 添加订单失败', _context7.t0);
|
|
706
|
+
this.logError('pushOrderAsync failed', _context7.t0, {
|
|
660
707
|
orderId: params.order_info.order_id
|
|
661
708
|
});
|
|
662
|
-
throw
|
|
709
|
+
throw _context7.t0;
|
|
663
710
|
case 37:
|
|
664
711
|
case "end":
|
|
665
|
-
return
|
|
712
|
+
return _context7.stop();
|
|
666
713
|
}
|
|
667
|
-
},
|
|
714
|
+
}, _callee7, this, [[1, 32]]);
|
|
668
715
|
}));
|
|
669
|
-
function pushOrderAsync(
|
|
716
|
+
function pushOrderAsync(_x6) {
|
|
670
717
|
return _pushOrderAsync.apply(this, arguments);
|
|
671
718
|
}
|
|
672
719
|
return pushOrderAsync;
|
|
@@ -678,46 +725,46 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
678
725
|
}, {
|
|
679
726
|
key: "deleteOrderAsync",
|
|
680
727
|
value: (function () {
|
|
681
|
-
var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
728
|
+
var _deleteOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(orderUuid) {
|
|
682
729
|
var order;
|
|
683
|
-
return _regeneratorRuntime().wrap(function
|
|
684
|
-
while (1) switch (
|
|
730
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
731
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
685
732
|
case 0:
|
|
686
|
-
|
|
687
|
-
|
|
733
|
+
_context8.prev = 0;
|
|
734
|
+
_context8.next = 3;
|
|
688
735
|
return this.dbManager.get('order', orderUuid);
|
|
689
736
|
case 3:
|
|
690
|
-
order =
|
|
737
|
+
order = _context8.sent;
|
|
691
738
|
if (!order) {
|
|
692
|
-
|
|
739
|
+
_context8.next = 11;
|
|
693
740
|
break;
|
|
694
741
|
}
|
|
695
|
-
|
|
742
|
+
_context8.next = 7;
|
|
696
743
|
return this.dbManager.delete('order', orderUuid);
|
|
697
744
|
case 7:
|
|
698
|
-
|
|
745
|
+
_context8.next = 9;
|
|
699
746
|
return this.core.effects.emit(PaymentHooks.OnOrderDeleted, order);
|
|
700
747
|
case 9:
|
|
701
|
-
|
|
748
|
+
_context8.next = 11;
|
|
702
749
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
703
750
|
action: 'delete',
|
|
704
751
|
order: order
|
|
705
752
|
});
|
|
706
753
|
case 11:
|
|
707
|
-
|
|
754
|
+
_context8.next = 17;
|
|
708
755
|
break;
|
|
709
756
|
case 13:
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
console.error('[PaymentModule] 删除订单失败',
|
|
713
|
-
throw
|
|
757
|
+
_context8.prev = 13;
|
|
758
|
+
_context8.t0 = _context8["catch"](0);
|
|
759
|
+
console.error('[PaymentModule] 删除订单失败', _context8.t0);
|
|
760
|
+
throw _context8.t0;
|
|
714
761
|
case 17:
|
|
715
762
|
case "end":
|
|
716
|
-
return
|
|
763
|
+
return _context8.stop();
|
|
717
764
|
}
|
|
718
|
-
},
|
|
765
|
+
}, _callee8, this, [[0, 13]]);
|
|
719
766
|
}));
|
|
720
|
-
function deleteOrderAsync(
|
|
767
|
+
function deleteOrderAsync(_x7) {
|
|
721
768
|
return _deleteOrderAsync.apply(this, arguments);
|
|
722
769
|
}
|
|
723
770
|
return deleteOrderAsync;
|
|
@@ -729,48 +776,48 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
729
776
|
}, {
|
|
730
777
|
key: "updateOrderAsync",
|
|
731
778
|
value: (function () {
|
|
732
|
-
var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
779
|
+
var _updateOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(orderUuid, params) {
|
|
733
780
|
var order, updatedOrder;
|
|
734
|
-
return _regeneratorRuntime().wrap(function
|
|
735
|
-
while (1) switch (
|
|
781
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
782
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
736
783
|
case 0:
|
|
737
|
-
|
|
738
|
-
|
|
784
|
+
_context9.prev = 0;
|
|
785
|
+
_context9.next = 3;
|
|
739
786
|
return this.dbManager.get('order', orderUuid);
|
|
740
787
|
case 3:
|
|
741
|
-
order =
|
|
788
|
+
order = _context9.sent;
|
|
742
789
|
if (!order) {
|
|
743
|
-
|
|
790
|
+
_context9.next = 12;
|
|
744
791
|
break;
|
|
745
792
|
}
|
|
746
793
|
updatedOrder = _objectSpread(_objectSpread({}, order), params);
|
|
747
|
-
|
|
794
|
+
_context9.next = 8;
|
|
748
795
|
return this.dbManager.update('order', updatedOrder);
|
|
749
796
|
case 8:
|
|
750
|
-
|
|
797
|
+
_context9.next = 10;
|
|
751
798
|
return this.core.effects.emit(PaymentHooks.OnOrderUpdated, updatedOrder);
|
|
752
799
|
case 10:
|
|
753
|
-
|
|
800
|
+
_context9.next = 12;
|
|
754
801
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
755
802
|
action: 'update',
|
|
756
803
|
order: updatedOrder,
|
|
757
804
|
originalOrder: order
|
|
758
805
|
});
|
|
759
806
|
case 12:
|
|
760
|
-
|
|
807
|
+
_context9.next = 18;
|
|
761
808
|
break;
|
|
762
809
|
case 14:
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
console.error('[PaymentModule] 更新订单失败',
|
|
766
|
-
throw
|
|
810
|
+
_context9.prev = 14;
|
|
811
|
+
_context9.t0 = _context9["catch"](0);
|
|
812
|
+
console.error('[PaymentModule] 更新订单失败', _context9.t0);
|
|
813
|
+
throw _context9.t0;
|
|
767
814
|
case 18:
|
|
768
815
|
case "end":
|
|
769
|
-
return
|
|
816
|
+
return _context9.stop();
|
|
770
817
|
}
|
|
771
|
-
},
|
|
818
|
+
}, _callee9, this, [[0, 14]]);
|
|
772
819
|
}));
|
|
773
|
-
function updateOrderAsync(
|
|
820
|
+
function updateOrderAsync(_x8, _x9) {
|
|
774
821
|
return _updateOrderAsync.apply(this, arguments);
|
|
775
822
|
}
|
|
776
823
|
return updateOrderAsync;
|
|
@@ -782,29 +829,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
782
829
|
}, {
|
|
783
830
|
key: "getPaymentAsync",
|
|
784
831
|
value: (function () {
|
|
785
|
-
var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
832
|
+
var _getPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(orderUuid) {
|
|
786
833
|
var order;
|
|
787
|
-
return _regeneratorRuntime().wrap(function
|
|
788
|
-
while (1) switch (
|
|
834
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
835
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
789
836
|
case 0:
|
|
790
837
|
if (orderUuid) {
|
|
791
|
-
|
|
838
|
+
_context10.next = 2;
|
|
792
839
|
break;
|
|
793
840
|
}
|
|
794
841
|
throw new Error('orderUuid is required');
|
|
795
842
|
case 2:
|
|
796
|
-
|
|
843
|
+
_context10.next = 4;
|
|
797
844
|
return this.getOrderByUuidAsync(orderUuid);
|
|
798
845
|
case 4:
|
|
799
|
-
order =
|
|
800
|
-
return
|
|
846
|
+
order = _context10.sent;
|
|
847
|
+
return _context10.abrupt("return", (order === null || order === void 0 ? void 0 : order.payment) || []);
|
|
801
848
|
case 6:
|
|
802
849
|
case "end":
|
|
803
|
-
return
|
|
850
|
+
return _context10.stop();
|
|
804
851
|
}
|
|
805
|
-
},
|
|
852
|
+
}, _callee10, this);
|
|
806
853
|
}));
|
|
807
|
-
function getPaymentAsync(
|
|
854
|
+
function getPaymentAsync(_x10) {
|
|
808
855
|
return _getPaymentAsync.apply(this, arguments);
|
|
809
856
|
}
|
|
810
857
|
return getPaymentAsync;
|
|
@@ -816,23 +863,23 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
816
863
|
}, {
|
|
817
864
|
key: "pushPaymentAsync",
|
|
818
865
|
value: (function () {
|
|
819
|
-
var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
866
|
+
var _pushPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(orderUuid, paymentItem) {
|
|
820
867
|
var order, newPaymentItem;
|
|
821
|
-
return _regeneratorRuntime().wrap(function
|
|
822
|
-
while (1) switch (
|
|
868
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
869
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
823
870
|
case 0:
|
|
824
871
|
this.logInfo('Starting pushPaymentAsync', {
|
|
825
872
|
orderUuid: orderUuid,
|
|
826
873
|
paymentAmount: paymentItem.amount,
|
|
827
874
|
paymentCode: paymentItem.code
|
|
828
875
|
});
|
|
829
|
-
|
|
830
|
-
|
|
876
|
+
_context11.prev = 1;
|
|
877
|
+
_context11.next = 4;
|
|
831
878
|
return this.dbManager.get('order', orderUuid);
|
|
832
879
|
case 4:
|
|
833
|
-
order =
|
|
880
|
+
order = _context11.sent;
|
|
834
881
|
if (order) {
|
|
835
|
-
|
|
882
|
+
_context11.next = 7;
|
|
836
883
|
break;
|
|
837
884
|
}
|
|
838
885
|
throw new Error('订单不存在');
|
|
@@ -849,16 +896,16 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
849
896
|
this.recalculateOrderAmount(order);
|
|
850
897
|
|
|
851
898
|
// 更新到 IndexDB
|
|
852
|
-
|
|
899
|
+
_context11.next = 12;
|
|
853
900
|
return this.dbManager.update('order', order);
|
|
854
901
|
case 12:
|
|
855
|
-
|
|
902
|
+
_context11.next = 14;
|
|
856
903
|
return this.core.effects.emit(PaymentHooks.OnPaymentAdded, {
|
|
857
904
|
order: order,
|
|
858
905
|
paymentItem: newPaymentItem
|
|
859
906
|
});
|
|
860
907
|
case 14:
|
|
861
|
-
|
|
908
|
+
_context11.next = 16;
|
|
862
909
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
863
910
|
action: 'payment_add',
|
|
864
911
|
order: order,
|
|
@@ -870,24 +917,24 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
870
917
|
paymentUuid: newPaymentItem.uuid,
|
|
871
918
|
newExpectAmount: order.expect_amount
|
|
872
919
|
});
|
|
873
|
-
|
|
920
|
+
_context11.next = 24;
|
|
874
921
|
break;
|
|
875
922
|
case 19:
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
console.error('[PaymentModule] 添加支付项失败',
|
|
879
|
-
this.logError('pushPaymentAsync failed',
|
|
923
|
+
_context11.prev = 19;
|
|
924
|
+
_context11.t0 = _context11["catch"](1);
|
|
925
|
+
console.error('[PaymentModule] 添加支付项失败', _context11.t0);
|
|
926
|
+
this.logError('pushPaymentAsync failed', _context11.t0, {
|
|
880
927
|
orderUuid: orderUuid,
|
|
881
928
|
paymentItem: paymentItem
|
|
882
929
|
});
|
|
883
|
-
throw
|
|
930
|
+
throw _context11.t0;
|
|
884
931
|
case 24:
|
|
885
932
|
case "end":
|
|
886
|
-
return
|
|
933
|
+
return _context11.stop();
|
|
887
934
|
}
|
|
888
|
-
},
|
|
935
|
+
}, _callee11, this, [[1, 19]]);
|
|
889
936
|
}));
|
|
890
|
-
function pushPaymentAsync(
|
|
937
|
+
function pushPaymentAsync(_x11, _x12) {
|
|
891
938
|
return _pushPaymentAsync.apply(this, arguments);
|
|
892
939
|
}
|
|
893
940
|
return pushPaymentAsync;
|
|
@@ -899,22 +946,22 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
899
946
|
}, {
|
|
900
947
|
key: "deletePaymentAsync",
|
|
901
948
|
value: (function () {
|
|
902
|
-
var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
949
|
+
var _deletePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(orderUuid, paymentUuid) {
|
|
903
950
|
var order, index, deletedPayment;
|
|
904
|
-
return _regeneratorRuntime().wrap(function
|
|
905
|
-
while (1) switch (
|
|
951
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
952
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
906
953
|
case 0:
|
|
907
954
|
this.logInfo('Starting deletePaymentAsync', {
|
|
908
955
|
orderUuid: orderUuid,
|
|
909
956
|
paymentUuid: paymentUuid
|
|
910
957
|
});
|
|
911
|
-
|
|
912
|
-
|
|
958
|
+
_context12.prev = 1;
|
|
959
|
+
_context12.next = 4;
|
|
913
960
|
return this.dbManager.get('order', orderUuid);
|
|
914
961
|
case 4:
|
|
915
|
-
order =
|
|
962
|
+
order = _context12.sent;
|
|
916
963
|
if (order) {
|
|
917
|
-
|
|
964
|
+
_context12.next = 7;
|
|
918
965
|
break;
|
|
919
966
|
}
|
|
920
967
|
throw new Error('订单不存在');
|
|
@@ -923,43 +970,43 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
923
970
|
return payment.uuid === paymentUuid;
|
|
924
971
|
});
|
|
925
972
|
if (!(index > -1)) {
|
|
926
|
-
|
|
973
|
+
_context12.next = 17;
|
|
927
974
|
break;
|
|
928
975
|
}
|
|
929
976
|
deletedPayment = order.payment.splice(index, 1)[0]; // 重新计算待付金额
|
|
930
977
|
this.recalculateOrderAmount(order);
|
|
931
978
|
|
|
932
979
|
// 更新到 IndexDB
|
|
933
|
-
|
|
980
|
+
_context12.next = 13;
|
|
934
981
|
return this.dbManager.update('order', order);
|
|
935
982
|
case 13:
|
|
936
|
-
|
|
983
|
+
_context12.next = 15;
|
|
937
984
|
return this.core.effects.emit(PaymentHooks.OnPaymentDeleted, {
|
|
938
985
|
order: order,
|
|
939
986
|
paymentItem: deletedPayment
|
|
940
987
|
});
|
|
941
988
|
case 15:
|
|
942
|
-
|
|
989
|
+
_context12.next = 17;
|
|
943
990
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
944
991
|
action: 'payment_delete',
|
|
945
992
|
order: order,
|
|
946
993
|
paymentItem: deletedPayment
|
|
947
994
|
});
|
|
948
995
|
case 17:
|
|
949
|
-
|
|
996
|
+
_context12.next = 23;
|
|
950
997
|
break;
|
|
951
998
|
case 19:
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
console.error('[PaymentModule] 删除支付项失败',
|
|
955
|
-
throw
|
|
999
|
+
_context12.prev = 19;
|
|
1000
|
+
_context12.t0 = _context12["catch"](1);
|
|
1001
|
+
console.error('[PaymentModule] 删除支付项失败', _context12.t0);
|
|
1002
|
+
throw _context12.t0;
|
|
956
1003
|
case 23:
|
|
957
1004
|
case "end":
|
|
958
|
-
return
|
|
1005
|
+
return _context12.stop();
|
|
959
1006
|
}
|
|
960
|
-
},
|
|
1007
|
+
}, _callee12, this, [[1, 19]]);
|
|
961
1008
|
}));
|
|
962
|
-
function deletePaymentAsync(
|
|
1009
|
+
function deletePaymentAsync(_x13, _x14) {
|
|
963
1010
|
return _deletePaymentAsync.apply(this, arguments);
|
|
964
1011
|
}
|
|
965
1012
|
return deletePaymentAsync;
|
|
@@ -971,18 +1018,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
971
1018
|
}, {
|
|
972
1019
|
key: "updatePaymentAsync",
|
|
973
1020
|
value: (function () {
|
|
974
|
-
var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1021
|
+
var _updatePaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderUuid, paymentUuid, params) {
|
|
975
1022
|
var order, paymentItem, formattedParams;
|
|
976
|
-
return _regeneratorRuntime().wrap(function
|
|
977
|
-
while (1) switch (
|
|
1023
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1024
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
978
1025
|
case 0:
|
|
979
|
-
|
|
980
|
-
|
|
1026
|
+
_context13.prev = 0;
|
|
1027
|
+
_context13.next = 3;
|
|
981
1028
|
return this.dbManager.get('order', orderUuid);
|
|
982
1029
|
case 3:
|
|
983
|
-
order =
|
|
1030
|
+
order = _context13.sent;
|
|
984
1031
|
if (order) {
|
|
985
|
-
|
|
1032
|
+
_context13.next = 6;
|
|
986
1033
|
break;
|
|
987
1034
|
}
|
|
988
1035
|
throw new Error('订单不存在');
|
|
@@ -991,7 +1038,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
991
1038
|
return payment.uuid === paymentUuid;
|
|
992
1039
|
});
|
|
993
1040
|
if (!paymentItem) {
|
|
994
|
-
|
|
1041
|
+
_context13.next = 18;
|
|
995
1042
|
break;
|
|
996
1043
|
}
|
|
997
1044
|
// 如果更新参数中包含 amount,先格式化
|
|
@@ -1005,36 +1052,36 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1005
1052
|
this.recalculateOrderAmount(order);
|
|
1006
1053
|
|
|
1007
1054
|
// 更新到 IndexDB
|
|
1008
|
-
|
|
1055
|
+
_context13.next = 14;
|
|
1009
1056
|
return this.dbManager.update('order', order);
|
|
1010
1057
|
case 14:
|
|
1011
|
-
|
|
1058
|
+
_context13.next = 16;
|
|
1012
1059
|
return this.core.effects.emit(PaymentHooks.OnPaymentUpdated, {
|
|
1013
1060
|
order: order,
|
|
1014
1061
|
paymentItem: paymentItem
|
|
1015
1062
|
});
|
|
1016
1063
|
case 16:
|
|
1017
|
-
|
|
1064
|
+
_context13.next = 18;
|
|
1018
1065
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
1019
1066
|
action: 'payment_update',
|
|
1020
1067
|
order: order,
|
|
1021
1068
|
paymentItem: paymentItem
|
|
1022
1069
|
});
|
|
1023
1070
|
case 18:
|
|
1024
|
-
|
|
1071
|
+
_context13.next = 24;
|
|
1025
1072
|
break;
|
|
1026
1073
|
case 20:
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
console.error('[PaymentModule] 更新支付项失败',
|
|
1030
|
-
throw
|
|
1074
|
+
_context13.prev = 20;
|
|
1075
|
+
_context13.t0 = _context13["catch"](0);
|
|
1076
|
+
console.error('[PaymentModule] 更新支付项失败', _context13.t0);
|
|
1077
|
+
throw _context13.t0;
|
|
1031
1078
|
case 24:
|
|
1032
1079
|
case "end":
|
|
1033
|
-
return
|
|
1080
|
+
return _context13.stop();
|
|
1034
1081
|
}
|
|
1035
|
-
},
|
|
1082
|
+
}, _callee13, this, [[0, 20]]);
|
|
1036
1083
|
}));
|
|
1037
|
-
function updatePaymentAsync(
|
|
1084
|
+
function updatePaymentAsync(_x15, _x16, _x17) {
|
|
1038
1085
|
return _updatePaymentAsync.apply(this, arguments);
|
|
1039
1086
|
}
|
|
1040
1087
|
return updatePaymentAsync;
|
|
@@ -1046,76 +1093,76 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1046
1093
|
}, {
|
|
1047
1094
|
key: "submitPayAsync",
|
|
1048
1095
|
value: (function () {
|
|
1049
|
-
var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1096
|
+
var _submitPayAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(orderUuid) {
|
|
1050
1097
|
var orderToSubmit, order, _allOrders, _iterator5, _step5, _order, allOrders, allOrdersProcessed, result;
|
|
1051
|
-
return _regeneratorRuntime().wrap(function
|
|
1052
|
-
while (1) switch (
|
|
1098
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1099
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1053
1100
|
case 0:
|
|
1054
1101
|
this.logInfo('Starting submitPayAsync', {
|
|
1055
1102
|
orderUuid: orderUuid
|
|
1056
1103
|
});
|
|
1057
|
-
|
|
1104
|
+
_context14.prev = 1;
|
|
1058
1105
|
if (!orderUuid) {
|
|
1059
|
-
|
|
1106
|
+
_context14.next = 9;
|
|
1060
1107
|
break;
|
|
1061
1108
|
}
|
|
1062
|
-
|
|
1109
|
+
_context14.next = 5;
|
|
1063
1110
|
return this.dbManager.get('order', orderUuid);
|
|
1064
1111
|
case 5:
|
|
1065
|
-
order =
|
|
1112
|
+
order = _context14.sent;
|
|
1066
1113
|
orderToSubmit = order ? [order] : [];
|
|
1067
|
-
|
|
1114
|
+
_context14.next = 13;
|
|
1068
1115
|
break;
|
|
1069
1116
|
case 9:
|
|
1070
|
-
|
|
1117
|
+
_context14.next = 11;
|
|
1071
1118
|
return this.dbManager.getAll('order');
|
|
1072
1119
|
case 11:
|
|
1073
|
-
_allOrders =
|
|
1120
|
+
_allOrders = _context14.sent;
|
|
1074
1121
|
// 包括正在处理中的订单和部分支付的订单(可能添加了新的支付项)
|
|
1075
1122
|
orderToSubmit = _allOrders.filter(function (order) {
|
|
1076
1123
|
return order.payment_status === PaymentStatus.Processing || order.payment_status === PaymentStatus.PartiallyPaid;
|
|
1077
1124
|
});
|
|
1078
1125
|
case 13:
|
|
1079
1126
|
_iterator5 = _createForOfIteratorHelper(orderToSubmit);
|
|
1080
|
-
|
|
1127
|
+
_context14.prev = 14;
|
|
1081
1128
|
_iterator5.s();
|
|
1082
1129
|
case 16:
|
|
1083
1130
|
if ((_step5 = _iterator5.n()).done) {
|
|
1084
|
-
|
|
1131
|
+
_context14.next = 22;
|
|
1085
1132
|
break;
|
|
1086
1133
|
}
|
|
1087
1134
|
_order = _step5.value;
|
|
1088
|
-
|
|
1135
|
+
_context14.next = 20;
|
|
1089
1136
|
return this.submitSingleOrderPayment(_order);
|
|
1090
1137
|
case 20:
|
|
1091
|
-
|
|
1138
|
+
_context14.next = 16;
|
|
1092
1139
|
break;
|
|
1093
1140
|
case 22:
|
|
1094
|
-
|
|
1141
|
+
_context14.next = 27;
|
|
1095
1142
|
break;
|
|
1096
1143
|
case 24:
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
_iterator5.e(
|
|
1144
|
+
_context14.prev = 24;
|
|
1145
|
+
_context14.t0 = _context14["catch"](14);
|
|
1146
|
+
_iterator5.e(_context14.t0);
|
|
1100
1147
|
case 27:
|
|
1101
|
-
|
|
1148
|
+
_context14.prev = 27;
|
|
1102
1149
|
_iterator5.f();
|
|
1103
|
-
return
|
|
1150
|
+
return _context14.finish(27);
|
|
1104
1151
|
case 30:
|
|
1105
|
-
|
|
1152
|
+
_context14.next = 32;
|
|
1106
1153
|
return this.runPaymentSyncQueue();
|
|
1107
1154
|
case 32:
|
|
1108
|
-
|
|
1155
|
+
_context14.next = 34;
|
|
1109
1156
|
return this.dbManager.getAll('order');
|
|
1110
1157
|
case 34:
|
|
1111
|
-
allOrders =
|
|
1158
|
+
allOrders = _context14.sent;
|
|
1112
1159
|
allOrdersProcessed = allOrders.every(function (order) {
|
|
1113
1160
|
return order.payment.every(function (payment) {
|
|
1114
1161
|
return payment.isSynced === true;
|
|
1115
1162
|
});
|
|
1116
1163
|
});
|
|
1117
1164
|
if (!allOrdersProcessed) {
|
|
1118
|
-
|
|
1165
|
+
_context14.next = 42;
|
|
1119
1166
|
break;
|
|
1120
1167
|
}
|
|
1121
1168
|
result = {
|
|
@@ -1125,34 +1172,34 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1125
1172
|
result: result.status,
|
|
1126
1173
|
processedOrdersCount: allOrders.length
|
|
1127
1174
|
});
|
|
1128
|
-
return
|
|
1175
|
+
return _context14.abrupt("return", result);
|
|
1129
1176
|
case 42:
|
|
1130
1177
|
this.logWarning('submitPayAsync completed with unprocessed orders', {
|
|
1131
1178
|
totalOrders: allOrders.length
|
|
1132
1179
|
});
|
|
1133
|
-
return
|
|
1180
|
+
return _context14.abrupt("return", {
|
|
1134
1181
|
status: 'failed'
|
|
1135
1182
|
});
|
|
1136
1183
|
case 44:
|
|
1137
|
-
|
|
1184
|
+
_context14.next = 51;
|
|
1138
1185
|
break;
|
|
1139
1186
|
case 46:
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
console.error('[PaymentModule] 提交支付失败',
|
|
1143
|
-
this.logError('submitPayAsync failed',
|
|
1187
|
+
_context14.prev = 46;
|
|
1188
|
+
_context14.t1 = _context14["catch"](1);
|
|
1189
|
+
console.error('[PaymentModule] 提交支付失败', _context14.t1);
|
|
1190
|
+
this.logError('submitPayAsync failed', _context14.t1, {
|
|
1144
1191
|
orderUuid: orderUuid
|
|
1145
1192
|
});
|
|
1146
|
-
return
|
|
1193
|
+
return _context14.abrupt("return", {
|
|
1147
1194
|
status: 'failed'
|
|
1148
1195
|
});
|
|
1149
1196
|
case 51:
|
|
1150
1197
|
case "end":
|
|
1151
|
-
return
|
|
1198
|
+
return _context14.stop();
|
|
1152
1199
|
}
|
|
1153
|
-
},
|
|
1200
|
+
}, _callee14, this, [[1, 46], [14, 24, 27, 30]]);
|
|
1154
1201
|
}));
|
|
1155
|
-
function submitPayAsync(
|
|
1202
|
+
function submitPayAsync(_x18) {
|
|
1156
1203
|
return _submitPayAsync.apply(this, arguments);
|
|
1157
1204
|
}
|
|
1158
1205
|
return submitPayAsync;
|
|
@@ -1164,12 +1211,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1164
1211
|
}, {
|
|
1165
1212
|
key: "submitSingleOrderPayment",
|
|
1166
1213
|
value: (function () {
|
|
1167
|
-
var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1214
|
+
var _submitSingleOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(order) {
|
|
1168
1215
|
var paymentData, totalPaidAmount, orderTotalAmount;
|
|
1169
|
-
return _regeneratorRuntime().wrap(function
|
|
1170
|
-
while (1) switch (
|
|
1216
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1217
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1171
1218
|
case 0:
|
|
1172
|
-
|
|
1219
|
+
_context15.prev = 0;
|
|
1173
1220
|
paymentData = {
|
|
1174
1221
|
payments: order.payment.map(function (payment) {
|
|
1175
1222
|
return payment;
|
|
@@ -1195,35 +1242,35 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1195
1242
|
|
|
1196
1243
|
// 更新订单状态到数据库
|
|
1197
1244
|
// 注意:isSynced 保持为 false,直到网络同步成功后才设为 true
|
|
1198
|
-
|
|
1245
|
+
_context15.next = 8;
|
|
1199
1246
|
return this.dbManager.update('order', order);
|
|
1200
1247
|
case 8:
|
|
1201
|
-
|
|
1248
|
+
_context15.next = 10;
|
|
1202
1249
|
return this.addToSyncQueue(order, paymentData);
|
|
1203
1250
|
case 10:
|
|
1204
|
-
|
|
1251
|
+
_context15.next = 12;
|
|
1205
1252
|
return this.core.effects.emit(PaymentHooks.OnPaymentSubmitted, order);
|
|
1206
1253
|
case 12:
|
|
1207
|
-
|
|
1254
|
+
_context15.next = 14;
|
|
1208
1255
|
return this.core.effects.emit(PaymentHooks.OnOrderChanged, {
|
|
1209
1256
|
action: 'submit',
|
|
1210
1257
|
order: order
|
|
1211
1258
|
});
|
|
1212
1259
|
case 14:
|
|
1213
|
-
|
|
1260
|
+
_context15.next = 20;
|
|
1214
1261
|
break;
|
|
1215
1262
|
case 16:
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"),
|
|
1219
|
-
throw
|
|
1263
|
+
_context15.prev = 16;
|
|
1264
|
+
_context15.t0 = _context15["catch"](0);
|
|
1265
|
+
console.error("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u652F\u4ED8\u63D0\u4EA4\u5931\u8D25"), _context15.t0);
|
|
1266
|
+
throw _context15.t0;
|
|
1220
1267
|
case 20:
|
|
1221
1268
|
case "end":
|
|
1222
|
-
return
|
|
1269
|
+
return _context15.stop();
|
|
1223
1270
|
}
|
|
1224
|
-
},
|
|
1271
|
+
}, _callee15, this, [[0, 16]]);
|
|
1225
1272
|
}));
|
|
1226
|
-
function submitSingleOrderPayment(
|
|
1273
|
+
function submitSingleOrderPayment(_x19) {
|
|
1227
1274
|
return _submitSingleOrderPayment.apply(this, arguments);
|
|
1228
1275
|
}
|
|
1229
1276
|
return submitSingleOrderPayment;
|
|
@@ -1235,9 +1282,9 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1235
1282
|
}, {
|
|
1236
1283
|
key: "addToSyncQueue",
|
|
1237
1284
|
value: (function () {
|
|
1238
|
-
var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1239
|
-
return _regeneratorRuntime().wrap(function
|
|
1240
|
-
while (1) switch (
|
|
1285
|
+
var _addToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(order, paymentData) {
|
|
1286
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1287
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1241
1288
|
case 0:
|
|
1242
1289
|
try {
|
|
1243
1290
|
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
|
|
@@ -1269,11 +1316,11 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1269
1316
|
}
|
|
1270
1317
|
case 1:
|
|
1271
1318
|
case "end":
|
|
1272
|
-
return
|
|
1319
|
+
return _context16.stop();
|
|
1273
1320
|
}
|
|
1274
|
-
},
|
|
1321
|
+
}, _callee16, this);
|
|
1275
1322
|
}));
|
|
1276
|
-
function addToSyncQueue(
|
|
1323
|
+
function addToSyncQueue(_x20, _x21) {
|
|
1277
1324
|
return _addToSyncQueue.apply(this, arguments);
|
|
1278
1325
|
}
|
|
1279
1326
|
return addToSyncQueue;
|
|
@@ -1285,29 +1332,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1285
1332
|
}, {
|
|
1286
1333
|
key: "getRemainingOrderAmountAsync",
|
|
1287
1334
|
value: (function () {
|
|
1288
|
-
var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1335
|
+
var _getRemainingOrderAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderUuid) {
|
|
1289
1336
|
var order;
|
|
1290
|
-
return _regeneratorRuntime().wrap(function
|
|
1291
|
-
while (1) switch (
|
|
1337
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1338
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1292
1339
|
case 0:
|
|
1293
|
-
|
|
1340
|
+
_context17.next = 2;
|
|
1294
1341
|
return this.getOrderByUuidAsync(orderUuid);
|
|
1295
1342
|
case 2:
|
|
1296
|
-
order =
|
|
1343
|
+
order = _context17.sent;
|
|
1297
1344
|
if (order) {
|
|
1298
|
-
|
|
1345
|
+
_context17.next = 5;
|
|
1299
1346
|
break;
|
|
1300
1347
|
}
|
|
1301
1348
|
throw new Error('订单不存在');
|
|
1302
1349
|
case 5:
|
|
1303
|
-
return
|
|
1350
|
+
return _context17.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1304
1351
|
case 6:
|
|
1305
1352
|
case "end":
|
|
1306
|
-
return
|
|
1353
|
+
return _context17.stop();
|
|
1307
1354
|
}
|
|
1308
|
-
},
|
|
1355
|
+
}, _callee17, this);
|
|
1309
1356
|
}));
|
|
1310
|
-
function getRemainingOrderAmountAsync(
|
|
1357
|
+
function getRemainingOrderAmountAsync(_x22) {
|
|
1311
1358
|
return _getRemainingOrderAmountAsync.apply(this, arguments);
|
|
1312
1359
|
}
|
|
1313
1360
|
return getRemainingOrderAmountAsync;
|
|
@@ -1319,65 +1366,65 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1319
1366
|
}, {
|
|
1320
1367
|
key: "getRemainingOrderAmountWithInputAsync",
|
|
1321
1368
|
value: (function () {
|
|
1322
|
-
var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1369
|
+
var _getRemainingOrderAmountWithInputAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(inputAmount, orderUuid) {
|
|
1323
1370
|
var order, inputDecimal;
|
|
1324
|
-
return _regeneratorRuntime().wrap(function
|
|
1325
|
-
while (1) switch (
|
|
1371
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1372
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1326
1373
|
case 0:
|
|
1327
|
-
|
|
1374
|
+
_context18.next = 2;
|
|
1328
1375
|
return this.getOrderByUuidAsync(orderUuid);
|
|
1329
1376
|
case 2:
|
|
1330
|
-
order =
|
|
1377
|
+
order = _context18.sent;
|
|
1331
1378
|
if (order) {
|
|
1332
|
-
|
|
1379
|
+
_context18.next = 5;
|
|
1333
1380
|
break;
|
|
1334
1381
|
}
|
|
1335
1382
|
throw new Error('订单不存在');
|
|
1336
1383
|
case 5:
|
|
1337
1384
|
if (!(inputAmount === null || inputAmount === undefined)) {
|
|
1338
|
-
|
|
1385
|
+
_context18.next = 7;
|
|
1339
1386
|
break;
|
|
1340
1387
|
}
|
|
1341
|
-
return
|
|
1388
|
+
return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1342
1389
|
case 7:
|
|
1343
1390
|
if (!(typeof inputAmount === 'string')) {
|
|
1344
|
-
|
|
1391
|
+
_context18.next = 10;
|
|
1345
1392
|
break;
|
|
1346
1393
|
}
|
|
1347
1394
|
if (!(inputAmount.trim() === '')) {
|
|
1348
|
-
|
|
1395
|
+
_context18.next = 10;
|
|
1349
1396
|
break;
|
|
1350
1397
|
}
|
|
1351
|
-
return
|
|
1398
|
+
return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1352
1399
|
case 10:
|
|
1353
1400
|
if (!(typeof inputAmount === 'number')) {
|
|
1354
|
-
|
|
1401
|
+
_context18.next = 14;
|
|
1355
1402
|
break;
|
|
1356
1403
|
}
|
|
1357
1404
|
if (!(isNaN(inputAmount) || !isFinite(inputAmount))) {
|
|
1358
|
-
|
|
1405
|
+
_context18.next = 14;
|
|
1359
1406
|
break;
|
|
1360
1407
|
}
|
|
1361
1408
|
// 如果输入是 NaN 或无穷大,返回原始的待付金额
|
|
1362
1409
|
console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u4E0D\u662F\u6709\u6548\u6570\u5B57: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
|
|
1363
|
-
return
|
|
1410
|
+
return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1364
1411
|
case 14:
|
|
1365
|
-
|
|
1412
|
+
_context18.prev = 14;
|
|
1366
1413
|
inputDecimal = new Decimal(inputAmount);
|
|
1367
|
-
return
|
|
1414
|
+
return _context18.abrupt("return", new Decimal(order.expect_amount).minus(inputDecimal).toNumber());
|
|
1368
1415
|
case 19:
|
|
1369
|
-
|
|
1370
|
-
|
|
1416
|
+
_context18.prev = 19;
|
|
1417
|
+
_context18.t0 = _context18["catch"](14);
|
|
1371
1418
|
// 如果输入不是有效的数字,返回原始的待付金额
|
|
1372
1419
|
console.warn("[PaymentModule] \u8F93\u5165\u91D1\u989D\u683C\u5F0F\u65E0\u6548: ".concat(inputAmount, "\uFF0C\u8FD4\u56DE\u539F\u59CB\u5F85\u4ED8\u91D1\u989D"));
|
|
1373
|
-
return
|
|
1420
|
+
return _context18.abrupt("return", new Decimal(order.expect_amount).toNumber());
|
|
1374
1421
|
case 23:
|
|
1375
1422
|
case "end":
|
|
1376
|
-
return
|
|
1423
|
+
return _context18.stop();
|
|
1377
1424
|
}
|
|
1378
|
-
},
|
|
1425
|
+
}, _callee18, this, [[14, 19]]);
|
|
1379
1426
|
}));
|
|
1380
|
-
function getRemainingOrderAmountWithInputAsync(
|
|
1427
|
+
function getRemainingOrderAmountWithInputAsync(_x23, _x24) {
|
|
1381
1428
|
return _getRemainingOrderAmountWithInputAsync.apply(this, arguments);
|
|
1382
1429
|
}
|
|
1383
1430
|
return getRemainingOrderAmountWithInputAsync;
|
|
@@ -1403,29 +1450,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1403
1450
|
}, {
|
|
1404
1451
|
key: "getCashPaymentMethod",
|
|
1405
1452
|
value: (function () {
|
|
1406
|
-
var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1453
|
+
var _getCashPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
1407
1454
|
var payMethods;
|
|
1408
|
-
return _regeneratorRuntime().wrap(function
|
|
1409
|
-
while (1) switch (
|
|
1455
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1456
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1410
1457
|
case 0:
|
|
1411
|
-
|
|
1412
|
-
|
|
1458
|
+
_context19.prev = 0;
|
|
1459
|
+
_context19.next = 3;
|
|
1413
1460
|
return this.dbManager.getAll('pay_method');
|
|
1414
1461
|
case 3:
|
|
1415
|
-
payMethods =
|
|
1416
|
-
return
|
|
1462
|
+
payMethods = _context19.sent;
|
|
1463
|
+
return _context19.abrupt("return", payMethods.find(function (method) {
|
|
1417
1464
|
return method.code === PaymentMethodType.Cash;
|
|
1418
1465
|
}) || null);
|
|
1419
1466
|
case 7:
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
console.error('[PaymentModule] 获取现金支付方式失败',
|
|
1423
|
-
return
|
|
1467
|
+
_context19.prev = 7;
|
|
1468
|
+
_context19.t0 = _context19["catch"](0);
|
|
1469
|
+
console.error('[PaymentModule] 获取现金支付方式失败', _context19.t0);
|
|
1470
|
+
return _context19.abrupt("return", null);
|
|
1424
1471
|
case 11:
|
|
1425
1472
|
case "end":
|
|
1426
|
-
return
|
|
1473
|
+
return _context19.stop();
|
|
1427
1474
|
}
|
|
1428
|
-
},
|
|
1475
|
+
}, _callee19, this, [[0, 7]]);
|
|
1429
1476
|
}));
|
|
1430
1477
|
function getCashPaymentMethod() {
|
|
1431
1478
|
return _getCashPaymentMethod.apply(this, arguments);
|
|
@@ -1439,29 +1486,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1439
1486
|
}, {
|
|
1440
1487
|
key: "getEftposPaymentMethod",
|
|
1441
1488
|
value: (function () {
|
|
1442
|
-
var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1489
|
+
var _getEftposPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
1443
1490
|
var payMethods;
|
|
1444
|
-
return _regeneratorRuntime().wrap(function
|
|
1445
|
-
while (1) switch (
|
|
1491
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1492
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1446
1493
|
case 0:
|
|
1447
|
-
|
|
1448
|
-
|
|
1494
|
+
_context20.prev = 0;
|
|
1495
|
+
_context20.next = 3;
|
|
1449
1496
|
return this.dbManager.getAll('pay_method');
|
|
1450
1497
|
case 3:
|
|
1451
|
-
payMethods =
|
|
1452
|
-
return
|
|
1498
|
+
payMethods = _context20.sent;
|
|
1499
|
+
return _context20.abrupt("return", payMethods.find(function (method) {
|
|
1453
1500
|
return method.code === PaymentMethodType.Eftpos;
|
|
1454
1501
|
}) || null);
|
|
1455
1502
|
case 7:
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
console.error('[PaymentModule] 获取Eftpos支付方式失败',
|
|
1459
|
-
return
|
|
1503
|
+
_context20.prev = 7;
|
|
1504
|
+
_context20.t0 = _context20["catch"](0);
|
|
1505
|
+
console.error('[PaymentModule] 获取Eftpos支付方式失败', _context20.t0);
|
|
1506
|
+
return _context20.abrupt("return", null);
|
|
1460
1507
|
case 11:
|
|
1461
1508
|
case "end":
|
|
1462
|
-
return
|
|
1509
|
+
return _context20.stop();
|
|
1463
1510
|
}
|
|
1464
|
-
},
|
|
1511
|
+
}, _callee20, this, [[0, 7]]);
|
|
1465
1512
|
}));
|
|
1466
1513
|
function getEftposPaymentMethod() {
|
|
1467
1514
|
return _getEftposPaymentMethod.apply(this, arguments);
|
|
@@ -1475,29 +1522,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1475
1522
|
}, {
|
|
1476
1523
|
key: "getWalletPaymentMethod",
|
|
1477
1524
|
value: (function () {
|
|
1478
|
-
var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1525
|
+
var _getWalletPaymentMethod = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
1479
1526
|
var payMethods;
|
|
1480
|
-
return _regeneratorRuntime().wrap(function
|
|
1481
|
-
while (1) switch (
|
|
1527
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1528
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1482
1529
|
case 0:
|
|
1483
|
-
|
|
1484
|
-
|
|
1530
|
+
_context21.prev = 0;
|
|
1531
|
+
_context21.next = 3;
|
|
1485
1532
|
return this.dbManager.getAll('pay_method');
|
|
1486
1533
|
case 3:
|
|
1487
|
-
payMethods =
|
|
1488
|
-
return
|
|
1534
|
+
payMethods = _context21.sent;
|
|
1535
|
+
return _context21.abrupt("return", payMethods.find(function (method) {
|
|
1489
1536
|
return method.code === PaymentMethodType.Wallet;
|
|
1490
1537
|
}) || null);
|
|
1491
1538
|
case 7:
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
console.error('[PaymentModule] 获取钱包支付方式失败',
|
|
1495
|
-
return
|
|
1539
|
+
_context21.prev = 7;
|
|
1540
|
+
_context21.t0 = _context21["catch"](0);
|
|
1541
|
+
console.error('[PaymentModule] 获取钱包支付方式失败', _context21.t0);
|
|
1542
|
+
return _context21.abrupt("return", null);
|
|
1496
1543
|
case 11:
|
|
1497
1544
|
case "end":
|
|
1498
|
-
return
|
|
1545
|
+
return _context21.stop();
|
|
1499
1546
|
}
|
|
1500
|
-
},
|
|
1547
|
+
}, _callee21, this, [[0, 7]]);
|
|
1501
1548
|
}));
|
|
1502
1549
|
function getWalletPaymentMethod() {
|
|
1503
1550
|
return _getWalletPaymentMethod.apply(this, arguments);
|
|
@@ -1531,38 +1578,38 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1531
1578
|
* 确保支付模块所需的数据库表已创建
|
|
1532
1579
|
*/
|
|
1533
1580
|
function () {
|
|
1534
|
-
var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1535
|
-
return _regeneratorRuntime().wrap(function
|
|
1536
|
-
while (1) switch (
|
|
1581
|
+
var _ensurePaymentTables = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
|
|
1582
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1583
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1537
1584
|
case 0:
|
|
1538
|
-
|
|
1539
|
-
|
|
1585
|
+
_context22.prev = 0;
|
|
1586
|
+
_context22.next = 3;
|
|
1540
1587
|
return this.dbManager.getAll('pay_method');
|
|
1541
1588
|
case 3:
|
|
1542
|
-
|
|
1589
|
+
_context22.next = 9;
|
|
1543
1590
|
break;
|
|
1544
1591
|
case 5:
|
|
1545
|
-
|
|
1546
|
-
|
|
1592
|
+
_context22.prev = 5;
|
|
1593
|
+
_context22.t0 = _context22["catch"](0);
|
|
1547
1594
|
console.warn('[PaymentModule] pay_method 表不存在,请在数据库配置中添加以下配置:');
|
|
1548
1595
|
console.warn('{ name: "pay_method", keyPath: "id" }');
|
|
1549
1596
|
case 9:
|
|
1550
|
-
|
|
1551
|
-
|
|
1597
|
+
_context22.prev = 9;
|
|
1598
|
+
_context22.next = 12;
|
|
1552
1599
|
return this.dbManager.getAll('order');
|
|
1553
1600
|
case 12:
|
|
1554
|
-
|
|
1601
|
+
_context22.next = 18;
|
|
1555
1602
|
break;
|
|
1556
1603
|
case 14:
|
|
1557
|
-
|
|
1558
|
-
|
|
1604
|
+
_context22.prev = 14;
|
|
1605
|
+
_context22.t1 = _context22["catch"](9);
|
|
1559
1606
|
console.warn('[PaymentModule] order 表不存在,请在数据库配置中添加以下配置:');
|
|
1560
1607
|
console.warn('{ name: "order", keyPath: "uuid" }');
|
|
1561
1608
|
case 18:
|
|
1562
1609
|
case "end":
|
|
1563
|
-
return
|
|
1610
|
+
return _context22.stop();
|
|
1564
1611
|
}
|
|
1565
|
-
},
|
|
1612
|
+
}, _callee22, this, [[0, 5], [9, 14]]);
|
|
1566
1613
|
}));
|
|
1567
1614
|
function ensurePaymentTables() {
|
|
1568
1615
|
return _ensurePaymentTables.apply(this, arguments);
|
|
@@ -1576,29 +1623,29 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1576
1623
|
}, {
|
|
1577
1624
|
key: "getPartiallyPaidOrdersAsync",
|
|
1578
1625
|
value: (function () {
|
|
1579
|
-
var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1626
|
+
var _getPartiallyPaidOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
1580
1627
|
var allOrders;
|
|
1581
|
-
return _regeneratorRuntime().wrap(function
|
|
1582
|
-
while (1) switch (
|
|
1628
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1629
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1583
1630
|
case 0:
|
|
1584
|
-
|
|
1585
|
-
|
|
1631
|
+
_context23.prev = 0;
|
|
1632
|
+
_context23.next = 3;
|
|
1586
1633
|
return this.dbManager.getAll('order');
|
|
1587
1634
|
case 3:
|
|
1588
|
-
allOrders =
|
|
1589
|
-
return
|
|
1635
|
+
allOrders = _context23.sent;
|
|
1636
|
+
return _context23.abrupt("return", allOrders.filter(function (order) {
|
|
1590
1637
|
return order.payment_status === PaymentStatus.PartiallyPaid;
|
|
1591
1638
|
}));
|
|
1592
1639
|
case 7:
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
console.error('[PaymentModule] 获取部分支付订单失败',
|
|
1596
|
-
return
|
|
1640
|
+
_context23.prev = 7;
|
|
1641
|
+
_context23.t0 = _context23["catch"](0);
|
|
1642
|
+
console.error('[PaymentModule] 获取部分支付订单失败', _context23.t0);
|
|
1643
|
+
return _context23.abrupt("return", []);
|
|
1597
1644
|
case 11:
|
|
1598
1645
|
case "end":
|
|
1599
|
-
return
|
|
1646
|
+
return _context23.stop();
|
|
1600
1647
|
}
|
|
1601
|
-
},
|
|
1648
|
+
}, _callee23, this, [[0, 7]]);
|
|
1602
1649
|
}));
|
|
1603
1650
|
function getPartiallyPaidOrdersAsync() {
|
|
1604
1651
|
return _getPartiallyPaidOrdersAsync.apply(this, arguments);
|
|
@@ -1612,32 +1659,32 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1612
1659
|
}, {
|
|
1613
1660
|
key: "getUnsyncedOrdersAsync",
|
|
1614
1661
|
value: (function () {
|
|
1615
|
-
var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1662
|
+
var _getUnsyncedOrdersAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
1616
1663
|
var allOrders;
|
|
1617
|
-
return _regeneratorRuntime().wrap(function
|
|
1618
|
-
while (1) switch (
|
|
1664
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1665
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1619
1666
|
case 0:
|
|
1620
|
-
|
|
1621
|
-
|
|
1667
|
+
_context24.prev = 0;
|
|
1668
|
+
_context24.next = 3;
|
|
1622
1669
|
return this.dbManager.getAll('order');
|
|
1623
1670
|
case 3:
|
|
1624
|
-
allOrders =
|
|
1625
|
-
return
|
|
1671
|
+
allOrders = _context24.sent;
|
|
1672
|
+
return _context24.abrupt("return", allOrders.filter(function (order) {
|
|
1626
1673
|
// 订单已完成或部分支付,但支付项还未同步
|
|
1627
1674
|
return (order.payment_status === PaymentStatus.Finished || order.payment_status === PaymentStatus.PartiallyPaid) && order.payment.some(function (payment) {
|
|
1628
1675
|
return !payment.isSynced;
|
|
1629
1676
|
});
|
|
1630
1677
|
}));
|
|
1631
1678
|
case 7:
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
console.error('[PaymentModule] 获取未同步订单失败',
|
|
1635
|
-
return
|
|
1679
|
+
_context24.prev = 7;
|
|
1680
|
+
_context24.t0 = _context24["catch"](0);
|
|
1681
|
+
console.error('[PaymentModule] 获取未同步订单失败', _context24.t0);
|
|
1682
|
+
return _context24.abrupt("return", []);
|
|
1636
1683
|
case 11:
|
|
1637
1684
|
case "end":
|
|
1638
|
-
return
|
|
1685
|
+
return _context24.stop();
|
|
1639
1686
|
}
|
|
1640
|
-
},
|
|
1687
|
+
}, _callee24, this, [[0, 7]]);
|
|
1641
1688
|
}));
|
|
1642
1689
|
function getUnsyncedOrdersAsync() {
|
|
1643
1690
|
return _getUnsyncedOrdersAsync.apply(this, arguments);
|
|
@@ -1652,90 +1699,225 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1652
1699
|
}, {
|
|
1653
1700
|
key: "cleanupFinishedOrders",
|
|
1654
1701
|
value: (function () {
|
|
1655
|
-
var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1702
|
+
var _cleanupFinishedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1656
1703
|
var allOrders, finishedAndSyncedOrders, _iterator6, _step6, order;
|
|
1657
|
-
return _regeneratorRuntime().wrap(function
|
|
1658
|
-
while (1) switch (
|
|
1704
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1705
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1659
1706
|
case 0:
|
|
1660
|
-
|
|
1661
|
-
|
|
1707
|
+
_context25.prev = 0;
|
|
1708
|
+
_context25.next = 3;
|
|
1662
1709
|
return this.dbManager.getAll('order');
|
|
1663
1710
|
case 3:
|
|
1664
|
-
allOrders =
|
|
1711
|
+
allOrders = _context25.sent;
|
|
1665
1712
|
finishedAndSyncedOrders = allOrders.filter(function (order) {
|
|
1666
1713
|
return order.payment_status === PaymentStatus.Finished && order.payment.every(function (payment) {
|
|
1667
1714
|
return payment.isSynced;
|
|
1668
1715
|
});
|
|
1669
1716
|
});
|
|
1670
1717
|
_iterator6 = _createForOfIteratorHelper(finishedAndSyncedOrders);
|
|
1671
|
-
|
|
1718
|
+
_context25.prev = 6;
|
|
1672
1719
|
_iterator6.s();
|
|
1673
1720
|
case 8:
|
|
1674
1721
|
if ((_step6 = _iterator6.n()).done) {
|
|
1675
|
-
|
|
1722
|
+
_context25.next = 14;
|
|
1676
1723
|
break;
|
|
1677
1724
|
}
|
|
1678
1725
|
order = _step6.value;
|
|
1679
|
-
|
|
1726
|
+
_context25.next = 12;
|
|
1680
1727
|
return this.deleteOrderAsync(order.uuid);
|
|
1681
1728
|
case 12:
|
|
1682
|
-
|
|
1729
|
+
_context25.next = 8;
|
|
1683
1730
|
break;
|
|
1684
1731
|
case 14:
|
|
1685
|
-
|
|
1732
|
+
_context25.next = 19;
|
|
1686
1733
|
break;
|
|
1687
1734
|
case 16:
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
_iterator6.e(
|
|
1735
|
+
_context25.prev = 16;
|
|
1736
|
+
_context25.t0 = _context25["catch"](6);
|
|
1737
|
+
_iterator6.e(_context25.t0);
|
|
1691
1738
|
case 19:
|
|
1692
|
-
|
|
1739
|
+
_context25.prev = 19;
|
|
1693
1740
|
_iterator6.f();
|
|
1694
|
-
return
|
|
1741
|
+
return _context25.finish(19);
|
|
1695
1742
|
case 22:
|
|
1696
1743
|
console.log("[PaymentModule] \u6E05\u7406\u4E86 ".concat(finishedAndSyncedOrders.length, " \u4E2A\u5DF2\u5B8C\u6210\u4E14\u5DF2\u540C\u6B65\u7684\u8BA2\u5355"));
|
|
1697
|
-
|
|
1744
|
+
_context25.next = 28;
|
|
1698
1745
|
break;
|
|
1699
1746
|
case 25:
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
console.error('[PaymentModule] 清理已完成订单失败',
|
|
1747
|
+
_context25.prev = 25;
|
|
1748
|
+
_context25.t1 = _context25["catch"](0);
|
|
1749
|
+
console.error('[PaymentModule] 清理已完成订单失败', _context25.t1);
|
|
1703
1750
|
case 28:
|
|
1704
1751
|
case "end":
|
|
1705
|
-
return
|
|
1752
|
+
return _context25.stop();
|
|
1706
1753
|
}
|
|
1707
|
-
},
|
|
1754
|
+
}, _callee25, this, [[0, 25], [6, 16, 19, 22]]);
|
|
1708
1755
|
}));
|
|
1709
1756
|
function cleanupFinishedOrders() {
|
|
1710
1757
|
return _cleanupFinishedOrders.apply(this, arguments);
|
|
1711
1758
|
}
|
|
1712
1759
|
return cleanupFinishedOrders;
|
|
1713
1760
|
}()
|
|
1761
|
+
/**
|
|
1762
|
+
* 检测未同步的订单并重新加入任务队列
|
|
1763
|
+
*
|
|
1764
|
+
* 此方法专门用于处理因网络问题导致任务队列执行失败但队列被清空的情况。
|
|
1765
|
+
* 它会检查本地 IndexDB 中所有未同步的订单(isSynced: false),
|
|
1766
|
+
* 并将这些订单重新添加到任务队列中。
|
|
1767
|
+
*
|
|
1768
|
+
* 使用场景:
|
|
1769
|
+
* - 网络恢复后重新检查未同步的订单
|
|
1770
|
+
* - 应用启动时检查并重新排队未完成的支付
|
|
1771
|
+
* - 用户手动重试前的预检查
|
|
1772
|
+
*
|
|
1773
|
+
* @returns Promise<number> 返回重新加入队列的订单数量
|
|
1774
|
+
*/
|
|
1775
|
+
)
|
|
1776
|
+
}, {
|
|
1777
|
+
key: "recheckAndRequeueUnsyncedOrders",
|
|
1778
|
+
value: (function () {
|
|
1779
|
+
var _recheckAndRequeueUnsyncedOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
1780
|
+
var unsyncedOrders, requeuedCount, _iterator7, _step7, order, success;
|
|
1781
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1782
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1783
|
+
case 0:
|
|
1784
|
+
this.logInfo('Starting recheckAndRequeueUnsyncedOrders');
|
|
1785
|
+
_context26.prev = 1;
|
|
1786
|
+
if (this.app.tasksManager) {
|
|
1787
|
+
_context26.next = 6;
|
|
1788
|
+
break;
|
|
1789
|
+
}
|
|
1790
|
+
console.warn('[PaymentModule] TasksManager 未初始化,无法重新排队未同步订单');
|
|
1791
|
+
this.logWarning('TasksManager not initialized, cannot requeue unsynced orders');
|
|
1792
|
+
return _context26.abrupt("return", 0);
|
|
1793
|
+
case 6:
|
|
1794
|
+
_context26.next = 8;
|
|
1795
|
+
return this.getUnsyncedOrdersAsync();
|
|
1796
|
+
case 8:
|
|
1797
|
+
unsyncedOrders = _context26.sent;
|
|
1798
|
+
if (!(unsyncedOrders.length === 0)) {
|
|
1799
|
+
_context26.next = 13;
|
|
1800
|
+
break;
|
|
1801
|
+
}
|
|
1802
|
+
console.log('[PaymentModule] 没有发现未同步的订单');
|
|
1803
|
+
this.logInfo('No unsynced orders found');
|
|
1804
|
+
return _context26.abrupt("return", 0);
|
|
1805
|
+
case 13:
|
|
1806
|
+
console.log("[PaymentModule] \u53D1\u73B0 ".concat(unsyncedOrders.length, " \u4E2A\u672A\u540C\u6B65\u7684\u8BA2\u5355\uFF0C\u5F00\u59CB\u91CD\u65B0\u52A0\u5165\u4EFB\u52A1\u961F\u5217"));
|
|
1807
|
+
this.logInfo('Found unsynced orders, adding to sync queue', {
|
|
1808
|
+
unsyncedCount: unsyncedOrders.length,
|
|
1809
|
+
orderUuids: unsyncedOrders.map(function (o) {
|
|
1810
|
+
return o.uuid;
|
|
1811
|
+
})
|
|
1812
|
+
});
|
|
1813
|
+
requeuedCount = 0; // 将未同步的订单重新添加到任务队列
|
|
1814
|
+
_iterator7 = _createForOfIteratorHelper(unsyncedOrders);
|
|
1815
|
+
_context26.prev = 17;
|
|
1816
|
+
_iterator7.s();
|
|
1817
|
+
case 19:
|
|
1818
|
+
if ((_step7 = _iterator7.n()).done) {
|
|
1819
|
+
_context26.next = 27;
|
|
1820
|
+
break;
|
|
1821
|
+
}
|
|
1822
|
+
order = _step7.value;
|
|
1823
|
+
_context26.next = 23;
|
|
1824
|
+
return this.reAddOrderToSyncQueue(order);
|
|
1825
|
+
case 23:
|
|
1826
|
+
success = _context26.sent;
|
|
1827
|
+
if (success) {
|
|
1828
|
+
requeuedCount++;
|
|
1829
|
+
}
|
|
1830
|
+
case 25:
|
|
1831
|
+
_context26.next = 19;
|
|
1832
|
+
break;
|
|
1833
|
+
case 27:
|
|
1834
|
+
_context26.next = 32;
|
|
1835
|
+
break;
|
|
1836
|
+
case 29:
|
|
1837
|
+
_context26.prev = 29;
|
|
1838
|
+
_context26.t0 = _context26["catch"](17);
|
|
1839
|
+
_iterator7.e(_context26.t0);
|
|
1840
|
+
case 32:
|
|
1841
|
+
_context26.prev = 32;
|
|
1842
|
+
_iterator7.f();
|
|
1843
|
+
return _context26.finish(32);
|
|
1844
|
+
case 35:
|
|
1845
|
+
console.log("[PaymentModule] \u6210\u529F\u91CD\u65B0\u52A0\u5165 ".concat(requeuedCount, " \u4E2A\u8BA2\u5355\u5230\u4EFB\u52A1\u961F\u5217"));
|
|
1846
|
+
this.logInfo('Successfully requeued unsynced orders', {
|
|
1847
|
+
requeuedCount: requeuedCount,
|
|
1848
|
+
totalFound: unsyncedOrders.length
|
|
1849
|
+
});
|
|
1850
|
+
return _context26.abrupt("return", requeuedCount);
|
|
1851
|
+
case 40:
|
|
1852
|
+
_context26.prev = 40;
|
|
1853
|
+
_context26.t1 = _context26["catch"](1);
|
|
1854
|
+
console.error('[PaymentModule] 重新排队未同步订单失败', _context26.t1);
|
|
1855
|
+
this.logError('recheckAndRequeueUnsyncedOrders failed', _context26.t1);
|
|
1856
|
+
return _context26.abrupt("return", 0);
|
|
1857
|
+
case 45:
|
|
1858
|
+
case "end":
|
|
1859
|
+
return _context26.stop();
|
|
1860
|
+
}
|
|
1861
|
+
}, _callee26, this, [[1, 40], [17, 29, 32, 35]]);
|
|
1862
|
+
}));
|
|
1863
|
+
function recheckAndRequeueUnsyncedOrders() {
|
|
1864
|
+
return _recheckAndRequeueUnsyncedOrders.apply(this, arguments);
|
|
1865
|
+
}
|
|
1866
|
+
return recheckAndRequeueUnsyncedOrders;
|
|
1867
|
+
}()
|
|
1714
1868
|
/**
|
|
1715
1869
|
* 手动执行支付同步队列
|
|
1716
1870
|
* 外部可以调用此方法来触发支付同步任务的执行
|
|
1871
|
+
*
|
|
1872
|
+
* 注意:此方法只执行现有队列中的任务,不会检查未同步的订单。
|
|
1873
|
+
* 如果需要检查未同步订单,请先调用 recheckAndRequeueUnsyncedOrders()
|
|
1874
|
+
*
|
|
1875
|
+
* 使用示例:
|
|
1876
|
+
* ```typescript
|
|
1877
|
+
* // 1. 先检查并重新排队未同步订单,然后执行队列
|
|
1878
|
+
* const requeuedCount = await paymentModule.recheckAndRequeueUnsyncedOrders();
|
|
1879
|
+
* if (requeuedCount > 0) {
|
|
1880
|
+
* await paymentModule.runPaymentSyncQueue();
|
|
1881
|
+
* }
|
|
1882
|
+
*
|
|
1883
|
+
* // 2. 或者直接执行现有队列(不检查未同步订单)
|
|
1884
|
+
* await paymentModule.runPaymentSyncQueue();
|
|
1885
|
+
* ```
|
|
1717
1886
|
*/
|
|
1718
1887
|
)
|
|
1719
1888
|
}, {
|
|
1720
1889
|
key: "runPaymentSyncQueue",
|
|
1721
1890
|
value: (function () {
|
|
1722
|
-
var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1891
|
+
var _runPaymentSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
1723
1892
|
var _this3 = this;
|
|
1724
|
-
|
|
1725
|
-
|
|
1893
|
+
var queue;
|
|
1894
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1895
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
1726
1896
|
case 0:
|
|
1727
1897
|
this.logInfo('Starting runPaymentSyncQueue');
|
|
1728
|
-
|
|
1898
|
+
_context27.prev = 1;
|
|
1729
1899
|
if (this.app.tasksManager) {
|
|
1730
|
-
|
|
1900
|
+
_context27.next = 6;
|
|
1731
1901
|
break;
|
|
1732
1902
|
}
|
|
1733
1903
|
console.warn('[PaymentModule] TasksManager 未初始化,无法执行同步队列');
|
|
1734
1904
|
this.logWarning('TasksManager not initialized, cannot run sync queue');
|
|
1735
|
-
return
|
|
1905
|
+
return _context27.abrupt("return");
|
|
1736
1906
|
case 6:
|
|
1907
|
+
// 检查队列里有没有要跑的东西,没有就不 run 了
|
|
1908
|
+
queue = this.app.tasksManager.getTaskQueue({
|
|
1909
|
+
module: 'payment',
|
|
1910
|
+
queueId: 'payment_sync'
|
|
1911
|
+
});
|
|
1912
|
+
if (queue !== null && queue !== void 0 && queue.length) {
|
|
1913
|
+
_context27.next = 10;
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
console.log('[PaymentModule] 支付同步队列无内容,不执行');
|
|
1917
|
+
return _context27.abrupt("return");
|
|
1918
|
+
case 10:
|
|
1737
1919
|
console.log('[PaymentModule] 开始执行支付同步队列');
|
|
1738
|
-
|
|
1920
|
+
_context27.next = 13;
|
|
1739
1921
|
return this.app.tasksManager.run({
|
|
1740
1922
|
module: 'payment',
|
|
1741
1923
|
queueId: 'payment_sync',
|
|
@@ -1750,38 +1932,113 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1750
1932
|
}
|
|
1751
1933
|
}
|
|
1752
1934
|
});
|
|
1753
|
-
case
|
|
1935
|
+
case 13:
|
|
1754
1936
|
this.logInfo('runPaymentSyncQueue completed successfully');
|
|
1755
|
-
|
|
1937
|
+
_context27.next = 20;
|
|
1756
1938
|
break;
|
|
1757
|
-
case 12:
|
|
1758
|
-
_context25.prev = 12;
|
|
1759
|
-
_context25.t0 = _context25["catch"](1);
|
|
1760
|
-
console.error('[PaymentModule] 执行支付同步队列失败', _context25.t0);
|
|
1761
|
-
this.logError('runPaymentSyncQueue failed', _context25.t0);
|
|
1762
|
-
// 不抛出错误,避免影响主流程
|
|
1763
1939
|
case 16:
|
|
1940
|
+
_context27.prev = 16;
|
|
1941
|
+
_context27.t0 = _context27["catch"](1);
|
|
1942
|
+
console.error('[PaymentModule] 执行支付同步队列失败', _context27.t0);
|
|
1943
|
+
this.logError('runPaymentSyncQueue failed', _context27.t0);
|
|
1944
|
+
// 不抛出错误,避免影响主流程
|
|
1945
|
+
case 20:
|
|
1764
1946
|
case "end":
|
|
1765
|
-
return
|
|
1947
|
+
return _context27.stop();
|
|
1766
1948
|
}
|
|
1767
|
-
},
|
|
1949
|
+
}, _callee27, this, [[1, 16]]);
|
|
1768
1950
|
}));
|
|
1769
1951
|
function runPaymentSyncQueue() {
|
|
1770
1952
|
return _runPaymentSyncQueue.apply(this, arguments);
|
|
1771
1953
|
}
|
|
1772
1954
|
return runPaymentSyncQueue;
|
|
1955
|
+
}()
|
|
1956
|
+
/**
|
|
1957
|
+
* 重新将订单添加到同步队列
|
|
1958
|
+
* 用于处理因网络问题导致任务队列清空但订单未同步的情况
|
|
1959
|
+
*
|
|
1960
|
+
* @param order 要重新添加的订单
|
|
1961
|
+
* @returns Promise<boolean> 是否成功添加到队列
|
|
1962
|
+
*/
|
|
1963
|
+
)
|
|
1964
|
+
}, {
|
|
1965
|
+
key: "reAddOrderToSyncQueue",
|
|
1966
|
+
value: (function () {
|
|
1967
|
+
var _reAddOrderToSyncQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order) {
|
|
1968
|
+
var paymentData, existingQueue, taskId, taskExists;
|
|
1969
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1970
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
1971
|
+
case 0:
|
|
1972
|
+
_context28.prev = 0;
|
|
1973
|
+
// 构造支付数据
|
|
1974
|
+
paymentData = {
|
|
1975
|
+
payments: order.payment.map(function (payment) {
|
|
1976
|
+
return payment;
|
|
1977
|
+
}),
|
|
1978
|
+
payment_status: order.payment_status === PaymentStatus.Finished ? 'paid' : 'partially_paid'
|
|
1979
|
+
}; // 检查是否已经在队列中,避免重复添加
|
|
1980
|
+
existingQueue = this.app.tasksManager.getTaskQueue({
|
|
1981
|
+
module: 'payment',
|
|
1982
|
+
queueId: 'payment_sync'
|
|
1983
|
+
});
|
|
1984
|
+
taskId = "payment_".concat(order.uuid);
|
|
1985
|
+
taskExists = existingQueue === null || existingQueue === void 0 ? void 0 : existingQueue.some(function (task) {
|
|
1986
|
+
return task.id === taskId;
|
|
1987
|
+
});
|
|
1988
|
+
if (!taskExists) {
|
|
1989
|
+
_context28.next = 8;
|
|
1990
|
+
break;
|
|
1991
|
+
}
|
|
1992
|
+
console.log("[PaymentModule] \u4EFB\u52A1 ".concat(taskId, " \u5DF2\u5B58\u5728\u4E8E\u961F\u5217\u4E2D\uFF0C\u8DF3\u8FC7\u91CD\u590D\u6DFB\u52A0"));
|
|
1993
|
+
return _context28.abrupt("return", false);
|
|
1994
|
+
case 8:
|
|
1995
|
+
_context28.next = 10;
|
|
1996
|
+
return this.addToSyncQueue(order, paymentData);
|
|
1997
|
+
case 10:
|
|
1998
|
+
console.log("[PaymentModule] \u8BA2\u5355 ".concat(order.uuid, " \u5DF2\u91CD\u65B0\u6DFB\u52A0\u5230\u540C\u6B65\u961F\u5217"));
|
|
1999
|
+
this.logInfo('Order re-added to sync queue', {
|
|
2000
|
+
orderUuid: order.uuid,
|
|
2001
|
+
orderId: order.order_info.order_id,
|
|
2002
|
+
paymentStatus: order.payment_status,
|
|
2003
|
+
unsyncedPayments: order.payment.filter(function (p) {
|
|
2004
|
+
return !p.isSynced;
|
|
2005
|
+
}).length
|
|
2006
|
+
});
|
|
2007
|
+
return _context28.abrupt("return", true);
|
|
2008
|
+
case 15:
|
|
2009
|
+
_context28.prev = 15;
|
|
2010
|
+
_context28.t0 = _context28["catch"](0);
|
|
2011
|
+
console.error("[PaymentModule] \u91CD\u65B0\u6DFB\u52A0\u8BA2\u5355 ".concat(order.uuid, " \u5230\u540C\u6B65\u961F\u5217\u5931\u8D25"), _context28.t0);
|
|
2012
|
+
this.logError('Failed to re-add order to sync queue', _context28.t0, {
|
|
2013
|
+
orderUuid: order.uuid,
|
|
2014
|
+
orderId: order.order_info.order_id
|
|
2015
|
+
});
|
|
2016
|
+
return _context28.abrupt("return", false);
|
|
2017
|
+
case 20:
|
|
2018
|
+
case "end":
|
|
2019
|
+
return _context28.stop();
|
|
2020
|
+
}
|
|
2021
|
+
}, _callee28, this, [[0, 15]]);
|
|
2022
|
+
}));
|
|
2023
|
+
function reAddOrderToSyncQueue(_x25) {
|
|
2024
|
+
return _reAddOrderToSyncQueue.apply(this, arguments);
|
|
2025
|
+
}
|
|
2026
|
+
return reAddOrderToSyncQueue;
|
|
1773
2027
|
}())
|
|
1774
2028
|
}], [{
|
|
1775
2029
|
key: "syncPaymentTask",
|
|
1776
2030
|
value: (function () {
|
|
1777
|
-
var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2031
|
+
var _syncPaymentTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(payload) {
|
|
1778
2032
|
var _payload$task$payload, orderUuid, orderId, paymentData, core, app, logger, request, dbManager, requestRes, order, businessError, _error$message, _error$message2, _error$message3, isNetworkError, _error$response3, _error$response, errorData, _error$response2, _order2;
|
|
1779
|
-
return _regeneratorRuntime().wrap(function
|
|
1780
|
-
while (1) switch (
|
|
2033
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
2034
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1781
2035
|
case 0:
|
|
1782
2036
|
_payload$task$payload = payload.task.payload, orderUuid = _payload$task$payload.orderUuid, orderId = _payload$task$payload.orderId, paymentData = _payload$task$payload.paymentData, core = _payload$task$payload.core;
|
|
1783
2037
|
console.log("[PaymentModule] \u5F00\u59CB\u540E\u53F0\u540C\u6B65\u652F\u4ED8\uFF0C\u8BA2\u5355ID: ".concat(orderId));
|
|
1784
2038
|
|
|
2039
|
+
// 生成request_unique: 年月日时分秒毫秒+4位随机数
|
|
2040
|
+
paymentData.request_unique = generateRequestUniqueId();
|
|
2041
|
+
|
|
1785
2042
|
// 从全局获取必要的实例
|
|
1786
2043
|
app = window.app;
|
|
1787
2044
|
logger = app === null || app === void 0 ? void 0 : app.logger; // 记录开始日志
|
|
@@ -1797,42 +2054,42 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1797
2054
|
});
|
|
1798
2055
|
}
|
|
1799
2056
|
if (app) {
|
|
1800
|
-
|
|
2057
|
+
_context29.next = 8;
|
|
1801
2058
|
break;
|
|
1802
2059
|
}
|
|
1803
2060
|
throw new Error('App 实例未找到');
|
|
1804
|
-
case
|
|
2061
|
+
case 8:
|
|
1805
2062
|
request = app.request;
|
|
1806
2063
|
if (request) {
|
|
1807
|
-
|
|
2064
|
+
_context29.next = 11;
|
|
1808
2065
|
break;
|
|
1809
2066
|
}
|
|
1810
2067
|
throw new Error('Request 插件未找到');
|
|
1811
|
-
case
|
|
2068
|
+
case 11:
|
|
1812
2069
|
dbManager = app.dbManager;
|
|
1813
2070
|
if (dbManager) {
|
|
1814
|
-
|
|
2071
|
+
_context29.next = 14;
|
|
1815
2072
|
break;
|
|
1816
2073
|
}
|
|
1817
2074
|
throw new Error('DBManager 未找到');
|
|
1818
|
-
case
|
|
1819
|
-
|
|
1820
|
-
|
|
2075
|
+
case 14:
|
|
2076
|
+
_context29.prev = 14;
|
|
2077
|
+
_context29.next = 17;
|
|
1821
2078
|
return request.post("/shop/order/".concat(orderId, "/order-payment"), paymentData, {
|
|
1822
2079
|
noToast: true
|
|
1823
2080
|
});
|
|
1824
|
-
case
|
|
1825
|
-
requestRes =
|
|
2081
|
+
case 17:
|
|
2082
|
+
requestRes = _context29.sent;
|
|
1826
2083
|
if (!(requestRes.status === true)) {
|
|
1827
|
-
|
|
2084
|
+
_context29.next = 35;
|
|
1828
2085
|
break;
|
|
1829
2086
|
}
|
|
1830
|
-
|
|
2087
|
+
_context29.next = 21;
|
|
1831
2088
|
return dbManager.get('order', orderUuid);
|
|
1832
|
-
case
|
|
1833
|
-
order =
|
|
2089
|
+
case 21:
|
|
2090
|
+
order = _context29.sent;
|
|
1834
2091
|
if (!order) {
|
|
1835
|
-
|
|
2092
|
+
_context29.next = 27;
|
|
1836
2093
|
break;
|
|
1837
2094
|
}
|
|
1838
2095
|
order.payment.forEach(function (payment) {
|
|
@@ -1840,19 +2097,19 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1840
2097
|
// 清除之前的错误状态
|
|
1841
2098
|
delete payment.syncError;
|
|
1842
2099
|
});
|
|
1843
|
-
|
|
2100
|
+
_context29.next = 26;
|
|
1844
2101
|
return dbManager.update('order', order);
|
|
1845
|
-
case 25:
|
|
1846
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
|
|
1847
2102
|
case 26:
|
|
2103
|
+
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u72B6\u6001\u5DF2\u66F4\u65B0"));
|
|
2104
|
+
case 27:
|
|
1848
2105
|
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u540E\u53F0\u540C\u6B65\u6210\u529F"));
|
|
1849
|
-
|
|
2106
|
+
_context29.next = 30;
|
|
1850
2107
|
return core.effects.emit('payment:onPaymentSyncSuccess', {
|
|
1851
2108
|
orderUuid: orderUuid,
|
|
1852
2109
|
orderId: orderId,
|
|
1853
2110
|
timestamp: Date.now()
|
|
1854
2111
|
});
|
|
1855
|
-
case
|
|
2112
|
+
case 30:
|
|
1856
2113
|
console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u6210\u529F"));
|
|
1857
2114
|
|
|
1858
2115
|
// 记录成功日志
|
|
@@ -1866,12 +2123,12 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1866
2123
|
}
|
|
1867
2124
|
});
|
|
1868
2125
|
}
|
|
1869
|
-
return
|
|
2126
|
+
return _context29.abrupt("return", {
|
|
1870
2127
|
status: 'success',
|
|
1871
2128
|
orderUuid: orderUuid,
|
|
1872
2129
|
orderId: orderId
|
|
1873
2130
|
});
|
|
1874
|
-
case
|
|
2131
|
+
case 35:
|
|
1875
2132
|
// 接口返回失败,视为业务错误处理
|
|
1876
2133
|
console.log("[PaymentModule] \u63A5\u53E3\u8FD4\u56DE\u5931\u8D25\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25"));
|
|
1877
2134
|
|
|
@@ -1883,18 +2140,18 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1883
2140
|
businessError.isBusinessError = true;
|
|
1884
2141
|
businessError.responseData = requestRes;
|
|
1885
2142
|
throw businessError;
|
|
1886
|
-
case
|
|
1887
|
-
|
|
2143
|
+
case 41:
|
|
2144
|
+
_context29.next = 80;
|
|
1888
2145
|
break;
|
|
1889
|
-
case
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
console.error('[PaymentModule] 后台同步失败:',
|
|
2146
|
+
case 43:
|
|
2147
|
+
_context29.prev = 43;
|
|
2148
|
+
_context29.t0 = _context29["catch"](14);
|
|
2149
|
+
console.error('[PaymentModule] 后台同步失败:', _context29.t0);
|
|
1893
2150
|
|
|
1894
2151
|
// 检查是否是网络错误(没有响应码)还是业务错误(有响应码)
|
|
1895
|
-
isNetworkError = !
|
|
2152
|
+
isNetworkError = !_context29.t0.response && !_context29.t0.status && (_context29.t0.code === 'NETWORK_ERROR' || _context29.t0.code === 'ERR_NETWORK' || _context29.t0.code === 'ECONNREFUSED' || _context29.t0.code === 'ENOTFOUND' || _context29.t0.code === 'ETIMEDOUT' || ((_error$message = _context29.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.includes('网络')) || ((_error$message2 = _context29.t0.message) === null || _error$message2 === void 0 ? void 0 : _error$message2.includes('network')) || ((_error$message3 = _context29.t0.message) === null || _error$message3 === void 0 ? void 0 : _error$message3.includes('fetch')));
|
|
1896
2153
|
if (!isNetworkError) {
|
|
1897
|
-
|
|
2154
|
+
_context29.next = 53;
|
|
1898
2155
|
break;
|
|
1899
2156
|
}
|
|
1900
2157
|
// 网络错误:重试
|
|
@@ -1908,43 +2165,43 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1908
2165
|
metadata: {
|
|
1909
2166
|
orderUuid: orderUuid,
|
|
1910
2167
|
orderId: orderId,
|
|
1911
|
-
errorCode:
|
|
1912
|
-
errorMessage:
|
|
2168
|
+
errorCode: _context29.t0.code,
|
|
2169
|
+
errorMessage: _context29.t0.message
|
|
1913
2170
|
}
|
|
1914
2171
|
});
|
|
1915
2172
|
}
|
|
1916
|
-
throw
|
|
1917
|
-
case
|
|
2173
|
+
throw _context29.t0;
|
|
2174
|
+
case 53:
|
|
1918
2175
|
// 业务错误(有响应码):不标记为已同步,通过 effects 通知前端,但不重试
|
|
1919
2176
|
console.log("[PaymentModule] \u4E1A\u52A1\u9519\u8BEF\uFF0C\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u5931\u8D25\uFF0C\u901A\u77E5\u524D\u7AEF"));
|
|
1920
|
-
|
|
2177
|
+
_context29.prev = 54;
|
|
1921
2178
|
if (!(core && core.effects)) {
|
|
1922
|
-
|
|
2179
|
+
_context29.next = 63;
|
|
1923
2180
|
break;
|
|
1924
2181
|
}
|
|
1925
2182
|
// 通过 effects 通知前端同步错误
|
|
1926
2183
|
errorData = {
|
|
1927
2184
|
orderUuid: orderUuid,
|
|
1928
2185
|
orderId: orderId,
|
|
1929
|
-
error:
|
|
1930
|
-
errorCode:
|
|
1931
|
-
statusCode: ((_error$response =
|
|
2186
|
+
error: _context29.t0.message || '业务错误',
|
|
2187
|
+
errorCode: _context29.t0.code,
|
|
2188
|
+
statusCode: ((_error$response = _context29.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status) || _context29.t0.status,
|
|
1932
2189
|
timestamp: Date.now()
|
|
1933
2190
|
}; // 如果是业务错误,添加响应数据
|
|
1934
|
-
if (
|
|
1935
|
-
errorData.error =
|
|
2191
|
+
if (_context29.t0.isBusinessError && _context29.t0.responseData) {
|
|
2192
|
+
errorData.error = _context29.t0.responseData.message || _context29.t0.message || '接口返回失败';
|
|
1936
2193
|
// 可以添加更多响应数据
|
|
1937
|
-
errorData.responseData =
|
|
2194
|
+
errorData.responseData = _context29.t0.responseData;
|
|
1938
2195
|
}
|
|
1939
|
-
|
|
2196
|
+
_context29.next = 60;
|
|
1940
2197
|
return core.effects.emit('payment:onPaymentSyncError', errorData);
|
|
1941
|
-
case
|
|
2198
|
+
case 60:
|
|
1942
2199
|
console.log("[PaymentModule] \u5DF2\u901A\u8FC7 effects \u901A\u77E5\u524D\u7AEF\u8BA2\u5355 ".concat(orderUuid, " \u540C\u6B65\u9519\u8BEF"));
|
|
1943
|
-
|
|
2200
|
+
_context29.next = 64;
|
|
1944
2201
|
break;
|
|
1945
|
-
case 62:
|
|
1946
|
-
console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
|
|
1947
2202
|
case 63:
|
|
2203
|
+
console.warn("[PaymentModule] \u65E0\u6CD5\u83B7\u53D6 core \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u901A\u77E5\u524D\u7AEF\u9519\u8BEF");
|
|
2204
|
+
case 64:
|
|
1948
2205
|
// 记录业务错误日志
|
|
1949
2206
|
if (logger) {
|
|
1950
2207
|
logger.addLog({
|
|
@@ -1953,19 +2210,19 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1953
2210
|
metadata: {
|
|
1954
2211
|
orderUuid: orderUuid,
|
|
1955
2212
|
orderId: orderId,
|
|
1956
|
-
errorCode:
|
|
1957
|
-
errorMessage:
|
|
1958
|
-
statusCode: ((_error$response2 =
|
|
1959
|
-
isBusinessError:
|
|
2213
|
+
errorCode: _context29.t0.code,
|
|
2214
|
+
errorMessage: _context29.t0.message,
|
|
2215
|
+
statusCode: ((_error$response2 = _context29.t0.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || _context29.t0.status,
|
|
2216
|
+
isBusinessError: _context29.t0.isBusinessError
|
|
1960
2217
|
}
|
|
1961
2218
|
});
|
|
1962
2219
|
}
|
|
1963
|
-
|
|
2220
|
+
_context29.next = 71;
|
|
1964
2221
|
break;
|
|
1965
|
-
case
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:",
|
|
2222
|
+
case 67:
|
|
2223
|
+
_context29.prev = 67;
|
|
2224
|
+
_context29.t1 = _context29["catch"](54);
|
|
2225
|
+
console.error("[PaymentModule] \u901A\u77E5\u524D\u7AEF\u540C\u6B65\u9519\u8BEF\u5931\u8D25:", _context29.t1);
|
|
1969
2226
|
|
|
1970
2227
|
// 记录通知错误日志
|
|
1971
2228
|
if (logger) {
|
|
@@ -1975,41 +2232,41 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1975
2232
|
metadata: {
|
|
1976
2233
|
orderUuid: orderUuid,
|
|
1977
2234
|
orderId: orderId,
|
|
1978
|
-
notifyError:
|
|
2235
|
+
notifyError: _context29.t1 instanceof Error ? _context29.t1.message : String(_context29.t1)
|
|
1979
2236
|
}
|
|
1980
2237
|
});
|
|
1981
2238
|
}
|
|
1982
|
-
case
|
|
1983
|
-
|
|
2239
|
+
case 71:
|
|
2240
|
+
_context29.next = 73;
|
|
1984
2241
|
return dbManager.get('order', orderUuid);
|
|
1985
|
-
case
|
|
1986
|
-
_order2 =
|
|
2242
|
+
case 73:
|
|
2243
|
+
_order2 = _context29.sent;
|
|
1987
2244
|
if (!_order2) {
|
|
1988
|
-
|
|
2245
|
+
_context29.next = 79;
|
|
1989
2246
|
break;
|
|
1990
2247
|
}
|
|
1991
2248
|
_order2.payment.forEach(function (payment) {
|
|
1992
2249
|
payment.isSynced = true;
|
|
1993
2250
|
});
|
|
1994
|
-
|
|
2251
|
+
_context29.next = 78;
|
|
1995
2252
|
return dbManager.update('order', _order2);
|
|
1996
|
-
case 77:
|
|
1997
|
-
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
|
|
1998
2253
|
case 78:
|
|
1999
|
-
|
|
2254
|
+
console.log("[PaymentModule] \u8BA2\u5355 ".concat(orderUuid, " \u4E1A\u52A1\u9519\u8BEF\uFF0C\u5DF2\u6807\u8BB0\u4E3A\u5DF2\u540C\u6B65"));
|
|
2255
|
+
case 79:
|
|
2256
|
+
return _context29.abrupt("return", {
|
|
2000
2257
|
status: 'completed_with_error',
|
|
2001
2258
|
orderUuid: orderUuid,
|
|
2002
2259
|
orderId: orderId,
|
|
2003
|
-
error:
|
|
2004
|
-
statusCode: ((_error$response3 =
|
|
2260
|
+
error: _context29.t0.message || '业务错误',
|
|
2261
|
+
statusCode: ((_error$response3 = _context29.t0.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.status) || _context29.t0.status
|
|
2005
2262
|
});
|
|
2006
|
-
case
|
|
2263
|
+
case 80:
|
|
2007
2264
|
case "end":
|
|
2008
|
-
return
|
|
2265
|
+
return _context29.stop();
|
|
2009
2266
|
}
|
|
2010
|
-
},
|
|
2267
|
+
}, _callee29, null, [[14, 43], [54, 67]]);
|
|
2011
2268
|
}));
|
|
2012
|
-
function syncPaymentTask(
|
|
2269
|
+
function syncPaymentTask(_x26) {
|
|
2013
2270
|
return _syncPaymentTask.apply(this, arguments);
|
|
2014
2271
|
}
|
|
2015
2272
|
return syncPaymentTask;
|