@pisell/pisellos 0.10.56 → 0.10.57

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 (111) hide show
  1. package/dist/modules/OpenData/index.js +2 -1
  2. package/dist/modules/Order/index.d.ts +2 -1
  3. package/dist/modules/Order/index.js +118 -59
  4. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  5. package/dist/modules/Order/utils/weighedProduct.js +94 -0
  6. package/dist/modules/Order/utils.d.ts +1 -1
  7. package/dist/modules/Order/utils.js +9 -6
  8. package/dist/modules/Payment/index.d.ts +0 -5
  9. package/dist/modules/Payment/index.js +35 -85
  10. package/dist/modules/ProductList/index.js +18 -5
  11. package/dist/modules/ResourcePlanner/planner.js +10 -8
  12. package/dist/modules/Rules/index.js +16 -14
  13. package/dist/modules/Rules/types.d.ts +2 -0
  14. package/dist/server/index.js +122 -69
  15. package/dist/server/modules/floor-plan/index.js +34 -3
  16. package/dist/server/modules/payment/index.d.ts +25 -6
  17. package/dist/server/modules/payment/index.js +660 -133
  18. package/dist/server/test.json +1 -1
  19. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  20. package/dist/shared/receipt/customerInvoiceLanguages.js +60 -0
  21. package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +5 -0
  22. package/dist/shared/receipt/loadCustomerInvoiceLayout.js +46 -4
  23. package/dist/shared/receipt/small-ticket.d.ts +11 -0
  24. package/dist/shared/receipt/small-ticket.js +430 -255
  25. package/dist/shared/receipt/templateVisibility.d.ts +23 -0
  26. package/dist/shared/receipt/templateVisibility.js +64 -0
  27. package/dist/solution/BaseSales/index.d.ts +4 -2
  28. package/dist/solution/BaseSales/index.js +1328 -1214
  29. package/dist/solution/BaseSales/types.d.ts +5 -1
  30. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
  31. package/dist/solution/BaseSales/utils.js +3 -2
  32. package/dist/solution/BookingByStep/index.d.ts +1 -1
  33. package/dist/solution/BookingTicket/index.d.ts +4 -1
  34. package/dist/solution/BookingTicket/index.js +120 -80
  35. package/dist/solution/OrderInvoicePreview/index.d.ts +10 -0
  36. package/dist/solution/OrderInvoicePreview/index.js +85 -14
  37. package/dist/solution/RegisterAndLogin/config.js +54 -11
  38. package/dist/solution/RegisterAndLogin/index.d.ts +2 -0
  39. package/dist/solution/RegisterAndLogin/index.js +1 -1
  40. package/dist/solution/RegisterAndLogin/utils.d.ts +12 -4
  41. package/dist/solution/RegisterAndLogin/utils.js +36 -16
  42. package/dist/solution/Sales/index.d.ts +2 -0
  43. package/dist/solution/Sales/index.js +15 -1
  44. package/dist/solution/ScanOrder/utils.js +3 -2
  45. package/dist/solution/UnifiedBookingSales/index.js +12 -13
  46. package/dist/solution/VenueBooking/index.d.ts +15 -2
  47. package/dist/solution/VenueBooking/index.js +1062 -785
  48. package/dist/solution/VenueBooking/types.d.ts +2 -1
  49. package/dist/solution/VenueBooking/types.js +1 -0
  50. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  51. package/dist/solution/VenueBooking/utils/dateSummary.js +7 -4
  52. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  53. package/dist/solution/VenueBooking/utils/smartPricing.js +273 -0
  54. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  55. package/dist/solution/VenueBooking/utils/timeSlot.js +6 -3
  56. package/lib/modules/OpenData/index.js +2 -1
  57. package/lib/modules/Order/index.d.ts +2 -1
  58. package/lib/modules/Order/index.js +71 -11
  59. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  60. package/lib/modules/Order/utils/weighedProduct.js +89 -0
  61. package/lib/modules/Order/utils.d.ts +1 -1
  62. package/lib/modules/Order/utils.js +5 -3
  63. package/lib/modules/Payment/index.d.ts +0 -5
  64. package/lib/modules/Payment/index.js +3 -28
  65. package/lib/modules/ProductList/index.js +14 -1
  66. package/lib/modules/ResourcePlanner/planner.js +10 -8
  67. package/lib/modules/Rules/index.js +16 -14
  68. package/lib/modules/Rules/types.d.ts +2 -0
  69. package/lib/server/index.js +72 -28
  70. package/lib/server/modules/floor-plan/index.js +29 -1
  71. package/lib/server/modules/payment/index.d.ts +25 -6
  72. package/lib/server/modules/payment/index.js +350 -78
  73. package/lib/server/test.json +1 -1
  74. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +8 -0
  75. package/lib/shared/receipt/customerInvoiceLanguages.js +58 -0
  76. package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +5 -0
  77. package/lib/shared/receipt/loadCustomerInvoiceLayout.js +42 -4
  78. package/lib/shared/receipt/small-ticket.d.ts +11 -0
  79. package/lib/shared/receipt/small-ticket.js +234 -30
  80. package/lib/shared/receipt/templateVisibility.d.ts +23 -0
  81. package/lib/shared/receipt/templateVisibility.js +63 -0
  82. package/lib/solution/BaseSales/index.d.ts +4 -2
  83. package/lib/solution/BaseSales/index.js +79 -18
  84. package/lib/solution/BaseSales/types.d.ts +5 -1
  85. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
  86. package/lib/solution/BaseSales/utils.js +2 -1
  87. package/lib/solution/BookingByStep/index.d.ts +1 -1
  88. package/lib/solution/BookingTicket/index.d.ts +4 -1
  89. package/lib/solution/BookingTicket/index.js +14 -2
  90. package/lib/solution/OrderInvoicePreview/index.d.ts +10 -0
  91. package/lib/solution/OrderInvoicePreview/index.js +61 -7
  92. package/lib/solution/RegisterAndLogin/config.js +57 -11
  93. package/lib/solution/RegisterAndLogin/index.d.ts +2 -0
  94. package/lib/solution/RegisterAndLogin/index.js +9 -1
  95. package/lib/solution/RegisterAndLogin/utils.d.ts +12 -4
  96. package/lib/solution/RegisterAndLogin/utils.js +24 -17
  97. package/lib/solution/Sales/index.d.ts +2 -0
  98. package/lib/solution/Sales/index.js +10 -1
  99. package/lib/solution/ScanOrder/utils.js +2 -1
  100. package/lib/solution/UnifiedBookingSales/index.js +5 -6
  101. package/lib/solution/VenueBooking/index.d.ts +15 -2
  102. package/lib/solution/VenueBooking/index.js +243 -96
  103. package/lib/solution/VenueBooking/types.d.ts +2 -1
  104. package/lib/solution/VenueBooking/types.js +1 -0
  105. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  106. package/lib/solution/VenueBooking/utils/dateSummary.js +7 -4
  107. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +71 -0
  108. package/lib/solution/VenueBooking/utils/smartPricing.js +224 -0
  109. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -0
  110. package/lib/solution/VenueBooking/utils/timeSlot.js +5 -2
  111. package/package.json +1 -1
@@ -25,6 +25,7 @@ var _types3 = require("./modules/order/types");
25
25
  var _filterOrders = require("./modules/order/utils/filterOrders");
26
26
  var _filterBookings = require("./modules/order/utils/filterBookings");
27
27
  var _smallTicket = require("./utils/small-ticket");
28
+ var _templateVisibility = require("../shared/receipt/templateVisibility");
28
29
  var _BaseSales = require("../solution/BaseSales");
29
30
  var _paymentUtils = require("../modules/Order/payment-utils");
30
31
  var _salesNotes = require("../modules/Order/salesNotes");
@@ -1296,6 +1297,10 @@ class Server {
1296
1297
  method: 'get',
1297
1298
  path: '/shop/pay/custom-payment/all',
1298
1299
  handler: this.handlePaymentMethods.bind(this)
1300
+ }, {
1301
+ method: 'get',
1302
+ path: '/pay/custom-payment/all',
1303
+ handler: this.handlePaymentMethods.bind(this)
1299
1304
  }, {
1300
1305
  method: 'get',
1301
1306
  path: '/shop/quotation/available',
@@ -3847,7 +3852,8 @@ class Server {
3847
3852
  }
3848
3853
  const printableOrder = await this.withLocalSmallTicketData(params.order, {
3849
3854
  requireFullyPaid: params.requireFullyPaid,
3850
- invoiceTemplateSettings: params.invoiceTemplateSettings
3855
+ invoiceTemplateSettings: params.invoiceTemplateSettings,
3856
+ applyTemplateVisibility: true
3851
3857
  });
3852
3858
  if (!(0, _smallTicket.hasSmallTicketData)(printableOrder.payment_info?.small_ticket_data)) {
3853
3859
  return {
@@ -3869,9 +3875,11 @@ class Server {
3869
3875
  invoiceLayoutConfig: params.invoiceLayoutConfig,
3870
3876
  invoiceTemplateSettings: params.invoiceTemplateSettings
3871
3877
  });
3878
+ // Receipt visibility belongs to this output only. Do not return a filtered
3879
+ // snapshot to callers that may retain the order for later sync or reprints.
3872
3880
  return {
3873
3881
  printed: true,
3874
- order: printableOrder
3882
+ order: (0, _templateVisibility.requiresInvoiceDataFiltering)(params.invoiceTemplateSettings) ? params.order : printableOrder
3875
3883
  };
3876
3884
  }
3877
3885
  shouldLookupLocalPrintOrder(input) {
@@ -4080,7 +4088,10 @@ class Server {
4080
4088
  small_ticket_data_flag: 1,
4081
4089
  payment_info: paymentInfo
4082
4090
  }, {
4083
- locales: this.normalizeRequestedReceiptLocales(input.locales)
4091
+ locales: this.normalizeRequestedReceiptLocales(input.locales),
4092
+ invoiceTemplateSettings: input.template_settings === undefined ? undefined : this.normalizePrintInvoiceTemplateSettings(input.template_settings),
4093
+ applyTemplateVisibility: true,
4094
+ includeReceiptKeys: input.template_settings !== undefined
4084
4095
  });
4085
4096
  const smallTicketData = rebuiltOrder.payment_info?.small_ticket_data;
4086
4097
  if (!(0, _smallTicket.hasSmallTicketData)(smallTicketData)) {
@@ -4098,7 +4109,17 @@ class Server {
4098
4109
  status: true,
4099
4110
  message: '',
4100
4111
  data: {
4101
- small_ticket_data: smallTicketData
4112
+ small_ticket_data: smallTicketData,
4113
+ template_visibility_applied: true,
4114
+ // These products and currency settings are the exact source used for
4115
+ // this receipt, not the potentially newer active tempOrder.
4116
+ source: {
4117
+ ...rebuiltOrder,
4118
+ payment_info: {
4119
+ ...(rebuiltOrder.payment_info || {}),
4120
+ small_ticket_data: undefined
4121
+ }
4122
+ }
4102
4123
  }
4103
4124
  };
4104
4125
  } catch (error) {
@@ -4339,15 +4360,24 @@ class Server {
4339
4360
  });
4340
4361
  if (pendingResult?.status === true) {
4341
4362
  const pendingOrder = pendingResult.data;
4342
- if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData) && this.isSalesOrderFullyPaid(pendingOrder) && this.shouldAutoPrintCheckoutReceipt()) {
4343
- await this.dispatchLocalReceiptPrint({
4344
- checkoutData,
4345
- order: pendingOrder,
4346
- response: pendingResult,
4347
- requireFullyPaid: true,
4348
- invoiceLayoutConfig,
4349
- invoiceTemplateSettings
4350
- });
4363
+ if (pendingOrder && this.shouldBuildSmallTicketData(checkoutData, invoiceTemplateSettings) && this.isSalesOrderFullyPaid(pendingOrder) && this.shouldAutoPrintCheckoutReceipt()) {
4364
+ try {
4365
+ await this.dispatchLocalReceiptPrint({
4366
+ checkoutData,
4367
+ order: pendingOrder,
4368
+ response: pendingResult,
4369
+ requireFullyPaid: true,
4370
+ invoiceLayoutConfig,
4371
+ invoiceTemplateSettings
4372
+ });
4373
+ } catch (error) {
4374
+ // The sale is already persisted. A failed receipt must not cancel its
4375
+ // sync task or send an unfiltered fallback to the printer.
4376
+ pendingResult.receipt_print_error = this.getUnknownErrorMessage(error);
4377
+ this.logError(`${title}: 小票生成失败,订单仍继续同步`, {
4378
+ error: pendingResult.receipt_print_error
4379
+ });
4380
+ }
4351
4381
  }
4352
4382
  await this.dispatchCheckoutSyncTask({
4353
4383
  backendPath,
@@ -4405,16 +4435,24 @@ class Server {
4405
4435
  }
4406
4436
  const response = this.withSyncedOrderIdInCheckoutResponse(syncResult.normalizedResponse, syncResult.syncedOrder);
4407
4437
  const syncedOrder = syncResult.syncedOrder;
4408
- if (syncedOrder && this.shouldBuildSmallTicketData(syncResult.checkoutData) && this.isSalesOrderFullyPaid(syncedOrder)) {
4409
- await this.dispatchLocalReceiptPrint({
4410
- checkoutData: syncResult.checkoutData,
4411
- order: syncedOrder,
4412
- response: syncResult.normalizedResponse,
4413
- requireFullyPaid: true,
4414
- invoiceLayoutConfig,
4415
- invoiceTemplateSettings
4416
- // print_all 的 type=0 是收据打印;不要沿用同步成功后的券/手环打印 type=99。
4417
- });
4438
+ if (syncedOrder && this.shouldBuildSmallTicketData(syncResult.checkoutData, invoiceTemplateSettings) && this.isSalesOrderFullyPaid(syncedOrder)) {
4439
+ try {
4440
+ await this.dispatchLocalReceiptPrint({
4441
+ checkoutData: syncResult.checkoutData,
4442
+ order: syncedOrder,
4443
+ response: syncResult.normalizedResponse,
4444
+ requireFullyPaid: true,
4445
+ invoiceLayoutConfig,
4446
+ invoiceTemplateSettings
4447
+ });
4448
+ } catch (error) {
4449
+ // Checkout already succeeded remotely; report the receipt failure
4450
+ // separately instead of implying that payment/order creation failed.
4451
+ response.receipt_print_error = this.getUnknownErrorMessage(error);
4452
+ this.logError(`${title}: 小票生成失败,订单已同步`, {
4453
+ error: response.receipt_print_error
4454
+ });
4455
+ }
4418
4456
  }
4419
4457
  return response;
4420
4458
  } catch (error) {
@@ -4623,10 +4661,12 @@ class Server {
4623
4661
  if (this.core.context?.getPlatform?.() !== 'android') return true;
4624
4662
  return this.app?.storage?.getStorage?.(AUTO_PRINT_STORAGE_KEY) !== 'false';
4625
4663
  }
4626
- shouldBuildSmallTicketData(order) {
4664
+ shouldBuildSmallTicketData(order, invoiceTemplateSettings) {
4627
4665
  if (!order || typeof order !== 'object') return false;
4628
- // if (hasSmallTicketData(order.payment_info?.small_ticket_data)) return false;
4629
- return Number(order.small_ticket_data_flag ?? order.smallTicketDataFlag ?? 0) === 1;
4666
+ const flag = order.small_ticket_data_flag ?? order.smallTicketDataFlag;
4667
+ // A synced order can omit the generation flag; required display filtering
4668
+ // still rebuilds its output. An explicit 0 retains the no-auto-print intent.
4669
+ return Number(flag ?? 0) === 1 || flag == null && (0, _templateVisibility.requiresInvoiceDataFiltering)(invoiceTemplateSettings);
4630
4670
  }
4631
4671
  shouldPrintSyncedOrder(params) {
4632
4672
  if (this.hasPaymentStatus(params.syncedOrder)) {
@@ -4930,7 +4970,8 @@ class Server {
4930
4970
  }
4931
4971
  }
4932
4972
  async withLocalSmallTicketData(order, options) {
4933
- if (!this.shouldBuildSmallTicketData(order)) return order;
4973
+ const mustApplyVisibility = options?.applyTemplateVisibility === true && (0, _templateVisibility.requiresInvoiceDataFiltering)(options.invoiceTemplateSettings);
4974
+ if (!this.shouldBuildSmallTicketData(order) && !mustApplyVisibility) return order;
4934
4975
  if (options?.requireFullyPaid && !this.isSalesOrderFullyPaid(order)) return order;
4935
4976
  try {
4936
4977
  const normalizedCollections = (0, _orderCollectionIdentity.normalizeOrderCollections)(order, {
@@ -4954,7 +4995,9 @@ class Server {
4954
4995
  order: enrichedOrder,
4955
4996
  shopInfo: this.getSmallTicketShopInfo(),
4956
4997
  locales: [...(0, _OpenData.resolveInvoiceReceiptLocales)(options?.invoiceTemplateSettings), ...(options?.locales || [])],
4957
- productMap
4998
+ productMap,
4999
+ includeReceiptKeys: options?.includeReceiptKeys,
5000
+ templateSettings: options?.applyTemplateVisibility ? options.invoiceTemplateSettings : undefined
4958
5001
  });
4959
5002
  return {
4960
5003
  ...enrichedOrder,
@@ -4967,6 +5010,7 @@ class Server {
4967
5010
  this.logError('withLocalSmallTicketData: 生成本地小票数据失败', {
4968
5011
  error: error instanceof Error ? error.message : String(error)
4969
5012
  });
5013
+ if (mustApplyVisibility) throw error;
4970
5014
  return order;
4971
5015
  }
4972
5016
  }
@@ -9,6 +9,30 @@ var _types = require("./types");
9
9
  const FLOOR_PLAN_SYNC_DEBOUNCE_MS = 3000;
10
10
  const FLOOR_PLAN_STORE_NAME = 'floor_plans';
11
11
 
12
+ /**
13
+ * Request failures can be plain response objects (rather than Error instances).
14
+ * Keep diagnostics useful without allowing the UI bridge to stringify them as
15
+ * "[object Object]".
16
+ */
17
+ function getRequestErrorInfo(error) {
18
+ if (error instanceof Error && error.message) return {
19
+ message: error.message
20
+ };
21
+ if (typeof error === 'string' && error) return {
22
+ message: error
23
+ };
24
+ const value = error;
25
+ const response = value?.resData?.res ?? value?.response?.data ?? value?.data ?? value;
26
+ const candidates = [value?.message, value?.error, response?.message, response?.error];
27
+ const message = candidates.find(candidate => typeof candidate === 'string' && candidate.trim() !== '');
28
+ return {
29
+ message: message || '平面图加载失败(未提供错误详情)',
30
+ code: response?.code ?? value?.code,
31
+ status: response?.status ?? value?.status,
32
+ httpStatus: value?.response?.status
33
+ };
34
+ }
35
+
12
36
  /**
13
37
  * 平面图模块:预加载列表、pubsub 同步、供 OS Server 路由读本地 store
14
38
  */
@@ -144,8 +168,12 @@ class FloorPlanModule extends _BaseModule.BaseModule {
144
168
  const list = Array.isArray(raw) ? raw : [];
145
169
  return list;
146
170
  } catch (e) {
171
+ const errorInfo = getRequestErrorInfo(e);
147
172
  this.logWarning('loadListFromServer 失败', {
148
- error: e instanceof Error ? e.message : String(e)
173
+ error: errorInfo.message,
174
+ code: errorInfo.code,
175
+ status: errorInfo.status,
176
+ httpStatus: errorInfo.httpStatus
149
177
  });
150
178
  return [];
151
179
  }
@@ -7,22 +7,41 @@ export declare class PaymentServerModule extends BaseModule implements Module {
7
7
  private request;
8
8
  private app;
9
9
  private logger;
10
+ private dbManager;
10
11
  private store;
11
- private payMethodMemoryCache;
12
- private payMethodListInFlight;
12
+ private paymentDataSource;
13
+ private initialLoadInFlight;
14
+ private refreshInFlight;
15
+ private hasLoadedPayMethods;
16
+ private hasEmittedLoaded;
17
+ private syncTimer;
18
+ private pendingMessageUuids;
19
+ private queuedTrailingRefresh;
20
+ private trailingMessageUuids;
13
21
  constructor(name?: string, version?: string);
14
22
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
23
+ preload(): Promise<void>;
15
24
  getPayMethodListAsync(options?: {
16
25
  shouldFilter?: boolean;
17
26
  }): Promise<PaymentMethod[]>;
18
- clearPayMethodCache(): void;
19
- private loadPayMethodListAsync;
27
+ private ensureInitialPayMethods;
28
+ private initPaymentDataSource;
29
+ private setupPaymentMethodSync;
30
+ private schedulePaymentMethodRefresh;
31
+ private refreshPayMethodsSingleFlight;
32
+ private performRemoteRefresh;
20
33
  private fetchRemotePayMethods;
21
- private shouldFilterPayMethods;
34
+ private loadPayMethodsFromSQLite;
35
+ private replacePayMethodsInSQLite;
36
+ private resolveCurrentShopScope;
37
+ private stripSnapshotFields;
38
+ private arePayMethodsEqual;
22
39
  private resolvePayMethods;
23
40
  private filterPayMethods;
24
- private setPayMethodCache;
41
+ private setPayMethodMirror;
42
+ private getErrorMessage;
25
43
  private logInfo;
26
44
  private logWarning;
27
45
  private logError;
46
+ destroy(): void;
28
47
  }