@pisell/pisellos 2.3.128 → 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 (160) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  4. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  8. package/dist/modules/Customer/index.js +6 -3
  9. package/dist/modules/Customer/types.d.ts +2 -0
  10. package/dist/modules/Discount/availability.d.ts +7 -0
  11. package/dist/modules/Discount/availability.js +49 -0
  12. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  13. package/dist/modules/Discount/entitlementPass.js +147 -0
  14. package/dist/modules/Discount/index.d.ts +2 -2
  15. package/dist/modules/Discount/index.js +37 -151
  16. package/dist/modules/Discount/types.d.ts +36 -5
  17. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  18. package/dist/modules/FulfillmentTiming/index.js +407 -0
  19. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  20. package/dist/modules/FulfillmentTiming/types.js +1 -0
  21. package/dist/modules/OpenData/types.d.ts +6 -0
  22. package/dist/modules/Order/index.d.ts +12 -0
  23. package/dist/modules/Order/index.js +498 -247
  24. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  25. package/dist/modules/Order/pickupTiming.js +53 -0
  26. package/dist/modules/Order/types.d.ts +5 -1
  27. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  28. package/dist/modules/Order/utils.d.ts +1 -1
  29. package/dist/modules/Order/utils.js +117 -66
  30. package/dist/modules/Payment/index.js +9 -10
  31. package/dist/modules/Payment/types.d.ts +21 -1
  32. package/dist/modules/Payment/types.js +2 -0
  33. package/dist/modules/Payment/walletpass.d.ts +1 -1
  34. package/dist/modules/Payment/walletpass.js +80 -47
  35. package/dist/modules/Rules/index.d.ts +2 -2
  36. package/dist/modules/Rules/index.js +480 -186
  37. package/dist/modules/Rules/types.d.ts +4 -0
  38. package/dist/modules/Schedule/index.d.ts +8 -0
  39. package/dist/modules/Schedule/index.js +141 -39
  40. package/dist/modules/index.d.ts +1 -0
  41. package/dist/modules/index.js +1 -0
  42. package/dist/plugins/request.d.ts +7 -0
  43. package/dist/server/modules/order/types.d.ts +2 -0
  44. package/dist/server/utils/small-ticket.d.ts +1 -85
  45. package/dist/server/utils/small-ticket.js +2 -2542
  46. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  47. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  48. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  49. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  50. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  51. package/dist/shared/receipt/small-ticket.js +2576 -0
  52. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  53. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  54. package/dist/solution/BaseSales/index.d.ts +25 -0
  55. package/dist/solution/BaseSales/index.js +1226 -1040
  56. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  57. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  58. package/dist/solution/BaseSales/types.d.ts +2 -2
  59. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  60. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  61. package/dist/solution/BookingByStep/index.d.ts +1 -1
  62. package/dist/solution/BookingTicket/index.d.ts +4 -5
  63. package/dist/solution/BookingTicket/index.js +60 -63
  64. package/dist/solution/BookingTicket/types.d.ts +5 -1
  65. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  66. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  67. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  68. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  69. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  70. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  71. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  72. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  73. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  74. package/dist/solution/ShopDiscount/index.js +99 -42
  75. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  76. package/dist/solution/ShopDiscount/utils.js +43 -23
  77. package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
  78. package/dist/solution/UnifiedBookingSales/index.js +874 -709
  79. package/dist/solution/index.d.ts +1 -0
  80. package/dist/solution/index.js +2 -1
  81. package/lib/index.d.ts +2 -0
  82. package/lib/index.js +21 -1
  83. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  84. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  85. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  87. package/lib/modules/Customer/index.js +5 -1
  88. package/lib/modules/Customer/types.d.ts +2 -0
  89. package/lib/modules/Discount/availability.d.ts +7 -0
  90. package/lib/modules/Discount/availability.js +43 -0
  91. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  92. package/lib/modules/Discount/entitlementPass.js +141 -0
  93. package/lib/modules/Discount/index.d.ts +2 -2
  94. package/lib/modules/Discount/index.js +23 -129
  95. package/lib/modules/Discount/types.d.ts +36 -5
  96. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  97. package/lib/modules/FulfillmentTiming/index.js +359 -0
  98. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  99. package/lib/modules/FulfillmentTiming/types.js +5 -0
  100. package/lib/modules/OpenData/types.d.ts +6 -0
  101. package/lib/modules/Order/index.d.ts +12 -0
  102. package/lib/modules/Order/index.js +252 -48
  103. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  104. package/lib/modules/Order/pickupTiming.js +61 -0
  105. package/lib/modules/Order/types.d.ts +5 -1
  106. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  107. package/lib/modules/Order/utils.d.ts +1 -1
  108. package/lib/modules/Order/utils.js +51 -7
  109. package/lib/modules/Payment/index.js +3 -4
  110. package/lib/modules/Payment/types.d.ts +21 -1
  111. package/lib/modules/Payment/types.js +1 -0
  112. package/lib/modules/Payment/walletpass.d.ts +1 -1
  113. package/lib/modules/Payment/walletpass.js +29 -9
  114. package/lib/modules/Rules/index.d.ts +2 -2
  115. package/lib/modules/Rules/index.js +357 -110
  116. package/lib/modules/Rules/types.d.ts +4 -0
  117. package/lib/modules/Schedule/index.d.ts +8 -0
  118. package/lib/modules/Schedule/index.js +68 -12
  119. package/lib/modules/index.d.ts +1 -0
  120. package/lib/modules/index.js +11 -0
  121. package/lib/plugins/request.d.ts +7 -0
  122. package/lib/server/modules/order/types.d.ts +2 -0
  123. package/lib/server/utils/small-ticket.d.ts +1 -85
  124. package/lib/server/utils/small-ticket.js +9 -2305
  125. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  126. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  127. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  128. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  129. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  130. package/lib/shared/receipt/small-ticket.js +2342 -0
  131. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  132. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  133. package/lib/solution/BaseSales/index.d.ts +25 -0
  134. package/lib/solution/BaseSales/index.js +102 -3
  135. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  136. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  137. package/lib/solution/BaseSales/types.d.ts +2 -2
  138. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  139. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  140. package/lib/solution/BookingByStep/index.d.ts +1 -1
  141. package/lib/solution/BookingTicket/index.d.ts +4 -5
  142. package/lib/solution/BookingTicket/index.js +36 -33
  143. package/lib/solution/BookingTicket/types.d.ts +5 -1
  144. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  145. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  146. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  147. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  148. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  149. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  150. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  151. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  152. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  153. package/lib/solution/ShopDiscount/index.js +55 -9
  154. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  155. package/lib/solution/ShopDiscount/utils.js +42 -25
  156. package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
  157. package/lib/solution/UnifiedBookingSales/index.js +132 -48
  158. package/lib/solution/index.d.ts +1 -0
  159. package/lib/solution/index.js +11 -0
  160. 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;
@@ -415,6 +439,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
415
439
  refreshWalletAssets(params?: {
416
440
  order_wait_pay_amount?: number;
417
441
  preserveSelection?: boolean;
442
+ retainSearchResultCodes?: string[];
418
443
  }): Promise<WalletAssetsState>;
419
444
  /** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */
420
445
  selectWalletAsset(params: {
@@ -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);
@@ -1849,7 +1931,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1849
1931
  if (!this.isPersistedOrderProduct(item)) return;
1850
1932
  (item.discount_list || []).forEach(discount => {
1851
1933
  const discountId = discount.discount?.resource_id || discount.id;
1852
- if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
1934
+ if (!discountId || !['entitlement_pass', 'good_pass', 'discount_card'].includes(discount.type)) return;
1853
1935
  const quantity = item.quantity || item.num || item.product_quantity || 1;
1854
1936
  const savedAmount = new _decimal.default(discount.amount || 0).times(quantity).plus(discount?.metadata?.product_discount_difference || 0);
1855
1937
  const index = historyDiscountList.findIndex(n => n.id === discountId);
@@ -2163,6 +2245,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2163
2245
  holders: [],
2164
2246
  isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
2165
2247
  orderTotalAmount
2248
+ }, {
2249
+ preserveEntitlementSelection: false
2166
2250
  }) || result;
2167
2251
  if (result.productList) {
2168
2252
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
@@ -2506,6 +2590,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2506
2590
  if (!this.store.order) {
2507
2591
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2508
2592
  }
2593
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2594
+ freeze: true
2595
+ });
2509
2596
  const virtualSettlement = await this.buildVirtualSettlementSubmitData();
2510
2597
  // this.store.order.persistTempOrder();
2511
2598
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
@@ -2564,6 +2651,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2564
2651
  if (!this.store.order) {
2565
2652
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2566
2653
  }
2654
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2655
+ freeze: false
2656
+ });
2567
2657
  return this.store.order.saveTempOrderAsDraft({
2568
2658
  cacheId: this.cacheId,
2569
2659
  platform: params?.platform ?? this.otherParams?.platform,
@@ -2579,6 +2669,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2579
2669
  if (!this.store.order) {
2580
2670
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2581
2671
  }
2672
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
2673
+ freeze: true
2674
+ });
2582
2675
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
2583
2676
  const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
2584
2677
  const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params?.enhancePayload);
@@ -3245,7 +3338,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3245
3338
  await this.publishWalletAssetsState(clearedState);
3246
3339
  }
3247
3340
  const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
3248
- preserveSelection: params?.preserveSelection !== false && !customerChanged
3341
+ preserveSelection: params?.preserveSelection !== false && !customerChanged,
3342
+ retainSearchResultCodes: params?.retainSearchResultCodes
3249
3343
  });
3250
3344
  await this.publishWalletAssetsState(wallet.getWalletAssetsState());
3251
3345
  let state = await refreshTask;
@@ -3505,6 +3599,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3505
3599
  if (!Number.isFinite(actualPaidAmount) || actualPaidAmount + 0.01 < amount) {
3506
3600
  throw new Error('顾客实收现金不能小于支付金额');
3507
3601
  }
3602
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
3603
+ freeze: true
3604
+ });
3508
3605
  this.window?.interaction?.utils?.postMessageToApp?.({
3509
3606
  module: 'till',
3510
3607
  key: 'open_till',
@@ -4058,6 +4155,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4058
4155
  async setOtherParams(params, {
4059
4156
  cover = false
4060
4157
  } = {}) {
4158
+ const previousPickupTimingScope = this.getPickupTimingScope();
4061
4159
  if (cover) {
4062
4160
  this.otherParams = {
4063
4161
  ...params
@@ -4069,6 +4167,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4069
4167
  };
4070
4168
  }
4071
4169
  this.cacheId = this.otherParams?.cacheId;
4170
+ if (previousPickupTimingScope !== this.getPickupTimingScope()) this.resetPickupTimingCache();
4072
4171
  await this.syncOtherParamsToSubModules(params, {
4073
4172
  cover
4074
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;
@@ -445,10 +445,10 @@ export interface BaseSalesAddLogParams extends BaseSalesLogInput {
445
445
  /** BaseSales.scanPromotionCode 对外的轻量结果(UI 可用 getDiscountList 或 scannedDiscountList 补 Holder) */
446
446
  export interface BaseSalesScanCodeResult {
447
447
  isAvailable: boolean;
448
- /** 卡券已加入 Promotion;false 时可能是无效、过期或已使用。 */
448
+ /** 卡券已加入 Promotion;可能因次数、时间或当前订单条件而暂时无法应用。 */
449
449
  isAccepted?: boolean;
450
450
  type?: 'server' | string;
451
451
  unavailableReason?: 'time_limit' | string;
452
- /** batchSearch 原始结果;Holder 补全等流程可从这里读取原始卡券。 */
452
+ /** 扫码卡券资料及最新可用状态,供 Holder 补全等流程使用。 */
453
453
  scannedDiscountList?: Discount[];
454
454
  }
@@ -17,6 +17,7 @@ exports.resolveStrategyEligibleProducts = resolveStrategyEligibleProducts;
17
17
  exports.resolveStrategyRequiredQuantity = resolveStrategyRequiredQuantity;
18
18
  var _decimal = _interopRequireDefault(require("decimal.js"));
19
19
  var _lodashEs = require("lodash-es");
20
+ var _entitlementPass = require("../../../modules/Discount/entitlementPass");
20
21
  var _utils = require("../../../modules/Order/utils");
21
22
  var _utils2 = require("../../ScanOrder/utils");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -395,11 +396,16 @@ function getProductLineNoteSignature(product) {
395
396
  const uid = getOrderProductUid(product);
396
397
  return uid ? `note:${uid}` : `note:${normalizedNote}`;
397
398
  }
398
- function hasGoodPassDiscount(product) {
399
+ function getFullCoveragePassDiscountType(product) {
399
400
  const productBundle = Array.isArray(product?.product_bundle) ? product.product_bundle : [];
400
401
  const extendedBundle = Array.isArray(product?._extend?.other?.bundle) ? product._extend.other.bundle : [];
401
402
  const discountLists = [product?.discount_list, ...productBundle.map(item => item?.discount_list), ...extendedBundle.map(item => item?.discount_list)];
402
- return discountLists.some(discountList => Array.isArray(discountList) && discountList.some(item => item?.type === 'good_pass' || item?.tag === 'good_pass'));
403
+ for (const discountList of discountLists) {
404
+ if (!Array.isArray(discountList)) continue;
405
+ const pass = discountList.find(item => (0, _entitlementPass.isFullCoveragePass)(item));
406
+ if (pass) return String(pass.type || pass.tag);
407
+ }
408
+ return null;
403
409
  }
404
410
 
405
411
  /**
@@ -412,8 +418,10 @@ function getPromotionLineMergeBoundary(product) {
412
418
  if (product?.product_id === undefined || product?.product_id === null) {
413
419
  return `custom:${getOrderProductUid(product)}`;
414
420
  }
415
- if (hasGoodPassDiscount(product)) {
416
- return `good-pass:${getOrderProductUid(product)}`;
421
+ const fullCoveragePassType = getFullCoveragePassDiscountType(product);
422
+ if (fullCoveragePassType) {
423
+ const boundary = fullCoveragePassType === 'good_pass' ? 'good-pass' : 'entitlement-pass';
424
+ return `${boundary}:${getOrderProductUid(product)}`;
417
425
  }
418
426
  if (Number(product?.product_sku?.open_sold_weight || 0) === 1) {
419
427
  return `weighing:${getOrderProductUid(product)}`;