@pisell/pisellos 3.0.84 → 3.0.86

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.
@@ -134,7 +134,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
134
134
  if (productList.every(function (item) {
135
135
  var _product$discount_lis;
136
136
  var product = _this2.hooks.getProduct(item);
137
- return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || (newDiscountList[0].tag === 'good_pass' ? product.price == 0 : product.total == 0));
137
+ return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || product.total == 0);
138
138
  })) {
139
139
  return {
140
140
  isAvailable: false,
@@ -1779,7 +1779,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1779
1779
  }
1780
1780
  // 计算在时间片内有交集的预约容量总和
1781
1781
  var totalCapacity = (countMap[n.id] || []).reduce(function (sum, item) {
1782
- var hasOverlap = !dayjs(item.time.start_at).isAfter(dayjs(timeSlots.start_at)) && !dayjs(item.time.end_at).isBefore(dayjs(timeSlots.end_at));
1782
+ var hasOverlap = dayjs(item.time.start_at).isBefore(dayjs(timeSlots.end_at)) && dayjs(item.time.end_at).isAfter(dayjs(timeSlots.start_at));
1783
1783
  return hasOverlap ? sum + item.pax : sum;
1784
1784
  }, 0);
1785
1785
 
@@ -1886,8 +1886,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1886
1886
  cartItems.forEach(function (item, index) {
1887
1887
  var _getCapacityInfoByCar6 = getCapacityInfoByCartItem(item),
1888
1888
  currentCapacity = _getCapacityInfoByCar6.currentCapacity;
1889
+ var hasOriginTimeSlot = Boolean(item._origin.start_time) && Boolean(item._origin.end_time) && !(timeSlots !== null && timeSlots !== void 0 && timeSlots.start_time);
1889
1890
  // 如果商品已经有时间数据了,意味着是通过先选日期再选商品流程进来的,相当于时间切片已经选中了
1890
- if (item._origin.start_time && !(timeSlots !== null && timeSlots !== void 0 && timeSlots.start_time)) {
1891
+ if (hasOriginTimeSlot) {
1891
1892
  recordTimeSlots = {
1892
1893
  start_time: item._origin.start_time,
1893
1894
  end_time: item._origin.end_time,
@@ -1903,10 +1904,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1903
1904
  return n.code === resources_code;
1904
1905
  });
1905
1906
  // 只有 duration 类商品且不含有灵活时间的商品需要这个操作
1906
- if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin3 = item._productOrigin) !== null && _item$_productOrigin3 !== void 0 && _item$_productOrigin3.duration && !hasFlexibleProduct) {
1907
- var _item$_productOrigin4, _item$_productOrigin5;
1908
- var start_at = dayjs(recordTimeSlots.end_time).add(((_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) || 10, 'minutes');
1909
- var end_at = start_at.add(((_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.duration) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.value) || 10, 'minutes');
1907
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig === null || currentResourceConfig === void 0 ? void 0 : currentResourceConfig.type) === 'single' && (_item$_productOrigin3 = item._productOrigin) !== null && _item$_productOrigin3 !== void 0 && _item$_productOrigin3.duration && !hasFlexibleProduct && !hasOriginTimeSlot) {
1908
+ var _item$_productOrigin4;
1909
+ var recordEndAt = recordTimeSlots.end_at ? dayjs(recordTimeSlots.end_at) : dayjs("".concat(item.start_date, " ").concat(recordTimeSlots.end_time));
1910
+ var start_at = recordEndAt;
1911
+ var end_at = start_at.add(((_item$_productOrigin4 = item._productOrigin) === null || _item$_productOrigin4 === void 0 || (_item$_productOrigin4 = _item$_productOrigin4.duration) === null || _item$_productOrigin4 === void 0 ? void 0 : _item$_productOrigin4.value) || 10, 'minutes');
1910
1912
  recordTimeSlots = {
1911
1913
  start_time: start_at.format('HH:mm'),
1912
1914
  end_time: end_at.format('HH:mm'),
@@ -1950,13 +1952,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1950
1952
  errorList.push(item._id);
1951
1953
  }
1952
1954
  } else {
1953
- var _item$_productOrigin6, _productResources$fin;
1955
+ var _item$_productOrigin5, _productResources$fin;
1954
1956
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1955
1957
  // 能进到这种逻辑,说明是 duration 类商品或者灵活时长商品,且是第一种资源,还没有确定时间
1956
1958
  var allCartItems = cloneDeep(_this11.store.cart.getItems());
1957
1959
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1958
1960
  var selectedResources = [];
1959
- var _resources = cloneDeep(((_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.product_resource) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.resources) || []);
1961
+ var _resources = cloneDeep(((_item$_productOrigin5 = item._productOrigin) === null || _item$_productOrigin5 === void 0 || (_item$_productOrigin5 = _item$_productOrigin5.product_resource) === null || _item$_productOrigin5 === void 0 ? void 0 : _item$_productOrigin5.resources) || []);
1960
1962
  var currentResourcesRenderList = [];
1961
1963
  _resources.forEach(function (n) {
1962
1964
  var _n$renderList;
@@ -1996,7 +1998,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1996
1998
  return n.code === resources_code;
1997
1999
  })) === null || _productResources$fin === void 0 ? void 0 : _productResources$fin.renderList;
1998
2000
  if (targetRenderList && targetRenderList.length > 0) {
1999
- var _item$_origin$resourc2;
2001
+ var _item$_origin$resourc2, _dateRange$5, _item$duration2, _item$_productOrigin6;
2000
2002
  // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
2001
2003
  if ((_item$_origin$resourc2 = item._origin.resources) !== null && _item$_origin$resourc2 !== void 0 && _item$_origin$resourc2.some(function (n) {
2002
2004
  return n.form_id === targetRenderList[0].form_id;
@@ -2006,7 +2008,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2006
2008
  var fastestResource = findFastestAvailableResource({
2007
2009
  resources: targetRenderList,
2008
2010
  currentCapacity: currentCapacity,
2009
- countMap: selectResourcesMap
2011
+ countMap: selectResourcesMap,
2012
+ targetDate: dateRange === null || dateRange === void 0 || (_dateRange$5 = dateRange[0]) === null || _dateRange$5 === void 0 ? void 0 : _dateRange$5.date,
2013
+ durationMinutes: (item === null || item === void 0 || (_item$duration2 = item.duration) === null || _item$duration2 === void 0 ? void 0 : _item$duration2.value) || (item === null || item === void 0 || (_item$_productOrigin6 = item._productOrigin) === null || _item$_productOrigin6 === void 0 || (_item$_productOrigin6 = _item$_productOrigin6.duration) === null || _item$_productOrigin6 === void 0 ? void 0 : _item$_productOrigin6.value) || 10
2010
2014
  });
2011
2015
  var targetResource = fastestResource || targetRenderList[0];
2012
2016
  targetResource.capacity = currentCapacity;
@@ -19,10 +19,12 @@ export declare function calculateResourceAvailableTime({ resource, timeSlots, cu
19
19
  * @param countMap 已预约数量映射
20
20
  * @returns 最快可用的资源
21
21
  */
22
- export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
22
+ export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, targetDate, durationMinutes, }: {
23
23
  resources: ResourceItem[];
24
24
  currentCapacity?: number;
25
25
  countMap?: Record<number, number>;
26
+ targetDate?: string | Dayjs;
27
+ durationMinutes?: number;
26
28
  }): ResourceItem | null;
27
29
  /**
28
30
  * 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
@@ -91,8 +91,14 @@ export function findFastestAvailableResource(_ref2) {
91
91
  _ref2$currentCapacity = _ref2.currentCapacity,
92
92
  currentCapacity = _ref2$currentCapacity === void 0 ? 1 : _ref2$currentCapacity,
93
93
  _ref2$countMap = _ref2.countMap,
94
- countMap = _ref2$countMap === void 0 ? {} : _ref2$countMap;
94
+ countMap = _ref2$countMap === void 0 ? {} : _ref2$countMap,
95
+ targetDate = _ref2.targetDate,
96
+ _ref2$durationMinutes = _ref2.durationMinutes,
97
+ durationMinutes = _ref2$durationMinutes === void 0 ? 30 : _ref2$durationMinutes;
95
98
  var currentTime = dayjs();
99
+ var resolvedDuration = durationMinutes > 0 ? durationMinutes : 30;
100
+ var targetDay = targetDate ? dayjs(targetDate) : currentTime;
101
+ var isTargetDayToday = targetDay.isSame(currentTime, 'day');
96
102
  var fastestTime = null;
97
103
  var fastestResources = [];
98
104
  console.log('[TimeslotUtils] 查找最快可用资源:', {
@@ -108,17 +114,18 @@ export function findFastestAvailableResource(_ref2) {
108
114
  try {
109
115
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
110
116
  var _resource = _step2.value;
111
- // 获取资源当天且还在工作时间内的时间段
112
- var todayTimes = _resource.times.filter(function (time) {
113
- var isToday = dayjs(time.start_at).isSame(currentTime, 'day');
114
- var isStillWorking = dayjs(time.end_at).isAfter(currentTime);
115
- return isToday && isStillWorking;
117
+ // 获取资源在目标日期且还在工作时间内的时间段
118
+ var targetDayTimes = _resource.times.filter(function (time) {
119
+ var isSameTargetDay = dayjs(time.start_at).isSame(targetDay, 'day');
120
+ if (!isSameTargetDay) return false;
121
+ if (!isTargetDayToday) return true;
122
+ return dayjs(time.end_at).isAfter(currentTime);
116
123
  });
117
- if (todayTimes.length === 0) {
124
+ if (targetDayTimes.length === 0) {
118
125
  console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, ") \u4ECA\u65E5\u65E0\u53EF\u7528\u65F6\u95F4\u6BB5"));
119
126
  continue;
120
127
  }
121
- var _iterator4 = _createForOfIteratorHelper(todayTimes),
128
+ var _iterator4 = _createForOfIteratorHelper(targetDayTimes),
122
129
  _step4;
123
130
  try {
124
131
  var _loop = function _loop() {
@@ -128,7 +135,7 @@ export function findFastestAvailableResource(_ref2) {
128
135
  var workEndTime = dayjs(time.end_at);
129
136
 
130
137
  // 确定检查的起始时间(当前时间 vs 工作开始时间)
131
- var nextAvailableTime = currentTime.isBefore(workStartTime) ? workStartTime : currentTime;
138
+ var nextAvailableTime = isTargetDayToday && currentTime.isAfter(workStartTime) ? currentTime : workStartTime;
132
139
  console.log("[TimeslotUtils] \u68C0\u67E5\u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, "):"), {
133
140
  workTime: "".concat(workStartTime.format('HH:mm'), "-").concat(workEndTime.format('HH:mm')),
134
141
  checkStartTime: nextAvailableTime.format('HH:mm:ss'),
@@ -165,7 +172,7 @@ export function findFastestAvailableResource(_ref2) {
165
172
  // 检查资源类型和容量
166
173
  if (_resource.resourceType === 'single' || (_resource.capacity || 1) === 1) {
167
174
  // 单人预约资源:检查时间冲突
168
- if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(30, 'minute'))) {
175
+ if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(resolvedDuration, 'minute'))) {
169
176
  // 有冲突,使用事件结束时间
170
177
  finalAvailableTime = _eventEnd;
171
178
  console.log("[TimeslotUtils] \u53D1\u73B0\u65F6\u95F4\u51B2\u7A81\uFF0C\u8C03\u6574\u5230: ".concat(finalAvailableTime.format('HH:mm:ss')));
@@ -177,7 +184,7 @@ export function findFastestAvailableResource(_ref2) {
177
184
  var eventUsedCapacity = _event.pax || 1;
178
185
 
179
186
  // 如果在事件时间范围内,检查容量是否足够
180
- if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(30, 'minute'))) {
187
+ if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(resolvedDuration, 'minute'))) {
181
188
  var totalRequiredCapacity = currentUsedCapacity + currentCapacity + eventUsedCapacity;
182
189
  if (totalRequiredCapacity > totalCapacity) {
183
190
  // 容量不足,使用事件结束时间
@@ -194,7 +201,7 @@ export function findFastestAvailableResource(_ref2) {
194
201
  } finally {
195
202
  _iterator5.f();
196
203
  }
197
- if (finalAvailableTime.isAfter(workEndTime)) {
204
+ if (finalAvailableTime.add(resolvedDuration, 'minute').isAfter(workEndTime)) {
198
205
  console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, " \u53EF\u7528\u65F6\u95F4\u8D85\u51FA\u5DE5\u4F5C\u65F6\u95F4\uFF0C\u8DF3\u8FC7"));
199
206
  return 0; // continue
200
207
  }
@@ -89,7 +89,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
89
89
  if (productList.every((item) => {
90
90
  var _a;
91
91
  const product = this.hooks.getProduct(item);
92
- return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || (newDiscountList[0].tag === "good_pass" ? product.price == 0 : product.total == 0));
92
+ return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || product.total == 0);
93
93
  })) {
94
94
  return {
95
95
  isAvailable: false,
@@ -1152,7 +1152,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1152
1152
  }
1153
1153
  const totalCapacity = (countMap[n.id] || []).reduce(
1154
1154
  (sum, item) => {
1155
- 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));
1155
+ const hasOverlap = (0, import_dayjs.default)(item.time.start_at).isBefore((0, import_dayjs.default)(timeSlots.end_at)) && (0, import_dayjs.default)(item.time.end_at).isAfter((0, import_dayjs.default)(timeSlots.start_at));
1156
1156
  return hasOverlap ? sum + item.pax : sum;
1157
1157
  },
1158
1158
  0
@@ -1234,9 +1234,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1234
1234
  }
1235
1235
  );
1236
1236
  cartItems2.forEach((item, index) => {
1237
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1237
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1238
1238
  const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
1239
- if (item._origin.start_time && !(timeSlots == null ? void 0 : timeSlots.start_time)) {
1239
+ const hasOriginTimeSlot = Boolean(item._origin.start_time) && Boolean(item._origin.end_time) && !(timeSlots == null ? void 0 : timeSlots.start_time);
1240
+ if (hasOriginTimeSlot) {
1240
1241
  recordTimeSlots = {
1241
1242
  start_time: item._origin.start_time,
1242
1243
  end_time: item._origin.end_time,
@@ -1248,13 +1249,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1248
1249
  const currentResourceConfig = (_c = (_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.find(
1249
1250
  (n) => n.code === resources_code
1250
1251
  );
1251
- if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct) {
1252
- let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
1253
- ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
1254
- "minutes"
1255
- );
1252
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct && !hasOriginTimeSlot) {
1253
+ const recordEndAt = recordTimeSlots.end_at ? (0, import_dayjs.default)(recordTimeSlots.end_at) : (0, import_dayjs.default)(`${item.start_date} ${recordTimeSlots.end_time}`);
1254
+ let start_at = recordEndAt;
1256
1255
  let end_at = start_at.add(
1257
- ((_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.value) || 10,
1256
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
1258
1257
  "minutes"
1259
1258
  );
1260
1259
  recordTimeSlots = {
@@ -1308,7 +1307,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1308
1307
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1309
1308
  let selectedResources = [];
1310
1309
  const resources2 = (0, import_lodash_es.cloneDeep)(
1311
- ((_j = (_i = item._productOrigin) == null ? void 0 : _i.product_resource) == null ? void 0 : _j.resources) || []
1310
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.product_resource) == null ? void 0 : _h.resources) || []
1312
1311
  );
1313
1312
  const currentResourcesRenderList = [];
1314
1313
  resources2.forEach((n) => {
@@ -1356,11 +1355,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1356
1355
  return recordCount >= currentCapacity;
1357
1356
  });
1358
1357
  });
1359
- const targetRenderList = (_k = productResources.find(
1358
+ const targetRenderList = (_i = productResources.find(
1360
1359
  (n) => n.code === resources_code
1361
- )) == null ? void 0 : _k.renderList;
1360
+ )) == null ? void 0 : _i.renderList;
1362
1361
  if (targetRenderList && targetRenderList.length > 0) {
1363
- if ((_l = item._origin.resources) == null ? void 0 : _l.some(
1362
+ if ((_j = item._origin.resources) == null ? void 0 : _j.some(
1364
1363
  (n) => n.form_id === targetRenderList[0].form_id
1365
1364
  )) {
1366
1365
  return;
@@ -1368,7 +1367,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1368
1367
  const fastestResource = (0, import_timeslots.findFastestAvailableResource)({
1369
1368
  resources: targetRenderList,
1370
1369
  currentCapacity,
1371
- countMap: selectResourcesMap
1370
+ countMap: selectResourcesMap,
1371
+ targetDate: (_k = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _k.date,
1372
+ durationMinutes: ((_l = item == null ? void 0 : item.duration) == null ? void 0 : _l.value) || ((_n = (_m = item == null ? void 0 : item._productOrigin) == null ? void 0 : _m.duration) == null ? void 0 : _n.value) || 10
1372
1373
  });
1373
1374
  const targetResource = fastestResource || targetRenderList[0];
1374
1375
  targetResource.capacity = currentCapacity;
@@ -19,10 +19,12 @@ export declare function calculateResourceAvailableTime({ resource, timeSlots, cu
19
19
  * @param countMap 已预约数量映射
20
20
  * @returns 最快可用的资源
21
21
  */
22
- export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
22
+ export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, targetDate, durationMinutes, }: {
23
23
  resources: ResourceItem[];
24
24
  currentCapacity?: number;
25
25
  countMap?: Record<number, number>;
26
+ targetDate?: string | Dayjs;
27
+ durationMinutes?: number;
26
28
  }): ResourceItem | null;
27
29
  /**
28
30
  * 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
@@ -77,10 +77,15 @@ function calculateResourceAvailableTime({
77
77
  function findFastestAvailableResource({
78
78
  resources,
79
79
  currentCapacity = 1,
80
- countMap = {}
80
+ countMap = {},
81
+ targetDate,
82
+ durationMinutes = 30
81
83
  }) {
82
84
  var _a, _b, _c;
83
85
  const currentTime = (0, import_dayjs.default)();
86
+ const resolvedDuration = durationMinutes > 0 ? durationMinutes : 30;
87
+ const targetDay = targetDate ? (0, import_dayjs.default)(targetDate) : currentTime;
88
+ const isTargetDayToday = targetDay.isSame(currentTime, "day");
84
89
  let fastestTime = null;
85
90
  let fastestResources = [];
86
91
  console.log("[TimeslotUtils] 查找最快可用资源:", {
@@ -90,19 +95,22 @@ function findFastestAvailableResource({
90
95
  countMap
91
96
  });
92
97
  for (const resource of resources) {
93
- const todayTimes = resource.times.filter((time) => {
94
- const isToday = (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
95
- const isStillWorking = (0, import_dayjs.default)(time.end_at).isAfter(currentTime);
96
- return isToday && isStillWorking;
98
+ const targetDayTimes = resource.times.filter((time) => {
99
+ const isSameTargetDay = (0, import_dayjs.default)(time.start_at).isSame(targetDay, "day");
100
+ if (!isSameTargetDay)
101
+ return false;
102
+ if (!isTargetDayToday)
103
+ return true;
104
+ return (0, import_dayjs.default)(time.end_at).isAfter(currentTime);
97
105
  });
98
- if (todayTimes.length === 0) {
106
+ if (targetDayTimes.length === 0) {
99
107
  console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}) 今日无可用时间段`);
100
108
  continue;
101
109
  }
102
- for (const time of todayTimes) {
110
+ for (const time of targetDayTimes) {
103
111
  const workStartTime = (0, import_dayjs.default)(time.start_at);
104
112
  const workEndTime = (0, import_dayjs.default)(time.end_at);
105
- let nextAvailableTime = currentTime.isBefore(workStartTime) ? workStartTime : currentTime;
113
+ let nextAvailableTime = isTargetDayToday && currentTime.isAfter(workStartTime) ? currentTime : workStartTime;
106
114
  console.log(`[TimeslotUtils] 检查资源 ${resource.id}(${resource.main_field}):`, {
107
115
  workTime: `${workStartTime.format("HH:mm")}-${workEndTime.format("HH:mm")}`,
108
116
  checkStartTime: nextAvailableTime.format("HH:mm:ss"),
@@ -126,7 +134,7 @@ function findFastestAvailableResource({
126
134
  pax: event.pax || 1
127
135
  });
128
136
  if (resource.resourceType === "single" || (resource.capacity || 1) === 1) {
129
- if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(30, "minute"))) {
137
+ if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(resolvedDuration, "minute"))) {
130
138
  finalAvailableTime = eventEnd;
131
139
  console.log(`[TimeslotUtils] 发现时间冲突,调整到: ${finalAvailableTime.format("HH:mm:ss")}`);
132
140
  }
@@ -134,7 +142,7 @@ function findFastestAvailableResource({
134
142
  const totalCapacity = resource.capacity || 0;
135
143
  const currentUsedCapacity = countMap[resource.id] || 0;
136
144
  const eventUsedCapacity = event.pax || 1;
137
- if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(30, "minute"))) {
145
+ if (finalAvailableTime.isBefore(eventEnd) && eventStart.isBefore(finalAvailableTime.add(resolvedDuration, "minute"))) {
138
146
  const totalRequiredCapacity = currentUsedCapacity + currentCapacity + eventUsedCapacity;
139
147
  if (totalRequiredCapacity > totalCapacity) {
140
148
  finalAvailableTime = eventEnd;
@@ -143,7 +151,7 @@ function findFastestAvailableResource({
143
151
  }
144
152
  }
145
153
  }
146
- if (finalAvailableTime.isAfter(workEndTime)) {
154
+ if (finalAvailableTime.add(resolvedDuration, "minute").isAfter(workEndTime)) {
147
155
  console.log(`[TimeslotUtils] 资源 ${resource.id} 可用时间超出工作时间,跳过`);
148
156
  continue;
149
157
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.84",
4
+ "version": "3.0.86",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",