@pisell/pisellos 2.3.37 → 2.3.39

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 (169) hide show
  1. package/dist/modules/Discount/index.d.ts +1 -0
  2. package/dist/modules/Discount/index.js +40 -11
  3. package/dist/modules/Discount/types.d.ts +1 -0
  4. package/dist/modules/Holder/index.d.ts +48 -0
  5. package/dist/modules/Holder/index.js +640 -0
  6. package/dist/modules/Holder/types.d.ts +123 -0
  7. package/dist/modules/Holder/types.js +1 -0
  8. package/dist/modules/Holder/utils.d.ts +13 -0
  9. package/dist/modules/Holder/utils.js +34 -0
  10. package/dist/modules/OpenData/index.js +2 -2
  11. package/dist/modules/Order/index.d.ts +11 -28
  12. package/dist/modules/Order/index.js +513 -747
  13. package/dist/modules/Order/types.d.ts +10 -33
  14. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  15. package/dist/modules/Order/utils.d.ts +10 -0
  16. package/dist/modules/Order/utils.js +40 -11
  17. package/dist/modules/Payment/index.d.ts +0 -2
  18. package/dist/modules/Payment/index.js +49 -78
  19. package/dist/modules/Payment/types.d.ts +24 -26
  20. package/dist/modules/Payment/types.js +0 -2
  21. package/dist/modules/Product/types.d.ts +1 -0
  22. package/dist/modules/ProductList/index.js +33 -14
  23. package/dist/modules/Quotation/index.d.ts +1 -1
  24. package/dist/modules/Quotation/index.js +2 -2
  25. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  26. package/dist/modules/ResourcePlanner/index.js +181 -0
  27. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  28. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  29. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  30. package/dist/modules/ResourcePlanner/types.js +1 -0
  31. package/dist/modules/Rules/index.js +48 -15
  32. package/dist/modules/SalesSummary/index.js +12 -13
  33. package/dist/modules/ScanOrderLogger/index.d.ts +2 -0
  34. package/dist/modules/ScanOrderLogger/index.js +15 -2
  35. package/dist/modules/ScanOrderLogger/providers/feishu.js +45 -27
  36. package/dist/modules/ScanOrderLogger/types.d.ts +1 -0
  37. package/dist/modules/Schedule/index.d.ts +3 -1
  38. package/dist/modules/Schedule/index.js +21 -16
  39. package/dist/modules/Summary/utils.js +38 -13
  40. package/dist/modules/index.d.ts +2 -0
  41. package/dist/modules/index.js +3 -1
  42. package/dist/plugins/window.d.ts +1 -0
  43. package/dist/server/index.d.ts +14 -16
  44. package/dist/server/index.js +1162 -1943
  45. package/dist/server/modules/order/index.d.ts +4 -49
  46. package/dist/server/modules/order/index.js +695 -1574
  47. package/dist/server/modules/order/types.d.ts +3 -11
  48. package/dist/server/modules/order/types.js +1 -1
  49. package/dist/solution/BaseSales/index.d.ts +10 -33
  50. package/dist/solution/BaseSales/index.js +385 -676
  51. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  52. package/dist/solution/BookingByStep/index.d.ts +17 -2
  53. package/dist/solution/BookingByStep/index.js +294 -215
  54. package/dist/solution/BookingByStep/types.d.ts +2 -1
  55. package/dist/solution/BookingByStep/types.js +3 -1
  56. package/dist/solution/BookingByStep/utils/capacity.js +17 -1
  57. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  58. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  59. package/dist/solution/BookingTicket/index.js +1 -2
  60. package/dist/solution/Sales/index.d.ts +0 -1
  61. package/dist/solution/Sales/index.js +2 -10
  62. package/dist/solution/ScanOrder/index.d.ts +26 -14
  63. package/dist/solution/ScanOrder/index.js +1140 -737
  64. package/dist/solution/ScanOrder/types.d.ts +21 -1
  65. package/dist/solution/ScanOrder/utils.d.ts +8 -0
  66. package/dist/solution/ScanOrder/utils.js +66 -25
  67. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  68. package/dist/solution/ShopDiscount/index.js +125 -87
  69. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  70. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  71. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  72. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  73. package/dist/solution/VenueBooking/index.d.ts +39 -11
  74. package/dist/solution/VenueBooking/index.js +1177 -850
  75. package/dist/solution/VenueBooking/types.d.ts +3 -0
  76. package/dist/solution/VenueBooking/utils/resource.js +1 -0
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -5
  79. package/dist/solution/index.d.ts +1 -0
  80. package/dist/solution/index.js +2 -1
  81. package/dist/types/index.d.ts +1 -0
  82. package/lib/modules/Discount/index.d.ts +1 -0
  83. package/lib/modules/Discount/index.js +9 -0
  84. package/lib/modules/Discount/types.d.ts +1 -0
  85. package/lib/modules/Holder/index.d.ts +48 -0
  86. package/lib/modules/Holder/index.js +402 -0
  87. package/lib/modules/Holder/types.d.ts +123 -0
  88. package/lib/modules/Holder/types.js +17 -0
  89. package/lib/modules/Holder/utils.d.ts +13 -0
  90. package/lib/modules/Holder/utils.js +71 -0
  91. package/lib/modules/OpenData/index.js +1 -1
  92. package/lib/modules/Order/index.d.ts +11 -28
  93. package/lib/modules/Order/index.js +83 -187
  94. package/lib/modules/Order/types.d.ts +10 -33
  95. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  96. package/lib/modules/Order/utils.d.ts +10 -0
  97. package/lib/modules/Order/utils.js +39 -10
  98. package/lib/modules/Payment/index.d.ts +0 -2
  99. package/lib/modules/Payment/index.js +12 -33
  100. package/lib/modules/Payment/types.d.ts +24 -26
  101. package/lib/modules/Product/types.d.ts +1 -0
  102. package/lib/modules/ProductList/index.js +40 -31
  103. package/lib/modules/Quotation/index.d.ts +1 -1
  104. package/lib/modules/Quotation/index.js +2 -2
  105. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  106. package/lib/modules/ResourcePlanner/index.js +148 -0
  107. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  108. package/lib/modules/ResourcePlanner/planner.js +933 -0
  109. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  110. package/lib/modules/ResourcePlanner/types.js +17 -0
  111. package/lib/modules/Rules/index.js +34 -18
  112. package/lib/modules/SalesSummary/index.js +6 -7
  113. package/lib/modules/ScanOrderLogger/index.d.ts +2 -0
  114. package/lib/modules/ScanOrderLogger/index.js +13 -1
  115. package/lib/modules/ScanOrderLogger/providers/feishu.js +15 -6
  116. package/lib/modules/ScanOrderLogger/types.d.ts +1 -0
  117. package/lib/modules/Schedule/index.d.ts +3 -1
  118. package/lib/modules/Schedule/index.js +10 -8
  119. package/lib/modules/Summary/utils.js +21 -1
  120. package/lib/modules/index.d.ts +2 -0
  121. package/lib/modules/index.js +5 -1
  122. package/lib/plugins/window.d.ts +1 -0
  123. package/lib/server/index.d.ts +14 -16
  124. package/lib/server/index.js +88 -678
  125. package/lib/server/modules/order/index.d.ts +4 -49
  126. package/lib/server/modules/order/index.js +66 -657
  127. package/lib/server/modules/order/types.d.ts +3 -11
  128. package/lib/solution/BaseSales/index.d.ts +10 -33
  129. package/lib/solution/BaseSales/index.js +33 -201
  130. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  131. package/lib/solution/BookingByStep/index.d.ts +17 -2
  132. package/lib/solution/BookingByStep/index.js +60 -18
  133. package/lib/solution/BookingByStep/types.d.ts +2 -1
  134. package/lib/solution/BookingByStep/types.js +5 -0
  135. package/lib/solution/BookingByStep/utils/capacity.js +20 -1
  136. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  137. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  138. package/lib/solution/BookingTicket/index.js +1 -2
  139. package/lib/solution/Sales/index.d.ts +0 -1
  140. package/lib/solution/Sales/index.js +3 -5
  141. package/lib/solution/ScanOrder/index.d.ts +26 -14
  142. package/lib/solution/ScanOrder/index.js +449 -182
  143. package/lib/solution/ScanOrder/types.d.ts +21 -1
  144. package/lib/solution/ScanOrder/utils.d.ts +8 -0
  145. package/lib/solution/ScanOrder/utils.js +31 -0
  146. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  147. package/lib/solution/ShopDiscount/index.js +14 -0
  148. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  149. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  150. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  151. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  152. package/lib/solution/VenueBooking/index.d.ts +39 -11
  153. package/lib/solution/VenueBooking/index.js +328 -115
  154. package/lib/solution/VenueBooking/types.d.ts +3 -0
  155. package/lib/solution/VenueBooking/utils/resource.js +1 -0
  156. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  157. package/lib/solution/VenueBooking/utils/slotMerge.js +6 -4
  158. package/lib/solution/index.d.ts +1 -0
  159. package/lib/solution/index.js +3 -1
  160. package/lib/types/index.d.ts +1 -0
  161. package/package.json +2 -2
  162. package/dist/modules/Order/payment-utils.d.ts +0 -26
  163. package/dist/modules/Order/payment-utils.js +0 -225
  164. package/dist/utils/payment-number.d.ts +0 -9
  165. package/dist/utils/payment-number.js +0 -69
  166. package/lib/modules/Order/payment-utils.d.ts +0 -26
  167. package/lib/modules/Order/payment-utils.js +0 -224
  168. package/lib/utils/payment-number.d.ts +0 -9
  169. package/lib/utils/payment-number.js +0 -64
@@ -33,7 +33,7 @@ __export(ScanOrder_exports, {
33
33
  ScanOrderImpl: () => ScanOrderImpl
34
34
  });
35
35
  module.exports = __toCommonJS(ScanOrder_exports);
36
- var import_BaseModule = require("../../modules/BaseModule");
36
+ var import_BaseSales = require("../BaseSales");
37
37
  var import_types = require("./types");
38
38
  var import_Order = require("../../modules/Order");
39
39
  var import_types2 = require("../../modules/Account/types");
@@ -42,13 +42,12 @@ var import_decimal = __toESM(require("decimal.js"));
42
42
  var import_utils = require("./utils");
43
43
  var import_types4 = require("../BookingByStep/types");
44
44
  var import_ProductList = require("../../modules/ProductList");
45
- var import_Schedule = require("../../modules/Schedule");
46
45
  var import_getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
47
46
  var import_utils2 = require("../../modules/Order/utils");
48
47
  var import_dayjs = __toESM(require("dayjs"));
49
48
  var import_itemRule = require("../../model/strategy/adapter/itemRule");
50
49
  __reExport(ScanOrder_exports, require("./types"), module.exports);
51
- var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
50
+ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
52
51
  constructor(name, version) {
53
52
  super(name, version);
54
53
  this.defaultName = "scanOrder";
@@ -300,28 +299,22 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
300
299
  }
301
300
  }
302
301
  }
302
+ getRegisteredModuleNames() {
303
+ return ["scanOrderLogger", "products", "order", "salesSummary", "schedule"];
304
+ }
305
+ createSubModule(moduleName) {
306
+ if (moduleName === "scanOrderLogger") {
307
+ return (0, import_types4.createModule)("scanOrderLogger", this.name);
308
+ }
309
+ return super.createSubModule(moduleName);
310
+ }
303
311
  /** 与 `otherParams.cacheId` 一致,供宿主在 URL 变化时判断是否需要重新注册模块 */
304
312
  getCacheId() {
305
313
  return this.cacheId;
306
314
  }
307
- async destroyRegisteredChildModules() {
308
- const modules = [
309
- this.store.schedule,
310
- this.store.salesSummary,
311
- this.store.order,
312
- this.store.products,
313
- this.store.scanOrderLogger
314
- ];
315
- for (const mod of modules) {
316
- if (mod && typeof mod.destroy === "function")
317
- await Promise.resolve(mod.destroy());
318
- }
319
- }
320
315
  async initialize(core, options = {}) {
321
- var _a, _b, _c, _d, _e, _f;
316
+ var _a, _b, _c, _d, _e, _f, _g, _h;
322
317
  this.logMethodStart("initialize");
323
- this.core = core;
324
- this.initializeOptions = options || {};
325
318
  this.store = { ...this.store, ...options.store };
326
319
  this.store.entryContext = ((_a = options.otherParams) == null ? void 0 : _a.entryContext) || this.store.entryContext;
327
320
  this.store.status = "initializing";
@@ -337,71 +330,26 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
337
330
  passed: null,
338
331
  failures: []
339
332
  };
340
- this.window = core.getPlugin("window");
341
- this.request = core.getPlugin("request");
342
- if (!this.window) {
343
- this.logMethodError("initialize", "window plugin missing");
344
- throw new Error("scanOrder解决方案需要 window 插件支持");
345
- }
346
- if (!this.request) {
347
- this.logMethodError("initialize", "request plugin missing");
348
- throw new Error("scanOrder解决方案需要 request 插件支持");
349
- }
350
- const moduleArr = [
351
- "scanOrderLogger",
352
- "products",
353
- "order",
354
- "salesSummary"
355
- ];
356
- moduleArr.forEach((step) => {
357
- var _a2, _b2, _c2, _d2, _e2, _f2;
358
- const targetModule = (0, import_types4.createModule)(step, this.name);
359
- if (targetModule) {
360
- this.store[step] = targetModule;
361
- const initialState = step === "salesSummary" ? {
362
- summary: ((_b2 = (_a2 = this.store.order) == null ? void 0 : _a2.getTempOrder()) == null ? void 0 : _b2.summary) || (0, import_utils.createEmptySummary)()
363
- } : {};
364
- const loggerProvider = ((_c2 = this.otherParams) == null ? void 0 : _c2.scanOrderLoggerProvider) || "feishu";
365
- const loggerConfig = ((_d2 = this.otherParams) == null ? void 0 : _d2.scanOrderLoggerConfig) || {
333
+ await super.initialize(core, options);
334
+ if (this.store.scanOrderLogger) {
335
+ this.store.scanOrderLogger.setProvider(
336
+ ((_e = this.otherParams) == null ? void 0 : _e.scanOrderLoggerProvider) || "feishu"
337
+ );
338
+ this.store.scanOrderLogger.setProviderConfig(
339
+ ((_f = this.otherParams) == null ? void 0 : _f.scanOrderLoggerConfig) || {
366
340
  feishu: {
367
341
  webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed",
368
342
  errorHook: "https://open.feishu.cn/open-apis/bot/v2/hook/015b7c2a-dd3c-4c30-9898-ef0f5253111f"
369
343
  }
370
- };
371
- this.core.registerModule(targetModule, {
372
- initialState,
373
- otherParams: {
374
- ...this.otherParams,
375
- fatherModule: this.name,
376
- openCache: ((_e2 = this.otherParams) == null ? void 0 : _e2.cacheId) ? true : false,
377
- cacheId: (_f2 = this.otherParams) == null ? void 0 : _f2.cacheId,
378
- salesSummaryModuleName: `${this.name}_salesSummary`,
379
- provider: loggerProvider,
380
- providerConfig: loggerConfig,
381
- context: this.getScanOrderLoggerContext()
382
- }
383
- });
384
- } else {
385
- this.logMethodError("initialize", `module ${step} missing`);
386
- throw new Error(`模块 ${step} 不存在`);
387
- }
388
- });
389
- if (this.store.scanOrderLogger) {
344
+ }
345
+ );
390
346
  this.store.scanOrderLogger.setContext(this.getScanOrderLoggerContext());
391
347
  }
392
- const scheduleModule = new import_Schedule.ScheduleModule(`${this.name}_schedule`);
393
- this.store.schedule = scheduleModule;
394
- this.core.registerModule(scheduleModule, {
395
- otherParams: {
396
- ...this.otherParams,
397
- fatherModule: this.name
398
- }
399
- });
400
348
  this.registerCustomerLoginListeners();
401
349
  console.log("[ScanOrder] 初始化开始");
402
350
  try {
403
- await ((_e = this.store.order) == null ? void 0 : _e.recalculateSummary({ createIfMissing: false }));
404
- (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
351
+ await ((_g = this.store.order) == null ? void 0 : _g.recalculateSummary({ createIfMissing: false }));
352
+ (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
405
353
  await this.loadRuntimeConfigs();
406
354
  if (this.store.schedule) {
407
355
  try {
@@ -433,7 +381,6 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
433
381
  this.logMethodStart("destroy");
434
382
  this.clearLoginEffectListeners();
435
383
  await this.core.effects.emit(import_types.ScanOrderHooks.onDestroy, {});
436
- await this.destroyRegisteredChildModules();
437
384
  super.destroy();
438
385
  console.log("[ScanOrder] 已销毁");
439
386
  this.logMethodSuccess("destroy");
@@ -533,18 +480,27 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
533
480
  });
534
481
  return result;
535
482
  }
536
- updateTempOrderNote(note) {
483
+ updateTempOrderNote(note, sync = false) {
537
484
  this.logMethodStart("updateTempOrderNote", {
538
485
  noteLength: String(note || "").length
539
486
  });
540
487
  try {
541
488
  if (!this.store.order)
542
489
  throw new Error("order 模块未初始化");
543
- const result = this.store.order.updateTempOrderNote(note);
490
+ const result = this.store.order.updateTempOrderNote(note, sync);
491
+ if (result && typeof result.then === "function") {
492
+ return result.then((nextNote2) => {
493
+ this.logMethodSuccess("updateTempOrderNote", {
494
+ noteLength: nextNote2.length
495
+ });
496
+ return nextNote2;
497
+ });
498
+ }
499
+ const nextNote = result;
544
500
  this.logMethodSuccess("updateTempOrderNote", {
545
- noteLength: result.length
501
+ noteLength: nextNote.length
546
502
  });
547
- return result;
503
+ return nextNote;
548
504
  } catch (error) {
549
505
  this.logMethodError("updateTempOrderNote", error);
550
506
  throw error;
@@ -553,6 +509,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
553
509
  // 存储 UI 层选择的取餐方式到 tempOrder.metadata.shop_service_data
554
510
  // service_type 在扫码点餐场景固定为 dine_in
555
511
  setPickupReferenceMode(mode) {
512
+ var _a;
556
513
  this.logMethodStart("setPickupReferenceMode", { mode });
557
514
  try {
558
515
  if (!this.store.order)
@@ -562,7 +519,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
562
519
  ...tempOrder.metadata || {},
563
520
  shop_service_data: {
564
521
  ...(tempOrder.metadata || {}).shop_service_data || {},
565
- service_type: "dine_in",
522
+ service_type: ((_a = this.otherParams) == null ? void 0 : _a.businessCode) === "dine_in" ? "dine_in" : "",
566
523
  pickup_reference_mode: mode
567
524
  }
568
525
  };
@@ -594,7 +551,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
594
551
  throw error;
595
552
  }
596
553
  }
597
- ensureTempOrder() {
554
+ ensureScanOrderTempOrder() {
598
555
  if (!this.store.order)
599
556
  throw new Error("order 模块未初始化");
600
557
  return this.store.order.ensureTempOrder();
@@ -815,6 +772,49 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
815
772
  combined_resource: isCombined ? combined : null
816
773
  };
817
774
  }
775
+ async prepareRetailAvailability(params) {
776
+ var _a, _b;
777
+ const { tempOrder, hasOrderId, resourceId, reason } = params;
778
+ this.enabledReservationRuleProducts = [];
779
+ tempOrder.bookings = [];
780
+ tempOrder.order_id = null;
781
+ delete tempOrder.relation_id;
782
+ delete tempOrder.table_form_id;
783
+ delete tempOrder.resource_id;
784
+ delete tempOrder.table_number;
785
+ tempOrder.metadata = { ...tempOrder.metadata || {} };
786
+ delete tempOrder.metadata.table_occupancy_duration;
787
+ const resourceState = {
788
+ mode: "idle",
789
+ deskmate_valid: false,
790
+ allowSnack: false,
791
+ deskmateValid: false,
792
+ isExclusive: false,
793
+ isFull: false,
794
+ raw: null
795
+ };
796
+ this.store.resource = resourceState;
797
+ (_a = this.store.order) == null ? void 0 : _a.persistTempOrder();
798
+ await this.addNewOrder();
799
+ await this.setItemRuleRuntimeConfig({
800
+ serviceType: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
801
+ submissionIndex: hasOrderId ? 1 : 0,
802
+ historicalItems: []
803
+ });
804
+ const availabilityInfo = {
805
+ mode: "idle",
806
+ deskmate_valid: false
807
+ };
808
+ this.logMethodSuccess("checkResourceAvailable", {
809
+ resourceId,
810
+ mode: availabilityInfo.mode,
811
+ retailMode: true,
812
+ retailReason: reason,
813
+ relationId: resourceState.relationId,
814
+ persistedResourceId: resourceState.relationId
815
+ });
816
+ return availabilityInfo;
817
+ }
818
818
  // ScanOrder 提交 payload enhancer:
819
819
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
820
820
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
@@ -824,23 +824,33 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
824
824
  const ruleProduct = this.enabledReservationRuleProducts[0];
825
825
  const resourceState = this.store.resource;
826
826
  const resourceSelectType = resourceState == null ? void 0 : resourceState.resourceSelectType;
827
- const resolveResourceCapacity = () => {
827
+ const resolveBookingCapacityValue = () => {
828
828
  var _a;
829
829
  if (resourceSelectType === "single") {
830
830
  const raw = (_a = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _a.capacity;
831
831
  const num = Number(raw);
832
832
  if (Number.isFinite(num) && num > 0)
833
- return num;
833
+ return Math.max(1, Math.floor(num));
834
834
  return 1;
835
835
  }
836
836
  return 1;
837
837
  };
838
838
  return (payload, { bookingUuid, tempOrder }) => {
839
839
  var _a, _b;
840
- const resourceId = tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId);
840
+ const resourceId = String((resourceState == null ? void 0 : resourceState.relationId) ?? "").trim();
841
+ const hasReservationBookingContext = Boolean(
842
+ ruleProduct && resourceState && resourceId && resourceState.relationId && resourceState.tableFormId
843
+ );
844
+ if (!hasReservationBookingContext) {
845
+ return {
846
+ ...payload,
847
+ bookings: [],
848
+ products: [...payload.products || []]
849
+ };
850
+ }
841
851
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
842
- const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
843
- const resourceCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
852
+ const hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
853
+ const bookingCapacityValue = resolveBookingCapacityValue();
844
854
  const pickOriginal = (value) => {
845
855
  if (value && typeof value === "object" && !Array.isArray(value)) {
846
856
  const original = value.original;
@@ -856,35 +866,42 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
856
866
  main_field: mainField,
857
867
  form_id: resourceState.tableFormId,
858
868
  relation_id: resourceState.relationId ?? resourceId,
859
- capacity: resourceCapacityValue,
869
+ capacity: bookingCapacityValue,
860
870
  metadata: this.buildScanOrderResourceMetadata({
861
871
  resourceState,
862
872
  resourceName: mainField
863
873
  })
864
874
  } : void 0;
865
875
  const ruleProductUid = ruleProduct ? (0, import_utils2.createUuidV4)() : void 0;
866
- const bookingCapacityValue = resourceCapacityValue;
867
876
  const bookingCapacityDimensionId = (0, import_utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
868
- const nextBookings = (payload.bookings || []).map((booking, idx) => ({
869
- ...booking,
870
- number: bookingCapacityValue,
871
- appointment_status: "started",
872
- metadata: {
873
- ...booking.metadata || {},
874
- ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
875
- ...resourceSelectType ? {
876
- capacity: [
877
- {
878
- id: bookingCapacityDimensionId,
879
- value: bookingCapacityValue,
880
- name: ""
881
- }
882
- ]
883
- } : {}
884
- },
885
- ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
886
- ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
887
- }));
877
+ const nextBookings = (payload.bookings || []).map((booking, idx) => {
878
+ const metadata = { ...booking.metadata || {} };
879
+ if (hasExplicitCollectPax) {
880
+ metadata.collect_pax = (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax);
881
+ } else {
882
+ delete metadata.collect_pax;
883
+ }
884
+ return {
885
+ ...booking,
886
+ number: bookingCapacityValue,
887
+ appointment_status: "started",
888
+ metadata: {
889
+ ...metadata,
890
+ ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
891
+ ...resourceSelectType ? {
892
+ capacity: [
893
+ {
894
+ id: bookingCapacityDimensionId,
895
+ value: bookingCapacityValue,
896
+ name: ""
897
+ }
898
+ ]
899
+ } : {}
900
+ },
901
+ ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
902
+ ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
903
+ };
904
+ });
888
905
  const nextProducts = [...payload.products || []];
889
906
  if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
890
907
  const sellingPrice = String(ruleProduct.price ?? "0.00");
@@ -913,8 +930,58 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
913
930
  return { ...payload, bookings: nextBookings, products: nextProducts };
914
931
  };
915
932
  }
933
+ isScanOrderMoreMode(tempOrder) {
934
+ var _a, _b;
935
+ const mode = (_a = this.store.resource) == null ? void 0 : _a.mode;
936
+ return Boolean(
937
+ tempOrder.order_id && (mode === "additional_order" || mode === "additional_order_with_code" || ((_b = this.store.entryContext) == null ? void 0 : _b.mode) === "append")
938
+ );
939
+ }
940
+ async submitScanOrderMore(params) {
941
+ var _a, _b, _c, _d, _e;
942
+ if (!this.request) {
943
+ throw new Error("scanOrder解决方案需要 request 插件支持");
944
+ }
945
+ if (!this.store.order) {
946
+ throw new Error("scanOrder解决方案需要 order 模块支持");
947
+ }
948
+ const { tempOrder, enhancePayload } = params;
949
+ const latestSummary = await this.store.order.recalculateSummary({
950
+ createIfMissing: true
951
+ });
952
+ const payload = (0, import_utils2.buildSubmitPayload)({
953
+ tempOrder,
954
+ cacheId: this.cacheId,
955
+ platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
956
+ businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
957
+ channel: (_d = this.otherParams) == null ? void 0 : _d.channel,
958
+ type: (_e = this.otherParams) == null ? void 0 : _e.type,
959
+ summary: latestSummary,
960
+ enhance: enhancePayload
961
+ });
962
+ const products = (0, import_utils.filterProductsForScanOrderMore)(payload.products);
963
+ const orderId = tempOrder.order_id;
964
+ const result = await this.request.put(
965
+ `/order/order/product/${orderId}`,
966
+ {
967
+ products,
968
+ request_unique_idempotency_token: payload.request_unique_idempotency_token
969
+ },
970
+ { customToast: () => {
971
+ } }
972
+ );
973
+ if ((result == null ? void 0 : result.code) === 200 && !(result == null ? void 0 : result.data)) {
974
+ return {
975
+ ...result,
976
+ data: {
977
+ order_id: orderId
978
+ }
979
+ };
980
+ }
981
+ return result;
982
+ }
916
983
  async submitScanOrder() {
917
- var _a, _b, _c, _d, _e, _f, _g;
984
+ var _a, _b, _c;
918
985
  this.logMethodStart("submitScanOrder");
919
986
  try {
920
987
  await this.validateBeforeSubmitByItemRule();
@@ -934,17 +1001,15 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
934
1001
  }
935
1002
  this.store.order.persistTempOrder();
936
1003
  const enhancePayload = this.buildSubmitPayloadEnhancer();
937
- const result = await this.store.order.submitTempOrder({
938
- cacheId: this.cacheId,
939
- platform: (_c = this.otherParams) == null ? void 0 : _c.platform,
940
- businessCode: (_d = this.otherParams) == null ? void 0 : _d.businessCode,
941
- channel: (_e = this.otherParams) == null ? void 0 : _e.channel,
942
- type: (_f = this.otherParams) == null ? void 0 : _f.type,
1004
+ const result = this.isScanOrderMoreMode(tempOrderForSubmit) ? await this.submitScanOrderMore({
1005
+ tempOrder: tempOrderForSubmit,
1006
+ enhancePayload
1007
+ }) : await this.submitSalesOrder({
943
1008
  enhancePayload
944
1009
  });
945
1010
  const tempOrder = this.store.order.getTempOrder();
946
1011
  this.logMethodSuccess("submitScanOrder", {
947
- productCount: ((_g = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _g.length) || 0
1012
+ productCount: ((_c = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _c.length) || 0
948
1013
  });
949
1014
  return result;
950
1015
  } catch (error) {
@@ -1185,7 +1250,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1185
1250
  return [];
1186
1251
  }
1187
1252
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1188
- tempOrder: this.ensureTempOrder(),
1253
+ tempOrder: this.ensureScanOrderTempOrder(),
1189
1254
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1190
1255
  itemRuleConfigs: this.itemRuleConfigs
1191
1256
  });
@@ -1211,7 +1276,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1211
1276
  if (!strategyConfigs.length)
1212
1277
  return;
1213
1278
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1214
- tempOrder: this.ensureTempOrder(),
1279
+ tempOrder: this.ensureScanOrderTempOrder(),
1215
1280
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1216
1281
  itemRuleConfigs: this.itemRuleConfigs
1217
1282
  });
@@ -1221,7 +1286,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1221
1286
  return;
1222
1287
  }
1223
1288
  const productSourceMap = await this.buildPrefillProductSourceMap();
1224
- const tempOrder = this.ensureTempOrder();
1289
+ const tempOrder = this.ensureScanOrderTempOrder();
1225
1290
  let hasChanges = false;
1226
1291
  for (const prefillItem of prefillItems) {
1227
1292
  const productId = Number(prefillItem.product_id);
@@ -1321,7 +1386,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1321
1386
  };
1322
1387
  }
1323
1388
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1324
- tempOrder: this.ensureTempOrder(),
1389
+ tempOrder: this.ensureScanOrderTempOrder(),
1325
1390
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1326
1391
  itemRuleConfigs: this.itemRuleConfigs
1327
1392
  });
@@ -1471,8 +1536,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1471
1536
  const matched = resources.find((r) => Number(r == null ? void 0 : r.id) === numericFormId);
1472
1537
  return matched == null ? void 0 : matched.type;
1473
1538
  }
1474
- async fetchResourceOccupyDetailByResourceId(resourceId) {
1475
- var _a, _b, _c, _d;
1539
+ async fetchResourceOccupyDetailsByResourceId(resourceId) {
1540
+ var _a, _b, _c;
1476
1541
  const formRecordId = Number(resourceId);
1477
1542
  if (!Number.isFinite(formRecordId) || formRecordId <= 0) {
1478
1543
  throw new Error(`[ScanOrder] 非法桌台 resourceId: ${resourceId}`);
@@ -1494,15 +1559,60 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1494
1559
  if (!(response == null ? void 0 : response.status)) {
1495
1560
  throw new Error((response == null ? void 0 : response.message) || "获取资源占用详情失败");
1496
1561
  }
1497
- return ((_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) == null ? void 0 : _d[0]) ?? null;
1562
+ return ((_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) ?? [];
1563
+ }
1564
+ resolveAdditionalOrderFromOccupyDetail(detail, resourceSelectType, allowAddItems) {
1565
+ const currentOrderId = (0, import_utils.toPositiveString)(detail == null ? void 0 : detail.order_id);
1566
+ if (currentOrderId) {
1567
+ return {
1568
+ matched: true,
1569
+ order_id: currentOrderId
1570
+ };
1571
+ }
1572
+ const orderListIds = (Array.isArray(detail == null ? void 0 : detail.order_list) ? (detail == null ? void 0 : detail.order_list) || [] : []).map((order) => (0, import_utils.toPositiveString)(order == null ? void 0 : order.id)).filter(Boolean);
1573
+ if (resourceSelectType !== "single") {
1574
+ return {
1575
+ matched: false,
1576
+ reason: "no_order"
1577
+ };
1578
+ }
1579
+ if (!orderListIds.length) {
1580
+ return {
1581
+ matched: false,
1582
+ reason: "no_order"
1583
+ };
1584
+ }
1585
+ if (!allowAddItems) {
1586
+ return {
1587
+ matched: false,
1588
+ reason: "add_items_disabled"
1589
+ };
1590
+ }
1591
+ if (orderListIds.length === 1) {
1592
+ return {
1593
+ matched: true,
1594
+ order_id: orderListIds[0]
1595
+ };
1596
+ }
1597
+ if (orderListIds.length > 1) {
1598
+ return {
1599
+ matched: false,
1600
+ reason: "multiple_orders"
1601
+ };
1602
+ }
1603
+ return {
1604
+ matched: false,
1605
+ reason: "no_order"
1606
+ };
1498
1607
  }
1499
1608
  // 检测当前链接是否可用
1500
1609
  // 通过 resource_id + 店铺配置
1501
1610
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1502
- async checkResourceAvailable(resourceId, hasOrderId) {
1503
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1611
+ async checkResourceAvailable(resourceId, hasOrderId = false) {
1612
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1613
+ const normalizedResourceId = String(resourceId ?? "").trim();
1504
1614
  this.logMethodStart("checkResourceAvailable", {
1505
- resourceId
1615
+ resourceId: normalizedResourceId
1506
1616
  });
1507
1617
  try {
1508
1618
  const businessCode = String(((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? "").trim();
@@ -1552,37 +1662,71 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1552
1662
  if (outsideOperatingHours && closedBehaviorValue !== "show_menu_disabled") {
1553
1663
  return makeShopClosed(closedMessage, closedBehaviorValue);
1554
1664
  }
1555
- const tempOrder = this.ensureTempOrder();
1665
+ const tempOrder = this.ensureScanOrderTempOrder();
1556
1666
  const reservationLinkIds = (0, import_utils.collectLinkProductIdsFromReservationRules)(
1557
1667
  dineInConfig["fulfillment.enabled_resource_rules"]
1558
1668
  );
1669
+ if (!normalizedResourceId || reservationLinkIds.length === 0) {
1670
+ return await this.prepareRetailAvailability({
1671
+ tempOrder,
1672
+ hasOrderId,
1673
+ resourceId: normalizedResourceId,
1674
+ reason: !normalizedResourceId ? "missing_resource_id" : "missing_enabled_resource_rules"
1675
+ });
1676
+ }
1559
1677
  let pendingRequestEntryPax;
1560
1678
  let pendingRequestPaxMin;
1561
1679
  let pendingRequestPaxMax;
1562
- if (reservationLinkIds.length === 0) {
1563
- this.enabledReservationRuleProducts = [];
1564
- } else {
1565
- tempOrder.metadata = { ...tempOrder.metadata || {} };
1566
- delete tempOrder.metadata.table_occupancy_duration;
1567
- const reservationProductList = new import_ProductList.ProductList(
1568
- `${this.name}_reservationEnabledRules`,
1569
- this.defaultVersion
1680
+ tempOrder.metadata = { ...tempOrder.metadata || {} };
1681
+ delete tempOrder.metadata.table_occupancy_duration;
1682
+ const reservationProductList = new import_ProductList.ProductList(
1683
+ `${this.name}_reservationEnabledRules`,
1684
+ this.defaultVersion
1685
+ );
1686
+ await reservationProductList.initialize(this.core, {
1687
+ store: { list: [], selectProducts: [] },
1688
+ otherParams: {
1689
+ ...this.otherParams,
1690
+ fatherModule: this.name,
1691
+ openCache: Boolean(this.cacheId),
1692
+ cacheId: this.cacheId
1693
+ }
1694
+ });
1695
+ const scheduleDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1696
+ const scheduleDatetime = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1697
+ const loaded = await reservationProductList.loadProducts({
1698
+ product_ids: reservationLinkIds,
1699
+ schedule_date: scheduleDate,
1700
+ schedule_datetime: scheduleDatetime,
1701
+ cacheId: this.cacheId
1702
+ });
1703
+ if (Array.isArray(loaded)) {
1704
+ const matchedRuleProduct = (0, import_utils.findReservationRuleProductByResourceId)(
1705
+ loaded,
1706
+ normalizedResourceId
1570
1707
  );
1571
- await reservationProductList.initialize(this.core, {
1572
- store: { list: [], selectProducts: [] },
1573
- otherParams: {
1574
- ...this.otherParams,
1575
- fatherModule: this.name,
1576
- openCache: Boolean(this.cacheId),
1577
- cacheId: this.cacheId
1578
- }
1579
- });
1580
- const scheduleDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1581
- const scheduleDatetime = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1582
- const loaded = await reservationProductList.loadProducts({
1583
- product_ids: reservationLinkIds,
1584
- schedule_date: scheduleDate,
1585
- schedule_datetime: scheduleDatetime,
1708
+ const ruleProductsForResource = matchedRuleProduct ? [matchedRuleProduct] : [];
1709
+ this.enabledReservationRuleProducts = ruleProductsForResource;
1710
+ const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(ruleProductsForResource);
1711
+ if (occupancyMinutes !== void 0) {
1712
+ tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
1713
+ }
1714
+ if ((0, import_utils.hasCustomCapacityProduct)(ruleProductsForResource)) {
1715
+ pendingRequestEntryPax = 1;
1716
+ const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(ruleProductsForResource);
1717
+ if ((paxBounds == null ? void 0 : paxBounds.min) !== void 0)
1718
+ pendingRequestPaxMin = paxBounds.min;
1719
+ if ((paxBounds == null ? void 0 : paxBounds.max) !== void 0)
1720
+ pendingRequestPaxMax = paxBounds.max;
1721
+ }
1722
+ } else {
1723
+ this.enabledReservationRuleProducts = [];
1724
+ const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1725
+ this.logMethodError("loadReservationRuleProducts", error, {
1726
+ resourceId: normalizedResourceId,
1727
+ reservationLinkIds,
1728
+ scheduleDate,
1729
+ scheduleDatetime,
1586
1730
  cacheId: this.cacheId
1587
1731
  });
1588
1732
  if (Array.isArray(loaded)) {
@@ -1601,8 +1745,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1601
1745
  }
1602
1746
  } else {
1603
1747
  this.enabledReservationRuleProducts = [];
1604
- const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1605
- this.logMethodError("loadReservationRuleProducts", error, {
1748
+ const error2 = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1749
+ this.logMethodError("loadReservationRuleProducts", error2, {
1606
1750
  resourceId,
1607
1751
  reservationLinkIds,
1608
1752
  scheduleDate,
@@ -1611,15 +1755,54 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1611
1755
  });
1612
1756
  }
1613
1757
  }
1614
- const occupyDetail = await this.fetchResourceOccupyDetailByResourceId(resourceId);
1758
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1759
+ const occupyDetail = occupyDetails[0] ?? null;
1615
1760
  const resourceSelectType = this.resolveResourceSelectType(
1616
1761
  (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1617
1762
  );
1763
+ const allowAddItems = (0, import_utils.toBoolean)(dineInConfig == null ? void 0 : dineInConfig["sale.allow_add_items"]);
1764
+ const additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(
1765
+ occupyDetail,
1766
+ resourceSelectType,
1767
+ allowAddItems
1768
+ );
1769
+ if (additionalOrderResult.reason === "multiple_orders") {
1770
+ const multipleOrdersState = {
1771
+ ...this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId),
1772
+ mode: "multiple_orders"
1773
+ };
1774
+ this.store.resource = multipleOrdersState;
1775
+ const availabilityInfo2 = {
1776
+ mode: "multiple_orders",
1777
+ deskmate_valid: multipleOrdersState.deskmate_valid,
1778
+ relation_id: multipleOrdersState.relationId,
1779
+ table_form_id: multipleOrdersState.tableFormId,
1780
+ table_form_record: multipleOrdersState.table_form_record
1781
+ };
1782
+ this.logMethodSuccess("checkResourceAvailable", {
1783
+ resourceId: normalizedResourceId,
1784
+ mode: availabilityInfo2.mode,
1785
+ orderListCount: ((_e = occupyDetail == null ? void 0 : occupyDetail.order_list) == null ? void 0 : _e.length) || 0,
1786
+ resourceSelectType
1787
+ });
1788
+ return availabilityInfo2;
1789
+ }
1618
1790
  const resourceState = this.normalizeResourceState(
1619
1791
  occupyDetail,
1620
1792
  resourceSelectType,
1621
1793
  hasOrderId
1622
1794
  );
1795
+ const additionalOrderId = additionalOrderResult.order_id;
1796
+ if (additionalOrderId) {
1797
+ resourceState.mode = "additional_order";
1798
+ resourceState.order_id = additionalOrderId;
1799
+ } else if (additionalOrderResult.reason === "add_items_disabled") {
1800
+ resourceState.mode = "resource_busy";
1801
+ resourceState.order_id = "0";
1802
+ } else if (resourceSelectType === "multiple" && resourceState.isFull) {
1803
+ resourceState.mode = "resource_busy";
1804
+ resourceState.order_id = "0";
1805
+ }
1623
1806
  this.store.resource = resourceState;
1624
1807
  if (pendingRequestEntryPax !== void 0) {
1625
1808
  this.store.resource.requestEntryPax = pendingRequestEntryPax;
@@ -1637,36 +1820,22 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1637
1820
  table_form_id: resourceState.tableFormId,
1638
1821
  deskmate_valid: resourceState.deskmate_valid,
1639
1822
  table_form_record: resourceState.table_form_record,
1640
- policy: (_e = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _e.policy,
1641
- partyroom_booking: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.partyroom_booking,
1823
+ policy: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.policy,
1824
+ partyroom_booking: (_g = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _g.partyroom_booking,
1642
1825
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1643
1826
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1644
1827
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1645
1828
  };
1646
- tempOrder.relation_id = resourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1647
- tempOrder.table_form_id = resourceState.tableFormId;
1648
- tempOrder.resource_id = resourceId;
1649
1829
  (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1650
1830
  if (availabilityInfo.mode === "idle") {
1651
1831
  await this.addNewOrder();
1652
1832
  }
1653
- if (availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code") {
1654
- tempOrder.order_id = resourceState.lastOrderId;
1655
- }
1656
- if (tempOrder.order_id) {
1657
- const res = await ((_i = this.store.order) == null ? void 0 : _i.getSalesOrderByLookup({
1658
- lookup: tempOrder.order_id
1659
- }));
1660
- const entryPaxNumber = (_m = (_l = (_k = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.bookings) == null ? void 0 : _k.find((p) => {
1661
- var _a2;
1662
- return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1663
- })) == null ? void 0 : _l.metadata) == null ? void 0 : _m.collect_pax;
1664
- if (entryPaxNumber) {
1665
- await this.setEntryPaxNumber(entryPaxNumber);
1666
- }
1833
+ const isAdditionalOrderMode = availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code";
1834
+ if (isAdditionalOrderMode) {
1835
+ tempOrder.order_id = additionalOrderId;
1667
1836
  }
1668
- const lastOrderInfo = (_o = (_n = this.store.order) == null ? void 0 : _n.getLastOrderInfo) == null ? void 0 : _o.call(_n);
1669
- const historicalItems = hasOrderId && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1837
+ const lastOrderInfo = (_j = (_i = this.store.order) == null ? void 0 : _i.getLastOrderInfo) == null ? void 0 : _j.call(_i);
1838
+ const historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1670
1839
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1671
1840
  return acc;
1672
1841
  acc.push({
@@ -1677,8 +1846,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1677
1846
  return acc;
1678
1847
  }, []) : [];
1679
1848
  await this.setItemRuleRuntimeConfig({
1680
- serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1681
- submissionIndex: hasOrderId ? 1 : 0,
1849
+ serviceType: (_k = this.otherParams) == null ? void 0 : _k.businessCode,
1850
+ submissionIndex: isAdditionalOrderMode ? 1 : 0,
1682
1851
  historicalItems
1683
1852
  });
1684
1853
  if (outsideOperatingHours && closedBehaviorValue === "show_menu_disabled") {
@@ -1687,13 +1856,13 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1687
1856
  availabilityInfo.closed_behavior = closedBehaviorValue;
1688
1857
  }
1689
1858
  this.logMethodSuccess("checkResourceAvailable", {
1690
- resourceId,
1859
+ resourceId: normalizedResourceId,
1691
1860
  mode: availabilityInfo.mode,
1692
1861
  orderId: availabilityInfo.order_id,
1693
1862
  relationId: availabilityInfo.relation_id,
1694
1863
  tableFormId: availabilityInfo.table_form_id,
1695
- persistedRelationId: tempOrder.relation_id,
1696
- persistedResourceId: tempOrder.resource_id,
1864
+ persistedRelationId: (_l = this.store.resource) == null ? void 0 : _l.relationId,
1865
+ persistedResourceId: (_m = this.store.resource) == null ? void 0 : _m.relationId,
1697
1866
  deskmateValid: availabilityInfo.deskmate_valid,
1698
1867
  resourceSelectType: resourceState.resourceSelectType,
1699
1868
  isExclusive: resourceState.isExclusive,
@@ -1702,11 +1871,29 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1702
1871
  return availabilityInfo;
1703
1872
  } catch (error) {
1704
1873
  this.logMethodError("checkResourceAvailable", error.message, {
1705
- resourceId
1874
+ resourceId: normalizedResourceId
1706
1875
  });
1707
1876
  throw error;
1708
1877
  }
1709
1878
  }
1879
+ // 恢复之前订单的数据,读取 entrypax
1880
+ async restorePreviousOrderData() {
1881
+ var _a, _b, _c, _d;
1882
+ const orderModule = this.store.order;
1883
+ if (!orderModule)
1884
+ return;
1885
+ const tempOrder = orderModule.ensureTempOrder();
1886
+ if (tempOrder.order_id) {
1887
+ const res = await orderModule.getOrderInfo(tempOrder.order_id);
1888
+ const entryPaxNumber = (_d = (_c = (_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.bookings) == null ? void 0 : _b.find((p) => {
1889
+ var _a2;
1890
+ return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1891
+ })) == null ? void 0 : _c.metadata) == null ? void 0 : _d.collect_pax;
1892
+ if (entryPaxNumber) {
1893
+ await this.setEntryPaxNumber(entryPaxNumber);
1894
+ }
1895
+ }
1896
+ }
1710
1897
  // 如果是加单的情况,提供返回当前订单相关信息的能力
1711
1898
  async getAdditionalOrderInfo() {
1712
1899
  this.logMethodStart("getAdditionalOrderInfo");
@@ -1727,7 +1914,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1727
1914
  async getProductList() {
1728
1915
  var _a, _b;
1729
1916
  this.logMethodStart("getProductList");
1730
- const menu_list_ids = ((_b = (_a = this.otherParams) == null ? void 0 : _a.dineInConfig) == null ? void 0 : _b["menu.associated_menus"].map((n) => Number(n.value))) || [];
1917
+ const associatedMenus = (_b = (_a = this.otherParams) == null ? void 0 : _a.dineInConfig) == null ? void 0 : _b["menu.associated_menus"];
1918
+ const menu_list_ids = associatedMenus.map((n) => Number(n.value)) || [];
1731
1919
  try {
1732
1920
  if (!this.store.products)
1733
1921
  throw new Error("products 模块未初始化");
@@ -1851,6 +2039,85 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1851
2039
  getEntryPaxNumber() {
1852
2040
  return this.store.entryPaxNumber;
1853
2041
  }
2042
+ async syncAdditionalOrderFromResource(resourceId) {
2043
+ var _a, _b, _c, _d, _e, _f;
2044
+ if (!this.store.order)
2045
+ throw new Error("order 模块未初始化");
2046
+ const tempOrder = this.store.order.ensureTempOrder();
2047
+ const normalizedResourceId = String(
2048
+ resourceId ?? tempOrder.resource_id ?? ((_a = this.store.resource) == null ? void 0 : _a.relationId) ?? ((_b = this.store.resource) == null ? void 0 : _b.relation_id) ?? ""
2049
+ ).trim();
2050
+ this.logMethodStart("syncAdditionalOrderFromResource", {
2051
+ resourceId: normalizedResourceId
2052
+ });
2053
+ if (!normalizedResourceId) {
2054
+ const result2 = {
2055
+ matched: false,
2056
+ reason: "missing_resource_id"
2057
+ };
2058
+ this.logMethodSuccess("syncAdditionalOrderFromResource", result2);
2059
+ return result2;
2060
+ }
2061
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2062
+ const occupyDetail = occupyDetails[0] ?? null;
2063
+ const resourceSelectType = ((_c = this.store.resource) == null ? void 0 : _c.resourceSelectType) || this.resolveResourceSelectType((0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id));
2064
+ const allowAddItems = (0, import_utils.toBoolean)(
2065
+ (_e = (_d = this.otherParams) == null ? void 0 : _d.dineInConfig) == null ? void 0 : _e["sale.allow_add_items"]
2066
+ );
2067
+ const result = this.resolveAdditionalOrderFromOccupyDetail(
2068
+ occupyDetail,
2069
+ resourceSelectType,
2070
+ allowAddItems
2071
+ );
2072
+ if (!result.matched || !result.order_id) {
2073
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2074
+ ...result,
2075
+ resourceId: normalizedResourceId,
2076
+ resourceSelectType,
2077
+ allowAddItems
2078
+ });
2079
+ return result;
2080
+ }
2081
+ tempOrder.order_id = result.order_id;
2082
+ tempOrder.resource_id = normalizedResourceId;
2083
+ tempOrder.relation_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
2084
+ tempOrder.table_form_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
2085
+ (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
2086
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2087
+ ...result,
2088
+ resourceId: normalizedResourceId,
2089
+ resourceSelectType,
2090
+ allowAddItems
2091
+ });
2092
+ return result;
2093
+ }
2094
+ // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
2095
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
2096
+ getReservationResourceSelectType() {
2097
+ var _a;
2098
+ this.logMethodStart("getReservationResourceSelectType");
2099
+ const resourceSelectType = (_a = this.store.resource) == null ? void 0 : _a.resourceSelectType;
2100
+ const result = {
2101
+ ...resourceSelectType ? { resourceSelectType } : {},
2102
+ isSingleReservation: resourceSelectType === "single",
2103
+ isMultipleReservation: resourceSelectType === "multiple",
2104
+ isCapacityReservation: resourceSelectType === "capacity"
2105
+ };
2106
+ this.logMethodSuccess("getReservationResourceSelectType", result);
2107
+ return result;
2108
+ }
2109
+ // 判定后台是否开启允许加餐
2110
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
2111
+ checkAllowAddItems() {
2112
+ var _a;
2113
+ this.logMethodStart("checkAllowAddItems");
2114
+ const dineInConfig = ((_a = this.otherParams) == null ? void 0 : _a.dineInConfig) || {};
2115
+ const result = {
2116
+ enabled: (0, import_utils.toBoolean)(dineInConfig["sale.allow_add_items"])
2117
+ };
2118
+ this.logMethodSuccess("checkAllowAddItems", result);
2119
+ return result;
2120
+ }
1854
2121
  // 读取取餐/送餐开关
1855
2122
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
1856
2123
  getFulfillmentModes() {