@pisell/pisellos 2.2.326 → 2.2.328

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 (32) hide show
  1. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -1
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.js +60 -15
  3. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  4. package/dist/modules/OpenData/index.d.ts +8 -1
  5. package/dist/modules/OpenData/index.js +276 -95
  6. package/dist/modules/Order/index.d.ts +1 -1
  7. package/dist/modules/Product/index.d.ts +1 -1
  8. package/dist/server/index.d.ts +3 -0
  9. package/dist/server/index.js +857 -598
  10. package/dist/server/modules/order/index.d.ts +1 -0
  11. package/dist/server/modules/order/index.js +51 -51
  12. package/dist/solution/BookingByStep/index.d.ts +1 -1
  13. package/dist/solution/Sales/index.d.ts +2 -5
  14. package/dist/solution/Sales/index.js +117 -143
  15. package/dist/solution/Sales/types.d.ts +6 -0
  16. package/dist/solution/Sales/types.js +2 -0
  17. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +2 -1
  18. package/lib/model/strategy/adapter/dataVariant/evaluator.js +40 -6
  19. package/lib/modules/OpenData/index.d.ts +8 -1
  20. package/lib/modules/OpenData/index.js +123 -21
  21. package/lib/modules/Order/index.d.ts +1 -1
  22. package/lib/modules/Product/index.d.ts +1 -1
  23. package/lib/server/index.d.ts +3 -0
  24. package/lib/server/index.js +155 -18
  25. package/lib/server/modules/order/index.d.ts +1 -0
  26. package/lib/server/modules/order/index.js +4 -3
  27. package/lib/solution/BookingByStep/index.d.ts +1 -1
  28. package/lib/solution/Sales/index.d.ts +2 -5
  29. package/lib/solution/Sales/index.js +32 -66
  30. package/lib/solution/Sales/types.d.ts +6 -0
  31. package/lib/solution/Sales/types.js +1 -0
  32. package/package.json +1 -1
@@ -26,9 +26,6 @@ Object.keys(_types).forEach(function (key) {
26
26
  var _OpenData = require("../../modules/OpenData");
27
27
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
28
  const UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
29
- const INVOICE_OPEN_DATA_SECTION_CODES = ['documents'];
30
- const INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
31
-
32
29
  /**
33
30
  * Sales 解决方案基础骨架
34
31
  *
@@ -51,9 +48,6 @@ class SalesImpl extends _BaseModule.BaseModule {
51
48
  request;
52
49
  logger; // LoggerManager 实例
53
50
  invoiceOpenDataModule = null;
54
- invoiceOpenDataTarget = null;
55
- invoiceOpenDataInFlight = null;
56
- invoiceOpenDataInFlightTarget = null;
57
51
  constructor(name, version) {
58
52
  super(name, version);
59
53
  }
@@ -86,9 +80,6 @@ class SalesImpl extends _BaseModule.BaseModule {
86
80
  // 在这里补充从 Server/Order 读取 currentDay 原始数据并转换为预约列表。
87
81
 
88
82
  this.logger = appPlugin?.getApp().logger;
89
- this.invoiceOpenDataTarget = null;
90
- this.invoiceOpenDataInFlight = null;
91
- this.invoiceOpenDataInFlightTarget = null;
92
83
  this.invoiceOpenDataModule = new _OpenData.OpenDataModule(`${this.name}_invoiceOpenData`);
93
84
  this.core.registerModule(this.invoiceOpenDataModule, {
94
85
  initialState: {},
@@ -175,51 +166,6 @@ class SalesImpl extends _BaseModule.BaseModule {
175
166
  const normalized = String(channel ?? contextChannel ?? '').trim();
176
167
  return !normalized || normalized === 'system' ? 'pos' : normalized;
177
168
  }
178
- async loadInvoiceOpenData(businessCode, channel) {
179
- if (!this.invoiceOpenDataModule) {
180
- throw new Error('Sales Invoice OpenData 模块未初始化');
181
- }
182
- const target = `${businessCode}+${channel}`;
183
- const cachedData = this.invoiceOpenDataModule.getOpenData();
184
- const lastFetchedAt = this.invoiceOpenDataModule.getLastFetchedAt();
185
- if (cachedData && this.invoiceOpenDataTarget === target && typeof lastFetchedAt === 'number' && Date.now() - lastFetchedAt < INVOICE_OPEN_DATA_CACHE_TTL) {
186
- if (typeof this.invoiceOpenDataModule.ensureInvoiceTemplateSettings === 'function') {
187
- await this.invoiceOpenDataModule.ensureInvoiceTemplateSettings(target);
188
- }
189
- return cachedData;
190
- }
191
- if (this.invoiceOpenDataInFlight) {
192
- if (this.invoiceOpenDataInFlightTarget === target) {
193
- return this.invoiceOpenDataInFlight;
194
- }
195
- try {
196
- await this.invoiceOpenDataInFlight;
197
- } catch {
198
- // 另一 target 的失败不应阻断当前 target 获取自己的 Documents 配置。
199
- }
200
- return this.loadInvoiceOpenData(businessCode, channel);
201
- }
202
- const request = this.invoiceOpenDataModule.fetchOpenData({
203
- scope: 'board',
204
- target,
205
- section_code: [...INVOICE_OPEN_DATA_SECTION_CODES]
206
- });
207
- this.invoiceOpenDataInFlight = request;
208
- this.invoiceOpenDataInFlightTarget = target;
209
- try {
210
- const openData = await request;
211
- // clearOpenDataCache() 或后续请求接管后,旧响应不得复活 target 归属。
212
- if (this.invoiceOpenDataInFlight === request) {
213
- this.invoiceOpenDataTarget = target;
214
- }
215
- return openData;
216
- } finally {
217
- if (this.invoiceOpenDataInFlight === request) {
218
- this.invoiceOpenDataInFlight = null;
219
- this.invoiceOpenDataInFlightTarget = null;
220
- }
221
- }
222
- }
223
169
  logInvoiceOpenDataFallback(error) {
224
170
  const message = error instanceof Error ? error.message : String(error);
225
171
  if (this.logger?.addLog) {
@@ -236,16 +182,11 @@ class SalesImpl extends _BaseModule.BaseModule {
236
182
  }
237
183
  async resolveInvoiceConfigs(businessCode, channel) {
238
184
  try {
239
- await this.loadInvoiceOpenData(businessCode, channel);
240
- if (this.invoiceOpenDataTarget !== `${businessCode}+${channel}`) {
241
- return {
242
- invoice: (0, _OpenData.getDefaultInvoiceLayoutConfig)(),
243
- templateSettings: (0, _OpenData.getDefaultInvoiceTemplateSettings)()
244
- };
245
- }
185
+ if (!this.invoiceOpenDataModule) throw new Error('Sales Invoice OpenData 模块未初始化');
186
+ const templateSettings = await this.invoiceOpenDataModule.loadPrintInvoiceTemplate(`${businessCode}+${channel}`, 'manual');
246
187
  return {
247
- invoice: this.invoiceOpenDataModule?.getInvoiceLayoutConfig() ?? (0, _OpenData.getDefaultInvoiceLayoutConfig)(),
248
- templateSettings: this.invoiceOpenDataModule?.getInvoiceTemplateSettings() ?? (0, _OpenData.getDefaultInvoiceTemplateSettings)()
188
+ invoice: (0, _OpenData.normalizeInvoiceLayoutFromTemplateSettings)(templateSettings),
189
+ templateSettings
249
190
  };
250
191
  } catch (error) {
251
192
  this.logInvoiceOpenDataFallback(error);
@@ -287,12 +228,37 @@ class SalesImpl extends _BaseModule.BaseModule {
287
228
  customToast: () => {}
288
229
  });
289
230
  }
231
+ async printCloudOrderInvoice(input) {
232
+ const orderId = input?.order_id;
233
+ const channel = typeof input?.channel === 'string' ? input.channel.trim() : '';
234
+ if (!channel) throw new Error('Cloud Invoice requires a channel');
235
+ const openData = this.invoiceOpenDataModule;
236
+ if (!openData) throw new Error('Cloud Invoice is not initialized');
237
+ const requestOptions = {
238
+ osServer: true,
239
+ customToast: () => {}
240
+ };
241
+ const lookup = await this.request.post('/shop/local/cloud-order-invoice/lookup', {
242
+ order_id: orderId
243
+ }, requestOptions);
244
+ if (lookup?.status !== true || lookup.code !== 200) {
245
+ throw new Error(lookup?.message || 'Cloud Invoice order lookup failed');
246
+ }
247
+ const businessCode = lookup.data?.business_code?.trim();
248
+ if (!businessCode) throw new Error('Cloud Invoice order has no business_code');
249
+ const settings = await openData.loadCloudInvoiceTemplate(`${businessCode}+${channel}`);
250
+ const result = await this.request.post('/shop/local/cloud-order-invoice/submit', {
251
+ order_id: orderId,
252
+ business_code: businessCode,
253
+ template_settings: settings
254
+ }, requestOptions);
255
+ if (result?.status !== true || result.code !== 200) {
256
+ throw new Error(result?.message || 'Cloud Invoice dispatch failed');
257
+ }
258
+ }
290
259
 
291
260
  /** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
292
261
  clearOpenDataCache() {
293
- this.invoiceOpenDataInFlight = null;
294
- this.invoiceOpenDataInFlightTarget = null;
295
- this.invoiceOpenDataTarget = null;
296
262
  this.invoiceOpenDataModule?.clearCache();
297
263
  }
298
264
 
@@ -56,6 +56,11 @@ export interface SalesPrintLocalOrderReceiptOptions {
56
56
  /** 当前销售入口;缺失或为 system 时按 pos 处理。 */
57
57
  channel?: string;
58
58
  }
59
+ /** Native cloud-order notification. */
60
+ export interface CloudOrderInvoiceRequest {
61
+ order_id: string | number;
62
+ channel: string;
63
+ }
59
64
  /**
60
65
  * Sales 解决方案状态
61
66
  *
@@ -90,6 +95,7 @@ export interface SalesModuleAPI {
90
95
  changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
91
96
  /** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
92
97
  printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
98
+ printCloudOrderInvoice: (request: CloudOrderInvoiceRequest) => Promise<void>;
93
99
  /** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
94
100
  clearOpenDataCache: () => void;
95
101
  /** 获取资源维度的预约占用列表 */
@@ -18,6 +18,7 @@ let SalesHooks = exports.SalesHooks = /*#__PURE__*/function (SalesHooks) {
18
18
  * 将 Server/Order 原始数据转换为真正的 Reservation DTO,
19
19
  * 当前不要直接把 OrderData 当作最终 UI 数据结构。
20
20
  */
21
+ /** Native cloud-order notification. */
21
22
  /**
22
23
  * Sales 解决方案状态
23
24
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.326",
4
+ "version": "2.2.328",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",