@pisell/pisellos 0.0.107 → 0.0.108
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/Date/index.d.ts +1 -0
- package/dist/modules/Date/index.js +65 -34
- package/dist/solution/BookingByStep/index.d.ts +8 -6
- package/dist/solution/BookingByStep/index.js +201 -41
- package/dist/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/dist/solution/BookingByStep/utils/resources.js +100 -1
- package/lib/modules/Date/index.d.ts +1 -0
- package/lib/modules/Date/index.js +20 -10
- package/lib/solution/BookingByStep/index.d.ts +8 -6
- package/lib/solution/BookingByStep/index.js +191 -49
- package/lib/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/lib/solution/BookingByStep/utils/resources.js +73 -2
- package/package.json +1 -1
|
@@ -782,4 +782,103 @@ export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resour
|
|
|
782
782
|
}
|
|
783
783
|
});
|
|
784
784
|
}
|
|
785
|
-
};
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* @title: 根据日期范围过滤日程
|
|
789
|
+
*
|
|
790
|
+
* @export
|
|
791
|
+
* @param {any[]} schedule
|
|
792
|
+
* @param {string} startDate
|
|
793
|
+
* @param {string} endDate
|
|
794
|
+
* @return {*}
|
|
795
|
+
*/
|
|
796
|
+
export function filterScheduleByDateRange(schedule, startDate, endDate) {
|
|
797
|
+
if (!(schedule !== null && schedule !== void 0 && schedule.length)) return [];
|
|
798
|
+
var start = new Date(startDate);
|
|
799
|
+
var end = new Date(endDate);
|
|
800
|
+
return schedule.filter(function (item) {
|
|
801
|
+
var itemDate = new Date(item.date);
|
|
802
|
+
return itemDate >= start && itemDate <= end;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* 传入商品数据,返回基于商品配置的提前量的最早开始日期和最晚结束日期
|
|
808
|
+
*
|
|
809
|
+
* @export
|
|
810
|
+
* @param {ProductData} product
|
|
811
|
+
* @return {*}
|
|
812
|
+
*/
|
|
813
|
+
export function checkSessionProductLeadTime(product) {
|
|
814
|
+
var latestStartDate = ''; // 最晚开始日期
|
|
815
|
+
var earliestEndDate = ''; // 最早结束日期
|
|
816
|
+
var _product$cut_off_time = product.cut_off_time,
|
|
817
|
+
future_day = _product$cut_off_time.future_day,
|
|
818
|
+
unit = _product$cut_off_time.unit,
|
|
819
|
+
unit_type = _product$cut_off_time.unit_type;
|
|
820
|
+
// 预定天数存在,则开始计算从当前时间开始往后推预定天数作为结束时间
|
|
821
|
+
if (future_day) {
|
|
822
|
+
var endDate = dayjs().add(future_day, 'day');
|
|
823
|
+
if (!earliestEndDate || endDate.isBefore(dayjs(earliestEndDate), 'day')) {
|
|
824
|
+
earliestEndDate = endDate.format('YYYY-MM-DD');
|
|
825
|
+
}
|
|
826
|
+
} else if (future_day === 0) {
|
|
827
|
+
var _endDate = dayjs();
|
|
828
|
+
if (!earliestEndDate || _endDate.isBefore(dayjs(earliestEndDate), 'day')) {
|
|
829
|
+
earliestEndDate = _endDate.format('YYYY-MM-DD');
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
// 如果存在提前预约时间,则开始计算从当前时间开始往后推提前预约时间作为开始时间
|
|
833
|
+
if (unit && unit_type) {
|
|
834
|
+
var startDate = dayjs(dayjs().add(unit, unit_type).format('YYYY-MM-DD'));
|
|
835
|
+
if (!latestStartDate || startDate.isAfter(dayjs(latestStartDate), 'day')) {
|
|
836
|
+
latestStartDate = startDate.format('YYYY-MM-DD');
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
return {
|
|
840
|
+
latestStartDate: latestStartDate,
|
|
841
|
+
earliestEndDate: earliestEndDate
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* 基于商品的 resources 配置,返回可选择的资源的 id 列表
|
|
847
|
+
*
|
|
848
|
+
* @export
|
|
849
|
+
* @param {ProductData} product
|
|
850
|
+
* @return {*}
|
|
851
|
+
*/
|
|
852
|
+
export function getResourcesIdsByProduct(product) {
|
|
853
|
+
var _product$product_reso, _product$product_reso2;
|
|
854
|
+
var tempResourceIds = [];
|
|
855
|
+
product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 || (_product$product_reso = _product$product_reso.resources) === null || _product$product_reso === void 0 || (_product$product_reso2 = _product$product_reso.forEach) === null || _product$product_reso2 === void 0 || _product$product_reso2.call(_product$product_reso, function (resource) {
|
|
856
|
+
if ((resource === null || resource === void 0 ? void 0 : resource.status) == 1) {
|
|
857
|
+
var _resource$default_res, _resource$optional_re;
|
|
858
|
+
if (resource !== null && resource !== void 0 && (_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.length) {
|
|
859
|
+
tempResourceIds.push.apply(tempResourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.default_resource));
|
|
860
|
+
} else if (resource !== null && resource !== void 0 && (_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.length) {
|
|
861
|
+
tempResourceIds.push.apply(tempResourceIds, _toConsumableArray(resource === null || resource === void 0 ? void 0 : resource.optional_resource));
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
});
|
|
865
|
+
return tempResourceIds;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* 资源排序,把单个资源靠前,组合资源排在后面
|
|
870
|
+
*
|
|
871
|
+
* @export
|
|
872
|
+
* @param {ResourceItem[]} resourcesList
|
|
873
|
+
* @return {*}
|
|
874
|
+
*/
|
|
875
|
+
export function sortCombinedResources(resourcesList) {
|
|
876
|
+
var newResourcesList = _toConsumableArray(resourcesList);
|
|
877
|
+
newResourcesList.sort(function (a, b) {
|
|
878
|
+
var _a$metadata2, _b$metadata2;
|
|
879
|
+
var aIsCombined = ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 || (_a$metadata2 = _a$metadata2.combined_resource) === null || _a$metadata2 === void 0 ? void 0 : _a$metadata2.status) === 1;
|
|
880
|
+
var bIsCombined = ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 || (_b$metadata2 = _b$metadata2.combined_resource) === null || _b$metadata2 === void 0 ? void 0 : _b$metadata2.status) === 1;
|
|
881
|
+
return aIsCombined === bIsCombined ? 0 : aIsCombined ? 1 : -1;
|
|
882
|
+
});
|
|
883
|
+
return newResourcesList;
|
|
884
|
+
}
|
|
@@ -15,6 +15,7 @@ export declare class DateModule extends BaseModule implements Module, DateModule
|
|
|
15
15
|
getDateRange(): ITime[];
|
|
16
16
|
getResourceDates(params: IGetAvailableTimeListParams): Promise<ITime[]>;
|
|
17
17
|
getDateList(): ITime[];
|
|
18
|
+
fetchResourceDates(params: IGetAvailableTimeListParams): Promise<any>;
|
|
18
19
|
getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
|
|
19
20
|
clearDateRange(): void;
|
|
20
21
|
storeChange(): void;
|
|
@@ -65,18 +65,10 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
65
65
|
getDateList() {
|
|
66
66
|
return this.store.dateList;
|
|
67
67
|
}
|
|
68
|
-
async
|
|
69
|
-
|
|
70
|
-
const { url, query, rules, type } = params;
|
|
68
|
+
async fetchResourceDates(params) {
|
|
69
|
+
const { url, query } = params;
|
|
71
70
|
const fetchUrl = url || "/schedule/resource/list";
|
|
72
71
|
const { start_date, end_date, resource_ids } = query || {};
|
|
73
|
-
if (!start_date || !end_date) {
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
|
|
77
|
-
if (!(resource_ids == null ? void 0 : resource_ids.length)) {
|
|
78
|
-
return (0, import_utils.disableAllDates)(dates);
|
|
79
|
-
}
|
|
80
72
|
try {
|
|
81
73
|
const res = await this.request.get(fetchUrl, {
|
|
82
74
|
start_date,
|
|
@@ -86,6 +78,24 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
86
78
|
}, {
|
|
87
79
|
useCache: true
|
|
88
80
|
});
|
|
81
|
+
return res;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(error);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async getResourceAvailableTimeList(params) {
|
|
87
|
+
var _a;
|
|
88
|
+
const { query, rules, type } = params;
|
|
89
|
+
const { start_date, end_date, resource_ids } = query || {};
|
|
90
|
+
if (!start_date || !end_date) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
let dates = (0, import_utils.generateMonthDates)(start_date, end_date, type);
|
|
94
|
+
if (!(resource_ids == null ? void 0 : resource_ids.length)) {
|
|
95
|
+
return (0, import_utils.disableAllDates)(dates);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const res = await this.fetchResourceDates(params);
|
|
89
99
|
if (!((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.length)) {
|
|
90
100
|
return (0, import_utils.disableAllDates)(dates);
|
|
91
101
|
}
|
|
@@ -5,7 +5,7 @@ import { BookingByStepState } from './types';
|
|
|
5
5
|
import { CartItem, IUpdateItemParams, ProductData, ProductResourceItem, ECartItemInfoType, ECartItemCheckType } from '../../modules';
|
|
6
6
|
import { Account } from '../../modules/Account/types';
|
|
7
7
|
import { IStep } from '../../modules/Step/tyeps';
|
|
8
|
-
import { TimeSliceItem } from './utils/resources';
|
|
8
|
+
import { TimeSliceItem, ResourceItem } from './utils/resources';
|
|
9
9
|
import { ITime } from '../../modules/Date/types';
|
|
10
10
|
import dayjs from 'dayjs';
|
|
11
11
|
import { IHolder, IFetchHolderAccountsParams } from '../../modules/AccountList/types';
|
|
@@ -153,7 +153,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
153
153
|
id: number | undefined;
|
|
154
154
|
_id: string;
|
|
155
155
|
product: ProductData | undefined;
|
|
156
|
-
resources:
|
|
156
|
+
resources: ResourceItem[];
|
|
157
157
|
holder_id: string | number | undefined;
|
|
158
158
|
holder_name: string | undefined;
|
|
159
159
|
} | undefined;
|
|
@@ -189,7 +189,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
189
189
|
private getScheduleDataByIds;
|
|
190
190
|
openProductDetail(productId: number): Promise<void>;
|
|
191
191
|
closeProductDetail(): void;
|
|
192
|
-
getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
|
|
192
|
+
getTimeslotBySchedule({ date, scheduleIds, resources, product, }: {
|
|
193
193
|
date: string;
|
|
194
194
|
scheduleIds?: number[];
|
|
195
195
|
resources?: ProductResourceItem[];
|
|
@@ -221,9 +221,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
221
221
|
* @memberof BookingByStepImpl
|
|
222
222
|
*/
|
|
223
223
|
getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
|
|
224
|
-
|
|
224
|
+
getAvailableDateForSessionOptimize(params?: {
|
|
225
225
|
startDate?: string;
|
|
226
226
|
endDate?: string;
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
}): Promise<{
|
|
228
|
+
dateList: any;
|
|
229
|
+
firstAvailableDate: any;
|
|
230
|
+
}>;
|
|
229
231
|
}
|
|
@@ -37,10 +37,14 @@ var import_types = require("./types");
|
|
|
37
37
|
var import_products = require("./utils/products");
|
|
38
38
|
var import_resources = require("./utils/resources");
|
|
39
39
|
var import_dayjs = __toESM(require("dayjs"));
|
|
40
|
+
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
|
|
41
|
+
var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
|
|
40
42
|
var import_utils = require("../../modules/Resource/utils");
|
|
41
43
|
var import_lodash_es = require("lodash-es");
|
|
42
44
|
var import_utils2 = require("../../modules/Schedule/utils");
|
|
43
45
|
var import_utils3 = require("../../modules/Date/utils");
|
|
46
|
+
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
47
|
+
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
44
48
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
45
49
|
constructor() {
|
|
46
50
|
super(...arguments);
|
|
@@ -242,16 +246,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
242
246
|
});
|
|
243
247
|
for (const item of cartItems) {
|
|
244
248
|
const targetProduct = res.find((n) => n.id === item.id);
|
|
245
|
-
const cartProduct = await this.store.products.getProduct(
|
|
249
|
+
const cartProduct = await this.store.products.getProduct(
|
|
250
|
+
item.id
|
|
251
|
+
);
|
|
246
252
|
const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
|
|
247
253
|
let bundle = item._bundleOrigin;
|
|
248
254
|
productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
|
|
249
255
|
productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
|
|
250
256
|
bundle = bundle == null ? void 0 : bundle.map((n) => {
|
|
251
257
|
var _a2;
|
|
252
|
-
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
258
|
+
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
259
|
+
(m) => m.id === n.group_id
|
|
260
|
+
);
|
|
253
261
|
if (targetBundle) {
|
|
254
|
-
const targetBundleItem = targetBundle.bundle_item.find(
|
|
262
|
+
const targetBundleItem = targetBundle.bundle_item.find(
|
|
263
|
+
(m) => m.id === n.id
|
|
264
|
+
);
|
|
255
265
|
if (targetBundleItem) {
|
|
256
266
|
return {
|
|
257
267
|
...n,
|
|
@@ -268,13 +278,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
268
278
|
bundle
|
|
269
279
|
});
|
|
270
280
|
}
|
|
271
|
-
;
|
|
272
281
|
}
|
|
273
282
|
}
|
|
274
283
|
// 加载当前店铺下所有 schedule
|
|
275
284
|
async loadAllSchedule() {
|
|
276
285
|
var _a;
|
|
277
|
-
const scheduleList = await this.request.get(
|
|
286
|
+
const scheduleList = await this.request.get(
|
|
287
|
+
`/schedule`,
|
|
288
|
+
{ num: 999 },
|
|
289
|
+
{ useCache: true }
|
|
290
|
+
);
|
|
278
291
|
this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
|
|
279
292
|
}
|
|
280
293
|
// ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
|
|
@@ -627,8 +640,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
627
640
|
capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
|
|
628
641
|
product_bundle: item._origin.product.product_bundle
|
|
629
642
|
});
|
|
630
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
631
|
-
|
|
643
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
644
|
+
capacity: formatCapacity
|
|
645
|
+
});
|
|
646
|
+
const originResource = allOriginResources.find(
|
|
647
|
+
(n) => n.id === targetRes.id
|
|
648
|
+
);
|
|
632
649
|
if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
|
|
633
650
|
return true;
|
|
634
651
|
}
|
|
@@ -651,7 +668,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
651
668
|
}
|
|
652
669
|
)))
|
|
653
670
|
return true;
|
|
654
|
-
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
671
|
+
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
672
|
+
targetRes.id
|
|
673
|
+
))
|
|
655
674
|
return true;
|
|
656
675
|
}
|
|
657
676
|
return false;
|
|
@@ -666,8 +685,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
666
685
|
_id: item._id,
|
|
667
686
|
resources,
|
|
668
687
|
date: {
|
|
669
|
-
startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
|
|
670
|
-
|
|
688
|
+
startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
|
|
689
|
+
"YYYY-MM-DD HH:mm"
|
|
690
|
+
),
|
|
691
|
+
endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format(
|
|
692
|
+
"YYYY-MM-DD HH:mm"
|
|
693
|
+
)
|
|
671
694
|
}
|
|
672
695
|
});
|
|
673
696
|
} else {
|
|
@@ -1147,10 +1170,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1147
1170
|
if (mTimes.length === 0) {
|
|
1148
1171
|
continue;
|
|
1149
1172
|
}
|
|
1150
|
-
const totalCapacity = (countMap[n.id] || []).reduce(
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1173
|
+
const totalCapacity = (countMap[n.id] || []).reduce(
|
|
1174
|
+
(sum, item) => {
|
|
1175
|
+
const hasOverlap = !(0, import_dayjs.default)(item.time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(item.time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
|
|
1176
|
+
return hasOverlap ? sum + item.pax : sum;
|
|
1177
|
+
},
|
|
1178
|
+
0
|
|
1179
|
+
);
|
|
1154
1180
|
const canUseTime = mTimes.find((item) => {
|
|
1155
1181
|
var _a2;
|
|
1156
1182
|
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
@@ -1228,7 +1254,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1228
1254
|
};
|
|
1229
1255
|
}
|
|
1230
1256
|
if (recordTimeSlots) {
|
|
1231
|
-
const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
|
|
1257
|
+
const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
|
|
1258
|
+
(n) => n.code === resources_code
|
|
1259
|
+
);
|
|
1232
1260
|
const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
|
|
1233
1261
|
if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
|
|
1234
1262
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
@@ -1407,7 +1435,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1407
1435
|
(n) => n.code === resources_code
|
|
1408
1436
|
)) == null ? void 0 : _g.id;
|
|
1409
1437
|
if (((_h = item._productOrigin) == null ? void 0 : _h.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
|
|
1410
|
-
const currentCutOffTime = (0, import_dayjs.default)().add(
|
|
1438
|
+
const currentCutOffTime = (0, import_dayjs.default)().add(
|
|
1439
|
+
item._productOrigin.cut_off_time.unit,
|
|
1440
|
+
item._productOrigin.cut_off_time.unit_type
|
|
1441
|
+
);
|
|
1411
1442
|
if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
|
|
1412
1443
|
maxCutOffTimeValue = currentCutOffTime;
|
|
1413
1444
|
maxCutOffTime = item._productOrigin.cut_off_time;
|
|
@@ -1599,7 +1630,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1599
1630
|
date
|
|
1600
1631
|
);
|
|
1601
1632
|
const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1602
|
-
console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
|
|
1603
1633
|
let allProductResources = productResources.flatMap((n) => n.renderList);
|
|
1604
1634
|
allProductResources.sort((a, b) => {
|
|
1605
1635
|
var _a2, _b2, _c2, _d;
|
|
@@ -1645,7 +1675,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1645
1675
|
}
|
|
1646
1676
|
currentResourcesTimeSlotCanUsedArr.push(res.usable);
|
|
1647
1677
|
});
|
|
1648
|
-
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1678
|
+
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1679
|
+
(n) => n === false
|
|
1680
|
+
) && currentResourcesCount >= count) {
|
|
1649
1681
|
count = currentResourcesCount;
|
|
1650
1682
|
}
|
|
1651
1683
|
});
|
|
@@ -1717,7 +1749,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1717
1749
|
*
|
|
1718
1750
|
* @param {string} cartItemId
|
|
1719
1751
|
* @param {string} resourceCode
|
|
1720
|
-
* @return {*}
|
|
1752
|
+
* @return {*}
|
|
1721
1753
|
* @memberof BookingByStepImpl
|
|
1722
1754
|
*/
|
|
1723
1755
|
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
@@ -1768,7 +1800,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1768
1800
|
selectedResources,
|
|
1769
1801
|
currentCapacity
|
|
1770
1802
|
);
|
|
1771
|
-
const targetResource = productResources.find(
|
|
1803
|
+
const targetResource = productResources.find(
|
|
1804
|
+
(resource) => resource.code === resourceCode
|
|
1805
|
+
);
|
|
1772
1806
|
if (!targetResource)
|
|
1773
1807
|
return [];
|
|
1774
1808
|
if (cartItem._origin.start_time) {
|
|
@@ -1779,16 +1813,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1779
1813
|
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
1780
1814
|
);
|
|
1781
1815
|
const resourcesUseableMap = {};
|
|
1782
|
-
targetResource.renderList = targetResource.renderList.sort(
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1816
|
+
targetResource.renderList = targetResource.renderList.sort(
|
|
1817
|
+
(a, b) => {
|
|
1818
|
+
var _a2, _b2, _c2, _d;
|
|
1819
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1820
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1821
|
+
if (aIsCombined && !bIsCombined)
|
|
1822
|
+
return 1;
|
|
1823
|
+
if (!aIsCombined && bIsCombined)
|
|
1824
|
+
return -1;
|
|
1825
|
+
return 0;
|
|
1826
|
+
}
|
|
1827
|
+
);
|
|
1792
1828
|
targetResource.renderList = targetResource.renderList.filter((m) => {
|
|
1793
1829
|
const mTimes = m.times.filter((n) => {
|
|
1794
1830
|
return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
|
|
@@ -1836,33 +1872,139 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1836
1872
|
}
|
|
1837
1873
|
return targetResource.renderList;
|
|
1838
1874
|
}
|
|
1839
|
-
async
|
|
1840
|
-
|
|
1875
|
+
async getAvailableDateForSessionOptimize(params = {}) {
|
|
1876
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1877
|
+
const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
|
|
1878
|
+
if (cache) {
|
|
1879
|
+
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")) {
|
|
1880
|
+
return {
|
|
1881
|
+
dateList: cache.dateList,
|
|
1882
|
+
firstAvailableDate: cache.firstAvailableDate
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
let { startDate, endDate } = params;
|
|
1841
1887
|
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"))) {
|
|
1842
1888
|
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1843
1889
|
}
|
|
1844
1890
|
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1845
|
-
let tempProducts
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
const
|
|
1855
|
-
this.otherParams.currentResourcesMap = resourcesMap;
|
|
1856
|
-
const res = await this.store.date.getResourceDates({
|
|
1891
|
+
let tempProducts;
|
|
1892
|
+
tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
|
|
1893
|
+
const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
|
|
1894
|
+
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
1895
|
+
schedule,
|
|
1896
|
+
startDate || "",
|
|
1897
|
+
endDate || ""
|
|
1898
|
+
);
|
|
1899
|
+
const tempResourceIds = (0, import_resources.getResourcesIdsByProduct)(tempProducts);
|
|
1900
|
+
const res = await this.store.date.fetchResourceDates({
|
|
1857
1901
|
query: {
|
|
1858
1902
|
start_date: startDate || "",
|
|
1859
1903
|
end_date: endDate || "",
|
|
1860
|
-
resource_ids:
|
|
1861
|
-
}
|
|
1862
|
-
rules,
|
|
1863
|
-
type
|
|
1904
|
+
resource_ids: tempResourceIds
|
|
1905
|
+
}
|
|
1864
1906
|
});
|
|
1865
|
-
|
|
1907
|
+
const dates = [];
|
|
1908
|
+
let currentDate = (0, import_dayjs.default)(startDate);
|
|
1909
|
+
let firstAvailableDate = "";
|
|
1910
|
+
const openResources = ((_e = (_d = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.filter(
|
|
1911
|
+
(m) => m.status === 1
|
|
1912
|
+
)) || [];
|
|
1913
|
+
const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
|
|
1914
|
+
const targetSchedules = this.store.schedule.getScheduleListByIds(
|
|
1915
|
+
tempProducts["schedule.ids"]
|
|
1916
|
+
);
|
|
1917
|
+
while ((0, import_dayjs.default)(currentDate).isBefore((0, import_dayjs.default)(endDate), "day") || (0, import_dayjs.default)(currentDate).isSame((0, import_dayjs.default)(endDate), "day")) {
|
|
1918
|
+
const currentDateStr = currentDate.format("YYYY-MM-DD");
|
|
1919
|
+
let status = "available";
|
|
1920
|
+
const { latestStartDate, earliestEndDate } = (0, import_resources.checkSessionProductLeadTime)(tempProducts);
|
|
1921
|
+
if (latestStartDate || earliestEndDate) {
|
|
1922
|
+
if (latestStartDate && (0, import_dayjs.default)(currentDate).isBefore(latestStartDate, "day")) {
|
|
1923
|
+
status = "unavailable";
|
|
1924
|
+
}
|
|
1925
|
+
if (earliestEndDate && (0, import_dayjs.default)(currentDate).isAfter(earliestEndDate, "day")) {
|
|
1926
|
+
status = "unavailable";
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
if (status === "available") {
|
|
1930
|
+
const scheduleByDate = filteredSchedule.find(
|
|
1931
|
+
(n) => n.date === currentDateStr
|
|
1932
|
+
);
|
|
1933
|
+
if (!scheduleByDate || (scheduleByDate == null ? void 0 : scheduleByDate.isExcluded)) {
|
|
1934
|
+
status = "unavailable";
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
if (status === "available") {
|
|
1938
|
+
const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
|
|
1939
|
+
targetSchedules,
|
|
1940
|
+
{},
|
|
1941
|
+
currentDateStr
|
|
1942
|
+
);
|
|
1943
|
+
const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1944
|
+
const timesSlotCanUse = scheduleTimeSlots.some((item) => {
|
|
1945
|
+
const resourcesUseableMap = {};
|
|
1946
|
+
return openResources.every((resource) => {
|
|
1947
|
+
const currentResourcesList = allProductResources.filter(
|
|
1948
|
+
(n) => n.form_id === resource.resource_type_id
|
|
1949
|
+
);
|
|
1950
|
+
return currentResourcesList == null ? void 0 : currentResourcesList.some((m) => {
|
|
1951
|
+
const mTimes = m.times.filter((n) => {
|
|
1952
|
+
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");
|
|
1953
|
+
});
|
|
1954
|
+
if (mTimes.length === 0) {
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
const targetCanUseTimes = mTimes.some((childTiem) => {
|
|
1958
|
+
const res2 = (0, import_resources.getIsUsableByTimeItem)({
|
|
1959
|
+
timeSlice: {
|
|
1960
|
+
start_time: item.start,
|
|
1961
|
+
end_time: item.end,
|
|
1962
|
+
start_at: (0, import_dayjs.default)(item.start),
|
|
1963
|
+
end_at: (0, import_dayjs.default)(item.end)
|
|
1964
|
+
},
|
|
1965
|
+
time: childTiem,
|
|
1966
|
+
resource: m,
|
|
1967
|
+
currentCount: 1,
|
|
1968
|
+
resourcesUseableMap,
|
|
1969
|
+
cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
|
|
1970
|
+
});
|
|
1971
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
|
|
1972
|
+
resourcesUseableMap[m.id] = res2.usable;
|
|
1973
|
+
}
|
|
1974
|
+
return res2.usable && !m.onlyComputed;
|
|
1975
|
+
});
|
|
1976
|
+
return targetCanUseTimes;
|
|
1977
|
+
});
|
|
1978
|
+
});
|
|
1979
|
+
});
|
|
1980
|
+
if (!timesSlotCanUse) {
|
|
1981
|
+
status = "unavailable";
|
|
1982
|
+
}
|
|
1983
|
+
if (status === "available" && !firstAvailableDate) {
|
|
1984
|
+
firstAvailableDate = currentDateStr;
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
dates.push({
|
|
1988
|
+
date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
|
|
1989
|
+
week: (0, import_dayjs.default)(currentDate).format("ddd"),
|
|
1990
|
+
weekNum: (0, import_dayjs.default)(currentDate).day(),
|
|
1991
|
+
status
|
|
1992
|
+
});
|
|
1993
|
+
if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 14) {
|
|
1994
|
+
break;
|
|
1995
|
+
}
|
|
1996
|
+
currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
|
|
1997
|
+
}
|
|
1998
|
+
(_f = this.store.currentProduct) == null ? void 0 : _f.setOtherParams("timeSlotBySchedule", {
|
|
1999
|
+
dateList: dates,
|
|
2000
|
+
firstAvailableDate,
|
|
2001
|
+
startDate,
|
|
2002
|
+
endDate
|
|
2003
|
+
});
|
|
2004
|
+
return {
|
|
2005
|
+
dateList: dates,
|
|
2006
|
+
firstAvailableDate
|
|
2007
|
+
};
|
|
1866
2008
|
}
|
|
1867
2009
|
};
|
|
1868
2010
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dayjs } from 'dayjs';
|
|
2
|
-
import { CartItem } from '../../../modules';
|
|
2
|
+
import { CartItem, ProductData } from '../../../modules';
|
|
3
3
|
/**
|
|
4
4
|
* 1. 获取资源列表
|
|
5
5
|
* 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
|
|
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
|
|
|
79
79
|
* @return {*}
|
|
80
80
|
* @Author: zhiwei.Wang
|
|
81
81
|
*/
|
|
82
|
-
export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
|
|
82
|
+
export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, }: {
|
|
83
83
|
resource: ResourceItem;
|
|
84
84
|
duration: number;
|
|
85
85
|
split: number;
|
|
@@ -133,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
|
|
|
133
133
|
* @return {*}
|
|
134
134
|
* @Author: zhiwei.Wang
|
|
135
135
|
*/
|
|
136
|
-
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
|
|
136
|
+
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, }: {
|
|
137
137
|
resourceIds: number[];
|
|
138
138
|
resourcesMap: any;
|
|
139
139
|
duration: number;
|
|
@@ -201,4 +201,41 @@ export declare const getSumCapacity: ({ capacity }: {
|
|
|
201
201
|
* @Author: jinglin.tan
|
|
202
202
|
*/
|
|
203
203
|
export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
|
|
204
|
+
/**
|
|
205
|
+
* @title: 根据日期范围过滤日程
|
|
206
|
+
*
|
|
207
|
+
* @export
|
|
208
|
+
* @param {any[]} schedule
|
|
209
|
+
* @param {string} startDate
|
|
210
|
+
* @param {string} endDate
|
|
211
|
+
* @return {*}
|
|
212
|
+
*/
|
|
213
|
+
export declare function filterScheduleByDateRange(schedule: any[], startDate: string, endDate: string): any[];
|
|
214
|
+
/**
|
|
215
|
+
* 传入商品数据,返回基于商品配置的提前量的最早开始日期和最晚结束日期
|
|
216
|
+
*
|
|
217
|
+
* @export
|
|
218
|
+
* @param {ProductData} product
|
|
219
|
+
* @return {*}
|
|
220
|
+
*/
|
|
221
|
+
export declare function checkSessionProductLeadTime(product: ProductData): {
|
|
222
|
+
latestStartDate: string;
|
|
223
|
+
earliestEndDate: string;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* 基于商品的 resources 配置,返回可选择的资源的 id 列表
|
|
227
|
+
*
|
|
228
|
+
* @export
|
|
229
|
+
* @param {ProductData} product
|
|
230
|
+
* @return {*}
|
|
231
|
+
*/
|
|
232
|
+
export declare function getResourcesIdsByProduct(product: ProductData): number[];
|
|
233
|
+
/**
|
|
234
|
+
* 资源排序,把单个资源靠前,组合资源排在后面
|
|
235
|
+
*
|
|
236
|
+
* @export
|
|
237
|
+
* @param {ResourceItem[]} resourcesList
|
|
238
|
+
* @return {*}
|
|
239
|
+
*/
|
|
240
|
+
export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
|
|
204
241
|
export {};
|