@pisell/pisellos 2.3.38 → 2.3.40

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 (229) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +0 -7
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  4. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  8. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  11. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  12. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -5
  13. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +3 -6
  14. package/dist/modules/Discount/index.d.ts +1 -0
  15. package/dist/modules/Discount/index.js +40 -11
  16. package/dist/modules/Discount/types.d.ts +1 -0
  17. package/dist/modules/Holder/index.d.ts +48 -0
  18. package/dist/modules/Holder/index.js +640 -0
  19. package/dist/modules/Holder/types.d.ts +123 -0
  20. package/dist/modules/Holder/types.js +1 -0
  21. package/dist/modules/Holder/utils.d.ts +13 -0
  22. package/dist/modules/Holder/utils.js +34 -0
  23. package/dist/modules/OpenData/index.d.ts +0 -2
  24. package/dist/modules/OpenData/index.js +2 -10
  25. package/dist/modules/Order/index.d.ts +11 -28
  26. package/dist/modules/Order/index.js +509 -750
  27. package/dist/modules/Order/types.d.ts +10 -33
  28. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  29. package/dist/modules/Order/utils.d.ts +10 -0
  30. package/dist/modules/Order/utils.js +41 -13
  31. package/dist/modules/Payment/index.d.ts +0 -2
  32. package/dist/modules/Payment/index.js +50 -79
  33. package/dist/modules/Payment/types.d.ts +28 -99
  34. package/dist/modules/Payment/types.js +3 -20
  35. package/dist/modules/Payment/walletpass.d.ts +1 -25
  36. package/dist/modules/Payment/walletpass.js +157 -707
  37. package/dist/modules/Product/types.d.ts +1 -0
  38. package/dist/modules/ProductList/index.js +33 -14
  39. package/dist/modules/Quotation/index.d.ts +1 -1
  40. package/dist/modules/Quotation/index.js +2 -2
  41. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  42. package/dist/modules/ResourcePlanner/index.js +181 -0
  43. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  44. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  45. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  46. package/dist/modules/ResourcePlanner/types.js +1 -0
  47. package/dist/modules/Rules/index.d.ts +0 -1
  48. package/dist/modules/Rules/index.js +96 -89
  49. package/dist/modules/SalesSummary/index.js +12 -13
  50. package/dist/modules/ScanOrderLogger/index.d.ts +2 -0
  51. package/dist/modules/ScanOrderLogger/index.js +15 -2
  52. package/dist/modules/ScanOrderLogger/providers/feishu.js +45 -27
  53. package/dist/modules/ScanOrderLogger/types.d.ts +1 -0
  54. package/dist/modules/Schedule/index.d.ts +3 -1
  55. package/dist/modules/Schedule/index.js +21 -16
  56. package/dist/modules/Summary/utils.js +38 -13
  57. package/dist/modules/index.d.ts +2 -0
  58. package/dist/modules/index.js +3 -1
  59. package/dist/plugins/window.d.ts +1 -0
  60. package/dist/server/index.d.ts +14 -16
  61. package/dist/server/index.js +1148 -1930
  62. package/dist/server/modules/order/index.d.ts +4 -54
  63. package/dist/server/modules/order/index.js +695 -1595
  64. package/dist/server/modules/order/types.d.ts +3 -11
  65. package/dist/server/modules/order/types.js +1 -1
  66. package/dist/solution/BaseSales/index.d.ts +20 -109
  67. package/dist/solution/BaseSales/index.js +481 -1797
  68. package/dist/solution/BaseSales/types.d.ts +0 -52
  69. package/dist/solution/BaseSales/types.js +1 -2
  70. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  71. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  72. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  73. package/dist/solution/BookingByStep/index.d.ts +17 -2
  74. package/dist/solution/BookingByStep/index.js +294 -215
  75. package/dist/solution/BookingByStep/types.d.ts +2 -1
  76. package/dist/solution/BookingByStep/types.js +3 -1
  77. package/dist/solution/BookingByStep/utils/capacity.js +17 -1
  78. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  79. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  80. package/dist/solution/BookingTicket/index.d.ts +4 -8
  81. package/dist/solution/BookingTicket/index.js +51 -134
  82. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -6
  83. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  84. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +82 -172
  85. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  86. package/dist/solution/BookingTicket/utils/scan/handleScan.js +10 -2
  87. package/dist/solution/Sales/index.d.ts +0 -1
  88. package/dist/solution/Sales/index.js +2 -10
  89. package/dist/solution/ScanOrder/index.d.ts +26 -14
  90. package/dist/solution/ScanOrder/index.js +1148 -756
  91. package/dist/solution/ScanOrder/types.d.ts +21 -1
  92. package/dist/solution/ScanOrder/utils.d.ts +8 -0
  93. package/dist/solution/ScanOrder/utils.js +66 -25
  94. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  95. package/dist/solution/ShopDiscount/index.js +125 -87
  96. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  97. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  98. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  99. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  100. package/dist/solution/VenueBooking/index.d.ts +39 -11
  101. package/dist/solution/VenueBooking/index.js +1176 -860
  102. package/dist/solution/VenueBooking/types.d.ts +3 -0
  103. package/dist/solution/VenueBooking/utils/resource.js +1 -0
  104. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  105. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -5
  106. package/dist/solution/index.d.ts +1 -0
  107. package/dist/solution/index.js +2 -1
  108. package/dist/types/index.d.ts +1 -1
  109. package/lib/core/index.d.ts +0 -2
  110. package/lib/core/index.js +0 -4
  111. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  112. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  113. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  114. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  115. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  116. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  117. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  118. package/lib/model/strategy/adapter/promotion/index.js +0 -2
  119. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  120. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  121. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +1 -2
  122. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -2
  123. package/lib/modules/Discount/index.d.ts +1 -0
  124. package/lib/modules/Discount/index.js +9 -0
  125. package/lib/modules/Discount/types.d.ts +1 -0
  126. package/lib/modules/Holder/index.d.ts +48 -0
  127. package/lib/modules/Holder/index.js +402 -0
  128. package/lib/modules/Holder/types.d.ts +123 -0
  129. package/lib/modules/Holder/types.js +17 -0
  130. package/lib/modules/Holder/utils.d.ts +13 -0
  131. package/lib/modules/Holder/utils.js +71 -0
  132. package/lib/modules/OpenData/index.d.ts +0 -2
  133. package/lib/modules/OpenData/index.js +1 -6
  134. package/lib/modules/Order/index.d.ts +11 -28
  135. package/lib/modules/Order/index.js +86 -196
  136. package/lib/modules/Order/types.d.ts +10 -33
  137. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  138. package/lib/modules/Order/utils.d.ts +10 -0
  139. package/lib/modules/Order/utils.js +40 -16
  140. package/lib/modules/Payment/index.d.ts +0 -2
  141. package/lib/modules/Payment/index.js +13 -34
  142. package/lib/modules/Payment/types.d.ts +28 -99
  143. package/lib/modules/Payment/types.js +3 -4
  144. package/lib/modules/Payment/walletpass.d.ts +1 -25
  145. package/lib/modules/Payment/walletpass.js +21 -470
  146. package/lib/modules/Product/types.d.ts +1 -0
  147. package/lib/modules/ProductList/index.js +40 -31
  148. package/lib/modules/Quotation/index.d.ts +1 -1
  149. package/lib/modules/Quotation/index.js +2 -2
  150. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  151. package/lib/modules/ResourcePlanner/index.js +148 -0
  152. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  153. package/lib/modules/ResourcePlanner/planner.js +933 -0
  154. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  155. package/lib/modules/ResourcePlanner/types.js +17 -0
  156. package/lib/modules/Rules/index.d.ts +0 -1
  157. package/lib/modules/Rules/index.js +40 -47
  158. package/lib/modules/SalesSummary/index.js +6 -7
  159. package/lib/modules/ScanOrderLogger/index.d.ts +2 -0
  160. package/lib/modules/ScanOrderLogger/index.js +13 -1
  161. package/lib/modules/ScanOrderLogger/providers/feishu.js +15 -6
  162. package/lib/modules/ScanOrderLogger/types.d.ts +1 -0
  163. package/lib/modules/Schedule/index.d.ts +3 -1
  164. package/lib/modules/Schedule/index.js +10 -8
  165. package/lib/modules/Summary/utils.js +21 -1
  166. package/lib/modules/index.d.ts +2 -0
  167. package/lib/modules/index.js +5 -1
  168. package/lib/plugins/window.d.ts +1 -0
  169. package/lib/server/index.d.ts +14 -16
  170. package/lib/server/index.js +83 -675
  171. package/lib/server/modules/order/index.d.ts +4 -54
  172. package/lib/server/modules/order/index.js +66 -679
  173. package/lib/server/modules/order/types.d.ts +3 -11
  174. package/lib/solution/BaseSales/index.d.ts +20 -109
  175. package/lib/solution/BaseSales/index.js +70 -881
  176. package/lib/solution/BaseSales/types.d.ts +0 -52
  177. package/lib/solution/BaseSales/types.js +1 -2
  178. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  179. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  180. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  181. package/lib/solution/BookingByStep/index.d.ts +17 -2
  182. package/lib/solution/BookingByStep/index.js +60 -18
  183. package/lib/solution/BookingByStep/types.d.ts +2 -1
  184. package/lib/solution/BookingByStep/types.js +5 -0
  185. package/lib/solution/BookingByStep/utils/capacity.js +20 -1
  186. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  187. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  188. package/lib/solution/BookingTicket/index.d.ts +4 -8
  189. package/lib/solution/BookingTicket/index.js +19 -64
  190. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -4
  191. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  192. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +4 -36
  193. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  194. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -2
  195. package/lib/solution/Sales/index.d.ts +0 -1
  196. package/lib/solution/Sales/index.js +3 -5
  197. package/lib/solution/ScanOrder/index.d.ts +26 -14
  198. package/lib/solution/ScanOrder/index.js +449 -190
  199. package/lib/solution/ScanOrder/types.d.ts +21 -1
  200. package/lib/solution/ScanOrder/utils.d.ts +8 -0
  201. package/lib/solution/ScanOrder/utils.js +31 -0
  202. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  203. package/lib/solution/ShopDiscount/index.js +14 -0
  204. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  205. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  206. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  207. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  208. package/lib/solution/VenueBooking/index.d.ts +39 -11
  209. package/lib/solution/VenueBooking/index.js +328 -123
  210. package/lib/solution/VenueBooking/types.d.ts +3 -0
  211. package/lib/solution/VenueBooking/utils/resource.js +1 -0
  212. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  213. package/lib/solution/VenueBooking/utils/slotMerge.js +6 -4
  214. package/lib/solution/index.d.ts +1 -0
  215. package/lib/solution/index.js +3 -1
  216. package/lib/types/index.d.ts +1 -1
  217. package/package.json +1 -1
  218. package/dist/modules/Order/payment-utils.d.ts +0 -26
  219. package/dist/modules/Order/payment-utils.js +0 -225
  220. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +0 -5
  221. package/dist/solution/BookingTicket/utils/weighingProductSku.js +0 -45
  222. package/dist/utils/payment-number.d.ts +0 -9
  223. package/dist/utils/payment-number.js +0 -69
  224. package/lib/modules/Order/payment-utils.d.ts +0 -26
  225. package/lib/modules/Order/payment-utils.js +0 -224
  226. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +0 -5
  227. package/lib/solution/BookingTicket/utils/weighingProductSku.js +0 -63
  228. package/lib/utils/payment-number.d.ts +0 -9
  229. 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,17 +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
- function isItemRewardProductDiscount(discount) {
52
- var _a, _b;
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";
54
- }
55
- var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
50
+ var _ScanOrderImpl = class extends import_BaseSales.BaseSalesImpl {
56
51
  constructor(name, version) {
57
52
  super(name, version);
58
53
  this.defaultName = "scanOrder";
@@ -304,28 +299,22 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
304
299
  }
305
300
  }
306
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
+ }
307
311
  /** 与 `otherParams.cacheId` 一致,供宿主在 URL 变化时判断是否需要重新注册模块 */
308
312
  getCacheId() {
309
313
  return this.cacheId;
310
314
  }
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
- }
324
315
  async initialize(core, options = {}) {
325
- var _a, _b, _c, _d, _e, _f;
316
+ var _a, _b, _c, _d, _e, _f, _g, _h;
326
317
  this.logMethodStart("initialize");
327
- this.core = core;
328
- this.initializeOptions = options || {};
329
318
  this.store = { ...this.store, ...options.store };
330
319
  this.store.entryContext = ((_a = options.otherParams) == null ? void 0 : _a.entryContext) || this.store.entryContext;
331
320
  this.store.status = "initializing";
@@ -341,71 +330,26 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
341
330
  passed: null,
342
331
  failures: []
343
332
  };
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) || {
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) || {
370
340
  feishu: {
371
341
  webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/216b3fe6-af98-424e-8706-f0471241a7ed",
372
342
  errorHook: "https://open.feishu.cn/open-apis/bot/v2/hook/015b7c2a-dd3c-4c30-9898-ef0f5253111f"
373
343
  }
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) {
344
+ }
345
+ );
394
346
  this.store.scanOrderLogger.setContext(this.getScanOrderLoggerContext());
395
347
  }
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
- });
404
348
  this.registerCustomerLoginListeners();
405
349
  console.log("[ScanOrder] 初始化开始");
406
350
  try {
407
- await ((_e = this.store.order) == null ? void 0 : _e.recalculateSummary({ createIfMissing: false }));
408
- (_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();
409
353
  await this.loadRuntimeConfigs();
410
354
  if (this.store.schedule) {
411
355
  try {
@@ -437,7 +381,6 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
437
381
  this.logMethodStart("destroy");
438
382
  this.clearLoginEffectListeners();
439
383
  await this.core.effects.emit(import_types.ScanOrderHooks.onDestroy, {});
440
- await this.destroyRegisteredChildModules();
441
384
  super.destroy();
442
385
  console.log("[ScanOrder] 已销毁");
443
386
  this.logMethodSuccess("destroy");
@@ -537,18 +480,27 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
537
480
  });
538
481
  return result;
539
482
  }
540
- updateTempOrderNote(note) {
483
+ updateTempOrderNote(note, sync = false) {
541
484
  this.logMethodStart("updateTempOrderNote", {
542
485
  noteLength: String(note || "").length
543
486
  });
544
487
  try {
545
488
  if (!this.store.order)
546
489
  throw new Error("order 模块未初始化");
547
- 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;
548
500
  this.logMethodSuccess("updateTempOrderNote", {
549
- noteLength: result.length
501
+ noteLength: nextNote.length
550
502
  });
551
- return result;
503
+ return nextNote;
552
504
  } catch (error) {
553
505
  this.logMethodError("updateTempOrderNote", error);
554
506
  throw error;
@@ -557,6 +509,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
557
509
  // 存储 UI 层选择的取餐方式到 tempOrder.metadata.shop_service_data
558
510
  // service_type 在扫码点餐场景固定为 dine_in
559
511
  setPickupReferenceMode(mode) {
512
+ var _a;
560
513
  this.logMethodStart("setPickupReferenceMode", { mode });
561
514
  try {
562
515
  if (!this.store.order)
@@ -566,7 +519,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
566
519
  ...tempOrder.metadata || {},
567
520
  shop_service_data: {
568
521
  ...(tempOrder.metadata || {}).shop_service_data || {},
569
- service_type: "dine_in",
522
+ service_type: ((_a = this.otherParams) == null ? void 0 : _a.businessCode) === "dine_in" ? "dine_in" : "",
570
523
  pickup_reference_mode: mode
571
524
  }
572
525
  };
@@ -598,7 +551,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
598
551
  throw error;
599
552
  }
600
553
  }
601
- ensureTempOrder() {
554
+ ensureScanOrderTempOrder() {
602
555
  if (!this.store.order)
603
556
  throw new Error("order 模块未初始化");
604
557
  return this.store.order.ensureTempOrder();
@@ -746,10 +699,6 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
746
699
  for (const product of tempOrder.products) {
747
700
  if ((_c = product._origin) == null ? void 0 : _c.isManualDiscount)
748
701
  continue;
749
- if ((product.discount_list || []).some(isItemRewardProductDiscount)) {
750
- product.discount_list = (product.discount_list || []).filter(isItemRewardProductDiscount);
751
- continue;
752
- }
753
702
  product.discount_list = (product.discount_list || []).filter((pd) => {
754
703
  var _a2;
755
704
  const rid = ((_a2 = pd.discount) == null ? void 0 : _a2.resource_id) ?? pd.id;
@@ -823,6 +772,49 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
823
772
  combined_resource: isCombined ? combined : null
824
773
  };
825
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
+ }
826
818
  // ScanOrder 提交 payload enhancer:
827
819
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
828
820
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
@@ -832,23 +824,33 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
832
824
  const ruleProduct = this.enabledReservationRuleProducts[0];
833
825
  const resourceState = this.store.resource;
834
826
  const resourceSelectType = resourceState == null ? void 0 : resourceState.resourceSelectType;
835
- const resolveResourceCapacity = () => {
827
+ const resolveBookingCapacityValue = () => {
836
828
  var _a;
837
829
  if (resourceSelectType === "single") {
838
830
  const raw = (_a = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _a.capacity;
839
831
  const num = Number(raw);
840
832
  if (Number.isFinite(num) && num > 0)
841
- return num;
833
+ return Math.max(1, Math.floor(num));
842
834
  return 1;
843
835
  }
844
836
  return 1;
845
837
  };
846
838
  return (payload, { bookingUuid, tempOrder }) => {
847
839
  var _a, _b;
848
- 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
+ }
849
851
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
850
- const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
851
- const resourceCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
852
+ const hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
853
+ const bookingCapacityValue = resolveBookingCapacityValue();
852
854
  const pickOriginal = (value) => {
853
855
  if (value && typeof value === "object" && !Array.isArray(value)) {
854
856
  const original = value.original;
@@ -864,35 +866,42 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
864
866
  main_field: mainField,
865
867
  form_id: resourceState.tableFormId,
866
868
  relation_id: resourceState.relationId ?? resourceId,
867
- capacity: resourceCapacityValue,
869
+ capacity: bookingCapacityValue,
868
870
  metadata: this.buildScanOrderResourceMetadata({
869
871
  resourceState,
870
872
  resourceName: mainField
871
873
  })
872
874
  } : void 0;
873
875
  const ruleProductUid = ruleProduct ? (0, import_utils2.createUuidV4)() : void 0;
874
- const bookingCapacityValue = resourceCapacityValue;
875
876
  const bookingCapacityDimensionId = (0, import_utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
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
- }));
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
+ });
896
905
  const nextProducts = [...payload.products || []];
897
906
  if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
898
907
  const sellingPrice = String(ruleProduct.price ?? "0.00");
@@ -921,8 +930,58 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
921
930
  return { ...payload, bookings: nextBookings, products: nextProducts };
922
931
  };
923
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
+ }
924
983
  async submitScanOrder() {
925
- var _a, _b, _c, _d, _e, _f, _g;
984
+ var _a, _b, _c;
926
985
  this.logMethodStart("submitScanOrder");
927
986
  try {
928
987
  await this.validateBeforeSubmitByItemRule();
@@ -942,17 +1001,15 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
942
1001
  }
943
1002
  this.store.order.persistTempOrder();
944
1003
  const enhancePayload = this.buildSubmitPayloadEnhancer();
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,
1004
+ const result = this.isScanOrderMoreMode(tempOrderForSubmit) ? await this.submitScanOrderMore({
1005
+ tempOrder: tempOrderForSubmit,
1006
+ enhancePayload
1007
+ }) : await this.submitSalesOrder({
951
1008
  enhancePayload
952
1009
  });
953
1010
  const tempOrder = this.store.order.getTempOrder();
954
1011
  this.logMethodSuccess("submitScanOrder", {
955
- 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
956
1013
  });
957
1014
  return result;
958
1015
  } catch (error) {
@@ -1193,7 +1250,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1193
1250
  return [];
1194
1251
  }
1195
1252
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1196
- tempOrder: this.ensureTempOrder(),
1253
+ tempOrder: this.ensureScanOrderTempOrder(),
1197
1254
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1198
1255
  itemRuleConfigs: this.itemRuleConfigs
1199
1256
  });
@@ -1219,7 +1276,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1219
1276
  if (!strategyConfigs.length)
1220
1277
  return;
1221
1278
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1222
- tempOrder: this.ensureTempOrder(),
1279
+ tempOrder: this.ensureScanOrderTempOrder(),
1223
1280
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1224
1281
  itemRuleConfigs: this.itemRuleConfigs
1225
1282
  });
@@ -1229,7 +1286,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1229
1286
  return;
1230
1287
  }
1231
1288
  const productSourceMap = await this.buildPrefillProductSourceMap();
1232
- const tempOrder = this.ensureTempOrder();
1289
+ const tempOrder = this.ensureScanOrderTempOrder();
1233
1290
  let hasChanges = false;
1234
1291
  for (const prefillItem of prefillItems) {
1235
1292
  const productId = Number(prefillItem.product_id);
@@ -1329,7 +1386,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1329
1386
  };
1330
1387
  }
1331
1388
  const businessData = (0, import_utils.buildItemRuleBusinessData)({
1332
- tempOrder: this.ensureTempOrder(),
1389
+ tempOrder: this.ensureScanOrderTempOrder(),
1333
1390
  runtimeConfig: this.getItemRuleRuntimeConfig(),
1334
1391
  itemRuleConfigs: this.itemRuleConfigs
1335
1392
  });
@@ -1479,8 +1536,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1479
1536
  const matched = resources.find((r) => Number(r == null ? void 0 : r.id) === numericFormId);
1480
1537
  return matched == null ? void 0 : matched.type;
1481
1538
  }
1482
- async fetchResourceOccupyDetailByResourceId(resourceId) {
1483
- var _a, _b, _c, _d;
1539
+ async fetchResourceOccupyDetailsByResourceId(resourceId) {
1540
+ var _a, _b, _c;
1484
1541
  const formRecordId = Number(resourceId);
1485
1542
  if (!Number.isFinite(formRecordId) || formRecordId <= 0) {
1486
1543
  throw new Error(`[ScanOrder] 非法桌台 resourceId: ${resourceId}`);
@@ -1502,15 +1559,60 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1502
1559
  if (!(response == null ? void 0 : response.status)) {
1503
1560
  throw new Error((response == null ? void 0 : response.message) || "获取资源占用详情失败");
1504
1561
  }
1505
- 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
+ };
1506
1607
  }
1507
1608
  // 检测当前链接是否可用
1508
1609
  // 通过 resource_id + 店铺配置
1509
1610
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1510
- async checkResourceAvailable(resourceId, hasOrderId) {
1511
- 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();
1512
1614
  this.logMethodStart("checkResourceAvailable", {
1513
- resourceId
1615
+ resourceId: normalizedResourceId
1514
1616
  });
1515
1617
  try {
1516
1618
  const businessCode = String(((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? "").trim();
@@ -1560,37 +1662,71 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1560
1662
  if (outsideOperatingHours && closedBehaviorValue !== "show_menu_disabled") {
1561
1663
  return makeShopClosed(closedMessage, closedBehaviorValue);
1562
1664
  }
1563
- const tempOrder = this.ensureTempOrder();
1665
+ const tempOrder = this.ensureScanOrderTempOrder();
1564
1666
  const reservationLinkIds = (0, import_utils.collectLinkProductIdsFromReservationRules)(
1565
1667
  dineInConfig["fulfillment.enabled_resource_rules"]
1566
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
+ }
1567
1677
  let pendingRequestEntryPax;
1568
1678
  let pendingRequestPaxMin;
1569
1679
  let pendingRequestPaxMax;
1570
- if (reservationLinkIds.length === 0) {
1571
- this.enabledReservationRuleProducts = [];
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
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
1578
1707
  );
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,
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,
1594
1730
  cacheId: this.cacheId
1595
1731
  });
1596
1732
  if (Array.isArray(loaded)) {
@@ -1609,8 +1745,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1609
1745
  }
1610
1746
  } else {
1611
1747
  this.enabledReservationRuleProducts = [];
1612
- const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1613
- this.logMethodError("loadReservationRuleProducts", error, {
1748
+ const error2 = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1749
+ this.logMethodError("loadReservationRuleProducts", error2, {
1614
1750
  resourceId,
1615
1751
  reservationLinkIds,
1616
1752
  scheduleDate,
@@ -1619,15 +1755,54 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1619
1755
  });
1620
1756
  }
1621
1757
  }
1622
- const occupyDetail = await this.fetchResourceOccupyDetailByResourceId(resourceId);
1758
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1759
+ const occupyDetail = occupyDetails[0] ?? null;
1623
1760
  const resourceSelectType = this.resolveResourceSelectType(
1624
1761
  (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1625
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
+ }
1626
1790
  const resourceState = this.normalizeResourceState(
1627
1791
  occupyDetail,
1628
1792
  resourceSelectType,
1629
1793
  hasOrderId
1630
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
+ }
1631
1806
  this.store.resource = resourceState;
1632
1807
  if (pendingRequestEntryPax !== void 0) {
1633
1808
  this.store.resource.requestEntryPax = pendingRequestEntryPax;
@@ -1645,36 +1820,22 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1645
1820
  table_form_id: resourceState.tableFormId,
1646
1821
  deskmate_valid: resourceState.deskmate_valid,
1647
1822
  table_form_record: resourceState.table_form_record,
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,
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,
1650
1825
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1651
1826
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1652
1827
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1653
1828
  };
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;
1657
1829
  (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1658
1830
  if (availabilityInfo.mode === "idle") {
1659
1831
  await this.addNewOrder();
1660
1832
  }
1661
- if (availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code") {
1662
- tempOrder.order_id = resourceState.lastOrderId;
1833
+ const isAdditionalOrderMode = availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code";
1834
+ if (isAdditionalOrderMode) {
1835
+ tempOrder.order_id = additionalOrderId;
1663
1836
  }
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
- }
1675
- }
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) => {
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) => {
1678
1839
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1679
1840
  return acc;
1680
1841
  acc.push({
@@ -1685,8 +1846,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1685
1846
  return acc;
1686
1847
  }, []) : [];
1687
1848
  await this.setItemRuleRuntimeConfig({
1688
- serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1689
- submissionIndex: hasOrderId ? 1 : 0,
1849
+ serviceType: (_k = this.otherParams) == null ? void 0 : _k.businessCode,
1850
+ submissionIndex: isAdditionalOrderMode ? 1 : 0,
1690
1851
  historicalItems
1691
1852
  });
1692
1853
  if (outsideOperatingHours && closedBehaviorValue === "show_menu_disabled") {
@@ -1695,13 +1856,13 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1695
1856
  availabilityInfo.closed_behavior = closedBehaviorValue;
1696
1857
  }
1697
1858
  this.logMethodSuccess("checkResourceAvailable", {
1698
- resourceId,
1859
+ resourceId: normalizedResourceId,
1699
1860
  mode: availabilityInfo.mode,
1700
1861
  orderId: availabilityInfo.order_id,
1701
1862
  relationId: availabilityInfo.relation_id,
1702
1863
  tableFormId: availabilityInfo.table_form_id,
1703
- persistedRelationId: tempOrder.relation_id,
1704
- 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,
1705
1866
  deskmateValid: availabilityInfo.deskmate_valid,
1706
1867
  resourceSelectType: resourceState.resourceSelectType,
1707
1868
  isExclusive: resourceState.isExclusive,
@@ -1710,11 +1871,29 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1710
1871
  return availabilityInfo;
1711
1872
  } catch (error) {
1712
1873
  this.logMethodError("checkResourceAvailable", error.message, {
1713
- resourceId
1874
+ resourceId: normalizedResourceId
1714
1875
  });
1715
1876
  throw error;
1716
1877
  }
1717
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
+ }
1718
1897
  // 如果是加单的情况,提供返回当前订单相关信息的能力
1719
1898
  async getAdditionalOrderInfo() {
1720
1899
  this.logMethodStart("getAdditionalOrderInfo");
@@ -1735,7 +1914,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1735
1914
  async getProductList() {
1736
1915
  var _a, _b;
1737
1916
  this.logMethodStart("getProductList");
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))) || [];
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)) || [];
1739
1919
  try {
1740
1920
  if (!this.store.products)
1741
1921
  throw new Error("products 模块未初始化");
@@ -1859,6 +2039,85 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1859
2039
  getEntryPaxNumber() {
1860
2040
  return this.store.entryPaxNumber;
1861
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
+ }
1862
2121
  // 读取取餐/送餐开关
1863
2122
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
1864
2123
  getFulfillmentModes() {