@pisell/pisellos 2.3.218 → 2.3.220

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/modules/OpenData/types.d.ts +3 -0
  2. package/dist/modules/Order/index.d.ts +1 -1
  3. package/dist/modules/Order/index.js +6 -3
  4. package/dist/modules/Order/types.d.ts +1 -1
  5. package/dist/modules/Order/utils.d.ts +4 -0
  6. package/dist/modules/Order/utils.js +105 -53
  7. package/dist/modules/Product/index.d.ts +1 -1
  8. package/dist/solution/BaseSales/index.d.ts +2 -0
  9. package/dist/solution/BaseSales/index.js +65 -37
  10. package/dist/solution/BaseSales/types.d.ts +2 -0
  11. package/dist/solution/BookingByStep/index.d.ts +1 -1
  12. package/dist/solution/BookingTicket/index.d.ts +16 -0
  13. package/dist/solution/BookingTicket/index.js +679 -332
  14. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +78 -0
  15. package/dist/solution/BookingTicket/utils/redeemArrival.js +175 -0
  16. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  17. package/lib/modules/OpenData/types.d.ts +3 -0
  18. package/lib/modules/Order/index.d.ts +1 -1
  19. package/lib/modules/Order/index.js +4 -1
  20. package/lib/modules/Order/types.d.ts +1 -1
  21. package/lib/modules/Order/utils.d.ts +4 -0
  22. package/lib/modules/Order/utils.js +45 -1
  23. package/lib/modules/Product/index.d.ts +1 -1
  24. package/lib/solution/BaseSales/index.d.ts +2 -0
  25. package/lib/solution/BaseSales/index.js +27 -6
  26. package/lib/solution/BaseSales/types.d.ts +2 -0
  27. package/lib/solution/BookingByStep/index.d.ts +1 -1
  28. package/lib/solution/BookingTicket/index.d.ts +16 -0
  29. package/lib/solution/BookingTicket/index.js +171 -5
  30. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +78 -0
  31. package/lib/solution/BookingTicket/utils/redeemArrival.js +156 -0
  32. package/package.json +1 -1
@@ -25,6 +25,7 @@ var _OpenData = require("../../modules/OpenData");
25
25
  var _BookingContext = require("../../modules/BookingContext");
26
26
  var _BaseSales = require("../BaseSales");
27
27
  var _scan = _interopRequireDefault(require("./utils/scan"));
28
+ var _redeemArrival = require("./utils/redeemArrival");
28
29
  var _orderCustomer = require("./utils/orderCustomer");
29
30
  var _handleScan = require("./utils/scan/handleScan");
30
31
  var _scanCache = _interopRequireDefault(require("./utils/scan/scanCache"));
@@ -167,6 +168,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
167
168
  orderCustomerDiscountRefreshCustomerId = null;
168
169
  orderCustomerDiscountRefreshTarget = null;
169
170
  orderCustomerPromotionRefreshInFlight = null;
171
+ // Retain the settled result too: a failed refresh must remain observable by checkout callers.
172
+ orderCustomerRefreshTask = Promise.resolve();
173
+ orderCustomerRefreshRevision = 0;
170
174
  orderCustomerContactRequest = null;
171
175
  customerResolveRequests = new Map();
172
176
  loadOpenDataInFlight = null;
@@ -1083,13 +1087,17 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1083
1087
  }
1084
1088
  return;
1085
1089
  }
1090
+ const enableMemberCartConsistency = this.isMemberCartConsistencyEnabled();
1086
1091
  const next = this.buildOrderCustomerPayload();
1087
1092
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, next && options?.source ? {
1088
1093
  ...next,
1089
1094
  source: options.source
1090
1095
  } : next);
1091
- this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
1092
- // 客户切换可能改变可用促销/赠品;触发一次重算(recursion-safe)。
1096
+ if (enableMemberCartConsistency) {
1097
+ this.refreshMemberCartContext(patch.customer_id);
1098
+ return;
1099
+ }
1100
+ void this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
1093
1101
  const promotionRefreshTask = this.store.order.applyPromotion().then(() => undefined);
1094
1102
  this.orderCustomerPromotionRefreshInFlight = promotionRefreshTask;
1095
1103
  void promotionRefreshTask.then(() => {
@@ -1101,6 +1109,31 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1101
1109
  this.orderCustomerPromotionRefreshInFlight = null;
1102
1110
  });
1103
1111
  }
1112
+
1113
+ /** Shared by customer changes and an explicit retry; keep the selected customer/cart intact. */
1114
+ refreshMemberCartContext(customerId) {
1115
+ const revision = ++this.orderCustomerRefreshRevision;
1116
+ const orderKey = this.getCustomerContactOrderKey();
1117
+ const isCurrent = () => revision === this.orderCustomerRefreshRevision && this.getCustomerContactOrderKey() === orderKey && Number(this.store.order.getOrderCustomer()?.customer_id || 0) === Number(customerId || 0);
1118
+ const task = (async () => {
1119
+ if (customerId) await this.refreshDiscountConfigAfterOrderCustomerChange(customerId);else await this.loadDiscountConfig({
1120
+ force: true
1121
+ });
1122
+ if (isCurrent()) await this.store.order.applyPromotion();
1123
+ })();
1124
+ this.orderCustomerRefreshTask = task;
1125
+ this.orderCustomerPromotionRefreshInFlight = task;
1126
+ void task.catch(error => {
1127
+ if (isCurrent()) console.error('[BookingTicket] Member cart refresh failed', error);
1128
+ }).finally(() => {
1129
+ if (this.orderCustomerPromotionRefreshInFlight === task) this.orderCustomerPromotionRefreshInFlight = null;
1130
+ });
1131
+ }
1132
+ async retryOrderCustomerRefresh() {
1133
+ if (!this.isMemberCartConsistencyEnabled()) return;
1134
+ this.refreshMemberCartContext(this.store.order.getOrderCustomer()?.customer_id ?? null);
1135
+ await this.waitForOrderCustomerRefresh();
1136
+ }
1104
1137
  resetOrderCustomerContactInfo() {
1105
1138
  this.orderCustomerContactRequest = null;
1106
1139
  const order = this.getTempOrder();
@@ -1219,6 +1252,8 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1219
1252
  * 清空下单客户(协议字段 + snapshot)。
1220
1253
  */
1221
1254
  clearOrderCustomer(options) {
1255
+ const enableMemberCartConsistency = this.isMemberCartConsistencyEnabled();
1256
+ const refreshRevision = enableMemberCartConsistency ? ++this.orderCustomerRefreshRevision : undefined;
1222
1257
  this.orderCustomerContactRequest = null;
1223
1258
  if (!options?.preserveContactInfo) this.resetOrderCustomerContactInfo();
1224
1259
  if (!options?.preserveContactInfo) this.store.order.updateTempOrderContactsInfo(null);
@@ -1230,9 +1265,11 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1230
1265
  void discountModule?.setOriginalDiscountList?.([]);
1231
1266
  void discountModule?.setDiscountList?.([]);
1232
1267
  this.store.order.applyDiscount();
1233
- void this.store.order.recalculateSummary({
1268
+ const customerOrderKey = enableMemberCartConsistency ? this.getCustomerContactOrderKey() : undefined;
1269
+ const refreshTask = this.store.order.recalculateSummary({
1234
1270
  createIfMissing: true
1235
1271
  }).then(() => {
1272
+ if (enableMemberCartConsistency && (this.orderCustomerRefreshRevision !== refreshRevision || this.getCustomerContactOrderKey() !== customerOrderKey)) return;
1236
1273
  const tempOrder = this.store.order.ensureTempOrder();
1237
1274
  this.store.order.persistTempOrder();
1238
1275
  return this.effectsEmit('onDiscountApplied', {
@@ -1241,7 +1278,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1241
1278
  selectedDiscountList: tempOrder.discount_list || [],
1242
1279
  tempOrder
1243
1280
  });
1244
- }).catch(error => {
1281
+ });
1282
+ if (enableMemberCartConsistency) this.orderCustomerRefreshTask = refreshTask.then(() => undefined);
1283
+ void (enableMemberCartConsistency ? this.orderCustomerRefreshTask : refreshTask).catch(error => {
1245
1284
  console.error('Failed to recalculate summary after clearing customer:', error);
1246
1285
  });
1247
1286
  this.core.effects.emit(`${this.name}:onOrderCustomerChange`, null);
@@ -1325,6 +1364,14 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
1325
1364
  waitForOrderCustomerPromotionRefresh() {
1326
1365
  return this.orderCustomerPromotionRefreshInFlight || Promise.resolve();
1327
1366
  }
1367
+
1368
+ /** Wait before reading cart rows: member coupons can split or consolidate them. */
1369
+ async waitForOrderCustomerRefresh() {
1370
+ if (!this.isMemberCartConsistencyEnabled()) return;
1371
+ // Customer-change listeners run synchronously before setOrderCustomer assigns its task.
1372
+ await Promise.resolve();
1373
+ await this.orderCustomerRefreshTask;
1374
+ }
1328
1375
  async prepareProductPriceQueryContext(customerId) {
1329
1376
  // onOrderCustomerChange 的订阅回调会立即开始重报价,而客户 Wallet/优惠资产
1330
1377
  // 在事件派发后才创建异步刷新任务。先让出一个微任务,确保能观察到该任务。
@@ -2117,6 +2164,9 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
2117
2164
  type: 'WRISTBAND',
2118
2165
  data: {
2119
2166
  order_id: this.getOrderIdentity()?.orderId,
2167
+ ...(params.voucher_times && {
2168
+ voucher_times: params.voucher_times
2169
+ }),
2120
2170
  voucher_ids: Array.isArray(params.voucher_ids) ? params.voucher_ids : [params.voucher_ids]
2121
2171
  }
2122
2172
  },
@@ -2127,6 +2177,14 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
2127
2177
  source_id: idempotencyKey
2128
2178
  });
2129
2179
  }
2180
+ redeemStatusWrite;
2181
+ arrivalQueue = Promise.resolve();
2182
+ getRedeemArrivalWindow() {
2183
+ return (0, _redeemArrival.readArrivalWindow)(this.store.openData?.getOpenData?.() ?? this.getInjectedOpenDataConfig());
2184
+ }
2185
+ isRedeemArrivalEnabled() {
2186
+ return Boolean(this.getRedeemArrivalWindow());
2187
+ }
2130
2188
 
2131
2189
  // 触发核销
2132
2190
  async handleRedeem(params) {
@@ -2153,12 +2211,18 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
2153
2211
  };
2154
2212
  });
2155
2213
  if (tempOrder && hasUpdatedVoucher) {
2156
- await this.replaceTempOrder({
2214
+ const write = this.replaceTempOrder({
2157
2215
  ...tempOrder,
2158
2216
  vouchers: nextVouchers
2159
2217
  }, {
2160
2218
  preserveOrderSessionId: this.getOrderSessionId() || undefined
2161
2219
  });
2220
+ this.redeemStatusWrite = write;
2221
+ try {
2222
+ await write;
2223
+ } finally {
2224
+ if (this.redeemStatusWrite === write) this.redeemStatusWrite = undefined;
2225
+ }
2162
2226
  }
2163
2227
  this.core.effects.emit(`${this.name}:onVouchersChange`, {});
2164
2228
  if (voucherIds.length === 0) {
@@ -2183,6 +2247,108 @@ class BookingTicketImpl extends _BaseSales.BaseSalesImpl {
2183
2247
  osServer: true
2184
2248
  });
2185
2249
  }
2250
+ async updateTicketArrival(voucherIds) {
2251
+ const window = this.getRedeemArrivalWindow();
2252
+ const tempOrder = this.store.order?.getTempOrder?.();
2253
+ const log = (0, _redeemArrival.createArrivalLogger)(this.logger, tempOrder, voucherIds);
2254
+ if (!window || !tempOrder) {
2255
+ log('skipped', {
2256
+ reason: !window ? 'no_effective_window' : 'missing_order'
2257
+ });
2258
+ return;
2259
+ }
2260
+ log('started', {
2261
+ early_minutes: window.earlyMinutes,
2262
+ late_minutes: window.lateMinutes
2263
+ });
2264
+ let operation = 'prepare';
2265
+ const arrivalTime = new Date();
2266
+ const session = this.getOrderSessionId();
2267
+ const updateArrival = async () => {
2268
+ // 本地核销状态写入期间读到的是旧快照。等写入完成再调时,batch 请求仍独立执行。
2269
+ if (this.redeemStatusWrite) await this.redeemStatusWrite.catch(() => {});
2270
+ const current = this.store.order?.getTempOrder?.();
2271
+ const sameOrder = () => {
2272
+ const active = this.store.order?.getTempOrder?.();
2273
+ return active && (session == null || this.getOrderSessionId() === session) && active.order_id === tempOrder.order_id && active.external_sale_number === tempOrder.external_sale_number;
2274
+ };
2275
+ const order = current && sameOrder() ? current : tempOrder;
2276
+ const arrival = (0, _redeemArrival.applyRedeemArrival)(order, new Set(voucherIds.map(String)), arrivalTime, window, reason => log('skipped', {
2277
+ reason
2278
+ }));
2279
+ if (!arrival) return;
2280
+ const next = {
2281
+ ...order,
2282
+ ...arrival
2283
+ };
2284
+ const query = (0, _redeemArrival.buildArrivalCheckoutQuery)(next, next.summary ?? (sameOrder() ? await this.getSummary() : undefined));
2285
+ operation = 'checkout';
2286
+ log('checkout_requested', {
2287
+ bookings: (0, _redeemArrival.describeChangedBookings)(order.bookings, arrival.bookings)
2288
+ });
2289
+ const checkout = await this.store.order.submitSalesOrder({
2290
+ query
2291
+ });
2292
+ if (checkout?.status === false || checkout?.code != null && checkout.code !== 200) {
2293
+ log('checkout_rejected', {
2294
+ code: checkout.code,
2295
+ status: checkout.status,
2296
+ message: checkout.message
2297
+ }, true);
2298
+ return checkout;
2299
+ }
2300
+ log('checkout_accepted', {
2301
+ code: checkout?.code
2302
+ });
2303
+ operation = 'local_update';
2304
+ if (this.redeemStatusWrite) await this.redeemStatusWrite.catch(() => {});
2305
+ if (sameOrder()) {
2306
+ const latest = this.store.order.getTempOrder();
2307
+ const patch = (0, _redeemArrival.applyRedeemArrival)(latest, new Set(voucherIds.map(String)), arrivalTime, window);
2308
+ if (patch) {
2309
+ await this.replaceTempOrder({
2310
+ ...latest,
2311
+ ...patch
2312
+ }, {
2313
+ preserveOrderSessionId: this.getOrderSessionId() || undefined
2314
+ });
2315
+ log('local_updated');
2316
+ this.core.effects.emit(`${this.name}:onVouchersChange`, {});
2317
+ } else {
2318
+ log('local_skipped', {
2319
+ reason: 'no_pending_change'
2320
+ });
2321
+ }
2322
+ } else {
2323
+ log('local_skipped', {
2324
+ reason: 'order_changed'
2325
+ });
2326
+ }
2327
+ // 从本次 checkout 已接受的快照取票面时间,避免打印接口短暂返回旧值。
2328
+ const voucherTimes = {};
2329
+ arrival.vouchers.forEach((voucher, index) => {
2330
+ if (voucher !== order.vouchers[index] && voucher.voucher_id != null && voucher.start_time && voucher.end_time) {
2331
+ voucherTimes[String(voucher.voucher_id)] = {
2332
+ start_time: voucher.start_time,
2333
+ end_time: voucher.end_time
2334
+ };
2335
+ }
2336
+ });
2337
+ return Object.keys(voucherTimes).length ? {
2338
+ ...checkout,
2339
+ voucher_times: voucherTimes
2340
+ } : checkout;
2341
+ };
2342
+ const completion = this.arrivalQueue.then(updateArrival).catch(error => {
2343
+ log('failed', {
2344
+ operation,
2345
+ message: error instanceof Error ? error.message : String(error)
2346
+ }, true);
2347
+ throw error;
2348
+ });
2349
+ this.arrivalQueue = completion.then(() => {}, () => {});
2350
+ return completion;
2351
+ }
2186
2352
 
2187
2353
  /**
2188
2354
  * 销毁模块:先调用父类(销毁所有 store 内子模块 + emit destroy + super.destroy()),
@@ -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,156 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyRedeemArrival = applyRedeemArrival;
7
+ exports.buildArrivalCheckoutQuery = buildArrivalCheckoutQuery;
8
+ exports.createArrivalLogger = createArrivalLogger;
9
+ exports.describeChangedBookings = describeChangedBookings;
10
+ exports.readArrivalWindow = readArrivalWindow;
11
+ var _dayjs = _interopRequireDefault(require("dayjs"));
12
+ var _posReceiptAutoPrint = require("../../../utils/pos-receipt-auto-print");
13
+ var _utils = require("../../../modules/Order/utils");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function readArrivalWindow(config) {
16
+ const enabled = config?.['fulfillment.enable_adjust_session_on_arrival'];
17
+ if (enabled !== true && enabled !== 1 && enabled !== '1') return;
18
+ const minutes = value => {
19
+ const number = Number(value);
20
+ return Number.isFinite(number) ? Math.max(0, Math.floor(number)) : 0;
21
+ };
22
+ const earlyMinutes = minutes(config?.['fulfillment.max_earlier_shift_minutes']);
23
+ const lateMinutes = minutes(config?.['fulfillment.max_later_shift_minutes']);
24
+ // 两个方向都没有可调整的分钟数时,核销和打印沿用关闭开关时的流程。
25
+ if (earlyMinutes === 0 && lateMinutes === 0) return;
26
+ return {
27
+ earlyMinutes,
28
+ lateMinutes
29
+ };
30
+ }
31
+ function shiftedSession(booking, now, window) {
32
+ if (!window || !booking.start_date || !booking.start_time || !booking.end_time) return null;
33
+ const start = (0, _dayjs.default)(`${booking.start_date} ${booking.start_time}`);
34
+ const end = (0, _dayjs.default)(`${booking.end_date || booking.start_date} ${booking.end_time}`);
35
+ if (!start.isValid() || !end.isValid() || end.isBefore(start)) return null;
36
+ const delta = (0, _dayjs.default)(now).startOf('minute').diff(start, 'minute');
37
+ const minutes = Math.max(-window.earlyMinutes, Math.min(window.lateMinutes, delta));
38
+ if (!Number.isFinite(minutes)) return null;
39
+ if (!minutes) return;
40
+ const shiftedStart = start.add(minutes, 'minute');
41
+ const shiftedEnd = end.add(minutes, 'minute');
42
+ return {
43
+ start_date: shiftedStart.format('YYYY-MM-DD'),
44
+ start_time: shiftedStart.format(booking.start_time.length > 5 ? 'HH:mm:ss' : 'HH:mm'),
45
+ end_date: shiftedEnd.format('YYYY-MM-DD'),
46
+ end_time: shiftedEnd.format(booking.end_time.length > 5 ? 'HH:mm:ss' : 'HH:mm')
47
+ };
48
+ }
49
+ function applyRedeemArrival(order, ids, now, window, onSkip) {
50
+ if (!window || !order.bookings?.length || !order.vouchers?.length) {
51
+ onSkip?.('missing_window_or_booking_data');
52
+ return;
53
+ }
54
+ const selected = new Set();
55
+ for (const voucher of order.vouchers) {
56
+ const event = (0, _utils.redeemEventKey)(voucher?.schedule_event_id);
57
+ if (event && ids.has(String(voucher.voucher_id))) selected.add(event);
58
+ }
59
+ let alreadyMarked = false;
60
+ let invalidSession = false;
61
+ const changes = new Map();
62
+ const bookings = order.bookings.map(booking => {
63
+ const event = (0, _utils.redeemEventKey)(booking?.schedule_event_id);
64
+ if (!event || !selected.has(event) || String(booking.parent_id) === '0') return booking;
65
+ if (Number(booking.metadata?.is_change_by_redeem) === 1) {
66
+ alreadyMarked = true;
67
+ return booking;
68
+ }
69
+ const shift = shiftedSession(booking, now, window);
70
+ if (shift === null) {
71
+ invalidSession = true;
72
+ return booking;
73
+ }
74
+ // 准点核销的偏移量为零,也要打标,避免下一张票改变这个时段。
75
+ changes.set(event, shift);
76
+ return {
77
+ ...booking,
78
+ ...shift,
79
+ metadata: {
80
+ ...booking.metadata,
81
+ is_change_by_redeem: 1
82
+ }
83
+ };
84
+ });
85
+ if (!changes.size) {
86
+ onSkip?.(invalidSession ? 'invalid_booking_time' : alreadyMarked ? 'already_marked' : 'no_linked_booking');
87
+ return;
88
+ }
89
+ const vouchers = order.vouchers.map(voucher => {
90
+ const event = (0, _utils.redeemEventKey)(voucher?.schedule_event_id);
91
+ const shift = event && changes.get(event);
92
+ if (!shift) return voucher;
93
+ return {
94
+ ...voucher,
95
+ start_date: shift.start_date,
96
+ expire_date: shift.end_date,
97
+ start_time: shift.start_time,
98
+ end_time: shift.end_time
99
+ };
100
+ });
101
+ return {
102
+ vouchers,
103
+ bookings
104
+ };
105
+ }
106
+ function createArrivalLogger(logger, order, voucherIds) {
107
+ return (stage, details = {}, failed = false) => {
108
+ try {
109
+ logger?.addLog({
110
+ type: failed ? 'error' : 'info',
111
+ title: '[BookingTicket] updateTicketArrival',
112
+ metadata: {
113
+ stage,
114
+ order_id: order?.order_id,
115
+ external_sale_number: order?.external_sale_number,
116
+ voucher_ids: voucherIds,
117
+ ...details
118
+ }
119
+ });
120
+ } catch {
121
+ // 日志不可用时,核销和预约调时仍按原流程执行。
122
+ }
123
+ };
124
+ }
125
+ function buildArrivalCheckoutQuery(order, summary) {
126
+ const {
127
+ vouchers: _localVouchers,
128
+ ...payload
129
+ } = (0, _utils.buildSubmitPayload)({
130
+ tempOrder: order,
131
+ platform: order.platform,
132
+ businessCode: order.business_code,
133
+ type: order.type,
134
+ summary
135
+ });
136
+ return {
137
+ ...payload,
138
+ // 调时提交无需自动打印整单小票;Redeem & Print 由票券按钮发起打印。
139
+ [_posReceiptAutoPrint.OS_POS_RECEIPT_AUTO_PRINT_PAYMENT_STATUSES_FIELD]: []
140
+ };
141
+ }
142
+ function describeChangedBookings(before, after) {
143
+ const changes = [];
144
+ for (const [index, booking] of after.entries()) {
145
+ const previous = before[index];
146
+ if (booking === previous) continue;
147
+ changes.push({
148
+ schedule_event_id: booking.schedule_event_id,
149
+ previous_start: previous.start_time,
150
+ previous_end: previous.end_time,
151
+ start: booking.start_time,
152
+ end: booking.end_time
153
+ });
154
+ }
155
+ return changes;
156
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.218",
4
+ "version": "2.3.220",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",