@pisell/pisellos 0.10.90 → 0.10.91

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 (227) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  6. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  7. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  8. package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
  14. package/dist/modules/BookingContext/utils/productExtend.js +132 -33
  15. package/dist/modules/BookingContext/utils/resources.js +1 -1
  16. package/dist/modules/Cart/index.js +4 -3
  17. package/dist/modules/Cart/types.d.ts +2 -0
  18. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  19. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  20. package/dist/modules/Date/index.d.ts +1 -1
  21. package/dist/modules/Date/index.js +60 -14
  22. package/dist/modules/Date/types.d.ts +5 -0
  23. package/dist/modules/OpenData/salesSettings.js +1 -1
  24. package/dist/modules/OpenData/types.d.ts +9 -0
  25. package/dist/modules/OpenData/utils.d.ts +1 -1
  26. package/dist/modules/OpenData/utils.js +3 -2
  27. package/dist/modules/Order/index.d.ts +22 -7
  28. package/dist/modules/Order/index.js +1565 -1161
  29. package/dist/modules/Order/localEftposState.d.ts +13 -0
  30. package/dist/modules/Order/localEftposState.js +39 -0
  31. package/dist/modules/Order/types.d.ts +33 -11
  32. package/dist/modules/Order/types.js +2 -2
  33. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  34. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  35. package/dist/modules/Order/utils.d.ts +4 -1
  36. package/dist/modules/Order/utils.js +75 -52
  37. package/dist/modules/Payment/walletpass.js +32 -6
  38. package/dist/modules/Product/types.d.ts +16 -0
  39. package/dist/modules/ProductList/index.js +1 -1
  40. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  41. package/dist/modules/ResourcePlanner/planner.js +383 -24
  42. package/dist/modules/ResourcePlanner/types.d.ts +42 -0
  43. package/dist/modules/Rules/index.js +86 -54
  44. package/dist/modules/Schedule/index.d.ts +7 -1
  45. package/dist/modules/Schedule/index.js +155 -39
  46. package/dist/modules/Schedule/types.d.ts +2 -0
  47. package/dist/modules/bookingReadValidation.d.ts +6 -0
  48. package/dist/modules/bookingReadValidation.js +72 -0
  49. package/dist/plugins/request.d.ts +2 -0
  50. package/dist/server/index.d.ts +9 -0
  51. package/dist/server/index.js +1928 -1462
  52. package/dist/server/modules/form/index.d.ts +19 -0
  53. package/dist/server/modules/form/index.js +205 -0
  54. package/dist/server/modules/form/types.d.ts +13 -0
  55. package/dist/server/modules/form/types.js +3 -0
  56. package/dist/server/modules/index.d.ts +3 -0
  57. package/dist/server/modules/index.js +4 -0
  58. package/dist/server/modules/order/index.d.ts +21 -0
  59. package/dist/server/modules/order/index.js +1399 -831
  60. package/dist/server/modules/order/types.d.ts +3 -0
  61. package/dist/server/modules/order/utils/filterOrders.js +20 -0
  62. package/dist/server/modules/products/index.d.ts +28 -7
  63. package/dist/server/modules/products/index.js +1295 -769
  64. package/dist/server/modules/products/replication.d.ts +8 -0
  65. package/dist/server/modules/products/replication.js +69 -0
  66. package/dist/server/modules/products/types.d.ts +12 -1
  67. package/dist/server/modules/products/types.js +4 -0
  68. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  69. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  70. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  71. package/dist/shared/receipt/small-ticket.js +58 -26
  72. package/dist/shared/receipt/templateVisibility.d.ts +3 -0
  73. package/dist/shared/receipt/templateVisibility.js +6 -2
  74. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  75. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  76. package/dist/solution/BaseSales/index.d.ts +22 -6
  77. package/dist/solution/BaseSales/index.js +1881 -1347
  78. package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
  79. package/dist/solution/BaseSales/pickupTiming.js +35 -8
  80. package/dist/solution/BaseSales/types.d.ts +4 -0
  81. package/dist/solution/BaseSales/types.js +1 -0
  82. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  83. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  84. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  85. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  86. package/dist/solution/BookingByStep/index.d.ts +18 -2
  87. package/dist/solution/BookingByStep/index.js +681 -361
  88. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  89. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  90. package/dist/solution/BookingTicket/index.d.ts +6 -0
  91. package/dist/solution/BookingTicket/index.js +666 -593
  92. package/dist/solution/BookingTicket/types.d.ts +1 -1
  93. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  94. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  95. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +3 -3
  96. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  97. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  98. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  99. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  100. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
  101. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  102. package/dist/solution/Sales/index.js +1 -1
  103. package/dist/solution/ScanOrder/index.d.ts +2 -0
  104. package/dist/solution/ScanOrder/index.js +230 -97
  105. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  106. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  107. package/dist/solution/ScanOrder/types.d.ts +3 -0
  108. package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
  109. package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
  110. package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
  111. package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
  112. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  113. package/dist/utils/pos-receipt-auto-print.js +14 -0
  114. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  115. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  116. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  117. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  118. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  119. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  120. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  121. package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
  122. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  123. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  124. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  125. package/lib/modules/BookingContext/utils/index.js +11 -0
  126. package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
  127. package/lib/modules/BookingContext/utils/productExtend.js +104 -5
  128. package/lib/modules/BookingContext/utils/resources.js +1 -1
  129. package/lib/modules/Cart/index.js +4 -2
  130. package/lib/modules/Cart/types.d.ts +2 -0
  131. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  132. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  133. package/lib/modules/Date/index.d.ts +1 -1
  134. package/lib/modules/Date/index.js +28 -5
  135. package/lib/modules/Date/types.d.ts +5 -0
  136. package/lib/modules/OpenData/salesSettings.js +1 -1
  137. package/lib/modules/OpenData/types.d.ts +9 -0
  138. package/lib/modules/OpenData/utils.d.ts +1 -1
  139. package/lib/modules/OpenData/utils.js +3 -2
  140. package/lib/modules/Order/index.d.ts +22 -7
  141. package/lib/modules/Order/index.js +457 -174
  142. package/lib/modules/Order/localEftposState.d.ts +13 -0
  143. package/lib/modules/Order/localEftposState.js +44 -0
  144. package/lib/modules/Order/types.d.ts +33 -11
  145. package/lib/modules/Order/types.js +2 -2
  146. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  147. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  148. package/lib/modules/Order/utils.d.ts +4 -1
  149. package/lib/modules/Order/utils.js +29 -3
  150. package/lib/modules/Payment/walletpass.js +23 -1
  151. package/lib/modules/Product/types.d.ts +16 -0
  152. package/lib/modules/ProductList/index.js +1 -1
  153. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  154. package/lib/modules/ResourcePlanner/planner.js +299 -9
  155. package/lib/modules/ResourcePlanner/types.d.ts +42 -0
  156. package/lib/modules/Rules/index.js +32 -3
  157. package/lib/modules/Schedule/index.d.ts +7 -1
  158. package/lib/modules/Schedule/index.js +68 -4
  159. package/lib/modules/Schedule/types.d.ts +2 -0
  160. package/lib/modules/bookingReadValidation.d.ts +6 -0
  161. package/lib/modules/bookingReadValidation.js +56 -0
  162. package/lib/plugins/request.d.ts +2 -0
  163. package/lib/server/index.d.ts +9 -0
  164. package/lib/server/index.js +279 -30
  165. package/lib/server/modules/form/index.d.ts +19 -0
  166. package/lib/server/modules/form/index.js +73 -0
  167. package/lib/server/modules/form/types.d.ts +13 -0
  168. package/lib/server/modules/form/types.js +9 -0
  169. package/lib/server/modules/index.d.ts +3 -0
  170. package/lib/server/modules/index.js +15 -1
  171. package/lib/server/modules/order/index.d.ts +21 -0
  172. package/lib/server/modules/order/index.js +344 -35
  173. package/lib/server/modules/order/types.d.ts +3 -0
  174. package/lib/server/modules/order/utils/filterOrders.js +18 -0
  175. package/lib/server/modules/products/index.d.ts +28 -7
  176. package/lib/server/modules/products/index.js +224 -62
  177. package/lib/server/modules/products/replication.d.ts +8 -0
  178. package/lib/server/modules/products/replication.js +30 -0
  179. package/lib/server/modules/products/types.d.ts +12 -1
  180. package/lib/server/modules/products/types.js +3 -0
  181. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  182. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  183. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  184. package/lib/shared/receipt/small-ticket.js +53 -25
  185. package/lib/shared/receipt/templateVisibility.d.ts +3 -0
  186. package/lib/shared/receipt/templateVisibility.js +6 -2
  187. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  188. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  189. package/lib/solution/BaseSales/index.d.ts +22 -6
  190. package/lib/solution/BaseSales/index.js +347 -59
  191. package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
  192. package/lib/solution/BaseSales/pickupTiming.js +24 -3
  193. package/lib/solution/BaseSales/types.d.ts +4 -0
  194. package/lib/solution/BaseSales/types.js +1 -0
  195. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  196. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  197. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  198. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  199. package/lib/solution/BookingByStep/index.d.ts +18 -2
  200. package/lib/solution/BookingByStep/index.js +229 -17
  201. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  202. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  203. package/lib/solution/BookingTicket/index.d.ts +6 -0
  204. package/lib/solution/BookingTicket/index.js +40 -5
  205. package/lib/solution/BookingTicket/types.d.ts +1 -1
  206. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  207. package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
  208. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +3 -3
  209. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  210. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  211. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  212. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  213. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
  214. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  215. package/lib/solution/Sales/index.js +1 -1
  216. package/lib/solution/ScanOrder/index.d.ts +2 -0
  217. package/lib/solution/ScanOrder/index.js +131 -22
  218. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  219. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  220. package/lib/solution/ScanOrder/types.d.ts +3 -0
  221. package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
  222. package/lib/solution/UnifiedBookingSales/index.js +717 -144
  223. package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
  224. package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
  225. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  226. package/lib/utils/pos-receipt-auto-print.js +13 -0
  227. package/package.json +1 -1
@@ -9,6 +9,7 @@ var _exportNames = {
9
9
  exports.BaseSalesImpl = void 0;
10
10
  var _inventory = require("../../inventory");
11
11
  var _BaseModule = require("../../modules/BaseModule");
12
+ var _localEftposState = require("../../modules/Order/localEftposState");
12
13
  var _types = require("./types");
13
14
  Object.keys(_types).forEach(function (key) {
14
15
  if (key === "default" || key === "__esModule") return;
@@ -24,6 +25,7 @@ Object.keys(_types).forEach(function (key) {
24
25
  var _Order = require("../../modules/Order");
25
26
  var _pickupTiming = require("../../modules/Order/pickupTiming");
26
27
  var _pickupTiming2 = require("./pickupTiming");
28
+ var _fulfillmentItemRules = require("./fulfillmentItemRules");
27
29
  var _holderRelations = require("../../modules/Order/holderRelations");
28
30
  var _contactInfo = require("../../modules/OpenData/contactInfo");
29
31
  var _promotionSelection = require("../../modules/Rules/promotionSelection");
@@ -38,9 +40,11 @@ var _orderCollectionIdentity = require("../../modules/Order/utils/orderCollectio
38
40
  var _dayjs = _interopRequireDefault(require("dayjs"));
39
41
  var _clientDataVariants = require("../../modules/ProductList/clientDataVariants");
40
42
  var _platform = require("../../utils/platform");
43
+ var _posReceiptAutoPrint = require("../../utils/pos-receipt-auto-print");
41
44
  var _Quotation = require("../../modules/Quotation");
42
45
  var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
43
46
  var _quotationPrice = require("./utils/quotationPrice");
47
+ var _posDurationPricing = require("./utils/posDurationPricing");
44
48
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
49
  const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
46
50
  const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
@@ -560,6 +564,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
560
564
  // 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
561
565
  currentSalesDetail = null;
562
566
  discountConfigCacheKey = null;
567
+ discountConfigPrepareInFlight = null;
563
568
  hasManualDiscountSelection = false;
564
569
  reusedSharedSubModuleNames = new Set();
565
570
  paymentMethodsCache = [];
@@ -572,11 +577,13 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
572
577
  salesDetailHydrateQueue = Promise.resolve();
573
578
  serverOrderChangeUnsubscribe = null;
574
579
  paymentMethodsChangedUnsubscribe = null;
580
+ orderSessionChangedUnsubscribe = null;
575
581
  serverOrderChangeHydrateInFlight = null;
576
582
  queuedServerOrderChanges = [];
577
583
  serverOrderChangeSyncEnabled = false;
578
584
  pickupTimingEnabled = false;
579
585
  pickupTimingController;
586
+ fulfillmentItemRulesController;
580
587
  constructor(name, version) {
581
588
  super(name, version);
582
589
  }
@@ -662,8 +669,12 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
662
669
  }
663
670
  this.queuedServerOrderChanges.push(snapshot);
664
671
  }
672
+ shouldSyncServerOrderChanges() {
673
+ const payments = this.store.order?.getTempOrder()?.payments || [];
674
+ return this.serverOrderChangeSyncEnabled || payments.some(_localEftposState.isLocalFinalizedPayment) && !payments.some(_paymentUtils.isPendingOrderPayment);
675
+ }
665
676
  async drainQueuedServerOrderChanges() {
666
- if (!this.serverOrderChangeSyncEnabled || this.salesDetailLoadInFlightCount > 0 || this.serverOrderChangeHydrateInFlight || this.queuedServerOrderChanges.length === 0) return;
677
+ if (!this.shouldSyncServerOrderChanges() || this.salesDetailLoadInFlightCount > 0 || this.serverOrderChangeHydrateInFlight || this.queuedServerOrderChanges.length === 0) return;
667
678
  const changedOrders = this.queuedServerOrderChanges;
668
679
  this.queuedServerOrderChanges = [];
669
680
  await this.syncCurrentSalesDetailFromServerOrderChange({
@@ -671,8 +682,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
671
682
  });
672
683
  }
673
684
  async syncCurrentSalesDetailFromServerOrderChange(payload) {
674
- const changedOrders = Array.isArray(payload) ? payload : Array.isArray(payload?.changedOrders) ? payload.changedOrders : payload?.data && typeof payload.data === 'object' ? [payload.data] : [];
675
- if (!this.serverOrderChangeSyncEnabled) return;
685
+ const fullSnapshotAfterFinalization = Array.isArray(payload?.list) && this.store.order?.getTempOrder()?.payments?.some(_localEftposState.isLocalFinalizedPayment);
686
+ const changedOrders = Array.isArray(payload) ? payload : Array.isArray(payload?.changedOrders) && payload.changedOrders.length > 0 ? payload.changedOrders : fullSnapshotAfterFinalization ? payload.list : payload?.data && typeof payload.data === 'object' ? [payload.data] : [];
687
+ if (!this.shouldSyncServerOrderChanges()) return;
676
688
 
677
689
  // 显式详情加载期间 current 可能仍是上一单,先按订单身份 latest-only 缓存;
678
690
  // load 完成后再用新的 current 过滤,避免恰好到达的最新支付快照丢失。
@@ -726,6 +738,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
726
738
  await this.getPaymentMethodsAsync();
727
739
  });
728
740
  }
741
+ registerOrderSessionChangeSync() {
742
+ this.orderSessionChangedUnsubscribe?.();
743
+ this.orderSessionChangedUnsubscribe = this.store.order?.effectsOn?.('onOrderSessionChanged', payload => this.effectsEmit(_types.BaseSalesHookNames.onOrderSessionChanged, payload)) || null;
744
+ }
729
745
  async hydrateLatestLoadedSalesDetail(record, loadSequence, options) {
730
746
  let hydratedSales = null;
731
747
  let skippedBeforeHydrate = false;
@@ -846,9 +862,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
846
862
  }
847
863
 
848
864
  /**
849
- * Change Time / customer reprice 必须沿用商品列表的渠道口径。
850
- * SalesSdk Provider 通常将渠道存为 platform,因此不能只读取 otherParams.channel。
851
- */
865
+ * Change Time / customer reprice 必须沿用商品列表的渠道口径。
866
+ * SalesSdk Provider 通常将渠道存为 platform,因此不能只读取 otherParams.channel。
867
+ */
852
868
  getPriceQueryChannel(channel) {
853
869
  const strategyContext = this.otherParams?.strategy_context && typeof this.otherParams.strategy_context === 'object' ? this.otherParams.strategy_context : {};
854
870
  const value = channel ?? strategyContext.channel ?? this.otherParams?.channel ?? this.otherParams?.platform;
@@ -1150,7 +1166,33 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1150
1166
  customerId: params.customerId,
1151
1167
  channel: params.channel
1152
1168
  });
1153
- return productIds.map(productId => productId === null ? null : productsById.get(productId) || null);
1169
+ const shouldAlignSelectedVariantPrice = handledByOsServer && this.preferAuthoritativeProductQueryPrice();
1170
+ return productIds.map((productId, index) => {
1171
+ const authoritativeProduct = productId === null ? null : productsById.get(productId) || null;
1172
+ if (authoritativeProduct && (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' && (params.strictDurationPricing || (0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(selectedProducts[index]))) {
1173
+ return (0, _posDurationPricing.resolveDurationPricingProduct)(authoritativeProduct, selectedProducts[index]);
1174
+ }
1175
+ if (!shouldAlignSelectedVariantPrice || !authoritativeProduct) return authoritativeProduct;
1176
+ const selectedProduct = selectedProducts[index];
1177
+ const selectedVariantId = this.getSelectedProductVariantId(selectedProduct);
1178
+ if (!selectedVariantId || this.getSelectedProductVariantId(authoritativeProduct) === selectedVariantId) {
1179
+ return authoritativeProduct;
1180
+ }
1181
+
1182
+ // OS 返回的是目录商品;已命中的智能价格不能被规格基础价覆盖。
1183
+ const appliedFields = authoritativeProduct._dataVariant?.appliedFields;
1184
+ if (Array.isArray(appliedFields) && ['price', 'selling_price', 'original_price', 'base_price'].some(field => appliedFields.includes(field))) {
1185
+ return authoritativeProduct;
1186
+ }
1187
+ const selectedVariant = Array.isArray(authoritativeProduct.variant) ? authoritativeProduct.variant.find(variant => Number(variant?.id) === selectedVariantId) : undefined;
1188
+ const selectedPrice = [selectedVariant?.price, selectedVariant?.selling_price, selectedVariant?.base_price, params.priceQueries[index].fallback_price, selectedProduct.price, selectedProduct.selling_price, selectedProduct.original_price].find(value => (typeof value === 'number' || typeof value === 'string' && value.trim() !== '') && Number.isFinite(Number(value)));
1189
+
1190
+ // 每行独立保留所选规格价格(含 0 元),避免同商品多规格共用目录对象串价。
1191
+ return selectedPrice === undefined ? authoritativeProduct : {
1192
+ ...authoritativeProduct,
1193
+ price: selectedPrice
1194
+ };
1195
+ });
1154
1196
  }
1155
1197
  const queryPayload = this.buildPriceQueryPayload({
1156
1198
  ids,
@@ -1247,6 +1289,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1247
1289
  return {
1248
1290
  ...product,
1249
1291
  ...authoritativeProduct,
1292
+ // An omitted current configuration clears a previous catalog/order snapshot.
1293
+ pricing_method: authoritativeProduct.pricing_method,
1250
1294
  id: product.id ?? authoritativeProduct.id,
1251
1295
  product_id: product.product_id ?? authoritativeProduct.product_id ?? authoritativeProduct.id,
1252
1296
  product_variant_id: product.product_variant_id ?? authoritativeProduct.product_variant_id ?? 0,
@@ -1274,6 +1318,34 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1274
1318
  async loadPickupTimingOpenData(_force) {
1275
1319
  return {};
1276
1320
  }
1321
+ async loadFulfillmentItemRuleOpenData() {
1322
+ const openData = this.otherParams?.openData ?? this.otherParams?.dineInConfig;
1323
+ return openData && typeof openData === 'object' && !Array.isArray(openData) ? openData : null;
1324
+ }
1325
+ getFulfillmentItemRulesController() {
1326
+ if (!this.fulfillmentItemRulesController) {
1327
+ this.fulfillmentItemRulesController = new _fulfillmentItemRules.FulfillmentItemRulesController({
1328
+ getOrder: () => {
1329
+ if (!this.store.order) throw new Error('order 模块未初始化');
1330
+ return this.store.order;
1331
+ },
1332
+ getProducts: () => this.store.products,
1333
+ loadOpenData: () => this.loadFulfillmentItemRuleOpenData(),
1334
+ getScope: () => this.getPickupTimingScope(),
1335
+ getOtherParams: () => this.otherParams,
1336
+ fetchStrategyModels: ids => this.request.get('/promotion', {
1337
+ skip: 1,
1338
+ num: 99,
1339
+ status: 'active',
1340
+ ids
1341
+ }),
1342
+ reportError: error => this.logWarning('履约费用策略执行失败,保留服务类型设置', {
1343
+ error: error instanceof Error ? error.message : String(error)
1344
+ })
1345
+ });
1346
+ }
1347
+ return this.fulfillmentItemRulesController;
1348
+ }
1277
1349
  isPickupTimingEnabled() {
1278
1350
  return this.pickupTimingEnabled && this.otherParams?.enablePickupTiming !== false;
1279
1351
  }
@@ -1302,6 +1374,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1302
1374
  if (!this.store.order) throw new Error('order 模块未初始化');
1303
1375
  return this.store.order;
1304
1376
  },
1377
+ setServiceType: serviceType => this.setServiceType(serviceType),
1305
1378
  getSchedule: () => this.store.schedule,
1306
1379
  loadOpenData: force => this.loadPickupTimingOpenData(force),
1307
1380
  getTimezone: () => String(this.getPickupTimingContextData('timezone') ?? ''),
@@ -1376,11 +1449,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1376
1449
  return undefined;
1377
1450
  }
1378
1451
  }
1452
+
1453
+ /** Only solutions with a current POS business configuration opt into this receipt policy. */
1454
+ getPosReceiptAutoPrintPaymentStatuses() {
1455
+ return undefined;
1456
+ }
1379
1457
  buildSubmitPayloadEnhancerWithOpenDataConfig(enhancePayload) {
1380
1458
  const fulfillmentRefMode = this.getFulfillmentRefMode();
1381
1459
  const invoiceLayoutConfig = this.getCachedInvoiceLayoutConfig();
1382
1460
  const invoiceTemplateSettings = this.getCachedInvoiceTemplateSettings();
1383
- if (!fulfillmentRefMode && !invoiceLayoutConfig && !invoiceTemplateSettings) {
1461
+ const receiptPaymentStatuses = this.getPosReceiptAutoPrintPaymentStatuses();
1462
+ if (!fulfillmentRefMode && !invoiceLayoutConfig && !invoiceTemplateSettings && receiptPaymentStatuses === undefined) {
1384
1463
  return enhancePayload;
1385
1464
  }
1386
1465
  return (payload, ctx) => {
@@ -1395,6 +1474,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1395
1474
  } : {}),
1396
1475
  ...(invoiceTemplateSettings ? {
1397
1476
  [OS_INVOICE_TEMPLATE_SETTINGS_FIELD]: (0, _lodashEs.cloneDeep)(invoiceTemplateSettings)
1477
+ } : {}),
1478
+ ...(receiptPaymentStatuses !== undefined ? {
1479
+ [_posReceiptAutoPrint.OS_POS_RECEIPT_AUTO_PRINT_PAYMENT_STATUSES_FIELD]: [...receiptPaymentStatuses]
1398
1480
  } : {})
1399
1481
  };
1400
1482
  };
@@ -1702,14 +1784,18 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1702
1784
  await this.getPaymentMethodsAsync();
1703
1785
  this.registerPaymentMethodsChangeSync();
1704
1786
  this.registerServerOrderChangeSync();
1787
+ this.registerOrderSessionChangeSync();
1705
1788
  this.core.effects.emit(`${this.name}:onInited`, {});
1706
1789
  }
1707
1790
  async destroy() {
1708
1791
  this.resetPickupTimingCache();
1792
+ this.fulfillmentItemRulesController?.invalidate();
1709
1793
  this.serverOrderChangeUnsubscribe?.();
1710
1794
  this.serverOrderChangeUnsubscribe = null;
1711
1795
  this.paymentMethodsChangedUnsubscribe?.();
1712
1796
  this.paymentMethodsChangedUnsubscribe = null;
1797
+ this.orderSessionChangedUnsubscribe?.();
1798
+ this.orderSessionChangedUnsubscribe = null;
1713
1799
  for (const key of Object.keys(this.store)) {
1714
1800
  if (this.reusedSharedSubModuleNames.has(key)) continue;
1715
1801
  const sub = this.store[key];
@@ -1842,6 +1928,12 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1842
1928
  const result = this.store.order?.getTempOrder() || null;
1843
1929
  return result;
1844
1930
  }
1931
+ getOrderSessionId() {
1932
+ return this.store.order?.getOrderSessionId?.() || null;
1933
+ }
1934
+ isOrderSessionCurrent(sessionId) {
1935
+ return this.store.order?.isOrderSessionCurrent?.(sessionId) || false;
1936
+ }
1845
1937
  async replaceTempOrder(tempOrder, options) {
1846
1938
  if (!this.store.order) throw new Error('order 模块未初始化');
1847
1939
  const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder, options);
@@ -1925,9 +2017,16 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
1925
2017
  if (!this.store.order) throw new Error('order 模块未初始化');
1926
2018
  return this.store.order.updateTempOrderPickupReferenceMode(mode);
1927
2019
  }
1928
- setServiceType(serviceType) {
2020
+ async setServiceType(serviceType) {
1929
2021
  if (!this.store.order) throw new Error('order 模块未初始化');
1930
- return this.store.order.updateTempOrderServiceType(serviceType);
2022
+ const serviceData = this.store.order.updateTempOrderServiceType(serviceType);
2023
+ await this.getFulfillmentItemRulesController().apply(serviceType);
2024
+ // 费用规则可能增删商品;即使没有普通促销,也要同步页面的购物车和金额快照。
2025
+ const tempOrder = this.getTempOrder();
2026
+ if (tempOrder) await this.effectsEmit('onTempOrderReplaced', {
2027
+ tempOrder
2028
+ });
2029
+ return serviceData;
1931
2030
  }
1932
2031
  getPickupTimingBooking() {
1933
2032
  return this.store.order?.getPickupTimingBooking() || null;
@@ -2036,12 +2135,13 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2036
2135
  }
2037
2136
 
2038
2137
  /**
2039
- * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
2138
+ * 清空 tempOrder 购物车行(products / bookings / discount_list)及整单折扣。
2040
2139
  * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
2041
2140
  */
2042
2141
  async clearOrderCartLines() {
2043
2142
  try {
2044
2143
  if (!this.store.order) throw new Error('order 模块未初始化');
2144
+ this.fulfillmentItemRulesController?.invalidate();
2045
2145
  const tempOrder = await this.store.order.clearOrderCartLines();
2046
2146
  if (this.currentSalesDetail) {
2047
2147
  this.currentSalesDetail = {
@@ -2069,6 +2169,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2069
2169
  /** 切换法币 / WalletPass 单位时清空商品、折扣与支付状态,保留客户。 */
2070
2170
  async clearOrderForSettlementSwitch() {
2071
2171
  if (!this.store.order) throw new Error('order 模块未初始化');
2172
+ this.fulfillmentItemRulesController?.invalidate();
2072
2173
  const tempOrder = await this.store.order.clearOrderForSettlementSwitch();
2073
2174
  if (this.currentSalesDetail) {
2074
2175
  this.currentSalesDetail = {
@@ -2250,9 +2351,16 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2250
2351
  const searchedDiscountIds = new Set(searchedDiscountList.map(discount => String(discount.id)));
2251
2352
  let preparedDiscountList = [...searchedDiscountList, ...originalDiscountList.filter(discount => !searchedDiscountIds.has(String(discount.id)))];
2252
2353
  if (customerId && customerId !== 1) {
2253
- if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
2354
+ const inFlight = this.discountConfigPrepareInFlight;
2355
+ // 客户刷新和商品查询共享配置准备;force 仅绕过已完成的缓存。
2356
+ if (inFlight?.key === discountConfigCacheKey && inFlight.epoch === requestEpoch) {
2357
+ preparedDiscountList = await inFlight.promise;
2358
+ if (!isCurrentRequest()) return getCurrentResult();
2359
+ } else if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
2254
2360
  preparedDiscountList = originalDiscountList;
2255
2361
  } else {
2362
+ // 强制刷新失败后,下次普通加载也应重试,不能命中刷新前的缓存。
2363
+ this.discountConfigCacheKey = null;
2256
2364
  const prepareConfigPromise = this.store.order.loadDiscountConfig({
2257
2365
  customerId,
2258
2366
  action: discountAction,
@@ -2261,11 +2369,28 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2261
2369
  });
2262
2370
  // OrderModule increments this epoch synchronously before its first await.
2263
2371
  requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
2264
- preparedDiscountList = await prepareConfigPromise;
2265
- if (!isCurrentRequest()) return getCurrentResult();
2266
- await discountModule?.setOriginalDiscountList?.(preparedDiscountList);
2372
+ const prepareTask = {
2373
+ key: discountConfigCacheKey,
2374
+ epoch: requestEpoch,
2375
+ promise: prepareConfigPromise.then(async discountList => {
2376
+ if (!isCurrentRequest()) return discountList;
2377
+ await discountModule?.setOriginalDiscountList?.(discountList);
2378
+ if (isCurrentRequest()) {
2379
+ this.discountConfigCacheKey = discountConfigCacheKey;
2380
+ }
2381
+ return discountList;
2382
+ })
2383
+ };
2384
+ this.discountConfigPrepareInFlight = prepareTask;
2385
+ try {
2386
+ preparedDiscountList = await prepareTask.promise;
2387
+ } finally {
2388
+ // 旧请求结束时不能清掉客户/订单切换后创建的新任务。
2389
+ if (this.discountConfigPrepareInFlight === prepareTask) {
2390
+ this.discountConfigPrepareInFlight = null;
2391
+ }
2392
+ }
2267
2393
  if (!isCurrentRequest()) return getCurrentResult();
2268
- this.discountConfigCacheKey = discountConfigCacheKey;
2269
2394
  }
2270
2395
  }
2271
2396
  if (this.isActiveVirtualSettlementOrder(tempOrder)) {
@@ -2847,16 +2972,128 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2847
2972
  } : params?.confirmPendingVoucherPayments !== undefined ? {
2848
2973
  confirmPendingVoucherPayments: params.confirmPendingVoucherPayments
2849
2974
  } : {}),
2850
- ...(enhancePayload !== undefined ? {
2975
+ ...(virtualSettlement ? {
2976
+ enhancePayload: (payload, ctx) => {
2977
+ const callerPayload = enhancePayload ? enhancePayload(payload, ctx) : payload;
2978
+ const currencySettlementConfig = callerPayload.metadata?.currency_settlement_config || {};
2979
+ return {
2980
+ ...callerPayload,
2981
+ metadata: {
2982
+ ...(callerPayload.metadata || {}),
2983
+ currency_settlement_config: {
2984
+ ...currencySettlementConfig,
2985
+ settlement_type: 'virtual_currency',
2986
+ settlement_ids: [virtualSettlement.currencyProductId],
2987
+ currency_display_snapshot: (0, _lodashEs.cloneDeep)(currencySettlementConfig.currency_display_snapshot ?? (0, _virtualSettlement.buildCurrencyDisplaySnapshot)(virtualSettlement.snapshot))
2988
+ }
2989
+ },
2990
+ currency_code: virtualSettlement.currencyCode,
2991
+ currency_symbol: virtualSettlement.currencySymbol,
2992
+ currency_format: virtualSettlement.currencyFormat
2993
+ };
2994
+ }
2995
+ } : enhancePayload !== undefined ? {
2851
2996
  enhancePayload
2852
2997
  } : {})
2853
2998
  };
2854
2999
  return this.shouldUseCheckoutSyncTask() ? this.store.order.submitTempOrder(submitParams) : this.store.order.submitTempOrderAsync(submitParams);
2855
3000
  }
3001
+ pendingLocalEftposFinalizations = new Map();
3002
+ async finalizeLocalEftposPayment(params) {
3003
+ const key = `${params.saleId}:${params.paymentNumber}`;
3004
+ // If SQLite rejects the write, retry this known result before another payment can start.
3005
+ this.pendingLocalEftposFinalizations.set(key, params);
3006
+ const response = await this.request.post('/local/finalizeLocalEftposPayment', {
3007
+ sale_id: params.saleId,
3008
+ payment_number: params.paymentNumber,
3009
+ result: params.result,
3010
+ failed_transaction_numbers: params.failedTransactionNumbers
3011
+ }, {
3012
+ osServer: true,
3013
+ customToast: () => {}
3014
+ });
3015
+ if (response?.code !== 200 || !response?.data?.order) {
3016
+ throw new Error(response?.message || '本地支付收尾失败,请刷新订单后重试');
3017
+ }
3018
+ this.pendingLocalEftposFinalizations.delete(key);
3019
+ const {
3020
+ order,
3021
+ payment
3022
+ } = response.data;
3023
+ const temp = this.getTempOrder();
3024
+ const isCurrentOrder = String(temp?.external_sale_number || temp?.order_id) === String(params.saleId) || temp?.order_id && String(temp.order_id) === String(order.order_id);
3025
+ if (isCurrentOrder) {
3026
+ // Persisted by the local route already. Saving a draft here would re-enable protection.
3027
+ if (temp?.payments?.some(item => String(item.payment_number) === params.paymentNumber)) {
3028
+ await this.updateOrderPayment(params.paymentNumber, payment, {
3029
+ persistDraft: false,
3030
+ submitWhenPaid: false
3031
+ });
3032
+ }
3033
+ if ((0, _localEftposState.requiresLocalPaymentRefresh)(order)) {
3034
+ // Set the in-memory gate before the GET so a failed refresh also blocks this page.
3035
+ const currentTemp = this.getTempOrder();
3036
+ if (currentTemp) currentTemp.metadata = {
3037
+ ...currentTemp.metadata,
3038
+ ...order.metadata
3039
+ };
3040
+ try {
3041
+ await this.loadSalesDetail({
3042
+ orderId: order.order_id,
3043
+ forceRemote: true,
3044
+ merge: false
3045
+ });
3046
+ } catch {
3047
+ throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
3048
+ }
3049
+ }
3050
+ } else if ((0, _localEftposState.requiresLocalPaymentRefresh)(order)) {
3051
+ const refreshed = await this.store.order?.getSalesOrderByLookup({
3052
+ lookup: order.order_id,
3053
+ forceRemote: true
3054
+ });
3055
+ if (refreshed?.code !== 200) throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
3056
+ }
3057
+ return response.data;
3058
+ }
2856
3059
 
2857
- /** Validate required contact fields before a new payment is initiated. */
3060
+ /** Entry gate also reads SQLite state, so stale sessions/restarts cannot bypass it. */
2858
3061
  async ensureSalesOrderReadyForPayment() {
3062
+ const temp = this.getTempOrder();
3063
+ const unfinished = [...this.pendingLocalEftposFinalizations.values()].filter(params => String(params.saleId) === String(temp?.external_sale_number) || String(params.saleId) === String(temp?.order_id));
3064
+ if (unfinished.length > 0) {
3065
+ for (const params of unfinished) await this.finalizeLocalEftposPayment(params);
3066
+ throw new Error('订单已更新,请确认商品和金额后重新付款');
3067
+ }
2859
3068
  await this.validateContactInfo();
3069
+ const lookup = temp?.order_id || temp?.external_sale_number;
3070
+ let localOrder = null;
3071
+ if (lookup && this.core?.server?.hasRoute?.('post', '/shop/local/orderPaymentReadiness')) {
3072
+ const response = await this.request.post('/local/orderPaymentReadiness', {
3073
+ sale_id: lookup
3074
+ }, {
3075
+ osServer: true,
3076
+ customToast: () => {}
3077
+ });
3078
+ if (response?.code !== 200) throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
3079
+ localOrder = response.data;
3080
+ }
3081
+ if (!(0, _localEftposState.requiresLocalPaymentRefresh)(temp) && !(0, _localEftposState.requiresLocalPaymentRefresh)(localOrder)) return;
3082
+ const orderId = localOrder?.order_id || temp?.order_id;
3083
+ if (!orderId || String(orderId) === String(temp?.external_sale_number)) {
3084
+ throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
3085
+ }
3086
+ try {
3087
+ await this.loadSalesDetail({
3088
+ orderId,
3089
+ forceRemote: true,
3090
+ merge: false
3091
+ });
3092
+ } catch {
3093
+ throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
3094
+ }
3095
+ // The initiating UI may have captured the old amount before this await.
3096
+ throw new Error('订单已刷新,请确认商品和金额后重新付款');
2860
3097
  }
2861
3098
  async saveSalesOrderDraft(params) {
2862
3099
  if (!this.store.order) {
@@ -2881,11 +3118,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
2881
3118
  throw new Error('BaseSales 解决方案需要 order 模块支持');
2882
3119
  }
2883
3120
  await this.validateContactInfo();
2884
- if (this.isPickupTimingEnabled()) {
2885
- await this.preparePickupTimingForCheckout({
2886
- freeze: true
2887
- });
2888
- }
3121
+ if (this.isPickupTimingEnabled()) await this.preparePickupTimingForCheckout({
3122
+ freeze: true
3123
+ });
2889
3124
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params?.paymentStatus);
2890
3125
  const smallTicketDataFlag = params?.smallTicketDataFlag ?? this.getDefaultCheckoutSmallTicketDataFlag();
2891
3126
  const enhancePayload = this.buildSubmitPayloadEnhancerWithOpenDataConfig(params?.enhancePayload);
@@ -4067,33 +4302,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4067
4302
  });
4068
4303
  }
4069
4304
  async calculateProductBookingPrice(params) {
4070
- const useCustomerUserPricing = this.isCustomerUserPriceQuery();
4071
- const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
4072
- const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
4073
- await this.prepareProductPriceQueryContext(customerId);
4074
- const channel = this.getPriceQueryChannel(params.channel);
4075
- const [authoritativeProduct] = await this.resolveProductsForPriceQuery({
4076
- priceQueries: [params],
4077
- schedule: this.getPriceQuerySchedule(params),
4078
- customerId,
4079
- channel
4080
- });
4081
- const product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
4082
- if (!useCustomerUserPricing) {
4083
- await this.loadQuotationForPriceQuery({
4084
- quotation,
4085
- customer_id: customerId,
4086
- channel
4087
- });
4088
- }
4089
- return (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
4090
- ...params,
4091
- channel,
4092
- product,
4093
- fallback_price: authoritativeProduct ? undefined : params.fallback_price,
4094
- customer_id: customerId,
4095
- quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
4096
- });
4305
+ const [result] = await this.calculateProductBookingPrices([params]);
4306
+ return result;
4097
4307
  }
4098
4308
  getQuotationCustomerScopeInfo() {
4099
4309
  const quotation = this.store.quotation;
@@ -4157,11 +4367,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4157
4367
  }
4158
4368
  return shouldRecalculate;
4159
4369
  }
4160
- async calculateProductBookingPrices(paramsList) {
4161
- if (!paramsList.length) return [];
4162
- const useCustomerUserPricing = this.isCustomerUserPriceQuery();
4163
- const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
4164
- const currentOrderCustomerId = this.getCurrentOrderCustomerId();
4370
+ async resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId, strictDurationPricing = false) {
4165
4371
  const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
4166
4372
  const authoritativeProducts = paramsList.map(() => null);
4167
4373
  const groups = new Map();
@@ -4179,22 +4385,68 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4179
4385
  group.indices.push(index);
4180
4386
  groups.set(groupKey, group);
4181
4387
  });
4182
- await Promise.all(Array.from(groups.values()).map(async group => {
4388
+ await (0, _posDurationPricing.forEachPriceQueryGroup)(Array.from(groups.values()), async group => {
4183
4389
  await this.prepareProductPriceQueryContext(group.customerId);
4184
4390
  const priceQueries = group.indices.map(index => paramsList[index]);
4185
4391
  const resolvedProducts = await this.resolveProductsForPriceQuery({
4186
4392
  priceQueries,
4187
4393
  schedule: group.schedule,
4188
4394
  customerId: group.customerId,
4189
- channel: group.channel
4395
+ channel: group.channel,
4396
+ strictDurationPricing
4190
4397
  });
4191
4398
  group.indices.forEach((originalIndex, groupIndex) => {
4192
4399
  authoritativeProducts[originalIndex] = resolvedProducts[groupIndex] || null;
4193
4400
  });
4194
- }));
4401
+ }, (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' ? 4 : groups.size);
4402
+ return authoritativeProducts;
4403
+ }
4404
+ async calculateProductBookingPrices(paramsList) {
4405
+ if (!paramsList.length) return [];
4406
+ const useCustomerUserPricing = this.isCustomerUserPriceQuery();
4407
+ const isPos = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos';
4408
+ const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
4409
+ const currentOrderCustomerId = this.getCurrentOrderCustomerId();
4410
+ const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
4411
+ const authoritativeProducts = await this.resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId);
4412
+ const plans = paramsList.map((params, index) => {
4413
+ if (!isPos) return null;
4414
+ const product = authoritativeProducts[index];
4415
+ if (!product && ((0, _posDurationPricing.usesPosDurationPricing)(params.product) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(params.product))) {
4416
+ throw (0, _posDurationPricing.durationPricingUnavailable)('The authoritative product is unavailable for duration pricing.');
4417
+ }
4418
+ // Read configuration from the response itself: an omitted field must not inherit an old snapshot.
4419
+ return product && (0, _posDurationPricing.usesPosDurationPricing)(product) ? (0, _posDurationPricing.buildPosDurationPricingPlan)(params, product) : null;
4420
+ });
4421
+ const segmentQueries = [];
4422
+ const segmentQueryIndices = plans.map((plan, index) => plan?.segments.slice(1).map(segment => {
4423
+ const queryIndex = segmentQueries.length;
4424
+ segmentQueries.push({
4425
+ ...paramsList[index],
4426
+ product: {
4427
+ ...paramsList[index].product,
4428
+ product_bundle: undefined
4429
+ },
4430
+ booking: {
4431
+ ...paramsList[index].booking,
4432
+ start_date: segment.start.slice(0, 10),
4433
+ start_time: segment.start.slice(11),
4434
+ end_date: segment.end.slice(0, 10),
4435
+ end_time: segment.end.slice(11)
4436
+ },
4437
+ duration: undefined,
4438
+ fallback_price: undefined
4439
+ });
4440
+ return queryIndex;
4441
+ }) || []);
4442
+ const segmentProducts = await this.resolveProductBookingPriceGroups(segmentQueries, currentOrderCustomerId, true);
4443
+ if (segmentProducts.some(product => !product)) {
4444
+ throw (0, _posDurationPricing.durationPricingUnavailable)('An authoritative product is missing for a billing unit.');
4445
+ }
4195
4446
  if (!useCustomerUserPricing) {
4196
4447
  const quotationContexts = new Map();
4197
4448
  paramsList.forEach((params, index) => {
4449
+ if (plans[index]) return;
4198
4450
  const channel = resolvedChannels[index];
4199
4451
  const key = channel || '';
4200
4452
  if (quotationContexts.has(key)) return;
@@ -4214,14 +4466,50 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
4214
4466
  const product = this.mergeProductForPriceQuery(productInput, authoritativeProduct);
4215
4467
  const customerId = params.customer_id ?? currentOrderCustomerId;
4216
4468
  const channel = resolvedChannels[index];
4217
- return (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
4469
+ const plan = plans[index];
4470
+ if (plan) {
4471
+ const unitProducts = [authoritativeProduct, ...segmentQueryIndices[index].map(queryIndex => segmentProducts[queryIndex])];
4472
+ const prices = unitProducts.map((unitProduct, unitIndex) => (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
4473
+ ...params,
4474
+ channel,
4475
+ product: this.mergeProductForPriceQuery(unitIndex === 0 ? productInput : {
4476
+ ...productInput,
4477
+ product_bundle: undefined
4478
+ }, unitProduct),
4479
+ booking: {
4480
+ ...params.booking,
4481
+ start_date: plan.segments[unitIndex].start.slice(0, 10),
4482
+ start_time: plan.segments[unitIndex].start.slice(11)
4483
+ },
4484
+ duration: undefined,
4485
+ fallback_price: undefined,
4486
+ customer_id: customerId,
4487
+ quotation: undefined
4488
+ }));
4489
+ return (0, _posDurationPricing.combinePosDurationPrices)(plan, prices);
4490
+ }
4491
+ const changedToFixed = isPos && ((0, _posDurationPricing.usesPosDurationPricing)(productInput) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(productInput)) && authoritativeProduct && !(0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct);
4492
+ // A switch to Days can explicitly request the existing per-day quotation path.
4493
+ // Discard the old minute basis, but do not erase that independent legacy input.
4494
+ const keepLegacyDayDuration = changedToFixed && ['day', 'days'].includes(String(authoritativeProduct?.duration?.type || '').trim().toLowerCase()) && ['day', 'days'].includes(String(params.duration?.type || '').trim().toLowerCase());
4495
+ const result = (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
4218
4496
  ...params,
4497
+ ...(changedToFixed && !keepLegacyDayDuration ? {
4498
+ duration: undefined
4499
+ } : {}),
4219
4500
  channel,
4220
4501
  product,
4221
4502
  fallback_price: authoritativeProduct ? undefined : params.fallback_price,
4222
4503
  customer_id: customerId,
4223
4504
  quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
4224
4505
  });
4506
+ return changedToFixed ? {
4507
+ ...result,
4508
+ pricing_method: {
4509
+ type: 'fixed_price'
4510
+ },
4511
+ duration: undefined
4512
+ } : result;
4225
4513
  });
4226
4514
  }
4227
4515
  setProductVoucherGroups(groups) {
@@ -1,8 +1,10 @@
1
1
  import type { OrderModule } from '../../modules/Order';
2
+ import type { ShopServiceType } from '../../modules/Order/types';
2
3
  import type { ScheduleModule } from '../../modules/Schedule';
3
4
  import { type PickupTimingAvailability, type PickupTimingSelection, type PickupTimingValidationResult } from '../../modules/FulfillmentTiming';
4
5
  interface PickupTimingHost {
5
6
  getOrder: () => OrderModule;
7
+ setServiceType?: (serviceType: ShopServiceType) => unknown | Promise<unknown>;
6
8
  getSchedule: () => ScheduleModule | undefined;
7
9
  loadOpenData: (force: boolean) => Promise<Record<string, unknown>>;
8
10
  getTimezone: () => string;
@@ -24,6 +26,8 @@ export declare class PickupTimingController {
24
26
  private getRuntime;
25
27
  private loadConfig;
26
28
  private loadSchedules;
29
+ /** Preserve an existing POS choice without adding it to the shared settings cache. */
30
+ private getEffectiveConfig;
27
31
  private snapshot;
28
32
  getAvailability(params?: {
29
33
  date?: string;