@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
|
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(ShopDiscount_exports);
|
|
|
36
36
|
var import_BaseModule = require("../../modules/BaseModule");
|
|
37
37
|
var import_Discount = require("../../modules/Discount");
|
|
38
38
|
var import_Rules = require("../../modules/Rules");
|
|
39
|
+
var import_utils = require("./utils");
|
|
39
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
40
41
|
var import_lodash_es = require("lodash-es");
|
|
41
42
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -50,7 +51,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
50
51
|
productList: [],
|
|
51
52
|
discount: null,
|
|
52
53
|
rules: null,
|
|
53
|
-
originalDiscountList: []
|
|
54
|
+
originalDiscountList: [],
|
|
55
|
+
currentBookingTime: "",
|
|
56
|
+
filteredDiscountList: []
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
// =========== 生命周期方法 ===========
|
|
@@ -139,6 +142,44 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
139
142
|
);
|
|
140
143
|
}
|
|
141
144
|
// =========== 公共 API ===========
|
|
145
|
+
// 设置预约时间
|
|
146
|
+
// public async setBookingTime(bookingTime: string | null): Promise<void> {
|
|
147
|
+
// if (this.store.currentBookingTime !== bookingTime) {
|
|
148
|
+
// this.store.currentBookingTime = bookingTime;
|
|
149
|
+
//
|
|
150
|
+
// // 更新过滤后的优惠券列表
|
|
151
|
+
// await this.updateFilteredDiscountList();
|
|
152
|
+
// }
|
|
153
|
+
// }
|
|
154
|
+
// 获取当前预约时间
|
|
155
|
+
getCurrentBookingTime() {
|
|
156
|
+
return this.store.currentBookingTime;
|
|
157
|
+
}
|
|
158
|
+
// 根据预约时间过滤优惠券列表
|
|
159
|
+
filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
160
|
+
if ((0, import_utils.isAllNormalProduct)(this.store.productList || [])) {
|
|
161
|
+
return discountList;
|
|
162
|
+
}
|
|
163
|
+
return (0, import_utils.filterDiscountListByBookingTime)(discountList, bookingTime);
|
|
164
|
+
}
|
|
165
|
+
// 更新过滤后的优惠券列表
|
|
166
|
+
// private async updateFilteredDiscountList(): Promise<void> {
|
|
167
|
+
// const originalList = this.store.originalDiscountList;
|
|
168
|
+
// const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
|
|
169
|
+
//
|
|
170
|
+
// this.store.filteredDiscountList = filteredList;
|
|
171
|
+
//
|
|
172
|
+
// // 更新 DiscountModule 中的优惠券列表
|
|
173
|
+
// this.setDiscountList(filteredList);
|
|
174
|
+
//
|
|
175
|
+
// if (this.store.productList?.length) {
|
|
176
|
+
// const result = this.calcDiscount(this.store.productList);
|
|
177
|
+
// await this.core.effects.emit(
|
|
178
|
+
// ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
179
|
+
// result,
|
|
180
|
+
// );
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
142
183
|
// 设置客户
|
|
143
184
|
async setCustomer(customer) {
|
|
144
185
|
var _a;
|
|
@@ -425,7 +466,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
425
466
|
}
|
|
426
467
|
// 加载准备配置
|
|
427
468
|
async loadPrepareConfig(params) {
|
|
428
|
-
var _a, _b, _c, _d;
|
|
469
|
+
var _a, _b, _c, _d, _e;
|
|
429
470
|
try {
|
|
430
471
|
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
431
472
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
@@ -441,8 +482,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
441
482
|
const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
|
|
442
483
|
const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
|
|
443
484
|
this.store.originalDiscountList = newDiscountList;
|
|
444
|
-
this.
|
|
445
|
-
|
|
485
|
+
await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
|
|
486
|
+
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
487
|
+
this.store.filteredDiscountList = filteredDiscountList;
|
|
488
|
+
this.setDiscountList(filteredDiscountList || []);
|
|
489
|
+
if ((_e = this.store.productList) == null ? void 0 : _e.length) {
|
|
446
490
|
const result = this.calcDiscount(this.store.productList);
|
|
447
491
|
await this.core.effects.emit(
|
|
448
492
|
`${this.name}:onLoadPrepareCalcResult`,
|
|
@@ -451,7 +495,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
451
495
|
}
|
|
452
496
|
await this.core.effects.emit(
|
|
453
497
|
`${this.name}:onLoadDiscountList`,
|
|
454
|
-
|
|
498
|
+
filteredDiscountList
|
|
455
499
|
);
|
|
456
500
|
} catch (error) {
|
|
457
501
|
console.error("[ShopDiscount] 加载准备配置出错:", error);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DiscountModule
|
|
1
|
+
import { DiscountModule } from '../../modules/Discount';
|
|
2
2
|
import { RulesModule } from '../../modules/Rules';
|
|
3
|
+
import { Discount } from "../../modules/Discount/types";
|
|
3
4
|
export declare enum ShopDiscountHooks {
|
|
4
5
|
onInited = "shopDiscount:onInited",
|
|
5
6
|
onDestroy = "shopDiscount:onDestroy",
|
|
@@ -23,6 +24,8 @@ export interface ShopDiscountState {
|
|
|
23
24
|
rules: RulesModule | null;
|
|
24
25
|
productList: Record<string, any>[];
|
|
25
26
|
originalDiscountList: Discount[];
|
|
27
|
+
currentBookingTime: string | null;
|
|
28
|
+
filteredDiscountList: Discount[];
|
|
26
29
|
}
|
|
27
30
|
export interface SetDiscountSelectedParams {
|
|
28
31
|
discountId: number;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Discount } from "../../modules/Discount/types";
|
|
2
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
export declare const isNormalProductByDurationSchedule: (item: any) => boolean;
|
|
4
|
+
export declare const isAllNormalProduct: (items: any[]) => boolean;
|
|
3
5
|
/**
|
|
4
6
|
* 获取折扣金额 基于折扣卡类型计算
|
|
5
7
|
* 商品券:直接返回商品价格
|
|
@@ -10,3 +12,49 @@ export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
|
10
12
|
* @returns
|
|
11
13
|
*/
|
|
12
14
|
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
15
|
+
export interface ScheduleItem {
|
|
16
|
+
id: number;
|
|
17
|
+
name: string | {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
};
|
|
20
|
+
type: 'standard' | 'time-slots' | 'designation';
|
|
21
|
+
start_time: string | null;
|
|
22
|
+
end_time: string | null;
|
|
23
|
+
repeat_type: 'none' | 'daily' | 'weekly';
|
|
24
|
+
repeat_rule: {
|
|
25
|
+
end: {
|
|
26
|
+
type: 'never' | 'date' | 'occurrence';
|
|
27
|
+
end_date: string | null;
|
|
28
|
+
occurrence: number | null;
|
|
29
|
+
};
|
|
30
|
+
frequency: number;
|
|
31
|
+
excluded_date: Array<{
|
|
32
|
+
start: string;
|
|
33
|
+
end: string;
|
|
34
|
+
}>;
|
|
35
|
+
included_date: Array<{
|
|
36
|
+
start: string;
|
|
37
|
+
end: string;
|
|
38
|
+
}>;
|
|
39
|
+
frequency_date: number[];
|
|
40
|
+
} | null;
|
|
41
|
+
designation: Array<{
|
|
42
|
+
start_date: string;
|
|
43
|
+
start_time: string;
|
|
44
|
+
end_date: string;
|
|
45
|
+
end_time: string;
|
|
46
|
+
}> | null;
|
|
47
|
+
is_all: number;
|
|
48
|
+
time_slot: Array<{
|
|
49
|
+
start_time: string;
|
|
50
|
+
end_time: string;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 根据预约时间过滤优惠券列表
|
|
56
|
+
* @param discountList 优惠券列表
|
|
57
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
58
|
+
* @returns 过滤后的优惠券列表
|
|
59
|
+
*/
|
|
60
|
+
export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
|
|
@@ -29,15 +29,27 @@ 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
|
+
isAllNormalProduct: () => isAllNormalProduct,
|
|
36
|
+
isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
|
|
33
37
|
uniqueById: () => uniqueById
|
|
34
38
|
});
|
|
35
39
|
module.exports = __toCommonJS(utils_exports);
|
|
36
40
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
37
42
|
var uniqueById = (arr, key = "id") => {
|
|
38
43
|
const seen = /* @__PURE__ */ new Set();
|
|
39
44
|
return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
|
|
40
45
|
};
|
|
46
|
+
var isNormalProductByDurationSchedule = (item) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
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);
|
|
49
|
+
};
|
|
50
|
+
var isAllNormalProduct = (items) => {
|
|
51
|
+
return items.every((item) => isNormalProductByDurationSchedule(item));
|
|
52
|
+
};
|
|
41
53
|
var getDiscountAmount = (discount, total, price) => {
|
|
42
54
|
var _a;
|
|
43
55
|
if (discount.tag === "good_pass") {
|
|
@@ -49,8 +61,236 @@ var getDiscountAmount = (discount, total, price) => {
|
|
|
49
61
|
}
|
|
50
62
|
return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
|
|
51
63
|
};
|
|
64
|
+
var getDateIsInSchedule = (dateTime, scheduleList) => {
|
|
65
|
+
if (!dateTime || !scheduleList || scheduleList.length === 0) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const targetDate = (0, import_dayjs.default)(dateTime);
|
|
69
|
+
if (!targetDate.isValid()) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
for (const schedule of scheduleList) {
|
|
73
|
+
if (isTimeInScheduleItem(dateTime, schedule)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
var isTimeInScheduleItem = (dateTime, schedule) => {
|
|
80
|
+
const targetDate = (0, import_dayjs.default)(dateTime);
|
|
81
|
+
const targetDateString = dateTime.split(" ")[0];
|
|
82
|
+
const targetTimeString = dateTime.split(" ")[1] || "00:00:00";
|
|
83
|
+
switch (schedule.type) {
|
|
84
|
+
case "standard":
|
|
85
|
+
return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
86
|
+
case "time-slots":
|
|
87
|
+
return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
88
|
+
case "designation":
|
|
89
|
+
return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
90
|
+
default:
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
95
|
+
if (!schedule.start_time || !schedule.end_time) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const startDate = (0, import_dayjs.default)(schedule.start_time);
|
|
99
|
+
const endDate = (0, import_dayjs.default)(schedule.end_time);
|
|
100
|
+
const isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
|
|
101
|
+
if (schedule.repeat_type === "none") {
|
|
102
|
+
return isInBasicRange;
|
|
103
|
+
}
|
|
104
|
+
return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
|
|
105
|
+
};
|
|
106
|
+
var isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
107
|
+
if (!schedule.start_time) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (schedule.repeat_type === "none") {
|
|
111
|
+
const scheduleDate = schedule.start_time.split(" ")[0];
|
|
112
|
+
if (targetDateString !== scheduleDate) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
116
|
+
}
|
|
117
|
+
return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
118
|
+
};
|
|
119
|
+
var isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
120
|
+
if (!schedule.designation) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
for (const designation of schedule.designation) {
|
|
124
|
+
const startDateTime = `${designation.start_date} ${designation.start_time}:00`;
|
|
125
|
+
const endDateTime = `${designation.end_date} ${designation.end_time}:00`;
|
|
126
|
+
const startDate = (0, import_dayjs.default)(startDateTime);
|
|
127
|
+
const endDate = (0, import_dayjs.default)(endDateTime);
|
|
128
|
+
if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
};
|
|
134
|
+
var isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
|
|
135
|
+
if (!schedule.repeat_rule) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const { repeat_rule, repeat_type } = schedule;
|
|
139
|
+
const targetDateOnly = (0, import_dayjs.default)(targetDateString);
|
|
140
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
141
|
+
for (const includedDate of repeat_rule.included_date) {
|
|
142
|
+
const includeStartDate = (0, import_dayjs.default)(includedDate.start);
|
|
143
|
+
const includeEndDate = (0, import_dayjs.default)(includedDate.end);
|
|
144
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const excludedDate of repeat_rule.excluded_date) {
|
|
150
|
+
const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
|
|
151
|
+
const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
|
|
152
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
|
|
157
|
+
const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
|
|
158
|
+
if (targetDate.isAfter(ruleEndDate)) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
switch (repeat_type) {
|
|
163
|
+
case "daily":
|
|
164
|
+
return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
165
|
+
case "weekly":
|
|
166
|
+
return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
167
|
+
default:
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
172
|
+
const daysDiff = targetDate.diff(startDate, "day");
|
|
173
|
+
if (daysDiff < 0) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
if (daysDiff % repeatRule.frequency !== 0) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
180
|
+
const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
181
|
+
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
182
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
183
|
+
};
|
|
184
|
+
var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
185
|
+
const targetDayOfWeek = targetDate.day();
|
|
186
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const weeksDiff = targetDate.diff(startDate, "week");
|
|
190
|
+
if (weeksDiff < 0) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
197
|
+
const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
198
|
+
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
199
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
200
|
+
};
|
|
201
|
+
var isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
202
|
+
if (!schedule.repeat_rule || !schedule.start_time) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const { repeat_rule, repeat_type } = schedule;
|
|
206
|
+
const startDate = (0, import_dayjs.default)(schedule.start_time);
|
|
207
|
+
const targetDateOnly = (0, import_dayjs.default)(targetDateString);
|
|
208
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
209
|
+
for (const includedDate of repeat_rule.included_date) {
|
|
210
|
+
const includeStartDate = (0, import_dayjs.default)(includedDate.start);
|
|
211
|
+
const includeEndDate = (0, import_dayjs.default)(includedDate.end);
|
|
212
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
|
|
213
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
for (const excludedDate of repeat_rule.excluded_date) {
|
|
218
|
+
const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
|
|
219
|
+
const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
|
|
220
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
|
|
225
|
+
const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
|
|
226
|
+
if (targetDateOnly.isAfter(ruleEndDate, "day")) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
let isDateValid = false;
|
|
231
|
+
switch (repeat_type) {
|
|
232
|
+
case "daily":
|
|
233
|
+
isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
234
|
+
break;
|
|
235
|
+
case "weekly":
|
|
236
|
+
isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
237
|
+
break;
|
|
238
|
+
default:
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
if (isDateValid) {
|
|
242
|
+
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
243
|
+
}
|
|
244
|
+
return false;
|
|
245
|
+
};
|
|
246
|
+
var checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
|
|
247
|
+
for (const timeSlot of timeSlots) {
|
|
248
|
+
const slotStart = `${targetDateString} ${timeSlot.start_time}:00`;
|
|
249
|
+
const slotEnd = `${targetDateString} ${timeSlot.end_time}:00`;
|
|
250
|
+
const slotStartDate = (0, import_dayjs.default)(slotStart);
|
|
251
|
+
const slotEndDate = (0, import_dayjs.default)(slotEnd);
|
|
252
|
+
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
};
|
|
258
|
+
var isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
259
|
+
const daysDiff = targetDate.diff(startDate, "day");
|
|
260
|
+
if (daysDiff < 0) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
return daysDiff % repeatRule.frequency === 0;
|
|
264
|
+
};
|
|
265
|
+
var isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
266
|
+
const targetDayOfWeek = targetDate.day();
|
|
267
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
const weeksDiff = targetDate.diff(startDate, "week");
|
|
271
|
+
if (weeksDiff < 0) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
return weeksDiff % repeatRule.frequency === 0;
|
|
275
|
+
};
|
|
276
|
+
var filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
277
|
+
if (!bookingTime) {
|
|
278
|
+
return discountList;
|
|
279
|
+
}
|
|
280
|
+
return discountList.filter((discount) => {
|
|
281
|
+
var _a, _b, _c;
|
|
282
|
+
if (!((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) || ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.validity_type) === "fixed_validity") {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
return getDateIsInSchedule(bookingTime, ((_c = discount.custom_schedule_snapshot) == null ? void 0 : _c.data) || []);
|
|
286
|
+
});
|
|
287
|
+
};
|
|
52
288
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
289
|
0 && (module.exports = {
|
|
290
|
+
filterDiscountListByBookingTime,
|
|
291
|
+
getDateIsInSchedule,
|
|
54
292
|
getDiscountAmount,
|
|
293
|
+
isAllNormalProduct,
|
|
294
|
+
isNormalProductByDurationSchedule,
|
|
55
295
|
uniqueById
|
|
56
296
|
});
|