@pisell/pisellos 2.1.118 → 2.1.119
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 +24 -56
- package/dist/modules/Discount/types.d.ts +0 -18
- 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 +5 -9
- package/dist/modules/Rules/index.js +162 -674
- package/dist/modules/Rules/types.d.ts +0 -2
- 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/BookingByStep/index.js +44 -42
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
- 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 +7 -23
- package/dist/solution/ShopDiscount/types.d.ts +0 -1
- package/dist/solution/ShopDiscount/types.js +1 -2
- package/dist/solution/ShopDiscount/utils.js +12 -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 +11 -39
- package/lib/modules/Discount/types.d.ts +0 -18
- 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 +5 -9
- package/lib/modules/Rules/index.js +284 -779
- package/lib/modules/Rules/types.d.ts +0 -2
- 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/BookingByStep/index.js +4 -2
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +8 -22
- 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 -499
- 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 -26
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -187
- 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 -1104
- 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 -423
- 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 -54
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -187
- 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 -791
- 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
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
var _excluded = ["_original_add_price"],
|
|
2
|
-
_excluded2 = ["_original_price", "_original_add_price"];
|
|
3
1
|
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; }
|
|
6
2
|
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; }
|
|
7
3
|
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; }
|
|
8
4
|
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; } } }; }
|
|
@@ -35,6 +31,7 @@ import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils"
|
|
|
35
31
|
import Decimal from 'decimal.js';
|
|
36
32
|
import { isBoolean } from 'lodash-es';
|
|
37
33
|
import dayjs from 'dayjs';
|
|
34
|
+
|
|
38
35
|
// 临时变量
|
|
39
36
|
var flatItem;
|
|
40
37
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
@@ -47,8 +44,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
47
44
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
|
|
48
45
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
49
46
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
50
|
-
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
51
|
-
// WindowPlugin 实例
|
|
52
47
|
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
53
48
|
_this.hooks = {};
|
|
54
49
|
return _this;
|
|
@@ -63,8 +58,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
63
58
|
this.core = core;
|
|
64
59
|
this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
|
|
65
60
|
this.store = options === null || options === void 0 ? void 0 : options.store;
|
|
66
|
-
|
|
67
|
-
case 4:
|
|
61
|
+
case 3:
|
|
68
62
|
case "end":
|
|
69
63
|
return _context.stop();
|
|
70
64
|
}
|
|
@@ -119,12 +113,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
119
113
|
// 最终直接匹配 holder 是否相同
|
|
120
114
|
return (productHolderId || orderHolderId) === discount.holder.holder_id;
|
|
121
115
|
}
|
|
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
|
-
}
|
|
128
116
|
|
|
129
117
|
// 判断discountList 是否可以对当前productList生效
|
|
130
118
|
}, {
|
|
@@ -134,7 +122,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
134
122
|
var oldDiscountList = _ref.oldDiscountList,
|
|
135
123
|
newDiscountList = _ref.newDiscountList,
|
|
136
124
|
productList = _ref.productList,
|
|
137
|
-
orderTotalAmount = _ref.orderTotalAmount,
|
|
138
125
|
holders = _ref.holders,
|
|
139
126
|
isFormSubject = _ref.isFormSubject;
|
|
140
127
|
// 首先检查是否有新的优惠券可应用
|
|
@@ -169,7 +156,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
169
156
|
var result = this.calcDiscount({
|
|
170
157
|
discountList: mergedDiscountList,
|
|
171
158
|
productList: _toConsumableArray(productList),
|
|
172
|
-
orderTotalAmount: orderTotalAmount,
|
|
173
159
|
holders: holders,
|
|
174
160
|
isFormSubject: isFormSubject
|
|
175
161
|
}, {
|
|
@@ -303,8 +289,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
303
289
|
var discountList = _ref2.discountList,
|
|
304
290
|
productList = _ref2.productList,
|
|
305
291
|
holders = _ref2.holders,
|
|
306
|
-
isFormSubject = _ref2.isFormSubject
|
|
307
|
-
orderTotalAmount = _ref2.orderTotalAmount;
|
|
292
|
+
isFormSubject = _ref2.isFormSubject;
|
|
308
293
|
var editModeDiscount = [];
|
|
309
294
|
var addModeDiscount = [];
|
|
310
295
|
discountList.forEach(function (discount) {
|
|
@@ -553,62 +538,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
553
538
|
return priceB.minus(priceA).toNumber();
|
|
554
539
|
});
|
|
555
540
|
|
|
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
|
-
|
|
609
541
|
/**
|
|
610
|
-
|
|
611
|
-
|
|
542
|
+
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
543
|
+
const sortedProductList = [...productList].sort((a, b) => {
|
|
612
544
|
const aProduct = this.hooks.getProduct(a);
|
|
613
545
|
const bProduct = this.hooks.getProduct(b);
|
|
614
546
|
const priceA = new Decimal((aProduct.price as string) || '0');
|
|
@@ -626,22 +558,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
626
558
|
// 标记已使用的优惠券
|
|
627
559
|
var usedDiscounts = new Map();
|
|
628
560
|
|
|
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
|
-
|
|
645
561
|
// 记录每个优惠券适用的商品ID
|
|
646
562
|
var discountApplicability = new Map();
|
|
647
563
|
|
|
@@ -857,7 +773,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
857
773
|
var _flatItem$parentProdu5;
|
|
858
774
|
// bundle子商品:构造虚拟商品对象
|
|
859
775
|
product = {
|
|
860
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
|
|
861
776
|
_id: flatItem._id,
|
|
862
777
|
id: flatItem.id,
|
|
863
778
|
price: flatItem.price,
|
|
@@ -866,12 +781,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
866
781
|
total: flatItem.total,
|
|
867
782
|
origin_total: flatItem.origin_total,
|
|
868
783
|
booking_id: flatItem.booking_id,
|
|
869
|
-
discount_list: flatItem.discount_list || []
|
|
784
|
+
discount_list: flatItem.discount_list || [],
|
|
785
|
+
startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
|
|
870
786
|
};
|
|
871
787
|
originProduct = flatItem.originProduct;
|
|
872
788
|
}
|
|
873
789
|
addModeDiscount.forEach(function (discount) {
|
|
874
|
-
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4
|
|
790
|
+
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
|
|
875
791
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
876
792
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
877
793
|
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;
|
|
@@ -882,7 +798,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
882
798
|
var timeLimit = true;
|
|
883
799
|
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
884
800
|
// 是符合折扣的商品
|
|
885
|
-
var isLimitedProduct = (limitedData.type === 'product_all'
|
|
801
|
+
var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
886
802
|
|
|
887
803
|
// 编辑的商品 使用了优惠券不可用
|
|
888
804
|
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) {
|
|
@@ -895,8 +811,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
895
811
|
var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
|
|
896
812
|
|
|
897
813
|
// 判断优惠券是否适用于该商品
|
|
898
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable
|
|
899
|
-
var _discountApplicabilit, _discount$
|
|
814
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
815
|
+
var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
|
|
900
816
|
// 记录此优惠券适用的商品
|
|
901
817
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
902
818
|
|
|
@@ -912,15 +828,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
912
828
|
type: discountType,
|
|
913
829
|
tag: discountType,
|
|
914
830
|
discount: {
|
|
915
|
-
discount_card_type: discount === null || discount === void 0 || (_discount$
|
|
831
|
+
discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
|
|
916
832
|
fixed_amount: product.price,
|
|
917
|
-
discount_calculation_mode: discount === null || discount === void 0 || (_discount$
|
|
833
|
+
discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
|
|
918
834
|
resource_id: discount.id,
|
|
919
835
|
title: discount.format_title,
|
|
920
836
|
original_amount: product.price || product.origin_total,
|
|
921
837
|
pre_value: discount.par_value,
|
|
922
|
-
product_id: originProduct.id
|
|
923
|
-
discount_product_id: discount.product_id
|
|
838
|
+
product_id: originProduct.id
|
|
924
839
|
},
|
|
925
840
|
metadata: {
|
|
926
841
|
num: num,
|
|
@@ -936,75 +851,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
936
851
|
// 🔥 用于存储扁平化商品处理结果的Map
|
|
937
852
|
var processedFlatItemsMap = new Map();
|
|
938
853
|
|
|
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
|
-
|
|
994
854
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
995
855
|
// 🔥 使用扁平化后的列表进行处理
|
|
996
856
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
997
|
-
var _product10, _product$discount_lis2, _product11
|
|
857
|
+
var _product10, _product$discount_lis2, _product11;
|
|
998
858
|
// 获取商品数据
|
|
999
859
|
var product, originProduct;
|
|
1000
860
|
if (flatItem.type === 'main') {
|
|
1001
861
|
product = flatItem.product;
|
|
1002
862
|
originProduct = flatItem.originProduct;
|
|
1003
863
|
} else {
|
|
1004
|
-
var _flatItem$
|
|
864
|
+
var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu6;
|
|
1005
865
|
// bundle子商品
|
|
1006
866
|
product = {
|
|
1007
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate,
|
|
1008
867
|
_id: flatItem._id,
|
|
1009
868
|
id: flatItem.id,
|
|
1010
869
|
price: flatItem.price,
|
|
@@ -1014,7 +873,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1014
873
|
original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
|
|
1015
874
|
origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
|
|
1016
875
|
booking_id: flatItem.booking_id,
|
|
1017
|
-
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || []
|
|
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
|
|
1018
878
|
};
|
|
1019
879
|
originProduct = flatItem.originProduct;
|
|
1020
880
|
}
|
|
@@ -1036,53 +896,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1036
896
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1037
897
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1038
898
|
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
|
-
|
|
1049
899
|
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
1050
900
|
// 商品券时主商品价格为0不可用
|
|
1051
901
|
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;
|
|
1052
902
|
|
|
1053
903
|
// 折扣卡商品价格为0时不可用
|
|
1054
|
-
if ((Number(product.
|
|
904
|
+
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) {
|
|
1055
905
|
var _n$discount;
|
|
1056
906
|
return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
|
|
1057
907
|
})) && (discount.tag || discount.type) !== 'good_pass') return false;
|
|
1058
908
|
// 如果优惠券已被使用,则跳过
|
|
1059
909
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
1060
910
|
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
|
-
}
|
|
1086
911
|
var limitedData = discount.limited_relation_product_data;
|
|
1087
912
|
|
|
1088
913
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
@@ -1101,9 +926,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1101
926
|
|
|
1102
927
|
// 判断优惠券是否适用于该商品
|
|
1103
928
|
if (limitedData.type === 'product_all') {
|
|
1104
|
-
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1105
|
-
return false;
|
|
1106
|
-
}
|
|
1107
929
|
// 检查 package_sub_item_usage_rules
|
|
1108
930
|
if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1109
931
|
return false;
|
|
@@ -1133,22 +955,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1133
955
|
var _product$discount_lis5, _product12, _product12$every;
|
|
1134
956
|
// 主商品:判断自身是否手动折扣
|
|
1135
957
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1136
|
-
var
|
|
1137
|
-
return !((
|
|
958
|
+
var _ref6;
|
|
959
|
+
return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
|
|
1138
960
|
}) && (!((_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) {
|
|
1139
961
|
return item.type === 'product';
|
|
1140
962
|
})));
|
|
1141
|
-
if (product.inPromotion) {
|
|
1142
|
-
isManualDiscount = false;
|
|
1143
|
-
}
|
|
1144
963
|
} else {
|
|
1145
964
|
// bundle子商品:判断父主商品是否手动折扣
|
|
1146
965
|
var parentProduct = flatItem.parentProduct;
|
|
1147
966
|
if (parentProduct) {
|
|
1148
967
|
var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
|
|
1149
968
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
1150
|
-
var
|
|
1151
|
-
return !((
|
|
969
|
+
var _ref7;
|
|
970
|
+
return !((_ref7 = item.discount_list || []) !== null && _ref7 !== void 0 && _ref7.length);
|
|
1152
971
|
}) && (!((_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) {
|
|
1153
972
|
return item.type === 'product';
|
|
1154
973
|
})));
|
|
@@ -1215,8 +1034,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1215
1034
|
// 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
|
|
1216
1035
|
if (applicableDiscounts.length === 0 || isManualDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
1217
1036
|
if (flatItem.type === 'main') {
|
|
1218
|
-
//
|
|
1219
|
-
var restoredOptions = restoreOptionPrices(product.options);
|
|
1037
|
+
// 主商品:保持原有逻辑
|
|
1220
1038
|
if (product.isClient) {
|
|
1221
1039
|
processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1222
1040
|
origin_total: getProductOriginTotalPrice({
|
|
@@ -1224,7 +1042,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1224
1042
|
original_price: product.original_price
|
|
1225
1043
|
},
|
|
1226
1044
|
bundle: product.bundle,
|
|
1227
|
-
options:
|
|
1045
|
+
options: product.options
|
|
1228
1046
|
}),
|
|
1229
1047
|
variant: originProduct._productInit.variant,
|
|
1230
1048
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1233,16 +1051,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1233
1051
|
price: product.price
|
|
1234
1052
|
},
|
|
1235
1053
|
bundle: product.bundle,
|
|
1236
|
-
options:
|
|
1054
|
+
options: product.options
|
|
1237
1055
|
}),
|
|
1238
|
-
price: product.price
|
|
1239
|
-
options: restoredOptions
|
|
1056
|
+
price: product.price
|
|
1240
1057
|
}), {}, {
|
|
1241
1058
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1242
1059
|
}))]);
|
|
1243
1060
|
} else {
|
|
1244
|
-
var
|
|
1245
|
-
var total = product.inPromotion ? (
|
|
1061
|
+
var _ref8, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
|
|
1062
|
+
var total = product.inPromotion ? (_ref8 = (_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 && _ref8 !== void 0 ? _ref8 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1246
1063
|
var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
|
|
1247
1064
|
if ((product.discount_list || []).some(function (item) {
|
|
1248
1065
|
return item.type === 'promotion';
|
|
@@ -1257,8 +1074,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1257
1074
|
_id: product._id.split('___')[0] + '___' + index,
|
|
1258
1075
|
total: total,
|
|
1259
1076
|
price: product.price,
|
|
1260
|
-
main_product_selling_price: main_product_selling_price
|
|
1261
|
-
options: restoredOptions
|
|
1077
|
+
main_product_selling_price: main_product_selling_price
|
|
1262
1078
|
}), {}, {
|
|
1263
1079
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1264
1080
|
}))]);
|
|
@@ -1278,81 +1094,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1278
1094
|
return;
|
|
1279
1095
|
}
|
|
1280
1096
|
|
|
1281
|
-
//
|
|
1282
|
-
var
|
|
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;
|
|
1097
|
+
// 是否需要拆分(商品券需要拆分)
|
|
1098
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
1289
1099
|
|
|
1290
1100
|
// 需要拆分出来的数量
|
|
1291
1101
|
var totalQuantity = product.quantity || product.num || 1;
|
|
1292
1102
|
var availableGoodPassCount = applicableDiscounts.filter(function (item) {
|
|
1293
1103
|
return (item.tag || item.type) === 'good_pass';
|
|
1294
1104
|
}).length;
|
|
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;
|
|
1105
|
+
var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
1314
1106
|
var arr = [];
|
|
1315
1107
|
|
|
1316
1108
|
// 🔥 主商品和bundle子商品分别处理
|
|
1317
1109
|
if (flatItem.type === 'main') {
|
|
1318
1110
|
// 主商品:保持原有逻辑
|
|
1319
1111
|
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
|
-
}
|
|
1328
1112
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1329
1113
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1330
1114
|
quantity: totalQuantity - splitCount,
|
|
1331
|
-
_id: product._id.split('___')[0]
|
|
1332
|
-
total: _total
|
|
1115
|
+
_id: product._id.split('___')[0]
|
|
1333
1116
|
}));
|
|
1334
1117
|
}
|
|
1335
1118
|
for (var i = 0; i < splitCount; i++) {
|
|
1336
|
-
var _originProduct, _selectedDiscount$
|
|
1337
|
-
//
|
|
1338
|
-
|
|
1339
|
-
var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1119
|
+
var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1120
|
+
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
1121
|
+
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
1340
1122
|
// 标记优惠券为已使用
|
|
1341
|
-
usedDiscounts.set(
|
|
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
|
-
}
|
|
1123
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
1353
1124
|
|
|
1354
1125
|
// 记录实际应用了优惠券的商品信息
|
|
1355
|
-
var appliedProducts = appliedDiscountProducts.get(
|
|
1126
|
+
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
1356
1127
|
|
|
1357
1128
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1358
1129
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
@@ -1367,492 +1138,210 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1367
1138
|
|
|
1368
1139
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
1369
1140
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1370
|
-
var isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1371
|
-
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1141
|
+
var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
|
|
1142
|
+
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
|
|
1372
1143
|
var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1373
|
-
var
|
|
1374
|
-
|
|
1375
|
-
// 主商品折后价(不含 option);勿与 option 合计混在同一变量,否则 main_product_selling_price 错误
|
|
1376
|
-
var mainProductSellingPrice = void 0;
|
|
1144
|
+
var targetProductTotal = void 0;
|
|
1377
1145
|
var amount = void 0;
|
|
1378
1146
|
var productDiscountDifference = void 0;
|
|
1379
|
-
var discountedOptions = product.options;
|
|
1380
|
-
var optionDiscountAmount = 0;
|
|
1381
1147
|
if (isOrderLevel && productAllocation) {
|
|
1382
1148
|
// order_level:使用预计算的分摊金额
|
|
1383
1149
|
amount = productAllocation.discountAmount;
|
|
1384
1150
|
productDiscountDifference = productAllocation.difference;
|
|
1385
|
-
|
|
1151
|
+
targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1386
1152
|
} else {
|
|
1387
1153
|
// item_level 或其他类型:使用原有逻辑
|
|
1388
|
-
|
|
1389
|
-
amount = new Decimal(product.price).minus(new Decimal(
|
|
1390
|
-
}
|
|
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;
|
|
1154
|
+
targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
|
|
1155
|
+
amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
|
|
1395
1156
|
}
|
|
1396
|
-
|
|
1397
|
-
|
|
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';
|
|
1157
|
+
var discountType = _selectedDiscount.tag || _selectedDiscount.type;
|
|
1158
|
+
var isGoodPass = discountType === 'good_pass';
|
|
1408
1159
|
var discountDetail = {
|
|
1409
|
-
amount:
|
|
1410
|
-
type:
|
|
1160
|
+
amount: amount,
|
|
1161
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
|
|
1411
1162
|
discount: {
|
|
1412
|
-
discount_card_type:
|
|
1413
|
-
fixed_amount:
|
|
1414
|
-
discount_calculation_mode:
|
|
1415
|
-
resource_id:
|
|
1416
|
-
title:
|
|
1163
|
+
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
1164
|
+
fixed_amount: amount,
|
|
1165
|
+
discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
|
|
1166
|
+
resource_id: _selectedDiscount.id,
|
|
1167
|
+
title: _selectedDiscount.format_title,
|
|
1417
1168
|
original_amount: product.price,
|
|
1418
1169
|
product_id: originProduct.id,
|
|
1419
|
-
percent:
|
|
1420
|
-
discount_product_id: currentSelectedDiscount.product_id
|
|
1170
|
+
percent: _selectedDiscount.par_value
|
|
1421
1171
|
},
|
|
1422
|
-
// 前端使用的num
|
|
1423
|
-
_num:
|
|
1424
|
-
|
|
1425
|
-
metadata: _objectSpread(_objectSpread({
|
|
1172
|
+
// 前端使用的num数量,为了计算优惠金额
|
|
1173
|
+
_num: isGoodPass ? 1 : product.num,
|
|
1174
|
+
metadata: _objectSpread({
|
|
1426
1175
|
num: 1,
|
|
1427
|
-
discount_rule_uncheck_flag:
|
|
1176
|
+
discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
|
|
1428
1177
|
}, productDiscountDifference !== undefined && {
|
|
1429
1178
|
product_discount_difference: productDiscountDifference
|
|
1430
|
-
}), {}, {
|
|
1431
|
-
/** 仅主商品上的优惠金额(不含 option) */
|
|
1432
|
-
mainProductDiscountAmount: mainProductDiscountAmount,
|
|
1433
|
-
optionDiscountAmount: optionDiscountAmount
|
|
1434
1179
|
})
|
|
1435
1180
|
};
|
|
1436
1181
|
appliedProducts.push(discountDetail);
|
|
1437
|
-
appliedDiscountProducts.set(
|
|
1182
|
+
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
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
|
+
}
|
|
1438
1191
|
|
|
1439
1192
|
// 记录应用了优惠券的商品
|
|
1440
1193
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1441
1194
|
if (product.isClient) {
|
|
1442
1195
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1443
1196
|
discount_list: [discountDetail],
|
|
1444
|
-
|
|
1445
|
-
price: currentIsGoodPass ? mainProductSellingPrice : product.price,
|
|
1197
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1446
1198
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1447
1199
|
origin_total: getProductOriginTotalPrice({
|
|
1448
1200
|
product: {
|
|
1449
1201
|
original_price: product.original_price
|
|
1450
1202
|
},
|
|
1451
1203
|
bundle: product.bundle,
|
|
1452
|
-
options:
|
|
1204
|
+
options: product.options
|
|
1453
1205
|
}),
|
|
1454
1206
|
variant: originProduct._productInit.variant,
|
|
1455
1207
|
original_price: new Decimal(product.price || 0).toNumber(),
|
|
1456
|
-
total:
|
|
1457
|
-
options: discountedOptions
|
|
1208
|
+
total: _total
|
|
1458
1209
|
}));
|
|
1459
1210
|
} else {
|
|
1460
1211
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1461
1212
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1462
|
-
_id: product._id.split('___')[0] +
|
|
1463
|
-
price:
|
|
1213
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
|
|
1214
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1464
1215
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1465
|
-
total:
|
|
1216
|
+
total: _total,
|
|
1466
1217
|
origin_total: productOriginTotal,
|
|
1467
|
-
main_product_selling_price:
|
|
1468
|
-
options: discountedOptions
|
|
1218
|
+
main_product_selling_price: targetProductTotal
|
|
1469
1219
|
}));
|
|
1470
1220
|
}
|
|
1471
1221
|
}
|
|
1472
1222
|
processedProductsMap.set(product._id, arr);
|
|
1473
1223
|
} else {
|
|
1474
|
-
// 🔥 bundle
|
|
1224
|
+
// 🔥 bundle子商品:支持拆分
|
|
1475
1225
|
var processedItems = [];
|
|
1476
1226
|
if (isNeedSplit) {
|
|
1477
|
-
//
|
|
1227
|
+
// 商品券:需要拆分数量
|
|
1478
1228
|
var discountNum = splitCount;
|
|
1479
1229
|
var normalNum = totalQuantity - discountNum;
|
|
1480
1230
|
|
|
1481
|
-
//
|
|
1231
|
+
// 生成有折扣的商品(每张商品券对应 num: 1)
|
|
1482
1232
|
for (var _i = 0; _i < discountNum; _i++) {
|
|
1483
|
-
var
|
|
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
|
-
}
|
|
1233
|
+
var _selectedDiscount2$me;
|
|
1234
|
+
var _selectedDiscount2 = applicableDiscounts[_i];
|
|
1235
|
+
usedDiscounts.set(_selectedDiscount2.id, true);
|
|
1499
1236
|
|
|
1500
1237
|
// 🔥 生成唯一的 _id
|
|
1501
1238
|
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;
|
|
1509
1239
|
var _discountDetail = {
|
|
1510
|
-
amount:
|
|
1511
|
-
type:
|
|
1240
|
+
amount: product.origin_total,
|
|
1241
|
+
type: 'good_pass',
|
|
1512
1242
|
discount: {
|
|
1513
|
-
|
|
1514
|
-
discount_calculation_mode:
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
title: currentBundleDiscount.format_title,
|
|
1243
|
+
fixed_amount: product.origin_total,
|
|
1244
|
+
discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
|
|
1245
|
+
resource_id: _selectedDiscount2.id,
|
|
1246
|
+
title: _selectedDiscount2.format_title,
|
|
1518
1247
|
original_amount: product.origin_total,
|
|
1519
|
-
product_id: product.id
|
|
1520
|
-
percent: currentBundleDiscount.par_value,
|
|
1521
|
-
discount_product_id: currentBundleDiscount.product_id
|
|
1248
|
+
product_id: product.id
|
|
1522
1249
|
},
|
|
1523
1250
|
metadata: {
|
|
1524
1251
|
// 🔥 使用拆分后的唯一 _id
|
|
1525
1252
|
custom_product_bundle_map_id: uniqueId,
|
|
1526
|
-
discount_rule_uncheck_flag:
|
|
1253
|
+
discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
|
|
1527
1254
|
num: 1
|
|
1528
1255
|
},
|
|
1529
|
-
_num: 1
|
|
1530
|
-
config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
|
|
1256
|
+
_num: 1
|
|
1531
1257
|
};
|
|
1532
1258
|
|
|
1533
1259
|
// 记录实际应用的折扣
|
|
1534
|
-
var _appliedProducts = appliedDiscountProducts.get(
|
|
1260
|
+
var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
|
|
1535
1261
|
_appliedProducts.push(_discountDetail);
|
|
1536
|
-
appliedDiscountProducts.set(
|
|
1262
|
+
appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
|
|
1537
1263
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1538
1264
|
// 🔥 使用唯一的 _id
|
|
1539
1265
|
_id: uniqueId,
|
|
1540
1266
|
num: 1,
|
|
1541
1267
|
quantity: 1,
|
|
1542
|
-
price:
|
|
1543
|
-
//
|
|
1544
|
-
total:
|
|
1268
|
+
price: 0,
|
|
1269
|
+
// 商品券价格为0
|
|
1270
|
+
total: 0,
|
|
1545
1271
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail]),
|
|
1546
1272
|
processed: true,
|
|
1547
|
-
_discountId:
|
|
1273
|
+
_discountId: _selectedDiscount2.id
|
|
1548
1274
|
}));
|
|
1549
1275
|
}
|
|
1550
1276
|
|
|
1551
|
-
//
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
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;
|
|
1277
|
+
// 生成无折扣的商品(剩余数量)
|
|
1278
|
+
if (normalNum > 0) {
|
|
1279
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1280
|
+
// 🔥 为剩余商品生成唯一的 _id
|
|
1281
|
+
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1282
|
+
num: normalNum,
|
|
1283
|
+
quantity: normalNum,
|
|
1284
|
+
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1285
|
+
processed: true
|
|
1286
|
+
}));
|
|
1781
1287
|
}
|
|
1782
1288
|
} else {
|
|
1783
|
-
var
|
|
1784
|
-
//
|
|
1785
|
-
var
|
|
1786
|
-
usedDiscounts.set(
|
|
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
|
-
}
|
|
1289
|
+
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
|
|
1290
|
+
// 折扣卡:不拆分数量,直接应用
|
|
1291
|
+
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1292
|
+
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
1799
1293
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1800
1294
|
|
|
1801
1295
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1802
|
-
var _isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1803
|
-
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1296
|
+
var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
|
|
1297
|
+
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
|
|
1804
1298
|
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1805
|
-
var
|
|
1299
|
+
var _targetProductTotal;
|
|
1806
1300
|
var fixedAmountPerItem;
|
|
1807
1301
|
var _productDiscountDifference;
|
|
1808
1302
|
if (_isOrderLevel && _productAllocation) {
|
|
1809
1303
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1810
1304
|
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1811
1305
|
_productDiscountDifference = _productAllocation.difference;
|
|
1812
|
-
|
|
1306
|
+
_targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1813
1307
|
} else {
|
|
1814
1308
|
// item_level 或其他类型:使用原有逻辑
|
|
1815
|
-
|
|
1816
|
-
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(
|
|
1309
|
+
_targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1310
|
+
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
|
|
1817
1311
|
}
|
|
1818
1312
|
|
|
1819
|
-
// 计算实际折扣金额
|
|
1820
|
-
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1821
|
-
|
|
1822
1313
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1823
1314
|
var _uniqueId = flatItem._id;
|
|
1824
1315
|
var _discountDetail2 = {
|
|
1825
|
-
amount:
|
|
1826
|
-
type:
|
|
1316
|
+
amount: fixedAmountPerItem * (product.num || 1),
|
|
1317
|
+
type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
|
|
1827
1318
|
discount: {
|
|
1828
|
-
discount_card_type:
|
|
1829
|
-
fixed_amount:
|
|
1830
|
-
discount_calculation_mode:
|
|
1831
|
-
resource_id:
|
|
1832
|
-
title:
|
|
1319
|
+
discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
|
|
1320
|
+
fixed_amount: fixedAmountPerItem,
|
|
1321
|
+
discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
|
|
1322
|
+
resource_id: _selectedDiscount3.id,
|
|
1323
|
+
title: _selectedDiscount3.format_title,
|
|
1833
1324
|
original_amount: product.original_price,
|
|
1834
1325
|
product_id: product.id,
|
|
1835
|
-
percent:
|
|
1836
|
-
discount_product_id: _currentBundleDiscount.product_id
|
|
1326
|
+
percent: _selectedDiscount3.par_value
|
|
1837
1327
|
},
|
|
1838
1328
|
metadata: _objectSpread({
|
|
1839
1329
|
// 🔥 使用唯一的 _id
|
|
1840
1330
|
custom_product_bundle_map_id: _uniqueId,
|
|
1841
|
-
discount_rule_uncheck_flag:
|
|
1331
|
+
discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
|
|
1842
1332
|
num: product.num || 1
|
|
1843
1333
|
}, _productDiscountDifference !== undefined && {
|
|
1844
1334
|
product_discount_difference: _productDiscountDifference
|
|
1845
1335
|
}),
|
|
1846
|
-
|
|
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)
|
|
1336
|
+
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
|
|
1848
1337
|
};
|
|
1849
1338
|
|
|
1850
1339
|
// 记录实际应用的折扣
|
|
1851
|
-
var _appliedProducts2 = appliedDiscountProducts.get(
|
|
1340
|
+
var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
|
|
1852
1341
|
_appliedProducts2.push(_discountDetail2);
|
|
1853
|
-
appliedDiscountProducts.set(
|
|
1342
|
+
appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
|
|
1854
1343
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1855
|
-
total:
|
|
1344
|
+
total: _targetProductTotal,
|
|
1856
1345
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
1857
1346
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
1858
1347
|
processed: true
|
|
@@ -1871,9 +1360,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1871
1360
|
// 获取主商品处理结果
|
|
1872
1361
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
1873
1362
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1874
|
-
//
|
|
1363
|
+
// 如果没有处理结果,返回默认商品
|
|
1875
1364
|
var getDefaultProduct = function getDefaultProduct() {
|
|
1876
|
-
var restoredOptions = restoreOptionPrices(product.options);
|
|
1877
1365
|
if (product.isClient) {
|
|
1878
1366
|
return _this3.hooks.setProduct(originProduct, {
|
|
1879
1367
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
@@ -1883,7 +1371,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1883
1371
|
original_price: product.original_price
|
|
1884
1372
|
},
|
|
1885
1373
|
bundle: product.bundle,
|
|
1886
|
-
options:
|
|
1374
|
+
options: product.options
|
|
1887
1375
|
}),
|
|
1888
1376
|
variant: originProduct._productInit.variant,
|
|
1889
1377
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1892,17 +1380,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1892
1380
|
price: product.price
|
|
1893
1381
|
},
|
|
1894
1382
|
bundle: product.bundle,
|
|
1895
|
-
options:
|
|
1896
|
-
})
|
|
1897
|
-
options: restoredOptions
|
|
1383
|
+
options: product.options
|
|
1384
|
+
})
|
|
1898
1385
|
});
|
|
1899
1386
|
} else {
|
|
1900
1387
|
return _this3.hooks.setProduct(originProduct, {
|
|
1901
1388
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1902
1389
|
total: product.total,
|
|
1903
1390
|
origin_total: product.origin_total,
|
|
1904
|
-
price: product.price
|
|
1905
|
-
options: restoreOptionPrices(product.options)
|
|
1391
|
+
price: product.price
|
|
1906
1392
|
});
|
|
1907
1393
|
}
|
|
1908
1394
|
};
|
|
@@ -1978,7 +1464,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1978
1464
|
product_id: bundleItem.product_id,
|
|
1979
1465
|
price: item.price,
|
|
1980
1466
|
num: item.num,
|
|
1981
|
-
quantity: item.num,
|
|
1982
1467
|
discount_list: updatedDiscountList
|
|
1983
1468
|
}));
|
|
1984
1469
|
});
|
|
@@ -2002,7 +1487,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2002
1487
|
product_id: bundleItem.product_id,
|
|
2003
1488
|
price: item.price,
|
|
2004
1489
|
num: item.num,
|
|
2005
|
-
quantity: item.num,
|
|
2006
1490
|
discount_list: _updatedDiscountList
|
|
2007
1491
|
}));
|
|
2008
1492
|
} else {
|
|
@@ -2017,8 +1501,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2017
1501
|
|
|
2018
1502
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
|
|
2019
1503
|
var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
|
|
2020
|
-
var _discount$
|
|
2021
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1504
|
+
var _discount$metadata6, _discount$metadata7;
|
|
1505
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
|
|
2022
1506
|
// bundle的discount_list保持不变
|
|
2023
1507
|
return discount;
|
|
2024
1508
|
}
|
|
@@ -2026,7 +1510,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2026
1510
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2027
1511
|
// num: 1,
|
|
2028
1512
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2029
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1513
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata7 = discount.metadata) === null || _discount$metadata7 === void 0 ? void 0 : _discount$metadata7.custom_product_bundle_map_id,
|
|
2030
1514
|
num: 1
|
|
2031
1515
|
})
|
|
2032
1516
|
});
|
|
@@ -2071,8 +1555,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2071
1555
|
quantity: 1,
|
|
2072
1556
|
discount_list: updatedMainDiscountList,
|
|
2073
1557
|
bundle: newBundleWithDiscount,
|
|
2074
|
-
total: newTotalWithDiscount,
|
|
2075
|
-
origin_total: newOriginTotalWithDiscount
|
|
1558
|
+
total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
|
|
1559
|
+
origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
|
|
2076
1560
|
})));
|
|
2077
1561
|
|
|
2078
1562
|
// 第二个:包含原始bundle (qty=原quantity-1)
|
|
@@ -2091,8 +1575,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2091
1575
|
|
|
2092
1576
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
|
|
2093
1577
|
var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
|
|
2094
|
-
var _discount$
|
|
2095
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1578
|
+
var _discount$metadata8, _discount$metadata9;
|
|
1579
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
|
|
2096
1580
|
// bundle的discount_list保持不变
|
|
2097
1581
|
return discount;
|
|
2098
1582
|
}
|
|
@@ -2100,7 +1584,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2100
1584
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2101
1585
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2102
1586
|
num: mainProductQuantity - 1,
|
|
2103
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1587
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata9 = discount.metadata) === null || _discount$metadata9 === void 0 ? void 0 : _discount$metadata9.custom_product_bundle_map_id
|
|
2104
1588
|
})
|
|
2105
1589
|
// num: mainProductQuantity - 1,
|
|
2106
1590
|
});
|
|
@@ -2167,11 +1651,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2167
1651
|
processedBundleItems.forEach(function (item) {
|
|
2168
1652
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
2169
1653
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
2170
|
-
var _discount$
|
|
1654
|
+
var _discount$metadata10;
|
|
2171
1655
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2172
1656
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2173
1657
|
num: item.num,
|
|
2174
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1658
|
+
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
|
|
2175
1659
|
})
|
|
2176
1660
|
// num: item.num, // 使用拆分后的 num
|
|
2177
1661
|
});
|
|
@@ -2181,9 +1665,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2181
1665
|
product_id: bundleItem.product_id,
|
|
2182
1666
|
price: item.price,
|
|
2183
1667
|
num: item.num,
|
|
2184
|
-
|
|
2185
|
-
discount_list: updatedDiscountList,
|
|
2186
|
-
bundle_selling_price: bundleItem.bundle_selling_price !== undefined ? item.price : undefined
|
|
1668
|
+
discount_list: updatedDiscountList
|
|
2187
1669
|
}));
|
|
2188
1670
|
});
|
|
2189
1671
|
}
|
|
@@ -2222,8 +1704,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2222
1704
|
// 累加bundle的价格(只累加一次)
|
|
2223
1705
|
if (newBundle.length > 0) {
|
|
2224
1706
|
newBundle.forEach(function (item) {
|
|
2225
|
-
var _item$discount_list3;
|
|
2226
1707
|
newTotal += Number(item.price) * Number(item.num);
|
|
1708
|
+
});
|
|
1709
|
+
|
|
1710
|
+
// 计算原始总价(不考虑折扣)
|
|
1711
|
+
newBundle.forEach(function (item) {
|
|
1712
|
+
var _item$discount_list3;
|
|
2227
1713
|
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;
|
|
2228
1714
|
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
2229
1715
|
});
|
|
@@ -2238,6 +1724,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2238
1724
|
return accumulator.add(currentPrice.mul(currentNum));
|
|
2239
1725
|
}, new Decimal(newTotal)).toNumber();
|
|
2240
1726
|
}
|
|
1727
|
+
newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
1728
|
+
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2241
1729
|
|
|
2242
1730
|
// 生成最终的主商品
|
|
2243
1731
|
result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
@@ -2345,14 +1833,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2345
1833
|
var ruleType = usageRules.type;
|
|
2346
1834
|
// 套餐适用范围配置
|
|
2347
1835
|
var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
|
|
2348
|
-
var
|
|
2349
|
-
scopeType =
|
|
2350
|
-
|
|
2351
|
-
exclude_bundle_product_ids =
|
|
2352
|
-
|
|
2353
|
-
include_bundle_product_ids =
|
|
2354
|
-
|
|
2355
|
-
filter =
|
|
1836
|
+
var _ref9 = packageScope || {},
|
|
1837
|
+
scopeType = _ref9.type,
|
|
1838
|
+
_ref9$exclude_bundle_ = _ref9.exclude_bundle_product_ids,
|
|
1839
|
+
exclude_bundle_product_ids = _ref9$exclude_bundle_ === void 0 ? [] : _ref9$exclude_bundle_,
|
|
1840
|
+
_ref9$include_bundle_ = _ref9.include_bundle_product_ids,
|
|
1841
|
+
include_bundle_product_ids = _ref9$include_bundle_ === void 0 ? [] : _ref9$include_bundle_,
|
|
1842
|
+
_ref9$filter = _ref9.filter,
|
|
1843
|
+
filter = _ref9$filter === void 0 ? 0 : _ref9$filter;
|
|
2356
1844
|
var isMainProduct = flatItem.type === 'main'; // 单独购买
|
|
2357
1845
|
var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
|
|
2358
1846
|
|
|
@@ -2367,12 +1855,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2367
1855
|
return true; // 单独购买时可用
|
|
2368
1856
|
}
|
|
2369
1857
|
if (isBundleItem) {
|
|
2370
|
-
var _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu, _flatItem$
|
|
1858
|
+
var _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu, _flatItem$parentProdu10;
|
|
2371
1859
|
// 套餐中购买时,判断是否为原价
|
|
2372
1860
|
var priceType = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type;
|
|
2373
1861
|
var priceTypeExt = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type_ext;
|
|
2374
1862
|
// 主商品id
|
|
2375
|
-
var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 || (_flatItem$originProdu = _flatItem$originProdu._productOrigin) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || (flatItem === null || flatItem === void 0 || (_flatItem$
|
|
1863
|
+
var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 || (_flatItem$originProdu = _flatItem$originProdu._productOrigin) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || (flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.id) || 0;
|
|
2376
1864
|
// original_price 对应:
|
|
2377
1865
|
// 1. price_type: "markup" && price_type_ext: "product_price"
|
|
2378
1866
|
// markup_price 对应:
|