@pisell/pisellos 2.3.170 → 2.3.172

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 (82) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/inventory/index.d.ts +92 -0
  4. package/dist/inventory/index.js +509 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +5 -4
  6. package/dist/modules/Discount/index.js +1 -0
  7. package/dist/modules/Discount/types.d.ts +4 -0
  8. package/dist/modules/Order/index.d.ts +25 -3
  9. package/dist/modules/Order/index.js +1791 -1318
  10. package/dist/modules/Order/types.d.ts +7 -0
  11. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  12. package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  13. package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
  14. package/dist/modules/Payment/walletpass.js +32 -6
  15. package/dist/modules/Product/index.d.ts +1 -1
  16. package/dist/modules/ProductList/index.js +33 -12
  17. package/dist/modules/Rules/index.d.ts +5 -10
  18. package/dist/modules/Rules/index.js +197 -107
  19. package/dist/modules/Rules/promotionSelection.d.ts +14 -0
  20. package/dist/modules/Rules/promotionSelection.js +390 -0
  21. package/dist/modules/Rules/types.d.ts +9 -0
  22. package/dist/server/modules/order/index.d.ts +6 -0
  23. package/dist/server/modules/order/index.js +782 -447
  24. package/dist/solution/BaseSales/index.d.ts +16 -1
  25. package/dist/solution/BaseSales/index.js +1545 -1339
  26. package/dist/solution/BaseSales/utils/cartPromotion.js +5 -2
  27. package/dist/solution/BookingByStep/index.d.ts +2 -2
  28. package/dist/solution/BookingTicket/index.js +200 -108
  29. package/dist/solution/BookingTicket/types.d.ts +14 -2
  30. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  31. package/dist/solution/BookingTicket/utils/addProductDecision.js +4 -3
  32. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +94 -58
  33. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
  34. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +117 -0
  35. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  36. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  37. package/dist/solution/UnifiedBookingSales/index.d.ts +1 -1
  38. package/dist/solution/UnifiedBookingSales/index.js +69 -49
  39. package/dist/utils/platform.d.ts +2 -0
  40. package/dist/utils/platform.js +6 -0
  41. package/lib/index.d.ts +1 -0
  42. package/lib/index.js +12 -0
  43. package/lib/inventory/index.d.ts +92 -0
  44. package/lib/inventory/index.js +287 -0
  45. package/lib/model/strategy/adapter/promotion/evaluator.js +5 -4
  46. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  47. package/lib/modules/Discount/index.js +1 -0
  48. package/lib/modules/Discount/types.d.ts +4 -0
  49. package/lib/modules/Order/index.d.ts +25 -3
  50. package/lib/modules/Order/index.js +203 -38
  51. package/lib/modules/Order/types.d.ts +7 -0
  52. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  53. package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  54. package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
  55. package/lib/modules/Payment/walletpass.js +23 -1
  56. package/lib/modules/Product/index.d.ts +1 -1
  57. package/lib/modules/ProductList/index.js +15 -0
  58. package/lib/modules/Rules/index.d.ts +5 -10
  59. package/lib/modules/Rules/index.js +68 -22
  60. package/lib/modules/Rules/promotionSelection.d.ts +14 -0
  61. package/lib/modules/Rules/promotionSelection.js +230 -0
  62. package/lib/modules/Rules/types.d.ts +9 -0
  63. package/lib/server/modules/order/index.d.ts +6 -0
  64. package/lib/server/modules/order/index.js +226 -29
  65. package/lib/solution/BaseSales/index.d.ts +16 -1
  66. package/lib/solution/BaseSales/index.js +108 -14
  67. package/lib/solution/BaseSales/utils/cartPromotion.js +5 -2
  68. package/lib/solution/BookingByStep/index.d.ts +2 -2
  69. package/lib/solution/BookingTicket/index.js +38 -2
  70. package/lib/solution/BookingTicket/types.d.ts +14 -2
  71. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  72. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -3
  73. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +14 -2
  74. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +10 -0
  75. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +71 -0
  76. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  77. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  78. package/lib/solution/UnifiedBookingSales/index.d.ts +1 -1
  79. package/lib/solution/UnifiedBookingSales/index.js +14 -3
  80. package/lib/utils/platform.d.ts +2 -0
  81. package/lib/utils/platform.js +7 -0
  82. package/package.json +1 -1
@@ -457,6 +457,8 @@ export type AddProductBookingInput = Record<string, any>;
457
457
  * 避免步进器修改数量改变该组展示位置。
458
458
  */
459
459
  export interface AddProductToOrderOptions {
460
+ /** Associates a selection with an existing runtime voucher group. */
461
+ productVoucherGroupKey?: string;
460
462
  insertAfterProductUid?: string;
461
463
  /** 新增商品行插入 products 首位,优先于 insertAfterProductUid。 */
462
464
  insertAtStart?: boolean;
@@ -557,6 +559,11 @@ export interface OrderHooksConfig {
557
559
  beforeCartIntentCommit?: (context: OrderCartIntentCommitContext) => void;
558
560
  /** Captures tenant/business runtime identity for asynchronous cart intents. */
559
561
  getCartIntentScope?: () => unknown;
562
+ /** Awaited before a local cart draft is published. Reject to leave the live order unchanged. */
563
+ onBeforeCartCommit?: (context: {
564
+ currentItems: readonly OrderProduct[];
565
+ proposedItems: readonly OrderProduct[];
566
+ }) => void | Promise<void>;
560
567
  onBeforeMergeProductToOrder?: (context: OrderProductMergeDecisionContext) => OrderProductMergeDecisionResult | Promise<OrderProductMergeDecisionResult>;
561
568
  }
562
569
  /**
@@ -279,7 +279,7 @@ export function consolidateDiscountFreeProductLines(tempOrder) {
279
279
  _step6;
280
280
  try {
281
281
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
282
- var _product$booking_uid, _product$metadata4, _booking_id, _product$metadata5, _product$order_detail, _holder_id, _product$metadata6, _product$metadata7, _product$metadata8, _product$product_sku2, _product$metadata9, _tempOrder$_extend, _product$selling_pric, _product$original_pri, _custom_price, _product$is_charge_ta, _product$gift_card, _product$bundle_edit, _product$metadata$pri, _product$metadata10, _product$metadata$sou, _product$metadata11, _product$metadata$mai, _product$metadata12, _product$metadata$mai2, _product$metadata13, _product$product_vari;
282
+ var _product$booking_uid, _product$metadata4, _booking_id, _product$metadata5, _product$order_detail, _holder_id, _product$metadata6, _product$metadata7, _product$metadata8, _product$product_sku2, _product$metadata9, _tempOrder$_extend, _product$selling_pric, _product$original_pri, _custom_price, _product$is_charge_ta, _product$gift_card, _product$bundle_edit, _product$metadata$pri, _product$metadata10, _product$metadata$sou, _product$metadata11, _product$metadata$mai, _product$metadata12, _product$metadata$mai2, _product$metadata13, _tempOrder$_extend$pr, _tempOrder$_extend2, _product$product_vari;
283
283
  var product = _step6.value;
284
284
  var productBundle = Array.isArray(product.product_bundle) ? product.product_bundle : [];
285
285
  var hasDiscount = (product.discount_list || []).length > 0 || productBundle.some(function (bundle) {
@@ -337,7 +337,7 @@ export function consolidateDiscountFreeProductLines(tempOrder) {
337
337
  };
338
338
  })
339
339
  });
340
- var mergeKey = [discountSplitOriginUid, product.product_id, (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0, fingerprint, priceSignature].join('#');
340
+ var mergeKey = [discountSplitOriginUid, productUid ? (_tempOrder$_extend$pr = (_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.productsByUid) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2[productUid]) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.productVoucherGroupKey) !== null && _tempOrder$_extend$pr !== void 0 ? _tempOrder$_extend$pr : '' : '', product.product_id, (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0, fingerprint, priceSignature].join('#');
341
341
  var matchedIndex = productIndexByKey.get(mergeKey);
342
342
 
343
343
  // 当前拆分来源 + 商品结构组合第一次出现时,保留该行作为回并目标。
@@ -0,0 +1,15 @@
1
+ import type { Discount } from '../../Discount/types';
2
+ import type { OrderTempOrder } from '../types';
3
+ /** Runtime-only allocation constraints. Never copied into order/product metadata. */
4
+ export interface ProductVoucherGroup {
5
+ key: string;
6
+ discountIds: Array<number | string>;
7
+ }
8
+ export declare function productVoucherGroupKey(order: OrderTempOrder, product: any): string | undefined;
9
+ export declare function isUsableProductVoucher(discount: Discount): boolean;
10
+ export declare function voucherGroupError(): Error & {
11
+ code: string;
12
+ };
13
+ export declare function allowsProductVoucher(order: OrderTempOrder | null | undefined, product: any, discount: Discount): boolean;
14
+ /** Reductions stay possible when a voucher expires; checkout always requires full coverage. */
15
+ export declare function validateProductVoucherGroups(order: OrderTempOrder, discounts: Discount[], previous?: OrderTempOrder, requireCoverage?: boolean): void;
@@ -0,0 +1,115 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
+ import { getDiscountUsageBlockReason } from "../../Discount/availability";
5
+ import dayjs from 'dayjs';
6
+ import { getDiscountTimeUnavailableReason } from "../../../solution/ShopDiscount/utils";
7
+
8
+ /** Runtime-only allocation constraints. Never copied into order/product metadata. */
9
+
10
+ export function productVoucherGroupKey(order, product) {
11
+ var _product$metadata$uni, _product$metadata, _order$_extend;
12
+ var uid = (_product$metadata$uni = product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product === null || product === void 0 ? void 0 : product.unique_identification_number;
13
+ return (_order$_extend = order._extend) === null || _order$_extend === void 0 || (_order$_extend = _order$_extend.productsByUid) === null || _order$_extend === void 0 || (_order$_extend = _order$_extend[String(uid)]) === null || _order$_extend === void 0 ? void 0 : _order$_extend.productVoucherGroupKey;
14
+ }
15
+ export function isUsableProductVoucher(discount) {
16
+ return (discount.tag || discount.type) === 'good_pass' && !discount.isEditMode && !discount.isDisabled && !getDiscountUsageBlockReason(discount) && !getDiscountTimeUnavailableReason(discount, dayjs().format('YYYY-MM-DD HH:mm:ss'));
17
+ }
18
+ export function voucherGroupError() {
19
+ return Object.assign(new Error('The selected items no longer match the available vouchers. Please adjust your selection.'), {
20
+ code: 'PRODUCT_VOUCHER_GROUP_INVALID'
21
+ });
22
+ }
23
+ export function allowsProductVoucher(order, product, discount) {
24
+ var _order$_extend2, _groups$find;
25
+ var groups = order === null || order === void 0 || (_order$_extend2 = order._extend) === null || _order$_extend2 === void 0 ? void 0 : _order$_extend2.productVoucherGroups;
26
+ if (!order || !(groups !== null && groups !== void 0 && groups.length)) return true;
27
+ var key = productVoucherGroupKey(order, product);
28
+ if (!key) return !groups.some(function (group) {
29
+ return group.discountIds.some(function (id) {
30
+ return String(id) === String(discount.id);
31
+ });
32
+ });
33
+ return (discount.tag || discount.type) === 'good_pass' && Boolean((_groups$find = groups.find(function (group) {
34
+ return group.key === key;
35
+ })) === null || _groups$find === void 0 ? void 0 : _groups$find.discountIds.some(function (id) {
36
+ return String(id) === String(discount.id);
37
+ }));
38
+ }
39
+
40
+ /** Reductions stay possible when a voucher expires; checkout always requires full coverage. */
41
+ export function validateProductVoucherGroups(order, discounts, previous) {
42
+ var _order$_extend3;
43
+ var requireCoverage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
44
+ var groups = (_order$_extend3 = order._extend) === null || _order$_extend3 === void 0 ? void 0 : _order$_extend3.productVoucherGroups;
45
+ if (!(groups !== null && groups !== void 0 && groups.length)) return;
46
+ var usedIds = new Set();
47
+ var byId = new Map(discounts.filter(isUsableProductVoucher).map(function (discount) {
48
+ return [String(discount.id), discount];
49
+ }));
50
+ var quantity = function quantity(item) {
51
+ var _ref, _item$num;
52
+ return Number((_ref = (_item$num = item.num) !== null && _item$num !== void 0 ? _item$num : item.product_quantity) !== null && _ref !== void 0 ? _ref : 0);
53
+ };
54
+ var _iterator = _createForOfIteratorHelper(groups),
55
+ _step;
56
+ try {
57
+ var _loop = function _loop() {
58
+ var _previous$products$fi;
59
+ var group = _step.value;
60
+ var items = order.products.filter(function (item) {
61
+ return productVoucherGroupKey(order, item) === group.key;
62
+ });
63
+ var selected = items.reduce(function (sum, item) {
64
+ return sum + quantity(item);
65
+ }, 0);
66
+ var before = (_previous$products$fi = previous === null || previous === void 0 ? void 0 : previous.products.filter(function (item) {
67
+ return productVoucherGroupKey(previous, item) === group.key;
68
+ }).reduce(function (sum, item) {
69
+ return sum + quantity(item);
70
+ }, 0)) !== null && _previous$products$fi !== void 0 ? _previous$products$fi : 0;
71
+ if (!requireCoverage && previous && selected <= before) return 0; // continue
72
+ var ids = new Set(group.discountIds.map(String).filter(function (id) {
73
+ return byId.has(id);
74
+ }));
75
+ if (!Number.isInteger(selected) || selected < 0 || selected > ids.size) throw voucherGroupError();
76
+ if (!requireCoverage) return 0; // continue
77
+ var _iterator2 = _createForOfIteratorHelper(items),
78
+ _step2;
79
+ try {
80
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
81
+ var _applied$0$discount$r, _applied$, _voucher$config;
82
+ var item = _step2.value;
83
+ var applied = (item.discount_list || []).filter(function (entry) {
84
+ return (entry.type || entry.tag) === 'good_pass';
85
+ });
86
+ // Rules splits a good_pass allocation into one physical line per instance.
87
+ var id = String((_applied$0$discount$r = (_applied$ = applied[0]) === null || _applied$ === void 0 || (_applied$ = _applied$.discount) === null || _applied$ === void 0 ? void 0 : _applied$.resource_id) !== null && _applied$0$discount$r !== void 0 ? _applied$0$discount$r : '');
88
+ var voucher = byId.get(id);
89
+ if (quantity(item) !== 1 || applied.length !== 1 || !ids.has(id) || !(voucher !== null && voucher !== void 0 && voucher.isAvailable) || ((_voucher$config = voucher.config) === null || _voucher$config === void 0 ? void 0 : _voucher$config.isAvailable) === false || usedIds.has(id)) throw voucherGroupError();
90
+ usedIds.add(id);
91
+ }
92
+ } catch (err) {
93
+ _iterator2.e(err);
94
+ } finally {
95
+ _iterator2.f();
96
+ }
97
+ },
98
+ _ret;
99
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
100
+ _ret = _loop();
101
+ if (_ret === 0) continue;
102
+ }
103
+ } catch (err) {
104
+ _iterator.e(err);
105
+ } finally {
106
+ _iterator.f();
107
+ }
108
+ if (order.products.some(function (item) {
109
+ return !groups.some(function (group) {
110
+ return group.key === productVoucherGroupKey(order, item);
111
+ });
112
+ })) {
113
+ throw voucherGroupError();
114
+ }
115
+ }
@@ -1525,7 +1525,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1525
1525
  key: "scanWalletAssetAsync",
1526
1526
  value: function () {
1527
1527
  var _scanWalletAssetAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(code) {
1528
- var normalizedCode, selectedAsset, result, paymentAssets, asset, items, recalculatedState, assetId, recalculatedAsset, selected, isSelected, selectedStateAsset, resolvedAsset;
1528
+ var normalizedCode, selectedAsset, result, paymentAssets, matchedAsset, assetsToApply, asset, _items, assetIds, selectionSources, _selected, items, recalculatedState, assetId, recalculatedAsset, selected, isSelected, selectedStateAsset, resolvedAsset;
1529
1529
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1530
1530
  while (1) switch (_context9.prev = _context9.next) {
1531
1531
  case 0:
@@ -1578,11 +1578,13 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1578
1578
  if (paymentAssets.length > 0) {
1579
1579
  this.searchResults = mergeWalletAssets(this.searchResults, paymentAssets);
1580
1580
  }
1581
- asset = paymentAssets.find(function (item) {
1581
+ matchedAsset = paymentAssets.find(function (item) {
1582
1582
  return String((item === null || item === void 0 ? void 0 : item.code) || '') === normalizedCode;
1583
- }) || paymentAssets[0];
1583
+ }); // 精确命中券码时仅处理该券;未命中时处理接口返回的全部结果。
1584
+ assetsToApply = matchedAsset ? [matchedAsset] : paymentAssets;
1585
+ asset = assetsToApply[0];
1584
1586
  if (asset) {
1585
- _context9.next = 17;
1587
+ _context9.next = 19;
1586
1588
  break;
1587
1589
  }
1588
1590
  return _context9.abrupt("return", {
@@ -1591,7 +1593,31 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1591
1593
  selected: false,
1592
1594
  state: this.getWalletAssetsState()
1593
1595
  });
1594
- case 17:
1596
+ case 19:
1597
+ if (!(!matchedAsset && assetsToApply.length > 1)) {
1598
+ _context9.next = 26;
1599
+ break;
1600
+ }
1601
+ _items = mergeWalletAssets(this.walletAssetsState.items, assetsToApply);
1602
+ assetIds = assetsToApply.map(function (item) {
1603
+ return getWalletAssetId(item);
1604
+ }).filter(function (id) {
1605
+ return id !== undefined && id !== null;
1606
+ });
1607
+ selectionSources = _objectSpread({}, this.walletAssetsState.selectionSources);
1608
+ assetIds.forEach(function (id) {
1609
+ selectionSources[String(id)] = 'scan';
1610
+ });
1611
+ _selected = this.walletAssetsBehavior.autoSelectAfterSearch ? this.recalculateWalletAssets(_items, Array.from(new Set([].concat(_toConsumableArray(this.walletAssetsState.selectedIds), _toConsumableArray(assetIds)))), selectionSources) : this.recalculateWalletAssets(_items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1612
+ return _context9.abrupt("return", {
1613
+ type: result.type,
1614
+ asset: asset,
1615
+ selected: assetIds.some(function (id) {
1616
+ return _selected.selectedIds.includes(id);
1617
+ }),
1618
+ state: _selected
1619
+ });
1620
+ case 26:
1595
1621
  items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1596
1622
  recalculatedState = this.recalculateWalletAssets(items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1597
1623
  assetId = getWalletAssetId(asset);
@@ -1621,7 +1647,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1621
1647
  selected: isSelected,
1622
1648
  state: selected
1623
1649
  });
1624
- case 27:
1650
+ case 36:
1625
1651
  case "end":
1626
1652
  return _context9.stop();
1627
1653
  }
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "normal" | "session";
53
53
  }
@@ -99,7 +99,13 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
99
99
  }, {
100
100
  key: "updateOtherParams",
101
101
  value: function updateOtherParams(params) {
102
+ var previousScope = this.otherParams.catalogScopeKey;
102
103
  this.otherParams = params || {};
104
+ if (previousScope !== this.otherParams.catalogScopeKey && (previousScope || this.otherParams.catalogScopeKey)) {
105
+ this.store.list = [];
106
+ this.rawProductPriceSources.clear();
107
+ this.core.effects.emit("".concat(this.name, ":changed"), this.store.list);
108
+ }
103
109
  }
104
110
  }, {
105
111
  key: "storeChange",
@@ -155,12 +161,12 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
155
161
  key: "loadProducts",
156
162
  value: function () {
157
163
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
158
- var _this$otherParams,
164
+ var _this2 = this,
165
+ _this$otherParams,
159
166
  _this$otherParams$bus,
160
167
  _this$otherParams2,
161
168
  _this$otherParams3,
162
- _this$otherParams4,
163
- _this2 = this;
169
+ _this$otherParams4;
164
170
  var _ref,
165
171
  _ref$category_ids,
166
172
  category_ids,
@@ -182,6 +188,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
182
188
  status,
183
189
  strategy_context,
184
190
  options,
191
+ scope,
192
+ assertScope,
185
193
  userPlugin,
186
194
  customer_id,
187
195
  _userPlugin$get,
@@ -203,7 +211,12 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
203
211
  case 0:
204
212
  _ref = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {}, _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, _ref$menu_list_ids = _ref.menu_list_ids, menu_list_ids = _ref$menu_list_ids === void 0 ? [] : _ref$menu_list_ids, paramsCustomerId = _ref.customer_id, _ref$with_count = _ref.with_count, with_count = _ref$with_count === void 0 ? [] : _ref$with_count, schedule_datetime = _ref.schedule_datetime, schedule_date = _ref.schedule_date, cacheId = _ref.cacheId, with_schedule = _ref.with_schedule, extension_type = _ref.extension_type, _ref$status = _ref.status, status = _ref$status === void 0 ? 'published' : _ref$status, strategy_context = _ref.strategy_context;
205
213
  options = _args5.length > 1 ? _args5[1] : undefined;
206
- // // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
214
+ scope = this.otherParams.catalogScopeKey;
215
+ assertScope = function assertScope() {
216
+ if (scope !== _this2.otherParams.catalogScopeKey) throw Object.assign(new Error('Product catalog context changed'), {
217
+ name: 'AbortError'
218
+ });
219
+ }; // // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
207
220
  // if (!schedule_ids?.length) {
208
221
  // const schedule_ids_data = this.store.schedule
209
222
  // .getScheduleListByIds(schedule_ids)
@@ -280,14 +293,20 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
280
293
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
281
294
  while (1) switch (_context4.prev = _context4.next) {
282
295
  case 0:
296
+ if (!(scope !== _this2.otherParams.catalogScopeKey)) {
297
+ _context4.next = 2;
298
+ break;
299
+ }
300
+ return _context4.abrupt("return");
301
+ case 2:
283
302
  callbackList = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.list;
284
303
  if (Array.isArray(callbackList)) {
285
- _context4.next = 4;
304
+ _context4.next = 6;
286
305
  break;
287
306
  }
288
307
  originalCallback(result);
289
308
  return _context4.abrupt("return");
290
- case 4:
309
+ case 6:
291
310
  if (!handledByOsServer) {
292
311
  // Subscription callbacks may contain only changed products. Upsert
293
312
  // their raw records without evicting other IDs from the scope.
@@ -300,15 +319,16 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
300
319
  queryPayload: queryPayload,
301
320
  handledByOsServer: handledByOsServer
302
321
  });
303
- _context4.next = 8;
322
+ assertScope();
323
+ _context4.next = 11;
304
324
  return _this2.addProduct(products);
305
- case 8:
325
+ case 11:
306
326
  originalCallback(handledByOsServer ? result : _objectSpread(_objectSpread({}, result), {}, {
307
327
  data: _objectSpread(_objectSpread({}, result.data), {}, {
308
328
  list: products
309
329
  })
310
330
  }));
311
- case 9:
331
+ case 12:
312
332
  case "end":
313
333
  return _context4.stop();
314
334
  }
@@ -318,15 +338,16 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
318
338
  return _ref2.apply(this, arguments);
319
339
  };
320
340
  }()) : undefined;
321
- _context5.next = 16;
341
+ _context5.next = 18;
322
342
  return this.request.post("/product/query", queryPayload, {
323
343
  osServer: true,
324
344
  callback: subscriptionCallback,
325
345
  subscriberId: options === null || options === void 0 ? void 0 : options.subscriberId,
326
346
  customToast: function customToast() {}
327
347
  });
328
- case 16:
348
+ case 18:
329
349
  productsData = _context5.sent;
350
+ assertScope();
330
351
  if (!handledByOsServer && Array.isArray(productsData.data.list)) {
331
352
  this.replaceRawProductQueryResult(productsData.data.list, product_ids);
332
353
  }
@@ -348,7 +369,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
348
369
  // }
349
370
  this.addProduct(sortedList);
350
371
  return _context5.abrupt("return", sortedList);
351
- case 22:
372
+ case 25:
352
373
  case "end":
353
374
  return _context5.stop();
354
375
  }
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, RulesCalcDiscountOptions, UnavailableReason } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, RulesFormSubject, RulesCalcDiscountOptions, RulesCalcDiscountParams, UnavailableReason } from './types';
4
4
  import { Discount } from '../Discount/types';
5
5
  import { WindowPlugin } from '../../plugins';
6
6
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
@@ -9,6 +9,8 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
9
9
  private store;
10
10
  window: WindowPlugin;
11
11
  private hooks;
12
+ private discountScope?;
13
+ setDiscountScope(scope: (product: any, discount: Discount) => boolean): void;
12
14
  constructor(name?: string, version?: string);
13
15
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
14
16
  setRulesList(rulesList: Rules[]): Promise<void>;
@@ -44,15 +46,8 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
44
46
  resolveDiscountListForManualOverride(discountList: Discount[]): Discount[];
45
47
  private isItemRewardProductDiscount;
46
48
  private getUnavailableReason;
47
- calcDiscount({ discountList, productList, holders, isFormSubject, orderTotalAmount }: {
48
- discountList: Discount[];
49
- productList: any[];
50
- holders: {
51
- form_record_id: number;
52
- }[];
53
- isFormSubject: RulesFormSubject;
54
- orderTotalAmount: number;
55
- }, options?: RulesCalcDiscountOptions): DiscountResult;
49
+ calcDiscount(params: RulesCalcDiscountParams, options?: RulesCalcDiscountOptions): DiscountResult;
50
+ private calcDiscountCore;
56
51
  /**
57
52
  * 检查优惠是否符合 PackageSubItemUsageRules 配置
58
53
  * @param discount 优惠券