@pisell/pisellos 0.0.10 → 0.0.13
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/Account/index.d.ts +4 -2
- package/dist/modules/Account/index.js +23 -36
- package/dist/modules/Account/types.d.ts +1 -0
- package/dist/modules/AccountList/index.d.ts +2 -0
- package/dist/modules/AccountList/index.js +34 -11
- package/dist/modules/Cart/index.d.ts +17 -11
- package/dist/modules/Cart/index.js +179 -121
- package/dist/modules/Cart/types.d.ts +98 -9
- package/dist/modules/Cart/types.js +8 -0
- package/dist/modules/Cart/utils.d.ts +114 -0
- package/dist/modules/Cart/utils.js +345 -0
- package/dist/modules/Date/index.d.ts +11 -12
- package/dist/modules/Date/index.js +104 -60
- package/dist/modules/Date/types.d.ts +51 -20
- package/dist/modules/Date/types.js +2 -5
- package/dist/modules/Date/utils.d.ts +35 -0
- package/dist/modules/Date/utils.js +211 -0
- package/dist/modules/Discount/index.d.ts +26 -0
- package/dist/modules/Discount/index.js +234 -0
- package/dist/modules/Discount/types.d.ts +66 -0
- package/dist/modules/Discount/types.js +5 -0
- package/dist/modules/Order/index.d.ts +16 -12
- package/dist/modules/Order/index.js +38 -166
- package/dist/modules/Order/types.d.ts +18 -41
- package/dist/modules/Order/types.js +0 -14
- package/dist/modules/Payment/index.d.ts +0 -2
- package/dist/modules/Payment/index.js +45 -76
- package/dist/modules/Payment/types.d.ts +0 -2
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Product/types.d.ts +48 -1
- package/dist/modules/ProductList/index.d.ts +1 -0
- package/dist/modules/ProductList/index.js +21 -1
- package/dist/modules/ProductList/types.d.ts +1 -0
- package/dist/modules/Resource/types.d.ts +6 -2
- package/dist/modules/Rules/index.d.ts +32 -0
- package/dist/modules/Rules/index.js +423 -0
- package/dist/modules/Rules/types.d.ts +46 -0
- package/dist/modules/Rules/types.js +5 -0
- package/dist/modules/Summary/index.d.ts +13 -0
- package/dist/modules/Summary/index.js +80 -0
- package/dist/modules/Summary/types.d.ts +13 -0
- package/dist/modules/Summary/types.js +1 -0
- package/dist/modules/Summary/utils.d.ts +19 -0
- package/dist/modules/Summary/utils.js +56 -0
- package/dist/plugins/index.d.ts +3 -2
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/request.d.ts +4 -3
- package/dist/plugins/request.js +30 -30
- package/dist/plugins/shopStore.d.ts +4 -0
- package/dist/plugins/shopStore.js +1 -0
- package/dist/solution/BookingByStep/index.d.ts +73 -12
- package/dist/solution/BookingByStep/index.js +635 -99
- package/dist/solution/BookingByStep/types.d.ts +2 -0
- package/dist/solution/BookingByStep/types.js +11 -8
- package/dist/solution/BookingByStep/utils/products.d.ts +11 -0
- package/dist/solution/BookingByStep/utils/products.js +47 -0
- package/dist/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/dist/solution/BookingByStep/utils/resources.js +144 -79
- package/dist/solution/ShopDiscount/index.d.ts +50 -0
- package/dist/solution/ShopDiscount/index.js +546 -0
- package/dist/solution/ShopDiscount/types.d.ts +24 -0
- package/dist/solution/ShopDiscount/types.js +10 -0
- package/dist/solution/ShopDiscount/utils.d.ts +1 -0
- package/dist/solution/ShopDiscount/utils.js +7 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/modules/Account/index.d.ts +4 -2
- package/lib/modules/Account/index.js +14 -3
- package/lib/modules/Account/types.d.ts +1 -0
- package/lib/modules/AccountList/index.d.ts +2 -0
- package/lib/modules/AccountList/index.js +17 -0
- package/lib/modules/Cart/index.d.ts +17 -11
- package/lib/modules/Cart/index.js +72 -21
- package/lib/modules/Cart/types.d.ts +98 -9
- package/lib/modules/Cart/utils.d.ts +114 -0
- package/lib/modules/Cart/utils.js +320 -0
- package/lib/modules/Date/index.d.ts +11 -12
- package/lib/modules/Date/index.js +50 -31
- package/lib/modules/Date/types.d.ts +51 -20
- package/lib/modules/Date/types.js +0 -4
- package/lib/modules/Date/utils.d.ts +35 -0
- package/lib/modules/Date/utils.js +167 -0
- package/lib/modules/Discount/index.d.ts +26 -0
- package/lib/modules/Discount/index.js +118 -0
- package/lib/modules/Discount/types.d.ts +66 -0
- package/lib/modules/Discount/types.js +33 -0
- package/lib/modules/Order/index.d.ts +16 -12
- package/lib/modules/Order/index.js +23 -51
- package/lib/modules/Order/types.d.ts +18 -41
- package/lib/modules/Payment/index.d.ts +0 -2
- package/lib/modules/Payment/index.js +6 -17
- package/lib/modules/Payment/types.d.ts +0 -2
- package/lib/modules/Product/types.d.ts +48 -1
- package/lib/modules/ProductList/index.d.ts +1 -0
- package/lib/modules/ProductList/index.js +4 -0
- package/lib/modules/ProductList/types.d.ts +1 -0
- package/lib/modules/Resource/types.d.ts +6 -2
- package/lib/modules/Rules/index.d.ts +32 -0
- package/lib/modules/Rules/index.js +283 -0
- package/lib/modules/Rules/types.d.ts +46 -0
- package/lib/modules/Rules/types.js +33 -0
- package/lib/modules/Summary/index.d.ts +13 -0
- package/lib/modules/Summary/index.js +49 -0
- package/lib/modules/Summary/types.d.ts +13 -0
- package/lib/modules/Summary/types.js +17 -0
- package/lib/modules/Summary/utils.d.ts +19 -0
- package/lib/modules/Summary/utils.js +79 -0
- package/lib/plugins/index.d.ts +3 -2
- package/lib/plugins/index.js +3 -1
- package/lib/plugins/request.d.ts +4 -3
- package/lib/plugins/request.js +4 -20
- package/lib/plugins/shopStore.d.ts +4 -0
- package/lib/plugins/shopStore.js +17 -0
- package/lib/solution/BookingByStep/index.d.ts +73 -12
- package/lib/solution/BookingByStep/index.js +451 -24
- package/lib/solution/BookingByStep/types.d.ts +2 -0
- package/lib/solution/BookingByStep/types.js +3 -0
- package/lib/solution/BookingByStep/utils/products.d.ts +11 -0
- package/lib/solution/BookingByStep/utils/products.js +60 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +59 -10
- package/lib/solution/BookingByStep/utils/resources.js +106 -49
- package/lib/solution/ShopDiscount/index.d.ts +50 -0
- package/lib/solution/ShopDiscount/index.js +321 -0
- package/lib/solution/ShopDiscount/types.d.ts +24 -0
- package/lib/solution/ShopDiscount/types.js +38 -0
- package/lib/solution/ShopDiscount/utils.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +32 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +3 -1
- package/package.json +4 -4
|
@@ -1,27 +1,42 @@
|
|
|
1
1
|
import { Dayjs } from 'dayjs';
|
|
2
|
+
import { CartItem } from '../../../modules';
|
|
2
3
|
/**
|
|
3
4
|
* 1. 获取资源列表
|
|
4
5
|
* 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
|
|
5
6
|
* 3. 格式化资源相关 格式化资源列表 --> 格式化资源 --> 获取时间切片列表 --> 判断单个时间切片是否可用 formatResources
|
|
6
7
|
*
|
|
7
8
|
*/
|
|
8
|
-
type DateType = Dayjs
|
|
9
|
-
interface TimeSliceItem {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
type DateType = Dayjs;
|
|
10
|
+
export interface TimeSliceItem {
|
|
11
|
+
start_time: string;
|
|
12
|
+
end_time: string;
|
|
12
13
|
start_at: DateType;
|
|
13
14
|
end_at: DateType;
|
|
14
15
|
[key: string]: any;
|
|
15
16
|
}
|
|
16
|
-
interface ResourceItem {
|
|
17
|
+
export interface ResourceItem {
|
|
17
18
|
[key: string]: any;
|
|
18
19
|
}
|
|
19
20
|
interface BookingItem {
|
|
20
21
|
[key: string]: any;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @title: 获取时间切片是否可用
|
|
25
|
+
* @description: 根据时间切片、资源、当前预约量判断时间切片是否可用
|
|
26
|
+
* @param {any} param1
|
|
27
|
+
* @return {*}
|
|
28
|
+
* @Author: zhiwei.Wang
|
|
29
|
+
*/
|
|
30
|
+
export declare const getIsUsableByTimeItem: ({ timeSlice, time, resource, currentCount }: {
|
|
31
|
+
timeSlice: TimeSliceItem;
|
|
32
|
+
time: any;
|
|
33
|
+
resource: ResourceItem;
|
|
34
|
+
currentCount: number;
|
|
35
|
+
}) => {
|
|
36
|
+
afterToDay: boolean;
|
|
37
|
+
capacity: boolean;
|
|
38
|
+
usable: boolean;
|
|
39
|
+
};
|
|
25
40
|
/**
|
|
26
41
|
* @title: 获取商品下绑定的资源列表
|
|
27
42
|
* @description:
|
|
@@ -30,7 +45,7 @@ interface ProductItem {
|
|
|
30
45
|
* @return {*}
|
|
31
46
|
* @Author: zhiwei.Wang
|
|
32
47
|
*/
|
|
33
|
-
export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>,
|
|
48
|
+
export declare const getResourcesByProduct: (resourcesMap: Record<string, ResourceItem>, cartItem: CartItem, cartList: CartItem[]) => ResourceItem[];
|
|
34
49
|
export declare const getSumCapacity: () => number;
|
|
35
50
|
/**
|
|
36
51
|
* @title: 获取资源列表
|
|
@@ -56,6 +71,40 @@ export declare const getTimeSlicesByResource: ({ resource, duration, split, curr
|
|
|
56
71
|
resource: ResourceItem;
|
|
57
72
|
duration: number;
|
|
58
73
|
split: number;
|
|
59
|
-
currentDate: DateType;
|
|
74
|
+
currentDate: DateType | string;
|
|
60
75
|
}) => TimeSliceItem[];
|
|
76
|
+
/**
|
|
77
|
+
* @title: 获取时间切片列表的交集
|
|
78
|
+
* @description: 注意: 需要将多个时间切片列表合并在一起,然后判断交集
|
|
79
|
+
* @param {TimeSliceItem} times 多个时间切片
|
|
80
|
+
* @param {number} count 交集次数, 符合此次数的会返回
|
|
81
|
+
* @return {*}
|
|
82
|
+
* @Author: zhiwei.Wang
|
|
83
|
+
*/
|
|
84
|
+
export declare const getTimesIntersection: (times: TimeSliceItem[], count: number) => any[];
|
|
85
|
+
/**
|
|
86
|
+
* @title: 根据ids筛选资源列表
|
|
87
|
+
* @description:
|
|
88
|
+
* @param {any} resourcesMap
|
|
89
|
+
* @param {any} ids
|
|
90
|
+
* @return {*}
|
|
91
|
+
* @Author: zhiwei.Wang
|
|
92
|
+
* @Date: 2024-09-19 20:23
|
|
93
|
+
*/
|
|
94
|
+
export declare const getResourcesByIds: (resourcesMap: Record<string, ResourceItem>, ids: number[]) => ResourceItem[];
|
|
95
|
+
/**
|
|
96
|
+
* @title: 根据资源id列表获取时间切片
|
|
97
|
+
* @description: 传入一个技师id列表, 找出技师列表中公共的时间切片
|
|
98
|
+
* @param {ResourceItem} resources
|
|
99
|
+
* @param {CartItem} cart
|
|
100
|
+
* @return {*}
|
|
101
|
+
* @Author: zhiwei.Wang
|
|
102
|
+
*/
|
|
103
|
+
export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split }: {
|
|
104
|
+
resourceIds: number[];
|
|
105
|
+
resourcesMap: any;
|
|
106
|
+
duration: number;
|
|
107
|
+
currentDate: DateType | string;
|
|
108
|
+
split: number;
|
|
109
|
+
}) => any[];
|
|
61
110
|
export {};
|
|
@@ -30,9 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var resources_exports = {};
|
|
31
31
|
__export(resources_exports, {
|
|
32
32
|
formatResources: () => formatResources,
|
|
33
|
+
getIsUsableByTimeItem: () => getIsUsableByTimeItem,
|
|
34
|
+
getResourcesByIds: () => getResourcesByIds,
|
|
33
35
|
getResourcesByProduct: () => getResourcesByProduct,
|
|
34
36
|
getSumCapacity: () => getSumCapacity,
|
|
35
|
-
getTimeSlicesByResource: () => getTimeSlicesByResource
|
|
37
|
+
getTimeSlicesByResource: () => getTimeSlicesByResource,
|
|
38
|
+
getTimeSlicesByResources: () => getTimeSlicesByResources,
|
|
39
|
+
getTimesIntersection: () => getTimesIntersection
|
|
36
40
|
});
|
|
37
41
|
module.exports = __toCommonJS(resources_exports);
|
|
38
42
|
var import_dayjs = __toESM(require("dayjs"));
|
|
@@ -104,40 +108,54 @@ var getIsUsableByTimeItem = ({ timeSlice, time, resource, currentCount = 1 }) =>
|
|
|
104
108
|
status.usable = true;
|
|
105
109
|
return status;
|
|
106
110
|
};
|
|
107
|
-
var getResourcesByProduct = (resourcesMap,
|
|
111
|
+
var getResourcesByProduct = (resourcesMap, cartItem, cartList) => {
|
|
108
112
|
var _a;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
(d) =>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
113
|
+
const product = cartItem._productOrigin;
|
|
114
|
+
return (((_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) || []).reduce((acc, item) => {
|
|
115
|
+
if ((item == null ? void 0 : item.status) == 1) {
|
|
116
|
+
const form_id = item.id;
|
|
117
|
+
item.optional_resource = (item.optional_resource || []).filter(
|
|
118
|
+
(d) => item.default_resource.indexOf(d) == -1
|
|
119
|
+
);
|
|
120
|
+
const selectedResources = cartList.reduce((acc2, d) => {
|
|
121
|
+
var _a2;
|
|
122
|
+
if (d.holder_id !== cartItem.holder_id) {
|
|
123
|
+
if ((_a2 = d._origin) == null ? void 0 : _a2.resources) {
|
|
124
|
+
d._origin.resources.forEach((n) => {
|
|
125
|
+
acc2.push(n.id);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return acc2;
|
|
130
|
+
}, []);
|
|
131
|
+
let optional_resource = item.optional_resource.reduce((childAcc, d) => {
|
|
132
|
+
if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
|
|
133
|
+
childAcc.push(Object.assign({}, resourcesMap[d], {
|
|
134
|
+
form_id,
|
|
135
|
+
resourceType: item.type
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
return childAcc;
|
|
139
|
+
}, []);
|
|
140
|
+
let default_resource = item.default_resource.reduce((childAcc, d) => {
|
|
141
|
+
if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
|
|
142
|
+
childAcc.push(Object.assign({}, resourcesMap[d], {
|
|
143
|
+
form_id,
|
|
144
|
+
resourceType: item.type,
|
|
145
|
+
is_default: 1
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
return childAcc;
|
|
149
|
+
}, []);
|
|
150
|
+
item.renderList = optional_resource.concat(default_resource);
|
|
151
|
+
item.renderList = item.renderList.filter((d) => {
|
|
152
|
+
return (0, import_dayjs.default)(d.times[0].end_at).isAfter((0, import_dayjs.default)());
|
|
153
|
+
});
|
|
154
|
+
item.form_id = form_id;
|
|
155
|
+
acc.push(item);
|
|
156
|
+
}
|
|
157
|
+
return acc;
|
|
158
|
+
}, []);
|
|
141
159
|
};
|
|
142
160
|
var getSumCapacity = () => {
|
|
143
161
|
return 1;
|
|
@@ -152,7 +170,7 @@ var formatResources = ({ booking, resources }) => {
|
|
|
152
170
|
let res = formatResource(d, booking);
|
|
153
171
|
renderListMaps[res.id] = res;
|
|
154
172
|
return res;
|
|
155
|
-
})
|
|
173
|
+
});
|
|
156
174
|
maps[item.form_id] = {
|
|
157
175
|
...item,
|
|
158
176
|
renderListMaps
|
|
@@ -177,8 +195,8 @@ var getTimeSlicesByResource = ({
|
|
|
177
195
|
const timeSlices = [];
|
|
178
196
|
times.forEach((time) => {
|
|
179
197
|
const today = (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD");
|
|
180
|
-
const startTime = (0, import_dayjs.default)(`${
|
|
181
|
-
const endTime = (0, import_dayjs.default)(`${
|
|
198
|
+
const startTime = (0, import_dayjs.default)(`${time.start_at}`);
|
|
199
|
+
const endTime = (0, import_dayjs.default)(`${time.end_at}`);
|
|
182
200
|
let currentStart = startTime;
|
|
183
201
|
while (true) {
|
|
184
202
|
const currentEnd = currentStart.add(duration, "minute");
|
|
@@ -186,30 +204,69 @@ var getTimeSlicesByResource = ({
|
|
|
186
204
|
break;
|
|
187
205
|
}
|
|
188
206
|
const timeSlice = {
|
|
189
|
-
|
|
190
|
-
|
|
207
|
+
start_time: currentStart.format("HH:mm"),
|
|
208
|
+
end_time: currentEnd.format("HH:mm"),
|
|
191
209
|
start_at: currentStart,
|
|
192
210
|
end_at: currentEnd
|
|
193
211
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
time,
|
|
200
|
-
resource,
|
|
201
|
-
currentCount: getSumCapacity()
|
|
202
|
-
})
|
|
212
|
+
const _status = getIsUsableByTimeItem({
|
|
213
|
+
timeSlice,
|
|
214
|
+
time,
|
|
215
|
+
resource,
|
|
216
|
+
currentCount: getSumCapacity()
|
|
203
217
|
});
|
|
218
|
+
if (_status.usable) {
|
|
219
|
+
timeSlices.push({
|
|
220
|
+
...timeSlice,
|
|
221
|
+
// 这里需要补充这个时间段内是否可预约
|
|
222
|
+
_status
|
|
223
|
+
});
|
|
224
|
+
}
|
|
204
225
|
currentStart = currentStart.add(split, "minute");
|
|
205
226
|
}
|
|
206
227
|
});
|
|
207
228
|
return timeSlices;
|
|
208
229
|
};
|
|
230
|
+
var getTimesIntersection = (times, count) => {
|
|
231
|
+
let obj = times.reduce((acc, item) => {
|
|
232
|
+
let _key = `${item.start_time}-${item.end_time}`;
|
|
233
|
+
if (!acc[_key]) {
|
|
234
|
+
acc[_key] = {
|
|
235
|
+
item,
|
|
236
|
+
count: 1
|
|
237
|
+
};
|
|
238
|
+
} else {
|
|
239
|
+
acc[_key].count += 1;
|
|
240
|
+
}
|
|
241
|
+
return acc;
|
|
242
|
+
}, {});
|
|
243
|
+
return Object.values(obj).filter((d) => d.count >= count).map((d) => d.item);
|
|
244
|
+
};
|
|
245
|
+
var getResourcesByIds = (resourcesMap, ids) => {
|
|
246
|
+
return (ids || []).map((id) => resourcesMap[id]);
|
|
247
|
+
};
|
|
248
|
+
var getTimeSlicesByResources = ({
|
|
249
|
+
resourceIds,
|
|
250
|
+
resourcesMap,
|
|
251
|
+
duration,
|
|
252
|
+
currentDate,
|
|
253
|
+
split
|
|
254
|
+
}) => {
|
|
255
|
+
let resources = getResourcesByIds(resourcesMap, resourceIds);
|
|
256
|
+
let timeSliceList = resources.reduce((acc, item) => {
|
|
257
|
+
return acc.concat(getTimeSlicesByResource({ resource: item, duration, split, currentDate }));
|
|
258
|
+
}, []);
|
|
259
|
+
let intersection = getTimesIntersection(timeSliceList, resources.length);
|
|
260
|
+
return intersection;
|
|
261
|
+
};
|
|
209
262
|
// Annotate the CommonJS export names for ESM import in node:
|
|
210
263
|
0 && (module.exports = {
|
|
211
264
|
formatResources,
|
|
265
|
+
getIsUsableByTimeItem,
|
|
266
|
+
getResourcesByIds,
|
|
212
267
|
getResourcesByProduct,
|
|
213
268
|
getSumCapacity,
|
|
214
|
-
getTimeSlicesByResource
|
|
269
|
+
getTimeSlicesByResource,
|
|
270
|
+
getTimeSlicesByResources,
|
|
271
|
+
getTimesIntersection
|
|
215
272
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Module, PisellCore } from "../../types";
|
|
2
|
+
import { BaseModule } from "../../modules/BaseModule";
|
|
3
|
+
import { Customer } from "./types";
|
|
4
|
+
import { Discount } from "../../modules/Discount/types";
|
|
5
|
+
export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
6
|
+
protected defaultName: string;
|
|
7
|
+
protected defaultVersion: string;
|
|
8
|
+
isSolution: boolean;
|
|
9
|
+
private request;
|
|
10
|
+
private window;
|
|
11
|
+
private store;
|
|
12
|
+
private options;
|
|
13
|
+
constructor(name?: string, version?: string);
|
|
14
|
+
initialize(core: PisellCore, options: any): Promise<void>;
|
|
15
|
+
destroy(): Promise<void>;
|
|
16
|
+
clear(): Promise<void>;
|
|
17
|
+
private initializePlugins;
|
|
18
|
+
private registerDependentModules;
|
|
19
|
+
private registerEventListeners;
|
|
20
|
+
setCustomer(customer: Customer): Promise<void>;
|
|
21
|
+
calcDiscount(productList: Record<string, any>[], options?: {
|
|
22
|
+
discountId: number;
|
|
23
|
+
isSelected: boolean;
|
|
24
|
+
}): {
|
|
25
|
+
productList: Record<string, any>[];
|
|
26
|
+
discountList: Discount[];
|
|
27
|
+
};
|
|
28
|
+
setDiscountSelected({ discountId, isSelected, }: {
|
|
29
|
+
discountId: number;
|
|
30
|
+
isSelected: boolean;
|
|
31
|
+
}): {
|
|
32
|
+
productList: Record<string, any>[];
|
|
33
|
+
discountList: Discount[];
|
|
34
|
+
};
|
|
35
|
+
setProductList(productList: Record<string, any>[]): void;
|
|
36
|
+
scanCode(code: string): Promise<{
|
|
37
|
+
isAvailable: boolean;
|
|
38
|
+
productList: Record<string, any>[];
|
|
39
|
+
discountList: Discount[];
|
|
40
|
+
}>;
|
|
41
|
+
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
42
|
+
private getCustomer;
|
|
43
|
+
private isWalkIn;
|
|
44
|
+
private emitDiscountListChange;
|
|
45
|
+
private setDiscountList;
|
|
46
|
+
private getDiscountList;
|
|
47
|
+
private getCustomerWallet;
|
|
48
|
+
private loadPrepareConfig;
|
|
49
|
+
}
|
|
50
|
+
export default ShopDiscountImpl;
|
|
@@ -0,0 +1,321 @@
|
|
|
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/ShopDiscount/index.ts
|
|
20
|
+
var ShopDiscount_exports = {};
|
|
21
|
+
__export(ShopDiscount_exports, {
|
|
22
|
+
ShopDiscountImpl: () => ShopDiscountImpl,
|
|
23
|
+
default: () => ShopDiscount_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(ShopDiscount_exports);
|
|
26
|
+
var import_BaseModule = require("../../modules/BaseModule");
|
|
27
|
+
var import_types = require("./types");
|
|
28
|
+
var import_Discount = require("../../modules/Discount");
|
|
29
|
+
var import_Rules = require("../../modules/Rules");
|
|
30
|
+
var import_utils = require("./utils");
|
|
31
|
+
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
32
|
+
constructor(name, version) {
|
|
33
|
+
super(name, version);
|
|
34
|
+
this.defaultName = "shopDiscount";
|
|
35
|
+
this.defaultVersion = "1.0.0";
|
|
36
|
+
this.isSolution = true;
|
|
37
|
+
this.options = {};
|
|
38
|
+
this.store = {
|
|
39
|
+
customer: null,
|
|
40
|
+
productList: [],
|
|
41
|
+
discount: null,
|
|
42
|
+
rules: null
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
// =========== 生命周期方法 ===========
|
|
46
|
+
async initialize(core, options) {
|
|
47
|
+
this.core = core;
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.store = { ...this.store, ...options.store || {} };
|
|
50
|
+
console.log("[ShopDiscount] 初始化完成");
|
|
51
|
+
this.initializePlugins();
|
|
52
|
+
this.registerDependentModules();
|
|
53
|
+
this.registerEventListeners();
|
|
54
|
+
}
|
|
55
|
+
async destroy() {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
this.store.productList = [];
|
|
58
|
+
this.store.customer = null;
|
|
59
|
+
(_a = this.store.discount) == null ? void 0 : _a.destroy();
|
|
60
|
+
(_b = this.store.rules) == null ? void 0 : _b.destroy();
|
|
61
|
+
this.core.effects.offByModuleDestroy(this.name);
|
|
62
|
+
await this.core.effects.emit(import_types.ShopDiscountHooks.onDestroy, {});
|
|
63
|
+
console.log("[ShopDiscount] 已销毁");
|
|
64
|
+
}
|
|
65
|
+
async clear() {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
this.store.productList = [];
|
|
68
|
+
this.store.customer = null;
|
|
69
|
+
(_a = this.store.discount) == null ? void 0 : _a.clear();
|
|
70
|
+
(_b = this.store.rules) == null ? void 0 : _b.clear();
|
|
71
|
+
console.log("[ShopDiscount] clear");
|
|
72
|
+
}
|
|
73
|
+
// =========== 初始化辅助方法 ===========
|
|
74
|
+
initializePlugins() {
|
|
75
|
+
this.request = this.core.getPlugin("request");
|
|
76
|
+
this.window = this.core.getPlugin("window");
|
|
77
|
+
if (!this.request) {
|
|
78
|
+
throw new Error("ShopDiscount需要 request 插件支持");
|
|
79
|
+
}
|
|
80
|
+
if (!this.window) {
|
|
81
|
+
throw new Error("ShopDiscount需要 window 插件支持");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
registerDependentModules() {
|
|
85
|
+
var _a, _b, _c, _d;
|
|
86
|
+
const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
|
|
87
|
+
this.core.registerModule(discount, {
|
|
88
|
+
hooks: (_b = (_a = this.options.otherParams) == null ? void 0 : _a.discount) == null ? void 0 : _b.hooks
|
|
89
|
+
});
|
|
90
|
+
this.store.discount = discount;
|
|
91
|
+
const rules = new import_Rules.RulesModule(`${this.name}_rules`);
|
|
92
|
+
this.core.registerModule(rules, {
|
|
93
|
+
hooks: (_d = (_c = this.options.otherParams) == null ? void 0 : _c.rules) == null ? void 0 : _d.hooks
|
|
94
|
+
});
|
|
95
|
+
this.store.rules = rules;
|
|
96
|
+
}
|
|
97
|
+
registerEventListeners() {
|
|
98
|
+
this.core.effects.on(
|
|
99
|
+
import_types.ShopDiscountHooks.onCustomerChange,
|
|
100
|
+
(customer) => {
|
|
101
|
+
this.loadPrepareConfig({
|
|
102
|
+
customerId: customer.id,
|
|
103
|
+
action: "create",
|
|
104
|
+
with_good_pass: 1
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
// =========== 公共 API ===========
|
|
110
|
+
// 设置客户
|
|
111
|
+
async setCustomer(customer) {
|
|
112
|
+
var _a;
|
|
113
|
+
if (((_a = this.store.customer) == null ? void 0 : _a.id) !== customer.id) {
|
|
114
|
+
this.store.customer = customer;
|
|
115
|
+
await this.core.effects.emit(
|
|
116
|
+
import_types.ShopDiscountHooks.onCustomerChange,
|
|
117
|
+
customer
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// 计算优惠券
|
|
122
|
+
calcDiscount(productList, options) {
|
|
123
|
+
const rulesModule = this.core.getModule(`${this.name}_rules`);
|
|
124
|
+
if (!rulesModule) {
|
|
125
|
+
return { productList, discountList: this.getDiscountList() };
|
|
126
|
+
}
|
|
127
|
+
const { productList: newProductList, discountList: newDiscountList } = rulesModule.calcDiscount(
|
|
128
|
+
{
|
|
129
|
+
productList,
|
|
130
|
+
discountList: this.getDiscountList()
|
|
131
|
+
},
|
|
132
|
+
options
|
|
133
|
+
) || { productList, discountList: this.getDiscountList() };
|
|
134
|
+
if (newDiscountList) {
|
|
135
|
+
this.setDiscountList(newDiscountList);
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
productList: newProductList || productList,
|
|
139
|
+
discountList: newDiscountList || this.getDiscountList()
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
// 设置优惠券使用状态
|
|
143
|
+
setDiscountSelected({
|
|
144
|
+
discountId,
|
|
145
|
+
isSelected
|
|
146
|
+
}) {
|
|
147
|
+
const discountList = this.getDiscountList();
|
|
148
|
+
const newDiscountList = discountList.map((discount) => {
|
|
149
|
+
if (discount.id === discountId) {
|
|
150
|
+
return {
|
|
151
|
+
...discount,
|
|
152
|
+
isSelected,
|
|
153
|
+
// 手动设置不使用
|
|
154
|
+
isManualSelect: !isSelected,
|
|
155
|
+
isUsed: isSelected
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return discount;
|
|
159
|
+
});
|
|
160
|
+
this.setDiscountList(newDiscountList);
|
|
161
|
+
return this.calcDiscount(this.store.productList || [], {
|
|
162
|
+
discountId,
|
|
163
|
+
isSelected
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
setProductList(productList) {
|
|
167
|
+
this.store.productList = productList;
|
|
168
|
+
}
|
|
169
|
+
// 扫码输入code
|
|
170
|
+
async scanCode(code) {
|
|
171
|
+
var _a;
|
|
172
|
+
try {
|
|
173
|
+
const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code)) || [];
|
|
174
|
+
const rulesModule = this.store.rules;
|
|
175
|
+
if (!rulesModule) {
|
|
176
|
+
return {
|
|
177
|
+
isAvailable: false,
|
|
178
|
+
productList: this.store.productList || [],
|
|
179
|
+
discountList: this.getDiscountList()
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const {
|
|
183
|
+
productList: newProductList,
|
|
184
|
+
discountList: newDiscountList,
|
|
185
|
+
isAvailable
|
|
186
|
+
} = rulesModule.isDiscountListAvailable({
|
|
187
|
+
productList: this.store.productList || [],
|
|
188
|
+
oldDiscountList: this.getDiscountList(),
|
|
189
|
+
newDiscountList: resultDiscountList
|
|
190
|
+
}) || {
|
|
191
|
+
isAvailable: false,
|
|
192
|
+
productList: this.store.productList || [],
|
|
193
|
+
discountList: this.getDiscountList()
|
|
194
|
+
};
|
|
195
|
+
if (isAvailable) {
|
|
196
|
+
this.setDiscountList(newDiscountList || []);
|
|
197
|
+
this.setProductList(newProductList || []);
|
|
198
|
+
if (this.isWalkIn() && resultDiscountList.length) {
|
|
199
|
+
await this.getCustomerWallet(
|
|
200
|
+
resultDiscountList[0].customer_id
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
isAvailable: isAvailable || false,
|
|
206
|
+
productList: newProductList || this.store.productList || [],
|
|
207
|
+
discountList: newDiscountList || this.getDiscountList()
|
|
208
|
+
};
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error("[ShopDiscount] 扫码出错:", error);
|
|
211
|
+
return {
|
|
212
|
+
isAvailable: false,
|
|
213
|
+
productList: this.store.productList || [],
|
|
214
|
+
discountList: this.getDiscountList()
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
calcDiscountApplicableProductTotalPrice(discount) {
|
|
219
|
+
var _a;
|
|
220
|
+
return (_a = this.store.discount) == null ? void 0 : _a.calcDiscountApplicableProductTotalPrice(
|
|
221
|
+
discount
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
// =========== 私有辅助方法 ===========
|
|
225
|
+
// 获取客户
|
|
226
|
+
getCustomer() {
|
|
227
|
+
return this.store.customer;
|
|
228
|
+
}
|
|
229
|
+
// 是否是walkIn
|
|
230
|
+
isWalkIn() {
|
|
231
|
+
var _a;
|
|
232
|
+
return (((_a = this.getCustomer()) == null ? void 0 : _a.id) || 1) === 1;
|
|
233
|
+
}
|
|
234
|
+
// 触发优惠列表变更事件
|
|
235
|
+
async emitDiscountListChange(discountList) {
|
|
236
|
+
await this.core.effects.emit(
|
|
237
|
+
import_types.ShopDiscountHooks.onDiscountListChange,
|
|
238
|
+
discountList
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
// 设置优惠券列表
|
|
242
|
+
async setDiscountList(discountList) {
|
|
243
|
+
var _a;
|
|
244
|
+
const productList = this.store.productList || [];
|
|
245
|
+
const editModeDiscountList = [];
|
|
246
|
+
productList.forEach((item) => {
|
|
247
|
+
if (item.booking_id) {
|
|
248
|
+
editModeDiscountList.push(...(item.discount_list || []).map((item2) => {
|
|
249
|
+
return {
|
|
250
|
+
...item2,
|
|
251
|
+
isEditMode: true,
|
|
252
|
+
limited_relation_product_data: {},
|
|
253
|
+
savedAmount: item2.amount,
|
|
254
|
+
isAvailable: true,
|
|
255
|
+
id: item2.discount.resource_id,
|
|
256
|
+
format_title: item2.discount.title,
|
|
257
|
+
isDisabled: true,
|
|
258
|
+
isSelected: true,
|
|
259
|
+
product_id: item2.discount.product_id
|
|
260
|
+
};
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
const newDiscountList = (0, import_utils.uniqueById)([...editModeDiscountList, ...discountList], "product_id");
|
|
265
|
+
(_a = this.store.discount) == null ? void 0 : _a.setDiscountList(newDiscountList);
|
|
266
|
+
await this.emitDiscountListChange(newDiscountList);
|
|
267
|
+
}
|
|
268
|
+
// 获取优惠券列表
|
|
269
|
+
getDiscountList() {
|
|
270
|
+
var _a;
|
|
271
|
+
return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
272
|
+
}
|
|
273
|
+
// 获取客户钱包信息
|
|
274
|
+
async getCustomerWallet(id) {
|
|
275
|
+
try {
|
|
276
|
+
const result = await this.request.get(`/customer/info/wallet/${id}`, {
|
|
277
|
+
wallet_pass_tags: ["good_pass"]
|
|
278
|
+
});
|
|
279
|
+
if (result == null ? void 0 : result.data) {
|
|
280
|
+
const { wallet_pass_list, ...customer } = result.data;
|
|
281
|
+
this.setCustomer(customer);
|
|
282
|
+
}
|
|
283
|
+
} catch (error) {
|
|
284
|
+
console.error("[ShopDiscount] 获取客户钱包信息出错:", error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// 加载准备配置
|
|
288
|
+
async loadPrepareConfig(params) {
|
|
289
|
+
var _a, _b, _c;
|
|
290
|
+
try {
|
|
291
|
+
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
292
|
+
if (customerId === 1 || !customerId) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
296
|
+
customer_id: customerId,
|
|
297
|
+
action: "create",
|
|
298
|
+
with_good_pass: 1
|
|
299
|
+
}));
|
|
300
|
+
this.setDiscountList(goodPassList || []);
|
|
301
|
+
if ((_c = this.store.productList) == null ? void 0 : _c.length) {
|
|
302
|
+
const result = this.calcDiscount(this.store.productList);
|
|
303
|
+
await this.core.effects.emit(
|
|
304
|
+
import_types.ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
305
|
+
result
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
await this.core.effects.emit(
|
|
309
|
+
import_types.ShopDiscountHooks.onLoadDiscountList,
|
|
310
|
+
goodPassList
|
|
311
|
+
);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
console.error("[ShopDiscount] 加载准备配置出错:", error);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var ShopDiscount_default = ShopDiscountImpl;
|
|
318
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
319
|
+
0 && (module.exports = {
|
|
320
|
+
ShopDiscountImpl
|
|
321
|
+
});
|