@pisell/pisellos 2.2.152 → 2.2.154

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 (92) hide show
  1. package/dist/core/index.js +1 -0
  2. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  3. package/dist/modules/Cart/utils/cartProduct.js +1 -1
  4. package/dist/modules/Discount/index.d.ts +6 -2
  5. package/dist/modules/Discount/index.js +14 -8
  6. package/dist/modules/Order/index.d.ts +2 -0
  7. package/dist/modules/Order/index.js +234 -161
  8. package/dist/modules/Order/types.d.ts +19 -0
  9. package/dist/modules/Order/utils.js +7 -6
  10. package/dist/modules/Payment/index.d.ts +4 -0
  11. package/dist/modules/Payment/index.js +567 -505
  12. package/dist/modules/Payment/types.d.ts +29 -9
  13. package/dist/modules/SalesSummary/index.d.ts +7 -5
  14. package/dist/modules/SalesSummary/index.js +35 -11
  15. package/dist/plugins/app.d.ts +2 -0
  16. package/dist/server/index.d.ts +2 -5
  17. package/dist/server/index.js +58 -66
  18. package/dist/server/modules/index.d.ts +1 -1
  19. package/dist/server/modules/products/index.d.ts +12 -1
  20. package/dist/server/modules/products/index.js +169 -78
  21. package/dist/server/modules/products/types.d.ts +11 -0
  22. package/dist/server/modules/products/types.js +4 -0
  23. package/dist/server/utils/product.js +2 -2
  24. package/dist/solution/BaseSales/index.d.ts +26 -2
  25. package/dist/solution/BaseSales/index.js +342 -112
  26. package/dist/solution/BaseSales/types.d.ts +4 -4
  27. package/dist/solution/BaseSales/types.js +4 -4
  28. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +62 -0
  29. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +116 -0
  30. package/dist/solution/BaseSales/utils.js +3 -3
  31. package/dist/solution/BookingByStep/index.d.ts +1 -1
  32. package/dist/solution/BookingTicket/index.d.ts +11 -13
  33. package/dist/solution/BookingTicket/index.js +23 -37
  34. package/dist/solution/BookingTicket/types.d.ts +9 -6
  35. package/dist/solution/BookingTicket/types.js +6 -3
  36. package/dist/solution/BookingTicket/utils/cartView.d.ts +7 -12
  37. package/dist/solution/BookingTicket/utils/cartView.js +52 -14
  38. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  39. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  40. package/dist/solution/Sales/index.d.ts +3 -0
  41. package/dist/solution/Sales/index.js +85 -43
  42. package/dist/solution/Sales/types.d.ts +3 -0
  43. package/dist/solution/ScanOrder/types.d.ts +4 -4
  44. package/dist/solution/ScanOrder/types.js +4 -4
  45. package/dist/solution/ScanOrder/utils.js +3 -3
  46. package/dist/solution/ShopDiscount/index.d.ts +2 -1
  47. package/dist/solution/ShopDiscount/index.js +32 -20
  48. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  49. package/lib/core/index.js +1 -0
  50. package/lib/modules/Cart/utils/cartProduct.js +1 -1
  51. package/lib/modules/Discount/index.d.ts +6 -2
  52. package/lib/modules/Discount/index.js +3 -1
  53. package/lib/modules/Order/index.d.ts +2 -0
  54. package/lib/modules/Order/index.js +40 -8
  55. package/lib/modules/Order/types.d.ts +19 -0
  56. package/lib/modules/Order/utils.js +4 -2
  57. package/lib/modules/Payment/index.d.ts +4 -0
  58. package/lib/modules/Payment/index.js +26 -2
  59. package/lib/modules/Payment/types.d.ts +29 -9
  60. package/lib/modules/SalesSummary/index.d.ts +7 -5
  61. package/lib/modules/SalesSummary/index.js +29 -9
  62. package/lib/plugins/app.d.ts +2 -0
  63. package/lib/server/index.d.ts +2 -5
  64. package/lib/server/index.js +38 -58
  65. package/lib/server/modules/index.d.ts +1 -1
  66. package/lib/server/modules/products/index.d.ts +12 -1
  67. package/lib/server/modules/products/index.js +69 -9
  68. package/lib/server/modules/products/types.d.ts +11 -0
  69. package/lib/server/utils/product.js +2 -2
  70. package/lib/solution/BaseSales/index.d.ts +26 -2
  71. package/lib/solution/BaseSales/index.js +169 -3
  72. package/lib/solution/BaseSales/types.d.ts +4 -4
  73. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +62 -0
  74. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +155 -0
  75. package/lib/solution/BaseSales/utils.js +3 -3
  76. package/lib/solution/BookingByStep/index.d.ts +1 -1
  77. package/lib/solution/BookingTicket/index.d.ts +11 -13
  78. package/lib/solution/BookingTicket/index.js +17 -27
  79. package/lib/solution/BookingTicket/types.d.ts +9 -6
  80. package/lib/solution/BookingTicket/utils/cartView.d.ts +7 -12
  81. package/lib/solution/BookingTicket/utils/cartView.js +44 -18
  82. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  83. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  84. package/lib/solution/Sales/index.d.ts +3 -0
  85. package/lib/solution/Sales/index.js +50 -15
  86. package/lib/solution/Sales/types.d.ts +3 -0
  87. package/lib/solution/ScanOrder/types.d.ts +4 -4
  88. package/lib/solution/ScanOrder/utils.js +3 -3
  89. package/lib/solution/ShopDiscount/index.d.ts +2 -1
  90. package/lib/solution/ShopDiscount/index.js +10 -4
  91. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  92. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ /** 从 ICustomer 富字段解析展示名(与 SalesSdk getClientName 语义对齐)。 */
2
+ function resolveCustomerDisplayName(customer) {
3
+ var _customer$name;
4
+ var c = customer;
5
+ var displayName = c.display_name;
6
+ if (typeof displayName === 'string' && displayName) return displayName;
7
+ var nickname = c.nickname;
8
+ if (typeof nickname === 'string' && nickname) return nickname;
9
+ var firstName = c.first_name;
10
+ var lastName = c.last_name;
11
+ if (typeof firstName === 'string' && firstName || typeof lastName === 'string' && lastName) {
12
+ return "".concat(typeof firstName === 'string' ? firstName : '', " ").concat(typeof lastName === 'string' ? lastName : '').trim();
13
+ }
14
+ var customerName = c.customer_name;
15
+ if (typeof customerName === 'string' && customerName) return customerName;
16
+ return (_customer$name = customer.name) !== null && _customer$name !== void 0 ? _customer$name : '';
17
+ }
18
+
19
+ /** 将 ICustomer 格式化为写入 tempOrder 的协议字段。 */
20
+ export function formatOrderCustomerPatch(customer) {
21
+ var _customer$phone, _customer$email, _country_calling_code, _country_calling_code2;
22
+ var rawId = customer.id;
23
+ var numericId = typeof rawId === 'number' ? rawId : rawId !== undefined && rawId !== null && rawId !== '' ? Number(rawId) : null;
24
+ return {
25
+ customer_id: Number.isFinite(numericId) ? numericId : null,
26
+ customer_name: resolveCustomerDisplayName(customer),
27
+ phone: (_customer$phone = customer.phone) !== null && _customer$phone !== void 0 ? _customer$phone : '',
28
+ email: (_customer$email = customer.email) !== null && _customer$email !== void 0 ? _customer$email : '',
29
+ country_calling_code: (_country_calling_code = (_country_calling_code2 = customer.country_calling_code) === null || _country_calling_code2 === void 0 ? void 0 : _country_calling_code2.toString()) !== null && _country_calling_code !== void 0 ? _country_calling_code : ''
30
+ };
31
+ }
@@ -82,6 +82,9 @@ export declare class SalesImpl extends BaseModule implements Module, SalesModule
82
82
  private getResourceId;
83
83
  private getBookingAppointmentStatus;
84
84
  private getBookingOrderPaymentStatus;
85
+ private countBookingOrders;
86
+ private countCompletedBookings;
87
+ private groupBookingsByResource;
85
88
  private isBookingMatchedResource;
86
89
  private sortMatchedBookings;
87
90
  /**
@@ -409,6 +409,43 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
409
409
  var _booking$order$paymen, _booking$order;
410
410
  return String((_booking$order$paymen = (_booking$order = booking.order) === null || _booking$order === void 0 ? void 0 : _booking$order.payment_status) !== null && _booking$order$paymen !== void 0 ? _booking$order$paymen : '');
411
411
  }
412
+ }, {
413
+ key: "countBookingOrders",
414
+ value: function countBookingOrders(bookings) {
415
+ var orderIds = new Set();
416
+ bookings.forEach(function (booking) {
417
+ var _order_id, _booking$order2;
418
+ var orderId = (_order_id = booking.order_id) !== null && _order_id !== void 0 ? _order_id : (_booking$order2 = booking.order) === null || _booking$order2 === void 0 ? void 0 : _booking$order2.order_id;
419
+ if (orderId === undefined || orderId === null) return;
420
+ orderIds.add(String(orderId));
421
+ });
422
+ return orderIds.size;
423
+ }
424
+ }, {
425
+ key: "countCompletedBookings",
426
+ value: function countCompletedBookings(bookings) {
427
+ var _this2 = this;
428
+ return bookings.filter(function (booking) {
429
+ return _this2.getBookingAppointmentStatus(booking) === 'completed';
430
+ }).length;
431
+ }
432
+ }, {
433
+ key: "groupBookingsByResource",
434
+ value: function groupBookingsByResource(bookingList) {
435
+ var bookingMap = new Map();
436
+ bookingList.forEach(function (booking) {
437
+ if (!Array.isArray(booking.resources)) return;
438
+ booking.resources.forEach(function (resource) {
439
+ var relationId = resource === null || resource === void 0 ? void 0 : resource.relation_id;
440
+ if (relationId === undefined || relationId === null) return;
441
+ var key = String(relationId);
442
+ var list = bookingMap.get(key) || [];
443
+ list.push(booking);
444
+ bookingMap.set(key, list);
445
+ });
446
+ });
447
+ return bookingMap;
448
+ }
412
449
  }, {
413
450
  key: "isBookingMatchedResource",
414
451
  value: function isBookingMatchedResource(booking, resourceId) {
@@ -422,10 +459,10 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
422
459
  }, {
423
460
  key: "sortMatchedBookings",
424
461
  value: function sortMatchedBookings(bookings) {
425
- var _this2 = this;
462
+ var _this3 = this;
426
463
  return _toConsumableArray(bookings).sort(function (left, right) {
427
- var leftStartAt = _this2.toBookingDateTime(left.start_date, left.start_time).valueOf();
428
- var rightStartAt = _this2.toBookingDateTime(right.start_date, right.start_time).valueOf();
464
+ var leftStartAt = _this3.toBookingDateTime(left.start_date, left.start_time).valueOf();
465
+ var rightStartAt = _this3.toBookingDateTime(right.start_date, right.start_time).valueOf();
429
466
  return leftStartAt - rightStartAt;
430
467
  });
431
468
  }
@@ -440,17 +477,17 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
440
477
  }, {
441
478
  key: "pickBookingsForCurrentPoint",
442
479
  value: function pickBookingsForCurrentPoint(current, bookings) {
443
- var _this3 = this;
480
+ var _this4 = this;
444
481
  if (bookings.length === 0) return [];
445
482
  var currentDayStart = current.startOf('day');
446
483
  var currentDayEnd = current.endOf('day');
447
484
 
448
485
  // 仅保留与 current 当天有时间交集的预约,避免跨天误命中
449
486
  var dayScopedBookings = bookings.filter(function (booking) {
450
- var startAt = _this3.toBookingDateTime(booking.start_date, booking.start_time);
451
- var endAt = _this3.toBookingDateTime(booking.end_date, booking.end_time);
487
+ var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
488
+ var endAt = _this4.toBookingDateTime(booking.end_date, booking.end_time);
452
489
  if (!startAt.isValid() || !endAt.isValid()) return false;
453
- return _this3.isSameOrBefore(startAt, currentDayEnd) && _this3.isSameOrAfter(endAt, currentDayStart);
490
+ return _this4.isSameOrBefore(startAt, currentDayEnd) && _this4.isSameOrAfter(endAt, currentDayStart);
454
491
  });
455
492
  if (dayScopedBookings.length === 0) return [];
456
493
  var appendNextStartGroupIfNeeded = function appendNextStartGroupIfNeeded(selectedBookings) {
@@ -460,21 +497,21 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
460
497
  });
461
498
  if (!shouldAppendNextGroup) return selectedBookings;
462
499
  var selectedStartValues = new Set(selectedBookings.map(function (booking) {
463
- return _this3.toBookingDateTime(booking.start_date, booking.start_time);
500
+ return _this4.toBookingDateTime(booking.start_date, booking.start_time);
464
501
  }).filter(function (startAt) {
465
502
  return startAt.isValid();
466
503
  }).map(function (startAt) {
467
504
  return startAt.valueOf();
468
505
  }));
469
506
  var futureCandidates = dayScopedBookings.filter(function (booking) {
470
- var startAt = _this3.toBookingDateTime(booking.start_date, booking.start_time);
507
+ var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
471
508
  if (!startAt.isValid()) return false;
472
509
  return startAt.isAfter(current) && !selectedStartValues.has(startAt.valueOf());
473
510
  });
474
511
  if (futureCandidates.length === 0) return selectedBookings;
475
- var nextStartAt = _this3.toBookingDateTime(futureCandidates[0].start_date, futureCandidates[0].start_time).valueOf();
512
+ var nextStartAt = _this4.toBookingDateTime(futureCandidates[0].start_date, futureCandidates[0].start_time).valueOf();
476
513
  var nextStartGroup = futureCandidates.filter(function (booking) {
477
- var startAt = _this3.toBookingDateTime(booking.start_date, booking.start_time);
514
+ var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
478
515
  return startAt.isValid() && startAt.valueOf() === nextStartAt;
479
516
  });
480
517
  if (nextStartGroup.length === 0) return selectedBookings;
@@ -486,10 +523,10 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
486
523
 
487
524
  // active: current 处于 [startAt, endAt] 区间
488
525
  var activeBookings = dayScopedBookings.filter(function (booking) {
489
- var startAt = _this3.toBookingDateTime(booking.start_date, booking.start_time);
490
- var endAt = _this3.toBookingDateTime(booking.end_date, booking.end_time);
526
+ var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
527
+ var endAt = _this4.toBookingDateTime(booking.end_date, booking.end_time);
491
528
  if (!startAt.isValid() || !endAt.isValid()) return false;
492
- return _this3.isSameOrAfter(current, startAt) && _this3.isSameOrBefore(current, endAt);
529
+ return _this4.isSameOrAfter(current, startAt) && _this4.isSameOrBefore(current, endAt);
493
530
  });
494
531
  if (activeBookings.length > 0) return appendNextStartGroupIfNeeded(activeBookings);
495
532
 
@@ -501,13 +538,13 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
501
538
 
502
539
  // upcoming: 从未来预约里只取最早那一组(同 start_time)
503
540
  var upcoming = dayScopedBookings.filter(function (booking) {
504
- var startAt = _this3.toBookingDateTime(booking.start_date, booking.start_time);
541
+ var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
505
542
  return startAt.isValid() && startAt.isAfter(current) && startAt.isSame(current, 'day');
506
543
  });
507
544
  if (upcoming.length > 0) {
508
545
  var firstStartAt = this.toBookingDateTime(upcoming[0].start_date, upcoming[0].start_time).valueOf();
509
546
  var upcomingStartGroup = upcoming.filter(function (booking) {
510
- var startAt = _this3.toBookingDateTime(booking.start_date, booking.start_time);
547
+ var startAt = _this4.toBookingDateTime(booking.start_date, booking.start_time);
511
548
  return startAt.valueOf() === firstStartAt;
512
549
  });
513
550
  return appendNextStartGroupIfNeeded(upcomingStartGroup);
@@ -560,10 +597,10 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
560
597
  }, {
561
598
  key: "normalizeResourceBookings",
562
599
  value: function normalizeResourceBookings(current, deviceCurrent, bookingList) {
563
- var _this4 = this;
600
+ var _this5 = this;
564
601
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
565
602
  var normalizedBookings = bookingList.map(function (booking) {
566
- return _this4.normalizeMatchedBooking(current, deviceCurrent, booking, options);
603
+ return _this5.normalizeMatchedBooking(current, deviceCurrent, booking, options);
567
604
  }).filter(function (booking) {
568
605
  return Boolean(booking);
569
606
  }).filter(function (booking) {
@@ -693,7 +730,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
693
730
  var _getResourceBookingList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(currentTime) {
694
731
  var _resourceResponse$dat,
695
732
  _resourceResponse$dat2,
696
- _this5 = this;
733
+ _this6 = this;
697
734
  var bookingList,
698
735
  deviceTime,
699
736
  current,
@@ -701,6 +738,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
701
738
  resourceResponse,
702
739
  resourceList,
703
740
  normalizedBookings,
741
+ rawBookingMap,
704
742
  bookingMap,
705
743
  list,
706
744
  _args5 = arguments;
@@ -745,26 +783,21 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
745
783
  case 14:
746
784
  // 全局先做 booking 标准化 + start_time 升序,后续映射直接复用
747
785
  normalizedBookings = this.normalizeResourceBookings(current, deviceCurrent, bookingList); // 建立 resourceId -> bookings[] 倒排索引,加速资源匹配
748
- bookingMap = new Map();
749
- normalizedBookings.forEach(function (booking) {
750
- if (!Array.isArray(booking.resources)) return;
751
- booking.resources.forEach(function (resource) {
752
- var relationId = resource === null || resource === void 0 ? void 0 : resource.relation_id;
753
- if (relationId === undefined || relationId === null) return;
754
- var key = String(relationId);
755
- var list = bookingMap.get(key) || [];
756
- list.push(booking);
757
- bookingMap.set(key, list);
758
- });
759
- });
760
-
761
- // 输出:每个资源都返回;bookings 可能是 0 / 1 / 多条(并发场景)
786
+ rawBookingMap = this.groupBookingsByResource(bookingList);
787
+ bookingMap = this.groupBookingsByResource(normalizedBookings); // 输出:每个资源都返回;bookings 可能是 0 / 1 / 多条(并发场景)
762
788
  list = resourceList.map(function (resource) {
763
- var resourceId = _this5.getResourceId(resource);
789
+ var resourceId = _this6.getResourceId(resource);
790
+ var rawMatchedBookings = rawBookingMap.get(String(resourceId)) || [];
764
791
  var matchedBookings = bookingMap.get(String(resourceId)) || [];
765
- var bookings = _this5.pickBookingsForCurrentPoint(current, matchedBookings);
792
+ var orderCount = _this6.countBookingOrders(rawMatchedBookings);
793
+ var bookingCount = rawMatchedBookings.length;
794
+ var compeleteBookingCount = _this6.countCompletedBookings(rawMatchedBookings);
795
+ var bookings = _this6.pickBookingsForCurrentPoint(current, matchedBookings);
766
796
  return _objectSpread(_objectSpread({}, resource), {}, {
767
797
  resource_id: resourceId,
798
+ orderCount: orderCount,
799
+ bookingCount: bookingCount,
800
+ compeleteBookingCount: compeleteBookingCount,
768
801
  bookings: bookings
769
802
  });
770
803
  });
@@ -796,9 +829,9 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
796
829
  var _getResourceBookingItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
797
830
  var _resourceResponse$dat3,
798
831
  _resourceResponse$dat4,
799
- _this6 = this,
832
+ _this7 = this,
800
833
  _params$bookingList;
801
- var current, deviceCurrent, resourceResponse, resourceList, targetResource, resourceId, matchedBookingList, completedBookingList, unpaidBookingList, bookings, completedBookings, unpaidBookings;
834
+ var current, deviceCurrent, resourceResponse, resourceList, targetResource, resourceId, matchedBookingList, completedBookingList, unpaidBookingList, bookings, completedBookings, unpaidBookings, orderCount, bookingCount, compeleteBookingCount;
802
835
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
803
836
  while (1) switch (_context6.prev = _context6.next) {
804
837
  case 0:
@@ -836,7 +869,7 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
836
869
  return _context6.abrupt("return", null);
837
870
  case 12:
838
871
  targetResource = resourceList.find(function (resource) {
839
- return String(_this6.getResourceId(resource)) === String(params.resourceId);
872
+ return String(_this7.getResourceId(resource)) === String(params.resourceId);
840
873
  });
841
874
  if (targetResource) {
842
875
  _context6.next = 15;
@@ -846,19 +879,22 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
846
879
  case 15:
847
880
  resourceId = this.getResourceId(targetResource);
848
881
  matchedBookingList = params.bookingList.filter(function (booking) {
849
- return _this6.isBookingMatchedResource(booking, resourceId);
882
+ return _this7.isBookingMatchedResource(booking, resourceId);
850
883
  });
851
884
  completedBookingList = matchedBookingList.filter(function (booking) {
852
- return _this6.getBookingAppointmentStatus(booking) === 'completed';
885
+ return _this7.getBookingAppointmentStatus(booking) === 'completed';
853
886
  });
854
887
  unpaidBookingList = matchedBookingList.filter(function (booking) {
855
- return _this6.getBookingOrderPaymentStatus(booking) === 'unpaid' || _this6.getBookingOrderPaymentStatus(booking) === 'payment_processing';
888
+ return _this7.getBookingOrderPaymentStatus(booking) === 'unpaid' || _this7.getBookingOrderPaymentStatus(booking) === 'payment_processing';
856
889
  });
857
890
  bookings = this.pickBookingsForCurrentPoint(current, this.normalizeResourceBookings(current, deviceCurrent, matchedBookingList));
858
891
  completedBookings = this.pickBookingsForCurrentPoint(current, this.normalizeResourceBookings(current, deviceCurrent, completedBookingList, {
859
892
  includeCompleted: true
860
893
  }));
861
894
  unpaidBookings = this.pickBookingsForCurrentPoint(current, this.normalizeResourceBookings(current, deviceCurrent, unpaidBookingList));
895
+ orderCount = this.countBookingOrders(matchedBookingList);
896
+ bookingCount = matchedBookingList.length;
897
+ compeleteBookingCount = completedBookingList.length;
862
898
  this.logger.addLog({
863
899
  type: 'info',
864
900
  title: 'getResourceBookingItem',
@@ -869,16 +905,22 @@ export var SalesImpl = /*#__PURE__*/function (_BaseModule) {
869
905
  bookingList: (_params$bookingList = params.bookingList) === null || _params$bookingList === void 0 ? void 0 : _params$bookingList.length,
870
906
  bookings: bookings.length,
871
907
  completedBookings: completedBookings.length,
872
- unpaidBookings: unpaidBookings.length
908
+ unpaidBookings: unpaidBookings.length,
909
+ orderCount: orderCount,
910
+ bookingCount: bookingCount,
911
+ compeleteBookingCount: compeleteBookingCount
873
912
  }
874
913
  });
875
914
  return _context6.abrupt("return", _objectSpread(_objectSpread({}, targetResource), {}, {
876
915
  resource_id: resourceId,
916
+ orderCount: orderCount,
917
+ bookingCount: bookingCount,
918
+ compeleteBookingCount: compeleteBookingCount,
877
919
  bookings: bookings,
878
920
  completedBookings: completedBookings,
879
921
  unpaidBookings: unpaidBookings
880
922
  }));
881
- case 24:
923
+ case 27:
882
924
  case "end":
883
925
  return _context6.stop();
884
926
  }
@@ -30,6 +30,9 @@ export interface SalesResourceMatchedBooking extends Omit<BookingData, 'status'>
30
30
  }
31
31
  export interface SalesResourceBookingItem extends Omit<ResourceData, 'bookings'> {
32
32
  resource_id: ResourceId;
33
+ orderCount: number;
34
+ bookingCount: number;
35
+ compeleteBookingCount: number;
33
36
  bookings: SalesResourceMatchedBooking[];
34
37
  }
35
38
  export interface SalesResourceBookingItemWithGroups extends SalesResourceBookingItem {
@@ -85,13 +85,13 @@ export interface ScanOrderOrderProduct extends ScanOrderOrderProductIdentity {
85
85
  * 出站 payload 版本的商品行。
86
86
  *
87
87
  * 与 tempOrder 内部 `ScanOrderOrderProduct` 的字段差异:
88
- * - `product_option_item[*]`:内部为 `{ product_option_item_id, option_group_id, num, price, ... }`,
89
- * 出站由 `normalizeSubmitProduct` 重命名为 `{ option_group_item_id, option_group_id, num }`
88
+ * - `product_option_item[*]`:内部为 `{ option_group_item_id, option_group_id, num, price, ... }`,
89
+ * 出站保留 `{ option_group_item_id, option_group_id, num }`
90
90
  * (后端 checkout 协议;丢弃 `price` 等运行时辅助字段)。
91
91
  * - `product_bundle[*].option[*]`:同上重命名规则。
92
92
  *
93
- * 运行时(UI 显示、加购合并、指纹、持久化)全部消费内部字段名 `product_option_item_id`,
94
- * 仅在 SDK 提交边界做一次出站映射,不影响 opaque identity 契约。
93
+ * 运行时(UI 显示、加购合并、指纹、持久化)与提交边界统一消费字段名
94
+ * `option_group_item_id`,保持 tempOrder 与后端协议一致。
95
95
  */
96
96
  export interface ScanOrderSubmitProduct extends Omit<ScanOrderOrderProduct, '_origin' | 'identity_key'> {
97
97
  /**
@@ -14,13 +14,13 @@ export var ScanOrderHooks = /*#__PURE__*/function (ScanOrderHooks) {
14
14
  * 出站 payload 版本的商品行。
15
15
  *
16
16
  * 与 tempOrder 内部 `ScanOrderOrderProduct` 的字段差异:
17
- * - `product_option_item[*]`:内部为 `{ product_option_item_id, option_group_id, num, price, ... }`,
18
- * 出站由 `normalizeSubmitProduct` 重命名为 `{ option_group_item_id, option_group_id, num }`
17
+ * - `product_option_item[*]`:内部为 `{ option_group_item_id, option_group_id, num, price, ... }`,
18
+ * 出站保留 `{ option_group_item_id, option_group_id, num }`
19
19
  * (后端 checkout 协议;丢弃 `price` 等运行时辅助字段)。
20
20
  * - `product_bundle[*].option[*]`:同上重命名规则。
21
21
  *
22
- * 运行时(UI 显示、加购合并、指纹、持久化)全部消费内部字段名 `product_option_item_id`,
23
- * 仅在 SDK 提交边界做一次出站映射,不影响 opaque identity 契约。
22
+ * 运行时(UI 显示、加购合并、指纹、持久化)与提交边界统一消费字段名
23
+ * `option_group_item_id`,保持 tempOrder 与后端协议一致。
24
24
  */
25
25
 
26
26
  /**
@@ -381,14 +381,14 @@ export function buildProductLineFingerprint(productOptionItem, productBundle) {
381
381
  var normalizedOpts = optArr.map(function (item) {
382
382
  var _item$price;
383
383
  return {
384
- product_option_item_id: Number(item === null || item === void 0 ? void 0 : item.product_option_item_id) || 0,
384
+ option_group_item_id: Number(item === null || item === void 0 ? void 0 : item.option_group_item_id) || 0,
385
385
  option_group_id: Number(item === null || item === void 0 ? void 0 : item.option_group_id) || 0,
386
386
  num: typeof (item === null || item === void 0 ? void 0 : item.num) === 'number' && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
387
387
  price: String((_item$price = item === null || item === void 0 ? void 0 : item.price) !== null && _item$price !== void 0 ? _item$price : '')
388
388
  };
389
389
  }).sort(function (p, q) {
390
- if (p.product_option_item_id !== q.product_option_item_id) {
391
- return p.product_option_item_id - q.product_option_item_id;
390
+ if (p.option_group_item_id !== q.option_group_item_id) {
391
+ return p.option_group_item_id - q.option_group_item_id;
392
392
  }
393
393
  if (p.option_group_id !== q.option_group_id) return p.option_group_id - q.option_group_id;
394
394
  if (p.num !== q.num) return p.num - q.num;
@@ -30,6 +30,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
30
30
  type?: 'form' | 'customer';
31
31
  [key: string]: any;
32
32
  }): void;
33
+ setOrderId(id?: number): void;
33
34
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
34
35
  productList: Record<string, any>[];
35
36
  discountList: Discount[];
@@ -56,7 +57,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
56
57
  private bestDiscount;
57
58
  loadPrepareConfig(params: {
58
59
  customerId: number;
59
- action?: 'create' | 'update';
60
+ action?: 'create' | 'edit';
60
61
  with_good_pass?: 0 | 1;
61
62
  with_discount_card?: 0 | 1;
62
63
  }): Promise<void>;
@@ -57,7 +57,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
57
57
  currentBookingTime: "",
58
58
  filteredDiscountList: [],
59
59
  bookingSubject: undefined,
60
- orderTotalAmount: 0
60
+ orderTotalAmount: 0,
61
+ orderId: undefined
61
62
  };
62
63
  return _this;
63
64
  }
@@ -307,6 +308,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
307
308
  value: function setBookingSubject(bookingSubject) {
308
309
  this.store.bookingSubject = bookingSubject;
309
310
  }
311
+ }, {
312
+ key: "setOrderId",
313
+ value: function setOrderId(id) {
314
+ this.store.orderId = id;
315
+ }
310
316
 
311
317
  // 计算优惠券
312
318
  }, {
@@ -406,7 +412,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
406
412
  case 0:
407
413
  _context5.prev = 0;
408
414
  _context5.next = 3;
409
- return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, customerId);
415
+ return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.batchSearch(code, {
416
+ customerId: customerId,
417
+ orderId: this.store.orderId
418
+ });
410
419
  case 3:
411
420
  _context5.t0 = _context5.sent;
412
421
  if (_context5.t0) {
@@ -742,24 +751,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
742
751
  key: "loadPrepareConfig",
743
752
  value: function () {
744
753
  var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
745
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
754
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi2, orderId, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
746
755
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
747
756
  while (1) switch (_context9.prev = _context9.next) {
748
757
  case 0:
749
758
  _context9.prev = 0;
759
+ orderId = this.store.orderId;
750
760
  customerId = params.customerId || ((_this$getCustomer2 = this.getCustomer()) === null || _this$getCustomer2 === void 0 ? void 0 : _this$getCustomer2.id); // if (customerId === 1 || !customerId) {
751
761
  // return
752
762
  // }
753
- _context9.next = 4;
754
- return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
763
+ _context9.next = 5;
764
+ return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig(_objectSpread({
755
765
  customer_id: customerId,
756
- action: 'create',
766
+ action: orderId ? 'edit' : 'create',
757
767
  with_good_pass: 1,
758
768
  with_discount_card: 1,
759
769
  with_wallet_pass_holder: 1,
760
770
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
761
- });
762
- case 4:
771
+ }, orderId ? {
772
+ order_id: orderId
773
+ } : {}));
774
+ case 5:
763
775
  goodPassList = _context9.sent;
764
776
  scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
765
777
  return item.isScan;
@@ -772,35 +784,35 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
772
784
  });
773
785
  newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
774
786
  this.store.originalDiscountList = newDiscountList;
775
- _context9.next = 12;
787
+ _context9.next = 13;
776
788
  return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.setOriginalDiscountList(newDiscountList);
777
- case 12:
789
+ case 13:
778
790
  // 根据当前预约时间过滤优惠券列表
779
791
  filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
780
792
  this.store.filteredDiscountList = filteredDiscountList;
781
793
  this.setDiscountList(filteredDiscountList || []);
782
794
  if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
783
- _context9.next = 19;
795
+ _context9.next = 20;
784
796
  break;
785
797
  }
786
798
  _result3 = this.calcDiscount(this.store.productList);
787
- _context9.next = 19;
799
+ _context9.next = 20;
788
800
  return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
789
- case 19:
790
- _context9.next = 21;
801
+ case 20:
802
+ _context9.next = 22;
791
803
  return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), filteredDiscountList);
792
- case 21:
793
- _context9.next = 26;
804
+ case 22:
805
+ _context9.next = 27;
794
806
  break;
795
- case 23:
796
- _context9.prev = 23;
807
+ case 24:
808
+ _context9.prev = 24;
797
809
  _context9.t0 = _context9["catch"](0);
798
810
  console.error('[ShopDiscount] 加载准备配置出错:', _context9.t0);
799
- case 26:
811
+ case 27:
800
812
  case "end":
801
813
  return _context9.stop();
802
814
  }
803
- }, _callee9, this, [[0, 23]]);
815
+ }, _callee9, this, [[0, 24]]);
804
816
  }));
805
817
  function loadPrepareConfig(_x9) {
806
818
  return _loadPrepareConfig.apply(this, arguments);
@@ -36,6 +36,7 @@ export interface ShopDiscountState {
36
36
  type?: 'form' | 'customer';
37
37
  [key: string]: any;
38
38
  };
39
+ orderId?: number;
39
40
  }
40
41
  export interface SetDiscountSelectedParams {
41
42
  discountId: number;
package/lib/core/index.js CHANGED
@@ -50,6 +50,7 @@ var PisellOSCore = class {
50
50
  this.serverOptions = options.server;
51
51
  }
52
52
  this.initialize(options);
53
+ console.log("constructor1234");
53
54
  }
54
55
  initialize(options) {
55
56
  if (options == null ? void 0 : options.plugins) {
@@ -289,7 +289,7 @@ var formatOptionsToOrigin = (options) => {
289
289
  return options.map((d) => {
290
290
  return {
291
291
  num: d.num,
292
- option_group_item_id: d.product_option_item_id,
292
+ option_group_item_id: d.option_group_item_id,
293
293
  option_group_id: d.option_group_id
294
294
  };
295
295
  });
@@ -17,14 +17,18 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
17
17
  setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
18
18
  getOriginalDiscountList(): Discount[];
19
19
  loadPrepareConfig(params: {
20
- action?: 'create';
20
+ action?: 'create' | 'edit';
21
21
  with_good_pass: 0 | 1;
22
22
  with_discount_card: 0 | 1;
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
25
  request_timezone: string;
26
+ order_id?: number;
27
+ }): Promise<Discount[]>;
28
+ batchSearch(code: string, options?: {
29
+ customerId?: number;
30
+ orderId?: number;
26
31
  }): Promise<Discount[]>;
27
- batchSearch(code: string, customerId?: number): Promise<Discount[]>;
28
32
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
29
33
  private checkUsageCreditsLimit;
30
34
  uniqueByProductId(discountList: Discount[]): Discount[];
@@ -102,7 +102,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
102
102
  ) || [];
103
103
  return goodPassList;
104
104
  }
105
- async batchSearch(code, customerId) {
105
+ async batchSearch(code, options) {
106
+ const { customerId, orderId } = options || {};
106
107
  const result = await this.request.get(`/machinecode/batch-search`, {
107
108
  code,
108
109
  translate_flag: 1,
@@ -112,6 +113,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
112
113
  with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
113
114
  order_behavior_count: 1,
114
115
  order_behavior_count_customer_id: customerId || 1,
116
+ ...orderId ? { order_behavior_count_order_id: orderId } : {},
115
117
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
116
118
  });
117
119
  const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
@@ -18,6 +18,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
18
18
  private cacheId;
19
19
  private salesSummaryModuleName;
20
20
  private rulesHooksOverride?;
21
+ private orderHooks?;
21
22
  private otherParams?;
22
23
  /**
23
24
  * Populate `savedAmount` on each discount based on product-level discount details.
@@ -143,6 +144,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
143
144
  * 视为 wallet pass;其它支付项保持不变。
144
145
  */
145
146
  updateVoucherOrderPayments(payments: OrderPaymentSource[]): OrderPaymentData[];
147
+ private shouldMergeProductToOrder;
146
148
  addProductToOrder(product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput): Promise<OrderProduct[]>;
147
149
  private hasGoodPassDiscount;
148
150
  updateProductInOrder(params: UpdateProductInOrderParams): Promise<OrderProduct[]>;