@pisell/pisellos 0.0.115 → 0.0.117
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/Cart/index.js +16 -35
- package/dist/modules/Cart/utils/cartAccount.d.ts +21 -0
- package/dist/modules/Cart/utils/cartAccount.js +52 -0
- package/dist/modules/Cart/utils/cartDate.d.ts +31 -0
- package/dist/modules/Cart/utils/cartDate.js +55 -0
- package/dist/modules/Cart/utils/cartDiscount.d.ts +19 -0
- package/dist/modules/Cart/utils/cartDiscount.js +35 -0
- package/dist/modules/Cart/utils/cartNote.d.ts +19 -0
- package/dist/modules/Cart/utils/cartNote.js +29 -0
- package/dist/modules/Cart/utils/cartProduct.d.ts +107 -0
- package/dist/modules/Cart/{utils.js → utils/cartProduct.js} +77 -416
- package/dist/modules/Cart/utils/cartRelationForms.d.ts +26 -0
- package/dist/modules/Cart/utils/cartRelationForms.js +29 -0
- package/dist/modules/Cart/utils/cartResource.d.ts +21 -0
- package/dist/modules/Cart/utils/cartResource.js +102 -0
- package/dist/modules/Cart/utils/index.d.ts +34 -0
- package/dist/modules/Cart/utils/index.js +63 -0
- package/dist/modules/Order/index.js +3 -2
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +4 -0
- package/dist/modules/Product/utils.d.ts +17 -0
- package/dist/modules/Product/utils.js +41 -0
- package/dist/solution/BookingByStep/index.d.ts +25 -0
- package/dist/solution/BookingByStep/index.js +320 -58
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +209 -0
- package/lib/modules/Cart/index.js +14 -25
- package/lib/modules/Cart/utils/cartAccount.d.ts +21 -0
- package/lib/modules/Cart/utils/cartAccount.js +65 -0
- package/lib/modules/Cart/utils/cartDate.d.ts +31 -0
- package/lib/modules/Cart/utils/cartDate.js +75 -0
- package/lib/modules/Cart/utils/cartDiscount.d.ts +19 -0
- package/lib/modules/Cart/utils/cartDiscount.js +52 -0
- package/lib/modules/Cart/utils/cartNote.d.ts +19 -0
- package/lib/modules/Cart/utils/cartNote.js +46 -0
- package/lib/modules/Cart/utils/cartProduct.d.ts +107 -0
- package/lib/modules/Cart/{utils.js → utils/cartProduct.js} +78 -328
- package/lib/modules/Cart/utils/cartRelationForms.d.ts +26 -0
- package/lib/modules/Cart/utils/cartRelationForms.js +48 -0
- package/lib/modules/Cart/utils/cartResource.d.ts +21 -0
- package/lib/modules/Cart/utils/cartResource.js +124 -0
- package/lib/modules/Cart/utils/index.d.ts +34 -0
- package/lib/modules/Cart/utils/index.js +91 -0
- package/lib/modules/Order/index.js +2 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +4 -0
- package/lib/modules/Product/utils.d.ts +17 -0
- package/lib/modules/Product/utils.js +46 -0
- package/lib/solution/BookingByStep/index.d.ts +25 -0
- package/lib/solution/BookingByStep/index.js +181 -23
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +159 -0
- package/package.json +1 -1
- package/dist/modules/Cart/utils.d.ts +0 -257
- package/lib/modules/Cart/utils.d.ts +0 -257
|
@@ -43,6 +43,8 @@ var import_utils = require("../../modules/Resource/utils");
|
|
|
43
43
|
var import_lodash_es = require("lodash-es");
|
|
44
44
|
var import_utils2 = require("../../modules/Schedule/utils");
|
|
45
45
|
var import_utils3 = require("../../modules/Date/utils");
|
|
46
|
+
var import_utils4 = require("../../modules/Product/utils");
|
|
47
|
+
var import_timeslots = require("./utils/timeslots");
|
|
46
48
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
47
49
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
48
50
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -339,12 +341,30 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
339
341
|
}
|
|
340
342
|
async storeProduct(productData) {
|
|
341
343
|
const activeAccount = this.getActiveAccount();
|
|
342
|
-
const { bundle, options, origin, product_variant_id } = productData || {};
|
|
343
|
-
const
|
|
344
|
+
const { bundle, options, origin, product_variant_id, quantity = 1, rowKey } = productData || {};
|
|
345
|
+
const cartItems = this.store.cart.getItems();
|
|
346
|
+
if (rowKey) {
|
|
347
|
+
const targetCartItem = cartItems.find((n) => {
|
|
348
|
+
var _a;
|
|
349
|
+
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
350
|
+
});
|
|
351
|
+
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
352
|
+
this.store.cart.updateItem({
|
|
353
|
+
_id: targetCartItem._id,
|
|
354
|
+
product: {
|
|
355
|
+
...targetCartItem._productOrigin
|
|
356
|
+
},
|
|
357
|
+
quantity: (targetCartItem.num || 1) + quantity
|
|
358
|
+
});
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const product = { ...origin, product_variant_id, rowKey };
|
|
344
363
|
const addCartItem = {
|
|
345
364
|
product,
|
|
346
365
|
bundle,
|
|
347
|
-
options
|
|
366
|
+
options,
|
|
367
|
+
quantity
|
|
348
368
|
};
|
|
349
369
|
if (activeAccount) {
|
|
350
370
|
addCartItem.account = activeAccount;
|
|
@@ -413,12 +433,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
413
433
|
* @param params
|
|
414
434
|
*/
|
|
415
435
|
async fetchHolderAccountsAsync(params) {
|
|
416
|
-
var _a, _b
|
|
436
|
+
var _a, _b;
|
|
417
437
|
const cartItems = this.store.cart.getItems();
|
|
418
438
|
if (cartItems.length) {
|
|
419
439
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
420
440
|
if (!date) {
|
|
421
|
-
|
|
441
|
+
const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
442
|
+
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
422
443
|
}
|
|
423
444
|
this.updateQuotationPriceAndCart(date);
|
|
424
445
|
}
|
|
@@ -505,7 +526,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
505
526
|
}
|
|
506
527
|
// 如果用户登录
|
|
507
528
|
async setLoginAccount(accountId, accountInfo) {
|
|
508
|
-
var _a, _b
|
|
529
|
+
var _a, _b;
|
|
509
530
|
const account = this.store.accountList.getAccount(accountId);
|
|
510
531
|
if (account) {
|
|
511
532
|
let stateAccountId = account.getId();
|
|
@@ -524,7 +545,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
524
545
|
if (cartItems.length) {
|
|
525
546
|
let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
|
|
526
547
|
if (!date) {
|
|
527
|
-
|
|
548
|
+
const normalProductCartItem = cartItems.find((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
549
|
+
date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
|
|
528
550
|
}
|
|
529
551
|
this.updateQuotationPriceAndCart(date);
|
|
530
552
|
}
|
|
@@ -577,7 +599,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
577
599
|
item._origin.number = currentCapacity;
|
|
578
600
|
}
|
|
579
601
|
});
|
|
580
|
-
|
|
602
|
+
let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
|
|
603
|
+
if ((0, import_utils4.areAllNormalProducts)(newCartItems.map((n) => n._productOrigin))) {
|
|
604
|
+
type = "virtual";
|
|
605
|
+
}
|
|
581
606
|
return this.store.order.submitOrder({ query: { cartItems: newCartItems, type } });
|
|
582
607
|
}
|
|
583
608
|
// 拉起支付模块
|
|
@@ -642,7 +667,11 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
642
667
|
var _a2;
|
|
643
668
|
if (item._id !== targetCartItem._id) {
|
|
644
669
|
const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
|
|
645
|
-
|
|
670
|
+
const sameFormIdResources = targetCartItem._origin.resources.filter((n) => n.form_id === m.form_id);
|
|
671
|
+
if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
return !sameFormIdResources.some((targetRes) => {
|
|
646
675
|
var _a3, _b, _c;
|
|
647
676
|
if (targetRes.resourceType !== "single") {
|
|
648
677
|
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
@@ -655,10 +684,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
655
684
|
const originResource = allOriginResources.find(
|
|
656
685
|
(n) => n.id === targetRes.id
|
|
657
686
|
);
|
|
658
|
-
if (currentResourcesCapacityMap[
|
|
687
|
+
if (currentResourcesCapacityMap[m.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
|
|
659
688
|
return true;
|
|
660
689
|
}
|
|
661
|
-
currentResourcesCapacityMap[
|
|
690
|
+
currentResourcesCapacityMap[m.id] += currentCapacity;
|
|
662
691
|
return false;
|
|
663
692
|
}
|
|
664
693
|
if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
|
|
@@ -789,7 +818,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
789
818
|
});
|
|
790
819
|
}
|
|
791
820
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
792
|
-
const cartItems = this.store.cart.getItems();
|
|
821
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
793
822
|
const arr = [];
|
|
794
823
|
cartItems.forEach((cartItem) => {
|
|
795
824
|
var _a, _b, _c;
|
|
@@ -918,7 +947,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
918
947
|
});
|
|
919
948
|
}
|
|
920
949
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
921
|
-
const cartItems = this.store.cart.getItems();
|
|
950
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
922
951
|
const arr = [];
|
|
923
952
|
cartItems.forEach((cartItem) => {
|
|
924
953
|
var _a, _b, _c;
|
|
@@ -1032,7 +1061,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1032
1061
|
// 给单个购物车里的商品获取资源列表
|
|
1033
1062
|
getResourcesListByCartItem(id) {
|
|
1034
1063
|
var _a, _b, _c;
|
|
1035
|
-
const cartItems =
|
|
1064
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1036
1065
|
const dateRange = this.store.date.getDateRange();
|
|
1037
1066
|
const resources = [];
|
|
1038
1067
|
dateRange.forEach((n) => {
|
|
@@ -1115,6 +1144,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1115
1144
|
capacity
|
|
1116
1145
|
}) {
|
|
1117
1146
|
var _a, _b, _c;
|
|
1147
|
+
if ((0, import_utils4.isNormalProduct)(cartItem._productOrigin)) {
|
|
1148
|
+
return {};
|
|
1149
|
+
}
|
|
1118
1150
|
const dateRange = this.store.date.getDateRange();
|
|
1119
1151
|
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1120
1152
|
let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
|
|
@@ -1172,6 +1204,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1172
1204
|
}, {});
|
|
1173
1205
|
if (timeSlots) {
|
|
1174
1206
|
let targetResource = null;
|
|
1207
|
+
let targetResourceTime = 0;
|
|
1175
1208
|
for (const n of resources) {
|
|
1176
1209
|
const mTimes = n.times.filter((n2) => {
|
|
1177
1210
|
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
|
|
@@ -1201,8 +1234,14 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1201
1234
|
}
|
|
1202
1235
|
return res.usable;
|
|
1203
1236
|
});
|
|
1204
|
-
|
|
1237
|
+
const currentResourceIdleTime = (0, import_timeslots.calculateResourceAvailableTime)({
|
|
1238
|
+
resource: n,
|
|
1239
|
+
timeSlots,
|
|
1240
|
+
currentCapacity: totalCapacity + (capacity || 0)
|
|
1241
|
+
});
|
|
1242
|
+
if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
|
|
1205
1243
|
targetResource = n;
|
|
1244
|
+
targetResourceTime = currentResourceIdleTime;
|
|
1206
1245
|
break;
|
|
1207
1246
|
}
|
|
1208
1247
|
}
|
|
@@ -1384,7 +1423,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1384
1423
|
)) {
|
|
1385
1424
|
return;
|
|
1386
1425
|
}
|
|
1387
|
-
const
|
|
1426
|
+
const fastestResource = (0, import_timeslots.findFastestAvailableResource)({
|
|
1427
|
+
resources: targetRenderList,
|
|
1428
|
+
currentCapacity,
|
|
1429
|
+
countMap: selectResourcesMap
|
|
1430
|
+
});
|
|
1431
|
+
const targetResource = fastestResource || targetRenderList[0];
|
|
1388
1432
|
targetResource.capacity = currentCapacity;
|
|
1389
1433
|
(0, import_resources.checkSubResourcesCapacity)(targetResource);
|
|
1390
1434
|
if (!selectResourcesMap[targetResource.id]) {
|
|
@@ -1407,7 +1451,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1407
1451
|
}
|
|
1408
1452
|
});
|
|
1409
1453
|
};
|
|
1410
|
-
const cartItems =
|
|
1454
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1411
1455
|
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1412
1456
|
accountList.forEach((account) => {
|
|
1413
1457
|
const cartItems2 = this.store.cart.getCartByAccount(account.getId());
|
|
@@ -1423,7 +1467,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1423
1467
|
var _a, _b, _c, _d, _e, _f;
|
|
1424
1468
|
let dateRange = this.store.date.getDateRange();
|
|
1425
1469
|
const resources = [];
|
|
1426
|
-
const cartItems =
|
|
1470
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1427
1471
|
const resourceIds = [];
|
|
1428
1472
|
let resourcesTypeId = void 0;
|
|
1429
1473
|
let isSingleResource = false;
|
|
@@ -1521,7 +1565,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1521
1565
|
}
|
|
1522
1566
|
// 提交时间切片,绑定到对应购物车的商品上,更新购物车
|
|
1523
1567
|
submitTimeSlot(timeSlots) {
|
|
1524
|
-
const cartItems =
|
|
1568
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1525
1569
|
const itemsByAccount = cartItems.reduce(
|
|
1526
1570
|
(acc, item) => {
|
|
1527
1571
|
const holderId = item.holder_id;
|
|
@@ -1710,7 +1754,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1710
1754
|
date,
|
|
1711
1755
|
account
|
|
1712
1756
|
}) {
|
|
1713
|
-
const { bundle, options, origin, product_variant_id } = product || {};
|
|
1757
|
+
const { bundle, options, origin, product_variant_id, rowKey, quantity = 1 } = product || {};
|
|
1714
1758
|
const productData = { ...origin, product_variant_id };
|
|
1715
1759
|
if (!account) {
|
|
1716
1760
|
const activeAccount = this.getActiveAccount();
|
|
@@ -1718,15 +1762,33 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1718
1762
|
account = activeAccount;
|
|
1719
1763
|
}
|
|
1720
1764
|
}
|
|
1765
|
+
if (rowKey) {
|
|
1766
|
+
const cartItems = this.store.cart.getItems();
|
|
1767
|
+
const targetCartItem = cartItems.find((n) => {
|
|
1768
|
+
var _a;
|
|
1769
|
+
return ((_a = n._productOrigin) == null ? void 0 : _a.rowKey) === rowKey;
|
|
1770
|
+
});
|
|
1771
|
+
if (targetCartItem && (0, import_utils4.isNormalProduct)(targetCartItem._productOrigin)) {
|
|
1772
|
+
this.store.cart.updateItem({
|
|
1773
|
+
_id: targetCartItem._id,
|
|
1774
|
+
product: {
|
|
1775
|
+
...targetCartItem._productOrigin,
|
|
1776
|
+
quantity: (targetCartItem.num || 1) + quantity
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1721
1782
|
this.store.cart.addItem({
|
|
1722
1783
|
product: productData,
|
|
1723
1784
|
date,
|
|
1724
1785
|
account,
|
|
1725
1786
|
bundle,
|
|
1726
|
-
options
|
|
1787
|
+
options,
|
|
1788
|
+
quantity
|
|
1727
1789
|
});
|
|
1728
1790
|
if (date) {
|
|
1729
|
-
const cartItems =
|
|
1791
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1730
1792
|
const cartItemsByDate = cartItems.filter(
|
|
1731
1793
|
(n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
|
|
1732
1794
|
);
|
|
@@ -1782,7 +1844,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1782
1844
|
});
|
|
1783
1845
|
}
|
|
1784
1846
|
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
1785
|
-
const cartItems = this.store.cart.getItems();
|
|
1847
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
1786
1848
|
const cartItem = cartItems.find((item) => item._id === cartItemId);
|
|
1787
1849
|
if (!cartItem)
|
|
1788
1850
|
return [];
|
|
@@ -1884,6 +1946,88 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1884
1946
|
}
|
|
1885
1947
|
return targetResource.renderList;
|
|
1886
1948
|
}
|
|
1949
|
+
/**
|
|
1950
|
+
* 根据日期范围批量获取时间槽
|
|
1951
|
+
* @param params 参数对象
|
|
1952
|
+
* @returns Promise<Record<string, TimeSliceItem[]>> 返回日期到时间槽的映射
|
|
1953
|
+
*/
|
|
1954
|
+
async getTimeslotsScheduleByDateRange({
|
|
1955
|
+
startDate,
|
|
1956
|
+
endDate,
|
|
1957
|
+
scheduleIds,
|
|
1958
|
+
resources
|
|
1959
|
+
}) {
|
|
1960
|
+
console.log(
|
|
1961
|
+
"appoimentBooking-session-date-getTimeslotsScheduleByDateRange",
|
|
1962
|
+
{ startDate, endDate, scheduleIds, resources }
|
|
1963
|
+
);
|
|
1964
|
+
const dates = [];
|
|
1965
|
+
let currentDate = (0, import_dayjs.default)(startDate);
|
|
1966
|
+
const end = (0, import_dayjs.default)(endDate);
|
|
1967
|
+
while (currentDate.isSameOrBefore(end)) {
|
|
1968
|
+
dates.push(currentDate.format("YYYY-MM-DD"));
|
|
1969
|
+
currentDate = currentDate.add(1, "day");
|
|
1970
|
+
}
|
|
1971
|
+
const results = {};
|
|
1972
|
+
for (const date of dates) {
|
|
1973
|
+
results[date] = this.getTimeslotBySchedule({
|
|
1974
|
+
date,
|
|
1975
|
+
scheduleIds,
|
|
1976
|
+
resources
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
return results;
|
|
1980
|
+
}
|
|
1981
|
+
async getAvailableDateForSession(params = {}) {
|
|
1982
|
+
let { startDate, endDate, type } = params;
|
|
1983
|
+
if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
|
|
1984
|
+
startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
|
|
1985
|
+
}
|
|
1986
|
+
endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
|
|
1987
|
+
let tempProducts = [];
|
|
1988
|
+
if (this.store.currentProduct) {
|
|
1989
|
+
tempProducts = [
|
|
1990
|
+
{
|
|
1991
|
+
...this.store.currentProduct.getData(),
|
|
1992
|
+
_schedule: this.store.currentProduct.getOtherParams()["schedule"]
|
|
1993
|
+
}
|
|
1994
|
+
];
|
|
1995
|
+
}
|
|
1996
|
+
const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
|
|
1997
|
+
this.otherParams.currentResourcesMap = resourcesMap;
|
|
1998
|
+
const res = await this.store.date.getResourceDates({
|
|
1999
|
+
query: {
|
|
2000
|
+
start_date: startDate || "",
|
|
2001
|
+
end_date: endDate || "",
|
|
2002
|
+
resource_ids: resourceIds
|
|
2003
|
+
},
|
|
2004
|
+
rules,
|
|
2005
|
+
type
|
|
2006
|
+
});
|
|
2007
|
+
if (this.store.currentProduct) {
|
|
2008
|
+
const dateListWithTimeSlots = await this.getTimeslotsScheduleByDateRange({
|
|
2009
|
+
startDate: startDate || "",
|
|
2010
|
+
endDate: endDate || ""
|
|
2011
|
+
});
|
|
2012
|
+
res.forEach((n) => {
|
|
2013
|
+
if (!dateListWithTimeSlots[n.date]) {
|
|
2014
|
+
n.status = "unavailable";
|
|
2015
|
+
} else {
|
|
2016
|
+
const allTimeSlotsCanUse = dateListWithTimeSlots[n.date].every(
|
|
2017
|
+
(d) => d.count
|
|
2018
|
+
);
|
|
2019
|
+
if (!allTimeSlotsCanUse) {
|
|
2020
|
+
n.status = "unavailable";
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
const firstAvailableDate = res.find((n) => n.status === "available");
|
|
2026
|
+
return {
|
|
2027
|
+
dateList: res,
|
|
2028
|
+
firstAvailableDate
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
1887
2031
|
async getAvailableDateForSessionOptimize(params = {}) {
|
|
1888
2032
|
var _a, _b, _c, _d, _e, _f;
|
|
1889
2033
|
const cache = (_a = this.store.currentProduct) == null ? void 0 : _a.getOtherParams()["timeSlotBySchedule"];
|
|
@@ -2020,6 +2164,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
2020
2164
|
firstAvailableDate
|
|
2021
2165
|
};
|
|
2022
2166
|
}
|
|
2167
|
+
isCartAllNormalProducts() {
|
|
2168
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
2169
|
+
return !cartItems.length;
|
|
2170
|
+
}
|
|
2171
|
+
isCartHasDurationProduct() {
|
|
2172
|
+
const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils4.isNormalProduct)(n._productOrigin));
|
|
2173
|
+
return cartItems.some((n) => {
|
|
2174
|
+
var _a;
|
|
2175
|
+
return (_a = n._productOrigin) == null ? void 0 : _a.duration;
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
isTargetNormalProduct(product) {
|
|
2179
|
+
return (0, import_utils4.isNormalProduct)(product);
|
|
2180
|
+
}
|
|
2023
2181
|
};
|
|
2024
2182
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2025
2183
|
0 && (module.exports = {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ResourceItem, TimeSliceItem } from "./resources";
|
|
2
|
+
/**
|
|
3
|
+
* 计算资源在指定时间段内的总可用时间(以分钟为单位)
|
|
4
|
+
* @param resource 需要计算可用时间的资源
|
|
5
|
+
* @param timeSlots 要检查可用性的时间段
|
|
6
|
+
* @param currentCapacity 当前预约所需的容量
|
|
7
|
+
* @returns 总可用时间(分钟)
|
|
8
|
+
*/
|
|
9
|
+
export declare function calculateResourceAvailableTime({ resource, timeSlots, currentCapacity, }: {
|
|
10
|
+
resource: ResourceItem;
|
|
11
|
+
timeSlots: TimeSliceItem;
|
|
12
|
+
currentCapacity?: number;
|
|
13
|
+
}): number;
|
|
14
|
+
/**
|
|
15
|
+
* 查找最快可用的资源,如果有多个资源在相同时间点可用,则选择空闲时间最长的资源
|
|
16
|
+
* @param resources 资源列表
|
|
17
|
+
* @param currentCapacity 当前预约所需的容量
|
|
18
|
+
* @param countMap 已预约数量映射
|
|
19
|
+
* @returns 最快可用的资源
|
|
20
|
+
*/
|
|
21
|
+
export declare function findFastestAvailableResource({ resources, currentCapacity, countMap, }: {
|
|
22
|
+
resources: ResourceItem[];
|
|
23
|
+
currentCapacity?: number;
|
|
24
|
+
countMap?: Record<number, number>;
|
|
25
|
+
}): ResourceItem | null;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/solution/BookingByStep/utils/timeslots.ts
|
|
30
|
+
var timeslots_exports = {};
|
|
31
|
+
__export(timeslots_exports, {
|
|
32
|
+
calculateResourceAvailableTime: () => calculateResourceAvailableTime,
|
|
33
|
+
findFastestAvailableResource: () => findFastestAvailableResource
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(timeslots_exports);
|
|
36
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
37
|
+
function calculateResourceAvailableTime({
|
|
38
|
+
resource,
|
|
39
|
+
timeSlots,
|
|
40
|
+
currentCapacity = 1
|
|
41
|
+
}) {
|
|
42
|
+
const matchingTimes = resource.times.filter((time) => {
|
|
43
|
+
return (0, import_dayjs.default)(time.start_at).isSame((0, import_dayjs.default)(timeSlots.start_at), "day");
|
|
44
|
+
});
|
|
45
|
+
if (matchingTimes.length === 0)
|
|
46
|
+
return 0;
|
|
47
|
+
const overlaps = [];
|
|
48
|
+
for (const time of matchingTimes) {
|
|
49
|
+
const overlapStart = (0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) ? (0, import_dayjs.default)(time.start_at) : (0, import_dayjs.default)(timeSlots.start_at);
|
|
50
|
+
const overlapEnd = (0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at)) ? (0, import_dayjs.default)(time.end_at) : (0, import_dayjs.default)(timeSlots.end_at);
|
|
51
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
52
|
+
overlaps.push({ start: overlapStart, end: overlapEnd });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (overlaps.length === 0)
|
|
56
|
+
return 0;
|
|
57
|
+
overlaps.sort((a, b) => a.start.diff(b.start));
|
|
58
|
+
const merged = [];
|
|
59
|
+
let current = overlaps[0];
|
|
60
|
+
for (let i = 1; i < overlaps.length; i++) {
|
|
61
|
+
const next = overlaps[i];
|
|
62
|
+
if (current.end.isSameOrAfter(next.start)) {
|
|
63
|
+
current.end = current.end.isAfter(next.end) ? current.end : next.end;
|
|
64
|
+
} else {
|
|
65
|
+
merged.push(current);
|
|
66
|
+
current = next;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
merged.push(current);
|
|
70
|
+
let totalAvailableMinutes = 0;
|
|
71
|
+
for (const segment of merged) {
|
|
72
|
+
totalAvailableMinutes += segment.end.diff(segment.start, "minute");
|
|
73
|
+
}
|
|
74
|
+
return totalAvailableMinutes;
|
|
75
|
+
}
|
|
76
|
+
function findFastestAvailableResource({
|
|
77
|
+
resources,
|
|
78
|
+
currentCapacity = 1,
|
|
79
|
+
countMap = {}
|
|
80
|
+
}) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const currentTime = (0, import_dayjs.default)();
|
|
83
|
+
let fastestTime = null;
|
|
84
|
+
let fastestResources = [];
|
|
85
|
+
for (const resource of resources) {
|
|
86
|
+
const todayTimes = resource.times.filter((time) => {
|
|
87
|
+
return (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
|
|
88
|
+
});
|
|
89
|
+
if (todayTimes.length === 0)
|
|
90
|
+
continue;
|
|
91
|
+
todayTimes.sort((a, b) => {
|
|
92
|
+
return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at));
|
|
93
|
+
});
|
|
94
|
+
for (const time of todayTimes) {
|
|
95
|
+
const startTime = (0, import_dayjs.default)(time.start_at);
|
|
96
|
+
if (startTime.isBefore(currentTime))
|
|
97
|
+
continue;
|
|
98
|
+
if (resource.resourceType === "single") {
|
|
99
|
+
const hasBooking = (_a = time.event_list) == null ? void 0 : _a.some((event) => {
|
|
100
|
+
return (0, import_dayjs.default)(event.start_at).isSame(startTime);
|
|
101
|
+
});
|
|
102
|
+
if (!hasBooking) {
|
|
103
|
+
if (!fastestTime || startTime.isSame(fastestTime)) {
|
|
104
|
+
fastestTime = startTime;
|
|
105
|
+
fastestResources.push(resource);
|
|
106
|
+
} else if (startTime.isBefore(fastestTime)) {
|
|
107
|
+
fastestTime = startTime;
|
|
108
|
+
fastestResources = [resource];
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
const totalCapacity = resource.capacity || 0;
|
|
114
|
+
const usedCapacity = ((_b = time.event_list) == null ? void 0 : _b.reduce((sum, event) => {
|
|
115
|
+
return (0, import_dayjs.default)(event.start_at).isSame(startTime) ? sum + (event.pax || 0) : sum;
|
|
116
|
+
}, 0)) || 0;
|
|
117
|
+
const remainingCapacity = totalCapacity - usedCapacity;
|
|
118
|
+
if (remainingCapacity >= (countMap[resource.id] || 0) + currentCapacity) {
|
|
119
|
+
if (!fastestTime || startTime.isSame(fastestTime)) {
|
|
120
|
+
fastestTime = startTime;
|
|
121
|
+
fastestResources.push(resource);
|
|
122
|
+
} else if (startTime.isBefore(fastestTime)) {
|
|
123
|
+
fastestTime = startTime;
|
|
124
|
+
fastestResources = [resource];
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!fastestTime || fastestResources.length === 0)
|
|
132
|
+
return null;
|
|
133
|
+
if (fastestResources.length === 1)
|
|
134
|
+
return fastestResources[0];
|
|
135
|
+
let maxIdleTime = 0;
|
|
136
|
+
let selectedResource = null;
|
|
137
|
+
for (const resource of fastestResources) {
|
|
138
|
+
const idleTime = calculateResourceAvailableTime({
|
|
139
|
+
resource,
|
|
140
|
+
timeSlots: {
|
|
141
|
+
start_time: fastestTime.format("HH:mm"),
|
|
142
|
+
end_time: fastestTime.format("HH:mm"),
|
|
143
|
+
start_at: fastestTime,
|
|
144
|
+
end_at: fastestTime
|
|
145
|
+
},
|
|
146
|
+
currentCapacity: (countMap[resource.id] || 0) + currentCapacity
|
|
147
|
+
});
|
|
148
|
+
if (idleTime > maxIdleTime) {
|
|
149
|
+
maxIdleTime = idleTime;
|
|
150
|
+
selectedResource = resource;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return selectedResource;
|
|
154
|
+
}
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
calculateResourceAvailableTime,
|
|
158
|
+
findFastestAvailableResource
|
|
159
|
+
});
|