@pisell/pisellos 0.0.439 → 0.0.441

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.
@@ -1502,24 +1502,59 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1502
1502
  }, {
1503
1503
  key: "addPaymentItemAsync",
1504
1504
  value: (function () {
1505
- var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentItem) {
1506
- var orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type, _paymentItem$code, isEftposPayment, _isCashPayment, isCustomePayment, syncResult;
1505
+ var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentItem, orderUuid) {
1506
+ var _paymentItem$type, _paymentItem$code;
1507
+ var isEftposPayment, shouldRepairFromIndexDb, _this$store$currentOr10, orderPaymentType, processedPaymentItem, metadata, paymentItemWithType, remainingAmount, _paymentItem$type2, _paymentItem$code2, _isEftposPayment, _isCashPayment, isCustomePayment, syncResult;
1507
1508
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1508
1509
  while (1) switch (_context16.prev = _context16.next) {
1509
1510
  case 0:
1510
- this.logInfo('addPaymentItemAsync called', paymentItem);
1511
- _context16.prev = 1;
1511
+ this.logInfo('addPaymentItemAsync called', {
1512
+ paymentItem: paymentItem,
1513
+ orderUuid: orderUuid
1514
+ });
1515
+ isEftposPayment = ((_paymentItem$type = paymentItem.type) === null || _paymentItem$type === void 0 ? void 0 : _paymentItem$type.toLowerCase()) === 'eftpos' || ((_paymentItem$code = paymentItem.code) === null || _paymentItem$code === void 0 ? void 0 : _paymentItem$code.toUpperCase().includes('EFTPOS'));
1516
+ shouldRepairFromIndexDb = !!orderUuid && isEftposPayment && (!this.store.currentOrder || this.store.currentOrder.uuid !== orderUuid);
1517
+ if (!shouldRepairFromIndexDb) {
1518
+ _context16.next = 14;
1519
+ break;
1520
+ }
1521
+ this.logError('EFTPOS push payment repair triggered', {
1522
+ orderUuid: orderUuid,
1523
+ currentOrderUuid: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.uuid,
1524
+ paymentCode: paymentItem.code,
1525
+ paymentType: paymentItem.type
1526
+ });
1527
+ _context16.prev = 5;
1528
+ _context16.next = 8;
1529
+ return this.repairEftposPaymentFromIndexDbAsync({
1530
+ orderUuid: orderUuid,
1531
+ paymentItem: paymentItem
1532
+ });
1533
+ case 8:
1534
+ _context16.next = 13;
1535
+ break;
1536
+ case 10:
1537
+ _context16.prev = 10;
1538
+ _context16.t0 = _context16["catch"](5);
1539
+ this.logError('EFTPOS push payment repair failed', {
1540
+ orderUuid: orderUuid,
1541
+ error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0)
1542
+ });
1543
+ case 13:
1544
+ return _context16.abrupt("return");
1545
+ case 14:
1546
+ _context16.prev = 14;
1512
1547
  if (this.store.currentOrder) {
1513
- _context16.next = 4;
1548
+ _context16.next = 17;
1514
1549
  break;
1515
1550
  }
1516
1551
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
1517
- case 4:
1552
+ case 17:
1518
1553
  // 根据当前订单的定金状态设置订单支付类型
1519
1554
  orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 处理现金支付的找零逻辑
1520
- _context16.next = 7;
1555
+ _context16.next = 20;
1521
1556
  return this.processCashPaymentItem(paymentItem);
1522
- case 7:
1557
+ case 20:
1523
1558
  processedPaymentItem = _context16.sent;
1524
1559
  // 从 otherParams 获取 metadata 字段
1525
1560
  metadata = _objectSpread(_objectSpread({}, processedPaymentItem.metadata), {}, {
@@ -1530,62 +1565,62 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1530
1565
  order_payment_type: orderPaymentType,
1531
1566
  metadata: metadata
1532
1567
  }); // 添加支付项到订单
1533
- _context16.next = 12;
1568
+ _context16.next = 25;
1534
1569
  return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItemWithType);
1535
- case 12:
1570
+ case 25:
1536
1571
  this.logInfo('支付项添加成功');
1537
1572
 
1538
1573
  // 🚀 清除计算缓存,确保获取最新数据
1539
1574
  this.clearCalculationCache();
1540
1575
 
1541
1576
  // 支付项添加后,更新 stateAmount 为剩余未支付金额
1542
- _context16.next = 16;
1577
+ _context16.next = 29;
1543
1578
  return this.updateStateAmountToRemaining();
1544
- case 16:
1545
- _context16.next = 18;
1579
+ case 29:
1580
+ _context16.next = 31;
1546
1581
  return this.calculateRemainingAmountAsync();
1547
- case 18:
1582
+ case 31:
1548
1583
  remainingAmount = _context16.sent;
1549
1584
  if (!(Number(remainingAmount) > 0)) {
1550
- _context16.next = 39;
1585
+ _context16.next = 52;
1551
1586
  break;
1552
1587
  }
1553
1588
  this.logInfo('订单金额还有待付的,同步 EFTPOS 支付');
1554
1589
  // 检查是否是 EFTPOS 支付,如果是则立即同步订单
1555
- isEftposPayment = ((_paymentItem$type = paymentItem.type) === null || _paymentItem$type === void 0 ? void 0 : _paymentItem$type.toLowerCase()) === 'eftpos' || ((_paymentItem$code = paymentItem.code) === null || _paymentItem$code === void 0 ? void 0 : _paymentItem$code.toUpperCase().includes('EFTPOS'));
1590
+ _isEftposPayment = ((_paymentItem$type2 = paymentItem.type) === null || _paymentItem$type2 === void 0 ? void 0 : _paymentItem$type2.toLowerCase()) === 'eftpos' || ((_paymentItem$code2 = paymentItem.code) === null || _paymentItem$code2 === void 0 ? void 0 : _paymentItem$code2.toUpperCase().includes('EFTPOS'));
1556
1591
  _isCashPayment = paymentItem.code === 'CASHMANUAL';
1557
1592
  isCustomePayment = paymentItem.type === 'custom';
1558
1593
  this.logInfo('EFTPOS 支付检查:', {
1559
1594
  paymentCode: paymentItem.code,
1560
1595
  paymentType: paymentItem.type,
1561
- isEftposPayment: isEftposPayment,
1596
+ isEftposPayment: _isEftposPayment,
1562
1597
  currentOrderSynced: this.store.isOrderSynced
1563
1598
  });
1564
- if (!(isEftposPayment || _isCashPayment || isCustomePayment)) {
1565
- _context16.next = 39;
1599
+ if (!(_isEftposPayment || _isCashPayment || isCustomePayment)) {
1600
+ _context16.next = 52;
1566
1601
  break;
1567
1602
  }
1568
1603
  this.logInfo('检测到 EFTPOS 支付,立即同步订单到后端...');
1569
- _context16.prev = 27;
1570
- _context16.next = 30;
1604
+ _context16.prev = 40;
1605
+ _context16.next = 43;
1571
1606
  return this.syncOrderToBackendWithReturn(true);
1572
- case 30:
1607
+ case 43:
1573
1608
  syncResult = _context16.sent;
1574
1609
  this.logInfo('EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1575
1610
  orderId: syncResult.orderId,
1576
1611
  isOrderSynced: this.store.isOrderSynced,
1577
1612
  backendResponse: syncResult.response
1578
1613
  });
1579
- _context16.next = 39;
1614
+ _context16.next = 52;
1580
1615
  break;
1581
- case 34:
1582
- _context16.prev = 34;
1583
- _context16.t0 = _context16["catch"](27);
1584
- this.logError('EFTPOS 支付后订单同步失败:', _context16.t0);
1616
+ case 47:
1617
+ _context16.prev = 47;
1618
+ _context16.t1 = _context16["catch"](40);
1619
+ this.logError('EFTPOS 支付后订单同步失败:', _context16.t1);
1585
1620
  // 不抛出错误,避免影响支付流程,但记录错误
1586
- _context16.next = 39;
1587
- 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);
1588
- case 39:
1621
+ _context16.next = 52;
1622
+ return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context16.t1 instanceof Error ? _context16.t1.message : String(_context16.t1))), CheckoutErrorType.OrderCreationFailed);
1623
+ case 52:
1589
1624
  // 触发支付项添加事件(可以复用支付开始事件)
1590
1625
  this.core.effects.emit("".concat(this.name, ":onPaymentItemAdded"), {
1591
1626
  orderUuid: this.store.currentOrder.uuid,
@@ -1594,23 +1629,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1594
1629
  amount: String(paymentItem.amount),
1595
1630
  timestamp: Date.now()
1596
1631
  });
1597
- _context16.next = 48;
1632
+ _context16.next = 61;
1598
1633
  break;
1599
- case 42:
1600
- _context16.prev = 42;
1601
- _context16.t1 = _context16["catch"](1);
1602
- this.logError('添加支付项失败:', _context16.t1);
1603
- _context16.next = 47;
1604
- return this.handleError(_context16.t1, CheckoutErrorType.PaymentFailed);
1605
- case 47:
1606
- throw _context16.t1;
1607
- case 48:
1634
+ case 55:
1635
+ _context16.prev = 55;
1636
+ _context16.t2 = _context16["catch"](14);
1637
+ this.logError('添加支付项失败:', _context16.t2);
1638
+ _context16.next = 60;
1639
+ return this.handleError(_context16.t2, CheckoutErrorType.PaymentFailed);
1640
+ case 60:
1641
+ throw _context16.t2;
1642
+ case 61:
1608
1643
  case "end":
1609
1644
  return _context16.stop();
1610
1645
  }
1611
- }, _callee16, this, [[1, 42], [27, 34]]);
1646
+ }, _callee16, this, [[5, 10], [14, 55], [40, 47]]);
1612
1647
  }));
1613
- function addPaymentItemAsync(_x15) {
1648
+ function addPaymentItemAsync(_x15, _x16) {
1614
1649
  return _addPaymentItemAsync.apply(this, arguments);
1615
1650
  }
1616
1651
  return addPaymentItemAsync;
@@ -1724,7 +1759,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1724
1759
  }
1725
1760
  }, _callee17, this, [[0, 27]]);
1726
1761
  }));
1727
- function deletePaymentItemAsync(_x16) {
1762
+ function deletePaymentItemAsync(_x17) {
1728
1763
  return _deletePaymentItemAsync.apply(this, arguments);
1729
1764
  }
1730
1765
  return deletePaymentItemAsync;
@@ -1860,7 +1895,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1860
1895
  }
1861
1896
  }, _callee18, this, [[0, 34]]);
1862
1897
  }));
1863
- function updateVoucherPaymentItemsAsync(_x17) {
1898
+ function updateVoucherPaymentItemsAsync(_x18) {
1864
1899
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
1865
1900
  }
1866
1901
  return updateVoucherPaymentItemsAsync;
@@ -1964,7 +1999,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1964
1999
  }
1965
2000
  }, _callee19, this, [[0, 24]]);
1966
2001
  }));
1967
- function updateOrderDepositStatusAsync(_x18) {
2002
+ function updateOrderDepositStatusAsync(_x19) {
1968
2003
  return _updateOrderDepositStatusAsync.apply(this, arguments);
1969
2004
  }
1970
2005
  return updateOrderDepositStatusAsync;
@@ -1983,7 +2018,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1983
2018
  key: "setDepositAmountAsync",
1984
2019
  value: (function () {
1985
2020
  var _setDepositAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(depositAmount) {
1986
- var _this$store$currentOr10, _this$store$currentOr11;
2021
+ var _this$store$currentOr11, _this$store$currentOr12;
1987
2022
  var depositValue, formattedDepositAmount, oldDepositAmount, updateParams;
1988
2023
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1989
2024
  while (1) switch (_context20.prev = _context20.next) {
@@ -1991,8 +2026,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1991
2026
  this.logInfo('setDepositAmountAsync called', {
1992
2027
  depositAmount: depositAmount,
1993
2028
  hasCurrentOrder: !!this.store.currentOrder,
1994
- currentOrderId: (_this$store$currentOr10 = this.store.currentOrder) === null || _this$store$currentOr10 === void 0 ? void 0 : _this$store$currentOr10.order_id,
1995
- currentTotalAmount: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.total_amount
2029
+ currentOrderId: (_this$store$currentOr11 = this.store.currentOrder) === null || _this$store$currentOr11 === void 0 ? void 0 : _this$store$currentOr11.order_id,
2030
+ currentTotalAmount: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.total_amount
1996
2031
  });
1997
2032
  _context20.prev = 1;
1998
2033
  // 验证定金金额格式
@@ -2097,7 +2132,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2097
2132
  }
2098
2133
  }, _callee20, this, [[1, 26]]);
2099
2134
  }));
2100
- function setDepositAmountAsync(_x19) {
2135
+ function setDepositAmountAsync(_x20) {
2101
2136
  return _setDepositAmountAsync.apply(this, arguments);
2102
2137
  }
2103
2138
  return setDepositAmountAsync;
@@ -2112,17 +2147,17 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2112
2147
  key: "manualSyncOrderAsync",
2113
2148
  value: (function () {
2114
2149
  var _manualSyncOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2115
- var _this$store$currentOr12, _this$store$currentOr13, _this$store$currentOr14;
2116
- var _this$store$currentOr15, orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, newRes, _this$store$currentOr16, errorMessage;
2150
+ var _this$store$currentOr13, _this$store$currentOr14, _this$store$currentOr15;
2151
+ var _this$store$currentOr16, orderUuid, oldOrderId, syncResult, finalOrderId, finalIsVirtual, newRes, _this$store$currentOr17, errorMessage;
2117
2152
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2118
2153
  while (1) switch (_context21.prev = _context21.next) {
2119
2154
  case 0:
2120
2155
  console.log('manualSyncOrderAsync called');
2121
2156
  this.logInfo('manualSyncOrderAsync called', {
2122
2157
  hasCurrentOrder: !!this.store.currentOrder,
2123
- currentOrderId: (_this$store$currentOr12 = this.store.currentOrder) === null || _this$store$currentOr12 === void 0 ? void 0 : _this$store$currentOr12.order_id,
2124
- orderUuid: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.uuid,
2125
- totalAmount: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.total_amount,
2158
+ currentOrderId: (_this$store$currentOr13 = this.store.currentOrder) === null || _this$store$currentOr13 === void 0 ? void 0 : _this$store$currentOr13.order_id,
2159
+ orderUuid: (_this$store$currentOr14 = this.store.currentOrder) === null || _this$store$currentOr14 === void 0 ? void 0 : _this$store$currentOr14.uuid,
2160
+ totalAmount: (_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.total_amount,
2126
2161
  isOrderSynced: this.store.isOrderSynced,
2127
2162
  isVirtualOrderId: this.store.currentOrder ? isVirtualOrderId(this.store.currentOrder.order_id) : false
2128
2163
  });
@@ -2182,7 +2217,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2182
2217
  this.logError('[Checkout] 严重警告:返回的订单ID与存储的订单ID不一致!');
2183
2218
  }
2184
2219
  newRes = _objectSpread(_objectSpread({}, syncResult), {}, {
2185
- is_deposit: ((_this$store$currentOr15 = this.store.currentOrder) === null || _this$store$currentOr15 === void 0 ? void 0 : _this$store$currentOr15.is_deposit) || 0
2220
+ is_deposit: ((_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.is_deposit) || 0
2186
2221
  });
2187
2222
  _context21.next = 30;
2188
2223
  return this.updateStateAmountToRemaining(false);
@@ -2196,7 +2231,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2196
2231
  return _context21.abrupt("return", {
2197
2232
  success: false,
2198
2233
  message: "\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(errorMessage),
2199
- orderUuid: (_this$store$currentOr16 = this.store.currentOrder) === null || _this$store$currentOr16 === void 0 ? void 0 : _this$store$currentOr16.uuid
2234
+ orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid
2200
2235
  });
2201
2236
  case 38:
2202
2237
  case "end":
@@ -2273,15 +2308,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2273
2308
  key: "cancelCurrentOrderAsync",
2274
2309
  value: (function () {
2275
2310
  var _cancelCurrentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(cancelReason) {
2276
- var _this$store$currentOr17, _this$store$currentOr18, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2311
+ var _this$store$currentOr18, _this$store$currentOr19, currentOrderUuid, currentOrderId, isOrderSynced, errorMessage;
2277
2312
  return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2278
2313
  while (1) switch (_context22.prev = _context22.next) {
2279
2314
  case 0:
2280
2315
  _context22.prev = 0;
2281
2316
  this.logInfo('开始取消当前本地订单:', {
2282
2317
  hasCurrentOrder: !!this.store.currentOrder,
2283
- orderUuid: (_this$store$currentOr17 = this.store.currentOrder) === null || _this$store$currentOr17 === void 0 ? void 0 : _this$store$currentOr17.uuid,
2284
- orderId: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.order_id,
2318
+ orderUuid: (_this$store$currentOr18 = this.store.currentOrder) === null || _this$store$currentOr18 === void 0 ? void 0 : _this$store$currentOr18.uuid,
2319
+ orderId: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.order_id,
2285
2320
  isOrderSynced: this.store.isOrderSynced,
2286
2321
  cancelReason: cancelReason
2287
2322
  });
@@ -2315,17 +2350,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2315
2350
  });
2316
2351
  case 11:
2317
2352
  _context22.prev = 11;
2318
- this.logInfo('删除本地订单数据');
2353
+ this.logInfo('标记本地订单为已删除');
2319
2354
  _context22.next = 15;
2320
- return this.payment.deletePaymentOrderAsync(currentOrderUuid);
2355
+ return this.payment.updateOrderAsync(currentOrderUuid, {
2356
+ payment_status: PaymentStatus.Voided
2357
+ });
2321
2358
  case 15:
2322
- this.logInfo('本地订单数据删除成功');
2359
+ this.logInfo('本地订单删除标记成功');
2323
2360
  _context22.next = 21;
2324
2361
  break;
2325
2362
  case 18:
2326
2363
  _context22.prev = 18;
2327
2364
  _context22.t0 = _context22["catch"](11);
2328
- this.logWarning('删除本地订单数据失败,但继续执行:', _context22.t0);
2365
+ this.logWarning('标记本地订单删除失败,但继续执行:', _context22.t0);
2329
2366
  case 21:
2330
2367
  // 清理订单相关状态,确保正确释放 currentOrder
2331
2368
  this.logInfo('清理订单相关状态');
@@ -2376,7 +2413,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2376
2413
  }
2377
2414
  }, _callee22, this, [[0, 36], [11, 18]]);
2378
2415
  }));
2379
- function cancelCurrentOrderAsync(_x20) {
2416
+ function cancelCurrentOrderAsync(_x21) {
2380
2417
  return _cancelCurrentOrderAsync.apply(this, arguments);
2381
2418
  }
2382
2419
  return cancelCurrentOrderAsync;
@@ -2392,7 +2429,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2392
2429
  key: "saveForLaterPaymentAsync",
2393
2430
  value: (function () {
2394
2431
  var _saveForLaterPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2395
- var orderUuid, currentOrderId, allPaymentItems, orderPaymentStatus, syncResult, _this$store$currentOr19, errorMessage;
2432
+ var orderUuid, currentOrderId, allPaymentItems, orderPaymentStatus, syncResult, _this$store$currentOr20, errorMessage;
2396
2433
  return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2397
2434
  while (1) switch (_context23.prev = _context23.next) {
2398
2435
  case 0:
@@ -2451,7 +2488,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2451
2488
  return _context23.abrupt("return", {
2452
2489
  success: false,
2453
2490
  message: "\u8BA2\u5355\u4FDD\u5B58\u5931\u8D25: ".concat(errorMessage),
2454
- orderUuid: (_this$store$currentOr19 = this.store.currentOrder) === null || _this$store$currentOr19 === void 0 ? void 0 : _this$store$currentOr19.uuid
2491
+ orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid
2455
2492
  });
2456
2493
  case 22:
2457
2494
  case "end":
@@ -2474,7 +2511,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2474
2511
  key: "updateOrderNoteAsync",
2475
2512
  value: (function () {
2476
2513
  var _updateOrderNoteAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(note) {
2477
- var _this$store$currentOr20, _this$store$currentOr21, oldNote, orderInPayment;
2514
+ var _this$store$currentOr21, _this$store$currentOr22, oldNote, orderInPayment;
2478
2515
  return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2479
2516
  while (1) switch (_context24.prev = _context24.next) {
2480
2517
  case 0:
@@ -2486,7 +2523,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2486
2523
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '没有本地订单数据,无法更新备注');
2487
2524
  case 3:
2488
2525
  console.log('[Checkout] 更新订单备注:', {
2489
- orderUuid: (_this$store$currentOr20 = this.store.currentOrder) === null || _this$store$currentOr20 === void 0 ? void 0 : _this$store$currentOr20.uuid,
2526
+ orderUuid: (_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.uuid,
2490
2527
  oldNote: this.store.localOrderData.shop_note,
2491
2528
  newNote: note
2492
2529
  });
@@ -2519,7 +2556,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2519
2556
  case 17:
2520
2557
  _context24.next = 19;
2521
2558
  return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
2522
- orderUuid: (_this$store$currentOr21 = this.store.currentOrder) === null || _this$store$currentOr21 === void 0 ? void 0 : _this$store$currentOr21.uuid,
2559
+ orderUuid: (_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.uuid,
2523
2560
  oldNote: oldNote,
2524
2561
  newNote: note,
2525
2562
  timestamp: Date.now()
@@ -2545,7 +2582,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2545
2582
  }
2546
2583
  }, _callee24, this, [[0, 22], [7, 14]]);
2547
2584
  }));
2548
- function updateOrderNoteAsync(_x21) {
2585
+ function updateOrderNoteAsync(_x22) {
2549
2586
  return _updateOrderNoteAsync.apply(this, arguments);
2550
2587
  }
2551
2588
  return updateOrderNoteAsync;
@@ -2578,7 +2615,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2578
2615
  }
2579
2616
  }, _callee25, this);
2580
2617
  }));
2581
- function handleError(_x22, _x23) {
2618
+ function handleError(_x23, _x24) {
2582
2619
  return _handleError.apply(this, arguments);
2583
2620
  }
2584
2621
  return handleError;
@@ -2591,7 +2628,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2591
2628
  key: "handlePaymentSuccess",
2592
2629
  value: (function () {
2593
2630
  var _handlePaymentSuccess = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(data) {
2594
- var _this$store$currentOr22;
2631
+ var _this$store$currentOr23;
2595
2632
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2596
2633
  while (1) switch (_context26.prev = _context26.next) {
2597
2634
  case 0:
@@ -2602,7 +2639,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2602
2639
  return this.core.effects.emit("".concat(this.name, ":onPaymentSuccess"), {
2603
2640
  orderUuid: data.orderUuid,
2604
2641
  paymentMethodCode: '',
2605
- amount: ((_this$store$currentOr22 = this.store.currentOrder) === null || _this$store$currentOr22 === void 0 ? void 0 : _this$store$currentOr22.total_amount) || '0',
2642
+ amount: ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.total_amount) || '0',
2606
2643
  timestamp: data.timestamp
2607
2644
  });
2608
2645
  case 4:
@@ -2614,7 +2651,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2614
2651
  }
2615
2652
  }, _callee26, this);
2616
2653
  }));
2617
- function handlePaymentSuccess(_x24) {
2654
+ function handlePaymentSuccess(_x25) {
2618
2655
  return _handlePaymentSuccess.apply(this, arguments);
2619
2656
  }
2620
2657
  return handlePaymentSuccess;
@@ -2627,7 +2664,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2627
2664
  key: "handlePaymentError",
2628
2665
  value: (function () {
2629
2666
  var _handlePaymentError = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(data) {
2630
- var _this$store$currentOr23;
2667
+ var _this$store$currentOr24;
2631
2668
  var error;
2632
2669
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2633
2670
  while (1) switch (_context27.prev = _context27.next) {
@@ -2640,7 +2677,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2640
2677
  return this.core.effects.emit("".concat(this.name, ":onPaymentFailed"), {
2641
2678
  orderUuid: data.orderUuid,
2642
2679
  paymentMethodCode: '',
2643
- amount: ((_this$store$currentOr23 = this.store.currentOrder) === null || _this$store$currentOr23 === void 0 ? void 0 : _this$store$currentOr23.total_amount) || '0',
2680
+ amount: ((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.total_amount) || '0',
2644
2681
  timestamp: data.timestamp
2645
2682
  });
2646
2683
  case 5:
@@ -2649,7 +2686,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2649
2686
  }
2650
2687
  }, _callee27, this);
2651
2688
  }));
2652
- function handlePaymentError(_x25) {
2689
+ function handlePaymentError(_x26) {
2653
2690
  return _handlePaymentError.apply(this, arguments);
2654
2691
  }
2655
2692
  return handlePaymentError;
@@ -2750,7 +2787,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
2750
2787
  }
2751
2788
  }, _callee28, this, [[3, 23]]);
2752
2789
  }));
2753
- function processCashPaymentItem(_x26) {
2790
+ function processCashPaymentItem(_x27) {
2754
2791
  return _processCashPaymentItem.apply(this, arguments);
2755
2792
  }
2756
2793
  return processCashPaymentItem;
@@ -3616,7 +3653,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3616
3653
  }
3617
3654
  }, _callee37, this, [[0, 23]]);
3618
3655
  }));
3619
- function checkOrderPaymentCompletionOptimized(_x27, _x28) {
3656
+ function checkOrderPaymentCompletionOptimized(_x28, _x29) {
3620
3657
  return _checkOrderPaymentCompletionOptimized.apply(this, arguments);
3621
3658
  }
3622
3659
  return checkOrderPaymentCompletionOptimized;
@@ -3749,6 +3786,343 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3749
3786
  return _checkOrderPaymentCompletion.apply(this, arguments);
3750
3787
  }
3751
3788
  return checkOrderPaymentCompletion;
3789
+ }())
3790
+ }, {
3791
+ key: "repairEftposPaymentFromIndexDbAsync",
3792
+ value: function () {
3793
+ var _repairEftposPaymentFromIndexDbAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
3794
+ var orderUuid, paymentItem, order, orderPaymentType, processedPaymentItem, metadata, paymentItemWithType;
3795
+ return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3796
+ while (1) switch (_context39.prev = _context39.next) {
3797
+ case 0:
3798
+ orderUuid = params.orderUuid, paymentItem = params.paymentItem;
3799
+ _context39.next = 3;
3800
+ return this.payment.getPaymentOrderByUuidAsync(orderUuid);
3801
+ case 3:
3802
+ order = _context39.sent;
3803
+ if (order) {
3804
+ _context39.next = 7;
3805
+ break;
3806
+ }
3807
+ this.logError('EFTPOS repair failed: order not found in IndexDB', {
3808
+ orderUuid: orderUuid,
3809
+ paymentItem: paymentItem
3810
+ });
3811
+ return _context39.abrupt("return");
3812
+ case 7:
3813
+ orderPaymentType = order.is_deposit === 1 ? 'deposit' : 'normal';
3814
+ _context39.next = 10;
3815
+ return this.processCashPaymentItem(paymentItem);
3816
+ case 10:
3817
+ processedPaymentItem = _context39.sent;
3818
+ metadata = _objectSpread(_objectSpread({}, processedPaymentItem.metadata), {}, {
3819
+ rounding_rule: this.otherParams.order_rounding_setting,
3820
+ shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
3821
+ });
3822
+ paymentItemWithType = _objectSpread(_objectSpread({}, processedPaymentItem), {}, {
3823
+ order_payment_type: orderPaymentType,
3824
+ metadata: metadata
3825
+ });
3826
+ _context39.next = 15;
3827
+ return this.payment.addPaymentItemAsync(orderUuid, paymentItemWithType);
3828
+ case 15:
3829
+ _context39.next = 17;
3830
+ return this.syncOrderToBackendFromIndexDbAsync({
3831
+ orderUuid: orderUuid
3832
+ });
3833
+ case 17:
3834
+ case "end":
3835
+ return _context39.stop();
3836
+ }
3837
+ }, _callee39, this);
3838
+ }));
3839
+ function repairEftposPaymentFromIndexDbAsync(_x30) {
3840
+ return _repairEftposPaymentFromIndexDbAsync.apply(this, arguments);
3841
+ }
3842
+ return repairEftposPaymentFromIndexDbAsync;
3843
+ }()
3844
+ }, {
3845
+ key: "syncOrderToBackendFromIndexDbAsync",
3846
+ value: function () {
3847
+ var _syncOrderToBackendFromIndexDbAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
3848
+ var _paymentOrder$order_i,
3849
+ _paymentOrder$order_i2,
3850
+ _this6 = this,
3851
+ _this$otherParams,
3852
+ _localOrderData$booki,
3853
+ _localOrderData$relat,
3854
+ _checkoutResponse2,
3855
+ _checkoutResponse3,
3856
+ _checkoutResponse7;
3857
+ var orderUuid, paymentOrder, localOrderData, paymentItems, processedPaymentItems, finalDepositAmount, manualDepositAmount, manualDepositValue, orderPaymentStatus, totalPaidAmount, orderParams, currentOrderId, isUpdateOperation, checkoutResponse, _checkoutResponse, responseStatus, isSuccessResponse, _checkoutResponse4, errorMessage, realOrderId, _checkoutResponse5, extractedOrderId, _checkoutResponse6, syncedPaymentUuids, _iterator3, _step3, paymentUuid, latestPaymentStatus;
3858
+ return _regeneratorRuntime().wrap(function _callee40$(_context40) {
3859
+ while (1) switch (_context40.prev = _context40.next) {
3860
+ case 0:
3861
+ orderUuid = params.orderUuid;
3862
+ _context40.next = 3;
3863
+ return this.payment.getPaymentOrderByUuidAsync(orderUuid);
3864
+ case 3:
3865
+ paymentOrder = _context40.sent;
3866
+ if (paymentOrder) {
3867
+ _context40.next = 7;
3868
+ break;
3869
+ }
3870
+ this.logError('EFTPOS repair sync failed: missing payment order', {
3871
+ orderUuid: orderUuid
3872
+ });
3873
+ return _context40.abrupt("return", {
3874
+ success: false
3875
+ });
3876
+ case 7:
3877
+ localOrderData = ((_paymentOrder$order_i = paymentOrder.order_info) === null || _paymentOrder$order_i === void 0 ? void 0 : _paymentOrder$order_i.original_order_data) || ((_paymentOrder$order_i2 = paymentOrder.order_info) === null || _paymentOrder$order_i2 === void 0 ? void 0 : _paymentOrder$order_i2.order_data);
3878
+ if (localOrderData) {
3879
+ _context40.next = 11;
3880
+ break;
3881
+ }
3882
+ this.logError('EFTPOS repair sync failed: missing local order data', {
3883
+ orderUuid: orderUuid,
3884
+ orderInfoKeys: Object.keys(paymentOrder.order_info || {})
3885
+ });
3886
+ return _context40.abrupt("return", {
3887
+ success: false
3888
+ });
3889
+ case 11:
3890
+ _context40.next = 13;
3891
+ return this.payment.getPaymentItemsAsync(orderUuid);
3892
+ case 13:
3893
+ paymentItems = _context40.sent;
3894
+ processedPaymentItems = paymentItems.map(function (item) {
3895
+ var _item$metadata, _item$metadata2;
3896
+ return _objectSpread(_objectSpread({}, item), {}, {
3897
+ metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
3898
+ rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this6.otherParams.order_rounding_setting,
3899
+ shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this6.otherParams.shop_wallet_pass_id
3900
+ })
3901
+ });
3902
+ });
3903
+ manualDepositAmount = paymentOrder.deposit_amount || '0.00';
3904
+ manualDepositValue = new Decimal(manualDepositAmount);
3905
+ if (manualDepositValue.gt(0)) {
3906
+ finalDepositAmount = manualDepositAmount;
3907
+ } else {
3908
+ finalDepositAmount = '0.00';
3909
+ }
3910
+ if (paymentOrder.is_deposit === 0 && processedPaymentItems.every(function (item) {
3911
+ return item.order_payment_type !== 'deposit';
3912
+ })) {
3913
+ finalDepositAmount = '0.00';
3914
+ }
3915
+ if (paymentOrder.is_deposit === 0 && processedPaymentItems.some(function (item) {
3916
+ return item.order_payment_type === 'deposit';
3917
+ })) {
3918
+ finalDepositAmount = processedPaymentItems.filter(function (item) {
3919
+ return item.status !== 'voided' && item.order_payment_type === 'deposit';
3920
+ }).reduce(function (sum, item) {
3921
+ var amountValue = new Decimal(item.amount || '0');
3922
+ var roundingValue = new Decimal(item.rounding_amount || '0');
3923
+ return sum.plus(amountValue).sub(roundingValue);
3924
+ }, new Decimal(0)).toFixed(2);
3925
+ }
3926
+ if (paymentOrder.is_deposit === 1 && new Decimal(finalDepositAmount).gte(new Decimal(paymentOrder.total_amount))) {
3927
+ finalDepositAmount = processedPaymentItems.filter(function (item) {
3928
+ return item.status !== 'voided' && item.order_payment_type === 'deposit';
3929
+ }).reduce(function (sum, item) {
3930
+ var amountValue = new Decimal(item.amount || '0');
3931
+ var roundingValue = new Decimal(item.rounding_amount || '0');
3932
+ return sum.plus(amountValue).sub(roundingValue);
3933
+ }, new Decimal(0)).toFixed(2);
3934
+ }
3935
+ totalPaidAmount = processedPaymentItems.filter(function (item) {
3936
+ return item.status !== 'voided';
3937
+ }).reduce(function (sum, item) {
3938
+ var amountValue = new Decimal(item.amount || '0');
3939
+ var roundingValue = new Decimal(item.rounding_amount || '0');
3940
+ return sum.plus(amountValue).sub(roundingValue);
3941
+ }, new Decimal(0));
3942
+ if (totalPaidAmount.gte(new Decimal(paymentOrder.total_amount))) {
3943
+ orderPaymentStatus = 'paid';
3944
+ } else if (totalPaidAmount.gt(0)) {
3945
+ orderPaymentStatus = 'partially_paid';
3946
+ } else {
3947
+ orderPaymentStatus = 'unpaid';
3948
+ }
3949
+ orderParams = _objectSpread(_objectSpread({}, localOrderData), {}, {
3950
+ payment_status: orderPaymentStatus,
3951
+ type: localOrderData.type,
3952
+ platform: localOrderData.platform,
3953
+ payments: processedPaymentItems,
3954
+ customer_id: localOrderData.customer_id,
3955
+ is_price_include_tax: this.otherParams.is_price_include_tax,
3956
+ tax_title: this.otherParams.tax_title,
3957
+ tax_rate: this.otherParams.tax_rate,
3958
+ tax_country_code: this.otherParams.tax_country_code,
3959
+ currency_code: this.otherParams.currency_code,
3960
+ currency_symbol: this.otherParams.currency_symbol,
3961
+ currency_format: this.otherParams.currency_format,
3962
+ business_code: ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.business_code) || undefined,
3963
+ is_deposit: (paymentOrder.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
3964
+ deposit_amount: finalDepositAmount,
3965
+ product_tax_fee: localOrderData.tax_fee,
3966
+ note: localOrderData.shop_note,
3967
+ bookings: (_localOrderData$booki = localOrderData.bookings) === null || _localOrderData$booki === void 0 ? void 0 : _localOrderData$booki.map(function (item) {
3968
+ return _objectSpread(_objectSpread({}, item), {}, {
3969
+ product: _objectSpread(_objectSpread({}, item.product), {}, {
3970
+ custom_deposit_data: undefined
3971
+ }),
3972
+ deposit: undefined
3973
+ });
3974
+ }),
3975
+ relation_products: (_localOrderData$relat = localOrderData.relation_products) === null || _localOrderData$relat === void 0 ? void 0 : _localOrderData$relat.map(function (item) {
3976
+ return _objectSpread(_objectSpread({}, item), {}, {
3977
+ custom_deposit_data: undefined,
3978
+ deposit: undefined
3979
+ });
3980
+ })
3981
+ });
3982
+ currentOrderId = paymentOrder.order_id;
3983
+ isUpdateOperation = currentOrderId && !isVirtualOrderId(currentOrderId);
3984
+ if (isUpdateOperation) {
3985
+ orderParams.order_id = currentOrderId;
3986
+ }
3987
+ this.logError('EFTPOS repair sync start', {
3988
+ orderUuid: orderUuid,
3989
+ orderId: currentOrderId,
3990
+ isUpdateOperation: isUpdateOperation,
3991
+ paymentItemCount: processedPaymentItems.length
3992
+ });
3993
+ _context40.prev = 28;
3994
+ this.logError('EFTPOS repair calling backend checkout API', _objectSpread({
3995
+ url: '/order/checkout',
3996
+ isManual: true
3997
+ }, orderParams));
3998
+ _context40.next = 32;
3999
+ return this.order.createOrderByCheckout(orderParams);
4000
+ case 32:
4001
+ checkoutResponse = _context40.sent;
4002
+ _context40.next = 39;
4003
+ break;
4004
+ case 35:
4005
+ _context40.prev = 35;
4006
+ _context40.t0 = _context40["catch"](28);
4007
+ this.logError('EFTPOS repair checkout API failed', {
4008
+ orderUuid: orderUuid,
4009
+ error: _context40.t0 instanceof Error ? _context40.t0.message : String(_context40.t0)
4010
+ });
4011
+ throw _context40.t0;
4012
+ case 39:
4013
+ _context40.prev = 39;
4014
+ this.logError('EFTPOS repair sync end', {
4015
+ orderUuid: orderUuid,
4016
+ orderId: currentOrderId,
4017
+ responseStatus: (_checkoutResponse = checkoutResponse) === null || _checkoutResponse === void 0 ? void 0 : _checkoutResponse.status
4018
+ });
4019
+ return _context40.finish(39);
4020
+ case 42:
4021
+ responseStatus = (_checkoutResponse2 = checkoutResponse) === null || _checkoutResponse2 === void 0 ? void 0 : _checkoutResponse2.status;
4022
+ isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.code) === 200;
4023
+ if (isSuccessResponse) {
4024
+ _context40.next = 48;
4025
+ break;
4026
+ }
4027
+ errorMessage = ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.message) || '订单同步失败,后端返回非成功状态';
4028
+ this.logError('EFTPOS repair sync failed: api error', {
4029
+ orderUuid: orderUuid,
4030
+ errorMessage: errorMessage,
4031
+ response: checkoutResponse
4032
+ });
4033
+ return _context40.abrupt("return", {
4034
+ success: false,
4035
+ response: checkoutResponse
4036
+ });
4037
+ case 48:
4038
+ realOrderId = currentOrderId;
4039
+ if (isUpdateOperation) {
4040
+ _context40.next = 60;
4041
+ break;
4042
+ }
4043
+ extractedOrderId = (_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 || (_checkoutResponse5 = _checkoutResponse5.data) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.order_id;
4044
+ if (!extractedOrderId) {
4045
+ extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id;
4046
+ }
4047
+ if (extractedOrderId !== undefined && extractedOrderId !== null) {
4048
+ extractedOrderId = String(extractedOrderId);
4049
+ }
4050
+ realOrderId = extractedOrderId;
4051
+ if (!realOrderId) {
4052
+ _context40.next = 59;
4053
+ break;
4054
+ }
4055
+ _context40.next = 57;
4056
+ return this.payment.replaceOrderIdByUuidAsync(orderUuid, realOrderId);
4057
+ case 57:
4058
+ _context40.next = 60;
4059
+ break;
4060
+ case 59:
4061
+ this.logError('EFTPOS repair missing order_id in response', {
4062
+ orderUuid: orderUuid,
4063
+ response: checkoutResponse
4064
+ });
4065
+ case 60:
4066
+ syncedPaymentUuids = processedPaymentItems.filter(function (item) {
4067
+ return item.status !== 'voided';
4068
+ }).map(function (item) {
4069
+ return item.uuid;
4070
+ }).filter(Boolean);
4071
+ _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
4072
+ _context40.prev = 62;
4073
+ _iterator3.s();
4074
+ case 64:
4075
+ if ((_step3 = _iterator3.n()).done) {
4076
+ _context40.next = 70;
4077
+ break;
4078
+ }
4079
+ paymentUuid = _step3.value;
4080
+ _context40.next = 68;
4081
+ return this.payment.updatePaymentAsync(orderUuid, paymentUuid, {
4082
+ isSynced: true,
4083
+ syncError: undefined
4084
+ });
4085
+ case 68:
4086
+ _context40.next = 64;
4087
+ break;
4088
+ case 70:
4089
+ _context40.next = 75;
4090
+ break;
4091
+ case 72:
4092
+ _context40.prev = 72;
4093
+ _context40.t1 = _context40["catch"](62);
4094
+ _iterator3.e(_context40.t1);
4095
+ case 75:
4096
+ _context40.prev = 75;
4097
+ _iterator3.f();
4098
+ return _context40.finish(75);
4099
+ case 78:
4100
+ latestPaymentStatus = ((_checkoutResponse7 = checkoutResponse) === null || _checkoutResponse7 === void 0 || (_checkoutResponse7 = _checkoutResponse7.data) === null || _checkoutResponse7 === void 0 ? void 0 : _checkoutResponse7.payment_status) || orderPaymentStatus;
4101
+ _context40.next = 81;
4102
+ return this.payment.updateOrderAsync(orderUuid, {
4103
+ payment_status: latestPaymentStatus
4104
+ });
4105
+ case 81:
4106
+ // 最后同步一个支付项添加成功事件,让购物车那边也显示支付成功
4107
+ // 触发支付项添加事件(可以复用支付开始事件)
4108
+ this.core.effects.emit("".concat(this.name, ":onPaymentItemAdded"), {
4109
+ orderUuid: orderUuid
4110
+ });
4111
+ return _context40.abrupt("return", {
4112
+ success: true,
4113
+ orderId: realOrderId,
4114
+ response: checkoutResponse
4115
+ });
4116
+ case 83:
4117
+ case "end":
4118
+ return _context40.stop();
4119
+ }
4120
+ }, _callee40, this, [[28, 35, 39, 42], [62, 72, 75, 78]]);
4121
+ }));
4122
+ function syncOrderToBackendFromIndexDbAsync(_x31) {
4123
+ return _syncOrderToBackendFromIndexDbAsync.apply(this, arguments);
4124
+ }
4125
+ return syncOrderToBackendFromIndexDbAsync;
3752
4126
  }()
3753
4127
  /**
3754
4128
  * 同步订单到后端并返回真实订单ID
@@ -3757,20 +4131,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3757
4131
  * @param customPaymentItems 自定义支付项列表,如果提供则使用此列表而不是从数据库获取
3758
4132
  * @returns 包含订单ID、UUID和完整后端响应的对象
3759
4133
  */
3760
- )
3761
4134
  }, {
3762
4135
  key: "syncOrderToBackendWithReturn",
3763
4136
  value: (function () {
3764
- var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39() {
3765
- var _this6 = this,
3766
- _this$store$currentOr24,
4137
+ var _syncOrderToBackendWithReturn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41() {
4138
+ var _this7 = this,
3767
4139
  _this$store$currentOr25,
3768
- _this$store$currentCu2,
3769
4140
  _this$store$currentOr26,
4141
+ _this$store$currentCu2,
4142
+ _this$store$currentOr27,
3770
4143
  _this$store$localOrde,
3771
4144
  _this$store$localOrde2,
3772
- _checkoutResponse3,
3773
- _checkoutResponse4;
4145
+ _checkoutResponse10,
4146
+ _checkoutResponse11;
3774
4147
  var isManual,
3775
4148
  customPaymentItems,
3776
4149
  paymentStatus,
@@ -3788,33 +4161,33 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3788
4161
  checkoutResponse,
3789
4162
  submitSuccess,
3790
4163
  submitError,
3791
- _checkoutResponse,
3792
- _checkoutResponse2,
4164
+ _checkoutResponse8,
4165
+ _checkoutResponse9,
3793
4166
  responseStatus,
3794
4167
  isSuccessResponse,
3795
- _checkoutResponse5,
4168
+ _checkoutResponse12,
3796
4169
  errorMessage,
3797
4170
  realOrderId,
3798
- _checkoutResponse6,
4171
+ _checkoutResponse13,
3799
4172
  extractedOrderId,
3800
- _checkoutResponse7,
4173
+ _checkoutResponse14,
3801
4174
  latestPaymentStatus,
3802
4175
  previousOrder,
3803
4176
  updatedOrder,
3804
4177
  beforeManualUpdate,
3805
4178
  syncedPaymentUuids,
3806
- _iterator3,
3807
- _step3,
4179
+ _iterator4,
4180
+ _step4,
3808
4181
  paymentUuid,
3809
- _args39 = arguments;
3810
- return _regeneratorRuntime().wrap(function _callee39$(_context39) {
3811
- while (1) switch (_context39.prev = _context39.next) {
4182
+ _args41 = arguments;
4183
+ return _regeneratorRuntime().wrap(function _callee41$(_context41) {
4184
+ while (1) switch (_context41.prev = _context41.next) {
3812
4185
  case 0:
3813
- isManual = _args39.length > 0 && _args39[0] !== undefined ? _args39[0] : false;
3814
- customPaymentItems = _args39.length > 1 ? _args39[1] : undefined;
3815
- paymentStatus = _args39.length > 2 ? _args39[2] : undefined;
4186
+ isManual = _args41.length > 0 && _args41[0] !== undefined ? _args41[0] : false;
4187
+ customPaymentItems = _args41.length > 1 ? _args41[1] : undefined;
4188
+ paymentStatus = _args41.length > 2 ? _args41[2] : undefined;
3816
4189
  if (!(!this.store.localOrderData || !this.store.currentOrder)) {
3817
- _context39.next = 5;
4190
+ _context41.next = 5;
3818
4191
  break;
3819
4192
  }
3820
4193
  throw new Error('缺少必要的订单数据,无法同步到后端');
@@ -3833,28 +4206,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3833
4206
  });
3834
4207
 
3835
4208
  // 获取当前订单的支付项
3836
- _context39.t0 = customPaymentItems;
3837
- if (_context39.t0) {
3838
- _context39.next = 14;
4209
+ _context41.t0 = customPaymentItems;
4210
+ if (_context41.t0) {
4211
+ _context41.next = 14;
3839
4212
  break;
3840
4213
  }
3841
- _context39.next = 13;
4214
+ _context41.next = 13;
3842
4215
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
3843
4216
  case 13:
3844
- _context39.t0 = _context39.sent;
4217
+ _context41.t0 = _context41.sent;
3845
4218
  case 14:
3846
- paymentItems = _context39.t0;
4219
+ paymentItems = _context41.t0;
3847
4220
  // 处理支付项数据,确保包含完整的 metadata
3848
4221
  processedPaymentItems = paymentItems.map(function (item) {
3849
- var _item$metadata, _item$metadata2;
4222
+ var _item$metadata3, _item$metadata4;
3850
4223
  return _objectSpread(_objectSpread({}, item), {}, {
3851
4224
  metadata: _objectSpread(_objectSpread({}, item.metadata), {}, {
3852
- rounding_rule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.rounding_rule) || _this6.otherParams.order_rounding_setting,
3853
- shop_wallet_pass_id: ((_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.shop_wallet_pass_id) || _this6.otherParams.shop_wallet_pass_id
4225
+ rounding_rule: ((_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.rounding_rule) || _this7.otherParams.order_rounding_setting,
4226
+ shop_wallet_pass_id: ((_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.shop_wallet_pass_id) || _this7.otherParams.shop_wallet_pass_id
3854
4227
  })
3855
4228
  });
3856
4229
  }); // 确定最终的定金金额:优先使用手动设置的值,否则从支付项中计算
3857
- manualDepositAmount = ((_this$store$currentOr24 = this.store.currentOrder) === null || _this$store$currentOr24 === void 0 ? void 0 : _this$store$currentOr24.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
4230
+ manualDepositAmount = ((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.deposit_amount) || '0.00'; // 优先级逻辑:手动设置的定金金额 > 从支付项计算的金额
3858
4231
  manualDepositValue = new Decimal(manualDepositAmount);
3859
4232
  if (manualDepositValue.gt(0)) {
3860
4233
  // 如果手动设置了定金金额且大于0,使用手动设置的值
@@ -3914,7 +4287,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3914
4287
  }),
3915
4288
  manualDepositAmount: manualDepositAmount,
3916
4289
  finalDepositAmount: finalDepositAmount,
3917
- isDeposit: ((_this$store$currentOr25 = this.store.currentOrder) === null || _this$store$currentOr25 === void 0 ? void 0 : _this$store$currentOr25.is_deposit) || 0
4290
+ isDeposit: ((_this$store$currentOr26 = this.store.currentOrder) === null || _this$store$currentOr26 === void 0 ? void 0 : _this$store$currentOr26.is_deposit) || 0
3918
4291
  });
3919
4292
 
3920
4293
  // 计算订单状态,优先读取外面传递的,如果没有则根据订单支付数据来
@@ -3961,7 +4334,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3961
4334
  currency_code: this.otherParams.currency_code,
3962
4335
  currency_symbol: this.otherParams.currency_symbol,
3963
4336
  currency_format: this.otherParams.currency_format,
3964
- is_deposit: ((_this$store$currentOr26 = this.store.currentOrder) !== null && _this$store$currentOr26 !== void 0 && _this$store$currentOr26.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
4337
+ is_deposit: ((_this$store$currentOr27 = this.store.currentOrder) !== null && _this$store$currentOr27 !== void 0 && _this$store$currentOr27.is_deposit || Number(finalDepositAmount) > 0 ? 1 : 0) || 0,
3965
4338
  deposit_amount: finalDepositAmount,
3966
4339
  // 使用最终确定的定金金额(手动设置优先)
3967
4340
  product_tax_fee: this.store.localOrderData.tax_fee,
@@ -3992,7 +4365,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3992
4365
 
3993
4366
  // 发送下单接口请求开始事件
3994
4367
  startTime = Date.now();
3995
- _context39.next = 30;
4368
+ _context41.next = 30;
3996
4369
  return this.core.effects.emit("".concat(this.name, ":onOrderSubmitStart"), {
3997
4370
  orderUuid: this.store.currentOrder.uuid,
3998
4371
  operation: isUpdateOperation ? 'update' : 'create',
@@ -4002,7 +4375,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4002
4375
  });
4003
4376
  case 30:
4004
4377
  submitSuccess = false;
4005
- _context39.prev = 31;
4378
+ _context41.prev = 31;
4006
4379
  // 记录接口调用参数
4007
4380
  this.logInfo('Calling backend checkout API', _objectSpread({
4008
4381
  url: '/order/checkout',
@@ -4010,24 +4383,24 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4010
4383
  }, orderParams));
4011
4384
 
4012
4385
  // 调用 Order 模块的专用 createOrderByCheckout 方法
4013
- _context39.next = 35;
4386
+ _context41.next = 35;
4014
4387
  return this.order.createOrderByCheckout(orderParams);
4015
4388
  case 35:
4016
- checkoutResponse = _context39.sent;
4389
+ checkoutResponse = _context41.sent;
4017
4390
  submitSuccess = true;
4018
4391
  this.store.currentOrder.payment_status = checkoutResponse.data.payment_status;
4019
4392
  this.logInfo('下单接口调用成功', checkoutResponse);
4020
- _context39.next = 49;
4393
+ _context41.next = 49;
4021
4394
  break;
4022
4395
  case 41:
4023
- _context39.prev = 41;
4024
- _context39.t1 = _context39["catch"](31);
4396
+ _context41.prev = 41;
4397
+ _context41.t1 = _context41["catch"](31);
4025
4398
  submitSuccess = false;
4026
- submitError = _context39.t1 instanceof Error ? _context39.t1.message : String(_context39.t1);
4399
+ submitError = _context41.t1 instanceof Error ? _context41.t1.message : String(_context41.t1);
4027
4400
  this.logError('下单接口调用失败:', submitError);
4028
4401
 
4029
4402
  // 发送订单同步失败事件(网络错误或请求失败)
4030
- _context39.next = 48;
4403
+ _context41.next = 48;
4031
4404
  return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
4032
4405
  orderUuid: this.store.currentOrder.uuid,
4033
4406
  operation: isUpdateOperation ? 'update' : 'create',
@@ -4038,32 +4411,32 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4038
4411
  timestamp: Date.now()
4039
4412
  });
4040
4413
  case 48:
4041
- throw _context39.t1;
4414
+ throw _context41.t1;
4042
4415
  case 49:
4043
- _context39.prev = 49;
4044
- _context39.next = 52;
4416
+ _context41.prev = 49;
4417
+ _context41.next = 52;
4045
4418
  return this.core.effects.emit("".concat(this.name, ":onOrderSubmitEnd"), {
4046
4419
  success: submitSuccess,
4047
4420
  orderUuid: this.store.currentOrder.uuid,
4048
4421
  operation: isUpdateOperation ? 'update' : 'create',
4049
4422
  isManual: isManual,
4050
- orderId: submitSuccess ? ((_checkoutResponse = checkoutResponse) === null || _checkoutResponse === void 0 || (_checkoutResponse = _checkoutResponse.data) === null || _checkoutResponse === void 0 ? void 0 : _checkoutResponse.order_id) || ((_checkoutResponse2 = checkoutResponse) === null || _checkoutResponse2 === void 0 ? void 0 : _checkoutResponse2.order_id) : undefined,
4423
+ orderId: submitSuccess ? ((_checkoutResponse8 = checkoutResponse) === null || _checkoutResponse8 === void 0 || (_checkoutResponse8 = _checkoutResponse8.data) === null || _checkoutResponse8 === void 0 ? void 0 : _checkoutResponse8.order_id) || ((_checkoutResponse9 = checkoutResponse) === null || _checkoutResponse9 === void 0 ? void 0 : _checkoutResponse9.order_id) : undefined,
4051
4424
  error: submitError,
4052
4425
  duration: Date.now() - startTime,
4053
4426
  timestamp: Date.now()
4054
4427
  });
4055
4428
  case 52:
4056
- return _context39.finish(49);
4429
+ return _context41.finish(49);
4057
4430
  case 53:
4058
4431
  // 检查响应状态是否为成功状态
4059
- responseStatus = (_checkoutResponse3 = checkoutResponse) === null || _checkoutResponse3 === void 0 ? void 0 : _checkoutResponse3.status;
4060
- isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse4 = checkoutResponse) === null || _checkoutResponse4 === void 0 ? void 0 : _checkoutResponse4.code) === 200;
4432
+ responseStatus = (_checkoutResponse10 = checkoutResponse) === null || _checkoutResponse10 === void 0 ? void 0 : _checkoutResponse10.status;
4433
+ isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === 'success' || responseStatus === 1 && ((_checkoutResponse11 = checkoutResponse) === null || _checkoutResponse11 === void 0 ? void 0 : _checkoutResponse11.code) === 200;
4061
4434
  if (isSuccessResponse) {
4062
- _context39.next = 60;
4435
+ _context41.next = 60;
4063
4436
  break;
4064
4437
  }
4065
- errorMessage = ((_checkoutResponse5 = checkoutResponse) === null || _checkoutResponse5 === void 0 ? void 0 : _checkoutResponse5.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
4066
- _context39.next = 59;
4438
+ errorMessage = ((_checkoutResponse12 = checkoutResponse) === null || _checkoutResponse12 === void 0 ? void 0 : _checkoutResponse12.message) || '订单同步失败,后端返回非成功状态'; // 发送订单同步失败事件
4439
+ _context41.next = 59;
4067
4440
  return this.core.effects.emit("".concat(this.name, ":onOrderSyncFailed"), {
4068
4441
  orderUuid: this.store.currentOrder.uuid,
4069
4442
  operation: isUpdateOperation ? 'update' : 'create',
@@ -4078,18 +4451,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4078
4451
  throw new Error(errorMessage);
4079
4452
  case 60:
4080
4453
  if (!isUpdateOperation) {
4081
- _context39.next = 64;
4454
+ _context41.next = 64;
4082
4455
  break;
4083
4456
  }
4084
4457
  // 更新操作:使用现有的订单ID
4085
4458
  realOrderId = currentOrderId;
4086
- _context39.next = 97;
4459
+ _context41.next = 97;
4087
4460
  break;
4088
4461
  case 64:
4089
4462
  // 创建操作:从响应中提取新的订单ID
4090
- extractedOrderId = (_checkoutResponse6 = checkoutResponse) === null || _checkoutResponse6 === void 0 || (_checkoutResponse6 = _checkoutResponse6.data) === null || _checkoutResponse6 === void 0 ? void 0 : _checkoutResponse6.order_id; // 如果data.order_id不存在,尝试直接从根级获取
4463
+ extractedOrderId = (_checkoutResponse13 = checkoutResponse) === null || _checkoutResponse13 === void 0 || (_checkoutResponse13 = _checkoutResponse13.data) === null || _checkoutResponse13 === void 0 ? void 0 : _checkoutResponse13.order_id; // 如果data.order_id不存在,尝试直接从根级获取
4091
4464
  if (!extractedOrderId) {
4092
- extractedOrderId = (_checkoutResponse7 = checkoutResponse) === null || _checkoutResponse7 === void 0 ? void 0 : _checkoutResponse7.order_id;
4465
+ extractedOrderId = (_checkoutResponse14 = checkoutResponse) === null || _checkoutResponse14 === void 0 ? void 0 : _checkoutResponse14.order_id;
4093
4466
  }
4094
4467
 
4095
4468
  // 确保转换为字符串类型
@@ -4107,20 +4480,20 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4107
4480
  oldOrderId: this.store.currentOrder.order_id,
4108
4481
  newOrderId: realOrderId
4109
4482
  });
4110
- _context39.prev = 70;
4483
+ _context41.prev = 70;
4111
4484
  latestPaymentStatus = this.store.currentOrder.payment_status;
4112
4485
  previousOrder = this.store.currentOrder;
4113
- _context39.next = 75;
4486
+ _context41.next = 75;
4114
4487
  return this.payment.replaceOrderIdByUuidAsync(previousOrder.uuid, realOrderId);
4115
4488
  case 75:
4116
- updatedOrder = _context39.sent;
4489
+ updatedOrder = _context41.sent;
4117
4490
  this.logInfo('Payment模块替换订单ID结果:', {
4118
4491
  wasSuccessful: !!updatedOrder,
4119
4492
  returnedOrderId: updatedOrder === null || updatedOrder === void 0 ? void 0 : updatedOrder.order_id,
4120
4493
  expectedOrderId: realOrderId
4121
4494
  });
4122
4495
  if (!updatedOrder) {
4123
- _context39.next = 86;
4496
+ _context41.next = 86;
4124
4497
  break;
4125
4498
  }
4126
4499
  this.logInfo('Payment模块返回的更新后订单:', {
@@ -4136,16 +4509,16 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4136
4509
 
4137
4510
  // 同步更新 Payment 模块 DB,避免后续读取 DB 时又拿回旧状态
4138
4511
  if (!latestPaymentStatus) {
4139
- _context39.next = 83;
4512
+ _context41.next = 83;
4140
4513
  break;
4141
4514
  }
4142
- _context39.next = 83;
4515
+ _context41.next = 83;
4143
4516
  return this.payment.updateOrderAsync(previousOrder.uuid, {
4144
4517
  payment_status: latestPaymentStatus
4145
4518
  });
4146
4519
  case 83:
4147
4520
  this.logInfo('[Checkout] 订单ID替换成功,当前订单ID:', this.store.currentOrder.order_id);
4148
- _context39.next = 90;
4521
+ _context41.next = 90;
4149
4522
  break;
4150
4523
  case 86:
4151
4524
  this.logError('[Checkout] Payment模块返回空订单,订单ID替换失败,开始手动替换');
@@ -4159,59 +4532,59 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4159
4532
  目标ID: realOrderId
4160
4533
  });
4161
4534
  case 90:
4162
- _context39.next = 97;
4535
+ _context41.next = 97;
4163
4536
  break;
4164
4537
  case 92:
4165
- _context39.prev = 92;
4166
- _context39.t2 = _context39["catch"](70);
4167
- this.logError('调用Payment模块替换订单ID时发生错误:', _context39.t2);
4538
+ _context41.prev = 92;
4539
+ _context41.t2 = _context41["catch"](70);
4540
+ this.logError('调用Payment模块替换订单ID时发生错误:', _context41.t2);
4168
4541
 
4169
4542
  // 发生错误时也进行手动替换
4170
4543
  this.store.currentOrder.order_id = realOrderId;
4171
4544
  this.logInfo('错误恢复:手动设置订单ID:', realOrderId);
4172
4545
  case 97:
4173
- _context39.prev = 97;
4546
+ _context41.prev = 97;
4174
4547
  syncedPaymentUuids = processedPaymentItems.filter(function (item) {
4175
4548
  return item.status !== 'voided';
4176
4549
  }).map(function (item) {
4177
4550
  return item.uuid;
4178
4551
  }).filter(Boolean);
4179
- _iterator3 = _createForOfIteratorHelper(syncedPaymentUuids);
4180
- _context39.prev = 100;
4181
- _iterator3.s();
4552
+ _iterator4 = _createForOfIteratorHelper(syncedPaymentUuids);
4553
+ _context41.prev = 100;
4554
+ _iterator4.s();
4182
4555
  case 102:
4183
- if ((_step3 = _iterator3.n()).done) {
4184
- _context39.next = 108;
4556
+ if ((_step4 = _iterator4.n()).done) {
4557
+ _context41.next = 108;
4185
4558
  break;
4186
4559
  }
4187
- paymentUuid = _step3.value;
4188
- _context39.next = 106;
4560
+ paymentUuid = _step4.value;
4561
+ _context41.next = 106;
4189
4562
  return this.payment.updatePaymentAsync(this.store.currentOrder.uuid, paymentUuid, {
4190
4563
  isSynced: true,
4191
4564
  syncError: undefined
4192
4565
  });
4193
4566
  case 106:
4194
- _context39.next = 102;
4567
+ _context41.next = 102;
4195
4568
  break;
4196
4569
  case 108:
4197
- _context39.next = 113;
4570
+ _context41.next = 113;
4198
4571
  break;
4199
4572
  case 110:
4200
- _context39.prev = 110;
4201
- _context39.t3 = _context39["catch"](100);
4202
- _iterator3.e(_context39.t3);
4573
+ _context41.prev = 110;
4574
+ _context41.t3 = _context41["catch"](100);
4575
+ _iterator4.e(_context41.t3);
4203
4576
  case 113:
4204
- _context39.prev = 113;
4205
- _iterator3.f();
4206
- return _context39.finish(113);
4577
+ _context41.prev = 113;
4578
+ _iterator4.f();
4579
+ return _context41.finish(113);
4207
4580
  case 116:
4208
- _context39.next = 121;
4581
+ _context41.next = 121;
4209
4582
  break;
4210
4583
  case 118:
4211
- _context39.prev = 118;
4212
- _context39.t4 = _context39["catch"](97);
4584
+ _context41.prev = 118;
4585
+ _context41.t4 = _context41["catch"](97);
4213
4586
  this.logWarning('标记支付项已同步失败(不阻塞主流程)', {
4214
- error: _context39.t4
4587
+ error: _context41.t4
4215
4588
  });
4216
4589
  case 121:
4217
4590
  // 标记订单已同步
@@ -4221,7 +4594,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4221
4594
  this.clearCalculationCache();
4222
4595
 
4223
4596
  // 触发订单同步完成事件
4224
- _context39.next = 125;
4597
+ _context41.next = 125;
4225
4598
  return this.core.effects.emit("".concat(this.name, ":onOrderSynced"), {
4226
4599
  orderUuid: this.store.currentOrder.uuid,
4227
4600
  realOrderId: realOrderId,
@@ -4231,7 +4604,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4231
4604
  response: checkoutResponse
4232
4605
  });
4233
4606
  case 125:
4234
- return _context39.abrupt("return", {
4607
+ return _context41.abrupt("return", {
4235
4608
  success: true,
4236
4609
  orderId: realOrderId,
4237
4610
  orderUuid: this.store.currentOrder.uuid,
@@ -4239,9 +4612,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4239
4612
  });
4240
4613
  case 126:
4241
4614
  case "end":
4242
- return _context39.stop();
4615
+ return _context41.stop();
4243
4616
  }
4244
- }, _callee39, this, [[31, 41, 49, 53], [70, 92], [97, 118], [100, 110, 113, 116]]);
4617
+ }, _callee41, this, [[31, 41, 49, 53], [70, 92], [97, 118], [100, 110, 113, 116]]);
4245
4618
  }));
4246
4619
  function syncOrderToBackendWithReturn() {
4247
4620
  return _syncOrderToBackendWithReturn.apply(this, arguments);
@@ -4251,15 +4624,15 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4251
4624
  }, {
4252
4625
  key: "setOtherParams",
4253
4626
  value: function () {
4254
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
4627
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
4255
4628
  var _ref5,
4256
4629
  _ref5$cover,
4257
4630
  cover,
4258
- _args40 = arguments;
4259
- return _regeneratorRuntime().wrap(function _callee40$(_context40) {
4260
- while (1) switch (_context40.prev = _context40.next) {
4631
+ _args42 = arguments;
4632
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4633
+ while (1) switch (_context42.prev = _context42.next) {
4261
4634
  case 0:
4262
- _ref5 = _args40.length > 1 && _args40[1] !== undefined ? _args40[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
4635
+ _ref5 = _args42.length > 1 && _args42[1] !== undefined ? _args42[1] : {}, _ref5$cover = _ref5.cover, cover = _ref5$cover === void 0 ? false : _ref5$cover;
4263
4636
  if (cover) {
4264
4637
  this.otherParams = params;
4265
4638
  } else {
@@ -4267,11 +4640,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4267
4640
  }
4268
4641
  case 2:
4269
4642
  case "end":
4270
- return _context40.stop();
4643
+ return _context42.stop();
4271
4644
  }
4272
- }, _callee40, this);
4645
+ }, _callee42, this);
4273
4646
  }));
4274
- function setOtherParams(_x29) {
4647
+ function setOtherParams(_x32) {
4275
4648
  return _setOtherParams.apply(this, arguments);
4276
4649
  }
4277
4650
  return setOtherParams;
@@ -4288,22 +4661,22 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4288
4661
  }, {
4289
4662
  key: "editOrderNoteByOrderIdAsync",
4290
4663
  value: (function () {
4291
- var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(orderId, note) {
4664
+ var _editOrderNoteByOrderIdAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(orderId, note) {
4292
4665
  var response, previousNote, errorMessage, _errorMessage;
4293
- return _regeneratorRuntime().wrap(function _callee41$(_context41) {
4294
- while (1) switch (_context41.prev = _context41.next) {
4666
+ return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4667
+ while (1) switch (_context43.prev = _context43.next) {
4295
4668
  case 0:
4296
4669
  this.logInfo('editOrderNoteByOrderIdAsync called', {
4297
4670
  orderId: orderId,
4298
4671
  note: note,
4299
4672
  noteLength: note.length
4300
4673
  });
4301
- _context41.prev = 1;
4674
+ _context43.prev = 1;
4302
4675
  if (orderId) {
4303
- _context41.next = 4;
4676
+ _context43.next = 4;
4304
4677
  break;
4305
4678
  }
4306
- return _context41.abrupt("return", {
4679
+ return _context43.abrupt("return", {
4307
4680
  success: false,
4308
4681
  message: '订单ID不能为空',
4309
4682
  orderId: orderId
@@ -4319,12 +4692,12 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4319
4692
  });
4320
4693
 
4321
4694
  // 调用后端API修改订单备注
4322
- _context41.next = 7;
4695
+ _context43.next = 7;
4323
4696
  return this.request.put("/order/order/".concat(orderId, "/note"), {
4324
4697
  note: note
4325
4698
  });
4326
4699
  case 7:
4327
- response = _context41.sent;
4700
+ response = _context43.sent;
4328
4701
  this.logInfo('订单备注编辑响应:', {
4329
4702
  orderId: orderId,
4330
4703
  status: response.status,
@@ -4334,11 +4707,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4334
4707
 
4335
4708
  // 检查响应状态
4336
4709
  if (!(response.status === true || response.status === 200)) {
4337
- _context41.next = 18;
4710
+ _context43.next = 18;
4338
4711
  break;
4339
4712
  }
4340
4713
  if (!(this.store.currentOrder && (String(this.store.currentOrder.order_id) === String(orderId) || String(this.store.currentOrder.id) === String(orderId)))) {
4341
- _context41.next = 15;
4714
+ _context43.next = 15;
4342
4715
  break;
4343
4716
  }
4344
4717
  // 获取修改前的备注用于事件
@@ -4348,7 +4721,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4348
4721
  }
4349
4722
 
4350
4723
  // 触发订单备注变更事件
4351
- _context41.next = 15;
4724
+ _context43.next = 15;
4352
4725
  return this.core.effects.emit("".concat(this.name, ":onOrderNoteChanged"), {
4353
4726
  orderUuid: this.store.currentOrder.uuid,
4354
4727
  oldNote: previousNote,
@@ -4356,7 +4729,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4356
4729
  timestamp: Date.now()
4357
4730
  });
4358
4731
  case 15:
4359
- return _context41.abrupt("return", {
4732
+ return _context43.abrupt("return", {
4360
4733
  success: true,
4361
4734
  message: response.message || '订单备注修改成功',
4362
4735
  orderId: orderId
@@ -4365,31 +4738,31 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4365
4738
  // API返回失败状态
4366
4739
  errorMessage = response.message || '订单备注修改失败';
4367
4740
  this.logError("\u8BA2\u5355 ".concat(orderId, " \u5907\u6CE8\u4FEE\u6539\u5931\u8D25:"), errorMessage);
4368
- return _context41.abrupt("return", {
4741
+ return _context43.abrupt("return", {
4369
4742
  success: false,
4370
4743
  message: errorMessage,
4371
4744
  orderId: orderId
4372
4745
  });
4373
4746
  case 21:
4374
- _context41.next = 28;
4747
+ _context43.next = 28;
4375
4748
  break;
4376
4749
  case 23:
4377
- _context41.prev = 23;
4378
- _context41.t0 = _context41["catch"](1);
4379
- this.logError('编辑订单备注失败:', _context41.t0);
4380
- _errorMessage = _context41.t0 instanceof Error ? _context41.t0.message : '网络错误或服务器异常';
4381
- return _context41.abrupt("return", {
4750
+ _context43.prev = 23;
4751
+ _context43.t0 = _context43["catch"](1);
4752
+ this.logError('编辑订单备注失败:', _context43.t0);
4753
+ _errorMessage = _context43.t0 instanceof Error ? _context43.t0.message : '网络错误或服务器异常';
4754
+ return _context43.abrupt("return", {
4382
4755
  success: false,
4383
4756
  message: "\u7F16\u8F91\u8BA2\u5355\u5907\u6CE8\u5931\u8D25: ".concat(_errorMessage),
4384
4757
  orderId: orderId
4385
4758
  });
4386
4759
  case 28:
4387
4760
  case "end":
4388
- return _context41.stop();
4761
+ return _context43.stop();
4389
4762
  }
4390
- }, _callee41, this, [[1, 23]]);
4763
+ }, _callee43, this, [[1, 23]]);
4391
4764
  }));
4392
- function editOrderNoteByOrderIdAsync(_x30, _x31) {
4765
+ function editOrderNoteByOrderIdAsync(_x33, _x34) {
4393
4766
  return _editOrderNoteByOrderIdAsync.apply(this, arguments);
4394
4767
  }
4395
4768
  return editOrderNoteByOrderIdAsync;
@@ -4406,11 +4779,11 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4406
4779
  }, {
4407
4780
  key: "sendCustomerPayLinkAsync",
4408
4781
  value: (function () {
4409
- var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
4782
+ var _sendCustomerPayLinkAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
4410
4783
  var _params$order_ids, _params$emails;
4411
4784
  var emailRegex, invalidEmails, requestBody, response, errorMessage, _errorMessage2;
4412
- return _regeneratorRuntime().wrap(function _callee42$(_context42) {
4413
- while (1) switch (_context42.prev = _context42.next) {
4785
+ return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4786
+ while (1) switch (_context44.prev = _context44.next) {
4414
4787
  case 0:
4415
4788
  this.logInfo('sendCustomerPayLinkAsync called', {
4416
4789
  orderIds: params.order_ids,
@@ -4419,21 +4792,21 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4419
4792
  emailsCount: ((_params$emails = params.emails) === null || _params$emails === void 0 ? void 0 : _params$emails.length) || 0,
4420
4793
  notifyAction: params.notify_action || 'order_payment_reminder'
4421
4794
  });
4422
- _context42.prev = 1;
4795
+ _context44.prev = 1;
4423
4796
  if (!(!params.order_ids || params.order_ids.length === 0)) {
4424
- _context42.next = 4;
4797
+ _context44.next = 4;
4425
4798
  break;
4426
4799
  }
4427
- return _context42.abrupt("return", {
4800
+ return _context44.abrupt("return", {
4428
4801
  success: false,
4429
4802
  message: '订单ID列表不能为空'
4430
4803
  });
4431
4804
  case 4:
4432
4805
  if (!(!params.emails || params.emails.length === 0)) {
4433
- _context42.next = 6;
4806
+ _context44.next = 6;
4434
4807
  break;
4435
4808
  }
4436
- return _context42.abrupt("return", {
4809
+ return _context44.abrupt("return", {
4437
4810
  success: false,
4438
4811
  message: '邮箱地址列表不能为空'
4439
4812
  });
@@ -4444,10 +4817,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4444
4817
  return !emailRegex.test(email);
4445
4818
  });
4446
4819
  if (!(invalidEmails.length > 0)) {
4447
- _context42.next = 10;
4820
+ _context44.next = 10;
4448
4821
  break;
4449
4822
  }
4450
- return _context42.abrupt("return", {
4823
+ return _context44.abrupt("return", {
4451
4824
  success: false,
4452
4825
  message: "\u90AE\u7BB1\u683C\u5F0F\u65E0\u6548: ".concat(invalidEmails.join(', '))
4453
4826
  });
@@ -4463,10 +4836,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4463
4836
  }, requestBody));
4464
4837
 
4465
4838
  // 调用后端API发送邮件
4466
- _context42.next = 14;
4839
+ _context44.next = 14;
4467
4840
  return this.request.post('/order/batch-email', requestBody);
4468
4841
  case 14:
4469
- response = _context42.sent;
4842
+ response = _context44.sent;
4470
4843
  this.logInfo('支付链接邮件发送响应:', {
4471
4844
  status: response.status,
4472
4845
  message: response.message,
@@ -4476,10 +4849,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4476
4849
 
4477
4850
  // 检查响应状态
4478
4851
  if (!(response.status === true || response.status === 200)) {
4479
- _context42.next = 20;
4852
+ _context44.next = 20;
4480
4853
  break;
4481
4854
  }
4482
- return _context42.abrupt("return", {
4855
+ return _context44.abrupt("return", {
4483
4856
  success: true,
4484
4857
  message: response.message || '支付链接邮件发送成功'
4485
4858
  });
@@ -4487,29 +4860,29 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4487
4860
  // API返回失败状态
4488
4861
  errorMessage = response.message || '支付链接邮件发送失败';
4489
4862
  console.error('[Checkout] 支付链接邮件发送失败:', errorMessage);
4490
- return _context42.abrupt("return", {
4863
+ return _context44.abrupt("return", {
4491
4864
  success: false,
4492
4865
  message: errorMessage
4493
4866
  });
4494
4867
  case 23:
4495
- _context42.next = 30;
4868
+ _context44.next = 30;
4496
4869
  break;
4497
4870
  case 25:
4498
- _context42.prev = 25;
4499
- _context42.t0 = _context42["catch"](1);
4500
- this.logError('发送客户支付链接邮件失败:', _context42.t0);
4501
- _errorMessage2 = _context42.t0 instanceof Error ? _context42.t0.message : '网络错误或服务器异常';
4502
- return _context42.abrupt("return", {
4871
+ _context44.prev = 25;
4872
+ _context44.t0 = _context44["catch"](1);
4873
+ this.logError('发送客户支付链接邮件失败:', _context44.t0);
4874
+ _errorMessage2 = _context44.t0 instanceof Error ? _context44.t0.message : '网络错误或服务器异常';
4875
+ return _context44.abrupt("return", {
4503
4876
  success: false,
4504
4877
  message: "\u53D1\u9001\u652F\u4ED8\u94FE\u63A5\u90AE\u4EF6\u5931\u8D25: ".concat(_errorMessage2)
4505
4878
  });
4506
4879
  case 30:
4507
4880
  case "end":
4508
- return _context42.stop();
4881
+ return _context44.stop();
4509
4882
  }
4510
- }, _callee42, this, [[1, 25]]);
4883
+ }, _callee44, this, [[1, 25]]);
4511
4884
  }));
4512
- function sendCustomerPayLinkAsync(_x32) {
4885
+ function sendCustomerPayLinkAsync(_x35) {
4513
4886
  return _sendCustomerPayLinkAsync.apply(this, arguments);
4514
4887
  }
4515
4888
  return sendCustomerPayLinkAsync;
@@ -4524,38 +4897,38 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4524
4897
  }, {
4525
4898
  key: "roundAmountAsync",
4526
4899
  value: (function () {
4527
- var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(amount) {
4900
+ var _roundAmountAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(amount) {
4528
4901
  var _cashManualPayment$me, _this$otherParams$ord, _this$otherParams$ord2;
4529
4902
  var cashManualPayment, result;
4530
- return _regeneratorRuntime().wrap(function _callee43$(_context43) {
4531
- while (1) switch (_context43.prev = _context43.next) {
4903
+ return _regeneratorRuntime().wrap(function _callee45$(_context45) {
4904
+ while (1) switch (_context45.prev = _context45.next) {
4532
4905
  case 0:
4533
4906
  // 检查 CASHMANUAL 的支付项是否开启了舍入,如果没开直接返回 amount
4534
4907
  cashManualPayment = this.store.paymentMethods.find(function (p) {
4535
4908
  return p.code === 'CASHMANUAL';
4536
4909
  });
4537
4910
  if (cashManualPayment !== null && cashManualPayment !== void 0 && (_cashManualPayment$me = cashManualPayment.metadata) !== null && _cashManualPayment$me !== void 0 && _cashManualPayment$me.order_rounding_switch) {
4538
- _context43.next = 3;
4911
+ _context45.next = 3;
4539
4912
  break;
4540
4913
  }
4541
- return _context43.abrupt("return", {
4914
+ return _context45.abrupt("return", {
4542
4915
  originalAmount: amount.toString(),
4543
4916
  roundedAmount: amount.toString(),
4544
4917
  roundingDifference: '0.00'
4545
4918
  });
4546
4919
  case 3:
4547
- _context43.next = 5;
4920
+ _context45.next = 5;
4548
4921
  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);
4549
4922
  case 5:
4550
- result = _context43.sent;
4551
- return _context43.abrupt("return", result);
4923
+ result = _context45.sent;
4924
+ return _context45.abrupt("return", result);
4552
4925
  case 7:
4553
4926
  case "end":
4554
- return _context43.stop();
4927
+ return _context45.stop();
4555
4928
  }
4556
- }, _callee43, this);
4929
+ }, _callee45, this);
4557
4930
  }));
4558
- function roundAmountAsync(_x33) {
4931
+ function roundAmountAsync(_x36) {
4559
4932
  return _roundAmountAsync.apply(this, arguments);
4560
4933
  }
4561
4934
  return roundAmountAsync;
@@ -4563,10 +4936,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4563
4936
  }, {
4564
4937
  key: "destroy",
4565
4938
  value: function () {
4566
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44() {
4939
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46() {
4567
4940
  var _this$order, _this$order$destroy, _this$payment, _this$payment$destroy;
4568
- return _regeneratorRuntime().wrap(function _callee44$(_context44) {
4569
- while (1) switch (_context44.prev = _context44.next) {
4941
+ return _regeneratorRuntime().wrap(function _callee46$(_context46) {
4942
+ while (1) switch (_context46.prev = _context46.next) {
4570
4943
  case 0:
4571
4944
  // 清理钱包模块的所有缓存数据
4572
4945
  this.payment.wallet.clearAllCache();
@@ -4575,10 +4948,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4575
4948
  this.core.effects.offByModuleDestroy(this.name);
4576
4949
 
4577
4950
  // 销毁子模块
4578
- _context44.next = 4;
4951
+ _context46.next = 4;
4579
4952
  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);
4580
4953
  case 4:
4581
- _context44.next = 6;
4954
+ _context46.next = 6;
4582
4955
  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);
4583
4956
  case 6:
4584
4957
  // 取消注册模块
@@ -4586,9 +4959,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4586
4959
  console.log('[Checkout] 已销毁');
4587
4960
  case 8:
4588
4961
  case "end":
4589
- return _context44.stop();
4962
+ return _context46.stop();
4590
4963
  }
4591
- }, _callee44, this);
4964
+ }, _callee46, this);
4592
4965
  }));
4593
4966
  function destroy() {
4594
4967
  return _destroy.apply(this, arguments);
@@ -4605,7 +4978,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4605
4978
  }, {
4606
4979
  key: "resetStoreState",
4607
4980
  value: function resetStoreState() {
4608
- var _this7 = this;
4981
+ var _this8 = this;
4609
4982
  try {
4610
4983
  var prevOrderInfo = this.store.currentOrder ? {
4611
4984
  uuid: this.store.currentOrder.uuid,
@@ -4640,7 +5013,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
4640
5013
  // 使用 setTimeout 确保事件处理不会阻塞状态重置
4641
5014
  if (prevOrderInfo) {
4642
5015
  setTimeout(function () {
4643
- _this7.core.effects.emit("".concat(_this7.name, ":onOrderCleared"), {
5016
+ _this8.core.effects.emit("".concat(_this8.name, ":onOrderCleared"), {
4644
5017
  previousOrder: prevOrderInfo,
4645
5018
  timestamp: Date.now()
4646
5019
  });