@pisell/pisellos 0.0.568 → 0.0.570

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 (455) hide show
  1. package/dist/effects/index.d.ts +2 -2
  2. package/dist/model/strategy/adapter/dataVariant/type.d.ts +3 -3
  3. package/dist/model/strategy/adapter/itemRule/type.d.ts +6 -6
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/promotion/type.d.ts +5 -5
  6. package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
  7. package/dist/model/strategy/type.d.ts +1 -1
  8. package/dist/modules/BaseModule.d.ts +2 -2
  9. package/dist/modules/BaseModule.js +4 -4
  10. package/dist/modules/BookingContext/index.d.ts +48 -0
  11. package/dist/modules/BookingContext/index.js +566 -0
  12. package/dist/modules/BookingContext/types.d.ts +102 -0
  13. package/dist/modules/BookingContext/types.js +51 -0
  14. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  15. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  16. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  17. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  18. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  19. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  20. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  21. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  22. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  23. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  24. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  25. package/dist/modules/BookingContext/utils/index.js +11 -0
  26. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  27. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  28. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  29. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  30. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  31. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  32. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  33. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  34. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  35. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  36. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  37. package/dist/modules/BookingContext/utils/resources.js +486 -0
  38. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  39. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  40. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  41. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  42. package/dist/modules/Cart/utils/cartProduct.js +26 -5
  43. package/dist/modules/Cart/utils/changePrice.js +27 -20
  44. package/dist/modules/Customer/index.d.ts +20 -0
  45. package/dist/modules/Customer/index.js +172 -83
  46. package/dist/modules/Customer/types.d.ts +3 -1
  47. package/dist/modules/Discount/index.d.ts +2 -1
  48. package/dist/modules/Discount/index.js +37 -9
  49. package/dist/modules/Discount/types.d.ts +2 -1
  50. package/dist/modules/Holder/types.d.ts +1 -1
  51. package/dist/modules/OpenData/index.d.ts +8 -0
  52. package/dist/modules/OpenData/index.js +36 -16
  53. package/dist/modules/OpenData/types.d.ts +1 -1
  54. package/dist/modules/Order/index.d.ts +448 -23
  55. package/dist/modules/Order/index.js +5417 -561
  56. package/dist/modules/Order/types.d.ts +693 -88
  57. package/dist/modules/Order/types.js +68 -1
  58. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  59. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  60. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  61. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  62. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  63. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  64. package/dist/modules/Order/utils.d.ts +167 -18
  65. package/dist/modules/Order/utils.js +960 -165
  66. package/dist/modules/Payment/index.d.ts +10 -9
  67. package/dist/modules/Payment/index.js +465 -703
  68. package/dist/modules/Payment/types.d.ts +47 -23
  69. package/dist/modules/Payment/utils.d.ts +1 -1
  70. package/dist/modules/Payment/utils.js +4 -3
  71. package/dist/modules/Payment/walletpass.js +44 -29
  72. package/dist/modules/Product/index.d.ts +1 -1
  73. package/dist/modules/Product/types.d.ts +29 -7
  74. package/dist/modules/ProductList/index.d.ts +17 -13
  75. package/dist/modules/ProductList/index.js +184 -74
  76. package/dist/modules/ProductList/types.d.ts +17 -0
  77. package/dist/modules/Quotation/index.d.ts +22 -2
  78. package/dist/modules/Quotation/index.js +108 -42
  79. package/dist/modules/Quotation/types.d.ts +19 -0
  80. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  81. package/dist/modules/ResourcePlanner/index.js +181 -0
  82. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  83. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  84. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  85. package/dist/modules/ResourcePlanner/types.js +1 -0
  86. package/dist/modules/Rules/index.d.ts +8 -10
  87. package/dist/modules/Rules/index.js +222 -109
  88. package/dist/modules/Rules/types.d.ts +15 -4
  89. package/dist/modules/SalesSummary/index.d.ts +23 -26
  90. package/dist/modules/SalesSummary/index.js +152 -46
  91. package/dist/modules/SalesSummary/types.d.ts +9 -1
  92. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  93. package/dist/modules/SalesSummary/utils.js +803 -163
  94. package/dist/modules/ScanOrderLogger/types.d.ts +2 -2
  95. package/dist/modules/Schedule/getDateIsInSchedule.d.ts +1 -1
  96. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -7
  97. package/dist/modules/Schedule/index.d.ts +18 -5
  98. package/dist/modules/Schedule/index.js +78 -24
  99. package/dist/modules/Schedule/type.d.ts +7 -7
  100. package/dist/modules/Schedule/types.d.ts +11 -9
  101. package/dist/modules/Summary/index.js +4 -3
  102. package/dist/modules/SurchargeList/index.d.ts +18 -0
  103. package/dist/modules/SurchargeList/index.js +185 -0
  104. package/dist/modules/SurchargeList/types.d.ts +15 -0
  105. package/dist/modules/SurchargeList/types.js +1 -0
  106. package/dist/modules/index.d.ts +3 -0
  107. package/dist/modules/index.js +4 -1
  108. package/dist/plugins/app.d.ts +2 -0
  109. package/dist/plugins/request.d.ts +3 -2
  110. package/dist/server/index.d.ts +462 -8
  111. package/dist/server/index.js +6112 -656
  112. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  113. package/dist/server/modules/floor-plan/index.js +595 -0
  114. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  115. package/dist/server/modules/floor-plan/types.js +13 -0
  116. package/dist/server/modules/index.d.ts +7 -2
  117. package/dist/server/modules/index.js +6 -0
  118. package/dist/server/modules/menu/types.d.ts +1 -1
  119. package/dist/server/modules/order/index.d.ts +207 -14
  120. package/dist/server/modules/order/index.js +2326 -379
  121. package/dist/server/modules/order/types.d.ts +91 -20
  122. package/dist/server/modules/order/types.js +14 -1
  123. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  124. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  125. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  126. package/dist/server/modules/payment/index.d.ts +28 -0
  127. package/dist/server/modules/payment/index.js +305 -0
  128. package/dist/server/modules/payment/types.d.ts +9 -0
  129. package/dist/server/modules/payment/types.js +1 -0
  130. package/dist/server/modules/products/index.d.ts +105 -14
  131. package/dist/server/modules/products/index.js +1393 -516
  132. package/dist/server/modules/products/types.d.ts +35 -2
  133. package/dist/server/modules/products/types.js +4 -0
  134. package/dist/server/modules/quotation/index.d.ts +39 -0
  135. package/dist/server/modules/quotation/index.js +278 -66
  136. package/dist/server/modules/resource/index.d.ts +2 -3
  137. package/dist/server/modules/resource/index.js +108 -86
  138. package/dist/server/modules/resource/types.d.ts +1 -1
  139. package/dist/server/modules/schedule/index.d.ts +6 -4
  140. package/dist/server/modules/schedule/index.js +116 -85
  141. package/dist/server/modules/schedule/utils.d.ts +1 -1
  142. package/dist/server/test.json +713 -0
  143. package/dist/server/types.d.ts +6 -4
  144. package/dist/server/utils/product.js +2 -2
  145. package/dist/server/utils/small-ticket.d.ts +71 -0
  146. package/dist/server/utils/small-ticket.js +963 -0
  147. package/dist/solution/BaseSales/index.d.ts +378 -0
  148. package/dist/solution/BaseSales/index.js +4006 -0
  149. package/dist/solution/BaseSales/types.d.ts +394 -0
  150. package/dist/solution/BaseSales/types.js +40 -0
  151. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  152. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  153. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  154. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  155. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  156. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  157. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  158. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  159. package/dist/solution/BaseSales/utils.d.ts +40 -0
  160. package/dist/solution/BaseSales/utils.js +263 -0
  161. package/dist/solution/BookingByStep/index.d.ts +2 -2
  162. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  163. package/dist/solution/BookingTicket/index.d.ts +382 -25
  164. package/dist/solution/BookingTicket/index.js +2506 -443
  165. package/dist/solution/BookingTicket/types.d.ts +191 -6
  166. package/dist/solution/BookingTicket/types.js +83 -10
  167. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  168. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  169. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  170. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  171. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  172. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  173. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  174. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  175. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  176. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  177. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  178. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  179. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  180. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  181. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  182. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  183. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  184. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +41 -1
  185. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  186. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  187. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  188. package/dist/solution/BookingTicket/utils/scan/handleScan.js +11 -3
  189. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  190. package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
  191. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  192. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  193. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  194. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  195. package/dist/solution/Checkout/index.d.ts +1 -0
  196. package/dist/solution/Checkout/index.js +25 -34
  197. package/dist/solution/Checkout/utils/index.js +4 -4
  198. package/dist/solution/RegisterAndLogin/config.js +2 -10
  199. package/dist/solution/Sales/index.d.ts +50 -5
  200. package/dist/solution/Sales/index.js +484 -92
  201. package/dist/solution/Sales/types.d.ts +29 -5
  202. package/dist/solution/ScanOrder/index.d.ts +27 -21
  203. package/dist/solution/ScanOrder/index.js +499 -434
  204. package/dist/solution/ScanOrder/types.d.ts +38 -16
  205. package/dist/solution/ScanOrder/types.js +4 -5
  206. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  207. package/dist/solution/ScanOrder/utils.js +109 -34
  208. package/dist/solution/ShopDiscount/index.js +4 -4
  209. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  210. package/dist/solution/ShopDiscount/utils.d.ts +2 -2
  211. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  212. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  213. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  214. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  215. package/dist/solution/VenueBooking/index.d.ts +29 -20
  216. package/dist/solution/VenueBooking/index.js +301 -213
  217. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  218. package/dist/solution/VenueBooking/types.d.ts +1 -1
  219. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  220. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  221. package/dist/solution/index.d.ts +2 -0
  222. package/dist/solution/index.js +3 -1
  223. package/dist/types/index.d.ts +12 -2
  224. package/dist/utils/task.d.ts +2 -2
  225. package/dist/utils/watch.d.ts +2 -2
  226. package/lib/effects/index.d.ts +2 -2
  227. package/lib/model/strategy/adapter/dataVariant/type.d.ts +3 -3
  228. package/lib/model/strategy/adapter/itemRule/type.d.ts +6 -6
  229. package/lib/model/strategy/adapter/promotion/evaluator.js +3 -2
  230. package/lib/model/strategy/adapter/promotion/type.d.ts +5 -5
  231. package/lib/model/strategy/adapter/walletPass/utils.js +6 -4
  232. package/lib/model/strategy/type.d.ts +1 -1
  233. package/lib/modules/BaseModule.d.ts +2 -2
  234. package/lib/modules/BaseModule.js +4 -4
  235. package/lib/modules/BookingContext/index.d.ts +48 -0
  236. package/lib/modules/BookingContext/index.js +390 -0
  237. package/lib/modules/BookingContext/types.d.ts +102 -0
  238. package/lib/modules/BookingContext/types.js +48 -0
  239. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  240. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +286 -0
  241. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  242. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +148 -0
  243. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  244. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +242 -0
  245. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  246. package/lib/modules/BookingContext/utils/flexible.js +63 -0
  247. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  248. package/lib/modules/BookingContext/utils/formatResourceList.js +35 -0
  249. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  250. package/lib/modules/BookingContext/utils/index.js +126 -0
  251. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  252. package/lib/modules/BookingContext/utils/noResource.js +78 -0
  253. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  254. package/lib/modules/BookingContext/utils/orderLineDisplay.js +29 -0
  255. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  256. package/lib/modules/BookingContext/utils/productExtend.js +330 -0
  257. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  258. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  259. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  260. package/lib/modules/BookingContext/utils/resourceSelection.js +24 -0
  261. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  262. package/lib/modules/BookingContext/utils/resources.js +419 -0
  263. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  264. package/lib/modules/BookingContext/utils/serviceTimes.js +161 -0
  265. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  266. package/lib/modules/BookingContext/utils/timeSlices.js +114 -0
  267. package/lib/modules/Cart/utils/cartProduct.js +27 -5
  268. package/lib/modules/Cart/utils/changePrice.js +20 -14
  269. package/lib/modules/Customer/index.d.ts +20 -0
  270. package/lib/modules/Customer/index.js +63 -10
  271. package/lib/modules/Customer/types.d.ts +3 -1
  272. package/lib/modules/Discount/index.d.ts +2 -1
  273. package/lib/modules/Discount/index.js +18 -2
  274. package/lib/modules/Discount/types.d.ts +2 -1
  275. package/lib/modules/Holder/types.d.ts +1 -1
  276. package/lib/modules/OpenData/index.d.ts +8 -0
  277. package/lib/modules/OpenData/index.js +21 -3
  278. package/lib/modules/OpenData/types.d.ts +1 -1
  279. package/lib/modules/Order/index.d.ts +448 -23
  280. package/lib/modules/Order/index.js +3641 -308
  281. package/lib/modules/Order/types.d.ts +693 -88
  282. package/lib/modules/Order/types.js +55 -1
  283. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  284. package/lib/modules/Order/utils/bundleDiscountHydration.js +106 -0
  285. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  286. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  287. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  288. package/lib/modules/Order/utils/orderCollectionIdentity.js +353 -0
  289. package/lib/modules/Order/utils.d.ts +167 -18
  290. package/lib/modules/Order/utils.js +974 -138
  291. package/lib/modules/Payment/index.d.ts +10 -9
  292. package/lib/modules/Payment/index.js +30 -124
  293. package/lib/modules/Payment/types.d.ts +47 -23
  294. package/lib/modules/Payment/utils.d.ts +1 -1
  295. package/lib/modules/Payment/utils.js +4 -3
  296. package/lib/modules/Payment/walletpass.js +16 -6
  297. package/lib/modules/Product/index.d.ts +1 -1
  298. package/lib/modules/Product/types.d.ts +29 -7
  299. package/lib/modules/ProductList/index.d.ts +17 -13
  300. package/lib/modules/ProductList/index.js +92 -51
  301. package/lib/modules/ProductList/types.d.ts +17 -0
  302. package/lib/modules/Quotation/index.d.ts +22 -2
  303. package/lib/modules/Quotation/index.js +76 -20
  304. package/lib/modules/Quotation/types.d.ts +19 -0
  305. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  306. package/lib/modules/ResourcePlanner/index.js +147 -0
  307. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  308. package/lib/modules/ResourcePlanner/planner.js +895 -0
  309. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  310. package/lib/modules/ResourcePlanner/types.js +5 -0
  311. package/lib/modules/Rules/index.d.ts +8 -10
  312. package/lib/modules/Rules/index.js +153 -61
  313. package/lib/modules/Rules/types.d.ts +15 -4
  314. package/lib/modules/SalesSummary/index.d.ts +23 -26
  315. package/lib/modules/SalesSummary/index.js +84 -16
  316. package/lib/modules/SalesSummary/types.d.ts +9 -1
  317. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  318. package/lib/modules/SalesSummary/utils.js +616 -111
  319. package/lib/modules/ScanOrderLogger/types.d.ts +2 -2
  320. package/lib/modules/Schedule/getDateIsInSchedule.d.ts +1 -1
  321. package/lib/modules/Schedule/getDateIsInSchedule.js +14 -7
  322. package/lib/modules/Schedule/index.d.ts +18 -5
  323. package/lib/modules/Schedule/index.js +49 -14
  324. package/lib/modules/Schedule/type.d.ts +7 -7
  325. package/lib/modules/Schedule/types.d.ts +11 -9
  326. package/lib/modules/Summary/index.js +2 -2
  327. package/lib/modules/SurchargeList/index.d.ts +18 -0
  328. package/lib/modules/SurchargeList/index.js +95 -0
  329. package/lib/modules/SurchargeList/types.d.ts +15 -0
  330. package/lib/modules/SurchargeList/types.js +5 -0
  331. package/lib/modules/index.d.ts +3 -0
  332. package/lib/modules/index.js +33 -0
  333. package/lib/plugins/app.d.ts +2 -0
  334. package/lib/plugins/request.d.ts +3 -2
  335. package/lib/server/index.d.ts +462 -8
  336. package/lib/server/index.js +3901 -205
  337. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  338. package/lib/server/modules/floor-plan/index.js +306 -0
  339. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  340. package/lib/server/modules/floor-plan/types.js +19 -0
  341. package/lib/server/modules/index.d.ts +7 -2
  342. package/lib/server/modules/index.js +21 -0
  343. package/lib/server/modules/menu/types.d.ts +1 -1
  344. package/lib/server/modules/order/index.d.ts +207 -14
  345. package/lib/server/modules/order/index.js +1324 -141
  346. package/lib/server/modules/order/types.d.ts +91 -20
  347. package/lib/server/modules/order/types.js +11 -1
  348. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  349. package/lib/server/modules/order/utils/filterBookings.js +119 -11
  350. package/lib/server/modules/order/utils/filterOrders.js +238 -13
  351. package/lib/server/modules/payment/index.d.ts +28 -0
  352. package/lib/server/modules/payment/index.js +168 -0
  353. package/lib/server/modules/payment/types.d.ts +9 -0
  354. package/lib/server/modules/payment/types.js +5 -0
  355. package/lib/server/modules/products/index.d.ts +105 -14
  356. package/lib/server/modules/products/index.js +588 -97
  357. package/lib/server/modules/products/types.d.ts +35 -2
  358. package/lib/server/modules/products/types.js +3 -0
  359. package/lib/server/modules/quotation/index.d.ts +39 -0
  360. package/lib/server/modules/quotation/index.js +145 -1
  361. package/lib/server/modules/resource/index.d.ts +2 -3
  362. package/lib/server/modules/resource/index.js +71 -45
  363. package/lib/server/modules/resource/types.d.ts +1 -1
  364. package/lib/server/modules/schedule/index.d.ts +6 -4
  365. package/lib/server/modules/schedule/index.js +55 -44
  366. package/lib/server/modules/schedule/utils.d.ts +1 -1
  367. package/lib/server/test.json +713 -0
  368. package/lib/server/types.d.ts +6 -4
  369. package/lib/server/utils/product.js +2 -2
  370. package/lib/server/utils/small-ticket.d.ts +71 -0
  371. package/lib/server/utils/small-ticket.js +926 -0
  372. package/lib/solution/BaseSales/index.d.ts +378 -0
  373. package/lib/solution/BaseSales/index.js +2367 -0
  374. package/lib/solution/BaseSales/types.d.ts +394 -0
  375. package/lib/solution/BaseSales/types.js +47 -0
  376. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  377. package/lib/solution/BaseSales/utils/cartPromotion.js +1155 -0
  378. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  379. package/lib/solution/BaseSales/utils/parseSalesResponse.js +140 -0
  380. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  381. package/lib/solution/BaseSales/utils/quotationPrice.js +231 -0
  382. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  383. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +215 -0
  384. package/lib/solution/BaseSales/utils.d.ts +40 -0
  385. package/lib/solution/BaseSales/utils.js +259 -0
  386. package/lib/solution/BookingByStep/index.d.ts +2 -2
  387. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  388. package/lib/solution/BookingTicket/index.d.ts +382 -25
  389. package/lib/solution/BookingTicket/index.js +1350 -76
  390. package/lib/solution/BookingTicket/types.d.ts +191 -6
  391. package/lib/solution/BookingTicket/types.js +71 -10
  392. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  393. package/lib/solution/BookingTicket/utils/addProductDecision.js +353 -0
  394. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  395. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +94 -0
  396. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  397. package/lib/solution/BookingTicket/utils/bookingStatus.js +136 -0
  398. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  399. package/lib/solution/BookingTicket/utils/cartView.js +200 -0
  400. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  401. package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
  402. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  403. package/lib/solution/BookingTicket/utils/orderCustomer.js +35 -0
  404. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  405. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +387 -0
  406. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  407. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +220 -0
  408. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  409. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +24 -3
  410. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  411. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +64 -0
  412. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  413. package/lib/solution/BookingTicket/utils/scan/handleScan.js +4 -2
  414. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  415. package/lib/solution/BookingTicket/utils/scan/index.js +14 -2
  416. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  417. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +115 -0
  418. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  419. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +83 -0
  420. package/lib/solution/Checkout/index.d.ts +1 -0
  421. package/lib/solution/Checkout/index.js +18 -19
  422. package/lib/solution/Checkout/utils/index.js +4 -4
  423. package/lib/solution/RegisterAndLogin/config.js +2 -10
  424. package/lib/solution/Sales/index.d.ts +50 -5
  425. package/lib/solution/Sales/index.js +296 -39
  426. package/lib/solution/Sales/types.d.ts +29 -5
  427. package/lib/solution/ScanOrder/index.d.ts +27 -21
  428. package/lib/solution/ScanOrder/index.js +144 -103
  429. package/lib/solution/ScanOrder/types.d.ts +38 -16
  430. package/lib/solution/ScanOrder/types.js +4 -5
  431. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  432. package/lib/solution/ScanOrder/utils.js +98 -26
  433. package/lib/solution/ShopDiscount/index.js +3 -3
  434. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  435. package/lib/solution/ShopDiscount/utils.d.ts +2 -2
  436. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  437. package/lib/solution/UnifiedBookingSales/index.js +1050 -0
  438. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  439. package/lib/solution/UnifiedBookingSales/types.js +14 -0
  440. package/lib/solution/VenueBooking/index.d.ts +29 -20
  441. package/lib/solution/VenueBooking/index.js +169 -94
  442. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  443. package/lib/solution/VenueBooking/types.d.ts +1 -1
  444. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  445. package/lib/solution/VenueBooking/utils/slotMerge.js +9 -3
  446. package/lib/solution/index.d.ts +2 -0
  447. package/lib/solution/index.js +22 -0
  448. package/lib/types/index.d.ts +12 -2
  449. package/lib/utils/task.d.ts +2 -2
  450. package/lib/utils/watch.d.ts +2 -2
  451. package/package.json +18 -19
  452. package/dist/model/strategy/adapter/promotion/index.d.ts +0 -4
  453. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  454. package/lib/model/strategy/adapter/promotion/index.d.ts +0 -4
  455. package/lib/solution/Checkout/appointmentDemo.json +0 -1
@@ -1,12 +1,12 @@
1
- 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); }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- 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."); }
4
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
2
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
3
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
9
4
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ 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."); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ 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); }
10
10
  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; }
11
11
  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; }
12
12
  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; } } }; }
@@ -29,17 +29,17 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
29
29
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
30
30
  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); }
31
31
  import { BaseModule } from "../../../modules/BaseModule";
32
- import { RequestModeENUM } from "../../../plugins";
32
+ import { QuotationModule as ClientQuotationModule } from "../../../modules/Quotation";
33
33
  import { ProductsHooks } from "./types";
34
34
  import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProducts, perfMark } from "../../utils/product";
35
-
36
35
  /**
37
36
  * IndexDB 存储名称
38
37
  */
39
38
  var INDEXDB_STORE_NAME = 'products';
40
-
41
39
  /** 商品同步防抖时间(毫秒) */
42
40
  var PRODUCT_SYNC_DEBOUNCE_MS = 10000;
41
+ /** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
42
+ var PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
43
43
 
44
44
  /**
45
45
  * Products 模块 - 用于获取和管理完整的商品详细数据
@@ -68,12 +68,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
68
68
  // 最多缓存7天
69
69
  // 商品格式化器列表
70
70
  _defineProperty(_assertThisInitialized(_this), "formatters", []);
71
- // 是否已注册内置价格格式化器
72
- _defineProperty(_assertThisInitialized(_this), "isPriceFormatterRegistered", false);
71
+ // 是否已注册内置商品格式化器
72
+ _defineProperty(_assertThisInitialized(_this), "isBuiltinFormatterRegistered", false);
73
+ // 旧报价单格式化器默认关闭,仅显式开启时作为兼容兜底注册
74
+ _defineProperty(_assertThisInitialized(_this), "isLegacyPriceFormatterEnabled", false);
75
+ // 普通层 QuotationModule 桥接器:本地计算报价单价格,替代 /product/query/price
76
+ _defineProperty(_assertThisInitialized(_this), "quotationPriceBridge", void 0);
77
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeChannel", void 0);
78
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeLoadedKey", '');
79
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeRefreshPromise", void 0);
80
+ _defineProperty(_assertThisInitialized(_this), "quotationBridgeRefreshKey", void 0);
81
+ _defineProperty(_assertThisInitialized(_this), "quotationScheduleCache", new Map());
82
+ _defineProperty(_assertThisInitialized(_this), "quotationScheduleCacheSource", null);
83
+ _defineProperty(_assertThisInitialized(_this), "quotationScheduleCacheLoaded", false);
73
84
  // ---- 商品数据同步相关 ----
74
85
  _defineProperty(_assertThisInitialized(_this), "productDataSource", void 0);
75
86
  _defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
76
87
  _defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
88
+ /** 最近一次 SSE 全量拉取完成时间 */
89
+ _defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
90
+ /** 最近一次 preload 完成时间(含 IndexDB 命中) */
91
+ _defineProperty(_assertThisInitialized(_this), "lastPreloadCompletedAtMs", 0);
92
+ /** IndexDB 写入串行队列,避免快照与 patch 并发交错 */
93
+ _defineProperty(_assertThisInitialized(_this), "productIndexDBSaveQueue", Promise.resolve());
94
+ /** 最近一次智能定价评估提取的 schedule 变价时间点(HH:mm),供 Server 订阅定时刷新使用 */
95
+ _defineProperty(_assertThisInitialized(_this), "lastScheduleTimePoints", []);
77
96
  return _this;
78
97
  }
79
98
  _createClass(ProductsModule, [{
@@ -110,8 +129,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
110
129
  }
111
130
  }
112
131
 
113
- // 注册内置的价格格式化器(作为第一个格式化器)
114
- this.registerBuiltinPriceFormatter();
132
+ // 注册内置商品格式化器;智能定价默认替代报价单价格逻辑
133
+ this.registerBuiltinProductFormatters();
115
134
 
116
135
  // 初始化 ProductDataSource 实例
117
136
  this.initProductDataSource();
@@ -205,41 +224,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
205
224
  key: "loadProductsPrice",
206
225
  value: (function () {
207
226
  var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
208
- var _ref$ids, ids, customer_id, schedule_date, startTime, _productsData$data$le, _productsData$data, productsData, duration, _duration, errorMessage;
227
+ var _this2 = this;
228
+ var _ref$ids, ids, schedule_date, schedule_datetime, customer_id, startTime, datetime, idSet, products, priceData, duration, _duration, errorMessage;
209
229
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
210
230
  while (1) switch (_context2.prev = _context2.next) {
211
231
  case 0:
212
- _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date;
232
+ _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, schedule_date = _ref.schedule_date, schedule_datetime = _ref.schedule_datetime, customer_id = _ref.customer_id;
213
233
  this.logInfo('开始加载商品价格', {
214
234
  productCount: ids.length,
215
235
  schedule_date: schedule_date,
236
+ schedule_datetime: schedule_datetime,
216
237
  customer_id: customer_id
217
238
  });
218
239
  startTime = Date.now();
219
- _context2.prev = 3;
220
- _context2.next = 6;
221
- return this.request.post("/product/query/price", {
222
- ids: ids,
223
- customer_id: customer_id,
224
- schedule_date: schedule_date
225
- }, {
226
- cache: {
227
- mode: RequestModeENUM.REMOTE_LOCAL,
228
- type: "memory"
229
- }
240
+ datetime = schedule_datetime || schedule_date;
241
+ _context2.prev = 4;
242
+ _context2.next = 7;
243
+ return this.ensureQuotationBridgeReady(customer_id);
244
+ case 7:
245
+ idSet = new Set(ids);
246
+ products = this.getProductsRef().filter(function (product) {
247
+ return idSet.has(product.id);
248
+ });
249
+ priceData = products.map(function (product) {
250
+ return _this2.buildPriceDataFromQuotation(product, datetime, customer_id);
230
251
  });
231
- case 6:
232
- productsData = _context2.sent;
233
252
  duration = Date.now() - startTime;
234
253
  this.logInfo('加载商品价格成功', {
235
254
  productCount: ids.length,
236
- priceDataCount: (_productsData$data$le = (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.length) !== null && _productsData$data$le !== void 0 ? _productsData$data$le : 0,
255
+ priceDataCount: priceData.length,
237
256
  duration: "".concat(duration, "ms")
238
257
  });
239
- return _context2.abrupt("return", productsData.data);
240
- case 12:
241
- _context2.prev = 12;
242
- _context2.t0 = _context2["catch"](3);
258
+ return _context2.abrupt("return", priceData);
259
+ case 15:
260
+ _context2.prev = 15;
261
+ _context2.t0 = _context2["catch"](4);
243
262
  _duration = Date.now() - startTime;
244
263
  errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
245
264
  this.logError('加载商品价格失败', {
@@ -248,17 +267,310 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
248
267
  error: errorMessage
249
268
  });
250
269
  return _context2.abrupt("return", []);
251
- case 18:
270
+ case 21:
252
271
  case "end":
253
272
  return _context2.stop();
254
273
  }
255
- }, _callee2, this, [[3, 12]]);
274
+ }, _callee2, this, [[4, 15]]);
256
275
  }));
257
276
  function loadProductsPrice(_x3) {
258
277
  return _loadProductsPrice.apply(this, arguments);
259
278
  }
260
279
  return loadProductsPrice;
261
280
  }()
281
+ /**
282
+ * 设置报价单价格桥接器。
283
+ * Server 层负责传入完整 schedule 模块,Products 只负责把报价单计算结果转成价格响应形状。
284
+ */
285
+ )
286
+ }, {
287
+ key: "setupQuotationPriceBridge",
288
+ value: (function () {
289
+ var _setupQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
290
+ var _this$otherParams,
291
+ _this3 = this;
292
+ var channel, quotation;
293
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
294
+ while (1) switch (_context3.prev = _context3.next) {
295
+ case 0:
296
+ if (this.core) {
297
+ _context3.next = 3;
298
+ break;
299
+ }
300
+ this.logWarning('setupQuotationPriceBridge: core 尚未初始化');
301
+ return _context3.abrupt("return");
302
+ case 3:
303
+ channel = params.channel || ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel);
304
+ this.quotationBridgeChannel = channel;
305
+ if (this.quotationPriceBridge) {
306
+ _context3.next = 10;
307
+ break;
308
+ }
309
+ quotation = new ClientQuotationModule("".concat(this.name, "_quotation_price_bridge"));
310
+ _context3.next = 9;
311
+ return quotation.initialize(this.core, {});
312
+ case 9:
313
+ this.quotationPriceBridge = quotation;
314
+ case 10:
315
+ if (params.scheduleModule) {
316
+ if (this.quotationScheduleCacheSource !== params.scheduleModule) {
317
+ this.quotationScheduleCache.clear();
318
+ this.quotationScheduleCacheLoaded = false;
319
+ this.quotationScheduleCacheSource = params.scheduleModule;
320
+ }
321
+ this.quotationPriceBridge.setScheduleResolver(function (id) {
322
+ var _params$scheduleModul3, _params$scheduleModul4, _params$scheduleModul5, _params$scheduleModul6;
323
+ var scheduleId = String(id);
324
+ if (_this3.quotationScheduleCache.has(scheduleId)) {
325
+ return _this3.quotationScheduleCache.get(scheduleId);
326
+ }
327
+ if (!_this3.quotationScheduleCacheLoaded) {
328
+ var _params$scheduleModul, _params$scheduleModul2;
329
+ var scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
330
+ var _iterator = _createForOfIteratorHelper(scheduleList),
331
+ _step;
332
+ try {
333
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
334
+ var schedule = _step.value;
335
+ _this3.quotationScheduleCache.set(String(schedule.id), schedule);
336
+ }
337
+ } catch (err) {
338
+ _iterator.e(err);
339
+ } finally {
340
+ _iterator.f();
341
+ }
342
+ _this3.quotationScheduleCacheLoaded = true;
343
+ }
344
+ if (_this3.quotationScheduleCache.has(scheduleId)) {
345
+ return _this3.quotationScheduleCache.get(scheduleId);
346
+ }
347
+ var schedules = ((_params$scheduleModul3 = (_params$scheduleModul4 = params.scheduleModule).getScheduleListByIds) === null || _params$scheduleModul3 === void 0 ? void 0 : _params$scheduleModul3.call(_params$scheduleModul4, [id])) || ((_params$scheduleModul5 = (_params$scheduleModul6 = params.scheduleModule).getScheduleByIds) === null || _params$scheduleModul5 === void 0 ? void 0 : _params$scheduleModul5.call(_params$scheduleModul6, [id])) || [];
348
+ if (schedules[0]) _this3.quotationScheduleCache.set(scheduleId, schedules[0]);
349
+ return schedules[0];
350
+ });
351
+ }
352
+ _context3.next = 13;
353
+ return this.refreshQuotationPriceBridge({
354
+ customer_id: params.customer_id
355
+ });
356
+ case 13:
357
+ case "end":
358
+ return _context3.stop();
359
+ }
360
+ }, _callee3, this);
361
+ }));
362
+ function setupQuotationPriceBridge(_x4) {
363
+ return _setupQuotationPriceBridge.apply(this, arguments);
364
+ }
365
+ return setupQuotationPriceBridge;
366
+ }()
367
+ /**
368
+ * 刷新桥接器内的报价单列表。
369
+ */
370
+ )
371
+ }, {
372
+ key: "refreshQuotationPriceBridge",
373
+ value: (function () {
374
+ var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
375
+ var _this4 = this;
376
+ var refreshKey;
377
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
378
+ while (1) switch (_context4.prev = _context4.next) {
379
+ case 0:
380
+ if (this.quotationPriceBridge) {
381
+ _context4.next = 2;
382
+ break;
383
+ }
384
+ return _context4.abrupt("return");
385
+ case 2:
386
+ refreshKey = this.getQuotationBridgeScopeKey();
387
+ if (!(this.quotationBridgeRefreshPromise && this.quotationBridgeRefreshKey === refreshKey)) {
388
+ _context4.next = 7;
389
+ break;
390
+ }
391
+ _context4.next = 6;
392
+ return this.quotationBridgeRefreshPromise;
393
+ case 6:
394
+ return _context4.abrupt("return");
395
+ case 7:
396
+ if (!this.quotationBridgeRefreshPromise) {
397
+ _context4.next = 10;
398
+ break;
399
+ }
400
+ _context4.next = 10;
401
+ return this.quotationBridgeRefreshPromise;
402
+ case 10:
403
+ this.quotationBridgeRefreshKey = refreshKey;
404
+ this.quotationBridgeRefreshPromise = this.quotationPriceBridge.loadQuotations({
405
+ channel: this.quotationBridgeChannel
406
+ }).then(function () {
407
+ _this4.quotationBridgeLoadedKey = refreshKey;
408
+ }).finally(function () {
409
+ _this4.quotationBridgeRefreshPromise = undefined;
410
+ _this4.quotationBridgeRefreshKey = undefined;
411
+ });
412
+ _context4.next = 14;
413
+ return this.quotationBridgeRefreshPromise;
414
+ case 14:
415
+ case "end":
416
+ return _context4.stop();
417
+ }
418
+ }, _callee4, this);
419
+ }));
420
+ function refreshQuotationPriceBridge(_x5) {
421
+ return _refreshQuotationPriceBridge.apply(this, arguments);
422
+ }
423
+ return refreshQuotationPriceBridge;
424
+ }())
425
+ }, {
426
+ key: "ensureQuotationBridgeReady",
427
+ value: function () {
428
+ var _ensureQuotationBridgeReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(customerId) {
429
+ var _this$otherParams2;
430
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
431
+ while (1) switch (_context5.prev = _context5.next) {
432
+ case 0:
433
+ if (this.quotationPriceBridge) {
434
+ _context5.next = 4;
435
+ break;
436
+ }
437
+ _context5.next = 3;
438
+ return this.setupQuotationPriceBridge({
439
+ channel: (_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.channel,
440
+ customer_id: customerId
441
+ });
442
+ case 3:
443
+ return _context5.abrupt("return");
444
+ case 4:
445
+ if (!this.quotationBridgeRefreshPromise) {
446
+ _context5.next = 7;
447
+ break;
448
+ }
449
+ _context5.next = 7;
450
+ return this.quotationBridgeRefreshPromise;
451
+ case 7:
452
+ if (!(this.getQuotationBridgeScopeKey() !== this.quotationBridgeLoadedKey)) {
453
+ _context5.next = 10;
454
+ break;
455
+ }
456
+ _context5.next = 10;
457
+ return this.refreshQuotationPriceBridge({
458
+ customer_id: customerId
459
+ });
460
+ case 10:
461
+ case "end":
462
+ return _context5.stop();
463
+ }
464
+ }, _callee5, this);
465
+ }));
466
+ function ensureQuotationBridgeReady(_x6) {
467
+ return _ensureQuotationBridgeReady.apply(this, arguments);
468
+ }
469
+ return ensureQuotationBridgeReady;
470
+ }()
471
+ }, {
472
+ key: "getQuotationBridgeScopeKey",
473
+ value: function getQuotationBridgeScopeKey() {
474
+ return this.quotationBridgeChannel || '';
475
+ }
476
+ }, {
477
+ key: "getQuotedPrice",
478
+ value: function getQuotedPrice(params) {
479
+ var quotation = this.quotationPriceBridge;
480
+ if (!quotation) return null;
481
+ var query = {
482
+ productId: params.productId,
483
+ variantId: params.variantId,
484
+ datetime: params.datetime,
485
+ customer_id: params.customerId
486
+ };
487
+ if (typeof quotation.getQuotationMatchForProduct === 'function') {
488
+ var _quotation$getQuotati, _quotation$getQuotati2;
489
+ return (_quotation$getQuotati = (_quotation$getQuotati2 = quotation.getQuotationMatchForProduct(query)) === null || _quotation$getQuotati2 === void 0 ? void 0 : _quotation$getQuotati2.price) !== null && _quotation$getQuotati !== void 0 ? _quotation$getQuotati : null;
490
+ }
491
+ if (typeof quotation.getPriceForProduct === 'function') {
492
+ return quotation.getPriceForProduct(query);
493
+ }
494
+ return null;
495
+ }
496
+ }, {
497
+ key: "buildPriceDataFromQuotation",
498
+ value: function buildPriceDataFromQuotation(product, datetime, customerId) {
499
+ var _ref2, _ref3;
500
+ var quotedPrice = this.getQuotedPrice({
501
+ productId: product.id,
502
+ datetime: datetime,
503
+ customerId: customerId
504
+ });
505
+ var productPrice = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.price;
506
+ var productBasePrice = (_ref2 = (_ref3 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.base_price) !== null && _ref3 !== void 0 ? _ref3 : product.price) !== null && _ref2 !== void 0 ? _ref2 : 0;
507
+ return {
508
+ id: product.id,
509
+ price: String(productPrice !== null && productPrice !== void 0 ? productPrice : 0),
510
+ base_price: String(productBasePrice),
511
+ variant: this.buildVariantPriceData(product, datetime, customerId),
512
+ bundle_group: this.buildBundleGroupPriceData(product, datetime, customerId)
513
+ };
514
+ }
515
+ }, {
516
+ key: "buildVariantPriceData",
517
+ value: function buildVariantPriceData(product, datetime, customerId) {
518
+ var _this5 = this;
519
+ if (!Array.isArray(product.variant)) return [];
520
+ return product.variant.map(function (variant) {
521
+ var _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _variant$product_id;
522
+ var quotedPrice = _this5.getQuotedPrice({
523
+ productId: product.id,
524
+ variantId: Number(variant.id),
525
+ datetime: datetime,
526
+ customerId: customerId
527
+ });
528
+ var price = (_ref4 = (_ref5 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref5 !== void 0 ? _ref5 : product.price) !== null && _ref4 !== void 0 ? _ref4 : 0;
529
+ var basePrice = (_ref6 = (_ref7 = (_ref8 = (_ref9 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.base_price) !== null && _ref9 !== void 0 ? _ref9 : variant.price) !== null && _ref8 !== void 0 ? _ref8 : product.base_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : 0;
530
+ return {
531
+ id: Number(variant.id),
532
+ product_id: Number((_variant$product_id = variant.product_id) !== null && _variant$product_id !== void 0 ? _variant$product_id : product.id),
533
+ base_price: Number(basePrice),
534
+ price: Number(price)
535
+ };
536
+ });
537
+ }
538
+ }, {
539
+ key: "buildBundleGroupPriceData",
540
+ value: function buildBundleGroupPriceData(product, datetime, customerId) {
541
+ var _this6 = this;
542
+ if (!Array.isArray(product.bundle_group)) return [];
543
+ return product.bundle_group.map(function (group) {
544
+ return {
545
+ id: Number(group.id),
546
+ bundle_item: (group.bundle_item || []).map(function (item) {
547
+ var _ref10, _ref11, _ref12, _item$product_id, _item$group_id;
548
+ var bundleProductId = Number(item.bundle_product_id);
549
+ var bundleVariantId = Number(item.bundle_variant_id || 0);
550
+ var quotedPrice = _this6.getQuotedPrice({
551
+ productId: bundleProductId,
552
+ variantId: bundleVariantId,
553
+ datetime: datetime,
554
+ customerId: customerId
555
+ });
556
+ var price = (_ref10 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0;
557
+ var basePrice = (_ref11 = (_ref12 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.base_price) !== null && _ref12 !== void 0 ? _ref12 : item.price) !== null && _ref11 !== void 0 ? _ref11 : 0;
558
+ return {
559
+ id: Number(item.id),
560
+ product_id: Number((_item$product_id = item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : product.id),
561
+ group_id: Number((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : group.id),
562
+ bundle_product_id: bundleProductId,
563
+ bundle_variant_id: bundleVariantId,
564
+ price: Number(price),
565
+ base_price: basePrice,
566
+ price_type: item.price_type,
567
+ price_type_ext: item.price_type_ext
568
+ };
569
+ })
570
+ };
571
+ });
572
+ }
573
+
262
574
  /**
263
575
  * 获取应用了价格的商品列表(带缓存)
264
576
  * 使用日期作为缓存 key,同一天的商品价格会被缓存
@@ -267,27 +579,32 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
267
579
  * @param extraContext 额外的上下文数据(可选,由 Server 层传入)
268
580
  * @param options 可选参数
269
581
  * @param options.changedIds 变更的商品 IDs,非空时仅对这些商品增量执行 prepare 并更新缓存
582
+ * @param options.productIds 指定商品 IDs,仅对这些商品执行价格计算;不传则处理全量
270
583
  * @returns 应用了价格的商品列表
271
584
  */
272
- )
273
585
  }, {
274
586
  key: "getProductsWithPrice",
275
587
  value: (function () {
276
- var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(schedule_date, extraContext, options) {
277
- var t0, cacheKey, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator, _step, p, _iterator2, _step2, _p, errorMessage, result;
278
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
279
- while (1) switch (_context3.prev = _context3.next) {
588
+ var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schedule_date, extraContext, options) {
589
+ var _options$changedIds;
590
+ var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator2, _step2, p, _iterator3, _step3, _p, errorMessage, result;
591
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
592
+ while (1) switch (_context6.prev = _context6.next) {
280
593
  case 0:
281
594
  t0 = performance.now();
282
- cacheKey = schedule_date;
283
- changedIds = options === null || options === void 0 ? void 0 : options.changedIds;
595
+ scopedProductIds = this.normalizeProductIds(options === null || options === void 0 ? void 0 : options.productIds);
596
+ cacheKey = this.getProductsPriceCacheKey(schedule_date, extraContext, scopedProductIds);
597
+ scopedProductIdSet = scopedProductIds ? new Set(scopedProductIds) : undefined;
598
+ changedIds = scopedProductIdSet ? options === null || options === void 0 || (_options$changedIds = options.changedIds) === null || _options$changedIds === void 0 ? void 0 : _options$changedIds.filter(function (id) {
599
+ return scopedProductIdSet.has(id);
600
+ }) : options === null || options === void 0 ? void 0 : options.changedIds;
284
601
  if (!this.productsPriceCache.has(cacheKey)) {
285
- _context3.next = 33;
602
+ _context6.next = 35;
286
603
  break;
287
604
  }
288
605
  cachedProducts = this.productsPriceCache.get(cacheKey); // 有变更的商品 → 增量 prepare 后 merge 回缓存
289
606
  if (!(changedIds && changedIds.length > 0)) {
290
- _context3.next = 30;
607
+ _context6.next = 32;
291
608
  break;
292
609
  }
293
610
  this.logInfo('商品价格缓存命中,增量更新变更商品', {
@@ -295,15 +612,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
295
612
  changedIds: changedIds,
296
613
  cachedProductCount: cachedProducts.length
297
614
  });
298
- _context3.prev = 7;
299
- _context3.next = 10;
615
+ _context6.prev = 9;
616
+ _context6.next = 12;
300
617
  return this.prepareProductsWithPrice(schedule_date, extraContext, {
301
618
  productIds: changedIds
302
619
  });
303
- case 10:
304
- updatedProducts = _context3.sent;
620
+ case 12:
621
+ updatedProducts = _context6.sent;
305
622
  if (!(updatedProducts.length > 0)) {
306
- _context3.next = 22;
623
+ _context6.next = 24;
307
624
  break;
308
625
  }
309
626
  // merge:用更新结果替换缓存中对应的商品,新增的追加
@@ -311,10 +628,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
311
628
  return [p.id, p];
312
629
  }));
313
630
  mergedCache = [];
314
- _iterator = _createForOfIteratorHelper(cachedProducts);
631
+ _iterator2 = _createForOfIteratorHelper(cachedProducts);
315
632
  try {
316
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
317
- p = _step.value;
633
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
634
+ p = _step2.value;
318
635
  if (updatedMap.has(p.id)) {
319
636
  mergedCache.push(updatedMap.get(p.id));
320
637
  updatedMap.delete(p.id);
@@ -324,20 +641,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
324
641
  }
325
642
  // 剩余的是新增商品(create 场景)
326
643
  } catch (err) {
327
- _iterator.e(err);
644
+ _iterator2.e(err);
328
645
  } finally {
329
- _iterator.f();
646
+ _iterator2.f();
330
647
  }
331
- _iterator2 = _createForOfIteratorHelper(updatedMap.values());
648
+ _iterator3 = _createForOfIteratorHelper(updatedMap.values());
332
649
  try {
333
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
334
- _p = _step2.value;
650
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
651
+ _p = _step3.value;
335
652
  mergedCache.push(_p);
336
653
  }
337
654
  } catch (err) {
338
- _iterator2.e(err);
655
+ _iterator3.e(err);
339
656
  } finally {
340
- _iterator2.f();
657
+ _iterator3.f();
341
658
  }
342
659
  this.productsPriceCache.set(cacheKey, mergedCache);
343
660
  this.logInfo('增量更新完成', {
@@ -350,27 +667,27 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
350
667
  changedCount: changedIds.length,
351
668
  count: mergedCache.length
352
669
  });
353
- return _context3.abrupt("return", mergedCache);
354
- case 22:
355
- _context3.next = 28;
356
- break;
670
+ return _context6.abrupt("return", mergedCache);
357
671
  case 24:
358
- _context3.prev = 24;
359
- _context3.t0 = _context3["catch"](7);
360
- errorMessage = _context3.t0 instanceof Error ? _context3.t0.message : String(_context3.t0);
672
+ _context6.next = 30;
673
+ break;
674
+ case 26:
675
+ _context6.prev = 26;
676
+ _context6.t0 = _context6["catch"](9);
677
+ errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
361
678
  this.logError('增量更新失败,返回现有缓存', {
362
679
  cacheKey: cacheKey,
363
680
  changedIds: changedIds,
364
681
  error: errorMessage
365
682
  });
366
- case 28:
683
+ case 30:
367
684
  perfMark('getProductsWithPrice(incrementalUpdate)', performance.now() - t0, {
368
685
  cacheKey: cacheKey,
369
686
  changedCount: changedIds.length,
370
687
  count: cachedProducts.length
371
688
  });
372
- return _context3.abrupt("return", cachedProducts);
373
- case 30:
689
+ return _context6.abrupt("return", cachedProducts);
690
+ case 32:
374
691
  perfMark('getProductsWithPrice(cacheHit)', performance.now() - t0, {
375
692
  cacheKey: cacheKey,
376
693
  count: cachedProducts.length
@@ -379,15 +696,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
379
696
  cacheKey: cacheKey,
380
697
  productCount: cachedProducts.length
381
698
  });
382
- return _context3.abrupt("return", cachedProducts);
383
- case 33:
699
+ return _context6.abrupt("return", cachedProducts);
700
+ case 35:
384
701
  this.logInfo('商品价格缓存未命中,准备获取', {
385
- cacheKey: cacheKey
702
+ cacheKey: cacheKey,
703
+ scopedProductCount: scopedProductIds === null || scopedProductIds === void 0 ? void 0 : scopedProductIds.length
386
704
  });
387
- _context3.next = 36;
388
- return this.prepareProductsWithPrice(schedule_date, extraContext);
389
- case 36:
390
- result = _context3.sent;
705
+ _context6.next = 38;
706
+ return this.prepareProductsWithPrice(schedule_date, extraContext, scopedProductIds ? {
707
+ productIds: scopedProductIds
708
+ } : undefined);
709
+ case 38:
710
+ result = _context6.sent;
391
711
  this.productsPriceCache.set(cacheKey, result);
392
712
  this.logInfo('商品价格已缓存', {
393
713
  cacheKey: cacheKey,
@@ -398,14 +718,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
398
718
  cacheKey: cacheKey,
399
719
  count: result.length
400
720
  });
401
- return _context3.abrupt("return", result);
402
- case 42:
721
+ return _context6.abrupt("return", result);
722
+ case 44:
403
723
  case "end":
404
- return _context3.stop();
724
+ return _context6.stop();
405
725
  }
406
- }, _callee3, this, [[7, 24]]);
726
+ }, _callee6, this, [[9, 26]]);
407
727
  }));
408
- function getProductsWithPrice(_x4, _x5, _x6) {
728
+ function getProductsWithPrice(_x7, _x8, _x9) {
409
729
  return _getProductsWithPrice.apply(this, arguments);
410
730
  }
411
731
  return getProductsWithPrice;
@@ -423,27 +743,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
423
743
  }, {
424
744
  key: "prepareProductsWithPrice",
425
745
  value: (function () {
426
- var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(schedule_date, extraContext, options) {
427
- var tTotal, targetIds, isIncremental, _priceData$length, _this$core, products, ids, idSet, tIds, i, tPrice, priceData, context, tFormat, processedProducts, errorMessage;
428
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
429
- while (1) switch (_context4.prev = _context4.next) {
746
+ var _prepareProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(schedule_date, extraContext, options) {
747
+ var tTotal, targetIds, isIncremental, _this$core, _this$core2, products, ids, tIds, i, priceData, _priceData$length, _priceData, tPrice, context, tFormat, processedProducts, errorMessage;
748
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
749
+ while (1) switch (_context7.prev = _context7.next) {
430
750
  case 0:
431
751
  tTotal = performance.now();
432
752
  targetIds = options === null || options === void 0 ? void 0 : options.productIds;
433
- isIncremental = targetIds && targetIds.length > 0;
753
+ isIncremental = Array.isArray(targetIds);
434
754
  this.logInfo('prepareProductsWithPrice 开始处理', {
435
755
  schedule_date: schedule_date,
436
756
  mode: isIncremental ? 'incremental' : 'full',
437
757
  targetIdsCount: targetIds === null || targetIds === void 0 ? void 0 : targetIds.length
438
758
  });
439
- _context4.prev = 4;
759
+ _context7.prev = 4;
440
760
  // 1. 获取商品列表:指定 IDs 时从 store 取子集,否则取全量
441
761
 
442
762
  if (isIncremental) {
443
- idSet = new Set(targetIds);
444
- products = this.getProductsRef().filter(function (p) {
445
- return idSet.has(p.id);
446
- });
763
+ products = this.getProductsRefByIds(targetIds);
447
764
  ids = products.map(function (p) {
448
765
  return p.id;
449
766
  });
@@ -462,31 +779,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
462
779
  productCount: products.length
463
780
  });
464
781
 
465
- // 2. 获取价格数据(网络请求)
782
+ // 2. 仅在 legacy 报价单 formatter 启用时加载报价单价格;默认由智能定价覆盖商品价格。
783
+ priceData = [];
784
+ if (!this.isLegacyPriceFormatterEnabled) {
785
+ _context7.next = 15;
786
+ break;
787
+ }
466
788
  tPrice = performance.now();
467
- _context4.next = 10;
789
+ _context7.next = 12;
468
790
  return this.loadProductsPrice({
469
791
  ids: ids,
470
- schedule_date: schedule_date
792
+ schedule_date: schedule_date,
793
+ schedule_datetime: extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime,
794
+ customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id
471
795
  });
472
- case 10:
473
- priceData = _context4.sent;
796
+ case 12:
797
+ priceData = _context7.sent;
474
798
  perfMark('prepareProducts.loadPrice', performance.now() - tPrice, {
475
799
  count: ids.length
476
800
  });
477
801
  this.logInfo('获取商品报价单价格成功', {
478
- priceDataCount: (_priceData$length = priceData === null || priceData === void 0 ? void 0 : priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
802
+ priceDataCount: (_priceData$length = (_priceData = priceData) === null || _priceData === void 0 ? void 0 : _priceData.length) !== null && _priceData$length !== void 0 ? _priceData$length : 0
479
803
  });
804
+ case 15:
480
805
  context = _objectSpread({
481
806
  schedule_date: schedule_date,
807
+ schedule_datetime: extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime,
808
+ customer_id: extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id,
482
809
  priceData: priceData,
483
- locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale
810
+ locale: (_this$core = this.core) === null || _this$core === void 0 || (_this$core = _this$core.context) === null || _this$core === void 0 ? void 0 : _this$core.locale,
811
+ dataVariantEvaluator: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.dataVariantEvaluator) || ((_this$core2 = this.core) === null || _this$core2 === void 0 || (_this$core2 = _this$core2.context) === null || _this$core2 === void 0 ? void 0 : _this$core2.dataVariantEvaluator),
812
+ menuList: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.menuList) || [],
813
+ scheduleList: (extraContext === null || extraContext === void 0 ? void 0 : extraContext.scheduleList) || [],
814
+ strategy_context: extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context
484
815
  }, extraContext); // 3. 通过格式化器流程处理商品
485
816
  tFormat = performance.now();
486
- _context4.next = 17;
817
+ _context7.next = 19;
487
818
  return this.applyFormatters(products, context);
488
- case 17:
489
- processedProducts = _context4.sent;
819
+ case 19:
820
+ processedProducts = _context7.sent;
490
821
  perfMark('prepareProducts.applyFormatters', performance.now() - tFormat, {
491
822
  count: products.length,
492
823
  formatterCount: this.formatters.length
@@ -498,39 +829,129 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
498
829
  formatterCount: this.formatters.length
499
830
  });
500
831
  if (isIncremental) {
501
- _context4.next = 23;
832
+ _context7.next = 25;
502
833
  break;
503
834
  }
504
- _context4.next = 23;
835
+ _context7.next = 25;
505
836
  return this.core.effects.emit(ProductsHooks.onProductsPriceApplied, processedProducts);
506
- case 23:
837
+ case 25:
507
838
  perfMark('prepareProductsWithPrice', performance.now() - tTotal, {
508
839
  productCount: products.length,
509
840
  formatterCount: this.formatters.length,
510
841
  mode: isIncremental ? 'incremental' : 'full'
511
842
  });
512
- return _context4.abrupt("return", processedProducts);
513
- case 27:
514
- _context4.prev = 27;
515
- _context4.t0 = _context4["catch"](4);
516
- errorMessage = _context4.t0 instanceof Error ? _context4.t0.message : String(_context4.t0);
843
+ return _context7.abrupt("return", processedProducts);
844
+ case 29:
845
+ _context7.prev = 29;
846
+ _context7.t0 = _context7["catch"](4);
847
+ errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
517
848
  this.logError('prepareProductsWithPrice 处理失败', {
518
849
  schedule_date: schedule_date,
519
850
  error: errorMessage
520
851
  });
521
- case 31:
522
- return _context4.abrupt("return", []);
523
- case 32:
852
+ case 33:
853
+ return _context7.abrupt("return", []);
854
+ case 34:
524
855
  case "end":
525
- return _context4.stop();
856
+ return _context7.stop();
526
857
  }
527
- }, _callee4, this, [[4, 27]]);
858
+ }, _callee7, this, [[4, 29]]);
528
859
  }));
529
- function prepareProductsWithPrice(_x7, _x8, _x9) {
860
+ function prepareProductsWithPrice(_x10, _x11, _x12) {
530
861
  return _prepareProductsWithPrice.apply(this, arguments);
531
862
  }
532
863
  return prepareProductsWithPrice;
533
- }()
864
+ }())
865
+ }, {
866
+ key: "getProductsPriceCacheKey",
867
+ value: function getProductsPriceCacheKey(schedule_date, extraContext, productIds) {
868
+ var _extraContext$custome;
869
+ var datetime = (extraContext === null || extraContext === void 0 ? void 0 : extraContext.schedule_datetime) || schedule_date;
870
+ var productScope = productIds ? ":products:".concat(productIds.join(',')) : '';
871
+ var strategyScope = this.stringifyStable((extraContext === null || extraContext === void 0 ? void 0 : extraContext.strategy_context) || {});
872
+ return "".concat(datetime, ":customer:").concat((_extraContext$custome = extraContext === null || extraContext === void 0 ? void 0 : extraContext.customer_id) !== null && _extraContext$custome !== void 0 ? _extraContext$custome : '', ":strategy:").concat(strategyScope).concat(productScope);
873
+ }
874
+
875
+ /**
876
+ * 稳定序列化策略上下文,避免对象 key 顺序不同导致缓存 key 抖动。
877
+ */
878
+ }, {
879
+ key: "stringifyStable",
880
+ value: function stringifyStable(value) {
881
+ var _this7 = this;
882
+ if (value == null) return '';
883
+ if (Array.isArray(value)) return "[".concat(value.map(function (item) {
884
+ return _this7.stringifyStable(item);
885
+ }).join(','), "]");
886
+ if (_typeof(value) === 'object') {
887
+ return "{".concat(Object.keys(value).sort().map(function (key) {
888
+ return "".concat(key, ":").concat(_this7.stringifyStable(value[key]));
889
+ }).join(','), "}");
890
+ }
891
+ return String(value);
892
+ }
893
+ }, {
894
+ key: "normalizeProductIds",
895
+ value: function normalizeProductIds(productIds) {
896
+ if (!Array.isArray(productIds)) return undefined;
897
+ return Array.from(new Set(productIds.map(function (id) {
898
+ return Number(id);
899
+ }).filter(function (id) {
900
+ return Number.isFinite(id);
901
+ }))).sort(function (a, b) {
902
+ return a - b;
903
+ });
904
+ }
905
+
906
+ /**
907
+ * 按轻量范围返回商品 ID,不做 structuredClone。
908
+ */
909
+ }, {
910
+ key: "getProductIdsByScope",
911
+ value: function getProductIdsByScope(scope) {
912
+ var productIds = this.normalizeProductIds(scope.productIds) || [];
913
+ var collectionIds = this.normalizeProductIds(scope.collectionIds) || [];
914
+ if (scope.isAllProducts) {
915
+ return this.getProductsRef().map(function (product) {
916
+ return product.id;
917
+ });
918
+ }
919
+ if (productIds.length === 0 && collectionIds.length === 0) return [];
920
+ var result = new Set();
921
+ var _iterator4 = _createForOfIteratorHelper(productIds),
922
+ _step4;
923
+ try {
924
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
925
+ var id = _step4.value;
926
+ if (this.store.map.has(id)) result.add(id);
927
+ }
928
+ } catch (err) {
929
+ _iterator4.e(err);
930
+ } finally {
931
+ _iterator4.f();
932
+ }
933
+ if (collectionIds.length === 0) return Array.from(result);
934
+ var collectionIdSet = new Set(collectionIds);
935
+ var _iterator5 = _createForOfIteratorHelper(this.getProductsRef()),
936
+ _step5;
937
+ try {
938
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
939
+ var product = _step5.value;
940
+ if (result.has(product.id)) continue;
941
+ if (!Array.isArray(product.collection)) continue;
942
+ var isInCollection = product.collection.some(function (collection) {
943
+ return collectionIdSet.has(collection.id);
944
+ });
945
+ if (isInCollection) result.add(product.id);
946
+ }
947
+ } catch (err) {
948
+ _iterator5.e(err);
949
+ } finally {
950
+ _iterator5.f();
951
+ }
952
+ return Array.from(result);
953
+ }
954
+
534
955
  /**
535
956
  * 应用所有已注册的格式化器
536
957
  * @param products 商品列表
@@ -538,25 +959,24 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
538
959
  * @returns 格式化后的商品列表
539
960
  * @private
540
961
  */
541
- )
542
962
  }, {
543
963
  key: "applyFormatters",
544
964
  value: (function () {
545
- var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products, context) {
965
+ var _applyFormatters = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(products, context) {
546
966
  var result, i, formatter, tF, errorMessage;
547
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
548
- while (1) switch (_context5.prev = _context5.next) {
967
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
968
+ while (1) switch (_context8.prev = _context8.next) {
549
969
  case 0:
550
970
  result = products;
551
971
  if (!(this.formatters.length === 0)) {
552
- _context5.next = 5;
972
+ _context8.next = 5;
553
973
  break;
554
974
  }
555
975
  console.warn('[ProductsModule] ⚠️ 没有注册任何格式化器');
556
976
  this.logWarning('没有注册任何格式化器', {
557
977
  productCount: products.length
558
978
  });
559
- return _context5.abrupt("return", result);
979
+ return _context8.abrupt("return", result);
560
980
  case 5:
561
981
  this.logInfo('开始应用格式化器', {
562
982
  productCount: products.length,
@@ -565,28 +985,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
565
985
  i = 0;
566
986
  case 7:
567
987
  if (!(i < this.formatters.length)) {
568
- _context5.next = 25;
988
+ _context8.next = 25;
569
989
  break;
570
990
  }
571
991
  formatter = this.formatters[i];
572
- _context5.prev = 9;
992
+ _context8.prev = 9;
573
993
  tF = performance.now();
574
- _context5.next = 13;
994
+ _context8.next = 13;
575
995
  return formatter(result, context);
576
996
  case 13:
577
- result = _context5.sent;
997
+ result = _context8.sent;
578
998
  perfMark("applyFormatters[".concat(i, "]"), performance.now() - tF, {
579
999
  index: i,
580
1000
  total: this.formatters.length,
581
1001
  productCount: result.length
582
1002
  });
583
- _context5.next = 22;
1003
+ _context8.next = 22;
584
1004
  break;
585
1005
  case 17:
586
- _context5.prev = 17;
587
- _context5.t0 = _context5["catch"](9);
588
- errorMessage = _context5.t0 instanceof Error ? _context5.t0.message : String(_context5.t0);
589
- console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context5.t0);
1006
+ _context8.prev = 17;
1007
+ _context8.t0 = _context8["catch"](9);
1008
+ errorMessage = _context8.t0 instanceof Error ? _context8.t0.message : String(_context8.t0);
1009
+ console.error("[ProductsModule] \u274C \u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25:"), _context8.t0);
590
1010
  this.logError("\u683C\u5F0F\u5316\u5668 ".concat(i + 1, " \u6267\u884C\u5931\u8D25"), {
591
1011
  formatterIndex: i + 1,
592
1012
  totalFormatters: this.formatters.length,
@@ -594,41 +1014,71 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
594
1014
  });
595
1015
  case 22:
596
1016
  i++;
597
- _context5.next = 7;
1017
+ _context8.next = 7;
598
1018
  break;
599
1019
  case 25:
600
1020
  this.logInfo('所有格式化器已应用', {
601
1021
  formatterCount: this.formatters.length,
602
1022
  resultProductCount: result.length
603
1023
  });
604
- return _context5.abrupt("return", result);
1024
+ return _context8.abrupt("return", result);
605
1025
  case 27:
606
1026
  case "end":
607
- return _context5.stop();
1027
+ return _context8.stop();
608
1028
  }
609
- }, _callee5, this, [[9, 17]]);
1029
+ }, _callee8, this, [[9, 17]]);
610
1030
  }));
611
- function applyFormatters(_x10, _x11) {
1031
+ function applyFormatters(_x13, _x14) {
612
1032
  return _applyFormatters.apply(this, arguments);
613
1033
  }
614
1034
  return applyFormatters;
615
1035
  }()
616
1036
  /**
617
- * 注册内置的价格格式化器
618
- * 这个格式化器负责将价格数据应用到商品上
1037
+ * 注册内置商品格式化器。
1038
+ *
1039
+ * 智能定价默认替代报价单逻辑;报价单 formatter 仅在 enableLegacyPriceFormatter=true 时启用。
619
1040
  * @private
620
1041
  */
621
1042
  )
622
1043
  }, {
623
- key: "registerBuiltinPriceFormatter",
624
- value: function registerBuiltinPriceFormatter() {
625
- if (this.isPriceFormatterRegistered) {
626
- console.warn('[ProductsModule] 内置价格格式化器已注册,跳过');
1044
+ key: "registerBuiltinProductFormatters",
1045
+ value: function registerBuiltinProductFormatters() {
1046
+ var _this8 = this;
1047
+ if (this.isBuiltinFormatterRegistered) {
1048
+ console.warn('[ProductsModule] 内置商品格式化器已注册,跳过');
627
1049
  return;
628
1050
  }
1051
+ this.isLegacyPriceFormatterEnabled = this.shouldEnableLegacyPriceFormatter();
1052
+ var dataVariantFormatter = function dataVariantFormatter(products, context) {
1053
+ var _this8$core, _strategyContext$busi;
1054
+ var evaluator = context.dataVariantEvaluator || ((_this8$core = _this8.core) === null || _this8$core === void 0 || (_this8$core = _this8$core.context) === null || _this8$core === void 0 ? void 0 : _this8$core.dataVariantEvaluator);
1055
+ if (!evaluator || typeof evaluator.resolveProducts !== 'function') {
1056
+ _this8.lastScheduleTimePoints = [];
1057
+ _this8.logWarning('智能定价评估器未注入,跳过 DataVariant 格式化', {
1058
+ productCount: products.length
1059
+ });
1060
+ return products;
1061
+ }
1062
+ var strategyContext = context.strategy_context || {};
1063
+ var businessData = {
1064
+ products: products,
1065
+ scheduleDateTime: context.schedule_datetime || context.schedule_date,
1066
+ scheduleList: context.scheduleList || [],
1067
+ menuList: context.menuList || [],
1068
+ customerId: context.customer_id,
1069
+ channel: strategyContext.channel,
1070
+ orderType: strategyContext.orderType || strategyContext.order_type,
1071
+ businessCode: (_strategyContext$busi = strategyContext.business_code) !== null && _strategyContext$busi !== void 0 ? _strategyContext$busi : strategyContext.businessCode,
1072
+ availableWalletIds: strategyContext.available_wallet_ids,
1073
+ custom: strategyContext
1074
+ };
1075
+ var result = evaluator.resolveProducts(businessData);
1076
+ _this8.lastScheduleTimePoints = Array.isArray(result === null || result === void 0 ? void 0 : result.scheduleTimePoints) ? _toConsumableArray(result.scheduleTimePoints) : [];
1077
+ return Array.isArray(result === null || result === void 0 ? void 0 : result.products) ? result.products : products;
1078
+ };
629
1079
 
630
- // 创建价格格式化器
631
- var priceFormatter = function priceFormatter(products, context) {
1080
+ // 创建 legacy 报价单格式化器
1081
+ var legacyPriceFormatter = function legacyPriceFormatter(products, context) {
632
1082
  if (!context.priceData || context.priceData.length === 0) {
633
1083
  return products;
634
1084
  }
@@ -640,17 +1090,40 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
640
1090
  var detailValueFormatter = function detailValueFormatter(products, context) {
641
1091
  return applyDetailValueToProducts(products, context);
642
1092
  };
643
-
644
- // 将价格格式化器注册为第一个格式化器
645
- this.formatters.unshift(priceFormatter);
1093
+ if (this.isLegacyPriceFormatterEnabled) {
1094
+ this.formatters.push(legacyPriceFormatter);
1095
+ }
1096
+ this.formatters.push(dataVariantFormatter);
646
1097
  this.formatters.push(i18nFormatter);
647
1098
  this.formatters.push(detailValueFormatter);
648
- this.isPriceFormatterRegistered = true;
1099
+ this.isBuiltinFormatterRegistered = true;
1100
+ }
1101
+
1102
+ /**
1103
+ * 是否启用旧报价单价格 formatter。
1104
+ *
1105
+ * 默认关闭,避免报价单逻辑覆盖智能定价结果。
1106
+ */
1107
+ }, {
1108
+ key: "shouldEnableLegacyPriceFormatter",
1109
+ value: function shouldEnableLegacyPriceFormatter() {
1110
+ var _this$otherParams3, _this$core3;
1111
+ return ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.enableLegacyPriceFormatter) === true || ((_this$core3 = this.core) === null || _this$core3 === void 0 || (_this$core3 = _this$core3.context) === null || _this$core3 === void 0 ? void 0 : _this$core3.enableLegacyPriceFormatter) === true;
1112
+ }
1113
+
1114
+ /**
1115
+ * 返回最近一次 prepareProductsWithPrice / DataVariant 评估提取的变价时间点(HH:mm)。
1116
+ * 供 OS Server 商品 query 订阅定时刷新使用。
1117
+ */
1118
+ }, {
1119
+ key: "getLastScheduleTimePoints",
1120
+ value: function getLastScheduleTimePoints() {
1121
+ return _toConsumableArray(this.lastScheduleTimePoints);
649
1122
  }
650
1123
 
651
1124
  /**
652
1125
  * 注册商品格式化器
653
- * 格式化器会按注册顺序依次执行(内置价格格式化器始终是第一个)
1126
+ * 格式化器会按注册顺序依次执行;legacy 启用时先兜底报价,再由智能定价覆盖。
654
1127
  * @param formatter 格式化函数
655
1128
  * @param prepend 是否插入到队列开头(默认 false,追加到末尾)
656
1129
  * @example
@@ -668,8 +1141,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
668
1141
  value: function registerFormatter(formatter) {
669
1142
  var prepend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
670
1143
  if (prepend) {
671
- // 插入到价格格式化器之后(索引 1 的位置)
672
- var insertIndex = this.isPriceFormatterRegistered ? 1 : 0;
1144
+ // 插入到内置智能定价格式化器之后;legacy 报价单启用时需跳过它。
1145
+ var insertIndex = this.isBuiltinFormatterRegistered ? this.isLegacyPriceFormatterEnabled ? 2 : 1 : 0;
673
1146
  this.formatters.splice(insertIndex, 0, formatter);
674
1147
  } else {
675
1148
  // 追加到末尾
@@ -678,19 +1151,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
678
1151
  }
679
1152
 
680
1153
  /**
681
- * 清空所有格式化器(包括内置价格格式化器)
682
- * @param keepBuiltin 是否保留内置价格格式化器(默认 true)
1154
+ * 清空所有格式化器(包括内置智能定价格式化器)
1155
+ * @param keepBuiltin 是否保留内置智能定价格式化器(默认 true)
683
1156
  */
684
1157
  }, {
685
1158
  key: "clearFormatters",
686
1159
  value: function clearFormatters() {
687
1160
  var keepBuiltin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
688
- if (keepBuiltin && this.isPriceFormatterRegistered) {
689
- // 只保留第一个格式化器(内置价格格式化器)
690
- this.formatters = [this.formatters[0]];
1161
+ if (keepBuiltin && this.isBuiltinFormatterRegistered) {
1162
+ // 保留 legacy 兜底(如果启用)和智能定价格式化器。
1163
+ var builtinCount = this.isLegacyPriceFormatterEnabled ? 2 : 1;
1164
+ this.formatters = this.formatters.slice(0, builtinCount);
691
1165
  } else {
692
1166
  this.formatters = [];
693
- this.isPriceFormatterRegistered = false;
1167
+ this.isBuiltinFormatterRegistered = false;
694
1168
  }
695
1169
  }
696
1170
 
@@ -725,28 +1199,28 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
725
1199
  }, {
726
1200
  key: "loadProductsByServer",
727
1201
  value: (function () {
728
- var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1202
+ var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
729
1203
  var t0, tSSE, productList, list, duration, errorMessage;
730
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
731
- while (1) switch (_context6.prev = _context6.next) {
1204
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
1205
+ while (1) switch (_context9.prev = _context9.next) {
732
1206
  case 0:
733
1207
  if (this.productDataSource) {
734
- _context6.next = 3;
1208
+ _context9.next = 3;
735
1209
  break;
736
1210
  }
737
1211
  this.logWarning('loadProductsByServer: ProductDataSource 不可用');
738
- return _context6.abrupt("return", []);
1212
+ return _context9.abrupt("return", []);
739
1213
  case 3:
740
1214
  this.logInfo('开始通过 DataSource SSE 加载商品列表');
741
1215
  t0 = performance.now();
742
- _context6.prev = 5;
1216
+ _context9.prev = 5;
743
1217
  tSSE = performance.now();
744
- _context6.next = 9;
1218
+ _context9.next = 9;
745
1219
  return this.productDataSource.run({
746
1220
  sse: {}
747
1221
  });
748
1222
  case 9:
749
- productList = _context6.sent;
1223
+ productList = _context9.sent;
750
1224
  list = productList || [];
751
1225
  perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
752
1226
  count: list.length
@@ -755,32 +1229,33 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
755
1229
  productCount: list.length,
756
1230
  duration: "".concat(Math.round(performance.now() - t0), "ms")
757
1231
  });
758
- _context6.next = 15;
759
- return this.saveProductsToIndexDB(list);
1232
+ _context9.next = 15;
1233
+ return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
760
1234
  case 15:
761
- _context6.next = 17;
1235
+ this.lastServerFullFetchAtMs = Date.now();
1236
+ _context9.next = 18;
762
1237
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
763
- case 17:
1238
+ case 18:
764
1239
  perfMark('loadProductsByServer', performance.now() - t0, {
765
1240
  count: list.length
766
1241
  });
767
- return _context6.abrupt("return", list);
768
- case 21:
769
- _context6.prev = 21;
770
- _context6.t0 = _context6["catch"](5);
1242
+ return _context9.abrupt("return", list);
1243
+ case 22:
1244
+ _context9.prev = 22;
1245
+ _context9.t0 = _context9["catch"](5);
771
1246
  duration = Math.round(performance.now() - t0);
772
- errorMessage = _context6.t0 instanceof Error ? _context6.t0.message : String(_context6.t0);
773
- console.error('[Products] 加载商品数据失败:', _context6.t0);
1247
+ errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
1248
+ console.error('[Products] 加载商品数据失败:', _context9.t0);
774
1249
  this.logError('通过 DataSource SSE 加载商品列表失败', {
775
1250
  duration: "".concat(duration, "ms"),
776
1251
  error: errorMessage
777
1252
  });
778
- return _context6.abrupt("return", []);
779
- case 28:
1253
+ return _context9.abrupt("return", []);
1254
+ case 29:
780
1255
  case "end":
781
- return _context6.stop();
1256
+ return _context9.stop();
782
1257
  }
783
- }, _callee6, this, [[5, 21]]);
1258
+ }, _callee9, this, [[5, 22]]);
784
1259
  }));
785
1260
  function loadProductsByServer() {
786
1261
  return _loadProductsByServer.apply(this, arguments);
@@ -796,12 +1271,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
796
1271
  }, {
797
1272
  key: "fetchProductsByHttp",
798
1273
  value: (function () {
799
- var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
800
- var _ref2, _ref2$category_ids, category_ids, _ref2$product_ids, product_ids, _ref2$collection, collection, customer_id, cacheId, startTime, _this$otherParams, _productsData$data2, productsData, productList, duration, _duration2, errorMessage;
801
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
802
- while (1) switch (_context7.prev = _context7.next) {
1274
+ var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
1275
+ var _ref13, _ref13$category_ids, category_ids, _ref13$product_ids, product_ids, _ref13$collection, collection, customer_id, cacheId, startTime, _this$otherParams4, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
1276
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1277
+ while (1) switch (_context10.prev = _context10.next) {
803
1278
  case 0:
804
- _ref2 = params || {}, _ref2$category_ids = _ref2.category_ids, category_ids = _ref2$category_ids === void 0 ? [] : _ref2$category_ids, _ref2$product_ids = _ref2.product_ids, product_ids = _ref2$product_ids === void 0 ? [] : _ref2$product_ids, _ref2$collection = _ref2.collection, collection = _ref2$collection === void 0 ? [] : _ref2$collection, customer_id = _ref2.customer_id, cacheId = _ref2.cacheId;
1279
+ _ref13 = params || {}, _ref13$category_ids = _ref13.category_ids, category_ids = _ref13$category_ids === void 0 ? [] : _ref13$category_ids, _ref13$product_ids = _ref13.product_ids, product_ids = _ref13$product_ids === void 0 ? [] : _ref13$product_ids, _ref13$collection = _ref13.collection, collection = _ref13$collection === void 0 ? [] : _ref13$collection, customer_id = _ref13.customer_id, cacheId = _ref13.cacheId;
805
1280
  this.logInfo('fetchProductsByHttp: 开始请求', {
806
1281
  categoryIdsCount: category_ids.length,
807
1282
  productIdsCount: product_ids.length,
@@ -809,13 +1284,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
809
1284
  customer_id: customer_id
810
1285
  });
811
1286
  startTime = Date.now();
812
- _context7.prev = 3;
813
- _context7.next = 6;
1287
+ _context10.prev = 3;
1288
+ _context10.next = 6;
814
1289
  return this.request.post("/product/query", {
815
1290
  open_bundle: 1,
816
1291
  exclude_extension_type: ['product_party', 'product_event', 'product_series_event', 'product_package_ticket', 'ticket', 'event_item'],
817
1292
  force_ignore_cache_flag: 1,
818
- with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem'],
1293
+ with: ['category', 'collection', 'resourceRelation', 'bundleGroup.bundleItem', 'optionGroup.optionItem', 'variantGroup.variantItem', 'dataVariants'],
819
1294
  open_deposit: 1,
820
1295
  is_append_product_description: 1,
821
1296
  with_count: ['bundleGroup', 'optionGroup'],
@@ -827,37 +1302,37 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
827
1302
  ids: product_ids,
828
1303
  collection: collection,
829
1304
  front_end_cache_id: cacheId,
830
- application_code: (_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 ? void 0 : _this$otherParams.channel
1305
+ application_code: (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.channel
831
1306
  }, {
832
1307
  cache: undefined
833
1308
  });
834
1309
  case 6:
835
- productsData = _context7.sent;
836
- productList = (productsData === null || productsData === void 0 || (_productsData$data2 = productsData.data) === null || _productsData$data2 === void 0 ? void 0 : _productsData$data2.list) || [];
1310
+ productsData = _context10.sent;
1311
+ productList = (productsData === null || productsData === void 0 || (_productsData$data = productsData.data) === null || _productsData$data === void 0 ? void 0 : _productsData$data.list) || [];
837
1312
  duration = Date.now() - startTime;
838
1313
  this.logInfo('fetchProductsByHttp: 请求成功', {
839
1314
  productCount: productList.length,
840
1315
  duration: "".concat(duration, "ms")
841
1316
  });
842
- return _context7.abrupt("return", productList);
1317
+ return _context10.abrupt("return", productList);
843
1318
  case 13:
844
- _context7.prev = 13;
845
- _context7.t0 = _context7["catch"](3);
1319
+ _context10.prev = 13;
1320
+ _context10.t0 = _context10["catch"](3);
846
1321
  _duration2 = Date.now() - startTime;
847
- errorMessage = _context7.t0 instanceof Error ? _context7.t0.message : String(_context7.t0);
848
- console.error('[Products] fetchProductsByHttp 失败:', _context7.t0);
1322
+ errorMessage = _context10.t0 instanceof Error ? _context10.t0.message : String(_context10.t0);
1323
+ console.error('[Products] fetchProductsByHttp 失败:', _context10.t0);
849
1324
  this.logError('fetchProductsByHttp: 请求失败', {
850
1325
  duration: "".concat(_duration2, "ms"),
851
1326
  error: errorMessage
852
1327
  });
853
- return _context7.abrupt("return", []);
1328
+ return _context10.abrupt("return", []);
854
1329
  case 20:
855
1330
  case "end":
856
- return _context7.stop();
1331
+ return _context10.stop();
857
1332
  }
858
- }, _callee7, this, [[3, 13]]);
1333
+ }, _callee10, this, [[3, 13]]);
859
1334
  }));
860
- function fetchProductsByHttp(_x12) {
1335
+ function fetchProductsByHttp(_x15) {
861
1336
  return _fetchProductsByHttp.apply(this, arguments);
862
1337
  }
863
1338
  return fetchProductsByHttp;
@@ -871,33 +1346,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
871
1346
  }, {
872
1347
  key: "loadProductsByServerHttp",
873
1348
  value: (function () {
874
- var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
1349
+ var _loadProductsByServerHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(params) {
875
1350
  var productList;
876
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
877
- while (1) switch (_context8.prev = _context8.next) {
1351
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1352
+ while (1) switch (_context11.prev = _context11.next) {
878
1353
  case 0:
879
- _context8.next = 2;
1354
+ _context11.next = 2;
880
1355
  return this.fetchProductsByHttp(params);
881
1356
  case 2:
882
- productList = _context8.sent;
1357
+ productList = _context11.sent;
883
1358
  if (!(productList.length > 0)) {
884
- _context8.next = 8;
1359
+ _context11.next = 9;
885
1360
  break;
886
1361
  }
887
- _context8.next = 6;
888
- return this.saveProductsToIndexDB(productList);
1362
+ _context11.next = 6;
1363
+ return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
889
1364
  case 6:
890
- _context8.next = 8;
1365
+ this.lastServerFullFetchAtMs = Date.now();
1366
+ _context11.next = 9;
891
1367
  return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
892
- case 8:
893
- return _context8.abrupt("return", productList);
894
1368
  case 9:
1369
+ return _context11.abrupt("return", productList);
1370
+ case 10:
895
1371
  case "end":
896
- return _context8.stop();
1372
+ return _context11.stop();
897
1373
  }
898
- }, _callee8, this);
1374
+ }, _callee11, this);
899
1375
  }));
900
- function loadProductsByServerHttp(_x13) {
1376
+ function loadProductsByServerHttp(_x16) {
901
1377
  return _loadProductsByServerHttp.apply(this, arguments);
902
1378
  }
903
1379
  return loadProductsByServerHttp;
@@ -909,27 +1385,95 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
909
1385
  }, {
910
1386
  key: "getProducts",
911
1387
  value: (function () {
912
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
1388
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
913
1389
  var t0, result;
914
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
915
- while (1) switch (_context9.prev = _context9.next) {
1390
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1391
+ while (1) switch (_context12.prev = _context12.next) {
916
1392
  case 0:
917
1393
  t0 = performance.now();
918
1394
  result = structuredClone(this.store.list);
919
1395
  perfMark('ProductsModule.getProducts(structuredClone)', performance.now() - t0, {
920
1396
  count: result.length
921
1397
  });
922
- return _context9.abrupt("return", result);
1398
+ return _context12.abrupt("return", result);
923
1399
  case 4:
924
1400
  case "end":
925
- return _context9.stop();
1401
+ return _context12.stop();
1402
+ }
1403
+ }, _callee12, this);
1404
+ }));
1405
+ function getProducts() {
1406
+ return _getProducts.apply(this, arguments);
1407
+ }
1408
+ return getProducts;
1409
+ }()
1410
+ /**
1411
+ * 批量获取商品轻量快照,供订单详情等响应补齐展示协议字段。
1412
+ */
1413
+ )
1414
+ }, {
1415
+ key: "getProductSnapshotsByIds",
1416
+ value: (function () {
1417
+ var _getProductSnapshotsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1418
+ var snapshots, seen, _iterator6, _step6, id, product;
1419
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1420
+ while (1) switch (_context13.prev = _context13.next) {
1421
+ case 0:
1422
+ snapshots = {};
1423
+ seen = new Set();
1424
+ _iterator6 = _createForOfIteratorHelper(ids);
1425
+ _context13.prev = 3;
1426
+ _iterator6.s();
1427
+ case 5:
1428
+ if ((_step6 = _iterator6.n()).done) {
1429
+ _context13.next = 16;
1430
+ break;
1431
+ }
1432
+ id = _step6.value;
1433
+ if (!(!Number.isFinite(id) || seen.has(id))) {
1434
+ _context13.next = 9;
1435
+ break;
1436
+ }
1437
+ return _context13.abrupt("continue", 14);
1438
+ case 9:
1439
+ seen.add(id);
1440
+ product = this.store.map.get(id);
1441
+ if (product) {
1442
+ _context13.next = 13;
1443
+ break;
1444
+ }
1445
+ return _context13.abrupt("continue", 14);
1446
+ case 13:
1447
+ snapshots[String(id)] = {
1448
+ cover: product.cover,
1449
+ holder_config: product.holder_config
1450
+ };
1451
+ case 14:
1452
+ _context13.next = 5;
1453
+ break;
1454
+ case 16:
1455
+ _context13.next = 21;
1456
+ break;
1457
+ case 18:
1458
+ _context13.prev = 18;
1459
+ _context13.t0 = _context13["catch"](3);
1460
+ _iterator6.e(_context13.t0);
1461
+ case 21:
1462
+ _context13.prev = 21;
1463
+ _iterator6.f();
1464
+ return _context13.finish(21);
1465
+ case 24:
1466
+ return _context13.abrupt("return", snapshots);
1467
+ case 25:
1468
+ case "end":
1469
+ return _context13.stop();
926
1470
  }
927
- }, _callee9, this);
1471
+ }, _callee13, this, [[3, 18, 21, 24]]);
928
1472
  }));
929
- function getProducts() {
930
- return _getProducts.apply(this, arguments);
1473
+ function getProductSnapshotsByIds(_x17) {
1474
+ return _getProductSnapshotsByIds.apply(this, arguments);
931
1475
  }
932
- return getProducts;
1476
+ return getProductSnapshotsByIds;
933
1477
  }()
934
1478
  /**
935
1479
  * 内部获取商品列表的直接引用(无拷贝)
@@ -942,6 +1486,29 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
942
1486
  return this.store.list;
943
1487
  }
944
1488
 
1489
+ /**
1490
+ * 按 ID 从 Map 取商品引用,供内部 formatter 流程使用。
1491
+ */
1492
+ }, {
1493
+ key: "getProductsRefByIds",
1494
+ value: function getProductsRefByIds(ids) {
1495
+ var products = [];
1496
+ var _iterator7 = _createForOfIteratorHelper(ids),
1497
+ _step7;
1498
+ try {
1499
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1500
+ var id = _step7.value;
1501
+ var product = this.store.map.get(id);
1502
+ if (product) products.push(product);
1503
+ }
1504
+ } catch (err) {
1505
+ _iterator7.e(err);
1506
+ } finally {
1507
+ _iterator7.f();
1508
+ }
1509
+ return products;
1510
+ }
1511
+
945
1512
  /**
946
1513
  * 根据ID获取单个商品(从内存缓存)
947
1514
  * 使用 Map 快速查询,时间复杂度 O(1)
@@ -949,20 +1516,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
949
1516
  }, {
950
1517
  key: "getProductById",
951
1518
  value: (function () {
952
- var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(id) {
1519
+ var _getProductById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(id) {
953
1520
  var product;
954
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
955
- while (1) switch (_context10.prev = _context10.next) {
1521
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1522
+ while (1) switch (_context14.prev = _context14.next) {
956
1523
  case 0:
957
1524
  product = this.store.map.get(id);
958
- return _context10.abrupt("return", product ? structuredClone(product) : undefined);
1525
+ return _context14.abrupt("return", product ? structuredClone(product) : undefined);
959
1526
  case 2:
960
1527
  case "end":
961
- return _context10.stop();
1528
+ return _context14.stop();
962
1529
  }
963
- }, _callee10, this);
1530
+ }, _callee14, this);
964
1531
  }));
965
- function getProductById(_x14) {
1532
+ function getProductById(_x18) {
966
1533
  return _getProductById.apply(this, arguments);
967
1534
  }
968
1535
  return getProductById;
@@ -975,10 +1542,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
975
1542
  }, {
976
1543
  key: "removeProductsByIds",
977
1544
  value: (function () {
978
- var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(ids) {
979
- var idSet, _iterator3, _step3, _id, _iterator4, _step4, id, errorMessage, _iterator5, _step5, _step5$value, dateKey, cachedProducts;
980
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
981
- while (1) switch (_context11.prev = _context11.next) {
1545
+ var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(ids) {
1546
+ var idSet, _iterator8, _step8, _id, _iterator9, _step9, id, errorMessage, _iterator10, _step10, _step10$value, dateKey, cachedProducts;
1547
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1548
+ while (1) switch (_context15.prev = _context15.next) {
982
1549
  case 0:
983
1550
  idSet = new Set(ids);
984
1551
  this.logInfo('removeProductsByIds', {
@@ -988,71 +1555,71 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
988
1555
  this.store.list = this.store.list.filter(function (p) {
989
1556
  return !idSet.has(p.id);
990
1557
  });
991
- _iterator3 = _createForOfIteratorHelper(ids);
1558
+ _iterator8 = _createForOfIteratorHelper(ids);
992
1559
  try {
993
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
994
- _id = _step3.value;
1560
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1561
+ _id = _step8.value;
995
1562
  this.store.map.delete(_id);
996
1563
  }
997
1564
  } catch (err) {
998
- _iterator3.e(err);
1565
+ _iterator8.e(err);
999
1566
  } finally {
1000
- _iterator3.f();
1567
+ _iterator8.f();
1001
1568
  }
1002
1569
  if (!this.dbManager) {
1003
- _context11.next = 30;
1570
+ _context15.next = 30;
1004
1571
  break;
1005
1572
  }
1006
- _context11.prev = 6;
1007
- _iterator4 = _createForOfIteratorHelper(ids);
1008
- _context11.prev = 8;
1009
- _iterator4.s();
1573
+ _context15.prev = 6;
1574
+ _iterator9 = _createForOfIteratorHelper(ids);
1575
+ _context15.prev = 8;
1576
+ _iterator9.s();
1010
1577
  case 10:
1011
- if ((_step4 = _iterator4.n()).done) {
1012
- _context11.next = 16;
1578
+ if ((_step9 = _iterator9.n()).done) {
1579
+ _context15.next = 16;
1013
1580
  break;
1014
1581
  }
1015
- id = _step4.value;
1016
- _context11.next = 14;
1582
+ id = _step9.value;
1583
+ _context15.next = 14;
1017
1584
  return this.dbManager.delete(INDEXDB_STORE_NAME, id);
1018
1585
  case 14:
1019
- _context11.next = 10;
1586
+ _context15.next = 10;
1020
1587
  break;
1021
1588
  case 16:
1022
- _context11.next = 21;
1589
+ _context15.next = 21;
1023
1590
  break;
1024
1591
  case 18:
1025
- _context11.prev = 18;
1026
- _context11.t0 = _context11["catch"](8);
1027
- _iterator4.e(_context11.t0);
1592
+ _context15.prev = 18;
1593
+ _context15.t0 = _context15["catch"](8);
1594
+ _iterator9.e(_context15.t0);
1028
1595
  case 21:
1029
- _context11.prev = 21;
1030
- _iterator4.f();
1031
- return _context11.finish(21);
1596
+ _context15.prev = 21;
1597
+ _iterator9.f();
1598
+ return _context15.finish(21);
1032
1599
  case 24:
1033
- _context11.next = 30;
1600
+ _context15.next = 30;
1034
1601
  break;
1035
1602
  case 26:
1036
- _context11.prev = 26;
1037
- _context11.t1 = _context11["catch"](6);
1038
- errorMessage = _context11.t1 instanceof Error ? _context11.t1.message : String(_context11.t1);
1603
+ _context15.prev = 26;
1604
+ _context15.t1 = _context15["catch"](6);
1605
+ errorMessage = _context15.t1 instanceof Error ? _context15.t1.message : String(_context15.t1);
1039
1606
  this.logError('removeProductsByIds: IndexDB 删除失败', {
1040
1607
  ids: ids,
1041
1608
  error: errorMessage
1042
1609
  });
1043
1610
  case 30:
1044
- _iterator5 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1611
+ _iterator10 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1045
1612
  try {
1046
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1047
- _step5$value = _slicedToArray(_step5.value, 2), dateKey = _step5$value[0], cachedProducts = _step5$value[1];
1613
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1614
+ _step10$value = _slicedToArray(_step10.value, 2), dateKey = _step10$value[0], cachedProducts = _step10$value[1];
1048
1615
  this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
1049
1616
  return !idSet.has(p.id);
1050
1617
  }));
1051
1618
  }
1052
1619
  } catch (err) {
1053
- _iterator5.e(err);
1620
+ _iterator10.e(err);
1054
1621
  } finally {
1055
- _iterator5.f();
1622
+ _iterator10.f();
1056
1623
  }
1057
1624
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1058
1625
  this.logInfo('removeProductsByIds 完成', {
@@ -1060,11 +1627,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1060
1627
  });
1061
1628
  case 34:
1062
1629
  case "end":
1063
- return _context11.stop();
1630
+ return _context15.stop();
1064
1631
  }
1065
- }, _callee11, this, [[6, 26], [8, 18, 21, 24]]);
1632
+ }, _callee15, this, [[6, 26], [8, 18, 21, 24]]);
1066
1633
  }));
1067
- function removeProductsByIds(_x15) {
1634
+ function removeProductsByIds(_x19) {
1068
1635
  return _removeProductsByIds.apply(this, arguments);
1069
1636
  }
1070
1637
  return removeProductsByIds;
@@ -1077,17 +1644,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1077
1644
  }, {
1078
1645
  key: "refreshProducts",
1079
1646
  value: (function () {
1080
- var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1647
+ var _refreshProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1081
1648
  var tTotal, products;
1082
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1083
- while (1) switch (_context12.prev = _context12.next) {
1649
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1650
+ while (1) switch (_context16.prev = _context16.next) {
1084
1651
  case 0:
1085
1652
  tTotal = performance.now();
1086
1653
  this.logInfo('refreshProducts 开始');
1087
- _context12.next = 4;
1654
+ _context16.next = 4;
1088
1655
  return this.loadProductsByServer();
1089
1656
  case 4:
1090
- products = _context12.sent;
1657
+ products = _context16.sent;
1091
1658
  if (products && products.length > 0) {
1092
1659
  // 服务器返回的数据已经是全新的,无需 cloneDeep
1093
1660
  this.store.list = products;
@@ -1102,12 +1669,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1102
1669
  perfMark('refreshProducts', performance.now() - tTotal, {
1103
1670
  count: this.store.list.length
1104
1671
  });
1105
- return _context12.abrupt("return", this.store.list);
1672
+ return _context16.abrupt("return", this.store.list);
1106
1673
  case 8:
1107
1674
  case "end":
1108
- return _context12.stop();
1675
+ return _context16.stop();
1109
1676
  }
1110
- }, _callee12, this);
1677
+ }, _callee16, this);
1111
1678
  }));
1112
1679
  function refreshProducts() {
1113
1680
  return _refreshProducts.apply(this, arguments);
@@ -1121,10 +1688,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1121
1688
  }, {
1122
1689
  key: "clear",
1123
1690
  value: (function () {
1124
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
1691
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1125
1692
  var errorMessage;
1126
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1127
- while (1) switch (_context13.prev = _context13.next) {
1693
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1694
+ while (1) switch (_context17.prev = _context17.next) {
1128
1695
  case 0:
1129
1696
  this.logInfo('开始清空缓存', {
1130
1697
  currentProductCount: this.store.list.length,
@@ -1135,21 +1702,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1135
1702
 
1136
1703
  // 同时清空 IndexDB 中的所有数据(包括商品和元数据)
1137
1704
  if (!this.dbManager) {
1138
- _context13.next = 15;
1705
+ _context17.next = 15;
1139
1706
  break;
1140
1707
  }
1141
- _context13.prev = 4;
1142
- _context13.next = 7;
1708
+ _context17.prev = 4;
1709
+ _context17.next = 7;
1143
1710
  return this.dbManager.clear(INDEXDB_STORE_NAME);
1144
1711
  case 7:
1145
1712
  this.logInfo('IndexDB 缓存已清空');
1146
- _context13.next = 15;
1713
+ _context17.next = 15;
1147
1714
  break;
1148
1715
  case 10:
1149
- _context13.prev = 10;
1150
- _context13.t0 = _context13["catch"](4);
1151
- errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1152
- console.error('[Products] 清空 IndexDB 缓存失败:', _context13.t0);
1716
+ _context17.prev = 10;
1717
+ _context17.t0 = _context17["catch"](4);
1718
+ errorMessage = _context17.t0 instanceof Error ? _context17.t0.message : String(_context17.t0);
1719
+ console.error('[Products] 清空 IndexDB 缓存失败:', _context17.t0);
1153
1720
  this.logError('清空 IndexDB 缓存失败', {
1154
1721
  error: errorMessage
1155
1722
  });
@@ -1157,9 +1724,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1157
1724
  this.logInfo('缓存清空完成');
1158
1725
  case 16:
1159
1726
  case "end":
1160
- return _context13.stop();
1727
+ return _context17.stop();
1161
1728
  }
1162
- }, _callee13, this, [[4, 10]]);
1729
+ }, _callee17, this, [[4, 10]]);
1163
1730
  }));
1164
1731
  function clear() {
1165
1732
  return _clear.apply(this, arguments);
@@ -1174,45 +1741,45 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1174
1741
  }, {
1175
1742
  key: "loadProductsFromIndexDB",
1176
1743
  value: (function () {
1177
- var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
1744
+ var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1178
1745
  var _products$length, _products$length2, t0, products, errorMessage;
1179
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1180
- while (1) switch (_context14.prev = _context14.next) {
1746
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1747
+ while (1) switch (_context18.prev = _context18.next) {
1181
1748
  case 0:
1182
1749
  if (this.dbManager) {
1183
- _context14.next = 3;
1750
+ _context18.next = 3;
1184
1751
  break;
1185
1752
  }
1186
1753
  this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
1187
- return _context14.abrupt("return", []);
1754
+ return _context18.abrupt("return", []);
1188
1755
  case 3:
1189
- _context14.prev = 3;
1756
+ _context18.prev = 3;
1190
1757
  t0 = performance.now();
1191
- _context14.next = 7;
1758
+ _context18.next = 7;
1192
1759
  return this.dbManager.getAll(INDEXDB_STORE_NAME);
1193
1760
  case 7:
1194
- products = _context14.sent;
1761
+ products = _context18.sent;
1195
1762
  perfMark('loadProductsFromIndexDB', performance.now() - t0, {
1196
1763
  count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
1197
1764
  });
1198
1765
  this.logInfo('从 IndexDB 加载商品数据', {
1199
1766
  productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
1200
1767
  });
1201
- return _context14.abrupt("return", products || []);
1768
+ return _context18.abrupt("return", products || []);
1202
1769
  case 13:
1203
- _context14.prev = 13;
1204
- _context14.t0 = _context14["catch"](3);
1205
- errorMessage = _context14.t0 instanceof Error ? _context14.t0.message : String(_context14.t0);
1206
- console.error('[Products] 从 IndexDB 读取数据失败:', _context14.t0);
1770
+ _context18.prev = 13;
1771
+ _context18.t0 = _context18["catch"](3);
1772
+ errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
1773
+ console.error('[Products] 从 IndexDB 读取数据失败:', _context18.t0);
1207
1774
  this.logError('从 IndexDB 读取数据失败', {
1208
1775
  error: errorMessage
1209
1776
  });
1210
- return _context14.abrupt("return", []);
1777
+ return _context18.abrupt("return", []);
1211
1778
  case 19:
1212
1779
  case "end":
1213
- return _context14.stop();
1780
+ return _context18.stop();
1214
1781
  }
1215
- }, _callee14, this, [[3, 13]]);
1782
+ }, _callee18, this, [[3, 13]]);
1216
1783
  }));
1217
1784
  function loadProductsFromIndexDB() {
1218
1785
  return _loadProductsFromIndexDB.apply(this, arguments);
@@ -1220,63 +1787,243 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1220
1787
  return loadProductsFromIndexDB;
1221
1788
  }()
1222
1789
  /**
1223
- * 保存商品数据到 IndexDB(平铺存储)
1224
- * @private
1790
+ * 串行执行商品 IndexDB 写入,避免快照替换与增量 patch 并发交错。
1791
+ *
1792
+ * @example
1793
+ * await this.runInProductIndexDBSaveQueue(async () => {
1794
+ * await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products)
1795
+ * })
1225
1796
  */
1226
1797
  )
1227
1798
  }, {
1228
- key: "saveProductsToIndexDB",
1799
+ key: "runInProductIndexDBSaveQueue",
1229
1800
  value: (function () {
1230
- var _saveProductsToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(products) {
1231
- var t0, errorMessage;
1232
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1233
- while (1) switch (_context15.prev = _context15.next) {
1801
+ var _runInProductIndexDBSaveQueue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(task) {
1802
+ var queuedTask;
1803
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1804
+ while (1) switch (_context19.prev = _context19.next) {
1805
+ case 0:
1806
+ queuedTask = this.productIndexDBSaveQueue.then(task, task);
1807
+ this.productIndexDBSaveQueue = queuedTask.then(function () {
1808
+ return undefined;
1809
+ }, function () {
1810
+ return undefined;
1811
+ });
1812
+ return _context19.abrupt("return", queuedTask);
1813
+ case 3:
1814
+ case "end":
1815
+ return _context19.stop();
1816
+ }
1817
+ }, _callee19, this);
1818
+ }));
1819
+ function runInProductIndexDBSaveQueue(_x20) {
1820
+ return _runInProductIndexDBSaveQueue.apply(this, arguments);
1821
+ }
1822
+ return runInProductIndexDBSaveQueue;
1823
+ }()
1824
+ /**
1825
+ * 全量快照写入 IndexDB:clear + bulkUpdate,仅用于 SSE/HTTP 全量拉取。
1826
+ *
1827
+ * @example
1828
+ * await this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer')
1829
+ */
1830
+ )
1831
+ }, {
1832
+ key: "replaceProductsSnapshotInIndexDB",
1833
+ value: (function () {
1834
+ var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(products, source) {
1835
+ var _this9 = this;
1836
+ var errorMessage;
1837
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1838
+ while (1) switch (_context21.prev = _context21.next) {
1234
1839
  case 0:
1235
1840
  if (this.dbManager) {
1236
- _context15.next = 3;
1841
+ _context21.next = 3;
1237
1842
  break;
1238
1843
  }
1239
- this.logWarning('saveProductsToIndexDB: dbManager 不可用');
1240
- return _context15.abrupt("return");
1844
+ this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
1845
+ return _context21.abrupt("return");
1241
1846
  case 3:
1242
- this.logInfo('开始保存商品数据到 IndexDB', {
1243
- productCount: products.length
1244
- });
1245
- _context15.prev = 4;
1246
- t0 = performance.now();
1247
- _context15.next = 8;
1248
- return this.dbManager.clear(INDEXDB_STORE_NAME);
1847
+ _context21.prev = 3;
1848
+ _context21.next = 6;
1849
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
1850
+ var t0;
1851
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1852
+ while (1) switch (_context20.prev = _context20.next) {
1853
+ case 0:
1854
+ _this9.logInfo('replaceProductsSnapshotInIndexDB 开始', {
1855
+ source: source,
1856
+ productCount: products.length
1857
+ });
1858
+ t0 = performance.now();
1859
+ _context20.next = 4;
1860
+ return _this9.dbManager.clear(INDEXDB_STORE_NAME);
1861
+ case 4:
1862
+ if (!(products.length > 0)) {
1863
+ _context20.next = 7;
1864
+ break;
1865
+ }
1866
+ _context20.next = 7;
1867
+ return _this9.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1868
+ case 7:
1869
+ perfMark('replaceProductsSnapshotInIndexDB', performance.now() - t0, {
1870
+ count: products.length
1871
+ });
1872
+ _this9.logInfo('replaceProductsSnapshotInIndexDB 完成', {
1873
+ source: source,
1874
+ productCount: products.length
1875
+ });
1876
+ case 9:
1877
+ case "end":
1878
+ return _context20.stop();
1879
+ }
1880
+ }, _callee20);
1881
+ })));
1882
+ case 6:
1883
+ _context21.next = 12;
1884
+ break;
1249
1885
  case 8:
1250
- _context15.next = 10;
1251
- return this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
1252
- case 10:
1253
- perfMark('saveProductsToIndexDB', performance.now() - t0, {
1254
- count: products.length
1886
+ _context21.prev = 8;
1887
+ _context21.t0 = _context21["catch"](3);
1888
+ errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
1889
+ this.logError('全量保存商品到 IndexDB 失败', {
1890
+ source: source,
1891
+ productCount: products.length,
1892
+ error: errorMessage
1255
1893
  });
1256
- this.logInfo('商品数据已保存到 IndexDB', {
1257
- productCount: products.length
1894
+ case 12:
1895
+ case "end":
1896
+ return _context21.stop();
1897
+ }
1898
+ }, _callee21, this, [[3, 8]]);
1899
+ }));
1900
+ function replaceProductsSnapshotInIndexDB(_x21, _x22) {
1901
+ return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
1902
+ }
1903
+ return replaceProductsSnapshotInIndexDB;
1904
+ }()
1905
+ /**
1906
+ * 增量 upsert 商品到 IndexDB,不清空表;用于 pubsub 批次合并后的变更商品。
1907
+ *
1908
+ * @example
1909
+ * await this.patchProductsInIndexDB(changedProducts, 'pubsub.processProductSyncMessages', mergeActions)
1910
+ */
1911
+ )
1912
+ }, {
1913
+ key: "patchProductsInIndexDB",
1914
+ value: (function () {
1915
+ var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(products, source) {
1916
+ var _this10 = this;
1917
+ var mergeActions,
1918
+ validProducts,
1919
+ errorMessage,
1920
+ _args23 = arguments;
1921
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1922
+ while (1) switch (_context23.prev = _context23.next) {
1923
+ case 0:
1924
+ mergeActions = _args23.length > 2 && _args23[2] !== undefined ? _args23[2] : {};
1925
+ if (!(!this.dbManager || products.length === 0)) {
1926
+ _context23.next = 3;
1927
+ break;
1928
+ }
1929
+ return _context23.abrupt("return");
1930
+ case 3:
1931
+ validProducts = products.filter(function (p) {
1932
+ return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
1258
1933
  });
1259
- _context15.next = 19;
1934
+ if (!(validProducts.length === 0)) {
1935
+ _context23.next = 6;
1936
+ break;
1937
+ }
1938
+ return _context23.abrupt("return");
1939
+ case 6:
1940
+ _context23.prev = 6;
1941
+ _context23.next = 9;
1942
+ return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
1943
+ var t0, _iterator11, _step11, product;
1944
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1945
+ while (1) switch (_context22.prev = _context22.next) {
1946
+ case 0:
1947
+ _this10.logInfo('patchProductsInIndexDB 开始', {
1948
+ source: source,
1949
+ count: validProducts.length
1950
+ });
1951
+ t0 = performance.now();
1952
+ if (!(typeof _this10.dbManager.bulkUpdate === 'function')) {
1953
+ _context22.next = 7;
1954
+ break;
1955
+ }
1956
+ _context22.next = 5;
1957
+ return _this10.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
1958
+ case 5:
1959
+ _context22.next = 25;
1960
+ break;
1961
+ case 7:
1962
+ if (!(typeof _this10.dbManager.update === 'function')) {
1963
+ _context22.next = 25;
1964
+ break;
1965
+ }
1966
+ _iterator11 = _createForOfIteratorHelper(validProducts);
1967
+ _context22.prev = 9;
1968
+ _iterator11.s();
1969
+ case 11:
1970
+ if ((_step11 = _iterator11.n()).done) {
1971
+ _context22.next = 17;
1972
+ break;
1973
+ }
1974
+ product = _step11.value;
1975
+ _context22.next = 15;
1976
+ return _this10.dbManager.update(INDEXDB_STORE_NAME, product);
1977
+ case 15:
1978
+ _context22.next = 11;
1979
+ break;
1980
+ case 17:
1981
+ _context22.next = 22;
1982
+ break;
1983
+ case 19:
1984
+ _context22.prev = 19;
1985
+ _context22.t0 = _context22["catch"](9);
1986
+ _iterator11.e(_context22.t0);
1987
+ case 22:
1988
+ _context22.prev = 22;
1989
+ _iterator11.f();
1990
+ return _context22.finish(22);
1991
+ case 25:
1992
+ perfMark('patchProductsInIndexDB', performance.now() - t0, {
1993
+ count: validProducts.length
1994
+ });
1995
+ _this10.logInfo('patchProductsInIndexDB 完成', {
1996
+ source: source,
1997
+ count: validProducts.length
1998
+ });
1999
+ case 27:
2000
+ case "end":
2001
+ return _context22.stop();
2002
+ }
2003
+ }, _callee22, null, [[9, 19, 22, 25]]);
2004
+ })));
2005
+ case 9:
2006
+ _context23.next = 15;
1260
2007
  break;
1261
- case 14:
1262
- _context15.prev = 14;
1263
- _context15.t0 = _context15["catch"](4);
1264
- errorMessage = _context15.t0 instanceof Error ? _context15.t0.message : String(_context15.t0);
1265
- console.error('[Products] 保存数据到 IndexDB 失败:', _context15.t0);
1266
- this.logError('保存数据到 IndexDB 失败', {
1267
- productCount: products.length,
1268
- error: errorMessage
2008
+ case 11:
2009
+ _context23.prev = 11;
2010
+ _context23.t0 = _context23["catch"](6);
2011
+ errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
2012
+ this.logError('增量保存商品到 IndexDB 失败', {
2013
+ source: source,
2014
+ error: errorMessage,
2015
+ productCount: validProducts.length
1269
2016
  });
1270
- case 19:
2017
+ case 15:
1271
2018
  case "end":
1272
- return _context15.stop();
2019
+ return _context23.stop();
1273
2020
  }
1274
- }, _callee15, this, [[4, 14]]);
2021
+ }, _callee23, this, [[6, 11]]);
1275
2022
  }));
1276
- function saveProductsToIndexDB(_x16) {
1277
- return _saveProductsToIndexDB.apply(this, arguments);
2023
+ function patchProductsInIndexDB(_x23, _x24) {
2024
+ return _patchProductsInIndexDB.apply(this, arguments);
1278
2025
  }
1279
- return saveProductsToIndexDB;
2026
+ return patchProductsInIndexDB;
1280
2027
  }()
1281
2028
  /**
1282
2029
  * 同步更新商品 Map 缓存
@@ -1289,17 +2036,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1289
2036
  value: function syncProductsMap() {
1290
2037
  var t0 = performance.now();
1291
2038
  this.store.map.clear();
1292
- var _iterator6 = _createForOfIteratorHelper(this.store.list),
1293
- _step6;
2039
+ var _iterator12 = _createForOfIteratorHelper(this.store.list),
2040
+ _step12;
1294
2041
  try {
1295
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1296
- var product = _step6.value;
2042
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
2043
+ var product = _step12.value;
1297
2044
  this.store.map.set(product.id, product);
1298
2045
  }
1299
2046
  } catch (err) {
1300
- _iterator6.e(err);
2047
+ _iterator12.e(err);
1301
2048
  } finally {
1302
- _iterator6.f();
2049
+ _iterator12.f();
1303
2050
  }
1304
2051
  perfMark('syncProductsMap', performance.now() - t0, {
1305
2052
  count: this.store.map.size
@@ -1313,25 +2060,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1313
2060
  }, {
1314
2061
  key: "preload",
1315
2062
  value: (function () {
1316
- var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
2063
+ var _preload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1317
2064
  var _products$length3;
1318
2065
  var tTotal, _cachedData$length, tIndexDB, cachedData, tSync, errorMessage, tServer, products, _tSync;
1319
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1320
- while (1) switch (_context16.prev = _context16.next) {
2066
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2067
+ while (1) switch (_context24.prev = _context24.next) {
1321
2068
  case 0:
1322
2069
  tTotal = performance.now();
1323
2070
  this.logInfo('开始预加载数据');
1324
- _context16.prev = 2;
2071
+ _context24.prev = 2;
1325
2072
  tIndexDB = performance.now();
1326
- _context16.next = 6;
2073
+ _context24.next = 6;
1327
2074
  return this.loadProductsFromIndexDB();
1328
2075
  case 6:
1329
- cachedData = _context16.sent;
2076
+ cachedData = _context24.sent;
1330
2077
  perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
1331
2078
  count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
1332
2079
  });
1333
2080
  if (!(cachedData && cachedData.length > 0)) {
1334
- _context16.next = 17;
2081
+ _context24.next = 18;
1335
2082
  break;
1336
2083
  }
1337
2084
  // IndexDB 反序列化的数据已经是全新的,无需 cloneDeep
@@ -1351,25 +2098,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1351
2098
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1352
2099
  source: 'IndexDB'
1353
2100
  });
1354
- return _context16.abrupt("return");
1355
- case 17:
2101
+ this.lastPreloadCompletedAtMs = Date.now();
2102
+ return _context24.abrupt("return");
2103
+ case 18:
1356
2104
  this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
1357
- _context16.next = 25;
2105
+ _context24.next = 26;
1358
2106
  break;
1359
- case 20:
1360
- _context16.prev = 20;
1361
- _context16.t0 = _context16["catch"](2);
1362
- errorMessage = _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0);
1363
- console.warn('[Products] 从 IndexDB 加载数据失败:', _context16.t0);
2107
+ case 21:
2108
+ _context24.prev = 21;
2109
+ _context24.t0 = _context24["catch"](2);
2110
+ errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
2111
+ console.warn('[Products] 从 IndexDB 加载数据失败:', _context24.t0);
1364
2112
  this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
1365
2113
  error: errorMessage
1366
2114
  });
1367
- case 25:
2115
+ case 26:
1368
2116
  tServer = performance.now();
1369
- _context16.next = 28;
2117
+ _context24.next = 29;
1370
2118
  return this.loadProductsByServer();
1371
- case 28:
1372
- products = _context16.sent;
2119
+ case 29:
2120
+ products = _context24.sent;
1373
2121
  perfMark('preload.loadFromServer', performance.now() - tServer, {
1374
2122
  count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
1375
2123
  });
@@ -1391,6 +2139,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1391
2139
  duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
1392
2140
  source: 'Server'
1393
2141
  });
2142
+ this.lastPreloadCompletedAtMs = Date.now();
1394
2143
  } else {
1395
2144
  perfMark('preload(empty)', performance.now() - tTotal, {
1396
2145
  source: 'empty'
@@ -1399,11 +2148,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1399
2148
  duration: "".concat(Math.round(performance.now() - tTotal), "ms")
1400
2149
  });
1401
2150
  }
1402
- case 31:
2151
+ case 32:
1403
2152
  case "end":
1404
- return _context16.stop();
2153
+ return _context24.stop();
1405
2154
  }
1406
- }, _callee16, this, [[2, 20]]);
2155
+ }, _callee24, this, [[2, 21]]);
1407
2156
  }));
1408
2157
  function preload() {
1409
2158
  return _preload.apply(this, arguments);
@@ -1438,7 +2187,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1438
2187
  }, {
1439
2188
  key: "setupProductSync",
1440
2189
  value: function setupProductSync() {
1441
- var _this2 = this;
2190
+ var _this11 = this;
1442
2191
  if (!this.productDataSource) {
1443
2192
  this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
1444
2193
  return;
@@ -1447,29 +2196,30 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1447
2196
  return function (message) {
1448
2197
  var data = (message === null || message === void 0 ? void 0 : message.data) || message;
1449
2198
  if (!data) return;
1450
- _this2.logInfo('收到同步消息', {
2199
+ _this11.logInfo('收到同步消息', {
1451
2200
  channelKey: channelKey,
1452
2201
  action: data.action,
1453
2202
  id: data.id,
1454
2203
  action_filed: data.action_filed
1455
2204
  });
1456
- _this2.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
2205
+ _this11.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
1457
2206
  _channelKey: channelKey
1458
2207
  }));
1459
- if (_this2.syncTimer) {
1460
- clearTimeout(_this2.syncTimer);
2208
+ if (_this11.syncTimer) {
2209
+ clearTimeout(_this11.syncTimer);
1461
2210
  }
1462
- _this2.syncTimer = setTimeout(function () {
1463
- _this2.processProductSyncMessages();
2211
+ _this11.syncTimer = setTimeout(function () {
2212
+ _this11.processProductSyncMessages();
1464
2213
  }, PRODUCT_SYNC_DEBOUNCE_MS);
1465
2214
  };
1466
2215
  };
1467
2216
  this.productDataSource.run({
1468
2217
  pubsub: {
1469
2218
  callback: function callback(res) {
1470
- _this2.logInfo('sse_products_callback: 收到同步消息', {
1471
- data: res === null || res === void 0 ? void 0 : res.data
1472
- });
2219
+ // console.log('sse_products_callback', res)
2220
+ // this.logInfo('sse_products_callback: 收到同步消息', {
2221
+ // data: res?.data,
2222
+ // });
1473
2223
  if (!(res !== null && res !== void 0 && res.data)) return;
1474
2224
  var data = res.data;
1475
2225
  var channelKey = data.module || 'product';
@@ -1477,7 +2227,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1477
2227
  }
1478
2228
  }
1479
2229
  }).catch(function (err) {
1480
- _this2.logError('setupProductSync: DataSource run 出错', {
2230
+ _this11.logError('setupProductSync: DataSource run 出错', {
1481
2231
  error: err instanceof Error ? err.message : String(err)
1482
2232
  });
1483
2233
  });
@@ -1505,18 +2255,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1505
2255
  }, {
1506
2256
  key: "processProductSyncMessages",
1507
2257
  value: (function () {
1508
- var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
1509
- var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator7, _step7, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, freshProducts, allChangedIds, hasChanges;
1510
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1511
- while (1) switch (_context17.prev = _context17.next) {
2258
+ var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2259
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator13, _step13, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, _msg$product_ids, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator14, _step14, product, freshProducts, mergeResult, _iterator15, _step15, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
2260
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2261
+ while (1) switch (_context25.prev = _context25.next) {
1512
2262
  case 0:
1513
2263
  messages = _toConsumableArray(this.pendingSyncMessages);
1514
2264
  this.pendingSyncMessages = [];
1515
2265
  if (!(messages.length === 0)) {
1516
- _context17.next = 4;
2266
+ _context25.next = 4;
1517
2267
  break;
1518
2268
  }
1519
- return _context17.abrupt("return");
2269
+ return _context25.abrupt("return");
1520
2270
  case 4:
1521
2271
  this.logInfo('processProductSyncMessages: 开始处理', {
1522
2272
  count: messages.length
@@ -1526,18 +2276,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1526
2276
  sseRefreshIds = [];
1527
2277
  priceRefreshIds = [];
1528
2278
  shouldClearPriceCache = false;
1529
- _iterator7 = _createForOfIteratorHelper(messages);
1530
- _context17.prev = 11;
1531
- _iterator7.s();
2279
+ _iterator13 = _createForOfIteratorHelper(messages);
2280
+ _context25.prev = 11;
2281
+ _iterator13.s();
1532
2282
  case 13:
1533
- if ((_step7 = _iterator7.n()).done) {
1534
- _context17.next = 36;
2283
+ if ((_step13 = _iterator13.n()).done) {
2284
+ _context25.next = 36;
1535
2285
  break;
1536
2286
  }
1537
- msg = _step7.value;
2287
+ msg = _step13.value;
1538
2288
  channelKey = msg._channelKey || msg.module || 'product';
1539
2289
  if (!(channelKey === 'product')) {
1540
- _context17.next = 33;
2290
+ _context25.next = 33;
1541
2291
  break;
1542
2292
  }
1543
2293
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
@@ -1545,14 +2295,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1545
2295
  }
1546
2296
  // 1. 删除场景:operation === 'delete' 或 action === 'delete'
1547
2297
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
1548
- _context17.next = 21;
2298
+ _context25.next = 21;
1549
2299
  break;
1550
2300
  }
1551
2301
  if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
1552
- return _context17.abrupt("continue", 34);
2302
+ return _context25.abrupt("continue", 34);
1553
2303
  case 21:
1554
2304
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
1555
- _context17.next = 26;
2305
+ _context25.next = 26;
1556
2306
  break;
1557
2307
  }
1558
2308
  ids = msg.ids || (msg.id ? [msg.id] : []);
@@ -1561,15 +2311,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1561
2311
  bodyId = msg.body.id;
1562
2312
  if (bodyId) bodyUpdates.set(bodyId, msg.body);
1563
2313
  }
1564
- return _context17.abrupt("continue", 34);
2314
+ return _context25.abrupt("continue", 34);
1565
2315
  case 26:
1566
2316
  if (!msg.body) {
1567
- _context17.next = 30;
2317
+ _context25.next = 30;
1568
2318
  break;
1569
2319
  }
1570
2320
  _bodyId = msg.body.id || msg.id;
1571
2321
  if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
1572
- return _context17.abrupt("continue", 34);
2322
+ return _context25.abrupt("continue", 34);
1573
2323
  case 30:
1574
2324
  // 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1575
2325
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
@@ -1577,7 +2327,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1577
2327
  } else if (msg.id) {
1578
2328
  sseRefreshIds.push(msg.id);
1579
2329
  }
1580
- _context17.next = 34;
2330
+ _context25.next = 34;
1581
2331
  break;
1582
2332
  case 33:
1583
2333
  if (channelKey === 'product_quotation') {
@@ -1590,59 +2340,117 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1590
2340
  if ((_msg$relation_product3 = msg.relation_product_ids) !== null && _msg$relation_product3 !== void 0 && _msg$relation_product3.length) {
1591
2341
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1592
2342
  }
2343
+ } else if (['product_data_variant'].includes(channelKey)) {
2344
+ if ((_msg$product_ids = msg.product_ids) !== null && _msg$product_ids !== void 0 && _msg$product_ids.length) {
2345
+ sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.product_ids));
2346
+ }
1593
2347
  }
1594
2348
  case 34:
1595
- _context17.next = 13;
2349
+ _context25.next = 13;
1596
2350
  break;
1597
2351
  case 36:
1598
- _context17.next = 41;
2352
+ _context25.next = 41;
1599
2353
  break;
1600
2354
  case 38:
1601
- _context17.prev = 38;
1602
- _context17.t0 = _context17["catch"](11);
1603
- _iterator7.e(_context17.t0);
2355
+ _context25.prev = 38;
2356
+ _context25.t0 = _context25["catch"](11);
2357
+ _iterator13.e(_context25.t0);
1604
2358
  case 41:
1605
- _context17.prev = 41;
1606
- _iterator7.f();
1607
- return _context17.finish(41);
2359
+ _context25.prev = 41;
2360
+ _iterator13.f();
2361
+ return _context25.finish(41);
1608
2362
  case 44:
1609
2363
  uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
1610
2364
  uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
1611
2365
  uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
1612
2366
  if (!(uniqueDeleteIds.length > 0)) {
1613
- _context17.next = 50;
2367
+ _context25.next = 50;
1614
2368
  break;
1615
2369
  }
1616
- _context17.next = 50;
2370
+ _context25.next = 50;
1617
2371
  return this.removeProductsByIds(uniqueDeleteIds);
1618
2372
  case 50:
2373
+ /** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
2374
+ patchProductMap = new Map();
2375
+ patchMergeActions = {};
2376
+ storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
1619
2377
  if (!(bodyUpdates.size > 0)) {
1620
- _context17.next = 53;
2378
+ _context25.next = 60;
1621
2379
  break;
1622
2380
  }
1623
- _context17.next = 53;
1624
- return this.applyBodyUpdatesToStore(bodyUpdates);
1625
- case 53:
2381
+ _context25.next = 56;
2382
+ return this.applyBodyUpdatesToStore(bodyUpdates, {
2383
+ skipIndexDB: true,
2384
+ skipEmit: true
2385
+ });
2386
+ case 56:
2387
+ bodyResult = _context25.sent;
2388
+ _iterator14 = _createForOfIteratorHelper(bodyResult.changedProducts);
2389
+ try {
2390
+ for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
2391
+ product = _step14.value;
2392
+ patchProductMap.set(product.id, product);
2393
+ patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
2394
+ }
2395
+ } catch (err) {
2396
+ _iterator14.e(err);
2397
+ } finally {
2398
+ _iterator14.f();
2399
+ }
2400
+ storeMutated = true;
2401
+ case 60:
2402
+ // 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
2403
+ freshProducts = [];
1626
2404
  if (!(uniqueSSEIds.length > 0)) {
1627
- _context17.next = 61;
2405
+ _context25.next = 73;
1628
2406
  break;
1629
2407
  }
1630
- _context17.next = 56;
2408
+ _context25.next = 64;
1631
2409
  return this.fetchProductsBySSE(uniqueSSEIds);
1632
- case 56:
1633
- freshProducts = _context17.sent;
2410
+ case 64:
2411
+ freshProducts = _context25.sent;
1634
2412
  if (!(freshProducts.length > 0)) {
1635
- _context17.next = 60;
2413
+ _context25.next = 72;
1636
2414
  break;
1637
2415
  }
1638
- _context17.next = 60;
1639
- return this.mergeProductsToStore(freshProducts);
1640
- case 60:
2416
+ _context25.next = 68;
2417
+ return this.mergeProductsToStore(freshProducts, {
2418
+ skipIndexDB: true,
2419
+ skipEmit: true
2420
+ });
2421
+ case 68:
2422
+ mergeResult = _context25.sent;
2423
+ _iterator15 = _createForOfIteratorHelper(mergeResult.changedProducts);
2424
+ try {
2425
+ for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
2426
+ _product = _step15.value;
2427
+ patchProductMap.set(_product.id, _product);
2428
+ patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
2429
+ }
2430
+ } catch (err) {
2431
+ _iterator15.e(err);
2432
+ } finally {
2433
+ _iterator15.f();
2434
+ }
2435
+ storeMutated = true;
2436
+ case 72:
1641
2437
  this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
1642
2438
  requestedCount: uniqueSSEIds.length,
1643
2439
  receivedCount: freshProducts.length
1644
2440
  });
1645
- case 61:
2441
+ case 73:
2442
+ patchProducts = _toConsumableArray(patchProductMap.values());
2443
+ if (!(patchProducts.length > 0)) {
2444
+ _context25.next = 77;
2445
+ break;
2446
+ }
2447
+ _context25.next = 77;
2448
+ return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
2449
+ case 77:
2450
+ if (storeMutated) {
2451
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2452
+ }
2453
+
1646
2454
  // 收集所有非 delete 的变更 IDs(body + SSE + price),用于增量更新价格缓存
1647
2455
  allChangedIds = _toConsumableArray(new Set([].concat(_toConsumableArray(Array.from(bodyUpdates.keys())), _toConsumableArray(uniqueSSEIds), _toConsumableArray(uniquePriceIds))));
1648
2456
  this.logInfo('processProductSyncMessages: 处理完成123', {
@@ -1655,25 +2463,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1655
2463
  });
1656
2464
  hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
1657
2465
  if (hasChanges) {
1658
- _context17.next = 67;
2466
+ _context25.next = 84;
1659
2467
  break;
1660
2468
  }
1661
2469
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
1662
- return _context17.abrupt("return");
1663
- case 67:
1664
- // 报价单变更 → 清除全量价格缓存,后续走全量重建
1665
- if (shouldClearPriceCache) {
1666
- this.clearPriceCache();
2470
+ return _context25.abrupt("return");
2471
+ case 84:
2472
+ if (!shouldClearPriceCache) {
2473
+ _context25.next = 95;
2474
+ break;
1667
2475
  }
1668
- _context17.next = 70;
2476
+ _context25.prev = 85;
2477
+ _context25.next = 88;
2478
+ return this.refreshQuotationPriceBridge();
2479
+ case 88:
2480
+ _context25.next = 94;
2481
+ break;
2482
+ case 90:
2483
+ _context25.prev = 90;
2484
+ _context25.t1 = _context25["catch"](85);
2485
+ errorMessage = _context25.t1 instanceof Error ? _context25.t1.message : String(_context25.t1);
2486
+ this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
2487
+ error: errorMessage
2488
+ });
2489
+ case 94:
2490
+ this.clearPriceCache();
2491
+ case 95:
2492
+ _context25.next = 97;
1669
2493
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
1670
2494
  changedIds: allChangedIds
1671
2495
  });
1672
- case 70:
2496
+ case 97:
1673
2497
  case "end":
1674
- return _context17.stop();
2498
+ return _context25.stop();
1675
2499
  }
1676
- }, _callee17, this, [[11, 38, 41, 44]]);
2500
+ }, _callee25, this, [[11, 38, 41, 44], [85, 90]]);
1677
2501
  }));
1678
2502
  function processProductSyncMessages() {
1679
2503
  return _processProductSyncMessages.apply(this, arguments);
@@ -1688,25 +2512,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1688
2512
  }, {
1689
2513
  key: "fetchProductsBySSE",
1690
2514
  value: (function () {
1691
- var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(ids) {
2515
+ var _fetchProductsBySSE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(ids) {
1692
2516
  var t0, productList, list, errorMessage;
1693
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1694
- while (1) switch (_context18.prev = _context18.next) {
2517
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2518
+ while (1) switch (_context26.prev = _context26.next) {
1695
2519
  case 0:
1696
2520
  if (this.productDataSource) {
1697
- _context18.next = 3;
2521
+ _context26.next = 3;
1698
2522
  break;
1699
2523
  }
1700
2524
  this.logWarning('fetchProductsBySSE: ProductDataSource 不可用');
1701
- return _context18.abrupt("return", []);
2525
+ return _context26.abrupt("return", []);
1702
2526
  case 3:
1703
2527
  this.logInfo('fetchProductsBySSE: 开始', {
1704
2528
  ids: ids,
1705
2529
  count: ids.length
1706
2530
  });
1707
2531
  t0 = performance.now();
1708
- _context18.prev = 5;
1709
- _context18.next = 8;
2532
+ _context26.prev = 5;
2533
+ _context26.next = 8;
1710
2534
  return this.productDataSource.run({
1711
2535
  sse: {
1712
2536
  query: {
@@ -1716,7 +2540,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1716
2540
  }
1717
2541
  });
1718
2542
  case 8:
1719
- productList = _context18.sent;
2543
+ productList = _context26.sent;
1720
2544
  list = productList || [];
1721
2545
  perfMark('fetchProductsBySSE', performance.now() - t0, {
1722
2546
  count: list.length
@@ -1726,23 +2550,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1726
2550
  receivedCount: list.length,
1727
2551
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1728
2552
  });
1729
- return _context18.abrupt("return", list);
2553
+ return _context26.abrupt("return", list);
1730
2554
  case 15:
1731
- _context18.prev = 15;
1732
- _context18.t0 = _context18["catch"](5);
1733
- errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
2555
+ _context26.prev = 15;
2556
+ _context26.t0 = _context26["catch"](5);
2557
+ errorMessage = _context26.t0 instanceof Error ? _context26.t0.message : String(_context26.t0);
1734
2558
  this.logError('fetchProductsBySSE: 失败', {
1735
2559
  ids: ids,
1736
2560
  error: errorMessage
1737
2561
  });
1738
- return _context18.abrupt("return", []);
2562
+ return _context26.abrupt("return", []);
1739
2563
  case 20:
1740
2564
  case "end":
1741
- return _context18.stop();
2565
+ return _context26.stop();
1742
2566
  }
1743
- }, _callee18, this, [[5, 15]]);
2567
+ }, _callee26, this, [[5, 15]]);
1744
2568
  }));
1745
- function fetchProductsBySSE(_x17) {
2569
+ function fetchProductsBySSE(_x25) {
1746
2570
  return _fetchProductsBySSE.apply(this, arguments);
1747
2571
  }
1748
2572
  return fetchProductsBySSE;
@@ -1750,63 +2574,84 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1750
2574
  /**
1751
2575
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
1752
2576
  * 已存在的 → 直接替换;不存在的 → 追加
1753
- * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
1754
- * 价格缓存由 processProductSyncMessages 末尾统一清除
2577
+ *
2578
+ * @example
2579
+ * await this.applyBodyUpdatesToStore(bodyUpdates, { skipIndexDB: true })
1755
2580
  */
1756
2581
  )
1757
2582
  }, {
1758
2583
  key: "applyBodyUpdatesToStore",
1759
2584
  value: (function () {
1760
- var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(bodyUpdates) {
1761
- var updatedCount, newCount, appliedIds, _iterator8, _step8, _step8$value, id, body;
1762
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1763
- while (1) switch (_context19.prev = _context19.next) {
2585
+ var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(bodyUpdates, options) {
2586
+ var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator16, _step16, _step16$value, id, body;
2587
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2588
+ while (1) switch (_context27.prev = _context27.next) {
1764
2589
  case 0:
2590
+ changedProductIds = _toConsumableArray(bodyUpdates.keys());
1765
2591
  this.logInfo('applyBodyUpdatesToStore: 开始', {
1766
2592
  count: bodyUpdates.size
1767
2593
  });
1768
2594
  updatedCount = 0;
1769
2595
  newCount = 0;
1770
2596
  appliedIds = new Set();
2597
+ mergeActions = {};
2598
+ changedProducts = [];
1771
2599
  this.store.list = this.store.list.map(function (p) {
1772
2600
  if (bodyUpdates.has(p.id)) {
1773
2601
  updatedCount++;
1774
2602
  appliedIds.add(p.id);
1775
- return bodyUpdates.get(p.id);
2603
+ mergeActions[p.id] = 'update';
2604
+ var next = bodyUpdates.get(p.id);
2605
+ changedProducts.push(next);
2606
+ return next;
1776
2607
  }
1777
2608
  return p;
1778
2609
  });
1779
- _iterator8 = _createForOfIteratorHelper(bodyUpdates);
2610
+ _iterator16 = _createForOfIteratorHelper(bodyUpdates);
1780
2611
  try {
1781
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1782
- _step8$value = _slicedToArray(_step8.value, 2), id = _step8$value[0], body = _step8$value[1];
2612
+ for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
2613
+ _step16$value = _slicedToArray(_step16.value, 2), id = _step16$value[0], body = _step16$value[1];
1783
2614
  if (!appliedIds.has(id)) {
1784
2615
  this.store.list.push(body);
1785
2616
  newCount++;
2617
+ mergeActions[id] = 'insert';
2618
+ changedProducts.push(body);
1786
2619
  }
1787
2620
  }
1788
2621
  } catch (err) {
1789
- _iterator8.e(err);
2622
+ _iterator16.e(err);
1790
2623
  } finally {
1791
- _iterator8.f();
2624
+ _iterator16.f();
1792
2625
  }
1793
2626
  this.syncProductsMap();
1794
- _context19.next = 10;
1795
- return this.saveProductsToIndexDB(this.store.list);
1796
- case 10:
1797
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2627
+ if (options !== null && options !== void 0 && options.skipIndexDB) {
2628
+ _context27.next = 14;
2629
+ break;
2630
+ }
2631
+ _context27.next = 14;
2632
+ return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
2633
+ case 14:
2634
+ if (!(options !== null && options !== void 0 && options.skipEmit)) {
2635
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2636
+ }
1798
2637
  this.logInfo('applyBodyUpdatesToStore: 完成', {
1799
2638
  updatedCount: updatedCount,
1800
2639
  newCount: newCount,
1801
2640
  totalCount: this.store.list.length
1802
2641
  });
1803
- case 12:
2642
+ return _context27.abrupt("return", {
2643
+ changedProducts: changedProducts,
2644
+ mergeActions: mergeActions,
2645
+ updatedCount: updatedCount,
2646
+ newCount: newCount
2647
+ });
2648
+ case 17:
1804
2649
  case "end":
1805
- return _context19.stop();
2650
+ return _context27.stop();
1806
2651
  }
1807
- }, _callee19, this);
2652
+ }, _callee27, this);
1808
2653
  }));
1809
- function applyBodyUpdatesToStore(_x18) {
2654
+ function applyBodyUpdatesToStore(_x26, _x27) {
1810
2655
  return _applyBodyUpdatesToStore.apply(this, arguments);
1811
2656
  }
1812
2657
  return applyBodyUpdatesToStore;
@@ -1814,68 +2659,91 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1814
2659
  /**
1815
2660
  * 将增量拉取的商品合并到 store
1816
2661
  * 已存在的 → 替换;新的 → 追加
1817
- * 同时更新 store.map、IndexDB,触发 onProductsChanged
2662
+ *
2663
+ * @example
2664
+ * await this.mergeProductsToStore(freshProducts, { skipIndexDB: true })
1818
2665
  */
1819
2666
  )
1820
2667
  }, {
1821
2668
  key: "mergeProductsToStore",
1822
2669
  value: (function () {
1823
- var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(freshProducts) {
1824
- var freshMap, _iterator9, _step9, p, updatedList, newCount, _iterator10, _step10, _p2, updatedCount;
1825
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1826
- while (1) switch (_context20.prev = _context20.next) {
2670
+ var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(freshProducts, options) {
2671
+ var freshMap, _iterator17, _step17, p, mergeActions, changedProducts, updatedList, newCount, _iterator18, _step18, _p2, updatedCount, changedProductIds;
2672
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2673
+ while (1) switch (_context28.prev = _context28.next) {
1827
2674
  case 0:
1828
2675
  freshMap = new Map();
1829
- _iterator9 = _createForOfIteratorHelper(freshProducts);
2676
+ _iterator17 = _createForOfIteratorHelper(freshProducts);
1830
2677
  try {
1831
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1832
- p = _step9.value;
2678
+ for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
2679
+ p = _step17.value;
1833
2680
  freshMap.set(p.id, p);
1834
2681
  }
1835
2682
  } catch (err) {
1836
- _iterator9.e(err);
2683
+ _iterator17.e(err);
1837
2684
  } finally {
1838
- _iterator9.f();
2685
+ _iterator17.f();
1839
2686
  }
2687
+ mergeActions = {};
2688
+ changedProducts = [];
1840
2689
  updatedList = this.store.list.map(function (p) {
1841
2690
  if (freshMap.has(p.id)) {
1842
2691
  var fresh = freshMap.get(p.id);
1843
2692
  freshMap.delete(p.id);
2693
+ mergeActions[p.id] = 'update';
2694
+ changedProducts.push(fresh);
1844
2695
  return fresh;
1845
2696
  }
1846
2697
  return p;
1847
2698
  }); // freshMap 中剩余的是新商品(create 场景)
1848
2699
  newCount = freshMap.size;
1849
- _iterator10 = _createForOfIteratorHelper(freshMap.values());
2700
+ _iterator18 = _createForOfIteratorHelper(freshMap.values());
1850
2701
  try {
1851
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1852
- _p2 = _step10.value;
2702
+ for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
2703
+ _p2 = _step18.value;
1853
2704
  updatedList.push(_p2);
2705
+ mergeActions[_p2.id] = 'insert';
2706
+ changedProducts.push(_p2);
1854
2707
  }
1855
2708
  } catch (err) {
1856
- _iterator10.e(err);
2709
+ _iterator18.e(err);
1857
2710
  } finally {
1858
- _iterator10.f();
2711
+ _iterator18.f();
1859
2712
  }
1860
2713
  updatedCount = freshProducts.length - newCount;
2714
+ changedProductIds = freshProducts.map(function (p) {
2715
+ return p.id;
2716
+ });
1861
2717
  this.store.list = updatedList;
1862
2718
  this.syncProductsMap();
1863
- _context20.next = 12;
1864
- return this.saveProductsToIndexDB(this.store.list);
1865
- case 12:
2719
+ if (options !== null && options !== void 0 && options.skipIndexDB) {
2720
+ _context28.next = 16;
2721
+ break;
2722
+ }
2723
+ _context28.next = 16;
2724
+ return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
2725
+ case 16:
2726
+ if (!(options !== null && options !== void 0 && options.skipEmit)) {
2727
+ this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2728
+ }
1866
2729
  this.logInfo('mergeProductsToStore: 合并完成', {
1867
2730
  updatedCount: updatedCount,
1868
2731
  newCount: newCount,
1869
2732
  totalCount: this.store.list.length
1870
2733
  });
1871
- this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1872
- case 14:
2734
+ return _context28.abrupt("return", {
2735
+ changedProducts: changedProducts,
2736
+ mergeActions: mergeActions,
2737
+ updatedCount: updatedCount,
2738
+ newCount: newCount
2739
+ });
2740
+ case 19:
1873
2741
  case "end":
1874
- return _context20.stop();
2742
+ return _context28.stop();
1875
2743
  }
1876
- }, _callee20, this);
2744
+ }, _callee28, this);
1877
2745
  }));
1878
- function mergeProductsToStore(_x19) {
2746
+ function mergeProductsToStore(_x28, _x29) {
1879
2747
  return _mergeProductsToStore.apply(this, arguments);
1880
2748
  }
1881
2749
  return mergeProductsToStore;
@@ -1889,56 +2757,65 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1889
2757
  }, {
1890
2758
  key: "silentRefresh",
1891
2759
  value: (function () {
1892
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
1893
- var t0, products, errorMessage;
1894
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1895
- while (1) switch (_context21.prev = _context21.next) {
2760
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
2761
+ var t0, now, elapsedSincePreload, elapsedSinceFullFetch, products, errorMessage;
2762
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2763
+ while (1) switch (_context29.prev = _context29.next) {
1896
2764
  case 0:
1897
2765
  t0 = performance.now();
2766
+ now = Date.now();
2767
+ elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
2768
+ elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
2769
+ if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
2770
+ _context29.next = 6;
2771
+ break;
2772
+ }
2773
+ return _context29.abrupt("return", this.store.list);
2774
+ case 6:
1898
2775
  this.logInfo('silentRefresh 开始');
1899
- _context21.prev = 2;
1900
- _context21.next = 5;
2776
+ _context29.prev = 7;
2777
+ _context29.next = 10;
1901
2778
  return this.loadProductsByServer();
1902
- case 5:
1903
- products = _context21.sent;
2779
+ case 10:
2780
+ products = _context29.sent;
1904
2781
  if (!(products && products.length > 0)) {
1905
- _context21.next = 16;
2782
+ _context29.next = 21;
1906
2783
  break;
1907
2784
  }
1908
2785
  this.store.list = products;
1909
2786
  this.syncProductsMap();
1910
2787
  this.clearPriceCache();
1911
2788
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1912
- _context21.next = 13;
2789
+ _context29.next = 18;
1913
2790
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1914
- case 13:
2791
+ case 18:
1915
2792
  this.logInfo('silentRefresh 完成', {
1916
2793
  productCount: products.length,
1917
2794
  duration: "".concat(Math.round(performance.now() - t0), "ms")
1918
2795
  });
1919
- _context21.next = 17;
2796
+ _context29.next = 22;
1920
2797
  break;
1921
- case 16:
2798
+ case 21:
1922
2799
  this.logWarning('silentRefresh: 服务器未返回数据');
1923
- case 17:
2800
+ case 22:
1924
2801
  perfMark('silentRefresh', performance.now() - t0, {
1925
2802
  count: this.store.list.length
1926
2803
  });
1927
- return _context21.abrupt("return", this.store.list);
1928
- case 21:
1929
- _context21.prev = 21;
1930
- _context21.t0 = _context21["catch"](2);
1931
- errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
2804
+ return _context29.abrupt("return", this.store.list);
2805
+ case 26:
2806
+ _context29.prev = 26;
2807
+ _context29.t0 = _context29["catch"](7);
2808
+ errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
1932
2809
  this.logError('silentRefresh 失败', {
1933
2810
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
1934
2811
  error: errorMessage
1935
2812
  });
1936
- return _context21.abrupt("return", this.store.list);
1937
- case 26:
2813
+ return _context29.abrupt("return", this.store.list);
2814
+ case 31:
1938
2815
  case "end":
1939
- return _context21.stop();
2816
+ return _context29.stop();
1940
2817
  }
1941
- }, _callee21, this, [[2, 21]]);
2818
+ }, _callee29, this, [[7, 26]]);
1942
2819
  }));
1943
2820
  function silentRefresh() {
1944
2821
  return _silentRefresh.apply(this, arguments);