@pisell/pisellos 2.2.244 → 2.2.246

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 (316) hide show
  1. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  2. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  3. package/dist/modules/BookingContext/index.d.ts +48 -0
  4. package/dist/modules/BookingContext/index.js +566 -0
  5. package/dist/modules/BookingContext/types.d.ts +102 -0
  6. package/dist/modules/BookingContext/types.js +51 -0
  7. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  8. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +284 -0
  9. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  10. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +148 -0
  11. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  12. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +218 -0
  13. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  14. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  15. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  16. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  17. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  18. package/dist/modules/BookingContext/utils/index.js +11 -0
  19. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  20. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  21. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  22. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  23. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  24. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  25. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  26. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  27. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  28. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  29. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  30. package/dist/modules/BookingContext/utils/resources.js +486 -0
  31. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  32. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  33. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  34. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  35. package/dist/modules/Cart/utils/cartProduct.js +24 -3
  36. package/dist/modules/Cart/utils/changePrice.js +11 -11
  37. package/dist/modules/Customer/index.d.ts +20 -0
  38. package/dist/modules/Customer/index.js +172 -83
  39. package/dist/modules/Customer/types.d.ts +2 -0
  40. package/dist/modules/Discount/index.d.ts +1 -1
  41. package/dist/modules/Discount/index.js +13 -6
  42. package/dist/modules/Discount/types.d.ts +1 -0
  43. package/dist/modules/OpenData/index.d.ts +8 -0
  44. package/dist/modules/OpenData/index.js +37 -17
  45. package/dist/modules/Order/index.d.ts +277 -18
  46. package/dist/modules/Order/index.js +3581 -779
  47. package/dist/modules/Order/types.d.ts +286 -31
  48. package/dist/modules/Order/types.js +38 -0
  49. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  50. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  51. package/dist/modules/Order/utils.d.ts +147 -5
  52. package/dist/modules/Order/utils.js +750 -104
  53. package/dist/modules/Payment/index.d.ts +10 -13
  54. package/dist/modules/Payment/index.js +467 -837
  55. package/dist/modules/Payment/types.d.ts +2 -0
  56. package/dist/modules/Payment/utils.js +2 -1
  57. package/dist/modules/Payment/walletpass.js +41 -25
  58. package/dist/modules/ProductList/index.d.ts +16 -12
  59. package/dist/modules/ProductList/index.js +133 -59
  60. package/dist/modules/ProductList/types.d.ts +14 -0
  61. package/dist/modules/Quotation/index.d.ts +0 -1
  62. package/dist/modules/Quotation/index.js +25 -22
  63. package/dist/modules/Rules/index.d.ts +4 -0
  64. package/dist/modules/Rules/index.js +97 -70
  65. package/dist/modules/Rules/types.d.ts +1 -0
  66. package/dist/modules/SalesSummary/index.d.ts +8 -25
  67. package/dist/modules/SalesSummary/index.js +86 -35
  68. package/dist/modules/SalesSummary/types.d.ts +4 -1
  69. package/dist/modules/SalesSummary/utils.d.ts +2 -25
  70. package/dist/modules/SalesSummary/utils.js +794 -162
  71. package/dist/modules/Schedule/index.d.ts +7 -0
  72. package/dist/modules/Schedule/index.js +24 -2
  73. package/dist/modules/Summary/index.js +4 -3
  74. package/dist/modules/SurchargeList/index.d.ts +16 -0
  75. package/dist/modules/SurchargeList/index.js +162 -0
  76. package/dist/modules/SurchargeList/types.d.ts +11 -0
  77. package/dist/modules/SurchargeList/types.js +1 -0
  78. package/dist/modules/index.d.ts +2 -0
  79. package/dist/modules/index.js +3 -1
  80. package/dist/plugins/request.d.ts +1 -0
  81. package/dist/server/index.d.ts +204 -1
  82. package/dist/server/index.js +3654 -922
  83. package/dist/server/modules/index.d.ts +2 -0
  84. package/dist/server/modules/index.js +2 -0
  85. package/dist/server/modules/order/index.d.ts +120 -3
  86. package/dist/server/modules/order/index.js +1762 -448
  87. package/dist/server/modules/order/types.d.ts +32 -3
  88. package/dist/server/modules/order/types.js +8 -0
  89. package/dist/server/modules/order/utils/filterBookings.js +26 -3
  90. package/dist/server/modules/order/utils/filterOrders.js +23 -8
  91. package/dist/server/modules/payment/index.d.ts +28 -0
  92. package/dist/server/modules/payment/index.js +305 -0
  93. package/dist/server/modules/payment/types.d.ts +9 -0
  94. package/dist/server/modules/payment/types.js +1 -0
  95. package/dist/server/modules/products/index.d.ts +34 -7
  96. package/dist/server/modules/products/index.js +631 -317
  97. package/dist/server/modules/resource/index.d.ts +2 -0
  98. package/dist/server/modules/resource/index.js +29 -3
  99. package/dist/server/modules/schedule/index.d.ts +4 -4
  100. package/dist/server/modules/schedule/index.js +111 -88
  101. package/dist/server/test.json +713 -0
  102. package/dist/server/utils/small-ticket.d.ts +71 -0
  103. package/dist/server/utils/small-ticket.js +840 -0
  104. package/dist/solution/BaseSales/index.d.ts +133 -10
  105. package/dist/solution/BaseSales/index.js +1950 -447
  106. package/dist/solution/BaseSales/types.d.ts +82 -6
  107. package/dist/solution/BaseSales/types.js +5 -4
  108. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  109. package/dist/solution/BaseSales/utils/cartPromotion.js +1438 -0
  110. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  111. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  112. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  113. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +105 -24
  114. package/dist/solution/BaseSales/utils.d.ts +1 -1
  115. package/dist/solution/BaseSales/utils.js +62 -21
  116. package/dist/solution/BookingByStep/index.d.ts +1 -1
  117. package/dist/solution/BookingTicket/index.d.ts +271 -11
  118. package/dist/solution/BookingTicket/index.js +1777 -242
  119. package/dist/solution/BookingTicket/types.d.ts +118 -1
  120. package/dist/solution/BookingTicket/types.js +41 -2
  121. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  122. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  123. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  124. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  125. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
  126. package/dist/solution/BookingTicket/utils/bookingStatus.js +70 -0
  127. package/dist/solution/BookingTicket/utils/cartView.d.ts +9 -1
  128. package/dist/solution/BookingTicket/utils/cartView.js +94 -7
  129. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  130. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  131. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  132. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  133. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  134. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  135. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  136. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  137. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  138. package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
  139. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  140. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  141. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  142. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  143. package/dist/solution/Checkout/index.d.ts +1 -0
  144. package/dist/solution/Checkout/index.js +10 -9
  145. package/dist/solution/RegisterAndLogin/config.js +2 -10
  146. package/dist/solution/ScanOrder/index.d.ts +9 -3
  147. package/dist/solution/ScanOrder/index.js +241 -134
  148. package/dist/solution/ScanOrder/types.d.ts +9 -5
  149. package/dist/solution/ScanOrder/types.js +2 -3
  150. package/dist/solution/ScanOrder/utils.d.ts +1 -1
  151. package/dist/solution/ScanOrder/utils.js +84 -22
  152. package/dist/solution/VenueBooking/index.d.ts +5 -2
  153. package/dist/solution/VenueBooking/index.js +110 -59
  154. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  155. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  156. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  157. package/dist/types/index.d.ts +10 -0
  158. package/lib/model/strategy/adapter/promotion/evaluator.js +2 -1
  159. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  160. package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
  161. package/lib/modules/BookingContext/index.d.ts +48 -0
  162. package/lib/modules/BookingContext/index.js +368 -0
  163. package/lib/modules/BookingContext/types.d.ts +102 -0
  164. package/lib/modules/BookingContext/types.js +34 -0
  165. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  166. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +276 -0
  167. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  168. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +154 -0
  169. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  170. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +201 -0
  171. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  172. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  173. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  174. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  175. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  176. package/lib/modules/BookingContext/utils/index.js +43 -0
  177. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  178. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  179. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  180. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  181. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  182. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  183. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  184. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  185. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  186. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  187. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  188. package/lib/modules/BookingContext/utils/resources.js +377 -0
  189. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  190. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  191. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  192. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  193. package/lib/modules/Cart/utils/cartProduct.js +20 -3
  194. package/lib/modules/Cart/utils/changePrice.js +12 -20
  195. package/lib/modules/Customer/index.d.ts +20 -0
  196. package/lib/modules/Customer/index.js +64 -11
  197. package/lib/modules/Customer/types.d.ts +2 -0
  198. package/lib/modules/Discount/index.d.ts +1 -1
  199. package/lib/modules/Discount/index.js +9 -1
  200. package/lib/modules/Discount/types.d.ts +1 -0
  201. package/lib/modules/OpenData/index.d.ts +8 -0
  202. package/lib/modules/OpenData/index.js +19 -5
  203. package/lib/modules/Order/index.d.ts +277 -18
  204. package/lib/modules/Order/index.js +2317 -337
  205. package/lib/modules/Order/types.d.ts +286 -31
  206. package/lib/modules/Order/types.js +1 -0
  207. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  208. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  209. package/lib/modules/Order/utils.d.ts +147 -5
  210. package/lib/modules/Order/utils.js +615 -46
  211. package/lib/modules/Payment/index.d.ts +10 -13
  212. package/lib/modules/Payment/index.js +18 -150
  213. package/lib/modules/Payment/types.d.ts +2 -0
  214. package/lib/modules/Payment/utils.js +2 -1
  215. package/lib/modules/Payment/walletpass.js +16 -3
  216. package/lib/modules/ProductList/index.d.ts +16 -12
  217. package/lib/modules/ProductList/index.js +41 -4
  218. package/lib/modules/ProductList/types.d.ts +14 -0
  219. package/lib/modules/Quotation/index.d.ts +0 -1
  220. package/lib/modules/Quotation/index.js +19 -16
  221. package/lib/modules/Rules/index.d.ts +4 -0
  222. package/lib/modules/Rules/index.js +137 -120
  223. package/lib/modules/Rules/types.d.ts +1 -0
  224. package/lib/modules/SalesSummary/index.d.ts +8 -25
  225. package/lib/modules/SalesSummary/index.js +30 -4
  226. package/lib/modules/SalesSummary/types.d.ts +4 -1
  227. package/lib/modules/SalesSummary/utils.d.ts +2 -25
  228. package/lib/modules/SalesSummary/utils.js +645 -91
  229. package/lib/modules/Schedule/index.d.ts +7 -0
  230. package/lib/modules/Schedule/index.js +17 -1
  231. package/lib/modules/Summary/index.js +5 -4
  232. package/lib/modules/SurchargeList/index.d.ts +16 -0
  233. package/lib/modules/SurchargeList/index.js +89 -0
  234. package/lib/modules/SurchargeList/types.d.ts +11 -0
  235. package/lib/modules/SurchargeList/types.js +17 -0
  236. package/lib/modules/index.d.ts +2 -0
  237. package/lib/modules/index.js +5 -1
  238. package/lib/plugins/request.d.ts +1 -0
  239. package/lib/server/index.d.ts +204 -1
  240. package/lib/server/index.js +1891 -59
  241. package/lib/server/modules/index.d.ts +2 -0
  242. package/lib/server/modules/index.js +3 -0
  243. package/lib/server/modules/order/index.d.ts +120 -3
  244. package/lib/server/modules/order/index.js +887 -94
  245. package/lib/server/modules/order/types.d.ts +32 -3
  246. package/lib/server/modules/order/utils/filterBookings.js +24 -5
  247. package/lib/server/modules/order/utils/filterOrders.js +15 -6
  248. package/lib/server/modules/payment/index.d.ts +28 -0
  249. package/lib/server/modules/payment/index.js +192 -0
  250. package/lib/server/modules/payment/types.d.ts +9 -0
  251. package/lib/server/modules/payment/types.js +17 -0
  252. package/lib/server/modules/products/index.d.ts +34 -7
  253. package/lib/server/modules/products/index.js +189 -54
  254. package/lib/server/modules/resource/index.d.ts +2 -0
  255. package/lib/server/modules/resource/index.js +27 -3
  256. package/lib/server/modules/schedule/index.d.ts +4 -4
  257. package/lib/server/modules/schedule/index.js +47 -40
  258. package/lib/server/test.json +713 -0
  259. package/lib/server/utils/small-ticket.d.ts +71 -0
  260. package/lib/server/utils/small-ticket.js +800 -0
  261. package/lib/solution/BaseSales/index.d.ts +133 -10
  262. package/lib/solution/BaseSales/index.js +1111 -63
  263. package/lib/solution/BaseSales/types.d.ts +82 -6
  264. package/lib/solution/BaseSales/types.js +3 -1
  265. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  266. package/lib/solution/BaseSales/utils/cartPromotion.js +992 -0
  267. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  268. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  269. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  270. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +106 -18
  271. package/lib/solution/BaseSales/utils.d.ts +1 -1
  272. package/lib/solution/BaseSales/utils.js +54 -10
  273. package/lib/solution/BookingByStep/index.d.ts +1 -1
  274. package/lib/solution/BookingTicket/index.d.ts +271 -11
  275. package/lib/solution/BookingTicket/index.js +922 -29
  276. package/lib/solution/BookingTicket/types.d.ts +118 -1
  277. package/lib/solution/BookingTicket/types.js +11 -0
  278. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  279. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  280. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  281. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
  282. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
  283. package/lib/solution/BookingTicket/utils/bookingStatus.js +44 -2
  284. package/lib/solution/BookingTicket/utils/cartView.d.ts +9 -1
  285. package/lib/solution/BookingTicket/utils/cartView.js +61 -6
  286. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  287. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  288. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  289. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
  290. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  291. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
  292. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  293. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  294. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  295. package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
  296. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  297. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  298. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  299. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
  300. package/lib/solution/Checkout/index.d.ts +1 -0
  301. package/lib/solution/Checkout/index.js +1 -2
  302. package/lib/solution/RegisterAndLogin/config.js +2 -10
  303. package/lib/solution/ScanOrder/index.d.ts +9 -3
  304. package/lib/solution/ScanOrder/index.js +153 -70
  305. package/lib/solution/ScanOrder/types.d.ts +9 -5
  306. package/lib/solution/ScanOrder/utils.d.ts +1 -1
  307. package/lib/solution/ScanOrder/utils.js +83 -17
  308. package/lib/solution/VenueBooking/index.d.ts +5 -2
  309. package/lib/solution/VenueBooking/index.js +54 -17
  310. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  311. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  312. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  313. package/lib/types/index.d.ts +10 -0
  314. package/package.json +1 -1
  315. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  316. package/lib/solution/Checkout/appointmentDemo.json +0 -1
@@ -1,12 +1,10 @@
1
1
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
2
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
3
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
6
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
4
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
9
5
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
9
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
10
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -22,14 +20,101 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
22
20
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
21
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
24
22
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
24
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
27
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
28
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
25
29
  import { BaseModule } from "../../modules/BaseModule";
30
+ import { BaseSalesHookNames } from "./types";
26
31
  import { OrderModule } from "../../modules/Order";
27
32
  import Decimal from 'decimal.js';
33
+ import { cloneDeep, mergeWith } from 'lodash-es';
28
34
  import { createModule } from "../BookingByStep/types";
29
- import { composeLinePrice, sumOptionUnitPrice } from "../../modules/Order/utils";
35
+ import { composeLinePrice, createUuidV4, ensureProductSku, getProductSkuOptions, sumOptionUnitPrice } from "../../modules/Order/utils";
30
36
  import dayjs from 'dayjs';
31
37
  export * from "./types";
38
+ import { QuotationModule } from "../../modules/Quotation";
32
39
  import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
40
+ import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
41
+ function isBaseSalesManualProductDiscountProduct(product) {
42
+ var _product$metadata, _product$metadata2;
43
+ return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
44
+ return (item === null || item === void 0 ? void 0 : item.type) === 'product';
45
+ });
46
+ }
47
+ function getBaseSalesProductUid(product) {
48
+ var _product$metadata3;
49
+ var uid = (product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
50
+ if (uid === undefined || uid === null || uid === '') return null;
51
+ return String(uid);
52
+ }
53
+ function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
54
+ var previousByUid = new Map();
55
+ (previousProducts || []).forEach(function (product, index) {
56
+ var uid = getBaseSalesProductUid(product);
57
+ if (uid) previousByUid.set(uid, product);
58
+ previousByUid.set("__index__:".concat(index), product);
59
+ });
60
+ return (nextProducts || []).map(function (product, index) {
61
+ var uid = getBaseSalesProductUid(product);
62
+ var previous = (uid ? previousByUid.get(uid) : undefined) || previousByUid.get("__index__:".concat(index));
63
+ return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
64
+ });
65
+ }
66
+ function getBaseSalesUniqueArrayMetadataKey(key) {
67
+ if (key === 'products' || key === 'bookings') return 'unique_identification_number';
68
+ if (key === 'payments' || key === 'payment') return 'unique_payment_number';
69
+ return null;
70
+ }
71
+ function getBaseSalesMetadataUid(item, metadataKey) {
72
+ var _item$metadata$metada, _item$metadata;
73
+ var uid = (_item$metadata$metada = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata[metadataKey]) !== null && _item$metadata$metada !== void 0 ? _item$metadata$metada : item === null || item === void 0 ? void 0 : item[metadataKey];
74
+ if (uid === undefined || uid === null || uid === '') return null;
75
+ return String(uid);
76
+ }
77
+ function mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey) {
78
+ var result = [];
79
+ var indexByUid = new Map();
80
+ var appendOrReplaceByUid = function appendOrReplaceByUid(item) {
81
+ var clonedItem = cloneDeep(item);
82
+ var uid = getBaseSalesMetadataUid(clonedItem, metadataKey);
83
+ if (!uid) {
84
+ result.push(clonedItem);
85
+ return;
86
+ }
87
+ var existingIndex = indexByUid.get(uid);
88
+ if (existingIndex !== undefined) {
89
+ result[existingIndex] = clonedItem;
90
+ return;
91
+ }
92
+ indexByUid.set(uid, result.length);
93
+ result.push(clonedItem);
94
+ };
95
+ currentValue.forEach(appendOrReplaceByUid);
96
+ loadedValue.forEach(appendOrReplaceByUid);
97
+ return result;
98
+ }
99
+ function mergeSalesDetailRecordWithTempOrder(currentTempOrder, loadedRecord) {
100
+ if (!currentTempOrder) return loadedRecord;
101
+ var mergedRecord = mergeWith(cloneDeep(currentTempOrder), cloneDeep(loadedRecord || {}), function (currentValue, loadedValue, key) {
102
+ if (Array.isArray(currentValue) && Array.isArray(loadedValue)) {
103
+ var metadataKey = getBaseSalesUniqueArrayMetadataKey(key);
104
+ if (metadataKey) {
105
+ return mergeBaseSalesUniqueArray(currentValue, loadedValue, metadataKey);
106
+ }
107
+ return [].concat(_toConsumableArray(cloneDeep(currentValue)), _toConsumableArray(cloneDeep(loadedValue)));
108
+ }
109
+ if (Array.isArray(loadedValue)) return cloneDeep(loadedValue);
110
+ if (Array.isArray(currentValue) && loadedValue === undefined) {
111
+ return cloneDeep(currentValue);
112
+ }
113
+ return undefined;
114
+ });
115
+ delete mergedRecord.request_unique_idempotency_token;
116
+ return mergedRecord;
117
+ }
33
118
  export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
34
119
  _inherits(BaseSalesImpl, _BaseModule);
35
120
  var _super = _createSuper(BaseSalesImpl);
@@ -43,6 +128,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
43
128
  _defineProperty(_assertThisInitialized(_this), "initializeOptions", {});
44
129
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
45
130
  // LoggerManager 实例
131
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
46
132
  _defineProperty(_assertThisInitialized(_this), "store", {
47
133
  order: undefined
48
134
  });
@@ -56,17 +142,20 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
56
142
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
57
143
  // 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
58
144
  _defineProperty(_assertThisInitialized(_this), "currentSalesDetail", null);
145
+ _defineProperty(_assertThisInitialized(_this), "discountConfigCacheKey", null);
146
+ _defineProperty(_assertThisInitialized(_this), "hasManualDiscountSelection", false);
147
+ _defineProperty(_assertThisInitialized(_this), "paymentMethodsCache", []);
59
148
  return _this;
60
149
  }
61
150
 
62
151
  /**
63
152
  * 子类可覆盖此方法以追加/收敛要注册的子模块。
64
- * 默认包含通用销售模块:products / order / salesSummary / schedule / payment。
153
+ * 默认包含通用销售模块:products / order / salesSummary / schedule / payment / quotation
65
154
  */
66
155
  _createClass(BaseSalesImpl, [{
67
156
  key: "getRegisteredModuleNames",
68
157
  value: function getRegisteredModuleNames() {
69
- return ['products', 'order', 'salesSummary', 'schedule', 'payment'];
158
+ return ['products', 'order', 'salesSummary', 'schedule', 'payment', 'quotation'];
70
159
  }
71
160
 
72
161
  /**
@@ -116,11 +205,291 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
116
205
  });
117
206
  }
118
207
  }
208
+ }, {
209
+ key: "hydrateOrderPaymentNames",
210
+ value: function hydrateOrderPaymentNames(payments) {
211
+ if (!payments.length) return [];
212
+ if (!this.paymentMethodsCache.length) {
213
+ return payments.map(function (payment) {
214
+ return _objectSpread({}, payment);
215
+ });
216
+ }
217
+ var paymentMethodById = new Map();
218
+ var paymentMethodByCode = new Map();
219
+ this.paymentMethodsCache.forEach(function (method) {
220
+ if ((method === null || method === void 0 ? void 0 : method.id) !== undefined && (method === null || method === void 0 ? void 0 : method.id) !== null) {
221
+ paymentMethodById.set(String(method.id), method);
222
+ }
223
+ if (method !== null && method !== void 0 && method.code) {
224
+ paymentMethodByCode.set(String(method.code), method);
225
+ }
226
+ });
227
+ return payments.map(function (payment) {
228
+ var nextPayment = _objectSpread({}, payment);
229
+ if (nextPayment.name) return nextPayment;
230
+ var paymentMethod = paymentMethodById.get(String(nextPayment.custom_payment_id)) || paymentMethodByCode.get(String(nextPayment.code));
231
+ if (!(paymentMethod !== null && paymentMethod !== void 0 && paymentMethod.name)) return nextPayment;
232
+ return _objectSpread(_objectSpread({}, nextPayment), {}, {
233
+ name: paymentMethod.name
234
+ });
235
+ });
236
+ }
119
237
  }, {
120
238
  key: "payment",
121
239
  get: function get() {
122
240
  return this.store.payment;
123
241
  }
242
+ }, {
243
+ key: "getCurrentOrderCustomerId",
244
+ value: function getCurrentOrderCustomerId() {
245
+ var _this$store$order, _this$store$order$get;
246
+ var tempOrder = (_this$store$order = this.store.order) === null || _this$store$order === void 0 || (_this$store$order$get = _this$store$order.getTempOrder) === null || _this$store$order$get === void 0 ? void 0 : _this$store$order$get.call(_this$store$order);
247
+ var customerId = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.customer_id;
248
+ if (customerId === null || customerId === undefined) return undefined;
249
+ return customerId;
250
+ }
251
+ }, {
252
+ key: "applyQuotationScheduleResolver",
253
+ value: function applyQuotationScheduleResolver(quotation) {
254
+ var scheduleModule = this.store.schedule;
255
+ if (!scheduleModule) return;
256
+ quotation.setScheduleResolver(function (id) {
257
+ var _scheduleModule$getSc;
258
+ var schedules = ((_scheduleModule$getSc = scheduleModule.getScheduleListByIds) === null || _scheduleModule$getSc === void 0 ? void 0 : _scheduleModule$getSc.call(scheduleModule, [id])) || [];
259
+ return schedules[0];
260
+ });
261
+ }
262
+ }, {
263
+ key: "loadQuotationForPriceQuery",
264
+ value: function () {
265
+ var _loadQuotationForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
266
+ var _this$otherParams;
267
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
268
+ while (1) switch (_context.prev = _context.next) {
269
+ case 0:
270
+ if (params.quotation) {
271
+ _context.next = 2;
272
+ break;
273
+ }
274
+ return _context.abrupt("return");
275
+ case 2:
276
+ this.applyQuotationScheduleResolver(params.quotation);
277
+ _context.next = 5;
278
+ return params.quotation.loadQuotations({
279
+ channel: params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel),
280
+ customer_id: params.customer_id
281
+ });
282
+ case 5:
283
+ case "end":
284
+ return _context.stop();
285
+ }
286
+ }, _callee, this);
287
+ }));
288
+ function loadQuotationForPriceQuery(_x) {
289
+ return _loadQuotationForPriceQuery.apply(this, arguments);
290
+ }
291
+ return loadQuotationForPriceQuery;
292
+ }()
293
+ }, {
294
+ key: "getPriceQueryProductId",
295
+ value: function getPriceQueryProductId(product) {
296
+ var _product$product_id;
297
+ var productId = Number((_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product === null || product === void 0 ? void 0 : product.id);
298
+ if (!Number.isFinite(productId)) return null;
299
+ return productId;
300
+ }
301
+ }, {
302
+ key: "getPriceQuerySchedule",
303
+ value: function getPriceQuerySchedule(params) {
304
+ var booking = params.booking || {};
305
+ if (typeof booking.start_date === 'string' && booking.start_date.trim()) {
306
+ var scheduleDate = booking.start_date.trim();
307
+ var startTime = typeof booking.start_time === 'string' && booking.start_time.trim() ? booking.start_time.trim() : '00:00:00';
308
+ var datetime = dayjs("".concat(scheduleDate, " ").concat(startTime));
309
+ return {
310
+ schedule_date: scheduleDate,
311
+ schedule_datetime: datetime.isValid() ? datetime.format('YYYY-MM-DD HH:mm:ss') : "".concat(scheduleDate, " ").concat(startTime)
312
+ };
313
+ }
314
+ if (typeof params.datetime === 'string' && params.datetime.trim()) {
315
+ var _datetime = dayjs(params.datetime.trim());
316
+ if (_datetime.isValid()) {
317
+ return {
318
+ schedule_date: _datetime.format('YYYY-MM-DD'),
319
+ schedule_datetime: _datetime.format('YYYY-MM-DD HH:mm:ss')
320
+ };
321
+ }
322
+ }
323
+ var now = dayjs();
324
+ return {
325
+ schedule_date: now.format('YYYY-MM-DD'),
326
+ schedule_datetime: now.format('YYYY-MM-DD HH:mm:ss')
327
+ };
328
+ }
329
+ }, {
330
+ key: "loadProductForPriceQuery",
331
+ value: function () {
332
+ var _loadProductForPriceQuery = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params, customerId) {
333
+ var product, productId, schedule, _this$otherParams2, _response$data, response, list;
334
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
335
+ while (1) switch (_context2.prev = _context2.next) {
336
+ case 0:
337
+ product = params.product || {};
338
+ productId = this.getPriceQueryProductId(product);
339
+ if (!(productId === null || !this.request)) {
340
+ _context2.next = 4;
341
+ break;
342
+ }
343
+ return _context2.abrupt("return", null);
344
+ case 4:
345
+ schedule = this.getPriceQuerySchedule(params);
346
+ _context2.prev = 5;
347
+ _context2.next = 8;
348
+ return this.request.post('/product/query', {
349
+ ids: [productId],
350
+ open_quotation: 1,
351
+ open_bundle: 1,
352
+ status: 'published',
353
+ num: 1,
354
+ skip: 1,
355
+ customer_id: customerId,
356
+ schedule_date: schedule.schedule_date,
357
+ schedule_datetime: schedule.schedule_datetime,
358
+ application_code: params.channel || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel)
359
+ }, {
360
+ osServer: true,
361
+ customToast: function customToast() {}
362
+ });
363
+ case 8:
364
+ response = _context2.sent;
365
+ list = (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.list) || (response === null || response === void 0 ? void 0 : response.list) || [];
366
+ if (Array.isArray(list)) {
367
+ _context2.next = 12;
368
+ break;
369
+ }
370
+ return _context2.abrupt("return", null);
371
+ case 12:
372
+ return _context2.abrupt("return", list.find(function (item) {
373
+ var _item$id;
374
+ return Number((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id) === productId;
375
+ }) || null);
376
+ case 15:
377
+ _context2.prev = 15;
378
+ _context2.t0 = _context2["catch"](5);
379
+ this.logWarning('loadProductForPriceQuery: 商品重查失败,使用入参 fallback', {
380
+ productId: productId,
381
+ error: _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0)
382
+ });
383
+ return _context2.abrupt("return", null);
384
+ case 19:
385
+ case "end":
386
+ return _context2.stop();
387
+ }
388
+ }, _callee2, this, [[5, 15]]);
389
+ }));
390
+ function loadProductForPriceQuery(_x2, _x3) {
391
+ return _loadProductForPriceQuery.apply(this, arguments);
392
+ }
393
+ return loadProductForPriceQuery;
394
+ }()
395
+ }, {
396
+ key: "getAuthoritativeBundleItems",
397
+ value: function getAuthoritativeBundleItems(product) {
398
+ if (Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle)) return product.product_bundle;
399
+ var groups = Array.isArray(product === null || product === void 0 ? void 0 : product.bundle_group) ? product.bundle_group : Array.isArray(product === null || product === void 0 ? void 0 : product.bundleGroup) ? product.bundleGroup : [];
400
+ return groups.flatMap(function (group) {
401
+ var items = Array.isArray(group === null || group === void 0 ? void 0 : group.bundle_item) ? group.bundle_item : Array.isArray(group === null || group === void 0 ? void 0 : group.bundleItem) ? group.bundleItem : [];
402
+ return items.map(function (item) {
403
+ var _item$group_id, _ref, _item$bundle_group_id;
404
+ return _objectSpread(_objectSpread({}, item), {}, {
405
+ group_id: (_item$group_id = item === null || item === void 0 ? void 0 : item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group === null || group === void 0 ? void 0 : group.id,
406
+ bundle_group_id: (_ref = (_item$bundle_group_id = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item === null || item === void 0 ? void 0 : item.group_id) !== null && _ref !== void 0 ? _ref : group === null || group === void 0 ? void 0 : group.id
407
+ });
408
+ });
409
+ });
410
+ }
411
+ }, {
412
+ key: "findAuthoritativeBundleItem",
413
+ value: function findAuthoritativeBundleItem(bundle, candidates) {
414
+ var _bundle$bundle_id, _bundle$bundle_produc, _bundle$bundle_group_;
415
+ var bundleId = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id;
416
+ if (bundleId != null) {
417
+ var matchedById = candidates.find(function (item) {
418
+ var _item$bundle_id;
419
+ return String((_item$bundle_id = item === null || item === void 0 ? void 0 : item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item === null || item === void 0 ? void 0 : item.id) === String(bundleId);
420
+ });
421
+ if (matchedById) return matchedById;
422
+ }
423
+ var productId = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id;
424
+ var groupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
425
+ return candidates.find(function (item) {
426
+ var _item$bundle_product_, _item$bundle_group_id2;
427
+ var itemProductId = (_item$bundle_product_ = item === null || item === void 0 ? void 0 : item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item === null || item === void 0 ? void 0 : item._bundle_product_id;
428
+ var itemGroupId = (_item$bundle_group_id2 = item === null || item === void 0 ? void 0 : item.bundle_group_id) !== null && _item$bundle_group_id2 !== void 0 ? _item$bundle_group_id2 : item === null || item === void 0 ? void 0 : item.group_id;
429
+ if (productId == null || String(itemProductId) !== String(productId)) return false;
430
+ if (groupId == null) return true;
431
+ return String(itemGroupId) === String(groupId);
432
+ }) || null;
433
+ }
434
+ }, {
435
+ key: "getAuthoritativeBundleUnitPrice",
436
+ value: function getAuthoritativeBundleUnitPrice(bundle) {
437
+ var _ref2, _ref3, _ref4, _bundle$price;
438
+ return (_ref2 = (_ref3 = (_ref4 = (_bundle$price = bundle.price) !== null && _bundle$price !== void 0 ? _bundle$price : bundle.bundle_selling_price) !== null && _ref4 !== void 0 ? _ref4 : bundle.custom_price) !== null && _ref3 !== void 0 ? _ref3 : bundle.product_price) !== null && _ref2 !== void 0 ? _ref2 : bundle.base_price;
439
+ }
440
+ }, {
441
+ key: "mergeProductForPriceQuery",
442
+ value: function mergeProductForPriceQuery(product, authoritativeProduct) {
443
+ var _this2 = this,
444
+ _product$id,
445
+ _ref5,
446
+ _product$product_id2,
447
+ _ref6,
448
+ _product$product_vari,
449
+ _ref7,
450
+ _product$num,
451
+ _ref8,
452
+ _product$quantity,
453
+ _product$metadata4;
454
+ if (!authoritativeProduct) return product;
455
+ var selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
456
+ var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
457
+ var productBundle = selectedBundles.map(function (bundle) {
458
+ var _authoritativeBundle$, _authoritativeBundle$2;
459
+ var authoritativeBundle = _this2.findAuthoritativeBundleItem(bundle, authoritativeBundles);
460
+ var unitPrice = authoritativeBundle ? _this2.getAuthoritativeBundleUnitPrice(authoritativeBundle) : undefined;
461
+ if (unitPrice === undefined || unitPrice === null || unitPrice === '') return bundle;
462
+ return _objectSpread(_objectSpread({}, bundle), {}, {
463
+ price: unitPrice,
464
+ bundle_selling_price: unitPrice,
465
+ base_price: (_authoritativeBundle$ = authoritativeBundle === null || authoritativeBundle === void 0 ? void 0 : authoritativeBundle.base_price) !== null && _authoritativeBundle$ !== void 0 ? _authoritativeBundle$ : bundle.base_price,
466
+ product_price: (_authoritativeBundle$2 = authoritativeBundle === null || authoritativeBundle === void 0 ? void 0 : authoritativeBundle.product_price) !== null && _authoritativeBundle$2 !== void 0 ? _authoritativeBundle$2 : bundle.product_price
467
+ });
468
+ });
469
+ return _objectSpread(_objectSpread(_objectSpread({}, product), authoritativeProduct), {}, {
470
+ id: (_product$id = product.id) !== null && _product$id !== void 0 ? _product$id : authoritativeProduct.id,
471
+ product_id: (_ref5 = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : authoritativeProduct.product_id) !== null && _ref5 !== void 0 ? _ref5 : authoritativeProduct.id,
472
+ product_variant_id: (_ref6 = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : authoritativeProduct.product_variant_id) !== null && _ref6 !== void 0 ? _ref6 : 0,
473
+ num: (_ref7 = (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity) !== null && _ref7 !== void 0 ? _ref7 : authoritativeProduct.num,
474
+ quantity: (_ref8 = (_product$quantity = product.quantity) !== null && _product$quantity !== void 0 ? _product$quantity : product.num) !== null && _ref8 !== void 0 ? _ref8 : authoritativeProduct.quantity,
475
+ product_sku: function () {
476
+ var authoritativeSku = ensureProductSku(authoritativeProduct);
477
+ var productSku = ensureProductSku(product);
478
+ var hasProductSku = product.product_sku && _typeof(product.product_sku) === 'object';
479
+ return _objectSpread(_objectSpread(_objectSpread({}, authoritativeSku), productSku), {}, {
480
+ option: hasProductSku ? productSku.option : authoritativeSku.option
481
+ });
482
+ }(),
483
+ product_bundle: productBundle,
484
+ metadata: (_product$metadata4 = product.metadata) !== null && _product$metadata4 !== void 0 ? _product$metadata4 : authoritativeProduct.metadata
485
+ });
486
+ }
487
+ }, {
488
+ key: "getSubmitOrderSalesChannel",
489
+ value: function getSubmitOrderSalesChannel() {
490
+ var _this$otherParams3;
491
+ return (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.channel;
492
+ }
124
493
 
125
494
  /**
126
495
  * 工厂入口:根据子模块名实例化对应模块。
@@ -130,6 +499,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
130
499
  }, {
131
500
  key: "createSubModule",
132
501
  value: function createSubModule(moduleName) {
502
+ if (moduleName === 'quotation') {
503
+ return new QuotationModule("".concat(this.name, "_quotation"));
504
+ }
133
505
  return createModule(moduleName, this.name);
134
506
  }
135
507
  }, {
@@ -146,10 +518,89 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
146
518
  return optionHooks[moduleName] || ((_this$otherParams$mod = this.otherParams[moduleName]) === null || _this$otherParams$mod === void 0 ? void 0 : _this$otherParams$mod.hooks) || otherHooks[moduleName];
147
519
  }
148
520
 
521
+ /**
522
+ * 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
523
+ *
524
+ * @example
525
+ * const params = this.buildSubModuleOtherParams();
526
+ * this.core.registerModule(orderModule, { otherParams: params });
527
+ */
528
+ }, {
529
+ key: "buildSubModuleOtherParams",
530
+ value: function buildSubModuleOtherParams() {
531
+ return _objectSpread(_objectSpread({}, this.otherParams), {}, {
532
+ salesSummaryModuleName: "".concat(this.name, "_salesSummary"),
533
+ fatherModule: this.name,
534
+ openCache: this.cacheId ? true : false,
535
+ cacheId: this.cacheId
536
+ });
537
+ }
538
+
539
+ /**
540
+ * 将父级 otherParams 的变更显式同步给已注册的子模块。
541
+ *
542
+ * @example
543
+ * await this.syncOtherParamsToSubModules({ channel: 'pos' });
544
+ */
545
+ }, {
546
+ key: "syncOtherParamsToSubModules",
547
+ value: (function () {
548
+ var _syncOtherParamsToSubModules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(changedParams) {
549
+ var _ref9,
550
+ _ref9$cover,
551
+ cover,
552
+ nextSubModuleOtherParams,
553
+ _args4 = arguments;
554
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
555
+ while (1) switch (_context4.prev = _context4.next) {
556
+ case 0:
557
+ _ref9 = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {}, _ref9$cover = _ref9.cover, cover = _ref9$cover === void 0 ? false : _ref9$cover;
558
+ nextSubModuleOtherParams = this.buildSubModuleOtherParams();
559
+ _context4.next = 4;
560
+ return Promise.all(Object.values(this.store).map( /*#__PURE__*/function () {
561
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(subModule) {
562
+ var targetModule;
563
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
564
+ while (1) switch (_context3.prev = _context3.next) {
565
+ case 0:
566
+ targetModule = subModule;
567
+ if (!(!targetModule || typeof targetModule.updateOtherParams !== 'function')) {
568
+ _context3.next = 3;
569
+ break;
570
+ }
571
+ return _context3.abrupt("return");
572
+ case 3:
573
+ _context3.next = 5;
574
+ return targetModule.updateOtherParams(nextSubModuleOtherParams, {
575
+ changedParams: changedParams,
576
+ cover: cover
577
+ });
578
+ case 5:
579
+ case "end":
580
+ return _context3.stop();
581
+ }
582
+ }, _callee3);
583
+ }));
584
+ return function (_x5) {
585
+ return _ref10.apply(this, arguments);
586
+ };
587
+ }()));
588
+ case 4:
589
+ case "end":
590
+ return _context4.stop();
591
+ }
592
+ }, _callee4, this);
593
+ }));
594
+ function syncOtherParamsToSubModules(_x4) {
595
+ return _syncOtherParamsToSubModules.apply(this, arguments);
596
+ }
597
+ return syncOtherParamsToSubModules;
598
+ }()
149
599
  /**
150
600
  * 读取 sessionStorage[this.name][cacheId],作为子模块 initialState 的来源。
151
601
  * sessionStorage 损坏时静默忽略,按空状态注册。
152
602
  */
603
+ )
153
604
  }, {
154
605
  key: "readSessionCacheData",
155
606
  value: function readSessionCacheData() {
@@ -163,77 +614,126 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
163
614
  return {};
164
615
  }
165
616
  }
617
+ }, {
618
+ key: "getAppData",
619
+ value: function getAppData(key) {
620
+ var _this$appPlugin$getDa, _this$appPlugin, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
621
+ var getData = (_this$appPlugin$getDa = (_this$appPlugin = this.appPlugin).getData) === null || _this$appPlugin$getDa === void 0 ? void 0 : _this$appPlugin$getDa.call(_this$appPlugin);
622
+ if (typeof getData === 'function') return getData(key);
623
+ var app = this.appPlugin.getApp();
624
+ var coreData = app === null || app === void 0 || (_app$models = app.models) === null || _app$models === void 0 || (_app$models$getStore = _app$models.getStore) === null || _app$models$getStore === void 0 || (_app$models$getStore$ = (_app$models$getStore$2 = _app$models$getStore.call(_app$models)).getDataByModel) === null || _app$models$getStore$ === void 0 ? void 0 : _app$models$getStore$.call(_app$models$getStore$2, 'core', 'core');
625
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
626
+ }
627
+ }, {
628
+ key: "syncAppDataToTempOrder",
629
+ value: function syncAppDataToTempOrder(tempOrder) {
630
+ var isPriceIncludeTax = this.getAppData('is_price_include_tax');
631
+ var taxCountryCode = this.getAppData('tax_country_code');
632
+ var currencyCode = this.getAppData('shop_currency_code');
633
+ var currencySymbol = this.getAppData('shop_symbol');
634
+ var isChanged = false;
635
+ if (isPriceIncludeTax !== undefined) {
636
+ var nextIsPriceIncludeTax = Number(isPriceIncludeTax);
637
+ if ((nextIsPriceIncludeTax === 0 || nextIsPriceIncludeTax === 1) && tempOrder.is_price_include_tax !== nextIsPriceIncludeTax) {
638
+ tempOrder.is_price_include_tax = nextIsPriceIncludeTax;
639
+ isChanged = true;
640
+ }
641
+ }
642
+ if (taxCountryCode !== undefined) {
643
+ var nextTaxCountryCode = String(taxCountryCode || '');
644
+ if (tempOrder.tax_country_code !== nextTaxCountryCode) {
645
+ tempOrder.tax_country_code = nextTaxCountryCode;
646
+ isChanged = true;
647
+ }
648
+ }
649
+ if (currencyCode !== undefined) {
650
+ var nextCurrencyCode = String(currencyCode || '');
651
+ if (tempOrder.currency_code !== nextCurrencyCode) {
652
+ tempOrder.currency_code = nextCurrencyCode;
653
+ isChanged = true;
654
+ }
655
+ }
656
+ if (currencySymbol !== undefined) {
657
+ var nextCurrencySymbol = String(currencySymbol || '');
658
+ if (tempOrder.currency_symbol !== nextCurrencySymbol) {
659
+ tempOrder.currency_symbol = nextCurrencySymbol;
660
+ isChanged = true;
661
+ }
662
+ }
663
+ return isChanged;
664
+ }
166
665
  }, {
167
666
  key: "initialize",
168
667
  value: function () {
169
- var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core) {
170
- var _this$otherParams,
171
- _this2 = this;
668
+ var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(core) {
669
+ var _this$otherParams4,
670
+ _this3 = this,
671
+ _this$otherParams5;
172
672
  var options,
173
- appPlugin,
174
673
  app,
175
674
  targetCacheData,
176
675
  moduleNames,
177
- _args = arguments;
178
- return _regeneratorRuntime().wrap(function _callee$(_context) {
179
- while (1) switch (_context.prev = _context.next) {
676
+ _args5 = arguments;
677
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
678
+ while (1) switch (_context5.prev = _context5.next) {
180
679
  case 0:
181
- options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
680
+ options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
182
681
  this.core = core;
183
682
  this.initializeOptions = options || {};
184
683
  // this.store = { ...this.store, ...(options.store as Partial<BaseSalesState>) };
185
684
  this.otherParams = options.otherParams || {};
186
- this.cacheId = (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.cacheId;
685
+ this.cacheId = (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.cacheId;
187
686
  this.window = core.getPlugin('window');
188
687
  this.request = core.getPlugin('request');
189
688
 
190
689
  // 获取 logger 实例
191
- appPlugin = core.getPlugin('app');
192
- if (appPlugin) {
193
- _context.next = 10;
690
+ this.appPlugin = core.getPlugin('app');
691
+ if (this.appPlugin) {
692
+ _context5.next = 10;
194
693
  break;
195
694
  }
196
695
  throw new Error('Checkout 解决方案需要 app 插件支持');
197
696
  case 10:
198
- app = appPlugin.getApp();
697
+ app = this.appPlugin.getApp();
199
698
  this.logger = app.logger;
200
699
  targetCacheData = this.readSessionCacheData();
201
700
  moduleNames = this.getRegisteredModuleNames();
202
701
  moduleNames.forEach(function (step) {
203
- var targetModule = _this2.createSubModule(step);
702
+ var targetModule = _this3.createSubModule(step);
204
703
  if (!targetModule) {
205
704
  throw new Error("\u6A21\u5757 ".concat(step, " \u4E0D\u5B58\u5728"));
206
705
  }
207
- var hooks = _this2.getSubModuleHooks(step);
208
- _this2.store[step] = targetModule;
209
- _this2.core.registerModule(targetModule, _objectSpread(_objectSpread({
706
+ var hooks = _this3.getSubModuleHooks(step);
707
+ _this3.store[step] = targetModule;
708
+ _this3.core.registerModule(targetModule, _objectSpread(_objectSpread({
210
709
  initialState: (targetCacheData === null || targetCacheData === void 0 ? void 0 : targetCacheData[targetModule.name]) || {}
211
710
  }, hooks ? {
212
711
  hooks: hooks
213
712
  } : {}), {}, {
214
- otherParams: _objectSpread(_objectSpread({}, _this2.otherParams), {}, {
215
- salesSummaryModuleName: "".concat(_this2.name, "_salesSummary"),
216
- fatherModule: _this2.name,
217
- openCache: _this2.cacheId ? true : false,
218
- cacheId: _this2.cacheId
219
- })
713
+ otherParams: _this3.buildSubModuleOtherParams()
220
714
  }));
221
715
  });
222
716
  if (!this.store.schedule) {
223
- _context.next = 18;
717
+ _context5.next = 18;
224
718
  break;
225
719
  }
226
- _context.next = 18;
720
+ _context5.next = 18;
227
721
  return this.store.schedule.loadAllSchedule();
228
722
  case 18:
723
+ if (this.store.order && typeof ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.enableTempOrderPersist) === 'boolean') {
724
+ this.store.order.setEnableTempOrderPersist(this.otherParams.enableTempOrderPersist);
725
+ }
726
+ _context5.next = 21;
727
+ return this.getPaymentMethodsAsync();
728
+ case 21:
229
729
  this.core.effects.emit("".concat(this.name, ":onInited"), {});
230
- case 19:
730
+ case 22:
231
731
  case "end":
232
- return _context.stop();
732
+ return _context5.stop();
233
733
  }
234
- }, _callee, this);
734
+ }, _callee5, this);
235
735
  }));
236
- function initialize(_x) {
736
+ function initialize(_x6) {
237
737
  return _initialize.apply(this, arguments);
238
738
  }
239
739
  return initialize;
@@ -241,13 +741,13 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
241
741
  }, {
242
742
  key: "destroy",
243
743
  value: function () {
244
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
245
- var _this3 = this;
246
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
247
- while (1) switch (_context2.prev = _context2.next) {
744
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
745
+ var _this4 = this;
746
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
747
+ while (1) switch (_context6.prev = _context6.next) {
248
748
  case 0:
249
749
  Object.keys(this.store).forEach(function (key) {
250
- var sub = _this3.store[key];
750
+ var sub = _this4.store[key];
251
751
  if (sub && typeof sub.destroy === 'function') {
252
752
  try {
253
753
  sub.destroy();
@@ -257,15 +757,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
257
757
  }
258
758
  });
259
759
  this.currentSalesDetail = null;
260
- _context2.next = 4;
760
+ _context6.next = 4;
261
761
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
262
762
  case 4:
263
763
  _get(_getPrototypeOf(BaseSalesImpl.prototype), "destroy", this).call(this);
264
764
  case 5:
265
765
  case "end":
266
- return _context2.stop();
766
+ return _context6.stop();
267
767
  }
268
- }, _callee2, this);
768
+ }, _callee6, this);
269
769
  }));
270
770
  function destroy() {
271
771
  return _destroy.apply(this, arguments);
@@ -274,7 +774,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
274
774
  }()
275
775
  /**
276
776
  * 加载销售订单到统一 tempOrder 工作区。
277
- * app.sqlite 时优先读取本地记录;本地未命中或 forceRemote=true 时再拉云端。
777
+ * 统一通过 OrderModule sales detail lookup 加载订单详情。
278
778
  *
279
779
  * 子类可在 `super.loadSalesDetail` 之后基于返回的 `sales` 做业务侧装配
280
780
  * (比如把 `sales.customer` 写入 CustomerModule、emit 业务 hook 等)。
@@ -282,13 +782,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
282
782
  }, {
283
783
  key: "loadSalesDetail",
284
784
  value: (function () {
285
- var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(orderIdOrParams) {
286
- var params, externalSaleNumber, localRecord, _sales, res, message, sales;
287
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
288
- while (1) switch (_context3.prev = _context3.next) {
785
+ var _loadSalesDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(orderIdOrParams) {
786
+ var _ref11, _params$orderId;
787
+ var params, externalSaleNumber, lookup, res, message, currentTempOrder, record, sales;
788
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
789
+ while (1) switch (_context7.prev = _context7.next) {
289
790
  case 0:
290
791
  if (this.store.order) {
291
- _context3.next = 2;
792
+ _context7.next = 2;
292
793
  break;
293
794
  }
294
795
  throw new Error('order 模块未初始化');
@@ -297,108 +798,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
297
798
  orderId: orderIdOrParams
298
799
  };
299
800
  externalSaleNumber = params.externalSaleNumber || params.external_sale_number;
300
- if (params.forceRemote) {
301
- _context3.next = 35;
302
- break;
303
- }
304
- if (!(params.orderId !== undefined)) {
305
- _context3.next = 11;
306
- break;
307
- }
308
- _context3.next = 8;
309
- return this.store.order.getLocalOrderByOrderId(params.orderId);
310
- case 8:
311
- _context3.t0 = _context3.sent;
312
- _context3.next = 26;
313
- break;
314
- case 11:
315
- if (!externalSaleNumber) {
316
- _context3.next = 17;
317
- break;
318
- }
319
- _context3.next = 14;
320
- return this.store.order.getLocalOrderByExternalSaleNumber(externalSaleNumber);
321
- case 14:
322
- _context3.t1 = _context3.sent;
323
- _context3.next = 25;
324
- break;
325
- case 17:
326
- if (!params.orderNumber) {
327
- _context3.next = 23;
328
- break;
329
- }
330
- _context3.next = 20;
331
- return this.store.order.getLocalOrderByOrderNumber(params.orderNumber);
332
- case 20:
333
- _context3.t2 = _context3.sent;
334
- _context3.next = 24;
335
- break;
336
- case 23:
337
- _context3.t2 = null;
338
- case 24:
339
- _context3.t1 = _context3.t2;
340
- case 25:
341
- _context3.t0 = _context3.t1;
342
- case 26:
343
- localRecord = _context3.t0;
344
- if (!localRecord) {
345
- _context3.next = 35;
801
+ lookup = (_ref11 = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : externalSaleNumber) !== null && _ref11 !== void 0 ? _ref11 : params.orderNumber;
802
+ if (!(lookup === undefined || lookup === null || lookup === '')) {
803
+ _context7.next = 7;
346
804
  break;
347
805
  }
348
- _context3.next = 30;
349
- return this.store.order.hydrateTempOrderFromRecord(localRecord, {
350
- recalcOnHydrate: false
351
- });
352
- case 30:
353
- _sales = _context3.sent;
354
- this.currentSalesDetail = _sales;
355
- _context3.next = 34;
356
- return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
357
- sales: _sales
806
+ throw new Error('加载销售详情需要 orderId、externalSaleNumber 或 orderNumber');
807
+ case 7:
808
+ _context7.next = 9;
809
+ return this.store.order.getSalesOrderByLookup({
810
+ lookup: lookup,
811
+ forceRemote: params.forceRemote
358
812
  });
359
- case 34:
360
- return _context3.abrupt("return", _sales);
361
- case 35:
362
- if (!(params.orderId === undefined || params.orderId === null)) {
363
- _context3.next = 37;
364
- break;
365
- }
366
- throw new Error('加载销售详情需要 orderId,或本地库中存在对应 externalSaleNumber/orderNumber');
367
- case 37:
368
- _context3.next = 39;
369
- return this.store.order.getOrderInfoByRemote(Number(params.orderId));
370
- case 39:
371
- res = _context3.sent;
813
+ case 9:
814
+ res = _context7.sent;
372
815
  if (!(!res || res.code !== 200)) {
373
- _context3.next = 43;
816
+ _context7.next = 13;
374
817
  break;
375
818
  }
376
- message = res && (res.message || res.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(params.orderId);
819
+ message = res && (res.message || res.msg) || "\u52A0\u8F7D\u9500\u552E\u8BE6\u60C5\u5931\u8D25: ".concat(lookup);
377
820
  throw new Error(message);
378
- case 43:
379
- _context3.next = 45;
380
- return this.store.order.hydrateTempOrderFromRecord(res.data, {
821
+ case 13:
822
+ currentTempOrder = params.merge ? this.store.order.getTempOrder() : null;
823
+ record = params.merge ? mergeSalesDetailRecordWithTempOrder(currentTempOrder, res.data) : res.data;
824
+ _context7.next = 17;
825
+ return this.store.order.hydrateTempOrderFromRecord(record, {
381
826
  recalcOnHydrate: false
382
827
  });
383
- case 45:
384
- sales = _context3.sent;
385
- _context3.next = 48;
386
- return this.store.order.saveDraft();
387
- case 48:
828
+ case 17:
829
+ sales = _context7.sent;
388
830
  this.currentSalesDetail = sales;
389
- _context3.next = 51;
831
+ _context7.next = 21;
390
832
  return this.core.effects.emit("".concat(this.name, ":onSalesOrderLoaded"), {
391
833
  sales: sales
392
834
  });
393
- case 51:
394
- return _context3.abrupt("return", sales);
395
- case 52:
835
+ case 21:
836
+ return _context7.abrupt("return", sales);
837
+ case 22:
396
838
  case "end":
397
- return _context3.stop();
839
+ return _context7.stop();
398
840
  }
399
- }, _callee3, this);
841
+ }, _callee7, this);
400
842
  }));
401
- function loadSalesDetail(_x2) {
843
+ function loadSalesDetail(_x7) {
402
844
  return _loadSalesDetail.apply(this, arguments);
403
845
  }
404
846
  return loadSalesDetail;
@@ -471,10 +913,45 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
471
913
  }, {
472
914
  key: "getTempOrder",
473
915
  value: function getTempOrder() {
474
- var _this$store$order;
475
- var result = ((_this$store$order = this.store.order) === null || _this$store$order === void 0 ? void 0 : _this$store$order.getTempOrder()) || null;
916
+ var _this$store$order2;
917
+ var result = ((_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.getTempOrder()) || null;
476
918
  return result;
477
919
  }
920
+ }, {
921
+ key: "replaceTempOrder",
922
+ value: function () {
923
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(tempOrder) {
924
+ var nextTempOrder;
925
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
926
+ while (1) switch (_context8.prev = _context8.next) {
927
+ case 0:
928
+ if (this.store.order) {
929
+ _context8.next = 2;
930
+ break;
931
+ }
932
+ throw new Error('order 模块未初始化');
933
+ case 2:
934
+ _context8.next = 4;
935
+ return this.store.order.replaceTempOrder(tempOrder);
936
+ case 4:
937
+ nextTempOrder = _context8.sent;
938
+ _context8.next = 7;
939
+ return this.effectsEmit('onTempOrderReplaced', {
940
+ tempOrder: nextTempOrder
941
+ });
942
+ case 7:
943
+ return _context8.abrupt("return", nextTempOrder);
944
+ case 8:
945
+ case "end":
946
+ return _context8.stop();
947
+ }
948
+ }, _callee8, this);
949
+ }));
950
+ function replaceTempOrder(_x8) {
951
+ return _replaceTempOrder.apply(this, arguments);
952
+ }
953
+ return replaceTempOrder;
954
+ }()
478
955
  }, {
479
956
  key: "getOrderIdentity",
480
957
  value: function getOrderIdentity() {
@@ -508,26 +985,55 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
508
985
  }, {
509
986
  key: "updateTempOrderNote",
510
987
  value: function updateTempOrderNote(note) {
988
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
511
989
  try {
512
990
  if (!this.store.order) throw new Error('order 模块未初始化');
513
- var result = this.store.order.updateTempOrderNote(note);
991
+ var result = this.store.order.updateTempOrderNote(note, sync);
514
992
  return result;
515
993
  } catch (error) {
516
994
  throw error;
517
995
  }
518
996
  }
997
+ }, {
998
+ key: "updateRemoteOrderNote",
999
+ value: function updateRemoteOrderNote(orderId, note) {
1000
+ if (!this.store.order) throw new Error('order 模块未初始化');
1001
+ this.store.order.syncTempOrderNoteToRemote(orderId, note);
1002
+ }
519
1003
  }, {
520
1004
  key: "updateTempOrderShopDiscount",
521
1005
  value: function updateTempOrderShopDiscount(amount) {
522
1006
  if (!this.store.order) throw new Error('order 模块未初始化');
523
1007
  return this.store.order.updateTempOrderShopDiscount(amount);
524
1008
  }
1009
+ }, {
1010
+ key: "updateTempOrderDepositAmount",
1011
+ value: function updateTempOrderDepositAmount(amount) {
1012
+ if (!this.store.order) throw new Error('order 模块未初始化');
1013
+ return this.store.order.updateTempOrderDepositAmount(amount);
1014
+ }
525
1015
  }, {
526
1016
  key: "updateTempOrderContactsInfo",
527
1017
  value: function updateTempOrderContactsInfo(contactsInfo) {
528
1018
  if (!this.store.order) throw new Error('order 模块未初始化');
529
1019
  return this.store.order.updateTempOrderContactsInfo(contactsInfo);
530
1020
  }
1021
+
1022
+ /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
1023
+ }, {
1024
+ key: "setEnableTempOrderPersist",
1025
+ value: function setEnableTempOrderPersist(enabled) {
1026
+ if (!this.store.order) throw new Error('order 模块未初始化');
1027
+ this.store.order.setEnableTempOrderPersist(enabled);
1028
+ }
1029
+
1030
+ /** 是否允许 saveDraft 写入 IndexedDB 草稿。 */
1031
+ }, {
1032
+ key: "isTempOrderPersistEnabled",
1033
+ value: function isTempOrderPersistEnabled() {
1034
+ if (!this.store.order) return false;
1035
+ return this.store.order.isTempOrderPersistEnabled();
1036
+ }
531
1037
  }, {
532
1038
  key: "ensureTempOrder",
533
1039
  value: function ensureTempOrder() {
@@ -539,32 +1045,40 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
539
1045
  }, {
540
1046
  key: "addNewOrder",
541
1047
  value: function () {
542
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1048
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
543
1049
  var tempOrder;
544
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
545
- while (1) switch (_context4.prev = _context4.next) {
1050
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1051
+ while (1) switch (_context9.prev = _context9.next) {
546
1052
  case 0:
547
- _context4.prev = 0;
1053
+ _context9.prev = 0;
548
1054
  if (this.store.order) {
549
- _context4.next = 3;
1055
+ _context9.next = 3;
550
1056
  break;
551
1057
  }
552
1058
  throw new Error('order 模块未初始化');
553
1059
  case 3:
554
- _context4.next = 5;
1060
+ _context9.next = 5;
555
1061
  return this.store.order.addNewOrder();
556
1062
  case 5:
557
- tempOrder = _context4.sent;
558
- return _context4.abrupt("return", tempOrder);
559
- case 9:
560
- _context4.prev = 9;
561
- _context4.t0 = _context4["catch"](0);
562
- throw _context4.t0;
563
- case 12:
1063
+ tempOrder = _context9.sent;
1064
+ if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1065
+ _context9.next = 10;
1066
+ break;
1067
+ }
1068
+ this.store.order.persistTempOrder();
1069
+ _context9.next = 10;
1070
+ return this.store.order.saveDraft();
1071
+ case 10:
1072
+ return _context9.abrupt("return", tempOrder);
1073
+ case 13:
1074
+ _context9.prev = 13;
1075
+ _context9.t0 = _context9["catch"](0);
1076
+ throw _context9.t0;
1077
+ case 16:
564
1078
  case "end":
565
- return _context4.stop();
1079
+ return _context9.stop();
566
1080
  }
567
- }, _callee4, this, [[0, 9]]);
1081
+ }, _callee9, this, [[0, 13]]);
568
1082
  }));
569
1083
  function addNewOrder() {
570
1084
  return _addNewOrder.apply(this, arguments);
@@ -574,22 +1088,22 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
574
1088
  }, {
575
1089
  key: "saveDraft",
576
1090
  value: function () {
577
- var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
578
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
579
- while (1) switch (_context5.prev = _context5.next) {
1091
+ var _saveDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
1092
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1093
+ while (1) switch (_context10.prev = _context10.next) {
580
1094
  case 0:
581
1095
  if (this.store.order) {
582
- _context5.next = 2;
1096
+ _context10.next = 2;
583
1097
  break;
584
1098
  }
585
1099
  throw new Error('order 模块未初始化');
586
1100
  case 2:
587
- return _context5.abrupt("return", this.store.order.saveDraft());
1101
+ return _context10.abrupt("return", this.store.order.saveDraft());
588
1102
  case 3:
589
1103
  case "end":
590
- return _context5.stop();
1104
+ return _context10.stop();
591
1105
  }
592
- }, _callee5, this);
1106
+ }, _callee10, this);
593
1107
  }));
594
1108
  function saveDraft() {
595
1109
  return _saveDraft.apply(this, arguments);
@@ -600,36 +1114,113 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
600
1114
  }, {
601
1115
  key: "restoreOrder",
602
1116
  value: function () {
603
- var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1117
+ var _restoreOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
604
1118
  var tempOrder;
605
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
606
- while (1) switch (_context6.prev = _context6.next) {
1119
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1120
+ while (1) switch (_context11.prev = _context11.next) {
607
1121
  case 0:
608
- _context6.prev = 0;
1122
+ _context11.prev = 0;
609
1123
  if (this.store.order) {
610
- _context6.next = 3;
1124
+ _context11.next = 3;
611
1125
  break;
612
1126
  }
613
1127
  throw new Error('scanOrder 解决方案需要 order 模块支持');
614
1128
  case 3:
615
1129
  // this.store.resource = null;
616
1130
  tempOrder = this.store.order.restoreOrder();
617
- return _context6.abrupt("return", tempOrder);
618
- case 7:
619
- _context6.prev = 7;
620
- _context6.t0 = _context6["catch"](0);
621
- throw _context6.t0;
622
- case 10:
1131
+ this.currentSalesDetail = null;
1132
+ this.discountConfigCacheKey = null;
1133
+ this.hasManualDiscountSelection = false;
1134
+ _context11.next = 9;
1135
+ return this.effectsEmit('onTempOrderReplaced', {
1136
+ tempOrder: tempOrder
1137
+ });
1138
+ case 9:
1139
+ if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1140
+ _context11.next = 13;
1141
+ break;
1142
+ }
1143
+ this.store.order.persistTempOrder();
1144
+ _context11.next = 13;
1145
+ return this.store.order.saveDraft();
1146
+ case 13:
1147
+ return _context11.abrupt("return", tempOrder);
1148
+ case 16:
1149
+ _context11.prev = 16;
1150
+ _context11.t0 = _context11["catch"](0);
1151
+ throw _context11.t0;
1152
+ case 19:
623
1153
  case "end":
624
- return _context6.stop();
1154
+ return _context11.stop();
625
1155
  }
626
- }, _callee6, this, [[0, 7]]);
1156
+ }, _callee11, this, [[0, 16]]);
627
1157
  }));
628
1158
  function restoreOrder() {
629
1159
  return _restoreOrder.apply(this, arguments);
630
1160
  }
631
1161
  return restoreOrder;
632
1162
  }()
1163
+ /**
1164
+ * 仅清空 tempOrder 购物车行(products / bookings / discount_list)。
1165
+ * 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
1166
+ */
1167
+ }, {
1168
+ key: "clearOrderCartLines",
1169
+ value: (function () {
1170
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1171
+ var tempOrder;
1172
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1173
+ while (1) switch (_context12.prev = _context12.next) {
1174
+ case 0:
1175
+ _context12.prev = 0;
1176
+ if (this.store.order) {
1177
+ _context12.next = 3;
1178
+ break;
1179
+ }
1180
+ throw new Error('order 模块未初始化');
1181
+ case 3:
1182
+ _context12.next = 5;
1183
+ return this.store.order.clearOrderCartLines();
1184
+ case 5:
1185
+ tempOrder = _context12.sent;
1186
+ if (this.currentSalesDetail) {
1187
+ this.currentSalesDetail = _objectSpread(_objectSpread({}, this.currentSalesDetail), {}, {
1188
+ products: [],
1189
+ bookings: [],
1190
+ rootBooking: null,
1191
+ bookingsByProductUid: {},
1192
+ discount_list: []
1193
+ });
1194
+ }
1195
+ _context12.next = 9;
1196
+ return this.effectsEmit('onTempOrderReplaced', {
1197
+ tempOrder: tempOrder
1198
+ });
1199
+ case 9:
1200
+ if (!(this.syncAppDataToTempOrder(tempOrder) && this.isTempOrderPersistEnabled())) {
1201
+ _context12.next = 13;
1202
+ break;
1203
+ }
1204
+ this.store.order.persistTempOrder();
1205
+ _context12.next = 13;
1206
+ return this.store.order.saveDraft();
1207
+ case 13:
1208
+ return _context12.abrupt("return", tempOrder);
1209
+ case 16:
1210
+ _context12.prev = 16;
1211
+ _context12.t0 = _context12["catch"](0);
1212
+ throw _context12.t0;
1213
+ case 19:
1214
+ case "end":
1215
+ return _context12.stop();
1216
+ }
1217
+ }, _callee12, this, [[0, 16]]);
1218
+ }));
1219
+ function clearOrderCartLines() {
1220
+ return _clearOrderCartLines.apply(this, arguments);
1221
+ }
1222
+ return clearOrderCartLines;
1223
+ }())
633
1224
  }, {
634
1225
  key: "getOrderProducts",
635
1226
  value: function getOrderProducts() {
@@ -640,38 +1231,433 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
640
1231
  }, {
641
1232
  key: "getSummary",
642
1233
  value: function () {
643
- var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1234
+ var _getSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
644
1235
  var summary;
645
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
646
- while (1) switch (_context7.prev = _context7.next) {
1236
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1237
+ while (1) switch (_context13.prev = _context13.next) {
647
1238
  case 0:
648
- _context7.prev = 0;
1239
+ _context13.prev = 0;
649
1240
  if (this.store.order) {
650
- _context7.next = 3;
1241
+ _context13.next = 3;
651
1242
  break;
652
1243
  }
653
1244
  throw new Error('order 模块未初始化');
654
1245
  case 3:
655
- _context7.next = 5;
1246
+ _context13.next = 5;
656
1247
  return this.store.order.getOrderSummary();
657
1248
  case 5:
658
- summary = _context7.sent;
659
- return _context7.abrupt("return", summary);
1249
+ summary = _context13.sent;
1250
+ return _context13.abrupt("return", summary);
660
1251
  case 9:
661
- _context7.prev = 9;
662
- _context7.t0 = _context7["catch"](0);
663
- throw _context7.t0;
1252
+ _context13.prev = 9;
1253
+ _context13.t0 = _context13["catch"](0);
1254
+ throw _context13.t0;
664
1255
  case 12:
665
1256
  case "end":
666
- return _context7.stop();
1257
+ return _context13.stop();
667
1258
  }
668
- }, _callee7, this, [[0, 9]]);
1259
+ }, _callee13, this, [[0, 9]]);
669
1260
  }));
670
1261
  function getSummary() {
671
1262
  return _getSummary.apply(this, arguments);
672
1263
  }
673
1264
  return getSummary;
674
1265
  }()
1266
+ }, {
1267
+ key: "getHistoricalProductDiscountList",
1268
+ value: function getHistoricalProductDiscountList(products) {
1269
+ var _this5 = this;
1270
+ var historyDiscountList = [];
1271
+ products.forEach(function (item) {
1272
+ if (!_this5.isPersistedOrderProduct(item)) return;
1273
+ (item.discount_list || []).forEach(function (discount) {
1274
+ var _discount$discount, _discount$metadata, _discount$discount2, _discount$discount3, _discount$discount4;
1275
+ var discountId = ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
1276
+ if (!discountId || !['good_pass', 'discount_card'].includes(discount.type)) return;
1277
+ var quantity = item.quantity || item.num || item.product_quantity || 1;
1278
+ var savedAmount = new Decimal(discount.amount || 0).times(quantity).plus((discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
1279
+ var index = historyDiscountList.findIndex(function (n) {
1280
+ return n.id === discountId;
1281
+ });
1282
+ if (index !== -1) {
1283
+ historyDiscountList[index] = _objectSpread(_objectSpread({}, historyDiscountList[index]), {}, {
1284
+ amount: new Decimal(historyDiscountList[index].amount || 0).plus(discount.amount || 0).toNumber(),
1285
+ savedAmount: savedAmount.plus(historyDiscountList[index].savedAmount || 0).toNumber()
1286
+ });
1287
+ return;
1288
+ }
1289
+ historyDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
1290
+ id: discountId,
1291
+ tag: discount.tag || discount.type,
1292
+ name: discount.name || ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 || (_discount$discount2 = _discount$discount2.title) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.auto),
1293
+ format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
1294
+ isEditMode: true,
1295
+ limited_relation_product_data: {},
1296
+ savedAmount: savedAmount.toNumber(),
1297
+ isAvailable: true,
1298
+ isDisabled: true,
1299
+ isSelected: true,
1300
+ product_id: ((_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.product_id) || discount.product_id
1301
+ }));
1302
+ });
1303
+ });
1304
+ return historyDiscountList;
1305
+ }
1306
+ }, {
1307
+ key: "isPersistedOrderProduct",
1308
+ value: function isPersistedOrderProduct(product) {
1309
+ var _product$order_detail, _product$booking_id;
1310
+ var orderDetailId = (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : product.orderDetailId;
1311
+ if (orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '') {
1312
+ return true;
1313
+ }
1314
+ var bookingId = (_product$booking_id = product.booking_id) !== null && _product$booking_id !== void 0 ? _product$booking_id : product.bookingId;
1315
+ return bookingId !== undefined && bookingId !== null && bookingId !== '';
1316
+ }
1317
+ }, {
1318
+ key: "mergeHistoricalDiscountList",
1319
+ value: function mergeHistoricalDiscountList(discountList, products) {
1320
+ var historyDiscountList = this.getHistoricalProductDiscountList(products);
1321
+ var historyIds = new Set(historyDiscountList.map(function (discount) {
1322
+ return discount.id;
1323
+ }));
1324
+ return [].concat(_toConsumableArray(historyDiscountList), _toConsumableArray((discountList || []).filter(function (discount) {
1325
+ return !historyIds.has(discount.id);
1326
+ })));
1327
+ }
1328
+ }, {
1329
+ key: "shouldSkipAutoApplyFetchedDiscountsInEditMode",
1330
+ value: function shouldSkipAutoApplyFetchedDiscountsInEditMode(params) {
1331
+ var _this6 = this;
1332
+ if (params.discountAction !== 'edit') return false;
1333
+ if (!params.products.length) return false;
1334
+ var hasDraftProduct = params.products.some(function (product) {
1335
+ return !_this6.isPersistedOrderProduct(product);
1336
+ });
1337
+ if (hasDraftProduct) return false;
1338
+ var hasSelectedDiscount = params.currentDiscountList.some(function (discount) {
1339
+ return discount.isSelected || discount.isEditMode || discount.isManualSelect;
1340
+ });
1341
+ if (hasSelectedDiscount) return false;
1342
+ return !params.nextDiscountList.some(function (discount) {
1343
+ return discount.isSelected || discount.isEditMode || discount.isManualSelect;
1344
+ });
1345
+ }
1346
+ }, {
1347
+ key: "mergeCurrentDiscountSelectionState",
1348
+ value: function mergeCurrentDiscountSelectionState(discountList, currentDiscountList) {
1349
+ if (!currentDiscountList.length) return discountList;
1350
+ var currentDiscountMap = new Map(currentDiscountList.map(function (discount) {
1351
+ return [discount.id, discount];
1352
+ }));
1353
+ return discountList.map(function (discount) {
1354
+ var currentDiscount = currentDiscountMap.get(discount.id);
1355
+ if (!currentDiscount) return discount;
1356
+ if (currentDiscount.isManualSelect) {
1357
+ return _objectSpread(_objectSpread({}, discount), {}, {
1358
+ isSelected: false,
1359
+ isManualSelect: true
1360
+ });
1361
+ }
1362
+ if (currentDiscount.isSelected) {
1363
+ return _objectSpread(_objectSpread({}, discount), {}, {
1364
+ isSelected: true,
1365
+ isManualSelect: false
1366
+ });
1367
+ }
1368
+ return discount;
1369
+ });
1370
+ }
1371
+ }, {
1372
+ key: "loadDiscountConfig",
1373
+ value: function () {
1374
+ var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
1375
+ var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getOr, _discountModule$getDi2;
1376
+ var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
1377
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1378
+ while (1) switch (_context14.prev = _context14.next) {
1379
+ case 0:
1380
+ if (this.store.order) {
1381
+ _context14.next = 2;
1382
+ break;
1383
+ }
1384
+ throw new Error('order 模块未初始化');
1385
+ case 2:
1386
+ tempOrder = this.store.order.ensureTempOrder();
1387
+ orderStore = this.store.order.store || {};
1388
+ discountModule = orderStore.discount;
1389
+ rulesModule = orderStore.rules;
1390
+ orderId = tempOrder.order_id || ((_this$getOrderIdentit = this.getOrderIdentity) === null || _this$getOrderIdentit === void 0 || (_this$getOrderIdentit = _this$getOrderIdentit.call(this)) === null || _this$getOrderIdentit === void 0 ? void 0 : _this$getOrderIdentit.orderId);
1391
+ customerId = Number((params === null || params === void 0 ? void 0 : params.customerId) || tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.customerSnapshot) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.customer_id) || 0);
1392
+ currentDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
1393
+ originalDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
1394
+ hasManualDiscountSelection = this.hasManualDiscountSelection || currentDiscountList.some(function (discount) {
1395
+ return discount.isManualSelect;
1396
+ });
1397
+ discountAction = (params === null || params === void 0 ? void 0 : params.action) || (orderId ? 'edit' : 'create');
1398
+ discountConfigCacheKey = [customerId, discountAction, Number(orderId) || 0].join(':');
1399
+ preparedDiscountList = [];
1400
+ if (!(customerId && customerId !== 1)) {
1401
+ _context14.next = 25;
1402
+ break;
1403
+ }
1404
+ if (!(this.discountConfigCacheKey === discountConfigCacheKey)) {
1405
+ _context14.next = 19;
1406
+ break;
1407
+ }
1408
+ preparedDiscountList = originalDiscountList;
1409
+ _context14.next = 25;
1410
+ break;
1411
+ case 19:
1412
+ _context14.next = 21;
1413
+ return this.store.order.loadDiscountConfig({
1414
+ customerId: customerId,
1415
+ action: discountAction,
1416
+ orderId: Number(orderId) || undefined,
1417
+ apply: false
1418
+ });
1419
+ case 21:
1420
+ preparedDiscountList = _context14.sent;
1421
+ this.discountConfigCacheKey = discountConfigCacheKey;
1422
+ _context14.next = 25;
1423
+ return discountModule === null || discountModule === void 0 || (_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, preparedDiscountList);
1424
+ case 25:
1425
+ if (!(hasManualDiscountSelection && currentDiscountList.length)) {
1426
+ _context14.next = 27;
1427
+ break;
1428
+ }
1429
+ return _context14.abrupt("return", {
1430
+ productList: tempOrder.products || [],
1431
+ discountList: currentDiscountList
1432
+ });
1433
+ case 27:
1434
+ nextDiscountList = this.mergeHistoricalDiscountList(preparedDiscountList || (discountModule === null || discountModule === void 0 || (_discountModule$getDi2 = discountModule.getDiscountList) === null || _discountModule$getDi2 === void 0 ? void 0 : _discountModule$getDi2.call(discountModule)) || [], tempOrder.products || []);
1435
+ nextDiscountList = this.mergeCurrentDiscountSelectionState(nextDiscountList, currentDiscountList);
1436
+ _context14.next = 31;
1437
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1438
+ case 31:
1439
+ shouldSkipAutoApplyFetchedDiscounts = this.shouldSkipAutoApplyFetchedDiscountsInEditMode({
1440
+ discountAction: discountAction,
1441
+ products: tempOrder.products || [],
1442
+ currentDiscountList: currentDiscountList,
1443
+ nextDiscountList: nextDiscountList
1444
+ });
1445
+ if (!shouldSkipAutoApplyFetchedDiscounts) {
1446
+ _context14.next = 40;
1447
+ break;
1448
+ }
1449
+ _context14.next = 35;
1450
+ return this.store.order.recalculateSummary({
1451
+ createIfMissing: true
1452
+ });
1453
+ case 35:
1454
+ _summary = _context14.sent;
1455
+ this.store.order.persistTempOrder();
1456
+ _context14.next = 39;
1457
+ return this.effectsEmit('onDiscountApplied', {
1458
+ productList: tempOrder.products || [],
1459
+ discountList: nextDiscountList,
1460
+ selectedDiscountList: tempOrder.discount_list || [],
1461
+ tempOrder: tempOrder
1462
+ });
1463
+ case 39:
1464
+ return _context14.abrupt("return", {
1465
+ productList: tempOrder.products || [],
1466
+ discountList: nextDiscountList
1467
+ });
1468
+ case 40:
1469
+ if (!rulesModule) {
1470
+ _context14.next = 76;
1471
+ break;
1472
+ }
1473
+ holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1474
+ form_record_id: tempOrder.holder.form_record_id
1475
+ }] : [];
1476
+ result = rulesModule.calcDiscount({
1477
+ productList: tempOrder.products,
1478
+ discountList: nextDiscountList,
1479
+ holders: holders,
1480
+ isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form',
1481
+ orderTotalAmount: Number(((_orderStore$summary = orderStore.summary) === null || _orderStore$summary === void 0 ? void 0 : _orderStore$summary.total_amount) || 0)
1482
+ }) || {
1483
+ productList: tempOrder.products,
1484
+ discountList: nextDiscountList
1485
+ };
1486
+ if (result.productList) {
1487
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1488
+ }
1489
+ _iterator = _createForOfIteratorHelper(tempOrder.products || []);
1490
+ _context14.prev = 45;
1491
+ _iterator.s();
1492
+ case 47:
1493
+ if ((_step = _iterator.n()).done) {
1494
+ _context14.next = 62;
1495
+ break;
1496
+ }
1497
+ product = _step.value;
1498
+ productUid = (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number;
1499
+ runtimeOrigin = productUid ? (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.productsByUid) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3[productUid]) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.origin : undefined;
1500
+ if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1501
+ _context14.next = 53;
1502
+ break;
1503
+ }
1504
+ return _context14.abrupt("continue", 60);
1505
+ case 53:
1506
+ totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
1507
+ return sum + Number(pd.amount || 0);
1508
+ }, 0);
1509
+ optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
1510
+ sourcePrice = (_product$metadata$sou = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
1511
+ newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1512
+ newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1513
+ if (product.metadata) {
1514
+ product.metadata.main_product_selling_price = newMainSellingPrice;
1515
+ product.metadata.price_schema_version = 2;
1516
+ }
1517
+ product.selling_price = composeLinePrice({
1518
+ mainPrice: newMainSellingPrice,
1519
+ bundle: product.product_bundle
1520
+ });
1521
+ case 60:
1522
+ _context14.next = 47;
1523
+ break;
1524
+ case 62:
1525
+ _context14.next = 67;
1526
+ break;
1527
+ case 64:
1528
+ _context14.prev = 64;
1529
+ _context14.t0 = _context14["catch"](45);
1530
+ _iterator.e(_context14.t0);
1531
+ case 67:
1532
+ _context14.prev = 67;
1533
+ _iterator.f();
1534
+ return _context14.finish(67);
1535
+ case 70:
1536
+ if (!result.discountList) {
1537
+ _context14.next = 76;
1538
+ break;
1539
+ }
1540
+ nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1541
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1542
+ _context14.next = 75;
1543
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1544
+ case 75:
1545
+ tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1546
+ return discount.isSelected;
1547
+ });
1548
+ case 76:
1549
+ _context14.next = 78;
1550
+ return this.store.order.recalculateSummary({
1551
+ createIfMissing: true
1552
+ });
1553
+ case 78:
1554
+ summary = _context14.sent;
1555
+ this.store.order.persistTempOrder();
1556
+ _context14.next = 82;
1557
+ return this.effectsEmit('onDiscountApplied', {
1558
+ productList: tempOrder.products || [],
1559
+ discountList: nextDiscountList,
1560
+ selectedDiscountList: tempOrder.discount_list || [],
1561
+ tempOrder: tempOrder
1562
+ });
1563
+ case 82:
1564
+ return _context14.abrupt("return", {
1565
+ productList: tempOrder.products || [],
1566
+ discountList: nextDiscountList
1567
+ });
1568
+ case 83:
1569
+ case "end":
1570
+ return _context14.stop();
1571
+ }
1572
+ }, _callee14, this, [[45, 64, 67, 70]]);
1573
+ }));
1574
+ function loadDiscountConfig(_x9) {
1575
+ return _loadDiscountConfig.apply(this, arguments);
1576
+ }
1577
+ return loadDiscountConfig;
1578
+ }()
1579
+ }, {
1580
+ key: "bestDiscount",
1581
+ value: function () {
1582
+ var _bestDiscount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(cb) {
1583
+ var _discountModule$getOr2, _discountModule$getDi3;
1584
+ var tempOrder, orderStore, discountModule, rulesModule, originalDiscountList, currentDiscountList, nextDiscountList, result, _tempOrder$holder3, _tempOrder$holder4, _orderStore$summary2, holders;
1585
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1586
+ while (1) switch (_context15.prev = _context15.next) {
1587
+ case 0:
1588
+ if (this.store.order) {
1589
+ _context15.next = 2;
1590
+ break;
1591
+ }
1592
+ throw new Error('order 模块未初始化');
1593
+ case 2:
1594
+ tempOrder = this.store.order.ensureTempOrder();
1595
+ orderStore = this.store.order.store || {};
1596
+ discountModule = orderStore.discount;
1597
+ rulesModule = orderStore.rules;
1598
+ originalDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getOr2 = discountModule.getOriginalDiscountList) === null || _discountModule$getOr2 === void 0 ? void 0 : _discountModule$getOr2.call(discountModule)) || this.getDiscountList();
1599
+ currentDiscountList = (discountModule === null || discountModule === void 0 || (_discountModule$getDi3 = discountModule.getDiscountList) === null || _discountModule$getDi3 === void 0 ? void 0 : _discountModule$getDi3.call(discountModule)) || [];
1600
+ nextDiscountList = this.mergeHistoricalDiscountList(originalDiscountList || [], tempOrder.products || []);
1601
+ result = {
1602
+ productList: tempOrder.products || [],
1603
+ discountList: nextDiscountList
1604
+ };
1605
+ _context15.next = 12;
1606
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1607
+ case 12:
1608
+ if (!rulesModule) {
1609
+ _context15.next = 23;
1610
+ break;
1611
+ }
1612
+ holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
1613
+ form_record_id: tempOrder.holder.form_record_id
1614
+ }] : [];
1615
+ result = rulesModule.calcDiscount({
1616
+ productList: tempOrder.products,
1617
+ discountList: nextDiscountList,
1618
+ holders: holders,
1619
+ isFormSubject: !!((_tempOrder$holder4 = tempOrder.holder) !== null && _tempOrder$holder4 !== void 0 && _tempOrder$holder4.type) && tempOrder.holder.type === 'form',
1620
+ orderTotalAmount: Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0)
1621
+ }) || result;
1622
+ if (result.productList) {
1623
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1624
+ }
1625
+ if (!result.discountList) {
1626
+ _context15.next = 23;
1627
+ break;
1628
+ }
1629
+ nextDiscountList = this.mergeHistoricalDiscountList(result.discountList, tempOrder.products || []);
1630
+ OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
1631
+ _context15.next = 21;
1632
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
1633
+ case 21:
1634
+ tempOrder.discount_list = nextDiscountList.filter(function (discount) {
1635
+ return discount.isSelected;
1636
+ });
1637
+ result = {
1638
+ productList: tempOrder.products,
1639
+ discountList: nextDiscountList
1640
+ };
1641
+ case 23:
1642
+ _context15.next = 25;
1643
+ return this.store.order.recalculateSummary({
1644
+ createIfMissing: true
1645
+ });
1646
+ case 25:
1647
+ this.store.order.persistTempOrder();
1648
+ cb === null || cb === void 0 || cb(result);
1649
+ return _context15.abrupt("return", result);
1650
+ case 28:
1651
+ case "end":
1652
+ return _context15.stop();
1653
+ }
1654
+ }, _callee15, this);
1655
+ }));
1656
+ function bestDiscount(_x10) {
1657
+ return _bestDiscount.apply(this, arguments);
1658
+ }
1659
+ return bestDiscount;
1660
+ }()
675
1661
  }, {
676
1662
  key: "getDiscountList",
677
1663
  value: function getDiscountList() {
@@ -681,49 +1667,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
681
1667
  }, {
682
1668
  key: "scanPromotionCode",
683
1669
  value: function () {
684
- var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(code, customerId) {
1670
+ var _scanPromotionCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(code, customerId) {
685
1671
  var raw;
686
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
687
- while (1) switch (_context8.prev = _context8.next) {
1672
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1673
+ while (1) switch (_context16.prev = _context16.next) {
688
1674
  case 0:
689
- _context8.prev = 0;
1675
+ _context16.prev = 0;
690
1676
  if (this.store.order) {
691
- _context8.next = 3;
1677
+ _context16.next = 3;
692
1678
  break;
693
1679
  }
694
1680
  throw new Error('order 模块未初始化');
695
1681
  case 3:
696
- _context8.next = 5;
1682
+ _context16.next = 5;
697
1683
  return this.store.order.scanCode(code, customerId);
698
1684
  case 5:
699
- raw = _context8.sent;
1685
+ raw = _context16.sent;
700
1686
  if (!raw.isAvailable) {
701
- _context8.next = 10;
1687
+ _context16.next = 10;
702
1688
  break;
703
1689
  }
704
- _context8.next = 9;
1690
+ _context16.next = 9;
705
1691
  return this.store.order.recalculateSummary({
706
1692
  createIfMissing: true
707
1693
  });
708
1694
  case 9:
709
1695
  this.store.order.persistTempOrder();
710
1696
  case 10:
711
- return _context8.abrupt("return", {
1697
+ return _context16.abrupt("return", {
712
1698
  isAvailable: raw.isAvailable,
713
1699
  type: raw.type,
714
1700
  unavailableReason: raw.unavailableReason
715
1701
  });
716
1702
  case 13:
717
- _context8.prev = 13;
718
- _context8.t0 = _context8["catch"](0);
719
- throw _context8.t0;
1703
+ _context16.prev = 13;
1704
+ _context16.t0 = _context16["catch"](0);
1705
+ throw _context16.t0;
720
1706
  case 16:
721
1707
  case "end":
722
- return _context8.stop();
1708
+ return _context16.stop();
723
1709
  }
724
- }, _callee8, this, [[0, 13]]);
1710
+ }, _callee16, this, [[0, 13]]);
725
1711
  }));
726
- function scanPromotionCode(_x3, _x4) {
1712
+ function scanPromotionCode(_x11, _x12) {
727
1713
  return _scanPromotionCode.apply(this, arguments);
728
1714
  }
729
1715
  return scanPromotionCode;
@@ -731,14 +1717,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
731
1717
  }, {
732
1718
  key: "setDiscountSelected",
733
1719
  value: function () {
734
- var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
735
- var _tempOrder$holder, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder2, result, beforeSelectedIds, _iterator, _step, d, selectedResourceIds, _iterator2, _step2, _product$metadata, _tempOrder$_extend, _product$metadata2, _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
736
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
737
- while (1) switch (_context9.prev = _context9.next) {
1720
+ var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
1721
+ var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
1722
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1723
+ while (1) switch (_context17.prev = _context17.next) {
738
1724
  case 0:
739
- _context9.prev = 0;
1725
+ _context17.prev = 0;
740
1726
  if (this.store.order) {
741
- _context9.next = 3;
1727
+ _context17.next = 3;
742
1728
  break;
743
1729
  }
744
1730
  throw new Error('order 模块未初始化');
@@ -750,23 +1736,24 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
750
1736
  isManualSelect: !params.isSelected
751
1737
  }) : d;
752
1738
  });
1739
+ this.hasManualDiscountSelection = true;
753
1740
  tempOrder = this.store.order.ensureTempOrder();
754
1741
  orderStore = this.store.order.store || {};
755
1742
  discountModule = orderStore.discount;
756
1743
  rulesModule = orderStore.rules;
757
- holders = (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
1744
+ holders = (_tempOrder$holder5 = tempOrder.holder) !== null && _tempOrder$holder5 !== void 0 && _tempOrder$holder5.form_record_id ? [{
758
1745
  form_record_id: tempOrder.holder.form_record_id
759
1746
  }] : [];
760
1747
  nextDiscountList = updated;
761
- _context9.next = 13;
1748
+ _context17.next = 14;
762
1749
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(updated);
763
- case 13:
1750
+ case 14:
764
1751
  if (rulesModule) {
765
1752
  result = rulesModule.calcDiscount({
766
1753
  productList: tempOrder.products,
767
1754
  discountList: updated,
768
1755
  holders: holders,
769
- isFormSubject: !!((_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form'
1756
+ isFormSubject: !!((_tempOrder$holder6 = tempOrder.holder) !== null && _tempOrder$holder6 !== void 0 && _tempOrder$holder6.type) && tempOrder.holder.type === 'form'
770
1757
  }, {
771
1758
  discountId: params.discountId,
772
1759
  isSelected: params.isSelected
@@ -775,7 +1762,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
775
1762
  discountList: updated
776
1763
  };
777
1764
  if (result !== null && result !== void 0 && result.productList) {
778
- tempOrder.products = result.productList;
1765
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
779
1766
  }
780
1767
  if (result !== null && result !== void 0 && result.discountList) {
781
1768
  nextDiscountList = result.discountList;
@@ -785,18 +1772,19 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
785
1772
  }).map(function (d) {
786
1773
  return d.id;
787
1774
  }));
788
- _iterator = _createForOfIteratorHelper(nextDiscountList);
1775
+ _iterator2 = _createForOfIteratorHelper(nextDiscountList);
789
1776
  try {
790
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
791
- d = _step.value;
1777
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
1778
+ d = _step2.value;
792
1779
  if (d.isSelected && !beforeSelectedIds.has(d.id)) {
793
1780
  d.isSelected = false;
1781
+ d.isManualSelect = true;
794
1782
  }
795
1783
  }
796
1784
  } catch (err) {
797
- _iterator.e(err);
1785
+ _iterator2.e(err);
798
1786
  } finally {
799
- _iterator.f();
1787
+ _iterator2.f();
800
1788
  }
801
1789
  }
802
1790
  }
@@ -806,23 +1794,23 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
806
1794
  }).map(function (d) {
807
1795
  return d.id;
808
1796
  }));
809
- _iterator2 = _createForOfIteratorHelper(tempOrder.products);
810
- _context9.prev = 16;
811
- _iterator2.s();
812
- case 18:
813
- if ((_step2 = _iterator2.n()).done) {
814
- _context9.next = 34;
1797
+ _iterator3 = _createForOfIteratorHelper(tempOrder.products);
1798
+ _context17.prev = 17;
1799
+ _iterator3.s();
1800
+ case 19:
1801
+ if ((_step3 = _iterator3.n()).done) {
1802
+ _context17.next = 35;
815
1803
  break;
816
1804
  }
817
- product = _step2.value;
818
- productUid = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number;
819
- runtimeOrigin = productUid ? (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.productsByUid) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend[productUid]) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.origin : undefined;
820
- if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (_product$metadata2 = product.metadata) !== null && _product$metadata2 !== void 0 && _product$metadata2.is_manual_discount)) {
821
- _context9.next = 24;
1805
+ product = _step3.value;
1806
+ productUid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
1807
+ runtimeOrigin = productUid ? (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4.productsByUid) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4[productUid]) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.origin : undefined;
1808
+ if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
1809
+ _context17.next = 25;
822
1810
  break;
823
1811
  }
824
- return _context9.abrupt("continue", 32);
825
- case 24:
1812
+ return _context17.abrupt("continue", 33);
1813
+ case 25:
826
1814
  product.discount_list = (product.discount_list || []).filter(function (pd) {
827
1815
  var _pd$discount$resource, _pd$discount;
828
1816
  var rid = (_pd$discount$resource = (_pd$discount = pd.discount) === null || _pd$discount === void 0 ? void 0 : _pd$discount.resource_id) !== null && _pd$discount$resource !== void 0 ? _pd$discount$resource : pd.id;
@@ -834,8 +1822,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
834
1822
  totalPerUnitDiscount = (product.discount_list || []).reduce(function (sum, pd) {
835
1823
  return sum + (pd.amount || 0);
836
1824
  }, 0); // TODO 这块逻辑需要拿掉
837
- optionSum = sumOptionUnitPrice(product.product_option_item);
838
- sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
1825
+ optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
1826
+ sourcePrice = (_product$metadata$sou2 = (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.source_product_price) !== null && _product$metadata$sou2 !== void 0 ? _product$metadata$sou2 : ((_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
839
1827
  newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
840
1828
  newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
841
1829
  if (product.metadata) {
@@ -846,66 +1834,134 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
846
1834
  mainPrice: newMainSellingPrice,
847
1835
  bundle: product.product_bundle
848
1836
  });
849
- case 32:
850
- _context9.next = 18;
1837
+ case 33:
1838
+ _context17.next = 19;
851
1839
  break;
852
- case 34:
853
- _context9.next = 39;
1840
+ case 35:
1841
+ _context17.next = 40;
854
1842
  break;
855
- case 36:
856
- _context9.prev = 36;
857
- _context9.t0 = _context9["catch"](16);
858
- _iterator2.e(_context9.t0);
859
- case 39:
860
- _context9.prev = 39;
861
- _iterator2.f();
862
- return _context9.finish(39);
863
- case 42:
1843
+ case 37:
1844
+ _context17.prev = 37;
1845
+ _context17.t0 = _context17["catch"](17);
1846
+ _iterator3.e(_context17.t0);
1847
+ case 40:
1848
+ _context17.prev = 40;
1849
+ _iterator3.f();
1850
+ return _context17.finish(40);
1851
+ case 43:
864
1852
  OrderModule.populateSavedAmounts(tempOrder.products, nextDiscountList);
865
- _context9.next = 45;
1853
+ _context17.next = 46;
866
1854
  return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(nextDiscountList);
867
- case 45:
1855
+ case 46:
868
1856
  tempOrder.discount_list = (nextDiscountList || []).filter(function (d) {
869
1857
  return d.isSelected;
870
1858
  });
871
- _context9.next = 48;
1859
+ _context17.next = 49;
872
1860
  return this.store.order.recalculateSummary({
873
1861
  createIfMissing: true
874
1862
  });
875
- case 48:
1863
+ case 49:
876
1864
  this.store.order.persistTempOrder();
877
- _context9.next = 54;
1865
+ this.effectsEmit('onDiscountApplied', {
1866
+ productList: tempOrder.products,
1867
+ discountList: nextDiscountList,
1868
+ selectedDiscountList: tempOrder.discount_list,
1869
+ tempOrder: tempOrder
1870
+ });
1871
+ _context17.next = 56;
878
1872
  break;
879
- case 51:
880
- _context9.prev = 51;
881
- _context9.t1 = _context9["catch"](0);
882
- throw _context9.t1;
883
- case 54:
1873
+ case 53:
1874
+ _context17.prev = 53;
1875
+ _context17.t1 = _context17["catch"](0);
1876
+ throw _context17.t1;
1877
+ case 56:
884
1878
  case "end":
885
- return _context9.stop();
1879
+ return _context17.stop();
886
1880
  }
887
- }, _callee9, this, [[0, 51], [16, 36, 39, 42]]);
1881
+ }, _callee17, this, [[0, 53], [17, 37, 40, 43]]);
888
1882
  }));
889
- function setDiscountSelected(_x5) {
1883
+ function setDiscountSelected(_x13) {
890
1884
  return _setDiscountSelected.apply(this, arguments);
891
1885
  }
892
1886
  return setDiscountSelected;
893
1887
  }()
1888
+ }, {
1889
+ key: "applyDiscountCalculationResult",
1890
+ value: function () {
1891
+ var _applyDiscountCalculationResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(result) {
1892
+ var tempOrder, orderStore, discountModule;
1893
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1894
+ while (1) switch (_context18.prev = _context18.next) {
1895
+ case 0:
1896
+ _context18.prev = 0;
1897
+ if (this.store.order) {
1898
+ _context18.next = 3;
1899
+ break;
1900
+ }
1901
+ throw new Error('order 模块未初始化');
1902
+ case 3:
1903
+ if (result) {
1904
+ _context18.next = 5;
1905
+ break;
1906
+ }
1907
+ return _context18.abrupt("return");
1908
+ case 5:
1909
+ tempOrder = this.store.order.ensureTempOrder();
1910
+ orderStore = this.store.order.store || {};
1911
+ discountModule = orderStore.discount;
1912
+ if (result.productList) {
1913
+ tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
1914
+ }
1915
+ if (!result.discountList) {
1916
+ _context18.next = 14;
1917
+ break;
1918
+ }
1919
+ OrderModule.populateSavedAmounts(tempOrder.products, result.discountList);
1920
+ _context18.next = 13;
1921
+ return discountModule === null || discountModule === void 0 ? void 0 : discountModule.setDiscountList(result.discountList);
1922
+ case 13:
1923
+ tempOrder.discount_list = result.discountList.filter(function (discount) {
1924
+ return discount.isSelected;
1925
+ });
1926
+ case 14:
1927
+ _context18.next = 16;
1928
+ return this.store.order.recalculateSummary({
1929
+ createIfMissing: true
1930
+ });
1931
+ case 16:
1932
+ this.store.order.persistTempOrder();
1933
+ _context18.next = 22;
1934
+ break;
1935
+ case 19:
1936
+ _context18.prev = 19;
1937
+ _context18.t0 = _context18["catch"](0);
1938
+ throw _context18.t0;
1939
+ case 22:
1940
+ case "end":
1941
+ return _context18.stop();
1942
+ }
1943
+ }, _callee18, this, [[0, 19]]);
1944
+ }));
1945
+ function applyDiscountCalculationResult(_x14) {
1946
+ return _applyDiscountCalculationResult.apply(this, arguments);
1947
+ }
1948
+ return applyDiscountCalculationResult;
1949
+ }()
894
1950
  }, {
895
1951
  key: "submitScanOrder",
896
1952
  value: function () {
897
- var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
898
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
899
- while (1) switch (_context10.prev = _context10.next) {
1953
+ var _submitScanOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(params) {
1954
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1955
+ while (1) switch (_context19.prev = _context19.next) {
900
1956
  case 0:
901
- return _context10.abrupt("return", this.submitSalesOrder(params));
1957
+ return _context19.abrupt("return", this.submitSalesOrder(params));
902
1958
  case 1:
903
1959
  case "end":
904
- return _context10.stop();
1960
+ return _context19.stop();
905
1961
  }
906
- }, _callee10, this);
1962
+ }, _callee19, this);
907
1963
  }));
908
- function submitScanOrder(_x6) {
1964
+ function submitScanOrder(_x15) {
909
1965
  return _submitScanOrder.apply(this, arguments);
910
1966
  }
911
1967
  return submitScanOrder;
@@ -919,67 +1975,246 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
919
1975
  }, {
920
1976
  key: "submitSalesOrder",
921
1977
  value: (function () {
922
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
923
- var _this$otherParams2, _this$otherParams3, _this$otherParams4, _this$otherParams5;
924
- var submitParams;
925
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
926
- while (1) switch (_context11.prev = _context11.next) {
1978
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1979
+ var _this$otherParams6, _this$otherParams7, _this$otherParams8, _this$otherParams9;
1980
+ var inferredPaymentStatus, submitParams;
1981
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1982
+ while (1) switch (_context20.prev = _context20.next) {
927
1983
  case 0:
928
1984
  if (this.store.order) {
929
- _context11.next = 2;
1985
+ _context20.next = 2;
930
1986
  break;
931
1987
  }
932
1988
  throw new Error('BaseSales 解决方案需要 order 模块支持');
933
1989
  case 2:
934
- this.store.order.persistTempOrder();
1990
+ // this.store.order.persistTempOrder();
1991
+ inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
935
1992
  submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
936
1993
  cacheId: this.cacheId,
937
- platform: (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform,
938
- businessCode: (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.businessCode,
939
- channel: (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.channel,
940
- type: (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.type
1994
+ platform: (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform,
1995
+ businessCode: ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code),
1996
+ channel: this.getSubmitOrderSalesChannel(),
1997
+ type: (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
1998
+ request_unique_idempotency_token: this.store.order.generateIdempotencyToken()
941
1999
  }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
942
2000
  payments: params.payments
943
- } : {}), (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined ? {
944
- paymentStatus: params.paymentStatus
2001
+ } : {}), inferredPaymentStatus !== undefined ? {
2002
+ paymentStatus: inferredPaymentStatus
945
2003
  } : {}), (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined ? {
946
2004
  smallTicketDataFlag: params.smallTicketDataFlag
947
2005
  } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
948
2006
  enhancePayload: params.enhancePayload
949
2007
  } : {});
950
- return _context11.abrupt("return", this.store.order.submitTempOrder(submitParams));
2008
+ return _context20.abrupt("return", this.store.order.submitTempOrder(submitParams));
951
2009
  case 5:
952
2010
  case "end":
953
- return _context11.stop();
2011
+ return _context20.stop();
954
2012
  }
955
- }, _callee11, this);
2013
+ }, _callee20, this);
956
2014
  }));
957
- function submitSalesOrder(_x7) {
2015
+ function submitSalesOrder(_x16) {
958
2016
  return _submitSalesOrder.apply(this, arguments);
959
2017
  }
960
2018
  return submitSalesOrder;
961
2019
  }())
2020
+ }, {
2021
+ key: "submitTempOrderAsync",
2022
+ value: function () {
2023
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2024
+ var _this$otherParams10, _this$otherParams11, _this$otherParams12, _this$otherParams13;
2025
+ var inferredPaymentStatus, submitParams;
2026
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2027
+ while (1) switch (_context21.prev = _context21.next) {
2028
+ case 0:
2029
+ if (this.store.order) {
2030
+ _context21.next = 2;
2031
+ break;
2032
+ }
2033
+ throw new Error('BaseSales 解决方案需要 order 模块支持');
2034
+ case 2:
2035
+ inferredPaymentStatus = this.getSubmitPaymentStatus(params === null || params === void 0 ? void 0 : params.paymentStatus);
2036
+ submitParams = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
2037
+ cacheId: this.cacheId,
2038
+ platform: (_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform,
2039
+ businessCode: ((_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code),
2040
+ channel: this.getSubmitOrderSalesChannel(),
2041
+ type: (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.type
2042
+ }, (params === null || params === void 0 ? void 0 : params.payments) !== undefined ? {
2043
+ payments: params.payments
2044
+ } : {}), inferredPaymentStatus !== undefined ? {
2045
+ paymentStatus: inferredPaymentStatus
2046
+ } : {}), (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined ? {
2047
+ smallTicketDataFlag: params.smallTicketDataFlag
2048
+ } : {}), (params === null || params === void 0 ? void 0 : params.enhancePayload) !== undefined ? {
2049
+ enhancePayload: params.enhancePayload
2050
+ } : {});
2051
+ return _context21.abrupt("return", this.store.order.submitTempOrderAsync(submitParams));
2052
+ case 5:
2053
+ case "end":
2054
+ return _context21.stop();
2055
+ }
2056
+ }, _callee21, this);
2057
+ }));
2058
+ function submitTempOrderAsync(_x17) {
2059
+ return _submitTempOrderAsync.apply(this, arguments);
2060
+ }
2061
+ return submitTempOrderAsync;
2062
+ }()
2063
+ }, {
2064
+ key: "printLocalOrderReceipt",
2065
+ value: function () {
2066
+ var _printLocalOrderReceipt = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(lookup) {
2067
+ var _this$otherParams14, _this$otherParams15, _this$otherParams16, _this$otherParams17;
2068
+ var hasLookup, lookupPayload, context, payload, response, _this$store$order$app, _this$store$order3, _data;
2069
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2070
+ while (1) switch (_context22.prev = _context22.next) {
2071
+ case 0:
2072
+ if (this.store.order) {
2073
+ _context22.next = 2;
2074
+ break;
2075
+ }
2076
+ throw new Error('BaseSales 解决方案需要 order 模块支持');
2077
+ case 2:
2078
+ hasLookup = lookup !== undefined && lookup !== null && lookup !== '';
2079
+ lookupPayload = typeof lookup === 'number' ? {
2080
+ order_id: lookup
2081
+ } : {
2082
+ external_sale_number: lookup
2083
+ };
2084
+ context = {
2085
+ platform: (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.platform,
2086
+ businessCode: ((_this$otherParams15 = this.otherParams) === null || _this$otherParams15 === void 0 ? void 0 : _this$otherParams15.businessCode) || ((_this$otherParams16 = this.otherParams) === null || _this$otherParams16 === void 0 ? void 0 : _this$otherParams16.business_code),
2087
+ channel: this.getSubmitOrderSalesChannel(),
2088
+ type: (_this$otherParams17 = this.otherParams) === null || _this$otherParams17 === void 0 ? void 0 : _this$otherParams17.type
2089
+ };
2090
+ payload = hasLookup ? _objectSpread(_objectSpread({}, lookupPayload), {}, {
2091
+ lookup_order_from_db: 1,
2092
+ small_ticket_data_flag: 1,
2093
+ platform: context.platform,
2094
+ business_code: context.businessCode,
2095
+ order_sales_channel: context.channel,
2096
+ type: context.type
2097
+ }) : this.store.order.buildCurrentSubmitPayloadForLocalPrint({
2098
+ cacheId: this.cacheId,
2099
+ platform: context.platform,
2100
+ businessCode: context.businessCode,
2101
+ channel: context.channel,
2102
+ type: context.type
2103
+ });
2104
+ _context22.next = 8;
2105
+ return this.request.post('/local/print-order', payload, {
2106
+ osServer: true,
2107
+ customToast: function customToast() {}
2108
+ });
2109
+ case 8:
2110
+ response = _context22.sent;
2111
+ if (hasLookup) {
2112
+ _context22.next = 12;
2113
+ break;
2114
+ }
2115
+ _context22.next = 12;
2116
+ return (_this$store$order$app = (_this$store$order3 = this.store.order).applyLocalPrintOrderNumbers) === null || _this$store$order$app === void 0 ? void 0 : _this$store$order$app.call(_this$store$order3, response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.order);
2117
+ case 12:
2118
+ return _context22.abrupt("return", response);
2119
+ case 13:
2120
+ case "end":
2121
+ return _context22.stop();
2122
+ }
2123
+ }, _callee22, this);
2124
+ }));
2125
+ function printLocalOrderReceipt(_x18) {
2126
+ return _printLocalOrderReceipt.apply(this, arguments);
2127
+ }
2128
+ return printLocalOrderReceipt;
2129
+ }()
2130
+ }, {
2131
+ key: "getSubmitPaymentStatus",
2132
+ value: function getSubmitPaymentStatus(paymentStatus) {
2133
+ var _this$store$order4, _this$store$order4$ge;
2134
+ if (paymentStatus !== undefined) return paymentStatus;
2135
+ var amountSnapshot = (_this$store$order4 = this.store.order) === null || _this$store$order4 === void 0 || (_this$store$order4$ge = _this$store$order4.getOrderAmountSnapshot) === null || _this$store$order4$ge === void 0 ? void 0 : _this$store$order4$ge.call(_this$store$order4);
2136
+ if (!amountSnapshot) return undefined;
2137
+ try {
2138
+ return new Decimal(amountSnapshot.amountGap || 0).lte(0) ? 'paid' : undefined;
2139
+ } catch (_unused2) {
2140
+ return undefined;
2141
+ }
2142
+ }
962
2143
  }, {
963
2144
  key: "syncPaymentsToOrder",
964
2145
  value: function () {
965
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
966
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
967
- while (1) switch (_context12.prev = _context12.next) {
2146
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2147
+ var _ref12, _params$businessCode, _this$otherParams18, _this$otherParams19, _params$channel;
2148
+ var businessCode, channel, syncParams, syncState, payments, syncResult;
2149
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2150
+ while (1) switch (_context23.prev = _context23.next) {
968
2151
  case 0:
969
2152
  if (this.store.order) {
970
- _context12.next = 2;
2153
+ _context23.next = 2;
971
2154
  break;
972
2155
  }
973
2156
  throw new Error('order 模块未初始化');
974
2157
  case 2:
975
- return _context12.abrupt("return", this.store.order.syncPaymentsToOrder(params));
976
- case 3:
2158
+ businessCode = (_ref12 = (_params$businessCode = params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams18 = this.otherParams) === null || _this$otherParams18 === void 0 ? void 0 : _this$otherParams18.businessCode) !== null && _ref12 !== void 0 ? _ref12 : (_this$otherParams19 = this.otherParams) === null || _this$otherParams19 === void 0 ? void 0 : _this$otherParams19.business_code;
2159
+ channel = (_params$channel = params.channel) !== null && _params$channel !== void 0 ? _params$channel : this.getSubmitOrderSalesChannel();
2160
+ syncParams = _objectSpread(_objectSpread(_objectSpread({}, params), businessCode !== undefined ? {
2161
+ businessCode: businessCode
2162
+ } : {}), channel !== undefined ? {
2163
+ channel: channel
2164
+ } : {});
2165
+ syncState = this.store.order.getOrderSyncState();
2166
+ if (!(params.submitWhenPaid && syncState === 'submitting')) {
2167
+ _context23.next = 8;
2168
+ break;
2169
+ }
2170
+ return _context23.abrupt("return", this.store.order.syncPaymentsToOrder(syncParams));
2171
+ case 8:
2172
+ payments = params.payments || [];
2173
+ _context23.next = 11;
2174
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncStart, {
2175
+ payments: payments,
2176
+ params: syncParams,
2177
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2178
+ orderSnapshot: this.store.order.getOrderSnapshot()
2179
+ });
2180
+ case 11:
2181
+ _context23.prev = 11;
2182
+ _context23.next = 14;
2183
+ return this.store.order.syncPaymentsToOrder(syncParams);
2184
+ case 14:
2185
+ syncResult = _context23.sent;
2186
+ _context23.next = 17;
2187
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2188
+ ok: true,
2189
+ syncResult: syncResult,
2190
+ payments: this.store.order.getOrderPayments(),
2191
+ params: syncParams,
2192
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2193
+ orderSnapshot: this.store.order.getOrderSnapshot()
2194
+ });
2195
+ case 17:
2196
+ return _context23.abrupt("return", syncResult);
2197
+ case 20:
2198
+ _context23.prev = 20;
2199
+ _context23.t0 = _context23["catch"](11);
2200
+ _context23.next = 24;
2201
+ return this.effectsEmit(BaseSalesHookNames.onPaymentSyncEnd, {
2202
+ ok: false,
2203
+ error: _context23.t0,
2204
+ payments: this.store.order.getOrderPayments(),
2205
+ params: syncParams,
2206
+ amountSnapshot: this.store.order.getOrderAmountSnapshot(),
2207
+ orderSnapshot: this.store.order.getOrderSnapshot()
2208
+ });
2209
+ case 24:
2210
+ throw _context23.t0;
2211
+ case 25:
977
2212
  case "end":
978
- return _context12.stop();
2213
+ return _context23.stop();
979
2214
  }
980
- }, _callee12, this);
2215
+ }, _callee23, this, [[11, 20]]);
981
2216
  }));
982
- function syncPaymentsToOrder(_x8) {
2217
+ function syncPaymentsToOrder(_x19) {
983
2218
  return _syncPaymentsToOrder.apply(this, arguments);
984
2219
  }
985
2220
  return syncPaymentsToOrder;
@@ -988,7 +2223,8 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
988
2223
  key: "getOrderPayments",
989
2224
  value: function getOrderPayments() {
990
2225
  if (!this.store.order) return [];
991
- return this.store.order.getOrderPayments();
2226
+ var payments = this.store.order.getOrderPayments();
2227
+ return this.hydrateOrderPaymentNames(payments);
992
2228
  }
993
2229
 
994
2230
  /** 覆盖当前订单支付项,内部由 OrderModule 清洗为 Sales 协议字段。 */
@@ -1003,8 +2239,51 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1003
2239
  }, {
1004
2240
  key: "addOrderPayment",
1005
2241
  value: function addOrderPayment(payment) {
2242
+ var _this$otherParams20,
2243
+ _paymentRecord$paymen,
2244
+ _paymentRecord$create,
2245
+ _this7 = this;
1006
2246
  if (!this.store.order) throw new Error('order 模块未初始化');
1007
- return this.store.order.addOrderPayment(payment);
2247
+ var paymentRecord = payment;
2248
+ var paymentAmount = new Decimal(paymentRecord.amount || 0);
2249
+ if (paymentAmount.isZero()) {
2250
+ this.logWarning('addOrderPayment: 支付金额为 0,跳过添加支付项', {
2251
+ payment: paymentRecord
2252
+ });
2253
+ return this.store.order.getOrderPayments();
2254
+ }
2255
+ var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
2256
+ var shopWalletPassId = (_this$otherParams20 = this.otherParams) === null || _this$otherParams20 === void 0 ? void 0 : _this$otherParams20.shop_wallet_pass_id;
2257
+ if (shopWalletPassId !== undefined && shopWalletPassId !== null) {
2258
+ metadata.shop_wallet_pass_id = shopWalletPassId;
2259
+ }
2260
+ if (!metadata.unique_payment_number) {
2261
+ metadata.unique_payment_number = createUuidV4();
2262
+ }
2263
+ var paymentTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss');
2264
+ var paymentTime = (_paymentRecord$paymen = paymentRecord.payment_time) !== null && _paymentRecord$paymen !== void 0 ? _paymentRecord$paymen : paymentTimestamp;
2265
+ var createdAt = (_paymentRecord$create = paymentRecord.created_at) !== null && _paymentRecord$create !== void 0 ? _paymentRecord$create : paymentTimestamp;
2266
+ var payments = this.store.order.addOrderPayment(_objectSpread(_objectSpread({}, paymentRecord), {}, {
2267
+ metadata: metadata,
2268
+ payment_time: paymentTime,
2269
+ created_at: createdAt
2270
+ }));
2271
+ var amountSnapshot = this.store.order.getOrderAmountSnapshot();
2272
+ var syncState = this.store.order.getOrderSyncState();
2273
+ if (amountSnapshot && syncState !== 'submitting') {
2274
+ var paymentStatus = Number(amountSnapshot.amountGap || 0) <= 0 ? 'paid' : 'partially_paid';
2275
+ void this.syncPaymentsToOrder({
2276
+ payments: payments,
2277
+ paymentStatus: paymentStatus,
2278
+ submitWhenPaid: true,
2279
+ smallTicketDataFlag: 1
2280
+ }).catch(function (error) {
2281
+ _this7.logError('auto sync payments failed', {
2282
+ error: error instanceof Error ? error.message : String(error)
2283
+ });
2284
+ });
2285
+ } else {}
2286
+ return payments;
1008
2287
  }
1009
2288
 
1010
2289
  /** 更新当前订单中的指定支付项。 */
@@ -1033,20 +2312,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1033
2312
  }, {
1034
2313
  key: "getWalletProductList",
1035
2314
  value: function getWalletProductList() {
1036
- var _this$store$order2, _tempOrder$products;
1037
- var tempOrder = (_this$store$order2 = this.store.order) === null || _this$store$order2 === void 0 ? void 0 : _this$store$order2.getTempOrder();
2315
+ var _this$store$order5, _tempOrder$products, _tempOrder$products2;
2316
+ var tempOrder = (_this$store$order5 = this.store.order) === null || _this$store$order5 === void 0 ? void 0 : _this$store$order5.getTempOrder();
1038
2317
  if (!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$products = tempOrder.products) !== null && _tempOrder$products !== void 0 && _tempOrder$products.length)) return [];
1039
- return tempOrder.products.map(function (product) {
1040
- var _product$product_vari, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
2318
+ // 过滤出有 product_id的商品来,如果没有代表他是自定义商品,不需要参与 wallet
2319
+ var products = tempOrder === null || tempOrder === void 0 || (_tempOrder$products2 = tempOrder.products) === null || _tempOrder$products2 === void 0 ? void 0 : _tempOrder$products2.filter(function (n) {
2320
+ return n.product_id;
2321
+ });
2322
+ var walletProducts = products.map(function (product) {
2323
+ var _product$product_vari2, _product$is_charge_ta, _product$holder_id, _metadata$main_produc, _metadata$main_produc2;
1041
2324
  var metadata = product.metadata || {};
1042
2325
  return {
1043
2326
  product_id: product.product_id,
1044
- product_variant_id: String((_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : ''),
2327
+ product_variant_id: String((_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : ''),
1045
2328
  quantity: product.num || 1,
1046
2329
  is_price_include_tax: tempOrder.is_price_include_tax,
1047
2330
  is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
1048
2331
  tax_fee: product.tax_fee,
1049
2332
  selling_price: Number(product.selling_price || 0),
2333
+ discount_list: product.discount_list || [],
1050
2334
  holder_id: (_product$holder_id = product.holder_id) !== null && _product$holder_id !== void 0 ? _product$holder_id : metadata.holder_id,
1051
2335
  original_price: product.original_price,
1052
2336
  main_product_original_price: (_metadata$main_produc = metadata.main_product_original_price) !== null && _metadata$main_produc !== void 0 ? _metadata$main_produc : product.original_price,
@@ -1057,11 +2341,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1057
2341
  surcharge_rounding_remainder: metadata.surcharge_rounding_remainder
1058
2342
  },
1059
2343
  product_bundle: (product.product_bundle || []).map(function (bundle) {
2344
+ var _bundle$bundle_id2, _bundle$bundle_produc2, _bundle$bundle_group_2;
1060
2345
  var bundleMetadata = bundle.metadata || {};
1061
2346
  return {
1062
2347
  is_price_include_tax: tempOrder.is_price_include_tax,
1063
- bundle_id: bundle.bundle_id,
1064
- bundle_product_id: bundle.bundle_product_id,
2348
+ // 套餐子项在 tempOrder 上常为 id(如 1718),prepare/deduction 协议要求 bundle_id
2349
+ bundle_id: (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id,
2350
+ bundle_product_id: (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id,
2351
+ bundle_group_id: (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id,
1065
2352
  bundle_variant_id: bundle.bundle_variant_id,
1066
2353
  price_type: bundle.price_type,
1067
2354
  price_type_ext: bundle.price_type_ext,
@@ -1078,24 +2365,25 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1078
2365
  })
1079
2366
  };
1080
2367
  });
2368
+ return walletProducts;
1081
2369
  }
1082
2370
  }, {
1083
2371
  key: "initWalletData",
1084
2372
  value: function () {
1085
- var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(params) {
1086
- var _params$order_wait_pa, _ref, _tempOrder$is_price_i;
2373
+ var _initWalletData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2374
+ var _params$order_wait_pa, _ref13, _tempOrder$is_price_i;
1087
2375
  var snapshot, tempOrder, amount, walletBusinessData, result;
1088
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1089
- while (1) switch (_context13.prev = _context13.next) {
2376
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2377
+ while (1) switch (_context24.prev = _context24.next) {
1090
2378
  case 0:
1091
2379
  if (this.store.order) {
1092
- _context13.next = 2;
2380
+ _context24.next = 2;
1093
2381
  break;
1094
2382
  }
1095
2383
  throw new Error('order 模块未初始化');
1096
2384
  case 2:
1097
2385
  if (this.store.payment) {
1098
- _context13.next = 4;
2386
+ _context24.next = 4;
1099
2387
  break;
1100
2388
  }
1101
2389
  throw new Error('payment 模块未初始化');
@@ -1104,10 +2392,10 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1104
2392
  tempOrder = snapshot === null || snapshot === void 0 ? void 0 : snapshot.tempOrder;
1105
2393
  amount = snapshot === null || snapshot === void 0 ? void 0 : snapshot.amount;
1106
2394
  if (!(!tempOrder || !amount)) {
1107
- _context13.next = 9;
2395
+ _context24.next = 9;
1108
2396
  break;
1109
2397
  }
1110
- return _context13.abrupt("return", {
2398
+ return _context24.abrupt("return", {
1111
2399
  walletRecommendList: [],
1112
2400
  userIdentificationCodes: [],
1113
2401
  transformList: [],
@@ -1126,15 +2414,15 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1126
2414
  },
1127
2415
  products: this.getWalletProductList(),
1128
2416
  order_wait_pay_amount: (_params$order_wait_pa = params === null || params === void 0 ? void 0 : params.order_wait_pay_amount) !== null && _params$order_wait_pa !== void 0 ? _params$order_wait_pa : Number(amount.amountGap || 0),
1129
- is_price_include_tax: (_ref = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref !== void 0 ? _ref : 1
2417
+ is_price_include_tax: (_ref13 = (_tempOrder$is_price_i = tempOrder.is_price_include_tax) !== null && _tempOrder$is_price_i !== void 0 ? _tempOrder$is_price_i : this.otherParams.is_price_include_tax) !== null && _ref13 !== void 0 ? _ref13 : 1
1130
2418
  }, snapshot.identity.orderId ? {
1131
2419
  payment_order_id: String(snapshot.identity.orderId)
1132
2420
  } : {});
1133
- _context13.next = 12;
2421
+ _context24.next = 12;
1134
2422
  return this.store.payment.wallet.initializeWalletDataFromBusinessAsync(walletBusinessData);
1135
2423
  case 12:
1136
- result = _context13.sent;
1137
- _context13.next = 15;
2424
+ result = _context24.sent;
2425
+ _context24.next = 15;
1138
2426
  return this.core.effects.emit("".concat(this.name, ":onWalletDataInitialized"), {
1139
2427
  orderId: snapshot.identity.orderId,
1140
2428
  customerId: walletBusinessData.customer_id,
@@ -1146,14 +2434,14 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1146
2434
  timestamp: Date.now()
1147
2435
  });
1148
2436
  case 15:
1149
- return _context13.abrupt("return", result);
2437
+ return _context24.abrupt("return", result);
1150
2438
  case 16:
1151
2439
  case "end":
1152
- return _context13.stop();
2440
+ return _context24.stop();
1153
2441
  }
1154
- }, _callee13, this);
2442
+ }, _callee24, this);
1155
2443
  }));
1156
- function initWalletData(_x9) {
2444
+ function initWalletData(_x20) {
1157
2445
  return _initWalletData.apply(this, arguments);
1158
2446
  }
1159
2447
  return initWalletData;
@@ -1180,33 +2468,48 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1180
2468
  }, {
1181
2469
  key: "getPaymentMethodsAsync",
1182
2470
  value: (function () {
1183
- var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1184
- var response;
1185
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1186
- while (1) switch (_context14.prev = _context14.next) {
2471
+ var _getPaymentMethodsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2472
+ var response, paymentMethods;
2473
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2474
+ while (1) switch (_context25.prev = _context25.next) {
1187
2475
  case 0:
1188
- if (!this.store.payment) {
1189
- _context14.next = 2;
1190
- break;
1191
- }
1192
- return _context14.abrupt("return", this.store.payment.getPayMethodListAsync());
1193
- case 2:
1194
- _context14.next = 4;
1195
- return this.request.get('/pay/custom-payment/all');
1196
- case 4:
1197
- response = _context14.sent;
1198
- return _context14.abrupt("return", (response === null || response === void 0 ? void 0 : response.data) || []);
1199
- case 6:
2476
+ _context25.prev = 0;
2477
+ _context25.next = 3;
2478
+ return this.request.get('/pay/custom-payment/all', {
2479
+ filterPaymentMethods: true
2480
+ }, {
2481
+ osServer: true
2482
+ });
2483
+ case 3:
2484
+ response = _context25.sent;
2485
+ paymentMethods = (response === null || response === void 0 ? void 0 : response.data) || [];
2486
+ this.paymentMethodsCache = Array.isArray(paymentMethods) ? _toConsumableArray(paymentMethods) : [];
2487
+ return _context25.abrupt("return", this.getPaymentMethods());
2488
+ case 9:
2489
+ _context25.prev = 9;
2490
+ _context25.t0 = _context25["catch"](0);
2491
+ this.logWarning('getPaymentMethodsAsync: 获取支付方式列表失败,使用缓存列表', {
2492
+ error: _context25.t0 instanceof Error ? _context25.t0.message : String(_context25.t0)
2493
+ });
2494
+ return _context25.abrupt("return", this.getPaymentMethods());
2495
+ case 13:
1200
2496
  case "end":
1201
- return _context14.stop();
2497
+ return _context25.stop();
1202
2498
  }
1203
- }, _callee14, this);
2499
+ }, _callee25, this, [[0, 9]]);
1204
2500
  }));
1205
2501
  function getPaymentMethodsAsync() {
1206
2502
  return _getPaymentMethodsAsync.apply(this, arguments);
1207
2503
  }
1208
2504
  return getPaymentMethodsAsync;
1209
- }() /** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */)
2505
+ }() /** 同步读取初始化时缓存的支付方式列表。 */)
2506
+ }, {
2507
+ key: "getPaymentMethods",
2508
+ value: function getPaymentMethods() {
2509
+ return _toConsumableArray(this.paymentMethodsCache);
2510
+ }
2511
+
2512
+ /** 轻量舍入能力,供现金支付 UI 计算 rounding_amount。 */
1210
2513
  }, {
1211
2514
  key: "roundAmount",
1212
2515
  value: function roundAmount(params) {
@@ -1241,49 +2544,49 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1241
2544
  }, {
1242
2545
  key: "sendCustomerPayLink",
1243
2546
  value: (function () {
1244
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
1245
- var orderIds, _ref2, _ref3, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
1246
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1247
- while (1) switch (_context15.prev = _context15.next) {
2547
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2548
+ var orderIds, _ref14, _ref15, _submitResult$data$or, _submitResult$data, _submitResult$data2, submitResult, orderId;
2549
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2550
+ while (1) switch (_context26.prev = _context26.next) {
1248
2551
  case 0:
1249
2552
  if (this.store.order) {
1250
- _context15.next = 2;
2553
+ _context26.next = 2;
1251
2554
  break;
1252
2555
  }
1253
2556
  throw new Error('order 模块未初始化');
1254
2557
  case 2:
1255
2558
  orderIds = params.order_ids || params.orderIds || [];
1256
2559
  if (!(!orderIds.length || params.submitBeforeSend)) {
1257
- _context15.next = 11;
2560
+ _context26.next = 11;
1258
2561
  break;
1259
2562
  }
1260
- _context15.next = 6;
2563
+ _context26.next = 6;
1261
2564
  return this.submitSalesOrder({
1262
2565
  smallTicketDataFlag: 1
1263
2566
  });
1264
2567
  case 6:
1265
- submitResult = _context15.sent;
1266
- orderId = (_ref2 = (_ref3 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref3 !== void 0 ? _ref3 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref2 !== void 0 ? _ref2 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
2568
+ submitResult = _context26.sent;
2569
+ orderId = (_ref14 = (_ref15 = (_submitResult$data$or = submitResult === null || submitResult === void 0 || (_submitResult$data = submitResult.data) === null || _submitResult$data === void 0 ? void 0 : _submitResult$data.order_id) !== null && _submitResult$data$or !== void 0 ? _submitResult$data$or : submitResult === null || submitResult === void 0 ? void 0 : submitResult.order_id) !== null && _ref15 !== void 0 ? _ref15 : submitResult === null || submitResult === void 0 || (_submitResult$data2 = submitResult.data) === null || _submitResult$data2 === void 0 ? void 0 : _submitResult$data2.id) !== null && _ref14 !== void 0 ? _ref14 : submitResult === null || submitResult === void 0 ? void 0 : submitResult.id;
1267
2570
  if (orderId) {
1268
- _context15.next = 10;
2571
+ _context26.next = 10;
1269
2572
  break;
1270
2573
  }
1271
2574
  throw new Error('本地订单提交云端失败,无法发送支付链接');
1272
2575
  case 10:
1273
2576
  orderIds = [orderId];
1274
2577
  case 11:
1275
- return _context15.abrupt("return", this.store.order.sendCustomerPayLink({
2578
+ return _context26.abrupt("return", this.store.order.sendCustomerPayLink({
1276
2579
  emails: params.emails,
1277
2580
  notify_action: params.notify_action,
1278
2581
  order_ids: orderIds
1279
2582
  }));
1280
2583
  case 12:
1281
2584
  case "end":
1282
- return _context15.stop();
2585
+ return _context26.stop();
1283
2586
  }
1284
- }, _callee15, this);
2587
+ }, _callee26, this);
1285
2588
  }));
1286
- function sendCustomerPayLink(_x10) {
2589
+ function sendCustomerPayLink(_x21) {
1287
2590
  return _sendCustomerPayLink.apply(this, arguments);
1288
2591
  }
1289
2592
  return sendCustomerPayLink;
@@ -1293,76 +2596,162 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1293
2596
  value: function transformBaseProductToOrderProduct(params) {
1294
2597
  return _transformBaseProductToOrderProduct(params);
1295
2598
  }
2599
+ }, {
2600
+ key: "calculateProductBookingPrice",
2601
+ value: function () {
2602
+ var _calculateProductBookingPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
2603
+ var _params$customer_id;
2604
+ var quotation, customerId, authoritativeProduct, product;
2605
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2606
+ while (1) switch (_context27.prev = _context27.next) {
2607
+ case 0:
2608
+ quotation = this.store.quotation;
2609
+ customerId = (_params$customer_id = params.customer_id) !== null && _params$customer_id !== void 0 ? _params$customer_id : this.getCurrentOrderCustomerId();
2610
+ _context27.next = 4;
2611
+ return this.loadProductForPriceQuery(params, customerId);
2612
+ case 4:
2613
+ authoritativeProduct = _context27.sent;
2614
+ product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
2615
+ _context27.next = 8;
2616
+ return this.loadQuotationForPriceQuery({
2617
+ quotation: quotation,
2618
+ customer_id: customerId,
2619
+ channel: params.channel
2620
+ });
2621
+ case 8:
2622
+ return _context27.abrupt("return", calculateBaseSalesProductBookingPrice(_objectSpread(_objectSpread({}, params), {}, {
2623
+ product: product,
2624
+ fallback_price: authoritativeProduct ? undefined : params.fallback_price,
2625
+ customer_id: customerId,
2626
+ quotation: quotation
2627
+ })));
2628
+ case 9:
2629
+ case "end":
2630
+ return _context27.stop();
2631
+ }
2632
+ }, _callee27, this);
2633
+ }));
2634
+ function calculateProductBookingPrice(_x22) {
2635
+ return _calculateProductBookingPrice.apply(this, arguments);
2636
+ }
2637
+ return calculateProductBookingPrice;
2638
+ }()
1296
2639
  }, {
1297
2640
  key: "addProductToOrder",
1298
2641
  value: function () {
1299
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(product, booking) {
2642
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(product, booking) {
1300
2643
  var products;
1301
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1302
- while (1) switch (_context16.prev = _context16.next) {
2644
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2645
+ while (1) switch (_context28.prev = _context28.next) {
1303
2646
  case 0:
1304
- _context16.prev = 0;
2647
+ _context28.prev = 0;
1305
2648
  if (this.store.order) {
1306
- _context16.next = 3;
2649
+ _context28.next = 3;
1307
2650
  break;
1308
2651
  }
1309
2652
  throw new Error('order 模块未初始化');
1310
2653
  case 3:
1311
- _context16.next = 5;
2654
+ _context28.next = 5;
1312
2655
  return this.store.order.addProductToOrder(product, booking);
1313
2656
  case 5:
1314
- products = _context16.sent;
1315
- return _context16.abrupt("return", products);
2657
+ products = _context28.sent;
2658
+ return _context28.abrupt("return", products);
1316
2659
  case 9:
1317
- _context16.prev = 9;
1318
- _context16.t0 = _context16["catch"](0);
1319
- throw _context16.t0;
2660
+ _context28.prev = 9;
2661
+ _context28.t0 = _context28["catch"](0);
2662
+ throw _context28.t0;
1320
2663
  case 12:
1321
2664
  case "end":
1322
- return _context16.stop();
2665
+ return _context28.stop();
1323
2666
  }
1324
- }, _callee16, this, [[0, 9]]);
2667
+ }, _callee28, this, [[0, 9]]);
1325
2668
  }));
1326
- function addProductToOrder(_x11, _x12) {
2669
+ function addProductToOrder(_x23, _x24) {
1327
2670
  return _addProductToOrder.apply(this, arguments);
1328
2671
  }
1329
2672
  return addProductToOrder;
1330
2673
  }()
1331
2674
  }, {
1332
- key: "updateProductInOrder",
2675
+ key: "updateOrderProduct",
1333
2676
  value: function () {
1334
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
2677
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
1335
2678
  var products;
1336
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1337
- while (1) switch (_context17.prev = _context17.next) {
2679
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2680
+ while (1) switch (_context29.prev = _context29.next) {
1338
2681
  case 0:
1339
- _context17.prev = 0;
2682
+ _context29.prev = 0;
1340
2683
  if (this.store.order) {
1341
- _context17.next = 3;
2684
+ _context29.next = 3;
1342
2685
  break;
1343
2686
  }
1344
2687
  throw new Error('order 模块未初始化');
1345
2688
  case 3:
1346
- _context17.next = 5;
1347
- return this.store.order.updateProductInOrder(params);
2689
+ _context29.next = 5;
2690
+ return this.store.order.updateOrderProduct(params);
1348
2691
  case 5:
1349
- products = _context17.sent;
1350
- return _context17.abrupt("return", products);
2692
+ products = _context29.sent;
2693
+ return _context29.abrupt("return", products);
1351
2694
  case 9:
1352
- _context17.prev = 9;
1353
- _context17.t0 = _context17["catch"](0);
1354
- throw _context17.t0;
2695
+ _context29.prev = 9;
2696
+ _context29.t0 = _context29["catch"](0);
2697
+ throw _context29.t0;
1355
2698
  case 12:
1356
2699
  case "end":
1357
- return _context17.stop();
2700
+ return _context29.stop();
1358
2701
  }
1359
- }, _callee17, this, [[0, 9]]);
2702
+ }, _callee29, this, [[0, 9]]);
1360
2703
  }));
1361
- function updateProductInOrder(_x13) {
1362
- return _updateProductInOrder.apply(this, arguments);
2704
+ function updateOrderProduct(_x25) {
2705
+ return _updateOrderProduct.apply(this, arguments);
1363
2706
  }
1364
- return updateProductInOrder;
2707
+ return updateOrderProduct;
1365
2708
  }()
2709
+ }, {
2710
+ key: "updateOrderProductQuantity",
2711
+ value: function () {
2712
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
2713
+ var products;
2714
+ return _regeneratorRuntime().wrap(function _callee30$(_context30) {
2715
+ while (1) switch (_context30.prev = _context30.next) {
2716
+ case 0:
2717
+ _context30.prev = 0;
2718
+ if (this.store.order) {
2719
+ _context30.next = 3;
2720
+ break;
2721
+ }
2722
+ throw new Error('order 模块未初始化');
2723
+ case 3:
2724
+ _context30.next = 5;
2725
+ return this.store.order.updateOrderProductQuantity(params);
2726
+ case 5:
2727
+ products = _context30.sent;
2728
+ return _context30.abrupt("return", products);
2729
+ case 9:
2730
+ _context30.prev = 9;
2731
+ _context30.t0 = _context30["catch"](0);
2732
+ throw _context30.t0;
2733
+ case 12:
2734
+ case "end":
2735
+ return _context30.stop();
2736
+ }
2737
+ }, _callee30, this, [[0, 9]]);
2738
+ }));
2739
+ function updateOrderProductQuantity(_x26) {
2740
+ return _updateOrderProductQuantity.apply(this, arguments);
2741
+ }
2742
+ return updateOrderProductQuantity;
2743
+ }()
2744
+ }, {
2745
+ key: "updateOrderBooking",
2746
+ value: function updateOrderBooking(params) {
2747
+ try {
2748
+ if (!this.store.order) throw new Error('order 模块未初始化');
2749
+ return this.store.order.updateOrderBooking(params);
2750
+ } catch (error) {
2751
+ throw error;
2752
+ }
2753
+ }
2754
+
1366
2755
  /**
1367
2756
  * 设置单行商品备注(与整单 `updateTempOrderNote` 区分)。
1368
2757
  * 多行同 SKU 时必须传入与删除/更新一致的 unique_identification_number。
@@ -1370,12 +2759,12 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1370
2759
  }, {
1371
2760
  key: "setOrderProductLineNote",
1372
2761
  value: (function () {
1373
- var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(identity, note) {
2762
+ var _setOrderProductLineNote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(identity, note) {
1374
2763
  var params, products;
1375
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1376
- while (1) switch (_context18.prev = _context18.next) {
2764
+ return _regeneratorRuntime().wrap(function _callee31$(_context31) {
2765
+ while (1) switch (_context31.prev = _context31.next) {
1377
2766
  case 0:
1378
- _context18.prev = 0;
2767
+ _context31.prev = 0;
1379
2768
  params = {
1380
2769
  product_id: identity.product_id,
1381
2770
  product_variant_id: identity.product_variant_id,
@@ -1386,81 +2775,189 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1386
2775
  if (identity.unique_identification_number !== undefined) {
1387
2776
  params.unique_identification_number = identity.unique_identification_number;
1388
2777
  }
1389
- if (identity.product_option_item !== undefined) {
1390
- params.product_option_item = identity.product_option_item;
2778
+ if (identity.product_sku !== undefined) {
2779
+ params.product_sku = identity.product_sku;
1391
2780
  }
1392
2781
  if (identity.product_bundle !== undefined) params.product_bundle = identity.product_bundle;
1393
- _context18.next = 7;
1394
- return this.updateProductInOrder(params);
2782
+ _context31.next = 7;
2783
+ return this.updateOrderProduct(params);
1395
2784
  case 7:
1396
- products = _context18.sent;
1397
- return _context18.abrupt("return", products);
2785
+ products = _context31.sent;
2786
+ return _context31.abrupt("return", products);
1398
2787
  case 11:
1399
- _context18.prev = 11;
1400
- _context18.t0 = _context18["catch"](0);
1401
- throw _context18.t0;
2788
+ _context31.prev = 11;
2789
+ _context31.t0 = _context31["catch"](0);
2790
+ throw _context31.t0;
1402
2791
  case 14:
1403
2792
  case "end":
1404
- return _context18.stop();
2793
+ return _context31.stop();
1405
2794
  }
1406
- }, _callee18, this, [[0, 11]]);
2795
+ }, _callee31, this, [[0, 11]]);
1407
2796
  }));
1408
- function setOrderProductLineNote(_x14, _x15) {
2797
+ function setOrderProductLineNote(_x27, _x28) {
1409
2798
  return _setOrderProductLineNote.apply(this, arguments);
1410
2799
  }
1411
2800
  return setOrderProductLineNote;
1412
- }())
2801
+ }()
2802
+ /**
2803
+ * 批量删除购物车行,末尾仅一次促销重算。
2804
+ *
2805
+ * @example
2806
+ * await baseSales.removeProductsFromOrder([identityA, identityB]);
2807
+ */
2808
+ )
1413
2809
  }, {
1414
- key: "removeProductFromOrder",
1415
- value: function () {
1416
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(identity) {
1417
- var products;
1418
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1419
- while (1) switch (_context19.prev = _context19.next) {
2810
+ key: "removeProductsFromOrder",
2811
+ value: (function () {
2812
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(identities) {
2813
+ return _regeneratorRuntime().wrap(function _callee32$(_context32) {
2814
+ while (1) switch (_context32.prev = _context32.next) {
1420
2815
  case 0:
1421
- _context19.prev = 0;
2816
+ _context32.prev = 0;
1422
2817
  if (this.store.order) {
1423
- _context19.next = 3;
2818
+ _context32.next = 3;
1424
2819
  break;
1425
2820
  }
1426
2821
  throw new Error('order 模块未初始化');
1427
2822
  case 3:
1428
- _context19.next = 5;
1429
- return this.store.order.removeProductFromOrder(identity);
2823
+ _context32.next = 5;
2824
+ return this.store.order.removeProductsFromOrder(identities);
1430
2825
  case 5:
1431
- products = _context19.sent;
1432
- return _context19.abrupt("return", products);
1433
- case 9:
1434
- _context19.prev = 9;
1435
- _context19.t0 = _context19["catch"](0);
1436
- throw _context19.t0;
1437
- case 12:
2826
+ return _context32.abrupt("return", _context32.sent);
2827
+ case 8:
2828
+ _context32.prev = 8;
2829
+ _context32.t0 = _context32["catch"](0);
2830
+ throw _context32.t0;
2831
+ case 11:
1438
2832
  case "end":
1439
- return _context19.stop();
2833
+ return _context32.stop();
1440
2834
  }
1441
- }, _callee19, this, [[0, 9]]);
2835
+ }, _callee32, this, [[0, 8]]);
1442
2836
  }));
1443
- function removeProductFromOrder(_x16) {
2837
+ function removeProductsFromOrder(_x29) {
2838
+ return _removeProductsFromOrder.apply(this, arguments);
2839
+ }
2840
+ return removeProductsFromOrder;
2841
+ }())
2842
+ }, {
2843
+ key: "removeProductFromOrder",
2844
+ value: function () {
2845
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(identity) {
2846
+ return _regeneratorRuntime().wrap(function _callee33$(_context33) {
2847
+ while (1) switch (_context33.prev = _context33.next) {
2848
+ case 0:
2849
+ return _context33.abrupt("return", this.removeProductsFromOrder([identity]));
2850
+ case 1:
2851
+ case "end":
2852
+ return _context33.stop();
2853
+ }
2854
+ }, _callee33, this);
2855
+ }));
2856
+ function removeProductFromOrder(_x30) {
1444
2857
  return _removeProductFromOrder.apply(this, arguments);
1445
2858
  }
1446
2859
  return removeProductFromOrder;
1447
- }() // 获取商品列表
2860
+ }() // ─── 促销/赠品 透传(迁移自 booking usePromotion) ────────────────
2861
+ /**
2862
+ * 注入促销评估器到底层 OrderModule。
2863
+ *
2864
+ * @example
2865
+ * solution.setPromotionEvaluator(appHelper.utils.promotionEvaluator);
2866
+ */
2867
+ }, {
2868
+ key: "setPromotionEvaluator",
2869
+ value: function setPromotionEvaluator(evaluator) {
2870
+ if (!this.store.order) throw new Error('order 模块未初始化');
2871
+ this.store.order.setPromotionEvaluator(evaluator);
2872
+ }
2873
+
2874
+ /**
2875
+ * 注入赠品选择 resolver。UI 层(SalesSdk)通过 bridge 提供。
2876
+ *
2877
+ * @example
2878
+ * solution.setGiftSelectResolver(async (ctx) => bridge.request(ctx));
2879
+ */
2880
+ }, {
2881
+ key: "setGiftSelectResolver",
2882
+ value: function setGiftSelectResolver(resolver) {
2883
+ if (!this.store.order) throw new Error('order 模块未初始化');
2884
+ this.store.order.setGiftSelectResolver(resolver);
2885
+ }
2886
+
2887
+ /**
2888
+ * 为商品目录追加促销标签,供 SalesSdkProductProvider 等商品列表入口复用。
2889
+ *
2890
+ * @example
2891
+ * const products = solution.appendPromotionTags(catalogProducts);
2892
+ */
2893
+ }, {
2894
+ key: "appendPromotionTags",
2895
+ value: function appendPromotionTags(products) {
2896
+ if (!this.store.order) throw new Error('order 模块未初始化');
2897
+ return this.store.order.appendPromotionTags(products);
2898
+ }
2899
+
2900
+ /**
2901
+ * 主动触发一次促销应用(一般写路径会自动触发,少数场景如客户切换后可手动调)。
2902
+ */
2903
+ }, {
2904
+ key: "applyPromotion",
2905
+ value: (function () {
2906
+ var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34() {
2907
+ return _regeneratorRuntime().wrap(function _callee34$(_context34) {
2908
+ while (1) switch (_context34.prev = _context34.next) {
2909
+ case 0:
2910
+ if (this.store.order) {
2911
+ _context34.next = 2;
2912
+ break;
2913
+ }
2914
+ throw new Error('order 模块未初始化');
2915
+ case 2:
2916
+ _context34.next = 4;
2917
+ return this.store.order.applyPromotion();
2918
+ case 4:
2919
+ case "end":
2920
+ return _context34.stop();
2921
+ }
2922
+ }, _callee34, this);
2923
+ }));
2924
+ function applyPromotion() {
2925
+ return _applyPromotion.apply(this, arguments);
2926
+ }
2927
+ return applyPromotion;
2928
+ }() /** 最近一次促销计算输出的未满足提示。 */)
2929
+ }, {
2930
+ key: "getUnfulfilledPromotions",
2931
+ value: function getUnfulfilledPromotions() {
2932
+ var _this$store$order6;
2933
+ return ((_this$store$order6 = this.store.order) === null || _this$store$order6 === void 0 ? void 0 : _this$store$order6.getUnfulfilledPromotions()) || [];
2934
+ }
2935
+
2936
+ /** 最近一次促销计算输出的赠品操作 diff。 */
2937
+ }, {
2938
+ key: "getLastGiftActions",
2939
+ value: function getLastGiftActions() {
2940
+ var _this$store$order7;
2941
+ return ((_this$store$order7 = this.store.order) === null || _this$store$order7 === void 0 ? void 0 : _this$store$order7.getLastGiftActions()) || null;
2942
+ }
2943
+
2944
+ // 获取商品列表
1448
2945
  // TODO 需要跟 webpos 内的对齐一下
1449
2946
  }, {
1450
2947
  key: "getProductList",
1451
2948
  value: function () {
1452
- var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1453
- var _this$otherParams6;
2949
+ var _getProductList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35() {
2950
+ var _this$otherParams21;
1454
2951
  var menu_list_ids, _this$store$products, res;
1455
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1456
- while (1) switch (_context20.prev = _context20.next) {
2952
+ return _regeneratorRuntime().wrap(function _callee35$(_context35) {
2953
+ while (1) switch (_context35.prev = _context35.next) {
1457
2954
  case 0:
1458
2955
  // 可以直接通过配置里的 menu 读取
1459
- menu_list_ids = ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 || (_this$otherParams6 = _this$otherParams6.dineInConfig) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6['menu.associated_menus'].map(function (n) {
2956
+ menu_list_ids = ((_this$otherParams21 = this.otherParams) === null || _this$otherParams21 === void 0 || (_this$otherParams21 = _this$otherParams21.dineInConfig) === null || _this$otherParams21 === void 0 ? void 0 : _this$otherParams21['menu.associated_menus'].map(function (n) {
1460
2957
  return Number(n.value);
1461
2958
  })) || [];
1462
- _context20.prev = 1;
1463
- _context20.next = 4;
2959
+ _context35.prev = 1;
2960
+ _context35.next = 4;
1464
2961
  return (_this$store$products = this.store.products) === null || _this$store$products === void 0 ? void 0 : _this$store$products.loadProducts({
1465
2962
  menu_list_ids: menu_list_ids,
1466
2963
  cacheId: this.cacheId,
@@ -1468,17 +2965,17 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1468
2965
  schedule_datetime: dayjs().format('YYYY-MM-DD HH:mm:ss')
1469
2966
  });
1470
2967
  case 4:
1471
- res = _context20.sent;
1472
- return _context20.abrupt("return", res);
2968
+ res = _context35.sent;
2969
+ return _context35.abrupt("return", res);
1473
2970
  case 8:
1474
- _context20.prev = 8;
1475
- _context20.t0 = _context20["catch"](1);
1476
- throw _context20.t0;
2971
+ _context35.prev = 8;
2972
+ _context35.t0 = _context35["catch"](1);
2973
+ throw _context35.t0;
1477
2974
  case 11:
1478
2975
  case "end":
1479
- return _context20.stop();
2976
+ return _context35.stop();
1480
2977
  }
1481
- }, _callee20, this, [[1, 8]]);
2978
+ }, _callee35, this, [[1, 8]]);
1482
2979
  }));
1483
2980
  function getProductList() {
1484
2981
  return _getProductList.apply(this, arguments);
@@ -1493,27 +2990,33 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
1493
2990
  }, {
1494
2991
  key: "setOtherParams",
1495
2992
  value: function () {
1496
- var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
1497
- var _ref4,
1498
- _ref4$cover,
2993
+ var _setOtherParams = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
2994
+ var _this$otherParams22;
2995
+ var _ref16,
2996
+ _ref16$cover,
1499
2997
  cover,
1500
- _args21 = arguments;
1501
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1502
- while (1) switch (_context21.prev = _context21.next) {
2998
+ _args36 = arguments;
2999
+ return _regeneratorRuntime().wrap(function _callee36$(_context36) {
3000
+ while (1) switch (_context36.prev = _context36.next) {
1503
3001
  case 0:
1504
- _ref4 = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {}, _ref4$cover = _ref4.cover, cover = _ref4$cover === void 0 ? false : _ref4$cover;
3002
+ _ref16 = _args36.length > 1 && _args36[1] !== undefined ? _args36[1] : {}, _ref16$cover = _ref16.cover, cover = _ref16$cover === void 0 ? false : _ref16$cover;
1505
3003
  if (cover) {
1506
- this.otherParams = params;
3004
+ this.otherParams = _objectSpread({}, params);
1507
3005
  } else {
1508
3006
  this.otherParams = _objectSpread(_objectSpread({}, this.otherParams), params);
1509
3007
  }
1510
- case 2:
3008
+ this.cacheId = (_this$otherParams22 = this.otherParams) === null || _this$otherParams22 === void 0 ? void 0 : _this$otherParams22.cacheId;
3009
+ _context36.next = 5;
3010
+ return this.syncOtherParamsToSubModules(params, {
3011
+ cover: cover
3012
+ });
3013
+ case 5:
1511
3014
  case "end":
1512
- return _context21.stop();
3015
+ return _context36.stop();
1513
3016
  }
1514
- }, _callee21, this);
3017
+ }, _callee36, this);
1515
3018
  }));
1516
- function setOtherParams(_x17) {
3019
+ function setOtherParams(_x31) {
1517
3020
  return _setOtherParams.apply(this, arguments);
1518
3021
  }
1519
3022
  return setOtherParams;