@pisell/pisellos 0.0.395 → 0.0.397

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.
@@ -98,7 +98,9 @@ export interface Discount {
98
98
  isEditMode?: boolean;
99
99
  isScan?: boolean;
100
100
  discount?: {
101
+ discount_product_id: number;
101
102
  resource_id: number;
103
+ discount_calculation_mode: 'item_level' | 'order_level';
102
104
  };
103
105
  isManualSelect?: boolean;
104
106
  isDisabled?: boolean;
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -227,6 +227,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
227
227
  }
228
228
  });
229
229
 
230
+ // 🔥 检查 editModeDiscount 中是否有订单级别的折扣,如果有则禁用 addModeDiscount 中相同 product_id 的折扣卡
231
+ var editModeOrderLevelProductIds = new Set();
232
+ editModeDiscount.forEach(function (discount) {
233
+ var _discount$discount2;
234
+ if (((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.discount_calculation_mode) === 'order_level') {
235
+ var _discount$discount3;
236
+ editModeOrderLevelProductIds.add(discount === null || discount === void 0 || (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_product_id);
237
+ }
238
+ });
239
+
240
+ // 如果存在订单级别的编辑模式折扣,禁用 addModeDiscount 中相同 product_id 的折扣卡
241
+ if (editModeOrderLevelProductIds.size > 0) {
242
+ addModeDiscount.forEach(function (discount) {
243
+ if (editModeOrderLevelProductIds.has(discount.product_id)) {
244
+ discount.isDisabled = true;
245
+ }
246
+ });
247
+ }
248
+
230
249
  // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
231
250
  var filteredDiscountList = addModeDiscount.filter(function (discount) {
232
251
  return !discount.isManualSelect;
@@ -523,81 +542,178 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
523
542
  discountApplicableProducts.set(discount.id, []);
524
543
  });
525
544
 
526
- // 🔥 预处理 order_level 固定金额折扣卡的分摊信息
545
+ // 预处理 order_level 固定金额折扣卡的分摊信息
527
546
  // Map<discountId, Map<productId, { discountAmount, difference }>>
528
547
  var orderLevelDiscountAllocations = new Map();
529
548
 
530
- // 识别 order_level 折扣卡并预计算分摊
549
+ // 第一步:收集所有被勾选的 order_level 折扣卡及其适用商品
550
+ // Map<discountId, Set<flatItemId>> - 记录每个折扣卡适用的商品
551
+ var orderLevelDiscountApplicableItems = new Map();
552
+ // Map<flatItemId, Set<discountId>> - 记录每个商品可以被哪些折扣卡使用
553
+ var itemApplicableDiscounts = new Map();
554
+
555
+ // 辅助函数:检查商品是否对某个折扣卡可用
556
+ var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
557
+ var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
558
+ var product;
559
+ if (flatItem.type === 'main') {
560
+ product = flatItem.product;
561
+ } else {
562
+ var _flatItem$parentProdu;
563
+ product = {
564
+ _id: flatItem._id,
565
+ id: flatItem.id,
566
+ price: flatItem.price,
567
+ quantity: flatItem.quantity,
568
+ num: flatItem.num,
569
+ booking_id: flatItem.booking_id,
570
+ discount_list: flatItem.discount_list || [],
571
+ startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
572
+ };
573
+ }
574
+
575
+ // 编辑的商品使用了优惠券不可用
576
+ 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) {
577
+ return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
578
+ })) : !(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) {
579
+ return d.id;
580
+ }));
581
+ if (!isAvailableProduct) {
582
+ return false;
583
+ }
584
+
585
+ // vouchersApplicable 为 false 的商品不参与订单级别折扣均摊
586
+ if (isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
587
+ return false;
588
+ }
589
+
590
+ // 商品价格为0时不可用
591
+ if (Number(product.price) <= 0 || !product.price) {
592
+ return false;
593
+ }
594
+ var limitedData = discount.limited_relation_product_data;
595
+
596
+ // 时间限制检查
597
+ var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
598
+ if (!timeLimit) {
599
+ return false;
600
+ }
601
+
602
+ // 判断商品是否适用
603
+ var isLimitedProduct = false;
604
+ if (limitedData.type === 'product_all') {
605
+ var _limitedData$exclude_;
606
+ // 全品类,但需要检查是否被排除
607
+ if (limitedData.filter === 1 && (_limitedData$exclude_ = limitedData.exclude_product_ids) !== null && _limitedData$exclude_ !== void 0 && _limitedData$exclude_.includes(product.id)) {
608
+ isLimitedProduct = false;
609
+ } else {
610
+ isLimitedProduct = true;
611
+ }
612
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
613
+ isLimitedProduct = true;
614
+ }
615
+
616
+ // 套餐规则检查
617
+ var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
618
+ return isLimitedProduct && isBundleAvailable;
619
+ };
620
+
621
+ // 收集所有被勾选的 order_level 折扣卡及其适用商品
622
+ var selectedOrderLevelDiscounts = sortedDiscountList.filter(function (discount) {
623
+ return isOrderLevelFixedAmountDiscount(discount) && discount.isSelected !== false;
624
+ });
625
+
626
+ // 遍历所有被勾选的 order_level 折扣卡,建立双向映射
627
+ selectedOrderLevelDiscounts.forEach(function (discount) {
628
+ var applicableItemIds = new Set();
629
+ sortedFlattenedList.forEach(function (flatItem) {
630
+ if (checkItemApplicableForDiscount(flatItem, discount)) {
631
+ applicableItemIds.add(flatItem._id);
632
+
633
+ // 记录商品可以被哪些折扣卡使用
634
+ if (!itemApplicableDiscounts.has(flatItem._id)) {
635
+ itemApplicableDiscounts.set(flatItem._id, new Set());
636
+ }
637
+ itemApplicableDiscounts.get(flatItem._id).add(discount.id);
638
+ }
639
+ });
640
+ orderLevelDiscountApplicableItems.set(discount.id, applicableItemIds);
641
+ });
642
+
643
+ // 专属折扣卡定义:限定了特定商品(product_ids),而不是全品类(product_all)的折扣卡
644
+ // 如果专属折扣卡被勾选,它适用的商品会被占用,其他折扣卡均摊时应排除这些商品
645
+ // Map<flatItemId, discountId> - 记录被占用的商品及其对应的折扣卡
646
+ var occupiedItems = new Map();
647
+
648
+ // 按排序顺序遍历折扣卡,判断哪些是专属折扣卡
649
+ selectedOrderLevelDiscounts.forEach(function (discount) {
650
+ var limitedData = discount.limited_relation_product_data;
651
+
652
+ // 判断是否是专属折扣卡(只能用于特定商品,而不是全品类)
653
+ var isExclusiveDiscount = limitedData.type !== 'product_all';
654
+ if (isExclusiveDiscount) {
655
+ // 专属折扣卡:它适用的所有商品都会被它占用
656
+ var applicableItems = orderLevelDiscountApplicableItems.get(discount.id);
657
+ if (applicableItems) {
658
+ applicableItems.forEach(function (itemId) {
659
+ // 如果商品还没被占用,则标记为被当前折扣卡占用
660
+ if (!occupiedItems.has(itemId)) {
661
+ occupiedItems.set(itemId, discount.id);
662
+ }
663
+ });
664
+ }
665
+ }
666
+ });
667
+ console.log('occupiedItems', occupiedItems, 'orderLevelDiscountApplicableItems', orderLevelDiscountApplicableItems);
668
+
669
+ // 🔥 第三步:识别 order_level 折扣卡并预计算分摊(排除被其他专属折扣卡占用的商品)
531
670
  sortedDiscountList.forEach(function (discount) {
532
671
  if (!isOrderLevelFixedAmountDiscount(discount)) {
533
672
  return;
534
673
  }
535
674
 
536
- // 收集该折扣卡适用的商品
675
+ // 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
537
676
  var applicableProducts = [];
538
677
  sortedFlattenedList.forEach(function (flatItem) {
539
- var _product, _product2, _product3, _flatItem$bundleItem, _product4;
678
+ var _flatItem$parentProdu2;
679
+ // 🔥 检查该商品是否被其他专属折扣卡占用
680
+ var occupyingDiscountId = occupiedItems.get(flatItem._id);
681
+ if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
682
+ // 该商品被其他专属折扣卡占用,跳过
683
+ return;
684
+ }
685
+ if (!checkItemApplicableForDiscount(flatItem, discount)) {
686
+ return;
687
+ }
540
688
  var product;
541
689
  if (flatItem.type === 'main') {
542
690
  product = flatItem.product;
543
691
  } else {
544
- var _flatItem$parentProdu;
545
692
  product = {
546
693
  _id: flatItem._id,
547
694
  id: flatItem.id,
548
695
  price: flatItem.price,
549
696
  quantity: flatItem.quantity,
550
- num: flatItem.num,
551
- booking_id: flatItem.booking_id,
552
- discount_list: flatItem.discount_list || [],
553
- startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
697
+ num: flatItem.num
554
698
  };
555
699
  }
556
700
 
557
- // 编辑的商品使用了优惠券不可用
558
- 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 (discount) {
559
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
560
- })) : !(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);
561
- if (!isAvailableProduct) {
562
- return;
563
- }
701
+ // 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
702
+ 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);
564
703
 
565
- // 商品价格为0时不可用
566
- if (Number(product.price) <= 0 || !product.price) {
567
- return;
568
- }
569
- var limitedData = discount.limited_relation_product_data;
570
-
571
- // 时间限制检查
572
- var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
573
- if (!timeLimit) {
574
- return;
575
- }
576
-
577
- // 判断商品是否适用
578
- var isLimitedProduct = limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id);
579
-
580
- // 套餐规则检查
581
- var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
582
- if (isLimitedProduct && isBundleAvailable) {
583
- var _flatItem$parentProdu2;
584
- // 🔥 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
585
- 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);
586
-
587
- // 🔥 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
588
- var productData = {
589
- productId: flatItem._id,
590
- amount: Number(product.price || 0),
591
- quantity: quantity
592
- };
704
+ // 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
705
+ var productData = {
706
+ productId: flatItem._id,
707
+ amount: Number(product.price || 0),
708
+ quantity: quantity
709
+ };
593
710
 
594
- // 子商品需要传递主商品数量
595
- if (flatItem.type === 'bundle') {
596
- var _flatItem$parentProdu3;
597
- productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
598
- }
599
- applicableProducts.push(productData);
711
+ // 子商品需要传递主商品数量
712
+ if (flatItem.type === 'bundle') {
713
+ var _flatItem$parentProdu3;
714
+ productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
600
715
  }
716
+ applicableProducts.push(productData);
601
717
  });
602
718
 
603
719
  // 计算分摊
@@ -639,7 +755,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
639
755
  originProduct = flatItem.originProduct;
640
756
  }
641
757
  addModeDiscount.forEach(function (discount) {
642
- var _product5, _product6, _product7, _product8, _flatItem$bundleItem2, _discount$config;
758
+ var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
643
759
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
644
760
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
645
761
  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;
@@ -655,14 +771,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
655
771
  // 编辑的商品 使用了优惠券不可用
656
772
  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) {
657
773
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
658
- })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.metadata) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.custom_product_bundle_map_id);
774
+ })) : !(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) {
775
+ return discount.id;
776
+ }));
659
777
 
660
778
  // 套餐是否可用判断
661
779
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
662
780
 
663
781
  // 判断优惠券是否适用于该商品
664
782
  if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
665
- var _discountApplicabilit, _discount$metadata4;
783
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
666
784
  // 记录此优惠券适用的商品
667
785
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
668
786
 
@@ -680,6 +798,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
680
798
  discount: {
681
799
  discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
682
800
  fixed_amount: product.price,
801
+ discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
683
802
  resource_id: discount.id,
684
803
  title: discount.format_title,
685
804
  original_amount: product.price || product.origin_total,
@@ -710,7 +829,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
710
829
  product = flatItem.product;
711
830
  originProduct = flatItem.originProduct;
712
831
  } else {
713
- var _flatItem$parentProdu5, _flatItem$bundleItem3, _flatItem$bundleItem4, _flatItem$bundleItem5;
832
+ var _flatItem$parentProdu5, _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7;
714
833
  // bundle子商品
715
834
  product = {
716
835
  startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
@@ -720,10 +839,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
720
839
  quantity: flatItem.quantity,
721
840
  num: flatItem.num,
722
841
  total: flatItem.total,
723
- original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem3 = flatItem.bundleItem) === null || _flatItem$bundleItem3 === void 0 ? void 0 : _flatItem$bundleItem3.original_price,
724
- origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem4 = flatItem.bundleItem) === null || _flatItem$bundleItem4 === void 0 ? void 0 : _flatItem$bundleItem4.original_price,
842
+ original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
843
+ origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
725
844
  booking_id: flatItem.booking_id,
726
- discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.discount_list) || []
845
+ discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || []
727
846
  };
728
847
  originProduct = flatItem.originProduct;
729
848
  }
@@ -986,7 +1105,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
986
1105
  }));
987
1106
  }
988
1107
  for (var i = 0; i < splitCount; i++) {
989
- var _product$discount_lis10, _originProduct, _selectedDiscount$met;
1108
+ var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
990
1109
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
991
1110
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
992
1111
  // 标记优惠券为已使用
@@ -1040,6 +1159,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1040
1159
  discount: {
1041
1160
  discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
1042
1161
  fixed_amount: actualDiscountAmount,
1162
+ discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
1043
1163
  resource_id: _selectedDiscount.id,
1044
1164
  title: _selectedDiscount.format_title,
1045
1165
  original_amount: product.price,
@@ -1109,6 +1229,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1109
1229
 
1110
1230
  // 生成有折扣的商品(每张商品券对应 num: 1)
1111
1231
  for (var _i = 0; _i < discountNum; _i++) {
1232
+ var _selectedDiscount2$me;
1112
1233
  var _selectedDiscount2 = applicableDiscounts[_i];
1113
1234
  usedDiscounts.set(_selectedDiscount2.id, true);
1114
1235
  // 🔥 更新 product_id 使用计数
@@ -1128,6 +1249,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1128
1249
  type: 'good_pass',
1129
1250
  discount: {
1130
1251
  fixed_amount: product.origin_total,
1252
+ discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
1131
1253
  resource_id: _selectedDiscount2.id,
1132
1254
  title: _selectedDiscount2.format_title,
1133
1255
  original_amount: product.origin_total,
@@ -1173,7 +1295,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1173
1295
  }));
1174
1296
  }
1175
1297
  } else {
1176
- var _selectedDiscount3$me, _flatItem$parentProdu8;
1298
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu8;
1177
1299
  // 折扣卡:不拆分数量,直接应用
1178
1300
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1179
1301
  usedDiscounts.set(_selectedDiscount3.id, true);
@@ -1201,7 +1323,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1201
1323
  _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1202
1324
  fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1203
1325
  }
1204
-
1326
+ debugger;
1205
1327
  // 🔥 使用当前的 _id 作为唯一标识
1206
1328
  var _uniqueId = flatItem._id;
1207
1329
  var _discountDetail2 = {
@@ -1210,6 +1332,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1210
1332
  discount: {
1211
1333
  discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
1212
1334
  fixed_amount: fixedAmountPerItem,
1335
+ discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
1213
1336
  resource_id: _selectedDiscount3.id,
1214
1337
  title: _selectedDiscount3.format_title,
1215
1338
  original_amount: product.original_price,
@@ -1393,8 +1516,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1393
1516
 
1394
1517
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
1395
1518
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
1396
- var _discount$metadata5, _discount$metadata6;
1397
- if (discount !== null && discount !== void 0 && (_discount$metadata5 = discount.metadata) !== null && _discount$metadata5 !== void 0 && _discount$metadata5.custom_product_bundle_map_id) {
1519
+ var _discount$metadata6, _discount$metadata7;
1520
+ if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
1398
1521
  // bundle的discount_list保持不变
1399
1522
  return discount;
1400
1523
  }
@@ -1402,7 +1525,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1402
1525
  return _objectSpread(_objectSpread({}, discount), {}, {
1403
1526
  // num: 1,
1404
1527
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1405
- 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,
1528
+ 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,
1406
1529
  num: 1
1407
1530
  })
1408
1531
  });
@@ -1467,8 +1590,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1467
1590
 
1468
1591
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1469
1592
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
1470
- var _discount$metadata7, _discount$metadata8;
1471
- if (discount !== null && discount !== void 0 && (_discount$metadata7 = discount.metadata) !== null && _discount$metadata7 !== void 0 && _discount$metadata7.custom_product_bundle_map_id) {
1593
+ var _discount$metadata8, _discount$metadata9;
1594
+ if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
1472
1595
  // bundle的discount_list保持不变
1473
1596
  return discount;
1474
1597
  }
@@ -1476,7 +1599,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1476
1599
  return _objectSpread(_objectSpread({}, discount), {}, {
1477
1600
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1478
1601
  num: mainProductQuantity - 1,
1479
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata8 = discount.metadata) === null || _discount$metadata8 === void 0 ? void 0 : _discount$metadata8.custom_product_bundle_map_id
1602
+ 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
1480
1603
  })
1481
1604
  // num: mainProductQuantity - 1,
1482
1605
  });
@@ -1541,11 +1664,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1541
1664
  processedBundleItems.forEach(function (item) {
1542
1665
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1543
1666
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1544
- var _discount$metadata9;
1667
+ var _discount$metadata10;
1545
1668
  return _objectSpread(_objectSpread({}, discount), {}, {
1546
1669
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1547
1670
  num: item.num,
1548
- 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
1671
+ 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
1549
1672
  })
1550
1673
  // num: item.num, // 使用拆分后的 num
1551
1674
  });
@@ -1729,10 +1852,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1729
1852
  return true; // 单独购买时可用
1730
1853
  }
1731
1854
  if (isBundleItem) {
1732
- var _flatItem$bundleItem6, _flatItem$bundleItem7;
1855
+ var _flatItem$bundleItem8, _flatItem$bundleItem9;
1733
1856
  // 套餐中购买时,判断是否为原价
1734
- var priceType = (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.price_type;
1735
- var priceTypeExt = (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.price_type_ext;
1857
+ var priceType = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type;
1858
+ var priceTypeExt = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type_ext;
1736
1859
  // original_price 对应:
1737
1860
  // 1. price_type: "markup" && price_type_ext: "product_price"
1738
1861
  // markup_price 对应:
@@ -1770,10 +1893,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1770
1893
  return false; // 单独购买时不可用
1771
1894
  }
1772
1895
  if (isBundleItem) {
1773
- var _flatItem$bundleItem8, _flatItem$bundleItem9;
1896
+ var _flatItem$bundleItem10, _flatItem$bundleItem11;
1774
1897
  // 套餐中购买时,判断是否为原价
1775
- var _priceType = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type;
1776
- var _priceTypeExt = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type_ext;
1898
+ var _priceType = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type;
1899
+ var _priceTypeExt = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type_ext;
1777
1900
 
1778
1901
  // original_price 对应:
1779
1902
  // 1. price_type: "markup" && price_type_ext: "product_price"
@@ -308,7 +308,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
308
308
  date: string;
309
309
  status: string;
310
310
  week: string;
311
- weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
311
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
312
312
  }[]>;
313
313
  submitTimeSlot(timeSlots: TimeSliceItem): void;
314
314
  private getScheduleDataByIds;
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -52,7 +52,8 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
52
52
 
53
53
  // 固定金额 小于0时返回0
54
54
  if (isFixedAmount) {
55
- discountedPrice = Math.max(new Decimal(price).minus(new Decimal(discount.amount || 0)).toNumber(), 0);
55
+ var _discount$amount;
56
+ discountedPrice = Math.max(new Decimal(price).minus(new Decimal(((_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.par_value) || 0)).toNumber(), 0);
56
57
  } else {
57
58
  // 百分比:根据折扣卡金额计算
58
59
  discountedPrice = new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
@@ -98,7 +98,9 @@ export interface Discount {
98
98
  isEditMode?: boolean;
99
99
  isScan?: boolean;
100
100
  discount?: {
101
+ discount_product_id: number;
101
102
  resource_id: number;
103
+ discount_calculation_mode: 'item_level' | 'order_level';
102
104
  };
103
105
  isManualSelect?: boolean;
104
106
  isDisabled?: boolean;
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -164,6 +164,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
164
164
  addModeDiscount.push(discount);
165
165
  }
166
166
  });
167
+ const editModeOrderLevelProductIds = /* @__PURE__ */ new Set();
168
+ editModeDiscount.forEach((discount) => {
169
+ var _a, _b;
170
+ if (((_a = discount.discount) == null ? void 0 : _a.discount_calculation_mode) === "order_level") {
171
+ editModeOrderLevelProductIds.add((_b = discount == null ? void 0 : discount.discount) == null ? void 0 : _b.discount_product_id);
172
+ }
173
+ });
174
+ if (editModeOrderLevelProductIds.size > 0) {
175
+ addModeDiscount.forEach((discount) => {
176
+ if (editModeOrderLevelProductIds.has(discount.product_id)) {
177
+ discount.isDisabled = true;
178
+ }
179
+ });
180
+ }
167
181
  const filteredDiscountList = addModeDiscount.filter((discount) => {
168
182
  return !discount.isManualSelect;
169
183
  });
@@ -367,13 +381,99 @@ var RulesModule = class extends import_BaseModule.BaseModule {
367
381
  discountApplicableProducts.set(discount.id, []);
368
382
  });
369
383
  const orderLevelDiscountAllocations = /* @__PURE__ */ new Map();
384
+ const orderLevelDiscountApplicableItems = /* @__PURE__ */ new Map();
385
+ const itemApplicableDiscounts = /* @__PURE__ */ new Map();
386
+ const checkItemApplicableForDiscount = (flatItem, discount) => {
387
+ var _a, _b, _c, _d, _e, _f, _g, _h;
388
+ let product;
389
+ if (flatItem.type === "main") {
390
+ product = flatItem.product;
391
+ } else {
392
+ product = {
393
+ _id: flatItem._id,
394
+ id: flatItem.id,
395
+ price: flatItem.price,
396
+ quantity: flatItem.quantity,
397
+ num: flatItem.num,
398
+ booking_id: flatItem.booking_id,
399
+ discount_list: flatItem.discount_list || [],
400
+ startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
401
+ };
402
+ }
403
+ const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.length) && ((_c = product == null ? void 0 : product.discount_list) == null ? void 0 : _c.every((d) => d.id && ["good_pass", "discount_card", "product_discount_card"].includes(d.tag || d.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_e = (_d = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _d.discount_list) == null ? void 0 : _e.length) && ((_g = (_f = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _f.discount_list) == null ? void 0 : _g.every((d) => d.id)));
404
+ if (!isAvailableProduct) {
405
+ return false;
406
+ }
407
+ if ((0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
408
+ return false;
409
+ }
410
+ if (Number(product.price) <= 0 || !product.price) {
411
+ return false;
412
+ }
413
+ const limitedData = discount.limited_relation_product_data;
414
+ const timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
415
+ if (!timeLimit) {
416
+ return false;
417
+ }
418
+ let isLimitedProduct = false;
419
+ if (limitedData.type === "product_all") {
420
+ if (limitedData.filter === 1 && ((_h = limitedData.exclude_product_ids) == null ? void 0 : _h.includes(product.id))) {
421
+ isLimitedProduct = false;
422
+ } else {
423
+ isLimitedProduct = true;
424
+ }
425
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
426
+ isLimitedProduct = true;
427
+ }
428
+ const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
429
+ return isLimitedProduct && isBundleAvailable;
430
+ };
431
+ const selectedOrderLevelDiscounts = sortedDiscountList.filter((discount) => {
432
+ return (0, import_utils.isOrderLevelFixedAmountDiscount)(discount) && discount.isSelected !== false;
433
+ });
434
+ selectedOrderLevelDiscounts.forEach((discount) => {
435
+ const applicableItemIds = /* @__PURE__ */ new Set();
436
+ sortedFlattenedList.forEach((flatItem) => {
437
+ if (checkItemApplicableForDiscount(flatItem, discount)) {
438
+ applicableItemIds.add(flatItem._id);
439
+ if (!itemApplicableDiscounts.has(flatItem._id)) {
440
+ itemApplicableDiscounts.set(flatItem._id, /* @__PURE__ */ new Set());
441
+ }
442
+ itemApplicableDiscounts.get(flatItem._id).add(discount.id);
443
+ }
444
+ });
445
+ orderLevelDiscountApplicableItems.set(discount.id, applicableItemIds);
446
+ });
447
+ const occupiedItems = /* @__PURE__ */ new Map();
448
+ selectedOrderLevelDiscounts.forEach((discount) => {
449
+ const limitedData = discount.limited_relation_product_data;
450
+ const isExclusiveDiscount = limitedData.type !== "product_all";
451
+ if (isExclusiveDiscount) {
452
+ const applicableItems = orderLevelDiscountApplicableItems.get(discount.id);
453
+ if (applicableItems) {
454
+ applicableItems.forEach((itemId) => {
455
+ if (!occupiedItems.has(itemId)) {
456
+ occupiedItems.set(itemId, discount.id);
457
+ }
458
+ });
459
+ }
460
+ }
461
+ });
462
+ console.log("occupiedItems", occupiedItems, "orderLevelDiscountApplicableItems", orderLevelDiscountApplicableItems);
370
463
  sortedDiscountList.forEach((discount) => {
371
464
  if (!(0, import_utils.isOrderLevelFixedAmountDiscount)(discount)) {
372
465
  return;
373
466
  }
374
467
  const applicableProducts = [];
375
468
  sortedFlattenedList.forEach((flatItem) => {
376
- var _a, _b, _c, _d, _e, _f, _g;
469
+ var _a, _b;
470
+ const occupyingDiscountId = occupiedItems.get(flatItem._id);
471
+ if (occupyingDiscountId !== void 0 && occupyingDiscountId !== discount.id) {
472
+ return;
473
+ }
474
+ if (!checkItemApplicableForDiscount(flatItem, discount)) {
475
+ return;
476
+ }
377
477
  let product;
378
478
  if (flatItem.type === "main") {
379
479
  product = flatItem.product;
@@ -383,38 +483,19 @@ var RulesModule = class extends import_BaseModule.BaseModule {
383
483
  id: flatItem.id,
384
484
  price: flatItem.price,
385
485
  quantity: flatItem.quantity,
386
- num: flatItem.num,
387
- booking_id: flatItem.booking_id,
388
- discount_list: flatItem.discount_list || [],
389
- startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
486
+ num: flatItem.num
390
487
  };
391
488
  }
392
- const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.length) && ((_c = product == null ? void 0 : product.discount_list) == null ? void 0 : _c.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_e = (_d = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _d.metadata) == null ? void 0 : _e.custom_product_bundle_map_id));
393
- if (!isAvailableProduct) {
394
- return;
395
- }
396
- if (Number(product.price) <= 0 || !product.price) {
397
- return;
398
- }
399
- const limitedData = discount.limited_relation_product_data;
400
- const timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
401
- if (!timeLimit) {
402
- return;
403
- }
404
- const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
405
- const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
406
- if (isLimitedProduct && isBundleAvailable) {
407
- const quantity = flatItem.type === "main" ? product.quantity || 1 : (product.num || 1) * (((_f = flatItem.parentProduct) == null ? void 0 : _f.quantity) || 1);
408
- const productData = {
409
- productId: flatItem._id,
410
- amount: Number(product.price || 0),
411
- quantity
412
- };
413
- if (flatItem.type === "bundle") {
414
- productData.parentQuantity = ((_g = flatItem.parentProduct) == null ? void 0 : _g.quantity) || 1;
415
- }
416
- applicableProducts.push(productData);
489
+ const quantity = flatItem.type === "main" ? product.quantity || 1 : (product.num || 1) * (((_a = flatItem.parentProduct) == null ? void 0 : _a.quantity) || 1);
490
+ const productData = {
491
+ productId: flatItem._id,
492
+ amount: Number(product.price || 0),
493
+ quantity
494
+ };
495
+ if (flatItem.type === "bundle") {
496
+ productData.parentQuantity = ((_b = flatItem.parentProduct) == null ? void 0 : _b.quantity) || 1;
417
497
  }
498
+ applicableProducts.push(productData);
418
499
  });
419
500
  if (applicableProducts.length > 0) {
420
501
  const allocation = (0, import_utils.calculateOrderLevelDiscountAllocation)(discount, applicableProducts);
@@ -445,7 +526,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
445
526
  originProduct = flatItem.originProduct;
446
527
  }
447
528
  addModeDiscount.forEach((discount) => {
448
- var _a2, _b, _c, _d, _e, _f, _g;
529
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
449
530
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
450
531
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
451
532
  const isHolderMatch = this.checkHolderMatch(
@@ -465,10 +546,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
465
546
  "discount_card",
466
547
  "product_discount_card"
467
548
  ].includes(discount2.tag || discount2.type)
468
- ))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
549
+ ))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) == null ? void 0 : _d.length) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.every((discount2) => discount2.id)));
469
550
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
470
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_e = discount.config) == null ? void 0 : _e.isAvailable)) {
471
- (_f = discountApplicability.get(discount.id)) == null ? void 0 : _f.push(product.id);
551
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_g = discount.config) == null ? void 0 : _g.isAvailable)) {
552
+ (_h = discountApplicability.get(discount.id)) == null ? void 0 : _h.push(product.id);
472
553
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
473
554
  const discountType = discount.tag || discount.type;
474
555
  const isGoodPass = discountType === "good_pass";
@@ -478,8 +559,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
478
559
  type: discountType,
479
560
  tag: discountType,
480
561
  discount: {
481
- discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
562
+ discount_card_type: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_card_type,
482
563
  fixed_amount: product.price,
564
+ discount_calculation_mode: (_j = discount == null ? void 0 : discount.metadata) == null ? void 0 : _j.discount_calculation_mode,
483
565
  resource_id: discount.id,
484
566
  title: discount.format_title,
485
567
  original_amount: product.price || product.origin_total,
@@ -498,7 +580,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
498
580
  });
499
581
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
500
582
  sortedFlattenedList.forEach((flatItem, index) => {
501
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
583
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
502
584
  let product, originProduct;
503
585
  if (flatItem.type === "main") {
504
586
  product = flatItem.product;
@@ -811,6 +893,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
811
893
  discount: {
812
894
  discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
813
895
  fixed_amount: actualDiscountAmount,
896
+ discount_calculation_mode: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_calculation_mode,
814
897
  resource_id: selectedDiscount2.id,
815
898
  title: selectedDiscount2.format_title,
816
899
  original_amount: product.price,
@@ -891,6 +974,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
891
974
  type: "good_pass",
892
975
  discount: {
893
976
  fixed_amount: product.origin_total,
977
+ discount_calculation_mode: (_y = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _y.discount_calculation_mode,
894
978
  resource_id: selectedDiscount2.id,
895
979
  title: selectedDiscount2.format_title,
896
980
  original_amount: product.origin_total,
@@ -959,13 +1043,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
959
1043
  );
960
1044
  fixedAmountPerItem = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
961
1045
  }
1046
+ debugger;
962
1047
  const uniqueId = flatItem._id;
963
1048
  const discountDetail = {
964
1049
  amount: fixedAmountPerItem * (product.num || 1),
965
1050
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
966
1051
  discount: {
967
- discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
1052
+ discount_card_type: (_z = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _z.discount_card_type,
968
1053
  fixed_amount: fixedAmountPerItem,
1054
+ discount_calculation_mode: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_calculation_mode,
969
1055
  resource_id: selectedDiscount2.id,
970
1056
  title: selectedDiscount2.format_title,
971
1057
  original_amount: product.original_price,
@@ -981,7 +1067,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
981
1067
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
982
1068
  },
983
1069
  config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
984
- _num: (product.num || 1) * (((_y = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _y.num) || 1)
1070
+ _num: (product.num || 1) * (((_B = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _B.num) || 1)
985
1071
  };
986
1072
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
987
1073
  appliedProducts.push(discountDetail);
@@ -308,7 +308,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
308
308
  date: string;
309
309
  status: string;
310
310
  week: string;
311
- weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
311
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
312
312
  }[]>;
313
313
  submitTimeSlot(timeSlots: TimeSliceItem): void;
314
314
  private getScheduleDataByIds;
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -62,7 +62,7 @@ var getDiscountAmount = (discount, total, price) => {
62
62
  } else {
63
63
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
64
64
  if (isFixedAmount) {
65
- discountedPrice = Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.amount || 0)).toNumber(), 0);
65
+ discountedPrice = Math.max(new import_decimal.default(price).minus(new import_decimal.default((discount.amount ?? discount.par_value) || 0)).toNumber(), 0);
66
66
  } else {
67
67
  discountedPrice = new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
68
68
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.395",
4
+ "version": "0.0.397",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",