@pisell/pisellos 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +36 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -1
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +100 -0
- package/dist/modules/Date/index.js +57 -6
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +15 -7
- package/dist/modules/Discount/types.d.ts +10 -0
- package/dist/modules/ProductList/index.d.ts +7 -0
- package/dist/modules/ProductList/index.js +102 -39
- package/dist/modules/Rules/index.js +59 -24
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +121 -1
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/solution/BookingByStep/index.d.ts +120 -30
- package/dist/solution/BookingByStep/index.js +749 -1083
- package/dist/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/dist/solution/BookingByStep/utils/capacity.js +132 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/dist/solution/BookingByStep/utils/resources.js +39 -94
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +15 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +63 -24
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +32 -0
- package/lib/modules/Cart/utils/cartProduct.js +1 -1
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +64 -0
- package/lib/modules/Date/index.js +62 -10
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +18 -6
- package/lib/modules/Discount/types.d.ts +10 -0
- package/lib/modules/ProductList/index.d.ts +7 -0
- package/lib/modules/ProductList/index.js +45 -0
- package/lib/modules/Rules/index.js +59 -22
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +78 -0
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/solution/BookingByStep/index.d.ts +120 -30
- package/lib/solution/BookingByStep/index.js +379 -581
- package/lib/solution/BookingByStep/utils/capacity.d.ts +47 -0
- package/lib/solution/BookingByStep/utils/capacity.js +106 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +29 -31
- package/lib/solution/BookingByStep/utils/resources.js +23 -59
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +7 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +68 -18
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CartItem } from "../../../modules";
|
|
2
|
+
import { CapacityItem, ResourceItem } from "./resources";
|
|
3
|
+
/**
|
|
4
|
+
* @title: 基于选择的商品格式化容量
|
|
5
|
+
* @description:
|
|
6
|
+
* @param {any} param1
|
|
7
|
+
* @return {*}
|
|
8
|
+
* @Author: zhiwei.Wang
|
|
9
|
+
*/
|
|
10
|
+
export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
|
|
11
|
+
/**
|
|
12
|
+
* @title: 获取总容量
|
|
13
|
+
* @description:
|
|
14
|
+
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
15
|
+
* @return {*}
|
|
16
|
+
* @Author: zhiwei.Wang
|
|
17
|
+
*/
|
|
18
|
+
export declare const getSumCapacity: ({ capacity }: {
|
|
19
|
+
capacity: CapacityItem[];
|
|
20
|
+
}) => number;
|
|
21
|
+
/**
|
|
22
|
+
* 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
|
|
23
|
+
*
|
|
24
|
+
* @export
|
|
25
|
+
* @param {CartItem} targetCartItem
|
|
26
|
+
* @return {*}
|
|
27
|
+
*/
|
|
28
|
+
export declare function getCapacityInfoByCartItem(targetCartItem: CartItem): {
|
|
29
|
+
formatCapacity: CapacityItem[];
|
|
30
|
+
currentCapacity: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
34
|
+
* @description:
|
|
35
|
+
* @param {object} resource
|
|
36
|
+
* @return {*}
|
|
37
|
+
* @Author: jinglin.tan
|
|
38
|
+
*/
|
|
39
|
+
export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
|
|
40
|
+
/**
|
|
41
|
+
* 检查资源是否有足够的容量供额外使用
|
|
42
|
+
* @param currentCapacity - 当前已使用的容量
|
|
43
|
+
* @param requiredCapacity - 需要的额外容量
|
|
44
|
+
* @param maxCapacity - 最大允许容量
|
|
45
|
+
* @returns 如果资源可以容纳额外的容量则返回 true
|
|
46
|
+
*/
|
|
47
|
+
export declare const checkResourceCanUseByCapacity: (currentCapacity: number, requiredCapacity: number, maxCapacity: number) => boolean;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
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; } } }; }
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
/**
|
|
5
|
+
* @title: 基于选择的商品格式化容量
|
|
6
|
+
* @description:
|
|
7
|
+
* @param {any} param1
|
|
8
|
+
* @return {*}
|
|
9
|
+
* @Author: zhiwei.Wang
|
|
10
|
+
*/
|
|
11
|
+
export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref) {
|
|
12
|
+
var capacity = _ref.capacity,
|
|
13
|
+
product_bundle = _ref.product_bundle;
|
|
14
|
+
if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
|
|
15
|
+
return (product_bundle || []).map(function (d) {
|
|
16
|
+
var id = d.bundle_product_id;
|
|
17
|
+
var item = ((capacity === null || capacity === void 0 ? void 0 : capacity.package) || []).find(function (item) {
|
|
18
|
+
return item.product_id === id;
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
id: id,
|
|
22
|
+
value: item ? d.num || 0 : 0,
|
|
23
|
+
name: (item === null || item === void 0 ? void 0 : item.name) || (d === null || d === void 0 ? void 0 : d.title)
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'custom') {
|
|
28
|
+
return ((capacity === null || capacity === void 0 ? void 0 : capacity.custom) || []).map(function (d) {
|
|
29
|
+
return {
|
|
30
|
+
id: d.id,
|
|
31
|
+
value: d.min,
|
|
32
|
+
name: d.name
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 默认为1
|
|
38
|
+
return [{
|
|
39
|
+
id: 0,
|
|
40
|
+
value: 1,
|
|
41
|
+
name: ''
|
|
42
|
+
}];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @title: 获取总容量
|
|
47
|
+
* @description:
|
|
48
|
+
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
49
|
+
* @return {*}
|
|
50
|
+
* @Author: zhiwei.Wang
|
|
51
|
+
*/
|
|
52
|
+
export var getSumCapacity = function getSumCapacity(_ref2) {
|
|
53
|
+
var capacity = _ref2.capacity;
|
|
54
|
+
var sum = 0;
|
|
55
|
+
var _iterator = _createForOfIteratorHelper(capacity || []),
|
|
56
|
+
_step;
|
|
57
|
+
try {
|
|
58
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
59
|
+
var item = _step.value;
|
|
60
|
+
sum += item.value;
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_iterator.e(err);
|
|
64
|
+
} finally {
|
|
65
|
+
_iterator.f();
|
|
66
|
+
}
|
|
67
|
+
return sum;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
|
|
72
|
+
*
|
|
73
|
+
* @export
|
|
74
|
+
* @param {CartItem} targetCartItem
|
|
75
|
+
* @return {*}
|
|
76
|
+
*/
|
|
77
|
+
export function getCapacityInfoByCartItem(targetCartItem) {
|
|
78
|
+
var _targetCartItem$_prod;
|
|
79
|
+
var formatCapacity = formatDefaultCapacitys({
|
|
80
|
+
capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
|
|
81
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
82
|
+
});
|
|
83
|
+
var currentCapacity = getSumCapacity({
|
|
84
|
+
capacity: formatCapacity
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
formatCapacity: formatCapacity,
|
|
88
|
+
currentCapacity: currentCapacity
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
94
|
+
* @description:
|
|
95
|
+
* @param {object} resource
|
|
96
|
+
* @return {*}
|
|
97
|
+
* @Author: jinglin.tan
|
|
98
|
+
*/
|
|
99
|
+
export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resource) {
|
|
100
|
+
if (resource.children && resource.children.length) {
|
|
101
|
+
var countCapacity = resource.capacity; // 100
|
|
102
|
+
resource.children.forEach(function (child, index) {
|
|
103
|
+
if (index === resource.children.length - 1) {
|
|
104
|
+
// 如果是最后一个资源,直接拿剩余未分配完的容量去占用
|
|
105
|
+
// 哪怕这个东西会超过资源本身的 capacity也得让他占,PRD 里有写
|
|
106
|
+
child.capacity = countCapacity;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (child.capacity <= countCapacity) {
|
|
110
|
+
countCapacity -= child.capacity; // 100 - = 90
|
|
111
|
+
} else {
|
|
112
|
+
child.capacity = countCapacity; // 10
|
|
113
|
+
countCapacity = 0; // 0
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 检查资源是否有足够的容量供额外使用
|
|
121
|
+
* @param currentCapacity - 当前已使用的容量
|
|
122
|
+
* @param requiredCapacity - 需要的额外容量
|
|
123
|
+
* @param maxCapacity - 最大允许容量
|
|
124
|
+
* @returns 如果资源可以容纳额外的容量则返回 true
|
|
125
|
+
*/
|
|
126
|
+
export var checkResourceCanUseByCapacity = function checkResourceCanUseByCapacity(currentCapacity, requiredCapacity, maxCapacity) {
|
|
127
|
+
// Handle edge cases early
|
|
128
|
+
if (currentCapacity < 0 || requiredCapacity < 0 || maxCapacity <= 0) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return currentCapacity + requiredCapacity <= maxCapacity;
|
|
132
|
+
};
|
|
@@ -79,7 +79,7 @@ export declare const formatResources: ({ booking, resources, }: {
|
|
|
79
79
|
* @return {*}
|
|
80
80
|
* @Author: zhiwei.Wang
|
|
81
81
|
*/
|
|
82
|
-
export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
|
|
82
|
+
export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
|
|
83
83
|
resource: ResourceItem;
|
|
84
84
|
duration: number;
|
|
85
85
|
split: number;
|
|
@@ -97,7 +97,10 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
|
|
|
97
97
|
} | undefined;
|
|
98
98
|
} | undefined;
|
|
99
99
|
hasFlexibleDuration?: boolean | undefined;
|
|
100
|
-
operating_day_boundary?:
|
|
100
|
+
operating_day_boundary?: {
|
|
101
|
+
type: string;
|
|
102
|
+
time: string;
|
|
103
|
+
} | undefined;
|
|
101
104
|
}) => TimeSliceItem[];
|
|
102
105
|
/**
|
|
103
106
|
* @title: 获取时间切片列表的交集
|
|
@@ -135,7 +138,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
|
|
|
135
138
|
* @return {*}
|
|
136
139
|
* @Author: zhiwei.Wang
|
|
137
140
|
*/
|
|
138
|
-
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary }: {
|
|
141
|
+
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time, hasFlexibleDuration, operating_day_boundary, }: {
|
|
139
142
|
resourceIds: number[];
|
|
140
143
|
resourcesMap: any;
|
|
141
144
|
duration: number;
|
|
@@ -154,7 +157,10 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
|
|
|
154
157
|
} | undefined;
|
|
155
158
|
} | undefined;
|
|
156
159
|
hasFlexibleDuration?: boolean | undefined;
|
|
157
|
-
operating_day_boundary?:
|
|
160
|
+
operating_day_boundary?: {
|
|
161
|
+
type: string;
|
|
162
|
+
time: string;
|
|
163
|
+
} | undefined;
|
|
158
164
|
}) => any[];
|
|
159
165
|
/**
|
|
160
166
|
* @title: 获取其他人的已选资源
|
|
@@ -174,37 +180,11 @@ export declare const getOthersSelectedResources: (cartItems: CartItem[], account
|
|
|
174
180
|
* @Author: jinglin.tan
|
|
175
181
|
*/
|
|
176
182
|
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
177
|
-
interface CapacityItem {
|
|
183
|
+
export interface CapacityItem {
|
|
178
184
|
id: number;
|
|
179
185
|
value: number;
|
|
180
186
|
name: string;
|
|
181
187
|
}
|
|
182
|
-
/**
|
|
183
|
-
* @title: 基于选择的商品格式化容量
|
|
184
|
-
* @description:
|
|
185
|
-
* @param {any} param1
|
|
186
|
-
* @return {*}
|
|
187
|
-
* @Author: zhiwei.Wang
|
|
188
|
-
*/
|
|
189
|
-
export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
|
|
190
|
-
/**
|
|
191
|
-
* @title: 获取总容量
|
|
192
|
-
* @description:
|
|
193
|
-
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
194
|
-
* @return {*}
|
|
195
|
-
* @Author: zhiwei.Wang
|
|
196
|
-
*/
|
|
197
|
-
export declare const getSumCapacity: ({ capacity }: {
|
|
198
|
-
capacity: CapacityItem[];
|
|
199
|
-
}) => number;
|
|
200
|
-
/**
|
|
201
|
-
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
202
|
-
* @description:
|
|
203
|
-
* @param {object} resource
|
|
204
|
-
* @return {*}
|
|
205
|
-
* @Author: jinglin.tan
|
|
206
|
-
*/
|
|
207
|
-
export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
|
|
208
188
|
/**
|
|
209
189
|
* @title: 根据日期范围过滤日程
|
|
210
190
|
*
|
|
@@ -242,4 +222,22 @@ export declare function getResourcesIdsByProduct(product: ProductData): number[]
|
|
|
242
222
|
* @return {*}
|
|
243
223
|
*/
|
|
244
224
|
export declare function sortCombinedResources(resourcesList: ResourceItem[]): ResourceItem[];
|
|
225
|
+
/**
|
|
226
|
+
* 传入一个资源组,根据 formid筛出相同类型的资源
|
|
227
|
+
*
|
|
228
|
+
* @export
|
|
229
|
+
* @param {ResourceItem[]} resources
|
|
230
|
+
* @param {string} form_id
|
|
231
|
+
* @return {*}
|
|
232
|
+
*/
|
|
233
|
+
export declare function filterResourcesByFormItem(resources: ResourceItem[], form_id: string): ResourceItem[];
|
|
234
|
+
/**
|
|
235
|
+
* 传入两个资源,确认这两个资源是否有交集(包括组合资源)
|
|
236
|
+
*
|
|
237
|
+
* @export
|
|
238
|
+
* @param {ResourceItem} resource1
|
|
239
|
+
* @param {ResourceItem} resource2
|
|
240
|
+
* @return {*}
|
|
241
|
+
*/
|
|
242
|
+
export declare function checkTwoResourcesIntersection(resource1: ResourceItem, resource2: ResourceItem): true | undefined;
|
|
245
243
|
export {};
|
|
@@ -463,7 +463,8 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
|
|
|
463
463
|
}
|
|
464
464
|
if (_status.usable) {
|
|
465
465
|
// 如果有hasFlexibleDuration,且timeSlice.start_at 大于等于operating_day_boundary,则不添加时间切片
|
|
466
|
-
|
|
466
|
+
var operatingBoundaryDateTime = (operating_day_boundary === null || operating_day_boundary === void 0 ? void 0 : operating_day_boundary.type) === 'start_time' ? '23:59' : operating_day_boundary === null || operating_day_boundary === void 0 ? void 0 : operating_day_boundary.time;
|
|
467
|
+
if (hasFlexibleDuration && operating_day_boundary && timeSlice.start_time >= (operatingBoundaryDateTime || '23:59')) {
|
|
467
468
|
break;
|
|
468
469
|
}
|
|
469
470
|
// 添加时间切片 09:00 ~ 10:00 09:20 ~ 10:20 09:00 ~ 10:00 09:20 ~ 10:20 11:00 ~ 12:00 11:20 ~ 12:20
|
|
@@ -701,99 +702,6 @@ export var getOthersCartSelectedResources = function getOthersCartSelectedResour
|
|
|
701
702
|
return acc;
|
|
702
703
|
}, []);
|
|
703
704
|
};
|
|
704
|
-
/**
|
|
705
|
-
* @title: 基于选择的商品格式化容量
|
|
706
|
-
* @description:
|
|
707
|
-
* @param {any} param1
|
|
708
|
-
* @return {*}
|
|
709
|
-
* @Author: zhiwei.Wang
|
|
710
|
-
*/
|
|
711
|
-
export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref7) {
|
|
712
|
-
var capacity = _ref7.capacity,
|
|
713
|
-
product_bundle = _ref7.product_bundle;
|
|
714
|
-
if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
|
|
715
|
-
return (product_bundle || []).map(function (d) {
|
|
716
|
-
var id = d.bundle_product_id;
|
|
717
|
-
var item = ((capacity === null || capacity === void 0 ? void 0 : capacity.package) || []).find(function (item) {
|
|
718
|
-
return item.product_id === id;
|
|
719
|
-
});
|
|
720
|
-
return {
|
|
721
|
-
id: id,
|
|
722
|
-
value: item ? d.num || 0 : 0,
|
|
723
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || (d === null || d === void 0 ? void 0 : d.title)
|
|
724
|
-
};
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
|
-
if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'custom') {
|
|
728
|
-
return ((capacity === null || capacity === void 0 ? void 0 : capacity.custom) || []).map(function (d) {
|
|
729
|
-
return {
|
|
730
|
-
id: d.id,
|
|
731
|
-
value: d.min,
|
|
732
|
-
name: d.name
|
|
733
|
-
};
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
// 默认为1
|
|
738
|
-
return [{
|
|
739
|
-
id: 0,
|
|
740
|
-
value: 1,
|
|
741
|
-
name: ''
|
|
742
|
-
}];
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* @title: 获取总容量
|
|
747
|
-
* @description:
|
|
748
|
-
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
749
|
-
* @return {*}
|
|
750
|
-
* @Author: zhiwei.Wang
|
|
751
|
-
*/
|
|
752
|
-
export var getSumCapacity = function getSumCapacity(_ref8) {
|
|
753
|
-
var capacity = _ref8.capacity;
|
|
754
|
-
var sum = 0;
|
|
755
|
-
var _iterator2 = _createForOfIteratorHelper(capacity || []),
|
|
756
|
-
_step2;
|
|
757
|
-
try {
|
|
758
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
759
|
-
var item = _step2.value;
|
|
760
|
-
sum += item.value;
|
|
761
|
-
}
|
|
762
|
-
} catch (err) {
|
|
763
|
-
_iterator2.e(err);
|
|
764
|
-
} finally {
|
|
765
|
-
_iterator2.f();
|
|
766
|
-
}
|
|
767
|
-
return sum;
|
|
768
|
-
};
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
772
|
-
* @description:
|
|
773
|
-
* @param {object} resource
|
|
774
|
-
* @return {*}
|
|
775
|
-
* @Author: jinglin.tan
|
|
776
|
-
*/
|
|
777
|
-
export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resource) {
|
|
778
|
-
if (resource.children && resource.children.length) {
|
|
779
|
-
var countCapacity = resource.capacity; // 100
|
|
780
|
-
resource.children.forEach(function (child, index) {
|
|
781
|
-
if (index === resource.children.length - 1) {
|
|
782
|
-
// 如果是最后一个资源,直接拿剩余未分配完的容量去占用
|
|
783
|
-
// 哪怕这个东西会超过资源本身的 capacity也得让他占,PRD 里有写
|
|
784
|
-
child.capacity = countCapacity;
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
if (child.capacity <= countCapacity) {
|
|
788
|
-
countCapacity -= child.capacity; // 100 - = 90
|
|
789
|
-
} else {
|
|
790
|
-
child.capacity = countCapacity; // 10
|
|
791
|
-
countCapacity = 0; // 0
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
};
|
|
796
|
-
|
|
797
705
|
/**
|
|
798
706
|
* @title: 根据日期范围过滤日程
|
|
799
707
|
*
|
|
@@ -891,4 +799,41 @@ export function sortCombinedResources(resourcesList) {
|
|
|
891
799
|
return aIsCombined === bIsCombined ? 0 : aIsCombined ? 1 : -1;
|
|
892
800
|
});
|
|
893
801
|
return newResourcesList;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* 传入一个资源组,根据 formid筛出相同类型的资源
|
|
806
|
+
*
|
|
807
|
+
* @export
|
|
808
|
+
* @param {ResourceItem[]} resources
|
|
809
|
+
* @param {string} form_id
|
|
810
|
+
* @return {*}
|
|
811
|
+
*/
|
|
812
|
+
export function filterResourcesByFormItem(resources, form_id) {
|
|
813
|
+
return resources.filter(function (n) {
|
|
814
|
+
return n.form_id === form_id;
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* 传入两个资源,确认这两个资源是否有交集(包括组合资源)
|
|
820
|
+
*
|
|
821
|
+
* @export
|
|
822
|
+
* @param {ResourceItem} resource1
|
|
823
|
+
* @param {ResourceItem} resource2
|
|
824
|
+
* @return {*}
|
|
825
|
+
*/
|
|
826
|
+
export function checkTwoResourcesIntersection(resource1, resource2) {
|
|
827
|
+
var _resource1$metadata$c, _resource2$metadata$c;
|
|
828
|
+
// 检查主资源ID是否匹配
|
|
829
|
+
if (resource1.id === resource2.id) return true;
|
|
830
|
+
// 检查组合资源的情况
|
|
831
|
+
if (((_resource1$metadata$c = resource1.metadata.combined_resource) === null || _resource1$metadata$c === void 0 ? void 0 : _resource1$metadata$c.status) === 1 && (
|
|
832
|
+
// 如果现在选择的是组合资源,需要判断
|
|
833
|
+
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
834
|
+
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
835
|
+
resource1.metadata.combined_resource.resource_ids.includes(resource2.id) || resource1.metadata.combined_resource.resource_ids.some(function (n) {
|
|
836
|
+
return resource2.metadata.combined_resource.resource_ids.includes(n);
|
|
837
|
+
}))) return true;
|
|
838
|
+
if (((_resource2$metadata$c = resource2.metadata.combined_resource) === null || _resource2$metadata$c === void 0 ? void 0 : _resource2$metadata$c.status) === 1 && resource2.metadata.combined_resource.resource_ids.includes(resource2.id)) return true;
|
|
894
839
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Dayjs } from "dayjs";
|
|
1
2
|
import { ResourceItem, TimeSliceItem } from "./resources";
|
|
2
3
|
/**
|
|
3
4
|
* 计算资源在指定时间段内的总可用时间(以分钟为单位)
|
|
@@ -23,3 +24,13 @@ export declare function findFastestAvailableResource({ resources, currentCapacit
|
|
|
23
24
|
currentCapacity?: number;
|
|
24
25
|
countMap?: Record<number, number>;
|
|
25
26
|
}): ResourceItem | null;
|
|
27
|
+
/**
|
|
28
|
+
* 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
|
|
29
|
+
*
|
|
30
|
+
* @export
|
|
31
|
+
* @param {TimeSliceItem[]} times
|
|
32
|
+
* @param {Dayjs} startTime
|
|
33
|
+
* @param {Dayjs} endTime
|
|
34
|
+
* @return {*}
|
|
35
|
+
*/
|
|
36
|
+
export declare function filterConditionTimeSlots(times: TimeSliceItem[], startTime: Dayjs, endTime: Dayjs): TimeSliceItem[];
|
|
@@ -206,4 +206,19 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
return selectedResource;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 给定一个时间列表,通过开始和结束时间过滤出符合条件的时间段
|
|
213
|
+
*
|
|
214
|
+
* @export
|
|
215
|
+
* @param {TimeSliceItem[]} times
|
|
216
|
+
* @param {Dayjs} startTime
|
|
217
|
+
* @param {Dayjs} endTime
|
|
218
|
+
* @return {*}
|
|
219
|
+
*/
|
|
220
|
+
export function filterConditionTimeSlots(times, startTime, endTime) {
|
|
221
|
+
return times.filter(function (n) {
|
|
222
|
+
return !dayjs(n.start_at).isAfter(dayjs(startTime)) && !dayjs(n.end_at).isBefore(dayjs(endTime));
|
|
223
|
+
});
|
|
209
224
|
}
|
|
@@ -10,6 +10,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
10
10
|
private window;
|
|
11
11
|
private store;
|
|
12
12
|
private options;
|
|
13
|
+
private hooks?;
|
|
13
14
|
constructor(name?: string, version?: string);
|
|
14
15
|
initialize(core: PisellCore, options: any): Promise<void>;
|
|
15
16
|
destroy(): Promise<void>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
var _excluded = ["wallet_pass_list"];
|
|
2
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); }
|
|
3
|
-
function
|
|
4
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2
|
+
function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
|
|
5
3
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
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."); }
|
|
7
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); }
|
|
@@ -30,6 +28,7 @@ import { BaseModule } from "../../modules/BaseModule";
|
|
|
30
28
|
import { ShopDiscountHooks } from "./types";
|
|
31
29
|
import { DiscountModule } from "../../modules/Discount";
|
|
32
30
|
import { RulesModule } from "../../modules/Rules";
|
|
31
|
+
import Decimal from 'decimal.js';
|
|
33
32
|
export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
34
33
|
_inherits(ShopDiscountImpl, _BaseModule);
|
|
35
34
|
var _super = _createSuper(ShopDiscountImpl);
|
|
@@ -45,6 +44,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
45
44
|
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
46
45
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
47
46
|
_defineProperty(_assertThisInitialized(_this), "options", {});
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
48
48
|
_this.store = {
|
|
49
49
|
customer: null,
|
|
50
50
|
productList: [],
|
|
@@ -59,12 +59,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
59
59
|
key: "initialize",
|
|
60
60
|
value: function () {
|
|
61
61
|
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
|
|
62
|
+
var _options$otherParams;
|
|
62
63
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
63
64
|
while (1) switch (_context.prev = _context.next) {
|
|
64
65
|
case 0:
|
|
65
66
|
this.core = core;
|
|
66
67
|
this.options = options;
|
|
67
68
|
this.store = _objectSpread(_objectSpread({}, this.store), options.store || {});
|
|
69
|
+
this.hooks = (_options$otherParams = options.otherParams) === null || _options$otherParams === void 0 || (_options$otherParams = _options$otherParams.rules) === null || _options$otherParams === void 0 ? void 0 : _options$otherParams.hooks;
|
|
68
70
|
console.log('[ShopDiscount] 初始化完成');
|
|
69
71
|
|
|
70
72
|
// 获取依赖的插件
|
|
@@ -75,7 +77,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
75
77
|
|
|
76
78
|
// 注册事件监听
|
|
77
79
|
this.registerEventListeners();
|
|
78
|
-
case
|
|
80
|
+
case 8:
|
|
79
81
|
case "end":
|
|
80
82
|
return _context.stop();
|
|
81
83
|
}
|
|
@@ -196,7 +198,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
196
198
|
_this2.loadPrepareConfig({
|
|
197
199
|
customerId: customer.id,
|
|
198
200
|
action: 'create',
|
|
199
|
-
with_good_pass: 1
|
|
201
|
+
with_good_pass: 1,
|
|
202
|
+
with_discount_card: 1
|
|
200
203
|
});
|
|
201
204
|
});
|
|
202
205
|
}
|
|
@@ -429,25 +432,42 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
429
432
|
}, {
|
|
430
433
|
key: "setDiscountList",
|
|
431
434
|
value: function setDiscountList(discountList) {
|
|
432
|
-
var
|
|
435
|
+
var _this3 = this,
|
|
436
|
+
_this$store$discount5;
|
|
433
437
|
var productList = this.store.productList || [];
|
|
434
438
|
var editModeDiscountList = [];
|
|
435
439
|
productList.forEach(function (item) {
|
|
436
440
|
if (item.booking_id) {
|
|
441
|
+
var _this3$hooks;
|
|
442
|
+
var product = (_this3$hooks = _this3.hooks) === null || _this3$hooks === void 0 ? void 0 : _this3$hooks.getProduct(item);
|
|
437
443
|
(item.discount_list || []).forEach(function (discount) {
|
|
438
|
-
if (discount.id && discount.type
|
|
439
|
-
var
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
444
|
+
if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
|
|
445
|
+
var index = editModeDiscountList.findIndex(function (n) {
|
|
446
|
+
var _discount$discount;
|
|
447
|
+
return n.id === ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
|
|
448
|
+
});
|
|
449
|
+
if (index !== -1) {
|
|
450
|
+
editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
|
|
451
|
+
amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
452
|
+
savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
453
|
+
});
|
|
454
|
+
} else {
|
|
455
|
+
var _discount$discount2, _discount$discount3, _discount$discount4;
|
|
456
|
+
if (discount.type && !discount.tag) {
|
|
457
|
+
discount.tag = discount.type;
|
|
458
|
+
}
|
|
459
|
+
editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
|
|
460
|
+
isEditMode: true,
|
|
461
|
+
limited_relation_product_data: {},
|
|
462
|
+
savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
|
|
463
|
+
isAvailable: true,
|
|
464
|
+
id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
|
|
465
|
+
format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
|
|
466
|
+
isDisabled: true,
|
|
467
|
+
isSelected: true,
|
|
468
|
+
product_id: ((_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.product_id) || discount.product_id
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
451
471
|
}
|
|
452
472
|
});
|
|
453
473
|
}
|
|
@@ -455,6 +475,24 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
455
475
|
var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
|
|
456
476
|
return !item.isDisabled;
|
|
457
477
|
})));
|
|
478
|
+
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
479
|
+
var _n$appliedProductDeta;
|
|
480
|
+
return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
481
|
+
var _n$discount;
|
|
482
|
+
return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
|
|
483
|
+
}) : [];
|
|
484
|
+
}).flat();
|
|
485
|
+
newDiscountList.forEach(function (item) {
|
|
486
|
+
var _item$applicableProdu;
|
|
487
|
+
var isAllProductUsed = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
|
|
488
|
+
return allUsedProductIds === null || allUsedProductIds === void 0 ? void 0 : allUsedProductIds.includes(id);
|
|
489
|
+
});
|
|
490
|
+
if (!item.isSelected && isAllProductUsed) {
|
|
491
|
+
item.isDisabledForProductUsed = true;
|
|
492
|
+
} else {
|
|
493
|
+
item.isDisabledForProductUsed = false;
|
|
494
|
+
}
|
|
495
|
+
});
|
|
458
496
|
(_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
|
|
459
497
|
this.emitDiscountListChange(newDiscountList);
|
|
460
498
|
return newDiscountList;
|
|
@@ -473,14 +511,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
473
511
|
key: "getCustomerWallet",
|
|
474
512
|
value: function () {
|
|
475
513
|
var _getCustomerWallet = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(id) {
|
|
476
|
-
var result,
|
|
514
|
+
var result, customer;
|
|
477
515
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
478
516
|
while (1) switch (_context7.prev = _context7.next) {
|
|
479
517
|
case 0:
|
|
480
518
|
_context7.prev = 0;
|
|
481
519
|
_context7.next = 3;
|
|
482
|
-
return this.request.get("/customer/info/
|
|
483
|
-
|
|
520
|
+
return this.request.get("/customer/info/".concat(id), {
|
|
521
|
+
with_trashed: 1
|
|
484
522
|
});
|
|
485
523
|
case 3:
|
|
486
524
|
result = _context7.sent;
|
|
@@ -488,7 +526,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
488
526
|
_context7.next = 9;
|
|
489
527
|
break;
|
|
490
528
|
}
|
|
491
|
-
|
|
529
|
+
customer = Object.assign({}, (_objectDestructuringEmpty(result.data), result.data));
|
|
492
530
|
this.setCustomer(customer);
|
|
493
531
|
_context7.next = 9;
|
|
494
532
|
return this.core.effects.emit(ShopDiscountHooks.onScanCustomerChange, customer);
|
|
@@ -526,7 +564,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
526
564
|
return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
|
|
527
565
|
customer_id: customerId,
|
|
528
566
|
action: 'create',
|
|
529
|
-
with_good_pass: 1
|
|
567
|
+
with_good_pass: 1,
|
|
568
|
+
with_discount_card: 1
|
|
530
569
|
});
|
|
531
570
|
case 4:
|
|
532
571
|
goodPassList = _context8.sent;
|