@pisell/pisellos 2.2.162 → 2.2.164

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 (116) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +157 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +107 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +191 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.js +23 -22
  32. package/dist/modules/Discount/index.js +4 -3
  33. package/dist/modules/Order/index.d.ts +17 -6
  34. package/dist/modules/Order/index.js +474 -287
  35. package/dist/modules/Order/types.d.ts +32 -12
  36. package/dist/modules/Order/utils.js +9 -8
  37. package/dist/modules/SalesSummary/index.js +4 -2
  38. package/dist/modules/index.d.ts +1 -0
  39. package/dist/modules/index.js +2 -1
  40. package/dist/solution/BaseSales/index.d.ts +38 -7
  41. package/dist/solution/BaseSales/index.js +797 -310
  42. package/dist/solution/BaseSales/types.d.ts +48 -1
  43. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  44. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  45. package/dist/solution/BookingByStep/index.d.ts +2 -2
  46. package/dist/solution/BookingTicket/index.d.ts +121 -1
  47. package/dist/solution/BookingTicket/index.js +401 -72
  48. package/dist/solution/BookingTicket/types.d.ts +2 -0
  49. package/dist/solution/BookingTicket/types.js +3 -0
  50. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  51. package/dist/solution/BookingTicket/utils/addProductDecision.js +326 -0
  52. package/dist/solution/ScanOrder/index.d.ts +9 -3
  53. package/dist/solution/ScanOrder/index.js +231 -128
  54. package/dist/solution/VenueBooking/index.d.ts +4 -2
  55. package/dist/solution/VenueBooking/index.js +103 -55
  56. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  57. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  58. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  59. package/lib/modules/BookingContext/index.d.ts +37 -0
  60. package/lib/modules/BookingContext/index.js +297 -0
  61. package/lib/modules/BookingContext/types.d.ts +102 -0
  62. package/lib/modules/BookingContext/types.js +34 -0
  63. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  64. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +174 -0
  65. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  66. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +115 -0
  67. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  68. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +177 -0
  69. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  70. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  71. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  72. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  73. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  74. package/lib/modules/BookingContext/utils/index.js +43 -0
  75. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  76. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  77. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  78. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  79. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  80. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  81. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  82. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  83. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  84. package/lib/modules/BookingContext/utils/resources.js +377 -0
  85. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  86. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  87. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  88. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  89. package/lib/modules/Customer/index.js +8 -8
  90. package/lib/modules/Discount/index.js +5 -1
  91. package/lib/modules/Order/index.d.ts +17 -6
  92. package/lib/modules/Order/index.js +164 -68
  93. package/lib/modules/Order/types.d.ts +32 -12
  94. package/lib/modules/Order/utils.js +8 -6
  95. package/lib/modules/SalesSummary/index.js +4 -2
  96. package/lib/modules/index.d.ts +1 -0
  97. package/lib/modules/index.js +3 -1
  98. package/lib/solution/BaseSales/index.d.ts +38 -7
  99. package/lib/solution/BaseSales/index.js +304 -14
  100. package/lib/solution/BaseSales/types.d.ts +48 -1
  101. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  102. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  103. package/lib/solution/BookingByStep/index.d.ts +2 -2
  104. package/lib/solution/BookingTicket/index.d.ts +121 -1
  105. package/lib/solution/BookingTicket/index.js +207 -2
  106. package/lib/solution/BookingTicket/types.d.ts +2 -0
  107. package/lib/solution/BookingTicket/types.js +6 -0
  108. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  109. package/lib/solution/BookingTicket/utils/addProductDecision.js +300 -0
  110. package/lib/solution/ScanOrder/index.d.ts +9 -3
  111. package/lib/solution/ScanOrder/index.js +147 -66
  112. package/lib/solution/VenueBooking/index.d.ts +4 -2
  113. package/lib/solution/VenueBooking/index.js +50 -14
  114. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  115. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  116. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ import dayjs from 'dayjs';
2
+ import { getDurationValue } from './flexible';
3
+ export interface TimeSlice {
4
+ label: string;
5
+ value: string;
6
+ }
7
+ export interface DurationSlice {
8
+ label: string;
9
+ value: number;
10
+ }
11
+ export interface TimeSlicesResult {
12
+ timeSlices: TimeSlice[];
13
+ durationSlicesBasedOnTime: DurationSlice[];
14
+ }
15
+ /**
16
+ * 把一天切成等长时间槽,输出 timeSlices(开始时间标签)与 durationSlicesBasedOnTime(基于切片的时长选项)。
17
+ *
18
+ * 与 info2 `sliceDayIntoFiveMinutes` 行为等价;为了不依赖 `locales`,label 输出原始时间字符串('08:00 AM' / '90'),
19
+ * UI 侧需要本地化展示时可基于 value 自行包装。
20
+ *
21
+ * @param config booking config `basic.service_time`,{ value: minutes }
22
+ * @param isDay 是否跨日预约(true 时按 1~30 天切片)
23
+ */
24
+ export declare function sliceDayIntoFiveMinutes(config: {
25
+ value?: number;
26
+ } | undefined | null, isDay?: boolean): TimeSlicesResult;
27
+ /**
28
+ * 取「下一个 duration 选项」:优先用 defaultValue;否则在 array 中找匹配的;找不到取第一个。
29
+ * 与 info2 `findNextDuration` 等价。
30
+ */
31
+ export declare function findNextDuration(current: {
32
+ value?: number;
33
+ } | undefined, array: DurationSlice[], defaultValue?: number): number | undefined;
34
+ /** 取首选 time slice:若指定 date(HH:mm)则找第一个 >= date 的;否则第一个。 */
35
+ export declare function findNextSlice(params: {
36
+ timeSlices: TimeSlice[];
37
+ index?: number;
38
+ date?: string;
39
+ }): string | undefined;
40
+ /** 取 endDate;duration='flexible' 时取 endDate 与店铺营业时间的较小值,否则 startDate + duration 分钟。 */
41
+ export declare function getEndDate(startDate: dayjs.Dayjs, duration: string | number, endDate: any, shopOpeningHours?: string): dayjs.Dayjs;
42
+ export { getDurationValue };
@@ -0,0 +1,124 @@
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/modules/BookingContext/utils/timeSlices.ts
30
+ var timeSlices_exports = {};
31
+ __export(timeSlices_exports, {
32
+ findNextDuration: () => findNextDuration,
33
+ findNextSlice: () => findNextSlice,
34
+ getDurationValue: () => import_flexible.getDurationValue,
35
+ getEndDate: () => getEndDate,
36
+ sliceDayIntoFiveMinutes: () => sliceDayIntoFiveMinutes
37
+ });
38
+ module.exports = __toCommonJS(timeSlices_exports);
39
+ var import_dayjs = __toESM(require("dayjs"));
40
+ var import_flexible = require("./flexible");
41
+ function sliceDayIntoFiveMinutes(config, isDay) {
42
+ const startTime = (0, import_dayjs.default)().startOf("day");
43
+ const endTime = (0, import_dayjs.default)().endOf("day");
44
+ const timeSlice = config && config.value || 5;
45
+ const timeSlices = [];
46
+ const durationSlicesBasedOnTime = [];
47
+ let currentTime = startTime;
48
+ if (isDay) {
49
+ let currentDay = 1;
50
+ while (currentDay <= 30) {
51
+ timeSlices.push({
52
+ label: currentTime.format("hh:mm A"),
53
+ value: currentTime.format("HH:mm")
54
+ });
55
+ durationSlicesBasedOnTime.push({
56
+ label: String(currentDay),
57
+ value: currentDay
58
+ });
59
+ currentDay += 1;
60
+ }
61
+ return { timeSlices, durationSlicesBasedOnTime };
62
+ }
63
+ while (currentTime.isBefore(endTime)) {
64
+ timeSlices.push({
65
+ label: currentTime.format("hh:mm A"),
66
+ value: currentTime.format("HH:mm")
67
+ });
68
+ const nextTime = currentTime.add(timeSlice, "minute");
69
+ const durationValue = nextTime.diff(startTime, "minute");
70
+ durationSlicesBasedOnTime.push({
71
+ label: String(durationValue),
72
+ value: durationValue
73
+ });
74
+ currentTime = nextTime;
75
+ }
76
+ return { timeSlices, durationSlicesBasedOnTime };
77
+ }
78
+ function findNextDuration(current, array, defaultValue) {
79
+ if (defaultValue !== void 0 && defaultValue !== null)
80
+ return defaultValue;
81
+ if (!array || array.length === 0)
82
+ return void 0;
83
+ for (let i = 0; i < array.length; i += 1) {
84
+ if (array[i].value === (current == null ? void 0 : current.value))
85
+ return array[i].value;
86
+ }
87
+ return array[0].value;
88
+ }
89
+ function findNextSlice(params) {
90
+ var _a;
91
+ const { timeSlices, index = 0, date = "" } = params;
92
+ const currentTimeValue = date || (0, import_dayjs.default)().format("HH:mm");
93
+ for (let i = 0; i < timeSlices.length; i += 1) {
94
+ if (timeSlices[i].value !== "now" && timeSlices[i].value >= currentTimeValue) {
95
+ return timeSlices[i].value;
96
+ }
97
+ }
98
+ return (_a = timeSlices[index]) == null ? void 0 : _a.value;
99
+ }
100
+ function getEndDate(startDate, duration, endDate, shopOpeningHours) {
101
+ if (duration === "flexible") {
102
+ let openingDate = (0, import_dayjs.default)(
103
+ `${startDate.format("YYYY-MM-DD")} ${shopOpeningHours || "23:59"}`
104
+ );
105
+ if ((0, import_dayjs.default)(startDate).isAfter(openingDate)) {
106
+ openingDate = openingDate.add(1, "day");
107
+ }
108
+ if (!endDate)
109
+ return openingDate;
110
+ const endDateObj = (0, import_dayjs.default)(endDate);
111
+ if (endDateObj.isAfter(openingDate))
112
+ return openingDate;
113
+ return endDateObj;
114
+ }
115
+ return startDate.add(Number(duration), "minute");
116
+ }
117
+ // Annotate the CommonJS export names for ESM import in node:
118
+ 0 && (module.exports = {
119
+ findNextDuration,
120
+ findNextSlice,
121
+ getDurationValue,
122
+ getEndDate,
123
+ sliceDayIntoFiveMinutes
124
+ });
@@ -169,10 +169,6 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
169
169
  this.store.total = total;
170
170
  this.store.hasMore = page * pageSize < total;
171
171
  this.store.customerList = (0, import_lodash_es.cloneDeep)(customerList);
172
- await this.core.effects.emit(
173
- `${this.name}:onCustomerListUpdate`,
174
- this.store
175
- );
176
172
  this.triggerPaginationChange({
177
173
  page,
178
174
  pageSize,
@@ -192,6 +188,10 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
192
188
  } finally {
193
189
  this.store.loading = false;
194
190
  this.storeChange();
191
+ await this.core.effects.emit(
192
+ `${this.name}:onCustomerListUpdate`,
193
+ this.store
194
+ );
195
195
  }
196
196
  }
197
197
  /**
@@ -372,10 +372,6 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
372
372
  hasMore: this.store.hasMore
373
373
  }
374
374
  );
375
- await this.core.effects.emit(
376
- `${this.name}:onCustomerListUpdate`,
377
- this.store
378
- );
379
375
  this.triggerPaginationChange({
380
376
  page,
381
377
  pageSize,
@@ -396,6 +392,10 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
396
392
  } finally {
397
393
  this.store.loadingMore = false;
398
394
  this.storeChange();
395
+ await this.core.effects.emit(
396
+ `${this.name}:onCustomerListUpdate`,
397
+ this.store
398
+ );
399
399
  }
400
400
  }
401
401
  /**
@@ -97,8 +97,12 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
97
97
  `/order/prepare/config`,
98
98
  params
99
99
  );
100
+ const rawDiscountList = [
101
+ ...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [],
102
+ ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []
103
+ ];
100
104
  const goodPassList = this.filterEnabledDiscountList(
101
- [...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [], ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []]
105
+ rawDiscountList
102
106
  ) || [];
103
107
  return goodPassList;
104
108
  }
@@ -1,9 +1,9 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { OrderModuleAPI, CommitOrderParams, UpdateProductInOrderParams, CheckoutOrderParams, CancelOrderParams, ChangeBookingStatusParams } from './types';
3
+ import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, CheckoutOrderParams, CancelOrderParams, ChangeBookingStatusParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  import { type SubmitPayloadEnhancer } from './utils';
6
- import type { OrderAmountSnapshot, AddProductBookingInput, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView } from './types';
6
+ import type { OrderAmountSnapshot, AddProductBookingInput, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions } from './types';
7
7
  import type { ICustomer } from '../AccountList/types';
8
8
  import type { Discount } from '../Discount/types';
9
9
  import { UnavailableReason } from '../Rules/types';
@@ -43,8 +43,10 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
43
43
  private createDefaultRulesHooks;
44
44
  loadDiscountConfig(params: {
45
45
  customerId: number;
46
- action?: 'create';
47
- }): Promise<void>;
46
+ action?: 'create' | 'edit';
47
+ orderId?: number;
48
+ apply?: boolean;
49
+ }): Promise<Discount[]>;
48
50
  getDiscountList(): Discount[];
49
51
  scanCode(code: string, customerId?: number): Promise<{
50
52
  isAvailable: boolean;
@@ -79,6 +81,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
79
81
  ensureTempOrder(): OrderTempOrder;
80
82
  restoreOrder(): OrderTempOrder;
81
83
  getTempOrder(): OrderTempOrder | null;
84
+ replaceTempOrder(tempOrder: OrderTempOrder, options?: ReplaceTempOrderOptions): Promise<OrderTempOrder>;
82
85
  getOrderIdentity(): OrderIdentitySnapshot | null;
83
86
  getOrderSyncState(): OrderSyncState;
84
87
  getOrderAmountSnapshot(): OrderAmountSnapshot | null;
@@ -89,12 +92,18 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
89
92
  private ensureExtend;
90
93
  private captureProductRuntime;
91
94
  private createLinkedProductAndBooking;
95
+ private getBookingUniqueIdentificationNumber;
96
+ private findBookingIndexByUniqueIdentificationNumber;
97
+ private removeLinkedBookingsForProduct;
92
98
  private getSalesSummary;
93
99
  recalculateSummary(options?: {
94
100
  createIfMissing?: boolean;
95
101
  }): Promise<OrderSummary | null>;
96
102
  getOrderSummary(): Promise<OrderSummary>;
97
103
  updateTempOrderNote(note: string): string;
104
+ updateTempOrderNote(note: string, sync: true): Promise<string>;
105
+ updateTempOrderNote(note: string, sync: boolean): string | Promise<string>;
106
+ private syncTempOrderNoteToRemote;
98
107
  getTempOrderNote(): string;
99
108
  updateTempOrderShopDiscount(amount: string | number): string;
100
109
  updateTempOrderBuzzer(buzzer: string): string;
@@ -147,7 +156,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
147
156
  private shouldMergeProductToOrder;
148
157
  addProductToOrder(product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput): Promise<OrderProduct[]>;
149
158
  private hasGoodPassDiscount;
150
- updateProductInOrder(params: UpdateProductInOrderParams): Promise<OrderProduct[]>;
159
+ updateOrderProduct(params: UpdateOrderProductParams): Promise<OrderProduct[]>;
160
+ updateOrderBooking(params: UpdateOrderBookingParams): any[];
151
161
  removeProductFromOrder(identity: OrderProductIdentity): Promise<OrderProduct[]>;
152
162
  /**
153
163
  * 提交当前 Sales tempOrder。
@@ -220,8 +230,9 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
220
230
  hydrateTempOrderFromRecord(record: Record<string, any>, options?: {
221
231
  recalcOnHydrate?: boolean;
222
232
  }): Promise<OrderTempOrder>;
233
+ private normalizeTempOrderForRuntime;
223
234
  private normalizeHydratedOrderProduct;
224
235
  getLastOrderInfo(): Record<string, any> | undefined;
225
236
  getOrderInfo(order_id: number): Promise<any>;
226
237
  }
227
- export type { UpdateProductInOrderParams } from './types';
238
+ export type { UpdateOrderBookingParams, UpdateOrderProductParams } from './types';
@@ -174,21 +174,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
174
174
  }
175
175
  // ─── Discount: 公共 API ───
176
176
  async loadDiscountConfig(params) {
177
- var _a, _b, _c, _d;
178
- const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
177
+ var _a, _b, _c, _d, _e, _f;
178
+ const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
179
+ const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
179
180
  customer_id: params.customerId,
180
- action: params.action || "create",
181
+ action: params.action || (orderId ? "edit" : "create"),
181
182
  with_good_pass: 1,
182
183
  with_discount_card: 1,
183
184
  with_wallet_pass_holder: 1,
184
- request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
185
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
186
+ ...orderId ? { order_id: orderId } : {}
185
187
  }));
186
188
  if (discountList) {
187
- (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
189
+ await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
190
+ await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
188
191
  }
189
- if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
192
+ if (params.apply !== false && ((_f = (_e = this.store.tempOrder) == null ? void 0 : _e.products) == null ? void 0 : _f.length)) {
190
193
  this.applyDiscount();
191
194
  }
195
+ return this.getDiscountList();
192
196
  }
193
197
  getDiscountList() {
194
198
  var _a;
@@ -568,6 +572,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
568
572
  getTempOrder() {
569
573
  return this.store.tempOrder;
570
574
  }
575
+ async replaceTempOrder(tempOrder, options) {
576
+ if (!(0, import_utils.isTempOrder)(tempOrder)) {
577
+ throw new Error("无效的 tempOrder 数据");
578
+ }
579
+ const nextTempOrder = this.normalizeTempOrderForRuntime(
580
+ (0, import_lodash_es.cloneDeep)(tempOrder),
581
+ { ensureIdentity: false }
582
+ );
583
+ this.store.tempOrder = nextTempOrder;
584
+ if ((options == null ? void 0 : options.recalculateSummary) !== false) {
585
+ await this.recalculateSummary({ createIfMissing: false });
586
+ } else {
587
+ this.store.summary = (0, import_utils.createEmptySummary)();
588
+ }
589
+ if ((options == null ? void 0 : options.persist) !== false) {
590
+ this.persistTempOrder();
591
+ }
592
+ if (options == null ? void 0 : options.saveDraft) {
593
+ await this.saveDraft();
594
+ }
595
+ return nextTempOrder;
596
+ }
571
597
  getOrderIdentity() {
572
598
  var _a;
573
599
  const tempOrder = this.store.tempOrder;
@@ -716,6 +742,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
716
742
  }
717
743
  };
718
744
  }
745
+ getBookingUniqueIdentificationNumber(booking) {
746
+ var _a;
747
+ const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
748
+ if (uid === void 0 || uid === null || uid === "")
749
+ return null;
750
+ return String(uid);
751
+ }
752
+ findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
753
+ return (tempOrder.bookings || []).findIndex((booking) => {
754
+ return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
755
+ });
756
+ }
757
+ removeLinkedBookingsForProduct(tempOrder, product) {
758
+ var _a, _b;
759
+ const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
760
+ const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
761
+ if (!productUid && !bookingUid)
762
+ return;
763
+ tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
764
+ const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
765
+ if (bookingUid && currentBookingUid === String(bookingUid))
766
+ return false;
767
+ if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
768
+ return false;
769
+ return true;
770
+ });
771
+ }
719
772
  // ─── TempOrder: 金额汇总 ───
720
773
  getSalesSummary() {
721
774
  if (!this.salesSummaryModuleName)
@@ -775,13 +828,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
775
828
  this.persistTempOrder();
776
829
  return summary;
777
830
  }
778
- // ─── TempOrder: 备注 ───
779
- updateTempOrderNote(note) {
831
+ updateTempOrderNote(note, sync = false) {
780
832
  const tempOrder = this.ensureTempOrder();
781
833
  tempOrder.note = String(note || "");
782
834
  this.persistTempOrder();
835
+ if (sync) {
836
+ const orderId = tempOrder.order_id;
837
+ if (!orderId)
838
+ return tempOrder.note;
839
+ return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
840
+ }
783
841
  return tempOrder.note;
784
842
  }
843
+ async syncTempOrderNoteToRemote(orderId, note) {
844
+ await this.request.put(`/order/order/${orderId}/note`, { note });
845
+ return note;
846
+ }
785
847
  getTempOrderNote() {
786
848
  var _a;
787
849
  return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
@@ -1125,15 +1187,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1125
1187
  (item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
1126
1188
  );
1127
1189
  }
1128
- async updateProductInOrder(params) {
1129
- var _a, _b, _c, _d, _e;
1190
+ async updateOrderProduct(params) {
1191
+ var _a, _b, _c, _d, _e, _f, _g;
1130
1192
  const {
1131
1193
  product_id,
1132
1194
  product_variant_id,
1133
1195
  updates,
1134
1196
  unique_identification_number,
1197
+ identity_key,
1135
1198
  product_option_item,
1136
- product_bundle
1199
+ product_bundle,
1200
+ booking
1137
1201
  } = params;
1138
1202
  const tempOrder = this.ensureTempOrder();
1139
1203
  const identityLookup = {
@@ -1143,6 +1207,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1143
1207
  if (unique_identification_number !== void 0) {
1144
1208
  identityLookup.unique_identification_number = unique_identification_number;
1145
1209
  }
1210
+ if (identity_key !== void 0) {
1211
+ identityLookup.identity_key = identity_key;
1212
+ }
1146
1213
  if (product_option_item !== void 0)
1147
1214
  identityLookup.product_option_item = product_option_item;
1148
1215
  if (product_bundle !== void 0)
@@ -1174,23 +1241,85 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1174
1241
  delete nextProduct.metadata.main_product_original_price;
1175
1242
  delete nextProduct.metadata.price_schema_version;
1176
1243
  }
1177
- tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1244
+ let normalizedProduct = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1245
+ if (booking) {
1246
+ const productUid = String(
1247
+ ((_e = normalizedProduct.metadata) == null ? void 0 : _e.unique_identification_number) || ((_f = targetProduct.metadata) == null ? void 0 : _f.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1248
+ );
1249
+ normalizedProduct.metadata = {
1250
+ ...normalizedProduct.metadata || {},
1251
+ unique_identification_number: productUid
1252
+ };
1253
+ const linked = this.createLinkedProductAndBooking({
1254
+ product: {
1255
+ ...normalizedProduct,
1256
+ unique_identification_number: productUid
1257
+ },
1258
+ booking
1259
+ });
1260
+ this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
1261
+ normalizedProduct = {
1262
+ ...normalizedProduct,
1263
+ booking_uid: linked.bookingUid,
1264
+ metadata: {
1265
+ ...normalizedProduct.metadata || {},
1266
+ booking_uid: linked.bookingUid,
1267
+ unique_identification_number: productUid
1268
+ }
1269
+ };
1270
+ tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
1271
+ }
1272
+ tempOrder.products[productIndex] = normalizedProduct;
1178
1273
  this.captureProductRuntime(
1179
1274
  tempOrder,
1180
1275
  updates,
1181
1276
  tempOrder.products[productIndex],
1182
- (_e = tempOrder.products[productIndex].metadata) == null ? void 0 : _e.unique_identification_number
1277
+ (_g = tempOrder.products[productIndex].metadata) == null ? void 0 : _g.unique_identification_number
1183
1278
  );
1184
1279
  this.applyDiscount();
1185
1280
  await this.recalculateSummary({ createIfMissing: true });
1186
1281
  this.persistTempOrder();
1187
1282
  return tempOrder.products;
1188
1283
  }
1189
- async removeProductFromOrder(identity) {
1284
+ updateOrderBooking(params) {
1285
+ const { unique_identification_number, updates } = params;
1190
1286
  const tempOrder = this.ensureTempOrder();
1191
- tempOrder.products = tempOrder.products.filter(
1192
- (item) => !(0, import_utils3.isIdentityMatch)(item, identity)
1287
+ const bookingUid = String(unique_identification_number || "");
1288
+ const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
1289
+ tempOrder,
1290
+ bookingUid
1193
1291
  );
1292
+ if (!bookingUid || bookingIndex === -1) {
1293
+ throw new Error("[Order] 目标 booking 不存在,无法更新");
1294
+ }
1295
+ const targetBooking = tempOrder.bookings[bookingIndex] || {};
1296
+ const nextBooking = {
1297
+ ...targetBooking,
1298
+ ...updates,
1299
+ metadata: {
1300
+ ...targetBooking.metadata || {},
1301
+ ...updates.metadata || {},
1302
+ unique_identification_number: bookingUid
1303
+ }
1304
+ };
1305
+ nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
1306
+ nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
1307
+ tempOrder.bookings[bookingIndex] = nextBooking;
1308
+ this.persistTempOrder();
1309
+ return tempOrder.bookings;
1310
+ }
1311
+ async removeProductFromOrder(identity) {
1312
+ const tempOrder = this.ensureTempOrder();
1313
+ const removedProducts = [];
1314
+ tempOrder.products = tempOrder.products.filter((item) => {
1315
+ const shouldRemove = (0, import_utils3.isIdentityMatch)(item, identity);
1316
+ if (shouldRemove)
1317
+ removedProducts.push(item);
1318
+ return !shouldRemove;
1319
+ });
1320
+ for (const product of removedProducts) {
1321
+ this.removeLinkedBookingsForProduct(tempOrder, product);
1322
+ }
1194
1323
  this.applyDiscount();
1195
1324
  await this.recalculateSummary({ createIfMissing: true });
1196
1325
  this.persistTempOrder();
@@ -1639,53 +1768,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1639
1768
  */
1640
1769
  async hydrateTempOrderFromRecord(record, options) {
1641
1770
  const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
1642
- const defaults = this.createDefaultTempOrderInstance();
1771
+ const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
1772
+ ensureIdentity: true
1773
+ });
1774
+ this.store.tempOrder = nextTempOrder;
1775
+ this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1776
+ this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1777
+ if (options == null ? void 0 : options.recalcOnHydrate) {
1778
+ await this.recalculateSummary({ createIfMissing: false });
1779
+ }
1780
+ this.persistTempOrder();
1781
+ return nextTempOrder;
1782
+ }
1783
+ normalizeTempOrderForRuntime(raw, options) {
1643
1784
  const nextTempOrder = {
1644
- ...defaults
1785
+ ...this.createDefaultTempOrderInstance(),
1786
+ ...raw || {}
1645
1787
  };
1646
- const TEMP_ORDER_KEYS = [
1647
- "order_id",
1648
- "external_sale_number",
1649
- "order_number",
1650
- "shop_order_number",
1651
- "shop_full_order_number",
1652
- "type",
1653
- "business_code",
1654
- "platform",
1655
- "sales_channel",
1656
- "order_sales_channel",
1657
- "status",
1658
- "payment_status",
1659
- "shipping_status",
1660
- "customer_id",
1661
- "customer_name",
1662
- "country_calling_code",
1663
- "phone",
1664
- "email",
1665
- "customer",
1666
- "is_price_include_tax",
1667
- "tax_title",
1668
- "tax_country_code",
1669
- "currency_code",
1670
- "currency_symbol",
1671
- "currency_format",
1672
- "is_deposit",
1673
- "deposit_amount",
1674
- "shop_discount",
1675
- "surcharge_fee",
1676
- "note",
1677
- "buzzer",
1678
- "delivery_type",
1679
- "table_number",
1680
- "schedule_date",
1681
- "created_at",
1682
- "request_unique_idempotency_token"
1683
- ];
1684
- TEMP_ORDER_KEYS.forEach((key) => {
1685
- if (raw[key] !== void 0) {
1686
- nextTempOrder[key] = raw[key];
1687
- }
1688
- });
1788
+ delete nextTempOrder.summary;
1789
+ delete nextTempOrder.lastOrderInfo;
1689
1790
  nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
1690
1791
  nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
1691
1792
  nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
@@ -1704,14 +1805,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1704
1805
  ...raw._extend,
1705
1806
  productsByUid: raw._extend.productsByUid || {}
1706
1807
  } : { productsByUid: {} };
1707
- this.ensureExternalSaleNumber(nextTempOrder);
1708
- this.store.tempOrder = nextTempOrder;
1709
- this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1710
- this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1711
- if (options == null ? void 0 : options.recalcOnHydrate) {
1712
- await this.recalculateSummary({ createIfMissing: false });
1808
+ if ((options == null ? void 0 : options.ensureIdentity) !== false) {
1809
+ this.ensureExternalSaleNumber(nextTempOrder);
1713
1810
  }
1714
- this.persistTempOrder();
1715
1811
  return nextTempOrder;
1716
1812
  }
1717
1813
  normalizeHydratedOrderProduct(product) {