@pisell/pisellos 2.2.276 → 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 (119) hide show
  1. package/dist/core/index.d.ts +0 -2
  2. package/dist/core/index.js +0 -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/modules/OpenData/index.d.ts +0 -2
  14. package/dist/modules/OpenData/index.js +0 -8
  15. package/dist/modules/Order/index.d.ts +8 -28
  16. package/dist/modules/Order/index.js +496 -808
  17. package/dist/modules/Order/types.d.ts +1 -35
  18. package/dist/modules/Order/utils/orderCollectionIdentity.js +2 -7
  19. package/dist/modules/Order/utils.js +6 -10
  20. package/dist/modules/Payment/index.d.ts +0 -2
  21. package/dist/modules/Payment/index.js +49 -78
  22. package/dist/modules/Payment/types.d.ts +25 -104
  23. package/dist/modules/Payment/types.js +0 -17
  24. package/dist/modules/Payment/walletpass.d.ts +1 -38
  25. package/dist/modules/Payment/walletpass.js +114 -917
  26. package/dist/modules/Rules/index.d.ts +0 -3
  27. package/dist/modules/Rules/index.js +70 -100
  28. package/dist/server/index.d.ts +0 -25
  29. package/dist/server/index.js +1069 -2001
  30. package/dist/server/modules/index.d.ts +1 -1
  31. package/dist/server/modules/order/index.d.ts +4 -70
  32. package/dist/server/modules/order/index.js +728 -1816
  33. package/dist/server/modules/order/types.d.ts +3 -25
  34. package/dist/server/modules/order/types.js +1 -7
  35. package/dist/server/utils/small-ticket.js +2 -1
  36. package/dist/solution/BaseSales/index.d.ts +5 -104
  37. package/dist/solution/BaseSales/index.js +436 -1767
  38. package/dist/solution/BaseSales/types.d.ts +1 -55
  39. package/dist/solution/BaseSales/types.js +1 -2
  40. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  41. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -90
  42. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  43. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -7
  44. package/dist/solution/BookingByStep/index.d.ts +1 -1
  45. package/dist/solution/BookingTicket/index.d.ts +5 -21
  46. package/dist/solution/BookingTicket/index.js +56 -139
  47. package/dist/solution/BookingTicket/types.d.ts +0 -1
  48. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +83 -173
  50. package/dist/solution/Sales/index.d.ts +0 -2
  51. package/dist/solution/Sales/index.js +4 -26
  52. package/dist/solution/ScanOrder/index.js +20 -31
  53. package/dist/solution/VenueBooking/index.d.ts +0 -1
  54. package/dist/solution/VenueBooking/index.js +19 -30
  55. package/dist/types/index.d.ts +0 -1
  56. package/lib/core/index.d.ts +0 -2
  57. package/lib/core/index.js +0 -4
  58. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  59. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  60. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  61. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  62. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  63. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  64. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  65. package/lib/model/strategy/adapter/promotion/index.js +0 -2
  66. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  67. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  68. package/lib/modules/OpenData/index.d.ts +0 -2
  69. package/lib/modules/OpenData/index.js +0 -5
  70. package/lib/modules/Order/index.d.ts +8 -28
  71. package/lib/modules/Order/index.js +69 -231
  72. package/lib/modules/Order/types.d.ts +1 -35
  73. package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -3
  74. package/lib/modules/Order/utils.js +4 -11
  75. package/lib/modules/Payment/index.d.ts +0 -2
  76. package/lib/modules/Payment/index.js +12 -33
  77. package/lib/modules/Payment/types.d.ts +25 -104
  78. package/lib/modules/Payment/types.js +0 -1
  79. package/lib/modules/Payment/walletpass.d.ts +1 -38
  80. package/lib/modules/Payment/walletpass.js +21 -730
  81. package/lib/modules/Rules/index.d.ts +0 -3
  82. package/lib/modules/Rules/index.js +9 -38
  83. package/lib/server/index.d.ts +0 -25
  84. package/lib/server/index.js +31 -726
  85. package/lib/server/modules/index.d.ts +1 -1
  86. package/lib/server/modules/order/index.d.ts +4 -70
  87. package/lib/server/modules/order/index.js +69 -818
  88. package/lib/server/modules/order/types.d.ts +3 -25
  89. package/lib/server/modules/order/types.js +0 -1
  90. package/lib/server/utils/small-ticket.js +1 -1
  91. package/lib/solution/BaseSales/index.d.ts +5 -104
  92. package/lib/solution/BaseSales/index.js +27 -858
  93. package/lib/solution/BaseSales/types.d.ts +1 -55
  94. package/lib/solution/BaseSales/types.js +1 -2
  95. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  96. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -63
  97. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +1 -6
  98. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -4
  99. package/lib/solution/BookingByStep/index.d.ts +1 -1
  100. package/lib/solution/BookingTicket/index.d.ts +5 -21
  101. package/lib/solution/BookingTicket/index.js +13 -64
  102. package/lib/solution/BookingTicket/types.d.ts +0 -1
  103. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -8
  104. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +5 -37
  105. package/lib/solution/Sales/index.d.ts +0 -2
  106. package/lib/solution/Sales/index.js +6 -20
  107. package/lib/solution/ScanOrder/index.js +0 -8
  108. package/lib/solution/VenueBooking/index.d.ts +0 -1
  109. package/lib/solution/VenueBooking/index.js +0 -8
  110. package/lib/types/index.d.ts +0 -1
  111. package/package.json +1 -1
  112. package/dist/modules/Order/payment-utils.d.ts +0 -26
  113. package/dist/modules/Order/payment-utils.js +0 -225
  114. package/dist/utils/payment-number.d.ts +0 -9
  115. package/dist/utils/payment-number.js +0 -69
  116. package/lib/modules/Order/payment-utils.d.ts +0 -26
  117. package/lib/modules/Order/payment-utils.js +0 -224
  118. package/lib/utils/payment-number.d.ts +0 -9
  119. package/lib/utils/payment-number.js +0 -64
@@ -24,85 +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 isWalletAssetAvailable(asset) {
56
- if (!asset)
57
- return false;
58
- if (asset.unified_available_status !== void 0 && Number(asset.unified_available_status) !== 1) {
59
- return false;
60
- }
61
- if (asset._unified_available_status !== void 0 && Number(asset._unified_available_status) !== 1) {
62
- return false;
63
- }
64
- if (asset.available === false || asset.isDisabled === true)
65
- return false;
66
- return true;
67
- }
68
- function getWalletAssetDeductionAmount(asset) {
69
- 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;
70
- const amount = Number(value);
71
- return Number.isFinite(amount) && amount > 0 ? amount : 0;
72
- }
73
- function mergeWalletAssets(...groups) {
74
- const merged = [];
75
- const indexByKey = /* @__PURE__ */ new Map();
76
- groups.flat().forEach((asset) => {
77
- const key = getWalletAssetKey(asset);
78
- if (!key)
79
- return;
80
- const existedIndex = indexByKey.get(key);
81
- if (existedIndex === void 0) {
82
- indexByKey.set(key, merged.length);
83
- merged.push(asset);
84
- return;
85
- }
86
- merged[existedIndex] = {
87
- ...merged[existedIndex],
88
- ...asset
89
- };
90
- });
91
- return merged;
92
- }
93
- function createInitialWalletAssetsState() {
94
- return {
95
- status: "idle",
96
- items: [],
97
- selectedIds: [],
98
- selectedItems: [],
99
- committedIds: [],
100
- selectionSources: {},
101
- totalSelectedAmount: 0,
102
- error: null,
103
- revision: 0
104
- };
105
- }
106
27
  var WalletPassPaymentImpl = class {
107
28
  constructor(paymentModule) {
108
29
  this.paymentModule = paymentModule;
@@ -111,24 +32,6 @@ var WalletPassPaymentImpl = class {
111
32
  this.searchResults = [];
112
33
  this.walletParams = null;
113
34
  this.walletInitData = null;
114
- this.walletAssetsState = createInitialWalletAssetsState();
115
- this.walletAssetsRequestSequence = 0;
116
- this.walletAssetsBehavior = {
117
- autoSelectAfterSearch: true
118
- };
119
- this.pendingAutoSelectSearchCodes = /* @__PURE__ */ new Set();
120
- this.walletAssetsCalculationContext = {
121
- orderTotalAmount: 0,
122
- products: []
123
- };
124
- }
125
- configureWalletAssetsBehavior(options) {
126
- if (options.autoSelectAfterSearch === void 0)
127
- return;
128
- this.walletAssetsBehavior.autoSelectAfterSearch = options.autoSelectAfterSearch;
129
- if (!options.autoSelectAfterSearch) {
130
- this.pendingAutoSelectSearchCodes.clear();
131
- }
132
35
  }
133
36
  /**
134
37
  * 发送事件的辅助方法
@@ -145,148 +48,6 @@ var WalletPassPaymentImpl = class {
145
48
  });
146
49
  }
147
50
  }
148
- publishWalletAssetsState(patch) {
149
- this.walletAssetsState = {
150
- ...this.walletAssetsState,
151
- ...patch,
152
- items: [...patch.items ?? this.walletAssetsState.items],
153
- selectedIds: [
154
- ...patch.selectedIds ?? this.walletAssetsState.selectedIds
155
- ],
156
- selectedItems: [
157
- ...patch.selectedItems ?? this.walletAssetsState.selectedItems
158
- ],
159
- committedIds: [
160
- ...patch.committedIds ?? this.walletAssetsState.committedIds
161
- ],
162
- selectionSources: {
163
- ...patch.selectionSources ?? this.walletAssetsState.selectionSources
164
- },
165
- revision: this.walletAssetsState.revision + 1
166
- };
167
- const state = this.getWalletAssetsState();
168
- this.emitEvent(import_types.WalletPassHooks.OnWalletAssetsStateChanged, { state });
169
- return state;
170
- }
171
- recalculateWalletAssets(items, requestedIds, selectionSources) {
172
- var _a, _b;
173
- const committedKeys = new Set(
174
- this.walletAssetsState.committedIds.map((id) => String(id))
175
- );
176
- const itemsByKey = new Map(
177
- items.map((item) => [getWalletAssetKey(item), item])
178
- );
179
- const requested = requestedIds.map((id) => String(id)).filter((id) => !committedKeys.has(id)).map((id) => itemsByKey.get(id)).filter((item) => item && isWalletAssetAvailable(item));
180
- let nextItems = items;
181
- let selectedItems = requested;
182
- const evaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
183
- if (evaluator == null ? void 0 : evaluator.recalculateVouchers) {
184
- try {
185
- const result = evaluator.recalculateVouchers(
186
- items,
187
- requested,
188
- this.walletAssetsCalculationContext.orderTotalAmount,
189
- this.walletAssetsCalculationContext.products
190
- );
191
- nextItems = mergeWalletAssets(items, (result == null ? void 0 : result.allWithUpdatedStatus) || []);
192
- selectedItems = ((result == null ? void 0 : result.selectedWithDetails) || []).filter(
193
- (item) => isWalletAssetAvailable(item) && getWalletAssetDeductionAmount(item) > 0
194
- );
195
- } catch (error) {
196
- this.paymentModule.logWarning(
197
- "[WalletPass] 共享钱包资产重新计算失败,回退接口可用状态",
198
- {
199
- error: error instanceof Error ? error.message : String(error)
200
- }
201
- );
202
- }
203
- }
204
- const selectedIds = selectedItems.map((item) => getWalletAssetId(item)).filter((id) => id !== void 0 && id !== null);
205
- const selectedKeys = new Set(selectedIds.map((id) => String(id)));
206
- const nextSources = Object.entries(selectionSources).reduce((result, [key, source]) => {
207
- if (selectedKeys.has(key))
208
- result[key] = source;
209
- return result;
210
- }, {});
211
- const totalSelectedAmount = selectedItems.reduce(
212
- (total, item) => total + getWalletAssetDeductionAmount(item),
213
- 0
214
- );
215
- return this.publishWalletAssetsState({
216
- status: "ready",
217
- items: nextItems,
218
- selectedIds,
219
- selectedItems,
220
- selectionSources: nextSources,
221
- totalSelectedAmount,
222
- error: null
223
- });
224
- }
225
- /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
226
- getSearchedWalletAssetCodes() {
227
- const cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
228
- const seenCodes = /* @__PURE__ */ new Set();
229
- return cachedAssets.map((item) => String((item == null ? void 0 : item.code) || "").trim()).filter((code) => {
230
- const normalizedCode = code.toUpperCase();
231
- if (!normalizedCode || seenCodes.has(normalizedCode))
232
- return false;
233
- seenCodes.add(normalizedCode);
234
- return true;
235
- });
236
- }
237
- /**
238
- * 用订单重算接口返回的数据更新扫码 Wallet 缓存。
239
- * 接口暂时缺失某个扫码 code 时继续保留旧值,避免列表闪空。
240
- */
241
- syncSearchedWalletAssets(refreshedCandidates) {
242
- const cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
243
- const searchedCodeKeys = new Set(
244
- this.getSearchedWalletAssetCodes().map((code) => code.toUpperCase())
245
- );
246
- if (searchedCodeKeys.size === 0)
247
- return cachedAssets;
248
- const refreshedAssets = refreshedCandidates.filter(
249
- (item) => isWalletPaymentAsset(item) && searchedCodeKeys.has(
250
- String((item == null ? void 0 : item.code) || "").trim().toUpperCase()
251
- )
252
- );
253
- if (refreshedAssets.length > 0) {
254
- const replacedCodes = new Set(
255
- refreshedAssets.map(
256
- (item) => String((item == null ? void 0 : item.code) || "").trim().toUpperCase()
257
- )
258
- );
259
- this.searchResults = [
260
- ...this.searchResults.filter(
261
- (item) => !replacedCodes.has(String((item == null ? void 0 : item.code) || "").trim().toUpperCase())
262
- ),
263
- ...refreshedAssets
264
- ];
265
- }
266
- return mergeWalletAssets(
267
- cachedAssets,
268
- refreshedAssets
269
- );
270
- }
271
- isPendingAutoSelectAsset(asset) {
272
- return getWalletAssetCodeKeys(asset).some(
273
- (code) => this.pendingAutoSelectSearchCodes.has(code)
274
- );
275
- }
276
- clearPendingAutoSelectForAsset(asset) {
277
- getWalletAssetCodeKeys(asset).forEach((code) => {
278
- this.pendingAutoSelectSearchCodes.delete(code);
279
- });
280
- }
281
- queuePendingAutoSelectForAssets(assets) {
282
- if (!this.walletAssetsBehavior.autoSelectAfterSearch)
283
- return;
284
- assets.forEach((asset) => {
285
- getWalletAssetCodeKeys(asset).forEach((code) => {
286
- this.pendingAutoSelectSearchCodes.add(code);
287
- });
288
- });
289
- }
290
51
  /**
291
52
  * 生成钱包API默认参数
292
53
  * 根据业务数据生成标准的钱包API参数,并存储在模块中
@@ -314,7 +75,7 @@ var WalletPassPaymentImpl = class {
314
75
  // 订单小计金额
315
76
  order_product_amount: subTotal,
316
77
  // 订单待支付金额
317
- 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),
318
79
  // order_behavior_count_customer_id: 1,
319
80
  products,
320
81
  prepare_payments: [],
@@ -494,96 +255,6 @@ var WalletPassPaymentImpl = class {
494
255
  throw error;
495
256
  }
496
257
  }
497
- /**
498
- * 商品或订单金额变化后,使用聚合接口一次重算已选与剩余 WalletPass。
499
- * Walk-In 不发送 customer_id;会员才携带真实 customer_id。
500
- */
501
- async aggregateRecalculateWalletAssetsAsync(businessData, selectedIds) {
502
- var _a, _b;
503
- const walletParams = this.generateWalletParams(businessData);
504
- const customerId = Number(walletParams.customer_id || 0);
505
- const requestParams = {
506
- ids: selectedIds.map((id) => String(id)),
507
- exact_codes: this.getSearchedWalletAssetCodes(),
508
- order_product_amount: walletParams.order_product_amount,
509
- order_expect_amount: walletParams.order_expect_amount,
510
- order_wait_pay_amount: walletParams.order_wait_pay_amount,
511
- products: walletParams.products,
512
- available: 2,
513
- filter_prepare_wallet_pass: 1,
514
- sale_channel: walletParams.sale_channel || "pos"
515
- };
516
- if (customerId > 1) {
517
- requestParams.customer_id = customerId;
518
- }
519
- const response = await this.paymentModule.request.post(
520
- "/machinecode/prepare/deduction/aggregate-recalculate",
521
- requestParams
522
- );
523
- const responseData = response == null ? void 0 : response.data;
524
- const hasAggregateLists = responseData && (Object.prototype.hasOwnProperty.call(
525
- responseData,
526
- "recalculate_list"
527
- ) || Object.prototype.hasOwnProperty.call(
528
- responseData,
529
- "customer_wallet_pass_list"
530
- ));
531
- if (!hasAggregateLists) {
532
- throw new Error("WalletPass aggregate response is missing list data");
533
- }
534
- const recalculateList = Array.isArray(responseData == null ? void 0 : responseData.recalculate_list) ? responseData.recalculate_list : [];
535
- const customerWalletPassList = Array.isArray(
536
- responseData == null ? void 0 : responseData.customer_wallet_pass_list
537
- ) ? responseData.customer_wallet_pass_list : [];
538
- const allList = mergeWalletAssets(
539
- recalculateList,
540
- customerWalletPassList
541
- );
542
- const walletPassEvaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
543
- const evaluated = (walletPassEvaluator == null ? void 0 : walletPassEvaluator.getRecommendedVouchers) ? walletPassEvaluator.getRecommendedVouchers({
544
- orderTotalAmount: walletParams.order_wait_pay_amount,
545
- products: walletParams.products,
546
- vouchers: allList
547
- }) : {
548
- recommended: [],
549
- transformList: allList.filter(isWalletAssetAvailable),
550
- noApplicableVoucher: allList.filter(
551
- (item) => !isWalletAssetAvailable(item)
552
- )
553
- };
554
- const returnedSelectedKeys = new Set(
555
- recalculateList.filter(isWalletAssetAvailable).map((item) => getWalletAssetKey(item))
556
- );
557
- const authoritativeSelectedIds = selectedIds.filter(
558
- (id) => returnedSelectedKeys.has(String(id))
559
- );
560
- this.walletRecommendList = evaluated.recommended || [];
561
- this.userIdentificationCodes = allList;
562
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
563
- userIdentificationCodes: this.userIdentificationCodes
564
- });
565
- this.walletInitData = {
566
- transformList: evaluated.transformList || [],
567
- noApplicableVoucher: evaluated.noApplicableVoucher || [],
568
- products: walletParams.products || []
569
- };
570
- this.paymentModule.logInfo(
571
- "[WalletPass] 聚合重算 WalletPass 完成",
572
- {
573
- selected_count: recalculateList.length,
574
- remaining_count: customerWalletPassList.length,
575
- searched_codes_count: requestParams.exact_codes.length
576
- }
577
- );
578
- return {
579
- walletRecommendList: this.walletRecommendList,
580
- userIdentificationCodes: this.userIdentificationCodes,
581
- transformList: evaluated.transformList || [],
582
- noApplicableVoucher: evaluated.noApplicableVoucher || [],
583
- products: walletParams.products || [],
584
- authoritativeSelectedIds
585
- };
586
- }
587
258
  async getWalletPassRecommendListAsync(params) {
588
259
  var _a;
589
260
  try {
@@ -685,6 +356,7 @@ var WalletPassPaymentImpl = class {
685
356
  * 特殊逻辑:当识别码长度为9位且前3位为"000"时,调用 /wallet/detail/search 接口
686
357
  */
687
358
  async searchIdentificationCodeAsync(params, config = {}) {
359
+ var _a;
688
360
  try {
689
361
  const { code } = params;
690
362
  this.paymentModule.logInfo("[WalletPass] 开始搜索识别码", {
@@ -722,14 +394,14 @@ var WalletPassPaymentImpl = class {
722
394
  const baseWalletParams = this.walletParams;
723
395
  const searchParams = {
724
396
  // 基础钱包参数
725
- sale_channel: params.sale_channel ?? (baseWalletParams == null ? void 0 : baseWalletParams.sale_channel) ?? "pos",
726
- customer_id: params.customer_id ?? (baseWalletParams == null ? void 0 : baseWalletParams.customer_id),
727
- order_expect_amount: params.order_expect_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_expect_amount),
728
- order_product_amount: params.order_product_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_product_amount),
729
- order_wait_pay_amount: params.order_wait_pay_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_wait_pay_amount),
730
- 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),
731
- products: params.products ?? (baseWalletParams == null ? void 0 : baseWalletParams.products) ?? [],
732
- 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),
733
405
  multiple: 1,
734
406
  // 搜索特有参数
735
407
  code: params.code,
@@ -745,10 +417,17 @@ var WalletPassPaymentImpl = class {
745
417
  if (typeof searchParams.payment_order_id === "string" && searchParams.payment_order_id.startsWith("LOCAL_")) {
746
418
  searchParams.payment_order_id = void 0;
747
419
  }
748
- const response = await this.paymentModule.request.post(
749
- "/machinecode/prepare/deduction/search",
750
- searchParams
751
- );
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
+ }
752
431
  const searchResults = (response == null ? void 0 : response.data) || [];
753
432
  if (config.noCache) {
754
433
  return {
@@ -790,385 +469,6 @@ var WalletPassPaymentImpl = class {
790
469
  throw error;
791
470
  }
792
471
  }
793
- /**
794
- * 刷新购物车与结账共享的钱包资产。
795
- *
796
- * 与 legacy initializeWalletDataFromBusinessAsync 不同,这里维护选择状态;
797
- * 推荐结果只作为可用性/金额计算输入,不会自动成为 selectedIds。
798
- */
799
- async refreshWalletAssetsFromBusinessAsync(businessData, options = {}) {
800
- var _a;
801
- const requestSequence = ++this.walletAssetsRequestSequence;
802
- const nextCustomerId = businessData.customer_id;
803
- const previousCustomerId = this.walletAssetsState.customerId;
804
- const customerChanged = String(previousCustomerId ?? "") !== String(nextCustomerId ?? "");
805
- const preserveSelection = options.preserveSelection !== false && !customerChanged;
806
- if (customerChanged) {
807
- this.clearSearchResults();
808
- }
809
- const committedKeys = new Set(
810
- this.walletAssetsState.committedIds.map((id) => String(id))
811
- );
812
- const committedItems = this.walletAssetsState.items.filter(
813
- (item) => committedKeys.has(getWalletAssetKey(item))
814
- );
815
- const selectedIds = preserveSelection ? [...this.walletAssetsState.selectedIds] : [];
816
- const selectionSources = preserveSelection ? { ...this.walletAssetsState.selectionSources } : {};
817
- const scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter((asset) => {
818
- const assetId = getWalletAssetId(asset);
819
- return assetId !== void 0 && assetId !== null && selectionSources[String(assetId)] === "scan";
820
- }) : [];
821
- if (!((_a = businessData.products) == null ? void 0 : _a.length)) {
822
- this.queuePendingAutoSelectForAssets(scanSelectedAssets);
823
- this.generateWalletParams(businessData);
824
- const restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map((item) => ({
825
- ...item,
826
- actualDeduction: 0,
827
- deductionDetails: [],
828
- _available_max_amount: 0,
829
- _unified_available_status: 0,
830
- _wallet_asset_recommended: false
831
- }));
832
- this.walletRecommendList = [];
833
- this.userIdentificationCodes = [];
834
- this.walletInitData = {
835
- transformList: [],
836
- noApplicableVoucher: restoredSearchedAssets,
837
- products: []
838
- };
839
- this.walletAssetsCalculationContext = {
840
- orderTotalAmount: 0,
841
- products: []
842
- };
843
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
844
- userIdentificationCodes: []
845
- });
846
- return this.publishWalletAssetsState({
847
- status: "ready",
848
- customerId: nextCustomerId,
849
- items: mergeWalletAssets(
850
- restoredSearchedAssets,
851
- committedItems
852
- ),
853
- selectedIds: [],
854
- selectedItems: [],
855
- selectionSources: {},
856
- totalSelectedAmount: 0,
857
- error: null
858
- });
859
- }
860
- this.publishWalletAssetsState({
861
- status: "loading",
862
- customerId: nextCustomerId,
863
- items: preserveSelection ? this.walletAssetsState.items : committedItems,
864
- selectedIds,
865
- selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
866
- selectionSources,
867
- totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
868
- error: null
869
- });
870
- try {
871
- const searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
872
- const useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
873
- const aggregateResult = useAggregateRecalculate ? await this.aggregateRecalculateWalletAssetsAsync(
874
- businessData,
875
- selectedIds
876
- ) : null;
877
- const result = aggregateResult || await this.initializeWalletDataFromBusinessAsync(businessData);
878
- if (requestSequence !== this.walletAssetsRequestSequence) {
879
- return this.getWalletAssetsState();
880
- }
881
- this.walletAssetsCalculationContext = {
882
- orderTotalAmount: Number(businessData.order_wait_pay_amount || 0),
883
- products: result.products || businessData.products || []
884
- };
885
- const authoritativeSelectedIds = (aggregateResult == null ? void 0 : aggregateResult.authoritativeSelectedIds) || selectedIds;
886
- if (aggregateResult) {
887
- const returnedAggregateKeys = new Set(
888
- [
889
- ...result.transformList || [],
890
- ...result.noApplicableVoucher || []
891
- ].map((item) => getWalletAssetKey(item))
892
- );
893
- const missingSelectedKeys = new Set(
894
- selectedIds.map((id) => String(id)).filter((id) => !returnedAggregateKeys.has(id))
895
- );
896
- if (missingSelectedKeys.size > 0) {
897
- this.searchResults = this.searchResults.filter(
898
- (item) => !missingSelectedKeys.has(getWalletAssetKey(item))
899
- );
900
- }
901
- }
902
- const searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([
903
- ...result.transformList || [],
904
- ...result.noApplicableVoucher || []
905
- ]) : [];
906
- if (requestSequence !== this.walletAssetsRequestSequence) {
907
- return this.getWalletAssetsState();
908
- }
909
- const recommendedKeys = new Set(
910
- (result.walletRecommendList || []).map(
911
- (asset) => getWalletAssetKey(asset)
912
- )
913
- );
914
- const items = mergeWalletAssets(
915
- preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [],
916
- searchedWalletAssets,
917
- result.transformList || [],
918
- result.noApplicableVoucher || []
919
- ).map((asset) => ({
920
- ...asset,
921
- _wallet_asset_recommended: recommendedKeys.has(
922
- getWalletAssetKey(asset)
923
- )
924
- }));
925
- const latestSelectedIds = preserveSelection ? authoritativeSelectedIds : [];
926
- const latestSelectionSources = preserveSelection ? { ...this.walletAssetsState.selectionSources } : {};
927
- const pendingAutoSelectAssets = this.walletAssetsBehavior.autoSelectAfterSearch ? items.filter(
928
- (asset) => this.isPendingAutoSelectAsset(asset) && isWalletAssetAvailable(asset)
929
- ) : [];
930
- const requestedKeySet = new Set(
931
- latestSelectedIds.map((id) => String(id))
932
- );
933
- pendingAutoSelectAssets.forEach((asset) => {
934
- const assetId = getWalletAssetId(asset);
935
- if (assetId === void 0 || assetId === null)
936
- return;
937
- const assetKey = String(assetId);
938
- if (!requestedKeySet.has(assetKey)) {
939
- requestedKeySet.add(assetKey);
940
- latestSelectedIds.push(assetId);
941
- }
942
- latestSelectionSources[assetKey] = "scan";
943
- });
944
- const nextState = this.recalculateWalletAssets(
945
- items,
946
- latestSelectedIds,
947
- latestSelectionSources
948
- );
949
- const selectedKeySet = new Set(
950
- nextState.selectedIds.map((id) => String(id))
951
- );
952
- pendingAutoSelectAssets.forEach((asset) => {
953
- const assetId = getWalletAssetId(asset);
954
- if (assetId !== void 0 && assetId !== null && selectedKeySet.has(String(assetId))) {
955
- this.clearPendingAutoSelectForAsset(asset);
956
- }
957
- });
958
- const droppedScanSelectedAssets = scanSelectedAssets.filter((asset) => {
959
- const assetId = getWalletAssetId(asset);
960
- return assetId !== void 0 && assetId !== null && !selectedKeySet.has(String(assetId));
961
- });
962
- this.queuePendingAutoSelectForAssets(droppedScanSelectedAssets);
963
- return nextState;
964
- } catch (error) {
965
- if (requestSequence !== this.walletAssetsRequestSequence) {
966
- return this.getWalletAssetsState();
967
- }
968
- this.paymentModule.logError(
969
- "[WalletPass] 刷新共享钱包资产失败,保留刷新前状态",
970
- error,
971
- {
972
- customer_id: businessData.customer_id,
973
- selected_ids: selectedIds,
974
- searched_codes: this.getSearchedWalletAssetCodes()
975
- }
976
- );
977
- return this.publishWalletAssetsState({
978
- status: "error",
979
- items: preserveSelection ? this.walletAssetsState.items : committedItems,
980
- selectedIds: preserveSelection ? this.walletAssetsState.selectedIds : [],
981
- selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
982
- selectionSources: preserveSelection ? this.walletAssetsState.selectionSources : {},
983
- totalSelectedAmount: preserveSelection ? this.walletAssetsState.totalSelectedAmount : 0,
984
- customerId: nextCustomerId,
985
- error: error instanceof Error ? error.message : String(error)
986
- });
987
- }
988
- }
989
- getWalletAssetsState() {
990
- return {
991
- ...this.walletAssetsState,
992
- items: [...this.walletAssetsState.items],
993
- selectedIds: [...this.walletAssetsState.selectedIds],
994
- selectedItems: [...this.walletAssetsState.selectedItems],
995
- committedIds: [...this.walletAssetsState.committedIds],
996
- selectionSources: { ...this.walletAssetsState.selectionSources }
997
- };
998
- }
999
- exportWalletAssetsSnapshot() {
1000
- return {
1001
- state: this.getWalletAssetsState(),
1002
- searchResults: [...this.searchResults],
1003
- pendingAutoSelectSearchCodes: [
1004
- ...this.pendingAutoSelectSearchCodes
1005
- ],
1006
- walletParams: this.walletParams ? { ...this.walletParams } : null,
1007
- calculationContext: {
1008
- orderTotalAmount: this.walletAssetsCalculationContext.orderTotalAmount,
1009
- products: [...this.walletAssetsCalculationContext.products]
1010
- }
1011
- };
1012
- }
1013
- importWalletAssetsSnapshot(snapshot) {
1014
- var _a, _b;
1015
- if (!(snapshot == null ? void 0 : snapshot.state))
1016
- return this.getWalletAssetsState();
1017
- this.walletAssetsRequestSequence += 1;
1018
- this.searchResults = Array.isArray(snapshot.searchResults) ? [...snapshot.searchResults] : [];
1019
- this.pendingAutoSelectSearchCodes = this.walletAssetsBehavior.autoSelectAfterSearch && Array.isArray(snapshot.pendingAutoSelectSearchCodes) ? new Set(
1020
- snapshot.pendingAutoSelectSearchCodes.map(normalizeWalletAssetCode).filter(Boolean)
1021
- ) : /* @__PURE__ */ new Set();
1022
- this.walletParams = snapshot.walletParams ? { ...snapshot.walletParams } : null;
1023
- this.walletAssetsCalculationContext = {
1024
- orderTotalAmount: Number(
1025
- ((_a = snapshot.calculationContext) == null ? void 0 : _a.orderTotalAmount) || 0
1026
- ),
1027
- products: Array.isArray((_b = snapshot.calculationContext) == null ? void 0 : _b.products) ? [...snapshot.calculationContext.products] : []
1028
- };
1029
- return this.publishWalletAssetsState({
1030
- ...snapshot.state,
1031
- items: Array.isArray(snapshot.state.items) ? snapshot.state.items : [],
1032
- selectedIds: Array.isArray(snapshot.state.selectedIds) ? snapshot.state.selectedIds : [],
1033
- selectedItems: Array.isArray(snapshot.state.selectedItems) ? snapshot.state.selectedItems : [],
1034
- committedIds: Array.isArray(snapshot.state.committedIds) ? snapshot.state.committedIds : [],
1035
- selectionSources: snapshot.state.selectionSources || {}
1036
- });
1037
- }
1038
- selectWalletAsset(assetId, options) {
1039
- const assetKey = String(assetId);
1040
- const asset = this.walletAssetsState.items.find(
1041
- (item) => getWalletAssetKey(item) === assetKey
1042
- );
1043
- const committedKeys = new Set(
1044
- this.walletAssetsState.committedIds.map((id) => String(id))
1045
- );
1046
- if (committedKeys.has(assetKey))
1047
- return this.getWalletAssetsState();
1048
- const selectedIds = this.walletAssetsState.selectedIds.filter(
1049
- (id) => String(id) !== assetKey
1050
- );
1051
- const selectionSources = { ...this.walletAssetsState.selectionSources };
1052
- delete selectionSources[assetKey];
1053
- if (options.selected) {
1054
- if (!asset || !isWalletAssetAvailable(asset)) {
1055
- return this.getWalletAssetsState();
1056
- }
1057
- selectedIds.push(assetId);
1058
- selectionSources[assetKey] = options.source || "manual";
1059
- } else if (asset) {
1060
- this.clearPendingAutoSelectForAsset(asset);
1061
- }
1062
- const nextState = this.recalculateWalletAssets(
1063
- this.walletAssetsState.items,
1064
- selectedIds,
1065
- selectionSources
1066
- );
1067
- if (options.selected && asset && nextState.selectedIds.some((id) => String(id) === assetKey)) {
1068
- this.clearPendingAutoSelectForAsset(asset);
1069
- }
1070
- return nextState;
1071
- }
1072
- async scanWalletAssetAsync(code) {
1073
- const normalizedCode = String(code || "").trim();
1074
- if (!normalizedCode) {
1075
- return {
1076
- type: "normalCode",
1077
- selected: false,
1078
- state: this.getWalletAssetsState()
1079
- };
1080
- }
1081
- const selectedAsset = this.walletAssetsState.selectedItems.find(
1082
- (asset2) => matchesWalletAssetCode(asset2, normalizedCode)
1083
- );
1084
- if (selectedAsset) {
1085
- return {
1086
- type: "normalCode",
1087
- asset: selectedAsset,
1088
- selected: true,
1089
- state: this.getWalletAssetsState()
1090
- };
1091
- }
1092
- this.walletAssetsRequestSequence += 1;
1093
- const result = await this.searchIdentificationCodeAsync({
1094
- ...this.walletParams || {},
1095
- code: normalizedCode,
1096
- prepare_payments: this.formatWalletPassList2PreparePayments(
1097
- this.walletAssetsState.selectedItems
1098
- )
1099
- });
1100
- const paymentAssets = result.data.filter(isWalletPaymentAsset);
1101
- const asset = paymentAssets.find(
1102
- (item) => String((item == null ? void 0 : item.code) || "") === normalizedCode
1103
- ) || paymentAssets[0];
1104
- if (!asset || result.type === "walletCode") {
1105
- return {
1106
- type: result.type,
1107
- asset,
1108
- selected: false,
1109
- state: this.getWalletAssetsState()
1110
- };
1111
- }
1112
- const items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1113
- const recalculatedState = this.recalculateWalletAssets(
1114
- items,
1115
- this.walletAssetsState.selectedIds,
1116
- this.walletAssetsState.selectionSources
1117
- );
1118
- const assetId = getWalletAssetId(asset);
1119
- const selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== void 0 && isWalletAssetAvailable(asset) ? this.selectWalletAsset(assetId, {
1120
- selected: true,
1121
- source: "scan"
1122
- }) : recalculatedState;
1123
- const isSelected = assetId !== void 0 && selected.selectedIds.some((id) => String(id) === String(assetId));
1124
- if (isSelected) {
1125
- this.clearPendingAutoSelectForAsset(asset);
1126
- } else if (this.walletAssetsBehavior.autoSelectAfterSearch) {
1127
- this.pendingAutoSelectSearchCodes.add(
1128
- normalizeWalletAssetCode(normalizedCode)
1129
- );
1130
- this.queuePendingAutoSelectForAssets([asset]);
1131
- }
1132
- return {
1133
- type: result.type,
1134
- asset,
1135
- selected: isSelected,
1136
- state: selected
1137
- };
1138
- }
1139
- clearWalletAssetSelection() {
1140
- this.pendingAutoSelectSearchCodes.clear();
1141
- return this.recalculateWalletAssets(
1142
- this.walletAssetsState.items,
1143
- [],
1144
- {}
1145
- );
1146
- }
1147
- setCommittedWalletAssets(committedIds, committedAssets = []) {
1148
- const committedKeys = new Set(committedIds.map((id) => String(id)));
1149
- const selectedIds = this.walletAssetsState.selectedIds.filter(
1150
- (id) => !committedKeys.has(String(id))
1151
- );
1152
- const selectionSources = Object.entries(
1153
- this.walletAssetsState.selectionSources
1154
- ).reduce(
1155
- (result, [key, source]) => {
1156
- if (!committedKeys.has(key))
1157
- result[key] = source;
1158
- return result;
1159
- },
1160
- {}
1161
- );
1162
- this.publishWalletAssetsState({
1163
- items: mergeWalletAssets(this.walletAssetsState.items, committedAssets),
1164
- committedIds
1165
- });
1166
- return this.recalculateWalletAssets(
1167
- this.walletAssetsState.items,
1168
- selectedIds,
1169
- selectionSources
1170
- );
1171
- }
1172
472
  async processWalletPayment(amount, orderUuid, voucherId) {
1173
473
  this.paymentModule.logInfo("[WalletPass] 开始处理钱包支付", {
1174
474
  amount,
@@ -1252,7 +552,6 @@ var WalletPassPaymentImpl = class {
1252
552
  */
1253
553
  clearSearchResults() {
1254
554
  this.searchResults = [];
1255
- this.pendingAutoSelectSearchCodes.clear();
1256
555
  this.paymentModule.logInfo("[WalletPass] 搜索结果缓存已清除");
1257
556
  }
1258
557
  /**
@@ -1275,16 +574,8 @@ var WalletPassPaymentImpl = class {
1275
574
  this.walletRecommendList = [];
1276
575
  this.userIdentificationCodes = [];
1277
576
  this.searchResults = [];
1278
- this.pendingAutoSelectSearchCodes.clear();
1279
577
  this.walletParams = null;
1280
578
  this.walletInitData = null;
1281
- this.walletAssetsRequestSequence += 1;
1282
- this.walletAssetsCalculationContext = {
1283
- orderTotalAmount: 0,
1284
- products: []
1285
- };
1286
- this.walletAssetsState = createInitialWalletAssetsState();
1287
- this.publishWalletAssetsState({});
1288
579
  this.emitEvent(import_types.WalletPassHooks.OnWalletCacheCleared, {
1289
580
  clearedTypes: ["all"]
1290
581
  });