@pisell/pisellos 0.0.242 → 0.0.244

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.
@@ -168,6 +168,8 @@ export interface LocalOrderData {
168
168
  created_at?: string;
169
169
  /** 附加费用 */
170
170
  surcharge_fee?: number;
171
+ /** 附加费列表 */
172
+ surcharges?: any[];
171
173
  /** 商店折扣金额 */
172
174
  shop_discount?: number;
173
175
  }
@@ -382,10 +384,14 @@ export declare enum CheckoutHooks {
382
384
  OnError = "checkout:onError",
383
385
  /** 自定义支付金额变更 */
384
386
  OnStateAmountChanged = "checkout:onStateAmountChanged",
387
+ /** 系统计算的待付金额变更 */
388
+ OnBalanceDueAmountChanged = "checkout:onBalanceDueAmountChanged",
385
389
  /** 订单支付完成(待付款金额 ≤ 0) */
386
390
  OnOrderPaymentCompleted = "checkout:onOrderPaymentCompleted",
387
391
  /** 订单同步到后端完成 */
388
392
  OnOrderSynced = "checkout:onOrderSynced",
393
+ /** 订单同步到后端失败 */
394
+ OnOrderSyncFailed = "checkout:onOrderSyncFailed",
389
395
  /** 订单备注变更 */
390
396
  OnOrderNoteChanged = "checkout:onOrderNoteChanged",
391
397
  /** 商店折扣变更 */
@@ -421,6 +427,8 @@ export interface CheckoutState {
421
427
  lastError?: CheckoutError;
422
428
  /** UI 自定义支付金额 */
423
429
  stateAmount: string;
430
+ /** 系统计算的待付金额(只读,由系统内部计算) */
431
+ balanceDueAmount: string;
424
432
  /** 订单是否已同步到后端 */
425
433
  isOrderSynced: boolean;
426
434
  /** 当前客户信息 */
@@ -560,6 +568,12 @@ export interface CheckoutModuleAPI extends Module {
560
568
  * 获取当前自定义支付金额
561
569
  */
562
570
  getStateAmount(): string;
571
+ /**
572
+ * 获取系统计算的待付金额(只读)
573
+ *
574
+ * @returns 当前系统计算的待付金额
575
+ */
576
+ getBalanceDueAmount(): string;
563
577
  /**
564
578
  * 刷新 stateAmount 为当前剩余未支付金额
565
579
  */
@@ -780,6 +794,12 @@ export interface CheckoutEventData {
780
794
  newAmount: string;
781
795
  timestamp: number;
782
796
  };
797
+ /** 系统计算的待付金额变更事件 */
798
+ balanceDueAmountChanged: {
799
+ oldAmount: string;
800
+ newAmount: string;
801
+ timestamp: number;
802
+ };
783
803
  /** 订单支付完成事件 */
784
804
  orderPaymentCompleted: {
785
805
  orderUuid: string;
@@ -797,6 +817,25 @@ export interface CheckoutEventData {
797
817
  timestamp: number;
798
818
  /** 是否为手动同步 */
799
819
  isManual?: boolean;
820
+ /** 后端响应数据 */
821
+ response?: any;
822
+ };
823
+ /** 订单同步到后端失败事件 */
824
+ orderSyncFailed: {
825
+ orderUuid: string;
826
+ /** 操作类型 */
827
+ operation: 'create' | 'update';
828
+ /** 是否为手动同步 */
829
+ isManual: boolean;
830
+ /** 错误信息 */
831
+ error: string;
832
+ /** 错误类型 */
833
+ errorType: 'network_error' | 'api_error' | 'response_invalid' | 'unknown';
834
+ /** 后端响应数据(如果有) */
835
+ response?: any;
836
+ /** 耗时(毫秒) */
837
+ duration?: number;
838
+ timestamp: number;
800
839
  };
801
840
  /** 订单备注变更事件 */
802
841
  orderNoteChanged: {
@@ -113,8 +113,10 @@ export var CheckoutHooks = /*#__PURE__*/function (CheckoutHooks) {
113
113
  CheckoutHooks["OnCheckoutCancelled"] = "checkout:onCancelled";
114
114
  CheckoutHooks["OnError"] = "checkout:onError";
115
115
  CheckoutHooks["OnStateAmountChanged"] = "checkout:onStateAmountChanged";
116
+ CheckoutHooks["OnBalanceDueAmountChanged"] = "checkout:onBalanceDueAmountChanged";
116
117
  CheckoutHooks["OnOrderPaymentCompleted"] = "checkout:onOrderPaymentCompleted";
117
118
  CheckoutHooks["OnOrderSynced"] = "checkout:onOrderSynced";
119
+ CheckoutHooks["OnOrderSyncFailed"] = "checkout:onOrderSyncFailed";
118
120
  CheckoutHooks["OnOrderNoteChanged"] = "checkout:onOrderNoteChanged";
119
121
  CheckoutHooks["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
120
122
  CheckoutHooks["OnOrderCancelled"] = "checkout:onOrderCancelled";
@@ -160,6 +160,14 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
160
160
  * @returns 当前设置的自定义支付金额
161
161
  */
162
162
  getStateAmount(): string;
163
+ /**
164
+ * 获取系统计算的待付金额(只读)
165
+ *
166
+ * 此方法返回系统内部计算的实际待付金额,不允许外部修改
167
+ *
168
+ * @returns 当前系统计算的待付金额
169
+ */
170
+ getBalanceDueAmount(): string;
163
171
  /**
164
172
  * 刷新 stateAmount 为当前剩余未支付金额
165
173
  *
@@ -391,6 +399,10 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
391
399
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
392
400
  */
393
401
  private calculateRemainingAmountAsync;
402
+ /**
403
+ * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
404
+ */
405
+ private updateBalanceDueAmount;
394
406
  /**
395
407
  * 更新 stateAmount 为当前剩余未支付金额
396
408
  */
@@ -53,6 +53,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
53
53
  cartItems: [],
54
54
  paymentMethods: [],
55
55
  stateAmount: "0.00",
56
+ balanceDueAmount: "0.00",
56
57
  cartSummary: void 0,
57
58
  isOrderSynced: false,
58
59
  currentCustomer: void 0
@@ -189,7 +190,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
189
190
  * 方法会记录参数并创建本地虚拟订单,然后用 Payment 模块管理支付流程。
190
191
  */
191
192
  async createLocalOrderAsync(params) {
192
- var _a, _b, _c, _d;
193
+ var _a, _b, _c, _d, _e, _f;
193
194
  try {
194
195
  await this.resetStoreStateAsync();
195
196
  await this.setStatus(import_types.CheckoutStatus.CreatingOrder);
@@ -204,8 +205,9 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
204
205
  const amountInfo = this.extractAmountFromCartSummary(params.cartSummary);
205
206
  params.orderData.platform = "pos";
206
207
  params.orderData.created_at = this.formatDateTime(/* @__PURE__ */ new Date());
207
- params.orderData.surcharge_fee = (_b = (_a = params.totalInfo) == null ? void 0 : _a.total) == null ? void 0 : _b.paySurchargeFee;
208
- params.orderData.shop_discount = (_d = (_c = params.totalInfo) == null ? void 0 : _c.total) == null ? void 0 : _d.shopDiscount;
208
+ params.orderData.surcharge_fee = (_b = (_a = params.totalInfo) == null ? void 0 : _a.total) == null ? void 0 : _b.otherAmount;
209
+ params.orderData.surcharges = (_d = (_c = params.totalInfo) == null ? void 0 : _c.total) == null ? void 0 : _d.surcharge;
210
+ params.orderData.shop_discount = (_f = (_e = params.totalInfo) == null ? void 0 : _e.total) == null ? void 0 : _f.shopDiscount;
209
211
  this.store.localOrderData = params.orderData;
210
212
  this.store.cartSummary = params.cartSummary;
211
213
  const customerInfo = {
@@ -514,6 +516,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
514
516
  this.payment.wallet.clearAllCache();
515
517
  this.store.cartItems = [];
516
518
  this.store.stateAmount = "0.00";
519
+ this.store.balanceDueAmount = "0.00";
517
520
  this.store.isOrderSynced = false;
518
521
  this.store.currentCustomer = void 0;
519
522
  await this.setStatus(import_types.CheckoutStatus.Cancelled);
@@ -823,6 +826,16 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
823
826
  getStateAmount() {
824
827
  return this.store.stateAmount;
825
828
  }
829
+ /**
830
+ * 获取系统计算的待付金额(只读)
831
+ *
832
+ * 此方法返回系统内部计算的实际待付金额,不允许外部修改
833
+ *
834
+ * @returns 当前系统计算的待付金额
835
+ */
836
+ getBalanceDueAmount() {
837
+ return this.store.balanceDueAmount;
838
+ }
826
839
  /**
827
840
  * 刷新 stateAmount 为当前剩余未支付金额
828
841
  *
@@ -1455,6 +1468,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1455
1468
  this.store.currentOrder = void 0;
1456
1469
  this.store.localOrderData = void 0;
1457
1470
  this.store.stateAmount = "0.00";
1471
+ this.store.balanceDueAmount = "0.00";
1458
1472
  this.store.isOrderSynced = false;
1459
1473
  this.store.currentCustomer = void 0;
1460
1474
  this.payment.wallet.clearAllCache();
@@ -1979,6 +1993,41 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
1979
1993
  });
1980
1994
  return result;
1981
1995
  }
1996
+ /**
1997
+ * 更新 balanceDueAmount 为当前剩余未支付金额(系统内部计算)
1998
+ */
1999
+ async updateBalanceDueAmount() {
2000
+ var _a;
2001
+ try {
2002
+ const remainingAmount = await this.calculateRemainingAmountAsync();
2003
+ const currentBalanceDueAmount = this.store.balanceDueAmount;
2004
+ console.log("[Checkout] updateBalanceDueAmount: 状态检查:", {
2005
+ calculatedRemainingAmount: remainingAmount,
2006
+ currentBalanceDueAmount,
2007
+ needsUpdate: remainingAmount !== currentBalanceDueAmount,
2008
+ orderUuid: (_a = this.store.currentOrder) == null ? void 0 : _a.uuid
2009
+ });
2010
+ if (remainingAmount !== currentBalanceDueAmount) {
2011
+ this.store.balanceDueAmount = remainingAmount;
2012
+ await this.core.effects.emit(import_types.CheckoutHooks.OnBalanceDueAmountChanged, {
2013
+ oldAmount: currentBalanceDueAmount,
2014
+ newAmount: remainingAmount,
2015
+ timestamp: Date.now()
2016
+ });
2017
+ console.log("[Checkout] balanceDueAmount 已自动更新:", {
2018
+ oldAmount: currentBalanceDueAmount,
2019
+ newAmount: remainingAmount
2020
+ });
2021
+ } else {
2022
+ console.log("[Checkout] balanceDueAmount 无需更新,当前值已是最新:", {
2023
+ balanceDueAmount: currentBalanceDueAmount,
2024
+ remainingAmount
2025
+ });
2026
+ }
2027
+ } catch (error) {
2028
+ console.error("[Checkout] 更新 balanceDueAmount 失败:", error);
2029
+ }
2030
+ }
1982
2031
  /**
1983
2032
  * 更新 stateAmount 为当前剩余未支付金额
1984
2033
  */
@@ -2010,6 +2059,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2010
2059
  remainingAmount
2011
2060
  });
2012
2061
  }
2062
+ await this.updateBalanceDueAmount();
2013
2063
  await this.checkOrderPaymentCompletion();
2014
2064
  } catch (error) {
2015
2065
  console.error("[Checkout] 更新 stateAmount 为剩余金额失败:", error);
@@ -2252,7 +2302,15 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2252
2302
  } catch (error) {
2253
2303
  submitSuccess = false;
2254
2304
  submitError = error instanceof Error ? error.message : String(error);
2255
- console.error("[Checkout] 下单接口调用失败:", submitError);
2305
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
2306
+ orderUuid: this.store.currentOrder.uuid,
2307
+ operation: isUpdateOperation ? "update" : "create",
2308
+ isManual,
2309
+ error: submitError,
2310
+ errorType: "network_error",
2311
+ duration: Date.now() - startTime,
2312
+ timestamp: Date.now()
2313
+ });
2256
2314
  throw error;
2257
2315
  } finally {
2258
2316
  await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSubmitEnd, {
@@ -2272,6 +2330,30 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2272
2330
  message: checkoutResponse == null ? void 0 : checkoutResponse.message,
2273
2331
  data: checkoutResponse == null ? void 0 : checkoutResponse.data
2274
2332
  });
2333
+ const responseStatus = checkoutResponse == null ? void 0 : checkoutResponse.status;
2334
+ const isSuccessResponse = responseStatus === true || responseStatus === 200 || responseStatus === "success" || responseStatus === 1 && (checkoutResponse == null ? void 0 : checkoutResponse.code) === 200;
2335
+ if (!isSuccessResponse) {
2336
+ const errorMessage = (checkoutResponse == null ? void 0 : checkoutResponse.message) || "订单同步失败,后端返回非成功状态";
2337
+ console.error("[Checkout] 订单同步失败,响应状态检查未通过:", {
2338
+ expectedSuccess: true,
2339
+ actualStatus: responseStatus,
2340
+ code: checkoutResponse == null ? void 0 : checkoutResponse.code,
2341
+ message: checkoutResponse == null ? void 0 : checkoutResponse.message,
2342
+ errorMessage
2343
+ });
2344
+ await this.core.effects.emit(import_types.CheckoutHooks.OnOrderSyncFailed, {
2345
+ orderUuid: this.store.currentOrder.uuid,
2346
+ operation: isUpdateOperation ? "update" : "create",
2347
+ isManual,
2348
+ error: errorMessage,
2349
+ errorType: "api_error",
2350
+ response: checkoutResponse,
2351
+ duration: Date.now() - startTime,
2352
+ timestamp: Date.now()
2353
+ });
2354
+ throw new Error(errorMessage);
2355
+ }
2356
+ console.log("[Checkout] 响应状态检查通过,开始处理订单数据");
2275
2357
  let realOrderId;
2276
2358
  if (isUpdateOperation) {
2277
2359
  realOrderId = currentOrderId;
@@ -2598,6 +2680,7 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
2598
2680
  this.store.localOrderData = void 0;
2599
2681
  this.store.cartSummary = void 0;
2600
2682
  this.store.stateAmount = "0.00";
2683
+ this.store.balanceDueAmount = "0.00";
2601
2684
  this.store.isOrderSynced = false;
2602
2685
  this.store.currentCustomer = void 0;
2603
2686
  this.store.lastError = void 0;
@@ -168,6 +168,8 @@ export interface LocalOrderData {
168
168
  created_at?: string;
169
169
  /** 附加费用 */
170
170
  surcharge_fee?: number;
171
+ /** 附加费列表 */
172
+ surcharges?: any[];
171
173
  /** 商店折扣金额 */
172
174
  shop_discount?: number;
173
175
  }
@@ -382,10 +384,14 @@ export declare enum CheckoutHooks {
382
384
  OnError = "checkout:onError",
383
385
  /** 自定义支付金额变更 */
384
386
  OnStateAmountChanged = "checkout:onStateAmountChanged",
387
+ /** 系统计算的待付金额变更 */
388
+ OnBalanceDueAmountChanged = "checkout:onBalanceDueAmountChanged",
385
389
  /** 订单支付完成(待付款金额 ≤ 0) */
386
390
  OnOrderPaymentCompleted = "checkout:onOrderPaymentCompleted",
387
391
  /** 订单同步到后端完成 */
388
392
  OnOrderSynced = "checkout:onOrderSynced",
393
+ /** 订单同步到后端失败 */
394
+ OnOrderSyncFailed = "checkout:onOrderSyncFailed",
389
395
  /** 订单备注变更 */
390
396
  OnOrderNoteChanged = "checkout:onOrderNoteChanged",
391
397
  /** 商店折扣变更 */
@@ -421,6 +427,8 @@ export interface CheckoutState {
421
427
  lastError?: CheckoutError;
422
428
  /** UI 自定义支付金额 */
423
429
  stateAmount: string;
430
+ /** 系统计算的待付金额(只读,由系统内部计算) */
431
+ balanceDueAmount: string;
424
432
  /** 订单是否已同步到后端 */
425
433
  isOrderSynced: boolean;
426
434
  /** 当前客户信息 */
@@ -560,6 +568,12 @@ export interface CheckoutModuleAPI extends Module {
560
568
  * 获取当前自定义支付金额
561
569
  */
562
570
  getStateAmount(): string;
571
+ /**
572
+ * 获取系统计算的待付金额(只读)
573
+ *
574
+ * @returns 当前系统计算的待付金额
575
+ */
576
+ getBalanceDueAmount(): string;
563
577
  /**
564
578
  * 刷新 stateAmount 为当前剩余未支付金额
565
579
  */
@@ -780,6 +794,12 @@ export interface CheckoutEventData {
780
794
  newAmount: string;
781
795
  timestamp: number;
782
796
  };
797
+ /** 系统计算的待付金额变更事件 */
798
+ balanceDueAmountChanged: {
799
+ oldAmount: string;
800
+ newAmount: string;
801
+ timestamp: number;
802
+ };
783
803
  /** 订单支付完成事件 */
784
804
  orderPaymentCompleted: {
785
805
  orderUuid: string;
@@ -797,6 +817,25 @@ export interface CheckoutEventData {
797
817
  timestamp: number;
798
818
  /** 是否为手动同步 */
799
819
  isManual?: boolean;
820
+ /** 后端响应数据 */
821
+ response?: any;
822
+ };
823
+ /** 订单同步到后端失败事件 */
824
+ orderSyncFailed: {
825
+ orderUuid: string;
826
+ /** 操作类型 */
827
+ operation: 'create' | 'update';
828
+ /** 是否为手动同步 */
829
+ isManual: boolean;
830
+ /** 错误信息 */
831
+ error: string;
832
+ /** 错误类型 */
833
+ errorType: 'network_error' | 'api_error' | 'response_invalid' | 'unknown';
834
+ /** 后端响应数据(如果有) */
835
+ response?: any;
836
+ /** 耗时(毫秒) */
837
+ duration?: number;
838
+ timestamp: number;
800
839
  };
801
840
  /** 订单备注变更事件 */
802
841
  orderNoteChanged: {
@@ -65,8 +65,10 @@ var CheckoutHooks = /* @__PURE__ */ ((CheckoutHooks2) => {
65
65
  CheckoutHooks2["OnCheckoutCancelled"] = "checkout:onCancelled";
66
66
  CheckoutHooks2["OnError"] = "checkout:onError";
67
67
  CheckoutHooks2["OnStateAmountChanged"] = "checkout:onStateAmountChanged";
68
+ CheckoutHooks2["OnBalanceDueAmountChanged"] = "checkout:onBalanceDueAmountChanged";
68
69
  CheckoutHooks2["OnOrderPaymentCompleted"] = "checkout:onOrderPaymentCompleted";
69
70
  CheckoutHooks2["OnOrderSynced"] = "checkout:onOrderSynced";
71
+ CheckoutHooks2["OnOrderSyncFailed"] = "checkout:onOrderSyncFailed";
70
72
  CheckoutHooks2["OnOrderNoteChanged"] = "checkout:onOrderNoteChanged";
71
73
  CheckoutHooks2["OnShopDiscountChanged"] = "checkout:onShopDiscountChanged";
72
74
  CheckoutHooks2["OnOrderCancelled"] = "checkout:onOrderCancelled";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.242",
4
+ "version": "0.0.244",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",