@pisell/pisellos 2.1.64 → 2.1.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/modules/Cart/types.d.ts +0 -2
- package/dist/modules/Cart/utils/cartProduct.js +21 -15
- package/dist/modules/Discount/index.js +2 -2
- package/dist/modules/Discount/types.d.ts +9 -15
- package/dist/modules/Payment/index.d.ts +1 -2
- package/dist/modules/Payment/index.js +7 -10
- package/dist/modules/Payment/utils.js +0 -3
- package/dist/modules/Payment/walletpass.d.ts +0 -23
- package/dist/modules/Payment/walletpass.js +95 -191
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +3 -8
- package/dist/modules/Rules/index.js +408 -240
- package/dist/modules/Rules/types.d.ts +0 -1
- package/dist/modules/Summary/types.d.ts +0 -2
- package/dist/modules/Summary/utils.d.ts +5 -6
- package/dist/modules/Summary/utils.js +34 -20
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -2
- package/dist/solution/BookingByStep/index.js +2 -1
- package/dist/solution/Checkout/index.js +0 -2
- package/dist/solution/ShopDiscount/index.d.ts +0 -1
- package/dist/solution/ShopDiscount/index.js +5 -14
- package/dist/solution/ShopDiscount/types.d.ts +0 -1
- package/dist/solution/ShopDiscount/utils.d.ts +24 -0
- package/dist/solution/ShopDiscount/utils.js +145 -26
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/modules/Cart/types.d.ts +0 -2
- package/lib/modules/Cart/utils/cartProduct.js +22 -15
- package/lib/modules/Discount/index.js +2 -2
- package/lib/modules/Discount/types.d.ts +9 -15
- package/lib/modules/Payment/index.d.ts +1 -2
- package/lib/modules/Payment/index.js +0 -1
- package/lib/modules/Payment/utils.js +0 -3
- package/lib/modules/Payment/walletpass.d.ts +0 -23
- package/lib/modules/Payment/walletpass.js +17 -94
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +3 -8
- package/lib/modules/Rules/index.js +441 -399
- package/lib/modules/Rules/types.d.ts +0 -1
- package/lib/modules/Summary/types.d.ts +0 -2
- package/lib/modules/Summary/utils.d.ts +5 -6
- package/lib/modules/Summary/utils.js +27 -18
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -2
- package/lib/solution/BookingByStep/index.js +1 -1
- package/lib/solution/BookingTicket/index.js +6 -0
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +6 -12
- package/lib/solution/ShopDiscount/types.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.d.ts +24 -0
- package/lib/solution/ShopDiscount/utils.js +93 -10
- package/package.json +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.js +0 -1
- package/dist/model/strategy/adapter/index.d.ts +0 -3
- package/dist/model/strategy/adapter/index.js +0 -4
- package/dist/model/strategy/adapter/type.d.ts +0 -28
- package/dist/model/strategy/adapter/type.js +0 -1
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -497
- package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
- package/dist/model/strategy/adapter/walletPass/example.js +0 -258
- package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
- package/dist/model/strategy/adapter/walletPass/index.js +0 -182
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
- package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -163
- package/dist/model/strategy/adapter/walletPass/type.js +0 -1
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
- package/dist/model/strategy/index.d.ts +0 -94
- package/dist/model/strategy/index.js +0 -551
- package/dist/model/strategy/strategy-example.d.ts +0 -5
- package/dist/model/strategy/strategy-example.js +0 -331
- package/dist/model/strategy/type.d.ts +0 -228
- package/dist/model/strategy/type.js +0 -94
- package/lib/model/index.d.ts +0 -1
- package/lib/model/index.js +0 -23
- package/lib/model/strategy/adapter/index.d.ts +0 -3
- package/lib/model/strategy/adapter/index.js +0 -45
- package/lib/model/strategy/adapter/type.d.ts +0 -28
- package/lib/model/strategy/adapter/type.js +0 -17
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -421
- package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
- package/lib/model/strategy/adapter/walletPass/example.js +0 -207
- package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
- package/lib/model/strategy/adapter/walletPass/index.js +0 -142
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
- package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -163
- package/lib/model/strategy/adapter/walletPass/type.js +0 -17
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
- package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
- package/lib/model/strategy/index.d.ts +0 -94
- package/lib/model/strategy/index.js +0 -413
- package/lib/model/strategy/strategy-example.d.ts +0 -5
- package/lib/model/strategy/strategy-example.js +0 -318
- package/lib/model/strategy/type.d.ts +0 -228
- package/lib/model/strategy/type.js +0 -44
|
@@ -24,11 +24,12 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
24
24
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
25
25
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
26
|
import { BaseModule } from "../BaseModule";
|
|
27
|
-
import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime } from "../../solution/ShopDiscount/utils";
|
|
27
|
+
import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, isOrderLevelFixedAmountDiscount, calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
|
|
28
28
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
29
29
|
import Decimal from 'decimal.js';
|
|
30
30
|
import { isBoolean } from 'lodash-es';
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
|
+
|
|
32
33
|
// 临时变量
|
|
33
34
|
var flatItem;
|
|
34
35
|
export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
@@ -41,8 +42,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
41
42
|
_defineProperty(_assertThisInitialized(_this), "defaultName", 'rules');
|
|
42
43
|
_defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
|
|
43
44
|
_defineProperty(_assertThisInitialized(_this), "store", void 0);
|
|
44
|
-
_defineProperty(_assertThisInitialized(_this), "window", void 0);
|
|
45
|
-
// WindowPlugin 实例
|
|
46
45
|
_defineProperty(_assertThisInitialized(_this), "hooks", void 0);
|
|
47
46
|
_this.hooks = {};
|
|
48
47
|
return _this;
|
|
@@ -57,8 +56,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
57
56
|
this.core = core;
|
|
58
57
|
this.hooks = options === null || options === void 0 ? void 0 : options.hooks;
|
|
59
58
|
this.store = options === null || options === void 0 ? void 0 : options.store;
|
|
60
|
-
|
|
61
|
-
case 4:
|
|
59
|
+
case 3:
|
|
62
60
|
case "end":
|
|
63
61
|
return _context.stop();
|
|
64
62
|
}
|
|
@@ -95,12 +93,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
95
93
|
value: function getRulesList() {
|
|
96
94
|
return this.store.rulesList;
|
|
97
95
|
}
|
|
98
|
-
}, {
|
|
99
|
-
key: "getWalletPassEvaluator",
|
|
100
|
-
value: function getWalletPassEvaluator() {
|
|
101
|
-
var _this$window$getWalle, _this$window;
|
|
102
|
-
return (_this$window$getWalle = (_this$window = this.window).getWalletPassEvaluator) === null || _this$window$getWalle === void 0 ? void 0 : _this$window$getWalle.call(_this$window);
|
|
103
|
-
}
|
|
104
96
|
|
|
105
97
|
// 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
|
|
106
98
|
}, {
|
|
@@ -130,7 +122,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
130
122
|
newDiscountList = _ref.newDiscountList,
|
|
131
123
|
productList = _ref.productList,
|
|
132
124
|
holders = _ref.holders,
|
|
133
|
-
orderTotalAmount = _ref.orderTotalAmount,
|
|
134
125
|
isFormSubject = _ref.isFormSubject;
|
|
135
126
|
// 首先检查是否有新的优惠券可应用
|
|
136
127
|
if (!newDiscountList || newDiscountList.length === 0) {
|
|
@@ -163,7 +154,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
163
154
|
discountList: mergedDiscountList,
|
|
164
155
|
productList: _toConsumableArray(productList),
|
|
165
156
|
holders: holders,
|
|
166
|
-
orderTotalAmount: orderTotalAmount,
|
|
167
157
|
isFormSubject: isFormSubject
|
|
168
158
|
}, {
|
|
169
159
|
scan: true
|
|
@@ -208,7 +198,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
208
198
|
var discountList = _ref2.discountList,
|
|
209
199
|
productList = _ref2.productList,
|
|
210
200
|
holders = _ref2.holders,
|
|
211
|
-
orderTotalAmount = _ref2.orderTotalAmount,
|
|
212
201
|
isFormSubject = _ref2.isFormSubject;
|
|
213
202
|
// 识别出来是不是在编辑的界面里又新增了商品
|
|
214
203
|
// 这种情况下,如果有可用的优惠券,也会自动勾选上
|
|
@@ -227,6 +216,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
227
216
|
}
|
|
228
217
|
});
|
|
229
218
|
|
|
219
|
+
// 🔥 检查 editModeDiscount 中是否有订单级别的折扣,如果有则禁用 addModeDiscount 中相同 product_id 的折扣卡
|
|
220
|
+
var editModeOrderLevelProductIds = new Set();
|
|
221
|
+
editModeDiscount.forEach(function (discount) {
|
|
222
|
+
var _discount$discount2;
|
|
223
|
+
if (((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.discount_calculation_mode) === 'order_level') {
|
|
224
|
+
var _discount$discount3;
|
|
225
|
+
editModeOrderLevelProductIds.add(discount === null || discount === void 0 || (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_product_id);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// 如果存在订单级别的编辑模式折扣,禁用 addModeDiscount 中相同 product_id 的折扣卡
|
|
230
|
+
if (editModeOrderLevelProductIds.size > 0) {
|
|
231
|
+
addModeDiscount.forEach(function (discount) {
|
|
232
|
+
if (editModeOrderLevelProductIds.has(discount.product_id)) {
|
|
233
|
+
discount.isDisabled = true;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
230
238
|
// 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
|
|
231
239
|
var filteredDiscountList = addModeDiscount.filter(function (discount) {
|
|
232
240
|
return !discount.isManualSelect;
|
|
@@ -282,26 +290,69 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
282
290
|
};
|
|
283
291
|
|
|
284
292
|
// 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
|
|
285
|
-
//
|
|
286
|
-
//
|
|
287
|
-
//
|
|
288
|
-
//
|
|
289
|
-
//
|
|
290
|
-
//
|
|
293
|
+
// 新的优先级排序规则(从高到低):
|
|
294
|
+
// 1. 带有Holder的商品券(metadata?.holder?.type === 'custom' && tag === 'good_pass')
|
|
295
|
+
// 2. 带有Holder的商品级折扣卡(metadata?.holder?.type === 'custom' && tag === 'product_discount_card' && discount_calculation_mode !== 'order_level')
|
|
296
|
+
// 3. 带有Holder的订单级折扣卡(metadata?.holder?.type === 'custom' && tag === 'product_discount_card' && discount_calculation_mode === 'order_level')
|
|
297
|
+
// 4. Customer商品券(metadata?.holder?.type !== 'custom' && tag === 'good_pass')
|
|
298
|
+
// 5. Customer商品级折扣卡(metadata?.holder?.type !== 'custom' && tag === 'product_discount_card' && discount_calculation_mode !== 'order_level')
|
|
299
|
+
// 6. Customer订单级固定金额折扣(metadata?.holder?.type !== 'custom' && tag === 'product_discount_card' && discount_calculation_mode === 'order_level')
|
|
300
|
+
// 同一优先级内部:固定金额优先于百分比,金额/折扣力度越大越优先,最后按过期时间排序
|
|
291
301
|
var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
302
|
+
// 辅助函数:判断是否是带有Holder的优惠券
|
|
303
|
+
var isHolderDiscount = function isHolderDiscount(discount) {
|
|
304
|
+
var _discount$metadata;
|
|
305
|
+
return ((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 || (_discount$metadata = _discount$metadata.holder) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.type) === 'custom';
|
|
306
|
+
};
|
|
295
307
|
|
|
296
|
-
//
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
var
|
|
304
|
-
|
|
308
|
+
// 辅助函数:判断是否是商品券
|
|
309
|
+
var isGoodPass = function isGoodPass(discount) {
|
|
310
|
+
return discount.tag === 'good_pass';
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// 辅助函数:判断是否是订单级折扣卡
|
|
314
|
+
var isOrderLevelDiscount = function isOrderLevelDiscount(discount) {
|
|
315
|
+
var _discount$metadata2;
|
|
316
|
+
return discount.tag === 'product_discount_card' && ((_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.discount_calculation_mode) === 'order_level';
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// 辅助函数:判断是否是商品级折扣卡
|
|
320
|
+
var isItemLevelDiscount = function isItemLevelDiscount(discount) {
|
|
321
|
+
var _discount$metadata3;
|
|
322
|
+
return discount.tag === 'product_discount_card' && ((_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.discount_calculation_mode) !== 'order_level';
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// 辅助函数:获取优先级(数字越小优先级越高)
|
|
326
|
+
var getPriority = function getPriority(discount) {
|
|
327
|
+
var isHolder = isHolderDiscount(discount);
|
|
328
|
+
if (isHolder) {
|
|
329
|
+
if (isGoodPass(discount)) return 1; // 带有Holder的商品券
|
|
330
|
+
if (isItemLevelDiscount(discount)) return 2; // 带有Holder的商品级折扣卡
|
|
331
|
+
if (isOrderLevelDiscount(discount)) return 3; // 带有Holder的订单级折扣卡
|
|
332
|
+
} else {
|
|
333
|
+
if (isGoodPass(discount)) return 4; // Customer商品券
|
|
334
|
+
if (isItemLevelDiscount(discount)) return 5; // Customer商品级折扣卡
|
|
335
|
+
if (isOrderLevelDiscount(discount)) return 6; // Customer订单级固定金额折扣
|
|
336
|
+
}
|
|
337
|
+
return 7; // 其他情况
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// 辅助函数:按过期时间比较
|
|
341
|
+
function compareByExpireTime(itemA, itemB) {
|
|
342
|
+
if (itemA.expire_time && itemB.expire_time) {
|
|
343
|
+
var timeA = new Date(itemA.expire_time).getTime();
|
|
344
|
+
var timeB = new Date(itemB.expire_time).getTime();
|
|
345
|
+
return timeA - timeB;
|
|
346
|
+
}
|
|
347
|
+
// 有过期时间的优先级高于永久的
|
|
348
|
+
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 辅助函数:同类型折扣卡内部排序(固定金额优先于百分比,金额/折扣力度排序)
|
|
352
|
+
function compareDiscountCardValue(itemA, itemB) {
|
|
353
|
+
var _itemA$metadata, _itemB$metadata;
|
|
354
|
+
var typeA = ((_itemA$metadata = itemA.metadata) === null || _itemA$metadata === void 0 ? void 0 : _itemA$metadata.discount_card_type) || 'percent';
|
|
355
|
+
var typeB = ((_itemB$metadata = itemB.metadata) === null || _itemB$metadata === void 0 ? void 0 : _itemB$metadata.discount_card_type) || 'percent';
|
|
305
356
|
|
|
306
357
|
// 1. 固定金额优先于百分比
|
|
307
358
|
if (typeA === 'fixed_amount' && typeB === 'percent') return -1;
|
|
@@ -309,37 +360,46 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
309
360
|
|
|
310
361
|
// 2. 都是固定金额时,金额越大越优先
|
|
311
362
|
if (typeA === 'fixed_amount' && typeB === 'fixed_amount') {
|
|
312
|
-
if (
|
|
313
|
-
var valueA = new Decimal(
|
|
314
|
-
var valueB = new Decimal(
|
|
363
|
+
if (itemA.par_value !== itemB.par_value) {
|
|
364
|
+
var valueA = new Decimal(itemA.par_value || 0);
|
|
365
|
+
var valueB = new Decimal(itemB.par_value || 0);
|
|
315
366
|
return valueB.minus(valueA).toNumber(); // 金额大的在前
|
|
316
367
|
}
|
|
317
368
|
}
|
|
318
369
|
|
|
319
370
|
// 3. 都是百分比时,折扣越大越优先(par_value越大越优先)
|
|
320
371
|
if (typeA === 'percent' && typeB === 'percent') {
|
|
321
|
-
if (
|
|
322
|
-
var _valueA = new Decimal(100).minus(
|
|
323
|
-
var _valueB = new Decimal(100).minus(
|
|
372
|
+
if (itemA.par_value !== itemB.par_value) {
|
|
373
|
+
var _valueA = new Decimal(100).minus(itemA.par_value || 0);
|
|
374
|
+
var _valueB = new Decimal(100).minus(itemB.par_value || 0);
|
|
324
375
|
return _valueA.minus(_valueB).toNumber(); // 折扣大的在前
|
|
325
376
|
}
|
|
326
377
|
}
|
|
378
|
+
return 0;
|
|
379
|
+
}
|
|
327
380
|
|
|
328
|
-
|
|
381
|
+
// 1. 先按优先级排序
|
|
382
|
+
var priorityA = getPriority(a);
|
|
383
|
+
var priorityB = getPriority(b);
|
|
384
|
+
if (priorityA !== priorityB) {
|
|
385
|
+
return priorityA - priorityB;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// 2. 同一优先级内部排序
|
|
389
|
+
// 如果是商品券(优先级1或4),按过期时间排序
|
|
390
|
+
if (isGoodPass(a) && isGoodPass(b)) {
|
|
391
|
+
return compareByExpireTime(a, b);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// 如果是折扣卡(优先级2、3、5、6),按折扣力度排序,然后按过期时间
|
|
395
|
+
if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
|
|
396
|
+
var valueCompare = compareDiscountCardValue(a, b);
|
|
397
|
+
if (valueCompare !== 0) return valueCompare;
|
|
329
398
|
return compareByExpireTime(a, b);
|
|
330
399
|
}
|
|
331
400
|
|
|
332
401
|
// 3. 其他情况按照过期时间排序
|
|
333
402
|
return compareByExpireTime(a, b);
|
|
334
|
-
function compareByExpireTime(itemA, itemB) {
|
|
335
|
-
if (itemA.expire_time && itemB.expire_time) {
|
|
336
|
-
var timeA = new Date(itemA.expire_time).getTime();
|
|
337
|
-
var timeB = new Date(itemB.expire_time).getTime();
|
|
338
|
-
return timeA - timeB;
|
|
339
|
-
}
|
|
340
|
-
// 有过期时间的优先级高于永久的
|
|
341
|
-
return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
|
|
342
|
-
}
|
|
343
403
|
});
|
|
344
404
|
|
|
345
405
|
// const newProductList = [];
|
|
@@ -385,57 +445,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
385
445
|
return priceB.minus(priceA).toNumber();
|
|
386
446
|
});
|
|
387
447
|
|
|
388
|
-
// 🔥 为每个折扣卡/商品券执行策略检查并附加config
|
|
389
|
-
var evaluator = this.getWalletPassEvaluator();
|
|
390
|
-
if (evaluator) {
|
|
391
|
-
addModeDiscount.forEach(function (discount) {
|
|
392
|
-
var discountType = discount.tag || discount.type;
|
|
393
|
-
// 只对 good_pass 和 discount_card 类型执行策略检查
|
|
394
|
-
if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
|
|
395
|
-
var _discount$limited_rel, _discount$limited_rel2;
|
|
396
|
-
// 转换 discount 为 Voucher 格式
|
|
397
|
-
var voucher = {
|
|
398
|
-
id: discount.id,
|
|
399
|
-
amount: Number(discount.par_value || 0),
|
|
400
|
-
balance: Number(discount.balance || 0),
|
|
401
|
-
type: discountType,
|
|
402
|
-
product_id: discount.product_id,
|
|
403
|
-
unified_available_status: 1,
|
|
404
|
-
available_product_type: (_discount$limited_rel = discount.limited_relation_product_data) === null || _discount$limited_rel === void 0 ? void 0 : _discount$limited_rel.type,
|
|
405
|
-
available_product_ids: (_discount$limited_rel2 = discount.limited_relation_product_data) === null || _discount$limited_rel2 === void 0 ? void 0 : _discount$limited_rel2.product_ids
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
// 转换 sortedFlattenedList 为 Product 格式
|
|
409
|
-
var productsForEvaluate = sortedFlattenedList.map(function (item) {
|
|
410
|
-
return {
|
|
411
|
-
product_id: item.id,
|
|
412
|
-
price: item.price || 0,
|
|
413
|
-
quantity: item.quantity || item.num || 1,
|
|
414
|
-
selling_price: item.price || 0
|
|
415
|
-
};
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
// 调用策略检查
|
|
419
|
-
var result = evaluator.checkVoucherAvailability({
|
|
420
|
-
orderTotalAmount: orderTotalAmount,
|
|
421
|
-
products: productsForEvaluate,
|
|
422
|
-
vouchers: [voucher]
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
// 将 config 附加到 discount 对象
|
|
426
|
-
if (result.isAvailable) {
|
|
427
|
-
discount.config = _objectSpread(_objectSpread({}, result.config), {}, {
|
|
428
|
-
isAvailable: true
|
|
429
|
-
});
|
|
430
|
-
} else {
|
|
431
|
-
discount.config = {
|
|
432
|
-
isAvailable: false
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
|
|
439
448
|
/**
|
|
440
449
|
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
441
450
|
const sortedProductList = [...productList].sort((a, b) => {
|
|
@@ -456,9 +465,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
456
465
|
// 标记已使用的优惠券
|
|
457
466
|
var usedDiscounts = new Map();
|
|
458
467
|
|
|
459
|
-
// 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
|
|
460
|
-
var usedProductIdCounts = new Map();
|
|
461
|
-
|
|
462
468
|
// 记录每个优惠券适用的商品ID
|
|
463
469
|
var discountApplicability = new Map();
|
|
464
470
|
|
|
@@ -471,6 +477,187 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
471
477
|
discountApplicableProducts.set(discount.id, []);
|
|
472
478
|
});
|
|
473
479
|
|
|
480
|
+
// 预处理 order_level 固定金额折扣卡的分摊信息
|
|
481
|
+
// Map<discountId, Map<productId, { discountAmount, difference }>>
|
|
482
|
+
var orderLevelDiscountAllocations = new Map();
|
|
483
|
+
|
|
484
|
+
// 第一步:收集所有被勾选的 order_level 折扣卡及其适用商品
|
|
485
|
+
// Map<discountId, Set<flatItemId>> - 记录每个折扣卡适用的商品
|
|
486
|
+
var orderLevelDiscountApplicableItems = new Map();
|
|
487
|
+
// Map<flatItemId, Set<discountId>> - 记录每个商品可以被哪些折扣卡使用
|
|
488
|
+
var itemApplicableDiscounts = new Map();
|
|
489
|
+
|
|
490
|
+
// 辅助函数:检查商品是否对某个折扣卡可用
|
|
491
|
+
var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
|
|
492
|
+
var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
|
|
493
|
+
var product;
|
|
494
|
+
if (flatItem.type === 'main') {
|
|
495
|
+
product = flatItem.product;
|
|
496
|
+
} else {
|
|
497
|
+
var _flatItem$parentProdu;
|
|
498
|
+
product = {
|
|
499
|
+
_id: flatItem._id,
|
|
500
|
+
id: flatItem.id,
|
|
501
|
+
price: flatItem.price,
|
|
502
|
+
quantity: flatItem.quantity,
|
|
503
|
+
num: flatItem.num,
|
|
504
|
+
booking_id: flatItem.booking_id,
|
|
505
|
+
discount_list: flatItem.discount_list || [],
|
|
506
|
+
startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// 编辑的商品使用了优惠券不可用
|
|
511
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
|
|
512
|
+
return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
|
|
513
|
+
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
|
|
514
|
+
return d.id;
|
|
515
|
+
}));
|
|
516
|
+
if (!isAvailableProduct) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// vouchersApplicable 为 false 的商品不参与订单级别折扣均摊
|
|
521
|
+
if (isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// 商品价格为0时不可用
|
|
526
|
+
if (Number(product.price) <= 0 || !product.price) {
|
|
527
|
+
return false;
|
|
528
|
+
}
|
|
529
|
+
var limitedData = discount.limited_relation_product_data;
|
|
530
|
+
|
|
531
|
+
// 时间限制检查
|
|
532
|
+
var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
533
|
+
if (!timeLimit) {
|
|
534
|
+
return false;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// 判断商品是否适用
|
|
538
|
+
var isLimitedProduct = false;
|
|
539
|
+
if (limitedData.type === 'product_all') {
|
|
540
|
+
var _limitedData$exclude_;
|
|
541
|
+
// 全品类,但需要检查是否被排除
|
|
542
|
+
if (limitedData.filter === 1 && (_limitedData$exclude_ = limitedData.exclude_product_ids) !== null && _limitedData$exclude_ !== void 0 && _limitedData$exclude_.includes(product.id)) {
|
|
543
|
+
isLimitedProduct = false;
|
|
544
|
+
} else {
|
|
545
|
+
isLimitedProduct = true;
|
|
546
|
+
}
|
|
547
|
+
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
548
|
+
isLimitedProduct = true;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// 套餐规则检查
|
|
552
|
+
var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
|
|
553
|
+
return isLimitedProduct && isBundleAvailable;
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// 收集所有被勾选的 order_level 折扣卡及其适用商品
|
|
557
|
+
var selectedOrderLevelDiscounts = sortedDiscountList.filter(function (discount) {
|
|
558
|
+
return isOrderLevelFixedAmountDiscount(discount) && discount.isSelected !== false;
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
// 遍历所有被勾选的 order_level 折扣卡,建立双向映射
|
|
562
|
+
selectedOrderLevelDiscounts.forEach(function (discount) {
|
|
563
|
+
var applicableItemIds = new Set();
|
|
564
|
+
sortedFlattenedList.forEach(function (flatItem) {
|
|
565
|
+
if (checkItemApplicableForDiscount(flatItem, discount)) {
|
|
566
|
+
applicableItemIds.add(flatItem._id);
|
|
567
|
+
|
|
568
|
+
// 记录商品可以被哪些折扣卡使用
|
|
569
|
+
if (!itemApplicableDiscounts.has(flatItem._id)) {
|
|
570
|
+
itemApplicableDiscounts.set(flatItem._id, new Set());
|
|
571
|
+
}
|
|
572
|
+
itemApplicableDiscounts.get(flatItem._id).add(discount.id);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
orderLevelDiscountApplicableItems.set(discount.id, applicableItemIds);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
// 专属折扣卡定义:限定了特定商品(product_ids),而不是全品类(product_all)的折扣卡
|
|
579
|
+
// 如果专属折扣卡被勾选,它适用的商品会被占用,其他折扣卡均摊时应排除这些商品
|
|
580
|
+
// Map<flatItemId, discountId> - 记录被占用的商品及其对应的折扣卡
|
|
581
|
+
var occupiedItems = new Map();
|
|
582
|
+
|
|
583
|
+
// 按排序顺序遍历折扣卡,判断哪些是专属折扣卡
|
|
584
|
+
selectedOrderLevelDiscounts.forEach(function (discount) {
|
|
585
|
+
var limitedData = discount.limited_relation_product_data;
|
|
586
|
+
|
|
587
|
+
// 判断是否是专属折扣卡(只能用于特定商品,而不是全品类)
|
|
588
|
+
var isExclusiveDiscount = limitedData.type !== 'product_all';
|
|
589
|
+
if (isExclusiveDiscount) {
|
|
590
|
+
// 专属折扣卡:它适用的所有商品都会被它占用
|
|
591
|
+
var applicableItems = orderLevelDiscountApplicableItems.get(discount.id);
|
|
592
|
+
if (applicableItems) {
|
|
593
|
+
applicableItems.forEach(function (itemId) {
|
|
594
|
+
// 如果商品还没被占用,则标记为被当前折扣卡占用
|
|
595
|
+
if (!occupiedItems.has(itemId)) {
|
|
596
|
+
occupiedItems.set(itemId, discount.id);
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
console.log('occupiedItems', occupiedItems, 'orderLevelDiscountApplicableItems', orderLevelDiscountApplicableItems);
|
|
603
|
+
|
|
604
|
+
// 🔥 第三步:识别 order_level 折扣卡并预计算分摊(排除被其他专属折扣卡占用的商品)
|
|
605
|
+
sortedDiscountList.forEach(function (discount) {
|
|
606
|
+
if (!isOrderLevelFixedAmountDiscount(discount)) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
611
|
+
var applicableProducts = [];
|
|
612
|
+
sortedFlattenedList.forEach(function (flatItem) {
|
|
613
|
+
var _flatItem$parentProdu2;
|
|
614
|
+
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
615
|
+
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
616
|
+
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
617
|
+
// 该商品被其他专属折扣卡占用,跳过
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (!checkItemApplicableForDiscount(flatItem, discount)) {
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
var product;
|
|
624
|
+
if (flatItem.type === 'main') {
|
|
625
|
+
product = flatItem.product;
|
|
626
|
+
} else {
|
|
627
|
+
product = {
|
|
628
|
+
_id: flatItem._id,
|
|
629
|
+
id: flatItem.id,
|
|
630
|
+
price: flatItem.price,
|
|
631
|
+
quantity: flatItem.quantity,
|
|
632
|
+
num: flatItem.num
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
|
|
637
|
+
var quantity = flatItem.type === 'main' ? product.quantity || 1 : (product.num || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.quantity) || 1);
|
|
638
|
+
|
|
639
|
+
// 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
640
|
+
var productData = {
|
|
641
|
+
productId: flatItem._id,
|
|
642
|
+
amount: Number(product.price || 0),
|
|
643
|
+
quantity: quantity
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// 子商品需要传递主商品数量
|
|
647
|
+
if (flatItem.type === 'bundle') {
|
|
648
|
+
var _flatItem$parentProdu3;
|
|
649
|
+
productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
|
|
650
|
+
}
|
|
651
|
+
applicableProducts.push(productData);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// 计算分摊
|
|
655
|
+
if (applicableProducts.length > 0) {
|
|
656
|
+
var allocation = calculateOrderLevelDiscountAllocation(discount, applicableProducts);
|
|
657
|
+
orderLevelDiscountAllocations.set(discount.id, allocation);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
474
661
|
// 处理后的商品列表(按排序后的顺序处理,记录优惠信息)
|
|
475
662
|
var processedProductsMap = new Map();
|
|
476
663
|
|
|
@@ -486,7 +673,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
486
673
|
product = flatItem.product;
|
|
487
674
|
originProduct = flatItem.originProduct;
|
|
488
675
|
} else {
|
|
489
|
-
var _flatItem$
|
|
676
|
+
var _flatItem$parentProdu4;
|
|
490
677
|
// bundle子商品:构造虚拟商品对象
|
|
491
678
|
product = {
|
|
492
679
|
_id: flatItem._id,
|
|
@@ -498,12 +685,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
498
685
|
origin_total: flatItem.origin_total,
|
|
499
686
|
booking_id: flatItem.booking_id,
|
|
500
687
|
discount_list: flatItem.discount_list || [],
|
|
501
|
-
startDate: (_flatItem$
|
|
688
|
+
startDate: (_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.startDate
|
|
502
689
|
};
|
|
503
690
|
originProduct = flatItem.originProduct;
|
|
504
691
|
}
|
|
505
692
|
addModeDiscount.forEach(function (discount) {
|
|
506
|
-
var
|
|
693
|
+
var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4;
|
|
507
694
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
508
695
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
509
696
|
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;
|
|
@@ -512,21 +699,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
512
699
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
513
700
|
}, holders);
|
|
514
701
|
var timeLimit = true;
|
|
515
|
-
timeLimit = !!filterDiscountListByBookingTime([discount], (((
|
|
702
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
516
703
|
// 是符合折扣的商品
|
|
517
|
-
var isLimitedProduct = (limitedData.type === 'product_all'
|
|
704
|
+
var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
518
705
|
|
|
519
706
|
// 编辑的商品 使用了优惠券不可用
|
|
520
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
707
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
|
|
521
708
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
522
|
-
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && flatItem !== null && flatItem !== void 0 && (_flatItem$
|
|
709
|
+
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
|
|
710
|
+
return discount.id;
|
|
711
|
+
}));
|
|
523
712
|
|
|
524
713
|
// 套餐是否可用判断
|
|
525
714
|
var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
|
|
526
715
|
|
|
527
716
|
// 判断优惠券是否适用于该商品
|
|
528
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable
|
|
529
|
-
var _discountApplicabilit, _discount$
|
|
717
|
+
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
|
|
718
|
+
var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
|
|
530
719
|
// 记录此优惠券适用的商品
|
|
531
720
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
532
721
|
|
|
@@ -542,14 +731,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
542
731
|
type: discountType,
|
|
543
732
|
tag: discountType,
|
|
544
733
|
discount: {
|
|
545
|
-
discount_card_type: discount === null || discount === void 0 || (_discount$
|
|
734
|
+
discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
|
|
546
735
|
fixed_amount: product.price,
|
|
736
|
+
discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
|
|
547
737
|
resource_id: discount.id,
|
|
548
738
|
title: discount.format_title,
|
|
549
739
|
original_amount: product.price || product.origin_total,
|
|
550
740
|
pre_value: discount.par_value,
|
|
551
|
-
product_id: originProduct.id
|
|
552
|
-
discount_product_id: discount.product_id
|
|
741
|
+
product_id: originProduct.id
|
|
553
742
|
},
|
|
554
743
|
metadata: {
|
|
555
744
|
num: num
|
|
@@ -567,14 +756,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
567
756
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
568
757
|
// 🔥 使用扁平化后的列表进行处理
|
|
569
758
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
570
|
-
var
|
|
759
|
+
var _product9, _product$discount_lis2, _product10;
|
|
571
760
|
// 获取商品数据
|
|
572
761
|
var product, originProduct;
|
|
573
762
|
if (flatItem.type === 'main') {
|
|
574
763
|
product = flatItem.product;
|
|
575
764
|
originProduct = flatItem.originProduct;
|
|
576
765
|
} else {
|
|
577
|
-
var _flatItem$
|
|
766
|
+
var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu5;
|
|
578
767
|
// bundle子商品
|
|
579
768
|
product = {
|
|
580
769
|
_id: flatItem._id,
|
|
@@ -583,17 +772,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
583
772
|
quantity: flatItem.quantity,
|
|
584
773
|
num: flatItem.num,
|
|
585
774
|
total: flatItem.total,
|
|
586
|
-
original_price: flatItem === null || flatItem === void 0 || (_flatItem$
|
|
587
|
-
origin_total: flatItem === null || flatItem === void 0 || (_flatItem$
|
|
775
|
+
original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
|
|
776
|
+
origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
|
|
588
777
|
booking_id: flatItem.booking_id,
|
|
589
|
-
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$
|
|
590
|
-
startDate: (_flatItem$
|
|
778
|
+
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || [],
|
|
779
|
+
startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
|
|
591
780
|
};
|
|
592
781
|
originProduct = flatItem.originProduct;
|
|
593
782
|
}
|
|
594
783
|
|
|
595
784
|
// 已有优惠的商品跳过
|
|
596
|
-
if ((
|
|
785
|
+
if ((_product9 = product) !== null && _product9 !== void 0 && _product9.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product10 = product) !== null && _product10 !== void 0 && (_product10 = _product10.discount_list) !== null && _product10 !== void 0 && _product10.every(function (discount) {
|
|
597
786
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
598
787
|
})) {
|
|
599
788
|
if (flatItem.type === 'main') {
|
|
@@ -609,16 +798,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
609
798
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
610
799
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
611
800
|
var _product$discount_lis3, _product$discount_lis4;
|
|
612
|
-
// 🔥 检查策略可用性(针对 good_pass 和折扣卡)
|
|
613
|
-
var discountType = discount.tag || discount.type;
|
|
614
|
-
if (['good_pass', 'discount_card', 'product_discount_card'].includes(discountType)) {
|
|
615
|
-
var _discount$config2;
|
|
616
|
-
// 如果策略检查后没有config,说明不可用
|
|
617
|
-
if (discount.config === undefined || !(discount !== null && discount !== void 0 && (_discount$config2 = discount.config) !== null && _discount$config2 !== void 0 && _discount$config2.isAvailable)) {
|
|
618
|
-
return false;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
801
|
// 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
|
|
623
802
|
// 商品券时主商品价格为0不可用
|
|
624
803
|
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;
|
|
@@ -631,18 +810,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
631
810
|
// 如果优惠券已被使用,则跳过
|
|
632
811
|
var targetUsedDiscounts = usedDiscounts.get(discount.id);
|
|
633
812
|
if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
|
|
634
|
-
|
|
635
|
-
// 🔥 检查 maxUsagePerOrder 限制:同一 product_id 的商品券使用数量不能超过配置值
|
|
636
|
-
if ((discount.tag || discount.type) === 'good_pass') {
|
|
637
|
-
var _discount$config3;
|
|
638
|
-
var maxUsagePerOrder = (_discount$config3 = discount.config) === null || _discount$config3 === void 0 ? void 0 : _discount$config3.maxUsagePerOrder;
|
|
639
|
-
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
640
|
-
var currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
|
|
641
|
-
if (currentUsedCount >= maxUsagePerOrder) {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
813
|
var limitedData = discount.limited_relation_product_data;
|
|
647
814
|
|
|
648
815
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
@@ -661,9 +828,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
661
828
|
|
|
662
829
|
// 判断优惠券是否适用于该商品
|
|
663
830
|
if (limitedData.type === 'product_all') {
|
|
664
|
-
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
665
|
-
return false;
|
|
666
|
-
}
|
|
667
831
|
// 检查 package_sub_item_usage_rules
|
|
668
832
|
if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
669
833
|
return false;
|
|
@@ -690,12 +854,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
690
854
|
// 如果是手动折扣,则不适用优惠券
|
|
691
855
|
var isManualDiscount = false;
|
|
692
856
|
if (flatItem.type === 'main') {
|
|
693
|
-
var _product$discount_lis5,
|
|
857
|
+
var _product$discount_lis5, _product11, _product11$every;
|
|
694
858
|
// 主商品:判断自身是否手动折扣
|
|
695
859
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
696
860
|
var _ref5;
|
|
697
861
|
return !((_ref5 = item.discount_list || []) !== null && _ref5 !== void 0 && _ref5.length);
|
|
698
|
-
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((
|
|
862
|
+
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
|
|
699
863
|
return item.type === 'product';
|
|
700
864
|
})));
|
|
701
865
|
} else {
|
|
@@ -724,11 +888,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
724
888
|
}
|
|
725
889
|
// bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
|
|
726
890
|
if (flatItem.type === 'bundle') {
|
|
727
|
-
var _product$discount_lis7, _flatItem$
|
|
891
|
+
var _product$discount_lis7, _flatItem$parentProdu6;
|
|
728
892
|
if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
|
|
729
893
|
var _item$discount2;
|
|
730
894
|
return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
|
|
731
|
-
}) || (_flatItem$
|
|
895
|
+
}) || (_flatItem$parentProdu6 = flatItem.parentProduct) !== null && _flatItem$parentProdu6 !== void 0 && (_flatItem$parentProdu6 = _flatItem$parentProdu6.discount_list) !== null && _flatItem$parentProdu6 !== void 0 && _flatItem$parentProdu6.some(function (item) {
|
|
732
896
|
var _item$discount3;
|
|
733
897
|
return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
|
|
734
898
|
})) {
|
|
@@ -750,14 +914,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
750
914
|
}
|
|
751
915
|
// bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
|
|
752
916
|
if (flatItem.type === 'bundle') {
|
|
753
|
-
var _product$discount_lis9, _flatItem$
|
|
917
|
+
var _product$discount_lis9, _flatItem$parentProdu7;
|
|
754
918
|
if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
|
|
755
919
|
var _options$selectedList2;
|
|
756
920
|
return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
|
|
757
921
|
var _item$discount5;
|
|
758
922
|
return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
|
|
759
923
|
});
|
|
760
|
-
}) || (_flatItem$
|
|
924
|
+
}) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
|
|
761
925
|
var _options$selectedList3;
|
|
762
926
|
return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
|
|
763
927
|
var _item$discount6;
|
|
@@ -830,13 +994,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
830
994
|
var availableGoodPassCount = applicableDiscounts.filter(function (item) {
|
|
831
995
|
return (item.tag || item.type) === 'good_pass';
|
|
832
996
|
}).length;
|
|
833
|
-
|
|
834
|
-
// 🔥 如果selectedDiscount有config配置,则使用config.maxUsagePerOrder限制使用次数
|
|
835
|
-
var maxUsageLimit = availableGoodPassCount;
|
|
836
|
-
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
837
|
-
maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
|
|
838
|
-
}
|
|
839
|
-
var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
997
|
+
var splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
|
|
840
998
|
var arr = [];
|
|
841
999
|
|
|
842
1000
|
// 🔥 主商品和bundle子商品分别处理
|
|
@@ -846,21 +1004,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
846
1004
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
847
1005
|
discount_list: [],
|
|
848
1006
|
quantity: totalQuantity - splitCount,
|
|
849
|
-
_id: product._id.split('___')[0]
|
|
850
|
-
total: product.origin_total || product.total
|
|
1007
|
+
_id: product._id.split('___')[0]
|
|
851
1008
|
}));
|
|
852
1009
|
}
|
|
853
1010
|
for (var i = 0; i < splitCount; i++) {
|
|
854
|
-
var _product$discount_lis10, _originProduct, _selectedDiscount$met;
|
|
1011
|
+
var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
|
|
855
1012
|
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
856
1013
|
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
857
1014
|
// 标记优惠券为已使用
|
|
858
1015
|
usedDiscounts.set(_selectedDiscount.id, true);
|
|
859
|
-
// 🔥 更新 product_id 使用计数
|
|
860
|
-
if ((_selectedDiscount.tag || _selectedDiscount.type) === 'good_pass') {
|
|
861
|
-
var currentCount = usedProductIdCounts.get(_selectedDiscount.product_id) || 0;
|
|
862
|
-
usedProductIdCounts.set(_selectedDiscount.product_id, currentCount + 1);
|
|
863
|
-
}
|
|
864
1016
|
|
|
865
1017
|
// 记录实际应用了优惠券的商品信息
|
|
866
1018
|
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
@@ -877,31 +1029,45 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
877
1029
|
}
|
|
878
1030
|
|
|
879
1031
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
880
|
-
|
|
881
|
-
var
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
var
|
|
1032
|
+
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1033
|
+
var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
|
|
1034
|
+
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
|
|
1035
|
+
var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1036
|
+
var targetProductTotal = void 0;
|
|
1037
|
+
var amount = void 0;
|
|
1038
|
+
var productDiscountDifference = void 0;
|
|
1039
|
+
if (isOrderLevel && productAllocation) {
|
|
1040
|
+
// order_level:使用预计算的分摊金额
|
|
1041
|
+
amount = productAllocation.discountAmount;
|
|
1042
|
+
productDiscountDifference = productAllocation.difference;
|
|
1043
|
+
targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1044
|
+
} else {
|
|
1045
|
+
// item_level 或其他类型:使用原有逻辑
|
|
1046
|
+
targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
|
|
1047
|
+
amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
|
|
1048
|
+
}
|
|
1049
|
+
var discountType = _selectedDiscount.tag || _selectedDiscount.type;
|
|
885
1050
|
var isGoodPass = discountType === 'good_pass';
|
|
886
1051
|
var discountDetail = {
|
|
887
|
-
amount:
|
|
888
|
-
type: discountType,
|
|
1052
|
+
amount: amount,
|
|
1053
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
|
|
889
1054
|
discount: {
|
|
890
1055
|
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
891
|
-
fixed_amount:
|
|
1056
|
+
fixed_amount: amount,
|
|
1057
|
+
discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
|
|
892
1058
|
resource_id: _selectedDiscount.id,
|
|
893
1059
|
title: _selectedDiscount.format_title,
|
|
894
1060
|
original_amount: product.price,
|
|
895
1061
|
product_id: originProduct.id,
|
|
896
|
-
percent: _selectedDiscount.par_value
|
|
897
|
-
discount_product_id: _selectedDiscount.product_id
|
|
1062
|
+
percent: _selectedDiscount.par_value
|
|
898
1063
|
},
|
|
899
1064
|
// 前端使用的num数量,为了计算优惠金额
|
|
900
1065
|
_num: isGoodPass ? 1 : product.num,
|
|
901
|
-
|
|
902
|
-
metadata: {
|
|
1066
|
+
metadata: _objectSpread({
|
|
903
1067
|
num: 1
|
|
904
|
-
}
|
|
1068
|
+
}, productDiscountDifference !== undefined && {
|
|
1069
|
+
product_discount_difference: productDiscountDifference
|
|
1070
|
+
})
|
|
905
1071
|
};
|
|
906
1072
|
appliedProducts.push(discountDetail);
|
|
907
1073
|
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
@@ -917,6 +1083,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
917
1083
|
// 记录应用了优惠券的商品
|
|
918
1084
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
919
1085
|
if (product.isClient) {
|
|
1086
|
+
debugger;
|
|
920
1087
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
921
1088
|
discount_list: [discountDetail],
|
|
922
1089
|
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
@@ -955,38 +1122,29 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
955
1122
|
|
|
956
1123
|
// 生成有折扣的商品(每张商品券对应 num: 1)
|
|
957
1124
|
for (var _i = 0; _i < discountNum; _i++) {
|
|
1125
|
+
var _selectedDiscount2$me;
|
|
958
1126
|
var _selectedDiscount2 = applicableDiscounts[_i];
|
|
959
1127
|
usedDiscounts.set(_selectedDiscount2.id, true);
|
|
960
|
-
// 🔥 更新 product_id 使用计数
|
|
961
|
-
if ((_selectedDiscount2.tag || _selectedDiscount2.type) === 'good_pass') {
|
|
962
|
-
var _currentCount = usedProductIdCounts.get(_selectedDiscount2.product_id) || 0;
|
|
963
|
-
usedProductIdCounts.set(_selectedDiscount2.product_id, _currentCount + 1);
|
|
964
|
-
}
|
|
965
1128
|
|
|
966
1129
|
// 🔥 生成唯一的 _id
|
|
967
1130
|
var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
|
|
968
|
-
|
|
969
|
-
// 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
|
|
970
|
-
var discountedPrice = getDiscountAmount(_selectedDiscount2, product.origin_total, product.origin_total);
|
|
971
|
-
var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
972
1131
|
var _discountDetail = {
|
|
973
|
-
amount:
|
|
1132
|
+
amount: product.origin_total,
|
|
974
1133
|
type: 'good_pass',
|
|
975
1134
|
discount: {
|
|
976
1135
|
fixed_amount: product.origin_total,
|
|
1136
|
+
discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
|
|
977
1137
|
resource_id: _selectedDiscount2.id,
|
|
978
1138
|
title: _selectedDiscount2.format_title,
|
|
979
1139
|
original_amount: product.origin_total,
|
|
980
|
-
product_id: product.id
|
|
981
|
-
discount_product_id: _selectedDiscount2.product_id
|
|
1140
|
+
product_id: product.id
|
|
982
1141
|
},
|
|
983
1142
|
metadata: {
|
|
984
1143
|
// 🔥 使用拆分后的唯一 _id
|
|
985
1144
|
custom_product_bundle_map_id: uniqueId,
|
|
986
1145
|
num: 1
|
|
987
1146
|
},
|
|
988
|
-
_num: 1
|
|
989
|
-
config: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.config
|
|
1147
|
+
_num: 1
|
|
990
1148
|
};
|
|
991
1149
|
|
|
992
1150
|
// 记录实际应用的折扣
|
|
@@ -998,9 +1156,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
998
1156
|
_id: uniqueId,
|
|
999
1157
|
num: 1,
|
|
1000
1158
|
quantity: 1,
|
|
1001
|
-
price:
|
|
1002
|
-
//
|
|
1003
|
-
total:
|
|
1159
|
+
price: 0,
|
|
1160
|
+
// 商品券价格为0
|
|
1161
|
+
total: 0,
|
|
1004
1162
|
discount_list: [_discountDetail],
|
|
1005
1163
|
processed: true,
|
|
1006
1164
|
_discountId: _selectedDiscount2.id
|
|
@@ -1019,43 +1177,53 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1019
1177
|
}));
|
|
1020
1178
|
}
|
|
1021
1179
|
} else {
|
|
1022
|
-
var _selectedDiscount3$me, _flatItem$
|
|
1180
|
+
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu8;
|
|
1023
1181
|
// 折扣卡:不拆分数量,直接应用
|
|
1024
1182
|
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1025
1183
|
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
1026
|
-
// 🔥 更新 product_id 使用计数(虽然此处主要是折扣卡,但保持一致性)
|
|
1027
|
-
if ((_selectedDiscount3.tag || _selectedDiscount3.type) === 'good_pass') {
|
|
1028
|
-
var _currentCount2 = usedProductIdCounts.get(_selectedDiscount3.product_id) || 0;
|
|
1029
|
-
usedProductIdCounts.set(_selectedDiscount3.product_id, _currentCount2 + 1);
|
|
1030
|
-
}
|
|
1031
1184
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1032
|
-
var _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1033
|
-
|
|
1034
|
-
// 计算实际折扣金额
|
|
1035
|
-
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
|
|
1036
1185
|
|
|
1186
|
+
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1187
|
+
var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
|
|
1188
|
+
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
|
|
1189
|
+
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1190
|
+
var _targetProductTotal;
|
|
1191
|
+
var fixedAmountPerItem;
|
|
1192
|
+
var _productDiscountDifference;
|
|
1193
|
+
if (_isOrderLevel && _productAllocation) {
|
|
1194
|
+
// order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
|
|
1195
|
+
fixedAmountPerItem = _productAllocation.discountAmount;
|
|
1196
|
+
_productDiscountDifference = _productAllocation.difference;
|
|
1197
|
+
_targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1198
|
+
} else {
|
|
1199
|
+
// item_level 或其他类型:使用原有逻辑
|
|
1200
|
+
_targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1201
|
+
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
|
|
1202
|
+
}
|
|
1203
|
+
debugger;
|
|
1037
1204
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1038
1205
|
var _uniqueId = flatItem._id;
|
|
1039
1206
|
var _discountDetail2 = {
|
|
1040
|
-
amount:
|
|
1207
|
+
amount: fixedAmountPerItem * (product.num || 1),
|
|
1041
1208
|
type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
|
|
1042
1209
|
discount: {
|
|
1043
1210
|
discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
|
|
1044
|
-
fixed_amount:
|
|
1211
|
+
fixed_amount: fixedAmountPerItem,
|
|
1212
|
+
discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
|
|
1045
1213
|
resource_id: _selectedDiscount3.id,
|
|
1046
1214
|
title: _selectedDiscount3.format_title,
|
|
1047
1215
|
original_amount: product.original_price,
|
|
1048
1216
|
product_id: product.id,
|
|
1049
|
-
percent: _selectedDiscount3.par_value
|
|
1050
|
-
discount_product_id: _selectedDiscount3.product_id
|
|
1217
|
+
percent: _selectedDiscount3.par_value
|
|
1051
1218
|
},
|
|
1052
|
-
metadata: {
|
|
1219
|
+
metadata: _objectSpread({
|
|
1053
1220
|
// 🔥 使用唯一的 _id
|
|
1054
1221
|
custom_product_bundle_map_id: _uniqueId,
|
|
1055
1222
|
num: product.num || 1
|
|
1056
|
-
},
|
|
1057
|
-
|
|
1058
|
-
|
|
1223
|
+
}, _productDiscountDifference !== undefined && {
|
|
1224
|
+
product_discount_difference: _productDiscountDifference
|
|
1225
|
+
}),
|
|
1226
|
+
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu8 = flatItem.parentProduct) === null || _flatItem$parentProdu8 === void 0 ? void 0 : _flatItem$parentProdu8.num) || 1)
|
|
1059
1227
|
};
|
|
1060
1228
|
|
|
1061
1229
|
// 记录实际应用的折扣
|
|
@@ -1064,7 +1232,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1064
1232
|
appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
|
|
1065
1233
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1066
1234
|
total: _targetProductTotal,
|
|
1067
|
-
price: new Decimal(_productOriginTotal || 0).minus(
|
|
1235
|
+
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
1068
1236
|
discount_list: [_discountDetail2],
|
|
1069
1237
|
processed: true
|
|
1070
1238
|
}));
|
|
@@ -1174,10 +1342,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1174
1342
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1175
1343
|
var _item$metadata;
|
|
1176
1344
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1177
|
-
metadata: {
|
|
1345
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1178
1346
|
num: item.num,
|
|
1179
1347
|
custom_product_bundle_map_id: (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.custom_product_bundle_map_id
|
|
1180
|
-
}
|
|
1348
|
+
})
|
|
1181
1349
|
// num: item.num, // 使用拆分后的 num
|
|
1182
1350
|
});
|
|
1183
1351
|
});
|
|
@@ -1197,10 +1365,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1197
1365
|
var _updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1198
1366
|
var _item$metadata2;
|
|
1199
1367
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1200
|
-
metadata: {
|
|
1368
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1201
1369
|
num: item.num,
|
|
1202
1370
|
custom_product_bundle_map_id: (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.custom_product_bundle_map_id
|
|
1203
|
-
}
|
|
1371
|
+
})
|
|
1204
1372
|
// num: item.num, // 使用当前的 num
|
|
1205
1373
|
});
|
|
1206
1374
|
});
|
|
@@ -1223,18 +1391,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1223
1391
|
|
|
1224
1392
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
|
|
1225
1393
|
var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
|
|
1226
|
-
var _discount$
|
|
1227
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1394
|
+
var _discount$metadata6, _discount$metadata7;
|
|
1395
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
|
|
1228
1396
|
// bundle的discount_list保持不变
|
|
1229
1397
|
return discount;
|
|
1230
1398
|
}
|
|
1231
1399
|
// 主商品自己的discount,更新num为1
|
|
1232
1400
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1233
1401
|
// num: 1,
|
|
1234
|
-
metadata: {
|
|
1235
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1402
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1403
|
+
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,
|
|
1236
1404
|
num: 1
|
|
1237
|
-
}
|
|
1405
|
+
})
|
|
1238
1406
|
});
|
|
1239
1407
|
});
|
|
1240
1408
|
|
|
@@ -1297,17 +1465,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1297
1465
|
|
|
1298
1466
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
|
|
1299
1467
|
var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
|
|
1300
|
-
var _discount$
|
|
1301
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1468
|
+
var _discount$metadata8, _discount$metadata9;
|
|
1469
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
|
|
1302
1470
|
// bundle的discount_list保持不变
|
|
1303
1471
|
return discount;
|
|
1304
1472
|
}
|
|
1305
1473
|
// 主商品自己的discount,更新num为 mainProductQuantity - 1
|
|
1306
1474
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1307
|
-
metadata: {
|
|
1475
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1308
1476
|
num: mainProductQuantity - 1,
|
|
1309
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1310
|
-
}
|
|
1477
|
+
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
|
|
1478
|
+
})
|
|
1311
1479
|
// num: mainProductQuantity - 1,
|
|
1312
1480
|
});
|
|
1313
1481
|
});
|
|
@@ -1371,12 +1539,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1371
1539
|
processedBundleItems.forEach(function (item) {
|
|
1372
1540
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
1373
1541
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1374
|
-
var _discount$
|
|
1542
|
+
var _discount$metadata10;
|
|
1375
1543
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1376
|
-
metadata: {
|
|
1544
|
+
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1377
1545
|
num: item.num,
|
|
1378
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1379
|
-
}
|
|
1546
|
+
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
|
|
1547
|
+
})
|
|
1380
1548
|
// num: item.num, // 使用拆分后的 num
|
|
1381
1549
|
});
|
|
1382
1550
|
});
|
|
@@ -1563,10 +1731,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1563
1731
|
return true; // 单独购买时可用
|
|
1564
1732
|
}
|
|
1565
1733
|
if (isBundleItem) {
|
|
1566
|
-
var _flatItem$
|
|
1734
|
+
var _flatItem$bundleItem8, _flatItem$bundleItem9;
|
|
1567
1735
|
// 套餐中购买时,判断是否为原价
|
|
1568
|
-
var priceType = (_flatItem$
|
|
1569
|
-
var priceTypeExt = (_flatItem$
|
|
1736
|
+
var priceType = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type;
|
|
1737
|
+
var priceTypeExt = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type_ext;
|
|
1570
1738
|
// original_price 对应:
|
|
1571
1739
|
// 1. price_type: "markup" && price_type_ext: "product_price"
|
|
1572
1740
|
// markup_price 对应:
|
|
@@ -1604,10 +1772,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1604
1772
|
return false; // 单独购买时不可用
|
|
1605
1773
|
}
|
|
1606
1774
|
if (isBundleItem) {
|
|
1607
|
-
var _flatItem$
|
|
1775
|
+
var _flatItem$bundleItem10, _flatItem$bundleItem11;
|
|
1608
1776
|
// 套餐中购买时,判断是否为原价
|
|
1609
|
-
var _priceType = (_flatItem$
|
|
1610
|
-
var _priceTypeExt = (_flatItem$
|
|
1777
|
+
var _priceType = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type;
|
|
1778
|
+
var _priceTypeExt = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type_ext;
|
|
1611
1779
|
|
|
1612
1780
|
// original_price 对应:
|
|
1613
1781
|
// 1. price_type: "markup" && price_type_ext: "product_price"
|