@pisell/pisellos 0.0.568 → 0.10.1

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 (588) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +24 -96
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +2 -2
  13. package/dist/modules/BaseModule.js +12 -14
  14. package/dist/modules/BookingContext/index.d.ts +48 -0
  15. package/dist/modules/BookingContext/index.js +566 -0
  16. package/dist/modules/BookingContext/types.d.ts +102 -0
  17. package/dist/modules/BookingContext/types.js +51 -0
  18. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  19. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
  20. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  21. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
  22. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  23. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
  24. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  25. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  26. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  27. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  28. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  29. package/dist/modules/BookingContext/utils/index.js +11 -0
  30. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  31. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  32. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  33. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  34. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  35. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  36. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  37. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  38. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  39. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  40. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  41. package/dist/modules/BookingContext/utils/resources.js +486 -0
  42. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  43. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  44. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  45. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  46. package/dist/modules/Cart/index.js +3 -0
  47. package/dist/modules/Cart/utils/cartProduct.js +27 -5
  48. package/dist/modules/Cart/utils/cartResource.js +0 -2
  49. package/dist/modules/Cart/utils/changePrice.js +11 -11
  50. package/dist/modules/Customer/index.d.ts +20 -0
  51. package/dist/modules/Customer/index.js +172 -83
  52. package/dist/modules/Customer/types.d.ts +2 -0
  53. package/dist/modules/Date/index.js +5 -1
  54. package/dist/modules/Discount/index.d.ts +2 -2
  55. package/dist/modules/Discount/index.js +43 -30
  56. package/dist/modules/Discount/types.d.ts +1 -1
  57. package/dist/modules/OpenData/index.d.ts +8 -0
  58. package/dist/modules/OpenData/index.js +38 -16
  59. package/dist/modules/Order/index.d.ts +449 -24
  60. package/dist/modules/Order/index.js +5460 -574
  61. package/dist/modules/Order/types.d.ts +693 -88
  62. package/dist/modules/Order/types.js +68 -1
  63. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  64. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  65. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  66. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  67. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  68. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  69. package/dist/modules/Order/utils.d.ts +167 -18
  70. package/dist/modules/Order/utils.js +960 -165
  71. package/dist/modules/Payment/index.d.ts +10 -9
  72. package/dist/modules/Payment/index.js +573 -746
  73. package/dist/modules/Payment/types.d.ts +44 -24
  74. package/dist/modules/Payment/utils.d.ts +1 -1
  75. package/dist/modules/Payment/utils.js +4 -3
  76. package/dist/modules/Payment/walletpass.d.ts +0 -2
  77. package/dist/modules/Payment/walletpass.js +49 -33
  78. package/dist/modules/Product/types.d.ts +29 -7
  79. package/dist/modules/ProductList/index.d.ts +17 -13
  80. package/dist/modules/ProductList/index.js +182 -81
  81. package/dist/modules/ProductList/types.d.ts +16 -0
  82. package/dist/modules/Quotation/index.d.ts +22 -2
  83. package/dist/modules/Quotation/index.js +108 -42
  84. package/dist/modules/Quotation/types.d.ts +19 -0
  85. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  86. package/dist/modules/ResourcePlanner/index.js +181 -0
  87. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  88. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  89. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  90. package/dist/modules/ResourcePlanner/types.js +1 -0
  91. package/dist/modules/Rules/index.d.ts +8 -10
  92. package/dist/modules/Rules/index.js +324 -513
  93. package/dist/modules/Rules/types.d.ts +14 -3
  94. package/dist/modules/SalesSummary/index.d.ts +23 -26
  95. package/dist/modules/SalesSummary/index.js +152 -46
  96. package/dist/modules/SalesSummary/types.d.ts +9 -1
  97. package/dist/modules/SalesSummary/utils.d.ts +3 -22
  98. package/dist/modules/SalesSummary/utils.js +804 -165
  99. package/dist/modules/Schedule/getDateIsInSchedule.js +14 -12
  100. package/dist/modules/Schedule/index.d.ts +18 -5
  101. package/dist/modules/Schedule/index.js +79 -24
  102. package/dist/modules/Schedule/types.d.ts +2 -0
  103. package/dist/modules/Schedule/utils.js +1 -0
  104. package/dist/modules/Step/index.js +1 -0
  105. package/dist/modules/Summary/index.js +4 -3
  106. package/dist/modules/Summary/utils.js +22 -43
  107. package/dist/modules/SurchargeList/index.d.ts +18 -0
  108. package/dist/modules/SurchargeList/index.js +185 -0
  109. package/dist/modules/SurchargeList/types.d.ts +15 -0
  110. package/dist/modules/SurchargeList/types.js +1 -0
  111. package/dist/modules/index.d.ts +3 -0
  112. package/dist/modules/index.js +4 -1
  113. package/dist/plugins/app.d.ts +2 -0
  114. package/dist/plugins/request.d.ts +1 -0
  115. package/dist/plugins/request.js +4 -1
  116. package/dist/plugins/window.js +6 -2
  117. package/dist/server/index.d.ts +462 -8
  118. package/dist/server/index.js +6168 -680
  119. package/dist/server/modules/floor-plan/index.d.ts +39 -0
  120. package/dist/server/modules/floor-plan/index.js +595 -0
  121. package/dist/server/modules/floor-plan/types.d.ts +43 -0
  122. package/dist/server/modules/floor-plan/types.js +13 -0
  123. package/dist/server/modules/index.d.ts +7 -2
  124. package/dist/server/modules/index.js +6 -0
  125. package/dist/server/modules/menu/index.js +41 -32
  126. package/dist/server/modules/order/index.d.ts +207 -14
  127. package/dist/server/modules/order/index.js +2328 -379
  128. package/dist/server/modules/order/types.d.ts +76 -5
  129. package/dist/server/modules/order/types.js +14 -1
  130. package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
  131. package/dist/server/modules/order/utils/filterBookings.js +118 -11
  132. package/dist/server/modules/order/utils/filterOrders.js +242 -14
  133. package/dist/server/modules/payment/index.d.ts +28 -0
  134. package/dist/server/modules/payment/index.js +305 -0
  135. package/dist/server/modules/payment/types.d.ts +9 -0
  136. package/dist/server/modules/payment/types.js +1 -0
  137. package/dist/server/modules/products/index.d.ts +105 -14
  138. package/dist/server/modules/products/index.js +1416 -521
  139. package/dist/server/modules/products/types.d.ts +34 -1
  140. package/dist/server/modules/products/types.js +4 -0
  141. package/dist/server/modules/quotation/index.d.ts +39 -0
  142. package/dist/server/modules/quotation/index.js +298 -77
  143. package/dist/server/modules/resource/index.d.ts +2 -3
  144. package/dist/server/modules/resource/index.js +109 -86
  145. package/dist/server/modules/schedule/index.d.ts +6 -4
  146. package/dist/server/modules/schedule/index.js +145 -106
  147. package/dist/server/test.json +713 -0
  148. package/dist/server/types.d.ts +2 -0
  149. package/dist/server/utils/product.js +3 -2
  150. package/dist/server/utils/small-ticket.d.ts +71 -0
  151. package/dist/server/utils/small-ticket.js +963 -0
  152. package/dist/solution/BaseSales/index.d.ts +378 -0
  153. package/dist/solution/BaseSales/index.js +4009 -0
  154. package/dist/solution/BaseSales/types.d.ts +394 -0
  155. package/dist/solution/BaseSales/types.js +40 -0
  156. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  157. package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
  158. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  159. package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
  160. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  161. package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
  162. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  163. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
  164. package/dist/solution/BaseSales/utils.d.ts +40 -0
  165. package/dist/solution/BaseSales/utils.js +263 -0
  166. package/dist/solution/BookingByStep/index.d.ts +1 -1
  167. package/dist/solution/BookingByStep/index.js +60 -11
  168. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  169. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  170. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  171. package/dist/solution/BookingTicket/index.d.ts +393 -24
  172. package/dist/solution/BookingTicket/index.js +2508 -443
  173. package/dist/solution/BookingTicket/types.d.ts +191 -6
  174. package/dist/solution/BookingTicket/types.js +83 -10
  175. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  176. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  177. package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  178. package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
  179. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  180. package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
  181. package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
  182. package/dist/solution/BookingTicket/utils/cartView.js +209 -0
  183. package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  184. package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
  185. package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  186. package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
  187. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  188. package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
  189. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  190. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
  191. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  192. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +42 -1
  193. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  194. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
  195. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  196. package/dist/solution/BookingTicket/utils/scan/handleScan.js +42 -28
  197. package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  198. package/dist/solution/BookingTicket/utils/scan/index.js +30 -14
  199. package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  200. package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
  201. package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  202. package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
  203. package/dist/solution/BuyTickets/index.js +12 -9
  204. package/dist/solution/Checkout/index.d.ts +1 -0
  205. package/dist/solution/Checkout/index.js +275 -209
  206. package/dist/solution/Checkout/utils/index.js +20 -8
  207. package/dist/solution/RegisterAndLogin/config.js +2 -10
  208. package/dist/solution/RegisterAndLogin/index.js +76 -30
  209. package/dist/solution/Sales/index.d.ts +50 -5
  210. package/dist/solution/Sales/index.js +484 -92
  211. package/dist/solution/Sales/types.d.ts +26 -2
  212. package/dist/solution/ScanOrder/index.d.ts +27 -21
  213. package/dist/solution/ScanOrder/index.js +519 -444
  214. package/dist/solution/ScanOrder/types.d.ts +33 -11
  215. package/dist/solution/ScanOrder/types.js +4 -5
  216. package/dist/solution/ScanOrder/utils.d.ts +4 -1
  217. package/dist/solution/ScanOrder/utils.js +109 -34
  218. package/dist/solution/ShopDiscount/index.js +18 -19
  219. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  220. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  221. package/dist/solution/ShopDiscount/utils.js +0 -9
  222. package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
  223. package/dist/solution/UnifiedBookingSales/index.js +1871 -0
  224. package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
  225. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  226. package/dist/solution/VenueBooking/index.d.ts +32 -51
  227. package/dist/solution/VenueBooking/index.js +741 -808
  228. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  229. package/dist/solution/VenueBooking/types.d.ts +1 -3
  230. package/dist/solution/VenueBooking/types.js +0 -1
  231. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  232. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  233. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  234. package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
  235. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  236. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  237. package/dist/solution/index.d.ts +2 -0
  238. package/dist/solution/index.js +3 -1
  239. package/dist/types/index.d.ts +12 -2
  240. package/dist/utils/task.js +18 -15
  241. package/dist/utils/watch.js +1 -0
  242. package/lib/apis/picoding.js +0 -2
  243. package/lib/core/index.js +132 -130
  244. package/lib/effects/index.js +57 -46
  245. package/lib/index.d.ts +0 -1
  246. package/lib/index.js +50 -92
  247. package/lib/model/index.js +21 -14
  248. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  249. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  250. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  251. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  252. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  253. package/lib/model/strategy/adapter/index.js +64 -100
  254. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  255. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  256. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  257. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  258. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  259. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  260. package/lib/model/strategy/adapter/promotion/evaluator.js +233 -382
  261. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  262. package/lib/model/strategy/adapter/promotion/index.js +0 -1
  263. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  264. package/lib/model/strategy/adapter/type.js +16 -4
  265. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  266. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  267. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  268. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  269. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  270. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  271. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  272. package/lib/model/strategy/adapter/walletPass/utils.js +383 -676
  273. package/lib/model/strategy/engine.js +168 -270
  274. package/lib/model/strategy/index.js +34 -49
  275. package/lib/model/strategy/strategy-example.js +239 -243
  276. package/lib/model/strategy/type.js +40 -100
  277. package/lib/modules/Account/index.js +53 -39
  278. package/lib/modules/Account/types.js +33 -20
  279. package/lib/modules/AccountList/index.js +154 -116
  280. package/lib/modules/AccountList/types.js +31 -30
  281. package/lib/modules/AccountList/utils.js +30 -18
  282. package/lib/modules/BaseModule.d.ts +2 -2
  283. package/lib/modules/BaseModule.js +50 -29
  284. package/lib/modules/BookingContext/index.d.ts +48 -0
  285. package/lib/modules/BookingContext/index.js +368 -0
  286. package/lib/modules/BookingContext/types.d.ts +102 -0
  287. package/lib/modules/BookingContext/types.js +34 -0
  288. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  289. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +298 -0
  290. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  291. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +155 -0
  292. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
  293. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +222 -0
  294. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  295. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  296. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  297. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  298. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  299. package/lib/modules/BookingContext/utils/index.js +43 -0
  300. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  301. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  302. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  303. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  304. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  305. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  306. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  307. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  308. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  309. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  310. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  311. package/lib/modules/BookingContext/utils/resources.js +377 -0
  312. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  313. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  314. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  315. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  316. package/lib/modules/Cart/index.js +124 -170
  317. package/lib/modules/Cart/types.js +51 -46
  318. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  319. package/lib/modules/Cart/utils/cartDate.js +61 -56
  320. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  321. package/lib/modules/Cart/utils/cartNote.js +32 -27
  322. package/lib/modules/Cart/utils/cartProduct.js +261 -309
  323. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  324. package/lib/modules/Cart/utils/cartResource.js +78 -72
  325. package/lib/modules/Cart/utils/changePrice.js +59 -31
  326. package/lib/modules/Cart/utils/index.js +48 -106
  327. package/lib/modules/Customer/constants.js +34 -13
  328. package/lib/modules/Customer/index.d.ts +20 -0
  329. package/lib/modules/Customer/index.js +207 -217
  330. package/lib/modules/Customer/types.d.ts +2 -0
  331. package/lib/modules/Customer/types.js +35 -38
  332. package/lib/modules/Date/index.js +115 -116
  333. package/lib/modules/Date/types.js +28 -16
  334. package/lib/modules/Date/utils.js +123 -174
  335. package/lib/modules/Discount/index.d.ts +2 -2
  336. package/lib/modules/Discount/index.js +133 -119
  337. package/lib/modules/Discount/types.d.ts +1 -1
  338. package/lib/modules/Discount/types.js +31 -9
  339. package/lib/modules/Guests/index.js +56 -30
  340. package/lib/modules/Guests/types.js +33 -23
  341. package/lib/modules/Holder/index.js +189 -209
  342. package/lib/modules/Holder/types.js +16 -4
  343. package/lib/modules/Holder/utils.js +49 -20
  344. package/lib/modules/OpenData/index.d.ts +8 -0
  345. package/lib/modules/OpenData/index.js +88 -63
  346. package/lib/modules/OpenData/types.js +16 -4
  347. package/lib/modules/OpenData/utils.js +78 -44
  348. package/lib/modules/Order/index.d.ts +449 -24
  349. package/lib/modules/Order/index.js +4184 -514
  350. package/lib/modules/Order/types.d.ts +693 -88
  351. package/lib/modules/Order/types.js +35 -24
  352. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  353. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  354. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  355. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  356. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  357. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  358. package/lib/modules/Order/utils.d.ts +167 -18
  359. package/lib/modules/Order/utils.js +1085 -414
  360. package/lib/modules/Payment/cash.js +33 -20
  361. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  362. package/lib/modules/Payment/eftpos.js +30 -16
  363. package/lib/modules/Payment/index.d.ts +10 -9
  364. package/lib/modules/Payment/index.js +402 -636
  365. package/lib/modules/Payment/mx51.js +0 -1
  366. package/lib/modules/Payment/types.d.ts +44 -24
  367. package/lib/modules/Payment/types.js +107 -216
  368. package/lib/modules/Payment/utils.d.ts +1 -1
  369. package/lib/modules/Payment/utils.js +50 -52
  370. package/lib/modules/Payment/walletpass.d.ts +0 -2
  371. package/lib/modules/Payment/walletpass.js +216 -221
  372. package/lib/modules/Product/index.js +46 -51
  373. package/lib/modules/Product/types.d.ts +29 -7
  374. package/lib/modules/Product/types.js +16 -4
  375. package/lib/modules/Product/utils.js +33 -32
  376. package/lib/modules/ProductList/index.d.ts +17 -13
  377. package/lib/modules/ProductList/index.js +161 -120
  378. package/lib/modules/ProductList/types.d.ts +16 -0
  379. package/lib/modules/ProductList/types.js +31 -9
  380. package/lib/modules/Quotation/index.d.ts +22 -2
  381. package/lib/modules/Quotation/index.js +154 -64
  382. package/lib/modules/Quotation/types.d.ts +19 -0
  383. package/lib/modules/Quotation/types.js +16 -4
  384. package/lib/modules/Resource/index.js +59 -27
  385. package/lib/modules/Resource/types.js +32 -22
  386. package/lib/modules/Resource/utils.js +38 -30
  387. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  388. package/lib/modules/ResourcePlanner/index.js +148 -0
  389. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  390. package/lib/modules/ResourcePlanner/planner.js +933 -0
  391. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  392. package/lib/modules/ResourcePlanner/types.js +17 -0
  393. package/lib/modules/Rules/index.d.ts +8 -10
  394. package/lib/modules/Rules/index.js +960 -1440
  395. package/lib/modules/Rules/types.d.ts +14 -3
  396. package/lib/modules/Rules/types.js +40 -17
  397. package/lib/modules/SalesSummary/index.d.ts +23 -26
  398. package/lib/modules/SalesSummary/index.js +134 -61
  399. package/lib/modules/SalesSummary/types.d.ts +9 -1
  400. package/lib/modules/SalesSummary/types.js +16 -4
  401. package/lib/modules/SalesSummary/utils.d.ts +3 -22
  402. package/lib/modules/SalesSummary/utils.js +814 -233
  403. package/lib/modules/ScanOrderLogger/index.js +79 -59
  404. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  405. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  406. package/lib/modules/ScanOrderLogger/types.js +16 -4
  407. package/lib/modules/Schedule/getDateIsInSchedule.js +169 -338
  408. package/lib/modules/Schedule/index.d.ts +18 -5
  409. package/lib/modules/Schedule/index.js +153 -104
  410. package/lib/modules/Schedule/type.js +16 -4
  411. package/lib/modules/Schedule/types.d.ts +2 -0
  412. package/lib/modules/Schedule/types.js +16 -4
  413. package/lib/modules/Schedule/utils.js +291 -433
  414. package/lib/modules/Step/index.js +52 -40
  415. package/lib/modules/Step/tyeps.js +16 -4
  416. package/lib/modules/Summary/index.js +71 -66
  417. package/lib/modules/Summary/types.js +16 -4
  418. package/lib/modules/Summary/utils.js +418 -791
  419. package/lib/modules/SurchargeList/index.d.ts +18 -0
  420. package/lib/modules/SurchargeList/index.js +109 -0
  421. package/lib/modules/SurchargeList/types.d.ts +15 -0
  422. package/lib/modules/SurchargeList/types.js +17 -0
  423. package/lib/modules/index.d.ts +3 -0
  424. package/lib/modules/index.js +63 -212
  425. package/lib/plugins/app.d.ts +2 -0
  426. package/lib/plugins/app.js +16 -4
  427. package/lib/plugins/index.js +25 -36
  428. package/lib/plugins/request.d.ts +1 -0
  429. package/lib/plugins/request.js +126 -137
  430. package/lib/plugins/shopStore.js +16 -4
  431. package/lib/plugins/user.js +16 -4
  432. package/lib/plugins/window.js +179 -171
  433. package/lib/server/index.d.ts +462 -8
  434. package/lib/server/index.js +4520 -1162
  435. package/lib/server/modules/floor-plan/index.d.ts +39 -0
  436. package/lib/server/modules/floor-plan/index.js +327 -0
  437. package/lib/server/modules/floor-plan/types.d.ts +43 -0
  438. package/lib/server/modules/floor-plan/types.js +34 -0
  439. package/lib/server/modules/index.d.ts +7 -2
  440. package/lib/server/modules/index.js +67 -84
  441. package/lib/server/modules/menu/index.js +122 -146
  442. package/lib/server/modules/menu/types.js +31 -18
  443. package/lib/server/modules/order/index.d.ts +207 -14
  444. package/lib/server/modules/order/index.js +1543 -285
  445. package/lib/server/modules/order/types.d.ts +76 -5
  446. package/lib/server/modules/order/types.js +32 -107
  447. package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
  448. package/lib/server/modules/order/utils/filterBookings.js +259 -176
  449. package/lib/server/modules/order/utils/filterOrders.js +293 -94
  450. package/lib/server/modules/payment/index.d.ts +28 -0
  451. package/lib/server/modules/payment/index.js +192 -0
  452. package/lib/server/modules/payment/types.d.ts +9 -0
  453. package/lib/server/modules/payment/types.js +17 -0
  454. package/lib/server/modules/products/index.d.ts +105 -14
  455. package/lib/server/modules/products/index.js +850 -475
  456. package/lib/server/modules/products/types.d.ts +34 -1
  457. package/lib/server/modules/products/types.js +34 -41
  458. package/lib/server/modules/quotation/index.d.ts +39 -0
  459. package/lib/server/modules/quotation/index.js +254 -75
  460. package/lib/server/modules/quotation/types.js +31 -21
  461. package/lib/server/modules/resource/index.d.ts +2 -3
  462. package/lib/server/modules/resource/index.js +240 -243
  463. package/lib/server/modules/resource/types.js +33 -42
  464. package/lib/server/modules/schedule/index.d.ts +6 -4
  465. package/lib/server/modules/schedule/index.js +146 -147
  466. package/lib/server/modules/schedule/types.js +21 -14
  467. package/lib/server/modules/schedule/utils.js +163 -334
  468. package/lib/server/test.json +713 -0
  469. package/lib/server/types.d.ts +2 -0
  470. package/lib/server/types.js +16 -4
  471. package/lib/server/utils/index.js +23 -25
  472. package/lib/server/utils/product.js +140 -197
  473. package/lib/server/utils/schedule.js +41 -34
  474. package/lib/server/utils/small-ticket.d.ts +71 -0
  475. package/lib/server/utils/small-ticket.js +904 -0
  476. package/lib/server/utils/time.js +49 -40
  477. package/lib/solution/BaseSales/index.d.ts +378 -0
  478. package/lib/solution/BaseSales/index.js +2533 -0
  479. package/lib/solution/BaseSales/types.d.ts +394 -0
  480. package/lib/solution/BaseSales/types.js +43 -0
  481. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
  482. package/lib/solution/BaseSales/utils/cartPromotion.js +1004 -0
  483. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
  484. package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
  485. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
  486. package/lib/solution/BaseSales/utils/quotationPrice.js +289 -0
  487. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
  488. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +256 -0
  489. package/lib/solution/BaseSales/utils.d.ts +40 -0
  490. package/lib/solution/BaseSales/utils.js +244 -0
  491. package/lib/solution/BookingByStep/index.d.ts +1 -1
  492. package/lib/solution/BookingByStep/index.js +1340 -1530
  493. package/lib/solution/BookingByStep/types.js +99 -40
  494. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  495. package/lib/solution/BookingByStep/utils/products.js +52 -42
  496. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  497. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  498. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  499. package/lib/solution/BookingTicket/index.d.ts +393 -24
  500. package/lib/solution/BookingTicket/index.js +1374 -184
  501. package/lib/solution/BookingTicket/types.d.ts +191 -6
  502. package/lib/solution/BookingTicket/types.js +79 -40
  503. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
  504. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  505. package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
  506. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
  507. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
  508. package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -0
  509. package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
  510. package/lib/solution/BookingTicket/utils/cartView.js +184 -0
  511. package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
  512. package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
  513. package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
  514. package/lib/solution/BookingTicket/utils/orderCustomer.js +58 -0
  515. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
  516. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
  517. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
  518. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
  519. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
  520. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +97 -64
  521. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
  522. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
  523. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  524. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -82
  525. package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
  526. package/lib/solution/BookingTicket/utils/scan/index.js +109 -91
  527. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  528. package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
  529. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
  530. package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
  531. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
  532. package/lib/solution/BuyTickets/index.js +70 -67
  533. package/lib/solution/BuyTickets/types.js +38 -22
  534. package/lib/solution/Checkout/index.d.ts +1 -0
  535. package/lib/solution/Checkout/index.js +1169 -1463
  536. package/lib/solution/Checkout/types.js +61 -91
  537. package/lib/solution/Checkout/utils/index.js +156 -228
  538. package/lib/solution/PlaceOrder/index.js +0 -55
  539. package/lib/solution/RegisterAndLogin/config.js +462 -503
  540. package/lib/solution/RegisterAndLogin/index.js +630 -633
  541. package/lib/solution/RegisterAndLogin/types.js +76 -189
  542. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  543. package/lib/solution/Sales/index.d.ts +50 -5
  544. package/lib/solution/Sales/index.js +498 -238
  545. package/lib/solution/Sales/types.d.ts +26 -2
  546. package/lib/solution/Sales/types.js +33 -27
  547. package/lib/solution/ScanOrder/index.d.ts +27 -21
  548. package/lib/solution/ScanOrder/index.js +936 -864
  549. package/lib/solution/ScanOrder/types.d.ts +33 -11
  550. package/lib/solution/ScanOrder/types.js +34 -34
  551. package/lib/solution/ScanOrder/utils.d.ts +4 -1
  552. package/lib/solution/ScanOrder/utils.js +422 -385
  553. package/lib/solution/ShopDiscount/index.js +233 -235
  554. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  555. package/lib/solution/ShopDiscount/types.js +37 -15
  556. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  557. package/lib/solution/ShopDiscount/utils.js +172 -309
  558. package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
  559. package/lib/solution/UnifiedBookingSales/index.js +1076 -0
  560. package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
  561. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  562. package/lib/solution/VenueBooking/index.d.ts +32 -51
  563. package/lib/solution/VenueBooking/index.js +1008 -984
  564. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  565. package/lib/solution/VenueBooking/types.d.ts +1 -3
  566. package/lib/solution/VenueBooking/types.js +39 -20
  567. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  568. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  569. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  570. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
  571. package/lib/solution/VenueBooking/utils/slotMerge.js +109 -90
  572. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  573. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  574. package/lib/solution/VenueBooking/utils.js +67 -130
  575. package/lib/solution/index.d.ts +2 -0
  576. package/lib/solution/index.js +41 -102
  577. package/lib/store/createStore.js +29 -32
  578. package/lib/types/index.d.ts +12 -2
  579. package/lib/types/index.js +16 -4
  580. package/lib/utils/task.js +36 -36
  581. package/lib/utils/watch.js +47 -81
  582. package/package.json +2 -4
  583. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  584. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  585. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  586. package/lib/solution/Checkout/appointmentDemo.json +0 -1
  587. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  588. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,128 +1,122 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/model/strategy/adapter/promotion/evaluator.ts
30
+ var evaluator_exports = {};
31
+ __export(evaluator_exports, {
32
+ PromotionEvaluator: () => PromotionEvaluator
5
33
  });
6
- exports.PromotionEvaluator = void 0;
7
- var _decimal = _interopRequireDefault(require("decimal.js"));
8
- var _engine = require("../../engine");
9
- var _adapter = require("./adapter");
10
- var _type = require("./type");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- // ============================================
13
- // 类型定义
14
- // ============================================
15
-
16
- // ============================================
17
- // 多语言定义
18
- // ============================================
19
-
20
- const defaultLocales = {
34
+ module.exports = __toCommonJS(evaluator_exports);
35
+ var import_decimal = __toESM(require("decimal.js"));
36
+ var import_engine = require("../../engine");
37
+ var import_adapter = require("./adapter");
38
+ var import_type = require("./type");
39
+ var defaultLocales = {
21
40
  en: {
22
- no_applicable_promotion: 'No applicable promotion',
23
- promotion_not_in_time_range: 'Promotion not in valid time range',
24
- product_not_in_promotion: 'Product not in promotion scope'
41
+ no_applicable_promotion: "No applicable promotion",
42
+ promotion_not_in_time_range: "Promotion not in valid time range",
43
+ product_not_in_promotion: "Product not in promotion scope"
25
44
  },
26
- 'zh-CN': {
27
- no_applicable_promotion: '无适用的促销活动',
28
- promotion_not_in_time_range: '促销活动不在有效时间范围内',
29
- product_not_in_promotion: '商品不在促销范围内'
45
+ "zh-CN": {
46
+ no_applicable_promotion: "无适用的促销活动",
47
+ promotion_not_in_time_range: "促销活动不在有效时间范围内",
48
+ product_not_in_promotion: "商品不在促销范围内"
30
49
  },
31
- 'zh-HK': {
32
- no_applicable_promotion: '無適用的促銷活動',
33
- promotion_not_in_time_range: '促銷活動不在有效時間範圍內',
34
- product_not_in_promotion: '商品不在促銷範圍內'
50
+ "zh-HK": {
51
+ no_applicable_promotion: "無適用的促銷活動",
52
+ promotion_not_in_time_range: "促銷活動不在有效時間範圍內",
53
+ product_not_in_promotion: "商品不在促銷範圍內"
35
54
  }
36
55
  };
37
-
38
- // ============================================
39
- // PromotionEvaluator 实现
40
- // ============================================
41
-
42
- /**
43
- * Promotion 评估器
44
- *
45
- * 用于评估商品适用的促销活动
46
- * 封装了 StrategyEngine 和 PromotionAdapter 的调用逻辑
47
- */
48
- class PromotionEvaluator {
49
- engine;
50
- adapter;
51
- strategyConfigs = [];
52
- locale = 'en';
53
- locales = defaultLocales;
56
+ var PromotionEvaluator = class {
54
57
  constructor() {
55
- this.engine = new _engine.StrategyEngine({
58
+ this.strategyConfigs = [];
59
+ this.locale = "en";
60
+ this.locales = defaultLocales;
61
+ this.engine = new import_engine.StrategyEngine({
56
62
  debug: false,
57
63
  enableTrace: false
58
64
  });
59
- this.adapter = new _adapter.PromotionAdapter();
65
+ this.adapter = new import_adapter.PromotionAdapter();
60
66
  }
61
-
62
67
  // ============================================
63
68
  // 配置管理
64
69
  // ============================================
65
-
66
70
  /**
67
71
  * 设置策略配置列表
68
72
  */
69
73
  setStrategyConfigs(strategyConfigs) {
70
- const newStrategyConfigs = strategyConfigs.filter(item => item.metadata.type === 'promotion');
74
+ const newStrategyConfigs = strategyConfigs.filter((item) => item.metadata.type === "promotion");
71
75
  this.strategyConfigs = newStrategyConfigs;
72
76
  }
73
-
74
77
  /**
75
78
  * 获取策略配置列表
76
79
  */
77
80
  getStrategyConfigs() {
78
81
  return this.strategyConfigs;
79
82
  }
80
-
81
83
  /**
82
84
  * 添加策略配置
83
85
  */
84
86
  addStrategyConfig(strategyConfig) {
85
87
  this.strategyConfigs.push(strategyConfig);
86
88
  }
87
-
88
89
  /**
89
90
  * 设置语言
90
91
  */
91
92
  setLocale(locale) {
92
93
  this.locale = locale;
93
94
  }
94
-
95
95
  /**
96
96
  * 设置自定义多语言文案
97
97
  */
98
98
  setLocales(locales) {
99
- this.locales = {
100
- ...defaultLocales,
101
- ...locales
102
- };
99
+ this.locales = { ...defaultLocales, ...locales };
103
100
  }
104
-
105
101
  /**
106
102
  * 获取多语言文案
107
103
  */
108
104
  getText(key) {
109
- return this.locales?.[this.locale]?.[key] || key;
105
+ var _a, _b;
106
+ return ((_b = (_a = this.locales) == null ? void 0 : _a[this.locale]) == null ? void 0 : _b[key]) || key;
110
107
  }
111
-
112
108
  /**
113
109
  * 获取多语言名称
114
110
  */
115
111
  getLocalizedName(name) {
116
- if (typeof name === 'string') {
112
+ if (typeof name === "string") {
117
113
  return name;
118
114
  }
119
- return name[this.locale] || name['en'] || Object.values(name)[0] || '';
115
+ return name[this.locale] || name["en"] || Object.values(name)[0] || "";
120
116
  }
121
-
122
117
  // ============================================
123
118
  // 核心评估方法
124
119
  // ============================================
125
-
126
120
  /**
127
121
  * 评估商品列表
128
122
  *
@@ -133,31 +127,19 @@ class PromotionEvaluator {
133
127
  * @returns 每个商品的促销评估结果
134
128
  */
135
129
  evaluateProducts(input) {
136
- const {
137
- products,
138
- strategyConfigs,
139
- channel
140
- } = input;
130
+ const { products, strategyConfigs, channel } = input;
141
131
  const configs = strategyConfigs || this.strategyConfigs;
142
132
  const results = [];
143
133
  for (const product of products) {
144
134
  const applicablePromotions = [];
145
-
146
- // 遍历所有策略,检查此商品是否适用
147
135
  for (const config of configs) {
148
- // 1. 先用 getProductMatchInfo 检查商品是否在策略的适用范围内(包含 bundle 子商品检查)
149
136
  const matchInfo = this.getProductMatchInfo(product, config);
150
137
  if (!matchInfo.isMatch) {
151
- // 商品不在策略适用范围内,跳过
152
138
  continue;
153
139
  }
154
-
155
- // 2. 准备上下文(如果是 bundle 子商品匹配,需要用 bundle 子商品的 ID)
156
140
  let contextProduct = product;
157
- if (matchInfo.matchedBundleIndex !== undefined && product.bundle) {
141
+ if (matchInfo.matchedBundleIndex !== void 0 && product.bundle) {
158
142
  const bundleItem = product.bundle[matchInfo.matchedBundleIndex];
159
- // 创建一个临时的"虚拟商品"用于策略引擎评估
160
- // 这样策略引擎的 product_match 条件能正确通过
161
143
  contextProduct = {
162
144
  ...product,
163
145
  product_id: bundleItem._bundle_product_id,
@@ -169,8 +151,6 @@ class PromotionEvaluator {
169
151
  currentProduct: contextProduct,
170
152
  channel
171
153
  });
172
-
173
- // 3. 评估策略(检查其他条件如时间范围等)
174
154
  const result = this.engine.evaluate(config, context);
175
155
  if (result.applicable && result.matchedActions.length > 0) {
176
156
  const action = result.matchedActions[0];
@@ -201,7 +181,6 @@ class PromotionEvaluator {
201
181
  }
202
182
  return results;
203
183
  }
204
-
205
184
  /**
206
185
  * 评估购物车
207
186
  *
@@ -212,42 +191,29 @@ class PromotionEvaluator {
212
191
  * @returns 购物车评估结果
213
192
  */
214
193
  evaluateCart(input) {
215
- const {
216
- products,
217
- strategyConfigs,
218
- channel
219
- } = input;
194
+ const { products, strategyConfigs, channel } = input;
220
195
  const configs = strategyConfigs || this.strategyConfigs;
221
-
222
- // 1. 先获取每个商品的促销结果
223
196
  const productResults = this.evaluateProducts(input);
224
-
225
- // 2. 收集所有适用的促销(去重)
226
- const promotionMap = new Map();
197
+ const promotionMap = /* @__PURE__ */ new Map();
227
198
  for (const productResult of productResults) {
228
199
  for (const promo of productResult.applicablePromotions) {
229
200
  const existing = promotionMap.get(promo.strategyId);
230
201
  const product = productResult.product;
231
-
232
- // 计算促销数量:如果是 bundle 子商品匹配,数量 = 主商品数量 × 子商品数量
233
202
  let promoQuantity = product.quantity;
234
- if (promo.matchedBundleIndex !== undefined && product.bundle) {
203
+ if (promo.matchedBundleIndex !== void 0 && product.bundle) {
235
204
  const bundleItem = product.bundle[promo.matchedBundleIndex];
236
205
  promoQuantity = product.quantity * (bundleItem.quantity || 1);
237
206
  }
238
207
  if (existing) {
239
- // 已存在,添加商品到列表
240
208
  existing.applicableProducts.push(product);
241
209
  existing.totalQuantity += promoQuantity;
242
210
  existing.totalAmount += product.price * product.quantity;
243
- // 记录每个商品的 matchedBundleIndex
244
211
  if (!existing.productMatchedBundleIndexMap) {
245
- existing.productMatchedBundleIndexMap = new Map();
212
+ existing.productMatchedBundleIndexMap = /* @__PURE__ */ new Map();
246
213
  }
247
214
  existing.productMatchedBundleIndexMap.set(product.id, promo.matchedBundleIndex);
248
215
  } else {
249
- // 新促销
250
- const productMatchedBundleIndexMap = new Map();
216
+ const productMatchedBundleIndexMap = /* @__PURE__ */ new Map();
251
217
  productMatchedBundleIndexMap.set(product.id, promo.matchedBundleIndex);
252
218
  promotionMap.set(promo.strategyId, {
253
219
  ...promo,
@@ -260,28 +226,30 @@ class PromotionEvaluator {
260
226
  }
261
227
  }
262
228
  const applicablePromotions = Array.from(promotionMap.values());
263
-
264
- // 3. 按促销分组
265
- const promotionGroups = applicablePromotions.map(promo => ({
266
- strategyId: promo.strategyId,
267
- strategyName: promo.strategyName,
268
- strategyMetadata: promo.strategyConfig?.metadata,
269
- strategyConfig: promo.strategyConfig,
270
- actionType: promo.actionType,
271
- actionDetail: promo.actionDetail,
272
- products: promo.applicableProducts,
273
- totalQuantity: promo.totalQuantity,
274
- totalAmount: promo.totalAmount,
275
- // 传递 productMatchedBundleIndexMap 到 group
276
- productMatchedBundleIndexMap: promo.productMatchedBundleIndexMap
277
- }));
229
+ const promotionGroups = applicablePromotions.map(
230
+ (promo) => {
231
+ var _a;
232
+ return {
233
+ strategyId: promo.strategyId,
234
+ strategyName: promo.strategyName,
235
+ strategyMetadata: (_a = promo.strategyConfig) == null ? void 0 : _a.metadata,
236
+ strategyConfig: promo.strategyConfig,
237
+ actionType: promo.actionType,
238
+ actionDetail: promo.actionDetail,
239
+ products: promo.applicableProducts,
240
+ totalQuantity: promo.totalQuantity,
241
+ totalAmount: promo.totalAmount,
242
+ // 传递 productMatchedBundleIndexMap 到 group
243
+ productMatchedBundleIndexMap: promo.productMatchedBundleIndexMap
244
+ };
245
+ }
246
+ );
278
247
  return {
279
248
  productResults,
280
249
  applicablePromotions,
281
250
  promotionGroups
282
251
  };
283
252
  }
284
-
285
253
  /**
286
254
  * 评估购物车并计算定价
287
255
  *
@@ -293,70 +261,60 @@ class PromotionEvaluator {
293
261
  * @returns 带定价的购物车评估结果
294
262
  */
295
263
  evaluateCartWithPricing(input) {
296
- const {
297
- products
298
- } = input;
299
-
300
- // 1. 先调用 evaluateCart 获取分组结果
264
+ const { products } = input;
301
265
  const cartResult = this.evaluateCart(input);
302
-
303
- // 2. 按 action priority 排序促销组(从 strategyConfig 获取 priority)
304
- const sortedGroups = this.sortPromotionGroupsByPriority(cartResult.promotionGroups, cartResult.applicablePromotions);
305
-
306
- // 3. 追踪已处理的商品(避免重复处理)
307
- // key: `${product_id}_${product_variant_id}`
308
- const processedQuantityMap = new Map();
309
-
310
- // 4. 处理每个促销组,收集结果
266
+ const sortedGroups = this.sortPromotionGroupsByPriority(
267
+ cartResult.promotionGroups,
268
+ cartResult.applicablePromotions
269
+ );
270
+ const processedQuantityMap = /* @__PURE__ */ new Map();
311
271
  const pricedProducts = [];
312
272
  const gifts = [];
313
- let totalOriginalAmount = new _decimal.default(0);
314
- let totalFinalAmount = new _decimal.default(0);
273
+ let totalOriginalAmount = new import_decimal.default(0);
274
+ let totalFinalAmount = new import_decimal.default(0);
315
275
  for (const group of sortedGroups) {
316
- const {
317
- actionType
318
- } = group;
319
-
320
- // 直接使用 evaluateCart 阶段计算好的 matchedBundleIndexMap
321
- const matchedBundleIndexMap = group.productMatchedBundleIndexMap || new Map();
322
- if (actionType === _type.PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE) {
323
- // X件Y元处理
324
- const result = this.processXItemsForYPrice(group, processedQuantityMap, matchedBundleIndexMap);
276
+ const { actionType } = group;
277
+ const matchedBundleIndexMap = group.productMatchedBundleIndexMap || /* @__PURE__ */ new Map();
278
+ if (actionType === import_type.PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE) {
279
+ const result = this.processXItemsForYPrice(
280
+ group,
281
+ processedQuantityMap,
282
+ matchedBundleIndexMap
283
+ );
325
284
  pricedProducts.push(...result.products);
326
285
  totalOriginalAmount = totalOriginalAmount.plus(result.originalAmount);
327
286
  totalFinalAmount = totalFinalAmount.plus(result.finalAmount);
328
- } else if (actionType === _type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE) {
329
- // 买X送Y处理
330
- const result = this.processBuyXGetYFree(group, processedQuantityMap, matchedBundleIndexMap);
287
+ } else if (actionType === import_type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE) {
288
+ const result = this.processBuyXGetYFree(
289
+ group,
290
+ processedQuantityMap,
291
+ matchedBundleIndexMap
292
+ );
331
293
  pricedProducts.push(...result.products);
332
294
  totalOriginalAmount = totalOriginalAmount.plus(result.originalAmount);
333
295
  totalFinalAmount = totalFinalAmount.plus(result.finalAmount);
334
-
335
- // 添加赠品信息
336
296
  if (result.giftInfo) {
337
297
  gifts.push(result.giftInfo);
338
298
  }
339
299
  }
340
300
  }
341
-
342
- // 5. 处理未参与任何促销的商品
343
- const remainingProducts = this.getRemainingProducts(products, processedQuantityMap);
301
+ const remainingProducts = this.getRemainingProducts(
302
+ products,
303
+ processedQuantityMap
304
+ );
344
305
  for (const product of remainingProducts) {
345
- const amount = new _decimal.default(product.price).mul(product.quantity);
306
+ const amount = new import_decimal.default(product.price).mul(product.quantity);
346
307
  totalOriginalAmount = totalOriginalAmount.plus(amount);
347
308
  totalFinalAmount = totalFinalAmount.plus(amount);
348
309
  }
349
310
  pricedProducts.push(...remainingProducts);
350
-
351
- // 6. 计算总优惠金额
352
311
  const totalDiscount = totalOriginalAmount.minus(totalFinalAmount);
353
312
  return {
354
313
  products: pricedProducts,
355
314
  gifts,
356
- totalDiscount: _decimal.default.max(0, totalDiscount).toNumber()
315
+ totalDiscount: import_decimal.default.max(0, totalDiscount).toNumber()
357
316
  };
358
317
  }
359
-
360
318
  /**
361
319
  * 获取商品适用的促销列表
362
320
  *
@@ -367,13 +325,13 @@ class PromotionEvaluator {
367
325
  * @returns 适用的促销列表
368
326
  */
369
327
  getProductPromotions(product, strategyConfigs) {
328
+ var _a;
370
329
  const results = this.evaluateProducts({
371
330
  products: [product],
372
331
  strategyConfigs
373
332
  });
374
- return results[0]?.applicablePromotions || [];
333
+ return ((_a = results[0]) == null ? void 0 : _a.applicablePromotions) || [];
375
334
  }
376
-
377
335
  /**
378
336
  * 获取商品的促销标签
379
337
  *
@@ -385,13 +343,12 @@ class PromotionEvaluator {
385
343
  */
386
344
  getProductPromotionTags(product, strategyConfigs) {
387
345
  const promotions = this.getProductPromotions(product, strategyConfigs);
388
- return promotions.filter(promo => promo.display).map(promo => ({
346
+ return promotions.filter((promo) => promo.display).map((promo) => ({
389
347
  text: this.getLocalizedName(promo.display.text),
390
348
  type: promo.display.type,
391
349
  strategyId: promo.strategyId
392
350
  }));
393
351
  }
394
-
395
352
  /**
396
353
  * 查找商品适用的策略配置
397
354
  *
@@ -401,9 +358,10 @@ class PromotionEvaluator {
401
358
  */
402
359
  findApplicableStrategies(product, strategyConfigs) {
403
360
  const configs = strategyConfigs || this.strategyConfigs;
404
- return configs.filter(config => this.isProductInStrategy(product, config));
361
+ return configs.filter(
362
+ (config) => this.isProductInStrategy(product, config)
363
+ );
405
364
  }
406
-
407
365
  /**
408
366
  * 批量获取商品列表的适用策略信息
409
367
  *
@@ -415,30 +373,23 @@ class PromotionEvaluator {
415
373
  * @returns 每个商品的适用策略完整数据
416
374
  */
417
375
  getProductsApplicableStrategies(input, matchVariant = true) {
418
- const {
419
- products,
420
- strategyConfigs,
421
- channel
422
- } = input;
376
+ const { products, strategyConfigs, channel } = input;
423
377
  const configs = strategyConfigs || this.strategyConfigs;
424
378
  const results = [];
425
379
  for (const product of products) {
426
380
  const applicableStrategies = [];
427
-
428
- // 遍历所有策略,检查此商品是否适用
429
381
  for (const config of configs) {
430
382
  let contextProduct = product;
431
383
  if (!matchVariant) {
432
- // 只匹配 product_id,忽略 product_variant_id
433
384
  const productMatchRule = this.findProductMatchRule(config);
434
385
  if (productMatchRule) {
435
386
  const configProducts = productMatchRule.value;
436
- const matchedConfig = configProducts.find(item => item.product_id === product.product_id);
387
+ const matchedConfig = configProducts.find(
388
+ (item) => item.product_id === product.product_id
389
+ );
437
390
  if (!matchedConfig) {
438
- // product_id 不在策略适用范围内,跳过
439
391
  continue;
440
392
  }
441
- // 用配置中的 variant_id 构造上下文,确保引擎 product_match 通过
442
393
  if (matchedConfig.product_variant_id !== 0 && matchedConfig.product_variant_id !== product.product_variant_id) {
443
394
  contextProduct = {
444
395
  ...product,
@@ -452,8 +403,6 @@ class PromotionEvaluator {
452
403
  currentProduct: contextProduct,
453
404
  channel
454
405
  });
455
-
456
- // 评估策略
457
406
  const result = this.engine.evaluate(config, context);
458
407
  if (result.applicable && result.matchedActions.length > 0) {
459
408
  const action = result.matchedActions[0];
@@ -463,11 +412,11 @@ class PromotionEvaluator {
463
412
  channel
464
413
  });
465
414
  if (transformedResult.actionDetail) {
466
- // 计算所需数量和可参与商品列表
467
- const {
468
- requiredQuantity,
469
- eligibleProducts
470
- } = this.getPromotionRequirements(action.type, transformedResult.actionDetail, config);
415
+ const { requiredQuantity, eligibleProducts } = this.getPromotionRequirements(
416
+ action.type,
417
+ transformedResult.actionDetail,
418
+ config
419
+ );
471
420
  applicableStrategies.push({
472
421
  strategyId: config.metadata.id,
473
422
  strategyName: config.metadata.name,
@@ -490,7 +439,6 @@ class PromotionEvaluator {
490
439
  }
491
440
  return results;
492
441
  }
493
-
494
442
  /**
495
443
  * 获取促销所需数量和可参与商品列表
496
444
  *
@@ -501,50 +449,41 @@ class PromotionEvaluator {
501
449
  */
502
450
  getPromotionRequirements(actionType, actionDetail, config) {
503
451
  let requiredQuantity = 0;
504
-
505
- // 根据促销类型获取所需数量
506
- if (actionType === 'BUY_X_GET_Y_FREE') {
452
+ if (actionType === "BUY_X_GET_Y_FREE") {
507
453
  const detail = actionDetail;
508
454
  requiredQuantity = detail.buyQuantity || 0;
509
- } else if (actionType === 'X_ITEMS_FOR_Y_PRICE') {
455
+ } else if (actionType === "X_ITEMS_FOR_Y_PRICE") {
510
456
  const detail = actionDetail;
511
457
  requiredQuantity = detail.x || 0;
512
458
  }
513
-
514
- // 获取可参与商品列表
515
459
  const productMatchRule = this.findProductMatchRule(config);
516
- const eligibleProducts = productMatchRule?.value || [];
460
+ const eligibleProducts = (productMatchRule == null ? void 0 : productMatchRule.value) || [];
517
461
  return {
518
462
  requiredQuantity,
519
463
  eligibleProducts
520
464
  };
521
465
  }
522
-
523
466
  // ============================================
524
467
  // 私有辅助方法
525
468
  // ============================================
526
-
527
469
  /**
528
470
  * 按优先级排序促销组
529
471
  * 优先级从 strategyConfig.actions[0].priority 获取,数值越小优先级越高
530
472
  */
531
473
  sortPromotionGroupsByPriority(groups, promotions) {
532
- // 创建策略ID到优先级的映射
533
- const priorityMap = new Map();
474
+ var _a, _b;
475
+ const priorityMap = /* @__PURE__ */ new Map();
534
476
  for (const promo of promotions) {
535
- const actions = promo.strategyConfig?.actions || [];
536
- const priority = actions[0]?.priority ?? 999;
477
+ const actions = ((_a = promo.strategyConfig) == null ? void 0 : _a.actions) || [];
478
+ const priority = ((_b = actions[0]) == null ? void 0 : _b.priority) ?? 999;
537
479
  priorityMap.set(promo.strategyId, priority);
538
480
  }
539
-
540
- // 按优先级排序(数值越小优先级越高)
541
481
  return [...groups].sort((a, b) => {
542
482
  const priorityA = priorityMap.get(a.strategyId) ?? 999;
543
483
  const priorityB = priorityMap.get(b.strategyId) ?? 999;
544
484
  return priorityA - priorityB;
545
485
  });
546
486
  }
547
-
548
487
  /**
549
488
  * 处理 X件Y元 促销
550
489
  *
@@ -556,32 +495,19 @@ class PromotionEvaluator {
556
495
  * 注意:每个商品按 id 独立处理,不会合并不同 id 的商品
557
496
  */
558
497
  processXItemsForYPrice(group, processedQuantityMap, matchedBundleIndexMap) {
559
- const {
560
- strategyId,
561
- strategyMetadata,
562
- actionDetail,
563
- products: groupProducts
564
- } = group;
498
+ const { strategyId, strategyMetadata, actionDetail, products: groupProducts } = group;
565
499
  const detail = actionDetail;
566
- const {
567
- x,
568
- price: groupPrice,
569
- cumulative
570
- } = detail;
500
+ const { x, price: groupPrice, cumulative } = detail;
571
501
  const result = [];
572
- let originalAmount = new _decimal.default(0);
573
- let finalAmount = new _decimal.default(0);
574
-
575
- // 1. 展开所有商品为单件列表(排除已处理的数量)
576
- // 每个单件记录来自哪个原商品(通过 product.id)
502
+ let originalAmount = new import_decimal.default(0);
503
+ let finalAmount = new import_decimal.default(0);
577
504
  const unitProducts = [];
578
505
  for (const product of groupProducts) {
579
506
  const key = this.getProductKey(product);
580
507
  const processedQty = processedQuantityMap.get(key) || 0;
581
508
  const availableQty = product.quantity - processedQty;
582
- if (availableQty <= 0) continue;
583
-
584
- // 展开为单件,每个单件都记录来源商品
509
+ if (availableQty <= 0)
510
+ continue;
585
511
  for (let i = 0; i < availableQty; i++) {
586
512
  unitProducts.push({
587
513
  product,
@@ -592,66 +518,47 @@ class PromotionEvaluator {
592
518
  }
593
519
  }
594
520
  if (unitProducts.length === 0) {
595
- return {
596
- products: [],
597
- originalAmount: 0,
598
- finalAmount: 0
599
- };
521
+ return { products: [], originalAmount: 0, finalAmount: 0 };
600
522
  }
601
-
602
- // 2. 排序:优先选择来源数量是 x 倍数的商品(可完整凑组不拆分),然后按价格从高到低
603
523
  unitProducts.sort((a, b) => {
604
- // 优先级1:来源购物车项数量是 x 的倍数的排前面(这些商品可以完整凑组,避免拆分)
605
524
  const aIsMultiple = a.sourceAvailableQty > 0 && a.sourceAvailableQty % x === 0 ? 1 : 0;
606
525
  const bIsMultiple = b.sourceAvailableQty > 0 && b.sourceAvailableQty % x === 0 ? 1 : 0;
607
- if (aIsMultiple !== bIsMultiple) return bIsMultiple - aIsMultiple;
608
- // 优先级2:按价格从高到低(优先使用高价商品)
526
+ if (aIsMultiple !== bIsMultiple)
527
+ return bIsMultiple - aIsMultiple;
609
528
  return b.price - a.price;
610
529
  });
611
-
612
- // 3. 计算可以凑成多少组
613
530
  const totalUnits = unitProducts.length;
614
- const groupCount = cumulative ? Math.floor(totalUnits / x) : totalUnits >= x ? 1 : 0;
531
+ const isCumulative = cumulative !== false;
532
+ const groupCount = isCumulative ? Math.floor(totalUnits / x) : totalUnits >= x ? 1 : 0;
615
533
  const promotionUnits = groupCount * x;
616
-
617
- // 4. 分离参与促销的和不参与的商品
618
534
  const inPromotionUnits = unitProducts.slice(0, promotionUnits);
619
535
  const notInPromotionUnits = unitProducts.slice(promotionUnits);
620
-
621
- // 5. 按原商品 id 统计参与促销和不参与的数量
622
- const promotionQtyByProductId = new Map();
536
+ const promotionQtyByProductId = /* @__PURE__ */ new Map();
623
537
  for (const unit of inPromotionUnits) {
624
538
  const id = unit.productId;
625
539
  promotionQtyByProductId.set(id, (promotionQtyByProductId.get(id) || 0) + 1);
626
540
  }
627
- const remainingQtyByProductId = new Map();
541
+ const remainingQtyByProductId = /* @__PURE__ */ new Map();
628
542
  for (const unit of notInPromotionUnits) {
629
543
  const id = unit.productId;
630
544
  remainingQtyByProductId.set(id, (remainingQtyByProductId.get(id) || 0) + 1);
631
545
  }
632
-
633
- // 6. 为每个参与促销的单件计算均摊价格
634
- // 按组内原价比例均摊
635
- // 记录每个原商品的均摊价格累加(用于后续聚合)
636
- const allocatedPricesByProductId = new Map();
546
+ const allocatedPricesByProductId = /* @__PURE__ */ new Map();
637
547
  for (let g = 0; g < groupCount; g++) {
638
548
  const startIdx = g * x;
639
549
  const endIdx = startIdx + x;
640
550
  const groupUnits = inPromotionUnits.slice(startIdx, endIdx);
641
-
642
- // 计算组内原价总和
643
- const groupOriginalTotal = groupUnits.reduce((sum, u) => sum.plus(u.price), new _decimal.default(0));
644
-
645
- // 按原价比例均摊
646
- const groupPriceDecimal = new _decimal.default(groupPrice);
647
- let allocatedSum = new _decimal.default(0);
551
+ const groupOriginalTotal = groupUnits.reduce(
552
+ (sum, u) => sum.plus(u.price),
553
+ new import_decimal.default(0)
554
+ );
555
+ const groupPriceDecimal = new import_decimal.default(groupPrice);
556
+ let allocatedSum = new import_decimal.default(0);
648
557
  for (let i = 0; i < groupUnits.length; i++) {
649
558
  const unit = groupUnits[i];
650
559
  const isLastUnit = i === groupUnits.length - 1;
651
- const ratio = groupOriginalTotal.eq(0) ? new _decimal.default(0) : new _decimal.default(unit.price).div(groupOriginalTotal);
560
+ const ratio = groupOriginalTotal.eq(0) ? new import_decimal.default(0) : new import_decimal.default(unit.price).div(groupOriginalTotal);
652
561
  const allocatedDecimal = isLastUnit ? groupPriceDecimal.minus(allocatedSum) : groupPriceDecimal.mul(ratio);
653
-
654
- // 记录这个单件的均摊价格
655
562
  const productId = unit.productId;
656
563
  const prices = allocatedPricesByProductId.get(productId) || [];
657
564
  prices.push(allocatedDecimal);
@@ -659,25 +566,23 @@ class PromotionEvaluator {
659
566
  allocatedSum = allocatedSum.plus(allocatedDecimal);
660
567
  }
661
568
  }
662
-
663
- // 7. 为每个原商品生成结果
664
569
  for (const product of groupProducts) {
665
570
  const key = this.getProductKey(product);
666
571
  const processedQty = processedQuantityMap.get(key) || 0;
667
572
  const availableQty = product.quantity - processedQty;
668
- if (availableQty <= 0) continue;
573
+ if (availableQty <= 0)
574
+ continue;
669
575
  const promoQty = promotionQtyByProductId.get(product.id) || 0;
670
576
  const remainingQty = remainingQtyByProductId.get(product.id) || 0;
671
577
  const allocatedPrices = allocatedPricesByProductId.get(product.id) || [];
672
-
673
- // 获取当前商品的 matchedBundleIndex
674
- const matchedBundleIndex = matchedBundleIndexMap?.get(product.id);
578
+ const matchedBundleIndex = matchedBundleIndexMap == null ? void 0 : matchedBundleIndexMap.get(product.id);
675
579
  if (promoQty > 0 && remainingQty === 0) {
676
- // 全部参与促销:保留原 id,计算总 finalPrice
677
- const totalAllocated = allocatedPrices.reduce((sum, p) => sum.plus(p), new _decimal.default(0));
678
- // 取促销价和原价的最小值,避免促销反而加价
679
- const productOriginalAmount = new _decimal.default(product.price).mul(promoQty);
680
- const actualTotal = _decimal.default.min(totalAllocated, productOriginalAmount);
580
+ const totalAllocated = allocatedPrices.reduce(
581
+ (sum, p) => sum.plus(p),
582
+ new import_decimal.default(0)
583
+ );
584
+ const productOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
585
+ const actualTotal = import_decimal.default.min(totalAllocated, productOriginalAmount);
681
586
  const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
682
587
  result.push({
683
588
  ...product,
@@ -692,26 +597,25 @@ class PromotionEvaluator {
692
597
  originalAmount = originalAmount.plus(productOriginalAmount);
693
598
  finalAmount = finalAmount.plus(actualTotal);
694
599
  } else if (promoQty === 0 && remainingQty > 0) {
695
- // 全部不参与促销:保留原 id,finalPrice = 原价
696
600
  result.push({
697
601
  ...product,
698
602
  quantity: remainingQty,
699
603
  finalPrice: this.formatPrice(product.price),
700
- strategyId: undefined,
701
- strategyMetadata: undefined,
604
+ strategyId: void 0,
605
+ strategyMetadata: void 0,
702
606
  inPromotion: false,
703
607
  isSplit: false
704
608
  });
705
- const amount = new _decimal.default(product.price).mul(remainingQty);
609
+ const amount = new import_decimal.default(product.price).mul(remainingQty);
706
610
  originalAmount = originalAmount.plus(amount);
707
611
  finalAmount = finalAmount.plus(amount);
708
612
  } else if (promoQty > 0 && remainingQty > 0) {
709
- // 部分参与促销,部分不参与:需要拆分
710
- // 参与促销的部分:新 id
711
- const totalAllocated = allocatedPrices.reduce((sum, p) => sum.plus(p), new _decimal.default(0));
712
- // 取促销价和原价的最小值,避免促销反而加价
713
- const promoOriginalAmount = new _decimal.default(product.price).mul(promoQty);
714
- const actualTotal = _decimal.default.min(totalAllocated, promoOriginalAmount);
613
+ const totalAllocated = allocatedPrices.reduce(
614
+ (sum, p) => sum.plus(p),
615
+ new import_decimal.default(0)
616
+ );
617
+ const promoOriginalAmount = new import_decimal.default(product.price).mul(promoQty);
618
+ const actualTotal = import_decimal.default.min(totalAllocated, promoOriginalAmount);
715
619
  const finalPricePerUnit = this.formatPrice(actualTotal.div(promoQty));
716
620
  result.push({
717
621
  ...product,
@@ -727,50 +631,44 @@ class PromotionEvaluator {
727
631
  });
728
632
  originalAmount = originalAmount.plus(promoOriginalAmount);
729
633
  finalAmount = finalAmount.plus(actualTotal);
730
-
731
- // 不参与促销的部分:保留原 id
732
634
  result.push({
733
635
  ...product,
734
636
  quantity: remainingQty,
735
637
  finalPrice: this.formatPrice(product.price),
736
- strategyId: undefined,
737
- strategyMetadata: undefined,
638
+ strategyId: void 0,
639
+ strategyMetadata: void 0,
738
640
  inPromotion: false,
739
641
  isSplit: true
740
642
  });
741
- const remainingAmount = new _decimal.default(product.price).mul(remainingQty);
643
+ const remainingAmount = new import_decimal.default(product.price).mul(remainingQty);
742
644
  originalAmount = originalAmount.plus(remainingAmount);
743
645
  finalAmount = finalAmount.plus(remainingAmount);
744
646
  }
745
-
746
- // 更新已处理数量
747
647
  processedQuantityMap.set(key, processedQty + availableQty);
748
648
  }
749
-
750
- // 8. 尾差调整:确保促销商品的 finalPrice × quantity 之和精确等于 groupPrice × groupCount
751
649
  if (groupCount > 0) {
752
- const expectedPromoTotal = new _decimal.default(groupPrice).mul(groupCount);
753
- const promoItems = result.filter(p => p.inPromotion);
754
- let actualPromoTotal = new _decimal.default(0);
650
+ const expectedPromoTotal = new import_decimal.default(groupPrice).mul(groupCount);
651
+ const promoItems = result.filter((p) => p.inPromotion);
652
+ let actualPromoTotal = new import_decimal.default(0);
755
653
  for (const p of promoItems) {
756
- actualPromoTotal = actualPromoTotal.plus(new _decimal.default(p.finalPrice).mul(p.quantity));
654
+ actualPromoTotal = actualPromoTotal.plus(
655
+ new import_decimal.default(p.finalPrice).mul(p.quantity)
656
+ );
757
657
  }
758
658
  const roundingDiff = actualPromoTotal.minus(expectedPromoTotal);
759
659
  if (!roundingDiff.eq(0)) {
760
- // 优先找 quantity=1 的促销商品调整(差额直接加减到单价上)
761
- const adjustTarget = promoItems.find(p => p.quantity === 1);
660
+ const adjustTarget = promoItems.find((p) => p.quantity === 1);
762
661
  if (adjustTarget) {
763
- adjustTarget.finalPrice = this.formatPrice(new _decimal.default(adjustTarget.finalPrice).minus(roundingDiff));
662
+ adjustTarget.finalPrice = this.formatPrice(
663
+ new import_decimal.default(adjustTarget.finalPrice).minus(roundingDiff)
664
+ );
764
665
  } else if (promoItems.length > 0) {
765
- // 没有 quantity=1 的促销商品,从最后一个促销商品中拆出1件做尾差调整
766
666
  const lastPromo = promoItems[promoItems.length - 1];
767
- const adjustedUnitPrice = this.formatPrice(new _decimal.default(lastPromo.finalPrice).minus(roundingDiff));
768
-
769
- // 原商品减少1件
667
+ const adjustedUnitPrice = this.formatPrice(
668
+ new import_decimal.default(lastPromo.finalPrice).minus(roundingDiff)
669
+ );
770
670
  lastPromo.quantity -= 1;
771
671
  lastPromo.isSplit = true;
772
-
773
- // 拆出1件用调整后的价格
774
672
  result.push({
775
673
  ...lastPromo,
776
674
  id: this.generateRandomId(),
@@ -780,11 +678,11 @@ class PromotionEvaluator {
780
678
  isSplit: true
781
679
  });
782
680
  }
783
-
784
- // 重新计算 finalAmount
785
- finalAmount = new _decimal.default(0);
681
+ finalAmount = new import_decimal.default(0);
786
682
  for (const p of result) {
787
- finalAmount = finalAmount.plus(new _decimal.default(p.finalPrice).mul(p.quantity));
683
+ finalAmount = finalAmount.plus(
684
+ new import_decimal.default(p.finalPrice).mul(p.quantity)
685
+ );
788
686
  }
789
687
  }
790
688
  }
@@ -794,7 +692,6 @@ class PromotionEvaluator {
794
692
  finalAmount: finalAmount.toNumber()
795
693
  };
796
694
  }
797
-
798
695
  /**
799
696
  * 处理 买X送Y 促销
800
697
  *
@@ -810,56 +707,34 @@ class PromotionEvaluator {
810
707
  products: groupProducts
811
708
  } = group;
812
709
  const detail = actionDetail;
813
- const {
814
- buyQuantity,
815
- freeQuantity,
816
- cumulative,
817
- giftProducts
818
- } = detail;
710
+ const { buyQuantity, freeQuantity, cumulative, giftProducts } = detail;
819
711
  const result = [];
820
- let originalAmount = new _decimal.default(0);
821
- let finalAmount = new _decimal.default(0);
822
-
823
- // 1. 先计算可用商品总数量(第一次遍历)
824
- // 对于 bundle 子商品匹配,促销数量 = 主商品数量 × bundle子商品数量
712
+ let originalAmount = new import_decimal.default(0);
713
+ let finalAmount = new import_decimal.default(0);
825
714
  let totalPromoQty = 0;
826
- const productInfoMap = new Map();
715
+ const productInfoMap = /* @__PURE__ */ new Map();
827
716
  for (const product of groupProducts) {
828
717
  const key = this.getProductKey(product);
829
718
  const processedQty = processedQuantityMap.get(key) || 0;
830
719
  const availableQty = product.quantity - processedQty;
831
- if (availableQty <= 0) continue;
832
-
833
- // 获取 matchedBundleIndex
834
- const matchedBundleIndex = matchedBundleIndexMap?.get(product.id);
835
-
836
- // 计算用于促销的数量
720
+ if (availableQty <= 0)
721
+ continue;
722
+ const matchedBundleIndex = matchedBundleIndexMap == null ? void 0 : matchedBundleIndexMap.get(product.id);
837
723
  let promoQty = availableQty;
838
- if (matchedBundleIndex !== undefined && product.bundle) {
724
+ if (matchedBundleIndex !== void 0 && product.bundle) {
839
725
  const bundleItem = product.bundle[matchedBundleIndex];
840
- // 促销数量 = 主商品数量 × bundle子商品数量
841
726
  promoQty = availableQty * (bundleItem.quantity || 1);
842
727
  }
843
728
  totalPromoQty += promoQty;
844
- productInfoMap.set(key, {
845
- availableQty,
846
- promoQty,
847
- matchedBundleIndex
848
- });
729
+ productInfoMap.set(key, { availableQty, promoQty, matchedBundleIndex });
849
730
  }
850
-
851
- // 2. 判断是否满足促销条件
852
731
  const isFulfilled = totalPromoQty >= buyQuantity;
853
-
854
- // 3. 生成商品结果(第二次遍历)
855
732
  for (const product of groupProducts) {
856
733
  const key = this.getProductKey(product);
857
734
  const info = productInfoMap.get(key);
858
- if (!info || info.availableQty <= 0) continue;
735
+ if (!info || info.availableQty <= 0)
736
+ continue;
859
737
  const processedQty = processedQuantityMap.get(key) || 0;
860
-
861
- // 商品本身价格不变,只是触发赠品
862
- // inPromotion 只有在满足条件时才为 true
863
738
  result.push({
864
739
  ...product,
865
740
  quantity: info.availableQty,
@@ -871,21 +746,15 @@ class PromotionEvaluator {
871
746
  isSplit: info.availableQty < product.quantity,
872
747
  matchedBundleIndex: info.matchedBundleIndex
873
748
  });
874
- const amount = new _decimal.default(product.price).mul(info.availableQty);
749
+ const amount = new import_decimal.default(product.price).mul(info.availableQty);
875
750
  originalAmount = originalAmount.plus(amount);
876
751
  finalAmount = finalAmount.plus(amount);
877
-
878
- // 更新已处理数量(使用主商品数量)
879
752
  processedQuantityMap.set(key, processedQty + info.availableQty);
880
753
  }
881
-
882
- // 4. 计算赠品数量(使用促销数量)
883
754
  let giftCount = 0;
884
755
  if (isFulfilled) {
885
756
  giftCount = cumulative ? Math.floor(totalPromoQty / buyQuantity) * freeQuantity : freeQuantity;
886
757
  }
887
-
888
- // 5. 构建赠品信息
889
758
  const giftInfo = giftCount > 0 ? {
890
759
  strategyId,
891
760
  strategyName,
@@ -899,7 +768,6 @@ class PromotionEvaluator {
899
768
  giftInfo
900
769
  };
901
770
  }
902
-
903
771
  /**
904
772
  * 获取未参与任何促销的商品
905
773
  */
@@ -914,7 +782,7 @@ class PromotionEvaluator {
914
782
  ...product,
915
783
  quantity: remainingQty,
916
784
  finalPrice: this.formatPrice(product.price),
917
- strategyId: undefined,
785
+ strategyId: void 0,
918
786
  inPromotion: false,
919
787
  isSplit: remainingQty < product.quantity
920
788
  });
@@ -922,14 +790,12 @@ class PromotionEvaluator {
922
790
  }
923
791
  return result;
924
792
  }
925
-
926
793
  /**
927
794
  * 价格统一保留两位小数
928
795
  */
929
796
  formatPrice(value) {
930
- return new _decimal.default(value).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
797
+ return new import_decimal.default(value).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
931
798
  }
932
-
933
799
  /**
934
800
  * 获取商品唯一标识 key
935
801
  * 使用商品的 id 作为唯一标识,不同 id 的商品不会被合并
@@ -937,107 +803,92 @@ class PromotionEvaluator {
937
803
  getProductKey(product) {
938
804
  return String(product.id);
939
805
  }
940
-
941
806
  /**
942
807
  * 生成随机ID
943
808
  */
944
809
  generateRandomId() {
945
- return Math.floor(Math.random() * 1000000000) + Date.now();
810
+ return Math.floor(Math.random() * 1e9) + Date.now();
946
811
  }
947
-
948
812
  /**
949
813
  * 商品匹配结果信息
950
814
  */
951
815
  getProductMatchInfo(product, config) {
952
816
  const productMatchRule = this.findProductMatchRule(config);
953
817
  if (!productMatchRule) {
954
- // 没有商品范围条件,默认适用所有商品(匹配主商品)
955
- return {
956
- isMatch: true
957
- };
818
+ return { isMatch: true };
958
819
  }
959
820
  const configProducts = productMatchRule.value;
960
-
961
- // 1. 先检查主商品是否匹配
962
821
  if (this.isProductIdMatch(product.product_id, product.product_variant_id, configProducts)) {
963
- return {
964
- isMatch: true
965
- };
822
+ return { isMatch: true };
966
823
  }
967
-
968
- // 2. 主商品不匹配,检查 bundle 子商品
969
824
  if (product.bundle && product.bundle.length > 0) {
970
825
  for (let i = 0; i < product.bundle.length; i++) {
971
826
  const bundleItem = product.bundle[i];
972
- if (this.isProductIdMatch(bundleItem._bundle_product_id, bundleItem.product_variant_id, configProducts)) {
973
- return {
974
- isMatch: true,
975
- matchedBundleIndex: i
976
- };
827
+ if (this.isProductIdMatch(
828
+ bundleItem._bundle_product_id,
829
+ bundleItem.product_variant_id,
830
+ configProducts
831
+ )) {
832
+ return { isMatch: true, matchedBundleIndex: i };
977
833
  }
978
834
  }
979
835
  }
980
- return {
981
- isMatch: false
982
- };
836
+ return { isMatch: false };
983
837
  }
984
-
985
838
  /**
986
839
  * 检查商品是否在策略的适用范围内
987
840
  */
988
841
  isProductInStrategy(product, config) {
989
842
  return this.getProductMatchInfo(product, config).isMatch;
990
843
  }
991
-
992
844
  /**
993
845
  * 查找商品匹配规则
994
846
  */
995
847
  findProductMatchRule(config) {
996
- if (!config?.conditions?.rules) {
848
+ var _a;
849
+ if (!((_a = config == null ? void 0 : config.conditions) == null ? void 0 : _a.rules)) {
997
850
  return null;
998
851
  }
999
- return config.conditions.rules.find(rule => rule.field === 'productIdAndVariantId' && (rule.operator === 'product_match' || rule.operator === 'object_in'));
852
+ return config.conditions.rules.find(
853
+ (rule) => rule.field === "productIdAndVariantId" && (rule.operator === "product_match" || rule.operator === "object_in")
854
+ );
1000
855
  }
1001
-
1002
856
  /**
1003
857
  * 检查商品ID是否匹配配置列表
1004
858
  */
1005
859
  isProductIdMatch(productId, productVariantId, configProducts) {
1006
- return configProducts.some(config => {
1007
- // 首先检查 product_id
860
+ return configProducts.some((config) => {
1008
861
  if (config.product_id !== productId) {
1009
862
  return false;
1010
863
  }
1011
-
1012
- // 如果配置的 product_variant_id = 0,只需要 product_id 匹配
1013
864
  if (config.product_variant_id === 0) {
1014
865
  return true;
1015
866
  }
1016
-
1017
- // 否则需要 product_variant_id 精确匹配
1018
867
  return config.product_variant_id === productVariantId;
1019
868
  });
1020
869
  }
1021
-
1022
870
  /**
1023
871
  * 检查商品是否匹配配置(兼容旧方法)
1024
872
  */
1025
873
  isProductMatch(product, configProducts) {
1026
874
  return this.isProductIdMatch(product.product_id, product.product_variant_id, configProducts);
1027
875
  }
1028
-
1029
876
  /**
1030
877
  * 获取展示配置
1031
878
  */
1032
879
  getDisplayConfig(config) {
880
+ var _a;
1033
881
  const custom = config.metadata.custom;
1034
- if (custom?.display?.product_card) {
882
+ if ((_a = custom == null ? void 0 : custom.display) == null ? void 0 : _a.product_card) {
1035
883
  return {
1036
884
  text: custom.display.product_card.text,
1037
885
  type: custom.display.product_card.type
1038
886
  };
1039
887
  }
1040
- return undefined;
888
+ return void 0;
1041
889
  }
1042
- }
1043
- exports.PromotionEvaluator = PromotionEvaluator;
890
+ };
891
+ // Annotate the CommonJS export names for ESM import in node:
892
+ 0 && (module.exports = {
893
+ PromotionEvaluator
894
+ });