@pisell/pisellos 3.0.31 → 3.0.33
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 +2 -0
- package/dist/modules/Date/index.js +70 -34
- package/dist/modules/Rules/index.js +1 -1
- package/dist/modules/Schedule/types.d.ts +1 -0
- package/dist/modules/Schedule/utils.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +26 -5
- package/dist/solution/BookingByStep/index.js +358 -27
- package/dist/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/dist/solution/BookingByStep/utils/resources.js +100 -1
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +209 -0
- package/lib/modules/Date/index.d.ts +2 -0
- package/lib/modules/Date/index.js +23 -10
- package/lib/modules/Rules/index.js +2 -2
- package/lib/modules/Schedule/types.d.ts +1 -0
- package/lib/modules/Schedule/utils.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +26 -5
- package/lib/solution/BookingByStep/index.js +280 -34
- package/lib/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/lib/solution/BookingByStep/utils/resources.js +73 -2
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +159 -0
- package/package.json +1 -1
|
@@ -37,10 +37,15 @@ 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
|
+
var import_timeslots = require("./utils/timeslots");
|
|
47
|
+
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
48
|
+
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
44
49
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
45
50
|
constructor() {
|
|
46
51
|
super(...arguments);
|
|
@@ -211,12 +216,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
211
216
|
product_ids,
|
|
212
217
|
category_ids = []
|
|
213
218
|
}) {
|
|
219
|
+
var _a;
|
|
214
220
|
const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
|
|
215
221
|
this.setDateRange([
|
|
216
222
|
{ date, status: "available", week: "", weekNum: 0 },
|
|
217
223
|
{ date, status: "available", week: "", weekNum: 0 }
|
|
218
224
|
]);
|
|
219
|
-
const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
|
|
225
|
+
const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id).filter((n) => n !== null && n !== void 0);
|
|
226
|
+
if (!(product_ids == null ? void 0 : product_ids.length)) {
|
|
227
|
+
const schedule = scheduleList.find((n) => n.date === date);
|
|
228
|
+
if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
|
|
229
|
+
product_ids = schedule.product_ids;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
220
232
|
return await this.loadProducts({
|
|
221
233
|
schedule_ids: scheduleIds,
|
|
222
234
|
product_ids,
|
|
@@ -242,16 +254,22 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
242
254
|
});
|
|
243
255
|
for (const item of cartItems) {
|
|
244
256
|
const targetProduct = res.find((n) => n.id === item.id);
|
|
245
|
-
const cartProduct = await this.store.products.getProduct(
|
|
257
|
+
const cartProduct = await this.store.products.getProduct(
|
|
258
|
+
item.id
|
|
259
|
+
);
|
|
246
260
|
const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
|
|
247
261
|
let bundle = item._bundleOrigin;
|
|
248
262
|
productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
|
|
249
263
|
productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
|
|
250
264
|
bundle = bundle == null ? void 0 : bundle.map((n) => {
|
|
251
265
|
var _a2;
|
|
252
|
-
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
266
|
+
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
267
|
+
(m) => m.id === n.group_id
|
|
268
|
+
);
|
|
253
269
|
if (targetBundle) {
|
|
254
|
-
const targetBundleItem = targetBundle.bundle_item.find(
|
|
270
|
+
const targetBundleItem = targetBundle.bundle_item.find(
|
|
271
|
+
(m) => m.id === n.id
|
|
272
|
+
);
|
|
255
273
|
if (targetBundleItem) {
|
|
256
274
|
return {
|
|
257
275
|
...n,
|
|
@@ -268,13 +286,16 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
268
286
|
bundle
|
|
269
287
|
});
|
|
270
288
|
}
|
|
271
|
-
;
|
|
272
289
|
}
|
|
273
290
|
}
|
|
274
291
|
// 加载当前店铺下所有 schedule
|
|
275
292
|
async loadAllSchedule() {
|
|
276
293
|
var _a;
|
|
277
|
-
const scheduleList = await this.request.get(
|
|
294
|
+
const scheduleList = await this.request.get(
|
|
295
|
+
`/schedule`,
|
|
296
|
+
{ num: 999 },
|
|
297
|
+
{ useCache: true }
|
|
298
|
+
);
|
|
278
299
|
this.store.schedule.setScheduleList(((_a = scheduleList.data) == null ? void 0 : _a.list) || []);
|
|
279
300
|
}
|
|
280
301
|
// ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
|
|
@@ -627,8 +648,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
627
648
|
capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
|
|
628
649
|
product_bundle: item._origin.product.product_bundle
|
|
629
650
|
});
|
|
630
|
-
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
631
|
-
|
|
651
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({
|
|
652
|
+
capacity: formatCapacity
|
|
653
|
+
});
|
|
654
|
+
const originResource = allOriginResources.find(
|
|
655
|
+
(n) => n.id === targetRes.id
|
|
656
|
+
);
|
|
632
657
|
if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
|
|
633
658
|
return true;
|
|
634
659
|
}
|
|
@@ -651,7 +676,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
651
676
|
}
|
|
652
677
|
)))
|
|
653
678
|
return true;
|
|
654
|
-
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
679
|
+
if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(
|
|
680
|
+
targetRes.id
|
|
681
|
+
))
|
|
655
682
|
return true;
|
|
656
683
|
}
|
|
657
684
|
return false;
|
|
@@ -666,8 +693,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
666
693
|
_id: item._id,
|
|
667
694
|
resources,
|
|
668
695
|
date: {
|
|
669
|
-
startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
|
|
670
|
-
|
|
696
|
+
startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
|
|
697
|
+
"YYYY-MM-DD HH:mm"
|
|
698
|
+
),
|
|
699
|
+
endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format(
|
|
700
|
+
"YYYY-MM-DD HH:mm"
|
|
701
|
+
)
|
|
671
702
|
}
|
|
672
703
|
});
|
|
673
704
|
} else {
|
|
@@ -1140,6 +1171,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1140
1171
|
}, {});
|
|
1141
1172
|
if (timeSlots) {
|
|
1142
1173
|
let targetResource = null;
|
|
1174
|
+
let targetResourceTime = 0;
|
|
1143
1175
|
for (const n of resources) {
|
|
1144
1176
|
const mTimes = n.times.filter((n2) => {
|
|
1145
1177
|
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
|
|
@@ -1147,10 +1179,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1147
1179
|
if (mTimes.length === 0) {
|
|
1148
1180
|
continue;
|
|
1149
1181
|
}
|
|
1150
|
-
const totalCapacity = (countMap[n.id] || []).reduce(
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1182
|
+
const totalCapacity = (countMap[n.id] || []).reduce(
|
|
1183
|
+
(sum, item) => {
|
|
1184
|
+
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));
|
|
1185
|
+
return hasOverlap ? sum + item.pax : sum;
|
|
1186
|
+
},
|
|
1187
|
+
0
|
|
1188
|
+
);
|
|
1154
1189
|
const canUseTime = mTimes.find((item) => {
|
|
1155
1190
|
var _a2;
|
|
1156
1191
|
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
@@ -1166,8 +1201,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1166
1201
|
}
|
|
1167
1202
|
return res.usable;
|
|
1168
1203
|
});
|
|
1169
|
-
|
|
1204
|
+
const currentResourceIdleTime = (0, import_timeslots.calculateResourceAvailableTime)({
|
|
1205
|
+
resource: n,
|
|
1206
|
+
timeSlots,
|
|
1207
|
+
currentCapacity: totalCapacity + (capacity || 0)
|
|
1208
|
+
});
|
|
1209
|
+
if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
|
|
1170
1210
|
targetResource = n;
|
|
1211
|
+
targetResourceTime = currentResourceIdleTime;
|
|
1171
1212
|
break;
|
|
1172
1213
|
}
|
|
1173
1214
|
}
|
|
@@ -1228,7 +1269,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1228
1269
|
};
|
|
1229
1270
|
}
|
|
1230
1271
|
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(
|
|
1272
|
+
const currentResourceConfig = (_d = (_c = (_b = item._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.find(
|
|
1273
|
+
(n) => n.code === resources_code
|
|
1274
|
+
);
|
|
1232
1275
|
const resourceBookingType = (currentResourceConfig == null ? void 0 : currentResourceConfig.type) || "single";
|
|
1233
1276
|
if (index !== 0 && recordTimeSlots && resourceBookingType === "single" && ((_e = item._productOrigin) == null ? void 0 : _e.duration)) {
|
|
1234
1277
|
let start_at = (0, import_dayjs.default)(recordTimeSlots.end_time).add(
|
|
@@ -1347,7 +1390,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1347
1390
|
)) {
|
|
1348
1391
|
return;
|
|
1349
1392
|
}
|
|
1350
|
-
const
|
|
1393
|
+
const fastestResource = (0, import_timeslots.findFastestAvailableResource)({
|
|
1394
|
+
resources: targetRenderList,
|
|
1395
|
+
currentCapacity,
|
|
1396
|
+
countMap: selectResourcesMap
|
|
1397
|
+
});
|
|
1398
|
+
const targetResource = fastestResource || targetRenderList[0];
|
|
1351
1399
|
targetResource.capacity = currentCapacity;
|
|
1352
1400
|
(0, import_resources.checkSubResourcesCapacity)(targetResource);
|
|
1353
1401
|
if (!selectResourcesMap[targetResource.id]) {
|
|
@@ -1407,7 +1455,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1407
1455
|
(n) => n.code === resources_code
|
|
1408
1456
|
)) == null ? void 0 : _g.id;
|
|
1409
1457
|
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(
|
|
1458
|
+
const currentCutOffTime = (0, import_dayjs.default)().add(
|
|
1459
|
+
item._productOrigin.cut_off_time.unit,
|
|
1460
|
+
item._productOrigin.cut_off_time.unit_type
|
|
1461
|
+
);
|
|
1411
1462
|
if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
|
|
1412
1463
|
maxCutOffTimeValue = currentCutOffTime;
|
|
1413
1464
|
maxCutOffTime = item._productOrigin.cut_off_time;
|
|
@@ -1599,7 +1650,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1599
1650
|
date
|
|
1600
1651
|
);
|
|
1601
1652
|
const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1602
|
-
console.log("scheduleTimeSlots:", scheduleTimeSlots, productResources);
|
|
1603
1653
|
let allProductResources = productResources.flatMap((n) => n.renderList);
|
|
1604
1654
|
allProductResources.sort((a, b) => {
|
|
1605
1655
|
var _a2, _b2, _c2, _d;
|
|
@@ -1645,7 +1695,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1645
1695
|
}
|
|
1646
1696
|
currentResourcesTimeSlotCanUsedArr.push(res.usable);
|
|
1647
1697
|
});
|
|
1648
|
-
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1698
|
+
if (!currentResourcesTimeSlotCanUsedArr.some(
|
|
1699
|
+
(n) => n === false
|
|
1700
|
+
) && currentResourcesCount >= count) {
|
|
1649
1701
|
count = currentResourcesCount;
|
|
1650
1702
|
}
|
|
1651
1703
|
});
|
|
@@ -1717,7 +1769,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1717
1769
|
*
|
|
1718
1770
|
* @param {string} cartItemId
|
|
1719
1771
|
* @param {string} resourceCode
|
|
1720
|
-
* @return {*}
|
|
1772
|
+
* @return {*}
|
|
1721
1773
|
* @memberof BookingByStepImpl
|
|
1722
1774
|
*/
|
|
1723
1775
|
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
@@ -1768,7 +1820,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1768
1820
|
selectedResources,
|
|
1769
1821
|
currentCapacity
|
|
1770
1822
|
);
|
|
1771
|
-
const targetResource = productResources.find(
|
|
1823
|
+
const targetResource = productResources.find(
|
|
1824
|
+
(resource) => resource.code === resourceCode
|
|
1825
|
+
);
|
|
1772
1826
|
if (!targetResource)
|
|
1773
1827
|
return [];
|
|
1774
1828
|
if (cartItem._origin.start_time) {
|
|
@@ -1779,16 +1833,18 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1779
1833
|
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
1780
1834
|
);
|
|
1781
1835
|
const resourcesUseableMap = {};
|
|
1782
|
-
targetResource.renderList = targetResource.renderList.sort(
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1836
|
+
targetResource.renderList = targetResource.renderList.sort(
|
|
1837
|
+
(a, b) => {
|
|
1838
|
+
var _a2, _b2, _c2, _d;
|
|
1839
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1840
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1841
|
+
if (aIsCombined && !bIsCombined)
|
|
1842
|
+
return 1;
|
|
1843
|
+
if (!aIsCombined && bIsCombined)
|
|
1844
|
+
return -1;
|
|
1845
|
+
return 0;
|
|
1846
|
+
}
|
|
1847
|
+
);
|
|
1792
1848
|
targetResource.renderList = targetResource.renderList.filter((m) => {
|
|
1793
1849
|
const mTimes = m.times.filter((n) => {
|
|
1794
1850
|
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,6 +1892,38 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1836
1892
|
}
|
|
1837
1893
|
return targetResource.renderList;
|
|
1838
1894
|
}
|
|
1895
|
+
/**
|
|
1896
|
+
* 根据日期范围批量获取时间槽
|
|
1897
|
+
* @param params 参数对象
|
|
1898
|
+
* @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
|
|
1899
|
+
*/
|
|
1900
|
+
async getTimeslotsScheduleByDateRange({
|
|
1901
|
+
startDate,
|
|
1902
|
+
endDate,
|
|
1903
|
+
scheduleIds,
|
|
1904
|
+
resources
|
|
1905
|
+
}) {
|
|
1906
|
+
console.log(
|
|
1907
|
+
"appoimentBooking-session-date-getTimeslotsScheduleByDateRange",
|
|
1908
|
+
{ startDate, endDate, scheduleIds, resources }
|
|
1909
|
+
);
|
|
1910
|
+
const dates = [];
|
|
1911
|
+
let currentDate = (0, import_dayjs.default)(startDate);
|
|
1912
|
+
const end = (0, import_dayjs.default)(endDate);
|
|
1913
|
+
while (currentDate.isSameOrBefore(end)) {
|
|
1914
|
+
dates.push(currentDate.format("YYYY-MM-DD"));
|
|
1915
|
+
currentDate = currentDate.add(1, "day");
|
|
1916
|
+
}
|
|
1917
|
+
const results = {};
|
|
1918
|
+
for (const date of dates) {
|
|
1919
|
+
results[date] = this.getTimeslotBySchedule({
|
|
1920
|
+
date,
|
|
1921
|
+
scheduleIds,
|
|
1922
|
+
resources
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
return results;
|
|
1926
|
+
}
|
|
1839
1927
|
async getAvailableDateForSession(params = {}) {
|
|
1840
1928
|
let { startDate, endDate, type } = params;
|
|
1841
1929
|
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"))) {
|
|
@@ -1862,7 +1950,165 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1862
1950
|
rules,
|
|
1863
1951
|
type
|
|
1864
1952
|
});
|
|
1865
|
-
|
|
1953
|
+
if (this.store.currentProduct) {
|
|
1954
|
+
const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
|
|
1955
|
+
startDate: startDate || "",
|
|
1956
|
+
endDate: endDate || ""
|
|
1957
|
+
});
|
|
1958
|
+
res.forEach((n) => {
|
|
1959
|
+
if (!dateListWithTimeSlots[n.date]) {
|
|
1960
|
+
n.status = "unavailable";
|
|
1961
|
+
} else {
|
|
1962
|
+
const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
|
|
1963
|
+
(d) => d.count
|
|
1964
|
+
);
|
|
1965
|
+
if (!allTimeSlotsCanUse) {
|
|
1966
|
+
n.status = "unavailable";
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
const firstAvailableDate = res.find((n) => n.status === "available");
|
|
1972
|
+
return {
|
|
1973
|
+
dateList: res,
|
|
1974
|
+
firstAvailableDate
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
async getAvailableDateForSessionOptimize(params = {}) {
|
|
1978
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1979
|
+
const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
|
|
1980
|
+
if (cache) {
|
|
1981
|
+
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")) {
|
|
1982
|
+
return {
|
|
1983
|
+
dateList: cache.dateList,
|
|
1984
|
+
firstAvailableDate: cache.firstAvailableDate
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
let { startDate, endDate } = params;
|
|
1989
|
+
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"))) {
|
|
1990
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1991
|
+
}
|
|
1992
|
+
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1993
|
+
let tempProducts;
|
|
1994
|
+
tempProducts = (_b = this.store.currentProduct) == null ? void 0 : _b.getData();
|
|
1995
|
+
const schedule = (_c = this.store.currentProduct) == null ? void 0 : _c.getOtherParams()["schedule"];
|
|
1996
|
+
const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
|
|
1997
|
+
schedule,
|
|
1998
|
+
startDate || "",
|
|
1999
|
+
endDate || ""
|
|
2000
|
+
);
|
|
2001
|
+
const tempResourceIds = (0, import_resources.getResourcesIdsByProduct)(tempProducts);
|
|
2002
|
+
const res = await this.store.date.fetchResourceDates({
|
|
2003
|
+
query: {
|
|
2004
|
+
start_date: startDate || "",
|
|
2005
|
+
end_date: endDate || "",
|
|
2006
|
+
resource_ids: tempResourceIds
|
|
2007
|
+
}
|
|
2008
|
+
});
|
|
2009
|
+
let dates = [];
|
|
2010
|
+
let currentDate = (0, import_dayjs.default)(startDate);
|
|
2011
|
+
let firstAvailableDate = "";
|
|
2012
|
+
const openResources = ((_e = (_d = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _d.resources) == null ? void 0 : _e.filter(
|
|
2013
|
+
(m) => m.status === 1
|
|
2014
|
+
)) || [];
|
|
2015
|
+
const allProductResources = (0, import_resources.sortCombinedResources)(res.data);
|
|
2016
|
+
const targetSchedules = this.store.schedule.getScheduleListByIds(
|
|
2017
|
+
tempProducts["schedule.ids"]
|
|
2018
|
+
);
|
|
2019
|
+
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")) {
|
|
2020
|
+
const currentDateStr = currentDate.format("YYYY-MM-DD");
|
|
2021
|
+
let status = "available";
|
|
2022
|
+
const { latestStartDate, earliestEndDate } = (0, import_resources.checkSessionProductLeadTime)(tempProducts);
|
|
2023
|
+
if (latestStartDate || earliestEndDate) {
|
|
2024
|
+
if (latestStartDate && (0, import_dayjs.default)(currentDate).isBefore(latestStartDate, "day")) {
|
|
2025
|
+
status = "unavailable";
|
|
2026
|
+
}
|
|
2027
|
+
if (earliestEndDate && (0, import_dayjs.default)(currentDate).isAfter(earliestEndDate, "day")) {
|
|
2028
|
+
status = "unavailable";
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
if (status === "available") {
|
|
2032
|
+
const scheduleByDate = filteredSchedule.find(
|
|
2033
|
+
(n) => n.date === currentDateStr
|
|
2034
|
+
);
|
|
2035
|
+
if (!scheduleByDate || (scheduleByDate == null ? void 0 : scheduleByDate.isExcluded)) {
|
|
2036
|
+
status = "unavailable";
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
if (status === "available") {
|
|
2040
|
+
const minTimeMaxTime = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
|
|
2041
|
+
targetSchedules,
|
|
2042
|
+
{},
|
|
2043
|
+
currentDateStr
|
|
2044
|
+
);
|
|
2045
|
+
const scheduleTimeSlots = (0, import_utils2.getAllSortedDateRanges)(minTimeMaxTime);
|
|
2046
|
+
const timesSlotCanUse = scheduleTimeSlots.some((item) => {
|
|
2047
|
+
const resourcesUseableMap = {};
|
|
2048
|
+
return openResources.every((resource) => {
|
|
2049
|
+
const currentResourcesList = allProductResources.filter(
|
|
2050
|
+
(n) => n.form_id === resource.resource_type_id
|
|
2051
|
+
);
|
|
2052
|
+
return currentResourcesList == null ? void 0 : currentResourcesList.some((m) => {
|
|
2053
|
+
const mTimes = m.times.filter((n) => {
|
|
2054
|
+
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");
|
|
2055
|
+
});
|
|
2056
|
+
if (mTimes.length === 0) {
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
const targetCanUseTimes = mTimes.some((childTiem) => {
|
|
2060
|
+
const res2 = (0, import_resources.getIsUsableByTimeItem)({
|
|
2061
|
+
timeSlice: {
|
|
2062
|
+
start_time: item.start,
|
|
2063
|
+
end_time: item.end,
|
|
2064
|
+
start_at: (0, import_dayjs.default)(item.start),
|
|
2065
|
+
end_at: (0, import_dayjs.default)(item.end)
|
|
2066
|
+
},
|
|
2067
|
+
time: childTiem,
|
|
2068
|
+
resource: m,
|
|
2069
|
+
currentCount: 1,
|
|
2070
|
+
resourcesUseableMap,
|
|
2071
|
+
cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
|
|
2072
|
+
});
|
|
2073
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
|
|
2074
|
+
resourcesUseableMap[m.id] = res2.usable;
|
|
2075
|
+
}
|
|
2076
|
+
return res2.usable && !m.onlyComputed;
|
|
2077
|
+
});
|
|
2078
|
+
return targetCanUseTimes;
|
|
2079
|
+
});
|
|
2080
|
+
});
|
|
2081
|
+
});
|
|
2082
|
+
if (!timesSlotCanUse) {
|
|
2083
|
+
status = "unavailable";
|
|
2084
|
+
}
|
|
2085
|
+
if (status === "available" && !firstAvailableDate) {
|
|
2086
|
+
firstAvailableDate = currentDateStr;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
dates.push({
|
|
2090
|
+
date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
|
|
2091
|
+
week: (0, import_dayjs.default)(currentDate).format("ddd"),
|
|
2092
|
+
weekNum: (0, import_dayjs.default)(currentDate).day(),
|
|
2093
|
+
status
|
|
2094
|
+
});
|
|
2095
|
+
if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 14) {
|
|
2096
|
+
break;
|
|
2097
|
+
}
|
|
2098
|
+
currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
|
|
2099
|
+
}
|
|
2100
|
+
dates = (0, import_utils3.handleAvailableDateByResource)(res.data, dates);
|
|
2101
|
+
this.store.date.setDateList(dates);
|
|
2102
|
+
(_f = this.store.currentProduct) == null ? void 0 : _f.setOtherParams("timeSlotBySchedule", {
|
|
2103
|
+
dateList: dates,
|
|
2104
|
+
firstAvailableDate,
|
|
2105
|
+
startDate,
|
|
2106
|
+
endDate
|
|
2107
|
+
});
|
|
2108
|
+
return {
|
|
2109
|
+
dateList: dates,
|
|
2110
|
+
firstAvailableDate
|
|
2111
|
+
};
|
|
1866
2112
|
}
|
|
1867
2113
|
};
|
|
1868
2114
|
// 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 {};
|
|
@@ -29,7 +29,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/solution/BookingByStep/utils/resources.ts
|
|
30
30
|
var resources_exports = {};
|
|
31
31
|
__export(resources_exports, {
|
|
32
|
+
checkSessionProductLeadTime: () => checkSessionProductLeadTime,
|
|
32
33
|
checkSubResourcesCapacity: () => checkSubResourcesCapacity,
|
|
34
|
+
filterScheduleByDateRange: () => filterScheduleByDateRange,
|
|
33
35
|
formatDefaultCapacitys: () => formatDefaultCapacitys,
|
|
34
36
|
formatResources: () => formatResources,
|
|
35
37
|
getIsUsableByTimeItem: () => getIsUsableByTimeItem,
|
|
@@ -37,11 +39,13 @@ __export(resources_exports, {
|
|
|
37
39
|
getOthersSelectedResources: () => getOthersSelectedResources,
|
|
38
40
|
getResourcesByIds: () => getResourcesByIds,
|
|
39
41
|
getResourcesByProduct: () => getResourcesByProduct,
|
|
42
|
+
getResourcesIdsByProduct: () => getResourcesIdsByProduct,
|
|
40
43
|
getSumCapacity: () => getSumCapacity,
|
|
41
44
|
getTimeSlicesByResource: () => getTimeSlicesByResource,
|
|
42
45
|
getTimeSlicesByResources: () => getTimeSlicesByResources,
|
|
43
46
|
getTimesIntersection: () => getTimesIntersection,
|
|
44
|
-
mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices
|
|
47
|
+
mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices,
|
|
48
|
+
sortCombinedResources: () => sortCombinedResources
|
|
45
49
|
});
|
|
46
50
|
module.exports = __toCommonJS(resources_exports);
|
|
47
51
|
var import_dayjs = __toESM(require("dayjs"));
|
|
@@ -561,9 +565,74 @@ var checkSubResourcesCapacity = (resource) => {
|
|
|
561
565
|
});
|
|
562
566
|
}
|
|
563
567
|
};
|
|
568
|
+
function filterScheduleByDateRange(schedule, startDate, endDate) {
|
|
569
|
+
if (!(schedule == null ? void 0 : schedule.length))
|
|
570
|
+
return [];
|
|
571
|
+
const start = new Date(startDate);
|
|
572
|
+
const end = new Date(endDate);
|
|
573
|
+
return schedule.filter((item) => {
|
|
574
|
+
const itemDate = new Date(item.date);
|
|
575
|
+
return itemDate >= start && itemDate <= end;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
function checkSessionProductLeadTime(product) {
|
|
579
|
+
let latestStartDate = "";
|
|
580
|
+
let earliestEndDate = "";
|
|
581
|
+
const { future_day, unit, unit_type } = product.cut_off_time;
|
|
582
|
+
if (future_day) {
|
|
583
|
+
const endDate = (0, import_dayjs.default)().add(future_day, "day");
|
|
584
|
+
if (!earliestEndDate || endDate.isBefore((0, import_dayjs.default)(earliestEndDate), "day")) {
|
|
585
|
+
earliestEndDate = endDate.format("YYYY-MM-DD");
|
|
586
|
+
}
|
|
587
|
+
} else if (future_day === 0) {
|
|
588
|
+
const endDate = (0, import_dayjs.default)();
|
|
589
|
+
if (!earliestEndDate || endDate.isBefore((0, import_dayjs.default)(earliestEndDate), "day")) {
|
|
590
|
+
earliestEndDate = endDate.format("YYYY-MM-DD");
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (unit && unit_type) {
|
|
594
|
+
const startDate = (0, import_dayjs.default)(
|
|
595
|
+
(0, import_dayjs.default)().add(unit, unit_type).format("YYYY-MM-DD")
|
|
596
|
+
);
|
|
597
|
+
if (!latestStartDate || startDate.isAfter((0, import_dayjs.default)(latestStartDate), "day")) {
|
|
598
|
+
latestStartDate = startDate.format("YYYY-MM-DD");
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
latestStartDate,
|
|
603
|
+
earliestEndDate
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function getResourcesIdsByProduct(product) {
|
|
607
|
+
var _a, _b, _c;
|
|
608
|
+
const tempResourceIds = [];
|
|
609
|
+
(_c = (_b = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach) == null ? void 0 : _c.call(_b, (resource) => {
|
|
610
|
+
var _a2, _b2;
|
|
611
|
+
if ((resource == null ? void 0 : resource.status) == 1) {
|
|
612
|
+
if ((_a2 = resource == null ? void 0 : resource.default_resource) == null ? void 0 : _a2.length) {
|
|
613
|
+
tempResourceIds.push(...resource == null ? void 0 : resource.default_resource);
|
|
614
|
+
} else if ((_b2 = resource == null ? void 0 : resource.optional_resource) == null ? void 0 : _b2.length) {
|
|
615
|
+
tempResourceIds.push(...resource == null ? void 0 : resource.optional_resource);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
return tempResourceIds;
|
|
620
|
+
}
|
|
621
|
+
function sortCombinedResources(resourcesList) {
|
|
622
|
+
const newResourcesList = [...resourcesList];
|
|
623
|
+
newResourcesList.sort((a, b) => {
|
|
624
|
+
var _a, _b, _c, _d;
|
|
625
|
+
const aIsCombined = ((_b = (_a = a.metadata) == null ? void 0 : _a.combined_resource) == null ? void 0 : _b.status) === 1;
|
|
626
|
+
const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
627
|
+
return aIsCombined === bIsCombined ? 0 : aIsCombined ? 1 : -1;
|
|
628
|
+
});
|
|
629
|
+
return newResourcesList;
|
|
630
|
+
}
|
|
564
631
|
// Annotate the CommonJS export names for ESM import in node:
|
|
565
632
|
0 && (module.exports = {
|
|
633
|
+
checkSessionProductLeadTime,
|
|
566
634
|
checkSubResourcesCapacity,
|
|
635
|
+
filterScheduleByDateRange,
|
|
567
636
|
formatDefaultCapacitys,
|
|
568
637
|
formatResources,
|
|
569
638
|
getIsUsableByTimeItem,
|
|
@@ -571,9 +640,11 @@ var checkSubResourcesCapacity = (resource) => {
|
|
|
571
640
|
getOthersSelectedResources,
|
|
572
641
|
getResourcesByIds,
|
|
573
642
|
getResourcesByProduct,
|
|
643
|
+
getResourcesIdsByProduct,
|
|
574
644
|
getSumCapacity,
|
|
575
645
|
getTimeSlicesByResource,
|
|
576
646
|
getTimeSlicesByResources,
|
|
577
647
|
getTimesIntersection,
|
|
578
|
-
mergeSubResourcesTimeSlices
|
|
648
|
+
mergeSubResourcesTimeSlices,
|
|
649
|
+
sortCombinedResources
|
|
579
650
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResourceItem, TimeSliceItem } from "./resources";
|
|
2
|
+
/**
|
|
3
|
+
* 计算资源在指定时间段内的总可用时间(以分钟为单位)
|
|
4
|
+
* @param resource 需要计算可用时间的资源
|
|
5
|
+
* @param timeSlots 要检查可用性的时间段
|
|
6
|
+
* @param currentCapacity 当前预约所需的容量
|
|
7
|
+
* @returns 总可用时间(分钟)
|
|
8
|
+
*/
|
|
9
|
+
export declare function calculateResourceAvailableTime({ resource, timeSlots, currentCapacity, }: {
|
|
10
|
+
resource: ResourceItem;
|
|
11
|
+
timeSlots: TimeSliceItem;
|
|
12
|
+
currentCapacity?: number;
|
|
13
|
+
}): number;
|
|
14
|
+
/**
|
|
15
|
+
* 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
|
|
16
|
+
* @param resources 资源列表
|
|
17
|
+
* @param currentCapacity 当前预约所需的容量
|
|
18
|
+
* @param countMap 已预约数量映射
|
|
19
|
+
* @returns 最快可用的资源
|
|
20
|
+
*/
|
|
21
|
+
export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
|
|
22
|
+
resources: ResourceItem[];
|
|
23
|
+
currentCapacity?: number;
|
|
24
|
+
countMap?: Record<number, number>;
|
|
25
|
+
}): ResourceItem | null;
|