@pisell/pisellos 2.1.30 → 2.1.32
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/ProductList/index.js +3 -2
- package/dist/solution/BookingByStep/index.d.ts +16 -0
- package/dist/solution/BookingByStep/index.js +466 -21
- package/dist/solution/BookingByStep/utils/capacity.d.ts +7 -2
- package/dist/solution/BookingByStep/utils/capacity.js +24 -8
- package/lib/modules/ProductList/index.js +3 -2
- package/lib/solution/BookingByStep/index.d.ts +16 -0
- package/lib/solution/BookingByStep/index.js +311 -39
- package/lib/solution/BookingByStep/utils/capacity.d.ts +7 -2
- package/lib/solution/BookingByStep/utils/capacity.js +21 -8
- 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);
|
|
@@ -841,7 +850,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
841
850
|
resources.push(...n.resource);
|
|
842
851
|
});
|
|
843
852
|
}
|
|
844
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
853
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
845
854
|
if (!resources.length) {
|
|
846
855
|
const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
|
|
847
856
|
if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
|
|
@@ -857,7 +866,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
857
866
|
});
|
|
858
867
|
}
|
|
859
868
|
}
|
|
860
|
-
const resourcesMap = (0,
|
|
869
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
861
870
|
const arr = [];
|
|
862
871
|
cartItems.forEach((cartItem) => {
|
|
863
872
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
@@ -986,14 +995,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
986
995
|
*/
|
|
987
996
|
getResourcesListByCartItem(id) {
|
|
988
997
|
var _a, _b;
|
|
989
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
998
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
990
999
|
const dateRange = this.store.date.getDateRange();
|
|
991
1000
|
const resources = [];
|
|
992
1001
|
dateRange.forEach((n) => {
|
|
993
1002
|
if (n.resource)
|
|
994
1003
|
resources.push(...n.resource);
|
|
995
1004
|
});
|
|
996
|
-
const resourcesMap = (0,
|
|
1005
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
997
1006
|
const targetCartItem = cartItems.find((n) => n._id === id);
|
|
998
1007
|
if (!targetCartItem) {
|
|
999
1008
|
throw new Error(`没有找到${id}购物车商品`);
|
|
@@ -1050,7 +1059,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1050
1059
|
capacity
|
|
1051
1060
|
}) {
|
|
1052
1061
|
var _a, _b, _c;
|
|
1053
|
-
if ((0,
|
|
1062
|
+
if ((0, import_utils5.isNormalProduct)(cartItem._productOrigin)) {
|
|
1054
1063
|
return {};
|
|
1055
1064
|
}
|
|
1056
1065
|
const dateRange = this.store.date.getDateRange();
|
|
@@ -1085,7 +1094,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1085
1094
|
});
|
|
1086
1095
|
}
|
|
1087
1096
|
}
|
|
1088
|
-
const resourcesMap = (0,
|
|
1097
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
|
|
1089
1098
|
const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1090
1099
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1091
1100
|
allCartItems,
|
|
@@ -1166,7 +1175,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1166
1175
|
selectedResource: targetResource
|
|
1167
1176
|
};
|
|
1168
1177
|
} else {
|
|
1169
|
-
const resourcesMap2 = (0,
|
|
1178
|
+
const resourcesMap2 = (0, import_utils2.getResourcesMap)(resources);
|
|
1170
1179
|
const resourceIds = resources.map((n) => n.id);
|
|
1171
1180
|
const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
|
|
1172
1181
|
resourceIds,
|
|
@@ -1304,7 +1313,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1304
1313
|
currentResourcesRenderList.push(...n.renderList || []);
|
|
1305
1314
|
}
|
|
1306
1315
|
});
|
|
1307
|
-
const resourcesMap = (0,
|
|
1316
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(currentResourcesRenderList);
|
|
1308
1317
|
if (item.holder_id) {
|
|
1309
1318
|
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1310
1319
|
allCartItems,
|
|
@@ -1369,7 +1378,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1369
1378
|
}
|
|
1370
1379
|
});
|
|
1371
1380
|
};
|
|
1372
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1381
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1373
1382
|
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1374
1383
|
accountList.forEach((account) => {
|
|
1375
1384
|
const cartItems2 = this.store.cart.getCartByAccount(account.getId());
|
|
@@ -1385,7 +1394,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1385
1394
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1386
1395
|
let dateRange = this.store.date.getDateRange();
|
|
1387
1396
|
const resources = [];
|
|
1388
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1397
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1389
1398
|
const resourceIds = [];
|
|
1390
1399
|
let resourcesTypeId = void 0;
|
|
1391
1400
|
let isSingleResource = false;
|
|
@@ -1423,7 +1432,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1423
1432
|
}
|
|
1424
1433
|
});
|
|
1425
1434
|
}
|
|
1426
|
-
const resourcesMap = (0,
|
|
1435
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1427
1436
|
let duration = 0;
|
|
1428
1437
|
const accountList = this.store.accountList.getAccounts();
|
|
1429
1438
|
const checkDuration = (cartItems2) => {
|
|
@@ -1522,7 +1531,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1522
1531
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
|
|
1523
1532
|
submitTimeSlot(timeSlots) {
|
|
1524
1533
|
var _a, _b;
|
|
1525
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
1534
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
1526
1535
|
const allResources = this.store.date.getResourcesListByDate(
|
|
1527
1536
|
timeSlots.start_at.format("YYYY-MM-DD")
|
|
1528
1537
|
);
|
|
@@ -1600,7 +1609,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1600
1609
|
getScheduleDataByIds(scheduleIds) {
|
|
1601
1610
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
1602
1611
|
const targetSchedulesData = targetSchedules.map((item) => {
|
|
1603
|
-
return (0,
|
|
1612
|
+
return (0, import_utils3.calcCalendarDataByScheduleResult)(item);
|
|
1604
1613
|
});
|
|
1605
1614
|
const newSchedule = {};
|
|
1606
1615
|
targetSchedulesData.forEach((item) => {
|
|
@@ -1672,7 +1681,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1672
1681
|
const resourcesDates = this.store.date.getDateList();
|
|
1673
1682
|
const targetResourceDate = resourcesDates.find((n) => n.date === date);
|
|
1674
1683
|
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1675
|
-
const resourcesMap = (0,
|
|
1684
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
|
|
1676
1685
|
const selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1677
1686
|
cartItems,
|
|
1678
1687
|
"",
|
|
@@ -1684,12 +1693,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1684
1693
|
selectedResources,
|
|
1685
1694
|
1
|
|
1686
1695
|
);
|
|
1687
|
-
const minTimeMaxTime = (0,
|
|
1696
|
+
const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
|
|
1688
1697
|
targetSchedules,
|
|
1689
1698
|
{},
|
|
1690
1699
|
date
|
|
1691
1700
|
);
|
|
1692
|
-
const scheduleTimeSlots = (0,
|
|
1701
|
+
const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
|
|
1693
1702
|
let allProductResources = productResources.flatMap((n) => n.renderList);
|
|
1694
1703
|
allProductResources.sort((a, b) => {
|
|
1695
1704
|
var _a2, _b2, _c2, _d2;
|
|
@@ -1805,7 +1814,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1805
1814
|
otherSameTimesCartItems.forEach((m) => {
|
|
1806
1815
|
var _a2, _b2;
|
|
1807
1816
|
const productResources2 = (0, import_resources.getResourcesByProduct)(
|
|
1808
|
-
(0,
|
|
1817
|
+
(0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
|
|
1809
1818
|
((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
|
|
1810
1819
|
selectedResources,
|
|
1811
1820
|
1
|
|
@@ -1952,7 +1961,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1952
1961
|
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
1953
1962
|
if (!targetResourceDate)
|
|
1954
1963
|
return { success: false, minAvailableCount: 0 };
|
|
1955
|
-
const resourcesMap = (0,
|
|
1964
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
1956
1965
|
const resourceCodeToFormIdMap = {};
|
|
1957
1966
|
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
1958
1967
|
var _a2, _b2;
|
|
@@ -2094,7 +2103,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2094
2103
|
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2095
2104
|
if (!targetResourceDate)
|
|
2096
2105
|
continue;
|
|
2097
|
-
const resourcesMap = (0,
|
|
2106
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2098
2107
|
itemsInTimeSlot.forEach((cartItem) => {
|
|
2099
2108
|
if (!cartItem._productOrigin)
|
|
2100
2109
|
return;
|
|
@@ -2106,7 +2115,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2106
2115
|
}
|
|
2107
2116
|
});
|
|
2108
2117
|
});
|
|
2109
|
-
|
|
2118
|
+
const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
|
|
2119
|
+
if (!success) {
|
|
2110
2120
|
const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2111
2121
|
return { success: false, minAvailableCount: minAvailableCount2 };
|
|
2112
2122
|
}
|
|
@@ -2114,6 +2124,268 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2114
2124
|
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2115
2125
|
return { success: true, minAvailableCount };
|
|
2116
2126
|
}
|
|
2127
|
+
/**
|
|
2128
|
+
* 将 ProductData 转换为 CartItem,但不添加到购物车
|
|
2129
|
+
* 参考 addProductToCart 方法的实现
|
|
2130
|
+
*/
|
|
2131
|
+
convertProductToCartItem({
|
|
2132
|
+
product,
|
|
2133
|
+
date,
|
|
2134
|
+
account
|
|
2135
|
+
}) {
|
|
2136
|
+
const {
|
|
2137
|
+
bundle,
|
|
2138
|
+
options,
|
|
2139
|
+
origin,
|
|
2140
|
+
product_variant_id,
|
|
2141
|
+
quantity = 1
|
|
2142
|
+
} = product || {};
|
|
2143
|
+
const productData = { ...origin, product_variant_id };
|
|
2144
|
+
const processedProduct = (0, import_utils.handleVariantProduct)(productData);
|
|
2145
|
+
if (!account) {
|
|
2146
|
+
const activeAccount = this.getActiveAccount();
|
|
2147
|
+
if (activeAccount) {
|
|
2148
|
+
account = activeAccount;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
const cartItem = {
|
|
2152
|
+
_id: (0, import_utils.getUniqueId)("temp_"),
|
|
2153
|
+
_origin: (0, import_utils.createCartItemOrigin)(),
|
|
2154
|
+
_productOrigin: processedProduct,
|
|
2155
|
+
_productInit: product
|
|
2156
|
+
};
|
|
2157
|
+
(0, import_utils.formatProductToCartItem)({
|
|
2158
|
+
cartItem,
|
|
2159
|
+
product: processedProduct,
|
|
2160
|
+
bundle,
|
|
2161
|
+
options,
|
|
2162
|
+
product_variant_id,
|
|
2163
|
+
quantity
|
|
2164
|
+
});
|
|
2165
|
+
if (date) {
|
|
2166
|
+
(0, import_utils.formatDateToCartItem)({
|
|
2167
|
+
cartItem,
|
|
2168
|
+
date
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
if (account) {
|
|
2172
|
+
(0, import_utils.formatAccountToCartItem)({
|
|
2173
|
+
cartItem,
|
|
2174
|
+
account
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
return cartItem;
|
|
2178
|
+
}
|
|
2179
|
+
checkMaxDurationCapacityForDetailNums({
|
|
2180
|
+
product,
|
|
2181
|
+
date,
|
|
2182
|
+
account
|
|
2183
|
+
}) {
|
|
2184
|
+
var _a, _b;
|
|
2185
|
+
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
2186
|
+
const currentCartItem = this.convertProductToCartItem({ product, date, account });
|
|
2187
|
+
cartItems.push(currentCartItem);
|
|
2188
|
+
if (cartItems.length === 0)
|
|
2189
|
+
return { success: true, minAvailableCount: 0 };
|
|
2190
|
+
const itemsWithTime = [];
|
|
2191
|
+
const itemsWithoutTime = [];
|
|
2192
|
+
const availableCountsByResourceType = [];
|
|
2193
|
+
cartItems.forEach((cartItem) => {
|
|
2194
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
2195
|
+
itemsWithTime.push(cartItem);
|
|
2196
|
+
} else {
|
|
2197
|
+
itemsWithoutTime.push(cartItem);
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2200
|
+
const processedItemsWithoutTime = [];
|
|
2201
|
+
if (itemsWithoutTime.length > 0) {
|
|
2202
|
+
const itemsByResourceType = {};
|
|
2203
|
+
itemsWithoutTime.forEach((cartItem) => {
|
|
2204
|
+
var _a2;
|
|
2205
|
+
if (!cartItem._productOrigin)
|
|
2206
|
+
return;
|
|
2207
|
+
const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
|
|
2208
|
+
resourceTypes.forEach((resourceType) => {
|
|
2209
|
+
var _a3;
|
|
2210
|
+
if (resourceType.status === 1) {
|
|
2211
|
+
const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
|
|
2212
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
2213
|
+
itemsByResourceType[resourceCode] = [];
|
|
2214
|
+
}
|
|
2215
|
+
if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
|
|
2216
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
});
|
|
2220
|
+
});
|
|
2221
|
+
const dateRange = this.store.date.getDateRange();
|
|
2222
|
+
if (!dateRange || dateRange.length === 0)
|
|
2223
|
+
return { success: false, minAvailableCount: 0 };
|
|
2224
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2225
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
2226
|
+
if (!targetResourceDate)
|
|
2227
|
+
return { success: false, minAvailableCount: 0 };
|
|
2228
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2229
|
+
const resourceCodeToFormIdMap = {};
|
|
2230
|
+
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
2231
|
+
var _a2, _b2;
|
|
2232
|
+
if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
|
|
2233
|
+
cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
|
|
2234
|
+
var _a3, _b3;
|
|
2235
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
2236
|
+
const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
|
|
2237
|
+
if (formId) {
|
|
2238
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
let hasCapacityIssue = false;
|
|
2245
|
+
const resourceCapacityInfo = [];
|
|
2246
|
+
const processedCartItemIds = /* @__PURE__ */ new Set();
|
|
2247
|
+
for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
|
|
2248
|
+
const targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
2249
|
+
if (!targetFormId) {
|
|
2250
|
+
console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
|
|
2251
|
+
return { success: false, minAvailableCount: 0 };
|
|
2252
|
+
}
|
|
2253
|
+
const resourcesOfThisType = [];
|
|
2254
|
+
items.forEach((cartItem) => {
|
|
2255
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
2256
|
+
productResourceIds.forEach((resourceId) => {
|
|
2257
|
+
var _a2;
|
|
2258
|
+
const resource = resourcesMap[resourceId];
|
|
2259
|
+
if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
|
|
2260
|
+
if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
|
|
2261
|
+
resourcesOfThisType.push(resource);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
});
|
|
2265
|
+
});
|
|
2266
|
+
if (resourcesOfThisType.length === 0) {
|
|
2267
|
+
console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
|
|
2268
|
+
return { success: false, minAvailableCount: 0 };
|
|
2269
|
+
}
|
|
2270
|
+
let resourceTypeConfig = null;
|
|
2271
|
+
for (const cartItem of items) {
|
|
2272
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
2273
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
2274
|
+
(r) => r.code === resourceCode && r.status === 1
|
|
2275
|
+
);
|
|
2276
|
+
if (resourceTypeConfig)
|
|
2277
|
+
break;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
2281
|
+
let totalAvailable;
|
|
2282
|
+
let requiredAmount;
|
|
2283
|
+
let availableAmount;
|
|
2284
|
+
if (isMultipleBooking) {
|
|
2285
|
+
totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
|
|
2286
|
+
return sum + (resource.capacity || 0);
|
|
2287
|
+
}, 0);
|
|
2288
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2289
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
2290
|
+
return sum + currentCapacity;
|
|
2291
|
+
}, 0);
|
|
2292
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2293
|
+
} else {
|
|
2294
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2295
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2296
|
+
return sum + (cartItem.num || 1);
|
|
2297
|
+
}, 0);
|
|
2298
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2299
|
+
}
|
|
2300
|
+
resourceCapacityInfo.push({
|
|
2301
|
+
code: resourceCode,
|
|
2302
|
+
available: availableAmount,
|
|
2303
|
+
total: totalAvailable,
|
|
2304
|
+
required: requiredAmount,
|
|
2305
|
+
isMultiple: isMultipleBooking
|
|
2306
|
+
});
|
|
2307
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2308
|
+
if (requiredAmount > totalAvailable) {
|
|
2309
|
+
hasCapacityIssue = true;
|
|
2310
|
+
console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
|
|
2311
|
+
}
|
|
2312
|
+
console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
|
|
2313
|
+
id: r.id,
|
|
2314
|
+
times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
|
|
2315
|
+
})));
|
|
2316
|
+
const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2317
|
+
console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
|
|
2318
|
+
if (commonTimeSlots.length === 0) {
|
|
2319
|
+
console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
|
|
2320
|
+
return { success: false, minAvailableCount: 0 };
|
|
2321
|
+
}
|
|
2322
|
+
const firstCommonSlot = commonTimeSlots[0];
|
|
2323
|
+
console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
|
|
2324
|
+
items.forEach((cartItem) => {
|
|
2325
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
2326
|
+
processedCartItemIds.add(cartItem._id);
|
|
2327
|
+
const processedItem = {
|
|
2328
|
+
...cartItem,
|
|
2329
|
+
start_date: dateRange[0].date,
|
|
2330
|
+
start_time: firstCommonSlot.startTime,
|
|
2331
|
+
end_time: firstCommonSlot.endTime,
|
|
2332
|
+
end_date: dateRange[0].date
|
|
2333
|
+
};
|
|
2334
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
if (hasCapacityIssue) {
|
|
2339
|
+
const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
|
|
2340
|
+
if (overCapacityResources.length > 0) {
|
|
2341
|
+
const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
|
|
2342
|
+
return { success: false, minAvailableCount: minTotalCapacity2 };
|
|
2343
|
+
}
|
|
2344
|
+
const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
|
|
2345
|
+
return { success: false, minAvailableCount: minTotalCapacity };
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
|
|
2349
|
+
const cartItemsByTimeSlot = {};
|
|
2350
|
+
allProcessedItems.forEach((cartItem) => {
|
|
2351
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
|
|
2352
|
+
return;
|
|
2353
|
+
const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
|
|
2354
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
2355
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
2356
|
+
}
|
|
2357
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
2358
|
+
});
|
|
2359
|
+
for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
|
|
2360
|
+
const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
|
|
2361
|
+
const timeSlotStart = `${startDate} ${startTime}`;
|
|
2362
|
+
const timeSlotEnd = `${endDate} ${endTime}`;
|
|
2363
|
+
const allResourcesForTimeSlot = [];
|
|
2364
|
+
const resourcesIdSet = /* @__PURE__ */ new Set();
|
|
2365
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2366
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2367
|
+
if (!targetResourceDate)
|
|
2368
|
+
continue;
|
|
2369
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
|
|
2370
|
+
itemsInTimeSlot.forEach((cartItem) => {
|
|
2371
|
+
if (!cartItem._productOrigin)
|
|
2372
|
+
return;
|
|
2373
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
2374
|
+
productResourceIds.forEach((resourceId) => {
|
|
2375
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
2376
|
+
resourcesIdSet.add(resourceId);
|
|
2377
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
2378
|
+
}
|
|
2379
|
+
});
|
|
2380
|
+
});
|
|
2381
|
+
const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
|
|
2382
|
+
if (!success) {
|
|
2383
|
+
return { success: false, minAvailableCount: available };
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2387
|
+
return { success: true, minAvailableCount };
|
|
2388
|
+
}
|
|
2117
2389
|
setOtherData(key, value) {
|
|
2118
2390
|
this.otherData[key] = value;
|
|
2119
2391
|
this.checkSaveCache({
|
|
@@ -2165,8 +2437,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2165
2437
|
resources.push(...n.resource);
|
|
2166
2438
|
});
|
|
2167
2439
|
}
|
|
2168
|
-
const resourcesMap = (0,
|
|
2169
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2440
|
+
const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
2441
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2170
2442
|
const cartItem = cartItems.find((item) => item._id === cartItemId);
|
|
2171
2443
|
if (!cartItem)
|
|
2172
2444
|
return [];
|
|
@@ -2379,12 +2651,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2379
2651
|
}
|
|
2380
2652
|
}
|
|
2381
2653
|
if (status === "available") {
|
|
2382
|
-
const minTimeMaxTime = (0,
|
|
2654
|
+
const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
|
|
2383
2655
|
targetSchedules,
|
|
2384
2656
|
{},
|
|
2385
2657
|
currentDateStr
|
|
2386
2658
|
);
|
|
2387
|
-
const scheduleTimeSlots = (0,
|
|
2659
|
+
const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
|
|
2388
2660
|
const timesSlotCanUse = scheduleTimeSlots.some((item) => {
|
|
2389
2661
|
const resourcesUseableMap = {};
|
|
2390
2662
|
return openResources.every((resource) => {
|
|
@@ -2441,7 +2713,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2441
2713
|
}
|
|
2442
2714
|
currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
|
|
2443
2715
|
}
|
|
2444
|
-
dates = (0,
|
|
2716
|
+
dates = (0, import_utils4.handleAvailableDateByResource)(res.data, dates);
|
|
2445
2717
|
this.store.date.setDateList(dates);
|
|
2446
2718
|
if (!this.store.currentProductMeta)
|
|
2447
2719
|
this.store.currentProductMeta = {};
|
|
@@ -2457,11 +2729,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2457
2729
|
};
|
|
2458
2730
|
}
|
|
2459
2731
|
isCartAllNormalProducts() {
|
|
2460
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2732
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2461
2733
|
return !cartItems.length;
|
|
2462
2734
|
}
|
|
2463
2735
|
isCartHasDurationProduct() {
|
|
2464
|
-
const cartItems = this.store.cart.getItems().filter((n) => !(0,
|
|
2736
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
|
|
2465
2737
|
return cartItems.some((n) => {
|
|
2466
2738
|
var _a;
|
|
2467
2739
|
return (_a = n._productOrigin) == null ? void 0 : _a.duration;
|
|
@@ -2470,11 +2742,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2470
2742
|
isTargetNormalProduct(product) {
|
|
2471
2743
|
if (!product)
|
|
2472
2744
|
return false;
|
|
2473
|
-
return (0,
|
|
2745
|
+
return (0, import_utils5.isNormalProduct)(product);
|
|
2474
2746
|
}
|
|
2475
2747
|
isTargetCartIdNormalProduct(id) {
|
|
2476
2748
|
const cartItem = this.store.cart.getItems().find((n) => n._id === id);
|
|
2477
|
-
return cartItem && (0,
|
|
2749
|
+
return cartItem && (0, import_utils5.isNormalProduct)(cartItem._productOrigin);
|
|
2478
2750
|
}
|
|
2479
2751
|
};
|
|
2480
2752
|
// 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
|
+
};
|