@pisell/pisellos 0.0.490 → 0.0.492

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 (157) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/model/strategy/adapter/index.d.ts +2 -0
  4. package/dist/model/strategy/adapter/index.js +3 -1
  5. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
  6. package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
  7. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  8. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  9. package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
  10. package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
  11. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  12. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  13. package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
  14. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  15. package/dist/model/strategy/adapter/walletPass/utils.js +2 -2
  16. package/dist/modules/OpenData/index.d.ts +23 -0
  17. package/dist/modules/OpenData/index.js +167 -0
  18. package/dist/modules/OpenData/types.d.ts +73 -0
  19. package/dist/modules/OpenData/types.js +1 -0
  20. package/dist/modules/OpenData/utils.d.ts +2 -0
  21. package/dist/modules/OpenData/utils.js +75 -0
  22. package/dist/modules/Order/index.d.ts +53 -1
  23. package/dist/modules/Order/index.js +717 -27
  24. package/dist/modules/Order/types.d.ts +144 -12
  25. package/dist/modules/Order/utils.d.ts +25 -0
  26. package/dist/modules/Order/utils.js +214 -1
  27. package/dist/modules/Product/utils.js +2 -2
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -1
  30. package/dist/modules/Quotation/index.d.ts +40 -0
  31. package/dist/modules/Quotation/index.js +212 -0
  32. package/dist/modules/Quotation/types.d.ts +42 -0
  33. package/dist/modules/Quotation/types.js +1 -0
  34. package/dist/modules/Rules/index.js +2 -2
  35. package/dist/modules/SalesSummary/index.d.ts +63 -0
  36. package/dist/modules/SalesSummary/index.js +174 -0
  37. package/dist/modules/SalesSummary/types.d.ts +59 -0
  38. package/dist/modules/SalesSummary/types.js +1 -0
  39. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  40. package/dist/modules/SalesSummary/utils.js +506 -0
  41. package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
  42. package/dist/modules/ScanOrderLogger/index.js +161 -0
  43. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  44. package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
  45. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  46. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  47. package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
  48. package/dist/modules/ScanOrderLogger/types.js +1 -0
  49. package/dist/modules/Summary/utils.d.ts +3 -3
  50. package/dist/modules/Summary/utils.js +4 -4
  51. package/dist/modules/index.d.ts +4 -0
  52. package/dist/modules/index.js +5 -1
  53. package/dist/solution/BookingByStep/index.d.ts +1 -1
  54. package/dist/solution/BookingByStep/types.d.ts +3 -1
  55. package/dist/solution/BookingByStep/types.js +5 -1
  56. package/dist/solution/ScanOrder/index.d.ts +90 -0
  57. package/dist/solution/ScanOrder/index.js +1853 -0
  58. package/dist/solution/ScanOrder/types.d.ts +210 -0
  59. package/dist/solution/ScanOrder/types.js +16 -0
  60. package/dist/solution/ScanOrder/utils.d.ts +93 -0
  61. package/dist/solution/ScanOrder/utils.js +378 -0
  62. package/dist/solution/VenueBooking/index.d.ts +159 -0
  63. package/dist/solution/VenueBooking/index.js +2773 -0
  64. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  65. package/dist/solution/VenueBooking/types.d.ts +123 -0
  66. package/dist/solution/VenueBooking/types.js +21 -0
  67. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
  68. package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
  69. package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
  70. package/dist/solution/VenueBooking/utils/resource.js +94 -0
  71. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +18 -0
  72. package/dist/solution/VenueBooking/utils/slotMerge.js +128 -0
  73. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  74. package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
  75. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  76. package/dist/solution/VenueBooking/utils.js +1 -0
  77. package/dist/solution/index.d.ts +2 -0
  78. package/dist/solution/index.js +3 -1
  79. package/lib/apis/picoding.d.ts +0 -0
  80. package/lib/apis/picoding.js +0 -0
  81. package/lib/model/strategy/adapter/index.d.ts +2 -0
  82. package/lib/model/strategy/adapter/index.js +6 -0
  83. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
  84. package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
  85. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  86. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  87. package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
  88. package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
  89. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  90. package/lib/model/strategy/adapter/itemRule/index.js +58 -0
  91. package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
  92. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  93. package/lib/model/strategy/adapter/walletPass/utils.js +2 -2
  94. package/lib/modules/OpenData/index.d.ts +23 -0
  95. package/lib/modules/OpenData/index.js +116 -0
  96. package/lib/modules/OpenData/types.d.ts +73 -0
  97. package/lib/modules/OpenData/types.js +17 -0
  98. package/lib/modules/OpenData/utils.d.ts +2 -0
  99. package/lib/modules/OpenData/utils.js +111 -0
  100. package/lib/modules/Order/index.d.ts +53 -1
  101. package/lib/modules/Order/index.js +389 -1
  102. package/lib/modules/Order/types.d.ts +144 -12
  103. package/lib/modules/Order/utils.d.ts +25 -0
  104. package/lib/modules/Order/utils.js +217 -0
  105. package/lib/modules/Product/utils.js +2 -2
  106. package/lib/modules/ProductList/index.d.ts +1 -1
  107. package/lib/modules/ProductList/index.js +2 -1
  108. package/lib/modules/Quotation/index.d.ts +40 -0
  109. package/lib/modules/Quotation/index.js +128 -0
  110. package/lib/modules/Quotation/types.d.ts +42 -0
  111. package/lib/modules/Quotation/types.js +17 -0
  112. package/lib/modules/Rules/index.js +1 -1
  113. package/lib/modules/SalesSummary/index.d.ts +63 -0
  114. package/lib/modules/SalesSummary/index.js +105 -0
  115. package/lib/modules/SalesSummary/types.d.ts +59 -0
  116. package/lib/modules/SalesSummary/types.js +17 -0
  117. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  118. package/lib/modules/SalesSummary/utils.js +445 -0
  119. package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
  120. package/lib/modules/ScanOrderLogger/index.js +135 -0
  121. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  122. package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
  123. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  124. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  125. package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
  126. package/lib/modules/ScanOrderLogger/types.js +17 -0
  127. package/lib/modules/Summary/utils.d.ts +3 -3
  128. package/lib/modules/Summary/utils.js +4 -4
  129. package/lib/modules/index.d.ts +4 -0
  130. package/lib/modules/index.js +9 -1
  131. package/lib/solution/BookingByStep/index.d.ts +1 -1
  132. package/lib/solution/BookingByStep/types.d.ts +3 -1
  133. package/lib/solution/BookingByStep/types.js +10 -0
  134. package/lib/solution/ScanOrder/index.d.ts +90 -0
  135. package/lib/solution/ScanOrder/index.js +1071 -0
  136. package/lib/solution/ScanOrder/types.d.ts +210 -0
  137. package/lib/solution/ScanOrder/types.js +36 -0
  138. package/lib/solution/ScanOrder/utils.d.ts +93 -0
  139. package/lib/solution/ScanOrder/utils.js +342 -0
  140. package/lib/solution/VenueBooking/index.d.ts +159 -0
  141. package/lib/solution/VenueBooking/index.js +1508 -0
  142. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  143. package/lib/solution/VenueBooking/types.d.ts +123 -0
  144. package/lib/solution/VenueBooking/types.js +44 -0
  145. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
  146. package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
  147. package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
  148. package/lib/solution/VenueBooking/utils/resource.js +80 -0
  149. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +18 -0
  150. package/lib/solution/VenueBooking/utils/slotMerge.js +156 -0
  151. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  152. package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
  153. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  154. package/lib/solution/VenueBooking/utils.js +69 -0
  155. package/lib/solution/index.d.ts +2 -0
  156. package/lib/solution/index.js +5 -1
  157. package/package.json +1 -1
@@ -29,12 +29,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/modules/Order/utils.ts
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
+ buildSubmitPayload: () => buildSubmitPayload,
33
+ createDefaultTempOrder: () => createDefaultTempOrder,
34
+ createEmptySummary: () => import_utils2.createEmptySummary,
35
+ createUuidV4: () => createUuidV4,
36
+ formatDateTime: () => formatDateTime,
37
+ formatV1Product: () => formatV1Product,
32
38
  generateDuration: () => generateDuration,
33
39
  getAllDiscountList: () => getAllDiscountList,
40
+ isTempOrder: () => isTempOrder,
34
41
  mergeRelationForms: () => mergeRelationForms
35
42
  });
36
43
  module.exports = __toCommonJS(utils_exports);
37
44
  var import_dayjs = __toESM(require("dayjs"));
45
+ var import_utils = require("../../solution/ScanOrder/utils");
46
+ var import_utils2 = require("../../solution/ScanOrder/utils");
38
47
  var generateDuration = (cartItem) => {
39
48
  const startDate = (0, import_dayjs.default)(`${cartItem.start_date} ${cartItem.start_time}`);
40
49
  const endDate = (0, import_dayjs.default)(`${cartItem.end_date} ${cartItem.end_time}`);
@@ -65,9 +74,217 @@ var getAllDiscountList = (cartItem) => {
65
74
  });
66
75
  return discountList;
67
76
  };
77
+ function createUuidV4() {
78
+ const template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
79
+ return template.replace(/[xy]/g, (char) => {
80
+ const randomValue = Math.floor(Math.random() * 16);
81
+ const value = char === "x" ? randomValue : randomValue & 3 | 8;
82
+ return value.toString(16);
83
+ });
84
+ }
85
+ function isTempOrder(data) {
86
+ if (!data || typeof data !== "object")
87
+ return false;
88
+ if (!Array.isArray(data.products))
89
+ return false;
90
+ return true;
91
+ }
92
+ function formatDateTime(date) {
93
+ const pad = (value) => value.toString().padStart(2, "0");
94
+ const year = date.getFullYear();
95
+ const month = pad(date.getMonth() + 1);
96
+ const day = pad(date.getDate());
97
+ const hours = pad(date.getHours());
98
+ const minutes = pad(date.getMinutes());
99
+ const seconds = pad(date.getSeconds());
100
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
101
+ }
102
+ function normalizeSubmitPlatform(platform) {
103
+ return (platform == null ? void 0 : platform.toLowerCase()) === "pc" ? "PC" : "H5";
104
+ }
105
+ function normalizeSubmitProduct(product) {
106
+ const { _origin, identity_key, ...submitProduct } = product;
107
+ const rawMetadata = submitProduct.metadata || {};
108
+ const bookingUid = rawMetadata.booking_uid;
109
+ const cleanMetadata = {};
110
+ if (rawMetadata.unique_identification_number) {
111
+ cleanMetadata.unique_identification_number = rawMetadata.unique_identification_number;
112
+ }
113
+ return {
114
+ ...submitProduct,
115
+ ...bookingUid ? { booking_uid: bookingUid } : {},
116
+ product_option_item: submitProduct.product_option_item || [],
117
+ discount_list: submitProduct.discount_list || [],
118
+ product_bundle: submitProduct.product_bundle || [],
119
+ metadata: cleanMetadata
120
+ };
121
+ }
122
+ var DEFAULT_TABLE_OCCUPANCY_DURATION = 20;
123
+ function resolveTableOccupancyDuration(tempOrder) {
124
+ var _a, _b, _c, _d;
125
+ const metadata = tempOrder.metadata || {};
126
+ const candidates = [
127
+ metadata.table_occupancy_duration,
128
+ metadata.booking_duration,
129
+ metadata.table_duration,
130
+ metadata.duration,
131
+ (_a = metadata.table_config) == null ? void 0 : _a.occupancy_duration,
132
+ (_b = metadata.tableConfig) == null ? void 0 : _b.occupancy_duration,
133
+ (_c = metadata.resource_config) == null ? void 0 : _c.occupancy_duration,
134
+ (_d = metadata.resourceConfig) == null ? void 0 : _d.occupancy_duration
135
+ ];
136
+ for (const value of candidates) {
137
+ const duration = Number(value);
138
+ if (Number.isFinite(duration) && duration > 0) {
139
+ return Math.floor(duration);
140
+ }
141
+ }
142
+ return DEFAULT_TABLE_OCCUPANCY_DURATION;
143
+ }
144
+ function createDefaultTempOrder(params) {
145
+ const summary = params.summary || (0, import_utils.createEmptySummary)();
146
+ return {
147
+ order_id: null,
148
+ relation_id: void 0,
149
+ table_form_id: void 0,
150
+ resource_id: void 0,
151
+ order_number: "",
152
+ shop_order_number: "",
153
+ type: "appointment_booking",
154
+ business_code: "appointment_booking",
155
+ platform: "h5",
156
+ sales_channel: "my_pisel",
157
+ order_sales_channel: "online_store",
158
+ status: "normal",
159
+ payment_status: "payment_processing",
160
+ shipping_status: "unfulfilled",
161
+ customer_id: null,
162
+ customer_name: "",
163
+ country_calling_code: "",
164
+ phone: "",
165
+ email: "",
166
+ is_price_include_tax: 1,
167
+ tax_title: "",
168
+ tax_country_code: "",
169
+ currency_code: "",
170
+ currency_symbol: "",
171
+ currency_format: "symbol_first",
172
+ is_deposit: 0,
173
+ deposit_amount: "0.00",
174
+ shop_discount: "0.00",
175
+ surcharge_fee: "0.00",
176
+ note: "",
177
+ schedule_date: params.now,
178
+ created_at: params.now,
179
+ products: [],
180
+ bookings: [],
181
+ payments: [],
182
+ surcharges: [],
183
+ discount_list: [],
184
+ relation_forms: [],
185
+ contacts: [],
186
+ contacts_info: [],
187
+ holder: null,
188
+ summary,
189
+ metadata: {}
190
+ };
191
+ }
192
+ function buildSubmitPayload(params) {
193
+ const { tempOrder, cacheId, now = /* @__PURE__ */ new Date() } = params;
194
+ const scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
195
+ const summary = tempOrder.summary || (0, import_utils.createEmptySummary)();
196
+ const relationId = tempOrder.relation_id;
197
+ const tableFormId = tempOrder.table_form_id;
198
+ const bookingUuid = createUuidV4();
199
+ const bookingStart = (0, import_dayjs.default)(now);
200
+ const bookingDuration = resolveTableOccupancyDuration(tempOrder);
201
+ const bookingEnd = bookingStart.add(bookingDuration, "minute");
202
+ const bookings = relationId && tableFormId ? [{
203
+ relation_id: relationId,
204
+ form_id: tableFormId,
205
+ start_time: bookingStart.format("HH:mm"),
206
+ start_date: bookingStart.format("YYYY-MM-DD"),
207
+ end_time: bookingEnd.format("HH:mm"),
208
+ end_date: bookingEnd.format("YYYY-MM-DD"),
209
+ duration: bookingDuration,
210
+ metadata: {
211
+ unique_identification_number: bookingUuid,
212
+ collect_pax: 1
213
+ },
214
+ select_date: bookingStart.format("YYYY-MM-DD"),
215
+ is_all: false,
216
+ "like_status": "common",
217
+ "schedule_id": 0,
218
+ "relation_type": "form",
219
+ "number": 1
220
+ }] : tempOrder.bookings || [];
221
+ const formRecordIds = relationId && tableFormId ? [{
222
+ form_id: tableFormId,
223
+ form_record_ids: [relationId]
224
+ }] : void 0;
225
+ const { created_at: _createdAt, ...tempOrderWithoutCreatedAt } = tempOrder;
226
+ return {
227
+ ...tempOrderWithoutCreatedAt,
228
+ platform: normalizeSubmitPlatform(tempOrder.platform),
229
+ request_unique_idempotency_token: cacheId,
230
+ type: tempOrder.type || "table-order",
231
+ business_code: tempOrder.business_code || "table-order",
232
+ sales_channel: tempOrder.sales_channel || "my_pisel",
233
+ order_sales_channel: tempOrder.order_sales_channel || "online_store",
234
+ status: tempOrder.status || "normal",
235
+ payment_status: tempOrder.payment_status || "payment_processing",
236
+ // shipping_status: tempOrder.shipping_status || 'unfulfilled',
237
+ is_price_include_tax: tempOrder.is_price_include_tax ?? 1,
238
+ currency_format: tempOrder.currency_format || "symbol_first",
239
+ is_deposit: tempOrder.is_deposit ?? 0,
240
+ deposit_amount: tempOrder.deposit_amount || "0.00",
241
+ shop_discount: tempOrder.shop_discount || "0.00",
242
+ surcharge_fee: summary.surcharge_fee || tempOrder.surcharge_fee || "0.00",
243
+ note: tempOrder.note || "",
244
+ schedule_date: scheduleDate,
245
+ bookings,
246
+ payments: tempOrder.payments || [],
247
+ surcharges: tempOrder.surcharges || [],
248
+ // discount_list: tempOrder.discount_list || [],
249
+ relation_forms: tempOrder.relation_forms || [],
250
+ form_record_ids: formRecordIds,
251
+ // contacts: tempOrder.contacts || [],
252
+ contacts_info: tempOrder.contacts_info || [],
253
+ // holder: tempOrder.holder || null,
254
+ // summary,
255
+ metadata: {
256
+ ...tempOrder.metadata
257
+ },
258
+ products: (tempOrder.products || []).map(
259
+ (product) => normalizeSubmitProduct(product)
260
+ )
261
+ };
262
+ }
263
+ function formatV1Product(products) {
264
+ return products.map((product) => {
265
+ return {
266
+ bundle: product.product_bundle,
267
+ key: product.product_id,
268
+ option: product.product_option_item,
269
+ product_id: product.product_id,
270
+ product_variant_id: product.product_variant_id,
271
+ quantity: product.num,
272
+ rowKey: product.product_id,
273
+ session: null,
274
+ unique: createUuidV4()
275
+ };
276
+ });
277
+ }
68
278
  // Annotate the CommonJS export names for ESM import in node:
69
279
  0 && (module.exports = {
280
+ buildSubmitPayload,
281
+ createDefaultTempOrder,
282
+ createEmptySummary,
283
+ createUuidV4,
284
+ formatDateTime,
285
+ formatV1Product,
70
286
  generateDuration,
71
287
  getAllDiscountList,
288
+ isTempOrder,
72
289
  mergeRelationForms
73
290
  });
@@ -25,10 +25,10 @@ __export(utils_exports, {
25
25
  module.exports = __toCommonJS(utils_exports);
26
26
  function isNormalProduct(product) {
27
27
  var _a;
28
- if (product.duration) {
28
+ if (product == null ? void 0 : product.duration) {
29
29
  return false;
30
30
  }
31
- if ((_a = product["schedule.ids"]) == null ? void 0 : _a.length) {
31
+ if ((_a = product == null ? void 0 : product["schedule.ids"]) == null ? void 0 : _a.length) {
32
32
  return false;
33
33
  }
34
34
  return true;
@@ -16,10 +16,10 @@ export declare class ProductList extends BaseModule implements Module {
16
16
  product_ids?: number[];
17
17
  collection?: number | string[];
18
18
  schedule_date?: string;
19
+ schedule_datetime?: string;
19
20
  cacheId?: string;
20
21
  customer_id?: number;
21
22
  menu_list_ids?: number[];
22
- schedule_datetime?: string;
23
23
  with_count?: string[];
24
24
  with_schedule?: number;
25
25
  }, options?: {
@@ -100,7 +100,8 @@ var ProductList = class extends import_BaseModule.BaseModule {
100
100
  application_code: (_b = this.otherParams) == null ? void 0 : _b.channel,
101
101
  is_eject: 1
102
102
  },
103
- { osServer: true, callback: options == null ? void 0 : options.callback, subscriberId: options == null ? void 0 : options.subscriberId }
103
+ { osServer: true, callback: options == null ? void 0 : options.callback, subscriberId: options == null ? void 0 : options.subscriberId, useCache: true, customToast: () => {
104
+ } }
104
105
  );
105
106
  const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
106
107
  this.addProduct(sortedList);
@@ -0,0 +1,40 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import type { QuotationItem } from './types';
4
+ export type { QuotationItem, QuotationProductData, QuotationSchedule, QuotationState } from './types';
5
+ export declare class QuotationModule extends BaseModule implements Module {
6
+ protected defaultName: string;
7
+ protected defaultVersion: string;
8
+ private request;
9
+ private store;
10
+ constructor(name?: string, version?: string);
11
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
12
+ loadQuotations(params?: {
13
+ channel?: string;
14
+ }): Promise<void>;
15
+ getQuotationList(): QuotationItem[];
16
+ /**
17
+ * Look up the quotation price for a specific product (+ optional variant) at a given datetime.
18
+ * Returns the price as a string (e.g. "300.00"), or null if no quotation applies.
19
+ *
20
+ * Priority: iterates quotations already sorted by `sort` ascending (lowest = highest priority).
21
+ * First matching quotation whose schedule covers `datetime` and whose product_data contains
22
+ * the requested productId wins.
23
+ */
24
+ getPriceForProduct(params: {
25
+ productId: number;
26
+ variantId?: number;
27
+ datetime: string;
28
+ }): string | null;
29
+ /**
30
+ * Batch pre-compute quotation prices for a set of products across multiple time points.
31
+ * Key format: `${productId}:${timePoint}`
32
+ * This avoids repeated schedule matching when the same product appears in multiple resource rows.
33
+ */
34
+ buildProductPriceMap(params: {
35
+ productIds: number[];
36
+ timePoints: string[];
37
+ }): Map<string, string | null>;
38
+ private isQuotationActiveAt;
39
+ private findProductData;
40
+ }
@@ -0,0 +1,128 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/Quotation/index.ts
20
+ var Quotation_exports = {};
21
+ __export(Quotation_exports, {
22
+ QuotationModule: () => QuotationModule
23
+ });
24
+ module.exports = __toCommonJS(Quotation_exports);
25
+ var import_BaseModule = require("../BaseModule");
26
+ var import_getDateIsInSchedule = require("../Schedule/getDateIsInSchedule");
27
+ var QuotationModule = class extends import_BaseModule.BaseModule {
28
+ constructor(name, version) {
29
+ super(name, version);
30
+ this.defaultName = "quotation";
31
+ this.defaultVersion = "1.0.0";
32
+ this.store = { list: [] };
33
+ }
34
+ async initialize(core, options) {
35
+ this.core = core;
36
+ this.request = core.getPlugin("request");
37
+ if (!this.request)
38
+ throw new Error("QuotationModule 需要 request 插件支持");
39
+ this.store = { list: [] };
40
+ }
41
+ async loadQuotations(params) {
42
+ var _a;
43
+ const query = {};
44
+ if (params == null ? void 0 : params.channel)
45
+ query.channel = params.channel;
46
+ const res = await this.request.get(
47
+ "/quotation/available",
48
+ query,
49
+ { useCache: false }
50
+ );
51
+ const list = ((_a = res == null ? void 0 : res.data) == null ? void 0 : _a.list) || (res == null ? void 0 : res.list) || [];
52
+ list.sort((a, b) => a.sort - b.sort);
53
+ this.store.list = list;
54
+ }
55
+ getQuotationList() {
56
+ return this.store.list;
57
+ }
58
+ /**
59
+ * Look up the quotation price for a specific product (+ optional variant) at a given datetime.
60
+ * Returns the price as a string (e.g. "300.00"), or null if no quotation applies.
61
+ *
62
+ * Priority: iterates quotations already sorted by `sort` ascending (lowest = highest priority).
63
+ * First matching quotation whose schedule covers `datetime` and whose product_data contains
64
+ * the requested productId wins.
65
+ */
66
+ getPriceForProduct(params) {
67
+ const { productId, variantId, datetime } = params;
68
+ for (const quotation of this.store.list) {
69
+ if (!this.isQuotationActiveAt(quotation, datetime))
70
+ continue;
71
+ const match = this.findProductData(quotation.product_data, productId, variantId);
72
+ if (!match)
73
+ continue;
74
+ if (match.value === 0)
75
+ continue;
76
+ return String(match.value);
77
+ }
78
+ return null;
79
+ }
80
+ /**
81
+ * Batch pre-compute quotation prices for a set of products across multiple time points.
82
+ * Key format: `${productId}:${timePoint}`
83
+ * This avoids repeated schedule matching when the same product appears in multiple resource rows.
84
+ */
85
+ buildProductPriceMap(params) {
86
+ const map = /* @__PURE__ */ new Map();
87
+ if (!this.store.list.length)
88
+ return map;
89
+ for (const productId of params.productIds) {
90
+ for (const timePoint of params.timePoints) {
91
+ const key = `${productId}:${timePoint}`;
92
+ const price = this.getPriceForProduct({ productId, datetime: timePoint });
93
+ if (price !== null) {
94
+ map.set(key, price);
95
+ }
96
+ }
97
+ }
98
+ return map;
99
+ }
100
+ isQuotationActiveAt(quotation, datetime) {
101
+ var _a;
102
+ if (!((_a = quotation.schedule) == null ? void 0 : _a.length))
103
+ return false;
104
+ const scheduleItems = quotation.schedule.map((s) => ({
105
+ ...s,
106
+ repeat_type: s.repeat_type || "none",
107
+ repeat_rule: s.repeat_rule || null,
108
+ time_slot: s.time_slot || []
109
+ }));
110
+ return (0, import_getDateIsInSchedule.getDateIsInSchedule)(datetime, scheduleItems);
111
+ }
112
+ findProductData(productData, productId, variantId) {
113
+ if (variantId && variantId !== 0) {
114
+ const variantMatch = productData.find(
115
+ (p) => p.product_id === productId && p.variant_id === variantId
116
+ );
117
+ if (variantMatch)
118
+ return variantMatch;
119
+ }
120
+ return productData.find(
121
+ (p) => p.product_id === productId && p.variant_id === 0
122
+ );
123
+ }
124
+ };
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ QuotationModule
128
+ });
@@ -0,0 +1,42 @@
1
+ export interface QuotationProductData {
2
+ id: number;
3
+ shelf_id: number;
4
+ product_id: number;
5
+ variant_id: number;
6
+ type: string;
7
+ value: number;
8
+ }
9
+ export interface QuotationSchedule {
10
+ id: number;
11
+ name: string;
12
+ type: 'standard' | 'time-slots' | 'designation';
13
+ start_time: string;
14
+ end_time: string;
15
+ is_all: number;
16
+ repeat_type?: string;
17
+ repeat_rule?: any;
18
+ designation?: any;
19
+ time_slot?: Array<{
20
+ start_time: string;
21
+ end_time: string;
22
+ }>;
23
+ pivot?: Record<string, any>;
24
+ }
25
+ export interface QuotationItem {
26
+ id: number;
27
+ shop_id: number;
28
+ shelf_type_id?: number;
29
+ name: string;
30
+ description?: string;
31
+ status: string;
32
+ sort: number;
33
+ channel: string[];
34
+ created_at?: string;
35
+ updated_at?: string;
36
+ deleted_at?: string | null;
37
+ schedule: QuotationSchedule[];
38
+ product_data: QuotationProductData[];
39
+ }
40
+ export interface QuotationState {
41
+ list: QuotationItem[];
42
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/modules/Quotation/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
@@ -1914,7 +1914,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1914
1914
  if (isBundleItem) {
1915
1915
  const priceType = (_a = flatItem.bundleItem) == null ? void 0 : _a.price_type;
1916
1916
  const priceTypeExt = (_b = flatItem.bundleItem) == null ? void 0 : _b.price_type_ext;
1917
- const mainProductId = ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.product_id) || ((_d = flatItem == null ? void 0 : flatItem.originProduct) == null ? void 0 : _d.id) || 0;
1917
+ const mainProductId = ((_c = flatItem == null ? void 0 : flatItem.originProduct) == null ? void 0 : _c.product_id) || ((_d = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _d.product_id) || 0;
1918
1918
  const isOriginalPrice = priceType === "markup" && priceTypeExt === "product_price";
1919
1919
  const isMarkupPrice = priceType === "markup" && (priceTypeExt === "" || !priceTypeExt);
1920
1920
  if (rules.length > 0) {
@@ -0,0 +1,63 @@
1
+ import { Module, ModuleOptions, PisellCore } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import { SalesSummaryModuleAPI } from './types';
4
+ export * from './types';
5
+ export declare class SalesSummaryModule extends BaseModule implements Module, SalesSummaryModuleAPI {
6
+ protected defaultName: string;
7
+ protected defaultVersion: string;
8
+ private shopStore;
9
+ private store;
10
+ private request;
11
+ constructor(name?: string, version?: string);
12
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
13
+ getSurchargeList(): Promise<void>;
14
+ getSummary(params: {
15
+ products: any[];
16
+ isPriceIncludeTax?: number;
17
+ taxRate?: number;
18
+ }): Promise<{
19
+ tax_title: any;
20
+ tax_rate: any;
21
+ product_quantity: number;
22
+ product_original_amount: string;
23
+ product_amount: string;
24
+ product_expect_amount: string;
25
+ product_tax_fee: string;
26
+ shipping_fee: string;
27
+ shipping_tax_fee: string;
28
+ tax_fee: string;
29
+ surcharge_fee: string;
30
+ surcharges: any[];
31
+ discount_amount: string;
32
+ deposit_amount: string;
33
+ deposit?: import("./types").DepositInfo | undefined;
34
+ expect_amount: string;
35
+ total_amount: string;
36
+ amount_gap: string;
37
+ rounding_amount: string;
38
+ pay_service_charge_amount: string;
39
+ is_price_include_tax?: number | undefined;
40
+ } | {
41
+ tax_title: any;
42
+ tax_rate: any;
43
+ product_quantity: number;
44
+ product_original_amount: string;
45
+ product_amount: string;
46
+ product_expect_amount: string;
47
+ product_tax_fee: string;
48
+ shipping_fee: string;
49
+ shipping_tax_fee: string;
50
+ tax_fee: string;
51
+ surcharge_fee: string;
52
+ surcharges: any;
53
+ discount_amount: string;
54
+ deposit_amount: string;
55
+ deposit: import("./types").DepositInfo | undefined;
56
+ expect_amount: string;
57
+ total_amount: string;
58
+ amount_gap: string;
59
+ rounding_amount: string;
60
+ pay_service_charge_amount: string;
61
+ is_price_include_tax: number;
62
+ }>;
63
+ }
@@ -0,0 +1,105 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/modules/SalesSummary/index.ts
21
+ var SalesSummary_exports = {};
22
+ __export(SalesSummary_exports, {
23
+ SalesSummaryModule: () => SalesSummaryModule
24
+ });
25
+ module.exports = __toCommonJS(SalesSummary_exports);
26
+ var import_BaseModule = require("../BaseModule");
27
+ var import_Schedule = require("../Schedule");
28
+ var import_utils = require("./utils");
29
+ __reExport(SalesSummary_exports, require("./types"), module.exports);
30
+ var SalesSummaryModule = class extends import_BaseModule.BaseModule {
31
+ constructor(name, version) {
32
+ super(name, version);
33
+ this.defaultName = "salesSummary";
34
+ this.defaultVersion = "1.0.0";
35
+ }
36
+ async initialize(core, options) {
37
+ var _a, _b;
38
+ this.core = core;
39
+ this.store = options.store;
40
+ this.shopStore = this.core.getPlugin("shopStore");
41
+ this.request = this.core.getPlugin("request");
42
+ this.store.surchargeList = ((_a = options.initialState) == null ? void 0 : _a.surchargeList) || [];
43
+ this.store.summary = ((_b = options.initialState) == null ? void 0 : _b.summary) || (0, import_utils.createEmptySalesSummary)();
44
+ if (!this.shopStore) {
45
+ throw new Error("SalesSummaryModule 需要 shopStore 插件支持");
46
+ }
47
+ if (!this.request) {
48
+ throw new Error("SalesSummaryModule 需要 request 插件支持");
49
+ }
50
+ await this.getSurchargeList();
51
+ }
52
+ async getSurchargeList() {
53
+ try {
54
+ const surchargeList = await this.request.get(
55
+ "/order/custom-surcharge/available/v2",
56
+ {
57
+ channel: "online-store",
58
+ is_assemble_product_data: 1,
59
+ is_assemble_schedule_data: 1,
60
+ with: ["relationSchedule"]
61
+ }
62
+ );
63
+ this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
64
+ } catch (error) {
65
+ console.warn("[SalesSummaryModule] 加载附加费配置失败", error);
66
+ this.store.surchargeList = [];
67
+ }
68
+ }
69
+ async getSummary(params) {
70
+ var _a, _b;
71
+ const { products = [], isPriceIncludeTax, taxRate } = params;
72
+ const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {};
73
+ const summarySchedule = this.core.getModule(
74
+ `${this.name.split("_")[0]}_schedule`
75
+ );
76
+ const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
77
+ const scheduleList = summarySchedule == null ? void 0 : summarySchedule.getScheduleListByIds(needScheduleIds);
78
+ const scheduleById = {};
79
+ if (Array.isArray(scheduleList)) {
80
+ for (const item of scheduleList) {
81
+ scheduleById[item.id] = item;
82
+ }
83
+ }
84
+ const summary = (0, import_utils.calculateSalesSummary)({
85
+ products,
86
+ isPriceIncludeTax: isPriceIncludeTax ?? (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ?? 1,
87
+ taxRate: taxRate ?? (shopInfo == null ? void 0 : shopInfo.tax_rate),
88
+ surchargeList: this.store.surchargeList,
89
+ scheduleById,
90
+ isInScheduleByDate: import_Schedule.ScheduleModule.isInScheduleByDate
91
+ });
92
+ const summaryWithTaxMeta = {
93
+ ...summary,
94
+ tax_title: (shopInfo == null ? void 0 : shopInfo.tax_title) || "",
95
+ tax_rate: taxRate ?? (shopInfo == null ? void 0 : shopInfo.tax_rate)
96
+ };
97
+ this.store.summary = summaryWithTaxMeta;
98
+ return summaryWithTaxMeta;
99
+ }
100
+ };
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ SalesSummaryModule,
104
+ ...require("./types")
105
+ });