@pisell/pisellos 2.1.63 → 2.1.65

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.
@@ -24,7 +24,7 @@ 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, filterDiscountListByBookingTime, getDiscountListAmountTotal, getDiscountListAmount } 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';
@@ -216,6 +216,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
216
216
  }
217
217
  });
218
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
+
219
238
  // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
220
239
  var filteredDiscountList = addModeDiscount.filter(function (discount) {
221
240
  return !discount.isManualSelect;
@@ -271,26 +290,69 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
271
290
  };
272
291
 
273
292
  // 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
274
- // 1. 商品券(n.tag=good_pass)视为最优惠(免费)
275
- // 2. 折扣券(n.tag=product_discount_card)按照新的优先级排序:
276
- // - 固定金额优先于百分比(固定金额 > 百分比)
277
- // - 固定金额内部:金额越大越优先
278
- // - 百分比内部:折扣越大越优先(par_value越小越优先)
279
- // 3. 相同类型和金额的情况下,按照过期时间(n.expire_time)排序
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
+ // 同一优先级内部:固定金额优先于百分比,金额/折扣力度越大越优先,最后按过期时间排序
280
301
  var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
281
- // 1. 商品券优先级最高
282
- if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
283
- if (b.tag === 'good_pass' && a.tag !== 'good_pass') return 1;
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
+ };
284
307
 
285
- // 2. 如果都是商品券或都不是商品券,按照类型和折扣力度排序
286
- if (a.tag === 'good_pass' && b.tag === 'good_pass') {
287
- // 都是商品券,按照过期时间排序
288
- return compareByExpireTime(a, b);
289
- } else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
290
- var _a$metadata, _b$metadata;
291
- // 都是折扣券,按照新的优先级排序:固定金额优先于百分比
292
- var typeA = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 ? void 0 : _a$metadata.discount_card_type) || 'percent'; // 默认为百分比
293
- var typeB = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 ? void 0 : _b$metadata.discount_card_type) || 'percent'; // 默认为百分比
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';
294
356
 
295
357
  // 1. 固定金额优先于百分比
296
358
  if (typeA === 'fixed_amount' && typeB === 'percent') return -1;
@@ -298,37 +360,46 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
298
360
 
299
361
  // 2. 都是固定金额时,金额越大越优先
300
362
  if (typeA === 'fixed_amount' && typeB === 'fixed_amount') {
301
- if (a.par_value !== b.par_value) {
302
- var valueA = new Decimal(a.par_value || 0);
303
- var valueB = new Decimal(b.par_value || 0);
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);
304
366
  return valueB.minus(valueA).toNumber(); // 金额大的在前
305
367
  }
306
368
  }
307
369
 
308
370
  // 3. 都是百分比时,折扣越大越优先(par_value越大越优先)
309
371
  if (typeA === 'percent' && typeB === 'percent') {
310
- if (a.par_value !== b.par_value) {
311
- var _valueA = new Decimal(100).minus(a.par_value || 0);
312
- var _valueB = new Decimal(100).minus(b.par_value || 0);
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);
313
375
  return _valueA.minus(_valueB).toNumber(); // 折扣大的在前
314
376
  }
315
377
  }
378
+ return 0;
379
+ }
380
+
381
+ // 1. 先按优先级排序
382
+ var priorityA = getPriority(a);
383
+ var priorityB = getPriority(b);
384
+ if (priorityA !== priorityB) {
385
+ return priorityA - priorityB;
386
+ }
316
387
 
317
- // 相同类型和金额的情况下,按照过期时间排序
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;
318
398
  return compareByExpireTime(a, b);
319
399
  }
320
400
 
321
401
  // 3. 其他情况按照过期时间排序
322
402
  return compareByExpireTime(a, b);
323
- function compareByExpireTime(itemA, itemB) {
324
- if (itemA.expire_time && itemB.expire_time) {
325
- var timeA = new Date(itemA.expire_time).getTime();
326
- var timeB = new Date(itemB.expire_time).getTime();
327
- return timeA - timeB;
328
- }
329
- // 有过期时间的优先级高于永久的
330
- return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
331
- }
332
403
  });
333
404
 
334
405
  // const newProductList = [];
@@ -406,6 +477,187 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
406
477
  discountApplicableProducts.set(discount.id, []);
407
478
  });
408
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
+
409
661
  // 处理后的商品列表(按排序后的顺序处理,记录优惠信息)
410
662
  var processedProductsMap = new Map();
411
663
 
@@ -421,7 +673,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
421
673
  product = flatItem.product;
422
674
  originProduct = flatItem.originProduct;
423
675
  } else {
424
- var _flatItem$parentProdu;
676
+ var _flatItem$parentProdu4;
425
677
  // bundle子商品:构造虚拟商品对象
426
678
  product = {
427
679
  _id: flatItem._id,
@@ -433,12 +685,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
433
685
  origin_total: flatItem.origin_total,
434
686
  booking_id: flatItem.booking_id,
435
687
  discount_list: flatItem.discount_list || [],
436
- startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
688
+ startDate: (_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.startDate
437
689
  };
438
690
  originProduct = flatItem.originProduct;
439
691
  }
440
692
  addModeDiscount.forEach(function (discount) {
441
- var _product, _product2, _product3, _product4, _flatItem$bundleItem;
693
+ var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4;
442
694
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
443
695
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
444
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;
@@ -447,21 +699,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
447
699
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
448
700
  }, holders);
449
701
  var timeLimit = true;
450
- timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
702
+ timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
451
703
  // 是符合折扣的商品
452
704
  var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
453
705
 
454
706
  // 编辑的商品 使用了优惠券不可用
455
- var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (discount) {
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) {
456
708
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
457
- })) : !(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.metadata) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.custom_product_bundle_map_id);
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
+ }));
458
712
 
459
713
  // 套餐是否可用判断
460
714
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
461
715
 
462
716
  // 判断优惠券是否适用于该商品
463
717
  if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
464
- var _discountApplicabilit, _discount$metadata;
718
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
465
719
  // 记录此优惠券适用的商品
466
720
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
467
721
 
@@ -477,8 +731,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
477
731
  type: discountType,
478
732
  tag: discountType,
479
733
  discount: {
480
- discount_card_type: discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type,
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,
481
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,
482
737
  resource_id: discount.id,
483
738
  title: discount.format_title,
484
739
  original_amount: product.price || product.origin_total,
@@ -501,14 +756,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
501
756
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
502
757
  // 🔥 使用扁平化后的列表进行处理
503
758
  sortedFlattenedList.forEach(function (flatItem, index) {
504
- var _product5, _product$discount_lis2, _product6;
759
+ var _product9, _product$discount_lis2, _product10;
505
760
  // 获取商品数据
506
761
  var product, originProduct;
507
762
  if (flatItem.type === 'main') {
508
763
  product = flatItem.product;
509
764
  originProduct = flatItem.originProduct;
510
765
  } else {
511
- var _flatItem$bundleItem2, _flatItem$bundleItem3, _flatItem$bundleItem4, _flatItem$parentProdu2;
766
+ var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu5;
512
767
  // bundle子商品
513
768
  product = {
514
769
  _id: flatItem._id,
@@ -517,17 +772,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
517
772
  quantity: flatItem.quantity,
518
773
  num: flatItem.num,
519
774
  total: flatItem.total,
520
- original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem2 = flatItem.bundleItem) === null || _flatItem$bundleItem2 === void 0 ? void 0 : _flatItem$bundleItem2.original_price,
521
- origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem3 = flatItem.bundleItem) === null || _flatItem$bundleItem3 === void 0 ? void 0 : _flatItem$bundleItem3.original_price,
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,
522
777
  booking_id: flatItem.booking_id,
523
- discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem4 = flatItem.bundleItem) === null || _flatItem$bundleItem4 === void 0 ? void 0 : _flatItem$bundleItem4.discount_list) || [],
524
- startDate: (_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.startDate
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
525
780
  };
526
781
  originProduct = flatItem.originProduct;
527
782
  }
528
783
 
529
784
  // 已有优惠的商品跳过
530
- if ((_product5 = product) !== null && _product5 !== void 0 && _product5.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product6 = product) !== null && _product6 !== void 0 && (_product6 = _product6.discount_list) !== null && _product6 !== void 0 && _product6.every(function (discount) {
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) {
531
786
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
532
787
  })) {
533
788
  if (flatItem.type === 'main') {
@@ -599,12 +854,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
599
854
  // 如果是手动折扣,则不适用优惠券
600
855
  var isManualDiscount = false;
601
856
  if (flatItem.type === 'main') {
602
- var _product$discount_lis5, _product7, _product7$every;
857
+ var _product$discount_lis5, _product11, _product11$every;
603
858
  // 主商品:判断自身是否手动折扣
604
859
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
605
860
  var _ref5;
606
861
  return !((_ref5 = item.discount_list || []) !== null && _ref5 !== void 0 && _ref5.length);
607
- }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product7 = product) === null || _product7 === void 0 || (_product7 = _product7.discount_list) === null || _product7 === void 0 || (_product7$every = _product7.every) === null || _product7$every === void 0 ? void 0 : _product7$every.call(_product7, function (item) {
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) {
608
863
  return item.type === 'product';
609
864
  })));
610
865
  } else {
@@ -633,11 +888,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
633
888
  }
634
889
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
635
890
  if (flatItem.type === 'bundle') {
636
- var _product$discount_lis7, _flatItem$parentProdu3;
891
+ var _product$discount_lis7, _flatItem$parentProdu6;
637
892
  if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
638
893
  var _item$discount2;
639
894
  return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
640
- }) || (_flatItem$parentProdu3 = flatItem.parentProduct) !== null && _flatItem$parentProdu3 !== void 0 && (_flatItem$parentProdu3 = _flatItem$parentProdu3.discount_list) !== null && _flatItem$parentProdu3 !== void 0 && _flatItem$parentProdu3.some(function (item) {
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) {
641
896
  var _item$discount3;
642
897
  return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
643
898
  })) {
@@ -659,14 +914,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
659
914
  }
660
915
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
661
916
  if (flatItem.type === 'bundle') {
662
- var _product$discount_lis9, _flatItem$parentProdu4;
917
+ var _product$discount_lis9, _flatItem$parentProdu7;
663
918
  if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
664
919
  var _options$selectedList2;
665
920
  return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
666
921
  var _item$discount5;
667
922
  return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
668
923
  });
669
- }) || (_flatItem$parentProdu4 = flatItem.parentProduct) !== null && _flatItem$parentProdu4 !== void 0 && (_flatItem$parentProdu4 = _flatItem$parentProdu4.discount_list) !== null && _flatItem$parentProdu4 !== void 0 && _flatItem$parentProdu4.some(function (item) {
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) {
670
925
  var _options$selectedList3;
671
926
  return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
672
927
  var _item$discount6;
@@ -753,7 +1008,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
753
1008
  }));
754
1009
  }
755
1010
  for (var i = 0; i < splitCount; i++) {
756
- var _product$discount_lis10, _originProduct, _selectedDiscount$met;
1011
+ var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
757
1012
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
758
1013
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
759
1014
  // 标记优惠券为已使用
@@ -774,16 +1029,32 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
774
1029
  }
775
1030
 
776
1031
  // 计算使用折扣卡/商品券以后,单个商品的总 total
777
- var targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
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
+ }
778
1049
  var discountType = _selectedDiscount.tag || _selectedDiscount.type;
779
1050
  var isGoodPass = discountType === 'good_pass';
780
- var amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
781
1051
  var discountDetail = {
782
1052
  amount: amount,
783
1053
  type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
784
1054
  discount: {
785
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,
786
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,
787
1058
  resource_id: _selectedDiscount.id,
788
1059
  title: _selectedDiscount.format_title,
789
1060
  original_amount: product.price,
@@ -792,9 +1063,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
792
1063
  },
793
1064
  // 前端使用的num数量,为了计算优惠金额
794
1065
  _num: isGoodPass ? 1 : product.num,
795
- metadata: {
1066
+ metadata: _objectSpread({
796
1067
  num: 1
797
- }
1068
+ }, productDiscountDifference !== undefined && {
1069
+ product_discount_difference: productDiscountDifference
1070
+ })
798
1071
  };
799
1072
  appliedProducts.push(discountDetail);
800
1073
  appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
@@ -849,6 +1122,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
849
1122
 
850
1123
  // 生成有折扣的商品(每张商品券对应 num: 1)
851
1124
  for (var _i = 0; _i < discountNum; _i++) {
1125
+ var _selectedDiscount2$me;
852
1126
  var _selectedDiscount2 = applicableDiscounts[_i];
853
1127
  usedDiscounts.set(_selectedDiscount2.id, true);
854
1128
 
@@ -859,6 +1133,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
859
1133
  type: 'good_pass',
860
1134
  discount: {
861
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,
862
1137
  resource_id: _selectedDiscount2.id,
863
1138
  title: _selectedDiscount2.format_title,
864
1139
  original_amount: product.origin_total,
@@ -902,33 +1177,53 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
902
1177
  }));
903
1178
  }
904
1179
  } else {
905
- var _selectedDiscount3$me, _flatItem$parentProdu5;
1180
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu8;
906
1181
  // 折扣卡:不拆分数量,直接应用
907
1182
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
908
1183
  usedDiscounts.set(_selectedDiscount3.id, true);
909
1184
  var _productOriginTotal = product.original_price || product.price || 0;
910
- var _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
911
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;
912
1204
  // 🔥 使用当前的 _id 作为唯一标识
913
1205
  var _uniqueId = flatItem._id;
914
1206
  var _discountDetail2 = {
915
- amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber() * (product.num || 1),
1207
+ amount: fixedAmountPerItem * (product.num || 1),
916
1208
  type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
917
1209
  discount: {
918
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,
919
- fixed_amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber(),
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,
920
1213
  resource_id: _selectedDiscount3.id,
921
1214
  title: _selectedDiscount3.format_title,
922
1215
  original_amount: product.original_price,
923
1216
  product_id: product.id,
924
1217
  percent: _selectedDiscount3.par_value
925
1218
  },
926
- metadata: {
1219
+ metadata: _objectSpread({
927
1220
  // 🔥 使用唯一的 _id
928
1221
  custom_product_bundle_map_id: _uniqueId,
929
1222
  num: product.num || 1
930
- },
931
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.num) || 1)
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)
932
1227
  };
933
1228
 
934
1229
  // 记录实际应用的折扣
@@ -937,7 +1232,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
937
1232
  appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
938
1233
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
939
1234
  total: _targetProductTotal,
940
- price: new Decimal(_productOriginTotal || 0).minus(_discountDetail2.discount.fixed_amount).toNumber(),
1235
+ price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
941
1236
  discount_list: [_discountDetail2],
942
1237
  processed: true
943
1238
  }));
@@ -1047,10 +1342,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1047
1342
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1048
1343
  var _item$metadata;
1049
1344
  return _objectSpread(_objectSpread({}, discount), {}, {
1050
- metadata: {
1345
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1051
1346
  num: item.num,
1052
1347
  custom_product_bundle_map_id: (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.custom_product_bundle_map_id
1053
- }
1348
+ })
1054
1349
  // num: item.num, // 使用拆分后的 num
1055
1350
  });
1056
1351
  });
@@ -1070,10 +1365,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1070
1365
  var _updatedDiscountList = (item.discount_list || []).map(function (discount) {
1071
1366
  var _item$metadata2;
1072
1367
  return _objectSpread(_objectSpread({}, discount), {}, {
1073
- metadata: {
1368
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1074
1369
  num: item.num,
1075
1370
  custom_product_bundle_map_id: (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.custom_product_bundle_map_id
1076
- }
1371
+ })
1077
1372
  // num: item.num, // 使用当前的 num
1078
1373
  });
1079
1374
  });
@@ -1096,18 +1391,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1096
1391
 
1097
1392
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
1098
1393
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
1099
- var _discount$metadata2, _discount$metadata3;
1100
- if (discount !== null && discount !== void 0 && (_discount$metadata2 = discount.metadata) !== null && _discount$metadata2 !== void 0 && _discount$metadata2.custom_product_bundle_map_id) {
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) {
1101
1396
  // bundle的discount_list保持不变
1102
1397
  return discount;
1103
1398
  }
1104
1399
  // 主商品自己的discount,更新num为1
1105
1400
  return _objectSpread(_objectSpread({}, discount), {}, {
1106
1401
  // num: 1,
1107
- metadata: {
1108
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.custom_product_bundle_map_id,
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,
1109
1404
  num: 1
1110
- }
1405
+ })
1111
1406
  });
1112
1407
  });
1113
1408
 
@@ -1170,17 +1465,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1170
1465
 
1171
1466
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1172
1467
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
1173
- var _discount$metadata4, _discount$metadata5;
1174
- if (discount !== null && discount !== void 0 && (_discount$metadata4 = discount.metadata) !== null && _discount$metadata4 !== void 0 && _discount$metadata4.custom_product_bundle_map_id) {
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) {
1175
1470
  // bundle的discount_list保持不变
1176
1471
  return discount;
1177
1472
  }
1178
1473
  // 主商品自己的discount,更新num为 mainProductQuantity - 1
1179
1474
  return _objectSpread(_objectSpread({}, discount), {}, {
1180
- metadata: {
1475
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1181
1476
  num: mainProductQuantity - 1,
1182
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.custom_product_bundle_map_id
1183
- }
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
+ })
1184
1479
  // num: mainProductQuantity - 1,
1185
1480
  });
1186
1481
  });
@@ -1244,12 +1539,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1244
1539
  processedBundleItems.forEach(function (item) {
1245
1540
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1246
1541
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1247
- var _discount$metadata6;
1542
+ var _discount$metadata10;
1248
1543
  return _objectSpread(_objectSpread({}, discount), {}, {
1249
- metadata: {
1544
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1250
1545
  num: item.num,
1251
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.custom_product_bundle_map_id
1252
- }
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
+ })
1253
1548
  // num: item.num, // 使用拆分后的 num
1254
1549
  });
1255
1550
  });
@@ -1436,10 +1731,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1436
1731
  return true; // 单独购买时可用
1437
1732
  }
1438
1733
  if (isBundleItem) {
1439
- var _flatItem$bundleItem5, _flatItem$bundleItem6;
1734
+ var _flatItem$bundleItem8, _flatItem$bundleItem9;
1440
1735
  // 套餐中购买时,判断是否为原价
1441
- var priceType = (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.price_type;
1442
- var priceTypeExt = (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.price_type_ext;
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;
1443
1738
  // original_price 对应:
1444
1739
  // 1. price_type: "markup" && price_type_ext: "product_price"
1445
1740
  // markup_price 对应:
@@ -1477,10 +1772,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1477
1772
  return false; // 单独购买时不可用
1478
1773
  }
1479
1774
  if (isBundleItem) {
1480
- var _flatItem$bundleItem7, _flatItem$bundleItem8;
1775
+ var _flatItem$bundleItem10, _flatItem$bundleItem11;
1481
1776
  // 套餐中购买时,判断是否为原价
1482
- var _priceType = (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.price_type;
1483
- var _priceTypeExt = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type_ext;
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;
1484
1779
 
1485
1780
  // original_price 对应:
1486
1781
  // 1. price_type: "markup" && price_type_ext: "product_price"