@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
@@ -36,17 +36,32 @@ var import_BaseModule = require("../BaseModule");
36
36
  var import_utils = require("./utils");
37
37
  var import_utils2 = require("../Product/utils");
38
38
  var import_dayjs = __toESM(require("dayjs"));
39
+ var import_utils3 = require("../../solution/ScanOrder/utils");
40
+ var import_Discount = require("../Discount");
41
+ var import_Rules = require("../Rules");
42
+ var import_types = require("../Rules/types");
43
+ var import_decimal = __toESM(require("decimal.js"));
39
44
  var OrderModule = class extends import_BaseModule.BaseModule {
40
- // LoggerManager 实例
41
45
  constructor(name, version) {
42
46
  super(name || "order", version);
43
47
  this.defaultName = "order";
44
48
  this.defaultVersion = "1.0.0";
45
49
  }
46
50
  async initialize(core, options) {
51
+ var _a;
47
52
  this.core = core;
48
53
  this.store = options.store;
54
+ if (!this.store.tempOrder) {
55
+ this.store.tempOrder = null;
56
+ }
49
57
  this.request = this.core.getPlugin("request");
58
+ this.window = this.core.getPlugin("window");
59
+ const otherParams = options.otherParams || {};
60
+ this.cacheId = otherParams.cacheId;
61
+ this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
62
+ this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
63
+ this.registerDiscountModules(options);
64
+ this.restoreTempOrderFromStorage();
50
65
  const appPlugin = this.core.getPlugin("app");
51
66
  if (!appPlugin) {
52
67
  console.warn("Order 模块需要 app 插件支持");
@@ -92,6 +107,365 @@ var OrderModule = class extends import_BaseModule.BaseModule {
92
107
  });
93
108
  }
94
109
  }
110
+ // ─── Discount: 子模块注册 ───
111
+ registerDiscountModules(options) {
112
+ const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
113
+ this.core.registerModule(discount, {
114
+ otherParams: {
115
+ fatherModule: this.name
116
+ }
117
+ });
118
+ this.store.discount = discount;
119
+ const rules = new import_Rules.RulesModule(`${this.name}_rules`);
120
+ this.core.registerModule(rules, {
121
+ hooks: this.rulesHooksOverride || this.createDefaultRulesHooks()
122
+ });
123
+ this.store.rules = rules;
124
+ }
125
+ createDefaultRulesHooks() {
126
+ return {
127
+ getProduct: (product) => {
128
+ var _a, _b, _c, _d;
129
+ return {
130
+ id: product.product_id,
131
+ _id: product.identity_key ? `${product.product_id}_${product.product_variant_id}_${product.identity_key}` : `${product.product_id}_${product.product_variant_id}`,
132
+ price: product.selling_price,
133
+ total: new import_decimal.default(product.payment_price || product.selling_price || 0).times(product.num || 1).toNumber(),
134
+ origin_total: new import_decimal.default(product.original_price || product.selling_price || 0).times(product.num || 1).toNumber(),
135
+ original_price: product.original_price,
136
+ quantity: product.num || 1,
137
+ num: product.num || 1,
138
+ discount_list: product.discount_list || [],
139
+ bundle: product.product_bundle || [],
140
+ booking_id: ((_a = product._origin) == null ? void 0 : _a.booking_id) || null,
141
+ isClient: false,
142
+ isManualDiscount: ((_b = product._origin) == null ? void 0 : _b.isManualDiscount) || false,
143
+ holder_id: (_c = product._origin) == null ? void 0 : _c.holder_id,
144
+ startDate: (_d = product._origin) == null ? void 0 : _d.startDate
145
+ };
146
+ },
147
+ setProduct: (product, values) => ({
148
+ ...product,
149
+ selling_price: values.price !== void 0 ? String(values.price) : product.selling_price,
150
+ payment_price: values.total !== void 0 ? String(values.total) : product.payment_price,
151
+ original_price: values.original_price !== void 0 ? String(values.original_price) : product.original_price,
152
+ discount_list: values.discount_list ?? product.discount_list,
153
+ num: values.quantity ?? product.num,
154
+ product_bundle: values.bundle ?? product.product_bundle
155
+ })
156
+ };
157
+ }
158
+ // ─── Discount: 公共 API ───
159
+ async loadDiscountConfig(params) {
160
+ var _a, _b, _c, _d;
161
+ const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
162
+ customer_id: params.customerId,
163
+ action: params.action || "create",
164
+ with_good_pass: 1,
165
+ with_discount_card: 1,
166
+ with_wallet_pass_holder: 1,
167
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
168
+ }));
169
+ if (discountList) {
170
+ (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
171
+ }
172
+ if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
173
+ this.applyDiscount();
174
+ }
175
+ }
176
+ getDiscountList() {
177
+ var _a;
178
+ return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
179
+ }
180
+ async scanCode(code, customerId) {
181
+ var _a, _b, _c, _d, _e;
182
+ const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || [];
183
+ const rulesModule = this.store.rules;
184
+ if (!rulesModule) {
185
+ return {
186
+ type: "clientCalc",
187
+ isAvailable: false,
188
+ discountList: this.getDiscountList(),
189
+ unavailableReason: import_types.UnavailableReason.Unknown
190
+ };
191
+ }
192
+ if (!resultDiscountList.length) {
193
+ return {
194
+ type: "server",
195
+ isAvailable: false,
196
+ discountList: this.getDiscountList()
197
+ };
198
+ }
199
+ const withScanList = resultDiscountList.map((item) => ({ ...item, isScan: true }));
200
+ const currentSelected = this.getDiscountList().filter((n) => n.isSelected);
201
+ if (currentSelected.length && currentSelected.some((n) => withScanList.some((m) => m.id === n.id))) {
202
+ return {
203
+ type: "clientCalc",
204
+ isAvailable: true,
205
+ discountList: this.getDiscountList()
206
+ };
207
+ }
208
+ const tempOrder = this.store.tempOrder;
209
+ const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
210
+ const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
211
+ productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
212
+ oldDiscountList: this.getDiscountList(),
213
+ newDiscountList: withScanList,
214
+ holders,
215
+ isFormSubject: !!((_c = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form",
216
+ orderTotalAmount: Number(((_d = tempOrder == null ? void 0 : tempOrder.summary) == null ? void 0 : _d.total_amount) || 0)
217
+ }) || { isAvailable: false, discountList: this.getDiscountList() };
218
+ if (isAvailable && newDiscountList) {
219
+ (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(newDiscountList);
220
+ this.applyDiscount();
221
+ }
222
+ return {
223
+ type: "clientCalc",
224
+ isAvailable: isAvailable || false,
225
+ discountList: newDiscountList || this.getDiscountList(),
226
+ unavailableReason
227
+ };
228
+ }
229
+ applyDiscount() {
230
+ var _a, _b, _c, _d, _e, _f;
231
+ const tempOrder = this.store.tempOrder;
232
+ if (!((_a = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _a.length))
233
+ return;
234
+ const rulesModule = this.store.rules;
235
+ if (!rulesModule)
236
+ return;
237
+ const discountList = ((_b = this.store.discount) == null ? void 0 : _b.getDiscountList()) || [];
238
+ const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
239
+ const result = rulesModule.calcDiscount({
240
+ productList: tempOrder.products,
241
+ discountList,
242
+ holders,
243
+ isFormSubject: !!((_d = tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form",
244
+ orderTotalAmount: Number(((_e = tempOrder == null ? void 0 : tempOrder.summary) == null ? void 0 : _e.total_amount) || 0)
245
+ });
246
+ if (result == null ? void 0 : result.productList) {
247
+ tempOrder.products = result.productList;
248
+ }
249
+ if (result == null ? void 0 : result.discountList) {
250
+ (_f = this.store.discount) == null ? void 0 : _f.setDiscountList(result.discountList);
251
+ tempOrder.discount_list = result.discountList.filter((d) => d.isSelected);
252
+ }
253
+ }
254
+ // ─── TempOrder: 初始化入口 ───
255
+ initTempOrder(params) {
256
+ if (params.cacheId !== void 0)
257
+ this.cacheId = params.cacheId;
258
+ if (params.salesSummaryModuleName !== void 0)
259
+ this.salesSummaryModuleName = params.salesSummaryModuleName;
260
+ this.restoreTempOrderFromStorage();
261
+ }
262
+ // ─── TempOrder: localStorage 持久化 ───
263
+ getTempOrderStorageKey() {
264
+ if (!this.cacheId)
265
+ return null;
266
+ return `scanOrder:tempOrder:${this.cacheId}`;
267
+ }
268
+ restoreTempOrderFromStorage() {
269
+ var _a, _b;
270
+ const key = this.getTempOrderStorageKey();
271
+ if (!key)
272
+ return;
273
+ if (!this.window)
274
+ return;
275
+ const cachedData = this.window.localStorage.getItem(key);
276
+ if (!cachedData)
277
+ return;
278
+ try {
279
+ const parsedData = JSON.parse(cachedData);
280
+ if (!(0, import_utils.isTempOrder)(parsedData)) {
281
+ this.window.localStorage.removeItem(key);
282
+ return;
283
+ }
284
+ this.store.tempOrder = parsedData;
285
+ } catch {
286
+ (_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
287
+ }
288
+ }
289
+ persistTempOrder() {
290
+ const key = this.getTempOrderStorageKey();
291
+ if (!key || !this.store.tempOrder)
292
+ return;
293
+ if (!this.window)
294
+ return;
295
+ this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
296
+ }
297
+ // ─── TempOrder: 创建 & 获取 ───
298
+ createDefaultTempOrderInstance() {
299
+ return (0, import_utils.createDefaultTempOrder)({
300
+ now: (0, import_utils.formatDateTime)(/* @__PURE__ */ new Date()),
301
+ summary: (0, import_utils.createEmptySummary)()
302
+ });
303
+ }
304
+ ensureTempOrder() {
305
+ if (this.store.tempOrder)
306
+ return this.store.tempOrder;
307
+ const newOrder = this.createDefaultTempOrderInstance();
308
+ this.store.tempOrder = newOrder;
309
+ this.persistTempOrder();
310
+ return newOrder;
311
+ }
312
+ getTempOrder() {
313
+ return this.store.tempOrder;
314
+ }
315
+ async addNewOrder() {
316
+ const tempOrder = this.ensureTempOrder();
317
+ await this.recalculateSummary({ createIfMissing: true });
318
+ this.persistTempOrder();
319
+ return tempOrder;
320
+ }
321
+ getOrderProducts() {
322
+ const tempOrder = this.ensureTempOrder();
323
+ return tempOrder.products;
324
+ }
325
+ // ─── TempOrder: 金额汇总 ───
326
+ getSalesSummary() {
327
+ if (!this.salesSummaryModuleName)
328
+ return null;
329
+ return this.core.getModule(this.salesSummaryModuleName);
330
+ }
331
+ async recalculateSummary(options) {
332
+ const tempOrder = (options == null ? void 0 : options.createIfMissing) ? this.ensureTempOrder() : this.store.tempOrder;
333
+ if (!tempOrder)
334
+ return null;
335
+ const salesSummary = this.getSalesSummary();
336
+ if (!salesSummary) {
337
+ tempOrder.summary = (0, import_utils.createEmptySummary)();
338
+ tempOrder.surcharge_fee = tempOrder.summary.surcharge_fee;
339
+ return tempOrder.summary;
340
+ }
341
+ const summary = await salesSummary.getSummary({
342
+ products: tempOrder.products
343
+ });
344
+ tempOrder.summary = summary;
345
+ if (summary.is_price_include_tax !== void 0) {
346
+ tempOrder.is_price_include_tax = summary.is_price_include_tax;
347
+ }
348
+ if (typeof summary.tax_title === "string") {
349
+ tempOrder.tax_title = summary.tax_title;
350
+ }
351
+ tempOrder.surcharge_fee = summary.surcharge_fee;
352
+ tempOrder.surcharges = summary.surcharges || [];
353
+ tempOrder.deposit_amount = summary.deposit_amount || "0.00";
354
+ tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
355
+ tempOrder.shop_discount = summary.discount_amount || "0.00";
356
+ return tempOrder.summary;
357
+ }
358
+ async getScanOrderSummary() {
359
+ const summary = await this.recalculateSummary({ createIfMissing: true });
360
+ if (!summary)
361
+ return (0, import_utils.createEmptySummary)();
362
+ this.persistTempOrder();
363
+ return summary;
364
+ }
365
+ // ─── TempOrder: 备注 ───
366
+ updateTempOrderNote(note) {
367
+ const tempOrder = this.ensureTempOrder();
368
+ tempOrder.note = String(note || "");
369
+ this.persistTempOrder();
370
+ return tempOrder.note;
371
+ }
372
+ updateTempOrderContactsInfo(contactsInfo) {
373
+ const tempOrder = this.ensureTempOrder();
374
+ tempOrder.contacts_info = Array.isArray(contactsInfo) ? contactsInfo : [];
375
+ this.persistTempOrder();
376
+ return tempOrder.contacts_info;
377
+ }
378
+ // ─── TempOrder: 商品 CRUD ───
379
+ async addProductToOrder(product) {
380
+ const tempOrder = this.ensureTempOrder();
381
+ const normalizedProduct = (0, import_utils3.normalizeOrderProduct)(product);
382
+ const productIndex = (0, import_utils3.getProductIdentityIndex)(
383
+ tempOrder.products,
384
+ normalizedProduct
385
+ );
386
+ if (productIndex === -1) {
387
+ tempOrder.products.push(normalizedProduct);
388
+ } else {
389
+ const targetProduct = tempOrder.products[productIndex];
390
+ tempOrder.products[productIndex] = {
391
+ ...targetProduct,
392
+ ...normalizedProduct,
393
+ num: (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num),
394
+ _origin: normalizedProduct._origin || targetProduct._origin
395
+ };
396
+ }
397
+ this.applyDiscount();
398
+ await this.recalculateSummary({ createIfMissing: true });
399
+ this.persistTempOrder();
400
+ return tempOrder.products;
401
+ }
402
+ async updateProductInOrder(params) {
403
+ const { product_id, product_variant_id, updates } = params;
404
+ const tempOrder = this.ensureTempOrder();
405
+ const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, {
406
+ product_id,
407
+ product_variant_id
408
+ });
409
+ if (productIndex === -1) {
410
+ throw new Error("[Order] 目标商品不存在,无法更新");
411
+ }
412
+ const targetProduct = tempOrder.products[productIndex];
413
+ const nextProduct = {
414
+ ...targetProduct,
415
+ ...updates,
416
+ product_id,
417
+ product_variant_id
418
+ };
419
+ nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
420
+ tempOrder.products[productIndex] = nextProduct;
421
+ this.applyDiscount();
422
+ await this.recalculateSummary({ createIfMissing: true });
423
+ this.persistTempOrder();
424
+ return tempOrder.products;
425
+ }
426
+ async removeProductFromOrder(identity) {
427
+ const tempOrder = this.ensureTempOrder();
428
+ tempOrder.products = tempOrder.products.filter(
429
+ (item) => !(0, import_utils3.isIdentityMatch)(item, identity)
430
+ );
431
+ this.applyDiscount();
432
+ await this.recalculateSummary({ createIfMissing: true });
433
+ this.persistTempOrder();
434
+ return tempOrder.products;
435
+ }
436
+ // ─── TempOrder: 提交 ───
437
+ async submitTempOrder(params) {
438
+ const tempOrder = this.ensureTempOrder();
439
+ this.persistTempOrder();
440
+ const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
441
+ const payload = (0, import_utils.buildSubmitPayload)({
442
+ tempOrder,
443
+ cacheId: effectiveCacheId
444
+ });
445
+ let result;
446
+ if (tempOrder.order_id) {
447
+ const products = (0, import_utils.formatV1Product)(payload.products);
448
+ const moreResult = await this.scanOrderMore({
449
+ query: {
450
+ order_id: tempOrder.order_id,
451
+ products,
452
+ request_unique_idempotency_token: payload.request_unique_idempotency_token
453
+ }
454
+ });
455
+ if (moreResult.code === 200) {
456
+ result = {
457
+ data: {
458
+ order_id: tempOrder.order_id
459
+ }
460
+ };
461
+ }
462
+ } else {
463
+ result = await this.submitScanOrder({
464
+ query: payload
465
+ });
466
+ }
467
+ return result;
468
+ }
95
469
  createOrder(params) {
96
470
  var _a;
97
471
  const order = {
@@ -295,6 +669,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
295
669
  throw error;
296
670
  }
297
671
  }
672
+ async submitScanOrder(params) {
673
+ const { url, query } = params;
674
+ const fetchUrl = url || "/order/sales/checkout";
675
+ return this.request.post(fetchUrl, query);
676
+ }
677
+ async scanOrderMore(params) {
678
+ const { url, query } = params;
679
+ const fetchUrl = url || `/order/order/product/${query.order_id}`;
680
+ const requestBody = {
681
+ products: query.products,
682
+ request_unique_idempotency_token: query.request_unique_idempotency_token
683
+ };
684
+ return this.request.put(fetchUrl, requestBody);
685
+ }
298
686
  };
299
687
  // Annotate the CommonJS export names for ESM import in node:
300
688
  0 && (module.exports = {
@@ -1,4 +1,8 @@
1
1
  import { CartItem } from '../Cart/types';
2
+ import type { ScanOrderTempOrder, ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderSummary } from '../../solution/ScanOrder/types';
3
+ import type { DiscountModule } from '../Discount';
4
+ import type { RulesModule } from '../Rules';
5
+ import type { Discount } from '../Discount/types';
2
6
  export declare enum OrderHooks {
3
7
  OnOrderCreate = "order:onOrderCreate",
4
8
  OnOrderUpdate = "order:onOrderUpdate",
@@ -6,6 +10,10 @@ export declare enum OrderHooks {
6
10
  OnOrderStatusChange = "order:onOrderStatusChange"
7
11
  }
8
12
  export interface OrderState {
13
+ tempOrder: ScanOrderTempOrder | null;
14
+ discountList: any[];
15
+ discount: DiscountModule | null;
16
+ rules: RulesModule | null;
9
17
  }
10
18
  /**
11
19
  * 订单信息
@@ -20,6 +28,109 @@ export interface CommitOrderParams {
20
28
  business_code?: string;
21
29
  };
22
30
  }
31
+ export interface SubmitScanOrderProduct {
32
+ order_detail_id: number | null;
33
+ product_id: number | null;
34
+ num: number;
35
+ product_variant_id: number;
36
+ product_option_item: any[];
37
+ selling_price: string;
38
+ original_price: string;
39
+ payment_price: string;
40
+ tax_fee: string;
41
+ is_charge_tax: number;
42
+ discount_list: any[];
43
+ product_bundle: any[];
44
+ metadata: Record<string, any>;
45
+ }
46
+ export interface SubmitScanOrderSummary {
47
+ product_quantity: number;
48
+ product_original_amount: string;
49
+ product_amount: string;
50
+ product_expect_amount: string;
51
+ product_tax_fee: string;
52
+ shipping_fee: string;
53
+ shipping_tax_fee: string;
54
+ tax_fee: string;
55
+ surcharge_fee: string;
56
+ discount_amount: string;
57
+ deposit_amount: string;
58
+ expect_amount: string;
59
+ total_amount: string;
60
+ amount_gap: string;
61
+ rounding_amount: string;
62
+ pay_service_charge_amount: string;
63
+ }
64
+ export interface SubmitScanOrderBooking {
65
+ relation_id?: string;
66
+ form_id?: string;
67
+ collect_pax?: number;
68
+ start_time?: string;
69
+ end_time?: string;
70
+ metadata?: Record<string, any>;
71
+ }
72
+ export interface SubmitScanOrderFormRecord {
73
+ form_id: number | string;
74
+ form_record_ids: Array<number | string>;
75
+ }
76
+ export interface SubmitScanOrderParams {
77
+ url?: string;
78
+ query: {
79
+ order_id: number | null;
80
+ relation_id?: string;
81
+ table_form_id?: string;
82
+ resource_id?: string;
83
+ order_number: string;
84
+ shop_order_number: string;
85
+ type: string;
86
+ business_code: string;
87
+ platform: 'H5' | 'PC';
88
+ request_unique_idempotency_token?: string;
89
+ sales_channel: string;
90
+ order_sales_channel: string;
91
+ status: string;
92
+ payment_status: string;
93
+ shipping_status: string;
94
+ customer_id: number | null;
95
+ customer_name: string;
96
+ country_calling_code: string;
97
+ phone: string;
98
+ email: string;
99
+ is_price_include_tax: number;
100
+ tax_title: string;
101
+ tax_country_code: string;
102
+ currency_code: string;
103
+ currency_symbol: string;
104
+ currency_format: string;
105
+ is_deposit: number;
106
+ deposit_amount: string;
107
+ shop_discount: string;
108
+ surcharge_fee: string;
109
+ note: string;
110
+ schedule_date: string;
111
+ created_at?: string;
112
+ products: SubmitScanOrderProduct[];
113
+ bookings: SubmitScanOrderBooking[];
114
+ payments: any[];
115
+ surcharges: any[];
116
+ discount_list: any[];
117
+ relation_forms: any[];
118
+ form_record_ids?: SubmitScanOrderFormRecord[];
119
+ contacts: any[];
120
+ contacts_info: any[];
121
+ holder: Record<string, any> | null;
122
+ summary: SubmitScanOrderSummary;
123
+ metadata: Record<string, any>;
124
+ };
125
+ }
126
+ export interface ScanOrderMoreParams {
127
+ url?: string;
128
+ query: {
129
+ order_id: number | string;
130
+ products: SubmitScanOrderProduct[];
131
+ request_unique_idempotency_token?: string;
132
+ };
133
+ }
23
134
  /**
24
135
  * 支付项数据
25
136
  */
@@ -63,23 +174,11 @@ export interface CheckoutOrderParams {
63
174
  * 订单模块 API
64
175
  */
65
176
  export interface OrderModuleAPI {
66
- /**
67
- * 创建订单
68
- * @param params 订单信息
69
- * @returns 订单信息
70
- */
71
177
  createOrder: (params: CommitOrderParams['query']) => any;
72
- /**
73
- * 检查购物车提交订单前是否符合条件
74
- */
75
178
  checkBeforeSubmitOrder: (params: {
76
179
  cartItems: CartItem[];
77
180
  type: 'holder' | 'account';
78
181
  }) => boolean;
79
- /**
80
- * 提交订单
81
- * @param params 订单信息
82
- */
83
182
  submitOrder: (params: CommitOrderParams) => Promise<void>;
84
183
  /**
85
184
  * Checkout 专用:创建订单到后端
@@ -87,4 +186,37 @@ export interface OrderModuleAPI {
87
186
  * @returns 后端返回的订单数据
88
187
  */
89
188
  createOrderByCheckout: (params: CheckoutOrderParams) => Promise<any>;
189
+ submitScanOrder: <T = any>(params: SubmitScanOrderParams) => Promise<T>;
190
+ scanOrderMore: <T = any>(params: ScanOrderMoreParams) => Promise<T>;
191
+ initTempOrder: (params: {
192
+ cacheId?: string;
193
+ salesSummaryModuleName?: string;
194
+ }) => void;
195
+ getTempOrder: () => ScanOrderTempOrder | null;
196
+ ensureTempOrder: () => ScanOrderTempOrder;
197
+ addNewOrder: () => Promise<ScanOrderTempOrder>;
198
+ getOrderProducts: () => ScanOrderOrderProduct[];
199
+ getScanOrderSummary: () => Promise<ScanOrderSummary>;
200
+ recalculateSummary: (options?: {
201
+ createIfMissing?: boolean;
202
+ }) => Promise<ScanOrderSummary | null>;
203
+ updateTempOrderNote: (note: string) => string;
204
+ updateTempOrderContactsInfo: (contactsInfo: any[]) => any[];
205
+ addProductToOrder: (product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity) => Promise<ScanOrderOrderProduct[]>;
206
+ updateProductInOrder: (params: {
207
+ product_id: number | null;
208
+ product_variant_id: number;
209
+ updates: Partial<ScanOrderOrderProduct>;
210
+ }) => Promise<ScanOrderOrderProduct[]>;
211
+ removeProductFromOrder: (identity: ScanOrderOrderProductIdentity) => Promise<ScanOrderOrderProduct[]>;
212
+ persistTempOrder: () => void;
213
+ submitTempOrder: <T = any>(params?: {
214
+ cacheId?: string;
215
+ }) => Promise<T>;
216
+ loadDiscountConfig: (params: {
217
+ customerId: number;
218
+ action?: 'create';
219
+ }) => Promise<void>;
220
+ getDiscountList: () => Discount[];
221
+ applyDiscount: () => void;
90
222
  }
@@ -1,4 +1,5 @@
1
1
  import { CartItem } from "../Cart";
2
+ import type { ScanOrderSubmitPayload, ScanOrderSubmitProduct, ScanOrderSummary, ScanOrderTempOrder } from '../../solution/ScanOrder/types';
2
3
  /**
3
4
  * 通过 session 类商品的开始时间结束时间生成商品的时长
4
5
  * @param {CartItem} cartItem
@@ -21,3 +22,27 @@ export declare const mergeRelationForms: (relationForms: {
21
22
  form_record_ids: number[];
22
23
  }[];
23
24
  export declare const getAllDiscountList: (cartItem: CartItem) => any;
25
+ export declare function createUuidV4(): string;
26
+ export declare function isTempOrder(data: any): data is ScanOrderTempOrder;
27
+ export declare function formatDateTime(date: Date): string;
28
+ export declare function createDefaultTempOrder(params: {
29
+ now: string;
30
+ summary?: ScanOrderSummary;
31
+ }): ScanOrderTempOrder;
32
+ export declare function buildSubmitPayload(params: {
33
+ tempOrder: ScanOrderTempOrder;
34
+ cacheId?: string;
35
+ now?: Date;
36
+ }): ScanOrderSubmitPayload;
37
+ export declare function formatV1Product(products: ScanOrderSubmitProduct[]): {
38
+ bundle: any[];
39
+ key: number | null;
40
+ option: any[];
41
+ product_id: number | null;
42
+ product_variant_id: number;
43
+ quantity: number;
44
+ rowKey: number | null;
45
+ session: null;
46
+ unique: string;
47
+ }[];
48
+ export { createEmptySummary } from '../../solution/ScanOrder/utils';