@pisell/pisellos 1.0.63 → 1.0.65
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/Cart/utils/cartProduct.js +9 -2
- package/dist/modules/Discount/types.d.ts +3 -0
- package/dist/modules/Rules/index.js +44 -17
- package/dist/solution/BookingByStep/utils/timeslots.js +88 -38
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/utils.d.ts +11 -0
- package/dist/solution/ShopDiscount/utils.js +29 -0
- package/lib/modules/Cart/utils/cartProduct.js +9 -2
- package/lib/modules/Discount/types.d.ts +3 -0
- package/lib/modules/Rules/index.js +30 -12
- package/lib/solution/BookingByStep/utils/timeslots.js +38 -3
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/utils.d.ts +11 -0
- package/lib/solution/ShopDiscount/utils.js +24 -0
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
12
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
13
|
import Decimal from 'decimal.js';
|
|
14
14
|
import { isNormalProduct } from "../../Product/utils";
|
|
15
|
+
import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @title 处理组合商品
|
|
@@ -192,8 +193,14 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
|
|
|
192
193
|
// 不是商品券则代表折扣卡,计算打折后的价格
|
|
193
194
|
// 一个商品折扣卡只能存在于一张
|
|
194
195
|
if (currentValue.type !== 'good_pass') {
|
|
195
|
-
var
|
|
196
|
-
price =
|
|
196
|
+
var _currentValue$discoun;
|
|
197
|
+
price = getDiscountAmount({
|
|
198
|
+
tag: currentValue.type,
|
|
199
|
+
par_value: currentValue.discount.percent,
|
|
200
|
+
metadata: {
|
|
201
|
+
discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
|
|
202
|
+
}
|
|
203
|
+
}, price, price);
|
|
197
204
|
}
|
|
198
205
|
});
|
|
199
206
|
}
|
|
@@ -70,6 +70,9 @@ export interface Discount {
|
|
|
70
70
|
limited_relation_product_data: Limitedrelationproductdata;
|
|
71
71
|
balance: string;
|
|
72
72
|
format_title: Formattitle;
|
|
73
|
+
metadata?: {
|
|
74
|
+
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
|
+
};
|
|
73
76
|
product: Product;
|
|
74
77
|
type: "product" | 'good_pass';
|
|
75
78
|
resource_id?: number;
|
|
@@ -25,7 +25,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
25
25
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
26
|
import { BaseModule } from "../BaseModule";
|
|
27
27
|
import { RulesHooks } from "./types";
|
|
28
|
-
import { uniqueById } from "../../solution/ShopDiscount/utils";
|
|
28
|
+
import { uniqueById, getDiscountAmount } from "../../solution/ShopDiscount/utils";
|
|
29
29
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
30
30
|
import Decimal from 'decimal.js';
|
|
31
31
|
import { isBoolean } from 'lodash-es';
|
|
@@ -189,8 +189,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
// 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
|
|
192
|
-
// 商品券(n.tag=good_pass
|
|
193
|
-
//
|
|
192
|
+
// 1. 商品券(n.tag=good_pass)视为最优惠(免费)
|
|
193
|
+
// 2. 折扣券(n.tag=product_discount_card)按照新的优先级排序:
|
|
194
|
+
// - 固定金额优先于百分比(固定金额 > 百分比)
|
|
195
|
+
// - 固定金额内部:金额越大越优先
|
|
196
|
+
// - 百分比内部:折扣越大越优先(par_value越小越优先)
|
|
197
|
+
// 3. 相同类型和金额的情况下,按照过期时间(n.expire_time)排序
|
|
194
198
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
195
199
|
// 1. 商品券优先级最高
|
|
196
200
|
if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
|
|
@@ -201,13 +205,34 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
201
205
|
// 都是商品券,按照过期时间排序
|
|
202
206
|
return compareByExpireTime(a, b);
|
|
203
207
|
} else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
var _a$metadata, _b$metadata;
|
|
209
|
+
// 都是折扣券,按照新的优先级排序:固定金额优先于百分比
|
|
210
|
+
var typeA = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 ? void 0 : _a$metadata.discount_card_type) || 'percent'; // 默认为百分比
|
|
211
|
+
var typeB = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 ? void 0 : _b$metadata.discount_card_type) || 'percent'; // 默认为百分比
|
|
212
|
+
|
|
213
|
+
// 1. 固定金额优先于百分比
|
|
214
|
+
if (typeA === 'fixed_amount' && typeB === 'percent') return -1;
|
|
215
|
+
if (typeA === 'percent' && typeB === 'fixed_amount') return 1;
|
|
216
|
+
|
|
217
|
+
// 2. 都是固定金额时,金额越大越优先
|
|
218
|
+
if (typeA === 'fixed_amount' && typeB === 'fixed_amount') {
|
|
219
|
+
if (a.par_value !== b.par_value) {
|
|
220
|
+
var valueA = new Decimal(a.par_value || 0);
|
|
221
|
+
var valueB = new Decimal(b.par_value || 0);
|
|
222
|
+
return valueB.minus(valueA).toNumber(); // 金额大的在前
|
|
223
|
+
}
|
|
209
224
|
}
|
|
210
|
-
|
|
225
|
+
|
|
226
|
+
// 3. 都是百分比时,折扣越大越优先(par_value越小越优先)
|
|
227
|
+
if (typeA === 'percent' && typeB === 'percent') {
|
|
228
|
+
if (a.par_value !== b.par_value) {
|
|
229
|
+
var _valueA = new Decimal(100).minus(a.par_value || 0);
|
|
230
|
+
var _valueB = new Decimal(100).minus(b.par_value || 0);
|
|
231
|
+
return _valueB.minus(_valueA).toNumber(); // 折扣大的在前
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 相同类型和金额的情况下,按照过期时间排序
|
|
211
236
|
return compareByExpireTime(a, b);
|
|
212
237
|
}
|
|
213
238
|
|
|
@@ -291,7 +316,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
291
316
|
|
|
292
317
|
// 判断优惠券是否适用于该商品
|
|
293
318
|
if (isAvailableProduct && isLimitedProduct) {
|
|
294
|
-
var _discountApplicabilit;
|
|
319
|
+
var _discountApplicabilit, _discount$metadata;
|
|
295
320
|
// 记录此优惠券适用的商品
|
|
296
321
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
297
322
|
|
|
@@ -303,6 +328,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
303
328
|
type: discountType,
|
|
304
329
|
tag: discountType,
|
|
305
330
|
discount: {
|
|
331
|
+
discount_card_type: discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type,
|
|
306
332
|
resource_id: discount.id,
|
|
307
333
|
title: discount.format_title,
|
|
308
334
|
original_amount: product.origin_total,
|
|
@@ -323,7 +349,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
323
349
|
console.log(sortedProductList, 'sortedProductListsortedProductList');
|
|
324
350
|
|
|
325
351
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
326
|
-
sortedProductList.forEach(function (originProduct,
|
|
352
|
+
sortedProductList.forEach(function (originProduct, index) {
|
|
327
353
|
var _product$discount_lis4, _product$discount_lis5, _product$discount_lis7, _product$discount_lis8, _product$discount_lis9, _product$discount_lis10, _product$discount_lis11;
|
|
328
354
|
var product = _this3.hooks.getProduct(originProduct);
|
|
329
355
|
if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length && product !== null && product !== void 0 && (_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.every(function (discount) {
|
|
@@ -415,7 +441,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
415
441
|
}))]);
|
|
416
442
|
} else {
|
|
417
443
|
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
418
|
-
_id: product._id.split('___')[0] + '___' +
|
|
444
|
+
_id: product._id.split('___')[0] + '___' + index,
|
|
419
445
|
total: product.origin_total || product.total,
|
|
420
446
|
price: product.price
|
|
421
447
|
}), {}, {
|
|
@@ -443,10 +469,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
443
469
|
_id: product._id.split('___')[0]
|
|
444
470
|
}));
|
|
445
471
|
}
|
|
446
|
-
for (var
|
|
447
|
-
var _product$discount_lis12, _originProduct$_produ;
|
|
472
|
+
for (var i = 0; i < splitCount; i++) {
|
|
473
|
+
var _product$discount_lis12, _originProduct$_produ, _selectedDiscount$met;
|
|
448
474
|
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
449
|
-
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[
|
|
475
|
+
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
450
476
|
// 标记优惠券为已使用
|
|
451
477
|
usedDiscounts.set(_selectedDiscount.id, true);
|
|
452
478
|
|
|
@@ -465,12 +491,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
465
491
|
}
|
|
466
492
|
|
|
467
493
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
468
|
-
var targetProductTotal = _selectedDiscount
|
|
494
|
+
var targetProductTotal = getDiscountAmount(_selectedDiscount, productOriginTotal, product.price);
|
|
469
495
|
var discountType = _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag;
|
|
470
496
|
var discountDetail = {
|
|
471
497
|
amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
|
|
472
498
|
type: discountType,
|
|
473
499
|
discount: {
|
|
500
|
+
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
474
501
|
resource_id: _selectedDiscount.id,
|
|
475
502
|
title: _selectedDiscount.format_title,
|
|
476
503
|
original_amount: productOriginTotal,
|
|
@@ -507,7 +534,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
507
534
|
} else {
|
|
508
535
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
509
536
|
discount_list: [discountDetail],
|
|
510
|
-
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
|
|
537
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
|
|
511
538
|
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
512
539
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
513
540
|
total: targetProductTotal,
|
|
@@ -107,29 +107,29 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
107
107
|
_step2;
|
|
108
108
|
try {
|
|
109
109
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
110
|
-
var
|
|
110
|
+
var _resource = _step2.value;
|
|
111
111
|
// 获取资源当天且还在工作时间内的时间段
|
|
112
|
-
var todayTimes =
|
|
112
|
+
var todayTimes = _resource.times.filter(function (time) {
|
|
113
113
|
var isToday = dayjs(time.start_at).isSame(currentTime, 'day');
|
|
114
114
|
var isStillWorking = dayjs(time.end_at).isAfter(currentTime);
|
|
115
115
|
return isToday && isStillWorking;
|
|
116
116
|
});
|
|
117
117
|
if (todayTimes.length === 0) {
|
|
118
|
-
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(
|
|
118
|
+
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, ") \u4ECA\u65E5\u65E0\u53EF\u7528\u65F6\u95F4\u6BB5"));
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
|
-
var
|
|
122
|
-
|
|
121
|
+
var _iterator4 = _createForOfIteratorHelper(todayTimes),
|
|
122
|
+
_step4;
|
|
123
123
|
try {
|
|
124
124
|
var _loop = function _loop() {
|
|
125
125
|
var _time$event_list, _time$event_list2;
|
|
126
|
-
var time =
|
|
126
|
+
var time = _step4.value;
|
|
127
127
|
var workStartTime = dayjs(time.start_at);
|
|
128
128
|
var workEndTime = dayjs(time.end_at);
|
|
129
129
|
|
|
130
130
|
// 确定检查的起始时间(当前时间 vs 工作开始时间)
|
|
131
131
|
var nextAvailableTime = currentTime.isBefore(workStartTime) ? workStartTime : currentTime;
|
|
132
|
-
console.log("[TimeslotUtils] \u68C0\u67E5\u8D44\u6E90 ".concat(
|
|
132
|
+
console.log("[TimeslotUtils] \u68C0\u67E5\u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, "):"), {
|
|
133
133
|
workTime: "".concat(workStartTime.format('HH:mm'), "-").concat(workEndTime.format('HH:mm')),
|
|
134
134
|
checkStartTime: nextAvailableTime.format('HH:mm:ss'),
|
|
135
135
|
eventCount: ((_time$event_list = time.event_list) === null || _time$event_list === void 0 ? void 0 : _time$event_list.length) || 0
|
|
@@ -148,40 +148,40 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
148
148
|
|
|
149
149
|
// 检查从 nextAvailableTime 开始的可用性
|
|
150
150
|
var finalAvailableTime = nextAvailableTime;
|
|
151
|
-
var
|
|
152
|
-
|
|
151
|
+
var _iterator5 = _createForOfIteratorHelper(relevantEvents),
|
|
152
|
+
_step5;
|
|
153
153
|
try {
|
|
154
|
-
for (
|
|
155
|
-
var
|
|
156
|
-
var
|
|
157
|
-
var
|
|
154
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
155
|
+
var _event = _step5.value;
|
|
156
|
+
var _eventStart = dayjs(_event.start_at);
|
|
157
|
+
var _eventEnd = dayjs(_event.end_at);
|
|
158
158
|
console.log("[TimeslotUtils] \u68C0\u67E5\u4E8B\u4EF6\u51B2\u7A81:", {
|
|
159
|
-
resourceId:
|
|
160
|
-
eventTime: "".concat(
|
|
159
|
+
resourceId: _resource.id,
|
|
160
|
+
eventTime: "".concat(_eventStart.format('HH:mm'), "-").concat(_eventEnd.format('HH:mm')),
|
|
161
161
|
checkTime: finalAvailableTime.format('HH:mm:ss'),
|
|
162
|
-
pax:
|
|
162
|
+
pax: _event.pax || 1
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
// 检查资源类型和容量
|
|
166
|
-
if (
|
|
166
|
+
if (_resource.resourceType === 'single' || (_resource.capacity || 1) === 1) {
|
|
167
167
|
// 单人预约资源:检查时间冲突
|
|
168
|
-
if (finalAvailableTime.isBefore(
|
|
168
|
+
if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(30, 'minute'))) {
|
|
169
169
|
// 有冲突,使用事件结束时间
|
|
170
|
-
finalAvailableTime =
|
|
170
|
+
finalAvailableTime = _eventEnd;
|
|
171
171
|
console.log("[TimeslotUtils] \u53D1\u73B0\u65F6\u95F4\u51B2\u7A81\uFF0C\u8C03\u6574\u5230: ".concat(finalAvailableTime.format('HH:mm:ss')));
|
|
172
172
|
}
|
|
173
173
|
} else {
|
|
174
174
|
// 多人预约资源:检查容量
|
|
175
|
-
var totalCapacity =
|
|
176
|
-
var currentUsedCapacity = countMap[
|
|
177
|
-
var eventUsedCapacity =
|
|
175
|
+
var totalCapacity = _resource.capacity || 0;
|
|
176
|
+
var currentUsedCapacity = countMap[_resource.id] || 0;
|
|
177
|
+
var eventUsedCapacity = _event.pax || 1;
|
|
178
178
|
|
|
179
179
|
// 如果在事件时间范围内,检查容量是否足够
|
|
180
|
-
if (finalAvailableTime.isBefore(
|
|
180
|
+
if (finalAvailableTime.isBefore(_eventEnd) && _eventStart.isBefore(finalAvailableTime.add(30, 'minute'))) {
|
|
181
181
|
var totalRequiredCapacity = currentUsedCapacity + currentCapacity + eventUsedCapacity;
|
|
182
182
|
if (totalRequiredCapacity > totalCapacity) {
|
|
183
183
|
// 容量不足,使用事件结束时间
|
|
184
|
-
finalAvailableTime =
|
|
184
|
+
finalAvailableTime = _eventEnd;
|
|
185
185
|
console.log("[TimeslotUtils] \u5BB9\u91CF\u4E0D\u8DB3\uFF0C\u8C03\u6574\u5230: ".concat(finalAvailableTime.format('HH:mm:ss')));
|
|
186
186
|
}
|
|
187
187
|
}
|
|
@@ -190,38 +190,38 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
190
190
|
|
|
191
191
|
// 确保可用时间在工作时间内
|
|
192
192
|
} catch (err) {
|
|
193
|
-
|
|
193
|
+
_iterator5.e(err);
|
|
194
194
|
} finally {
|
|
195
|
-
|
|
195
|
+
_iterator5.f();
|
|
196
196
|
}
|
|
197
197
|
if (finalAvailableTime.isAfter(workEndTime)) {
|
|
198
|
-
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(
|
|
198
|
+
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, " \u53EF\u7528\u65F6\u95F4\u8D85\u51FA\u5DE5\u4F5C\u65F6\u95F4\uFF0C\u8DF3\u8FC7"));
|
|
199
199
|
return 0; // continue
|
|
200
200
|
}
|
|
201
|
-
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(
|
|
201
|
+
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(_resource.id, "(").concat(_resource.main_field, ") \u6700\u5FEB\u53EF\u7528\u65F6\u95F4: ").concat(finalAvailableTime.format('HH:mm:ss')));
|
|
202
202
|
|
|
203
203
|
// 更新最快可用时间和资源
|
|
204
204
|
if (!fastestTime || finalAvailableTime.isBefore(fastestTime)) {
|
|
205
205
|
fastestTime = finalAvailableTime;
|
|
206
|
-
fastestResources = [
|
|
207
|
-
console.log("[TimeslotUtils] \u66F4\u65B0\u6700\u5FEB\u65F6\u95F4: ".concat(fastestTime.format('HH:mm:ss'), ", \u8D44\u6E90: ").concat(
|
|
206
|
+
fastestResources = [_resource];
|
|
207
|
+
console.log("[TimeslotUtils] \u66F4\u65B0\u6700\u5FEB\u65F6\u95F4: ".concat(fastestTime.format('HH:mm:ss'), ", \u8D44\u6E90: ").concat(_resource.main_field));
|
|
208
208
|
} else if (finalAvailableTime.isSame(fastestTime)) {
|
|
209
|
-
fastestResources.push(
|
|
210
|
-
console.log("[TimeslotUtils] \u6DFB\u52A0\u76F8\u540C\u65F6\u95F4\u8D44\u6E90: ".concat(
|
|
209
|
+
fastestResources.push(_resource);
|
|
210
|
+
console.log("[TimeslotUtils] \u6DFB\u52A0\u76F8\u540C\u65F6\u95F4\u8D44\u6E90: ".concat(_resource.main_field));
|
|
211
211
|
}
|
|
212
212
|
return 1; // break
|
|
213
213
|
// 每个资源只需要计算一次
|
|
214
214
|
},
|
|
215
215
|
_ret;
|
|
216
|
-
for (
|
|
216
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
217
217
|
_ret = _loop();
|
|
218
218
|
if (_ret === 0) continue;
|
|
219
219
|
if (_ret === 1) break;
|
|
220
220
|
}
|
|
221
221
|
} catch (err) {
|
|
222
|
-
|
|
222
|
+
_iterator4.e(err);
|
|
223
223
|
} finally {
|
|
224
|
-
|
|
224
|
+
_iterator4.f();
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -243,10 +243,60 @@ export function findFastestAvailableResource(_ref2) {
|
|
|
243
243
|
return fastestResources[0];
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
//
|
|
247
|
-
// 这里简化处理,直接返回第一个
|
|
246
|
+
// 如果有多个最快可用的资源,选择空闲时间最长的资源
|
|
248
247
|
var selectedResource = fastestResources[0];
|
|
249
|
-
|
|
248
|
+
var maxIdleTime = 0;
|
|
249
|
+
console.log("[TimeslotUtils] \u6BD4\u8F83 ".concat(fastestResources.length, " \u4E2A\u8D44\u6E90\u7684\u7A7A\u95F2\u65F6\u95F4:"));
|
|
250
|
+
for (var _i2 = 0, _fastestResources = fastestResources; _i2 < _fastestResources.length; _i2++) {
|
|
251
|
+
var _workingTime$event_li;
|
|
252
|
+
var resource = _fastestResources[_i2];
|
|
253
|
+
// 找到该资源当天且还在工作的时间段
|
|
254
|
+
var workingTime = resource.times.find(function (time) {
|
|
255
|
+
var isToday = dayjs(time.start_at).isSame(fastestTime, 'day');
|
|
256
|
+
var isStillWorking = dayjs(time.end_at).isAfter(fastestTime);
|
|
257
|
+
return isToday && isStillWorking;
|
|
258
|
+
});
|
|
259
|
+
if (!workingTime) continue;
|
|
260
|
+
var workEndTime = dayjs(workingTime.end_at);
|
|
261
|
+
|
|
262
|
+
// 计算从最快可用时间到工作结束时间的空闲时长(分钟)
|
|
263
|
+
var totalIdleTime = workEndTime.diff(fastestTime, 'minute');
|
|
264
|
+
|
|
265
|
+
// 减去已有预约占用的时间
|
|
266
|
+
var relevantEvents = ((_workingTime$event_li = workingTime.event_list) === null || _workingTime$event_li === void 0 ? void 0 : _workingTime$event_li.filter(function (event) {
|
|
267
|
+
var eventStart = dayjs(event.start_at);
|
|
268
|
+
var eventEnd = dayjs(event.end_at);
|
|
269
|
+
// 只计算在最快可用时间之后的预约
|
|
270
|
+
return eventEnd.isAfter(fastestTime) && eventStart.isAfter(fastestTime);
|
|
271
|
+
})) || [];
|
|
272
|
+
var _iterator3 = _createForOfIteratorHelper(relevantEvents),
|
|
273
|
+
_step3;
|
|
274
|
+
try {
|
|
275
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
276
|
+
var event = _step3.value;
|
|
277
|
+
var eventStart = dayjs(event.start_at);
|
|
278
|
+
var eventEnd = dayjs(event.end_at);
|
|
279
|
+
var eventDuration = eventEnd.diff(eventStart, 'minute');
|
|
280
|
+
totalIdleTime -= eventDuration;
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
_iterator3.e(err);
|
|
284
|
+
} finally {
|
|
285
|
+
_iterator3.f();
|
|
286
|
+
}
|
|
287
|
+
console.log("[TimeslotUtils] \u8D44\u6E90 ".concat(resource.id, "(").concat(resource.main_field, "):"), {
|
|
288
|
+
工作结束时间: workEndTime.format('HH:mm'),
|
|
289
|
+
总工作时长: workEndTime.diff(fastestTime, 'minute') + '分钟',
|
|
290
|
+
预约占用时长: workEndTime.diff(fastestTime, 'minute') - totalIdleTime + '分钟',
|
|
291
|
+
实际空闲时长: totalIdleTime + '分钟'
|
|
292
|
+
});
|
|
293
|
+
if (totalIdleTime > maxIdleTime) {
|
|
294
|
+
maxIdleTime = totalIdleTime;
|
|
295
|
+
selectedResource = resource;
|
|
296
|
+
console.log("[TimeslotUtils] \u66F4\u65B0\u6700\u4F73\u9009\u62E9: ".concat(resource.main_field, " (\u7A7A\u95F2").concat(totalIdleTime, "\u5206\u949F)"));
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
console.log("[TimeslotUtils] \u6700\u7EC8\u9009\u62E9\u8D44\u6E90: ".concat(selectedResource.main_field, " (\u6700\u957F\u7A7A\u95F2").concat(maxIdleTime, "\u5206\u949F)"));
|
|
250
300
|
return selectedResource;
|
|
251
301
|
}
|
|
252
302
|
|
|
@@ -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 客户状态
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Discount } from "../../modules/Discount/types";
|
|
1
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
/**
|
|
4
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
5
|
+
* 商品券:直接返回商品价格
|
|
6
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
7
|
+
* @param discount
|
|
8
|
+
* @param total
|
|
9
|
+
* @param price
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
+
import Decimal from "decimal.js";
|
|
1
2
|
export var uniqueById = function uniqueById(arr) {
|
|
2
3
|
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
|
|
3
4
|
var seen = new Set();
|
|
4
5
|
return arr.filter(function (item) {
|
|
5
6
|
return !seen.has(item[key]) && seen.add(item[key]);
|
|
6
7
|
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
12
|
+
* 商品券:直接返回商品价格
|
|
13
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
14
|
+
* @param discount
|
|
15
|
+
* @param total
|
|
16
|
+
* @param price
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
|
|
20
|
+
var _discount$metadata;
|
|
21
|
+
// 商品券
|
|
22
|
+
if (discount.tag === 'good_pass') {
|
|
23
|
+
return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 判断是否是固定金额
|
|
27
|
+
var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
|
|
28
|
+
|
|
29
|
+
// 固定金额 小于0时返回0
|
|
30
|
+
if (isFixedAmount) {
|
|
31
|
+
return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 百分比:根据折扣卡金额计算
|
|
35
|
+
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
|
|
7
36
|
};
|
|
@@ -44,6 +44,7 @@ __export(cartProduct_exports, {
|
|
|
44
44
|
module.exports = __toCommonJS(cartProduct_exports);
|
|
45
45
|
var import_decimal = __toESM(require("decimal.js"));
|
|
46
46
|
var import_utils = require("../../Product/utils");
|
|
47
|
+
var import_utils2 = require("../../../solution/ShopDiscount/utils");
|
|
47
48
|
var handleVariantProduct = (product) => {
|
|
48
49
|
var _a;
|
|
49
50
|
if (product == null ? void 0 : product.product_variant_id) {
|
|
@@ -183,9 +184,15 @@ var getProductTotalPrice = (params) => {
|
|
|
183
184
|
}
|
|
184
185
|
if (discounts == null ? void 0 : discounts.length) {
|
|
185
186
|
discounts.forEach((currentValue) => {
|
|
187
|
+
var _a;
|
|
186
188
|
if (currentValue.type !== "good_pass") {
|
|
187
|
-
|
|
188
|
-
|
|
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);
|
|
189
196
|
}
|
|
190
197
|
});
|
|
191
198
|
}
|
|
@@ -70,6 +70,9 @@ export interface Discount {
|
|
|
70
70
|
limited_relation_product_data: Limitedrelationproductdata;
|
|
71
71
|
balance: string;
|
|
72
72
|
format_title: Formattitle;
|
|
73
|
+
metadata?: {
|
|
74
|
+
discount_card_type?: 'fixed_amount' | 'percent';
|
|
75
|
+
};
|
|
73
76
|
product: Product;
|
|
74
77
|
type: "product" | 'good_pass';
|
|
75
78
|
resource_id?: number;
|
|
@@ -132,6 +132,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
132
132
|
return !discount.isManualSelect;
|
|
133
133
|
});
|
|
134
134
|
const sortedDiscountList = [...filteredDiscountList].sort((a, b) => {
|
|
135
|
+
var _a, _b;
|
|
135
136
|
if (a.tag === "good_pass" && b.tag !== "good_pass")
|
|
136
137
|
return -1;
|
|
137
138
|
if (b.tag === "good_pass" && a.tag !== "good_pass")
|
|
@@ -139,10 +140,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
139
140
|
if (a.tag === "good_pass" && b.tag === "good_pass") {
|
|
140
141
|
return compareByExpireTime(a, b);
|
|
141
142
|
} else if (a.tag === "product_discount_card" && b.tag === "product_discount_card") {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return
|
|
143
|
+
const typeA = ((_a = a.metadata) == null ? void 0 : _a.discount_card_type) || "percent";
|
|
144
|
+
const typeB = ((_b = b.metadata) == null ? void 0 : _b.discount_card_type) || "percent";
|
|
145
|
+
if (typeA === "fixed_amount" && typeB === "percent")
|
|
146
|
+
return -1;
|
|
147
|
+
if (typeA === "percent" && typeB === "fixed_amount")
|
|
148
|
+
return 1;
|
|
149
|
+
if (typeA === "fixed_amount" && typeB === "fixed_amount") {
|
|
150
|
+
if (a.par_value !== b.par_value) {
|
|
151
|
+
const valueA = new import_decimal.default(a.par_value || 0);
|
|
152
|
+
const valueB = new import_decimal.default(b.par_value || 0);
|
|
153
|
+
return valueB.minus(valueA).toNumber();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (typeA === "percent" && typeB === "percent") {
|
|
157
|
+
if (a.par_value !== b.par_value) {
|
|
158
|
+
const valueA = new import_decimal.default(100).minus(a.par_value || 0);
|
|
159
|
+
const valueB = new import_decimal.default(100).minus(b.par_value || 0);
|
|
160
|
+
return valueB.minus(valueA).toNumber();
|
|
161
|
+
}
|
|
146
162
|
}
|
|
147
163
|
return compareByExpireTime(a, b);
|
|
148
164
|
}
|
|
@@ -182,7 +198,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
182
198
|
sortedProductList.forEach((originProduct) => {
|
|
183
199
|
const product = this.hooks.getProduct(originProduct);
|
|
184
200
|
addModeDiscount.forEach((discount) => {
|
|
185
|
-
var _a, _b, _c;
|
|
201
|
+
var _a, _b, _c, _d;
|
|
186
202
|
const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
|
|
187
203
|
const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
|
|
188
204
|
const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type))));
|
|
@@ -195,6 +211,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
195
211
|
type: discountType,
|
|
196
212
|
tag: discountType,
|
|
197
213
|
discount: {
|
|
214
|
+
discount_card_type: (_d = discount == null ? void 0 : discount.metadata) == null ? void 0 : _d.discount_card_type,
|
|
198
215
|
resource_id: discount.id,
|
|
199
216
|
title: discount.format_title,
|
|
200
217
|
original_amount: product.origin_total,
|
|
@@ -211,8 +228,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
211
228
|
});
|
|
212
229
|
});
|
|
213
230
|
console.log(sortedProductList, "sortedProductListsortedProductList");
|
|
214
|
-
sortedProductList.forEach((originProduct,
|
|
215
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
231
|
+
sortedProductList.forEach((originProduct, index) => {
|
|
232
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
216
233
|
const product = this.hooks.getProduct(originProduct);
|
|
217
234
|
if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
|
|
218
235
|
processedProductsMap.set(product._id, [originProduct]);
|
|
@@ -288,7 +305,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
288
305
|
product._id,
|
|
289
306
|
[this.hooks.setProduct(originProduct, {
|
|
290
307
|
...isManualDiscount ? {} : {
|
|
291
|
-
_id: product._id.split("___")[0] + "___" +
|
|
308
|
+
_id: product._id.split("___")[0] + "___" + index,
|
|
292
309
|
total: product.origin_total || product.total,
|
|
293
310
|
price: product.price
|
|
294
311
|
},
|
|
@@ -311,8 +328,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
311
328
|
_id: product._id.split("___")[0]
|
|
312
329
|
}));
|
|
313
330
|
}
|
|
314
|
-
for (let
|
|
315
|
-
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[
|
|
331
|
+
for (let i = 0; i < splitCount; i++) {
|
|
332
|
+
const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
|
|
316
333
|
usedDiscounts.set(selectedDiscount2.id, true);
|
|
317
334
|
const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
|
|
318
335
|
let productOriginTotal = product.origin_total || product.total || 0;
|
|
@@ -322,12 +339,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
322
339
|
if (Number(((_i = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _i.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
|
|
323
340
|
productOriginTotal = product.total;
|
|
324
341
|
}
|
|
325
|
-
const targetProductTotal =
|
|
342
|
+
const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, productOriginTotal, product.price);
|
|
326
343
|
const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
|
|
327
344
|
const discountDetail = {
|
|
328
345
|
amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
|
|
329
346
|
type: discountType,
|
|
330
347
|
discount: {
|
|
348
|
+
discount_card_type: (_j = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _j.discount_card_type,
|
|
331
349
|
resource_id: selectedDiscount2.id,
|
|
332
350
|
title: selectedDiscount2.format_title,
|
|
333
351
|
original_amount: productOriginTotal,
|
|
@@ -359,7 +377,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
359
377
|
} else {
|
|
360
378
|
arr.push(this.hooks.setProduct(originProduct, {
|
|
361
379
|
discount_list: [discountDetail],
|
|
362
|
-
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
|
|
380
|
+
_id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
|
|
363
381
|
price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
|
|
364
382
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
365
383
|
total: targetProductTotal,
|
|
@@ -79,7 +79,7 @@ function findFastestAvailableResource({
|
|
|
79
79
|
currentCapacity = 1,
|
|
80
80
|
countMap = {}
|
|
81
81
|
}) {
|
|
82
|
-
var _a, _b;
|
|
82
|
+
var _a, _b, _c;
|
|
83
83
|
const currentTime = (0, import_dayjs.default)();
|
|
84
84
|
let fastestTime = null;
|
|
85
85
|
let fastestResources = [];
|
|
@@ -168,8 +168,43 @@ function findFastestAvailableResource({
|
|
|
168
168
|
console.log(`[TimeslotUtils] 返回唯一最快资源: ${fastestResources[0].main_field}`);
|
|
169
169
|
return fastestResources[0];
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
let selectedResource = fastestResources[0];
|
|
172
|
+
let maxIdleTime = 0;
|
|
173
|
+
console.log(`[TimeslotUtils] 比较 ${fastestResources.length} 个资源的空闲时间:`);
|
|
174
|
+
for (const resource of fastestResources) {
|
|
175
|
+
const workingTime = resource.times.find((time) => {
|
|
176
|
+
const isToday = (0, import_dayjs.default)(time.start_at).isSame(fastestTime, "day");
|
|
177
|
+
const isStillWorking = (0, import_dayjs.default)(time.end_at).isAfter(fastestTime);
|
|
178
|
+
return isToday && isStillWorking;
|
|
179
|
+
});
|
|
180
|
+
if (!workingTime)
|
|
181
|
+
continue;
|
|
182
|
+
const workEndTime = (0, import_dayjs.default)(workingTime.end_at);
|
|
183
|
+
let totalIdleTime = workEndTime.diff(fastestTime, "minute");
|
|
184
|
+
const relevantEvents = ((_c = workingTime.event_list) == null ? void 0 : _c.filter((event) => {
|
|
185
|
+
const eventStart = (0, import_dayjs.default)(event.start_at);
|
|
186
|
+
const eventEnd = (0, import_dayjs.default)(event.end_at);
|
|
187
|
+
return eventEnd.isAfter(fastestTime) && eventStart.isAfter(fastestTime);
|
|
188
|
+
})) || [];
|
|
189
|
+
for (const event of relevantEvents) {
|
|
190
|
+
const eventStart = (0, import_dayjs.default)(event.start_at);
|
|
191
|
+
const eventEnd = (0, import_dayjs.default)(event.end_at);
|
|
192
|
+
const eventDuration = eventEnd.diff(eventStart, "minute");
|
|
193
|
+
totalIdleTime -= eventDuration;
|
|
194
|
+
}
|
|
195
|
+
console.log(`[TimeslotUtils] 资源 ${resource.id}(${resource.main_field}):`, {
|
|
196
|
+
工作结束时间: workEndTime.format("HH:mm"),
|
|
197
|
+
总工作时长: workEndTime.diff(fastestTime, "minute") + "分钟",
|
|
198
|
+
预约占用时长: workEndTime.diff(fastestTime, "minute") - totalIdleTime + "分钟",
|
|
199
|
+
实际空闲时长: totalIdleTime + "分钟"
|
|
200
|
+
});
|
|
201
|
+
if (totalIdleTime > maxIdleTime) {
|
|
202
|
+
maxIdleTime = totalIdleTime;
|
|
203
|
+
selectedResource = resource;
|
|
204
|
+
console.log(`[TimeslotUtils] 更新最佳选择: ${resource.main_field} (空闲${totalIdleTime}分钟)`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
console.log(`[TimeslotUtils] 最终选择资源: ${selectedResource.main_field} (最长空闲${maxIdleTime}分钟)`);
|
|
173
208
|
return selectedResource;
|
|
174
209
|
}
|
|
175
210
|
function filterConditionTimeSlots(times, startTime, endTime) {
|
|
@@ -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 客户状态
|
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { Discount } from "../../modules/Discount/types";
|
|
1
2
|
export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
|
|
3
|
+
/**
|
|
4
|
+
* 获取折扣金额 基于折扣卡类型计算
|
|
5
|
+
* 商品券:直接返回商品价格
|
|
6
|
+
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
7
|
+
* @param discount
|
|
8
|
+
* @param total
|
|
9
|
+
* @param price
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,19 +16,41 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/solution/ShopDiscount/utils.ts
|
|
20
30
|
var utils_exports = {};
|
|
21
31
|
__export(utils_exports, {
|
|
32
|
+
getDiscountAmount: () => getDiscountAmount,
|
|
22
33
|
uniqueById: () => uniqueById
|
|
23
34
|
});
|
|
24
35
|
module.exports = __toCommonJS(utils_exports);
|
|
36
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
25
37
|
var uniqueById = (arr, key = "id") => {
|
|
26
38
|
const seen = /* @__PURE__ */ new Set();
|
|
27
39
|
return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
|
|
28
40
|
};
|
|
41
|
+
var getDiscountAmount = (discount, total, price) => {
|
|
42
|
+
var _a;
|
|
43
|
+
if (discount.tag === "good_pass") {
|
|
44
|
+
return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
|
|
45
|
+
}
|
|
46
|
+
const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
|
|
47
|
+
if (isFixedAmount) {
|
|
48
|
+
return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
|
|
49
|
+
}
|
|
50
|
+
return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
|
|
51
|
+
};
|
|
29
52
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
53
|
0 && (module.exports = {
|
|
54
|
+
getDiscountAmount,
|
|
31
55
|
uniqueById
|
|
32
56
|
});
|