@pisell/pisellos 2.1.129 → 2.1.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/Order/index.d.ts +7 -6
  3. package/dist/modules/Order/index.js +137 -42
  4. package/dist/modules/Order/types.d.ts +32 -6
  5. package/dist/modules/Order/types.js +2 -0
  6. package/dist/modules/Order/utils.d.ts +73 -11
  7. package/dist/modules/Order/utils.js +304 -52
  8. package/dist/modules/SalesSummary/utils.js +33 -68
  9. package/dist/modules/ScanOrderLogger/providers/feishu.js +168 -60
  10. package/dist/modules/ScanOrderLogger/types.d.ts +6 -0
  11. package/dist/modules/Summary/utils.js +6 -21
  12. package/dist/solution/ScanOrder/index.d.ts +57 -8
  13. package/dist/solution/ScanOrder/index.js +1531 -583
  14. package/dist/solution/ScanOrder/types.d.ts +86 -26
  15. package/dist/solution/ScanOrder/types.js +20 -1
  16. package/dist/solution/ScanOrder/utils.d.ts +53 -5
  17. package/dist/solution/ScanOrder/utils.js +257 -37
  18. package/dist/solution/VenueBooking/index.d.ts +30 -10
  19. package/dist/solution/VenueBooking/index.js +460 -217
  20. package/dist/solution/VenueBooking/types.d.ts +23 -0
  21. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  22. package/dist/solution/VenueBooking/utils/dateSummary.js +1 -1
  23. package/dist/solution/VenueBooking/utils/resource.d.ts +11 -1
  24. package/dist/solution/VenueBooking/utils/resource.js +57 -21
  25. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  26. package/dist/solution/VenueBooking/utils/slotMerge.js +33 -12
  27. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  28. package/dist/solution/VenueBooking/utils/timeSlot.js +259 -62
  29. package/lib/modules/Order/index.d.ts +7 -6
  30. package/lib/modules/Order/index.js +123 -31
  31. package/lib/modules/Order/types.d.ts +32 -6
  32. package/lib/modules/Order/utils.d.ts +73 -11
  33. package/lib/modules/Order/utils.js +203 -28
  34. package/lib/modules/SalesSummary/utils.js +13 -47
  35. package/lib/modules/ScanOrderLogger/providers/feishu.js +100 -34
  36. package/lib/modules/ScanOrderLogger/types.d.ts +6 -0
  37. package/lib/modules/Summary/utils.js +4 -18
  38. package/lib/solution/ScanOrder/index.d.ts +57 -8
  39. package/lib/solution/ScanOrder/index.js +713 -117
  40. package/lib/solution/ScanOrder/types.d.ts +86 -26
  41. package/lib/solution/ScanOrder/utils.d.ts +53 -5
  42. package/lib/solution/ScanOrder/utils.js +186 -19
  43. package/lib/solution/VenueBooking/index.d.ts +30 -10
  44. package/lib/solution/VenueBooking/index.js +206 -51
  45. package/lib/solution/VenueBooking/types.d.ts +23 -0
  46. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -1
  47. package/lib/solution/VenueBooking/utils/dateSummary.js +1 -1
  48. package/lib/solution/VenueBooking/utils/resource.d.ts +11 -1
  49. package/lib/solution/VenueBooking/utils/resource.js +15 -4
  50. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +5 -0
  51. package/lib/solution/VenueBooking/utils/slotMerge.js +29 -12
  52. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +1 -1
  53. package/lib/solution/VenueBooking/utils/timeSlot.js +182 -43
  54. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType } from '../../modules';
1
+ import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLogInput, ScanOrderLoggerModule, ScanOrderLoggerProviderConfig, ScanOrderLoggerProviderType, ScheduleModule } from '../../modules';
2
2
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
3
  /**
4
4
  * 扫码下单流程 hook
@@ -31,26 +31,70 @@ export interface ScanOrderOrderProductIdentity {
31
31
  product_id: number | null;
32
32
  product_variant_id: number;
33
33
  identity_key?: string;
34
+ /** 参与合并/匹配;与 remove 通配语义见 isSkuOnlyDeleteIdentity */
35
+ product_option_item?: any[];
36
+ product_bundle?: any[];
34
37
  }
35
38
  export interface ScanOrderOrderProduct extends ScanOrderOrderProductIdentity {
36
39
  order_detail_id: number | null;
37
40
  num: number;
38
41
  product_option_item: any[];
39
- /** 券后单品单价(= 订单域实际成交单价)。未应用券时等同 original_price。 */
42
+ /**
43
+ * 券后 **行 composite 单价** = `metadata.main_product_selling_price`
44
+ * + Σ((bundle.bundle_selling_price ?? bundle.price) × (bundle.num ?? 1))
45
+ *
46
+ * 新语义 v2 下 `metadata.main_product_selling_price` 已经**含 option**、含主商品折扣,
47
+ * 因此本字段不再叠加 option。未应用券时等同 `original_price`。
48
+ * Rules 钩子、主商品计税、Summary 统一读 metadata,不以此字段反推。
49
+ */
40
50
  selling_price: string;
41
- /** 券前单品单价(= 店铺售价),不承载后台划线价语义。 */
51
+ /**
52
+ * 券前 **行 composite 单价** = `metadata.main_product_original_price`
53
+ * + Σ(bundle 原价 × num)
54
+ *
55
+ * 新语义 v2 下 `metadata.main_product_original_price` 已经**含 option**、不含折扣。
56
+ * 不承载后台划线价语义。
57
+ */
42
58
  original_price: string;
43
59
  tax_fee: string;
44
60
  is_charge_tax: number;
45
61
  discount_list: any[];
46
62
  product_bundle: any[];
63
+ /**
64
+ * 行级扩展 metadata。价格相关的权威字段:
65
+ *
66
+ * - `source_product_price`:主商品/variant 基础价(已应用报价单),**不含 option、不含折扣**。
67
+ * 是派生 `main_product_*` 的唯一源。variant 分支优先读 `metadata.origin.variant[vid].price`。
68
+ * - `main_product_original_price` = `source_product_price + Σ(option.price × option.num)`,
69
+ * **含 option、不含折扣**。
70
+ * - `main_product_selling_price` = `main_product_original_price − 主商品券 per-unit amount`,
71
+ * **含 option、含主商品折扣**。Rules 钩子 / Summary / 计税均以此为主商品权威源。
72
+ * - `price_schema_version`(当前 = 2):schema 版本 sentinel,用于跨端协商价格口径、
73
+ * 区分 v1 旧缓存以便 `normalizeOrderProduct` 触发迁移。
74
+ */
47
75
  metadata: Record<string, any>;
76
+ /** 商品行备注(如顾客对单品的特殊要求) */
77
+ note?: string;
48
78
  _origin?: Record<string, any>;
49
79
  }
80
+ /**
81
+ * 出站 payload 版本的商品行。
82
+ *
83
+ * 与 tempOrder 内部 `ScanOrderOrderProduct` 的字段差异:
84
+ * - `product_option_item[*]`:内部为 `{ product_option_item_id, option_group_id, num, price, ... }`,
85
+ * 出站由 `normalizeSubmitProduct` 重命名为 `{ option_group_item_id, option_group_id, num }`
86
+ * (后端 checkout 协议;丢弃 `price` 等运行时辅助字段)。
87
+ * - `product_bundle[*].option[*]`:同上重命名规则。
88
+ *
89
+ * 运行时(UI 显示、加购合并、指纹、持久化)全部消费内部字段名 `product_option_item_id`,
90
+ * 仅在 SDK 提交边界做一次出站映射,不影响 opaque identity 契约。
91
+ */
50
92
  export interface ScanOrderSubmitProduct extends Omit<ScanOrderOrderProduct, '_origin' | 'identity_key'> {
51
93
  /**
52
94
  * 出站兼容字段:SDK 内部不再消费 payment_price,
53
95
  * 仅在提交后端时由 selling_price 派生,保持原有后端契约。
96
+ * 新语义 v2 下 selling_price 是 composite(含 option、含 bundle、含主商品折扣),
97
+ * 因此 payment_price 同样是 composite。
54
98
  */
55
99
  payment_price: string;
56
100
  }
@@ -114,6 +158,9 @@ export interface ScanOrderTempOrder {
114
158
  shop_discount: string;
115
159
  surcharge_fee: string;
116
160
  note: string;
161
+ buzzer?: string;
162
+ delivery_type?: string;
163
+ table_number?: Record<string, any>;
117
164
  schedule_date: string;
118
165
  created_at: string;
119
166
  products: ScanOrderOrderProduct[];
@@ -134,14 +181,15 @@ export interface ScanOrderSubmitPayload extends Omit<ScanOrderTempOrder, 'platfo
134
181
  request_unique_idempotency_token?: string;
135
182
  form_record_ids?: Array<{
136
183
  form_id: number | string;
137
- form_record_ids: Array<number | string>;
184
+ form_record_id: number | string;
138
185
  }>;
139
186
  products: ScanOrderSubmitProduct[];
140
187
  }
141
- export type ScanOrderAvailabilityMode = 'idle' | 'shop_closed' | 'resource_block' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
188
+ export type ScanOrderAvailabilityMode = 'idle' | 'shop_closed' | 'submit_disabled' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
142
189
  export interface ScanOrderTableFormRecord {
143
190
  policy?: string | null;
144
191
  partyroom_booking?: string | null;
192
+ capacity?: number | string | null;
145
193
  [key: string]: any;
146
194
  }
147
195
  export interface ScanOrderAvailabilityInfo {
@@ -151,7 +199,9 @@ export interface ScanOrderAvailabilityInfo {
151
199
  table_form_id?: string;
152
200
  deskmate_valid?: boolean;
153
201
  errorTips?: string;
154
- /** `/order/dining/table/config` 返回的 `table_form_record` 原样透出 */
202
+ /** 透传 `availability.closed_behavior`,便于 UI 识别拦截类型(如 show_menu_disabled) */
203
+ closed_behavior?: string;
204
+ /** `/order/resource/occupy-detail` 返回的 `form_record` 原样透出 */
155
205
  table_form_record?: ScanOrderTableFormRecord | null;
156
206
  policy?: string | null;
157
207
  partyroom_booking?: string | null;
@@ -162,34 +212,36 @@ export interface ScanOrderAvailabilityInfo {
162
212
  /** 首个 `capacity.type === 'custom'` 商品里 `custom[0]` 的 max(人数上限) */
163
213
  requestPaxMax?: number;
164
214
  }
165
- export interface ScanOrderTableSnackConfig {
166
- snack?: boolean | number | string;
167
- table_validate?: boolean | number | string;
215
+ /** `resource_capacity[i].capacity_list[j]` */
216
+ export interface ScanOrderResourceCapacitySlot {
217
+ start_at?: string;
218
+ end_at?: string;
219
+ pax?: number | string;
168
220
  }
169
- export interface ScanOrderOrderNumberPrefixConfig {
170
- table_order?: string;
171
- pos?: string;
221
+ export interface ScanOrderResourceCapacity {
222
+ capacity?: number | string;
223
+ capacity_list?: ScanOrderResourceCapacitySlot[];
172
224
  }
173
- export interface ScanOrderTableConfigApiData {
174
- table_max_number?: number | string | null;
175
- order_count?: number | string | null;
225
+ /** `/order/resource/occupy-detail` 单条 `occupy_details[i]` */
226
+ export interface ScanOrderResourceOccupyDetail {
227
+ form_record_id?: number | string | null;
228
+ form_id?: number | string | null;
176
229
  order_id?: number | string | null;
177
230
  last_order_id?: number | string | null;
178
- relation_id?: number | string | null;
179
- table_form_id?: number | string | null;
180
- table_snack?: ScanOrderTableSnackConfig[] | null;
181
- order_number_prefix?: ScanOrderOrderNumberPrefixConfig[] | null;
231
+ resource_capacity?: ScanOrderResourceCapacity[] | null;
232
+ form_record?: ScanOrderTableFormRecord | null;
182
233
  [key: string]: any;
183
234
  }
184
- export interface ScanOrderTableConfigApiResponse {
235
+ export interface ScanOrderResourceOccupyDetailApiResponse {
185
236
  status?: boolean;
186
237
  code?: number;
187
238
  message?: string;
188
- data?: ScanOrderTableConfigApiData | null;
239
+ data?: {
240
+ occupy_details?: ScanOrderResourceOccupyDetail[] | null;
241
+ } | null;
189
242
  }
243
+ export type ScanOrderResourceSelectType = 'single' | 'multiple' | 'capacity';
190
244
  export interface ScanOrderResourceState extends ScanOrderAvailabilityInfo {
191
- tableMaxNumber: number;
192
- orderCount: number;
193
245
  relationId?: string;
194
246
  tableFormId?: string;
195
247
  currentOrderId?: string;
@@ -198,13 +250,14 @@ export interface ScanOrderResourceState extends ScanOrderAvailabilityInfo {
198
250
  deskmateValid: boolean;
199
251
  isExclusive: boolean;
200
252
  isFull: boolean;
201
- orderNumberPrefix: ScanOrderOrderNumberPrefixConfig[];
202
- raw: ScanOrderTableConfigApiData | null;
253
+ /** 来自首个预约规则商品 product_resource.resources 中与 form_id 匹配的 resource type */
254
+ resourceSelectType?: ScanOrderResourceSelectType;
255
+ raw: ScanOrderResourceOccupyDetail | null;
203
256
  }
204
257
  export interface ScanOrderState {
205
258
  entryContext: ScanOrderEntryContext | null;
206
259
  status: ScanOrderStatus;
207
- config: ScanOrderTableConfigApiData | null;
260
+ config: Record<string, any> | null;
208
261
  resource: ScanOrderResourceState | null;
209
262
  flow: Record<string, any>;
210
263
  error: string | null;
@@ -212,6 +265,7 @@ export interface ScanOrderState {
212
265
  order?: OrderModule;
213
266
  salesSummary?: SalesSummaryModule;
214
267
  scanOrderLogger?: ScanOrderLoggerModule;
268
+ schedule?: ScheduleModule;
215
269
  itemRuleQuantityLimits: QuantityLimitResult[];
216
270
  cartValidation: {
217
271
  passed: boolean | null;
@@ -225,3 +279,9 @@ export interface ScanOrderLoggerRuntimeConfig {
225
279
  }
226
280
  export interface ScanOrderAddLogParams extends ScanOrderLogInput {
227
281
  }
282
+ /** ScanOrder.scanCode 对外的轻量结果(不含 discountList,UI 在 resolve 后调 getDiscountList) */
283
+ export interface ScanOrderScanCodeResult {
284
+ isAvailable: boolean;
285
+ type?: 'server' | string;
286
+ unavailableReason?: 'time_limit' | string;
287
+ }
@@ -10,7 +10,26 @@ export var ScanOrderHooks = /*#__PURE__*/function (ScanOrderHooks) {
10
10
  return ScanOrderHooks;
11
11
  }({});
12
12
 
13
+ /**
14
+ * 出站 payload 版本的商品行。
15
+ *
16
+ * 与 tempOrder 内部 `ScanOrderOrderProduct` 的字段差异:
17
+ * - `product_option_item[*]`:内部为 `{ product_option_item_id, option_group_id, num, price, ... }`,
18
+ * 出站由 `normalizeSubmitProduct` 重命名为 `{ option_group_item_id, option_group_id, num }`
19
+ * (后端 checkout 协议;丢弃 `price` 等运行时辅助字段)。
20
+ * - `product_bundle[*].option[*]`:同上重命名规则。
21
+ *
22
+ * 运行时(UI 显示、加购合并、指纹、持久化)全部消费内部字段名 `product_option_item_id`,
23
+ * 仅在 SDK 提交边界做一次出站映射,不影响 opaque identity 契约。
24
+ */
25
+
13
26
  /**
14
27
  * ScanOrder 临时订单(runtime-clean 版本)
15
28
  * 只保留运行时字段,不包含任何 __comment 字段
16
- */
29
+ */
30
+
31
+ /** `resource_capacity[i].capacity_list[j]` */
32
+
33
+ /** `/order/resource/occupy-detail` 单条 `occupy_details[i]` */
34
+
35
+ /** ScanOrder.scanCode 对外的轻量结果(不含 discountList,UI 在 resolve 后调 getDiscountList) */
@@ -1,4 +1,4 @@
1
- import { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderSummary, ScanOrderTempOrder } from './types';
1
+ import { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderResourceCapacitySlot, ScanOrderResourceSelectType, ScanOrderSummary, ScanOrderTempOrder } from './types';
2
2
  import type { CartItemSummary, ItemRuleBusinessData, PaxInfo, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
3
3
  import type { StrategyConfig } from '../../model/strategy/type';
4
4
  import type { ProductData } from '../../modules/Product/types';
@@ -82,9 +82,24 @@ export declare function buildItemRuleBusinessData(params: {
82
82
  }): ItemRuleBusinessData;
83
83
  export declare function attachItemRuleLimitsToTopLevelProducts<T>(productList: T, limits: QuantityLimitResult[]): T;
84
84
  /**
85
- * 判断两个商品 identity 是否匹配。
86
- * 当双方都没有 identity_key 时回退到 product_id + product_variant_id 比较(向后兼容);
87
- * 一旦有一方携带 identity_key,则必须严格相等。
85
+ * 将选项行 / 套餐行归一成稳定 JSON,用于「同 SKU 是否合并」判断。
86
+ * 数组元素先按主键排序再序列化,避免顺序差异导致误判为不同行。
87
+ */
88
+ export declare function buildProductLineFingerprint(productOptionItem?: unknown, productBundle?: unknown): string;
89
+ /**
90
+ * removeProductFromOrder 仅传 SKU 时的通配 identity(对象上未声明选项键)。
91
+ * 与显式 `product_option_item: []` 区分:后者只匹配「无选项」行。
92
+ */
93
+ export declare function isSkuOnlyDeleteIdentity(x: ScanOrderOrderProductIdentity): boolean;
94
+ /**
95
+ * 判断两个商品 identity 是否匹配(不透明 identity 契约)。
96
+ *
97
+ * 调用约定:始终 `isIdentityMatch(line, callerIdentity)`。
98
+ * - 若 SKU(product_id + product_variant_id)不一致 → 不匹配。
99
+ * - **双方都带** `identity_key` → 严格字符串相等比较(不再猜测合成 key / metadata 桥接)。
100
+ * 这是 opaque identity 契约的标准路径:UI 删改时透传 SDK 回灌的 identity_key。
101
+ * - 否则(即至少一侧未声明 identity_key)→ 进入「SKU 通配 / 显式空选项 / 指纹」回退路径,
102
+ * 忽略线侧 identity_key,按内容语义匹配。这给「行已 opaque、调用方却想按 SKU 通配 / 选项指纹删除」留兼容入口。
88
103
  */
89
104
  export declare function isIdentityMatch(a: ScanOrderOrderProductIdentity, b: ScanOrderOrderProductIdentity): boolean;
90
105
  /**
@@ -93,10 +108,26 @@ export declare function isIdentityMatch(a: ScanOrderOrderProductIdentity, b: Sca
93
108
  */
94
109
  export declare function getProductIdentityIndex(products: ScanOrderOrderProduct[], identity: ScanOrderOrderProductIdentity): number;
95
110
  /**
96
- * 对外部传入的商品对象做归一化:
111
+ * 对外部传入的商品对象做归一化(v2 composite 语义):
97
112
  * - 补全可选字段默认值(未传则使用兜底值,避免后续计算时因 undefined 导致异常)
98
113
  * - 对 num 调用 getSafeProductNum 做安全处理
99
114
  * - 保留 _origin 供后续业务流程(如促销规则)使用
115
+ *
116
+ * 价格字段语义(metadata 权威源 + composite 派生):
117
+ * - `metadata.source_product_price`:主商品/variant 基础价(已应用报价单),**不含 option**、
118
+ * **不含折扣**。是推导 main_product_* 的起点。variant 分支优先读 `metadata.origin.variant[vid].price`。
119
+ * - `metadata.main_product_original_price`:`source + Σ(option.price × option.num)`,**含 option**、
120
+ * **不含折扣**。
121
+ * - `metadata.main_product_selling_price`:`main_product_original_price - 主商品券 per-unit amount`,
122
+ * **含 option**、**含折扣**。
123
+ * - 行级 `selling_price` = `main_product_selling_price + Σ(bundle_selling_price × num)`。
124
+ * - 行级 `original_price` = `main_product_original_price + Σ(bundle 原价 × num)`。
125
+ *
126
+ * 迁移与幂等:
127
+ * - `metadata.price_schema_version === 2` → 已新语义归一化,保留 main_product_* 原值(保留折扣)。
128
+ * - 其它情况(v1 / 缺字段 / 无 metadata)→ 按"main_product_selling_price 曾是 main-only"的旧约定
129
+ * 反推 legacyDiscount,再以新 source + options 基准重算。最终统一打上 `price_schema_version: 2`。
130
+ * - 因此多次 normalize 不会重复叠加 option/bundle。
100
131
  */
101
132
  export declare function normalizeOrderProduct(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): ScanOrderOrderProduct;
102
133
  /**
@@ -109,6 +140,18 @@ export declare function collectLinkProductIdsFromReservationRules(rules: unknown
109
140
  export declare function pickFirstDurationMinutesFromProducts(products: ProductData[]): number | undefined;
110
141
  /** 是否存在 capacity.type === 'custom' 的商品 */
111
142
  export declare function hasCustomCapacityProduct(products: ProductData[]): boolean;
143
+ /**
144
+ * 根据预约规则商品的 resource.type 计算桌台是否已被"占满"。
145
+ * - single:只要有 `lastOrderId` 即视为占用
146
+ * - multiple:当前时间落在 `capacity_list[i]` 的 `[start_at, end_at]`(inclusive)内的 pax 之和 >= 总容量
147
+ * - 其他('capacity' / undefined):返回 false,不施加限制
148
+ */
149
+ export declare function computeResourceIsFull(params: {
150
+ resourceSelectType?: ScanOrderResourceSelectType;
151
+ lastOrderId?: string;
152
+ capacityList?: ScanOrderResourceCapacitySlot[];
153
+ capacity?: number | string | null;
154
+ }): boolean;
112
155
  /**
113
156
  * 在商品列表中找到第一个 `capacity.type === 'custom'` 的商品,取其 `custom` 数组第一项的 min/max。
114
157
  * 仅返回有限数字字段;若均无法解析则返回 `undefined`。
@@ -117,3 +160,8 @@ export declare function pickFirstCustomCapacityPaxBounds(products: ProductData[]
117
160
  min?: number;
118
161
  max?: number;
119
162
  } | undefined;
163
+ /**
164
+ * 第一个 `capacity.type === 'custom'` 的商品,取其 `custom[0].id`(提交 booking metadata.capacity 维度 id)。
165
+ * 无匹配时返回 `undefined`,调用方应回退为 `0`。
166
+ */
167
+ export declare function pickFirstCustomCapacityDimensionId(products: ProductData[]): string | number | undefined;