@pisell/pisellos 2.1.129 → 2.1.130

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 (44) hide show
  1. package/dist/modules/Order/index.d.ts +4 -0
  2. package/dist/modules/Order/index.js +18 -1
  3. package/dist/modules/Order/types.d.ts +9 -1
  4. package/dist/modules/Order/utils.d.ts +7 -0
  5. package/dist/modules/Order/utils.js +27 -11
  6. package/dist/solution/ScanOrder/index.d.ts +27 -3
  7. package/dist/solution/ScanOrder/index.js +865 -481
  8. package/dist/solution/ScanOrder/types.d.ts +34 -24
  9. package/dist/solution/ScanOrder/types.js +5 -1
  10. package/dist/solution/ScanOrder/utils.d.ts +13 -1
  11. package/dist/solution/ScanOrder/utils.js +45 -6
  12. package/dist/solution/VenueBooking/index.d.ts +28 -5
  13. package/dist/solution/VenueBooking/index.js +428 -193
  14. package/dist/solution/VenueBooking/types.d.ts +23 -0
  15. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  16. package/dist/solution/VenueBooking/utils/dateSummary.js +1 -1
  17. package/dist/solution/VenueBooking/utils/resource.d.ts +11 -1
  18. package/dist/solution/VenueBooking/utils/resource.js +57 -21
  19. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  20. package/dist/solution/VenueBooking/utils/slotMerge.js +33 -12
  21. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  22. package/dist/solution/VenueBooking/utils/timeSlot.js +259 -62
  23. package/lib/modules/Order/index.d.ts +4 -0
  24. package/lib/modules/Order/index.js +14 -1
  25. package/lib/modules/Order/types.d.ts +9 -1
  26. package/lib/modules/Order/utils.d.ts +7 -0
  27. package/lib/modules/Order/utils.js +22 -12
  28. package/lib/solution/ScanOrder/index.d.ts +27 -3
  29. package/lib/solution/ScanOrder/index.js +409 -114
  30. package/lib/solution/ScanOrder/types.d.ts +34 -24
  31. package/lib/solution/ScanOrder/utils.d.ts +13 -1
  32. package/lib/solution/ScanOrder/utils.js +37 -0
  33. package/lib/solution/VenueBooking/index.d.ts +28 -5
  34. package/lib/solution/VenueBooking/index.js +193 -45
  35. package/lib/solution/VenueBooking/types.d.ts +23 -0
  36. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  37. package/lib/solution/VenueBooking/utils/dateSummary.js +1 -1
  38. package/lib/solution/VenueBooking/utils/resource.d.ts +11 -1
  39. package/lib/solution/VenueBooking/utils/resource.js +15 -4
  40. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  41. package/lib/solution/VenueBooking/utils/slotMerge.js +29 -12
  42. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  43. package/lib/solution/VenueBooking/utils/timeSlot.js +182 -43
  44. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType } from '../../modules';
1
+ import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, ScheduleModule } from '../../modules';
2
2
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
3
  /**
4
4
  * 扫码下单流程 hook
@@ -114,6 +114,9 @@ export interface ScanOrderTempOrder {
114
114
  shop_discount: string;
115
115
  surcharge_fee: string;
116
116
  note: string;
117
+ buzzer?: string;
118
+ delivery_type?: string;
119
+ table_number?: Record<string, any>;
117
120
  schedule_date: string;
118
121
  created_at: string;
119
122
  products: ScanOrderOrderProduct[];
@@ -134,14 +137,15 @@ export interface ScanOrderSubmitPayload extends Omit<ScanOrderTempOrder, 'platfo
134
137
  request_unique_idempotency_token?: string;
135
138
  form_record_ids?: Array<{
136
139
  form_id: number | string;
137
- form_record_ids: Array<number | string>;
140
+ form_record_id: number | string;
138
141
  }>;
139
142
  products: ScanOrderSubmitProduct[];
140
143
  }
141
- export type ScanOrderAvailabilityMode = 'idle' | 'shop_closed' | 'resource_block' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
144
+ export type ScanOrderAvailabilityMode = 'idle' | 'shop_closed' | 'submit_disabled' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
142
145
  export interface ScanOrderTableFormRecord {
143
146
  policy?: string | null;
144
147
  partyroom_booking?: string | null;
148
+ capacity?: number | string | null;
145
149
  [key: string]: any;
146
150
  }
147
151
  export interface ScanOrderAvailabilityInfo {
@@ -151,7 +155,9 @@ export interface ScanOrderAvailabilityInfo {
151
155
  table_form_id?: string;
152
156
  deskmate_valid?: boolean;
153
157
  errorTips?: string;
154
- /** `/order/dining/table/config` 返回的 `table_form_record` 原样透出 */
158
+ /** 透传 `availability.closed_behavior`,便于 UI 识别拦截类型(如 show_menu_disabled) */
159
+ closed_behavior?: string;
160
+ /** `/order/resource/occupy-detail` 返回的 `form_record` 原样透出 */
155
161
  table_form_record?: ScanOrderTableFormRecord | null;
156
162
  policy?: string | null;
157
163
  partyroom_booking?: string | null;
@@ -162,34 +168,36 @@ export interface ScanOrderAvailabilityInfo {
162
168
  /** 首个 `capacity.type === 'custom'` 商品里 `custom[0]` 的 max(人数上限) */
163
169
  requestPaxMax?: number;
164
170
  }
165
- export interface ScanOrderTableSnackConfig {
166
- snack?: boolean | number | string;
167
- table_validate?: boolean | number | string;
171
+ /** `resource_capacity[i].capacity_list[j]` */
172
+ export interface ScanOrderResourceCapacitySlot {
173
+ start_at?: string;
174
+ end_at?: string;
175
+ pax?: number | string;
168
176
  }
169
- export interface ScanOrderOrderNumberPrefixConfig {
170
- table_order?: string;
171
- pos?: string;
177
+ export interface ScanOrderResourceCapacity {
178
+ capacity?: number | string;
179
+ capacity_list?: ScanOrderResourceCapacitySlot[];
172
180
  }
173
- export interface ScanOrderTableConfigApiData {
174
- table_max_number?: number | string | null;
175
- order_count?: number | string | null;
181
+ /** `/order/resource/occupy-detail` 单条 `occupy_details[i]` */
182
+ export interface ScanOrderResourceOccupyDetail {
183
+ form_record_id?: number | string | null;
184
+ form_id?: number | string | null;
176
185
  order_id?: number | string | null;
177
186
  last_order_id?: number | string | null;
178
- relation_id?: number | string | null;
179
- table_form_id?: number | string | null;
180
- table_snack?: ScanOrderTableSnackConfig[] | null;
181
- order_number_prefix?: ScanOrderOrderNumberPrefixConfig[] | null;
187
+ resource_capacity?: ScanOrderResourceCapacity[] | null;
188
+ form_record?: ScanOrderTableFormRecord | null;
182
189
  [key: string]: any;
183
190
  }
184
- export interface ScanOrderTableConfigApiResponse {
191
+ export interface ScanOrderResourceOccupyDetailApiResponse {
185
192
  status?: boolean;
186
193
  code?: number;
187
194
  message?: string;
188
- data?: ScanOrderTableConfigApiData | null;
195
+ data?: {
196
+ occupy_details?: ScanOrderResourceOccupyDetail[] | null;
197
+ } | null;
189
198
  }
199
+ export type ScanOrderResourceSelectType = 'single' | 'multiple' | 'capacity';
190
200
  export interface ScanOrderResourceState extends ScanOrderAvailabilityInfo {
191
- tableMaxNumber: number;
192
- orderCount: number;
193
201
  relationId?: string;
194
202
  tableFormId?: string;
195
203
  currentOrderId?: string;
@@ -198,13 +206,14 @@ export interface ScanOrderResourceState extends ScanOrderAvailabilityInfo {
198
206
  deskmateValid: boolean;
199
207
  isExclusive: boolean;
200
208
  isFull: boolean;
201
- orderNumberPrefix: ScanOrderOrderNumberPrefixConfig[];
202
- raw: ScanOrderTableConfigApiData | null;
209
+ /** 来自首个预约规则商品 product_resource.resources 中与 form_id 匹配的 resource type */
210
+ resourceSelectType?: ScanOrderResourceSelectType;
211
+ raw: ScanOrderResourceOccupyDetail | null;
203
212
  }
204
213
  export interface ScanOrderState {
205
214
  entryContext: ScanOrderEntryContext | null;
206
215
  status: ScanOrderStatus;
207
- config: ScanOrderTableConfigApiData | null;
216
+ config: Record<string, any> | null;
208
217
  resource: ScanOrderResourceState | null;
209
218
  flow: Record<string, any>;
210
219
  error: string | null;
@@ -212,6 +221,7 @@ export interface ScanOrderState {
212
221
  order?: OrderModule;
213
222
  salesSummary?: SalesSummaryModule;
214
223
  scanOrderLogger?: ScanOrderLoggerModule;
224
+ schedule?: ScheduleModule;
215
225
  itemRuleQuantityLimits: QuantityLimitResult[];
216
226
  cartValidation: {
217
227
  passed: boolean | null;
@@ -1,4 +1,4 @@
1
- import { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderSummary, ScanOrderTempOrder } from './types';
1
+ import { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderResourceCapacitySlot, ScanOrderResourceSelectType, ScanOrderSummary, ScanOrderTempOrder } from './types';
2
2
  import type { CartItemSummary, ItemRuleBusinessData, PaxInfo, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
3
  import type { StrategyConfig } from '../../model/strategy/type';
4
4
  import type { ProductData } from '../../modules/Product/types';
@@ -109,6 +109,18 @@ export declare function collectLinkProductIdsFromReservationRules(rules: unknown
109
109
  export declare function pickFirstDurationMinutesFromProducts(products: ProductData[]): number | undefined;
110
110
  /** 是否存在 capacity.type === 'custom' 的商品 */
111
111
  export declare function hasCustomCapacityProduct(products: ProductData[]): boolean;
112
+ /**
113
+ * 根据预约规则商品的 resource.type 计算桌台是否已被"占满"。
114
+ * - single:只要有 `lastOrderId` 即视为占用
115
+ * - multiple:当前时间落在 `capacity_list[i]` 的 `[start_at, end_at]`(inclusive)内的 pax 之和 > 总容量
116
+ * - 其他('capacity' / undefined):返回 false,不施加限制
117
+ */
118
+ export declare function computeResourceIsFull(params: {
119
+ resourceSelectType?: ScanOrderResourceSelectType;
120
+ lastOrderId?: string;
121
+ capacityList?: ScanOrderResourceCapacitySlot[];
122
+ capacity?: number | string | null;
123
+ }): boolean;
112
124
  /**
113
125
  * 在商品列表中找到第一个 `capacity.type === 'custom'` 的商品,取其 `custom` 数组第一项的 min/max。
114
126
  * 仅返回有限数字字段;若均无法解析则返回 `undefined`。
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
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
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/solution/ScanOrder/utils.ts
@@ -25,6 +35,7 @@ __export(utils_exports, {
25
35
  buildProductKey: () => buildProductKey,
26
36
  buildQuantityLimitIndex: () => buildQuantityLimitIndex,
27
37
  collectLinkProductIdsFromReservationRules: () => collectLinkProductIdsFromReservationRules,
38
+ computeResourceIsFull: () => computeResourceIsFull,
28
39
  createEmptySummary: () => createEmptySummary,
29
40
  extractStrategyModelIdsFromTableConfig: () => extractStrategyModelIdsFromTableConfig,
30
41
  getProductIdentityIndex: () => getProductIdentityIndex,
@@ -46,6 +57,7 @@ __export(utils_exports, {
46
57
  toPriceString: () => toPriceString
47
58
  });
48
59
  module.exports = __toCommonJS(utils_exports);
60
+ var import_dayjs = __toESM(require("dayjs"));
49
61
  function createEmptySummary() {
50
62
  return {
51
63
  product_quantity: 0,
@@ -411,6 +423,30 @@ function hasCustomCapacityProduct(products) {
411
423
  return ((_a = p == null ? void 0 : p.capacity) == null ? void 0 : _a.type) === "custom";
412
424
  });
413
425
  }
426
+ function computeResourceIsFull(params) {
427
+ const { resourceSelectType, lastOrderId, capacityList, capacity } = params;
428
+ if (resourceSelectType === "single")
429
+ return Boolean(lastOrderId);
430
+ if (resourceSelectType !== "multiple")
431
+ return false;
432
+ const totalCapacity = Number(capacity);
433
+ if (!Number.isFinite(totalCapacity) || totalCapacity <= 0)
434
+ return false;
435
+ const now = (0, import_dayjs.default)();
436
+ let occupied = 0;
437
+ for (const slot of capacityList || []) {
438
+ const start = (0, import_dayjs.default)(slot == null ? void 0 : slot.start_at);
439
+ const end = (0, import_dayjs.default)(slot == null ? void 0 : slot.end_at);
440
+ if (!start.isValid() || !end.isValid())
441
+ continue;
442
+ if ((now.isAfter(start) || now.isSame(start)) && (now.isBefore(end) || now.isSame(end))) {
443
+ const pax = Number(slot == null ? void 0 : slot.pax);
444
+ if (Number.isFinite(pax) && pax > 0)
445
+ occupied += pax;
446
+ }
447
+ }
448
+ return occupied > totalCapacity;
449
+ }
414
450
  function pickFirstCustomCapacityPaxBounds(products) {
415
451
  for (const p of products) {
416
452
  const cap = p == null ? void 0 : p.capacity;
@@ -446,6 +482,7 @@ function pickFirstCustomCapacityPaxBounds(products) {
446
482
  buildProductKey,
447
483
  buildQuantityLimitIndex,
448
484
  collectLinkProductIdsFromReservationRules,
485
+ computeResourceIsFull,
449
486
  createEmptySummary,
450
487
  extractStrategyModelIdsFromTableConfig,
451
488
  getProductIdentityIndex,
@@ -92,25 +92,48 @@ export declare class VenueBookingImpl extends BaseModule implements Module {
92
92
  /**
93
93
  * 切换单个时段的选中状态(选中/取消)。
94
94
  * 内部自动处理连续时段的合并与拆分,订单是唯一真相源。
95
+ *
96
+ * slot.productId 指定当前操作针对的是该 resourceId 下的哪一个商品。
97
+ * 同一资源下不同 productId 之间互相隔离,不会相互合并。
95
98
  */
96
99
  toggleSlot(slot: VenueSlotSelection): Promise<ScanOrderOrderProduct[]>;
97
100
  /**
98
101
  * 获取某资源当前选中的所有独立时段(从订单中解析)。
102
+ * 不传 productId 时返回该资源下所有商品的选中时段;传了则精确匹配。
99
103
  */
100
- getSelectedSlotsForResource(resourceId: number | string): VenueSlotSelection[];
104
+ getSelectedSlotsForResource(resourceId: number | string, productId?: number): VenueSlotSelection[];
105
+ /** getSelectedSlotsForResource 的 (resourceId, productId) 精确版,内部使用。 */
106
+ private getSelectedSlotsForResourceProduct;
101
107
  /**
102
108
  * 判断某个时段是否已选中。
109
+ * 不传 productId 时:只要该资源下任一商品在 startTime 被选中即返回 true;传了则精确匹配。
103
110
  */
104
- isSlotSelected(resourceId: number | string, startTime: string): boolean;
111
+ isSlotSelected(resourceId: number | string, startTime: string, productId?: number): boolean;
105
112
  /**
106
- * 获取所有已选时段(按资源分组)。
113
+ * 判断指定 (resourceId, productId, startTime) 格子是否应因其它已选项而被禁用。
114
+ * 规则:
115
+ * 1) 同一 resourceId 下若已选了另一个 productId 的同 startTime → 禁用
116
+ * 2) 当前 resource 是组合资源:若其任一 child resource 在 startTime 被选中 → 禁用
117
+ * 3) 当前 resource 是某些组合资源的 child:若该组合资源在 startTime 被选中 → 禁用
118
+ * 4) 两个组合资源的 child 集合有交集,且对方在该 startTime 被选中 → 禁用
119
+ */
120
+ isSlotDisabledBySelection(params: {
121
+ resourceId: number | string;
122
+ productId: number;
123
+ startTime: string;
124
+ }): boolean;
125
+ /**
126
+ * 获取所有已选时段(按资源分组)。每个 slot 上带 productId,便于 UI 做 per-product 判定。
107
127
  */
108
128
  getAllSelectedSlots(): Map<number | string, VenueSlotSelection[]>;
109
129
  /**
110
- * 对指定资源的订单商品进行 reconcile:
130
+ * 对指定 (resourceId, productId) 的订单商品进行 reconcile:
111
131
  * 清除旧商品 → 合并连续时段 → 重新写入。
132
+ * 同一场地下不同商品互不干扰,各自单独 reconcile。
112
133
  */
113
- private reconcileOrderForResource;
134
+ private reconcileOrderForResourceProduct;
135
+ /** 给定一个父 rawResource,返回其 combined_resource.resource_ids 对应的子 rawResource 列表。 */
136
+ private getCombinedChildRawResources;
114
137
  setSlotConfig(config: Partial<VenueBookingSlotConfig>): void;
115
138
  getSlotConfig(): VenueBookingSlotConfig;
116
139
  loadSchedules(): Promise<void>;
@@ -629,12 +629,14 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
629
629
  }
630
630
  this.store.rawResourceData = rawData;
631
631
  for (const item of rawData) {
632
- const mapping = this.resourceProductMap.get(item.resourceId);
633
- if (mapping && item.main_field) {
634
- mapping.resourceName = item.main_field;
635
- }
636
- if (mapping && item.resource_form_id) {
637
- mapping.formId = item.resource_form_id;
632
+ const mappings = this.resourceProductMap.get(item.resourceId);
633
+ if (!mappings)
634
+ continue;
635
+ for (const mapping of mappings) {
636
+ if (item.main_field)
637
+ mapping.resourceName = item.main_field;
638
+ if (item.resource_form_id)
639
+ mapping.formId = item.resource_form_id;
638
640
  }
639
641
  }
640
642
  this.logMethodSuccess("fetchResourceAvailability", {
@@ -721,7 +723,11 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
721
723
  const resolvedSlotConfig = this.syncOperatingHoursToSlotConfig(date);
722
724
  let quotationPriceMap;
723
725
  if (this.store.quotation) {
724
- const productIds = [...new Set([...this.resourceProductMap.values()].map((m) => m.productId))];
726
+ const productIds = [
727
+ ...new Set(
728
+ [...this.resourceProductMap.values()].flat().map((m) => m.productId)
729
+ )
730
+ ];
725
731
  const timeLabels = (0, import_timeSlot.generateTimeLabels)(resolvedSlotConfig);
726
732
  const timePoints = timeLabels.map((label) => `${date} ${label}`);
727
733
  quotationPriceMap = this.store.quotation.buildProductPriceMap({ productIds, timePoints });
@@ -738,19 +744,31 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
738
744
  /**
739
745
  * 切换单个时段的选中状态(选中/取消)。
740
746
  * 内部自动处理连续时段的合并与拆分,订单是唯一真相源。
747
+ *
748
+ * slot.productId 指定当前操作针对的是该 resourceId 下的哪一个商品。
749
+ * 同一资源下不同 productId 之间互相隔离,不会相互合并。
741
750
  */
742
751
  async toggleSlot(slot) {
743
752
  this.logMethodStart("toggleSlot", {
744
753
  resourceId: slot.resourceId,
754
+ productId: slot.productId,
745
755
  startTime: slot.startTime
746
756
  });
747
757
  try {
748
- const mapping = this.resourceProductMap.get(slot.resourceId);
749
- if (!mapping)
758
+ const mappings = this.resourceProductMap.get(slot.resourceId);
759
+ if (!mappings || !mappings.length) {
750
760
  throw new Error(`未找到资源 ${slot.resourceId} 的商品映射`);
761
+ }
762
+ const mapping = mappings.find((m) => m.productId === slot.productId);
763
+ if (!mapping) {
764
+ throw new Error(`资源 ${slot.resourceId} 未关联商品 ${slot.productId}`);
765
+ }
751
766
  if (!this.store.order)
752
767
  throw new Error("order 模块未初始化");
753
- const currentSlots = this.getSelectedSlotsForResource(slot.resourceId);
768
+ const currentSlots = this.getSelectedSlotsForResourceProduct(
769
+ slot.resourceId,
770
+ slot.productId
771
+ );
754
772
  const existIndex = currentSlots.findIndex((s) => s.startTime === slot.startTime);
755
773
  let nextSlots;
756
774
  if (existIndex !== -1) {
@@ -758,13 +776,18 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
758
776
  } else {
759
777
  nextSlots = [...currentSlots, slot];
760
778
  }
761
- await this.reconcileOrderForResource(slot.resourceId, nextSlots);
779
+ await this.reconcileOrderForResourceProduct(
780
+ slot.resourceId,
781
+ slot.productId,
782
+ nextSlots
783
+ );
762
784
  const products = this.store.order.getOrderProducts();
763
785
  await this.refreshItemRuleQuantityLimits();
764
786
  await this.refreshCartValidationPassed();
765
787
  this.logMethodSuccess("toggleSlot", {
766
788
  action: existIndex !== -1 ? "remove" : "add",
767
789
  resourceId: slot.resourceId,
790
+ productId: slot.productId,
768
791
  slotCount: nextSlots.length
769
792
  });
770
793
  return products;
@@ -775,33 +798,106 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
775
798
  }
776
799
  /**
777
800
  * 获取某资源当前选中的所有独立时段(从订单中解析)。
801
+ * 不传 productId 时返回该资源下所有商品的选中时段;传了则精确匹配。
778
802
  */
779
- getSelectedSlotsForResource(resourceId) {
803
+ getSelectedSlotsForResource(resourceId, productId) {
780
804
  var _a;
781
805
  const tempOrder = (_a = this.store.order) == null ? void 0 : _a.getTempOrder();
782
806
  if (!tempOrder)
783
807
  return [];
784
- const venueProducts = tempOrder.products.filter(
785
- (p) => {
786
- var _a2, _b;
787
- return ((_a2 = p.metadata) == null ? void 0 : _a2.venue_booking) && String((_b = p.metadata) == null ? void 0 : _b.resource_id) === String(resourceId);
788
- }
789
- );
808
+ const venueProducts = tempOrder.products.filter((p) => {
809
+ var _a2, _b;
810
+ if (!((_a2 = p.metadata) == null ? void 0 : _a2.venue_booking))
811
+ return false;
812
+ if (String((_b = p.metadata) == null ? void 0 : _b.resource_id) !== String(resourceId))
813
+ return false;
814
+ if (productId != null && Number(p.product_id) !== Number(productId))
815
+ return false;
816
+ return true;
817
+ });
790
818
  const slotDuration = this.store.slotConfig.slotDurationMinutes;
791
819
  const slots = [];
792
820
  for (const product of venueProducts) {
793
- slots.push(...(0, import_slotMerge.expandMergedSlotToIndividual)(product, slotDuration));
821
+ slots.push(
822
+ ...(0, import_slotMerge.expandMergedSlotToIndividual)(product, slotDuration).map((s) => ({
823
+ ...s,
824
+ productId: Number(product.product_id)
825
+ }))
826
+ );
794
827
  }
795
828
  return slots.sort((a, b) => a.startTime.localeCompare(b.startTime));
796
829
  }
830
+ /** getSelectedSlotsForResource 的 (resourceId, productId) 精确版,内部使用。 */
831
+ getSelectedSlotsForResourceProduct(resourceId, productId) {
832
+ return this.getSelectedSlotsForResource(resourceId, productId);
833
+ }
797
834
  /**
798
835
  * 判断某个时段是否已选中。
836
+ * 不传 productId 时:只要该资源下任一商品在 startTime 被选中即返回 true;传了则精确匹配。
837
+ */
838
+ isSlotSelected(resourceId, startTime, productId) {
839
+ return this.getSelectedSlotsForResource(resourceId, productId).some((s) => s.startTime === startTime);
840
+ }
841
+ /**
842
+ * 判断指定 (resourceId, productId, startTime) 格子是否应因其它已选项而被禁用。
843
+ * 规则:
844
+ * 1) 同一 resourceId 下若已选了另一个 productId 的同 startTime → 禁用
845
+ * 2) 当前 resource 是组合资源:若其任一 child resource 在 startTime 被选中 → 禁用
846
+ * 3) 当前 resource 是某些组合资源的 child:若该组合资源在 startTime 被选中 → 禁用
847
+ * 4) 两个组合资源的 child 集合有交集,且对方在该 startTime 被选中 → 禁用
799
848
  */
800
- isSlotSelected(resourceId, startTime) {
801
- return this.getSelectedSlotsForResource(resourceId).some((s) => s.startTime === startTime);
849
+ isSlotDisabledBySelection(params) {
850
+ const { resourceId, productId, startTime } = params;
851
+ const allSelected = this.getAllSelectedSlots();
852
+ const getSelectedAt = (resId) => {
853
+ const list = allSelected.get(resId) || [];
854
+ return list.filter((s) => s.startTime === startTime);
855
+ };
856
+ const sameResourceSelections = getSelectedAt(resourceId);
857
+ if (sameResourceSelections.some((s) => Number(s.productId) !== Number(productId))) {
858
+ return true;
859
+ }
860
+ const getCombinedChildIds = (resId) => {
861
+ const raw = this.store.rawResourceData.find(
862
+ (r) => String(r.resourceId) === String(resId)
863
+ );
864
+ const combined = raw == null ? void 0 : raw.combined_resource;
865
+ if (combined && combined.status === 1 && Array.isArray(combined.resource_ids)) {
866
+ return combined.resource_ids;
867
+ }
868
+ return [];
869
+ };
870
+ const currentChildIds = getCombinedChildIds(resourceId);
871
+ const currentIsCombined = currentChildIds.length > 0;
872
+ if (currentIsCombined) {
873
+ for (const childId of currentChildIds) {
874
+ if (getSelectedAt(childId).length > 0)
875
+ return true;
876
+ }
877
+ }
878
+ for (const [selectedResId, slots] of allSelected) {
879
+ if (!slots.some((s) => s.startTime === startTime))
880
+ continue;
881
+ if (String(selectedResId) === String(resourceId))
882
+ continue;
883
+ const selectedChildIds = getCombinedChildIds(selectedResId);
884
+ if (selectedChildIds.length === 0)
885
+ continue;
886
+ if (selectedChildIds.some((id) => String(id) === String(resourceId))) {
887
+ return true;
888
+ }
889
+ if (currentIsCombined) {
890
+ const intersect = selectedChildIds.some(
891
+ (id) => currentChildIds.some((cid) => String(cid) === String(id))
892
+ );
893
+ if (intersect)
894
+ return true;
895
+ }
896
+ }
897
+ return false;
802
898
  }
803
899
  /**
804
- * 获取所有已选时段(按资源分组)。
900
+ * 获取所有已选时段(按资源分组)。每个 slot 上带 productId,便于 UI 做 per-product 判定。
805
901
  */
806
902
  getAllSelectedSlots() {
807
903
  var _a, _b;
@@ -818,8 +914,14 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
818
914
  const resourceId = (_b = product.metadata) == null ? void 0 : _b.resource_id;
819
915
  if (resourceId == null)
820
916
  continue;
917
+ const productId = Number(product.product_id);
821
918
  const existing = result.get(resourceId) || [];
822
- existing.push(...(0, import_slotMerge.expandMergedSlotToIndividual)(product, slotDuration));
919
+ existing.push(
920
+ ...(0, import_slotMerge.expandMergedSlotToIndividual)(product, slotDuration).map((s) => ({
921
+ ...s,
922
+ productId
923
+ }))
924
+ );
823
925
  result.set(resourceId, existing);
824
926
  }
825
927
  for (const [key, slots] of result) {
@@ -828,24 +930,33 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
828
930
  return result;
829
931
  }
830
932
  /**
831
- * 对指定资源的订单商品进行 reconcile:
933
+ * 对指定 (resourceId, productId) 的订单商品进行 reconcile:
832
934
  * 清除旧商品 → 合并连续时段 → 重新写入。
935
+ * 同一场地下不同商品互不干扰,各自单独 reconcile。
833
936
  */
834
- async reconcileOrderForResource(resourceId, slots) {
835
- const mapping = this.resourceProductMap.get(resourceId);
836
- if (!mapping || !this.store.order)
937
+ async reconcileOrderForResourceProduct(resourceId, productId, slots) {
938
+ const mappings = this.resourceProductMap.get(resourceId);
939
+ if (!mappings || !mappings.length || !this.store.order)
940
+ return;
941
+ const mapping = mappings.find((m) => m.productId === productId);
942
+ if (!mapping)
837
943
  return;
838
944
  const tempOrder = this.store.order.ensureTempOrder();
945
+ const matchesCurrent = (meta, pid) => !!(meta == null ? void 0 : meta.venue_booking) && String(meta == null ? void 0 : meta.resource_id) === String(resourceId) && Number(pid) === Number(productId);
839
946
  tempOrder.products = tempOrder.products.filter(
840
- (p) => {
841
- var _a, _b;
842
- return !(((_a = p.metadata) == null ? void 0 : _a.venue_booking) && String((_b = p.metadata) == null ? void 0 : _b.resource_id) === String(resourceId));
843
- }
947
+ (p) => !matchesCurrent(p.metadata, p.product_id)
844
948
  );
845
949
  tempOrder.bookings = (tempOrder.bookings || []).filter(
846
950
  (b) => {
847
- var _a, _b;
848
- return !(((_a = b.metadata) == null ? void 0 : _a.venue_booking) && String((_b = b.metadata) == null ? void 0 : _b.resource_id) === String(resourceId));
951
+ var _a, _b, _c, _d;
952
+ if (!((_a = b.metadata) == null ? void 0 : _a.venue_booking))
953
+ return true;
954
+ if (String((_b = b.metadata) == null ? void 0 : _b.resource_id) !== String(resourceId))
955
+ return true;
956
+ const bookingProductId = ((_c = b.metadata) == null ? void 0 : _c.product_id) ?? ((_d = b == null ? void 0 : b.product) == null ? void 0 : _d.product_id);
957
+ if (bookingProductId == null)
958
+ return false;
959
+ return Number(bookingProductId) !== Number(productId);
849
960
  }
850
961
  );
851
962
  if (!slots.length) {
@@ -858,6 +969,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
858
969
  const rawResource = this.store.rawResourceData.find(
859
970
  (r) => String(r.resourceId) === String(resourceId)
860
971
  );
972
+ const childRawResources = this.getCombinedChildRawResources(rawResource);
861
973
  const venueProduct = this.getVenueProducts().find((p) => p.id === mapping.productId);
862
974
  tempOrder.bookings = tempOrder.bookings || [];
863
975
  for (let i = 0; i < merged.length; i++) {
@@ -868,6 +980,28 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
868
980
  const endMoment = (0, import_dayjs.default)(group.endTime, "YYYY-MM-DD HH:mm");
869
981
  const duration = endMoment.diff(startMoment, "minute");
870
982
  const customDepositData = cloneCustomDepositData(venueProduct == null ? void 0 : venueProduct.custom_deposit_data);
983
+ const resourceEntry = {
984
+ relation_type: "form",
985
+ like_status: "common",
986
+ id: resourceId,
987
+ main_field: mapping.resourceName,
988
+ form_id: (rawResource == null ? void 0 : rawResource.form_id) ?? mapping.formId,
989
+ relation_id: resourceId,
990
+ capacity: 1,
991
+ metadata: {}
992
+ };
993
+ if (childRawResources && childRawResources.length) {
994
+ resourceEntry.children = childRawResources.map((child) => ({
995
+ relation_type: "form",
996
+ like_status: "common",
997
+ id: child.resourceId,
998
+ main_field: child.main_field || "",
999
+ form_id: child.form_id ?? child.formId,
1000
+ relation_id: child.resourceId,
1001
+ capacity: child.capacity ?? 1,
1002
+ metadata: {}
1003
+ }));
1004
+ }
871
1005
  tempOrder.products.push(
872
1006
  (0, import_utils.normalizeOrderProduct)({
873
1007
  product_id: mapping.productId,
@@ -914,16 +1048,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
914
1048
  sub_type: "minutes",
915
1049
  duration,
916
1050
  like_status: "common",
917
- resources: [{
918
- relation_type: "form",
919
- like_status: "common",
920
- id: resourceId,
921
- main_field: mapping.resourceName,
922
- form_id: (rawResource == null ? void 0 : rawResource.form_id) ?? mapping.formId,
923
- relation_id: resourceId,
924
- capacity: 1,
925
- metadata: {}
926
- }],
1051
+ resources: [resourceEntry],
927
1052
  schedule_id: 0,
928
1053
  select_date: startMoment.format("YYYY-MM-DD"),
929
1054
  start_date: startMoment.format("YYYY-MM-DD"),
@@ -944,7 +1069,8 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
944
1069
  mapping,
945
1070
  rawResource,
946
1071
  bookingUuid,
947
- productUid: identityKey
1072
+ productUid: identityKey,
1073
+ childResources: childRawResources
948
1074
  });
949
1075
  tempOrder.bookings.push(booking);
950
1076
  }
@@ -952,6 +1078,24 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
952
1078
  await this.store.order.recalculateSummary({ createIfMissing: true });
953
1079
  this.store.order.persistTempOrder();
954
1080
  }
1081
+ /** 给定一个父 rawResource,返回其 combined_resource.resource_ids 对应的子 rawResource 列表。 */
1082
+ getCombinedChildRawResources(rawResource) {
1083
+ if (!rawResource)
1084
+ return void 0;
1085
+ const combined = rawResource.combined_resource;
1086
+ if (!combined || combined.status !== 1 || !Array.isArray(combined.resource_ids) || !combined.resource_ids.length) {
1087
+ return void 0;
1088
+ }
1089
+ const children = [];
1090
+ for (const id of combined.resource_ids) {
1091
+ const child = this.store.rawResourceData.find(
1092
+ (r) => String(r.resourceId) === String(id)
1093
+ );
1094
+ if (child)
1095
+ children.push(child);
1096
+ }
1097
+ return children.length ? children : void 0;
1098
+ }
955
1099
  // ─── 配置 ───
956
1100
  setSlotConfig(config) {
957
1101
  this.baseSlotConfig = {
@@ -1034,7 +1178,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1034
1178
  const now = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1035
1179
  for (const product of tempOrder.products) {
1036
1180
  if ((_b = product.metadata) == null ? void 0 : _b.venue_booking) {
1037
- const mapping = this.resourceProductMap.get(product.metadata.resource_id);
1181
+ const mappings = this.resourceProductMap.get(product.metadata.resource_id);
1182
+ if (!mappings || !mappings.length)
1183
+ continue;
1184
+ const mapping = mappings.find((m) => Number(m.productId) === Number(product.product_id)) || mappings[0];
1038
1185
  if (!mapping)
1039
1186
  continue;
1040
1187
  const slots = (0, import_slotMerge.expandMergedSlotToIndividual)(
@@ -1043,6 +1190,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1043
1190
  );
1044
1191
  const updatedSlots = slots.map((slot) => ({
1045
1192
  ...slot,
1193
+ productId: mapping.productId,
1046
1194
  price: this.store.quotation.getPriceForProduct({
1047
1195
  productId: mapping.productId,
1048
1196
  datetime: slot.startTime