@pisell/pisellos 3.0.41 → 3.0.43
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/AccountList/index.js +17 -12
- package/dist/modules/Cart/index.d.ts +14 -0
- package/dist/modules/Cart/index.js +38 -1
- package/dist/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +28 -8
- package/dist/modules/Cart/utils/changePrice.d.ts +3 -0
- package/dist/modules/Cart/utils/changePrice.js +104 -0
- package/dist/modules/Date/index.js +74 -10
- package/dist/modules/Date/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +13 -6
- 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 +218 -80
- package/dist/modules/Rules/types.d.ts +7 -1
- package/dist/modules/Schedule/index.d.ts +9 -1
- package/dist/modules/Schedule/index.js +122 -2
- package/dist/modules/Schedule/types.d.ts +13 -0
- package/dist/modules/Schedule/utils.js +4 -0
- package/dist/solution/BookingByStep/index.d.ts +121 -30
- package/dist/solution/BookingByStep/index.js +760 -1065
- 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 +21 -29
- package/dist/solution/BookingByStep/utils/resources.js +39 -95
- 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 +2 -0
- package/dist/solution/ShopDiscount/index.js +119 -44
- package/lib/modules/AccountList/index.js +4 -0
- package/lib/modules/Cart/index.d.ts +14 -0
- package/lib/modules/Cart/index.js +34 -1
- package/lib/modules/Cart/utils/cartProduct.d.ts +3 -0
- package/lib/modules/Cart/utils/cartProduct.js +20 -8
- package/lib/modules/Cart/utils/changePrice.d.ts +3 -0
- package/lib/modules/Cart/utils/changePrice.js +78 -0
- package/lib/modules/Date/index.js +62 -5
- package/lib/modules/Date/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +17 -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 +154 -63
- package/lib/modules/Rules/types.d.ts +7 -1
- package/lib/modules/Schedule/index.d.ts +9 -1
- package/lib/modules/Schedule/index.js +79 -1
- package/lib/modules/Schedule/types.d.ts +13 -0
- package/lib/modules/Schedule/utils.js +4 -1
- package/lib/solution/BookingByStep/index.d.ts +121 -30
- package/lib/solution/BookingByStep/index.js +395 -585
- 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 +21 -29
- package/lib/solution/BookingByStep/utils/resources.js +21 -58
- 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 +2 -0
- package/lib/solution/ShopDiscount/index.js +91 -19
- 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,106 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/solution/BookingByStep/utils/capacity.ts
|
|
20
|
+
var capacity_exports = {};
|
|
21
|
+
__export(capacity_exports, {
|
|
22
|
+
checkResourceCanUseByCapacity: () => checkResourceCanUseByCapacity,
|
|
23
|
+
checkSubResourcesCapacity: () => checkSubResourcesCapacity,
|
|
24
|
+
formatDefaultCapacitys: () => formatDefaultCapacitys,
|
|
25
|
+
getCapacityInfoByCartItem: () => getCapacityInfoByCartItem,
|
|
26
|
+
getSumCapacity: () => getSumCapacity
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(capacity_exports);
|
|
29
|
+
var formatDefaultCapacitys = ({
|
|
30
|
+
capacity,
|
|
31
|
+
product_bundle
|
|
32
|
+
}) => {
|
|
33
|
+
if ((capacity == null ? void 0 : capacity.type) === "package") {
|
|
34
|
+
return (product_bundle || []).map((d) => {
|
|
35
|
+
const id = d.bundle_product_id;
|
|
36
|
+
const item = ((capacity == null ? void 0 : capacity.package) || []).find(
|
|
37
|
+
(item2) => item2.product_id === id
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
value: item ? d.num || 0 : 0,
|
|
42
|
+
name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if ((capacity == null ? void 0 : capacity.type) === "custom") {
|
|
47
|
+
return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
|
|
48
|
+
return {
|
|
49
|
+
id: d.id,
|
|
50
|
+
value: d.min,
|
|
51
|
+
name: d.name
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return [{ id: 0, value: 1, name: "" }];
|
|
56
|
+
};
|
|
57
|
+
var getSumCapacity = ({ capacity }) => {
|
|
58
|
+
let sum = 0;
|
|
59
|
+
for (let item of capacity || []) {
|
|
60
|
+
sum += item.value;
|
|
61
|
+
}
|
|
62
|
+
return sum;
|
|
63
|
+
};
|
|
64
|
+
function getCapacityInfoByCartItem(targetCartItem) {
|
|
65
|
+
var _a;
|
|
66
|
+
const formatCapacity = formatDefaultCapacitys({
|
|
67
|
+
capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
|
|
68
|
+
product_bundle: targetCartItem._origin.product.product_bundle
|
|
69
|
+
});
|
|
70
|
+
const currentCapacity = getSumCapacity({ capacity: formatCapacity });
|
|
71
|
+
return {
|
|
72
|
+
formatCapacity,
|
|
73
|
+
currentCapacity
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var checkSubResourcesCapacity = (resource) => {
|
|
77
|
+
if (resource.children && resource.children.length) {
|
|
78
|
+
let countCapacity = resource.capacity;
|
|
79
|
+
resource.children.forEach((child, index) => {
|
|
80
|
+
if (index === resource.children.length - 1) {
|
|
81
|
+
child.capacity = countCapacity;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (child.capacity <= countCapacity) {
|
|
85
|
+
countCapacity -= child.capacity;
|
|
86
|
+
} else {
|
|
87
|
+
child.capacity = countCapacity;
|
|
88
|
+
countCapacity = 0;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
var checkResourceCanUseByCapacity = (currentCapacity, requiredCapacity, maxCapacity) => {
|
|
94
|
+
if (currentCapacity < 0 || requiredCapacity < 0 || maxCapacity <= 0) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return currentCapacity + requiredCapacity <= maxCapacity;
|
|
98
|
+
};
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
checkResourceCanUseByCapacity,
|
|
102
|
+
checkSubResourcesCapacity,
|
|
103
|
+
formatDefaultCapacitys,
|
|
104
|
+
getCapacityInfoByCartItem,
|
|
105
|
+
getSumCapacity
|
|
106
|
+
});
|
|
@@ -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;
|
|
@@ -138,7 +138,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
|
|
|
138
138
|
* @return {*}
|
|
139
139
|
* @Author: zhiwei.Wang
|
|
140
140
|
*/
|
|
141
|
-
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, }: {
|
|
142
142
|
resourceIds: number[];
|
|
143
143
|
resourcesMap: any;
|
|
144
144
|
duration: number;
|
|
@@ -180,37 +180,11 @@ export declare const getOthersSelectedResources: (cartItems: CartItem[], account
|
|
|
180
180
|
* @Author: jinglin.tan
|
|
181
181
|
*/
|
|
182
182
|
export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
|
|
183
|
-
interface CapacityItem {
|
|
183
|
+
export interface CapacityItem {
|
|
184
184
|
id: number;
|
|
185
185
|
value: number;
|
|
186
186
|
name: string;
|
|
187
187
|
}
|
|
188
|
-
/**
|
|
189
|
-
* @title: 基于选择的商品格式化容量
|
|
190
|
-
* @description:
|
|
191
|
-
* @param {any} param1
|
|
192
|
-
* @return {*}
|
|
193
|
-
* @Author: zhiwei.Wang
|
|
194
|
-
*/
|
|
195
|
-
export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any) => CapacityItem[];
|
|
196
|
-
/**
|
|
197
|
-
* @title: 获取总容量
|
|
198
|
-
* @description:
|
|
199
|
-
* @param {object} capacity 为 formatDefaultCapacitys()的结果
|
|
200
|
-
* @return {*}
|
|
201
|
-
* @Author: zhiwei.Wang
|
|
202
|
-
*/
|
|
203
|
-
export declare const getSumCapacity: ({ capacity }: {
|
|
204
|
-
capacity: CapacityItem[];
|
|
205
|
-
}) => number;
|
|
206
|
-
/**
|
|
207
|
-
* @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
|
|
208
|
-
* @description:
|
|
209
|
-
* @param {object} resource
|
|
210
|
-
* @return {*}
|
|
211
|
-
* @Author: jinglin.tan
|
|
212
|
-
*/
|
|
213
|
-
export declare const checkSubResourcesCapacity: (resource: ResourceItem) => void;
|
|
214
188
|
/**
|
|
215
189
|
* @title: 根据日期范围过滤日程
|
|
216
190
|
*
|
|
@@ -248,4 +222,22 @@ export declare function getResourcesIdsByProduct(product: ProductData): number[]
|
|
|
248
222
|
* @return {*}
|
|
249
223
|
*/
|
|
250
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;
|
|
251
243
|
export {};
|
|
@@ -30,9 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var resources_exports = {};
|
|
31
31
|
__export(resources_exports, {
|
|
32
32
|
checkSessionProductLeadTime: () => checkSessionProductLeadTime,
|
|
33
|
-
|
|
33
|
+
checkTwoResourcesIntersection: () => checkTwoResourcesIntersection,
|
|
34
|
+
filterResourcesByFormItem: () => filterResourcesByFormItem,
|
|
34
35
|
filterScheduleByDateRange: () => filterScheduleByDateRange,
|
|
35
|
-
formatDefaultCapacitys: () => formatDefaultCapacitys,
|
|
36
36
|
formatResources: () => formatResources,
|
|
37
37
|
getIsUsableByTimeItem: () => getIsUsableByTimeItem,
|
|
38
38
|
getOthersCartSelectedResources: () => getOthersCartSelectedResources,
|
|
@@ -40,7 +40,6 @@ __export(resources_exports, {
|
|
|
40
40
|
getResourcesByIds: () => getResourcesByIds,
|
|
41
41
|
getResourcesByProduct: () => getResourcesByProduct,
|
|
42
42
|
getResourcesIdsByProduct: () => getResourcesIdsByProduct,
|
|
43
|
-
getSumCapacity: () => getSumCapacity,
|
|
44
43
|
getTimeSlicesByResource: () => getTimeSlicesByResource,
|
|
45
44
|
getTimeSlicesByResources: () => getTimeSlicesByResources,
|
|
46
45
|
getTimesIntersection: () => getTimesIntersection,
|
|
@@ -522,58 +521,6 @@ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
|
|
|
522
521
|
return acc;
|
|
523
522
|
}, []);
|
|
524
523
|
};
|
|
525
|
-
var formatDefaultCapacitys = ({
|
|
526
|
-
capacity,
|
|
527
|
-
product_bundle
|
|
528
|
-
}) => {
|
|
529
|
-
if ((capacity == null ? void 0 : capacity.type) === "package") {
|
|
530
|
-
return (product_bundle || []).map((d) => {
|
|
531
|
-
const id = d.bundle_product_id;
|
|
532
|
-
const item = ((capacity == null ? void 0 : capacity.package) || []).find(
|
|
533
|
-
(item2) => item2.product_id === id
|
|
534
|
-
);
|
|
535
|
-
return {
|
|
536
|
-
id,
|
|
537
|
-
value: item ? d.num || 0 : 0,
|
|
538
|
-
name: (item == null ? void 0 : item.name) || (d == null ? void 0 : d.title)
|
|
539
|
-
};
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
if ((capacity == null ? void 0 : capacity.type) === "custom") {
|
|
543
|
-
return ((capacity == null ? void 0 : capacity.custom) || []).map((d) => {
|
|
544
|
-
return {
|
|
545
|
-
id: d.id,
|
|
546
|
-
value: d.min,
|
|
547
|
-
name: d.name
|
|
548
|
-
};
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
return [{ id: 0, value: 1, name: "" }];
|
|
552
|
-
};
|
|
553
|
-
var getSumCapacity = ({ capacity }) => {
|
|
554
|
-
let sum = 0;
|
|
555
|
-
for (let item of capacity || []) {
|
|
556
|
-
sum += item.value;
|
|
557
|
-
}
|
|
558
|
-
return sum;
|
|
559
|
-
};
|
|
560
|
-
var checkSubResourcesCapacity = (resource) => {
|
|
561
|
-
if (resource.children && resource.children.length) {
|
|
562
|
-
let countCapacity = resource.capacity;
|
|
563
|
-
resource.children.forEach((child, index) => {
|
|
564
|
-
if (index === resource.children.length - 1) {
|
|
565
|
-
child.capacity = countCapacity;
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
if (child.capacity <= countCapacity) {
|
|
569
|
-
countCapacity -= child.capacity;
|
|
570
|
-
} else {
|
|
571
|
-
child.capacity = countCapacity;
|
|
572
|
-
countCapacity = 0;
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
524
|
function filterScheduleByDateRange(schedule, startDate, endDate) {
|
|
578
525
|
if (!(schedule == null ? void 0 : schedule.length))
|
|
579
526
|
return [];
|
|
@@ -637,12 +584,29 @@ function sortCombinedResources(resourcesList) {
|
|
|
637
584
|
});
|
|
638
585
|
return newResourcesList;
|
|
639
586
|
}
|
|
587
|
+
function filterResourcesByFormItem(resources, form_id) {
|
|
588
|
+
return resources.filter((n) => n.form_id === form_id);
|
|
589
|
+
}
|
|
590
|
+
function checkTwoResourcesIntersection(resource1, resource2) {
|
|
591
|
+
var _a, _b;
|
|
592
|
+
if (resource1.id === resource2.id)
|
|
593
|
+
return true;
|
|
594
|
+
if (((_a = resource1.metadata.combined_resource) == null ? void 0 : _a.status) === 1 && // 如果现在选择的是组合资源,需要判断
|
|
595
|
+
// 1、当前其他购物车里是否选了当前组合资源的子资源
|
|
596
|
+
// 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
|
|
597
|
+
(resource1.metadata.combined_resource.resource_ids.includes(resource2.id) || resource1.metadata.combined_resource.resource_ids.some((n) => {
|
|
598
|
+
return resource2.metadata.combined_resource.resource_ids.includes(n);
|
|
599
|
+
})))
|
|
600
|
+
return true;
|
|
601
|
+
if (((_b = resource2.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && resource2.metadata.combined_resource.resource_ids.includes(resource2.id))
|
|
602
|
+
return true;
|
|
603
|
+
}
|
|
640
604
|
// Annotate the CommonJS export names for ESM import in node:
|
|
641
605
|
0 && (module.exports = {
|
|
642
606
|
checkSessionProductLeadTime,
|
|
643
|
-
|
|
607
|
+
checkTwoResourcesIntersection,
|
|
608
|
+
filterResourcesByFormItem,
|
|
644
609
|
filterScheduleByDateRange,
|
|
645
|
-
formatDefaultCapacitys,
|
|
646
610
|
formatResources,
|
|
647
611
|
getIsUsableByTimeItem,
|
|
648
612
|
getOthersCartSelectedResources,
|
|
@@ -650,7 +614,6 @@ function sortCombinedResources(resourcesList) {
|
|
|
650
614
|
getResourcesByIds,
|
|
651
615
|
getResourcesByProduct,
|
|
652
616
|
getResourcesIdsByProduct,
|
|
653
|
-
getSumCapacity,
|
|
654
617
|
getTimeSlicesByResource,
|
|
655
618
|
getTimeSlicesByResources,
|
|
656
619
|
getTimesIntersection,
|
|
@@ -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[];
|
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var timeslots_exports = {};
|
|
31
31
|
__export(timeslots_exports, {
|
|
32
32
|
calculateResourceAvailableTime: () => calculateResourceAvailableTime,
|
|
33
|
+
filterConditionTimeSlots: () => filterConditionTimeSlots,
|
|
33
34
|
findFastestAvailableResource: () => findFastestAvailableResource
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(timeslots_exports);
|
|
@@ -152,8 +153,14 @@ function findFastestAvailableResource({
|
|
|
152
153
|
}
|
|
153
154
|
return selectedResource;
|
|
154
155
|
}
|
|
156
|
+
function filterConditionTimeSlots(times, startTime, endTime) {
|
|
157
|
+
return times.filter((n) => {
|
|
158
|
+
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));
|
|
159
|
+
});
|
|
160
|
+
}
|
|
155
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
156
162
|
0 && (module.exports = {
|
|
157
163
|
calculateResourceAvailableTime,
|
|
164
|
+
filterConditionTimeSlots,
|
|
158
165
|
findFastestAvailableResource
|
|
159
166
|
});
|
|
@@ -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>;
|
|
@@ -37,6 +38,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
37
38
|
isAvailable: boolean;
|
|
38
39
|
productList: Record<string, any>[];
|
|
39
40
|
discountList: Discount[];
|
|
41
|
+
type: "server" | "clientCalc";
|
|
40
42
|
}>;
|
|
41
43
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
42
44
|
private getCustomer;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/solution/ShopDiscount/index.ts
|
|
@@ -27,6 +37,7 @@ var import_BaseModule = require("../../modules/BaseModule");
|
|
|
27
37
|
var import_types = require("./types");
|
|
28
38
|
var import_Discount = require("../../modules/Discount");
|
|
29
39
|
var import_Rules = require("../../modules/Rules");
|
|
40
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
30
41
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
31
42
|
constructor(name, version) {
|
|
32
43
|
super(name, version);
|
|
@@ -43,9 +54,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
43
54
|
}
|
|
44
55
|
// =========== 生命周期方法 ===========
|
|
45
56
|
async initialize(core, options) {
|
|
57
|
+
var _a, _b;
|
|
46
58
|
this.core = core;
|
|
47
59
|
this.options = options;
|
|
48
60
|
this.store = { ...this.store, ...options.store || {} };
|
|
61
|
+
this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
|
|
49
62
|
console.log("[ShopDiscount] 初始化完成");
|
|
50
63
|
this.initializePlugins();
|
|
51
64
|
this.registerDependentModules();
|
|
@@ -118,7 +131,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
118
131
|
this.loadPrepareConfig({
|
|
119
132
|
customerId: customer.id,
|
|
120
133
|
action: "create",
|
|
121
|
-
with_good_pass: 1
|
|
134
|
+
with_good_pass: 1,
|
|
135
|
+
with_discount_card: 1
|
|
122
136
|
});
|
|
123
137
|
}
|
|
124
138
|
);
|
|
@@ -191,6 +205,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
191
205
|
const rulesModule = this.store.rules;
|
|
192
206
|
if (!rulesModule) {
|
|
193
207
|
return {
|
|
208
|
+
type: "clientCalc",
|
|
209
|
+
isAvailable: false,
|
|
210
|
+
productList: this.store.productList || [],
|
|
211
|
+
discountList: this.getDiscountList()
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (!resultDiscountList.length) {
|
|
215
|
+
return {
|
|
216
|
+
type: "server",
|
|
194
217
|
isAvailable: false,
|
|
195
218
|
productList: this.store.productList || [],
|
|
196
219
|
discountList: this.getDiscountList()
|
|
@@ -225,6 +248,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
225
248
|
}
|
|
226
249
|
}
|
|
227
250
|
return {
|
|
251
|
+
type: "clientCalc",
|
|
228
252
|
isAvailable: isAvailable || false,
|
|
229
253
|
productList: newProductList || this.store.productList || [],
|
|
230
254
|
discountList: newDiscountList || this.getDiscountList()
|
|
@@ -232,6 +256,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
232
256
|
} catch (error) {
|
|
233
257
|
console.error("[ShopDiscount] 扫码出错:", error);
|
|
234
258
|
return {
|
|
259
|
+
type: "clientCalc",
|
|
235
260
|
isAvailable: false,
|
|
236
261
|
productList: this.store.productList || [],
|
|
237
262
|
discountList: this.getDiscountList()
|
|
@@ -267,22 +292,39 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
267
292
|
const productList = this.store.productList || [];
|
|
268
293
|
const editModeDiscountList = [];
|
|
269
294
|
productList.forEach((item) => {
|
|
295
|
+
var _a2;
|
|
270
296
|
if (item.booking_id) {
|
|
297
|
+
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
|
|
271
298
|
(item.discount_list || []).forEach((discount) => {
|
|
272
|
-
var
|
|
273
|
-
if (discount.id && discount.type
|
|
274
|
-
editModeDiscountList.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
limited_relation_product_data: {},
|
|
278
|
-
savedAmount: discount.amount,
|
|
279
|
-
isAvailable: true,
|
|
280
|
-
id: ((_a2 = discount.discount) == null ? void 0 : _a2.resource_id) || discount.id,
|
|
281
|
-
format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
|
|
282
|
-
isDisabled: true,
|
|
283
|
-
isSelected: true,
|
|
284
|
-
product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
|
|
299
|
+
var _a3, _b, _c;
|
|
300
|
+
if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
|
|
301
|
+
const index = editModeDiscountList.findIndex((n) => {
|
|
302
|
+
var _a4;
|
|
303
|
+
return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
|
|
285
304
|
});
|
|
305
|
+
if (index !== -1) {
|
|
306
|
+
editModeDiscountList[index] = {
|
|
307
|
+
...editModeDiscountList[index],
|
|
308
|
+
amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
|
|
309
|
+
savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
|
|
310
|
+
};
|
|
311
|
+
} else {
|
|
312
|
+
if (discount.type && !discount.tag) {
|
|
313
|
+
discount.tag = discount.type;
|
|
314
|
+
}
|
|
315
|
+
editModeDiscountList.push({
|
|
316
|
+
...discount,
|
|
317
|
+
isEditMode: true,
|
|
318
|
+
limited_relation_product_data: {},
|
|
319
|
+
savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
|
|
320
|
+
isAvailable: true,
|
|
321
|
+
id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
|
|
322
|
+
format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
|
|
323
|
+
isDisabled: true,
|
|
324
|
+
isSelected: true,
|
|
325
|
+
product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
|
|
326
|
+
});
|
|
327
|
+
}
|
|
286
328
|
}
|
|
287
329
|
});
|
|
288
330
|
}
|
|
@@ -291,6 +333,33 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
291
333
|
...editModeDiscountList,
|
|
292
334
|
...discountList.filter((item) => !item.isDisabled)
|
|
293
335
|
];
|
|
336
|
+
const allUsedProductIds = newDiscountList.map((n) => {
|
|
337
|
+
var _a2;
|
|
338
|
+
return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
|
|
339
|
+
var _a3;
|
|
340
|
+
return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
|
|
341
|
+
}) : [];
|
|
342
|
+
}).flat();
|
|
343
|
+
newDiscountList.forEach((item) => {
|
|
344
|
+
var _a2;
|
|
345
|
+
const isProductFree = (id) => {
|
|
346
|
+
var _a3;
|
|
347
|
+
const targetProduct = productList.find((n) => n.id === id);
|
|
348
|
+
const product = (_a3 = this.hooks) == null ? void 0 : _a3.getProduct(targetProduct);
|
|
349
|
+
return Number(product == null ? void 0 : product.total) === 0;
|
|
350
|
+
};
|
|
351
|
+
const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|
|
352
|
+
var _a3;
|
|
353
|
+
const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
|
|
354
|
+
const targetIdTimes = (allUsedProductIds == null ? void 0 : allUsedProductIds.filter((n) => n === id).length) || 0;
|
|
355
|
+
return targetIdTimes >= sameIdTimes || isProductFree(id);
|
|
356
|
+
});
|
|
357
|
+
if (!item.isSelected && isAllProductUsedOrFree) {
|
|
358
|
+
item.isDisabledForProductUsed = true;
|
|
359
|
+
} else {
|
|
360
|
+
item.isDisabledForProductUsed = false;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
294
363
|
(_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
|
|
295
364
|
this.emitDiscountListChange(newDiscountList);
|
|
296
365
|
return newDiscountList;
|
|
@@ -303,11 +372,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
303
372
|
// 获取客户钱包信息
|
|
304
373
|
async getCustomerWallet(id) {
|
|
305
374
|
try {
|
|
306
|
-
const result = await this.request.get(`/customer/info
|
|
307
|
-
|
|
375
|
+
const result = await this.request.get(`/customer/info/${id}`, {
|
|
376
|
+
with_trashed: 1
|
|
308
377
|
});
|
|
309
378
|
if (result == null ? void 0 : result.data) {
|
|
310
|
-
const {
|
|
379
|
+
const { ...customer } = result.data;
|
|
311
380
|
this.setCustomer(customer);
|
|
312
381
|
await this.core.effects.emit(
|
|
313
382
|
import_types.ShopDiscountHooks.onScanCustomerChange,
|
|
@@ -326,12 +395,15 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
326
395
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
327
396
|
customer_id: customerId,
|
|
328
397
|
action: "create",
|
|
329
|
-
with_good_pass: 1
|
|
398
|
+
with_good_pass: 1,
|
|
399
|
+
with_discount_card: 1
|
|
330
400
|
}));
|
|
331
401
|
const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
|
|
332
402
|
(item) => item.isScan
|
|
333
403
|
);
|
|
334
|
-
const
|
|
404
|
+
const scanDiscountIds = scanDiscount.map((n) => n.id);
|
|
405
|
+
const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
|
|
406
|
+
const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
|
|
335
407
|
this.setDiscountList(newDiscountList || []);
|
|
336
408
|
if ((_d = this.store.productList) == null ? void 0 : _d.length) {
|
|
337
409
|
const result = this.calcDiscount(this.store.productList);
|