@pisell/pisellos 2.2.29 → 2.2.31

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.
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -21,7 +21,7 @@ export declare const calculateSubtotal: (items: CartItem[]) => string;
21
21
  * @return {*}
22
22
  * @Author: xiangfeng.xue
23
23
  */
24
- export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
24
+ export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00" | Decimal;
25
25
  /**
26
26
  * @title: 计算定金
27
27
  * @param items - 购物车商品数组
@@ -1745,32 +1745,53 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1745
1745
  value: (function () {
1746
1746
  var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(voucherPaymentItems) {
1747
1747
  var _this4 = this;
1748
- var paymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1748
+ var paymentItems, savedVoucherPaymentItems, allPaymentItemsSynced, remainingAmount, remainingValue, isOrderSynced, orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder;
1749
1749
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1750
1750
  while (1) switch (_context18.prev = _context18.next) {
1751
1751
  case 0:
1752
1752
  _context18.prev = 0;
1753
+ this.logInfo('updateVoucherPaymentItemsAsync called:', {
1754
+ voucherPaymentItems: voucherPaymentItems
1755
+ });
1756
+ // 检查是否有当前订单
1753
1757
  if (this.store.currentOrder) {
1754
- _context18.next = 3;
1758
+ _context18.next = 4;
1755
1759
  break;
1756
1760
  }
1757
1761
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '当前没有活跃订单,无法更新代金券支付项');
1758
- case 3:
1759
- _context18.next = 5;
1762
+ case 4:
1763
+ _context18.next = 6;
1760
1764
  return this.payment.getPaymentItemsAsync(this.store.currentOrder.uuid);
1761
- case 5:
1765
+ case 6:
1762
1766
  paymentItems = _context18.sent;
1767
+ if (!(!voucherPaymentItems || (voucherPaymentItems === null || voucherPaymentItems === void 0 ? void 0 : voucherPaymentItems.length) === 0)) {
1768
+ _context18.next = 12;
1769
+ break;
1770
+ }
1771
+ savedVoucherPaymentItems = (paymentItems === null || paymentItems === void 0 ? void 0 : paymentItems.filter(function (item) {
1772
+ return item.voucher_id && !item.isSynced;
1773
+ })) || [];
1774
+ this.logInfo('未传入 voucher 且本地订单无 voucher 记录,阻断updateVoucherPaymentItemsAsync', {
1775
+ voucherPaymentItems: voucherPaymentItems,
1776
+ savedVoucherPaymentItems: savedVoucherPaymentItems
1777
+ });
1778
+ if (!((savedVoucherPaymentItems === null || savedVoucherPaymentItems === void 0 ? void 0 : savedVoucherPaymentItems.length) === 0)) {
1779
+ _context18.next = 12;
1780
+ break;
1781
+ }
1782
+ return _context18.abrupt("return");
1783
+ case 12:
1763
1784
  allPaymentItemsSynced = paymentItems.every(function (item) {
1764
1785
  return item.isSynced;
1765
1786
  });
1766
- _context18.next = 9;
1787
+ _context18.next = 15;
1767
1788
  return this.calculateRemainingAmountAsync();
1768
- case 9:
1789
+ case 15:
1769
1790
  remainingAmount = _context18.sent;
1770
1791
  remainingValue = new Decimal(remainingAmount);
1771
1792
  isOrderSynced = this.store.isOrderSynced;
1772
1793
  if (!(remainingValue.lte(0) && isOrderSynced && voucherPaymentItems.length === 0 && allPaymentItemsSynced)) {
1773
- _context18.next = 15;
1794
+ _context18.next = 21;
1774
1795
  break;
1775
1796
  }
1776
1797
  this.logInfo('订单已同步且支付完成,跳过清空代金券操作避免重复同步:', {
@@ -1782,7 +1803,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1782
1803
  reason: 'Order synced and payment completed, skip clear vouchers to avoid duplicate sync'
1783
1804
  });
1784
1805
  return _context18.abrupt("return");
1785
- case 15:
1806
+ case 21:
1786
1807
  this.logInfo('开始批量更新代金券支付项:', {
1787
1808
  voucherPaymentItems: voucherPaymentItems
1788
1809
  });
@@ -1804,18 +1825,18 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1804
1825
  metadata: metadata
1805
1826
  });
1806
1827
  }); // 调用 Payment 模块的批量更新方法
1807
- _context18.next = 20;
1828
+ _context18.next = 26;
1808
1829
  return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1809
- case 20:
1830
+ case 26:
1810
1831
  // 🚀 清除计算缓存,确保获取最新数据
1811
1832
  this.clearCalculationCache();
1812
1833
 
1813
1834
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1814
1835
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1815
1836
  isCurrentOrderReal = currentOrderId && !isVirtualOrderId(currentOrderId);
1816
- _context18.next = 25;
1837
+ _context18.next = 31;
1817
1838
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1818
- case 25:
1839
+ case 31:
1819
1840
  updatedOrder = _context18.sent;
1820
1841
  if (updatedOrder) {
1821
1842
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1830,10 +1851,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1830
1851
  }
1831
1852
 
1832
1853
  // 更新 stateAmount 为剩余未支付金额
1833
- _context18.next = 29;
1854
+ _context18.next = 35;
1834
1855
  return this.updateStateAmountToRemaining(false);
1835
- case 29:
1836
- _context18.next = 31;
1856
+ case 35:
1857
+ _context18.next = 37;
1837
1858
  return this.core.effects.emit("".concat(this.name, ":onPaymentStarted"), {
1838
1859
  orderUuid: this.store.currentOrder.uuid,
1839
1860
  paymentMethodCode: 'VOUCHER_BATCH',
@@ -1842,23 +1863,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1842
1863
  }, 0).toFixed(2),
1843
1864
  timestamp: Date.now()
1844
1865
  });
1845
- case 31:
1866
+ case 37:
1846
1867
  this.logInfo('代金券支付项批量更新成功');
1847
- _context18.next = 40;
1868
+ _context18.next = 46;
1848
1869
  break;
1849
- case 34:
1850
- _context18.prev = 34;
1870
+ case 40:
1871
+ _context18.prev = 40;
1851
1872
  _context18.t0 = _context18["catch"](0);
1852
1873
  this.logError('[Checkout] 批量更新代金券支付项失败:', _context18.t0);
1853
- _context18.next = 39;
1874
+ _context18.next = 45;
1854
1875
  return this.handleError(_context18.t0, CheckoutErrorType.PaymentFailed);
1855
- case 39:
1876
+ case 45:
1856
1877
  throw _context18.t0;
1857
- case 40:
1878
+ case 46:
1858
1879
  case "end":
1859
1880
  return _context18.stop();
1860
1881
  }
1861
- }, _callee18, this, [[0, 34]]);
1882
+ }, _callee18, this, [[0, 40]]);
1862
1883
  }));
1863
1884
  function updateVoucherPaymentItemsAsync(_x17) {
1864
1885
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -21,7 +21,7 @@ export declare const calculateSubtotal: (items: CartItem[]) => string;
21
21
  * @return {*}
22
22
  * @Author: xiangfeng.xue
23
23
  */
24
- export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => Decimal | "0.00";
24
+ export declare const calculateTaxFee: (shopInfo: any, items: CartItem[]) => "0.00" | Decimal;
25
25
  /**
26
26
  * @title: 计算定金
27
27
  * @param items - 购物车商品数组
@@ -1172,6 +1172,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1172
1172
  */
1173
1173
  async updateVoucherPaymentItemsAsync(voucherPaymentItems) {
1174
1174
  try {
1175
+ this.logInfo("updateVoucherPaymentItemsAsync called:", {
1176
+ voucherPaymentItems
1177
+ });
1175
1178
  if (!this.store.currentOrder) {
1176
1179
  throw (0, import_utils.createCheckoutError)(
1177
1180
  import_types.CheckoutErrorType.ValidationFailed,
@@ -1181,6 +1184,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1181
1184
  const paymentItems = await this.payment.getPaymentItemsAsync(
1182
1185
  this.store.currentOrder.uuid
1183
1186
  );
1187
+ if (!voucherPaymentItems || (voucherPaymentItems == null ? void 0 : voucherPaymentItems.length) === 0) {
1188
+ const savedVoucherPaymentItems = (paymentItems == null ? void 0 : paymentItems.filter((item) => item.voucher_id && !item.isSynced)) || [];
1189
+ this.logInfo("未传入 voucher 且本地订单无 voucher 记录,阻断updateVoucherPaymentItemsAsync", {
1190
+ voucherPaymentItems,
1191
+ savedVoucherPaymentItems
1192
+ });
1193
+ if ((savedVoucherPaymentItems == null ? void 0 : savedVoucherPaymentItems.length) === 0)
1194
+ return;
1195
+ }
1184
1196
  const allPaymentItemsSynced = paymentItems.every((item) => item.isSynced);
1185
1197
  const remainingAmount = await this.calculateRemainingAmountAsync();
1186
1198
  const remainingValue = new import_decimal.default(remainingAmount);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.29",
4
+ "version": "2.2.31",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",