@pisell/pisellos 2.2.1 → 2.2.3
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.js +56 -46
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/plugins/request.d.ts +18 -0
- package/dist/plugins/request.js +11 -0
- package/dist/server/modules/products/index.js +6 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/Checkout/index.d.ts +46 -1
- package/dist/solution/Checkout/index.js +823 -503
- package/lib/modules/Payment/index.js +27 -40
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/plugins/request.d.ts +18 -0
- package/lib/plugins/request.js +11 -1
- package/lib/server/modules/products/index.js +8 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/Checkout/index.d.ts +46 -1
- package/lib/solution/Checkout/index.js +263 -66
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
3
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
5
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
2
6
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
7
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
8
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -55,6 +59,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
55
59
|
_defineProperty(_assertThisInitialized(_this), "otherParams", {});
|
|
56
60
|
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
|
57
61
|
// LoggerManager 实例
|
|
62
|
+
// 计算缓存(用于性能优化)
|
|
63
|
+
_defineProperty(_assertThisInitialized(_this), "calculationCache", {});
|
|
58
64
|
// 直接挂载的模块
|
|
59
65
|
_defineProperty(_assertThisInitialized(_this), "order", void 0);
|
|
60
66
|
_defineProperty(_assertThisInitialized(_this), "payment", void 0);
|
|
@@ -539,7 +545,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
539
545
|
value: (function () {
|
|
540
546
|
var _createLocalOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
|
|
541
547
|
var _params$orderData, _params$orderData2, _params$orderData3, _params$orderData4, _params$orderData5, _params$cartSummary;
|
|
542
|
-
var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, isNeedDeposit, paymentOrder;
|
|
548
|
+
var _params$totalInfo, _params$totalInfo2, _params$totalInfo3, _params$totalInfo4, validation, localOrderId, amountInfo, customerInfo, isNeedDeposit, paymentOrder, updateAmountStartTime, updateAmountDuration;
|
|
543
549
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
544
550
|
while (1) switch (_context9.prev = _context9.next) {
|
|
545
551
|
case 0:
|
|
@@ -554,17 +560,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
554
560
|
totalInfoKeys: params.totalInfo ? Object.keys(params.totalInfo) : []
|
|
555
561
|
});
|
|
556
562
|
_context9.prev = 1;
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
case 4:
|
|
563
|
+
// 🔧 修改:在创建新订单前,直接重置 store 状态(同步执行)
|
|
564
|
+
this.resetStoreState();
|
|
560
565
|
// 验证订单数据
|
|
561
566
|
validation = validateLocalOrderData(params.orderData);
|
|
562
567
|
if (validation.valid) {
|
|
563
|
-
_context9.next =
|
|
568
|
+
_context9.next = 6;
|
|
564
569
|
break;
|
|
565
570
|
}
|
|
566
571
|
throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u8BA2\u5355\u6570\u636E\u9A8C\u8BC1\u5931\u8D25: ".concat(validation.errors.join(', ')));
|
|
567
|
-
case
|
|
572
|
+
case 6:
|
|
568
573
|
// 生成本地虚拟订单ID (后续可以被真实订单ID替换)
|
|
569
574
|
localOrderId = generateLocalOrderId(); // 从购物车小计数据中提取金额信息
|
|
570
575
|
amountInfo = extractAmountFromCartSummary(params.cartSummary); // TODO: 外面传的是 pos ,但是现在 后端只有 shop 和 kiosk
|
|
@@ -598,7 +603,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
598
603
|
|
|
599
604
|
// 计算是否需要支付定金,如果需要默认切换到定金模式,以及记录定金总金额,并把当前默认待付金额调整为定金总金额
|
|
600
605
|
isNeedDeposit = this.checkIsNeedDepositAsync(params.orderData.bookings, params.orderData.relation_products); // 创建支付订单对象
|
|
601
|
-
_context9.next =
|
|
606
|
+
_context9.next = 21;
|
|
602
607
|
return this.payment.createPaymentOrderAsync({
|
|
603
608
|
order_id: localOrderId,
|
|
604
609
|
total_amount: amountInfo.totalAmount,
|
|
@@ -615,23 +620,34 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
615
620
|
amount_breakdown: amountInfo
|
|
616
621
|
}
|
|
617
622
|
});
|
|
618
|
-
case
|
|
623
|
+
case 21:
|
|
619
624
|
paymentOrder = _context9.sent;
|
|
620
625
|
this.store.currentOrder = paymentOrder;
|
|
621
626
|
|
|
622
|
-
// 如果设置了自动支付,直接跳转到支付步骤
|
|
623
|
-
if (params.autoPayment) {
|
|
624
|
-
|
|
625
|
-
}
|
|
627
|
+
// // 如果设置了自动支付,直接跳转到支付步骤
|
|
628
|
+
// if (params.autoPayment) {
|
|
629
|
+
// // 自动支付模式标记
|
|
630
|
+
// }
|
|
631
|
+
|
|
626
632
|
this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
627
633
|
order: paymentOrder,
|
|
628
634
|
timestamp: Date.now()
|
|
629
635
|
});
|
|
630
636
|
|
|
631
637
|
// 自动设置 stateAmount 为剩余未支付金额
|
|
632
|
-
|
|
638
|
+
// 🚀 性能监控:记录 updateStateAmountToRemaining 操作耗时
|
|
639
|
+
updateAmountStartTime = Date.now();
|
|
640
|
+
_context9.next = 27;
|
|
633
641
|
return this.updateStateAmountToRemaining(false);
|
|
634
|
-
case
|
|
642
|
+
case 27:
|
|
643
|
+
updateAmountDuration = Date.now() - updateAmountStartTime;
|
|
644
|
+
this.logInfo('updateStateAmountToRemaining operation completed', {
|
|
645
|
+
operation: 'updateStateAmountToRemaining',
|
|
646
|
+
orderUuid: paymentOrder.uuid,
|
|
647
|
+
orderId: paymentOrder.order_id,
|
|
648
|
+
duration: "".concat(updateAmountDuration, "ms"),
|
|
649
|
+
performance: updateAmountDuration > 200 ? 'slow' : updateAmountDuration > 100 ? 'medium' : 'fast'
|
|
650
|
+
});
|
|
635
651
|
this.logInfo('本地订单创建成功:', {
|
|
636
652
|
localOrderId: localOrderId,
|
|
637
653
|
uuid: paymentOrder.uuid,
|
|
@@ -642,23 +658,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
642
658
|
});
|
|
643
659
|
this.initWalletData();
|
|
644
660
|
return _context9.abrupt("return", paymentOrder);
|
|
645
|
-
case
|
|
646
|
-
_context9.prev =
|
|
661
|
+
case 34:
|
|
662
|
+
_context9.prev = 34;
|
|
647
663
|
_context9.t0 = _context9["catch"](1);
|
|
648
|
-
_context9.next =
|
|
664
|
+
_context9.next = 38;
|
|
649
665
|
return this.handleError(_context9.t0, CheckoutErrorType.OrderCreationFailed);
|
|
650
|
-
case
|
|
666
|
+
case 38:
|
|
651
667
|
this.logError('本地订单创建失败:', _context9.t0);
|
|
652
668
|
this.core.effects.emit("".concat(this.name, ":onOrderCreationFailed"), {
|
|
653
669
|
error: this.store.lastError,
|
|
654
670
|
timestamp: Date.now()
|
|
655
671
|
});
|
|
656
672
|
throw _context9.t0;
|
|
657
|
-
case
|
|
673
|
+
case 41:
|
|
658
674
|
case "end":
|
|
659
675
|
return _context9.stop();
|
|
660
676
|
}
|
|
661
|
-
}, _callee9, this, [[1,
|
|
677
|
+
}, _callee9, this, [[1, 34]]);
|
|
662
678
|
}));
|
|
663
679
|
function createLocalOrderAsync(_x11) {
|
|
664
680
|
return _createLocalOrderAsync.apply(this, arguments);
|
|
@@ -882,28 +898,26 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
882
898
|
case 11:
|
|
883
899
|
console.log('[Checkout] 结账流程完成:', order.id);
|
|
884
900
|
|
|
885
|
-
// 🔧 新增:自动重置 store
|
|
886
|
-
|
|
887
|
-
return this.resetStoreStateAsync();
|
|
888
|
-
case 14:
|
|
901
|
+
// 🔧 新增:自动重置 store 状态(同步执行)
|
|
902
|
+
this.resetStoreState();
|
|
889
903
|
return _context11.abrupt("return", {
|
|
890
904
|
success: true,
|
|
891
905
|
orderId: String(order.id)
|
|
892
906
|
});
|
|
893
|
-
case
|
|
894
|
-
_context11.prev =
|
|
907
|
+
case 16:
|
|
908
|
+
_context11.prev = 16;
|
|
895
909
|
_context11.t0 = _context11["catch"](0);
|
|
896
|
-
_context11.next =
|
|
910
|
+
_context11.next = 20;
|
|
897
911
|
return this.handleError(_context11.t0, CheckoutErrorType.UnknownError);
|
|
898
|
-
case
|
|
912
|
+
case 20:
|
|
899
913
|
return _context11.abrupt("return", {
|
|
900
914
|
success: false
|
|
901
915
|
});
|
|
902
|
-
case
|
|
916
|
+
case 21:
|
|
903
917
|
case "end":
|
|
904
918
|
return _context11.stop();
|
|
905
919
|
}
|
|
906
|
-
}, _callee11, this, [[0,
|
|
920
|
+
}, _callee11, this, [[0, 16]]);
|
|
907
921
|
}));
|
|
908
922
|
function completeCheckoutAsync() {
|
|
909
923
|
return _completeCheckoutAsync.apply(this, arguments);
|
|
@@ -1319,16 +1333,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1319
1333
|
case 12:
|
|
1320
1334
|
this.logInfo('支付项添加成功');
|
|
1321
1335
|
|
|
1336
|
+
// 🚀 清除计算缓存,确保获取最新数据
|
|
1337
|
+
this.clearCalculationCache();
|
|
1338
|
+
|
|
1322
1339
|
// 支付项添加后,更新 stateAmount 为剩余未支付金额
|
|
1323
|
-
_context16.next =
|
|
1340
|
+
_context16.next = 16;
|
|
1324
1341
|
return this.updateStateAmountToRemaining();
|
|
1325
|
-
case
|
|
1326
|
-
_context16.next =
|
|
1342
|
+
case 16:
|
|
1343
|
+
_context16.next = 18;
|
|
1327
1344
|
return this.calculateRemainingAmountAsync();
|
|
1328
|
-
case
|
|
1345
|
+
case 18:
|
|
1329
1346
|
remainingAmount = _context16.sent;
|
|
1330
1347
|
if (!(Number(remainingAmount) > 0)) {
|
|
1331
|
-
_context16.next =
|
|
1348
|
+
_context16.next = 39;
|
|
1332
1349
|
break;
|
|
1333
1350
|
}
|
|
1334
1351
|
this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
|
|
@@ -1343,30 +1360,30 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1343
1360
|
currentOrderSynced: this.store.isOrderSynced
|
|
1344
1361
|
});
|
|
1345
1362
|
if (!(isEftposPayment || _isCashPayment || isCustomePayment)) {
|
|
1346
|
-
_context16.next =
|
|
1363
|
+
_context16.next = 39;
|
|
1347
1364
|
break;
|
|
1348
1365
|
}
|
|
1349
1366
|
this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
|
|
1350
|
-
_context16.prev =
|
|
1351
|
-
_context16.next =
|
|
1367
|
+
_context16.prev = 27;
|
|
1368
|
+
_context16.next = 30;
|
|
1352
1369
|
return this.syncOrderToBackendWithReturn(true);
|
|
1353
|
-
case
|
|
1370
|
+
case 30:
|
|
1354
1371
|
syncResult = _context16.sent;
|
|
1355
1372
|
this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
|
|
1356
1373
|
orderId: syncResult.orderId,
|
|
1357
1374
|
isOrderSynced: this.store.isOrderSynced,
|
|
1358
1375
|
backendResponse: syncResult.response
|
|
1359
1376
|
});
|
|
1360
|
-
_context16.next =
|
|
1377
|
+
_context16.next = 39;
|
|
1361
1378
|
break;
|
|
1362
|
-
case
|
|
1363
|
-
_context16.prev =
|
|
1364
|
-
_context16.t0 = _context16["catch"](
|
|
1379
|
+
case 34:
|
|
1380
|
+
_context16.prev = 34;
|
|
1381
|
+
_context16.t0 = _context16["catch"](27);
|
|
1365
1382
|
this.logError('EFTPOS 支付后订单同步失败:', _context16.t0);
|
|
1366
1383
|
// 不抛出错误,避免影响支付流程,但记录错误
|
|
1367
|
-
_context16.next =
|
|
1384
|
+
_context16.next = 39;
|
|
1368
1385
|
return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0))), CheckoutErrorType.OrderCreationFailed);
|
|
1369
|
-
case
|
|
1386
|
+
case 39:
|
|
1370
1387
|
// 触发支付项添加事件(可以复用支付开始事件)
|
|
1371
1388
|
this.core.effects.emit("".concat(this.name, ":onPaymentItemAdded"), {
|
|
1372
1389
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -1375,21 +1392,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1375
1392
|
amount: String(paymentItem.amount),
|
|
1376
1393
|
timestamp: Date.now()
|
|
1377
1394
|
});
|
|
1378
|
-
_context16.next =
|
|
1395
|
+
_context16.next = 48;
|
|
1379
1396
|
break;
|
|
1380
|
-
case
|
|
1381
|
-
_context16.prev =
|
|
1397
|
+
case 42:
|
|
1398
|
+
_context16.prev = 42;
|
|
1382
1399
|
_context16.t1 = _context16["catch"](1);
|
|
1383
1400
|
this.logError('添加支付项失败:', _context16.t1);
|
|
1384
|
-
_context16.next =
|
|
1401
|
+
_context16.next = 47;
|
|
1385
1402
|
return this.handleError(_context16.t1, CheckoutErrorType.PaymentFailed);
|
|
1386
|
-
case 46:
|
|
1387
|
-
throw _context16.t1;
|
|
1388
1403
|
case 47:
|
|
1404
|
+
throw _context16.t1;
|
|
1405
|
+
case 48:
|
|
1389
1406
|
case "end":
|
|
1390
1407
|
return _context16.stop();
|
|
1391
1408
|
}
|
|
1392
|
-
}, _callee16, this, [[1,
|
|
1409
|
+
}, _callee16, this, [[1, 42], [27, 34]]);
|
|
1393
1410
|
}));
|
|
1394
1411
|
function addPaymentItemAsync(_x15) {
|
|
1395
1412
|
return _addPaymentItemAsync.apply(this, arguments);
|
|
@@ -1454,12 +1471,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1454
1471
|
case 13:
|
|
1455
1472
|
this.logInfo('Payment支付项删除完成', paymentItem);
|
|
1456
1473
|
|
|
1474
|
+
// 🚀 清除计算缓存,确保获取最新数据
|
|
1475
|
+
this.clearCalculationCache();
|
|
1476
|
+
|
|
1457
1477
|
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1458
1478
|
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1459
1479
|
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1460
|
-
_context17.next =
|
|
1480
|
+
_context17.next = 19;
|
|
1461
1481
|
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1462
|
-
case
|
|
1482
|
+
case 19:
|
|
1463
1483
|
updatedOrder = _context17.sent;
|
|
1464
1484
|
if (updatedOrder) {
|
|
1465
1485
|
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
@@ -1474,10 +1494,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1474
1494
|
}
|
|
1475
1495
|
|
|
1476
1496
|
// 更新 stateAmount 为剩余未支付金额
|
|
1477
|
-
_context17.next =
|
|
1497
|
+
_context17.next = 23;
|
|
1478
1498
|
return this.updateStateAmountToRemaining(false);
|
|
1479
|
-
case
|
|
1480
|
-
_context17.next =
|
|
1499
|
+
case 23:
|
|
1500
|
+
_context17.next = 25;
|
|
1481
1501
|
return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
|
|
1482
1502
|
orderUuid: this.store.currentOrder.uuid,
|
|
1483
1503
|
paymentMethodCode: paymentItem.code,
|
|
@@ -1485,22 +1505,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1485
1505
|
// 负数表示删除
|
|
1486
1506
|
timestamp: Date.now()
|
|
1487
1507
|
});
|
|
1488
|
-
case
|
|
1489
|
-
_context17.next =
|
|
1508
|
+
case 25:
|
|
1509
|
+
_context17.next = 33;
|
|
1490
1510
|
break;
|
|
1491
|
-
case
|
|
1492
|
-
_context17.prev =
|
|
1511
|
+
case 27:
|
|
1512
|
+
_context17.prev = 27;
|
|
1493
1513
|
_context17.t0 = _context17["catch"](0);
|
|
1494
1514
|
this.logError('删除支付项失败:', _context17.t0);
|
|
1495
|
-
_context17.next =
|
|
1515
|
+
_context17.next = 32;
|
|
1496
1516
|
return this.handleError(_context17.t0, CheckoutErrorType.PaymentFailed);
|
|
1497
|
-
case 31:
|
|
1498
|
-
throw _context17.t0;
|
|
1499
1517
|
case 32:
|
|
1518
|
+
throw _context17.t0;
|
|
1519
|
+
case 33:
|
|
1500
1520
|
case "end":
|
|
1501
1521
|
return _context17.stop();
|
|
1502
1522
|
}
|
|
1503
|
-
}, _callee17, this, [[0,
|
|
1523
|
+
}, _callee17, this, [[0, 27]]);
|
|
1504
1524
|
}));
|
|
1505
1525
|
function deletePaymentItemAsync(_x16) {
|
|
1506
1526
|
return _deletePaymentItemAsync.apply(this, arguments);
|
|
@@ -1585,12 +1605,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1585
1605
|
_context18.next = 20;
|
|
1586
1606
|
return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
|
|
1587
1607
|
case 20:
|
|
1608
|
+
// 🚀 清除计算缓存,确保获取最新数据
|
|
1609
|
+
this.clearCalculationCache();
|
|
1610
|
+
|
|
1588
1611
|
// 重新从Payment模块获取最新的订单数据,确保支付项同步
|
|
1589
1612
|
currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
|
|
1590
1613
|
isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
|
|
1591
|
-
_context18.next =
|
|
1614
|
+
_context18.next = 25;
|
|
1592
1615
|
return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
|
|
1593
|
-
case
|
|
1616
|
+
case 25:
|
|
1594
1617
|
updatedOrder = _context18.sent;
|
|
1595
1618
|
if (updatedOrder) {
|
|
1596
1619
|
// 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
|
|
@@ -1605,10 +1628,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1605
1628
|
}
|
|
1606
1629
|
|
|
1607
1630
|
// 更新 stateAmount 为剩余未支付金额
|
|
1608
|
-
_context18.next =
|
|
1631
|
+
_context18.next = 29;
|
|
1609
1632
|
return this.updateStateAmountToRemaining(false);
|
|
1610
|
-
case
|
|
1611
|
-
_context18.next =
|
|
1633
|
+
case 29:
|
|
1634
|
+
_context18.next = 31;
|
|
1612
1635
|
return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
|
|
1613
1636
|
orderUuid: this.store.currentOrder.uuid,
|
|
1614
1637
|
paymentMethodCode: 'VOUCHER_BATCH',
|
|
@@ -1617,23 +1640,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1617
1640
|
}, 0).toFixed(2),
|
|
1618
1641
|
timestamp: Date.now()
|
|
1619
1642
|
});
|
|
1620
|
-
case
|
|
1643
|
+
case 31:
|
|
1621
1644
|
this.logInfo('代金券支付项批量更新成功');
|
|
1622
|
-
_context18.next =
|
|
1645
|
+
_context18.next = 40;
|
|
1623
1646
|
break;
|
|
1624
|
-
case
|
|
1625
|
-
_context18.prev =
|
|
1647
|
+
case 34:
|
|
1648
|
+
_context18.prev = 34;
|
|
1626
1649
|
_context18.t0 = _context18["catch"](0);
|
|
1627
1650
|
this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
|
|
1628
|
-
_context18.next =
|
|
1651
|
+
_context18.next = 39;
|
|
1629
1652
|
return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
|
|
1630
|
-
case 38:
|
|
1631
|
-
throw _context18.t0;
|
|
1632
1653
|
case 39:
|
|
1654
|
+
throw _context18.t0;
|
|
1655
|
+
case 40:
|
|
1633
1656
|
case "end":
|
|
1634
1657
|
return _context18.stop();
|
|
1635
1658
|
}
|
|
1636
|
-
}, _callee18, this, [[0,
|
|
1659
|
+
}, _callee18, this, [[0, 34]]);
|
|
1637
1660
|
}));
|
|
1638
1661
|
function updateVoucherPaymentItemsAsync(_x17) {
|
|
1639
1662
|
return _updateVoucherPaymentItemsAsync.apply(this, arguments);
|
|
@@ -1707,34 +1730,37 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1707
1730
|
if (this.store.localOrderData) {
|
|
1708
1731
|
this.store.localOrderData.is_deposit = newDepositValue;
|
|
1709
1732
|
}
|
|
1733
|
+
|
|
1734
|
+
// 🚀 清除计算缓存,确保获取最新数据
|
|
1735
|
+
this.clearCalculationCache();
|
|
1710
1736
|
this.updateStateAmountToRemaining(false);
|
|
1711
1737
|
|
|
1712
1738
|
// 触发订单更新事件
|
|
1713
|
-
_context19.next =
|
|
1739
|
+
_context19.next = 21;
|
|
1714
1740
|
return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
1715
1741
|
order: this.store.currentOrder,
|
|
1716
1742
|
timestamp: Date.now()
|
|
1717
1743
|
});
|
|
1718
|
-
case
|
|
1744
|
+
case 21:
|
|
1719
1745
|
this.logInfo('订单定金状态更新成功:', {
|
|
1720
1746
|
isDeposit: newDepositValue,
|
|
1721
1747
|
depositAmount: this.store.currentOrder.deposit_amount
|
|
1722
1748
|
});
|
|
1723
|
-
_context19.next =
|
|
1749
|
+
_context19.next = 30;
|
|
1724
1750
|
break;
|
|
1725
|
-
case
|
|
1726
|
-
_context19.prev =
|
|
1751
|
+
case 24:
|
|
1752
|
+
_context19.prev = 24;
|
|
1727
1753
|
_context19.t0 = _context19["catch"](0);
|
|
1728
1754
|
this.logError('更新订单定金状态失败:', _context19.t0);
|
|
1729
|
-
_context19.next =
|
|
1755
|
+
_context19.next = 29;
|
|
1730
1756
|
return this.handleError(_context19.t0, CheckoutErrorType.ValidationFailed);
|
|
1731
|
-
case 28:
|
|
1732
|
-
throw _context19.t0;
|
|
1733
1757
|
case 29:
|
|
1758
|
+
throw _context19.t0;
|
|
1759
|
+
case 30:
|
|
1734
1760
|
case "end":
|
|
1735
1761
|
return _context19.stop();
|
|
1736
1762
|
}
|
|
1737
|
-
}, _callee19, this, [[0,
|
|
1763
|
+
}, _callee19, this, [[0, 24]]);
|
|
1738
1764
|
}));
|
|
1739
1765
|
function updateOrderDepositStatusAsync(_x18) {
|
|
1740
1766
|
return _updateOrderDepositStatusAsync.apply(this, arguments);
|
|
@@ -1833,15 +1859,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1833
1859
|
this.store.localOrderData.is_deposit = updateParams.is_deposit;
|
|
1834
1860
|
}
|
|
1835
1861
|
}
|
|
1862
|
+
|
|
1863
|
+
// 🚀 清除计算缓存,确保获取最新数据
|
|
1864
|
+
this.clearCalculationCache();
|
|
1836
1865
|
this.updateStateAmountToRemaining(false);
|
|
1837
1866
|
|
|
1838
1867
|
// 触发订单更新事件
|
|
1839
|
-
_context20.next =
|
|
1868
|
+
_context20.next = 23;
|
|
1840
1869
|
return this.core.effects.emit("".concat(this.name, ":onOrderCreated"), {
|
|
1841
1870
|
order: this.store.currentOrder,
|
|
1842
1871
|
timestamp: Date.now()
|
|
1843
1872
|
});
|
|
1844
|
-
case
|
|
1873
|
+
case 23:
|
|
1845
1874
|
this.logInfo('订单定金金额设置成功:', {
|
|
1846
1875
|
orderUuid: this.store.currentOrder.uuid,
|
|
1847
1876
|
orderId: this.store.currentOrder.order_id,
|
|
@@ -1850,21 +1879,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1850
1879
|
isDeposit: this.store.currentOrder.is_deposit,
|
|
1851
1880
|
totalAmount: this.store.currentOrder.total_amount
|
|
1852
1881
|
});
|
|
1853
|
-
_context20.next =
|
|
1882
|
+
_context20.next = 32;
|
|
1854
1883
|
break;
|
|
1855
|
-
case
|
|
1856
|
-
_context20.prev =
|
|
1884
|
+
case 26:
|
|
1885
|
+
_context20.prev = 26;
|
|
1857
1886
|
_context20.t0 = _context20["catch"](1);
|
|
1858
1887
|
this.logError('设置订单定金金额失败:', _context20.t0);
|
|
1859
|
-
_context20.next =
|
|
1888
|
+
_context20.next = 31;
|
|
1860
1889
|
return this.handleError(_context20.t0, CheckoutErrorType.ValidationFailed);
|
|
1861
|
-
case 30:
|
|
1862
|
-
throw _context20.t0;
|
|
1863
1890
|
case 31:
|
|
1891
|
+
throw _context20.t0;
|
|
1892
|
+
case 32:
|
|
1864
1893
|
case "end":
|
|
1865
1894
|
return _context20.stop();
|
|
1866
1895
|
}
|
|
1867
|
-
}, _callee20, this, [[1,
|
|
1896
|
+
}, _callee20, this, [[1, 26]]);
|
|
1868
1897
|
}));
|
|
1869
1898
|
function setDepositAmountAsync(_x19) {
|
|
1870
1899
|
return _setDepositAmountAsync.apply(this, arguments);
|
|
@@ -1886,6 +1915,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1886
1915
|
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1887
1916
|
while (1) switch (_context21.prev = _context21.next) {
|
|
1888
1917
|
case 0:
|
|
1918
|
+
console.log('manualSyncOrderAsync called');
|
|
1889
1919
|
this.logInfo('manualSyncOrderAsync called', {
|
|
1890
1920
|
hasCurrentOrder: !!this.store.currentOrder,
|
|
1891
1921
|
currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
|
|
@@ -1894,16 +1924,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1894
1924
|
isOrderSynced: this.store.isOrderSynced,
|
|
1895
1925
|
isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
|
|
1896
1926
|
});
|
|
1897
|
-
_context21.prev =
|
|
1927
|
+
_context21.prev = 2;
|
|
1898
1928
|
if (this.store.currentOrder) {
|
|
1899
|
-
_context21.next =
|
|
1929
|
+
_context21.next = 5;
|
|
1900
1930
|
break;
|
|
1901
1931
|
}
|
|
1902
1932
|
return _context21.abrupt("return", {
|
|
1903
1933
|
success: false,
|
|
1904
1934
|
message: '当前没有活跃订单,无法同步'
|
|
1905
1935
|
});
|
|
1906
|
-
case
|
|
1936
|
+
case 5:
|
|
1907
1937
|
orderUuid = this.store.currentOrder.uuid;
|
|
1908
1938
|
oldOrderId = this.store.currentOrder.order_id; // 检查订单是否已经同步
|
|
1909
1939
|
if (this.store.isOrderSynced) {
|
|
@@ -1913,9 +1943,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1913
1943
|
_context21.t1 = orderUuid;
|
|
1914
1944
|
_context21.t2 = oldOrderId;
|
|
1915
1945
|
_context21.t3 = this.store.currentOrder.total_amount;
|
|
1916
|
-
_context21.next =
|
|
1946
|
+
_context21.next = 14;
|
|
1917
1947
|
return this.calculateRemainingAmountAsync();
|
|
1918
|
-
case
|
|
1948
|
+
case 14:
|
|
1919
1949
|
_context21.t4 = _context21.sent;
|
|
1920
1950
|
_context21.t5 = {
|
|
1921
1951
|
orderUuid: _context21.t1,
|
|
@@ -1924,10 +1954,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1924
1954
|
remainingAmount: _context21.t4
|
|
1925
1955
|
};
|
|
1926
1956
|
_context21.t0.logInfo.call(_context21.t0, '开始手动同步订单到后端:', _context21.t5);
|
|
1927
|
-
|
|
1957
|
+
console.time('manualSyncOrderAsync');
|
|
1958
|
+
|
|
1959
|
+
// 强制同步订单到后端,并获取完整响应数据
|
|
1960
|
+
_context21.next = 20;
|
|
1928
1961
|
return this.syncOrderToBackendWithReturn(true);
|
|
1929
|
-
case
|
|
1962
|
+
case 20:
|
|
1930
1963
|
syncResult = _context21.sent;
|
|
1964
|
+
console.timeEnd('manualSyncOrderAsync');
|
|
1931
1965
|
this.logInfo('手动同步订单完成:', {
|
|
1932
1966
|
orderUuid: orderUuid,
|
|
1933
1967
|
syncResult: syncResult,
|
|
@@ -1948,13 +1982,13 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1948
1982
|
newRes = _objectSpread(_objectSpread({}, syncResult), {}, {
|
|
1949
1983
|
is_deposit: ((_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.is_deposit) || 0
|
|
1950
1984
|
});
|
|
1951
|
-
_context21.next =
|
|
1985
|
+
_context21.next = 30;
|
|
1952
1986
|
return this.updateStateAmountToRemaining(false);
|
|
1953
|
-
case 27:
|
|
1954
|
-
return _context21.abrupt("return", newRes);
|
|
1955
1987
|
case 30:
|
|
1956
|
-
_context21.
|
|
1957
|
-
|
|
1988
|
+
return _context21.abrupt("return", newRes);
|
|
1989
|
+
case 33:
|
|
1990
|
+
_context21.prev = 33;
|
|
1991
|
+
_context21.t6 = _context21["catch"](2);
|
|
1958
1992
|
this.logError('手动同步订单失败:', _context21.t6);
|
|
1959
1993
|
errorMessage = _context21.t6 instanceof Error ? _context21.t6.message : '同步失败';
|
|
1960
1994
|
return _context21.abrupt("return", {
|
|
@@ -1962,11 +1996,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1962
1996
|
message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
|
|
1963
1997
|
orderUuid: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.uuid
|
|
1964
1998
|
});
|
|
1965
|
-
case
|
|
1999
|
+
case 38:
|
|
1966
2000
|
case "end":
|
|
1967
2001
|
return _context21.stop();
|
|
1968
2002
|
}
|
|
1969
|
-
}, _callee21, this, [[
|
|
2003
|
+
}, _callee21, this, [[2, 33]]);
|
|
1970
2004
|
}));
|
|
1971
2005
|
function manualSyncOrderAsync() {
|
|
1972
2006
|
return _manualSyncOrderAsync.apply(this, arguments);
|
|
@@ -2742,69 +2776,151 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2742
2776
|
return cleanupExpiredOrdersAsync;
|
|
2743
2777
|
}()
|
|
2744
2778
|
/**
|
|
2745
|
-
*
|
|
2779
|
+
* 清除计算缓存
|
|
2746
2780
|
*/
|
|
2747
2781
|
)
|
|
2748
2782
|
}, {
|
|
2749
|
-
key: "
|
|
2783
|
+
key: "clearCalculationCache",
|
|
2784
|
+
value: function clearCalculationCache() {
|
|
2785
|
+
this.calculationCache = {};
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
/**
|
|
2789
|
+
* 批量获取订单数据(用于性能优化)
|
|
2790
|
+
* 一次性获取所有需要的数据,避免重复查询
|
|
2791
|
+
*/
|
|
2792
|
+
}, {
|
|
2793
|
+
key: "fetchOrderDataBatch",
|
|
2750
2794
|
value: (function () {
|
|
2751
|
-
var
|
|
2752
|
-
var
|
|
2795
|
+
var _fetchOrderDataBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
|
|
2796
|
+
var orderUuid, now, cacheValid, _yield$Promise$all, _yield$Promise$all2, paymentItems, currentOrder;
|
|
2753
2797
|
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
2754
2798
|
while (1) switch (_context31.prev = _context31.next) {
|
|
2755
2799
|
case 0:
|
|
2756
2800
|
if (this.store.currentOrder) {
|
|
2757
|
-
_context31.next =
|
|
2801
|
+
_context31.next = 2;
|
|
2802
|
+
break;
|
|
2803
|
+
}
|
|
2804
|
+
return _context31.abrupt("return", {
|
|
2805
|
+
paymentItems: [],
|
|
2806
|
+
currentOrder: null
|
|
2807
|
+
});
|
|
2808
|
+
case 2:
|
|
2809
|
+
orderUuid = this.store.currentOrder.uuid; // 检查缓存是否有效(5秒内的缓存认为有效)
|
|
2810
|
+
now = Date.now();
|
|
2811
|
+
cacheValid = this.calculationCache.orderUuid === orderUuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5000;
|
|
2812
|
+
if (!(cacheValid && this.calculationCache.paymentItems && this.calculationCache.currentOrder)) {
|
|
2813
|
+
_context31.next = 7;
|
|
2814
|
+
break;
|
|
2815
|
+
}
|
|
2816
|
+
return _context31.abrupt("return", {
|
|
2817
|
+
paymentItems: this.calculationCache.paymentItems,
|
|
2818
|
+
currentOrder: this.calculationCache.currentOrder
|
|
2819
|
+
});
|
|
2820
|
+
case 7:
|
|
2821
|
+
_context31.next = 9;
|
|
2822
|
+
return Promise.all([this.payment.getPaymentItemsAsync(orderUuid, false), this.payment.getPaymentOrderByUuidAsync(orderUuid)]);
|
|
2823
|
+
case 9:
|
|
2824
|
+
_yield$Promise$all = _context31.sent;
|
|
2825
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
2826
|
+
paymentItems = _yield$Promise$all2[0];
|
|
2827
|
+
currentOrder = _yield$Promise$all2[1];
|
|
2828
|
+
// 更新缓存
|
|
2829
|
+
this.calculationCache = {
|
|
2830
|
+
paymentItems: paymentItems,
|
|
2831
|
+
currentOrder: currentOrder,
|
|
2832
|
+
orderUuid: orderUuid,
|
|
2833
|
+
timestamp: now
|
|
2834
|
+
};
|
|
2835
|
+
return _context31.abrupt("return", {
|
|
2836
|
+
paymentItems: paymentItems,
|
|
2837
|
+
currentOrder: currentOrder
|
|
2838
|
+
});
|
|
2839
|
+
case 15:
|
|
2840
|
+
case "end":
|
|
2841
|
+
return _context31.stop();
|
|
2842
|
+
}
|
|
2843
|
+
}, _callee31, this);
|
|
2844
|
+
}));
|
|
2845
|
+
function fetchOrderDataBatch() {
|
|
2846
|
+
return _fetchOrderDataBatch.apply(this, arguments);
|
|
2847
|
+
}
|
|
2848
|
+
return fetchOrderDataBatch;
|
|
2849
|
+
}()
|
|
2850
|
+
/**
|
|
2851
|
+
* 从支付项数组计算已支付金额(纯计算,不查询数据库)
|
|
2852
|
+
*/
|
|
2853
|
+
)
|
|
2854
|
+
}, {
|
|
2855
|
+
key: "calculatePaidAmountFromItems",
|
|
2856
|
+
value: function calculatePaidAmountFromItems(payments) {
|
|
2857
|
+
// 使用 Decimal.js 进行安全的金额计算
|
|
2858
|
+
var paidAmount = payments.filter(function (payment) {
|
|
2859
|
+
return payment.status !== 'voided';
|
|
2860
|
+
}) // 只计算未撤销的支付项
|
|
2861
|
+
.reduce(function (sum, payment) {
|
|
2862
|
+
var amount = new Decimal(payment.amount || '0');
|
|
2863
|
+
var roundingAmount = new Decimal(payment.rounding_amount || '0');
|
|
2864
|
+
|
|
2865
|
+
// 使用 Decimal.js 计算实际支付有效金额:
|
|
2866
|
+
// 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
|
|
2867
|
+
// 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
|
|
2868
|
+
var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
2869
|
+
return sum.add(effectiveAmount);
|
|
2870
|
+
}, new Decimal(0));
|
|
2871
|
+
return paidAmount.toFixed(2);
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
/**
|
|
2875
|
+
* 计算已支付金额(从 Payment 模块获取最新数据)
|
|
2876
|
+
*
|
|
2877
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
2878
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
2879
|
+
*/
|
|
2880
|
+
}, {
|
|
2881
|
+
key: "calculatePaidAmountAsync",
|
|
2882
|
+
value: (function () {
|
|
2883
|
+
var _calculatePaidAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32() {
|
|
2884
|
+
var now, cacheValid, payments, result;
|
|
2885
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
2886
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
2887
|
+
case 0:
|
|
2888
|
+
if (this.store.currentOrder) {
|
|
2889
|
+
_context32.next = 3;
|
|
2758
2890
|
break;
|
|
2759
2891
|
}
|
|
2760
2892
|
this.logWarning('[Checkout] calculatePaidAmountAsync: 没有当前订单');
|
|
2761
|
-
return
|
|
2893
|
+
return _context32.abrupt("return", '0.00');
|
|
2762
2894
|
case 3:
|
|
2763
|
-
|
|
2764
|
-
|
|
2895
|
+
_context32.prev = 3;
|
|
2896
|
+
// 检查是否有缓存的已支付金额
|
|
2897
|
+
now = Date.now();
|
|
2898
|
+
cacheValid = this.calculationCache.orderUuid === this.store.currentOrder.uuid && this.calculationCache.timestamp && now - this.calculationCache.timestamp < 5000 && this.calculationCache.paidAmount;
|
|
2899
|
+
if (!(cacheValid && this.calculationCache.paidAmount)) {
|
|
2900
|
+
_context32.next = 8;
|
|
2901
|
+
break;
|
|
2902
|
+
}
|
|
2903
|
+
return _context32.abrupt("return", this.calculationCache.paidAmount);
|
|
2904
|
+
case 8:
|
|
2905
|
+
_context32.next = 10;
|
|
2765
2906
|
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
|
|
2766
2907
|
);
|
|
2767
|
-
case
|
|
2768
|
-
payments =
|
|
2769
|
-
|
|
2770
|
-
paidAmount =
|
|
2771
|
-
return payment.status !== 'voided';
|
|
2772
|
-
}) // 只计算未撤销的支付项
|
|
2773
|
-
.reduce(function (sum, payment) {
|
|
2774
|
-
var amount = new Decimal(payment.amount || '0');
|
|
2775
|
-
var roundingAmount = new Decimal(payment.rounding_amount || '0');
|
|
2776
|
-
|
|
2777
|
-
// 使用 Decimal.js 计算实际支付有效金额:
|
|
2778
|
-
// 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
|
|
2779
|
-
// 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
|
|
2780
|
-
var effectiveAmount = amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0);
|
|
2781
|
-
console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code), {
|
|
2782
|
-
originalAmount: amount.toFixed(2),
|
|
2783
|
-
roundingAmount: roundingAmount.toFixed(2),
|
|
2784
|
-
effectiveAmount: effectiveAmount.toFixed(2),
|
|
2785
|
-
description: !roundingAmount.isZero() ? "\u62B9\u96F6\u91D1\u989D ".concat(roundingAmount.toFixed(2), " \u5143\uFF0C\u6709\u6548\u652F\u4ED8\u589E\u52A0 ").concat(roundingAmount.abs().toFixed(2), " \u5143") : '无抹零',
|
|
2786
|
-
// Decimal 精度验证
|
|
2787
|
-
preciseCalculationValues: {
|
|
2788
|
-
amount: amount.toString(),
|
|
2789
|
-
roundingAmount: roundingAmount.toString(),
|
|
2790
|
-
effectiveAmount: effectiveAmount.toString()
|
|
2791
|
-
}
|
|
2792
|
-
});
|
|
2793
|
-
return sum.add(effectiveAmount);
|
|
2794
|
-
}, new Decimal(0));
|
|
2795
|
-
result = paidAmount.toFixed(2);
|
|
2908
|
+
case 10:
|
|
2909
|
+
payments = _context32.sent;
|
|
2910
|
+
result = this.calculatePaidAmountFromItems(payments); // 更新缓存
|
|
2911
|
+
this.calculationCache.paidAmount = result;
|
|
2796
2912
|
this.logInfo('calculatePaidAmountAsync: 计算结果 =', result);
|
|
2797
|
-
return
|
|
2798
|
-
case 13:
|
|
2799
|
-
_context31.prev = 13;
|
|
2800
|
-
_context31.t0 = _context31["catch"](3);
|
|
2801
|
-
this.logError('calculatePaidAmountAsync 失败:', _context31.t0);
|
|
2802
|
-
return _context31.abrupt("return", '0.00');
|
|
2913
|
+
return _context32.abrupt("return", result);
|
|
2803
2914
|
case 17:
|
|
2915
|
+
_context32.prev = 17;
|
|
2916
|
+
_context32.t0 = _context32["catch"](3);
|
|
2917
|
+
this.logError('calculatePaidAmountAsync 失败:', _context32.t0);
|
|
2918
|
+
return _context32.abrupt("return", '0.00');
|
|
2919
|
+
case 21:
|
|
2804
2920
|
case "end":
|
|
2805
|
-
return
|
|
2921
|
+
return _context32.stop();
|
|
2806
2922
|
}
|
|
2807
|
-
},
|
|
2923
|
+
}, _callee32, this, [[3, 17]]);
|
|
2808
2924
|
}));
|
|
2809
2925
|
function calculatePaidAmountAsync() {
|
|
2810
2926
|
return _calculatePaidAmountAsync.apply(this, arguments);
|
|
@@ -2812,47 +2928,85 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2812
2928
|
return calculatePaidAmountAsync;
|
|
2813
2929
|
}()
|
|
2814
2930
|
/**
|
|
2815
|
-
*
|
|
2931
|
+
* 从订单和支付项计算剩余金额(纯计算,不查询数据库)
|
|
2816
2932
|
*/
|
|
2817
2933
|
)
|
|
2934
|
+
}, {
|
|
2935
|
+
key: "calculateRemainingAmountFromData",
|
|
2936
|
+
value: function calculateRemainingAmountFromData(currentOrder, paidAmount) {
|
|
2937
|
+
// 使用 Decimal.js 进行安全的金额计算
|
|
2938
|
+
var totalAmount = new Decimal(currentOrder.total_amount || '0');
|
|
2939
|
+
|
|
2940
|
+
// 如果是定金订单,使用定金金额
|
|
2941
|
+
if (currentOrder.is_deposit && currentOrder.deposit_amount && Number(currentOrder.deposit_amount) > 0) {
|
|
2942
|
+
totalAmount = new Decimal(currentOrder.deposit_amount);
|
|
2943
|
+
}
|
|
2944
|
+
var paid = new Decimal(paidAmount);
|
|
2945
|
+
var remainingAmount = totalAmount.sub(paid);
|
|
2946
|
+
|
|
2947
|
+
// 确保剩余金额不为负数
|
|
2948
|
+
return Decimal.max(0, remainingAmount).toFixed(2);
|
|
2949
|
+
}
|
|
2950
|
+
|
|
2951
|
+
/**
|
|
2952
|
+
* 从订单和支付项计算剩余总金额(纯计算,排除定金)
|
|
2953
|
+
*/
|
|
2954
|
+
}, {
|
|
2955
|
+
key: "calculateRemainingTotalAmountFromData",
|
|
2956
|
+
value: function calculateRemainingTotalAmountFromData(currentOrder, paidAmount) {
|
|
2957
|
+
// 始终使用订单总金额,不进行定金相关的计算
|
|
2958
|
+
var totalAmount = new Decimal(currentOrder.total_amount || '0');
|
|
2959
|
+
var paid = new Decimal(paidAmount);
|
|
2960
|
+
var remainingAmount = totalAmount.sub(paid);
|
|
2961
|
+
|
|
2962
|
+
// 确保剩余金额不为负数
|
|
2963
|
+
return Decimal.max(0, remainingAmount).toFixed(2);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
/**
|
|
2967
|
+
* 计算剩余未支付金额(从 Payment 模块获取最新数据)
|
|
2968
|
+
*
|
|
2969
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
2970
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
2971
|
+
*/
|
|
2818
2972
|
}, {
|
|
2819
2973
|
key: "calculateRemainingAmountAsync",
|
|
2820
2974
|
value: (function () {
|
|
2821
|
-
var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2822
|
-
var
|
|
2823
|
-
return _regeneratorRuntime().wrap(function
|
|
2824
|
-
while (1) switch (
|
|
2975
|
+
var _calculateRemainingAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
2976
|
+
var _yield$this$fetchOrde, currentOrder, paidAmountStr, result;
|
|
2977
|
+
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
2978
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
2825
2979
|
case 0:
|
|
2826
2980
|
if (this.store.currentOrder) {
|
|
2827
|
-
|
|
2981
|
+
_context33.next = 3;
|
|
2828
2982
|
break;
|
|
2829
2983
|
}
|
|
2830
2984
|
this.logWarning('calculateRemainingAmountAsync: 没有当前订单');
|
|
2831
|
-
return
|
|
2985
|
+
return _context33.abrupt("return", '0.00');
|
|
2832
2986
|
case 3:
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
currentOrder
|
|
2839
|
-
|
|
2840
|
-
|
|
2987
|
+
_context33.next = 5;
|
|
2988
|
+
return this.fetchOrderDataBatch();
|
|
2989
|
+
case 5:
|
|
2990
|
+
_yield$this$fetchOrde = _context33.sent;
|
|
2991
|
+
currentOrder = _yield$this$fetchOrde.currentOrder;
|
|
2992
|
+
if (currentOrder) {
|
|
2993
|
+
_context33.next = 9;
|
|
2994
|
+
break;
|
|
2841
2995
|
}
|
|
2842
|
-
|
|
2996
|
+
return _context33.abrupt("return", '0.00');
|
|
2997
|
+
case 9:
|
|
2998
|
+
_context33.next = 11;
|
|
2843
2999
|
return this.calculatePaidAmountAsync();
|
|
2844
|
-
case
|
|
2845
|
-
paidAmountStr =
|
|
2846
|
-
|
|
2847
|
-
remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
|
|
2848
|
-
result = Decimal.max(0, remainingAmount).toFixed(2);
|
|
3000
|
+
case 11:
|
|
3001
|
+
paidAmountStr = _context33.sent;
|
|
3002
|
+
result = this.calculateRemainingAmountFromData(currentOrder, paidAmountStr);
|
|
2849
3003
|
this.logInfo('calculateRemainingAmountAsync: 计算=', result);
|
|
2850
|
-
return
|
|
2851
|
-
case
|
|
3004
|
+
return _context33.abrupt("return", result);
|
|
3005
|
+
case 15:
|
|
2852
3006
|
case "end":
|
|
2853
|
-
return
|
|
3007
|
+
return _context33.stop();
|
|
2854
3008
|
}
|
|
2855
|
-
},
|
|
3009
|
+
}, _callee33, this);
|
|
2856
3010
|
}));
|
|
2857
3011
|
function calculateRemainingAmountAsync() {
|
|
2858
3012
|
return _calculateRemainingAmountAsync.apply(this, arguments);
|
|
@@ -2861,40 +3015,49 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2861
3015
|
}()
|
|
2862
3016
|
/**
|
|
2863
3017
|
* 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
|
|
3018
|
+
*
|
|
3019
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
3020
|
+
* 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
|
|
2864
3021
|
*/
|
|
2865
3022
|
)
|
|
2866
3023
|
}, {
|
|
2867
3024
|
key: "calculateRemainingTotalAmountAsync",
|
|
2868
3025
|
value: (function () {
|
|
2869
|
-
var _calculateRemainingTotalAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2870
|
-
var
|
|
2871
|
-
return _regeneratorRuntime().wrap(function
|
|
2872
|
-
while (1) switch (
|
|
3026
|
+
var _calculateRemainingTotalAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
|
|
3027
|
+
var _yield$this$fetchOrde2, currentOrder, paidAmountStr, result;
|
|
3028
|
+
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
3029
|
+
while (1) switch (_context34.prev = _context34.next) {
|
|
2873
3030
|
case 0:
|
|
2874
3031
|
if (this.store.currentOrder) {
|
|
2875
|
-
|
|
3032
|
+
_context34.next = 3;
|
|
2876
3033
|
break;
|
|
2877
3034
|
}
|
|
2878
3035
|
this.logWarning('calculateRemainingTotalAmountAsync: 没有当前订单');
|
|
2879
|
-
return
|
|
3036
|
+
return _context34.abrupt("return", '0.00');
|
|
2880
3037
|
case 3:
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
3038
|
+
_context34.next = 5;
|
|
3039
|
+
return this.fetchOrderDataBatch();
|
|
3040
|
+
case 5:
|
|
3041
|
+
_yield$this$fetchOrde2 = _context34.sent;
|
|
3042
|
+
currentOrder = _yield$this$fetchOrde2.currentOrder;
|
|
3043
|
+
if (currentOrder) {
|
|
3044
|
+
_context34.next = 9;
|
|
3045
|
+
break;
|
|
3046
|
+
}
|
|
3047
|
+
return _context34.abrupt("return", '0.00');
|
|
3048
|
+
case 9:
|
|
3049
|
+
_context34.next = 11;
|
|
2885
3050
|
return this.calculatePaidAmountAsync();
|
|
2886
|
-
case
|
|
2887
|
-
paidAmountStr =
|
|
2888
|
-
|
|
2889
|
-
remainingAmount = totalAmount.sub(paidAmount); // 确保剩余金额不为负数
|
|
2890
|
-
result = Decimal.max(0, remainingAmount).toFixed(2);
|
|
3051
|
+
case 11:
|
|
3052
|
+
paidAmountStr = _context34.sent;
|
|
3053
|
+
result = this.calculateRemainingTotalAmountFromData(currentOrder, paidAmountStr);
|
|
2891
3054
|
this.logInfo('calculateRemainingTotalAmountAsync: 计算=', result);
|
|
2892
|
-
return
|
|
2893
|
-
case
|
|
3055
|
+
return _context34.abrupt("return", result);
|
|
3056
|
+
case 15:
|
|
2894
3057
|
case "end":
|
|
2895
|
-
return
|
|
3058
|
+
return _context34.stop();
|
|
2896
3059
|
}
|
|
2897
|
-
},
|
|
3060
|
+
}, _callee34, this);
|
|
2898
3061
|
}));
|
|
2899
3062
|
function calculateRemainingTotalAmountAsync() {
|
|
2900
3063
|
return _calculateRemainingTotalAmountAsync.apply(this, arguments);
|
|
@@ -2908,29 +3071,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2908
3071
|
}, {
|
|
2909
3072
|
key: "updateBalanceDueAmount",
|
|
2910
3073
|
value: (function () {
|
|
2911
|
-
var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3074
|
+
var _updateBalanceDueAmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
|
|
2912
3075
|
var remainingAmount, remainingTotalAmount, currentBalanceDueAmount;
|
|
2913
|
-
return _regeneratorRuntime().wrap(function
|
|
2914
|
-
while (1) switch (
|
|
3076
|
+
return _regeneratorRuntime().wrap(function _callee35$(_context35) {
|
|
3077
|
+
while (1) switch (_context35.prev = _context35.next) {
|
|
2915
3078
|
case 0:
|
|
2916
|
-
|
|
2917
|
-
|
|
3079
|
+
_context35.prev = 0;
|
|
3080
|
+
_context35.next = 3;
|
|
2918
3081
|
return this.calculateRemainingAmountAsync();
|
|
2919
3082
|
case 3:
|
|
2920
|
-
remainingAmount =
|
|
2921
|
-
|
|
3083
|
+
remainingAmount = _context35.sent;
|
|
3084
|
+
_context35.next = 6;
|
|
2922
3085
|
return this.calculateRemainingTotalAmountAsync();
|
|
2923
3086
|
case 6:
|
|
2924
|
-
remainingTotalAmount =
|
|
3087
|
+
remainingTotalAmount = _context35.sent;
|
|
2925
3088
|
currentBalanceDueAmount = this.store.balanceDueAmount; // 只有当剩余金额与当前 balanceDueAmount 不同时才更新
|
|
2926
3089
|
if (!(remainingAmount !== currentBalanceDueAmount)) {
|
|
2927
|
-
|
|
3090
|
+
_context35.next = 15;
|
|
2928
3091
|
break;
|
|
2929
3092
|
}
|
|
2930
3093
|
this.store.balanceDueAmount = remainingAmount;
|
|
2931
3094
|
|
|
2932
3095
|
// 发出 balanceDueAmount 变更事件
|
|
2933
|
-
|
|
3096
|
+
_context35.next = 12;
|
|
2934
3097
|
return this.core.effects.emit("".concat(this.name, ":onBalanceDueAmountChanged"), {
|
|
2935
3098
|
oldAmount: currentBalanceDueAmount,
|
|
2936
3099
|
newAmount: remainingAmount,
|
|
@@ -2942,7 +3105,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2942
3105
|
oldAmount: currentBalanceDueAmount,
|
|
2943
3106
|
newAmount: remainingAmount
|
|
2944
3107
|
});
|
|
2945
|
-
|
|
3108
|
+
_context35.next = 16;
|
|
2946
3109
|
break;
|
|
2947
3110
|
case 15:
|
|
2948
3111
|
this.logInfo('balanceDueAmount 无需更新,当前值已是最新:', {
|
|
@@ -2950,17 +3113,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2950
3113
|
remainingAmount: remainingAmount
|
|
2951
3114
|
});
|
|
2952
3115
|
case 16:
|
|
2953
|
-
|
|
3116
|
+
_context35.next = 21;
|
|
2954
3117
|
break;
|
|
2955
3118
|
case 18:
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
this.logError('更新 balanceDueAmount 失败:',
|
|
3119
|
+
_context35.prev = 18;
|
|
3120
|
+
_context35.t0 = _context35["catch"](0);
|
|
3121
|
+
this.logError('更新 balanceDueAmount 失败:', _context35.t0);
|
|
2959
3122
|
case 21:
|
|
2960
3123
|
case "end":
|
|
2961
|
-
return
|
|
3124
|
+
return _context35.stop();
|
|
2962
3125
|
}
|
|
2963
|
-
},
|
|
3126
|
+
}, _callee35, this, [[0, 18]]);
|
|
2964
3127
|
}));
|
|
2965
3128
|
function updateBalanceDueAmount() {
|
|
2966
3129
|
return _updateBalanceDueAmount.apply(this, arguments);
|
|
@@ -2969,156 +3132,323 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2969
3132
|
}()
|
|
2970
3133
|
/**
|
|
2971
3134
|
* 更新 stateAmount 为当前剩余未支付金额
|
|
3135
|
+
*
|
|
3136
|
+
* 优化版本:批量获取数据,避免重复查询数据库
|
|
2972
3137
|
*/
|
|
2973
3138
|
)
|
|
2974
3139
|
}, {
|
|
2975
3140
|
key: "updateStateAmountToRemaining",
|
|
2976
3141
|
value: (function () {
|
|
2977
|
-
var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3142
|
+
var _updateStateAmountToRemaining = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36() {
|
|
3143
|
+
var _this4 = this;
|
|
2978
3144
|
var checkOrder,
|
|
2979
|
-
|
|
2980
|
-
_this$store$currentOr24,
|
|
2981
|
-
_this$store$currentOr25,
|
|
3145
|
+
_yield$this$fetchOrde3,
|
|
2982
3146
|
paymentItems,
|
|
3147
|
+
_currentOrder3,
|
|
3148
|
+
paidAmount,
|
|
3149
|
+
needUpdateDepositStatus,
|
|
2983
3150
|
depositPaidAmount,
|
|
2984
|
-
_this$store$currentOr26,
|
|
2985
3151
|
remainingAmount,
|
|
2986
3152
|
remainingTotalAmount,
|
|
2987
3153
|
currentStateAmount,
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3154
|
+
currentBalanceDueAmount,
|
|
3155
|
+
hasStateChanged,
|
|
3156
|
+
_args36 = arguments;
|
|
3157
|
+
return _regeneratorRuntime().wrap(function _callee36$(_context36) {
|
|
3158
|
+
while (1) switch (_context36.prev = _context36.next) {
|
|
2991
3159
|
case 0:
|
|
2992
|
-
checkOrder =
|
|
2993
|
-
|
|
2994
|
-
if (
|
|
2995
|
-
|
|
3160
|
+
checkOrder = _args36.length > 0 && _args36[0] !== undefined ? _args36[0] : true;
|
|
3161
|
+
_context36.prev = 1;
|
|
3162
|
+
if (this.store.currentOrder) {
|
|
3163
|
+
_context36.next = 4;
|
|
2996
3164
|
break;
|
|
2997
3165
|
}
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3166
|
+
return _context36.abrupt("return");
|
|
3167
|
+
case 4:
|
|
3168
|
+
console.time('updateStateAmountToRemaining');
|
|
3169
|
+
// 🚀 性能优化:一次性批量获取所有需要的数据
|
|
3170
|
+
_context36.next = 7;
|
|
3171
|
+
return this.fetchOrderDataBatch();
|
|
3172
|
+
case 7:
|
|
3173
|
+
_yield$this$fetchOrde3 = _context36.sent;
|
|
3174
|
+
paymentItems = _yield$this$fetchOrde3.paymentItems;
|
|
3175
|
+
_currentOrder3 = _yield$this$fetchOrde3.currentOrder;
|
|
3176
|
+
console.timeEnd('updateStateAmountToRemaining');
|
|
3177
|
+
if (_currentOrder3) {
|
|
3178
|
+
_context36.next = 14;
|
|
3179
|
+
break;
|
|
3180
|
+
}
|
|
3181
|
+
this.logWarning('updateStateAmountToRemaining: 未找到当前订单');
|
|
3182
|
+
return _context36.abrupt("return");
|
|
3183
|
+
case 14:
|
|
3184
|
+
// 🚀 性能优化:一次性计算所有金额(纯计算,不查询数据库)
|
|
3185
|
+
paidAmount = this.calculatePaidAmountFromItems(paymentItems); // 缓存已支付金额,供其他方法使用
|
|
3186
|
+
this.calculationCache.paidAmount = paidAmount;
|
|
3187
|
+
|
|
3188
|
+
// 检查定金支付状态,可能需要切换支付模式
|
|
3189
|
+
needUpdateDepositStatus = false;
|
|
3190
|
+
if (_currentOrder3.is_deposit === 1) {
|
|
3191
|
+
depositPaidAmount = paymentItems.filter(function (item) {
|
|
3192
|
+
return item.order_payment_type === 'deposit' && item.status !== 'voided';
|
|
3193
|
+
}).reduce(function (sum, item) {
|
|
3194
|
+
// 如果是 wallet,并且还没同步到后端,则不计入这一部分金额
|
|
3195
|
+
if (item.voucher_id && !item.isSynced) {
|
|
3196
|
+
return sum;
|
|
3197
|
+
}
|
|
3198
|
+
var amount = new Decimal(item.amount || '0');
|
|
3199
|
+
var roundingAmount = new Decimal(item.rounding_amount || '0');
|
|
3200
|
+
return sum.add(amount.add(roundingAmount.isNegative() ? roundingAmount.abs() : 0));
|
|
3201
|
+
}, new Decimal(0));
|
|
3202
|
+
if (depositPaidAmount.gte(_currentOrder3.deposit_amount || '0')) {
|
|
3203
|
+
needUpdateDepositStatus = true;
|
|
3204
|
+
// 更新缓存中的订单状态
|
|
3205
|
+
_currentOrder3.is_deposit = 0;
|
|
3008
3206
|
}
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3207
|
+
}
|
|
3208
|
+
|
|
3209
|
+
// 计算剩余金额(使用缓存的数据)
|
|
3210
|
+
remainingAmount = this.calculateRemainingAmountFromData(_currentOrder3, paidAmount);
|
|
3211
|
+
remainingTotalAmount = this.calculateRemainingTotalAmountFromData(_currentOrder3, paidAmount);
|
|
3212
|
+
currentStateAmount = this.store.stateAmount;
|
|
3213
|
+
currentBalanceDueAmount = this.store.balanceDueAmount; // 批量更新状态,减少操作次数
|
|
3214
|
+
hasStateChanged = false; // 如果需要更新定金状态
|
|
3215
|
+
if (!needUpdateDepositStatus) {
|
|
3216
|
+
_context36.next = 28;
|
|
3015
3217
|
break;
|
|
3016
3218
|
}
|
|
3017
3219
|
this.store.currentOrder = _objectSpread(_objectSpread({}, this.store.currentOrder), {}, {
|
|
3018
3220
|
is_deposit: 0
|
|
3019
3221
|
});
|
|
3020
|
-
|
|
3021
|
-
return this.payment.updateOrderAsync(
|
|
3222
|
+
_context36.next = 27;
|
|
3223
|
+
return this.payment.updateOrderAsync(this.store.currentOrder.uuid, {
|
|
3022
3224
|
is_deposit: 0
|
|
3023
3225
|
});
|
|
3024
|
-
case
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
_context35.next = 16;
|
|
3030
|
-
return this.calculateRemainingTotalAmountAsync();
|
|
3031
|
-
case 16:
|
|
3032
|
-
remainingTotalAmount = _context35.sent;
|
|
3033
|
-
currentStateAmount = this.store.stateAmount; // 只有当剩余金额与当前 stateAmount 不同时才更新
|
|
3226
|
+
case 27:
|
|
3227
|
+
hasStateChanged = true;
|
|
3228
|
+
case 28:
|
|
3229
|
+
console.time('updateStateAmountToRemaining: remainingAmount');
|
|
3230
|
+
// 更新 stateAmount
|
|
3034
3231
|
if (remainingAmount !== currentStateAmount) {
|
|
3035
3232
|
this.store.stateAmount = remainingAmount;
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3233
|
+
hasStateChanged = true;
|
|
3234
|
+
setTimeout(function () {
|
|
3235
|
+
// 发出 stateAmount 变更事件
|
|
3236
|
+
_this4.core.effects.emit("".concat(_this4.name, ":onStateAmountChanged"), {
|
|
3237
|
+
oldAmount: currentStateAmount,
|
|
3238
|
+
newAmount: remainingAmount,
|
|
3239
|
+
timestamp: Date.now(),
|
|
3240
|
+
totalAmount: remainingTotalAmount
|
|
3241
|
+
});
|
|
3242
|
+
}, 0);
|
|
3044
3243
|
this.logInfo('stateAmount 已自动更新为剩余金额:', {
|
|
3045
3244
|
oldAmount: currentStateAmount,
|
|
3046
3245
|
newAmount: remainingAmount
|
|
3047
3246
|
});
|
|
3048
|
-
}
|
|
3049
|
-
|
|
3247
|
+
}
|
|
3248
|
+
console.timeEnd('updateStateAmountToRemaining: remainingAmount');
|
|
3249
|
+
console.time('updateStateAmountToRemaining: updateStateAmountToRemaining');
|
|
3250
|
+
// 更新 balanceDueAmount
|
|
3251
|
+
if (remainingAmount !== currentBalanceDueAmount) {
|
|
3252
|
+
this.store.balanceDueAmount = remainingAmount;
|
|
3253
|
+
hasStateChanged = true;
|
|
3254
|
+
|
|
3255
|
+
// 发出 balanceDueAmount 变更事件
|
|
3256
|
+
setTimeout(function () {
|
|
3257
|
+
_this4.core.effects.emit("".concat(_this4.name, ":onBalanceDueAmountChanged"), {
|
|
3258
|
+
oldAmount: currentBalanceDueAmount,
|
|
3259
|
+
newAmount: remainingAmount,
|
|
3260
|
+
timestamp: Date.now(),
|
|
3261
|
+
totalAmount: remainingTotalAmount
|
|
3262
|
+
});
|
|
3263
|
+
}, 0);
|
|
3264
|
+
this.logInfo('balanceDueAmount 已自动更新:', {
|
|
3265
|
+
oldAmount: currentBalanceDueAmount,
|
|
3266
|
+
newAmount: remainingAmount
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
3269
|
+
console.timeEnd('updateStateAmountToRemaining: updateStateAmountToRemaining');
|
|
3270
|
+
if (!hasStateChanged) {
|
|
3271
|
+
this.logInfo('状态无需更新,当前值已是最新:', {
|
|
3050
3272
|
stateAmount: currentStateAmount,
|
|
3051
3273
|
remainingAmount: remainingAmount
|
|
3052
3274
|
});
|
|
3053
3275
|
}
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
return this.updateBalanceDueAmount();
|
|
3057
|
-
case 21:
|
|
3276
|
+
|
|
3277
|
+
// 检查订单支付完成(复用已获取的数据)
|
|
3058
3278
|
if (!checkOrder) {
|
|
3059
|
-
|
|
3279
|
+
_context36.next = 40;
|
|
3060
3280
|
break;
|
|
3061
3281
|
}
|
|
3062
|
-
|
|
3063
|
-
return this.
|
|
3064
|
-
case
|
|
3065
|
-
|
|
3282
|
+
_context36.next = 38;
|
|
3283
|
+
return this.checkOrderPaymentCompletionOptimized(paymentItems, remainingAmount);
|
|
3284
|
+
case 38:
|
|
3285
|
+
_context36.next = 41;
|
|
3066
3286
|
break;
|
|
3067
|
-
case
|
|
3287
|
+
case 40:
|
|
3068
3288
|
this.logInfo('外部传入无需 checkOrder,不执行订单支付完成检测和同步');
|
|
3069
|
-
case
|
|
3070
|
-
|
|
3289
|
+
case 41:
|
|
3290
|
+
_context36.next = 46;
|
|
3071
3291
|
break;
|
|
3072
|
-
case
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
this.logError('更新 stateAmount 为剩余金额失败:',
|
|
3076
|
-
case
|
|
3292
|
+
case 43:
|
|
3293
|
+
_context36.prev = 43;
|
|
3294
|
+
_context36.t0 = _context36["catch"](1);
|
|
3295
|
+
this.logError('更新 stateAmount 为剩余金额失败:', _context36.t0);
|
|
3296
|
+
case 46:
|
|
3077
3297
|
case "end":
|
|
3078
|
-
return
|
|
3298
|
+
return _context36.stop();
|
|
3079
3299
|
}
|
|
3080
|
-
},
|
|
3300
|
+
}, _callee36, this, [[1, 43]]);
|
|
3081
3301
|
}));
|
|
3082
3302
|
function updateStateAmountToRemaining() {
|
|
3083
3303
|
return _updateStateAmountToRemaining.apply(this, arguments);
|
|
3084
3304
|
}
|
|
3085
3305
|
return updateStateAmountToRemaining;
|
|
3086
3306
|
}()
|
|
3307
|
+
/**
|
|
3308
|
+
* 检查订单支付是否完成(优化版,复用已获取的数据)
|
|
3309
|
+
*
|
|
3310
|
+
* @param paymentItems 已获取的支付项数据
|
|
3311
|
+
* @param remainingAmount 已计算的剩余金额
|
|
3312
|
+
*/
|
|
3313
|
+
)
|
|
3314
|
+
}, {
|
|
3315
|
+
key: "checkOrderPaymentCompletionOptimized",
|
|
3316
|
+
value: (function () {
|
|
3317
|
+
var _checkOrderPaymentCompletionOptimized = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(paymentItems, remainingAmount) {
|
|
3318
|
+
var remainingValue, totalAmount, paidAmount, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
|
|
3319
|
+
return _regeneratorRuntime().wrap(function _callee37$(_context37) {
|
|
3320
|
+
while (1) switch (_context37.prev = _context37.next) {
|
|
3321
|
+
case 0:
|
|
3322
|
+
_context37.prev = 0;
|
|
3323
|
+
if (this.store.currentOrder) {
|
|
3324
|
+
_context37.next = 3;
|
|
3325
|
+
break;
|
|
3326
|
+
}
|
|
3327
|
+
return _context37.abrupt("return");
|
|
3328
|
+
case 3:
|
|
3329
|
+
remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
|
|
3330
|
+
if (!remainingValue.lte(0)) {
|
|
3331
|
+
_context37.next = 21;
|
|
3332
|
+
break;
|
|
3333
|
+
}
|
|
3334
|
+
totalAmount = this.store.currentOrder.total_amount;
|
|
3335
|
+
paidAmount = this.calculationCache.paidAmount || '0.00';
|
|
3336
|
+
this.logInfo('检测到订单支付完成:', {
|
|
3337
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
3338
|
+
orderId: this.store.currentOrder.order_id,
|
|
3339
|
+
totalAmount: totalAmount,
|
|
3340
|
+
paidAmount: paidAmount,
|
|
3341
|
+
remainingAmount: remainingAmount,
|
|
3342
|
+
isOrderSynced: this.store.isOrderSynced
|
|
3343
|
+
});
|
|
3344
|
+
|
|
3345
|
+
// 检查自动同步条件(复用已获取的支付项数据)
|
|
3346
|
+
hasPaymentItems = paymentItems.length > 0;
|
|
3347
|
+
allPaymentsHaveVoucherId = hasPaymentItems && paymentItems.every(function (item) {
|
|
3348
|
+
return item.status !== 'voided' && item.voucher_id;
|
|
3349
|
+
});
|
|
3350
|
+
shouldAutoSync = hasPaymentItems && !allPaymentsHaveVoucherId;
|
|
3351
|
+
this.logInfo('自动同步订单条件检查:', {
|
|
3352
|
+
paymentCount: paymentItems.length,
|
|
3353
|
+
hasPaymentItems: hasPaymentItems,
|
|
3354
|
+
allHaveVoucherId: allPaymentsHaveVoucherId,
|
|
3355
|
+
isOrderSynced: this.store.isOrderSynced,
|
|
3356
|
+
shouldAutoSync: shouldAutoSync,
|
|
3357
|
+
reason: shouldAutoSync ? '支付完成,需要同步最终支付状态' : '跳过同步',
|
|
3358
|
+
paymentItems: paymentItems.map(function (p) {
|
|
3359
|
+
return {
|
|
3360
|
+
uuid: p.uuid,
|
|
3361
|
+
code: p.code,
|
|
3362
|
+
amount: p.amount,
|
|
3363
|
+
rounding_amount: p.rounding_amount,
|
|
3364
|
+
effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(Number(p.rounding_amount) > 0 ? '0' : p.rounding_amount || '0'))).toFixed(2),
|
|
3365
|
+
voucher_id: p.voucher_id,
|
|
3366
|
+
status: p.status
|
|
3367
|
+
};
|
|
3368
|
+
})
|
|
3369
|
+
});
|
|
3370
|
+
if (!shouldAutoSync) {
|
|
3371
|
+
_context37.next = 18;
|
|
3372
|
+
break;
|
|
3373
|
+
}
|
|
3374
|
+
this.logInfo('满足自动同步条件,开始同步订单到后端...');
|
|
3375
|
+
_context37.next = 16;
|
|
3376
|
+
return this.syncOrderToBackendWithReturn(false);
|
|
3377
|
+
case 16:
|
|
3378
|
+
_context37.next = 19;
|
|
3379
|
+
break;
|
|
3380
|
+
case 18:
|
|
3381
|
+
if (!hasPaymentItems) {
|
|
3382
|
+
this.logInfo('没有支付项,跳过订单同步');
|
|
3383
|
+
} else if (allPaymentsHaveVoucherId) {
|
|
3384
|
+
this.logInfo('所有支付项均为代金券类型,跳过订单同步');
|
|
3385
|
+
}
|
|
3386
|
+
case 19:
|
|
3387
|
+
_context37.next = 21;
|
|
3388
|
+
return this.core.effects.emit("".concat(this.name, ":onOrderPaymentCompleted"), {
|
|
3389
|
+
orderUuid: this.store.currentOrder.uuid,
|
|
3390
|
+
orderId: this.store.currentOrder.order_id,
|
|
3391
|
+
totalAmount: totalAmount,
|
|
3392
|
+
paidAmount: paidAmount,
|
|
3393
|
+
remainingAmount: remainingAmount,
|
|
3394
|
+
timestamp: Date.now()
|
|
3395
|
+
});
|
|
3396
|
+
case 21:
|
|
3397
|
+
_context37.next = 26;
|
|
3398
|
+
break;
|
|
3399
|
+
case 23:
|
|
3400
|
+
_context37.prev = 23;
|
|
3401
|
+
_context37.t0 = _context37["catch"](0);
|
|
3402
|
+
this.logError('检查订单支付完成状态失败:', _context37.t0);
|
|
3403
|
+
case 26:
|
|
3404
|
+
case "end":
|
|
3405
|
+
return _context37.stop();
|
|
3406
|
+
}
|
|
3407
|
+
}, _callee37, this, [[0, 23]]);
|
|
3408
|
+
}));
|
|
3409
|
+
function checkOrderPaymentCompletionOptimized(_x27, _x28) {
|
|
3410
|
+
return _checkOrderPaymentCompletionOptimized.apply(this, arguments);
|
|
3411
|
+
}
|
|
3412
|
+
return checkOrderPaymentCompletionOptimized;
|
|
3413
|
+
}()
|
|
3087
3414
|
/**
|
|
3088
3415
|
* 检查订单支付是否完成
|
|
3089
3416
|
*
|
|
3090
3417
|
* 当剩余待付款金额 <= 0 时,触发订单支付完成事件
|
|
3418
|
+
*
|
|
3419
|
+
* 注意:此方法保持独立性,可以单独调用。
|
|
3420
|
+
* 在 updateStateAmountToRemaining 中会使用优化版本。
|
|
3091
3421
|
*/
|
|
3092
3422
|
)
|
|
3093
3423
|
}, {
|
|
3094
3424
|
key: "checkOrderPaymentCompletion",
|
|
3095
3425
|
value: (function () {
|
|
3096
|
-
var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3426
|
+
var _checkOrderPaymentCompletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38() {
|
|
3097
3427
|
var remainingAmount, remainingValue, totalAmount, paidAmount, currentPayments, hasPaymentItems, allPaymentsHaveVoucherId, shouldAutoSync;
|
|
3098
|
-
return _regeneratorRuntime().wrap(function
|
|
3099
|
-
while (1) switch (
|
|
3428
|
+
return _regeneratorRuntime().wrap(function _callee38$(_context38) {
|
|
3429
|
+
while (1) switch (_context38.prev = _context38.next) {
|
|
3100
3430
|
case 0:
|
|
3101
|
-
|
|
3431
|
+
_context38.prev = 0;
|
|
3102
3432
|
if (this.store.currentOrder) {
|
|
3103
|
-
|
|
3433
|
+
_context38.next = 3;
|
|
3104
3434
|
break;
|
|
3105
3435
|
}
|
|
3106
|
-
return
|
|
3436
|
+
return _context38.abrupt("return");
|
|
3107
3437
|
case 3:
|
|
3108
|
-
|
|
3438
|
+
_context38.next = 5;
|
|
3109
3439
|
return this.calculateRemainingAmountAsync();
|
|
3110
3440
|
case 5:
|
|
3111
|
-
remainingAmount =
|
|
3441
|
+
remainingAmount = _context38.sent;
|
|
3112
3442
|
remainingValue = new Decimal(remainingAmount); // 当剩余金额小于等于0时,认为订单已完成支付
|
|
3113
3443
|
if (!remainingValue.lte(0)) {
|
|
3114
|
-
|
|
3444
|
+
_context38.next = 29;
|
|
3115
3445
|
break;
|
|
3116
3446
|
}
|
|
3117
3447
|
totalAmount = this.store.currentOrder.total_amount;
|
|
3118
|
-
|
|
3448
|
+
_context38.next = 11;
|
|
3119
3449
|
return this.calculatePaidAmountAsync();
|
|
3120
3450
|
case 11:
|
|
3121
|
-
paidAmount =
|
|
3451
|
+
paidAmount = _context38.sent;
|
|
3122
3452
|
this.logInfo('检测到订单支付完成:', {
|
|
3123
3453
|
orderUuid: this.store.currentOrder.uuid,
|
|
3124
3454
|
orderId: this.store.currentOrder.order_id,
|
|
@@ -3129,11 +3459,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3129
3459
|
});
|
|
3130
3460
|
|
|
3131
3461
|
// 从 Payment 模块获取最新支付项,检查自动同步条件
|
|
3132
|
-
|
|
3462
|
+
_context38.next = 15;
|
|
3133
3463
|
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid, false // 不包括已撤销的支付项
|
|
3134
3464
|
);
|
|
3135
3465
|
case 15:
|
|
3136
|
-
currentPayments =
|
|
3466
|
+
currentPayments = _context38.sent;
|
|
3137
3467
|
// 检查自动同步条件:
|
|
3138
3468
|
// 1. 待付金额为 0 ✓ (已在上面检查)
|
|
3139
3469
|
// 2. 需要有支付项
|
|
@@ -3167,14 +3497,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3167
3497
|
})
|
|
3168
3498
|
});
|
|
3169
3499
|
if (!shouldAutoSync) {
|
|
3170
|
-
|
|
3500
|
+
_context38.next = 26;
|
|
3171
3501
|
break;
|
|
3172
3502
|
}
|
|
3173
3503
|
this.logInfo('满足自动同步条件,开始同步订单到后端...');
|
|
3174
|
-
|
|
3504
|
+
_context38.next = 24;
|
|
3175
3505
|
return this.syncOrderToBackendWithReturn(false);
|
|
3176
3506
|
case 24:
|
|
3177
|
-
|
|
3507
|
+
_context38.next = 27;
|
|
3178
3508
|
break;
|
|
3179
3509
|
case 26:
|
|
3180
3510
|
if (!hasPaymentItems) {
|
|
@@ -3183,7 +3513,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3183
3513
|
this.logInfo('所有支付项均为代金券类型,跳过订单同步');
|
|
3184
3514
|
}
|
|
3185
3515
|
case 27:
|
|
3186
|
-
|
|
3516
|
+
_context38.next = 29;
|
|
3187
3517
|
return this.core.effects.emit("".concat(this.name, ":onOrderPaymentCompleted"), {
|
|
3188
3518
|
orderUuid: this.store.currentOrder.uuid,
|
|
3189
3519
|
orderId: this.store.currentOrder.order_id,
|
|
@@ -3193,17 +3523,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3193
3523
|
timestamp: Date.now()
|
|
3194
3524
|
});
|
|
3195
3525
|
case 29:
|
|
3196
|
-
|
|
3526
|
+
_context38.next = 34;
|
|
3197
3527
|
break;
|
|
3198
3528
|
case 31:
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
this.logError('检查订单支付完成状态失败:',
|
|
3529
|
+
_context38.prev = 31;
|
|
3530
|
+
_context38.t0 = _context38["catch"](0);
|
|
3531
|
+
this.logError('检查订单支付完成状态失败:', _context38.t0);
|
|
3202
3532
|
case 34:
|
|
3203
3533
|
case "end":
|
|
3204
|
-
return
|
|
3534
|
+
return _context38.stop();
|
|
3205
3535
|
}
|
|
3206
|
-
},
|
|
3536
|
+
}, _callee38, this, [[0, 31]]);
|
|
3207
3537
|
}));
|
|
3208
3538
|
function checkOrderPaymentCompletion() {
|
|
3209
3539
|
return _checkOrderPaymentCompletion.apply(this, arguments);
|
|
@@ -3221,12 +3551,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3221
3551
|
}, {
|
|
3222
3552
|
key: "syncOrderToBackendWithReturn",
|
|
3223
3553
|
value: (function () {
|
|
3224
|
-
var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3225
|
-
var
|
|
3226
|
-
_this$store$
|
|
3227
|
-
_this$store$
|
|
3554
|
+
var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
|
|
3555
|
+
var _this5 = this,
|
|
3556
|
+
_this$store$currentOr23,
|
|
3557
|
+
_this$store$currentOr24,
|
|
3228
3558
|
_this$store$currentCu2,
|
|
3229
|
-
_this$store$
|
|
3559
|
+
_this$store$currentOr25,
|
|
3230
3560
|
_this$store$localOrde,
|
|
3231
3561
|
_this$store$localOrde2,
|
|
3232
3562
|
_checkoutResponse3,
|
|
@@ -3261,14 +3591,14 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3261
3591
|
_iterator3,
|
|
3262
3592
|
_step3,
|
|
3263
3593
|
paymentUuid,
|
|
3264
|
-
|
|
3265
|
-
return _regeneratorRuntime().wrap(function
|
|
3266
|
-
while (1) switch (
|
|
3594
|
+
_args39 = arguments;
|
|
3595
|
+
return _regeneratorRuntime().wrap(function _callee39$(_context39) {
|
|
3596
|
+
while (1) switch (_context39.prev = _context39.next) {
|
|
3267
3597
|
case 0:
|
|
3268
|
-
isManual =
|
|
3269
|
-
customPaymentItems =
|
|
3598
|
+
isManual = _args39.length > 0 && _args39[0] !== undefined ? _args39[0] : false;
|
|
3599
|
+
customPaymentItems = _args39.length > 1 ? _args39[1] : undefined;
|
|
3270
3600
|
if (!(!this.store.localOrderData || !this.store.currentOrder)) {
|
|
3271
|
-
|
|
3601
|
+
_context39.next = 4;
|
|
3272
3602
|
break;
|
|
3273
3603
|
}
|
|
3274
3604
|
throw new Error('缺少必要的订单数据,无法同步到后端');
|
|
@@ -3287,28 +3617,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3287
3617
|
});
|
|
3288
3618
|
|
|
3289
3619
|
// 获取当前订单的支付项
|
|
3290
|
-
|
|
3291
|
-
if (
|
|
3292
|
-
|
|
3620
|
+
_context39.t0 = customPaymentItems;
|
|
3621
|
+
if (_context39.t0) {
|
|
3622
|
+
_context39.next = 13;
|
|
3293
3623
|
break;
|
|
3294
3624
|
}
|
|
3295
|
-
|
|
3625
|
+
_context39.next = 12;
|
|
3296
3626
|
return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
|
|
3297
3627
|
case 12:
|
|
3298
|
-
|
|
3628
|
+
_context39.t0 = _context39.sent;
|
|
3299
3629
|
case 13:
|
|
3300
|
-
paymentItems =
|
|
3630
|
+
paymentItems = _context39.t0;
|
|
3301
3631
|
// 处理支付项数据,确保包含完整的 metadata
|
|
3302
3632
|
processedPaymentItems = paymentItems.map(function (item) {
|
|
3303
3633
|
var _item$metadata, _item$metadata2;
|
|
3304
3634
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
3305
3635
|
metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
|
|
3306
|
-
rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) ||
|
|
3307
|
-
shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) ||
|
|
3636
|
+
rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this5.otherParams.order_rounding_setting,
|
|
3637
|
+
shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this5.otherParams.shop_wallet_pass_id
|
|
3308
3638
|
})
|
|
3309
3639
|
});
|
|
3310
3640
|
}); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
|
|
3311
|
-
manualDepositAmount = ((_this$store$
|
|
3641
|
+
manualDepositAmount = ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
|
|
3312
3642
|
manualDepositValue = new Decimal(manualDepositAmount);
|
|
3313
3643
|
if (manualDepositValue.gt(0)) {
|
|
3314
3644
|
// 如果手动设置了定金金额且大于0,使用手动设置的值
|
|
@@ -3368,7 +3698,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3368
3698
|
}),
|
|
3369
3699
|
manualDepositAmount: manualDepositAmount,
|
|
3370
3700
|
finalDepositAmount: finalDepositAmount,
|
|
3371
|
-
isDeposit: ((_this$store$
|
|
3701
|
+
isDeposit: ((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.is_deposit) || 0
|
|
3372
3702
|
});
|
|
3373
3703
|
|
|
3374
3704
|
// 构造订单参数,直接使用 localOrderData 中已处理好的数据
|
|
@@ -3390,7 +3720,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3390
3720
|
currency_code: this.otherParams.currency_code,
|
|
3391
3721
|
currency_symbol: this.otherParams.currency_symbol,
|
|
3392
3722
|
currency_format: this.otherParams.currency_format,
|
|
3393
|
-
is_deposit: ((_this$store$
|
|
3723
|
+
is_deposit: ((_this$store$currentOr25 = this.store.currentOrder) !== null && _this$store$currentOr25 !== void 0 && _this$store$currentOr25.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
|
|
3394
3724
|
deposit_amount: finalDepositAmount,
|
|
3395
3725
|
// 使用最终确定的定金金额(手动设置优先)
|
|
3396
3726
|
product_tax_fee: this.store.localOrderData.tax_fee,
|
|
@@ -3421,7 +3751,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3421
3751
|
|
|
3422
3752
|
// 发送下单接口请求开始事件
|
|
3423
3753
|
startTime = Date.now();
|
|
3424
|
-
|
|
3754
|
+
_context39.next = 27;
|
|
3425
3755
|
return this.core.effects.emit("".concat(this.name, ":onOrderSubmitStart"), {
|
|
3426
3756
|
orderUuid: this.store.currentOrder.uuid,
|
|
3427
3757
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3431,7 +3761,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3431
3761
|
});
|
|
3432
3762
|
case 27:
|
|
3433
3763
|
submitSuccess = false;
|
|
3434
|
-
|
|
3764
|
+
_context39.prev = 28;
|
|
3435
3765
|
// 记录接口调用参数
|
|
3436
3766
|
this.logInfo('Calling backend checkout API', _objectSpread({
|
|
3437
3767
|
url: '/order/checkout',
|
|
@@ -3439,23 +3769,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3439
3769
|
}, orderParams));
|
|
3440
3770
|
|
|
3441
3771
|
// 调用 Order 模块的专用 createOrderByCheckout 方法
|
|
3442
|
-
|
|
3772
|
+
_context39.next = 32;
|
|
3443
3773
|
return this.order.createOrderByCheckout(orderParams);
|
|
3444
3774
|
case 32:
|
|
3445
|
-
checkoutResponse =
|
|
3775
|
+
checkoutResponse = _context39.sent;
|
|
3446
3776
|
submitSuccess = true;
|
|
3447
3777
|
this.logInfo('下单接口调用成功', checkoutResponse);
|
|
3448
|
-
|
|
3778
|
+
_context39.next = 45;
|
|
3449
3779
|
break;
|
|
3450
3780
|
case 37:
|
|
3451
|
-
|
|
3452
|
-
|
|
3781
|
+
_context39.prev = 37;
|
|
3782
|
+
_context39.t1 = _context39["catch"](28);
|
|
3453
3783
|
submitSuccess = false;
|
|
3454
|
-
submitError =
|
|
3784
|
+
submitError = _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1);
|
|
3455
3785
|
this.logError('下单接口调用失败:', submitError);
|
|
3456
3786
|
|
|
3457
3787
|
// 发送订单同步失败事件(网络错误或请求失败)
|
|
3458
|
-
|
|
3788
|
+
_context39.next = 44;
|
|
3459
3789
|
return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
|
|
3460
3790
|
orderUuid: this.store.currentOrder.uuid,
|
|
3461
3791
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3466,10 +3796,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3466
3796
|
timestamp: Date.now()
|
|
3467
3797
|
});
|
|
3468
3798
|
case 44:
|
|
3469
|
-
throw
|
|
3799
|
+
throw _context39.t1;
|
|
3470
3800
|
case 45:
|
|
3471
|
-
|
|
3472
|
-
|
|
3801
|
+
_context39.prev = 45;
|
|
3802
|
+
_context39.next = 48;
|
|
3473
3803
|
return this.core.effects.emit("".concat(this.name, ":onOrderSubmitEnd"), {
|
|
3474
3804
|
success: submitSuccess,
|
|
3475
3805
|
orderUuid: this.store.currentOrder.uuid,
|
|
@@ -3481,17 +3811,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3481
3811
|
timestamp: Date.now()
|
|
3482
3812
|
});
|
|
3483
3813
|
case 48:
|
|
3484
|
-
return
|
|
3814
|
+
return _context39.finish(45);
|
|
3485
3815
|
case 49:
|
|
3486
3816
|
// 检查响应状态是否为成功状态
|
|
3487
3817
|
responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
|
|
3488
3818
|
isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
|
|
3489
3819
|
if (isSuccessResponse) {
|
|
3490
|
-
|
|
3820
|
+
_context39.next = 56;
|
|
3491
3821
|
break;
|
|
3492
3822
|
}
|
|
3493
3823
|
errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
|
|
3494
|
-
|
|
3824
|
+
_context39.next = 55;
|
|
3495
3825
|
return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
|
|
3496
3826
|
orderUuid: this.store.currentOrder.uuid,
|
|
3497
3827
|
operation: isUpdateOperation ? 'update' : 'create',
|
|
@@ -3506,12 +3836,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3506
3836
|
throw new Error(errorMessage);
|
|
3507
3837
|
case 56:
|
|
3508
3838
|
if (!isUpdateOperation) {
|
|
3509
|
-
|
|
3839
|
+
_context39.next = 60;
|
|
3510
3840
|
break;
|
|
3511
3841
|
}
|
|
3512
3842
|
// 更新操作:使用现有的订单ID
|
|
3513
3843
|
realOrderId = currentOrderId;
|
|
3514
|
-
|
|
3844
|
+
_context39.next = 79;
|
|
3515
3845
|
break;
|
|
3516
3846
|
case 60:
|
|
3517
3847
|
// 创建操作:从响应中提取新的订单ID
|
|
@@ -3535,11 +3865,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3535
3865
|
oldOrderId: this.store.currentOrder.order_id,
|
|
3536
3866
|
newOrderId: realOrderId
|
|
3537
3867
|
});
|
|
3538
|
-
|
|
3539
|
-
|
|
3868
|
+
_context39.prev = 66;
|
|
3869
|
+
_context39.next = 69;
|
|
3540
3870
|
return this.payment.replaceOrderIdByUuidAsync(this.store.currentOrder.uuid, realOrderId);
|
|
3541
3871
|
case 69:
|
|
3542
|
-
updatedOrder =
|
|
3872
|
+
updatedOrder = _context39.sent;
|
|
3543
3873
|
this.logInfo('Payment模块替换订单ID结果:', {
|
|
3544
3874
|
wasSuccessful: !!updatedOrder,
|
|
3545
3875
|
returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
|
|
@@ -3565,66 +3895,69 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3565
3895
|
目标ID: realOrderId
|
|
3566
3896
|
});
|
|
3567
3897
|
}
|
|
3568
|
-
|
|
3898
|
+
_context39.next = 79;
|
|
3569
3899
|
break;
|
|
3570
3900
|
case 74:
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
this.logError('调用Payment模块替换订单ID时发生错误:',
|
|
3901
|
+
_context39.prev = 74;
|
|
3902
|
+
_context39.t2 = _context39["catch"](66);
|
|
3903
|
+
this.logError('调用Payment模块替换订单ID时发生错误:', _context39.t2);
|
|
3574
3904
|
|
|
3575
3905
|
// 发生错误时也进行手动替换
|
|
3576
3906
|
this.store.currentOrder.order_id = realOrderId;
|
|
3577
3907
|
this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
|
|
3578
3908
|
case 79:
|
|
3579
|
-
|
|
3909
|
+
_context39.prev = 79;
|
|
3580
3910
|
syncedPaymentUuids = processedPaymentItems.filter(function (item) {
|
|
3581
3911
|
return item.status !== 'voided';
|
|
3582
3912
|
}).map(function (item) {
|
|
3583
3913
|
return item.uuid;
|
|
3584
3914
|
}).filter(Boolean);
|
|
3585
3915
|
_iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
|
|
3586
|
-
|
|
3916
|
+
_context39.prev = 82;
|
|
3587
3917
|
_iterator3.s();
|
|
3588
3918
|
case 84:
|
|
3589
3919
|
if ((_step3 = _iterator3.n()).done) {
|
|
3590
|
-
|
|
3920
|
+
_context39.next = 90;
|
|
3591
3921
|
break;
|
|
3592
3922
|
}
|
|
3593
3923
|
paymentUuid = _step3.value;
|
|
3594
|
-
|
|
3924
|
+
_context39.next = 88;
|
|
3595
3925
|
return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
|
|
3596
3926
|
isSynced: true,
|
|
3597
3927
|
syncError: undefined
|
|
3598
3928
|
});
|
|
3599
3929
|
case 88:
|
|
3600
|
-
|
|
3930
|
+
_context39.next = 84;
|
|
3601
3931
|
break;
|
|
3602
3932
|
case 90:
|
|
3603
|
-
|
|
3933
|
+
_context39.next = 95;
|
|
3604
3934
|
break;
|
|
3605
3935
|
case 92:
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
_iterator3.e(
|
|
3936
|
+
_context39.prev = 92;
|
|
3937
|
+
_context39.t3 = _context39["catch"](82);
|
|
3938
|
+
_iterator3.e(_context39.t3);
|
|
3609
3939
|
case 95:
|
|
3610
|
-
|
|
3940
|
+
_context39.prev = 95;
|
|
3611
3941
|
_iterator3.f();
|
|
3612
|
-
return
|
|
3942
|
+
return _context39.finish(95);
|
|
3613
3943
|
case 98:
|
|
3614
|
-
|
|
3944
|
+
_context39.next = 103;
|
|
3615
3945
|
break;
|
|
3616
3946
|
case 100:
|
|
3617
|
-
|
|
3618
|
-
|
|
3947
|
+
_context39.prev = 100;
|
|
3948
|
+
_context39.t4 = _context39["catch"](79);
|
|
3619
3949
|
this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
|
|
3620
|
-
error:
|
|
3950
|
+
error: _context39.t4
|
|
3621
3951
|
});
|
|
3622
3952
|
case 103:
|
|
3623
3953
|
// 标记订单已同步
|
|
3624
3954
|
this.store.isOrderSynced = true;
|
|
3625
3955
|
|
|
3956
|
+
// 🚀 清除计算缓存,订单已同步,数据可能已变更
|
|
3957
|
+
this.clearCalculationCache();
|
|
3958
|
+
|
|
3626
3959
|
// 触发订单同步完成事件
|
|
3627
|
-
|
|
3960
|
+
_context39.next = 107;
|
|
3628
3961
|
return this.core.effects.emit("".concat(this.name, ":onOrderSynced"), {
|
|
3629
3962
|
orderUuid: this.store.currentOrder.uuid,
|
|
3630
3963
|
realOrderId: realOrderId,
|
|
@@ -3633,18 +3966,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3633
3966
|
isManual: isManual,
|
|
3634
3967
|
response: checkoutResponse
|
|
3635
3968
|
});
|
|
3636
|
-
case
|
|
3637
|
-
return
|
|
3969
|
+
case 107:
|
|
3970
|
+
return _context39.abrupt("return", {
|
|
3638
3971
|
success: true,
|
|
3639
3972
|
orderId: realOrderId,
|
|
3640
3973
|
orderUuid: this.store.currentOrder.uuid,
|
|
3641
3974
|
response: checkoutResponse
|
|
3642
3975
|
});
|
|
3643
|
-
case
|
|
3976
|
+
case 108:
|
|
3644
3977
|
case "end":
|
|
3645
|
-
return
|
|
3978
|
+
return _context39.stop();
|
|
3646
3979
|
}
|
|
3647
|
-
},
|
|
3980
|
+
}, _callee39, this, [[28, 37, 45, 49], [66, 74], [79, 100], [82, 92, 95, 98]]);
|
|
3648
3981
|
}));
|
|
3649
3982
|
function syncOrderToBackendWithReturn() {
|
|
3650
3983
|
return _syncOrderToBackendWithReturn.apply(this, arguments);
|
|
@@ -3654,15 +3987,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3654
3987
|
}, {
|
|
3655
3988
|
key: "setOtherParams",
|
|
3656
3989
|
value: function () {
|
|
3657
|
-
var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
3990
|
+
var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
|
|
3658
3991
|
var _ref5,
|
|
3659
3992
|
_ref5$cover,
|
|
3660
3993
|
cover,
|
|
3661
|
-
|
|
3662
|
-
return _regeneratorRuntime().wrap(function
|
|
3663
|
-
while (1) switch (
|
|
3994
|
+
_args40 = arguments;
|
|
3995
|
+
return _regeneratorRuntime().wrap(function _callee40$(_context40) {
|
|
3996
|
+
while (1) switch (_context40.prev = _context40.next) {
|
|
3664
3997
|
case 0:
|
|
3665
|
-
_ref5 =
|
|
3998
|
+
_ref5 = _args40.length > 1 && _args40[1] !== undefined ? _args40[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
|
|
3666
3999
|
if (cover) {
|
|
3667
4000
|
this.otherParams = params;
|
|
3668
4001
|
} else {
|
|
@@ -3670,11 +4003,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3670
4003
|
}
|
|
3671
4004
|
case 2:
|
|
3672
4005
|
case "end":
|
|
3673
|
-
return
|
|
4006
|
+
return _context40.stop();
|
|
3674
4007
|
}
|
|
3675
|
-
},
|
|
4008
|
+
}, _callee40, this);
|
|
3676
4009
|
}));
|
|
3677
|
-
function setOtherParams(
|
|
4010
|
+
function setOtherParams(_x29) {
|
|
3678
4011
|
return _setOtherParams.apply(this, arguments);
|
|
3679
4012
|
}
|
|
3680
4013
|
return setOtherParams;
|
|
@@ -3691,22 +4024,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3691
4024
|
}, {
|
|
3692
4025
|
key: "editOrderNoteByOrderIdAsync",
|
|
3693
4026
|
value: (function () {
|
|
3694
|
-
var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4027
|
+
var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(orderId, note) {
|
|
3695
4028
|
var response, previousNote, errorMessage, _errorMessage;
|
|
3696
|
-
return _regeneratorRuntime().wrap(function
|
|
3697
|
-
while (1) switch (
|
|
4029
|
+
return _regeneratorRuntime().wrap(function _callee41$(_context41) {
|
|
4030
|
+
while (1) switch (_context41.prev = _context41.next) {
|
|
3698
4031
|
case 0:
|
|
3699
4032
|
this.logInfo('editOrderNoteByOrderIdAsync called', {
|
|
3700
4033
|
orderId: orderId,
|
|
3701
4034
|
note: note,
|
|
3702
4035
|
noteLength: note.length
|
|
3703
4036
|
});
|
|
3704
|
-
|
|
4037
|
+
_context41.prev = 1;
|
|
3705
4038
|
if (orderId) {
|
|
3706
|
-
|
|
4039
|
+
_context41.next = 4;
|
|
3707
4040
|
break;
|
|
3708
4041
|
}
|
|
3709
|
-
return
|
|
4042
|
+
return _context41.abrupt("return", {
|
|
3710
4043
|
success: false,
|
|
3711
4044
|
message: '订单ID不能为空',
|
|
3712
4045
|
orderId: orderId
|
|
@@ -3722,12 +4055,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3722
4055
|
});
|
|
3723
4056
|
|
|
3724
4057
|
// 调用后端API修改订单备注
|
|
3725
|
-
|
|
4058
|
+
_context41.next = 7;
|
|
3726
4059
|
return this.request.put("/order/order/".concat(orderId, "/note"), {
|
|
3727
4060
|
note: note
|
|
3728
4061
|
});
|
|
3729
4062
|
case 7:
|
|
3730
|
-
response =
|
|
4063
|
+
response = _context41.sent;
|
|
3731
4064
|
this.logInfo('订单备注编辑响应:', {
|
|
3732
4065
|
orderId: orderId,
|
|
3733
4066
|
status: response.status,
|
|
@@ -3737,11 +4070,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3737
4070
|
|
|
3738
4071
|
// 检查响应状态
|
|
3739
4072
|
if (!(response.status === true || response.status === 200)) {
|
|
3740
|
-
|
|
4073
|
+
_context41.next = 18;
|
|
3741
4074
|
break;
|
|
3742
4075
|
}
|
|
3743
4076
|
if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
|
|
3744
|
-
|
|
4077
|
+
_context41.next = 15;
|
|
3745
4078
|
break;
|
|
3746
4079
|
}
|
|
3747
4080
|
// 获取修改前的备注用于事件
|
|
@@ -3751,7 +4084,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3751
4084
|
}
|
|
3752
4085
|
|
|
3753
4086
|
// 触发订单备注变更事件
|
|
3754
|
-
|
|
4087
|
+
_context41.next = 15;
|
|
3755
4088
|
return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
|
|
3756
4089
|
orderUuid: this.store.currentOrder.uuid,
|
|
3757
4090
|
oldNote: previousNote,
|
|
@@ -3759,7 +4092,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3759
4092
|
timestamp: Date.now()
|
|
3760
4093
|
});
|
|
3761
4094
|
case 15:
|
|
3762
|
-
return
|
|
4095
|
+
return _context41.abrupt("return", {
|
|
3763
4096
|
success: true,
|
|
3764
4097
|
message: response.message || '订单备注修改成功',
|
|
3765
4098
|
orderId: orderId
|
|
@@ -3768,31 +4101,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3768
4101
|
// API返回失败状态
|
|
3769
4102
|
errorMessage = response.message || '订单备注修改失败';
|
|
3770
4103
|
this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
|
|
3771
|
-
return
|
|
4104
|
+
return _context41.abrupt("return", {
|
|
3772
4105
|
success: false,
|
|
3773
4106
|
message: errorMessage,
|
|
3774
4107
|
orderId: orderId
|
|
3775
4108
|
});
|
|
3776
4109
|
case 21:
|
|
3777
|
-
|
|
4110
|
+
_context41.next = 28;
|
|
3778
4111
|
break;
|
|
3779
4112
|
case 23:
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
this.logError('编辑订单备注失败:',
|
|
3783
|
-
_errorMessage =
|
|
3784
|
-
return
|
|
4113
|
+
_context41.prev = 23;
|
|
4114
|
+
_context41.t0 = _context41["catch"](1);
|
|
4115
|
+
this.logError('编辑订单备注失败:', _context41.t0);
|
|
4116
|
+
_errorMessage = _context41.t0 instanceof Error ? _context41.t0.message : '网络错误或服务器异常';
|
|
4117
|
+
return _context41.abrupt("return", {
|
|
3785
4118
|
success: false,
|
|
3786
4119
|
message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
|
|
3787
4120
|
orderId: orderId
|
|
3788
4121
|
});
|
|
3789
4122
|
case 28:
|
|
3790
4123
|
case "end":
|
|
3791
|
-
return
|
|
4124
|
+
return _context41.stop();
|
|
3792
4125
|
}
|
|
3793
|
-
},
|
|
4126
|
+
}, _callee41, this, [[1, 23]]);
|
|
3794
4127
|
}));
|
|
3795
|
-
function editOrderNoteByOrderIdAsync(
|
|
4128
|
+
function editOrderNoteByOrderIdAsync(_x30, _x31) {
|
|
3796
4129
|
return _editOrderNoteByOrderIdAsync.apply(this, arguments);
|
|
3797
4130
|
}
|
|
3798
4131
|
return editOrderNoteByOrderIdAsync;
|
|
@@ -3809,11 +4142,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3809
4142
|
}, {
|
|
3810
4143
|
key: "sendCustomerPayLinkAsync",
|
|
3811
4144
|
value: (function () {
|
|
3812
|
-
var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4145
|
+
var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
|
|
3813
4146
|
var _params$order_ids, _params$emails;
|
|
3814
4147
|
var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
|
|
3815
|
-
return _regeneratorRuntime().wrap(function
|
|
3816
|
-
while (1) switch (
|
|
4148
|
+
return _regeneratorRuntime().wrap(function _callee42$(_context42) {
|
|
4149
|
+
while (1) switch (_context42.prev = _context42.next) {
|
|
3817
4150
|
case 0:
|
|
3818
4151
|
this.logInfo('sendCustomerPayLinkAsync called', {
|
|
3819
4152
|
orderIds: params.order_ids,
|
|
@@ -3822,21 +4155,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3822
4155
|
emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
|
|
3823
4156
|
notifyAction: params.notify_action || 'order_payment_reminder'
|
|
3824
4157
|
});
|
|
3825
|
-
|
|
4158
|
+
_context42.prev = 1;
|
|
3826
4159
|
if (!(!params.order_ids || params.order_ids.length === 0)) {
|
|
3827
|
-
|
|
4160
|
+
_context42.next = 4;
|
|
3828
4161
|
break;
|
|
3829
4162
|
}
|
|
3830
|
-
return
|
|
4163
|
+
return _context42.abrupt("return", {
|
|
3831
4164
|
success: false,
|
|
3832
4165
|
message: '订单ID列表不能为空'
|
|
3833
4166
|
});
|
|
3834
4167
|
case 4:
|
|
3835
4168
|
if (!(!params.emails || params.emails.length === 0)) {
|
|
3836
|
-
|
|
4169
|
+
_context42.next = 6;
|
|
3837
4170
|
break;
|
|
3838
4171
|
}
|
|
3839
|
-
return
|
|
4172
|
+
return _context42.abrupt("return", {
|
|
3840
4173
|
success: false,
|
|
3841
4174
|
message: '邮箱地址列表不能为空'
|
|
3842
4175
|
});
|
|
@@ -3847,10 +4180,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3847
4180
|
return !emailRegex.test(email);
|
|
3848
4181
|
});
|
|
3849
4182
|
if (!(invalidEmails.length > 0)) {
|
|
3850
|
-
|
|
4183
|
+
_context42.next = 10;
|
|
3851
4184
|
break;
|
|
3852
4185
|
}
|
|
3853
|
-
return
|
|
4186
|
+
return _context42.abrupt("return", {
|
|
3854
4187
|
success: false,
|
|
3855
4188
|
message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
|
|
3856
4189
|
});
|
|
@@ -3866,10 +4199,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3866
4199
|
}, requestBody));
|
|
3867
4200
|
|
|
3868
4201
|
// 调用后端API发送邮件
|
|
3869
|
-
|
|
4202
|
+
_context42.next = 14;
|
|
3870
4203
|
return this.request.post('/order/batch-email', requestBody);
|
|
3871
4204
|
case 14:
|
|
3872
|
-
response =
|
|
4205
|
+
response = _context42.sent;
|
|
3873
4206
|
this.logInfo('支付链接邮件发送响应:', {
|
|
3874
4207
|
status: response.status,
|
|
3875
4208
|
message: response.message,
|
|
@@ -3879,10 +4212,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3879
4212
|
|
|
3880
4213
|
// 检查响应状态
|
|
3881
4214
|
if (!(response.status === true || response.status === 200)) {
|
|
3882
|
-
|
|
4215
|
+
_context42.next = 20;
|
|
3883
4216
|
break;
|
|
3884
4217
|
}
|
|
3885
|
-
return
|
|
4218
|
+
return _context42.abrupt("return", {
|
|
3886
4219
|
success: true,
|
|
3887
4220
|
message: response.message || '支付链接邮件发送成功'
|
|
3888
4221
|
});
|
|
@@ -3890,29 +4223,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3890
4223
|
// API返回失败状态
|
|
3891
4224
|
errorMessage = response.message || '支付链接邮件发送失败';
|
|
3892
4225
|
console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
|
|
3893
|
-
return
|
|
4226
|
+
return _context42.abrupt("return", {
|
|
3894
4227
|
success: false,
|
|
3895
4228
|
message: errorMessage
|
|
3896
4229
|
});
|
|
3897
4230
|
case 23:
|
|
3898
|
-
|
|
4231
|
+
_context42.next = 30;
|
|
3899
4232
|
break;
|
|
3900
4233
|
case 25:
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
this.logError('发送客户支付链接邮件失败:',
|
|
3904
|
-
_errorMessage2 =
|
|
3905
|
-
return
|
|
4234
|
+
_context42.prev = 25;
|
|
4235
|
+
_context42.t0 = _context42["catch"](1);
|
|
4236
|
+
this.logError('发送客户支付链接邮件失败:', _context42.t0);
|
|
4237
|
+
_errorMessage2 = _context42.t0 instanceof Error ? _context42.t0.message : '网络错误或服务器异常';
|
|
4238
|
+
return _context42.abrupt("return", {
|
|
3906
4239
|
success: false,
|
|
3907
4240
|
message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
|
|
3908
4241
|
});
|
|
3909
4242
|
case 30:
|
|
3910
4243
|
case "end":
|
|
3911
|
-
return
|
|
4244
|
+
return _context42.stop();
|
|
3912
4245
|
}
|
|
3913
|
-
},
|
|
4246
|
+
}, _callee42, this, [[1, 25]]);
|
|
3914
4247
|
}));
|
|
3915
|
-
function sendCustomerPayLinkAsync(
|
|
4248
|
+
function sendCustomerPayLinkAsync(_x32) {
|
|
3916
4249
|
return _sendCustomerPayLinkAsync.apply(this, arguments);
|
|
3917
4250
|
}
|
|
3918
4251
|
return sendCustomerPayLinkAsync;
|
|
@@ -3927,38 +4260,38 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3927
4260
|
}, {
|
|
3928
4261
|
key: "roundAmountAsync",
|
|
3929
4262
|
value: (function () {
|
|
3930
|
-
var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4263
|
+
var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(amount) {
|
|
3931
4264
|
var _cashManualPayment$me, _this$otherParams$ord, _this$otherParams$ord2;
|
|
3932
4265
|
var cashManualPayment, result;
|
|
3933
|
-
return _regeneratorRuntime().wrap(function
|
|
3934
|
-
while (1) switch (
|
|
4266
|
+
return _regeneratorRuntime().wrap(function _callee43$(_context43) {
|
|
4267
|
+
while (1) switch (_context43.prev = _context43.next) {
|
|
3935
4268
|
case 0:
|
|
3936
4269
|
// 检查 CASHMANUAL 的支付项是否开启了舍入,如果没开直接返回 amount
|
|
3937
4270
|
cashManualPayment = this.store.paymentMethods.find(function (p) {
|
|
3938
4271
|
return p.code === 'CASHMANUAL';
|
|
3939
4272
|
});
|
|
3940
4273
|
if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
|
|
3941
|
-
|
|
4274
|
+
_context43.next = 3;
|
|
3942
4275
|
break;
|
|
3943
4276
|
}
|
|
3944
|
-
return
|
|
4277
|
+
return _context43.abrupt("return", {
|
|
3945
4278
|
originalAmount: amount.toString(),
|
|
3946
4279
|
roundedAmount: amount.toString(),
|
|
3947
4280
|
roundingDifference: '0.00'
|
|
3948
4281
|
});
|
|
3949
4282
|
case 3:
|
|
3950
|
-
|
|
4283
|
+
_context43.next = 5;
|
|
3951
4284
|
return this.payment.roundAmountAsync(amount, (_this$otherParams$ord = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord === void 0 ? void 0 : _this$otherParams$ord.interval, (_this$otherParams$ord2 = this.otherParams.order_rounding_setting) === null || _this$otherParams$ord2 === void 0 ? void 0 : _this$otherParams$ord2.type);
|
|
3952
4285
|
case 5:
|
|
3953
|
-
result =
|
|
3954
|
-
return
|
|
4286
|
+
result = _context43.sent;
|
|
4287
|
+
return _context43.abrupt("return", result);
|
|
3955
4288
|
case 7:
|
|
3956
4289
|
case "end":
|
|
3957
|
-
return
|
|
4290
|
+
return _context43.stop();
|
|
3958
4291
|
}
|
|
3959
|
-
},
|
|
4292
|
+
}, _callee43, this);
|
|
3960
4293
|
}));
|
|
3961
|
-
function roundAmountAsync(
|
|
4294
|
+
function roundAmountAsync(_x33) {
|
|
3962
4295
|
return _roundAmountAsync.apply(this, arguments);
|
|
3963
4296
|
}
|
|
3964
4297
|
return roundAmountAsync;
|
|
@@ -3966,10 +4299,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3966
4299
|
}, {
|
|
3967
4300
|
key: "destroy",
|
|
3968
4301
|
value: function () {
|
|
3969
|
-
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
4302
|
+
var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
|
|
3970
4303
|
var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
|
|
3971
|
-
return _regeneratorRuntime().wrap(function
|
|
3972
|
-
while (1) switch (
|
|
4304
|
+
return _regeneratorRuntime().wrap(function _callee44$(_context44) {
|
|
4305
|
+
while (1) switch (_context44.prev = _context44.next) {
|
|
3973
4306
|
case 0:
|
|
3974
4307
|
// 清理钱包模块的所有缓存数据
|
|
3975
4308
|
this.payment.wallet.clearAllCache();
|
|
@@ -3978,10 +4311,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3978
4311
|
this.core.effects.offByModuleDestroy(this.name);
|
|
3979
4312
|
|
|
3980
4313
|
// 销毁子模块
|
|
3981
|
-
|
|
4314
|
+
_context44.next = 4;
|
|
3982
4315
|
return (_this$order = this.order) === null || _this$order === void 0 || (_this$order$destroy = _this$order.destroy) === null || _this$order$destroy === void 0 ? void 0 : _this$order$destroy.call(_this$order);
|
|
3983
4316
|
case 4:
|
|
3984
|
-
|
|
4317
|
+
_context44.next = 6;
|
|
3985
4318
|
return (_this$payment = this.payment) === null || _this$payment === void 0 || (_this$payment$destroy = _this$payment.destroy) === null || _this$payment$destroy === void 0 ? void 0 : _this$payment$destroy.call(_this$payment);
|
|
3986
4319
|
case 6:
|
|
3987
4320
|
// 取消注册模块
|
|
@@ -3989,9 +4322,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3989
4322
|
console.log('[Checkout] 已销毁');
|
|
3990
4323
|
case 8:
|
|
3991
4324
|
case "end":
|
|
3992
|
-
return
|
|
4325
|
+
return _context44.stop();
|
|
3993
4326
|
}
|
|
3994
|
-
},
|
|
4327
|
+
}, _callee44, this);
|
|
3995
4328
|
}));
|
|
3996
4329
|
function destroy() {
|
|
3997
4330
|
return _destroy.apply(this, arguments);
|
|
@@ -4002,70 +4335,57 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
4002
4335
|
* 重置 store 状态
|
|
4003
4336
|
*
|
|
4004
4337
|
* 在创建新订单前调用,确保状态完全干净
|
|
4338
|
+
*
|
|
4339
|
+
* 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
|
|
4005
4340
|
*/
|
|
4006
4341
|
}, {
|
|
4007
|
-
key: "
|
|
4008
|
-
value:
|
|
4009
|
-
var
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
uuid: this.store.currentOrder.uuid,
|
|
4017
|
-
orderId: this.store.currentOrder.order_id
|
|
4018
|
-
} : null;
|
|
4019
|
-
console.log('[Checkout] 重置 store 状态,准备创建新订单', prevOrderInfo);
|
|
4020
|
-
|
|
4021
|
-
// 重置订单相关的 store 状态(保留 paymentMethods,因为支付方式数据变更不频繁)
|
|
4022
|
-
this.store.currentOrder = undefined;
|
|
4023
|
-
this.store.localOrderData = undefined;
|
|
4024
|
-
this.store.cartSummary = undefined;
|
|
4025
|
-
this.store.stateAmount = '0.00';
|
|
4026
|
-
this.store.balanceDueAmount = '0.00';
|
|
4027
|
-
this.store.isOrderSynced = false;
|
|
4028
|
-
this.store.currentCustomer = undefined;
|
|
4029
|
-
this.store.lastError = undefined;
|
|
4342
|
+
key: "resetStoreState",
|
|
4343
|
+
value: function resetStoreState() {
|
|
4344
|
+
var _this6 = this;
|
|
4345
|
+
try {
|
|
4346
|
+
var prevOrderInfo = this.store.currentOrder ? {
|
|
4347
|
+
uuid: this.store.currentOrder.uuid,
|
|
4348
|
+
orderId: this.store.currentOrder.order_id
|
|
4349
|
+
} : null;
|
|
4350
|
+
console.log('[Checkout] 重置 store 状态,准备创建新订单', prevOrderInfo);
|
|
4030
4351
|
|
|
4031
|
-
|
|
4032
|
-
|
|
4352
|
+
// 重置订单相关的 store 状态(保留 paymentMethods,因为支付方式数据变更不频繁)
|
|
4353
|
+
this.store.currentOrder = undefined;
|
|
4354
|
+
this.store.localOrderData = undefined;
|
|
4355
|
+
this.store.cartSummary = undefined;
|
|
4356
|
+
this.store.stateAmount = '0.00';
|
|
4357
|
+
this.store.balanceDueAmount = '0.00';
|
|
4358
|
+
this.store.isOrderSynced = false;
|
|
4359
|
+
this.store.currentCustomer = undefined;
|
|
4360
|
+
this.store.lastError = undefined;
|
|
4033
4361
|
|
|
4034
|
-
|
|
4035
|
-
|
|
4362
|
+
// 清空购物车项目
|
|
4363
|
+
this.store.cartItems = [];
|
|
4036
4364
|
|
|
4037
|
-
|
|
4365
|
+
// 清理钱包缓存(同步操作)
|
|
4366
|
+
this.payment.wallet.clearAllCache();
|
|
4038
4367
|
|
|
4039
|
-
|
|
4368
|
+
// 🚀 清除计算缓存
|
|
4369
|
+
this.clearCalculationCache();
|
|
4040
4370
|
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
console.error('[Checkout] 重置 store 状态失败:', _context43.t0);
|
|
4058
|
-
case 22:
|
|
4059
|
-
case "end":
|
|
4060
|
-
return _context43.stop();
|
|
4061
|
-
}
|
|
4062
|
-
}, _callee43, this, [[0, 19]]);
|
|
4063
|
-
}));
|
|
4064
|
-
function resetStoreStateAsync() {
|
|
4065
|
-
return _resetStoreStateAsync.apply(this, arguments);
|
|
4371
|
+
// 注意:故意保留 this.store.paymentMethods,因为支付方式数据不易变更,保留在内存中提高性能
|
|
4372
|
+
|
|
4373
|
+
console.log('[Checkout] Store 状态重置完成');
|
|
4374
|
+
|
|
4375
|
+
// 🚀 性能优化:异步触发订单清理事件(不阻塞主流程)
|
|
4376
|
+
// 使用 setTimeout 确保事件处理不会阻塞状态重置
|
|
4377
|
+
if (prevOrderInfo) {
|
|
4378
|
+
setTimeout(function () {
|
|
4379
|
+
_this6.core.effects.emit("".concat(_this6.name, ":onOrderCleared"), {
|
|
4380
|
+
previousOrder: prevOrderInfo,
|
|
4381
|
+
timestamp: Date.now()
|
|
4382
|
+
});
|
|
4383
|
+
}, 0);
|
|
4384
|
+
}
|
|
4385
|
+
} catch (error) {
|
|
4386
|
+
console.error('[Checkout] 重置 store 状态失败:', error);
|
|
4066
4387
|
}
|
|
4067
|
-
|
|
4068
|
-
}())
|
|
4388
|
+
}
|
|
4069
4389
|
}]);
|
|
4070
4390
|
return CheckoutImpl;
|
|
4071
4391
|
}(BaseModule);
|