@pisell/pisellos 2.1.71 → 2.1.73
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 +11 -7
- package/dist/solution/BookingByStep/index.js +519 -210
- package/dist/solution/BookingByStep/utils/resources.js +4 -0
- package/lib/solution/BookingByStep/index.d.ts +11 -7
- package/lib/solution/BookingByStep/index.js +336 -92
- package/lib/solution/BookingByStep/utils/resources.js +4 -1
- package/package.json +1 -1
|
@@ -444,6 +444,10 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
|
|
|
444
444
|
// 解析开始和结束时间
|
|
445
445
|
var startTime = dayjs("".concat(time.start_at));
|
|
446
446
|
var endTime = dayjs("".concat(time.end_at));
|
|
447
|
+
// 结束时间要做修复,如果time.end_at 是超过了 currentDate 的那一天,则把 end_at 设置为 currentDate 那一天的 23:59:59
|
|
448
|
+
if (endTime.isAfter(dayjs(currentDate).endOf('day'))) {
|
|
449
|
+
endTime = dayjs(currentDate).endOf('day');
|
|
450
|
+
}
|
|
447
451
|
|
|
448
452
|
// 当前切片的开始时间
|
|
449
453
|
var currentStart = startTime;
|
|
@@ -299,6 +299,16 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
299
299
|
errorList: any[];
|
|
300
300
|
};
|
|
301
301
|
getTimeSlotByAllResources(resources_code: string): any[];
|
|
302
|
+
getTimeSlotByAllResourcesForDate({ resources_code, startDate, endDate }: {
|
|
303
|
+
resources_code: string;
|
|
304
|
+
startDate: string;
|
|
305
|
+
endDate: string;
|
|
306
|
+
}): Promise<{
|
|
307
|
+
date: string;
|
|
308
|
+
status: string;
|
|
309
|
+
week: string;
|
|
310
|
+
weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
311
|
+
}[]>;
|
|
302
312
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
303
313
|
private getScheduleDataByIds;
|
|
304
314
|
openProductDetail(productId: number): Promise<void>;
|
|
@@ -316,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
316
326
|
count: number;
|
|
317
327
|
left: number;
|
|
318
328
|
summaryCount: number;
|
|
319
|
-
status:
|
|
329
|
+
status: "lots_of_space" | "filling_up_fast" | "sold_out";
|
|
320
330
|
}[];
|
|
321
331
|
/**
|
|
322
332
|
* 找到多个资源的公共可用时间段
|
|
@@ -381,9 +391,3 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
381
391
|
*/
|
|
382
392
|
getContactInfo(params: any): Promise<any>;
|
|
383
393
|
}
|
|
384
|
-
interface TimeStatusMap {
|
|
385
|
-
lots_of_space: true;
|
|
386
|
-
filling_up_fast: true;
|
|
387
|
-
sold_out: true;
|
|
388
|
-
}
|
|
389
|
-
export {};
|
|
@@ -1405,7 +1405,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1405
1405
|
}
|
|
1406
1406
|
// 从购物车中获取已经分配好第一步资源的所有时间片
|
|
1407
1407
|
getTimeSlotByAllResources(resources_code) {
|
|
1408
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1408
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
1409
1409
|
let dateRange = this.store.date.getDateRange();
|
|
1410
1410
|
const resources = [];
|
|
1411
1411
|
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
@@ -1415,7 +1415,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1415
1415
|
let maxCutOffTime = void 0;
|
|
1416
1416
|
let maxCutOffTimeValue = (0, import_dayjs.default)();
|
|
1417
1417
|
cartItems.forEach((item) => {
|
|
1418
|
-
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2,
|
|
1418
|
+
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
|
|
1419
1419
|
(_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
|
|
1420
1420
|
if (n.code === resources_code) {
|
|
1421
1421
|
resources.push(...n.renderList || []);
|
|
@@ -1428,7 +1428,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1428
1428
|
resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
|
|
1429
1429
|
(n) => n.code === resources_code
|
|
1430
1430
|
)) == null ? void 0 : _g2.id;
|
|
1431
|
-
if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((
|
|
1431
|
+
if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((_i2 = item._productOrigin) == null ? void 0 : _i2.cut_off_time.type) === "advance") {
|
|
1432
1432
|
const currentCutOffTime = (0, import_dayjs.default)().add(
|
|
1433
1433
|
item._productOrigin.cut_off_time.unit,
|
|
1434
1434
|
item._productOrigin.cut_off_time.unit_type
|
|
@@ -1446,6 +1446,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1446
1446
|
}
|
|
1447
1447
|
});
|
|
1448
1448
|
}
|
|
1449
|
+
if (((_c = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _c.date) && resources.length) {
|
|
1450
|
+
const currentDate = (_d = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _d.date;
|
|
1451
|
+
const theDateResources = this.store.date.getResourcesListByDate(currentDate);
|
|
1452
|
+
resources.forEach((item) => {
|
|
1453
|
+
var _a2;
|
|
1454
|
+
const noCurrentDateTimes = item.times.some((n) => {
|
|
1455
|
+
return (0, import_dayjs.default)(n.start_at).isSame((0, import_dayjs.default)(currentDate), "day");
|
|
1456
|
+
});
|
|
1457
|
+
if (!noCurrentDateTimes) {
|
|
1458
|
+
item.times = ((_a2 = theDateResources == null ? void 0 : theDateResources.find((n) => n.id === item.id)) == null ? void 0 : _a2.times) || [];
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1449
1462
|
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1450
1463
|
let duration = 0;
|
|
1451
1464
|
const accountList = this.store.accountList.getAccounts();
|
|
@@ -1473,7 +1486,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1473
1486
|
} else {
|
|
1474
1487
|
checkDuration(cartItems);
|
|
1475
1488
|
}
|
|
1476
|
-
if (!((
|
|
1489
|
+
if (!((_e = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _e.start_date) && !((_f = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _f.resource_id) || !(cartItems == null ? void 0 : cartItems[0].duration)) {
|
|
1477
1490
|
return [];
|
|
1478
1491
|
}
|
|
1479
1492
|
if ((cartItems == null ? void 0 : cartItems[0].start_date) && !dateRange) {
|
|
@@ -1485,7 +1498,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1485
1498
|
weekNum: 0
|
|
1486
1499
|
},
|
|
1487
1500
|
{
|
|
1488
|
-
date: ((
|
|
1501
|
+
date: ((_g = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _g.end_date) || ((_h = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _h.start_date) || "",
|
|
1489
1502
|
status: "available",
|
|
1490
1503
|
week: "",
|
|
1491
1504
|
weekNum: 0
|
|
@@ -1499,18 +1512,30 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1499
1512
|
return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
|
|
1500
1513
|
}
|
|
1501
1514
|
);
|
|
1502
|
-
let operating_day_boundary = (
|
|
1515
|
+
let operating_day_boundary = (_j = (_i = this.shopStore.get("core")) == null ? void 0 : _i.core) == null ? void 0 : _j.operating_day_boundary;
|
|
1503
1516
|
let maxBlockThreshold = 0;
|
|
1504
1517
|
if (hasFlexibleDuration) {
|
|
1505
1518
|
maxBlockThreshold = cartItems.reduce((max, item) => {
|
|
1506
1519
|
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
1507
1520
|
if ((_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.flexible_config) == null ? void 0 : _c2.is_enable_minimum_duration) {
|
|
1508
|
-
return Math.max(
|
|
1521
|
+
return Math.max(
|
|
1522
|
+
max,
|
|
1523
|
+
((_f2 = (_e2 = (_d2 = item._productOrigin) == null ? void 0 : _d2.duration) == null ? void 0 : _e2.flexible_config) == null ? void 0 : _f2.block_threshold) || 0
|
|
1524
|
+
);
|
|
1509
1525
|
}
|
|
1510
1526
|
return 0;
|
|
1511
1527
|
}, 0);
|
|
1512
1528
|
}
|
|
1513
1529
|
const calculateCapacityFromCartItems = (items) => {
|
|
1530
|
+
var _a2;
|
|
1531
|
+
const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
|
|
1532
|
+
const sameResourceLength = items.filter((item) => {
|
|
1533
|
+
var _a3;
|
|
1534
|
+
return ((_a3 = item._resourceOrigin) == null ? void 0 : _a3[0].id) === firstResource;
|
|
1535
|
+
}).length;
|
|
1536
|
+
if (sameResourceLength !== items.length) {
|
|
1537
|
+
return 1;
|
|
1538
|
+
}
|
|
1514
1539
|
return items.reduce((total, item) => {
|
|
1515
1540
|
return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
|
|
1516
1541
|
}, 0);
|
|
@@ -1518,7 +1543,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1518
1543
|
let maxCapacity = 1;
|
|
1519
1544
|
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1520
1545
|
accountList.forEach((account) => {
|
|
1521
|
-
const accountCartItems = this.store.cart.getCartByAccount(
|
|
1546
|
+
const accountCartItems = this.store.cart.getCartByAccount(
|
|
1547
|
+
account.getId()
|
|
1548
|
+
);
|
|
1522
1549
|
const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
|
|
1523
1550
|
if (currentCapacity > maxCapacity) {
|
|
1524
1551
|
maxCapacity = currentCapacity;
|
|
@@ -1542,6 +1569,174 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1542
1569
|
});
|
|
1543
1570
|
return timeSlots;
|
|
1544
1571
|
}
|
|
1572
|
+
// 从购物车中获取已经分配好第一步资源的所有时间片,批量版本,用于给日期提供能否高亮的判断
|
|
1573
|
+
async getTimeSlotByAllResourcesForDate({ resources_code, startDate, endDate }) {
|
|
1574
|
+
var _a, _b, _c, _d;
|
|
1575
|
+
if ((0, import_dayjs.default)(endDate).diff((0, import_dayjs.default)(startDate), "day") < 30) {
|
|
1576
|
+
endDate = (0, import_dayjs.default)(startDate).add(30, "day").format("YYYY-MM-DD");
|
|
1577
|
+
}
|
|
1578
|
+
await this.getAvailableDate({
|
|
1579
|
+
startDate,
|
|
1580
|
+
endDate,
|
|
1581
|
+
useCache: true
|
|
1582
|
+
});
|
|
1583
|
+
const resources = [];
|
|
1584
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1585
|
+
const resourceIds = [];
|
|
1586
|
+
let resourcesTypeId = void 0;
|
|
1587
|
+
let isSingleResource = false;
|
|
1588
|
+
let maxCutOffTime = void 0;
|
|
1589
|
+
let maxCutOffTimeValue = (0, import_dayjs.default)();
|
|
1590
|
+
cartItems.forEach((item) => {
|
|
1591
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i;
|
|
1592
|
+
(_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
|
|
1593
|
+
if (n.code === resources_code) {
|
|
1594
|
+
resources.push(...n.renderList || []);
|
|
1595
|
+
isSingleResource = n.type === "single";
|
|
1596
|
+
}
|
|
1597
|
+
});
|
|
1598
|
+
if (item.resource_id && !resourceIds.includes(item.resource_id)) {
|
|
1599
|
+
resourceIds.push(item.resource_id);
|
|
1600
|
+
}
|
|
1601
|
+
resourcesTypeId = (_g = (_f = (_e = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e.resources) == null ? void 0 : _f.find(
|
|
1602
|
+
(n) => n.code === resources_code
|
|
1603
|
+
)) == null ? void 0 : _g.id;
|
|
1604
|
+
if (((_h = item._productOrigin) == null ? void 0 : _h.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
|
|
1605
|
+
const currentCutOffTime = (0, import_dayjs.default)().add(
|
|
1606
|
+
item._productOrigin.cut_off_time.unit,
|
|
1607
|
+
item._productOrigin.cut_off_time.unit_type
|
|
1608
|
+
);
|
|
1609
|
+
if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
|
|
1610
|
+
maxCutOffTimeValue = currentCutOffTime;
|
|
1611
|
+
maxCutOffTime = item._productOrigin.cut_off_time;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
});
|
|
1615
|
+
if (!resources.length)
|
|
1616
|
+
return [];
|
|
1617
|
+
let duration = 0;
|
|
1618
|
+
const accountList = this.store.accountList.getAccounts();
|
|
1619
|
+
const checkDuration = (cartItems2) => {
|
|
1620
|
+
let accountDuration = 0;
|
|
1621
|
+
cartItems2.forEach((item) => {
|
|
1622
|
+
var _a2, _b2, _c2, _d2, _e, _f;
|
|
1623
|
+
if (isSingleResource) {
|
|
1624
|
+
accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10;
|
|
1625
|
+
} else {
|
|
1626
|
+
if (accountDuration < (((_d2 = (_c2 = item._productOrigin) == null ? void 0 : _c2.duration) == null ? void 0 : _d2.value) || 10)) {
|
|
1627
|
+
accountDuration = ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
});
|
|
1631
|
+
if (accountDuration > duration) {
|
|
1632
|
+
duration = accountDuration;
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1636
|
+
accountList.forEach((account) => {
|
|
1637
|
+
const cartItems2 = this.store.cart.getCartByAccount(account.getId());
|
|
1638
|
+
checkDuration(cartItems2);
|
|
1639
|
+
});
|
|
1640
|
+
} else {
|
|
1641
|
+
checkDuration(cartItems);
|
|
1642
|
+
}
|
|
1643
|
+
if (!((_a = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _a.start_date) && !((_b = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _b.resource_id) || !(cartItems == null ? void 0 : cartItems[0].duration)) {
|
|
1644
|
+
return [];
|
|
1645
|
+
}
|
|
1646
|
+
const resourcesUseableMap = {};
|
|
1647
|
+
const hasFlexibleDuration = cartItems.some(
|
|
1648
|
+
(item) => {
|
|
1649
|
+
var _a2, _b2;
|
|
1650
|
+
return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
|
|
1651
|
+
}
|
|
1652
|
+
);
|
|
1653
|
+
let operating_day_boundary = (_d = (_c = this.shopStore.get("core")) == null ? void 0 : _c.core) == null ? void 0 : _d.operating_day_boundary;
|
|
1654
|
+
let maxBlockThreshold = 0;
|
|
1655
|
+
if (hasFlexibleDuration) {
|
|
1656
|
+
maxBlockThreshold = cartItems.reduce((max, item) => {
|
|
1657
|
+
var _a2, _b2, _c2, _d2, _e, _f;
|
|
1658
|
+
if ((_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.flexible_config) == null ? void 0 : _c2.is_enable_minimum_duration) {
|
|
1659
|
+
return Math.max(max, ((_f = (_e = (_d2 = item._productOrigin) == null ? void 0 : _d2.duration) == null ? void 0 : _e.flexible_config) == null ? void 0 : _f.block_threshold) || 0);
|
|
1660
|
+
}
|
|
1661
|
+
return 0;
|
|
1662
|
+
}, 0);
|
|
1663
|
+
}
|
|
1664
|
+
const calculateCapacityFromCartItems = (items) => {
|
|
1665
|
+
var _a2;
|
|
1666
|
+
const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
|
|
1667
|
+
const sameResourceLength = items.filter((item) => {
|
|
1668
|
+
var _a3;
|
|
1669
|
+
return ((_a3 = item._resourceOrigin) == null ? void 0 : _a3[0].id) === firstResource;
|
|
1670
|
+
}).length;
|
|
1671
|
+
if (sameResourceLength !== items.length) {
|
|
1672
|
+
return 1;
|
|
1673
|
+
}
|
|
1674
|
+
return items.reduce((total, item) => {
|
|
1675
|
+
return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
|
|
1676
|
+
}, 0);
|
|
1677
|
+
};
|
|
1678
|
+
let maxCapacity = 1;
|
|
1679
|
+
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1680
|
+
accountList.forEach((account) => {
|
|
1681
|
+
const accountCartItems = this.store.cart.getCartByAccount(account.getId());
|
|
1682
|
+
const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
|
|
1683
|
+
if (currentCapacity > maxCapacity) {
|
|
1684
|
+
maxCapacity = currentCapacity;
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
} else {
|
|
1688
|
+
maxCapacity = calculateCapacityFromCartItems(cartItems);
|
|
1689
|
+
}
|
|
1690
|
+
const arr = [];
|
|
1691
|
+
const today = (0, import_dayjs.default)().startOf("day");
|
|
1692
|
+
for (let i = (0, import_dayjs.default)(startDate); i.isBefore((0, import_dayjs.default)(endDate)); i = i.add(1, "day")) {
|
|
1693
|
+
const currentDate = i.format("YYYY-MM-DD");
|
|
1694
|
+
const theDateResources = this.store.date.getResourcesListByDate(currentDate);
|
|
1695
|
+
resources.forEach((item) => {
|
|
1696
|
+
var _a2;
|
|
1697
|
+
item.times = ((_a2 = theDateResources == null ? void 0 : theDateResources.find((n) => n.id === item.id)) == null ? void 0 : _a2.times) || [];
|
|
1698
|
+
});
|
|
1699
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1700
|
+
if (i.isBefore(today)) {
|
|
1701
|
+
arr.push({
|
|
1702
|
+
date: currentDate,
|
|
1703
|
+
status: "unavailable",
|
|
1704
|
+
week: i.format("ddd"),
|
|
1705
|
+
weekNum: i.day()
|
|
1706
|
+
});
|
|
1707
|
+
continue;
|
|
1708
|
+
}
|
|
1709
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResources)({
|
|
1710
|
+
resourceIds,
|
|
1711
|
+
resourcesMap,
|
|
1712
|
+
duration,
|
|
1713
|
+
currentDate,
|
|
1714
|
+
split: 10,
|
|
1715
|
+
resourcesUseableMap,
|
|
1716
|
+
capacity: maxCapacity,
|
|
1717
|
+
cut_off_time: maxCutOffTime,
|
|
1718
|
+
hasFlexibleDuration,
|
|
1719
|
+
operating_day_boundary,
|
|
1720
|
+
maxBlockThreshold
|
|
1721
|
+
});
|
|
1722
|
+
if (timeSlots.length > 0) {
|
|
1723
|
+
arr.push({
|
|
1724
|
+
date: currentDate,
|
|
1725
|
+
status: "available",
|
|
1726
|
+
week: i.format("ddd"),
|
|
1727
|
+
weekNum: i.day()
|
|
1728
|
+
});
|
|
1729
|
+
} else {
|
|
1730
|
+
arr.push({
|
|
1731
|
+
date: currentDate,
|
|
1732
|
+
status: "unavailable",
|
|
1733
|
+
week: i.format("ddd"),
|
|
1734
|
+
weekNum: i.day()
|
|
1735
|
+
});
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
return arr;
|
|
1739
|
+
}
|
|
1545
1740
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
|
|
1546
1741
|
submitTimeSlot(timeSlots) {
|
|
1547
1742
|
var _a, _b;
|
|
@@ -1685,7 +1880,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1685
1880
|
resources,
|
|
1686
1881
|
product
|
|
1687
1882
|
}) {
|
|
1688
|
-
var _a, _b, _c, _d
|
|
1883
|
+
var _a, _b, _c, _d;
|
|
1689
1884
|
const targetProduct = this.store.currentProduct;
|
|
1690
1885
|
const targetProductData = product || targetProduct;
|
|
1691
1886
|
let targetSchedules = [];
|
|
@@ -1728,29 +1923,48 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1728
1923
|
return -1;
|
|
1729
1924
|
return 0;
|
|
1730
1925
|
});
|
|
1731
|
-
const
|
|
1926
|
+
const enabledResourceTypeConfigs = ((_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.filter(
|
|
1732
1927
|
(n) => n.status === 1
|
|
1733
|
-
))
|
|
1734
|
-
const
|
|
1735
|
-
(n) => n.
|
|
1928
|
+
)) || [];
|
|
1929
|
+
const resourceTypeConfigById = new Map(
|
|
1930
|
+
enabledResourceTypeConfigs.map((n) => [n.id, n])
|
|
1736
1931
|
);
|
|
1737
|
-
const isMultipleBooking = (firstEnabledResourceConfig == null ? void 0 : firstEnabledResourceConfig.type) === "multiple";
|
|
1738
1932
|
const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
|
|
1739
1933
|
const resourcesUseableMap = {};
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1934
|
+
const statsByResourceType = {};
|
|
1935
|
+
enabledResourceTypeConfigs.forEach((cfg) => {
|
|
1936
|
+
statsByResourceType[cfg.id] = {
|
|
1937
|
+
count: 0,
|
|
1938
|
+
left: 0,
|
|
1939
|
+
summaryCount: 0,
|
|
1940
|
+
summaryConfigCount: 0
|
|
1941
|
+
};
|
|
1942
|
+
});
|
|
1744
1943
|
allProductResources == null ? void 0 : allProductResources.forEach((m) => {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1944
|
+
const currentResourceTypeConfig = resourceTypeConfigById.get(m.form_id);
|
|
1945
|
+
if (!currentResourceTypeConfig)
|
|
1946
|
+
return;
|
|
1947
|
+
let currentResourceMaxRemainingCapacity = 0;
|
|
1948
|
+
let isAllTimeSlicesUsable = true;
|
|
1748
1949
|
const mTimes = m.times.filter((n) => {
|
|
1749
1950
|
return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || m.onlyComputed && (0, import_dayjs.default)(n.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
|
|
1750
1951
|
});
|
|
1751
1952
|
if (mTimes.length === 0) {
|
|
1752
1953
|
return;
|
|
1753
1954
|
}
|
|
1955
|
+
if (!m.onlyComputed) {
|
|
1956
|
+
const currentStats2 = statsByResourceType[m.form_id] || {
|
|
1957
|
+
count: 0,
|
|
1958
|
+
left: 0,
|
|
1959
|
+
summaryCount: 0,
|
|
1960
|
+
summaryConfigCount: 0
|
|
1961
|
+
};
|
|
1962
|
+
if (currentResourceTypeConfig.type === "multiple")
|
|
1963
|
+
currentStats2.summaryConfigCount += m.capacity;
|
|
1964
|
+
else
|
|
1965
|
+
currentStats2.summaryConfigCount += 1;
|
|
1966
|
+
statsByResourceType[m.form_id] = currentStats2;
|
|
1967
|
+
}
|
|
1754
1968
|
mTimes.forEach((childTiem) => {
|
|
1755
1969
|
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1756
1970
|
timeSlice: {
|
|
@@ -1768,54 +1982,67 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1768
1982
|
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
1769
1983
|
resourcesUseableMap[m.id] = res.usable;
|
|
1770
1984
|
}
|
|
1771
|
-
if (res.usable
|
|
1772
|
-
|
|
1985
|
+
if (!res.usable)
|
|
1986
|
+
isAllTimeSlicesUsable = false;
|
|
1987
|
+
if (res.usable && !m.onlyComputed) {
|
|
1988
|
+
if (res.remainingCapacity > currentResourceMaxRemainingCapacity)
|
|
1989
|
+
currentResourceMaxRemainingCapacity = res.remainingCapacity;
|
|
1773
1990
|
}
|
|
1774
|
-
if (res.usable && !m.onlyComputed && res.remainingCapacity >= currentResourcesSummaryCount) {
|
|
1775
|
-
currentResourcesSummaryCount = res.remainingCapacity;
|
|
1776
|
-
}
|
|
1777
|
-
currentResourcesTimeSlotCanUsedArr.push(res.usable);
|
|
1778
1991
|
});
|
|
1779
|
-
if (
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1992
|
+
if (!isAllTimeSlicesUsable)
|
|
1993
|
+
return;
|
|
1994
|
+
if (m.onlyComputed)
|
|
1995
|
+
return;
|
|
1996
|
+
const currentStats = statsByResourceType[m.form_id] || {
|
|
1997
|
+
count: 0,
|
|
1998
|
+
left: 0,
|
|
1999
|
+
summaryCount: 0,
|
|
2000
|
+
summaryConfigCount: 0
|
|
2001
|
+
};
|
|
2002
|
+
currentStats.left += 1;
|
|
2003
|
+
if (currentResourceTypeConfig.type === "multiple") {
|
|
2004
|
+
currentStats.summaryCount += currentResourceMaxRemainingCapacity;
|
|
2005
|
+
if (currentResourceMaxRemainingCapacity > currentStats.count)
|
|
2006
|
+
currentStats.count = currentResourceMaxRemainingCapacity;
|
|
2007
|
+
} else {
|
|
2008
|
+
currentStats.summaryCount += 1;
|
|
2009
|
+
if (currentStats.count < 1)
|
|
2010
|
+
currentStats.count = 1;
|
|
1797
2011
|
}
|
|
2012
|
+
statsByResourceType[m.form_id] = currentStats;
|
|
1798
2013
|
});
|
|
1799
2014
|
const cartItems2 = this.store.cart.getItems();
|
|
1800
2015
|
productResources.forEach((n) => {
|
|
2016
|
+
const currentResourceTypeConfig = resourceTypeConfigById.get(n.id);
|
|
2017
|
+
if (!currentResourceTypeConfig)
|
|
2018
|
+
return;
|
|
2019
|
+
const currentStats = statsByResourceType[n.id] || {
|
|
2020
|
+
count: 0,
|
|
2021
|
+
left: 0,
|
|
2022
|
+
summaryCount: 0
|
|
2023
|
+
};
|
|
1801
2024
|
if (n.type === "single") {
|
|
1802
2025
|
const currentResourcesSet = /* @__PURE__ */ new Set([...n.optional_resource, ...n.default_resource]);
|
|
1803
2026
|
const sameCartItems = cartItems2.filter((m) => {
|
|
1804
2027
|
var _a2, _b2, _c2;
|
|
1805
2028
|
return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) === ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
|
|
1806
2029
|
});
|
|
1807
|
-
if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length >
|
|
1808
|
-
|
|
1809
|
-
count = 0;
|
|
1810
|
-
summaryCount = 0;
|
|
2030
|
+
if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > currentStats.left) {
|
|
2031
|
+
currentStats.left = 0;
|
|
2032
|
+
currentStats.count = 0;
|
|
2033
|
+
currentStats.summaryCount = 0;
|
|
1811
2034
|
}
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
2035
|
+
let otherCartItems = cartItems2.filter(
|
|
2036
|
+
(m) => {
|
|
2037
|
+
var _a2, _b2, _c2, _d2, _e, _f;
|
|
2038
|
+
const isTimeMatch = ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) !== ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
|
|
2039
|
+
const isResourceMatch = (_f = (_e = (_d2 = m._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e.resources) == null ? void 0 : _f.find((m2) => m2.type === n.type && m2.status === 1);
|
|
2040
|
+
return isTimeMatch && isResourceMatch;
|
|
2041
|
+
}
|
|
2042
|
+
);
|
|
1816
2043
|
otherCartItems.forEach((m) => {
|
|
1817
2044
|
var _a2, _b2, _c2;
|
|
1818
|
-
const sameTypeResources = (_c2 = (_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.find((m2) => m2.type === n.type);
|
|
2045
|
+
const sameTypeResources = (_c2 = (_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.find((m2) => m2.type === n.type && m2.status === 1);
|
|
1819
2046
|
const sameTypeResourcesSet = /* @__PURE__ */ new Set([...(sameTypeResources == null ? void 0 : sameTypeResources.optional_resource) || [], ...(sameTypeResources == null ? void 0 : sameTypeResources.default_resource) || []]);
|
|
1820
2047
|
sameTypeResourcesSet.forEach((resource) => currentResourcesSet.add(resource));
|
|
1821
2048
|
});
|
|
@@ -1831,9 +2058,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1831
2058
|
}
|
|
1832
2059
|
});
|
|
1833
2060
|
if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
|
|
1834
|
-
|
|
1835
|
-
count = 0;
|
|
1836
|
-
summaryCount = 0;
|
|
2061
|
+
currentStats.left = 0;
|
|
2062
|
+
currentStats.count = 0;
|
|
2063
|
+
currentStats.summaryCount = 0;
|
|
1837
2064
|
}
|
|
1838
2065
|
} else {
|
|
1839
2066
|
const sameCartItems = cartItems2.filter((m) => {
|
|
@@ -1843,9 +2070,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1843
2070
|
const sameCartNeedCapacity = sameCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
|
|
1844
2071
|
const currentProductResourcesCapacity = n.renderList.reduce((acc, curr) => !curr.onlyComputed ? acc + curr.capacity || 0 : acc, 0);
|
|
1845
2072
|
if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
|
|
1846
|
-
|
|
1847
|
-
count = 0;
|
|
1848
|
-
summaryCount = 0;
|
|
2073
|
+
currentStats.left = 0;
|
|
2074
|
+
currentStats.count = 0;
|
|
2075
|
+
currentStats.summaryCount = 0;
|
|
1849
2076
|
}
|
|
1850
2077
|
const otherSameTimesCartItems = cartItems2.filter((m) => `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
|
|
1851
2078
|
const otherCartNeedCapacity = otherSameTimesCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
|
|
@@ -1888,51 +2115,68 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1888
2115
|
return acc;
|
|
1889
2116
|
}, 0);
|
|
1890
2117
|
if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
|
|
1891
|
-
|
|
1892
|
-
count = 0;
|
|
1893
|
-
summaryCount = 0;
|
|
2118
|
+
currentStats.left = 0;
|
|
2119
|
+
currentStats.count = 0;
|
|
2120
|
+
currentStats.summaryCount = 0;
|
|
1894
2121
|
}
|
|
1895
2122
|
}
|
|
2123
|
+
statsByResourceType[n.id] = currentStats;
|
|
1896
2124
|
});
|
|
1897
2125
|
const startDayJs = (0, import_dayjs.default)(item.start);
|
|
1898
2126
|
const endDayJs = (0, import_dayjs.default)(item.end);
|
|
1899
|
-
let
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
timeStatus = "sold_out";
|
|
2127
|
+
let bottleneckResourceTypeId;
|
|
2128
|
+
let bottleneckValue = Infinity;
|
|
2129
|
+
enabledResourceTypeConfigs.forEach((cfg) => {
|
|
2130
|
+
const stats = statsByResourceType[cfg.id] || {
|
|
2131
|
+
count: 0,
|
|
2132
|
+
left: 0,
|
|
2133
|
+
summaryCount: 0,
|
|
2134
|
+
summaryConfigCount: 0
|
|
2135
|
+
};
|
|
2136
|
+
const value = cfg.type === "multiple" ? stats.summaryCount : stats.left;
|
|
2137
|
+
if (value < bottleneckValue) {
|
|
2138
|
+
bottleneckValue = value;
|
|
2139
|
+
bottleneckResourceTypeId = cfg.id;
|
|
1913
2140
|
}
|
|
2141
|
+
});
|
|
2142
|
+
const bottleneckStats = bottleneckResourceTypeId !== void 0 ? statsByResourceType[bottleneckResourceTypeId] || {
|
|
2143
|
+
count: 0,
|
|
2144
|
+
left: 0,
|
|
2145
|
+
summaryCount: 0,
|
|
2146
|
+
summaryConfigCount: 0
|
|
2147
|
+
} : { count: 0, left: 0, summaryCount: 0, summaryConfigCount: 0 };
|
|
2148
|
+
const bottleneckConfig = bottleneckResourceTypeId !== void 0 ? resourceTypeConfigById.get(bottleneckResourceTypeId) : void 0;
|
|
2149
|
+
let status = "sold_out";
|
|
2150
|
+
if (bottleneckStats.left === 0)
|
|
2151
|
+
status = "sold_out";
|
|
2152
|
+
else if (!bottleneckConfig || bottleneckStats.summaryConfigCount === 0)
|
|
2153
|
+
status = "sold_out";
|
|
2154
|
+
else if (bottleneckConfig.type === "multiple") {
|
|
2155
|
+
const usageRatio = bottleneckStats.summaryCount / bottleneckStats.summaryConfigCount;
|
|
2156
|
+
if (usageRatio > 0.5)
|
|
2157
|
+
status = "lots_of_space";
|
|
2158
|
+
else if (bottleneckStats.summaryCount > 0)
|
|
2159
|
+
status = "filling_up_fast";
|
|
2160
|
+
else
|
|
2161
|
+
status = "sold_out";
|
|
1914
2162
|
} else {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
timeStatus = "filling_up_fast";
|
|
1923
|
-
else
|
|
1924
|
-
timeStatus = "sold_out";
|
|
1925
|
-
}
|
|
2163
|
+
const usageRatio = bottleneckStats.left / bottleneckStats.summaryConfigCount;
|
|
2164
|
+
if (usageRatio > 0.5)
|
|
2165
|
+
status = "lots_of_space";
|
|
2166
|
+
else if (bottleneckStats.count > 0)
|
|
2167
|
+
status = "filling_up_fast";
|
|
2168
|
+
else
|
|
2169
|
+
status = "sold_out";
|
|
1926
2170
|
}
|
|
1927
2171
|
return {
|
|
1928
2172
|
start_time: startDayJs.format("HH:mm"),
|
|
1929
2173
|
end_time: endDayJs.format("HH:mm"),
|
|
1930
2174
|
start_at: startDayJs,
|
|
1931
2175
|
end_at: endDayJs,
|
|
1932
|
-
count,
|
|
1933
|
-
left:
|
|
1934
|
-
summaryCount,
|
|
1935
|
-
status
|
|
2176
|
+
count: bottleneckStats.count,
|
|
2177
|
+
left: bottleneckStats.left,
|
|
2178
|
+
summaryCount: bottleneckStats.summaryCount,
|
|
2179
|
+
status
|
|
1936
2180
|
};
|
|
1937
2181
|
});
|
|
1938
2182
|
return formatScheduleTimeSlots;
|
|
@@ -353,7 +353,10 @@ var getTimeSlicesByResource = ({
|
|
|
353
353
|
});
|
|
354
354
|
times.forEach((time) => {
|
|
355
355
|
const startTime = (0, import_dayjs.default)(`${time.start_at}`);
|
|
356
|
-
|
|
356
|
+
let endTime = (0, import_dayjs.default)(`${time.end_at}`);
|
|
357
|
+
if (endTime.isAfter((0, import_dayjs.default)(currentDate).endOf("day"))) {
|
|
358
|
+
endTime = (0, import_dayjs.default)(currentDate).endOf("day");
|
|
359
|
+
}
|
|
357
360
|
let currentStart = startTime;
|
|
358
361
|
while (true) {
|
|
359
362
|
const currentEnd = currentStart.add(duration, "minute");
|