@pisell/pisellos 2.3.74 → 2.3.76

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 (283) hide show
  1. package/dist/core/index.js +6 -10
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/model/strategy/adapter/walletPass/example.js +3 -26
  4. package/dist/model/strategy/strategy-example.js +5 -19
  5. package/dist/modules/Cart/index.js +0 -3
  6. package/dist/modules/Cart/utils/cartProduct.js +0 -1
  7. package/dist/modules/Date/index.js +1 -5
  8. package/dist/modules/Discount/index.js +2 -4
  9. package/dist/modules/OpenData/index.js +0 -2
  10. package/dist/modules/Order/index.d.ts +1 -1
  11. package/dist/modules/Order/index.js +75 -91
  12. package/dist/modules/Order/types.d.ts +3 -1
  13. package/dist/modules/Payment/index.js +97 -162
  14. package/dist/modules/Rules/index.js +1 -4
  15. package/dist/modules/Schedule/index.js +0 -1
  16. package/dist/modules/Schedule/utils.js +0 -1
  17. package/dist/modules/Step/index.js +0 -1
  18. package/dist/plugins/request.js +1 -4
  19. package/dist/plugins/window.js +2 -6
  20. package/dist/server/index.js +97 -129
  21. package/dist/server/modules/menu/index.js +32 -41
  22. package/dist/server/modules/order/index.js +2 -4
  23. package/dist/server/modules/products/index.js +24 -42
  24. package/dist/server/modules/quotation/index.js +29 -38
  25. package/dist/server/modules/resource/index.js +3 -4
  26. package/dist/server/modules/schedule/index.js +27 -35
  27. package/dist/server/utils/product.js +0 -1
  28. package/dist/solution/BaseSales/index.js +100 -72
  29. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +15 -6
  31. package/dist/solution/BookingByStep/index.js +7 -59
  32. package/dist/solution/BookingByStep/utils/capacity.js +1 -11
  33. package/dist/solution/BookingByStep/utils/resources.js +1 -3
  34. package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
  35. package/dist/solution/BookingTicket/index.js +0 -2
  36. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
  37. package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
  38. package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
  39. package/dist/solution/BuyTickets/index.js +9 -12
  40. package/dist/solution/Checkout/index.js +177 -252
  41. package/dist/solution/Checkout/utils/index.js +4 -16
  42. package/dist/solution/RegisterAndLogin/index.js +30 -76
  43. package/dist/solution/ScanOrder/index.js +50 -60
  44. package/dist/solution/ShopDiscount/index.js +2 -7
  45. package/dist/solution/VenueBooking/index.js +45 -55
  46. package/dist/utils/task.js +15 -18
  47. package/dist/utils/watch.js +0 -1
  48. package/lib/apis/picoding.js +2 -0
  49. package/lib/core/index.js +134 -134
  50. package/lib/effects/index.js +46 -57
  51. package/lib/index.js +82 -49
  52. package/lib/model/index.js +14 -21
  53. package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
  54. package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
  55. package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
  56. package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
  57. package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
  58. package/lib/model/strategy/adapter/index.js +100 -64
  59. package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
  60. package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
  61. package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
  62. package/lib/model/strategy/adapter/itemRule/index.js +83 -57
  63. package/lib/model/strategy/adapter/itemRule/type.js +97 -36
  64. package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
  65. package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
  66. package/lib/model/strategy/adapter/promotion/examples.js +222 -234
  67. package/lib/model/strategy/adapter/promotion/index.js +1 -0
  68. package/lib/model/strategy/adapter/promotion/type.js +243 -36
  69. package/lib/model/strategy/adapter/type.js +4 -16
  70. package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
  71. package/lib/model/strategy/adapter/walletPass/example.js +217 -190
  72. package/lib/model/strategy/adapter/walletPass/index.js +75 -51
  73. package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
  74. package/lib/model/strategy/adapter/walletPass/type.js +4 -16
  75. package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
  76. package/lib/model/strategy/engine.js +270 -168
  77. package/lib/model/strategy/index.js +49 -34
  78. package/lib/model/strategy/strategy-example.js +243 -239
  79. package/lib/model/strategy/type.js +100 -40
  80. package/lib/modules/Account/index.js +39 -53
  81. package/lib/modules/Account/types.js +20 -33
  82. package/lib/modules/AccountList/index.js +116 -154
  83. package/lib/modules/AccountList/types.js +30 -31
  84. package/lib/modules/AccountList/utils.js +18 -30
  85. package/lib/modules/BaseModule.js +23 -42
  86. package/lib/modules/BookingContext/index.js +158 -136
  87. package/lib/modules/BookingContext/types.js +46 -32
  88. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
  89. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
  90. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
  91. package/lib/modules/BookingContext/utils/flexible.js +38 -55
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
  93. package/lib/modules/BookingContext/utils/index.js +124 -41
  94. package/lib/modules/BookingContext/utils/noResource.js +58 -70
  95. package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
  96. package/lib/modules/BookingContext/utils/productExtend.js +202 -155
  97. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  98. package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
  99. package/lib/modules/BookingContext/utils/resources.js +209 -167
  100. package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
  101. package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
  102. package/lib/modules/Cart/index.js +170 -124
  103. package/lib/modules/Cart/types.js +46 -51
  104. package/lib/modules/Cart/utils/cartAccount.js +40 -39
  105. package/lib/modules/Cart/utils/cartDate.js +56 -61
  106. package/lib/modules/Cart/utils/cartDiscount.js +28 -33
  107. package/lib/modules/Cart/utils/cartNote.js +27 -32
  108. package/lib/modules/Cart/utils/cartProduct.js +321 -251
  109. package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
  110. package/lib/modules/Cart/utils/cartResource.js +70 -78
  111. package/lib/modules/Cart/utils/changePrice.js +22 -50
  112. package/lib/modules/Cart/utils/index.js +106 -48
  113. package/lib/modules/Customer/constants.js +13 -34
  114. package/lib/modules/Customer/index.js +235 -172
  115. package/lib/modules/Customer/types.js +38 -35
  116. package/lib/modules/Date/index.js +116 -115
  117. package/lib/modules/Date/types.js +16 -28
  118. package/lib/modules/Date/utils.js +174 -123
  119. package/lib/modules/Discount/index.js +122 -127
  120. package/lib/modules/Discount/types.js +9 -31
  121. package/lib/modules/Guests/index.js +30 -56
  122. package/lib/modules/Guests/types.js +23 -33
  123. package/lib/modules/Holder/index.js +209 -189
  124. package/lib/modules/Holder/types.js +4 -16
  125. package/lib/modules/Holder/utils.js +20 -49
  126. package/lib/modules/OpenData/index.js +70 -76
  127. package/lib/modules/OpenData/types.js +4 -16
  128. package/lib/modules/OpenData/utils.js +44 -78
  129. package/lib/modules/Order/index.d.ts +1 -1
  130. package/lib/modules/Order/index.js +1733 -2121
  131. package/lib/modules/Order/payment-utils.js +77 -120
  132. package/lib/modules/Order/types.d.ts +3 -1
  133. package/lib/modules/Order/types.js +88 -35
  134. package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
  135. package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
  136. package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
  137. package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
  138. package/lib/modules/Order/utils.js +814 -647
  139. package/lib/modules/Payment/cash.js +20 -33
  140. package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
  141. package/lib/modules/Payment/eftpos.js +16 -30
  142. package/lib/modules/Payment/index.js +532 -399
  143. package/lib/modules/Payment/mx51.js +1 -0
  144. package/lib/modules/Payment/types.js +230 -108
  145. package/lib/modules/Payment/utils.js +52 -51
  146. package/lib/modules/Payment/walletpass.js +485 -660
  147. package/lib/modules/Product/index.js +51 -46
  148. package/lib/modules/Product/types.js +4 -16
  149. package/lib/modules/Product/utils.js +32 -33
  150. package/lib/modules/ProductList/index.js +113 -123
  151. package/lib/modules/ProductList/types.js +9 -31
  152. package/lib/modules/Quotation/index.js +81 -118
  153. package/lib/modules/Quotation/types.js +4 -16
  154. package/lib/modules/Resource/index.js +27 -59
  155. package/lib/modules/Resource/types.js +22 -32
  156. package/lib/modules/Resource/utils.js +30 -38
  157. package/lib/modules/ResourcePlanner/index.js +25 -23
  158. package/lib/modules/ResourcePlanner/localClock.js +54 -119
  159. package/lib/modules/ResourcePlanner/planner.js +589 -770
  160. package/lib/modules/ResourcePlanner/types.js +10 -29
  161. package/lib/modules/Rules/index.js +1218 -959
  162. package/lib/modules/Rules/types.js +17 -40
  163. package/lib/modules/SalesSummary/index.js +85 -90
  164. package/lib/modules/SalesSummary/types.js +4 -16
  165. package/lib/modules/SalesSummary/utils.js +355 -430
  166. package/lib/modules/ScanOrderLogger/index.js +59 -79
  167. package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
  168. package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
  169. package/lib/modules/ScanOrderLogger/types.js +4 -16
  170. package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
  171. package/lib/modules/Schedule/index.js +100 -114
  172. package/lib/modules/Schedule/type.js +4 -16
  173. package/lib/modules/Schedule/types.js +4 -16
  174. package/lib/modules/Schedule/utils.js +433 -291
  175. package/lib/modules/Step/index.js +40 -52
  176. package/lib/modules/Step/tyeps.js +4 -16
  177. package/lib/modules/Summary/index.js +66 -71
  178. package/lib/modules/Summary/types.js +4 -16
  179. package/lib/modules/Summary/utils.js +773 -418
  180. package/lib/modules/SurchargeList/index.js +46 -60
  181. package/lib/modules/SurchargeList/types.js +4 -16
  182. package/lib/modules/index.js +245 -63
  183. package/lib/plugins/app.js +4 -16
  184. package/lib/plugins/index.js +36 -25
  185. package/lib/plugins/request.js +137 -126
  186. package/lib/plugins/shopStore.js +4 -16
  187. package/lib/plugins/user.js +4 -16
  188. package/lib/plugins/window.js +171 -179
  189. package/lib/server/index.js +3050 -2665
  190. package/lib/server/modules/floor-plan/index.js +118 -134
  191. package/lib/server/modules/floor-plan/types.js +15 -30
  192. package/lib/server/modules/index.js +106 -68
  193. package/lib/server/modules/menu/index.js +142 -122
  194. package/lib/server/modules/menu/types.js +18 -31
  195. package/lib/server/modules/order/index.js +784 -1002
  196. package/lib/server/modules/order/types.js +122 -33
  197. package/lib/server/modules/order/utils/filterBookings.js +219 -194
  198. package/lib/server/modules/order/utils/filterOrders.js +118 -92
  199. package/lib/server/modules/payment/index.js +59 -83
  200. package/lib/server/modules/payment/types.js +4 -16
  201. package/lib/server/modules/products/index.js +583 -471
  202. package/lib/server/modules/products/types.js +44 -34
  203. package/lib/server/modules/quotation/index.js +137 -172
  204. package/lib/server/modules/quotation/types.js +21 -31
  205. package/lib/server/modules/resource/index.js +220 -186
  206. package/lib/server/modules/resource/types.js +42 -33
  207. package/lib/server/modules/schedule/index.js +135 -123
  208. package/lib/server/modules/schedule/types.js +14 -21
  209. package/lib/server/modules/schedule/utils.js +334 -163
  210. package/lib/server/types.js +4 -16
  211. package/lib/server/utils/index.js +25 -23
  212. package/lib/server/utils/product.js +196 -139
  213. package/lib/server/utils/schedule.js +34 -41
  214. package/lib/server/utils/small-ticket.js +479 -456
  215. package/lib/server/utils/time.js +40 -49
  216. package/lib/solution/BaseSales/index.js +1220 -1412
  217. package/lib/solution/BaseSales/types.js +42 -38
  218. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +5 -0
  219. package/lib/solution/BaseSales/utils/cartPromotion.js +652 -498
  220. package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
  221. package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
  222. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
  223. package/lib/solution/BaseSales/utils.js +158 -143
  224. package/lib/solution/BookingByStep/index.js +1527 -1340
  225. package/lib/solution/BookingByStep/types.js +40 -99
  226. package/lib/solution/BookingByStep/utils/capacity.js +192 -160
  227. package/lib/solution/BookingByStep/utils/products.js +42 -52
  228. package/lib/solution/BookingByStep/utils/resources.js +527 -330
  229. package/lib/solution/BookingByStep/utils/stock.js +65 -44
  230. package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
  231. package/lib/solution/BookingTicket/index.js +607 -522
  232. package/lib/solution/BookingTicket/types.js +99 -77
  233. package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
  234. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
  235. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
  236. package/lib/solution/BookingTicket/utils/cartView.js +114 -99
  237. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  238. package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
  239. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
  240. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
  241. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
  242. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
  243. package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
  244. package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
  245. package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
  246. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
  247. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
  248. package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
  249. package/lib/solution/BuyTickets/index.js +67 -70
  250. package/lib/solution/BuyTickets/types.js +22 -38
  251. package/lib/solution/Checkout/index.js +1451 -1158
  252. package/lib/solution/Checkout/types.js +91 -61
  253. package/lib/solution/Checkout/utils/index.js +228 -156
  254. package/lib/solution/PlaceOrder/index.js +55 -0
  255. package/lib/solution/RegisterAndLogin/config.js +493 -460
  256. package/lib/solution/RegisterAndLogin/index.js +633 -630
  257. package/lib/solution/RegisterAndLogin/types.js +189 -76
  258. package/lib/solution/RegisterAndLogin/utils.js +183 -125
  259. package/lib/solution/Sales/index.js +328 -324
  260. package/lib/solution/Sales/types.js +27 -33
  261. package/lib/solution/ScanOrder/index.js +832 -864
  262. package/lib/solution/ScanOrder/types.js +33 -34
  263. package/lib/solution/ScanOrder/utils.js +409 -374
  264. package/lib/solution/ShopDiscount/index.js +226 -232
  265. package/lib/solution/ShopDiscount/types.js +15 -37
  266. package/lib/solution/ShopDiscount/utils.js +300 -172
  267. package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
  268. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
  269. package/lib/solution/UnifiedBookingSales/types.js +10 -32
  270. package/lib/solution/VenueBooking/index.js +811 -879
  271. package/lib/solution/VenueBooking/types.js +19 -39
  272. package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
  273. package/lib/solution/VenueBooking/utils/resource.js +31 -54
  274. package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
  275. package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
  276. package/lib/solution/VenueBooking/utils.js +130 -67
  277. package/lib/solution/index.js +124 -41
  278. package/lib/store/createStore.js +32 -29
  279. package/lib/types/index.js +4 -16
  280. package/lib/utils/payment-number.js +26 -46
  281. package/lib/utils/task.js +36 -36
  282. package/lib/utils/watch.js +81 -47
  283. package/package.json +2 -1
@@ -1,68 +1,47 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";
18
2
 
19
- // src/modules/Payment/walletpass.ts
20
- var walletpass_exports = {};
21
- __export(walletpass_exports, {
22
- WalletPassPaymentImpl: () => WalletPassPaymentImpl
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
23
5
  });
24
- module.exports = __toCommonJS(walletpass_exports);
25
- var import_types = require("./types");
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
- ]);
6
+ exports.WalletPassPaymentImpl = void 0;
7
+ var _types = require("./types");
8
+ var _utils = require("./utils");
9
+ const WALLET_PAYMENT_ASSET_TAGS = new Set(['product_voucher', 'gift_card', 'point_card']);
32
10
  function isWalletPaymentAsset(asset) {
33
- return WALLET_PAYMENT_ASSET_TAGS.has(
34
- String((asset == null ? void 0 : asset.tag) || "").toLowerCase()
35
- );
11
+ return WALLET_PAYMENT_ASSET_TAGS.has(String(asset?.tag || '').toLowerCase());
36
12
  }
37
13
  function getWalletAssetId(asset) {
38
- return (asset == null ? void 0 : asset.id) ?? (asset == null ? void 0 : asset.voucher_id) ?? (asset == null ? void 0 : asset.code);
14
+ return asset?.id ?? asset?.voucher_id ?? asset?.code;
39
15
  }
40
16
  function getWalletAssetKey(assetOrId) {
41
- const id = assetOrId && typeof assetOrId === "object" ? getWalletAssetId(assetOrId) : assetOrId;
42
- return id === void 0 || id === null ? "" : String(id);
17
+ const id = assetOrId && typeof assetOrId === 'object' ? getWalletAssetId(assetOrId) : assetOrId;
18
+ return id === undefined || id === null ? '' : String(id);
43
19
  }
44
20
  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
- );
21
+ return [asset?.code, asset?.encoded].some(identifier => String(identifier ?? '').trim() === normalizedCode);
48
22
  }
49
23
  function normalizeWalletAssetCode(code) {
50
- return String(code ?? "").trim().toUpperCase();
24
+ return String(code ?? '').trim().toUpperCase();
51
25
  }
52
26
  function getWalletAssetCodeKeys(asset) {
53
- return [asset == null ? void 0 : asset.code, asset == null ? void 0 : asset.encoded].map(normalizeWalletAssetCode).filter(Boolean);
27
+ return [asset?.code, asset?.encoded].map(normalizeWalletAssetCode).filter(Boolean);
54
28
  }
29
+
30
+ /**
31
+ * 保存货币类扫码资产自身的可用余额,供后续前端策略重新计算。
32
+ * 搜索接口的 recommended_usage_amount 已扣除了搜索时的已选券,不能作为
33
+ * 取消勾选后的永久上限。积分卡的 balance_par_value 是积分值,不能直接
34
+ * 当作货币金额,因此继续沿用接口推荐金额。
35
+ */
55
36
  function withWalletAssetRecalculationBaseAmount(asset) {
56
- const existingBaseAmount = Number(
57
- asset == null ? void 0 : asset._wallet_asset_recalculation_base_amount
58
- );
37
+ const existingBaseAmount = Number(asset?._wallet_asset_recalculation_base_amount);
59
38
  if (Number.isFinite(existingBaseAmount) && existingBaseAmount >= 0) {
60
39
  return asset;
61
40
  }
62
- if (!["product_voucher", "gift_card"].includes(asset == null ? void 0 : asset.tag)) {
41
+ if (!['product_voucher', 'gift_card'].includes(asset?.tag)) {
63
42
  return asset;
64
43
  }
65
- const balanceParValue = Number(asset == null ? void 0 : asset.balance_par_value);
44
+ const balanceParValue = Number(asset?.balance_par_value);
66
45
  if (!Number.isFinite(balanceParValue) || balanceParValue < 0) {
67
46
  return asset;
68
47
  }
@@ -72,32 +51,29 @@ function withWalletAssetRecalculationBaseAmount(asset) {
72
51
  };
73
52
  }
74
53
  function isWalletAssetAvailable(asset) {
75
- if (!asset)
76
- return false;
77
- if (asset.unified_available_status !== void 0 && Number(asset.unified_available_status) !== 1) {
54
+ if (!asset) return false;
55
+ if (asset.unified_available_status !== undefined && Number(asset.unified_available_status) !== 1) {
78
56
  return false;
79
57
  }
80
- if (asset._unified_available_status !== void 0 && Number(asset._unified_available_status) !== 1) {
58
+ if (asset._unified_available_status !== undefined && Number(asset._unified_available_status) !== 1) {
81
59
  return false;
82
60
  }
83
- if (asset.available === false || asset.isDisabled === true)
84
- return false;
61
+ if (asset.available === false || asset.isDisabled === true) return false;
85
62
  return true;
86
63
  }
87
64
  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;
65
+ const value = asset?.actualDeduction ?? asset?._available_max_amount ?? asset?.edit_current_amount ?? asset?.recommended_usage_amount ?? asset?.available_max_amount ?? asset?.amount ?? 0;
89
66
  const amount = Number(value);
90
67
  return Number.isFinite(amount) && amount > 0 ? amount : 0;
91
68
  }
92
69
  function mergeWalletAssets(...groups) {
93
70
  const merged = [];
94
- const indexByKey = /* @__PURE__ */ new Map();
95
- groups.flat().forEach((asset) => {
71
+ const indexByKey = new Map();
72
+ groups.flat().forEach(asset => {
96
73
  const key = getWalletAssetKey(asset);
97
- if (!key)
98
- return;
74
+ if (!key) return;
99
75
  const existedIndex = indexByKey.get(key);
100
- if (existedIndex === void 0) {
76
+ if (existedIndex === undefined) {
101
77
  indexByKey.set(key, merged.length);
102
78
  merged.push(asset);
103
79
  return;
@@ -109,19 +85,19 @@ function mergeWalletAssets(...groups) {
109
85
  });
110
86
  return merged;
111
87
  }
88
+
89
+ /**
90
+ * 聚合接口不保证 recalculate_list 顺序;派生抵扣额依赖选择顺序,
91
+ * 因此已选资产必须先恢复为 selectedIds 的顺序再进入策略计算。
92
+ */
112
93
  function orderWalletAssetsByIds(assets, orderedIds) {
113
- const assetByKey = new Map(
114
- assets.map((asset) => [getWalletAssetKey(asset), asset])
115
- );
116
- const orderedKeys = new Set(orderedIds.map((id) => String(id)));
117
- return [
118
- ...orderedIds.map((id) => assetByKey.get(String(id))).filter((asset) => asset !== void 0),
119
- ...assets.filter((asset) => !orderedKeys.has(getWalletAssetKey(asset)))
120
- ];
94
+ const assetByKey = new Map(assets.map(asset => [getWalletAssetKey(asset), asset]));
95
+ const orderedKeys = new Set(orderedIds.map(id => String(id)));
96
+ return [...orderedIds.map(id => assetByKey.get(String(id))).filter(asset => asset !== undefined), ...assets.filter(asset => !orderedKeys.has(getWalletAssetKey(asset)))];
121
97
  }
122
98
  function createInitialWalletAssetsState() {
123
99
  return {
124
- status: "idle",
100
+ status: 'idle',
125
101
  items: [],
126
102
  selectedIds: [],
127
103
  selectedItems: [],
@@ -132,45 +108,50 @@ function createInitialWalletAssetsState() {
132
108
  revision: 0
133
109
  };
134
110
  }
135
- var WalletPassPaymentImpl = class {
111
+
112
+ /**
113
+ * 钱包支付实现
114
+ */
115
+ class WalletPassPaymentImpl {
116
+ walletRecommendList = [];
117
+ userIdentificationCodes = [];
118
+ searchResults = [];
119
+ walletParams = null;
120
+ walletInitData = null;
121
+ walletAssetsState = createInitialWalletAssetsState();
122
+ walletAssetsRequestSequence = 0;
123
+ walletAssetsBehavior = {
124
+ autoSelectAfterSearch: true
125
+ };
126
+ pendingAutoSelectSearchCodes = new Set();
127
+ walletAssetsCalculationContext = {
128
+ orderTotalAmount: 0,
129
+ products: []
130
+ };
136
131
  constructor(paymentModule) {
137
132
  this.paymentModule = paymentModule;
138
- this.walletRecommendList = [];
139
- this.userIdentificationCodes = [];
140
- this.searchResults = [];
141
- this.walletParams = null;
142
- this.walletInitData = null;
143
- this.walletAssetsState = createInitialWalletAssetsState();
144
- this.walletAssetsRequestSequence = 0;
145
- this.walletAssetsBehavior = {
146
- autoSelectAfterSearch: true
147
- };
148
- this.pendingAutoSelectSearchCodes = /* @__PURE__ */ new Set();
149
- this.walletAssetsCalculationContext = {
150
- orderTotalAmount: 0,
151
- products: []
152
- };
153
133
  }
154
134
  configureWalletAssetsBehavior(options) {
155
- if (options.autoSelectAfterSearch === void 0)
156
- return;
135
+ if (options.autoSelectAfterSearch === undefined) return;
157
136
  this.walletAssetsBehavior.autoSelectAfterSearch = options.autoSelectAfterSearch;
158
137
  if (!options.autoSelectAfterSearch) {
159
138
  this.pendingAutoSelectSearchCodes.clear();
160
139
  }
161
140
  }
141
+
162
142
  /**
163
143
  * 发送事件的辅助方法
164
144
  * 支持使用WalletPassHooks或PaymentHooks
165
145
  */
166
146
  emitEvent(hook, data) {
167
147
  try {
168
- const eventName = hook.split(":")[1] || hook.replace(/^[A-Z][a-z]+/, "").replace(/^On/, "").toLowerCase();
148
+ // 提取事件名称,去掉模块前缀
149
+ const eventName = hook.split(':')[1] || hook.replace(/^[A-Z][a-z]+/, '').replace(/^On/, '').toLowerCase();
169
150
  const fullEventName = `${this.paymentModule.name}:${eventName}`;
170
151
  this.paymentModule.core.effects.emit(fullEventName, data);
171
152
  } catch (error) {
172
- this.paymentModule.logError("[WalletPass] 发送事件失败", error, {
173
- hook
153
+ this.paymentModule.logError('[WalletPass] 发送事件失败', error, {
154
+ hook: hook
174
155
  });
175
156
  }
176
157
  }
@@ -178,71 +159,48 @@ var WalletPassPaymentImpl = class {
178
159
  this.walletAssetsState = {
179
160
  ...this.walletAssetsState,
180
161
  ...patch,
181
- items: [...patch.items ?? this.walletAssetsState.items],
182
- selectedIds: [
183
- ...patch.selectedIds ?? this.walletAssetsState.selectedIds
184
- ],
185
- selectedItems: [
186
- ...patch.selectedItems ?? this.walletAssetsState.selectedItems
187
- ],
188
- committedIds: [
189
- ...patch.committedIds ?? this.walletAssetsState.committedIds
190
- ],
162
+ items: [...(patch.items ?? this.walletAssetsState.items)],
163
+ selectedIds: [...(patch.selectedIds ?? this.walletAssetsState.selectedIds)],
164
+ selectedItems: [...(patch.selectedItems ?? this.walletAssetsState.selectedItems)],
165
+ committedIds: [...(patch.committedIds ?? this.walletAssetsState.committedIds)],
191
166
  selectionSources: {
192
- ...patch.selectionSources ?? this.walletAssetsState.selectionSources
167
+ ...(patch.selectionSources ?? this.walletAssetsState.selectionSources)
193
168
  },
194
169
  revision: this.walletAssetsState.revision + 1
195
170
  };
196
171
  const state = this.getWalletAssetsState();
197
- this.emitEvent(import_types.WalletPassHooks.OnWalletAssetsStateChanged, { state });
172
+ this.emitEvent(_types.WalletPassHooks.OnWalletAssetsStateChanged, {
173
+ state
174
+ });
198
175
  return state;
199
176
  }
200
177
  recalculateWalletAssets(items, requestedIds, selectionSources) {
201
- var _a, _b;
202
- const committedKeys = new Set(
203
- this.walletAssetsState.committedIds.map((id) => String(id))
204
- );
205
- const itemsByKey = new Map(
206
- items.map((item) => [getWalletAssetKey(item), item])
207
- );
208
- const requested = requestedIds.map((id) => String(id)).filter((id) => !committedKeys.has(id)).map((id) => itemsByKey.get(id)).filter((item) => item && isWalletAssetAvailable(item));
178
+ const committedKeys = new Set(this.walletAssetsState.committedIds.map(id => String(id)));
179
+ const itemsByKey = new Map(items.map(item => [getWalletAssetKey(item), item]));
180
+ const requested = requestedIds.map(id => String(id)).filter(id => !committedKeys.has(id)).map(id => itemsByKey.get(id)).filter(item => item && isWalletAssetAvailable(item));
209
181
  let nextItems = items;
210
182
  let selectedItems = requested;
211
- const evaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
212
- if (evaluator == null ? void 0 : evaluator.recalculateVouchers) {
183
+ const evaluator = this.paymentModule.window?.getWalletPassEvaluator?.();
184
+ if (evaluator?.recalculateVouchers) {
213
185
  try {
214
- const result = evaluator.recalculateVouchers(
215
- items,
216
- requested,
217
- this.walletAssetsCalculationContext.orderTotalAmount,
218
- this.walletAssetsCalculationContext.products
219
- );
220
- nextItems = mergeWalletAssets(items, (result == null ? void 0 : result.allWithUpdatedStatus) || []);
221
- selectedItems = ((result == null ? void 0 : result.selectedWithDetails) || []).filter(
222
- (item) => isWalletAssetAvailable(item) && getWalletAssetDeductionAmount(item) > 0
223
- );
186
+ const result = evaluator.recalculateVouchers(items, requested, this.walletAssetsCalculationContext.orderTotalAmount, this.walletAssetsCalculationContext.products);
187
+ nextItems = mergeWalletAssets(items, result?.allWithUpdatedStatus || []);
188
+ selectedItems = (result?.selectedWithDetails || []).filter(item => isWalletAssetAvailable(item) && getWalletAssetDeductionAmount(item) > 0);
224
189
  } catch (error) {
225
- this.paymentModule.logWarning(
226
- "[WalletPass] 共享钱包资产重新计算失败,回退接口可用状态",
227
- {
228
- error: error instanceof Error ? error.message : String(error)
229
- }
230
- );
190
+ this.paymentModule.logWarning('[WalletPass] 共享钱包资产重新计算失败,回退接口可用状态', {
191
+ error: error instanceof Error ? error.message : String(error)
192
+ });
231
193
  }
232
194
  }
233
- const selectedIds = selectedItems.map((item) => getWalletAssetId(item)).filter((id) => id !== void 0 && id !== null);
234
- const selectedKeys = new Set(selectedIds.map((id) => String(id)));
195
+ const selectedIds = selectedItems.map(item => getWalletAssetId(item)).filter(id => id !== undefined && id !== null);
196
+ const selectedKeys = new Set(selectedIds.map(id => String(id)));
235
197
  const nextSources = Object.entries(selectionSources).reduce((result, [key, source]) => {
236
- if (selectedKeys.has(key))
237
- result[key] = source;
198
+ if (selectedKeys.has(key)) result[key] = source;
238
199
  return result;
239
200
  }, {});
240
- const totalSelectedAmount = selectedItems.reduce(
241
- (total, item) => total + getWalletAssetDeductionAmount(item),
242
- 0
243
- );
201
+ const totalSelectedAmount = selectedItems.reduce((total, item) => total + getWalletAssetDeductionAmount(item), 0);
244
202
  return this.publishWalletAssetsState({
245
- status: "ready",
203
+ status: 'ready',
246
204
  items: nextItems,
247
205
  selectedIds,
248
206
  selectedItems,
@@ -251,25 +209,19 @@ var WalletPassPaymentImpl = class {
251
209
  error: null
252
210
  });
253
211
  }
212
+
254
213
  /**
255
214
  * 搜索接口只返回后端 Wallet Pass 数据,不包含前端策略 config。
256
215
  * 在资产进入共享选择状态前补齐策略结果,避免增量重算回退到接口状态。
257
216
  */
258
217
  formatSearchedWalletPaymentAssets(assets) {
259
- var _a, _b, _c, _d;
260
- if (!assets.length)
261
- return assets;
262
- const assetsWithRecalculationBase = assets.map(
263
- withWalletAssetRecalculationBaseAmount
264
- );
265
- const evaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
266
- if (!(evaluator == null ? void 0 : evaluator.searchVoucherFormat))
267
- return assetsWithRecalculationBase;
218
+ if (!assets.length) return assets;
219
+ const assetsWithRecalculationBase = assets.map(withWalletAssetRecalculationBaseAmount);
220
+ const evaluator = this.paymentModule.window?.getWalletPassEvaluator?.();
221
+ if (!evaluator?.searchVoucherFormat) return assetsWithRecalculationBase;
268
222
  const hasCalculationProducts = this.walletAssetsCalculationContext.products.length > 0;
269
- const products = hasCalculationProducts ? this.walletAssetsCalculationContext.products : ((_c = this.walletParams) == null ? void 0 : _c.products) || [];
270
- const orderTotalAmount = Number(
271
- hasCalculationProducts ? this.walletAssetsCalculationContext.orderTotalAmount : ((_d = this.walletParams) == null ? void 0 : _d.order_wait_pay_amount) || 0
272
- );
223
+ const products = hasCalculationProducts ? this.walletAssetsCalculationContext.products : this.walletParams?.products || [];
224
+ const orderTotalAmount = Number(hasCalculationProducts ? this.walletAssetsCalculationContext.orderTotalAmount : this.walletParams?.order_wait_pay_amount || 0);
273
225
  try {
274
226
  const formattedAssets = evaluator.searchVoucherFormat({
275
227
  orderTotalAmount,
@@ -278,98 +230,74 @@ var WalletPassPaymentImpl = class {
278
230
  });
279
231
  return formattedAssets;
280
232
  } catch (error) {
281
- this.paymentModule.logWarning(
282
- "[WalletPass] 搜索资产策略格式化失败,保留接口结果",
283
- {
284
- error: error instanceof Error ? error.message : String(error)
285
- }
286
- );
233
+ this.paymentModule.logWarning('[WalletPass] 搜索资产策略格式化失败,保留接口结果', {
234
+ error: error instanceof Error ? error.message : String(error)
235
+ });
287
236
  return assetsWithRecalculationBase;
288
237
  }
289
238
  }
239
+
290
240
  /** 获取当前缓存中所有支付类 Wallet 资产的扫码 code。 */
291
241
  getSearchedWalletAssetCodes() {
292
242
  const cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
293
- const seenCodes = /* @__PURE__ */ new Set();
294
- return cachedAssets.map((item) => String((item == null ? void 0 : item.code) || "").trim()).filter((code) => {
243
+ const seenCodes = new Set();
244
+ return cachedAssets.map(item => String(item?.code || '').trim()).filter(code => {
295
245
  const normalizedCode = code.toUpperCase();
296
- if (!normalizedCode || seenCodes.has(normalizedCode))
297
- return false;
246
+ if (!normalizedCode || seenCodes.has(normalizedCode)) return false;
298
247
  seenCodes.add(normalizedCode);
299
248
  return true;
300
249
  });
301
250
  }
251
+
302
252
  /**
303
253
  * 用订单重算接口返回的数据更新扫码 Wallet 缓存。
304
254
  * 接口暂时缺失某个扫码 code 时继续保留旧值,避免列表闪空。
305
255
  */
306
256
  syncSearchedWalletAssets(refreshedCandidates) {
307
257
  const cachedAssets = this.searchResults.filter(isWalletPaymentAsset);
308
- const searchedCodeKeys = new Set(
309
- this.getSearchedWalletAssetCodes().map((code) => code.toUpperCase())
310
- );
311
- if (searchedCodeKeys.size === 0)
312
- return cachedAssets;
313
- const cachedAssetByCode = /* @__PURE__ */ new Map();
314
- cachedAssets.forEach((item) => {
315
- getWalletAssetCodeKeys(item).forEach((code) => {
258
+ const searchedCodeKeys = new Set(this.getSearchedWalletAssetCodes().map(code => code.toUpperCase()));
259
+ if (searchedCodeKeys.size === 0) return cachedAssets;
260
+ const cachedAssetByCode = new Map();
261
+ cachedAssets.forEach(item => {
262
+ getWalletAssetCodeKeys(item).forEach(code => {
316
263
  cachedAssetByCode.set(code, item);
317
264
  });
318
265
  });
319
- const refreshedAssets = refreshedCandidates.filter(
320
- (item) => isWalletPaymentAsset(item) && searchedCodeKeys.has(
321
- String((item == null ? void 0 : item.code) || "").trim().toUpperCase()
322
- )
323
- ).map((item) => {
324
- const cachedAsset = getWalletAssetCodeKeys(item).map((code) => cachedAssetByCode.get(code)).find(Boolean);
266
+ const refreshedAssets = refreshedCandidates.filter(item => isWalletPaymentAsset(item) && searchedCodeKeys.has(String(item?.code || '').trim().toUpperCase())).map(item => {
267
+ const cachedAsset = getWalletAssetCodeKeys(item).map(code => cachedAssetByCode.get(code)).find(Boolean);
325
268
  return withWalletAssetRecalculationBaseAmount({
326
269
  ...cachedAsset,
327
270
  ...item
328
271
  });
329
272
  });
330
273
  if (refreshedAssets.length > 0) {
331
- const replacedCodes = new Set(
332
- refreshedAssets.map(
333
- (item) => String((item == null ? void 0 : item.code) || "").trim().toUpperCase()
334
- )
335
- );
336
- this.searchResults = [
337
- ...this.searchResults.filter(
338
- (item) => !replacedCodes.has(String((item == null ? void 0 : item.code) || "").trim().toUpperCase())
339
- ),
340
- ...refreshedAssets
341
- ];
274
+ const replacedCodes = new Set(refreshedAssets.map(item => String(item?.code || '').trim().toUpperCase()));
275
+ this.searchResults = [...this.searchResults.filter(item => !replacedCodes.has(String(item?.code || '').trim().toUpperCase())), ...refreshedAssets];
342
276
  }
343
- return mergeWalletAssets(
344
- cachedAssets,
345
- refreshedAssets
346
- );
277
+ return mergeWalletAssets(cachedAssets, refreshedAssets);
347
278
  }
348
279
  isPendingAutoSelectAsset(asset) {
349
- return getWalletAssetCodeKeys(asset).some(
350
- (code) => this.pendingAutoSelectSearchCodes.has(code)
351
- );
280
+ return getWalletAssetCodeKeys(asset).some(code => this.pendingAutoSelectSearchCodes.has(code));
352
281
  }
353
282
  clearPendingAutoSelectForAsset(asset) {
354
- getWalletAssetCodeKeys(asset).forEach((code) => {
283
+ getWalletAssetCodeKeys(asset).forEach(code => {
355
284
  this.pendingAutoSelectSearchCodes.delete(code);
356
285
  });
357
286
  }
358
287
  queuePendingAutoSelectForAssets(assets) {
359
- if (!this.walletAssetsBehavior.autoSelectAfterSearch)
360
- return;
361
- assets.forEach((asset) => {
362
- getWalletAssetCodeKeys(asset).forEach((code) => {
288
+ if (!this.walletAssetsBehavior.autoSelectAfterSearch) return;
289
+ assets.forEach(asset => {
290
+ getWalletAssetCodeKeys(asset).forEach(code => {
363
291
  this.pendingAutoSelectSearchCodes.add(code);
364
292
  });
365
293
  });
366
294
  }
295
+
367
296
  /**
368
297
  * 生成钱包API默认参数
369
298
  * 根据业务数据生成标准的钱包API参数,并存储在模块中
370
299
  */
371
300
  generateWalletParams(businessData) {
372
- var _a, _b;
373
301
  const {
374
302
  customer_id,
375
303
  holder,
@@ -379,36 +307,42 @@ var WalletPassPaymentImpl = class {
379
307
  payment_order_id,
380
308
  is_price_include_tax
381
309
  } = businessData;
310
+
311
+ // 转换金额为数字类型
382
312
  const totalAmount = Number(amountInfo.totalAmount);
383
313
  const subTotal = Number(amountInfo.subTotal);
384
314
  const walletParams = {
385
315
  is_price_include_tax,
386
- sale_channel: "pos",
316
+ sale_channel: 'pos',
387
317
  customer_id: customer_id || 0,
388
318
  // 提供默认值,确保类型为 number
389
- holder_id: ((_a = holder == null ? void 0 : holder.form_record) == null ? void 0 : _a[0]) || void 0,
319
+ holder_id: holder?.form_record?.[0] || undefined,
390
320
  order_expect_amount: totalAmount,
391
321
  // 订单小计金额
392
322
  order_product_amount: subTotal,
393
323
  // 订单待支付金额
394
- order_wait_pay_amount: order_wait_pay_amount ?? ((amountInfo == null ? void 0 : amountInfo.isDeposit) ? Number(amountInfo == null ? void 0 : amountInfo.depositAmount) : totalAmount),
324
+ order_wait_pay_amount: order_wait_pay_amount ?? (amountInfo?.isDeposit ? Number(amountInfo?.depositAmount) : totalAmount),
395
325
  // order_behavior_count_customer_id: 1,
396
326
  products,
397
327
  prepare_payments: [],
398
328
  payment_order_id
399
329
  };
330
+
331
+ // 扫码可能早于异步 Wallet 初始化完成。walletParams 与前端增量重算
332
+ // 必须使用同一份当前购物车上下文,避免搜索按真实金额判断可用,
333
+ // 随后的 recalculateVouchers 却仍读取初始的 0 元/空商品上下文。
400
334
  this.walletParams = walletParams;
401
335
  this.walletAssetsCalculationContext = {
402
336
  orderTotalAmount: Number(walletParams.order_wait_pay_amount || 0),
403
337
  products: Array.isArray(walletParams.products) ? walletParams.products : []
404
338
  };
405
- this.paymentModule.logInfo("[WalletPass] 钱包默认参数已生成并存储", {
339
+ this.paymentModule.logInfo('[WalletPass] 钱包默认参数已生成并存储', {
406
340
  customer_id: walletParams.customer_id,
407
341
  holder_id: walletParams.holder_id,
408
342
  order_expect_amount: walletParams.order_expect_amount,
409
343
  order_product_amount: walletParams.order_product_amount,
410
344
  order_wait_pay_amount: walletParams.order_wait_pay_amount,
411
- products_count: ((_b = walletParams.products) == null ? void 0 : _b.length) || 0
345
+ products_count: walletParams.products?.length || 0
412
346
  });
413
347
  this.walletInitData = {
414
348
  transformList: [],
@@ -417,6 +351,7 @@ var WalletPassPaymentImpl = class {
417
351
  };
418
352
  return walletParams;
419
353
  }
354
+
420
355
  /**
421
356
  * 获取已存储的钱包参数
422
357
  * 返回之前生成并存储的钱包参数
@@ -424,23 +359,24 @@ var WalletPassPaymentImpl = class {
424
359
  getStoredWalletParams() {
425
360
  return this.walletParams;
426
361
  }
362
+
427
363
  /**
428
364
  * 清理已存储的钱包参数
429
365
  * 清除之前存储的钱包参数
430
366
  */
431
367
  clearStoredWalletParams() {
432
368
  this.walletParams = null;
433
- this.paymentModule.logInfo("[WalletPass] 已存储的钱包参数已清理");
369
+ this.paymentModule.logInfo('[WalletPass] 已存储的钱包参数已清理');
434
370
  }
371
+
435
372
  /**
436
373
  * 从业务数据初始化钱包数据
437
374
  * 内部生成参数,然后调用标准的初始化流程
438
375
  */
439
376
  async initializeWalletDataFromBusinessAsync(businessData) {
440
- var _a, _b, _c, _d, _e, _f, _g, _h;
441
377
  const startTime = Date.now();
442
378
  const walletParams = this.generateWalletParams(businessData);
443
- if (Number(((_a = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _a.totalAmount) || 0) < 0 || Number(((_b = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _b.subTotal) || 0) < 0) {
379
+ if (Number(businessData?.amountInfo?.totalAmount || 0) < 0 || Number(businessData?.amountInfo?.subTotal || 0) < 0) {
444
380
  return {
445
381
  walletRecommendList: [],
446
382
  userIdentificationCodes: [],
@@ -449,28 +385,36 @@ var WalletPassPaymentImpl = class {
449
385
  products: []
450
386
  };
451
387
  }
452
- if ([1, 0].includes((walletParams == null ? void 0 : walletParams.customer_id) || 0)) {
388
+ if ([1, 0].includes(walletParams?.customer_id || 0)) {
453
389
  return {
454
390
  walletRecommendList: [],
455
391
  userIdentificationCodes: []
456
392
  };
457
393
  }
458
- this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationStarted, {
394
+
395
+ // 发送初始化开始事件
396
+ this.emitEvent(_types.WalletPassHooks.OnWalletInitializationStarted, {
459
397
  businessData,
460
398
  startTime
461
399
  });
462
- this.paymentModule.logInfo("[WalletPass] 开始从业务数据初始化钱包数据", {
400
+ this.paymentModule.logInfo('[WalletPass] 开始从业务数据初始化钱包数据', {
463
401
  customer_id: businessData.customer_id,
464
- totalAmount: (_c = businessData.amountInfo) == null ? void 0 : _c.totalAmount,
465
- subTotal: (_d = businessData.amountInfo) == null ? void 0 : _d.subTotal,
402
+ totalAmount: businessData.amountInfo?.totalAmount,
403
+ subTotal: businessData.amountInfo?.subTotal,
466
404
  order_wait_pay_amount: businessData.order_wait_pay_amount,
467
- products_count: ((_e = businessData.products) == null ? void 0 : _e.length) || 0
405
+ products_count: businessData.products?.length || 0
468
406
  });
469
407
  try {
408
+ // 生成钱包API参数
409
+ // const walletParams = this.generateWalletParams(businessData);
410
+
411
+ // 调用标准的初始化流程
470
412
  const result = await this.initializeWalletDataAsync(walletParams);
471
413
  const endTime = Date.now();
472
414
  const duration = endTime - startTime;
473
- this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationCompleted, {
415
+
416
+ // 发送初始化完成事件
417
+ this.emitEvent(_types.WalletPassHooks.OnWalletInitializationCompleted, {
474
418
  businessData,
475
419
  result,
476
420
  startTime,
@@ -479,52 +423,50 @@ var WalletPassPaymentImpl = class {
479
423
  });
480
424
  this.paymentModule.logInfo(`[WalletPass] 从业务数据初始化钱包数据成功`, {
481
425
  duration: `${duration}ms`,
482
- walletRecommendList_count: ((_f = result.walletRecommendList) == null ? void 0 : _f.length) || 0,
483
- userIdentificationCodes_count: ((_g = result.userIdentificationCodes) == null ? void 0 : _g.length) || 0
426
+ walletRecommendList_count: result.walletRecommendList?.length || 0,
427
+ userIdentificationCodes_count: result.userIdentificationCodes?.length || 0
484
428
  });
485
429
  return result;
486
430
  } catch (error) {
487
431
  const endTime = Date.now();
488
432
  const duration = endTime - startTime;
489
- this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationFailed, {
433
+
434
+ // 发送初始化失败事件
435
+ this.emitEvent(_types.WalletPassHooks.OnWalletInitializationFailed, {
490
436
  businessData,
491
- error,
437
+ error: error,
492
438
  startTime,
493
439
  endTime,
494
440
  duration
495
441
  });
496
- this.paymentModule.logError(
497
- `[WalletPass] 从业务数据初始化钱包数据失败`,
498
- error,
499
- {
500
- duration: `${duration}ms`,
501
- customer_id: businessData.customer_id,
502
- totalAmount: (_h = businessData.amountInfo) == null ? void 0 : _h.totalAmount
503
- }
504
- );
442
+ this.paymentModule.logError(`[WalletPass] 从业务数据初始化钱包数据失败`, error, {
443
+ duration: `${duration}ms`,
444
+ customer_id: businessData.customer_id,
445
+ totalAmount: businessData.amountInfo?.totalAmount
446
+ });
505
447
  throw error;
506
448
  }
507
449
  }
450
+
508
451
  /**
509
452
  * 获取订单基础详情
510
453
  */
511
454
  async getOrderBasicDetailAsync(orderId) {
512
455
  try {
513
- const response = await this.paymentModule.request.get(
514
- `/order/order/${orderId}/basic-detail`
515
- );
516
- return (response == null ? void 0 : response.data) || {};
456
+ const response = await this.paymentModule.request.get(`/order/order/${orderId}/basic-detail`);
457
+ return response?.data || {};
517
458
  } catch (error) {
518
459
  throw error;
519
460
  }
520
461
  }
462
+
521
463
  /**
522
464
  * 初始化钱包数据
523
465
  * 先获取推荐列表,再获取用户识别码列表(顺序执行)
524
466
  */
525
467
  async initializeWalletDataAsync(baseParams) {
526
- var _a, _b;
527
468
  try {
469
+ // 格式化用户识别码列表参数
528
470
  const identificationParams = {
529
471
  ...baseParams,
530
472
  available: 2,
@@ -532,11 +474,10 @@ var WalletPassPaymentImpl = class {
532
474
  other_exact_codes: [],
533
475
  filter_prepare_wallet_pass: 1
534
476
  };
535
- const [allList, orderBasicDetail] = await Promise.all([
536
- this.getUserIdentificationCodeListAsync(identificationParams),
537
- baseParams.payment_order_id && typeof baseParams.payment_order_id === "string" && !baseParams.payment_order_id.startsWith("LOCAL_") ? this.getOrderBasicDetailAsync(baseParams.payment_order_id) : Promise.resolve(null)
538
- ]);
539
- const walletPassEvaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
477
+
478
+ // 并行获取用户识别码列表和订单详情
479
+ const [allList, orderBasicDetail] = await Promise.all([this.getUserIdentificationCodeListAsync(identificationParams), baseParams.payment_order_id && typeof baseParams.payment_order_id === 'string' && !baseParams.payment_order_id.startsWith('LOCAL_') ? this.getOrderBasicDetailAsync(baseParams.payment_order_id) : Promise.resolve(null)]);
480
+ const walletPassEvaluator = this.paymentModule.window?.getWalletPassEvaluator?.();
540
481
  if (!walletPassEvaluator) {
541
482
  return {
542
483
  walletRecommendList: [],
@@ -546,44 +487,56 @@ var WalletPassPaymentImpl = class {
546
487
  products: []
547
488
  };
548
489
  }
549
- const products = (orderBasicDetail == null ? void 0 : orderBasicDetail.detail) || baseParams.products;
550
- const res = walletPassEvaluator == null ? void 0 : walletPassEvaluator.getRecommendedVouchers({
490
+ const products = orderBasicDetail?.detail || baseParams.products;
491
+ const res = walletPassEvaluator?.getRecommendedVouchers({
551
492
  orderTotalAmount: baseParams.order_wait_pay_amount,
552
- products,
493
+ products: products,
553
494
  vouchers: allList
554
495
  });
555
- const { recommended, transformList, noApplicableVoucher, recommendedAmount } = res;
556
- this.walletRecommendList = recommended;
557
- this.walletInitData = {
496
+ const {
497
+ recommended,
558
498
  transformList,
559
499
  noApplicableVoucher,
500
+ recommendedAmount
501
+ } = res;
502
+ this.walletRecommendList = recommended;
503
+
504
+ // 存储初始化数据到内存中,供 useWalletPass 使用
505
+ this.walletInitData = {
506
+ transformList: transformList,
507
+ noApplicableVoucher: noApplicableVoucher,
560
508
  products: products || []
561
509
  };
510
+
511
+ // // 再获取用户识别码列表
512
+ // const userIdentificationCodes =
513
+ // await this.getUserIdentificationCodeListAsync(identificationParams);
514
+
562
515
  return {
563
516
  walletRecommendList: recommended,
564
517
  userIdentificationCodes: allList,
565
- transformList,
566
- noApplicableVoucher,
518
+ transformList: transformList,
519
+ noApplicableVoucher: noApplicableVoucher,
567
520
  products: products || []
568
521
  };
569
522
  } catch (error) {
570
- this.paymentModule.logError("[WalletPass] 初始化钱包数据失败", error, {
523
+ this.paymentModule.logError('[WalletPass] 初始化钱包数据失败', error, {
571
524
  customer_id: baseParams.customer_id,
572
525
  order_expect_amount: baseParams.order_expect_amount
573
526
  });
574
527
  throw error;
575
528
  }
576
529
  }
530
+
577
531
  /**
578
532
  * 商品或订单金额变化后,使用聚合接口一次重算已选与剩余 WalletPass。
579
533
  * Walk-In 不发送 customer_id;会员才携带真实 customer_id。
580
534
  */
581
535
  async aggregateRecalculateWalletAssetsAsync(businessData, selectedIds) {
582
- var _a, _b;
583
536
  const walletParams = this.generateWalletParams(businessData);
584
537
  const customerId = Number(walletParams.customer_id || 0);
585
538
  const requestParams = {
586
- ids: selectedIds.map((id) => String(id)),
539
+ ids: selectedIds.map(id => String(id)),
587
540
  exact_codes: this.getSearchedWalletAssetCodes(),
588
541
  order_product_amount: walletParams.order_product_amount,
589
542
  order_expect_amount: walletParams.order_expect_amount,
@@ -591,59 +544,39 @@ var WalletPassPaymentImpl = class {
591
544
  products: walletParams.products,
592
545
  available: 2,
593
546
  filter_prepare_wallet_pass: 1,
594
- sale_channel: walletParams.sale_channel || "pos"
547
+ sale_channel: walletParams.sale_channel || 'pos'
595
548
  };
596
549
  if (customerId > 1) {
597
550
  requestParams.customer_id = customerId;
598
551
  }
599
- const response = await this.paymentModule.request.post(
600
- "/machinecode/prepare/deduction/aggregate-recalculate",
601
- requestParams
602
- );
603
- const responseData = response == null ? void 0 : response.data;
604
- const hasAggregateLists = responseData && (Object.prototype.hasOwnProperty.call(
605
- responseData,
606
- "recalculate_list"
607
- ) || Object.prototype.hasOwnProperty.call(
608
- responseData,
609
- "customer_wallet_pass_list"
610
- ));
552
+ const response = await this.paymentModule.request.post('/machinecode/prepare/deduction/aggregate-recalculate', requestParams);
553
+ const responseData = response?.data;
554
+ const hasAggregateLists = responseData && (Object.prototype.hasOwnProperty.call(responseData, 'recalculate_list') || Object.prototype.hasOwnProperty.call(responseData, 'customer_wallet_pass_list'));
611
555
  if (!hasAggregateLists) {
612
- throw new Error("WalletPass aggregate response is missing list data");
556
+ throw new Error('WalletPass aggregate response is missing list data');
613
557
  }
614
- const recalculateList = Array.isArray(responseData == null ? void 0 : responseData.recalculate_list) ? responseData.recalculate_list : [];
615
- const customerWalletPassList = Array.isArray(
616
- responseData == null ? void 0 : responseData.customer_wallet_pass_list
617
- ) ? responseData.customer_wallet_pass_list : [];
618
- const orderedRecalculateList = orderWalletAssetsByIds(
619
- recalculateList,
620
- selectedIds
621
- );
622
- const allList = mergeWalletAssets(
623
- orderedRecalculateList,
624
- customerWalletPassList
625
- );
626
- const walletPassEvaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
627
- const evaluated = (walletPassEvaluator == null ? void 0 : walletPassEvaluator.getRecommendedVouchers) ? walletPassEvaluator.getRecommendedVouchers({
558
+ const recalculateList = Array.isArray(responseData?.recalculate_list) ? responseData.recalculate_list : [];
559
+ const customerWalletPassList = Array.isArray(responseData?.customer_wallet_pass_list) ? responseData.customer_wallet_pass_list : [];
560
+ const orderedRecalculateList = orderWalletAssetsByIds(recalculateList, selectedIds);
561
+ const allList = mergeWalletAssets(orderedRecalculateList, customerWalletPassList);
562
+ const walletPassEvaluator = this.paymentModule.window?.getWalletPassEvaluator?.();
563
+ const evaluated = walletPassEvaluator?.getRecommendedVouchers ? walletPassEvaluator.getRecommendedVouchers({
628
564
  orderTotalAmount: walletParams.order_wait_pay_amount,
629
565
  products: walletParams.products,
630
566
  vouchers: allList
631
567
  }) : {
632
568
  recommended: [],
633
569
  transformList: allList.filter(isWalletAssetAvailable),
634
- noApplicableVoucher: allList.filter(
635
- (item) => !isWalletAssetAvailable(item)
636
- )
570
+ noApplicableVoucher: allList.filter(item => !isWalletAssetAvailable(item))
637
571
  };
638
- const returnedSelectedKeys = new Set(
639
- allList.map((item) => getWalletAssetKey(item))
640
- );
641
- const authoritativeSelectedIds = selectedIds.filter(
642
- (id) => returnedSelectedKeys.has(String(id))
643
- );
572
+ // 聚合接口只负责刷新资产数据;选中资格最终由前端 evaluator 重算。
573
+ // 这里仅移除接口完全未返回的资产,不能把 recalculate_list 当作
574
+ // 策略选中结果,否则 customer_wallet_pass_list 中的可用券会被误取消。
575
+ const returnedSelectedKeys = new Set(allList.map(item => getWalletAssetKey(item)));
576
+ const authoritativeSelectedIds = selectedIds.filter(id => returnedSelectedKeys.has(String(id)));
644
577
  this.walletRecommendList = evaluated.recommended || [];
645
578
  this.userIdentificationCodes = allList;
646
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
579
+ this.emitEvent(_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
647
580
  userIdentificationCodes: this.userIdentificationCodes
648
581
  });
649
582
  this.walletInitData = {
@@ -651,14 +584,11 @@ var WalletPassPaymentImpl = class {
651
584
  noApplicableVoucher: evaluated.noApplicableVoucher || [],
652
585
  products: walletParams.products || []
653
586
  };
654
- this.paymentModule.logInfo(
655
- "[WalletPass] 聚合重算 WalletPass 完成",
656
- {
657
- selected_count: recalculateList.length,
658
- remaining_count: customerWalletPassList.length,
659
- searched_codes_count: requestParams.exact_codes.length
660
- }
661
- );
587
+ this.paymentModule.logInfo('[WalletPass] 聚合重算 WalletPass 完成', {
588
+ selected_count: recalculateList.length,
589
+ remaining_count: customerWalletPassList.length,
590
+ searched_codes_count: requestParams.exact_codes.length
591
+ });
662
592
  return {
663
593
  walletRecommendList: this.walletRecommendList,
664
594
  userIdentificationCodes: this.userIdentificationCodes,
@@ -669,29 +599,27 @@ var WalletPassPaymentImpl = class {
669
599
  };
670
600
  }
671
601
  async getWalletPassRecommendListAsync(params) {
672
- var _a;
673
602
  try {
674
- this.paymentModule.logInfo("[WalletPass] 开始获取钱包推荐列表", {
603
+ this.paymentModule.logInfo('[WalletPass] 开始获取钱包推荐列表', {
675
604
  customer_id: params.customer_id,
676
605
  order_expect_amount: params.order_expect_amount,
677
606
  sale_channel: params.sale_channel,
678
- payment_order_id: (_a = this.walletParams) == null ? void 0 : _a.payment_order_id
607
+ payment_order_id: this.walletParams?.payment_order_id
679
608
  });
680
- if (typeof params.payment_order_id === "string" && params.payment_order_id.startsWith("LOCAL_")) {
681
- params.payment_order_id = void 0;
609
+ if (typeof params.payment_order_id === 'string' && params.payment_order_id.startsWith('LOCAL_')) {
610
+ params.payment_order_id = undefined;
682
611
  }
683
- const response = await this.paymentModule.request.post(
684
- "/machinecode/prepare/deduction/recommend",
685
- params
686
- // 将 params 作为请求体数据
612
+ const response = await this.paymentModule.request.post('/machinecode/prepare/deduction/recommend', params // 将 params 作为请求体数据
687
613
  );
688
- this.walletRecommendList = (response == null ? void 0 : response.data) || [];
689
- this.emitEvent(import_types.WalletPassHooks.OnWalletRecommendListUpdated, {
614
+ this.walletRecommendList = response?.data || [];
615
+
616
+ // 发送钱包推荐列表更新事件(使用专用的WalletPassHooks)
617
+ this.emitEvent(_types.WalletPassHooks.OnWalletRecommendListUpdated, {
690
618
  walletRecommendList: this.walletRecommendList
691
619
  });
692
- this.paymentModule.logInfo("[WalletPass] 钱包推荐列表已更新", {
620
+ this.paymentModule.logInfo('[WalletPass] 钱包推荐列表已更新', {
693
621
  count: this.walletRecommendList.length,
694
- items: this.walletRecommendList.map((item) => ({
622
+ items: this.walletRecommendList.map(item => ({
695
623
  voucher_id: item.voucher_id,
696
624
  name: item.name,
697
625
  amount: item.amount,
@@ -700,62 +628,61 @@ var WalletPassPaymentImpl = class {
700
628
  });
701
629
  return this.walletRecommendList;
702
630
  } catch (error) {
703
- this.paymentModule.logError("[WalletPass] 获取钱包推荐列表失败", error, {
631
+ this.paymentModule.logError('[WalletPass] 获取钱包推荐列表失败', error, {
704
632
  customer_id: params.customer_id,
705
633
  order_expect_amount: params.order_expect_amount,
706
634
  sale_channel: params.sale_channel
707
635
  });
636
+ // throw error;
708
637
  return [];
709
638
  }
710
639
  }
711
640
  formatWalletPassList2PreparePayments(list) {
712
- return (0, import_utils.formatWalletPassList2PreparePayments)(list);
641
+ return (0, _utils.formatWalletPassList2PreparePayments)(list);
713
642
  }
714
643
  async getUserIdentificationCodeListAsync(params) {
715
- var _a, _b, _c;
716
644
  try {
717
645
  const newParams = {
718
646
  ...this.walletParams,
719
647
  ...params
720
648
  };
721
- if (!((_a = newParams.products) == null ? void 0 : _a.length)) {
722
- this.paymentModule.logInfo("[WalletPass] 商品列表为空,跳过获取用户识别码列表");
649
+ if (!newParams.products?.length) {
650
+ this.paymentModule.logInfo('[WalletPass] 商品列表为空,跳过获取用户识别码列表');
723
651
  return [];
724
652
  }
725
653
  const platform = this.paymentModule.getPlatform();
726
- if (platform === "pc" || platform === "h5") {
654
+ if (platform === 'pc' || platform === 'h5') {
727
655
  this.userIdentificationCodes = [];
728
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
656
+ this.emitEvent(_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
729
657
  userIdentificationCodes: []
730
658
  });
731
- this.paymentModule.logInfo(
732
- "[WalletPass] 用户端平台跳过获取用户识别码列表",
733
- { platform }
734
- );
659
+ this.paymentModule.logInfo('[WalletPass] 用户端平台跳过获取用户识别码列表', {
660
+ platform
661
+ });
735
662
  return [];
736
663
  }
737
- if (typeof newParams.payment_order_id === "string" && newParams.payment_order_id.startsWith("LOCAL_")) {
738
- newParams.payment_order_id = void 0;
664
+ if (typeof newParams.payment_order_id === 'string' && newParams.payment_order_id.startsWith('LOCAL_')) {
665
+ newParams.payment_order_id = undefined;
739
666
  }
740
- this.paymentModule.logInfo("[WalletPass] 开始获取用户识别码列表", {
667
+ this.paymentModule.logInfo('[WalletPass] 开始获取用户识别码列表', {
741
668
  customer_id: newParams.customer_id,
742
669
  available: newParams.available,
743
- prepare_payments_count: ((_b = newParams.prepare_payments) == null ? void 0 : _b.length) || 0,
670
+ prepare_payments_count: newParams.prepare_payments?.length || 0,
744
671
  filter_prepare_wallet_pass: newParams.filter_prepare_wallet_pass,
745
- payment_order_id: (_c = this.walletParams) == null ? void 0 : _c.payment_order_id
672
+ payment_order_id: this.walletParams?.payment_order_id
746
673
  });
747
- const response = await this.paymentModule.request.post(
748
- "/machinecode/prepare/deduction",
749
- newParams
750
- );
751
- const sortedData = (0, import_utils.sortUserIdentificationCodeList)((response == null ? void 0 : response.data) || []);
674
+ const response = await this.paymentModule.request.post('/machinecode/prepare/deduction', newParams);
675
+ // 对获取到的数据进行排序,将错误码为 500100、500200、500300 的项目排到最后
676
+ const sortedData = (0, _utils.sortUserIdentificationCodeList)(response?.data || []);
752
677
  this.userIdentificationCodes = sortedData;
753
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
678
+
679
+ // 发送用户识别码列表更新事件(使用专用的WalletPassHooks)
680
+ this.emitEvent(_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
754
681
  userIdentificationCodes: this.userIdentificationCodes
755
682
  });
756
- this.paymentModule.logInfo("[WalletPass] 用户识别码列表已更新", {
683
+ this.paymentModule.logInfo('[WalletPass] 用户识别码列表已更新', {
757
684
  count: this.userIdentificationCodes.length,
758
- sorted_items: this.userIdentificationCodes.slice(0, 5).map((item) => ({
685
+ sorted_items: this.userIdentificationCodes.slice(0, 5).map(item => ({
759
686
  code: item.code,
760
687
  error_code: item.error_code,
761
688
  error_msg: item.error_msg
@@ -763,17 +690,14 @@ var WalletPassPaymentImpl = class {
763
690
  });
764
691
  return this.userIdentificationCodes;
765
692
  } catch (error) {
766
- this.paymentModule.logError(
767
- "[WalletPass] 获取用户识别码列表失败",
768
- error,
769
- {
770
- customer_id: params.customer_id,
771
- available: params.available
772
- }
773
- );
693
+ this.paymentModule.logError('[WalletPass] 获取用户识别码列表失败', error, {
694
+ customer_id: params.customer_id,
695
+ available: params.available
696
+ });
774
697
  return [];
775
698
  }
776
699
  }
700
+
777
701
  /**
778
702
  * 搜索识别码信息
779
703
  * 通过识别码搜索相关的钱包通行证信息
@@ -782,103 +706,107 @@ var WalletPassPaymentImpl = class {
782
706
  */
783
707
  async searchIdentificationCodeAsync(params, config = {}) {
784
708
  try {
785
- const { code } = params;
786
- this.paymentModule.logInfo("[WalletPass] 开始搜索识别码", {
787
- code,
709
+ const {
710
+ code
711
+ } = params;
712
+ this.paymentModule.logInfo('[WalletPass] 开始搜索识别码', {
713
+ code: code,
788
714
  code_length: code.length,
789
715
  noCache: config.noCache || false
790
716
  });
791
- const isWalletCode = code.startsWith("WL") || code.startsWith("200") && code.length === 10;
717
+
718
+ // 新钱包规则
719
+ const isWalletCode = code.startsWith('WL') || code.startsWith('200') && code.length === 10;
792
720
  if (isWalletCode) {
721
+ // 钱包识别码直接调用专门接口,不缓存,直接返回
793
722
  const walletDetailParams = {
794
- code,
723
+ code: code,
795
724
  with_customer: 1,
796
- with: ["wallet"]
725
+ with: ['wallet']
797
726
  };
798
- this.paymentModule.logInfo("[WalletPass] 搜索钱包识别码", {
799
- code,
727
+ this.paymentModule.logInfo('[WalletPass] 搜索钱包识别码', {
728
+ code: code,
800
729
  with_customer: walletDetailParams.with_customer,
801
730
  with: walletDetailParams.with
802
731
  });
803
- const response2 = await this.paymentModule.request.post(
804
- "/wallet/detail/search",
805
- walletDetailParams
806
- );
807
- const searchResults2 = (response2 == null ? void 0 : response2.data) || [];
808
- this.paymentModule.logInfo("[WalletPass] 钱包识别码搜索完成", {
809
- code,
810
- results_count: searchResults2.length,
811
- type: "walletCode"
732
+ const response = await this.paymentModule.request.post('/wallet/detail/search', walletDetailParams);
733
+ const searchResults = response?.data || [];
734
+ this.paymentModule.logInfo('[WalletPass] 钱包识别码搜索完成', {
735
+ code: code,
736
+ results_count: searchResults.length,
737
+ type: 'walletCode'
812
738
  });
813
739
  return {
814
- type: "walletCode",
815
- data: searchResults2
740
+ type: 'walletCode',
741
+ data: searchResults
816
742
  };
817
743
  }
744
+
745
+ // 合并钱包参数和搜索参数
818
746
  const baseWalletParams = this.walletParams;
747
+
748
+ // 构建完整的搜索参数,包含钱包扣款推荐的所有参数
819
749
  const searchParams = {
820
750
  // 基础钱包参数
821
- sale_channel: params.sale_channel ?? (baseWalletParams == null ? void 0 : baseWalletParams.sale_channel) ?? "pos",
822
- customer_id: params.customer_id ?? (baseWalletParams == null ? void 0 : baseWalletParams.customer_id),
823
- order_expect_amount: params.order_expect_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_expect_amount),
824
- order_product_amount: params.order_product_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_product_amount),
825
- order_wait_pay_amount: params.order_wait_pay_amount ?? (baseWalletParams == null ? void 0 : baseWalletParams.order_wait_pay_amount),
826
- 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),
827
- products: params.products ?? (baseWalletParams == null ? void 0 : baseWalletParams.products) ?? [],
828
- prepare_payments: params.prepare_payments ?? (baseWalletParams == null ? void 0 : baseWalletParams.prepare_payments) ?? [],
751
+ sale_channel: params.sale_channel ?? baseWalletParams?.sale_channel ?? 'pos',
752
+ customer_id: params.customer_id ?? baseWalletParams?.customer_id,
753
+ order_expect_amount: params.order_expect_amount ?? baseWalletParams?.order_expect_amount,
754
+ order_product_amount: params.order_product_amount ?? baseWalletParams?.order_product_amount,
755
+ order_wait_pay_amount: params.order_wait_pay_amount ?? baseWalletParams?.order_wait_pay_amount,
756
+ order_behavior_count_customer_id: params.order_behavior_count_customer_id ?? baseWalletParams?.order_behavior_count_customer_id ?? params.customer_id ?? baseWalletParams?.customer_id,
757
+ products: params.products ?? baseWalletParams?.products ?? [],
758
+ prepare_payments: params.prepare_payments ?? baseWalletParams?.prepare_payments ?? [],
829
759
  multiple: 1,
830
760
  // 搜索特有参数
831
761
  code: params.code,
832
- payment_order_id: baseWalletParams == null ? void 0 : baseWalletParams.payment_order_id
762
+ payment_order_id: baseWalletParams?.payment_order_id
833
763
  };
834
- this.paymentModule.logInfo("[WalletPass] 搜索普通识别码", {
764
+ this.paymentModule.logInfo('[WalletPass] 搜索普通识别码', {
835
765
  code: searchParams.code,
836
766
  customer_id: searchParams.customer_id,
837
767
  order_expect_amount: searchParams.order_expect_amount,
838
768
  multiple: searchParams.multiple,
839
- payment_order_id: baseWalletParams == null ? void 0 : baseWalletParams.payment_order_id
769
+ payment_order_id: baseWalletParams?.payment_order_id
840
770
  });
841
- if (typeof searchParams.payment_order_id === "string" && searchParams.payment_order_id.startsWith("LOCAL_")) {
842
- searchParams.payment_order_id = void 0;
771
+ if (typeof searchParams.payment_order_id === 'string' && searchParams.payment_order_id.startsWith('LOCAL_')) {
772
+ searchParams.payment_order_id = undefined;
843
773
  }
844
- const response = await this.paymentModule.request.post(
845
- "/machinecode/prepare/deduction/search",
846
- searchParams
847
- );
848
- const searchResults = (response == null ? void 0 : response.data) || [];
774
+ const response = await this.paymentModule.request.post('/machinecode/prepare/deduction/search', searchParams);
775
+ const searchResults = response?.data || [];
849
776
  if (config.noCache) {
850
777
  return {
851
- type: "normalCode",
778
+ type: 'normalCode',
852
779
  data: searchResults
853
780
  };
854
781
  }
782
+
783
+ // 将搜索结果存储到缓存数组中
855
784
  if (searchResults.length > 0) {
856
- const existingCodes = new Set(
857
- this.searchResults.map((item) => item.code)
858
- );
859
- const newResults = searchResults.filter(
860
- (item) => !existingCodes.has(item.code)
861
- );
785
+ // 避免重复存储相同的识别码
786
+ const existingCodes = new Set(this.searchResults.map(item => item.code));
787
+ const newResults = searchResults.filter(item => !existingCodes.has(item.code));
862
788
  this.searchResults.push(...newResults);
863
789
  }
864
- this.emitEvent(import_types.WalletPassHooks.OnSearchIdentificationCodeCompleted, {
790
+
791
+ // 通过事件暴露当前搜索结果和缓存结果
792
+ this.emitEvent(_types.WalletPassHooks.OnSearchIdentificationCodeCompleted, {
865
793
  searchCode: params.code,
866
794
  currentSearchResults: searchResults,
867
795
  cachedSearchResults: [...this.searchResults],
868
796
  searchParams: params
869
797
  });
870
- this.paymentModule.logInfo("[WalletPass] 普通识别码搜索完成", {
798
+ this.paymentModule.logInfo('[WalletPass] 普通识别码搜索完成', {
871
799
  code: params.code,
872
800
  results_count: searchResults.length,
873
801
  cached_results_count: this.searchResults.length,
874
- type: "normalCode"
802
+ type: 'normalCode'
875
803
  });
876
804
  return {
877
- type: "normalCode",
805
+ type: 'normalCode',
878
806
  data: searchResults
879
807
  };
880
808
  } catch (error) {
881
- this.paymentModule.logError("[WalletPass] 搜索识别码信息失败", error, {
809
+ this.paymentModule.logError('[WalletPass] 搜索识别码信息失败', error, {
882
810
  code: params.code,
883
811
  customer_id: params.customer_id,
884
812
  order_expect_amount: params.order_expect_amount
@@ -886,6 +814,7 @@ var WalletPassPaymentImpl = class {
886
814
  throw error;
887
815
  }
888
816
  }
817
+
889
818
  /**
890
819
  * 刷新购物车与结账共享的钱包资产。
891
820
  *
@@ -893,42 +822,39 @@ var WalletPassPaymentImpl = class {
893
822
  * 推荐结果只作为可用性/金额计算输入,不会自动成为 selectedIds。
894
823
  */
895
824
  async refreshWalletAssetsFromBusinessAsync(businessData, options = {}) {
896
- var _a;
897
825
  const requestSequence = ++this.walletAssetsRequestSequence;
898
826
  const nextCustomerId = businessData.customer_id;
899
827
  const previousCustomerId = this.walletAssetsState.customerId;
900
- const customerChanged = String(previousCustomerId ?? "") !== String(nextCustomerId ?? "");
828
+ const customerChanged = String(previousCustomerId ?? '') !== String(nextCustomerId ?? '');
901
829
  const preserveSelection = options.preserveSelection !== false && !customerChanged;
902
830
  if (customerChanged) {
903
831
  this.clearSearchResults();
904
832
  }
905
- const committedKeys = new Set(
906
- this.walletAssetsState.committedIds.map((id) => String(id))
907
- );
908
- const committedItems = this.walletAssetsState.items.filter(
909
- (item) => committedKeys.has(getWalletAssetKey(item))
910
- );
833
+ const committedKeys = new Set(this.walletAssetsState.committedIds.map(id => String(id)));
834
+ const committedItems = this.walletAssetsState.items.filter(item => committedKeys.has(getWalletAssetKey(item)));
911
835
  const selectedIds = preserveSelection ? [...this.walletAssetsState.selectedIds] : [];
912
- const selectionSources = preserveSelection ? { ...this.walletAssetsState.selectionSources } : {};
913
- const scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter((asset) => {
836
+ const selectionSources = preserveSelection ? {
837
+ ...this.walletAssetsState.selectionSources
838
+ } : {};
839
+ const scanSelectedAssets = preserveSelection ? this.walletAssetsState.selectedItems.filter(asset => {
914
840
  const assetId = getWalletAssetId(asset);
915
- return assetId !== void 0 && assetId !== null && selectionSources[String(assetId)] === "scan";
841
+ return assetId !== undefined && assetId !== null && selectionSources[String(assetId)] === 'scan';
916
842
  }) : [];
917
- const manualEditAmountByKey = /* @__PURE__ */ new Map();
843
+ const manualEditAmountByKey = new Map();
918
844
  if (preserveSelection) {
919
- this.walletAssetsState.selectedItems.forEach((asset) => {
920
- if (typeof (asset == null ? void 0 : asset.edit_current_amount) !== "number")
921
- return;
922
- manualEditAmountByKey.set(
923
- getWalletAssetKey(asset),
924
- asset.edit_current_amount
925
- );
845
+ this.walletAssetsState.selectedItems.forEach(asset => {
846
+ if (typeof asset?.edit_current_amount !== 'number') return;
847
+ manualEditAmountByKey.set(getWalletAssetKey(asset), asset.edit_current_amount);
926
848
  });
927
849
  }
928
- if (!((_a = businessData.products) == null ? void 0 : _a.length)) {
850
+
851
+ // aggregate-recalculate 不接受空商品列表。
852
+ // 清空购物车时保留扫码资产供后续加购恢复;只有手动 Remove/Clear
853
+ // 会取消自动应用资格,商品变化导致的自动失效需要重新进入待选队列。
854
+ if (!businessData.products?.length) {
929
855
  this.queuePendingAutoSelectForAssets(scanSelectedAssets);
930
856
  this.generateWalletParams(businessData);
931
- const restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map((item) => ({
857
+ const restoredSearchedAssets = this.searchResults.filter(isWalletPaymentAsset).map(item => ({
932
858
  ...item,
933
859
  actualDeduction: 0,
934
860
  deductionDetails: [],
@@ -947,16 +873,13 @@ var WalletPassPaymentImpl = class {
947
873
  orderTotalAmount: 0,
948
874
  products: []
949
875
  };
950
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
876
+ this.emitEvent(_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
951
877
  userIdentificationCodes: []
952
878
  });
953
879
  return this.publishWalletAssetsState({
954
- status: "ready",
880
+ status: 'ready',
955
881
  customerId: nextCustomerId,
956
- items: mergeWalletAssets(
957
- restoredSearchedAssets,
958
- committedItems
959
- ),
882
+ items: mergeWalletAssets(restoredSearchedAssets, committedItems),
960
883
  selectedIds: [],
961
884
  selectedItems: [],
962
885
  selectionSources: {},
@@ -965,7 +888,7 @@ var WalletPassPaymentImpl = class {
965
888
  });
966
889
  }
967
890
  this.publishWalletAssetsState({
968
- status: "loading",
891
+ status: 'loading',
969
892
  customerId: nextCustomerId,
970
893
  items: preserveSelection ? this.walletAssetsState.items : committedItems,
971
894
  selectedIds,
@@ -977,11 +900,8 @@ var WalletPassPaymentImpl = class {
977
900
  try {
978
901
  const searchedWalletAssetCodes = preserveSelection ? this.getSearchedWalletAssetCodes() : [];
979
902
  const useAggregateRecalculate = preserveSelection && (selectedIds.length > 0 || searchedWalletAssetCodes.length > 0);
980
- const aggregateResult = useAggregateRecalculate ? await this.aggregateRecalculateWalletAssetsAsync(
981
- businessData,
982
- selectedIds
983
- ) : null;
984
- const result = aggregateResult || await this.initializeWalletDataFromBusinessAsync(businessData);
903
+ const aggregateResult = useAggregateRecalculate ? await this.aggregateRecalculateWalletAssetsAsync(businessData, selectedIds) : null;
904
+ const result = aggregateResult || (await this.initializeWalletDataFromBusinessAsync(businessData));
985
905
  if (requestSequence !== this.walletAssetsRequestSequence) {
986
906
  return this.getWalletAssetsState();
987
907
  }
@@ -989,86 +909,56 @@ var WalletPassPaymentImpl = class {
989
909
  orderTotalAmount: Number(businessData.order_wait_pay_amount || 0),
990
910
  products: result.products || businessData.products || []
991
911
  };
992
- const authoritativeSelectedIds = (aggregateResult == null ? void 0 : aggregateResult.authoritativeSelectedIds) || selectedIds;
912
+ const authoritativeSelectedIds = aggregateResult?.authoritativeSelectedIds || selectedIds;
993
913
  if (aggregateResult) {
994
- const returnedAggregateKeys = new Set(
995
- [
996
- ...result.transformList || [],
997
- ...result.noApplicableVoucher || []
998
- ].map((item) => getWalletAssetKey(item))
999
- );
1000
- const missingSelectedKeys = new Set(
1001
- selectedIds.map((id) => String(id)).filter((id) => !returnedAggregateKeys.has(id))
1002
- );
914
+ const returnedAggregateKeys = new Set([...(result.transformList || []), ...(result.noApplicableVoucher || [])].map(item => getWalletAssetKey(item)));
915
+ const missingSelectedKeys = new Set(selectedIds.map(id => String(id)).filter(id => !returnedAggregateKeys.has(id)));
1003
916
  if (missingSelectedKeys.size > 0) {
1004
- this.searchResults = this.searchResults.filter(
1005
- (item) => !missingSelectedKeys.has(getWalletAssetKey(item))
1006
- );
917
+ this.searchResults = this.searchResults.filter(item => !missingSelectedKeys.has(getWalletAssetKey(item)));
1007
918
  }
1008
919
  }
1009
- const searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([
1010
- ...result.transformList || [],
1011
- ...result.noApplicableVoucher || []
1012
- ]) : [];
920
+ const searchedWalletAssets = preserveSelection ? this.syncSearchedWalletAssets([...(result.transformList || []), ...(result.noApplicableVoucher || [])]) : [];
1013
921
  if (requestSequence !== this.walletAssetsRequestSequence) {
1014
922
  return this.getWalletAssetsState();
1015
923
  }
1016
- const recommendedKeys = new Set(
1017
- (result.walletRecommendList || []).map(
1018
- (asset) => getWalletAssetKey(asset)
1019
- )
1020
- );
1021
- const items = mergeWalletAssets(
1022
- preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [],
1023
- searchedWalletAssets,
1024
- result.transformList || [],
1025
- result.noApplicableVoucher || []
1026
- ).map((asset) => {
924
+ const recommendedKeys = new Set((result.walletRecommendList || []).map(asset => getWalletAssetKey(asset)));
925
+ const items = mergeWalletAssets(preserveSelection && !aggregateResult ? this.walletAssetsState.selectedItems : [], searchedWalletAssets, result.transformList || [], result.noApplicableVoucher || []).map(asset => {
1027
926
  const assetKey = getWalletAssetKey(asset);
1028
927
  return {
1029
928
  ...asset,
1030
- ...manualEditAmountByKey.has(assetKey) ? {
929
+ ...(manualEditAmountByKey.has(assetKey) ? {
1031
930
  edit_current_amount: manualEditAmountByKey.get(assetKey)
1032
- } : {},
931
+ } : {}),
1033
932
  _wallet_asset_recommended: recommendedKeys.has(assetKey)
1034
933
  };
1035
934
  });
1036
935
  const latestSelectedIds = preserveSelection ? authoritativeSelectedIds : [];
1037
- const latestSelectionSources = preserveSelection ? { ...this.walletAssetsState.selectionSources } : {};
1038
- const pendingAutoSelectAssets = this.walletAssetsBehavior.autoSelectAfterSearch ? items.filter(
1039
- (asset) => this.isPendingAutoSelectAsset(asset) && isWalletAssetAvailable(asset)
1040
- ) : [];
1041
- const requestedKeySet = new Set(
1042
- latestSelectedIds.map((id) => String(id))
1043
- );
1044
- pendingAutoSelectAssets.forEach((asset) => {
936
+ const latestSelectionSources = preserveSelection ? {
937
+ ...this.walletAssetsState.selectionSources
938
+ } : {};
939
+ const pendingAutoSelectAssets = this.walletAssetsBehavior.autoSelectAfterSearch ? items.filter(asset => this.isPendingAutoSelectAsset(asset) && isWalletAssetAvailable(asset)) : [];
940
+ const requestedKeySet = new Set(latestSelectedIds.map(id => String(id)));
941
+ pendingAutoSelectAssets.forEach(asset => {
1045
942
  const assetId = getWalletAssetId(asset);
1046
- if (assetId === void 0 || assetId === null)
1047
- return;
943
+ if (assetId === undefined || assetId === null) return;
1048
944
  const assetKey = String(assetId);
1049
945
  if (!requestedKeySet.has(assetKey)) {
1050
946
  requestedKeySet.add(assetKey);
1051
947
  latestSelectedIds.push(assetId);
1052
948
  }
1053
- latestSelectionSources[assetKey] = "scan";
949
+ latestSelectionSources[assetKey] = 'scan';
1054
950
  });
1055
- const nextState = this.recalculateWalletAssets(
1056
- items,
1057
- latestSelectedIds,
1058
- latestSelectionSources
1059
- );
1060
- const selectedKeySet = new Set(
1061
- nextState.selectedIds.map((id) => String(id))
1062
- );
1063
- pendingAutoSelectAssets.forEach((asset) => {
951
+ const nextState = this.recalculateWalletAssets(items, latestSelectedIds, latestSelectionSources);
952
+ const selectedKeySet = new Set(nextState.selectedIds.map(id => String(id)));
953
+ pendingAutoSelectAssets.forEach(asset => {
1064
954
  const assetId = getWalletAssetId(asset);
1065
- if (assetId !== void 0 && assetId !== null && selectedKeySet.has(String(assetId))) {
955
+ if (assetId !== undefined && assetId !== null && selectedKeySet.has(String(assetId))) {
1066
956
  this.clearPendingAutoSelectForAsset(asset);
1067
957
  }
1068
958
  });
1069
- const droppedScanSelectedAssets = scanSelectedAssets.filter((asset) => {
959
+ const droppedScanSelectedAssets = scanSelectedAssets.filter(asset => {
1070
960
  const assetId = getWalletAssetId(asset);
1071
- return assetId !== void 0 && assetId !== null && !selectedKeySet.has(String(assetId));
961
+ return assetId !== undefined && assetId !== null && !selectedKeySet.has(String(assetId));
1072
962
  });
1073
963
  this.queuePendingAutoSelectForAssets(droppedScanSelectedAssets);
1074
964
  return nextState;
@@ -1076,17 +966,13 @@ var WalletPassPaymentImpl = class {
1076
966
  if (requestSequence !== this.walletAssetsRequestSequence) {
1077
967
  return this.getWalletAssetsState();
1078
968
  }
1079
- this.paymentModule.logError(
1080
- "[WalletPass] 刷新共享钱包资产失败,保留刷新前状态",
1081
- error,
1082
- {
1083
- customer_id: businessData.customer_id,
1084
- selected_ids: selectedIds,
1085
- searched_codes: this.getSearchedWalletAssetCodes()
1086
- }
1087
- );
969
+ this.paymentModule.logError('[WalletPass] 刷新共享钱包资产失败,保留刷新前状态', error, {
970
+ customer_id: businessData.customer_id,
971
+ selected_ids: selectedIds,
972
+ searched_codes: this.getSearchedWalletAssetCodes()
973
+ });
1088
974
  return this.publishWalletAssetsState({
1089
- status: "error",
975
+ status: 'error',
1090
976
  items: preserveSelection ? this.walletAssetsState.items : committedItems,
1091
977
  selectedIds: preserveSelection ? this.walletAssetsState.selectedIds : [],
1092
978
  selectedItems: preserveSelection ? this.walletAssetsState.selectedItems : [],
@@ -1104,17 +990,19 @@ var WalletPassPaymentImpl = class {
1104
990
  selectedIds: [...this.walletAssetsState.selectedIds],
1105
991
  selectedItems: [...this.walletAssetsState.selectedItems],
1106
992
  committedIds: [...this.walletAssetsState.committedIds],
1107
- selectionSources: { ...this.walletAssetsState.selectionSources }
993
+ selectionSources: {
994
+ ...this.walletAssetsState.selectionSources
995
+ }
1108
996
  };
1109
997
  }
1110
998
  exportWalletAssetsSnapshot() {
1111
999
  return {
1112
1000
  state: this.getWalletAssetsState(),
1113
1001
  searchResults: [...this.searchResults],
1114
- pendingAutoSelectSearchCodes: [
1115
- ...this.pendingAutoSelectSearchCodes
1116
- ],
1117
- walletParams: this.walletParams ? { ...this.walletParams } : null,
1002
+ pendingAutoSelectSearchCodes: [...this.pendingAutoSelectSearchCodes],
1003
+ walletParams: this.walletParams ? {
1004
+ ...this.walletParams
1005
+ } : null,
1118
1006
  calculationContext: {
1119
1007
  orderTotalAmount: this.walletAssetsCalculationContext.orderTotalAmount,
1120
1008
  products: [...this.walletAssetsCalculationContext.products]
@@ -1122,20 +1010,16 @@ var WalletPassPaymentImpl = class {
1122
1010
  };
1123
1011
  }
1124
1012
  importWalletAssetsSnapshot(snapshot) {
1125
- var _a, _b;
1126
- if (!(snapshot == null ? void 0 : snapshot.state))
1127
- return this.getWalletAssetsState();
1013
+ if (!snapshot?.state) return this.getWalletAssetsState();
1128
1014
  this.walletAssetsRequestSequence += 1;
1129
1015
  this.searchResults = Array.isArray(snapshot.searchResults) ? [...snapshot.searchResults] : [];
1130
- this.pendingAutoSelectSearchCodes = this.walletAssetsBehavior.autoSelectAfterSearch && Array.isArray(snapshot.pendingAutoSelectSearchCodes) ? new Set(
1131
- snapshot.pendingAutoSelectSearchCodes.map(normalizeWalletAssetCode).filter(Boolean)
1132
- ) : /* @__PURE__ */ new Set();
1133
- this.walletParams = snapshot.walletParams ? { ...snapshot.walletParams } : null;
1016
+ this.pendingAutoSelectSearchCodes = this.walletAssetsBehavior.autoSelectAfterSearch && Array.isArray(snapshot.pendingAutoSelectSearchCodes) ? new Set(snapshot.pendingAutoSelectSearchCodes.map(normalizeWalletAssetCode).filter(Boolean)) : new Set();
1017
+ this.walletParams = snapshot.walletParams ? {
1018
+ ...snapshot.walletParams
1019
+ } : null;
1134
1020
  this.walletAssetsCalculationContext = {
1135
- orderTotalAmount: Number(
1136
- ((_a = snapshot.calculationContext) == null ? void 0 : _a.orderTotalAmount) || 0
1137
- ),
1138
- products: Array.isArray((_b = snapshot.calculationContext) == null ? void 0 : _b.products) ? [...snapshot.calculationContext.products] : []
1021
+ orderTotalAmount: Number(snapshot.calculationContext?.orderTotalAmount || 0),
1022
+ products: Array.isArray(snapshot.calculationContext?.products) ? [...snapshot.calculationContext.products] : []
1139
1023
  };
1140
1024
  return this.publishWalletAssetsState({
1141
1025
  ...snapshot.state,
@@ -1147,26 +1031,22 @@ var WalletPassPaymentImpl = class {
1147
1031
  });
1148
1032
  }
1149
1033
  updateWalletAssetEditAmountInCaches(assetKey, amount) {
1150
- const updateAsset = (asset) => getWalletAssetKey(asset) === assetKey ? { ...asset, edit_current_amount: amount } : asset;
1151
- this.searchResults = this.searchResults.map(
1152
- updateAsset
1153
- );
1034
+ const updateAsset = asset => getWalletAssetKey(asset) === assetKey ? {
1035
+ ...asset,
1036
+ edit_current_amount: amount
1037
+ } : asset;
1038
+ this.searchResults = this.searchResults.map(updateAsset);
1154
1039
  return this.walletAssetsState.items.map(updateAsset);
1155
1040
  }
1156
1041
  selectWalletAsset(assetId, options) {
1157
1042
  const assetKey = String(assetId);
1158
- const asset = this.walletAssetsState.items.find(
1159
- (item) => getWalletAssetKey(item) === assetKey
1160
- );
1161
- const committedKeys = new Set(
1162
- this.walletAssetsState.committedIds.map((id) => String(id))
1163
- );
1164
- if (committedKeys.has(assetKey))
1165
- return this.getWalletAssetsState();
1166
- const selectedIds = this.walletAssetsState.selectedIds.filter(
1167
- (id) => String(id) !== assetKey
1168
- );
1169
- const selectionSources = { ...this.walletAssetsState.selectionSources };
1043
+ const asset = this.walletAssetsState.items.find(item => getWalletAssetKey(item) === assetKey);
1044
+ const committedKeys = new Set(this.walletAssetsState.committedIds.map(id => String(id)));
1045
+ if (committedKeys.has(assetKey)) return this.getWalletAssetsState();
1046
+ const selectedIds = this.walletAssetsState.selectedIds.filter(id => String(id) !== assetKey);
1047
+ const selectionSources = {
1048
+ ...this.walletAssetsState.selectionSources
1049
+ };
1170
1050
  delete selectionSources[assetKey];
1171
1051
  let nextItems = this.walletAssetsState.items;
1172
1052
  if (options.selected) {
@@ -1174,87 +1054,60 @@ var WalletPassPaymentImpl = class {
1174
1054
  return this.getWalletAssetsState();
1175
1055
  }
1176
1056
  selectedIds.push(assetId);
1177
- selectionSources[assetKey] = options.source || "manual";
1057
+ selectionSources[assetKey] = options.source || 'manual';
1178
1058
  } else if (asset) {
1179
1059
  this.clearPendingAutoSelectForAsset(asset);
1180
- nextItems = this.updateWalletAssetEditAmountInCaches(
1181
- assetKey,
1182
- void 0
1183
- );
1060
+ nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, undefined);
1184
1061
  }
1185
- const nextState = this.recalculateWalletAssets(
1186
- nextItems,
1187
- selectedIds,
1188
- selectionSources
1189
- );
1190
- if (options.selected && asset && nextState.selectedIds.some((id) => String(id) === assetKey)) {
1062
+ const nextState = this.recalculateWalletAssets(nextItems, selectedIds, selectionSources);
1063
+ if (options.selected && asset && nextState.selectedIds.some(id => String(id) === assetKey)) {
1191
1064
  this.clearPendingAutoSelectForAsset(asset);
1192
1065
  }
1193
1066
  return nextState;
1194
1067
  }
1068
+
1195
1069
  /**
1196
1070
  * 更新已选资产的手动金额。只允许在当前实际抵扣额内向下调整,
1197
1071
  * 金额为 0 时沿用 legacy 行为取消选择。
1198
1072
  */
1199
1073
  updateWalletAssetAmount(assetId, amount) {
1200
1074
  const assetKey = String(assetId);
1201
- const committedKeys = new Set(
1202
- this.walletAssetsState.committedIds.map((id) => String(id))
1203
- );
1204
- const selectedKeys = new Set(
1205
- this.walletAssetsState.selectedIds.map((id) => String(id))
1206
- );
1207
- const asset = this.walletAssetsState.items.find(
1208
- (item) => getWalletAssetKey(item) === assetKey
1209
- );
1075
+ const committedKeys = new Set(this.walletAssetsState.committedIds.map(id => String(id)));
1076
+ const selectedKeys = new Set(this.walletAssetsState.selectedIds.map(id => String(id)));
1077
+ const asset = this.walletAssetsState.items.find(item => getWalletAssetKey(item) === assetKey);
1210
1078
  const requestedAmount = Number(amount);
1211
1079
  if (!asset || committedKeys.has(assetKey) || !selectedKeys.has(assetKey) || !Number.isFinite(requestedAmount) || requestedAmount < 0) {
1212
1080
  return this.getWalletAssetsState();
1213
1081
  }
1214
1082
  const selectedIds = [...this.walletAssetsState.selectedIds];
1215
- const selectionSources = { ...this.walletAssetsState.selectionSources };
1083
+ const selectionSources = {
1084
+ ...this.walletAssetsState.selectionSources
1085
+ };
1216
1086
  if (requestedAmount === 0) {
1217
- const nextItems2 = this.updateWalletAssetEditAmountInCaches(
1218
- assetKey,
1219
- void 0
1220
- );
1087
+ const nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, undefined);
1221
1088
  delete selectionSources[assetKey];
1222
1089
  this.clearPendingAutoSelectForAsset(asset);
1223
- return this.recalculateWalletAssets(
1224
- nextItems2,
1225
- selectedIds.filter((id) => String(id) !== assetKey),
1226
- selectionSources
1227
- );
1090
+ return this.recalculateWalletAssets(nextItems, selectedIds.filter(id => String(id) !== assetKey), selectionSources);
1228
1091
  }
1229
1092
  const currentDeductionAmount = getWalletAssetDeductionAmount(asset);
1230
1093
  const editAmount = Math.min(requestedAmount, currentDeductionAmount);
1231
- if (editAmount <= 0)
1232
- return this.getWalletAssetsState();
1233
- const nextItems = this.updateWalletAssetEditAmountInCaches(
1234
- assetKey,
1235
- editAmount
1236
- );
1237
- return this.recalculateWalletAssets(
1238
- nextItems,
1239
- selectedIds,
1240
- selectionSources
1241
- );
1094
+ if (editAmount <= 0) return this.getWalletAssetsState();
1095
+ const nextItems = this.updateWalletAssetEditAmountInCaches(assetKey, editAmount);
1096
+ return this.recalculateWalletAssets(nextItems, selectedIds, selectionSources);
1242
1097
  }
1243
1098
  async scanWalletAssetAsync(code) {
1244
- const normalizedCode = String(code || "").trim();
1099
+ const normalizedCode = String(code || '').trim();
1245
1100
  if (!normalizedCode) {
1246
1101
  return {
1247
- type: "normalCode",
1102
+ type: 'normalCode',
1248
1103
  selected: false,
1249
1104
  state: this.getWalletAssetsState()
1250
1105
  };
1251
1106
  }
1252
- const selectedAsset = this.walletAssetsState.selectedItems.find(
1253
- (asset2) => matchesWalletAssetCode(asset2, normalizedCode)
1254
- );
1107
+ const selectedAsset = this.walletAssetsState.selectedItems.find(asset => matchesWalletAssetCode(asset, normalizedCode));
1255
1108
  if (selectedAsset) {
1256
1109
  return {
1257
- type: "normalCode",
1110
+ type: 'normalCode',
1258
1111
  asset: selectedAsset,
1259
1112
  selected: true,
1260
1113
  state: this.getWalletAssetsState()
@@ -1262,25 +1115,16 @@ var WalletPassPaymentImpl = class {
1262
1115
  }
1263
1116
  this.walletAssetsRequestSequence += 1;
1264
1117
  const result = await this.searchIdentificationCodeAsync({
1265
- ...this.walletParams || {},
1118
+ ...(this.walletParams || {}),
1266
1119
  code: normalizedCode,
1267
- prepare_payments: this.formatWalletPassList2PreparePayments(
1268
- this.walletAssetsState.selectedItems
1269
- )
1120
+ prepare_payments: this.formatWalletPassList2PreparePayments(this.walletAssetsState.selectedItems)
1270
1121
  });
1271
- const paymentAssets = this.formatSearchedWalletPaymentAssets(
1272
- result.data.filter(isWalletPaymentAsset)
1273
- );
1122
+ const paymentAssets = this.formatSearchedWalletPaymentAssets(result.data.filter(isWalletPaymentAsset));
1274
1123
  if (paymentAssets.length > 0) {
1275
- this.searchResults = mergeWalletAssets(
1276
- this.searchResults,
1277
- paymentAssets
1278
- );
1124
+ this.searchResults = mergeWalletAssets(this.searchResults, paymentAssets);
1279
1125
  }
1280
- const asset = paymentAssets.find(
1281
- (item) => String((item == null ? void 0 : item.code) || "") === normalizedCode
1282
- ) || paymentAssets[0];
1283
- if (!asset || result.type === "walletCode") {
1126
+ const asset = paymentAssets.find(item => String(item?.code || '') === normalizedCode) || paymentAssets[0];
1127
+ if (!asset || result.type === 'walletCode') {
1284
1128
  return {
1285
1129
  type: result.type,
1286
1130
  asset,
@@ -1289,30 +1133,20 @@ var WalletPassPaymentImpl = class {
1289
1133
  };
1290
1134
  }
1291
1135
  const items = mergeWalletAssets(this.walletAssetsState.items, [asset]);
1292
- const recalculatedState = this.recalculateWalletAssets(
1293
- items,
1294
- this.walletAssetsState.selectedIds,
1295
- this.walletAssetsState.selectionSources
1296
- );
1136
+ const recalculatedState = this.recalculateWalletAssets(items, this.walletAssetsState.selectedIds, this.walletAssetsState.selectionSources);
1297
1137
  const assetId = getWalletAssetId(asset);
1298
- const recalculatedAsset = assetId === void 0 ? void 0 : recalculatedState.items.find(
1299
- (item) => getWalletAssetKey(item) === String(assetId)
1300
- );
1301
- const selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== void 0 && isWalletAssetAvailable(recalculatedAsset) ? this.selectWalletAsset(assetId, {
1138
+ const recalculatedAsset = assetId === undefined ? undefined : recalculatedState.items.find(item => getWalletAssetKey(item) === String(assetId));
1139
+ const selected = this.walletAssetsBehavior.autoSelectAfterSearch && assetId !== undefined && isWalletAssetAvailable(recalculatedAsset) ? this.selectWalletAsset(assetId, {
1302
1140
  selected: true,
1303
- source: "scan"
1141
+ source: 'scan'
1304
1142
  }) : recalculatedState;
1305
- const isSelected = assetId !== void 0 && selected.selectedIds.some((id) => String(id) === String(assetId));
1306
- const selectedStateAsset = assetId === void 0 ? void 0 : selected.items.find(
1307
- (item) => getWalletAssetKey(item) === String(assetId)
1308
- );
1143
+ const isSelected = assetId !== undefined && selected.selectedIds.some(id => String(id) === String(assetId));
1144
+ const selectedStateAsset = assetId === undefined ? undefined : selected.items.find(item => getWalletAssetKey(item) === String(assetId));
1309
1145
  const resolvedAsset = selectedStateAsset || recalculatedAsset || asset;
1310
1146
  if (isSelected) {
1311
1147
  this.clearPendingAutoSelectForAsset(resolvedAsset);
1312
1148
  } else if (this.walletAssetsBehavior.autoSelectAfterSearch) {
1313
- this.pendingAutoSelectSearchCodes.add(
1314
- normalizeWalletAssetCode(normalizedCode)
1315
- );
1149
+ this.pendingAutoSelectSearchCodes.add(normalizeWalletAssetCode(normalizedCode));
1316
1150
  this.queuePendingAutoSelectForAssets([resolvedAsset]);
1317
1151
  }
1318
1152
  return {
@@ -1324,58 +1158,41 @@ var WalletPassPaymentImpl = class {
1324
1158
  }
1325
1159
  clearWalletAssetSelection() {
1326
1160
  this.pendingAutoSelectSearchCodes.clear();
1327
- const selectedKeys = new Set(
1328
- this.walletAssetsState.selectedIds.map((id) => String(id))
1329
- );
1330
- const clearSelectedEditAmount = (asset) => selectedKeys.has(getWalletAssetKey(asset)) ? { ...asset, edit_current_amount: void 0 } : asset;
1331
- this.searchResults = this.searchResults.map(
1332
- clearSelectedEditAmount
1333
- );
1334
- return this.recalculateWalletAssets(
1335
- this.walletAssetsState.items.map(clearSelectedEditAmount),
1336
- [],
1337
- {}
1338
- );
1161
+ const selectedKeys = new Set(this.walletAssetsState.selectedIds.map(id => String(id)));
1162
+ const clearSelectedEditAmount = asset => selectedKeys.has(getWalletAssetKey(asset)) ? {
1163
+ ...asset,
1164
+ edit_current_amount: undefined
1165
+ } : asset;
1166
+ this.searchResults = this.searchResults.map(clearSelectedEditAmount);
1167
+ return this.recalculateWalletAssets(this.walletAssetsState.items.map(clearSelectedEditAmount), [], {});
1339
1168
  }
1340
1169
  setCommittedWalletAssets(committedIds, committedAssets = []) {
1341
- const committedKeys = new Set(committedIds.map((id) => String(id)));
1342
- const selectedIds = this.walletAssetsState.selectedIds.filter(
1343
- (id) => !committedKeys.has(String(id))
1344
- );
1345
- const selectionSources = Object.entries(
1346
- this.walletAssetsState.selectionSources
1347
- ).reduce(
1348
- (result, [key, source]) => {
1349
- if (!committedKeys.has(key))
1350
- result[key] = source;
1351
- return result;
1352
- },
1353
- {}
1354
- );
1170
+ const committedKeys = new Set(committedIds.map(id => String(id)));
1171
+ const selectedIds = this.walletAssetsState.selectedIds.filter(id => !committedKeys.has(String(id)));
1172
+ const selectionSources = Object.entries(this.walletAssetsState.selectionSources).reduce((result, [key, source]) => {
1173
+ if (!committedKeys.has(key)) result[key] = source;
1174
+ return result;
1175
+ }, {});
1355
1176
  this.publishWalletAssetsState({
1356
1177
  items: mergeWalletAssets(this.walletAssetsState.items, committedAssets),
1357
1178
  committedIds
1358
1179
  });
1359
- return this.recalculateWalletAssets(
1360
- this.walletAssetsState.items,
1361
- selectedIds,
1362
- selectionSources
1363
- );
1180
+ return this.recalculateWalletAssets(this.walletAssetsState.items, selectedIds, selectionSources);
1364
1181
  }
1365
1182
  async processWalletPayment(amount, orderUuid, voucherId) {
1366
- this.paymentModule.logInfo("[WalletPass] 开始处理钱包支付", {
1367
- amount,
1368
- orderUuid,
1369
- voucherId: voucherId || "none"
1183
+ this.paymentModule.logInfo('[WalletPass] 开始处理钱包支付', {
1184
+ amount: amount,
1185
+ orderUuid: orderUuid,
1186
+ voucherId: voucherId || 'none'
1370
1187
  });
1371
1188
  const walletMethod = await this.paymentModule.getWalletPaymentMethod();
1372
1189
  if (!walletMethod) {
1373
- this.paymentModule.logError("[WalletPass] 钱包支付方式未找到", null, {
1374
- amount,
1375
- orderUuid,
1376
- voucherId
1190
+ this.paymentModule.logError('[WalletPass] 钱包支付方式未找到', null, {
1191
+ amount: amount,
1192
+ orderUuid: orderUuid,
1193
+ voucherId: voucherId
1377
1194
  });
1378
- throw new Error("钱包支付方式未找到");
1195
+ throw new Error('钱包支付方式未找到');
1379
1196
  }
1380
1197
  const paymentItem = {
1381
1198
  amount: amount.toString(),
@@ -1383,84 +1200,99 @@ var WalletPassPaymentImpl = class {
1383
1200
  custom_payment_id: walletMethod.id,
1384
1201
  name: walletMethod.name,
1385
1202
  type: walletMethod.type,
1386
- voucher_id: voucherId || ""
1203
+ voucher_id: voucherId || ''
1387
1204
  };
1388
1205
  await this.paymentModule.addPaymentItemAsync(orderUuid, paymentItem);
1389
- this.paymentModule.logInfo("[WalletPass] 钱包支付处理完成", {
1390
- amount,
1391
- orderUuid,
1392
- voucherId: voucherId || "none",
1206
+ this.paymentModule.logInfo('[WalletPass] 钱包支付处理完成', {
1207
+ amount: amount,
1208
+ orderUuid: orderUuid,
1209
+ voucherId: voucherId || 'none',
1393
1210
  payment_method: walletMethod.name
1394
1211
  });
1395
1212
  }
1396
1213
  async getWalletBalance(voucherId) {
1214
+ // 获取钱包余额的逻辑
1397
1215
  return 0;
1398
1216
  }
1217
+
1399
1218
  /**
1400
1219
  * 获取缓存的钱包推荐列表
1401
1220
  */
1402
1221
  getWalletRecommendList() {
1403
1222
  return this.walletRecommendList;
1404
1223
  }
1224
+
1405
1225
  /**
1406
1226
  * 获取缓存的用户识别码列表
1407
1227
  */
1408
1228
  getUserIdentificationCodes() {
1409
1229
  return this.userIdentificationCodes;
1410
1230
  }
1231
+
1411
1232
  /**
1412
1233
  * 清除钱包推荐列表
1413
1234
  */
1414
1235
  clearWalletRecommendList() {
1415
1236
  this.walletRecommendList = [];
1416
- this.emitEvent(import_types.WalletPassHooks.OnWalletRecommendListCleared, {
1417
- clearedTypes: ["walletRecommendList"]
1237
+
1238
+ // 发送钱包推荐列表清除事件
1239
+ this.emitEvent(_types.WalletPassHooks.OnWalletRecommendListCleared, {
1240
+ clearedTypes: ['walletRecommendList']
1418
1241
  });
1419
- this.paymentModule.logInfo("[WalletPass] 钱包推荐列表已清除");
1242
+ this.paymentModule.logInfo('[WalletPass] 钱包推荐列表已清除');
1420
1243
  }
1244
+
1421
1245
  /**
1422
1246
  * 清除用户识别码列表
1423
1247
  */
1424
1248
  clearUserIdentificationCodes() {
1425
1249
  this.userIdentificationCodes = [];
1426
- this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesCleared, {
1427
- clearedTypes: ["userIdentificationCodes"]
1250
+
1251
+ // 发送用户识别码列表清除事件
1252
+ this.emitEvent(_types.WalletPassHooks.OnUserIdentificationCodesCleared, {
1253
+ clearedTypes: ['userIdentificationCodes']
1428
1254
  });
1429
- this.paymentModule.logInfo("[WalletPass] 用户识别码列表已清除");
1255
+ this.paymentModule.logInfo('[WalletPass] 用户识别码列表已清除');
1430
1256
  }
1257
+
1431
1258
  /**
1432
1259
  * 获取缓存的搜索结果列表
1433
1260
  */
1434
1261
  getSearchResults() {
1435
1262
  return this.searchResults;
1436
1263
  }
1264
+
1437
1265
  /**
1438
1266
  * 根据识别码查找搜索结果
1439
1267
  */
1440
1268
  findSearchResultByCode(code) {
1441
- return this.searchResults.find((item) => item.code === code);
1269
+ return this.searchResults.find(item => item.code === code);
1442
1270
  }
1271
+
1443
1272
  /**
1444
1273
  * 清除搜索结果缓存
1445
1274
  */
1446
1275
  clearSearchResults() {
1447
1276
  this.searchResults = [];
1448
1277
  this.pendingAutoSelectSearchCodes.clear();
1449
- this.paymentModule.logInfo("[WalletPass] 搜索结果缓存已清除");
1278
+ this.paymentModule.logInfo('[WalletPass] 搜索结果缓存已清除');
1450
1279
  }
1280
+
1451
1281
  /**
1452
1282
  * 获取存储的钱包初始化数据
1453
1283
  */
1454
1284
  getStoredWalletInitData() {
1455
1285
  return this.walletInitData;
1456
1286
  }
1287
+
1457
1288
  /**
1458
1289
  * 清除存储的钱包初始化数据
1459
1290
  */
1460
1291
  clearStoredWalletInitData() {
1461
1292
  this.walletInitData = null;
1462
- this.paymentModule.logInfo("[WalletPass] 钱包初始化数据已清除");
1293
+ this.paymentModule.logInfo('[WalletPass] 钱包初始化数据已清除');
1463
1294
  }
1295
+
1464
1296
  /**
1465
1297
  * 清除所有缓存数据
1466
1298
  */
@@ -1478,21 +1310,14 @@ var WalletPassPaymentImpl = class {
1478
1310
  };
1479
1311
  this.walletAssetsState = createInitialWalletAssetsState();
1480
1312
  this.publishWalletAssetsState({});
1481
- this.emitEvent(import_types.WalletPassHooks.OnWalletCacheCleared, {
1482
- clearedTypes: ["all"]
1313
+
1314
+ // 发送所有缓存清除事件
1315
+ this.emitEvent(_types.WalletPassHooks.OnWalletCacheCleared, {
1316
+ clearedTypes: ['all']
1483
1317
  });
1484
- this.paymentModule.logInfo("[WalletPass] 所有缓存数据已清除", {
1485
- cleared_types: [
1486
- "walletRecommendList",
1487
- "userIdentificationCodes",
1488
- "searchResults",
1489
- "walletParams",
1490
- "walletInitData"
1491
- ]
1318
+ this.paymentModule.logInfo('[WalletPass] 所有缓存数据已清除', {
1319
+ cleared_types: ['walletRecommendList', 'userIdentificationCodes', 'searchResults', 'walletParams', 'walletInitData']
1492
1320
  });
1493
1321
  }
1494
- };
1495
- // Annotate the CommonJS export names for ESM import in node:
1496
- 0 && (module.exports = {
1497
- WalletPassPaymentImpl
1498
- });
1322
+ }
1323
+ exports.WalletPassPaymentImpl = WalletPassPaymentImpl;