@pisell/pisellos 2.3.189 → 2.3.190
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/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingByStep/index.js +8 -5
- package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/dist/solution/BookingByStep/utils/resources.js +117 -76
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingByStep/index.js +8 -2
- package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/lib/solution/BookingByStep/utils/resources.js +25 -15
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// 导出评估器
|
|
2
|
+
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
+
|
|
4
|
+
// 导出适配器
|
|
5
|
+
export { PromotionAdapter } from "./adapter";
|
|
6
|
+
export { default } from "./adapter";
|
|
7
|
+
|
|
8
|
+
// 导出策略配置示例常量
|
|
9
|
+
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "normal" | "session";
|
|
53
53
|
}
|
|
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
328
328
|
date: string;
|
|
329
329
|
status: string;
|
|
330
330
|
week: string;
|
|
331
|
-
weekNum: 0 | 2 | 1 |
|
|
331
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
332
332
|
}[]>;
|
|
333
333
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
334
334
|
private getScheduleDataByIds;
|
|
@@ -375,7 +375,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
375
375
|
};
|
|
376
376
|
setOtherData(key: string, value: any): void;
|
|
377
377
|
getOtherData(key: string): any;
|
|
378
|
-
getProductTypeById(id: number): Promise<"
|
|
378
|
+
getProductTypeById(id: number): Promise<"duration" | "normal" | "session">;
|
|
379
379
|
/**
|
|
380
380
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
381
381
|
*
|
|
@@ -32,7 +32,7 @@ import { BaseModule } from "../../modules/BaseModule";
|
|
|
32
32
|
import { createModule } from "./types";
|
|
33
33
|
import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
|
|
34
34
|
import { getAvailableProductResources, isSessionProduct } from "./utils/products";
|
|
35
|
-
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
|
|
35
|
+
import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getPeakConcurrentPax, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
|
|
36
36
|
import dayjs from 'dayjs';
|
|
37
37
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
38
38
|
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
|
|
@@ -3109,13 +3109,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
3109
3109
|
end_at: dayjs(item.end)
|
|
3110
3110
|
})) {
|
|
3111
3111
|
var _m$pax;
|
|
3112
|
-
mSet.set(m.id, (
|
|
3112
|
+
mSet.set(m.id, _objectSpread(_objectSpread({}, m), {}, {
|
|
3113
|
+
pax: (_m$pax = m.pax) !== null && _m$pax !== void 0 ? _m$pax : 1
|
|
3114
|
+
}));
|
|
3113
3115
|
}
|
|
3114
3116
|
});
|
|
3115
3117
|
});
|
|
3116
|
-
acc += Array.from(mSet.values())
|
|
3117
|
-
|
|
3118
|
-
|
|
3118
|
+
acc += getPeakConcurrentPax(Array.from(mSet.values()), {
|
|
3119
|
+
start_at: dayjs(item.start),
|
|
3120
|
+
end_at: dayjs(item.end)
|
|
3121
|
+
});
|
|
3119
3122
|
return acc;
|
|
3120
3123
|
}, 0);
|
|
3121
3124
|
// 如果已使用容量超过了当前类型资源的容量,则不可用
|
|
@@ -7,6 +7,11 @@ import { CartItem, ProductData } from '../../../modules';
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
type DateType = Dayjs;
|
|
10
|
+
interface EventItem {
|
|
11
|
+
pax: number;
|
|
12
|
+
start_at: DateType;
|
|
13
|
+
end_at: DateType;
|
|
14
|
+
}
|
|
10
15
|
export interface TimeSliceItem {
|
|
11
16
|
start_time: string;
|
|
12
17
|
end_time: string;
|
|
@@ -20,6 +25,11 @@ export interface ResourceItem {
|
|
|
20
25
|
interface BookingItem {
|
|
21
26
|
[key: string]: any;
|
|
22
27
|
}
|
|
28
|
+
/** 计算目标区间内的最大同时占用人数;事件去重由调用方负责。 */
|
|
29
|
+
export declare const getPeakConcurrentPax: (eventList: EventItem[], timeSlice: {
|
|
30
|
+
start_at: DateType;
|
|
31
|
+
end_at: DateType;
|
|
32
|
+
}) => number;
|
|
23
33
|
/**
|
|
24
34
|
* @title: 判断两个时间段是否有重叠
|
|
25
35
|
* @description:
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
9
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
4
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
12
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
15
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
18
|
import dayjs from 'dayjs';
|
|
15
19
|
|
|
16
20
|
/**
|
|
@@ -20,18 +24,53 @@ import dayjs from 'dayjs';
|
|
|
20
24
|
*
|
|
21
25
|
*/
|
|
22
26
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
/** 计算目标区间内的最大同时占用人数;事件去重由调用方负责。 */
|
|
28
|
+
export var getPeakConcurrentPax = function getPeakConcurrentPax(eventList, timeSlice) {
|
|
29
|
+
var start = dayjs(timeSlice.start_at).valueOf();
|
|
30
|
+
var end = dayjs(timeSlice.end_at).valueOf();
|
|
31
|
+
var changes = new Map();
|
|
32
|
+
var _iterator = _createForOfIteratorHelper(eventList || []),
|
|
33
|
+
_step;
|
|
34
|
+
try {
|
|
35
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
36
|
+
var _changes$get, _changes$get2;
|
|
37
|
+
var event = _step.value;
|
|
38
|
+
var eventStart = Math.max(start, dayjs(event.start_at).valueOf());
|
|
39
|
+
var eventEnd = Math.min(end, dayjs(event.end_at).valueOf());
|
|
40
|
+
if (!(eventStart < eventEnd)) continue;
|
|
41
|
+
var pax = Number(event.pax);
|
|
42
|
+
changes.set(eventStart, ((_changes$get = changes.get(eventStart)) !== null && _changes$get !== void 0 ? _changes$get : 0) + pax);
|
|
43
|
+
changes.set(eventEnd, ((_changes$get2 = changes.get(eventEnd)) !== null && _changes$get2 !== void 0 ? _changes$get2 : 0) - pax);
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_iterator.e(err);
|
|
47
|
+
} finally {
|
|
48
|
+
_iterator.f();
|
|
49
|
+
}
|
|
50
|
+
var current = 0;
|
|
51
|
+
var peak = 0;
|
|
52
|
+
// 同一时刻合并增减量,保持 [start, end) 语义,首尾相接不叠加。
|
|
53
|
+
var _iterator2 = _createForOfIteratorHelper(_toConsumableArray(changes).sort(function (_ref, _ref2) {
|
|
54
|
+
var _ref3 = _slicedToArray(_ref, 1),
|
|
55
|
+
a = _ref3[0];
|
|
56
|
+
var _ref4 = _slicedToArray(_ref2, 1),
|
|
57
|
+
b = _ref4[0];
|
|
58
|
+
return a - b;
|
|
59
|
+
})),
|
|
60
|
+
_step2;
|
|
61
|
+
try {
|
|
62
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
63
|
+
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
64
|
+
change = _step2$value[1];
|
|
65
|
+
current += change;
|
|
66
|
+
peak = Math.max(peak, current);
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
_iterator2.e(err);
|
|
70
|
+
} finally {
|
|
71
|
+
_iterator2.f();
|
|
72
|
+
}
|
|
73
|
+
return peak;
|
|
35
74
|
};
|
|
36
75
|
|
|
37
76
|
/**
|
|
@@ -104,12 +143,12 @@ var formatResource = function formatResource(resourceItem, booking) {
|
|
|
104
143
|
* @return {*}
|
|
105
144
|
* @Author: zhiwei.Wang
|
|
106
145
|
*/
|
|
107
|
-
var checkCapacity = function checkCapacity(
|
|
108
|
-
var event_list =
|
|
109
|
-
timeSlice =
|
|
110
|
-
resource =
|
|
111
|
-
|
|
112
|
-
currentCount =
|
|
146
|
+
var checkCapacity = function checkCapacity(_ref5) {
|
|
147
|
+
var event_list = _ref5.event_list,
|
|
148
|
+
timeSlice = _ref5.timeSlice,
|
|
149
|
+
resource = _ref5.resource,
|
|
150
|
+
_ref5$currentCount = _ref5.currentCount,
|
|
151
|
+
currentCount = _ref5$currentCount === void 0 ? 1 : _ref5$currentCount;
|
|
113
152
|
// 单个预约:如果当前资源容量不足以满足需求的容量,且当前资源是没有被占用的,返回资源不可用标记,但在外部运算会通过 reason=capacityOnly 来处理组合资源可用
|
|
114
153
|
// 多个预约:只需判断容量是否足够
|
|
115
154
|
var isMultipleBooking = resource.resourceType === 'multiple';
|
|
@@ -130,8 +169,10 @@ var checkCapacity = function checkCapacity(_ref) {
|
|
|
130
169
|
});
|
|
131
170
|
});
|
|
132
171
|
|
|
133
|
-
//
|
|
134
|
-
var conflictCount =
|
|
172
|
+
// 多人预约按同时占用峰值扣减,不能把先后到访的所有人数相加。
|
|
173
|
+
var conflictCount = resource.resourceType === 'single' ? conflict.reduce(function (remaining, event) {
|
|
174
|
+
return remaining - event.pax;
|
|
175
|
+
}, resource.capacity || 0) : (resource.capacity || 0) - getPeakConcurrentPax(conflict, timeSlice);
|
|
135
176
|
|
|
136
177
|
// 同一时间段内只能进行一个预约,无论容量是否已满。
|
|
137
178
|
if (resource.resourceType === 'single') {
|
|
@@ -170,16 +211,16 @@ var checkCapacity = function checkCapacity(_ref) {
|
|
|
170
211
|
* @return {*}
|
|
171
212
|
* @Author: zhiwei.Wang
|
|
172
213
|
*/
|
|
173
|
-
export var getIsUsableByTimeItem = function getIsUsableByTimeItem(
|
|
214
|
+
export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref6) {
|
|
174
215
|
var _resource$combined_re;
|
|
175
|
-
var timeSlice =
|
|
176
|
-
time =
|
|
177
|
-
resource =
|
|
178
|
-
|
|
179
|
-
currentCount =
|
|
180
|
-
|
|
181
|
-
resourcesUseableMap =
|
|
182
|
-
cut_off_time =
|
|
216
|
+
var timeSlice = _ref6.timeSlice,
|
|
217
|
+
time = _ref6.time,
|
|
218
|
+
resource = _ref6.resource,
|
|
219
|
+
_ref6$currentCount = _ref6.currentCount,
|
|
220
|
+
currentCount = _ref6$currentCount === void 0 ? 1 : _ref6$currentCount,
|
|
221
|
+
_ref6$resourcesUseabl = _ref6.resourcesUseableMap,
|
|
222
|
+
resourcesUseableMap = _ref6$resourcesUseabl === void 0 ? {} : _ref6$resourcesUseabl,
|
|
223
|
+
cut_off_time = _ref6.cut_off_time;
|
|
183
224
|
var status = {
|
|
184
225
|
afterToDay: false,
|
|
185
226
|
capacity: false,
|
|
@@ -191,11 +232,11 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
|
|
|
191
232
|
// 最早可预约时间为 当前日期之后并且提前量之后
|
|
192
233
|
var earliest = dayjs();
|
|
193
234
|
var canBookingForOngoing = false;
|
|
194
|
-
var
|
|
195
|
-
unit =
|
|
196
|
-
unit_type =
|
|
197
|
-
type =
|
|
198
|
-
ongoing =
|
|
235
|
+
var _ref7 = cut_off_time || {},
|
|
236
|
+
unit = _ref7.unit,
|
|
237
|
+
unit_type = _ref7.unit_type,
|
|
238
|
+
type = _ref7.type,
|
|
239
|
+
ongoing = _ref7.ongoing;
|
|
199
240
|
// 允许购买已开始的活动
|
|
200
241
|
if (type === 'ongoing' && (ongoing === null || ongoing === void 0 ? void 0 : ongoing.type) === 'after_start') {
|
|
201
242
|
// 如果timeSlice.start_at 小于当前时间,判断当前时间是否在如果timeSlice.start_at+ongoing.unit之间
|
|
@@ -366,17 +407,17 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
|
|
|
366
407
|
* @Author: zhiwei.Wang
|
|
367
408
|
* @Date: 2024-01-09 13:38
|
|
368
409
|
*/
|
|
369
|
-
export var formatResources = function formatResources(
|
|
370
|
-
var booking =
|
|
371
|
-
resources =
|
|
410
|
+
export var formatResources = function formatResources(_ref8) {
|
|
411
|
+
var booking = _ref8.booking,
|
|
412
|
+
resources = _ref8.resources;
|
|
372
413
|
try {
|
|
373
414
|
var _list = _toConsumableArray(resources);
|
|
374
415
|
var maps = {};
|
|
375
|
-
var
|
|
376
|
-
|
|
416
|
+
var _iterator3 = _createForOfIteratorHelper(_list),
|
|
417
|
+
_step3;
|
|
377
418
|
try {
|
|
378
419
|
var _loop = function _loop() {
|
|
379
|
-
var item =
|
|
420
|
+
var item = _step3.value;
|
|
380
421
|
var renderListMaps = {};
|
|
381
422
|
item.renderList = item.renderList.map(function (d) {
|
|
382
423
|
var res = formatResource(d, booking);
|
|
@@ -387,13 +428,13 @@ export var formatResources = function formatResources(_ref4) {
|
|
|
387
428
|
renderListMaps: renderListMaps
|
|
388
429
|
});
|
|
389
430
|
};
|
|
390
|
-
for (
|
|
431
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
391
432
|
_loop();
|
|
392
433
|
}
|
|
393
434
|
} catch (err) {
|
|
394
|
-
|
|
435
|
+
_iterator3.e(err);
|
|
395
436
|
} finally {
|
|
396
|
-
|
|
437
|
+
_iterator3.f();
|
|
397
438
|
}
|
|
398
439
|
return {
|
|
399
440
|
list: _list,
|
|
@@ -412,20 +453,20 @@ export var formatResources = function formatResources(_ref4) {
|
|
|
412
453
|
* @return {*}
|
|
413
454
|
* @Author: zhiwei.Wang
|
|
414
455
|
*/
|
|
415
|
-
export var getTimeSlicesByResource = function getTimeSlicesByResource(
|
|
416
|
-
var resource =
|
|
417
|
-
duration =
|
|
418
|
-
|
|
419
|
-
split =
|
|
420
|
-
|
|
421
|
-
currentDate =
|
|
422
|
-
capacity =
|
|
423
|
-
|
|
424
|
-
resourcesUseableMap =
|
|
425
|
-
cut_off_time =
|
|
426
|
-
hasFlexibleDuration =
|
|
427
|
-
operating_day_boundary =
|
|
428
|
-
maxBlockThreshold =
|
|
456
|
+
export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref9) {
|
|
457
|
+
var resource = _ref9.resource,
|
|
458
|
+
duration = _ref9.duration,
|
|
459
|
+
_ref9$split = _ref9.split,
|
|
460
|
+
split = _ref9$split === void 0 ? 10 : _ref9$split,
|
|
461
|
+
_ref9$currentDate = _ref9.currentDate,
|
|
462
|
+
currentDate = _ref9$currentDate === void 0 ? dayjs() : _ref9$currentDate,
|
|
463
|
+
capacity = _ref9.capacity,
|
|
464
|
+
_ref9$resourcesUseabl = _ref9.resourcesUseableMap,
|
|
465
|
+
resourcesUseableMap = _ref9$resourcesUseabl === void 0 ? {} : _ref9$resourcesUseabl,
|
|
466
|
+
cut_off_time = _ref9.cut_off_time,
|
|
467
|
+
hasFlexibleDuration = _ref9.hasFlexibleDuration,
|
|
468
|
+
operating_day_boundary = _ref9.operating_day_boundary,
|
|
469
|
+
maxBlockThreshold = _ref9.maxBlockThreshold;
|
|
429
470
|
var times = resource.times;
|
|
430
471
|
|
|
431
472
|
// 存储所有时间切片
|
|
@@ -587,18 +628,18 @@ export var mergeSubResourcesTimeSlices = function mergeSubResourcesTimeSlices(re
|
|
|
587
628
|
* @return {*}
|
|
588
629
|
* @Author: zhiwei.Wang
|
|
589
630
|
*/
|
|
590
|
-
export var getTimeSlicesByResources = function getTimeSlicesByResources(
|
|
591
|
-
var resourceIds =
|
|
592
|
-
resourcesMap =
|
|
593
|
-
duration =
|
|
594
|
-
currentDate =
|
|
595
|
-
split =
|
|
596
|
-
capacity =
|
|
597
|
-
resourcesUseableMap =
|
|
598
|
-
cut_off_time =
|
|
599
|
-
hasFlexibleDuration =
|
|
600
|
-
operating_day_boundary =
|
|
601
|
-
maxBlockThreshold =
|
|
631
|
+
export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref10) {
|
|
632
|
+
var resourceIds = _ref10.resourceIds,
|
|
633
|
+
resourcesMap = _ref10.resourcesMap,
|
|
634
|
+
duration = _ref10.duration,
|
|
635
|
+
currentDate = _ref10.currentDate,
|
|
636
|
+
split = _ref10.split,
|
|
637
|
+
capacity = _ref10.capacity,
|
|
638
|
+
resourcesUseableMap = _ref10.resourcesUseableMap,
|
|
639
|
+
cut_off_time = _ref10.cut_off_time,
|
|
640
|
+
hasFlexibleDuration = _ref10.hasFlexibleDuration,
|
|
641
|
+
operating_day_boundary = _ref10.operating_day_boundary,
|
|
642
|
+
maxBlockThreshold = _ref10.maxBlockThreshold;
|
|
602
643
|
// 获取资源列表
|
|
603
644
|
var resources = getResourcesByIds(resourcesMap, resourceIds);
|
|
604
645
|
mergeSubResourcesTimeSlices(resources, resourcesMap);
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "duration" | "normal" | "session";
|
|
53
53
|
}
|
|
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
328
328
|
date: string;
|
|
329
329
|
status: string;
|
|
330
330
|
week: string;
|
|
331
|
-
weekNum: 0 | 2 | 1 |
|
|
331
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
332
332
|
}[]>;
|
|
333
333
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
334
334
|
private getScheduleDataByIds;
|
|
@@ -375,7 +375,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
375
375
|
};
|
|
376
376
|
setOtherData(key: string, value: any): void;
|
|
377
377
|
getOtherData(key: string): any;
|
|
378
|
-
getProductTypeById(id: number): Promise<"
|
|
378
|
+
getProductTypeById(id: number): Promise<"duration" | "normal" | "session">;
|
|
379
379
|
/**
|
|
380
380
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
381
381
|
*
|
|
@@ -2222,11 +2222,17 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
|
|
|
2222
2222
|
start_at: (0, _dayjs.default)(item.start),
|
|
2223
2223
|
end_at: (0, _dayjs.default)(item.end)
|
|
2224
2224
|
})) {
|
|
2225
|
-
mSet.set(m.id,
|
|
2225
|
+
mSet.set(m.id, {
|
|
2226
|
+
...m,
|
|
2227
|
+
pax: m.pax ?? 1
|
|
2228
|
+
});
|
|
2226
2229
|
}
|
|
2227
2230
|
});
|
|
2228
2231
|
});
|
|
2229
|
-
acc += Array.from(mSet.values())
|
|
2232
|
+
acc += (0, _resources.getPeakConcurrentPax)(Array.from(mSet.values()), {
|
|
2233
|
+
start_at: (0, _dayjs.default)(item.start),
|
|
2234
|
+
end_at: (0, _dayjs.default)(item.end)
|
|
2235
|
+
});
|
|
2230
2236
|
return acc;
|
|
2231
2237
|
}, 0);
|
|
2232
2238
|
// 如果已使用容量超过了当前类型资源的容量,则不可用
|
|
@@ -7,6 +7,11 @@ import { CartItem, ProductData } from '../../../modules';
|
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
9
|
type DateType = Dayjs;
|
|
10
|
+
interface EventItem {
|
|
11
|
+
pax: number;
|
|
12
|
+
start_at: DateType;
|
|
13
|
+
end_at: DateType;
|
|
14
|
+
}
|
|
10
15
|
export interface TimeSliceItem {
|
|
11
16
|
start_time: string;
|
|
12
17
|
end_time: string;
|
|
@@ -20,6 +25,11 @@ export interface ResourceItem {
|
|
|
20
25
|
interface BookingItem {
|
|
21
26
|
[key: string]: any;
|
|
22
27
|
}
|
|
28
|
+
/** 计算目标区间内的最大同时占用人数;事件去重由调用方负责。 */
|
|
29
|
+
export declare const getPeakConcurrentPax: (eventList: EventItem[], timeSlice: {
|
|
30
|
+
start_at: DateType;
|
|
31
|
+
end_at: DateType;
|
|
32
|
+
}) => number;
|
|
23
33
|
/**
|
|
24
34
|
* @title: 判断两个时间段是否有重叠
|
|
25
35
|
* @description:
|
|
@@ -7,7 +7,7 @@ exports.checkSessionProductLeadTime = checkSessionProductLeadTime;
|
|
|
7
7
|
exports.checkTwoResourcesIntersection = checkTwoResourcesIntersection;
|
|
8
8
|
exports.filterResourcesByFormItem = filterResourcesByFormItem;
|
|
9
9
|
exports.filterScheduleByDateRange = filterScheduleByDateRange;
|
|
10
|
-
exports.getResourcesByProduct = exports.getResourcesByIds = exports.getOthersSelectedResources = exports.getOthersCartSelectedResources = exports.getIsUsableByTimeItem = exports.formatResources = void 0;
|
|
10
|
+
exports.getResourcesByProduct = exports.getResourcesByIds = exports.getPeakConcurrentPax = exports.getOthersSelectedResources = exports.getOthersCartSelectedResources = exports.getIsUsableByTimeItem = exports.formatResources = void 0;
|
|
11
11
|
exports.getResourcesIdsByProduct = getResourcesIdsByProduct;
|
|
12
12
|
exports.mergeSubResourcesTimeSlices = exports.isConflict = exports.getTimesIntersection = exports.getTimeSlicesByResources = exports.getTimeSlicesByResource = void 0;
|
|
13
13
|
exports.sortCombinedResources = sortCombinedResources;
|
|
@@ -20,18 +20,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
/** 计算目标区间内的最大同时占用人数;事件去重由调用方负责。 */
|
|
24
|
+
const getPeakConcurrentPax = (eventList, timeSlice) => {
|
|
25
|
+
const start = (0, _dayjs.default)(timeSlice.start_at).valueOf();
|
|
26
|
+
const end = (0, _dayjs.default)(timeSlice.end_at).valueOf();
|
|
27
|
+
const changes = new Map();
|
|
28
|
+
for (const event of eventList || []) {
|
|
29
|
+
const eventStart = Math.max(start, (0, _dayjs.default)(event.start_at).valueOf());
|
|
30
|
+
const eventEnd = Math.min(end, (0, _dayjs.default)(event.end_at).valueOf());
|
|
31
|
+
if (!(eventStart < eventEnd)) continue;
|
|
32
|
+
const pax = Number(event.pax);
|
|
33
|
+
changes.set(eventStart, (changes.get(eventStart) ?? 0) + pax);
|
|
34
|
+
changes.set(eventEnd, (changes.get(eventEnd) ?? 0) - pax);
|
|
35
|
+
}
|
|
36
|
+
let current = 0;
|
|
37
|
+
let peak = 0;
|
|
38
|
+
// 同一时刻合并增减量,保持 [start, end) 语义,首尾相接不叠加。
|
|
39
|
+
for (const [, change] of [...changes].sort(([a], [b]) => a - b)) {
|
|
40
|
+
current += change;
|
|
41
|
+
peak = Math.max(peak, current);
|
|
42
|
+
}
|
|
43
|
+
return peak;
|
|
35
44
|
};
|
|
36
45
|
|
|
37
46
|
/**
|
|
@@ -42,6 +51,7 @@ const getUseableEventCount = (eventList, current) => {
|
|
|
42
51
|
* @return {*}
|
|
43
52
|
* @Author: zhiwei.Wang
|
|
44
53
|
*/
|
|
54
|
+
exports.getPeakConcurrentPax = getPeakConcurrentPax;
|
|
45
55
|
const isConflict = (event, current) => {
|
|
46
56
|
const eventStart = (0, _dayjs.default)(event.start_at);
|
|
47
57
|
const eventEnd = (0, _dayjs.default)(event.end_at);
|
|
@@ -132,8 +142,8 @@ const checkCapacity = ({
|
|
|
132
142
|
});
|
|
133
143
|
});
|
|
134
144
|
|
|
135
|
-
//
|
|
136
|
-
|
|
145
|
+
// 多人预约按同时占用峰值扣减,不能把先后到访的所有人数相加。
|
|
146
|
+
const conflictCount = resource.resourceType === 'single' ? conflict.reduce((remaining, event) => remaining - event.pax, resource.capacity || 0) : (resource.capacity || 0) - getPeakConcurrentPax(conflict, timeSlice);
|
|
137
147
|
|
|
138
148
|
// 同一时间段内只能进行一个预约,无论容量是否已满。
|
|
139
149
|
if (resource.resourceType === 'single') {
|