@pisell/pisellos 2.2.302 → 2.2.303

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 (153) hide show
  1. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  3. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  4. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  5. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  6. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  7. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  8. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  9. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +10 -7
  12. package/dist/modules/Discount/index.d.ts +2 -0
  13. package/dist/modules/Discount/index.js +41 -5
  14. package/dist/modules/Discount/types.d.ts +21 -0
  15. package/dist/modules/OpenData/index.d.ts +15 -2
  16. package/dist/modules/OpenData/index.js +307 -19
  17. package/dist/modules/OpenData/types.d.ts +55 -0
  18. package/dist/modules/OpenData/types.js +7 -1
  19. package/dist/modules/OpenData/utils.d.ts +21 -1
  20. package/dist/modules/OpenData/utils.js +138 -0
  21. package/dist/modules/Order/index.d.ts +50 -7
  22. package/dist/modules/Order/index.js +1690 -815
  23. package/dist/modules/Order/salesNotes.d.ts +31 -0
  24. package/dist/modules/Order/salesNotes.js +492 -0
  25. package/dist/modules/Order/types.d.ts +117 -10
  26. package/dist/modules/Order/types.js +6 -1
  27. package/dist/modules/Order/utils/virtualSettlement.d.ts +63 -0
  28. package/dist/modules/Order/utils/virtualSettlement.js +284 -0
  29. package/dist/modules/Order/utils.d.ts +5 -1
  30. package/dist/modules/Order/utils.js +138 -33
  31. package/dist/modules/Payment/walletpass.js +20 -21
  32. package/dist/modules/Product/types.d.ts +23 -0
  33. package/dist/modules/ProductList/index.d.ts +2 -1
  34. package/dist/modules/ProductList/index.js +100 -20
  35. package/dist/modules/ProductList/types.d.ts +10 -0
  36. package/dist/modules/Rules/index.d.ts +5 -0
  37. package/dist/modules/Rules/index.js +30 -14
  38. package/dist/modules/SalesSummary/index.d.ts +1 -0
  39. package/dist/modules/SalesSummary/index.js +4 -3
  40. package/dist/modules/SalesSummary/types.d.ts +1 -0
  41. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  42. package/dist/modules/SalesSummary/utils.js +21 -1
  43. package/dist/plugins/request.d.ts +2 -1
  44. package/dist/plugins/request.js +4 -2
  45. package/dist/server/index.d.ts +21 -0
  46. package/dist/server/index.js +1774 -1285
  47. package/dist/server/modules/order/types.d.ts +50 -0
  48. package/dist/server/modules/order/types.js +2 -0
  49. package/dist/server/utils/small-ticket.d.ts +4 -1
  50. package/dist/server/utils/small-ticket.js +461 -96
  51. package/dist/solution/BaseSales/index.d.ts +24 -3
  52. package/dist/solution/BaseSales/index.js +1484 -873
  53. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  54. package/dist/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  55. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  56. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +72 -9
  57. package/dist/solution/BookingByStep/index.d.ts +1 -1
  58. package/dist/solution/BookingTicket/index.d.ts +22 -5
  59. package/dist/solution/BookingTicket/index.js +558 -443
  60. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  61. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  62. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  63. package/dist/solution/RegisterAndLogin/config.js +95 -40
  64. package/dist/solution/RegisterAndLogin/index.js +4 -1
  65. package/dist/solution/Sales/index.d.ts +16 -1
  66. package/dist/solution/Sales/index.js +338 -63
  67. package/dist/solution/Sales/types.d.ts +10 -0
  68. package/dist/solution/ScanOrder/index.d.ts +1 -0
  69. package/dist/solution/ScanOrder/index.js +31 -27
  70. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  71. package/dist/solution/ScanOrder/utils.js +2 -0
  72. package/dist/solution/UnifiedBookingSales/index.d.ts +20 -6
  73. package/dist/solution/UnifiedBookingSales/index.js +874 -527
  74. package/dist/solution/UnifiedBookingSales/types.d.ts +21 -2
  75. package/dist/solution/VenueBooking/index.d.ts +1 -0
  76. package/dist/solution/VenueBooking/index.js +8 -4
  77. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  78. package/lib/model/strategy/adapter/dataVariant/evaluator.js +137 -6
  79. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  80. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  81. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  82. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  83. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  84. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  85. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  86. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  87. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +4 -0
  88. package/lib/modules/Discount/index.d.ts +2 -0
  89. package/lib/modules/Discount/index.js +34 -2
  90. package/lib/modules/Discount/types.d.ts +21 -0
  91. package/lib/modules/OpenData/index.d.ts +15 -2
  92. package/lib/modules/OpenData/index.js +230 -3
  93. package/lib/modules/OpenData/types.d.ts +55 -0
  94. package/lib/modules/OpenData/types.js +9 -1
  95. package/lib/modules/OpenData/utils.d.ts +21 -1
  96. package/lib/modules/OpenData/utils.js +126 -0
  97. package/lib/modules/Order/index.d.ts +50 -7
  98. package/lib/modules/Order/index.js +704 -64
  99. package/lib/modules/Order/salesNotes.d.ts +31 -0
  100. package/lib/modules/Order/salesNotes.js +382 -0
  101. package/lib/modules/Order/types.d.ts +117 -10
  102. package/lib/modules/Order/types.js +5 -1
  103. package/lib/modules/Order/utils/virtualSettlement.d.ts +63 -0
  104. package/lib/modules/Order/utils/virtualSettlement.js +262 -0
  105. package/lib/modules/Order/utils.d.ts +5 -1
  106. package/lib/modules/Order/utils.js +127 -21
  107. package/lib/modules/Payment/walletpass.js +14 -11
  108. package/lib/modules/Product/types.d.ts +23 -0
  109. package/lib/modules/ProductList/index.d.ts +2 -1
  110. package/lib/modules/ProductList/index.js +47 -2
  111. package/lib/modules/ProductList/types.d.ts +10 -0
  112. package/lib/modules/Rules/index.d.ts +5 -0
  113. package/lib/modules/Rules/index.js +22 -12
  114. package/lib/modules/SalesSummary/index.d.ts +1 -0
  115. package/lib/modules/SalesSummary/index.js +4 -2
  116. package/lib/modules/SalesSummary/types.d.ts +1 -0
  117. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  118. package/lib/modules/SalesSummary/utils.js +17 -1
  119. package/lib/plugins/request.d.ts +2 -1
  120. package/lib/plugins/request.js +3 -2
  121. package/lib/server/index.d.ts +21 -0
  122. package/lib/server/index.js +492 -108
  123. package/lib/server/modules/order/types.d.ts +50 -0
  124. package/lib/server/modules/order/types.js +1 -0
  125. package/lib/server/utils/small-ticket.d.ts +4 -1
  126. package/lib/server/utils/small-ticket.js +427 -72
  127. package/lib/solution/BaseSales/index.d.ts +24 -3
  128. package/lib/solution/BaseSales/index.js +433 -30
  129. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +2 -0
  130. package/lib/solution/BaseSales/utils/parseSalesResponse.js +1 -1
  131. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  132. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +38 -0
  133. package/lib/solution/BookingByStep/index.d.ts +1 -1
  134. package/lib/solution/BookingTicket/index.d.ts +22 -5
  135. package/lib/solution/BookingTicket/index.js +60 -15
  136. package/lib/solution/BookingTicket/utils/addProductDecision.js +1 -0
  137. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  138. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  139. package/lib/solution/RegisterAndLogin/config.js +49 -8
  140. package/lib/solution/RegisterAndLogin/index.js +4 -1
  141. package/lib/solution/Sales/index.d.ts +16 -1
  142. package/lib/solution/Sales/index.js +168 -1
  143. package/lib/solution/Sales/types.d.ts +10 -0
  144. package/lib/solution/ScanOrder/index.d.ts +1 -0
  145. package/lib/solution/ScanOrder/index.js +5 -1
  146. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  147. package/lib/solution/ScanOrder/utils.js +1 -0
  148. package/lib/solution/UnifiedBookingSales/index.d.ts +20 -6
  149. package/lib/solution/UnifiedBookingSales/index.js +169 -16
  150. package/lib/solution/UnifiedBookingSales/types.d.ts +21 -2
  151. package/lib/solution/VenueBooking/index.d.ts +1 -0
  152. package/lib/solution/VenueBooking/index.js +5 -1
  153. package/package.json +1 -1
@@ -26,10 +26,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
26
26
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
27
27
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
28
28
  import dayjs from 'dayjs';
29
+ import { cloneDeep } from 'lodash-es';
29
30
  import { BaseModule } from "../../modules/BaseModule";
30
31
  import { SalesHooks } from "./types";
32
+ import { getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings, OpenDataModule } from "../../modules/OpenData";
31
33
  export * from "./types";
32
34
  var UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_processing']);
35
+ var INVOICE_OPEN_DATA_SECTION_CODES = ['documents'];
36
+ var INVOICE_OPEN_DATA_CACHE_TTL = 5 * 60 * 1000;
33
37
 
34
38
  /**
35
39
  * Sales 解决方案基础骨架
@@ -45,8 +49,6 @@ var UNPAID_PAYMENT_STATUSES = new Set(['unpaid', 'partially_paid', 'payment_proc
45
49
  export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
46
50
  _inherits(SalesImpl, _BaseModule);
47
51
  var _super = _createSuper(SalesImpl);
48
- // LoggerManager 实例
49
-
50
52
  function SalesImpl(name, version) {
51
53
  var _this;
52
54
  _classCallCheck(this, SalesImpl);
@@ -60,12 +62,18 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
60
62
  _defineProperty(_assertThisInitialized(_this), "otherParams", {});
61
63
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
62
64
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
65
+ // LoggerManager 实例
66
+ _defineProperty(_assertThisInitialized(_this), "invoiceOpenDataModule", null);
67
+ _defineProperty(_assertThisInitialized(_this), "invoiceOpenDataTarget", null);
68
+ _defineProperty(_assertThisInitialized(_this), "invoiceOpenDataInFlight", null);
69
+ _defineProperty(_assertThisInitialized(_this), "invoiceOpenDataInFlightTarget", null);
63
70
  return _this;
64
71
  }
65
72
  _createClass(SalesImpl, [{
66
73
  key: "initialize",
67
74
  value: function () {
68
75
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core) {
76
+ var _this$otherParams;
69
77
  var options,
70
78
  appPlugin,
71
79
  _args = arguments;
@@ -73,17 +81,25 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
73
81
  while (1) switch (_context.prev = _context.next) {
74
82
  case 0:
75
83
  options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
84
+ if (this.invoiceOpenDataModule) {
85
+ try {
86
+ this.clearOpenDataCache();
87
+ this.invoiceOpenDataModule.destroy();
88
+ } catch (error) {
89
+ console.warn('[Sales] 旧 Invoice OpenData 子模块销毁失败', error);
90
+ }
91
+ }
76
92
  this.core = core;
77
93
  this.options = options;
78
94
  this.otherParams = options.otherParams || {};
79
95
  appPlugin = this.core.getPlugin('app'); // @ts-ignore
80
96
  this.request = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp().request;
81
97
  if (this.request) {
82
- _context.next = 8;
98
+ _context.next = 9;
83
99
  break;
84
100
  }
85
101
  throw new Error('Sales 解决方案需要 request 插件支持');
86
- case 8:
102
+ case 9:
87
103
  // 初始化 store 状态
88
104
  this.store = {
89
105
  currentDay: dayjs().startOf('day'),
@@ -94,9 +110,21 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
94
110
  // 在这里补充从 Server/Order 读取 currentDay 原始数据并转换为预约列表。
95
111
 
96
112
  this.logger = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp().logger;
97
- _context.next = 12;
113
+ this.invoiceOpenDataTarget = null;
114
+ this.invoiceOpenDataInFlight = null;
115
+ this.invoiceOpenDataInFlightTarget = null;
116
+ this.invoiceOpenDataModule = new OpenDataModule("".concat(this.name, "_invoiceOpenData"));
117
+ this.core.registerModule(this.invoiceOpenDataModule, {
118
+ initialState: {},
119
+ otherParams: {
120
+ fatherModule: this.name,
121
+ openCache: false,
122
+ platform: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.platform
123
+ }
124
+ });
125
+ _context.next = 18;
98
126
  return this.core.effects.emit("".concat(this.name, ":onInited"), {});
99
- case 12:
127
+ case 18:
100
128
  case "end":
101
129
  return _context.stop();
102
130
  }
@@ -218,25 +246,272 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
218
246
  return _changeBookingStatus.apply(this, arguments);
219
247
  }
220
248
  return changeBookingStatus;
221
- }() // -------------------------------------------------------------------------
249
+ }()
250
+ /**
251
+ * 将显式 channel 或当前运行上下文归一为 Invoice OpenData 使用的销售入口。
252
+ * Legacy Sales 的系统上下文没有可打印的 system target,因此统一回退 pos。
253
+ */
254
+ }, {
255
+ key: "getInvoiceSalesChannel",
256
+ value: function getInvoiceSalesChannel(channel) {
257
+ var _this$core, _this$core$getChannel, _ref;
258
+ var contextChannel = (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 || (_this$core$getChannel = _this$core.getChannel) === null || _this$core$getChannel === void 0 ? void 0 : _this$core$getChannel.call(_this$core);
259
+ var normalized = String((_ref = channel !== null && channel !== void 0 ? channel : contextChannel) !== null && _ref !== void 0 ? _ref : '').trim();
260
+ return !normalized || normalized === 'system' ? 'pos' : normalized;
261
+ }
262
+ }, {
263
+ key: "loadInvoiceOpenData",
264
+ value: function () {
265
+ var _loadInvoiceOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(businessCode, channel) {
266
+ var target, cachedData, lastFetchedAt, request, openData;
267
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
268
+ while (1) switch (_context4.prev = _context4.next) {
269
+ case 0:
270
+ if (this.invoiceOpenDataModule) {
271
+ _context4.next = 2;
272
+ break;
273
+ }
274
+ throw new Error('Sales Invoice OpenData 模块未初始化');
275
+ case 2:
276
+ target = "".concat(businessCode, "+").concat(channel);
277
+ cachedData = this.invoiceOpenDataModule.getOpenData();
278
+ lastFetchedAt = this.invoiceOpenDataModule.getLastFetchedAt();
279
+ if (!(cachedData && this.invoiceOpenDataTarget === target && typeof lastFetchedAt === 'number' && Date.now() - lastFetchedAt < INVOICE_OPEN_DATA_CACHE_TTL)) {
280
+ _context4.next = 10;
281
+ break;
282
+ }
283
+ if (!(typeof this.invoiceOpenDataModule.ensureInvoiceTemplateSettings === 'function')) {
284
+ _context4.next = 9;
285
+ break;
286
+ }
287
+ _context4.next = 9;
288
+ return this.invoiceOpenDataModule.ensureInvoiceTemplateSettings(target);
289
+ case 9:
290
+ return _context4.abrupt("return", cachedData);
291
+ case 10:
292
+ if (!this.invoiceOpenDataInFlight) {
293
+ _context4.next = 21;
294
+ break;
295
+ }
296
+ if (!(this.invoiceOpenDataInFlightTarget === target)) {
297
+ _context4.next = 13;
298
+ break;
299
+ }
300
+ return _context4.abrupt("return", this.invoiceOpenDataInFlight);
301
+ case 13:
302
+ _context4.prev = 13;
303
+ _context4.next = 16;
304
+ return this.invoiceOpenDataInFlight;
305
+ case 16:
306
+ _context4.next = 20;
307
+ break;
308
+ case 18:
309
+ _context4.prev = 18;
310
+ _context4.t0 = _context4["catch"](13);
311
+ case 20:
312
+ return _context4.abrupt("return", this.loadInvoiceOpenData(businessCode, channel));
313
+ case 21:
314
+ request = this.invoiceOpenDataModule.fetchOpenData({
315
+ scope: 'board',
316
+ target: target,
317
+ section_code: [].concat(INVOICE_OPEN_DATA_SECTION_CODES)
318
+ });
319
+ this.invoiceOpenDataInFlight = request;
320
+ this.invoiceOpenDataInFlightTarget = target;
321
+ _context4.prev = 24;
322
+ _context4.next = 27;
323
+ return request;
324
+ case 27:
325
+ openData = _context4.sent;
326
+ // clearOpenDataCache() 或后续请求接管后,旧响应不得复活 target 归属。
327
+ if (this.invoiceOpenDataInFlight === request) {
328
+ this.invoiceOpenDataTarget = target;
329
+ }
330
+ return _context4.abrupt("return", openData);
331
+ case 30:
332
+ _context4.prev = 30;
333
+ if (this.invoiceOpenDataInFlight === request) {
334
+ this.invoiceOpenDataInFlight = null;
335
+ this.invoiceOpenDataInFlightTarget = null;
336
+ }
337
+ return _context4.finish(30);
338
+ case 33:
339
+ case "end":
340
+ return _context4.stop();
341
+ }
342
+ }, _callee4, this, [[13, 18], [24,, 30, 33]]);
343
+ }));
344
+ function loadInvoiceOpenData(_x4, _x5) {
345
+ return _loadInvoiceOpenData.apply(this, arguments);
346
+ }
347
+ return loadInvoiceOpenData;
348
+ }()
349
+ }, {
350
+ key: "logInvoiceOpenDataFallback",
351
+ value: function logInvoiceOpenDataFallback(error) {
352
+ var _this$logger;
353
+ var message = error instanceof Error ? error.message : String(error);
354
+ if ((_this$logger = this.logger) !== null && _this$logger !== void 0 && _this$logger.addLog) {
355
+ this.logger.addLog({
356
+ type: 'warning',
357
+ title: 'Sales Invoice OpenData 加载失败,使用默认配置',
358
+ metadata: {
359
+ message: message
360
+ }
361
+ });
362
+ return;
363
+ }
364
+ console.warn('[Sales] Invoice OpenData 加载失败,使用默认配置', error);
365
+ }
366
+ }, {
367
+ key: "resolveInvoiceConfigs",
368
+ value: function () {
369
+ var _resolveInvoiceConfigs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(businessCode, channel) {
370
+ var _this$invoiceOpenData, _this$invoiceOpenData2, _this$invoiceOpenData3, _this$invoiceOpenData4;
371
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
372
+ while (1) switch (_context5.prev = _context5.next) {
373
+ case 0:
374
+ _context5.prev = 0;
375
+ _context5.next = 3;
376
+ return this.loadInvoiceOpenData(businessCode, channel);
377
+ case 3:
378
+ if (!(this.invoiceOpenDataTarget !== "".concat(businessCode, "+").concat(channel))) {
379
+ _context5.next = 5;
380
+ break;
381
+ }
382
+ return _context5.abrupt("return", {
383
+ invoice: getDefaultInvoiceLayoutConfig(),
384
+ templateSettings: getDefaultInvoiceTemplateSettings()
385
+ });
386
+ case 5:
387
+ return _context5.abrupt("return", {
388
+ invoice: (_this$invoiceOpenData = (_this$invoiceOpenData2 = this.invoiceOpenDataModule) === null || _this$invoiceOpenData2 === void 0 ? void 0 : _this$invoiceOpenData2.getInvoiceLayoutConfig()) !== null && _this$invoiceOpenData !== void 0 ? _this$invoiceOpenData : getDefaultInvoiceLayoutConfig(),
389
+ templateSettings: (_this$invoiceOpenData3 = (_this$invoiceOpenData4 = this.invoiceOpenDataModule) === null || _this$invoiceOpenData4 === void 0 ? void 0 : _this$invoiceOpenData4.getInvoiceTemplateSettings()) !== null && _this$invoiceOpenData3 !== void 0 ? _this$invoiceOpenData3 : getDefaultInvoiceTemplateSettings()
390
+ });
391
+ case 8:
392
+ _context5.prev = 8;
393
+ _context5.t0 = _context5["catch"](0);
394
+ this.logInvoiceOpenDataFallback(_context5.t0);
395
+ return _context5.abrupt("return", {
396
+ invoice: getDefaultInvoiceLayoutConfig(),
397
+ templateSettings: getDefaultInvoiceTemplateSettings()
398
+ });
399
+ case 12:
400
+ case "end":
401
+ return _context5.stop();
402
+ }
403
+ }, _callee5, this, [[0, 8]]);
404
+ }));
405
+ function resolveInvoiceConfigs(_x6, _x7) {
406
+ return _resolveInvoiceConfigs.apply(this, arguments);
407
+ }
408
+ return resolveInvoiceConfigs;
409
+ }()
410
+ }, {
411
+ key: "printLocalOrderReceipt",
412
+ value: function () {
413
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(lookup, options) {
414
+ var _options$businessCode;
415
+ var normalizedLookup, businessCode, channel, _yield$this$resolveIn, invoice, templateSettings, lookupPayload;
416
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
417
+ while (1) switch (_context6.prev = _context6.next) {
418
+ case 0:
419
+ normalizedLookup = typeof lookup === 'string' ? lookup.trim() : lookup;
420
+ if (!(normalizedLookup === '' || normalizedLookup === null || normalizedLookup === undefined)) {
421
+ _context6.next = 3;
422
+ break;
423
+ }
424
+ throw new Error('Sales 本地小票打印需要订单标识');
425
+ case 3:
426
+ businessCode = String((_options$businessCode = options === null || options === void 0 ? void 0 : options.businessCode) !== null && _options$businessCode !== void 0 ? _options$businessCode : '').trim();
427
+ if (businessCode) {
428
+ _context6.next = 6;
429
+ break;
430
+ }
431
+ throw new Error('Sales 本地小票打印需要 businessCode');
432
+ case 6:
433
+ channel = this.getInvoiceSalesChannel(options === null || options === void 0 ? void 0 : options.channel);
434
+ _context6.next = 9;
435
+ return this.resolveInvoiceConfigs(businessCode, channel);
436
+ case 9:
437
+ _yield$this$resolveIn = _context6.sent;
438
+ invoice = _yield$this$resolveIn.invoice;
439
+ templateSettings = _yield$this$resolveIn.templateSettings;
440
+ lookupPayload = typeof normalizedLookup === 'number' ? {
441
+ order_id: normalizedLookup
442
+ } : {
443
+ external_sale_number: normalizedLookup
444
+ };
445
+ return _context6.abrupt("return", this.request.post('/local/print-order', _objectSpread(_objectSpread({}, lookupPayload), {}, {
446
+ lookup_order_from_db: 1,
447
+ small_ticket_data_flag: 1,
448
+ business_code: businessCode,
449
+ order_sales_channel: channel,
450
+ invoice: cloneDeep(invoice),
451
+ template_settings: cloneDeep(templateSettings)
452
+ }), {
453
+ osServer: true,
454
+ customToast: function customToast() {}
455
+ }));
456
+ case 14:
457
+ case "end":
458
+ return _context6.stop();
459
+ }
460
+ }, _callee6, this);
461
+ }));
462
+ function printLocalOrderReceipt(_x8, _x9) {
463
+ return _printLocalOrderReceipt.apply(this, arguments);
464
+ }
465
+ return printLocalOrderReceipt;
466
+ }() /** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
467
+ }, {
468
+ key: "clearOpenDataCache",
469
+ value: function clearOpenDataCache() {
470
+ var _this$invoiceOpenData5;
471
+ this.invoiceOpenDataInFlight = null;
472
+ this.invoiceOpenDataInFlightTarget = null;
473
+ this.invoiceOpenDataTarget = null;
474
+ (_this$invoiceOpenData5 = this.invoiceOpenDataModule) === null || _this$invoiceOpenData5 === void 0 || _this$invoiceOpenData5.clearCache();
475
+ }
476
+
477
+ // -------------------------------------------------------------------------
222
478
  // 生命周期
223
479
  // -------------------------------------------------------------------------
224
480
  }, {
225
481
  key: "destroy",
226
482
  value: function () {
227
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
228
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
229
- while (1) switch (_context4.prev = _context4.next) {
483
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
484
+ var invoiceOpenDataModule;
485
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
486
+ while (1) switch (_context7.prev = _context7.next) {
230
487
  case 0:
231
- _context4.next = 2;
488
+ this.clearOpenDataCache();
489
+ invoiceOpenDataModule = this.invoiceOpenDataModule;
490
+ this.invoiceOpenDataModule = null;
491
+ if (!invoiceOpenDataModule) {
492
+ _context7.next = 12;
493
+ break;
494
+ }
495
+ _context7.prev = 4;
496
+ _context7.next = 7;
497
+ return invoiceOpenDataModule.destroy();
498
+ case 7:
499
+ _context7.next = 12;
500
+ break;
501
+ case 9:
502
+ _context7.prev = 9;
503
+ _context7.t0 = _context7["catch"](4);
504
+ console.warn('[Sales] Invoice OpenData 子模块销毁失败', _context7.t0);
505
+ case 12:
506
+ _context7.next = 14;
232
507
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
233
- case 2:
508
+ case 14:
234
509
  _get(_getPrototypeOf(SalesImpl.prototype), "destroy", this).call(this);
235
- case 3:
510
+ case 15:
236
511
  case "end":
237
- return _context4.stop();
512
+ return _context7.stop();
238
513
  }
239
- }, _callee4, this);
514
+ }, _callee7, this, [[4, 9]]);
240
515
  }));
241
516
  function destroy() {
242
517
  return _destroy.apply(this, arguments);
@@ -251,8 +526,8 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
251
526
  }, {
252
527
  key: "getTimelineBucketMinutes",
253
528
  value: function getTimelineBucketMinutes() {
254
- var _this$otherParams;
255
- var dynamicBucket = Number((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.timelineBucketMinutes);
529
+ var _this$otherParams2;
530
+ var dynamicBucket = Number((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.timelineBucketMinutes);
256
531
  if (!Number.isFinite(dynamicBucket) || dynamicBucket <= 0) return this.defaultTimelineBucketMinutes;
257
532
  return Math.floor(dynamicBucket);
258
533
  }
@@ -266,11 +541,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
266
541
  }, {
267
542
  key: "getOperatingDayRange",
268
543
  value: function getOperatingDayRange() {
269
- var _this$core, _appPlugin$getApp, _appPlugin$getApp$get, _appPlugin$getApp$get2, _appPlugin$getApp$get3, _coreData$core;
544
+ var _this$core2, _appPlugin$getApp, _appPlugin$getApp$get, _appPlugin$getApp$get2, _appPlugin$getApp$get3, _coreData$core;
270
545
  var referenceTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dayjs();
271
546
  var defaultStart = referenceTime.startOf('day');
272
547
  var defaultEndExclusive = defaultStart.add(1, 'day');
273
- var appPlugin = (_this$core = this.core) === null || _this$core === void 0 ? void 0 : _this$core.getPlugin('app');
548
+ var appPlugin = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.getPlugin('app');
274
549
  var coreData = appPlugin === null || appPlugin === void 0 || (_appPlugin$getApp = appPlugin.getApp()) === null || _appPlugin$getApp === void 0 || (_appPlugin$getApp = _appPlugin$getApp.data) === null || _appPlugin$getApp === void 0 || (_appPlugin$getApp = _appPlugin$getApp.store) === null || _appPlugin$getApp === void 0 || (_appPlugin$getApp$get = _appPlugin$getApp.getStore) === null || _appPlugin$getApp$get === void 0 || (_appPlugin$getApp$get2 = (_appPlugin$getApp$get3 = _appPlugin$getApp$get.call(_appPlugin$getApp)).getDataByModel) === null || _appPlugin$getApp$get2 === void 0 ? void 0 : _appPlugin$getApp$get2.call(_appPlugin$getApp$get3, 'core');
275
550
  var operatingDayBoundary = coreData === null || coreData === void 0 || (_coreData$core = coreData.core) === null || _coreData$core === void 0 ? void 0 : _coreData$core.operating_day_boundary;
276
551
  if ((operatingDayBoundary === null || operatingDayBoundary === void 0 ? void 0 : operatingDayBoundary.type) !== 'start_time') {
@@ -316,12 +591,12 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
316
591
  var customStartAt = startDateTime ? dayjs(startDateTime) : dayjs('');
317
592
  var customEndExclusiveAt = endDateTime ? dayjs(endDateTime) : dayjs('');
318
593
  var hasValidCustomRange = customStartAt.isValid() && customEndExclusiveAt.isValid();
319
- var _ref = hasValidCustomRange ? {
594
+ var _ref2 = hasValidCustomRange ? {
320
595
  startAt: customStartAt,
321
596
  endExclusiveAt: customEndExclusiveAt
322
597
  } : this.getTimelineRangeByOperatingBoundary(),
323
- startAt = _ref.startAt,
324
- endExclusiveAt = _ref.endExclusiveAt;
598
+ startAt = _ref2.startAt,
599
+ endExclusiveAt = _ref2.endExclusiveAt;
325
600
  var startAtMs = startAt.valueOf();
326
601
  var endExclusiveAtMs = endExclusiveAt.valueOf();
327
602
  if (!startAt.isValid() || !endExclusiveAt.isValid() || endExclusiveAtMs <= startAtMs) return [];
@@ -329,9 +604,9 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
329
604
  if (slotCount <= 0) return [];
330
605
  var diff = new Int32Array(slotCount + 1);
331
606
  for (var i = 0; i < bookingList.length; i++) {
332
- var _ref2, _booking$appointment_;
607
+ var _ref3, _booking$appointment_;
333
608
  var booking = bookingList[i];
334
- var appointmentStatus = String((_ref2 = (_booking$appointment_ = booking.appointment_status) !== null && _booking$appointment_ !== void 0 ? _booking$appointment_ : booking.status) !== null && _ref2 !== void 0 ? _ref2 : '');
609
+ var appointmentStatus = String((_ref3 = (_booking$appointment_ = booking.appointment_status) !== null && _booking$appointment_ !== void 0 ? _booking$appointment_ : booking.status) !== null && _ref3 !== void 0 ? _ref3 : '');
335
610
  if (appointmentStatus === 'new' || appointmentStatus === 'rejected' || appointmentStatus === 'cancelled') continue;
336
611
  var bookingStartAt = this.toBookingDateTime(booking.start_date, booking.start_time);
337
612
  var bookingEndAt = this.toBookingDateTime(booking.end_date, booking.end_time);
@@ -401,14 +676,14 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
401
676
  }, {
402
677
  key: "getResourceId",
403
678
  value: function getResourceId(resource) {
404
- var _ref3, _resource$id;
405
- return (_ref3 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.form_record_id) !== null && _ref3 !== void 0 ? _ref3 : '';
679
+ var _ref4, _resource$id;
680
+ return (_ref4 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.form_record_id) !== null && _ref4 !== void 0 ? _ref4 : '';
406
681
  }
407
682
  }, {
408
683
  key: "getBookingAppointmentStatus",
409
684
  value: function getBookingAppointmentStatus(booking) {
410
- var _ref4, _booking$appointment_2;
411
- return String((_ref4 = (_booking$appointment_2 = booking.appointment_status) !== null && _booking$appointment_2 !== void 0 ? _booking$appointment_2 : booking.status) !== null && _ref4 !== void 0 ? _ref4 : '');
685
+ var _ref5, _booking$appointment_2;
686
+ return String((_ref5 = (_booking$appointment_2 = booking.appointment_status) !== null && _booking$appointment_2 !== void 0 ? _booking$appointment_2 : booking.status) !== null && _ref5 !== void 0 ? _ref5 : '');
412
687
  }
413
688
  }, {
414
689
  key: "isBookingIncludedInStats",
@@ -814,7 +1089,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
814
1089
  }, {
815
1090
  key: "getResourceBookingList",
816
1091
  value: function () {
817
- var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(currentTime) {
1092
+ var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(currentTime) {
818
1093
  var _resourceResponse$dat,
819
1094
  _resourceResponse$dat2,
820
1095
  _this8 = this;
@@ -828,28 +1103,28 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
828
1103
  rawBookingMap,
829
1104
  bookingMap,
830
1105
  list,
831
- _args5 = arguments;
832
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
833
- while (1) switch (_context5.prev = _context5.next) {
1106
+ _args8 = arguments;
1107
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1108
+ while (1) switch (_context8.prev = _context8.next) {
834
1109
  case 0:
835
- bookingList = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : [];
836
- deviceTime = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : currentTime;
1110
+ bookingList = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : [];
1111
+ deviceTime = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : currentTime;
837
1112
  // currentTime 约定为完整 datetime;非法值直接返回空,避免误判
838
1113
  current = dayjs(currentTime);
839
1114
  if (current.isValid()) {
840
- _context5.next = 5;
1115
+ _context8.next = 5;
841
1116
  break;
842
1117
  }
843
- return _context5.abrupt("return", []);
1118
+ return _context8.abrupt("return", []);
844
1119
  case 5:
845
1120
  deviceCurrent = dayjs(deviceTime);
846
1121
  if (deviceCurrent.isValid()) {
847
- _context5.next = 8;
1122
+ _context8.next = 8;
848
1123
  break;
849
1124
  }
850
- return _context5.abrupt("return", []);
1125
+ return _context8.abrupt("return", []);
851
1126
  case 8:
852
- _context5.next = 10;
1127
+ _context8.next = 10;
853
1128
  return this.request.get('/shop/form/resource/page', {
854
1129
  skip: 1,
855
1130
  num: 999
@@ -860,13 +1135,13 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
860
1135
  isShopApi: true
861
1136
  });
862
1137
  case 10:
863
- resourceResponse = _context5.sent;
1138
+ resourceResponse = _context8.sent;
864
1139
  resourceList = (_resourceResponse$dat = resourceResponse === null || resourceResponse === void 0 || (_resourceResponse$dat2 = resourceResponse.data) === null || _resourceResponse$dat2 === void 0 ? void 0 : _resourceResponse$dat2.list) !== null && _resourceResponse$dat !== void 0 ? _resourceResponse$dat : [];
865
1140
  if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
866
- _context5.next = 14;
1141
+ _context8.next = 14;
867
1142
  break;
868
1143
  }
869
- return _context5.abrupt("return", []);
1144
+ return _context8.abrupt("return", []);
870
1145
  case 14:
871
1146
  // 全局先做 booking 标准化 + start_time 升序,后续映射直接复用
872
1147
  normalizedBookings = this.normalizeResourceBookings(current, deviceCurrent, bookingList); // 建立 resourceId -> bookings[] 倒排索引,加速资源匹配
@@ -901,14 +1176,14 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
901
1176
  list: list === null || list === void 0 ? void 0 : list.length
902
1177
  }
903
1178
  });
904
- return _context5.abrupt("return", list);
1179
+ return _context8.abrupt("return", list);
905
1180
  case 20:
906
1181
  case "end":
907
- return _context5.stop();
1182
+ return _context8.stop();
908
1183
  }
909
- }, _callee5, this);
1184
+ }, _callee8, this);
910
1185
  }));
911
- function getResourceBookingList(_x4) {
1186
+ function getResourceBookingList(_x10) {
912
1187
  return _getResourceBookingList.apply(this, arguments);
913
1188
  }
914
1189
  return getResourceBookingList;
@@ -916,30 +1191,30 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
916
1191
  }, {
917
1192
  key: "getResourceBookingItem",
918
1193
  value: function () {
919
- var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
1194
+ var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
920
1195
  var _resourceResponse$dat3,
921
1196
  _resourceResponse$dat4,
922
1197
  _this9 = this,
923
1198
  _params$bookingList;
924
1199
  var current, deviceCurrent, resourceResponse, resourceList, targetResource, resourceId, matchedBookingList, statsBookingList, completedBookingList, unpaidBookingList, bookings, completedBookings, unpaidBookings, orderCount, bookingCount, compeleteBookingCount;
925
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
926
- while (1) switch (_context6.prev = _context6.next) {
1200
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1201
+ while (1) switch (_context9.prev = _context9.next) {
927
1202
  case 0:
928
1203
  current = dayjs(params.currentTime);
929
1204
  if (current.isValid()) {
930
- _context6.next = 3;
1205
+ _context9.next = 3;
931
1206
  break;
932
1207
  }
933
- return _context6.abrupt("return", null);
1208
+ return _context9.abrupt("return", null);
934
1209
  case 3:
935
1210
  deviceCurrent = dayjs(params.deviceTime || params.currentTime);
936
1211
  if (deviceCurrent.isValid()) {
937
- _context6.next = 6;
1212
+ _context9.next = 6;
938
1213
  break;
939
1214
  }
940
- return _context6.abrupt("return", null);
1215
+ return _context9.abrupt("return", null);
941
1216
  case 6:
942
- _context6.next = 8;
1217
+ _context9.next = 8;
943
1218
  return this.request.get('/shop/form/resource/page', {
944
1219
  skip: 1,
945
1220
  num: 999
@@ -950,22 +1225,22 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
950
1225
  isShopApi: true
951
1226
  });
952
1227
  case 8:
953
- resourceResponse = _context6.sent;
1228
+ resourceResponse = _context9.sent;
954
1229
  resourceList = (_resourceResponse$dat3 = resourceResponse === null || resourceResponse === void 0 || (_resourceResponse$dat4 = resourceResponse.data) === null || _resourceResponse$dat4 === void 0 ? void 0 : _resourceResponse$dat4.list) !== null && _resourceResponse$dat3 !== void 0 ? _resourceResponse$dat3 : [];
955
1230
  if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
956
- _context6.next = 12;
1231
+ _context9.next = 12;
957
1232
  break;
958
1233
  }
959
- return _context6.abrupt("return", null);
1234
+ return _context9.abrupt("return", null);
960
1235
  case 12:
961
1236
  targetResource = resourceList.find(function (resource) {
962
1237
  return String(_this9.getResourceId(resource)) === String(params.resourceId);
963
1238
  });
964
1239
  if (targetResource) {
965
- _context6.next = 15;
1240
+ _context9.next = 15;
966
1241
  break;
967
1242
  }
968
- return _context6.abrupt("return", null);
1243
+ return _context9.abrupt("return", null);
969
1244
  case 15:
970
1245
  resourceId = this.getResourceId(targetResource);
971
1246
  matchedBookingList = params.bookingList.filter(function (booking) {
@@ -1016,7 +1291,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1016
1291
  compeleteBookingCount: compeleteBookingCount
1017
1292
  }
1018
1293
  });
1019
- return _context6.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
1294
+ return _context9.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
1020
1295
  resource_id: resourceId,
1021
1296
  orderCount: orderCount,
1022
1297
  bookingCount: bookingCount,
@@ -1027,11 +1302,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
1027
1302
  }));
1028
1303
  case 28:
1029
1304
  case "end":
1030
- return _context6.stop();
1305
+ return _context9.stop();
1031
1306
  }
1032
- }, _callee6, this);
1307
+ }, _callee9, this);
1033
1308
  }));
1034
- function getResourceBookingItem(_x5) {
1309
+ function getResourceBookingItem(_x11) {
1035
1310
  return _getResourceBookingItem.apply(this, arguments);
1036
1311
  }
1037
1312
  return getResourceBookingItem;
@@ -50,6 +50,12 @@ export interface GetResourceBookingItemParams {
50
50
  bookingList: BookingData[];
51
51
  deviceTime?: string;
52
52
  }
53
+ export interface SalesPrintLocalOrderReceiptOptions {
54
+ /** 当前销售业务类型,用于隔离 Documents Invoice 配置。 */
55
+ businessCode: string;
56
+ /** 当前销售入口;缺失或为 system 时按 pos 处理。 */
57
+ channel?: string;
58
+ }
53
59
  /**
54
60
  * Sales 解决方案状态
55
61
  *
@@ -82,6 +88,10 @@ export interface SalesModuleAPI {
82
88
  cancelOrder: (orderIds: Array<number | string>) => Promise<any>;
83
89
  /** 变更预约状态 */
84
90
  changeBookingStatus: (params: ChangeBookingStatusParams) => Promise<any>;
91
+ /** 按本地订单标识打印小票;本地未命中时由 OS Server 负责远端兜底。 */
92
+ printLocalOrderReceipt: <T = any>(lookup: string | number, options: SalesPrintLocalOrderReceiptOptions) => Promise<T>;
93
+ /** 清除 Legacy Sales 独立维护的 Documents OpenData 缓存。 */
94
+ clearOpenDataCache: () => void;
85
95
  /** 获取资源维度的预约占用列表 */
86
96
  getResourceBookingList: (currentTime: string, bookingList: BookingData[], deviceTime?: string) => Promise<SalesResourceBookingItem[]>;
87
97
  /** 获取单个资源维度的预约占用、已完成、未支付列表 */
@@ -13,6 +13,7 @@ interface ScanOrderItemRuleRuntimeConfig {
13
13
  pax?: Partial<PaxInfo>;
14
14
  historicalItems?: CartItemSummary[];
15
15
  serviceType?: string;
16
+ channel?: string;
16
17
  submissionIndex?: number;
17
18
  custom?: Record<string, any>;
18
19
  }