@pisell/pisellos 2.1.60 → 2.1.61
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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/modules/Cart/types.d.ts +0 -2
- package/dist/modules/Cart/utils/cartProduct.js +0 -11
- package/dist/modules/Customer/index.js +1 -1
- package/dist/modules/Discount/types.d.ts +0 -15
- package/dist/modules/Payment/index.d.ts +1 -2
- package/dist/modules/Payment/index.js +7 -10
- package/dist/modules/Payment/utils.js +0 -3
- package/dist/modules/Payment/walletpass.d.ts +0 -23
- package/dist/modules/Payment/walletpass.js +95 -191
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +3 -8
- package/dist/modules/Rules/index.js +28 -158
- package/dist/modules/Rules/types.d.ts +0 -1
- package/dist/modules/Summary/types.d.ts +0 -2
- package/dist/modules/Summary/utils.d.ts +0 -6
- package/dist/modules/Summary/utils.js +0 -21
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +0 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.js +0 -2
- package/dist/solution/ShopDiscount/index.d.ts +0 -1
- package/dist/solution/ShopDiscount/index.js +1 -11
- package/dist/solution/ShopDiscount/types.d.ts +0 -1
- package/dist/solution/ShopDiscount/utils.js +11 -26
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/modules/Cart/types.d.ts +0 -2
- package/lib/modules/Cart/utils/cartProduct.js +0 -9
- package/lib/modules/Customer/index.js +1 -1
- package/lib/modules/Discount/types.d.ts +0 -15
- package/lib/modules/Payment/index.d.ts +1 -2
- package/lib/modules/Payment/index.js +0 -1
- package/lib/modules/Payment/utils.js +0 -3
- package/lib/modules/Payment/walletpass.d.ts +0 -23
- package/lib/modules/Payment/walletpass.js +17 -94
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +3 -8
- package/lib/modules/Rules/index.js +191 -373
- package/lib/modules/Rules/types.d.ts +0 -1
- package/lib/modules/Summary/types.d.ts +0 -2
- package/lib/modules/Summary/utils.d.ts +0 -6
- package/lib/modules/Summary/utils.js +0 -15
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +0 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +6 -0
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +0 -6
- package/lib/solution/ShopDiscount/types.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.js +6 -10
- package/package.json +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.js +0 -1
- package/dist/model/strategy/adapter/index.d.ts +0 -3
- package/dist/model/strategy/adapter/index.js +0 -4
- package/dist/model/strategy/adapter/type.d.ts +0 -28
- package/dist/model/strategy/adapter/type.js +0 -1
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -496
- package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
- package/dist/model/strategy/adapter/walletPass/example.js +0 -258
- package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
- package/dist/model/strategy/adapter/walletPass/index.js +0 -182
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
- package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -163
- package/dist/model/strategy/adapter/walletPass/type.js +0 -1
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
- package/dist/model/strategy/index.d.ts +0 -94
- package/dist/model/strategy/index.js +0 -551
- package/dist/model/strategy/strategy-example.d.ts +0 -5
- package/dist/model/strategy/strategy-example.js +0 -331
- package/dist/model/strategy/type.d.ts +0 -228
- package/dist/model/strategy/type.js +0 -94
- package/lib/model/index.d.ts +0 -1
- package/lib/model/index.js +0 -23
- package/lib/model/strategy/adapter/index.d.ts +0 -3
- package/lib/model/strategy/adapter/index.js +0 -45
- package/lib/model/strategy/adapter/type.d.ts +0 -28
- package/lib/model/strategy/adapter/type.js +0 -17
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -420
- package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
- package/lib/model/strategy/adapter/walletPass/example.js +0 -207
- package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
- package/lib/model/strategy/adapter/walletPass/index.js +0 -142
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
- package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -163
- package/lib/model/strategy/adapter/walletPass/type.js +0 -17
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
- package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
- package/lib/model/strategy/index.d.ts +0 -94
- package/lib/model/strategy/index.js +0 -413
- package/lib/model/strategy/strategy-example.d.ts +0 -5
- package/lib/model/strategy/strategy-example.js +0 -318
- package/lib/model/strategy/type.d.ts +0 -228
- package/lib/model/strategy/type.js +0 -44
|
@@ -24,11 +24,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
24
24
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
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
|
-
import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount
|
|
27
|
+
import { uniqueById, getDiscountAmount, filterDiscountListByBookingTime, getDiscountListAmountTotal, getDiscountListAmount } from "../../solution/ShopDiscount/utils";
|
|
28
28
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
29
29
|
import Decimal from 'decimal.js';
|
|
30
30
|
import { isBoolean } from 'lodash-es';
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
|
+
|
|
32
33
|
// 临时变量
|
|
33
34
|
var flatItem;
|
|
34
35
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
@@ -41,8 +42,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
41
42
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
|
|
42
43
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
43
44
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
44
|
-
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
45
|
-
// WindowPlugin 实例
|
|
46
45
|
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
47
46
|
_this.hooks = {};
|
|
48
47
|
return _this;
|
|
@@ -57,8 +56,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
57
56
|
this.core = core;
|
|
58
57
|
this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
|
|
59
58
|
this.store = options === null || options === void 0 ? void 0 : options.store;
|
|
60
|
-
|
|
61
|
-
case 4:
|
|
59
|
+
case 3:
|
|
62
60
|
case "end":
|
|
63
61
|
return _context.stop();
|
|
64
62
|
}
|
|
@@ -95,12 +93,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
95
93
|
value: function getRulesList() {
|
|
96
94
|
return this.store.rulesList;
|
|
97
95
|
}
|
|
98
|
-
}, {
|
|
99
|
-
key: "getWalletPassEvaluator",
|
|
100
|
-
value: function getWalletPassEvaluator() {
|
|
101
|
-
var _this$window$getWalle, _this$window;
|
|
102
|
-
return (_this$window$getWalle = (_this$window = this.window).getWalletPassEvaluator) === null || _this$window$getWalle === void 0 ? void 0 : _this$window$getWalle.call(_this$window);
|
|
103
|
-
}
|
|
104
96
|
|
|
105
97
|
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
106
98
|
}, {
|
|
@@ -130,7 +122,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
130
122
|
newDiscountList = _ref.newDiscountList,
|
|
131
123
|
productList = _ref.productList,
|
|
132
124
|
holders = _ref.holders,
|
|
133
|
-
orderTotalAmount = _ref.orderTotalAmount,
|
|
134
125
|
isFormSubject = _ref.isFormSubject;
|
|
135
126
|
// 首先检查是否有新的优惠券可应用
|
|
136
127
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
@@ -163,7 +154,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
163
154
|
discountList: mergedDiscountList,
|
|
164
155
|
productList: _toConsumableArray(productList),
|
|
165
156
|
holders: holders,
|
|
166
|
-
orderTotalAmount: orderTotalAmount,
|
|
167
157
|
isFormSubject: isFormSubject
|
|
168
158
|
}, {
|
|
169
159
|
scan: true
|
|
@@ -208,7 +198,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
208
198
|
var discountList = _ref2.discountList,
|
|
209
199
|
productList = _ref2.productList,
|
|
210
200
|
holders = _ref2.holders,
|
|
211
|
-
orderTotalAmount = _ref2.orderTotalAmount,
|
|
212
201
|
isFormSubject = _ref2.isFormSubject;
|
|
213
202
|
// 识别出来是不是在编辑的界面里又新增了商品
|
|
214
203
|
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
@@ -383,57 +372,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
383
372
|
return priceB.minus(priceA).toNumber();
|
|
384
373
|
});
|
|
385
374
|
|
|
386
|
-
// 🔥 为每个折扣卡/商品券执行策略检查并附加config
|
|
387
|
-
var evaluator = this.getWalletPassEvaluator();
|
|
388
|
-
if (evaluator) {
|
|
389
|
-
addModeDiscount.forEach(function (discount) {
|
|
390
|
-
var discountType = discount.tag || discount.type;
|
|
391
|
-
// 只对 good_pass 和 discount_card 类型执行策略检查
|
|
392
|
-
if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
|
|
393
|
-
var _discount$limited_rel, _discount$limited_rel2;
|
|
394
|
-
// 转换 discount 为 Voucher 格式
|
|
395
|
-
var voucher = {
|
|
396
|
-
id: discount.id,
|
|
397
|
-
amount: Number(discount.par_value || 0),
|
|
398
|
-
balance: Number(discount.balance || 0),
|
|
399
|
-
type: discountType,
|
|
400
|
-
product_id: discount.product_id,
|
|
401
|
-
unified_available_status: 1,
|
|
402
|
-
available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
|
|
403
|
-
available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
// 转换 sortedFlattenedList 为 Product 格式
|
|
407
|
-
var productsForEvaluate = sortedFlattenedList.map(function (item) {
|
|
408
|
-
return {
|
|
409
|
-
product_id: item.id,
|
|
410
|
-
price: item.price || 0,
|
|
411
|
-
quantity: item.quantity || item.num || 1,
|
|
412
|
-
selling_price: item.price || 0
|
|
413
|
-
};
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
// 调用策略检查
|
|
417
|
-
var result = evaluator.checkVoucherAvailability({
|
|
418
|
-
orderTotalAmount: orderTotalAmount,
|
|
419
|
-
products: productsForEvaluate,
|
|
420
|
-
vouchers: [voucher]
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
// 将 config 附加到 discount 对象
|
|
424
|
-
if (result.isAvailable) {
|
|
425
|
-
discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
|
|
426
|
-
isAvailable: true
|
|
427
|
-
});
|
|
428
|
-
} else {
|
|
429
|
-
discount.config = {
|
|
430
|
-
isAvailable: false
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
|
|
437
375
|
/**
|
|
438
376
|
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
439
377
|
const sortedProductList = [...productList].sort((a, b) => {
|
|
@@ -454,9 +392,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
454
392
|
// 标记已使用的优惠券
|
|
455
393
|
var usedDiscounts = new Map();
|
|
456
394
|
|
|
457
|
-
// 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
|
|
458
|
-
var usedProductIdCounts = new Map();
|
|
459
|
-
|
|
460
395
|
// 记录每个优惠券适用的商品ID
|
|
461
396
|
var discountApplicability = new Map();
|
|
462
397
|
|
|
@@ -499,7 +434,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
499
434
|
originProduct = flatItem.originProduct;
|
|
500
435
|
}
|
|
501
436
|
addModeDiscount.forEach(function (discount) {
|
|
502
|
-
var _product, _product2, _product3, _product4, _flatItem$bundleItem
|
|
437
|
+
var _product, _product2, _product3, _product4, _flatItem$bundleItem;
|
|
503
438
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
504
439
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
505
440
|
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
@@ -510,7 +445,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
510
445
|
var timeLimit = true;
|
|
511
446
|
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
512
447
|
// 是符合折扣的商品
|
|
513
|
-
var isLimitedProduct = (limitedData.type === 'product_all'
|
|
448
|
+
var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
514
449
|
|
|
515
450
|
// 编辑的商品 使用了优惠券不可用
|
|
516
451
|
var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (discount) {
|
|
@@ -521,7 +456,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
521
456
|
var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
|
|
522
457
|
|
|
523
458
|
// 判断优惠券是否适用于该商品
|
|
524
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable
|
|
459
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
525
460
|
var _discountApplicabilit, _discount$metadata;
|
|
526
461
|
// 记录此优惠券适用的商品
|
|
527
462
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
@@ -544,8 +479,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
544
479
|
title: discount.format_title,
|
|
545
480
|
original_amount: product.price || product.origin_total,
|
|
546
481
|
pre_value: discount.par_value,
|
|
547
|
-
product_id: originProduct.id
|
|
548
|
-
discount_product_id: discount.product_id
|
|
482
|
+
product_id: originProduct.id
|
|
549
483
|
},
|
|
550
484
|
metadata: {
|
|
551
485
|
num: num
|
|
@@ -604,43 +538,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
604
538
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
605
539
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
606
540
|
var _product$discount_lis3, _product$discount_lis4;
|
|
607
|
-
// 🔥 检查策略可用性(针对 good_pass 和折扣卡)
|
|
608
|
-
var discountType = discount.tag || discount.type;
|
|
609
|
-
if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
|
|
610
|
-
var _discount$config2;
|
|
611
|
-
// 如果策略检查后没有config,说明不可用
|
|
612
|
-
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
541
|
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
618
542
|
// 商品券时主商品价格为0不可用
|
|
619
|
-
if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.
|
|
620
|
-
var _n$discount;
|
|
621
|
-
return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
|
|
622
|
-
})) && (discount.tag || discount.type) === 'good_pass') return false;
|
|
543
|
+
if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length) && (discount.tag || discount.type) === 'good_pass') return false;
|
|
623
544
|
|
|
624
545
|
// 折扣卡商品价格为0时不可用
|
|
625
546
|
if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
|
|
626
|
-
var _n$
|
|
627
|
-
return ((_n$
|
|
547
|
+
var _n$discount;
|
|
548
|
+
return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
|
|
628
549
|
})) && (discount.tag || discount.type) !== 'good_pass') return false;
|
|
629
550
|
// 如果优惠券已被使用,则跳过
|
|
630
551
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
631
552
|
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
632
|
-
|
|
633
|
-
// 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
|
|
634
|
-
if ((discount.tag || discount.type) === 'good_pass') {
|
|
635
|
-
var _discount$config3;
|
|
636
|
-
var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
|
|
637
|
-
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
638
|
-
var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
639
|
-
if (currentUsedCount >= maxUsagePerOrder) {
|
|
640
|
-
return false;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
553
|
var limitedData = discount.limited_relation_product_data;
|
|
645
554
|
|
|
646
555
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
@@ -659,9 +568,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
659
568
|
|
|
660
569
|
// 判断优惠券是否适用于该商品
|
|
661
570
|
if (limitedData.type === 'product_all') {
|
|
662
|
-
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
571
|
// 检查 package_sub_item_usage_rules
|
|
666
572
|
if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
667
573
|
return false;
|
|
@@ -828,13 +734,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
828
734
|
var availableGoodPassCount = applicableDiscounts.filter(function (item) {
|
|
829
735
|
return (item.tag || item.type) === 'good_pass';
|
|
830
736
|
}).length;
|
|
831
|
-
|
|
832
|
-
// 🔥 如果selectedDiscount有config配置,则使用config.maxUsagePerOrder限制使用次数
|
|
833
|
-
var maxUsageLimit = availableGoodPassCount;
|
|
834
|
-
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
835
|
-
maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
|
|
836
|
-
}
|
|
837
|
-
var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
737
|
+
var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
838
738
|
var arr = [];
|
|
839
739
|
|
|
840
740
|
// 🔥 主商品和bundle子商品分别处理
|
|
@@ -844,8 +744,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
844
744
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
845
745
|
discount_list: [],
|
|
846
746
|
quantity: totalQuantity - splitCount,
|
|
847
|
-
_id: product._id.split('___')[0]
|
|
848
|
-
total: product.origin_total || product.total
|
|
747
|
+
_id: product._id.split('___')[0]
|
|
849
748
|
}));
|
|
850
749
|
}
|
|
851
750
|
for (var i = 0; i < splitCount; i++) {
|
|
@@ -854,11 +753,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
854
753
|
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
855
754
|
// 标记优惠券为已使用
|
|
856
755
|
usedDiscounts.set(_selectedDiscount.id, true);
|
|
857
|
-
// 🔥 更新 product_id 使用计数
|
|
858
|
-
if ((_selectedDiscount.tag || _selectedDiscount.type) === 'good_pass') {
|
|
859
|
-
var currentCount = usedProductIdCounts.get(_selectedDiscount.product_id) || 0;
|
|
860
|
-
usedProductIdCounts.set(_selectedDiscount.product_id, currentCount + 1);
|
|
861
|
-
}
|
|
862
756
|
|
|
863
757
|
// 记录实际应用了优惠券的商品信息
|
|
864
758
|
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
@@ -876,27 +770,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
876
770
|
|
|
877
771
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
878
772
|
var targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
|
|
879
|
-
var discountType = _selectedDiscount.tag
|
|
880
|
-
|
|
881
|
-
// 计算实际折扣金额
|
|
882
|
-
var actualDiscountAmount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
|
|
773
|
+
var discountType = _selectedDiscount.tag || _selectedDiscount.type;
|
|
883
774
|
var isGoodPass = discountType === 'good_pass';
|
|
775
|
+
var amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
|
|
884
776
|
var discountDetail = {
|
|
885
|
-
amount:
|
|
886
|
-
type: discountType,
|
|
777
|
+
amount: amount,
|
|
778
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
|
|
887
779
|
discount: {
|
|
888
780
|
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
889
|
-
fixed_amount:
|
|
781
|
+
fixed_amount: amount,
|
|
890
782
|
resource_id: _selectedDiscount.id,
|
|
891
783
|
title: _selectedDiscount.format_title,
|
|
892
784
|
original_amount: product.price,
|
|
893
785
|
product_id: originProduct.id,
|
|
894
|
-
percent: _selectedDiscount.par_value
|
|
895
|
-
discount_product_id: _selectedDiscount.product_id
|
|
786
|
+
percent: _selectedDiscount.par_value
|
|
896
787
|
},
|
|
897
788
|
// 前端使用的num数量,为了计算优惠金额
|
|
898
789
|
_num: isGoodPass ? 1 : product.num,
|
|
899
|
-
config: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.config,
|
|
900
790
|
metadata: {
|
|
901
791
|
num: 1
|
|
902
792
|
}
|
|
@@ -915,6 +805,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
915
805
|
// 记录应用了优惠券的商品
|
|
916
806
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
917
807
|
if (product.isClient) {
|
|
808
|
+
debugger;
|
|
918
809
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
919
810
|
discount_list: [discountDetail],
|
|
920
811
|
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
@@ -955,36 +846,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
955
846
|
for (var _i = 0; _i < discountNum; _i++) {
|
|
956
847
|
var _selectedDiscount2 = applicableDiscounts[_i];
|
|
957
848
|
usedDiscounts.set(_selectedDiscount2.id, true);
|
|
958
|
-
// 🔥 更新 product_id 使用计数
|
|
959
|
-
if ((_selectedDiscount2.tag || _selectedDiscount2.type) === 'good_pass') {
|
|
960
|
-
var _currentCount = usedProductIdCounts.get(_selectedDiscount2.product_id) || 0;
|
|
961
|
-
usedProductIdCounts.set(_selectedDiscount2.product_id, _currentCount + 1);
|
|
962
|
-
}
|
|
963
849
|
|
|
964
850
|
// 🔥 生成唯一的 _id
|
|
965
851
|
var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
|
|
966
|
-
|
|
967
|
-
// 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
|
|
968
|
-
var discountedPrice = getDiscountAmount(_selectedDiscount2, product.origin_total, product.origin_total);
|
|
969
|
-
var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
970
852
|
var _discountDetail = {
|
|
971
|
-
amount:
|
|
853
|
+
amount: product.origin_total,
|
|
972
854
|
type: 'good_pass',
|
|
973
855
|
discount: {
|
|
974
856
|
fixed_amount: product.origin_total,
|
|
975
857
|
resource_id: _selectedDiscount2.id,
|
|
976
858
|
title: _selectedDiscount2.format_title,
|
|
977
859
|
original_amount: product.origin_total,
|
|
978
|
-
product_id: product.id
|
|
979
|
-
discount_product_id: _selectedDiscount2.product_id
|
|
860
|
+
product_id: product.id
|
|
980
861
|
},
|
|
981
862
|
metadata: {
|
|
982
863
|
// 🔥 使用拆分后的唯一 _id
|
|
983
864
|
custom_product_bundle_map_id: uniqueId,
|
|
984
865
|
num: 1
|
|
985
866
|
},
|
|
986
|
-
_num: 1
|
|
987
|
-
config: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.config
|
|
867
|
+
_num: 1
|
|
988
868
|
};
|
|
989
869
|
|
|
990
870
|
// 记录实际应用的折扣
|
|
@@ -996,9 +876,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
996
876
|
_id: uniqueId,
|
|
997
877
|
num: 1,
|
|
998
878
|
quantity: 1,
|
|
999
|
-
price:
|
|
1000
|
-
//
|
|
1001
|
-
total:
|
|
879
|
+
price: 0,
|
|
880
|
+
// 商品券价格为0
|
|
881
|
+
total: 0,
|
|
1002
882
|
discount_list: [_discountDetail],
|
|
1003
883
|
processed: true,
|
|
1004
884
|
_discountId: _selectedDiscount2.id
|
|
@@ -1021,38 +901,28 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1021
901
|
// 折扣卡:不拆分数量,直接应用
|
|
1022
902
|
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1023
903
|
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
1024
|
-
// 🔥 更新 product_id 使用计数(虽然此处主要是折扣卡,但保持一致性)
|
|
1025
|
-
if ((_selectedDiscount3.tag || _selectedDiscount3.type) === 'good_pass') {
|
|
1026
|
-
var _currentCount2 = usedProductIdCounts.get(_selectedDiscount3.product_id) || 0;
|
|
1027
|
-
usedProductIdCounts.set(_selectedDiscount3.product_id, _currentCount2 + 1);
|
|
1028
|
-
}
|
|
1029
904
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1030
905
|
var _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1031
906
|
|
|
1032
|
-
// 计算实际折扣金额
|
|
1033
|
-
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
|
|
1034
|
-
|
|
1035
907
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1036
908
|
var _uniqueId = flatItem._id;
|
|
1037
909
|
var _discountDetail2 = {
|
|
1038
|
-
amount:
|
|
910
|
+
amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber() * (product.num || 1),
|
|
1039
911
|
type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
|
|
1040
912
|
discount: {
|
|
1041
913
|
discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
|
|
1042
|
-
fixed_amount:
|
|
914
|
+
fixed_amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber(),
|
|
1043
915
|
resource_id: _selectedDiscount3.id,
|
|
1044
916
|
title: _selectedDiscount3.format_title,
|
|
1045
917
|
original_amount: product.original_price,
|
|
1046
918
|
product_id: product.id,
|
|
1047
|
-
percent: _selectedDiscount3.par_value
|
|
1048
|
-
discount_product_id: _selectedDiscount3.product_id
|
|
919
|
+
percent: _selectedDiscount3.par_value
|
|
1049
920
|
},
|
|
1050
921
|
metadata: {
|
|
1051
922
|
// 🔥 使用唯一的 _id
|
|
1052
923
|
custom_product_bundle_map_id: _uniqueId,
|
|
1053
924
|
num: product.num || 1
|
|
1054
925
|
},
|
|
1055
|
-
config: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.config,
|
|
1056
926
|
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.num) || 1)
|
|
1057
927
|
};
|
|
1058
928
|
|
|
@@ -8,12 +8,6 @@ export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[]) =
|
|
|
8
8
|
* @returns 商品总价字符串,保留2位小数
|
|
9
9
|
*/
|
|
10
10
|
export declare const calculateSubtotal: (items: CartItem[]) => string;
|
|
11
|
-
/**
|
|
12
|
-
* 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
|
|
13
|
-
* @param items - 购物车商品数组
|
|
14
|
-
* @returns 商品总价字符串,保留2位小数
|
|
15
|
-
*/
|
|
16
|
-
export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
|
|
17
11
|
/**
|
|
18
12
|
* @title: 单个商品的税费
|
|
19
13
|
* @description:
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import Decimal from 'decimal.js';
|
|
2
2
|
export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items) {
|
|
3
3
|
var subtotal = new Decimal(calculateSubtotal(items));
|
|
4
|
-
var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
|
|
5
4
|
var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
|
|
6
5
|
|
|
7
6
|
// 计算总价
|
|
8
7
|
var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal : subtotal.plus(totalTaxFee);
|
|
9
8
|
|
|
10
|
-
// 计算总价 不包含折扣卡商品券折扣信息价格
|
|
11
|
-
var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
|
|
12
|
-
|
|
13
9
|
// 计算定金
|
|
14
10
|
var deposit = calculateDeposit(items);
|
|
15
11
|
return {
|
|
16
12
|
subtotal: subtotal.toFixed(2),
|
|
17
13
|
total: total.toFixed(2),
|
|
18
|
-
originTotal: originTotal.toFixed(2),
|
|
19
14
|
taxTitle: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_title,
|
|
20
15
|
totalTaxFee: totalTaxFee.toFixed(2),
|
|
21
16
|
isPriceIncludeTax: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.is_price_include_tax,
|
|
@@ -39,22 +34,6 @@ export var calculateSubtotal = function calculateSubtotal(items) {
|
|
|
39
34
|
return subtotal.toFixed(2);
|
|
40
35
|
};
|
|
41
36
|
|
|
42
|
-
/**
|
|
43
|
-
* 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
|
|
44
|
-
* @param items - 购物车商品数组
|
|
45
|
-
* @returns 商品总价字符串,保留2位小数
|
|
46
|
-
*/
|
|
47
|
-
export var calculateOriginSubtotal = function calculateOriginSubtotal(items) {
|
|
48
|
-
if (!(items !== null && items !== void 0 && items.length)) {
|
|
49
|
-
return '0.00';
|
|
50
|
-
}
|
|
51
|
-
var subtotal = items.reduce(function (sum, item) {
|
|
52
|
-
var cartItemTotalPrice = new Decimal(item.summaryOriginTotal || 0);
|
|
53
|
-
return sum.plus(cartItemTotalPrice);
|
|
54
|
-
}, new Decimal(0));
|
|
55
|
-
return subtotal.toFixed(2);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
37
|
/**
|
|
59
38
|
* @title: 单个商品的税费
|
|
60
39
|
* @description:
|
package/dist/plugins/window.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { WalletPassEvaluator } from '../model';
|
|
2
1
|
import { Plugin } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* WindowPlugin 接口定义
|
|
@@ -15,7 +14,6 @@ export interface WindowPlugin extends Plugin {
|
|
|
15
14
|
document: Partial<Document>;
|
|
16
15
|
history: History;
|
|
17
16
|
interaction?: any;
|
|
18
|
-
getWalletPassEvaluator?: () => WalletPassEvaluator;
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* 简单的 Storage 接口实现
|
|
@@ -144,7 +144,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
144
144
|
getSummary(): Promise<{
|
|
145
145
|
subtotal: string | number;
|
|
146
146
|
total: string | number;
|
|
147
|
-
originTotal: string | number;
|
|
148
147
|
taxTitle?: string | undefined;
|
|
149
148
|
totalTaxFee?: string | number | undefined;
|
|
150
149
|
isPriceIncludeTax?: 0 | 1 | undefined;
|
|
@@ -115,7 +115,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
|
|
|
115
115
|
* 获取当前的客户搜索条件
|
|
116
116
|
* @returns 当前搜索条件
|
|
117
117
|
*/
|
|
118
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
118
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
119
119
|
/**
|
|
120
120
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
121
121
|
* @returns 客户状态
|
|
@@ -403,7 +403,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
403
403
|
product_id: item.product_id,
|
|
404
404
|
product_variant_id: item.product_variant_id,
|
|
405
405
|
quantity: item.num,
|
|
406
|
-
is_price_include_tax: item.is_price_include_tax,
|
|
407
406
|
// 商品是否含税:1;0
|
|
408
407
|
is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
|
|
409
408
|
// 若商品不含税,计算得到的税费,单位(元)
|
|
@@ -428,7 +427,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
428
427
|
},
|
|
429
428
|
product_bundle: item.product_bundle.map(function (bundle) {
|
|
430
429
|
return {
|
|
431
|
-
is_price_include_tax: item.is_price_include_tax,
|
|
432
430
|
bundle_id: bundle.bundle_id,
|
|
433
431
|
bundle_product_id: bundle.bundle_product_id,
|
|
434
432
|
bundle_variant_id: bundle.bundle_variant_id,
|
|
@@ -21,7 +21,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
21
21
|
getCurrentBookingTime(): string | null;
|
|
22
22
|
private filterDiscountListByBookingTime;
|
|
23
23
|
setCustomer(customer: Customer): Promise<void>;
|
|
24
|
-
setOriginTotalAmount(amount: number): void;
|
|
25
24
|
setHolders(holders: {
|
|
26
25
|
form_record_id: number;
|
|
27
26
|
}[]): void;
|
|
@@ -55,7 +55,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
55
55
|
originalDiscountList: [],
|
|
56
56
|
currentBookingTime: "",
|
|
57
57
|
filteredDiscountList: [],
|
|
58
|
-
orderTotalAmount: 0,
|
|
59
58
|
bookingSubject: undefined
|
|
60
59
|
};
|
|
61
60
|
return _this;
|
|
@@ -288,14 +287,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
288
287
|
return _setCustomer.apply(this, arguments);
|
|
289
288
|
}
|
|
290
289
|
return setCustomer;
|
|
291
|
-
}()
|
|
292
|
-
}, {
|
|
293
|
-
key: "setOriginTotalAmount",
|
|
294
|
-
value: function setOriginTotalAmount(amount) {
|
|
295
|
-
this.store.orderTotalAmount = amount;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// 设置holders
|
|
290
|
+
}() // 设置holders
|
|
299
291
|
}, {
|
|
300
292
|
key: "setHolders",
|
|
301
293
|
value: function setHolders(holders) {
|
|
@@ -324,7 +316,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
324
316
|
productList: productList,
|
|
325
317
|
discountList: this.getDiscountList(),
|
|
326
318
|
holders: this.store.holders || [],
|
|
327
|
-
orderTotalAmount: this.store.orderTotalAmount || 0,
|
|
328
319
|
isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
|
|
329
320
|
}, options) || {
|
|
330
321
|
productList: productList,
|
|
@@ -465,7 +456,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
465
456
|
oldDiscountList: this.getDiscountList(),
|
|
466
457
|
newDiscountList: withScanList,
|
|
467
458
|
holders: this.store.holders || [],
|
|
468
|
-
orderTotalAmount: this.store.orderTotalAmount || 0,
|
|
469
459
|
isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
|
|
470
460
|
}) || {
|
|
471
461
|
isAvailable: false,
|
|
@@ -34,37 +34,22 @@ export var isAllNormalProduct = function isAllNormalProduct(items) {
|
|
|
34
34
|
* @returns
|
|
35
35
|
*/
|
|
36
36
|
export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
|
|
37
|
-
var
|
|
38
|
-
|
|
37
|
+
var _discount$metadata;
|
|
39
38
|
// 商品券
|
|
40
39
|
if (discount.tag === 'good_pass') {
|
|
41
|
-
|
|
42
|
-
} else {
|
|
43
|
-
var _discount$metadata;
|
|
44
|
-
// 判断是否是固定金额
|
|
45
|
-
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';
|
|
46
|
-
|
|
47
|
-
// 固定金额 小于0时返回0
|
|
48
|
-
if (isFixedAmount) {
|
|
49
|
-
discountedPrice = Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
50
|
-
} else {
|
|
51
|
-
// 百分比:根据折扣卡金额计算
|
|
52
|
-
discountedPrice = new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
53
|
-
}
|
|
40
|
+
return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
|
|
54
41
|
}
|
|
55
42
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
*/
|
|
43
|
+
// 判断是否是固定金额
|
|
44
|
+
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';
|
|
45
|
+
|
|
46
|
+
// 固定金额 小于0时返回0
|
|
47
|
+
if (isFixedAmount) {
|
|
48
|
+
return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
49
|
+
}
|
|
66
50
|
|
|
67
|
-
|
|
51
|
+
// 百分比:根据折扣卡金额计算
|
|
52
|
+
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
68
53
|
};
|
|
69
54
|
export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
|
|
70
55
|
return discount.reduce(function (acc, cur) {
|
package/lib/index.d.ts
CHANGED