@pisell/pisellos 0.0.421 → 0.0.423
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.
- package/dist/modules/Summary/utils.js +3 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -7
- package/dist/solution/BookingByStep/index.js +112 -78
- package/lib/modules/Rules/index.js +4 -1
- package/lib/modules/Summary/utils.js +3 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -7
- package/lib/solution/BookingByStep/index.js +126 -81
- package/package.json +1 -1
|
@@ -678,8 +678,10 @@ var getDiscountAmount = function getDiscountAmount(discounts) {
|
|
|
678
678
|
* 获取主商品加价减价后的总价 (主商品价格 + 子商品加价减价)
|
|
679
679
|
*/
|
|
680
680
|
var getMainProductTotal = function getMainProductTotal(item) {
|
|
681
|
-
var _ref7, _ref8, _item$main_product_se, _item$metadata;
|
|
681
|
+
var _ref7, _ref8, _item$main_product_se, _item$metadata, _item$_origin3, _item$_originData$pro;
|
|
682
682
|
var total = new Decimal((_ref7 = (_ref8 = (_item$main_product_se = item === null || item === void 0 ? void 0 : item.main_product_selling_price) !== null && _item$main_product_se !== void 0 ? _item$main_product_se : item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.main_product_selling_price) !== null && _ref8 !== void 0 ? _ref8 : item.price) !== null && _ref7 !== void 0 ? _ref7 : 0);
|
|
683
|
+
var mainProductDiscountAmount = getDiscountAmount((item === null || item === void 0 || (_item$_origin3 = item._origin) === null || _item$_origin3 === void 0 || (_item$_origin3 = _item$_origin3.product) === null || _item$_origin3 === void 0 ? void 0 : _item$_origin3.discount_list) || (item === null || item === void 0 || (_item$_originData$pro = item._originData.product) === null || _item$_originData$pro === void 0 ? void 0 : _item$_originData$pro.discount_list) || []);
|
|
684
|
+
total = total.minus(mainProductDiscountAmount);
|
|
683
685
|
|
|
684
686
|
// 单规格
|
|
685
687
|
if (item !== null && item !== void 0 && item.option && Array.isArray(item === null || item === void 0 ? void 0 : item.option)) {
|
|
@@ -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:
|
|
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
|
-
}))
|
|
2741
|
-
var
|
|
2742
|
-
return n.
|
|
2743
|
-
});
|
|
2744
|
-
|
|
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
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
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
|
|
2757
|
-
var
|
|
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
|
|
2794
|
-
|
|
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 (
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
if (
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
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 >
|
|
2838
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
if (
|
|
2980
|
-
|
|
2981
|
-
|
|
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
|
-
|
|
2985
|
-
|
|
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:
|
|
2996
|
-
summaryCount: summaryCount,
|
|
2997
|
-
status:
|
|
3028
|
+
count: bottleneckStats.count,
|
|
3029
|
+
left: bottleneckStats.left,
|
|
3030
|
+
summaryCount: bottleneckStats.summaryCount,
|
|
3031
|
+
status: status
|
|
2998
3032
|
};
|
|
2999
3033
|
});
|
|
3000
3034
|
return formatScheduleTimeSlots;
|
|
@@ -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)([
|
|
108
|
+
const mergedDiscountList = (0, import_utils.uniqueById)([
|
|
109
|
+
...filteredOldDiscountList,
|
|
110
|
+
...newDiscountList
|
|
111
|
+
]);
|
|
109
112
|
const result = this.calcDiscount(
|
|
110
113
|
{
|
|
111
114
|
discountList: mergedDiscountList,
|
|
@@ -409,8 +409,10 @@ var getDiscountAmount = (discounts) => {
|
|
|
409
409
|
}, new import_decimal.default(0)).toNumber();
|
|
410
410
|
};
|
|
411
411
|
var getMainProductTotal = (item) => {
|
|
412
|
-
var _a;
|
|
412
|
+
var _a, _b, _c, _d;
|
|
413
413
|
let total = new import_decimal.default((item == null ? void 0 : item.main_product_selling_price) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.main_product_selling_price) ?? item.price ?? 0);
|
|
414
|
+
const mainProductDiscountAmount = getDiscountAmount(((_c = (_b = item == null ? void 0 : item._origin) == null ? void 0 : _b.product) == null ? void 0 : _c.discount_list) || ((_d = item == null ? void 0 : item._originData.product) == null ? void 0 : _d.discount_list) || []);
|
|
415
|
+
total = total.minus(mainProductDiscountAmount);
|
|
414
416
|
if ((item == null ? void 0 : item.option) && Array.isArray(item == null ? void 0 : item.option)) {
|
|
415
417
|
total = total.add(item == null ? void 0 : item.option.reduce((t, option) => {
|
|
416
418
|
return t.add(new import_decimal.default(option.price || 0).mul(option.num || 1));
|
|
@@ -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:
|
|
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
|
|
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
|
|
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
|
-
))
|
|
1932
|
-
const
|
|
1933
|
-
(n) => n.
|
|
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
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
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
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
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
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
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 (
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
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 >
|
|
2006
|
-
|
|
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,
|
|
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 = (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
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
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
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:
|
|
2136
|
-
summaryCount,
|
|
2137
|
-
status
|
|
2179
|
+
count: bottleneckStats.count,
|
|
2180
|
+
left: bottleneckStats.left,
|
|
2181
|
+
summaryCount: bottleneckStats.summaryCount,
|
|
2182
|
+
status
|
|
2138
2183
|
};
|
|
2139
2184
|
});
|
|
2140
2185
|
return formatScheduleTimeSlots;
|