@pisell/pisellos 2.2.277 → 2.2.800

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +1 -7
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  4. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  8. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  12. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  13. package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -0
  14. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -5
  15. package/dist/model/strategy/adapter/walletPass/utils.js +26 -57
  16. package/dist/modules/OpenData/index.d.ts +0 -2
  17. package/dist/modules/OpenData/index.js +0 -8
  18. package/dist/modules/Order/index.d.ts +8 -28
  19. package/dist/modules/Order/index.js +496 -808
  20. package/dist/modules/Order/types.d.ts +1 -35
  21. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  22. package/dist/modules/Order/utils.js +6 -10
  23. package/dist/modules/Payment/index.d.ts +0 -2
  24. package/dist/modules/Payment/index.js +49 -78
  25. package/dist/modules/Payment/types.d.ts +25 -106
  26. package/dist/modules/Payment/types.js +0 -17
  27. package/dist/modules/Payment/utils.js +1 -4
  28. package/dist/modules/Payment/walletpass.d.ts +1 -49
  29. package/dist/modules/Payment/walletpass.js +124 -1081
  30. package/dist/modules/Rules/index.d.ts +0 -3
  31. package/dist/modules/Rules/index.js +70 -100
  32. package/dist/server/index.d.ts +0 -25
  33. package/dist/server/index.js +1069 -2001
  34. package/dist/server/modules/index.d.ts +1 -1
  35. package/dist/server/modules/order/index.d.ts +4 -70
  36. package/dist/server/modules/order/index.js +728 -1816
  37. package/dist/server/modules/order/types.d.ts +3 -25
  38. package/dist/server/modules/order/types.js +1 -7
  39. package/dist/server/utils/small-ticket.js +2 -1
  40. package/dist/solution/BaseSales/index.d.ts +5 -109
  41. package/dist/solution/BaseSales/index.js +436 -1802
  42. package/dist/solution/BaseSales/types.d.ts +1 -55
  43. package/dist/solution/BaseSales/types.js +1 -2
  44. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  45. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  46. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -7
  48. package/dist/solution/BookingByStep/index.d.ts +1 -1
  49. package/dist/solution/BookingTicket/index.d.ts +5 -21
  50. package/dist/solution/BookingTicket/index.js +56 -139
  51. package/dist/solution/BookingTicket/types.d.ts +0 -1
  52. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  53. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +83 -173
  54. package/dist/solution/Sales/index.d.ts +0 -2
  55. package/dist/solution/Sales/index.js +4 -26
  56. package/dist/solution/ScanOrder/index.js +20 -31
  57. package/dist/solution/VenueBooking/index.d.ts +0 -1
  58. package/dist/solution/VenueBooking/index.js +19 -30
  59. package/dist/types/index.d.ts +0 -1
  60. package/lib/core/index.d.ts +0 -2
  61. package/lib/core/index.js +1 -4
  62. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  63. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  64. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  65. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  66. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  67. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  68. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  69. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  70. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  71. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  72. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  73. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -5
  74. package/lib/model/strategy/adapter/walletPass/utils.js +11 -62
  75. package/lib/modules/OpenData/index.d.ts +0 -2
  76. package/lib/modules/OpenData/index.js +0 -5
  77. package/lib/modules/Order/index.d.ts +8 -28
  78. package/lib/modules/Order/index.js +69 -231
  79. package/lib/modules/Order/types.d.ts +1 -35
  80. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  81. package/lib/modules/Order/utils.js +4 -11
  82. package/lib/modules/Payment/index.d.ts +0 -2
  83. package/lib/modules/Payment/index.js +12 -33
  84. package/lib/modules/Payment/types.d.ts +25 -106
  85. package/lib/modules/Payment/types.js +0 -1
  86. package/lib/modules/Payment/utils.js +1 -5
  87. package/lib/modules/Payment/walletpass.d.ts +1 -49
  88. package/lib/modules/Payment/walletpass.js +22 -898
  89. package/lib/modules/Rules/index.d.ts +0 -3
  90. package/lib/modules/Rules/index.js +9 -38
  91. package/lib/server/index.d.ts +0 -25
  92. package/lib/server/index.js +31 -726
  93. package/lib/server/modules/index.d.ts +1 -1
  94. package/lib/server/modules/order/index.d.ts +4 -70
  95. package/lib/server/modules/order/index.js +69 -818
  96. package/lib/server/modules/order/types.d.ts +3 -25
  97. package/lib/server/modules/order/types.js +0 -1
  98. package/lib/server/utils/small-ticket.js +1 -1
  99. package/lib/solution/BaseSales/index.d.ts +5 -109
  100. package/lib/solution/BaseSales/index.js +27 -874
  101. package/lib/solution/BaseSales/types.d.ts +1 -55
  102. package/lib/solution/BaseSales/types.js +1 -2
  103. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  104. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  105. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  106. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -4
  107. package/lib/solution/BookingByStep/index.d.ts +1 -1
  108. package/lib/solution/BookingTicket/index.d.ts +5 -21
  109. package/lib/solution/BookingTicket/index.js +13 -64
  110. package/lib/solution/BookingTicket/types.d.ts +0 -1
  111. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  112. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +5 -37
  113. package/lib/solution/Sales/index.d.ts +0 -2
  114. package/lib/solution/Sales/index.js +6 -20
  115. package/lib/solution/ScanOrder/index.js +0 -8
  116. package/lib/solution/VenueBooking/index.d.ts +0 -1
  117. package/lib/solution/VenueBooking/index.js +0 -8
  118. package/lib/types/index.d.ts +0 -1
  119. package/package.json +1 -1
  120. package/dist/modules/Order/payment-utils.d.ts +0 -26
  121. package/dist/modules/Order/payment-utils.js +0 -225
  122. package/dist/utils/payment-number.d.ts +0 -9
  123. package/dist/utils/payment-number.js +0 -69
  124. package/lib/modules/Order/payment-utils.d.ts +0 -26
  125. package/lib/modules/Order/payment-utils.js +0 -224
  126. package/lib/utils/payment-number.d.ts +0 -9
  127. package/lib/utils/payment-number.js +0 -64
@@ -24,104 +24,6 @@ __export(walletpass_exports, {
24
24
  module.exports = __toCommonJS(walletpass_exports);
25
25
  var import_types = require("./types");
26
26
  var import_utils = require("./utils");
27
- var WALLET_PAYMENT_ASSET_TAGS = /* @__PURE__ */ new Set([
28
- "product_voucher",
29
- "gift_card",
30
- "point_card"
31
- ]);
32
- function isWalletPaymentAsset(asset) {
33
- return WALLET_PAYMENT_ASSET_TAGS.has(
34
- String((asset == null ? void 0 : asset.tag) || "").toLowerCase()
35
- );
36
- }
37
- function getWalletAssetId(asset) {
38
- return (asset == null ? void 0 : asset.id) ?? (asset == null ? void 0 : asset.voucher_id) ?? (asset == null ? void 0 : asset.code);
39
- }
40
- function getWalletAssetKey(assetOrId) {
41
- const id = assetOrId && typeof assetOrId === "object" ? getWalletAssetId(assetOrId) : assetOrId;
42
- return id === void 0 || id === null ? "" : String(id);
43
- }
44
- function matchesWalletAssetCode(asset, normalizedCode) {
45
- return [asset == null ? void 0 : asset.code, asset == null ? void 0 : asset.encoded].some(
46
- (identifier) => String(identifier ?? "").trim() === normalizedCode
47
- );
48
- }
49
- function normalizeWalletAssetCode(code) {
50
- return String(code ?? "").trim().toUpperCase();
51
- }
52
- function getWalletAssetCodeKeys(asset) {
53
- return [asset == null ? void 0 : asset.code, asset == null ? void 0 : asset.encoded].map(normalizeWalletAssetCode).filter(Boolean);
54
- }
55
- function withWalletAssetRecalculationBaseAmount(asset) {
56
- const existingBaseAmount = Number(
57
- asset == null ? void 0 : asset._wallet_asset_recalculation_base_amount
58
- );
59
- if (Number.isFinite(existingBaseAmount) && existingBaseAmount >= 0) {
60
- return asset;
61
- }
62
- if (!["product_voucher", "gift_card"].includes(asset == null ? void 0 : asset.tag)) {
63
- return asset;
64
- }
65
- const balanceParValue = Number(asset == null ? void 0 : asset.balance_par_value);
66
- if (!Number.isFinite(balanceParValue) || balanceParValue < 0) {
67
- return asset;
68
- }
69
- return {
70
- ...asset,
71
- _wallet_asset_recalculation_base_amount: balanceParValue
72
- };
73
- }
74
- function isWalletAssetAvailable(asset) {
75
- if (!asset)
76
- return false;
77
- if (asset.unified_available_status !== void 0 && Number(asset.unified_available_status) !== 1) {
78
- return false;
79
- }
80
- if (asset._unified_available_status !== void 0 && Number(asset._unified_available_status) !== 1) {
81
- return false;
82
- }
83
- if (asset.available === false || asset.isDisabled === true)
84
- return false;
85
- return true;
86
- }
87
- function getWalletAssetDeductionAmount(asset) {
88
- const value = (asset == null ? void 0 : asset.actualDeduction) ?? (asset == null ? void 0 : asset._available_max_amount) ?? (asset == null ? void 0 : asset.edit_current_amount) ?? (asset == null ? void 0 : asset.recommended_usage_amount) ?? (asset == null ? void 0 : asset.available_max_amount) ?? (asset == null ? void 0 : asset.amount) ?? 0;
89
- const amount = Number(value);
90
- return Number.isFinite(amount) && amount > 0 ? amount : 0;
91
- }
92
- function mergeWalletAssets(...groups) {
93
- const merged = [];
94
- const indexByKey = /* @__PURE__ */ new Map();
95
- groups.flat().forEach((asset) => {
96
- const key = getWalletAssetKey(asset);
97
- if (!key)
98
- return;
99
- const existedIndex = indexByKey.get(key);
100
- if (existedIndex === void 0) {
101
- indexByKey.set(key, merged.length);
102
- merged.push(asset);
103
- return;
104
- }
105
- merged[existedIndex] = {
106
- ...merged[existedIndex],
107
- ...asset
108
- };
109
- });
110
- return merged;
111
- }
112
- function createInitialWalletAssetsState() {
113
- return {
114
- status: "idle",
115
- items: [],
116
- selectedIds: [],
117
- selectedItems: [],
118
- committedIds: [],
119
- selectionSources: {},
120
- totalSelectedAmount: 0,
121
- error: null,
122
- revision: 0
123
- };
124
- }
125
27
  var WalletPassPaymentImpl = class {
126
28
  constructor(paymentModule) {
127
29
  this.paymentModule = paymentModule;
@@ -130,24 +32,6 @@ var WalletPassPaymentImpl = class {
130
32
  this.searchResults = [];
131
33
  this.walletParams = null;
132
34
  this.walletInitData = null;
133
- this.walletAssetsState = createInitialWalletAssetsState();
134
- this.walletAssetsRequestSequence = 0;
135
- this.walletAssetsBehavior = {
136
- autoSelectAfterSearch: true
137
- };
138
- this.pendingAutoSelectSearchCodes = /* @__PURE__ */ new Set();
139
- this.walletAssetsCalculationContext = {
140
- orderTotalAmount: 0,
141
- products: []
142
- };
143
- }
144
- configureWalletAssetsBehavior(options) {
145
- if (options.autoSelectAfterSearch === void 0)
146
- return;
147
- this.walletAssetsBehavior.autoSelectAfterSearch = options.autoSelectAfterSearch;
148
- if (!options.autoSelectAfterSearch) {
149
- this.pendingAutoSelectSearchCodes.clear();
150
- }
151
35
  }
152
36
  /**
153
37
  * 发送事件的辅助方法
@@ -164,196 +48,6 @@ var WalletPassPaymentImpl = class {
164
48
  });
165
49
  }
166
50
  }
167
- publishWalletAssetsState(patch) {
168
- this.walletAssetsState = {
169
- ...this.walletAssetsState,
170
- ...patch,
171
- items: [...patch.items ?? this.walletAssetsState.items],
172
- selectedIds: [
173
- ...patch.selectedIds ?? this.walletAssetsState.selectedIds
174
- ],
175
- selectedItems: [
176
- ...patch.selectedItems ?? this.walletAssetsState.selectedItems
177
- ],
178
- committedIds: [
179
- ...patch.committedIds ?? this.walletAssetsState.committedIds
180
- ],
181
- selectionSources: {
182
- ...patch.selectionSources ?? this.walletAssetsState.selectionSources
183
- },
184
- revision: this.walletAssetsState.revision + 1
185
- };
186
- const state = this.getWalletAssetsState();
187
- this.emitEvent(import_types.WalletPassHooks.OnWalletAssetsStateChanged, { state });
188
- return state;
189
- }
190
- recalculateWalletAssets(items, requestedIds, selectionSources) {
191
- var _a, _b;
192
- const committedKeys = new Set(
193
- this.walletAssetsState.committedIds.map((id) => String(id))
194
- );
195
- const itemsByKey = new Map(
196
- items.map((item) => [getWalletAssetKey(item), item])
197
- );
198
- const requested = requestedIds.map((id) => String(id)).filter((id) => !committedKeys.has(id)).map((id) => itemsByKey.get(id)).filter((item) => item && isWalletAssetAvailable(item));
199
- let nextItems = items;
200
- let selectedItems = requested;
201
- const evaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
202
- if (evaluator == null ? void 0 : evaluator.recalculateVouchers) {
203
- try {
204
- const result = evaluator.recalculateVouchers(
205
- items,
206
- requested,
207
- this.walletAssetsCalculationContext.orderTotalAmount,
208
- this.walletAssetsCalculationContext.products
209
- );
210
- nextItems = mergeWalletAssets(items, (result == null ? void 0 : result.allWithUpdatedStatus) || []);
211
- selectedItems = ((result == null ? void 0 : result.selectedWithDetails) || []).filter(
212
- (item) => isWalletAssetAvailable(item) && getWalletAssetDeductionAmount(item) > 0
213
- );
214
- } catch (error) {
215
- this.paymentModule.logWarning(
216
- "[WalletPass] 共享钱包资产重新计算失败,回退接口可用状态",
217
- {
218
- error: error instanceof Error ? error.message : String(error)
219
- }
220
- );
221
- }
222
- }
223
- const selectedIds = selectedItems.map((item) => getWalletAssetId(item)).filter((id) => id !== void 0 && id !== null);
224
- const selectedKeys = new Set(selectedIds.map((id) => String(id)));
225
- const nextSources = Object.entries(selectionSources).reduce((result, [key, source]) => {
226
- if (selectedKeys.has(key))
227
- result[key] = source;
228
- return result;
229
- }, {});
230
- const totalSelectedAmount = selectedItems.reduce(
231
- (total, item) => total + getWalletAssetDeductionAmount(item),
232
- 0
233
- );
234
- return this.publishWalletAssetsState({
235
- status: "ready",
236
- items: nextItems,
237
- selectedIds,
238
- selectedItems,
239
- selectionSources: nextSources,
240
- totalSelectedAmount,
241
- error: null
242
- });
243
- }
244
- /**
245
- * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
246
- * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
247
- */
248
- formatSearchedWalletPaymentAssets(assets) {
249
- var _a, _b, _c, _d;
250
- if (!assets.length)
251
- return assets;
252
- const assetsWithRecalculationBase = assets.map(
253
- withWalletAssetRecalculationBaseAmount
254
- );
255
- const evaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
256
- if (!(evaluator == null ? void 0 : evaluator.searchVoucherFormat))
257
- return assetsWithRecalculationBase;
258
- const hasCalculationProducts = this.walletAssetsCalculationContext.products.length > 0;
259
- const products = hasCalculationProducts ? this.walletAssetsCalculationContext.products : ((_c = this.walletParams) == null ? void 0 : _c.products) || [];
260
- const orderTotalAmount = Number(
261
- hasCalculationProducts ? this.walletAssetsCalculationContext.orderTotalAmount : ((_d = this.walletParams) == null ? void 0 : _d.order_wait_pay_amount) || 0
262
- );
263
- try {
264
- const formattedAssets = evaluator.searchVoucherFormat({
265
- orderTotalAmount,
266
- products,
267
- vouchers: assetsWithRecalculationBase
268
- });
269
- return formattedAssets;
270
- } catch (error) {
271
- this.paymentModule.logWarning(
272
- "[WalletPass] 搜索资产策略格式化失败,保留接口结果",
273
- {
274
- error: error instanceof Error ? error.message : String(error)
275
- }
276
- );
277
- return assetsWithRecalculationBase;
278
- }
279
- }
280
- /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
281
- getSearchedWalletAssetCodes() {
282
- const cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
283
- const seenCodes = /* @__PURE__ */ new Set();
284
- return cachedAssets.map((item) => String((item == null ? void 0 : item.code) || "").trim()).filter((code) => {
285
- const normalizedCode = code.toUpperCase();
286
- if (!normalizedCode || seenCodes.has(normalizedCode))
287
- return false;
288
- seenCodes.add(normalizedCode);
289
- return true;
290
- });
291
- }
292
- /**
293
- * 用订单重算接口返回的数据更新扫码 Wallet 缓存。
294
- * 接口暂时缺失某个扫码 code 时继续保留旧值,避免列表闪空。
295
- */
296
- syncSearchedWalletAssets(refreshedCandidates) {
297
- const cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
298
- const searchedCodeKeys = new Set(
299
- this.getSearchedWalletAssetCodes().map((code) => code.toUpperCase())
300
- );
301
- if (searchedCodeKeys.size === 0)
302
- return cachedAssets;
303
- const cachedAssetByCode = /* @__PURE__ */ new Map();
304
- cachedAssets.forEach((item) => {
305
- getWalletAssetCodeKeys(item).forEach((code) => {
306
- cachedAssetByCode.set(code, item);
307
- });
308
- });
309
- const refreshedAssets = refreshedCandidates.filter(
310
- (item) => isWalletPaymentAsset(item) && searchedCodeKeys.has(
311
- String((item == null ? void 0 : item.code) || "").trim().toUpperCase()
312
- )
313
- ).map((item) => {
314
- const cachedAsset = getWalletAssetCodeKeys(item).map((code) => cachedAssetByCode.get(code)).find(Boolean);
315
- return withWalletAssetRecalculationBaseAmount({
316
- ...cachedAsset,
317
- ...item
318
- });
319
- });
320
- if (refreshedAssets.length > 0) {
321
- const replacedCodes = new Set(
322
- refreshedAssets.map(
323
- (item) => String((item == null ? void 0 : item.code) || "").trim().toUpperCase()
324
- )
325
- );
326
- this.searchResults = [
327
- ...this.searchResults.filter(
328
- (item) => !replacedCodes.has(String((item == null ? void 0 : item.code) || "").trim().toUpperCase())
329
- ),
330
- ...refreshedAssets
331
- ];
332
- }
333
- return mergeWalletAssets(
334
- cachedAssets,
335
- refreshedAssets
336
- );
337
- }
338
- isPendingAutoSelectAsset(asset) {
339
- return getWalletAssetCodeKeys(asset).some(
340
- (code) => this.pendingAutoSelectSearchCodes.has(code)
341
- );
342
- }
343
- clearPendingAutoSelectForAsset(asset) {
344
- getWalletAssetCodeKeys(asset).forEach((code) => {
345
- this.pendingAutoSelectSearchCodes.delete(code);
346
- });
347
- }
348
- queuePendingAutoSelectForAssets(assets) {
349
- if (!this.walletAssetsBehavior.autoSelectAfterSearch)
350
- return;
351
- assets.forEach((asset) => {
352
- getWalletAssetCodeKeys(asset).forEach((code) => {
353
- this.pendingAutoSelectSearchCodes.add(code);
354
- });
355
- });
356
- }
357
51
  /**
358
52
  * 生成钱包API默认参数
359
53
  * 根据业务数据生成标准的钱包API参数,并存储在模块中
@@ -381,17 +75,13 @@ var WalletPassPaymentImpl = class {
381
75
  // 订单小计金额
382
76
  order_product_amount: subTotal,
383
77
  // 订单待支付金额
384
- order_wait_pay_amount: order_wait_pay_amount ?? ((amountInfo == null ? void 0 : amountInfo.isDeposit) ? Number(amountInfo == null ? void 0 : amountInfo.depositAmount) : totalAmount),
78
+ order_wait_pay_amount: order_wait_pay_amount || ((amountInfo == null ? void 0 : amountInfo.isDeposit) ? Number(amountInfo == null ? void 0 : amountInfo.depositAmount) : totalAmount),
385
79
  // order_behavior_count_customer_id: 1,
386
80
  products,
387
81
  prepare_payments: [],
388
82
  payment_order_id
389
83
  };
390
84
  this.walletParams = walletParams;
391
- this.walletAssetsCalculationContext = {
392
- orderTotalAmount: Number(walletParams.order_wait_pay_amount || 0),
393
- products: Array.isArray(walletParams.products) ? walletParams.products : []
394
- };
395
85
  this.paymentModule.logInfo("[WalletPass] 钱包默认参数已生成并存储", {
396
86
  customer_id: walletParams.customer_id,
397
87
  holder_id: walletParams.holder_id,
@@ -543,6 +233,7 @@ var WalletPassPaymentImpl = class {
543
233
  vouchers: allList
544
234
  });
545
235
  const { recommended, transformList, noApplicableVoucher, recommendedAmount } = res;
236
+ console.log(res, "resres12");
546
237
  this.walletRecommendList = recommended;
547
238
  this.walletInitData = {
548
239
  transformList,
@@ -564,96 +255,6 @@ var WalletPassPaymentImpl = class {
564
255
  throw error;
565
256
  }
566
257
  }
567
- /**
568
- * 商品或订单金额变化后,使用聚合接口一次重算已选与剩余 WalletPass。
569
- * Walk-In 不发送 customer_id;会员才携带真实 customer_id。
570
- */
571
- async aggregateRecalculateWalletAssetsAsync(businessData, selectedIds) {
572
- var _a, _b;
573
- const walletParams = this.generateWalletParams(businessData);
574
- const customerId = Number(walletParams.customer_id || 0);
575
- const requestParams = {
576
- ids: selectedIds.map((id) => String(id)),
577
- exact_codes: this.getSearchedWalletAssetCodes(),
578
- order_product_amount: walletParams.order_product_amount,
579
- order_expect_amount: walletParams.order_expect_amount,
580
- order_wait_pay_amount: walletParams.order_wait_pay_amount,
581
- products: walletParams.products,
582
- available: 2,
583
- filter_prepare_wallet_pass: 1,
584
- sale_channel: walletParams.sale_channel || "pos"
585
- };
586
- if (customerId > 1) {
587
- requestParams.customer_id = customerId;
588
- }
589
- const response = await this.paymentModule.request.post(
590
- "/machinecode/prepare/deduction/aggregate-recalculate",
591
- requestParams
592
- );
593
- const responseData = response == null ? void 0 : response.data;
594
- const hasAggregateLists = responseData && (Object.prototype.hasOwnProperty.call(
595
- responseData,
596
- "recalculate_list"
597
- ) || Object.prototype.hasOwnProperty.call(
598
- responseData,
599
- "customer_wallet_pass_list"
600
- ));
601
- if (!hasAggregateLists) {
602
- throw new Error("WalletPass aggregate response is missing list data");
603
- }
604
- const recalculateList = Array.isArray(responseData == null ? void 0 : responseData.recalculate_list) ? responseData.recalculate_list : [];
605
- const customerWalletPassList = Array.isArray(
606
- responseData == null ? void 0 : responseData.customer_wallet_pass_list
607
- ) ? responseData.customer_wallet_pass_list : [];
608
- const allList = mergeWalletAssets(
609
- recalculateList,
610
- customerWalletPassList
611
- );
612
- const walletPassEvaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
613
- const evaluated = (walletPassEvaluator == null ? void 0 : walletPassEvaluator.getRecommendedVouchers) ? walletPassEvaluator.getRecommendedVouchers({
614
- orderTotalAmount: walletParams.order_wait_pay_amount,
615
- products: walletParams.products,
616
- vouchers: allList
617
- }) : {
618
- recommended: [],
619
- transformList: allList.filter(isWalletAssetAvailable),
620
- noApplicableVoucher: allList.filter(
621
- (item) => !isWalletAssetAvailable(item)
622
- )
623
- };
624
- const returnedSelectedKeys = new Set(
625
- allList.map((item) => getWalletAssetKey(item))
626
- );
627
- const authoritativeSelectedIds = selectedIds.filter(
628
- (id) => returnedSelectedKeys.has(String(id))
629
- );
630
- this.walletRecommendList = evaluated.recommended || [];
631
- this.userIdentificationCodes = allList;
632
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
633
- userIdentificationCodes: this.userIdentificationCodes
634
- });
635
- this.walletInitData = {
636
- transformList: evaluated.transformList || [],
637
- noApplicableVoucher: evaluated.noApplicableVoucher || [],
638
- products: walletParams.products || []
639
- };
640
- this.paymentModule.logInfo(
641
- "[WalletPass] 聚合重算 WalletPass 完成",
642
- {
643
- selected_count: recalculateList.length,
644
- remaining_count: customerWalletPassList.length,
645
- searched_codes_count: requestParams.exact_codes.length
646
- }
647
- );
648
- return {
649
- walletRecommendList: this.walletRecommendList,
650
- userIdentificationCodes: this.userIdentificationCodes,
651
- transformList: evaluated.transformList || [],
652
- noApplicableVoucher: evaluated.noApplicableVoucher || [],
653
- products: walletParams.products || [],
654
- authoritativeSelectedIds
655
- };
656
- }
657
258
  async getWalletPassRecommendListAsync(params) {
658
259
  var _a;
659
260
  try {
@@ -755,6 +356,7 @@ var WalletPassPaymentImpl = class {
755
356
  * 特殊逻辑:当识别码长度为9位且前3位为"000"时,调用 /wallet/detail/search 接口
756
357
  */
757
358
  async searchIdentificationCodeAsync(params, config = {}) {
359
+ var _a;
758
360
  try {
759
361
  const { code } = params;
760
362
  this.paymentModule.logInfo("[WalletPass] 开始搜索识别码", {
@@ -792,14 +394,14 @@ var WalletPassPaymentImpl = class {
792
394
  const baseWalletParams = this.walletParams;
793
395
  const searchParams = {
794
396
  // 基础钱包参数
795
- sale_channel: params.sale_channel ?? (baseWalletParams == null ? void 0 : baseWalletParams.sale_channel) ?? "pos",
796
- customer_id: params.customer_id ?? (baseWalletParams == null ? void 0 : baseWalletParams.customer_id),
797
- order_expect_amount: params.order_expect_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_expect_amount),
798
- order_product_amount: params.order_product_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_product_amount),
799
- order_wait_pay_amount: params.order_wait_pay_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_wait_pay_amount),
800
- order_behavior_count_customer_id: params.order_behavior_count_customer_id ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_behavior_count_customer_id) ?? params.customer_id ?? (baseWalletParams == null ? void 0 : baseWalletParams.customer_id),
801
- products: params.products ?? (baseWalletParams == null ? void 0 : baseWalletParams.products) ?? [],
802
- prepare_payments: params.prepare_payments ?? (baseWalletParams == null ? void 0 : baseWalletParams.prepare_payments) ?? [],
397
+ sale_channel: params.sale_channel || (baseWalletParams == null ? void 0 : baseWalletParams.sale_channel) || "pos",
398
+ customer_id: params.customer_id || (baseWalletParams == null ? void 0 : baseWalletParams.customer_id),
399
+ order_expect_amount: params.order_expect_amount || (baseWalletParams == null ? void 0 : baseWalletParams.order_expect_amount),
400
+ order_product_amount: params.order_product_amount || (baseWalletParams == null ? void 0 : baseWalletParams.order_product_amount),
401
+ order_wait_pay_amount: params.order_wait_pay_amount || (baseWalletParams == null ? void 0 : baseWalletParams.order_wait_pay_amount),
402
+ order_behavior_count_customer_id: params.order_behavior_count_customer_id || (baseWalletParams == null ? void 0 : baseWalletParams.order_behavior_count_customer_id) || params.customer_id || (baseWalletParams == null ? void 0 : baseWalletParams.customer_id),
403
+ products: params.products || (baseWalletParams == null ? void 0 : baseWalletParams.products),
404
+ prepare_payments: params.prepare_payments || (baseWalletParams == null ? void 0 : baseWalletParams.prepare_payments),
803
405
  multiple: 1,
804
406
  // 搜索特有参数
805
407
  code: params.code,
@@ -815,10 +417,17 @@ var WalletPassPaymentImpl = class {
815
417
  if (typeof searchParams.payment_order_id === "string" && searchParams.payment_order_id.startsWith("LOCAL_")) {
816
418
  searchParams.payment_order_id = void 0;
817
419
  }
818
- const response = await this.paymentModule.request.post(
819
- "/machinecode/prepare/deduction/search",
820
- searchParams
821
- );
420
+ let response;
421
+ if (!searchParams.products || ((_a = searchParams.products || []) == null ? void 0 : _a.length) === 0) {
422
+ response = {
423
+ data: []
424
+ };
425
+ } else {
426
+ response = await this.paymentModule.request.post(
427
+ "/machinecode/prepare/deduction/search",
428
+ searchParams
429
+ );
430
+ }
822
431
  const searchResults = (response == null ? void 0 : response.data) || [];
823
432
  if (config.noCache) {
824
433
  return {
@@ -860,482 +469,6 @@ var WalletPassPaymentImpl = class {
860
469
  throw error;
861
470
  }
862
471
  }
863
- /**
864
- * 刷新购物车与结账共享的钱包资产。
865
- *
866
- * 与 legacy initializeWalletDataFromBusinessAsync 不同,这里维护选择状态;
867
- * 推荐结果只作为可用性/金额计算输入,不会自动成为 selectedIds。
868
- */
869
- async refreshWalletAssetsFromBusinessAsync(businessData, options = {}) {
870
- var _a;
871
- const requestSequence = ++this.walletAssetsRequestSequence;
872
- const nextCustomerId = businessData.customer_id;
873
- const previousCustomerId = this.walletAssetsState.customerId;
874
- const customerChanged = String(previousCustomerId ?? "") !== String(nextCustomerId ?? "");
875
- const preserveSelection = options.preserveSelection !== false && !customerChanged;
876
- if (customerChanged) {
877
- this.clearSearchResults();
878
- }
879
- const committedKeys = new Set(
880
- this.walletAssetsState.committedIds.map((id) => String(id))
881
- );
882
- const committedItems = this.walletAssetsState.items.filter(
883
- (item) => committedKeys.has(getWalletAssetKey(item))
884
- );
885
- const selectedIds = preserveSelection ? [...this.walletAssetsState.selectedIds] : [];
886
- const selectionSources = preserveSelection ? { ...this.walletAssetsState.selectionSources } : {};
887
- const scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter((asset) => {
888
- const assetId = getWalletAssetId(asset);
889
- return assetId !== void 0 && assetId !== null && selectionSources[String(assetId)] === "scan";
890
- }) : [];
891
- const manualEditAmountByKey = /* @__PURE__ */ new Map();
892
- if (preserveSelection) {
893
- this.walletAssetsState.selectedItems.forEach((asset) => {
894
- if (typeof (asset == null ? void 0 : asset.edit_current_amount) !== "number")
895
- return;
896
- manualEditAmountByKey.set(
897
- getWalletAssetKey(asset),
898
- asset.edit_current_amount
899
- );
900
- });
901
- }
902
- if (!((_a = businessData.products) == null ? void 0 : _a.length)) {
903
- this.queuePendingAutoSelectForAssets(scanSelectedAssets);
904
- this.generateWalletParams(businessData);
905
- const restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map((item) => ({
906
- ...item,
907
- actualDeduction: 0,
908
- deductionDetails: [],
909
- _available_max_amount: 0,
910
- _unified_available_status: 0,
911
- _wallet_asset_recommended: false
912
- }));
913
- this.walletRecommendList = [];
914
- this.userIdentificationCodes = [];
915
- this.walletInitData = {
916
- transformList: [],
917
- noApplicableVoucher: restoredSearchedAssets,
918
- products: []
919
- };
920
- this.walletAssetsCalculationContext = {
921
- orderTotalAmount: 0,
922
- products: []
923
- };
924
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
925
- userIdentificationCodes: []
926
- });
927
- return this.publishWalletAssetsState({
928
- status: "ready",
929
- customerId: nextCustomerId,
930
- items: mergeWalletAssets(
931
- restoredSearchedAssets,
932
- committedItems
933
- ),
934
- selectedIds: [],
935
- selectedItems: [],
936
- selectionSources: {},
937
- totalSelectedAmount: 0,
938
- error: null
939
- });
940
- }
941
- this.publishWalletAssetsState({
942
- status: "loading",
943
- customerId: nextCustomerId,
944
- items: preserveSelection ? this.walletAssetsState.items : committedItems,
945
- selectedIds,
946
- selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
947
- selectionSources,
948
- totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
949
- error: null
950
- });
951
- try {
952
- const searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
953
- const useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
954
- const aggregateResult = useAggregateRecalculate ? await this.aggregateRecalculateWalletAssetsAsync(
955
- businessData,
956
- selectedIds
957
- ) : null;
958
- const result = aggregateResult || await this.initializeWalletDataFromBusinessAsync(businessData);
959
- if (requestSequence !== this.walletAssetsRequestSequence) {
960
- return this.getWalletAssetsState();
961
- }
962
- this.walletAssetsCalculationContext = {
963
- orderTotalAmount: Number(businessData.order_wait_pay_amount || 0),
964
- products: result.products || businessData.products || []
965
- };
966
- const authoritativeSelectedIds = (aggregateResult == null ? void 0 : aggregateResult.authoritativeSelectedIds) || selectedIds;
967
- if (aggregateResult) {
968
- const returnedAggregateKeys = new Set(
969
- [
970
- ...result.transformList || [],
971
- ...result.noApplicableVoucher || []
972
- ].map((item) => getWalletAssetKey(item))
973
- );
974
- const missingSelectedKeys = new Set(
975
- selectedIds.map((id) => String(id)).filter((id) => !returnedAggregateKeys.has(id))
976
- );
977
- if (missingSelectedKeys.size > 0) {
978
- this.searchResults = this.searchResults.filter(
979
- (item) => !missingSelectedKeys.has(getWalletAssetKey(item))
980
- );
981
- }
982
- }
983
- const searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([
984
- ...result.transformList || [],
985
- ...result.noApplicableVoucher || []
986
- ]) : [];
987
- if (requestSequence !== this.walletAssetsRequestSequence) {
988
- return this.getWalletAssetsState();
989
- }
990
- const recommendedKeys = new Set(
991
- (result.walletRecommendList || []).map(
992
- (asset) => getWalletAssetKey(asset)
993
- )
994
- );
995
- const items = mergeWalletAssets(
996
- preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [],
997
- searchedWalletAssets,
998
- result.transformList || [],
999
- result.noApplicableVoucher || []
1000
- ).map((asset) => {
1001
- const assetKey = getWalletAssetKey(asset);
1002
- return {
1003
- ...asset,
1004
- ...manualEditAmountByKey.has(assetKey) ? {
1005
- edit_current_amount: manualEditAmountByKey.get(assetKey)
1006
- } : {},
1007
- _wallet_asset_recommended: recommendedKeys.has(assetKey)
1008
- };
1009
- });
1010
- const latestSelectedIds = preserveSelection ? authoritativeSelectedIds : [];
1011
- const latestSelectionSources = preserveSelection ? { ...this.walletAssetsState.selectionSources } : {};
1012
- const pendingAutoSelectAssets = this.walletAssetsBehavior.autoSelectAfterSearch ? items.filter(
1013
- (asset) => this.isPendingAutoSelectAsset(asset) && isWalletAssetAvailable(asset)
1014
- ) : [];
1015
- const requestedKeySet = new Set(
1016
- latestSelectedIds.map((id) => String(id))
1017
- );
1018
- pendingAutoSelectAssets.forEach((asset) => {
1019
- const assetId = getWalletAssetId(asset);
1020
- if (assetId === void 0 || assetId === null)
1021
- return;
1022
- const assetKey = String(assetId);
1023
- if (!requestedKeySet.has(assetKey)) {
1024
- requestedKeySet.add(assetKey);
1025
- latestSelectedIds.push(assetId);
1026
- }
1027
- latestSelectionSources[assetKey] = "scan";
1028
- });
1029
- const nextState = this.recalculateWalletAssets(
1030
- items,
1031
- latestSelectedIds,
1032
- latestSelectionSources
1033
- );
1034
- const selectedKeySet = new Set(
1035
- nextState.selectedIds.map((id) => String(id))
1036
- );
1037
- pendingAutoSelectAssets.forEach((asset) => {
1038
- const assetId = getWalletAssetId(asset);
1039
- if (assetId !== void 0 && assetId !== null && selectedKeySet.has(String(assetId))) {
1040
- this.clearPendingAutoSelectForAsset(asset);
1041
- }
1042
- });
1043
- const droppedScanSelectedAssets = scanSelectedAssets.filter((asset) => {
1044
- const assetId = getWalletAssetId(asset);
1045
- return assetId !== void 0 && assetId !== null && !selectedKeySet.has(String(assetId));
1046
- });
1047
- this.queuePendingAutoSelectForAssets(droppedScanSelectedAssets);
1048
- return nextState;
1049
- } catch (error) {
1050
- if (requestSequence !== this.walletAssetsRequestSequence) {
1051
- return this.getWalletAssetsState();
1052
- }
1053
- this.paymentModule.logError(
1054
- "[WalletPass] 刷新共享钱包资产失败,保留刷新前状态",
1055
- error,
1056
- {
1057
- customer_id: businessData.customer_id,
1058
- selected_ids: selectedIds,
1059
- searched_codes: this.getSearchedWalletAssetCodes()
1060
- }
1061
- );
1062
- return this.publishWalletAssetsState({
1063
- status: "error",
1064
- items: preserveSelection ? this.walletAssetsState.items : committedItems,
1065
- selectedIds: preserveSelection ? this.walletAssetsState.selectedIds : [],
1066
- selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
1067
- selectionSources: preserveSelection ? this.walletAssetsState.selectionSources : {},
1068
- totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
1069
- customerId: nextCustomerId,
1070
- error: error instanceof Error ? error.message : String(error)
1071
- });
1072
- }
1073
- }
1074
- getWalletAssetsState() {
1075
- return {
1076
- ...this.walletAssetsState,
1077
- items: [...this.walletAssetsState.items],
1078
- selectedIds: [...this.walletAssetsState.selectedIds],
1079
- selectedItems: [...this.walletAssetsState.selectedItems],
1080
- committedIds: [...this.walletAssetsState.committedIds],
1081
- selectionSources: { ...this.walletAssetsState.selectionSources }
1082
- };
1083
- }
1084
- exportWalletAssetsSnapshot() {
1085
- return {
1086
- state: this.getWalletAssetsState(),
1087
- searchResults: [...this.searchResults],
1088
- pendingAutoSelectSearchCodes: [
1089
- ...this.pendingAutoSelectSearchCodes
1090
- ],
1091
- walletParams: this.walletParams ? { ...this.walletParams } : null,
1092
- calculationContext: {
1093
- orderTotalAmount: this.walletAssetsCalculationContext.orderTotalAmount,
1094
- products: [...this.walletAssetsCalculationContext.products]
1095
- }
1096
- };
1097
- }
1098
- importWalletAssetsSnapshot(snapshot) {
1099
- var _a, _b;
1100
- if (!(snapshot == null ? void 0 : snapshot.state))
1101
- return this.getWalletAssetsState();
1102
- this.walletAssetsRequestSequence += 1;
1103
- this.searchResults = Array.isArray(snapshot.searchResults) ? [...snapshot.searchResults] : [];
1104
- this.pendingAutoSelectSearchCodes = this.walletAssetsBehavior.autoSelectAfterSearch && Array.isArray(snapshot.pendingAutoSelectSearchCodes) ? new Set(
1105
- snapshot.pendingAutoSelectSearchCodes.map(normalizeWalletAssetCode).filter(Boolean)
1106
- ) : /* @__PURE__ */ new Set();
1107
- this.walletParams = snapshot.walletParams ? { ...snapshot.walletParams } : null;
1108
- this.walletAssetsCalculationContext = {
1109
- orderTotalAmount: Number(
1110
- ((_a = snapshot.calculationContext) == null ? void 0 : _a.orderTotalAmount) || 0
1111
- ),
1112
- products: Array.isArray((_b = snapshot.calculationContext) == null ? void 0 : _b.products) ? [...snapshot.calculationContext.products] : []
1113
- };
1114
- return this.publishWalletAssetsState({
1115
- ...snapshot.state,
1116
- items: Array.isArray(snapshot.state.items) ? snapshot.state.items : [],
1117
- selectedIds: Array.isArray(snapshot.state.selectedIds) ? snapshot.state.selectedIds : [],
1118
- selectedItems: Array.isArray(snapshot.state.selectedItems) ? snapshot.state.selectedItems : [],
1119
- committedIds: Array.isArray(snapshot.state.committedIds) ? snapshot.state.committedIds : [],
1120
- selectionSources: snapshot.state.selectionSources || {}
1121
- });
1122
- }
1123
- updateWalletAssetEditAmountInCaches(assetKey, amount) {
1124
- const updateAsset = (asset) => getWalletAssetKey(asset) === assetKey ? { ...asset, edit_current_amount: amount } : asset;
1125
- this.searchResults = this.searchResults.map(
1126
- updateAsset
1127
- );
1128
- return this.walletAssetsState.items.map(updateAsset);
1129
- }
1130
- selectWalletAsset(assetId, options) {
1131
- const assetKey = String(assetId);
1132
- const asset = this.walletAssetsState.items.find(
1133
- (item) => getWalletAssetKey(item) === assetKey
1134
- );
1135
- const committedKeys = new Set(
1136
- this.walletAssetsState.committedIds.map((id) => String(id))
1137
- );
1138
- if (committedKeys.has(assetKey))
1139
- return this.getWalletAssetsState();
1140
- const selectedIds = this.walletAssetsState.selectedIds.filter(
1141
- (id) => String(id) !== assetKey
1142
- );
1143
- const selectionSources = { ...this.walletAssetsState.selectionSources };
1144
- delete selectionSources[assetKey];
1145
- let nextItems = this.walletAssetsState.items;
1146
- if (options.selected) {
1147
- if (!asset || !isWalletAssetAvailable(asset)) {
1148
- return this.getWalletAssetsState();
1149
- }
1150
- selectedIds.push(assetId);
1151
- selectionSources[assetKey] = options.source || "manual";
1152
- } else if (asset) {
1153
- this.clearPendingAutoSelectForAsset(asset);
1154
- nextItems = this.updateWalletAssetEditAmountInCaches(
1155
- assetKey,
1156
- void 0
1157
- );
1158
- }
1159
- const nextState = this.recalculateWalletAssets(
1160
- nextItems,
1161
- selectedIds,
1162
- selectionSources
1163
- );
1164
- if (options.selected && asset && nextState.selectedIds.some((id) => String(id) === assetKey)) {
1165
- this.clearPendingAutoSelectForAsset(asset);
1166
- }
1167
- return nextState;
1168
- }
1169
- /**
1170
- * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
1171
- * 金额为 0 时沿用 legacy 行为取消选择。
1172
- */
1173
- updateWalletAssetAmount(assetId, amount) {
1174
- const assetKey = String(assetId);
1175
- const committedKeys = new Set(
1176
- this.walletAssetsState.committedIds.map((id) => String(id))
1177
- );
1178
- const selectedKeys = new Set(
1179
- this.walletAssetsState.selectedIds.map((id) => String(id))
1180
- );
1181
- const asset = this.walletAssetsState.items.find(
1182
- (item) => getWalletAssetKey(item) === assetKey
1183
- );
1184
- const requestedAmount = Number(amount);
1185
- if (!asset || committedKeys.has(assetKey) || !selectedKeys.has(assetKey) || !Number.isFinite(requestedAmount) || requestedAmount < 0) {
1186
- return this.getWalletAssetsState();
1187
- }
1188
- const selectedIds = [...this.walletAssetsState.selectedIds];
1189
- const selectionSources = { ...this.walletAssetsState.selectionSources };
1190
- if (requestedAmount === 0) {
1191
- const nextItems2 = this.updateWalletAssetEditAmountInCaches(
1192
- assetKey,
1193
- void 0
1194
- );
1195
- delete selectionSources[assetKey];
1196
- this.clearPendingAutoSelectForAsset(asset);
1197
- return this.recalculateWalletAssets(
1198
- nextItems2,
1199
- selectedIds.filter((id) => String(id) !== assetKey),
1200
- selectionSources
1201
- );
1202
- }
1203
- const currentDeductionAmount = getWalletAssetDeductionAmount(asset);
1204
- const editAmount = Math.min(requestedAmount, currentDeductionAmount);
1205
- if (editAmount <= 0)
1206
- return this.getWalletAssetsState();
1207
- const nextItems = this.updateWalletAssetEditAmountInCaches(
1208
- assetKey,
1209
- editAmount
1210
- );
1211
- return this.recalculateWalletAssets(
1212
- nextItems,
1213
- selectedIds,
1214
- selectionSources
1215
- );
1216
- }
1217
- async scanWalletAssetAsync(code) {
1218
- const normalizedCode = String(code || "").trim();
1219
- if (!normalizedCode) {
1220
- return {
1221
- type: "normalCode",
1222
- selected: false,
1223
- state: this.getWalletAssetsState()
1224
- };
1225
- }
1226
- const selectedAsset = this.walletAssetsState.selectedItems.find(
1227
- (asset2) => matchesWalletAssetCode(asset2, normalizedCode)
1228
- );
1229
- if (selectedAsset) {
1230
- return {
1231
- type: "normalCode",
1232
- asset: selectedAsset,
1233
- selected: true,
1234
- state: this.getWalletAssetsState()
1235
- };
1236
- }
1237
- this.walletAssetsRequestSequence += 1;
1238
- const result = await this.searchIdentificationCodeAsync({
1239
- ...this.walletParams || {},
1240
- code: normalizedCode,
1241
- prepare_payments: this.formatWalletPassList2PreparePayments(
1242
- this.walletAssetsState.selectedItems
1243
- )
1244
- });
1245
- const paymentAssets = this.formatSearchedWalletPaymentAssets(
1246
- result.data.filter(isWalletPaymentAsset)
1247
- );
1248
- if (paymentAssets.length > 0) {
1249
- this.searchResults = mergeWalletAssets(
1250
- this.searchResults,
1251
- paymentAssets
1252
- );
1253
- }
1254
- const asset = paymentAssets.find(
1255
- (item) => String((item == null ? void 0 : item.code) || "") === normalizedCode
1256
- ) || paymentAssets[0];
1257
- if (!asset || result.type === "walletCode") {
1258
- return {
1259
- type: result.type,
1260
- asset,
1261
- selected: false,
1262
- state: this.getWalletAssetsState()
1263
- };
1264
- }
1265
- const items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1266
- const recalculatedState = this.recalculateWalletAssets(
1267
- items,
1268
- this.walletAssetsState.selectedIds,
1269
- this.walletAssetsState.selectionSources
1270
- );
1271
- const assetId = getWalletAssetId(asset);
1272
- const recalculatedAsset = assetId === void 0 ? void 0 : recalculatedState.items.find(
1273
- (item) => getWalletAssetKey(item) === String(assetId)
1274
- );
1275
- const selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== void 0 && isWalletAssetAvailable(recalculatedAsset) ? this.selectWalletAsset(assetId, {
1276
- selected: true,
1277
- source: "scan"
1278
- }) : recalculatedState;
1279
- const isSelected = assetId !== void 0 && selected.selectedIds.some((id) => String(id) === String(assetId));
1280
- const selectedStateAsset = assetId === void 0 ? void 0 : selected.items.find(
1281
- (item) => getWalletAssetKey(item) === String(assetId)
1282
- );
1283
- const resolvedAsset = selectedStateAsset || recalculatedAsset || asset;
1284
- if (isSelected) {
1285
- this.clearPendingAutoSelectForAsset(resolvedAsset);
1286
- } else if (this.walletAssetsBehavior.autoSelectAfterSearch) {
1287
- this.pendingAutoSelectSearchCodes.add(
1288
- normalizeWalletAssetCode(normalizedCode)
1289
- );
1290
- this.queuePendingAutoSelectForAssets([resolvedAsset]);
1291
- }
1292
- return {
1293
- type: result.type,
1294
- asset: resolvedAsset,
1295
- selected: isSelected,
1296
- state: selected
1297
- };
1298
- }
1299
- clearWalletAssetSelection() {
1300
- this.pendingAutoSelectSearchCodes.clear();
1301
- const selectedKeys = new Set(
1302
- this.walletAssetsState.selectedIds.map((id) => String(id))
1303
- );
1304
- const clearSelectedEditAmount = (asset) => selectedKeys.has(getWalletAssetKey(asset)) ? { ...asset, edit_current_amount: void 0 } : asset;
1305
- this.searchResults = this.searchResults.map(
1306
- clearSelectedEditAmount
1307
- );
1308
- return this.recalculateWalletAssets(
1309
- this.walletAssetsState.items.map(clearSelectedEditAmount),
1310
- [],
1311
- {}
1312
- );
1313
- }
1314
- setCommittedWalletAssets(committedIds, committedAssets = []) {
1315
- const committedKeys = new Set(committedIds.map((id) => String(id)));
1316
- const selectedIds = this.walletAssetsState.selectedIds.filter(
1317
- (id) => !committedKeys.has(String(id))
1318
- );
1319
- const selectionSources = Object.entries(
1320
- this.walletAssetsState.selectionSources
1321
- ).reduce(
1322
- (result, [key, source]) => {
1323
- if (!committedKeys.has(key))
1324
- result[key] = source;
1325
- return result;
1326
- },
1327
- {}
1328
- );
1329
- this.publishWalletAssetsState({
1330
- items: mergeWalletAssets(this.walletAssetsState.items, committedAssets),
1331
- committedIds
1332
- });
1333
- return this.recalculateWalletAssets(
1334
- this.walletAssetsState.items,
1335
- selectedIds,
1336
- selectionSources
1337
- );
1338
- }
1339
472
  async processWalletPayment(amount, orderUuid, voucherId) {
1340
473
  this.paymentModule.logInfo("[WalletPass] 开始处理钱包支付", {
1341
474
  amount,
@@ -1419,7 +552,6 @@ var WalletPassPaymentImpl = class {
1419
552
  */
1420
553
  clearSearchResults() {
1421
554
  this.searchResults = [];
1422
- this.pendingAutoSelectSearchCodes.clear();
1423
555
  this.paymentModule.logInfo("[WalletPass] 搜索结果缓存已清除");
1424
556
  }
1425
557
  /**
@@ -1442,16 +574,8 @@ var WalletPassPaymentImpl = class {
1442
574
  this.walletRecommendList = [];
1443
575
  this.userIdentificationCodes = [];
1444
576
  this.searchResults = [];
1445
- this.pendingAutoSelectSearchCodes.clear();
1446
577
  this.walletParams = null;
1447
578
  this.walletInitData = null;
1448
- this.walletAssetsRequestSequence += 1;
1449
- this.walletAssetsCalculationContext = {
1450
- orderTotalAmount: 0,
1451
- products: []
1452
- };
1453
- this.walletAssetsState = createInitialWalletAssetsState();
1454
- this.publishWalletAssetsState({});
1455
579
  this.emitEvent(import_types.WalletPassHooks.OnWalletCacheCleared, {
1456
580
  clearedTypes: ["all"]
1457
581
  });