@pisell/pisellos 2.3.164 → 2.3.166

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 (77) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +89 -104
  2. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  3. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +28 -4
  4. package/dist/modules/Holder/utils.d.ts +2 -0
  5. package/dist/modules/Holder/utils.js +32 -2
  6. package/dist/modules/OpenData/contactInfo.d.ts +20 -0
  7. package/dist/modules/OpenData/contactInfo.js +70 -0
  8. package/dist/modules/OpenData/index.d.ts +1 -0
  9. package/dist/modules/OpenData/index.js +1 -0
  10. package/dist/modules/OpenData/types.d.ts +9 -0
  11. package/dist/modules/Order/holderRelations.d.ts +14 -0
  12. package/dist/modules/Order/holderRelations.js +154 -0
  13. package/dist/modules/Order/index.d.ts +1 -1
  14. package/dist/modules/Order/index.js +89 -44
  15. package/dist/modules/Order/types.d.ts +19 -1
  16. package/dist/modules/Order/types.js +2 -0
  17. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  18. package/dist/modules/Order/utils/discountProductLineIdentity.js +142 -7
  19. package/dist/modules/Order/utils/orderCollectionIdentity.js +24 -10
  20. package/dist/modules/Order/utils.d.ts +1 -1
  21. package/dist/modules/Order/utils.js +35 -9
  22. package/dist/modules/Rules/index.js +62 -61
  23. package/dist/server/index.js +18 -12
  24. package/dist/server/modules/order/index.d.ts +4 -0
  25. package/dist/server/modules/order/index.js +255 -190
  26. package/dist/server/modules/order/types.d.ts +3 -0
  27. package/dist/server/modules/products/index.js +3 -2
  28. package/dist/shared/receipt/small-ticket.js +17 -6
  29. package/dist/shared/sales/loadSalesOrderSnapshot.js +1 -1
  30. package/dist/solution/BaseSales/index.d.ts +4 -0
  31. package/dist/solution/BaseSales/index.js +1116 -935
  32. package/dist/solution/BaseSales/types.d.ts +2 -1
  33. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  34. package/dist/solution/BaseSales/utils/parseSalesResponse.js +7 -3
  35. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -4
  36. package/dist/solution/BookingTicket/index.d.ts +15 -1
  37. package/dist/solution/BookingTicket/index.js +784 -501
  38. package/dist/solution/UnifiedBookingSales/index.js +1 -1
  39. package/lib/model/strategy/adapter/promotion/evaluator.js +9 -14
  40. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +3 -1
  41. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +17 -1
  42. package/lib/modules/Holder/utils.d.ts +2 -0
  43. package/lib/modules/Holder/utils.js +27 -1
  44. package/lib/modules/OpenData/contactInfo.d.ts +20 -0
  45. package/lib/modules/OpenData/contactInfo.js +56 -0
  46. package/lib/modules/OpenData/index.d.ts +1 -0
  47. package/lib/modules/OpenData/index.js +12 -0
  48. package/lib/modules/OpenData/types.d.ts +9 -0
  49. package/lib/modules/Order/holderRelations.d.ts +14 -0
  50. package/lib/modules/Order/holderRelations.js +98 -0
  51. package/lib/modules/Order/index.d.ts +1 -1
  52. package/lib/modules/Order/index.js +44 -12
  53. package/lib/modules/Order/types.d.ts +19 -1
  54. package/lib/modules/Order/types.js +1 -0
  55. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +1 -1
  56. package/lib/modules/Order/utils/discountProductLineIdentity.js +51 -2
  57. package/lib/modules/Order/utils/orderCollectionIdentity.js +5 -0
  58. package/lib/modules/Order/utils.d.ts +1 -1
  59. package/lib/modules/Order/utils.js +27 -6
  60. package/lib/modules/Rules/index.js +2 -1
  61. package/lib/server/index.js +6 -0
  62. package/lib/server/modules/order/index.d.ts +4 -0
  63. package/lib/server/modules/order/index.js +46 -4
  64. package/lib/server/modules/order/types.d.ts +3 -0
  65. package/lib/server/modules/products/index.js +2 -1
  66. package/lib/shared/receipt/small-ticket.js +15 -7
  67. package/lib/shared/sales/loadSalesOrderSnapshot.js +1 -1
  68. package/lib/solution/BaseSales/index.d.ts +4 -0
  69. package/lib/solution/BaseSales/index.js +68 -2
  70. package/lib/solution/BaseSales/types.d.ts +2 -1
  71. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -1
  72. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -0
  73. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +16 -8
  74. package/lib/solution/BookingTicket/index.d.ts +15 -1
  75. package/lib/solution/BookingTicket/index.js +132 -3
  76. package/lib/solution/UnifiedBookingSales/index.js +1 -1
  77. package/package.json +1 -1
@@ -38,6 +38,7 @@ import { BaseModule } from "../BaseModule";
38
38
  import { UnavailableReason } from "./types";
39
39
  import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, getDiscountTimeUnavailableReason } from "../../solution/ShopDiscount/utils";
40
40
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
41
+ import { resolveProductHolderConfig } from "../Holder/utils";
41
42
  import Decimal from 'decimal.js';
42
43
  import { cloneDeep, isBoolean } from 'lodash-es';
43
44
  import dayjs from 'dayjs';
@@ -136,12 +137,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
136
137
  }, {
137
138
  key: "checkHolderMatch",
138
139
  value: function checkHolderMatch(discount, product, holderSource, holders) {
139
- var _discount$holder, _ref, _ref2, _ref3, _ref4, _ref5, _ref6, _holderSource$holder_, _holderSource$metadat, _holderSource$origin, _holderSource$metadat2, _holderSource$_origin, _holderSource$_extend, _holderSource$_extend2, _holderSource$_extend3;
140
+ var _discount$holder;
140
141
  // 非表单类型 holder 视为匹配
141
142
  if (((_discount$holder = discount.holder) === null || _discount$holder === void 0 ? void 0 : _discount$holder.holder_type) !== 'form') return true;
142
143
 
143
144
  // getProduct 会裁剪商品字段,从原始商品读取配置,套餐子项沿用父商品。
144
- var holderConfig = (_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_ref6 = (_holderSource$holder_ = holderSource === null || holderSource === void 0 ? void 0 : holderSource.holder_config) !== null && _holderSource$holder_ !== void 0 ? _holderSource$holder_ : holderSource === null || holderSource === void 0 || (_holderSource$metadat = holderSource.metadata) === null || _holderSource$metadat === void 0 ? void 0 : _holderSource$metadat.holder_config) !== null && _ref6 !== void 0 ? _ref6 : holderSource === null || holderSource === void 0 || (_holderSource$origin = holderSource.origin) === null || _holderSource$origin === void 0 ? void 0 : _holderSource$origin.holder_config) !== null && _ref5 !== void 0 ? _ref5 : holderSource === null || holderSource === void 0 || (_holderSource$metadat2 = holderSource.metadata) === null || _holderSource$metadat2 === void 0 || (_holderSource$metadat2 = _holderSource$metadat2.origin) === null || _holderSource$metadat2 === void 0 ? void 0 : _holderSource$metadat2.holder_config) !== null && _ref4 !== void 0 ? _ref4 : holderSource === null || holderSource === void 0 || (_holderSource$_origin = holderSource._origin) === null || _holderSource$_origin === void 0 ? void 0 : _holderSource$_origin.holder_config) !== null && _ref3 !== void 0 ? _ref3 : holderSource === null || holderSource === void 0 || (_holderSource$_extend = holderSource._extend) === null || _holderSource$_extend === void 0 ? void 0 : _holderSource$_extend.holder_config) !== null && _ref2 !== void 0 ? _ref2 : holderSource === null || holderSource === void 0 || (_holderSource$_extend2 = holderSource._extend) === null || _holderSource$_extend2 === void 0 || (_holderSource$_extend2 = _holderSource$_extend2.product) === null || _holderSource$_extend2 === void 0 ? void 0 : _holderSource$_extend2.holder_config) !== null && _ref !== void 0 ? _ref : holderSource === null || holderSource === void 0 || (_holderSource$_extend3 = holderSource._extend) === null || _holderSource$_extend3 === void 0 || (_holderSource$_extend3 = _holderSource$_extend3.product) === null || _holderSource$_extend3 === void 0 || (_holderSource$_extend3 = _holderSource$_extend3.metadata) === null || _holderSource$_extend3 === void 0 ? void 0 : _holderSource$_extend3.holder_config;
145
+ var holderConfig = resolveProductHolderConfig(holderSource);
145
146
  var holderStatus = holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.status;
146
147
  var holderEnabled = holderStatus === true || ['enable', '1'].includes(String(holderStatus).trim().toLowerCase());
147
148
  if (!holderEnabled || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.resource_id) === undefined || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.resource_id) === null || (holderConfig === null || holderConfig === void 0 ? void 0 : holderConfig.resource_id) === '') {
@@ -161,14 +162,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
161
162
  // 判断discountList 是否可以对当前productList生效
162
163
  }, {
163
164
  key: "isDiscountListAvailable",
164
- value: function isDiscountListAvailable(_ref7) {
165
+ value: function isDiscountListAvailable(_ref) {
165
166
  var _this2 = this;
166
- var oldDiscountList = _ref7.oldDiscountList,
167
- newDiscountList = _ref7.newDiscountList,
168
- productList = _ref7.productList,
169
- orderTotalAmount = _ref7.orderTotalAmount,
170
- holders = _ref7.holders,
171
- isFormSubject = _ref7.isFormSubject;
167
+ var oldDiscountList = _ref.oldDiscountList,
168
+ newDiscountList = _ref.newDiscountList,
169
+ productList = _ref.productList,
170
+ orderTotalAmount = _ref.orderTotalAmount,
171
+ holders = _ref.holders,
172
+ isFormSubject = _ref.isFormSubject;
172
173
  // 首先检查是否有新的优惠券可应用
173
174
  if (!newDiscountList || newDiscountList.length === 0) {
174
175
  return {
@@ -367,14 +368,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
367
368
  }
368
369
  }, {
369
370
  key: "calcDiscount",
370
- value: function calcDiscount(_ref8, options) {
371
+ value: function calcDiscount(_ref2, options) {
371
372
  var _options$selectedList,
372
373
  _this4 = this;
373
- var discountList = _ref8.discountList,
374
- productList = _ref8.productList,
375
- holders = _ref8.holders,
376
- isFormSubject = _ref8.isFormSubject,
377
- orderTotalAmount = _ref8.orderTotalAmount;
374
+ var discountList = _ref2.discountList,
375
+ productList = _ref2.productList,
376
+ holders = _ref2.holders,
377
+ isFormSubject = _ref2.isFormSubject,
378
+ orderTotalAmount = _ref2.orderTotalAmount;
378
379
  var preferredEntitlementPassIds = new Set(((options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds) || []).map(String));
379
380
  var resolveIsFormSubject = function resolveIsFormSubject(product) {
380
381
  return typeof isFormSubject === 'function' ? Boolean(isFormSubject(product)) : Boolean(isFormSubject);
@@ -488,7 +489,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
488
489
  // 2. 展开 bundle 子商品
489
490
  if (product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0) {
490
491
  product.bundle.forEach(function (bundleItem, bundleIndex) {
491
- var _ref9, _bundleItem$bundle_pr;
492
+ var _ref3, _bundleItem$bundle_pr;
492
493
  flattened.push({
493
494
  type: 'bundle',
494
495
  originProduct: originProduct,
@@ -500,7 +501,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
500
501
  // 新增商品运行态通常带 _bundle_product_id;订单 hydrate 后只有
501
502
  // bundle_product_id。Change time 必须兼容两种结构,否则 bundle
502
503
  // 子项无法命中折扣卡的 limited_relation_product_data.product_ids。
503
- id: (_ref9 = (_bundleItem$bundle_pr = bundleItem.bundle_product_id) !== null && _bundleItem$bundle_pr !== void 0 ? _bundleItem$bundle_pr : bundleItem._bundle_product_id) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.product_id,
504
+ 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,
504
505
  _id: "".concat(product._id, "_bundle_").concat(bundleIndex),
505
506
  parentId: product._id,
506
507
  num: bundleItem.num || 1,
@@ -660,10 +661,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
660
661
 
661
662
  // 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
662
663
  var sortedFlattenedList = flattenedList.sort(function (a, b) {
663
- var _ref10, _a$original_price, _ref11, _b$original_price;
664
+ var _ref4, _a$original_price, _ref5, _b$original_price;
664
665
  // 子商品优先使用 original_price,主商品使用 price
665
- var priceA = new Decimal(a.type === 'bundle' ? (_ref10 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref10 !== void 0 ? _ref10 : '0' : a.price || '0');
666
- var priceB = new Decimal(b.type === 'bundle' ? (_ref11 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref11 !== void 0 ? _ref11 : '0' : b.price || '0');
666
+ 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');
667
+ 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');
667
668
  if (priceA.equals(priceB)) {
668
669
  // 价格相同时,主商品优先
669
670
  if (a.type !== b.type) {
@@ -797,13 +798,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
797
798
  var buildFullCoveragePassUsageGroups = function buildFullCoveragePassUsageGroups(discounts, requestedCount) {
798
799
  var _firstGoodPass$config;
799
800
  var groups = [];
800
- var pendingUsedDiscounts = new Set(Array.from(usedDiscounts.entries()).filter(function (_ref12) {
801
- var _ref13 = _slicedToArray(_ref12, 2),
802
- used = _ref13[1];
801
+ var pendingUsedDiscounts = new Set(Array.from(usedDiscounts.entries()).filter(function (_ref6) {
802
+ var _ref7 = _slicedToArray(_ref6, 2),
803
+ used = _ref7[1];
803
804
  return used;
804
- }).map(function (_ref14) {
805
- var _ref15 = _slicedToArray(_ref14, 1),
806
- discountId = _ref15[0];
805
+ }).map(function (_ref8) {
806
+ var _ref9 = _slicedToArray(_ref8, 1),
807
+ discountId = _ref9[0];
807
808
  return discountId;
808
809
  }));
809
810
  var pendingEntitlementCounts = new Map(entitlementUsageCounts);
@@ -878,7 +879,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
878
879
  _step6;
879
880
  try {
880
881
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
881
- var _detail$discount$reso, _detail$discount, _detail$discount$prod, _detail$discount2, _detail$metadata$cust, _detail$metadata, _detail$discount3, _ref16, _detail$metadata$num, _detail$metadata2, _ref17, _existed$metadata$num, _existed$metadata;
882
+ var _detail$discount$reso, _detail$discount, _detail$discount$prod, _detail$discount2, _detail$metadata$cust, _detail$metadata, _detail$discount3, _ref10, _detail$metadata$num, _detail$metadata2, _ref11, _existed$metadata$num, _existed$metadata;
882
883
  var detail = _step6.value;
883
884
  if (!isEntitlementPass(detail)) {
884
885
  mergedDetails.push(detail);
@@ -890,7 +891,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
890
891
  continue;
891
892
  }
892
893
  var key = [resourceId, (_detail$discount$prod = detail === null || detail === void 0 || (_detail$discount2 = detail.discount) === null || _detail$discount2 === void 0 ? void 0 : _detail$discount2.product_id) !== null && _detail$discount$prod !== void 0 ? _detail$discount$prod : '', (_detail$metadata$cust = detail === null || detail === void 0 || (_detail$metadata = detail.metadata) === null || _detail$metadata === void 0 ? void 0 : _detail$metadata.custom_product_bundle_map_id) !== null && _detail$metadata$cust !== void 0 ? _detail$metadata$cust : '', toComparableNumber(detail === null || detail === void 0 ? void 0 : detail.amount), toComparableNumber(detail === null || detail === void 0 || (_detail$discount3 = detail.discount) === null || _detail$discount3 === void 0 ? void 0 : _detail$discount3.fixed_amount)].join('|');
893
- var rawUsageCount = Number((_ref16 = (_detail$metadata$num = detail === null || detail === void 0 || (_detail$metadata2 = detail.metadata) === null || _detail$metadata2 === void 0 ? void 0 : _detail$metadata2.num) !== null && _detail$metadata$num !== void 0 ? _detail$metadata$num : detail === null || detail === void 0 ? void 0 : detail._num) !== null && _ref16 !== void 0 ? _ref16 : 1);
894
+ var rawUsageCount = Number((_ref10 = (_detail$metadata$num = detail === null || detail === void 0 || (_detail$metadata2 = detail.metadata) === null || _detail$metadata2 === void 0 ? void 0 : _detail$metadata2.num) !== null && _detail$metadata$num !== void 0 ? _detail$metadata$num : detail === null || detail === void 0 ? void 0 : detail._num) !== null && _ref10 !== void 0 ? _ref10 : 1);
894
895
  var usageCount = Number.isFinite(rawUsageCount) && rawUsageCount > 0 ? rawUsageCount : 1;
895
896
  var mergedIndex = mergedIndexByKey.get(key);
896
897
  if (mergedIndex === undefined) {
@@ -904,7 +905,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
904
905
  continue;
905
906
  }
906
907
  var existed = mergedDetails[mergedIndex];
907
- var existedUsageCount = Number((_ref17 = (_existed$metadata$num = existed === null || existed === void 0 || (_existed$metadata = existed.metadata) === null || _existed$metadata === void 0 ? void 0 : _existed$metadata.num) !== null && _existed$metadata$num !== void 0 ? _existed$metadata$num : existed === null || existed === void 0 ? void 0 : existed._num) !== null && _ref17 !== void 0 ? _ref17 : 1);
908
+ var existedUsageCount = Number((_ref11 = (_existed$metadata$num = existed === null || existed === void 0 || (_existed$metadata = existed.metadata) === null || _existed$metadata === void 0 ? void 0 : _existed$metadata.num) !== null && _existed$metadata$num !== void 0 ? _existed$metadata$num : existed === null || existed === void 0 ? void 0 : existed._num) !== null && _ref11 !== void 0 ? _ref11 : 1);
908
909
  var totalUsageCount = existedUsageCount + usageCount;
909
910
  mergedDetails[mergedIndex] = _objectSpread(_objectSpread({}, existed), {}, {
910
911
  metadata: _objectSpread(_objectSpread({}, (existed === null || existed === void 0 ? void 0 : existed.metadata) || {}), {}, {
@@ -1071,7 +1072,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1071
1072
  // 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
1072
1073
  var applicableProducts = [];
1073
1074
  sortedFlattenedList.forEach(function (flatItem) {
1074
- var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref18, _flatItem$original_pr;
1075
+ var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref12, _flatItem$original_pr;
1075
1076
  // 🔥 检查该商品是否被其他专属折扣卡占用
1076
1077
  var occupyingDiscountId = occupiedItems.get(flatItem._id);
1077
1078
  if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
@@ -1099,7 +1100,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1099
1100
 
1100
1101
  // 对于主商品:使用 price
1101
1102
  // 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
1102
- var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref18 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref18 !== void 0 ? _ref18 : 0);
1103
+ var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref12 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0);
1103
1104
 
1104
1105
  // 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
1105
1106
  var productData = {
@@ -1143,9 +1144,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1143
1144
  return false;
1144
1145
  }
1145
1146
  return (product.options || []).reduce(function (total, option) {
1146
- var _ref19, _ref20, _ref21, _option$_original_pri, _ref22, _option$num;
1147
- var unitPrice = Number((_ref19 = (_ref20 = (_ref21 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref21 !== void 0 ? _ref21 : option.price) !== null && _ref20 !== void 0 ? _ref20 : option.add_price) !== null && _ref19 !== void 0 ? _ref19 : 0);
1148
- var quantity = Number((_ref22 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref22 !== void 0 ? _ref22 : 1);
1147
+ var _ref13, _ref14, _ref15, _option$_original_pri, _ref16, _option$num;
1148
+ var unitPrice = Number((_ref13 = (_ref14 = (_ref15 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref15 !== void 0 ? _ref15 : option.price) !== null && _ref14 !== void 0 ? _ref14 : option.add_price) !== null && _ref13 !== void 0 ? _ref13 : 0);
1149
+ var quantity = Number((_ref16 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref16 !== void 0 ? _ref16 : 1);
1149
1150
  if (!Number.isFinite(unitPrice) || !Number.isFinite(quantity) || quantity <= 0) {
1150
1151
  return total;
1151
1152
  }
@@ -1261,13 +1262,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1261
1262
  };
1262
1263
  var optionDiscountAmount = 0;
1263
1264
  var discountedOptions = options.map(function (option) {
1264
- var _ref23, _ref24, _option$_original_pri2, _ref25, _option$num2, _rest$price, _option$_original_pri3;
1265
+ var _ref17, _ref18, _option$_original_pri2, _ref19, _option$num2, _rest$price, _option$_original_pri3;
1265
1266
  // 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
1266
- var rawUnit = (_ref23 = (_ref24 = (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : option._original_add_price) !== null && _ref24 !== void 0 ? _ref24 : option.price) !== null && _ref23 !== void 0 ? _ref23 : option.add_price;
1267
+ var rawUnit = (_ref17 = (_ref18 = (_option$_original_pri2 = option._original_price) !== null && _option$_original_pri2 !== void 0 ? _option$_original_pri2 : option._original_add_price) !== null && _ref18 !== void 0 ? _ref18 : option.price) !== null && _ref17 !== void 0 ? _ref17 : option.add_price;
1267
1268
  var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
1268
1269
  if (baseUnitNum <= 0) return option;
1269
1270
  var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
1270
- var optQty = Number((_ref25 = (_option$num2 = option.num) !== null && _option$num2 !== void 0 ? _option$num2 : option.quantity) !== null && _ref25 !== void 0 ? _ref25 : 1);
1271
+ var optQty = Number((_ref19 = (_option$num2 = option.num) !== null && _option$num2 !== void 0 ? _option$num2 : option.quantity) !== null && _ref19 !== void 0 ? _ref19 : 1);
1271
1272
  optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
1272
1273
  var _original_add_price = option._original_add_price,
1273
1274
  rest = _objectWithoutProperties(option, _excluded);
@@ -1301,9 +1302,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1301
1302
  var getOptionTotal = function getOptionTotal(options) {
1302
1303
  if (!(options !== null && options !== void 0 && options.length)) return 0;
1303
1304
  return options.reduce(function (sum, opt) {
1304
- var _ref26, _opt$price, _ref27, _opt$num;
1305
- var unit = Number((_ref26 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref26 !== void 0 ? _ref26 : 0);
1306
- var n = Number((_ref27 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1);
1305
+ var _ref20, _opt$price, _ref21, _opt$num;
1306
+ var unit = Number((_ref20 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref20 !== void 0 ? _ref20 : 0);
1307
+ var n = Number((_ref21 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref21 !== void 0 ? _ref21 : 1);
1307
1308
  return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
1308
1309
  }, 0);
1309
1310
  };
@@ -1452,8 +1453,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1452
1453
  var appliedWalletDiscountIds = new Set((product.discount_list || []).filter(function (item) {
1453
1454
  return ['entitlement_pass', 'discount_card', 'product_discount_card'].includes((item === null || item === void 0 ? void 0 : item.tag) || (item === null || item === void 0 ? void 0 : item.type));
1454
1455
  }).map(function (item) {
1455
- var _ref28, _item$discount$resour, _item$discount2;
1456
- return (_ref28 = (_item$discount$resour = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref28 !== void 0 ? _ref28 : item === null || item === void 0 ? void 0 : item.id;
1456
+ var _ref22, _item$discount$resour, _item$discount2;
1457
+ return (_ref22 = (_item$discount$resour = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref22 !== void 0 ? _ref22 : item === null || item === void 0 ? void 0 : item.id;
1457
1458
  }).filter(function (id) {
1458
1459
  return id !== undefined && id !== null;
1459
1460
  }).map(String));
@@ -1493,8 +1494,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1493
1494
  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) {
1494
1495
  return item.type === 'product';
1495
1496
  })) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
1496
- var _ref29;
1497
- return !((_ref29 = item.discount_list || []) !== null && _ref29 !== void 0 && _ref29.length);
1497
+ var _ref23;
1498
+ return !((_ref23 = item.discount_list || []) !== null && _ref23 !== void 0 && _ref23.length);
1498
1499
  }) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
1499
1500
  return item.type === 'product';
1500
1501
  })));
@@ -1510,8 +1511,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1510
1511
  isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : ((_parentProduct$discou = parentProduct.discount_list) === null || _parentProduct$discou === void 0 ? void 0 : _parentProduct$discou.some(function (item) {
1511
1512
  return item.type === 'product';
1512
1513
  })) || parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
1513
- var _ref30;
1514
- return !((_ref30 = item.discount_list || []) !== null && _ref30 !== void 0 && _ref30.length);
1514
+ var _ref24;
1515
+ return !((_ref24 = item.discount_list || []) !== null && _ref24 !== void 0 && _ref24.length);
1515
1516
  }) && (!((_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) {
1516
1517
  return item.type === 'product';
1517
1518
  })));
@@ -1604,8 +1605,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1604
1605
  discount_list: isManualDiscount ? _this4.resolveDiscountListForManualOverride(product.discount_list) : _this4.filterDiscountListByType(product.discount_list, 'promotion')
1605
1606
  }))]);
1606
1607
  } else {
1607
- var _ref31, _product$_promotion$f, _product12, _product$origin_total;
1608
- var total = product.inPromotion ? (_ref31 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref31 !== void 0 ? _ref31 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1608
+ var _ref25, _product$_promotion$f, _product12, _product$origin_total;
1609
+ var total = product.inPromotion ? (_ref25 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref25 !== void 0 ? _ref25 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1609
1610
  var main_product_selling_price = product.price;
1610
1611
  if ((product.discount_list || []).some(function (item) {
1611
1612
  return item.type === 'promotion';
@@ -2308,7 +2309,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2308
2309
  } else {
2309
2310
  // 🔥 没有子商品被拆分,使用原有逻辑
2310
2311
  mainProductArr.forEach(function (mainProduct) {
2311
- var _ref33, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
2312
+ var _ref27, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
2312
2313
  var mainProductData = _this4.hooks.getProduct(mainProduct);
2313
2314
 
2314
2315
  // 重组bundle
@@ -2323,9 +2324,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2323
2324
  } else {
2324
2325
  // 🔥 关键:拆分后的bundle item
2325
2326
  processedBundleItems.forEach(function (item) {
2326
- var _item$price, _ref32, _item$bundle_selling_;
2327
+ var _item$price, _ref26, _item$bundle_selling_;
2327
2328
  var nextBundlePrice = (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : bundleItem.price;
2328
- var nextBundleSellingPrice = (_ref32 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref32 !== void 0 ? _ref32 : bundleItem.bundle_selling_price;
2329
+ var nextBundleSellingPrice = (_ref26 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref26 !== void 0 ? _ref26 : bundleItem.bundle_selling_price;
2329
2330
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
2330
2331
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
2331
2332
  var _discount$metadata11;
@@ -2352,7 +2353,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2352
2353
 
2353
2354
  // 主商品已经在前面的 setProduct 中应用过折扣;这里只替换 bundle,
2354
2355
  // 避免把主商品 discount_list 再扣一次。
2355
- var mainSellingPrice = (_ref33 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref33 !== void 0 ? _ref33 : 0;
2356
+ var mainSellingPrice = (_ref27 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref27 !== void 0 ? _ref27 : 0;
2356
2357
  var newTotal = Number(mainSellingPrice || 0);
2357
2358
  var newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
2358
2359
 
@@ -2568,15 +2569,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
2568
2569
  var ruleType = usageRules.type;
2569
2570
  // 套餐适用范围配置
2570
2571
  var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
2571
- var _ref34 = packageScope || {},
2572
- _ref34$type = _ref34.type,
2573
- scopeType = _ref34$type === void 0 ? 'product_all' : _ref34$type,
2574
- _ref34$exclude_bundle = _ref34.exclude_bundle_product_ids,
2575
- exclude_bundle_product_ids = _ref34$exclude_bundle === void 0 ? [] : _ref34$exclude_bundle,
2576
- _ref34$include_bundle = _ref34.include_bundle_product_ids,
2577
- include_bundle_product_ids = _ref34$include_bundle === void 0 ? [] : _ref34$include_bundle,
2578
- _ref34$filter = _ref34.filter,
2579
- filter = _ref34$filter === void 0 ? 0 : _ref34$filter;
2572
+ var _ref28 = packageScope || {},
2573
+ _ref28$type = _ref28.type,
2574
+ scopeType = _ref28$type === void 0 ? 'product_all' : _ref28$type,
2575
+ _ref28$exclude_bundle = _ref28.exclude_bundle_product_ids,
2576
+ exclude_bundle_product_ids = _ref28$exclude_bundle === void 0 ? [] : _ref28$exclude_bundle,
2577
+ _ref28$include_bundle = _ref28.include_bundle_product_ids,
2578
+ include_bundle_product_ids = _ref28$include_bundle === void 0 ? [] : _ref28$include_bundle,
2579
+ _ref28$filter = _ref28.filter,
2580
+ filter = _ref28$filter === void 0 ? 0 : _ref28$filter;
2580
2581
  var isMainProduct = flatItem.type === 'main'; // 单独购买
2581
2582
  var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
2582
2583
  var bundleMainProductId = (_flatItem$product = flatItem.product) === null || _flatItem$product === void 0 ? void 0 : _flatItem$product.product_id;
@@ -2925,7 +2925,7 @@ var Server = /*#__PURE__*/function () {
2925
2925
  backendPath = params.backendPath, checkoutData = params.checkoutData, externalSaleNumber = params.externalSaleNumber, fresh = params.fresh, title = params.title, persistCheckoutDataWithResponse = params.persistCheckoutDataWithResponse;
2926
2926
  shouldMergeRemoteOrder = fresh ? this.isMergeableCheckoutOrder(fresh, externalSaleNumber) : false;
2927
2927
  if (!(this.order && fresh && (shouldMergeRemoteOrder || persistCheckoutDataWithResponse))) {
2928
- _context36.next = 9;
2928
+ _context36.next = 10;
2929
2929
  break;
2930
2930
  }
2931
2931
  syncedOrder = persistCheckoutDataWithResponse ? _objectSpread(_objectSpread(_objectSpread({}, checkoutData), this.mergeCheckoutSyncPayments(checkoutData, fresh, title)), {}, {
@@ -2937,9 +2937,12 @@ var Server = /*#__PURE__*/function () {
2937
2937
  need_sync: 0,
2938
2938
  is_draft_order: 0
2939
2939
  });
2940
- _context36.next = 6;
2940
+ if (!Array.isArray(fresh.holder_relations) && Array.isArray(checkoutData === null || checkoutData === void 0 ? void 0 : checkoutData.holder_relations)) {
2941
+ syncedOrder.holder_relations = cloneDeep(checkoutData.holder_relations);
2942
+ }
2943
+ _context36.next = 7;
2941
2944
  return this.order.upsertOrdersFromRemote([syncedOrder], 'checkoutSync');
2942
- case 6:
2945
+ case 7:
2943
2946
  this.logInfo("".concat(title, ": sync_sales \u5B8C\u6574\u8BA2\u5355\u5DF2\u540C\u6B65\u5230\u672C\u5730"), {
2944
2947
  order_id: fresh.order_id,
2945
2948
  external_sale_number: syncedOrder.external_sale_number,
@@ -2947,20 +2950,20 @@ var Server = /*#__PURE__*/function () {
2947
2950
  mergedRemoteOrder: shouldMergeRemoteOrder,
2948
2951
  persistedCheckoutDataWithResponse: persistCheckoutDataWithResponse
2949
2952
  });
2950
- _context36.next = 19;
2953
+ _context36.next = 20;
2951
2954
  break;
2952
- case 9:
2955
+ case 10:
2953
2956
  if (!(this.order && externalSaleNumber && typeof this.order.markOrderSyncedByExternalSaleNumber === 'function')) {
2954
- _context36.next = 18;
2957
+ _context36.next = 19;
2955
2958
  break;
2956
2959
  }
2957
2960
  patch = this.buildCheckoutSyncSuccessPatch(fresh);
2958
- _context36.next = 13;
2961
+ _context36.next = 14;
2959
2962
  return this.order.markOrderSyncedByExternalSaleNumber({
2960
2963
  externalSaleNumber: externalSaleNumber,
2961
2964
  patch: patch
2962
2965
  });
2963
- case 13:
2966
+ case 14:
2964
2967
  result = _context36.sent;
2965
2968
  syncedOrder = (result === null || result === void 0 ? void 0 : result.order) || _objectSpread(_objectSpread(_objectSpread({}, checkoutData), patch), {}, {
2966
2969
  external_sale_number: externalSaleNumber,
@@ -2973,17 +2976,17 @@ var Server = /*#__PURE__*/function () {
2973
2976
  hasRemoteOrder: !!fresh,
2974
2977
  mergedRemoteOrder: false
2975
2978
  });
2976
- _context36.next = 19;
2979
+ _context36.next = 20;
2977
2980
  break;
2978
- case 18:
2981
+ case 19:
2979
2982
  this.logWarning("".concat(title, ": sync_sales Order \u6A21\u5757\u672A\u6CE8\u518C"), {
2980
2983
  backendPath: backendPath,
2981
2984
  external_sale_number: externalSaleNumber,
2982
2985
  order_id: fresh === null || fresh === void 0 ? void 0 : fresh.order_id
2983
2986
  });
2984
- case 19:
2985
- return _context36.abrupt("return", syncedOrder);
2986
2987
  case 20:
2988
+ return _context36.abrupt("return", syncedOrder);
2989
+ case 21:
2987
2990
  case "end":
2988
2991
  return _context36.stop();
2989
2992
  }
@@ -8178,6 +8181,9 @@ var Server = /*#__PURE__*/function () {
8178
8181
  if (fresh.order_number !== undefined && fresh.order_number !== null) {
8179
8182
  patch.order_number = fresh.order_number;
8180
8183
  }
8184
+ if (Array.isArray(fresh.holder_relations)) {
8185
+ patch.holder_relations = cloneDeep(fresh.holder_relations);
8186
+ }
8181
8187
  return patch;
8182
8188
  }
8183
8189
  }, {
@@ -326,6 +326,10 @@ export declare class OrderModule extends BaseModule implements Module {
326
326
  private getIdentifiedPendingPayments;
327
327
  private shouldProtectLocalOrderFromRemoteSnapshot;
328
328
  private getUnmatchedIdentifiedPendingPayments;
329
+ /** 关系数组是完整快照,不能拼接或按商品子项生成 UID;扩展字段整体保留。 */
330
+ private applyHolderRelationsSnapshot;
331
+ /** 全量拉取缺少关系字段时,仍保留同一订单已有的关系快照。 */
332
+ private preserveOmittedHolderRelations;
329
333
  private mergeOrderRecords;
330
334
  private summarizeDuplicateOrders;
331
335
  private logDuplicateOrders;