@pisell/pisellos 0.0.261 → 0.0.263

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.
@@ -438,6 +438,12 @@ export interface CheckoutModuleAPI extends Module {
438
438
  * 修改当前订单的定金状态
439
439
  */
440
440
  updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
441
+ /**
442
+ * 手动设置当前订单的定金金额
443
+ *
444
+ * @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
445
+ */
446
+ setDepositAmountAsync(depositAmount: string): Promise<void>;
441
447
  /**
442
448
  * 手动同步订单到后端
443
449
  *
@@ -324,9 +324,12 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
324
324
  });
325
325
  try {
326
326
  const existingOrder = await this.dbManager.get("order", params.order_id);
327
+ this.logInfo("createPaymentOrderAsync existingOrder", {
328
+ existingOrder
329
+ });
327
330
  if (existingOrder) {
328
- console.log(
329
- `[PaymentModule] 发现重复订单 ID: ${params.order_id},更新现有支付订单`
331
+ this.logInfo(
332
+ `createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`
330
333
  );
331
334
  existingOrder.order_info = params.order_info;
332
335
  existingOrder.total_amount = params.total_amount;
@@ -182,6 +182,16 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
182
182
  * @throws 当前没有活跃订单时抛出错误
183
183
  */
184
184
  updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
185
+ /**
186
+ * 手动设置当前订单的定金金额
187
+ *
188
+ * 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
189
+ *
190
+ * @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
191
+ * @throws 当前没有活跃订单时抛出错误
192
+ * @throws 定金金额格式无效或超过订单总额时抛出错误
193
+ */
194
+ setDepositAmountAsync(depositAmount: string): Promise<void>;
185
195
  /**
186
196
  * 手动同步订单到后端
187
197
  *
@@ -222,8 +222,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
222
222
  }
223
223
  async initWalletData(params) {
224
224
  var _a, _b, _c, _d;
225
+ this.logInfo("initWalletData called", {
226
+ params
227
+ });
225
228
  const amountInfo = (_b = (_a = this.store.currentOrder) == null ? void 0 : _a.order_info) == null ? void 0 : _b.amount_breakdown;
226
229
  if (!amountInfo) {
230
+ this.logInfo("initWalletData amountInfo not found", {
231
+ params
232
+ });
227
233
  return;
228
234
  }
229
235
  const walletBusinessData = {
@@ -235,12 +241,21 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
235
241
  products: this.getProductListByOrder(),
236
242
  ...params
237
243
  };
244
+ this.logInfo("开始拉取:initializeWalletDataFromBusinessAsync", {
245
+ walletBusinessData
246
+ });
238
247
  await this.payment.wallet.initializeWalletDataFromBusinessAsync(
239
248
  walletBusinessData
240
249
  );
250
+ this.logInfo("调用结束:initializeWalletDataFromBusinessAsync", {
251
+ walletBusinessData
252
+ });
241
253
  if (!this.store.currentOrder) {
242
254
  return;
243
255
  }
256
+ this.logInfo("initWalletData currentOrder found", {
257
+ currentOrder: this.store.currentOrder
258
+ });
244
259
  await this.core.effects.emit(import_types.CheckoutHooks.OnWalletDataInitialized, {
245
260
  orderUuid: (_d = this.store.currentOrder) == null ? void 0 : _d.uuid,
246
261
  customerId: walletBusinessData.customer_id,
@@ -318,7 +333,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
318
333
  }
319
334
  });
320
335
  this.store.currentOrder = paymentOrder;
321
- this.initWalletData();
322
336
  if (params.autoPayment) {
323
337
  }
324
338
  this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
@@ -334,12 +348,14 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
334
348
  taxAmount: amountInfo.taxAmount,
335
349
  stateAmount: this.store.stateAmount
336
350
  });
351
+ this.initWalletData();
337
352
  return paymentOrder;
338
353
  } catch (error) {
339
354
  await this.handleError(
340
355
  error,
341
356
  import_types.CheckoutErrorType.OrderCreationFailed
342
357
  );
358
+ this.logError("本地订单创建失败:", error);
343
359
  this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreationFailed, {
344
360
  error: this.store.lastError,
345
361
  timestamp: Date.now()
@@ -897,6 +913,107 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
897
913
  throw error;
898
914
  }
899
915
  }
916
+ /**
917
+ * 手动设置当前订单的定金金额
918
+ *
919
+ * 允许手动设置订单的定金金额,通常用于用户自定义定金支付场景
920
+ *
921
+ * @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
922
+ * @throws 当前没有活跃订单时抛出错误
923
+ * @throws 定金金额格式无效或超过订单总额时抛出错误
924
+ */
925
+ async setDepositAmountAsync(depositAmount) {
926
+ var _a, _b;
927
+ this.logInfo("setDepositAmountAsync called", {
928
+ depositAmount,
929
+ hasCurrentOrder: !!this.store.currentOrder,
930
+ currentOrderId: (_a = this.store.currentOrder) == null ? void 0 : _a.order_id,
931
+ currentTotalAmount: (_b = this.store.currentOrder) == null ? void 0 : _b.total_amount
932
+ });
933
+ try {
934
+ const depositValue = new import_decimal.default(depositAmount);
935
+ if (depositValue.isNaN() || depositValue.lt(0)) {
936
+ throw (0, import_utils.createCheckoutError)(
937
+ import_types.CheckoutErrorType.ValidationFailed,
938
+ `无效的定金金额格式: ${depositAmount}`
939
+ );
940
+ }
941
+ if (!this.store.currentOrder) {
942
+ throw (0, import_utils.createCheckoutError)(
943
+ import_types.CheckoutErrorType.ValidationFailed,
944
+ "未找到当前订单,无法设置定金金额"
945
+ );
946
+ }
947
+ const totalAmount = new import_decimal.default(this.store.currentOrder.total_amount || "0");
948
+ if (depositValue.gt(totalAmount)) {
949
+ throw (0, import_utils.createCheckoutError)(
950
+ import_types.CheckoutErrorType.ValidationFailed,
951
+ `定金金额 ${depositAmount} 不能超过订单总额 ${totalAmount.toFixed(2)}`
952
+ );
953
+ }
954
+ const formattedDepositAmount = depositValue.toFixed(2);
955
+ const oldDepositAmount = this.store.currentOrder.deposit_amount || "0.00";
956
+ if (formattedDepositAmount === oldDepositAmount) {
957
+ this.logInfo("定金金额无变化,跳过更新:", {
958
+ currentAmount: oldDepositAmount,
959
+ newAmount: formattedDepositAmount
960
+ });
961
+ return;
962
+ }
963
+ this.logInfo("开始设置订单定金金额:", {
964
+ orderUuid: this.store.currentOrder.uuid,
965
+ orderId: this.store.currentOrder.order_id,
966
+ oldDepositAmount,
967
+ newDepositAmount: formattedDepositAmount,
968
+ totalAmount: totalAmount.toFixed(2)
969
+ });
970
+ const updateParams = {
971
+ deposit_amount: formattedDepositAmount
972
+ };
973
+ if (depositValue.gt(0) && this.store.currentOrder.is_deposit !== 1) {
974
+ updateParams.is_deposit = 1;
975
+ this.logInfo("定金金额大于0,自动设置为定金订单");
976
+ } else if (depositValue.eq(0) && this.store.currentOrder.is_deposit === 1) {
977
+ updateParams.is_deposit = 0;
978
+ this.logInfo("定金金额为0,自动设置为全款订单");
979
+ }
980
+ await this.payment.updateOrderAsync(
981
+ this.store.currentOrder.uuid,
982
+ updateParams
983
+ );
984
+ this.store.currentOrder = {
985
+ ...this.store.currentOrder,
986
+ ...updateParams
987
+ };
988
+ if (this.store.localOrderData) {
989
+ if ("deposit_amount" in this.store.localOrderData) {
990
+ this.store.localOrderData.deposit_amount = formattedDepositAmount;
991
+ }
992
+ if (updateParams.is_deposit !== void 0) {
993
+ this.store.localOrderData.is_deposit = updateParams.is_deposit;
994
+ }
995
+ }
996
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderCreated, {
997
+ order: this.store.currentOrder,
998
+ timestamp: Date.now()
999
+ });
1000
+ this.logInfo("订单定金金额设置成功:", {
1001
+ orderUuid: this.store.currentOrder.uuid,
1002
+ orderId: this.store.currentOrder.order_id,
1003
+ oldDepositAmount,
1004
+ newDepositAmount: formattedDepositAmount,
1005
+ isDeposit: this.store.currentOrder.is_deposit,
1006
+ totalAmount: this.store.currentOrder.total_amount
1007
+ });
1008
+ } catch (error) {
1009
+ this.logError("设置订单定金金额失败:", error);
1010
+ await this.handleError(
1011
+ error,
1012
+ import_types.CheckoutErrorType.ValidationFailed
1013
+ );
1014
+ throw error;
1015
+ }
1016
+ }
900
1017
  /**
901
1018
  * 手动同步订单到后端
902
1019
  *
@@ -1615,7 +1732,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1615
1732
  * @returns 包含订单ID、UUID和完整后端响应的对象
1616
1733
  */
1617
1734
  async syncOrderToBackendWithReturn(isManual = false, customPaymentItems) {
1618
- var _a, _b, _c, _d, _e;
1735
+ var _a, _b, _c, _d, _e, _f;
1619
1736
  if (!this.store.localOrderData || !this.store.currentOrder) {
1620
1737
  throw new Error("缺少必要的订单数据,无法同步到后端");
1621
1738
  }
@@ -1641,6 +1758,8 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1641
1758
  }
1642
1759
  };
1643
1760
  });
1761
+ let finalDepositAmount;
1762
+ const manualDepositAmount = ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00";
1644
1763
  const depositPaymentItems = processedPaymentItems.filter(
1645
1764
  (item) => item.order_payment_type === "deposit" && item.status !== "voided"
1646
1765
  );
@@ -1650,7 +1769,31 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1650
1769
  const effectiveAmount = amount.add(roundingAmount.abs());
1651
1770
  return sum.add(effectiveAmount);
1652
1771
  }, new import_decimal.default(0)).toFixed(2);
1653
- this.logInfo("计算定金支付项总金额", {
1772
+ const manualDepositValue = new import_decimal.default(manualDepositAmount);
1773
+ const calculatedDepositValue = new import_decimal.default(calculatedDepositAmount);
1774
+ if (manualDepositValue.gt(0)) {
1775
+ finalDepositAmount = manualDepositAmount;
1776
+ this.logInfo("使用手动设置的定金金额", {
1777
+ manualDepositAmount,
1778
+ calculatedDepositAmount,
1779
+ reason: "用户通过setDepositAmountAsync手动设置了定金金额"
1780
+ });
1781
+ } else if (calculatedDepositValue.gt(0)) {
1782
+ finalDepositAmount = calculatedDepositAmount;
1783
+ this.logInfo("使用从支付项计算的定金金额", {
1784
+ manualDepositAmount,
1785
+ calculatedDepositAmount,
1786
+ reason: "未手动设置定金金额,从定金类型支付项计算得出"
1787
+ });
1788
+ } else {
1789
+ finalDepositAmount = "0.00";
1790
+ this.logInfo("定金金额为0", {
1791
+ manualDepositAmount,
1792
+ calculatedDepositAmount,
1793
+ reason: "手动设置和计算值均为0"
1794
+ });
1795
+ }
1796
+ this.logInfo("定金金额确定结果", {
1654
1797
  depositPaymentItemsCount: depositPaymentItems.length,
1655
1798
  depositPaymentItems: depositPaymentItems.map((item) => ({
1656
1799
  uuid: item.uuid,
@@ -1660,8 +1803,10 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1660
1803
  order_payment_type: item.order_payment_type,
1661
1804
  status: item.status
1662
1805
  })),
1806
+ manualDepositAmount,
1663
1807
  calculatedDepositAmount,
1664
- originalDepositAmount: ((_a = this.store.currentOrder) == null ? void 0 : _a.deposit_amount) || "0.00"
1808
+ finalDepositAmount,
1809
+ isDeposit: ((_b = this.store.currentOrder) == null ? void 0 : _b.is_deposit) || 0
1665
1810
  });
1666
1811
  const orderParams = {
1667
1812
  ...this.store.localOrderData,
@@ -1669,7 +1814,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1669
1814
  platform: this.store.localOrderData.platform,
1670
1815
  payments: processedPaymentItems,
1671
1816
  // 使用处理过的支付项数据
1672
- customer_id: (_b = this.store.currentCustomer) == null ? void 0 : _b.customer_id,
1817
+ customer_id: (_c = this.store.currentCustomer) == null ? void 0 : _c.customer_id,
1673
1818
  // 添加客户ID
1674
1819
  is_price_include_tax: this.otherParams.is_price_include_tax,
1675
1820
  // core 有
@@ -1682,9 +1827,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1682
1827
  currency_code: this.otherParams.currency_code,
1683
1828
  currency_symbol: this.otherParams.currency_symbol,
1684
1829
  currency_format: this.otherParams.currency_format,
1685
- is_deposit: ((_c = this.store.currentOrder) == null ? void 0 : _c.is_deposit) || 0,
1686
- deposit_amount: calculatedDepositAmount,
1687
- // 使用从支付项中计算出的定金金额
1830
+ is_deposit: ((_d = this.store.currentOrder) == null ? void 0 : _d.is_deposit) || 0,
1831
+ deposit_amount: finalDepositAmount,
1832
+ // 使用最终确定的定金金额(手动设置优先)
1688
1833
  product_tax_fee: this.store.localOrderData.tax_fee,
1689
1834
  note: this.store.localOrderData.shop_note
1690
1835
  };
@@ -1737,7 +1882,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1737
1882
  orderUuid: this.store.currentOrder.uuid,
1738
1883
  operation: isUpdateOperation ? "update" : "create",
1739
1884
  isManual,
1740
- orderId: submitSuccess ? ((_d = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _d.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
1885
+ orderId: submitSuccess ? ((_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id) || (checkoutResponse == null ? void 0 : checkoutResponse.order_id) : void 0,
1741
1886
  error: submitError,
1742
1887
  duration: Date.now() - startTime,
1743
1888
  timestamp: Date.now()
@@ -1763,7 +1908,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1763
1908
  if (isUpdateOperation) {
1764
1909
  realOrderId = currentOrderId;
1765
1910
  } else {
1766
- let extractedOrderId = (_e = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _e.order_id;
1911
+ let extractedOrderId = (_f = checkoutResponse == null ? void 0 : checkoutResponse.data) == null ? void 0 : _f.order_id;
1767
1912
  if (!extractedOrderId) {
1768
1913
  extractedOrderId = checkoutResponse == null ? void 0 : checkoutResponse.order_id;
1769
1914
  }
@@ -438,6 +438,12 @@ export interface CheckoutModuleAPI extends Module {
438
438
  * 修改当前订单的定金状态
439
439
  */
440
440
  updateOrderDepositStatusAsync(isDeposit: number): Promise<void>;
441
+ /**
442
+ * 手动设置当前订单的定金金额
443
+ *
444
+ * @param depositAmount 定金金额,必须是有效的数字字符串,且不能超过订单总额
445
+ */
446
+ setDepositAmountAsync(depositAmount: string): Promise<void>;
441
447
  /**
442
448
  * 手动同步订单到后端
443
449
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.261",
4
+ "version": "0.0.263",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",