@pisell/pisellos 2.2.11 → 2.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/modules/Cart/utils/cartProduct.js +41 -26
  2. package/dist/modules/Customer/index.js +1 -1
  3. package/dist/modules/Discount/index.d.ts +2 -0
  4. package/dist/modules/Discount/index.js +69 -36
  5. package/dist/modules/Discount/types.d.ts +16 -0
  6. package/dist/modules/Order/index.js +4 -1
  7. package/dist/modules/Order/utils.d.ts +1 -0
  8. package/dist/modules/Order/utils.js +9 -0
  9. package/dist/modules/Payment/index.js +2 -2
  10. package/dist/modules/Payment/types.d.ts +1 -0
  11. package/dist/modules/Payment/walletpass.js +3 -1
  12. package/dist/modules/ProductList/index.js +8 -9
  13. package/dist/modules/Rules/index.d.ts +7 -0
  14. package/dist/modules/Rules/index.js +1065 -196
  15. package/dist/modules/Rules/types.d.ts +4 -1
  16. package/dist/solution/BookingByStep/index.d.ts +1 -1
  17. package/dist/solution/BookingByStep/index.js +30 -8
  18. package/dist/solution/BookingByStep/utils/products.d.ts +6 -0
  19. package/dist/solution/BookingByStep/utils/products.js +10 -0
  20. package/dist/solution/BookingTicket/index.d.ts +1 -1
  21. package/dist/solution/Checkout/index.js +61 -17
  22. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  23. package/dist/solution/ShopDiscount/index.js +80 -19
  24. package/dist/solution/ShopDiscount/types.d.ts +4 -1
  25. package/dist/solution/ShopDiscount/utils.d.ts +55 -0
  26. package/dist/solution/ShopDiscount/utils.js +432 -3
  27. package/lib/modules/Cart/utils/cartProduct.js +35 -22
  28. package/lib/modules/Customer/index.js +1 -1
  29. package/lib/modules/Discount/index.d.ts +2 -0
  30. package/lib/modules/Discount/index.js +19 -4
  31. package/lib/modules/Discount/types.d.ts +16 -0
  32. package/lib/modules/Order/index.js +2 -0
  33. package/lib/modules/Order/utils.d.ts +1 -0
  34. package/lib/modules/Order/utils.js +11 -0
  35. package/lib/modules/Payment/index.js +1 -1
  36. package/lib/modules/Payment/types.d.ts +1 -0
  37. package/lib/modules/Payment/walletpass.js +10 -1
  38. package/lib/modules/ProductList/index.js +0 -7
  39. package/lib/modules/Rules/index.d.ts +7 -0
  40. package/lib/modules/Rules/index.js +824 -182
  41. package/lib/modules/Rules/types.d.ts +4 -1
  42. package/lib/solution/BookingByStep/index.d.ts +1 -1
  43. package/lib/solution/BookingByStep/index.js +19 -2
  44. package/lib/solution/BookingByStep/utils/products.d.ts +6 -0
  45. package/lib/solution/BookingByStep/utils/products.js +8 -2
  46. package/lib/solution/BookingTicket/index.d.ts +1 -1
  47. package/lib/solution/Checkout/index.js +66 -17
  48. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  49. package/lib/solution/ShopDiscount/index.js +55 -9
  50. package/lib/solution/ShopDiscount/types.d.ts +4 -1
  51. package/lib/solution/ShopDiscount/utils.d.ts +55 -0
  52. package/lib/solution/ShopDiscount/utils.js +266 -3
  53. package/package.json +2 -2
@@ -29,28 +29,291 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/solution/ShopDiscount/utils.ts
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
+ filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
33
+ getDateIsInSchedule: () => getDateIsInSchedule,
32
34
  getDiscountAmount: () => getDiscountAmount,
35
+ getDiscountListAmount: () => getDiscountListAmount,
36
+ getDiscountListAmountTotal: () => getDiscountListAmountTotal,
37
+ isAllNormalProduct: () => isAllNormalProduct,
38
+ isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
33
39
  uniqueById: () => uniqueById
34
40
  });
35
41
  module.exports = __toCommonJS(utils_exports);
36
42
  var import_decimal = __toESM(require("decimal.js"));
43
+ var import_dayjs = __toESM(require("dayjs"));
37
44
  var uniqueById = (arr, key = "id") => {
38
45
  const seen = /* @__PURE__ */ new Set();
39
46
  return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
40
47
  };
48
+ var isNormalProductByDurationSchedule = (item) => {
49
+ var _a, _b;
50
+ return !(item == null ? void 0 : item.duration) && !((_a = item == null ? void 0 : item.schedules) == null ? void 0 : _a.length) && !((_b = item == null ? void 0 : item["schedule.ids"]) == null ? void 0 : _b.length);
51
+ };
52
+ var isAllNormalProduct = (items) => {
53
+ return items.every((item) => isNormalProductByDurationSchedule(item));
54
+ };
41
55
  var getDiscountAmount = (discount, total, price) => {
42
56
  var _a;
43
57
  if (discount.tag === "good_pass") {
44
- return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
58
+ return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
45
59
  }
46
60
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
47
61
  if (isFixedAmount) {
48
- return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
62
+ return Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
63
+ }
64
+ return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
65
+ };
66
+ var getDiscountListAmountTotal = (discount) => {
67
+ return discount.reduce((acc, cur) => {
68
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.num || 1).mul(new import_decimal.default(cur.amount || 0))).toNumber();
69
+ }, new import_decimal.default(0));
70
+ };
71
+ var getDiscountListAmount = (discount) => {
72
+ return discount.reduce((acc, cur) => {
73
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.amount || 0)).toNumber();
74
+ }, new import_decimal.default(0));
75
+ };
76
+ var getDateIsInSchedule = (dateTime, scheduleList) => {
77
+ if (!dateTime || !scheduleList || scheduleList.length === 0) {
78
+ return false;
79
+ }
80
+ const targetDate = (0, import_dayjs.default)(dateTime);
81
+ if (!targetDate.isValid()) {
82
+ return false;
83
+ }
84
+ for (const schedule of scheduleList) {
85
+ if (isTimeInScheduleItem(dateTime, schedule)) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ };
91
+ var isTimeInScheduleItem = (dateTime, schedule) => {
92
+ const targetDate = (0, import_dayjs.default)(dateTime);
93
+ const targetDateString = dateTime.split(" ")[0];
94
+ const targetTimeString = dateTime.split(" ")[1] || "00:00:00";
95
+ switch (schedule.type) {
96
+ case "standard":
97
+ return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
98
+ case "time-slots":
99
+ return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
100
+ case "designation":
101
+ return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
102
+ default:
103
+ return false;
104
+ }
105
+ };
106
+ var isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
107
+ if (!schedule.start_time || !schedule.end_time) {
108
+ return false;
109
+ }
110
+ const startDate = (0, import_dayjs.default)(schedule.start_time);
111
+ const endDate = (0, import_dayjs.default)(schedule.end_time);
112
+ const isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
113
+ if (schedule.repeat_type === "none") {
114
+ return isInBasicRange;
115
+ }
116
+ return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
117
+ };
118
+ var isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
119
+ if (!schedule.start_time) {
120
+ return false;
121
+ }
122
+ if (schedule.repeat_type === "none") {
123
+ const scheduleDate = schedule.start_time.split(" ")[0];
124
+ if (targetDateString !== scheduleDate) {
125
+ return false;
126
+ }
127
+ return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
128
+ }
129
+ return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
130
+ };
131
+ var isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
132
+ if (!schedule.designation) {
133
+ return false;
134
+ }
135
+ for (const designation of schedule.designation) {
136
+ const startDateTime = `${designation.start_date} ${designation.start_time}:00`;
137
+ const endDateTime = `${designation.end_date} ${designation.end_time}:00`;
138
+ const startDate = (0, import_dayjs.default)(startDateTime);
139
+ const endDate = (0, import_dayjs.default)(endDateTime);
140
+ if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
141
+ return true;
142
+ }
143
+ }
144
+ return false;
145
+ };
146
+ var isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
147
+ if (!schedule.repeat_rule) {
148
+ return false;
149
+ }
150
+ const { repeat_rule, repeat_type } = schedule;
151
+ const targetDateOnly = (0, import_dayjs.default)(targetDateString);
152
+ if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
153
+ for (const includedDate of repeat_rule.included_date) {
154
+ const includeStartDate = (0, import_dayjs.default)(includedDate.start);
155
+ const includeEndDate = (0, import_dayjs.default)(includedDate.end);
156
+ if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
157
+ return true;
158
+ }
159
+ }
160
+ }
161
+ for (const excludedDate of repeat_rule.excluded_date) {
162
+ const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
163
+ const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
164
+ if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
165
+ return false;
166
+ }
167
+ }
168
+ if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
169
+ const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
170
+ if (targetDate.isAfter(ruleEndDate)) {
171
+ return false;
172
+ }
173
+ }
174
+ switch (repeat_type) {
175
+ case "daily":
176
+ return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
177
+ case "weekly":
178
+ return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
179
+ default:
180
+ return false;
181
+ }
182
+ };
183
+ var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
184
+ const daysDiff = targetDate.diff(startDate, "day");
185
+ if (daysDiff < 0) {
186
+ return false;
187
+ }
188
+ if (daysDiff % repeatRule.frequency !== 0) {
189
+ return false;
190
+ }
191
+ const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
192
+ const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
193
+ const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
194
+ return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
195
+ };
196
+ var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
197
+ const targetDayOfWeek = targetDate.day();
198
+ if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
199
+ return false;
200
+ }
201
+ const weeksDiff = targetDate.diff(startDate, "week");
202
+ if (weeksDiff < 0) {
203
+ return false;
204
+ }
205
+ if (weeksDiff % repeatRule.frequency !== 0) {
206
+ return false;
207
+ }
208
+ const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
209
+ const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
210
+ const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
211
+ return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
212
+ };
213
+ var isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
214
+ if (!schedule.repeat_rule || !schedule.start_time) {
215
+ return false;
216
+ }
217
+ const { repeat_rule, repeat_type } = schedule;
218
+ const startDate = (0, import_dayjs.default)(schedule.start_time);
219
+ const targetDateOnly = (0, import_dayjs.default)(targetDateString);
220
+ if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
221
+ for (const includedDate of repeat_rule.included_date) {
222
+ const includeStartDate = (0, import_dayjs.default)(includedDate.start);
223
+ const includeEndDate = (0, import_dayjs.default)(includedDate.end);
224
+ if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
225
+ return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
226
+ }
227
+ }
228
+ }
229
+ for (const excludedDate of repeat_rule.excluded_date) {
230
+ const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
231
+ const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
232
+ if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
233
+ return false;
234
+ }
235
+ }
236
+ if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
237
+ const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
238
+ if (targetDateOnly.isAfter(ruleEndDate, "day")) {
239
+ return false;
240
+ }
241
+ }
242
+ let isDateValid = false;
243
+ switch (repeat_type) {
244
+ case "daily":
245
+ isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
246
+ break;
247
+ case "weekly":
248
+ isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
249
+ break;
250
+ default:
251
+ return false;
252
+ }
253
+ if (isDateValid) {
254
+ return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
255
+ }
256
+ return false;
257
+ };
258
+ var checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
259
+ for (const timeSlot of timeSlots) {
260
+ const slotStart = `${targetDateString} ${timeSlot.start_time}:00`;
261
+ const slotEnd = `${targetDateString} ${timeSlot.end_time}:00`;
262
+ const slotStartDate = (0, import_dayjs.default)(slotStart);
263
+ const slotEndDate = (0, import_dayjs.default)(slotEnd);
264
+ if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
265
+ return true;
266
+ }
267
+ }
268
+ return false;
269
+ };
270
+ var isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
271
+ const daysDiff = targetDate.diff(startDate, "day");
272
+ if (daysDiff < 0) {
273
+ return false;
274
+ }
275
+ return daysDiff % repeatRule.frequency === 0;
276
+ };
277
+ var isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
278
+ const targetDayOfWeek = targetDate.day();
279
+ if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
280
+ return false;
281
+ }
282
+ const weeksDiff = targetDate.diff(startDate, "week");
283
+ if (weeksDiff < 0) {
284
+ return false;
285
+ }
286
+ return weeksDiff % repeatRule.frequency === 0;
287
+ };
288
+ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
289
+ if (!bookingTime) {
290
+ return discountList;
49
291
  }
50
- return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
292
+ return discountList.filter((discount) => {
293
+ var _a, _b;
294
+ if (((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) === "custom_schedule_validity") {
295
+ return getDateIsInSchedule(bookingTime, ((_b = discount.custom_schedule_snapshot) == null ? void 0 : _b.data) || []);
296
+ }
297
+ try {
298
+ const isHasStart = !!discount.start_date && !!discount.start_time;
299
+ const startDate = (0, import_dayjs.default)(`${discount.start_date} ${discount.start_time}`);
300
+ const bookingTimeDayjs = (0, import_dayjs.default)(bookingTime);
301
+ const isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
302
+ const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, import_dayjs.default)(discount.expire_time)) : true;
303
+ return isAfterStart && isBeforeExpire;
304
+ } catch (error) {
305
+ return true;
306
+ }
307
+ });
51
308
  };
52
309
  // Annotate the CommonJS export names for ESM import in node:
53
310
  0 && (module.exports = {
311
+ filterDiscountListByBookingTime,
312
+ getDateIsInSchedule,
54
313
  getDiscountAmount,
314
+ getDiscountListAmount,
315
+ getDiscountListAmountTotal,
316
+ isAllNormalProduct,
317
+ isNormalProductByDurationSchedule,
55
318
  uniqueById
56
319
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.11",
4
+ "version": "2.2.13",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -69,4 +69,4 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  }
72
- }
72
+ }