@pisell/pisellos 2.1.152 → 2.1.153

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,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
+ });
@@ -310,7 +310,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
310
310
  date: string;
311
311
  status: string;
312
312
  week: string;
313
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
313
+ weekNum: 0 | 2 | 1 | 5 | 4 | 3 | 6;
314
314
  }[]>;
315
315
  submitTimeSlot(timeSlots: TimeSliceItem): void;
316
316
  private getScheduleDataByIds;
@@ -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 } from './types';
3
+ import { ScanOrderAddLogParams, ScanOrderAvailabilityInfo, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderScanCodeResult, 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';
@@ -69,7 +69,7 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
69
69
  passed: boolean | null;
70
70
  failures: QuantityCheckResult[];
71
71
  };
72
- getTempOrder(): import("./types").ScanOrderTempOrder | null;
72
+ getTempOrder(): ScanOrderTempOrder | null;
73
73
  updateTempOrderNote(note: string): string;
74
74
  setPickupReferenceMode(mode: 'counter_pickup' | 'table_service'): {
75
75
  service_type: 'dine_in';
@@ -77,8 +77,8 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
77
77
  };
78
78
  setPickupRef(buzzer: string): string;
79
79
  private ensureTempOrder;
80
- addNewOrder(): Promise<import("./types").ScanOrderTempOrder>;
81
- restoreOrder(): Promise<import("./types").ScanOrderTempOrder>;
80
+ addNewOrder(): Promise<ScanOrderTempOrder>;
81
+ restoreOrder(): Promise<ScanOrderTempOrder>;
82
82
  getOrderProducts(): ScanOrderOrderProduct[];
83
83
  getSummary(): Promise<import("./types").ScanOrderSummary>;
84
84
  getDiscountList(): Discount[];
@@ -92,6 +92,7 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
92
92
  }): Promise<void>;
93
93
  private findReservationRuleResource;
94
94
  private buildScanOrderResourceMetadata;
95
+ private prepareRetailAvailability;
95
96
  private buildSubmitPayloadEnhancer;
96
97
  submitScanOrder<T = any>(): Promise<T>;
97
98
  addProductToOrder(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
@@ -118,7 +119,7 @@ export declare class ScanOrderImpl extends BaseModule implements Module {
118
119
  private normalizeResourceState;
119
120
  private resolveResourceSelectType;
120
121
  private fetchResourceOccupyDetailByResourceId;
121
- checkResourceAvailable(resourceId: string, hasOrderId: boolean): Promise<ScanOrderAvailabilityInfo>;
122
+ checkResourceAvailable(resourceId?: string | null, hasOrderId?: boolean): Promise<ScanOrderAvailabilityInfo>;
122
123
  getAdditionalOrderInfo(): Promise<{
123
124
  orderId: string;
124
125
  orderStatus: 'pending' | 'processing' | 'completed' | 'cancelled';
@@ -815,6 +815,49 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
815
815
  combined_resource: isCombined ? combined : null
816
816
  };
817
817
  }
818
+ async prepareRetailAvailability(params) {
819
+ var _a, _b;
820
+ const { tempOrder, hasOrderId, resourceId, reason } = params;
821
+ this.enabledReservationRuleProducts = [];
822
+ tempOrder.bookings = [];
823
+ tempOrder.order_id = null;
824
+ delete tempOrder.relation_id;
825
+ delete tempOrder.table_form_id;
826
+ delete tempOrder.resource_id;
827
+ delete tempOrder.table_number;
828
+ tempOrder.metadata = { ...tempOrder.metadata || {} };
829
+ delete tempOrder.metadata.table_occupancy_duration;
830
+ const resourceState = {
831
+ mode: "idle",
832
+ deskmate_valid: false,
833
+ allowSnack: false,
834
+ deskmateValid: false,
835
+ isExclusive: false,
836
+ isFull: false,
837
+ raw: null
838
+ };
839
+ this.store.resource = resourceState;
840
+ (_a = this.store.order) == null ? void 0 : _a.persistTempOrder();
841
+ await this.addNewOrder();
842
+ await this.setItemRuleRuntimeConfig({
843
+ serviceType: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
844
+ submissionIndex: hasOrderId ? 1 : 0,
845
+ historicalItems: []
846
+ });
847
+ const availabilityInfo = {
848
+ mode: "idle",
849
+ deskmate_valid: false
850
+ };
851
+ this.logMethodSuccess("checkResourceAvailable", {
852
+ resourceId,
853
+ mode: availabilityInfo.mode,
854
+ retailMode: true,
855
+ retailReason: reason,
856
+ persistedRelationId: tempOrder.relation_id,
857
+ persistedResourceId: tempOrder.resource_id
858
+ });
859
+ return availabilityInfo;
860
+ }
818
861
  // ScanOrder 提交 payload enhancer:
819
862
  // - 给所有 booking 注入 appointment_status: 'started'(扫码点餐语义)
820
863
  // - 给所有 booking 的 metadata 注入 resource_select_type(来自预约规则商品的 resource.type)
@@ -837,7 +880,17 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
837
880
  };
838
881
  return (payload, { bookingUuid, tempOrder }) => {
839
882
  var _a, _b;
840
- const resourceId = tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId);
883
+ const resourceId = String(tempOrder.resource_id ?? (resourceState == null ? void 0 : resourceState.relationId) ?? "").trim();
884
+ const hasReservationBookingContext = Boolean(
885
+ ruleProduct && resourceState && resourceId && (tempOrder.relation_id || resourceState.relationId) && (tempOrder.table_form_id || resourceState.tableFormId)
886
+ );
887
+ if (!hasReservationBookingContext) {
888
+ return {
889
+ ...payload,
890
+ bookings: [],
891
+ products: [...payload.products || []]
892
+ };
893
+ }
841
894
  const rawCollectPax = (_a = tempOrder.metadata) == null ? void 0 : _a.collect_pax;
842
895
  const hasCollectPaxForCapacity = rawCollectPax !== null && rawCollectPax !== void 0 && rawCollectPax !== "";
843
896
  const resourceCapacityValue = hasCollectPaxForCapacity ? (0, import_utils2.normalizeSubmitCollectPaxValue)(rawCollectPax) : resolveResourceCapacity();
@@ -1499,10 +1552,11 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1499
1552
  // 检测当前链接是否可用
1500
1553
  // 通过 resource_id + 店铺配置
1501
1554
  // hasOrderId 表示 url 上是否有 orderid,如果是的话,后续的流程会走加单
1502
- async checkResourceAvailable(resourceId, hasOrderId) {
1555
+ async checkResourceAvailable(resourceId, hasOrderId = false) {
1503
1556
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1557
+ const normalizedResourceId = String(resourceId ?? "").trim();
1504
1558
  this.logMethodStart("checkResourceAvailable", {
1505
- resourceId
1559
+ resourceId: normalizedResourceId
1506
1560
  });
1507
1561
  try {
1508
1562
  const businessCode = String(((_a = this.otherParams) == null ? void 0 : _a.businessCode) ?? "").trim();
@@ -1556,62 +1610,66 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1556
1610
  const reservationLinkIds = (0, import_utils.collectLinkProductIdsFromReservationRules)(
1557
1611
  dineInConfig["fulfillment.enabled_resource_rules"]
1558
1612
  );
1613
+ if (!normalizedResourceId || reservationLinkIds.length === 0) {
1614
+ return await this.prepareRetailAvailability({
1615
+ tempOrder,
1616
+ hasOrderId,
1617
+ resourceId: normalizedResourceId,
1618
+ reason: !normalizedResourceId ? "missing_resource_id" : "missing_enabled_resource_rules"
1619
+ });
1620
+ }
1559
1621
  let pendingRequestEntryPax;
1560
1622
  let pendingRequestPaxMin;
1561
1623
  let pendingRequestPaxMax;
1562
- if (reservationLinkIds.length === 0) {
1563
- this.enabledReservationRuleProducts = [];
1624
+ tempOrder.metadata = { ...tempOrder.metadata || {} };
1625
+ delete tempOrder.metadata.table_occupancy_duration;
1626
+ const reservationProductList = new import_ProductList.ProductList(
1627
+ `${this.name}_reservationEnabledRules`,
1628
+ this.defaultVersion
1629
+ );
1630
+ await reservationProductList.initialize(this.core, {
1631
+ store: { list: [], selectProducts: [] },
1632
+ otherParams: {
1633
+ ...this.otherParams,
1634
+ fatherModule: this.name,
1635
+ openCache: Boolean(this.cacheId),
1636
+ cacheId: this.cacheId
1637
+ }
1638
+ });
1639
+ const scheduleDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1640
+ const scheduleDatetime = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1641
+ const loaded = await reservationProductList.loadProducts({
1642
+ product_ids: reservationLinkIds,
1643
+ schedule_date: scheduleDate,
1644
+ schedule_datetime: scheduleDatetime,
1645
+ cacheId: this.cacheId
1646
+ });
1647
+ if (Array.isArray(loaded)) {
1648
+ this.enabledReservationRuleProducts = loaded;
1649
+ const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(loaded);
1650
+ if (occupancyMinutes !== void 0) {
1651
+ tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
1652
+ }
1653
+ if ((0, import_utils.hasCustomCapacityProduct)(loaded)) {
1654
+ pendingRequestEntryPax = 1;
1655
+ const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(loaded);
1656
+ if ((paxBounds == null ? void 0 : paxBounds.min) !== void 0)
1657
+ pendingRequestPaxMin = paxBounds.min;
1658
+ if ((paxBounds == null ? void 0 : paxBounds.max) !== void 0)
1659
+ pendingRequestPaxMax = paxBounds.max;
1660
+ }
1564
1661
  } else {
1565
- tempOrder.metadata = { ...tempOrder.metadata || {} };
1566
- delete tempOrder.metadata.table_occupancy_duration;
1567
- const reservationProductList = new import_ProductList.ProductList(
1568
- `${this.name}_reservationEnabledRules`,
1569
- this.defaultVersion
1570
- );
1571
- await reservationProductList.initialize(this.core, {
1572
- store: { list: [], selectProducts: [] },
1573
- otherParams: {
1574
- ...this.otherParams,
1575
- fatherModule: this.name,
1576
- openCache: Boolean(this.cacheId),
1577
- cacheId: this.cacheId
1578
- }
1579
- });
1580
- const scheduleDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
1581
- const scheduleDatetime = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
1582
- const loaded = await reservationProductList.loadProducts({
1583
- product_ids: reservationLinkIds,
1584
- schedule_date: scheduleDate,
1585
- schedule_datetime: scheduleDatetime,
1662
+ this.enabledReservationRuleProducts = [];
1663
+ const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1664
+ this.logMethodError("loadReservationRuleProducts", error, {
1665
+ resourceId: normalizedResourceId,
1666
+ reservationLinkIds,
1667
+ scheduleDate,
1668
+ scheduleDatetime,
1586
1669
  cacheId: this.cacheId
1587
1670
  });
1588
- if (Array.isArray(loaded)) {
1589
- this.enabledReservationRuleProducts = loaded;
1590
- const occupancyMinutes = (0, import_utils.pickFirstDurationMinutesFromProducts)(loaded);
1591
- if (occupancyMinutes !== void 0) {
1592
- tempOrder.metadata.table_occupancy_duration = occupancyMinutes;
1593
- }
1594
- if ((0, import_utils.hasCustomCapacityProduct)(loaded)) {
1595
- pendingRequestEntryPax = 1;
1596
- const paxBounds = (0, import_utils.pickFirstCustomCapacityPaxBounds)(loaded);
1597
- if ((paxBounds == null ? void 0 : paxBounds.min) !== void 0)
1598
- pendingRequestPaxMin = paxBounds.min;
1599
- if ((paxBounds == null ? void 0 : paxBounds.max) !== void 0)
1600
- pendingRequestPaxMax = paxBounds.max;
1601
- }
1602
- } else {
1603
- this.enabledReservationRuleProducts = [];
1604
- const error = loaded instanceof Error ? loaded : new Error("预约规则商品列表接口返回异常");
1605
- this.logMethodError("loadReservationRuleProducts", error, {
1606
- resourceId,
1607
- reservationLinkIds,
1608
- scheduleDate,
1609
- scheduleDatetime,
1610
- cacheId: this.cacheId
1611
- });
1612
- }
1613
1671
  }
1614
- const occupyDetail = await this.fetchResourceOccupyDetailByResourceId(resourceId);
1672
+ const occupyDetail = await this.fetchResourceOccupyDetailByResourceId(normalizedResourceId);
1615
1673
  const resourceSelectType = this.resolveResourceSelectType(
1616
1674
  (0, import_utils.toPositiveString)(occupyDetail == null ? void 0 : occupyDetail.form_id)
1617
1675
  );
@@ -1643,9 +1701,9 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1643
1701
  ...this.store.resource.requestPaxMin !== void 0 ? { requestPaxMin: this.store.resource.requestPaxMin } : {},
1644
1702
  ...this.store.resource.requestPaxMax !== void 0 ? { requestPaxMax: this.store.resource.requestPaxMax } : {}
1645
1703
  };
1646
- tempOrder.relation_id = resourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1704
+ tempOrder.relation_id = normalizedResourceId || ((_g = this.otherParams) == null ? void 0 : _g.relation_id);
1647
1705
  tempOrder.table_form_id = resourceState.tableFormId;
1648
- tempOrder.resource_id = resourceId;
1706
+ tempOrder.resource_id = normalizedResourceId;
1649
1707
  (_h = this.store.order) == null ? void 0 : _h.persistTempOrder();
1650
1708
  if (availabilityInfo.mode === "idle") {
1651
1709
  await this.addNewOrder();
@@ -1685,7 +1743,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1685
1743
  availabilityInfo.closed_behavior = closedBehaviorValue;
1686
1744
  }
1687
1745
  this.logMethodSuccess("checkResourceAvailable", {
1688
- resourceId,
1746
+ resourceId: normalizedResourceId,
1689
1747
  mode: availabilityInfo.mode,
1690
1748
  orderId: availabilityInfo.order_id,
1691
1749
  relationId: availabilityInfo.relation_id,
@@ -1700,7 +1758,7 @@ var _ScanOrderImpl = class extends import_BaseModule.BaseModule {
1700
1758
  return availabilityInfo;
1701
1759
  } catch (error) {
1702
1760
  this.logMethodError("checkResourceAvailable", error.message, {
1703
- resourceId
1761
+ resourceId: normalizedResourceId
1704
1762
  });
1705
1763
  throw error;
1706
1764
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.152",
4
+ "version": "2.1.153",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",