@pisell/pisellos 0.10.63 → 0.10.65

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.
@@ -456,6 +456,8 @@ export type AddProductBookingInput = Record<string, any>;
456
456
  * 避免步进器修改数量改变该组展示位置。
457
457
  */
458
458
  export interface AddProductToOrderOptions {
459
+ /** Associates a selection with an existing runtime voucher group. */
460
+ productVoucherGroupKey?: string;
459
461
  insertAfterProductUid?: string;
460
462
  /** 跳过同商品/规格匹配,始终新增购物车行。 */
461
463
  disableMerge?: boolean;
@@ -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
+ }
@@ -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>;
@@ -58,10 +58,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
58
58
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
59
59
  // WindowPlugin 实例
60
60
  _defineProperty(_assertThisInitialized(_this), "hooks", void 0);
61
+ _defineProperty(_assertThisInitialized(_this), "discountScope", void 0);
61
62
  _this.hooks = {};
62
63
  return _this;
63
64
  }
64
65
  _createClass(RulesModule, [{
66
+ key: "setDiscountScope",
67
+ value: function setDiscountScope(scope) {
68
+ this.discountScope = scope;
69
+ }
70
+ }, {
65
71
  key: "initialize",
66
72
  value: function () {
67
73
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
@@ -299,7 +305,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
299
305
  _step;
300
306
  try {
301
307
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
302
- var discount = _step.value;
308
+ var _discount = _step.value;
303
309
  var bookingTimes = productList.length ? productList.map(function (item) {
304
310
  var product = _this3.hooks.getProduct(item);
305
311
  return ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
@@ -309,7 +315,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
309
315
  try {
310
316
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
311
317
  var bookingTime = _step3.value;
312
- var filteredList = filterDiscountListByBookingTime([discount], bookingTime);
318
+ var filteredList = filterDiscountListByBookingTime([_discount], bookingTime);
313
319
  if (filteredList.length === 0) {
314
320
  return UnavailableReason.TimeLimit;
315
321
  }
@@ -331,8 +337,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
331
337
  _step2;
332
338
  try {
333
339
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
334
- var _discount = _step2.value;
335
- var limitedData = _discount.limited_relation_product_data;
340
+ var _discount2 = _step2.value;
341
+ var limitedData = _discount2.limited_relation_product_data;
336
342
  var hasApplicableProduct = false;
337
343
  var _iterator4 = _createForOfIteratorHelper(productList),
338
344
  _step4;
@@ -340,11 +346,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
340
346
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
341
347
  var _limitedData$product_;
342
348
  var item = _step4.value;
343
- var product = this.hooks.getProduct(item);
349
+ var _product = this.hooks.getProduct(item);
344
350
  if (limitedData.type === 'product_all') {
345
351
  hasApplicableProduct = true;
346
352
  break;
347
- } else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(product.id)) {
353
+ } else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(_product.id)) {
348
354
  hasApplicableProduct = true;
349
355
  break;
350
356
  }
@@ -405,13 +411,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
405
411
  return selectedDiscount.isEditMode === true && selectedDiscount.isSelected === true && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discountType !== null && discountType !== void 0 ? discountType : '');
406
412
  };
407
413
  var resolveReapplyBookingDiscountPercent = function resolveReapplyBookingDiscountPercent(originProduct, selectedDiscount) {
408
- var _discount2;
414
+ var _discount3;
409
415
  if (!shouldReapplyBookingDiscount(originProduct, selectedDiscount)) return undefined;
410
416
  var discountType = (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.tag) || (selectedDiscount === null || selectedDiscount === void 0 ? void 0 : selectedDiscount.type);
411
417
  if (discountType !== 'discount_card' && discountType !== 'product_discount_card') {
412
418
  return undefined;
413
419
  }
414
- var percent = Number((_discount2 = selectedDiscount.discount) === null || _discount2 === void 0 ? void 0 : _discount2.percent);
420
+ var percent = Number((_discount3 = selectedDiscount.discount) === null || _discount3 === void 0 ? void 0 : _discount3.percent);
415
421
  return Number.isFinite(percent) ? percent : undefined;
416
422
  };
417
423
  var editModeDiscount = [];
@@ -947,7 +953,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
947
953
 
948
954
  // 辅助函数:检查商品是否对某个折扣卡可用
949
955
  var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
950
- var _discount$config2, _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
956
+ var _discount$config2, _product2, _product3, _product4, _flatItem$bundleItem, _flatItem$bundleItem2, _product5;
957
+ if (_this4.discountScope && !_this4.discountScope(flatItem.originProduct, discount)) return false;
951
958
  if (((_discount$config2 = discount.config) === null || _discount$config2 === void 0 ? void 0 : _discount$config2.isAvailable) === false) return false;
952
959
  var product;
953
960
  if (flatItem.type === 'main') {
@@ -970,7 +977,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
970
977
  }
971
978
 
972
979
  // 编辑的商品使用了优惠券不可用
973
- var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
980
+ 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) {
974
981
  return d.id && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
975
982
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
976
983
  return d.id;
@@ -991,7 +998,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
991
998
  var limitedData = discount.limited_relation_product_data;
992
999
 
993
1000
  // 时间限制检查
994
- var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
1001
+ var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
995
1002
  if (!timeLimit) {
996
1003
  return false;
997
1004
  }
@@ -1156,7 +1163,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1156
1163
  }
1157
1164
  var isItemRewardProductDiscount = _this4.isItemRewardProductDiscount(product);
1158
1165
  addModeDiscount.forEach(function (discount) {
1159
- var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config3;
1166
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config3;
1160
1167
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
1161
1168
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
1162
1169
  var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
@@ -1164,14 +1171,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1164
1171
  isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
1165
1172
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
1166
1173
  }, flatItem.originProduct, holders);
1167
- var timeReason = getDiscountTimeUnavailableReason(discount, (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss'));
1174
+ var timeReason = getDiscountTimeUnavailableReason(discount, (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss'));
1168
1175
  var timeLimit = !timeReason;
1169
1176
  // 是符合折扣的商品
1170
1177
  var isProductInScope = limitedData.type === 'product_all' && limitedData.filter !== 1 || limitedData.type === 'product_all' && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id);
1171
1178
  var isLimitedProduct = isProductInScope && isHolderMatch;
1172
1179
 
1173
1180
  // 编辑的商品 使用了优惠券不可用
1174
- var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
1181
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
1175
1182
  return discount.id && ['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
1176
1183
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
1177
1184
  return discount.id;
@@ -1287,7 +1294,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1287
1294
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
1288
1295
  // 🔥 使用扁平化后的列表进行处理
1289
1296
  sortedFlattenedList.forEach(function (flatItem, index) {
1290
- var _product9, _originProduct, _originProduct2, _originProduct3, _product$discount_lis2, _product10;
1297
+ var _product10, _originProduct, _originProduct2, _originProduct3, _product$discount_lis2, _product11;
1291
1298
  // 获取商品数据
1292
1299
  var product, originProduct;
1293
1300
  if (flatItem.type === 'main') {
@@ -1311,8 +1318,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1311
1318
  };
1312
1319
  originProduct = flatItem.originProduct;
1313
1320
  }
1314
- var isPersistedProduct = ((_product9 = product) === null || _product9 === void 0 ? void 0 : _product9.booking_id) || ((_originProduct = originProduct) === null || _originProduct === void 0 ? void 0 : _originProduct.order_detail_id) || ((_originProduct2 = originProduct) === null || _originProduct2 === void 0 ? void 0 : _originProduct2.orderDetailId) || ((_originProduct3 = originProduct) === null || _originProduct3 === void 0 ? void 0 : _originProduct3.booking_id);
1315
- var hasExistingWalletDiscount = ((_product$discount_lis2 = product.discount_list) === null || _product$discount_lis2 === void 0 ? void 0 : _product$discount_lis2.length) && ((_product10 = product) === null || _product10 === void 0 || (_product10 = _product10.discount_list) === null || _product10 === void 0 ? void 0 : _product10.every(function (discount) {
1321
+ var isPersistedProduct = ((_product10 = product) === null || _product10 === void 0 ? void 0 : _product10.booking_id) || ((_originProduct = originProduct) === null || _originProduct === void 0 ? void 0 : _originProduct.order_detail_id) || ((_originProduct2 = originProduct) === null || _originProduct2 === void 0 ? void 0 : _originProduct2.orderDetailId) || ((_originProduct3 = originProduct) === null || _originProduct3 === void 0 ? void 0 : _originProduct3.booking_id);
1322
+ var hasExistingWalletDiscount = ((_product$discount_lis2 = product.discount_list) === null || _product$discount_lis2 === void 0 ? void 0 : _product$discount_lis2.length) && ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 ? void 0 : _product11.every(function (discount) {
1316
1323
  var _discount$id, _discount$discount4;
1317
1324
  var discountIdentity = (_discount$id = discount.id) !== null && _discount$id !== void 0 ? _discount$id : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.resource_id;
1318
1325
  var discountType = discount.tag || discount.type;
@@ -1334,6 +1341,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1334
1341
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1335
1342
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
1336
1343
  var _product$discount_lis3, _product$discount_lis4;
1344
+ if (_this4.discountScope && !_this4.discountScope(originProduct, discount)) return false;
1337
1345
  if (_this4.isItemRewardProductDiscount(product)) return false;
1338
1346
  // 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
1339
1347
  var discountType = discount.tag || discount.type;
@@ -1467,14 +1475,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1467
1475
  var isManualDiscount = false;
1468
1476
  var isItemRewardProductDiscount = false;
1469
1477
  if (flatItem.type === 'main') {
1470
- var _product$discount_lis5, _product$discount_lis6, _product11, _product11$every;
1478
+ var _product$discount_lis5, _product$discount_lis6, _product12, _product12$every;
1471
1479
  // 主商品:判断自身是否手动折扣
1472
1480
  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) {
1473
1481
  return item.type === 'product';
1474
1482
  })) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
1475
1483
  var _ref25;
1476
1484
  return !((_ref25 = item.discount_list || []) !== null && _ref25 !== void 0 && _ref25.length);
1477
- }) && (!((_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) {
1485
+ }) && (!((_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) {
1478
1486
  return item.type === 'product';
1479
1487
  })));
1480
1488
  isItemRewardProductDiscount = _this4.isItemRewardProductDiscount(product);
@@ -1583,8 +1591,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1583
1591
  discount_list: isManualDiscount ? _this4.resolveDiscountListForManualOverride(product.discount_list) : _this4.filterDiscountListByType(product.discount_list, 'promotion')
1584
1592
  }))]);
1585
1593
  } else {
1586
- var _ref27, _product$_promotion$f, _product12, _product$origin_total;
1587
- var total = product.inPromotion ? (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1594
+ var _ref27, _product$_promotion$f, _product13, _product$origin_total;
1595
+ var total = product.inPromotion ? (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
1588
1596
  var main_product_selling_price = product.price;
1589
1597
  if ((product.discount_list || []).some(function (item) {
1590
1598
  return item.type === 'promotion';
@@ -338,7 +338,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
338
338
  discountList: Discount[];
339
339
  originalDiscountList?: Discount[];
340
340
  }): Promise<void>;
341
- scanPromotionCode(code: string, customerId?: number): Promise<BaseSalesScanCodeResult>;
341
+ scanPromotionCode(code: string, customerId?: number, options?: {
342
+ productVouchersOnly?: boolean;
343
+ }): Promise<BaseSalesScanCodeResult>;
342
344
  setDiscountSelected(params: {
343
345
  discountId: number;
344
346
  isSelected: boolean;
@@ -519,6 +521,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
519
521
  private hasSmartPricingStrategies;
520
522
  shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
521
523
  calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
524
+ setProductVoucherGroups(groups: Array<{
525
+ key: string;
526
+ discountIds: Array<number | string>;
527
+ }>): void;
528
+ validateProductVoucherSelection(): void;
522
529
  addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
523
530
  updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
524
531
  updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<import("../../modules/Order/types").OrderProduct[]>;