@pisell/pisellos 2.2.171 → 2.2.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 (156) 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 +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -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.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +47 -16
  38. package/dist/modules/Order/index.js +743 -334
  39. package/dist/modules/Order/types.d.ts +57 -17
  40. package/dist/modules/Order/types.js +2 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +23 -1
  44. package/dist/modules/Order/utils.js +139 -30
  45. package/dist/modules/Quotation/index.js +16 -5
  46. package/dist/modules/Rules/index.d.ts +4 -0
  47. package/dist/modules/Rules/index.js +26 -10
  48. package/dist/modules/SalesSummary/index.js +4 -2
  49. package/dist/modules/Schedule/index.js +6 -2
  50. package/dist/modules/index.d.ts +1 -0
  51. package/dist/modules/index.js +2 -1
  52. package/dist/server/index.js +10 -6
  53. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  54. package/dist/server/modules/products/index.js +9 -8
  55. package/dist/server/modules/schedule/index.js +13 -6
  56. package/dist/solution/BaseSales/index.d.ts +65 -7
  57. package/dist/solution/BaseSales/index.js +1066 -315
  58. package/dist/solution/BaseSales/types.d.ts +53 -1
  59. package/dist/solution/BaseSales/types.js +3 -1
  60. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  61. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  62. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
  63. package/dist/solution/BaseSales/utils.js +46 -8
  64. package/dist/solution/BookingTicket/index.d.ts +134 -2
  65. package/dist/solution/BookingTicket/index.js +768 -175
  66. package/dist/solution/BookingTicket/types.d.ts +2 -0
  67. package/dist/solution/BookingTicket/types.js +3 -0
  68. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  69. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  70. package/dist/solution/ScanOrder/index.d.ts +9 -3
  71. package/dist/solution/ScanOrder/index.js +231 -128
  72. package/dist/solution/ScanOrder/utils.js +46 -8
  73. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  74. package/dist/solution/ShopDiscount/index.js +18 -23
  75. package/dist/solution/VenueBooking/index.d.ts +5 -9
  76. package/dist/solution/VenueBooking/index.js +103 -55
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  79. package/lib/modules/BookingContext/index.d.ts +37 -0
  80. package/lib/modules/BookingContext/index.js +297 -0
  81. package/lib/modules/BookingContext/types.d.ts +102 -0
  82. package/lib/modules/BookingContext/types.js +34 -0
  83. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  87. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  88. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  89. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  90. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  91. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  93. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  94. package/lib/modules/BookingContext/utils/index.js +43 -0
  95. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  96. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  97. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  98. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  99. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  100. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  101. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  102. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  103. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  104. package/lib/modules/BookingContext/utils/resources.js +377 -0
  105. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  106. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  107. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  108. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  109. package/lib/modules/Customer/index.d.ts +6 -0
  110. package/lib/modules/Customer/index.js +26 -11
  111. package/lib/modules/Customer/types.d.ts +2 -0
  112. package/lib/modules/Discount/index.d.ts +2 -4
  113. package/lib/modules/Discount/index.js +8 -63
  114. package/lib/modules/Discount/types.d.ts +1 -7
  115. package/lib/modules/Order/index.d.ts +47 -16
  116. package/lib/modules/Order/index.js +389 -90
  117. package/lib/modules/Order/types.d.ts +57 -17
  118. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  119. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  120. package/lib/modules/Order/utils.d.ts +23 -1
  121. package/lib/modules/Order/utils.js +145 -21
  122. package/lib/modules/Quotation/index.js +17 -6
  123. package/lib/modules/Rules/index.d.ts +4 -0
  124. package/lib/modules/Rules/index.js +22 -14
  125. package/lib/modules/SalesSummary/index.js +4 -2
  126. package/lib/modules/Schedule/index.js +3 -1
  127. package/lib/modules/index.d.ts +1 -0
  128. package/lib/modules/index.js +3 -1
  129. package/lib/server/index.js +2 -0
  130. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  131. package/lib/server/modules/products/index.js +8 -9
  132. package/lib/server/modules/schedule/index.js +2 -1
  133. package/lib/solution/BaseSales/index.d.ts +65 -7
  134. package/lib/solution/BaseSales/index.js +492 -20
  135. package/lib/solution/BaseSales/types.d.ts +53 -1
  136. package/lib/solution/BaseSales/types.js +3 -1
  137. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  138. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  139. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
  140. package/lib/solution/BaseSales/utils.js +46 -6
  141. package/lib/solution/BookingTicket/index.d.ts +134 -2
  142. package/lib/solution/BookingTicket/index.js +341 -8
  143. package/lib/solution/BookingTicket/types.d.ts +2 -0
  144. package/lib/solution/BookingTicket/types.js +6 -0
  145. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  146. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  147. package/lib/solution/ScanOrder/index.d.ts +9 -3
  148. package/lib/solution/ScanOrder/index.js +147 -66
  149. package/lib/solution/ScanOrder/utils.js +46 -6
  150. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  151. package/lib/solution/ShopDiscount/index.js +2 -4
  152. package/lib/solution/VenueBooking/index.d.ts +5 -9
  153. package/lib/solution/VenueBooking/index.js +50 -14
  154. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  155. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  156. package/package.json +2 -2
@@ -1,10 +1,16 @@
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';
7
+ import type { BaseSalesScanCodeResult } from '../BaseSales/types';
6
8
  import type { ISalesDetail } from '../BaseSales/utils/parseSalesResponse';
7
9
  import type { LoadSalesDetailParams } from '../../modules/Order/types';
10
+ import { AddProductDecideContext, AddProductRequiresDetailPayload } from './utils/addProductDecision';
11
+ import { type BuildCacheItemFromOrderLineInput } from '../../modules/BookingContext/utils/buildCacheItemFromOrderLine';
12
+ import { type BuildNormalProductCacheItemFromOrderLineInput } from '../../modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine';
13
+ import type { AddProductBookingInput, OrderProduct, OrderProductIdentity, UpdateOrderProductParams } from '../../modules/Order/types';
8
14
  export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
9
15
  protected defaultName: string;
10
16
  protected defaultVersion: string;
@@ -16,10 +22,14 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
16
22
  private platform;
17
23
  private scan;
18
24
  private productCatalog;
25
+ private orderCustomerDiscountRefreshInFlight;
26
+ private orderCustomerDiscountRefreshCustomerId;
19
27
  /**
20
- * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer。
28
+ * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer + bookingContext
29
+ * bookingContext 是 SalesSdk 加车下沉所需的「预约 UI 上下文」(bookingConfig / resourcesOrigin / date)。
21
30
  */
22
31
  protected getRegisteredModuleNames(): readonly string[];
32
+ protected getSubmitOrderSalesChannel(): string;
23
33
  /**
24
34
  * 业务侧子模块工厂:BookingTicket 自带的 createBookingTicketModule 优先匹配;
25
35
  * 未识别的模块名(如 BookingByStep 公共类型)回退到父类工厂。
@@ -34,6 +44,14 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
34
44
  * 让现有 setActiveCustomer / getActiveCustomer 调用方零成本拿到详情态客户。
35
45
  */
36
46
  loadSalesDetail(orderIdOrParams: number | string | LoadSalesDetailParams): Promise<ISalesDetail>;
47
+ scanPromotionCode(code: string, customerId?: number): Promise<BaseSalesScanCodeResult>;
48
+ private hydrateOrderCustomerFromScanDiscounts;
49
+ private getDiscountCustomerId;
50
+ private resolveCustomerByDiscountCustomerId;
51
+ private findCustomerById;
52
+ private normalizeCustomer;
53
+ private getRawCustomerId;
54
+ private hasUsableCustomerDetails;
37
55
  /**
38
56
  * 更新当前预约的 appointment_status。
39
57
  *
@@ -186,8 +204,19 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
186
204
  * 清空下单客户(协议字段 + snapshot)。
187
205
  */
188
206
  clearOrderCustomer(): void;
207
+ /**
208
+ * 重置 tempOrder,并同步清空下单客户运行态。
209
+ *
210
+ * OrderModule.restoreOrder 会重建空单(customer_id 已为 null),但不会:
211
+ * - emit BookingTicket `onOrderCustomerChange`
212
+ * - 重置 CustomerModule.selectedCustomer(老路 getActiveCustomer)
213
+ *
214
+ * 因此在 super.restoreOrder 之后显式清客户,保证 SalesSdk / ticketBooking 订阅方与 tempOrder 一致。
215
+ */
216
+ restoreOrder(): Promise<import("../../modules/Order/types").OrderTempOrder>;
189
217
  /** 内部:基于 OrderModule 当前状态构造一份 OrderCustomerChangePayload。 */
190
218
  private buildOrderCustomerPayload;
219
+ private refreshDiscountConfigAfterOrderCustomerChange;
191
220
  /**
192
221
  * 获取客户分页信息
193
222
  * @returns 分页信息
@@ -231,7 +260,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
231
260
  * 获取当前的客户搜索条件
232
261
  * @returns 当前搜索条件
233
262
  */
234
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
263
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
235
264
  /**
236
265
  * 获取客户列表状态(包含滚动加载相关状态)
237
266
  * @returns 客户状态
@@ -291,6 +320,109 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
291
320
  * @returns 其他参数
292
321
  */
293
322
  getOtherParams(): Promise<Record<string, any>>;
323
+ /** 拉取 board config 并写入 BookingContext。 */
324
+ loadBookingConfig(params?: LoadBookingConfigParams): Promise<BookingContextConfig | null>;
325
+ /** 拉取资源全集并写入 BookingContext。 */
326
+ loadBookingResources(params?: LoadBookingResourcesParams): Promise<BookingContextResource[]>;
327
+ /** 初始化 BookingContext(date + config + resources)。 */
328
+ initBookingContext(params?: InitBookingContextParams): Promise<BookingContextState>;
329
+ /** 当前 store 是否已具备与入参等价的 config / resources(无需再请求接口)。 */
330
+ isBookingContextReady(params?: InitBookingContextParams): boolean;
331
+ /** 写入 booking config(来源:`/core/board/management/config`)。 */
332
+ setBookingConfig(config: BookingContextConfig | null): void;
333
+ /** 读取当前 booking config。 */
334
+ getBookingConfig(): BookingContextConfig | null;
335
+ /** 写入资源全集(来源:`/form/schedule`),同步派生 resourcesOriginMap。 */
336
+ setResources(resources: BookingContextResource[] | null | undefined): void;
337
+ /** 读取资源全集(浅克隆)。 */
338
+ getResourcesOrigin(): BookingContextResource[];
339
+ /** 读取资源全集 map(id → resource)。 */
340
+ getResourcesOriginMap(): BookingContextResourceMap;
341
+ /** 写入当前选择的日期;支持 dayjs / Date / string。 */
342
+ setBookingDate(date: BookingContextDateInput): void;
343
+ /** 读取当前选择的日期(统一 string)。 */
344
+ getBookingDate(): string | null;
345
+ /** 读取 BookingContext 完整 store(调试 / 测试 / 透传给 SDK 使用)。 */
346
+ getBookingContextState(): BookingContextState;
347
+ /** 清空 BookingContext(切租户 / destroy 场景)。 */
348
+ clearBookingContext(): void;
349
+ /**
350
+ * 构造 BookingContext 计算上下文(供 getProductExtend / getResourceByIds 等读 API 复用)。
351
+ */
352
+ private buildBookingCalcContext;
353
+ /**
354
+ * 取商品当前可选资源列表(透传 OS BookingContext utils#getResourceByIds)。
355
+ * `extraResources` 用于把拖入未绑定的资源也展示出来。
356
+ */
357
+ getResourcesForProduct(product: any, options?: {
358
+ extraResources?: Array<{
359
+ form_id: number | string;
360
+ id: number;
361
+ }>;
362
+ }): any[];
363
+ /**
364
+ * 拼装 cacheItem 的 _extend / _data(资源 / 容量 / timeObj),与 info2 `getProductExtend` 等价。
365
+ */
366
+ getProductExtend(cacheItem: any, extra?: Partial<BookingCalcContext>): any;
367
+ /**
368
+ * 取资源不可用原因列表(结构化 enum + params,i18n 文案由 UI 渲染)。
369
+ */
370
+ getResourceErrors(resource: any, cacheItem: any): ResourceError[];
371
+ /**
372
+ * 拼装 addProductDecision 通用上下文(从 store 自取)。
373
+ */
374
+ private buildAddProductCtx;
375
+ /**
376
+ * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
377
+ * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
378
+ */
379
+ decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
380
+ /** 规格弹窗 callback 后的第二段决策。 */
381
+ decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
382
+ /**
383
+ * @deprecated 请用 `decideAddProduct`;`autoClose=true` 仅当 action=add。
384
+ */
385
+ decideAutoClose(item: any, options?: Partial<AddProductDecideContext>): {
386
+ autoClose: boolean;
387
+ cacheItem?: any;
388
+ };
389
+ /** 替代 info2 `getIsEject`:商品是否需要弹窗(0/1)。 */
390
+ getIsEject(item: any, type?: 'select' | 'detail'): 0 | 1;
391
+ /** 仅 session 商品(无 variant/option/package)→ true。 */
392
+ getIsOnlySession(item: any): boolean;
393
+ /**
394
+ * 拼装 requiresDetail payload(给 SDK 直接 return 给 UI 用)。
395
+ */
396
+ buildRequiresDetailPayload(item: any, options?: Partial<AddProductDecideContext>): AddProductRequiresDetailPayload;
397
+ /**
398
+ * 把 detail 弹窗回调结果(e, extension_type, detail)转换为 `(product, booking)` 入参。
399
+ * 内部会先拼 cacheItem,再走 cacheItemToBookingInput 严格协议对齐。
400
+ */
401
+ transformDetailToProductAndBooking(input: {
402
+ item: any;
403
+ cacheItem?: any;
404
+ detailResult?: {
405
+ e: any;
406
+ extension_type?: any;
407
+ detail?: any;
408
+ };
409
+ options?: Partial<AddProductDecideContext>;
410
+ }): {
411
+ product: Partial<OrderProduct> & OrderProductIdentity;
412
+ booking?: AddProductBookingInput;
413
+ cacheItem: any;
414
+ };
415
+ /**
416
+ * 从已加车的 order line + booking 反查资源编辑抽屉所需的 cacheItem。
417
+ * 供 SalesSdk「编辑资源」等场景使用;字段语义与 buildCacheItemFromDetail 产出对齐。
418
+ */
419
+ buildCacheItemFromOrderLine(input: BuildCacheItemFromOrderLineInput): Record<string, any>;
420
+ /**
421
+ * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
422
+ */
423
+ buildNormalProductCacheItemFromOrderLine(input: BuildNormalProductCacheItemFromOrderLineInput): Record<string, any>;
424
+ /** 文档别名:与 OrderModule.updateOrderProduct 一致。 */
425
+ updateProductInOrder(params: UpdateOrderProductParams): Promise<OrderProduct[]>;
294
426
  /**
295
427
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
296
428
  * 再清理 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 {
@@ -54,12 +58,18 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
54
58
  */
55
59
  this.store = {};
56
60
  this.productCatalog = [];
61
+ this.orderCustomerDiscountRefreshInFlight = null;
62
+ this.orderCustomerDiscountRefreshCustomerId = null;
57
63
  }
58
64
  /**
59
- * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer。
65
+ * 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer + bookingContext
66
+ * bookingContext 是 SalesSdk 加车下沉所需的「预约 UI 上下文」(bookingConfig / resourcesOrigin / date)。
60
67
  */
61
68
  getRegisteredModuleNames() {
62
- return [...super.getRegisteredModuleNames(), "customer"];
69
+ return [...super.getRegisteredModuleNames(), "customer", "bookingContext"];
70
+ }
71
+ getSubmitOrderSalesChannel() {
72
+ return "pos";
63
73
  }
64
74
  /**
65
75
  * 业务侧子模块工厂:BookingTicket 自带的 createBookingTicketModule 优先匹配;
@@ -96,22 +106,110 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
96
106
  console.log(sales, "1234sales");
97
107
  const customerModule = this.store.customer;
98
108
  const detailCustomer = sales == null ? void 0 : sales.customer;
99
- if (customerModule && detailCustomer) {
100
- const { id: detailCustomerId, ...detailCustomerRest } = detailCustomer ?? {};
109
+ const orderCustomerSnapshot = this.store.order.getOrderCustomerSnapshot();
110
+ const protocolCustomerId = sales == null ? void 0 : sales.customer_id;
111
+ const protocolCustomer = protocolCustomerId !== void 0 && protocolCustomerId !== null ? {
112
+ id: protocolCustomerId,
113
+ name: String((sales == null ? void 0 : sales.customer_name) || ""),
114
+ phone: sales == null ? void 0 : sales.phone,
115
+ email: sales == null ? void 0 : sales.email,
116
+ country_calling_code: sales == null ? void 0 : sales.country_calling_code
117
+ } : null;
118
+ const selectedCustomer = detailCustomer ?? orderCustomerSnapshot ?? protocolCustomer;
119
+ if (customerModule && selectedCustomer) {
120
+ const { id: detailCustomerId, ...detailCustomerRest } = selectedCustomer ?? {};
101
121
  const rawId = detailCustomerId ?? "";
102
122
  const customer = {
103
123
  ...detailCustomerRest,
104
124
  id: rawId == null ? "" : rawId,
105
- name: (detailCustomer == null ? void 0 : detailCustomer.name) ?? "",
106
- phone: detailCustomer == null ? void 0 : detailCustomer.phone,
107
- email: detailCustomer == null ? void 0 : detailCustomer.email,
108
- country_calling_code: detailCustomer == null ? void 0 : detailCustomer.country_calling_code
125
+ name: (selectedCustomer == null ? void 0 : selectedCustomer.name) ?? "",
126
+ phone: selectedCustomer == null ? void 0 : selectedCustomer.phone,
127
+ email: selectedCustomer == null ? void 0 : selectedCustomer.email,
128
+ country_calling_code: selectedCustomer == null ? void 0 : selectedCustomer.country_calling_code
109
129
  };
110
130
  customerModule.setSelectedCustomer(customer);
111
131
  this.setOrderCustomer(customer);
132
+ await this.store.order.saveDraft();
112
133
  }
113
134
  return sales;
114
135
  }
136
+ async scanPromotionCode(code, customerId) {
137
+ if (!this.store.order)
138
+ throw new Error("order 模块未初始化");
139
+ const raw = await this.store.order.scanCode(code, customerId);
140
+ if (raw.isAvailable) {
141
+ await this.hydrateOrderCustomerFromScanDiscounts(raw.scannedDiscountList);
142
+ await this.store.order.recalculateSummary({ createIfMissing: true });
143
+ this.store.order.persistTempOrder();
144
+ }
145
+ return {
146
+ isAvailable: raw.isAvailable,
147
+ type: raw.type,
148
+ unavailableReason: raw.unavailableReason
149
+ };
150
+ }
151
+ async hydrateOrderCustomerFromScanDiscounts(discounts) {
152
+ const currentOrderCustomer = this.store.order.getOrderCustomer();
153
+ if (currentOrderCustomer)
154
+ return;
155
+ const customerId = this.getDiscountCustomerId(discounts);
156
+ if (!customerId)
157
+ return;
158
+ const customer = await this.resolveCustomerByDiscountCustomerId(customerId);
159
+ if (!customer)
160
+ return;
161
+ this.store.customer.setSelectedCustomer(customer);
162
+ this.setOrderCustomer(customer);
163
+ }
164
+ getDiscountCustomerId(discounts) {
165
+ const discount = discounts.find((item) => item.customer_id != null);
166
+ const customerId = Number(discount == null ? void 0 : discount.customer_id);
167
+ if (!Number.isFinite(customerId) || customerId <= 0)
168
+ return null;
169
+ return customerId;
170
+ }
171
+ async resolveCustomerByDiscountCustomerId(customerId) {
172
+ var _a;
173
+ const localCustomers = this.store.customer.getCustomers();
174
+ const localCustomer = this.findCustomerById(localCustomers, customerId);
175
+ const normalizedLocalCustomer = localCustomer ? this.normalizeCustomer(localCustomer) : null;
176
+ if (normalizedLocalCustomer && this.hasUsableCustomerDetails(normalizedLocalCustomer)) {
177
+ return normalizedLocalCustomer;
178
+ }
179
+ const result = await this.store.customer.queryCustomerList({
180
+ ids: [customerId],
181
+ skip: 1,
182
+ num: 1
183
+ });
184
+ const remoteCustomer = this.findCustomerById((result == null ? void 0 : result.list) || [], customerId) || ((_a = result == null ? void 0 : result.list) == null ? void 0 : _a[0]) || null;
185
+ return remoteCustomer ? this.normalizeCustomer(remoteCustomer) : null;
186
+ }
187
+ findCustomerById(customers = [], customerId) {
188
+ return customers.find((customer) => {
189
+ const rawId = this.getRawCustomerId(customer);
190
+ return rawId !== null && String(rawId) === String(customerId);
191
+ }) || null;
192
+ }
193
+ normalizeCustomer(customer) {
194
+ const raw = customer;
195
+ const rawId = this.getRawCustomerId(customer);
196
+ const name = customer.name || raw.display_name || raw.nickname || raw.customer_name || [raw.first_name, raw.last_name].filter(Boolean).join(" ") || "";
197
+ return {
198
+ ...customer,
199
+ id: rawId ?? customer.id,
200
+ name,
201
+ phone: customer.phone ?? raw.phone ?? raw.mobile ?? "",
202
+ email: customer.email ?? raw.email ?? "",
203
+ country_calling_code: customer.country_calling_code ?? raw.country_calling_code ?? ""
204
+ };
205
+ }
206
+ getRawCustomerId(customer) {
207
+ const raw = customer;
208
+ return customer.id ?? raw.customer_id ?? raw.customerId ?? null;
209
+ }
210
+ hasUsableCustomerDetails(customer) {
211
+ return !!(customer.name || customer.phone || customer.email || customer.display_name || customer.customer_name);
212
+ }
115
213
  /**
116
214
  * 更新当前预约的 appointment_status。
117
215
  *
@@ -192,6 +290,10 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
192
290
  */
193
291
  async loadProducts(params = {}, options) {
194
292
  const { schedule_date, customer_id, menu_list_ids, schedule_datetime } = params;
293
+ const bookingDate = schedule_datetime || schedule_date || "";
294
+ if (bookingDate) {
295
+ this.setBookingDate(bookingDate);
296
+ }
195
297
  try {
196
298
  const result = await this.store.products.loadProducts({
197
299
  with_count: ["bundleGroup", "optionGroup"],
@@ -388,6 +490,7 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
388
490
  this.store.order.setOrderCustomer(patch, customer);
389
491
  const next = this.buildOrderCustomerPayload();
390
492
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, next);
493
+ this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
391
494
  }
392
495
  /**
393
496
  * 读取 tempOrder 上的下单客户协议字段;customer_id 缺失时返回 null。
@@ -405,9 +508,34 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
405
508
  * 清空下单客户(协议字段 + snapshot)。
406
509
  */
407
510
  clearOrderCustomer() {
511
+ var _a, _b;
408
512
  this.store.order.clearOrderCustomer();
513
+ const orderStore = this.store.order.store || {};
514
+ const discountModule = orderStore.discount;
515
+ void ((_a = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _a.call(discountModule, []));
516
+ void ((_b = discountModule == null ? void 0 : discountModule.setDiscountList) == null ? void 0 : _b.call(discountModule, []));
517
+ this.store.order.applyDiscount();
518
+ void this.store.order.recalculateSummary({ createIfMissing: true }).then(() => this.store.order.persistTempOrder()).catch((error) => {
519
+ console.error("Failed to recalculate summary after clearing customer:", error);
520
+ });
409
521
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, null);
410
522
  }
523
+ /**
524
+ * 重置 tempOrder,并同步清空下单客户运行态。
525
+ *
526
+ * OrderModule.restoreOrder 会重建空单(customer_id 已为 null),但不会:
527
+ * - emit BookingTicket `onOrderCustomerChange`
528
+ * - 重置 CustomerModule.selectedCustomer(老路 getActiveCustomer)
529
+ *
530
+ * 因此在 super.restoreOrder 之后显式清客户,保证 SalesSdk / ticketBooking 订阅方与 tempOrder 一致。
531
+ */
532
+ async restoreOrder() {
533
+ var _a;
534
+ const tempOrder = await super.restoreOrder();
535
+ this.clearOrderCustomer();
536
+ (_a = this.store.customer) == null ? void 0 : _a.setSelectedCustomer(null);
537
+ return tempOrder;
538
+ }
411
539
  /** 内部:基于 OrderModule 当前状态构造一份 OrderCustomerChangePayload。 */
412
540
  buildOrderCustomerPayload() {
413
541
  const patch = this.store.order.getOrderCustomer();
@@ -418,6 +546,34 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
418
546
  snapshot: this.store.order.getOrderCustomerSnapshot()
419
547
  };
420
548
  }
549
+ refreshDiscountConfigAfterOrderCustomerChange(customerId) {
550
+ if (!customerId || customerId === 1)
551
+ return;
552
+ if (this.orderCustomerDiscountRefreshInFlight && this.orderCustomerDiscountRefreshCustomerId === customerId) {
553
+ return;
554
+ }
555
+ const previousRefresh = this.orderCustomerDiscountRefreshInFlight;
556
+ const refreshTask = (async () => {
557
+ if (previousRefresh) {
558
+ await previousRefresh.catch(() => void 0);
559
+ }
560
+ const currentCustomer = this.store.order.getOrderCustomer();
561
+ if (!currentCustomer || Number(currentCustomer.customer_id) !== customerId) {
562
+ return;
563
+ }
564
+ await this.loadDiscountConfig({ customerId });
565
+ })();
566
+ this.orderCustomerDiscountRefreshInFlight = refreshTask;
567
+ this.orderCustomerDiscountRefreshCustomerId = customerId;
568
+ refreshTask.catch((error) => {
569
+ console.error("Failed to load discount config after customer change:", error);
570
+ }).finally(() => {
571
+ if (this.orderCustomerDiscountRefreshInFlight !== refreshTask)
572
+ return;
573
+ this.orderCustomerDiscountRefreshInFlight = null;
574
+ this.orderCustomerDiscountRefreshCustomerId = null;
575
+ });
576
+ }
421
577
  /**
422
578
  * 获取客户分页信息
423
579
  * @returns 分页信息
@@ -613,6 +769,183 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
613
769
  async getOtherParams() {
614
770
  return this.otherParams;
615
771
  }
772
+ // ─── BookingContext API(透传给 BookingContextModule) ──────────────────────
773
+ // SalesSdkProvider 挂载时默认调 initBookingContext;也可由 UI 显式 set* 灌入已有数据。
774
+ /** 拉取 board config 并写入 BookingContext。 */
775
+ loadBookingConfig(params) {
776
+ return this.store.bookingContext.loadBookingConfig(params);
777
+ }
778
+ /** 拉取资源全集并写入 BookingContext。 */
779
+ loadBookingResources(params) {
780
+ return this.store.bookingContext.loadResources(params);
781
+ }
782
+ /** 初始化 BookingContext(date + config + resources)。 */
783
+ initBookingContext(params) {
784
+ return this.store.bookingContext.initBookingContext(params);
785
+ }
786
+ /** 当前 store 是否已具备与入参等价的 config / resources(无需再请求接口)。 */
787
+ isBookingContextReady(params) {
788
+ return this.store.bookingContext.isBookingContextReady(params);
789
+ }
790
+ /** 写入 booking config(来源:`/core/board/management/config`)。 */
791
+ setBookingConfig(config) {
792
+ this.store.bookingContext.setBookingConfig(config);
793
+ }
794
+ /** 读取当前 booking config。 */
795
+ getBookingConfig() {
796
+ return this.store.bookingContext.getBookingConfig();
797
+ }
798
+ /** 写入资源全集(来源:`/form/schedule`),同步派生 resourcesOriginMap。 */
799
+ setResources(resources) {
800
+ this.store.bookingContext.setResources(resources);
801
+ }
802
+ /** 读取资源全集(浅克隆)。 */
803
+ getResourcesOrigin() {
804
+ return this.store.bookingContext.getResourcesOrigin();
805
+ }
806
+ /** 读取资源全集 map(id → resource)。 */
807
+ getResourcesOriginMap() {
808
+ return this.store.bookingContext.getResourcesOriginMap();
809
+ }
810
+ /** 写入当前选择的日期;支持 dayjs / Date / string。 */
811
+ setBookingDate(date) {
812
+ this.store.bookingContext.setDate(date);
813
+ }
814
+ /** 读取当前选择的日期(统一 string)。 */
815
+ getBookingDate() {
816
+ return this.store.bookingContext.getDate();
817
+ }
818
+ /** 读取 BookingContext 完整 store(调试 / 测试 / 透传给 SDK 使用)。 */
819
+ getBookingContextState() {
820
+ return this.store.bookingContext.getState();
821
+ }
822
+ /** 清空 BookingContext(切租户 / destroy 场景)。 */
823
+ clearBookingContext() {
824
+ this.store.bookingContext.clear();
825
+ }
826
+ /**
827
+ * 构造 BookingContext 计算上下文(供 getProductExtend / getResourceByIds 等读 API 复用)。
828
+ */
829
+ buildBookingCalcContext(extra) {
830
+ const state = this.store.bookingContext.getState();
831
+ const date = (extra == null ? void 0 : extra.date) ?? state.date;
832
+ return {
833
+ bookingConfig: state.bookingConfig,
834
+ resourcesOrigin: state.resourcesOrigin,
835
+ resourcesOriginMap: state.resourcesOriginMap,
836
+ date,
837
+ presetStartTime: (extra == null ? void 0 : extra.presetStartTime) ?? (0, import_BookingContext.derivePresetStartTimeFromDate)(date),
838
+ ...extra || {}
839
+ };
840
+ }
841
+ /**
842
+ * 取商品当前可选资源列表(透传 OS BookingContext utils#getResourceByIds)。
843
+ * `extraResources` 用于把拖入未绑定的资源也展示出来。
844
+ */
845
+ getResourcesForProduct(product, options) {
846
+ var _a, _b;
847
+ const ctx = this.buildBookingCalcContext();
848
+ return (0, import_BookingContext.getResourceByIds)(ctx.resourcesOriginMap || {}, product, {
849
+ resourceTab: (_b = (_a = ctx.bookingConfig) == null ? void 0 : _a.config) == null ? void 0 : _b.resource_tab,
850
+ resourcesOrigin: ctx.resourcesOrigin,
851
+ extraResources: (options == null ? void 0 : options.extraResources) || []
852
+ });
853
+ }
854
+ /**
855
+ * 拼装 cacheItem 的 _extend / _data(资源 / 容量 / timeObj),与 info2 `getProductExtend` 等价。
856
+ */
857
+ getProductExtend(cacheItem, extra) {
858
+ return (0, import_BookingContext.getProductExtend)({
859
+ cacheItem,
860
+ ctx: this.buildBookingCalcContext(extra)
861
+ });
862
+ }
863
+ /**
864
+ * 取资源不可用原因列表(结构化 enum + params,i18n 文案由 UI 渲染)。
865
+ */
866
+ getResourceErrors(resource, cacheItem) {
867
+ return (0, import_BookingContext.getResourceErrors)(resource, cacheItem);
868
+ }
869
+ // ─── addProduct 决策 / 转换 API(SDK 加车下沉所需) ─────────────────────────
870
+ // 这一组方法是 SalesSdkCartContext.addProduct / confirmDetail 的 OS 后端。
871
+ // 调用方传入 ProductData,OS 自取 bookingContext / customer / date 等上下文,
872
+ // 输出 (a) autoClose 决策结果或 (b) `{ product, booking }` 协议入参。
873
+ /**
874
+ * 拼装 addProductDecision 通用上下文(从 store 自取)。
875
+ */
876
+ buildAddProductCtx(extra) {
877
+ var _a, _b;
878
+ const bookingContextState = this.store.bookingContext.getState();
879
+ const date = (extra == null ? void 0 : extra.date) ?? bookingContextState.date;
880
+ const orderCustomerId = ((_a = this.getOrderCustomerSnapshot()) == null ? void 0 : _a.id) ?? ((_b = this.store.order.getTempOrder()) == null ? void 0 : _b.customer_id) ?? void 0;
881
+ return {
882
+ bookingConfig: bookingContextState.bookingConfig,
883
+ resourcesOrigin: bookingContextState.resourcesOrigin,
884
+ resourcesOriginMap: bookingContextState.resourcesOriginMap,
885
+ date,
886
+ presetStartTime: (extra == null ? void 0 : extra.presetStartTime) ?? (0, import_BookingContext.derivePresetStartTimeFromDate)(date),
887
+ customerId: orderCustomerId,
888
+ ...extra || {}
889
+ };
890
+ }
891
+ /**
892
+ * 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
893
+ * 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
894
+ */
895
+ decideAddProduct(item, options) {
896
+ return (0, import_addProductDecision.decideAddProduct)(item, this.buildAddProductCtx(options));
897
+ }
898
+ /** 规格弹窗 callback 后的第二段决策。 */
899
+ decideAfterDetail(cacheItem, options) {
900
+ return (0, import_addProductDecision.decideAfterDetail)(cacheItem, this.buildAddProductCtx(options));
901
+ }
902
+ /**
903
+ * @deprecated 请用 `decideAddProduct`;`autoClose=true` 仅当 action=add。
904
+ */
905
+ decideAutoClose(item, options) {
906
+ return (0, import_addProductDecision.decideAutoClose)(item, this.buildAddProductCtx(options));
907
+ }
908
+ /** 替代 info2 `getIsEject`:商品是否需要弹窗(0/1)。 */
909
+ getIsEject(item, type = "select") {
910
+ return (0, import_addProductDecision.getIsEject)(item, type);
911
+ }
912
+ /** 仅 session 商品(无 variant/option/package)→ true。 */
913
+ getIsOnlySession(item) {
914
+ return (0, import_addProductDecision.getIsOnlySession)(item);
915
+ }
916
+ /**
917
+ * 拼装 requiresDetail payload(给 SDK 直接 return 给 UI 用)。
918
+ */
919
+ buildRequiresDetailPayload(item, options) {
920
+ return (0, import_addProductDecision.buildRequiresDetailPayload)(item, this.buildAddProductCtx(options));
921
+ }
922
+ /**
923
+ * 把 detail 弹窗回调结果(e, extension_type, detail)转换为 `(product, booking)` 入参。
924
+ * 内部会先拼 cacheItem,再走 cacheItemToBookingInput 严格协议对齐。
925
+ */
926
+ transformDetailToProductAndBooking(input) {
927
+ const { item, cacheItem: preparedCacheItem, detailResult, options } = input;
928
+ const ctx = this.buildAddProductCtx(options);
929
+ const cacheItem = preparedCacheItem || (detailResult ? (0, import_addProductDecision.buildCacheItemFromDetail)(item, detailResult, ctx) : (0, import_addProductDecision.buildCacheItemFromCartDetail)(item, ctx));
930
+ return (0, import_addProductDecision.transformDetailToProductAndBooking)(cacheItem, ctx);
931
+ }
932
+ /**
933
+ * 从已加车的 order line + booking 反查资源编辑抽屉所需的 cacheItem。
934
+ * 供 SalesSdk「编辑资源」等场景使用;字段语义与 buildCacheItemFromDetail 产出对齐。
935
+ */
936
+ buildCacheItemFromOrderLine(input) {
937
+ return (0, import_buildCacheItemFromOrderLine.buildCacheItemFromOrderLine)(input);
938
+ }
939
+ /**
940
+ * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
941
+ */
942
+ buildNormalProductCacheItemFromOrderLine(input) {
943
+ return (0, import_buildNormalProductCacheItemFromOrderLine.buildNormalProductCacheItemFromOrderLine)(input);
944
+ }
945
+ /** 文档别名:与 OrderModule.updateOrderProduct 一致。 */
946
+ async updateProductInOrder(params) {
947
+ return this.updateOrderProduct(params);
948
+ }
616
949
  /**
617
950
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
618
951
  * 再清理 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
  }