@pisell/pisellos 2.3.128 → 2.3.130

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 (160) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +3 -1
  3. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  4. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  8. package/dist/modules/Customer/index.js +6 -3
  9. package/dist/modules/Customer/types.d.ts +2 -0
  10. package/dist/modules/Discount/availability.d.ts +7 -0
  11. package/dist/modules/Discount/availability.js +49 -0
  12. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  13. package/dist/modules/Discount/entitlementPass.js +147 -0
  14. package/dist/modules/Discount/index.d.ts +2 -2
  15. package/dist/modules/Discount/index.js +37 -151
  16. package/dist/modules/Discount/types.d.ts +36 -5
  17. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  18. package/dist/modules/FulfillmentTiming/index.js +407 -0
  19. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  20. package/dist/modules/FulfillmentTiming/types.js +1 -0
  21. package/dist/modules/OpenData/types.d.ts +6 -0
  22. package/dist/modules/Order/index.d.ts +12 -0
  23. package/dist/modules/Order/index.js +498 -247
  24. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  25. package/dist/modules/Order/pickupTiming.js +53 -0
  26. package/dist/modules/Order/types.d.ts +5 -1
  27. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  28. package/dist/modules/Order/utils.d.ts +1 -1
  29. package/dist/modules/Order/utils.js +117 -66
  30. package/dist/modules/Payment/index.js +9 -10
  31. package/dist/modules/Payment/types.d.ts +21 -1
  32. package/dist/modules/Payment/types.js +2 -0
  33. package/dist/modules/Payment/walletpass.d.ts +1 -1
  34. package/dist/modules/Payment/walletpass.js +80 -47
  35. package/dist/modules/Rules/index.d.ts +2 -2
  36. package/dist/modules/Rules/index.js +480 -186
  37. package/dist/modules/Rules/types.d.ts +4 -0
  38. package/dist/modules/Schedule/index.d.ts +8 -0
  39. package/dist/modules/Schedule/index.js +141 -39
  40. package/dist/modules/index.d.ts +1 -0
  41. package/dist/modules/index.js +1 -0
  42. package/dist/plugins/request.d.ts +7 -0
  43. package/dist/server/modules/order/types.d.ts +2 -0
  44. package/dist/server/utils/small-ticket.d.ts +1 -85
  45. package/dist/server/utils/small-ticket.js +2 -2542
  46. package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
  47. package/dist/shared/payment/loadPaymentMethods.js +66 -0
  48. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  49. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -0
  50. package/dist/shared/receipt/small-ticket.d.ts +85 -0
  51. package/dist/shared/receipt/small-ticket.js +2576 -0
  52. package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  53. package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
  54. package/dist/solution/BaseSales/index.d.ts +25 -0
  55. package/dist/solution/BaseSales/index.js +1226 -1040
  56. package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
  57. package/dist/solution/BaseSales/pickupTiming.js +589 -0
  58. package/dist/solution/BaseSales/types.d.ts +2 -2
  59. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  60. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  61. package/dist/solution/BookingByStep/index.d.ts +1 -1
  62. package/dist/solution/BookingTicket/index.d.ts +4 -5
  63. package/dist/solution/BookingTicket/index.js +60 -63
  64. package/dist/solution/BookingTicket/types.d.ts +5 -1
  65. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  66. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  67. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  68. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  69. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  70. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  71. package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
  72. package/dist/solution/OrderInvoicePreview/index.js +269 -0
  73. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  74. package/dist/solution/ShopDiscount/index.js +99 -42
  75. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  76. package/dist/solution/ShopDiscount/utils.js +43 -23
  77. package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
  78. package/dist/solution/UnifiedBookingSales/index.js +874 -709
  79. package/dist/solution/index.d.ts +1 -0
  80. package/dist/solution/index.js +2 -1
  81. package/lib/index.d.ts +2 -0
  82. package/lib/index.js +21 -1
  83. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  84. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  85. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  87. package/lib/modules/Customer/index.js +5 -1
  88. package/lib/modules/Customer/types.d.ts +2 -0
  89. package/lib/modules/Discount/availability.d.ts +7 -0
  90. package/lib/modules/Discount/availability.js +43 -0
  91. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  92. package/lib/modules/Discount/entitlementPass.js +141 -0
  93. package/lib/modules/Discount/index.d.ts +2 -2
  94. package/lib/modules/Discount/index.js +23 -129
  95. package/lib/modules/Discount/types.d.ts +36 -5
  96. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  97. package/lib/modules/FulfillmentTiming/index.js +359 -0
  98. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  99. package/lib/modules/FulfillmentTiming/types.js +5 -0
  100. package/lib/modules/OpenData/types.d.ts +6 -0
  101. package/lib/modules/Order/index.d.ts +12 -0
  102. package/lib/modules/Order/index.js +252 -48
  103. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  104. package/lib/modules/Order/pickupTiming.js +61 -0
  105. package/lib/modules/Order/types.d.ts +5 -1
  106. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  107. package/lib/modules/Order/utils.d.ts +1 -1
  108. package/lib/modules/Order/utils.js +51 -7
  109. package/lib/modules/Payment/index.js +3 -4
  110. package/lib/modules/Payment/types.d.ts +21 -1
  111. package/lib/modules/Payment/types.js +1 -0
  112. package/lib/modules/Payment/walletpass.d.ts +1 -1
  113. package/lib/modules/Payment/walletpass.js +29 -9
  114. package/lib/modules/Rules/index.d.ts +2 -2
  115. package/lib/modules/Rules/index.js +357 -110
  116. package/lib/modules/Rules/types.d.ts +4 -0
  117. package/lib/modules/Schedule/index.d.ts +8 -0
  118. package/lib/modules/Schedule/index.js +68 -12
  119. package/lib/modules/index.d.ts +1 -0
  120. package/lib/modules/index.js +11 -0
  121. package/lib/plugins/request.d.ts +7 -0
  122. package/lib/server/modules/order/types.d.ts +2 -0
  123. package/lib/server/utils/small-ticket.d.ts +1 -85
  124. package/lib/server/utils/small-ticket.js +9 -2305
  125. package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
  126. package/lib/shared/payment/loadPaymentMethods.js +40 -0
  127. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
  128. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -0
  129. package/lib/shared/receipt/small-ticket.d.ts +85 -0
  130. package/lib/shared/receipt/small-ticket.js +2342 -0
  131. package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
  132. package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
  133. package/lib/solution/BaseSales/index.d.ts +25 -0
  134. package/lib/solution/BaseSales/index.js +102 -3
  135. package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
  136. package/lib/solution/BaseSales/pickupTiming.js +269 -0
  137. package/lib/solution/BaseSales/types.d.ts +2 -2
  138. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  139. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  140. package/lib/solution/BookingByStep/index.d.ts +1 -1
  141. package/lib/solution/BookingTicket/index.d.ts +4 -5
  142. package/lib/solution/BookingTicket/index.js +36 -33
  143. package/lib/solution/BookingTicket/types.d.ts +5 -1
  144. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  145. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  146. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  147. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  148. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  149. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  150. package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
  151. package/lib/solution/OrderInvoicePreview/index.js +192 -0
  152. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  153. package/lib/solution/ShopDiscount/index.js +55 -9
  154. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  155. package/lib/solution/ShopDiscount/utils.js +42 -25
  156. package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
  157. package/lib/solution/UnifiedBookingSales/index.js +132 -48
  158. package/lib/solution/index.d.ts +1 -0
  159. package/lib/solution/index.js +11 -0
  160. package/package.json +1 -1
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.parseSalesResponse = parseSalesResponse;
7
7
  var _orderCollectionIdentity = require("../../../modules/Order/utils/orderCollectionIdentity");
8
+ var _pickupTiming = require("../../../modules/Order/pickupTiming");
8
9
  /**
9
10
  * 把 `/order/sales/{id}` 响应(OrderData)解析为 ISalesDetail。
10
11
  *
@@ -64,6 +65,7 @@ function pickCustomer(raw) {
64
65
  */
65
66
  function isRootBooking(booking) {
66
67
  if (!booking || typeof booking !== 'object') return false;
68
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return false;
67
69
  const parentId = booking.parent_id;
68
70
  if (parentId === 0 || parentId === null || parentId === undefined) return true;
69
71
  return false;
@@ -71,6 +73,7 @@ function isRootBooking(booking) {
71
73
  function indexBookingsByProductUid(bookings) {
72
74
  const result = {};
73
75
  for (const b of bookings) {
76
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(b)) continue;
74
77
  const uid = b && (b.product_uid || b.metadata?.product_uid) || '';
75
78
  if (!uid) continue;
76
79
  const key = String(uid);
@@ -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 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 2 | 1 | 5 | 4 | 3 | 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;
@@ -52,10 +53,10 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
52
53
  * 在解决方案对外 ready 前准备 Invoice Document;失败只降级模板,不阻断销售。
53
54
  * 已由页面取得的 OpenData 直接交给模块接管,没有注入数据时再走 target-scoped 加载。
54
55
  */
55
- private prepareInvoiceTemplateAtSolutionReady;
56
+ protected prepareInvoiceTemplateAtSolutionReady(injectedOpenData?: OpenDataConfig): Promise<void>;
56
57
  protected getBookingTicketBusinessCode(): string | null;
57
58
  private getIdGeneratorPlugin;
58
- private loadOpenDataConfig;
59
+ protected loadOpenDataConfig(): Promise<OpenDataConfig | null>;
59
60
  getOpenData(): Promise<OpenDataConfig | null>;
60
61
  getInvoiceLayoutConfig(): Promise<InvoiceLayoutConfig>;
61
62
  getInvoiceTemplateSettings(): Promise<InvoiceTemplateSettings>;
@@ -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
  *
@@ -347,7 +346,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
347
346
  * 获取当前的客户搜索条件
348
347
  * @returns 当前搜索条件
349
348
  */
350
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
349
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
351
350
  /**
352
351
  * 获取客户列表状态(包含滚动加载相关状态)
353
352
  * @returns 客户状态
@@ -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
  }
@@ -8,12 +8,14 @@ exports.buildCustomerView = buildCustomerView;
8
8
  exports.indexBookingsByProductUid = indexBookingsByProductUid;
9
9
  exports.isWalkInCustomer = isWalkInCustomer;
10
10
  var _addTimeAvailability = require("./addTimeAvailability");
11
+ var _pickupTiming = require("../../../modules/Order/pickupTiming");
11
12
  /**
12
13
  * 仅按 booking.product_uid 建索引,避免发明 booking 与商品行之间的其它等价关系。
13
14
  */
14
15
  function indexBookingsByProductUid(bookings) {
15
16
  if (!Array.isArray(bookings) || bookings.length === 0) return {};
16
17
  return bookings.reduce((acc, booking) => {
18
+ if ((0, _pickupTiming.isFulfillmentTimingBooking)(booking)) return acc;
17
19
  const uid = booking?.product_uid;
18
20
  if (uid === undefined || uid === null || uid === '') return acc;
19
21
  const key = String(uid);
@@ -105,7 +107,7 @@ function isGiftProductLine(line) {
105
107
  function buildCartView(lines, bookings, options = {}) {
106
108
  const productLines = Array.isArray(lines) ? lines : [];
107
109
  const bookingList = Array.isArray(bookings) ? bookings : [];
108
- const childBookings = bookingList.filter(booking => booking.parent_id !== 0);
110
+ const childBookings = bookingList.filter(booking => booking.parent_id !== 0 && !(0, _pickupTiming.isFulfillmentTimingBooking)(booking));
109
111
  const bookingsByProductUid = indexBookingsByProductUid(childBookings);
110
112
  const linesByUid = indexProductsByUid(productLines);
111
113
  const addTimeLinesByBookingUid = indexAddTimeProductsByBookingUid(productLines);
@@ -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') {
@@ -0,0 +1,56 @@
1
+ import type { Module, ModuleOptions, PisellCore } from '../../types';
2
+ import { BaseModule } from '../../modules/BaseModule';
3
+ import type { InvoiceLayoutConfig } from '../../modules/OpenData';
4
+ import { type SmallTicketData } from '../../shared/receipt/small-ticket';
5
+ export interface OrderInvoicePreviewInput {
6
+ orderId: string | number;
7
+ tenantId: string | number;
8
+ shopId: string | number;
9
+ /** Changes on login/logout, without exposing credentials in state or cache keys. */
10
+ identity: string;
11
+ businessCode: string;
12
+ channel: string;
13
+ locale: string;
14
+ sourceRevision: string;
15
+ shop?: Record<string, any>;
16
+ }
17
+ export interface OrderInvoicePreviewResult {
18
+ identity: string;
19
+ sourceRevision: string;
20
+ generatedAt: string;
21
+ locale: string;
22
+ orderId: string | number;
23
+ source: Record<string, any>;
24
+ shop: Record<string, any>;
25
+ layout: InvoiceLayoutConfig;
26
+ smallTicketData: SmallTicketData;
27
+ }
28
+ export interface OrderInvoicePreviewState {
29
+ status: 'idle' | 'loading' | 'ready' | 'error';
30
+ result: OrderInvoicePreviewResult | null;
31
+ error: string | null;
32
+ }
33
+ /** Read-only, page-owned solution. No Order, Schedule, quotation or payment modules. */
34
+ export declare class OrderInvoicePreviewImpl extends BaseModule implements Module {
35
+ isSolution: boolean;
36
+ private request;
37
+ private state;
38
+ private listeners;
39
+ private generation;
40
+ private disposed;
41
+ private input?;
42
+ private activeKey;
43
+ private pending?;
44
+ private snapshotCache;
45
+ constructor(name?: string);
46
+ initialize(core: PisellCore, _options: ModuleOptions): void;
47
+ getState: () => OrderInvoicePreviewState;
48
+ subscribe: (listener: () => void) => (() => void);
49
+ private publish;
50
+ private getScope;
51
+ private loadContext;
52
+ private loadSource;
53
+ prepare(input: OrderInvoicePreviewInput): Promise<OrderInvoicePreviewResult>;
54
+ retry(): Promise<OrderInvoicePreviewResult>;
55
+ destroy(): void;
56
+ }