@pisell/pisellos 2.2.309 → 2.2.310

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 (121) hide show
  1. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  3. package/dist/modules/BookingContext/index.js +4 -4
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  6. package/dist/modules/Customer/index.js +6 -3
  7. package/dist/modules/Customer/types.d.ts +2 -0
  8. package/dist/modules/Discount/availability.d.ts +7 -0
  9. package/dist/modules/Discount/availability.js +49 -0
  10. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  11. package/dist/modules/Discount/entitlementPass.js +147 -0
  12. package/dist/modules/Discount/index.d.ts +2 -2
  13. package/dist/modules/Discount/index.js +37 -151
  14. package/dist/modules/Discount/types.d.ts +36 -5
  15. package/dist/modules/OpenData/index.d.ts +1 -1
  16. package/dist/modules/OpenData/index.js +21 -12
  17. package/dist/modules/Order/index.d.ts +32 -4
  18. package/dist/modules/Order/index.js +733 -373
  19. package/dist/modules/Order/types.d.ts +17 -0
  20. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  21. package/dist/modules/Order/utils.d.ts +14 -2
  22. package/dist/modules/Order/utils.js +275 -76
  23. package/dist/modules/Payment/index.d.ts +0 -5
  24. package/dist/modules/Payment/index.js +35 -85
  25. package/dist/modules/Payment/types.d.ts +21 -1
  26. package/dist/modules/Payment/types.js +2 -0
  27. package/dist/modules/Payment/walletpass.d.ts +1 -1
  28. package/dist/modules/Payment/walletpass.js +80 -47
  29. package/dist/modules/ProductList/index.js +18 -5
  30. package/dist/modules/Rules/index.d.ts +2 -2
  31. package/dist/modules/Rules/index.js +480 -186
  32. package/dist/modules/Rules/types.d.ts +4 -0
  33. package/dist/server/index.js +8 -5
  34. package/dist/server/modules/order/index.js +6 -0
  35. package/dist/server/modules/order/types.d.ts +12 -0
  36. package/dist/server/modules/payment/index.d.ts +25 -6
  37. package/dist/server/modules/payment/index.js +660 -133
  38. package/dist/server/utils/small-ticket.d.ts +8 -5
  39. package/dist/server/utils/small-ticket.js +1269 -199
  40. package/dist/solution/BaseSales/index.d.ts +11 -2
  41. package/dist/solution/BaseSales/index.js +1463 -1173
  42. package/dist/solution/BaseSales/types.d.ts +7 -3
  43. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  44. package/dist/solution/BookingByStep/index.d.ts +1 -1
  45. package/dist/solution/BookingTicket/index.d.ts +12 -3
  46. package/dist/solution/BookingTicket/index.js +663 -542
  47. package/dist/solution/BookingTicket/types.d.ts +5 -1
  48. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  50. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  51. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  52. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  53. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  54. package/dist/solution/ShopDiscount/index.js +99 -42
  55. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  56. package/dist/solution/ShopDiscount/utils.js +43 -23
  57. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
  58. package/dist/solution/UnifiedBookingSales/index.js +5 -5
  59. package/dist/utils/os-private-payload.d.ts +5 -0
  60. package/dist/utils/os-private-payload.js +17 -0
  61. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  62. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  63. package/lib/modules/BookingContext/index.js +3 -3
  64. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  65. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  66. package/lib/modules/Customer/index.js +5 -1
  67. package/lib/modules/Customer/types.d.ts +2 -0
  68. package/lib/modules/Discount/availability.d.ts +7 -0
  69. package/lib/modules/Discount/availability.js +43 -0
  70. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  71. package/lib/modules/Discount/entitlementPass.js +141 -0
  72. package/lib/modules/Discount/index.d.ts +2 -2
  73. package/lib/modules/Discount/index.js +23 -129
  74. package/lib/modules/Discount/types.d.ts +36 -5
  75. package/lib/modules/OpenData/index.d.ts +1 -1
  76. package/lib/modules/OpenData/index.js +11 -2
  77. package/lib/modules/Order/index.d.ts +32 -4
  78. package/lib/modules/Order/index.js +341 -71
  79. package/lib/modules/Order/types.d.ts +17 -0
  80. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  81. package/lib/modules/Order/utils.d.ts +14 -2
  82. package/lib/modules/Order/utils.js +186 -3
  83. package/lib/modules/Payment/index.d.ts +0 -5
  84. package/lib/modules/Payment/index.js +3 -28
  85. package/lib/modules/Payment/types.d.ts +21 -1
  86. package/lib/modules/Payment/types.js +1 -0
  87. package/lib/modules/Payment/walletpass.d.ts +1 -1
  88. package/lib/modules/Payment/walletpass.js +29 -9
  89. package/lib/modules/ProductList/index.js +14 -1
  90. package/lib/modules/Rules/index.d.ts +2 -2
  91. package/lib/modules/Rules/index.js +357 -110
  92. package/lib/modules/Rules/types.d.ts +4 -0
  93. package/lib/server/index.js +8 -5
  94. package/lib/server/modules/order/index.js +6 -0
  95. package/lib/server/modules/order/types.d.ts +12 -0
  96. package/lib/server/modules/payment/index.d.ts +25 -6
  97. package/lib/server/modules/payment/index.js +350 -78
  98. package/lib/server/utils/small-ticket.d.ts +8 -5
  99. package/lib/server/utils/small-ticket.js +1009 -121
  100. package/lib/solution/BaseSales/index.d.ts +11 -2
  101. package/lib/solution/BaseSales/index.js +164 -30
  102. package/lib/solution/BaseSales/types.d.ts +7 -3
  103. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  104. package/lib/solution/BookingByStep/index.d.ts +1 -1
  105. package/lib/solution/BookingTicket/index.d.ts +12 -3
  106. package/lib/solution/BookingTicket/index.js +103 -41
  107. package/lib/solution/BookingTicket/types.d.ts +5 -1
  108. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  109. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  110. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  111. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  112. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  113. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  114. package/lib/solution/ShopDiscount/index.js +55 -9
  115. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  116. package/lib/solution/ShopDiscount/utils.js +42 -25
  117. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
  118. package/lib/solution/UnifiedBookingSales/index.js +5 -5
  119. package/lib/utils/os-private-payload.d.ts +5 -0
  120. package/lib/utils/os-private-payload.js +22 -0
  121. package/package.json +1 -1
@@ -11,10 +11,24 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
11
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
13
  import { buildRequiresDetailPayload } from "../addProductDecision";
14
- import { isWalkInCustomer } from "../cartView";
15
14
  import { countScanVariantMatches, genScanProductValues, isScanProductBundle, isScanProductOption } from "./scanProductValues";
16
15
 
17
16
  /** applyGlobalScan 所需的 BookingTicket 运行时能力 */
17
+
18
+ function getRealCustomerId(customer) {
19
+ var _customer$id;
20
+ var customerId = Number((_customer$id = customer === null || customer === void 0 ? void 0 : customer.id) !== null && _customer$id !== void 0 ? _customer$id : customer === null || customer === void 0 ? void 0 : customer.customer_id);
21
+ return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
22
+ }
23
+ function getWalletAssetCustomerId(asset) {
24
+ var _asset$customer_id, _asset$holder;
25
+ var customerId = Number((_asset$customer_id = asset === null || asset === void 0 ? void 0 : asset.customer_id) !== null && _asset$customer_id !== void 0 ? _asset$customer_id : asset === null || asset === void 0 || (_asset$holder = asset.holder) === null || _asset$holder === void 0 ? void 0 : _asset$holder.customer_id);
26
+ return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
27
+ }
28
+ function getErrorMessage(error) {
29
+ return error instanceof Error ? error.message : String(error || '');
30
+ }
31
+
18
32
  /**
19
33
  * 处理单条扫码商品的加车决策(含弹窗链)。
20
34
  */
@@ -191,300 +205,477 @@ export function applyGlobalScan(_x14, _x15, _x16) {
191
205
  return _applyGlobalScan.apply(this, arguments);
192
206
  }
193
207
  function _applyGlobalScan() {
194
- _applyGlobalScan = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(host, formatted, bridge) {
195
- var searchType, data, scanCode, _bridge$onNotify2, _bridge$onNotify, _host$refreshWalletAs, _bridge$onNotify5, snapshot, scannedCustomerIsWalkIn, trySelectWalletAsset, _result$isAccepted, _walletSelection, result, walletSelection, _data$id, _promotionResult$isAc, promotionResult, list, _bridge$onNotify6, addedCount, _iterator, _step, _item, outcome, _bridge$onNotify7, _data$order_id, _data$business_code, orderId, _bridge$onNotify8;
196
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
197
- while (1) switch (_context5.prev = _context5.next) {
208
+ _applyGlobalScan = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(host, formatted, bridge) {
209
+ var searchType, data, scanCode, formattedCustomerId, isCrossShopWallet, isWalletPassUnavailableAtStore, _getRealCustomerId, _bridge$onNotify5, currentCustomer, currentCustomerId, _customer, sourceCustomerId, _bridge$onNotify, _bridge$onNotify2, _customerId, _bridge$onNotify3, orderCustomer, switched, _bridge$onNotify4, _promotionResult$isAc, _bridge$onNotify6, snapshot, activeCustomer, bindWalletPassCustomer, trySelectWalletAsset, bindResult, walletSelection, promotionCustomerId, promotionResult, list, _bridge$onNotify12, addedCount, _iterator, _step, _item, outcome, _bridge$onNotify13, _data$order_id, _data$business_code, orderId, _bridge$onNotify14;
210
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
211
+ while (1) switch (_context6.prev = _context6.next) {
198
212
  case 0:
199
- searchType = formatted.searchType, data = formatted.data, scanCode = formatted.scanCode;
213
+ searchType = formatted.searchType, data = formatted.data, scanCode = formatted.scanCode, formattedCustomerId = formatted.customerId, isCrossShopWallet = formatted.isCrossShopWallet, isWalletPassUnavailableAtStore = formatted.isWalletPassUnavailableAtStore;
200
214
  if (!(searchType === 'wallet')) {
201
- _context5.next = 8;
215
+ _context6.next = 44;
216
+ break;
217
+ }
218
+ currentCustomer = host.getOrderCustomerSnapshot();
219
+ currentCustomerId = getRealCustomerId(currentCustomer);
220
+ _customer = data;
221
+ if (!isCrossShopWallet) {
222
+ _context6.next = 20;
202
223
  break;
203
224
  }
204
- if (data) {
205
- _context5.next = 5;
225
+ sourceCustomerId = getRealCustomerId({
226
+ id: formattedCustomerId
227
+ });
228
+ if (!(sourceCustomerId === undefined || !host.resolveCustomerById)) {
229
+ _context6.next = 10;
206
230
  break;
207
231
  }
208
232
  bridge === null || bridge === void 0 || (_bridge$onNotify = bridge.onNotify) === null || _bridge$onNotify === void 0 || _bridge$onNotify.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
209
- return _context5.abrupt("return", {
233
+ return _context6.abrupt("return", {
210
234
  status: 'failed',
211
235
  reason: 'invalid_data'
212
236
  });
213
- case 5:
214
- host.setOrderCustomer(data);
215
- bridge === null || bridge === void 0 || (_bridge$onNotify2 = bridge.onNotify) === null || _bridge$onNotify2 === void 0 || _bridge$onNotify2.call(bridge, 'success', 'pisell2.text.add-client-success');
216
- return _context5.abrupt("return", {
237
+ case 10:
238
+ _context6.prev = 10;
239
+ _context6.next = 13;
240
+ return host.resolveCustomerById(sourceCustomerId);
241
+ case 13:
242
+ _customer = _context6.sent;
243
+ _context6.next = 20;
244
+ break;
245
+ case 16:
246
+ _context6.prev = 16;
247
+ _context6.t0 = _context6["catch"](10);
248
+ bridge === null || bridge === void 0 || (_bridge$onNotify2 = bridge.onNotify) === null || _bridge$onNotify2 === void 0 || _bridge$onNotify2.call(bridge, 'fail', getErrorMessage(_context6.t0) || 'pisell2.text.scan-global-failed');
249
+ return _context6.abrupt("return", {
250
+ status: 'failed',
251
+ reason: 'invalid_data'
252
+ });
253
+ case 20:
254
+ _customerId = (_getRealCustomerId = getRealCustomerId(_customer)) !== null && _getRealCustomerId !== void 0 ? _getRealCustomerId : !isCrossShopWallet ? getRealCustomerId({
255
+ id: formattedCustomerId
256
+ }) : undefined;
257
+ if (!(!_customer || _customerId === undefined)) {
258
+ _context6.next = 24;
259
+ break;
260
+ }
261
+ bridge === null || bridge === void 0 || (_bridge$onNotify3 = bridge.onNotify) === null || _bridge$onNotify3 === void 0 || _bridge$onNotify3.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
262
+ return _context6.abrupt("return", {
263
+ status: 'failed',
264
+ reason: 'invalid_data'
265
+ });
266
+ case 24:
267
+ orderCustomer = _customer.id === undefined || _customer.id === null ? _objectSpread(_objectSpread({}, _customer), {}, {
268
+ id: _customerId
269
+ }) : _customer;
270
+ if (!(currentCustomerId === _customerId)) {
271
+ _context6.next = 27;
272
+ break;
273
+ }
274
+ return _context6.abrupt("return", {
217
275
  status: 'success',
218
276
  kind: 'customer'
219
277
  });
220
- case 8:
278
+ case 27:
279
+ if (!(currentCustomerId !== undefined)) {
280
+ _context6.next = 41;
281
+ break;
282
+ }
283
+ if (bridge !== null && bridge !== void 0 && bridge.requestCustomerSwitch) {
284
+ _context6.next = 30;
285
+ break;
286
+ }
287
+ return _context6.abrupt("return", {
288
+ status: 'success',
289
+ kind: 'customer'
290
+ });
291
+ case 30:
292
+ _context6.prev = 30;
293
+ _context6.next = 33;
294
+ return bridge.requestCustomerSwitch(orderCustomer);
295
+ case 33:
296
+ switched = _context6.sent;
297
+ return _context6.abrupt("return", switched ? {
298
+ status: 'success',
299
+ kind: 'customer'
300
+ } : {
301
+ status: 'cancelled'
302
+ });
303
+ case 37:
304
+ _context6.prev = 37;
305
+ _context6.t1 = _context6["catch"](30);
306
+ (_bridge$onNotify4 = bridge.onNotify) === null || _bridge$onNotify4 === void 0 || _bridge$onNotify4.call(bridge, 'fail', getErrorMessage(_context6.t1) || 'pisell2.text.scan-global-failed');
307
+ return _context6.abrupt("return", {
308
+ status: 'failed',
309
+ reason: 'invalid_data'
310
+ });
311
+ case 41:
312
+ host.setOrderCustomer(orderCustomer);
313
+ bridge === null || bridge === void 0 || (_bridge$onNotify5 = bridge.onNotify) === null || _bridge$onNotify5 === void 0 || _bridge$onNotify5.call(bridge, 'success', 'pisell2.text.add-client-success');
314
+ return _context6.abrupt("return", {
315
+ status: 'success',
316
+ kind: 'customer'
317
+ });
318
+ case 44:
221
319
  if (!(searchType === 'walletPass')) {
222
- _context5.next = 42;
320
+ _context6.next = 78;
321
+ break;
322
+ }
323
+ if (!isWalletPassUnavailableAtStore) {
324
+ _context6.next = 48;
223
325
  break;
224
326
  }
327
+ bridge === null || bridge === void 0 || (_bridge$onNotify6 = bridge.onNotify) === null || _bridge$onNotify6 === void 0 || _bridge$onNotify6.call(bridge, 'fail', 'pisell2.text.wallet-pass-not-available-at-store');
328
+ return _context6.abrupt("return", {
329
+ status: 'failed',
330
+ reason: 'invalid_data'
331
+ });
332
+ case 48:
225
333
  snapshot = host.getOrderCustomerSnapshot();
226
- scannedCustomerIsWalkIn = isWalkInCustomer(data);
227
- trySelectWalletAsset = /*#__PURE__*/function () {
228
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
229
- var _bridge$onNotify4;
230
- var walletResult, _bridge$onNotify3;
334
+ activeCustomer = snapshot;
335
+ bindWalletPassCustomer = /*#__PURE__*/function () {
336
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(asset) {
337
+ var _getWalletAssetCustom, _host$refreshWalletAs;
338
+ var assetCustomerId, customer, _bridge$onNotify7, _bridge$onNotify8, customerId, _bridge$onNotify9, orderCustomer;
231
339
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
232
340
  while (1) switch (_context4.prev = _context4.next) {
233
341
  case 0:
234
- if (host.scanWalletAsset) {
342
+ if (!(getRealCustomerId(activeCustomer) !== undefined)) {
235
343
  _context4.next = 2;
236
344
  break;
237
345
  }
238
- return _context4.abrupt("return", null);
346
+ return _context4.abrupt("return", {
347
+ resolveFailed: false,
348
+ customerBound: false
349
+ });
350
+ case 2:
351
+ assetCustomerId = (_getWalletAssetCustom = getWalletAssetCustomerId(asset)) !== null && _getWalletAssetCustom !== void 0 ? _getWalletAssetCustom : getRealCustomerId({
352
+ id: formattedCustomerId
353
+ });
354
+ customer = null;
355
+ if (!(assetCustomerId !== undefined)) {
356
+ _context4.next = 19;
357
+ break;
358
+ }
359
+ if (host.resolveCustomerById) {
360
+ _context4.next = 8;
361
+ break;
362
+ }
363
+ bridge === null || bridge === void 0 || (_bridge$onNotify7 = bridge.onNotify) === null || _bridge$onNotify7 === void 0 || _bridge$onNotify7.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
364
+ return _context4.abrupt("return", {
365
+ resolveFailed: true,
366
+ customerBound: false
367
+ });
368
+ case 8:
369
+ _context4.prev = 8;
370
+ _context4.next = 11;
371
+ return host.resolveCustomerById(assetCustomerId);
372
+ case 11:
373
+ customer = _context4.sent;
374
+ _context4.next = 19;
375
+ break;
376
+ case 14:
377
+ _context4.prev = 14;
378
+ _context4.t0 = _context4["catch"](8);
379
+ console.warn('[GlobalScan] Wallet asset customer lookup failed', _context4.t0);
380
+ bridge === null || bridge === void 0 || (_bridge$onNotify8 = bridge.onNotify) === null || _bridge$onNotify8 === void 0 || _bridge$onNotify8.call(bridge, 'fail', getErrorMessage(_context4.t0) || 'pisell2.text.scan-global-failed');
381
+ return _context4.abrupt("return", {
382
+ resolveFailed: true,
383
+ customerBound: false
384
+ });
385
+ case 19:
386
+ customerId = getRealCustomerId(customer);
387
+ if (!(!customer || customerId === undefined)) {
388
+ _context4.next = 23;
389
+ break;
390
+ }
391
+ if (assetCustomerId !== undefined) {
392
+ bridge === null || bridge === void 0 || (_bridge$onNotify9 = bridge.onNotify) === null || _bridge$onNotify9 === void 0 || _bridge$onNotify9.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
393
+ }
394
+ return _context4.abrupt("return", {
395
+ resolveFailed: assetCustomerId !== undefined,
396
+ customerBound: false
397
+ });
398
+ case 23:
399
+ orderCustomer = customer.id === undefined || customer.id === null ? _objectSpread(_objectSpread({}, customer), {}, {
400
+ id: customerId
401
+ }) : customer;
402
+ host.setOrderCustomer(orderCustomer);
403
+ activeCustomer = orderCustomer;
404
+ _context4.next = 28;
405
+ return (_host$refreshWalletAs = host.refreshWalletAssets) === null || _host$refreshWalletAs === void 0 ? void 0 : _host$refreshWalletAs.call(host, {
406
+ preserveSelection: false,
407
+ retainSearchResultCodes: [scanCode]
408
+ });
409
+ case 28:
410
+ return _context4.abrupt("return", {
411
+ resolveFailed: false,
412
+ customerBound: true
413
+ });
414
+ case 29:
415
+ case "end":
416
+ return _context4.stop();
417
+ }
418
+ }, _callee4, null, [[8, 14]]);
419
+ }));
420
+ return function bindWalletPassCustomer(_x17) {
421
+ return _ref2.apply(this, arguments);
422
+ };
423
+ }();
424
+ trySelectWalletAsset = /*#__PURE__*/function () {
425
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
426
+ var walletResult, bindResult, _bridge$onNotify10, _bridge$onNotify11;
427
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
428
+ while (1) switch (_context5.prev = _context5.next) {
429
+ case 0:
430
+ if (host.scanWalletAsset) {
431
+ _context5.next = 2;
432
+ break;
433
+ }
434
+ return _context5.abrupt("return", null);
239
435
  case 2:
240
- _context4.next = 4;
436
+ _context5.next = 4;
241
437
  return host.scanWalletAsset(scanCode).catch(function (error) {
242
438
  console.warn('[GlobalScan] Wallet asset lookup failed', error);
243
439
  return null;
244
440
  });
245
441
  case 4:
246
- walletResult = _context4.sent;
442
+ walletResult = _context5.sent;
247
443
  if (walletResult) {
248
- _context4.next = 7;
444
+ _context5.next = 7;
249
445
  break;
250
446
  }
251
- return _context4.abrupt("return", null);
447
+ return _context5.abrupt("return", null);
252
448
  case 7:
253
449
  if (!(walletResult.type !== 'normalCode' || !walletResult.asset)) {
254
- _context4.next = 9;
450
+ _context5.next = 9;
255
451
  break;
256
452
  }
257
- return _context4.abrupt("return", null);
453
+ return _context5.abrupt("return", null);
258
454
  case 9:
455
+ _context5.next = 11;
456
+ return bindWalletPassCustomer(walletResult.asset);
457
+ case 11:
458
+ bindResult = _context5.sent;
259
459
  if (!walletResult.selected) {
260
- _context4.next = 12;
460
+ _context5.next = 15;
261
461
  break;
262
462
  }
263
- bridge === null || bridge === void 0 || (_bridge$onNotify3 = bridge.onNotify) === null || _bridge$onNotify3 === void 0 || _bridge$onNotify3.call(bridge, 'success');
264
- return _context4.abrupt("return", {
463
+ if (!bindResult.resolveFailed) {
464
+ bridge === null || bridge === void 0 || (_bridge$onNotify10 = bridge.onNotify) === null || _bridge$onNotify10 === void 0 || _bridge$onNotify10.call(bridge, 'success');
465
+ }
466
+ return _context5.abrupt("return", {
265
467
  status: 'success',
266
468
  kind: 'promotion'
267
469
  });
268
- case 12:
470
+ case 15:
269
471
  // 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
270
- bridge === null || bridge === void 0 || (_bridge$onNotify4 = bridge.onNotify) === null || _bridge$onNotify4 === void 0 || _bridge$onNotify4.call(bridge, 'fail', 'pisell2.text.goodpass.code-invalid-cart');
271
- return _context4.abrupt("return", {
472
+ if (!bindResult.resolveFailed) {
473
+ bridge === null || bridge === void 0 || (_bridge$onNotify11 = bridge.onNotify) === null || _bridge$onNotify11 === void 0 || _bridge$onNotify11.call(bridge, 'fail', 'pisell2.text.goodpass.code-invalid-cart');
474
+ }
475
+ return _context5.abrupt("return", {
272
476
  status: 'failed',
273
477
  reason: 'invalid_data'
274
478
  });
275
- case 14:
479
+ case 17:
276
480
  case "end":
277
- return _context4.stop();
481
+ return _context5.stop();
278
482
  }
279
- }, _callee4);
483
+ }, _callee5);
280
484
  }));
281
485
  return function trySelectWalletAsset() {
282
- return _ref2.apply(this, arguments);
486
+ return _ref3.apply(this, arguments);
283
487
  };
284
- }();
285
- if (!(isWalkInCustomer(snapshot) || scannedCustomerIsWalkIn)) {
286
- _context5.next = 26;
287
- break;
288
- }
289
- _context5.next = 15;
488
+ }(); // batch-search 可能返回来源门店客户;先映射到当前门店,确保 Wallet
489
+ // 支付资产查询使用本店客户上下文。
490
+ _context6.next = 54;
491
+ return bindWalletPassCustomer();
492
+ case 54:
493
+ bindResult = _context6.sent;
494
+ _context6.next = 57;
290
495
  return trySelectWalletAsset();
291
- case 15:
292
- _walletSelection = _context5.sent;
293
- if (!_walletSelection) {
294
- _context5.next = 18;
496
+ case 57:
497
+ walletSelection = _context6.sent;
498
+ if (!walletSelection) {
499
+ _context6.next = 60;
295
500
  break;
296
501
  }
297
- return _context5.abrupt("return", _walletSelection);
298
- case 18:
502
+ return _context6.abrupt("return", walletSelection);
503
+ case 60:
299
504
  if (bridge !== null && bridge !== void 0 && bridge.applyPromotionCode) {
300
- _context5.next = 20;
505
+ _context6.next = 62;
301
506
  break;
302
507
  }
303
- return _context5.abrupt("return", {
508
+ return _context6.abrupt("return", {
304
509
  status: 'failed',
305
510
  reason: 'no_bridge'
306
511
  });
307
- case 20:
308
- _context5.next = 22;
309
- return bridge.applyPromotionCode(scanCode);
310
- case 22:
311
- result = _context5.sent;
312
- if (!((_result$isAccepted = result === null || result === void 0 ? void 0 : result.isAccepted) !== null && _result$isAccepted !== void 0 ? _result$isAccepted : result === null || result === void 0 ? void 0 : result.isAvailable)) {
313
- _context5.next = 25;
512
+ case 62:
513
+ promotionCustomerId = getRealCustomerId(activeCustomer);
514
+ if (!bindResult.customerBound) {
515
+ _context6.next = 69;
314
516
  break;
315
517
  }
316
- return _context5.abrupt("return", {
317
- status: 'success',
318
- kind: 'promotion'
518
+ _context6.next = 66;
519
+ return bridge.applyPromotionCode(scanCode, promotionCustomerId, {
520
+ suppressFailureNotification: true
319
521
  });
320
- case 25:
321
- return _context5.abrupt("return", {
322
- status: 'failed',
323
- reason: 'invalid_data'
324
- });
325
- case 26:
326
- host.setOrderCustomer(data);
327
- _context5.next = 29;
328
- return (_host$refreshWalletAs = host.refreshWalletAssets) === null || _host$refreshWalletAs === void 0 ? void 0 : _host$refreshWalletAs.call(host, {
329
- preserveSelection: false
330
- });
331
- case 29:
332
- _context5.next = 31;
333
- return trySelectWalletAsset();
334
- case 31:
335
- walletSelection = _context5.sent;
336
- if (!walletSelection) {
337
- _context5.next = 34;
338
- break;
339
- }
340
- return _context5.abrupt("return", walletSelection);
341
- case 34:
342
- if (!(bridge !== null && bridge !== void 0 && bridge.applyPromotionCode)) {
343
- _context5.next = 40;
344
- break;
345
- }
346
- _context5.next = 37;
347
- return bridge.applyPromotionCode(scanCode, Number((_data$id = data === null || data === void 0 ? void 0 : data.id) !== null && _data$id !== void 0 ? _data$id : data === null || data === void 0 ? void 0 : data.customer_id) || undefined);
348
- case 37:
349
- promotionResult = _context5.sent;
522
+ case 66:
523
+ _context6.t2 = _context6.sent;
524
+ _context6.next = 72;
525
+ break;
526
+ case 69:
527
+ _context6.next = 71;
528
+ return bridge.applyPromotionCode(scanCode, promotionCustomerId);
529
+ case 71:
530
+ _context6.t2 = _context6.sent;
531
+ case 72:
532
+ promotionResult = _context6.t2;
350
533
  if (!((_promotionResult$isAc = promotionResult === null || promotionResult === void 0 ? void 0 : promotionResult.isAccepted) !== null && _promotionResult$isAc !== void 0 ? _promotionResult$isAc : promotionResult === null || promotionResult === void 0 ? void 0 : promotionResult.isAvailable)) {
351
- _context5.next = 40;
534
+ _context6.next = 75;
352
535
  break;
353
536
  }
354
- return _context5.abrupt("return", {
537
+ return _context6.abrupt("return", {
355
538
  status: 'success',
356
539
  kind: 'promotion'
357
540
  });
358
- case 40:
359
- bridge === null || bridge === void 0 || (_bridge$onNotify5 = bridge.onNotify) === null || _bridge$onNotify5 === void 0 || _bridge$onNotify5.call(bridge, 'success', 'pisell2.text.add-client-success');
360
- return _context5.abrupt("return", {
541
+ case 75:
542
+ if (!bindResult.customerBound) {
543
+ _context6.next = 77;
544
+ break;
545
+ }
546
+ return _context6.abrupt("return", {
361
547
  status: 'success',
362
548
  kind: 'customer'
363
549
  });
364
- case 42:
550
+ case 77:
551
+ return _context6.abrupt("return", {
552
+ status: 'failed',
553
+ reason: 'invalid_data'
554
+ });
555
+ case 78:
365
556
  if (!(searchType === 'product' || searchType === 'local_product')) {
366
- _context5.next = 75;
557
+ _context6.next = 111;
367
558
  break;
368
559
  }
369
560
  list = data === null || data === void 0 ? void 0 : data.list;
370
561
  if (!(!Array.isArray(list) || list.length === 0)) {
371
- _context5.next = 47;
562
+ _context6.next = 83;
372
563
  break;
373
564
  }
374
- bridge === null || bridge === void 0 || (_bridge$onNotify6 = bridge.onNotify) === null || _bridge$onNotify6 === void 0 || _bridge$onNotify6.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
375
- return _context5.abrupt("return", {
565
+ bridge === null || bridge === void 0 || (_bridge$onNotify12 = bridge.onNotify) === null || _bridge$onNotify12 === void 0 || _bridge$onNotify12.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
566
+ return _context6.abrupt("return", {
376
567
  status: 'failed',
377
568
  reason: 'invalid_data'
378
569
  });
379
- case 47:
570
+ case 83:
380
571
  addedCount = 0;
381
572
  _iterator = _createForOfIteratorHelper(list);
382
- _context5.prev = 49;
573
+ _context6.prev = 85;
383
574
  _iterator.s();
384
- case 51:
575
+ case 87:
385
576
  if ((_step = _iterator.n()).done) {
386
- _context5.next = 63;
577
+ _context6.next = 99;
387
578
  break;
388
579
  }
389
580
  _item = _step.value;
390
- _context5.next = 55;
581
+ _context6.next = 91;
391
582
  return processScannedProductItem(host, _item, scanCode, bridge);
392
- case 55:
393
- outcome = _context5.sent;
583
+ case 91:
584
+ outcome = _context6.sent;
394
585
  if (outcome === 'added') {
395
586
  addedCount += 1;
396
587
  }
397
588
  if (!(outcome === 'cancelled')) {
398
- _context5.next = 59;
589
+ _context6.next = 95;
399
590
  break;
400
591
  }
401
- return _context5.abrupt("return", {
592
+ return _context6.abrupt("return", {
402
593
  status: 'cancelled'
403
594
  });
404
- case 59:
595
+ case 95:
405
596
  if (!(outcome === 'pending')) {
406
- _context5.next = 61;
597
+ _context6.next = 97;
407
598
  break;
408
599
  }
409
- return _context5.abrupt("return", {
600
+ return _context6.abrupt("return", {
410
601
  status: 'pending',
411
602
  kind: 'requiresDetail'
412
603
  });
413
- case 61:
414
- _context5.next = 51;
604
+ case 97:
605
+ _context6.next = 87;
415
606
  break;
416
- case 63:
417
- _context5.next = 68;
607
+ case 99:
608
+ _context6.next = 104;
418
609
  break;
419
- case 65:
420
- _context5.prev = 65;
421
- _context5.t0 = _context5["catch"](49);
422
- _iterator.e(_context5.t0);
423
- case 68:
424
- _context5.prev = 68;
610
+ case 101:
611
+ _context6.prev = 101;
612
+ _context6.t3 = _context6["catch"](85);
613
+ _iterator.e(_context6.t3);
614
+ case 104:
615
+ _context6.prev = 104;
425
616
  _iterator.f();
426
- return _context5.finish(68);
427
- case 71:
617
+ return _context6.finish(104);
618
+ case 107:
428
619
  if (!(addedCount > 0)) {
429
- _context5.next = 74;
620
+ _context6.next = 110;
430
621
  break;
431
622
  }
432
- bridge === null || bridge === void 0 || (_bridge$onNotify7 = bridge.onNotify) === null || _bridge$onNotify7 === void 0 || _bridge$onNotify7.call(bridge, 'success');
433
- return _context5.abrupt("return", {
623
+ bridge === null || bridge === void 0 || (_bridge$onNotify13 = bridge.onNotify) === null || _bridge$onNotify13 === void 0 || _bridge$onNotify13.call(bridge, 'success');
624
+ return _context6.abrupt("return", {
434
625
  status: 'success',
435
626
  kind: 'products',
436
627
  meta: {
437
628
  count: addedCount
438
629
  }
439
630
  });
440
- case 74:
441
- return _context5.abrupt("return", {
631
+ case 110:
632
+ return _context6.abrupt("return", {
442
633
  status: 'failed',
443
634
  reason: 'no_bridge'
444
635
  });
445
- case 75:
636
+ case 111:
446
637
  if (!(searchType === 'order')) {
447
- _context5.next = 84;
638
+ _context6.next = 120;
448
639
  break;
449
640
  }
450
641
  orderId = (_data$order_id = data === null || data === void 0 ? void 0 : data.order_id) !== null && _data$order_id !== void 0 ? _data$order_id : data === null || data === void 0 ? void 0 : data.id;
451
642
  if (orderId) {
452
- _context5.next = 80;
643
+ _context6.next = 116;
453
644
  break;
454
645
  }
455
- bridge === null || bridge === void 0 || (_bridge$onNotify8 = bridge.onNotify) === null || _bridge$onNotify8 === void 0 || _bridge$onNotify8.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
456
- return _context5.abrupt("return", {
646
+ bridge === null || bridge === void 0 || (_bridge$onNotify14 = bridge.onNotify) === null || _bridge$onNotify14 === void 0 || _bridge$onNotify14.call(bridge, 'fail', 'pisell2.text.scan-global-failed');
647
+ return _context6.abrupt("return", {
457
648
  status: 'failed',
458
649
  reason: 'invalid_data'
459
650
  });
460
- case 80:
651
+ case 116:
461
652
  if (bridge !== null && bridge !== void 0 && bridge.openOrder) {
462
- _context5.next = 82;
653
+ _context6.next = 118;
463
654
  break;
464
655
  }
465
- return _context5.abrupt("return", {
656
+ return _context6.abrupt("return", {
466
657
  status: 'pending',
467
658
  kind: 'openOrder'
468
659
  });
469
- case 82:
660
+ case 118:
470
661
  bridge.openOrder({
471
662
  order_id: Number(orderId),
472
663
  business_code: (_data$business_code = data === null || data === void 0 ? void 0 : data.business_code) !== null && _data$business_code !== void 0 ? _data$business_code : host.getBusinessCode()
473
664
  });
474
- return _context5.abrupt("return", {
665
+ return _context6.abrupt("return", {
475
666
  status: 'pending',
476
667
  kind: 'openOrder'
477
668
  });
478
- case 84:
479
- return _context5.abrupt("return", {
669
+ case 120:
670
+ return _context6.abrupt("return", {
480
671
  status: 'failed',
481
672
  reason: 'invalid_data'
482
673
  });
483
- case 85:
674
+ case 121:
484
675
  case "end":
485
- return _context5.stop();
676
+ return _context6.stop();
486
677
  }
487
- }, _callee5, null, [[49, 65, 68, 71]]);
678
+ }, _callee6, null, [[10, 16], [30, 37], [85, 101, 104, 107]]);
488
679
  }));
489
680
  return _applyGlobalScan.apply(this, arguments);
490
681
  }