@pisell/pisellos 0.0.420 → 0.0.422

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.
@@ -330,7 +330,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
330
330
  count: number;
331
331
  left: number;
332
332
  summaryCount: number;
333
- status: keyof TimeStatusMap;
333
+ status: "lots_of_space" | "filling_up_fast" | "sold_out";
334
334
  }[];
335
335
  /**
336
336
  * 找到多个资源的公共可用时间段
@@ -395,9 +395,3 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
395
395
  */
396
396
  getContactInfo(params: any): Promise<any>;
397
397
  }
398
- interface TimeStatusMap {
399
- lots_of_space: true;
400
- filling_up_fast: true;
401
- sold_out: true;
402
- }
403
- export {};
@@ -2694,7 +2694,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2694
2694
  value: function getTimeslotBySchedule(_ref11) {
2695
2695
  var _this$store$currentPr2,
2696
2696
  _targetProductData$pr,
2697
- _targetProductData$pr2,
2698
2697
  _this15 = this;
2699
2698
  var date = _ref11.date,
2700
2699
  scheduleIds = _ref11.scheduleIds,
@@ -2733,29 +2732,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2733
2732
  if (!aIsCombined && bIsCombined) return -1;
2734
2733
  return 0;
2735
2734
  });
2736
-
2737
- // 找到当前商品下第一个启用的资源id
2738
- 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) {
2735
+ var enabledResourceTypeConfigs = (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 ? void 0 : _targetProductData$pr.filter(function (n) {
2739
2736
  return n.status === 1;
2740
- })) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.id;
2741
- 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) {
2742
- return n.status === 1 && n.id === firstEnabledResourceId;
2743
- });
2744
- var isMultipleBooking = (firstEnabledResourceConfig === null || firstEnabledResourceConfig === void 0 ? void 0 : firstEnabledResourceConfig.type) === 'multiple';
2737
+ })) || [];
2738
+ var resourceTypeConfigById = new Map(enabledResourceTypeConfigs.map(function (n) {
2739
+ return [n.id, n];
2740
+ }));
2741
+
2745
2742
  // 计算每个日程切片下日程可用的资源的容量总和
2746
2743
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2747
2744
  // 用来计算资源的可使用情况,针对单个schedule 时间片
2748
2745
  var resourcesUseableMap = {};
2749
- var count = 0;
2750
- var bookingLeft = 0;
2751
- var summaryCount = 0;
2752
- var summaryConfigCount = 0;
2746
+ var statsByResourceType = {};
2747
+ enabledResourceTypeConfigs.forEach(function (cfg) {
2748
+ statsByResourceType[cfg.id] = {
2749
+ count: 0,
2750
+ left: 0,
2751
+ summaryCount: 0,
2752
+ summaryConfigCount: 0
2753
+ };
2754
+ });
2755
+
2753
2756
  // 遍历所有资源
2754
2757
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
2758
+ var currentResourceTypeConfig = resourceTypeConfigById.get(m.form_id);
2759
+ if (!currentResourceTypeConfig) return;
2760
+
2755
2761
  // 遍历所有资源的上工时间片
2756
- var currentResourcesCount = 0;
2757
- var currentResourcesSummaryCount = 0;
2758
- var currentResourcesTimeSlotCanUsedArr = [];
2762
+ var currentResourceMaxRemainingCapacity = 0;
2763
+ var isAllTimeSlicesUsable = true;
2759
2764
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2760
2765
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2761
2766
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -2772,6 +2777,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2772
2777
  if (mTimes.length === 0) {
2773
2778
  return;
2774
2779
  }
2780
+
2781
+ // 统计该资源类型在这个时间片的“配置容量”(无占用),只统计上工的资源
2782
+ if (!m.onlyComputed) {
2783
+ var _currentStats = statsByResourceType[m.form_id] || {
2784
+ count: 0,
2785
+ left: 0,
2786
+ summaryCount: 0,
2787
+ summaryConfigCount: 0
2788
+ };
2789
+ if (currentResourceTypeConfig.type === 'multiple') _currentStats.summaryConfigCount += m.capacity;else _currentStats.summaryConfigCount += 1;
2790
+ statsByResourceType[m.form_id] = _currentStats;
2791
+ }
2775
2792
  mTimes.forEach(function (childTiem) {
2776
2793
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
2777
2794
  var res = getIsUsableByTimeItem({
@@ -2790,40 +2807,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2790
2807
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2791
2808
  resourcesUseableMap[m.id] = res.usable;
2792
2809
  }
2793
- if (res.usable && res.remainingCapacity >= count && !m.onlyComputed) {
2794
- currentResourcesCount = res.remainingCapacity;
2810
+ if (!res.usable) isAllTimeSlicesUsable = false;
2811
+ if (res.usable && !m.onlyComputed) {
2812
+ if (res.remainingCapacity > currentResourceMaxRemainingCapacity) currentResourceMaxRemainingCapacity = res.remainingCapacity;
2795
2813
  }
2796
- if (res.usable && !m.onlyComputed && res.remainingCapacity >= currentResourcesSummaryCount) {
2797
- currentResourcesSummaryCount = res.remainingCapacity;
2798
- }
2799
- currentResourcesTimeSlotCanUsedArr.push(res.usable);
2800
2814
  });
2801
- if (m.form_id === firstEnabledResourceId) {
2802
- // 确认当前资源是单个预约还是多个预约,单个预约则只需要计数,多个预约才添加容量
2803
- if (isMultipleBooking) {
2804
- summaryConfigCount += m.capacity;
2805
- } else {
2806
- summaryConfigCount += 1;
2807
- }
2808
- }
2809
- // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2810
- if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2811
- return n === false;
2812
- }) &&
2813
- // 只统计第一种资源的容量和 left
2814
- m.form_id === firstEnabledResourceId) {
2815
- if (currentResourcesCount >= count) {
2816
- count = currentResourcesCount;
2817
- }
2818
- if (!m.onlyComputed) {
2819
- bookingLeft += 1;
2820
- summaryCount += currentResourcesSummaryCount;
2821
- }
2815
+ if (!isAllTimeSlicesUsable) return;
2816
+ if (m.onlyComputed) return;
2817
+ var currentStats = statsByResourceType[m.form_id] || {
2818
+ count: 0,
2819
+ left: 0,
2820
+ summaryCount: 0,
2821
+ summaryConfigCount: 0
2822
+ };
2823
+ currentStats.left += 1;
2824
+ if (currentResourceTypeConfig.type === 'multiple') {
2825
+ currentStats.summaryCount += currentResourceMaxRemainingCapacity;
2826
+ if (currentResourceMaxRemainingCapacity > currentStats.count) currentStats.count = currentResourceMaxRemainingCapacity;
2827
+ } else {
2828
+ // 单个预约:一个资源只计 1,不关心剩余容量
2829
+ currentStats.summaryCount += 1;
2830
+ if (currentStats.count < 1) currentStats.count = 1;
2822
2831
  }
2832
+ statsByResourceType[m.form_id] = currentStats;
2823
2833
  });
2824
2834
  // 容量检测
2825
2835
  var cartItems = _this15.store.cart.getItems();
2826
2836
  productResources.forEach(function (n) {
2837
+ var currentResourceTypeConfig = resourceTypeConfigById.get(n.id);
2838
+ if (!currentResourceTypeConfig) return;
2839
+ var currentStats = statsByResourceType[n.id] || {
2840
+ count: 0,
2841
+ left: 0,
2842
+ summaryCount: 0
2843
+ };
2844
+
2827
2845
  // 单个预约检测规则:
2828
2846
  // 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
2829
2847
  // 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
@@ -2834,10 +2852,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2834
2852
  var _m$_productOrigin, _targetProductData$id;
2835
2853
  return ((_m$_productOrigin = m._productOrigin) === null || _m$_productOrigin === void 0 || (_m$_productOrigin = _m$_productOrigin.id) === null || _m$_productOrigin === void 0 ? void 0 : _m$_productOrigin.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id = targetProductData.id) === null || _targetProductData$id === void 0 ? void 0 : _targetProductData$id.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2836
2854
  });
2837
- if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
2838
- bookingLeft = 0;
2839
- count = 0;
2840
- summaryCount = 0;
2855
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > currentStats.left) {
2856
+ currentStats.left = 0;
2857
+ currentStats.count = 0;
2858
+ currentStats.summaryCount = 0;
2841
2859
  }
2842
2860
  // 规则 2
2843
2861
  var otherCartItems = cartItems.filter(function (m) {
@@ -2874,9 +2892,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2874
2892
  }
2875
2893
  });
2876
2894
  if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
2877
- bookingLeft = 0;
2878
- count = 0;
2879
- summaryCount = 0;
2895
+ currentStats.left = 0;
2896
+ currentStats.count = 0;
2897
+ currentStats.summaryCount = 0;
2880
2898
  }
2881
2899
  } else {
2882
2900
  // 多个预约的检测规则:
@@ -2892,9 +2910,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2892
2910
  return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
2893
2911
  }, 0);
2894
2912
  if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2895
- bookingLeft = 0;
2896
- count = 0;
2897
- summaryCount = 0;
2913
+ currentStats.left = 0;
2914
+ currentStats.count = 0;
2915
+ currentStats.summaryCount = 0;
2898
2916
  }
2899
2917
  // 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
2900
2918
  // const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
@@ -2956,45 +2974,61 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2956
2974
  }, 0);
2957
2975
  // 如果已使用容量超过了当前类型资源的容量,则不可用
2958
2976
  if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2959
- bookingLeft = 0;
2960
- count = 0;
2961
- summaryCount = 0;
2977
+ currentStats.left = 0;
2978
+ currentStats.count = 0;
2979
+ currentStats.summaryCount = 0;
2962
2980
  }
2963
2981
  }
2982
+ statsByResourceType[n.id] = currentStats;
2964
2983
  });
2965
2984
  var startDayJs = dayjs(item.start);
2966
2985
  var endDayJs = dayjs(item.end);
2967
2986
 
2968
- // 状态
2969
- // 如果是isMultipleBooking
2970
- // lots_of_space: summaryCount / summaryConfigCount > 0.5
2971
- // filling_up_fast: summaryCount / summaryConfigCount <= 0.5 && summaryCount > 0
2972
- // sold_out: bookingLeft = 0
2973
- // 如果不是isMultipleBooking
2974
- // lots_of_space: bookingLeft / summaryConfigCount > 0.5
2975
- // filling_up_fast: bookingLeft / summaryConfigCount <= 0.5 && count > 0
2976
- // sold_out: bookingLeft = 0
2977
- var timeStatus = 'sold_out';
2978
- if (bookingLeft === 0) timeStatus = 'sold_out';else if (isMultipleBooking) {
2979
- if (summaryConfigCount === 0) timeStatus = 'sold_out';else {
2980
- var usageRatio = summaryCount / summaryConfigCount;
2981
- if (usageRatio > 0.5) timeStatus = 'lots_of_space';else if (summaryCount > 0) timeStatus = 'filling_up_fast';else timeStatus = 'sold_out';
2987
+ // 选择“瓶颈资源类型”:multiple 取 summaryCount 最小,single 取 left 最小
2988
+ var bottleneckResourceTypeId;
2989
+ var bottleneckValue = Infinity;
2990
+ enabledResourceTypeConfigs.forEach(function (cfg) {
2991
+ var stats = statsByResourceType[cfg.id] || {
2992
+ count: 0,
2993
+ left: 0,
2994
+ summaryCount: 0,
2995
+ summaryConfigCount: 0
2996
+ };
2997
+ var value = cfg.type === 'multiple' ? stats.summaryCount : stats.left;
2998
+ if (value < bottleneckValue) {
2999
+ bottleneckValue = value;
3000
+ bottleneckResourceTypeId = cfg.id;
2982
3001
  }
3002
+ });
3003
+ var bottleneckStats = bottleneckResourceTypeId !== undefined ? statsByResourceType[bottleneckResourceTypeId] || {
3004
+ count: 0,
3005
+ left: 0,
3006
+ summaryCount: 0,
3007
+ summaryConfigCount: 0
3008
+ } : {
3009
+ count: 0,
3010
+ left: 0,
3011
+ summaryCount: 0,
3012
+ summaryConfigCount: 0
3013
+ };
3014
+ var bottleneckConfig = bottleneckResourceTypeId !== undefined ? resourceTypeConfigById.get(bottleneckResourceTypeId) : undefined;
3015
+ var status = 'sold_out';
3016
+ if (bottleneckStats.left === 0) status = 'sold_out';else if (!bottleneckConfig || bottleneckStats.summaryConfigCount === 0) status = 'sold_out';else if (bottleneckConfig.type === 'multiple') {
3017
+ var usageRatio = bottleneckStats.summaryCount / bottleneckStats.summaryConfigCount;
3018
+ if (usageRatio > 0.5) status = 'lots_of_space';else if (bottleneckStats.summaryCount > 0) status = 'filling_up_fast';else status = 'sold_out';
2983
3019
  } else {
2984
- if (summaryConfigCount === 0) timeStatus = 'sold_out';else {
2985
- var _usageRatio = bookingLeft / summaryConfigCount;
2986
- if (_usageRatio > 0.5) timeStatus = 'lots_of_space';else if (count > 0) timeStatus = 'filling_up_fast';else timeStatus = 'sold_out';
2987
- }
3020
+ var _usageRatio = bottleneckStats.left / bottleneckStats.summaryConfigCount;
3021
+ if (_usageRatio > 0.5) status = 'lots_of_space';else if (bottleneckStats.count > 0) status = 'filling_up_fast';else status = 'sold_out';
2988
3022
  }
2989
3023
  return {
2990
3024
  start_time: startDayJs.format('HH:mm'),
2991
3025
  end_time: endDayJs.format('HH:mm'),
2992
3026
  start_at: startDayJs,
2993
3027
  end_at: endDayJs,
2994
- count: count,
2995
- left: bookingLeft,
2996
- summaryCount: summaryCount,
2997
- status: timeStatus
3028
+ count: bottleneckStats.count,
3029
+ left: bottleneckStats.left,
3030
+ summaryCount: bottleneckStats.summaryCount,
3031
+ status: status
2998
3032
  };
2999
3033
  });
3000
3034
  return formatScheduleTimeSlots;
@@ -4299,7 +4333,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4299
4333
 
4300
4334
  if (status === 'unavailable') {
4301
4335
  // dateStatus = 'unavailable'
4302
- if (summaryCount === 0) dateStatus = 'sold_out';else dateStatus = 'unavailable';
4336
+ if (availableCount === 0 && summaryCount > 0) dateStatus = 'sold_out';else dateStatus = 'unavailable';
4303
4337
  } else {
4304
4338
  usageRatio = availableCount / summaryCount;
4305
4339
  if (usageRatio > 0.5) dateStatus = 'lots_of_space';else dateStatus = 'filling_up_fast';
@@ -105,7 +105,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
105
105
  const filteredOldDiscountList = oldDiscountList.filter(
106
106
  (discount) => !discount.isEditMode && (discount.tag !== "good_pass" || discount.isScan)
107
107
  );
108
- const mergedDiscountList = (0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]);
108
+ const mergedDiscountList = (0, import_utils.uniqueById)([
109
+ ...filteredOldDiscountList,
110
+ ...newDiscountList
111
+ ]);
109
112
  const result = this.calcDiscount(
110
113
  {
111
114
  discountList: mergedDiscountList,
@@ -330,7 +330,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
330
330
  count: number;
331
331
  left: number;
332
332
  summaryCount: number;
333
- status: keyof TimeStatusMap;
333
+ status: "lots_of_space" | "filling_up_fast" | "sold_out";
334
334
  }[];
335
335
  /**
336
336
  * 找到多个资源的公共可用时间段
@@ -395,9 +395,3 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
395
395
  */
396
396
  getContactInfo(params: any): Promise<any>;
397
397
  }
398
- interface TimeStatusMap {
399
- lots_of_space: true;
400
- filling_up_fast: true;
401
- sold_out: true;
402
- }
403
- export {};
@@ -1883,7 +1883,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1883
1883
  resources,
1884
1884
  product
1885
1885
  }) {
1886
- var _a, _b, _c, _d, _e, _f, _g;
1886
+ var _a, _b, _c, _d;
1887
1887
  const targetProduct = this.store.currentProduct;
1888
1888
  const targetProductData = product || targetProduct;
1889
1889
  let targetSchedules = [];
@@ -1926,29 +1926,48 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1926
1926
  return -1;
1927
1927
  return 0;
1928
1928
  });
1929
- const firstEnabledResourceId = (_e = (_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
1929
+ const enabledResourceTypeConfigs = ((_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.filter(
1930
1930
  (n) => n.status === 1
1931
- )) == null ? void 0 : _e.id;
1932
- const firstEnabledResourceConfig = (_g = (_f = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _f.resources) == null ? void 0 : _g.find(
1933
- (n) => n.status === 1 && n.id === firstEnabledResourceId
1931
+ )) || [];
1932
+ const resourceTypeConfigById = new Map(
1933
+ enabledResourceTypeConfigs.map((n) => [n.id, n])
1934
1934
  );
1935
- const isMultipleBooking = (firstEnabledResourceConfig == null ? void 0 : firstEnabledResourceConfig.type) === "multiple";
1936
1935
  const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
1937
1936
  const resourcesUseableMap = {};
1938
- let count = 0;
1939
- let bookingLeft = 0;
1940
- let summaryCount = 0;
1941
- let summaryConfigCount = 0;
1937
+ const statsByResourceType = {};
1938
+ enabledResourceTypeConfigs.forEach((cfg) => {
1939
+ statsByResourceType[cfg.id] = {
1940
+ count: 0,
1941
+ left: 0,
1942
+ summaryCount: 0,
1943
+ summaryConfigCount: 0
1944
+ };
1945
+ });
1942
1946
  allProductResources == null ? void 0 : allProductResources.forEach((m) => {
1943
- let currentResourcesCount = 0;
1944
- let currentResourcesSummaryCount = 0;
1945
- const currentResourcesTimeSlotCanUsedArr = [];
1947
+ const currentResourceTypeConfig = resourceTypeConfigById.get(m.form_id);
1948
+ if (!currentResourceTypeConfig)
1949
+ return;
1950
+ let currentResourceMaxRemainingCapacity = 0;
1951
+ let isAllTimeSlicesUsable = true;
1946
1952
  const mTimes = m.times.filter((n) => {
1947
1953
  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") || m.onlyComputed && (0, import_dayjs.default)(n.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1948
1954
  });
1949
1955
  if (mTimes.length === 0) {
1950
1956
  return;
1951
1957
  }
1958
+ if (!m.onlyComputed) {
1959
+ const currentStats2 = statsByResourceType[m.form_id] || {
1960
+ count: 0,
1961
+ left: 0,
1962
+ summaryCount: 0,
1963
+ summaryConfigCount: 0
1964
+ };
1965
+ if (currentResourceTypeConfig.type === "multiple")
1966
+ currentStats2.summaryConfigCount += m.capacity;
1967
+ else
1968
+ currentStats2.summaryConfigCount += 1;
1969
+ statsByResourceType[m.form_id] = currentStats2;
1970
+ }
1952
1971
  mTimes.forEach((childTiem) => {
1953
1972
  const res = (0, import_resources.getIsUsableByTimeItem)({
1954
1973
  timeSlice: {
@@ -1966,52 +1985,61 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1966
1985
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
1967
1986
  resourcesUseableMap[m.id] = res.usable;
1968
1987
  }
1969
- if (res.usable && res.remainingCapacity >= count && !m.onlyComputed) {
1970
- currentResourcesCount = res.remainingCapacity;
1971
- }
1972
- if (res.usable && !m.onlyComputed && res.remainingCapacity >= currentResourcesSummaryCount) {
1973
- currentResourcesSummaryCount = res.remainingCapacity;
1988
+ if (!res.usable)
1989
+ isAllTimeSlicesUsable = false;
1990
+ if (res.usable && !m.onlyComputed) {
1991
+ if (res.remainingCapacity > currentResourceMaxRemainingCapacity)
1992
+ currentResourceMaxRemainingCapacity = res.remainingCapacity;
1974
1993
  }
1975
- currentResourcesTimeSlotCanUsedArr.push(res.usable);
1976
1994
  });
1977
- if (m.form_id === firstEnabledResourceId) {
1978
- if (isMultipleBooking) {
1979
- summaryConfigCount += m.capacity;
1980
- } else {
1981
- summaryConfigCount += 1;
1982
- }
1983
- }
1984
- if (!currentResourcesTimeSlotCanUsedArr.some(
1985
- (n) => n === false
1986
- ) && // 只统计第一种资源的容量和 left
1987
- m.form_id === firstEnabledResourceId) {
1988
- if (currentResourcesCount >= count) {
1989
- count = currentResourcesCount;
1990
- }
1991
- if (!m.onlyComputed) {
1992
- bookingLeft += 1;
1993
- summaryCount += currentResourcesSummaryCount;
1994
- }
1995
+ if (!isAllTimeSlicesUsable)
1996
+ return;
1997
+ if (m.onlyComputed)
1998
+ return;
1999
+ const currentStats = statsByResourceType[m.form_id] || {
2000
+ count: 0,
2001
+ left: 0,
2002
+ summaryCount: 0,
2003
+ summaryConfigCount: 0
2004
+ };
2005
+ currentStats.left += 1;
2006
+ if (currentResourceTypeConfig.type === "multiple") {
2007
+ currentStats.summaryCount += currentResourceMaxRemainingCapacity;
2008
+ if (currentResourceMaxRemainingCapacity > currentStats.count)
2009
+ currentStats.count = currentResourceMaxRemainingCapacity;
2010
+ } else {
2011
+ currentStats.summaryCount += 1;
2012
+ if (currentStats.count < 1)
2013
+ currentStats.count = 1;
1995
2014
  }
2015
+ statsByResourceType[m.form_id] = currentStats;
1996
2016
  });
1997
2017
  const cartItems2 = this.store.cart.getItems();
1998
2018
  productResources.forEach((n) => {
2019
+ const currentResourceTypeConfig = resourceTypeConfigById.get(n.id);
2020
+ if (!currentResourceTypeConfig)
2021
+ return;
2022
+ const currentStats = statsByResourceType[n.id] || {
2023
+ count: 0,
2024
+ left: 0,
2025
+ summaryCount: 0
2026
+ };
1999
2027
  if (n.type === "single") {
2000
2028
  const currentResourcesSet = /* @__PURE__ */ new Set([...n.optional_resource, ...n.default_resource]);
2001
2029
  const sameCartItems = cartItems2.filter((m) => {
2002
2030
  var _a2, _b2, _c2;
2003
2031
  return ((_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;
2004
2032
  });
2005
- if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
2006
- bookingLeft = 0;
2007
- count = 0;
2008
- summaryCount = 0;
2033
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > currentStats.left) {
2034
+ currentStats.left = 0;
2035
+ currentStats.count = 0;
2036
+ currentStats.summaryCount = 0;
2009
2037
  }
2010
2038
  let otherCartItems = cartItems2.filter(
2011
2039
  (m) => {
2012
- var _a2, _b2, _c2, _d2, _e2, _f2;
2040
+ var _a2, _b2, _c2, _d2, _e, _f;
2013
2041
  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;
2014
- 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);
2042
+ const isResourceMatch = (_f = (_e = (_d2 = m._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e.resources) == null ? void 0 : _f.find((m2) => m2.type === n.type && m2.status === 1);
2015
2043
  return isTimeMatch && isResourceMatch;
2016
2044
  }
2017
2045
  );
@@ -2033,9 +2061,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2033
2061
  }
2034
2062
  });
2035
2063
  if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
2036
- bookingLeft = 0;
2037
- count = 0;
2038
- summaryCount = 0;
2064
+ currentStats.left = 0;
2065
+ currentStats.count = 0;
2066
+ currentStats.summaryCount = 0;
2039
2067
  }
2040
2068
  } else {
2041
2069
  const sameCartItems = cartItems2.filter((m) => {
@@ -2045,9 +2073,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2045
2073
  const sameCartNeedCapacity = sameCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
2046
2074
  const currentProductResourcesCapacity = n.renderList.reduce((acc, curr) => !curr.onlyComputed ? acc + curr.capacity || 0 : acc, 0);
2047
2075
  if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2048
- bookingLeft = 0;
2049
- count = 0;
2050
- summaryCount = 0;
2076
+ currentStats.left = 0;
2077
+ currentStats.count = 0;
2078
+ currentStats.summaryCount = 0;
2051
2079
  }
2052
2080
  const otherSameTimesCartItems = cartItems2.filter((m) => `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
2053
2081
  const otherCartNeedCapacity = otherSameTimesCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
@@ -2090,51 +2118,68 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2090
2118
  return acc;
2091
2119
  }, 0);
2092
2120
  if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2093
- bookingLeft = 0;
2094
- count = 0;
2095
- summaryCount = 0;
2121
+ currentStats.left = 0;
2122
+ currentStats.count = 0;
2123
+ currentStats.summaryCount = 0;
2096
2124
  }
2097
2125
  }
2126
+ statsByResourceType[n.id] = currentStats;
2098
2127
  });
2099
2128
  const startDayJs = (0, import_dayjs.default)(item.start);
2100
2129
  const endDayJs = (0, import_dayjs.default)(item.end);
2101
- let timeStatus = "sold_out";
2102
- if (bookingLeft === 0)
2103
- timeStatus = "sold_out";
2104
- else if (isMultipleBooking) {
2105
- if (summaryConfigCount === 0)
2106
- timeStatus = "sold_out";
2107
- else {
2108
- const usageRatio = summaryCount / summaryConfigCount;
2109
- if (usageRatio > 0.5)
2110
- timeStatus = "lots_of_space";
2111
- else if (summaryCount > 0)
2112
- timeStatus = "filling_up_fast";
2113
- else
2114
- timeStatus = "sold_out";
2130
+ let bottleneckResourceTypeId;
2131
+ let bottleneckValue = Infinity;
2132
+ enabledResourceTypeConfigs.forEach((cfg) => {
2133
+ const stats = statsByResourceType[cfg.id] || {
2134
+ count: 0,
2135
+ left: 0,
2136
+ summaryCount: 0,
2137
+ summaryConfigCount: 0
2138
+ };
2139
+ const value = cfg.type === "multiple" ? stats.summaryCount : stats.left;
2140
+ if (value < bottleneckValue) {
2141
+ bottleneckValue = value;
2142
+ bottleneckResourceTypeId = cfg.id;
2115
2143
  }
2144
+ });
2145
+ const bottleneckStats = bottleneckResourceTypeId !== void 0 ? statsByResourceType[bottleneckResourceTypeId] || {
2146
+ count: 0,
2147
+ left: 0,
2148
+ summaryCount: 0,
2149
+ summaryConfigCount: 0
2150
+ } : { count: 0, left: 0, summaryCount: 0, summaryConfigCount: 0 };
2151
+ const bottleneckConfig = bottleneckResourceTypeId !== void 0 ? resourceTypeConfigById.get(bottleneckResourceTypeId) : void 0;
2152
+ let status = "sold_out";
2153
+ if (bottleneckStats.left === 0)
2154
+ status = "sold_out";
2155
+ else if (!bottleneckConfig || bottleneckStats.summaryConfigCount === 0)
2156
+ status = "sold_out";
2157
+ else if (bottleneckConfig.type === "multiple") {
2158
+ const usageRatio = bottleneckStats.summaryCount / bottleneckStats.summaryConfigCount;
2159
+ if (usageRatio > 0.5)
2160
+ status = "lots_of_space";
2161
+ else if (bottleneckStats.summaryCount > 0)
2162
+ status = "filling_up_fast";
2163
+ else
2164
+ status = "sold_out";
2116
2165
  } else {
2117
- if (summaryConfigCount === 0)
2118
- timeStatus = "sold_out";
2119
- else {
2120
- const usageRatio = bookingLeft / summaryConfigCount;
2121
- if (usageRatio > 0.5)
2122
- timeStatus = "lots_of_space";
2123
- else if (count > 0)
2124
- timeStatus = "filling_up_fast";
2125
- else
2126
- timeStatus = "sold_out";
2127
- }
2166
+ const usageRatio = bottleneckStats.left / bottleneckStats.summaryConfigCount;
2167
+ if (usageRatio > 0.5)
2168
+ status = "lots_of_space";
2169
+ else if (bottleneckStats.count > 0)
2170
+ status = "filling_up_fast";
2171
+ else
2172
+ status = "sold_out";
2128
2173
  }
2129
2174
  return {
2130
2175
  start_time: startDayJs.format("HH:mm"),
2131
2176
  end_time: endDayJs.format("HH:mm"),
2132
2177
  start_at: startDayJs,
2133
2178
  end_at: endDayJs,
2134
- count,
2135
- left: bookingLeft,
2136
- summaryCount,
2137
- status: timeStatus
2179
+ count: bottleneckStats.count,
2180
+ left: bottleneckStats.left,
2181
+ summaryCount: bottleneckStats.summaryCount,
2182
+ status
2138
2183
  };
2139
2184
  });
2140
2185
  return formatScheduleTimeSlots;
@@ -2999,7 +3044,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2999
3044
  }
3000
3045
  let dateStatus;
3001
3046
  if (status === "unavailable") {
3002
- if (summaryCount === 0)
3047
+ if (availableCount === 0 && summaryCount > 0)
3003
3048
  dateStatus = "sold_out";
3004
3049
  else
3005
3050
  dateStatus = "unavailable";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.420",
4
+ "version": "0.0.422",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",