@pisell/pisellos 2.2.175 → 2.2.176

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 (172) 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 +193 -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 +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -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.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +84 -17
  38. package/dist/modules/Order/index.js +1239 -495
  39. package/dist/modules/Order/types.d.ts +198 -18
  40. package/dist/modules/Order/types.js +31 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +50 -1
  44. package/dist/modules/Order/utils.js +261 -31
  45. package/dist/modules/Quotation/index.d.ts +0 -1
  46. package/dist/modules/Quotation/index.js +23 -21
  47. package/dist/modules/Rules/index.d.ts +4 -0
  48. package/dist/modules/Rules/index.js +26 -10
  49. package/dist/modules/SalesSummary/index.js +4 -2
  50. package/dist/modules/SalesSummary/utils.js +3 -3
  51. package/dist/modules/Schedule/index.js +6 -2
  52. package/dist/modules/index.d.ts +1 -0
  53. package/dist/modules/index.js +2 -1
  54. package/dist/server/index.js +87 -29
  55. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  56. package/dist/server/modules/products/index.d.ts +1 -1
  57. package/dist/server/modules/products/index.js +130 -113
  58. package/dist/server/modules/schedule/index.js +13 -6
  59. package/dist/solution/BaseSales/index.d.ts +89 -7
  60. package/dist/solution/BaseSales/index.js +1484 -365
  61. package/dist/solution/BaseSales/types.d.ts +67 -1
  62. package/dist/solution/BaseSales/types.js +3 -1
  63. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  64. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  65. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  66. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  67. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  68. package/dist/solution/BaseSales/utils.js +46 -8
  69. package/dist/solution/BookingByStep/index.d.ts +1 -1
  70. package/dist/solution/BookingTicket/index.d.ts +133 -1
  71. package/dist/solution/BookingTicket/index.js +780 -175
  72. package/dist/solution/BookingTicket/types.d.ts +2 -0
  73. package/dist/solution/BookingTicket/types.js +3 -0
  74. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  75. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  76. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  77. package/dist/solution/ScanOrder/index.d.ts +9 -3
  78. package/dist/solution/ScanOrder/index.js +231 -128
  79. package/dist/solution/ScanOrder/utils.js +46 -8
  80. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  81. package/dist/solution/ShopDiscount/index.js +18 -23
  82. package/dist/solution/VenueBooking/index.d.ts +5 -9
  83. package/dist/solution/VenueBooking/index.js +103 -55
  84. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  85. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  86. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  87. package/lib/modules/BookingContext/index.d.ts +37 -0
  88. package/lib/modules/BookingContext/index.js +297 -0
  89. package/lib/modules/BookingContext/types.d.ts +102 -0
  90. package/lib/modules/BookingContext/types.js +34 -0
  91. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  92. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  93. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  94. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  95. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  96. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  97. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  98. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  99. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  100. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  101. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  102. package/lib/modules/BookingContext/utils/index.js +43 -0
  103. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  104. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  105. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  106. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  107. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  108. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  109. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  110. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  111. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  112. package/lib/modules/BookingContext/utils/resources.js +377 -0
  113. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  114. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  115. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  116. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  117. package/lib/modules/Customer/index.d.ts +6 -0
  118. package/lib/modules/Customer/index.js +26 -11
  119. package/lib/modules/Customer/types.d.ts +2 -0
  120. package/lib/modules/Discount/index.d.ts +2 -4
  121. package/lib/modules/Discount/index.js +8 -63
  122. package/lib/modules/Discount/types.d.ts +1 -7
  123. package/lib/modules/Order/index.d.ts +84 -17
  124. package/lib/modules/Order/index.js +588 -145
  125. package/lib/modules/Order/types.d.ts +198 -18
  126. package/lib/modules/Order/types.js +1 -0
  127. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  128. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  129. package/lib/modules/Order/utils.d.ts +50 -1
  130. package/lib/modules/Order/utils.js +229 -21
  131. package/lib/modules/Quotation/index.d.ts +0 -1
  132. package/lib/modules/Quotation/index.js +18 -15
  133. package/lib/modules/Rules/index.d.ts +4 -0
  134. package/lib/modules/Rules/index.js +22 -14
  135. package/lib/modules/SalesSummary/index.js +4 -2
  136. package/lib/modules/SalesSummary/utils.js +3 -3
  137. package/lib/modules/Schedule/index.js +3 -1
  138. package/lib/modules/index.d.ts +1 -0
  139. package/lib/modules/index.js +3 -1
  140. package/lib/server/index.js +41 -4
  141. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  142. package/lib/server/modules/products/index.d.ts +1 -1
  143. package/lib/server/modules/products/index.js +30 -20
  144. package/lib/server/modules/schedule/index.js +2 -1
  145. package/lib/solution/BaseSales/index.d.ts +89 -7
  146. package/lib/solution/BaseSales/index.js +736 -22
  147. package/lib/solution/BaseSales/types.d.ts +67 -1
  148. package/lib/solution/BaseSales/types.js +3 -1
  149. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  150. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  151. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  152. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  153. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  154. package/lib/solution/BaseSales/utils.js +46 -6
  155. package/lib/solution/BookingByStep/index.d.ts +1 -1
  156. package/lib/solution/BookingTicket/index.d.ts +133 -1
  157. package/lib/solution/BookingTicket/index.js +352 -8
  158. package/lib/solution/BookingTicket/types.d.ts +2 -0
  159. package/lib/solution/BookingTicket/types.js +6 -0
  160. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  161. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  162. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  163. package/lib/solution/ScanOrder/index.d.ts +9 -3
  164. package/lib/solution/ScanOrder/index.js +147 -66
  165. package/lib/solution/ScanOrder/utils.js +46 -6
  166. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  167. package/lib/solution/ShopDiscount/index.js +2 -4
  168. package/lib/solution/VenueBooking/index.d.ts +5 -9
  169. package/lib/solution/VenueBooking/index.js +50 -14
  170. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  171. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  172. package/package.json +2 -2
@@ -34,13 +34,16 @@ __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");
37
38
  var import_Order = require("../../modules/Order");
38
39
  var import_decimal = __toESM(require("decimal.js"));
39
- var import_types = require("../BookingByStep/types");
40
+ var import_types2 = require("../BookingByStep/types");
40
41
  var import_utils = require("../../modules/Order/utils");
41
42
  var import_dayjs = __toESM(require("dayjs"));
42
43
  __reExport(BaseSales_exports, require("./types"), module.exports);
44
+ var import_Quotation = require("../../modules/Quotation");
43
45
  var import_transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
46
+ var import_quotationPrice = require("./utils/quotationPrice");
44
47
  var BaseSalesImpl = class extends import_BaseModule.BaseModule {
45
48
  constructor(name, version) {
46
49
  super(name, version);
@@ -48,20 +51,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
48
51
  this.defaultVersion = "1.0.0";
49
52
  this.isSolution = true;
50
53
  this.initializeOptions = {};
51
- // LoggerManager 实例
52
54
  this.store = {
53
55
  order: void 0
54
56
  };
55
57
  this.otherParams = {};
56
58
  // 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
57
59
  this.currentSalesDetail = null;
60
+ this.discountConfigCacheKey = null;
61
+ this.hasManualDiscountSelection = false;
58
62
  }
59
63
  /**
60
64
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
61
- * 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
65
+ * 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation
62
66
  */
63
67
  getRegisteredModuleNames() {
64
- return ["products", "order", "salesSummary", "schedule", "payment"];
68
+ return ["products", "order", "salesSummary", "schedule", "payment", "quotation"];
65
69
  }
66
70
  /**
67
71
  * 记录信息日志
@@ -105,13 +109,182 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
105
109
  get payment() {
106
110
  return this.store.payment;
107
111
  }
112
+ getCurrentOrderCustomerId() {
113
+ var _a, _b;
114
+ const tempOrder = (_b = (_a = this.store.order) == null ? void 0 : _a.getTempOrder) == null ? void 0 : _b.call(_a);
115
+ const customerId = tempOrder == null ? void 0 : tempOrder.customer_id;
116
+ if (customerId === null || customerId === void 0)
117
+ return void 0;
118
+ return customerId;
119
+ }
120
+ applyQuotationScheduleResolver(quotation) {
121
+ const scheduleModule = this.store.schedule;
122
+ if (!scheduleModule)
123
+ return;
124
+ quotation.setScheduleResolver((id) => {
125
+ var _a;
126
+ const schedules = ((_a = scheduleModule.getScheduleListByIds) == null ? void 0 : _a.call(scheduleModule, [id])) || [];
127
+ return schedules[0];
128
+ });
129
+ }
130
+ async loadQuotationForPriceQuery(params) {
131
+ var _a;
132
+ if (!params.quotation)
133
+ return;
134
+ this.applyQuotationScheduleResolver(params.quotation);
135
+ await params.quotation.loadQuotations({
136
+ channel: params.channel || ((_a = this.otherParams) == null ? void 0 : _a.channel),
137
+ customer_id: params.customer_id
138
+ });
139
+ }
140
+ getPriceQueryProductId(product) {
141
+ const productId = Number((product == null ? void 0 : product.product_id) ?? (product == null ? void 0 : product.id));
142
+ if (!Number.isFinite(productId))
143
+ return null;
144
+ return productId;
145
+ }
146
+ getPriceQuerySchedule(params) {
147
+ const booking = params.booking || {};
148
+ if (typeof booking.start_date === "string" && booking.start_date.trim()) {
149
+ const scheduleDate = booking.start_date.trim();
150
+ const startTime = typeof booking.start_time === "string" && booking.start_time.trim() ? booking.start_time.trim() : "00:00:00";
151
+ const datetime = (0, import_dayjs.default)(`${scheduleDate} ${startTime}`);
152
+ return {
153
+ schedule_date: scheduleDate,
154
+ schedule_datetime: datetime.isValid() ? datetime.format("YYYY-MM-DD HH:mm:ss") : `${scheduleDate} ${startTime}`
155
+ };
156
+ }
157
+ if (typeof params.datetime === "string" && params.datetime.trim()) {
158
+ const datetime = (0, import_dayjs.default)(params.datetime.trim());
159
+ if (datetime.isValid()) {
160
+ return {
161
+ schedule_date: datetime.format("YYYY-MM-DD"),
162
+ schedule_datetime: datetime.format("YYYY-MM-DD HH:mm:ss")
163
+ };
164
+ }
165
+ }
166
+ const now = (0, import_dayjs.default)();
167
+ return {
168
+ schedule_date: now.format("YYYY-MM-DD"),
169
+ schedule_datetime: now.format("YYYY-MM-DD HH:mm:ss")
170
+ };
171
+ }
172
+ async loadProductForPriceQuery(params, customerId) {
173
+ var _a, _b;
174
+ const product = params.product || {};
175
+ const productId = this.getPriceQueryProductId(product);
176
+ if (productId === null || !this.request)
177
+ return null;
178
+ const schedule = this.getPriceQuerySchedule(params);
179
+ try {
180
+ const response = await this.request.post("/product/query", {
181
+ ids: [productId],
182
+ open_quotation: 1,
183
+ open_bundle: 1,
184
+ status: "published",
185
+ num: 1,
186
+ skip: 1,
187
+ customer_id: customerId,
188
+ schedule_date: schedule.schedule_date,
189
+ schedule_datetime: schedule.schedule_datetime,
190
+ application_code: params.channel || ((_a = this.otherParams) == null ? void 0 : _a.channel)
191
+ }, {
192
+ osServer: true,
193
+ customToast: () => {
194
+ }
195
+ });
196
+ const list = ((_b = response == null ? void 0 : response.data) == null ? void 0 : _b.list) || (response == null ? void 0 : response.list) || [];
197
+ if (!Array.isArray(list))
198
+ return null;
199
+ return list.find((item) => Number((item == null ? void 0 : item.id) ?? (item == null ? void 0 : item.product_id)) === productId) || null;
200
+ } catch (error) {
201
+ this.logWarning("loadProductForPriceQuery: 商品重查失败,使用入参 fallback", {
202
+ productId,
203
+ error: error instanceof Error ? error.message : String(error)
204
+ });
205
+ return null;
206
+ }
207
+ }
208
+ getAuthoritativeBundleItems(product) {
209
+ if (Array.isArray(product == null ? void 0 : product.product_bundle))
210
+ return product.product_bundle;
211
+ const groups = Array.isArray(product == null ? void 0 : product.bundle_group) ? product.bundle_group : Array.isArray(product == null ? void 0 : product.bundleGroup) ? product.bundleGroup : [];
212
+ return groups.flatMap((group) => {
213
+ const items = Array.isArray(group == null ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group == null ? void 0 : group.bundleItem) ? group.bundleItem : [];
214
+ return items.map((item) => ({
215
+ ...item,
216
+ group_id: (item == null ? void 0 : item.group_id) ?? (group == null ? void 0 : group.id),
217
+ bundle_group_id: (item == null ? void 0 : item.bundle_group_id) ?? (item == null ? void 0 : item.group_id) ?? (group == null ? void 0 : group.id)
218
+ }));
219
+ });
220
+ }
221
+ findAuthoritativeBundleItem(bundle, candidates) {
222
+ const bundleId = bundle.bundle_id ?? bundle.id;
223
+ if (bundleId != null) {
224
+ const matchedById = candidates.find((item) => String((item == null ? void 0 : item.bundle_id) ?? (item == null ? void 0 : item.id)) === String(bundleId));
225
+ if (matchedById)
226
+ return matchedById;
227
+ }
228
+ const productId = bundle.bundle_product_id ?? bundle._bundle_product_id;
229
+ const groupId = bundle.bundle_group_id ?? bundle.group_id;
230
+ return candidates.find((item) => {
231
+ const itemProductId = (item == null ? void 0 : item.bundle_product_id) ?? (item == null ? void 0 : item._bundle_product_id);
232
+ const itemGroupId = (item == null ? void 0 : item.bundle_group_id) ?? (item == null ? void 0 : item.group_id);
233
+ if (productId == null || String(itemProductId) !== String(productId))
234
+ return false;
235
+ if (groupId == null)
236
+ return true;
237
+ return String(itemGroupId) === String(groupId);
238
+ }) || null;
239
+ }
240
+ getAuthoritativeBundleUnitPrice(bundle) {
241
+ return bundle.price ?? bundle.bundle_selling_price ?? bundle.custom_price ?? bundle.product_price ?? bundle.base_price;
242
+ }
243
+ mergeProductForPriceQuery(product, authoritativeProduct) {
244
+ if (!authoritativeProduct)
245
+ return product;
246
+ const selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
247
+ const authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
248
+ const productBundle = selectedBundles.map((bundle) => {
249
+ const authoritativeBundle = this.findAuthoritativeBundleItem(bundle, authoritativeBundles);
250
+ const unitPrice = authoritativeBundle ? this.getAuthoritativeBundleUnitPrice(authoritativeBundle) : void 0;
251
+ if (unitPrice === void 0 || unitPrice === null || unitPrice === "")
252
+ return bundle;
253
+ return {
254
+ ...bundle,
255
+ price: unitPrice,
256
+ bundle_selling_price: unitPrice,
257
+ base_price: (authoritativeBundle == null ? void 0 : authoritativeBundle.base_price) ?? bundle.base_price,
258
+ product_price: (authoritativeBundle == null ? void 0 : authoritativeBundle.product_price) ?? bundle.product_price
259
+ };
260
+ });
261
+ return {
262
+ ...product,
263
+ ...authoritativeProduct,
264
+ id: product.id ?? authoritativeProduct.id,
265
+ product_id: product.product_id ?? authoritativeProduct.product_id ?? authoritativeProduct.id,
266
+ product_variant_id: product.product_variant_id ?? authoritativeProduct.product_variant_id ?? 0,
267
+ num: product.num ?? product.quantity ?? authoritativeProduct.num,
268
+ quantity: product.quantity ?? product.num ?? authoritativeProduct.quantity,
269
+ product_option_item: product.product_option_item ?? authoritativeProduct.product_option_item,
270
+ product_bundle: productBundle,
271
+ metadata: product.metadata ?? authoritativeProduct.metadata
272
+ };
273
+ }
274
+ getSubmitOrderSalesChannel() {
275
+ var _a;
276
+ return (_a = this.otherParams) == null ? void 0 : _a.channel;
277
+ }
108
278
  /**
109
279
  * 工厂入口:根据子模块名实例化对应模块。
110
280
  * 默认使用 BookingByStep 公共 `createModule`。子类若需引入额外类型(如 customer),
111
281
  * 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
112
282
  */
113
283
  createSubModule(moduleName) {
114
- return (0, import_types.createModule)(moduleName, this.name);
284
+ if (moduleName === "quotation") {
285
+ return new import_Quotation.QuotationModule(`${this.name}_quotation`);
286
+ }
287
+ return (0, import_types2.createModule)(moduleName, this.name);
115
288
  }
116
289
  getSubModuleHooks(moduleName) {
117
290
  var _a, _b;
@@ -140,6 +313,51 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
140
313
  return {};
141
314
  }
142
315
  }
316
+ getAppData(key) {
317
+ var _a, _b, _c, _d, _e, _f;
318
+ const getData = (_b = (_a = this.appPlugin).getData) == null ? void 0 : _b.call(_a);
319
+ if (typeof getData === "function")
320
+ return getData(key);
321
+ const app = this.appPlugin.getApp();
322
+ 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");
323
+ return coreData == null ? void 0 : coreData[key];
324
+ }
325
+ syncAppDataToTempOrder(tempOrder) {
326
+ const isPriceIncludeTax = this.getAppData("is_price_include_tax");
327
+ const taxCountryCode = this.getAppData("tax_country_code");
328
+ const currencyCode = this.getAppData("shop_currency_code");
329
+ const currencySymbol = this.getAppData("shop_symbol");
330
+ let isChanged = false;
331
+ if (isPriceIncludeTax !== void 0) {
332
+ const nextIsPriceIncludeTax = Number(isPriceIncludeTax);
333
+ if ((nextIsPriceIncludeTax === 0 || nextIsPriceIncludeTax === 1) && tempOrder.is_price_include_tax !== nextIsPriceIncludeTax) {
334
+ tempOrder.is_price_include_tax = nextIsPriceIncludeTax;
335
+ isChanged = true;
336
+ }
337
+ }
338
+ if (taxCountryCode !== void 0) {
339
+ const nextTaxCountryCode = String(taxCountryCode || "");
340
+ if (tempOrder.tax_country_code !== nextTaxCountryCode) {
341
+ tempOrder.tax_country_code = nextTaxCountryCode;
342
+ isChanged = true;
343
+ }
344
+ }
345
+ if (currencyCode !== void 0) {
346
+ const nextCurrencyCode = String(currencyCode || "");
347
+ if (tempOrder.currency_code !== nextCurrencyCode) {
348
+ tempOrder.currency_code = nextCurrencyCode;
349
+ isChanged = true;
350
+ }
351
+ }
352
+ if (currencySymbol !== void 0) {
353
+ const nextCurrencySymbol = String(currencySymbol || "");
354
+ if (tempOrder.currency_symbol !== nextCurrencySymbol) {
355
+ tempOrder.currency_symbol = nextCurrencySymbol;
356
+ isChanged = true;
357
+ }
358
+ }
359
+ return isChanged;
360
+ }
143
361
  async initialize(core, options = {}) {
144
362
  var _a;
145
363
  this.core = core;
@@ -148,11 +366,11 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
148
366
  this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
149
367
  this.window = core.getPlugin("window");
150
368
  this.request = core.getPlugin("request");
151
- const appPlugin = core.getPlugin("app");
152
- if (!appPlugin) {
369
+ this.appPlugin = core.getPlugin("app");
370
+ if (!this.appPlugin) {
153
371
  throw new Error("Checkout 解决方案需要 app 插件支持");
154
372
  }
155
- const app = appPlugin.getApp();
373
+ const app = this.appPlugin.getApp();
156
374
  this.logger = app.logger;
157
375
  const targetCacheData = this.readSessionCacheData();
158
376
  const moduleNames = this.getRegisteredModuleNames();
@@ -286,6 +504,13 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
286
504
  const result = ((_a = this.store.order) == null ? void 0 : _a.getTempOrder()) || null;
287
505
  return result;
288
506
  }
507
+ async replaceTempOrder(tempOrder) {
508
+ if (!this.store.order)
509
+ throw new Error("order 模块未初始化");
510
+ const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder);
511
+ await this.effectsEmit("onTempOrderReplaced", { tempOrder: nextTempOrder });
512
+ return nextTempOrder;
513
+ }
289
514
  getOrderIdentity() {
290
515
  if (!this.store.order)
291
516
  return null;
@@ -311,16 +536,21 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
311
536
  return "";
312
537
  return this.store.order.getTempOrderNote();
313
538
  }
314
- updateTempOrderNote(note) {
539
+ updateTempOrderNote(note, sync = false) {
315
540
  try {
316
541
  if (!this.store.order)
317
542
  throw new Error("order 模块未初始化");
318
- const result = this.store.order.updateTempOrderNote(note);
543
+ const result = this.store.order.updateTempOrderNote(note, sync);
319
544
  return result;
320
545
  } catch (error) {
321
546
  throw error;
322
547
  }
323
548
  }
549
+ updateRemoteOrderNote(orderId, note) {
550
+ if (!this.store.order)
551
+ throw new Error("order 模块未初始化");
552
+ this.store.order.syncTempOrderNoteToRemote(orderId, note);
553
+ }
324
554
  updateTempOrderShopDiscount(amount) {
325
555
  if (!this.store.order)
326
556
  throw new Error("order 模块未初始化");
@@ -331,6 +561,18 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
331
561
  throw new Error("order 模块未初始化");
332
562
  return this.store.order.updateTempOrderContactsInfo(contactsInfo);
333
563
  }
564
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
565
+ setEnableTempOrderPersist(enabled) {
566
+ if (!this.store.order)
567
+ throw new Error("order 模块未初始化");
568
+ this.store.order.setEnableTempOrderPersist(enabled);
569
+ }
570
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
571
+ isTempOrderPersistEnabled() {
572
+ if (!this.store.order)
573
+ return false;
574
+ return this.store.order.isTempOrderPersistEnabled();
575
+ }
334
576
  ensureTempOrder() {
335
577
  if (!this.store.order)
336
578
  throw new Error("order 模块未初始化");
@@ -342,6 +584,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
342
584
  if (!this.store.order)
343
585
  throw new Error("order 模块未初始化");
344
586
  const tempOrder = await this.store.order.addNewOrder();
587
+ if (this.syncAppDataToTempOrder(tempOrder)) {
588
+ this.store.order.persistTempOrder();
589
+ await this.store.order.saveDraft();
590
+ }
345
591
  return tempOrder;
346
592
  } catch (error) {
347
593
  throw error;
@@ -360,6 +606,43 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
360
606
  throw new Error("scanOrder 解决方案需要 order 模块支持");
361
607
  }
362
608
  const tempOrder = this.store.order.restoreOrder();
609
+ this.currentSalesDetail = null;
610
+ this.discountConfigCacheKey = null;
611
+ this.hasManualDiscountSelection = false;
612
+ await this.effectsEmit("onTempOrderReplaced", { tempOrder });
613
+ if (this.syncAppDataToTempOrder(tempOrder)) {
614
+ this.store.order.persistTempOrder();
615
+ await this.store.order.saveDraft();
616
+ }
617
+ return tempOrder;
618
+ } catch (error) {
619
+ throw error;
620
+ }
621
+ }
622
+ /**
623
+ * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
624
+ * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
625
+ */
626
+ async clearOrderCartLines() {
627
+ try {
628
+ if (!this.store.order)
629
+ throw new Error("order 模块未初始化");
630
+ const tempOrder = await this.store.order.clearOrderCartLines();
631
+ if (this.currentSalesDetail) {
632
+ this.currentSalesDetail = {
633
+ ...this.currentSalesDetail,
634
+ products: [],
635
+ bookings: [],
636
+ rootBooking: null,
637
+ bookingsByProductUid: {},
638
+ discount_list: []
639
+ };
640
+ }
641
+ await this.effectsEmit("onTempOrderReplaced", { tempOrder });
642
+ if (this.syncAppDataToTempOrder(tempOrder)) {
643
+ this.store.order.persistTempOrder();
644
+ await this.store.order.saveDraft();
645
+ }
363
646
  return tempOrder;
364
647
  } catch (error) {
365
648
  throw error;
@@ -381,6 +664,246 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
381
664
  throw error;
382
665
  }
383
666
  }
667
+ getHistoricalProductDiscountList(products) {
668
+ const historyDiscountList = [];
669
+ products.forEach((item) => {
670
+ if (!this.isPersistedOrderProduct(item))
671
+ return;
672
+ (item.discount_list || []).forEach((discount) => {
673
+ var _a, _b, _c, _d, _e, _f;
674
+ const discountId = ((_a = discount.discount) == null ? void 0 : _a.resource_id) || discount.id;
675
+ if (!discountId || !["good_pass", "discount_card"].includes(discount.type))
676
+ return;
677
+ const quantity = item.quantity || item.num || item.product_quantity || 1;
678
+ 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);
679
+ const index = historyDiscountList.findIndex((n) => n.id === discountId);
680
+ if (index !== -1) {
681
+ historyDiscountList[index] = {
682
+ ...historyDiscountList[index],
683
+ amount: new import_decimal.default(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
684
+ savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
685
+ };
686
+ return;
687
+ }
688
+ historyDiscountList.push({
689
+ ...discount,
690
+ id: discountId,
691
+ tag: discount.tag || discount.type,
692
+ name: discount.name || ((_d = (_c = discount.discount) == null ? void 0 : _c.title) == null ? void 0 : _d.auto),
693
+ format_title: ((_e = discount.discount) == null ? void 0 : _e.title) || discount.format_title,
694
+ isEditMode: true,
695
+ limited_relation_product_data: {},
696
+ savedAmount: savedAmount.toNumber(),
697
+ isAvailable: true,
698
+ isDisabled: true,
699
+ isSelected: true,
700
+ product_id: ((_f = discount.discount) == null ? void 0 : _f.product_id) || discount.product_id
701
+ });
702
+ });
703
+ });
704
+ return historyDiscountList;
705
+ }
706
+ isPersistedOrderProduct(product) {
707
+ const orderDetailId = product.order_detail_id ?? product.orderDetailId;
708
+ if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
709
+ return true;
710
+ }
711
+ const bookingId = product.booking_id ?? product.bookingId;
712
+ return bookingId !== void 0 && bookingId !== null && bookingId !== "";
713
+ }
714
+ mergeHistoricalDiscountList(discountList, products) {
715
+ const historyDiscountList = this.getHistoricalProductDiscountList(products);
716
+ const historyIds = new Set(historyDiscountList.map((discount) => discount.id));
717
+ return [
718
+ ...historyDiscountList,
719
+ ...(discountList || []).filter((discount) => !historyIds.has(discount.id))
720
+ ];
721
+ }
722
+ mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
723
+ if (!currentDiscountList.length)
724
+ return discountList;
725
+ const currentDiscountMap = new Map(
726
+ currentDiscountList.map((discount) => [discount.id, discount])
727
+ );
728
+ return discountList.map((discount) => {
729
+ const currentDiscount = currentDiscountMap.get(discount.id);
730
+ if (!currentDiscount)
731
+ return discount;
732
+ if (currentDiscount.isManualSelect) {
733
+ return {
734
+ ...discount,
735
+ isSelected: false,
736
+ isManualSelect: true
737
+ };
738
+ }
739
+ if (currentDiscount.isSelected) {
740
+ return {
741
+ ...discount,
742
+ isSelected: true,
743
+ isManualSelect: false
744
+ };
745
+ }
746
+ return discount;
747
+ });
748
+ }
749
+ async loadDiscountConfig(params) {
750
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
751
+ if (!this.store.order)
752
+ throw new Error("order 模块未初始化");
753
+ const tempOrder = this.store.order.ensureTempOrder();
754
+ const orderStore = this.store.order.store || {};
755
+ const discountModule = orderStore.discount;
756
+ const rulesModule = orderStore.rules;
757
+ const orderId = tempOrder.order_id || ((_b = (_a = this.getOrderIdentity) == null ? void 0 : _a.call(this)) == null ? void 0 : _b.orderId);
758
+ const customerId = Number(
759
+ (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
760
+ );
761
+ const currentDiscountList = ((_h = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _h.call(discountModule)) || [];
762
+ const originalDiscountList = ((_i = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _i.call(discountModule)) || [];
763
+ const hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some((discount) => discount.isManualSelect);
764
+ const discountAction = (params == null ? void 0 : params.action) || (orderId ? "edit" : "create");
765
+ const discountConfigCacheKey = [
766
+ customerId,
767
+ discountAction,
768
+ Number(orderId) || 0
769
+ ].join(":");
770
+ let preparedDiscountList = [];
771
+ if (customerId && customerId !== 1) {
772
+ if (this.discountConfigCacheKey === discountConfigCacheKey) {
773
+ preparedDiscountList = originalDiscountList;
774
+ } else {
775
+ preparedDiscountList = await this.store.order.loadDiscountConfig({
776
+ customerId,
777
+ action: discountAction,
778
+ orderId: Number(orderId) || void 0,
779
+ apply: false
780
+ });
781
+ this.discountConfigCacheKey = discountConfigCacheKey;
782
+ await ((_j = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _j.call(discountModule, preparedDiscountList));
783
+ }
784
+ }
785
+ if (hasManualDiscountSelection && currentDiscountList.length) {
786
+ return {
787
+ productList: tempOrder.products || [],
788
+ discountList: currentDiscountList
789
+ };
790
+ }
791
+ let nextDiscountList = this.mergeHistoricalDiscountList(
792
+ preparedDiscountList || ((_k = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _k.call(discountModule)) || [],
793
+ tempOrder.products || []
794
+ );
795
+ nextDiscountList = this.mergeCurrentDiscountSelectionState(
796
+ nextDiscountList,
797
+ currentDiscountList
798
+ );
799
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
800
+ if (rulesModule) {
801
+ const holders = ((_l = tempOrder.holder) == null ? void 0 : _l.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
802
+ const result = rulesModule.calcDiscount({
803
+ productList: tempOrder.products,
804
+ discountList: nextDiscountList,
805
+ holders,
806
+ isFormSubject: !!((_m = tempOrder.holder) == null ? void 0 : _m.type) && tempOrder.holder.type === "form",
807
+ orderTotalAmount: Number(((_n = orderStore.summary) == null ? void 0 : _n.total_amount) || 0)
808
+ }) || { productList: tempOrder.products, discountList: nextDiscountList };
809
+ if (result.productList) {
810
+ tempOrder.products = result.productList;
811
+ }
812
+ for (const product of tempOrder.products || []) {
813
+ const productUid = (_o = product.metadata) == null ? void 0 : _o.unique_identification_number;
814
+ const runtimeOrigin = productUid ? (_r = (_q = (_p = tempOrder._extend) == null ? void 0 : _p.productsByUid) == null ? void 0 : _q[productUid]) == null ? void 0 : _r.origin : void 0;
815
+ if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || ((_s = product.metadata) == null ? void 0 : _s.is_manual_discount))
816
+ continue;
817
+ const totalPerUnitDiscount = (product.discount_list || []).reduce(
818
+ (sum, pd) => sum + Number(pd.amount || 0),
819
+ 0
820
+ );
821
+ const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
822
+ const sourcePrice = ((_t = product.metadata) == null ? void 0 : _t.source_product_price) ?? (((_u = product.metadata) == null ? void 0 : _u.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
823
+ const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
824
+ const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
825
+ if (product.metadata) {
826
+ product.metadata.main_product_selling_price = newMainSellingPrice;
827
+ product.metadata.price_schema_version = 2;
828
+ }
829
+ product.selling_price = (0, import_utils.composeLinePrice)({
830
+ mainPrice: newMainSellingPrice,
831
+ bundle: product.product_bundle
832
+ });
833
+ }
834
+ if (result.discountList) {
835
+ nextDiscountList = this.mergeHistoricalDiscountList(
836
+ result.discountList,
837
+ tempOrder.products || []
838
+ );
839
+ import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
840
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
841
+ tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
842
+ }
843
+ }
844
+ const summary = await this.store.order.recalculateSummary({ createIfMissing: true });
845
+ this.store.order.persistTempOrder();
846
+ await this.effectsEmit("onDiscountApplied", {
847
+ productList: tempOrder.products || [],
848
+ discountList: nextDiscountList,
849
+ selectedDiscountList: tempOrder.discount_list || [],
850
+ tempOrder
851
+ });
852
+ return {
853
+ productList: tempOrder.products || [],
854
+ discountList: nextDiscountList
855
+ };
856
+ }
857
+ async bestDiscount(cb) {
858
+ var _a, _b, _c, _d, _e;
859
+ if (!this.store.order)
860
+ throw new Error("order 模块未初始化");
861
+ const tempOrder = this.store.order.ensureTempOrder();
862
+ const orderStore = this.store.order.store || {};
863
+ const discountModule = orderStore.discount;
864
+ const rulesModule = orderStore.rules;
865
+ const originalDiscountList = ((_a = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _a.call(discountModule)) || this.getDiscountList();
866
+ const currentDiscountList = ((_b = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
867
+ let nextDiscountList = this.mergeHistoricalDiscountList(
868
+ originalDiscountList || [],
869
+ tempOrder.products || []
870
+ );
871
+ let result = {
872
+ productList: tempOrder.products || [],
873
+ discountList: nextDiscountList
874
+ };
875
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
876
+ if (rulesModule) {
877
+ const holders = ((_c = tempOrder.holder) == null ? void 0 : _c.form_record_id) ? [{ form_record_id: tempOrder.holder.form_record_id }] : [];
878
+ result = rulesModule.calcDiscount({
879
+ productList: tempOrder.products,
880
+ discountList: nextDiscountList,
881
+ holders,
882
+ isFormSubject: !!((_d = tempOrder.holder) == null ? void 0 : _d.type) && tempOrder.holder.type === "form",
883
+ orderTotalAmount: Number(((_e = orderStore.summary) == null ? void 0 : _e.total_amount) || 0)
884
+ }) || result;
885
+ if (result.productList) {
886
+ tempOrder.products = result.productList;
887
+ }
888
+ if (result.discountList) {
889
+ nextDiscountList = this.mergeHistoricalDiscountList(
890
+ result.discountList,
891
+ tempOrder.products || []
892
+ );
893
+ import_Order.OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
894
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(nextDiscountList));
895
+ tempOrder.discount_list = nextDiscountList.filter((discount) => discount.isSelected);
896
+ result = {
897
+ productList: tempOrder.products,
898
+ discountList: nextDiscountList
899
+ };
900
+ }
901
+ }
902
+ await this.store.order.recalculateSummary({ createIfMissing: true });
903
+ this.store.order.persistTempOrder();
904
+ cb == null ? void 0 : cb(result);
905
+ return result;
906
+ }
384
907
  getDiscountList() {
385
908
  if (!this.store.order)
386
909
  return [];
@@ -418,6 +941,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
418
941
  isManualSelect: !params.isSelected
419
942
  } : d
420
943
  );
944
+ this.hasManualDiscountSelection = true;
421
945
  const tempOrder = this.store.order.ensureTempOrder();
422
946
  const orderStore = this.store.order.store || {};
423
947
  const discountModule = orderStore.discount;
@@ -450,6 +974,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
450
974
  for (const d of nextDiscountList) {
451
975
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
452
976
  d.isSelected = false;
977
+ d.isManualSelect = true;
453
978
  }
454
979
  }
455
980
  }
@@ -490,6 +1015,40 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
490
1015
  tempOrder.discount_list = (nextDiscountList || []).filter((d) => d.isSelected);
491
1016
  await this.store.order.recalculateSummary({ createIfMissing: true });
492
1017
  this.store.order.persistTempOrder();
1018
+ this.effectsEmit("onDiscountApplied", {
1019
+ productList: tempOrder.products,
1020
+ discountList: nextDiscountList,
1021
+ selectedDiscountList: tempOrder.discount_list,
1022
+ tempOrder
1023
+ });
1024
+ } catch (error) {
1025
+ throw error;
1026
+ }
1027
+ }
1028
+ async applyDiscountCalculationResult(result) {
1029
+ try {
1030
+ if (!this.store.order)
1031
+ throw new Error("order 模块未初始化");
1032
+ if (!result)
1033
+ return;
1034
+ const tempOrder = this.store.order.ensureTempOrder();
1035
+ const orderStore = this.store.order.store || {};
1036
+ const discountModule = orderStore.discount;
1037
+ if (result.productList) {
1038
+ tempOrder.products = result.productList;
1039
+ }
1040
+ if (result.discountList) {
1041
+ import_Order.OrderModule.populateSavedAmounts(
1042
+ tempOrder.products,
1043
+ result.discountList
1044
+ );
1045
+ await (discountModule == null ? void 0 : discountModule.setDiscountList(result.discountList));
1046
+ tempOrder.discount_list = result.discountList.filter(
1047
+ (discount) => discount.isSelected
1048
+ );
1049
+ }
1050
+ await this.store.order.recalculateSummary({ createIfMissing: true });
1051
+ this.store.order.persistTempOrder();
493
1052
  } catch (error) {
494
1053
  throw error;
495
1054
  }
@@ -504,7 +1063,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
504
1063
  * payments 会交给 OrderModule 统一映射为 Sales 协议支付项。
505
1064
  */
506
1065
  async submitSalesOrder(params) {
507
- var _a, _b, _c, _d;
1066
+ var _a, _b, _c;
508
1067
  if (!this.store.order) {
509
1068
  throw new Error("BaseSales 解决方案需要 order 模块支持");
510
1069
  }
@@ -513,19 +1072,57 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
513
1072
  cacheId: this.cacheId,
514
1073
  platform: (_a = this.otherParams) == null ? void 0 : _a.platform,
515
1074
  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,
1075
+ channel: this.getSubmitOrderSalesChannel(),
1076
+ type: (_c = this.otherParams) == null ? void 0 : _c.type,
518
1077
  ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
519
1078
  ...(params == null ? void 0 : params.paymentStatus) !== void 0 ? { paymentStatus: params.paymentStatus } : {},
520
1079
  ...(params == null ? void 0 : params.smallTicketDataFlag) !== void 0 ? { smallTicketDataFlag: params.smallTicketDataFlag } : {},
521
1080
  ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
522
1081
  };
1082
+ console.log(submitParams, "submitParams123");
523
1083
  return this.store.order.submitTempOrder(submitParams);
524
1084
  }
525
1085
  async syncPaymentsToOrder(params) {
526
1086
  if (!this.store.order)
527
1087
  throw new Error("order 模块未初始化");
528
- return this.store.order.syncPaymentsToOrder(params);
1088
+ const channel = params.channel ?? this.getSubmitOrderSalesChannel();
1089
+ const syncParams = {
1090
+ ...params,
1091
+ ...channel !== void 0 ? { channel } : {}
1092
+ };
1093
+ const syncState = this.store.order.getOrderSyncState();
1094
+ if (params.submitWhenPaid && syncState === "submitting") {
1095
+ return this.store.order.syncPaymentsToOrder(syncParams);
1096
+ }
1097
+ const payments = params.payments || [];
1098
+ await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncStart, {
1099
+ payments,
1100
+ params: syncParams,
1101
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1102
+ orderSnapshot: this.store.order.getOrderSnapshot()
1103
+ });
1104
+ try {
1105
+ const syncResult = await this.store.order.syncPaymentsToOrder(syncParams);
1106
+ await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
1107
+ ok: true,
1108
+ syncResult,
1109
+ payments: this.store.order.getOrderPayments(),
1110
+ params: syncParams,
1111
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1112
+ orderSnapshot: this.store.order.getOrderSnapshot()
1113
+ });
1114
+ return syncResult;
1115
+ } catch (error) {
1116
+ await this.effectsEmit(import_types.BaseSalesHookNames.onPaymentSyncEnd, {
1117
+ ok: false,
1118
+ error,
1119
+ payments: this.store.order.getOrderPayments(),
1120
+ params: syncParams,
1121
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
1122
+ orderSnapshot: this.store.order.getOrderSnapshot()
1123
+ });
1124
+ throw error;
1125
+ }
529
1126
  }
530
1127
  /** 读取当前 BaseSales 订单上下文中的 Sales 协议支付项。 */
531
1128
  getOrderPayments() {
@@ -543,7 +1140,31 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
543
1140
  addOrderPayment(payment) {
544
1141
  if (!this.store.order)
545
1142
  throw new Error("order 模块未初始化");
546
- return this.store.order.addOrderPayment(payment);
1143
+ const paymentRecord = payment;
1144
+ const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1145
+ if (!metadata.unique_identification_number) {
1146
+ metadata.unique_identification_number = (0, import_utils.createUuidV4)();
1147
+ }
1148
+ const payments = this.store.order.addOrderPayment({
1149
+ ...paymentRecord,
1150
+ metadata
1151
+ });
1152
+ const amountSnapshot = this.store.order.getOrderAmountSnapshot();
1153
+ const syncState = this.store.order.getOrderSyncState();
1154
+ if (amountSnapshot && syncState !== "submitting") {
1155
+ const paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? "paid" : "partially_paid";
1156
+ void this.syncPaymentsToOrder({
1157
+ payments,
1158
+ paymentStatus,
1159
+ submitWhenPaid: true,
1160
+ smallTicketDataFlag: 1
1161
+ }).catch((error) => {
1162
+ this.logError("auto sync payments failed", {
1163
+ error: error instanceof Error ? error.message : String(error)
1164
+ });
1165
+ });
1166
+ }
1167
+ return payments;
547
1168
  }
548
1169
  /** 更新当前订单中的指定支付项。 */
549
1170
  updateOrderPayment(paymentIdentity, updates) {
@@ -564,11 +1185,12 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
564
1185
  return this.store.order.updateVoucherOrderPayments(payments);
565
1186
  }
566
1187
  getWalletProductList() {
567
- var _a, _b;
1188
+ var _a, _b, _c;
568
1189
  const tempOrder = (_a = this.store.order) == null ? void 0 : _a.getTempOrder();
569
1190
  if (!((_b = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _b.length))
570
1191
  return [];
571
- return tempOrder.products.map((product) => {
1192
+ const products = (_c = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _c.filter((n) => n.product_id);
1193
+ return products.map((product) => {
572
1194
  const metadata = product.metadata || {};
573
1195
  return {
574
1196
  product_id: product.product_id,
@@ -578,6 +1200,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
578
1200
  is_charge_tax: product.is_charge_tax ?? 0,
579
1201
  tax_fee: product.tax_fee,
580
1202
  selling_price: Number(product.selling_price || 0),
1203
+ discount_list: product.discount_list || [],
581
1204
  holder_id: product.holder_id ?? metadata.holder_id,
582
1205
  original_price: product.original_price,
583
1206
  main_product_original_price: metadata.main_product_original_price ?? product.original_price,
@@ -591,8 +1214,10 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
591
1214
  const bundleMetadata = bundle.metadata || {};
592
1215
  return {
593
1216
  is_price_include_tax: tempOrder.is_price_include_tax,
594
- bundle_id: bundle.bundle_id,
595
- bundle_product_id: bundle.bundle_product_id,
1217
+ // 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
1218
+ bundle_id: bundle.bundle_id ?? bundle.id,
1219
+ bundle_product_id: bundle.bundle_product_id ?? bundle._bundle_product_id,
1220
+ bundle_group_id: bundle.bundle_group_id ?? bundle.group_id,
596
1221
  bundle_variant_id: bundle.bundle_variant_id,
597
1222
  price_type: bundle.price_type,
598
1223
  price_type_ext: bundle.price_type_ext,
@@ -731,6 +1356,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
731
1356
  transformBaseProductToOrderProduct(params) {
732
1357
  return (0, import_transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
733
1358
  }
1359
+ async calculateProductBookingPrice(params) {
1360
+ const quotation = this.store.quotation;
1361
+ const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
1362
+ const authoritativeProduct = await this.loadProductForPriceQuery(params, customerId);
1363
+ const product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
1364
+ await this.loadQuotationForPriceQuery({
1365
+ quotation,
1366
+ customer_id: customerId,
1367
+ channel: params.channel
1368
+ });
1369
+ return (0, import_quotationPrice.calculateBaseSalesProductBookingPrice)({
1370
+ ...params,
1371
+ product,
1372
+ fallback_price: authoritativeProduct ? void 0 : params.fallback_price,
1373
+ customer_id: customerId,
1374
+ quotation
1375
+ });
1376
+ }
734
1377
  async addProductToOrder(product, booking) {
735
1378
  try {
736
1379
  if (!this.store.order)
@@ -741,16 +1384,35 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
741
1384
  throw error;
742
1385
  }
743
1386
  }
744
- async updateProductInOrder(params) {
1387
+ async updateOrderProduct(params) {
1388
+ try {
1389
+ if (!this.store.order)
1390
+ throw new Error("order 模块未初始化");
1391
+ const products = await this.store.order.updateOrderProduct(params);
1392
+ return products;
1393
+ } catch (error) {
1394
+ throw error;
1395
+ }
1396
+ }
1397
+ async updateOrderProductQuantity(params) {
745
1398
  try {
746
1399
  if (!this.store.order)
747
1400
  throw new Error("order 模块未初始化");
748
- const products = await this.store.order.updateProductInOrder(params);
1401
+ const products = await this.store.order.updateOrderProductQuantity(params);
749
1402
  return products;
750
1403
  } catch (error) {
751
1404
  throw error;
752
1405
  }
753
1406
  }
1407
+ updateOrderBooking(params) {
1408
+ try {
1409
+ if (!this.store.order)
1410
+ throw new Error("order 模块未初始化");
1411
+ return this.store.order.updateOrderBooking(params);
1412
+ } catch (error) {
1413
+ throw error;
1414
+ }
1415
+ }
754
1416
  /**
755
1417
  * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
756
1418
  * 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
@@ -770,7 +1432,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
770
1432
  }
771
1433
  if (identity.product_bundle !== void 0)
772
1434
  params.product_bundle = identity.product_bundle;
773
- const products = await this.updateProductInOrder(params);
1435
+ const products = await this.updateOrderProduct(params);
774
1436
  return products;
775
1437
  } catch (error) {
776
1438
  throw error;
@@ -786,6 +1448,58 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
786
1448
  throw error;
787
1449
  }
788
1450
  }
1451
+ // ─── 促销/赠品 透传(迁移自 booking usePromotion) ────────────────
1452
+ /**
1453
+ * 注入促销评估器到底层 OrderModule。
1454
+ *
1455
+ * @example
1456
+ * solution.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
1457
+ */
1458
+ setPromotionEvaluator(evaluator) {
1459
+ if (!this.store.order)
1460
+ throw new Error("order 模块未初始化");
1461
+ this.store.order.setPromotionEvaluator(evaluator);
1462
+ }
1463
+ /**
1464
+ * 注入赠品选择 resolver。UI 层(SalesSdk)通过 bridge 提供。
1465
+ *
1466
+ * @example
1467
+ * solution.setGiftSelectResolver(async (ctx) => bridge.request(ctx));
1468
+ */
1469
+ setGiftSelectResolver(resolver) {
1470
+ if (!this.store.order)
1471
+ throw new Error("order 模块未初始化");
1472
+ this.store.order.setGiftSelectResolver(resolver);
1473
+ }
1474
+ /**
1475
+ * 为商品目录追加促销标签,供 SalesSdkProductProvider 等商品列表入口复用。
1476
+ *
1477
+ * @example
1478
+ * const products = solution.appendPromotionTags(catalogProducts);
1479
+ */
1480
+ appendPromotionTags(products) {
1481
+ if (!this.store.order)
1482
+ throw new Error("order 模块未初始化");
1483
+ return this.store.order.appendPromotionTags(products);
1484
+ }
1485
+ /**
1486
+ * 主动触发一次促销应用(一般写路径会自动触发,少数场景如客户切换后可手动调)。
1487
+ */
1488
+ async applyPromotion() {
1489
+ if (!this.store.order)
1490
+ throw new Error("order 模块未初始化");
1491
+ await this.store.order.applyPromotion();
1492
+ }
1493
+ /** 最近一次促销计算输出的未满足提示。 */
1494
+ getUnfulfilledPromotions() {
1495
+ var _a;
1496
+ return ((_a = this.store.order) == null ? void 0 : _a.getUnfulfilledPromotions()) || [];
1497
+ }
1498
+ /** 最近一次促销计算输出的赠品操作 diff。 */
1499
+ getLastGiftActions() {
1500
+ var _a;
1501
+ return ((_a = this.store.order) == null ? void 0 : _a.getLastGiftActions()) || null;
1502
+ }
789
1503
  // 获取商品列表
790
1504
  // TODO 需要跟 webpos 内的对齐一下
791
1505
  async getProductList() {