@pisell/pisellos 2.3.122 → 2.3.124

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 (92) 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/utils/buildCacheItemFromOrderLine.js +58 -19
  4. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  5. package/dist/modules/Customer/index.js +6 -3
  6. package/dist/modules/Customer/types.d.ts +2 -0
  7. package/dist/modules/Discount/availability.d.ts +7 -0
  8. package/dist/modules/Discount/availability.js +49 -0
  9. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  10. package/dist/modules/Discount/entitlementPass.js +147 -0
  11. package/dist/modules/Discount/index.d.ts +2 -2
  12. package/dist/modules/Discount/index.js +37 -151
  13. package/dist/modules/Discount/types.d.ts +36 -5
  14. package/dist/modules/Order/index.d.ts +6 -0
  15. package/dist/modules/Order/index.js +437 -229
  16. package/dist/modules/Order/types.d.ts +1 -0
  17. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  18. package/dist/modules/Order/utils.d.ts +1 -1
  19. package/dist/modules/Order/utils.js +105 -60
  20. package/dist/modules/Payment/types.d.ts +21 -1
  21. package/dist/modules/Payment/types.js +2 -0
  22. package/dist/modules/Payment/walletpass.d.ts +1 -1
  23. package/dist/modules/Payment/walletpass.js +80 -47
  24. package/dist/modules/Rules/index.d.ts +2 -2
  25. package/dist/modules/Rules/index.js +480 -186
  26. package/dist/modules/Rules/types.d.ts +4 -0
  27. package/dist/server/modules/order/types.d.ts +3 -0
  28. package/dist/server/utils/small-ticket.js +25 -15
  29. package/dist/solution/BaseSales/index.d.ts +1 -0
  30. package/dist/solution/BaseSales/index.js +5 -2
  31. package/dist/solution/BaseSales/types.d.ts +2 -2
  32. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  33. package/dist/solution/BookingTicket/index.d.ts +1 -2
  34. package/dist/solution/BookingTicket/index.js +60 -63
  35. package/dist/solution/BookingTicket/types.d.ts +5 -1
  36. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  37. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  38. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  39. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  40. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  41. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  42. package/dist/solution/ShopDiscount/index.js +99 -42
  43. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  44. package/dist/solution/ShopDiscount/utils.js +43 -23
  45. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  46. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  47. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  48. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  49. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  50. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  51. package/lib/modules/Customer/index.js +5 -1
  52. package/lib/modules/Customer/types.d.ts +2 -0
  53. package/lib/modules/Discount/availability.d.ts +7 -0
  54. package/lib/modules/Discount/availability.js +43 -0
  55. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  56. package/lib/modules/Discount/entitlementPass.js +141 -0
  57. package/lib/modules/Discount/index.d.ts +2 -2
  58. package/lib/modules/Discount/index.js +23 -129
  59. package/lib/modules/Discount/types.d.ts +36 -5
  60. package/lib/modules/Order/index.d.ts +6 -0
  61. package/lib/modules/Order/index.js +213 -40
  62. package/lib/modules/Order/types.d.ts +1 -0
  63. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  64. package/lib/modules/Order/utils.d.ts +1 -1
  65. package/lib/modules/Order/utils.js +43 -3
  66. package/lib/modules/Payment/types.d.ts +21 -1
  67. package/lib/modules/Payment/types.js +1 -0
  68. package/lib/modules/Payment/walletpass.d.ts +1 -1
  69. package/lib/modules/Payment/walletpass.js +29 -9
  70. package/lib/modules/Rules/index.d.ts +2 -2
  71. package/lib/modules/Rules/index.js +357 -110
  72. package/lib/modules/Rules/types.d.ts +4 -0
  73. package/lib/server/modules/order/types.d.ts +3 -0
  74. package/lib/server/utils/small-ticket.js +25 -14
  75. package/lib/solution/BaseSales/index.d.ts +1 -0
  76. package/lib/solution/BaseSales/index.js +5 -2
  77. package/lib/solution/BaseSales/types.d.ts +2 -2
  78. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  79. package/lib/solution/BookingTicket/index.d.ts +1 -2
  80. package/lib/solution/BookingTicket/index.js +36 -33
  81. package/lib/solution/BookingTicket/types.d.ts +5 -1
  82. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  83. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  84. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  85. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  86. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  87. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  88. package/lib/solution/ShopDiscount/index.js +55 -9
  89. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  90. package/lib/solution/ShopDiscount/utils.js +42 -25
  91. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  92. package/package.json +1 -1
@@ -29,6 +29,10 @@ export interface RulesCalcDiscountOptions {
29
29
  discountId?: number;
30
30
  selectedList?: SetDiscountSelectedParams[];
31
31
  scan?: boolean;
32
+ /** 本次扫码优先使用的次卡实例;普通重算不传,继续保留商品行当前选择。 */
33
+ preferredEntitlementPassIds?: number[];
34
+ /** 普通重算保留商品行已应用的次卡;最优选择传 false 恢复自动排序。 */
35
+ preserveEntitlementSelection?: boolean;
32
36
  /** Change time 重报价目标行:允许已选编辑态折扣卡重新应用到这些 booking 商品。 */
33
37
  reapplyBookingDiscountProductUids?: string[];
34
38
  }
@@ -36,6 +36,8 @@ export type OrderSurchargeType = string;
36
36
  export interface OrderProductDiscountMetadata {
37
37
  /** 设备端本地唯一标识,用于与服务端记录对齐 */
38
38
  unique_identification_number?: string;
39
+ /** 月卡扣除本单新增使用后的剩余次数;不限次数时为 null。 */
40
+ balance?: number | null;
39
41
  [key: string]: unknown;
40
42
  }
41
43
  /**
@@ -452,6 +454,7 @@ export interface OrderData {
452
454
  id: number | string;
453
455
  tag: 'point_card';
454
456
  product_id?: number | string;
457
+ code?: string;
455
458
  product_name: string;
456
459
  par_value: string;
457
460
  used_par_value: string;
@@ -774,9 +774,11 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
774
774
  options: rawOptions
775
775
  });
776
776
  const nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
777
+ const productTitle = getBundleProductTitleSource(combination, locale);
777
778
  const snapshot = {
778
779
  ...combination
779
780
  };
781
+ delete snapshot.product_title;
780
782
  delete snapshot.product_note;
781
783
  delete snapshot.note;
782
784
  delete snapshot.combinations;
@@ -796,6 +798,9 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
796
798
  const shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
797
799
  return {
798
800
  ...snapshot,
801
+ ...(productTitle ? {
802
+ product_title: productTitle
803
+ } : {}),
799
804
  product_quantity: quantity,
800
805
  total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol),
801
806
  ...(shouldIncludeBasePrice ? {
@@ -864,18 +869,18 @@ function resolveBundleProductTitle(params) {
864
869
  locale,
865
870
  parentProduct
866
871
  } = params;
867
- const ownTitle = getProductTitleSource(bundle, locale);
872
+ const ownTitle = getBundleProductTitleSource(bundle, locale);
868
873
  if (ownTitle) return ownTitle;
869
874
  const parentBundleItem = resolveBundleItemFromParentProduct({
870
875
  bundle,
871
876
  parentProduct
872
877
  });
873
- const parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
878
+ const parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
874
879
  if (parentBundleTitle) return parentBundleTitle;
875
880
  const productId = bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id ?? bundle.id;
876
881
  const fallbackProduct = resolveProductFromMap(productId, productMap);
877
882
  if (!fallbackProduct) return '';
878
- return getProductTitleSource(fallbackProduct, locale);
883
+ return getBundleProductTitleSource(fallbackProduct, locale);
879
884
  }
880
885
  function resolveProductFromMap(productId, productMap) {
881
886
  if (productId === undefined || productId === null || productId === '') return null;
@@ -947,7 +952,11 @@ function resolveVariantItem(group, itemPositionId) {
947
952
  }
948
953
  function getProductTitleSource(source, locale) {
949
954
  if (!source || typeof source !== 'object') return '';
950
- return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
955
+ return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
956
+ }
957
+ function getBundleProductTitleSource(source, locale) {
958
+ if (!source || typeof source !== 'object') return '';
959
+ return resolveTitleValue(source.bundle_title, locale) || resolveTitleValue(source.trans_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
951
960
  }
952
961
  function resolveTitleValue(value, locale) {
953
962
  if (value === undefined || value === null) return '';
@@ -1698,7 +1707,7 @@ function buildPointCardSnapshotAssets(params) {
1698
1707
  codes: []
1699
1708
  })) return [];
1700
1709
  const rows = [{
1701
- item: stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'),
1710
+ item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
1702
1711
  value: ''
1703
1712
  }];
1704
1713
  const remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
@@ -2170,9 +2179,14 @@ function isPointCardPayment(payment) {
2170
2179
  return code === 'POINTCARD' || type === 'point_card';
2171
2180
  }
2172
2181
  function maskMachineCode(code) {
2173
- const text = stringify(code);
2174
- if (text.length <= 6) return text;
2175
- return `${text.slice(0, 2)}**${text.slice(-4)}`;
2182
+ const text = stringify(code).trim();
2183
+ if (!text) return '';
2184
+ if (text.length <= 6) return '*'.repeat(text.length);
2185
+ return `${text.slice(0, 2)}****${text.slice(-4)}`;
2186
+ }
2187
+ function appendMaskedCardCode(name, code) {
2188
+ const maskedCode = maskMachineCode(code);
2189
+ return maskedCode ? `${name}(${maskedCode})` : name;
2176
2190
  }
2177
2191
  function trimDecimal(value) {
2178
2192
  return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
@@ -2181,16 +2195,13 @@ function getFundRecordPaymentName(payment, locale) {
2181
2195
  const fundRecord = getFundRecord(payment);
2182
2196
  if (!fundRecord) return '';
2183
2197
  const name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
2184
- const code = maskMachineCode(fundRecord.code);
2185
- if (!name && !code) return '';
2186
- if (!code) return name;
2198
+ if (!name && !maskMachineCode(fundRecord.code)) return '';
2187
2199
  const fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
2188
- return `${name || fallbackName}(${code})`;
2200
+ return appendMaskedCardCode(name || fallbackName, fundRecord.code);
2189
2201
  }
2190
2202
  function appendMachineCodeToName(name, payment) {
2191
2203
  const fundRecord = getFundRecord(payment);
2192
- if (!fundRecord?.code) return name;
2193
- return `${name}(${maskMachineCode(fundRecord.code)})`;
2204
+ return appendMaskedCardCode(name, fundRecord?.code);
2194
2205
  }
2195
2206
  function paymentMethodName(payment, locale) {
2196
2207
  const fundRecordName = getFundRecordPaymentName(payment, locale);
@@ -415,6 +415,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
415
415
  refreshWalletAssets(params?: {
416
416
  order_wait_pay_amount?: number;
417
417
  preserveSelection?: boolean;
418
+ retainSearchResultCodes?: string[];
418
419
  }): Promise<WalletAssetsState>;
419
420
  /** 选择或取消单张钱包资产,并立即同步 pending wallet payments。 */
420
421
  selectWalletAsset(params: {
@@ -1849,7 +1849,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1849
1849
  if (!this.isPersistedOrderProduct(item)) return;
1850
1850
  (item.discount_list || []).forEach(discount => {
1851
1851
  const discountId = discount.discount?.resource_id || discount.id;
1852
- if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
1852
+ if (!discountId || !['entitlement_pass', 'good_pass', 'discount_card'].includes(discount.type)) return;
1853
1853
  const quantity = item.quantity || item.num || item.product_quantity || 1;
1854
1854
  const savedAmount = new _decimal.default(discount.amount || 0).times(quantity).plus(discount?.metadata?.product_discount_difference || 0);
1855
1855
  const index = historyDiscountList.findIndex(n => n.id === discountId);
@@ -2163,6 +2163,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2163
2163
  holders: [],
2164
2164
  isFormSubject: product => (0, _utils.resolveIsFormSubject)(tempOrder, product),
2165
2165
  orderTotalAmount
2166
+ }, {
2167
+ preserveEntitlementSelection: false
2166
2168
  }) || result;
2167
2169
  if (result.productList) {
2168
2170
  tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
@@ -3236,7 +3238,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
3236
3238
  await this.publishWalletAssetsState(clearedState);
3237
3239
  }
3238
3240
  const refreshTask = wallet.refreshWalletAssetsFromBusinessAsync(businessData, {
3239
- preserveSelection: params?.preserveSelection !== false && !customerChanged
3241
+ preserveSelection: params?.preserveSelection !== false && !customerChanged,
3242
+ retainSearchResultCodes: params?.retainSearchResultCodes
3240
3243
  });
3241
3244
  await this.publishWalletAssetsState(wallet.getWalletAssetsState());
3242
3245
  let state = await refreshTask;
@@ -441,10 +441,10 @@ export interface BaseSalesAddLogParams extends BaseSalesLogInput {
441
441
  /** BaseSales.scanPromotionCode 对外的轻量结果(UI 可用 getDiscountList 或 scannedDiscountList 补 Holder) */
442
442
  export interface BaseSalesScanCodeResult {
443
443
  isAvailable: boolean;
444
- /** 卡券已加入 Promotion;false 时可能是无效、过期或已使用。 */
444
+ /** 卡券已加入 Promotion;可能因次数、时间或当前订单条件而暂时无法应用。 */
445
445
  isAccepted?: boolean;
446
446
  type?: 'server' | string;
447
447
  unavailableReason?: 'time_limit' | string;
448
- /** batchSearch 原始结果;Holder 补全等流程可从这里读取原始卡券。 */
448
+ /** 扫码卡券资料及最新可用状态,供 Holder 补全等流程使用。 */
449
449
  scannedDiscountList?: Discount[];
450
450
  }
@@ -17,6 +17,7 @@ exports.resolveStrategyEligibleProducts = resolveStrategyEligibleProducts;
17
17
  exports.resolveStrategyRequiredQuantity = resolveStrategyRequiredQuantity;
18
18
  var _decimal = _interopRequireDefault(require("decimal.js"));
19
19
  var _lodashEs = require("lodash-es");
20
+ var _entitlementPass = require("../../../modules/Discount/entitlementPass");
20
21
  var _utils = require("../../../modules/Order/utils");
21
22
  var _utils2 = require("../../ScanOrder/utils");
22
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -395,11 +396,16 @@ function getProductLineNoteSignature(product) {
395
396
  const uid = getOrderProductUid(product);
396
397
  return uid ? `note:${uid}` : `note:${normalizedNote}`;
397
398
  }
398
- function hasGoodPassDiscount(product) {
399
+ function getFullCoveragePassDiscountType(product) {
399
400
  const productBundle = Array.isArray(product?.product_bundle) ? product.product_bundle : [];
400
401
  const extendedBundle = Array.isArray(product?._extend?.other?.bundle) ? product._extend.other.bundle : [];
401
402
  const discountLists = [product?.discount_list, ...productBundle.map(item => item?.discount_list), ...extendedBundle.map(item => item?.discount_list)];
402
- return discountLists.some(discountList => Array.isArray(discountList) && discountList.some(item => item?.type === 'good_pass' || item?.tag === 'good_pass'));
403
+ for (const discountList of discountLists) {
404
+ if (!Array.isArray(discountList)) continue;
405
+ const pass = discountList.find(item => (0, _entitlementPass.isFullCoveragePass)(item));
406
+ if (pass) return String(pass.type || pass.tag);
407
+ }
408
+ return null;
403
409
  }
404
410
 
405
411
  /**
@@ -412,8 +418,10 @@ function getPromotionLineMergeBoundary(product) {
412
418
  if (product?.product_id === undefined || product?.product_id === null) {
413
419
  return `custom:${getOrderProductUid(product)}`;
414
420
  }
415
- if (hasGoodPassDiscount(product)) {
416
- return `good-pass:${getOrderProductUid(product)}`;
421
+ const fullCoveragePassType = getFullCoveragePassDiscountType(product);
422
+ if (fullCoveragePassType) {
423
+ const boundary = fullCoveragePassType === 'good_pass' ? 'good-pass' : 'entitlement-pass';
424
+ return `${boundary}:${getOrderProductUid(product)}`;
417
425
  }
418
426
  if (Number(product?.product_sku?.open_sold_weight || 0) === 1) {
419
427
  return `weighing:${getOrderProductUid(product)}`;
@@ -32,6 +32,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
32
32
  private orderCustomerDiscountRefreshCustomerId;
33
33
  private orderCustomerDiscountRefreshTarget;
34
34
  private orderCustomerPromotionRefreshInFlight;
35
+ private readonly customerResolveRequests;
35
36
  protected loadOpenDataInFlight: Promise<OpenDataConfig> | null;
36
37
  protected loadOpenDataInFlightTarget: string | null;
37
38
  protected openDataTarget: string | null;
@@ -80,10 +81,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
80
81
  resolveCustomerById(customerId: string | number): Promise<ICustomer | null>;
81
82
  /** 兼容既有优惠码扫码逻辑。 */
82
83
  private resolveCustomerByDiscountCustomerId;
83
- private findCustomerById;
84
84
  private normalizeCustomer;
85
85
  private getRawCustomerId;
86
- private hasUsableCustomerDetails;
87
86
  /**
88
87
  * 更新当前预约的 appointment_status。
89
88
  *
@@ -162,6 +162,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
162
162
  orderCustomerDiscountRefreshCustomerId = null;
163
163
  orderCustomerDiscountRefreshTarget = null;
164
164
  orderCustomerPromotionRefreshInFlight = null;
165
+ customerResolveRequests = new Map();
165
166
  loadOpenDataInFlight = null;
166
167
  loadOpenDataInFlightTarget = null;
167
168
  openDataTarget = null;
@@ -443,7 +444,15 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
443
444
 
444
445
  // 缺 Holder 等场景 isAvailable=false,但仍需把 Pass 归属客户带入订单,供 Holder 弹窗使用。
445
446
  if (!hasOrderCustomer && extractedCustomerId && !isUserPlatform) {
446
- await this.hydrateOrderCustomerFromScanDiscounts(scannedList);
447
+ try {
448
+ await this.hydrateOrderCustomerFromScanDiscounts(scannedList);
449
+ } catch (error) {
450
+ // 客户映射失败不能阻断原有 Pass 的可用性、展示或优惠处理。
451
+ console.warn('[BookingTicket] scan discount customer resolve failed', {
452
+ customerId: extractedCustomerId,
453
+ error
454
+ });
455
+ }
447
456
  }
448
457
  if (raw.isAvailable) {
449
458
  await this.store.order.recalculateSummary({
@@ -494,43 +503,39 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
494
503
  return null;
495
504
  }
496
505
  async resolveCustomerById(customerId) {
497
- const localCustomers = this.store.customer.getCustomers();
498
- const localCustomer = this.findCustomerById(localCustomers, customerId);
499
- const normalizedLocalCustomer = localCustomer ? this.normalizeCustomer(localCustomer) : null;
500
- if (normalizedLocalCustomer && this.hasUsableCustomerDetails(normalizedLocalCustomer)) {
501
- return normalizedLocalCustomer;
502
- }
503
- const result = await this.store.customer.queryCustomerList({
504
- ids: [customerId],
505
- skip: 1,
506
- num: 1
507
- });
508
- const remoteCustomer = this.findCustomerById(result?.list || [], customerId) || result?.list?.[0] || null;
509
- if (remoteCustomer) {
510
- return this.normalizeCustomer(remoteCustomer);
511
- }
512
- try {
513
- const detailCustomer = await this.store.customer.queryCustomerDetail(customerId);
514
- return detailCustomer ? this.normalizeCustomer(detailCustomer) : null;
515
- } catch (error) {
516
- console.warn('[BookingTicket] resolveCustomerById detail request failed', {
517
- customerId,
518
- error
519
- });
506
+ const rawCustomerId = String(customerId ?? '').trim();
507
+ const numericCustomerId = Number(rawCustomerId);
508
+ if (!rawCustomerId || !Number.isInteger(numericCustomerId) || numericCustomerId <= 1) {
520
509
  return null;
521
510
  }
511
+ const normalizedCustomerId = String(numericCustomerId);
512
+ const existingRequest = this.customerResolveRequests.get(normalizedCustomerId);
513
+ if (existingRequest) return existingRequest;
514
+ const request = this.request.post(`/customer/resolve/${encodeURIComponent(normalizedCustomerId)}`, {
515
+ with_franchisor_data: 1,
516
+ with: ['latestWalletDetail.wallet', 'contactsInfo', 'formRecord']
517
+ }).then(result => {
518
+ const customer = result?.data;
519
+ const resolvedCustomerId = Number(customer && typeof customer === 'object' && !Array.isArray(customer) ? this.getRawCustomerId(customer) : NaN);
520
+ if (result?.status !== true || result?.code !== 200 || !customer || typeof customer !== 'object' || Array.isArray(customer) || !Number.isInteger(resolvedCustomerId) || resolvedCustomerId <= 1) {
521
+ const error = new Error(result?.message || 'Customer resolve failed');
522
+ error.code = result?.code;
523
+ throw error;
524
+ }
525
+ return this.normalizeCustomer(customer);
526
+ }).finally(() => {
527
+ if (this.customerResolveRequests.get(normalizedCustomerId) === request) {
528
+ this.customerResolveRequests.delete(normalizedCustomerId);
529
+ }
530
+ });
531
+ this.customerResolveRequests.set(normalizedCustomerId, request);
532
+ return request;
522
533
  }
523
534
 
524
535
  /** 兼容既有优惠码扫码逻辑。 */
525
536
  resolveCustomerByDiscountCustomerId(customerId) {
526
537
  return this.resolveCustomerById(customerId);
527
538
  }
528
- findCustomerById(customers = [], customerId) {
529
- return customers.find(customer => {
530
- const rawId = this.getRawCustomerId(customer);
531
- return rawId !== null && String(rawId) === String(customerId);
532
- }) || null;
533
- }
534
539
  normalizeCustomer(customer) {
535
540
  const raw = customer;
536
541
  const rawId = this.getRawCustomerId(customer);
@@ -548,9 +553,6 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
548
553
  const raw = customer;
549
554
  return customer.id ?? raw.customer_id ?? raw.customerId ?? null;
550
555
  }
551
- hasUsableCustomerDetails(customer) {
552
- return !!(customer.name || customer.phone || customer.email || customer.display_name || customer.customer_name);
553
- }
554
556
 
555
557
  /**
556
558
  * 更新当前预约的 appointment_status。
@@ -1687,6 +1689,7 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1687
1689
  const result = await (0, _applyGlobalScan.applyGlobalScan)({
1688
1690
  setOrderCustomer: customer => this.setOrderCustomer(customer),
1689
1691
  getOrderCustomerSnapshot: () => this.getOrderCustomerSnapshot(),
1692
+ resolveCustomerById: customerId => this.resolveCustomerById(customerId),
1690
1693
  getBusinessCode: () => this.otherParams?.businessCode,
1691
1694
  buildAddProductCtx: extra => this.buildAddProductCtx(extra),
1692
1695
  decideAddProduct: (item, options) => this.decideAddProduct(item, options),
@@ -230,12 +230,16 @@ export interface GlobalScanHostBridge {
230
230
  /**
231
231
  * walk-in 扫 walletPass:直接核销优惠码(对齐 SaleDetail Voucher.handleApplyCode / cart.scanCode)。
232
232
  */
233
- applyPromotionCode?: (code: string, customerId?: number) => Promise<{
233
+ applyPromotionCode?: (code: string, customerId?: number, options?: {
234
+ suppressFailureNotification?: boolean;
235
+ }) => Promise<{
234
236
  isAvailable?: boolean;
235
237
  isAccepted?: boolean;
236
238
  type?: string;
237
239
  unavailableReason?: string;
238
240
  }>;
241
+ /** 当前订单已有其他客户时,由宿主复用客户组件完成确认及切换。 */
242
+ requestCustomerSwitch?: (customer: ICustomer) => Promise<boolean | null>;
239
243
  onNotify?: (type: 'success' | 'fail' | 'info', messageKey?: string) => void;
240
244
  refresh?: () => void;
241
245
  }
@@ -5,6 +5,7 @@ import { GlobalScanFormattedResult } from './formatGlobalScan';
5
5
  export interface GlobalScanApplyHost {
6
6
  setOrderCustomer(customer: ICustomer | null): void;
7
7
  getOrderCustomerSnapshot(): ICustomer | null;
8
+ resolveCustomerById?(customerId: string | number): Promise<ICustomer | null>;
8
9
  getBusinessCode(): string | undefined;
9
10
  buildAddProductCtx(extra?: Record<string, any>): Record<string, any>;
10
11
  decideAddProduct(item: any, options?: Record<string, any>): AddProductDecision;
@@ -26,6 +27,7 @@ export interface GlobalScanApplyHost {
26
27
  addProductToOrder(product: any, booking?: any): Promise<any>;
27
28
  refreshWalletAssets?(params?: {
28
29
  preserveSelection?: boolean;
30
+ retainSearchResultCodes?: string[];
29
31
  }): Promise<any>;
30
32
  scanWalletAsset?(code: string): Promise<{
31
33
  type: 'walletCode' | 'normalCode';
@@ -5,10 +5,21 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyGlobalScan = applyGlobalScan;
7
7
  var _addProductDecision = require("../addProductDecision");
8
- var _cartView = require("../cartView");
9
8
  var _scanProductValues = require("./scanProductValues");
10
9
  /** applyGlobalScan 所需的 BookingTicket 运行时能力 */
11
10
 
11
+ function getRealCustomerId(customer) {
12
+ const customerId = Number(customer?.id ?? customer?.customer_id);
13
+ return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
14
+ }
15
+ function getWalletAssetCustomerId(asset) {
16
+ const customerId = Number(asset?.customer_id ?? asset?.holder?.customer_id);
17
+ return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
18
+ }
19
+ function getErrorMessage(error) {
20
+ return error instanceof Error ? error.message : String(error || '');
21
+ }
22
+
12
23
  /**
13
24
  * 处理单条扫码商品的加车决策(含弹窗链)。
14
25
  */
@@ -93,17 +104,81 @@ async function applyGlobalScan(host, formatted, bridge) {
93
104
  const {
94
105
  searchType,
95
106
  data,
96
- scanCode
107
+ scanCode,
108
+ customerId: formattedCustomerId,
109
+ isCrossShopWallet,
110
+ isWalletPassUnavailableAtStore
97
111
  } = formatted;
98
112
  if (searchType === 'wallet') {
99
- if (!data) {
113
+ const currentCustomer = host.getOrderCustomerSnapshot();
114
+ const currentCustomerId = getRealCustomerId(currentCustomer);
115
+ let customer = data;
116
+ if (isCrossShopWallet) {
117
+ const sourceCustomerId = getRealCustomerId({
118
+ id: formattedCustomerId
119
+ });
120
+ if (sourceCustomerId === undefined || !host.resolveCustomerById) {
121
+ bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
122
+ return {
123
+ status: 'failed',
124
+ reason: 'invalid_data'
125
+ };
126
+ }
127
+ try {
128
+ customer = await host.resolveCustomerById(sourceCustomerId);
129
+ } catch (error) {
130
+ bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
131
+ return {
132
+ status: 'failed',
133
+ reason: 'invalid_data'
134
+ };
135
+ }
136
+ }
137
+ const customerId = getRealCustomerId(customer) ?? (!isCrossShopWallet ? getRealCustomerId({
138
+ id: formattedCustomerId
139
+ }) : undefined);
140
+ if (!customer || customerId === undefined) {
100
141
  bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
101
142
  return {
102
143
  status: 'failed',
103
144
  reason: 'invalid_data'
104
145
  };
105
146
  }
106
- host.setOrderCustomer(data);
147
+ const orderCustomer = customer.id === undefined || customer.id === null ? {
148
+ ...customer,
149
+ id: customerId
150
+ } : customer;
151
+ if (currentCustomerId === customerId) {
152
+ return {
153
+ status: 'success',
154
+ kind: 'customer'
155
+ };
156
+ }
157
+ if (currentCustomerId !== undefined) {
158
+ // 未接入新桥接的宿主保持原行为:已有客户时不直接覆盖。
159
+ if (!bridge?.requestCustomerSwitch) {
160
+ return {
161
+ status: 'success',
162
+ kind: 'customer'
163
+ };
164
+ }
165
+ try {
166
+ const switched = await bridge.requestCustomerSwitch(orderCustomer);
167
+ return switched ? {
168
+ status: 'success',
169
+ kind: 'customer'
170
+ } : {
171
+ status: 'cancelled'
172
+ };
173
+ } catch (error) {
174
+ bridge.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
175
+ return {
176
+ status: 'failed',
177
+ reason: 'invalid_data'
178
+ };
179
+ }
180
+ }
181
+ host.setOrderCustomer(orderCustomer);
107
182
  bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
108
183
  return {
109
184
  status: 'success',
@@ -111,8 +186,70 @@ async function applyGlobalScan(host, formatted, bridge) {
111
186
  };
112
187
  }
113
188
  if (searchType === 'walletPass') {
189
+ if (isWalletPassUnavailableAtStore) {
190
+ bridge?.onNotify?.('fail', 'pisell2.text.wallet-pass-not-available-at-store');
191
+ return {
192
+ status: 'failed',
193
+ reason: 'invalid_data'
194
+ };
195
+ }
114
196
  const snapshot = host.getOrderCustomerSnapshot();
115
- const scannedCustomerIsWalkIn = (0, _cartView.isWalkInCustomer)(data);
197
+ let activeCustomer = snapshot;
198
+ const bindWalletPassCustomer = async asset => {
199
+ if (getRealCustomerId(activeCustomer) !== undefined) {
200
+ return {
201
+ resolveFailed: false,
202
+ customerBound: false
203
+ };
204
+ }
205
+ const assetCustomerId = getWalletAssetCustomerId(asset) ?? getRealCustomerId({
206
+ id: formattedCustomerId
207
+ });
208
+ let customer = null;
209
+ if (assetCustomerId !== undefined) {
210
+ if (!host.resolveCustomerById) {
211
+ bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
212
+ return {
213
+ resolveFailed: true,
214
+ customerBound: false
215
+ };
216
+ }
217
+ try {
218
+ customer = await host.resolveCustomerById(assetCustomerId);
219
+ } catch (error) {
220
+ console.warn('[GlobalScan] Wallet asset customer lookup failed', error);
221
+ bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
222
+ return {
223
+ resolveFailed: true,
224
+ customerBound: false
225
+ };
226
+ }
227
+ }
228
+ const customerId = getRealCustomerId(customer);
229
+ if (!customer || customerId === undefined) {
230
+ if (assetCustomerId !== undefined) {
231
+ bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
232
+ }
233
+ return {
234
+ resolveFailed: assetCustomerId !== undefined,
235
+ customerBound: false
236
+ };
237
+ }
238
+ const orderCustomer = customer.id === undefined || customer.id === null ? {
239
+ ...customer,
240
+ id: customerId
241
+ } : customer;
242
+ host.setOrderCustomer(orderCustomer);
243
+ activeCustomer = orderCustomer;
244
+ await host.refreshWalletAssets?.({
245
+ preserveSelection: false,
246
+ retainSearchResultCodes: [scanCode]
247
+ });
248
+ return {
249
+ resolveFailed: false,
250
+ customerBound: true
251
+ };
252
+ };
116
253
  const trySelectWalletAsset = async () => {
117
254
  if (!host.scanWalletAsset) return null;
118
255
  const walletResult = await host.scanWalletAsset(scanCode).catch(error => {
@@ -123,61 +260,56 @@ async function applyGlobalScan(host, formatted, bridge) {
123
260
  if (walletResult.type !== 'normalCode' || !walletResult.asset) {
124
261
  return null;
125
262
  }
263
+ const bindResult = await bindWalletPassCustomer(walletResult.asset);
126
264
  if (walletResult.selected) {
127
- bridge?.onNotify?.('success');
265
+ if (!bindResult.resolveFailed) {
266
+ bridge?.onNotify?.('success');
267
+ }
128
268
  return {
129
269
  status: 'success',
130
270
  kind: 'promotion'
131
271
  };
132
272
  }
133
273
  // 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
134
- bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
274
+ if (!bindResult.resolveFailed) {
275
+ bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
276
+ }
135
277
  return {
136
278
  status: 'failed',
137
279
  reason: 'invalid_data'
138
280
  };
139
281
  };
140
- if ((0, _cartView.isWalkInCustomer)(snapshot) || scannedCustomerIsWalkIn) {
141
- // 当前购物车或 walletPass 绑定客户为 walk-in 时不绑客户,避免覆盖已有下单客户。
142
- const walletSelection = await trySelectWalletAsset();
143
- if (walletSelection) return walletSelection;
144
- if (!bridge?.applyPromotionCode) {
145
- return {
146
- status: 'failed',
147
- reason: 'no_bridge'
148
- };
149
- }
150
- const result = await bridge.applyPromotionCode(scanCode);
151
- if (result?.isAccepted ?? result?.isAvailable) {
152
- return {
153
- status: 'success',
154
- kind: 'promotion'
155
- };
156
- }
282
+
283
+ // batch-search 可能返回来源门店客户;先映射到当前门店,确保 Wallet
284
+ // 支付资产查询使用本店客户上下文。
285
+ const bindResult = await bindWalletPassCustomer();
286
+ const walletSelection = await trySelectWalletAsset();
287
+ if (walletSelection) return walletSelection;
288
+ if (!bridge?.applyPromotionCode) {
157
289
  return {
158
290
  status: 'failed',
159
- reason: 'invalid_data'
291
+ reason: 'no_bridge'
160
292
  };
161
293
  }
162
- host.setOrderCustomer(data);
163
- await host.refreshWalletAssets?.({
164
- preserveSelection: false
165
- });
166
- const walletSelection = await trySelectWalletAsset();
167
- if (walletSelection) return walletSelection;
168
- if (bridge?.applyPromotionCode) {
169
- const promotionResult = await bridge.applyPromotionCode(scanCode, Number(data?.id ?? data?.customer_id) || undefined);
170
- if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
171
- return {
172
- status: 'success',
173
- kind: 'promotion'
174
- };
175
- }
294
+ const promotionCustomerId = getRealCustomerId(activeCustomer);
295
+ const promotionResult = bindResult.customerBound ? await bridge.applyPromotionCode(scanCode, promotionCustomerId, {
296
+ suppressFailureNotification: true
297
+ }) : await bridge.applyPromotionCode(scanCode, promotionCustomerId);
298
+ if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
299
+ return {
300
+ status: 'success',
301
+ kind: 'promotion'
302
+ };
303
+ }
304
+ if (bindResult.customerBound) {
305
+ return {
306
+ status: 'success',
307
+ kind: 'customer'
308
+ };
176
309
  }
177
- bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
178
310
  return {
179
- status: 'success',
180
- kind: 'customer'
311
+ status: 'failed',
312
+ reason: 'invalid_data'
181
313
  };
182
314
  }
183
315
  if (searchType === 'product' || searchType === 'local_product') {