@pisell/pisellos 1.0.112 → 1.0.113

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.
@@ -20,7 +20,9 @@ export interface ITime {
20
20
  date: string;
21
21
  week: string;
22
22
  weekNum: number;
23
- status: 'unavailable' | 'available';
23
+ status: 'unavailable' | 'available' | 'lots_of_space' | 'filling_up_fast' | 'sold_out';
24
+ summaryCount?: number;
25
+ availableCount?: number;
24
26
  resource?: any[];
25
27
  color?: string[];
26
28
  }
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -110,7 +110,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
110
110
  if (!product.isNeedHolder) return true;
111
111
  // 商品需要holder,但父预约及商品都无holder,返回false
112
112
  if (!orderHolderId && !productHolderId) return false;
113
-
114
113
  // 最终直接匹配 holder 是否相同
115
114
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
116
115
  }
@@ -767,7 +766,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
767
766
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
768
767
  // 是符合折扣的商品
769
768
  var isLimitedProduct = (limitedData.type === 'product_all' && limitedData.filter !== 1 || limitedData.type === 'product_all' && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
770
-
771
769
  // 编辑的商品 使用了优惠券不可用
772
770
  var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
773
771
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
@@ -327,6 +327,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
327
327
  count: number;
328
328
  left: number;
329
329
  summaryCount: number;
330
+ status: keyof TimeStatusMap;
330
331
  }[];
331
332
  /**
332
333
  * 找到多个资源的公共可用时间段
@@ -391,3 +392,9 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
391
392
  */
392
393
  getContactInfo(params: any): Promise<any>;
393
394
  }
395
+ interface TimeStatusMap {
396
+ lots_of_space: true;
397
+ filling_up_fast: true;
398
+ sold_out: true;
399
+ }
400
+ export {};
@@ -2674,6 +2674,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2674
2674
  value: function getTimeslotBySchedule(_ref11) {
2675
2675
  var _this$store$currentPr2,
2676
2676
  _targetProductData$pr,
2677
+ _targetProductData$pr2,
2677
2678
  _this15 = this;
2678
2679
  var date = _ref11.date,
2679
2680
  scheduleIds = _ref11.scheduleIds,
@@ -2717,7 +2718,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2717
2718
  var firstEnabledResourceId = targetProductData === null || targetProductData === void 0 || (_targetProductData$pr = targetProductData.product_resource) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.resources) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.find(function (n) {
2718
2719
  return n.status === 1;
2719
2720
  })) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.id;
2720
-
2721
+ var firstEnabledResourceConfig = targetProductData === null || targetProductData === void 0 || (_targetProductData$pr2 = targetProductData.product_resource) === null || _targetProductData$pr2 === void 0 || (_targetProductData$pr2 = _targetProductData$pr2.resources) === null || _targetProductData$pr2 === void 0 ? void 0 : _targetProductData$pr2.find(function (n) {
2722
+ return n.status === 1 && n.id === firstEnabledResourceId;
2723
+ });
2724
+ var isMultipleBooking = (firstEnabledResourceConfig === null || firstEnabledResourceConfig === void 0 ? void 0 : firstEnabledResourceConfig.type) === 'multiple';
2721
2725
  // 计算每个日程切片下日程可用的资源的容量总和
2722
2726
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2723
2727
  // 用来计算资源的可使用情况,针对单个schedule 时间片
@@ -2725,6 +2729,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2725
2729
  var count = 0;
2726
2730
  var bookingLeft = 0;
2727
2731
  var summaryCount = 0;
2732
+ var summaryConfigCount = 0;
2728
2733
  // 遍历所有资源
2729
2734
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
2730
2735
  // 遍历所有资源的上工时间片
@@ -2772,6 +2777,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2772
2777
  }
2773
2778
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
2774
2779
  });
2780
+ if (m.form_id === firstEnabledResourceId) {
2781
+ // 确认当前资源是单个预约还是多个预约,单个预约则只需要计数,多个预约才添加容量
2782
+ if (isMultipleBooking) {
2783
+ summaryConfigCount += m.capacity;
2784
+ } else {
2785
+ summaryConfigCount += 1;
2786
+ }
2787
+ }
2775
2788
  // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2776
2789
  if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2777
2790
  return n === false;
@@ -2910,7 +2923,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2910
2923
  start_at: dayjs(item.start),
2911
2924
  end_at: dayjs(item.end)
2912
2925
  })) {
2913
- mSet.set(m.id, m.pax || 1);
2926
+ var _m$pax;
2927
+ mSet.set(m.id, (_m$pax = m.pax) !== null && _m$pax !== void 0 ? _m$pax : 1);
2914
2928
  }
2915
2929
  });
2916
2930
  });
@@ -2929,6 +2943,28 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2929
2943
  });
2930
2944
  var startDayJs = dayjs(item.start);
2931
2945
  var endDayJs = dayjs(item.end);
2946
+
2947
+ // 状态
2948
+ // 如果是isMultipleBooking
2949
+ // lots_of_space: summaryCount / summaryConfigCount > 0.5
2950
+ // filling_up_fast: summaryCount / summaryConfigCount <= 0.5 && summaryCount > 0
2951
+ // sold_out: bookingLeft = 0
2952
+ // 如果不是isMultipleBooking
2953
+ // lots_of_space: bookingLeft / summaryConfigCount > 0.5
2954
+ // filling_up_fast: bookingLeft / summaryConfigCount <= 0.5 && count > 0
2955
+ // sold_out: bookingLeft = 0
2956
+ var timeStatus = 'sold_out';
2957
+ if (bookingLeft === 0) timeStatus = 'sold_out';else if (isMultipleBooking) {
2958
+ if (summaryConfigCount === 0) timeStatus = 'sold_out';else {
2959
+ var usageRatio = summaryCount / summaryConfigCount;
2960
+ if (usageRatio > 0.5) timeStatus = 'lots_of_space';else if (summaryCount > 0) timeStatus = 'filling_up_fast';else timeStatus = 'sold_out';
2961
+ }
2962
+ } else {
2963
+ if (summaryConfigCount === 0) timeStatus = 'sold_out';else {
2964
+ var _usageRatio = bookingLeft / summaryConfigCount;
2965
+ if (_usageRatio > 0.5) timeStatus = 'lots_of_space';else if (count > 0) timeStatus = 'filling_up_fast';else timeStatus = 'sold_out';
2966
+ }
2967
+ }
2932
2968
  return {
2933
2969
  start_time: startDayJs.format('HH:mm'),
2934
2970
  end_time: endDayJs.format('HH:mm'),
@@ -2936,7 +2972,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2936
2972
  end_at: endDayJs,
2937
2973
  count: count,
2938
2974
  left: bookingLeft,
2939
- summaryCount: summaryCount
2975
+ summaryCount: summaryCount,
2976
+ status: timeStatus
2940
2977
  };
2941
2978
  });
2942
2979
  return formatScheduleTimeSlots;
@@ -4121,12 +4158,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4121
4158
  });
4122
4159
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
4123
4160
  _loop8 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop8() {
4124
- var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
4161
+ var currentDateStr, status, summaryCount, availableCount, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse, dateStatus, usageRatio;
4125
4162
  return _regeneratorRuntime().wrap(function _loop8$(_context29) {
4126
4163
  while (1) switch (_context29.prev = _context29.next) {
4127
4164
  case 0:
4128
4165
  currentDateStr = currentDate.format('YYYY-MM-DD');
4129
- status = 'available'; // 1. 检查商品的提前量等情况是否满足
4166
+ status = 'available';
4167
+ summaryCount = 0;
4168
+ availableCount = 0; // 1. 检查商品的提前量等情况是否满足
4130
4169
  _checkSessionProductL = checkSessionProductLeadTime(tempProducts), latestStartDate = _checkSessionProductL.latestStartDate, earliestEndDate = _checkSessionProductL.earliestEndDate;
4131
4170
  if (latestStartDate || earliestEndDate) {
4132
4171
  // 如果时间在最早开始时间之前,则设置为不可用
@@ -4152,17 +4191,25 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4152
4191
  if (status === 'available') {
4153
4192
  minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, currentDateStr);
4154
4193
  scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime); // 同一天内多个时间片下 只要有一个可用则视为可用
4155
- timesSlotCanUse = scheduleTimeSlots.some(function (item) {
4194
+ timesSlotCanUse = false;
4195
+ scheduleTimeSlots.forEach(function (item) {
4156
4196
  // 用来计算资源的可使用情况,针对单个schedule 时间片
4157
4197
  var resourcesUseableMap = {};
4158
4198
  // 遍历产品下启用的资源
4159
4199
  // 必须要保证每种类型的资源都至少有一个能够在对应时间点被选择
4160
- return openResources.every(function (resource) {
4200
+ // 求出第一个资源的剩余量和总量
4201
+ // 剩余量=每个资源在每个时间片内剩余之和
4202
+ // 总量=每个资源在每个时间片内资源总量之和
4203
+ var isAllResourceTypesUseable = true;
4204
+ openResources.forEach(function (resource) {
4205
+ // if (!isAllResourceTypesUseable) return;
4206
+
4161
4207
  // 获取当前资源类型的资源列表
4162
4208
  var currentResourcesList = allProductResources.filter(function (n) {
4163
4209
  return n.form_id === resource.resource_type_id;
4164
4210
  });
4165
- return currentResourcesList === null || currentResourcesList === void 0 ? void 0 : currentResourcesList.some(function (m) {
4211
+ var isAnyResourceUseableInType = false;
4212
+ currentResourcesList === null || currentResourcesList === void 0 || currentResourcesList.forEach(function (m) {
4166
4213
  // 遍历所有资源的上工时间片
4167
4214
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
4168
4215
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
@@ -4170,12 +4217,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4170
4217
  var mTimes = m.times.filter(function (n) {
4171
4218
  return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
4172
4219
  });
4220
+
4173
4221
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
4174
- if (mTimes.length === 0) {
4175
- return;
4222
+ if (mTimes.length === 0) return;
4223
+ // 如果资源可用则把他的容量纳入总计
4224
+ if (resource.type === 'multiple') {
4225
+ summaryCount += m.capacity;
4226
+ } else {
4227
+ summaryCount += 1;
4176
4228
  }
4177
- var targetCanUseTimes = mTimes.some(function (childTiem) {
4229
+ var isAnyTimeSliceUseable = false;
4230
+ mTimes.forEach(function (childTiem) {
4178
4231
  var _tempProducts3;
4232
+ if (isAnyTimeSliceUseable) return;
4233
+
4179
4234
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
4180
4235
  var res = getIsUsableByTimeItem({
4181
4236
  timeSlice: {
@@ -4193,11 +4248,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4193
4248
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
4194
4249
  resourcesUseableMap[m.id] = res.usable;
4195
4250
  }
4196
- return res.usable && !m.onlyComputed;
4251
+ if (res.usable && !m.onlyComputed) {
4252
+ isAnyTimeSliceUseable = true;
4253
+ if (resource.type === 'multiple') {
4254
+ availableCount += res.remainingCapacity;
4255
+ } else {
4256
+ availableCount += 1;
4257
+ }
4258
+ }
4259
+ ;
4197
4260
  });
4198
- return targetCanUseTimes;
4261
+ if (isAnyTimeSliceUseable) isAnyResourceUseableInType = true;
4199
4262
  });
4263
+ if (!isAnyResourceUseableInType) isAllResourceTypesUseable = false;
4200
4264
  });
4265
+ if (isAllResourceTypesUseable) timesSlotCanUse = true;
4201
4266
  });
4202
4267
  if (!timesSlotCanUse) {
4203
4268
  status = 'unavailable';
@@ -4206,22 +4271,36 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4206
4271
  firstAvailableDate = currentDateStr;
4207
4272
  }
4208
4273
  }
4274
+ // 状态: lots_of_space: availableCount / summaryCount > 0.5
4275
+ // filling_up_fast: availableCount / summaryCount <= 0.5 && availableCount > 0
4276
+ // sold_out: summaryCount = 0
4277
+ // unavailable: summaryCount > 0 && availableCount = 0
4278
+
4279
+ if (status === 'unavailable') {
4280
+ // dateStatus = 'unavailable'
4281
+ if (availableCount === 0 && summaryCount > 0) dateStatus = 'sold_out';else dateStatus = 'unavailable';
4282
+ } else {
4283
+ usageRatio = availableCount / summaryCount;
4284
+ if (usageRatio > 0.5) dateStatus = 'lots_of_space';else dateStatus = 'filling_up_fast';
4285
+ }
4209
4286
  dates.push({
4210
4287
  date: dayjs(currentDate).format('YYYY-MM-DD'),
4211
4288
  week: dayjs(currentDate).format('ddd'),
4212
4289
  weekNum: dayjs(currentDate).day(),
4213
- status: status
4290
+ summaryCount: summaryCount,
4291
+ availableCount: availableCount,
4292
+ status: dateStatus
4214
4293
  });
4215
4294
 
4216
4295
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
4217
4296
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
4218
- _context29.next = 9;
4297
+ _context29.next = 12;
4219
4298
  break;
4220
4299
  }
4221
4300
  return _context29.abrupt("return", 1);
4222
- case 9:
4301
+ case 12:
4223
4302
  currentDate = dayjs(currentDate).add(1, 'day');
4224
- case 10:
4303
+ case 13:
4225
4304
  case "end":
4226
4305
  return _context29.stop();
4227
4306
  }
@@ -20,7 +20,9 @@ export interface ITime {
20
20
  date: string;
21
21
  week: string;
22
22
  weekNum: number;
23
- status: 'unavailable' | 'available';
23
+ status: 'unavailable' | 'available' | 'lots_of_space' | 'filling_up_fast' | 'sold_out';
24
+ summaryCount?: number;
25
+ availableCount?: number;
24
26
  resource?: any[];
25
27
  color?: string[];
26
28
  }
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -327,6 +327,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
327
327
  count: number;
328
328
  left: number;
329
329
  summaryCount: number;
330
+ status: keyof TimeStatusMap;
330
331
  }[];
331
332
  /**
332
333
  * 找到多个资源的公共可用时间段
@@ -391,3 +392,9 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
391
392
  */
392
393
  getContactInfo(params: any): Promise<any>;
393
394
  }
395
+ interface TimeStatusMap {
396
+ lots_of_space: true;
397
+ filling_up_fast: true;
398
+ sold_out: true;
399
+ }
400
+ export {};
@@ -1865,7 +1865,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1865
1865
  resources,
1866
1866
  product
1867
1867
  }) {
1868
- var _a, _b, _c, _d, _e;
1868
+ var _a, _b, _c, _d, _e, _f, _g;
1869
1869
  const targetProduct = this.store.currentProduct;
1870
1870
  const targetProductData = product || targetProduct;
1871
1871
  let targetSchedules = [];
@@ -1911,11 +1911,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1911
1911
  const firstEnabledResourceId = (_e = (_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1912
1912
  (n) => n.status === 1
1913
1913
  )) == null ? void 0 : _e.id;
1914
+ const firstEnabledResourceConfig = (_g = (_f = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _f.resources) == null ? void 0 : _g.find(
1915
+ (n) => n.status === 1 && n.id === firstEnabledResourceId
1916
+ );
1917
+ const isMultipleBooking = (firstEnabledResourceConfig == null ? void 0 : firstEnabledResourceConfig.type) === "multiple";
1914
1918
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1915
1919
  const resourcesUseableMap = {};
1916
1920
  let count = 0;
1917
1921
  let bookingLeft = 0;
1918
1922
  let summaryCount = 0;
1923
+ let summaryConfigCount = 0;
1919
1924
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1920
1925
  let currentResourcesCount = 0;
1921
1926
  let currentResourcesSummaryCount = 0;
@@ -1951,6 +1956,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1951
1956
  }
1952
1957
  currentResourcesTimeSlotCanUsedArr.push(res.usable);
1953
1958
  });
1959
+ if (m.form_id === firstEnabledResourceId) {
1960
+ if (isMultipleBooking) {
1961
+ summaryConfigCount += m.capacity;
1962
+ } else {
1963
+ summaryConfigCount += 1;
1964
+ }
1965
+ }
1954
1966
  if (!currentResourcesTimeSlotCanUsedArr.some(
1955
1967
  (n) => n === false
1956
1968
  ) && // 只统计第一种资源的容量和 left
@@ -1979,9 +1991,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1979
1991
  }
1980
1992
  let otherCartItems = cartItems2.filter(
1981
1993
  (m) => {
1982
- var _a2, _b2, _c2, _d2, _e2, _f;
1994
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1983
1995
  const isTimeMatch = ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) !== ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
1984
- const isResourceMatch = (_f = (_e2 = (_d2 = m._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f.find((m2) => m2.type === n.type && m2.status === 1);
1996
+ const isResourceMatch = (_f2 = (_e2 = (_d2 = m._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find((m2) => m2.type === n.type && m2.status === 1);
1985
1997
  return isTimeMatch && isResourceMatch;
1986
1998
  }
1987
1999
  );
@@ -2052,7 +2064,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2052
2064
  { start_at: m.start_at, end_at: m.end_at },
2053
2065
  { start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
2054
2066
  )) {
2055
- mSet.set(m.id, m.pax || 1);
2067
+ mSet.set(m.id, m.pax ?? 1);
2056
2068
  }
2057
2069
  });
2058
2070
  });
@@ -2068,6 +2080,34 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2068
2080
  });
2069
2081
  const startDayJs = (0, import_dayjs.default)(item.start);
2070
2082
  const endDayJs = (0, import_dayjs.default)(item.end);
2083
+ let timeStatus = "sold_out";
2084
+ if (bookingLeft === 0)
2085
+ timeStatus = "sold_out";
2086
+ else if (isMultipleBooking) {
2087
+ if (summaryConfigCount === 0)
2088
+ timeStatus = "sold_out";
2089
+ else {
2090
+ const usageRatio = summaryCount / summaryConfigCount;
2091
+ if (usageRatio > 0.5)
2092
+ timeStatus = "lots_of_space";
2093
+ else if (summaryCount > 0)
2094
+ timeStatus = "filling_up_fast";
2095
+ else
2096
+ timeStatus = "sold_out";
2097
+ }
2098
+ } else {
2099
+ if (summaryConfigCount === 0)
2100
+ timeStatus = "sold_out";
2101
+ else {
2102
+ const usageRatio = bookingLeft / summaryConfigCount;
2103
+ if (usageRatio > 0.5)
2104
+ timeStatus = "lots_of_space";
2105
+ else if (count > 0)
2106
+ timeStatus = "filling_up_fast";
2107
+ else
2108
+ timeStatus = "sold_out";
2109
+ }
2110
+ }
2071
2111
  return {
2072
2112
  start_time: startDayJs.format("HH:mm"),
2073
2113
  end_time: endDayJs.format("HH:mm"),
@@ -2075,7 +2115,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2075
2115
  end_at: endDayJs,
2076
2116
  count,
2077
2117
  left: bookingLeft,
2078
- summaryCount
2118
+ summaryCount,
2119
+ status: timeStatus
2079
2120
  };
2080
2121
  });
2081
2122
  return formatScheduleTimeSlots;
@@ -2846,6 +2887,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2846
2887
  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")) {
2847
2888
  const currentDateStr = currentDate.format("YYYY-MM-DD");
2848
2889
  let status = "available";
2890
+ let summaryCount = 0;
2891
+ let availableCount = 0;
2849
2892
  const { latestStartDate, earliestEndDate } = (0, import_resources.checkSessionProductLeadTime)(tempProducts);
2850
2893
  if (latestStartDate || earliestEndDate) {
2851
2894
  if (latestStartDate && (0, import_dayjs.default)(currentDate).isBefore(latestStartDate, "day")) {
@@ -2870,43 +2913,64 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2870
2913
  currentDateStr
2871
2914
  );
2872
2915
  const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
2873
- const timesSlotCanUse = scheduleTimeSlots.some((item) => {
2916
+ let timesSlotCanUse = false;
2917
+ scheduleTimeSlots.forEach((item) => {
2874
2918
  const resourcesUseableMap = {};
2875
- return openResources.every((resource) => {
2919
+ let isAllResourceTypesUseable = true;
2920
+ openResources.forEach((resource) => {
2876
2921
  const currentResourcesList = allProductResources.filter(
2877
2922
  (n) => n.form_id === resource.resource_type_id
2878
2923
  );
2879
- return currentResourcesList == null ? void 0 : currentResourcesList.some((m) => {
2924
+ let isAnyResourceUseableInType = false;
2925
+ currentResourcesList == null ? void 0 : currentResourcesList.forEach((m) => {
2880
2926
  const mTimes = m.times.filter((n) => {
2881
2927
  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");
2882
2928
  });
2883
- if (mTimes.length === 0) {
2929
+ if (mTimes.length === 0)
2884
2930
  return;
2931
+ if (resource.type === "multiple") {
2932
+ summaryCount += m.capacity;
2933
+ } else {
2934
+ summaryCount += 1;
2885
2935
  }
2886
- const targetCanUseTimes = mTimes.some(
2887
- (childTiem) => {
2888
- const res2 = (0, import_resources.getIsUsableByTimeItem)({
2889
- timeSlice: {
2890
- start_time: item.start,
2891
- end_time: item.end,
2892
- start_at: (0, import_dayjs.default)(item.start),
2893
- end_at: (0, import_dayjs.default)(item.end)
2894
- },
2895
- time: childTiem,
2896
- resource: m,
2897
- currentCount: 1,
2898
- resourcesUseableMap,
2899
- cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
2900
- });
2901
- if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
2902
- resourcesUseableMap[m.id] = res2.usable;
2936
+ let isAnyTimeSliceUseable = false;
2937
+ mTimes.forEach((childTiem) => {
2938
+ if (isAnyTimeSliceUseable)
2939
+ return;
2940
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
2941
+ timeSlice: {
2942
+ start_time: item.start,
2943
+ end_time: item.end,
2944
+ start_at: (0, import_dayjs.default)(item.start),
2945
+ end_at: (0, import_dayjs.default)(item.end)
2946
+ },
2947
+ time: childTiem,
2948
+ resource: m,
2949
+ currentCount: 1,
2950
+ resourcesUseableMap,
2951
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
2952
+ });
2953
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
2954
+ resourcesUseableMap[m.id] = res2.usable;
2955
+ }
2956
+ if (res2.usable && !m.onlyComputed) {
2957
+ isAnyTimeSliceUseable = true;
2958
+ if (resource.type === "multiple") {
2959
+ availableCount += res2.remainingCapacity;
2960
+ } else {
2961
+ availableCount += 1;
2903
2962
  }
2904
- return res2.usable && !m.onlyComputed;
2905
2963
  }
2906
- );
2907
- return targetCanUseTimes;
2964
+ ;
2965
+ });
2966
+ if (isAnyTimeSliceUseable)
2967
+ isAnyResourceUseableInType = true;
2908
2968
  });
2969
+ if (!isAnyResourceUseableInType)
2970
+ isAllResourceTypesUseable = false;
2909
2971
  });
2972
+ if (isAllResourceTypesUseable)
2973
+ timesSlotCanUse = true;
2910
2974
  });
2911
2975
  if (!timesSlotCanUse) {
2912
2976
  status = "unavailable";
@@ -2915,11 +2979,26 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2915
2979
  firstAvailableDate = currentDateStr;
2916
2980
  }
2917
2981
  }
2982
+ let dateStatus;
2983
+ if (status === "unavailable") {
2984
+ if (availableCount === 0 && summaryCount > 0)
2985
+ dateStatus = "sold_out";
2986
+ else
2987
+ dateStatus = "unavailable";
2988
+ } else {
2989
+ const usageRatio = availableCount / summaryCount;
2990
+ if (usageRatio > 0.5)
2991
+ dateStatus = "lots_of_space";
2992
+ else
2993
+ dateStatus = "filling_up_fast";
2994
+ }
2918
2995
  dates.push({
2919
2996
  date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
2920
2997
  week: (0, import_dayjs.default)(currentDate).format("ddd"),
2921
2998
  weekNum: (0, import_dayjs.default)(currentDate).day(),
2922
- status
2999
+ summaryCount,
3000
+ availableCount,
3001
+ status: dateStatus
2923
3002
  });
2924
3003
  if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 31) {
2925
3004
  break;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.112",
4
+ "version": "1.0.113",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",