@pisell/pisellos 0.0.553 → 0.0.555

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.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -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,57 @@ 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, allowAddItems) {
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
+ 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) {
2633
+ return toPositiveString(order === null || order === void 0 ? void 0 : order.id);
2634
+ }).filter(Boolean);
2635
+ if (resourceSelectType !== 'single') {
2636
+ return {
2637
+ matched: false,
2638
+ reason: 'no_order'
2639
+ };
2640
+ }
2641
+ if (!orderListIds.length) {
2642
+ return {
2643
+ matched: false,
2644
+ reason: 'no_order'
2645
+ };
2646
+ }
2647
+ if (!allowAddItems) {
2648
+ return {
2649
+ matched: false,
2650
+ reason: 'add_items_disabled'
2651
+ };
2652
+ }
2653
+ if (orderListIds.length === 1) {
2654
+ return {
2655
+ matched: true,
2656
+ order_id: orderListIds[0]
2657
+ };
2658
+ }
2659
+ if (orderListIds.length > 1) {
2660
+ return {
2661
+ matched: false,
2662
+ reason: 'multiple_orders'
2663
+ };
2664
+ }
2665
+ return {
2666
+ matched: false,
2667
+ reason: 'no_order'
2668
+ };
2669
+ }
2670
+
2671
+ // 检测当前链接是否可用
2622
2672
  // 通过 resource_id + 店铺配置
2623
2673
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
2624
2674
  }, {
@@ -2669,11 +2719,12 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2669
2719
  error,
2670
2720
  occupyDetails,
2671
2721
  occupyDetail,
2672
- currentOrderId,
2673
- orderListIds,
2722
+ resourceSelectType,
2723
+ allowAddItems,
2724
+ additionalOrderResult,
2725
+ _occupyDetail$order_l,
2674
2726
  multipleOrdersState,
2675
2727
  _availabilityInfo,
2676
- resourceSelectType,
2677
2728
  resourceState,
2678
2729
  additionalOrderId,
2679
2730
  availabilityInfo,
@@ -2841,16 +2892,16 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2841
2892
  return this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2842
2893
  case 50:
2843
2894
  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)) {
2850
- _context37.next = 60;
2895
+ occupyDetail = (_occupyDetails$ = occupyDetails[0]) !== null && _occupyDetails$ !== void 0 ? _occupyDetails$ : null; // Step3: 结合预约规则商品的 product_resource.resources 与占用接口返回的 form_id,
2896
+ // 计算当前桌台的 resourceSelectType(single/multiple/capacity)
2897
+ resourceSelectType = this.resolveResourceSelectType(toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id));
2898
+ allowAddItems = toBoolean(dineInConfig === null || dineInConfig === void 0 ? void 0 : dineInConfig['sale.allow_add_items']);
2899
+ additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(occupyDetail, resourceSelectType, allowAddItems);
2900
+ if (!(additionalOrderResult.reason === 'multiple_orders')) {
2901
+ _context37.next = 61;
2851
2902
  break;
2852
2903
  }
2853
- multipleOrdersState = _objectSpread(_objectSpread({}, this.normalizeResourceState(occupyDetail, undefined, hasOrderId)), {}, {
2904
+ multipleOrdersState = _objectSpread(_objectSpread({}, this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId)), {}, {
2854
2905
  mode: 'multiple_orders'
2855
2906
  });
2856
2907
  this.store.resource = multipleOrdersState;
@@ -2864,21 +2915,23 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
2864
2915
  this.logMethodSuccess('checkResourceAvailable', {
2865
2916
  resourceId: normalizedResourceId,
2866
2917
  mode: _availabilityInfo.mode,
2867
- orderListCount: orderListIds.length
2918
+ 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,
2919
+ resourceSelectType: resourceSelectType
2868
2920
  });
2869
2921
  return _context37.abrupt("return", _availabilityInfo);
2870
- 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
2922
+ case 61:
2923
+ // Step4: occupyDetail + resourceSelectType 规整为 resourceState
2874
2924
  resourceState = this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId);
2875
- additionalOrderId = currentOrderId || orderListIds[0];
2925
+ additionalOrderId = additionalOrderResult.order_id;
2876
2926
  if (additionalOrderId) {
2877
2927
  resourceState.mode = 'additional_order';
2878
2928
  resourceState.order_id = additionalOrderId;
2879
- } else if (!currentOrderId && orderListIds.length === 0) {
2880
- resourceState.mode = 'idle';
2881
- resourceState.order_id = undefined;
2929
+ } else if (additionalOrderResult.reason === 'add_items_disabled') {
2930
+ resourceState.mode = 'resource_busy';
2931
+ resourceState.order_id = '0';
2932
+ } else if (resourceSelectType === 'multiple' && resourceState.isFull) {
2933
+ resourceState.mode = 'resource_busy';
2934
+ resourceState.order_id = '0';
2882
2935
  }
2883
2936
  this.store.resource = resourceState;
2884
2937
 
@@ -3257,15 +3310,113 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
3257
3310
  value: function getEntryPaxNumber() {
3258
3311
  return this.store.entryPaxNumber;
3259
3312
  }
3313
+ }, {
3314
+ key: "syncAdditionalOrderFromResource",
3315
+ value: function () {
3316
+ var _syncAdditionalOrderFromResource = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(resourceId) {
3317
+ var _ref10, _ref11, _ref12, _this$store$resource2, _this$store$resource3, _occupyDetails$2, _this$store$resource4, _this$otherParams17, _this$store$order9;
3318
+ var tempOrder, normalizedResourceId, _result, occupyDetails, occupyDetail, resourceSelectType, allowAddItems, result;
3319
+ return _regeneratorRuntime().wrap(function _callee42$(_context42) {
3320
+ while (1) switch (_context42.prev = _context42.next) {
3321
+ case 0:
3322
+ tempOrder = this.ensureTempOrder();
3323
+ 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();
3324
+ this.logMethodStart('syncAdditionalOrderFromResource', {
3325
+ resourceId: normalizedResourceId
3326
+ });
3327
+ if (normalizedResourceId) {
3328
+ _context42.next = 7;
3329
+ break;
3330
+ }
3331
+ _result = {
3332
+ matched: false,
3333
+ reason: 'missing_resource_id'
3334
+ };
3335
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _result);
3336
+ return _context42.abrupt("return", _result);
3337
+ case 7:
3338
+ _context42.next = 9;
3339
+ return this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
3340
+ case 9:
3341
+ occupyDetails = _context42.sent;
3342
+ occupyDetail = (_occupyDetails$2 = occupyDetails[0]) !== null && _occupyDetails$2 !== void 0 ? _occupyDetails$2 : null;
3343
+ 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));
3344
+ allowAddItems = toBoolean((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 || (_this$otherParams17 = _this$otherParams17.dineInConfig) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17['sale.allow_add_items']);
3345
+ result = this.resolveAdditionalOrderFromOccupyDetail(occupyDetail, resourceSelectType, allowAddItems);
3346
+ if (!(!result.matched || !result.order_id)) {
3347
+ _context42.next = 17;
3348
+ break;
3349
+ }
3350
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _objectSpread(_objectSpread({}, result), {}, {
3351
+ resourceId: normalizedResourceId,
3352
+ resourceSelectType: resourceSelectType,
3353
+ allowAddItems: allowAddItems
3354
+ }));
3355
+ return _context42.abrupt("return", result);
3356
+ case 17:
3357
+ tempOrder.order_id = result.order_id;
3358
+ tempOrder.resource_id = normalizedResourceId;
3359
+ tempOrder.relation_id = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
3360
+ tempOrder.table_form_id = toPositiveString(occupyDetail === null || occupyDetail === void 0 ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
3361
+ (_this$store$order9 = this.store.order) === null || _this$store$order9 === void 0 || _this$store$order9.persistTempOrder();
3362
+ this.logMethodSuccess('syncAdditionalOrderFromResource', _objectSpread(_objectSpread({}, result), {}, {
3363
+ resourceId: normalizedResourceId,
3364
+ resourceSelectType: resourceSelectType,
3365
+ allowAddItems: allowAddItems
3366
+ }));
3367
+ return _context42.abrupt("return", result);
3368
+ case 24:
3369
+ case "end":
3370
+ return _context42.stop();
3371
+ }
3372
+ }, _callee42, this);
3373
+ }));
3374
+ function syncAdditionalOrderFromResource(_x22) {
3375
+ return _syncAdditionalOrderFromResource.apply(this, arguments);
3376
+ }
3377
+ return syncAdditionalOrderFromResource;
3378
+ }() // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
3379
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
3380
+ }, {
3381
+ key: "getReservationResourceSelectType",
3382
+ value: function getReservationResourceSelectType() {
3383
+ var _this$store$resource5;
3384
+ this.logMethodStart('getReservationResourceSelectType');
3385
+ var resourceSelectType = (_this$store$resource5 = this.store.resource) === null || _this$store$resource5 === void 0 ? void 0 : _this$store$resource5.resourceSelectType;
3386
+ var result = _objectSpread(_objectSpread({}, resourceSelectType ? {
3387
+ resourceSelectType: resourceSelectType
3388
+ } : {}), {}, {
3389
+ isSingleReservation: resourceSelectType === 'single',
3390
+ isMultipleReservation: resourceSelectType === 'multiple',
3391
+ isCapacityReservation: resourceSelectType === 'capacity'
3392
+ });
3393
+ this.logMethodSuccess('getReservationResourceSelectType', result);
3394
+ return result;
3395
+ }
3396
+
3397
+ // 判定后台是否开启允许加餐
3398
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3399
+ }, {
3400
+ key: "checkAllowAddItems",
3401
+ value: function checkAllowAddItems() {
3402
+ var _this$otherParams18;
3403
+ this.logMethodStart('checkAllowAddItems');
3404
+ var dineInConfig = ((_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.dineInConfig) || {};
3405
+ var result = {
3406
+ enabled: toBoolean(dineInConfig['sale.allow_add_items'])
3407
+ };
3408
+ this.logMethodSuccess('checkAllowAddItems', result);
3409
+ return result;
3410
+ }
3260
3411
 
3261
3412
  // 读取取餐/送餐开关
3262
3413
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
3263
3414
  }, {
3264
3415
  key: "getFulfillmentModes",
3265
3416
  value: function getFulfillmentModes() {
3266
- var _this$otherParams17;
3417
+ var _this$otherParams19;
3267
3418
  this.logMethodStart('getFulfillmentModes');
3268
- var dineInConfig = ((_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.dineInConfig) || {};
3419
+ var dineInConfig = ((_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.dineInConfig) || {};
3269
3420
  var result = {
3270
3421
  enablePickup: Boolean(dineInConfig['fulfillment.enable_pickup']),
3271
3422
  enableTableService: Boolean(dineInConfig['fulfillment.enable_table_service'])
@@ -3279,9 +3430,9 @@ export var ScanOrderImpl = /*#__PURE__*/function (_BaseModule) {
3279
3430
  }, {
3280
3431
  key: "checkManualPickupRef",
3281
3432
  value: function checkManualPickupRef() {
3282
- var _this$otherParams18;
3433
+ var _this$otherParams20;
3283
3434
  this.logMethodStart('checkManualPickupRef');
3284
- var dineInConfig = ((_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.dineInConfig) || {};
3435
+ var dineInConfig = ((_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.dineInConfig) || {};
3285
3436
  var refMode = dineInConfig['fulfillment.fulfillment_ref_mode'];
3286
3437
  var manualInputType = dineInConfig['fulfillment.manual_input_type'];
3287
3438
  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' | 'add_items_disabled' | '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;
@@ -0,0 +1,49 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/index.ts
30
+ var promotion_exports = {};
31
+ __export(promotion_exports, {
32
+ BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
+ X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
+ default: () => import_adapter2.default
37
+ });
38
+ module.exports = __toCommonJS(promotion_exports);
39
+ var import_evaluator = require("./evaluator");
40
+ var import_adapter = require("./adapter");
41
+ var import_adapter2 = __toESM(require("./adapter"));
42
+ var import_examples = require("./examples");
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ BUY_X_GET_Y_FREE_STRATEGY,
46
+ PromotionAdapter,
47
+ PromotionEvaluator,
48
+ X_ITEMS_FOR_Y_PRICE_STRATEGY
49
+ });
@@ -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,55 @@ 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, allowAddItems) {
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
+ 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);
1561
+ if (resourceSelectType !== "single") {
1562
+ return {
1563
+ matched: false,
1564
+ reason: "no_order"
1565
+ };
1566
+ }
1567
+ if (!orderListIds.length) {
1568
+ return {
1569
+ matched: false,
1570
+ reason: "no_order"
1571
+ };
1572
+ }
1573
+ if (!allowAddItems) {
1574
+ return {
1575
+ matched: false,
1576
+ reason: "add_items_disabled"
1577
+ };
1578
+ }
1579
+ if (orderListIds.length === 1) {
1580
+ return {
1581
+ matched: true,
1582
+ order_id: orderListIds[0]
1583
+ };
1584
+ }
1585
+ if (orderListIds.length > 1) {
1586
+ return {
1587
+ matched: false,
1588
+ reason: "multiple_orders"
1589
+ };
1590
+ }
1591
+ return {
1592
+ matched: false,
1593
+ reason: "no_order"
1594
+ };
1595
+ }
1552
1596
  // 检测当前链接是否可用
1553
1597
  // 通过 resource_id + 店铺配置
1554
1598
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1555
1599
  async checkResourceAvailable(resourceId, hasOrderId = false) {
1556
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1600
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1557
1601
  const normalizedResourceId = String(resourceId ?? "").trim();
1558
1602
  this.logMethodStart("checkResourceAvailable", {
1559
1603
  resourceId: normalizedResourceId
@@ -1671,11 +1715,18 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1671
1715
  }
1672
1716
  const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
1673
1717
  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) {
1718
+ const resourceSelectType = this.resolveResourceSelectType(
1719
+ (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1720
+ );
1721
+ const allowAddItems = (0, import_utils.toBoolean)(dineInConfig == null ? void 0 : dineInConfig["sale.allow_add_items"]);
1722
+ const additionalOrderResult = this.resolveAdditionalOrderFromOccupyDetail(
1723
+ occupyDetail,
1724
+ resourceSelectType,
1725
+ allowAddItems
1726
+ );
1727
+ if (additionalOrderResult.reason === "multiple_orders") {
1677
1728
  const multipleOrdersState = {
1678
- ...this.normalizeResourceState(occupyDetail, void 0, hasOrderId),
1729
+ ...this.normalizeResourceState(occupyDetail, resourceSelectType, hasOrderId),
1679
1730
  mode: "multiple_orders"
1680
1731
  };
1681
1732
  this.store.resource = multipleOrdersState;
@@ -1689,25 +1740,26 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1689
1740
  this.logMethodSuccess("checkResourceAvailable", {
1690
1741
  resourceId: normalizedResourceId,
1691
1742
  mode: availabilityInfo2.mode,
1692
- orderListCount: orderListIds.length
1743
+ orderListCount: ((_e = occupyDetail == null ? void 0 : occupyDetail.order_list) == null ? void 0 : _e.length) || 0,
1744
+ resourceSelectType
1693
1745
  });
1694
1746
  return availabilityInfo2;
1695
1747
  }
1696
- const resourceSelectType = this.resolveResourceSelectType(
1697
- (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1698
- );
1699
1748
  const resourceState = this.normalizeResourceState(
1700
1749
  occupyDetail,
1701
1750
  resourceSelectType,
1702
1751
  hasOrderId
1703
1752
  );
1704
- const additionalOrderId = currentOrderId || orderListIds[0];
1753
+ const additionalOrderId = additionalOrderResult.order_id;
1705
1754
  if (additionalOrderId) {
1706
1755
  resourceState.mode = "additional_order";
1707
1756
  resourceState.order_id = additionalOrderId;
1708
- } else if (!currentOrderId && orderListIds.length === 0) {
1709
- resourceState.mode = "idle";
1710
- resourceState.order_id = void 0;
1757
+ } else if (additionalOrderResult.reason === "add_items_disabled") {
1758
+ resourceState.mode = "resource_busy";
1759
+ resourceState.order_id = "0";
1760
+ } else if (resourceSelectType === "multiple" && resourceState.isFull) {
1761
+ resourceState.mode = "resource_busy";
1762
+ resourceState.order_id = "0";
1711
1763
  }
1712
1764
  this.store.resource = resourceState;
1713
1765
  if (pendingRequestEntryPax !== void 0) {
@@ -1726,16 +1778,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1726
1778
  table_form_id: resourceState.tableFormId,
1727
1779
  deskmate_valid: resourceState.deskmate_valid,
1728
1780
  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,
1781
+ policy: (_f = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _f.policy,
1782
+ partyroom_booking: (_g = occupyDetail == null ? void 0 : occupyDetail.form_record) == null ? void 0 : _g.partyroom_booking,
1731
1783
  ...this.store.resource.requestEntryPax !== void 0 ? { requestEntryPax: this.store.resource.requestEntryPax } : {},
1732
1784
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1733
1785
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1734
1786
  };
1735
- tempOrder.relation_id = normalizedResourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1787
+ tempOrder.relation_id = normalizedResourceId || ((_h = this.otherParams) == null ? void 0 : _h.relation_id);
1736
1788
  tempOrder.table_form_id = resourceState.tableFormId;
1737
1789
  tempOrder.resource_id = normalizedResourceId;
1738
- (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1790
+ (_i = this.store.order) == null ? void 0 : _i.persistTempOrder();
1739
1791
  if (availabilityInfo.mode === "idle") {
1740
1792
  await this.addNewOrder();
1741
1793
  }
@@ -1744,16 +1796,16 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1744
1796
  tempOrder.order_id = additionalOrderId;
1745
1797
  }
1746
1798
  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) => {
1799
+ const res = await ((_j = this.store.order) == null ? void 0 : _j.getOrderInfoByRemote(tempOrder.order_id));
1800
+ const entryPaxNumber = (_n = (_m = (_l = (_k = res == null ? void 0 : res.data) == null ? void 0 : _k.bookings) == null ? void 0 : _l.find((p) => {
1749
1801
  var _a2;
1750
1802
  return (_a2 = p.metadata) == null ? void 0 : _a2.collect_pax;
1751
- })) == null ? void 0 : _l.metadata) == null ? void 0 : _m.collect_pax;
1803
+ })) == null ? void 0 : _m.metadata) == null ? void 0 : _n.collect_pax;
1752
1804
  if (entryPaxNumber) {
1753
1805
  await this.setEntryPaxNumber(entryPaxNumber);
1754
1806
  }
1755
1807
  }
1756
- const lastOrderInfo = (_o = (_n = this.store.order) == null ? void 0 : _n.getLastOrderInfo) == null ? void 0 : _o.call(_n);
1808
+ const lastOrderInfo = (_p = (_o = this.store.order) == null ? void 0 : _o.getLastOrderInfo) == null ? void 0 : _p.call(_o);
1757
1809
  const historicalItems = isAdditionalOrderMode && Array.isArray(lastOrderInfo == null ? void 0 : lastOrderInfo.products) ? lastOrderInfo.products.reduce((acc, p) => {
1758
1810
  if (typeof (p == null ? void 0 : p.product_id) !== "number")
1759
1811
  return acc;
@@ -1765,7 +1817,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1765
1817
  return acc;
1766
1818
  }, []) : [];
1767
1819
  await this.setItemRuleRuntimeConfig({
1768
- serviceType: (_p = this.otherParams) == null ? void 0 : _p.businessCode,
1820
+ serviceType: (_q = this.otherParams) == null ? void 0 : _q.businessCode,
1769
1821
  submissionIndex: isAdditionalOrderMode ? 1 : 0,
1770
1822
  historicalItems
1771
1823
  });
@@ -1939,6 +1991,83 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1939
1991
  getEntryPaxNumber() {
1940
1992
  return this.store.entryPaxNumber;
1941
1993
  }
1994
+ async syncAdditionalOrderFromResource(resourceId) {
1995
+ var _a, _b, _c, _d, _e, _f;
1996
+ const tempOrder = this.ensureTempOrder();
1997
+ const normalizedResourceId = String(
1998
+ resourceId ?? tempOrder.resource_id ?? ((_a = this.store.resource) == null ? void 0 : _a.relationId) ?? ((_b = this.store.resource) == null ? void 0 : _b.relation_id) ?? ""
1999
+ ).trim();
2000
+ this.logMethodStart("syncAdditionalOrderFromResource", {
2001
+ resourceId: normalizedResourceId
2002
+ });
2003
+ if (!normalizedResourceId) {
2004
+ const result2 = {
2005
+ matched: false,
2006
+ reason: "missing_resource_id"
2007
+ };
2008
+ this.logMethodSuccess("syncAdditionalOrderFromResource", result2);
2009
+ return result2;
2010
+ }
2011
+ const occupyDetails = await this.fetchResourceOccupyDetailsByResourceId(normalizedResourceId);
2012
+ const occupyDetail = occupyDetails[0] ?? null;
2013
+ const resourceSelectType = ((_c = this.store.resource) == null ? void 0 : _c.resourceSelectType) || this.resolveResourceSelectType((0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id));
2014
+ const allowAddItems = (0, import_utils.toBoolean)(
2015
+ (_e = (_d = this.otherParams) == null ? void 0 : _d.dineInConfig) == null ? void 0 : _e["sale.allow_add_items"]
2016
+ );
2017
+ const result = this.resolveAdditionalOrderFromOccupyDetail(
2018
+ occupyDetail,
2019
+ resourceSelectType,
2020
+ allowAddItems
2021
+ );
2022
+ if (!result.matched || !result.order_id) {
2023
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2024
+ ...result,
2025
+ resourceId: normalizedResourceId,
2026
+ resourceSelectType,
2027
+ allowAddItems
2028
+ });
2029
+ return result;
2030
+ }
2031
+ tempOrder.order_id = result.order_id;
2032
+ tempOrder.resource_id = normalizedResourceId;
2033
+ tempOrder.relation_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_record_id) || normalizedResourceId || tempOrder.relation_id;
2034
+ tempOrder.table_form_id = (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id) || tempOrder.table_form_id;
2035
+ (_f = this.store.order) == null ? void 0 : _f.persistTempOrder();
2036
+ this.logMethodSuccess("syncAdditionalOrderFromResource", {
2037
+ ...result,
2038
+ resourceId: normalizedResourceId,
2039
+ resourceSelectType,
2040
+ allowAddItems
2041
+ });
2042
+ return result;
2043
+ }
2044
+ // 读取预约规则商品的资源选择类型:single=单个预约,multiple=多个预约,capacity=容量型预约
2045
+ // 依赖 checkResourceAvailable 已根据预约规则商品与 occupy-detail 的 form_id 计算并缓存 store.resource
2046
+ getReservationResourceSelectType() {
2047
+ var _a;
2048
+ this.logMethodStart("getReservationResourceSelectType");
2049
+ const resourceSelectType = (_a = this.store.resource) == null ? void 0 : _a.resourceSelectType;
2050
+ const result = {
2051
+ ...resourceSelectType ? { resourceSelectType } : {},
2052
+ isSingleReservation: resourceSelectType === "single",
2053
+ isMultipleReservation: resourceSelectType === "multiple",
2054
+ isCapacityReservation: resourceSelectType === "capacity"
2055
+ };
2056
+ this.logMethodSuccess("getReservationResourceSelectType", result);
2057
+ return result;
2058
+ }
2059
+ // 判定后台是否开启允许加餐
2060
+ // 依赖 checkResourceAvailable 已缓存的 dineInConfig
2061
+ checkAllowAddItems() {
2062
+ var _a;
2063
+ this.logMethodStart("checkAllowAddItems");
2064
+ const dineInConfig = ((_a = this.otherParams) == null ? void 0 : _a.dineInConfig) || {};
2065
+ const result = {
2066
+ enabled: (0, import_utils.toBoolean)(dineInConfig["sale.allow_add_items"])
2067
+ };
2068
+ this.logMethodSuccess("checkAllowAddItems", result);
2069
+ return result;
2070
+ }
1942
2071
  // 读取取餐/送餐开关
1943
2072
  // 依赖 checkResourceAvailable 已缓存的 dineInConfig
1944
2073
  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' | 'add_items_disabled' | '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.555",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",