@pisell/pisellos 2.3.60 → 2.3.62

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.
@@ -1,9 +0,0 @@
1
- // 导出评估器
2
- export { PromotionEvaluator } from "./evaluator";
3
-
4
- // 导出适配器
5
- export { PromotionAdapter } from "./adapter";
6
- export { default } from "./adapter";
7
-
8
- // 导出策略配置示例常量
9
- export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, ITEM_REWARD_STRATEGY } from "./examples";
@@ -257,7 +257,6 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
257
257
  var rawText = this.getText(reasonCode);
258
258
  // 金额类型字段:从 otherParams.getData 取货币符号;非金额或取不到则留空
259
259
  var currency = failedField && AMOUNT_FIELDS.has(failedField) ? ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 || (_this$otherParams$get = (_this$otherParams2 = _this$otherParams).getData) === null || _this$otherParams$get === void 0 ? void 0 : _this$otherParams$get.call(_this$otherParams2, 'shop_symbol')) || '' : '';
260
- console.log(currency, 'currency12345');
261
260
  var reason = thresholdValue !== undefined ? formatReason(rawText, thresholdValue, currency) : rawText;
262
261
  results.push({
263
262
  voucher: voucher,
@@ -26,6 +26,11 @@ export interface Voucher {
26
26
  recommended_usage_amount: number;
27
27
  /** 后端计算推荐使用金额(仅商品) 不包含税费附加费 */
28
28
  recommended_pure_product_usage_amount: number;
29
+ /**
30
+ * 扫码资产自身可供前端重新计算的金额基准。
31
+ * 后端 recommended_usage_amount 会包含当前已选券上下文,取消勾选后不能继续把它当作资产永久上限。
32
+ */
33
+ _wallet_asset_recalculation_base_amount?: number;
29
34
  /** 实际抵扣金额 */
30
35
  actualDeduction: number;
31
36
  /** 抵扣详情 */
@@ -1,9 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
2
  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; } } }; }
8
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
4
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -11,7 +6,25 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
11
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
8
  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; }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
14
  import Decimal from 'decimal.js';
15
+ var DEFAULT_WALLET_PASS_CALCULATION_CONFIG = {
16
+ maxDeductionAmount: 99999,
17
+ maxUsagePerOrder: 0,
18
+ allowCrossProduct: true,
19
+ applicableProductLimit: 0,
20
+ deductTaxAndFee: true,
21
+ maxPassesPerItem: 0,
22
+ deductOptionPrice: false
23
+ };
24
+ function getWalletPassCalculationConfig(voucher) {
25
+ return _objectSpread(_objectSpread({}, DEFAULT_WALLET_PASS_CALCULATION_CONFIG), (voucher === null || voucher === void 0 ? void 0 : voucher.config) || {});
26
+ }
27
+
15
28
  /** 订单商品数量 */
16
29
  export var getProductQuantity = function getProductQuantity(product) {
17
30
  return product.quantity || product.product_quantity || 1;
@@ -72,12 +85,22 @@ function applyMaxPassUsageIncrements(usageMap, walletPassProductId, maxPassesPer
72
85
  // 辅助函数:根据 deductTaxAndFee 配置获取推荐使用金额
73
86
  var getRecommendedAmount = function getRecommendedAmount(voucher) {
74
87
  var _config$deductTaxAndF;
75
- console.log('voucher312', voucher);
76
88
  var config = voucher.config,
77
89
  recommended_usage_amount = voucher.recommended_usage_amount,
78
90
  recommended_pure_product_usage_amount = voucher.recommended_pure_product_usage_amount;
79
91
  var deductTaxAndFee = (_config$deductTaxAndF = config === null || config === void 0 ? void 0 : config.deductTaxAndFee) !== null && _config$deductTaxAndF !== void 0 ? _config$deductTaxAndF : true; // 默认开启抵扣税费
80
92
 
93
+ // 扫码接口的 recommended_* 金额包含搜索时已选券的上下文,可能只是当时的
94
+ // 剩余可抵扣额。取消其他券后,前端重算需要回到资产自身金额基准,再由
95
+ // 剩余订单金额、适用商品金额和策略上限重新裁剪。
96
+ var rawRecalculationBaseAmount = voucher._wallet_asset_recalculation_base_amount;
97
+ if (rawRecalculationBaseAmount !== undefined && rawRecalculationBaseAmount !== null) {
98
+ var recalculationBaseAmount = Number(rawRecalculationBaseAmount);
99
+ if (Number.isFinite(recalculationBaseAmount) && recalculationBaseAmount >= 0) {
100
+ return recalculationBaseAmount;
101
+ }
102
+ }
103
+
81
104
  // 如果开启抵扣税费,使用 recommended_usage_amount(包含税费)
82
105
  // 如果关闭抵扣税费,使用 recommended_pure_product_usage_amount(仅商品金额)
83
106
  return deductTaxAndFee ? recommended_usage_amount : recommended_pure_product_usage_amount !== null && recommended_pure_product_usage_amount !== void 0 ? recommended_pure_product_usage_amount : recommended_usage_amount;
@@ -285,7 +308,6 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
285
308
  // 辅助函数:判断券是否可用,返回可用性和原因代码
286
309
  var isVoucherAvailable = function isVoucherAvailable(voucher, productsData, usedVoucherCounts, itemPassUsage) {
287
310
  var config = voucher.config,
288
- id = voucher.id,
289
311
  product_id = voucher.product_id;
290
312
 
291
313
  // 根据 deductTaxAndFee 配置获取推荐金额
@@ -659,6 +681,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
659
681
  var productsForCalc = expandProductsWithBundleItems(products, true);
660
682
  var remainingOrderAmount = new Decimal(orderTotalAmount);
661
683
  var selectedWithDetails = [];
684
+ var usedVoucherCounts = new Map();
662
685
 
663
686
  // 追踪每个 Wallet Pass 商品对每个订单商品行的已使用卡券次数(按行唯一键)
664
687
  var itemPassUsageMap = new Map();
@@ -678,15 +701,26 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
678
701
  // 第一步:按顺序应用已选中的券,计算实际抵扣
679
702
  selectedVouchers.forEach(function (selectedVoucher) {
680
703
  var _selectedVoucher$_ava;
681
- var config = selectedVoucher.config,
682
- id = selectedVoucher.id;
704
+ var product_id = selectedVoucher.product_id;
705
+ var config = getWalletPassCalculationConfig(selectedVoucher);
683
706
  var maxDeductionAmount = config.maxDeductionAmount,
707
+ maxUsagePerOrder = config.maxUsagePerOrder,
684
708
  allowCrossProduct = config.allowCrossProduct,
685
709
  applicableProductLimit = config.applicableProductLimit,
686
- _config$deductTaxAndF4 = config.deductTaxAndFee,
687
- deductTaxAndFee = _config$deductTaxAndF4 === void 0 ? true : _config$deductTaxAndF4,
688
- _config$maxPassesPerI = config.maxPassesPerItem,
689
- maxPassesPerItem = _config$maxPassesPerI === void 0 ? 0 : _config$maxPassesPerI;
710
+ deductTaxAndFee = config.deductTaxAndFee,
711
+ maxPassesPerItem = config.maxPassesPerItem;
712
+ var usedCount = usedVoucherCounts.get(product_id) || 0;
713
+ if (maxUsagePerOrder > 0 && usedCount >= maxUsagePerOrder) {
714
+ selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
715
+ config: config,
716
+ actualDeduction: 0,
717
+ deductionDetails: [],
718
+ _available_max_amount: 0,
719
+ _unified_available_status: 0,
720
+ reasonCode: 'usage_limit_reached'
721
+ }));
722
+ return;
723
+ }
690
724
 
691
725
  // 根据券的配置选择使用哪个单价字段和金额字段
692
726
  var unitPriceField = deductTaxAndFee ? 'unitPriceWithTax' : 'unitPricePure';
@@ -702,6 +736,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
702
736
  if (applicableProducts.length === 0) {
703
737
  // 无适用商品,跳过
704
738
  selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
739
+ config: config,
705
740
  actualDeduction: 0,
706
741
  deductionDetails: [],
707
742
  _available_max_amount: 0,
@@ -798,6 +833,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
798
833
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
799
834
  applyMaxPassUsageIncrements(itemPassUsageMap, selectedVoucher.product_id, maxPassesPerItem, deductionDetails);
800
835
  selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
836
+ config: config,
801
837
  actualDeduction: totalDeducted.toNumber(),
802
838
  // 转换为数字
803
839
  deductionDetails: deductionDetails,
@@ -805,16 +841,15 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
805
841
  // 转换为数字
806
842
  _unified_available_status: totalDeducted.greaterThan(0) ? 1 : 0
807
843
  }));
844
+ if (totalDeducted.greaterThan(0)) {
845
+ usedVoucherCounts.set(product_id, usedCount + 1);
846
+ }
808
847
  });
809
848
 
810
849
  // 第二步:为所有券重新计算 _available_max_amount 和 _unified_available_status
811
850
  var selectedIds = new Set(selectedVouchers.map(function (v) {
812
851
  return v.id;
813
852
  }));
814
- var usedVoucherCounts = new Map();
815
- selectedVouchers.forEach(function (v) {
816
- usedVoucherCounts.set(v.product_id, (usedVoucherCounts.get(v.product_id) || 0) + 1);
817
- });
818
853
  var allWithUpdatedStatus = allVouchers.map(function (voucher) {
819
854
  // 如果是已选中的券,使用详细计算结果
820
855
  if (selectedIds.has(voucher.id)) {
@@ -825,16 +860,13 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
825
860
  }
826
861
 
827
862
  // 未选中的券,重新计算其可用状态
828
- var config = voucher.config,
829
- id = voucher.id,
830
- product_id = voucher.product_id;
863
+ var product_id = voucher.product_id;
864
+ var config = getWalletPassCalculationConfig(voucher);
831
865
  var maxDeductionAmount = config.maxDeductionAmount,
832
866
  allowCrossProduct = config.allowCrossProduct,
833
867
  applicableProductLimit = config.applicableProductLimit,
834
- _config$deductTaxAndF5 = config.deductTaxAndFee,
835
- deductTaxAndFee = _config$deductTaxAndF5 === void 0 ? true : _config$deductTaxAndF5,
836
- _config$maxPassesPerI2 = config.maxPassesPerItem,
837
- maxPassesPerItem = _config$maxPassesPerI2 === void 0 ? 0 : _config$maxPassesPerI2;
868
+ deductTaxAndFee = config.deductTaxAndFee,
869
+ maxPassesPerItem = config.maxPassesPerItem;
838
870
 
839
871
  // 根据券的配置选择使用哪个单价字段和金额字段
840
872
  var unitPriceField = deductTaxAndFee ? 'unitPriceWithTax' : 'unitPricePure';
@@ -929,6 +961,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
929
961
  }
930
962
  }
931
963
  return _objectSpread(_objectSpread({}, voucher), {}, {
964
+ config: config,
932
965
  _available_max_amount: calculatedMaxAmount.toNumber(),
933
966
  // 转换为数字
934
967
  _unified_available_status: isAvailable ? 1 : 0
@@ -486,6 +486,8 @@ export interface WalletPassPayment {
486
486
  importWalletAssetsSnapshot: (snapshot: WalletAssetsSnapshot) => WalletAssetsState;
487
487
  /** 设置单张钱包资产的选择状态并重新计算其实际抵扣额。 */
488
488
  selectWalletAsset: (assetId: WalletAssetId, options: SelectWalletAssetOptions) => WalletAssetsState;
489
+ /** 更新已选钱包资产的手动使用金额,并保持原有选择顺序重新计算。 */
490
+ updateWalletAssetAmount: (assetId: WalletAssetId, amount: number) => WalletAssetsState;
489
491
  /** 精确搜索钱包资产;仅当前券可用时自动选择。 */
490
492
  scanWalletAssetAsync: (code: string) => Promise<ScanWalletAssetResult>;
491
493
  /** 清空未确认的钱包资产选择。 */
@@ -12,9 +12,12 @@ export var getAvailableMaxAmount = function getAvailableMaxAmount(data) {
12
12
  */
13
13
  export var formatWalletPassList2PreparePayments = function formatWalletPassList2PreparePayments(list) {
14
14
  var formatted = (list || []).map(function (item) {
15
+ var _ref, _item$actualDeduction;
15
16
  return {
16
17
  voucher_id: item.id || 0,
17
- amount: Number(item.edit_current_amount || getAvailableMaxAmount(item)) || 0,
18
+ // 前端策略重算后的 actualDeduction 才是最终可同步金额;
19
+ // edit_current_amount 只是用户请求值,仍可能被策略和订单剩余金额裁剪。
20
+ amount: Number((_ref = (_item$actualDeduction = item.actualDeduction) !== null && _item$actualDeduction !== void 0 ? _item$actualDeduction : item.edit_current_amount) !== null && _ref !== void 0 ? _ref : getAvailableMaxAmount(item)) || 0,
18
21
  tag: item.tag || '',
19
22
  wallet_pass_usage_unit: item.wallet_pass_usage_unit || {},
20
23
  wallet_pass_use_value: item.wallet_pass_use_value || undefined
@@ -24,6 +24,11 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
24
24
  private emitEvent;
25
25
  private publishWalletAssetsState;
26
26
  private recalculateWalletAssets;
27
+ /**
28
+ * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
29
+ * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
30
+ */
31
+ private formatSearchedWalletPaymentAssets;
27
32
  /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
28
33
  private getSearchedWalletAssetCodes;
29
34
  /**
@@ -106,7 +111,13 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
106
111
  getWalletAssetsState(): WalletAssetsState;
107
112
  exportWalletAssetsSnapshot(): WalletAssetsSnapshot;
108
113
  importWalletAssetsSnapshot(snapshot: WalletAssetsSnapshot): WalletAssetsState;
114
+ private updateWalletAssetEditAmountInCaches;
109
115
  selectWalletAsset(assetId: WalletAssetId, options: SelectWalletAssetOptions): WalletAssetsState;
116
+ /**
117
+ * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
118
+ * 金额为 0 时沿用 legacy 行为取消选择。
119
+ */
120
+ updateWalletAssetAmount(assetId: WalletAssetId, amount: number): WalletAssetsState;
110
121
  scanWalletAssetAsync(code: string): Promise<ScanWalletAssetResult>;
111
122
  clearWalletAssetSelection(): WalletAssetsState;
112
123
  setCommittedWalletAssets(committedIds: WalletAssetId[], committedAssets?: any[]): WalletAssetsState;