@pisell/pisellos 2.3.123 → 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 (89) 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 +7 -1
  15. package/dist/modules/Order/index.js +437 -229
  16. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  17. package/dist/modules/Order/utils.d.ts +1 -1
  18. package/dist/modules/Order/utils.js +101 -60
  19. package/dist/modules/Payment/types.d.ts +21 -1
  20. package/dist/modules/Payment/types.js +2 -0
  21. package/dist/modules/Payment/walletpass.d.ts +1 -1
  22. package/dist/modules/Payment/walletpass.js +80 -47
  23. package/dist/modules/Rules/index.d.ts +2 -2
  24. package/dist/modules/Rules/index.js +480 -186
  25. package/dist/modules/Rules/types.d.ts +4 -0
  26. package/dist/server/modules/order/types.d.ts +2 -0
  27. package/dist/solution/BaseSales/index.d.ts +1 -0
  28. package/dist/solution/BaseSales/index.js +5 -2
  29. package/dist/solution/BaseSales/types.d.ts +2 -2
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  31. package/dist/solution/BookingByStep/index.d.ts +1 -1
  32. package/dist/solution/BookingTicket/index.d.ts +1 -2
  33. package/dist/solution/BookingTicket/index.js +60 -63
  34. package/dist/solution/BookingTicket/types.d.ts +5 -1
  35. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  36. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  37. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  38. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  39. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  40. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  41. package/dist/solution/ShopDiscount/index.js +99 -42
  42. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  43. package/dist/solution/ShopDiscount/utils.js +43 -23
  44. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  45. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  46. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  47. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  48. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  49. package/lib/modules/Customer/index.js +5 -1
  50. package/lib/modules/Customer/types.d.ts +2 -0
  51. package/lib/modules/Discount/availability.d.ts +7 -0
  52. package/lib/modules/Discount/availability.js +43 -0
  53. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  54. package/lib/modules/Discount/entitlementPass.js +141 -0
  55. package/lib/modules/Discount/index.d.ts +2 -2
  56. package/lib/modules/Discount/index.js +23 -129
  57. package/lib/modules/Discount/types.d.ts +36 -5
  58. package/lib/modules/Order/index.d.ts +7 -1
  59. package/lib/modules/Order/index.js +213 -40
  60. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  61. package/lib/modules/Order/utils.d.ts +1 -1
  62. package/lib/modules/Order/utils.js +39 -3
  63. package/lib/modules/Payment/types.d.ts +21 -1
  64. package/lib/modules/Payment/types.js +1 -0
  65. package/lib/modules/Payment/walletpass.d.ts +1 -1
  66. package/lib/modules/Payment/walletpass.js +29 -9
  67. package/lib/modules/Rules/index.d.ts +2 -2
  68. package/lib/modules/Rules/index.js +357 -110
  69. package/lib/modules/Rules/types.d.ts +4 -0
  70. package/lib/server/modules/order/types.d.ts +2 -0
  71. package/lib/solution/BaseSales/index.d.ts +1 -0
  72. package/lib/solution/BaseSales/index.js +5 -2
  73. package/lib/solution/BaseSales/types.d.ts +2 -2
  74. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  75. package/lib/solution/BookingByStep/index.d.ts +1 -1
  76. package/lib/solution/BookingTicket/index.d.ts +1 -2
  77. package/lib/solution/BookingTicket/index.js +36 -33
  78. package/lib/solution/BookingTicket/types.d.ts +5 -1
  79. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  80. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  81. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  82. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  83. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  84. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  85. package/lib/solution/ShopDiscount/index.js +55 -9
  86. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  87. package/lib/solution/ShopDiscount/utils.js +42 -25
  88. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  89. 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
  /**
@@ -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)}`;
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 1 | 2 | 5 | 4 | 3 | 6;
329
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -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') {
@@ -14,7 +14,8 @@ const searchWalletPass = async (request, code) => {
14
14
  // 翻译识别码名称 0:不翻译 1:翻译
15
15
  relation_product: 1,
16
16
  // 组装关联商品: 0不处理 1处理
17
- with: ['customer'],
17
+ with_franchisor_data: 1,
18
+ with: ['customer', 'franchiseeWalletPass:shop_id,source_shop_id,product_id,use'],
18
19
  tags: ['point_card',
19
20
  // 积分卡
20
21
  'gift_card',
@@ -25,6 +26,8 @@ const searchWalletPass = async (request, code) => {
25
26
  // 折扣卡
26
27
  'good_pass',
27
28
  // 商品券
29
+ 'entitlement_pass',
30
+ // 月卡 / 年卡 / 多次使用卡
28
31
  'session_ticket',
29
32
  // 场次票
30
33
  'appointment_ticket' // 预约类门票
@@ -51,17 +54,18 @@ exports.searchWalletPass = searchWalletPass;
51
54
  const searchWallet = async (request, code) => {
52
55
  const params = {
53
56
  code,
54
- with_customer: 1
57
+ with_customer: 1,
58
+ with_franchisor_data: 1
55
59
  };
56
60
  try {
57
61
  const res = await request?.post('/wallet/detail/search', params);
58
- if (res?.code == 200 && !!res?.data) {
62
+ if (res?.status === true && res?.code === 200 && !!res?.data) {
59
63
  return {
60
64
  searchType: 'wallet',
61
65
  response: res
62
66
  };
63
67
  }
64
- throw new Error('没有找到对应的识别码');
68
+ throw new Error(res?.message || '没有找到对应的识别码');
65
69
  } catch (error) {
66
70
  throw error;
67
71
  }
@@ -6,6 +6,12 @@ export interface GlobalScanFormattedResult {
6
6
  searchType: GlobalScanSearchType;
7
7
  data: any;
8
8
  scanCode: string;
9
+ /** Wallet / Wallet Pass 来源客户 ID;跨店时必须先解析为当前店客户。 */
10
+ customerId?: string | number;
11
+ /** 仅 Wallet 返回;true 时禁止直接使用响应内的来源客户。 */
12
+ isCrossShopWallet?: boolean;
13
+ /** 总店 Wallet Pass 未共享给当前子店。 */
14
+ isWalletPassUnavailableAtStore?: boolean;
9
15
  }
10
16
  interface RawScanSearchResult {
11
17
  searchType?: GlobalScanSearchType;
@@ -36,14 +36,22 @@ function formatGlobalScanResult(raw, scanCode) {
36
36
  return {
37
37
  searchType,
38
38
  data: resultData?.customer,
39
- scanCode
39
+ scanCode,
40
+ customerId: resultData?.customer_id,
41
+ isCrossShopWallet: resultData?.is_cross_shop_wallet === true || Number(resultData?.is_cross_shop_wallet) === 1
40
42
  };
41
43
  }
42
44
  if (searchType === 'walletPass') {
45
+ const firstResult = resultData?.[0];
46
+ const isWalletPassUnavailableAtStore = firstResult?.is_franchisor_pass === 1 && firstResult?.franchisee_wallet_pass?.use !== 'enabled';
43
47
  return {
44
48
  searchType,
45
- data: resultData?.[0]?.customer,
46
- scanCode
49
+ data: firstResult?.customer,
50
+ scanCode,
51
+ customerId: firstResult?.customer_id ?? firstResult?.holder?.customer_id ?? firstResult?.customer?.id ?? firstResult?.customer?.customer_id,
52
+ ...(isWalletPassUnavailableAtStore ? {
53
+ isWalletPassUnavailableAtStore: true
54
+ } : {})
47
55
  };
48
56
  }
49
57
  if (searchType === 'product' || searchType === 'local_product') {
@@ -43,6 +43,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
43
43
  batchSearchByProductIds(productIds: number[]): Promise<Discount[]>;
44
44
  scanCode(code: string, customerId?: number): Promise<{
45
45
  isAvailable: boolean;
46
+ isAccepted?: boolean;
46
47
  productList: Record<string, any>[];
47
48
  discountList: Discount[];
48
49
  type: "server" | "clientCalc";
@@ -62,6 +63,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
62
63
  action?: 'create' | 'edit';
63
64
  with_good_pass?: 0 | 1;
64
65
  with_discount_card?: 0 | 1;
66
+ with_entitlement_pass?: 0 | 1;
65
67
  }): Promise<void>;
66
68
  }
67
69
  export default ShopDiscountImpl;