@pisell/pisellos 0.0.246 → 0.0.248

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.
@@ -1037,7 +1037,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1037
1037
  this.logInfo('Starting addPaymentItemAsync', {
1038
1038
  orderUuid: orderUuid,
1039
1039
  paymentAmount: paymentItem.amount,
1040
- paymentCode: paymentItem.code
1040
+ paymentCode: paymentItem.code,
1041
+ orderPaymentType: paymentItem.order_payment_type
1041
1042
  });
1042
1043
  _context13.prev = 1;
1043
1044
  _context13.next = 4;
@@ -1063,6 +1064,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1063
1064
  service_charge: paymentItem.service_charge,
1064
1065
  status: 'active',
1065
1066
  // 新支付项默认为活跃状态
1067
+ order_payment_type: paymentItem.order_payment_type || 'normal',
1068
+ // 默认为正常支付
1066
1069
  metadata: {
1067
1070
  unique_payment_number: paymentUuid // 设置唯一支付号为支付项的 uuid
1068
1071
  }
@@ -1230,7 +1233,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1230
1233
  return {
1231
1234
  code: item.code,
1232
1235
  amount: item.amount,
1233
- voucher_id: item.voucher_id
1236
+ voucher_id: item.voucher_id,
1237
+ order_payment_type: item.order_payment_type
1234
1238
  };
1235
1239
  })
1236
1240
  });
@@ -1313,7 +1317,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1313
1317
  console.log("[PaymentModule] \u6DFB\u52A0\u4EE3\u91D1\u5238\u652F\u4ED8\u9879:", {
1314
1318
  code: _voucherItem.code,
1315
1319
  amount: _voucherItem.amount,
1316
- voucher_id: _voucherItem.voucher_id
1320
+ voucher_id: _voucherItem.voucher_id,
1321
+ order_payment_type: _voucherItem.order_payment_type
1317
1322
  });
1318
1323
  _context15.next = 38;
1319
1324
  return this.addPaymentItemAsync(orderUuid, _voucherItem);
@@ -1745,9 +1750,16 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1745
1750
  if (payment.status === 'voided') {
1746
1751
  return sum;
1747
1752
  }
1748
- return sum.plus(payment.amount);
1753
+
1754
+ // 计算有效支付金额:支付金额 + 抹零金额的绝对值
1755
+ // 当 rounding_amount 为负数时,表示抹掉的金额,按绝对值计算有效支付
1756
+ // 例如:amount=15, rounding_amount=-0.2,有效支付=15.2(抹掉0.2元零头)
1757
+ var paymentAmount = new Decimal(payment.amount || 0);
1758
+ var roundingAmount = new Decimal(payment.rounding_amount || 0);
1759
+ var effectiveAmount = paymentAmount.plus(roundingAmount.abs());
1760
+ return sum.plus(effectiveAmount);
1749
1761
  } catch (error) {
1750
- console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: ".concat(payment.amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
1762
+ console.warn("[PaymentModule] \u65E0\u6548\u7684\u652F\u4ED8\u91D1\u989D: amount=".concat(payment.amount, ", rounding_amount=").concat(payment.rounding_amount, "\uFF0C\u8DF3\u8FC7\u8BA1\u7B97"));
1751
1763
  return sum;
1752
1764
  }
1753
1765
  }, new Decimal(0));
@@ -1756,14 +1768,25 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
1756
1768
  console.log("[PaymentModule] \u91CD\u65B0\u8BA1\u7B97\u8BA2\u5355\u91D1\u989D:", {
1757
1769
  orderUuid: order.uuid,
1758
1770
  totalAmount: order.total_amount,
1759
- paidAmount: paidAmount.toFixed(2),
1771
+ effectivePaidAmount: paidAmount.toFixed(2),
1760
1772
  remainingAmount: order.expect_amount,
1761
1773
  activePayments: order.payment.filter(function (p) {
1762
1774
  return p.status !== 'voided';
1763
1775
  }).length,
1764
1776
  voidedPayments: order.payment.filter(function (p) {
1765
1777
  return p.status === 'voided';
1766
- }).length
1778
+ }).length,
1779
+ paymentDetails: order.payment.filter(function (p) {
1780
+ return p.status !== 'voided';
1781
+ }).map(function (p) {
1782
+ return {
1783
+ code: p.code,
1784
+ amount: p.amount,
1785
+ rounding_amount: p.rounding_amount || '0.00',
1786
+ effective_amount: new Decimal(p.amount || 0).plus(new Decimal(p.rounding_amount || 0).abs()).toFixed(2)
1787
+ };
1788
+ }),
1789
+ 说明: '有效支付金额包含抹零计算(amount + |rounding_amount|)'
1767
1790
  });
1768
1791
  }
1769
1792
 
@@ -123,6 +123,8 @@ export interface PaymentItem {
123
123
  status?: 'active' | 'voided';
124
124
  /** 原始金额(用于记录撤销前的金额) */
125
125
  origin_amount?: string;
126
+ /** 订单支付类型 */
127
+ order_payment_type?: 'normal' | 'deposit';
126
128
  }
127
129
  /**
128
130
  * 订单信息
@@ -218,6 +220,17 @@ export interface PaymentItemInput {
218
220
  };
219
221
  /** 舍入金额 */
220
222
  rounding_amount?: string;
223
+ /** 订单支付类型 */
224
+ order_payment_type?: 'normal' | 'deposit';
225
+ /** 扩展参数字段 */
226
+ metadata?: {
227
+ /** 钱箱 ID */
228
+ shop_wallet_pass_id?: string;
229
+ /** 唯一支付号 */
230
+ unique_payment_number?: string;
231
+ /** rounding规则 */
232
+ rounding_rule?: any;
233
+ };
221
234
  }
222
235
  /**
223
236
  * 推送支付项参数
@@ -314,7 +314,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
314
314
  }[];
315
315
  setOtherData(key: string, value: any): void;
316
316
  getOtherData(key: string): any;
317
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
317
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
318
318
  /**
319
319
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
320
320
  *
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
111
111
  * 获取当前的客户搜索条件
112
112
  * @returns 当前搜索条件
113
113
  */
114
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
114
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
115
115
  /**
116
116
  * 获取客户列表状态(包含滚动加载相关状态)
117
117
  * @returns 客户状态
@@ -1,4 +1,3 @@
1
- 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; } } }; }
2
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); }
3
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
3
  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."); }
@@ -1661,7 +1660,7 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1661
1660
  key: "addPaymentItemAsync",
1662
1661
  value: (function () {
1663
1662
  var _addPaymentItemAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(paymentItem) {
1664
- var _paymentItem$type, _paymentItem$code, isEftposPayment;
1663
+ var _paymentItem$type, _paymentItem$code, orderPaymentType, metadata, paymentItemWithType, isEftposPayment;
1665
1664
  return _regeneratorRuntime().wrap(function _callee25$(_context25) {
1666
1665
  while (1) switch (_context25.prev = _context25.next) {
1667
1666
  case 0:
@@ -1672,23 +1671,37 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1672
1671
  }
1673
1672
  throw createCheckoutError(CheckoutErrorType.ValidationFailed, '未找到当前订单,无法添加支付项');
1674
1673
  case 3:
1674
+ // 根据当前订单的定金状态设置订单支付类型
1675
+ orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 从 otherParams 获取 metadata 字段
1676
+ metadata = _objectSpread(_objectSpread({}, paymentItem.metadata), {}, {
1677
+ rounding_rule: this.otherParams.order_rounding_setting,
1678
+ shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
1679
+ }); // 设置支付项的订单支付类型和 metadata
1680
+ paymentItemWithType = _objectSpread(_objectSpread({}, paymentItem), {}, {
1681
+ order_payment_type: orderPaymentType,
1682
+ metadata: metadata
1683
+ });
1675
1684
  console.log('[Checkout] 为当前订单添加支付项:', {
1676
1685
  orderUuid: this.store.currentOrder.uuid,
1677
1686
  paymentItem: {
1678
- code: paymentItem.code,
1679
- name: paymentItem.name,
1680
- type: paymentItem.type,
1681
- amount: paymentItem.amount,
1682
- service_charge: paymentItem.service_charge,
1683
- rounding_amount: paymentItem.rounding_amount,
1684
- voucher_id: paymentItem.voucher_id
1685
- }
1687
+ code: paymentItemWithType.code,
1688
+ name: paymentItemWithType.name,
1689
+ type: paymentItemWithType.type,
1690
+ amount: paymentItemWithType.amount,
1691
+ service_charge: paymentItemWithType.service_charge,
1692
+ rounding_amount: paymentItemWithType.rounding_amount,
1693
+ voucher_id: paymentItemWithType.voucher_id,
1694
+ order_payment_type: paymentItemWithType.order_payment_type,
1695
+ metadata: paymentItemWithType.metadata
1696
+ },
1697
+ orderDepositStatus: this.store.currentOrder.is_deposit,
1698
+ calculatedOrderPaymentType: orderPaymentType
1686
1699
  });
1687
1700
 
1688
1701
  // 添加支付项到订单
1689
- _context25.next = 6;
1690
- return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItem);
1691
- case 6:
1702
+ _context25.next = 9;
1703
+ return this.payment.addPaymentItemAsync(this.store.currentOrder.uuid, paymentItemWithType);
1704
+ case 9:
1692
1705
  console.log('[Checkout] 支付项添加成功');
1693
1706
 
1694
1707
  // 检查是否是 EFTPOS 支付,如果是则立即同步订单
@@ -1700,54 +1713,54 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1700
1713
  currentOrderSynced: this.store.isOrderSynced
1701
1714
  });
1702
1715
  if (!isEftposPayment) {
1703
- _context25.next = 22;
1716
+ _context25.next = 25;
1704
1717
  break;
1705
1718
  }
1706
1719
  console.log('[Checkout] 检测到 EFTPOS 支付,立即同步订单到后端...');
1707
- _context25.prev = 11;
1708
- _context25.next = 14;
1720
+ _context25.prev = 14;
1721
+ _context25.next = 17;
1709
1722
  return this.syncOrderToBackendWithReturn(true);
1710
- case 14:
1723
+ case 17:
1711
1724
  console.log('[Checkout] EFTPOS 支付后订单同步完成 (已标记为手动同步):', {
1712
1725
  订单ID: this.store.currentOrder.order_id,
1713
1726
  是否已同步: this.store.isOrderSynced
1714
1727
  });
1715
- _context25.next = 22;
1728
+ _context25.next = 25;
1716
1729
  break;
1717
- case 17:
1718
- _context25.prev = 17;
1719
- _context25.t0 = _context25["catch"](11);
1730
+ case 20:
1731
+ _context25.prev = 20;
1732
+ _context25.t0 = _context25["catch"](14);
1720
1733
  console.error('[Checkout] EFTPOS 支付后订单同步失败:', _context25.t0);
1721
1734
  // 不抛出错误,避免影响支付流程,但记录错误
1722
- _context25.next = 22;
1735
+ _context25.next = 25;
1723
1736
  return this.handleError(new Error("EFTPOS \u652F\u4ED8\u540E\u8BA2\u5355\u540C\u6B65\u5931\u8D25: ".concat(_context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0))), CheckoutErrorType.OrderCreationFailed);
1724
- case 22:
1725
- _context25.next = 24;
1737
+ case 25:
1738
+ _context25.next = 27;
1726
1739
  return this.updateStateAmountToRemaining();
1727
- case 24:
1728
- _context25.next = 26;
1740
+ case 27:
1741
+ _context25.next = 29;
1729
1742
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1730
1743
  orderUuid: this.store.currentOrder.uuid,
1731
1744
  paymentMethodCode: paymentItem.code,
1732
1745
  amount: String(paymentItem.amount),
1733
1746
  timestamp: Date.now()
1734
1747
  });
1735
- case 26:
1736
- _context25.next = 34;
1748
+ case 29:
1749
+ _context25.next = 37;
1737
1750
  break;
1738
- case 28:
1739
- _context25.prev = 28;
1751
+ case 31:
1752
+ _context25.prev = 31;
1740
1753
  _context25.t1 = _context25["catch"](0);
1741
1754
  console.error('[Checkout] 添加支付项失败:', _context25.t1);
1742
- _context25.next = 33;
1755
+ _context25.next = 36;
1743
1756
  return this.handleError(_context25.t1, CheckoutErrorType.PaymentFailed);
1744
- case 33:
1757
+ case 36:
1745
1758
  throw _context25.t1;
1746
- case 34:
1759
+ case 37:
1747
1760
  case "end":
1748
1761
  return _context25.stop();
1749
1762
  }
1750
- }, _callee25, this, [[0, 28], [11, 17]]);
1763
+ }, _callee25, this, [[0, 31], [14, 20]]);
1751
1764
  }));
1752
1765
  function addPaymentItemAsync(_x16) {
1753
1766
  return _addPaymentItemAsync.apply(this, arguments);
@@ -1882,7 +1895,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1882
1895
  key: "updateVoucherPaymentItemsAsync",
1883
1896
  value: (function () {
1884
1897
  var _updateVoucherPaymentItemsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(voucherPaymentItems) {
1885
- var _iterator, _step, item, currentOrderId, isCurrentOrderReal, updatedOrder, voucherItems;
1898
+ var _this3 = this;
1899
+ var orderPaymentType, voucherPaymentItemsWithType, currentOrderId, isCurrentOrderReal, updatedOrder, voucherItems;
1886
1900
  return _regeneratorRuntime().wrap(function _callee27$(_context27) {
1887
1901
  while (1) switch (_context27.prev = _context27.next) {
1888
1902
  case 0:
@@ -1899,47 +1913,41 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1899
1913
  voucherPaymentItems: voucherPaymentItems
1900
1914
  });
1901
1915
 
1902
- // 验证所有支付项都包含 voucher_id
1903
- _iterator = _createForOfIteratorHelper(voucherPaymentItems);
1904
- _context27.prev = 5;
1905
- _iterator.s();
1906
- case 7:
1907
- if ((_step = _iterator.n()).done) {
1908
- _context27.next = 13;
1909
- break;
1910
- }
1911
- item = _step.value;
1912
- if (item.voucher_id) {
1913
- _context27.next = 11;
1914
- break;
1915
- }
1916
- throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
1917
- case 11:
1918
- _context27.next = 7;
1919
- break;
1920
- case 13:
1921
- _context27.next = 18;
1922
- break;
1923
- case 15:
1924
- _context27.prev = 15;
1925
- _context27.t0 = _context27["catch"](5);
1926
- _iterator.e(_context27.t0);
1927
- case 18:
1928
- _context27.prev = 18;
1929
- _iterator.f();
1930
- return _context27.finish(18);
1931
- case 21:
1932
- _context27.next = 23;
1933
- return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItems);
1934
- case 23:
1916
+ // 根据当前订单的定金状态设置订单支付类型
1917
+ orderPaymentType = this.store.currentOrder.is_deposit === 1 ? 'deposit' : 'normal'; // 验证所有支付项都包含 voucher_id,并设置 order_payment_type 和 metadata
1918
+ voucherPaymentItemsWithType = voucherPaymentItems.map(function (item) {
1919
+ if (!item.voucher_id) {
1920
+ throw createCheckoutError(CheckoutErrorType.ValidationFailed, "\u4EE3\u91D1\u5238\u652F\u4ED8\u9879\u7F3A\u5C11 voucher_id: ".concat(JSON.stringify(item)));
1921
+ }
1922
+
1923
+ // 从 otherParams 获取 metadata 字段
1924
+ var metadata = _objectSpread(_objectSpread({}, item.metadata), {}, {
1925
+ rounding_rule: _this3.otherParams.order_rounding_setting,
1926
+ shop_wallet_pass_id: _this3.otherParams.shop_wallet_pass_id
1927
+ });
1928
+ return _objectSpread(_objectSpread({}, item), {}, {
1929
+ order_payment_type: orderPaymentType,
1930
+ metadata: metadata
1931
+ });
1932
+ });
1933
+ console.log('[Checkout] 代金券支付项订单支付类型设置:', {
1934
+ orderDepositStatus: this.store.currentOrder.is_deposit,
1935
+ calculatedOrderPaymentType: orderPaymentType,
1936
+ itemsCount: voucherPaymentItemsWithType.length
1937
+ });
1938
+
1939
+ // 调用 Payment 模块的批量更新方法
1940
+ _context27.next = 9;
1941
+ return this.payment.updateVoucherPaymentItemsAsync(this.store.currentOrder.uuid, voucherPaymentItemsWithType);
1942
+ case 9:
1935
1943
  console.log('[Checkout] Payment模块批量更新完成');
1936
1944
 
1937
1945
  // 重新从Payment模块获取最新的订单数据,确保支付项同步
1938
1946
  currentOrderId = this.store.currentOrder.order_id; // 保存当前的订单ID
1939
1947
  isCurrentOrderReal = currentOrderId && !this.isVirtualOrderId(currentOrderId);
1940
- _context27.next = 28;
1948
+ _context27.next = 14;
1941
1949
  return this.payment.getPaymentOrderByUuidAsync(this.store.currentOrder.uuid);
1942
- case 28:
1950
+ case 14:
1943
1951
  updatedOrder = _context27.sent;
1944
1952
  if (updatedOrder) {
1945
1953
  // 如果当前订单ID是真实ID,但获取到的订单ID是虚拟ID,需要保护真实ID
@@ -1971,10 +1979,10 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1971
1979
  }
1972
1980
 
1973
1981
  // 更新 stateAmount 为剩余未支付金额
1974
- _context27.next = 32;
1982
+ _context27.next = 18;
1975
1983
  return this.updateStateAmountToRemaining();
1976
- case 32:
1977
- _context27.next = 34;
1984
+ case 18:
1985
+ _context27.next = 20;
1978
1986
  return this.core.effects.emit(CheckoutHooks.OnPaymentStarted, {
1979
1987
  orderUuid: this.store.currentOrder.uuid,
1980
1988
  paymentMethodCode: 'VOUCHER_BATCH',
@@ -1983,23 +1991,23 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
1983
1991
  }, 0).toFixed(2),
1984
1992
  timestamp: Date.now()
1985
1993
  });
1986
- case 34:
1994
+ case 20:
1987
1995
  console.log('[Checkout] 代金券支付项批量更新成功');
1988
- _context27.next = 43;
1996
+ _context27.next = 29;
1989
1997
  break;
1990
- case 37:
1991
- _context27.prev = 37;
1992
- _context27.t1 = _context27["catch"](0);
1993
- console.error('[Checkout] 批量更新代金券支付项失败:', _context27.t1);
1994
- _context27.next = 42;
1995
- return this.handleError(_context27.t1, CheckoutErrorType.PaymentFailed);
1996
- case 42:
1997
- throw _context27.t1;
1998
- case 43:
1998
+ case 23:
1999
+ _context27.prev = 23;
2000
+ _context27.t0 = _context27["catch"](0);
2001
+ console.error('[Checkout] 批量更新代金券支付项失败:', _context27.t0);
2002
+ _context27.next = 28;
2003
+ return this.handleError(_context27.t0, CheckoutErrorType.PaymentFailed);
2004
+ case 28:
2005
+ throw _context27.t0;
2006
+ case 29:
1999
2007
  case "end":
2000
2008
  return _context27.stop();
2001
2009
  }
2002
- }, _callee27, this, [[0, 37], [5, 15, 18, 21]]);
2010
+ }, _callee27, this, [[0, 23]]);
2003
2011
  }));
2004
2012
  function updateVoucherPaymentItemsAsync(_x18) {
2005
2013
  return _updateVoucherPaymentItemsAsync.apply(this, arguments);
@@ -3246,7 +3254,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3246
3254
  uuid: p.uuid,
3247
3255
  amount: p.amount,
3248
3256
  code: p.code,
3249
- status: p.status
3257
+ status: p.status,
3258
+ rounding_amount: p.rounding_amount
3250
3259
  };
3251
3260
  })
3252
3261
  });
@@ -3255,8 +3264,19 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3255
3264
  }) // 只计算未撤销的支付项
3256
3265
  .reduce(function (sum, payment) {
3257
3266
  var amount = parseFloat(payment.amount || '0');
3258
- console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code, " = ").concat(amount));
3259
- return sum + amount;
3267
+ var roundingAmount = parseFloat(payment.rounding_amount || '0');
3268
+
3269
+ // 计算实际支付有效金额:
3270
+ // 当 rounding_amount 为负数时,表示抹掉的金额,应该按绝对值加到实际支付中
3271
+ // 例如:amount=15, rounding_amount=-0.2,实际相当于支付了15.2(抹掉了0.2元的零头)
3272
+ var effectiveAmount = amount + Math.abs(roundingAmount);
3273
+ console.log("[Checkout] \u8BA1\u7B97\u652F\u4ED8\u9879: ".concat(payment.code), {
3274
+ 原始金额: amount,
3275
+ 抹零金额: roundingAmount,
3276
+ 有效金额: effectiveAmount,
3277
+ 说明: roundingAmount !== 0 ? "\u62B9\u96F6\u91D1\u989D ".concat(roundingAmount, " \u5143\uFF0C\u6709\u6548\u652F\u4ED8\u589E\u52A0 ").concat(Math.abs(roundingAmount), " \u5143") : '无抹零'
3278
+ });
3279
+ return sum + effectiveAmount;
3260
3280
  }, 0);
3261
3281
  result = paidAmount.toFixed(2);
3262
3282
  console.log('[Checkout] calculatePaidAmountAsync: 计算结果 =', result);
@@ -3310,7 +3330,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3310
3330
  totalAmount: totalAmount.toFixed(2),
3311
3331
  paidAmount: paidAmount.toFixed(2),
3312
3332
  calculatedRemaining: remainingAmount.toFixed(2),
3313
- finalResult: result
3333
+ finalResult: result,
3334
+ 说明: '已支付金额包含抹零计算(amount + |rounding_amount|)'
3314
3335
  });
3315
3336
  return _context43.abrupt("return", result);
3316
3337
  case 13:
@@ -3543,6 +3564,8 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3543
3564
  uuid: p.uuid,
3544
3565
  code: p.code,
3545
3566
  amount: p.amount,
3567
+ rounding_amount: p.rounding_amount,
3568
+ effective_amount: (parseFloat(p.amount || '0') + Math.abs(parseFloat(p.rounding_amount || '0'))).toFixed(2),
3546
3569
  voucher_id: p.voucher_id,
3547
3570
  status: p.status
3548
3571
  };
@@ -3764,7 +3787,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
3764
3787
  code: p.code,
3765
3788
  amount: p.amount,
3766
3789
  uniquePaymentNumber: (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.unique_payment_number,
3767
- voucherId: p.voucher_id
3790
+ voucherId: p.voucher_id,
3791
+ orderPaymentType: p.order_payment_type,
3792
+ metadata: p.metadata
3768
3793
  };
3769
3794
  })
3770
3795
  });
@@ -508,7 +508,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
508
508
  this.logInfo("Starting addPaymentItemAsync", {
509
509
  orderUuid,
510
510
  paymentAmount: paymentItem.amount,
511
- paymentCode: paymentItem.code
511
+ paymentCode: paymentItem.code,
512
+ orderPaymentType: paymentItem.order_payment_type
512
513
  });
513
514
  try {
514
515
  const order = await this.getPaymentOrderByUuidAsync(orderUuid);
@@ -528,6 +529,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
528
529
  service_charge: paymentItem.service_charge,
529
530
  status: "active",
530
531
  // 新支付项默认为活跃状态
532
+ order_payment_type: paymentItem.order_payment_type || "normal",
533
+ // 默认为正常支付
531
534
  metadata: {
532
535
  unique_payment_number: paymentUuid
533
536
  // 设置唯一支付号为支付项的 uuid
@@ -622,7 +625,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
622
625
  voucherItems: voucherPaymentItems.map((item) => ({
623
626
  code: item.code,
624
627
  amount: item.amount,
625
- voucher_id: item.voucher_id
628
+ voucher_id: item.voucher_id,
629
+ order_payment_type: item.order_payment_type
626
630
  }))
627
631
  });
628
632
  try {
@@ -658,7 +662,8 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
658
662
  console.log(`[PaymentModule] 添加代金券支付项:`, {
659
663
  code: voucherItem.code,
660
664
  amount: voucherItem.amount,
661
- voucher_id: voucherItem.voucher_id
665
+ voucher_id: voucherItem.voucher_id,
666
+ order_payment_type: voucherItem.order_payment_type
662
667
  });
663
668
  await this.addPaymentItemAsync(orderUuid, voucherItem);
664
669
  }
@@ -861,9 +866,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
861
866
  if (payment.status === "voided") {
862
867
  return sum;
863
868
  }
864
- return sum.plus(payment.amount);
869
+ const paymentAmount = new import_decimal.Decimal(payment.amount || 0);
870
+ const roundingAmount = new import_decimal.Decimal(payment.rounding_amount || 0);
871
+ const effectiveAmount = paymentAmount.plus(roundingAmount.abs());
872
+ return sum.plus(effectiveAmount);
865
873
  } catch (error) {
866
- console.warn(`[PaymentModule] 无效的支付金额: ${payment.amount},跳过计算`);
874
+ console.warn(`[PaymentModule] 无效的支付金额: amount=${payment.amount}, rounding_amount=${payment.rounding_amount},跳过计算`);
867
875
  return sum;
868
876
  }
869
877
  },
@@ -874,10 +882,17 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
874
882
  console.log(`[PaymentModule] 重新计算订单金额:`, {
875
883
  orderUuid: order.uuid,
876
884
  totalAmount: order.total_amount,
877
- paidAmount: paidAmount.toFixed(2),
885
+ effectivePaidAmount: paidAmount.toFixed(2),
878
886
  remainingAmount: order.expect_amount,
879
887
  activePayments: order.payment.filter((p) => p.status !== "voided").length,
880
- voidedPayments: order.payment.filter((p) => p.status === "voided").length
888
+ voidedPayments: order.payment.filter((p) => p.status === "voided").length,
889
+ paymentDetails: order.payment.filter((p) => p.status !== "voided").map((p) => ({
890
+ code: p.code,
891
+ amount: p.amount,
892
+ rounding_amount: p.rounding_amount || "0.00",
893
+ effective_amount: new import_decimal.Decimal(p.amount || 0).plus(new import_decimal.Decimal(p.rounding_amount || 0).abs()).toFixed(2)
894
+ })),
895
+ 说明: "有效支付金额包含抹零计算(amount + |rounding_amount|)"
881
896
  });
882
897
  }
883
898
  /**
@@ -123,6 +123,8 @@ export interface PaymentItem {
123
123
  status?: 'active' | 'voided';
124
124
  /** 原始金额(用于记录撤销前的金额) */
125
125
  origin_amount?: string;
126
+ /** 订单支付类型 */
127
+ order_payment_type?: 'normal' | 'deposit';
126
128
  }
127
129
  /**
128
130
  * 订单信息
@@ -218,6 +220,17 @@ export interface PaymentItemInput {
218
220
  };
219
221
  /** 舍入金额 */
220
222
  rounding_amount?: string;
223
+ /** 订单支付类型 */
224
+ order_payment_type?: 'normal' | 'deposit';
225
+ /** 扩展参数字段 */
226
+ metadata?: {
227
+ /** 钱箱 ID */
228
+ shop_wallet_pass_id?: string;
229
+ /** 唯一支付号 */
230
+ unique_payment_number?: string;
231
+ /** rounding规则 */
232
+ rounding_rule?: any;
233
+ };
221
234
  }
222
235
  /**
223
236
  * 推送支付项参数
@@ -314,7 +314,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
314
314
  }[];
315
315
  setOtherData(key: string, value: any): void;
316
316
  getOtherData(key: string): any;
317
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
317
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
318
318
  /**
319
319
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
320
320
  *
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
111
111
  * 获取当前的客户搜索条件
112
112
  * @returns 当前搜索条件
113
113
  */
114
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
114
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
115
115
  /**
116
116
  * 获取客户列表状态(包含滚动加载相关状态)
117
117
  * @returns 客户状态
@@ -939,21 +939,36 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
939
939
  "未找到当前订单,无法添加支付项"
940
940
  );
941
941
  }
942
+ const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
943
+ const metadata = {
944
+ ...paymentItem.metadata,
945
+ rounding_rule: this.otherParams.order_rounding_setting,
946
+ shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
947
+ };
948
+ const paymentItemWithType = {
949
+ ...paymentItem,
950
+ order_payment_type: orderPaymentType,
951
+ metadata
952
+ };
942
953
  console.log("[Checkout] 为当前订单添加支付项:", {
943
954
  orderUuid: this.store.currentOrder.uuid,
944
955
  paymentItem: {
945
- code: paymentItem.code,
946
- name: paymentItem.name,
947
- type: paymentItem.type,
948
- amount: paymentItem.amount,
949
- service_charge: paymentItem.service_charge,
950
- rounding_amount: paymentItem.rounding_amount,
951
- voucher_id: paymentItem.voucher_id
952
- }
956
+ code: paymentItemWithType.code,
957
+ name: paymentItemWithType.name,
958
+ type: paymentItemWithType.type,
959
+ amount: paymentItemWithType.amount,
960
+ service_charge: paymentItemWithType.service_charge,
961
+ rounding_amount: paymentItemWithType.rounding_amount,
962
+ voucher_id: paymentItemWithType.voucher_id,
963
+ order_payment_type: paymentItemWithType.order_payment_type,
964
+ metadata: paymentItemWithType.metadata
965
+ },
966
+ orderDepositStatus: this.store.currentOrder.is_deposit,
967
+ calculatedOrderPaymentType: orderPaymentType
953
968
  });
954
969
  await this.payment.addPaymentItemAsync(
955
970
  this.store.currentOrder.uuid,
956
- paymentItem
971
+ paymentItemWithType
957
972
  );
958
973
  console.log("[Checkout] 支付项添加成功");
959
974
  const isEftposPayment = ((_a = paymentItem.type) == null ? void 0 : _a.toLowerCase()) === "eftpos" || ((_b = paymentItem.code) == null ? void 0 : _b.toUpperCase().includes("EFTPOS"));
@@ -1096,17 +1111,33 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1096
1111
  newVoucherCount: voucherPaymentItems.length,
1097
1112
  voucherPaymentItems
1098
1113
  });
1099
- for (const item of voucherPaymentItems) {
1114
+ const orderPaymentType = this.store.currentOrder.is_deposit === 1 ? "deposit" : "normal";
1115
+ const voucherPaymentItemsWithType = voucherPaymentItems.map((item) => {
1100
1116
  if (!item.voucher_id) {
1101
1117
  throw (0, import_utils.createCheckoutError)(
1102
1118
  import_types.CheckoutErrorType.ValidationFailed,
1103
1119
  `代金券支付项缺少 voucher_id: ${JSON.stringify(item)}`
1104
1120
  );
1105
1121
  }
1106
- }
1122
+ const metadata = {
1123
+ ...item.metadata,
1124
+ rounding_rule: this.otherParams.order_rounding_setting,
1125
+ shop_wallet_pass_id: this.otherParams.shop_wallet_pass_id
1126
+ };
1127
+ return {
1128
+ ...item,
1129
+ order_payment_type: orderPaymentType,
1130
+ metadata
1131
+ };
1132
+ });
1133
+ console.log("[Checkout] 代金券支付项订单支付类型设置:", {
1134
+ orderDepositStatus: this.store.currentOrder.is_deposit,
1135
+ calculatedOrderPaymentType: orderPaymentType,
1136
+ itemsCount: voucherPaymentItemsWithType.length
1137
+ });
1107
1138
  await this.payment.updateVoucherPaymentItemsAsync(
1108
1139
  this.store.currentOrder.uuid,
1109
- voucherPaymentItems
1140
+ voucherPaymentItemsWithType
1110
1141
  );
1111
1142
  console.log("[Checkout] Payment模块批量更新完成");
1112
1143
  const currentOrderId = this.store.currentOrder.order_id;
@@ -1966,13 +1997,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1966
1997
  uuid: p.uuid,
1967
1998
  amount: p.amount,
1968
1999
  code: p.code,
1969
- status: p.status
2000
+ status: p.status,
2001
+ rounding_amount: p.rounding_amount
1970
2002
  }))
1971
2003
  });
1972
2004
  const paidAmount = payments.filter((payment) => payment.status !== "voided").reduce((sum, payment) => {
1973
2005
  const amount = parseFloat(payment.amount || "0");
1974
- console.log(`[Checkout] 计算支付项: ${payment.code} = ${amount}`);
1975
- return sum + amount;
2006
+ const roundingAmount = parseFloat(payment.rounding_amount || "0");
2007
+ const effectiveAmount = amount + Math.abs(roundingAmount);
2008
+ console.log(`[Checkout] 计算支付项: ${payment.code}`, {
2009
+ 原始金额: amount,
2010
+ 抹零金额: roundingAmount,
2011
+ 有效金额: effectiveAmount,
2012
+ 说明: roundingAmount !== 0 ? `抹零金额 ${roundingAmount} 元,有效支付增加 ${Math.abs(roundingAmount)} 元` : "无抹零"
2013
+ });
2014
+ return sum + effectiveAmount;
1976
2015
  }, 0);
1977
2016
  const result = paidAmount.toFixed(2);
1978
2017
  console.log("[Checkout] calculatePaidAmountAsync: 计算结果 =", result);
@@ -1999,7 +2038,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1999
2038
  totalAmount: totalAmount.toFixed(2),
2000
2039
  paidAmount: paidAmount.toFixed(2),
2001
2040
  calculatedRemaining: remainingAmount.toFixed(2),
2002
- finalResult: result
2041
+ finalResult: result,
2042
+ 说明: "已支付金额包含抹零计算(amount + |rounding_amount|)"
2003
2043
  });
2004
2044
  return result;
2005
2045
  }
@@ -2119,6 +2159,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2119
2159
  uuid: p.uuid,
2120
2160
  code: p.code,
2121
2161
  amount: p.amount,
2162
+ rounding_amount: p.rounding_amount,
2163
+ effective_amount: (parseFloat(p.amount || "0") + Math.abs(parseFloat(p.rounding_amount || "0"))).toFixed(2),
2122
2164
  voucher_id: p.voucher_id,
2123
2165
  status: p.status
2124
2166
  }))
@@ -2242,7 +2284,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2242
2284
  code: p.code,
2243
2285
  amount: p.amount,
2244
2286
  uniquePaymentNumber: (_a2 = p.metadata) == null ? void 0 : _a2.unique_payment_number,
2245
- voucherId: p.voucher_id
2287
+ voucherId: p.voucher_id,
2288
+ orderPaymentType: p.order_payment_type,
2289
+ metadata: p.metadata
2246
2290
  };
2247
2291
  })
2248
2292
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.246",
4
+ "version": "0.0.248",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",