@pisell/pisellos 2.3.129 → 2.3.131

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.
Files changed (102) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/modules/BusinessAvailability/index.d.ts +30 -0
  4. package/dist/modules/BusinessAvailability/index.js +204 -0
  5. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  6. package/dist/modules/FulfillmentTiming/index.js +407 -0
  7. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  8. package/dist/modules/FulfillmentTiming/types.js +1 -0
  9. package/dist/modules/OpenData/types.d.ts +8 -0
  10. package/dist/modules/Order/index.d.ts +11 -2
  11. package/dist/modules/Order/index.js +370 -253
  12. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  13. package/dist/modules/Order/pickupTiming.js +53 -0
  14. package/dist/modules/Order/types.d.ts +13 -1
  15. package/dist/modules/Order/utils.js +16 -6
  16. package/dist/modules/Payment/index.js +9 -10
  17. package/dist/modules/Schedule/index.d.ts +8 -0
  18. package/dist/modules/Schedule/index.js +141 -39
  19. package/dist/modules/index.d.ts +1 -0
  20. package/dist/modules/index.js +1 -0
  21. package/dist/plugins/request.d.ts +7 -0
  22. package/dist/server/utils/small-ticket.d.ts +1 -85
  23. package/dist/server/utils/small-ticket.js +2 -2542
  24. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  25. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  26. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  27. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  28. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  29. package/dist/shared/receipt/small-ticket.js +2576 -0
  30. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  31. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  32. package/dist/solution/BaseSales/index.d.ts +28 -15
  33. package/dist/solution/BaseSales/index.js +1346 -1101
  34. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  35. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  36. package/dist/solution/BaseSales/types.d.ts +11 -0
  37. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  38. package/dist/solution/BookingByStep/index.d.ts +1 -1
  39. package/dist/solution/BookingTicket/index.d.ts +2 -2
  40. package/dist/solution/BookingTicket/index.js +41 -13
  41. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  42. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  43. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  44. package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  45. package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
  46. package/dist/solution/UnifiedBookingSales/index.d.ts +24 -4
  47. package/dist/solution/UnifiedBookingSales/index.js +953 -709
  48. package/dist/solution/UnifiedBookingSales/types.d.ts +2 -0
  49. package/dist/solution/index.d.ts +1 -0
  50. package/dist/solution/index.js +2 -1
  51. package/lib/index.d.ts +2 -0
  52. package/lib/index.js +21 -1
  53. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  54. package/lib/modules/BusinessAvailability/index.d.ts +30 -0
  55. package/lib/modules/BusinessAvailability/index.js +146 -0
  56. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  57. package/lib/modules/FulfillmentTiming/index.js +359 -0
  58. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  59. package/lib/modules/FulfillmentTiming/types.js +5 -0
  60. package/lib/modules/OpenData/types.d.ts +8 -0
  61. package/lib/modules/Order/index.d.ts +11 -2
  62. package/lib/modules/Order/index.js +101 -14
  63. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  64. package/lib/modules/Order/pickupTiming.js +61 -0
  65. package/lib/modules/Order/types.d.ts +13 -1
  66. package/lib/modules/Order/utils.js +12 -4
  67. package/lib/modules/Payment/index.js +3 -4
  68. package/lib/modules/Schedule/index.d.ts +8 -0
  69. package/lib/modules/Schedule/index.js +68 -12
  70. package/lib/modules/index.d.ts +1 -0
  71. package/lib/modules/index.js +11 -0
  72. package/lib/plugins/request.d.ts +7 -0
  73. package/lib/server/utils/small-ticket.d.ts +1 -85
  74. package/lib/server/utils/small-ticket.js +9 -2305
  75. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  76. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  77. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  78. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  79. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  80. package/lib/shared/receipt/small-ticket.js +2342 -0
  81. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  82. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  83. package/lib/solution/BaseSales/index.d.ts +28 -15
  84. package/lib/solution/BaseSales/index.js +161 -25
  85. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  86. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  87. package/lib/solution/BaseSales/types.d.ts +11 -0
  88. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  89. package/lib/solution/BookingByStep/index.d.ts +1 -1
  90. package/lib/solution/BookingTicket/index.d.ts +2 -2
  91. package/lib/solution/BookingTicket/index.js +37 -4
  92. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  93. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  94. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  95. package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
  96. package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
  97. package/lib/solution/UnifiedBookingSales/index.d.ts +24 -4
  98. package/lib/solution/UnifiedBookingSales/index.js +184 -46
  99. package/lib/solution/UnifiedBookingSales/types.d.ts +2 -0
  100. package/lib/solution/index.d.ts +1 -0
  101. package/lib/solution/index.js +11 -0
  102. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ import type { RequestPlugin } from '../../plugins/request';
2
+ export declare const SALES_ORDER_RELATIONS: string[];
3
+ /** Shared transport contract; remote callers use their host's /h5 prefix. */
4
+ export declare function loadSalesOrderSnapshot(request: RequestPlugin, params: {
5
+ lookup: string | number;
6
+ transport: 'remote' | 'os-server';
7
+ forceRemote?: boolean;
8
+ with?: string[];
9
+ }): Promise<any>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SALES_ORDER_RELATIONS = void 0;
7
+ exports.loadSalesOrderSnapshot = loadSalesOrderSnapshot;
8
+ const SALES_ORDER_RELATIONS = exports.SALES_ORDER_RELATIONS = ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'order_meta_list', 'refunds', 'notes'];
9
+
10
+ /** Shared transport contract; remote callers use their host's /h5 prefix. */
11
+ function loadSalesOrderSnapshot(request, params) {
12
+ const lookup = String(params.lookup ?? '').trim();
13
+ if (!lookup) throw new Error('加载销售详情需要 lookup');
14
+ return request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
15
+ with: params.with ?? SALES_ORDER_RELATIONS,
16
+ ...(params.forceRemote && !lookup.startsWith('LOCAL_') ? {
17
+ forceRemote: true
18
+ } : {})
19
+ }, params.transport === 'os-server' ? {
20
+ osServer: true
21
+ } : undefined);
22
+ }
@@ -1,7 +1,9 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
- import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, BaseSalesUpdateOrderProductQuantityParams, BaseSalesCalculateProductBookingPriceParams, BaseSalesPriceRecalculationContextChange, BaseSalesProductBookingPriceResult, BaseSalesQuotationCustomerScopeInfo, BaseSalesScanCodeResult, BaseSalesCashPaymentOptions, BaseSalesCashPaymentConfig, BaseSalesPayCashParams, BaseSalesPayCashResult, BaseSalesCommitPaymentMethodParams, BaseSalesCommitPaymentMethodResult, BaseSalesConfirmWalletPaymentResult } from './types';
3
+ import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, BaseSalesSubmitSalesOrderParams, BaseSalesUpdateOrderProductQuantityParams, BaseSalesCalculateProductBookingPriceParams, BaseSalesPriceRecalculationContextChange, BaseSalesProductBookingPriceResult, BaseSalesQuotationCustomerScopeInfo, BaseSalesScanCodeResult, BaseSalesCashPaymentOptions, BaseSalesCashPaymentConfig, BaseSalesPayCashParams, BaseSalesPayCashResult, BaseSalesCommitPaymentMethodParams, BaseSalesCommitPaymentMethodResult, BaseSalesConfirmWalletPaymentResult } from './types';
4
4
  import { OrderModule } from '../../modules/Order';
5
+ import { type PickupTimingBookingInput } from '../../modules/Order/pickupTiming';
6
+ import type { PickupTimingAvailability, PickupTimingSelection, PickupTimingValidationResult } from '../../modules/FulfillmentTiming';
5
7
  import type { AddProductBookingInput, AddProductToOrderOptions, LoadSalesDetailParams, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, OrderPaymentSource, SendCustomerPayLinkParams, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, UpdateTempOrderCustomerInput, UpdateOrderBookingParams, UpdateOrderProductParams, OrderTempOrder, OrderSummary, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, ReplaceTempOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, ShopServiceData, ShopServiceType } from '../../modules/Order/types';
6
8
  import type { SubmitPayloadEnhancer } from '../../modules/Order/utils';
7
9
  import type { Discount, VirtualCurrencyAsset } from '../../modules/Discount/types';
@@ -76,6 +78,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
76
78
  private serverOrderChangeHydrateInFlight;
77
79
  private queuedServerOrderChanges;
78
80
  private serverOrderChangeSyncEnabled;
81
+ protected pickupTimingEnabled: boolean;
82
+ private pickupTimingController?;
79
83
  constructor(name?: string, version?: string);
80
84
  /**
81
85
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
@@ -153,6 +157,23 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
153
157
  private getAuthoritativeBundleUnitPrice;
154
158
  private mergeProductForPriceQuery;
155
159
  protected getSubmitOrderSalesChannel(): string | undefined;
160
+ /** Only solutions opting into Pickup Timing supply effective OpenData. */
161
+ protected loadPickupTimingOpenData(_force: boolean): Promise<Record<string, unknown>>;
162
+ protected isPickupTimingEnabled(): boolean;
163
+ protected getPickupTimingContextData(key: string): unknown;
164
+ protected getPickupTimingScope(): string;
165
+ protected resetPickupTimingCache(): void;
166
+ private getPickupTimingController;
167
+ getPickupTimingAvailability(params?: {
168
+ date?: string;
169
+ force?: boolean;
170
+ }): Promise<PickupTimingAvailability>;
171
+ getPickupTimingSelection(): PickupTimingSelection;
172
+ setPickupTimingSelection(selection: PickupTimingSelection): Promise<PickupTimingSelection>;
173
+ validatePickupTimingSelection(selection: PickupTimingSelection): Promise<PickupTimingValidationResult>;
174
+ preparePickupTimingForCheckout(options?: {
175
+ freeze?: boolean;
176
+ }): Promise<PickupTimingSelection>;
156
177
  /** Subclasses with target-scoped OpenData override this guard before reusing the cache. */
157
178
  protected isInvoiceOpenDataCacheCurrent(): boolean;
158
179
  private getFulfillmentRefModeConfigs;
@@ -250,6 +271,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
250
271
  updateTempOrderDepositAmount(amount: string | number): OrderSummary;
251
272
  setPickupReferenceMode(mode: PickupReferenceMode): ShopServiceData;
252
273
  setServiceType(serviceType: ShopServiceType): ShopServiceData;
274
+ getPickupTimingBooking(): import("../../modules/Order").PickupTimingBooking | null;
275
+ setPickupTimingBooking(input: PickupTimingBookingInput): import("../../modules/Order").PickupTimingBooking;
276
+ clearPickupTimingBooking(): void;
253
277
  updateTempOrderContactsInfo(contactsInfo: Record<string, any> | null): Record<string, any> | null;
254
278
  /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
255
279
  setEnableTempOrderPersist(enabled: boolean): void;
@@ -315,13 +339,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
315
339
  productList?: Record<string, any>[];
316
340
  discountList?: Discount[];
317
341
  }): Promise<void>;
318
- submitScanOrder<T = any>(params?: {
319
- payments?: OrderPaymentSource[];
320
- paymentStatus?: BaseSalesPaymentStatus;
321
- smallTicketDataFlag?: number;
322
- confirmPendingVoucherPayments?: boolean;
323
- enhancePayload?: SubmitPayloadEnhancer;
324
- }): Promise<T>;
342
+ submitScanOrder<T = any>(params?: BaseSalesSubmitSalesOrderParams): Promise<T>;
343
+ private buildVirtualSettlementOrderData;
325
344
  private buildVirtualSettlementSubmitData;
326
345
  /**
327
346
  * 提交当前 Sales 订单。
@@ -329,13 +348,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
329
348
  * PaymentModal 场景通过 smallTicketDataFlag=1 请求 B 端小票数据;
330
349
  * payments 会交给 OrderModule 统一映射为 Sales 协议支付项。
331
350
  */
332
- submitSalesOrder<T = any>(params?: {
333
- payments?: OrderPaymentSource[];
334
- paymentStatus?: BaseSalesPaymentStatus;
335
- smallTicketDataFlag?: number;
336
- confirmPendingVoucherPayments?: boolean;
337
- enhancePayload?: SubmitPayloadEnhancer;
338
- }): Promise<T>;
351
+ submitSalesOrder<T = any>(params?: BaseSalesSubmitSalesOrderParams): Promise<T>;
339
352
  saveSalesOrderDraft<T = any>(params?: {
340
353
  platform?: string;
341
354
  businessCode?: string;
@@ -21,6 +21,8 @@ Object.keys(_types).forEach(function (key) {
21
21
  });
22
22
  });
23
23
  var _Order = require("../../modules/Order");
24
+ var _pickupTiming = require("../../modules/Order/pickupTiming");
25
+ var _pickupTiming2 = require("./pickupTiming");
24
26
  var _decimal = _interopRequireDefault(require("decimal.js"));
25
27
  var _lodashEs = require("lodash-es");
26
28
  var _types2 = require("../BookingByStep/types");
@@ -499,6 +501,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
499
501
  serverOrderChangeHydrateInFlight = null;
500
502
  queuedServerOrderChanges = [];
501
503
  serverOrderChangeSyncEnabled = false;
504
+ pickupTimingEnabled = false;
505
+ pickupTimingController;
502
506
  constructor(name, version) {
503
507
  super(name, version);
504
508
  }
@@ -1157,6 +1161,69 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1157
1161
  return this.otherParams?.channel;
1158
1162
  }
1159
1163
 
1164
+ /** Only solutions opting into Pickup Timing supply effective OpenData. */
1165
+ async loadPickupTimingOpenData(_force) {
1166
+ return {};
1167
+ }
1168
+ isPickupTimingEnabled() {
1169
+ return this.pickupTimingEnabled && this.otherParams?.enablePickupTiming !== false;
1170
+ }
1171
+ getPickupTimingContextData(key) {
1172
+ const context = this.core?.context;
1173
+ const getData = context?.getData;
1174
+ return typeof getData === 'function' ? getData.call(context, key) : undefined;
1175
+ }
1176
+ getPickupTimingScope() {
1177
+ return JSON.stringify({
1178
+ shop: this.getPickupTimingContextData('shop_id'),
1179
+ businessCode: this.otherParams?.businessCode ?? this.otherParams?.business_code,
1180
+ channel: this.getSubmitOrderSalesChannel(),
1181
+ timezone: this.getPickupTimingContextData('timezone'),
1182
+ platform: (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform),
1183
+ cacheId: this.cacheId
1184
+ });
1185
+ }
1186
+ resetPickupTimingCache() {
1187
+ this.pickupTimingController?.invalidate();
1188
+ }
1189
+ getPickupTimingController() {
1190
+ if (!this.pickupTimingController) {
1191
+ this.pickupTimingController = new _pickupTiming2.PickupTimingController({
1192
+ getOrder: () => {
1193
+ if (!this.store.order) throw new Error('order 模块未初始化');
1194
+ return this.store.order;
1195
+ },
1196
+ getSchedule: () => this.store.schedule,
1197
+ loadOpenData: force => this.loadPickupTimingOpenData(force),
1198
+ getTimezone: () => String(this.getPickupTimingContextData('timezone') ?? ''),
1199
+ getScope: () => this.getPickupTimingScope(),
1200
+ isPos: () => (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos'
1201
+ });
1202
+ }
1203
+ return this.pickupTimingController;
1204
+ }
1205
+ getPickupTimingAvailability(params) {
1206
+ return this.getPickupTimingController().getAvailability(params);
1207
+ }
1208
+ getPickupTimingSelection() {
1209
+ return this.getPickupTimingController().getSelection();
1210
+ }
1211
+ setPickupTimingSelection(selection) {
1212
+ return this.getPickupTimingController().setSelection(selection);
1213
+ }
1214
+ validatePickupTimingSelection(selection) {
1215
+ return this.getPickupTimingController().validate(selection);
1216
+ }
1217
+ preparePickupTimingForCheckout(options) {
1218
+ if (!this.isPickupTimingEnabled()) {
1219
+ return Promise.resolve({
1220
+ serviceType: String(this.getTempOrder()?.metadata?.shop_service_data?.service_type || ''),
1221
+ mode: 'asap'
1222
+ });
1223
+ }
1224
+ return this.getPickupTimingController().prepare(options);
1225
+ }
1226
+
1160
1227
  /** Subclasses with target-scoped OpenData override this guard before reusing the cache. */
1161
1228
  isInvoiceOpenDataCacheCurrent() {
1162
1229
  return true;
@@ -1438,6 +1505,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1438
1505
  return isChanged;
1439
1506
  }
1440
1507
  async initialize(core, options = {}) {
1508
+ this.resetPickupTimingCache();
1441
1509
  this.core = core;
1442
1510
  this.initializeOptions = options || {};
1443
1511
  this.paymentNumberDevicePrefix = null;
@@ -1490,6 +1558,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1490
1558
  this.core.effects.emit(`${this.name}:onInited`, {});
1491
1559
  }
1492
1560
  async destroy() {
1561
+ this.resetPickupTimingCache();
1493
1562
  this.serverOrderChangeUnsubscribe?.();
1494
1563
  this.serverOrderChangeUnsubscribe = null;
1495
1564
  this.paymentMethodsChangedUnsubscribe?.();
@@ -1589,9 +1658,12 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1589
1658
  /** 获取根 booking(is_next === 0 / is_root === 1),多个时取第一个。 */
1590
1659
  getRootBooking() {
1591
1660
  if (!this.currentSalesDetail) return null;
1592
- if (this.currentSalesDetail.rootBooking) return this.currentSalesDetail.rootBooking;
1661
+ if (this.currentSalesDetail.rootBooking && !(0, _pickupTiming.isFulfillmentTimingBooking)(this.currentSalesDetail.rootBooking)) {
1662
+ return this.currentSalesDetail.rootBooking;
1663
+ }
1593
1664
  const bookings = this.currentSalesDetail.bookings || [];
1594
1665
  return bookings.find(booking => {
1666
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return false;
1595
1667
  const parentId = booking?.parent_id;
1596
1668
  return parentId === 0 || parentId === null || parentId === undefined;
1597
1669
  }) || null;
@@ -1708,6 +1780,16 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1708
1780
  if (!this.store.order) throw new Error('order 模块未初始化');
1709
1781
  return this.store.order.updateTempOrderServiceType(serviceType);
1710
1782
  }
1783
+ getPickupTimingBooking() {
1784
+ return this.store.order?.getPickupTimingBooking() || null;
1785
+ }
1786
+ setPickupTimingBooking(input) {
1787
+ if (!this.store.order) throw new Error('order 模块未初始化');
1788
+ return this.store.order.setPickupTimingBooking(input);
1789
+ }
1790
+ clearPickupTimingBooking() {
1791
+ this.store.order?.clearPickupTimingBooking();
1792
+ }
1711
1793
  updateTempOrderContactsInfo(contactsInfo) {
1712
1794
  if (!this.store.order) throw new Error('order 模块未初始化');
1713
1795
  return this.store.order.updateTempOrderContactsInfo(contactsInfo);
@@ -2402,7 +2484,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2402
2484
  // Deprecated compatibility alias. New BaseSales callers should use submitSalesOrder.
2403
2485
  return this.submitSalesOrder(params);
2404
2486
  }
2405
- async buildVirtualSettlementSubmitData() {
2487
+ buildVirtualSettlementOrderData() {
2406
2488
  if (!this.store.order) return null;
2407
2489
  const tempOrder = this.store.order.getTempOrder();
2408
2490
  if (!this.isActiveVirtualSettlementOrder(tempOrder)) return null;
@@ -2411,6 +2493,21 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2411
2493
  if (!snapshot || !Number.isFinite(currencyProductId) || currencyProductId <= 0) {
2412
2494
  throw new Error('Virtual currency settlement configuration is invalid.');
2413
2495
  }
2496
+ return {
2497
+ snapshot,
2498
+ currencyProductId,
2499
+ currencyCode: String(tempOrder?.currency_code || ''),
2500
+ currencySymbol: String(tempOrder?.currency_symbol || ''),
2501
+ currencyFormat: String(tempOrder?.currency_format || 'symbol_first')
2502
+ };
2503
+ }
2504
+ async buildVirtualSettlementSubmitData() {
2505
+ const settlement = this.buildVirtualSettlementOrderData();
2506
+ if (!settlement || !this.store.order) return null;
2507
+ const tempOrder = this.store.order.getTempOrder();
2508
+ const {
2509
+ currencyProductId
2510
+ } = settlement;
2414
2511
  const summary = await this.store.order.recalculateSummary({
2415
2512
  createIfMissing: true
2416
2513
  });
@@ -2425,17 +2522,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2425
2522
  });
2426
2523
  }
2427
2524
  const asset = this.store.order.getVirtualCurrencyList().find(item => Number(item?.product_id) === currencyProductId);
2428
- const currencyCode = String(tempOrder?.currency_code || '');
2429
- const currencySymbol = String(tempOrder?.currency_symbol || '');
2430
- const currencyFormat = String(tempOrder?.currency_format || 'symbol_first');
2431
2525
  if (amount.lte(0)) {
2432
2526
  return {
2433
- payments: [],
2434
- snapshot,
2435
- currencyProductId,
2436
- currencyCode,
2437
- currencySymbol,
2438
- currencyFormat
2527
+ ...settlement,
2528
+ payments: []
2439
2529
  };
2440
2530
  }
2441
2531
  if (!asset) {
@@ -2489,12 +2579,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2489
2579
  };
2490
2580
  }
2491
2581
  return {
2492
- payments: [payment],
2493
- snapshot,
2494
- currencyProductId,
2495
- currencyCode,
2496
- currencySymbol,
2497
- currencyFormat
2582
+ ...settlement,
2583
+ payments: [payment]
2498
2584
  };
2499
2585
  }
2500
2586
 
@@ -2508,11 +2594,48 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2508
2594
  if (!this.store.order) {
2509
2595
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2510
2596
  }
2511
- const virtualSettlement = await this.buildVirtualSettlementSubmitData();
2597
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2598
+ freeze: true
2599
+ });
2600
+ const isDeferredPayment = params?.paymentExecution === 'deferred';
2601
+ const virtualPaymentSettlement = isDeferredPayment ? null : await this.buildVirtualSettlementSubmitData();
2602
+ const virtualSettlement = isDeferredPayment ? this.buildVirtualSettlementOrderData() : virtualPaymentSettlement;
2512
2603
  // this.store.order.persistTempOrder();
2513
- const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
2604
+ const inferredPaymentStatus = isDeferredPayment ? undefined : this.getSubmitPaymentStatus(params?.paymentStatus);
2514
2605
  const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
2515
- const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params?.enhancePayload);
2606
+ const virtualSettlementEnhancePayload = virtualSettlement ? (payload, ctx) => {
2607
+ const callerPayload = params?.enhancePayload ? params.enhancePayload(payload, ctx) : payload;
2608
+ const currencySettlementConfig = callerPayload.metadata?.currency_settlement_config || {};
2609
+ return {
2610
+ ...callerPayload,
2611
+ metadata: {
2612
+ ...(callerPayload.metadata || {}),
2613
+ currency_settlement_config: {
2614
+ ...currencySettlementConfig,
2615
+ settlement_type: 'virtual_currency',
2616
+ settlement_ids: [virtualSettlement.currencyProductId],
2617
+ currency_display_snapshot: (0, _lodashEs.cloneDeep)(currencySettlementConfig.currency_display_snapshot ?? (0, _virtualSettlement.buildCurrencyDisplaySnapshot)(virtualSettlement.snapshot))
2618
+ }
2619
+ },
2620
+ currency_code: virtualSettlement.currencyCode,
2621
+ currency_symbol: virtualSettlement.currencySymbol,
2622
+ currency_format: virtualSettlement.currencyFormat
2623
+ };
2624
+ } : params?.enhancePayload;
2625
+ const configuredEnhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(virtualSettlementEnhancePayload);
2626
+ // Apply this last so neither a stale draft status nor a caller enhancer can
2627
+ // turn deferred submission into payment. The live wallet selection is untouched.
2628
+ const enhancePayload = isDeferredPayment ? (payload, ctx) => {
2629
+ const enhancedPayload = configuredEnhancePayload ? configuredEnhancePayload(payload, ctx) : payload;
2630
+ const {
2631
+ payment_status: _paymentStatus,
2632
+ ...orderPayload
2633
+ } = enhancedPayload;
2634
+ return {
2635
+ ...orderPayload,
2636
+ payments: []
2637
+ };
2638
+ } : configuredEnhancePayload;
2516
2639
  const submitParams = {
2517
2640
  cacheId: this.cacheId,
2518
2641
  platform: this.otherParams?.platform,
@@ -2520,8 +2643,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2520
2643
  channel: this.getSubmitOrderSalesChannel(),
2521
2644
  type: this.otherParams?.type,
2522
2645
  request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
2523
- ...(virtualSettlement ? {
2524
- payments: virtualSettlement.payments
2646
+ ...(isDeferredPayment ? {
2647
+ payments: []
2648
+ } : virtualPaymentSettlement ? {
2649
+ payments: virtualPaymentSettlement.payments
2525
2650
  } : params?.payments !== undefined ? {
2526
2651
  payments: params.payments
2527
2652
  } : {}),
@@ -2531,7 +2656,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2531
2656
  ...(smallTicketDataFlag !== undefined ? {
2532
2657
  smallTicketDataFlag
2533
2658
  } : {}),
2534
- ...(virtualSettlement ? {
2659
+ ...(isDeferredPayment || virtualSettlement ? {
2535
2660
  confirmPendingVoucherPayments: false
2536
2661
  } : params?.confirmPendingVoucherPayments !== undefined ? {
2537
2662
  confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
@@ -2566,6 +2691,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2566
2691
  if (!this.store.order) {
2567
2692
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2568
2693
  }
2694
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2695
+ freeze: false
2696
+ });
2569
2697
  return this.store.order.saveTempOrderAsDraft({
2570
2698
  cacheId: this.cacheId,
2571
2699
  platform: params?.platform ?? this.otherParams?.platform,
@@ -2581,6 +2709,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2581
2709
  if (!this.store.order) {
2582
2710
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2583
2711
  }
2712
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2713
+ freeze: true
2714
+ });
2584
2715
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
2585
2716
  const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
2586
2717
  const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params?.enhancePayload);
@@ -3508,6 +3639,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3508
3639
  if (!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount) {
3509
3640
  throw new Error('顾客实收现金不能小于支付金额');
3510
3641
  }
3642
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
3643
+ freeze: true
3644
+ });
3511
3645
  this.window?.interaction?.utils?.postMessageToApp?.({
3512
3646
  module: 'till',
3513
3647
  key: 'open_till',
@@ -3887,7 +4021,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3887
4021
  async addProductToOrder(product, booking, options) {
3888
4022
  try {
3889
4023
  if (!this.store.order) throw new Error('order 模块未初始化');
3890
- const products = await this.store.order.addProductToOrder(product, booking, options);
4024
+ const products = options === undefined ? await this.store.order.addProductToOrder(product, booking) : await this.store.order.addProductToOrder(product, booking, options);
3891
4025
  // // 需要叠加
3892
4026
  // if (this.hooks.onAddProductOverlay) {
3893
4027
  // const res = this.hooks.onAddProductOverlay(是否叠加, product)
@@ -3976,7 +4110,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3976
4110
  async removeProductsFromOrder(identities, options) {
3977
4111
  try {
3978
4112
  if (!this.store.order) throw new Error('order 模块未初始化');
3979
- return await this.store.order.removeProductsFromOrder(identities, options);
4113
+ return options === undefined ? await this.store.order.removeProductsFromOrder(identities) : await this.store.order.removeProductsFromOrder(identities, options);
3980
4114
  } catch (error) {
3981
4115
  throw error;
3982
4116
  }
@@ -4061,6 +4195,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4061
4195
  async setOtherParams(params, {
4062
4196
  cover = false
4063
4197
  } = {}) {
4198
+ const previousPickupTimingScope = this.getPickupTimingScope();
4064
4199
  if (cover) {
4065
4200
  this.otherParams = {
4066
4201
  ...params
@@ -4072,6 +4207,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4072
4207
  };
4073
4208
  }
4074
4209
  this.cacheId = this.otherParams?.cacheId;
4210
+ if (previousPickupTimingScope !== this.getPickupTimingScope()) this.resetPickupTimingCache();
4075
4211
  await this.syncOtherParamsToSubModules(params, {
4076
4212
  cover
4077
4213
  });
@@ -0,0 +1,43 @@
1
+ import type { OrderModule } from '../../modules/Order';
2
+ import type { ScheduleModule } from '../../modules/Schedule';
3
+ import { type PickupTimingAvailability, type PickupTimingSelection, type PickupTimingValidationResult } from '../../modules/FulfillmentTiming';
4
+ interface PickupTimingHost {
5
+ getOrder: () => OrderModule;
6
+ getSchedule: () => ScheduleModule | undefined;
7
+ loadOpenData: (force: boolean) => Promise<Record<string, unknown>>;
8
+ getTimezone: () => string;
9
+ getScope: () => string;
10
+ isPos: () => boolean;
11
+ now?: () => Date;
12
+ }
13
+ /** Reuses runtime configuration and schedules; every calculation still uses the live clock. */
14
+ export declare class PickupTimingController {
15
+ private readonly host;
16
+ private latest?;
17
+ private runtime?;
18
+ private writeSequence;
19
+ constructor(host: PickupTimingHost);
20
+ private now;
21
+ /** A new solution context or an explicit settings refresh invalidates pending work too. */
22
+ invalidate(): void;
23
+ private assertCurrentRuntime;
24
+ private getRuntime;
25
+ private loadConfig;
26
+ private loadSchedules;
27
+ private snapshot;
28
+ getAvailability(params?: {
29
+ date?: string;
30
+ force?: boolean;
31
+ }): Promise<PickupTimingAvailability>;
32
+ getSelection(): PickupTimingSelection;
33
+ private validateSnapshot;
34
+ validate(selection: PickupTimingSelection): Promise<PickupTimingValidationResult>;
35
+ setSelection(selection: PickupTimingSelection, options?: {
36
+ frozen?: boolean;
37
+ }): Promise<PickupTimingSelection>;
38
+ /** Called before a new checkout/payment; payment callbacks keep their already prepared appointment. */
39
+ prepare(options?: {
40
+ freeze?: boolean;
41
+ }): Promise<PickupTimingSelection>;
42
+ }
43
+ export {};