@pisell/pisellos 0.0.320 → 0.0.321
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/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +4 -0
- package/dist/solution/ShopDiscount/index.js +190 -101
- package/dist/solution/ShopDiscount/types.d.ts +4 -1
- package/dist/solution/ShopDiscount/utils.d.ts +48 -0
- package/dist/solution/ShopDiscount/utils.js +281 -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/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +4 -0
- package/lib/solution/ShopDiscount/index.js +44 -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 +172 -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,268 @@ 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
|
+
var scheduleDate = schedule.start_time.split(' ')[0];
|
|
127
|
+
|
|
128
|
+
// 检查日期是否匹配
|
|
129
|
+
if (targetDateString !== scheduleDate) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 检查是否在任一时间段内
|
|
134
|
+
var _iterator2 = _createForOfIteratorHelper(schedule.time_slot),
|
|
135
|
+
_step2;
|
|
136
|
+
try {
|
|
137
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
138
|
+
var timeSlot = _step2.value;
|
|
139
|
+
var slotStart = "".concat(scheduleDate, " ").concat(timeSlot.start_time, ":00");
|
|
140
|
+
var slotEnd = "".concat(scheduleDate, " ").concat(timeSlot.end_time, ":00");
|
|
141
|
+
var slotStartDate = dayjs(slotStart);
|
|
142
|
+
var slotEndDate = dayjs(slotEnd);
|
|
143
|
+
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch (err) {
|
|
148
|
+
_iterator2.e(err);
|
|
149
|
+
} finally {
|
|
150
|
+
_iterator2.f();
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// 处理指定类型日程
|
|
156
|
+
var isInDesignationSchedule = function isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule) {
|
|
157
|
+
if (!schedule.designation) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
var _iterator3 = _createForOfIteratorHelper(schedule.designation),
|
|
161
|
+
_step3;
|
|
162
|
+
try {
|
|
163
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
164
|
+
var designation = _step3.value;
|
|
165
|
+
var startDateTime = "".concat(designation.start_date, " ").concat(designation.start_time, ":00");
|
|
166
|
+
var endDateTime = "".concat(designation.end_date, " ").concat(designation.end_time, ":00");
|
|
167
|
+
var startDate = dayjs(startDateTime);
|
|
168
|
+
var endDate = dayjs(endDateTime);
|
|
169
|
+
if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
_iterator3.e(err);
|
|
175
|
+
} finally {
|
|
176
|
+
_iterator3.f();
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// 处理重复日程逻辑
|
|
182
|
+
var isInRepeatingSchedule = function isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) {
|
|
183
|
+
if (!schedule.repeat_rule) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
var repeat_rule = schedule.repeat_rule,
|
|
187
|
+
repeat_type = schedule.repeat_type;
|
|
188
|
+
var targetDateOnly = dayjs(targetDateString); // 只取日期部分
|
|
189
|
+
|
|
190
|
+
// 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
|
|
191
|
+
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
192
|
+
var _iterator4 = _createForOfIteratorHelper(repeat_rule.included_date),
|
|
193
|
+
_step4;
|
|
194
|
+
try {
|
|
195
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
196
|
+
var includedDate = _step4.value;
|
|
197
|
+
var includeStartDate = dayjs(includedDate.start);
|
|
198
|
+
var includeEndDate = dayjs(includedDate.end);
|
|
199
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
|
|
200
|
+
// 在包含日期中,直接返回true,无需检查其他条件
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
_iterator4.e(err);
|
|
206
|
+
} finally {
|
|
207
|
+
_iterator4.f();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 检查是否在排除日期中
|
|
212
|
+
var _iterator5 = _createForOfIteratorHelper(repeat_rule.excluded_date),
|
|
213
|
+
_step5;
|
|
214
|
+
try {
|
|
215
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
216
|
+
var excludedDate = _step5.value;
|
|
217
|
+
var excludeStartDate = dayjs(excludedDate.start);
|
|
218
|
+
var excludeEndDate = dayjs(excludedDate.end);
|
|
219
|
+
// 检查目标日期是否在排除范围内(包含边界)
|
|
220
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 检查重复规则的结束条件
|
|
226
|
+
} catch (err) {
|
|
227
|
+
_iterator5.e(err);
|
|
228
|
+
} finally {
|
|
229
|
+
_iterator5.f();
|
|
230
|
+
}
|
|
231
|
+
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
232
|
+
var ruleEndDate = dayjs(repeat_rule.end.end_date);
|
|
233
|
+
if (targetDate.isAfter(ruleEndDate)) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 根据重复类型检查
|
|
239
|
+
switch (repeat_type) {
|
|
240
|
+
case 'daily':
|
|
241
|
+
return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
242
|
+
case 'weekly':
|
|
243
|
+
return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
244
|
+
default:
|
|
245
|
+
return false;
|
|
246
|
+
// 不支持月和年重复
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// 每日重复逻辑
|
|
251
|
+
var isInDailyRepeat = function isInDailyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
252
|
+
var daysDiff = targetDate.diff(startDate, 'day');
|
|
253
|
+
if (daysDiff < 0) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// 检查频率
|
|
258
|
+
if (daysDiff % repeatRule.frequency !== 0) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// 检查时间是否在日程的时间范围内
|
|
263
|
+
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
264
|
+
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
265
|
+
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
266
|
+
|
|
267
|
+
// 每日重复:每天都在相同的时间段内有效
|
|
268
|
+
// 例如:01:00:00 - 16:00:00,每天都是这个时间段
|
|
269
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// 每周重复逻辑
|
|
273
|
+
var isInWeeklyRepeat = function isInWeeklyRepeat(targetDate, startDate, endDate, repeatRule) {
|
|
274
|
+
var targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
275
|
+
|
|
276
|
+
// 检查是否在指定的星期几内
|
|
277
|
+
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 计算周差
|
|
282
|
+
var weeksDiff = targetDate.diff(startDate, 'week');
|
|
283
|
+
if (weeksDiff < 0) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 检查频率
|
|
288
|
+
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 检查时间是否在日程的时间范围内
|
|
293
|
+
var targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
294
|
+
var startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
295
|
+
var endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
296
|
+
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 根据预约时间过滤优惠券列表
|
|
301
|
+
* @param discountList 优惠券列表
|
|
302
|
+
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
303
|
+
* @returns 过滤后的优惠券列表
|
|
304
|
+
*/
|
|
305
|
+
export var filterDiscountListByBookingTime = function filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
306
|
+
if (!bookingTime) {
|
|
307
|
+
return discountList;
|
|
308
|
+
}
|
|
309
|
+
return discountList.filter(function (discount) {
|
|
310
|
+
var _discount$metadata2, _discount$metadata3, _discount$custom_sche;
|
|
311
|
+
debugger;
|
|
312
|
+
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") {
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
return getDateIsInSchedule(bookingTime, ((_discount$custom_sche = discount.custom_schedule_snapshot) === null || _discount$custom_sche === void 0 ? void 0 : _discount$custom_sche.data) || []);
|
|
316
|
+
});
|
|
36
317
|
};
|
|
@@ -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
|
}
|
|
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
111
111
|
* 获取当前的客户搜索条件
|
|
112
112
|
* @returns 当前搜索条件
|
|
113
113
|
*/
|
|
114
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
114
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
115
115
|
/**
|
|
116
116
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
117
117
|
* @returns 客户状态
|
|
@@ -18,6 +18,10 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
18
18
|
private initializePlugins;
|
|
19
19
|
private registerDependentModules;
|
|
20
20
|
private registerEventListeners;
|
|
21
|
+
setBookingTime(bookingTime: string | null): Promise<void>;
|
|
22
|
+
getCurrentBookingTime(): string | null;
|
|
23
|
+
private filterDiscountListByBookingTime;
|
|
24
|
+
private updateFilteredDiscountList;
|
|
21
25
|
setCustomer(customer: Customer): Promise<void>;
|
|
22
26
|
calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
|
|
23
27
|
productList: Record<string, any>[];
|
|
@@ -37,6 +37,7 @@ var import_BaseModule = require("../../modules/BaseModule");
|
|
|
37
37
|
var import_types = require("./types");
|
|
38
38
|
var import_Discount = require("../../modules/Discount");
|
|
39
39
|
var import_Rules = require("../../modules/Rules");
|
|
40
|
+
var import_utils = require("./utils");
|
|
40
41
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
42
|
var import_lodash_es = require("lodash-es");
|
|
42
43
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -51,7 +52,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
51
52
|
productList: [],
|
|
52
53
|
discount: null,
|
|
53
54
|
rules: null,
|
|
54
|
-
originalDiscountList: []
|
|
55
|
+
originalDiscountList: [],
|
|
56
|
+
currentBookingTime: "",
|
|
57
|
+
filteredDiscountList: []
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
// =========== 生命周期方法 ===========
|
|
@@ -140,6 +143,39 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
140
143
|
);
|
|
141
144
|
}
|
|
142
145
|
// =========== 公共 API ===========
|
|
146
|
+
// 设置预约时间
|
|
147
|
+
async setBookingTime(bookingTime) {
|
|
148
|
+
if (this.store.currentBookingTime !== bookingTime) {
|
|
149
|
+
this.store.currentBookingTime = bookingTime;
|
|
150
|
+
await this.updateFilteredDiscountList();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// 获取当前预约时间
|
|
154
|
+
getCurrentBookingTime() {
|
|
155
|
+
return this.store.currentBookingTime;
|
|
156
|
+
}
|
|
157
|
+
// 根据预约时间过滤优惠券列表
|
|
158
|
+
filterDiscountListByBookingTime(discountList, bookingTime) {
|
|
159
|
+
if ((0, import_utils.isAllNormalProduct)(this.store.productList || [])) {
|
|
160
|
+
return discountList;
|
|
161
|
+
}
|
|
162
|
+
return (0, import_utils.filterDiscountListByBookingTime)(discountList, bookingTime);
|
|
163
|
+
}
|
|
164
|
+
// 更新过滤后的优惠券列表
|
|
165
|
+
async updateFilteredDiscountList() {
|
|
166
|
+
var _a;
|
|
167
|
+
const originalList = this.store.originalDiscountList;
|
|
168
|
+
const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
|
|
169
|
+
this.store.filteredDiscountList = filteredList;
|
|
170
|
+
this.setDiscountList(filteredList);
|
|
171
|
+
if ((_a = this.store.productList) == null ? void 0 : _a.length) {
|
|
172
|
+
const result = this.calcDiscount(this.store.productList);
|
|
173
|
+
await this.core.effects.emit(
|
|
174
|
+
import_types.ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
175
|
+
result
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
143
179
|
// 设置客户
|
|
144
180
|
async setCustomer(customer) {
|
|
145
181
|
var _a;
|
|
@@ -417,7 +453,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
417
453
|
}
|
|
418
454
|
// 加载准备配置
|
|
419
455
|
async loadPrepareConfig(params) {
|
|
420
|
-
var _a, _b, _c, _d;
|
|
456
|
+
var _a, _b, _c, _d, _e;
|
|
421
457
|
try {
|
|
422
458
|
const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
|
|
423
459
|
const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
@@ -433,8 +469,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
433
469
|
const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
|
|
434
470
|
const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
|
|
435
471
|
this.store.originalDiscountList = newDiscountList;
|
|
436
|
-
this.
|
|
437
|
-
|
|
472
|
+
await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
|
|
473
|
+
const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
|
|
474
|
+
this.store.filteredDiscountList = filteredDiscountList;
|
|
475
|
+
this.setDiscountList(filteredDiscountList || []);
|
|
476
|
+
if ((_e = this.store.productList) == null ? void 0 : _e.length) {
|
|
438
477
|
const result = this.calcDiscount(this.store.productList);
|
|
439
478
|
await this.core.effects.emit(
|
|
440
479
|
import_types.ShopDiscountHooks.onLoadPrepareCalcResult,
|
|
@@ -443,7 +482,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
443
482
|
}
|
|
444
483
|
await this.core.effects.emit(
|
|
445
484
|
import_types.ShopDiscountHooks.onLoadDiscountList,
|
|
446
|
-
|
|
485
|
+
filteredDiscountList
|
|
447
486
|
);
|
|
448
487
|
} catch (error) {
|
|
449
488
|
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[];
|