@pisell/pisellos 2.2.170 → 2.2.171

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 (149) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/Customer/index.d.ts +0 -6
  3. package/dist/modules/Customer/index.js +83 -129
  4. package/dist/modules/Customer/types.d.ts +0 -2
  5. package/dist/modules/Discount/index.d.ts +4 -2
  6. package/dist/modules/Discount/index.js +93 -8
  7. package/dist/modules/Discount/types.d.ts +7 -1
  8. package/dist/modules/Order/index.d.ts +15 -27
  9. package/dist/modules/Order/index.js +322 -695
  10. package/dist/modules/Order/types.d.ts +14 -49
  11. package/dist/modules/Order/types.js +0 -2
  12. package/dist/modules/Order/utils.d.ts +0 -17
  13. package/dist/modules/Order/utils.js +26 -97
  14. package/dist/modules/Rules/index.d.ts +0 -4
  15. package/dist/modules/Rules/index.js +10 -26
  16. package/dist/modules/SalesSummary/index.js +2 -4
  17. package/dist/modules/index.d.ts +0 -1
  18. package/dist/modules/index.js +1 -2
  19. package/dist/server/modules/order/utils/filterOrders.js +6 -20
  20. package/dist/solution/BaseSales/index.d.ts +7 -46
  21. package/dist/solution/BaseSales/index.js +315 -1009
  22. package/dist/solution/BaseSales/types.d.ts +1 -53
  23. package/dist/solution/BaseSales/types.js +1 -3
  24. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -65
  25. package/dist/solution/BaseSales/utils.js +8 -46
  26. package/dist/solution/BookingByStep/index.d.ts +1 -1
  27. package/dist/solution/BookingTicket/index.d.ts +1 -133
  28. package/dist/solution/BookingTicket/index.js +175 -768
  29. package/dist/solution/BookingTicket/types.d.ts +0 -2
  30. package/dist/solution/BookingTicket/types.js +0 -3
  31. package/dist/solution/ScanOrder/index.d.ts +3 -9
  32. package/dist/solution/ScanOrder/index.js +128 -231
  33. package/dist/solution/ScanOrder/utils.js +8 -46
  34. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  35. package/dist/solution/ShopDiscount/index.js +23 -18
  36. package/dist/solution/VenueBooking/index.d.ts +9 -5
  37. package/dist/solution/VenueBooking/index.js +55 -103
  38. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  39. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  40. package/lib/modules/Customer/index.d.ts +0 -6
  41. package/lib/modules/Customer/index.js +11 -26
  42. package/lib/modules/Customer/types.d.ts +0 -2
  43. package/lib/modules/Discount/index.d.ts +4 -2
  44. package/lib/modules/Discount/index.js +63 -8
  45. package/lib/modules/Discount/types.d.ts +7 -1
  46. package/lib/modules/Order/index.d.ts +15 -27
  47. package/lib/modules/Order/index.js +84 -336
  48. package/lib/modules/Order/types.d.ts +14 -49
  49. package/lib/modules/Order/utils.d.ts +0 -17
  50. package/lib/modules/Order/utils.js +18 -105
  51. package/lib/modules/Rules/index.d.ts +0 -4
  52. package/lib/modules/Rules/index.js +14 -22
  53. package/lib/modules/SalesSummary/index.js +2 -4
  54. package/lib/modules/index.d.ts +0 -1
  55. package/lib/modules/index.js +1 -3
  56. package/lib/server/modules/order/utils/filterOrders.js +4 -12
  57. package/lib/solution/BaseSales/index.d.ts +7 -46
  58. package/lib/solution/BaseSales/index.js +20 -434
  59. package/lib/solution/BaseSales/types.d.ts +1 -53
  60. package/lib/solution/BaseSales/types.js +1 -3
  61. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +11 -70
  62. package/lib/solution/BaseSales/utils.js +6 -46
  63. package/lib/solution/BookingByStep/index.d.ts +1 -1
  64. package/lib/solution/BookingTicket/index.d.ts +1 -133
  65. package/lib/solution/BookingTicket/index.js +8 -341
  66. package/lib/solution/BookingTicket/types.d.ts +0 -2
  67. package/lib/solution/BookingTicket/types.js +0 -6
  68. package/lib/solution/ScanOrder/index.d.ts +3 -9
  69. package/lib/solution/ScanOrder/index.js +66 -147
  70. package/lib/solution/ScanOrder/utils.js +6 -46
  71. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  72. package/lib/solution/ShopDiscount/index.js +4 -2
  73. package/lib/solution/VenueBooking/index.d.ts +9 -5
  74. package/lib/solution/VenueBooking/index.js +14 -50
  75. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  76. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  77. package/package.json +2 -2
  78. package/dist/modules/BookingContext/index.d.ts +0 -37
  79. package/dist/modules/BookingContext/index.js +0 -436
  80. package/dist/modules/BookingContext/types.d.ts +0 -102
  81. package/dist/modules/BookingContext/types.js +0 -51
  82. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  83. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
  84. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  85. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
  86. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  87. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
  88. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  89. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  90. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  91. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  92. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  93. package/dist/modules/BookingContext/utils/index.js +0 -11
  94. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  95. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  96. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  97. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  98. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  99. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  100. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  101. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  102. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  103. package/dist/modules/BookingContext/utils/resources.js +0 -486
  104. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  105. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  106. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  107. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  108. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  109. package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
  110. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  111. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -159
  112. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  113. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  114. package/lib/modules/BookingContext/index.d.ts +0 -37
  115. package/lib/modules/BookingContext/index.js +0 -297
  116. package/lib/modules/BookingContext/types.d.ts +0 -102
  117. package/lib/modules/BookingContext/types.js +0 -34
  118. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  119. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
  120. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  121. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
  122. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  123. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
  124. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  125. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  126. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  128. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  129. package/lib/modules/BookingContext/utils/index.js +0 -43
  130. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  131. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  132. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  133. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  134. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  135. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  136. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  137. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  138. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  139. package/lib/modules/BookingContext/utils/resources.js +0 -377
  140. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  141. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  142. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  143. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  144. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  145. package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
  146. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  147. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -201
  148. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  149. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
@@ -34,16 +34,13 @@ __export(BaseSales_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(BaseSales_exports);
36
36
  var import_BaseModule = require("../../modules/BaseModule");
37
- var import_types = require("./types");
38
37
  var import_Order = require("../../modules/Order");
39
38
  var import_decimal = __toESM(require("decimal.js"));
40
- var import_types2 = require("../BookingByStep/types");
39
+ var import_types = require("../BookingByStep/types");
41
40
  var import_utils = require("../../modules/Order/utils");
42
41
  var import_dayjs = __toESM(require("dayjs"));
43
42
  __reExport(BaseSales_exports, require("./types"), module.exports);
44
- var import_Quotation = require("../../modules/Quotation");
45
43
  var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
46
- var import_quotationPrice = require("./utils/quotationPrice");
47
44
  var BaseSalesImpl = class extends import_BaseModule.BaseModule {
48
45
  constructor(name, version) {
49
46
  super(name, version);
@@ -51,6 +48,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
51
48
  this.defaultVersion = "1.0.0";
52
49
  this.isSolution = true;
53
50
  this.initializeOptions = {};
51
+ // LoggerManager 实例
54
52
  this.store = {
55
53
  order: void 0
56
54
  };
@@ -60,10 +58,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
60
58
  }
61
59
  /**
62
60
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
63
- * 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation
61
+ * 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
64
62
  */
65
63
  getRegisteredModuleNames() {
66
- return ["products", "order", "salesSummary", "schedule", "payment", "quotation"];
64
+ return ["products", "order", "salesSummary", "schedule", "payment"];
67
65
  }
68
66
  /**
69
67
  * 记录信息日志
@@ -107,48 +105,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
107
105
  get payment() {
108
106
  return this.store.payment;
109
107
  }
110
- getCurrentOrderCustomerId() {
111
- var _a, _b;
112
- const tempOrder = (_b = (_a = this.store.order) == null ? void 0 : _a.getTempOrder) == null ? void 0 : _b.call(_a);
113
- const customerId = tempOrder == null ? void 0 : tempOrder.customer_id;
114
- if (customerId === null || customerId === void 0)
115
- return void 0;
116
- return customerId;
117
- }
118
- applyQuotationScheduleResolver(quotation) {
119
- const scheduleModule = this.store.schedule;
120
- if (!scheduleModule)
121
- return;
122
- quotation.setScheduleResolver((id) => {
123
- var _a;
124
- const schedules = ((_a = scheduleModule.getScheduleListByIds) == null ? void 0 : _a.call(scheduleModule, [id])) || [];
125
- return schedules[0];
126
- });
127
- }
128
- async loadQuotationForPriceQuery(params) {
129
- var _a;
130
- if (!params.quotation)
131
- return;
132
- this.applyQuotationScheduleResolver(params.quotation);
133
- await params.quotation.loadQuotations({
134
- channel: params.channel || ((_a = this.otherParams) == null ? void 0 : _a.channel),
135
- customer_id: params.customer_id
136
- });
137
- }
138
- getSubmitOrderSalesChannel() {
139
- var _a;
140
- return (_a = this.otherParams) == null ? void 0 : _a.channel;
141
- }
142
108
  /**
143
109
  * 工厂入口:根据子模块名实例化对应模块。
144
110
  * 默认使用 BookingByStep 公共 `createModule`。子类若需引入额外类型(如 customer),
145
111
  * 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
146
112
  */
147
113
  createSubModule(moduleName) {
148
- if (moduleName === "quotation") {
149
- return new import_Quotation.QuotationModule(`${this.name}_quotation`);
150
- }
151
- return (0, import_types2.createModule)(moduleName, this.name);
114
+ return (0, import_types.createModule)(moduleName, this.name);
152
115
  }
153
116
  getSubModuleHooks(moduleName) {
154
117
  var _a, _b;
@@ -177,43 +140,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
177
140
  return {};
178
141
  }
179
142
  }
180
- getAppData(key) {
181
- var _a, _b, _c, _d, _e, _f;
182
- const getData = (_b = (_a = this.appPlugin).getData) == null ? void 0 : _b.call(_a);
183
- if (typeof getData === "function")
184
- return getData(key);
185
- const app = this.appPlugin.getApp();
186
- const coreData = (_f = (_d = (_c = app == null ? void 0 : app.models) == null ? void 0 : _c.getStore) == null ? void 0 : (_e = _d.call(_c)).getDataByModel) == null ? void 0 : _f.call(_e, "core", "core");
187
- return coreData == null ? void 0 : coreData[key];
188
- }
189
- syncAppDataToTempOrder(tempOrder) {
190
- const taxCountryCode = this.getAppData("tax_country_code");
191
- const currencyCode = this.getAppData("shop_currency_code");
192
- const currencySymbol = this.getAppData("shop_symbol");
193
- let isChanged = false;
194
- if (taxCountryCode !== void 0) {
195
- const nextTaxCountryCode = String(taxCountryCode || "");
196
- if (tempOrder.tax_country_code !== nextTaxCountryCode) {
197
- tempOrder.tax_country_code = nextTaxCountryCode;
198
- isChanged = true;
199
- }
200
- }
201
- if (currencyCode !== void 0) {
202
- const nextCurrencyCode = String(currencyCode || "");
203
- if (tempOrder.currency_code !== nextCurrencyCode) {
204
- tempOrder.currency_code = nextCurrencyCode;
205
- isChanged = true;
206
- }
207
- }
208
- if (currencySymbol !== void 0) {
209
- const nextCurrencySymbol = String(currencySymbol || "");
210
- if (tempOrder.currency_symbol !== nextCurrencySymbol) {
211
- tempOrder.currency_symbol = nextCurrencySymbol;
212
- isChanged = true;
213
- }
214
- }
215
- return isChanged;
216
- }
217
143
  async initialize(core, options = {}) {
218
144
  var _a;
219
145
  this.core = core;
@@ -222,11 +148,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
222
148
  this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
223
149
  this.window = core.getPlugin("window");
224
150
  this.request = core.getPlugin("request");
225
- this.appPlugin = core.getPlugin("app");
226
- if (!this.appPlugin) {
151
+ const appPlugin = core.getPlugin("app");
152
+ if (!appPlugin) {
227
153
  throw new Error("Checkout 解决方案需要 app 插件支持");
228
154
  }
229
- const app = this.appPlugin.getApp();
155
+ const app = appPlugin.getApp();
230
156
  this.logger = app.logger;
231
157
  const targetCacheData = this.readSessionCacheData();
232
158
  const moduleNames = this.getRegisteredModuleNames();
@@ -360,13 +286,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
360
286
  const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
361
287
  return result;
362
288
  }
363
- async replaceTempOrder(tempOrder) {
364
- if (!this.store.order)
365
- throw new Error("order 模块未初始化");
366
- const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder);
367
- await this.effectsEmit("onTempOrderReplaced", { tempOrder: nextTempOrder });
368
- return nextTempOrder;
369
- }
370
289
  getOrderIdentity() {
371
290
  if (!this.store.order)
372
291
  return null;
@@ -392,21 +311,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
392
311
  return "";
393
312
  return this.store.order.getTempOrderNote();
394
313
  }
395
- updateTempOrderNote(note, sync = false) {
314
+ updateTempOrderNote(note) {
396
315
  try {
397
316
  if (!this.store.order)
398
317
  throw new Error("order 模块未初始化");
399
- const result = this.store.order.updateTempOrderNote(note, sync);
318
+ const result = this.store.order.updateTempOrderNote(note);
400
319
  return result;
401
320
  } catch (error) {
402
321
  throw error;
403
322
  }
404
323
  }
405
- updateRemoteOrderNote(orderId, note) {
406
- if (!this.store.order)
407
- throw new Error("order 模块未初始化");
408
- this.store.order.syncTempOrderNoteToRemote(orderId, note);
409
- }
410
324
  updateTempOrderShopDiscount(amount) {
411
325
  if (!this.store.order)
412
326
  throw new Error("order 模块未初始化");
@@ -428,10 +342,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
428
342
  if (!this.store.order)
429
343
  throw new Error("order 模块未初始化");
430
344
  const tempOrder = await this.store.order.addNewOrder();
431
- if (this.syncAppDataToTempOrder(tempOrder)) {
432
- this.store.order.persistTempOrder();
433
- await this.store.order.saveDraft();
434
- }
435
345
  return tempOrder;
436
346
  } catch (error) {
437
347
  throw error;
@@ -450,41 +360,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
450
360
  throw new Error("scanOrder 解决方案需要 order 模块支持");
451
361
  }
452
362
  const tempOrder = this.store.order.restoreOrder();
453
- this.currentSalesDetail = null;
454
- await this.effectsEmit("onTempOrderReplaced", { tempOrder });
455
- if (this.syncAppDataToTempOrder(tempOrder)) {
456
- this.store.order.persistTempOrder();
457
- await this.store.order.saveDraft();
458
- }
459
- return tempOrder;
460
- } catch (error) {
461
- throw error;
462
- }
463
- }
464
- /**
465
- * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
466
- * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
467
- */
468
- async clearOrderCartLines() {
469
- try {
470
- if (!this.store.order)
471
- throw new Error("order 模块未初始化");
472
- const tempOrder = await this.store.order.clearOrderCartLines();
473
- if (this.currentSalesDetail) {
474
- this.currentSalesDetail = {
475
- ...this.currentSalesDetail,
476
- products: [],
477
- bookings: [],
478
- rootBooking: null,
479
- bookingsByProductUid: {},
480
- discount_list: []
481
- };
482
- }
483
- await this.effectsEmit("onTempOrderReplaced", { tempOrder });
484
- if (this.syncAppDataToTempOrder(tempOrder)) {
485
- this.store.order.persistTempOrder();
486
- await this.store.order.saveDraft();
487
- }
488
363
  return tempOrder;
489
364
  } catch (error) {
490
365
  throw error;
@@ -506,171 +381,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
506
381
  throw error;
507
382
  }
508
383
  }
509
- getHistoricalProductDiscountList(products) {
510
- const historyDiscountList = [];
511
- products.forEach((item) => {
512
- if (!this.isPersistedOrderProduct(item))
513
- return;
514
- (item.discount_list || []).forEach((discount) => {
515
- var _a, _b, _c, _d, _e, _f;
516
- const discountId = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
517
- if (!discountId || !["good_pass", "discount_card"].includes(discount.type))
518
- return;
519
- const quantity = item.quantity || item.num || item.product_quantity || 1;
520
- const savedAmount = new import_decimal.default(discount.amount || 0).times(quantity).plus(((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0);
521
- const index = historyDiscountList.findIndex((n) => n.id === discountId);
522
- if (index !== -1) {
523
- historyDiscountList[index] = {
524
- ...historyDiscountList[index],
525
- amount: new import_decimal.default(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
526
- savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
527
- };
528
- return;
529
- }
530
- historyDiscountList.push({
531
- ...discount,
532
- id: discountId,
533
- tag: discount.tag || discount.type,
534
- name: discount.name || ((_d = (_c = discount.discount) == null ? void 0 : _c.title) == null ? void 0 : _d.auto),
535
- format_title: ((_e = discount.discount) == null ? void 0 : _e.title) || discount.format_title,
536
- isEditMode: true,
537
- limited_relation_product_data: {},
538
- savedAmount: savedAmount.toNumber(),
539
- isAvailable: true,
540
- isDisabled: true,
541
- isSelected: true,
542
- product_id: ((_f = discount.discount) == null ? void 0 : _f.product_id) || discount.product_id
543
- });
544
- });
545
- });
546
- return historyDiscountList;
547
- }
548
- isPersistedOrderProduct(product) {
549
- const orderDetailId = product.order_detail_id ?? product.orderDetailId;
550
- if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
551
- return true;
552
- }
553
- const bookingId = product.booking_id ?? product.bookingId;
554
- return bookingId !== void 0 && bookingId !== null && bookingId !== "";
555
- }
556
- mergeHistoricalDiscountList(discountList, products) {
557
- const historyDiscountList = this.getHistoricalProductDiscountList(products);
558
- const historyIds = new Set(historyDiscountList.map((discount) => discount.id));
559
- return [
560
- ...historyDiscountList,
561
- ...(discountList || []).filter((discount) => !historyIds.has(discount.id))
562
- ];
563
- }
564
- async loadDiscountConfig(params) {
565
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
566
- if (!this.store.order)
567
- throw new Error("order 模块未初始化");
568
- const tempOrder = this.store.order.ensureTempOrder();
569
- const orderStore = this.store.order.store || {};
570
- const discountModule = orderStore.discount;
571
- const rulesModule = orderStore.rules;
572
- const orderId = tempOrder.order_id || ((_b = (_a = this.getOrderIdentity) == null ? void 0 : _a.call(this)) == null ? void 0 : _b.orderId);
573
- const customerId = Number(
574
- (params == null ? void 0 : params.customerId) || tempOrder.customer_id || ((_c = tempOrder.customer) == null ? void 0 : _c.id) || ((_e = (_d = tempOrder._extend) == null ? void 0 : _d.customerSnapshot) == null ? void 0 : _e.id) || ((_g = (_f = tempOrder._extend) == null ? void 0 : _f.customerSnapshot) == null ? void 0 : _g.customer_id) || 0
575
- );
576
- let preparedDiscountList = [];
577
- if (customerId && customerId !== 1) {
578
- preparedDiscountList = await this.store.order.loadDiscountConfig({
579
- customerId,
580
- action: (params == null ? void 0 : params.action) || (orderId ? "edit" : "create"),
581
- orderId: Number(orderId) || void 0,
582
- apply: false
583
- });
584
- await ((_h = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _h.call(discountModule, preparedDiscountList));
585
- }
586
- let nextDiscountList = this.mergeHistoricalDiscountList(
587
- preparedDiscountList || ((_i = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _i.call(discountModule)) || [],
588
- tempOrder.products || []
589
- );
590
- await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
591
- if (rulesModule) {
592
- const holders = ((_j = tempOrder.holder) == null ? void 0 : _j.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
593
- const result = rulesModule.calcDiscount({
594
- productList: tempOrder.products,
595
- discountList: nextDiscountList,
596
- holders,
597
- isFormSubject: !!((_k = tempOrder.holder) == null ? void 0 : _k.type) && tempOrder.holder.type === "form",
598
- orderTotalAmount: Number(((_l = orderStore.summary) == null ? void 0 : _l.total_amount) || 0)
599
- }) || { productList: tempOrder.products, discountList: nextDiscountList };
600
- if (result.productList) {
601
- tempOrder.products = result.productList;
602
- }
603
- if (result.discountList) {
604
- nextDiscountList = this.mergeHistoricalDiscountList(
605
- result.discountList,
606
- tempOrder.products || []
607
- );
608
- import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
609
- await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
610
- tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
611
- }
612
- }
613
- this.store.order.persistTempOrder();
614
- await this.effectsEmit("onDiscountApplied", {
615
- productList: tempOrder.products || [],
616
- discountList: nextDiscountList,
617
- selectedDiscountList: tempOrder.discount_list || [],
618
- tempOrder
619
- });
620
- return {
621
- productList: tempOrder.products || [],
622
- discountList: nextDiscountList
623
- };
624
- }
625
- async bestDiscount(cb) {
626
- var _a, _b, _c, _d;
627
- if (!this.store.order)
628
- throw new Error("order 模块未初始化");
629
- const tempOrder = this.store.order.ensureTempOrder();
630
- const orderStore = this.store.order.store || {};
631
- const discountModule = orderStore.discount;
632
- const rulesModule = orderStore.rules;
633
- const originalDiscountList = ((_a = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _a.call(discountModule)) || this.getDiscountList();
634
- let nextDiscountList = this.mergeHistoricalDiscountList(
635
- originalDiscountList || [],
636
- tempOrder.products || []
637
- );
638
- let result = {
639
- productList: tempOrder.products || [],
640
- discountList: nextDiscountList
641
- };
642
- await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
643
- if (rulesModule) {
644
- const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
645
- result = rulesModule.calcDiscount({
646
- productList: tempOrder.products,
647
- discountList: nextDiscountList,
648
- holders,
649
- isFormSubject: !!((_c = tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form",
650
- orderTotalAmount: Number(((_d = orderStore.summary) == null ? void 0 : _d.total_amount) || 0)
651
- }) || result;
652
- if (result.productList) {
653
- tempOrder.products = result.productList;
654
- }
655
- if (result.discountList) {
656
- nextDiscountList = this.mergeHistoricalDiscountList(
657
- result.discountList,
658
- tempOrder.products || []
659
- );
660
- import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
661
- await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
662
- tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
663
- result = {
664
- productList: tempOrder.products,
665
- discountList: nextDiscountList
666
- };
667
- }
668
- }
669
- await this.store.order.recalculateSummary({ createIfMissing: true });
670
- this.store.order.persistTempOrder();
671
- cb == null ? void 0 : cb(result);
672
- return result;
673
- }
674
384
  getDiscountList() {
675
385
  if (!this.store.order)
676
386
  return [];
@@ -780,40 +490,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
780
490
  tempOrder.discount_list = (nextDiscountList || []).filter((d) => d.isSelected);
781
491
  await this.store.order.recalculateSummary({ createIfMissing: true });
782
492
  this.store.order.persistTempOrder();
783
- this.effectsEmit("onDiscountApplied", {
784
- productList: tempOrder.products,
785
- discountList: nextDiscountList,
786
- selectedDiscountList: tempOrder.discount_list,
787
- tempOrder
788
- });
789
- } catch (error) {
790
- throw error;
791
- }
792
- }
793
- async applyDiscountCalculationResult(result) {
794
- try {
795
- if (!this.store.order)
796
- throw new Error("order 模块未初始化");
797
- if (!result)
798
- return;
799
- const tempOrder = this.store.order.ensureTempOrder();
800
- const orderStore = this.store.order.store || {};
801
- const discountModule = orderStore.discount;
802
- if (result.productList) {
803
- tempOrder.products = result.productList;
804
- }
805
- if (result.discountList) {
806
- import_Order.OrderModule.populateSavedAmounts(
807
- tempOrder.products,
808
- result.discountList
809
- );
810
- await (discountModule == null ? void 0 : discountModule.setDiscountList(result.discountList));
811
- tempOrder.discount_list = result.discountList.filter(
812
- (discount) => discount.isSelected
813
- );
814
- }
815
- await this.store.order.recalculateSummary({ createIfMissing: true });
816
- this.store.order.persistTempOrder();
817
493
  } catch (error) {
818
494
  throw error;
819
495
  }
@@ -828,7 +504,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
828
504
  * payments 会交给 OrderModule 统一映射为 Sales 协议支付项。
829
505
  */
830
506
  async submitSalesOrder(params) {
831
- var _a, _b, _c;
507
+ var _a, _b, _c, _d;
832
508
  if (!this.store.order) {
833
509
  throw new Error("BaseSales 解决方案需要 order 模块支持");
834
510
  }
@@ -837,57 +513,19 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
837
513
  cacheId: this.cacheId,
838
514
  platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
839
515
  businessCode: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
840
- channel: this.getSubmitOrderSalesChannel(),
841
- type: (_c = this.otherParams) == null ? void 0 : _c.type,
516
+ channel: (_c = this.otherParams) == null ? void 0 : _c.channel,
517
+ type: (_d = this.otherParams) == null ? void 0 : _d.type,
842
518
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
843
519
  ...(params == null ? void 0 : params.paymentStatus) !== void 0 ? { paymentStatus: params.paymentStatus } : {},
844
520
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
845
521
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
846
522
  };
847
- console.log(submitParams, "submitParams123");
848
523
  return this.store.order.submitTempOrder(submitParams);
849
524
  }
850
525
  async syncPaymentsToOrder(params) {
851
526
  if (!this.store.order)
852
527
  throw new Error("order 模块未初始化");
853
- const channel = params.channel ?? this.getSubmitOrderSalesChannel();
854
- const syncParams = {
855
- ...params,
856
- ...channel !== void 0 ? { channel } : {}
857
- };
858
- const syncState = this.store.order.getOrderSyncState();
859
- if (params.submitWhenPaid && syncState === "submitting") {
860
- return this.store.order.syncPaymentsToOrder(syncParams);
861
- }
862
- const payments = params.payments || [];
863
- await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncStart, {
864
- payments,
865
- params: syncParams,
866
- amountSnapshot: this.store.order.getOrderAmountSnapshot(),
867
- orderSnapshot: this.store.order.getOrderSnapshot()
868
- });
869
- try {
870
- const syncResult = await this.store.order.syncPaymentsToOrder(syncParams);
871
- await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
872
- ok: true,
873
- syncResult,
874
- payments: this.store.order.getOrderPayments(),
875
- params: syncParams,
876
- amountSnapshot: this.store.order.getOrderAmountSnapshot(),
877
- orderSnapshot: this.store.order.getOrderSnapshot()
878
- });
879
- return syncResult;
880
- } catch (error) {
881
- await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
882
- ok: false,
883
- error,
884
- payments: this.store.order.getOrderPayments(),
885
- params: syncParams,
886
- amountSnapshot: this.store.order.getOrderAmountSnapshot(),
887
- orderSnapshot: this.store.order.getOrderSnapshot()
888
- });
889
- throw error;
890
- }
528
+ return this.store.order.syncPaymentsToOrder(params);
891
529
  }
892
530
  /** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
893
531
  getOrderPayments() {
@@ -905,23 +543,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
905
543
  addOrderPayment(payment) {
906
544
  if (!this.store.order)
907
545
  throw new Error("order 模块未初始化");
908
- const payments = this.store.order.addOrderPayment(payment);
909
- const amountSnapshot = this.store.order.getOrderAmountSnapshot();
910
- const syncState = this.store.order.getOrderSyncState();
911
- if (amountSnapshot && syncState !== "submitting") {
912
- const paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? "paid" : "partially_paid";
913
- void this.syncPaymentsToOrder({
914
- payments,
915
- paymentStatus,
916
- submitWhenPaid: true,
917
- smallTicketDataFlag: 1
918
- }).catch((error) => {
919
- this.logError("auto sync payments failed", {
920
- error: error instanceof Error ? error.message : String(error)
921
- });
922
- });
923
- }
924
- return payments;
546
+ return this.store.order.addOrderPayment(payment);
925
547
  }
926
548
  /** 更新当前订单中的指定支付项。 */
927
549
  updateOrderPayment(paymentIdentity, updates) {
@@ -956,7 +578,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
956
578
  is_charge_tax: product.is_charge_tax ?? 0,
957
579
  tax_fee: product.tax_fee,
958
580
  selling_price: Number(product.selling_price || 0),
959
- discount_list: product.discount_list || [],
960
581
  holder_id: product.holder_id ?? metadata.holder_id,
961
582
  original_price: product.original_price,
962
583
  main_product_original_price: metadata.main_product_original_price ?? product.original_price,
@@ -970,10 +591,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
970
591
  const bundleMetadata = bundle.metadata || {};
971
592
  return {
972
593
  is_price_include_tax: tempOrder.is_price_include_tax,
973
- // 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
974
- bundle_id: bundle.bundle_id ?? bundle.id,
975
- bundle_product_id: bundle.bundle_product_id ?? bundle._bundle_product_id,
976
- bundle_group_id: bundle.bundle_group_id ?? bundle.group_id,
594
+ bundle_id: bundle.bundle_id,
595
+ bundle_product_id: bundle.bundle_product_id,
977
596
  bundle_variant_id: bundle.bundle_variant_id,
978
597
  price_type: bundle.price_type,
979
598
  price_type_ext: bundle.price_type_ext,
@@ -1112,20 +731,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1112
731
  transformBaseProductToOrderProduct(params) {
1113
732
  return (0, import_transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
1114
733
  }
1115
- async calculateProductBookingPrice(params) {
1116
- const quotation = this.store.quotation;
1117
- const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
1118
- await this.loadQuotationForPriceQuery({
1119
- quotation,
1120
- customer_id: customerId,
1121
- channel: params.channel
1122
- });
1123
- return (0, import_quotationPrice.calculateBaseSalesProductBookingPrice)({
1124
- ...params,
1125
- customer_id: customerId,
1126
- quotation
1127
- });
1128
- }
1129
734
  async addProductToOrder(product, booking) {
1130
735
  try {
1131
736
  if (!this.store.order)
@@ -1136,35 +741,16 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1136
741
  throw error;
1137
742
  }
1138
743
  }
1139
- async updateOrderProduct(params) {
744
+ async updateProductInOrder(params) {
1140
745
  try {
1141
746
  if (!this.store.order)
1142
747
  throw new Error("order 模块未初始化");
1143
- const products = await this.store.order.updateOrderProduct(params);
748
+ const products = await this.store.order.updateProductInOrder(params);
1144
749
  return products;
1145
750
  } catch (error) {
1146
751
  throw error;
1147
752
  }
1148
753
  }
1149
- async updateOrderProductQuantity(params) {
1150
- try {
1151
- if (!this.store.order)
1152
- throw new Error("order 模块未初始化");
1153
- const products = await this.store.order.updateOrderProductQuantity(params);
1154
- return products;
1155
- } catch (error) {
1156
- throw error;
1157
- }
1158
- }
1159
- updateOrderBooking(params) {
1160
- try {
1161
- if (!this.store.order)
1162
- throw new Error("order 模块未初始化");
1163
- return this.store.order.updateOrderBooking(params);
1164
- } catch (error) {
1165
- throw error;
1166
- }
1167
- }
1168
754
  /**
1169
755
  * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
1170
756
  * 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
@@ -1184,7 +770,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1184
770
  }
1185
771
  if (identity.product_bundle !== void 0)
1186
772
  params.product_bundle = identity.product_bundle;
1187
- const products = await this.updateOrderProduct(params);
773
+ const products = await this.updateProductInOrder(params);
1188
774
  return products;
1189
775
  } catch (error) {
1190
776
  throw error;