@pisell/pisellos 1.0.85 → 1.0.87
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/Discount/index.d.ts +2 -0
- package/dist/modules/Discount/index.js +67 -35
- package/dist/modules/Discount/types.d.ts +5 -0
- package/dist/modules/Rules/index.js +53 -11
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +1 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +73 -15
- package/dist/solution/ShopDiscount/types.d.ts +4 -1
- package/dist/solution/ShopDiscount/utils.d.ts +48 -0
- package/dist/solution/ShopDiscount/utils.js +401 -2
- package/lib/modules/Discount/index.d.ts +2 -0
- package/lib/modules/Discount/index.js +17 -3
- package/lib/modules/Discount/types.d.ts +5 -0
- package/lib/modules/Rules/index.js +40 -3
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +4 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +49 -5
- package/lib/solution/ShopDiscount/types.d.ts +4 -1
- package/lib/solution/ShopDiscount/utils.d.ts +48 -0
- package/lib/solution/ShopDiscount/utils.js +240 -0
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
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; }
|
|
1
4
|
import Decimal from "decimal.js";
|
|
5
|
+
import dayjs from "dayjs";
|
|
2
6
|
export var uniqueById = function uniqueById(arr) {
|
|
3
7
|
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
|
|
4
8
|
var seen = new Set();
|
|
@@ -7,6 +11,19 @@ export var uniqueById = function uniqueById(arr) {
|
|
|
7
11
|
});
|
|
8
12
|
};
|
|
9
13
|
|
|
14
|
+
// 非预约商品 通过时长和日程判断是否是普通商品
|
|
15
|
+
export var isNormalProductByDurationSchedule = function isNormalProductByDurationSchedule(item) {
|
|
16
|
+
var _item$schedules, _item$scheduleIds;
|
|
17
|
+
return !(item !== null && item !== void 0 && item.duration) && !(item !== null && item !== void 0 && (_item$schedules = item.schedules) !== null && _item$schedules !== void 0 && _item$schedules.length) && !(item !== null && item !== void 0 && (_item$scheduleIds = item['schedule.ids']) !== null && _item$scheduleIds !== void 0 && _item$scheduleIds.length);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// 是否全部是普通商品
|
|
21
|
+
export var isAllNormalProduct = function isAllNormalProduct(items) {
|
|
22
|
+
return items.every(function (item) {
|
|
23
|
+
return isNormalProductByDurationSchedule(item);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
10
27
|
/**
|
|
11
28
|
* 获取折扣金额 基于折扣卡类型计算
|
|
12
29
|
* 商品券:直接返回商品价格
|
|
@@ -42,11 +59,393 @@ export var getDiscountListAmountTotal = function getDiscountListAmountTotal(disc
|
|
|
42
59
|
|
|
43
60
|
/**
|
|
44
61
|
* 获取折扣金额 计算每个折扣的金额
|
|
45
|
-
* @param discount
|
|
46
|
-
* @returns
|
|
62
|
+
* @param discount
|
|
63
|
+
* @returns
|
|
47
64
|
*/
|
|
48
65
|
export var getDiscountListAmount = function getDiscountListAmount(discount) {
|
|
49
66
|
return discount.reduce(function (acc, cur) {
|
|
50
67
|
return new Decimal(acc).plus(new Decimal(cur.amount || 0)).toNumber();
|
|
51
68
|
}, new Decimal(0));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// 日程项接口定义
|
|
72
|
+
|
|
73
|
+
// 获取时间是否在日程范围内
|
|
74
|
+
export var getDateIsInSchedule = function getDateIsInSchedule(dateTime, scheduleList) {
|
|
75
|
+
if (!dateTime || !scheduleList || scheduleList.length === 0) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
var targetDate = dayjs(dateTime);
|
|
79
|
+
if (!targetDate.isValid()) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 遍历所有日程项
|
|
84
|
+
var _iterator = _createForOfIteratorHelper(scheduleList),
|
|
85
|
+
_step;
|
|
86
|
+
try {
|
|
87
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
88
|
+
var schedule = _step.value;
|
|
89
|
+
if (isTimeInScheduleItem(dateTime, schedule)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
_iterator.e(err);
|
|
95
|
+
} finally {
|
|
96
|
+
_iterator.f();
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// 判断时间是否在单个日程项范围内
|
|
102
|
+
var isTimeInScheduleItem = function isTimeInScheduleItem(dateTime, schedule) {
|
|
103
|
+
var targetDate = dayjs(dateTime);
|
|
104
|
+
var targetDateString = dateTime.split(' ')[0]; // YYYY-MM-DD
|
|
105
|
+
var targetTimeString = dateTime.split(' ')[1] || '00:00:00'; // HH:mm:ss
|
|
106
|
+
|
|
107
|
+
switch (schedule.type) {
|
|
108
|
+
case 'standard':
|
|
109
|
+
return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
110
|
+
case 'time-slots':
|
|
111
|
+
return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
112
|
+
case 'designation':
|
|
113
|
+
return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// 处理标准类型日程
|
|
120
|
+
var isInStandardSchedule = function isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
121
|
+
if (!schedule.start_time || !schedule.end_time) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
var startDate = dayjs(schedule.start_time);
|
|
125
|
+
var endDate = dayjs(schedule.end_time);
|
|
126
|
+
|
|
127
|
+
// 先检查是否在基础时间范围内(不考虑重复)
|
|
128
|
+
var isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
|
|
129
|
+
if (schedule.repeat_type === 'none') {
|
|
130
|
+
return isInBasicRange;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 处理重复日程
|
|
134
|
+
return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// 处理时间段类型日程
|
|
138
|
+
var isInTimeSlotsSchedule = function isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
139
|
+
if (!schedule.start_time) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 如果不重复,使用原有逻辑
|
|
144
|
+
if (schedule.repeat_type === 'none') {
|
|
145
|
+
var scheduleDate = schedule.start_time.split(' ')[0];
|
|
146
|
+
|
|
147
|
+
// 检查日期是否匹配
|
|
148
|
+
if (targetDateString !== scheduleDate) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 检查是否在任一时间段内
|
|
153
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 处理重复日程
|
|
157
|
+
return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// 处理指定类型日程
|
|
161
|
+
var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
162
|
+
if (!schedule.designation) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
var _iterator2 = _createForOfIteratorHelper(schedule.designation),
|
|
166
|
+
_step2;
|
|
167
|
+
try {
|
|
168
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
169
|
+
var designation = _step2.value;
|
|
170
|
+
var startDateTime = "".concat(designation.start_date, " ").concat(designation.start_time, ":00");
|
|
171
|
+
var endDateTime = "".concat(designation.end_date, " ").concat(designation.end_time, ":00");
|
|
172
|
+
var startDate = dayjs(startDateTime);
|
|
173
|
+
var endDate = dayjs(endDateTime);
|
|
174
|
+
if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
_iterator2.e(err);
|
|
180
|
+
} finally {
|
|
181
|
+
_iterator2.f();
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// 处理重复日程逻辑
|
|
187
|
+
var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) {
|
|
188
|
+
if (!schedule.repeat_rule) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
var repeat_rule = schedule.repeat_rule,
|
|
192
|
+
repeat_type = schedule.repeat_type;
|
|
193
|
+
var targetDateOnly = dayjs(targetDateString); // 只取日期部分
|
|
194
|
+
|
|
195
|
+
// 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
|
|
196
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
197
|
+
var _iterator3 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
198
|
+
_step3;
|
|
199
|
+
try {
|
|
200
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
201
|
+
var includedDate = _step3.value;
|
|
202
|
+
var includeStartDate = dayjs(includedDate.start);
|
|
203
|
+
var includeEndDate = dayjs(includedDate.end);
|
|
204
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
205
|
+
// 在包含日期中,直接返回true,无需检查其他条件
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
} catch (err) {
|
|
210
|
+
_iterator3.e(err);
|
|
211
|
+
} finally {
|
|
212
|
+
_iterator3.f();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 检查是否在排除日期中
|
|
217
|
+
var _iterator4 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
218
|
+
_step4;
|
|
219
|
+
try {
|
|
220
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
221
|
+
var excludedDate = _step4.value;
|
|
222
|
+
var excludeStartDate = dayjs(excludedDate.start);
|
|
223
|
+
var excludeEndDate = dayjs(excludedDate.end);
|
|
224
|
+
// 检查目标日期是否在排除范围内(包含边界)
|
|
225
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// 检查重复规则的结束条件
|
|
231
|
+
} catch (err) {
|
|
232
|
+
_iterator4.e(err);
|
|
233
|
+
} finally {
|
|
234
|
+
_iterator4.f();
|
|
235
|
+
}
|
|
236
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
237
|
+
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
238
|
+
if (targetDate.isAfter(ruleEndDate)) {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 根据重复类型检查
|
|
244
|
+
switch (repeat_type) {
|
|
245
|
+
case 'daily':
|
|
246
|
+
return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
247
|
+
case 'weekly':
|
|
248
|
+
return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
249
|
+
default:
|
|
250
|
+
return false;
|
|
251
|
+
// 不支持月和年重复
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// 每日重复逻辑
|
|
256
|
+
var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
257
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
258
|
+
if (daysDiff < 0) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// 检查频率
|
|
263
|
+
if (daysDiff % repeatRule.frequency !== 0) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// 检查时间是否在日程的时间范围内
|
|
268
|
+
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
269
|
+
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
270
|
+
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
271
|
+
|
|
272
|
+
// 每日重复:每天都在相同的时间段内有效
|
|
273
|
+
// 例如:01:00:00 - 16:00:00,每天都是这个时间段
|
|
274
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// 每周重复逻辑
|
|
278
|
+
var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
279
|
+
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
280
|
+
|
|
281
|
+
// 检查是否在指定的星期几内
|
|
282
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// 计算周差
|
|
287
|
+
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
288
|
+
if (weeksDiff < 0) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 检查频率
|
|
293
|
+
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 检查时间是否在日程的时间范围内
|
|
298
|
+
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
299
|
+
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
300
|
+
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
301
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// 处理 time-slots 类型的重复日程
|
|
305
|
+
var isInTimeSlotsRepeatingSchedule = function isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
306
|
+
if (!schedule.repeat_rule || !schedule.start_time) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
var repeat_rule = schedule.repeat_rule,
|
|
310
|
+
repeat_type = schedule.repeat_type;
|
|
311
|
+
var startDate = dayjs(schedule.start_time);
|
|
312
|
+
var targetDateOnly = dayjs(targetDateString);
|
|
313
|
+
|
|
314
|
+
// 检查包含日期
|
|
315
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
316
|
+
var _iterator5 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
317
|
+
_step5;
|
|
318
|
+
try {
|
|
319
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
320
|
+
var includedDate = _step5.value;
|
|
321
|
+
var includeStartDate = dayjs(includedDate.start);
|
|
322
|
+
var includeEndDate = dayjs(includedDate.end);
|
|
323
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
324
|
+
// 在包含日期中,检查时间段
|
|
325
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} catch (err) {
|
|
329
|
+
_iterator5.e(err);
|
|
330
|
+
} finally {
|
|
331
|
+
_iterator5.f();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// 检查排除日期
|
|
336
|
+
var _iterator6 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
337
|
+
_step6;
|
|
338
|
+
try {
|
|
339
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
340
|
+
var excludedDate = _step6.value;
|
|
341
|
+
var excludeStartDate = dayjs(excludedDate.start);
|
|
342
|
+
var excludeEndDate = dayjs(excludedDate.end);
|
|
343
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// 检查重复规则的结束条件
|
|
349
|
+
} catch (err) {
|
|
350
|
+
_iterator6.e(err);
|
|
351
|
+
} finally {
|
|
352
|
+
_iterator6.f();
|
|
353
|
+
}
|
|
354
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
355
|
+
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
356
|
+
if (targetDateOnly.isAfter(ruleEndDate, 'day')) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// 检查目标日期是否在重复规则范围内
|
|
362
|
+
var isDateValid = false;
|
|
363
|
+
switch (repeat_type) {
|
|
364
|
+
case 'daily':
|
|
365
|
+
isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
366
|
+
break;
|
|
367
|
+
case 'weekly':
|
|
368
|
+
isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
369
|
+
break;
|
|
370
|
+
default:
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 如果日期有效,检查时间段
|
|
375
|
+
if (isDateValid) {
|
|
376
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// 检查目标时间是否在某个时间段内(使用目标日期 + time_slot 时间)
|
|
382
|
+
var checkTimeSlotsForDate = function checkTimeSlotsForDate(targetDate, targetDateString, timeSlots) {
|
|
383
|
+
var _iterator7 = _createForOfIteratorHelper(timeSlots),
|
|
384
|
+
_step7;
|
|
385
|
+
try {
|
|
386
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
387
|
+
var timeSlot = _step7.value;
|
|
388
|
+
var slotStart = "".concat(targetDateString, " ").concat(timeSlot.start_time, ":00");
|
|
389
|
+
var slotEnd = "".concat(targetDateString, " ").concat(timeSlot.end_time, ":00");
|
|
390
|
+
var slotStartDate = dayjs(slotStart);
|
|
391
|
+
var slotEndDate = dayjs(slotEnd);
|
|
392
|
+
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
} catch (err) {
|
|
397
|
+
_iterator7.e(err);
|
|
398
|
+
} finally {
|
|
399
|
+
_iterator7.f();
|
|
400
|
+
}
|
|
401
|
+
return false;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// 检查日期是否满足每日重复规则(只检查日期,不检查时间)
|
|
405
|
+
var isInDailyRepeatForDate = function isInDailyRepeatForDate(targetDate, startDate, repeatRule) {
|
|
406
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
407
|
+
if (daysDiff < 0) {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// 检查频率
|
|
412
|
+
return daysDiff % repeatRule.frequency === 0;
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// 检查日期是否满足每周重复规则(只检查日期,不检查时间)
|
|
416
|
+
var isInWeeklyRepeatForDate = function isInWeeklyRepeatForDate(targetDate, startDate, repeatRule) {
|
|
417
|
+
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
418
|
+
|
|
419
|
+
// 检查是否在指定的星期几内
|
|
420
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// 计算周差
|
|
425
|
+
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
426
|
+
if (weeksDiff < 0) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 检查频率
|
|
431
|
+
return weeksDiff % repeatRule.frequency === 0;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* 根据预约时间过滤优惠券列表
|
|
436
|
+
* @param discountList 优惠券列表
|
|
437
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
438
|
+
* @returns 过滤后的优惠券列表
|
|
439
|
+
*/
|
|
440
|
+
export var filterDiscountListByBookingTime = function filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
441
|
+
if (!bookingTime) {
|
|
442
|
+
return discountList;
|
|
443
|
+
}
|
|
444
|
+
return discountList.filter(function (discount) {
|
|
445
|
+
var _discount$metadata2, _discount$metadata3, _discount$custom_sche;
|
|
446
|
+
if (!(discount !== null && discount !== void 0 && (_discount$metadata2 = discount.metadata) !== null && _discount$metadata2 !== void 0 && _discount$metadata2.validity_type) || (discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.validity_type) === "fixed_validity") {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
|
|
450
|
+
});
|
|
52
451
|
};
|
|
@@ -14,6 +14,8 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
|
|
|
14
14
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
15
15
|
setDiscountList(discountList: Discount[]): Promise<void>;
|
|
16
16
|
getDiscountList(): Discount[];
|
|
17
|
+
setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
|
|
18
|
+
getOriginalDiscountList(): Discount[];
|
|
17
19
|
loadPrepareConfig(params: {
|
|
18
20
|
action?: 'create';
|
|
19
21
|
with_good_pass: 0 | 1;
|
|
@@ -44,7 +44,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
44
44
|
this.openCache = false;
|
|
45
45
|
}
|
|
46
46
|
async initialize(core, options) {
|
|
47
|
-
var _a, _b, _c;
|
|
47
|
+
var _a, _b, _c, _d;
|
|
48
48
|
this.core = core;
|
|
49
49
|
this.store = options == null ? void 0 : options.store;
|
|
50
50
|
if (Array.isArray((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.discountList)) {
|
|
@@ -52,11 +52,16 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
52
52
|
} else {
|
|
53
53
|
this.store.discountList = [];
|
|
54
54
|
}
|
|
55
|
-
if ((_b = options == null ? void 0 : options.
|
|
55
|
+
if (Array.isArray((_b = options == null ? void 0 : options.initialState) == null ? void 0 : _b.originalDiscountList)) {
|
|
56
|
+
this.store.originalDiscountList = options == null ? void 0 : options.initialState.originalDiscountList;
|
|
57
|
+
} else {
|
|
58
|
+
this.store.originalDiscountList = [];
|
|
59
|
+
}
|
|
60
|
+
if ((_c = options == null ? void 0 : options.otherParams) == null ? void 0 : _c.cacheId) {
|
|
56
61
|
this.openCache = options.otherParams.openCache;
|
|
57
62
|
this.cacheId = options.otherParams.cacheId;
|
|
58
63
|
}
|
|
59
|
-
if ((
|
|
64
|
+
if ((_d = options == null ? void 0 : options.otherParams) == null ? void 0 : _d.fatherModule) {
|
|
60
65
|
this.fatherModule = options.otherParams.fatherModule;
|
|
61
66
|
}
|
|
62
67
|
this.request = core.getPlugin("request");
|
|
@@ -78,6 +83,14 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
78
83
|
getDiscountList() {
|
|
79
84
|
return this.store.discountList;
|
|
80
85
|
}
|
|
86
|
+
// 设置原始优惠券列表
|
|
87
|
+
async setOriginalDiscountList(originalDiscountList) {
|
|
88
|
+
this.store.originalDiscountList = originalDiscountList;
|
|
89
|
+
}
|
|
90
|
+
// 获取原始优惠券列表
|
|
91
|
+
getOriginalDiscountList() {
|
|
92
|
+
return this.store.originalDiscountList || [];
|
|
93
|
+
}
|
|
81
94
|
async loadPrepareConfig(params) {
|
|
82
95
|
var _a, _b;
|
|
83
96
|
const prepareConfig = await this.request.post(
|
|
@@ -177,6 +190,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
177
190
|
}
|
|
178
191
|
async clear() {
|
|
179
192
|
this.store.discountList = [];
|
|
193
|
+
this.store.originalDiscountList = [];
|
|
180
194
|
console.log("[Discount] clear");
|
|
181
195
|
}
|
|
182
196
|
storeChange() {
|
|
@@ -80,6 +80,7 @@ export interface Discount {
|
|
|
80
80
|
metadata?: {
|
|
81
81
|
discount_card_type?: 'fixed_amount' | 'percent';
|
|
82
82
|
custom_product_bundle_map_id?: string;
|
|
83
|
+
validity_type?: "custom_schedule_validity" | "fixed_validity";
|
|
83
84
|
};
|
|
84
85
|
product: Product;
|
|
85
86
|
type: "product" | 'good_pass';
|
|
@@ -107,9 +108,13 @@ export interface Discount {
|
|
|
107
108
|
month_order_behavior_count?: number;
|
|
108
109
|
customer_order_behavior_count?: number;
|
|
109
110
|
num?: number;
|
|
111
|
+
custom_schedule_snapshot?: {
|
|
112
|
+
data: any[];
|
|
113
|
+
};
|
|
110
114
|
}
|
|
111
115
|
export interface DiscountState {
|
|
112
116
|
discountList: Discount[];
|
|
117
|
+
originalDiscountList?: Discount[];
|
|
113
118
|
}
|
|
114
119
|
export interface DiscountModuleAPI {
|
|
115
120
|
setDiscountList: (discountList: Discount[]) => Promise<void>;
|
|
@@ -38,6 +38,7 @@ var import_utils = require("../../solution/ShopDiscount/utils");
|
|
|
38
38
|
var import_utils2 = require("../Cart/utils");
|
|
39
39
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
40
|
var import_lodash_es = require("lodash-es");
|
|
41
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
41
42
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
42
43
|
constructor(name, version) {
|
|
43
44
|
super(name, version);
|
|
@@ -267,10 +268,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
267
268
|
addModeDiscount.forEach((discount) => {
|
|
268
269
|
var _a, _b, _c, _d, _e, _f;
|
|
269
270
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
271
|
+
let timeLimit = true;
|
|
272
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
270
273
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
271
274
|
const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
|
|
272
275
|
const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
|
|
273
|
-
if (isAvailableProduct && isLimitedProduct && isBundleAvailable) {
|
|
276
|
+
if (isAvailableProduct && isLimitedProduct && isBundleAvailable && timeLimit) {
|
|
274
277
|
(_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
|
|
275
278
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
276
279
|
const discountType = discount.tag || discount.type;
|
|
@@ -344,6 +347,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
344
347
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
345
348
|
return false;
|
|
346
349
|
const limitedData = discount.limited_relation_product_data;
|
|
350
|
+
let timeLimit = true;
|
|
351
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
352
|
+
if (!timeLimit) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
347
355
|
if (limitedData.type === "product_all") {
|
|
348
356
|
if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
349
357
|
return false;
|
|
@@ -524,6 +532,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
524
532
|
};
|
|
525
533
|
appliedProducts.push(discountDetail);
|
|
526
534
|
appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
|
|
535
|
+
let total = targetProductTotal;
|
|
536
|
+
if (product.options) {
|
|
537
|
+
total = product.options.reduce((accumulator, currentValue) => {
|
|
538
|
+
const currentPrice = new import_decimal.default(currentValue.price || 0);
|
|
539
|
+
const currentNum = new import_decimal.default(currentValue.num || 0);
|
|
540
|
+
return accumulator.add(currentPrice.mul(currentNum));
|
|
541
|
+
}, new import_decimal.default(total)).toNumber();
|
|
542
|
+
}
|
|
527
543
|
if (product.isClient) {
|
|
528
544
|
debugger;
|
|
529
545
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
@@ -539,7 +555,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
539
555
|
}),
|
|
540
556
|
variant: originProduct._productInit.variant,
|
|
541
557
|
original_price: new import_decimal.default(product.price || 0).toNumber(),
|
|
542
|
-
total
|
|
558
|
+
total
|
|
543
559
|
}));
|
|
544
560
|
} else {
|
|
545
561
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
@@ -547,7 +563,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
547
563
|
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
|
|
548
564
|
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
549
565
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
550
|
-
total
|
|
566
|
+
total,
|
|
551
567
|
origin_total: productOriginTotal,
|
|
552
568
|
main_product_selling_price: targetProductTotal
|
|
553
569
|
}));
|
|
@@ -810,6 +826,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
810
826
|
newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
|
|
811
827
|
});
|
|
812
828
|
}
|
|
829
|
+
if (product == null ? void 0 : product.options) {
|
|
830
|
+
newTotalWithDiscount = product.options.reduce((accumulator, currentValue) => {
|
|
831
|
+
const currentPrice = new import_decimal.default(currentValue.price || 0);
|
|
832
|
+
const currentNum = new import_decimal.default(currentValue.num || 0);
|
|
833
|
+
return accumulator.add(currentPrice.mul(currentNum));
|
|
834
|
+
}, new import_decimal.default(newTotalWithDiscount)).toNumber();
|
|
835
|
+
}
|
|
813
836
|
result.push(
|
|
814
837
|
this.hooks.setProduct(mainProduct, {
|
|
815
838
|
...mainProductData,
|
|
@@ -860,6 +883,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
860
883
|
newOriginTotalOriginal += Number(item.price) * Number(item.num);
|
|
861
884
|
});
|
|
862
885
|
}
|
|
886
|
+
if (product == null ? void 0 : product.options) {
|
|
887
|
+
newTotalOriginal = product.options.reduce((accumulator, currentValue) => {
|
|
888
|
+
const currentPrice = new import_decimal.default(currentValue.price || 0);
|
|
889
|
+
const currentNum = new import_decimal.default(currentValue.num || 0);
|
|
890
|
+
return accumulator.add(currentPrice.mul(currentNum));
|
|
891
|
+
}, new import_decimal.default(newTotalOriginal)).toNumber();
|
|
892
|
+
}
|
|
863
893
|
result.push(
|
|
864
894
|
this.hooks.setProduct(mainProduct, {
|
|
865
895
|
...mainProductData,
|
|
@@ -935,6 +965,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
935
965
|
});
|
|
936
966
|
}
|
|
937
967
|
}
|
|
968
|
+
if (product == null ? void 0 : product.options) {
|
|
969
|
+
newTotal = product.options.reduce((accumulator, currentValue) => {
|
|
970
|
+
const currentPrice = new import_decimal.default(currentValue.price || 0);
|
|
971
|
+
const currentNum = new import_decimal.default(currentValue.num || 0);
|
|
972
|
+
return accumulator.add(currentPrice.mul(currentNum));
|
|
973
|
+
}, new import_decimal.default(newTotal)).toNumber();
|
|
974
|
+
}
|
|
938
975
|
result.push(
|
|
939
976
|
this.hooks.setProduct(mainProduct, {
|
|
940
977
|
...mainProductData,
|
|
@@ -1609,6 +1609,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1609
1609
|
}
|
|
1610
1610
|
});
|
|
1611
1611
|
});
|
|
1612
|
+
this.core.effects.emit(
|
|
1613
|
+
`${this.store.cart.name}:onUpdateBookingDate`,
|
|
1614
|
+
{}
|
|
1615
|
+
);
|
|
1612
1616
|
}
|
|
1613
1617
|
getScheduleDataByIds(scheduleIds) {
|
|
1614
1618
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
@@ -18,6 +18,8 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
18
18
|
private initializePlugins;
|
|
19
19
|
private registerDependentModules;
|
|
20
20
|
private registerEventListeners;
|
|
21
|
+
getCurrentBookingTime(): string | null;
|
|
22
|
+
private filterDiscountListByBookingTime;
|
|
21
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
22
24
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
23
25
|
productList: Record<string, any>[];
|