@pisell/pisellos 2.3.37 → 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 +19 -18
  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 +1322 -297
  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 +51 -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 +5 -3
  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 +682 -39
  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
 
@@ -5716,7 +5716,7 @@ var Server = /*#__PURE__*/function () {
5716
5716
  key: "handleOrderCheckoutSubmit",
5717
5717
  value: function () {
5718
5718
  var _handleOrderCheckoutSubmit = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee58(params) {
5719
- var backendPath, data, title, normalizedData, checkoutData, pendingResult, pendingOrder;
5719
+ var backendPath, data, title, normalizedData, checkoutData, pendingResult, _this$core$context2, pendingOrder, platform, isAndroid;
5720
5720
  return _regeneratorRuntime().wrap(function _callee58$(_context58) {
5721
5721
  while (1) switch (_context58.prev = _context58.next) {
5722
5722
  case 0:
@@ -5755,34 +5755,35 @@ var Server = /*#__PURE__*/function () {
5755
5755
  case 12:
5756
5756
  pendingResult = _context58.sent;
5757
5757
  if (!((pendingResult === null || pendingResult === void 0 ? void 0 : pendingResult.status) === true)) {
5758
- _context58.next = 20;
5758
+ _context58.next = 22;
5759
5759
  break;
5760
5760
  }
5761
5761
  pendingOrder = pendingResult.data;
5762
- if (!(pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) &&
5763
- // TODO 这里先加个兼容,只有 type 为 virtual 才走打印
5764
- // 后期需要迁移到 picoding ,根据工作流配置
5765
- checkoutData.type === 'virtual')) {
5766
- _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;
5767
5768
  break;
5768
5769
  }
5769
- _context58.next = 18;
5770
+ _context58.next = 20;
5770
5771
  return this.dispatchLocalReceiptPrint({
5771
5772
  checkoutData: checkoutData,
5772
5773
  order: pendingOrder,
5773
5774
  response: pendingResult,
5774
5775
  requireFullyPaid: true
5775
5776
  });
5776
- case 18:
5777
- _context58.next = 20;
5777
+ case 20:
5778
+ _context58.next = 22;
5778
5779
  return this.dispatchCheckoutSyncTask({
5779
5780
  backendPath: backendPath,
5780
5781
  data: checkoutData,
5781
5782
  title: title
5782
5783
  });
5783
- case 20:
5784
+ case 22:
5784
5785
  if (pendingResult.data.order_id) {
5785
- _context58.next = 22;
5786
+ _context58.next = 24;
5786
5787
  break;
5787
5788
  }
5788
5789
  return _context58.abrupt("return", _objectSpread(_objectSpread({}, pendingResult), {}, {
@@ -5790,9 +5791,9 @@ var Server = /*#__PURE__*/function () {
5790
5791
  order_id: pendingResult.data.external_sale_number
5791
5792
  })
5792
5793
  }));
5793
- case 22:
5794
+ case 24:
5794
5795
  return _context58.abrupt("return", pendingResult);
5795
- case 23:
5796
+ case 25:
5796
5797
  case "end":
5797
5798
  return _context58.stop();
5798
5799
  }
@@ -6457,9 +6458,9 @@ var Server = /*#__PURE__*/function () {
6457
6458
  }, {
6458
6459
  key: "getProductTitleSnapshotCurrentLocale",
6459
6460
  value: function getProductTitleSnapshotCurrentLocale() {
6460
- var _this$core$context2, _this$core$context3;
6461
+ var _this$core$context3, _this$core$context4;
6461
6462
  var shopInfo = this.getSmallTicketShopInfo();
6462
- 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);
6463
6464
  return this.normalizeProductTitleSnapshotLocale(rawLocale);
6464
6465
  }
6465
6466
  }, {
@@ -7834,7 +7835,7 @@ var Server = /*#__PURE__*/function () {
7834
7835
  }, {
7835
7836
  key: "buildProductFormatterContext",
7836
7837
  value: function buildProductFormatterContext(context) {
7837
- var _this$menu, _this$menu$getMenuLis, _scheduleModule$getSc, _this$core$context4;
7838
+ var _this$menu, _this$menu$getMenuLis, _scheduleModule$getSc, _this$core$context5;
7838
7839
  var scheduleModule = this.getSchedule();
7839
7840
  return {
7840
7841
  scheduleModule: scheduleModule,
@@ -7843,7 +7844,7 @@ var Server = /*#__PURE__*/function () {
7843
7844
  strategy_context: context.strategy_context,
7844
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)) || [],
7845
7846
  scheduleList: (scheduleModule === null || scheduleModule === void 0 || (_scheduleModule$getSc = scheduleModule.getScheduleList) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule)) || [],
7846
- 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
7847
7848
  };
7848
7849
  }
7849
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;
@@ -1572,7 +1572,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1572
1572
  value: (function () {
1573
1573
  var _upsertLocalDraftOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(draftOrders) {
1574
1574
  var _this10 = this;
1575
- var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, memoryDraftOrder, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, mergedOrder, nextOrder, insertIndex, previousList, removedLegacyMemoryDraft;
1575
+ var draftMap, memoryDraftMap, _iterator8, _step8, order, draftOrder, storageKey, memoryDraftOrder, mergeActions, updatedList, identityKeyToIndex, index, _iterator9, _step9, key, _iterator10, _step10, _step10$value, _storageKey2, _draftOrder, matchIndex, existingOrder, reconciledDraftOrder, mergedOrder, nextOrder, insertIndex, patchedOrders, previousList, removedLegacyMemoryDraft;
1576
1576
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1577
1577
  while (1) switch (_context13.prev = _context13.next) {
1578
1578
  case 0:
@@ -1639,7 +1639,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1639
1639
  memoryDraftCount: memoryDraftMap.size,
1640
1640
  sqliteOnlyDraftCount: draftMap.size - memoryDraftMap.size
1641
1641
  });
1642
- patchedOrders = _toConsumableArray(draftMap.values());
1643
1642
  mergeActions = {};
1644
1643
  updatedList = this.store.list.filter(function (order) {
1645
1644
  return _this10.shouldKeepOrderInMemory(order);
@@ -1659,66 +1658,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1659
1658
  }
1660
1659
  }
1661
1660
  _iterator10 = _createForOfIteratorHelper(memoryDraftMap.entries());
1662
- _context13.prev = 37;
1661
+ _context13.prev = 36;
1663
1662
  _iterator10.s();
1664
- case 39:
1663
+ case 38:
1665
1664
  if ((_step10 = _iterator10.n()).done) {
1666
- _context13.next = 55;
1665
+ _context13.next = 57;
1667
1666
  break;
1668
1667
  }
1669
1668
  _step10$value = _slicedToArray(_step10.value, 2), _storageKey2 = _step10$value[0], _draftOrder = _step10$value[1];
1670
1669
  matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(_draftOrder));
1671
1670
  if (!(matchIndex >= 0)) {
1672
- _context13.next = 49;
1671
+ _context13.next = 51;
1673
1672
  break;
1674
1673
  }
1675
- mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], _draftOrder);
1674
+ existingOrder = updatedList[matchIndex];
1675
+ reconciledDraftOrder = this.preserveExistingBusinessCodeForDraft(existingOrder, _draftOrder);
1676
+ mergedOrder = this.mergeOrderRecords(existingOrder, reconciledDraftOrder);
1676
1677
  nextOrder = _objectSpread(_objectSpread({}, mergedOrder), {}, {
1677
1678
  need_sync: 0,
1678
1679
  is_draft_order: 1
1679
1680
  });
1680
1681
  updatedList[matchIndex] = nextOrder;
1682
+ // SQLite 必须与内存中的草稿保持同一份 business_code,避免下次 hydrate 再次丢失分类。
1683
+ draftMap.set(_storageKey2, reconciledDraftOrder);
1681
1684
  this.registerOrderIdentityKeys(identityKeyToIndex, nextOrder, matchIndex);
1682
1685
  mergeActions[_storageKey2] = 'update';
1683
- return _context13.abrupt("continue", 53);
1684
- case 49:
1686
+ return _context13.abrupt("continue", 55);
1687
+ case 51:
1685
1688
  insertIndex = updatedList.length;
1686
1689
  updatedList.push(_draftOrder);
1687
1690
  this.registerOrderIdentityKeys(identityKeyToIndex, _draftOrder, insertIndex);
1688
1691
  mergeActions[_storageKey2] = 'insert';
1689
- case 53:
1690
- _context13.next = 39;
1691
- break;
1692
1692
  case 55:
1693
- _context13.next = 60;
1693
+ _context13.next = 38;
1694
1694
  break;
1695
1695
  case 57:
1696
- _context13.prev = 57;
1697
- _context13.t1 = _context13["catch"](37);
1696
+ _context13.next = 62;
1697
+ break;
1698
+ case 59:
1699
+ _context13.prev = 59;
1700
+ _context13.t1 = _context13["catch"](36);
1698
1701
  _iterator10.e(_context13.t1);
1699
- case 60:
1700
- _context13.prev = 60;
1702
+ case 62:
1703
+ _context13.prev = 62;
1701
1704
  _iterator10.f();
1702
- return _context13.finish(60);
1703
- case 63:
1705
+ return _context13.finish(62);
1706
+ case 65:
1707
+ patchedOrders = _toConsumableArray(draftMap.values());
1704
1708
  previousList = this.store.list;
1705
1709
  this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertLocalDraftOrders.store');
1706
1710
  this.syncOrdersMap();
1707
- _context13.prev = 66;
1708
- _context13.next = 69;
1711
+ _context13.prev = 69;
1712
+ _context13.next = 72;
1709
1713
  return this.patchOrdersInSQLite(patchedOrders, 'upsertLocalDraftOrders', mergeActions, {
1710
1714
  throwOnError: true
1711
1715
  });
1712
- case 69:
1713
- _context13.next = 76;
1716
+ case 72:
1717
+ _context13.next = 79;
1714
1718
  break;
1715
- case 71:
1716
- _context13.prev = 71;
1717
- _context13.t2 = _context13["catch"](66);
1719
+ case 74:
1720
+ _context13.prev = 74;
1721
+ _context13.t2 = _context13["catch"](69);
1718
1722
  this.store.list = previousList;
1719
1723
  this.syncOrdersMap();
1720
1724
  throw _context13.t2;
1721
- case 76:
1725
+ case 79:
1722
1726
  this.logInfo('upsertLocalDraftOrders-结束', {
1723
1727
  count: patchedOrders.length,
1724
1728
  storeOrderCountAfter: this.store.list.length
@@ -1727,18 +1731,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1727
1731
  return !_this10.shouldKeepOrderInMemory(order);
1728
1732
  });
1729
1733
  if (!(memoryDraftMap.size > 0 || removedLegacyMemoryDraft)) {
1730
- _context13.next = 81;
1734
+ _context13.next = 84;
1731
1735
  break;
1732
1736
  }
1733
- _context13.next = 81;
1737
+ _context13.next = 84;
1734
1738
  return this.emitOrdersChanged(patchedOrders.filter(function (order) {
1735
1739
  return _this10.shouldKeepOrderInMemory(order);
1736
1740
  }), 'upsertLocalDraftOrders');
1737
- case 81:
1741
+ case 84:
1738
1742
  case "end":
1739
1743
  return _context13.stop();
1740
1744
  }
1741
- }, _callee13, this, [[6, 21, 24, 27], [37, 57, 60, 63], [66, 71]]);
1745
+ }, _callee13, this, [[6, 21, 24, 27], [36, 59, 62, 65], [69, 74]]);
1742
1746
  }));
1743
1747
  function upsertLocalDraftOrders(_x10) {
1744
1748
  return _upsertLocalDraftOrders.apply(this, arguments);
@@ -1853,6 +1857,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1853
1857
  value: function isBlankIdentityValue(value) {
1854
1858
  return value === undefined || value === null || value === '';
1855
1859
  }
1860
+
1861
+ /**
1862
+ * `/sales/draft` 的旧调用方可能把未设置的 business_code 传成空串。
1863
+ * 对同一真实订单,空值不能覆盖已有的分类,否则 booking 查询会把该订单从 Party 列表过滤掉。
1864
+ */
1865
+ }, {
1866
+ key: "preserveExistingBusinessCodeForDraft",
1867
+ value: function preserveExistingBusinessCodeForDraft(existingOrder, draftOrder) {
1868
+ var existingBusinessCode = existingOrder.business_code;
1869
+ var draftBusinessCode = draftOrder.business_code;
1870
+ var hasExistingBusinessCode = typeof existingBusinessCode === 'string' && existingBusinessCode.trim() !== '';
1871
+ var hasDraftBusinessCode = typeof draftBusinessCode === 'string' && draftBusinessCode.trim() !== '';
1872
+ if (!hasExistingBusinessCode || hasDraftBusinessCode) return draftOrder;
1873
+ return _objectSpread(_objectSpread({}, draftOrder), {}, {
1874
+ business_code: existingBusinessCode
1875
+ });
1876
+ }
1856
1877
  }, {
1857
1878
  key: "getOrderIdentityEntries",
1858
1879
  value: function getOrderIdentityEntries(order) {