@pisell/pisellos 2.2.276 → 2.2.278

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.
@@ -45,7 +45,6 @@ var PisellOSCore = /*#__PURE__*/function () {
45
45
  this.serverOptions = options.server;
46
46
  }
47
47
  this.initialize(options);
48
- console.log('constructor1234');
49
48
  }
50
49
  _createClass(PisellOSCore, [{
51
50
  key: "initialize",
@@ -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,
@@ -506,7 +505,6 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
506
505
  }, {
507
506
  key: "calculateApplicableProducts",
508
507
  value: function calculateApplicableProducts(products, applicableProductIds, deductTaxAndFee) {
509
- console.log(products, 'products1234');
510
508
  var total = 0;
511
509
  var count = 0;
512
510
 
@@ -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;
@@ -166,8 +189,6 @@ var getApplicableProducts = function getApplicableProducts(voucher, productsData
166
189
  * @returns 返回推荐券列表和全部列表,每个券包含 _available_max_amount 和 _unified_available_status
167
190
  */
168
191
  export function processVouchers(applicableVouchers, orderTotalAmount, products) {
169
- console.log(products, 'products123');
170
-
171
192
  // 拆分商品数据,同时维护含税和不含税两个金额池
172
193
  // remainingAmountWithTax: 含税费的剩余可抵扣金额
173
194
  // remainingAmountPure: 纯商品金额(不含税费)的剩余可抵扣金额
@@ -285,7 +306,6 @@ export function processVouchers(applicableVouchers, orderTotalAmount, products)
285
306
  // 辅助函数:判断券是否可用,返回可用性和原因代码
286
307
  var isVoucherAvailable = function isVoucherAvailable(voucher, productsData, usedVoucherCounts, itemPassUsage) {
287
308
  var config = voucher.config,
288
- id = voucher.id,
289
309
  product_id = voucher.product_id;
290
310
 
291
311
  // 根据 deductTaxAndFee 配置获取推荐金额
@@ -659,6 +679,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
659
679
  var productsForCalc = expandProductsWithBundleItems(products, true);
660
680
  var remainingOrderAmount = new Decimal(orderTotalAmount);
661
681
  var selectedWithDetails = [];
682
+ var usedVoucherCounts = new Map();
662
683
 
663
684
  // 追踪每个 Wallet Pass 商品对每个订单商品行的已使用卡券次数(按行唯一键)
664
685
  var itemPassUsageMap = new Map();
@@ -678,15 +699,26 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
678
699
  // 第一步:按顺序应用已选中的券,计算实际抵扣
679
700
  selectedVouchers.forEach(function (selectedVoucher) {
680
701
  var _selectedVoucher$_ava;
681
- var config = selectedVoucher.config,
682
- id = selectedVoucher.id;
702
+ var product_id = selectedVoucher.product_id;
703
+ var config = getWalletPassCalculationConfig(selectedVoucher);
683
704
  var maxDeductionAmount = config.maxDeductionAmount,
705
+ maxUsagePerOrder = config.maxUsagePerOrder,
684
706
  allowCrossProduct = config.allowCrossProduct,
685
707
  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;
708
+ deductTaxAndFee = config.deductTaxAndFee,
709
+ maxPassesPerItem = config.maxPassesPerItem;
710
+ var usedCount = usedVoucherCounts.get(product_id) || 0;
711
+ if (maxUsagePerOrder > 0 && usedCount >= maxUsagePerOrder) {
712
+ selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
713
+ config: config,
714
+ actualDeduction: 0,
715
+ deductionDetails: [],
716
+ _available_max_amount: 0,
717
+ _unified_available_status: 0,
718
+ reasonCode: 'usage_limit_reached'
719
+ }));
720
+ return;
721
+ }
690
722
 
691
723
  // 根据券的配置选择使用哪个单价字段和金额字段
692
724
  var unitPriceField = deductTaxAndFee ? 'unitPriceWithTax' : 'unitPricePure';
@@ -702,6 +734,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
702
734
  if (applicableProducts.length === 0) {
703
735
  // 无适用商品,跳过
704
736
  selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
737
+ config: config,
705
738
  actualDeduction: 0,
706
739
  deductionDetails: [],
707
740
  _available_max_amount: 0,
@@ -798,6 +831,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
798
831
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
799
832
  applyMaxPassUsageIncrements(itemPassUsageMap, selectedVoucher.product_id, maxPassesPerItem, deductionDetails);
800
833
  selectedWithDetails.push(_objectSpread(_objectSpread({}, selectedVoucher), {}, {
834
+ config: config,
801
835
  actualDeduction: totalDeducted.toNumber(),
802
836
  // 转换为数字
803
837
  deductionDetails: deductionDetails,
@@ -805,16 +839,15 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
805
839
  // 转换为数字
806
840
  _unified_available_status: totalDeducted.greaterThan(0) ? 1 : 0
807
841
  }));
842
+ if (totalDeducted.greaterThan(0)) {
843
+ usedVoucherCounts.set(product_id, usedCount + 1);
844
+ }
808
845
  });
809
846
 
810
847
  // 第二步:为所有券重新计算 _available_max_amount 和 _unified_available_status
811
848
  var selectedIds = new Set(selectedVouchers.map(function (v) {
812
849
  return v.id;
813
850
  }));
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
851
  var allWithUpdatedStatus = allVouchers.map(function (voucher) {
819
852
  // 如果是已选中的券,使用详细计算结果
820
853
  if (selectedIds.has(voucher.id)) {
@@ -825,16 +858,13 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
825
858
  }
826
859
 
827
860
  // 未选中的券,重新计算其可用状态
828
- var config = voucher.config,
829
- id = voucher.id,
830
- product_id = voucher.product_id;
861
+ var product_id = voucher.product_id;
862
+ var config = getWalletPassCalculationConfig(voucher);
831
863
  var maxDeductionAmount = config.maxDeductionAmount,
832
864
  allowCrossProduct = config.allowCrossProduct,
833
865
  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;
866
+ deductTaxAndFee = config.deductTaxAndFee,
867
+ maxPassesPerItem = config.maxPassesPerItem;
838
868
 
839
869
  // 根据券的配置选择使用哪个单价字段和金额字段
840
870
  var unitPriceField = deductTaxAndFee ? 'unitPriceWithTax' : 'unitPricePure';
@@ -929,6 +959,7 @@ export function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmo
929
959
  }
930
960
  }
931
961
  return _objectSpread(_objectSpread({}, voucher), {}, {
962
+ config: config,
932
963
  _available_max_amount: calculatedMaxAmount.toNumber(),
933
964
  // 转换为数字
934
965
  _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;