@pisell/pisellos 3.0.32 → 3.0.34

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.
@@ -37,10 +37,15 @@ var import_types = require("./types");
37
37
  var import_products = require("./utils/products");
38
38
  var import_resources = require("./utils/resources");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
+ var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
41
+ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
40
42
  var import_utils = require("../../modules/Resource/utils");
41
43
  var import_lodash_es = require("lodash-es");
42
44
  var import_utils2 = require("../../modules/Schedule/utils");
43
45
  var import_utils3 = require("../../modules/Date/utils");
46
+ var import_timeslots = require("./utils/timeslots");
47
+ import_dayjs.default.extend(import_isSameOrBefore.default);
48
+ import_dayjs.default.extend(import_isSameOrAfter.default);
44
49
  var BookingByStepImpl = class extends import_BaseModule.BaseModule {
45
50
  constructor() {
46
51
  super(...arguments);
@@ -211,12 +216,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
211
216
  product_ids,
212
217
  category_ids = []
213
218
  }) {
219
+ var _a;
214
220
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
215
221
  this.setDateRange([
216
222
  { date, status: "available", week: "", weekNum: 0 },
217
223
  { date, status: "available", week: "", weekNum: 0 }
218
224
  ]);
219
- const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
225
+ const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id).filter((n) => n !== null && n !== void 0);
226
+ if (!(product_ids == null ? void 0 : product_ids.length)) {
227
+ const schedule = scheduleList.find((n) => n.date === date);
228
+ if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
229
+ product_ids = schedule.product_ids;
230
+ }
231
+ }
220
232
  return await this.loadProducts({
221
233
  schedule_ids: scheduleIds,
222
234
  product_ids,
@@ -242,16 +254,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
242
254
  });
243
255
  for (const item of cartItems) {
244
256
  const targetProduct = res.find((n) => n.id === item.id);
245
- const cartProduct = await this.store.products.getProduct(item.id);
257
+ const cartProduct = await this.store.products.getProduct(
258
+ item.id
259
+ );
246
260
  const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
247
261
  let bundle = item._bundleOrigin;
248
262
  productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
249
263
  productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
250
264
  bundle = bundle == null ? void 0 : bundle.map((n) => {
251
265
  var _a2;
252
- const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find((m) => m.id === n.group_id);
266
+ const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
267
+ (m) => m.id === n.group_id
268
+ );
253
269
  if (targetBundle) {
254
- const targetBundleItem = targetBundle.bundle_item.find((m) => m.id === n.id);
270
+ const targetBundleItem = targetBundle.bundle_item.find(
271
+ (m) => m.id === n.id
272
+ );
255
273
  if (targetBundleItem) {
256
274
  return {
257
275
  ...n,
@@ -268,13 +286,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
268
286
  bundle
269
287
  });
270
288
  }
271
- ;
272
289
  }
273
290
  }
274
291
  // 加载当前店铺下所有 schedule
275
292
  async loadAllSchedule() {
276
293
  var _a;
277
- const scheduleList = await this.request.get(`/schedule`, { num: 999 }, { useCache: true });
294
+ const scheduleList = await this.request.get(
295
+ `/schedule`,
296
+ { num: 999 },
297
+ { useCache: true }
298
+ );
278
299
  this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
279
300
  }
280
301
  // ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
@@ -620,19 +641,27 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
620
641
  var _a2;
621
642
  if (item._id !== targetCartItem._id) {
622
643
  const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
623
- return !targetCartItem._origin.resources.some((targetRes) => {
644
+ const sameFormIdResources = targetCartItem._origin.resources.filter((n) => n.form_id === m.form_id);
645
+ if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
646
+ return true;
647
+ }
648
+ return !sameFormIdResources.some((targetRes) => {
624
649
  var _a3, _b, _c;
625
650
  if (targetRes.resourceType !== "single") {
626
651
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
627
652
  capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
628
653
  product_bundle: item._origin.product.product_bundle
629
654
  });
630
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
631
- const originResource = allOriginResources.find((n) => n.id === targetRes.id);
632
- if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
655
+ const currentCapacity = (0, import_resources.getSumCapacity)({
656
+ capacity: formatCapacity
657
+ });
658
+ const originResource = allOriginResources.find(
659
+ (n) => n.id === targetRes.id
660
+ );
661
+ if (currentResourcesCapacityMap[m.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
633
662
  return true;
634
663
  }
635
- currentResourcesCapacityMap[targetRes.id] += currentCapacity;
664
+ currentResourcesCapacityMap[m.id] += currentCapacity;
636
665
  return false;
637
666
  }
638
667
  if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
@@ -651,7 +680,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
651
680
  }
652
681
  )))
653
682
  return true;
654
- if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
683
+ if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
684
+ targetRes.id
685
+ ))
655
686
  return true;
656
687
  }
657
688
  return false;
@@ -666,8 +697,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
666
697
  _id: item._id,
667
698
  resources,
668
699
  date: {
669
- startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
670
- endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
700
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
701
+ "YYYY-MM-DD HH:mm"
702
+ ),
703
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format(
704
+ "YYYY-MM-DD HH:mm"
705
+ )
671
706
  }
672
707
  });
673
708
  } else {
@@ -1140,6 +1175,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1140
1175
  }, {});
1141
1176
  if (timeSlots) {
1142
1177
  let targetResource = null;
1178
+ let targetResourceTime = 0;
1143
1179
  for (const n of resources) {
1144
1180
  const mTimes = n.times.filter((n2) => {
1145
1181
  return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
@@ -1147,10 +1183,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1147
1183
  if (mTimes.length === 0) {
1148
1184
  continue;
1149
1185
  }
1150
- const totalCapacity = (countMap[n.id] || []).reduce((sum, item) => {
1151
- const hasOverlap = !(0, import_dayjs.default)(item.time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(item.time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
1152
- return hasOverlap ? sum + item.pax : sum;
1153
- }, 0);
1186
+ const totalCapacity = (countMap[n.id] || []).reduce(
1187
+ (sum, item) => {
1188
+ const hasOverlap = !(0, import_dayjs.default)(item.time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(item.time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
1189
+ return hasOverlap ? sum + item.pax : sum;
1190
+ },
1191
+ 0
1192
+ );
1154
1193
  const canUseTime = mTimes.find((item) => {
1155
1194
  var _a2;
1156
1195
  const res = (0, import_resources.getIsUsableByTimeItem)({
@@ -1166,8 +1205,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1166
1205
  }
1167
1206
  return res.usable;
1168
1207
  });
1169
- if (canUseTime && !n.onlyComputed) {
1208
+ const currentResourceIdleTime = (0, import_timeslots.calculateResourceAvailableTime)({
1209
+ resource: n,
1210
+ timeSlots,
1211
+ currentCapacity: totalCapacity + (capacity || 0)
1212
+ });
1213
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1170
1214
  targetResource = n;
1215
+ targetResourceTime = currentResourceIdleTime;
1171
1216
  break;
1172
1217
  }
1173
1218
  }
@@ -1228,7 +1273,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1228
1273
  };
1229
1274
  }
1230
1275
  if (recordTimeSlots) {
1231
- const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find((n) => n.code === resources_code);
1276
+ const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1277
+ (n) => n.code === resources_code
1278
+ );
1232
1279
  const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
1233
1280
  if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
1234
1281
  let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
@@ -1347,7 +1394,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1347
1394
  )) {
1348
1395
  return;
1349
1396
  }
1350
- const targetResource = targetRenderList[0];
1397
+ const fastestResource = (0, import_timeslots.findFastestAvailableResource)({
1398
+ resources: targetRenderList,
1399
+ currentCapacity,
1400
+ countMap: selectResourcesMap
1401
+ });
1402
+ const targetResource = fastestResource || targetRenderList[0];
1351
1403
  targetResource.capacity = currentCapacity;
1352
1404
  (0, import_resources.checkSubResourcesCapacity)(targetResource);
1353
1405
  if (!selectResourcesMap[targetResource.id]) {
@@ -1407,7 +1459,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1407
1459
  (n) => n.code === resources_code
1408
1460
  )) == null ? void 0 : _g.id;
1409
1461
  if (((_h = item._productOrigin) == null ? void 0 : _h.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
1410
- const currentCutOffTime = (0, import_dayjs.default)().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
1462
+ const currentCutOffTime = (0, import_dayjs.default)().add(
1463
+ item._productOrigin.cut_off_time.unit,
1464
+ item._productOrigin.cut_off_time.unit_type
1465
+ );
1411
1466
  if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
1412
1467
  maxCutOffTimeValue = currentCutOffTime;
1413
1468
  maxCutOffTime = item._productOrigin.cut_off_time;
@@ -1599,7 +1654,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1599
1654
  date
1600
1655
  );
1601
1656
  const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
1602
- console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
1603
1657
  let allProductResources = productResources.flatMap((n) => n.renderList);
1604
1658
  allProductResources.sort((a, b) => {
1605
1659
  var _a2, _b2, _c2, _d;
@@ -1645,7 +1699,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1645
1699
  }
1646
1700
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1647
1701
  });
1648
- if (!currentResourcesTimeSlotCanUsedArr.some((n) => n === false) && currentResourcesCount >= count) {
1702
+ if (!currentResourcesTimeSlotCanUsedArr.some(
1703
+ (n) => n === false
1704
+ ) && currentResourcesCount >= count) {
1649
1705
  count = currentResourcesCount;
1650
1706
  }
1651
1707
  });
@@ -1717,7 +1773,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1717
1773
  *
1718
1774
  * @param {string} cartItemId
1719
1775
  * @param {string} resourceCode
1720
- * @return {*}
1776
+ * @return {*}
1721
1777
  * @memberof BookingByStepImpl
1722
1778
  */
1723
1779
  getResourcesByCartItemAndCode(cartItemId, resourceCode) {
@@ -1768,7 +1824,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1768
1824
  selectedResources,
1769
1825
  currentCapacity
1770
1826
  );
1771
- const targetResource = productResources.find((resource) => resource.code === resourceCode);
1827
+ const targetResource = productResources.find(
1828
+ (resource) => resource.code === resourceCode
1829
+ );
1772
1830
  if (!targetResource)
1773
1831
  return [];
1774
1832
  if (cartItem._origin.start_time) {
@@ -1779,16 +1837,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1779
1837
  `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
1780
1838
  );
1781
1839
  const resourcesUseableMap = {};
1782
- targetResource.renderList = targetResource.renderList.sort((a, b) => {
1783
- var _a2, _b2, _c2, _d;
1784
- const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1785
- const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1786
- if (aIsCombined && !bIsCombined)
1787
- return 1;
1788
- if (!aIsCombined && bIsCombined)
1789
- return -1;
1790
- return 0;
1791
- });
1840
+ targetResource.renderList = targetResource.renderList.sort(
1841
+ (a, b) => {
1842
+ var _a2, _b2, _c2, _d;
1843
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1844
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1845
+ if (aIsCombined && !bIsCombined)
1846
+ return 1;
1847
+ if (!aIsCombined && bIsCombined)
1848
+ return -1;
1849
+ return 0;
1850
+ }
1851
+ );
1792
1852
  targetResource.renderList = targetResource.renderList.filter((m) => {
1793
1853
  const mTimes = m.times.filter((n) => {
1794
1854
  return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
@@ -1836,6 +1896,38 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1836
1896
  }
1837
1897
  return targetResource.renderList;
1838
1898
  }
1899
+ /**
1900
+ * 根据日期范围批量获取时间槽
1901
+ * @param params 参数对象
1902
+ * @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
1903
+ */
1904
+ async getTimeslotsScheduleByDateRange({
1905
+ startDate,
1906
+ endDate,
1907
+ scheduleIds,
1908
+ resources
1909
+ }) {
1910
+ console.log(
1911
+ "appoimentBooking-session-date-getTimeslotsScheduleByDateRange",
1912
+ { startDate, endDate, scheduleIds, resources }
1913
+ );
1914
+ const dates = [];
1915
+ let currentDate = (0, import_dayjs.default)(startDate);
1916
+ const end = (0, import_dayjs.default)(endDate);
1917
+ while (currentDate.isSameOrBefore(end)) {
1918
+ dates.push(currentDate.format("YYYY-MM-DD"));
1919
+ currentDate = currentDate.add(1, "day");
1920
+ }
1921
+ const results = {};
1922
+ for (const date of dates) {
1923
+ results[date] = this.getTimeslotBySchedule({
1924
+ date,
1925
+ scheduleIds,
1926
+ resources
1927
+ });
1928
+ }
1929
+ return results;
1930
+ }
1839
1931
  async getAvailableDateForSession(params = {}) {
1840
1932
  let { startDate, endDate, type } = params;
1841
1933
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
@@ -1862,7 +1954,165 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1862
1954
  rules,
1863
1955
  type
1864
1956
  });
1865
- return res;
1957
+ if (this.store.currentProduct) {
1958
+ const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
1959
+ startDate: startDate || "",
1960
+ endDate: endDate || ""
1961
+ });
1962
+ res.forEach((n) => {
1963
+ if (!dateListWithTimeSlots[n.date]) {
1964
+ n.status = "unavailable";
1965
+ } else {
1966
+ const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
1967
+ (d) => d.count
1968
+ );
1969
+ if (!allTimeSlotsCanUse) {
1970
+ n.status = "unavailable";
1971
+ }
1972
+ }
1973
+ });
1974
+ }
1975
+ const firstAvailableDate = res.find((n) => n.status === "available");
1976
+ return {
1977
+ dateList: res,
1978
+ firstAvailableDate
1979
+ };
1980
+ }
1981
+ async getAvailableDateForSessionOptimize(params = {}) {
1982
+ var _a, _b, _c, _d, _e, _f;
1983
+ const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
1984
+ if (cache) {
1985
+ if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
1986
+ return {
1987
+ dateList: cache.dateList,
1988
+ firstAvailableDate: cache.firstAvailableDate
1989
+ };
1990
+ }
1991
+ }
1992
+ let { startDate, endDate } = params;
1993
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
1994
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1995
+ }
1996
+ endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
1997
+ let tempProducts;
1998
+ tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
1999
+ const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
2000
+ const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2001
+ schedule,
2002
+ startDate || "",
2003
+ endDate || ""
2004
+ );
2005
+ const tempResourceIds = (0, import_resources.getResourcesIdsByProduct)(tempProducts);
2006
+ const res = await this.store.date.fetchResourceDates({
2007
+ query: {
2008
+ start_date: startDate || "",
2009
+ end_date: endDate || "",
2010
+ resource_ids: tempResourceIds
2011
+ }
2012
+ });
2013
+ let dates = [];
2014
+ let currentDate = (0, import_dayjs.default)(startDate);
2015
+ let firstAvailableDate = "";
2016
+ const openResources = ((_e = (_d = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.filter(
2017
+ (m) => m.status === 1
2018
+ )) || [];
2019
+ const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
2020
+ const targetSchedules = this.store.schedule.getScheduleListByIds(
2021
+ tempProducts["schedule.ids"]
2022
+ );
2023
+ while ((0, import_dayjs.default)(currentDate).isBefore((0, import_dayjs.default)(endDate), "day") || (0, import_dayjs.default)(currentDate).isSame((0, import_dayjs.default)(endDate), "day")) {
2024
+ const currentDateStr = currentDate.format("YYYY-MM-DD");
2025
+ let status = "available";
2026
+ const { latestStartDate, earliestEndDate } = (0, import_resources.checkSessionProductLeadTime)(tempProducts);
2027
+ if (latestStartDate || earliestEndDate) {
2028
+ if (latestStartDate && (0, import_dayjs.default)(currentDate).isBefore(latestStartDate, "day")) {
2029
+ status = "unavailable";
2030
+ }
2031
+ if (earliestEndDate && (0, import_dayjs.default)(currentDate).isAfter(earliestEndDate, "day")) {
2032
+ status = "unavailable";
2033
+ }
2034
+ }
2035
+ if (status === "available") {
2036
+ const scheduleByDate = filteredSchedule.find(
2037
+ (n) => n.date === currentDateStr
2038
+ );
2039
+ if (!scheduleByDate || (scheduleByDate == null ? void 0 : scheduleByDate.isExcluded)) {
2040
+ status = "unavailable";
2041
+ }
2042
+ }
2043
+ if (status === "available") {
2044
+ const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
2045
+ targetSchedules,
2046
+ {},
2047
+ currentDateStr
2048
+ );
2049
+ const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
2050
+ const timesSlotCanUse = scheduleTimeSlots.some((item) => {
2051
+ const resourcesUseableMap = {};
2052
+ return openResources.every((resource) => {
2053
+ const currentResourcesList = allProductResources.filter(
2054
+ (n) => n.form_id === resource.resource_type_id
2055
+ );
2056
+ return currentResourcesList == null ? void 0 : currentResourcesList.some((m) => {
2057
+ const mTimes = m.times.filter((n) => {
2058
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute");
2059
+ });
2060
+ if (mTimes.length === 0) {
2061
+ return;
2062
+ }
2063
+ const targetCanUseTimes = mTimes.some((childTiem) => {
2064
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
2065
+ timeSlice: {
2066
+ start_time: item.start,
2067
+ end_time: item.end,
2068
+ start_at: (0, import_dayjs.default)(item.start),
2069
+ end_at: (0, import_dayjs.default)(item.end)
2070
+ },
2071
+ time: childTiem,
2072
+ resource: m,
2073
+ currentCount: 1,
2074
+ resourcesUseableMap,
2075
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
2076
+ });
2077
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
2078
+ resourcesUseableMap[m.id] = res2.usable;
2079
+ }
2080
+ return res2.usable && !m.onlyComputed;
2081
+ });
2082
+ return targetCanUseTimes;
2083
+ });
2084
+ });
2085
+ });
2086
+ if (!timesSlotCanUse) {
2087
+ status = "unavailable";
2088
+ }
2089
+ if (status === "available" && !firstAvailableDate) {
2090
+ firstAvailableDate = currentDateStr;
2091
+ }
2092
+ }
2093
+ dates.push({
2094
+ date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
2095
+ week: (0, import_dayjs.default)(currentDate).format("ddd"),
2096
+ weekNum: (0, import_dayjs.default)(currentDate).day(),
2097
+ status
2098
+ });
2099
+ if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 14) {
2100
+ break;
2101
+ }
2102
+ currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
2103
+ }
2104
+ dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
2105
+ this.store.date.setDateList(dates);
2106
+ (_f = this.store.currentProduct) == null ? void 0 : _f.setOtherParams("timeSlotBySchedule", {
2107
+ dateList: dates,
2108
+ firstAvailableDate,
2109
+ startDate,
2110
+ endDate
2111
+ });
2112
+ return {
2113
+ dateList: dates,
2114
+ firstAvailableDate
2115
+ };
1866
2116
  }
1867
2117
  };
1868
2118
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,5 +1,5 @@
1
1
  import { Dayjs } from 'dayjs';
2
- import { CartItem } from '../../../modules';
2
+ import { CartItem, ProductData } from '../../../modules';
3
3
  /**
4
4
  * 1. 获取资源列表
5
5
  * 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
@@ -133,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
133
133
  * @return {*}
134
134
  * @Author: zhiwei.Wang
135
135
  */
136
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
136
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, }: {
137
137
  resourceIds: number[];
138
138
  resourcesMap: any;
139
139
  duration: number;
@@ -201,4 +201,41 @@ export declare const getSumCapacity: ({ capacity }: {
201
201
  * @Author: jinglin.tan
202
202
  */
203
203
  export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
204
+ /**
205
+ * @title: 根据日期范围过滤日程
206
+ *
207
+ * @export
208
+ * @param {any[]} schedule
209
+ * @param {string} startDate
210
+ * @param {string} endDate
211
+ * @return {*}
212
+ */
213
+ export declare function filterScheduleByDateRange(schedule: any[], startDate: string, endDate: string): any[];
214
+ /**
215
+ * 传入商品数据,返回基于商品配置的提前量的最早开始日期和最晚结束日期
216
+ *
217
+ * @export
218
+ * @param {ProductData} product
219
+ * @return {*}
220
+ */
221
+ export declare function checkSessionProductLeadTime(product: ProductData): {
222
+ latestStartDate: string;
223
+ earliestEndDate: string;
224
+ };
225
+ /**
226
+ * 基于商品的 resources 配置,返回可选择的资源的 id 列表
227
+ *
228
+ * @export
229
+ * @param {ProductData} product
230
+ * @return {*}
231
+ */
232
+ export declare function getResourcesIdsByProduct(product: ProductData): number[];
233
+ /**
234
+ * 资源排序,把单个资源靠前,组合资源排在后面
235
+ *
236
+ * @export
237
+ * @param {ResourceItem[]} resourcesList
238
+ * @return {*}
239
+ */
240
+ export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
204
241
  export {};
@@ -29,7 +29,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/solution/BookingByStep/utils/resources.ts
30
30
  var resources_exports = {};
31
31
  __export(resources_exports, {
32
+ checkSessionProductLeadTime: () => checkSessionProductLeadTime,
32
33
  checkSubResourcesCapacity: () => checkSubResourcesCapacity,
34
+ filterScheduleByDateRange: () => filterScheduleByDateRange,
33
35
  formatDefaultCapacitys: () => formatDefaultCapacitys,
34
36
  formatResources: () => formatResources,
35
37
  getIsUsableByTimeItem: () => getIsUsableByTimeItem,
@@ -37,11 +39,13 @@ __export(resources_exports, {
37
39
  getOthersSelectedResources: () => getOthersSelectedResources,
38
40
  getResourcesByIds: () => getResourcesByIds,
39
41
  getResourcesByProduct: () => getResourcesByProduct,
42
+ getResourcesIdsByProduct: () => getResourcesIdsByProduct,
40
43
  getSumCapacity: () => getSumCapacity,
41
44
  getTimeSlicesByResource: () => getTimeSlicesByResource,
42
45
  getTimeSlicesByResources: () => getTimeSlicesByResources,
43
46
  getTimesIntersection: () => getTimesIntersection,
44
- mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices
47
+ mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices,
48
+ sortCombinedResources: () => sortCombinedResources
45
49
  });
46
50
  module.exports = __toCommonJS(resources_exports);
47
51
  var import_dayjs = __toESM(require("dayjs"));
@@ -561,9 +565,74 @@ var checkSubResourcesCapacity = (resource) => {
561
565
  });
562
566
  }
563
567
  };
568
+ function filterScheduleByDateRange(schedule, startDate, endDate) {
569
+ if (!(schedule == null ? void 0 : schedule.length))
570
+ return [];
571
+ const start = new Date(startDate);
572
+ const end = new Date(endDate);
573
+ return schedule.filter((item) => {
574
+ const itemDate = new Date(item.date);
575
+ return itemDate >= start && itemDate <= end;
576
+ });
577
+ }
578
+ function checkSessionProductLeadTime(product) {
579
+ let latestStartDate = "";
580
+ let earliestEndDate = "";
581
+ const { future_day, unit, unit_type } = product.cut_off_time;
582
+ if (future_day) {
583
+ const endDate = (0, import_dayjs.default)().add(future_day, "day");
584
+ if (!earliestEndDate || endDate.isBefore((0, import_dayjs.default)(earliestEndDate), "day")) {
585
+ earliestEndDate = endDate.format("YYYY-MM-DD");
586
+ }
587
+ } else if (future_day === 0) {
588
+ const endDate = (0, import_dayjs.default)();
589
+ if (!earliestEndDate || endDate.isBefore((0, import_dayjs.default)(earliestEndDate), "day")) {
590
+ earliestEndDate = endDate.format("YYYY-MM-DD");
591
+ }
592
+ }
593
+ if (unit && unit_type) {
594
+ const startDate = (0, import_dayjs.default)(
595
+ (0, import_dayjs.default)().add(unit, unit_type).format("YYYY-MM-DD")
596
+ );
597
+ if (!latestStartDate || startDate.isAfter((0, import_dayjs.default)(latestStartDate), "day")) {
598
+ latestStartDate = startDate.format("YYYY-MM-DD");
599
+ }
600
+ }
601
+ return {
602
+ latestStartDate,
603
+ earliestEndDate
604
+ };
605
+ }
606
+ function getResourcesIdsByProduct(product) {
607
+ var _a, _b, _c;
608
+ const tempResourceIds = [];
609
+ (_c = (_b = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach) == null ? void 0 : _c.call(_b, (resource) => {
610
+ var _a2, _b2;
611
+ if ((resource == null ? void 0 : resource.status) == 1) {
612
+ if ((_a2 = resource == null ? void 0 : resource.default_resource) == null ? void 0 : _a2.length) {
613
+ tempResourceIds.push(...resource == null ? void 0 : resource.default_resource);
614
+ } else if ((_b2 = resource == null ? void 0 : resource.optional_resource) == null ? void 0 : _b2.length) {
615
+ tempResourceIds.push(...resource == null ? void 0 : resource.optional_resource);
616
+ }
617
+ }
618
+ });
619
+ return tempResourceIds;
620
+ }
621
+ function sortCombinedResources(resourcesList) {
622
+ const newResourcesList = [...resourcesList];
623
+ newResourcesList.sort((a, b) => {
624
+ var _a, _b, _c, _d;
625
+ const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
626
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
627
+ return aIsCombined === bIsCombined ? 0 : aIsCombined ? 1 : -1;
628
+ });
629
+ return newResourcesList;
630
+ }
564
631
  // Annotate the CommonJS export names for ESM import in node:
565
632
  0 && (module.exports = {
633
+ checkSessionProductLeadTime,
566
634
  checkSubResourcesCapacity,
635
+ filterScheduleByDateRange,
567
636
  formatDefaultCapacitys,
568
637
  formatResources,
569
638
  getIsUsableByTimeItem,
@@ -571,9 +640,11 @@ var checkSubResourcesCapacity = (resource) => {
571
640
  getOthersSelectedResources,
572
641
  getResourcesByIds,
573
642
  getResourcesByProduct,
643
+ getResourcesIdsByProduct,
574
644
  getSumCapacity,
575
645
  getTimeSlicesByResource,
576
646
  getTimeSlicesByResources,
577
647
  getTimesIntersection,
578
- mergeSubResourcesTimeSlices
648
+ mergeSubResourcesTimeSlices,
649
+ sortCombinedResources
579
650
  });