@pisell/pisellos 2.3.36 → 2.3.38

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.
Files changed (90) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  11. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  12. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  13. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  14. package/dist/modules/OpenData/index.d.ts +2 -0
  15. package/dist/modules/OpenData/index.js +8 -0
  16. package/dist/modules/Order/index.js +21 -14
  17. package/dist/modules/Order/utils.js +2 -1
  18. package/dist/modules/Payment/index.js +1 -1
  19. package/dist/modules/Payment/types.d.ts +73 -4
  20. package/dist/modules/Payment/types.js +18 -3
  21. package/dist/modules/Payment/walletpass.d.ts +25 -1
  22. package/dist/modules/Payment/walletpass.js +707 -157
  23. package/dist/modules/Rules/index.d.ts +1 -0
  24. package/dist/modules/Rules/index.js +75 -49
  25. package/dist/server/index.js +28 -24
  26. package/dist/server/modules/order/index.d.ts +5 -0
  27. package/dist/server/modules/order/index.js +52 -31
  28. package/dist/solution/BaseSales/index.d.ts +77 -11
  29. package/dist/solution/BaseSales/index.js +1476 -434
  30. package/dist/solution/BaseSales/types.d.ts +52 -0
  31. package/dist/solution/BaseSales/types.js +2 -1
  32. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  33. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  34. package/dist/solution/BookingByStep/index.d.ts +1 -1
  35. package/dist/solution/BookingTicket/index.d.ts +7 -3
  36. package/dist/solution/BookingTicket/index.js +130 -48
  37. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  38. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  39. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +172 -82
  40. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  41. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  42. package/dist/solution/ScanOrder/index.js +31 -20
  43. package/dist/solution/VenueBooking/index.js +30 -19
  44. package/dist/types/index.d.ts +1 -0
  45. package/lib/core/index.d.ts +2 -0
  46. package/lib/core/index.js +4 -0
  47. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  48. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  49. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  50. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  51. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  52. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  53. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  54. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  55. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  56. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  57. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  58. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  59. package/lib/modules/OpenData/index.d.ts +2 -0
  60. package/lib/modules/OpenData/index.js +5 -0
  61. package/lib/modules/Order/index.js +10 -4
  62. package/lib/modules/Order/utils.js +6 -1
  63. package/lib/modules/Payment/index.js +1 -1
  64. package/lib/modules/Payment/types.d.ts +73 -4
  65. package/lib/modules/Payment/types.js +4 -3
  66. package/lib/modules/Payment/walletpass.d.ts +25 -1
  67. package/lib/modules/Payment/walletpass.js +470 -21
  68. package/lib/modules/Rules/index.d.ts +1 -0
  69. package/lib/modules/Rules/index.js +30 -7
  70. package/lib/server/index.js +11 -8
  71. package/lib/server/modules/order/index.d.ts +5 -0
  72. package/lib/server/modules/order/index.js +24 -2
  73. package/lib/solution/BaseSales/index.d.ts +77 -11
  74. package/lib/solution/BaseSales/index.js +699 -41
  75. package/lib/solution/BaseSales/types.d.ts +52 -0
  76. package/lib/solution/BaseSales/types.js +2 -1
  77. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  78. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  79. package/lib/solution/BookingByStep/index.d.ts +1 -1
  80. package/lib/solution/BookingTicket/index.d.ts +7 -3
  81. package/lib/solution/BookingTicket/index.js +60 -8
  82. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  83. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  84. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +36 -4
  85. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  86. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  87. package/lib/solution/ScanOrder/index.js +8 -0
  88. package/lib/solution/VenueBooking/index.js +8 -0
  89. package/lib/types/index.d.ts +1 -0
  90. package/package.json +2 -2
@@ -35,6 +35,7 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
35
35
  excludeDiscountListByType(discountList: Discount[], type: string): Discount[];
36
36
  /** 手动改价场景:去掉 promotion,保留 type=product 等行内折扣 */
37
37
  resolveDiscountListForManualOverride(discountList: Discount[]): Discount[];
38
+ private isItemRewardProductDiscount;
38
39
  private getUnavailableReason;
39
40
  calcDiscount({ discountList, productList, holders, isFormSubject, orderTotalAmount }: {
40
41
  discountList: Discount[];
@@ -241,6 +241,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
241
241
  value: function resolveDiscountListForManualOverride(discountList) {
242
242
  return this.excludeDiscountListByType(discountList, 'promotion');
243
243
  }
244
+ }, {
245
+ key: "isItemRewardProductDiscount",
246
+ value: function isItemRewardProductDiscount(product) {
247
+ var _product$_promotion;
248
+ var discountList = Array.isArray(product === null || product === void 0 ? void 0 : product.discount_list) ? product.discount_list : [];
249
+ return (product === null || product === void 0 || (_product$_promotion = product._promotion) === null || _product$_promotion === void 0 ? void 0 : _product$_promotion.actionType) === 'ITEM_REWARD' && discountList.some(function (item) {
250
+ var _item$metadata, _item$metadata2;
251
+ return (item === null || item === void 0 ? void 0 : item.type) === 'product' && (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.source) === 'promotion' && (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.actionType) === 'ITEM_REWARD';
252
+ });
253
+ }
254
+
244
255
  // 获取券不可用的原因
245
256
  }, {
246
257
  key: "getUnavailableReason",
@@ -429,6 +440,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
429
440
  // 2. 展开 bundle 子商品
430
441
  if (product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0) {
431
442
  product.bundle.forEach(function (bundleItem, bundleIndex) {
443
+ var _ref3, _bundleItem$bundle_pr;
432
444
  flattened.push({
433
445
  type: 'bundle',
434
446
  originProduct: originProduct,
@@ -437,8 +449,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
437
449
  bundleIndex: bundleIndex,
438
450
  // 虚拟商品属性
439
451
  price: Number(bundleItem.price || 0),
440
- id: bundleItem._bundle_product_id,
441
- // 🔥 使用 _bundle_product_id
452
+ id: (_ref3 = (_bundleItem$bundle_pr = bundleItem.bundle_product_id) !== null && _bundleItem$bundle_pr !== void 0 ? _bundleItem$bundle_pr : bundleItem._bundle_product_id) !== null && _ref3 !== void 0 ? _ref3 : bundleItem.product_id,
442
453
  _id: "".concat(product._id, "_bundle_").concat(bundleIndex),
443
454
  parentId: product._id,
444
455
  num: bundleItem.num || 1,
@@ -587,10 +598,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
587
598
 
588
599
  // 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
589
600
  var sortedFlattenedList = flattenedList.sort(function (a, b) {
590
- var _ref3, _a$original_price, _ref4, _b$original_price;
601
+ var _ref4, _a$original_price, _ref5, _b$original_price;
591
602
  // 子商品优先使用 original_price,主商品使用 price
592
- var priceA = new Decimal(a.type === 'bundle' ? (_ref3 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref3 !== void 0 ? _ref3 : '0' : a.price || '0');
593
- var priceB = new Decimal(b.type === 'bundle' ? (_ref4 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : b.price || '0');
603
+ var priceA = new Decimal(a.type === 'bundle' ? (_ref4 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : a.price || '0');
604
+ var priceB = new Decimal(b.type === 'bundle' ? (_ref5 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref5 !== void 0 ? _ref5 : '0' : b.price || '0');
594
605
  if (priceA.equals(priceB)) {
595
606
  // 价格相同时,主商品优先
596
607
  if (a.type !== b.type) {
@@ -729,6 +740,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
729
740
  startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
730
741
  };
731
742
  }
743
+ if (_this3.isItemRewardProductDiscount(product)) {
744
+ return false;
745
+ }
732
746
 
733
747
  // 编辑的商品使用了优惠券不可用
734
748
  var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
@@ -832,7 +846,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
832
846
  // 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
833
847
  var applicableProducts = [];
834
848
  sortedFlattenedList.forEach(function (flatItem) {
835
- var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref5, _flatItem$original_pr;
849
+ var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref6, _flatItem$original_pr;
836
850
  // 🔥 检查该商品是否被其他专属折扣卡占用
837
851
  var occupyingDiscountId = occupiedItems.get(flatItem._id);
838
852
  if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
@@ -860,7 +874,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
860
874
 
861
875
  // 对于主商品:使用 price
862
876
  // 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
863
- var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref5 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
877
+ var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref6 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref6 !== void 0 ? _ref6 : 0);
864
878
 
865
879
  // 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
866
880
  var productData = {
@@ -915,6 +929,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
915
929
  };
916
930
  originProduct = flatItem.originProduct;
917
931
  }
932
+ var isItemRewardProductDiscount = _this3.isItemRewardProductDiscount(product);
918
933
  addModeDiscount.forEach(function (discount) {
919
934
  var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
920
935
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
@@ -940,7 +955,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
940
955
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
941
956
 
942
957
  // 判断优惠券是否适用于该商品
943
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
958
+ if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
944
959
  var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
945
960
  // 记录此优惠券适用的商品
946
961
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
@@ -988,13 +1003,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
988
1003
  };
989
1004
  var optionDiscountAmount = 0;
990
1005
  var discountedOptions = options.map(function (option) {
991
- var _ref6, _ref7, _option$_original_pri, _ref8, _option$num, _rest$price, _option$_original_pri2;
1006
+ var _ref7, _ref8, _option$_original_pri, _ref9, _option$num, _rest$price, _option$_original_pri2;
992
1007
  // 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
993
- var rawUnit = (_ref6 = (_ref7 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref7 !== void 0 ? _ref7 : option.price) !== null && _ref6 !== void 0 ? _ref6 : option.add_price;
1008
+ var rawUnit = (_ref7 = (_ref8 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref8 !== void 0 ? _ref8 : option.price) !== null && _ref7 !== void 0 ? _ref7 : option.add_price;
994
1009
  var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
995
1010
  if (baseUnitNum <= 0) return option;
996
1011
  var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
997
- var optQty = Number((_ref8 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref8 !== void 0 ? _ref8 : 1);
1012
+ var optQty = Number((_ref9 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref9 !== void 0 ? _ref9 : 1);
998
1013
  optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
999
1014
  var _original_add_price = option._original_add_price,
1000
1015
  rest = _objectWithoutProperties(option, _excluded);
@@ -1028,9 +1043,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1028
1043
  var getOptionTotal = function getOptionTotal(options) {
1029
1044
  if (!(options !== null && options !== void 0 && options.length)) return 0;
1030
1045
  return options.reduce(function (sum, opt) {
1031
- var _ref9, _opt$price, _ref10, _opt$num;
1032
- var unit = Number((_ref9 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref9 !== void 0 ? _ref9 : 0);
1033
- var n = Number((_ref10 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref10 !== void 0 ? _ref10 : 1);
1046
+ var _ref10, _opt$price, _ref11, _opt$num;
1047
+ var unit = Number((_ref10 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref10 !== void 0 ? _ref10 : 0);
1048
+ var n = Number((_ref11 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref11 !== void 0 ? _ref11 : 1);
1034
1049
  return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
1035
1050
  }, 0);
1036
1051
  };
@@ -1085,6 +1100,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1085
1100
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1086
1101
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
1087
1102
  var _product$discount_lis3, _product$discount_lis4;
1103
+ if (_this3.isItemRewardProductDiscount(product)) return false;
1088
1104
  // 🔥 检查策略可用性(针对 good_pass 和折扣卡)
1089
1105
  var discountType = discount.tag || discount.type;
1090
1106
  var currentOriginUid = getOriginProductUid(originProduct);
@@ -1162,28 +1178,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1162
1178
  return false;
1163
1179
  });
1164
1180
 
1165
- // 选择第一个适用的优惠券(已经按过期时间排序)
1166
- // 如果有 isScan isSelected 的折扣卡,则优先选中,否则再选择第一个
1167
- // 用于处理:先手动扫描了一张折扣卡,扫描完以后带入客户信息,但是之前那张折扣卡不是最优惠的情况
1168
- var selectedDiscountCard = applicableDiscounts.find(function (n) {
1181
+ // 用户显式点击某张折扣卡时,本次选择优先于自动排序和扫码默认选择。
1182
+ // 目标仍必须在当前商品的 applicableDiscounts 中,因此不会绕过 Holder、时间或商品范围校验。
1183
+ var explicitlySelectedDiscountCard = (options === null || options === void 0 ? void 0 : options.isSelected) === true && options.discountId !== undefined ? applicableDiscounts.find(function (discount) {
1184
+ var discountType = discount.tag || discount.type;
1185
+ return String(discount.id) === String(options.discountId) && ['discount_card', 'product_discount_card'].includes(discountType);
1186
+ }) : undefined;
1187
+
1188
+ // 没有显式选择时保持现有行为:扫码且已选中的折扣卡优先,否则使用自动排序第一项。
1189
+ var scannedSelectedDiscountCard = applicableDiscounts.find(function (n) {
1169
1190
  return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
1170
1191
  });
1192
+ var selectedDiscountCard = explicitlySelectedDiscountCard || scannedSelectedDiscountCard;
1171
1193
  var selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
1172
1194
 
1173
1195
  // 如果是手动折扣,则不适用优惠券
1174
1196
  var isManualDiscount = false;
1197
+ var isItemRewardProductDiscount = false;
1175
1198
  if (flatItem.type === 'main') {
1176
1199
  var _product$discount_lis5, _product$discount_lis6, _product12, _product12$every;
1177
1200
  // 主商品:判断自身是否手动折扣
1178
1201
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : ((_product$discount_lis5 = product.discount_list) === null || _product$discount_lis5 === void 0 ? void 0 : _product$discount_lis5.some(function (item) {
1179
1202
  return item.type === 'product';
1180
1203
  })) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
1181
- var _ref11;
1182
- return !((_ref11 = item.discount_list || []) !== null && _ref11 !== void 0 && _ref11.length);
1204
+ var _ref12;
1205
+ return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
1183
1206
  }) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
1184
1207
  return item.type === 'product';
1185
1208
  })));
1186
- if (product.inPromotion) {
1209
+ isItemRewardProductDiscount = _this3.isItemRewardProductDiscount(product);
1210
+ if (product.inPromotion && !isItemRewardProductDiscount) {
1187
1211
  isManualDiscount = false;
1188
1212
  }
1189
1213
  } else {
@@ -1194,8 +1218,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1194
1218
  isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : ((_parentProduct$discou = parentProduct.discount_list) === null || _parentProduct$discou === void 0 ? void 0 : _parentProduct$discou.some(function (item) {
1195
1219
  return item.type === 'product';
1196
1220
  })) || parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1197
- var _ref12;
1198
- return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
1221
+ var _ref13;
1222
+ return !((_ref13 = item.discount_list || []) !== null && _ref13 !== void 0 && _ref13.length);
1199
1223
  }) && (!((_parentProduct$discou2 = parentProduct.discount_list) !== null && _parentProduct$discou2 !== void 0 && _parentProduct$discou2.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou3 = parentProduct.discount_list) === null || _parentProduct$discou3 === void 0 || (_parentProduct$discou4 = _parentProduct$discou3.every) === null || _parentProduct$discou4 === void 0 ? void 0 : _parentProduct$discou4.call(_parentProduct$discou3, function (item) {
1200
1224
  return item.type === 'product';
1201
1225
  })));
@@ -1288,20 +1312,22 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1288
1312
  discount_list: isManualDiscount ? _this3.resolveDiscountListForManualOverride(product.discount_list) : _this3.filterDiscountListByType(product.discount_list, 'promotion')
1289
1313
  }))]);
1290
1314
  } else {
1291
- var _ref13, _product$_promotion$f, _product13, _product$origin_total;
1292
- var total = product.inPromotion ? (_ref13 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref13 !== void 0 ? _ref13 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1315
+ var _ref14, _product$_promotion$f, _product13, _product$origin_total;
1316
+ var total = product.inPromotion ? (_ref14 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref14 !== void 0 ? _ref14 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1293
1317
  var main_product_selling_price = product.price;
1294
1318
  if ((product.discount_list || []).some(function (item) {
1295
1319
  return item.type === 'promotion';
1296
- }) || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
1320
+ }) || isItemRewardProductDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
1297
1321
  var _product$total, _product$main_product;
1298
1322
  total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
1299
1323
  main_product_selling_price = (_product$main_product = product.main_product_selling_price) !== null && _product$main_product !== void 0 ? _product$main_product : main_product_selling_price;
1300
1324
  }
1301
- processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
1325
+ processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? _objectSpread({
1302
1326
  price: product.price,
1303
- main_product_selling_price: product.price
1304
- } : {
1327
+ main_product_selling_price: isItemRewardProductDiscount ? main_product_selling_price : product.price
1328
+ }, isItemRewardProductDiscount ? {
1329
+ total: total
1330
+ } : {}) : {
1305
1331
  _id: product._id.split('___')[0] + '___' + index,
1306
1332
  total: total,
1307
1333
  price: product.price,
@@ -1750,11 +1776,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1750
1776
  processedItems.forEach(function (item) {
1751
1777
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1752
1778
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1753
- var _item$metadata;
1779
+ var _item$metadata3;
1754
1780
  return _objectSpread(_objectSpread({}, discount), {}, {
1755
1781
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1756
1782
  num: item.num,
1757
- custom_product_bundle_map_id: (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.custom_product_bundle_map_id
1783
+ custom_product_bundle_map_id: (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.custom_product_bundle_map_id
1758
1784
  })
1759
1785
  // num: item.num, // 使用拆分后的 num
1760
1786
  });
@@ -1773,11 +1799,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1773
1799
  if (item.processed) {
1774
1800
  // 🔥 同样需要更新 discount_list 中的 num
1775
1801
  var _updatedDiscountList = (item.discount_list || []).map(function (discount) {
1776
- var _item$metadata2;
1802
+ var _item$metadata4;
1777
1803
  return _objectSpread(_objectSpread({}, discount), {}, {
1778
1804
  metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1779
1805
  num: item.num,
1780
- custom_product_bundle_map_id: (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.custom_product_bundle_map_id
1806
+ custom_product_bundle_map_id: (_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.custom_product_bundle_map_id
1781
1807
  })
1782
1808
  // num: item.num, // 使用当前的 num
1783
1809
  });
@@ -1818,8 +1844,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1818
1844
 
1819
1845
  // 🔥 使用更新后的列表计算折扣金额
1820
1846
  var mainDiscountList = updatedMainDiscountList.filter(function (item) {
1821
- var _item$metadata3;
1822
- return !(item !== null && item !== void 0 && (_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.custom_product_bundle_map_id);
1847
+ var _item$metadata5;
1848
+ return !(item !== null && item !== void 0 && (_item$metadata5 = item.metadata) !== null && _item$metadata5 !== void 0 && _item$metadata5.custom_product_bundle_map_id);
1823
1849
  });
1824
1850
  if (mainDiscountList && mainDiscountList.length > 0) {
1825
1851
  var _Decimal$minus$toNumb, _mainProductData$orig;
@@ -1892,8 +1918,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1892
1918
 
1893
1919
  // 🔥 使用更新后的列表计算折扣金额
1894
1920
  var mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(function (item) {
1895
- var _item$metadata4;
1896
- return !(item !== null && item !== void 0 && (_item$metadata4 = item.metadata) !== null && _item$metadata4 !== void 0 && _item$metadata4.custom_product_bundle_map_id);
1921
+ var _item$metadata6;
1922
+ return !(item !== null && item !== void 0 && (_item$metadata6 = item.metadata) !== null && _item$metadata6 !== void 0 && _item$metadata6.custom_product_bundle_map_id);
1897
1923
  });
1898
1924
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
1899
1925
  var _Decimal$minus$toNumb2, _mainProductData$orig2;
@@ -1934,7 +1960,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1934
1960
  } else {
1935
1961
  // 🔥 没有子商品被拆分,使用原有逻辑
1936
1962
  mainProductArr.forEach(function (mainProduct) {
1937
- var _ref15, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
1963
+ var _ref16, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
1938
1964
  var mainProductData = _this3.hooks.getProduct(mainProduct);
1939
1965
 
1940
1966
  // 重组bundle
@@ -1949,9 +1975,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1949
1975
  } else {
1950
1976
  // 🔥 关键:拆分后的bundle item
1951
1977
  processedBundleItems.forEach(function (item) {
1952
- var _item$price, _ref14, _item$bundle_selling_;
1978
+ var _item$price, _ref15, _item$bundle_selling_;
1953
1979
  var nextBundlePrice = (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : bundleItem.price;
1954
- var nextBundleSellingPrice = (_ref14 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref14 !== void 0 ? _ref14 : bundleItem.bundle_selling_price;
1980
+ var nextBundleSellingPrice = (_ref15 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref15 !== void 0 ? _ref15 : bundleItem.bundle_selling_price;
1955
1981
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1956
1982
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1957
1983
  var _discount$metadata10;
@@ -1978,7 +2004,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1978
2004
 
1979
2005
  // 主商品已经在前面的 setProduct 中应用过折扣;这里只替换 bundle,
1980
2006
  // 避免把主商品 discount_list 再扣一次。
1981
- var mainSellingPrice = (_ref15 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref15 !== void 0 ? _ref15 : 0;
2007
+ var mainSellingPrice = (_ref16 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref16 !== void 0 ? _ref16 : 0;
1982
2008
  var newTotal = Number(mainSellingPrice || 0);
1983
2009
  var newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
1984
2010
 
@@ -2126,14 +2152,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2126
2152
  var ruleType = usageRules.type;
2127
2153
  // 套餐适用范围配置
2128
2154
  var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
2129
- var _ref16 = packageScope || {},
2130
- scopeType = _ref16.type,
2131
- _ref16$exclude_bundle = _ref16.exclude_bundle_product_ids,
2132
- exclude_bundle_product_ids = _ref16$exclude_bundle === void 0 ? [] : _ref16$exclude_bundle,
2133
- _ref16$include_bundle = _ref16.include_bundle_product_ids,
2134
- include_bundle_product_ids = _ref16$include_bundle === void 0 ? [] : _ref16$include_bundle,
2135
- _ref16$filter = _ref16.filter,
2136
- filter = _ref16$filter === void 0 ? 0 : _ref16$filter;
2155
+ var _ref17 = packageScope || {},
2156
+ scopeType = _ref17.type,
2157
+ _ref17$exclude_bundle = _ref17.exclude_bundle_product_ids,
2158
+ exclude_bundle_product_ids = _ref17$exclude_bundle === void 0 ? [] : _ref17$exclude_bundle,
2159
+ _ref17$include_bundle = _ref17.include_bundle_product_ids,
2160
+ include_bundle_product_ids = _ref17$include_bundle === void 0 ? [] : _ref17$include_bundle,
2161
+ _ref17$filter = _ref17.filter,
2162
+ filter = _ref17$filter === void 0 ? 0 : _ref17$filter;
2137
2163
  var isMainProduct = flatItem.type === 'main'; // 单独购买
2138
2164
  var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
2139
2165
 
@@ -4924,12 +4924,9 @@ var Server = /*#__PURE__*/function () {
4924
4924
  case 10:
4925
4925
  this.logInfo('processSuccessfulLocalPayment: BaseSales 初始化完成', recoveryContext);
4926
4926
  _context50.next = 13;
4927
- return baseSales.loadSalesDetail({
4928
- externalSaleNumber: String(params.saleId),
4929
- preloadedSalesDetail: order
4930
- });
4927
+ return baseSales.replaceTempOrder(order);
4931
4928
  case 13:
4932
- this.logInfo('processSuccessfulLocalPayment: 本地订单 hydrate 完成', recoveryContext);
4929
+ this.logInfo('processSuccessfulLocalPayment: 本地订单 tempOrder 恢复完成', recoveryContext);
4933
4930
  this.logInfo('processSuccessfulLocalPayment: 开始更新支付项并提交', _objectSpread(_objectSpread({}, recoveryContext), {}, {
4934
4931
  incoming_payment_update: params.paymentUpdate
4935
4932
  }));
@@ -5719,7 +5716,7 @@ var Server = /*#__PURE__*/function () {
5719
5716
  key: "handleOrderCheckoutSubmit",
5720
5717
  value: function () {
5721
5718
  var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee58(params) {
5722
- var backendPath, data, title, normalizedData, checkoutData, pendingResult, pendingOrder;
5719
+ var backendPath, data, title, normalizedData, checkoutData, pendingResult, _this$core$context2, pendingOrder, platform, isAndroid;
5723
5720
  return _regeneratorRuntime().wrap(function _callee58$(_context58) {
5724
5721
  while (1) switch (_context58.prev = _context58.next) {
5725
5722
  case 0:
@@ -5758,34 +5755,35 @@ var Server = /*#__PURE__*/function () {
5758
5755
  case 12:
5759
5756
  pendingResult = _context58.sent;
5760
5757
  if (!((pendingResult === null || pendingResult === void 0 ? void 0 : pendingResult.status) === true)) {
5761
- _context58.next = 20;
5758
+ _context58.next = 22;
5762
5759
  break;
5763
5760
  }
5764
5761
  pendingOrder = pendingResult.data;
5765
- if (!(pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) &&
5766
- // TODO 这里先加个兼容,只有 type 为 virtual 才走打印
5767
- // 后期需要迁移到 picoding ,根据工作流配置
5768
- checkoutData.type === 'virtual')) {
5769
- _context58.next = 18;
5762
+ platform = (_this$core$context2 = this.core.context) === null || _this$core$context2 === void 0 ? void 0 : _this$core$context2.getPlatform();
5763
+ isAndroid = platform === 'android';
5764
+ if (!(pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) && (
5765
+ // TODO 这里先加个兼容,如果是安卓,则需要 type=virtual 才走打印,如果是苹果则无限制
5766
+ isAndroid ? checkoutData.type === 'virtual' : true))) {
5767
+ _context58.next = 20;
5770
5768
  break;
5771
5769
  }
5772
- _context58.next = 18;
5770
+ _context58.next = 20;
5773
5771
  return this.dispatchLocalReceiptPrint({
5774
5772
  checkoutData: checkoutData,
5775
5773
  order: pendingOrder,
5776
5774
  response: pendingResult,
5777
5775
  requireFullyPaid: true
5778
5776
  });
5779
- case 18:
5780
- _context58.next = 20;
5777
+ case 20:
5778
+ _context58.next = 22;
5781
5779
  return this.dispatchCheckoutSyncTask({
5782
5780
  backendPath: backendPath,
5783
5781
  data: checkoutData,
5784
5782
  title: title
5785
5783
  });
5786
- case 20:
5784
+ case 22:
5787
5785
  if (pendingResult.data.order_id) {
5788
- _context58.next = 22;
5786
+ _context58.next = 24;
5789
5787
  break;
5790
5788
  }
5791
5789
  return _context58.abrupt("return", _objectSpread(_objectSpread({}, pendingResult), {}, {
@@ -5793,9 +5791,9 @@ var Server = /*#__PURE__*/function () {
5793
5791
  order_id: pendingResult.data.external_sale_number
5794
5792
  })
5795
5793
  }));
5796
- case 22:
5794
+ case 24:
5797
5795
  return _context58.abrupt("return", pendingResult);
5798
- case 23:
5796
+ case 25:
5799
5797
  case "end":
5800
5798
  return _context58.stop();
5801
5799
  }
@@ -6460,9 +6458,9 @@ var Server = /*#__PURE__*/function () {
6460
6458
  }, {
6461
6459
  key: "getProductTitleSnapshotCurrentLocale",
6462
6460
  value: function getProductTitleSnapshotCurrentLocale() {
6463
- var _this$core$context2, _this$core$context3;
6461
+ var _this$core$context3, _this$core$context4;
6464
6462
  var shopInfo = this.getSmallTicketShopInfo();
6465
- var rawLocale = shopInfo.primary_locale || this.getAppData('locale') || this.getAppData('language') || ((_this$core$context2 = this.core.context) === null || _this$core$context2 === void 0 ? void 0 : _this$core$context2.locale) || ((_this$core$context3 = this.core.context) === null || _this$core$context3 === void 0 ? void 0 : _this$core$context3.language);
6463
+ var rawLocale = shopInfo.primary_locale || this.getAppData('locale') || this.getAppData('language') || ((_this$core$context3 = this.core.context) === null || _this$core$context3 === void 0 ? void 0 : _this$core$context3.locale) || ((_this$core$context4 = this.core.context) === null || _this$core$context4 === void 0 ? void 0 : _this$core$context4.language);
6466
6464
  return this.normalizeProductTitleSnapshotLocale(rawLocale);
6467
6465
  }
6468
6466
  }, {
@@ -7400,6 +7398,12 @@ var Server = /*#__PURE__*/function () {
7400
7398
 
7401
7399
  // 使用 filterOrders 进行过滤、排序、分页
7402
7400
  result = filterOrders(rawList, data);
7401
+ result.list.forEach(function (order) {
7402
+ var _order$payments;
7403
+ order.payments = (_order$payments = order.payments) === null || _order$payments === void 0 ? void 0 : _order$payments.filter(function (payment) {
7404
+ return !isPendingOrderPayment(payment);
7405
+ });
7406
+ });
7403
7407
  this.logInfo('computeOrderQueryResult: 过滤结果', {
7404
7408
  rawCount: rawList.length,
7405
7409
  filteredCount: result.count,
@@ -7413,7 +7417,7 @@ var Server = /*#__PURE__*/function () {
7413
7417
  message: '',
7414
7418
  status: true
7415
7419
  });
7416
- case 10:
7420
+ case 11:
7417
7421
  case "end":
7418
7422
  return _context71.stop();
7419
7423
  }
@@ -7831,7 +7835,7 @@ var Server = /*#__PURE__*/function () {
7831
7835
  }, {
7832
7836
  key: "buildProductFormatterContext",
7833
7837
  value: function buildProductFormatterContext(context) {
7834
- var _this$menu, _this$menu$getMenuLis, _scheduleModule$getSc, _this$core$context4;
7838
+ var _this$menu, _this$menu$getMenuLis, _scheduleModule$getSc, _this$core$context5;
7835
7839
  var scheduleModule = this.getSchedule();
7836
7840
  return {
7837
7841
  scheduleModule: scheduleModule,
@@ -7840,7 +7844,7 @@ var Server = /*#__PURE__*/function () {
7840
7844
  strategy_context: context.strategy_context,
7841
7845
  menuList: ((_this$menu = this.menu) === null || _this$menu === void 0 || (_this$menu$getMenuLis = _this$menu.getMenuList) === null || _this$menu$getMenuLis === void 0 ? void 0 : _this$menu$getMenuLis.call(_this$menu)) || [],
7842
7846
  scheduleList: (scheduleModule === null || scheduleModule === void 0 || (_scheduleModule$getSc = scheduleModule.getScheduleList) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule)) || [],
7843
- dataVariantEvaluator: (_this$core$context4 = this.core.context) === null || _this$core$context4 === void 0 ? void 0 : _this$core$context4.dataVariantEvaluator
7847
+ dataVariantEvaluator: (_this$core$context5 = this.core.context) === null || _this$core$context5 === void 0 ? void 0 : _this$core$context5.dataVariantEvaluator
7844
7848
  };
7845
7849
  }
7846
7850
 
@@ -167,6 +167,11 @@ export declare class OrderModule extends BaseModule implements Module {
167
167
  private syncOrdersMap;
168
168
  private getOrderMapKey;
169
169
  private isBlankIdentityValue;
170
+ /**
171
+ * `/sales/draft` 的旧调用方可能把未设置的 business_code 传成空串。
172
+ * 对同一真实订单,空值不能覆盖已有的分类,否则 booking 查询会把该订单从 Party 列表过滤掉。
173
+ */
174
+ private preserveExistingBusinessCodeForDraft;
170
175
  private getOrderIdentityEntries;
171
176
  private getOrderIdentityKeys;
172
177
  private getOrderDateKey;