@pisell/pisellos 0.0.274 → 0.0.276
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/solution/BookingByStep/index.d.ts +8 -1
- package/dist/solution/BookingByStep/index.js +317 -55
- package/dist/solution/BookingByStep/utils/capacity.js +33 -3
- package/lib/solution/BookingByStep/index.d.ts +8 -1
- package/lib/solution/BookingByStep/index.js +176 -30
- package/lib/solution/BookingByStep/utils/capacity.js +25 -4
- package/package.json +1 -1
|
@@ -316,7 +316,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
316
316
|
count: number;
|
|
317
317
|
left: number;
|
|
318
318
|
}[];
|
|
319
|
-
|
|
319
|
+
/**
|
|
320
|
+
* 找到多个资源的公共可用时间段
|
|
321
|
+
*/
|
|
322
|
+
private findCommonAvailableTimeSlots;
|
|
323
|
+
checkMaxDurationCapacity(): {
|
|
324
|
+
success: boolean;
|
|
325
|
+
minAvailableCount: number;
|
|
326
|
+
};
|
|
320
327
|
setOtherData(key: string, value: any): void;
|
|
321
328
|
getOtherData(key: string): any;
|
|
322
329
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
@@ -2611,16 +2611,100 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2611
2611
|
// 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
|
|
2612
2612
|
// 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
|
|
2613
2613
|
// 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
|
|
2614
|
+
/**
|
|
2615
|
+
* 找到多个资源的公共可用时间段
|
|
2616
|
+
*/
|
|
2617
|
+
}, {
|
|
2618
|
+
key: "findCommonAvailableTimeSlots",
|
|
2619
|
+
value: function findCommonAvailableTimeSlots(resources) {
|
|
2620
|
+
if (resources.length === 0) return [];
|
|
2621
|
+
console.log("\u8BA1\u7B97 ".concat(resources.length, " \u4E2A\u8D44\u6E90\u7684\u516C\u5171\u65F6\u95F4\u6BB5"));
|
|
2622
|
+
|
|
2623
|
+
// 收集所有资源的时间段,转换为统一的时间格式
|
|
2624
|
+
var allTimeSlots = resources.map(function (resource) {
|
|
2625
|
+
return resource.times.map(function (time) {
|
|
2626
|
+
return {
|
|
2627
|
+
start: dayjs(time.start_at),
|
|
2628
|
+
end: dayjs(time.end_at)
|
|
2629
|
+
};
|
|
2630
|
+
});
|
|
2631
|
+
});
|
|
2632
|
+
console.log('所有资源的时间段:', allTimeSlots.map(function (slots) {
|
|
2633
|
+
return slots.map(function (slot) {
|
|
2634
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2635
|
+
});
|
|
2636
|
+
}));
|
|
2637
|
+
|
|
2638
|
+
// 找到公共时间段的交集
|
|
2639
|
+
var commonSlots = allTimeSlots[0]; // 从第一个资源的时间段开始
|
|
2640
|
+
console.log('初始公共时间段:', commonSlots.map(function (slot) {
|
|
2641
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2642
|
+
}));
|
|
2643
|
+
|
|
2644
|
+
// 与其他资源的时间段求交集
|
|
2645
|
+
var _loop2 = function _loop2() {
|
|
2646
|
+
var currentResourceSlots = allTimeSlots[i];
|
|
2647
|
+
var intersections = [];
|
|
2648
|
+
|
|
2649
|
+
// 计算当前公共时间段与下一个资源时间段的交集
|
|
2650
|
+
commonSlots.forEach(function (commonSlot) {
|
|
2651
|
+
currentResourceSlots.forEach(function (currentSlot) {
|
|
2652
|
+
var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
|
|
2653
|
+
var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
|
|
2654
|
+
|
|
2655
|
+
// 如果有重叠时间且重叠时间大于0
|
|
2656
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
2657
|
+
intersections.push({
|
|
2658
|
+
start: overlapStart,
|
|
2659
|
+
end: overlapEnd
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
2662
|
+
});
|
|
2663
|
+
});
|
|
2664
|
+
commonSlots = intersections;
|
|
2665
|
+
console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
|
|
2666
|
+
return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
|
|
2667
|
+
}));
|
|
2668
|
+
|
|
2669
|
+
// 如果没有公共时间段,直接返回
|
|
2670
|
+
if (commonSlots.length === 0) {
|
|
2671
|
+
console.log('没有找到公共时间段');
|
|
2672
|
+
return {
|
|
2673
|
+
v: []
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
},
|
|
2677
|
+
_ret2;
|
|
2678
|
+
for (var i = 1; i < allTimeSlots.length; i++) {
|
|
2679
|
+
_ret2 = _loop2();
|
|
2680
|
+
if (_ret2) return _ret2.v;
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
// 格式化返回结果
|
|
2684
|
+
var result = commonSlots.map(function (slot) {
|
|
2685
|
+
return {
|
|
2686
|
+
startTime: slot.start.format('HH:mm'),
|
|
2687
|
+
endTime: slot.end.format('HH:mm')
|
|
2688
|
+
};
|
|
2689
|
+
});
|
|
2690
|
+
console.log('最终公共时间段:', result);
|
|
2691
|
+
return result;
|
|
2692
|
+
}
|
|
2614
2693
|
}, {
|
|
2615
2694
|
key: "checkMaxDurationCapacity",
|
|
2616
2695
|
value: function checkMaxDurationCapacity() {
|
|
2617
2696
|
var _this15 = this;
|
|
2618
2697
|
var cartItems = cloneDeep(this.store.cart.getItems());
|
|
2619
|
-
if (cartItems.length === 0) return
|
|
2698
|
+
if (cartItems.length === 0) return {
|
|
2699
|
+
success: true,
|
|
2700
|
+
minAvailableCount: 0
|
|
2701
|
+
};
|
|
2620
2702
|
|
|
2621
2703
|
// 将购物车商品分为有时间的和没有时间的
|
|
2622
2704
|
var itemsWithTime = [];
|
|
2623
2705
|
var itemsWithoutTime = [];
|
|
2706
|
+
// 记录每种资源类型的可用数量
|
|
2707
|
+
var availableCountsByResourceType = [];
|
|
2624
2708
|
cartItems.forEach(function (cartItem) {
|
|
2625
2709
|
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2626
2710
|
itemsWithTime.push(cartItem);
|
|
@@ -2655,48 +2739,215 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2655
2739
|
});
|
|
2656
2740
|
});
|
|
2657
2741
|
|
|
2658
|
-
//
|
|
2659
|
-
var
|
|
2742
|
+
// 为每种资源类型检查容量
|
|
2743
|
+
var dateRange = this.store.date.getDateRange();
|
|
2744
|
+
if (!dateRange || dateRange.length === 0) return {
|
|
2745
|
+
success: false,
|
|
2746
|
+
minAvailableCount: 0
|
|
2747
|
+
};
|
|
2748
|
+
var resourcesDates = this.store.date.getDateList();
|
|
2749
|
+
var targetResourceDate = resourcesDates.find(function (n) {
|
|
2750
|
+
return n.date === dateRange[0].date;
|
|
2751
|
+
});
|
|
2752
|
+
if (!targetResourceDate) return {
|
|
2753
|
+
success: false,
|
|
2754
|
+
minAvailableCount: 0
|
|
2755
|
+
};
|
|
2756
|
+
var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
|
|
2757
|
+
|
|
2758
|
+
// 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
|
|
2759
|
+
var resourceCodeToFormIdMap = {};
|
|
2760
|
+
|
|
2761
|
+
// 遍历购物车中的商品,收集所有资源类型配置
|
|
2762
|
+
Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
|
|
2763
|
+
var _cartItem$_productOri11;
|
|
2764
|
+
if ((_cartItem$_productOri11 = cartItem._productOrigin) !== null && _cartItem$_productOri11 !== void 0 && (_cartItem$_productOri11 = _cartItem$_productOri11.product_resource) !== null && _cartItem$_productOri11 !== void 0 && _cartItem$_productOri11.resources) {
|
|
2765
|
+
cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
|
|
2766
|
+
// 只处理启用的资源类型 (status === 1)
|
|
2767
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
2768
|
+
var _resourceConfig$id, _resourceConfig$resou;
|
|
2769
|
+
var formId = ((_resourceConfig$id = resourceConfig.id) === null || _resourceConfig$id === void 0 ? void 0 : _resourceConfig$id.toString()) || ((_resourceConfig$resou = resourceConfig.resource_type_id) === null || _resourceConfig$resou === void 0 ? void 0 : _resourceConfig$resou.toString());
|
|
2770
|
+
if (formId) {
|
|
2771
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
});
|
|
2775
|
+
}
|
|
2776
|
+
});
|
|
2777
|
+
var hasCapacityIssue = false;
|
|
2778
|
+
var resourceCapacityInfo = [];
|
|
2779
|
+
|
|
2780
|
+
// 先检查所有资源类型,收集可用数量信息
|
|
2781
|
+
var _loop3 = function _loop3() {
|
|
2782
|
+
var _resourceTypeConfig;
|
|
2660
2783
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
2661
2784
|
resourceCode = _Object$entries$_i[0],
|
|
2662
2785
|
items = _Object$entries$_i[1];
|
|
2786
|
+
// 获取该资源类型对应的 form_id
|
|
2787
|
+
var targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
2788
|
+
if (!targetFormId) {
|
|
2789
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
|
|
2790
|
+
return {
|
|
2791
|
+
v: {
|
|
2792
|
+
success: false,
|
|
2793
|
+
minAvailableCount: 0
|
|
2794
|
+
}
|
|
2795
|
+
};
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
// 获取该资源类型的所有资源
|
|
2799
|
+
var resourcesOfThisType = [];
|
|
2800
|
+
items.forEach(function (cartItem) {
|
|
2801
|
+
var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
2802
|
+
productResourceIds.forEach(function (resourceId) {
|
|
2803
|
+
var _resource$form_id;
|
|
2804
|
+
var resource = resourcesMap[resourceId];
|
|
2805
|
+
if (resource && ((_resource$form_id = resource.form_id) === null || _resource$form_id === void 0 ? void 0 : _resource$form_id.toString()) === targetFormId) {
|
|
2806
|
+
// 避免重复添加同一个资源
|
|
2807
|
+
if (!resourcesOfThisType.find(function (r) {
|
|
2808
|
+
return r.id === resource.id;
|
|
2809
|
+
})) {
|
|
2810
|
+
resourcesOfThisType.push(resource);
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
});
|
|
2814
|
+
});
|
|
2815
|
+
if (resourcesOfThisType.length === 0) {
|
|
2816
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
|
|
2817
|
+
return {
|
|
2818
|
+
v: {
|
|
2819
|
+
success: false,
|
|
2820
|
+
minAvailableCount: 0
|
|
2821
|
+
}
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
// 检查资源类型(单个预约 vs 多个预约)
|
|
2826
|
+
// 从商品配置中获取资源类型信息
|
|
2827
|
+
var resourceTypeConfig = null;
|
|
2828
|
+
var _iterator3 = _createForOfIteratorHelper(items),
|
|
2829
|
+
_step3;
|
|
2663
2830
|
try {
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
var endTime = firstTimeSlot.end_time;
|
|
2671
|
-
|
|
2672
|
-
// 为这些商品设置时间信息(创建副本,不修改原始数据)
|
|
2673
|
-
items.forEach(function (cartItem) {
|
|
2674
|
-
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
2675
|
-
start_date: startDate,
|
|
2676
|
-
start_time: startTime,
|
|
2677
|
-
end_time: endTime,
|
|
2678
|
-
end_date: startDate
|
|
2831
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
2832
|
+
var _cartItem$_productOri12;
|
|
2833
|
+
var cartItem = _step3.value;
|
|
2834
|
+
if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
|
|
2835
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
2836
|
+
return r.code === resourceCode && r.status === 1;
|
|
2679
2837
|
});
|
|
2680
|
-
|
|
2681
|
-
}
|
|
2682
|
-
} else {
|
|
2683
|
-
// 如果没有公共可用时间,说明容量不足
|
|
2684
|
-
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4"));
|
|
2685
|
-
return {
|
|
2686
|
-
v: false
|
|
2687
|
-
};
|
|
2838
|
+
if (resourceTypeConfig) break;
|
|
2839
|
+
}
|
|
2688
2840
|
}
|
|
2689
|
-
} catch (
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2841
|
+
} catch (err) {
|
|
2842
|
+
_iterator3.e(err);
|
|
2843
|
+
} finally {
|
|
2844
|
+
_iterator3.f();
|
|
2845
|
+
}
|
|
2846
|
+
var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
|
|
2847
|
+
var totalAvailable;
|
|
2848
|
+
var requiredAmount;
|
|
2849
|
+
var availableAmount;
|
|
2850
|
+
if (isMultipleBooking) {
|
|
2851
|
+
// 多个预约:计算容量
|
|
2852
|
+
totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
|
|
2853
|
+
return sum + (resource.capacity || 0);
|
|
2854
|
+
}, 0);
|
|
2855
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
2856
|
+
var _getCapacityInfoByCar7 = getCapacityInfoByCartItem(cartItem),
|
|
2857
|
+
currentCapacity = _getCapacityInfoByCar7.currentCapacity;
|
|
2858
|
+
return sum + currentCapacity;
|
|
2859
|
+
}, 0);
|
|
2860
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2861
|
+
} else {
|
|
2862
|
+
// 单个预约:计算资源个数
|
|
2863
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2864
|
+
requiredAmount = items.reduce(function (sum, cartItem) {
|
|
2865
|
+
return sum + (cartItem.num || 1);
|
|
2866
|
+
}, 0);
|
|
2867
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
// 记录资源容量信息
|
|
2871
|
+
resourceCapacityInfo.push({
|
|
2872
|
+
code: resourceCode,
|
|
2873
|
+
available: availableAmount,
|
|
2874
|
+
total: totalAvailable,
|
|
2875
|
+
required: requiredAmount,
|
|
2876
|
+
isMultiple: isMultipleBooking
|
|
2877
|
+
});
|
|
2878
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2879
|
+
|
|
2880
|
+
// 检查是否有容量问题
|
|
2881
|
+
if (requiredAmount > totalAvailable) {
|
|
2882
|
+
hasCapacityIssue = true;
|
|
2883
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
|
|
2693
2884
|
}
|
|
2885
|
+
|
|
2886
|
+
// 为通过检测的商品分配一个公共可用时间段
|
|
2887
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
|
|
2888
|
+
return {
|
|
2889
|
+
id: r.id,
|
|
2890
|
+
times: r.times.map(function (t) {
|
|
2891
|
+
return "".concat(t.start_at, " - ").concat(t.end_at);
|
|
2892
|
+
})
|
|
2893
|
+
};
|
|
2894
|
+
}));
|
|
2895
|
+
|
|
2896
|
+
// 找到所有资源都可用的时间段
|
|
2897
|
+
var commonTimeSlots = _this15.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2898
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
|
|
2899
|
+
if (commonTimeSlots.length === 0) {
|
|
2900
|
+
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
2901
|
+
return {
|
|
2902
|
+
v: {
|
|
2903
|
+
success: false,
|
|
2904
|
+
minAvailableCount: 0
|
|
2905
|
+
}
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
// 使用第一个公共可用时间段
|
|
2910
|
+
var firstCommonSlot = commonTimeSlots[0];
|
|
2911
|
+
console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
|
|
2912
|
+
items.forEach(function (cartItem) {
|
|
2913
|
+
var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
|
|
2914
|
+
start_date: dateRange[0].date,
|
|
2915
|
+
start_time: firstCommonSlot.startTime,
|
|
2916
|
+
end_time: firstCommonSlot.endTime,
|
|
2917
|
+
end_date: dateRange[0].date
|
|
2918
|
+
});
|
|
2919
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2920
|
+
});
|
|
2694
2921
|
},
|
|
2695
|
-
|
|
2922
|
+
_ret3;
|
|
2696
2923
|
for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
|
|
2697
|
-
|
|
2698
|
-
if (
|
|
2699
|
-
|
|
2924
|
+
_ret3 = _loop3();
|
|
2925
|
+
if (_ret3) return _ret3.v;
|
|
2926
|
+
}
|
|
2927
|
+
|
|
2928
|
+
// 如果有容量问题,找出限制最严格的资源类型,返回其总容量
|
|
2929
|
+
if (hasCapacityIssue) {
|
|
2930
|
+
// 找出超出容量的资源类型中,总容量最少的那个
|
|
2931
|
+
var overCapacityResources = resourceCapacityInfo.filter(function (info) {
|
|
2932
|
+
return info.required > info.total;
|
|
2933
|
+
});
|
|
2934
|
+
if (overCapacityResources.length > 0) {
|
|
2935
|
+
var _minTotalCapacity = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
|
|
2936
|
+
return info.total;
|
|
2937
|
+
})));
|
|
2938
|
+
return {
|
|
2939
|
+
success: false,
|
|
2940
|
+
minAvailableCount: _minTotalCapacity
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
// 如果没有超出容量的(理论上不应该发生),返回总容量最少的
|
|
2944
|
+
var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
|
|
2945
|
+
return info.total;
|
|
2946
|
+
})));
|
|
2947
|
+
return {
|
|
2948
|
+
success: false,
|
|
2949
|
+
minAvailableCount: minTotalCapacity
|
|
2950
|
+
};
|
|
2700
2951
|
}
|
|
2701
2952
|
}
|
|
2702
2953
|
|
|
@@ -2715,7 +2966,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2715
2966
|
});
|
|
2716
2967
|
|
|
2717
2968
|
// 检查每个时间段是否有足够的资源容量
|
|
2718
|
-
var
|
|
2969
|
+
var _loop4 = function _loop4() {
|
|
2719
2970
|
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
2720
2971
|
timeSlotKey = _Object$entries2$_i[0],
|
|
2721
2972
|
itemsInTimeSlot = _Object$entries2$_i[1];
|
|
@@ -2755,18 +3006,29 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2755
3006
|
|
|
2756
3007
|
// 按资源类型分组检查容量
|
|
2757
3008
|
if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
3009
|
+
// 如果有可用数量记录,返回最小值;否则返回 0
|
|
3010
|
+
var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
2758
3011
|
return {
|
|
2759
|
-
v:
|
|
3012
|
+
v: {
|
|
3013
|
+
success: false,
|
|
3014
|
+
minAvailableCount: _minAvailableCount
|
|
3015
|
+
}
|
|
2760
3016
|
};
|
|
2761
3017
|
}
|
|
2762
3018
|
},
|
|
2763
|
-
|
|
3019
|
+
_ret4;
|
|
2764
3020
|
for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
|
|
2765
|
-
|
|
2766
|
-
if (
|
|
2767
|
-
if (
|
|
3021
|
+
_ret4 = _loop4();
|
|
3022
|
+
if (_ret4 === 0) continue;
|
|
3023
|
+
if (_ret4) return _ret4.v;
|
|
2768
3024
|
}
|
|
2769
|
-
|
|
3025
|
+
|
|
3026
|
+
// 全部通过检测,返回成功和最小可用数量
|
|
3027
|
+
var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
|
|
3028
|
+
return {
|
|
3029
|
+
success: true,
|
|
3030
|
+
minAvailableCount: minAvailableCount
|
|
3031
|
+
};
|
|
2770
3032
|
}
|
|
2771
3033
|
}, {
|
|
2772
3034
|
key: "setOtherData",
|
|
@@ -2839,7 +3101,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2839
3101
|
}, {
|
|
2840
3102
|
key: "getResourcesByCartItemAndCode",
|
|
2841
3103
|
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
2842
|
-
var _cartItem$
|
|
3104
|
+
var _cartItem$_productOri13;
|
|
2843
3105
|
var dateRange = this.store.date.getDateRange();
|
|
2844
3106
|
var resources = [];
|
|
2845
3107
|
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
@@ -2862,16 +3124,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2862
3124
|
});
|
|
2863
3125
|
if (!cartItem) return [];
|
|
2864
3126
|
var selectedResources = [];
|
|
2865
|
-
var
|
|
2866
|
-
currentCapacity =
|
|
2867
|
-
formatCapacity =
|
|
3127
|
+
var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
|
|
3128
|
+
currentCapacity = _getCapacityInfoByCar8.currentCapacity,
|
|
3129
|
+
formatCapacity = _getCapacityInfoByCar8.formatCapacity;
|
|
2868
3130
|
cartItem._origin.metadata.capacity = formatCapacity;
|
|
2869
3131
|
if (cartItem.holder_id) {
|
|
2870
3132
|
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
2871
3133
|
} else {
|
|
2872
3134
|
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
2873
3135
|
}
|
|
2874
|
-
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$
|
|
3136
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 || (_cartItem$_productOri13 = _cartItem$_productOri13.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [], selectedResources, currentCapacity);
|
|
2875
3137
|
var targetResource = productResources.find(function (resource) {
|
|
2876
3138
|
return resource.code === resourceCode;
|
|
2877
3139
|
});
|
|
@@ -2894,7 +3156,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2894
3156
|
});
|
|
2895
3157
|
if (mTimes.length === 0) return false;
|
|
2896
3158
|
var canUseArr = mTimes.map(function (item) {
|
|
2897
|
-
var _cartItem$
|
|
3159
|
+
var _cartItem$_productOri14;
|
|
2898
3160
|
var res = getIsUsableByTimeItem({
|
|
2899
3161
|
timeSlice: {
|
|
2900
3162
|
start_time: startTime.format('HH:mm'),
|
|
@@ -2906,7 +3168,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2906
3168
|
resource: m,
|
|
2907
3169
|
currentCount: currentCapacity || 0,
|
|
2908
3170
|
resourcesUseableMap: resourcesUseableMap,
|
|
2909
|
-
cut_off_time: (_cartItem$
|
|
3171
|
+
cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
|
|
2910
3172
|
});
|
|
2911
3173
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2912
3174
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -2920,12 +3182,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2920
3182
|
});
|
|
2921
3183
|
} else {
|
|
2922
3184
|
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
2923
|
-
var _cartItem$
|
|
3185
|
+
var _cartItem$_productOri15;
|
|
2924
3186
|
var recordCount = n.capacity || 0;
|
|
2925
3187
|
if (n.onlyComputed) return false;
|
|
2926
3188
|
var timeSlots = getTimeSlicesByResource({
|
|
2927
3189
|
resource: n,
|
|
2928
|
-
duration: ((_cartItem$
|
|
3190
|
+
duration: ((_cartItem$_productOri15 = cartItem._productOrigin) === null || _cartItem$_productOri15 === void 0 || (_cartItem$_productOri15 = _cartItem$_productOri15.duration) === null || _cartItem$_productOri15 === void 0 ? void 0 : _cartItem$_productOri15.value) || 10,
|
|
2929
3191
|
split: 10,
|
|
2930
3192
|
currentDate: dateRange[0].date
|
|
2931
3193
|
});
|
|
@@ -3007,7 +3269,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3007
3269
|
openResources,
|
|
3008
3270
|
allProductResources,
|
|
3009
3271
|
targetSchedules,
|
|
3010
|
-
|
|
3272
|
+
_loop5,
|
|
3011
3273
|
_args28 = arguments;
|
|
3012
3274
|
return _regeneratorRuntime().wrap(function _callee27$(_context28) {
|
|
3013
3275
|
while (1) switch (_context28.prev = _context28.next) {
|
|
@@ -3084,9 +3346,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3084
3346
|
}
|
|
3085
3347
|
});
|
|
3086
3348
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
3087
|
-
|
|
3349
|
+
_loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
|
|
3088
3350
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
3089
|
-
return _regeneratorRuntime().wrap(function
|
|
3351
|
+
return _regeneratorRuntime().wrap(function _loop5$(_context27) {
|
|
3090
3352
|
while (1) switch (_context27.prev = _context27.next) {
|
|
3091
3353
|
case 0:
|
|
3092
3354
|
currentDateStr = currentDate.format('YYYY-MM-DD');
|
|
@@ -3189,14 +3451,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3189
3451
|
case "end":
|
|
3190
3452
|
return _context27.stop();
|
|
3191
3453
|
}
|
|
3192
|
-
},
|
|
3454
|
+
}, _loop5);
|
|
3193
3455
|
});
|
|
3194
3456
|
case 28:
|
|
3195
3457
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
3196
3458
|
_context28.next = 34;
|
|
3197
3459
|
break;
|
|
3198
3460
|
}
|
|
3199
|
-
return _context28.delegateYield(
|
|
3461
|
+
return _context28.delegateYield(_loop5(), "t0", 30);
|
|
3200
3462
|
case 30:
|
|
3201
3463
|
if (!_context28.t0) {
|
|
3202
3464
|
_context28.next = 32;
|
|
@@ -262,15 +262,43 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
262
262
|
|
|
263
263
|
// 检查每种资源类型是否有足够的容量
|
|
264
264
|
var _loop = function _loop() {
|
|
265
|
+
var _resourceTypeConfig, _resourceTypeConfig2;
|
|
265
266
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
266
267
|
formId = _Object$entries$_i[0],
|
|
267
268
|
requiredCapacity = _Object$entries$_i[1];
|
|
268
269
|
var resourcesInType = resourceTypeMap[formId];
|
|
269
270
|
if (resourcesInType.length === 0) return 0; // continue
|
|
270
271
|
|
|
271
|
-
//
|
|
272
|
-
var
|
|
273
|
-
var
|
|
272
|
+
// 从购物车商品中获取正确的资源类型配置
|
|
273
|
+
var resourceTypeConfig = null;
|
|
274
|
+
var _iterator2 = _createForOfIteratorHelper(cartItems),
|
|
275
|
+
_step2;
|
|
276
|
+
try {
|
|
277
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
278
|
+
var _cartItem$_productOri;
|
|
279
|
+
var cartItem = _step2.value;
|
|
280
|
+
if ((_cartItem$_productOri = cartItem._productOrigin) !== null && _cartItem$_productOri !== void 0 && (_cartItem$_productOri = _cartItem$_productOri.product_resource) !== null && _cartItem$_productOri !== void 0 && _cartItem$_productOri.resources) {
|
|
281
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
|
|
282
|
+
var _r$id;
|
|
283
|
+
return ((_r$id = r.id) === null || _r$id === void 0 ? void 0 : _r$id.toString()) === formId && r.status === 1;
|
|
284
|
+
});
|
|
285
|
+
if (resourceTypeConfig) break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// 确定这种资源类型的预约类型
|
|
290
|
+
} catch (err) {
|
|
291
|
+
_iterator2.e(err);
|
|
292
|
+
} finally {
|
|
293
|
+
_iterator2.f();
|
|
294
|
+
}
|
|
295
|
+
var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
|
|
296
|
+
console.log("capacity.ts - \u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u914D\u7F6E:"), {
|
|
297
|
+
resourceTypeConfig: resourceTypeConfig,
|
|
298
|
+
type: (_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type,
|
|
299
|
+
isMultipleBooking: isMultipleBooking,
|
|
300
|
+
requiredCapacity: requiredCapacity
|
|
301
|
+
});
|
|
274
302
|
if (isMultipleBooking) {
|
|
275
303
|
// 多个预约:计算总可用容量
|
|
276
304
|
var totalAvailableCapacity = 0;
|
|
@@ -284,6 +312,7 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
284
312
|
totalAvailableCapacity += resource.capacity || 0;
|
|
285
313
|
}
|
|
286
314
|
});
|
|
315
|
+
console.log("capacity.ts - \u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u591A\u4E2A\u9884\u7EA6\u68C0\u67E5: \u603B\u5BB9\u91CF ").concat(totalAvailableCapacity, ", \u9700\u6C42 ").concat(requiredCapacity));
|
|
287
316
|
if (totalAvailableCapacity < requiredCapacity) {
|
|
288
317
|
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u5BB9\u91CF\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredCapacity, ", \u53EF\u7528 ").concat(totalAvailableCapacity));
|
|
289
318
|
return {
|
|
@@ -302,6 +331,7 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
|
|
|
302
331
|
availableResourceCount++;
|
|
303
332
|
}
|
|
304
333
|
});
|
|
334
|
+
console.log("capacity.ts - \u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u5355\u4E2A\u9884\u7EA6\u68C0\u67E5: \u53EF\u7528\u8D44\u6E90\u6570 ").concat(availableResourceCount, ", \u9700\u6C42 ").concat(requiredCapacity));
|
|
305
335
|
if (availableResourceCount < requiredCapacity) {
|
|
306
336
|
console.log("\u8D44\u6E90\u7C7B\u578B ".concat(formId, " \u6570\u91CF\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredCapacity, ", \u53EF\u7528 ").concat(availableResourceCount));
|
|
307
337
|
return {
|
|
@@ -316,7 +316,14 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
316
316
|
count: number;
|
|
317
317
|
left: number;
|
|
318
318
|
}[];
|
|
319
|
-
|
|
319
|
+
/**
|
|
320
|
+
* 找到多个资源的公共可用时间段
|
|
321
|
+
*/
|
|
322
|
+
private findCommonAvailableTimeSlots;
|
|
323
|
+
checkMaxDurationCapacity(): {
|
|
324
|
+
success: boolean;
|
|
325
|
+
minAvailableCount: number;
|
|
326
|
+
};
|
|
320
327
|
setOtherData(key: string, value: any): void;
|
|
321
328
|
getOtherData(key: string): any;
|
|
322
329
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
@@ -1839,12 +1839,61 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1839
1839
|
// 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
|
|
1840
1840
|
// 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
|
|
1841
1841
|
// 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
|
|
1842
|
+
/**
|
|
1843
|
+
* 找到多个资源的公共可用时间段
|
|
1844
|
+
*/
|
|
1845
|
+
findCommonAvailableTimeSlots(resources) {
|
|
1846
|
+
if (resources.length === 0)
|
|
1847
|
+
return [];
|
|
1848
|
+
console.log(`计算 ${resources.length} 个资源的公共时间段`);
|
|
1849
|
+
const allTimeSlots = resources.map(
|
|
1850
|
+
(resource) => resource.times.map((time) => ({
|
|
1851
|
+
start: (0, import_dayjs.default)(time.start_at),
|
|
1852
|
+
end: (0, import_dayjs.default)(time.end_at)
|
|
1853
|
+
}))
|
|
1854
|
+
);
|
|
1855
|
+
console.log("所有资源的时间段:", allTimeSlots.map(
|
|
1856
|
+
(slots) => slots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`)
|
|
1857
|
+
));
|
|
1858
|
+
let commonSlots = allTimeSlots[0];
|
|
1859
|
+
console.log("初始公共时间段:", commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
|
|
1860
|
+
for (let i = 1; i < allTimeSlots.length; i++) {
|
|
1861
|
+
const currentResourceSlots = allTimeSlots[i];
|
|
1862
|
+
const intersections = [];
|
|
1863
|
+
commonSlots.forEach((commonSlot) => {
|
|
1864
|
+
currentResourceSlots.forEach((currentSlot) => {
|
|
1865
|
+
const overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
|
|
1866
|
+
const overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
|
|
1867
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
1868
|
+
intersections.push({
|
|
1869
|
+
start: overlapStart,
|
|
1870
|
+
end: overlapEnd
|
|
1871
|
+
});
|
|
1872
|
+
}
|
|
1873
|
+
});
|
|
1874
|
+
});
|
|
1875
|
+
commonSlots = intersections;
|
|
1876
|
+
console.log(`与资源${i}求交集后的公共时间段:`, commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
|
|
1877
|
+
if (commonSlots.length === 0) {
|
|
1878
|
+
console.log("没有找到公共时间段");
|
|
1879
|
+
return [];
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
const result = commonSlots.map((slot) => ({
|
|
1883
|
+
startTime: slot.start.format("HH:mm"),
|
|
1884
|
+
endTime: slot.end.format("HH:mm")
|
|
1885
|
+
}));
|
|
1886
|
+
console.log("最终公共时间段:", result);
|
|
1887
|
+
return result;
|
|
1888
|
+
}
|
|
1842
1889
|
checkMaxDurationCapacity() {
|
|
1890
|
+
var _a, _b;
|
|
1843
1891
|
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1844
1892
|
if (cartItems.length === 0)
|
|
1845
|
-
return true;
|
|
1893
|
+
return { success: true, minAvailableCount: 0 };
|
|
1846
1894
|
const itemsWithTime = [];
|
|
1847
1895
|
const itemsWithoutTime = [];
|
|
1896
|
+
const availableCountsByResourceType = [];
|
|
1848
1897
|
cartItems.forEach((cartItem) => {
|
|
1849
1898
|
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
1850
1899
|
itemsWithTime.push(cartItem);
|
|
@@ -1856,14 +1905,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1856
1905
|
if (itemsWithoutTime.length > 0) {
|
|
1857
1906
|
const itemsByResourceType = {};
|
|
1858
1907
|
itemsWithoutTime.forEach((cartItem) => {
|
|
1859
|
-
var
|
|
1908
|
+
var _a2;
|
|
1860
1909
|
if (!cartItem._productOrigin)
|
|
1861
1910
|
return;
|
|
1862
|
-
const resourceTypes = ((
|
|
1911
|
+
const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
|
|
1863
1912
|
resourceTypes.forEach((resourceType) => {
|
|
1864
|
-
var
|
|
1913
|
+
var _a3;
|
|
1865
1914
|
if (resourceType.status === 1) {
|
|
1866
|
-
const resourceCode = resourceType.code || ((
|
|
1915
|
+
const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
|
|
1867
1916
|
if (!itemsByResourceType[resourceCode]) {
|
|
1868
1917
|
itemsByResourceType[resourceCode] = [];
|
|
1869
1918
|
}
|
|
@@ -1873,32 +1922,127 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1873
1922
|
}
|
|
1874
1923
|
});
|
|
1875
1924
|
});
|
|
1925
|
+
const dateRange = this.store.date.getDateRange();
|
|
1926
|
+
if (!dateRange || dateRange.length === 0)
|
|
1927
|
+
return { success: false, minAvailableCount: 0 };
|
|
1928
|
+
const resourcesDates = this.store.date.getDateList();
|
|
1929
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
1930
|
+
if (!targetResourceDate)
|
|
1931
|
+
return { success: false, minAvailableCount: 0 };
|
|
1932
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
|
|
1933
|
+
const resourceCodeToFormIdMap = {};
|
|
1934
|
+
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
1935
|
+
var _a2, _b2;
|
|
1936
|
+
if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
|
|
1937
|
+
cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
|
|
1938
|
+
var _a3, _b3;
|
|
1939
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
1940
|
+
const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
|
|
1941
|
+
if (formId) {
|
|
1942
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1948
|
+
let hasCapacityIssue = false;
|
|
1949
|
+
const resourceCapacityInfo = [];
|
|
1876
1950
|
for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1951
|
+
const targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
1952
|
+
if (!targetFormId) {
|
|
1953
|
+
console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
|
|
1954
|
+
return { success: false, minAvailableCount: 0 };
|
|
1955
|
+
}
|
|
1956
|
+
const resourcesOfThisType = [];
|
|
1957
|
+
items.forEach((cartItem) => {
|
|
1958
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
1959
|
+
productResourceIds.forEach((resourceId) => {
|
|
1960
|
+
var _a2;
|
|
1961
|
+
const resource = resourcesMap[resourceId];
|
|
1962
|
+
if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
|
|
1963
|
+
if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
|
|
1964
|
+
resourcesOfThisType.push(resource);
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
});
|
|
1969
|
+
if (resourcesOfThisType.length === 0) {
|
|
1970
|
+
console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
|
|
1971
|
+
return { success: false, minAvailableCount: 0 };
|
|
1972
|
+
}
|
|
1973
|
+
let resourceTypeConfig = null;
|
|
1974
|
+
for (const cartItem of items) {
|
|
1975
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
1976
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
1977
|
+
(r) => r.code === resourceCode && r.status === 1
|
|
1978
|
+
);
|
|
1979
|
+
if (resourceTypeConfig)
|
|
1980
|
+
break;
|
|
1897
1981
|
}
|
|
1898
|
-
} catch (error) {
|
|
1899
|
-
console.warn(`获取资源类型 ${resourceCode} 的公共可用时间失败:`, error);
|
|
1900
|
-
continue;
|
|
1901
1982
|
}
|
|
1983
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
1984
|
+
let totalAvailable;
|
|
1985
|
+
let requiredAmount;
|
|
1986
|
+
let availableAmount;
|
|
1987
|
+
if (isMultipleBooking) {
|
|
1988
|
+
totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
|
|
1989
|
+
return sum + (resource.capacity || 0);
|
|
1990
|
+
}, 0);
|
|
1991
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
1992
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
1993
|
+
return sum + currentCapacity;
|
|
1994
|
+
}, 0);
|
|
1995
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
1996
|
+
} else {
|
|
1997
|
+
totalAvailable = resourcesOfThisType.length;
|
|
1998
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
1999
|
+
return sum + (cartItem.num || 1);
|
|
2000
|
+
}, 0);
|
|
2001
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2002
|
+
}
|
|
2003
|
+
resourceCapacityInfo.push({
|
|
2004
|
+
code: resourceCode,
|
|
2005
|
+
available: availableAmount,
|
|
2006
|
+
total: totalAvailable,
|
|
2007
|
+
required: requiredAmount,
|
|
2008
|
+
isMultiple: isMultipleBooking
|
|
2009
|
+
});
|
|
2010
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2011
|
+
if (requiredAmount > totalAvailable) {
|
|
2012
|
+
hasCapacityIssue = true;
|
|
2013
|
+
console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
|
|
2014
|
+
}
|
|
2015
|
+
console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
|
|
2016
|
+
id: r.id,
|
|
2017
|
+
times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
|
|
2018
|
+
})));
|
|
2019
|
+
const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2020
|
+
console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
|
|
2021
|
+
if (commonTimeSlots.length === 0) {
|
|
2022
|
+
console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
|
|
2023
|
+
return { success: false, minAvailableCount: 0 };
|
|
2024
|
+
}
|
|
2025
|
+
const firstCommonSlot = commonTimeSlots[0];
|
|
2026
|
+
console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
|
|
2027
|
+
items.forEach((cartItem) => {
|
|
2028
|
+
const processedItem = {
|
|
2029
|
+
...cartItem,
|
|
2030
|
+
start_date: dateRange[0].date,
|
|
2031
|
+
start_time: firstCommonSlot.startTime,
|
|
2032
|
+
end_time: firstCommonSlot.endTime,
|
|
2033
|
+
end_date: dateRange[0].date
|
|
2034
|
+
};
|
|
2035
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
if (hasCapacityIssue) {
|
|
2039
|
+
const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
|
|
2040
|
+
if (overCapacityResources.length > 0) {
|
|
2041
|
+
const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
|
|
2042
|
+
return { success: false, minAvailableCount: minTotalCapacity2 };
|
|
2043
|
+
}
|
|
2044
|
+
const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
|
|
2045
|
+
return { success: false, minAvailableCount: minTotalCapacity };
|
|
1902
2046
|
}
|
|
1903
2047
|
}
|
|
1904
2048
|
const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
|
|
@@ -1936,10 +2080,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1936
2080
|
});
|
|
1937
2081
|
});
|
|
1938
2082
|
if (!(0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
1939
|
-
|
|
2083
|
+
const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2084
|
+
return { success: false, minAvailableCount: minAvailableCount2 };
|
|
1940
2085
|
}
|
|
1941
2086
|
}
|
|
1942
|
-
|
|
2087
|
+
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2088
|
+
return { success: true, minAvailableCount };
|
|
1943
2089
|
}
|
|
1944
2090
|
setOtherData(key, value) {
|
|
1945
2091
|
this.otherData[key] = value;
|
|
@@ -167,10 +167,11 @@ function getResourcesIdsByProduct(product) {
|
|
|
167
167
|
return tempResourceIds;
|
|
168
168
|
}
|
|
169
169
|
function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResources) {
|
|
170
|
+
var _a, _b;
|
|
170
171
|
const resourceTypeMap = {};
|
|
171
172
|
allResources.forEach((resource) => {
|
|
172
|
-
var
|
|
173
|
-
const formId = ((
|
|
173
|
+
var _a2;
|
|
174
|
+
const formId = ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) || "default";
|
|
174
175
|
if (!resourceTypeMap[formId]) {
|
|
175
176
|
resourceTypeMap[formId] = [];
|
|
176
177
|
}
|
|
@@ -195,8 +196,26 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
195
196
|
const resourcesInType = resourceTypeMap[formId];
|
|
196
197
|
if (resourcesInType.length === 0)
|
|
197
198
|
continue;
|
|
198
|
-
|
|
199
|
-
const
|
|
199
|
+
let resourceTypeConfig = null;
|
|
200
|
+
for (const cartItem of cartItems) {
|
|
201
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
202
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
203
|
+
(r) => {
|
|
204
|
+
var _a2;
|
|
205
|
+
return ((_a2 = r.id) == null ? void 0 : _a2.toString()) === formId && r.status === 1;
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
if (resourceTypeConfig)
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
213
|
+
console.log(`capacity.ts - 资源类型 ${formId} 配置:`, {
|
|
214
|
+
resourceTypeConfig,
|
|
215
|
+
type: resourceTypeConfig == null ? void 0 : resourceTypeConfig.type,
|
|
216
|
+
isMultipleBooking,
|
|
217
|
+
requiredCapacity
|
|
218
|
+
});
|
|
200
219
|
if (isMultipleBooking) {
|
|
201
220
|
let totalAvailableCapacity = 0;
|
|
202
221
|
resourcesInType.forEach((resource) => {
|
|
@@ -207,6 +226,7 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
207
226
|
totalAvailableCapacity += resource.capacity || 0;
|
|
208
227
|
}
|
|
209
228
|
});
|
|
229
|
+
console.log(`capacity.ts - 资源类型 ${formId} 多个预约检查: 总容量 ${totalAvailableCapacity}, 需求 ${requiredCapacity}`);
|
|
210
230
|
if (totalAvailableCapacity < requiredCapacity) {
|
|
211
231
|
console.log(`资源类型 ${formId} 容量不足: 需要 ${requiredCapacity}, 可用 ${totalAvailableCapacity}`);
|
|
212
232
|
return false;
|
|
@@ -221,6 +241,7 @@ function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResourc
|
|
|
221
241
|
availableResourceCount++;
|
|
222
242
|
}
|
|
223
243
|
});
|
|
244
|
+
console.log(`capacity.ts - 资源类型 ${formId} 单个预约检查: 可用资源数 ${availableResourceCount}, 需求 ${requiredCapacity}`);
|
|
224
245
|
if (availableResourceCount < requiredCapacity) {
|
|
225
246
|
console.log(`资源类型 ${formId} 数量不足: 需要 ${requiredCapacity}, 可用 ${availableResourceCount}`);
|
|
226
247
|
return false;
|