@pisell/pisellos 2.3.129 → 2.3.130

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 (87) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  4. package/dist/modules/FulfillmentTiming/index.js +407 -0
  5. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  6. package/dist/modules/FulfillmentTiming/types.js +1 -0
  7. package/dist/modules/OpenData/types.d.ts +6 -0
  8. package/dist/modules/Order/index.d.ts +6 -0
  9. package/dist/modules/Order/index.js +55 -12
  10. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  11. package/dist/modules/Order/pickupTiming.js +53 -0
  12. package/dist/modules/Order/types.d.ts +5 -1
  13. package/dist/modules/Order/utils.js +16 -6
  14. package/dist/modules/Payment/index.js +9 -10
  15. package/dist/modules/Schedule/index.d.ts +8 -0
  16. package/dist/modules/Schedule/index.js +141 -39
  17. package/dist/modules/index.d.ts +1 -0
  18. package/dist/modules/index.js +1 -0
  19. package/dist/plugins/request.d.ts +7 -0
  20. package/dist/server/utils/small-ticket.d.ts +1 -85
  21. package/dist/server/utils/small-ticket.js +2 -2542
  22. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  23. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  24. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  25. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  26. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  27. package/dist/shared/receipt/small-ticket.js +2576 -0
  28. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  29. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  30. package/dist/solution/BaseSales/index.d.ts +24 -0
  31. package/dist/solution/BaseSales/index.js +1221 -1038
  32. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  33. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  34. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  35. package/dist/solution/BookingByStep/index.d.ts +1 -1
  36. package/dist/solution/BookingTicket/index.d.ts +3 -3
  37. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  38. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  39. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  40. package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
  41. package/dist/solution/UnifiedBookingSales/index.js +872 -707
  42. package/dist/solution/index.d.ts +1 -0
  43. package/dist/solution/index.js +2 -1
  44. package/lib/index.d.ts +2 -0
  45. package/lib/index.js +21 -1
  46. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  47. package/lib/modules/FulfillmentTiming/index.js +359 -0
  48. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  49. package/lib/modules/FulfillmentTiming/types.js +5 -0
  50. package/lib/modules/OpenData/types.d.ts +6 -0
  51. package/lib/modules/Order/index.d.ts +6 -0
  52. package/lib/modules/Order/index.js +39 -8
  53. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  54. package/lib/modules/Order/pickupTiming.js +61 -0
  55. package/lib/modules/Order/types.d.ts +5 -1
  56. package/lib/modules/Order/utils.js +12 -4
  57. package/lib/modules/Payment/index.js +3 -4
  58. package/lib/modules/Schedule/index.d.ts +8 -0
  59. package/lib/modules/Schedule/index.js +68 -12
  60. package/lib/modules/index.d.ts +1 -0
  61. package/lib/modules/index.js +11 -0
  62. package/lib/plugins/request.d.ts +7 -0
  63. package/lib/server/utils/small-ticket.d.ts +1 -85
  64. package/lib/server/utils/small-ticket.js +9 -2305
  65. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  66. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  67. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  68. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  69. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  70. package/lib/shared/receipt/small-ticket.js +2342 -0
  71. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  72. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  73. package/lib/solution/BaseSales/index.d.ts +24 -0
  74. package/lib/solution/BaseSales/index.js +97 -1
  75. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  76. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  77. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  78. package/lib/solution/BookingByStep/index.d.ts +1 -1
  79. package/lib/solution/BookingTicket/index.d.ts +3 -3
  80. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  81. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  82. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  83. package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
  84. package/lib/solution/UnifiedBookingSales/index.js +130 -46
  85. package/lib/solution/index.d.ts +1 -0
  86. package/lib/solution/index.js +11 -0
  87. 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
+ }
@@ -2,6 +2,8 @@ import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, 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;
@@ -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);
@@ -2508,6 +2590,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2508
2590
  if (!this.store.order) {
2509
2591
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2510
2592
  }
2593
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2594
+ freeze: true
2595
+ });
2511
2596
  const virtualSettlement = await this.buildVirtualSettlementSubmitData();
2512
2597
  // this.store.order.persistTempOrder();
2513
2598
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
@@ -2566,6 +2651,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2566
2651
  if (!this.store.order) {
2567
2652
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2568
2653
  }
2654
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2655
+ freeze: false
2656
+ });
2569
2657
  return this.store.order.saveTempOrderAsDraft({
2570
2658
  cacheId: this.cacheId,
2571
2659
  platform: params?.platform ?? this.otherParams?.platform,
@@ -2581,6 +2669,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2581
2669
  if (!this.store.order) {
2582
2670
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2583
2671
  }
2672
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2673
+ freeze: true
2674
+ });
2584
2675
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
2585
2676
  const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
2586
2677
  const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params?.enhancePayload);
@@ -3508,6 +3599,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3508
3599
  if (!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount) {
3509
3600
  throw new Error('顾客实收现金不能小于支付金额');
3510
3601
  }
3602
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
3603
+ freeze: true
3604
+ });
3511
3605
  this.window?.interaction?.utils?.postMessageToApp?.({
3512
3606
  module: 'till',
3513
3607
  key: 'open_till',
@@ -4061,6 +4155,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4061
4155
  async setOtherParams(params, {
4062
4156
  cover = false
4063
4157
  } = {}) {
4158
+ const previousPickupTimingScope = this.getPickupTimingScope();
4064
4159
  if (cover) {
4065
4160
  this.otherParams = {
4066
4161
  ...params
@@ -4072,6 +4167,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4072
4167
  };
4073
4168
  }
4074
4169
  this.cacheId = this.otherParams?.cacheId;
4170
+ if (previousPickupTimingScope !== this.getPickupTimingScope()) this.resetPickupTimingCache();
4075
4171
  await this.syncOtherParamsToSubModules(params, {
4076
4172
  cover
4077
4173
  });
@@ -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 {};
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PickupTimingController = void 0;
7
+ var _lodashEs = require("lodash-es");
8
+ var _FulfillmentTiming = require("../../modules/FulfillmentTiming");
9
+ async function withTimeout(request) {
10
+ let timer;
11
+ try {
12
+ return await Promise.race([request, new Promise((_, reject) => {
13
+ timer = setTimeout(() => reject(new Error('Unable to load pickup times. Please try again.')), 30000);
14
+ })]);
15
+ } finally {
16
+ if (timer !== undefined) clearTimeout(timer);
17
+ }
18
+ }
19
+
20
+ /** Reuses runtime configuration and schedules; every calculation still uses the live clock. */
21
+ class PickupTimingController {
22
+ latest;
23
+ runtime;
24
+ writeSequence = 0;
25
+ constructor(host) {
26
+ this.host = host;
27
+ }
28
+ now() {
29
+ return this.host.now?.() ?? new Date();
30
+ }
31
+
32
+ /** A new solution context or an explicit settings refresh invalidates pending work too. */
33
+ invalidate() {
34
+ this.runtime = undefined;
35
+ this.latest = undefined;
36
+ this.writeSequence += 1;
37
+ }
38
+ assertCurrentRuntime(runtime) {
39
+ if (this.runtime !== runtime || runtime.scope !== this.host.getScope()) {
40
+ throw new Error('Store settings changed. Please try again.');
41
+ }
42
+ }
43
+ getRuntime() {
44
+ const scope = this.host.getScope();
45
+ if (this.runtime?.scope !== scope) {
46
+ this.latest = undefined;
47
+ this.runtime = {
48
+ scope
49
+ };
50
+ }
51
+ return this.runtime;
52
+ }
53
+ async loadConfig(runtime) {
54
+ if (runtime.config) return runtime.config;
55
+ if (!runtime.configRequest) {
56
+ const request = (async () => {
57
+ const config = (0, _FulfillmentTiming.normalizePickupTimingConfig)(await withTimeout(this.host.loadOpenData(false)));
58
+ this.assertCurrentRuntime(runtime);
59
+ runtime.config = config;
60
+ return config;
61
+ })();
62
+ runtime.configRequest = request;
63
+ }
64
+ const request = runtime.configRequest;
65
+ try {
66
+ return await request;
67
+ } finally {
68
+ if (runtime.configRequest === request) runtime.configRequest = undefined;
69
+ }
70
+ }
71
+ async loadSchedules(runtime, config) {
72
+ if (runtime.schedules) return runtime.schedules;
73
+ if (!runtime.scheduleRequest) {
74
+ const request = (async () => {
75
+ const schedule = this.host.getSchedule();
76
+ if (!schedule) throw new Error('Pickup schedule is unavailable. Please try again.');
77
+ // Reuse the catalog loaded by solution initialization, including its in-flight request.
78
+ await withTimeout(schedule.loadAllSchedule({
79
+ useCache: true
80
+ }));
81
+ this.assertCurrentRuntime(runtime);
82
+ const ids = [...new Set([...config.scheduleIds, ...(config.operatingHoursScheduleIds || [])])];
83
+ const schedules = (0, _lodashEs.cloneDeep)(schedule.getScheduleListByIds(ids) || []);
84
+ runtime.schedules = schedules;
85
+ return schedules;
86
+ })();
87
+ runtime.scheduleRequest = request;
88
+ }
89
+ const request = runtime.scheduleRequest;
90
+ try {
91
+ return await request;
92
+ } finally {
93
+ if (runtime.scheduleRequest === request) runtime.scheduleRequest = undefined;
94
+ }
95
+ }
96
+ async snapshot(includeSchedule, tolerateScheduleError = false) {
97
+ const runtime = this.getRuntime();
98
+ const config = await this.loadConfig(runtime);
99
+ this.assertCurrentRuntime(runtime);
100
+ let schedules = [];
101
+ let error;
102
+ if (includeSchedule && config.handoverModes.includes('pick_up') && config.timingMode !== 'asap_only' && config.scheduleIds.length) {
103
+ try {
104
+ schedules = await this.loadSchedules(runtime, config);
105
+ } catch (reason) {
106
+ if (!tolerateScheduleError) throw reason;
107
+ error = reason instanceof Error ? reason.message : 'Pickup schedule is unavailable. Please try again.';
108
+ }
109
+ }
110
+ this.assertCurrentRuntime(runtime);
111
+ const result = {
112
+ config,
113
+ timezone: this.host.getTimezone(),
114
+ schedules,
115
+ scope: runtime.scope,
116
+ error
117
+ };
118
+ this.latest = result;
119
+ return result;
120
+ }
121
+ async getAvailability(params = {}) {
122
+ // `force` remains accepted for older callers; refresh recomputes time using the runtime catalog.
123
+ const snapshot = await this.snapshot(true, true);
124
+ const now = this.now();
125
+ try {
126
+ return {
127
+ ...(0, _FulfillmentTiming.computePickupTimingAvailability)({
128
+ ...snapshot,
129
+ date: params.date,
130
+ now
131
+ }),
132
+ error: snapshot.error
133
+ };
134
+ } catch (reason) {
135
+ // Keep the handover selector usable when only Pickup's timezone is unavailable.
136
+ return {
137
+ config: snapshot.config,
138
+ timezone: snapshot.timezone,
139
+ now: now.toISOString(),
140
+ today: '',
141
+ maxDate: '',
142
+ date: params.date || '',
143
+ dates: [],
144
+ slots: [],
145
+ error: reason instanceof Error ? reason.message : 'Pickup times are unavailable. Please try again.'
146
+ };
147
+ }
148
+ }
149
+ getSelection() {
150
+ const order = this.host.getOrder();
151
+ const tempOrder = order.getTempOrder();
152
+ const booking = order.getPickupTimingBooking();
153
+ const config = this.latest?.scope === this.host.getScope() ? this.latest.config : undefined;
154
+ const storedServiceType = String(tempOrder?.metadata?.shop_service_data?.service_type || '');
155
+ const serviceType = config?.handoverModes.length ? config.handoverModes.includes(storedServiceType) ? storedServiceType : config.handoverModes[0] : storedServiceType;
156
+ const details = serviceType === 'pick_up' ? booking?.metadata.fulfillment_timing : undefined;
157
+ const mode = config?.timingMode === 'asap_only' ? 'asap' : config?.timingMode === 'scheduled_only' ? 'scheduled' : details?.mode ?? 'asap';
158
+ const sameMode = details?.mode === mode;
159
+ return {
160
+ serviceType,
161
+ mode,
162
+ source: mode === 'asap' ? 'asap' : sameMode && details?.source || 'schedule',
163
+ ...(sameMode && booking ? {
164
+ date: booking.start_date,
165
+ time: booking.start_time,
166
+ instant: details?.instant
167
+ } : {})
168
+ };
169
+ }
170
+ async validateSnapshot(selection) {
171
+ const snapshot = await this.snapshot(selection.serviceType === 'pick_up' && selection.mode === 'scheduled' && selection.source !== 'pos_manual');
172
+ const now = this.now();
173
+ const result = (0, _FulfillmentTiming.validatePickupTimingSelection)(selection, {
174
+ ...snapshot,
175
+ now,
176
+ allowManualOverride: this.host.isPos()
177
+ });
178
+ return {
179
+ snapshot,
180
+ now,
181
+ result
182
+ };
183
+ }
184
+ async validate(selection) {
185
+ return (await this.validateSnapshot(selection)).result;
186
+ }
187
+ async setSelection(selection, options = {}) {
188
+ const order = this.host.getOrder();
189
+ const tempOrder = order.ensureTempOrder();
190
+ const sequence = ++this.writeSequence;
191
+ const {
192
+ snapshot,
193
+ now,
194
+ result
195
+ } = await this.validateSnapshot(selection);
196
+ if (sequence !== this.writeSequence || order.getTempOrder() !== tempOrder || snapshot.scope !== this.host.getScope()) {
197
+ throw new Error('The order changed. Please choose the pickup time again.');
198
+ }
199
+ if (!result.valid) throw new Error(result.message || 'Please choose a valid pickup time.');
200
+ if (!snapshot.config.handoverModes.length) {
201
+ order.clearPickupTimingBooking();
202
+ return this.getSelection();
203
+ }
204
+ if (selection.serviceType !== 'pick_up') {
205
+ order.updateTempOrderServiceType(selection.serviceType);
206
+ return this.getSelection();
207
+ }
208
+ const slot = selection.mode === 'asap' ? (0, _FulfillmentTiming.getAsapPickupTiming)({
209
+ ...snapshot,
210
+ now
211
+ }) : result.slot;
212
+ if (!slot) throw new Error('Please choose a pickup time.');
213
+ // Validate everything before either field is changed; notify once after the combined update.
214
+ tempOrder.metadata = {
215
+ ...(tempOrder.metadata || {}),
216
+ shop_service_data: {
217
+ ...(tempOrder.metadata?.shop_service_data || {}),
218
+ service_type: 'pick_up'
219
+ }
220
+ };
221
+ order.setPickupTimingBooking({
222
+ mode: selection.mode,
223
+ source: selection.mode === 'asap' ? 'asap' : selection.source === 'pos_manual' ? 'pos_manual' : 'schedule',
224
+ date: slot.date,
225
+ time: slot.time,
226
+ instant: slot.instant,
227
+ timezone: snapshot.timezone,
228
+ frozen: options.frozen ?? false
229
+ });
230
+ return this.getSelection();
231
+ }
232
+
233
+ /** Called before a new checkout/payment; payment callbacks keep their already prepared appointment. */
234
+ async prepare(options = {}) {
235
+ const order = this.host.getOrder();
236
+ const tempOrder = order.getTempOrder();
237
+ const sequence = this.writeSequence;
238
+ if (order.getOrderIdentity()?.isSubmitted) return this.getSelection();
239
+ const booking = order.getPickupTimingBooking();
240
+ if (booking?.metadata.fulfillment_timing?.frozen) return this.getSelection();
241
+ // An actual payment callback must never revalidate or move the time after funds have been taken.
242
+ const paymentStatus = order.getTempOrder()?.payment_status;
243
+ if (paymentStatus === 'paid' || paymentStatus === 'partially_paid') {
244
+ if (booking?.metadata.fulfillment_timing) {
245
+ const detail = booking.metadata.fulfillment_timing;
246
+ order.setPickupTimingBooking({
247
+ ...detail,
248
+ date: booking.start_date,
249
+ time: booking.start_time,
250
+ frozen: true
251
+ });
252
+ }
253
+ return this.getSelection();
254
+ }
255
+ const snapshot = await this.snapshot(false);
256
+ if (order !== this.host.getOrder() || order.getTempOrder() !== tempOrder || sequence !== this.writeSequence) {
257
+ throw new Error('The order changed. Please choose the pickup time again.');
258
+ }
259
+ const selection = this.getSelection();
260
+ if (!snapshot.config.handoverModes.length) {
261
+ order.clearPickupTimingBooking();
262
+ return selection;
263
+ }
264
+ return this.setSelection(selection, {
265
+ frozen: options.freeze ?? false
266
+ });
267
+ }
268
+ }
269
+ exports.PickupTimingController = PickupTimingController;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.parseSalesResponse = parseSalesResponse;
7
7
  var _orderCollectionIdentity = require("../../../modules/Order/utils/orderCollectionIdentity");
8
+ var _pickupTiming = require("../../../modules/Order/pickupTiming");
8
9
  /**
9
10
  * 把 `/order/sales/{id}` 响应(OrderData)解析为 ISalesDetail。
10
11
  *
@@ -64,6 +65,7 @@ function pickCustomer(raw) {
64
65
  */
65
66
  function isRootBooking(booking) {
66
67
  if (!booking || typeof booking !== 'object') return false;
68
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return false;
67
69
  const parentId = booking.parent_id;
68
70
  if (parentId === 0 || parentId === null || parentId === undefined) return true;
69
71
  return false;
@@ -71,6 +73,7 @@ function isRootBooking(booking) {
71
73
  function indexBookingsByProductUid(bookings) {
72
74
  const result = {};
73
75
  for (const b of bookings) {
76
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(b)) continue;
74
77
  const uid = b && (b.product_uid || b.metadata?.product_uid) || '';
75
78
  if (!uid) continue;
76
79
  const key = String(uid);
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 2 | 1 | 5 | 4 | 3 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -53,10 +53,10 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
53
53
  * 在解决方案对外 ready 前准备 Invoice Document;失败只降级模板,不阻断销售。
54
54
  * 已由页面取得的 OpenData 直接交给模块接管,没有注入数据时再走 target-scoped 加载。
55
55
  */
56
- private prepareInvoiceTemplateAtSolutionReady;
56
+ protected prepareInvoiceTemplateAtSolutionReady(injectedOpenData?: OpenDataConfig): Promise<void>;
57
57
  protected getBookingTicketBusinessCode(): string | null;
58
58
  private getIdGeneratorPlugin;
59
- private loadOpenDataConfig;
59
+ protected loadOpenDataConfig(): Promise<OpenDataConfig | null>;
60
60
  getOpenData(): Promise<OpenDataConfig | null>;
61
61
  getInvoiceLayoutConfig(): Promise<InvoiceLayoutConfig>;
62
62
  getInvoiceTemplateSettings(): Promise<InvoiceTemplateSettings>;
@@ -346,7 +346,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
346
346
  * 获取当前的客户搜索条件
347
347
  * @returns 当前搜索条件
348
348
  */
349
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
349
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
350
350
  /**
351
351
  * 获取客户列表状态(包含滚动加载相关状态)
352
352
  * @returns 客户状态
@@ -8,12 +8,14 @@ exports.buildCustomerView = buildCustomerView;
8
8
  exports.indexBookingsByProductUid = indexBookingsByProductUid;
9
9
  exports.isWalkInCustomer = isWalkInCustomer;
10
10
  var _addTimeAvailability = require("./addTimeAvailability");
11
+ var _pickupTiming = require("../../../modules/Order/pickupTiming");
11
12
  /**
12
13
  * 仅按 booking.product_uid 建索引,避免发明 booking 与商品行之间的其它等价关系。
13
14
  */
14
15
  function indexBookingsByProductUid(bookings) {
15
16
  if (!Array.isArray(bookings) || bookings.length === 0) return {};
16
17
  return bookings.reduce((acc, booking) => {
18
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return acc;
17
19
  const uid = booking?.product_uid;
18
20
  if (uid === undefined || uid === null || uid === '') return acc;
19
21
  const key = String(uid);
@@ -105,7 +107,7 @@ function isGiftProductLine(line) {
105
107
  function buildCartView(lines, bookings, options = {}) {
106
108
  const productLines = Array.isArray(lines) ? lines : [];
107
109
  const bookingList = Array.isArray(bookings) ? bookings : [];
108
- const childBookings = bookingList.filter(booking => booking.parent_id !== 0);
110
+ const childBookings = bookingList.filter(booking => booking.parent_id !== 0 && !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
109
111
  const bookingsByProductUid = indexBookingsByProductUid(childBookings);
110
112
  const linesByUid = indexProductsByUid(productLines);
111
113
  const addTimeLinesByBookingUid = indexAddTimeProductsByBookingUid(productLines);