@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.
@@ -5,15 +5,15 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
5
5
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
10
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
11
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
12
  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."); }
10
13
  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); }
11
14
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
15
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
16
  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; }
14
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
16
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
17
  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; }
18
18
  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; }
19
19
  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; }
@@ -45,6 +45,29 @@ function normalizeWalletAssetCode(code) {
45
45
  function getWalletAssetCodeKeys(asset) {
46
46
  return [asset === null || asset === void 0 ? void 0 : asset.code, asset === null || asset === void 0 ? void 0 : asset.encoded].map(normalizeWalletAssetCode).filter(Boolean);
47
47
  }
48
+
49
+ /**
50
+ * 保存货币类扫码资产自身的可用余额,供后续前端策略重新计算。
51
+ * 搜索接口的 recommended_usage_amount 已扣除了搜索时的已选券,不能作为
52
+ * 取消勾选后的永久上限。积分卡的 balance_par_value 是积分值,不能直接
53
+ * 当作货币金额,因此继续沿用接口推荐金额。
54
+ */
55
+ function withWalletAssetRecalculationBaseAmount(asset) {
56
+ var existingBaseAmount = Number(asset === null || asset === void 0 ? void 0 : asset._wallet_asset_recalculation_base_amount);
57
+ if (Number.isFinite(existingBaseAmount) && existingBaseAmount >= 0) {
58
+ return asset;
59
+ }
60
+ if (!['product_voucher', 'gift_card'].includes(asset === null || asset === void 0 ? void 0 : asset.tag)) {
61
+ return asset;
62
+ }
63
+ var balanceParValue = Number(asset === null || asset === void 0 ? void 0 : asset.balance_par_value);
64
+ if (!Number.isFinite(balanceParValue) || balanceParValue < 0) {
65
+ return asset;
66
+ }
67
+ return _objectSpread(_objectSpread({}, asset), {}, {
68
+ _wallet_asset_recalculation_base_amount: balanceParValue
69
+ });
70
+ }
48
71
  function isWalletAssetAvailable(asset) {
49
72
  if (!asset) return false;
50
73
  if (asset.unified_available_status !== undefined && Number(asset.unified_available_status) !== 1) {
@@ -81,6 +104,26 @@ function mergeWalletAssets() {
81
104
  });
82
105
  return merged;
83
106
  }
107
+
108
+ /**
109
+ * 聚合接口不保证 recalculate_list 顺序;派生抵扣额依赖选择顺序,
110
+ * 因此已选资产必须先恢复为 selectedIds 的顺序再进入策略计算。
111
+ */
112
+ function orderWalletAssetsByIds(assets, orderedIds) {
113
+ var assetByKey = new Map(assets.map(function (asset) {
114
+ return [getWalletAssetKey(asset), asset];
115
+ }));
116
+ var orderedKeys = new Set(orderedIds.map(function (id) {
117
+ return String(id);
118
+ }));
119
+ return [].concat(_toConsumableArray(orderedIds.map(function (id) {
120
+ return assetByKey.get(String(id));
121
+ }).filter(function (asset) {
122
+ return asset !== undefined;
123
+ })), _toConsumableArray(assets.filter(function (asset) {
124
+ return !orderedKeys.has(getWalletAssetKey(asset));
125
+ })));
126
+ }
84
127
  function createInitialWalletAssetsState() {
85
128
  return {
86
129
  status: 'idle',
@@ -228,6 +271,36 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
228
271
  });
229
272
  }
230
273
 
274
+ /**
275
+ * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
276
+ * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
277
+ */
278
+ }, {
279
+ key: "formatSearchedWalletPaymentAssets",
280
+ value: function formatSearchedWalletPaymentAssets(assets) {
281
+ var _this$paymentModule$w3, _this$paymentModule$w4, _this$walletParams, _this$walletParams2;
282
+ if (!assets.length) return assets;
283
+ var assetsWithRecalculationBase = assets.map(withWalletAssetRecalculationBaseAmount);
284
+ var evaluator = (_this$paymentModule$w3 = this.paymentModule.window) === null || _this$paymentModule$w3 === void 0 || (_this$paymentModule$w4 = _this$paymentModule$w3.getWalletPassEvaluator) === null || _this$paymentModule$w4 === void 0 ? void 0 : _this$paymentModule$w4.call(_this$paymentModule$w3);
285
+ if (!(evaluator !== null && evaluator !== void 0 && evaluator.searchVoucherFormat)) return assetsWithRecalculationBase;
286
+ var hasCalculationProducts = this.walletAssetsCalculationContext.products.length > 0;
287
+ var products = hasCalculationProducts ? this.walletAssetsCalculationContext.products : ((_this$walletParams = this.walletParams) === null || _this$walletParams === void 0 ? void 0 : _this$walletParams.products) || [];
288
+ var orderTotalAmount = Number(hasCalculationProducts ? this.walletAssetsCalculationContext.orderTotalAmount : ((_this$walletParams2 = this.walletParams) === null || _this$walletParams2 === void 0 ? void 0 : _this$walletParams2.order_wait_pay_amount) || 0);
289
+ try {
290
+ var formattedAssets = evaluator.searchVoucherFormat({
291
+ orderTotalAmount: orderTotalAmount,
292
+ products: products,
293
+ vouchers: assetsWithRecalculationBase
294
+ });
295
+ return formattedAssets;
296
+ } catch (error) {
297
+ this.paymentModule.logWarning('[WalletPass] 搜索资产策略格式化失败,保留接口结果', {
298
+ error: error instanceof Error ? error.message : String(error)
299
+ });
300
+ return assetsWithRecalculationBase;
301
+ }
302
+ }
303
+
231
304
  /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
232
305
  }, {
233
306
  key: "getSearchedWalletAssetCodes",
@@ -256,8 +329,19 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
256
329
  return code.toUpperCase();
257
330
  }));
258
331
  if (searchedCodeKeys.size === 0) return cachedAssets;
332
+ var cachedAssetByCode = new Map();
333
+ cachedAssets.forEach(function (item) {
334
+ getWalletAssetCodeKeys(item).forEach(function (code) {
335
+ cachedAssetByCode.set(code, item);
336
+ });
337
+ });
259
338
  var refreshedAssets = refreshedCandidates.filter(function (item) {
260
339
  return isWalletPaymentAsset(item) && searchedCodeKeys.has(String((item === null || item === void 0 ? void 0 : item.code) || '').trim().toUpperCase());
340
+ }).map(function (item) {
341
+ var cachedAsset = getWalletAssetCodeKeys(item).map(function (code) {
342
+ return cachedAssetByCode.get(code);
343
+ }).find(Boolean);
344
+ return withWalletAssetRecalculationBaseAmount(_objectSpread(_objectSpread({}, cachedAsset), item));
261
345
  });
262
346
  if (refreshedAssets.length > 0) {
263
347
  var replacedCodes = new Set(refreshedAssets.map(function (item) {
@@ -333,8 +417,14 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
333
417
  payment_order_id: payment_order_id
334
418
  };
335
419
 
336
- // 存储生成的参数到模块中
420
+ // 扫码可能早于异步 Wallet 初始化完成。walletParams 与前端增量重算
421
+ // 必须使用同一份当前购物车上下文,避免搜索按真实金额判断可用,
422
+ // 随后的 recalculateVouchers 却仍读取初始的 0 元/空商品上下文。
337
423
  this.walletParams = walletParams;
424
+ this.walletAssetsCalculationContext = {
425
+ orderTotalAmount: Number(walletParams.order_wait_pay_amount || 0),
426
+ products: Array.isArray(walletParams.products) ? walletParams.products : []
427
+ };
338
428
  this.paymentModule.logInfo('[WalletPass] 钱包默认参数已生成并存储', {
339
429
  customer_id: walletParams.customer_id,
340
430
  holder_id: walletParams.holder_id,
@@ -511,7 +601,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
511
601
  key: "initializeWalletDataAsync",
512
602
  value: (function () {
513
603
  var _initializeWalletDataAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(baseParams) {
514
- var _this$paymentModule$w3, _this$paymentModule$w4, identificationParams, _yield$Promise$all, _yield$Promise$all2, allList, orderBasicDetail, walletPassEvaluator, products, res, recommended, transformList, noApplicableVoucher, recommendedAmount;
604
+ var _this$paymentModule$w5, _this$paymentModule$w6, identificationParams, _yield$Promise$all, _yield$Promise$all2, allList, orderBasicDetail, walletPassEvaluator, products, res, recommended, transformList, noApplicableVoucher, recommendedAmount;
515
605
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
516
606
  while (1) switch (_context3.prev = _context3.next) {
517
607
  case 0:
@@ -530,7 +620,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
530
620
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
531
621
  allList = _yield$Promise$all2[0];
532
622
  orderBasicDetail = _yield$Promise$all2[1];
533
- walletPassEvaluator = (_this$paymentModule$w3 = this.paymentModule.window) === null || _this$paymentModule$w3 === void 0 || (_this$paymentModule$w4 = _this$paymentModule$w3.getWalletPassEvaluator) === null || _this$paymentModule$w4 === void 0 ? void 0 : _this$paymentModule$w4.call(_this$paymentModule$w3);
623
+ walletPassEvaluator = (_this$paymentModule$w5 = this.paymentModule.window) === null || _this$paymentModule$w5 === void 0 || (_this$paymentModule$w6 = _this$paymentModule$w5.getWalletPassEvaluator) === null || _this$paymentModule$w6 === void 0 ? void 0 : _this$paymentModule$w6.call(_this$paymentModule$w5);
534
624
  if (walletPassEvaluator) {
535
625
  _context3.next = 11;
536
626
  break;
@@ -550,7 +640,6 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
550
640
  vouchers: allList
551
641
  });
552
642
  recommended = res.recommended, transformList = res.transformList, noApplicableVoucher = res.noApplicableVoucher, recommendedAmount = res.recommendedAmount;
553
- console.log(res, 'resres12');
554
643
  this.walletRecommendList = recommended;
555
644
 
556
645
  // 存储初始化数据到内存中,供 useWalletPass 使用
@@ -570,19 +659,19 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
570
659
  noApplicableVoucher: noApplicableVoucher,
571
660
  products: products || []
572
661
  });
573
- case 20:
574
- _context3.prev = 20;
662
+ case 19:
663
+ _context3.prev = 19;
575
664
  _context3.t0 = _context3["catch"](0);
576
665
  this.paymentModule.logError('[WalletPass] 初始化钱包数据失败', _context3.t0, {
577
666
  customer_id: baseParams.customer_id,
578
667
  order_expect_amount: baseParams.order_expect_amount
579
668
  });
580
669
  throw _context3.t0;
581
- case 24:
670
+ case 23:
582
671
  case "end":
583
672
  return _context3.stop();
584
673
  }
585
- }, _callee3, this, [[0, 20]]);
674
+ }, _callee3, this, [[0, 19]]);
586
675
  }));
587
676
  function initializeWalletDataAsync(_x3) {
588
677
  return _initializeWalletDataAsync.apply(this, arguments);
@@ -598,8 +687,8 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
598
687
  key: "aggregateRecalculateWalletAssetsAsync",
599
688
  value: (function () {
600
689
  var _aggregateRecalculateWalletAssetsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(businessData, selectedIds) {
601
- var _this$paymentModule$w5, _this$paymentModule$w6;
602
- var walletParams, customerId, requestParams, response, responseData, hasAggregateLists, recalculateList, customerWalletPassList, allList, walletPassEvaluator, evaluated, returnedSelectedKeys, authoritativeSelectedIds;
690
+ var _this$paymentModule$w7, _this$paymentModule$w8;
691
+ var walletParams, customerId, requestParams, response, responseData, hasAggregateLists, recalculateList, customerWalletPassList, orderedRecalculateList, allList, walletPassEvaluator, evaluated, returnedSelectedKeys, authoritativeSelectedIds;
603
692
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
604
693
  while (1) switch (_context4.prev = _context4.next) {
605
694
  case 0:
@@ -635,8 +724,9 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
635
724
  case 11:
636
725
  recalculateList = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.recalculate_list) ? responseData.recalculate_list : [];
637
726
  customerWalletPassList = Array.isArray(responseData === null || responseData === void 0 ? void 0 : responseData.customer_wallet_pass_list) ? responseData.customer_wallet_pass_list : [];
638
- allList = mergeWalletAssets(recalculateList, customerWalletPassList);
639
- walletPassEvaluator = (_this$paymentModule$w5 = this.paymentModule.window) === null || _this$paymentModule$w5 === void 0 || (_this$paymentModule$w6 = _this$paymentModule$w5.getWalletPassEvaluator) === null || _this$paymentModule$w6 === void 0 ? void 0 : _this$paymentModule$w6.call(_this$paymentModule$w5);
727
+ orderedRecalculateList = orderWalletAssetsByIds(recalculateList, selectedIds);
728
+ allList = mergeWalletAssets(orderedRecalculateList, customerWalletPassList);
729
+ walletPassEvaluator = (_this$paymentModule$w7 = this.paymentModule.window) === null || _this$paymentModule$w7 === void 0 || (_this$paymentModule$w8 = _this$paymentModule$w7.getWalletPassEvaluator) === null || _this$paymentModule$w8 === void 0 ? void 0 : _this$paymentModule$w8.call(_this$paymentModule$w7);
640
730
  evaluated = walletPassEvaluator !== null && walletPassEvaluator !== void 0 && walletPassEvaluator.getRecommendedVouchers ? walletPassEvaluator.getRecommendedVouchers({
641
731
  orderTotalAmount: walletParams.order_wait_pay_amount,
642
732
  products: walletParams.products,
@@ -647,8 +737,10 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
647
737
  noApplicableVoucher: allList.filter(function (item) {
648
738
  return !isWalletAssetAvailable(item);
649
739
  })
650
- };
651
- returnedSelectedKeys = new Set(recalculateList.filter(isWalletAssetAvailable).map(function (item) {
740
+ }; // 聚合接口只负责刷新资产数据;选中资格最终由前端 evaluator 重算。
741
+ // 这里仅移除接口完全未返回的资产,不能把 recalculate_list 当作
742
+ // 策略选中结果,否则 customer_wallet_pass_list 中的可用券会被误取消。
743
+ returnedSelectedKeys = new Set(allList.map(function (item) {
652
744
  return getWalletAssetKey(item);
653
745
  }));
654
746
  authoritativeSelectedIds = selectedIds.filter(function (id) {
@@ -677,7 +769,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
677
769
  products: walletParams.products || [],
678
770
  authoritativeSelectedIds: authoritativeSelectedIds
679
771
  });
680
- case 24:
772
+ case 25:
681
773
  case "end":
682
774
  return _context4.stop();
683
775
  }
@@ -692,7 +784,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
692
784
  key: "getWalletPassRecommendListAsync",
693
785
  value: function () {
694
786
  var _getWalletPassRecommendListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(params) {
695
- var _this$walletParams, response;
787
+ var _this$walletParams3, response;
696
788
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
697
789
  while (1) switch (_context5.prev = _context5.next) {
698
790
  case 0:
@@ -701,7 +793,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
701
793
  customer_id: params.customer_id,
702
794
  order_expect_amount: params.order_expect_amount,
703
795
  sale_channel: params.sale_channel,
704
- payment_order_id: (_this$walletParams = this.walletParams) === null || _this$walletParams === void 0 ? void 0 : _this$walletParams.payment_order_id
796
+ payment_order_id: (_this$walletParams3 = this.walletParams) === null || _this$walletParams3 === void 0 ? void 0 : _this$walletParams3.payment_order_id
705
797
  });
706
798
  if (typeof params.payment_order_id === 'string' && params.payment_order_id.startsWith('LOCAL_')) {
707
799
  params.payment_order_id = undefined;
@@ -759,7 +851,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
759
851
  key: "getUserIdentificationCodeListAsync",
760
852
  value: function () {
761
853
  var _getUserIdentificationCodeListAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
762
- var _newParams$products, _newParams$prepare_pa, _this$walletParams2, newParams, response, sortedData;
854
+ var _newParams$products, _newParams$prepare_pa, _this$walletParams4, newParams, response, sortedData;
763
855
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
764
856
  while (1) switch (_context6.prev = _context6.next) {
765
857
  case 0:
@@ -780,7 +872,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
780
872
  available: newParams.available,
781
873
  prepare_payments_count: ((_newParams$prepare_pa = newParams.prepare_payments) === null || _newParams$prepare_pa === void 0 ? void 0 : _newParams$prepare_pa.length) || 0,
782
874
  filter_prepare_wallet_pass: newParams.filter_prepare_wallet_pass,
783
- payment_order_id: (_this$walletParams2 = this.walletParams) === null || _this$walletParams2 === void 0 ? void 0 : _this$walletParams2.payment_order_id
875
+ payment_order_id: (_this$walletParams4 = this.walletParams) === null || _this$walletParams4 === void 0 ? void 0 : _this$walletParams4.payment_order_id
784
876
  });
785
877
  _context6.next = 9;
786
878
  return this.paymentModule.request.post('/machinecode/prepare/deduction', newParams);
@@ -1019,6 +1111,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1019
1111
  selectedIds,
1020
1112
  selectionSources,
1021
1113
  scanSelectedAssets,
1114
+ manualEditAmountByKey,
1022
1115
  restoredSearchedAssets,
1023
1116
  searchedWalletAssetCodes,
1024
1117
  useAggregateRecalculate,
@@ -1061,11 +1154,20 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1061
1154
  scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter(function (asset) {
1062
1155
  var assetId = getWalletAssetId(asset);
1063
1156
  return assetId !== undefined && assetId !== null && selectionSources[String(assetId)] === 'scan';
1064
- }) : []; // aggregate-recalculate 不接受空商品列表。
1157
+ }) : [];
1158
+ manualEditAmountByKey = new Map();
1159
+ if (preserveSelection) {
1160
+ this.walletAssetsState.selectedItems.forEach(function (asset) {
1161
+ if (typeof (asset === null || asset === void 0 ? void 0 : asset.edit_current_amount) !== 'number') return;
1162
+ manualEditAmountByKey.set(getWalletAssetKey(asset), asset.edit_current_amount);
1163
+ });
1164
+ }
1165
+
1166
+ // aggregate-recalculate 不接受空商品列表。
1065
1167
  // 清空购物车时保留扫码资产供后续加购恢复;只有手动 Remove/Clear
1066
1168
  // 会取消自动应用资格,商品变化导致的自动失效需要重新进入待选队列。
1067
1169
  if ((_businessData$product2 = businessData.products) !== null && _businessData$product2 !== void 0 && _businessData$product2.length) {
1068
- _context8.next = 22;
1170
+ _context8.next = 24;
1069
1171
  break;
1070
1172
  }
1071
1173
  this.queuePendingAutoSelectForAssets(scanSelectedAssets);
@@ -1103,7 +1205,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1103
1205
  totalSelectedAmount: 0,
1104
1206
  error: null
1105
1207
  }));
1106
- case 22:
1208
+ case 24:
1107
1209
  this.publishWalletAssetsState({
1108
1210
  status: 'loading',
1109
1211
  customerId: nextCustomerId,
@@ -1114,40 +1216,40 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1114
1216
  totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
1115
1217
  error: null
1116
1218
  });
1117
- _context8.prev = 23;
1219
+ _context8.prev = 25;
1118
1220
  searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
1119
1221
  useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
1120
1222
  if (!useAggregateRecalculate) {
1121
- _context8.next = 32;
1223
+ _context8.next = 34;
1122
1224
  break;
1123
1225
  }
1124
- _context8.next = 29;
1226
+ _context8.next = 31;
1125
1227
  return this.aggregateRecalculateWalletAssetsAsync(businessData, selectedIds);
1126
- case 29:
1228
+ case 31:
1127
1229
  _context8.t0 = _context8.sent;
1128
- _context8.next = 33;
1230
+ _context8.next = 35;
1129
1231
  break;
1130
- case 32:
1232
+ case 34:
1131
1233
  _context8.t0 = null;
1132
- case 33:
1234
+ case 35:
1133
1235
  aggregateResult = _context8.t0;
1134
1236
  _context8.t1 = aggregateResult;
1135
1237
  if (_context8.t1) {
1136
- _context8.next = 39;
1238
+ _context8.next = 41;
1137
1239
  break;
1138
1240
  }
1139
- _context8.next = 38;
1241
+ _context8.next = 40;
1140
1242
  return this.initializeWalletDataFromBusinessAsync(businessData);
1141
- case 38:
1243
+ case 40:
1142
1244
  _context8.t1 = _context8.sent;
1143
- case 39:
1245
+ case 41:
1144
1246
  result = _context8.t1;
1145
1247
  if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1146
- _context8.next = 42;
1248
+ _context8.next = 44;
1147
1249
  break;
1148
1250
  }
1149
1251
  return _context8.abrupt("return", this.getWalletAssetsState());
1150
- case 42:
1252
+ case 44:
1151
1253
  this.walletAssetsCalculationContext = {
1152
1254
  orderTotalAmount: Number(businessData.order_wait_pay_amount || 0),
1153
1255
  products: result.products || businessData.products || []
@@ -1170,17 +1272,20 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1170
1272
  }
1171
1273
  searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([].concat(_toConsumableArray(result.transformList || []), _toConsumableArray(result.noApplicableVoucher || []))) : [];
1172
1274
  if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1173
- _context8.next = 48;
1275
+ _context8.next = 50;
1174
1276
  break;
1175
1277
  }
1176
1278
  return _context8.abrupt("return", this.getWalletAssetsState());
1177
- case 48:
1279
+ case 50:
1178
1280
  recommendedKeys = new Set((result.walletRecommendList || []).map(function (asset) {
1179
1281
  return getWalletAssetKey(asset);
1180
1282
  }));
1181
1283
  items = mergeWalletAssets(preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [], searchedWalletAssets, result.transformList || [], result.noApplicableVoucher || []).map(function (asset) {
1182
- return _objectSpread(_objectSpread({}, asset), {}, {
1183
- _wallet_asset_recommended: recommendedKeys.has(getWalletAssetKey(asset))
1284
+ var assetKey = getWalletAssetKey(asset);
1285
+ return _objectSpread(_objectSpread(_objectSpread({}, asset), manualEditAmountByKey.has(assetKey) ? {
1286
+ edit_current_amount: manualEditAmountByKey.get(assetKey)
1287
+ } : {}), {}, {
1288
+ _wallet_asset_recommended: recommendedKeys.has(assetKey)
1184
1289
  });
1185
1290
  });
1186
1291
  latestSelectedIds = preserveSelection ? authoritativeSelectedIds : [];
@@ -1217,15 +1322,15 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1217
1322
  });
1218
1323
  this.queuePendingAutoSelectForAssets(droppedScanSelectedAssets);
1219
1324
  return _context8.abrupt("return", nextState);
1220
- case 63:
1221
- _context8.prev = 63;
1222
- _context8.t2 = _context8["catch"](23);
1325
+ case 65:
1326
+ _context8.prev = 65;
1327
+ _context8.t2 = _context8["catch"](25);
1223
1328
  if (!(requestSequence !== this.walletAssetsRequestSequence)) {
1224
- _context8.next = 67;
1329
+ _context8.next = 69;
1225
1330
  break;
1226
1331
  }
1227
1332
  return _context8.abrupt("return", this.getWalletAssetsState());
1228
- case 67:
1333
+ case 69:
1229
1334
  this.paymentModule.logError('[WalletPass] 刷新共享钱包资产失败,保留刷新前状态', _context8.t2, {
1230
1335
  customer_id: businessData.customer_id,
1231
1336
  selected_ids: selectedIds,
@@ -1241,11 +1346,11 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1241
1346
  customerId: nextCustomerId,
1242
1347
  error: _context8.t2 instanceof Error ? _context8.t2.message : String(_context8.t2)
1243
1348
  }));
1244
- case 69:
1349
+ case 71:
1245
1350
  case "end":
1246
1351
  return _context8.stop();
1247
1352
  }
1248
- }, _callee8, this, [[23, 63]]);
1353
+ }, _callee8, this, [[25, 65]]);
1249
1354
  }));
1250
1355
  function refreshWalletAssetsFromBusinessAsync(_x9) {
1251
1356
  return _refreshWalletAssetsFromBusinessAsync.apply(this, arguments);
@@ -1298,6 +1403,17 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1298
1403
  selectionSources: snapshot.state.selectionSources || {}
1299
1404
  }));
1300
1405
  }
1406
+ }, {
1407
+ key: "updateWalletAssetEditAmountInCaches",
1408
+ value: function updateWalletAssetEditAmountInCaches(assetKey, amount) {
1409
+ var updateAsset = function updateAsset(asset) {
1410
+ return getWalletAssetKey(asset) === assetKey ? _objectSpread(_objectSpread({}, asset), {}, {
1411
+ edit_current_amount: amount
1412
+ }) : asset;
1413
+ };
1414
+ this.searchResults = this.searchResults.map(updateAsset);
1415
+ return this.walletAssetsState.items.map(updateAsset);
1416
+ }
1301
1417
  }, {
1302
1418
  key: "selectWalletAsset",
1303
1419
  value: function selectWalletAsset(assetId, options) {
@@ -1314,6 +1430,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1314
1430
  });
1315
1431
  var selectionSources = _objectSpread({}, this.walletAssetsState.selectionSources);
1316
1432
  delete selectionSources[assetKey];
1433
+ var nextItems = this.walletAssetsState.items;
1317
1434
  if (options.selected) {
1318
1435
  if (!asset || !isWalletAssetAvailable(asset)) {
1319
1436
  return this.getWalletAssetsState();
@@ -1322,8 +1439,9 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1322
1439
  selectionSources[assetKey] = options.source || 'manual';
1323
1440
  } else if (asset) {
1324
1441
  this.clearPendingAutoSelectForAsset(asset);
1442
+ nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, undefined);
1325
1443
  }
1326
- var nextState = this.recalculateWalletAssets(this.walletAssetsState.items, selectedIds, selectionSources);
1444
+ var nextState = this.recalculateWalletAssets(nextItems, selectedIds, selectionSources);
1327
1445
  if (options.selected && asset && nextState.selectedIds.some(function (id) {
1328
1446
  return String(id) === assetKey;
1329
1447
  })) {
@@ -1331,11 +1449,49 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1331
1449
  }
1332
1450
  return nextState;
1333
1451
  }
1452
+
1453
+ /**
1454
+ * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
1455
+ * 金额为 0 时沿用 legacy 行为取消选择。
1456
+ */
1457
+ }, {
1458
+ key: "updateWalletAssetAmount",
1459
+ value: function updateWalletAssetAmount(assetId, amount) {
1460
+ var assetKey = String(assetId);
1461
+ var committedKeys = new Set(this.walletAssetsState.committedIds.map(function (id) {
1462
+ return String(id);
1463
+ }));
1464
+ var selectedKeys = new Set(this.walletAssetsState.selectedIds.map(function (id) {
1465
+ return String(id);
1466
+ }));
1467
+ var asset = this.walletAssetsState.items.find(function (item) {
1468
+ return getWalletAssetKey(item) === assetKey;
1469
+ });
1470
+ var requestedAmount = Number(amount);
1471
+ if (!asset || committedKeys.has(assetKey) || !selectedKeys.has(assetKey) || !Number.isFinite(requestedAmount) || requestedAmount < 0) {
1472
+ return this.getWalletAssetsState();
1473
+ }
1474
+ var selectedIds = _toConsumableArray(this.walletAssetsState.selectedIds);
1475
+ var selectionSources = _objectSpread({}, this.walletAssetsState.selectionSources);
1476
+ if (requestedAmount === 0) {
1477
+ var _nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, undefined);
1478
+ delete selectionSources[assetKey];
1479
+ this.clearPendingAutoSelectForAsset(asset);
1480
+ return this.recalculateWalletAssets(_nextItems, selectedIds.filter(function (id) {
1481
+ return String(id) !== assetKey;
1482
+ }), selectionSources);
1483
+ }
1484
+ var currentDeductionAmount = getWalletAssetDeductionAmount(asset);
1485
+ var editAmount = Math.min(requestedAmount, currentDeductionAmount);
1486
+ if (editAmount <= 0) return this.getWalletAssetsState();
1487
+ var nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, editAmount);
1488
+ return this.recalculateWalletAssets(nextItems, selectedIds, selectionSources);
1489
+ }
1334
1490
  }, {
1335
1491
  key: "scanWalletAssetAsync",
1336
1492
  value: function () {
1337
1493
  var _scanWalletAssetAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(code) {
1338
- var normalizedCode, selectedAsset, result, paymentAssets, asset, items, recalculatedState, assetId, selected, isSelected;
1494
+ var normalizedCode, selectedAsset, result, paymentAssets, asset, items, recalculatedState, assetId, recalculatedAsset, selected, isSelected, selectedStateAsset, resolvedAsset;
1339
1495
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1340
1496
  while (1) switch (_context9.prev = _context9.next) {
1341
1497
  case 0:
@@ -1372,12 +1528,15 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1372
1528
  }));
1373
1529
  case 9:
1374
1530
  result = _context9.sent;
1375
- paymentAssets = result.data.filter(isWalletPaymentAsset);
1531
+ paymentAssets = this.formatSearchedWalletPaymentAssets(result.data.filter(isWalletPaymentAsset));
1532
+ if (paymentAssets.length > 0) {
1533
+ this.searchResults = mergeWalletAssets(this.searchResults, paymentAssets);
1534
+ }
1376
1535
  asset = paymentAssets.find(function (item) {
1377
1536
  return String((item === null || item === void 0 ? void 0 : item.code) || '') === normalizedCode;
1378
1537
  }) || paymentAssets[0];
1379
1538
  if (!(!asset || result.type === 'walletCode')) {
1380
- _context9.next = 14;
1539
+ _context9.next = 15;
1381
1540
  break;
1382
1541
  }
1383
1542
  return _context9.abrupt("return", {
@@ -1386,30 +1545,37 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1386
1545
  selected: false,
1387
1546
  state: this.getWalletAssetsState()
1388
1547
  });
1389
- case 14:
1548
+ case 15:
1390
1549
  items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1391
1550
  recalculatedState = this.recalculateWalletAssets(items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1392
1551
  assetId = getWalletAssetId(asset);
1393
- selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== undefined && isWalletAssetAvailable(asset) ? this.selectWalletAsset(assetId, {
1552
+ recalculatedAsset = assetId === undefined ? undefined : recalculatedState.items.find(function (item) {
1553
+ return getWalletAssetKey(item) === String(assetId);
1554
+ });
1555
+ selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== undefined && isWalletAssetAvailable(recalculatedAsset) ? this.selectWalletAsset(assetId, {
1394
1556
  selected: true,
1395
1557
  source: 'scan'
1396
1558
  }) : recalculatedState;
1397
1559
  isSelected = assetId !== undefined && selected.selectedIds.some(function (id) {
1398
1560
  return String(id) === String(assetId);
1399
1561
  });
1562
+ selectedStateAsset = assetId === undefined ? undefined : selected.items.find(function (item) {
1563
+ return getWalletAssetKey(item) === String(assetId);
1564
+ });
1565
+ resolvedAsset = selectedStateAsset || recalculatedAsset || asset;
1400
1566
  if (isSelected) {
1401
- this.clearPendingAutoSelectForAsset(asset);
1567
+ this.clearPendingAutoSelectForAsset(resolvedAsset);
1402
1568
  } else if (this.walletAssetsBehavior.autoSelectAfterSearch) {
1403
1569
  this.pendingAutoSelectSearchCodes.add(normalizeWalletAssetCode(normalizedCode));
1404
- this.queuePendingAutoSelectForAssets([asset]);
1570
+ this.queuePendingAutoSelectForAssets([resolvedAsset]);
1405
1571
  }
1406
1572
  return _context9.abrupt("return", {
1407
1573
  type: result.type,
1408
- asset: asset,
1574
+ asset: resolvedAsset,
1409
1575
  selected: isSelected,
1410
1576
  state: selected
1411
1577
  });
1412
- case 21:
1578
+ case 25:
1413
1579
  case "end":
1414
1580
  return _context9.stop();
1415
1581
  }
@@ -1424,7 +1590,16 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
1424
1590
  key: "clearWalletAssetSelection",
1425
1591
  value: function clearWalletAssetSelection() {
1426
1592
  this.pendingAutoSelectSearchCodes.clear();
1427
- return this.recalculateWalletAssets(this.walletAssetsState.items, [], {});
1593
+ var selectedKeys = new Set(this.walletAssetsState.selectedIds.map(function (id) {
1594
+ return String(id);
1595
+ }));
1596
+ var clearSelectedEditAmount = function clearSelectedEditAmount(asset) {
1597
+ return selectedKeys.has(getWalletAssetKey(asset)) ? _objectSpread(_objectSpread({}, asset), {}, {
1598
+ edit_current_amount: undefined
1599
+ }) : asset;
1600
+ };
1601
+ this.searchResults = this.searchResults.map(clearSelectedEditAmount);
1602
+ return this.recalculateWalletAssets(this.walletAssetsState.items.map(clearSelectedEditAmount), [], {});
1428
1603
  }
1429
1604
  }, {
1430
1605
  key: "setCommittedWalletAssets",
@@ -619,7 +619,8 @@ function formatBundlePrice(bundle, currencySymbol) {
619
619
  var _ref33, _ref34, _bundle$bundle_sellin;
620
620
  var value = (_ref33 = (_ref34 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref34 !== void 0 ? _ref34 : bundle.price) !== null && _ref33 !== void 0 ? _ref33 : 0;
621
621
  var amount = new Decimal(toMoneyNumber(value));
622
- var isNegative = bundle.price_type === 'markdown' || bundle.price_type === 'markup' && bundle.price_type_ext === 'product_price';
622
+ // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
623
+ var isNegative = bundle.price_type === 'markdown';
623
624
  if (isNegative) return "-".concat(currencySymbol).concat(amount.abs().toFixed(2));
624
625
  return formatMoney(amount, currencySymbol);
625
626
  }
@@ -355,6 +355,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
355
355
  selected: boolean;
356
356
  source?: WalletAssetSelectionSource;
357
357
  }): Promise<WalletAssetsState>;
358
+ /** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
359
+ updateWalletAssetAmount(params: {
360
+ assetId: WalletAssetId;
361
+ amount: number;
362
+ }): Promise<WalletAssetsState>;
358
363
  /** 扫码精确查券;仅可用资产会被自动选中。 */
359
364
  scanWalletAsset(code: string): Promise<ScanWalletAssetResult>;
360
365
  /** 清空全部未确认钱包选择,已支付钱包项由 Order 模块继续保留。 */