@pisell/pisellos 2.1.111 → 2.1.112
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +3 -0
- package/dist/model/strategy/adapter/index.js +4 -0
- package/dist/model/strategy/adapter/type.d.ts +28 -0
- package/dist/model/strategy/adapter/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +499 -0
- package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/dist/model/strategy/adapter/walletPass/example.js +258 -0
- package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/dist/model/strategy/adapter/walletPass/index.js +182 -0
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
- package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -0
- package/dist/model/strategy/adapter/walletPass/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +1104 -0
- package/dist/model/strategy/index.d.ts +94 -0
- package/dist/model/strategy/index.js +551 -0
- package/dist/model/strategy/strategy-example.d.ts +5 -0
- package/dist/model/strategy/strategy-example.js +331 -0
- package/dist/model/strategy/type.d.ts +228 -0
- package/dist/model/strategy/type.js +94 -0
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +56 -24
- package/dist/modules/Discount/types.d.ts +18 -0
- package/dist/modules/Payment/index.d.ts +2 -1
- package/dist/modules/Payment/index.js +10 -7
- package/dist/modules/Payment/utils.js +3 -0
- package/dist/modules/Payment/walletpass.d.ts +23 -0
- package/dist/modules/Payment/walletpass.js +191 -95
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +9 -5
- package/dist/modules/Rules/index.js +664 -152
- package/dist/modules/Rules/types.d.ts +2 -0
- package/dist/modules/Summary/types.d.ts +2 -0
- package/dist/modules/Summary/utils.d.ts +6 -0
- package/dist/modules/Summary/utils.js +21 -0
- package/dist/plugins/window.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +2 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.js +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +1 -0
- package/dist/solution/ShopDiscount/index.js +23 -7
- package/dist/solution/ShopDiscount/types.d.ts +1 -0
- package/dist/solution/ShopDiscount/types.js +2 -1
- package/dist/solution/ShopDiscount/utils.js +26 -12
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +23 -0
- package/lib/model/strategy/adapter/index.d.ts +3 -0
- package/lib/model/strategy/adapter/index.js +45 -0
- package/lib/model/strategy/adapter/type.d.ts +28 -0
- package/lib/model/strategy/adapter/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +423 -0
- package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/lib/model/strategy/adapter/walletPass/example.js +207 -0
- package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/lib/model/strategy/adapter/walletPass/index.js +142 -0
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
- package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
- package/lib/model/strategy/adapter/walletPass/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
- package/lib/model/strategy/index.d.ts +94 -0
- package/lib/model/strategy/index.js +413 -0
- package/lib/model/strategy/strategy-example.d.ts +5 -0
- package/lib/model/strategy/strategy-example.js +318 -0
- package/lib/model/strategy/type.d.ts +228 -0
- package/lib/model/strategy/type.js +44 -0
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +39 -11
- package/lib/modules/Discount/types.d.ts +18 -0
- package/lib/modules/Payment/index.d.ts +2 -1
- package/lib/modules/Payment/index.js +1 -0
- package/lib/modules/Payment/utils.js +3 -0
- package/lib/modules/Payment/walletpass.d.ts +23 -0
- package/lib/modules/Payment/walletpass.js +94 -17
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +9 -5
- package/lib/modules/Rules/index.js +779 -284
- package/lib/modules/Rules/types.d.ts +2 -0
- package/lib/modules/Summary/types.d.ts +2 -0
- package/lib/modules/Summary/utils.d.ts +6 -0
- package/lib/modules/Summary/utils.js +15 -0
- package/lib/plugins/window.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +2 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.js +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +1 -0
- package/lib/solution/ShopDiscount/index.js +22 -8
- package/lib/solution/ShopDiscount/types.d.ts +1 -0
- package/lib/solution/ShopDiscount/utils.js +10 -6
- package/package.json +1 -1
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
var _excluded = ["_original_add_price"],
|
|
2
|
+
_excluded2 = ["_original_price", "_original_add_price"];
|
|
1
3
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
2
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
8
|
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; } } }; }
|
|
@@ -31,7 +35,6 @@ import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils"
|
|
|
31
35
|
import Decimal from 'decimal.js';
|
|
32
36
|
import { isBoolean } from 'lodash-es';
|
|
33
37
|
import dayjs from 'dayjs';
|
|
34
|
-
|
|
35
38
|
// 临时变量
|
|
36
39
|
var flatItem;
|
|
37
40
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
@@ -44,6 +47,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
44
47
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
|
|
45
48
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
46
49
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
50
|
+
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
51
|
+
// WindowPlugin 实例
|
|
47
52
|
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
48
53
|
_this.hooks = {};
|
|
49
54
|
return _this;
|
|
@@ -58,7 +63,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
58
63
|
this.core = core;
|
|
59
64
|
this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
|
|
60
65
|
this.store = options === null || options === void 0 ? void 0 : options.store;
|
|
61
|
-
|
|
66
|
+
this.window = core.getPlugin('window');
|
|
67
|
+
case 4:
|
|
62
68
|
case "end":
|
|
63
69
|
return _context.stop();
|
|
64
70
|
}
|
|
@@ -113,6 +119,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
113
119
|
// 最终直接匹配 holder 是否相同
|
|
114
120
|
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
115
121
|
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "getWalletPassEvaluator",
|
|
124
|
+
value: function getWalletPassEvaluator() {
|
|
125
|
+
var _this$window$getWalle, _this$window;
|
|
126
|
+
return (_this$window$getWalle = (_this$window = this.window).getWalletPassEvaluator) === null || _this$window$getWalle === void 0 ? void 0 : _this$window$getWalle.call(_this$window);
|
|
127
|
+
}
|
|
116
128
|
|
|
117
129
|
// 判断discountList 是否可以对当前productList生效
|
|
118
130
|
}, {
|
|
@@ -122,6 +134,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
122
134
|
var oldDiscountList = _ref.oldDiscountList,
|
|
123
135
|
newDiscountList = _ref.newDiscountList,
|
|
124
136
|
productList = _ref.productList,
|
|
137
|
+
orderTotalAmount = _ref.orderTotalAmount,
|
|
125
138
|
holders = _ref.holders,
|
|
126
139
|
isFormSubject = _ref.isFormSubject;
|
|
127
140
|
// 首先检查是否有新的优惠券可应用
|
|
@@ -156,6 +169,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
156
169
|
var result = this.calcDiscount({
|
|
157
170
|
discountList: mergedDiscountList,
|
|
158
171
|
productList: _toConsumableArray(productList),
|
|
172
|
+
orderTotalAmount: orderTotalAmount,
|
|
159
173
|
holders: holders,
|
|
160
174
|
isFormSubject: isFormSubject
|
|
161
175
|
}, {
|
|
@@ -289,7 +303,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
289
303
|
var discountList = _ref2.discountList,
|
|
290
304
|
productList = _ref2.productList,
|
|
291
305
|
holders = _ref2.holders,
|
|
292
|
-
isFormSubject = _ref2.isFormSubject
|
|
306
|
+
isFormSubject = _ref2.isFormSubject,
|
|
307
|
+
orderTotalAmount = _ref2.orderTotalAmount;
|
|
293
308
|
var editModeDiscount = [];
|
|
294
309
|
var addModeDiscount = [];
|
|
295
310
|
discountList.forEach(function (discount) {
|
|
@@ -538,9 +553,62 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
538
553
|
return priceB.minus(priceA).toNumber();
|
|
539
554
|
});
|
|
540
555
|
|
|
556
|
+
// 🔥 为每个折扣卡/商品券执行策略检查并附加config
|
|
557
|
+
var evaluator = this.getWalletPassEvaluator();
|
|
558
|
+
if (evaluator) {
|
|
559
|
+
addModeDiscount.forEach(function (discount) {
|
|
560
|
+
var discountType = discount.tag || discount.type;
|
|
561
|
+
// 只对 good_pass 和 discount_card 类型执行策略检查
|
|
562
|
+
if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
|
|
563
|
+
var _discount$limited_rel, _discount$limited_rel2;
|
|
564
|
+
// 转换 discount 为 Voucher 格式
|
|
565
|
+
var voucher = {
|
|
566
|
+
id: discount.id,
|
|
567
|
+
amount: Number(discount.par_value || 0),
|
|
568
|
+
balance: Number(discount.balance || 0),
|
|
569
|
+
type: discountType,
|
|
570
|
+
product_id: discount.product_id,
|
|
571
|
+
unified_available_status: 1,
|
|
572
|
+
available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
|
|
573
|
+
available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
// 转换 sortedFlattenedList 为 Product 格式
|
|
577
|
+
var productsForEvaluate = sortedFlattenedList.map(function (item) {
|
|
578
|
+
var _item$product;
|
|
579
|
+
return {
|
|
580
|
+
product_id: item.id,
|
|
581
|
+
price: item.price || 0,
|
|
582
|
+
quantity: item.quantity || item.num || 1,
|
|
583
|
+
selling_price: item.price || 0,
|
|
584
|
+
product_options: item.type === 'main' ? (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.options : undefined
|
|
585
|
+
};
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
// 调用策略检查
|
|
589
|
+
var result = evaluator.checkVoucherAvailability({
|
|
590
|
+
orderTotalAmount: orderTotalAmount,
|
|
591
|
+
products: productsForEvaluate,
|
|
592
|
+
vouchers: [voucher]
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
// 将 config 附加到 discount 对象
|
|
596
|
+
if (result.isAvailable) {
|
|
597
|
+
discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
|
|
598
|
+
isAvailable: true
|
|
599
|
+
});
|
|
600
|
+
} else {
|
|
601
|
+
discount.config = {
|
|
602
|
+
isAvailable: false
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
541
609
|
/**
|
|
542
|
-
|
|
543
|
-
|
|
610
|
+
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
611
|
+
const sortedProductList = [...productList].sort((a, b) => {
|
|
544
612
|
const aProduct = this.hooks.getProduct(a);
|
|
545
613
|
const bProduct = this.hooks.getProduct(b);
|
|
546
614
|
const priceA = new Decimal((aProduct.price as string) || '0');
|
|
@@ -558,6 +626,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
558
626
|
// 标记已使用的优惠券
|
|
559
627
|
var usedDiscounts = new Map();
|
|
560
628
|
|
|
629
|
+
// 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
|
|
630
|
+
var usedProductIdCounts = new Map();
|
|
631
|
+
|
|
632
|
+
// 🔥 统计每张折扣卡的 applicableProductLimit 已使用次数(跨商品全局计数)
|
|
633
|
+
var usedDiscountCardLimitCounts = new Map();
|
|
634
|
+
|
|
635
|
+
// 🔥 预先将 editModeDiscount 中的折扣卡计入 applicableProductLimit 已使用次数
|
|
636
|
+
editModeDiscount.forEach(function (discount) {
|
|
637
|
+
var discountType = discount.tag || discount.type;
|
|
638
|
+
if (['discount_card', 'product_discount_card'].includes(discountType)) {
|
|
639
|
+
var _discount$metadata4;
|
|
640
|
+
var currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
641
|
+
usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.num) || 1));
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
|
|
561
645
|
// 记录每个优惠券适用的商品ID
|
|
562
646
|
var discountApplicability = new Map();
|
|
563
647
|
|
|
@@ -773,6 +857,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
773
857
|
var _flatItem$parentProdu5;
|
|
774
858
|
// bundle子商品:构造虚拟商品对象
|
|
775
859
|
product = {
|
|
860
|
+
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
|
|
776
861
|
_id: flatItem._id,
|
|
777
862
|
id: flatItem.id,
|
|
778
863
|
price: flatItem.price,
|
|
@@ -781,13 +866,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
781
866
|
total: flatItem.total,
|
|
782
867
|
origin_total: flatItem.origin_total,
|
|
783
868
|
booking_id: flatItem.booking_id,
|
|
784
|
-
discount_list: flatItem.discount_list || []
|
|
785
|
-
startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
|
|
869
|
+
discount_list: flatItem.discount_list || []
|
|
786
870
|
};
|
|
787
871
|
originProduct = flatItem.originProduct;
|
|
788
872
|
}
|
|
789
873
|
addModeDiscount.forEach(function (discount) {
|
|
790
|
-
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
|
|
874
|
+
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
|
|
791
875
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
792
876
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
793
877
|
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;
|
|
@@ -798,7 +882,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
798
882
|
var timeLimit = true;
|
|
799
883
|
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
800
884
|
// 是符合折扣的商品
|
|
801
|
-
var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
885
|
+
var isLimitedProduct = (limitedData.type === 'product_all' && limitedData.filter !== 1 || limitedData.type === 'product_all' && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
802
886
|
|
|
803
887
|
// 编辑的商品 使用了优惠券不可用
|
|
804
888
|
var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
|
|
@@ -811,8 +895,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
811
895
|
var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
|
|
812
896
|
|
|
813
897
|
// 判断优惠券是否适用于该商品
|
|
814
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
815
|
-
var _discountApplicabilit, _discount$
|
|
898
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
|
|
899
|
+
var _discountApplicabilit, _discount$metadata5, _discount$metadata6;
|
|
816
900
|
// 记录此优惠券适用的商品
|
|
817
901
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
818
902
|
|
|
@@ -828,14 +912,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
828
912
|
type: discountType,
|
|
829
913
|
tag: discountType,
|
|
830
914
|
discount: {
|
|
831
|
-
discount_card_type: discount === null || discount === void 0 || (_discount$
|
|
915
|
+
discount_card_type: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_card_type,
|
|
832
916
|
fixed_amount: product.price,
|
|
833
|
-
discount_calculation_mode: discount === null || discount === void 0 || (_discount$
|
|
917
|
+
discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.discount_calculation_mode,
|
|
834
918
|
resource_id: discount.id,
|
|
835
919
|
title: discount.format_title,
|
|
836
920
|
original_amount: product.price || product.origin_total,
|
|
837
921
|
pre_value: discount.par_value,
|
|
838
|
-
product_id: originProduct.id
|
|
922
|
+
product_id: originProduct.id,
|
|
923
|
+
discount_product_id: discount.product_id
|
|
839
924
|
},
|
|
840
925
|
metadata: {
|
|
841
926
|
num: num,
|
|
@@ -851,19 +936,75 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
851
936
|
// 🔥 用于存储扁平化商品处理结果的Map
|
|
852
937
|
var processedFlatItemsMap = new Map();
|
|
853
938
|
|
|
939
|
+
// 🔥 Option 折扣辅助函数
|
|
940
|
+
var applyDiscountToOptions = function applyDiscountToOptions(options, discount) {
|
|
941
|
+
if (!(options !== null && options !== void 0 && options.length)) return {
|
|
942
|
+
discountedOptions: options,
|
|
943
|
+
optionDiscountAmount: 0
|
|
944
|
+
};
|
|
945
|
+
var optionDiscountAmount = 0;
|
|
946
|
+
var discountedOptions = options.map(function (option) {
|
|
947
|
+
var _ref6, _ref7, _option$_original_pri, _ref8, _option$num, _rest$price, _option$_original_pri2;
|
|
948
|
+
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
949
|
+
var rawUnit = (_ref6 = (_ref7 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref7 !== void 0 ? _ref7 : option.price) !== null && _ref6 !== void 0 ? _ref6 : option.add_price;
|
|
950
|
+
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
951
|
+
if (baseUnitNum <= 0) return option;
|
|
952
|
+
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
953
|
+
var optQty = Number((_ref8 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref8 !== void 0 ? _ref8 : 1);
|
|
954
|
+
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
955
|
+
var _original_add_price = option._original_add_price,
|
|
956
|
+
rest = _objectWithoutProperties(option, _excluded);
|
|
957
|
+
var tmpl = (_rest$price = rest.price) !== null && _rest$price !== void 0 ? _rest$price : rest.add_price;
|
|
958
|
+
var nextPrice = typeof tmpl === 'string' ? String(discountedPrice) : discountedPrice;
|
|
959
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
960
|
+
_original_price: (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : _original_add_price !== undefined ? _original_add_price : rawUnit,
|
|
961
|
+
price: nextPrice
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
return {
|
|
965
|
+
discountedOptions: discountedOptions,
|
|
966
|
+
optionDiscountAmount: optionDiscountAmount
|
|
967
|
+
};
|
|
968
|
+
};
|
|
969
|
+
var restoreOptionPrices = function restoreOptionPrices(options) {
|
|
970
|
+
if (!(options !== null && options !== void 0 && options.length)) return options;
|
|
971
|
+
return options.map(function (option) {
|
|
972
|
+
var orig = option._original_price !== undefined ? option._original_price : option._original_add_price;
|
|
973
|
+
if (orig !== undefined) {
|
|
974
|
+
var _original_price = option._original_price,
|
|
975
|
+
_original_add_price = option._original_add_price,
|
|
976
|
+
rest = _objectWithoutProperties(option, _excluded2);
|
|
977
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
978
|
+
price: orig
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
return option;
|
|
982
|
+
});
|
|
983
|
+
};
|
|
984
|
+
var getOptionTotal = function getOptionTotal(options) {
|
|
985
|
+
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
986
|
+
return options.reduce(function (sum, opt) {
|
|
987
|
+
var _ref9, _opt$price, _ref10, _opt$num;
|
|
988
|
+
var unit = Number((_ref9 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref9 !== void 0 ? _ref9 : 0);
|
|
989
|
+
var n = Number((_ref10 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref10 !== void 0 ? _ref10 : 1);
|
|
990
|
+
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
991
|
+
}, 0);
|
|
992
|
+
};
|
|
993
|
+
|
|
854
994
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
855
995
|
// 🔥 使用扁平化后的列表进行处理
|
|
856
996
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
857
|
-
var _product10, _product$discount_lis2, _product11;
|
|
997
|
+
var _product10, _product$discount_lis2, _product11, _selectedDiscount$con;
|
|
858
998
|
// 获取商品数据
|
|
859
999
|
var product, originProduct;
|
|
860
1000
|
if (flatItem.type === 'main') {
|
|
861
1001
|
product = flatItem.product;
|
|
862
1002
|
originProduct = flatItem.originProduct;
|
|
863
1003
|
} else {
|
|
864
|
-
var _flatItem$
|
|
1004
|
+
var _flatItem$parentProdu6, _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7;
|
|
865
1005
|
// bundle子商品
|
|
866
1006
|
product = {
|
|
1007
|
+
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate,
|
|
867
1008
|
_id: flatItem._id,
|
|
868
1009
|
id: flatItem.id,
|
|
869
1010
|
price: flatItem.price,
|
|
@@ -873,8 +1014,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
873
1014
|
original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
|
|
874
1015
|
origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
|
|
875
1016
|
booking_id: flatItem.booking_id,
|
|
876
|
-
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || []
|
|
877
|
-
startDate: (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate
|
|
1017
|
+
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || []
|
|
878
1018
|
};
|
|
879
1019
|
originProduct = flatItem.originProduct;
|
|
880
1020
|
}
|
|
@@ -896,18 +1036,53 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
896
1036
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
897
1037
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
898
1038
|
var _product$discount_lis3, _product$discount_lis4;
|
|
1039
|
+
// 🔥 检查策略可用性(针对 good_pass 和折扣卡)
|
|
1040
|
+
var discountType = discount.tag || discount.type;
|
|
1041
|
+
if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
|
|
1042
|
+
var _discount$config2;
|
|
1043
|
+
// 如果策略检查后没有config,说明不可用
|
|
1044
|
+
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
|
|
1045
|
+
return false;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
899
1049
|
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
900
1050
|
// 商品券时主商品价格为0不可用
|
|
901
1051
|
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;
|
|
902
1052
|
|
|
903
1053
|
// 折扣卡商品价格为0时不可用
|
|
904
|
-
if ((Number(product.
|
|
1054
|
+
if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
|
|
905
1055
|
var _n$discount;
|
|
906
1056
|
return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
|
|
907
1057
|
})) && (discount.tag || discount.type) !== 'good_pass') return false;
|
|
908
1058
|
// 如果优惠券已被使用,则跳过
|
|
909
1059
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
910
1060
|
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
1061
|
+
|
|
1062
|
+
// 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
|
|
1063
|
+
if ((discount.tag || discount.type) === 'good_pass') {
|
|
1064
|
+
var _discount$config3;
|
|
1065
|
+
var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
|
|
1066
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1067
|
+
var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
1068
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
1069
|
+
return false;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
// 🔥 检查折扣卡的 applicableProductLimit 限制:折扣卡可使用的最大次数(跨商品全局)
|
|
1075
|
+
var discountTypeForLimit = discount.tag || discount.type;
|
|
1076
|
+
if (['discount_card', 'product_discount_card'].includes(discountTypeForLimit)) {
|
|
1077
|
+
var _discount$config4;
|
|
1078
|
+
var applicableProductLimitConfig = ((_discount$config4 = discount.config) === null || _discount$config4 === void 0 ? void 0 : _discount$config4.applicableProductLimit) || 0;
|
|
1079
|
+
if (applicableProductLimitConfig > 0) {
|
|
1080
|
+
var currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
1081
|
+
if (currentUsedLimitCount >= applicableProductLimitConfig) {
|
|
1082
|
+
return false;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
911
1086
|
var limitedData = discount.limited_relation_product_data;
|
|
912
1087
|
|
|
913
1088
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
@@ -926,6 +1101,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
926
1101
|
|
|
927
1102
|
// 判断优惠券是否适用于该商品
|
|
928
1103
|
if (limitedData.type === 'product_all') {
|
|
1104
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1105
|
+
return false;
|
|
1106
|
+
}
|
|
929
1107
|
// 检查 package_sub_item_usage_rules
|
|
930
1108
|
if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
931
1109
|
return false;
|
|
@@ -955,19 +1133,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
955
1133
|
var _product$discount_lis5, _product12, _product12$every;
|
|
956
1134
|
// 主商品:判断自身是否手动折扣
|
|
957
1135
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
958
|
-
var
|
|
959
|
-
return !((
|
|
1136
|
+
var _ref11;
|
|
1137
|
+
return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
|
|
960
1138
|
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
|
|
961
1139
|
return item.type === 'product';
|
|
962
1140
|
})));
|
|
1141
|
+
if (product.inPromotion) {
|
|
1142
|
+
isManualDiscount = false;
|
|
1143
|
+
}
|
|
963
1144
|
} else {
|
|
964
1145
|
// bundle子商品:判断父主商品是否手动折扣
|
|
965
1146
|
var parentProduct = flatItem.parentProduct;
|
|
966
1147
|
if (parentProduct) {
|
|
967
1148
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
968
1149
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
969
|
-
var
|
|
970
|
-
return !((
|
|
1150
|
+
var _ref12;
|
|
1151
|
+
return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
|
|
971
1152
|
}) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
|
|
972
1153
|
return item.type === 'product';
|
|
973
1154
|
})));
|
|
@@ -1034,7 +1215,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1034
1215
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
1035
1216
|
if (applicableDiscounts.length === 0 || isManualDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
1036
1217
|
if (flatItem.type === 'main') {
|
|
1037
|
-
//
|
|
1218
|
+
// 主商品:保持原有逻辑,还原 option 价格
|
|
1219
|
+
var restoredOptions = restoreOptionPrices(product.options);
|
|
1038
1220
|
if (product.isClient) {
|
|
1039
1221
|
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1040
1222
|
origin_total: getProductOriginTotalPrice({
|
|
@@ -1042,7 +1224,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1042
1224
|
original_price: product.original_price
|
|
1043
1225
|
},
|
|
1044
1226
|
bundle: product.bundle,
|
|
1045
|
-
options:
|
|
1227
|
+
options: restoredOptions
|
|
1046
1228
|
}),
|
|
1047
1229
|
variant: originProduct._productInit.variant,
|
|
1048
1230
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1051,15 +1233,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1051
1233
|
price: product.price
|
|
1052
1234
|
},
|
|
1053
1235
|
bundle: product.bundle,
|
|
1054
|
-
options:
|
|
1236
|
+
options: restoredOptions
|
|
1055
1237
|
}),
|
|
1056
|
-
price: product.price
|
|
1238
|
+
price: product.price,
|
|
1239
|
+
options: restoredOptions
|
|
1057
1240
|
}), {}, {
|
|
1058
1241
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1059
1242
|
}))]);
|
|
1060
1243
|
} else {
|
|
1061
|
-
var
|
|
1062
|
-
var total = product.inPromotion ? (
|
|
1244
|
+
var _ref13, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
|
|
1245
|
+
var total = product.inPromotion ? (_ref13 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref13 !== void 0 ? _ref13 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1063
1246
|
var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
|
|
1064
1247
|
if ((product.discount_list || []).some(function (item) {
|
|
1065
1248
|
return item.type === 'promotion';
|
|
@@ -1074,7 +1257,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1074
1257
|
_id: product._id.split('___')[0] + '___' + index,
|
|
1075
1258
|
total: total,
|
|
1076
1259
|
price: product.price,
|
|
1077
|
-
main_product_selling_price: main_product_selling_price
|
|
1260
|
+
main_product_selling_price: main_product_selling_price,
|
|
1261
|
+
options: restoredOptions
|
|
1078
1262
|
}), {}, {
|
|
1079
1263
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1080
1264
|
}))]);
|
|
@@ -1094,36 +1278,81 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1094
1278
|
return;
|
|
1095
1279
|
}
|
|
1096
1280
|
|
|
1097
|
-
//
|
|
1098
|
-
var
|
|
1281
|
+
// 是否需要拆分(商品券需要拆分,折扣卡在 applicableProductLimit > 0 时也需要拆分)
|
|
1282
|
+
var discountType = selectedDiscount.tag || selectedDiscount.type;
|
|
1283
|
+
var isGoodPass = discountType === 'good_pass';
|
|
1284
|
+
var isDiscountCard = ['discount_card', 'product_discount_card'].includes(discountType);
|
|
1285
|
+
var applicableProductLimit = ((_selectedDiscount$con = selectedDiscount.config) === null || _selectedDiscount$con === void 0 ? void 0 : _selectedDiscount$con.applicableProductLimit) || 0;
|
|
1286
|
+
|
|
1287
|
+
// 商品券始终需要拆分,折扣卡在 applicableProductLimit > 0 时需要拆分
|
|
1288
|
+
var isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
|
|
1099
1289
|
|
|
1100
1290
|
// 需要拆分出来的数量
|
|
1101
1291
|
var totalQuantity = product.quantity || product.num || 1;
|
|
1102
1292
|
var availableGoodPassCount = applicableDiscounts.filter(function (item) {
|
|
1103
1293
|
return (item.tag || item.type) === 'good_pass';
|
|
1104
1294
|
}).length;
|
|
1105
|
-
|
|
1295
|
+
|
|
1296
|
+
// 🔥 计算最大使用次数限制
|
|
1297
|
+
var maxUsageLimit;
|
|
1298
|
+
if (isGoodPass) {
|
|
1299
|
+
// 商品券:使用 maxUsagePerOrder 限制
|
|
1300
|
+
maxUsageLimit = availableGoodPassCount;
|
|
1301
|
+
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
1302
|
+
maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
|
|
1303
|
+
}
|
|
1304
|
+
} else if (isDiscountCard && applicableProductLimit > 0) {
|
|
1305
|
+
// 折扣卡:使用 applicableProductLimit 限制(一个商品使用一次折扣卡算1次)
|
|
1306
|
+
// 需要减去已使用次数(跨商品全局计数)
|
|
1307
|
+
var usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
|
|
1308
|
+
maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
|
|
1309
|
+
} else {
|
|
1310
|
+
// 其他情况不拆分
|
|
1311
|
+
maxUsageLimit = 1;
|
|
1312
|
+
}
|
|
1313
|
+
var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
1106
1314
|
var arr = [];
|
|
1107
1315
|
|
|
1108
1316
|
// 🔥 主商品和bundle子商品分别处理
|
|
1109
1317
|
if (flatItem.type === 'main') {
|
|
1110
1318
|
// 主商品:保持原有逻辑
|
|
1111
1319
|
if (splitCount < totalQuantity && isNeedSplit) {
|
|
1320
|
+
var _product$origin_total2;
|
|
1321
|
+
var _total = (_product$origin_total2 = product.origin_total) !== null && _product$origin_total2 !== void 0 ? _product$origin_total2 : product.total;
|
|
1322
|
+
if ((product.discount_list || []).some(function (item) {
|
|
1323
|
+
return item.type === 'promotion';
|
|
1324
|
+
})) {
|
|
1325
|
+
var _product$total2;
|
|
1326
|
+
_total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
|
|
1327
|
+
}
|
|
1112
1328
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1113
1329
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1114
1330
|
quantity: totalQuantity - splitCount,
|
|
1115
|
-
_id: product._id.split('___')[0]
|
|
1331
|
+
_id: product._id.split('___')[0],
|
|
1332
|
+
total: _total
|
|
1116
1333
|
}));
|
|
1117
1334
|
}
|
|
1118
1335
|
for (var i = 0; i < splitCount; i++) {
|
|
1119
|
-
var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1120
|
-
//
|
|
1121
|
-
|
|
1336
|
+
var _originProduct, _selectedDiscount$con2, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1337
|
+
// 商品券:每个拆分商品使用不同的商品券(从 applicableDiscounts 按索引取)
|
|
1338
|
+
// 折扣卡:所有拆分商品使用同一张折扣卡(selectedDiscountCard 或 applicableDiscounts[0])
|
|
1339
|
+
var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1122
1340
|
// 标记优惠券为已使用
|
|
1123
|
-
usedDiscounts.set(
|
|
1341
|
+
usedDiscounts.set(currentSelectedDiscount.id, true);
|
|
1342
|
+
// 🔥 更新 product_id 使用计数
|
|
1343
|
+
if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === 'good_pass') {
|
|
1344
|
+
var currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
|
|
1345
|
+
usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
|
|
1346
|
+
}
|
|
1347
|
+
// 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
|
|
1348
|
+
var currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
|
|
1349
|
+
if (['discount_card', 'product_discount_card'].includes(currentDiscountTypeForCount)) {
|
|
1350
|
+
var currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
|
|
1351
|
+
usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
|
|
1352
|
+
}
|
|
1124
1353
|
|
|
1125
1354
|
// 记录实际应用了优惠券的商品信息
|
|
1126
|
-
var appliedProducts = appliedDiscountProducts.get(
|
|
1355
|
+
var appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
|
|
1127
1356
|
|
|
1128
1357
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1129
1358
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
@@ -1138,210 +1367,492 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1138
1367
|
|
|
1139
1368
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
1140
1369
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1141
|
-
var isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1142
|
-
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1370
|
+
var isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
|
|
1371
|
+
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
1143
1372
|
var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1144
|
-
var
|
|
1373
|
+
var isDeductOptionPrice = !!((_selectedDiscount$con2 = selectedDiscount.config) !== null && _selectedDiscount$con2 !== void 0 && _selectedDiscount$con2.deductOptionPrice);
|
|
1374
|
+
|
|
1375
|
+
// 主商品折后价(不含 option);勿与 option 合计混在同一变量,否则 main_product_selling_price 错误
|
|
1376
|
+
var mainProductSellingPrice = void 0;
|
|
1145
1377
|
var amount = void 0;
|
|
1146
1378
|
var productDiscountDifference = void 0;
|
|
1379
|
+
var discountedOptions = product.options;
|
|
1380
|
+
var optionDiscountAmount = 0;
|
|
1147
1381
|
if (isOrderLevel && productAllocation) {
|
|
1148
1382
|
// order_level:使用预计算的分摊金额
|
|
1149
1383
|
amount = productAllocation.discountAmount;
|
|
1150
1384
|
productDiscountDifference = productAllocation.difference;
|
|
1151
|
-
|
|
1385
|
+
mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1152
1386
|
} else {
|
|
1153
1387
|
// item_level 或其他类型:使用原有逻辑
|
|
1154
|
-
|
|
1155
|
-
amount = new Decimal(product.price).minus(new Decimal(
|
|
1388
|
+
mainProductSellingPrice = getDiscountAmount(currentSelectedDiscount, product.price, product.price);
|
|
1389
|
+
amount = new Decimal(product.price).minus(new Decimal(mainProductSellingPrice)).toNumber();
|
|
1156
1390
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1391
|
+
if (isDeductOptionPrice && (_product$options = product.options) !== null && _product$options !== void 0 && _product$options.length) {
|
|
1392
|
+
var optionResult = applyDiscountToOptions(product.options, currentSelectedDiscount);
|
|
1393
|
+
discountedOptions = optionResult.discountedOptions;
|
|
1394
|
+
optionDiscountAmount = optionResult.optionDiscountAmount;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// total = 主商品折后 + option 行合计;开启 option 抵扣时必须用 discountedOptions,不能用未折扣的 product.options 再算一遍
|
|
1398
|
+
var optionsForLineTotal = isDeductOptionPrice && (_product$options2 = product.options) !== null && _product$options2 !== void 0 && _product$options2.length ? discountedOptions : product.options;
|
|
1399
|
+
var optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
|
|
1400
|
+
var _total2 = new Decimal(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
|
|
1401
|
+
|
|
1402
|
+
// discount_list.amount / fixed_amount:行级总优惠 = 主商品优惠 + option 优惠(与 total 变化一致)
|
|
1403
|
+
var mainProductDiscountAmount = amount;
|
|
1404
|
+
var lineDiscountAmount = new Decimal(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
|
|
1405
|
+
var currentDiscountType = currentSelectedDiscount.tag === 'product_discount_card' ? 'discount_card' : currentSelectedDiscount.tag;
|
|
1406
|
+
var _discountType = selectedDiscount.tag || selectedDiscount.type;
|
|
1407
|
+
var currentIsGoodPass = currentDiscountType === 'good_pass';
|
|
1159
1408
|
var discountDetail = {
|
|
1160
|
-
amount:
|
|
1161
|
-
type:
|
|
1409
|
+
amount: lineDiscountAmount,
|
|
1410
|
+
type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _discountType,
|
|
1162
1411
|
discount: {
|
|
1163
|
-
discount_card_type:
|
|
1164
|
-
fixed_amount:
|
|
1165
|
-
discount_calculation_mode:
|
|
1166
|
-
resource_id:
|
|
1167
|
-
title:
|
|
1412
|
+
discount_card_type: selectedDiscount === null || selectedDiscount === void 0 || (_selectedDiscount$met = selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
1413
|
+
fixed_amount: lineDiscountAmount,
|
|
1414
|
+
discount_calculation_mode: selectedDiscount === null || selectedDiscount === void 0 || (_selectedDiscount$met2 = selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
|
|
1415
|
+
resource_id: selectedDiscount.id,
|
|
1416
|
+
title: selectedDiscount.format_title,
|
|
1168
1417
|
original_amount: product.price,
|
|
1169
1418
|
product_id: originProduct.id,
|
|
1170
|
-
percent:
|
|
1419
|
+
percent: currentSelectedDiscount.par_value,
|
|
1420
|
+
discount_product_id: currentSelectedDiscount.product_id
|
|
1171
1421
|
},
|
|
1172
|
-
// 前端使用的num
|
|
1173
|
-
_num:
|
|
1174
|
-
|
|
1422
|
+
// 前端使用的num数量,为了计算优惠金额(拆分时为1)
|
|
1423
|
+
_num: isNeedSplit ? 1 : product.num,
|
|
1424
|
+
config: currentSelectedDiscount === null || currentSelectedDiscount === void 0 ? void 0 : currentSelectedDiscount.config,
|
|
1425
|
+
metadata: _objectSpread(_objectSpread({
|
|
1175
1426
|
num: 1,
|
|
1176
|
-
discount_rule_uncheck_flag:
|
|
1427
|
+
discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag
|
|
1177
1428
|
}, productDiscountDifference !== undefined && {
|
|
1178
1429
|
product_discount_difference: productDiscountDifference
|
|
1430
|
+
}), {}, {
|
|
1431
|
+
/** 仅主商品上的优惠金额(不含 option) */
|
|
1432
|
+
mainProductDiscountAmount: mainProductDiscountAmount,
|
|
1433
|
+
optionDiscountAmount: optionDiscountAmount
|
|
1179
1434
|
})
|
|
1180
1435
|
};
|
|
1181
1436
|
appliedProducts.push(discountDetail);
|
|
1182
|
-
appliedDiscountProducts.set(
|
|
1183
|
-
var _total = targetProductTotal;
|
|
1184
|
-
if (product.options) {
|
|
1185
|
-
_total = product.options.reduce(function (accumulator, currentValue) {
|
|
1186
|
-
var currentPrice = new Decimal(currentValue.price || 0);
|
|
1187
|
-
var currentNum = new Decimal(currentValue.num || 0);
|
|
1188
|
-
return accumulator.add(currentPrice.mul(currentNum));
|
|
1189
|
-
}, new Decimal(_total)).toNumber();
|
|
1190
|
-
}
|
|
1437
|
+
appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
|
|
1191
1438
|
|
|
1192
1439
|
// 记录应用了优惠券的商品
|
|
1193
1440
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1194
1441
|
if (product.isClient) {
|
|
1195
1442
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1196
1443
|
discount_list: [discountDetail],
|
|
1197
|
-
|
|
1444
|
+
// good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1445
|
+
price: currentIsGoodPass ? mainProductSellingPrice : product.price,
|
|
1198
1446
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1199
1447
|
origin_total: getProductOriginTotalPrice({
|
|
1200
1448
|
product: {
|
|
1201
1449
|
original_price: product.original_price
|
|
1202
1450
|
},
|
|
1203
1451
|
bundle: product.bundle,
|
|
1204
|
-
options: product.options
|
|
1452
|
+
options: restoreOptionPrices(product.options)
|
|
1205
1453
|
}),
|
|
1206
1454
|
variant: originProduct._productInit.variant,
|
|
1207
1455
|
original_price: new Decimal(product.price || 0).toNumber(),
|
|
1208
|
-
total:
|
|
1456
|
+
total: _total2,
|
|
1457
|
+
options: discountedOptions
|
|
1209
1458
|
}));
|
|
1210
1459
|
} else {
|
|
1211
1460
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1212
1461
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1213
|
-
_id: product._id.split('___')[0] +
|
|
1214
|
-
price:
|
|
1462
|
+
_id: product._id.split('___')[0] + '___' + currentSelectedDiscount.id + '_' + i + '_' + index,
|
|
1463
|
+
price: currentIsGoodPass ? 0 : product.price,
|
|
1215
1464
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1216
|
-
total:
|
|
1465
|
+
total: _total2,
|
|
1217
1466
|
origin_total: productOriginTotal,
|
|
1218
|
-
main_product_selling_price:
|
|
1467
|
+
main_product_selling_price: mainProductSellingPrice,
|
|
1468
|
+
options: discountedOptions
|
|
1219
1469
|
}));
|
|
1220
1470
|
}
|
|
1221
1471
|
}
|
|
1222
1472
|
processedProductsMap.set(product._id, arr);
|
|
1223
1473
|
} else {
|
|
1224
|
-
// 🔥 bundle
|
|
1474
|
+
// 🔥 bundle子商品:支持拆分(商品券和折扣卡在 applicableProductLimit > 0 时都需要拆分)
|
|
1225
1475
|
var processedItems = [];
|
|
1226
1476
|
if (isNeedSplit) {
|
|
1227
|
-
//
|
|
1477
|
+
// 需要拆分数量(商品券或折扣卡有 applicableProductLimit 限制)
|
|
1228
1478
|
var discountNum = splitCount;
|
|
1229
1479
|
var normalNum = totalQuantity - discountNum;
|
|
1230
1480
|
|
|
1231
|
-
//
|
|
1481
|
+
// 生成有折扣的商品(每个拆分商品 num: 1)
|
|
1232
1482
|
for (var _i = 0; _i < discountNum; _i++) {
|
|
1233
|
-
var
|
|
1234
|
-
|
|
1235
|
-
|
|
1483
|
+
var _currentBundleDiscoun, _currentBundleDiscoun2;
|
|
1484
|
+
// 商品券:每个拆分商品使用不同的商品券
|
|
1485
|
+
// 折扣卡:所有拆分商品使用同一张折扣卡
|
|
1486
|
+
var currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[_i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1487
|
+
usedDiscounts.set(currentBundleDiscount.id, true);
|
|
1488
|
+
// 🔥 更新 product_id 使用计数
|
|
1489
|
+
if ((currentBundleDiscount.tag || currentBundleDiscount.type) === 'good_pass') {
|
|
1490
|
+
var _currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
|
|
1491
|
+
usedProductIdCounts.set(currentBundleDiscount.product_id, _currentCount + 1);
|
|
1492
|
+
}
|
|
1493
|
+
// 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
|
|
1494
|
+
var bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
|
|
1495
|
+
if (['discount_card', 'product_discount_card'].includes(bundleDiscountTypeForCount)) {
|
|
1496
|
+
var currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
|
|
1497
|
+
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
|
|
1498
|
+
}
|
|
1236
1499
|
|
|
1237
1500
|
// 🔥 生成唯一的 _id
|
|
1238
1501
|
var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
|
|
1502
|
+
|
|
1503
|
+
// 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
|
|
1504
|
+
var discountedPrice = getDiscountAmount(currentBundleDiscount, product.origin_total, product.origin_total);
|
|
1505
|
+
var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
1506
|
+
|
|
1507
|
+
// 确定折扣类型
|
|
1508
|
+
var bundleDiscountType = currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : currentBundleDiscount.tag;
|
|
1239
1509
|
var _discountDetail = {
|
|
1240
|
-
amount:
|
|
1241
|
-
type:
|
|
1510
|
+
amount: bundleDiscountAmount,
|
|
1511
|
+
type: bundleDiscountType,
|
|
1242
1512
|
discount: {
|
|
1243
|
-
|
|
1244
|
-
discount_calculation_mode:
|
|
1245
|
-
|
|
1246
|
-
|
|
1513
|
+
discount_card_type: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun = currentBundleDiscount.metadata) === null || _currentBundleDiscoun === void 0 ? void 0 : _currentBundleDiscoun.discount_card_type,
|
|
1514
|
+
discount_calculation_mode: currentBundleDiscount === null || currentBundleDiscount === void 0 || (_currentBundleDiscoun2 = currentBundleDiscount.metadata) === null || _currentBundleDiscoun2 === void 0 ? void 0 : _currentBundleDiscoun2.discount_calculation_mode,
|
|
1515
|
+
fixed_amount: bundleDiscountAmount,
|
|
1516
|
+
resource_id: currentBundleDiscount.id,
|
|
1517
|
+
title: currentBundleDiscount.format_title,
|
|
1247
1518
|
original_amount: product.origin_total,
|
|
1248
|
-
product_id: product.id
|
|
1519
|
+
product_id: product.id,
|
|
1520
|
+
percent: currentBundleDiscount.par_value,
|
|
1521
|
+
discount_product_id: currentBundleDiscount.product_id
|
|
1249
1522
|
},
|
|
1250
1523
|
metadata: {
|
|
1251
1524
|
// 🔥 使用拆分后的唯一 _id
|
|
1252
1525
|
custom_product_bundle_map_id: uniqueId,
|
|
1253
|
-
discount_rule_uncheck_flag:
|
|
1526
|
+
discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
|
|
1254
1527
|
num: 1
|
|
1255
1528
|
},
|
|
1256
|
-
_num: 1
|
|
1529
|
+
_num: 1,
|
|
1530
|
+
config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
|
|
1257
1531
|
};
|
|
1258
1532
|
|
|
1259
1533
|
// 记录实际应用的折扣
|
|
1260
|
-
var _appliedProducts = appliedDiscountProducts.get(
|
|
1534
|
+
var _appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
|
|
1261
1535
|
_appliedProducts.push(_discountDetail);
|
|
1262
|
-
appliedDiscountProducts.set(
|
|
1536
|
+
appliedDiscountProducts.set(currentBundleDiscount.id, _appliedProducts);
|
|
1263
1537
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1264
1538
|
// 🔥 使用唯一的 _id
|
|
1265
1539
|
_id: uniqueId,
|
|
1266
1540
|
num: 1,
|
|
1267
1541
|
quantity: 1,
|
|
1268
|
-
price:
|
|
1269
|
-
//
|
|
1270
|
-
total:
|
|
1542
|
+
price: discountedPrice,
|
|
1543
|
+
// 折扣后的价格
|
|
1544
|
+
total: discountedPrice,
|
|
1271
1545
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail]),
|
|
1272
1546
|
processed: true,
|
|
1273
|
-
_discountId:
|
|
1547
|
+
_discountId: currentBundleDiscount.id
|
|
1274
1548
|
}));
|
|
1275
1549
|
}
|
|
1276
1550
|
|
|
1277
|
-
//
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1551
|
+
// 🔥 对拆分后的剩余商品继续匹配其他可用折扣(而不是等到下次执行才应用)
|
|
1552
|
+
var remainingNum = normalNum;
|
|
1553
|
+
var continueSplitIndex = discountNum;
|
|
1554
|
+
while (remainingNum > 0) {
|
|
1555
|
+
var _nextSelectedDiscount;
|
|
1556
|
+
// 重新查找适用于剩余商品的可用折扣(已使用的会被自动过滤掉)
|
|
1557
|
+
var nextApplicableDiscounts = sortedDiscountList.filter(function (nextDiscount) {
|
|
1558
|
+
var _product$discount_lis10;
|
|
1559
|
+
var nextDiscountType = nextDiscount.tag || nextDiscount.type;
|
|
1560
|
+
// 检查策略可用性
|
|
1561
|
+
if (['good_pass', 'discount_card', 'product_discount_card'].includes(nextDiscountType)) {
|
|
1562
|
+
var _nextDiscount$config;
|
|
1563
|
+
if (nextDiscount.config === undefined || !(nextDiscount !== null && nextDiscount !== void 0 && (_nextDiscount$config = nextDiscount.config) !== null && _nextDiscount$config !== void 0 && _nextDiscount$config.isAvailable)) {
|
|
1564
|
+
return false;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
// 折扣卡时总价为0时不可用
|
|
1568
|
+
if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.find(function (n) {
|
|
1569
|
+
var _n$discount2;
|
|
1570
|
+
return ((_n$discount2 = n.discount) === null || _n$discount2 === void 0 ? void 0 : _n$discount2.resource_id) === nextDiscount.id;
|
|
1571
|
+
})) && nextDiscountType !== 'good_pass') return false;
|
|
1572
|
+
|
|
1573
|
+
// 商品券已被使用则跳过
|
|
1574
|
+
if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === 'good_pass') return false;
|
|
1575
|
+
|
|
1576
|
+
// 检查 maxUsagePerOrder 限制
|
|
1577
|
+
if (nextDiscountType === 'good_pass') {
|
|
1578
|
+
var _nextDiscount$config2;
|
|
1579
|
+
var maxUsagePerOrder = (_nextDiscount$config2 = nextDiscount.config) === null || _nextDiscount$config2 === void 0 ? void 0 : _nextDiscount$config2.maxUsagePerOrder;
|
|
1580
|
+
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1581
|
+
var currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
|
|
1582
|
+
if (currentUsedCount >= maxUsagePerOrder) {
|
|
1583
|
+
return false;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// 检查折扣卡的 applicableProductLimit 限制
|
|
1589
|
+
if (['discount_card', 'product_discount_card'].includes(nextDiscountType)) {
|
|
1590
|
+
var _nextDiscount$config3;
|
|
1591
|
+
var limitConfig = ((_nextDiscount$config3 = nextDiscount.config) === null || _nextDiscount$config3 === void 0 ? void 0 : _nextDiscount$config3.applicableProductLimit) || 0;
|
|
1592
|
+
if (limitConfig > 0) {
|
|
1593
|
+
var currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
|
|
1594
|
+
if (currentUsedLimitCount >= limitConfig) {
|
|
1595
|
+
return false;
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
var limitedData = nextDiscount.limited_relation_product_data;
|
|
1600
|
+
if (limitedData.type === 'product_all') {
|
|
1601
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1602
|
+
return false;
|
|
1603
|
+
}
|
|
1604
|
+
if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1605
|
+
return false;
|
|
1606
|
+
}
|
|
1607
|
+
return true;
|
|
1608
|
+
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1609
|
+
if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1610
|
+
return false;
|
|
1611
|
+
}
|
|
1612
|
+
return true;
|
|
1613
|
+
}
|
|
1614
|
+
return false;
|
|
1615
|
+
});
|
|
1616
|
+
|
|
1617
|
+
// 没有更多可用折扣,剩余商品无折扣存储
|
|
1618
|
+
if (nextApplicableDiscounts.length === 0) {
|
|
1619
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1620
|
+
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1621
|
+
num: remainingNum,
|
|
1622
|
+
quantity: remainingNum,
|
|
1623
|
+
discount_list: [],
|
|
1624
|
+
processed: true
|
|
1625
|
+
}));
|
|
1626
|
+
break;
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// 选择最优折扣
|
|
1630
|
+
var nextSelectedDiscountCard = nextApplicableDiscounts.find(function (n) {
|
|
1631
|
+
return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
|
|
1632
|
+
});
|
|
1633
|
+
var nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1634
|
+
|
|
1635
|
+
// 判断新折扣是否需要拆分
|
|
1636
|
+
var nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
|
|
1637
|
+
var nextIsGoodPass = nextDiscType === 'good_pass';
|
|
1638
|
+
var nextIsDiscountCard = ['discount_card', 'product_discount_card'].includes(nextDiscType);
|
|
1639
|
+
var nextApplicableProductLimit = ((_nextSelectedDiscount = nextSelectedDiscount.config) === null || _nextSelectedDiscount === void 0 ? void 0 : _nextSelectedDiscount.applicableProductLimit) || 0;
|
|
1640
|
+
var nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
|
|
1641
|
+
if (!nextIsNeedSplit) {
|
|
1642
|
+
var _nextBundleDiscount$m, _flatItem$parentProdu9;
|
|
1643
|
+
// 🔥 不需要拆分:直接应用折扣到所有剩余商品
|
|
1644
|
+
var nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1645
|
+
usedDiscounts.set(nextBundleDiscount.id, true);
|
|
1646
|
+
if ((nextBundleDiscount.tag || nextBundleDiscount.type) === 'good_pass') {
|
|
1647
|
+
var curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
|
|
1648
|
+
usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
|
|
1649
|
+
}
|
|
1650
|
+
var nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
|
|
1651
|
+
if (['discount_card', 'product_discount_card'].includes(nextNoSplitType)) {
|
|
1652
|
+
var _curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
|
|
1653
|
+
usedDiscountCardLimitCounts.set(nextBundleDiscount.id, _curCount + remainingNum);
|
|
1654
|
+
}
|
|
1655
|
+
var nextOriginTotal = product.original_price || product.price || 0;
|
|
1656
|
+
var nextTargetTotal = getDiscountAmount(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
|
|
1657
|
+
var nextDiscountAmount = new Decimal(nextOriginTotal).minus(nextTargetTotal).toNumber();
|
|
1658
|
+
var nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
|
|
1659
|
+
var nextBundleDiscType = nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : nextBundleDiscount.tag;
|
|
1660
|
+
var nextDiscountDetail = {
|
|
1661
|
+
amount: nextDiscountAmount * remainingNum,
|
|
1662
|
+
type: nextBundleDiscType,
|
|
1663
|
+
discount: {
|
|
1664
|
+
discount_card_type: nextBundleDiscount === null || nextBundleDiscount === void 0 || (_nextBundleDiscount$m = nextBundleDiscount.metadata) === null || _nextBundleDiscount$m === void 0 ? void 0 : _nextBundleDiscount$m.discount_card_type,
|
|
1665
|
+
fixed_amount: nextDiscountAmount,
|
|
1666
|
+
resource_id: nextBundleDiscount.id,
|
|
1667
|
+
title: nextBundleDiscount.format_title,
|
|
1668
|
+
original_amount: product.original_price,
|
|
1669
|
+
product_id: product.id,
|
|
1670
|
+
percent: nextBundleDiscount.par_value,
|
|
1671
|
+
discount_product_id: nextBundleDiscount.product_id
|
|
1672
|
+
},
|
|
1673
|
+
metadata: {
|
|
1674
|
+
custom_product_bundle_map_id: nextUniqueId,
|
|
1675
|
+
num: remainingNum
|
|
1676
|
+
},
|
|
1677
|
+
config: nextBundleDiscount === null || nextBundleDiscount === void 0 ? void 0 : nextBundleDiscount.config,
|
|
1678
|
+
_num: remainingNum * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
|
|
1679
|
+
};
|
|
1680
|
+
var nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1681
|
+
nextAppliedProducts.push(nextDiscountDetail);
|
|
1682
|
+
appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
|
|
1683
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1684
|
+
_id: nextUniqueId,
|
|
1685
|
+
num: remainingNum,
|
|
1686
|
+
quantity: remainingNum,
|
|
1687
|
+
total: nextTargetTotal,
|
|
1688
|
+
price: new Decimal(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
|
|
1689
|
+
discount_list: [nextDiscountDetail],
|
|
1690
|
+
processed: true
|
|
1691
|
+
}));
|
|
1692
|
+
remainingNum = 0;
|
|
1693
|
+
break;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// 🔥 需要拆分:计算最大使用次数
|
|
1697
|
+
var nextMaxUsageLimit = void 0;
|
|
1698
|
+
if (nextIsGoodPass) {
|
|
1699
|
+
var _nextSelectedDiscount2;
|
|
1700
|
+
var nextGoodPassCount = nextApplicableDiscounts.filter(function (item) {
|
|
1701
|
+
return (item.tag || item.type) === 'good_pass';
|
|
1702
|
+
}).length;
|
|
1703
|
+
nextMaxUsageLimit = nextGoodPassCount;
|
|
1704
|
+
if ((_nextSelectedDiscount2 = nextSelectedDiscount.config) !== null && _nextSelectedDiscount2 !== void 0 && _nextSelectedDiscount2.maxUsagePerOrder) {
|
|
1705
|
+
var usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
|
|
1706
|
+
nextMaxUsageLimit = Math.min(nextGoodPassCount, Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount));
|
|
1707
|
+
}
|
|
1708
|
+
} else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
|
|
1709
|
+
var _usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
|
|
1710
|
+
nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - _usedLimitCount);
|
|
1711
|
+
} else {
|
|
1712
|
+
nextMaxUsageLimit = 1;
|
|
1713
|
+
}
|
|
1714
|
+
var nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
|
|
1715
|
+
if (nextSplitCount === 0) {
|
|
1716
|
+
// 已达使用上限,剩余商品无折扣存储
|
|
1717
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1718
|
+
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1719
|
+
num: remainingNum,
|
|
1720
|
+
quantity: remainingNum,
|
|
1721
|
+
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1722
|
+
processed: true
|
|
1723
|
+
}));
|
|
1724
|
+
break;
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
// 生成有折扣的商品
|
|
1728
|
+
for (var j = 0; j < nextSplitCount; j++) {
|
|
1729
|
+
var _nextBundleDiscount$m2;
|
|
1730
|
+
var _nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1731
|
+
usedDiscounts.set(_nextBundleDiscount.id, true);
|
|
1732
|
+
if ((_nextBundleDiscount.tag || _nextBundleDiscount.type) === 'good_pass') {
|
|
1733
|
+
var _curCount2 = usedProductIdCounts.get(_nextBundleDiscount.product_id) || 0;
|
|
1734
|
+
usedProductIdCounts.set(_nextBundleDiscount.product_id, _curCount2 + 1);
|
|
1735
|
+
}
|
|
1736
|
+
var nextBundleDiscTypeForCount = _nextBundleDiscount.tag || _nextBundleDiscount.type;
|
|
1737
|
+
if (['discount_card', 'product_discount_card'].includes(nextBundleDiscTypeForCount)) {
|
|
1738
|
+
var curLimitCount = usedDiscountCardLimitCounts.get(_nextBundleDiscount.id) || 0;
|
|
1739
|
+
usedDiscountCardLimitCounts.set(_nextBundleDiscount.id, curLimitCount + 1);
|
|
1740
|
+
}
|
|
1741
|
+
var _nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
|
|
1742
|
+
var nextDiscountedPrice = getDiscountAmount(_nextBundleDiscount, product.origin_total, product.origin_total);
|
|
1743
|
+
var nextBundleDiscAmount = new Decimal(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
|
|
1744
|
+
var nextBundleDiscTypeStr = _nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _nextBundleDiscount.tag;
|
|
1745
|
+
var _nextDiscountDetail = {
|
|
1746
|
+
amount: nextBundleDiscAmount,
|
|
1747
|
+
type: nextBundleDiscTypeStr,
|
|
1748
|
+
discount: {
|
|
1749
|
+
discount_card_type: _nextBundleDiscount === null || _nextBundleDiscount === void 0 || (_nextBundleDiscount$m2 = _nextBundleDiscount.metadata) === null || _nextBundleDiscount$m2 === void 0 ? void 0 : _nextBundleDiscount$m2.discount_card_type,
|
|
1750
|
+
fixed_amount: nextBundleDiscAmount,
|
|
1751
|
+
resource_id: _nextBundleDiscount.id,
|
|
1752
|
+
title: _nextBundleDiscount.format_title,
|
|
1753
|
+
original_amount: product.origin_total,
|
|
1754
|
+
product_id: product.id,
|
|
1755
|
+
percent: _nextBundleDiscount.par_value,
|
|
1756
|
+
discount_product_id: _nextBundleDiscount.product_id
|
|
1757
|
+
},
|
|
1758
|
+
metadata: {
|
|
1759
|
+
custom_product_bundle_map_id: _nextUniqueId,
|
|
1760
|
+
num: 1
|
|
1761
|
+
},
|
|
1762
|
+
_num: 1,
|
|
1763
|
+
config: _nextBundleDiscount === null || _nextBundleDiscount === void 0 ? void 0 : _nextBundleDiscount.config
|
|
1764
|
+
};
|
|
1765
|
+
var _nextAppliedProducts = appliedDiscountProducts.get(_nextBundleDiscount.id) || [];
|
|
1766
|
+
_nextAppliedProducts.push(_nextDiscountDetail);
|
|
1767
|
+
appliedDiscountProducts.set(_nextBundleDiscount.id, _nextAppliedProducts);
|
|
1768
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1769
|
+
_id: _nextUniqueId,
|
|
1770
|
+
num: 1,
|
|
1771
|
+
quantity: 1,
|
|
1772
|
+
price: nextDiscountedPrice,
|
|
1773
|
+
total: nextDiscountedPrice,
|
|
1774
|
+
discount_list: [_nextDiscountDetail],
|
|
1775
|
+
processed: true,
|
|
1776
|
+
_discountId: _nextBundleDiscount.id
|
|
1777
|
+
}));
|
|
1778
|
+
continueSplitIndex++;
|
|
1779
|
+
}
|
|
1780
|
+
remainingNum -= nextSplitCount;
|
|
1287
1781
|
}
|
|
1288
1782
|
} else {
|
|
1289
|
-
var
|
|
1290
|
-
//
|
|
1291
|
-
var
|
|
1292
|
-
usedDiscounts.set(
|
|
1783
|
+
var _currentBundleDiscoun3, _currentBundleDiscoun4, _flatItem$parentProdu10;
|
|
1784
|
+
// 不拆分:直接应用折扣
|
|
1785
|
+
var _currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
1786
|
+
usedDiscounts.set(_currentBundleDiscount.id, true);
|
|
1787
|
+
// 🔥 更新 product_id 使用计数
|
|
1788
|
+
if ((_currentBundleDiscount.tag || _currentBundleDiscount.type) === 'good_pass') {
|
|
1789
|
+
var _currentCount2 = usedProductIdCounts.get(_currentBundleDiscount.product_id) || 0;
|
|
1790
|
+
usedProductIdCounts.set(_currentBundleDiscount.product_id, _currentCount2 + 1);
|
|
1791
|
+
}
|
|
1792
|
+
// 🔥 更新折扣卡 applicableProductLimit 使用计数(不拆分时按商品数量计数)
|
|
1793
|
+
var noSplitDiscountType = _currentBundleDiscount.tag || _currentBundleDiscount.type;
|
|
1794
|
+
if (['discount_card', 'product_discount_card'].includes(noSplitDiscountType)) {
|
|
1795
|
+
var bundleQuantity = product.num || 1;
|
|
1796
|
+
var currentNoSplitCount = usedDiscountCardLimitCounts.get(_currentBundleDiscount.id) || 0;
|
|
1797
|
+
usedDiscountCardLimitCounts.set(_currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
|
|
1798
|
+
}
|
|
1293
1799
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1294
1800
|
|
|
1295
1801
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1296
|
-
var _isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1297
|
-
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1802
|
+
var _isOrderLevel = isOrderLevelFixedAmountDiscount(selectedDiscount);
|
|
1803
|
+
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
|
|
1298
1804
|
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1299
|
-
var
|
|
1805
|
+
var targetProductTotal;
|
|
1300
1806
|
var fixedAmountPerItem;
|
|
1301
1807
|
var _productDiscountDifference;
|
|
1302
1808
|
if (_isOrderLevel && _productAllocation) {
|
|
1303
1809
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1304
1810
|
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1305
1811
|
_productDiscountDifference = _productAllocation.difference;
|
|
1306
|
-
|
|
1812
|
+
targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1307
1813
|
} else {
|
|
1308
1814
|
// item_level 或其他类型:使用原有逻辑
|
|
1309
|
-
|
|
1310
|
-
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(
|
|
1815
|
+
targetProductTotal = getDiscountAmount(_currentBundleDiscount, _productOriginTotal, _productOriginTotal);
|
|
1816
|
+
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1311
1817
|
}
|
|
1312
1818
|
|
|
1819
|
+
// 计算实际折扣金额
|
|
1820
|
+
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1821
|
+
|
|
1313
1822
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1314
1823
|
var _uniqueId = flatItem._id;
|
|
1315
1824
|
var _discountDetail2 = {
|
|
1316
|
-
amount:
|
|
1317
|
-
type:
|
|
1825
|
+
amount: bundleActualDiscountAmount * (product.num || 1),
|
|
1826
|
+
type: _currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _currentBundleDiscount.tag,
|
|
1318
1827
|
discount: {
|
|
1319
|
-
discount_card_type:
|
|
1320
|
-
fixed_amount:
|
|
1321
|
-
discount_calculation_mode:
|
|
1322
|
-
resource_id:
|
|
1323
|
-
title:
|
|
1828
|
+
discount_card_type: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun3 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun3 === void 0 ? void 0 : _currentBundleDiscoun3.discount_card_type,
|
|
1829
|
+
fixed_amount: bundleActualDiscountAmount,
|
|
1830
|
+
discount_calculation_mode: _currentBundleDiscount === null || _currentBundleDiscount === void 0 || (_currentBundleDiscoun4 = _currentBundleDiscount.metadata) === null || _currentBundleDiscoun4 === void 0 ? void 0 : _currentBundleDiscoun4.discount_calculation_mode,
|
|
1831
|
+
resource_id: _currentBundleDiscount.id,
|
|
1832
|
+
title: _currentBundleDiscount.format_title,
|
|
1324
1833
|
original_amount: product.original_price,
|
|
1325
1834
|
product_id: product.id,
|
|
1326
|
-
percent:
|
|
1835
|
+
percent: _currentBundleDiscount.par_value,
|
|
1836
|
+
discount_product_id: _currentBundleDiscount.product_id
|
|
1327
1837
|
},
|
|
1328
1838
|
metadata: _objectSpread({
|
|
1329
1839
|
// 🔥 使用唯一的 _id
|
|
1330
1840
|
custom_product_bundle_map_id: _uniqueId,
|
|
1331
|
-
discount_rule_uncheck_flag:
|
|
1841
|
+
discount_rule_uncheck_flag: selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
|
|
1332
1842
|
num: product.num || 1
|
|
1333
1843
|
}, _productDiscountDifference !== undefined && {
|
|
1334
1844
|
product_discount_difference: _productDiscountDifference
|
|
1335
1845
|
}),
|
|
1336
|
-
|
|
1846
|
+
config: _currentBundleDiscount === null || _currentBundleDiscount === void 0 ? void 0 : _currentBundleDiscount.config,
|
|
1847
|
+
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.num) || 1)
|
|
1337
1848
|
};
|
|
1338
1849
|
|
|
1339
1850
|
// 记录实际应用的折扣
|
|
1340
|
-
var _appliedProducts2 = appliedDiscountProducts.get(
|
|
1851
|
+
var _appliedProducts2 = appliedDiscountProducts.get(_currentBundleDiscount.id) || [];
|
|
1341
1852
|
_appliedProducts2.push(_discountDetail2);
|
|
1342
|
-
appliedDiscountProducts.set(
|
|
1853
|
+
appliedDiscountProducts.set(_currentBundleDiscount.id, _appliedProducts2);
|
|
1343
1854
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1344
|
-
total:
|
|
1855
|
+
total: targetProductTotal,
|
|
1345
1856
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
1346
1857
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
1347
1858
|
processed: true
|
|
@@ -1360,8 +1871,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1360
1871
|
// 获取主商品处理结果
|
|
1361
1872
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
1362
1873
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1363
|
-
//
|
|
1874
|
+
// 如果没有处理结果,返回默认商品(还原 option 价格)
|
|
1364
1875
|
var getDefaultProduct = function getDefaultProduct() {
|
|
1876
|
+
var restoredOptions = restoreOptionPrices(product.options);
|
|
1365
1877
|
if (product.isClient) {
|
|
1366
1878
|
return _this3.hooks.setProduct(originProduct, {
|
|
1367
1879
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
@@ -1371,7 +1883,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1371
1883
|
original_price: product.original_price
|
|
1372
1884
|
},
|
|
1373
1885
|
bundle: product.bundle,
|
|
1374
|
-
options:
|
|
1886
|
+
options: restoredOptions
|
|
1375
1887
|
}),
|
|
1376
1888
|
variant: originProduct._productInit.variant,
|
|
1377
1889
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1380,15 +1892,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1380
1892
|
price: product.price
|
|
1381
1893
|
},
|
|
1382
1894
|
bundle: product.bundle,
|
|
1383
|
-
options:
|
|
1384
|
-
})
|
|
1895
|
+
options: restoredOptions
|
|
1896
|
+
}),
|
|
1897
|
+
options: restoredOptions
|
|
1385
1898
|
});
|
|
1386
1899
|
} else {
|
|
1387
1900
|
return _this3.hooks.setProduct(originProduct, {
|
|
1388
1901
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1389
1902
|
total: product.total,
|
|
1390
1903
|
origin_total: product.origin_total,
|
|
1391
|
-
price: product.price
|
|
1904
|
+
price: product.price,
|
|
1905
|
+
options: restoreOptionPrices(product.options)
|
|
1392
1906
|
});
|
|
1393
1907
|
}
|
|
1394
1908
|
};
|
|
@@ -1464,6 +1978,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1464
1978
|
product_id: bundleItem.product_id,
|
|
1465
1979
|
price: item.price,
|
|
1466
1980
|
num: item.num,
|
|
1981
|
+
quantity: item.num,
|
|
1467
1982
|
discount_list: updatedDiscountList
|
|
1468
1983
|
}));
|
|
1469
1984
|
});
|
|
@@ -1487,6 +2002,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1487
2002
|
product_id: bundleItem.product_id,
|
|
1488
2003
|
price: item.price,
|
|
1489
2004
|
num: item.num,
|
|
2005
|
+
quantity: item.num,
|
|
1490
2006
|
discount_list: _updatedDiscountList
|
|
1491
2007
|
}));
|
|
1492
2008
|
} else {
|
|
@@ -1501,8 +2017,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1501
2017
|
|
|
1502
2018
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
|
|
1503
2019
|
var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
|
|
1504
|
-
var _discount$
|
|
1505
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
2020
|
+
var _discount$metadata7, _discount$metadata8;
|
|
2021
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata7 = discount.metadata) !== null && _discount$metadata7 !== void 0 && _discount$metadata7.custom_product_bundle_map_id) {
|
|
1506
2022
|
// bundle的discount_list保持不变
|
|
1507
2023
|
return discount;
|
|
1508
2024
|
}
|
|
@@ -1510,7 +2026,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1510
2026
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1511
2027
|
// num: 1,
|
|
1512
2028
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1513
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
2029
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata8 = discount.metadata) === null || _discount$metadata8 === void 0 ? void 0 : _discount$metadata8.custom_product_bundle_map_id,
|
|
1514
2030
|
num: 1
|
|
1515
2031
|
})
|
|
1516
2032
|
});
|
|
@@ -1555,8 +2071,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1555
2071
|
quantity: 1,
|
|
1556
2072
|
discount_list: updatedMainDiscountList,
|
|
1557
2073
|
bundle: newBundleWithDiscount,
|
|
1558
|
-
total:
|
|
1559
|
-
origin_total:
|
|
2074
|
+
total: newTotalWithDiscount,
|
|
2075
|
+
origin_total: newOriginTotalWithDiscount
|
|
1560
2076
|
})));
|
|
1561
2077
|
|
|
1562
2078
|
// 第二个:包含原始bundle (qty=原quantity-1)
|
|
@@ -1575,8 +2091,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1575
2091
|
|
|
1576
2092
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
|
|
1577
2093
|
var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
|
|
1578
|
-
var _discount$
|
|
1579
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
2094
|
+
var _discount$metadata9, _discount$metadata10;
|
|
2095
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata9 = discount.metadata) !== null && _discount$metadata9 !== void 0 && _discount$metadata9.custom_product_bundle_map_id) {
|
|
1580
2096
|
// bundle的discount_list保持不变
|
|
1581
2097
|
return discount;
|
|
1582
2098
|
}
|
|
@@ -1584,7 +2100,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1584
2100
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1585
2101
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1586
2102
|
num: mainProductQuantity - 1,
|
|
1587
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
2103
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata10 = discount.metadata) === null || _discount$metadata10 === void 0 ? void 0 : _discount$metadata10.custom_product_bundle_map_id
|
|
1588
2104
|
})
|
|
1589
2105
|
// num: mainProductQuantity - 1,
|
|
1590
2106
|
});
|
|
@@ -1651,11 +2167,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1651
2167
|
processedBundleItems.forEach(function (item) {
|
|
1652
2168
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
1653
2169
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1654
|
-
var _discount$
|
|
2170
|
+
var _discount$metadata11;
|
|
1655
2171
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1656
2172
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1657
2173
|
num: item.num,
|
|
1658
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
2174
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata11 = discount.metadata) === null || _discount$metadata11 === void 0 ? void 0 : _discount$metadata11.custom_product_bundle_map_id
|
|
1659
2175
|
})
|
|
1660
2176
|
// num: item.num, // 使用拆分后的 num
|
|
1661
2177
|
});
|
|
@@ -1665,7 +2181,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1665
2181
|
product_id: bundleItem.product_id,
|
|
1666
2182
|
price: item.price,
|
|
1667
2183
|
num: item.num,
|
|
1668
|
-
|
|
2184
|
+
quantity: item.num,
|
|
2185
|
+
discount_list: updatedDiscountList,
|
|
2186
|
+
bundle_selling_price: bundleItem.bundle_selling_price !== undefined ? item.price : undefined
|
|
1669
2187
|
}));
|
|
1670
2188
|
});
|
|
1671
2189
|
}
|
|
@@ -1703,13 +2221,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1703
2221
|
|
|
1704
2222
|
// 累加bundle的价格(只累加一次)
|
|
1705
2223
|
if (newBundle.length > 0) {
|
|
1706
|
-
newBundle.forEach(function (item) {
|
|
1707
|
-
newTotal += Number(item.price) * Number(item.num);
|
|
1708
|
-
});
|
|
1709
|
-
|
|
1710
|
-
// 计算原始总价(不考虑折扣)
|
|
1711
2224
|
newBundle.forEach(function (item) {
|
|
1712
2225
|
var _item$discount_list3;
|
|
2226
|
+
newTotal += Number(item.price) * Number(item.num);
|
|
1713
2227
|
var originalPrice = ((_item$discount_list3 = item.discount_list) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3[0]) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3.discount) === null || _item$discount_list3 === void 0 ? void 0 : _item$discount_list3.original_amount) || item.price;
|
|
1714
2228
|
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
1715
2229
|
});
|
|
@@ -1724,8 +2238,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1724
2238
|
return accumulator.add(currentPrice.mul(currentNum));
|
|
1725
2239
|
}, new Decimal(newTotal)).toNumber();
|
|
1726
2240
|
}
|
|
1727
|
-
newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
1728
|
-
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
1729
2241
|
|
|
1730
2242
|
// 生成最终的主商品
|
|
1731
2243
|
result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|