@pisell/pisellos 3.0.71 → 3.0.73

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.
Files changed (33) hide show
  1. package/dist/modules/Cart/utils/cartProduct.js +41 -26
  2. package/dist/modules/Discount/index.d.ts +2 -0
  3. package/dist/modules/Discount/index.js +69 -36
  4. package/dist/modules/Discount/types.d.ts +16 -0
  5. package/dist/modules/Order/index.js +4 -1
  6. package/dist/modules/Order/utils.d.ts +1 -0
  7. package/dist/modules/Order/utils.js +9 -0
  8. package/dist/modules/Rules/index.d.ts +8 -0
  9. package/dist/modules/Rules/index.js +1033 -183
  10. package/dist/modules/Rules/types.d.ts +4 -1
  11. package/dist/solution/BookingByStep/index.js +1 -0
  12. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  13. package/dist/solution/ShopDiscount/index.js +82 -19
  14. package/dist/solution/ShopDiscount/types.d.ts +4 -0
  15. package/dist/solution/ShopDiscount/utils.d.ts +55 -0
  16. package/dist/solution/ShopDiscount/utils.js +432 -3
  17. package/lib/modules/Cart/utils/cartProduct.js +35 -22
  18. package/lib/modules/Discount/index.d.ts +2 -0
  19. package/lib/modules/Discount/index.js +19 -4
  20. package/lib/modules/Discount/types.d.ts +16 -0
  21. package/lib/modules/Order/index.js +2 -0
  22. package/lib/modules/Order/utils.d.ts +1 -0
  23. package/lib/modules/Order/utils.js +11 -0
  24. package/lib/modules/Rules/index.d.ts +8 -0
  25. package/lib/modules/Rules/index.js +813 -172
  26. package/lib/modules/Rules/types.d.ts +4 -1
  27. package/lib/solution/BookingByStep/index.js +4 -0
  28. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  29. package/lib/solution/ShopDiscount/index.js +58 -10
  30. package/lib/solution/ShopDiscount/types.d.ts +4 -0
  31. package/lib/solution/ShopDiscount/utils.d.ts +55 -0
  32. package/lib/solution/ShopDiscount/utils.js +266 -3
  33. 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
  * 商品券:直接返回商品价格
@@ -20,7 +37,7 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
20
37
  var _discount$metadata;
21
38
  // 商品券
22
39
  if (discount.tag === 'good_pass') {
23
- return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
40
+ return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
24
41
  }
25
42
 
26
43
  // 判断是否是固定金额
@@ -28,9 +45,421 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
28
45
 
29
46
  // 固定金额 小于0时返回0
30
47
  if (isFixedAmount) {
31
- return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
48
+ return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
32
49
  }
33
50
 
34
51
  // 百分比:根据折扣卡金额计算
35
- return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
52
+ return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
53
+ };
54
+ export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
55
+ return discount.reduce(function (acc, cur) {
56
+ return new Decimal(acc).plus(new Decimal(cur.num || 1).mul(new Decimal(cur.amount || 0))).toNumber();
57
+ }, new Decimal(0));
58
+ };
59
+
60
+ /**
61
+ * 获取折扣金额 计算每个折扣的金额
62
+ * @param discount
63
+ * @returns
64
+ */
65
+ export var getDiscountListAmount = function getDiscountListAmount(discount) {
66
+ return discount.reduce(function (acc, cur) {
67
+ return new Decimal(acc).plus(new Decimal(cur.amount || 0)).toNumber();
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;
446
+ if ((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.validity_type) === "custom_schedule_validity") {
447
+ var _discount$custom_sche;
448
+ return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
449
+ }
450
+ try {
451
+ var isHasStart = !!discount.start_date && !!discount.start_time;
452
+ var startDate = dayjs("".concat(discount.start_date, " ").concat(discount.start_time));
453
+ var bookingTimeDayjs = dayjs(bookingTime);
454
+
455
+ // 判断预约时间是否在开始时间之后
456
+ var isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
457
+
458
+ // 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
459
+ var isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore(dayjs(discount.expire_time)) : true;
460
+ return isAfterStart && isBeforeExpire;
461
+ } catch (error) {
462
+ return true;
463
+ }
464
+ });
36
465
  };
@@ -172,6 +172,18 @@ var formatProductToCartItemOrigin = (params) => {
172
172
  var getProductTotalPrice = (params) => {
173
173
  const { product, bundle, options, discounts } = params;
174
174
  let price = Number(product.price);
175
+ if (discounts == null ? void 0 : discounts.length) {
176
+ discounts.forEach((currentValue) => {
177
+ var _a;
178
+ price = (0, import_utils2.getDiscountAmount)({
179
+ tag: currentValue.type,
180
+ par_value: currentValue.discount.percent,
181
+ metadata: {
182
+ discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
183
+ }
184
+ }, price, price);
185
+ });
186
+ }
175
187
  if (bundle == null ? void 0 : bundle.length) {
176
188
  price = bundle.reduce((accumulator, currentValue) => {
177
189
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
@@ -182,21 +194,7 @@ var getProductTotalPrice = (params) => {
182
194
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
183
195
  }, price);
184
196
  }
185
- if (discounts == null ? void 0 : discounts.length) {
186
- discounts.forEach((currentValue) => {
187
- var _a;
188
- if (currentValue.type !== "good_pass") {
189
- price = (0, import_utils2.getDiscountAmount)({
190
- tag: currentValue.type,
191
- par_value: currentValue.discount.percent,
192
- metadata: {
193
- discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
194
- }
195
- }, price, price);
196
- }
197
- });
198
- }
199
- return price;
197
+ return Math.max(0, price);
200
198
  };
201
199
  var getProductOriginTotalPrice = (params) => {
202
200
  const { product, bundle, options, discounts } = params;
@@ -254,9 +252,15 @@ var formatBundle = (bundle) => {
254
252
  price: item == null ? void 0 : item.price,
255
253
  total: item == null ? void 0 : item.price,
256
254
  price_type: item == null ? void 0 : item.price_type,
255
+ original_price: item == null ? void 0 : item.original_price,
256
+ original_total: item == null ? void 0 : item.original_total,
257
+ price_type_ext: item == null ? void 0 : item.price_type_ext,
257
258
  bundle_sum_price: item == null ? void 0 : item.bundle_sum_price,
258
259
  bundle_sum_type: item == null ? void 0 : item.bundle_sum_type,
259
- options: formatOptions(item == null ? void 0 : item.option)
260
+ options: formatOptions(item == null ? void 0 : item.option),
261
+ _bundle_product_id: item._bundle_product_id,
262
+ discount_list: item.discount_list,
263
+ originBundleItem: item.originBundleItem || item
260
264
  };
261
265
  });
262
266
  };
@@ -264,15 +268,24 @@ var formatBundleToOrigin = (bundle) => {
264
268
  if (!(bundle == null ? void 0 : bundle.length))
265
269
  return [];
266
270
  return bundle.map((d) => {
271
+ const getBundleValueByKey = (key) => {
272
+ var _a;
273
+ return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
274
+ };
267
275
  return {
268
- bundle_group_id: d.group_id,
276
+ bundle_group_id: getBundleValueByKey("group_id"),
269
277
  bundle_id: d.id,
270
- bundle_product_id: (d == null ? void 0 : d._bundle_product_id) || (d == null ? void 0 : d.product_id),
271
- bundle_variant_id: d.bundle_variant_id,
278
+ bundle_product_id: getBundleValueByKey("_bundle_product_id") || getBundleValueByKey("product_id"),
279
+ bundle_variant_id: getBundleValueByKey("bundle_variant_id"),
272
280
  num: d.num,
273
- extension_id: d.extension_id,
274
- extension_type: d.extension_type,
275
- option: formatOptionsToOrigin(d.option)
281
+ extension_id: getBundleValueByKey("extension_id"),
282
+ extension_type: getBundleValueByKey("extension_type"),
283
+ option: formatOptionsToOrigin(getBundleValueByKey("option")),
284
+ discount_list: d.discount_list,
285
+ "bundle_selling_price": d == null ? void 0 : d.price,
286
+ metadata: {
287
+ custom_product_bundle_map_id: d._id
288
+ }
276
289
  };
277
290
  });
278
291
  };
@@ -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.otherParams) == null ? void 0 : _b.cacheId) {
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 ((_c = options == null ? void 0 : options.otherParams) == null ? void 0 : _c.fatherModule) {
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(
@@ -163,7 +176,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
163
176
  }
164
177
  if (discount.appliedProductDetails) {
165
178
  return discount.appliedProductDetails.reduce((total, product) => {
166
- const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0).mul((product == null ? void 0 : product.num) || 1);
179
+ var _a;
180
+ const price = new import_decimal.default(((_a = product == null ? void 0 : product.discount) == null ? void 0 : _a.fixed_amount) || 0).mul((product == null ? void 0 : product._num) || 1);
167
181
  return new import_decimal.default(total).plus(price).toNumber();
168
182
  }, 0);
169
183
  }
@@ -176,6 +190,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
176
190
  }
177
191
  async clear() {
178
192
  this.store.discountList = [];
193
+ this.store.originalDiscountList = [];
179
194
  console.log("[Discount] clear");
180
195
  }
181
196
  storeChange() {
@@ -15,11 +15,16 @@ interface Formattitle {
15
15
  'zh-CN'?: any;
16
16
  'zh-HK'?: any;
17
17
  }
18
+ interface PackageSubItemUsageRules {
19
+ type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
+ rules: ("original_price" | "markup_price")[];
21
+ }
18
22
  interface Limitedrelationproductdata {
19
23
  id: number;
20
24
  type: 'product_all' | 'products' | 'product_collection';
21
25
  product_ids: number[];
22
26
  product_collection_id: number[];
27
+ package_sub_item_usage_rules?: PackageSubItemUsageRules;
23
28
  }
24
29
  interface ApplicableProductDetails {
25
30
  amount: string;
@@ -29,12 +34,14 @@ interface ApplicableProductDetails {
29
34
  original_amount: string;
30
35
  num: number;
31
36
  discount?: {
37
+ fixed_amount?: number;
32
38
  product_id?: number;
33
39
  original_amount?: string;
34
40
  percent?: string;
35
41
  resource_id?: number;
36
42
  title?: string;
37
43
  };
44
+ _num: number;
38
45
  }
39
46
  interface UsageCreditsValue {
40
47
  total_credits: number;
@@ -72,6 +79,8 @@ export interface Discount {
72
79
  format_title: Formattitle;
73
80
  metadata?: {
74
81
  discount_card_type?: 'fixed_amount' | 'percent';
82
+ custom_product_bundle_map_id?: string;
83
+ validity_type?: "custom_schedule_validity" | "fixed_validity";
75
84
  };
76
85
  product: Product;
77
86
  type: "product" | 'good_pass';
@@ -98,9 +107,16 @@ export interface Discount {
98
107
  week_order_behavior_count?: number;
99
108
  month_order_behavior_count?: number;
100
109
  customer_order_behavior_count?: number;
110
+ custom_schedule_snapshot?: {
111
+ data: any[];
112
+ };
113
+ num?: number;
114
+ start_date?: string;
115
+ start_time?: string;
101
116
  }
102
117
  export interface DiscountState {
103
118
  discountList: Discount[];
119
+ originalDiscountList?: Discount[];
104
120
  }
105
121
  export interface DiscountModuleAPI {
106
122
  setDiscountList: (discountList: Discount[]) => Promise<void>;
@@ -60,6 +60,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
60
60
  item._origin.duration = duration;
61
61
  item._origin.sub_type = durationType;
62
62
  }
63
+ const discountList = (0, import_utils.getAllDiscountList)(item);
64
+ item._origin.product.discount_list = discountList;
63
65
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
64
66
  order.relation_products.push(item._origin.product);
65
67
  const relationForms = item._origin.relation_forms || [];