@pisell/pisellos 2.3.8 → 2.3.9

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.
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -458,7 +458,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
458
458
  generateIdempotencyToken(): string;
459
459
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
460
460
  createOrder(params: CommitOrderParams['query']): {
461
- type: "appointment_booking" | "virtual";
461
+ type: "virtual" | "appointment_booking";
462
462
  platform: string;
463
463
  sales_channel: string;
464
464
  order_sales_channel: string;
@@ -79,6 +79,9 @@ function isPendingVoucherPaymentRecord(payment) {
79
79
  function isPaidPaymentRecord(payment) {
80
80
  return (payment == null ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PAID;
81
81
  }
82
+ function isCommittedVoucherPaymentRecord(payment) {
83
+ return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
84
+ }
82
85
  var OrderModule = class extends import_BaseModule.BaseModule {
83
86
  constructor(name, version) {
84
87
  super(name || "order", version);
@@ -2541,25 +2544,39 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2541
2544
  const nonVoucherPayments = (tempOrder.payments || []).filter((payment) => {
2542
2545
  return !isVoucherPaymentRecord(payment);
2543
2546
  });
2544
- const syncedVoucherPayments = (tempOrder.payments || []).filter((payment) => {
2545
- return isVoucherPaymentRecord(payment) && hasSyncedOrderPaymentRecord(payment);
2546
- });
2547
- const syncedVoucherPaymentIds = new Set(
2548
- syncedVoucherPayments.map((payment) => String(payment.order_payment_id))
2547
+ const normalizeCommittedVoucherPayment = (payment) => {
2548
+ if (hasSyncedOrderPaymentRecord(payment) && (payment.status === void 0 || payment.status === "active")) {
2549
+ return {
2550
+ ...payment,
2551
+ status: ORDER_PAYMENT_STATUS_PAID
2552
+ };
2553
+ }
2554
+ return payment;
2555
+ };
2556
+ const committedVoucherPayments = (tempOrder.payments || []).filter((payment) => isCommittedVoucherPaymentRecord(payment)).map((payment) => normalizeCommittedVoucherPayment(payment));
2557
+ const committedVoucherPaymentIds = new Set(
2558
+ committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2559
+ );
2560
+ const committedVoucherIds = new Set(
2561
+ committedVoucherPayments.map((payment) => String(payment.voucher_id))
2549
2562
  );
2550
2563
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2551
- if (!hasSyncedOrderPaymentRecord(payment))
2552
- return true;
2553
- return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
2564
+ if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2565
+ return false;
2566
+ }
2567
+ if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2568
+ return false;
2569
+ }
2570
+ return true;
2554
2571
  });
2555
2572
  const cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
2556
2573
  vouchers: replaceableVouchers,
2557
2574
  nonVoucherPayments: [
2558
2575
  ...nonVoucherPayments,
2559
- ...syncedVoucherPayments
2576
+ ...committedVoucherPayments
2560
2577
  ]
2561
2578
  });
2562
- tempOrder.payments = [...nonVoucherPayments, ...syncedVoucherPayments, ...cappedVouchers];
2579
+ tempOrder.payments = [...nonVoucherPayments, ...committedVoucherPayments, ...cappedVouchers];
2563
2580
  this.updateTempOrderPaymentStatus(tempOrder);
2564
2581
  this.persistTempOrder();
2565
2582
  void this.recalculateSummary({ createIfMissing: true }).catch((error) => {
@@ -3371,7 +3388,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3371
3388
  ...hasPaymentOverride ? {
3372
3389
  payments: preparedPaymentOverride || []
3373
3390
  } : {},
3374
- ...hasPaymentStatusOverride ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
3391
+ ...hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? { payment_status: params == null ? void 0 : params.paymentStatus } : {},
3375
3392
  ...hasSmallTicketDataFlagOverride ? { small_ticket_data_flag: params == null ? void 0 : params.smallTicketDataFlag } : {}
3376
3393
  };
3377
3394
  const enhancedPayload = (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(nextPayload, ctx) : nextPayload;
@@ -46,6 +46,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
46
46
  protected hasManualDiscountSelection: boolean;
47
47
  private readonly reusedSharedSubModuleNames;
48
48
  private paymentMethodsCache;
49
+ private queuedAutoPaymentSync;
50
+ private autoPaymentSyncFlushing;
51
+ private autoPaymentSyncTimer;
49
52
  constructor(name?: string, version?: string);
50
53
  /**
51
54
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -225,6 +228,10 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
225
228
  getOrderPayments(): OrderPaymentData[];
226
229
  /** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
227
230
  setOrderPayments(payments: OrderPaymentSource[]): OrderPaymentData[];
231
+ private getPaymentStatusForSync;
232
+ private queueLatestAutoPaymentSync;
233
+ private scheduleQueuedAutoPaymentSyncFlush;
234
+ private flushQueuedAutoPaymentSync;
228
235
  /** 追加单个支付项到当前订单。 */
229
236
  addOrderPayment(payment: OrderPaymentSource): OrderPaymentData[];
230
237
  /** 更新当前订单中的指定支付项。 */
@@ -156,6 +156,9 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
156
156
  this.hasManualDiscountSelection = false;
157
157
  this.reusedSharedSubModuleNames = /* @__PURE__ */ new Set();
158
158
  this.paymentMethodsCache = [];
159
+ this.queuedAutoPaymentSync = false;
160
+ this.autoPaymentSyncFlushing = false;
161
+ this.autoPaymentSyncTimer = null;
159
162
  }
160
163
  /**
161
164
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -1495,6 +1498,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1495
1498
  };
1496
1499
  const syncState = this.store.order.getOrderSyncState();
1497
1500
  if (params.submitWhenPaid && syncState === "submitting") {
1501
+ this.queueLatestAutoPaymentSync();
1498
1502
  return this.store.order.syncPaymentsToOrder(syncParams);
1499
1503
  }
1500
1504
  const payments = params.payments || [];
@@ -1527,6 +1531,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1527
1531
  if (syncResult.isDepositFullyPaid && !syncResult.isOrderFullyPaid) {
1528
1532
  await this.effectsEmit(import_types.BaseSalesHookNames.onDepositPaymentSyncEnd, syncPayload);
1529
1533
  }
1534
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
1530
1535
  return syncResult;
1531
1536
  } catch (error) {
1532
1537
  await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
@@ -1537,6 +1542,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1537
1542
  amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1538
1543
  orderSnapshot: this.store.order.getOrderSnapshot()
1539
1544
  });
1545
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
1540
1546
  throw error;
1541
1547
  }
1542
1548
  }
@@ -1553,6 +1559,61 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1553
1559
  throw new Error("order 模块未初始化");
1554
1560
  return this.store.order.setOrderPayments(payments);
1555
1561
  }
1562
+ getPaymentStatusForSync(payments) {
1563
+ const order = this.store.order;
1564
+ if (!order)
1565
+ throw new Error("order 模块未初始化");
1566
+ const completion = order.getPaymentCompletion(payments);
1567
+ return completion.isOrderFullyPaid ? "paid" : "partially_paid";
1568
+ }
1569
+ queueLatestAutoPaymentSync() {
1570
+ this.queuedAutoPaymentSync = true;
1571
+ this.scheduleQueuedAutoPaymentSyncFlush();
1572
+ }
1573
+ scheduleQueuedAutoPaymentSyncFlush(delay = 100) {
1574
+ if (!this.queuedAutoPaymentSync)
1575
+ return;
1576
+ if (this.autoPaymentSyncTimer)
1577
+ return;
1578
+ this.autoPaymentSyncTimer = setTimeout(() => {
1579
+ this.autoPaymentSyncTimer = null;
1580
+ void this.flushQueuedAutoPaymentSync();
1581
+ }, delay);
1582
+ }
1583
+ async flushQueuedAutoPaymentSync() {
1584
+ if (!this.store.order)
1585
+ return;
1586
+ if (!this.queuedAutoPaymentSync || this.autoPaymentSyncFlushing)
1587
+ return;
1588
+ if (this.store.order.getOrderSyncState() === "submitting") {
1589
+ this.scheduleQueuedAutoPaymentSyncFlush();
1590
+ return;
1591
+ }
1592
+ this.autoPaymentSyncFlushing = true;
1593
+ try {
1594
+ while (this.queuedAutoPaymentSync) {
1595
+ this.queuedAutoPaymentSync = false;
1596
+ const payments = this.store.order.getOrderPayments();
1597
+ if (!payments.length)
1598
+ continue;
1599
+ await this.syncPaymentsToOrder({
1600
+ payments,
1601
+ paymentStatus: this.getPaymentStatusForSync(payments),
1602
+ submitWhenPaid: true,
1603
+ smallTicketDataFlag: 1
1604
+ });
1605
+ }
1606
+ } catch (error) {
1607
+ this.logError("queued auto sync payments failed", {
1608
+ error: error instanceof Error ? error.message : String(error)
1609
+ });
1610
+ } finally {
1611
+ this.autoPaymentSyncFlushing = false;
1612
+ if (this.queuedAutoPaymentSync) {
1613
+ this.scheduleQueuedAutoPaymentSyncFlush(0);
1614
+ }
1615
+ }
1616
+ }
1556
1617
  /** 追加单个支付项到当前订单。 */
1557
1618
  addOrderPayment(payment) {
1558
1619
  var _a;
@@ -1588,12 +1649,14 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1588
1649
  });
1589
1650
  const amountSnapshot = this.store.order.getOrderAmountSnapshot();
1590
1651
  const syncState = this.store.order.getOrderSyncState();
1591
- if (amountSnapshot && syncState !== "submitting") {
1592
- const completion = this.store.order.getPaymentCompletion(payments);
1593
- const paymentStatus = completion.isOrderFullyPaid ? "paid" : "partially_paid";
1652
+ if (amountSnapshot) {
1653
+ if (syncState === "submitting") {
1654
+ this.queueLatestAutoPaymentSync();
1655
+ return payments;
1656
+ }
1594
1657
  void this.syncPaymentsToOrder({
1595
1658
  payments,
1596
- paymentStatus,
1659
+ paymentStatus: this.getPaymentStatusForSync(payments),
1597
1660
  submitWhenPaid: true,
1598
1661
  smallTicketDataFlag: 1
1599
1662
  }).catch((error) => {
@@ -1601,7 +1664,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1601
1664
  error: error instanceof Error ? error.message : String(error)
1602
1665
  });
1603
1666
  });
1604
- } else {
1605
1667
  }
1606
1668
  return payments;
1607
1669
  }
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.8",
4
+ "version": "2.3.9",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",