@pisell/pisellos 2.2.162 → 2.2.164

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 (116) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +157 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +107 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +191 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.js +23 -22
  32. package/dist/modules/Discount/index.js +4 -3
  33. package/dist/modules/Order/index.d.ts +17 -6
  34. package/dist/modules/Order/index.js +474 -287
  35. package/dist/modules/Order/types.d.ts +32 -12
  36. package/dist/modules/Order/utils.js +9 -8
  37. package/dist/modules/SalesSummary/index.js +4 -2
  38. package/dist/modules/index.d.ts +1 -0
  39. package/dist/modules/index.js +2 -1
  40. package/dist/solution/BaseSales/index.d.ts +38 -7
  41. package/dist/solution/BaseSales/index.js +797 -310
  42. package/dist/solution/BaseSales/types.d.ts +48 -1
  43. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  44. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  45. package/dist/solution/BookingByStep/index.d.ts +2 -2
  46. package/dist/solution/BookingTicket/index.d.ts +121 -1
  47. package/dist/solution/BookingTicket/index.js +401 -72
  48. package/dist/solution/BookingTicket/types.d.ts +2 -0
  49. package/dist/solution/BookingTicket/types.js +3 -0
  50. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  51. package/dist/solution/BookingTicket/utils/addProductDecision.js +326 -0
  52. package/dist/solution/ScanOrder/index.d.ts +9 -3
  53. package/dist/solution/ScanOrder/index.js +231 -128
  54. package/dist/solution/VenueBooking/index.d.ts +4 -2
  55. package/dist/solution/VenueBooking/index.js +103 -55
  56. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  57. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  58. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  59. package/lib/modules/BookingContext/index.d.ts +37 -0
  60. package/lib/modules/BookingContext/index.js +297 -0
  61. package/lib/modules/BookingContext/types.d.ts +102 -0
  62. package/lib/modules/BookingContext/types.js +34 -0
  63. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  64. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +174 -0
  65. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  66. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +115 -0
  67. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  68. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +177 -0
  69. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  70. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  71. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  72. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  73. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  74. package/lib/modules/BookingContext/utils/index.js +43 -0
  75. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  76. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  77. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  78. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  79. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  80. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  81. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  82. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  83. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  84. package/lib/modules/BookingContext/utils/resources.js +377 -0
  85. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  86. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  87. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  88. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  89. package/lib/modules/Customer/index.js +8 -8
  90. package/lib/modules/Discount/index.js +5 -1
  91. package/lib/modules/Order/index.d.ts +17 -6
  92. package/lib/modules/Order/index.js +164 -68
  93. package/lib/modules/Order/types.d.ts +32 -12
  94. package/lib/modules/Order/utils.js +8 -6
  95. package/lib/modules/SalesSummary/index.js +4 -2
  96. package/lib/modules/index.d.ts +1 -0
  97. package/lib/modules/index.js +3 -1
  98. package/lib/solution/BaseSales/index.d.ts +38 -7
  99. package/lib/solution/BaseSales/index.js +304 -14
  100. package/lib/solution/BaseSales/types.d.ts +48 -1
  101. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  102. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  103. package/lib/solution/BookingByStep/index.d.ts +2 -2
  104. package/lib/solution/BookingTicket/index.d.ts +121 -1
  105. package/lib/solution/BookingTicket/index.js +207 -2
  106. package/lib/solution/BookingTicket/types.d.ts +2 -0
  107. package/lib/solution/BookingTicket/types.js +6 -0
  108. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  109. package/lib/solution/BookingTicket/utils/addProductDecision.js +300 -0
  110. package/lib/solution/ScanOrder/index.d.ts +9 -3
  111. package/lib/solution/ScanOrder/index.js +147 -66
  112. package/lib/solution/VenueBooking/index.d.ts +4 -2
  113. package/lib/solution/VenueBooking/index.js +50 -14
  114. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  115. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  116. package/package.json +1 -1
@@ -0,0 +1,201 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/solution/BaseSales/utils/quotationPrice.ts
30
+ var quotationPrice_exports = {};
31
+ __export(quotationPrice_exports, {
32
+ calculateBaseSalesProductBookingPrice: () => calculateBaseSalesProductBookingPrice
33
+ });
34
+ module.exports = __toCommonJS(quotationPrice_exports);
35
+ var import_dayjs = __toESM(require("dayjs"));
36
+ var import_decimal = __toESM(require("decimal.js"));
37
+ function toFiniteNumber(value, fallback = 0) {
38
+ const parsedValue = Number(value);
39
+ if (!Number.isFinite(parsedValue))
40
+ return fallback;
41
+ return parsedValue;
42
+ }
43
+ function toPositiveInt(value, fallback = 1) {
44
+ const parsedValue = Math.floor(Number(value));
45
+ if (!Number.isFinite(parsedValue) || parsedValue < 1)
46
+ return fallback;
47
+ return parsedValue;
48
+ }
49
+ function toPriceString(value) {
50
+ return new import_decimal.default(Number(value) || 0).toDecimalPlaces(2).toFixed(2);
51
+ }
52
+ function normalizeDateTime(value) {
53
+ if (typeof value !== "string" || !value.trim())
54
+ return null;
55
+ const normalized = value.includes(":") ? value : `${value} 00:00:00`;
56
+ const datetime = (0, import_dayjs.default)(normalized);
57
+ if (!datetime.isValid())
58
+ return null;
59
+ return datetime;
60
+ }
61
+ function buildBookingDateTime(date, time) {
62
+ if (typeof date !== "string" || !date.trim())
63
+ return null;
64
+ const timeText = typeof time === "string" && time.trim() ? time.trim() : "00:00";
65
+ const datetime = (0, import_dayjs.default)(`${date.trim()} ${timeText}`);
66
+ if (!datetime.isValid())
67
+ return null;
68
+ return datetime;
69
+ }
70
+ function getDurationUnit(type) {
71
+ const normalizedType = String(type || "").toLowerCase();
72
+ if (normalizedType === "day" || normalizedType === "days")
73
+ return "day";
74
+ if (normalizedType === "minute" || normalizedType === "minutes")
75
+ return "minute";
76
+ return null;
77
+ }
78
+ function getProductId(product) {
79
+ const productId = toFiniteNumber(product.product_id ?? product.id, NaN);
80
+ if (!Number.isFinite(productId))
81
+ return null;
82
+ return productId;
83
+ }
84
+ function getProductVariantId(product) {
85
+ const variantId = toFiniteNumber(
86
+ product.product_variant_id ?? product.variant_id,
87
+ 0
88
+ );
89
+ if (!Number.isFinite(variantId) || variantId <= 0)
90
+ return void 0;
91
+ return variantId;
92
+ }
93
+ function getFallbackPrice(params) {
94
+ const product = params.product || {};
95
+ return toPriceString(
96
+ params.fallback_price ?? product.price ?? product.selling_price ?? product.original_price ?? 0
97
+ );
98
+ }
99
+ function getProductQuantity(product) {
100
+ return toPositiveInt(product.num ?? product.quantity, 1);
101
+ }
102
+ function shouldSplitByDuration(duration, start, end) {
103
+ if (!duration)
104
+ return false;
105
+ if (!start || !end || !end.isAfter(start))
106
+ return false;
107
+ const unit = getDurationUnit(duration.type);
108
+ const value = toFiniteNumber(duration.value);
109
+ return !!unit && value > 0;
110
+ }
111
+ function buildTimeSegments(params) {
112
+ const booking = params.booking || {};
113
+ const explicitDatetime = normalizeDateTime(params.datetime);
114
+ const bookingStart = buildBookingDateTime(booking.start_date, booking.start_time);
115
+ const start = bookingStart || explicitDatetime || (0, import_dayjs.default)();
116
+ const bookingEnd = buildBookingDateTime(booking.end_date, booking.end_time);
117
+ if (!shouldSplitByDuration(params.duration, start, bookingEnd)) {
118
+ return [{ start }];
119
+ }
120
+ const unit = getDurationUnit(params.duration.type);
121
+ const value = toFiniteNumber(params.duration.value);
122
+ const segments = [];
123
+ let cursor = start;
124
+ let guard = 0;
125
+ while (cursor.isBefore(bookingEnd) && guard < 1e4) {
126
+ const next = cursor.add(value, unit);
127
+ segments.push({
128
+ start: cursor,
129
+ end: next.isBefore(bookingEnd) ? next : bookingEnd ?? void 0
130
+ });
131
+ cursor = next;
132
+ guard += 1;
133
+ }
134
+ return segments.length ? segments : [{ start }];
135
+ }
136
+ function formatTimePoint(datetime) {
137
+ return datetime.format("YYYY-MM-DD HH:mm:ss");
138
+ }
139
+ function buildPriceSegment(params) {
140
+ const timePoint = formatTimePoint(params.segment.start);
141
+ const quotedPrice = params.quotation && params.productId !== null ? params.quotation.getPriceForProduct({
142
+ productId: params.productId,
143
+ variantId: params.variantId,
144
+ datetime: timePoint,
145
+ customer_id: params.customerId
146
+ }) : null;
147
+ const unitPrice = toPriceString(quotedPrice ?? params.fallbackPrice);
148
+ const quotationShelfId = quotedPrice !== null && params.quotation && params.productId !== null ? params.quotation.getQuotationShelfId({
149
+ productId: params.productId,
150
+ variantId: params.variantId,
151
+ datetime: timePoint,
152
+ customer_id: params.customerId
153
+ }) : 0;
154
+ return {
155
+ start_datetime: timePoint,
156
+ end_datetime: params.segment.end ? formatTimePoint(params.segment.end) : void 0,
157
+ time_point: timePoint,
158
+ unit_price: unitPrice,
159
+ quantity: 1,
160
+ total_price: unitPrice,
161
+ quotation_shelf_id: quotationShelfId,
162
+ source: quotedPrice !== null ? "quotation" : "fallback"
163
+ };
164
+ }
165
+ function calculateBaseSalesProductBookingPrice(params) {
166
+ var _a;
167
+ const product = params.product || {};
168
+ const productId = getProductId(product);
169
+ const variantId = getProductVariantId(product);
170
+ const productQuantity = getProductQuantity(product);
171
+ const fallbackPrice = getFallbackPrice(params);
172
+ const segments = buildTimeSegments(params).map((segment) => buildPriceSegment({
173
+ quotation: params.quotation,
174
+ productId,
175
+ variantId,
176
+ customerId: params.customer_id,
177
+ fallbackPrice,
178
+ segment
179
+ }));
180
+ const unitPrice = segments.reduce(
181
+ (total, segment) => total.plus(segment.total_price),
182
+ new import_decimal.default(0)
183
+ );
184
+ const totalPrice = unitPrice.times(productQuantity);
185
+ const quotationShelfId = ((_a = segments.find((segment) => segment.quotation_shelf_id)) == null ? void 0 : _a.quotation_shelf_id) || 0;
186
+ return {
187
+ product_id: productId,
188
+ product_variant_id: variantId ?? 0,
189
+ customer_id: params.customer_id,
190
+ unit_price: unitPrice.toDecimalPlaces(2).toFixed(2),
191
+ total_price: totalPrice.toDecimalPlaces(2).toFixed(2),
192
+ quantity: productQuantity,
193
+ duration: params.duration,
194
+ quotation_shelf_id: quotationShelfId,
195
+ segments
196
+ };
197
+ }
198
+ // Annotate the CommonJS export names for ESM import in node:
199
+ 0 && (module.exports = {
200
+ calculateBaseSalesProductBookingPrice
201
+ });
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 5 | 4 | 2 | 3 | 6;
314
+ weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -330,7 +330,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
330
330
  count: number;
331
331
  left: number;
332
332
  summaryCount: number;
333
- status: "sold_out" | "lots_of_space" | "filling_up_fast";
333
+ status: "lots_of_space" | "filling_up_fast" | "sold_out";
334
334
  }[];
335
335
  /**
336
336
  * 找到多个资源的公共可用时间段
@@ -1,10 +1,15 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BookingTicketCartView, BookingTicketProductCatalogView, BookingTicketState, IGetCustomerListParams, ICustomer, ILoadProductsParams, ILoadProductDetailParams, IScanResult } from './types';
3
3
  import type { ProductData } from '../../modules';
4
+ import { type BookingContextConfig, type BookingContextDateInput, type BookingContextResource, type BookingContextResourceMap, type BookingContextState, type InitBookingContextParams, type LoadBookingConfigParams, type LoadBookingResourcesParams, type ResourceError, type BookingCalcContext } from '../../modules/BookingContext';
4
5
  import type { OrderCustomerView } from '../../modules/Order/types';
5
6
  import { BaseSalesImpl } from '../BaseSales';
6
7
  import type { ISalesDetail } from '../BaseSales/utils/parseSalesResponse';
7
8
  import type { LoadSalesDetailParams } from '../../modules/Order/types';
9
+ import { AddProductDecideContext, AddProductRequiresDetailPayload } from './utils/addProductDecision';
10
+ import { type BuildCacheItemFromOrderLineInput } from '../../modules/BookingContext/utils/buildCacheItemFromOrderLine';
11
+ import { type BuildNormalProductCacheItemFromOrderLineInput } from '../../modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine';
12
+ import type { AddProductBookingInput, OrderProduct, OrderProductIdentity, UpdateOrderProductParams } from '../../modules/Order/types';
8
13
  export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
9
14
  protected defaultName: string;
10
15
  protected defaultVersion: string;
@@ -17,9 +22,11 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
17
22
  private scan;
18
23
  private productCatalog;
19
24
  /**
20
- * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer。
25
+ * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer + bookingContext
26
+ * bookingContext 是 SalesSdk 加车下沉所需的「预约 UI 上下文」(bookingConfig / resourcesOrigin / date)。
21
27
  */
22
28
  protected getRegisteredModuleNames(): readonly string[];
29
+ protected getSubmitOrderSalesChannel(): string;
23
30
  /**
24
31
  * 业务侧子模块工厂:BookingTicket 自带的 createBookingTicketModule 优先匹配;
25
32
  * 未识别的模块名(如 BookingByStep 公共类型)回退到父类工厂。
@@ -186,6 +193,16 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
186
193
  * 清空下单客户(协议字段 + snapshot)。
187
194
  */
188
195
  clearOrderCustomer(): void;
196
+ /**
197
+ * 重置 tempOrder,并同步清空下单客户运行态。
198
+ *
199
+ * OrderModule.restoreOrder 会重建空单(customer_id 已为 null),但不会:
200
+ * - emit BookingTicket `onOrderCustomerChange`
201
+ * - 重置 CustomerModule.selectedCustomer(老路 getActiveCustomer)
202
+ *
203
+ * 因此在 super.restoreOrder 之后显式清客户,保证 SalesSdk / ticketBooking 订阅方与 tempOrder 一致。
204
+ */
205
+ restoreOrder(): Promise<import("../../modules/Order/types").OrderTempOrder>;
189
206
  /** 内部:基于 OrderModule 当前状态构造一份 OrderCustomerChangePayload。 */
190
207
  private buildOrderCustomerPayload;
191
208
  /**
@@ -291,6 +308,109 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
291
308
  * @returns 其他参数
292
309
  */
293
310
  getOtherParams(): Promise<Record<string, any>>;
311
+ /** 拉取 board config 并写入 BookingContext。 */
312
+ loadBookingConfig(params?: LoadBookingConfigParams): Promise<BookingContextConfig | null>;
313
+ /** 拉取资源全集并写入 BookingContext。 */
314
+ loadBookingResources(params?: LoadBookingResourcesParams): Promise<BookingContextResource[]>;
315
+ /** 初始化 BookingContext(date + config + resources)。 */
316
+ initBookingContext(params?: InitBookingContextParams): Promise<BookingContextState>;
317
+ /** 当前 store 是否已具备与入参等价的 config / resources(无需再请求接口)。 */
318
+ isBookingContextReady(params?: InitBookingContextParams): boolean;
319
+ /** 写入 booking config(来源:`/core/board/management/config`)。 */
320
+ setBookingConfig(config: BookingContextConfig | null): void;
321
+ /** 读取当前 booking config。 */
322
+ getBookingConfig(): BookingContextConfig | null;
323
+ /** 写入资源全集(来源:`/form/schedule`),同步派生 resourcesOriginMap。 */
324
+ setResources(resources: BookingContextResource[] | null | undefined): void;
325
+ /** 读取资源全集(浅克隆)。 */
326
+ getResourcesOrigin(): BookingContextResource[];
327
+ /** 读取资源全集 map(id → resource)。 */
328
+ getResourcesOriginMap(): BookingContextResourceMap;
329
+ /** 写入当前选择的日期;支持 dayjs / Date / string。 */
330
+ setBookingDate(date: BookingContextDateInput): void;
331
+ /** 读取当前选择的日期(统一 string)。 */
332
+ getBookingDate(): string | null;
333
+ /** 读取 BookingContext 完整 store(调试 / 测试 / 透传给 SDK 使用)。 */
334
+ getBookingContextState(): BookingContextState;
335
+ /** 清空 BookingContext(切租户 / destroy 场景)。 */
336
+ clearBookingContext(): void;
337
+ /**
338
+ * 构造 BookingContext 计算上下文(供 getProductExtend / getResourceByIds 等读 API 复用)。
339
+ */
340
+ private buildBookingCalcContext;
341
+ /**
342
+ * 取商品当前可选资源列表(透传 OS BookingContext utils#getResourceByIds)。
343
+ * `extraResources` 用于把拖入未绑定的资源也展示出来。
344
+ */
345
+ getResourcesForProduct(product: any, options?: {
346
+ extraResources?: Array<{
347
+ form_id: number | string;
348
+ id: number;
349
+ }>;
350
+ }): any[];
351
+ /**
352
+ * 拼装 cacheItem 的 _extend / _data(资源 / 容量 / timeObj),与 info2 `getProductExtend` 等价。
353
+ */
354
+ getProductExtend(cacheItem: any, extra?: Partial<BookingCalcContext>): any;
355
+ /**
356
+ * 取资源不可用原因列表(结构化 enum + params,i18n 文案由 UI 渲染)。
357
+ */
358
+ getResourceErrors(resource: any, cacheItem: any): ResourceError[];
359
+ /**
360
+ * 拼装 addProductDecision 通用上下文(从 store 自取)。
361
+ */
362
+ private buildAddProductCtx;
363
+ /**
364
+ * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
365
+ * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
366
+ */
367
+ decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
368
+ /** 规格弹窗 callback 后的第二段决策。 */
369
+ decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
370
+ /**
371
+ * @deprecated 请用 `decideAddProduct`;`autoClose=true` 仅当 action=add。
372
+ */
373
+ decideAutoClose(item: any, options?: Partial<AddProductDecideContext>): {
374
+ autoClose: boolean;
375
+ cacheItem?: any;
376
+ };
377
+ /** 替代 info2 `getIsEject`:商品是否需要弹窗(0/1)。 */
378
+ getIsEject(item: any, type?: 'select' | 'detail'): 0 | 1;
379
+ /** 仅 session 商品(无 variant/option/package)→ true。 */
380
+ getIsOnlySession(item: any): boolean;
381
+ /**
382
+ * 拼装 requiresDetail payload(给 SDK 直接 return 给 UI 用)。
383
+ */
384
+ buildRequiresDetailPayload(item: any, options?: Partial<AddProductDecideContext>): AddProductRequiresDetailPayload;
385
+ /**
386
+ * 把 detail 弹窗回调结果(e, extension_type, detail)转换为 `(product, booking)` 入参。
387
+ * 内部会先拼 cacheItem,再走 cacheItemToBookingInput 严格协议对齐。
388
+ */
389
+ transformDetailToProductAndBooking(input: {
390
+ item: any;
391
+ cacheItem?: any;
392
+ detailResult?: {
393
+ e: any;
394
+ extension_type?: any;
395
+ detail?: any;
396
+ };
397
+ options?: Partial<AddProductDecideContext>;
398
+ }): {
399
+ product: Partial<OrderProduct> & OrderProductIdentity;
400
+ booking?: AddProductBookingInput;
401
+ cacheItem: any;
402
+ };
403
+ /**
404
+ * 从已加车的 order line + booking 反查资源编辑抽屉所需的 cacheItem。
405
+ * 供 SalesSdk「编辑资源」等场景使用;字段语义与 buildCacheItemFromDetail 产出对齐。
406
+ */
407
+ buildCacheItemFromOrderLine(input: BuildCacheItemFromOrderLineInput): Record<string, any>;
408
+ /**
409
+ * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
410
+ */
411
+ buildNormalProductCacheItemFromOrderLine(input: BuildNormalProductCacheItemFromOrderLineInput): Record<string, any>;
412
+ /** 文档别名:与 OrderModule.updateOrderProduct 一致。 */
413
+ updateProductInOrder(params: UpdateOrderProductParams): Promise<OrderProduct[]>;
294
414
  /**
295
415
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
296
416
  * 再清理 BookingTicket 自有资源(scan 监听 + scan 内存缓存)。
@@ -35,12 +35,16 @@ __export(BookingTicket_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(BookingTicket_exports);
37
37
  var import_types = require("./types");
38
+ var import_BookingContext = require("../../modules/BookingContext");
38
39
  var import_BaseSales = require("../BaseSales");
39
40
  var import_scan = __toESM(require("./utils/scan"));
40
41
  var import_orderCustomer = require("./utils/orderCustomer");
41
42
  var import_handleScan = require("./utils/scan/handleScan");
42
43
  var import_scanCache = __toESM(require("./utils/scan/scanCache"));
43
44
  var import_cartView = require("./utils/cartView");
45
+ var import_addProductDecision = require("./utils/addProductDecision");
46
+ var import_buildCacheItemFromOrderLine = require("../../modules/BookingContext/utils/buildCacheItemFromOrderLine");
47
+ var import_buildNormalProductCacheItemFromOrderLine = require("../../modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine");
44
48
  var import_bookingStatus = require("./utils/bookingStatus");
45
49
  __reExport(BookingTicket_exports, require("./types"), module.exports);
46
50
  var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
@@ -56,10 +60,14 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
56
60
  this.productCatalog = [];
57
61
  }
58
62
  /**
59
- * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer。
63
+ * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer + bookingContext
64
+ * bookingContext 是 SalesSdk 加车下沉所需的「预约 UI 上下文」(bookingConfig / resourcesOrigin / date)。
60
65
  */
61
66
  getRegisteredModuleNames() {
62
- return [...super.getRegisteredModuleNames(), "customer"];
67
+ return [...super.getRegisteredModuleNames(), "customer", "bookingContext"];
68
+ }
69
+ getSubmitOrderSalesChannel() {
70
+ return "pos";
63
71
  }
64
72
  /**
65
73
  * 业务侧子模块工厂:BookingTicket 自带的 createBookingTicketModule 优先匹配;
@@ -192,6 +200,10 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
192
200
  */
193
201
  async loadProducts(params = {}, options) {
194
202
  const { schedule_date, customer_id, menu_list_ids, schedule_datetime } = params;
203
+ const bookingDate = schedule_date || (schedule_datetime ? String(schedule_datetime).slice(0, 10) : "");
204
+ if (bookingDate) {
205
+ this.setBookingDate(bookingDate);
206
+ }
195
207
  try {
196
208
  const result = await this.store.products.loadProducts({
197
209
  with_count: ["bundleGroup", "optionGroup"],
@@ -408,6 +420,22 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
408
420
  this.store.order.clearOrderCustomer();
409
421
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, null);
410
422
  }
423
+ /**
424
+ * 重置 tempOrder,并同步清空下单客户运行态。
425
+ *
426
+ * OrderModule.restoreOrder 会重建空单(customer_id 已为 null),但不会:
427
+ * - emit BookingTicket `onOrderCustomerChange`
428
+ * - 重置 CustomerModule.selectedCustomer(老路 getActiveCustomer)
429
+ *
430
+ * 因此在 super.restoreOrder 之后显式清客户,保证 SalesSdk / ticketBooking 订阅方与 tempOrder 一致。
431
+ */
432
+ async restoreOrder() {
433
+ var _a;
434
+ const tempOrder = await super.restoreOrder();
435
+ this.clearOrderCustomer();
436
+ (_a = this.store.customer) == null ? void 0 : _a.setSelectedCustomer(null);
437
+ return tempOrder;
438
+ }
411
439
  /** 内部:基于 OrderModule 当前状态构造一份 OrderCustomerChangePayload。 */
412
440
  buildOrderCustomerPayload() {
413
441
  const patch = this.store.order.getOrderCustomer();
@@ -613,6 +641,183 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
613
641
  async getOtherParams() {
614
642
  return this.otherParams;
615
643
  }
644
+ // ─── BookingContext API(透传给 BookingContextModule) ──────────────────────
645
+ // SalesSdkProvider 挂载时默认调 initBookingContext;也可由 UI 显式 set* 灌入已有数据。
646
+ /** 拉取 board config 并写入 BookingContext。 */
647
+ loadBookingConfig(params) {
648
+ return this.store.bookingContext.loadBookingConfig(params);
649
+ }
650
+ /** 拉取资源全集并写入 BookingContext。 */
651
+ loadBookingResources(params) {
652
+ return this.store.bookingContext.loadResources(params);
653
+ }
654
+ /** 初始化 BookingContext(date + config + resources)。 */
655
+ initBookingContext(params) {
656
+ return this.store.bookingContext.initBookingContext(params);
657
+ }
658
+ /** 当前 store 是否已具备与入参等价的 config / resources(无需再请求接口)。 */
659
+ isBookingContextReady(params) {
660
+ return this.store.bookingContext.isBookingContextReady(params);
661
+ }
662
+ /** 写入 booking config(来源:`/core/board/management/config`)。 */
663
+ setBookingConfig(config) {
664
+ this.store.bookingContext.setBookingConfig(config);
665
+ }
666
+ /** 读取当前 booking config。 */
667
+ getBookingConfig() {
668
+ return this.store.bookingContext.getBookingConfig();
669
+ }
670
+ /** 写入资源全集(来源:`/form/schedule`),同步派生 resourcesOriginMap。 */
671
+ setResources(resources) {
672
+ this.store.bookingContext.setResources(resources);
673
+ }
674
+ /** 读取资源全集(浅克隆)。 */
675
+ getResourcesOrigin() {
676
+ return this.store.bookingContext.getResourcesOrigin();
677
+ }
678
+ /** 读取资源全集 map(id → resource)。 */
679
+ getResourcesOriginMap() {
680
+ return this.store.bookingContext.getResourcesOriginMap();
681
+ }
682
+ /** 写入当前选择的日期;支持 dayjs / Date / string。 */
683
+ setBookingDate(date) {
684
+ this.store.bookingContext.setDate(date);
685
+ }
686
+ /** 读取当前选择的日期(统一 string)。 */
687
+ getBookingDate() {
688
+ return this.store.bookingContext.getDate();
689
+ }
690
+ /** 读取 BookingContext 完整 store(调试 / 测试 / 透传给 SDK 使用)。 */
691
+ getBookingContextState() {
692
+ return this.store.bookingContext.getState();
693
+ }
694
+ /** 清空 BookingContext(切租户 / destroy 场景)。 */
695
+ clearBookingContext() {
696
+ this.store.bookingContext.clear();
697
+ }
698
+ /**
699
+ * 构造 BookingContext 计算上下文(供 getProductExtend / getResourceByIds 等读 API 复用)。
700
+ */
701
+ buildBookingCalcContext(extra) {
702
+ const state = this.store.bookingContext.getState();
703
+ const date = (extra == null ? void 0 : extra.date) ?? state.date;
704
+ return {
705
+ bookingConfig: state.bookingConfig,
706
+ resourcesOrigin: state.resourcesOrigin,
707
+ resourcesOriginMap: state.resourcesOriginMap,
708
+ date,
709
+ presetStartTime: (extra == null ? void 0 : extra.presetStartTime) ?? (0, import_BookingContext.derivePresetStartTimeFromDate)(date),
710
+ ...extra || {}
711
+ };
712
+ }
713
+ /**
714
+ * 取商品当前可选资源列表(透传 OS BookingContext utils#getResourceByIds)。
715
+ * `extraResources` 用于把拖入未绑定的资源也展示出来。
716
+ */
717
+ getResourcesForProduct(product, options) {
718
+ var _a, _b;
719
+ const ctx = this.buildBookingCalcContext();
720
+ return (0, import_BookingContext.getResourceByIds)(ctx.resourcesOriginMap || {}, product, {
721
+ resourceTab: (_b = (_a = ctx.bookingConfig) == null ? void 0 : _a.config) == null ? void 0 : _b.resource_tab,
722
+ resourcesOrigin: ctx.resourcesOrigin,
723
+ extraResources: (options == null ? void 0 : options.extraResources) || []
724
+ });
725
+ }
726
+ /**
727
+ * 拼装 cacheItem 的 _extend / _data(资源 / 容量 / timeObj),与 info2 `getProductExtend` 等价。
728
+ */
729
+ getProductExtend(cacheItem, extra) {
730
+ return (0, import_BookingContext.getProductExtend)({
731
+ cacheItem,
732
+ ctx: this.buildBookingCalcContext(extra)
733
+ });
734
+ }
735
+ /**
736
+ * 取资源不可用原因列表(结构化 enum + params,i18n 文案由 UI 渲染)。
737
+ */
738
+ getResourceErrors(resource, cacheItem) {
739
+ return (0, import_BookingContext.getResourceErrors)(resource, cacheItem);
740
+ }
741
+ // ─── addProduct 决策 / 转换 API(SDK 加车下沉所需) ─────────────────────────
742
+ // 这一组方法是 SalesSdkCartContext.addProduct / confirmDetail 的 OS 后端。
743
+ // 调用方传入 ProductData,OS 自取 bookingContext / customer / date 等上下文,
744
+ // 输出 (a) autoClose 决策结果或 (b) `{ product, booking }` 协议入参。
745
+ /**
746
+ * 拼装 addProductDecision 通用上下文(从 store 自取)。
747
+ */
748
+ buildAddProductCtx(extra) {
749
+ var _a, _b;
750
+ const bookingContextState = this.store.bookingContext.getState();
751
+ const date = (extra == null ? void 0 : extra.date) ?? bookingContextState.date;
752
+ const orderCustomerId = ((_a = this.getOrderCustomerSnapshot()) == null ? void 0 : _a.id) ?? ((_b = this.store.order.getTempOrder()) == null ? void 0 : _b.customer_id) ?? void 0;
753
+ return {
754
+ bookingConfig: bookingContextState.bookingConfig,
755
+ resourcesOrigin: bookingContextState.resourcesOrigin,
756
+ resourcesOriginMap: bookingContextState.resourcesOriginMap,
757
+ date,
758
+ presetStartTime: (extra == null ? void 0 : extra.presetStartTime) ?? (0, import_BookingContext.derivePresetStartTimeFromDate)(date),
759
+ customerId: orderCustomerId,
760
+ ...extra || {}
761
+ };
762
+ }
763
+ /**
764
+ * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
765
+ * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
766
+ */
767
+ decideAddProduct(item, options) {
768
+ return (0, import_addProductDecision.decideAddProduct)(item, this.buildAddProductCtx(options));
769
+ }
770
+ /** 规格弹窗 callback 后的第二段决策。 */
771
+ decideAfterDetail(cacheItem, options) {
772
+ return (0, import_addProductDecision.decideAfterDetail)(cacheItem, this.buildAddProductCtx(options));
773
+ }
774
+ /**
775
+ * @deprecated 请用 `decideAddProduct`;`autoClose=true` 仅当 action=add。
776
+ */
777
+ decideAutoClose(item, options) {
778
+ return (0, import_addProductDecision.decideAutoClose)(item, this.buildAddProductCtx(options));
779
+ }
780
+ /** 替代 info2 `getIsEject`:商品是否需要弹窗(0/1)。 */
781
+ getIsEject(item, type = "select") {
782
+ return (0, import_addProductDecision.getIsEject)(item, type);
783
+ }
784
+ /** 仅 session 商品(无 variant/option/package)→ true。 */
785
+ getIsOnlySession(item) {
786
+ return (0, import_addProductDecision.getIsOnlySession)(item);
787
+ }
788
+ /**
789
+ * 拼装 requiresDetail payload(给 SDK 直接 return 给 UI 用)。
790
+ */
791
+ buildRequiresDetailPayload(item, options) {
792
+ return (0, import_addProductDecision.buildRequiresDetailPayload)(item, this.buildAddProductCtx(options));
793
+ }
794
+ /**
795
+ * 把 detail 弹窗回调结果(e, extension_type, detail)转换为 `(product, booking)` 入参。
796
+ * 内部会先拼 cacheItem,再走 cacheItemToBookingInput 严格协议对齐。
797
+ */
798
+ transformDetailToProductAndBooking(input) {
799
+ const { item, cacheItem: preparedCacheItem, detailResult, options } = input;
800
+ const ctx = this.buildAddProductCtx(options);
801
+ const cacheItem = preparedCacheItem || (detailResult ? (0, import_addProductDecision.buildCacheItemFromDetail)(item, detailResult, ctx) : (0, import_addProductDecision.buildCacheItemFromCartDetail)(item, ctx));
802
+ return (0, import_addProductDecision.transformDetailToProductAndBooking)(cacheItem, ctx);
803
+ }
804
+ /**
805
+ * 从已加车的 order line + booking 反查资源编辑抽屉所需的 cacheItem。
806
+ * 供 SalesSdk「编辑资源」等场景使用;字段语义与 buildCacheItemFromDetail 产出对齐。
807
+ */
808
+ buildCacheItemFromOrderLine(input) {
809
+ return (0, import_buildCacheItemFromOrderLine.buildCacheItemFromOrderLine)(input);
810
+ }
811
+ /**
812
+ * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
813
+ */
814
+ buildNormalProductCacheItemFromOrderLine(input) {
815
+ return (0, import_buildNormalProductCacheItemFromOrderLine.buildNormalProductCacheItemFromOrderLine)(input);
816
+ }
817
+ /** 文档别名:与 OrderModule.updateOrderProduct 一致。 */
818
+ async updateProductInOrder(params) {
819
+ return this.updateOrderProduct(params);
820
+ }
616
821
  /**
617
822
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
618
823
  * 再清理 BookingTicket 自有资源(scan 监听 + scan 内存缓存)。
@@ -1,4 +1,5 @@
1
1
  import { ProductList, OrderModule } from '../../modules';
2
+ import { BookingContextModule } from '../../modules/BookingContext';
2
3
  import { CustomerModule } from '../../modules/Customer';
3
4
  import { SalesSummaryModule } from '../../modules/SalesSummary';
4
5
  import { ScheduleModule } from '../../modules/Schedule';
@@ -16,6 +17,7 @@ export interface BookingTicketState extends BaseSalesState {
16
17
  salesSummary: SalesSummaryModule;
17
18
  schedule: ScheduleModule;
18
19
  customer: CustomerModule;
20
+ bookingContext: BookingContextModule;
19
21
  }
20
22
  export declare function createBookingTicketModule<T extends keyof BookingTicketState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingTicketState[T] | null;
21
23
  export declare enum BookingTicketHooks {
@@ -24,6 +24,7 @@ __export(types_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(types_exports);
26
26
  var import_modules = require("../../modules");
27
+ var import_BookingContext = require("../../modules/BookingContext");
27
28
  var import_Customer = require("../../modules/Customer");
28
29
  var import_SalesSummary = require("../../modules/SalesSummary");
29
30
  var import_Schedule = require("../../modules/Schedule");
@@ -54,6 +55,11 @@ function createBookingTicketModule(moduleName, solutionName, name, version) {
54
55
  `${solutionName}_${name || moduleName}`,
55
56
  version
56
57
  );
58
+ case "bookingContext":
59
+ return new import_BookingContext.BookingContextModule(
60
+ `${solutionName}_${name || moduleName}`,
61
+ version
62
+ );
57
63
  default:
58
64
  return null;
59
65
  }