@pisell/pisellos 0.0.100 → 0.0.102
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/Rules/index.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +9 -0
- package/dist/solution/BookingByStep/index.js +108 -0
- package/lib/modules/Rules/index.js +2 -2
- package/lib/solution/BookingByStep/index.d.ts +9 -0
- package/lib/solution/BookingByStep/index.js +124 -0
- package/package.json +1 -1
|
@@ -107,7 +107,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// 合并新旧折扣列表,并计算折扣结果
|
|
110
|
-
var mergedDiscountList = uniqueById([].concat(_toConsumableArray(oldDiscountList), _toConsumableArray(newDiscountList)));
|
|
110
|
+
var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(oldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
|
|
111
111
|
var result = this.calcDiscount({
|
|
112
112
|
discountList: mergedDiscountList,
|
|
113
113
|
productList: _toConsumableArray(productList)
|
|
@@ -209,4 +209,13 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
209
209
|
setOtherData(key: string, value: any): void;
|
|
210
210
|
getOtherData(key: string): any;
|
|
211
211
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
212
|
+
/**
|
|
213
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
214
|
+
*
|
|
215
|
+
* @param {string} cartItemId
|
|
216
|
+
* @param {string} resourceCode
|
|
217
|
+
* @return {*}
|
|
218
|
+
* @memberof BookingByStepImpl
|
|
219
|
+
*/
|
|
220
|
+
getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
|
|
212
221
|
}
|
|
@@ -2476,6 +2476,114 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2476
2476
|
}
|
|
2477
2477
|
return getProductTypeById;
|
|
2478
2478
|
}()
|
|
2479
|
+
/**
|
|
2480
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
2481
|
+
*
|
|
2482
|
+
* @param {string} cartItemId
|
|
2483
|
+
* @param {string} resourceCode
|
|
2484
|
+
* @return {*}
|
|
2485
|
+
* @memberof BookingByStepImpl
|
|
2486
|
+
*/
|
|
2487
|
+
}, {
|
|
2488
|
+
key: "getResourcesByCartItemAndCode",
|
|
2489
|
+
value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
2490
|
+
var _cartItem$_productOri11, _cartItem$_productOri12;
|
|
2491
|
+
var dateRange = this.store.date.getDateRange();
|
|
2492
|
+
var resources = [];
|
|
2493
|
+
if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
|
|
2494
|
+
dateRange.forEach(function (n) {
|
|
2495
|
+
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
if (!resources.length) {
|
|
2499
|
+
var dateList = this.store.date.getDateList();
|
|
2500
|
+
dateList.forEach(function (n) {
|
|
2501
|
+
if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
|
|
2502
|
+
});
|
|
2503
|
+
}
|
|
2504
|
+
var resourcesMap = getResourcesMap(cloneDeep(resources));
|
|
2505
|
+
var cartItems = this.store.cart.getItems();
|
|
2506
|
+
var cartItem = cartItems.find(function (item) {
|
|
2507
|
+
return item._id === cartItemId;
|
|
2508
|
+
});
|
|
2509
|
+
if (!cartItem) return [];
|
|
2510
|
+
var selectedResources = [];
|
|
2511
|
+
var formatCapacity = formatDefaultCapacitys({
|
|
2512
|
+
capacity: (_cartItem$_productOri11 = cartItem._productOrigin) === null || _cartItem$_productOri11 === void 0 ? void 0 : _cartItem$_productOri11.capacity,
|
|
2513
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
2514
|
+
});
|
|
2515
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
2516
|
+
var currentCapacity = getSumCapacity({
|
|
2517
|
+
capacity: formatCapacity
|
|
2518
|
+
});
|
|
2519
|
+
if (cartItem.holder_id) {
|
|
2520
|
+
selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
|
|
2521
|
+
} else {
|
|
2522
|
+
selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
|
|
2523
|
+
}
|
|
2524
|
+
var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri12 = cartItem._productOrigin) === null || _cartItem$_productOri12 === void 0 || (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) === null || _cartItem$_productOri12 === void 0 ? void 0 : _cartItem$_productOri12.resources) || [], selectedResources, currentCapacity);
|
|
2525
|
+
var targetResource = productResources.find(function (resource) {
|
|
2526
|
+
return resource.code === resourceCode;
|
|
2527
|
+
});
|
|
2528
|
+
if (!targetResource) return [];
|
|
2529
|
+
if (cartItem._origin.start_time) {
|
|
2530
|
+
var startTime = dayjs("".concat(cartItem._origin.start_date, " ").concat(cartItem._origin.start_time));
|
|
2531
|
+
var endTime = dayjs("".concat(cartItem._origin.end_date, " ").concat(cartItem._origin.end_time));
|
|
2532
|
+
var resourcesUseableMap = {};
|
|
2533
|
+
targetResource.renderList = targetResource.renderList.sort(function (a, b) {
|
|
2534
|
+
var _a$metadata5, _b$metadata5;
|
|
2535
|
+
var aIsCombined = ((_a$metadata5 = a.metadata) === null || _a$metadata5 === void 0 || (_a$metadata5 = _a$metadata5.combined_resource) === null || _a$metadata5 === void 0 ? void 0 : _a$metadata5.status) === 1;
|
|
2536
|
+
var bIsCombined = ((_b$metadata5 = b.metadata) === null || _b$metadata5 === void 0 || (_b$metadata5 = _b$metadata5.combined_resource) === null || _b$metadata5 === void 0 ? void 0 : _b$metadata5.status) === 1;
|
|
2537
|
+
if (aIsCombined && !bIsCombined) return 1;
|
|
2538
|
+
if (!aIsCombined && bIsCombined) return -1;
|
|
2539
|
+
return 0;
|
|
2540
|
+
});
|
|
2541
|
+
targetResource.renderList = targetResource.renderList.filter(function (m) {
|
|
2542
|
+
var mTimes = m.times.filter(function (n) {
|
|
2543
|
+
return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
|
|
2544
|
+
});
|
|
2545
|
+
if (mTimes.length === 0) return false;
|
|
2546
|
+
var canUseArr = mTimes.map(function (item) {
|
|
2547
|
+
var _cartItem$_productOri13;
|
|
2548
|
+
var res = getIsUsableByTimeItem({
|
|
2549
|
+
timeSlice: {
|
|
2550
|
+
start_time: startTime.format('HH:mm'),
|
|
2551
|
+
end_time: endTime.format('HH:mm'),
|
|
2552
|
+
start_at: startTime,
|
|
2553
|
+
end_at: endTime
|
|
2554
|
+
},
|
|
2555
|
+
time: item,
|
|
2556
|
+
resource: m,
|
|
2557
|
+
currentCount: currentCapacity || 0,
|
|
2558
|
+
resourcesUseableMap: resourcesUseableMap,
|
|
2559
|
+
cut_off_time: (_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.cut_off_time
|
|
2560
|
+
});
|
|
2561
|
+
if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
|
|
2562
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
2563
|
+
}
|
|
2564
|
+
return res.usable;
|
|
2565
|
+
});
|
|
2566
|
+
if (m.onlyComputed) return false;
|
|
2567
|
+
return !canUseArr.some(function (n) {
|
|
2568
|
+
return n === false;
|
|
2569
|
+
});
|
|
2570
|
+
});
|
|
2571
|
+
} else {
|
|
2572
|
+
targetResource.renderList = targetResource.renderList.filter(function (n) {
|
|
2573
|
+
var _cartItem$_productOri14;
|
|
2574
|
+
var recordCount = n.capacity || 0;
|
|
2575
|
+
if (n.onlyComputed) return false;
|
|
2576
|
+
var timeSlots = getTimeSlicesByResource({
|
|
2577
|
+
resource: n,
|
|
2578
|
+
duration: ((_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 || (_cartItem$_productOri14 = _cartItem$_productOri14.duration) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.value) || 0,
|
|
2579
|
+
split: 10,
|
|
2580
|
+
currentDate: dateRange[0].date
|
|
2581
|
+
});
|
|
2582
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
2583
|
+
});
|
|
2584
|
+
}
|
|
2585
|
+
return targetResource.renderList;
|
|
2586
|
+
}
|
|
2479
2587
|
}]);
|
|
2480
2588
|
return BookingByStepImpl;
|
|
2481
2589
|
}(BaseModule);
|
|
@@ -58,10 +58,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
58
58
|
productList
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const mergedDiscountList = (0, import_utils.uniqueById)([
|
|
61
|
+
const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
|
|
62
62
|
...oldDiscountList,
|
|
63
63
|
...newDiscountList
|
|
64
|
-
]);
|
|
64
|
+
]), "product_id");
|
|
65
65
|
const result = this.calcDiscount({
|
|
66
66
|
discountList: mergedDiscountList,
|
|
67
67
|
productList: [...productList]
|
|
@@ -209,4 +209,13 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
209
209
|
setOtherData(key: string, value: any): void;
|
|
210
210
|
getOtherData(key: string): any;
|
|
211
211
|
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
212
|
+
/**
|
|
213
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
214
|
+
*
|
|
215
|
+
* @param {string} cartItemId
|
|
216
|
+
* @param {string} resourceCode
|
|
217
|
+
* @return {*}
|
|
218
|
+
* @memberof BookingByStepImpl
|
|
219
|
+
*/
|
|
220
|
+
getResourcesByCartItemAndCode(cartItemId: string, resourceCode: string): any;
|
|
212
221
|
}
|
|
@@ -1692,6 +1692,130 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1692
1692
|
}
|
|
1693
1693
|
return "normal";
|
|
1694
1694
|
}
|
|
1695
|
+
/**
|
|
1696
|
+
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
1697
|
+
*
|
|
1698
|
+
* @param {string} cartItemId
|
|
1699
|
+
* @param {string} resourceCode
|
|
1700
|
+
* @return {*}
|
|
1701
|
+
* @memberof BookingByStepImpl
|
|
1702
|
+
*/
|
|
1703
|
+
getResourcesByCartItemAndCode(cartItemId, resourceCode) {
|
|
1704
|
+
var _a, _b, _c;
|
|
1705
|
+
const dateRange = this.store.date.getDateRange();
|
|
1706
|
+
const resources = [];
|
|
1707
|
+
if (dateRange == null ? void 0 : dateRange.length) {
|
|
1708
|
+
dateRange.forEach((n) => {
|
|
1709
|
+
if (n.resource)
|
|
1710
|
+
resources.push(...n.resource);
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
if (!resources.length) {
|
|
1714
|
+
const dateList = this.store.date.getDateList();
|
|
1715
|
+
dateList.forEach((n) => {
|
|
1716
|
+
if (n.resource)
|
|
1717
|
+
resources.push(...n.resource);
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
|
|
1721
|
+
const cartItems = this.store.cart.getItems();
|
|
1722
|
+
const cartItem = cartItems.find((item) => item._id === cartItemId);
|
|
1723
|
+
if (!cartItem)
|
|
1724
|
+
return [];
|
|
1725
|
+
let selectedResources = [];
|
|
1726
|
+
const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
|
|
1727
|
+
capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
1728
|
+
product_bundle: cartItem._origin.product.product_bundle
|
|
1729
|
+
});
|
|
1730
|
+
cartItem._origin.metadata.capacity = formatCapacity;
|
|
1731
|
+
const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
|
|
1732
|
+
if (cartItem.holder_id) {
|
|
1733
|
+
selectedResources = (0, import_resources.getOthersSelectedResources)(
|
|
1734
|
+
cartItems,
|
|
1735
|
+
cartItem.holder_id,
|
|
1736
|
+
resourcesMap
|
|
1737
|
+
);
|
|
1738
|
+
} else {
|
|
1739
|
+
selectedResources = (0, import_resources.getOthersCartSelectedResources)(
|
|
1740
|
+
cartItems,
|
|
1741
|
+
cartItem._id,
|
|
1742
|
+
resourcesMap
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
const productResources = (0, import_resources.getResourcesByProduct)(
|
|
1746
|
+
resourcesMap,
|
|
1747
|
+
((_c = (_b = cartItem._productOrigin) == null ? void 0 : _b.product_resource) == null ? void 0 : _c.resources) || [],
|
|
1748
|
+
selectedResources,
|
|
1749
|
+
currentCapacity
|
|
1750
|
+
);
|
|
1751
|
+
const targetResource = productResources.find((resource) => resource.code === resourceCode);
|
|
1752
|
+
if (!targetResource)
|
|
1753
|
+
return [];
|
|
1754
|
+
if (cartItem._origin.start_time) {
|
|
1755
|
+
const startTime = (0, import_dayjs.default)(
|
|
1756
|
+
`${cartItem._origin.start_date} ${cartItem._origin.start_time}`
|
|
1757
|
+
);
|
|
1758
|
+
const endTime = (0, import_dayjs.default)(
|
|
1759
|
+
`${cartItem._origin.end_date} ${cartItem._origin.end_time}`
|
|
1760
|
+
);
|
|
1761
|
+
const resourcesUseableMap = {};
|
|
1762
|
+
targetResource.renderList = targetResource.renderList.sort((a, b) => {
|
|
1763
|
+
var _a2, _b2, _c2, _d;
|
|
1764
|
+
const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
|
|
1765
|
+
const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
|
|
1766
|
+
if (aIsCombined && !bIsCombined)
|
|
1767
|
+
return 1;
|
|
1768
|
+
if (!aIsCombined && bIsCombined)
|
|
1769
|
+
return -1;
|
|
1770
|
+
return 0;
|
|
1771
|
+
});
|
|
1772
|
+
targetResource.renderList = targetResource.renderList.filter((m) => {
|
|
1773
|
+
const mTimes = m.times.filter((n) => {
|
|
1774
|
+
return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
|
|
1775
|
+
});
|
|
1776
|
+
if (mTimes.length === 0)
|
|
1777
|
+
return false;
|
|
1778
|
+
const canUseArr = mTimes.map((item) => {
|
|
1779
|
+
var _a2;
|
|
1780
|
+
const res = (0, import_resources.getIsUsableByTimeItem)({
|
|
1781
|
+
timeSlice: {
|
|
1782
|
+
start_time: startTime.format("HH:mm"),
|
|
1783
|
+
end_time: endTime.format("HH:mm"),
|
|
1784
|
+
start_at: startTime,
|
|
1785
|
+
end_at: endTime
|
|
1786
|
+
},
|
|
1787
|
+
time: item,
|
|
1788
|
+
resource: m,
|
|
1789
|
+
currentCount: currentCapacity || 0,
|
|
1790
|
+
resourcesUseableMap,
|
|
1791
|
+
cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
|
|
1792
|
+
});
|
|
1793
|
+
if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
|
|
1794
|
+
resourcesUseableMap[m.id] = res.usable;
|
|
1795
|
+
}
|
|
1796
|
+
return res.usable;
|
|
1797
|
+
});
|
|
1798
|
+
if (m.onlyComputed)
|
|
1799
|
+
return false;
|
|
1800
|
+
return !canUseArr.some((n) => n === false);
|
|
1801
|
+
});
|
|
1802
|
+
} else {
|
|
1803
|
+
targetResource.renderList = targetResource.renderList.filter((n) => {
|
|
1804
|
+
var _a2, _b2;
|
|
1805
|
+
const recordCount = n.capacity || 0;
|
|
1806
|
+
if (n.onlyComputed)
|
|
1807
|
+
return false;
|
|
1808
|
+
const timeSlots = (0, import_resources.getTimeSlicesByResource)({
|
|
1809
|
+
resource: n,
|
|
1810
|
+
duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 0,
|
|
1811
|
+
split: 10,
|
|
1812
|
+
currentDate: dateRange[0].date
|
|
1813
|
+
});
|
|
1814
|
+
return recordCount >= currentCapacity && timeSlots.length > 0;
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
return targetResource.renderList;
|
|
1818
|
+
}
|
|
1695
1819
|
};
|
|
1696
1820
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1697
1821
|
0 && (module.exports = {
|