@pisell/pisellos 2.2.205 → 2.2.206

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 (42) hide show
  1. package/dist/modules/OpenData/index.d.ts +1 -0
  2. package/dist/modules/OpenData/index.js +21 -16
  3. package/dist/modules/Order/index.d.ts +9 -0
  4. package/dist/modules/Order/index.js +230 -145
  5. package/dist/modules/Order/types.d.ts +10 -0
  6. package/dist/modules/Order/utils.js +7 -5
  7. package/dist/server/index.d.ts +136 -0
  8. package/dist/server/index.js +2054 -781
  9. package/dist/server/modules/order/index.d.ts +7 -0
  10. package/dist/server/modules/order/index.js +375 -337
  11. package/dist/server/modules/order/types.d.ts +15 -0
  12. package/dist/server/modules/order/types.js +8 -0
  13. package/dist/server/utils/small-ticket.d.ts +69 -0
  14. package/dist/server/utils/small-ticket.js +528 -0
  15. package/dist/solution/BaseSales/index.d.ts +4 -2
  16. package/dist/solution/BaseSales/index.js +248 -188
  17. package/dist/solution/BookingByStep/index.d.ts +1 -1
  18. package/dist/solution/BookingTicket/index.d.ts +8 -1
  19. package/dist/solution/BookingTicket/index.js +443 -263
  20. package/dist/solution/BookingTicket/types.d.ts +2 -1
  21. package/dist/solution/BookingTicket/types.js +3 -1
  22. package/lib/modules/OpenData/index.d.ts +1 -0
  23. package/lib/modules/OpenData/index.js +6 -4
  24. package/lib/modules/Order/index.d.ts +9 -0
  25. package/lib/modules/Order/index.js +59 -3
  26. package/lib/modules/Order/types.d.ts +10 -0
  27. package/lib/modules/Order/utils.js +4 -3
  28. package/lib/server/index.d.ts +136 -0
  29. package/lib/server/index.js +822 -50
  30. package/lib/server/modules/order/index.d.ts +7 -0
  31. package/lib/server/modules/order/index.js +21 -7
  32. package/lib/server/modules/order/types.d.ts +15 -0
  33. package/lib/server/utils/small-ticket.d.ts +69 -0
  34. package/lib/server/utils/small-ticket.js +555 -0
  35. package/lib/solution/BaseSales/index.d.ts +4 -2
  36. package/lib/solution/BaseSales/index.js +47 -1
  37. package/lib/solution/BookingByStep/index.d.ts +1 -1
  38. package/lib/solution/BookingTicket/index.d.ts +8 -1
  39. package/lib/solution/BookingTicket/index.js +108 -1
  40. package/lib/solution/BookingTicket/types.d.ts +2 -1
  41. package/lib/solution/BookingTicket/types.js +5 -0
  42. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { ProductList, OrderModule } from '../../modules';
1
+ import { ProductList, OrderModule, OpenDataModule } from '../../modules';
2
2
  import { BookingContextModule } from '../../modules/BookingContext';
3
3
  import { CustomerModule } from '../../modules/Customer';
4
4
  import { SalesSummaryModule } from '../../modules/SalesSummary';
@@ -18,6 +18,7 @@ export interface BookingTicketState extends BaseSalesState {
18
18
  schedule: ScheduleModule;
19
19
  customer: CustomerModule;
20
20
  bookingContext: BookingContextModule;
21
+ openData: OpenDataModule;
21
22
  }
22
23
  export declare function createBookingTicketModule<T extends keyof BookingTicketState>(moduleName: T, solutionName: string, name?: string, version?: string): BookingTicketState[T] | null;
23
24
  export declare enum BookingTicketHooks {
@@ -1,4 +1,4 @@
1
- import { ProductList, OrderModule } from "../../modules";
1
+ import { ProductList, OrderModule, OpenDataModule } from "../../modules";
2
2
  import { BookingContextModule } from "../../modules/BookingContext";
3
3
  import { CustomerModule } from "../../modules/Customer";
4
4
  import { SalesSummaryModule } from "../../modules/SalesSummary";
@@ -23,6 +23,8 @@ export function createBookingTicketModule(moduleName, solutionName, name, versio
23
23
  return new CustomerModule("".concat(solutionName, "_").concat(name || moduleName), version);
24
24
  case 'bookingContext':
25
25
  return new BookingContextModule("".concat(solutionName, "_").concat(name || moduleName), version);
26
+ case 'openData':
27
+ return new OpenDataModule("".concat(solutionName, "_").concat(name || moduleName), version);
26
28
  default:
27
29
  return null;
28
30
  }
@@ -9,6 +9,7 @@ export declare class OpenDataModule extends BaseModule implements Module {
9
9
  protected defaultVersion: string;
10
10
  private request;
11
11
  private window;
12
+ private appPlugin;
12
13
  private store;
13
14
  private cacheId;
14
15
  private openCache;
@@ -52,6 +52,7 @@ var OpenDataModule = class extends import_BaseModule.BaseModule {
52
52
  }
53
53
  this.request = core.getPlugin("request");
54
54
  this.window = core.getPlugin("window");
55
+ this.appPlugin = core.getPlugin("app");
55
56
  if (!this.request)
56
57
  throw new Error("OpenDataModule 需要 request 插件支持");
57
58
  if (!this.window)
@@ -59,11 +60,12 @@ var OpenDataModule = class extends import_BaseModule.BaseModule {
59
60
  console.log("[OpenDataModule] 初始化完成");
60
61
  }
61
62
  async fetchOpenData(params) {
62
- var _a, _b, _c, _d;
63
- const shopId = (_b = (_a = this.otherParams) == null ? void 0 : _a.getStateData) == null ? void 0 : _b.call(_a, "shop_id");
63
+ var _a, _b;
64
+ const getData = (_b = (_a = this.appPlugin).getData) == null ? void 0 : _b.call(_a);
65
+ const shopId = getData == null ? void 0 : getData("shop_id");
64
66
  if (!shopId)
65
67
  throw new Error("[OpenDataModule] 无法获取 shop_id");
66
- const tenantId = (_d = (_c = this.otherParams) == null ? void 0 : _c.getStateData) == null ? void 0 : _d.call(_c, "tenant_id");
68
+ const tenantId = getData == null ? void 0 : getData("tenant_id");
67
69
  const headers = {};
68
70
  if (tenantId)
69
71
  headers["Tenant-Id"] = String(tenantId);
@@ -74,7 +76,7 @@ var OpenDataModule = class extends import_BaseModule.BaseModule {
74
76
  target: params.target,
75
77
  section_code: params.section_code
76
78
  },
77
- { pisell2: true, headers }
79
+ { pisell2: true, isPisell2: true, prefix: false, headers }
78
80
  );
79
81
  if ((response == null ? void 0 : response.status) === false) {
80
82
  throw new Error((response == null ? void 0 : response.message) || "获取 OpenData 配置失败");
@@ -149,6 +149,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
149
149
  private updateTempOrderPaymentStatus;
150
150
  private shouldKeepPaymentStatusAfterAmountRecalc;
151
151
  private resolveWalletPassUseValue;
152
+ private adjustVoucherFundRecord;
152
153
  private capVoucherPaymentsByRemainingAmount;
153
154
  private calculatePaidPaymentSummary;
154
155
  private calculatePaymentServiceFee;
@@ -300,6 +301,14 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
300
301
  * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
301
302
  */
302
303
  clearOrderCartLines(): Promise<OrderTempOrder>;
304
+ buildCurrentSubmitPayloadForLocalPrint(params?: {
305
+ cacheId?: string;
306
+ platform?: string;
307
+ businessCode?: string;
308
+ channel?: string;
309
+ type?: string;
310
+ }): import("./types").OrderSubmitPayload;
311
+ applyLocalPrintOrderNumbers(order?: Record<string, any> | null): Promise<OrderTempOrder>;
303
312
  /**
304
313
  * 提交当前 Sales tempOrder。
305
314
  *
@@ -826,6 +826,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
826
826
  return payment.wallet_pass_use_value;
827
827
  return amount.div(price).times(points).toDecimalPlaces(2).toFixed(2);
828
828
  }
829
+ adjustVoucherFundRecord(params) {
830
+ var _a;
831
+ const fundRecord = params.voucher.fund_record && typeof params.voucher.fund_record === "object" && !Array.isArray(params.voucher.fund_record) ? { ...params.voucher.fund_record } : null;
832
+ if (!fundRecord || fundRecord.using_before_value === void 0 || fundRecord.using_before_value === null) {
833
+ return fundRecord || void 0;
834
+ }
835
+ const code = String(params.voucher.code || "").toUpperCase();
836
+ const isPointCard = code === "POINTCARD" || String(((_a = params.voucher.fund_record) == null ? void 0 : _a.tag) || "").toLowerCase() === "point_card";
837
+ const usingValue = isPointCard ? new import_decimal.default(params.walletPassUseValue || 0) : params.amount;
838
+ fundRecord.using_after_value = new import_decimal.default(fundRecord.using_before_value || 0).minus(usingValue).toDecimalPlaces(2).toFixed(2);
839
+ return fundRecord;
840
+ }
829
841
  capVoucherPaymentsByRemainingAmount(params) {
830
842
  const targetAmount = this.getPaymentTargetAmount();
831
843
  const nonVoucherTotal = this.calculatePaymentTotal(params.nonVoucherPayments);
@@ -844,14 +856,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
844
856
  continue;
845
857
  const cappedAmount = import_decimal.default.min(voucherAmount, remainingAmount);
846
858
  const amountText = cappedAmount.toDecimalPlaces(2).toFixed(2);
859
+ const walletPassUseValue = this.resolveWalletPassUseValue(
860
+ voucher,
861
+ cappedAmount
862
+ );
847
863
  cappedVouchers.push({
848
864
  ...voucher,
849
865
  amount: amountText,
850
866
  origin_amount: amountText,
851
- wallet_pass_use_value: this.resolveWalletPassUseValue(
867
+ wallet_pass_use_value: walletPassUseValue,
868
+ fund_record: this.adjustVoucherFundRecord({
852
869
  voucher,
853
- cappedAmount
854
- )
870
+ amount: cappedAmount,
871
+ walletPassUseValue
872
+ })
855
873
  });
856
874
  remainingAmount = remainingAmount.minus(cappedAmount);
857
875
  }
@@ -2509,6 +2527,44 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2509
2527
  return tempOrder;
2510
2528
  }
2511
2529
  // ─── TempOrder: 提交 ───
2530
+ buildCurrentSubmitPayloadForLocalPrint(params) {
2531
+ var _a, _b, _c;
2532
+ const tempOrder = this.ensureTempOrder();
2533
+ this.persistTempOrder();
2534
+ const payload = (0, import_utils.buildSubmitPayload)({
2535
+ tempOrder,
2536
+ cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
2537
+ platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
2538
+ businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
2539
+ channel: params == null ? void 0 : params.channel,
2540
+ type: params == null ? void 0 : params.type,
2541
+ enhance: (nextPayload) => ({
2542
+ ...nextPayload,
2543
+ order_number: tempOrder.order_number ?? nextPayload.order_number ?? null,
2544
+ shop_order_number: tempOrder.shop_order_number ?? nextPayload.shop_order_number ?? null,
2545
+ shop_full_order_number: tempOrder.shop_full_order_number ?? nextPayload.shop_full_order_number ?? null,
2546
+ small_ticket_data_flag: 1
2547
+ })
2548
+ });
2549
+ payload.created_at = void 0;
2550
+ return payload;
2551
+ }
2552
+ async applyLocalPrintOrderNumbers(order) {
2553
+ const tempOrder = this.ensureTempOrder();
2554
+ if (!order || typeof order !== "object")
2555
+ return tempOrder;
2556
+ const shopOrderNumber = order.shop_order_number;
2557
+ const shopFullOrderNumber = order.shop_full_order_number;
2558
+ if (shopOrderNumber !== void 0 && shopOrderNumber !== null && shopOrderNumber !== "") {
2559
+ tempOrder.shop_order_number = String(shopOrderNumber);
2560
+ }
2561
+ if (shopFullOrderNumber !== void 0 && shopFullOrderNumber !== null && shopFullOrderNumber !== "") {
2562
+ tempOrder.shop_full_order_number = String(shopFullOrderNumber);
2563
+ }
2564
+ this.persistTempOrder();
2565
+ await this.saveDraft();
2566
+ return tempOrder;
2567
+ }
2512
2568
  /**
2513
2569
  * 提交当前 Sales tempOrder。
2514
2570
  *
@@ -456,6 +456,7 @@ export interface OrderPaymentData {
456
456
  payment_time?: string;
457
457
  wallet_pass_usage_unit?: unknown;
458
458
  wallet_pass_use_value?: string | number | null;
459
+ fund_record?: Record<string, any>;
459
460
  metadata: OrderPaymentMetadata;
460
461
  rounding_amount?: string;
461
462
  service_charge?: {
@@ -477,6 +478,7 @@ export interface LoadSalesDetailParams {
477
478
  externalSaleNumber?: string;
478
479
  external_sale_number?: string;
479
480
  forceRemote?: boolean;
481
+ merge?: boolean;
480
482
  }
481
483
  export interface SalesOrderLookupParams {
482
484
  lookup: number | string;
@@ -597,6 +599,14 @@ export interface OrderModuleAPI {
597
599
  getOrderSnapshot: () => OrderSnapshot | null;
598
600
  getOrderSyncState: () => OrderSyncState;
599
601
  getOrderAmountSnapshot: () => OrderAmountSnapshot | null;
602
+ buildCurrentSubmitPayloadForLocalPrint: (params?: {
603
+ cacheId?: string;
604
+ platform?: string;
605
+ businessCode?: string;
606
+ channel?: string;
607
+ type?: string;
608
+ }) => OrderSubmitPayload;
609
+ applyLocalPrintOrderNumbers: (order?: Record<string, any> | null) => Promise<OrderTempOrder>;
600
610
  getTempOrderNote: () => string;
601
611
  updateTempOrderNote: {
602
612
  (note: string): string;
@@ -748,9 +748,9 @@ function buildSubmitPayload(params) {
748
748
  ...tempOrderRest,
749
749
  customer_id: tempOrder.customer_id ?? 1,
750
750
  customer_name: tempOrder.customer_name || "Select a customer",
751
- order_number: null,
752
- shop_order_number: null,
753
- shop_full_order_number: null,
751
+ order_number: tempOrder.order_number ?? null,
752
+ shop_order_number: tempOrder.shop_order_number ?? null,
753
+ shop_full_order_number: tempOrder.shop_full_order_number ?? null,
754
754
  platform: normalizeSubmitPlatform(platform),
755
755
  request_unique_idempotency_token: tempOrder.request_unique_idempotency_token || `${tempOrder.external_sale_number}_${now.getTime()}`,
756
756
  type: submitType,
@@ -825,6 +825,7 @@ function mapPaymentItemToOrderPayment(paymentItem) {
825
825
  ...item.payment_time !== void 0 ? { payment_time: item.payment_time } : {},
826
826
  ...item.wallet_pass_usage_unit !== void 0 ? { wallet_pass_usage_unit: item.wallet_pass_usage_unit } : {},
827
827
  ...item.wallet_pass_use_value !== void 0 ? { wallet_pass_use_value: item.wallet_pass_use_value } : {},
828
+ ...item.fund_record && typeof item.fund_record === "object" && !Array.isArray(item.fund_record) ? { fund_record: { ...item.fund_record } } : {},
828
829
  metadata,
829
830
  ...item.rounding_amount !== void 0 ? { rounding_amount: String(item.rounding_amount) } : {},
830
831
  ...item.service_charge !== void 0 ? { service_charge: item.service_charge } : {},
@@ -37,6 +37,8 @@ declare class Server {
37
37
  private bookingRemoteCache;
38
38
  private readonly BOOKING_REMOTE_CACHE_TTL_MS;
39
39
  private readonly BOOKING_REMOTE_CACHE_MAX_ENTRIES;
40
+ private salesSearchSubscribers;
41
+ private deviceTaskActionsRegistered;
40
42
  private floorPlanQuerySubscribers;
41
43
  private moduleRegistry;
42
44
  constructor(core: PisellCore);
@@ -89,6 +91,8 @@ declare class Server {
89
91
  config: ModuleRegistryConfig;
90
92
  shouldPreload: boolean;
91
93
  }[]>;
94
+ private registerDeviceTaskActions;
95
+ private handleSyncSalesTask;
92
96
  /**
93
97
  * 将普通层 QuotationModule 的报价单计算能力桥接到 Server Products 模块。
94
98
  */
@@ -200,6 +204,84 @@ declare class Server {
200
204
  * 取消订单列表查询订阅(HTTP 路由入口)
201
205
  */
202
206
  private handleUnsubscribeOrderQuery;
207
+ /**
208
+ * 处理 sales 单模块搜索:请求透传后端,仅在 OS 层维护已返回订单号集合。
209
+ *
210
+ * @example
211
+ * await this.handleSalesSearchModule({ url: '/shop/es/search/sales', method: 'post', data: { keyword: 'A' } })
212
+ */
213
+ private handleSalesSearchModule;
214
+ /**
215
+ * 处理 sales 聚合搜索:请求透传后端,仅订阅 sales 分组的已返回订单号。
216
+ *
217
+ * @example
218
+ * await this.handleSalesSearchAggregate({ url: '/shop/es/search', method: 'post', data: { modules: [] } })
219
+ */
220
+ private handleSalesSearchAggregate;
221
+ /**
222
+ * 取消 sales 搜索订阅。
223
+ *
224
+ * @example
225
+ * await this.handleUnsubscribeSalesSearch({ data: { subscriberId: 'global-search-order' } } as any)
226
+ */
227
+ private handleUnsubscribeSalesSearch;
228
+ /**
229
+ * 执行 sales 搜索并登记可见订单号。
230
+ * 搜索参数完全透传后端,OS 不做过滤、筛选、排序。
231
+ *
232
+ * @example
233
+ * const result = await this.handleSalesSearchRequest('single', '/shop/es/search/sales', { keyword: '1001' }, {})
234
+ */
235
+ private handleSalesSearchRequest;
236
+ /**
237
+ * 透传调用后端 sales 搜索接口。
238
+ *
239
+ * @example
240
+ * const res = await this.fetchSalesSearchFromAPI('/shop/es/search/sales', { keyword: '1001' })
241
+ */
242
+ private fetchSalesSearchFromAPI;
243
+ /**
244
+ * 构建搜索订阅签名;页码变化不重置,可继续累计 visibleOrderIds。
245
+ *
246
+ * @example
247
+ * const signature = this.buildSalesSearchSignature('single', { keyword: 'A', page: 2 })
248
+ */
249
+ private buildSalesSearchSignature;
250
+ /**
251
+ * 移除页码参数,保留 page size、keyword、filters、sort 等查询语义参数。
252
+ *
253
+ * @example
254
+ * this.stripSalesSearchPageParams({ page: 2, per_page: 20, keyword: 'A' })
255
+ */
256
+ private stripSalesSearchPageParams;
257
+ /**
258
+ * 提取响应 data,兼容 OS 包装结构与后端直接响应结构。
259
+ *
260
+ * @example
261
+ * const data = this.extractSalesSearchResponseData(result)
262
+ */
263
+ private extractSalesSearchResponseData;
264
+ /**
265
+ * 从搜索响应中提取 sales 命中的订单号。
266
+ *
267
+ * @example
268
+ * const ids = this.extractSalesSearchOrderIds('single', result)
269
+ */
270
+ private extractSalesSearchOrderIds;
271
+ /**
272
+ * 查找聚合搜索响应中的 sales 分组。
273
+ *
274
+ * @example
275
+ * const group = this.findSalesSearchAggregateGroup({ results: [{ module: 'sales' }] })
276
+ */
277
+ private findSalesSearchAggregateGroup;
278
+ /**
279
+ * 从订单或搜索命中项中取订单号。
280
+ *
281
+ * @example
282
+ * const id = this.getSalesSearchOrderId({ order_id: 1001 })
283
+ */
284
+ private getSalesSearchOrderId;
203
285
  /**
204
286
  * 从查询值中提取 YYYY-MM-DD 日期串。
205
287
  *
@@ -292,9 +374,33 @@ declare class Server {
292
374
  private handleUpdateLocalOrder;
293
375
  private handleOrderSalesCheckout;
294
376
  private handleOrderCheckout;
377
+ private getDeviceTaskPlugin;
378
+ private getIdGeneratorPlugin;
379
+ private getAppData;
380
+ private getSmallTicketShopInfo;
381
+ private taskOk;
382
+ private taskFail;
383
+ private taskTimeout;
384
+ private resolveCheckoutTaskDeviceId;
385
+ private buildCheckoutTaskIdempotencyKey;
386
+ private ensureCheckoutOrderNumbers;
387
+ private dispatchCheckoutSyncTask;
388
+ private dispatchPrintOtherReceiptTask;
389
+ private buildPrintOtherReceiptIdempotencyKey;
390
+ private getPrintOrderIdentity;
391
+ private dispatchLocalReceiptPrint;
392
+ private handleLocalPrintOrder;
295
393
  private handleOrderCheckoutSubmit;
296
394
  private handlePendingSyncCheckoutOrder;
297
395
  private buildPendingSyncCheckoutOrder;
396
+ private shouldBuildSmallTicketData;
397
+ private shouldPrintSyncedOrder;
398
+ private hasPaymentStatus;
399
+ private isSalesOrderFullyPaid;
400
+ private sumPaidOrderPayments;
401
+ private toAmountNumber;
402
+ private buildSmallTicketProductMap;
403
+ private withLocalSmallTicketData;
298
404
  private handleOrderSalesDetail;
299
405
  /**
300
406
  * 解析 order_ids 入参,兼容 url query / data 字段、字符串(csv) / 数组两种形态。
@@ -327,6 +433,7 @@ declare class Server {
327
433
  private buildOrderSalesDetailBackendPath;
328
434
  private extractOrderDataFromCheckoutResponse;
329
435
  private normalizeCheckoutResponse;
436
+ private isCheckoutResponseRejected;
330
437
  private extractBackendErrorResponse;
331
438
  private isExplicitBackendErrorResponse;
332
439
  /**
@@ -383,6 +490,35 @@ declare class Server {
383
490
  * 订单数据变更后,遍历订阅者重新计算并通过 callback 推送
384
491
  */
385
492
  private recomputeAndNotifyOrderQuery;
493
+ /**
494
+ * 订单变更后通知 sales 搜索订阅者。
495
+ * 仅回传当前查询已返回订单号集合中的变更订单。
496
+ *
497
+ * @example
498
+ * this.notifySalesSearchSubscribers({ list: [], changedOrders: [order], source: 'pubsub.bodyUpsert' })
499
+ */
500
+ private notifySalesSearchSubscribers;
501
+ /**
502
+ * 从订单变更事件中提取明确 delta。
503
+ *
504
+ * @example
505
+ * const list = this.extractChangedOrdersFromPayload(payload)
506
+ */
507
+ private extractChangedOrdersFromPayload;
508
+ /**
509
+ * 构建与当前搜索接口一致的 delta 响应。
510
+ *
511
+ * @example
512
+ * const response = this.buildSalesSearchDeltaResponse(subscriber, [order])
513
+ */
514
+ private buildSalesSearchDeltaResponse;
515
+ /**
516
+ * 构建聚合搜索接口的 sales 分组 delta 响应。
517
+ *
518
+ * @example
519
+ * const response = this.buildAggregateSalesSearchDeltaResponse(subscriber, [order])
520
+ */
521
+ private buildAggregateSalesSearchDeltaResponse;
386
522
  /**
387
523
  * 预约数据变更后,遍历订阅者重新计算并通过 callback 推送
388
524
  */