@pisell/pisellos 2.3.218 → 2.3.219

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.
@@ -37,6 +37,7 @@ import { getDefaultInvoiceLayoutConfig, getDefaultInvoiceTemplateSettings } from
37
37
  import { getProductExtend as getProductExtendUtil, getResourceByIds as getResourceByIdsUtil, getResourceErrors as getResourceErrorsUtil, derivePresetStartTimeFromDate } from "../../modules/BookingContext";
38
38
  import { BaseSalesImpl } from "../BaseSales";
39
39
  import Scan from "./utils/scan";
40
+ import { applyRedeemArrival, buildArrivalCheckoutQuery, createArrivalLogger, describeChangedBookings, readArrivalWindow } from "./utils/redeemArrival";
40
41
  import { formatOrderCustomerPatch } from "./utils/orderCustomer";
41
42
  import { handleGlobalScan, handleCustomerScan, handleUniversalScan } from "./utils/scan/handleScan";
42
43
  import scanCache from "./utils/scan/scanCache";
@@ -192,6 +193,8 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
192
193
  _defineProperty(_assertThisInitialized(_this), "loadOpenDataInFlight", null);
193
194
  _defineProperty(_assertThisInitialized(_this), "loadOpenDataInFlightTarget", null);
194
195
  _defineProperty(_assertThisInitialized(_this), "openDataTarget", null);
196
+ _defineProperty(_assertThisInitialized(_this), "redeemStatusWrite", void 0);
197
+ _defineProperty(_assertThisInitialized(_this), "arrivalQueue", Promise.resolve());
195
198
  return _this;
196
199
  }
197
200
  _createClass(BookingTicketImpl, [{
@@ -3571,10 +3574,13 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3571
3574
  device_id: deviceId,
3572
3575
  payload: {
3573
3576
  type: 'WRISTBAND',
3574
- data: {
3575
- order_id: (_this$getOrderIdentit2 = this.getOrderIdentity()) === null || _this$getOrderIdentit2 === void 0 ? void 0 : _this$getOrderIdentit2.orderId,
3577
+ data: _objectSpread(_objectSpread({
3578
+ order_id: (_this$getOrderIdentit2 = this.getOrderIdentity()) === null || _this$getOrderIdentit2 === void 0 ? void 0 : _this$getOrderIdentit2.orderId
3579
+ }, params.voucher_times && {
3580
+ voucher_times: params.voucher_times
3581
+ }), {}, {
3576
3582
  voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids]
3577
- }
3583
+ })
3578
3584
  },
3579
3585
  idempotency_key: idempotencyKey,
3580
3586
  name: 'PRINT_WRISTBAND',
@@ -3592,13 +3598,26 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3592
3598
  return _handlePrintWristband.apply(this, arguments);
3593
3599
  }
3594
3600
  return handlePrintWristband;
3595
- }() // 触发核销
3601
+ }()
3602
+ }, {
3603
+ key: "getRedeemArrivalWindow",
3604
+ value: function getRedeemArrivalWindow() {
3605
+ var _this$store$openData$, _this$store$openData2, _this$store$openData3;
3606
+ return readArrivalWindow((_this$store$openData$ = (_this$store$openData2 = this.store.openData) === null || _this$store$openData2 === void 0 || (_this$store$openData3 = _this$store$openData2.getOpenData) === null || _this$store$openData3 === void 0 ? void 0 : _this$store$openData3.call(_this$store$openData2)) !== null && _this$store$openData$ !== void 0 ? _this$store$openData$ : this.getInjectedOpenDataConfig());
3607
+ }
3608
+ }, {
3609
+ key: "isRedeemArrivalEnabled",
3610
+ value: function isRedeemArrivalEnabled() {
3611
+ return Boolean(this.getRedeemArrivalWindow());
3612
+ }
3613
+
3614
+ // 触发核销
3596
3615
  }, {
3597
3616
  key: "handleRedeem",
3598
3617
  value: function () {
3599
3618
  var _handleRedeem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee46(params) {
3600
3619
  var _this$store$order8, _this$store$order8$ge, _this$store$order9, _ref22, _tempOrder$order_id2;
3601
- var voucherIds, status, voucherIdSet, tempOrder, vouchers, hasUpdatedVoucher, nextVouchers, identity, externalSaleNumber, orderId, orderLookup;
3620
+ var voucherIds, status, voucherIdSet, tempOrder, vouchers, hasUpdatedVoucher, nextVouchers, write, identity, externalSaleNumber, orderId, orderLookup;
3602
3621
  return _regeneratorRuntime().wrap(function _callee46$(_context46) {
3603
3622
  while (1) switch (_context46.prev = _context46.next) {
3604
3623
  case 0:
@@ -3624,19 +3643,26 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3624
3643
  });
3625
3644
  });
3626
3645
  if (!(tempOrder && hasUpdatedVoucher)) {
3627
- _context46.next = 11;
3646
+ _context46.next = 17;
3628
3647
  break;
3629
3648
  }
3630
- _context46.next = 11;
3631
- return this.replaceTempOrder(_objectSpread(_objectSpread({}, tempOrder), {}, {
3649
+ write = this.replaceTempOrder(_objectSpread(_objectSpread({}, tempOrder), {}, {
3632
3650
  vouchers: nextVouchers
3633
3651
  }), {
3634
3652
  preserveOrderSessionId: this.getOrderSessionId() || undefined
3635
3653
  });
3636
- case 11:
3654
+ this.redeemStatusWrite = write;
3655
+ _context46.prev = 11;
3656
+ _context46.next = 14;
3657
+ return write;
3658
+ case 14:
3659
+ _context46.prev = 14;
3660
+ if (this.redeemStatusWrite === write) this.redeemStatusWrite = undefined;
3661
+ return _context46.finish(14);
3662
+ case 17:
3637
3663
  this.core.effects.emit("".concat(this.name, ":onVouchersChange"), {});
3638
3664
  if (!(voucherIds.length === 0)) {
3639
- _context46.next = 14;
3665
+ _context46.next = 20;
3640
3666
  break;
3641
3667
  }
3642
3668
  return _context46.abrupt("return", {
@@ -3645,7 +3671,7 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3645
3671
  message: '',
3646
3672
  data: []
3647
3673
  });
3648
- case 14:
3674
+ case 20:
3649
3675
  identity = this.getOrderIdentity();
3650
3676
  externalSaleNumber = (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.external_sale_number) || (identity === null || identity === void 0 ? void 0 : identity.externalSaleNumber) || undefined;
3651
3677
  orderId = (_ref22 = (_tempOrder$order_id2 = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_id) !== null && _tempOrder$order_id2 !== void 0 ? _tempOrder$order_id2 : identity === null || identity === void 0 ? void 0 : identity.orderId) !== null && _ref22 !== void 0 ? _ref22 : undefined;
@@ -3659,17 +3685,213 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3659
3685
  }, {
3660
3686
  osServer: true
3661
3687
  }));
3662
- case 19:
3688
+ case 25:
3663
3689
  case "end":
3664
3690
  return _context46.stop();
3665
3691
  }
3666
- }, _callee46, this);
3692
+ }, _callee46, this, [[11,, 14, 17]]);
3667
3693
  }));
3668
3694
  function handleRedeem(_x30) {
3669
3695
  return _handleRedeem.apply(this, arguments);
3670
3696
  }
3671
3697
  return handleRedeem;
3672
3698
  }()
3699
+ }, {
3700
+ key: "updateTicketArrival",
3701
+ value: function () {
3702
+ var _updateTicketArrival = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee48(voucherIds) {
3703
+ var _this$store$order10,
3704
+ _this$store$order10$g,
3705
+ _this14 = this;
3706
+ var window, tempOrder, log, operation, arrivalTime, session, updateArrival, completion;
3707
+ return _regeneratorRuntime().wrap(function _callee48$(_context48) {
3708
+ while (1) switch (_context48.prev = _context48.next) {
3709
+ case 0:
3710
+ window = this.getRedeemArrivalWindow();
3711
+ tempOrder = (_this$store$order10 = this.store.order) === null || _this$store$order10 === void 0 || (_this$store$order10$g = _this$store$order10.getTempOrder) === null || _this$store$order10$g === void 0 ? void 0 : _this$store$order10$g.call(_this$store$order10);
3712
+ log = createArrivalLogger(this.logger, tempOrder, voucherIds);
3713
+ if (!(!window || !tempOrder)) {
3714
+ _context48.next = 6;
3715
+ break;
3716
+ }
3717
+ log('skipped', {
3718
+ reason: !window ? 'no_effective_window' : 'missing_order'
3719
+ });
3720
+ return _context48.abrupt("return");
3721
+ case 6:
3722
+ log('started', {
3723
+ early_minutes: window.earlyMinutes,
3724
+ late_minutes: window.lateMinutes
3725
+ });
3726
+ operation = 'prepare';
3727
+ arrivalTime = new Date();
3728
+ session = this.getOrderSessionId();
3729
+ updateArrival = /*#__PURE__*/function () {
3730
+ var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
3731
+ var _this14$store$order, _this14$store$order$g, _next$summary;
3732
+ var current, sameOrder, order, arrival, next, query, checkout, latest, patch, voucherTimes;
3733
+ return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3734
+ while (1) switch (_context47.prev = _context47.next) {
3735
+ case 0:
3736
+ if (!_this14.redeemStatusWrite) {
3737
+ _context47.next = 3;
3738
+ break;
3739
+ }
3740
+ _context47.next = 3;
3741
+ return _this14.redeemStatusWrite.catch(function () {});
3742
+ case 3:
3743
+ current = (_this14$store$order = _this14.store.order) === null || _this14$store$order === void 0 || (_this14$store$order$g = _this14$store$order.getTempOrder) === null || _this14$store$order$g === void 0 ? void 0 : _this14$store$order$g.call(_this14$store$order);
3744
+ sameOrder = function sameOrder() {
3745
+ var _this14$store$order2, _this14$store$order2$;
3746
+ var active = (_this14$store$order2 = _this14.store.order) === null || _this14$store$order2 === void 0 || (_this14$store$order2$ = _this14$store$order2.getTempOrder) === null || _this14$store$order2$ === void 0 ? void 0 : _this14$store$order2$.call(_this14$store$order2);
3747
+ return active && (session == null || _this14.getOrderSessionId() === session) && active.order_id === tempOrder.order_id && active.external_sale_number === tempOrder.external_sale_number;
3748
+ };
3749
+ order = current && sameOrder() ? current : tempOrder;
3750
+ arrival = applyRedeemArrival(order, new Set(voucherIds.map(String)), arrivalTime, window, function (reason) {
3751
+ return log('skipped', {
3752
+ reason: reason
3753
+ });
3754
+ });
3755
+ if (arrival) {
3756
+ _context47.next = 9;
3757
+ break;
3758
+ }
3759
+ return _context47.abrupt("return");
3760
+ case 9:
3761
+ next = _objectSpread(_objectSpread({}, order), arrival);
3762
+ _context47.t0 = buildArrivalCheckoutQuery;
3763
+ _context47.t1 = next;
3764
+ if (!((_next$summary = next.summary) !== null && _next$summary !== void 0)) {
3765
+ _context47.next = 16;
3766
+ break;
3767
+ }
3768
+ _context47.t2 = _next$summary;
3769
+ _context47.next = 24;
3770
+ break;
3771
+ case 16:
3772
+ if (!sameOrder()) {
3773
+ _context47.next = 22;
3774
+ break;
3775
+ }
3776
+ _context47.next = 19;
3777
+ return _this14.getSummary();
3778
+ case 19:
3779
+ _context47.t3 = _context47.sent;
3780
+ _context47.next = 23;
3781
+ break;
3782
+ case 22:
3783
+ _context47.t3 = undefined;
3784
+ case 23:
3785
+ _context47.t2 = _context47.t3;
3786
+ case 24:
3787
+ _context47.t4 = _context47.t2;
3788
+ query = (0, _context47.t0)(_context47.t1, _context47.t4);
3789
+ operation = 'checkout';
3790
+ log('checkout_requested', {
3791
+ bookings: describeChangedBookings(order.bookings, arrival.bookings)
3792
+ });
3793
+ _context47.next = 30;
3794
+ return _this14.store.order.submitSalesOrder({
3795
+ query: query
3796
+ });
3797
+ case 30:
3798
+ checkout = _context47.sent;
3799
+ if (!((checkout === null || checkout === void 0 ? void 0 : checkout.status) === false || (checkout === null || checkout === void 0 ? void 0 : checkout.code) != null && checkout.code !== 200)) {
3800
+ _context47.next = 34;
3801
+ break;
3802
+ }
3803
+ log('checkout_rejected', {
3804
+ code: checkout.code,
3805
+ status: checkout.status,
3806
+ message: checkout.message
3807
+ }, true);
3808
+ return _context47.abrupt("return", checkout);
3809
+ case 34:
3810
+ log('checkout_accepted', {
3811
+ code: checkout === null || checkout === void 0 ? void 0 : checkout.code
3812
+ });
3813
+ operation = 'local_update';
3814
+ if (!_this14.redeemStatusWrite) {
3815
+ _context47.next = 39;
3816
+ break;
3817
+ }
3818
+ _context47.next = 39;
3819
+ return _this14.redeemStatusWrite.catch(function () {});
3820
+ case 39:
3821
+ if (!sameOrder()) {
3822
+ _context47.next = 52;
3823
+ break;
3824
+ }
3825
+ latest = _this14.store.order.getTempOrder();
3826
+ patch = applyRedeemArrival(latest, new Set(voucherIds.map(String)), arrivalTime, window);
3827
+ if (!patch) {
3828
+ _context47.next = 49;
3829
+ break;
3830
+ }
3831
+ _context47.next = 45;
3832
+ return _this14.replaceTempOrder(_objectSpread(_objectSpread({}, latest), patch), {
3833
+ preserveOrderSessionId: _this14.getOrderSessionId() || undefined
3834
+ });
3835
+ case 45:
3836
+ log('local_updated');
3837
+ _this14.core.effects.emit("".concat(_this14.name, ":onVouchersChange"), {});
3838
+ _context47.next = 50;
3839
+ break;
3840
+ case 49:
3841
+ log('local_skipped', {
3842
+ reason: 'no_pending_change'
3843
+ });
3844
+ case 50:
3845
+ _context47.next = 53;
3846
+ break;
3847
+ case 52:
3848
+ log('local_skipped', {
3849
+ reason: 'order_changed'
3850
+ });
3851
+ case 53:
3852
+ // 从本次 checkout 已接受的快照取票面时间,避免打印接口短暂返回旧值。
3853
+ voucherTimes = {};
3854
+ arrival.vouchers.forEach(function (voucher, index) {
3855
+ if (voucher !== order.vouchers[index] && voucher.voucher_id != null && voucher.start_time && voucher.end_time) {
3856
+ voucherTimes[String(voucher.voucher_id)] = {
3857
+ start_time: voucher.start_time,
3858
+ end_time: voucher.end_time
3859
+ };
3860
+ }
3861
+ });
3862
+ return _context47.abrupt("return", Object.keys(voucherTimes).length ? _objectSpread(_objectSpread({}, checkout), {}, {
3863
+ voucher_times: voucherTimes
3864
+ }) : checkout);
3865
+ case 56:
3866
+ case "end":
3867
+ return _context47.stop();
3868
+ }
3869
+ }, _callee47);
3870
+ }));
3871
+ return function updateArrival() {
3872
+ return _ref23.apply(this, arguments);
3873
+ };
3874
+ }();
3875
+ completion = this.arrivalQueue.then(updateArrival).catch(function (error) {
3876
+ log('failed', {
3877
+ operation: operation,
3878
+ message: error instanceof Error ? error.message : String(error)
3879
+ }, true);
3880
+ throw error;
3881
+ });
3882
+ this.arrivalQueue = completion.then(function () {}, function () {});
3883
+ return _context48.abrupt("return", completion);
3884
+ case 14:
3885
+ case "end":
3886
+ return _context48.stop();
3887
+ }
3888
+ }, _callee48, this);
3889
+ }));
3890
+ function updateTicketArrival(_x31) {
3891
+ return _updateTicketArrival.apply(this, arguments);
3892
+ }
3893
+ return updateTicketArrival;
3894
+ }()
3673
3895
  /**
3674
3896
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
3675
3897
  * 再清理 BookingTicket 自有资源(scan 监听 + scan 内存缓存)。
@@ -3677,13 +3899,13 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3677
3899
  }, {
3678
3900
  key: "destroy",
3679
3901
  value: (function () {
3680
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee47() {
3902
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee49() {
3681
3903
  var _this$scan;
3682
- return _regeneratorRuntime().wrap(function _callee47$(_context47) {
3683
- while (1) switch (_context47.prev = _context47.next) {
3904
+ return _regeneratorRuntime().wrap(function _callee49$(_context49) {
3905
+ while (1) switch (_context49.prev = _context49.next) {
3684
3906
  case 0:
3685
3907
  this.orderCustomerContactRequest = null;
3686
- _context47.next = 3;
3908
+ _context49.next = 3;
3687
3909
  return _get(_getPrototypeOf(BookingTicketImpl.prototype), "destroy", this).call(this);
3688
3910
  case 3:
3689
3911
  try {
@@ -3694,9 +3916,9 @@ export var BookingTicketImpl = /*#__PURE__*/function (_BaseSalesImpl) {
3694
3916
  scanCache.clear();
3695
3917
  case 5:
3696
3918
  case "end":
3697
- return _context47.stop();
3919
+ return _context49.stop();
3698
3920
  }
3699
- }, _callee47, this);
3921
+ }, _callee49, this);
3700
3922
  }));
3701
3923
  function destroy() {
3702
3924
  return _destroy.apply(this, arguments);
@@ -0,0 +1,78 @@
1
+ import type LoggerManager from '../../../plugins/app-types/logger';
2
+ import type { OrderTempOrder } from '../../../modules/Order/types';
3
+ export interface ArrivalWindow {
4
+ earlyMinutes: number;
5
+ lateMinutes: number;
6
+ }
7
+ export declare function readArrivalWindow(config?: Record<string, any> | null): ArrivalWindow | undefined;
8
+ type TicketOrder = Pick<OrderTempOrder, 'vouchers' | 'bookings'>;
9
+ export declare function applyRedeemArrival(order: TicketOrder, ids: Set<string>, now: Date, window?: ArrivalWindow, onSkip?: (reason: string) => void): {
10
+ vouchers: any[];
11
+ bookings: any[];
12
+ } | undefined;
13
+ export declare function createArrivalLogger(logger: Pick<LoggerManager, 'addLog'> | undefined, order: OrderTempOrder | null | undefined, voucherIds: Array<string | number>): (stage: string, details?: Record<string, unknown>, failed?: boolean) => void;
14
+ export declare function buildArrivalCheckoutQuery(order: OrderTempOrder, summary: OrderTempOrder['summary']): {
15
+ _os_pos_receipt_auto_print_payment_statuses: never[];
16
+ platform: string;
17
+ payment_status?: string | undefined;
18
+ created_at?: string | undefined;
19
+ request_unique_idempotency_token?: string | undefined;
20
+ form_record_ids?: {
21
+ form_id: string | number;
22
+ form_record_id: string | number;
23
+ }[] | undefined;
24
+ products: import("../../../modules/Order/types").OrderSubmitProduct[];
25
+ notes?: import("../../../modules/Order/types").SalesNote[] | undefined;
26
+ summary?: import("../../../modules/Order/types").OrderSummary | undefined;
27
+ small_ticket_data_flag?: number | undefined;
28
+ holder_relations?: import("../../../modules/Order/types").OrderHolderRelation[] | undefined;
29
+ metadata: Record<string, any>;
30
+ note: string;
31
+ order_id: number | null;
32
+ external_sale_number: string;
33
+ order_number: string | null;
34
+ shop_order_number: string | null;
35
+ shop_full_order_number: string | null;
36
+ type: string;
37
+ business_code?: string | undefined;
38
+ sales_channel: string;
39
+ order_sales_channel: string;
40
+ status: string;
41
+ shipping_status: string;
42
+ customer_id: number | null;
43
+ customer_name: string;
44
+ country_calling_code: string;
45
+ phone: string;
46
+ email: string;
47
+ is_price_include_tax: number;
48
+ tax_title: string;
49
+ tax_country_code: string;
50
+ currency_code: string;
51
+ currency_symbol: string;
52
+ currency_format: string;
53
+ is_deposit: number;
54
+ deposit_amount: string;
55
+ shop_discount: string;
56
+ surcharge_fee: string;
57
+ buzzer?: string | undefined;
58
+ delivery_type?: string | undefined;
59
+ table_number?: Record<string, any> | undefined;
60
+ schedule_date: string;
61
+ bookings: any[];
62
+ payments: any[];
63
+ refunds?: any[] | undefined;
64
+ surcharges: any[];
65
+ relation_forms: any[];
66
+ contacts: any[];
67
+ contacts_info: Record<string, any> | null;
68
+ holder: Record<string, any> | null;
69
+ order_meta_list?: import("../../../modules/Order/types").OrderMetaList | undefined;
70
+ };
71
+ export declare function describeChangedBookings(before: OrderTempOrder['bookings'], after: OrderTempOrder['bookings']): {
72
+ schedule_event_id: any;
73
+ previous_start: any;
74
+ previous_end: any;
75
+ start: any;
76
+ end: any;
77
+ }[];
78
+ export {};
@@ -0,0 +1,175 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["vouchers"];
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
8
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ 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); }
14
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
17
+ import dayjs from 'dayjs';
18
+ import { OS_POS_RECEIPT_AUTO_PRINT_PAYMENT_STATUSES_FIELD } from "../../../utils/pos-receipt-auto-print";
19
+ import { buildSubmitPayload, redeemEventKey } from "../../../modules/Order/utils";
20
+ export function readArrivalWindow(config) {
21
+ var enabled = config === null || config === void 0 ? void 0 : config['fulfillment.enable_adjust_session_on_arrival'];
22
+ if (enabled !== true && enabled !== 1 && enabled !== '1') return;
23
+ var minutes = function minutes(value) {
24
+ var number = Number(value);
25
+ return Number.isFinite(number) ? Math.max(0, Math.floor(number)) : 0;
26
+ };
27
+ var earlyMinutes = minutes(config === null || config === void 0 ? void 0 : config['fulfillment.max_earlier_shift_minutes']);
28
+ var lateMinutes = minutes(config === null || config === void 0 ? void 0 : config['fulfillment.max_later_shift_minutes']);
29
+ // 两个方向都没有可调整的分钟数时,核销和打印沿用关闭开关时的流程。
30
+ if (earlyMinutes === 0 && lateMinutes === 0) return;
31
+ return {
32
+ earlyMinutes: earlyMinutes,
33
+ lateMinutes: lateMinutes
34
+ };
35
+ }
36
+ function shiftedSession(booking, now, window) {
37
+ if (!window || !booking.start_date || !booking.start_time || !booking.end_time) return null;
38
+ var start = dayjs("".concat(booking.start_date, " ").concat(booking.start_time));
39
+ var end = dayjs("".concat(booking.end_date || booking.start_date, " ").concat(booking.end_time));
40
+ if (!start.isValid() || !end.isValid() || end.isBefore(start)) return null;
41
+ var delta = dayjs(now).startOf('minute').diff(start, 'minute');
42
+ var minutes = Math.max(-window.earlyMinutes, Math.min(window.lateMinutes, delta));
43
+ if (!Number.isFinite(minutes)) return null;
44
+ if (!minutes) return;
45
+ var shiftedStart = start.add(minutes, 'minute');
46
+ var shiftedEnd = end.add(minutes, 'minute');
47
+ return {
48
+ start_date: shiftedStart.format('YYYY-MM-DD'),
49
+ start_time: shiftedStart.format(booking.start_time.length > 5 ? 'HH:mm:ss' : 'HH:mm'),
50
+ end_date: shiftedEnd.format('YYYY-MM-DD'),
51
+ end_time: shiftedEnd.format(booking.end_time.length > 5 ? 'HH:mm:ss' : 'HH:mm')
52
+ };
53
+ }
54
+ export function applyRedeemArrival(order, ids, now, window, onSkip) {
55
+ var _order$bookings, _order$vouchers;
56
+ if (!window || !((_order$bookings = order.bookings) !== null && _order$bookings !== void 0 && _order$bookings.length) || !((_order$vouchers = order.vouchers) !== null && _order$vouchers !== void 0 && _order$vouchers.length)) {
57
+ onSkip === null || onSkip === void 0 || onSkip('missing_window_or_booking_data');
58
+ return;
59
+ }
60
+ var selected = new Set();
61
+ var _iterator = _createForOfIteratorHelper(order.vouchers),
62
+ _step;
63
+ try {
64
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
65
+ var voucher = _step.value;
66
+ var event = redeemEventKey(voucher === null || voucher === void 0 ? void 0 : voucher.schedule_event_id);
67
+ if (event && ids.has(String(voucher.voucher_id))) selected.add(event);
68
+ }
69
+ } catch (err) {
70
+ _iterator.e(err);
71
+ } finally {
72
+ _iterator.f();
73
+ }
74
+ var alreadyMarked = false;
75
+ var invalidSession = false;
76
+ var changes = new Map();
77
+ var bookings = order.bookings.map(function (booking) {
78
+ var _booking$metadata;
79
+ var event = redeemEventKey(booking === null || booking === void 0 ? void 0 : booking.schedule_event_id);
80
+ if (!event || !selected.has(event) || String(booking.parent_id) === '0') return booking;
81
+ if (Number((_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.is_change_by_redeem) === 1) {
82
+ alreadyMarked = true;
83
+ return booking;
84
+ }
85
+ var shift = shiftedSession(booking, now, window);
86
+ if (shift === null) {
87
+ invalidSession = true;
88
+ return booking;
89
+ }
90
+ // 准点核销的偏移量为零,也要打标,避免下一张票改变这个时段。
91
+ changes.set(event, shift);
92
+ return _objectSpread(_objectSpread(_objectSpread({}, booking), shift), {}, {
93
+ metadata: _objectSpread(_objectSpread({}, booking.metadata), {}, {
94
+ is_change_by_redeem: 1
95
+ })
96
+ });
97
+ });
98
+ if (!changes.size) {
99
+ onSkip === null || onSkip === void 0 || onSkip(invalidSession ? 'invalid_booking_time' : alreadyMarked ? 'already_marked' : 'no_linked_booking');
100
+ return;
101
+ }
102
+ var vouchers = order.vouchers.map(function (voucher) {
103
+ var event = redeemEventKey(voucher === null || voucher === void 0 ? void 0 : voucher.schedule_event_id);
104
+ var shift = event && changes.get(event);
105
+ if (!shift) return voucher;
106
+ return _objectSpread(_objectSpread({}, voucher), {}, {
107
+ start_date: shift.start_date,
108
+ expire_date: shift.end_date,
109
+ start_time: shift.start_time,
110
+ end_time: shift.end_time
111
+ });
112
+ });
113
+ return {
114
+ vouchers: vouchers,
115
+ bookings: bookings
116
+ };
117
+ }
118
+ export function createArrivalLogger(logger, order, voucherIds) {
119
+ return function (stage) {
120
+ var details = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
121
+ var failed = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
122
+ try {
123
+ logger === null || logger === void 0 || logger.addLog({
124
+ type: failed ? 'error' : 'info',
125
+ title: '[BookingTicket] updateTicketArrival',
126
+ metadata: _objectSpread({
127
+ stage: stage,
128
+ order_id: order === null || order === void 0 ? void 0 : order.order_id,
129
+ external_sale_number: order === null || order === void 0 ? void 0 : order.external_sale_number,
130
+ voucher_ids: voucherIds
131
+ }, details)
132
+ });
133
+ } catch (_unused) {
134
+ // 日志不可用时,核销和预约调时仍按原流程执行。
135
+ }
136
+ };
137
+ }
138
+ export function buildArrivalCheckoutQuery(order, summary) {
139
+ var _buildSubmitPayload = buildSubmitPayload({
140
+ tempOrder: order,
141
+ platform: order.platform,
142
+ businessCode: order.business_code,
143
+ type: order.type,
144
+ summary: summary
145
+ }),
146
+ _localVouchers = _buildSubmitPayload.vouchers,
147
+ payload = _objectWithoutProperties(_buildSubmitPayload, _excluded);
148
+ return _objectSpread(_objectSpread({}, payload), {}, _defineProperty({}, OS_POS_RECEIPT_AUTO_PRINT_PAYMENT_STATUSES_FIELD, []));
149
+ }
150
+ export function describeChangedBookings(before, after) {
151
+ var changes = [];
152
+ var _iterator2 = _createForOfIteratorHelper(after.entries()),
153
+ _step2;
154
+ try {
155
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
156
+ var _step2$value = _slicedToArray(_step2.value, 2),
157
+ index = _step2$value[0],
158
+ booking = _step2$value[1];
159
+ var previous = before[index];
160
+ if (booking === previous) continue;
161
+ changes.push({
162
+ schedule_event_id: booking.schedule_event_id,
163
+ previous_start: previous.start_time,
164
+ previous_end: previous.end_time,
165
+ start: booking.start_time,
166
+ end: booking.end_time
167
+ });
168
+ }
169
+ } catch (err) {
170
+ _iterator2.e(err);
171
+ } finally {
172
+ _iterator2.f();
173
+ }
174
+ return changes;
175
+ }
@@ -106,6 +106,9 @@ export interface OpenDataConfig {
106
106
  'sale.short_number_prefix'?: string | null;
107
107
  'sale.sale_number_prefix'?: string | null;
108
108
  'sale.enabled_item_rules'?: number[];
109
+ 'fulfillment.enable_adjust_session_on_arrival'?: boolean | 0 | 1;
110
+ 'fulfillment.max_earlier_shift_minutes'?: number | string;
111
+ 'fulfillment.max_later_shift_minutes'?: number | string;
109
112
  'fulfillment.enable_pickup'?: boolean;
110
113
  'fulfillment.handover_mode'?: string[];
111
114
  'fulfillment.takeaway_fees_rules'?: number[];
@@ -642,7 +642,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
642
642
  generateIdempotencyToken(): string;
643
643
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
644
644
  createOrder(params: CommitOrderParams['query']): {
645
- type: "appointment_booking" | "virtual";
645
+ type: "virtual" | "appointment_booking";
646
646
  platform: string;
647
647
  sales_channel: string;
648
648
  order_sales_channel: string;
@@ -5001,6 +5001,9 @@ class OrderModule extends _BaseModule.BaseModule {
5001
5001
  metadata: {
5002
5002
  ...(targetBooking.metadata || {}),
5003
5003
  ...(updates.metadata || {}),
5004
+ ...(Number(targetBooking.metadata?.is_change_by_redeem) === 1 ? {
5005
+ is_change_by_redeem: 1
5006
+ } : {}),
5004
5007
  unique_identification_number: bookingUid
5005
5008
  }
5006
5009
  };
@@ -6217,7 +6220,7 @@ class OrderModule extends _BaseModule.BaseModule {
6217
6220
  if (options?.ensureIdentity !== false) {
6218
6221
  this.ensureExternalSaleNumber(nextTempOrder);
6219
6222
  }
6220
- nextTempOrder.vouchers = raw.vouchers || [];
6223
+ nextTempOrder.vouchers = (0, _utils.restoreRedeemVoucherTimes)(nextTempOrder, raw.vouchers || []);
6221
6224
  return nextTempOrder;
6222
6225
  }
6223
6226
  isSyntheticDraftOrderIdForRuntime(record, options) {
@@ -668,7 +668,7 @@ export interface SubmitSalesOrderParams {
668
668
  holder_relations?: OrderHolderRelation[];
669
669
  bookings: OrderSubmitBooking[];
670
670
  payments: any[];
671
- vouchers: any[];
671
+ vouchers?: any[];
672
672
  surcharges?: any[];
673
673
  relation_forms: any[];
674
674
  form_record_ids?: OrderSubmitFormRecord[];