@pisell/pisellos 3.0.66 → 3.0.67

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.
@@ -34,16 +34,17 @@ __export(BookingByStep_exports, {
34
34
  module.exports = __toCommonJS(BookingByStep_exports);
35
35
  var import_BaseModule = require("../../modules/BaseModule");
36
36
  var import_types = require("./types");
37
+ var import_utils = require("../../modules/Cart/utils");
37
38
  var import_products = require("./utils/products");
38
39
  var import_resources = require("./utils/resources");
39
40
  var import_dayjs = __toESM(require("dayjs"));
40
41
  var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
41
42
  var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
42
- var import_utils = require("../../modules/Resource/utils");
43
+ var import_utils2 = require("../../modules/Resource/utils");
43
44
  var import_lodash_es = require("lodash-es");
44
- var import_utils2 = require("../../modules/Schedule/utils");
45
- var import_utils3 = require("../../modules/Date/utils");
46
- var import_utils4 = require("../../modules/Product/utils");
45
+ var import_utils3 = require("../../modules/Schedule/utils");
46
+ var import_utils4 = require("../../modules/Date/utils");
47
+ var import_utils5 = require("../../modules/Product/utils");
47
48
  var import_timeslots = require("./utils/timeslots");
48
49
  var import_changePrice = require("../../modules/Cart/utils/changePrice");
49
50
  var import_capacity = require("./utils/capacity");
@@ -364,7 +365,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
364
365
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
365
366
  if (!date) {
366
367
  const normalProductCartItem = cartItems.find(
367
- (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
368
+ (n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
368
369
  );
369
370
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
370
371
  }
@@ -474,7 +475,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
474
475
  let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
475
476
  if (!date) {
476
477
  const normalProductCartItem = cartItems.find(
477
- (n) => !(0, import_utils4.isNormalProduct)(n._productOrigin)
478
+ (n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
478
479
  );
479
480
  date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
480
481
  }
@@ -526,7 +527,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
526
527
  }
527
528
  });
528
529
  let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
529
- if ((0, import_utils4.areAllNormalProducts)(
530
+ if ((0, import_utils5.areAllNormalProducts)(
530
531
  newCartItems.map((n) => n._productOrigin)
531
532
  )) {
532
533
  type = "virtual";
@@ -636,7 +637,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
636
637
  addItemParams.account = account;
637
638
  }
638
639
  this.addProductCheck({ date });
639
- this.store.cart.addItem(addItemParams);
640
+ if (addItemParams.quantity > 1 && !(0, import_utils5.isNormalProduct)(productData)) {
641
+ for (let i = 0; i < addItemParams.quantity; i++) {
642
+ const newAddItemParams = (0, import_lodash_es.cloneDeep)(addItemParams);
643
+ newAddItemParams.quantity = 1;
644
+ this.store.cart.addItem(newAddItemParams);
645
+ }
646
+ } else {
647
+ this.store.cart.addItem(addItemParams);
648
+ }
640
649
  return { success: true };
641
650
  }
642
651
  /**
@@ -649,7 +658,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
649
658
  date
650
659
  }) {
651
660
  if (date) {
652
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
661
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
653
662
  const cartItemsByDate = cartItems.filter(
654
663
  (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
655
664
  );
@@ -811,7 +820,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
811
820
  * @returns 不符合条件的购物车商品ID列表
812
821
  */
813
822
  checkCartItems(type) {
814
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
823
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
815
824
  const errorCartItemIds = [];
816
825
  cartItems.forEach((cartItem) => {
817
826
  const result = this.store.cart.checkCartItemByType(cartItem, type);
@@ -842,7 +851,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
842
851
  resources.push(...n.resource);
843
852
  });
844
853
  }
845
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
854
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
846
855
  if (!resources.length) {
847
856
  const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
848
857
  if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
@@ -858,7 +867,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
858
867
  });
859
868
  }
860
869
  }
861
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
870
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
862
871
  const arr = [];
863
872
  cartItems.forEach((cartItem) => {
864
873
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
@@ -987,14 +996,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
987
996
  */
988
997
  getResourcesListByCartItem(id) {
989
998
  var _a, _b;
990
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
999
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
991
1000
  const dateRange = this.store.date.getDateRange();
992
1001
  const resources = [];
993
1002
  dateRange.forEach((n) => {
994
1003
  if (n.resource)
995
1004
  resources.push(...n.resource);
996
1005
  });
997
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
1006
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
998
1007
  const targetCartItem = cartItems.find((n) => n._id === id);
999
1008
  if (!targetCartItem) {
1000
1009
  throw new Error(`没有找到${id}购物车商品`);
@@ -1051,7 +1060,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1051
1060
  capacity
1052
1061
  }) {
1053
1062
  var _a, _b, _c;
1054
- if ((0, import_utils4.isNormalProduct)(cartItem._productOrigin)) {
1063
+ if ((0, import_utils5.isNormalProduct)(cartItem._productOrigin)) {
1055
1064
  return {};
1056
1065
  }
1057
1066
  const dateRange = this.store.date.getDateRange();
@@ -1086,7 +1095,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1086
1095
  });
1087
1096
  }
1088
1097
  }
1089
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
1098
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
1090
1099
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1091
1100
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1092
1101
  allCartItems,
@@ -1167,7 +1176,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1167
1176
  selectedResource: targetResource
1168
1177
  };
1169
1178
  } else {
1170
- const resourcesMap2 = (0, import_utils.getResourcesMap)(resources);
1179
+ const resourcesMap2 = (0, import_utils2.getResourcesMap)(resources);
1171
1180
  const resourceIds = resources.map((n) => n.id);
1172
1181
  const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
1173
1182
  resourceIds,
@@ -1305,7 +1314,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1305
1314
  currentResourcesRenderList.push(...n.renderList || []);
1306
1315
  }
1307
1316
  });
1308
- const resourcesMap = (0, import_utils.getResourcesMap)(currentResourcesRenderList);
1317
+ const resourcesMap = (0, import_utils2.getResourcesMap)(currentResourcesRenderList);
1309
1318
  if (item.holder_id) {
1310
1319
  selectedResources = (0, import_resources.getOthersSelectedResources)(
1311
1320
  allCartItems,
@@ -1370,7 +1379,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1370
1379
  }
1371
1380
  });
1372
1381
  };
1373
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1382
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1374
1383
  if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1375
1384
  accountList.forEach((account) => {
1376
1385
  const cartItems2 = this.store.cart.getCartByAccount(account.getId());
@@ -1386,7 +1395,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1386
1395
  var _a, _b, _c, _d, _e, _f, _g, _h;
1387
1396
  let dateRange = this.store.date.getDateRange();
1388
1397
  const resources = [];
1389
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1398
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1390
1399
  const resourceIds = [];
1391
1400
  let resourcesTypeId = void 0;
1392
1401
  let isSingleResource = false;
@@ -1424,7 +1433,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1424
1433
  }
1425
1434
  });
1426
1435
  }
1427
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
1436
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1428
1437
  let duration = 0;
1429
1438
  const accountList = this.store.accountList.getAccounts();
1430
1439
  const checkDuration = (cartItems2) => {
@@ -1523,7 +1532,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1523
1532
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
1524
1533
  submitTimeSlot(timeSlots) {
1525
1534
  var _a, _b;
1526
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
1535
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1527
1536
  const allResources = this.store.date.getResourcesListByDate(
1528
1537
  timeSlots.start_at.format("YYYY-MM-DD")
1529
1538
  );
@@ -1601,7 +1610,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1601
1610
  getScheduleDataByIds(scheduleIds) {
1602
1611
  const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1603
1612
  const targetSchedulesData = targetSchedules.map((item) => {
1604
- return (0, import_utils2.calcCalendarDataByScheduleResult)(item);
1613
+ return (0, import_utils3.calcCalendarDataByScheduleResult)(item);
1605
1614
  });
1606
1615
  const newSchedule = {};
1607
1616
  targetSchedulesData.forEach((item) => {
@@ -1673,7 +1682,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1673
1682
  const resourcesDates = this.store.date.getDateList();
1674
1683
  const targetResourceDate = resourcesDates.find((n) => n.date === date);
1675
1684
  const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1676
- const resourcesMap = (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1685
+ const resourcesMap = (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1677
1686
  const selectedResources = (0, import_resources.getOthersSelectedResources)(
1678
1687
  cartItems,
1679
1688
  "",
@@ -1685,12 +1694,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1685
1694
  selectedResources,
1686
1695
  1
1687
1696
  );
1688
- const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
1697
+ const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
1689
1698
  targetSchedules,
1690
1699
  {},
1691
1700
  date
1692
1701
  );
1693
- const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1702
+ const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
1694
1703
  let allProductResources = productResources.flatMap((n) => n.renderList);
1695
1704
  allProductResources.sort((a, b) => {
1696
1705
  var _a2, _b2, _c2, _d2;
@@ -1806,7 +1815,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1806
1815
  otherSameTimesCartItems.forEach((m) => {
1807
1816
  var _a2, _b2;
1808
1817
  const productResources2 = (0, import_resources.getResourcesByProduct)(
1809
- (0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
1818
+ (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
1810
1819
  ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
1811
1820
  selectedResources,
1812
1821
  1
@@ -1896,12 +1905,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1896
1905
  }
1897
1906
  });
1898
1907
  });
1908
+ if (intersections.length === 0) {
1909
+ console.log(`资源${i}与当前公共时间段无交集,跳过该资源`);
1910
+ continue;
1911
+ }
1899
1912
  commonSlots = intersections;
1900
1913
  console.log(`与资源${i}求交集后的公共时间段:`, commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
1901
- if (commonSlots.length === 0) {
1902
- console.log("没有找到公共时间段");
1903
- return [];
1904
- }
1905
1914
  }
1906
1915
  const result = commonSlots.map((slot) => ({
1907
1916
  startTime: slot.start.format("HH:mm"),
@@ -1912,7 +1921,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1912
1921
  }
1913
1922
  checkMaxDurationCapacity() {
1914
1923
  var _a, _b;
1915
- const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1924
+ const cartItems = this.store.cart.getItems().filter((item) => !(0, import_utils5.isNormalProduct)(item._productOrigin));
1916
1925
  if (cartItems.length === 0)
1917
1926
  return { success: true, minAvailableCount: 0 };
1918
1927
  const itemsWithTime = [];
@@ -1953,7 +1962,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1953
1962
  const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
1954
1963
  if (!targetResourceDate)
1955
1964
  return { success: false, minAvailableCount: 0 };
1956
- const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
1965
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
1957
1966
  const resourceCodeToFormIdMap = {};
1958
1967
  Object.values(itemsByResourceType).flat().forEach((cartItem) => {
1959
1968
  var _a2, _b2;
@@ -2095,7 +2104,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2095
2104
  const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
2096
2105
  if (!targetResourceDate)
2097
2106
  continue;
2098
- const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
2107
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2099
2108
  itemsInTimeSlot.forEach((cartItem) => {
2100
2109
  if (!cartItem._productOrigin)
2101
2110
  return;
@@ -2107,7 +2116,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2107
2116
  }
2108
2117
  });
2109
2118
  });
2110
- if (!(0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
2119
+ const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
2120
+ if (!success) {
2111
2121
  const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2112
2122
  return { success: false, minAvailableCount: minAvailableCount2 };
2113
2123
  }
@@ -2115,6 +2125,268 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2115
2125
  const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2116
2126
  return { success: true, minAvailableCount };
2117
2127
  }
2128
+ /**
2129
+ * 将 ProductData 转换为 CartItem,但不添加到购物车
2130
+ * 参考 addProductToCart 方法的实现
2131
+ */
2132
+ convertProductToCartItem({
2133
+ product,
2134
+ date,
2135
+ account
2136
+ }) {
2137
+ const {
2138
+ bundle,
2139
+ options,
2140
+ origin,
2141
+ product_variant_id,
2142
+ quantity = 1
2143
+ } = product || {};
2144
+ const productData = { ...origin, product_variant_id };
2145
+ const processedProduct = (0, import_utils.handleVariantProduct)(productData);
2146
+ if (!account) {
2147
+ const activeAccount = this.getActiveAccount();
2148
+ if (activeAccount) {
2149
+ account = activeAccount;
2150
+ }
2151
+ }
2152
+ const cartItem = {
2153
+ _id: (0, import_utils.getUniqueId)("temp_"),
2154
+ _origin: (0, import_utils.createCartItemOrigin)(),
2155
+ _productOrigin: processedProduct,
2156
+ _productInit: product
2157
+ };
2158
+ (0, import_utils.formatProductToCartItem)({
2159
+ cartItem,
2160
+ product: processedProduct,
2161
+ bundle,
2162
+ options,
2163
+ product_variant_id,
2164
+ quantity
2165
+ });
2166
+ if (date) {
2167
+ (0, import_utils.formatDateToCartItem)({
2168
+ cartItem,
2169
+ date
2170
+ });
2171
+ }
2172
+ if (account) {
2173
+ (0, import_utils.formatAccountToCartItem)({
2174
+ cartItem,
2175
+ account
2176
+ });
2177
+ }
2178
+ return cartItem;
2179
+ }
2180
+ checkMaxDurationCapacityForDetailNums({
2181
+ product,
2182
+ date,
2183
+ account
2184
+ }) {
2185
+ var _a, _b;
2186
+ const cartItems = this.store.cart.getItems().filter((item) => !(0, import_utils5.isNormalProduct)(item._productOrigin));
2187
+ const currentCartItem = this.convertProductToCartItem({ product, date, account });
2188
+ cartItems.push(currentCartItem);
2189
+ if (cartItems.length === 0)
2190
+ return { success: true, minAvailableCount: 0 };
2191
+ const itemsWithTime = [];
2192
+ const itemsWithoutTime = [];
2193
+ const availableCountsByResourceType = [];
2194
+ cartItems.forEach((cartItem) => {
2195
+ if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
2196
+ itemsWithTime.push(cartItem);
2197
+ } else {
2198
+ itemsWithoutTime.push(cartItem);
2199
+ }
2200
+ });
2201
+ const processedItemsWithoutTime = [];
2202
+ if (itemsWithoutTime.length > 0) {
2203
+ const itemsByResourceType = {};
2204
+ itemsWithoutTime.forEach((cartItem) => {
2205
+ var _a2;
2206
+ if (!cartItem._productOrigin)
2207
+ return;
2208
+ const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
2209
+ resourceTypes.forEach((resourceType) => {
2210
+ var _a3;
2211
+ if (resourceType.status === 1) {
2212
+ const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
2213
+ if (!itemsByResourceType[resourceCode]) {
2214
+ itemsByResourceType[resourceCode] = [];
2215
+ }
2216
+ if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
2217
+ itemsByResourceType[resourceCode].push(cartItem);
2218
+ }
2219
+ }
2220
+ });
2221
+ });
2222
+ const dateRange = this.store.date.getDateRange();
2223
+ if (!dateRange || dateRange.length === 0)
2224
+ return { success: false, minAvailableCount: 0 };
2225
+ const resourcesDates = this.store.date.getDateList();
2226
+ const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
2227
+ if (!targetResourceDate)
2228
+ return { success: false, minAvailableCount: 0 };
2229
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2230
+ const resourceCodeToFormIdMap = {};
2231
+ Object.values(itemsByResourceType).flat().forEach((cartItem) => {
2232
+ var _a2, _b2;
2233
+ if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
2234
+ cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
2235
+ var _a3, _b3;
2236
+ if (resourceConfig.status === 1 && resourceConfig.code) {
2237
+ const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
2238
+ if (formId) {
2239
+ resourceCodeToFormIdMap[resourceConfig.code] = formId;
2240
+ }
2241
+ }
2242
+ });
2243
+ }
2244
+ });
2245
+ let hasCapacityIssue = false;
2246
+ const resourceCapacityInfo = [];
2247
+ const processedCartItemIds = /* @__PURE__ */ new Set();
2248
+ for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
2249
+ const targetFormId = resourceCodeToFormIdMap[resourceCode];
2250
+ if (!targetFormId) {
2251
+ console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
2252
+ return { success: false, minAvailableCount: 0 };
2253
+ }
2254
+ const resourcesOfThisType = [];
2255
+ items.forEach((cartItem) => {
2256
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2257
+ productResourceIds.forEach((resourceId) => {
2258
+ var _a2;
2259
+ const resource = resourcesMap[resourceId];
2260
+ if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
2261
+ if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
2262
+ resourcesOfThisType.push(resource);
2263
+ }
2264
+ }
2265
+ });
2266
+ });
2267
+ if (resourcesOfThisType.length === 0) {
2268
+ console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
2269
+ return { success: false, minAvailableCount: 0 };
2270
+ }
2271
+ let resourceTypeConfig = null;
2272
+ for (const cartItem of items) {
2273
+ if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
2274
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
2275
+ (r) => r.code === resourceCode && r.status === 1
2276
+ );
2277
+ if (resourceTypeConfig)
2278
+ break;
2279
+ }
2280
+ }
2281
+ const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
2282
+ let totalAvailable;
2283
+ let requiredAmount;
2284
+ let availableAmount;
2285
+ if (isMultipleBooking) {
2286
+ totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
2287
+ return sum + (resource.capacity || 0);
2288
+ }, 0);
2289
+ requiredAmount = items.reduce((sum, cartItem) => {
2290
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
2291
+ return sum + currentCapacity;
2292
+ }, 0);
2293
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2294
+ } else {
2295
+ totalAvailable = resourcesOfThisType.length;
2296
+ requiredAmount = items.reduce((sum, cartItem) => {
2297
+ return sum + (cartItem.num || 1);
2298
+ }, 0);
2299
+ availableAmount = Math.max(0, totalAvailable - requiredAmount);
2300
+ }
2301
+ resourceCapacityInfo.push({
2302
+ code: resourceCode,
2303
+ available: availableAmount,
2304
+ total: totalAvailable,
2305
+ required: requiredAmount,
2306
+ isMultiple: isMultipleBooking
2307
+ });
2308
+ availableCountsByResourceType.push(availableAmount);
2309
+ if (requiredAmount > totalAvailable) {
2310
+ hasCapacityIssue = true;
2311
+ console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
2312
+ }
2313
+ console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
2314
+ id: r.id,
2315
+ times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
2316
+ })));
2317
+ const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
2318
+ console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
2319
+ if (commonTimeSlots.length === 0) {
2320
+ console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
2321
+ return { success: false, minAvailableCount: 0 };
2322
+ }
2323
+ const firstCommonSlot = commonTimeSlots[0];
2324
+ console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
2325
+ items.forEach((cartItem) => {
2326
+ if (!processedCartItemIds.has(cartItem._id)) {
2327
+ processedCartItemIds.add(cartItem._id);
2328
+ const processedItem = {
2329
+ ...cartItem,
2330
+ start_date: dateRange[0].date,
2331
+ start_time: firstCommonSlot.startTime,
2332
+ end_time: firstCommonSlot.endTime,
2333
+ end_date: dateRange[0].date
2334
+ };
2335
+ processedItemsWithoutTime.push(processedItem);
2336
+ }
2337
+ });
2338
+ }
2339
+ if (hasCapacityIssue) {
2340
+ const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
2341
+ if (overCapacityResources.length > 0) {
2342
+ const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
2343
+ return { success: false, minAvailableCount: minTotalCapacity2 };
2344
+ }
2345
+ const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
2346
+ return { success: false, minAvailableCount: minTotalCapacity };
2347
+ }
2348
+ }
2349
+ const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
2350
+ const cartItemsByTimeSlot = {};
2351
+ allProcessedItems.forEach((cartItem) => {
2352
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
2353
+ return;
2354
+ const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
2355
+ if (!cartItemsByTimeSlot[timeSlotKey]) {
2356
+ cartItemsByTimeSlot[timeSlotKey] = [];
2357
+ }
2358
+ cartItemsByTimeSlot[timeSlotKey].push(cartItem);
2359
+ });
2360
+ for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
2361
+ const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
2362
+ const timeSlotStart = `${startDate} ${startTime}`;
2363
+ const timeSlotEnd = `${endDate} ${endTime}`;
2364
+ const allResourcesForTimeSlot = [];
2365
+ const resourcesIdSet = /* @__PURE__ */ new Set();
2366
+ const resourcesDates = this.store.date.getDateList();
2367
+ const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
2368
+ if (!targetResourceDate)
2369
+ continue;
2370
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2371
+ itemsInTimeSlot.forEach((cartItem) => {
2372
+ if (!cartItem._productOrigin)
2373
+ return;
2374
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2375
+ productResourceIds.forEach((resourceId) => {
2376
+ if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
2377
+ resourcesIdSet.add(resourceId);
2378
+ allResourcesForTimeSlot.push(resourcesMap[resourceId]);
2379
+ }
2380
+ });
2381
+ });
2382
+ const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
2383
+ if (!success) {
2384
+ return { success: false, minAvailableCount: available };
2385
+ }
2386
+ }
2387
+ const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2388
+ return { success: true, minAvailableCount };
2389
+ }
2118
2390
  setOtherData(key, value) {
2119
2391
  this.otherData[key] = value;
2120
2392
  this.checkSaveCache({
@@ -2166,8 +2438,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2166
2438
  resources.push(...n.resource);
2167
2439
  });
2168
2440
  }
2169
- const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
2170
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2441
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
2442
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2171
2443
  const cartItem = cartItems.find((item) => item._id === cartItemId);
2172
2444
  if (!cartItem)
2173
2445
  return [];
@@ -2380,12 +2652,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2380
2652
  }
2381
2653
  }
2382
2654
  if (status === "available") {
2383
- const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
2655
+ const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
2384
2656
  targetSchedules,
2385
2657
  {},
2386
2658
  currentDateStr
2387
2659
  );
2388
- const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
2660
+ const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
2389
2661
  const timesSlotCanUse = scheduleTimeSlots.some((item) => {
2390
2662
  const resourcesUseableMap = {};
2391
2663
  return openResources.every((resource) => {
@@ -2442,7 +2714,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2442
2714
  }
2443
2715
  currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
2444
2716
  }
2445
- dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
2717
+ dates = (0, import_utils4.handleAvailableDateByResource)(res.data, dates);
2446
2718
  this.store.date.setDateList(dates);
2447
2719
  if (!this.store.currentProductMeta)
2448
2720
  this.store.currentProductMeta = {};
@@ -2458,11 +2730,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2458
2730
  };
2459
2731
  }
2460
2732
  isCartAllNormalProducts() {
2461
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2733
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2462
2734
  return !cartItems.length;
2463
2735
  }
2464
2736
  isCartHasDurationProduct() {
2465
- const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
2737
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2466
2738
  return cartItems.some((n) => {
2467
2739
  var _a;
2468
2740
  return (_a = n._productOrigin) == null ? void 0 : _a.duration;
@@ -2471,11 +2743,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2471
2743
  isTargetNormalProduct(product) {
2472
2744
  if (!product)
2473
2745
  return false;
2474
- return (0, import_utils4.isNormalProduct)(product);
2746
+ return (0, import_utils5.isNormalProduct)(product);
2475
2747
  }
2476
2748
  isTargetCartIdNormalProduct(id) {
2477
2749
  const cartItem = this.store.cart.getItems().find((n) => n._id === id);
2478
- return cartItem && (0, import_utils4.isNormalProduct)(cartItem._productOrigin);
2750
+ return cartItem && (0, import_utils5.isNormalProduct)(cartItem._productOrigin);
2479
2751
  }
2480
2752
  };
2481
2753
  // Annotate the CommonJS export names for ESM import in node:
@@ -15,8 +15,9 @@ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any
15
15
  * @return {*}
16
16
  * @Author: zhiwei.Wang
17
17
  */
18
- export declare const getSumCapacity: ({ capacity }: {
18
+ export declare const getSumCapacity: ({ capacity, num }: {
19
19
  capacity: CapacityItem[];
20
+ num: number;
20
21
  }) => number;
21
22
  /**
22
23
  * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
@@ -67,4 +68,8 @@ export declare function getResourcesIdsByProduct(product: any): number[];
67
68
  /**
68
69
  * 检查特定时间段的容量是否足够
69
70
  */
70
- export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): boolean;
71
+ export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
72
+ success: boolean;
73
+ required: number;
74
+ available: number;
75
+ };