@pisell/pisellos 2.3.171 → 2.3.172

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 (62) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/inventory/index.d.ts +92 -0
  4. package/dist/inventory/index.js +509 -0
  5. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  6. package/dist/modules/Discount/index.js +1 -0
  7. package/dist/modules/Order/index.d.ts +25 -3
  8. package/dist/modules/Order/index.js +1770 -1311
  9. package/dist/modules/Order/types.d.ts +7 -0
  10. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  11. package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  12. package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
  13. package/dist/modules/Payment/walletpass.js +32 -6
  14. package/dist/modules/ProductList/index.js +33 -12
  15. package/dist/modules/Rules/index.d.ts +2 -0
  16. package/dist/modules/Rules/index.js +29 -21
  17. package/dist/solution/BaseSales/index.d.ts +16 -1
  18. package/dist/solution/BaseSales/index.js +1511 -1325
  19. package/dist/solution/BookingTicket/index.js +200 -108
  20. package/dist/solution/BookingTicket/types.d.ts +14 -2
  21. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  22. package/dist/solution/BookingTicket/utils/addProductDecision.js +4 -3
  23. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +94 -58
  24. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
  25. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +117 -0
  26. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  27. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  28. package/dist/solution/UnifiedBookingSales/index.d.ts +1 -1
  29. package/dist/solution/UnifiedBookingSales/index.js +69 -49
  30. package/dist/utils/platform.d.ts +2 -0
  31. package/dist/utils/platform.js +6 -0
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +12 -0
  34. package/lib/inventory/index.d.ts +92 -0
  35. package/lib/inventory/index.js +287 -0
  36. package/lib/modules/Discount/index.js +1 -0
  37. package/lib/modules/Order/index.d.ts +25 -3
  38. package/lib/modules/Order/index.js +192 -38
  39. package/lib/modules/Order/types.d.ts +7 -0
  40. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  41. package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  42. package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
  43. package/lib/modules/Payment/walletpass.js +23 -1
  44. package/lib/modules/ProductList/index.js +15 -0
  45. package/lib/modules/Rules/index.d.ts +2 -0
  46. package/lib/modules/Rules/index.js +6 -0
  47. package/lib/solution/BaseSales/index.d.ts +16 -1
  48. package/lib/solution/BaseSales/index.js +89 -9
  49. package/lib/solution/BookingTicket/index.js +38 -2
  50. package/lib/solution/BookingTicket/types.d.ts +14 -2
  51. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  52. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -3
  53. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +14 -2
  54. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
  55. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +71 -0
  56. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  57. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  58. package/lib/solution/UnifiedBookingSales/index.d.ts +1 -1
  59. package/lib/solution/UnifiedBookingSales/index.js +14 -3
  60. package/lib/utils/platform.d.ts +2 -0
  61. package/lib/utils/platform.js +7 -0
  62. package/package.json +1 -1
@@ -22,6 +22,10 @@ class RulesModule extends _BaseModule.BaseModule {
22
22
  store;
23
23
  window; // WindowPlugin 实例
24
24
  hooks;
25
+ discountScope;
26
+ setDiscountScope(scope) {
27
+ this.discountScope = scope;
28
+ }
25
29
  constructor(name, version) {
26
30
  super(name, version);
27
31
  this.hooks = {};
@@ -745,6 +749,7 @@ class RulesModule extends _BaseModule.BaseModule {
745
749
 
746
750
  // 辅助函数:检查商品是否对某个折扣卡可用
747
751
  const checkItemApplicableForDiscount = (flatItem, discount) => {
752
+ if (this.discountScope && !this.discountScope(flatItem.originProduct, discount)) return false;
748
753
  if (discount.config?.isAvailable === false) return false;
749
754
  if (isCardBlockedByPromotion(flatItem, discount)) return false;
750
755
  let product;
@@ -1156,6 +1161,7 @@ class RulesModule extends _BaseModule.BaseModule {
1156
1161
 
1157
1162
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1158
1163
  const applicableDiscounts = sortedDiscountList.filter(discount => {
1164
+ if (this.discountScope && !this.discountScope(originProduct, discount)) return false;
1159
1165
  if (this.isItemRewardProductDiscount(product)) return false;
1160
1166
  if (isCardBlockedByPromotion(flatItem, discount)) return false;
1161
1167
  // 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
@@ -1,3 +1,4 @@
1
+ import { InventoryController, type CheckoutRuntimeSnapshot } from '../../inventory';
1
2
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
3
  import { BaseModule } from '../../modules/BaseModule';
3
4
  import { type LocalEftposFinalization } from '../../modules/Order/localEftposState';
@@ -52,6 +53,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
52
53
  protected appPlugin: AppPlugin;
53
54
  protected store: BaseSalesState;
54
55
  protected otherParams: Record<string, any>;
56
+ getInventory(): InventoryController | undefined;
57
+ prepareCheckout(signal?: AbortSignal): Promise<CheckoutRuntimeSnapshot | undefined>;
55
58
  protected cacheId: string | undefined;
56
59
  /**
57
60
  * 由已在初始化阶段解析过设备短号的业务解决方案写入。
@@ -194,6 +197,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
194
197
  * 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
195
198
  */
196
199
  protected createSubModule(moduleName: string): Module | null;
200
+ private inventoryOrderHooks?;
197
201
  protected getSubModuleHooks(moduleName: string): any;
198
202
  /**
199
203
  * 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
@@ -231,7 +235,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
231
235
  private isActiveVirtualSettlementOrder;
232
236
  private isHistoricalVirtualSettlementOrder;
233
237
  private syncAppDataToTempOrder;
238
+ private initialization?;
239
+ /** Hosts can await readiness without changing Core's synchronous registration API. */
240
+ whenInitialized(): Promise<void>;
234
241
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
242
+ private initializeSalesRuntime;
235
243
  destroy(): Promise<void>;
236
244
  /**
237
245
  * 加载销售订单到统一 tempOrder 工作区。
@@ -340,7 +348,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
340
348
  discountList: Discount[];
341
349
  originalDiscountList?: Discount[];
342
350
  }): Promise<void>;
343
- scanPromotionCode(code: string, customerId?: number): Promise<BaseSalesScanCodeResult>;
351
+ scanPromotionCode(code: string, customerId?: number, options?: {
352
+ productVouchersOnly?: boolean;
353
+ }): Promise<BaseSalesScanCodeResult>;
344
354
  setDiscountSelected(params: {
345
355
  discountId: number;
346
356
  isSelected: boolean;
@@ -525,6 +535,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
525
535
  private hasSmartPricingStrategies;
526
536
  shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
527
537
  calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
538
+ setProductVoucherGroups(groups: Array<{
539
+ key: string;
540
+ discountIds: Array<number | string>;
541
+ }>): void;
542
+ validateProductVoucherSelection(): void;
528
543
  addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
529
544
  updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
530
545
  updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<import("../../modules/Order/types").OrderProduct[]>;
@@ -7,6 +7,7 @@ var _exportNames = {
7
7
  BaseSalesImpl: true
8
8
  };
9
9
  exports.BaseSalesImpl = void 0;
10
+ var _inventory = require("../../inventory");
10
11
  var _BaseModule = require("../../modules/BaseModule");
11
12
  var _localEftposState = require("../../modules/Order/localEftposState");
12
13
  var _types = require("./types");
@@ -511,6 +512,40 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
511
512
  order: undefined
512
513
  };
513
514
  otherParams = {};
515
+ getInventory() {
516
+ return this.otherParams.inventory;
517
+ }
518
+ async prepareCheckout(signal) {
519
+ const inventory = this.getInventory();
520
+ const hooks = this.otherParams.checkoutHooks;
521
+ if (!inventory && !hooks?.beforeCheckout) return undefined;
522
+ if (!this.store.order) throw new Error('Order module is not ready');
523
+ return this.store.order.prepareCheckout(async items => {
524
+ const assertCurrent = () => {
525
+ if (signal?.aborted) throw Object.assign(new Error('Checkout cancelled'), {
526
+ name: 'AbortError'
527
+ });
528
+ if (inventory !== this.getInventory() || hooks !== this.otherParams.checkoutHooks) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
529
+ };
530
+ assertCurrent();
531
+ try {
532
+ await hooks?.beforeCheckout?.({
533
+ items,
534
+ signal
535
+ });
536
+ if (inventory) await inventory.refresh({
537
+ reason: 'checkout',
538
+ force: true,
539
+ signal
540
+ });
541
+ assertCurrent();
542
+ return inventory?.freezeCheckout(items);
543
+ } catch (error) {
544
+ if (error?.name === 'AbortError') throw error;
545
+ throw (0, _inventory.salesGuardError)(error instanceof Error ? error.message : String(error));
546
+ }
547
+ });
548
+ }
514
549
  cacheId;
515
550
  /**
516
551
  * 由已在初始化阶段解析过设备短号的业务解决方案写入。
@@ -1401,12 +1436,35 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1401
1436
  }
1402
1437
  return (0, _types2.createModule)(moduleName, this.name);
1403
1438
  }
1439
+ inventoryOrderHooks;
1404
1440
  getSubModuleHooks(moduleName) {
1405
1441
  const optionHooks = this.initializeOptions.hooks || {};
1406
1442
  const otherHooks = this.otherParams.hooks || {};
1407
1443
  if (moduleName === 'order') {
1408
1444
  const directOrderHooks = optionHooks;
1409
- return optionHooks.order || this.otherParams.order?.hooks || otherHooks.order || (directOrderHooks.onBeforeMergeProductToOrder ? directOrderHooks : undefined);
1445
+ const hooks = optionHooks.order || this.otherParams.order?.hooks || otherHooks.order || (directOrderHooks.onBeforeMergeProductToOrder || directOrderHooks.onBeforeCartCommit ? directOrderHooks : undefined);
1446
+ const inventory = this.getInventory();
1447
+ if (!inventory) {
1448
+ this.inventoryOrderHooks = undefined;
1449
+ return hooks;
1450
+ }
1451
+ if (this.inventoryOrderHooks?.inventory === inventory && this.inventoryOrderHooks.base === hooks) {
1452
+ return this.inventoryOrderHooks.hooks;
1453
+ }
1454
+ const combined = {
1455
+ ...hooks,
1456
+ onBeforeCartCommit: async context => {
1457
+ await hooks?.onBeforeCartCommit?.(context);
1458
+ if (inventory !== this.getInventory()) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
1459
+ inventory.validate(context.proposedItems, context.currentItems);
1460
+ }
1461
+ };
1462
+ this.inventoryOrderHooks = {
1463
+ inventory,
1464
+ base: hooks,
1465
+ hooks: combined
1466
+ };
1467
+ return combined;
1410
1468
  }
1411
1469
  return optionHooks[moduleName] || this.otherParams[moduleName]?.hooks || otherHooks[moduleName];
1412
1470
  }
@@ -1454,7 +1512,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1454
1512
  const nextSubModuleOtherParams = this.buildSubModuleOtherParams(moduleName);
1455
1513
  await targetModule.updateOtherParams(nextSubModuleOtherParams, {
1456
1514
  changedParams,
1457
- cover
1515
+ cover,
1516
+ ...(moduleName === 'order' ? {
1517
+ hooks: this.getSubModuleHooks(moduleName)
1518
+ } : {})
1458
1519
  });
1459
1520
  }));
1460
1521
  }
@@ -1603,7 +1664,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1603
1664
  }
1604
1665
  return isChanged;
1605
1666
  }
1606
- async initialize(core, options = {}) {
1667
+ initialization;
1668
+
1669
+ /** Hosts can await readiness without changing Core's synchronous registration API. */
1670
+ whenInitialized() {
1671
+ return this.initialization || Promise.reject(new Error('Sales module is not registered'));
1672
+ }
1673
+ initialize(core, options = {}) {
1674
+ this.initialization = this.initializeSalesRuntime(core, options);
1675
+ return this.initialization;
1676
+ }
1677
+ async initializeSalesRuntime(core, options = {}) {
1607
1678
  this.resetPickupTimingCache();
1608
1679
  this.core = core;
1609
1680
  this.initializeOptions = options || {};
@@ -1663,17 +1734,19 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1663
1734
  this.serverOrderChangeUnsubscribe = null;
1664
1735
  this.paymentMethodsChangedUnsubscribe?.();
1665
1736
  this.paymentMethodsChangedUnsubscribe = null;
1666
- Object.keys(this.store).forEach(key => {
1667
- if (this.reusedSharedSubModuleNames.has(key)) return;
1737
+ for (const key of Object.keys(this.store)) {
1738
+ if (this.reusedSharedSubModuleNames.has(key)) continue;
1668
1739
  const sub = this.store[key];
1669
1740
  if (sub && typeof sub.destroy === 'function') {
1670
1741
  try {
1671
- sub.destroy();
1742
+ // A host may register a replacement after destroy resolves. Wait for
1743
+ // nested modules so their cleanup cannot unregister the replacement.
1744
+ await sub.destroy();
1672
1745
  } catch (error) {
1673
1746
  console.warn(`[BaseSales] 子模块 ${key} 销毁失败`, error);
1674
1747
  }
1675
1748
  }
1676
- });
1749
+ }
1677
1750
  this.currentSalesDetail = null;
1678
1751
  this.paymentNumberDevicePrefix = null;
1679
1752
  this.queuedServerOrderChanges = [];
@@ -2441,10 +2514,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2441
2514
  }
2442
2515
  await discountModule.setDiscountList(params.discountList);
2443
2516
  }
2444
- async scanPromotionCode(code, customerId) {
2517
+ async scanPromotionCode(code, customerId, options) {
2445
2518
  try {
2446
2519
  if (!this.store.order) throw new Error('order 模块未初始化');
2447
- const raw = await this.store.order.scanCode(code, customerId);
2520
+ const raw = await this.store.order.scanCode(code, customerId, options);
2448
2521
  if (raw.isAvailable) {
2449
2522
  await this.store.order.recalculateSummary({
2450
2523
  createIfMissing: true
@@ -4264,6 +4337,13 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4264
4337
  });
4265
4338
  });
4266
4339
  }
4340
+ setProductVoucherGroups(groups) {
4341
+ if (!this.store.order) throw new Error('order 模块未初始化');
4342
+ this.store.order.setProductVoucherGroups(groups);
4343
+ }
4344
+ validateProductVoucherSelection() {
4345
+ this.store.order?.validateProductVoucherSelection();
4346
+ }
4267
4347
  async addProductToOrder(product, booking, options) {
4268
4348
  try {
4269
4349
  if (!this.store.order) throw new Error('order 模块未初始化');
@@ -30,6 +30,7 @@ var _handleScan = require("./utils/scan/handleScan");
30
30
  var _scanCache = _interopRequireDefault(require("./utils/scan/scanCache"));
31
31
  var _formatGlobalScan = require("./utils/scan/formatGlobalScan");
32
32
  var _applyGlobalScan = require("./utils/scan/applyGlobalScan");
33
+ var _applyProductVoucherCollectionScan = require("./utils/scan/applyProductVoucherCollectionScan");
33
34
  var _cartView = require("./utils/cartView");
34
35
  var _addProductDecision = require("./utils/addProductDecision");
35
36
  var _buildCacheItemFromOrderLine = require("../../modules/BookingContext/utils/buildCacheItemFromOrderLine");
@@ -1845,6 +1846,20 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1845
1846
  return bridge.openBookingEdit(payload);
1846
1847
  } : undefined
1847
1848
  } : undefined;
1849
+ if (guardedBridge?.scanScope === 'product-voucher') {
1850
+ if (!guardedBridge.applyPromotionCode) return {
1851
+ status: 'failed',
1852
+ reason: 'no_bridge'
1853
+ };
1854
+ const promotion = await guardedBridge.applyPromotionCode(trimmed);
1855
+ return promotion.isAccepted ?? promotion.isAvailable ? {
1856
+ status: 'success',
1857
+ kind: 'promotion'
1858
+ } : {
1859
+ status: 'failed',
1860
+ reason: 'not_found'
1861
+ };
1862
+ }
1848
1863
  const localSearch = v => this.store.products.findProductsByCodeOrBarcode(v);
1849
1864
  const scanCallback = (0, _handleScan.handleGlobalScan)(this.request, localSearch, this.getSubmitOrderSalesChannel());
1850
1865
  const raw = await scanCallback({
@@ -1859,7 +1874,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1859
1874
  reason: 'not_found'
1860
1875
  };
1861
1876
  }
1862
- const result = await (0, _applyGlobalScan.applyGlobalScan)({
1877
+ const host = {
1863
1878
  setOrderCustomer: customer => {
1864
1879
  beforeScanCommit();
1865
1880
  this.setOrderCustomer(customer);
@@ -1880,10 +1895,31 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1880
1895
  beforeScanCommit();
1881
1896
  return this.scanWalletAsset(scanCode);
1882
1897
  }
1883
- }, formatted, guardedBridge);
1898
+ };
1899
+ const result = guardedBridge?.scanScope === 'product-voucher-collection' ? await (0, _applyProductVoucherCollectionScan.applyProductVoucherCollectionScan)({
1900
+ ...host,
1901
+ waitForCustomerDiscounts: () => this.orderCustomerDiscountRefreshInFlight || Promise.resolve(),
1902
+ loadCustomerDiscounts: async () => {
1903
+ beforeScanCommit();
1904
+ const customerId = Number(this.getOrderCustomer()?.customer_id || 0);
1905
+ if (customerId <= 1) return [];
1906
+ await this.refreshDiscountConfigAfterOrderCustomerChange(customerId);
1907
+ beforeScanCommit();
1908
+ return this.getDiscountList();
1909
+ }
1910
+ }, formatted, guardedBridge) : await (0, _applyGlobalScan.applyGlobalScan)(host, formatted, guardedBridge);
1884
1911
  bridge?.refresh?.();
1885
1912
  return result;
1886
1913
  } catch (error) {
1914
+ if (bridge?.scanScope === 'product-voucher-collection') {
1915
+ if (bridge.isCurrent?.() === false) return {
1916
+ status: 'cancelled'
1917
+ };
1918
+ return {
1919
+ status: 'failed',
1920
+ reason: 'entry_resolution_failed'
1921
+ };
1922
+ }
1887
1923
  console.error('[BookingTicket] handleGlobalScanCode failed', error);
1888
1924
  bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
1889
1925
  return {
@@ -208,6 +208,10 @@ export interface AddAddTimeProductsToBookingInput {
208
208
  }
209
209
  /** 扫码宿主桥接:SalesSdk 在 pubsub 订阅回调里注入,OS 需要 UI 时直接调用 */
210
210
  export interface GlobalScanHostBridge {
211
+ /** product-voucher handles voucher codes only; product-voucher-collection also resolves wallet customer vouchers. */
212
+ scanScope?: 'all' | 'product-voucher' | 'product-voucher-collection';
213
+ /** A one-shot entry may outlive its page while requests are in flight. */
214
+ isCurrent?: () => boolean;
211
215
  openProductDetail?: (payload: Record<string, any>) => Promise<any | null>;
212
216
  openBookingEdit?: (payload: Record<string, any>) => Promise<any | null>;
213
217
  confirmDetail?: (input: {
@@ -232,11 +236,13 @@ export interface GlobalScanHostBridge {
232
236
  */
233
237
  applyPromotionCode?: (code: string, customerId?: number, options?: {
234
238
  suppressFailureNotification?: boolean;
239
+ productVouchersOnly?: boolean;
235
240
  }) => Promise<{
236
241
  isAvailable?: boolean;
237
242
  isAccepted?: boolean;
238
243
  type?: string;
239
244
  unavailableReason?: string;
245
+ scannedDiscountList?: Record<string, any>[];
240
246
  }>;
241
247
  /** 当前订单已有其他客户时,由宿主复用客户组件完成确认及切换。 */
242
248
  requestCustomerSwitch?: (customer: ICustomer) => Promise<boolean | null>;
@@ -244,7 +250,7 @@ export interface GlobalScanHostBridge {
244
250
  refresh?: () => void;
245
251
  }
246
252
  /** handleGlobalScanCode 结构化返回 */
247
- export type GlobalScanHandleResult = {
253
+ export type GlobalScanHandleResult = ({
248
254
  status: 'success';
249
255
  kind: 'customer' | 'products' | 'promotion';
250
256
  meta?: {
@@ -257,5 +263,11 @@ export type GlobalScanHandleResult = {
257
263
  status: 'cancelled';
258
264
  } | {
259
265
  status: 'failed';
260
- reason: 'empty_code' | 'not_found' | 'invalid_data' | 'no_bridge';
266
+ reason: 'empty_code' | 'not_found' | 'invalid_data' | 'no_bridge' | 'entry_resolution_failed';
267
+ }) & {
268
+ /** product-voucher-collection returns voucher candidates; the caller decides how to use them. */
269
+ redemption?: {
270
+ source: 'wallet' | 'scan';
271
+ vouchers: Record<string, any>[];
272
+ };
261
273
  };
@@ -5,7 +5,7 @@ import type { OrderProduct, OrderProductIdentity, AddProductBookingInput } from
5
5
  * cart.addProduct 两阶段决策(与 ticketBooking `handleSelectProduct` 对齐):
6
6
  *
7
7
  * 1. `requiresDetail`:规格 / SKU / 套餐 / Session / 称重弹窗(门禁:`isOpenDetailModal` / `cartDetailValue` / `open_sold_weight`)
8
- * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(kiosk 强制进入;其他渠道由 `getIsAutoClose` 决定)
8
+ * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(自助终端强制进入;其他渠道由 `getIsAutoClose` 决定)
9
9
  * 3. `add`:两关均通过,直接 transform + 加车
10
10
  */
11
11
  export type AddProductDecision = {
@@ -17,12 +17,13 @@ var _dayjs = _interopRequireDefault(require("dayjs"));
17
17
  var _BookingContext = require("../../../modules/BookingContext");
18
18
  var _transformBaseProductToOrderProduct = require("../../BaseSales/utils/transformBaseProductToOrderProduct");
19
19
  var _weighingProductSku = require("./weighingProductSku");
20
+ var _platform = require("../../../utils/platform");
20
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22
  /**
22
23
  * cart.addProduct 两阶段决策(与 ticketBooking `handleSelectProduct` 对齐):
23
24
  *
24
25
  * 1. `requiresDetail`:规格 / SKU / 套餐 / Session / 称重弹窗(门禁:`isOpenDetailModal` / `cartDetailValue` / `open_sold_weight`)
25
- * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(kiosk 强制进入;其他渠道由 `getIsAutoClose` 决定)
26
+ * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(自助终端强制进入;其他渠道由 `getIsAutoClose` 决定)
26
27
  * 3. `add`:两关均通过,直接 transform + 加车
27
28
  */
28
29
 
@@ -39,11 +40,11 @@ function needsSpecDetailModal(item) {
39
40
  }
40
41
 
41
42
  /**
42
- * 第二段:预约商品是否仍需打开资源 / 时间编辑(kiosk 强制打开,其他渠道与 info2 `cacheItem.autoClose` 等价)。
43
+ * 第二段:预约商品是否仍需打开资源 / 时间编辑(自助终端强制打开,其他渠道与 info2 `cacheItem.autoClose` 等价)。
43
44
  */
44
45
  function needsBookingEdit(cacheItem, ctx) {
45
46
  if (isNormalBookingProduct(cacheItem)) return false;
46
- if (ctx?.channel === 'kiosk') return true;
47
+ if ((0, _platform.isSelfServicePlatform)(ctx?.channel)) return true;
47
48
  const isAutoAllocationOn = ctx?.isAutoAllocationOn || (() => true);
48
49
  return !(0, _BookingContext.getIsAutoClose)(cacheItem, isAutoAllocationOn);
49
50
  }
@@ -289,6 +289,18 @@ async function applyGlobalScan(host, formatted, bridge) {
289
289
  // batch-search 可能返回来源门店客户;先映射到当前门店,确保 Wallet
290
290
  // 支付资产查询使用本店客户上下文。
291
291
  const bindResult = await bindWalletPassCustomer();
292
+ // Voucher collection prioritizes goods coupons resolved from the wristband/order.
293
+ // Only this opt-in flow checks them before selecting a payment wallet asset.
294
+ const collectionPromotion = bridge?.scanScope === 'product-voucher-collection' && bridge.applyPromotionCode ? await bridge.applyPromotionCode(scanCode, getRealCustomerId(activeCustomer), {
295
+ suppressFailureNotification: true,
296
+ productVouchersOnly: true
297
+ }) : undefined;
298
+ if (collectionPromotion?.isAccepted ?? collectionPromotion?.isAvailable) {
299
+ return {
300
+ status: 'success',
301
+ kind: 'promotion'
302
+ };
303
+ }
292
304
  const walletSelection = await trySelectWalletAsset();
293
305
  if (walletSelection) return walletSelection;
294
306
  if (!bridge?.applyPromotionCode) {
@@ -298,9 +310,9 @@ async function applyGlobalScan(host, formatted, bridge) {
298
310
  };
299
311
  }
300
312
  const promotionCustomerId = getRealCustomerId(activeCustomer);
301
- const promotionResult = bindResult.customerBound ? await bridge.applyPromotionCode(scanCode, promotionCustomerId, {
313
+ const promotionResult = collectionPromotion ?? (bindResult.customerBound ? await bridge.applyPromotionCode(scanCode, promotionCustomerId, {
302
314
  suppressFailureNotification: true
303
- }) : await bridge.applyPromotionCode(scanCode, promotionCustomerId);
315
+ }) : await bridge.applyPromotionCode(scanCode, promotionCustomerId));
304
316
  if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
305
317
  return {
306
318
  status: 'success',
@@ -0,0 +1,10 @@
1
+ import type { GlobalScanHandleResult, GlobalScanHostBridge } from '../../types';
2
+ import { type GlobalScanApplyHost } from './applyGlobalScan';
3
+ import type { GlobalScanFormattedResult } from './formatGlobalScan';
4
+ export interface ProductVoucherCollectionScanHost extends GlobalScanApplyHost {
5
+ waitForCustomerDiscounts(): Promise<void>;
6
+ loadCustomerDiscounts(): Promise<Record<string, any>[]>;
7
+ }
8
+ /** Collect voucher candidates after customer binding and coupon loading finish.
9
+ * Never expand a wristband's result to other orders of the same customer. */
10
+ export declare function applyProductVoucherCollectionScan(host: ProductVoucherCollectionScanHost, formatted: GlobalScanFormattedResult, bridge: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyProductVoucherCollectionScan = applyProductVoucherCollectionScan;
7
+ var _applyGlobalScan = require("./applyGlobalScan");
8
+ /** Collect voucher candidates after customer binding and coupon loading finish.
9
+ * Never expand a wristband's result to other orders of the same customer. */
10
+ async function applyProductVoucherCollectionScan(host, formatted, bridge) {
11
+ const assertCurrent = () => {
12
+ if (bridge.isCurrent?.() === false) {
13
+ throw new DOMException('Scan session ended', 'AbortError');
14
+ }
15
+ };
16
+ let vouchers = [];
17
+ assertCurrent();
18
+ const result = await (0, _applyGlobalScan.applyGlobalScan)({
19
+ ...host,
20
+ setOrderCustomer: customer => {
21
+ assertCurrent();
22
+ host.setOrderCustomer(customer);
23
+ },
24
+ addProductToOrder: (product, booking) => {
25
+ assertCurrent();
26
+ return host.addProductToOrder(product, booking);
27
+ }
28
+ }, formatted, {
29
+ ...bridge,
30
+ applyPromotionCode: bridge.applyPromotionCode && (async (code, customerId, options) => {
31
+ // Customer binding starts prepare/config in the background. Let it finish
32
+ // before adding scanned coupons so its response cannot overwrite them.
33
+ await host.waitForCustomerDiscounts();
34
+ assertCurrent();
35
+ const promotion = await bridge.applyPromotionCode(code, customerId, {
36
+ ...options,
37
+ productVouchersOnly: true,
38
+ suppressFailureNotification: true
39
+ });
40
+ assertCurrent();
41
+ // An empty successful search is different from a swallowed request error.
42
+ if (!Array.isArray(promotion.scannedDiscountList)) {
43
+ throw new Error('Could not resolve scanned vouchers');
44
+ }
45
+ vouchers = promotion.scannedDiscountList;
46
+ return promotion;
47
+ })
48
+ });
49
+ assertCurrent();
50
+ if (formatted.searchType === 'wallet' && result.status === 'success') {
51
+ vouchers = await host.loadCustomerDiscounts();
52
+ assertCurrent();
53
+ return {
54
+ ...result,
55
+ redemption: {
56
+ source: 'wallet',
57
+ vouchers
58
+ }
59
+ };
60
+ }
61
+ if (formatted.searchType === 'walletPass') {
62
+ return {
63
+ ...result,
64
+ redemption: {
65
+ source: 'scan',
66
+ vouchers
67
+ }
68
+ };
69
+ }
70
+ return result;
71
+ }
@@ -10,6 +10,7 @@ exports.searchWalletPass = exports.searchWallet = exports.searchProduct = export
10
10
  const searchWalletPass = async (request, code) => {
11
11
  const params = {
12
12
  code,
13
+ resolve_ticket_order: 1,
13
14
  translate_flag: 1,
14
15
  // 翻译识别码名称 0:不翻译 1:翻译
15
16
  relation_product: 1,
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.handleUniversalScan = exports.handleGlobalScan = exports.handleCustomerScan = void 0;
7
7
  var _cloudSearch = require("./cloudSearch");
8
8
  var _scanCache = _interopRequireDefault(require("./scanCache"));
9
+ var _platform = require("../../../../utils/platform");
9
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
11
  /**
11
12
  * Promise.any 的替代实现
@@ -107,7 +108,7 @@ const handleGlobalScan = (request, localSearch, channel) => {
107
108
  if (value.startsWith('WL')) {
108
109
  requestList = [(0, _cloudSearch.searchWallet)(request, value)];
109
110
  } else {
110
- requestList = [...(channel === 'kiosk' ? [] : [(0, _cloudSearch.searchOrder)(request, value)]), (0, _cloudSearch.searchWalletPass)(request, value), (0, _cloudSearch.searchWallet)(request, value), (0, _cloudSearch.searchProduct)(request, value)];
111
+ requestList = [...((0, _platform.isSelfServicePlatform)(channel) ? [] : [(0, _cloudSearch.searchOrder)(request, value)]), (0, _cloudSearch.searchWalletPass)(request, value), (0, _cloudSearch.searchWallet)(request, value), (0, _cloudSearch.searchProduct)(request, value)];
111
112
  }
112
113
  return requestList;
113
114
  };
@@ -156,7 +156,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
156
156
  /** 在 Kiosk 拉起支付设备前补齐订单号,同一订单重试复用已分配的号码。 */
157
157
  ensureLocalOrderNumbersForCheckout(): Promise<void>;
158
158
  /**
159
- * PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
159
+ * PC/H5 及自助终端结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
160
160
  * 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
161
161
  */
162
162
  protected shouldUseCheckoutSyncTask(): boolean;
@@ -1546,6 +1546,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1546
1546
  cover = false
1547
1547
  } = {}) {
1548
1548
  const previousScope = this.getAvailabilityScopeDescriptor(this.otherParams || {});
1549
+ const previousCatalogScope = this.otherParams?.catalogScopeKey;
1549
1550
  const previousItemRuleConfig = this.otherParams?.itemRule;
1550
1551
  const explicitlySetsOpenData = Object.prototype.hasOwnProperty.call(params, 'openData');
1551
1552
  const nextParams = cover ? params : {
@@ -1558,6 +1559,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1558
1559
  await super.setOtherParams(params, {
1559
1560
  cover
1560
1561
  });
1562
+ if (previousCatalogScope !== this.otherParams?.catalogScopeKey && (previousCatalogScope || this.otherParams?.catalogScopeKey)) {
1563
+ this.unifiedProductCatalog = [];
1564
+ await this.core.effects.emit(`${this.name}:onProductsLoaded`, []);
1565
+ }
1561
1566
  const nextScope = this.getAvailabilityScopeDescriptor(this.otherParams || {});
1562
1567
  if (explicitlySetsOpenData) {
1563
1568
  this.openDataTarget = this.otherParams?.openData && nextScope.businessCode && nextScope.channel ? `${nextScope.businessCode}+${nextScope.channel}` : null;
@@ -1812,14 +1817,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1812
1817
  }
1813
1818
 
1814
1819
  /**
1815
- * PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
1820
+ * PC/H5 及自助终端结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
1816
1821
  * 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
1817
1822
  */
1818
1823
  shouldUseCheckoutSyncTask() {
1819
1824
  const configured = this.otherParams?.checkoutSyncTaskEnabled;
1820
1825
  if (configured === true) return true;
1821
1826
  const platform = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform);
1822
- return !(0, _platform.isCustomerUserPlatform)(platform) && platform !== 'kiosk';
1827
+ return !(0, _platform.isCustomerUserPlatform)(platform) && !(0, _platform.isSelfServicePlatform)(platform);
1823
1828
  }
1824
1829
 
1825
1830
  /** UnifiedBookingSales 的真实结账默认请求收据数据,供云端确认后再本地打印。 */
@@ -2176,7 +2181,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2176
2181
  throw new Error('[UnifiedBookingSales] getProtocol 需要 policyId');
2177
2182
  }
2178
2183
  let policyUrl = 'shop-policy';
2179
- if (this.otherParams.platform === 'kiosk' || this.otherParams.platform === 'pos' || this.otherParams.platform === 'shop') {
2184
+ if ((0, _platform.isSelfServicePlatform)(this.otherParams.platform) || this.otherParams.platform === 'pos' || this.otherParams.platform === 'shop') {
2180
2185
  policyUrl = 'policy';
2181
2186
  }
2182
2187
  return this.request.get(`/${policyUrl}/${encodeURIComponent(normalizedPolicyId)}`);
@@ -2188,6 +2193,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2188
2193
  */
2189
2194
  async loadProducts(params = {}, options) {
2190
2195
  if (!this.store.products) throw new Error('[UnifiedBookingSales] products 模块未初始化');
2196
+ const catalogScope = this.otherParams.catalogScopeKey;
2191
2197
  const schedule_date = params.schedule_date || (0, _dayjs.default)().format('YYYY-MM-DD');
2192
2198
  const schedule_datetime = params.schedule_datetime || `${schedule_date} ${(0, _dayjs.default)().format('HH:mm:ss')}`;
2193
2199
  const result = await this.store.products.loadProducts({
@@ -2198,6 +2204,11 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2198
2204
  schedule_datetime,
2199
2205
  cacheId: this.cacheId
2200
2206
  }, options);
2207
+ if (catalogScope !== this.otherParams.catalogScopeKey) {
2208
+ throw Object.assign(new Error('Product scope changed'), {
2209
+ name: 'AbortError'
2210
+ });
2211
+ }
2201
2212
  this.unifiedProductCatalog = Array.isArray(result) ? [...result] : [];
2202
2213
  await this.core.effects.emit(`${this.name}:onProductsLoaded`, result);
2203
2214
  return result;
@@ -6,3 +6,5 @@ export declare function normalizeRuntimePlatform(platform: unknown): string;
6
6
  * PC and H5 are authenticated-customer clients rather than staff terminals.
7
7
  */
8
8
  export declare function isCustomerUserPlatform(platform: unknown): boolean;
9
+ /** Kiosk and vending retain distinct channels but share self-service checkout behavior. */
10
+ export declare function isSelfServicePlatform(platform: unknown): boolean;
@@ -4,8 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isCustomerUserPlatform = isCustomerUserPlatform;
7
+ exports.isSelfServicePlatform = isSelfServicePlatform;
7
8
  exports.normalizeRuntimePlatform = normalizeRuntimePlatform;
8
9
  const CUSTOMER_USER_PLATFORMS = new Set(['pc', 'h5']);
10
+ const SELF_SERVICE_PLATFORMS = new Set(['kiosk', 'vending']);
9
11
 
10
12
  /**
11
13
  * Normalize the runtime platform passed through solution/module otherParams.
@@ -19,4 +21,9 @@ function normalizeRuntimePlatform(platform) {
19
21
  */
20
22
  function isCustomerUserPlatform(platform) {
21
23
  return CUSTOMER_USER_PLATFORMS.has(normalizeRuntimePlatform(platform));
24
+ }
25
+
26
+ /** Kiosk and vending retain distinct channels but share self-service checkout behavior. */
27
+ function isSelfServicePlatform(platform) {
28
+ return SELF_SERVICE_PLATFORMS.has(normalizeRuntimePlatform(platform));
22
29
  }