@pisell/pisellos 0.0.553 → 0.0.554

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,6 +1,6 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
- import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderScanCodeResult, ScanOrderTempOrder } from './types';
3
+ import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderAllowAddItemsInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderReservationResourceSelectInfo, ScanOrderScanCodeResult, ScanOrderSyncAdditionalOrderResult, ScanOrderTempOrder } from './types';
4
4
  import type { UpdateProductInOrderParams } from '../../modules/Order/types';
5
5
  import type { Discount } from '../../modules/Discount/types';
6
6
  import { type CartItemSummary, type PaxInfo, type QuantityCheckResult, type QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
@@ -119,6 +119,7 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
119
119
  private normalizeResourceState;
120
120
  private resolveResourceSelectType;
121
121
  private fetchResourceOccupyDetailsByResourceId;
122
+ private resolveAdditionalOrderFromOccupyDetail;
122
123
  checkResourceAvailable(resourceId?: string | null, hasOrderId?: boolean): Promise<ScanOrderAvailabilityInfo>;
123
124
  getAdditionalOrderInfo(): Promise<{
124
125
  orderId: string;
@@ -142,6 +143,9 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
142
143
  clearUIState(): void;
143
144
  setEntryPaxNumber(number: number): Promise<void>;
144
145
  getEntryPaxNumber(): number | null;
146
+ syncAdditionalOrderFromResource(resourceId?: string | null): Promise<ScanOrderSyncAdditionalOrderResult>;
147
+ getReservationResourceSelectType(): ScanOrderReservationResourceSelectInfo;
148
+ checkAllowAddItems(): ScanOrderAllowAddItemsInfo;
145
149
  getFulfillmentModes(): {
146
150
  enablePickup: boolean;
147
151
  enableTableService: boolean;
@@ -2618,7 +2618,45 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2618
2618
  return _fetchResourceOccupyDetailsByResourceId.apply(this, arguments);
2619
2619
  }
2620
2620
  return fetchResourceOccupyDetailsByResourceId;
2621
- }() // 检测当前链接是否可用
2621
+ }()
2622
+ }, {
2623
+ key: "resolveAdditionalOrderFromOccupyDetail",
2624
+ value: function resolveAdditionalOrderFromOccupyDetail(detail, resourceSelectType) {
2625
+ var currentOrderId = toPositiveString(detail === null || detail === void 0 ? void 0 : detail.order_id);
2626
+ if (currentOrderId) {
2627
+ return {
2628
+ matched: true,
2629
+ order_id: currentOrderId
2630
+ };
2631
+ }
2632
+ if (resourceSelectType !== 'single') {
2633
+ return {
2634
+ matched: false,
2635
+ reason: 'no_order'
2636
+ };
2637
+ }
2638
+ var orderListIds = (Array.isArray(detail === null || detail === void 0 ? void 0 : detail.order_list) ? (detail === null || detail === void 0 ? void 0 : detail.order_list) || [] : []).map(function (order) {
2639
+ return toPositiveString(order === null || order === void 0 ? void 0 : order.id);
2640
+ }).filter(Boolean);
2641
+ if (orderListIds.length === 1) {
2642
+ return {
2643
+ matched: true,
2644
+ order_id: orderListIds[0]
2645
+ };
2646
+ }
2647
+ if (orderListIds.length > 1) {
2648
+ return {
2649
+ matched: false,
2650
+ reason: 'multiple_orders'
2651
+ };
2652
+ }
2653
+ return {
2654
+ matched: false,
2655
+ reason: 'no_order'
2656
+ };
2657
+ }
2658
+
2659
+ // 检测当前链接是否可用
2622
2660
  // 通过 resource_id + 店铺配置
2623
2661
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
2624
2662
  }, {
@@ -2669,11 +2707,11 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2669
2707
  error,
2670
2708
  occupyDetails,
2671
2709
  occupyDetail,
2672
- currentOrderId,
2673
- orderListIds,
2710
+ resourceSelectType,
2711
+ additionalOrderResult,
2712
+ _occupyDetail$order_l,
2674
2713
  multipleOrdersState,
2675
2714
  _availabilityInfo,
2676
- resourceSelectType,
2677
2715
  resourceState,
2678
2716
  additionalOrderId,
2679
2717
  availabilityInfo,
@@ -2841,16 +2879,15 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2841
2879
  return this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2842
2880
  case 50:
2843
2881
  occupyDetails = _context37.sent;
2844
- occupyDetail = (_occupyDetails$ = occupyDetails[0]) !== null && _occupyDetails$ !== void 0 ? _occupyDetails$ : null;
2845
- currentOrderId = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.order_id);
2846
- orderListIds = (Array.isArray(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.order_list) ? (occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.order_list) || [] : []).map(function (order) {
2847
- return toPositiveString(order === null || order === void 0 ? void 0 : order.id);
2848
- }).filter(Boolean);
2849
- if (!(!currentOrderId && orderListIds.length > 1)) {
2882
+ occupyDetail = (_occupyDetails$ = occupyDetails[0]) !== null && _occupyDetails$ !== void 0 ? _occupyDetails$ : null; // Step3: 结合预约规则商品的 product_resource.resources 与占用接口返回的 form_id,
2883
+ // 计算当前桌台的 resourceSelectType(single/multiple/capacity)
2884
+ resourceSelectType = this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id));
2885
+ additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(occupyDetail, resourceSelectType);
2886
+ if (!(additionalOrderResult.reason === 'multiple_orders')) {
2850
2887
  _context37.next = 60;
2851
2888
  break;
2852
2889
  }
2853
- multipleOrdersState = _objectSpread(_objectSpread({}, this.normalizeResourceState(occupyDetail, undefined, hasOrderId)), {}, {
2890
+ multipleOrdersState = _objectSpread(_objectSpread({}, this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId)), {}, {
2854
2891
  mode: 'multiple_orders'
2855
2892
  });
2856
2893
  this.store.resource = multipleOrdersState;
@@ -2864,21 +2901,17 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2864
2901
  this.logMethodSuccess('checkResourceAvailable', {
2865
2902
  resourceId: normalizedResourceId,
2866
2903
  mode: _availabilityInfo.mode,
2867
- orderListCount: orderListIds.length
2904
+ orderListCount: (occupyDetail === null || occupyDetail === void 0 || (_occupyDetail$order_l = occupyDetail.order_list) === null || _occupyDetail$order_l === void 0 ? void 0 : _occupyDetail$order_l.length) || 0,
2905
+ resourceSelectType: resourceSelectType
2868
2906
  });
2869
2907
  return _context37.abrupt("return", _availabilityInfo);
2870
2908
  case 60:
2871
- // Step3: 结合预约规则商品的 product_resource.resources 与占用接口返回的 form_id,
2872
- // 计算当前桌台的 resourceSelectType(single/multiple/capacity)
2873
- resourceSelectType = this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id)); // Step4: 用 occupyDetail + resourceSelectType 规整为 resourceState
2909
+ // Step4: occupyDetail + resourceSelectType 规整为 resourceState
2874
2910
  resourceState = this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId);
2875
- additionalOrderId = currentOrderId || orderListIds[0];
2911
+ additionalOrderId = additionalOrderResult.order_id;
2876
2912
  if (additionalOrderId) {
2877
2913
  resourceState.mode = 'additional_order';
2878
2914
  resourceState.order_id = additionalOrderId;
2879
- } else if (!currentOrderId && orderListIds.length === 0) {
2880
- resourceState.mode = 'idle';
2881
- resourceState.order_id = undefined;
2882
2915
  }
2883
2916
  this.store.resource = resourceState;
2884
2917
 
@@ -2915,23 +2948,23 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2915
2948
 
2916
2949
  // 空闲状态下自动准备本地临时订单,供后续“购物车式”商品操作使用
2917
2950
  if (!(availabilityInfo.mode === 'idle')) {
2918
- _context37.next = 76;
2951
+ _context37.next = 75;
2919
2952
  break;
2920
2953
  }
2921
- _context37.next = 76;
2954
+ _context37.next = 75;
2922
2955
  return this.addNewOrder();
2923
- case 76:
2956
+ case 75:
2924
2957
  isAdditionalOrderMode = availabilityInfo.mode === 'additional_order' || availabilityInfo.mode === 'additional_order_with_code'; // 如果是加单模式,tempOrder 里需要记录目标订单 id,提交的时候走加单接口
2925
2958
  if (isAdditionalOrderMode) {
2926
2959
  tempOrder.order_id = additionalOrderId;
2927
2960
  }
2928
2961
  if (!tempOrder.order_id) {
2929
- _context37.next = 86;
2962
+ _context37.next = 85;
2930
2963
  break;
2931
2964
  }
2932
- _context37.next = 81;
2965
+ _context37.next = 80;
2933
2966
  return (_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 ? void 0 : _this$store$order7.getOrderInfoByRemote(tempOrder.order_id);
2934
- case 81:
2967
+ case 80:
2935
2968
  res = _context37.sent;
2936
2969
  // 找到下单的时候输入的 entryPaxNumber
2937
2970
  entryPaxNumber = res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 || (_res$data = _res$data.bookings) === null || _res$data === void 0 || (_res$data = _res$data.find(function (p) {
@@ -2939,12 +2972,12 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2939
2972
  return (_p$metadata = p.metadata) === null || _p$metadata === void 0 ? void 0 : _p$metadata.collect_pax;
2940
2973
  })) === null || _res$data === void 0 || (_res$data = _res$data.metadata) === null || _res$data === void 0 ? void 0 : _res$data.collect_pax;
2941
2974
  if (!entryPaxNumber) {
2942
- _context37.next = 86;
2975
+ _context37.next = 85;
2943
2976
  break;
2944
2977
  }
2945
- _context37.next = 86;
2978
+ _context37.next = 85;
2946
2979
  return this.setEntryPaxNumber(entryPaxNumber);
2947
- case 86:
2980
+ case 85:
2948
2981
  lastOrderInfo = (_this$store$order8 = this.store.order) === null || _this$store$order8 === void 0 || (_this$store$order8$ge = _this$store$order8.getLastOrderInfo) === null || _this$store$order8$ge === void 0 ? void 0 : _this$store$order8$ge.call(_this$store$order8);
2949
2982
  historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo === null || lastOrderInfo === void 0 ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce(function (acc, p) {
2950
2983
  if (typeof (p === null || p === void 0 ? void 0 : p.product_id) !== 'number') return acc;
@@ -2956,13 +2989,13 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2956
2989
  } : {}));
2957
2990
  return acc;
2958
2991
  }, []) : []; // pax 由 setEntryPaxNumber 负责写入 itemRuleRuntimeConfig.pax
2959
- _context37.next = 90;
2992
+ _context37.next = 89;
2960
2993
  return this.setItemRuleRuntimeConfig({
2961
2994
  serviceType: (_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.businessCode,
2962
2995
  submissionIndex: isAdditionalOrderMode ? 1 : 0,
2963
2996
  historicalItems: historicalItems
2964
2997
  });
2965
- case 90:
2998
+ case 89:
2966
2999
  // operating_hours 超出营业时段 + closed_behavior=show_menu_disabled:
2967
3000
  // 允许浏览商品但 UI 层需拦截“下一步”,这里覆盖最终 mode 并回传错误提示
2968
3001
  if (outsideOperatingHours && closedBehaviorValue === 'show_menu_disabled') {
@@ -2984,18 +3017,18 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2984
3017
  isFull: resourceState.isFull
2985
3018
  });
2986
3019
  return _context37.abrupt("return", availabilityInfo);
2987
- case 95:
2988
- _context37.prev = 95;
3020
+ case 94:
3021
+ _context37.prev = 94;
2989
3022
  _context37.t0 = _context37["catch"](3);
2990
3023
  this.logMethodError('checkResourceAvailable', _context37.t0.message, {
2991
3024
  resourceId: normalizedResourceId
2992
3025
  });
2993
3026
  throw _context37.t0;
2994
- case 99:
3027
+ case 98:
2995
3028
  case "end":
2996
3029
  return _context37.stop();
2997
3030
  }
2998
- }, _callee37, this, [[3, 95]]);
3031
+ }, _callee37, this, [[3, 94]]);
2999
3032
  }));
3000
3033
  function checkResourceAvailable(_x19) {
3001
3034
  return _checkResourceAvailable.apply(this, arguments);
@@ -3257,15 +3290,110 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
3257
3290
  value: function getEntryPaxNumber() {
3258
3291
  return this.store.entryPaxNumber;
3259
3292
  }
3293
+ }, {
3294
+ key: "syncAdditionalOrderFromResource",
3295
+ value: function () {
3296
+ var _syncAdditionalOrderFromResource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(resourceId) {
3297
+ var _ref10, _ref11, _ref12, _this$store$resource2, _this$store$resource3, _occupyDetails$2, _this$store$resource4, _this$store$order9;
3298
+ var tempOrder, normalizedResourceId, _result, occupyDetails, occupyDetail, resourceSelectType, result;
3299
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3300
+ while (1) switch (_context42.prev = _context42.next) {
3301
+ case 0:
3302
+ tempOrder = this.ensureTempOrder();
3303
+ normalizedResourceId = String((_ref10 = (_ref11 = (_ref12 = resourceId !== null && resourceId !== void 0 ? resourceId : tempOrder.resource_id) !== null && _ref12 !== void 0 ? _ref12 : (_this$store$resource2 = this.store.resource) === null || _this$store$resource2 === void 0 ? void 0 : _this$store$resource2.relationId) !== null && _ref11 !== void 0 ? _ref11 : (_this$store$resource3 = this.store.resource) === null || _this$store$resource3 === void 0 ? void 0 : _this$store$resource3.relation_id) !== null && _ref10 !== void 0 ? _ref10 : '').trim();
3304
+ this.logMethodStart('syncAdditionalOrderFromResource', {
3305
+ resourceId: normalizedResourceId
3306
+ });
3307
+ if (normalizedResourceId) {
3308
+ _context42.next = 7;
3309
+ break;
3310
+ }
3311
+ _result = {
3312
+ matched: false,
3313
+ reason: 'missing_resource_id'
3314
+ };
3315
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _result);
3316
+ return _context42.abrupt("return", _result);
3317
+ case 7:
3318
+ _context42.next = 9;
3319
+ return this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
3320
+ case 9:
3321
+ occupyDetails = _context42.sent;
3322
+ occupyDetail = (_occupyDetails$2 = occupyDetails[0]) !== null && _occupyDetails$2 !== void 0 ? _occupyDetails$2 : null;
3323
+ resourceSelectType = ((_this$store$resource4 = this.store.resource) === null || _this$store$resource4 === void 0 ? void 0 : _this$store$resource4.resourceSelectType) || this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id));
3324
+ result = this.resolveAdditionalOrderFromOccupyDetail(occupyDetail, resourceSelectType);
3325
+ if (!(!result.matched || !result.order_id)) {
3326
+ _context42.next = 16;
3327
+ break;
3328
+ }
3329
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _objectSpread(_objectSpread({}, result), {}, {
3330
+ resourceId: normalizedResourceId,
3331
+ resourceSelectType: resourceSelectType
3332
+ }));
3333
+ return _context42.abrupt("return", result);
3334
+ case 16:
3335
+ tempOrder.order_id = result.order_id;
3336
+ tempOrder.resource_id = normalizedResourceId;
3337
+ tempOrder.relation_id = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
3338
+ tempOrder.table_form_id = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
3339
+ (_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 || _this$store$order9.persistTempOrder();
3340
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _objectSpread(_objectSpread({}, result), {}, {
3341
+ resourceId: normalizedResourceId,
3342
+ resourceSelectType: resourceSelectType
3343
+ }));
3344
+ return _context42.abrupt("return", result);
3345
+ case 23:
3346
+ case "end":
3347
+ return _context42.stop();
3348
+ }
3349
+ }, _callee42, this);
3350
+ }));
3351
+ function syncAdditionalOrderFromResource(_x22) {
3352
+ return _syncAdditionalOrderFromResource.apply(this, arguments);
3353
+ }
3354
+ return syncAdditionalOrderFromResource;
3355
+ }() // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
3356
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
3357
+ }, {
3358
+ key: "getReservationResourceSelectType",
3359
+ value: function getReservationResourceSelectType() {
3360
+ var _this$store$resource5;
3361
+ this.logMethodStart('getReservationResourceSelectType');
3362
+ var resourceSelectType = (_this$store$resource5 = this.store.resource) === null || _this$store$resource5 === void 0 ? void 0 : _this$store$resource5.resourceSelectType;
3363
+ var result = _objectSpread(_objectSpread({}, resourceSelectType ? {
3364
+ resourceSelectType: resourceSelectType
3365
+ } : {}), {}, {
3366
+ isSingleReservation: resourceSelectType === 'single',
3367
+ isMultipleReservation: resourceSelectType === 'multiple',
3368
+ isCapacityReservation: resourceSelectType === 'capacity'
3369
+ });
3370
+ this.logMethodSuccess('getReservationResourceSelectType', result);
3371
+ return result;
3372
+ }
3373
+
3374
+ // 判定后台是否开启允许加餐
3375
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3376
+ }, {
3377
+ key: "checkAllowAddItems",
3378
+ value: function checkAllowAddItems() {
3379
+ var _this$otherParams17;
3380
+ this.logMethodStart('checkAllowAddItems');
3381
+ var dineInConfig = ((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.dineInConfig) || {};
3382
+ var result = {
3383
+ enabled: toBoolean(dineInConfig['sale.allow_add_items'])
3384
+ };
3385
+ this.logMethodSuccess('checkAllowAddItems', result);
3386
+ return result;
3387
+ }
3260
3388
 
3261
3389
  // 读取取餐/送餐开关
3262
3390
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3263
3391
  }, {
3264
3392
  key: "getFulfillmentModes",
3265
3393
  value: function getFulfillmentModes() {
3266
- var _this$otherParams17;
3394
+ var _this$otherParams18;
3267
3395
  this.logMethodStart('getFulfillmentModes');
3268
- var dineInConfig = ((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.dineInConfig) || {};
3396
+ var dineInConfig = ((_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.dineInConfig) || {};
3269
3397
  var result = {
3270
3398
  enablePickup: Boolean(dineInConfig['fulfillment.enable_pickup']),
3271
3399
  enableTableService: Boolean(dineInConfig['fulfillment.enable_table_service'])
@@ -3279,9 +3407,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
3279
3407
  }, {
3280
3408
  key: "checkManualPickupRef",
3281
3409
  value: function checkManualPickupRef() {
3282
- var _this$otherParams18;
3410
+ var _this$otherParams19;
3283
3411
  this.logMethodStart('checkManualPickupRef');
3284
- var dineInConfig = ((_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.dineInConfig) || {};
3412
+ var dineInConfig = ((_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.dineInConfig) || {};
3285
3413
  var refMode = dineInConfig['fulfillment.fulfillment_ref_mode'];
3286
3414
  var manualInputType = dineInConfig['fulfillment.manual_input_type'];
3287
3415
  var enabled = refMode === 'manual_input';
@@ -246,6 +246,21 @@ export interface ScanOrderResourceOccupyDetailApiResponse {
246
246
  } | null;
247
247
  }
248
248
  export type ScanOrderResourceSelectType = 'single' | 'multiple' | 'capacity';
249
+ export interface ScanOrderReservationResourceSelectInfo {
250
+ resourceSelectType?: ScanOrderResourceSelectType;
251
+ isSingleReservation: boolean;
252
+ isMultipleReservation: boolean;
253
+ isCapacityReservation: boolean;
254
+ }
255
+ export interface ScanOrderAllowAddItemsInfo {
256
+ enabled: boolean;
257
+ }
258
+ export type ScanOrderSyncAdditionalOrderReason = 'missing_resource_id' | 'no_order' | 'multiple_orders' | 'invalid_order_id';
259
+ export interface ScanOrderSyncAdditionalOrderResult {
260
+ matched: boolean;
261
+ order_id?: string;
262
+ reason?: ScanOrderSyncAdditionalOrderReason;
263
+ }
249
264
  export interface ScanOrderResourceState extends ScanOrderAvailabilityInfo {
250
265
  relationId?: string;
251
266
  tableFormId?: string;
@@ -1,6 +1,6 @@
1
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
- import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderScanCodeResult, ScanOrderTempOrder } from './types';
3
+ import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderAllowAddItemsInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderReservationResourceSelectInfo, ScanOrderScanCodeResult, ScanOrderSyncAdditionalOrderResult, ScanOrderTempOrder } from './types';
4
4
  import type { UpdateProductInOrderParams } from '../../modules/Order/types';
5
5
  import type { Discount } from '../../modules/Discount/types';
6
6
  import { type CartItemSummary, type PaxInfo, type QuantityCheckResult, type QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
@@ -119,6 +119,7 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
119
119
  private normalizeResourceState;
120
120
  private resolveResourceSelectType;
121
121
  private fetchResourceOccupyDetailsByResourceId;
122
+ private resolveAdditionalOrderFromOccupyDetail;
122
123
  checkResourceAvailable(resourceId?: string | null, hasOrderId?: boolean): Promise<ScanOrderAvailabilityInfo>;
123
124
  getAdditionalOrderInfo(): Promise<{
124
125
  orderId: string;
@@ -142,6 +143,9 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
142
143
  clearUIState(): void;
143
144
  setEntryPaxNumber(number: number): Promise<void>;
144
145
  getEntryPaxNumber(): number | null;
146
+ syncAdditionalOrderFromResource(resourceId?: string | null): Promise<ScanOrderSyncAdditionalOrderResult>;
147
+ getReservationResourceSelectType(): ScanOrderReservationResourceSelectInfo;
148
+ checkAllowAddItems(): ScanOrderAllowAddItemsInfo;
145
149
  getFulfillmentModes(): {
146
150
  enablePickup: boolean;
147
151
  enableTableService: boolean;
@@ -1549,11 +1549,43 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1549
1549
  }
1550
1550
  return ((_c = response == null ? void 0 : response.data) == null ? void 0 : _c.occupy_details) ?? [];
1551
1551
  }
1552
+ resolveAdditionalOrderFromOccupyDetail(detail, resourceSelectType) {
1553
+ const currentOrderId = (0, import_utils.toPositiveString)(detail == null ? void 0 : detail.order_id);
1554
+ if (currentOrderId) {
1555
+ return {
1556
+ matched: true,
1557
+ order_id: currentOrderId
1558
+ };
1559
+ }
1560
+ if (resourceSelectType !== "single") {
1561
+ return {
1562
+ matched: false,
1563
+ reason: "no_order"
1564
+ };
1565
+ }
1566
+ const orderListIds = (Array.isArray(detail == null ? void 0 : detail.order_list) ? (detail == null ? void 0 : detail.order_list) || [] : []).map((order) => (0, import_utils.toPositiveString)(order == null ? void 0 : order.id)).filter(Boolean);
1567
+ if (orderListIds.length === 1) {
1568
+ return {
1569
+ matched: true,
1570
+ order_id: orderListIds[0]
1571
+ };
1572
+ }
1573
+ if (orderListIds.length > 1) {
1574
+ return {
1575
+ matched: false,
1576
+ reason: "multiple_orders"
1577
+ };
1578
+ }
1579
+ return {
1580
+ matched: false,
1581
+ reason: "no_order"
1582
+ };
1583
+ }
1552
1584
  // 检测当前链接是否可用
1553
1585
  // 通过 resource_id + 店铺配置
1554
1586
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1555
1587
  async checkResourceAvailable(resourceId, hasOrderId = false) {
1556
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1557
1589
  const normalizedResourceId = String(resourceId ?? "").trim();
1558
1590
  this.logMethodStart("checkResourceAvailable", {
1559
1591
  resourceId: normalizedResourceId
@@ -1671,11 +1703,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1671
1703
  }
1672
1704
  const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1673
1705
  const occupyDetail = occupyDetails[0] ?? null;
1674
- const currentOrderId = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.order_id);
1675
- const orderListIds = (Array.isArray(occupyDetail == null ? void 0 : occupyDetail.order_list) ? (occupyDetail == null ? void 0 : occupyDetail.order_list) || [] : []).map((order) => (0, import_utils.toPositiveString)(order == null ? void 0 : order.id)).filter(Boolean);
1676
- if (!currentOrderId && orderListIds.length > 1) {
1706
+ const resourceSelectType = this.resolveResourceSelectType(
1707
+ (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1708
+ );
1709
+ const additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(
1710
+ occupyDetail,
1711
+ resourceSelectType
1712
+ );
1713
+ if (additionalOrderResult.reason === "multiple_orders") {
1677
1714
  const multipleOrdersState = {
1678
- ...this.normalizeResourceState(occupyDetail, void 0, hasOrderId),
1715
+ ...this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId),
1679
1716
  mode: "multiple_orders"
1680
1717
  };
1681
1718
  this.store.resource = multipleOrdersState;
@@ -1689,25 +1726,20 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1689
1726
  this.logMethodSuccess("checkResourceAvailable", {
1690
1727
  resourceId: normalizedResourceId,
1691
1728
  mode: availabilityInfo2.mode,
1692
- orderListCount: orderListIds.length
1729
+ orderListCount: ((_e = occupyDetail == null ? void 0 : occupyDetail.order_list) == null ? void 0 : _e.length) || 0,
1730
+ resourceSelectType
1693
1731
  });
1694
1732
  return availabilityInfo2;
1695
1733
  }
1696
- const resourceSelectType = this.resolveResourceSelectType(
1697
- (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1698
- );
1699
1734
  const resourceState = this.normalizeResourceState(
1700
1735
  occupyDetail,
1701
1736
  resourceSelectType,
1702
1737
  hasOrderId
1703
1738
  );
1704
- const additionalOrderId = currentOrderId || orderListIds[0];
1739
+ const additionalOrderId = additionalOrderResult.order_id;
1705
1740
  if (additionalOrderId) {
1706
1741
  resourceState.mode = "additional_order";
1707
1742
  resourceState.order_id = additionalOrderId;
1708
- } else if (!currentOrderId && orderListIds.length === 0) {
1709
- resourceState.mode = "idle";
1710
- resourceState.order_id = void 0;
1711
1743
  }
1712
1744
  this.store.resource = resourceState;
1713
1745
  if (pendingRequestEntryPax !== void 0) {
@@ -1726,16 +1758,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1726
1758
  table_form_id: resourceState.tableFormId,
1727
1759
  deskmate_valid: resourceState.deskmate_valid,
1728
1760
  table_form_record: resourceState.table_form_record,
1729
- policy: (_e = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _e.policy,
1730
- partyroom_booking: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.partyroom_booking,
1761
+ policy: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.policy,
1762
+ partyroom_booking: (_g = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _g.partyroom_booking,
1731
1763
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1732
1764
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1733
1765
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1734
1766
  };
1735
- tempOrder.relation_id = normalizedResourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1767
+ tempOrder.relation_id = normalizedResourceId || ((_h = this.otherParams) == null ? void 0 : _h.relation_id);
1736
1768
  tempOrder.table_form_id = resourceState.tableFormId;
1737
1769
  tempOrder.resource_id = normalizedResourceId;
1738
- (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1770
+ (_i = this.store.order) == null ? void 0 : _i.persistTempOrder();
1739
1771
  if (availabilityInfo.mode === "idle") {
1740
1772
  await this.addNewOrder();
1741
1773
  }
@@ -1744,16 +1776,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1744
1776
  tempOrder.order_id = additionalOrderId;
1745
1777
  }
1746
1778
  if (tempOrder.order_id) {
1747
- const res = await ((_i = this.store.order) == null ? void 0 : _i.getOrderInfoByRemote(tempOrder.order_id));
1748
- const entryPaxNumber = (_m = (_l = (_k = (_j = res == null ? void 0 : res.data) == null ? void 0 : _j.bookings) == null ? void 0 : _k.find((p) => {
1779
+ const res = await ((_j = this.store.order) == null ? void 0 : _j.getOrderInfoByRemote(tempOrder.order_id));
1780
+ const entryPaxNumber = (_n = (_m = (_l = (_k = res == null ? void 0 : res.data) == null ? void 0 : _k.bookings) == null ? void 0 : _l.find((p) => {
1749
1781
  var _a2;
1750
1782
  return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1751
- })) == null ? void 0 : _l.metadata) == null ? void 0 : _m.collect_pax;
1783
+ })) == null ? void 0 : _m.metadata) == null ? void 0 : _n.collect_pax;
1752
1784
  if (entryPaxNumber) {
1753
1785
  await this.setEntryPaxNumber(entryPaxNumber);
1754
1786
  }
1755
1787
  }
1756
- const lastOrderInfo = (_o = (_n = this.store.order) == null ? void 0 : _n.getLastOrderInfo) == null ? void 0 : _o.call(_n);
1788
+ const lastOrderInfo = (_p = (_o = this.store.order) == null ? void 0 : _o.getLastOrderInfo) == null ? void 0 : _p.call(_o);
1757
1789
  const historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1758
1790
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1759
1791
  return acc;
@@ -1765,7 +1797,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1765
1797
  return acc;
1766
1798
  }, []) : [];
1767
1799
  await this.setItemRuleRuntimeConfig({
1768
- serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1800
+ serviceType: (_q = this.otherParams) == null ? void 0 : _q.businessCode,
1769
1801
  submissionIndex: isAdditionalOrderMode ? 1 : 0,
1770
1802
  historicalItems
1771
1803
  });
@@ -1939,6 +1971,77 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1939
1971
  getEntryPaxNumber() {
1940
1972
  return this.store.entryPaxNumber;
1941
1973
  }
1974
+ async syncAdditionalOrderFromResource(resourceId) {
1975
+ var _a, _b, _c, _d;
1976
+ const tempOrder = this.ensureTempOrder();
1977
+ const normalizedResourceId = String(
1978
+ resourceId ?? tempOrder.resource_id ?? ((_a = this.store.resource) == null ? void 0 : _a.relationId) ?? ((_b = this.store.resource) == null ? void 0 : _b.relation_id) ?? ""
1979
+ ).trim();
1980
+ this.logMethodStart("syncAdditionalOrderFromResource", {
1981
+ resourceId: normalizedResourceId
1982
+ });
1983
+ if (!normalizedResourceId) {
1984
+ const result2 = {
1985
+ matched: false,
1986
+ reason: "missing_resource_id"
1987
+ };
1988
+ this.logMethodSuccess("syncAdditionalOrderFromResource", result2);
1989
+ return result2;
1990
+ }
1991
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1992
+ const occupyDetail = occupyDetails[0] ?? null;
1993
+ const resourceSelectType = ((_c = this.store.resource) == null ? void 0 : _c.resourceSelectType) || this.resolveResourceSelectType((0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id));
1994
+ const result = this.resolveAdditionalOrderFromOccupyDetail(
1995
+ occupyDetail,
1996
+ resourceSelectType
1997
+ );
1998
+ if (!result.matched || !result.order_id) {
1999
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2000
+ ...result,
2001
+ resourceId: normalizedResourceId,
2002
+ resourceSelectType
2003
+ });
2004
+ return result;
2005
+ }
2006
+ tempOrder.order_id = result.order_id;
2007
+ tempOrder.resource_id = normalizedResourceId;
2008
+ tempOrder.relation_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
2009
+ tempOrder.table_form_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
2010
+ (_d = this.store.order) == null ? void 0 : _d.persistTempOrder();
2011
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2012
+ ...result,
2013
+ resourceId: normalizedResourceId,
2014
+ resourceSelectType
2015
+ });
2016
+ return result;
2017
+ }
2018
+ // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
2019
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
2020
+ getReservationResourceSelectType() {
2021
+ var _a;
2022
+ this.logMethodStart("getReservationResourceSelectType");
2023
+ const resourceSelectType = (_a = this.store.resource) == null ? void 0 : _a.resourceSelectType;
2024
+ const result = {
2025
+ ...resourceSelectType ? { resourceSelectType } : {},
2026
+ isSingleReservation: resourceSelectType === "single",
2027
+ isMultipleReservation: resourceSelectType === "multiple",
2028
+ isCapacityReservation: resourceSelectType === "capacity"
2029
+ };
2030
+ this.logMethodSuccess("getReservationResourceSelectType", result);
2031
+ return result;
2032
+ }
2033
+ // 判定后台是否开启允许加餐
2034
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
2035
+ checkAllowAddItems() {
2036
+ var _a;
2037
+ this.logMethodStart("checkAllowAddItems");
2038
+ const dineInConfig = ((_a = this.otherParams) == null ? void 0 : _a.dineInConfig) || {};
2039
+ const result = {
2040
+ enabled: (0, import_utils.toBoolean)(dineInConfig["sale.allow_add_items"])
2041
+ };
2042
+ this.logMethodSuccess("checkAllowAddItems", result);
2043
+ return result;
2044
+ }
1942
2045
  // 读取取餐/送餐开关
1943
2046
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
1944
2047
  getFulfillmentModes() {
@@ -246,6 +246,21 @@ export interface ScanOrderResourceOccupyDetailApiResponse {
246
246
  } | null;
247
247
  }
248
248
  export type ScanOrderResourceSelectType = 'single' | 'multiple' | 'capacity';
249
+ export interface ScanOrderReservationResourceSelectInfo {
250
+ resourceSelectType?: ScanOrderResourceSelectType;
251
+ isSingleReservation: boolean;
252
+ isMultipleReservation: boolean;
253
+ isCapacityReservation: boolean;
254
+ }
255
+ export interface ScanOrderAllowAddItemsInfo {
256
+ enabled: boolean;
257
+ }
258
+ export type ScanOrderSyncAdditionalOrderReason = 'missing_resource_id' | 'no_order' | 'multiple_orders' | 'invalid_order_id';
259
+ export interface ScanOrderSyncAdditionalOrderResult {
260
+ matched: boolean;
261
+ order_id?: string;
262
+ reason?: ScanOrderSyncAdditionalOrderReason;
263
+ }
249
264
  export interface ScanOrderResourceState extends ScanOrderAvailabilityInfo {
250
265
  relationId?: string;
251
266
  tableFormId?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.553",
4
+ "version": "0.0.554",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",