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