@pisell/pisellos 3.0.64 → 3.0.66
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/Date/index.js +4 -0
- package/dist/solution/BookingByStep/index.d.ts +16 -4
- package/dist/solution/BookingByStep/index.js +702 -110
- package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/dist/solution/BookingByStep/utils/capacity.js +230 -1
- package/dist/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/dist/solution/BookingByStep/utils/resources.js +1 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/lib/modules/Date/index.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +16 -4
- package/lib/solution/BookingByStep/index.js +387 -9
- package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/lib/solution/BookingByStep/utils/capacity.js +166 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/lib/solution/BookingByStep/utils/resources.js +2 -0
- package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/lib/solution/BookingByStep/utils/stock.js +89 -0
- package/package.json +1 -1
|
@@ -47,6 +47,7 @@ var import_utils4 = require("../../modules/Product/utils");
|
|
|
47
47
|
var import_timeslots = require("./utils/timeslots");
|
|
48
48
|
var import_changePrice = require("../../modules/Cart/utils/changePrice");
|
|
49
49
|
var import_capacity = require("./utils/capacity");
|
|
50
|
+
var import_stock = require("./utils/stock");
|
|
50
51
|
import_dayjs.default.extend(import_isSameOrBefore.default);
|
|
51
52
|
import_dayjs.default.extend(import_isSameOrAfter.default);
|
|
52
53
|
var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -561,9 +562,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
561
562
|
* @param {ProductData} productData
|
|
562
563
|
* @memberof BookingByStepImpl
|
|
563
564
|
*/
|
|
564
|
-
|
|
565
|
+
storeProduct(productData) {
|
|
565
566
|
const activeAccount = this.getActiveAccount();
|
|
566
|
-
this.addProductToCart({
|
|
567
|
+
return this.addProductToCart({
|
|
567
568
|
product: productData,
|
|
568
569
|
account: activeAccount
|
|
569
570
|
});
|
|
@@ -597,6 +598,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
597
598
|
quantity = 1
|
|
598
599
|
} = product || {};
|
|
599
600
|
const productData = { ...origin, product_variant_id };
|
|
601
|
+
const currentCartItems = this.store.cart.getItems();
|
|
602
|
+
const stockCheckResult = (0, import_stock.checkProductStock)({
|
|
603
|
+
productData,
|
|
604
|
+
product_variant_id,
|
|
605
|
+
quantity,
|
|
606
|
+
bundle,
|
|
607
|
+
currentCartItems
|
|
608
|
+
});
|
|
609
|
+
if (!stockCheckResult.success) {
|
|
610
|
+
return stockCheckResult;
|
|
611
|
+
}
|
|
600
612
|
if (!account) {
|
|
601
613
|
const activeAccount = this.getActiveAccount();
|
|
602
614
|
if (activeAccount) {
|
|
@@ -609,7 +621,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
609
621
|
account: account || void 0
|
|
610
622
|
});
|
|
611
623
|
if (flag) {
|
|
612
|
-
return;
|
|
624
|
+
return { success: true };
|
|
613
625
|
}
|
|
614
626
|
const addItemParams = {
|
|
615
627
|
product: productData,
|
|
@@ -625,6 +637,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
625
637
|
}
|
|
626
638
|
this.addProductCheck({ date });
|
|
627
639
|
this.store.cart.addItem(addItemParams);
|
|
640
|
+
return { success: true };
|
|
628
641
|
}
|
|
629
642
|
/**
|
|
630
643
|
* 添加完购物车以后做的一些检测,比如日期是否在同一天
|
|
@@ -1387,7 +1400,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1387
1400
|
isSingleResource = n.type === "single";
|
|
1388
1401
|
}
|
|
1389
1402
|
});
|
|
1390
|
-
if (item.resource_id) {
|
|
1403
|
+
if (item.resource_id && !resourceIds.includes(item.resource_id)) {
|
|
1391
1404
|
resourceIds.push(item.resource_id);
|
|
1392
1405
|
}
|
|
1393
1406
|
resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
|
|
@@ -1475,6 +1488,23 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1475
1488
|
return 0;
|
|
1476
1489
|
}, 0);
|
|
1477
1490
|
}
|
|
1491
|
+
const calculateCapacityFromCartItems = (items) => {
|
|
1492
|
+
return items.reduce((total, item) => {
|
|
1493
|
+
return total + ((0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 0);
|
|
1494
|
+
}, 0);
|
|
1495
|
+
};
|
|
1496
|
+
let maxCapacity = 1;
|
|
1497
|
+
if (cartItems == null ? void 0 : cartItems[0].holder_id) {
|
|
1498
|
+
accountList.forEach((account) => {
|
|
1499
|
+
const accountCartItems = this.store.cart.getCartByAccount(account.getId());
|
|
1500
|
+
const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
|
|
1501
|
+
if (currentCapacity > maxCapacity) {
|
|
1502
|
+
maxCapacity = currentCapacity;
|
|
1503
|
+
}
|
|
1504
|
+
});
|
|
1505
|
+
} else {
|
|
1506
|
+
maxCapacity = calculateCapacityFromCartItems(cartItems);
|
|
1507
|
+
}
|
|
1478
1508
|
const timeSlots = (0, import_resources.getTimeSlicesByResources)({
|
|
1479
1509
|
resourceIds,
|
|
1480
1510
|
resourcesMap,
|
|
@@ -1482,6 +1512,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1482
1512
|
currentDate: dateRange[0].date,
|
|
1483
1513
|
split: 10,
|
|
1484
1514
|
resourcesUseableMap,
|
|
1515
|
+
capacity: maxCapacity,
|
|
1485
1516
|
cut_off_time: maxCutOffTime,
|
|
1486
1517
|
hasFlexibleDuration,
|
|
1487
1518
|
operating_day_boundary,
|
|
@@ -1567,10 +1598,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1567
1598
|
});
|
|
1568
1599
|
});
|
|
1569
1600
|
}
|
|
1570
|
-
clearCache() {
|
|
1571
|
-
}
|
|
1572
|
-
clearCacheByModule(module2) {
|
|
1573
|
-
}
|
|
1574
1601
|
getScheduleDataByIds(scheduleIds) {
|
|
1575
1602
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
1576
1603
|
const targetSchedulesData = targetSchedules.map((item) => {
|
|
@@ -1625,6 +1652,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1625
1652
|
}
|
|
1626
1653
|
this.store.currentProduct = void 0;
|
|
1627
1654
|
}
|
|
1655
|
+
// 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
|
|
1628
1656
|
getTimeslotBySchedule({
|
|
1629
1657
|
date,
|
|
1630
1658
|
scheduleIds,
|
|
@@ -1724,6 +1752,100 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1724
1752
|
}
|
|
1725
1753
|
}
|
|
1726
1754
|
});
|
|
1755
|
+
const cartItems2 = this.store.cart.getItems();
|
|
1756
|
+
productResources.forEach((n) => {
|
|
1757
|
+
if (n.type === "single") {
|
|
1758
|
+
const currentResourcesSet = /* @__PURE__ */ new Set([...n.optional_resource, ...n.default_resource]);
|
|
1759
|
+
const sameCartItems = cartItems2.filter((m) => {
|
|
1760
|
+
var _a2, _b2, _c2;
|
|
1761
|
+
return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) === ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
|
|
1762
|
+
});
|
|
1763
|
+
if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
|
|
1764
|
+
bookingLeft = 0;
|
|
1765
|
+
count = 0;
|
|
1766
|
+
}
|
|
1767
|
+
const otherCartItems = cartItems2.filter((m) => {
|
|
1768
|
+
var _a2, _b2, _c2;
|
|
1769
|
+
return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) !== ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
|
|
1770
|
+
});
|
|
1771
|
+
otherCartItems.forEach((m) => {
|
|
1772
|
+
var _a2, _b2, _c2;
|
|
1773
|
+
const sameTypeResources = (_c2 = (_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.find((m2) => m2.type === n.type);
|
|
1774
|
+
const sameTypeResourcesSet = /* @__PURE__ */ new Set([...(sameTypeResources == null ? void 0 : sameTypeResources.optional_resource) || [], ...(sameTypeResources == null ? void 0 : sameTypeResources.default_resource) || []]);
|
|
1775
|
+
sameTypeResourcesSet.forEach((resource) => currentResourcesSet.add(resource));
|
|
1776
|
+
});
|
|
1777
|
+
const currentDataResources = this.store.date.getResourcesListByDate((0, import_dayjs.default)(item.start).format("YYYY-MM-DD"));
|
|
1778
|
+
currentDataResources == null ? void 0 : currentDataResources.forEach((m) => {
|
|
1779
|
+
if (currentResourcesSet.has(m.id)) {
|
|
1780
|
+
const mTimes = m.times.filter((n2) => {
|
|
1781
|
+
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
|
|
1782
|
+
});
|
|
1783
|
+
if (!mTimes.length || mTimes.some((n2) => n2.event_list.length)) {
|
|
1784
|
+
currentResourcesSet.delete(m.id);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
});
|
|
1788
|
+
if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
|
|
1789
|
+
bookingLeft = 0;
|
|
1790
|
+
count = 0;
|
|
1791
|
+
}
|
|
1792
|
+
} else {
|
|
1793
|
+
const sameCartItems = cartItems2.filter((m) => {
|
|
1794
|
+
var _a2, _b2, _c2;
|
|
1795
|
+
return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) === ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
|
|
1796
|
+
});
|
|
1797
|
+
const sameCartNeedCapacity = sameCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
|
|
1798
|
+
const currentProductResourcesCapacity = n.renderList.reduce((acc, curr) => !curr.onlyComputed ? acc + curr.capacity || 0 : acc, 0);
|
|
1799
|
+
if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
|
|
1800
|
+
bookingLeft = 0;
|
|
1801
|
+
count = 0;
|
|
1802
|
+
}
|
|
1803
|
+
const otherSameTimesCartItems = cartItems2.filter((m) => `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
|
|
1804
|
+
const otherCartNeedCapacity = otherSameTimesCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
|
|
1805
|
+
const allRenderList = [...n.renderList.filter((m) => !m.onlyComputed)];
|
|
1806
|
+
otherSameTimesCartItems.forEach((m) => {
|
|
1807
|
+
var _a2, _b2;
|
|
1808
|
+
const productResources2 = (0, import_resources.getResourcesByProduct)(
|
|
1809
|
+
(0, import_utils.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
|
|
1810
|
+
((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
|
|
1811
|
+
selectedResources,
|
|
1812
|
+
1
|
|
1813
|
+
);
|
|
1814
|
+
productResources2.forEach((m2) => {
|
|
1815
|
+
if (m2.id === n.id) {
|
|
1816
|
+
m2.renderList.forEach((n2) => {
|
|
1817
|
+
if (!n2.onlyComputed && !allRenderList.find((m3) => m3.id === n2.id)) {
|
|
1818
|
+
allRenderList.push(n2);
|
|
1819
|
+
}
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
});
|
|
1823
|
+
});
|
|
1824
|
+
const currentTypeResourcesCapacity = allRenderList.reduce((acc, curr) => acc + curr.capacity || 0, 0);
|
|
1825
|
+
const usedCapacity = allRenderList.reduce((acc, curr) => {
|
|
1826
|
+
const mTimes = curr.times.filter((n2) => {
|
|
1827
|
+
return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
|
|
1828
|
+
});
|
|
1829
|
+
const mSet = /* @__PURE__ */ new Map();
|
|
1830
|
+
mTimes.forEach((n2) => {
|
|
1831
|
+
n2.event_list.forEach((m) => {
|
|
1832
|
+
if ((0, import_resources.isConflict)(
|
|
1833
|
+
{ start_at: m.start_at, end_at: m.end_at },
|
|
1834
|
+
{ start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
|
|
1835
|
+
)) {
|
|
1836
|
+
mSet.set(m.id, m.pax || 1);
|
|
1837
|
+
}
|
|
1838
|
+
});
|
|
1839
|
+
});
|
|
1840
|
+
acc += Array.from(mSet.values()).reduce((acc2, curr2) => acc2 + curr2, 0);
|
|
1841
|
+
return acc;
|
|
1842
|
+
}, 0);
|
|
1843
|
+
if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
|
|
1844
|
+
bookingLeft = 0;
|
|
1845
|
+
count = 0;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
});
|
|
1727
1849
|
const startDayJs = (0, import_dayjs.default)(item.start);
|
|
1728
1850
|
const endDayJs = (0, import_dayjs.default)(item.end);
|
|
1729
1851
|
return {
|
|
@@ -1737,6 +1859,262 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1737
1859
|
});
|
|
1738
1860
|
return formatScheduleTimeSlots;
|
|
1739
1861
|
}
|
|
1862
|
+
// 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
|
|
1863
|
+
// 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
|
|
1864
|
+
// 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
|
|
1865
|
+
// 注意 资源分为多个种类,需要每个种类单独检测,不能一股脑把所有资源的容量加起来检测
|
|
1866
|
+
/**
|
|
1867
|
+
* 找到多个资源的公共可用时间段
|
|
1868
|
+
*/
|
|
1869
|
+
findCommonAvailableTimeSlots(resources) {
|
|
1870
|
+
if (resources.length === 0)
|
|
1871
|
+
return [];
|
|
1872
|
+
console.log(`计算 ${resources.length} 个资源的公共时间段`);
|
|
1873
|
+
const allTimeSlots = resources.map(
|
|
1874
|
+
(resource) => resource.times.map((time) => ({
|
|
1875
|
+
start: (0, import_dayjs.default)(time.start_at),
|
|
1876
|
+
end: (0, import_dayjs.default)(time.end_at)
|
|
1877
|
+
}))
|
|
1878
|
+
);
|
|
1879
|
+
console.log("所有资源的时间段:", allTimeSlots.map(
|
|
1880
|
+
(slots) => slots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`)
|
|
1881
|
+
));
|
|
1882
|
+
let commonSlots = allTimeSlots[0];
|
|
1883
|
+
console.log("初始公共时间段:", commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
|
|
1884
|
+
for (let i = 1; i < allTimeSlots.length; i++) {
|
|
1885
|
+
const currentResourceSlots = allTimeSlots[i];
|
|
1886
|
+
const intersections = [];
|
|
1887
|
+
commonSlots.forEach((commonSlot) => {
|
|
1888
|
+
currentResourceSlots.forEach((currentSlot) => {
|
|
1889
|
+
const overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
|
|
1890
|
+
const overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
|
|
1891
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
1892
|
+
intersections.push({
|
|
1893
|
+
start: overlapStart,
|
|
1894
|
+
end: overlapEnd
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
});
|
|
1898
|
+
});
|
|
1899
|
+
commonSlots = intersections;
|
|
1900
|
+
console.log(`与资源${i}求交集后的公共时间段:`, commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
|
|
1901
|
+
if (commonSlots.length === 0) {
|
|
1902
|
+
console.log("没有找到公共时间段");
|
|
1903
|
+
return [];
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
const result = commonSlots.map((slot) => ({
|
|
1907
|
+
startTime: slot.start.format("HH:mm"),
|
|
1908
|
+
endTime: slot.end.format("HH:mm")
|
|
1909
|
+
}));
|
|
1910
|
+
console.log("最终公共时间段:", result);
|
|
1911
|
+
return result;
|
|
1912
|
+
}
|
|
1913
|
+
checkMaxDurationCapacity() {
|
|
1914
|
+
var _a, _b;
|
|
1915
|
+
const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
|
|
1916
|
+
if (cartItems.length === 0)
|
|
1917
|
+
return { success: true, minAvailableCount: 0 };
|
|
1918
|
+
const itemsWithTime = [];
|
|
1919
|
+
const itemsWithoutTime = [];
|
|
1920
|
+
const availableCountsByResourceType = [];
|
|
1921
|
+
cartItems.forEach((cartItem) => {
|
|
1922
|
+
if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
|
|
1923
|
+
itemsWithTime.push(cartItem);
|
|
1924
|
+
} else {
|
|
1925
|
+
itemsWithoutTime.push(cartItem);
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
const processedItemsWithoutTime = [];
|
|
1929
|
+
if (itemsWithoutTime.length > 0) {
|
|
1930
|
+
const itemsByResourceType = {};
|
|
1931
|
+
itemsWithoutTime.forEach((cartItem) => {
|
|
1932
|
+
var _a2;
|
|
1933
|
+
if (!cartItem._productOrigin)
|
|
1934
|
+
return;
|
|
1935
|
+
const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
|
|
1936
|
+
resourceTypes.forEach((resourceType) => {
|
|
1937
|
+
var _a3;
|
|
1938
|
+
if (resourceType.status === 1) {
|
|
1939
|
+
const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
|
|
1940
|
+
if (!itemsByResourceType[resourceCode]) {
|
|
1941
|
+
itemsByResourceType[resourceCode] = [];
|
|
1942
|
+
}
|
|
1943
|
+
if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
|
|
1944
|
+
itemsByResourceType[resourceCode].push(cartItem);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1948
|
+
});
|
|
1949
|
+
const dateRange = this.store.date.getDateRange();
|
|
1950
|
+
if (!dateRange || dateRange.length === 0)
|
|
1951
|
+
return { success: false, minAvailableCount: 0 };
|
|
1952
|
+
const resourcesDates = this.store.date.getDateList();
|
|
1953
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
|
|
1954
|
+
if (!targetResourceDate)
|
|
1955
|
+
return { success: false, minAvailableCount: 0 };
|
|
1956
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
|
|
1957
|
+
const resourceCodeToFormIdMap = {};
|
|
1958
|
+
Object.values(itemsByResourceType).flat().forEach((cartItem) => {
|
|
1959
|
+
var _a2, _b2;
|
|
1960
|
+
if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
|
|
1961
|
+
cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
|
|
1962
|
+
var _a3, _b3;
|
|
1963
|
+
if (resourceConfig.status === 1 && resourceConfig.code) {
|
|
1964
|
+
const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
|
|
1965
|
+
if (formId) {
|
|
1966
|
+
resourceCodeToFormIdMap[resourceConfig.code] = formId;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
});
|
|
1970
|
+
}
|
|
1971
|
+
});
|
|
1972
|
+
let hasCapacityIssue = false;
|
|
1973
|
+
const resourceCapacityInfo = [];
|
|
1974
|
+
const processedCartItemIds = /* @__PURE__ */ new Set();
|
|
1975
|
+
for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
|
|
1976
|
+
const targetFormId = resourceCodeToFormIdMap[resourceCode];
|
|
1977
|
+
if (!targetFormId) {
|
|
1978
|
+
console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
|
|
1979
|
+
return { success: false, minAvailableCount: 0 };
|
|
1980
|
+
}
|
|
1981
|
+
const resourcesOfThisType = [];
|
|
1982
|
+
items.forEach((cartItem) => {
|
|
1983
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
1984
|
+
productResourceIds.forEach((resourceId) => {
|
|
1985
|
+
var _a2;
|
|
1986
|
+
const resource = resourcesMap[resourceId];
|
|
1987
|
+
if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
|
|
1988
|
+
if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
|
|
1989
|
+
resourcesOfThisType.push(resource);
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
});
|
|
1993
|
+
});
|
|
1994
|
+
if (resourcesOfThisType.length === 0) {
|
|
1995
|
+
console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
|
|
1996
|
+
return { success: false, minAvailableCount: 0 };
|
|
1997
|
+
}
|
|
1998
|
+
let resourceTypeConfig = null;
|
|
1999
|
+
for (const cartItem of items) {
|
|
2000
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
2001
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
2002
|
+
(r) => r.code === resourceCode && r.status === 1
|
|
2003
|
+
);
|
|
2004
|
+
if (resourceTypeConfig)
|
|
2005
|
+
break;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
2009
|
+
let totalAvailable;
|
|
2010
|
+
let requiredAmount;
|
|
2011
|
+
let availableAmount;
|
|
2012
|
+
if (isMultipleBooking) {
|
|
2013
|
+
totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
|
|
2014
|
+
return sum + (resource.capacity || 0);
|
|
2015
|
+
}, 0);
|
|
2016
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2017
|
+
const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
|
|
2018
|
+
return sum + currentCapacity;
|
|
2019
|
+
}, 0);
|
|
2020
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2021
|
+
} else {
|
|
2022
|
+
totalAvailable = resourcesOfThisType.length;
|
|
2023
|
+
requiredAmount = items.reduce((sum, cartItem) => {
|
|
2024
|
+
return sum + (cartItem.num || 1);
|
|
2025
|
+
}, 0);
|
|
2026
|
+
availableAmount = Math.max(0, totalAvailable - requiredAmount);
|
|
2027
|
+
}
|
|
2028
|
+
resourceCapacityInfo.push({
|
|
2029
|
+
code: resourceCode,
|
|
2030
|
+
available: availableAmount,
|
|
2031
|
+
total: totalAvailable,
|
|
2032
|
+
required: requiredAmount,
|
|
2033
|
+
isMultiple: isMultipleBooking
|
|
2034
|
+
});
|
|
2035
|
+
availableCountsByResourceType.push(availableAmount);
|
|
2036
|
+
if (requiredAmount > totalAvailable) {
|
|
2037
|
+
hasCapacityIssue = true;
|
|
2038
|
+
console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
|
|
2039
|
+
}
|
|
2040
|
+
console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
|
|
2041
|
+
id: r.id,
|
|
2042
|
+
times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
|
|
2043
|
+
})));
|
|
2044
|
+
const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
|
|
2045
|
+
console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
|
|
2046
|
+
if (commonTimeSlots.length === 0) {
|
|
2047
|
+
console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
|
|
2048
|
+
return { success: false, minAvailableCount: 0 };
|
|
2049
|
+
}
|
|
2050
|
+
const firstCommonSlot = commonTimeSlots[0];
|
|
2051
|
+
console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
|
|
2052
|
+
items.forEach((cartItem) => {
|
|
2053
|
+
if (!processedCartItemIds.has(cartItem._id)) {
|
|
2054
|
+
processedCartItemIds.add(cartItem._id);
|
|
2055
|
+
const processedItem = {
|
|
2056
|
+
...cartItem,
|
|
2057
|
+
start_date: dateRange[0].date,
|
|
2058
|
+
start_time: firstCommonSlot.startTime,
|
|
2059
|
+
end_time: firstCommonSlot.endTime,
|
|
2060
|
+
end_date: dateRange[0].date
|
|
2061
|
+
};
|
|
2062
|
+
processedItemsWithoutTime.push(processedItem);
|
|
2063
|
+
}
|
|
2064
|
+
});
|
|
2065
|
+
}
|
|
2066
|
+
if (hasCapacityIssue) {
|
|
2067
|
+
const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
|
|
2068
|
+
if (overCapacityResources.length > 0) {
|
|
2069
|
+
const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
|
|
2070
|
+
return { success: false, minAvailableCount: minTotalCapacity2 };
|
|
2071
|
+
}
|
|
2072
|
+
const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
|
|
2073
|
+
return { success: false, minAvailableCount: minTotalCapacity };
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
|
|
2077
|
+
const cartItemsByTimeSlot = {};
|
|
2078
|
+
allProcessedItems.forEach((cartItem) => {
|
|
2079
|
+
if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
|
|
2080
|
+
return;
|
|
2081
|
+
const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
|
|
2082
|
+
if (!cartItemsByTimeSlot[timeSlotKey]) {
|
|
2083
|
+
cartItemsByTimeSlot[timeSlotKey] = [];
|
|
2084
|
+
}
|
|
2085
|
+
cartItemsByTimeSlot[timeSlotKey].push(cartItem);
|
|
2086
|
+
});
|
|
2087
|
+
for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
|
|
2088
|
+
const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
|
|
2089
|
+
const timeSlotStart = `${startDate} ${startTime}`;
|
|
2090
|
+
const timeSlotEnd = `${endDate} ${endTime}`;
|
|
2091
|
+
const allResourcesForTimeSlot = [];
|
|
2092
|
+
const resourcesIdSet = /* @__PURE__ */ new Set();
|
|
2093
|
+
const dateRange = this.store.date.getDateRange();
|
|
2094
|
+
const resourcesDates = this.store.date.getDateList();
|
|
2095
|
+
const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
|
|
2096
|
+
if (!targetResourceDate)
|
|
2097
|
+
continue;
|
|
2098
|
+
const resourcesMap = (0, import_utils.getResourcesMap)(targetResourceDate.resource || []);
|
|
2099
|
+
itemsInTimeSlot.forEach((cartItem) => {
|
|
2100
|
+
if (!cartItem._productOrigin)
|
|
2101
|
+
return;
|
|
2102
|
+
const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
|
|
2103
|
+
productResourceIds.forEach((resourceId) => {
|
|
2104
|
+
if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
|
|
2105
|
+
resourcesIdSet.add(resourceId);
|
|
2106
|
+
allResourcesForTimeSlot.push(resourcesMap[resourceId]);
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
});
|
|
2110
|
+
if (!(0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
|
|
2111
|
+
const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2112
|
+
return { success: false, minAvailableCount: minAvailableCount2 };
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
|
|
2116
|
+
return { success: true, minAvailableCount };
|
|
2117
|
+
}
|
|
1740
2118
|
setOtherData(key, value) {
|
|
1741
2119
|
this.otherData[key] = value;
|
|
1742
2120
|
this.checkSaveCache({
|
|
@@ -1954,7 +2332,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1954
2332
|
startDate || "",
|
|
1955
2333
|
endDate || ""
|
|
1956
2334
|
);
|
|
1957
|
-
const tempResourceIds = (0,
|
|
2335
|
+
const tempResourceIds = (0, import_capacity.getResourcesIdsByProduct)(tempProducts);
|
|
1958
2336
|
const res = await this.store.date.fetchResourceDates({
|
|
1959
2337
|
query: {
|
|
1960
2338
|
start_date: startDate || "",
|
|
@@ -45,3 +45,26 @@ export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void
|
|
|
45
45
|
* @returns 如果资源可以容纳额外的容量则返回 true
|
|
46
46
|
*/
|
|
47
47
|
export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* 计算按资源类型分组的容量占用情况
|
|
50
|
+
*
|
|
51
|
+
* @param {CartItem[]} cartItems 购物车商品列表
|
|
52
|
+
* @param {string} timeSlotStart 时间段开始时间
|
|
53
|
+
* @param {string} timeSlotEnd 时间段结束时间
|
|
54
|
+
* @param {ResourceItem[]} allProductResources 当前商品的所有资源列表
|
|
55
|
+
* @return {Record<string, number>} 返回每种资源类型(form_id)的容量占用
|
|
56
|
+
*/
|
|
57
|
+
export declare function calculateCartItemsCapacityUsageByResourceType({ cartItems, timeSlotStart, timeSlotEnd, allProductResources }: {
|
|
58
|
+
cartItems: CartItem[];
|
|
59
|
+
timeSlotStart: string;
|
|
60
|
+
timeSlotEnd: string;
|
|
61
|
+
allProductResources: ResourceItem[];
|
|
62
|
+
}): Record<string, number>;
|
|
63
|
+
/**
|
|
64
|
+
* 获取商品的资源ID列表
|
|
65
|
+
*/
|
|
66
|
+
export declare function getResourcesIdsByProduct(product: any): number[];
|
|
67
|
+
/**
|
|
68
|
+
* 检查特定时间段的容量是否足够
|
|
69
|
+
*/
|
|
70
|
+
export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): boolean;
|