@pisell/pisellos 0.10.16 → 0.10.18

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 (63) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/OpenData/index.d.ts +5 -2
  3. package/dist/modules/OpenData/index.js +27 -12
  4. package/dist/modules/OpenData/types.d.ts +42 -0
  5. package/dist/modules/OpenData/types.js +7 -1
  6. package/dist/modules/OpenData/utils.d.ts +15 -1
  7. package/dist/modules/OpenData/utils.js +85 -0
  8. package/dist/modules/Order/index.d.ts +3 -1
  9. package/dist/modules/Order/index.js +68 -44
  10. package/dist/modules/Order/types.d.ts +3 -0
  11. package/dist/modules/Order/types.js +1 -0
  12. package/dist/modules/ProductList/index.js +96 -74
  13. package/dist/modules/Rules/index.js +11 -8
  14. package/dist/modules/SalesSummary/index.js +6 -4
  15. package/dist/server/index.d.ts +11 -0
  16. package/dist/server/index.js +845 -481
  17. package/dist/server/modules/order/index.d.ts +8 -0
  18. package/dist/server/modules/order/index.js +251 -215
  19. package/dist/server/utils/small-ticket.d.ts +9 -1
  20. package/dist/server/utils/small-ticket.js +117 -43
  21. package/dist/solution/BaseSales/index.d.ts +7 -0
  22. package/dist/solution/BaseSales/index.js +251 -144
  23. package/dist/solution/BookingByStep/index.d.ts +2 -2
  24. package/dist/solution/BookingTicket/index.d.ts +14 -19
  25. package/dist/solution/BookingTicket/index.js +545 -429
  26. package/dist/solution/Sales/index.d.ts +20 -4
  27. package/dist/solution/Sales/index.js +348 -75
  28. package/dist/solution/Sales/types.d.ts +10 -0
  29. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  30. package/dist/solution/UnifiedBookingSales/index.js +495 -422
  31. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -1
  32. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  33. package/lib/modules/OpenData/index.d.ts +5 -2
  34. package/lib/modules/OpenData/index.js +50 -3
  35. package/lib/modules/OpenData/types.d.ts +42 -0
  36. package/lib/modules/OpenData/types.js +9 -1
  37. package/lib/modules/OpenData/utils.d.ts +15 -1
  38. package/lib/modules/OpenData/utils.js +85 -0
  39. package/lib/modules/Order/index.d.ts +3 -1
  40. package/lib/modules/Order/index.js +41 -21
  41. package/lib/modules/Order/types.d.ts +3 -0
  42. package/lib/modules/Order/types.js +1 -0
  43. package/lib/modules/ProductList/index.js +9 -6
  44. package/lib/modules/Rules/index.js +8 -6
  45. package/lib/modules/SalesSummary/index.js +3 -1
  46. package/lib/server/index.d.ts +11 -0
  47. package/lib/server/index.js +395 -96
  48. package/lib/server/modules/order/index.d.ts +8 -0
  49. package/lib/server/modules/order/index.js +23 -0
  50. package/lib/server/utils/small-ticket.d.ts +9 -1
  51. package/lib/server/utils/small-ticket.js +107 -35
  52. package/lib/solution/BaseSales/index.d.ts +7 -0
  53. package/lib/solution/BaseSales/index.js +125 -28
  54. package/lib/solution/BookingByStep/index.d.ts +2 -2
  55. package/lib/solution/BookingTicket/index.d.ts +14 -19
  56. package/lib/solution/BookingTicket/index.js +70 -17
  57. package/lib/solution/Sales/index.d.ts +20 -4
  58. package/lib/solution/Sales/index.js +183 -15
  59. package/lib/solution/Sales/types.d.ts +10 -0
  60. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  61. package/lib/solution/UnifiedBookingSales/index.js +41 -15
  62. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -1
  63. 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,6 +62,11 @@ 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, [{
@@ -73,17 +80,25 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
73
80
  while (1) switch (_context.prev = _context.next) {
74
81
  case 0:
75
82
  options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
83
+ if (this.invoiceOpenDataModule) {
84
+ try {
85
+ this.clearOpenDataCache();
86
+ this.invoiceOpenDataModule.destroy();
87
+ } catch (error) {
88
+ console.warn('[Sales] 旧 Invoice OpenData 子模块销毁失败', error);
89
+ }
90
+ }
76
91
  this.core = core;
77
92
  this.options = options;
78
93
  this.otherParams = options.otherParams || {};
79
94
  appPlugin = this.core.getPlugin('app'); // @ts-ignore
80
95
  this.request = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp().request;
81
96
  if (this.request) {
82
- _context.next = 8;
97
+ _context.next = 9;
83
98
  break;
84
99
  }
85
100
  throw new Error('Sales 解决方案需要 request 插件支持');
86
- case 8:
101
+ case 9:
87
102
  // 初始化 store 状态
88
103
  this.store = {
89
104
  currentDay: dayjs().startOf('day'),
@@ -94,9 +109,20 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
94
109
  // 在这里补充从 Server/Order 读取 currentDay 原始数据并转换为预约列表。
95
110
 
96
111
  this.logger = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp().logger;
97
- _context.next = 12;
112
+ this.invoiceOpenDataTarget = null;
113
+ this.invoiceOpenDataInFlight = null;
114
+ this.invoiceOpenDataInFlightTarget = null;
115
+ this.invoiceOpenDataModule = new OpenDataModule("".concat(this.name, "_invoiceOpenData"));
116
+ this.core.registerModule(this.invoiceOpenDataModule, {
117
+ initialState: {},
118
+ otherParams: {
119
+ fatherModule: this.name,
120
+ openCache: false
121
+ }
122
+ });
123
+ _context.next = 18;
98
124
  return this.core.effects.emit("".concat(this.name, ":onInited"), {});
99
- case 12:
125
+ case 18:
100
126
  case "end":
101
127
  return _context.stop();
102
128
  }
@@ -218,25 +244,265 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
218
244
  return _changeBookingStatus.apply(this, arguments);
219
245
  }
220
246
  return changeBookingStatus;
221
- }() // -------------------------------------------------------------------------
247
+ }()
248
+ /**
249
+ * 将显式 channel 或当前运行上下文归一为 Invoice OpenData 使用的销售入口。
250
+ * Legacy Sales 的系统上下文没有可打印的 system target,因此统一回退 pos。
251
+ */
252
+ }, {
253
+ key: "getInvoiceSalesChannel",
254
+ value: function getInvoiceSalesChannel(channel) {
255
+ var _this$core, _this$core$getChannel, _ref;
256
+ 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);
257
+ var normalized = String((_ref = channel !== null && channel !== void 0 ? channel : contextChannel) !== null && _ref !== void 0 ? _ref : '').trim();
258
+ return !normalized || normalized === 'system' ? 'pos' : normalized;
259
+ }
260
+ }, {
261
+ key: "loadInvoiceOpenData",
262
+ value: function () {
263
+ var _loadInvoiceOpenData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(businessCode, channel) {
264
+ var target, cachedData, lastFetchedAt, request, openData;
265
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
266
+ while (1) switch (_context4.prev = _context4.next) {
267
+ case 0:
268
+ if (this.invoiceOpenDataModule) {
269
+ _context4.next = 2;
270
+ break;
271
+ }
272
+ throw new Error('Sales Invoice OpenData 模块未初始化');
273
+ case 2:
274
+ target = "".concat(businessCode, "+").concat(channel);
275
+ cachedData = this.invoiceOpenDataModule.getOpenData();
276
+ lastFetchedAt = this.invoiceOpenDataModule.getLastFetchedAt();
277
+ if (!(cachedData && this.invoiceOpenDataTarget === target && typeof lastFetchedAt === 'number' && Date.now() - lastFetchedAt < INVOICE_OPEN_DATA_CACHE_TTL)) {
278
+ _context4.next = 7;
279
+ break;
280
+ }
281
+ return _context4.abrupt("return", cachedData);
282
+ case 7:
283
+ if (!this.invoiceOpenDataInFlight) {
284
+ _context4.next = 18;
285
+ break;
286
+ }
287
+ if (!(this.invoiceOpenDataInFlightTarget === target)) {
288
+ _context4.next = 10;
289
+ break;
290
+ }
291
+ return _context4.abrupt("return", this.invoiceOpenDataInFlight);
292
+ case 10:
293
+ _context4.prev = 10;
294
+ _context4.next = 13;
295
+ return this.invoiceOpenDataInFlight;
296
+ case 13:
297
+ _context4.next = 17;
298
+ break;
299
+ case 15:
300
+ _context4.prev = 15;
301
+ _context4.t0 = _context4["catch"](10);
302
+ case 17:
303
+ return _context4.abrupt("return", this.loadInvoiceOpenData(businessCode, channel));
304
+ case 18:
305
+ request = this.invoiceOpenDataModule.fetchOpenData({
306
+ scope: 'board',
307
+ target: target,
308
+ section_code: [].concat(INVOICE_OPEN_DATA_SECTION_CODES)
309
+ });
310
+ this.invoiceOpenDataInFlight = request;
311
+ this.invoiceOpenDataInFlightTarget = target;
312
+ _context4.prev = 21;
313
+ _context4.next = 24;
314
+ return request;
315
+ case 24:
316
+ openData = _context4.sent;
317
+ // clearOpenDataCache() 或后续请求接管后,旧响应不得复活 target 归属。
318
+ if (this.invoiceOpenDataInFlight === request) {
319
+ this.invoiceOpenDataTarget = target;
320
+ }
321
+ return _context4.abrupt("return", openData);
322
+ case 27:
323
+ _context4.prev = 27;
324
+ if (this.invoiceOpenDataInFlight === request) {
325
+ this.invoiceOpenDataInFlight = null;
326
+ this.invoiceOpenDataInFlightTarget = null;
327
+ }
328
+ return _context4.finish(27);
329
+ case 30:
330
+ case "end":
331
+ return _context4.stop();
332
+ }
333
+ }, _callee4, this, [[10, 15], [21,, 27, 30]]);
334
+ }));
335
+ function loadInvoiceOpenData(_x4, _x5) {
336
+ return _loadInvoiceOpenData.apply(this, arguments);
337
+ }
338
+ return loadInvoiceOpenData;
339
+ }()
340
+ }, {
341
+ key: "logInvoiceOpenDataFallback",
342
+ value: function logInvoiceOpenDataFallback(error) {
343
+ var _this$logger;
344
+ var message = error instanceof Error ? error.message : String(error);
345
+ if ((_this$logger = this.logger) !== null && _this$logger !== void 0 && _this$logger.addLog) {
346
+ this.logger.addLog({
347
+ type: 'warning',
348
+ title: 'Sales Invoice OpenData 加载失败,使用默认配置',
349
+ metadata: {
350
+ message: message
351
+ }
352
+ });
353
+ return;
354
+ }
355
+ console.warn('[Sales] Invoice OpenData 加载失败,使用默认配置', error);
356
+ }
357
+ }, {
358
+ key: "resolveInvoiceConfigs",
359
+ value: function () {
360
+ var _resolveInvoiceConfigs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(businessCode, channel) {
361
+ var _this$invoiceOpenData, _this$invoiceOpenData2, _this$invoiceOpenData3, _this$invoiceOpenData4;
362
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
363
+ while (1) switch (_context5.prev = _context5.next) {
364
+ case 0:
365
+ _context5.prev = 0;
366
+ _context5.next = 3;
367
+ return this.loadInvoiceOpenData(businessCode, channel);
368
+ case 3:
369
+ if (!(this.invoiceOpenDataTarget !== "".concat(businessCode, "+").concat(channel))) {
370
+ _context5.next = 5;
371
+ break;
372
+ }
373
+ return _context5.abrupt("return", {
374
+ invoice: getDefaultInvoiceLayoutConfig(),
375
+ templateSettings: getDefaultInvoiceTemplateSettings()
376
+ });
377
+ case 5:
378
+ return _context5.abrupt("return", {
379
+ 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(),
380
+ 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()
381
+ });
382
+ case 8:
383
+ _context5.prev = 8;
384
+ _context5.t0 = _context5["catch"](0);
385
+ this.logInvoiceOpenDataFallback(_context5.t0);
386
+ return _context5.abrupt("return", {
387
+ invoice: getDefaultInvoiceLayoutConfig(),
388
+ templateSettings: getDefaultInvoiceTemplateSettings()
389
+ });
390
+ case 12:
391
+ case "end":
392
+ return _context5.stop();
393
+ }
394
+ }, _callee5, this, [[0, 8]]);
395
+ }));
396
+ function resolveInvoiceConfigs(_x6, _x7) {
397
+ return _resolveInvoiceConfigs.apply(this, arguments);
398
+ }
399
+ return resolveInvoiceConfigs;
400
+ }()
401
+ }, {
402
+ key: "printLocalOrderReceipt",
403
+ value: function () {
404
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(lookup, options) {
405
+ var _options$businessCode;
406
+ var normalizedLookup, businessCode, channel, _yield$this$resolveIn, invoice, templateSettings, lookupPayload;
407
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
408
+ while (1) switch (_context6.prev = _context6.next) {
409
+ case 0:
410
+ normalizedLookup = typeof lookup === 'string' ? lookup.trim() : lookup;
411
+ if (!(normalizedLookup === '' || normalizedLookup === null || normalizedLookup === undefined)) {
412
+ _context6.next = 3;
413
+ break;
414
+ }
415
+ throw new Error('Sales 本地小票打印需要订单标识');
416
+ case 3:
417
+ businessCode = String((_options$businessCode = options === null || options === void 0 ? void 0 : options.businessCode) !== null && _options$businessCode !== void 0 ? _options$businessCode : '').trim();
418
+ if (businessCode) {
419
+ _context6.next = 6;
420
+ break;
421
+ }
422
+ throw new Error('Sales 本地小票打印需要 businessCode');
423
+ case 6:
424
+ channel = this.getInvoiceSalesChannel(options === null || options === void 0 ? void 0 : options.channel);
425
+ _context6.next = 9;
426
+ return this.resolveInvoiceConfigs(businessCode, channel);
427
+ case 9:
428
+ _yield$this$resolveIn = _context6.sent;
429
+ invoice = _yield$this$resolveIn.invoice;
430
+ templateSettings = _yield$this$resolveIn.templateSettings;
431
+ lookupPayload = typeof normalizedLookup === 'number' ? {
432
+ order_id: normalizedLookup
433
+ } : {
434
+ external_sale_number: normalizedLookup
435
+ };
436
+ return _context6.abrupt("return", this.request.post('/local/print-order', _objectSpread(_objectSpread({}, lookupPayload), {}, {
437
+ lookup_order_from_db: 1,
438
+ small_ticket_data_flag: 1,
439
+ business_code: businessCode,
440
+ order_sales_channel: channel,
441
+ invoice: cloneDeep(invoice),
442
+ template_settings: cloneDeep(templateSettings)
443
+ }), {
444
+ osServer: true,
445
+ customToast: function customToast() {}
446
+ }));
447
+ case 14:
448
+ case "end":
449
+ return _context6.stop();
450
+ }
451
+ }, _callee6, this);
452
+ }));
453
+ function printLocalOrderReceipt(_x8, _x9) {
454
+ return _printLocalOrderReceipt.apply(this, arguments);
455
+ }
456
+ return printLocalOrderReceipt;
457
+ }() /** 清除独立 Documents 缓存;下一次打印会按当前 target 重新获取。 */
458
+ }, {
459
+ key: "clearOpenDataCache",
460
+ value: function clearOpenDataCache() {
461
+ var _this$invoiceOpenData5;
462
+ this.invoiceOpenDataInFlight = null;
463
+ this.invoiceOpenDataInFlightTarget = null;
464
+ this.invoiceOpenDataTarget = null;
465
+ (_this$invoiceOpenData5 = this.invoiceOpenDataModule) === null || _this$invoiceOpenData5 === void 0 || _this$invoiceOpenData5.clearCache();
466
+ }
467
+
468
+ // -------------------------------------------------------------------------
222
469
  // 生命周期
223
470
  // -------------------------------------------------------------------------
224
471
  }, {
225
472
  key: "destroy",
226
473
  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) {
474
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
475
+ var invoiceOpenDataModule;
476
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
477
+ while (1) switch (_context7.prev = _context7.next) {
230
478
  case 0:
231
- _context4.next = 2;
479
+ this.clearOpenDataCache();
480
+ invoiceOpenDataModule = this.invoiceOpenDataModule;
481
+ this.invoiceOpenDataModule = null;
482
+ if (!invoiceOpenDataModule) {
483
+ _context7.next = 12;
484
+ break;
485
+ }
486
+ _context7.prev = 4;
487
+ _context7.next = 7;
488
+ return invoiceOpenDataModule.destroy();
489
+ case 7:
490
+ _context7.next = 12;
491
+ break;
492
+ case 9:
493
+ _context7.prev = 9;
494
+ _context7.t0 = _context7["catch"](4);
495
+ console.warn('[Sales] Invoice OpenData 子模块销毁失败', _context7.t0);
496
+ case 12:
497
+ _context7.next = 14;
232
498
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
233
- case 2:
499
+ case 14:
234
500
  _get(_getPrototypeOf(SalesImpl.prototype), "destroy", this).call(this);
235
- case 3:
501
+ case 15:
236
502
  case "end":
237
- return _context4.stop();
503
+ return _context7.stop();
238
504
  }
239
- }, _callee4, this);
505
+ }, _callee7, this, [[4, 9]]);
240
506
  }));
241
507
  function destroy() {
242
508
  return _destroy.apply(this, arguments);
@@ -258,19 +524,19 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
258
524
  }
259
525
 
260
526
  /**
261
- * 解析营业日统计窗口:
527
+ * 解析 current 所属营业日窗口:
262
528
  * - 当 operating_day_boundary.type === 'start_time'
263
- * 使用「今天 + boundary.time」到「明天 + boundary.time」
529
+ * 使用「最近一个 boundary.time」到「下一个 boundary.time」
264
530
  * - 否则回退自然日(00:00 到次日 00:00)
265
531
  */
266
532
  }, {
267
- key: "getTimelineRangeByOperatingBoundary",
268
- value: function getTimelineRangeByOperatingBoundary() {
269
- var _appPlugin$getApp, _appPlugin$getApp$get, _appPlugin$getApp$get2, _appPlugin$getApp$get3, _coreData$core;
270
- var today = dayjs();
271
- var defaultStart = today.startOf('day');
533
+ key: "getOperatingDayRange",
534
+ value: function getOperatingDayRange() {
535
+ var _this$core2, _appPlugin$getApp, _appPlugin$getApp$get, _appPlugin$getApp$get2, _appPlugin$getApp$get3, _coreData$core;
536
+ var referenceTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : dayjs();
537
+ var defaultStart = referenceTime.startOf('day');
272
538
  var defaultEndExclusive = defaultStart.add(1, 'day');
273
- var appPlugin = this.core.getPlugin('app');
539
+ var appPlugin = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.getPlugin('app');
274
540
  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
541
  var operatingDayBoundary = coreData === null || coreData === void 0 || (_coreData$core = coreData.core) === null || _coreData$core === void 0 ? void 0 : _coreData$core.operating_day_boundary;
276
542
  if ((operatingDayBoundary === null || operatingDayBoundary === void 0 ? void 0 : operatingDayBoundary.type) !== 'start_time') {
@@ -280,18 +546,24 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
280
546
  };
281
547
  }
282
548
  var boundaryTime = String(operatingDayBoundary.time || '').trim();
283
- var startAt = dayjs("".concat(today.format('YYYY-MM-DD'), " ").concat(boundaryTime));
284
- if (!startAt.isValid()) {
549
+ var boundaryStart = dayjs("".concat(referenceTime.format('YYYY-MM-DD'), " ").concat(boundaryTime));
550
+ if (!boundaryStart.isValid()) {
285
551
  return {
286
552
  startAt: defaultStart,
287
553
  endExclusiveAt: defaultEndExclusive
288
554
  };
289
555
  }
556
+ var startAt = referenceTime.isBefore(boundaryStart) ? boundaryStart.subtract(1, 'day') : boundaryStart;
290
557
  return {
291
558
  startAt: startAt,
292
559
  endExclusiveAt: startAt.add(1, 'day')
293
560
  };
294
561
  }
562
+ }, {
563
+ key: "getTimelineRangeByOperatingBoundary",
564
+ value: function getTimelineRangeByOperatingBoundary() {
565
+ return this.getOperatingDayRange();
566
+ }
295
567
 
296
568
  /**
297
569
  * 统计时间轴每个时间片的预约数量。
@@ -310,12 +582,12 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
310
582
  var customStartAt = startDateTime ? dayjs(startDateTime) : dayjs('');
311
583
  var customEndExclusiveAt = endDateTime ? dayjs(endDateTime) : dayjs('');
312
584
  var hasValidCustomRange = customStartAt.isValid() && customEndExclusiveAt.isValid();
313
- var _ref = hasValidCustomRange ? {
585
+ var _ref2 = hasValidCustomRange ? {
314
586
  startAt: customStartAt,
315
587
  endExclusiveAt: customEndExclusiveAt
316
588
  } : this.getTimelineRangeByOperatingBoundary(),
317
- startAt = _ref.startAt,
318
- endExclusiveAt = _ref.endExclusiveAt;
589
+ startAt = _ref2.startAt,
590
+ endExclusiveAt = _ref2.endExclusiveAt;
319
591
  var startAtMs = startAt.valueOf();
320
592
  var endExclusiveAtMs = endExclusiveAt.valueOf();
321
593
  if (!startAt.isValid() || !endExclusiveAt.isValid() || endExclusiveAtMs <= startAtMs) return [];
@@ -323,9 +595,9 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
323
595
  if (slotCount <= 0) return [];
324
596
  var diff = new Int32Array(slotCount + 1);
325
597
  for (var i = 0; i < bookingList.length; i++) {
326
- var _ref2, _booking$appointment_;
598
+ var _ref3, _booking$appointment_;
327
599
  var booking = bookingList[i];
328
- var appointmentStatus = String((_ref2 = (_booking$appointment_ = booking.appointment_status) !== null && _booking$appointment_ !== void 0 ? _booking$appointment_ : booking.status) !== null && _ref2 !== void 0 ? _ref2 : '');
600
+ var appointmentStatus = String((_ref3 = (_booking$appointment_ = booking.appointment_status) !== null && _booking$appointment_ !== void 0 ? _booking$appointment_ : booking.status) !== null && _ref3 !== void 0 ? _ref3 : '');
329
601
  if (appointmentStatus === 'new' || appointmentStatus === 'rejected' || appointmentStatus === 'cancelled') continue;
330
602
  var bookingStartAt = this.toBookingDateTime(booking.start_date, booking.start_time);
331
603
  var bookingEndAt = this.toBookingDateTime(booking.end_date, booking.end_time);
@@ -395,14 +667,14 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
395
667
  }, {
396
668
  key: "getResourceId",
397
669
  value: function getResourceId(resource) {
398
- var _ref3, _resource$id;
399
- return (_ref3 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.form_record_id) !== null && _ref3 !== void 0 ? _ref3 : '';
670
+ var _ref4, _resource$id;
671
+ return (_ref4 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.form_record_id) !== null && _ref4 !== void 0 ? _ref4 : '';
400
672
  }
401
673
  }, {
402
674
  key: "getBookingAppointmentStatus",
403
675
  value: function getBookingAppointmentStatus(booking) {
404
- var _ref4, _booking$appointment_2;
405
- 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 : '');
676
+ var _ref5, _booking$appointment_2;
677
+ 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 : '');
406
678
  }
407
679
  }, {
408
680
  key: "isBookingIncludedInStats",
@@ -485,7 +757,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
485
757
  * 2) 若无 active,返回已超时且仍占用中的预约(允许并发多条)
486
758
  * 3) 若仍无,返回最近一组未来预约(同 start_time 的并发预约全部返回)
487
759
  * 4) 最后兜底返回一条(避免资源有历史预约时完全无反馈)
488
- * - includeAllFuture 时,保留选中预约并返回当天全部后续预约;仅详情接口启用。
760
+ * - includeAllFuture 时,保留选中预约并返回当前营业日全部后续预约;仅详情接口启用。
489
761
  */
490
762
  }, {
491
763
  key: "pickBookingsForCurrentPoint",
@@ -493,15 +765,16 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
493
765
  var _this4 = this;
494
766
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
495
767
  if (bookings.length === 0) return [];
496
- var currentDayStart = current.startOf('day');
497
- var currentDayEnd = current.endOf('day');
768
+ var _this$getOperatingDay = this.getOperatingDayRange(current),
769
+ operatingDayStart = _this$getOperatingDay.startAt,
770
+ operatingDayEndExclusive = _this$getOperatingDay.endExclusiveAt;
498
771
 
499
- // 仅保留与 current 当天有时间交集的预约,避免跨天误命中
772
+ // 仅保留与 current 所属营业日窗口有时间交集的预约,避免跨营业日误命中
500
773
  var dayScopedBookings = bookings.filter(function (booking) {
501
774
  var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
502
775
  var endAt = _this4.toBookingDateTime(booking.end_date, booking.end_time);
503
776
  if (!startAt.isValid() || !endAt.isValid()) return false;
504
- return _this4.isSameOrBefore(startAt, currentDayEnd) && _this4.isSameOrAfter(endAt, currentDayStart);
777
+ return startAt.isBefore(operatingDayEndExclusive) && _this4.isSameOrAfter(endAt, operatingDayStart);
505
778
  });
506
779
  if (dayScopedBookings.length === 0) return [];
507
780
  var appendNextStartGroupIfNeeded = function appendNextStartGroupIfNeeded(selectedBookings) {
@@ -560,7 +833,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
560
833
  // upcoming: 从未来预约里只取最早那一组(同 start_time)
561
834
  var upcoming = dayScopedBookings.filter(function (booking) {
562
835
  var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
563
- return startAt.isValid() && startAt.isAfter(current) && startAt.isSame(current, 'day');
836
+ return startAt.isValid() && startAt.isAfter(current);
564
837
  });
565
838
  if (upcoming.length > 0) {
566
839
  if (options.includeAllFuture) return upcoming;
@@ -749,7 +1022,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
749
1022
  }, {
750
1023
  key: "getResourceBookingList",
751
1024
  value: function () {
752
- var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(currentTime) {
1025
+ var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(currentTime) {
753
1026
  var _resourceResponse$dat,
754
1027
  _resourceResponse$dat2,
755
1028
  _this6 = this;
@@ -763,28 +1036,28 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
763
1036
  rawBookingMap,
764
1037
  bookingMap,
765
1038
  list,
766
- _args5 = arguments;
767
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
768
- while (1) switch (_context5.prev = _context5.next) {
1039
+ _args8 = arguments;
1040
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1041
+ while (1) switch (_context8.prev = _context8.next) {
769
1042
  case 0:
770
- bookingList = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : [];
771
- deviceTime = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : currentTime;
1043
+ bookingList = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : [];
1044
+ deviceTime = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : currentTime;
772
1045
  // currentTime 约定为完整 datetime;非法值直接返回空,避免误判
773
1046
  current = dayjs(currentTime);
774
1047
  if (current.isValid()) {
775
- _context5.next = 5;
1048
+ _context8.next = 5;
776
1049
  break;
777
1050
  }
778
- return _context5.abrupt("return", []);
1051
+ return _context8.abrupt("return", []);
779
1052
  case 5:
780
1053
  deviceCurrent = dayjs(deviceTime);
781
1054
  if (deviceCurrent.isValid()) {
782
- _context5.next = 8;
1055
+ _context8.next = 8;
783
1056
  break;
784
1057
  }
785
- return _context5.abrupt("return", []);
1058
+ return _context8.abrupt("return", []);
786
1059
  case 8:
787
- _context5.next = 10;
1060
+ _context8.next = 10;
788
1061
  return this.request.get('/shop/form/resource/page', {
789
1062
  skip: 1,
790
1063
  num: 999
@@ -795,13 +1068,13 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
795
1068
  isShopApi: true
796
1069
  });
797
1070
  case 10:
798
- resourceResponse = _context5.sent;
1071
+ resourceResponse = _context8.sent;
799
1072
  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 : [];
800
1073
  if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
801
- _context5.next = 14;
1074
+ _context8.next = 14;
802
1075
  break;
803
1076
  }
804
- return _context5.abrupt("return", []);
1077
+ return _context8.abrupt("return", []);
805
1078
  case 14:
806
1079
  // 全局先做 booking 标准化 + start_time 升序,后续映射直接复用
807
1080
  normalizedBookings = this.normalizeResourceBookings(current, deviceCurrent, bookingList); // 建立 resourceId -> bookings[] 倒排索引,加速资源匹配
@@ -836,14 +1109,14 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
836
1109
  list: list === null || list === void 0 ? void 0 : list.length
837
1110
  }
838
1111
  });
839
- return _context5.abrupt("return", list);
1112
+ return _context8.abrupt("return", list);
840
1113
  case 20:
841
1114
  case "end":
842
- return _context5.stop();
1115
+ return _context8.stop();
843
1116
  }
844
- }, _callee5, this);
1117
+ }, _callee8, this);
845
1118
  }));
846
- function getResourceBookingList(_x4) {
1119
+ function getResourceBookingList(_x10) {
847
1120
  return _getResourceBookingList.apply(this, arguments);
848
1121
  }
849
1122
  return getResourceBookingList;
@@ -851,30 +1124,30 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
851
1124
  }, {
852
1125
  key: "getResourceBookingItem",
853
1126
  value: function () {
854
- var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
1127
+ var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
855
1128
  var _resourceResponse$dat3,
856
1129
  _resourceResponse$dat4,
857
1130
  _this7 = this,
858
1131
  _params$bookingList;
859
1132
  var current, deviceCurrent, resourceResponse, resourceList, targetResource, resourceId, matchedBookingList, statsBookingList, completedBookingList, unpaidBookingList, bookings, completedBookings, unpaidBookings, orderCount, bookingCount, compeleteBookingCount;
860
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
861
- while (1) switch (_context6.prev = _context6.next) {
1133
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1134
+ while (1) switch (_context9.prev = _context9.next) {
862
1135
  case 0:
863
1136
  current = dayjs(params.currentTime);
864
1137
  if (current.isValid()) {
865
- _context6.next = 3;
1138
+ _context9.next = 3;
866
1139
  break;
867
1140
  }
868
- return _context6.abrupt("return", null);
1141
+ return _context9.abrupt("return", null);
869
1142
  case 3:
870
1143
  deviceCurrent = dayjs(params.deviceTime || params.currentTime);
871
1144
  if (deviceCurrent.isValid()) {
872
- _context6.next = 6;
1145
+ _context9.next = 6;
873
1146
  break;
874
1147
  }
875
- return _context6.abrupt("return", null);
1148
+ return _context9.abrupt("return", null);
876
1149
  case 6:
877
- _context6.next = 8;
1150
+ _context9.next = 8;
878
1151
  return this.request.get('/shop/form/resource/page', {
879
1152
  skip: 1,
880
1153
  num: 999
@@ -885,22 +1158,22 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
885
1158
  isShopApi: true
886
1159
  });
887
1160
  case 8:
888
- resourceResponse = _context6.sent;
1161
+ resourceResponse = _context9.sent;
889
1162
  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 : [];
890
1163
  if (!(!Array.isArray(resourceList) || resourceList.length === 0)) {
891
- _context6.next = 12;
1164
+ _context9.next = 12;
892
1165
  break;
893
1166
  }
894
- return _context6.abrupt("return", null);
1167
+ return _context9.abrupt("return", null);
895
1168
  case 12:
896
1169
  targetResource = resourceList.find(function (resource) {
897
1170
  return String(_this7.getResourceId(resource)) === String(params.resourceId);
898
1171
  });
899
1172
  if (targetResource) {
900
- _context6.next = 15;
1173
+ _context9.next = 15;
901
1174
  break;
902
1175
  }
903
- return _context6.abrupt("return", null);
1176
+ return _context9.abrupt("return", null);
904
1177
  case 15:
905
1178
  resourceId = this.getResourceId(targetResource);
906
1179
  matchedBookingList = params.bookingList.filter(function (booking) {
@@ -953,7 +1226,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
953
1226
  compeleteBookingCount: compeleteBookingCount
954
1227
  }
955
1228
  });
956
- return _context6.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
1229
+ return _context9.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
957
1230
  resource_id: resourceId,
958
1231
  orderCount: orderCount,
959
1232
  bookingCount: bookingCount,
@@ -964,11 +1237,11 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
964
1237
  }));
965
1238
  case 28:
966
1239
  case "end":
967
- return _context6.stop();
1240
+ return _context9.stop();
968
1241
  }
969
- }, _callee6, this);
1242
+ }, _callee9, this);
970
1243
  }));
971
- function getResourceBookingItem(_x5) {
1244
+ function getResourceBookingItem(_x11) {
972
1245
  return _getResourceBookingItem.apply(this, arguments);
973
1246
  }
974
1247
  return getResourceBookingItem;