@pisell/pisellos 0.0.350 → 0.0.351

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.
@@ -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
  }
@@ -451,7 +451,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
451
451
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
452
452
  // 🔥 使用扁平化后的列表进行处理
453
453
  sortedFlattenedList.forEach(function (flatItem, index) {
454
- var _product4, _product$discount_lis2, _product5, _product$discount_lis4, _product6, _product6$every, _product$discount_lis5, _product$discount_lis6;
454
+ var _product4, _product$discount_lis2, _product5;
455
455
  // 获取商品数据
456
456
  var product, originProduct;
457
457
  if (flatItem.type === 'main') {
@@ -532,28 +532,85 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
532
532
  var selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
533
533
 
534
534
  // 如果是手动折扣,则不适用优惠券
535
- var isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && flatItem.type === 'main' && (product.bundle || []).every(function (item) {
536
- var _ref3;
537
- return !((_ref3 = item.discount_list || []) !== null && _ref3 !== void 0 && _ref3.length);
538
- }) && (!((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length) || ((_product6 = product) === null || _product6 === void 0 || (_product6 = _product6.discount_list) === null || _product6 === void 0 || (_product6$every = _product6.every) === null || _product6$every === void 0 ? void 0 : _product6$every.call(_product6, function (item) {
539
- return item.type === 'product';
540
- })));
535
+ var isManualDiscount = false;
536
+ if (flatItem.type === 'main') {
537
+ var _product$discount_lis4, _product6, _product6$every;
538
+ // 主商品:判断自身是否手动折扣
539
+ isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
540
+ var _ref3;
541
+ return !((_ref3 = item.discount_list || []) !== null && _ref3 !== void 0 && _ref3.length);
542
+ }) && (!((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length) || ((_product6 = product) === null || _product6 === void 0 || (_product6 = _product6.discount_list) === null || _product6 === void 0 || (_product6$every = _product6.every) === null || _product6$every === void 0 ? void 0 : _product6$every.call(_product6, function (item) {
543
+ return item.type === 'product';
544
+ })));
545
+ } else {
546
+ // bundle子商品:判断父主商品是否手动折扣
547
+ var parentProduct = flatItem.parentProduct;
548
+ if (parentProduct) {
549
+ var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
550
+ isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
551
+ var _ref4;
552
+ return !((_ref4 = item.discount_list || []) !== null && _ref4 !== void 0 && _ref4.length);
553
+ }) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
554
+ return item.type === 'product';
555
+ })));
556
+ }
557
+ }
541
558
 
542
559
  // 勾选时覆盖手动折扣
543
- if (options !== null && options !== void 0 && options.discountId && (_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.some(function (item) {
544
- var _item$discount;
545
- return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
546
- })) {
547
- isManualDiscount = false;
560
+ if (options !== null && options !== void 0 && options.discountId) {
561
+ var _product$discount_lis5;
562
+ // 主商品:检查自己的 discount_list
563
+ if (flatItem.type === 'main' && (_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.some(function (item) {
564
+ var _item$discount;
565
+ return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
566
+ })) {
567
+ isManualDiscount = false;
568
+ }
569
+ // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
570
+ if (flatItem.type === 'bundle') {
571
+ var _product$discount_lis6, _flatItem$parentProdu;
572
+ if ((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.some(function (item) {
573
+ var _item$discount2;
574
+ return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
575
+ }) || (_flatItem$parentProdu = flatItem.parentProduct) !== null && _flatItem$parentProdu !== void 0 && (_flatItem$parentProdu = _flatItem$parentProdu.discount_list) !== null && _flatItem$parentProdu !== void 0 && _flatItem$parentProdu.some(function (item) {
576
+ var _item$discount3;
577
+ return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
578
+ })) {
579
+ isManualDiscount = false;
580
+ }
581
+ }
548
582
  }
549
- if (options !== null && options !== void 0 && options.selectedList && (_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.some(function (item) {
550
- var _options$selectedList;
551
- return options === null || options === void 0 || (_options$selectedList = options.selectedList) === null || _options$selectedList === void 0 ? void 0 : _options$selectedList.some(function (n) {
552
- var _item$discount2;
553
- return n.discountId === ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id);
554
- });
555
- })) {
556
- isManualDiscount = false;
583
+ if (options !== null && options !== void 0 && options.selectedList) {
584
+ var _product$discount_lis7;
585
+ // 主商品:检查自己的 discount_list
586
+ if (flatItem.type === 'main' && (_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
587
+ var _options$selectedList;
588
+ return options === null || options === void 0 || (_options$selectedList = options.selectedList) === null || _options$selectedList === void 0 ? void 0 : _options$selectedList.some(function (n) {
589
+ var _item$discount4;
590
+ return n.discountId === ((_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.resource_id);
591
+ });
592
+ })) {
593
+ isManualDiscount = false;
594
+ }
595
+ // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
596
+ if (flatItem.type === 'bundle') {
597
+ var _product$discount_lis8, _flatItem$parentProdu2;
598
+ if ((_product$discount_lis8 = product.discount_list) !== null && _product$discount_lis8 !== void 0 && _product$discount_lis8.some(function (item) {
599
+ var _options$selectedList2;
600
+ return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
601
+ var _item$discount5;
602
+ return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
603
+ });
604
+ }) || (_flatItem$parentProdu2 = flatItem.parentProduct) !== null && _flatItem$parentProdu2 !== void 0 && (_flatItem$parentProdu2 = _flatItem$parentProdu2.discount_list) !== null && _flatItem$parentProdu2 !== void 0 && _flatItem$parentProdu2.some(function (item) {
605
+ var _options$selectedList3;
606
+ return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
607
+ var _item$discount6;
608
+ return n.discountId === ((_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.resource_id);
609
+ });
610
+ })) {
611
+ isManualDiscount = false;
612
+ }
613
+ }
557
614
  }
558
615
 
559
616
  // 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
@@ -586,7 +643,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
586
643
  processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
587
644
  _id: product._id.split('___')[0] + '___' + index,
588
645
  total: product.origin_total || product.total,
589
- price: product.price
646
+ price: product.price,
647
+ main_product_selling_price: product.price
590
648
  }), {}, {
591
649
  discount_list: []
592
650
  }))]);
@@ -627,7 +685,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
627
685
  }));
628
686
  }
629
687
  for (var i = 0; i < splitCount; i++) {
630
- var _product$discount_lis7, _originProduct, _selectedDiscount$met;
688
+ var _product$discount_lis9, _originProduct, _selectedDiscount$met;
631
689
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
632
690
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
633
691
  // 标记优惠券为已使用
@@ -639,7 +697,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
639
697
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
640
698
  var productOriginTotal = product.origin_total || product.total || 0;
641
699
  // 如果当前 product 有 discount_list,则先从 origin_total 拿
642
- if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.length && product.origin_total) {
700
+ if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.length && product.origin_total) {
643
701
  productOriginTotal = product.origin_total;
644
702
  }
645
703
  // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
@@ -696,7 +754,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
696
754
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
697
755
  quantity: isNeedSplit ? 1 : product.quantity,
698
756
  total: targetProductTotal,
699
- origin_total: productOriginTotal
757
+ origin_total: productOriginTotal,
758
+ main_product_selling_price: targetProductTotal
700
759
  }));
701
760
  }
702
761
  }
@@ -854,6 +913,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
854
913
 
855
914
  // 检查是否有bundle子商品需要重组
856
915
  var hasBundle = product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0;
916
+ debugger;
857
917
  if (!hasBundle) {
858
918
  // 没有bundle,直接使用主商品处理结果
859
919
  result.push.apply(result, _toConsumableArray(mainProductArr));
@@ -944,16 +1004,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
944
1004
  // 计算第一个主商品的总价(包含拆分后的bundle)
945
1005
  var newTotalWithDiscount = Number(mainProductData.price || 0);
946
1006
  var newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
947
- if (newBundleWithDiscount.length > 0) {
948
- newBundleWithDiscount.forEach(function (item) {
949
- newTotalWithDiscount += Number(item.price) * Number(item.num);
950
- });
951
- newBundleWithDiscount.forEach(function (item) {
952
- var _item$discount_list2;
953
- var originalPrice = ((_item$discount_list2 = item.discount_list) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2[0]) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2.discount) === null || _item$discount_list2 === void 0 ? void 0 : _item$discount_list2.original_amount) || item.price;
954
- newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
955
- });
956
- }
957
1007
 
958
1008
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
959
1009
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
@@ -977,14 +1027,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
977
1027
  var allDiscountAmount = getDiscountListAmountTotal(mainDiscountList);
978
1028
  newTotalWithDiscount = new Decimal(mainProductData.price || 0).minus(allDiscountAmount).toNumber() || newTotalWithDiscount;
979
1029
  newOriginTotalWithDiscount = mainProductData.origin_total || newOriginTotalWithDiscount;
980
- if (newBundleWithDiscount.length > 0) {
981
- newBundleWithDiscount.forEach(function (item) {
982
- var _item$discount_list3;
983
- newTotalWithDiscount += Number(item.price) * Number(item.num);
984
- var originalPrice = ((_item$discount_list3 = item.discount_list) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3[0]) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3.discount) === null || _item$discount_list3 === void 0 ? void 0 : _item$discount_list3.original_amount) || item.price;
985
- newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
986
- });
987
- }
1030
+ }
1031
+
1032
+ // 累加bundle的价格(只累加一次)
1033
+ if (newBundleWithDiscount.length > 0) {
1034
+ newBundleWithDiscount.forEach(function (item) {
1035
+ newTotalWithDiscount += Number(item.price) * Number(item.num);
1036
+ });
1037
+ newBundleWithDiscount.forEach(function (item) {
1038
+ var _item$discount_list2;
1039
+ var originalPrice = ((_item$discount_list2 = item.discount_list) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2[0]) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2.discount) === null || _item$discount_list2 === void 0 ? void 0 : _item$discount_list2.original_amount) || item.price;
1040
+ newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
1041
+ });
988
1042
  }
989
1043
 
990
1044
  // 添加第一个主商品:qty=1,包含拆分后的bundle
@@ -1010,12 +1064,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1010
1064
  // 计算第二个主商品的总价
1011
1065
  var newTotalOriginal = Number(mainProductData.price || 0);
1012
1066
  var newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
1013
- if (newBundleOriginal.length > 0) {
1014
- newBundleOriginal.forEach(function (item) {
1015
- newTotalOriginal += Number(item.price) * Number(item.num);
1016
- newOriginTotalOriginal += Number(item.price) * Number(item.num);
1017
- });
1018
- }
1019
1067
 
1020
1068
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1021
1069
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
@@ -1039,12 +1087,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1039
1087
  var _allDiscountAmount = getDiscountListAmount(mainDiscountListOriginal);
1040
1088
  newTotalOriginal = new Decimal(mainProductData.price || 0).minus(_allDiscountAmount).toNumber() || newTotalOriginal;
1041
1089
  newOriginTotalOriginal = mainProductData.origin_total || newOriginTotalOriginal;
1042
- if (newBundleOriginal.length > 0) {
1043
- newBundleOriginal.forEach(function (item) {
1044
- newTotalOriginal += Number(item.price) * Number(item.num);
1045
- newOriginTotalOriginal += Number(item.price) * Number(item.num);
1046
- });
1047
- }
1090
+ }
1091
+
1092
+ // 累加bundle的价格(只累加一次)
1093
+ if (newBundleOriginal.length > 0) {
1094
+ newBundleOriginal.forEach(function (item) {
1095
+ newTotalOriginal += Number(item.price) * Number(item.num);
1096
+ newOriginTotalOriginal += Number(item.price) * Number(item.num);
1097
+ });
1048
1098
  }
1049
1099
 
1050
1100
  // 添加第二个主商品:qty=原quantity-1,包含原始bundle
@@ -1060,6 +1110,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1060
1110
  } else {
1061
1111
  // 🔥 没有子商品被拆分,使用原有逻辑
1062
1112
  mainProductArr.forEach(function (mainProduct) {
1113
+ var _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
1063
1114
  var mainProductData = _this3.hooks.getProduct(mainProduct);
1064
1115
 
1065
1116
  // 重组bundle
@@ -1096,36 +1147,39 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1096
1147
  var newTotal = Number(mainProductData.price || 0);
1097
1148
  var newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
1098
1149
 
1099
- // 累加bundle的价格
1100
- if (newBundle.length > 0) {
1101
- newBundle.forEach(function (item) {
1102
- newTotal += Number(item.price) * Number(item.num);
1103
- });
1150
+ // 判断是否是手动折扣
1151
+ var isManualDiscount = typeof mainProductData.isManualDiscount === 'boolean' ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_mainProductData$disc = mainProductData.discount_list) !== null && _mainProductData$disc !== void 0 && _mainProductData$disc.length) || (mainProductData === null || mainProductData === void 0 || (_mainProductData$disc2 = mainProductData.discount_list) === null || _mainProductData$disc2 === void 0 || (_mainProductData$disc3 = _mainProductData$disc2.every) === null || _mainProductData$disc3 === void 0 ? void 0 : _mainProductData$disc3.call(_mainProductData$disc2, function (item) {
1152
+ return item.type === 'product';
1153
+ })));
1104
1154
 
1105
- // 计算原始总价(不考虑折扣)
1106
- newBundle.forEach(function (item) {
1107
- var _item$discount_list4;
1108
- var originalPrice = ((_item$discount_list4 = item.discount_list) === null || _item$discount_list4 === void 0 || (_item$discount_list4 = _item$discount_list4[0]) === null || _item$discount_list4 === void 0 || (_item$discount_list4 = _item$discount_list4.discount) === null || _item$discount_list4 === void 0 ? void 0 : _item$discount_list4.original_amount) || item.price;
1109
- newOriginTotal += Number(originalPrice) * Number(item.num);
1155
+ // 如果是手动折扣,使用原有的total和origin_total,不重新计算
1156
+ if (isManualDiscount) {
1157
+ newTotal = mainProductData.total || newTotal;
1158
+ newOriginTotal = mainProductData.origin_total || newOriginTotal;
1159
+ } else {
1160
+ // 不是手动折扣时,才重新计算
1161
+ var _mainDiscountList = mainProductData.discount_list.filter(function (item) {
1162
+ var _item$metadata3;
1163
+ return !(item !== null && item !== void 0 && (_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.custom_product_bundle_map_id);
1110
1164
  });
1111
- }
1112
- var mainDiscountList = mainProductData.discount_list.filter(function (item) {
1113
- var _item$metadata3;
1114
- return !(item !== null && item !== void 0 && (_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.custom_product_bundle_map_id);
1115
- });
1116
1165
 
1117
- // 如果主商品本身有折扣,需要重新计算
1118
- if (mainDiscountList && mainDiscountList.length > 0) {
1119
- var _allDiscountAmount2 = getDiscountListAmount(mainDiscountList);
1120
- newTotal = new Decimal(mainProductData.price || 0).minus(_allDiscountAmount2).toNumber() || newTotal;
1121
- newOriginTotal = mainProductData.origin_total || newOriginTotal;
1166
+ // 如果主商品本身有折扣,需要重新计算主商品价格
1167
+ if (_mainDiscountList && _mainDiscountList.length > 0) {
1168
+ var _allDiscountAmount2 = getDiscountListAmount(_mainDiscountList);
1169
+ newTotal = new Decimal(mainProductData.price || 0).minus(_allDiscountAmount2).toNumber() || newTotal;
1170
+ newOriginTotal = mainProductData.origin_total || newOriginTotal;
1171
+ }
1122
1172
 
1123
- // 累加bundle的价格
1173
+ // 累加bundle的价格(只累加一次)
1124
1174
  if (newBundle.length > 0) {
1125
1175
  newBundle.forEach(function (item) {
1126
- var _item$discount_list5;
1127
1176
  newTotal += Number(item.price) * Number(item.num);
1128
- var originalPrice = ((_item$discount_list5 = item.discount_list) === null || _item$discount_list5 === void 0 || (_item$discount_list5 = _item$discount_list5[0]) === null || _item$discount_list5 === void 0 || (_item$discount_list5 = _item$discount_list5.discount) === null || _item$discount_list5 === void 0 ? void 0 : _item$discount_list5.original_amount) || item.price;
1177
+ });
1178
+
1179
+ // 计算原始总价(不考虑折扣)
1180
+ newBundle.forEach(function (item) {
1181
+ var _item$discount_list3;
1182
+ var originalPrice = ((_item$discount_list3 = item.discount_list) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3[0]) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3.discount) === null || _item$discount_list3 === void 0 ? void 0 : _item$discount_list3.original_amount) || item.price;
1129
1183
  newOriginTotal += Number(originalPrice) * Number(item.num);
1130
1184
  });
1131
1185
  }
@@ -53,6 +53,7 @@ export interface RulesParamsHooks {
53
53
  original_price?: number | string;
54
54
  quantity?: number;
55
55
  bundle?: any[];
56
+ main_product_selling_price?: string | number;
56
57
  }) => Record<string, any>;
57
58
  }
58
59
  export {};
@@ -388,7 +388,28 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
388
388
  product_id: item.product.product_id,
389
389
  product_variant_id: item.product.product_variant_id,
390
390
  quantity: item.product.num,
391
- selling_price: item.product.calculated_selling_price
391
+ // 整个商品折扣后的总金额
392
+ selling_price: item.product.calculated_selling_price,
393
+ // 整个商品折扣前的总金额
394
+ original_price: item.product.calculated_original_price,
395
+ // 主商品折扣前金额,不包含套餐子商品
396
+ main_product_original_price: item.product.price,
397
+ // 主商品折扣后金额,不包含套餐子商品
398
+ main_product_selling_price: item.product.main_product_selling_price,
399
+ product_bundle: item.product.product_bundle.map(function (bundle) {
400
+ return {
401
+ bundle_id: bundle.bundle_id,
402
+ bundle_product_id: bundle.bundle_product_id,
403
+ bundle_variant_id: bundle.bundle_variant_id,
404
+ price_type: bundle.price_type,
405
+ price_type_ext: bundle.price_type_ext,
406
+ // 套餐子商品总价,不包含折扣金额
407
+ bundle_sum_price: bundle.bundle_sum_price,
408
+ // 套餐子商品折扣后金额
409
+ bundle_selling_price: bundle.bundle_selling_price,
410
+ num: bundle.num
411
+ };
412
+ })
392
413
  };
393
414
  })) || [];
394
415
  var relationProducts = ((_this$store$currentOr2 = this.store.currentOrder.order_info) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.original_order_data) === null || _this$store$currentOr2 === void 0 || (_this$store$currentOr2 = _this$store$currentOr2.relation_products) === null || _this$store$currentOr2 === void 0 ? void 0 : _this$store$currentOr2.map(function (item) {
@@ -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
  }
@@ -296,7 +296,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
296
296
  });
297
297
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
298
298
  sortedFlattenedList.forEach((flatItem, index) => {
299
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
299
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
300
300
  let product, originProduct;
301
301
  if (flatItem.type === "main") {
302
302
  product = flatItem.product;
@@ -355,24 +355,67 @@ var RulesModule = class extends import_BaseModule.BaseModule {
355
355
  });
356
356
  const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
357
357
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
358
- let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (flatItem.type === "main" && (product.bundle || []).every((item) => {
359
- var _a2;
360
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
361
- })) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(_g, (item) => item.type === "product")));
362
- if ((options == null ? void 0 : options.discountId) && ((_i = product.discount_list) == null ? void 0 : _i.some((item) => {
363
- var _a2;
364
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
365
- }))) {
366
- isManualDiscount = false;
358
+ let isManualDiscount = false;
359
+ if (flatItem.type === "main") {
360
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
361
+ var _a2;
362
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
363
+ }) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(_g, (item) => item.type === "product")));
364
+ } else {
365
+ const parentProduct = flatItem.parentProduct;
366
+ if (parentProduct) {
367
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
368
+ var _a2;
369
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
370
+ }) && (!((_i = parentProduct.discount_list) == null ? void 0 : _i.length) || ((_k = (_j = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _j.every) == null ? void 0 : _k.call(_j, (item) => item.type === "product")));
371
+ }
367
372
  }
368
- if ((options == null ? void 0 : options.selectedList) && ((_j = product.discount_list) == null ? void 0 : _j.some((item) => {
369
- var _a2;
370
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
371
- var _a3;
372
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
373
- });
374
- }))) {
375
- isManualDiscount = false;
373
+ if (options == null ? void 0 : options.discountId) {
374
+ if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some((item) => {
375
+ var _a2;
376
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
377
+ }))) {
378
+ isManualDiscount = false;
379
+ }
380
+ if (flatItem.type === "bundle") {
381
+ if (((_m = product.discount_list) == null ? void 0 : _m.some((item) => {
382
+ var _a2;
383
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
384
+ })) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some((item) => {
385
+ var _a2;
386
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
387
+ }))) {
388
+ isManualDiscount = false;
389
+ }
390
+ }
391
+ }
392
+ if (options == null ? void 0 : options.selectedList) {
393
+ if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some((item) => {
394
+ var _a2;
395
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
396
+ var _a3;
397
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
398
+ });
399
+ }))) {
400
+ isManualDiscount = false;
401
+ }
402
+ if (flatItem.type === "bundle") {
403
+ if (((_q = product.discount_list) == null ? void 0 : _q.some((item) => {
404
+ var _a2;
405
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
406
+ var _a3;
407
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
408
+ });
409
+ })) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some((item) => {
410
+ var _a2;
411
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
412
+ var _a3;
413
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
414
+ });
415
+ }))) {
416
+ isManualDiscount = false;
417
+ }
418
+ }
376
419
  }
377
420
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
378
421
  if (flatItem.type === "main") {
@@ -409,7 +452,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
409
452
  ...isManualDiscount ? {} : {
410
453
  _id: product._id.split("___")[0] + "___" + index,
411
454
  total: product.origin_total || product.total,
412
- price: product.price
455
+ price: product.price,
456
+ main_product_selling_price: product.price
413
457
  },
414
458
  discount_list: []
415
459
  })]
@@ -446,10 +490,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
446
490
  usedDiscounts.set(selectedDiscount2.id, true);
447
491
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
448
492
  let productOriginTotal = product.origin_total || product.total || 0;
449
- if (((_k = product.discount_list) == null ? void 0 : _k.length) && product.origin_total) {
493
+ if (((_t = product.discount_list) == null ? void 0 : _t.length) && product.origin_total) {
450
494
  productOriginTotal = product.origin_total;
451
495
  }
452
- if (Number(((_l = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _l.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
496
+ if (Number(((_u = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _u.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
453
497
  productOriginTotal = product.total;
454
498
  }
455
499
  const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
@@ -458,7 +502,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
458
502
  amount: new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber(),
459
503
  type: discountType,
460
504
  discount: {
461
- discount_card_type: (_m = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _m.discount_card_type,
505
+ discount_card_type: (_v = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _v.discount_card_type,
462
506
  fixed_amount: new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber(),
463
507
  resource_id: selectedDiscount2.id,
464
508
  title: selectedDiscount2.format_title,
@@ -495,7 +539,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
495
539
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
496
540
  quantity: isNeedSplit ? 1 : product.quantity,
497
541
  total: targetProductTotal,
498
- origin_total: productOriginTotal
542
+ origin_total: productOriginTotal,
543
+ main_product_selling_price: targetProductTotal
499
544
  }));
500
545
  }
501
546
  }
@@ -567,7 +612,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
567
612
  amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
568
613
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
569
614
  discount: {
570
- discount_card_type: (_n = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _n.discount_card_type,
615
+ discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
571
616
  fixed_amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
572
617
  resource_id: selectedDiscount2.id,
573
618
  title: selectedDiscount2.format_title,
@@ -637,6 +682,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
637
682
  return;
638
683
  }
639
684
  const hasBundle = product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0;
685
+ debugger;
640
686
  if (!hasBundle) {
641
687
  result.push(...mainProductArr);
642
688
  } else {
@@ -710,16 +756,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
710
756
  });
711
757
  let newTotalWithDiscount = Number(mainProductData.price || 0);
712
758
  let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
713
- if (newBundleWithDiscount.length > 0) {
714
- newBundleWithDiscount.forEach((item) => {
715
- newTotalWithDiscount += Number(item.price) * Number(item.num);
716
- });
717
- newBundleWithDiscount.forEach((item) => {
718
- var _a, _b, _c;
719
- const originalPrice = ((_c = (_b = (_a = item.discount_list) == null ? void 0 : _a[0]) == null ? void 0 : _b.discount) == null ? void 0 : _c.original_amount) || item.price;
720
- newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
721
- });
722
- }
723
759
  const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
724
760
  var _a;
725
761
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -738,14 +774,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
738
774
  const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
739
775
  newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() || newTotalWithDiscount;
740
776
  newOriginTotalWithDiscount = mainProductData.origin_total || newOriginTotalWithDiscount;
741
- if (newBundleWithDiscount.length > 0) {
742
- newBundleWithDiscount.forEach((item) => {
743
- var _a, _b, _c;
744
- newTotalWithDiscount += Number(item.price) * Number(item.num);
745
- const originalPrice = ((_c = (_b = (_a = item.discount_list) == null ? void 0 : _a[0]) == null ? void 0 : _b.discount) == null ? void 0 : _c.original_amount) || item.price;
746
- newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
747
- });
748
- }
777
+ }
778
+ if (newBundleWithDiscount.length > 0) {
779
+ newBundleWithDiscount.forEach((item) => {
780
+ newTotalWithDiscount += Number(item.price) * Number(item.num);
781
+ });
782
+ newBundleWithDiscount.forEach((item) => {
783
+ var _a, _b, _c;
784
+ const originalPrice = ((_c = (_b = (_a = item.discount_list) == null ? void 0 : _a[0]) == null ? void 0 : _b.discount) == null ? void 0 : _c.original_amount) || item.price;
785
+ newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
786
+ });
749
787
  }
750
788
  result.push(
751
789
  this.hooks.setProduct(mainProduct, {
@@ -768,12 +806,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
768
806
  });
769
807
  let newTotalOriginal = Number(mainProductData.price || 0);
770
808
  let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
771
- if (newBundleOriginal.length > 0) {
772
- newBundleOriginal.forEach((item) => {
773
- newTotalOriginal += Number(item.price) * Number(item.num);
774
- newOriginTotalOriginal += Number(item.price) * Number(item.num);
775
- });
776
- }
777
809
  const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
778
810
  var _a;
779
811
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -792,12 +824,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
792
824
  const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
793
825
  newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() || newTotalOriginal;
794
826
  newOriginTotalOriginal = mainProductData.origin_total || newOriginTotalOriginal;
795
- if (newBundleOriginal.length > 0) {
796
- newBundleOriginal.forEach((item) => {
797
- newTotalOriginal += Number(item.price) * Number(item.num);
798
- newOriginTotalOriginal += Number(item.price) * Number(item.num);
799
- });
800
- }
827
+ }
828
+ if (newBundleOriginal.length > 0) {
829
+ newBundleOriginal.forEach((item) => {
830
+ newTotalOriginal += Number(item.price) * Number(item.num);
831
+ newOriginTotalOriginal += Number(item.price) * Number(item.num);
832
+ });
801
833
  }
802
834
  result.push(
803
835
  this.hooks.setProduct(mainProduct, {
@@ -813,6 +845,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
813
845
  }
814
846
  } else {
815
847
  mainProductArr.forEach((mainProduct) => {
848
+ var _a, _b, _c;
816
849
  const mainProductData = this.hooks.getProduct(mainProduct);
817
850
  const newBundle = [];
818
851
  if (product.bundle && Array.isArray(product.bundle)) {
@@ -842,29 +875,27 @@ var RulesModule = class extends import_BaseModule.BaseModule {
842
875
  }
843
876
  let newTotal = Number(mainProductData.price || 0);
844
877
  let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
845
- if (newBundle.length > 0) {
846
- newBundle.forEach((item) => {
847
- newTotal += Number(item.price) * Number(item.num);
848
- });
849
- newBundle.forEach((item) => {
850
- var _a, _b, _c;
851
- const originalPrice = ((_c = (_b = (_a = item.discount_list) == null ? void 0 : _a[0]) == null ? void 0 : _b.discount) == null ? void 0 : _c.original_amount) || item.price;
852
- newOriginTotal += Number(originalPrice) * Number(item.num);
853
- });
854
- }
855
- const mainDiscountList = mainProductData.discount_list.filter((item) => {
856
- var _a;
857
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
858
- });
859
- if (mainDiscountList && mainDiscountList.length > 0) {
860
- const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
861
- newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() || newTotal;
878
+ const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(_b, (item) => item.type === "product")));
879
+ if (isManualDiscount) {
880
+ newTotal = mainProductData.total || newTotal;
862
881
  newOriginTotal = mainProductData.origin_total || newOriginTotal;
882
+ } else {
883
+ const mainDiscountList = mainProductData.discount_list.filter((item) => {
884
+ var _a2;
885
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
886
+ });
887
+ if (mainDiscountList && mainDiscountList.length > 0) {
888
+ const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
889
+ newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() || newTotal;
890
+ newOriginTotal = mainProductData.origin_total || newOriginTotal;
891
+ }
863
892
  if (newBundle.length > 0) {
864
893
  newBundle.forEach((item) => {
865
- var _a, _b, _c;
866
894
  newTotal += Number(item.price) * Number(item.num);
867
- const originalPrice = ((_c = (_b = (_a = item.discount_list) == null ? void 0 : _a[0]) == null ? void 0 : _b.discount) == null ? void 0 : _c.original_amount) || item.price;
895
+ });
896
+ newBundle.forEach((item) => {
897
+ var _a2, _b2, _c2;
898
+ const originalPrice = ((_c2 = (_b2 = (_a2 = item.discount_list) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.discount) == null ? void 0 : _c2.original_amount) || item.price;
868
899
  newOriginTotal += Number(originalPrice) * Number(item.num);
869
900
  });
870
901
  }
@@ -53,6 +53,7 @@ export interface RulesParamsHooks {
53
53
  original_price?: number | string;
54
54
  quantity?: number;
55
55
  bundle?: any[];
56
+ main_product_selling_price?: string | number;
56
57
  }) => Record<string, any>;
57
58
  }
58
59
  export {};
@@ -122,12 +122,6 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
122
122
  throw error;
123
123
  }
124
124
  }
125
- /**
126
- * 初始化外设扫码结果监听
127
- */
128
- initPeripheralsListener() {
129
- this.scan.initPeripheralsListener();
130
- }
131
125
  /**
132
126
  * 获取商品列表(不加载到模块中)
133
127
  * @returns 商品列表
@@ -211,7 +211,28 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
211
211
  product_id: item.product.product_id,
212
212
  product_variant_id: item.product.product_variant_id,
213
213
  quantity: item.product.num,
214
- selling_price: item.product.calculated_selling_price
214
+ // 整个商品折扣后的总金额
215
+ selling_price: item.product.calculated_selling_price,
216
+ // 整个商品折扣前的总金额
217
+ original_price: item.product.calculated_original_price,
218
+ // 主商品折扣前金额,不包含套餐子商品
219
+ main_product_original_price: item.product.price,
220
+ // 主商品折扣后金额,不包含套餐子商品
221
+ main_product_selling_price: item.product.main_product_selling_price,
222
+ product_bundle: item.product.product_bundle.map((bundle) => {
223
+ return {
224
+ bundle_id: bundle.bundle_id,
225
+ bundle_product_id: bundle.bundle_product_id,
226
+ bundle_variant_id: bundle.bundle_variant_id,
227
+ price_type: bundle.price_type,
228
+ price_type_ext: bundle.price_type_ext,
229
+ // 套餐子商品总价,不包含折扣金额
230
+ bundle_sum_price: bundle.bundle_sum_price,
231
+ // 套餐子商品折扣后金额
232
+ bundle_selling_price: bundle.bundle_selling_price,
233
+ num: bundle.num
234
+ };
235
+ })
215
236
  })
216
237
  )) || [];
217
238
  const relationProducts = ((_e = (_d = (_c = this.store.currentOrder.order_info) == null ? void 0 : _c.original_order_data) == null ? void 0 : _d.relation_products) == null ? void 0 : _e.map(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.350",
4
+ "version": "0.0.351",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",