@pisell/pisellos 2.2.163 → 2.2.165

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 (124) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +157 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +191 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.js +23 -22
  32. package/dist/modules/Discount/index.js +4 -3
  33. package/dist/modules/Order/index.d.ts +25 -7
  34. package/dist/modules/Order/index.js +608 -291
  35. package/dist/modules/Order/types.d.ts +46 -14
  36. package/dist/modules/Order/types.js +2 -0
  37. package/dist/modules/Order/utils.d.ts +10 -0
  38. package/dist/modules/Order/utils.js +76 -23
  39. package/dist/modules/SalesSummary/index.js +4 -2
  40. package/dist/modules/index.d.ts +1 -0
  41. package/dist/modules/index.js +2 -1
  42. package/dist/solution/BaseSales/index.d.ts +46 -7
  43. package/dist/solution/BaseSales/index.js +928 -312
  44. package/dist/solution/BaseSales/types.d.ts +51 -1
  45. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  46. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +33 -14
  48. package/dist/solution/BaseSales/utils.js +36 -7
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingTicket/index.d.ts +124 -1
  51. package/dist/solution/BookingTicket/index.js +488 -90
  52. package/dist/solution/BookingTicket/types.d.ts +2 -0
  53. package/dist/solution/BookingTicket/types.js +3 -0
  54. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  55. package/dist/solution/BookingTicket/utils/addProductDecision.js +334 -0
  56. package/dist/solution/ScanOrder/index.d.ts +9 -3
  57. package/dist/solution/ScanOrder/index.js +231 -128
  58. package/dist/solution/ScanOrder/utils.js +36 -7
  59. package/dist/solution/VenueBooking/index.d.ts +4 -2
  60. package/dist/solution/VenueBooking/index.js +103 -55
  61. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  62. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  63. package/lib/modules/BookingContext/index.d.ts +37 -0
  64. package/lib/modules/BookingContext/index.js +297 -0
  65. package/lib/modules/BookingContext/types.d.ts +102 -0
  66. package/lib/modules/BookingContext/types.js +34 -0
  67. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  68. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +174 -0
  69. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  70. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  71. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  72. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +177 -0
  73. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  74. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  75. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  76. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  77. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  78. package/lib/modules/BookingContext/utils/index.js +43 -0
  79. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  80. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  81. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  82. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  83. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  84. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  85. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  86. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  87. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  88. package/lib/modules/BookingContext/utils/resources.js +377 -0
  89. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  90. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  91. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  92. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  93. package/lib/modules/Customer/index.js +8 -8
  94. package/lib/modules/Discount/index.js +5 -1
  95. package/lib/modules/Order/index.d.ts +25 -7
  96. package/lib/modules/Order/index.js +268 -72
  97. package/lib/modules/Order/types.d.ts +46 -14
  98. package/lib/modules/Order/utils.d.ts +10 -0
  99. package/lib/modules/Order/utils.js +66 -15
  100. package/lib/modules/SalesSummary/index.js +4 -2
  101. package/lib/modules/index.d.ts +1 -0
  102. package/lib/modules/index.js +3 -1
  103. package/lib/solution/BaseSales/index.d.ts +46 -7
  104. package/lib/solution/BaseSales/index.js +369 -17
  105. package/lib/solution/BaseSales/types.d.ts +51 -1
  106. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  107. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  108. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +31 -10
  109. package/lib/solution/BaseSales/utils.js +37 -5
  110. package/lib/solution/BookingByStep/index.d.ts +1 -1
  111. package/lib/solution/BookingTicket/index.d.ts +124 -1
  112. package/lib/solution/BookingTicket/index.js +255 -8
  113. package/lib/solution/BookingTicket/types.d.ts +2 -0
  114. package/lib/solution/BookingTicket/types.js +6 -0
  115. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  116. package/lib/solution/BookingTicket/utils/addProductDecision.js +308 -0
  117. package/lib/solution/ScanOrder/index.d.ts +9 -3
  118. package/lib/solution/ScanOrder/index.js +147 -66
  119. package/lib/solution/ScanOrder/utils.js +37 -5
  120. package/lib/solution/VenueBooking/index.d.ts +4 -2
  121. package/lib/solution/VenueBooking/index.js +50 -14
  122. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  123. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  124. package/package.json +1 -1
@@ -40,7 +40,9 @@ var import_types = require("../BookingByStep/types");
40
40
  var import_utils = require("../../modules/Order/utils");
41
41
  var import_dayjs = __toESM(require("dayjs"));
42
42
  __reExport(BaseSales_exports, require("./types"), module.exports);
43
+ var import_Quotation = require("../../modules/Quotation");
43
44
  var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
45
+ var import_quotationPrice = require("./utils/quotationPrice");
44
46
  var BaseSalesImpl = class extends import_BaseModule.BaseModule {
45
47
  constructor(name, version) {
46
48
  super(name, version);
@@ -48,7 +50,6 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
48
50
  this.defaultVersion = "1.0.0";
49
51
  this.isSolution = true;
50
52
  this.initializeOptions = {};
51
- // LoggerManager 实例
52
53
  this.store = {
53
54
  order: void 0
54
55
  };
@@ -58,10 +59,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
58
59
  }
59
60
  /**
60
61
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
61
- * 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
62
+ * 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation
62
63
  */
63
64
  getRegisteredModuleNames() {
64
- return ["products", "order", "salesSummary", "schedule", "payment"];
65
+ return ["products", "order", "salesSummary", "schedule", "payment", "quotation"];
65
66
  }
66
67
  /**
67
68
  * 记录信息日志
@@ -105,12 +106,47 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
105
106
  get payment() {
106
107
  return this.store.payment;
107
108
  }
109
+ getCurrentOrderCustomerId() {
110
+ var _a, _b;
111
+ const tempOrder = (_b = (_a = this.store.order) == null ? void 0 : _a.getTempOrder) == null ? void 0 : _b.call(_a);
112
+ const customerId = tempOrder == null ? void 0 : tempOrder.customer_id;
113
+ if (customerId === null || customerId === void 0)
114
+ return void 0;
115
+ return customerId;
116
+ }
117
+ applyQuotationScheduleResolver(quotation) {
118
+ const scheduleModule = this.store.schedule;
119
+ if (!scheduleModule)
120
+ return;
121
+ quotation.setScheduleResolver((id) => {
122
+ var _a;
123
+ const schedules = ((_a = scheduleModule.getScheduleListByIds) == null ? void 0 : _a.call(scheduleModule, [id])) || [];
124
+ return schedules[0];
125
+ });
126
+ }
127
+ async loadQuotationForPriceQuery(params) {
128
+ var _a;
129
+ if (!params.quotation)
130
+ return;
131
+ this.applyQuotationScheduleResolver(params.quotation);
132
+ await params.quotation.loadQuotations({
133
+ channel: params.channel || ((_a = this.otherParams) == null ? void 0 : _a.channel),
134
+ customer_id: params.customer_id
135
+ });
136
+ }
137
+ getSubmitOrderSalesChannel() {
138
+ var _a;
139
+ return (_a = this.otherParams) == null ? void 0 : _a.channel;
140
+ }
108
141
  /**
109
142
  * 工厂入口:根据子模块名实例化对应模块。
110
143
  * 默认使用 BookingByStep 公共 `createModule`。子类若需引入额外类型(如 customer),
111
144
  * 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
112
145
  */
113
146
  createSubModule(moduleName) {
147
+ if (moduleName === "quotation") {
148
+ return new import_Quotation.QuotationModule(`${this.name}_quotation`);
149
+ }
114
150
  return (0, import_types.createModule)(moduleName, this.name);
115
151
  }
116
152
  getSubModuleHooks(moduleName) {
@@ -140,6 +176,43 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
140
176
  return {};
141
177
  }
142
178
  }
179
+ getAppData(key) {
180
+ var _a, _b, _c, _d, _e, _f;
181
+ const getData = (_b = (_a = this.appPlugin).getData) == null ? void 0 : _b.call(_a);
182
+ if (typeof getData === "function")
183
+ return getData(key);
184
+ const app = this.appPlugin.getApp();
185
+ 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");
186
+ return coreData == null ? void 0 : coreData[key];
187
+ }
188
+ syncAppDataToTempOrder(tempOrder) {
189
+ const taxCountryCode = this.getAppData("tax_country_code");
190
+ const currencyCode = this.getAppData("shop_currency_code");
191
+ const currencySymbol = this.getAppData("shop_symbol");
192
+ let isChanged = false;
193
+ if (taxCountryCode !== void 0) {
194
+ const nextTaxCountryCode = String(taxCountryCode || "");
195
+ if (tempOrder.tax_country_code !== nextTaxCountryCode) {
196
+ tempOrder.tax_country_code = nextTaxCountryCode;
197
+ isChanged = true;
198
+ }
199
+ }
200
+ if (currencyCode !== void 0) {
201
+ const nextCurrencyCode = String(currencyCode || "");
202
+ if (tempOrder.currency_code !== nextCurrencyCode) {
203
+ tempOrder.currency_code = nextCurrencyCode;
204
+ isChanged = true;
205
+ }
206
+ }
207
+ if (currencySymbol !== void 0) {
208
+ const nextCurrencySymbol = String(currencySymbol || "");
209
+ if (tempOrder.currency_symbol !== nextCurrencySymbol) {
210
+ tempOrder.currency_symbol = nextCurrencySymbol;
211
+ isChanged = true;
212
+ }
213
+ }
214
+ return isChanged;
215
+ }
143
216
  async initialize(core, options = {}) {
144
217
  var _a;
145
218
  this.core = core;
@@ -148,11 +221,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
148
221
  this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
149
222
  this.window = core.getPlugin("window");
150
223
  this.request = core.getPlugin("request");
151
- const appPlugin = core.getPlugin("app");
152
- if (!appPlugin) {
224
+ this.appPlugin = core.getPlugin("app");
225
+ if (!this.appPlugin) {
153
226
  throw new Error("Checkout 解决方案需要 app 插件支持");
154
227
  }
155
- const app = appPlugin.getApp();
228
+ const app = this.appPlugin.getApp();
156
229
  this.logger = app.logger;
157
230
  const targetCacheData = this.readSessionCacheData();
158
231
  const moduleNames = this.getRegisteredModuleNames();
@@ -286,6 +359,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
286
359
  const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
287
360
  return result;
288
361
  }
362
+ async replaceTempOrder(tempOrder) {
363
+ if (!this.store.order)
364
+ throw new Error("order 模块未初始化");
365
+ const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder);
366
+ await this.effectsEmit("onTempOrderReplaced", { tempOrder: nextTempOrder });
367
+ return nextTempOrder;
368
+ }
289
369
  getOrderIdentity() {
290
370
  if (!this.store.order)
291
371
  return null;
@@ -311,16 +391,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
311
391
  return "";
312
392
  return this.store.order.getTempOrderNote();
313
393
  }
314
- updateTempOrderNote(note) {
394
+ updateTempOrderNote(note, sync = false) {
315
395
  try {
316
396
  if (!this.store.order)
317
397
  throw new Error("order 模块未初始化");
318
- const result = this.store.order.updateTempOrderNote(note);
398
+ const result = this.store.order.updateTempOrderNote(note, sync);
319
399
  return result;
320
400
  } catch (error) {
321
401
  throw error;
322
402
  }
323
403
  }
404
+ updateRemoteOrderNote(orderId, note) {
405
+ if (!this.store.order)
406
+ throw new Error("order 模块未初始化");
407
+ this.store.order.syncTempOrderNoteToRemote(orderId, note);
408
+ }
324
409
  updateTempOrderShopDiscount(amount) {
325
410
  if (!this.store.order)
326
411
  throw new Error("order 模块未初始化");
@@ -342,6 +427,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
342
427
  if (!this.store.order)
343
428
  throw new Error("order 模块未初始化");
344
429
  const tempOrder = await this.store.order.addNewOrder();
430
+ if (this.syncAppDataToTempOrder(tempOrder)) {
431
+ this.store.order.persistTempOrder();
432
+ await this.store.order.saveDraft();
433
+ }
345
434
  return tempOrder;
346
435
  } catch (error) {
347
436
  throw error;
@@ -360,6 +449,41 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
360
449
  throw new Error("scanOrder 解决方案需要 order 模块支持");
361
450
  }
362
451
  const tempOrder = this.store.order.restoreOrder();
452
+ this.currentSalesDetail = null;
453
+ await this.effectsEmit("onTempOrderReplaced", { tempOrder });
454
+ if (this.syncAppDataToTempOrder(tempOrder)) {
455
+ this.store.order.persistTempOrder();
456
+ await this.store.order.saveDraft();
457
+ }
458
+ return tempOrder;
459
+ } catch (error) {
460
+ throw error;
461
+ }
462
+ }
463
+ /**
464
+ * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
465
+ * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
466
+ */
467
+ async clearOrderCartLines() {
468
+ try {
469
+ if (!this.store.order)
470
+ throw new Error("order 模块未初始化");
471
+ const tempOrder = await this.store.order.clearOrderCartLines();
472
+ if (this.currentSalesDetail) {
473
+ this.currentSalesDetail = {
474
+ ...this.currentSalesDetail,
475
+ products: [],
476
+ bookings: [],
477
+ rootBooking: null,
478
+ bookingsByProductUid: {},
479
+ discount_list: []
480
+ };
481
+ }
482
+ await this.effectsEmit("onTempOrderReplaced", { tempOrder });
483
+ if (this.syncAppDataToTempOrder(tempOrder)) {
484
+ this.store.order.persistTempOrder();
485
+ await this.store.order.saveDraft();
486
+ }
363
487
  return tempOrder;
364
488
  } catch (error) {
365
489
  throw error;
@@ -381,6 +505,165 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
381
505
  throw error;
382
506
  }
383
507
  }
508
+ getHistoricalProductDiscountList(products) {
509
+ const historyDiscountList = [];
510
+ products.forEach((item) => {
511
+ if (!this.isPersistedOrderProduct(item))
512
+ return;
513
+ (item.discount_list || []).forEach((discount) => {
514
+ var _a, _b, _c, _d, _e, _f;
515
+ const discountId = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
516
+ if (!discountId || !["good_pass", "discount_card"].includes(discount.type))
517
+ return;
518
+ const quantity = item.quantity || item.num || item.product_quantity || 1;
519
+ 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);
520
+ const index = historyDiscountList.findIndex((n) => n.id === discountId);
521
+ if (index !== -1) {
522
+ historyDiscountList[index] = {
523
+ ...historyDiscountList[index],
524
+ amount: new import_decimal.default(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
525
+ savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
526
+ };
527
+ return;
528
+ }
529
+ historyDiscountList.push({
530
+ ...discount,
531
+ id: discountId,
532
+ tag: discount.tag || discount.type,
533
+ name: discount.name || ((_d = (_c = discount.discount) == null ? void 0 : _c.title) == null ? void 0 : _d.auto),
534
+ format_title: ((_e = discount.discount) == null ? void 0 : _e.title) || discount.format_title,
535
+ isEditMode: true,
536
+ limited_relation_product_data: {},
537
+ savedAmount: savedAmount.toNumber(),
538
+ isAvailable: true,
539
+ isDisabled: true,
540
+ isSelected: true,
541
+ product_id: ((_f = discount.discount) == null ? void 0 : _f.product_id) || discount.product_id
542
+ });
543
+ });
544
+ });
545
+ return historyDiscountList;
546
+ }
547
+ isPersistedOrderProduct(product) {
548
+ const orderDetailId = product.order_detail_id ?? product.orderDetailId;
549
+ if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
550
+ return true;
551
+ }
552
+ const bookingId = product.booking_id ?? product.bookingId;
553
+ return bookingId !== void 0 && bookingId !== null && bookingId !== "";
554
+ }
555
+ mergeHistoricalDiscountList(discountList, products) {
556
+ const historyDiscountList = this.getHistoricalProductDiscountList(products);
557
+ const historyIds = new Set(historyDiscountList.map((discount) => discount.id));
558
+ return [
559
+ ...historyDiscountList,
560
+ ...(discountList || []).filter((discount) => !historyIds.has(discount.id))
561
+ ];
562
+ }
563
+ async loadDiscountConfig(params) {
564
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
565
+ if (!this.store.order)
566
+ throw new Error("order 模块未初始化");
567
+ const tempOrder = this.store.order.ensureTempOrder();
568
+ const orderStore = this.store.order.store || {};
569
+ const discountModule = orderStore.discount;
570
+ const rulesModule = orderStore.rules;
571
+ const orderId = tempOrder.order_id || ((_b = (_a = this.getOrderIdentity) == null ? void 0 : _a.call(this)) == null ? void 0 : _b.orderId);
572
+ const customerId = Number(
573
+ (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
574
+ );
575
+ let preparedDiscountList = [];
576
+ if (customerId && customerId !== 1) {
577
+ preparedDiscountList = await this.store.order.loadDiscountConfig({
578
+ customerId,
579
+ action: (params == null ? void 0 : params.action) || (orderId ? "edit" : "create"),
580
+ orderId: Number(orderId) || void 0,
581
+ apply: false
582
+ });
583
+ await ((_h = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _h.call(discountModule, preparedDiscountList));
584
+ }
585
+ let nextDiscountList = this.mergeHistoricalDiscountList(
586
+ preparedDiscountList || ((_i = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _i.call(discountModule)) || [],
587
+ tempOrder.products || []
588
+ );
589
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
590
+ if (rulesModule) {
591
+ const holders = ((_j = tempOrder.holder) == null ? void 0 : _j.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
592
+ const result = rulesModule.calcDiscount({
593
+ productList: tempOrder.products,
594
+ discountList: nextDiscountList,
595
+ holders,
596
+ isFormSubject: !!((_k = tempOrder.holder) == null ? void 0 : _k.type) && tempOrder.holder.type === "form",
597
+ orderTotalAmount: Number(((_l = orderStore.summary) == null ? void 0 : _l.total_amount) || 0)
598
+ }) || { productList: tempOrder.products, discountList: nextDiscountList };
599
+ if (result.productList) {
600
+ tempOrder.products = result.productList;
601
+ }
602
+ if (result.discountList) {
603
+ nextDiscountList = this.mergeHistoricalDiscountList(
604
+ result.discountList,
605
+ tempOrder.products || []
606
+ );
607
+ import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
608
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
609
+ tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
610
+ }
611
+ }
612
+ this.store.order.persistTempOrder();
613
+ return {
614
+ productList: tempOrder.products || [],
615
+ discountList: nextDiscountList
616
+ };
617
+ }
618
+ async bestDiscount(cb) {
619
+ var _a, _b, _c, _d;
620
+ if (!this.store.order)
621
+ throw new Error("order 模块未初始化");
622
+ const tempOrder = this.store.order.ensureTempOrder();
623
+ const orderStore = this.store.order.store || {};
624
+ const discountModule = orderStore.discount;
625
+ const rulesModule = orderStore.rules;
626
+ const originalDiscountList = ((_a = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _a.call(discountModule)) || this.getDiscountList();
627
+ let nextDiscountList = this.mergeHistoricalDiscountList(
628
+ originalDiscountList || [],
629
+ tempOrder.products || []
630
+ );
631
+ let result = {
632
+ productList: tempOrder.products || [],
633
+ discountList: nextDiscountList
634
+ };
635
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
636
+ if (rulesModule) {
637
+ const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
638
+ result = rulesModule.calcDiscount({
639
+ productList: tempOrder.products,
640
+ discountList: nextDiscountList,
641
+ holders,
642
+ isFormSubject: !!((_c = tempOrder.holder) == null ? void 0 : _c.type) && tempOrder.holder.type === "form",
643
+ orderTotalAmount: Number(((_d = orderStore.summary) == null ? void 0 : _d.total_amount) || 0)
644
+ }) || result;
645
+ if (result.productList) {
646
+ tempOrder.products = result.productList;
647
+ }
648
+ if (result.discountList) {
649
+ nextDiscountList = this.mergeHistoricalDiscountList(
650
+ result.discountList,
651
+ tempOrder.products || []
652
+ );
653
+ import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
654
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
655
+ tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
656
+ result = {
657
+ productList: tempOrder.products,
658
+ discountList: nextDiscountList
659
+ };
660
+ }
661
+ }
662
+ await this.store.order.recalculateSummary({ createIfMissing: true });
663
+ this.store.order.persistTempOrder();
664
+ cb == null ? void 0 : cb(result);
665
+ return result;
666
+ }
384
667
  getDiscountList() {
385
668
  if (!this.store.order)
386
669
  return [];
@@ -494,6 +777,34 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
494
777
  throw error;
495
778
  }
496
779
  }
780
+ async applyDiscountCalculationResult(result) {
781
+ try {
782
+ if (!this.store.order)
783
+ throw new Error("order 模块未初始化");
784
+ if (!result)
785
+ return;
786
+ const tempOrder = this.store.order.ensureTempOrder();
787
+ const orderStore = this.store.order.store || {};
788
+ const discountModule = orderStore.discount;
789
+ if (result.productList) {
790
+ tempOrder.products = result.productList;
791
+ }
792
+ if (result.discountList) {
793
+ import_Order.OrderModule.populateSavedAmounts(
794
+ tempOrder.products,
795
+ result.discountList
796
+ );
797
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(result.discountList));
798
+ tempOrder.discount_list = result.discountList.filter(
799
+ (discount) => discount.isSelected
800
+ );
801
+ }
802
+ await this.store.order.recalculateSummary({ createIfMissing: true });
803
+ this.store.order.persistTempOrder();
804
+ } catch (error) {
805
+ throw error;
806
+ }
807
+ }
497
808
  async submitScanOrder(params) {
498
809
  return this.submitSalesOrder(params);
499
810
  }
@@ -504,7 +815,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
504
815
  * payments 会交给 OrderModule 统一映射为 Sales 协议支付项。
505
816
  */
506
817
  async submitSalesOrder(params) {
507
- var _a, _b, _c, _d;
818
+ var _a, _b, _c;
508
819
  if (!this.store.order) {
509
820
  throw new Error("BaseSales 解决方案需要 order 模块支持");
510
821
  }
@@ -513,19 +824,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
513
824
  cacheId: this.cacheId,
514
825
  platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
515
826
  businessCode: (_b = this.otherParams) == null ? void 0 : _b.businessCode,
516
- channel: (_c = this.otherParams) == null ? void 0 : _c.channel,
517
- type: (_d = this.otherParams) == null ? void 0 : _d.type,
827
+ channel: this.getSubmitOrderSalesChannel(),
828
+ type: (_c = this.otherParams) == null ? void 0 : _c.type,
518
829
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
519
830
  ...(params == null ? void 0 : params.paymentStatus) !== void 0 ? { paymentStatus: params.paymentStatus } : {},
520
831
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
521
832
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
522
833
  };
834
+ console.log(submitParams, "submitParams123");
523
835
  return this.store.order.submitTempOrder(submitParams);
524
836
  }
525
837
  async syncPaymentsToOrder(params) {
526
838
  if (!this.store.order)
527
839
  throw new Error("order 模块未初始化");
528
- return this.store.order.syncPaymentsToOrder(params);
840
+ const channel = params.channel ?? this.getSubmitOrderSalesChannel();
841
+ return this.store.order.syncPaymentsToOrder({
842
+ ...params,
843
+ ...channel !== void 0 ? { channel } : {}
844
+ });
529
845
  }
530
846
  /** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
531
847
  getOrderPayments() {
@@ -578,6 +894,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
578
894
  is_charge_tax: product.is_charge_tax ?? 0,
579
895
  tax_fee: product.tax_fee,
580
896
  selling_price: Number(product.selling_price || 0),
897
+ discount_list: product.discount_list || [],
581
898
  holder_id: product.holder_id ?? metadata.holder_id,
582
899
  original_price: product.original_price,
583
900
  main_product_original_price: metadata.main_product_original_price ?? product.original_price,
@@ -591,8 +908,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
591
908
  const bundleMetadata = bundle.metadata || {};
592
909
  return {
593
910
  is_price_include_tax: tempOrder.is_price_include_tax,
594
- bundle_id: bundle.bundle_id,
595
- bundle_product_id: bundle.bundle_product_id,
911
+ // 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
912
+ bundle_id: bundle.bundle_id ?? bundle.id,
913
+ bundle_product_id: bundle.bundle_product_id ?? bundle._bundle_product_id,
914
+ bundle_group_id: bundle.bundle_group_id ?? bundle.group_id,
596
915
  bundle_variant_id: bundle.bundle_variant_id,
597
916
  price_type: bundle.price_type,
598
917
  price_type_ext: bundle.price_type_ext,
@@ -731,6 +1050,20 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
731
1050
  transformBaseProductToOrderProduct(params) {
732
1051
  return (0, import_transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
733
1052
  }
1053
+ async calculateProductBookingPrice(params) {
1054
+ const quotation = this.store.quotation;
1055
+ const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
1056
+ await this.loadQuotationForPriceQuery({
1057
+ quotation,
1058
+ customer_id: customerId,
1059
+ channel: params.channel
1060
+ });
1061
+ return (0, import_quotationPrice.calculateBaseSalesProductBookingPrice)({
1062
+ ...params,
1063
+ customer_id: customerId,
1064
+ quotation
1065
+ });
1066
+ }
734
1067
  async addProductToOrder(product, booking) {
735
1068
  try {
736
1069
  if (!this.store.order)
@@ -741,16 +1074,35 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
741
1074
  throw error;
742
1075
  }
743
1076
  }
744
- async updateProductInOrder(params) {
1077
+ async updateOrderProduct(params) {
1078
+ try {
1079
+ if (!this.store.order)
1080
+ throw new Error("order 模块未初始化");
1081
+ const products = await this.store.order.updateOrderProduct(params);
1082
+ return products;
1083
+ } catch (error) {
1084
+ throw error;
1085
+ }
1086
+ }
1087
+ async updateOrderProductQuantity(params) {
745
1088
  try {
746
1089
  if (!this.store.order)
747
1090
  throw new Error("order 模块未初始化");
748
- const products = await this.store.order.updateProductInOrder(params);
1091
+ const products = await this.store.order.updateOrderProductQuantity(params);
749
1092
  return products;
750
1093
  } catch (error) {
751
1094
  throw error;
752
1095
  }
753
1096
  }
1097
+ updateOrderBooking(params) {
1098
+ try {
1099
+ if (!this.store.order)
1100
+ throw new Error("order 模块未初始化");
1101
+ return this.store.order.updateOrderBooking(params);
1102
+ } catch (error) {
1103
+ throw error;
1104
+ }
1105
+ }
754
1106
  /**
755
1107
  * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
756
1108
  * 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
@@ -770,7 +1122,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
770
1122
  }
771
1123
  if (identity.product_bundle !== void 0)
772
1124
  params.product_bundle = identity.product_bundle;
773
- const products = await this.updateProductInOrder(params);
1125
+ const products = await this.updateOrderProduct(params);
774
1126
  return products;
775
1127
  } catch (error) {
776
1128
  throw error;
@@ -1,4 +1,4 @@
1
- import { OrderModule, ProductList, SalesSummaryModule, ScanOrderLoggerModule as BaseSalesLoggerModule, ScheduleModule } from '../../modules';
1
+ import { OrderModule, ProductList, QuotationModule, SalesSummaryModule, ScanOrderLoggerModule as BaseSalesLoggerModule, ScheduleModule } from '../../modules';
2
2
  import type { ScanOrderLogInput as BaseSalesLogInput, ScanOrderLoggerProviderConfig as BaseSalesLoggerProviderConfig, ScanOrderLoggerProviderType as BaseSalesLoggerProviderType } from '../../modules/ScanOrderLogger/types';
3
3
  import type { QuantityCheckResult, QuantityLimitResult } from '../../model/strategy/adapter/itemRule';
4
4
  /**
@@ -42,6 +42,9 @@ export interface BaseSalesOrderProductIdentity {
42
42
  product_option_item?: any[];
43
43
  product_bundle?: any[];
44
44
  }
45
+ export interface BaseSalesUpdateOrderProductQuantityParams extends BaseSalesOrderProductIdentity {
46
+ num: number;
47
+ }
45
48
  export interface BaseSalesOrderProduct extends BaseSalesOrderProductIdentity {
46
49
  order_detail_id: number | null;
47
50
  num: number;
@@ -203,6 +206,52 @@ export interface BaseSalesSubmitPayload extends Omit<BaseSalesTempOrder, 'platfo
203
206
  }>;
204
207
  products: BaseSalesSubmitProduct[];
205
208
  }
209
+ export interface BaseSalesQuotationDurationConfig {
210
+ type: string;
211
+ value: number;
212
+ flexible_config?: {
213
+ is_enable_minimum_duration?: 0 | 1;
214
+ warning_threshold?: number;
215
+ block_threshold?: number;
216
+ };
217
+ }
218
+ export interface BaseSalesCalculateProductBookingPriceParams {
219
+ product: Record<string, any>;
220
+ booking?: {
221
+ start_date?: string;
222
+ start_time?: string;
223
+ end_date?: string;
224
+ end_time?: string;
225
+ [key: string]: any;
226
+ };
227
+ duration?: BaseSalesQuotationDurationConfig;
228
+ customer_id?: number | string;
229
+ fallback_price?: number | string;
230
+ datetime?: string;
231
+ channel?: string;
232
+ }
233
+ export type BaseSalesProductBookingPriceSegmentSource = 'quotation' | 'fallback';
234
+ export interface BaseSalesProductBookingPriceSegment {
235
+ start_datetime: string;
236
+ end_datetime?: string;
237
+ time_point: string;
238
+ unit_price: string;
239
+ quantity: number;
240
+ total_price: string;
241
+ quotation_shelf_id: number;
242
+ source: BaseSalesProductBookingPriceSegmentSource;
243
+ }
244
+ export interface BaseSalesProductBookingPriceResult {
245
+ product_id: number | null;
246
+ product_variant_id: number;
247
+ customer_id?: number | string;
248
+ unit_price: string;
249
+ total_price: string;
250
+ quantity: number;
251
+ duration?: BaseSalesQuotationDurationConfig;
252
+ quotation_shelf_id: number;
253
+ segments: BaseSalesProductBookingPriceSegment[];
254
+ }
206
255
  export type BaseSalesAvailabilityMode = 'idle' | 'shop_closed' | 'submit_disabled' | 'resource_busy' | 'additional_order_with_code' | 'additional_order';
207
256
  export interface BaseSalesTableFormRecord {
208
257
  policy?: string | null;
@@ -281,6 +330,7 @@ export interface BaseSalesState {
281
330
  error: string | null;
282
331
  products?: ProductList;
283
332
  order?: OrderModule;
333
+ quotation?: QuotationModule;
284
334
  salesSummary?: SalesSummaryModule;
285
335
  baseSalesLogger?: BaseSalesLoggerModule;
286
336
  schedule?: ScheduleModule;
@@ -0,0 +1,7 @@
1
+ import type { QuotationModule } from '../../../modules/Quotation';
2
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../types';
3
+ interface BuildBaseSalesQuotationPriceParams extends BaseSalesCalculateProductBookingPriceParams {
4
+ quotation?: Pick<QuotationModule, 'getPriceForProduct' | 'getQuotationShelfId'> | null;
5
+ }
6
+ export declare function calculateBaseSalesProductBookingPrice(params: BuildBaseSalesQuotationPriceParams): BaseSalesProductBookingPriceResult;
7
+ export {};