@pisell/pisellos 2.1.118 → 2.1.120
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.js +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +4 -1
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
- package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/dist/model/strategy/adapter/promotion/examples.js +166 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/dist/model/strategy/adapter/promotion/type.js +209 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -1
- package/dist/model/strategy/engine.d.ts +106 -0
- package/dist/model/strategy/engine.js +611 -0
- package/dist/model/strategy/index.d.ts +2 -93
- package/dist/model/strategy/index.js +6 -549
- package/dist/modules/Cart/types.d.ts +0 -2
- package/dist/modules/Cart/utils/cartProduct.js +25 -56
- package/dist/modules/Discount/types.d.ts +0 -18
- package/dist/modules/OpenData/index.d.ts +23 -0
- package/dist/modules/OpenData/index.js +167 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +58 -1
- package/dist/modules/Order/index.js +780 -29
- package/dist/modules/Order/types.d.ts +144 -12
- package/dist/modules/Order/utils.d.ts +25 -0
- package/dist/modules/Order/utils.js +225 -1
- 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/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -1
- package/dist/modules/Quotation/index.d.ts +48 -0
- package/dist/modules/Quotation/index.js +245 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/index.d.ts +5 -9
- package/dist/modules/Rules/index.js +164 -673
- package/dist/modules/Rules/types.d.ts +0 -2
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +59 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +513 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
- package/dist/modules/ScanOrderLogger/index.js +161 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
- package/dist/modules/Summary/types.d.ts +0 -2
- package/dist/modules/Summary/utils.d.ts +3 -9
- package/dist/modules/Summary/utils.js +4 -25
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -2
- package/dist/solution/BookingByStep/index.js +44 -42
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
- package/dist/solution/Checkout/index.js +0 -2
- package/dist/solution/ScanOrder/index.d.ts +90 -0
- package/dist/solution/ScanOrder/index.js +1853 -0
- package/dist/solution/ScanOrder/types.d.ts +210 -0
- package/dist/solution/ScanOrder/types.js +16 -0
- package/dist/solution/ScanOrder/utils.d.ts +93 -0
- package/dist/solution/ScanOrder/utils.js +397 -0
- 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/dist/solution/VenueBooking/index.d.ts +158 -0
- package/dist/solution/VenueBooking/index.js +2873 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +130 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/resource.js +94 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +204 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +12 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +58 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/lib/model/strategy/adapter/promotion/examples.js +192 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/lib/model/strategy/adapter/promotion/type.js +51 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
- package/lib/model/strategy/engine.d.ts +106 -0
- package/lib/model/strategy/engine.js +450 -0
- package/lib/model/strategy/index.d.ts +2 -93
- package/lib/model/strategy/index.js +6 -381
- package/lib/modules/Cart/types.d.ts +0 -2
- package/lib/modules/Cart/utils/cartProduct.js +12 -39
- package/lib/modules/Discount/types.d.ts +0 -18
- package/lib/modules/OpenData/index.d.ts +23 -0
- package/lib/modules/OpenData/index.js +116 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +58 -1
- package/lib/modules/Order/index.js +423 -1
- package/lib/modules/Order/types.d.ts +144 -12
- package/lib/modules/Order/utils.d.ts +25 -0
- package/lib/modules/Order/utils.js +229 -0
- 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/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/modules/Quotation/index.d.ts +48 -0
- package/lib/modules/Quotation/index.js +149 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/index.d.ts +5 -9
- package/lib/modules/Rules/index.js +286 -778
- package/lib/modules/Rules/types.d.ts +0 -2
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +59 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +452 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
- package/lib/modules/ScanOrderLogger/index.js +135 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
- package/lib/modules/Summary/types.d.ts +0 -2
- package/lib/modules/Summary/utils.d.ts +3 -9
- package/lib/modules/Summary/utils.js +4 -19
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -2
- package/lib/solution/BookingByStep/index.js +4 -2
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
- package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ScanOrder/index.d.ts +90 -0
- package/lib/solution/ScanOrder/index.js +1071 -0
- package/lib/solution/ScanOrder/types.d.ts +210 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +93 -0
- package/lib/solution/ScanOrder/utils.js +359 -0
- 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/lib/solution/VenueBooking/index.d.ts +158 -0
- package/lib/solution/VenueBooking/index.js +1545 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +130 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/resource.js +80 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +209 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/package.json +1 -1
|
@@ -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,16 @@ 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
1056
|
price: product.price,
|
|
1239
|
-
options:
|
|
1057
|
+
options: product.options
|
|
1240
1058
|
}), {}, {
|
|
1241
1059
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1242
1060
|
}))]);
|
|
1243
1061
|
} else {
|
|
1244
|
-
var
|
|
1245
|
-
var total = product.inPromotion ? (
|
|
1062
|
+
var _ref8, _product$_promotion$f, _product13, _product$origin_total, _product$price2;
|
|
1063
|
+
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
1064
|
var main_product_selling_price = (_product$price2 = product.price) !== null && _product$price2 !== void 0 ? _product$price2 : product.main_product_selling_price;
|
|
1247
1065
|
if ((product.discount_list || []).some(function (item) {
|
|
1248
1066
|
return item.type === 'promotion';
|
|
@@ -1255,10 +1073,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1255
1073
|
price: product.price
|
|
1256
1074
|
} : {
|
|
1257
1075
|
_id: product._id.split('___')[0] + '___' + index,
|
|
1076
|
+
origin_total: product.origin_total,
|
|
1258
1077
|
total: total,
|
|
1078
|
+
original_price: product.original_price,
|
|
1259
1079
|
price: product.price,
|
|
1260
|
-
main_product_selling_price: main_product_selling_price
|
|
1261
|
-
options: restoredOptions
|
|
1080
|
+
main_product_selling_price: main_product_selling_price
|
|
1262
1081
|
}), {}, {
|
|
1263
1082
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1264
1083
|
}))]);
|
|
@@ -1278,81 +1097,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1278
1097
|
return;
|
|
1279
1098
|
}
|
|
1280
1099
|
|
|
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;
|
|
1100
|
+
// 是否需要拆分(商品券需要拆分)
|
|
1101
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
1289
1102
|
|
|
1290
1103
|
// 需要拆分出来的数量
|
|
1291
1104
|
var totalQuantity = product.quantity || product.num || 1;
|
|
1292
1105
|
var availableGoodPassCount = applicableDiscounts.filter(function (item) {
|
|
1293
1106
|
return (item.tag || item.type) === 'good_pass';
|
|
1294
1107
|
}).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;
|
|
1108
|
+
var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
1314
1109
|
var arr = [];
|
|
1315
1110
|
|
|
1316
1111
|
// 🔥 主商品和bundle子商品分别处理
|
|
1317
1112
|
if (flatItem.type === 'main') {
|
|
1318
1113
|
// 主商品:保持原有逻辑
|
|
1319
1114
|
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
1115
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1329
1116
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1330
1117
|
quantity: totalQuantity - splitCount,
|
|
1331
|
-
_id: product._id.split('___')[0]
|
|
1332
|
-
total: _total
|
|
1118
|
+
_id: product._id.split('___')[0]
|
|
1333
1119
|
}));
|
|
1334
1120
|
}
|
|
1335
1121
|
for (var i = 0; i < splitCount; i++) {
|
|
1336
|
-
var _originProduct, _selectedDiscount$
|
|
1337
|
-
//
|
|
1338
|
-
|
|
1339
|
-
var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1122
|
+
var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
|
|
1123
|
+
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
1124
|
+
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
1340
1125
|
// 标记优惠券为已使用
|
|
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
|
-
}
|
|
1126
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
1353
1127
|
|
|
1354
1128
|
// 记录实际应用了优惠券的商品信息
|
|
1355
|
-
var appliedProducts = appliedDiscountProducts.get(
|
|
1129
|
+
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
1356
1130
|
|
|
1357
1131
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1358
1132
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
@@ -1367,492 +1141,210 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1367
1141
|
|
|
1368
1142
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
1369
1143
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1370
|
-
var isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1371
|
-
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1144
|
+
var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
|
|
1145
|
+
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
|
|
1372
1146
|
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;
|
|
1147
|
+
var targetProductTotal = void 0;
|
|
1377
1148
|
var amount = void 0;
|
|
1378
1149
|
var productDiscountDifference = void 0;
|
|
1379
|
-
var discountedOptions = product.options;
|
|
1380
|
-
var optionDiscountAmount = 0;
|
|
1381
1150
|
if (isOrderLevel && productAllocation) {
|
|
1382
1151
|
// order_level:使用预计算的分摊金额
|
|
1383
1152
|
amount = productAllocation.discountAmount;
|
|
1384
1153
|
productDiscountDifference = productAllocation.difference;
|
|
1385
|
-
|
|
1154
|
+
targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1386
1155
|
} else {
|
|
1387
1156
|
// 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;
|
|
1157
|
+
targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
|
|
1158
|
+
amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
|
|
1395
1159
|
}
|
|
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';
|
|
1160
|
+
var discountType = _selectedDiscount.tag || _selectedDiscount.type;
|
|
1161
|
+
var isGoodPass = discountType === 'good_pass';
|
|
1408
1162
|
var discountDetail = {
|
|
1409
|
-
amount:
|
|
1410
|
-
type:
|
|
1163
|
+
amount: amount,
|
|
1164
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
|
|
1411
1165
|
discount: {
|
|
1412
|
-
discount_card_type:
|
|
1413
|
-
fixed_amount:
|
|
1414
|
-
discount_calculation_mode:
|
|
1415
|
-
resource_id:
|
|
1416
|
-
title:
|
|
1166
|
+
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
1167
|
+
fixed_amount: amount,
|
|
1168
|
+
discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
|
|
1169
|
+
resource_id: _selectedDiscount.id,
|
|
1170
|
+
title: _selectedDiscount.format_title,
|
|
1417
1171
|
original_amount: product.price,
|
|
1418
1172
|
product_id: originProduct.id,
|
|
1419
|
-
percent:
|
|
1420
|
-
discount_product_id: currentSelectedDiscount.product_id
|
|
1173
|
+
percent: _selectedDiscount.par_value
|
|
1421
1174
|
},
|
|
1422
|
-
// 前端使用的num
|
|
1423
|
-
_num:
|
|
1424
|
-
|
|
1425
|
-
metadata: _objectSpread(_objectSpread({
|
|
1175
|
+
// 前端使用的num数量,为了计算优惠金额
|
|
1176
|
+
_num: isGoodPass ? 1 : product.num,
|
|
1177
|
+
metadata: _objectSpread({
|
|
1426
1178
|
num: 1,
|
|
1427
|
-
discount_rule_uncheck_flag:
|
|
1179
|
+
discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
|
|
1428
1180
|
}, productDiscountDifference !== undefined && {
|
|
1429
1181
|
product_discount_difference: productDiscountDifference
|
|
1430
|
-
}), {}, {
|
|
1431
|
-
/** 仅主商品上的优惠金额(不含 option) */
|
|
1432
|
-
mainProductDiscountAmount: mainProductDiscountAmount,
|
|
1433
|
-
optionDiscountAmount: optionDiscountAmount
|
|
1434
1182
|
})
|
|
1435
1183
|
};
|
|
1436
1184
|
appliedProducts.push(discountDetail);
|
|
1437
|
-
appliedDiscountProducts.set(
|
|
1185
|
+
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
1186
|
+
var _total = targetProductTotal;
|
|
1187
|
+
if (product.options) {
|
|
1188
|
+
_total = product.options.reduce(function (accumulator, currentValue) {
|
|
1189
|
+
var currentPrice = new Decimal(currentValue.price || 0);
|
|
1190
|
+
var currentNum = new Decimal(currentValue.num || 0);
|
|
1191
|
+
return accumulator.add(currentPrice.mul(currentNum));
|
|
1192
|
+
}, new Decimal(_total)).toNumber();
|
|
1193
|
+
}
|
|
1438
1194
|
|
|
1439
1195
|
// 记录应用了优惠券的商品
|
|
1440
1196
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1441
1197
|
if (product.isClient) {
|
|
1442
1198
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1443
1199
|
discount_list: [discountDetail],
|
|
1444
|
-
|
|
1445
|
-
price: currentIsGoodPass ? mainProductSellingPrice : product.price,
|
|
1200
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1446
1201
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1447
1202
|
origin_total: getProductOriginTotalPrice({
|
|
1448
1203
|
product: {
|
|
1449
1204
|
original_price: product.original_price
|
|
1450
1205
|
},
|
|
1451
1206
|
bundle: product.bundle,
|
|
1452
|
-
options:
|
|
1207
|
+
options: product.options
|
|
1453
1208
|
}),
|
|
1454
1209
|
variant: originProduct._productInit.variant,
|
|
1455
1210
|
original_price: new Decimal(product.price || 0).toNumber(),
|
|
1456
|
-
total:
|
|
1457
|
-
options: discountedOptions
|
|
1211
|
+
total: _total
|
|
1458
1212
|
}));
|
|
1459
1213
|
} else {
|
|
1460
1214
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1461
1215
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1462
|
-
_id: product._id.split('___')[0] +
|
|
1463
|
-
price:
|
|
1216
|
+
_id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
|
|
1217
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1464
1218
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1465
|
-
total:
|
|
1219
|
+
total: _total,
|
|
1466
1220
|
origin_total: productOriginTotal,
|
|
1467
|
-
main_product_selling_price:
|
|
1468
|
-
options: discountedOptions
|
|
1221
|
+
main_product_selling_price: targetProductTotal
|
|
1469
1222
|
}));
|
|
1470
1223
|
}
|
|
1471
1224
|
}
|
|
1472
1225
|
processedProductsMap.set(product._id, arr);
|
|
1473
1226
|
} else {
|
|
1474
|
-
// 🔥 bundle
|
|
1227
|
+
// 🔥 bundle子商品:支持拆分
|
|
1475
1228
|
var processedItems = [];
|
|
1476
1229
|
if (isNeedSplit) {
|
|
1477
|
-
//
|
|
1230
|
+
// 商品券:需要拆分数量
|
|
1478
1231
|
var discountNum = splitCount;
|
|
1479
1232
|
var normalNum = totalQuantity - discountNum;
|
|
1480
1233
|
|
|
1481
|
-
//
|
|
1234
|
+
// 生成有折扣的商品(每张商品券对应 num: 1)
|
|
1482
1235
|
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
|
-
}
|
|
1236
|
+
var _selectedDiscount2$me;
|
|
1237
|
+
var _selectedDiscount2 = applicableDiscounts[_i];
|
|
1238
|
+
usedDiscounts.set(_selectedDiscount2.id, true);
|
|
1499
1239
|
|
|
1500
1240
|
// 🔥 生成唯一的 _id
|
|
1501
1241
|
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
1242
|
var _discountDetail = {
|
|
1510
|
-
amount:
|
|
1511
|
-
type:
|
|
1243
|
+
amount: product.origin_total,
|
|
1244
|
+
type: 'good_pass',
|
|
1512
1245
|
discount: {
|
|
1513
|
-
|
|
1514
|
-
discount_calculation_mode:
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
title: currentBundleDiscount.format_title,
|
|
1246
|
+
fixed_amount: product.origin_total,
|
|
1247
|
+
discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
|
|
1248
|
+
resource_id: _selectedDiscount2.id,
|
|
1249
|
+
title: _selectedDiscount2.format_title,
|
|
1518
1250
|
original_amount: product.origin_total,
|
|
1519
|
-
product_id: product.id
|
|
1520
|
-
percent: currentBundleDiscount.par_value,
|
|
1521
|
-
discount_product_id: currentBundleDiscount.product_id
|
|
1251
|
+
product_id: product.id
|
|
1522
1252
|
},
|
|
1523
1253
|
metadata: {
|
|
1524
1254
|
// 🔥 使用拆分后的唯一 _id
|
|
1525
1255
|
custom_product_bundle_map_id: uniqueId,
|
|
1526
|
-
discount_rule_uncheck_flag:
|
|
1256
|
+
discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
|
|
1527
1257
|
num: 1
|
|
1528
1258
|
},
|
|
1529
|
-
_num: 1
|
|
1530
|
-
config: currentBundleDiscount === null || currentBundleDiscount === void 0 ? void 0 : currentBundleDiscount.config
|
|
1259
|
+
_num: 1
|
|
1531
1260
|
};
|
|
1532
1261
|
|
|
1533
1262
|
// 记录实际应用的折扣
|
|
1534
|
-
var _appliedProducts = appliedDiscountProducts.get(
|
|
1263
|
+
var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
|
|
1535
1264
|
_appliedProducts.push(_discountDetail);
|
|
1536
|
-
appliedDiscountProducts.set(
|
|
1265
|
+
appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
|
|
1537
1266
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1538
1267
|
// 🔥 使用唯一的 _id
|
|
1539
1268
|
_id: uniqueId,
|
|
1540
1269
|
num: 1,
|
|
1541
1270
|
quantity: 1,
|
|
1542
|
-
price:
|
|
1543
|
-
//
|
|
1544
|
-
total:
|
|
1271
|
+
price: 0,
|
|
1272
|
+
// 商品券价格为0
|
|
1273
|
+
total: 0,
|
|
1545
1274
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail]),
|
|
1546
1275
|
processed: true,
|
|
1547
|
-
_discountId:
|
|
1276
|
+
_discountId: _selectedDiscount2.id
|
|
1548
1277
|
}));
|
|
1549
1278
|
}
|
|
1550
1279
|
|
|
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;
|
|
1280
|
+
// 生成无折扣的商品(剩余数量)
|
|
1281
|
+
if (normalNum > 0) {
|
|
1282
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1283
|
+
// 🔥 为剩余商品生成唯一的 _id
|
|
1284
|
+
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1285
|
+
num: normalNum,
|
|
1286
|
+
quantity: normalNum,
|
|
1287
|
+
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1288
|
+
processed: true
|
|
1289
|
+
}));
|
|
1781
1290
|
}
|
|
1782
1291
|
} 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
|
-
}
|
|
1292
|
+
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
|
|
1293
|
+
// 折扣卡:不拆分数量,直接应用
|
|
1294
|
+
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1295
|
+
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
1799
1296
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1800
1297
|
|
|
1801
1298
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1802
|
-
var _isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1803
|
-
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1299
|
+
var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
|
|
1300
|
+
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
|
|
1804
1301
|
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1805
|
-
var
|
|
1302
|
+
var _targetProductTotal;
|
|
1806
1303
|
var fixedAmountPerItem;
|
|
1807
1304
|
var _productDiscountDifference;
|
|
1808
1305
|
if (_isOrderLevel && _productAllocation) {
|
|
1809
1306
|
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1810
1307
|
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1811
1308
|
_productDiscountDifference = _productAllocation.difference;
|
|
1812
|
-
|
|
1309
|
+
_targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1813
1310
|
} else {
|
|
1814
1311
|
// item_level 或其他类型:使用原有逻辑
|
|
1815
|
-
|
|
1816
|
-
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(
|
|
1312
|
+
_targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1313
|
+
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
|
|
1817
1314
|
}
|
|
1818
1315
|
|
|
1819
|
-
// 计算实际折扣金额
|
|
1820
|
-
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1821
|
-
|
|
1822
1316
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1823
1317
|
var _uniqueId = flatItem._id;
|
|
1824
1318
|
var _discountDetail2 = {
|
|
1825
|
-
amount:
|
|
1826
|
-
type:
|
|
1319
|
+
amount: fixedAmountPerItem * (product.num || 1),
|
|
1320
|
+
type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
|
|
1827
1321
|
discount: {
|
|
1828
|
-
discount_card_type:
|
|
1829
|
-
fixed_amount:
|
|
1830
|
-
discount_calculation_mode:
|
|
1831
|
-
resource_id:
|
|
1832
|
-
title:
|
|
1322
|
+
discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
|
|
1323
|
+
fixed_amount: fixedAmountPerItem,
|
|
1324
|
+
discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
|
|
1325
|
+
resource_id: _selectedDiscount3.id,
|
|
1326
|
+
title: _selectedDiscount3.format_title,
|
|
1833
1327
|
original_amount: product.original_price,
|
|
1834
1328
|
product_id: product.id,
|
|
1835
|
-
percent:
|
|
1836
|
-
discount_product_id: _currentBundleDiscount.product_id
|
|
1329
|
+
percent: _selectedDiscount3.par_value
|
|
1837
1330
|
},
|
|
1838
1331
|
metadata: _objectSpread({
|
|
1839
1332
|
// 🔥 使用唯一的 _id
|
|
1840
1333
|
custom_product_bundle_map_id: _uniqueId,
|
|
1841
|
-
discount_rule_uncheck_flag:
|
|
1334
|
+
discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
|
|
1842
1335
|
num: product.num || 1
|
|
1843
1336
|
}, _productDiscountDifference !== undefined && {
|
|
1844
1337
|
product_discount_difference: _productDiscountDifference
|
|
1845
1338
|
}),
|
|
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)
|
|
1339
|
+
_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
1340
|
};
|
|
1849
1341
|
|
|
1850
1342
|
// 记录实际应用的折扣
|
|
1851
|
-
var _appliedProducts2 = appliedDiscountProducts.get(
|
|
1343
|
+
var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
|
|
1852
1344
|
_appliedProducts2.push(_discountDetail2);
|
|
1853
|
-
appliedDiscountProducts.set(
|
|
1345
|
+
appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
|
|
1854
1346
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1855
|
-
total:
|
|
1347
|
+
total: _targetProductTotal,
|
|
1856
1348
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
1857
1349
|
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
1858
1350
|
processed: true
|
|
@@ -1871,9 +1363,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1871
1363
|
// 获取主商品处理结果
|
|
1872
1364
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
1873
1365
|
if (!mainProductArr || mainProductArr.length === 0) {
|
|
1874
|
-
//
|
|
1366
|
+
// 如果没有处理结果,返回默认商品
|
|
1875
1367
|
var getDefaultProduct = function getDefaultProduct() {
|
|
1876
|
-
var restoredOptions = restoreOptionPrices(product.options);
|
|
1877
1368
|
if (product.isClient) {
|
|
1878
1369
|
return _this3.hooks.setProduct(originProduct, {
|
|
1879
1370
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
@@ -1883,7 +1374,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1883
1374
|
original_price: product.original_price
|
|
1884
1375
|
},
|
|
1885
1376
|
bundle: product.bundle,
|
|
1886
|
-
options:
|
|
1377
|
+
options: product.options
|
|
1887
1378
|
}),
|
|
1888
1379
|
variant: originProduct._productInit.variant,
|
|
1889
1380
|
original_price: originProduct._productInit.original_price,
|
|
@@ -1892,17 +1383,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1892
1383
|
price: product.price
|
|
1893
1384
|
},
|
|
1894
1385
|
bundle: product.bundle,
|
|
1895
|
-
options:
|
|
1896
|
-
})
|
|
1897
|
-
options: restoredOptions
|
|
1386
|
+
options: product.options
|
|
1387
|
+
})
|
|
1898
1388
|
});
|
|
1899
1389
|
} else {
|
|
1900
1390
|
return _this3.hooks.setProduct(originProduct, {
|
|
1901
1391
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1902
1392
|
total: product.total,
|
|
1903
1393
|
origin_total: product.origin_total,
|
|
1904
|
-
price: product.price
|
|
1905
|
-
options: restoreOptionPrices(product.options)
|
|
1394
|
+
price: product.price
|
|
1906
1395
|
});
|
|
1907
1396
|
}
|
|
1908
1397
|
};
|
|
@@ -1978,7 +1467,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1978
1467
|
product_id: bundleItem.product_id,
|
|
1979
1468
|
price: item.price,
|
|
1980
1469
|
num: item.num,
|
|
1981
|
-
quantity: item.num,
|
|
1982
1470
|
discount_list: updatedDiscountList
|
|
1983
1471
|
}));
|
|
1984
1472
|
});
|
|
@@ -2002,7 +1490,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2002
1490
|
product_id: bundleItem.product_id,
|
|
2003
1491
|
price: item.price,
|
|
2004
1492
|
num: item.num,
|
|
2005
|
-
quantity: item.num,
|
|
2006
1493
|
discount_list: _updatedDiscountList
|
|
2007
1494
|
}));
|
|
2008
1495
|
} else {
|
|
@@ -2017,8 +1504,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2017
1504
|
|
|
2018
1505
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
|
|
2019
1506
|
var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
|
|
2020
|
-
var _discount$
|
|
2021
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1507
|
+
var _discount$metadata6, _discount$metadata7;
|
|
1508
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
|
|
2022
1509
|
// bundle的discount_list保持不变
|
|
2023
1510
|
return discount;
|
|
2024
1511
|
}
|
|
@@ -2026,7 +1513,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2026
1513
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2027
1514
|
// num: 1,
|
|
2028
1515
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2029
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1516
|
+
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
1517
|
num: 1
|
|
2031
1518
|
})
|
|
2032
1519
|
});
|
|
@@ -2071,8 +1558,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2071
1558
|
quantity: 1,
|
|
2072
1559
|
discount_list: updatedMainDiscountList,
|
|
2073
1560
|
bundle: newBundleWithDiscount,
|
|
2074
|
-
total: newTotalWithDiscount,
|
|
2075
|
-
origin_total: newOriginTotalWithDiscount
|
|
1561
|
+
total: new Decimal(newTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber(),
|
|
1562
|
+
origin_total: new Decimal(newOriginTotalWithDiscount).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber()
|
|
2076
1563
|
})));
|
|
2077
1564
|
|
|
2078
1565
|
// 第二个:包含原始bundle (qty=原quantity-1)
|
|
@@ -2091,8 +1578,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2091
1578
|
|
|
2092
1579
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
|
|
2093
1580
|
var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
|
|
2094
|
-
var _discount$
|
|
2095
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1581
|
+
var _discount$metadata8, _discount$metadata9;
|
|
1582
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
|
|
2096
1583
|
// bundle的discount_list保持不变
|
|
2097
1584
|
return discount;
|
|
2098
1585
|
}
|
|
@@ -2100,7 +1587,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2100
1587
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2101
1588
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2102
1589
|
num: mainProductQuantity - 1,
|
|
2103
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1590
|
+
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
1591
|
})
|
|
2105
1592
|
// num: mainProductQuantity - 1,
|
|
2106
1593
|
});
|
|
@@ -2167,11 +1654,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2167
1654
|
processedBundleItems.forEach(function (item) {
|
|
2168
1655
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
2169
1656
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
2170
|
-
var _discount$
|
|
1657
|
+
var _discount$metadata10;
|
|
2171
1658
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2172
1659
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2173
1660
|
num: item.num,
|
|
2174
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1661
|
+
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
1662
|
})
|
|
2176
1663
|
// num: item.num, // 使用拆分后的 num
|
|
2177
1664
|
});
|
|
@@ -2181,9 +1668,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2181
1668
|
product_id: bundleItem.product_id,
|
|
2182
1669
|
price: item.price,
|
|
2183
1670
|
num: item.num,
|
|
2184
|
-
|
|
2185
|
-
discount_list: updatedDiscountList,
|
|
2186
|
-
bundle_selling_price: bundleItem.bundle_selling_price !== undefined ? item.price : undefined
|
|
1671
|
+
discount_list: updatedDiscountList
|
|
2187
1672
|
}));
|
|
2188
1673
|
});
|
|
2189
1674
|
}
|
|
@@ -2222,8 +1707,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2222
1707
|
// 累加bundle的价格(只累加一次)
|
|
2223
1708
|
if (newBundle.length > 0) {
|
|
2224
1709
|
newBundle.forEach(function (item) {
|
|
2225
|
-
var _item$discount_list3;
|
|
2226
1710
|
newTotal += Number(item.price) * Number(item.num);
|
|
1711
|
+
});
|
|
1712
|
+
|
|
1713
|
+
// 计算原始总价(不考虑折扣)
|
|
1714
|
+
newBundle.forEach(function (item) {
|
|
1715
|
+
var _item$discount_list3;
|
|
2227
1716
|
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
1717
|
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
2229
1718
|
});
|
|
@@ -2238,6 +1727,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2238
1727
|
return accumulator.add(currentPrice.mul(currentNum));
|
|
2239
1728
|
}, new Decimal(newTotal)).toNumber();
|
|
2240
1729
|
}
|
|
1730
|
+
newTotal = new Decimal(newTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
1731
|
+
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2241
1732
|
|
|
2242
1733
|
// 生成最终的主商品
|
|
2243
1734
|
result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
@@ -2345,14 +1836,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2345
1836
|
var ruleType = usageRules.type;
|
|
2346
1837
|
// 套餐适用范围配置
|
|
2347
1838
|
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 =
|
|
1839
|
+
var _ref9 = packageScope || {},
|
|
1840
|
+
scopeType = _ref9.type,
|
|
1841
|
+
_ref9$exclude_bundle_ = _ref9.exclude_bundle_product_ids,
|
|
1842
|
+
exclude_bundle_product_ids = _ref9$exclude_bundle_ === void 0 ? [] : _ref9$exclude_bundle_,
|
|
1843
|
+
_ref9$include_bundle_ = _ref9.include_bundle_product_ids,
|
|
1844
|
+
include_bundle_product_ids = _ref9$include_bundle_ === void 0 ? [] : _ref9$include_bundle_,
|
|
1845
|
+
_ref9$filter = _ref9.filter,
|
|
1846
|
+
filter = _ref9$filter === void 0 ? 0 : _ref9$filter;
|
|
2356
1847
|
var isMainProduct = flatItem.type === 'main'; // 单独购买
|
|
2357
1848
|
var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
|
|
2358
1849
|
|
|
@@ -2367,12 +1858,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2367
1858
|
return true; // 单独购买时可用
|
|
2368
1859
|
}
|
|
2369
1860
|
if (isBundleItem) {
|
|
2370
|
-
var _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu, _flatItem$
|
|
1861
|
+
var _flatItem$bundleItem9, _flatItem$bundleItem10, _flatItem$originProdu, _flatItem$parentProdu10;
|
|
2371
1862
|
// 套餐中购买时,判断是否为原价
|
|
2372
1863
|
var priceType = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type;
|
|
2373
1864
|
var priceTypeExt = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type_ext;
|
|
2374
1865
|
// 主商品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$
|
|
1866
|
+
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
1867
|
// original_price 对应:
|
|
2377
1868
|
// 1. price_type: "markup" && price_type_ext: "product_price"
|
|
2378
1869
|
// markup_price 对应:
|