@pisell/pisellos 2.3.106 → 2.3.108

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 (69) hide show
  1. package/dist/modules/Discount/index.js +4 -1
  2. package/dist/modules/Discount/types.d.ts +10 -0
  3. package/dist/modules/OpenData/index.d.ts +15 -2
  4. package/dist/modules/OpenData/index.js +307 -19
  5. package/dist/modules/OpenData/types.d.ts +55 -0
  6. package/dist/modules/OpenData/types.js +7 -1
  7. package/dist/modules/OpenData/utils.d.ts +21 -1
  8. package/dist/modules/OpenData/utils.js +138 -0
  9. package/dist/modules/Order/index.d.ts +4 -2
  10. package/dist/modules/Order/index.js +69 -16
  11. package/dist/modules/Order/types.d.ts +13 -0
  12. package/dist/modules/Order/utils.d.ts +4 -1
  13. package/dist/modules/Order/utils.js +57 -3
  14. package/dist/plugins/request.d.ts +2 -1
  15. package/dist/plugins/request.js +4 -2
  16. package/dist/server/index.d.ts +14 -0
  17. package/dist/server/index.js +1732 -1285
  18. package/dist/server/modules/order/types.d.ts +50 -0
  19. package/dist/server/modules/order/types.js +2 -0
  20. package/dist/server/utils/small-ticket.d.ts +4 -1
  21. package/dist/server/utils/small-ticket.js +461 -96
  22. package/dist/solution/BaseSales/index.d.ts +7 -1
  23. package/dist/solution/BaseSales/index.js +128 -45
  24. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  25. package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  26. package/dist/solution/BookingByStep/index.d.ts +1 -1
  27. package/dist/solution/BookingTicket/index.d.ts +8 -3
  28. package/dist/solution/BookingTicket/index.js +558 -443
  29. package/dist/solution/Sales/index.d.ts +16 -1
  30. package/dist/solution/Sales/index.js +338 -63
  31. package/dist/solution/Sales/types.d.ts +10 -0
  32. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  33. package/dist/solution/UnifiedBookingSales/index.js +526 -447
  34. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
  35. package/lib/modules/Discount/index.js +4 -1
  36. package/lib/modules/Discount/types.d.ts +10 -0
  37. package/lib/modules/OpenData/index.d.ts +15 -2
  38. package/lib/modules/OpenData/index.js +230 -3
  39. package/lib/modules/OpenData/types.d.ts +55 -0
  40. package/lib/modules/OpenData/types.js +9 -1
  41. package/lib/modules/OpenData/utils.d.ts +21 -1
  42. package/lib/modules/OpenData/utils.js +126 -0
  43. package/lib/modules/Order/index.d.ts +4 -2
  44. package/lib/modules/Order/index.js +52 -1
  45. package/lib/modules/Order/types.d.ts +13 -0
  46. package/lib/modules/Order/utils.d.ts +4 -1
  47. package/lib/modules/Order/utils.js +58 -1
  48. package/lib/plugins/request.d.ts +2 -1
  49. package/lib/plugins/request.js +3 -2
  50. package/lib/server/index.d.ts +14 -0
  51. package/lib/server/index.js +453 -105
  52. package/lib/server/modules/order/types.d.ts +50 -0
  53. package/lib/server/modules/order/types.js +1 -0
  54. package/lib/server/utils/small-ticket.d.ts +4 -1
  55. package/lib/server/utils/small-ticket.js +427 -72
  56. package/lib/solution/BaseSales/index.d.ts +7 -1
  57. package/lib/solution/BaseSales/index.js +90 -7
  58. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  59. package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  60. package/lib/solution/BookingByStep/index.d.ts +1 -1
  61. package/lib/solution/BookingTicket/index.d.ts +8 -3
  62. package/lib/solution/BookingTicket/index.js +60 -15
  63. package/lib/solution/Sales/index.d.ts +16 -1
  64. package/lib/solution/Sales/index.js +168 -1
  65. package/lib/solution/Sales/types.d.ts +10 -0
  66. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  67. package/lib/solution/UnifiedBookingSales/index.js +44 -15
  68. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
  69. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import type { OpenDataConfig } from '../../modules/OpenData';
1
+ import type { InvoiceLayoutConfig, InvoiceTemplateSettings, OpenDataConfig } from '../../modules/OpenData';
2
2
  import type { ProductListLoadProductsParams, ProductListStoreQueryParams } from '../../modules/ProductList';
3
3
  import type { ProductData } from '../../modules/Product/types';
4
4
  import type { LoadScheduleAvailableDateParams } from '../../modules/Schedule/types';
@@ -217,7 +217,13 @@ export interface UnifiedBookingSalesDiscountResult {
217
217
  }
218
218
  export interface UnifiedBookingSalesApi {
219
219
  loadOpenData: (params: UnifiedBookingSalesLoadOpenDataParams) => Promise<OpenDataConfig>;
220
+ /** Returns the latest OpenData payload cached by this solution instance. */
220
221
  getOpenData: () => Promise<OpenDataConfig | null>;
222
+ /** Returns the normalized Documents Invoice layout for the active target. */
223
+ getInvoiceLayoutConfig: () => Promise<InvoiceLayoutConfig>;
224
+ /** Returns the Native Invoice template settings for the active target. */
225
+ getInvoiceTemplateSettings: () => Promise<InvoiceTemplateSettings>;
226
+ /** Date-first calendar availability backed by ScheduleModule. */
221
227
  loadScheduleAvailableDate: (params: LoadScheduleAvailableDateParams) => Promise<unknown>;
222
228
  loadProductsByScheduleDate: (params: UnifiedBookingSalesLoadProductsByScheduleDateParams) => Promise<unknown[]>;
223
229
  queryProducts: (params?: ProductListStoreQueryParams) => Promise<ProductData[]>;
@@ -95,7 +95,10 @@ class DiscountModule extends _BaseModule.BaseModule {
95
95
  return {
96
96
  discountList: goodPassList,
97
97
  availableWalletIds,
98
- virtualCurrencyList
98
+ virtualCurrencyList,
99
+ availableWalletPassList: availableWalletPassList.map(item => ({
100
+ ...(item || {})
101
+ }))
99
102
  };
100
103
  }
101
104
  normalizeVirtualCurrencyList(value) {
@@ -68,10 +68,20 @@ export interface DiscountWithReason {
68
68
  discountList: Discount[];
69
69
  unavailableReasonKey: DiscountFilterRejectKey | null;
70
70
  }
71
+ export interface WalletPassPrepareConfigItem {
72
+ id?: number | string | null;
73
+ tag?: string | null;
74
+ product_id?: number | string | null;
75
+ product_name?: string | null;
76
+ par_value?: string | number | null;
77
+ used_par_value?: string | number | null;
78
+ [key: string]: any;
79
+ }
71
80
  export interface DiscountPrepareConfigResult {
72
81
  discountList: Discount[];
73
82
  availableWalletIds: number[];
74
83
  virtualCurrencyList?: VirtualCurrencyAsset[];
84
+ availableWalletPassList?: WalletPassPrepareConfigItem[];
75
85
  }
76
86
  export interface VirtualCurrencyAsset extends Record<string, any> {
77
87
  id: number;
@@ -1,9 +1,9 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
3
  import type { ScheduleModule } from '../Schedule';
4
- import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult } from './types';
4
+ import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
5
5
  export * from './types';
6
- export { computeAvailability } from './utils';
6
+ export { computeAvailability, getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, normalizeInvoiceLayoutConfig, normalizeInvoiceLayoutFromTemplateSettings, normalizeInvoiceTemplateSettings, normalizeRawInvoiceTemplateSettings, resolveInvoiceReceiptLocales, } from './utils';
7
7
  export declare class OpenDataModule extends BaseModule implements Module {
8
8
  protected defaultName: string;
9
9
  protected defaultVersion: string;
@@ -15,6 +15,10 @@ export declare class OpenDataModule extends BaseModule implements Module {
15
15
  private openCache;
16
16
  private fatherModule;
17
17
  private otherParams;
18
+ private fetchRevision;
19
+ private invoiceTemplateCacheRevision;
20
+ private invoiceTemplateDocumentCache;
21
+ private invoiceTemplateDocumentInFlight;
18
22
  constructor(name?: string, version?: string);
19
23
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
20
24
  /**
@@ -24,8 +28,17 @@ export declare class OpenDataModule extends BaseModule implements Module {
24
28
  * openDataModule.updateOtherParams({ openCache: true, cacheId: 'cache-2' })
25
29
  */
26
30
  updateOtherParams(params: Record<string, any>): void;
31
+ private shouldSkipInvoiceTemplateDocument;
27
32
  fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
28
33
  getOpenData(): OpenDataConfig | null;
34
+ getInvoiceLayoutConfig(): InvoiceLayoutConfig;
35
+ getInvoiceTemplateSettings(): InvoiceTemplateSettings;
36
+ ensureInvoiceTemplateSettings(target: string): Promise<InvoiceTemplateSettings>;
37
+ private commitInvoiceTemplateSettings;
38
+ private resolveInvoiceTemplateSettings;
39
+ private buildInvoiceTemplateCacheKey;
40
+ private fetchInvoiceTemplateDocument;
41
+ private logInvoiceTemplateDocumentFallback;
29
42
  getLastFetchedAt(): number | null;
30
43
  /** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
31
44
  clearCache(): void;
@@ -5,7 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  OpenDataModule: true,
8
- computeAvailability: true
8
+ computeAvailability: true,
9
+ getDefaultInvoiceLayoutConfig: true,
10
+ getDefaultInvoiceTemplateSettings: true,
11
+ normalizeInvoiceLayoutConfig: true,
12
+ normalizeInvoiceLayoutFromTemplateSettings: true,
13
+ normalizeInvoiceTemplateSettings: true,
14
+ normalizeRawInvoiceTemplateSettings: true,
15
+ resolveInvoiceReceiptLocales: true
9
16
  };
10
17
  exports.OpenDataModule = void 0;
11
18
  Object.defineProperty(exports, "computeAvailability", {
@@ -14,6 +21,48 @@ Object.defineProperty(exports, "computeAvailability", {
14
21
  return _utils.computeAvailability;
15
22
  }
16
23
  });
24
+ Object.defineProperty(exports, "getDefaultInvoiceLayoutConfig", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _utils.getDefaultInvoiceLayoutConfig;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "getDefaultInvoiceTemplateSettings", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _utils.getDefaultInvoiceTemplateSettings;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "normalizeInvoiceLayoutConfig", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _utils.normalizeInvoiceLayoutConfig;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "normalizeInvoiceLayoutFromTemplateSettings", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _utils.normalizeInvoiceLayoutFromTemplateSettings;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "normalizeInvoiceTemplateSettings", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _utils.normalizeInvoiceTemplateSettings;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "normalizeRawInvoiceTemplateSettings", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _utils.normalizeRawInvoiceTemplateSettings;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "resolveInvoiceReceiptLocales", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _utils.resolveInvoiceReceiptLocales;
64
+ }
65
+ });
17
66
  var _BaseModule = require("../BaseModule");
18
67
  var _utils = require("./utils");
19
68
  var _types = require("./types");
@@ -28,6 +77,25 @@ Object.keys(_types).forEach(function (key) {
28
77
  }
29
78
  });
30
79
  });
80
+ function isRecord(value) {
81
+ return !!value && typeof value === 'object' && !Array.isArray(value);
82
+ }
83
+ function resolveInvoiceDocumentId(value) {
84
+ if (typeof value === 'number') {
85
+ return Number.isSafeInteger(value) && value > 0 ? String(value) : null;
86
+ }
87
+ if (typeof value !== 'string') return null;
88
+ const normalized = value.trim();
89
+ if (!/^\d+$/.test(normalized)) return null;
90
+ const numericId = Number(normalized);
91
+ return Number.isSafeInteger(numericId) && numericId > 0 ? String(numericId) : null;
92
+ }
93
+ function isLegacyInvoiceTemplate(value) {
94
+ if (typeof value !== 'string' || value.trim().length === 0) return false;
95
+ const normalized = value.trim();
96
+ const numericLike = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
97
+ return !numericLike.test(normalized);
98
+ }
31
99
  class OpenDataModule extends _BaseModule.BaseModule {
32
100
  defaultName = 'openData';
33
101
  defaultVersion = '1.0.0';
@@ -39,6 +107,10 @@ class OpenDataModule extends _BaseModule.BaseModule {
39
107
  openCache = false;
40
108
  fatherModule;
41
109
  otherParams = {};
110
+ fetchRevision = 0;
111
+ invoiceTemplateCacheRevision = 0;
112
+ invoiceTemplateDocumentCache = new Map();
113
+ invoiceTemplateDocumentInFlight = new Map();
42
114
  constructor(name, version) {
43
115
  super(name, version);
44
116
  }
@@ -47,6 +119,12 @@ class OpenDataModule extends _BaseModule.BaseModule {
47
119
  this.store = options.store;
48
120
  this.store.data = options.initialState?.data ?? null;
49
121
  this.store.lastFetchedAt = options.initialState?.lastFetchedAt ?? null;
122
+ // Document 解析结果只在当前模块实例内复用。页面刷新后即使恢复了原始
123
+ // OpenData,也必须重新查询一次 NocoBase,以取得当前模板内容。
124
+ this.store.invoiceTemplateSettings = null;
125
+ this.store.invoiceTemplateTarget = null;
126
+ this.store.invoiceTemplateDocumentId = null;
127
+ this.store.invoiceTemplateCacheKey = null;
50
128
  this.otherParams = options.otherParams || {};
51
129
  if (this.otherParams.cacheId) {
52
130
  this.openCache = this.otherParams.openCache ?? false;
@@ -74,7 +152,11 @@ class OpenDataModule extends _BaseModule.BaseModule {
74
152
  this.cacheId = this.otherParams.cacheId;
75
153
  this.fatherModule = this.otherParams.fatherModule;
76
154
  }
155
+ shouldSkipInvoiceTemplateDocument() {
156
+ return String(this.otherParams?.platform || '').trim().toLowerCase() === 'h5';
157
+ }
77
158
  async fetchOpenData(params) {
159
+ const fetchRevision = ++this.fetchRevision;
78
160
  const getData = this.appPlugin?.getData?.();
79
161
  const shopId = getData?.('shop_id');
80
162
  if (!shopId) throw new Error('[OpenDataModule] 无法获取 shop_id');
@@ -95,21 +177,166 @@ class OpenDataModule extends _BaseModule.BaseModule {
95
177
  throw new Error(response?.message || '获取 OpenData 配置失败');
96
178
  }
97
179
  const data = response?.data || {};
98
- this.store.data = data;
99
- this.store.lastFetchedAt = Date.now();
180
+ const resolvedInvoiceTemplate = await this.resolveInvoiceTemplateSettings(data, params.target);
181
+ // clearCache() 或后续请求发生后,旧响应不得复活已失效的 target 配置。
182
+ if (fetchRevision === this.fetchRevision) {
183
+ this.store.data = data;
184
+ this.store.lastFetchedAt = Date.now();
185
+ this.commitInvoiceTemplateSettings(params.target, resolvedInvoiceTemplate);
186
+ }
100
187
  return data;
101
188
  }
102
189
  getOpenData() {
103
190
  return this.store.data;
104
191
  }
192
+ getInvoiceLayoutConfig() {
193
+ return (0, _utils.normalizeInvoiceLayoutFromTemplateSettings)(this.getInvoiceTemplateSettings());
194
+ }
195
+ getInvoiceTemplateSettings() {
196
+ if (this.shouldSkipInvoiceTemplateDocument()) {
197
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
198
+ }
199
+ if (isRecord(this.store.invoiceTemplateSettings)) {
200
+ const documentId = resolveInvoiceDocumentId(this.store.data?.['documents.invoice_template']);
201
+ if (documentId) {
202
+ const target = this.store.invoiceTemplateTarget;
203
+ if (!target || this.store.invoiceTemplateCacheKey !== this.buildInvoiceTemplateCacheKey(target, documentId)) {
204
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
205
+ }
206
+ }
207
+ return (0, _utils.normalizeRawInvoiceTemplateSettings)(this.store.invoiceTemplateSettings);
208
+ }
209
+ if (isLegacyInvoiceTemplate(this.store.data?.['documents.invoice_template'])) {
210
+ return (0, _utils.normalizeInvoiceTemplateSettings)(this.store.data);
211
+ }
212
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
213
+ }
214
+ async ensureInvoiceTemplateSettings(target) {
215
+ const normalizedTarget = String(target || '').trim();
216
+ const config = this.store.data;
217
+ if (!normalizedTarget || !config) {
218
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
219
+ }
220
+ const fetchRevision = this.fetchRevision;
221
+ const resolved = await this.resolveInvoiceTemplateSettings(config, normalizedTarget);
222
+ if (fetchRevision !== this.fetchRevision || this.store.data !== config) {
223
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
224
+ }
225
+ this.commitInvoiceTemplateSettings(normalizedTarget, resolved);
226
+ return (0, _utils.normalizeRawInvoiceTemplateSettings)(resolved.settings);
227
+ }
228
+ commitInvoiceTemplateSettings(target, resolved) {
229
+ this.store.invoiceTemplateSettings = (0, _utils.normalizeRawInvoiceTemplateSettings)(resolved.settings);
230
+ this.store.invoiceTemplateTarget = target;
231
+ this.store.invoiceTemplateDocumentId = resolved.documentId;
232
+ this.store.invoiceTemplateCacheKey = resolved.cacheKey;
233
+ }
234
+ async resolveInvoiceTemplateSettings(config, target) {
235
+ if (this.shouldSkipInvoiceTemplateDocument()) {
236
+ return {
237
+ settings: (0, _utils.getDefaultInvoiceTemplateSettings)(),
238
+ documentId: null,
239
+ cacheKey: null
240
+ };
241
+ }
242
+ const rawTemplate = config['documents.invoice_template'];
243
+ const documentId = resolveInvoiceDocumentId(rawTemplate);
244
+ if (!documentId) {
245
+ return {
246
+ settings: isLegacyInvoiceTemplate(rawTemplate) ? (0, _utils.normalizeInvoiceTemplateSettings)(config) : (0, _utils.getDefaultInvoiceTemplateSettings)(),
247
+ documentId: null,
248
+ cacheKey: null
249
+ };
250
+ }
251
+ const cacheKey = this.buildInvoiceTemplateCacheKey(target, documentId);
252
+ if (this.store.invoiceTemplateTarget === target && this.store.invoiceTemplateDocumentId === documentId && this.store.invoiceTemplateCacheKey === cacheKey && isRecord(this.store.invoiceTemplateSettings)) {
253
+ return {
254
+ settings: (0, _utils.normalizeRawInvoiceTemplateSettings)(this.store.invoiceTemplateSettings),
255
+ documentId,
256
+ cacheKey
257
+ };
258
+ }
259
+ const cachedSettings = this.invoiceTemplateDocumentCache.get(cacheKey);
260
+ if (cachedSettings) {
261
+ return {
262
+ settings: (0, _utils.normalizeRawInvoiceTemplateSettings)(cachedSettings),
263
+ documentId,
264
+ cacheKey
265
+ };
266
+ }
267
+ let request = this.invoiceTemplateDocumentInFlight.get(cacheKey);
268
+ if (!request) {
269
+ const cacheRevision = this.invoiceTemplateCacheRevision;
270
+ request = this.fetchInvoiceTemplateDocument(documentId).catch(error => {
271
+ this.logInvoiceTemplateDocumentFallback(error, target, documentId);
272
+ return (0, _utils.getDefaultInvoiceTemplateSettings)();
273
+ }).then(settings => {
274
+ const normalized = (0, _utils.normalizeRawInvoiceTemplateSettings)(settings);
275
+ if (cacheRevision === this.invoiceTemplateCacheRevision) {
276
+ this.invoiceTemplateDocumentCache.set(cacheKey, normalized);
277
+ }
278
+ return normalized;
279
+ }).finally(() => {
280
+ if (this.invoiceTemplateDocumentInFlight.get(cacheKey) === request) {
281
+ this.invoiceTemplateDocumentInFlight.delete(cacheKey);
282
+ }
283
+ });
284
+ this.invoiceTemplateDocumentInFlight.set(cacheKey, request);
285
+ }
286
+ return {
287
+ settings: await request,
288
+ documentId,
289
+ cacheKey
290
+ };
291
+ }
292
+ buildInvoiceTemplateCacheKey(target, documentId) {
293
+ const getData = this.appPlugin?.getData?.();
294
+ return JSON.stringify([getData?.('tenant_id') ?? null, getData?.('shop_id') ?? null, target, documentId]);
295
+ }
296
+ async fetchInvoiceTemplateDocument(documentId) {
297
+ const response = await this.request.get(`/document:get?filterByTk=${encodeURIComponent(documentId)}`, {}, {
298
+ isNocobase: true,
299
+ prefix: false,
300
+ headers: {
301
+ 'x-data-source': 'pisell2'
302
+ },
303
+ customToast: () => {}
304
+ });
305
+ const document = response?.data;
306
+ if (!document || resolveInvoiceDocumentId(document.id) !== documentId) {
307
+ throw new Error(`Invoice Document ${documentId} 返回的 ID 不匹配`);
308
+ }
309
+ if (document.deleted_at !== null && document.deleted_at !== undefined) {
310
+ throw new Error(`Invoice Document ${documentId} 已被删除`);
311
+ }
312
+ if (!isRecord(document.data) || !isRecord(document.data.template_settings)) {
313
+ throw new Error(`Invoice Document ${documentId} 缺少 template_settings`);
314
+ }
315
+ return (0, _utils.normalizeRawInvoiceTemplateSettings)(document.data.template_settings);
316
+ }
317
+ logInvoiceTemplateDocumentFallback(error, target, documentId) {
318
+ console.warn('[OpenDataModule] Invoice Document 加载失败,使用 DEFAULT', {
319
+ target,
320
+ documentId,
321
+ message: error instanceof Error ? error.message : String(error)
322
+ });
323
+ }
105
324
  getLastFetchedAt() {
106
325
  return this.store.lastFetchedAt ?? null;
107
326
  }
108
327
 
109
328
  /** 清除内存与 sessionStorage 镜像中的 OpenData,供宿主切店时调用。 */
110
329
  clearCache() {
330
+ this.fetchRevision += 1;
331
+ this.invoiceTemplateCacheRevision += 1;
332
+ this.invoiceTemplateDocumentCache.clear();
333
+ this.invoiceTemplateDocumentInFlight.clear();
111
334
  this.store.data = null;
112
335
  this.store.lastFetchedAt = null;
336
+ this.store.invoiceTemplateSettings = null;
337
+ this.store.invoiceTemplateTarget = null;
338
+ this.store.invoiceTemplateDocumentId = null;
339
+ this.store.invoiceTemplateCacheKey = null;
113
340
  }
114
341
  checkAvailability(scheduleModule) {
115
342
  const scheduleList = scheduleModule ? scheduleModule?.getScheduleListByIds(this.store.data?.['availability.operating_hours'] || []) : undefined;
@@ -8,6 +8,49 @@ export interface MultiLangObject {
8
8
  original?: string;
9
9
  [key: string]: string | undefined;
10
10
  }
11
+ export declare const INVOICE_MODULE_KEYS: readonly ["reference", "brand", "custom_1", "order", "handover", "customer", "line_groups", "settlement", "custom_2", "payment", "card", "total_savings", "custom_3", "barcode"];
12
+ export type InvoiceModuleKey = (typeof INVOICE_MODULE_KEYS)[number];
13
+ /**
14
+ * Documents Registry 中的 Invoice 模块配置。
15
+ *
16
+ * 模块 key、显隐值及模块私有字段均由 Registry/Native 约定,OS 不做枚举收窄或改写。
17
+ */
18
+ export interface InvoiceTemplateModuleConfig {
19
+ key: string;
20
+ is_show?: unknown;
21
+ [key: string]: unknown;
22
+ }
23
+ export interface InvoiceModuleConfig extends InvoiceTemplateModuleConfig {
24
+ }
25
+ export interface InvoiceLayoutConfig {
26
+ locale?: string;
27
+ module: InvoiceModuleConfig[];
28
+ }
29
+ export interface InvoiceTemplateSettings {
30
+ template: string;
31
+ language: Record<string, number>;
32
+ modules: InvoiceTemplateModuleConfig[];
33
+ [key: string]: unknown;
34
+ }
35
+ export interface InvoiceDocumentResponse {
36
+ data?: {
37
+ id?: number | string;
38
+ deleted_at?: string | null;
39
+ data?: {
40
+ template_settings?: unknown;
41
+ };
42
+ };
43
+ }
44
+ export type RawInvoiceEditConfig = string | {
45
+ language?: unknown;
46
+ modules?: unknown;
47
+ [key: string]: unknown;
48
+ };
49
+ export type RawInvoiceLayoutConfig = string | {
50
+ locale?: unknown;
51
+ module?: unknown[];
52
+ [key: string]: unknown;
53
+ };
11
54
  export interface OpenDataConfig {
12
55
  'basic.enable'?: boolean;
13
56
  'basic.code'?: string | null;
@@ -45,11 +88,23 @@ export interface OpenDataConfig {
45
88
  label: string;
46
89
  value: number;
47
90
  }>;
91
+ 'documents.invoice_template'?: string | number;
92
+ 'documents.invoice_edit'?: RawInvoiceEditConfig;
93
+ /** @deprecated 仅保留旧调用方的类型兼容,Invoice 读取逻辑不再消费该字段。 */
94
+ 'documents.invoice'?: RawInvoiceLayoutConfig;
95
+ /** @deprecated Invoice 读取逻辑只消费扁平的 documents.invoice_* 字段。 */
96
+ documents?: {
97
+ invoice?: RawInvoiceLayoutConfig;
98
+ };
48
99
  [key: string]: any;
49
100
  }
50
101
  export interface OpenDataState {
51
102
  data: OpenDataConfig | null;
52
103
  lastFetchedAt: number | null;
104
+ invoiceTemplateSettings?: InvoiceTemplateSettings | null;
105
+ invoiceTemplateTarget?: string | null;
106
+ invoiceTemplateDocumentId?: string | null;
107
+ invoiceTemplateCacheKey?: string | null;
53
108
  }
54
109
  export interface OpenDataFetchParams {
55
110
  scope: string;
@@ -2,4 +2,12 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.INVOICE_MODULE_KEYS = void 0;
7
+ const INVOICE_MODULE_KEYS = exports.INVOICE_MODULE_KEYS = ['reference', 'brand', 'custom_1', 'order', 'handover', 'customer', 'line_groups', 'settlement', 'custom_2', 'payment', 'card', 'total_savings', 'custom_3', 'barcode'];
8
+
9
+ /**
10
+ * Documents Registry 中的 Invoice 模块配置。
11
+ *
12
+ * 模块 key、显隐值及模块私有字段均由 Registry/Native 约定,OS 不做枚举收窄或改写。
13
+ */
@@ -1,2 +1,22 @@
1
- import type { OpenDataAvailabilityResult, ComputeAvailabilityParams } from './types';
1
+ import type { OpenDataConfig, OpenDataAvailabilityResult, ComputeAvailabilityParams, InvoiceLayoutConfig, InvoiceTemplateSettings } from './types';
2
+ export declare function getDefaultInvoiceLayoutConfig(): InvoiceLayoutConfig;
3
+ export declare function getDefaultInvoiceTemplateSettings(): InvoiceTemplateSettings;
4
+ /**
5
+ * 将非 DEFAULT Invoice 模板启用的语言转换为 small_ticket_data locale。
6
+ * cn_en 是中英组合打印模式,因此展开为 en 与 zh_CN 两份数据。
7
+ */
8
+ export declare function resolveInvoiceReceiptLocales(settings?: InvoiceTemplateSettings | null): string[];
9
+ /**
10
+ * 规范化已经提取出的公开 template_settings 值,供打印入口复用。
11
+ */
12
+ export declare function normalizeRawInvoiceTemplateSettings(value: unknown): InvoiceTemplateSettings;
13
+ /**
14
+ * 从 OpenData Documents section 的两个扁平字段中构造 Native Invoice 配置。
15
+ */
16
+ export declare function normalizeInvoiceTemplateSettings(config: OpenDataConfig | null | undefined): InvoiceTemplateSettings;
17
+ export declare function normalizeInvoiceLayoutFromTemplateSettings(settings: InvoiceTemplateSettings | null | undefined): InvoiceLayoutConfig;
18
+ /**
19
+ * 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
20
+ */
21
+ export declare function normalizeInvoiceLayoutConfig(config: OpenDataConfig | null | undefined): InvoiceLayoutConfig;
2
22
  export declare function computeAvailability(params: ComputeAvailabilityParams): OpenDataAvailabilityResult;
@@ -4,9 +4,135 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.computeAvailability = computeAvailability;
7
+ exports.getDefaultInvoiceLayoutConfig = getDefaultInvoiceLayoutConfig;
8
+ exports.getDefaultInvoiceTemplateSettings = getDefaultInvoiceTemplateSettings;
9
+ exports.normalizeInvoiceLayoutConfig = normalizeInvoiceLayoutConfig;
10
+ exports.normalizeInvoiceLayoutFromTemplateSettings = normalizeInvoiceLayoutFromTemplateSettings;
11
+ exports.normalizeInvoiceTemplateSettings = normalizeInvoiceTemplateSettings;
12
+ exports.normalizeRawInvoiceTemplateSettings = normalizeRawInvoiceTemplateSettings;
13
+ exports.resolveInvoiceReceiptLocales = resolveInvoiceReceiptLocales;
7
14
  var _dayjs = _interopRequireDefault(require("dayjs"));
8
15
  var _getDateIsInSchedule = require("../Schedule/getDateIsInSchedule");
16
+ var _types = require("./types");
9
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function isRecord(value) {
19
+ return !!value && typeof value === 'object' && !Array.isArray(value);
20
+ }
21
+ function parseInvoiceRecord(value) {
22
+ let parsed = value;
23
+ if (typeof parsed === 'string') {
24
+ try {
25
+ parsed = JSON.parse(parsed);
26
+ } catch {
27
+ return null;
28
+ }
29
+ }
30
+ return isRecord(parsed) ? parsed : null;
31
+ }
32
+ function getDefaultInvoiceLayoutConfig() {
33
+ return {
34
+ module: _types.INVOICE_MODULE_KEYS.map(key => ({
35
+ key,
36
+ is_show: 1
37
+ }))
38
+ };
39
+ }
40
+ function getDefaultInvoiceTemplateSettings() {
41
+ return {
42
+ template: 'DEFAULT',
43
+ language: {},
44
+ modules: []
45
+ };
46
+ }
47
+ const INVOICE_RECEIPT_LOCALE_ORDER = ['en', 'zh_CN', 'zh_HK', 'ja', 'pt'];
48
+ const INVOICE_RECEIPT_LOCALE_MAPPING = {
49
+ en: ['en'],
50
+ zh_cn: ['zh_CN'],
51
+ zh_hk: ['zh_HK'],
52
+ ja: ['ja'],
53
+ pt: ['pt'],
54
+ cn_en: ['en', 'zh_CN']
55
+ };
56
+
57
+ /**
58
+ * 将非 DEFAULT Invoice 模板启用的语言转换为 small_ticket_data locale。
59
+ * cn_en 是中英组合打印模式,因此展开为 en 与 zh_CN 两份数据。
60
+ */
61
+ function resolveInvoiceReceiptLocales(settings) {
62
+ if (typeof settings?.template !== 'string' || settings.template.trim().length === 0 || settings.template.trim().toUpperCase() === 'DEFAULT' || !isRecord(settings.language)) {
63
+ return [];
64
+ }
65
+ const enabledLocales = new Set();
66
+ Object.entries(settings.language).forEach(([rawKey, count]) => {
67
+ if (typeof count !== 'number' || !Number.isFinite(count) || count <= 0) {
68
+ return;
69
+ }
70
+ const key = rawKey.trim().toLowerCase().replace(/-/g, '_');
71
+ INVOICE_RECEIPT_LOCALE_MAPPING[key]?.forEach(locale => {
72
+ enabledLocales.add(locale);
73
+ });
74
+ });
75
+ return INVOICE_RECEIPT_LOCALE_ORDER.filter(locale => enabledLocales.has(locale));
76
+ }
77
+ function normalizeInvoiceTemplate(value) {
78
+ if (typeof value !== 'string' || value.trim().length === 0) return 'DEFAULT';
79
+ return value.trim().toUpperCase() === 'DEFAULT' ? 'DEFAULT' : value;
80
+ }
81
+ function normalizeInvoiceLanguage(value) {
82
+ if (!isRecord(value)) return {};
83
+ if (Object.values(value).some(item => typeof item !== 'number')) return {};
84
+ return {
85
+ ...value
86
+ };
87
+ }
88
+ function normalizeInvoiceModules(value) {
89
+ if (!Array.isArray(value)) return [];
90
+ if (value.some(item => !isRecord(item) || typeof item.key !== 'string')) {
91
+ return [];
92
+ }
93
+ return value.map(item => ({
94
+ ...item
95
+ }));
96
+ }
97
+
98
+ /**
99
+ * 规范化已经提取出的公开 template_settings 值,供打印入口复用。
100
+ */
101
+ function normalizeRawInvoiceTemplateSettings(value) {
102
+ const parsed = parseInvoiceRecord(value);
103
+ if (!parsed) return getDefaultInvoiceTemplateSettings();
104
+ return {
105
+ ...parsed,
106
+ template: normalizeInvoiceTemplate(parsed.template),
107
+ language: normalizeInvoiceLanguage(parsed.language),
108
+ modules: normalizeInvoiceModules(parsed.modules)
109
+ };
110
+ }
111
+
112
+ /**
113
+ * 从 OpenData Documents section 的两个扁平字段中构造 Native Invoice 配置。
114
+ */
115
+ function normalizeInvoiceTemplateSettings(config) {
116
+ const parsedEdit = parseInvoiceRecord(config?.['documents.invoice_edit']);
117
+ return normalizeRawInvoiceTemplateSettings({
118
+ ...(parsedEdit ?? {}),
119
+ template: normalizeInvoiceTemplate(config?.['documents.invoice_template'])
120
+ });
121
+ }
122
+ function normalizeInvoiceLayoutFromTemplateSettings(settings) {
123
+ const modules = normalizeRawInvoiceTemplateSettings(settings).modules;
124
+ if (modules.length === 0) return getDefaultInvoiceLayoutConfig();
125
+ return {
126
+ module: modules
127
+ };
128
+ }
129
+
130
+ /**
131
+ * 将 invoice_edit.modules 原样投影为 Web Invoice 使用的 module 字段。
132
+ */
133
+ function normalizeInvoiceLayoutConfig(config) {
134
+ return normalizeInvoiceLayoutFromTemplateSettings(normalizeInvoiceTemplateSettings(config));
135
+ }
10
136
  function toBoolean(value) {
11
137
  if (typeof value === 'boolean') return value;
12
138
  if (typeof value === 'string') return value === 'true' || value === '1';
@@ -176,6 +176,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
176
176
  consumeSessionStorageRestore(): Record<string, any> | null;
177
177
  notifyTempOrderChanged(): void;
178
178
  private createDefaultTempOrderInstance;
179
+ private clearTempOrderPointCardSnapshot;
180
+ private writePointCardSnapshotFromPrepareConfig;
179
181
  private createExternalSaleNumber;
180
182
  private ensureExternalSaleNumber;
181
183
  private ensureRequestUniqueIdempotencyToken;
@@ -555,7 +557,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
555
557
  generateIdempotencyToken(): string;
556
558
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
557
559
  createOrder(params: CommitOrderParams['query']): {
558
- type: "appointment_booking" | "virtual";
560
+ type: "virtual" | "appointment_booking";
559
561
  platform: string;
560
562
  sales_channel: string;
561
563
  order_sales_channel: string;
@@ -632,4 +634,4 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
632
634
  getOrderInfo(order_id: number): Promise<any>;
633
635
  getVouchers(): any[];
634
636
  }
635
- export type { AddProductToOrderOptions, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
637
+ export type { AddProductToOrderOptions, OrderMetaList, PointCardSnapshotItem, RemoveProductsFromOrderOptions, SalesNote, SalesNoteDraftInput, SalesNoteLocalizedSelection, SalesNoteLocalizedText, SalesNoteRelation, SalesNoteTextInput, SetSalesNoteInput, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';