@pisell/pisellos 2.3.43 → 2.3.45

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 (160) hide show
  1. package/dist/modules/Discount/index.d.ts +0 -1
  2. package/dist/modules/Discount/index.js +11 -40
  3. package/dist/modules/Discount/types.d.ts +0 -1
  4. package/dist/modules/OpenData/index.js +2 -2
  5. package/dist/modules/Order/index.d.ts +2 -3
  6. package/dist/modules/Order/index.js +98 -82
  7. package/dist/modules/Order/types.d.ts +2 -9
  8. package/dist/modules/Order/utils.d.ts +0 -10
  9. package/dist/modules/Order/utils.js +3 -35
  10. package/dist/modules/Payment/walletpass.d.ts +10 -3
  11. package/dist/modules/Payment/walletpass.js +425 -282
  12. package/dist/modules/Product/types.d.ts +0 -1
  13. package/dist/modules/ProductList/index.js +14 -33
  14. package/dist/modules/Quotation/index.d.ts +1 -1
  15. package/dist/modules/Quotation/index.js +2 -2
  16. package/dist/modules/Rules/index.d.ts +2 -0
  17. package/dist/modules/Rules/index.js +72 -102
  18. package/dist/modules/SalesSummary/index.js +13 -12
  19. package/dist/modules/ScanOrderLogger/index.d.ts +0 -2
  20. package/dist/modules/ScanOrderLogger/index.js +2 -15
  21. package/dist/modules/ScanOrderLogger/providers/feishu.js +27 -45
  22. package/dist/modules/ScanOrderLogger/types.d.ts +0 -1
  23. package/dist/modules/Schedule/index.d.ts +1 -3
  24. package/dist/modules/Schedule/index.js +16 -21
  25. package/dist/modules/Summary/utils.js +13 -38
  26. package/dist/modules/index.d.ts +0 -2
  27. package/dist/modules/index.js +1 -3
  28. package/dist/plugins/window.d.ts +0 -1
  29. package/dist/server/index.d.ts +0 -14
  30. package/dist/server/index.js +657 -772
  31. package/dist/solution/BaseSales/index.d.ts +0 -7
  32. package/dist/solution/BaseSales/index.js +48 -67
  33. package/dist/solution/BaseSales/types.d.ts +3 -1
  34. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  35. package/dist/solution/BookingByStep/index.d.ts +1 -16
  36. package/dist/solution/BookingByStep/index.js +215 -294
  37. package/dist/solution/BookingByStep/types.d.ts +1 -2
  38. package/dist/solution/BookingByStep/types.js +1 -3
  39. package/dist/solution/BookingByStep/utils/capacity.js +1 -17
  40. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  41. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  42. package/dist/solution/BookingTicket/index.d.ts +1 -13
  43. package/dist/solution/BookingTicket/index.js +8 -5
  44. package/dist/solution/BookingTicket/types.d.ts +1 -0
  45. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +3 -3
  46. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +1 -3
  47. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -10
  48. package/dist/solution/ScanOrder/index.d.ts +14 -26
  49. package/dist/solution/ScanOrder/index.js +739 -1142
  50. package/dist/solution/ScanOrder/types.d.ts +1 -21
  51. package/dist/solution/ScanOrder/utils.d.ts +0 -8
  52. package/dist/solution/ScanOrder/utils.js +25 -66
  53. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  54. package/dist/solution/ShopDiscount/index.js +87 -125
  55. package/dist/solution/VenueBooking/index.d.ts +12 -39
  56. package/dist/solution/VenueBooking/index.js +841 -1167
  57. package/dist/solution/VenueBooking/types.d.ts +0 -3
  58. package/dist/solution/VenueBooking/utils/resource.js +0 -1
  59. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  60. package/dist/solution/VenueBooking/utils/slotMerge.js +5 -10
  61. package/dist/solution/index.d.ts +0 -1
  62. package/dist/solution/index.js +1 -2
  63. package/dist/types/index.d.ts +0 -1
  64. package/lib/model/strategy/adapter/promotion/index.js +51 -0
  65. package/lib/modules/Discount/index.d.ts +0 -1
  66. package/lib/modules/Discount/index.js +0 -9
  67. package/lib/modules/Discount/types.d.ts +0 -1
  68. package/lib/modules/OpenData/index.js +1 -1
  69. package/lib/modules/Order/index.d.ts +2 -3
  70. package/lib/modules/Order/index.js +56 -33
  71. package/lib/modules/Order/types.d.ts +2 -9
  72. package/lib/modules/Order/utils.d.ts +0 -10
  73. package/lib/modules/Order/utils.js +5 -36
  74. package/lib/modules/Payment/walletpass.d.ts +10 -3
  75. package/lib/modules/Payment/walletpass.js +218 -56
  76. package/lib/modules/Product/types.d.ts +0 -1
  77. package/lib/modules/ProductList/index.js +31 -40
  78. package/lib/modules/Quotation/index.d.ts +1 -1
  79. package/lib/modules/Quotation/index.js +2 -2
  80. package/lib/modules/Rules/index.d.ts +2 -0
  81. package/lib/modules/Rules/index.js +24 -36
  82. package/lib/modules/SalesSummary/index.js +7 -6
  83. package/lib/modules/ScanOrderLogger/index.d.ts +0 -2
  84. package/lib/modules/ScanOrderLogger/index.js +1 -13
  85. package/lib/modules/ScanOrderLogger/providers/feishu.js +6 -15
  86. package/lib/modules/ScanOrderLogger/types.d.ts +0 -1
  87. package/lib/modules/Schedule/index.d.ts +1 -3
  88. package/lib/modules/Schedule/index.js +8 -10
  89. package/lib/modules/Summary/utils.js +1 -21
  90. package/lib/modules/index.d.ts +0 -2
  91. package/lib/modules/index.js +1 -5
  92. package/lib/plugins/window.d.ts +0 -1
  93. package/lib/server/index.d.ts +0 -14
  94. package/lib/server/index.js +5 -65
  95. package/lib/solution/BaseSales/index.d.ts +0 -7
  96. package/lib/solution/BaseSales/index.js +9 -24
  97. package/lib/solution/BaseSales/types.d.ts +3 -1
  98. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  99. package/lib/solution/BookingByStep/index.d.ts +1 -16
  100. package/lib/solution/BookingByStep/index.js +18 -60
  101. package/lib/solution/BookingByStep/types.d.ts +1 -2
  102. package/lib/solution/BookingByStep/types.js +0 -5
  103. package/lib/solution/BookingByStep/utils/capacity.js +1 -20
  104. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  105. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  106. package/lib/solution/BookingTicket/index.d.ts +1 -13
  107. package/lib/solution/BookingTicket/index.js +3 -10
  108. package/lib/solution/BookingTicket/types.d.ts +1 -0
  109. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -2
  110. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +1 -3
  111. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -2
  112. package/lib/solution/ScanOrder/index.d.ts +14 -26
  113. package/lib/solution/ScanOrder/index.js +182 -449
  114. package/lib/solution/ScanOrder/types.d.ts +1 -21
  115. package/lib/solution/ScanOrder/utils.d.ts +0 -8
  116. package/lib/solution/ScanOrder/utils.js +0 -31
  117. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  118. package/lib/solution/ShopDiscount/index.js +0 -14
  119. package/lib/solution/VenueBooking/index.d.ts +12 -39
  120. package/lib/solution/VenueBooking/index.js +110 -322
  121. package/lib/solution/VenueBooking/types.d.ts +0 -3
  122. package/lib/solution/VenueBooking/utils/resource.js +0 -1
  123. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  124. package/lib/solution/VenueBooking/utils/slotMerge.js +4 -6
  125. package/lib/solution/index.d.ts +0 -1
  126. package/lib/solution/index.js +1 -3
  127. package/lib/types/index.d.ts +0 -1
  128. package/package.json +1 -1
  129. package/dist/modules/Holder/index.d.ts +0 -48
  130. package/dist/modules/Holder/index.js +0 -640
  131. package/dist/modules/Holder/types.d.ts +0 -123
  132. package/dist/modules/Holder/types.js +0 -1
  133. package/dist/modules/Holder/utils.d.ts +0 -13
  134. package/dist/modules/Holder/utils.js +0 -34
  135. package/dist/modules/ResourcePlanner/index.d.ts +0 -24
  136. package/dist/modules/ResourcePlanner/index.js +0 -181
  137. package/dist/modules/ResourcePlanner/planner.d.ts +0 -14
  138. package/dist/modules/ResourcePlanner/planner.js +0 -1069
  139. package/dist/modules/ResourcePlanner/types.d.ts +0 -227
  140. package/dist/modules/ResourcePlanner/types.js +0 -1
  141. package/dist/solution/UnifiedBookingSales/index.d.ts +0 -183
  142. package/dist/solution/UnifiedBookingSales/index.js +0 -1891
  143. package/dist/solution/UnifiedBookingSales/types.d.ts +0 -143
  144. package/dist/solution/UnifiedBookingSales/types.js +0 -11
  145. package/lib/modules/Holder/index.d.ts +0 -48
  146. package/lib/modules/Holder/index.js +0 -402
  147. package/lib/modules/Holder/types.d.ts +0 -123
  148. package/lib/modules/Holder/types.js +0 -17
  149. package/lib/modules/Holder/utils.d.ts +0 -13
  150. package/lib/modules/Holder/utils.js +0 -71
  151. package/lib/modules/ResourcePlanner/index.d.ts +0 -24
  152. package/lib/modules/ResourcePlanner/index.js +0 -148
  153. package/lib/modules/ResourcePlanner/planner.d.ts +0 -14
  154. package/lib/modules/ResourcePlanner/planner.js +0 -933
  155. package/lib/modules/ResourcePlanner/types.d.ts +0 -227
  156. package/lib/modules/ResourcePlanner/types.js +0 -17
  157. package/lib/solution/UnifiedBookingSales/index.d.ts +0 -183
  158. package/lib/solution/UnifiedBookingSales/index.js +0 -1084
  159. package/lib/solution/UnifiedBookingSales/types.d.ts +0 -143
  160. package/lib/solution/UnifiedBookingSales/types.js +0 -33
@@ -33,7 +33,7 @@ __export(ScanOrder_exports, {
33
33
  ScanOrderImpl: () => ScanOrderImpl
34
34
  });
35
35
  module.exports = __toCommonJS(ScanOrder_exports);
36
- var import_BaseSales = require("../BaseSales");
36
+ var import_BaseModule = require("../../modules/BaseModule");
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,6 +42,7 @@ 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");
45
46
  var import_getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
46
47
  var import_utils2 = require("../../modules/Order/utils");
47
48
  var import_dayjs = __toESM(require("dayjs"));
@@ -51,7 +52,7 @@ function isItemRewardProductDiscount(discount) {
51
52
  var _a, _b;
52
53
  return (discount == null ? void 0 : discount.type) === "product" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.source) === "promotion" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.actionType) === "ITEM_REWARD";
53
54
  }
54
- var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
55
+ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
55
56
  constructor(name, version) {
56
57
  super(name, version);
57
58
  this.defaultName = "scanOrder";
@@ -303,22 +304,28 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
303
304
  }
304
305
  }
305
306
  }
306
- getRegisteredModuleNames() {
307
- return ["scanOrderLogger", "products", "order", "salesSummary", "schedule"];
308
- }
309
- createSubModule(moduleName) {
310
- if (moduleName === "scanOrderLogger") {
311
- return (0, import_types4.createModule)("scanOrderLogger", this.name);
312
- }
313
- return super.createSubModule(moduleName);
314
- }
315
307
  /** 与 `otherParams.cacheId` 一致,供宿主在 URL 变化时判断是否需要重新注册模块 */
316
308
  getCacheId() {
317
309
  return this.cacheId;
318
310
  }
311
+ async destroyRegisteredChildModules() {
312
+ const modules = [
313
+ this.store.schedule,
314
+ this.store.salesSummary,
315
+ this.store.order,
316
+ this.store.products,
317
+ this.store.scanOrderLogger
318
+ ];
319
+ for (const mod of modules) {
320
+ if (mod && typeof mod.destroy === "function")
321
+ await Promise.resolve(mod.destroy());
322
+ }
323
+ }
319
324
  async initialize(core, options = {}) {
320
- var _a, _b, _c, _d, _e, _f, _g, _h;
325
+ var _a, _b, _c, _d, _e, _f;
321
326
  this.logMethodStart("initialize");
327
+ this.core = core;
328
+ this.initializeOptions = options || {};
322
329
  this.store = { ...this.store, ...options.store };
323
330
  this.store.entryContext = ((_a = options.otherParams) == null ? void 0 : _a.entryContext) || this.store.entryContext;
324
331
  this.store.status = "initializing";
@@ -334,26 +341,71 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
334
341
  passed: null,
335
342
  failures: []
336
343
  };
337
- await super.initialize(core, options);
338
- if (this.store.scanOrderLogger) {
339
- this.store.scanOrderLogger.setProvider(
340
- ((_e = this.otherParams) == null ? void 0 : _e.scanOrderLoggerProvider) || "feishu"
341
- );
342
- this.store.scanOrderLogger.setProviderConfig(
343
- ((_f = this.otherParams) == null ? void 0 : _f.scanOrderLoggerConfig) || {
344
+ this.window = core.getPlugin("window");
345
+ this.request = core.getPlugin("request");
346
+ if (!this.window) {
347
+ this.logMethodError("initialize", "window plugin missing");
348
+ throw new Error("scanOrder解决方案需要 window 插件支持");
349
+ }
350
+ if (!this.request) {
351
+ this.logMethodError("initialize", "request plugin missing");
352
+ throw new Error("scanOrder解决方案需要 request 插件支持");
353
+ }
354
+ const moduleArr = [
355
+ "scanOrderLogger",
356
+ "products",
357
+ "order",
358
+ "salesSummary"
359
+ ];
360
+ moduleArr.forEach((step) => {
361
+ var _a2, _b2, _c2, _d2, _e2, _f2;
362
+ const targetModule = (0, import_types4.createModule)(step, this.name);
363
+ if (targetModule) {
364
+ this.store[step] = targetModule;
365
+ const initialState = step === "salesSummary" ? {
366
+ summary: ((_b2 = (_a2 = this.store.order) == null ? void 0 : _a2.getTempOrder()) == null ? void 0 : _b2.summary) || (0, import_utils.createEmptySummary)()
367
+ } : {};
368
+ const loggerProvider = ((_c2 = this.otherParams) == null ? void 0 : _c2.scanOrderLoggerProvider) || "feishu";
369
+ const loggerConfig = ((_d2 = this.otherParams) == null ? void 0 : _d2.scanOrderLoggerConfig) || {
344
370
  feishu: {
345
371
  webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed",
346
372
  errorHook: "https://open.feishu.cn/open-apis/bot/v2/hook/015b7c2a-dd3c-4c30-9898-ef0f5253111f"
347
373
  }
348
- }
349
- );
374
+ };
375
+ this.core.registerModule(targetModule, {
376
+ initialState,
377
+ otherParams: {
378
+ ...this.otherParams,
379
+ fatherModule: this.name,
380
+ openCache: ((_e2 = this.otherParams) == null ? void 0 : _e2.cacheId) ? true : false,
381
+ cacheId: (_f2 = this.otherParams) == null ? void 0 : _f2.cacheId,
382
+ salesSummaryModuleName: `${this.name}_salesSummary`,
383
+ provider: loggerProvider,
384
+ providerConfig: loggerConfig,
385
+ context: this.getScanOrderLoggerContext()
386
+ }
387
+ });
388
+ } else {
389
+ this.logMethodError("initialize", `module ${step} missing`);
390
+ throw new Error(`模块 ${step} 不存在`);
391
+ }
392
+ });
393
+ if (this.store.scanOrderLogger) {
350
394
  this.store.scanOrderLogger.setContext(this.getScanOrderLoggerContext());
351
395
  }
396
+ const scheduleModule = new import_Schedule.ScheduleModule(`${this.name}_schedule`);
397
+ this.store.schedule = scheduleModule;
398
+ this.core.registerModule(scheduleModule, {
399
+ otherParams: {
400
+ ...this.otherParams,
401
+ fatherModule: this.name
402
+ }
403
+ });
352
404
  this.registerCustomerLoginListeners();
353
405
  console.log("[ScanOrder] 初始化开始");
354
406
  try {
355
- await ((_g = this.store.order) == null ? void 0 : _g.recalculateSummary({ createIfMissing: false }));
356
- (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
407
+ await ((_e = this.store.order) == null ? void 0 : _e.recalculateSummary({ createIfMissing: false }));
408
+ (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
357
409
  await this.loadRuntimeConfigs();
358
410
  if (this.store.schedule) {
359
411
  try {
@@ -385,6 +437,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
385
437
  this.logMethodStart("destroy");
386
438
  this.clearLoginEffectListeners();
387
439
  await this.core.effects.emit(import_types.ScanOrderHooks.onDestroy, {});
440
+ await this.destroyRegisteredChildModules();
388
441
  super.destroy();
389
442
  console.log("[ScanOrder] 已销毁");
390
443
  this.logMethodSuccess("destroy");
@@ -484,27 +537,18 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
484
537
  });
485
538
  return result;
486
539
  }
487
- updateTempOrderNote(note, sync = false) {
540
+ updateTempOrderNote(note) {
488
541
  this.logMethodStart("updateTempOrderNote", {
489
542
  noteLength: String(note || "").length
490
543
  });
491
544
  try {
492
545
  if (!this.store.order)
493
546
  throw new Error("order 模块未初始化");
494
- const result = this.store.order.updateTempOrderNote(note, sync);
495
- if (result && typeof result.then === "function") {
496
- return result.then((nextNote2) => {
497
- this.logMethodSuccess("updateTempOrderNote", {
498
- noteLength: nextNote2.length
499
- });
500
- return nextNote2;
501
- });
502
- }
503
- const nextNote = result;
547
+ const result = this.store.order.updateTempOrderNote(note);
504
548
  this.logMethodSuccess("updateTempOrderNote", {
505
- noteLength: nextNote.length
549
+ noteLength: result.length
506
550
  });
507
- return nextNote;
551
+ return result;
508
552
  } catch (error) {
509
553
  this.logMethodError("updateTempOrderNote", error);
510
554
  throw error;
@@ -513,7 +557,6 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
513
557
  // 存储 UI 层选择的取餐方式到 tempOrder.metadata.shop_service_data
514
558
  // service_type 在扫码点餐场景固定为 dine_in
515
559
  setPickupReferenceMode(mode) {
516
- var _a;
517
560
  this.logMethodStart("setPickupReferenceMode", { mode });
518
561
  try {
519
562
  if (!this.store.order)
@@ -523,7 +566,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
523
566
  ...tempOrder.metadata || {},
524
567
  shop_service_data: {
525
568
  ...(tempOrder.metadata || {}).shop_service_data || {},
526
- service_type: ((_a = this.otherParams) == null ? void 0 : _a.businessCode) === "dine_in" ? "dine_in" : "",
569
+ service_type: "dine_in",
527
570
  pickup_reference_mode: mode
528
571
  }
529
572
  };
@@ -555,7 +598,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
555
598
  throw error;
556
599
  }
557
600
  }
558
- ensureScanOrderTempOrder() {
601
+ ensureTempOrder() {
559
602
  if (!this.store.order)
560
603
  throw new Error("order 模块未初始化");
561
604
  return this.store.order.ensureTempOrder();
@@ -780,49 +823,6 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
780
823
  combined_resource: isCombined ? combined : null
781
824
  };
782
825
  }
783
- async prepareRetailAvailability(params) {
784
- var _a, _b;
785
- const { tempOrder, hasOrderId, resourceId, reason } = params;
786
- this.enabledReservationRuleProducts = [];
787
- tempOrder.bookings = [];
788
- tempOrder.order_id = null;
789
- delete tempOrder.relation_id;
790
- delete tempOrder.table_form_id;
791
- delete tempOrder.resource_id;
792
- delete tempOrder.table_number;
793
- tempOrder.metadata = { ...tempOrder.metadata || {} };
794
- delete tempOrder.metadata.table_occupancy_duration;
795
- const resourceState = {
796
- mode: "idle",
797
- deskmate_valid: false,
798
- allowSnack: false,
799
- deskmateValid: false,
800
- isExclusive: false,
801
- isFull: false,
802
- raw: null
803
- };
804
- this.store.resource = resourceState;
805
- (_a = this.store.order) == null ? void 0 : _a.persistTempOrder();
806
- await this.addNewOrder();
807
- await this.setItemRuleRuntimeConfig({
808
- serviceType: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
809
- submissionIndex: hasOrderId ? 1 : 0,
810
- historicalItems: []
811
- });
812
- const availabilityInfo = {
813
- mode: "idle",
814
- deskmate_valid: false
815
- };
816
- this.logMethodSuccess("checkResourceAvailable", {
817
- resourceId,
818
- mode: availabilityInfo.mode,
819
- retailMode: true,
820
- retailReason: reason,
821
- relationId: resourceState.relationId,
822
- persistedResourceId: resourceState.relationId
823
- });
824
- return availabilityInfo;
825
- }
826
826
  // ScanOrder 提交 payload enhancer:
827
827
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
828
828
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
@@ -832,33 +832,23 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
832
832
  const ruleProduct = this.enabledReservationRuleProducts[0];
833
833
  const resourceState = this.store.resource;
834
834
  const resourceSelectType = resourceState == null ? void 0 : resourceState.resourceSelectType;
835
- const resolveBookingCapacityValue = () => {
835
+ const resolveResourceCapacity = () => {
836
836
  var _a;
837
837
  if (resourceSelectType === "single") {
838
838
  const raw = (_a = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _a.capacity;
839
839
  const num = Number(raw);
840
840
  if (Number.isFinite(num) && num > 0)
841
- return Math.max(1, Math.floor(num));
841
+ return num;
842
842
  return 1;
843
843
  }
844
844
  return 1;
845
845
  };
846
846
  return (payload, { bookingUuid, tempOrder }) => {
847
847
  var _a, _b;
848
- const resourceId = String((resourceState == null ? void 0 : resourceState.relationId) ?? "").trim();
849
- const hasReservationBookingContext = Boolean(
850
- ruleProduct && resourceState && resourceId && resourceState.relationId && resourceState.tableFormId
851
- );
852
- if (!hasReservationBookingContext) {
853
- return {
854
- ...payload,
855
- bookings: [],
856
- products: [...payload.products || []]
857
- };
858
- }
848
+ const resourceId = tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId);
859
849
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
860
- const hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
861
- const bookingCapacityValue = resolveBookingCapacityValue();
850
+ const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
851
+ const resourceCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
862
852
  const pickOriginal = (value) => {
863
853
  if (value && typeof value === "object" && !Array.isArray(value)) {
864
854
  const original = value.original;
@@ -874,42 +864,35 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
874
864
  main_field: mainField,
875
865
  form_id: resourceState.tableFormId,
876
866
  relation_id: resourceState.relationId ?? resourceId,
877
- capacity: bookingCapacityValue,
867
+ capacity: resourceCapacityValue,
878
868
  metadata: this.buildScanOrderResourceMetadata({
879
869
  resourceState,
880
870
  resourceName: mainField
881
871
  })
882
872
  } : void 0;
883
873
  const ruleProductUid = ruleProduct ? (0, import_utils2.createUuidV4)() : void 0;
874
+ const bookingCapacityValue = resourceCapacityValue;
884
875
  const bookingCapacityDimensionId = (0, import_utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
885
- const nextBookings = (payload.bookings || []).map((booking, idx) => {
886
- const metadata = { ...booking.metadata || {} };
887
- if (hasExplicitCollectPax) {
888
- metadata.collect_pax = (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax);
889
- } else {
890
- delete metadata.collect_pax;
891
- }
892
- return {
893
- ...booking,
894
- number: bookingCapacityValue,
895
- appointment_status: "started",
896
- metadata: {
897
- ...metadata,
898
- ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
899
- ...resourceSelectType ? {
900
- capacity: [
901
- {
902
- id: bookingCapacityDimensionId,
903
- value: bookingCapacityValue,
904
- name: ""
905
- }
906
- ]
907
- } : {}
908
- },
909
- ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
910
- ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
911
- };
912
- });
876
+ const nextBookings = (payload.bookings || []).map((booking, idx) => ({
877
+ ...booking,
878
+ number: bookingCapacityValue,
879
+ appointment_status: "started",
880
+ metadata: {
881
+ ...booking.metadata || {},
882
+ ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
883
+ ...resourceSelectType ? {
884
+ capacity: [
885
+ {
886
+ id: bookingCapacityDimensionId,
887
+ value: bookingCapacityValue,
888
+ name: ""
889
+ }
890
+ ]
891
+ } : {}
892
+ },
893
+ ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
894
+ ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
895
+ }));
913
896
  const nextProducts = [...payload.products || []];
914
897
  if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
915
898
  const sellingPrice = String(ruleProduct.price ?? "0.00");
@@ -938,58 +921,8 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
938
921
  return { ...payload, bookings: nextBookings, products: nextProducts };
939
922
  };
940
923
  }
941
- isScanOrderMoreMode(tempOrder) {
942
- var _a, _b;
943
- const mode = (_a = this.store.resource) == null ? void 0 : _a.mode;
944
- return Boolean(
945
- tempOrder.order_id && (mode === "additional_order" || mode === "additional_order_with_code" || ((_b = this.store.entryContext) == null ? void 0 : _b.mode) === "append")
946
- );
947
- }
948
- async submitScanOrderMore(params) {
949
- var _a, _b, _c, _d, _e;
950
- if (!this.request) {
951
- throw new Error("scanOrder解决方案需要 request 插件支持");
952
- }
953
- if (!this.store.order) {
954
- throw new Error("scanOrder解决方案需要 order 模块支持");
955
- }
956
- const { tempOrder, enhancePayload } = params;
957
- const latestSummary = await this.store.order.recalculateSummary({
958
- createIfMissing: true
959
- });
960
- const payload = (0, import_utils2.buildSubmitPayload)({
961
- tempOrder,
962
- cacheId: this.cacheId,
963
- platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
964
- businessCode: ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code),
965
- channel: (_d = this.otherParams) == null ? void 0 : _d.channel,
966
- type: (_e = this.otherParams) == null ? void 0 : _e.type,
967
- summary: latestSummary,
968
- enhance: enhancePayload
969
- });
970
- const products = (0, import_utils.filterProductsForScanOrderMore)(payload.products);
971
- const orderId = tempOrder.order_id;
972
- const result = await this.request.put(
973
- `/order/order/product/${orderId}`,
974
- {
975
- products,
976
- request_unique_idempotency_token: payload.request_unique_idempotency_token
977
- },
978
- { customToast: () => {
979
- } }
980
- );
981
- if ((result == null ? void 0 : result.code) === 200 && !(result == null ? void 0 : result.data)) {
982
- return {
983
- ...result,
984
- data: {
985
- order_id: orderId
986
- }
987
- };
988
- }
989
- return result;
990
- }
991
924
  async submitScanOrder() {
992
- var _a, _b, _c;
925
+ var _a, _b, _c, _d, _e, _f, _g;
993
926
  this.logMethodStart("submitScanOrder");
994
927
  try {
995
928
  await this.validateBeforeSubmitByItemRule();
@@ -1009,15 +942,17 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1009
942
  }
1010
943
  this.store.order.persistTempOrder();
1011
944
  const enhancePayload = this.buildSubmitPayloadEnhancer();
1012
- const result = this.isScanOrderMoreMode(tempOrderForSubmit) ? await this.submitScanOrderMore({
1013
- tempOrder: tempOrderForSubmit,
1014
- enhancePayload
1015
- }) : await this.submitSalesOrder({
945
+ const result = await this.store.order.submitTempOrder({
946
+ cacheId: this.cacheId,
947
+ platform: (_c = this.otherParams) == null ? void 0 : _c.platform,
948
+ businessCode: (_d = this.otherParams) == null ? void 0 : _d.businessCode,
949
+ channel: (_e = this.otherParams) == null ? void 0 : _e.channel,
950
+ type: (_f = this.otherParams) == null ? void 0 : _f.type,
1016
951
  enhancePayload
1017
952
  });
1018
953
  const tempOrder = this.store.order.getTempOrder();
1019
954
  this.logMethodSuccess("submitScanOrder", {
1020
- productCount: ((_c = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _c.length) || 0
955
+ productCount: ((_g = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _g.length) || 0
1021
956
  });
1022
957
  return result;
1023
958
  } catch (error) {
@@ -1258,7 +1193,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1258
1193
  return [];
1259
1194
  }
1260
1195
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1261
- tempOrder: this.ensureScanOrderTempOrder(),
1196
+ tempOrder: this.ensureTempOrder(),
1262
1197
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1263
1198
  itemRuleConfigs: this.itemRuleConfigs
1264
1199
  });
@@ -1284,7 +1219,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1284
1219
  if (!strategyConfigs.length)
1285
1220
  return;
1286
1221
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1287
- tempOrder: this.ensureScanOrderTempOrder(),
1222
+ tempOrder: this.ensureTempOrder(),
1288
1223
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1289
1224
  itemRuleConfigs: this.itemRuleConfigs
1290
1225
  });
@@ -1294,7 +1229,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1294
1229
  return;
1295
1230
  }
1296
1231
  const productSourceMap = await this.buildPrefillProductSourceMap();
1297
- const tempOrder = this.ensureScanOrderTempOrder();
1232
+ const tempOrder = this.ensureTempOrder();
1298
1233
  let hasChanges = false;
1299
1234
  for (const prefillItem of prefillItems) {
1300
1235
  const productId = Number(prefillItem.product_id);
@@ -1394,7 +1329,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1394
1329
  };
1395
1330
  }
1396
1331
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1397
- tempOrder: this.ensureScanOrderTempOrder(),
1332
+ tempOrder: this.ensureTempOrder(),
1398
1333
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1399
1334
  itemRuleConfigs: this.itemRuleConfigs
1400
1335
  });
@@ -1544,8 +1479,8 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1544
1479
  const matched = resources.find((r) => Number(r == null ? void 0 : r.id) === numericFormId);
1545
1480
  return matched == null ? void 0 : matched.type;
1546
1481
  }
1547
- async fetchResourceOccupyDetailsByResourceId(resourceId) {
1548
- var _a, _b, _c;
1482
+ async fetchResourceOccupyDetailByResourceId(resourceId) {
1483
+ var _a, _b, _c, _d;
1549
1484
  const formRecordId = Number(resourceId);
1550
1485
  if (!Number.isFinite(formRecordId) || formRecordId <= 0) {
1551
1486
  throw new Error(`[ScanOrder] 非法桌台 resourceId: ${resourceId}`);
@@ -1567,60 +1502,15 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1567
1502
  if (!(response == null ? void 0 : response.status)) {
1568
1503
  throw new Error((response == null ? void 0 : response.message) || "获取资源占用详情失败");
1569
1504
  }
1570
- return ((_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) ?? [];
1571
- }
1572
- resolveAdditionalOrderFromOccupyDetail(detail, resourceSelectType, allowAddItems) {
1573
- const currentOrderId = (0, import_utils.toPositiveString)(detail == null ? void 0 : detail.order_id);
1574
- if (currentOrderId) {
1575
- return {
1576
- matched: true,
1577
- order_id: currentOrderId
1578
- };
1579
- }
1580
- 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);
1581
- if (resourceSelectType !== "single") {
1582
- return {
1583
- matched: false,
1584
- reason: "no_order"
1585
- };
1586
- }
1587
- if (!orderListIds.length) {
1588
- return {
1589
- matched: false,
1590
- reason: "no_order"
1591
- };
1592
- }
1593
- if (!allowAddItems) {
1594
- return {
1595
- matched: false,
1596
- reason: "add_items_disabled"
1597
- };
1598
- }
1599
- if (orderListIds.length === 1) {
1600
- return {
1601
- matched: true,
1602
- order_id: orderListIds[0]
1603
- };
1604
- }
1605
- if (orderListIds.length > 1) {
1606
- return {
1607
- matched: false,
1608
- reason: "multiple_orders"
1609
- };
1610
- }
1611
- return {
1612
- matched: false,
1613
- reason: "no_order"
1614
- };
1505
+ return ((_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) == null ? void 0 : _d[0]) ?? null;
1615
1506
  }
1616
1507
  // 检测当前链接是否可用
1617
1508
  // 通过 resource_id + 店铺配置
1618
1509
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1619
- async checkResourceAvailable(resourceId, hasOrderId = false) {
1620
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1621
- const normalizedResourceId = String(resourceId ?? "").trim();
1510
+ async checkResourceAvailable(resourceId, hasOrderId) {
1511
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1622
1512
  this.logMethodStart("checkResourceAvailable", {
1623
- resourceId: normalizedResourceId
1513
+ resourceId
1624
1514
  });
1625
1515
  try {
1626
1516
  const businessCode = String(((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? "").trim();
@@ -1670,71 +1560,37 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1670
1560
  if (outsideOperatingHours && closedBehaviorValue !== "show_menu_disabled") {
1671
1561
  return makeShopClosed(closedMessage, closedBehaviorValue);
1672
1562
  }
1673
- const tempOrder = this.ensureScanOrderTempOrder();
1563
+ const tempOrder = this.ensureTempOrder();
1674
1564
  const reservationLinkIds = (0, import_utils.collectLinkProductIdsFromReservationRules)(
1675
1565
  dineInConfig["fulfillment.enabled_resource_rules"]
1676
1566
  );
1677
- if (!normalizedResourceId || reservationLinkIds.length === 0) {
1678
- return await this.prepareRetailAvailability({
1679
- tempOrder,
1680
- hasOrderId,
1681
- resourceId: normalizedResourceId,
1682
- reason: !normalizedResourceId ? "missing_resource_id" : "missing_enabled_resource_rules"
1683
- });
1684
- }
1685
1567
  let pendingRequestEntryPax;
1686
1568
  let pendingRequestPaxMin;
1687
1569
  let pendingRequestPaxMax;
1688
- tempOrder.metadata = { ...tempOrder.metadata || {} };
1689
- delete tempOrder.metadata.table_occupancy_duration;
1690
- const reservationProductList = new import_ProductList.ProductList(
1691
- `${this.name}_reservationEnabledRules`,
1692
- this.defaultVersion
1693
- );
1694
- await reservationProductList.initialize(this.core, {
1695
- store: { list: [], selectProducts: [] },
1696
- otherParams: {
1697
- ...this.otherParams,
1698
- fatherModule: this.name,
1699
- openCache: Boolean(this.cacheId),
1700
- cacheId: this.cacheId
1701
- }
1702
- });
1703
- const scheduleDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1704
- const scheduleDatetime = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1705
- const loaded = await reservationProductList.loadProducts({
1706
- product_ids: reservationLinkIds,
1707
- schedule_date: scheduleDate,
1708
- schedule_datetime: scheduleDatetime,
1709
- cacheId: this.cacheId
1710
- });
1711
- if (Array.isArray(loaded)) {
1712
- const matchedRuleProduct = (0, import_utils.findReservationRuleProductByResourceId)(
1713
- loaded,
1714
- normalizedResourceId
1715
- );
1716
- const ruleProductsForResource = matchedRuleProduct ? [matchedRuleProduct] : [];
1717
- this.enabledReservationRuleProducts = ruleProductsForResource;
1718
- const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(ruleProductsForResource);
1719
- if (occupancyMinutes !== void 0) {
1720
- tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
1721
- }
1722
- if ((0, import_utils.hasCustomCapacityProduct)(ruleProductsForResource)) {
1723
- pendingRequestEntryPax = 1;
1724
- const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(ruleProductsForResource);
1725
- if ((paxBounds == null ? void 0 : paxBounds.min) !== void 0)
1726
- pendingRequestPaxMin = paxBounds.min;
1727
- if ((paxBounds == null ? void 0 : paxBounds.max) !== void 0)
1728
- pendingRequestPaxMax = paxBounds.max;
1729
- }
1730
- } else {
1570
+ if (reservationLinkIds.length === 0) {
1731
1571
  this.enabledReservationRuleProducts = [];
1732
- const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1733
- this.logMethodError("loadReservationRuleProducts", error, {
1734
- resourceId: normalizedResourceId,
1735
- reservationLinkIds,
1736
- scheduleDate,
1737
- scheduleDatetime,
1572
+ } else {
1573
+ tempOrder.metadata = { ...tempOrder.metadata || {} };
1574
+ delete tempOrder.metadata.table_occupancy_duration;
1575
+ const reservationProductList = new import_ProductList.ProductList(
1576
+ `${this.name}_reservationEnabledRules`,
1577
+ this.defaultVersion
1578
+ );
1579
+ await reservationProductList.initialize(this.core, {
1580
+ store: { list: [], selectProducts: [] },
1581
+ otherParams: {
1582
+ ...this.otherParams,
1583
+ fatherModule: this.name,
1584
+ openCache: Boolean(this.cacheId),
1585
+ cacheId: this.cacheId
1586
+ }
1587
+ });
1588
+ const scheduleDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1589
+ const scheduleDatetime = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1590
+ const loaded = await reservationProductList.loadProducts({
1591
+ product_ids: reservationLinkIds,
1592
+ schedule_date: scheduleDate,
1593
+ schedule_datetime: scheduleDatetime,
1738
1594
  cacheId: this.cacheId
1739
1595
  });
1740
1596
  if (Array.isArray(loaded)) {
@@ -1753,8 +1609,8 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1753
1609
  }
1754
1610
  } else {
1755
1611
  this.enabledReservationRuleProducts = [];
1756
- const error2 = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1757
- this.logMethodError("loadReservationRuleProducts", error2, {
1612
+ const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1613
+ this.logMethodError("loadReservationRuleProducts", error, {
1758
1614
  resourceId,
1759
1615
  reservationLinkIds,
1760
1616
  scheduleDate,
@@ -1763,54 +1619,15 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1763
1619
  });
1764
1620
  }
1765
1621
  }
1766
- const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1767
- const occupyDetail = occupyDetails[0] ?? null;
1622
+ const occupyDetail = await this.fetchResourceOccupyDetailByResourceId(resourceId);
1768
1623
  const resourceSelectType = this.resolveResourceSelectType(
1769
1624
  (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1770
1625
  );
1771
- const allowAddItems = (0, import_utils.toBoolean)(dineInConfig == null ? void 0 : dineInConfig["sale.allow_add_items"]);
1772
- const additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(
1773
- occupyDetail,
1774
- resourceSelectType,
1775
- allowAddItems
1776
- );
1777
- if (additionalOrderResult.reason === "multiple_orders") {
1778
- const multipleOrdersState = {
1779
- ...this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId),
1780
- mode: "multiple_orders"
1781
- };
1782
- this.store.resource = multipleOrdersState;
1783
- const availabilityInfo2 = {
1784
- mode: "multiple_orders",
1785
- deskmate_valid: multipleOrdersState.deskmate_valid,
1786
- relation_id: multipleOrdersState.relationId,
1787
- table_form_id: multipleOrdersState.tableFormId,
1788
- table_form_record: multipleOrdersState.table_form_record
1789
- };
1790
- this.logMethodSuccess("checkResourceAvailable", {
1791
- resourceId: normalizedResourceId,
1792
- mode: availabilityInfo2.mode,
1793
- orderListCount: ((_e = occupyDetail == null ? void 0 : occupyDetail.order_list) == null ? void 0 : _e.length) || 0,
1794
- resourceSelectType
1795
- });
1796
- return availabilityInfo2;
1797
- }
1798
1626
  const resourceState = this.normalizeResourceState(
1799
1627
  occupyDetail,
1800
1628
  resourceSelectType,
1801
1629
  hasOrderId
1802
1630
  );
1803
- const additionalOrderId = additionalOrderResult.order_id;
1804
- if (additionalOrderId) {
1805
- resourceState.mode = "additional_order";
1806
- resourceState.order_id = additionalOrderId;
1807
- } else if (additionalOrderResult.reason === "add_items_disabled") {
1808
- resourceState.mode = "resource_busy";
1809
- resourceState.order_id = "0";
1810
- } else if (resourceSelectType === "multiple" && resourceState.isFull) {
1811
- resourceState.mode = "resource_busy";
1812
- resourceState.order_id = "0";
1813
- }
1814
1631
  this.store.resource = resourceState;
1815
1632
  if (pendingRequestEntryPax !== void 0) {
1816
1633
  this.store.resource.requestEntryPax = pendingRequestEntryPax;
@@ -1828,22 +1645,36 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1828
1645
  table_form_id: resourceState.tableFormId,
1829
1646
  deskmate_valid: resourceState.deskmate_valid,
1830
1647
  table_form_record: resourceState.table_form_record,
1831
- policy: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.policy,
1832
- partyroom_booking: (_g = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _g.partyroom_booking,
1648
+ policy: (_e = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _e.policy,
1649
+ partyroom_booking: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.partyroom_booking,
1833
1650
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1834
1651
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1835
1652
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1836
1653
  };
1654
+ tempOrder.relation_id = resourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1655
+ tempOrder.table_form_id = resourceState.tableFormId;
1656
+ tempOrder.resource_id = resourceId;
1837
1657
  (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1838
1658
  if (availabilityInfo.mode === "idle") {
1839
1659
  await this.addNewOrder();
1840
1660
  }
1841
- const isAdditionalOrderMode = availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code";
1842
- if (isAdditionalOrderMode) {
1843
- tempOrder.order_id = additionalOrderId;
1661
+ if (availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code") {
1662
+ tempOrder.order_id = resourceState.lastOrderId;
1663
+ }
1664
+ if (tempOrder.order_id) {
1665
+ const res = await ((_i = this.store.order) == null ? void 0 : _i.getSalesOrderByLookup({
1666
+ lookup: tempOrder.order_id
1667
+ }));
1668
+ const entryPaxNumber = (_m = (_l = (_k = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.bookings) == null ? void 0 : _k.find((p) => {
1669
+ var _a2;
1670
+ return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1671
+ })) == null ? void 0 : _l.metadata) == null ? void 0 : _m.collect_pax;
1672
+ if (entryPaxNumber) {
1673
+ await this.setEntryPaxNumber(entryPaxNumber);
1674
+ }
1844
1675
  }
1845
- const lastOrderInfo = (_j = (_i = this.store.order) == null ? void 0 : _i.getLastOrderInfo) == null ? void 0 : _j.call(_i);
1846
- const historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1676
+ const lastOrderInfo = (_o = (_n = this.store.order) == null ? void 0 : _n.getLastOrderInfo) == null ? void 0 : _o.call(_n);
1677
+ const historicalItems = hasOrderId && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1847
1678
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1848
1679
  return acc;
1849
1680
  acc.push({
@@ -1854,8 +1685,8 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1854
1685
  return acc;
1855
1686
  }, []) : [];
1856
1687
  await this.setItemRuleRuntimeConfig({
1857
- serviceType: (_k = this.otherParams) == null ? void 0 : _k.businessCode,
1858
- submissionIndex: isAdditionalOrderMode ? 1 : 0,
1688
+ serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1689
+ submissionIndex: hasOrderId ? 1 : 0,
1859
1690
  historicalItems
1860
1691
  });
1861
1692
  if (outsideOperatingHours && closedBehaviorValue === "show_menu_disabled") {
@@ -1864,13 +1695,13 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1864
1695
  availabilityInfo.closed_behavior = closedBehaviorValue;
1865
1696
  }
1866
1697
  this.logMethodSuccess("checkResourceAvailable", {
1867
- resourceId: normalizedResourceId,
1698
+ resourceId,
1868
1699
  mode: availabilityInfo.mode,
1869
1700
  orderId: availabilityInfo.order_id,
1870
1701
  relationId: availabilityInfo.relation_id,
1871
1702
  tableFormId: availabilityInfo.table_form_id,
1872
- persistedRelationId: (_l = this.store.resource) == null ? void 0 : _l.relationId,
1873
- persistedResourceId: (_m = this.store.resource) == null ? void 0 : _m.relationId,
1703
+ persistedRelationId: tempOrder.relation_id,
1704
+ persistedResourceId: tempOrder.resource_id,
1874
1705
  deskmateValid: availabilityInfo.deskmate_valid,
1875
1706
  resourceSelectType: resourceState.resourceSelectType,
1876
1707
  isExclusive: resourceState.isExclusive,
@@ -1879,29 +1710,11 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1879
1710
  return availabilityInfo;
1880
1711
  } catch (error) {
1881
1712
  this.logMethodError("checkResourceAvailable", error.message, {
1882
- resourceId: normalizedResourceId
1713
+ resourceId
1883
1714
  });
1884
1715
  throw error;
1885
1716
  }
1886
1717
  }
1887
- // 恢复之前订单的数据,读取 entrypax
1888
- async restorePreviousOrderData() {
1889
- var _a, _b, _c, _d;
1890
- const orderModule = this.store.order;
1891
- if (!orderModule)
1892
- return;
1893
- const tempOrder = orderModule.ensureTempOrder();
1894
- if (tempOrder.order_id) {
1895
- const res = await orderModule.getOrderInfo(tempOrder.order_id);
1896
- const entryPaxNumber = (_d = (_c = (_b = (_a = res == null ? void 0 : res.data) == null ? void 0 : _a.bookings) == null ? void 0 : _b.find((p) => {
1897
- var _a2;
1898
- return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1899
- })) == null ? void 0 : _c.metadata) == null ? void 0 : _d.collect_pax;
1900
- if (entryPaxNumber) {
1901
- await this.setEntryPaxNumber(entryPaxNumber);
1902
- }
1903
- }
1904
- }
1905
1718
  // 如果是加单的情况,提供返回当前订单相关信息的能力
1906
1719
  async getAdditionalOrderInfo() {
1907
1720
  this.logMethodStart("getAdditionalOrderInfo");
@@ -1922,8 +1735,7 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
1922
1735
  async getProductList() {
1923
1736
  var _a, _b;
1924
1737
  this.logMethodStart("getProductList");
1925
- const associatedMenus = (_b = (_a = this.otherParams) == null ? void 0 : _a.dineInConfig) == null ? void 0 : _b["menu.associated_menus"];
1926
- const menu_list_ids = associatedMenus.map((n) => Number(n.value)) || [];
1738
+ 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))) || [];
1927
1739
  try {
1928
1740
  if (!this.store.products)
1929
1741
  throw new Error("products 模块未初始化");
@@ -2047,85 +1859,6 @@ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
2047
1859
  getEntryPaxNumber() {
2048
1860
  return this.store.entryPaxNumber;
2049
1861
  }
2050
- async syncAdditionalOrderFromResource(resourceId) {
2051
- var _a, _b, _c, _d, _e, _f;
2052
- if (!this.store.order)
2053
- throw new Error("order 模块未初始化");
2054
- const tempOrder = this.store.order.ensureTempOrder();
2055
- const normalizedResourceId = String(
2056
- resourceId ?? tempOrder.resource_id ?? ((_a = this.store.resource) == null ? void 0 : _a.relationId) ?? ((_b = this.store.resource) == null ? void 0 : _b.relation_id) ?? ""
2057
- ).trim();
2058
- this.logMethodStart("syncAdditionalOrderFromResource", {
2059
- resourceId: normalizedResourceId
2060
- });
2061
- if (!normalizedResourceId) {
2062
- const result2 = {
2063
- matched: false,
2064
- reason: "missing_resource_id"
2065
- };
2066
- this.logMethodSuccess("syncAdditionalOrderFromResource", result2);
2067
- return result2;
2068
- }
2069
- const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2070
- const occupyDetail = occupyDetails[0] ?? null;
2071
- const resourceSelectType = ((_c = this.store.resource) == null ? void 0 : _c.resourceSelectType) || this.resolveResourceSelectType((0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id));
2072
- const allowAddItems = (0, import_utils.toBoolean)(
2073
- (_e = (_d = this.otherParams) == null ? void 0 : _d.dineInConfig) == null ? void 0 : _e["sale.allow_add_items"]
2074
- );
2075
- const result = this.resolveAdditionalOrderFromOccupyDetail(
2076
- occupyDetail,
2077
- resourceSelectType,
2078
- allowAddItems
2079
- );
2080
- if (!result.matched || !result.order_id) {
2081
- this.logMethodSuccess("syncAdditionalOrderFromResource", {
2082
- ...result,
2083
- resourceId: normalizedResourceId,
2084
- resourceSelectType,
2085
- allowAddItems
2086
- });
2087
- return result;
2088
- }
2089
- tempOrder.order_id = result.order_id;
2090
- tempOrder.resource_id = normalizedResourceId;
2091
- tempOrder.relation_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
2092
- tempOrder.table_form_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
2093
- (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
2094
- this.logMethodSuccess("syncAdditionalOrderFromResource", {
2095
- ...result,
2096
- resourceId: normalizedResourceId,
2097
- resourceSelectType,
2098
- allowAddItems
2099
- });
2100
- return result;
2101
- }
2102
- // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
2103
- // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
2104
- getReservationResourceSelectType() {
2105
- var _a;
2106
- this.logMethodStart("getReservationResourceSelectType");
2107
- const resourceSelectType = (_a = this.store.resource) == null ? void 0 : _a.resourceSelectType;
2108
- const result = {
2109
- ...resourceSelectType ? { resourceSelectType } : {},
2110
- isSingleReservation: resourceSelectType === "single",
2111
- isMultipleReservation: resourceSelectType === "multiple",
2112
- isCapacityReservation: resourceSelectType === "capacity"
2113
- };
2114
- this.logMethodSuccess("getReservationResourceSelectType", result);
2115
- return result;
2116
- }
2117
- // 判定后台是否开启允许加餐
2118
- // 依赖 checkResourceAvailable 已缓存的 dineInConfig
2119
- checkAllowAddItems() {
2120
- var _a;
2121
- this.logMethodStart("checkAllowAddItems");
2122
- const dineInConfig = ((_a = this.otherParams) == null ? void 0 : _a.dineInConfig) || {};
2123
- const result = {
2124
- enabled: (0, import_utils.toBoolean)(dineInConfig["sale.allow_add_items"])
2125
- };
2126
- this.logMethodSuccess("checkAllowAddItems", result);
2127
- return result;
2128
- }
2129
1862
  // 读取取餐/送餐开关
2130
1863
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
2131
1864
  getFulfillmentModes() {