@pisell/pisellos 1.0.70 → 1.0.71
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/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -1
- package/dist/solution/BookingByStep/index.d.ts +16 -0
- package/dist/solution/BookingByStep/index.js +499 -24
- package/dist/solution/BookingByStep/utils/capacity.d.ts +7 -2
- package/dist/solution/BookingByStep/utils/capacity.js +39 -12
- package/dist/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/dist/solution/BookingByStep/utils/resources.js +1 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/solution/BookingByStep/index.d.ts +16 -0
- package/lib/solution/BookingByStep/index.js +336 -41
- package/lib/solution/BookingByStep/utils/capacity.d.ts +7 -2
- package/lib/solution/BookingByStep/utils/capacity.js +30 -8
- package/lib/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/lib/solution/BookingByStep/utils/resources.js +2 -0
- package/lib/solution/BookingTicket/index.js +6 -0
- package/package.json +1 -1
|
@@ -34,16 +34,17 @@ __export(BookingByStep_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(BookingByStep_exports);
|
|
35
35
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
36
36
|
var import_types = require("./types");
|
|
37
|
+
var import_utils = require("../../modules/Cart/utils");
|
|
37
38
|
var import_products = require("./utils/products");
|
|
38
39
|
var import_resources = require("./utils/resources");
|
|
39
40
|
var import_dayjs = __toESM(require("dayjs"));
|
|
40
41
|
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
|
|
41
42
|
var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
|
|
42
|
-
var
|
|
43
|
+
var import_utils2 = require("../../modules/Resource/utils");
|
|
43
44
|
var import_lodash_es = require("lodash-es");
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
45
|
+
var import_utils3 = require("../../modules/Schedule/utils");
|
|
46
|
+
var import_utils4 = require("../../modules/Date/utils");
|
|
47
|
+
var import_utils5 = require("../../modules/Product/utils");
|
|
47
48
|
var import_timeslots = require("./utils/timeslots");
|
|
48
49
|
var import_changePrice = require("../../modules/Cart/utils/changePrice");
|
|
49
50
|
var import_capacity = require("./utils/capacity");
|
|
@@ -363,7 +364,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
363
364
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
364
365
|
if (!date) {
|
|
365
366
|
const normalProductCartItem = cartItems.find(
|
|
366
|
-
(n) => !(0,
|
|
367
|
+
(n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
|
|
367
368
|
);
|
|
368
369
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
369
370
|
}
|
|
@@ -473,7 +474,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
473
474
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
474
475
|
if (!date) {
|
|
475
476
|
const normalProductCartItem = cartItems.find(
|
|
476
|
-
(n) => !(0,
|
|
477
|
+
(n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
|
|
477
478
|
);
|
|
478
479
|
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
479
480
|
}
|
|
@@ -525,7 +526,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
525
526
|
}
|
|
526
527
|
});
|
|
527
528
|
let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
|
|
528
|
-
if ((0,
|
|
529
|
+
if ((0, import_utils5.areAllNormalProducts)(
|
|
529
530
|
newCartItems.map((n) => n._productOrigin)
|
|
530
531
|
)) {
|
|
531
532
|
type = "virtual";
|
|
@@ -635,7 +636,15 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
635
636
|
addItemParams.account = account;
|
|
636
637
|
}
|
|
637
638
|
this.addProductCheck({ date });
|
|
638
|
-
|
|
639
|
+
if (addItemParams.quantity > 1 && !(0, import_utils5.isNormalProduct)(productData.origin)) {
|
|
640
|
+
for (let i = 0; i < addItemParams.quantity; i++) {
|
|
641
|
+
const newAddItemParams = (0, import_lodash_es.cloneDeep)(addItemParams);
|
|
642
|
+
newAddItemParams.quantity = 1;
|
|
643
|
+
this.store.cart.addItem(newAddItemParams);
|
|
644
|
+
}
|
|
645
|
+
} else {
|
|
646
|
+
this.store.cart.addItem(addItemParams);
|
|
647
|
+
}
|
|
639
648
|
return { success: true };
|
|
640
649
|
}
|
|
641
650
|
/**
|
|
@@ -648,7 +657,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
648
657
|
date
|
|
649
658
|
}) {
|
|
650
659
|
if (date) {
|
|
651
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
660
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
652
661
|
const cartItemsByDate = cartItems.filter(
|
|
653
662
|
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
654
663
|
);
|
|
@@ -810,7 +819,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
810
819
|
* @returns 不符合条件的购物车商品ID列表
|
|
811
820
|
*/
|
|
812
821
|
checkCartItems(type) {
|
|
813
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
822
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
814
823
|
const errorCartItemIds = [];
|
|
815
824
|
cartItems.forEach((cartItem) => {
|
|
816
825
|
const result = this.store.cart.checkCartItemByType(cartItem, type);
|
|
@@ -844,7 +853,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
844
853
|
resources.push(...n.resource);
|
|
845
854
|
});
|
|
846
855
|
}
|
|
847
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
856
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
848
857
|
if (!resources.length) {
|
|
849
858
|
const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
|
|
850
859
|
if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
|
|
@@ -860,7 +869,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
860
869
|
});
|
|
861
870
|
}
|
|
862
871
|
}
|
|
863
|
-
const resourcesMap = (0,
|
|
872
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
864
873
|
const arr = [];
|
|
865
874
|
cartItems.forEach((cartItem) => {
|
|
866
875
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
@@ -989,14 +998,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
989
998
|
*/
|
|
990
999
|
getResourcesListByCartItem(id) {
|
|
991
1000
|
var _a, _b;
|
|
992
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1001
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
993
1002
|
const dateRange = this.store.date.getDateRange();
|
|
994
1003
|
const resources = [];
|
|
995
1004
|
dateRange.forEach((n) => {
|
|
996
1005
|
if (n.resource)
|
|
997
1006
|
resources.push(...n.resource);
|
|
998
1007
|
});
|
|
999
|
-
const resourcesMap = (0,
|
|
1008
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1000
1009
|
const targetCartItem = cartItems.find((n) => n._id === id);
|
|
1001
1010
|
if (!targetCartItem) {
|
|
1002
1011
|
throw new Error(`没有找到${id}购物车商品`);
|
|
@@ -1053,7 +1062,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1053
1062
|
capacity
|
|
1054
1063
|
}) {
|
|
1055
1064
|
var _a, _b, _c;
|
|
1056
|
-
if ((0,
|
|
1065
|
+
if ((0, import_utils5.isNormalProduct)(cartItem._productOrigin)) {
|
|
1057
1066
|
return {};
|
|
1058
1067
|
}
|
|
1059
1068
|
const dateRange = this.store.date.getDateRange();
|
|
@@ -1088,7 +1097,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1088
1097
|
});
|
|
1089
1098
|
}
|
|
1090
1099
|
}
|
|
1091
|
-
const resourcesMap = (0,
|
|
1100
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
|
|
1092
1101
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1093
1102
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1094
1103
|
allCartItems,
|
|
@@ -1169,7 +1178,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1169
1178
|
selectedResource: targetResource
|
|
1170
1179
|
};
|
|
1171
1180
|
} else {
|
|
1172
|
-
const resourcesMap2 = (0,
|
|
1181
|
+
const resourcesMap2 = (0, import_utils2.getResourcesMap)(resources);
|
|
1173
1182
|
const resourceIds = resources.map((n) => n.id);
|
|
1174
1183
|
const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
|
|
1175
1184
|
resourceIds,
|
|
@@ -1307,7 +1316,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1307
1316
|
currentResourcesRenderList.push(...n.renderList || []);
|
|
1308
1317
|
}
|
|
1309
1318
|
});
|
|
1310
|
-
const resourcesMap = (0,
|
|
1319
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(currentResourcesRenderList);
|
|
1311
1320
|
if (item.holder_id) {
|
|
1312
1321
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1313
1322
|
allCartItems,
|
|
@@ -1372,7 +1381,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1372
1381
|
}
|
|
1373
1382
|
});
|
|
1374
1383
|
};
|
|
1375
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1384
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1376
1385
|
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1377
1386
|
accountList.forEach((account) => {
|
|
1378
1387
|
const cartItems2 = this.store.cart.getCartByAccount(account.getId());
|
|
@@ -1388,7 +1397,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1388
1397
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1389
1398
|
let dateRange = this.store.date.getDateRange();
|
|
1390
1399
|
const resources = [];
|
|
1391
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1400
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1392
1401
|
const resourceIds = [];
|
|
1393
1402
|
let resourcesTypeId = void 0;
|
|
1394
1403
|
let isSingleResource = false;
|
|
@@ -1402,7 +1411,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1402
1411
|
isSingleResource = n.type === "single";
|
|
1403
1412
|
}
|
|
1404
1413
|
});
|
|
1405
|
-
if (item.resource_id) {
|
|
1414
|
+
if (item.resource_id && !resourceIds.includes(item.resource_id)) {
|
|
1406
1415
|
resourceIds.push(item.resource_id);
|
|
1407
1416
|
}
|
|
1408
1417
|
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(
|
|
@@ -1426,7 +1435,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1426
1435
|
}
|
|
1427
1436
|
});
|
|
1428
1437
|
}
|
|
1429
|
-
const resourcesMap = (0,
|
|
1438
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1430
1439
|
let duration = 0;
|
|
1431
1440
|
const accountList = this.store.accountList.getAccounts();
|
|
1432
1441
|
const checkDuration = (cartItems2) => {
|
|
@@ -1490,6 +1499,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1490
1499
|
return 0;
|
|
1491
1500
|
}, 0);
|
|
1492
1501
|
}
|
|
1502
|
+
const calculateCapacityFromCartItems = (items) => {
|
|
1503
|
+
return items.reduce((total, item) => {
|
|
1504
|
+
return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
|
|
1505
|
+
}, 0);
|
|
1506
|
+
};
|
|
1507
|
+
let maxCapacity = 1;
|
|
1508
|
+
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1509
|
+
accountList.forEach((account) => {
|
|
1510
|
+
const accountCartItems = this.store.cart.getCartByAccount(account.getId());
|
|
1511
|
+
const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
|
|
1512
|
+
if (currentCapacity > maxCapacity) {
|
|
1513
|
+
maxCapacity = currentCapacity;
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
} else {
|
|
1517
|
+
maxCapacity = calculateCapacityFromCartItems(cartItems);
|
|
1518
|
+
}
|
|
1493
1519
|
const timeSlots = (0, import_resources.getTimeSlicesByResources)({
|
|
1494
1520
|
resourceIds,
|
|
1495
1521
|
resourcesMap,
|
|
@@ -1497,6 +1523,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1497
1523
|
currentDate: dateRange[0].date,
|
|
1498
1524
|
split: 10,
|
|
1499
1525
|
resourcesUseableMap,
|
|
1526
|
+
capacity: maxCapacity,
|
|
1500
1527
|
cut_off_time: maxCutOffTime,
|
|
1501
1528
|
hasFlexibleDuration,
|
|
1502
1529
|
operating_day_boundary,
|
|
@@ -1507,7 +1534,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1507
1534
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
|
|
1508
1535
|
submitTimeSlot(timeSlots) {
|
|
1509
1536
|
var _a, _b;
|
|
1510
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1537
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1511
1538
|
const allResources = this.store.date.getResourcesListByDate(
|
|
1512
1539
|
timeSlots.start_at.format("YYYY-MM-DD")
|
|
1513
1540
|
);
|
|
@@ -1585,7 +1612,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1585
1612
|
getScheduleDataByIds(scheduleIds) {
|
|
1586
1613
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
1587
1614
|
const targetSchedulesData = targetSchedules.map((item) => {
|
|
1588
|
-
return (0,
|
|
1615
|
+
return (0, import_utils3.calcCalendarDataByScheduleResult)(item);
|
|
1589
1616
|
});
|
|
1590
1617
|
const newSchedule = {};
|
|
1591
1618
|
targetSchedulesData.forEach((item) => {
|
|
@@ -1657,7 +1684,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1657
1684
|
const resourcesDates = this.store.date.getDateList();
|
|
1658
1685
|
const targetResourceDate = resourcesDates.find((n) => n.date === date);
|
|
1659
1686
|
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1660
|
-
const resourcesMap = (0,
|
|
1687
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
|
|
1661
1688
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1662
1689
|
cartItems,
|
|
1663
1690
|
"",
|
|
@@ -1669,12 +1696,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1669
1696
|
selectedResources,
|
|
1670
1697
|
1
|
|
1671
1698
|
);
|
|
1672
|
-
const minTimeMaxTime = (0,
|
|
1699
|
+
const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
|
|
1673
1700
|
targetSchedules,
|
|
1674
1701
|
{},
|
|
1675
1702
|
date
|
|
1676
1703
|
);
|
|
1677
|
-
const scheduleTimeSlots = (0,
|
|
1704
|
+
const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1678
1705
|
let allProductResources = productResources.flatMap((n) => n.renderList);
|
|
1679
1706
|
allProductResources.sort((a, b) => {
|
|
1680
1707
|
var _a2, _b2, _c2, _d2;
|
|
@@ -1790,7 +1817,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1790
1817
|
otherSameTimesCartItems.forEach((m) => {
|
|
1791
1818
|
var _a2, _b2;
|
|
1792
1819
|
const productResources2 = (0, import_resources.getResourcesByProduct)(
|
|
1793
|
-
(0,
|
|
1820
|
+
(0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
|
|
1794
1821
|
((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
|
|
1795
1822
|
selectedResources,
|
|
1796
1823
|
1
|
|
@@ -1813,7 +1840,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1813
1840
|
const mSet = /* @__PURE__ */ new Map();
|
|
1814
1841
|
mTimes.forEach((n2) => {
|
|
1815
1842
|
n2.event_list.forEach((m) => {
|
|
1816
|
-
|
|
1843
|
+
if ((0, import_resources.isConflict)(
|
|
1844
|
+
{ start_at: m.start_at, end_at: m.end_at },
|
|
1845
|
+
{ start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
|
|
1846
|
+
)) {
|
|
1847
|
+
mSet.set(m.id, m.pax || 1);
|
|
1848
|
+
}
|
|
1817
1849
|
});
|
|
1818
1850
|
});
|
|
1819
1851
|
acc += Array.from(mSet.values()).reduce((acc2, curr2) => acc2 + curr2, 0);
|
|
@@ -1932,7 +1964,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1932
1964
|
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
1933
1965
|
if (!targetResourceDate)
|
|
1934
1966
|
return { success: false, minAvailableCount: 0 };
|
|
1935
|
-
const resourcesMap = (0,
|
|
1967
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
1936
1968
|
const resourceCodeToFormIdMap = {};
|
|
1937
1969
|
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
1938
1970
|
var _a2, _b2;
|
|
@@ -2074,7 +2106,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2074
2106
|
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2075
2107
|
if (!targetResourceDate)
|
|
2076
2108
|
continue;
|
|
2077
|
-
const resourcesMap = (0,
|
|
2109
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2078
2110
|
itemsInTimeSlot.forEach((cartItem) => {
|
|
2079
2111
|
if (!cartItem._productOrigin)
|
|
2080
2112
|
return;
|
|
@@ -2086,7 +2118,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2086
2118
|
}
|
|
2087
2119
|
});
|
|
2088
2120
|
});
|
|
2089
|
-
|
|
2121
|
+
const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
|
|
2122
|
+
if (!success) {
|
|
2090
2123
|
const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2091
2124
|
return { success: false, minAvailableCount: minAvailableCount2 };
|
|
2092
2125
|
}
|
|
@@ -2094,6 +2127,268 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2094
2127
|
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2095
2128
|
return { success: true, minAvailableCount };
|
|
2096
2129
|
}
|
|
2130
|
+
/**
|
|
2131
|
+
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
2132
|
+
* 参考 addProductToCart 方法的实现
|
|
2133
|
+
*/
|
|
2134
|
+
convertProductToCartItem({
|
|
2135
|
+
product,
|
|
2136
|
+
date,
|
|
2137
|
+
account
|
|
2138
|
+
}) {
|
|
2139
|
+
const {
|
|
2140
|
+
bundle,
|
|
2141
|
+
options,
|
|
2142
|
+
origin,
|
|
2143
|
+
product_variant_id,
|
|
2144
|
+
quantity = 1
|
|
2145
|
+
} = product || {};
|
|
2146
|
+
const productData = { ...origin, product_variant_id };
|
|
2147
|
+
const processedProduct = (0, import_utils.handleVariantProduct)(productData);
|
|
2148
|
+
if (!account) {
|
|
2149
|
+
const activeAccount = this.getActiveAccount();
|
|
2150
|
+
if (activeAccount) {
|
|
2151
|
+
account = activeAccount;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
const cartItem = {
|
|
2155
|
+
_id: (0, import_utils.getUniqueId)("temp_"),
|
|
2156
|
+
_origin: (0, import_utils.createCartItemOrigin)(),
|
|
2157
|
+
_productOrigin: processedProduct,
|
|
2158
|
+
_productInit: product
|
|
2159
|
+
};
|
|
2160
|
+
(0, import_utils.formatProductToCartItem)({
|
|
2161
|
+
cartItem,
|
|
2162
|
+
product: processedProduct,
|
|
2163
|
+
bundle,
|
|
2164
|
+
options,
|
|
2165
|
+
product_variant_id,
|
|
2166
|
+
quantity
|
|
2167
|
+
});
|
|
2168
|
+
if (date) {
|
|
2169
|
+
(0, import_utils.formatDateToCartItem)({
|
|
2170
|
+
cartItem,
|
|
2171
|
+
date
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
if (account) {
|
|
2175
|
+
(0, import_utils.formatAccountToCartItem)({
|
|
2176
|
+
cartItem,
|
|
2177
|
+
account
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
2180
|
+
return cartItem;
|
|
2181
|
+
}
|
|
2182
|
+
checkMaxDurationCapacityForDetailNums({
|
|
2183
|
+
product,
|
|
2184
|
+
date,
|
|
2185
|
+
account
|
|
2186
|
+
}) {
|
|
2187
|
+
var _a, _b;
|
|
2188
|
+
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
2189
|
+
const currentCartItem = this.convertProductToCartItem({ product, date, account });
|
|
2190
|
+
cartItems.push(currentCartItem);
|
|
2191
|
+
if (cartItems.length === 0)
|
|
2192
|
+
return { success: true, minAvailableCount: 0 };
|
|
2193
|
+
const itemsWithTime = [];
|
|
2194
|
+
const itemsWithoutTime = [];
|
|
2195
|
+
const availableCountsByResourceType = [];
|
|
2196
|
+
cartItems.forEach((cartItem) => {
|
|
2197
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2198
|
+
itemsWithTime.push(cartItem);
|
|
2199
|
+
} else {
|
|
2200
|
+
itemsWithoutTime.push(cartItem);
|
|
2201
|
+
}
|
|
2202
|
+
});
|
|
2203
|
+
const processedItemsWithoutTime = [];
|
|
2204
|
+
if (itemsWithoutTime.length > 0) {
|
|
2205
|
+
const itemsByResourceType = {};
|
|
2206
|
+
itemsWithoutTime.forEach((cartItem) => {
|
|
2207
|
+
var _a2;
|
|
2208
|
+
if (!cartItem._productOrigin)
|
|
2209
|
+
return;
|
|
2210
|
+
const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
|
|
2211
|
+
resourceTypes.forEach((resourceType) => {
|
|
2212
|
+
var _a3;
|
|
2213
|
+
if (resourceType.status === 1) {
|
|
2214
|
+
const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
|
|
2215
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
2216
|
+
itemsByResourceType[resourceCode] = [];
|
|
2217
|
+
}
|
|
2218
|
+
if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
|
|
2219
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
});
|
|
2223
|
+
});
|
|
2224
|
+
const dateRange = this.store.date.getDateRange();
|
|
2225
|
+
if (!dateRange || dateRange.length === 0)
|
|
2226
|
+
return { success: false, minAvailableCount: 0 };
|
|
2227
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2228
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
2229
|
+
if (!targetResourceDate)
|
|
2230
|
+
return { success: false, minAvailableCount: 0 };
|
|
2231
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2232
|
+
const resourceCodeToFormIdMap = {};
|
|
2233
|
+
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
2234
|
+
var _a2, _b2;
|
|
2235
|
+
if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
|
|
2236
|
+
cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
|
|
2237
|
+
var _a3, _b3;
|
|
2238
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
2239
|
+
const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
|
|
2240
|
+
if (formId) {
|
|
2241
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
});
|
|
2247
|
+
let hasCapacityIssue = false;
|
|
2248
|
+
const resourceCapacityInfo = [];
|
|
2249
|
+
const processedCartItemIds = /* @__PURE__ */ new Set();
|
|
2250
|
+
for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
|
|
2251
|
+
const targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
2252
|
+
if (!targetFormId) {
|
|
2253
|
+
console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
|
|
2254
|
+
return { success: false, minAvailableCount: 0 };
|
|
2255
|
+
}
|
|
2256
|
+
const resourcesOfThisType = [];
|
|
2257
|
+
items.forEach((cartItem) => {
|
|
2258
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
2259
|
+
productResourceIds.forEach((resourceId) => {
|
|
2260
|
+
var _a2;
|
|
2261
|
+
const resource = resourcesMap[resourceId];
|
|
2262
|
+
if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
|
|
2263
|
+
if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
|
|
2264
|
+
resourcesOfThisType.push(resource);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
});
|
|
2269
|
+
if (resourcesOfThisType.length === 0) {
|
|
2270
|
+
console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
|
|
2271
|
+
return { success: false, minAvailableCount: 0 };
|
|
2272
|
+
}
|
|
2273
|
+
let resourceTypeConfig = null;
|
|
2274
|
+
for (const cartItem of items) {
|
|
2275
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
2276
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
2277
|
+
(r) => r.code === resourceCode && r.status === 1
|
|
2278
|
+
);
|
|
2279
|
+
if (resourceTypeConfig)
|
|
2280
|
+
break;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
2284
|
+
let totalAvailable;
|
|
2285
|
+
let requiredAmount;
|
|
2286
|
+
let availableAmount;
|
|
2287
|
+
if (isMultipleBooking) {
|
|
2288
|
+
totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
|
|
2289
|
+
return sum + (resource.capacity || 0);
|
|
2290
|
+
}, 0);
|
|
2291
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2292
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
2293
|
+
return sum + currentCapacity;
|
|
2294
|
+
}, 0);
|
|
2295
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2296
|
+
} else {
|
|
2297
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2298
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2299
|
+
return sum + (cartItem.num || 1);
|
|
2300
|
+
}, 0);
|
|
2301
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2302
|
+
}
|
|
2303
|
+
resourceCapacityInfo.push({
|
|
2304
|
+
code: resourceCode,
|
|
2305
|
+
available: availableAmount,
|
|
2306
|
+
total: totalAvailable,
|
|
2307
|
+
required: requiredAmount,
|
|
2308
|
+
isMultiple: isMultipleBooking
|
|
2309
|
+
});
|
|
2310
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2311
|
+
if (requiredAmount > totalAvailable) {
|
|
2312
|
+
hasCapacityIssue = true;
|
|
2313
|
+
console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
|
|
2314
|
+
}
|
|
2315
|
+
console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
|
|
2316
|
+
id: r.id,
|
|
2317
|
+
times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
|
|
2318
|
+
})));
|
|
2319
|
+
const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2320
|
+
console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
|
|
2321
|
+
if (commonTimeSlots.length === 0) {
|
|
2322
|
+
console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
|
|
2323
|
+
return { success: false, minAvailableCount: 0 };
|
|
2324
|
+
}
|
|
2325
|
+
const firstCommonSlot = commonTimeSlots[0];
|
|
2326
|
+
console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
|
|
2327
|
+
items.forEach((cartItem) => {
|
|
2328
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
2329
|
+
processedCartItemIds.add(cartItem._id);
|
|
2330
|
+
const processedItem = {
|
|
2331
|
+
...cartItem,
|
|
2332
|
+
start_date: dateRange[0].date,
|
|
2333
|
+
start_time: firstCommonSlot.startTime,
|
|
2334
|
+
end_time: firstCommonSlot.endTime,
|
|
2335
|
+
end_date: dateRange[0].date
|
|
2336
|
+
};
|
|
2337
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
}
|
|
2341
|
+
if (hasCapacityIssue) {
|
|
2342
|
+
const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
|
|
2343
|
+
if (overCapacityResources.length > 0) {
|
|
2344
|
+
const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
|
|
2345
|
+
return { success: false, minAvailableCount: minTotalCapacity2 };
|
|
2346
|
+
}
|
|
2347
|
+
const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
|
|
2348
|
+
return { success: false, minAvailableCount: minTotalCapacity };
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
|
|
2352
|
+
const cartItemsByTimeSlot = {};
|
|
2353
|
+
allProcessedItems.forEach((cartItem) => {
|
|
2354
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
|
|
2355
|
+
return;
|
|
2356
|
+
const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
|
|
2357
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
2358
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
2359
|
+
}
|
|
2360
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
2361
|
+
});
|
|
2362
|
+
for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
|
|
2363
|
+
const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
|
|
2364
|
+
const timeSlotStart = `${startDate} ${startTime}`;
|
|
2365
|
+
const timeSlotEnd = `${endDate} ${endTime}`;
|
|
2366
|
+
const allResourcesForTimeSlot = [];
|
|
2367
|
+
const resourcesIdSet = /* @__PURE__ */ new Set();
|
|
2368
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2369
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2370
|
+
if (!targetResourceDate)
|
|
2371
|
+
continue;
|
|
2372
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2373
|
+
itemsInTimeSlot.forEach((cartItem) => {
|
|
2374
|
+
if (!cartItem._productOrigin)
|
|
2375
|
+
return;
|
|
2376
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
2377
|
+
productResourceIds.forEach((resourceId) => {
|
|
2378
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
2379
|
+
resourcesIdSet.add(resourceId);
|
|
2380
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
2381
|
+
}
|
|
2382
|
+
});
|
|
2383
|
+
});
|
|
2384
|
+
const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
|
|
2385
|
+
if (!success) {
|
|
2386
|
+
return { success: false, minAvailableCount: available };
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2390
|
+
return { success: true, minAvailableCount };
|
|
2391
|
+
}
|
|
2097
2392
|
setOtherData(key, value) {
|
|
2098
2393
|
this.otherData[key] = value;
|
|
2099
2394
|
this.checkSaveCache({
|
|
@@ -2145,8 +2440,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2145
2440
|
resources.push(...n.resource);
|
|
2146
2441
|
});
|
|
2147
2442
|
}
|
|
2148
|
-
const resourcesMap = (0,
|
|
2149
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2443
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
2444
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2150
2445
|
const cartItem = cartItems.find((item) => item._id === cartItemId);
|
|
2151
2446
|
if (!cartItem)
|
|
2152
2447
|
return [];
|
|
@@ -2359,12 +2654,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2359
2654
|
}
|
|
2360
2655
|
}
|
|
2361
2656
|
if (status === "available") {
|
|
2362
|
-
const minTimeMaxTime = (0,
|
|
2657
|
+
const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
|
|
2363
2658
|
targetSchedules,
|
|
2364
2659
|
{},
|
|
2365
2660
|
currentDateStr
|
|
2366
2661
|
);
|
|
2367
|
-
const scheduleTimeSlots = (0,
|
|
2662
|
+
const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
|
|
2368
2663
|
const timesSlotCanUse = scheduleTimeSlots.some((item) => {
|
|
2369
2664
|
const resourcesUseableMap = {};
|
|
2370
2665
|
return openResources.every((resource) => {
|
|
@@ -2421,7 +2716,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2421
2716
|
}
|
|
2422
2717
|
currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
|
|
2423
2718
|
}
|
|
2424
|
-
dates = (0,
|
|
2719
|
+
dates = (0, import_utils4.handleAvailableDateByResource)(res.data, dates);
|
|
2425
2720
|
this.store.date.setDateList(dates);
|
|
2426
2721
|
if (!this.store.currentProductMeta)
|
|
2427
2722
|
this.store.currentProductMeta = {};
|
|
@@ -2437,11 +2732,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2437
2732
|
};
|
|
2438
2733
|
}
|
|
2439
2734
|
isCartAllNormalProducts() {
|
|
2440
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2735
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2441
2736
|
return !cartItems.length;
|
|
2442
2737
|
}
|
|
2443
2738
|
isCartHasDurationProduct() {
|
|
2444
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2739
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2445
2740
|
return cartItems.some((n) => {
|
|
2446
2741
|
var _a;
|
|
2447
2742
|
return (_a = n._productOrigin) == null ? void 0 : _a.duration;
|
|
@@ -2450,11 +2745,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2450
2745
|
isTargetNormalProduct(product) {
|
|
2451
2746
|
if (!product)
|
|
2452
2747
|
return false;
|
|
2453
|
-
return (0,
|
|
2748
|
+
return (0, import_utils5.isNormalProduct)(product);
|
|
2454
2749
|
}
|
|
2455
2750
|
isTargetCartIdNormalProduct(id) {
|
|
2456
2751
|
const cartItem = this.store.cart.getItems().find((n) => n._id === id);
|
|
2457
|
-
return cartItem && (0,
|
|
2752
|
+
return cartItem && (0, import_utils5.isNormalProduct)(cartItem._productOrigin);
|
|
2458
2753
|
}
|
|
2459
2754
|
};
|
|
2460
2755
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -15,8 +15,9 @@ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any
|
|
|
15
15
|
* @return {*}
|
|
16
16
|
* @Author: zhiwei.Wang
|
|
17
17
|
*/
|
|
18
|
-
export declare const getSumCapacity: ({ capacity }: {
|
|
18
|
+
export declare const getSumCapacity: ({ capacity, num }: {
|
|
19
19
|
capacity: CapacityItem[];
|
|
20
|
+
num: number;
|
|
20
21
|
}) => number;
|
|
21
22
|
/**
|
|
22
23
|
* 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
|
|
@@ -67,4 +68,8 @@ export declare function getResourcesIdsByProduct(product: any): number[];
|
|
|
67
68
|
/**
|
|
68
69
|
* 检查特定时间段的容量是否足够
|
|
69
70
|
*/
|
|
70
|
-
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]):
|
|
71
|
+
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
|
|
72
|
+
success: boolean;
|
|
73
|
+
required: number;
|
|
74
|
+
available: number;
|
|
75
|
+
};
|