@pisell/pisellos 2.3.184 → 2.3.186

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 (78) 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/Order/utils.js +12 -1
  14. package/dist/modules/Product/index.d.ts +1 -1
  15. package/dist/modules/Product/types.d.ts +5 -0
  16. package/dist/modules/ProductList/index.js +33 -12
  17. package/dist/modules/Rules/index.d.ts +2 -0
  18. package/dist/modules/Rules/index.js +29 -21
  19. package/dist/solution/BaseSales/index.d.ts +18 -1
  20. package/dist/solution/BaseSales/index.js +1762 -1434
  21. package/dist/solution/BaseSales/types.d.ts +3 -0
  22. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  23. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  24. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  25. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  26. package/dist/solution/BookingByStep/index.d.ts +2 -2
  27. package/dist/solution/BookingTicket/index.d.ts +13 -1
  28. package/dist/solution/BookingTicket/index.js +197 -108
  29. package/dist/solution/BookingTicket/types.d.ts +14 -2
  30. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  31. package/dist/solution/BookingTicket/utils/addProductDecision.js +4 -3
  32. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  33. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
  34. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  35. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  36. package/dist/solution/UnifiedBookingSales/index.d.ts +1 -1
  37. package/dist/solution/UnifiedBookingSales/index.js +102 -64
  38. package/dist/utils/platform.d.ts +2 -0
  39. package/dist/utils/platform.js +6 -0
  40. package/lib/index.d.ts +1 -0
  41. package/lib/index.js +12 -0
  42. package/lib/inventory/index.d.ts +92 -0
  43. package/lib/inventory/index.js +287 -0
  44. package/lib/modules/Discount/index.js +1 -0
  45. package/lib/modules/Order/index.d.ts +25 -3
  46. package/lib/modules/Order/index.js +192 -38
  47. package/lib/modules/Order/types.d.ts +7 -0
  48. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  49. package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  50. package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
  51. package/lib/modules/Order/utils.js +13 -0
  52. package/lib/modules/Product/index.d.ts +1 -1
  53. package/lib/modules/Product/types.d.ts +5 -0
  54. package/lib/modules/ProductList/index.js +15 -0
  55. package/lib/modules/Rules/index.d.ts +2 -0
  56. package/lib/modules/Rules/index.js +6 -0
  57. package/lib/solution/BaseSales/index.d.ts +18 -1
  58. package/lib/solution/BaseSales/index.js +214 -50
  59. package/lib/solution/BaseSales/types.d.ts +3 -0
  60. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  61. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  62. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  63. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  64. package/lib/solution/BookingByStep/index.d.ts +2 -2
  65. package/lib/solution/BookingTicket/index.d.ts +13 -1
  66. package/lib/solution/BookingTicket/index.js +37 -2
  67. package/lib/solution/BookingTicket/types.d.ts +14 -2
  68. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  69. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -3
  70. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  71. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
  72. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  73. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  74. package/lib/solution/UnifiedBookingSales/index.d.ts +1 -1
  75. package/lib/solution/UnifiedBookingSales/index.js +37 -4
  76. package/lib/utils/platform.d.ts +2 -0
  77. package/lib/utils/platform.js +7 -0
  78. package/package.json +1 -1
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildPosDurationPricingPlan = buildPosDurationPricingPlan;
7
+ exports.combinePosDurationPrices = combinePosDurationPrices;
8
+ exports.durationPricingUnavailable = durationPricingUnavailable;
9
+ exports.forEachPriceQueryGroup = forEachPriceQueryGroup;
10
+ exports.hasAppliedPosDurationPricing = hasAppliedPosDurationPricing;
11
+ exports.hasDurationBasedPricing = hasDurationBasedPricing;
12
+ exports.resolveDurationPricingProduct = resolveDurationPricingProduct;
13
+ exports.usesPosDurationPricing = usesPosDurationPricing;
14
+ var _dayjs = _interopRequireDefault(require("dayjs"));
15
+ var _decimal = _interopRequireDefault(require("decimal.js"));
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ function durationPricingUnavailable(message) {
18
+ return Object.assign(new Error(message), {
19
+ code: 'DURATION_PRICING_UNAVAILABLE'
20
+ });
21
+ }
22
+ function hasDurationBasedPricing(product) {
23
+ return product?.pricing_method?.type === 'duration_based';
24
+ }
25
+
26
+ /** Days/Flexible retain their existing quotation behavior. */
27
+ function usesPosDurationPricing(product) {
28
+ const type = String(product?.duration?.type || '').trim().toLowerCase();
29
+ return hasDurationBasedPricing(product) && !['day', 'days', 'flexible'].includes(type);
30
+ }
31
+
32
+ /** A hydrated catalog can already be fixed while its order/quote still contains an applied duration price. */
33
+ function hasAppliedPosDurationPricing(product) {
34
+ return usesPosDurationPricing(product?._extend?.bookingPriceQuote) || usesPosDurationPricing(product?._extend?.bookingPrice?.quote) || usesPosDurationPricing(product?.metadata);
35
+ }
36
+ function bookingDateTime(date, time) {
37
+ const dateText = typeof date === 'string' ? date.trim() : '';
38
+ const timeText = typeof time === 'string' ? time.trim() : '';
39
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(dateText) || !/^\d{2}:\d{2}(?::\d{2})?$/.test(timeText)) {
40
+ throw durationPricingUnavailable('A valid booking start and end are required for duration pricing.');
41
+ }
42
+ const text = `${dateText} ${timeText.length === 5 ? `${timeText}:00` : timeText}`;
43
+ const value = (0, _dayjs.default)(text);
44
+ if (!value.isValid() || value.format('YYYY-MM-DD HH:mm:ss') !== text) {
45
+ throw durationPricingUnavailable('The booking time is invalid for duration pricing.');
46
+ }
47
+ return value;
48
+ }
49
+ function buildPosDurationPricingPlan(params, product) {
50
+ const type = String(product.duration?.type || '').trim().toLowerCase();
51
+ const value = Number(product.duration?.value);
52
+ const minutes = ['hour', 'hours'].includes(type) ? value * 60 : value;
53
+ if (!['minute', 'minutes', 'hour', 'hours'].includes(type) || !Number.isFinite(minutes) || minutes <= 0) {
54
+ throw durationPricingUnavailable('A positive fixed billing duration is required.');
55
+ }
56
+ const start = bookingDateTime(params.booking?.start_date, params.booking?.start_time);
57
+ const end = bookingDateTime(params.booking?.end_date, params.booking?.end_time);
58
+ const count = end.diff(start) / (minutes * 60_000);
59
+ if (!Number.isInteger(count) || count < 1 || count > 10_000) {
60
+ throw durationPricingUnavailable('The booking duration must be a whole multiple of its billing duration.');
61
+ }
62
+ return {
63
+ duration: {
64
+ type: 'minutes',
65
+ value: minutes
66
+ },
67
+ segments: Array.from({
68
+ length: count
69
+ }, (_, index) => ({
70
+ start: start.add(index * minutes, 'minute').format('YYYY-MM-DD HH:mm:ss'),
71
+ end: start.add((index + 1) * minutes, 'minute').format('YYYY-MM-DD HH:mm:ss')
72
+ }))
73
+ };
74
+ }
75
+
76
+ /** Never use a previously accumulated order price as one unit's fallback. */
77
+ function resolveDurationPricingProduct(product, selected) {
78
+ const variantId = Number(selected.product_variant_id ?? selected.variant_id ?? 0);
79
+ const authoritativeVariantId = Number(product.product_variant_id ?? product.variant_id ?? 0);
80
+ const variant = variantId > 0 && Array.isArray(product.variant) ? product.variant.find(item => Number(item?.id) === variantId) : undefined;
81
+ if (variantId > 0 && !variant && authoritativeVariantId !== variantId) {
82
+ throw durationPricingUnavailable('The selected SKU is missing from the authoritative price response.');
83
+ }
84
+ const appliedFields = product._dataVariant?.appliedFields;
85
+ const hasAppliedPrice = Array.isArray(appliedFields) && ['price', 'selling_price', 'original_price', 'base_price'].some(field => appliedFields.includes(field));
86
+ const priceSource = variantId > 0 && authoritativeVariantId !== variantId && !hasAppliedPrice ? variant : product;
87
+ const price = priceSource?.price ?? priceSource?.selling_price ?? priceSource?.base_price ?? priceSource?.original_price;
88
+ if (!(typeof price === 'number' || typeof price === 'string' && price.trim() !== '') || !Number.isFinite(Number(price)) || Number(price) < 0) {
89
+ throw durationPricingUnavailable('An authoritative price is required for every billing unit.');
90
+ }
91
+ return {
92
+ ...product,
93
+ price
94
+ };
95
+ }
96
+ function combinePosDurationPrices(plan, prices) {
97
+ if (prices.length !== plan.segments.length || prices.length === 0) {
98
+ throw durationPricingUnavailable('The duration price is incomplete.');
99
+ }
100
+ const unitPrice = prices.reduce((sum, price) => sum.plus(price.unit_price), new _decimal.default(0));
101
+ return {
102
+ ...prices[0],
103
+ pricing_method: {
104
+ type: 'duration_based'
105
+ },
106
+ duration: plan.duration,
107
+ unit_price: unitPrice.toFixed(2),
108
+ total_price: unitPrice.times(prices[0].quantity).toFixed(2),
109
+ quotation_shelf_id: prices.find(price => price.quotation_shelf_id)?.quotation_shelf_id || 0,
110
+ segments: prices.map((price, index) => ({
111
+ ...price.segments[0],
112
+ start_datetime: plan.segments[index].start,
113
+ end_datetime: plan.segments[index].end,
114
+ time_point: plan.segments[index].start,
115
+ unit_price: price.unit_price,
116
+ total_price: price.unit_price,
117
+ quantity: 1
118
+ })),
119
+ // Options are composed by the caller; bundle pricing belongs to the first unit only.
120
+ product_bundle: prices[0].product_bundle
121
+ };
122
+ }
123
+ async function forEachPriceQueryGroup(groups, resolve, concurrency) {
124
+ let next = 0;
125
+ await Promise.all(Array.from({
126
+ length: Math.min(groups.length, concurrency)
127
+ }, async () => {
128
+ while (next < groups.length) {
129
+ const group = groups[next++];
130
+ await resolve(group);
131
+ }
132
+ }));
133
+ }
@@ -55,6 +55,8 @@ export interface TransformBaseProductToOrderProductParams {
55
55
  fallbackProductId?: number | string | null;
56
56
  sourceProduct?: ProductData | Record<string, any> | null;
57
57
  sourceItem?: ProductData | Record<string, any> | null;
58
+ /** Validated booking quote's pre-discount main price, excluding options/bundles. */
59
+ quotedSourceProductPrice?: number | string;
58
60
  }
59
61
  export type BaseProductOrderProductInput = Partial<OrderProduct> & OrderProductIdentity & {
60
62
  _origin?: Record<string, any>;
@@ -156,7 +156,7 @@ function transformBaseProductToOrderProduct(params) {
156
156
  // 售价仍由 line_total - bundle 推导。
157
157
  const catalogSourcePrice = matchedVariant?.price ?? matchedVariant?.base_price ?? origin?.price ?? origin?.base_price ?? sourceProduct?.price ?? sourceProduct?.selling_price ?? sourceProduct?.base_price;
158
158
  const weighedSourcePrice = (0, _weighedProduct.resolveWeighedSourcePrice)(payload.product_sku ?? origin.product_sku, payload._extend?.weighing ?? origin._extend?.weighing);
159
- const sourceProductPrice = toPriceString(weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
159
+ const sourceProductPrice = toPriceString(params.quotedSourceProductPrice ?? weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
160
160
  const explicitLineTotal = payload.line_total ?? payload.total ?? payload._extend?.total;
161
161
  const hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
162
162
  const lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
328
328
  date: string;
329
329
  status: string;
330
330
  week: string;
331
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
331
+ weekNum: 0 | 2 | 1 | 6 | 4 | 5 | 3;
332
332
  }[]>;
333
333
  submitTimeSlot(timeSlots: TimeSliceItem): void;
334
334
  private getScheduleDataByIds;
@@ -375,7 +375,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
375
375
  };
376
376
  setOtherData(key: string, value: any): void;
377
377
  getOtherData(key: string): any;
378
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
378
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
379
379
  /**
380
380
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
381
381
  *
@@ -485,7 +485,19 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
485
485
  * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
486
486
  * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
487
487
  */
488
- decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
488
+ decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): {
489
+ action: "reloadCatalog";
490
+ } | {
491
+ action: "add";
492
+ cacheItem: any;
493
+ } | {
494
+ action: "requiresDetail";
495
+ payload: AddProductRequiresDetailPayload;
496
+ } | {
497
+ action: "requiresBookingEdit";
498
+ cacheItem: any;
499
+ payload: import("./utils/addProductDecision").AddProductRequiresBookingEditPayload;
500
+ };
489
501
  /** 规格弹窗 callback 后的第二段决策。 */
490
502
  decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
491
503
  /**
@@ -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,30 @@ 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
+ loadCustomerDiscounts: async () => {
1902
+ beforeScanCommit();
1903
+ const customerId = Number(this.getOrderCustomer()?.customer_id || 0);
1904
+ if (customerId <= 1) return [];
1905
+ await this.refreshDiscountConfigAfterOrderCustomerChange(customerId);
1906
+ beforeScanCommit();
1907
+ return this.getDiscountList();
1908
+ }
1909
+ }, formatted, guardedBridge) : await (0, _applyGlobalScan.applyGlobalScan)(host, formatted, guardedBridge);
1884
1910
  bridge?.refresh?.();
1885
1911
  return result;
1886
1912
  } catch (error) {
1913
+ if (bridge?.scanScope === 'product-voucher-collection') {
1914
+ if (bridge.isCurrent?.() === false) return {
1915
+ status: 'cancelled'
1916
+ };
1917
+ return {
1918
+ status: 'failed',
1919
+ reason: 'entry_resolution_failed'
1920
+ };
1921
+ }
1887
1922
  console.error('[BookingTicket] handleGlobalScanCode failed', error);
1888
1923
  bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
1889
1924
  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; product-voucher-collection loads all vouchers for the scanned customer. */
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
  }
@@ -0,0 +1,8 @@
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
+ loadCustomerDiscounts(): Promise<Record<string, any>[]>;
6
+ }
7
+ /** Resolve the scanned account, then collect all of that customer's vouchers. */
8
+ export declare function applyProductVoucherCollectionScan(host: ProductVoucherCollectionScanHost, formatted: GlobalScanFormattedResult, bridge: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyProductVoucherCollectionScan = applyProductVoucherCollectionScan;
7
+ var _applyGlobalScan = require("./applyGlobalScan");
8
+ /** Resolve the scanned account, then collect all of that customer's vouchers. */
9
+ async function applyProductVoucherCollectionScan(host, formatted, bridge) {
10
+ const assertCurrent = () => {
11
+ if (bridge.isCurrent?.() === false) {
12
+ throw new DOMException('Scan session ended', 'AbortError');
13
+ }
14
+ };
15
+ const isPass = formatted.searchType === 'walletPass';
16
+ // Order numbers and wristbands resolve through batch-search. Their returned
17
+ // passes identify the customer; they are not the collection's voucher list.
18
+ // Resolve source-shop IDs before reusing the wallet customer-binding flow.
19
+ const customerScan = isPass ? {
20
+ ...formatted,
21
+ searchType: 'wallet',
22
+ customerId: formatted.customerId ?? formatted.data?.id ?? formatted.data?.customer_id,
23
+ isCrossShopWallet: true
24
+ } : formatted;
25
+ assertCurrent();
26
+ const result = await (0, _applyGlobalScan.applyGlobalScan)({
27
+ ...host,
28
+ setOrderCustomer: customer => {
29
+ assertCurrent();
30
+ host.setOrderCustomer(customer);
31
+ },
32
+ addProductToOrder: (product, booking) => {
33
+ assertCurrent();
34
+ return host.addProductToOrder(product, booking);
35
+ }
36
+ }, customerScan, {
37
+ ...bridge,
38
+ // Without a switch bridge, do not return the previous customer's vouchers.
39
+ requestCustomerSwitch: bridge.requestCustomerSwitch ?? (async () => false)
40
+ });
41
+ assertCurrent();
42
+ if (customerScan.searchType === 'wallet' && result.status === 'success') {
43
+ const vouchers = await host.loadCustomerDiscounts();
44
+ assertCurrent();
45
+ return {
46
+ ...result,
47
+ redemption: {
48
+ source: isPass ? 'scan' : 'wallet',
49
+ vouchers
50
+ }
51
+ };
52
+ }
53
+ return result;
54
+ }
@@ -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
  };
@@ -160,7 +160,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
160
160
  /** 在 Kiosk 拉起支付设备前补齐订单号,同一订单重试复用已分配的号码。 */
161
161
  ensureLocalOrderNumbersForCheckout(): Promise<void>;
162
162
  /**
163
- * PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
163
+ * PC/H5 及自助终端结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
164
164
  * 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
165
165
  */
166
166
  protected shouldUseCheckoutSyncTask(): boolean;
@@ -1558,6 +1558,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1558
1558
  cover = false
1559
1559
  } = {}) {
1560
1560
  const previousScope = this.getAvailabilityScopeDescriptor(this.otherParams || {});
1561
+ const previousCatalogScope = this.otherParams?.catalogScopeKey;
1561
1562
  const previousItemRuleConfig = this.otherParams?.itemRule;
1562
1563
  const explicitlySetsOpenData = Object.prototype.hasOwnProperty.call(params, 'openData');
1563
1564
  const nextParams = cover ? params : {
@@ -1570,6 +1571,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1570
1571
  await super.setOtherParams(params, {
1571
1572
  cover
1572
1573
  });
1574
+ if (previousCatalogScope !== this.otherParams?.catalogScopeKey && (previousCatalogScope || this.otherParams?.catalogScopeKey)) {
1575
+ this.unifiedProductCatalog = [];
1576
+ await this.core.effects.emit(`${this.name}:onProductsLoaded`, []);
1577
+ }
1573
1578
  const nextScope = this.getAvailabilityScopeDescriptor(this.otherParams || {});
1574
1579
  if (explicitlySetsOpenData) {
1575
1580
  this.openDataTarget = this.otherParams?.openData && nextScope.businessCode && nextScope.channel ? `${nextScope.businessCode}+${nextScope.channel}` : null;
@@ -1824,14 +1829,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1824
1829
  }
1825
1830
 
1826
1831
  /**
1827
- * PC/H5/Kiosk 结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
1832
+ * PC/H5 及自助终端结账默认直接等待云端 checkout;POS/WebPOS 仍保持本地待同步。
1828
1833
  * 显式传 checkoutSyncTaskEnabled: true 时仍可回退到本地同步模式。
1829
1834
  */
1830
1835
  shouldUseCheckoutSyncTask() {
1831
1836
  const configured = this.otherParams?.checkoutSyncTaskEnabled;
1832
1837
  if (configured === true) return true;
1833
1838
  const platform = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform);
1834
- return !(0, _platform.isCustomerUserPlatform)(platform) && platform !== 'kiosk';
1839
+ return !(0, _platform.isCustomerUserPlatform)(platform) && !(0, _platform.isSelfServicePlatform)(platform);
1835
1840
  }
1836
1841
 
1837
1842
  /** UnifiedBookingSales 的真实结账默认请求收据数据,供云端确认后再本地打印。 */
@@ -2379,7 +2384,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2379
2384
  throw new Error('[UnifiedBookingSales] getProtocol 需要 policyId');
2380
2385
  }
2381
2386
  let policyUrl = 'shop-policy';
2382
- if (this.otherParams.platform === 'kiosk' || this.otherParams.platform === 'pos' || this.otherParams.platform === 'shop') {
2387
+ if ((0, _platform.isSelfServicePlatform)(this.otherParams.platform) || this.otherParams.platform === 'pos' || this.otherParams.platform === 'shop') {
2383
2388
  policyUrl = 'policy';
2384
2389
  }
2385
2390
  return this.request.get(`/${policyUrl}/${encodeURIComponent(normalizedPolicyId)}`);
@@ -2391,6 +2396,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2391
2396
  */
2392
2397
  async loadProducts(params = {}, options) {
2393
2398
  if (!this.store.products) throw new Error('[UnifiedBookingSales] products 模块未初始化');
2399
+ const catalogScope = this.otherParams.catalogScopeKey;
2394
2400
  const schedule_date = params.schedule_date || (0, _dayjs.default)().format('YYYY-MM-DD');
2395
2401
  const schedule_datetime = params.schedule_datetime || `${schedule_date} ${(0, _dayjs.default)().format('HH:mm:ss')}`;
2396
2402
  const result = await this.store.products.loadProducts({
@@ -2401,6 +2407,11 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2401
2407
  schedule_datetime,
2402
2408
  cacheId: this.cacheId
2403
2409
  }, options);
2410
+ if (catalogScope !== this.otherParams.catalogScopeKey) {
2411
+ throw Object.assign(new Error('Product scope changed'), {
2412
+ name: 'AbortError'
2413
+ });
2414
+ }
2404
2415
  this.unifiedProductCatalog = Array.isArray(result) ? [...result] : [];
2405
2416
  await this.core.effects.emit(`${this.name}:onProductsLoaded`, result);
2406
2417
  return result;
@@ -2578,6 +2589,17 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2578
2589
  }
2579
2590
  buildUnifiedOrderProduct(sourceProduct, ownershipKey, product) {
2580
2591
  const normalizedProductRaw = product?.raw || {};
2592
+ const bookingQuote = sourceProduct._extend?.bookingPriceQuote;
2593
+ const isPos = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos';
2594
+ const quoteMethod = isPos ? bookingQuote?.pricing_method?.type : undefined;
2595
+ const hasDurationQuote = quoteMethod === 'duration_based';
2596
+ const quoteSourcePrice = bookingQuote?.sourceUnitPrice;
2597
+ const quoteDuration = bookingQuote?.duration;
2598
+ if (hasDurationQuote && (quoteSourcePrice === undefined || quoteSourcePrice === null || quoteSourcePrice === '' || !Number.isFinite(Number(quoteSourcePrice)) || Number(quoteSourcePrice) < 0 || quoteDuration?.type !== 'minutes' || !Number.isFinite(Number(quoteDuration.value)) || Number(quoteDuration.value) <= 0)) {
2599
+ throw Object.assign(new Error('按时长计价结果无效,请重新选择预约时间。'), {
2600
+ code: 'DURATION_PRICING_UNAVAILABLE'
2601
+ });
2602
+ }
2581
2603
  const quotationShelfId = sourceProduct._extend?.quotation_shelf_id ?? sourceProduct.quotation_shelf_id ?? sourceProduct.metadata?.quotation_shelf_id;
2582
2604
  const orderProduct = this.transformBaseProductToOrderProduct({
2583
2605
  payload: {
@@ -2592,7 +2614,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2592
2614
  [ownershipKey]: true
2593
2615
  }
2594
2616
  },
2595
- sourceProduct
2617
+ sourceProduct,
2618
+ ...(hasDurationQuote ? {
2619
+ quotedSourceProductPrice: quoteSourcePrice
2620
+ } : {})
2596
2621
  });
2597
2622
  if (orderProduct && typeof orderProduct === 'object') {
2598
2623
  // BaseSales may rebuild metadata from its price source. Stamp ownership and the selected
@@ -2600,6 +2625,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2600
2625
  orderProduct.metadata = {
2601
2626
  ...(orderProduct.metadata || {}),
2602
2627
  [ownershipKey]: true,
2628
+ ...(hasDurationQuote || quoteMethod === 'fixed_price' ? {
2629
+ pricing_method: {
2630
+ type: quoteMethod
2631
+ },
2632
+ duration: hasDurationQuote ? {
2633
+ ...quoteDuration
2634
+ } : undefined
2635
+ } : {}),
2603
2636
  ...(quotationShelfId !== undefined ? {
2604
2637
  quotation_shelf_id: quotationShelfId
2605
2638
  } : {})
@@ -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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.184",
4
+ "version": "2.3.186",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",