@pisell/pisellos 2.1.153 → 2.1.155

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.
@@ -629,23 +629,55 @@ export function collectLinkProductIdsFromReservationRules(rules) {
629
629
  }
630
630
 
631
631
  /**
632
- * 返回列表中第一个带有效 duration.value(分钟)的商品时长。
632
+ * 找到第一个归属指定桌台的预约规则商品。
633
+ * 归属判断基于商品资源中的 default_resource / optional_resource。
633
634
  */
634
- export function pickFirstDurationMinutesFromProducts(products) {
635
+ export function findReservationRuleProductByResourceId(products, resourceId) {
636
+ var numericResourceId = Number(resourceId);
637
+ if (!Number.isFinite(numericResourceId) || numericResourceId <= 0) return undefined;
635
638
  var _iterator7 = _createForOfIteratorHelper(products),
636
639
  _step7;
637
640
  try {
638
641
  for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
639
- var _product$duration;
642
+ var _product$product_reso;
640
643
  var product = _step7.value;
644
+ var resources = product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.resources;
645
+ if (!Array.isArray(resources)) continue;
646
+ var hasMatchedResource = resources.some(function (resource) {
647
+ var defaultResources = Array.isArray(resource === null || resource === void 0 ? void 0 : resource.default_resource) ? resource.default_resource : [];
648
+ var optionalResources = Array.isArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource) ? resource.optional_resource : [];
649
+ return [].concat(_toConsumableArray(defaultResources), _toConsumableArray(optionalResources)).some(function (id) {
650
+ return Number(id) === numericResourceId;
651
+ });
652
+ });
653
+ if (hasMatchedResource) return product;
654
+ }
655
+ } catch (err) {
656
+ _iterator7.e(err);
657
+ } finally {
658
+ _iterator7.f();
659
+ }
660
+ return undefined;
661
+ }
662
+
663
+ /**
664
+ * 返回列表中第一个带有效 duration.value(分钟)的商品时长。
665
+ */
666
+ export function pickFirstDurationMinutesFromProducts(products) {
667
+ var _iterator8 = _createForOfIteratorHelper(products),
668
+ _step8;
669
+ try {
670
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
671
+ var _product$duration;
672
+ var product = _step8.value;
641
673
  var value = product === null || product === void 0 || (_product$duration = product.duration) === null || _product$duration === void 0 ? void 0 : _product$duration.value;
642
674
  var n = Number(value);
643
675
  if (Number.isFinite(n) && n > 0) return Math.floor(n);
644
676
  }
645
677
  } catch (err) {
646
- _iterator7.e(err);
678
+ _iterator8.e(err);
647
679
  } finally {
648
- _iterator7.f();
680
+ _iterator8.f();
649
681
  }
650
682
  return undefined;
651
683
  }
@@ -675,11 +707,11 @@ export function computeResourceIsFull(params) {
675
707
  if (!Number.isFinite(totalCapacity) || totalCapacity <= 0) return false;
676
708
  var now = dayjs();
677
709
  var occupied = 0;
678
- var _iterator8 = _createForOfIteratorHelper(capacityList || []),
679
- _step8;
710
+ var _iterator9 = _createForOfIteratorHelper(capacityList || []),
711
+ _step9;
680
712
  try {
681
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
682
- var slot = _step8.value;
713
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
714
+ var slot = _step9.value;
683
715
  var start = dayjs(slot === null || slot === void 0 ? void 0 : slot.start_at);
684
716
  var end = dayjs(slot === null || slot === void 0 ? void 0 : slot.end_at);
685
717
  if (!start.isValid() || !end.isValid()) continue;
@@ -689,9 +721,9 @@ export function computeResourceIsFull(params) {
689
721
  }
690
722
  }
691
723
  } catch (err) {
692
- _iterator8.e(err);
724
+ _iterator9.e(err);
693
725
  } finally {
694
- _iterator8.f();
726
+ _iterator9.f();
695
727
  }
696
728
  return occupied >= totalCapacity;
697
729
  }
@@ -701,11 +733,11 @@ export function computeResourceIsFull(params) {
701
733
  * 仅返回有限数字字段;若均无法解析则返回 `undefined`。
702
734
  */
703
735
  export function pickFirstCustomCapacityPaxBounds(products) {
704
- var _iterator9 = _createForOfIteratorHelper(products),
705
- _step9;
736
+ var _iterator10 = _createForOfIteratorHelper(products),
737
+ _step10;
706
738
  try {
707
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
708
- var p = _step9.value;
739
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
740
+ var p = _step10.value;
709
741
  var cap = p === null || p === void 0 ? void 0 : p.capacity;
710
742
  if (!cap || cap.type !== 'custom') continue;
711
743
  if (!Array.isArray(cap.custom) || cap.custom.length === 0) continue;
@@ -724,9 +756,9 @@ export function pickFirstCustomCapacityPaxBounds(products) {
724
756
  if (out.min !== undefined || out.max !== undefined) return out;
725
757
  }
726
758
  } catch (err) {
727
- _iterator9.e(err);
759
+ _iterator10.e(err);
728
760
  } finally {
729
- _iterator9.f();
761
+ _iterator10.f();
730
762
  }
731
763
  return undefined;
732
764
  }
@@ -736,11 +768,11 @@ export function pickFirstCustomCapacityPaxBounds(products) {
736
768
  * 无匹配时返回 `undefined`,调用方应回退为 `0`。
737
769
  */
738
770
  export function pickFirstCustomCapacityDimensionId(products) {
739
- var _iterator10 = _createForOfIteratorHelper(products),
740
- _step10;
771
+ var _iterator11 = _createForOfIteratorHelper(products),
772
+ _step11;
741
773
  try {
742
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
743
- var p = _step10.value;
774
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
775
+ var p = _step11.value;
744
776
  var cap = p === null || p === void 0 ? void 0 : p.capacity;
745
777
  if (!cap || cap.type !== 'custom') continue;
746
778
  if (!Array.isArray(cap.custom) || cap.custom.length === 0) continue;
@@ -756,9 +788,9 @@ export function pickFirstCustomCapacityDimensionId(products) {
756
788
  }
757
789
  }
758
790
  } catch (err) {
759
- _iterator10.e(err);
791
+ _iterator11.e(err);
760
792
  } finally {
761
- _iterator10.f();
793
+ _iterator11.f();
762
794
  }
763
795
  return undefined;
764
796
  }
@@ -193,6 +193,7 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
193
193
  setUIState(key: string, value: any): void;
194
194
  getUIState<T = any>(key: string): T | undefined;
195
195
  deleteUIState(key: string): void;
196
+ setBookingHolder(bookingUid: string, holder: any): void;
196
197
  checkOpenDataAvailability(): Promise<OpenDataAvailabilityResult>;
197
198
  setOtherParams(params: Record<string, any>, { cover }?: {
198
199
  cover?: boolean;
@@ -3394,6 +3394,19 @@ export var VenueBookingImpl = /*#__PURE__*/function (_BaseModule) {
3394
3394
  this.writeUIStateBucket(bucket);
3395
3395
  }
3396
3396
  }
3397
+ }, {
3398
+ key: "setBookingHolder",
3399
+ value: function setBookingHolder(bookingUid, holder) {
3400
+ var _order$bookings;
3401
+ var order = this.getTempOrder();
3402
+ var booking = order === null || order === void 0 || (_order$bookings = order.bookings) === null || _order$bookings === void 0 ? void 0 : _order$bookings.find(function (b) {
3403
+ var _b$metadata4;
3404
+ return ((_b$metadata4 = b.metadata) === null || _b$metadata4 === void 0 ? void 0 : _b$metadata4.unique_identification_number) === bookingUid;
3405
+ });
3406
+ if (booking) {
3407
+ booking.holder = holder;
3408
+ }
3409
+ }
3397
3410
 
3398
3411
  // ─── OpenData 可用性 ───
3399
3412
  }, {
@@ -1,49 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/model/strategy/adapter/promotion/index.ts
30
- var promotion_exports = {};
31
- __export(promotion_exports, {
32
- BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
- PromotionAdapter: () => import_adapter.PromotionAdapter,
34
- PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
- X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
- default: () => import_adapter2.default
37
- });
38
- module.exports = __toCommonJS(promotion_exports);
39
- var import_evaluator = require("./evaluator");
40
- var import_adapter = require("./adapter");
41
- var import_adapter2 = __toESM(require("./adapter"));
42
- var import_examples = require("./examples");
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- BUY_X_GET_Y_FREE_STRATEGY,
46
- PromotionAdapter,
47
- PromotionEvaluator,
48
- X_ITEMS_FOR_Y_PRICE_STRATEGY
49
- });
@@ -1,6 +1,6 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
- import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderScanCodeResult, ScanOrderTempOrder } from './types';
3
+ import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderAllowAddItemsInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderReservationResourceSelectInfo, ScanOrderScanCodeResult, ScanOrderSyncAdditionalOrderResult, ScanOrderTempOrder } from './types';
4
4
  import type { UpdateProductInOrderParams } from '../../modules/Order/types';
5
5
  import type { Discount } from '../../modules/Discount/types';
6
6
  import { type CartItemSummary, type PaxInfo, type QuantityCheckResult, type QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
@@ -118,7 +118,8 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
118
118
  setItemRuleRuntimeConfig(config?: ScanOrderItemRuleRuntimeConfig): Promise<void>;
119
119
  private normalizeResourceState;
120
120
  private resolveResourceSelectType;
121
- private fetchResourceOccupyDetailByResourceId;
121
+ private fetchResourceOccupyDetailsByResourceId;
122
+ private resolveAdditionalOrderFromOccupyDetail;
122
123
  checkResourceAvailable(resourceId?: string | null, hasOrderId?: boolean): Promise<ScanOrderAvailabilityInfo>;
123
124
  getAdditionalOrderInfo(): Promise<{
124
125
  orderId: string;
@@ -142,6 +143,9 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
142
143
  clearUIState(): void;
143
144
  setEntryPaxNumber(number: number): Promise<void>;
144
145
  getEntryPaxNumber(): number | null;
146
+ syncAdditionalOrderFromResource(resourceId?: string | null): Promise<ScanOrderSyncAdditionalOrderResult>;
147
+ getReservationResourceSelectType(): ScanOrderReservationResourceSelectInfo;
148
+ checkAllowAddItems(): ScanOrderAllowAddItemsInfo;
145
149
  getFulfillmentModes(): {
146
150
  enablePickup: boolean;
147
151
  enableTableService: boolean;
@@ -867,13 +867,13 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
867
867
  const ruleProduct = this.enabledReservationRuleProducts[0];
868
868
  const resourceState = this.store.resource;
869
869
  const resourceSelectType = resourceState == null ? void 0 : resourceState.resourceSelectType;
870
- const resolveResourceCapacity = () => {
870
+ const resolveBookingCapacityValue = () => {
871
871
  var _a;
872
872
  if (resourceSelectType === "single") {
873
873
  const raw = (_a = resourceState == null ? void 0 : resourceState.table_form_record) == null ? void 0 : _a.capacity;
874
874
  const num = Number(raw);
875
875
  if (Number.isFinite(num) && num > 0)
876
- return num;
876
+ return Math.max(1, Math.floor(num));
877
877
  return 1;
878
878
  }
879
879
  return 1;
@@ -892,8 +892,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
892
892
  };
893
893
  }
894
894
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
895
- const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
896
- const resourceCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
895
+ const hasExplicitCollectPax = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
896
+ const bookingCapacityValue = resolveBookingCapacityValue();
897
897
  const pickOriginal = (value) => {
898
898
  if (value && typeof value === "object" && !Array.isArray(value)) {
899
899
  const original = value.original;
@@ -909,35 +909,42 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
909
909
  main_field: mainField,
910
910
  form_id: resourceState.tableFormId,
911
911
  relation_id: resourceState.relationId ?? resourceId,
912
- capacity: resourceCapacityValue,
912
+ capacity: bookingCapacityValue,
913
913
  metadata: this.buildScanOrderResourceMetadata({
914
914
  resourceState,
915
915
  resourceName: mainField
916
916
  })
917
917
  } : void 0;
918
918
  const ruleProductUid = ruleProduct ? (0, import_utils2.createUuidV4)() : void 0;
919
- const bookingCapacityValue = resourceCapacityValue;
920
919
  const bookingCapacityDimensionId = (0, import_utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
921
- const nextBookings = (payload.bookings || []).map((booking, idx) => ({
922
- ...booking,
923
- number: bookingCapacityValue,
924
- appointment_status: "started",
925
- metadata: {
926
- ...booking.metadata || {},
927
- ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
928
- ...resourceSelectType ? {
929
- capacity: [
930
- {
931
- id: bookingCapacityDimensionId,
932
- value: bookingCapacityValue,
933
- name: ""
934
- }
935
- ]
936
- } : {}
937
- },
938
- ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
939
- ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
940
- }));
920
+ const nextBookings = (payload.bookings || []).map((booking, idx) => {
921
+ const metadata = { ...booking.metadata || {} };
922
+ if (hasExplicitCollectPax) {
923
+ metadata.collect_pax = (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax);
924
+ } else {
925
+ delete metadata.collect_pax;
926
+ }
927
+ return {
928
+ ...booking,
929
+ number: bookingCapacityValue,
930
+ appointment_status: "started",
931
+ metadata: {
932
+ ...metadata,
933
+ ...resourceSelectType ? { resource_select_type: resourceSelectType } : {},
934
+ ...resourceSelectType ? {
935
+ capacity: [
936
+ {
937
+ id: bookingCapacityDimensionId,
938
+ value: bookingCapacityValue,
939
+ name: ""
940
+ }
941
+ ]
942
+ } : {}
943
+ },
944
+ ...idx === 0 && resourceEntry ? { resources: [resourceEntry] } : {},
945
+ ...idx === 0 && ruleProductUid ? { product_uid: ruleProductUid } : {}
946
+ };
947
+ });
941
948
  const nextProducts = [...payload.products || []];
942
949
  if (ruleProduct && ruleProductUid && !tempOrder.order_id) {
943
950
  const sellingPrice = String(ruleProduct.price ?? "0.00");
@@ -974,10 +981,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
974
981
  if (!this.store.order) {
975
982
  throw new Error("scanOrder解决方案需要 order 模块支持");
976
983
  }
977
- const pax = (0, import_utils2.normalizeSubmitCollectPaxValue)(this.store.entryPaxNumber);
978
- this.store.entryPaxNumber = pax;
979
984
  const tempOrderForSubmit = this.store.order.ensureTempOrder();
980
- tempOrderForSubmit.metadata = { ...tempOrderForSubmit.metadata, collect_pax: pax };
981
985
  tempOrderForSubmit.delivery_type = "shop_service";
982
986
  const resourceTableName = (_b = (_a = this.store.resource) == null ? void 0 : _a.table_form_record) == null ? void 0 : _b.name;
983
987
  if (resourceTableName && typeof resourceTableName === "object") {
@@ -1524,8 +1528,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1524
1528
  const matched = resources.find((r) => Number(r == null ? void 0 : r.id) === numericFormId);
1525
1529
  return matched == null ? void 0 : matched.type;
1526
1530
  }
1527
- async fetchResourceOccupyDetailByResourceId(resourceId) {
1528
- var _a, _b, _c, _d;
1531
+ async fetchResourceOccupyDetailsByResourceId(resourceId) {
1532
+ var _a, _b, _c;
1529
1533
  const formRecordId = Number(resourceId);
1530
1534
  if (!Number.isFinite(formRecordId) || formRecordId <= 0) {
1531
1535
  throw new Error(`[ScanOrder] 非法桌台 resourceId: ${resourceId}`);
@@ -1547,13 +1551,57 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1547
1551
  if (!(response == null ? void 0 : response.status)) {
1548
1552
  throw new Error((response == null ? void 0 : response.message) || "获取资源占用详情失败");
1549
1553
  }
1550
- return ((_d = (_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) == null ? void 0 : _d[0]) ?? null;
1554
+ return ((_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) ?? [];
1555
+ }
1556
+ resolveAdditionalOrderFromOccupyDetail(detail, resourceSelectType, allowAddItems) {
1557
+ const currentOrderId = (0, import_utils.toPositiveString)(detail == null ? void 0 : detail.order_id);
1558
+ if (currentOrderId) {
1559
+ return {
1560
+ matched: true,
1561
+ order_id: currentOrderId
1562
+ };
1563
+ }
1564
+ 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);
1565
+ if (resourceSelectType !== "single") {
1566
+ return {
1567
+ matched: false,
1568
+ reason: "no_order"
1569
+ };
1570
+ }
1571
+ if (!orderListIds.length) {
1572
+ return {
1573
+ matched: false,
1574
+ reason: "no_order"
1575
+ };
1576
+ }
1577
+ if (!allowAddItems) {
1578
+ return {
1579
+ matched: false,
1580
+ reason: "add_items_disabled"
1581
+ };
1582
+ }
1583
+ if (orderListIds.length === 1) {
1584
+ return {
1585
+ matched: true,
1586
+ order_id: orderListIds[0]
1587
+ };
1588
+ }
1589
+ if (orderListIds.length > 1) {
1590
+ return {
1591
+ matched: false,
1592
+ reason: "multiple_orders"
1593
+ };
1594
+ }
1595
+ return {
1596
+ matched: false,
1597
+ reason: "no_order"
1598
+ };
1551
1599
  }
1552
1600
  // 检测当前链接是否可用
1553
1601
  // 通过 resource_id + 店铺配置
1554
1602
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1555
1603
  async checkResourceAvailable(resourceId, hasOrderId = false) {
1556
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1604
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1557
1605
  const normalizedResourceId = String(resourceId ?? "").trim();
1558
1606
  this.logMethodStart("checkResourceAvailable", {
1559
1607
  resourceId: normalizedResourceId
@@ -1645,14 +1693,19 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1645
1693
  cacheId: this.cacheId
1646
1694
  });
1647
1695
  if (Array.isArray(loaded)) {
1648
- this.enabledReservationRuleProducts = loaded;
1649
- const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(loaded);
1696
+ const matchedRuleProduct = (0, import_utils.findReservationRuleProductByResourceId)(
1697
+ loaded,
1698
+ normalizedResourceId
1699
+ );
1700
+ const ruleProductsForResource = matchedRuleProduct ? [matchedRuleProduct] : [];
1701
+ this.enabledReservationRuleProducts = ruleProductsForResource;
1702
+ const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(ruleProductsForResource);
1650
1703
  if (occupancyMinutes !== void 0) {
1651
1704
  tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
1652
1705
  }
1653
- if ((0, import_utils.hasCustomCapacityProduct)(loaded)) {
1706
+ if ((0, import_utils.hasCustomCapacityProduct)(ruleProductsForResource)) {
1654
1707
  pendingRequestEntryPax = 1;
1655
- const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(loaded);
1708
+ const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(ruleProductsForResource);
1656
1709
  if ((paxBounds == null ? void 0 : paxBounds.min) !== void 0)
1657
1710
  pendingRequestPaxMin = paxBounds.min;
1658
1711
  if ((paxBounds == null ? void 0 : paxBounds.max) !== void 0)
@@ -1669,15 +1722,54 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1669
1722
  cacheId: this.cacheId
1670
1723
  });
1671
1724
  }
1672
- const occupyDetail = await this.fetchResourceOccupyDetailByResourceId(normalizedResourceId);
1725
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1726
+ const occupyDetail = occupyDetails[0] ?? null;
1673
1727
  const resourceSelectType = this.resolveResourceSelectType(
1674
1728
  (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1675
1729
  );
1730
+ const allowAddItems = (0, import_utils.toBoolean)(dineInConfig == null ? void 0 : dineInConfig["sale.allow_add_items"]);
1731
+ const additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(
1732
+ occupyDetail,
1733
+ resourceSelectType,
1734
+ allowAddItems
1735
+ );
1736
+ if (additionalOrderResult.reason === "multiple_orders") {
1737
+ const multipleOrdersState = {
1738
+ ...this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId),
1739
+ mode: "multiple_orders"
1740
+ };
1741
+ this.store.resource = multipleOrdersState;
1742
+ const availabilityInfo2 = {
1743
+ mode: "multiple_orders",
1744
+ deskmate_valid: multipleOrdersState.deskmate_valid,
1745
+ relation_id: multipleOrdersState.relationId,
1746
+ table_form_id: multipleOrdersState.tableFormId,
1747
+ table_form_record: multipleOrdersState.table_form_record
1748
+ };
1749
+ this.logMethodSuccess("checkResourceAvailable", {
1750
+ resourceId: normalizedResourceId,
1751
+ mode: availabilityInfo2.mode,
1752
+ orderListCount: ((_e = occupyDetail == null ? void 0 : occupyDetail.order_list) == null ? void 0 : _e.length) || 0,
1753
+ resourceSelectType
1754
+ });
1755
+ return availabilityInfo2;
1756
+ }
1676
1757
  const resourceState = this.normalizeResourceState(
1677
1758
  occupyDetail,
1678
1759
  resourceSelectType,
1679
1760
  hasOrderId
1680
1761
  );
1762
+ const additionalOrderId = additionalOrderResult.order_id;
1763
+ if (additionalOrderId) {
1764
+ resourceState.mode = "additional_order";
1765
+ resourceState.order_id = additionalOrderId;
1766
+ } else if (additionalOrderResult.reason === "add_items_disabled") {
1767
+ resourceState.mode = "resource_busy";
1768
+ resourceState.order_id = "0";
1769
+ } else if (resourceSelectType === "multiple" && resourceState.isFull) {
1770
+ resourceState.mode = "resource_busy";
1771
+ resourceState.order_id = "0";
1772
+ }
1681
1773
  this.store.resource = resourceState;
1682
1774
  if (pendingRequestEntryPax !== void 0) {
1683
1775
  this.store.resource.requestEntryPax = pendingRequestEntryPax;
@@ -1695,34 +1787,35 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1695
1787
  table_form_id: resourceState.tableFormId,
1696
1788
  deskmate_valid: resourceState.deskmate_valid,
1697
1789
  table_form_record: resourceState.table_form_record,
1698
- policy: (_e = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _e.policy,
1699
- partyroom_booking: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.partyroom_booking,
1790
+ policy: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.policy,
1791
+ partyroom_booking: (_g = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _g.partyroom_booking,
1700
1792
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1701
1793
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1702
1794
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1703
1795
  };
1704
- tempOrder.relation_id = normalizedResourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1796
+ tempOrder.relation_id = normalizedResourceId || ((_h = this.otherParams) == null ? void 0 : _h.relation_id);
1705
1797
  tempOrder.table_form_id = resourceState.tableFormId;
1706
1798
  tempOrder.resource_id = normalizedResourceId;
1707
- (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1799
+ (_i = this.store.order) == null ? void 0 : _i.persistTempOrder();
1708
1800
  if (availabilityInfo.mode === "idle") {
1709
1801
  await this.addNewOrder();
1710
1802
  }
1711
- if (availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code") {
1712
- tempOrder.order_id = resourceState.lastOrderId;
1803
+ const isAdditionalOrderMode = availabilityInfo.mode === "additional_order" || availabilityInfo.mode === "additional_order_with_code";
1804
+ if (isAdditionalOrderMode) {
1805
+ tempOrder.order_id = additionalOrderId;
1713
1806
  }
1714
1807
  if (tempOrder.order_id) {
1715
- const res = await ((_i = this.store.order) == null ? void 0 : _i.getOrderInfoByRemote(tempOrder.order_id));
1716
- const entryPaxNumber = (_m = (_l = (_k = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.bookings) == null ? void 0 : _k.find((p) => {
1808
+ const res = await ((_j = this.store.order) == null ? void 0 : _j.getOrderInfoByRemote(tempOrder.order_id));
1809
+ const entryPaxNumber = (_n = (_m = (_l = (_k = res == null ? void 0 : res.data) == null ? void 0 : _k.bookings) == null ? void 0 : _l.find((p) => {
1717
1810
  var _a2;
1718
1811
  return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1719
- })) == null ? void 0 : _l.metadata) == null ? void 0 : _m.collect_pax;
1812
+ })) == null ? void 0 : _m.metadata) == null ? void 0 : _n.collect_pax;
1720
1813
  if (entryPaxNumber) {
1721
1814
  await this.setEntryPaxNumber(entryPaxNumber);
1722
1815
  }
1723
1816
  }
1724
- const lastOrderInfo = (_o = (_n = this.store.order) == null ? void 0 : _n.getLastOrderInfo) == null ? void 0 : _o.call(_n);
1725
- const historicalItems = hasOrderId && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1817
+ const lastOrderInfo = (_p = (_o = this.store.order) == null ? void 0 : _o.getLastOrderInfo) == null ? void 0 : _p.call(_o);
1818
+ const historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1726
1819
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1727
1820
  return acc;
1728
1821
  acc.push({
@@ -1733,8 +1826,8 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1733
1826
  return acc;
1734
1827
  }, []) : [];
1735
1828
  await this.setItemRuleRuntimeConfig({
1736
- serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1737
- submissionIndex: hasOrderId ? 1 : 0,
1829
+ serviceType: (_q = this.otherParams) == null ? void 0 : _q.businessCode,
1830
+ submissionIndex: isAdditionalOrderMode ? 1 : 0,
1738
1831
  historicalItems
1739
1832
  });
1740
1833
  if (outsideOperatingHours && closedBehaviorValue === "show_menu_disabled") {
@@ -1907,6 +2000,83 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1907
2000
  getEntryPaxNumber() {
1908
2001
  return this.store.entryPaxNumber;
1909
2002
  }
2003
+ async syncAdditionalOrderFromResource(resourceId) {
2004
+ var _a, _b, _c, _d, _e, _f;
2005
+ const tempOrder = this.ensureTempOrder();
2006
+ const normalizedResourceId = String(
2007
+ resourceId ?? tempOrder.resource_id ?? ((_a = this.store.resource) == null ? void 0 : _a.relationId) ?? ((_b = this.store.resource) == null ? void 0 : _b.relation_id) ?? ""
2008
+ ).trim();
2009
+ this.logMethodStart("syncAdditionalOrderFromResource", {
2010
+ resourceId: normalizedResourceId
2011
+ });
2012
+ if (!normalizedResourceId) {
2013
+ const result2 = {
2014
+ matched: false,
2015
+ reason: "missing_resource_id"
2016
+ };
2017
+ this.logMethodSuccess("syncAdditionalOrderFromResource", result2);
2018
+ return result2;
2019
+ }
2020
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2021
+ const occupyDetail = occupyDetails[0] ?? null;
2022
+ const resourceSelectType = ((_c = this.store.resource) == null ? void 0 : _c.resourceSelectType) || this.resolveResourceSelectType((0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id));
2023
+ const allowAddItems = (0, import_utils.toBoolean)(
2024
+ (_e = (_d = this.otherParams) == null ? void 0 : _d.dineInConfig) == null ? void 0 : _e["sale.allow_add_items"]
2025
+ );
2026
+ const result = this.resolveAdditionalOrderFromOccupyDetail(
2027
+ occupyDetail,
2028
+ resourceSelectType,
2029
+ allowAddItems
2030
+ );
2031
+ if (!result.matched || !result.order_id) {
2032
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2033
+ ...result,
2034
+ resourceId: normalizedResourceId,
2035
+ resourceSelectType,
2036
+ allowAddItems
2037
+ });
2038
+ return result;
2039
+ }
2040
+ tempOrder.order_id = result.order_id;
2041
+ tempOrder.resource_id = normalizedResourceId;
2042
+ tempOrder.relation_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
2043
+ tempOrder.table_form_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
2044
+ (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
2045
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2046
+ ...result,
2047
+ resourceId: normalizedResourceId,
2048
+ resourceSelectType,
2049
+ allowAddItems
2050
+ });
2051
+ return result;
2052
+ }
2053
+ // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
2054
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
2055
+ getReservationResourceSelectType() {
2056
+ var _a;
2057
+ this.logMethodStart("getReservationResourceSelectType");
2058
+ const resourceSelectType = (_a = this.store.resource) == null ? void 0 : _a.resourceSelectType;
2059
+ const result = {
2060
+ ...resourceSelectType ? { resourceSelectType } : {},
2061
+ isSingleReservation: resourceSelectType === "single",
2062
+ isMultipleReservation: resourceSelectType === "multiple",
2063
+ isCapacityReservation: resourceSelectType === "capacity"
2064
+ };
2065
+ this.logMethodSuccess("getReservationResourceSelectType", result);
2066
+ return result;
2067
+ }
2068
+ // 判定后台是否开启允许加餐
2069
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
2070
+ checkAllowAddItems() {
2071
+ var _a;
2072
+ this.logMethodStart("checkAllowAddItems");
2073
+ const dineInConfig = ((_a = this.otherParams) == null ? void 0 : _a.dineInConfig) || {};
2074
+ const result = {
2075
+ enabled: (0, import_utils.toBoolean)(dineInConfig["sale.allow_add_items"])
2076
+ };
2077
+ this.logMethodSuccess("checkAllowAddItems", result);
2078
+ return result;
2079
+ }
1910
2080
  // 读取取餐/送餐开关
1911
2081
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
1912
2082
  getFulfillmentModes() {