@pisell/pisellos 2.1.44 → 2.1.46
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/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +8 -9
- package/dist/modules/Rules/index.js +10 -3
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/solution/BookingByStep/index.js +30 -8
- package/dist/solution/BookingByStep/utils/products.d.ts +6 -0
- package/dist/solution/BookingByStep/utils/products.js +10 -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 +399 -0
- 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/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +0 -7
- package/lib/modules/Rules/index.js +9 -1
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/solution/BookingByStep/index.js +19 -2
- package/lib/solution/BookingByStep/utils/products.d.ts +6 -0
- package/lib/solution/BookingByStep/utils/products.js +8 -2
- package/lib/solution/BookingTicket/index.js +0 -6
- 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
|
* 商品券:直接返回商品价格
|
|
@@ -33,4 +50,386 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
|
|
|
33
50
|
|
|
34
51
|
// 百分比:根据折扣卡金额计算
|
|
35
52
|
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 日程项接口定义
|
|
56
|
+
|
|
57
|
+
// 获取时间是否在日程范围内
|
|
58
|
+
export var getDateIsInSchedule = function getDateIsInSchedule(dateTime, scheduleList) {
|
|
59
|
+
if (!dateTime || !scheduleList || scheduleList.length === 0) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
var targetDate = dayjs(dateTime);
|
|
63
|
+
if (!targetDate.isValid()) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 遍历所有日程项
|
|
68
|
+
var _iterator = _createForOfIteratorHelper(scheduleList),
|
|
69
|
+
_step;
|
|
70
|
+
try {
|
|
71
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
|
+
var schedule = _step.value;
|
|
73
|
+
if (isTimeInScheduleItem(dateTime, schedule)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
_iterator.e(err);
|
|
79
|
+
} finally {
|
|
80
|
+
_iterator.f();
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// 判断时间是否在单个日程项范围内
|
|
86
|
+
var isTimeInScheduleItem = function isTimeInScheduleItem(dateTime, schedule) {
|
|
87
|
+
var targetDate = dayjs(dateTime);
|
|
88
|
+
var targetDateString = dateTime.split(' ')[0]; // YYYY-MM-DD
|
|
89
|
+
var targetTimeString = dateTime.split(' ')[1] || '00:00:00'; // HH:mm:ss
|
|
90
|
+
|
|
91
|
+
switch (schedule.type) {
|
|
92
|
+
case 'standard':
|
|
93
|
+
return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
94
|
+
case 'time-slots':
|
|
95
|
+
return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
96
|
+
case 'designation':
|
|
97
|
+
return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
98
|
+
default:
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 处理标准类型日程
|
|
104
|
+
var isInStandardSchedule = function isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
105
|
+
if (!schedule.start_time || !schedule.end_time) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
var startDate = dayjs(schedule.start_time);
|
|
109
|
+
var endDate = dayjs(schedule.end_time);
|
|
110
|
+
|
|
111
|
+
// 先检查是否在基础时间范围内(不考虑重复)
|
|
112
|
+
var isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
|
|
113
|
+
if (schedule.repeat_type === 'none') {
|
|
114
|
+
return isInBasicRange;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 处理重复日程
|
|
118
|
+
return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// 处理时间段类型日程
|
|
122
|
+
var isInTimeSlotsSchedule = function isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
123
|
+
if (!schedule.start_time) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 如果不重复,使用原有逻辑
|
|
128
|
+
if (schedule.repeat_type === 'none') {
|
|
129
|
+
var scheduleDate = schedule.start_time.split(' ')[0];
|
|
130
|
+
|
|
131
|
+
// 检查日期是否匹配
|
|
132
|
+
if (targetDateString !== scheduleDate) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 检查是否在任一时间段内
|
|
137
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// 处理重复日程
|
|
141
|
+
return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// 处理指定类型日程
|
|
145
|
+
var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
146
|
+
if (!schedule.designation) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
var _iterator2 = _createForOfIteratorHelper(schedule.designation),
|
|
150
|
+
_step2;
|
|
151
|
+
try {
|
|
152
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
153
|
+
var designation = _step2.value;
|
|
154
|
+
var startDateTime = "".concat(designation.start_date, " ").concat(designation.start_time, ":00");
|
|
155
|
+
var endDateTime = "".concat(designation.end_date, " ").concat(designation.end_time, ":00");
|
|
156
|
+
var startDate = dayjs(startDateTime);
|
|
157
|
+
var endDate = dayjs(endDateTime);
|
|
158
|
+
if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch (err) {
|
|
163
|
+
_iterator2.e(err);
|
|
164
|
+
} finally {
|
|
165
|
+
_iterator2.f();
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// 处理重复日程逻辑
|
|
171
|
+
var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) {
|
|
172
|
+
if (!schedule.repeat_rule) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
var repeat_rule = schedule.repeat_rule,
|
|
176
|
+
repeat_type = schedule.repeat_type;
|
|
177
|
+
var targetDateOnly = dayjs(targetDateString); // 只取日期部分
|
|
178
|
+
|
|
179
|
+
// 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
|
|
180
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
181
|
+
var _iterator3 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
182
|
+
_step3;
|
|
183
|
+
try {
|
|
184
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
185
|
+
var includedDate = _step3.value;
|
|
186
|
+
var includeStartDate = dayjs(includedDate.start);
|
|
187
|
+
var includeEndDate = dayjs(includedDate.end);
|
|
188
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
189
|
+
// 在包含日期中,直接返回true,无需检查其他条件
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
} catch (err) {
|
|
194
|
+
_iterator3.e(err);
|
|
195
|
+
} finally {
|
|
196
|
+
_iterator3.f();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 检查是否在排除日期中
|
|
201
|
+
var _iterator4 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
202
|
+
_step4;
|
|
203
|
+
try {
|
|
204
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
205
|
+
var excludedDate = _step4.value;
|
|
206
|
+
var excludeStartDate = dayjs(excludedDate.start);
|
|
207
|
+
var excludeEndDate = dayjs(excludedDate.end);
|
|
208
|
+
// 检查目标日期是否在排除范围内(包含边界)
|
|
209
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// 检查重复规则的结束条件
|
|
215
|
+
} catch (err) {
|
|
216
|
+
_iterator4.e(err);
|
|
217
|
+
} finally {
|
|
218
|
+
_iterator4.f();
|
|
219
|
+
}
|
|
220
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
221
|
+
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
222
|
+
if (targetDate.isAfter(ruleEndDate)) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 根据重复类型检查
|
|
228
|
+
switch (repeat_type) {
|
|
229
|
+
case 'daily':
|
|
230
|
+
return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
231
|
+
case 'weekly':
|
|
232
|
+
return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
233
|
+
default:
|
|
234
|
+
return false;
|
|
235
|
+
// 不支持月和年重复
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// 每日重复逻辑
|
|
240
|
+
var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
241
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
242
|
+
if (daysDiff < 0) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// 检查频率
|
|
247
|
+
if (daysDiff % repeatRule.frequency !== 0) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 检查时间是否在日程的时间范围内
|
|
252
|
+
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
253
|
+
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
254
|
+
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
255
|
+
|
|
256
|
+
// 每日重复:每天都在相同的时间段内有效
|
|
257
|
+
// 例如:01:00:00 - 16:00:00,每天都是这个时间段
|
|
258
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// 每周重复逻辑
|
|
262
|
+
var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
263
|
+
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
264
|
+
|
|
265
|
+
// 检查是否在指定的星期几内
|
|
266
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 计算周差
|
|
271
|
+
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
272
|
+
if (weeksDiff < 0) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// 检查频率
|
|
277
|
+
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 检查时间是否在日程的时间范围内
|
|
282
|
+
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
283
|
+
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
284
|
+
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
285
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// 处理 time-slots 类型的重复日程
|
|
289
|
+
var isInTimeSlotsRepeatingSchedule = function isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
290
|
+
if (!schedule.repeat_rule || !schedule.start_time) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
var repeat_rule = schedule.repeat_rule,
|
|
294
|
+
repeat_type = schedule.repeat_type;
|
|
295
|
+
var startDate = dayjs(schedule.start_time);
|
|
296
|
+
var targetDateOnly = dayjs(targetDateString);
|
|
297
|
+
|
|
298
|
+
// 检查包含日期
|
|
299
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
300
|
+
var _iterator5 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
301
|
+
_step5;
|
|
302
|
+
try {
|
|
303
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
304
|
+
var includedDate = _step5.value;
|
|
305
|
+
var includeStartDate = dayjs(includedDate.start);
|
|
306
|
+
var includeEndDate = dayjs(includedDate.end);
|
|
307
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
308
|
+
// 在包含日期中,检查时间段
|
|
309
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
} catch (err) {
|
|
313
|
+
_iterator5.e(err);
|
|
314
|
+
} finally {
|
|
315
|
+
_iterator5.f();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// 检查排除日期
|
|
320
|
+
var _iterator6 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
321
|
+
_step6;
|
|
322
|
+
try {
|
|
323
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
324
|
+
var excludedDate = _step6.value;
|
|
325
|
+
var excludeStartDate = dayjs(excludedDate.start);
|
|
326
|
+
var excludeEndDate = dayjs(excludedDate.end);
|
|
327
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// 检查重复规则的结束条件
|
|
333
|
+
} catch (err) {
|
|
334
|
+
_iterator6.e(err);
|
|
335
|
+
} finally {
|
|
336
|
+
_iterator6.f();
|
|
337
|
+
}
|
|
338
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
339
|
+
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
340
|
+
if (targetDateOnly.isAfter(ruleEndDate, 'day')) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// 检查目标日期是否在重复规则范围内
|
|
346
|
+
var isDateValid = false;
|
|
347
|
+
switch (repeat_type) {
|
|
348
|
+
case 'daily':
|
|
349
|
+
isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
350
|
+
break;
|
|
351
|
+
case 'weekly':
|
|
352
|
+
isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
353
|
+
break;
|
|
354
|
+
default:
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 如果日期有效,检查时间段
|
|
359
|
+
if (isDateValid) {
|
|
360
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
361
|
+
}
|
|
362
|
+
return false;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
// 检查目标时间是否在某个时间段内(使用目标日期 + time_slot 时间)
|
|
366
|
+
var checkTimeSlotsForDate = function checkTimeSlotsForDate(targetDate, targetDateString, timeSlots) {
|
|
367
|
+
var _iterator7 = _createForOfIteratorHelper(timeSlots),
|
|
368
|
+
_step7;
|
|
369
|
+
try {
|
|
370
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
371
|
+
var timeSlot = _step7.value;
|
|
372
|
+
var slotStart = "".concat(targetDateString, " ").concat(timeSlot.start_time, ":00");
|
|
373
|
+
var slotEnd = "".concat(targetDateString, " ").concat(timeSlot.end_time, ":00");
|
|
374
|
+
var slotStartDate = dayjs(slotStart);
|
|
375
|
+
var slotEndDate = dayjs(slotEnd);
|
|
376
|
+
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
} catch (err) {
|
|
381
|
+
_iterator7.e(err);
|
|
382
|
+
} finally {
|
|
383
|
+
_iterator7.f();
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// 检查日期是否满足每日重复规则(只检查日期,不检查时间)
|
|
389
|
+
var isInDailyRepeatForDate = function isInDailyRepeatForDate(targetDate, startDate, repeatRule) {
|
|
390
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
391
|
+
if (daysDiff < 0) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// 检查频率
|
|
396
|
+
return daysDiff % repeatRule.frequency === 0;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// 检查日期是否满足每周重复规则(只检查日期,不检查时间)
|
|
400
|
+
var isInWeeklyRepeatForDate = function isInWeeklyRepeatForDate(targetDate, startDate, repeatRule) {
|
|
401
|
+
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
402
|
+
|
|
403
|
+
// 检查是否在指定的星期几内
|
|
404
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// 计算周差
|
|
409
|
+
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
410
|
+
if (weeksDiff < 0) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// 检查频率
|
|
415
|
+
return weeksDiff % repeatRule.frequency === 0;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* 根据预约时间过滤优惠券列表
|
|
420
|
+
* @param discountList 优惠券列表
|
|
421
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
422
|
+
* @returns 过滤后的优惠券列表
|
|
423
|
+
*/
|
|
424
|
+
export var filterDiscountListByBookingTime = function filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
425
|
+
if (!bookingTime) {
|
|
426
|
+
return discountList;
|
|
427
|
+
}
|
|
428
|
+
return discountList.filter(function (discount) {
|
|
429
|
+
var _discount$metadata2, _discount$metadata3, _discount$custom_sche;
|
|
430
|
+
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") {
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
|
|
434
|
+
});
|
|
36
435
|
};
|
|
@@ -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(
|
|
@@ -176,6 +189,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
|
|
|
176
189
|
}
|
|
177
190
|
async clear() {
|
|
178
191
|
this.store.discountList = [];
|
|
192
|
+
this.store.originalDiscountList = [];
|
|
179
193
|
console.log("[Discount] clear");
|
|
180
194
|
}
|
|
181
195
|
storeChange() {
|
|
@@ -72,6 +72,7 @@ export interface Discount {
|
|
|
72
72
|
format_title: Formattitle;
|
|
73
73
|
metadata?: {
|
|
74
74
|
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
|
+
validity_type?: "custom_schedule_validity" | "fixed_validity";
|
|
75
76
|
};
|
|
76
77
|
product: Product;
|
|
77
78
|
type: "product" | 'good_pass';
|
|
@@ -98,9 +99,13 @@ export interface Discount {
|
|
|
98
99
|
week_order_behavior_count?: number;
|
|
99
100
|
month_order_behavior_count?: number;
|
|
100
101
|
customer_order_behavior_count?: number;
|
|
102
|
+
custom_schedule_snapshot?: {
|
|
103
|
+
data: any[];
|
|
104
|
+
};
|
|
101
105
|
}
|
|
102
106
|
export interface DiscountState {
|
|
103
107
|
discountList: Discount[];
|
|
108
|
+
originalDiscountList?: Discount[];
|
|
104
109
|
}
|
|
105
110
|
export interface DiscountModuleAPI {
|
|
106
111
|
setDiscountList: (discountList: Discount[]) => Promise<void>;
|
|
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
|
|
|
49
49
|
getCategories(): ProductCategory[];
|
|
50
50
|
setOtherParams(key: string, value: any): void;
|
|
51
51
|
getOtherParams(): any;
|
|
52
|
-
getProductType(): "
|
|
52
|
+
getProductType(): "normal" | "duration" | "session";
|
|
53
53
|
}
|
|
@@ -103,13 +103,6 @@ var ProductList = class extends import_BaseModule.BaseModule {
|
|
|
103
103
|
{ useCache: true }
|
|
104
104
|
);
|
|
105
105
|
const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
|
|
106
|
-
if (sortedList.length) {
|
|
107
|
-
sortedList.forEach((n) => {
|
|
108
|
-
if (n.is_eject !== 1 && n["schedule.ids"] && n["schedule.ids"].length) {
|
|
109
|
-
n.is_eject = 1;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
106
|
this.addProduct(sortedList);
|
|
114
107
|
return sortedList;
|
|
115
108
|
}
|
|
@@ -37,6 +37,7 @@ var import_utils = require("../../solution/ShopDiscount/utils");
|
|
|
37
37
|
var import_utils2 = require("../Cart/utils");
|
|
38
38
|
var import_decimal = __toESM(require("decimal.js"));
|
|
39
39
|
var import_lodash_es = require("lodash-es");
|
|
40
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
40
41
|
var RulesModule = class extends import_BaseModule.BaseModule {
|
|
41
42
|
constructor(name, version) {
|
|
42
43
|
super(name, version);
|
|
@@ -199,9 +200,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
199
200
|
addModeDiscount.forEach((discount) => {
|
|
200
201
|
var _a, _b, _c, _d;
|
|
201
202
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
203
|
+
let timeLimit = true;
|
|
204
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
202
205
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
203
206
|
const isAvailableProduct = !((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))));
|
|
204
|
-
if (isAvailableProduct && isLimitedProduct) {
|
|
207
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit) {
|
|
205
208
|
(_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
|
|
206
209
|
const applicableProducts = discountApplicableProducts.get(discount.id) || [];
|
|
207
210
|
const discountType = discount.tag || discount.type;
|
|
@@ -248,6 +251,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
248
251
|
if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
|
|
249
252
|
return false;
|
|
250
253
|
const limitedData = discount.limited_relation_product_data;
|
|
254
|
+
let timeLimit = true;
|
|
255
|
+
timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
|
|
256
|
+
if (!timeLimit) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
251
259
|
if (limitedData.type === "product_all") {
|
|
252
260
|
return true;
|
|
253
261
|
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
@@ -185,13 +185,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
185
185
|
collection = [],
|
|
186
186
|
schedule_date
|
|
187
187
|
}) {
|
|
188
|
-
|
|
188
|
+
const res = await this.store.products.loadProducts({
|
|
189
189
|
category_ids,
|
|
190
190
|
product_ids,
|
|
191
191
|
collection,
|
|
192
192
|
schedule_date,
|
|
193
193
|
cacheId: this.cacheId
|
|
194
194
|
});
|
|
195
|
+
this.getAvailableDate({
|
|
196
|
+
startDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
|
|
197
|
+
endDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
|
|
198
|
+
products: [...res]
|
|
199
|
+
});
|
|
200
|
+
return res;
|
|
195
201
|
}
|
|
196
202
|
/**
|
|
197
203
|
* 通过 schedule 来读取商品,适用于 session 类商品
|
|
@@ -228,11 +234,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
228
234
|
const allProductIds = [...newProductIds, ...otherProductsIds].filter(
|
|
229
235
|
(n, index, self) => self.indexOf(n) === index
|
|
230
236
|
);
|
|
231
|
-
|
|
237
|
+
const res = await this.loadProducts({
|
|
232
238
|
product_ids: allProductIds,
|
|
233
239
|
category_ids,
|
|
234
240
|
schedule_date: date
|
|
235
241
|
});
|
|
242
|
+
return res;
|
|
236
243
|
}
|
|
237
244
|
/**
|
|
238
245
|
* 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
|
|
@@ -599,6 +606,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
599
606
|
quantity = 1
|
|
600
607
|
} = product || {};
|
|
601
608
|
const productData = { ...origin, product_variant_id };
|
|
609
|
+
debugger;
|
|
610
|
+
if ((0, import_products.isSessionProduct)(productData)) {
|
|
611
|
+
if (!date || !date.startTime || !date.endTime) {
|
|
612
|
+
return { success: false, errorCode: "date_or_time_required" };
|
|
613
|
+
}
|
|
614
|
+
}
|
|
602
615
|
const currentCartItems = this.store.cart.getItems();
|
|
603
616
|
const stockCheckResult = (0, import_stock.checkProductStock)({
|
|
604
617
|
productData,
|
|
@@ -1606,6 +1619,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1606
1619
|
}
|
|
1607
1620
|
});
|
|
1608
1621
|
});
|
|
1622
|
+
this.core.effects.emit(
|
|
1623
|
+
`${this.store.cart.name}:onUpdateBookingDate`,
|
|
1624
|
+
{}
|
|
1625
|
+
);
|
|
1609
1626
|
}
|
|
1610
1627
|
getScheduleDataByIds(scheduleIds) {
|
|
1611
1628
|
const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
|
|
@@ -9,3 +9,9 @@ export declare const getAvailableProductResources: (products: ProductData[]) =>
|
|
|
9
9
|
rules: any[];
|
|
10
10
|
resourcesMap: Record<number, ProductResourceItem>;
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* 判断商品是否是 session 商品
|
|
14
|
+
* @param product 商品数据
|
|
15
|
+
* @returns 是否是 session 商品
|
|
16
|
+
*/
|
|
17
|
+
export declare const isSessionProduct: (product: ProductData) => boolean;
|
|
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/solution/BookingByStep/utils/products.ts
|
|
20
20
|
var products_exports = {};
|
|
21
21
|
__export(products_exports, {
|
|
22
|
-
getAvailableProductResources: () => getAvailableProductResources
|
|
22
|
+
getAvailableProductResources: () => getAvailableProductResources,
|
|
23
|
+
isSessionProduct: () => isSessionProduct
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(products_exports);
|
|
25
26
|
var getAvailableProductResources = (products) => {
|
|
@@ -57,7 +58,12 @@ var getAvailableProductResources = (products) => {
|
|
|
57
58
|
});
|
|
58
59
|
return { resourceIds: [...new Set(resourceIds)], rules, resourcesMap };
|
|
59
60
|
};
|
|
61
|
+
var isSessionProduct = (product) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return (((_a = product == null ? void 0 : product["schedule.ids"]) == null ? void 0 : _a.length) ?? 0) > 0;
|
|
64
|
+
};
|
|
60
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
66
|
0 && (module.exports = {
|
|
62
|
-
getAvailableProductResources
|
|
67
|
+
getAvailableProductResources,
|
|
68
|
+
isSessionProduct
|
|
63
69
|
});
|
|
@@ -122,12 +122,6 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
|
|
|
122
122
|
throw error;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
/**
|
|
126
|
-
* 初始化外设扫码结果监听
|
|
127
|
-
*/
|
|
128
|
-
initPeripheralsListener() {
|
|
129
|
-
this.scan.initPeripheralsListener();
|
|
130
|
-
}
|
|
131
125
|
/**
|
|
132
126
|
* 获取商品列表(不加载到模块中)
|
|
133
127
|
* @returns 商品列表
|
|
@@ -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>[];
|