@pisell/pisellos 2.0.29 → 2.0.31
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/Schedule/utils.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +53 -36
- package/lib/modules/Schedule/utils.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +27 -14
- package/package.json +1 -1
|
@@ -143,7 +143,7 @@ var getDaysByRepeatWeek = function getDaysByRepeatWeek(params, isGetRange) {
|
|
|
143
143
|
var _end = _start.add(scheduleDiff, 'second');
|
|
144
144
|
if (isGetRange) {
|
|
145
145
|
if (excludedDaysMap.has(_start.format('YYYY-MM-DD'))) {
|
|
146
|
-
startTmp = startTmp.day(1).add(frequency, '
|
|
146
|
+
startTmp = startTmp.day(1).add(frequency, 'day');
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
149
|
var arr = getDataRange({
|
|
@@ -210,7 +210,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
210
210
|
}): void;
|
|
211
211
|
setOtherData(key: string, value: any): void;
|
|
212
212
|
getOtherData(key: string): any;
|
|
213
|
-
getProductTypeById(id: number): Promise<"
|
|
213
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
214
214
|
/**
|
|
215
215
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
216
216
|
*
|
|
@@ -1266,7 +1266,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1266
1266
|
var _item$_origin$resourc;
|
|
1267
1267
|
var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
|
|
1268
1268
|
// 检查当前资源是否与目标资源的任何资源匹配
|
|
1269
|
-
|
|
1269
|
+
// 目标资源,应该只取跟当前 m.form_id 相同的资源
|
|
1270
|
+
var sameFormIdResources = targetCartItem._origin.resources.filter(function (n) {
|
|
1271
|
+
return n.form_id === m.form_id;
|
|
1272
|
+
});
|
|
1273
|
+
if (!(sameFormIdResources !== null && sameFormIdResources !== void 0 && sameFormIdResources.length)) {
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1276
|
+
return !sameFormIdResources.some(function (targetRes) {
|
|
1270
1277
|
// 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
|
|
1271
1278
|
if (targetRes.resourceType !== 'single') {
|
|
1272
1279
|
var _item$_productOrigin2;
|
|
@@ -1280,10 +1287,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1280
1287
|
var originResource = allOriginResources.find(function (n) {
|
|
1281
1288
|
return n.id === targetRes.id;
|
|
1282
1289
|
});
|
|
1283
|
-
if (currentResourcesCapacityMap[
|
|
1290
|
+
if (currentResourcesCapacityMap[m.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
|
|
1284
1291
|
return true;
|
|
1285
1292
|
}
|
|
1286
|
-
currentResourcesCapacityMap[
|
|
1293
|
+
currentResourcesCapacityMap[m.id] += _currentCapacity;
|
|
1287
1294
|
return false;
|
|
1288
1295
|
}
|
|
1289
1296
|
if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
|
|
@@ -2795,7 +2802,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2795
2802
|
var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
2796
2803
|
var _this$store$currentPr3, _this$store$currentPr4, _this$store$currentPr5, _tempProducts, _this$store$currentPr6;
|
|
2797
2804
|
var params,
|
|
2798
|
-
cache,
|
|
2799
2805
|
startDate,
|
|
2800
2806
|
endDate,
|
|
2801
2807
|
tempProducts,
|
|
@@ -2803,6 +2809,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2803
2809
|
filteredSchedule,
|
|
2804
2810
|
tempResourceIds,
|
|
2805
2811
|
res,
|
|
2812
|
+
cache,
|
|
2806
2813
|
dates,
|
|
2807
2814
|
currentDate,
|
|
2808
2815
|
firstAvailableDate,
|
|
@@ -2815,21 +2822,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2815
2822
|
while (1) switch (_context32.prev = _context32.next) {
|
|
2816
2823
|
case 0:
|
|
2817
2824
|
params = _args32.length > 0 && _args32[0] !== undefined ? _args32[0] : {};
|
|
2818
|
-
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2819
|
-
cache = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getOtherParams()['timeSlotBySchedule'];
|
|
2820
|
-
if (!cache) {
|
|
2821
|
-
_context32.next = 5;
|
|
2822
|
-
break;
|
|
2823
|
-
}
|
|
2824
|
-
if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
|
|
2825
|
-
_context32.next = 5;
|
|
2826
|
-
break;
|
|
2827
|
-
}
|
|
2828
|
-
return _context32.abrupt("return", {
|
|
2829
|
-
dateList: cache.dateList,
|
|
2830
|
-
firstAvailableDate: cache.firstAvailableDate
|
|
2831
|
-
});
|
|
2832
|
-
case 5:
|
|
2833
2825
|
// 开始日期如果小于今天,直接以今天当做开始日期
|
|
2834
2826
|
startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
|
|
2835
2827
|
if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
|
|
@@ -2838,11 +2830,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2838
2830
|
// 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
|
|
2839
2831
|
endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
|
|
2840
2832
|
// 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
|
|
2841
|
-
tempProducts = (_this$store$
|
|
2842
|
-
schedule = (_this$store$
|
|
2833
|
+
tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
|
|
2834
|
+
schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
|
|
2843
2835
|
filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
|
|
2844
2836
|
tempResourceIds = getResourcesIdsByProduct(tempProducts);
|
|
2845
|
-
_context32.next =
|
|
2837
|
+
_context32.next = 10;
|
|
2846
2838
|
return this.store.date.fetchResourceDates({
|
|
2847
2839
|
query: {
|
|
2848
2840
|
start_date: startDate || '',
|
|
@@ -2850,8 +2842,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2850
2842
|
resource_ids: tempResourceIds
|
|
2851
2843
|
}
|
|
2852
2844
|
});
|
|
2853
|
-
case
|
|
2845
|
+
case 10:
|
|
2854
2846
|
res = _context32.sent;
|
|
2847
|
+
// 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
|
|
2848
|
+
// TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
|
|
2849
|
+
cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
|
|
2850
|
+
if (!cache) {
|
|
2851
|
+
_context32.next = 15;
|
|
2852
|
+
break;
|
|
2853
|
+
}
|
|
2854
|
+
if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
|
|
2855
|
+
_context32.next = 15;
|
|
2856
|
+
break;
|
|
2857
|
+
}
|
|
2858
|
+
return _context32.abrupt("return", {
|
|
2859
|
+
dateList: cache.dateList,
|
|
2860
|
+
firstAvailableDate: cache.firstAvailableDate
|
|
2861
|
+
});
|
|
2862
|
+
case 15:
|
|
2855
2863
|
// 2. 商品 schedule 数据,确定日程在每一天的时间片
|
|
2856
2864
|
// 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
|
|
2857
2865
|
dates = [];
|
|
@@ -2860,7 +2868,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2860
2868
|
openResources = ((_tempProducts = tempProducts) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.product_resource) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.resources) === null || _tempProducts === void 0 ? void 0 : _tempProducts.filter(function (m) {
|
|
2861
2869
|
return m.status === 1;
|
|
2862
2870
|
})) || []; // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
|
|
2863
|
-
allProductResources = sortCombinedResources(res.data);
|
|
2871
|
+
allProductResources = sortCombinedResources(res.data); // allProductResources 需要根据商品里的资源的单个预约多个预约补充resourceType
|
|
2872
|
+
allProductResources.forEach(function (m) {
|
|
2873
|
+
var _tempProducts2;
|
|
2874
|
+
var resource = (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 || (_tempProducts2 = _tempProducts2.product_resource) === null || _tempProducts2 === void 0 || (_tempProducts2 = _tempProducts2.resources) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.find(function (n) {
|
|
2875
|
+
return n.id === m.form_id;
|
|
2876
|
+
});
|
|
2877
|
+
if (resource) {
|
|
2878
|
+
m.resourceType = resource.type;
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2864
2881
|
targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
|
|
2865
2882
|
_loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
|
|
2866
2883
|
var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
|
|
@@ -2917,7 +2934,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2917
2934
|
return;
|
|
2918
2935
|
}
|
|
2919
2936
|
var targetCanUseTimes = mTimes.some(function (childTiem) {
|
|
2920
|
-
var
|
|
2937
|
+
var _tempProducts3;
|
|
2921
2938
|
// 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
|
|
2922
2939
|
var res = getIsUsableByTimeItem({
|
|
2923
2940
|
timeSlice: {
|
|
@@ -2930,7 +2947,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2930
2947
|
resource: m,
|
|
2931
2948
|
currentCount: 1,
|
|
2932
2949
|
resourcesUseableMap: resourcesUseableMap,
|
|
2933
|
-
cut_off_time: (
|
|
2950
|
+
cut_off_time: (_tempProducts3 = tempProducts) === null || _tempProducts3 === void 0 ? void 0 : _tempProducts3.cut_off_time
|
|
2934
2951
|
});
|
|
2935
2952
|
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2936
2953
|
resourcesUseableMap[m.id] = res.usable;
|
|
@@ -2969,22 +2986,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2969
2986
|
}
|
|
2970
2987
|
}, _loop3);
|
|
2971
2988
|
});
|
|
2972
|
-
case
|
|
2989
|
+
case 23:
|
|
2973
2990
|
if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
|
|
2974
|
-
_context32.next =
|
|
2991
|
+
_context32.next = 29;
|
|
2975
2992
|
break;
|
|
2976
2993
|
}
|
|
2977
|
-
return _context32.delegateYield(_loop3(), "t0",
|
|
2978
|
-
case
|
|
2994
|
+
return _context32.delegateYield(_loop3(), "t0", 25);
|
|
2995
|
+
case 25:
|
|
2979
2996
|
if (!_context32.t0) {
|
|
2980
|
-
_context32.next =
|
|
2997
|
+
_context32.next = 27;
|
|
2981
2998
|
break;
|
|
2982
2999
|
}
|
|
2983
|
-
return _context32.abrupt("break",
|
|
2984
|
-
case
|
|
2985
|
-
_context32.next =
|
|
3000
|
+
return _context32.abrupt("break", 29);
|
|
3001
|
+
case 27:
|
|
3002
|
+
_context32.next = 23;
|
|
2986
3003
|
break;
|
|
2987
|
-
case
|
|
3004
|
+
case 29:
|
|
2988
3005
|
// 最终把资源数据也加到日期内
|
|
2989
3006
|
dates = handleAvailableDateByResource(res.data, dates);
|
|
2990
3007
|
this.store.date.setDateList(dates);
|
|
@@ -3000,7 +3017,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3000
3017
|
dateList: dates,
|
|
3001
3018
|
firstAvailableDate: firstAvailableDate
|
|
3002
3019
|
});
|
|
3003
|
-
case
|
|
3020
|
+
case 33:
|
|
3004
3021
|
case "end":
|
|
3005
3022
|
return _context32.stop();
|
|
3006
3023
|
}
|
|
@@ -143,7 +143,7 @@ var getDaysByRepeatWeek = (params, isGetRange) => {
|
|
|
143
143
|
const _end = _start.add(scheduleDiff, "second");
|
|
144
144
|
if (isGetRange) {
|
|
145
145
|
if (excludedDaysMap.has(_start.format("YYYY-MM-DD"))) {
|
|
146
|
-
startTmp = startTmp.day(1).add(frequency, "
|
|
146
|
+
startTmp = startTmp.day(1).add(frequency, "day");
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
149
|
const arr = getDataRange({
|
|
@@ -210,7 +210,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
210
210
|
}): void;
|
|
211
211
|
setOtherData(key: string, value: any): void;
|
|
212
212
|
getOtherData(key: string): any;
|
|
213
|
-
getProductTypeById(id: number): Promise<"
|
|
213
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
214
214
|
/**
|
|
215
215
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
216
216
|
*
|
|
@@ -643,7 +643,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
643
643
|
var _a2;
|
|
644
644
|
if (item._id !== targetCartItem._id) {
|
|
645
645
|
const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
|
|
646
|
-
|
|
646
|
+
const sameFormIdResources = targetCartItem._origin.resources.filter((n) => n.form_id === m.form_id);
|
|
647
|
+
if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
return !sameFormIdResources.some((targetRes) => {
|
|
647
651
|
var _a3, _b, _c;
|
|
648
652
|
if (targetRes.resourceType !== "single") {
|
|
649
653
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
@@ -656,10 +660,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
656
660
|
const originResource = allOriginResources.find(
|
|
657
661
|
(n) => n.id === targetRes.id
|
|
658
662
|
);
|
|
659
|
-
if (currentResourcesCapacityMap[
|
|
663
|
+
if (currentResourcesCapacityMap[m.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
|
|
660
664
|
return true;
|
|
661
665
|
}
|
|
662
|
-
currentResourcesCapacityMap[
|
|
666
|
+
currentResourcesCapacityMap[m.id] += currentCapacity;
|
|
663
667
|
return false;
|
|
664
668
|
}
|
|
665
669
|
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
@@ -1982,23 +1986,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1982
1986
|
}
|
|
1983
1987
|
async getAvailableDateForSessionOptimize(params = {}) {
|
|
1984
1988
|
var _a, _b, _c, _d, _e, _f;
|
|
1985
|
-
const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
|
|
1986
|
-
if (cache) {
|
|
1987
|
-
if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
|
|
1988
|
-
return {
|
|
1989
|
-
dateList: cache.dateList,
|
|
1990
|
-
firstAvailableDate: cache.firstAvailableDate
|
|
1991
|
-
};
|
|
1992
|
-
}
|
|
1993
|
-
}
|
|
1994
1989
|
let { startDate, endDate } = params;
|
|
1995
1990
|
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
|
|
1996
1991
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1997
1992
|
}
|
|
1998
1993
|
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1999
1994
|
let tempProducts;
|
|
2000
|
-
tempProducts = (
|
|
2001
|
-
const schedule = (
|
|
1995
|
+
tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
|
|
1996
|
+
const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
|
|
2002
1997
|
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
2003
1998
|
schedule,
|
|
2004
1999
|
startDate || "",
|
|
@@ -2012,6 +2007,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2012
2007
|
resource_ids: tempResourceIds
|
|
2013
2008
|
}
|
|
2014
2009
|
});
|
|
2010
|
+
const cache = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["timeSlotBySchedule"];
|
|
2011
|
+
if (cache) {
|
|
2012
|
+
if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
|
|
2013
|
+
return {
|
|
2014
|
+
dateList: cache.dateList,
|
|
2015
|
+
firstAvailableDate: cache.firstAvailableDate
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
}
|
|
2015
2019
|
let dates = [];
|
|
2016
2020
|
let currentDate = (0, import_dayjs.default)(startDate);
|
|
2017
2021
|
let firstAvailableDate = "";
|
|
@@ -2019,6 +2023,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2019
2023
|
(m) => m.status === 1
|
|
2020
2024
|
)) || [];
|
|
2021
2025
|
const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
|
|
2026
|
+
allProductResources.forEach((m) => {
|
|
2027
|
+
var _a2, _b2;
|
|
2028
|
+
const resource = (_b2 = (_a2 = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _a2.resources) == null ? void 0 : _b2.find(
|
|
2029
|
+
(n) => n.id === m.form_id
|
|
2030
|
+
);
|
|
2031
|
+
if (resource) {
|
|
2032
|
+
m.resourceType = resource.type;
|
|
2033
|
+
}
|
|
2034
|
+
});
|
|
2022
2035
|
const targetSchedules = this.store.schedule.getScheduleListByIds(
|
|
2023
2036
|
tempProducts["schedule.ids"]
|
|
2024
2037
|
);
|