@pisell/pisellos 2.3.161 → 2.3.163

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.
@@ -1 +1,46 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _examples.BUY_X_GET_Y_FREE_STRATEGY;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _examples.ITEM_REWARD_STRATEGY;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "PromotionAdapter", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _adapter.PromotionAdapter;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "PromotionEvaluator", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _evaluator.PromotionEvaluator;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "default", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _adapter.default;
40
+ }
41
+ });
42
+ var _evaluator = require("./evaluator");
43
+ var _adapter = _interopRequireWildcard(require("./adapter"));
44
+ var _examples = require("./examples");
45
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
46
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -595,7 +595,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
595
595
  generateIdempotencyToken(): string;
596
596
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
597
597
  createOrder(params: CommitOrderParams['query']): {
598
- type: "appointment_booking" | "virtual";
598
+ type: "virtual" | "appointment_booking";
599
599
  platform: string;
600
600
  sales_channel: string;
601
601
  order_sales_channel: string;
@@ -213,6 +213,7 @@ export declare function normalizeBookingSubType(booking: Record<string, any>): s
213
213
  export declare function normalizeSubmitBooking<T extends {
214
214
  metadata?: Record<string, any>;
215
215
  }>(booking: T): T;
216
+ export declare function resolveTableOccupancyDuration(tempOrder: OrderTempOrder): number;
216
217
  /** 提交用人数:有限且为正则向下取整,否则为 1 */
217
218
  export declare function normalizeSubmitCollectPaxValue(value: unknown): number;
218
219
  /** 从临时订单 metadata 解析合成 booking 的 collect_pax */
@@ -109,6 +109,7 @@ Object.defineProperty(exports, "resolveSafeProductNum", {
109
109
  });
110
110
  exports.resolveSubmitCollectPax = resolveSubmitCollectPax;
111
111
  exports.resolveSubmitOrderType = resolveSubmitOrderType;
112
+ exports.resolveTableOccupancyDuration = resolveTableOccupancyDuration;
112
113
  Object.defineProperty(exports, "shouldBuildManualProductDiscount", {
113
114
  enumerable: true,
114
115
  get: function () {
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
328
328
  date: string;
329
329
  status: string;
330
330
  week: string;
331
- weekNum: 0 | 1 | 2 | 6 | 3 | 4 | 5;
331
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
332
332
  }[]>;
333
333
  submitTimeSlot(timeSlots: TimeSliceItem): void;
334
334
  private getScheduleDataByIds;
@@ -274,7 +274,7 @@ class SalesImpl extends _BaseModule.BaseModule {
274
274
  } : {
275
275
  external_sale_number: normalizedLookup
276
276
  };
277
- return this.request.post('/local/print-order', {
277
+ return this.request.post('/shop/local/print-order', {
278
278
  ...lookupPayload,
279
279
  lookup_order_from_db: 1,
280
280
  small_ticket_data_flag: 1,
@@ -797,6 +797,7 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
797
797
  }
798
798
 
799
799
  // ScanOrder 提交 payload enhancer:
800
+ // - 新单有桌台上下文但无 booking 时,补建基础预约(通用 Order 已不再自动生成)
800
801
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
801
802
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
802
803
  // - 给第一条 booking 补 resources 与 product_uid(仅当存在 resource / rule product)
@@ -818,7 +819,8 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
818
819
  };
819
820
  return (payload, {
820
821
  bookingUuid,
821
- tempOrder
822
+ tempOrder,
823
+ now
822
824
  }) => {
823
825
  const resourceId = String(resourceState?.relationId ?? '').trim();
824
826
  const hasReservationBookingContext = Boolean(ruleProduct && resourceState && resourceId && resourceState.relationId && resourceState.tableFormId);
@@ -855,7 +857,31 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
855
857
  } : undefined;
856
858
  const ruleProductUid = ruleProduct ? (0, _utils2.createUuidV4)() : undefined;
857
859
  const bookingCapacityDimensionId = (0, _utils.pickFirstCustomCapacityDimensionId)(this.enabledReservationRuleProducts) ?? 0;
858
- const nextBookings = (payload.bookings || []).map((booking, idx) => {
860
+ let bookings = payload.bookings || [];
861
+ if (!tempOrder.order_id && bookings.length === 0) {
862
+ const bookingStart = (0, _dayjs.default)(now);
863
+ const bookingDuration = (0, _utils2.resolveTableOccupancyDuration)(tempOrder);
864
+ const bookingEnd = bookingStart.add(bookingDuration, 'minute');
865
+ bookings = [(0, _utils2.normalizeSubmitBooking)({
866
+ relation_id: 0,
867
+ form_id: 0,
868
+ start_time: bookingStart.format('HH:mm'),
869
+ start_date: bookingStart.format('YYYY-MM-DD'),
870
+ end_time: bookingEnd.format('HH:mm'),
871
+ end_date: bookingEnd.format('YYYY-MM-DD'),
872
+ duration: bookingDuration,
873
+ metadata: {
874
+ unique_identification_number: bookingUuid
875
+ },
876
+ select_date: bookingStart.format('YYYY-MM-DD'),
877
+ is_all: false,
878
+ like_status: 'common',
879
+ schedule_id: 0,
880
+ relation_type: '',
881
+ number: 1
882
+ })];
883
+ }
884
+ const nextBookings = bookings.map((booking, idx) => {
859
885
  const metadata = {
860
886
  ...(booking.metadata || {})
861
887
  };
@@ -105,6 +105,12 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
105
105
  private normalizeAvailabilityIdList;
106
106
  private normalizeAvailabilityStringList;
107
107
  private normalizeAvailabilityPrepareDescriptor;
108
+ /**
109
+ * 列表直加没有经过 SKU availability flow,legacy cacheItem 的灵活时长可能落到
110
+ * 23:59。提交前用同一套营业排期补齐结束时间,保留已选开始时间、资源和 Holder。
111
+ * 仅供直加调用;手动时间选择和 availability candidate 不经过此方法。
112
+ */
113
+ prepareDirectAddFlexibleBooking(cacheItem: any): Promise<any>;
108
114
  private resolveAvailabilityPrepareDefaults;
109
115
  private buildAvailabilityPrepareKey;
110
116
  private clearAvailabilityRemoteResourceState;
@@ -33,8 +33,8 @@ var _dayjs = _interopRequireDefault(require("dayjs"));
33
33
  var _lodashEs = require("lodash-es");
34
34
  var _modules = require("../../modules");
35
35
  var _pickupTiming = require("../../modules/Order/pickupTiming");
36
- var _utils = require("../../modules/BookingContext/utils");
37
36
  var _cacheItemToBookingInput = require("../../modules/BookingContext/utils/cacheItemToBookingInput");
37
+ var _utils = require("../../modules/BookingContext/utils");
38
38
  var _OpenData = require("../../modules/OpenData");
39
39
  var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule");
40
40
  var _ResourcePlanner = require("../../modules/ResourcePlanner");
@@ -1385,6 +1385,90 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1385
1385
  mode
1386
1386
  });
1387
1387
  }
1388
+
1389
+ /**
1390
+ * 列表直加没有经过 SKU availability flow,legacy cacheItem 的灵活时长可能落到
1391
+ * 23:59。提交前用同一套营业排期补齐结束时间,保留已选开始时间、资源和 Holder。
1392
+ * 仅供直加调用;手动时间选择和 availability candidate 不经过此方法。
1393
+ */
1394
+ async prepareDirectAddFlexibleBooking(cacheItem) {
1395
+ if (!(0, _utils.isProductFlexibleDuration)(cacheItem?.duration) || (0, _utils.isSessionProduct)(cacheItem)) {
1396
+ return cacheItem;
1397
+ }
1398
+ const extend = cacheItem?._extend;
1399
+ const {
1400
+ startDate
1401
+ } = (0, _utils.getServiceTimes)(cacheItem);
1402
+ if (!extend?.start_date || !extend?.start_time || !startDate.isValid()) {
1403
+ throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', '灵活时长商品缺少有效开始时间');
1404
+ }
1405
+ const date = startDate.format('YYYY-MM-DD');
1406
+ // 带上前一天,覆盖凌晨仍处在前一营业时段内的情况。
1407
+ const dateRange = {
1408
+ startDate: startDate.subtract(1, 'day').format('YYYY-MM-DD'),
1409
+ endDate: date
1410
+ };
1411
+ const prepare = await this.resolveAvailabilityPrepareDefaults({
1412
+ dateRange
1413
+ });
1414
+ if (prepare._availabilityOperatingHours?.source !== 'open_data_schedule') {
1415
+ return cacheItem;
1416
+ }
1417
+ const operatingHours = this.buildAvailabilityOperatingHoursSnapshot({
1418
+ prepare,
1419
+ dateRange,
1420
+ scheduleList: this.getAvailabilityScheduleCatalog(),
1421
+ businessHours: DEFAULT_AVAILABILITY_BUSINESS_HOURS
1422
+ });
1423
+ if (operatingHours.missingScheduleIds.length > 0) {
1424
+ throw new _ResourcePlanner.AvailabilityError('OPERATING_HOURS_RESOLVE_FAILED', '店铺营业时间排期缺失,请重试', {
1425
+ missingScheduleIds: operatingHours.missingScheduleIds
1426
+ });
1427
+ }
1428
+ const start = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(startDate.format('YYYY-MM-DDTHH:mm:00')));
1429
+ const nextDay = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(`${startDate.add(1, 'day').format('YYYY-MM-DD')}T00:00:00`));
1430
+ const windows = operatingHours.windows.map(window => ({
1431
+ start: (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(window.startAt)),
1432
+ end: (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(window.endAt))
1433
+ })).filter(window => window.end > start && window.start < nextDay).sort((left, right) => left.start - right.start);
1434
+ const merged = [];
1435
+ for (const window of windows) {
1436
+ const previous = merged[merged.length - 1];
1437
+ if (previous && window.start <= previous.end) {
1438
+ previous.end = Math.max(previous.end, window.end);
1439
+ } else {
1440
+ merged.push({
1441
+ ...window
1442
+ });
1443
+ }
1444
+ }
1445
+ // POS 可以提前售票;保留开始分钟,结束取当前或当天下一段营业时间。
1446
+ // 不跨越午休,也不把闭店后的直加顺延到次日。
1447
+ let end = merged[0]?.end;
1448
+ const resourceEndAt = (0, _utils.getUsableTime)(cacheItem)?._extend?.usableTime?.end_at;
1449
+ if (resourceEndAt) {
1450
+ const resourceEnd = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)((0, _dayjs.default)(resourceEndAt).format('YYYY-MM-DDTHH:mm:00')));
1451
+ if (end !== undefined) end = Math.min(end, resourceEnd);
1452
+ }
1453
+ if (end === undefined || end <= start) {
1454
+ throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', '当前时间没有可用营业时段,请选择预约时间');
1455
+ }
1456
+ const duration = Math.floor((end - start) / 60000);
1457
+ if (duration <= 0) {
1458
+ throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', '灵活时长商品的结束时间必须晚于开始时间');
1459
+ }
1460
+ const endDate = (0, _dayjs.default)((0, _localClock.formatLocalDateTime)(start + duration * 60000));
1461
+ return {
1462
+ ...cacheItem,
1463
+ _extend: {
1464
+ ...extend,
1465
+ duration: _utils.flexibleObj.create(duration),
1466
+ endDate,
1467
+ end_date: endDate.format('YYYY-MM-DD'),
1468
+ end_time: endDate.format('HH:mm')
1469
+ }
1470
+ };
1471
+ }
1388
1472
  async resolveAvailabilityPrepareDefaults(params) {
1389
1473
  const needsOperatingHours = params.businessHours === undefined;
1390
1474
  const needsTimeSlice = params.slotStepMinutes === undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.161",
4
+ "version": "2.3.163",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",