@pisell/pisellos 3.0.74 → 3.0.76

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 (319) hide show
  1. package/dist/core/index.js +2 -1
  2. package/dist/effects/index.d.ts +5 -3
  3. package/dist/effects/index.js +40 -8
  4. package/dist/modules/Account/index.js +2 -3
  5. package/dist/modules/AccountList/index.d.ts +7 -1
  6. package/dist/modules/AccountList/index.js +81 -14
  7. package/dist/modules/AccountList/types.d.ts +28 -0
  8. package/dist/modules/AccountList/types.js +8 -0
  9. package/dist/modules/BaseModule.d.ts +3 -0
  10. package/dist/modules/BaseModule.js +15 -0
  11. package/dist/modules/Cart/index.d.ts +1 -0
  12. package/dist/modules/Cart/index.js +2 -1
  13. package/dist/modules/Cart/utils/cartProduct.js +21 -4
  14. package/dist/modules/Customer/constants.d.ts +7 -0
  15. package/dist/modules/Customer/constants.js +12 -0
  16. package/dist/modules/Customer/index.d.ts +122 -0
  17. package/dist/modules/Customer/index.js +696 -0
  18. package/dist/modules/Customer/types.d.ts +146 -0
  19. package/dist/modules/Customer/types.js +41 -0
  20. package/dist/modules/Discount/index.d.ts +1 -0
  21. package/dist/modules/Discount/index.js +3 -3
  22. package/dist/modules/Discount/types.d.ts +9 -0
  23. package/dist/modules/Guests/index.js +9 -9
  24. package/dist/modules/Order/index.d.ts +25 -1
  25. package/dist/modules/Order/index.js +224 -3
  26. package/dist/modules/Order/types.d.ts +45 -0
  27. package/dist/modules/Order/types.js +8 -0
  28. package/dist/modules/Order/utils.js +1 -1
  29. package/dist/modules/Payment/cash.d.ts +19 -0
  30. package/dist/modules/Payment/cash.js +97 -0
  31. package/dist/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  32. package/dist/modules/Payment/cashRecommendationAlgorithm.js +423 -0
  33. package/dist/modules/Payment/eftpos.d.ts +11 -0
  34. package/dist/modules/Payment/eftpos.js +80 -0
  35. package/dist/modules/Payment/index.d.ts +184 -9
  36. package/dist/modules/Payment/index.js +2084 -109
  37. package/dist/modules/Payment/mx51.d.ts +0 -0
  38. package/dist/modules/Payment/mx51.js +0 -0
  39. package/dist/modules/Payment/types.d.ts +772 -30
  40. package/dist/modules/Payment/types.js +236 -12
  41. package/dist/modules/Payment/utils.d.ts +17 -0
  42. package/dist/modules/Payment/utils.js +62 -0
  43. package/dist/modules/Payment/walletpass.d.ts +99 -0
  44. package/dist/modules/Payment/walletpass.js +711 -0
  45. package/dist/modules/ProductList/index.d.ts +12 -1
  46. package/dist/modules/ProductList/index.js +37 -15
  47. package/dist/modules/Resource/index.js +1 -1
  48. package/dist/modules/Rules/index.d.ts +2 -1
  49. package/dist/modules/Rules/index.js +470 -127
  50. package/dist/modules/Rules/types.d.ts +1 -0
  51. package/dist/modules/Schedule/index.d.ts +9 -0
  52. package/dist/modules/Schedule/index.js +77 -0
  53. package/dist/modules/Summary/utils.d.ts +5 -0
  54. package/dist/modules/Summary/utils.js +36 -1
  55. package/dist/modules/index.d.ts +1 -0
  56. package/dist/modules/index.js +1 -0
  57. package/dist/plugins/app-types/app/app.d.ts +83 -0
  58. package/dist/plugins/app-types/app/const.d.ts +4 -0
  59. package/dist/plugins/app-types/app/index.d.ts +14 -0
  60. package/dist/plugins/app-types/applicationManager/application.d.ts +50 -0
  61. package/dist/plugins/app-types/applicationManager/index.d.ts +13 -0
  62. package/dist/plugins/app-types/config.d.ts +3 -0
  63. package/dist/plugins/app-types/cookie/index.d.ts +13 -0
  64. package/dist/plugins/app-types/data/index.d.ts +8 -0
  65. package/dist/plugins/app-types/history/config.d.ts +24 -0
  66. package/dist/plugins/app-types/history/index.d.ts +20 -0
  67. package/dist/plugins/app-types/history/type.d.ts +2 -0
  68. package/dist/plugins/app-types/hooks/index.d.ts +12 -0
  69. package/dist/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  70. package/dist/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  71. package/dist/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  72. package/dist/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  73. package/dist/plugins/app-types/index.d.ts +6 -0
  74. package/dist/plugins/app-types/indexDB/index.d.ts +178 -0
  75. package/dist/plugins/app-types/locales/en.d.ts +3 -0
  76. package/dist/plugins/app-types/locales/index.d.ts +37 -0
  77. package/dist/plugins/app-types/locales/original.d.ts +3 -0
  78. package/dist/plugins/app-types/locales/type.d.ts +19 -0
  79. package/dist/plugins/app-types/locales/zh-CN.d.ts +3 -0
  80. package/dist/plugins/app-types/locales/zh-HK.d.ts +3 -0
  81. package/dist/plugins/app-types/logger/feishu.d.ts +11 -0
  82. package/dist/plugins/app-types/logger/index.d.ts +122 -0
  83. package/dist/plugins/app-types/menuManager/hooks.d.ts +17 -0
  84. package/dist/plugins/app-types/menuManager/index.d.ts +28 -0
  85. package/dist/plugins/app-types/models/global.d.ts +32 -0
  86. package/dist/plugins/app-types/models/index.d.ts +45 -0
  87. package/dist/plugins/app-types/models/type.d.ts +2 -0
  88. package/dist/plugins/app-types/package.json +15 -0
  89. package/dist/plugins/app-types/plugin/index.d.ts +0 -0
  90. package/dist/plugins/app-types/pubsub/example.d.ts +5 -0
  91. package/dist/plugins/app-types/pubsub/index.d.ts +63 -0
  92. package/dist/plugins/app-types/request/cache.d.ts +46 -0
  93. package/dist/plugins/app-types/request/cancelToken.d.ts +38 -0
  94. package/dist/plugins/app-types/request/config.d.ts +3 -0
  95. package/dist/plugins/app-types/request/constants.d.ts +2 -0
  96. package/dist/plugins/app-types/request/index.d.ts +24 -0
  97. package/dist/plugins/app-types/request/pisell2Request.d.ts +6 -0
  98. package/dist/plugins/app-types/request/type.d.ts +41 -0
  99. package/dist/plugins/app-types/request/utils.d.ts +46 -0
  100. package/dist/plugins/app-types/routes/config.d.ts +7 -0
  101. package/dist/plugins/app-types/routes/index.d.ts +28 -0
  102. package/dist/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  103. package/dist/plugins/app-types/socket/components/index.d.ts +2 -0
  104. package/dist/plugins/app-types/socket/constants.d.ts +33 -0
  105. package/dist/plugins/app-types/socket/events.d.ts +31 -0
  106. package/dist/plugins/app-types/socket/heartbeat.d.ts +66 -0
  107. package/dist/plugins/app-types/socket/index.d.ts +61 -0
  108. package/dist/plugins/app-types/socket/monitor.d.ts +169 -0
  109. package/dist/plugins/app-types/socket/reconnect.d.ts +61 -0
  110. package/dist/plugins/app-types/socket/socket.d.ts +129 -0
  111. package/dist/plugins/app-types/socket/types.d.ts +85 -0
  112. package/dist/plugins/app-types/storage/index.d.ts +17 -0
  113. package/dist/plugins/app-types/tasks/index.d.ts +77 -0
  114. package/dist/plugins/app-types/tasks/type.d.ts +62 -0
  115. package/dist/plugins/app-types/tasks/useTasks.d.ts +5 -0
  116. package/dist/plugins/app-types/type.d.ts +2 -0
  117. package/dist/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  118. package/dist/plugins/app-types/variables/config.d.ts +3 -0
  119. package/dist/plugins/app-types/variables/index.d.ts +6 -0
  120. package/dist/plugins/app-types/variables/type.d.ts +2 -0
  121. package/dist/plugins/app-types/website/index.d.ts +6 -0
  122. package/dist/plugins/app.d.ts +8 -0
  123. package/dist/plugins/app.js +1 -0
  124. package/dist/plugins/window.d.ts +1 -0
  125. package/dist/solution/BookingByStep/index.js +43 -13
  126. package/dist/solution/BookingByStep/utils/capacity.js +1 -1
  127. package/dist/solution/BookingByStep/utils/products.d.ts +6 -0
  128. package/dist/solution/BookingByStep/utils/products.js +10 -0
  129. package/dist/solution/BookingTicket/index.d.ts +184 -0
  130. package/dist/solution/BookingTicket/index.js +698 -0
  131. package/dist/solution/BookingTicket/types.d.ts +68 -0
  132. package/dist/solution/BookingTicket/types.js +43 -0
  133. package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  134. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +159 -0
  135. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +22 -0
  136. package/dist/solution/BookingTicket/utils/scan/handleScan.js +189 -0
  137. package/dist/solution/BookingTicket/utils/scan/index.d.ts +85 -0
  138. package/dist/solution/BookingTicket/utils/scan/index.js +294 -0
  139. package/dist/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  140. package/dist/solution/BookingTicket/utils/scan/scanCache.js +305 -0
  141. package/dist/solution/BuyTickets/index.js +7 -8
  142. package/dist/solution/Checkout/appointmentDemo.json +1 -0
  143. package/dist/solution/Checkout/index.d.ts +432 -0
  144. package/dist/solution/Checkout/index.js +4452 -0
  145. package/dist/solution/Checkout/types.d.ts +727 -0
  146. package/dist/solution/Checkout/types.js +104 -0
  147. package/dist/solution/Checkout/utils/index.d.ts +121 -0
  148. package/dist/solution/Checkout/utils/index.js +511 -0
  149. package/dist/solution/ShopDiscount/index.d.ts +10 -10
  150. package/dist/solution/ShopDiscount/index.js +111 -60
  151. package/dist/solution/ShopDiscount/types.d.ts +8 -0
  152. package/dist/solution/ShopDiscount/utils.d.ts +24 -0
  153. package/dist/solution/ShopDiscount/utils.js +135 -1
  154. package/dist/solution/index.d.ts +2 -0
  155. package/dist/solution/index.js +3 -1
  156. package/dist/types/index.d.ts +4 -1
  157. package/dist/utils/task.d.ts +40 -0
  158. package/dist/utils/task.js +171 -0
  159. package/dist/utils/watch.d.ts +102 -0
  160. package/dist/utils/watch.js +294 -0
  161. package/lib/core/index.js +1 -1
  162. package/lib/effects/index.d.ts +5 -3
  163. package/lib/effects/index.js +17 -1
  164. package/lib/modules/Account/index.js +2 -3
  165. package/lib/modules/AccountList/index.d.ts +7 -1
  166. package/lib/modules/AccountList/index.js +27 -0
  167. package/lib/modules/AccountList/types.d.ts +28 -0
  168. package/lib/modules/BaseModule.d.ts +3 -0
  169. package/lib/modules/BaseModule.js +9 -0
  170. package/lib/modules/Cart/index.d.ts +1 -0
  171. package/lib/modules/Cart/index.js +5 -2
  172. package/lib/modules/Cart/utils/cartProduct.js +22 -6
  173. package/lib/modules/Customer/constants.d.ts +7 -0
  174. package/lib/modules/Customer/constants.js +39 -0
  175. package/lib/modules/Customer/index.d.ts +122 -0
  176. package/lib/modules/Customer/index.js +439 -0
  177. package/lib/modules/Customer/types.d.ts +146 -0
  178. package/lib/modules/Customer/types.js +37 -0
  179. package/lib/modules/Discount/index.d.ts +1 -0
  180. package/lib/modules/Discount/index.js +3 -3
  181. package/lib/modules/Discount/types.d.ts +9 -0
  182. package/lib/modules/Guests/index.js +9 -9
  183. package/lib/modules/Order/index.d.ts +25 -1
  184. package/lib/modules/Order/index.js +186 -1
  185. package/lib/modules/Order/types.d.ts +45 -0
  186. package/lib/modules/Order/utils.js +1 -1
  187. package/lib/modules/Payment/cash.d.ts +19 -0
  188. package/lib/modules/Payment/cash.js +64 -0
  189. package/lib/modules/Payment/cashRecommendationAlgorithm.d.ts +22 -0
  190. package/lib/modules/Payment/cashRecommendationAlgorithm.js +342 -0
  191. package/lib/modules/Payment/eftpos.d.ts +11 -0
  192. package/lib/modules/Payment/eftpos.js +51 -0
  193. package/lib/modules/Payment/index.d.ts +184 -9
  194. package/lib/modules/Payment/index.js +1084 -51
  195. package/lib/modules/Payment/mx51.d.ts +0 -0
  196. package/lib/modules/Payment/mx51.js +0 -0
  197. package/lib/modules/Payment/types.d.ts +772 -30
  198. package/lib/modules/Payment/types.js +79 -6
  199. package/lib/modules/Payment/utils.d.ts +17 -0
  200. package/lib/modules/Payment/utils.js +67 -0
  201. package/lib/modules/Payment/walletpass.d.ts +99 -0
  202. package/lib/modules/Payment/walletpass.js +484 -0
  203. package/lib/modules/ProductList/index.d.ts +12 -1
  204. package/lib/modules/ProductList/index.js +31 -12
  205. package/lib/modules/Resource/index.js +1 -1
  206. package/lib/modules/Rules/index.d.ts +2 -1
  207. package/lib/modules/Rules/index.js +318 -72
  208. package/lib/modules/Rules/types.d.ts +1 -0
  209. package/lib/modules/Schedule/index.d.ts +9 -0
  210. package/lib/modules/Schedule/index.js +60 -0
  211. package/lib/modules/Summary/utils.d.ts +5 -0
  212. package/lib/modules/Summary/utils.js +27 -3
  213. package/lib/modules/index.d.ts +1 -0
  214. package/lib/modules/index.js +2 -0
  215. package/lib/plugins/app-types/app/app.d.ts +83 -0
  216. package/lib/plugins/app-types/app/const.d.ts +4 -0
  217. package/lib/plugins/app-types/app/index.d.ts +14 -0
  218. package/lib/plugins/app-types/applicationManager/application.d.ts +50 -0
  219. package/lib/plugins/app-types/applicationManager/index.d.ts +13 -0
  220. package/lib/plugins/app-types/config.d.ts +3 -0
  221. package/lib/plugins/app-types/cookie/index.d.ts +13 -0
  222. package/lib/plugins/app-types/data/index.d.ts +8 -0
  223. package/lib/plugins/app-types/history/config.d.ts +24 -0
  224. package/lib/plugins/app-types/history/index.d.ts +20 -0
  225. package/lib/plugins/app-types/history/type.d.ts +2 -0
  226. package/lib/plugins/app-types/hooks/index.d.ts +12 -0
  227. package/lib/plugins/app-types/hooks/useDelayedValue/index.d.ts +2 -0
  228. package/lib/plugins/app-types/hooks/useDispatch/index.d.ts +2 -0
  229. package/lib/plugins/app-types/hooks/useLowCode/index.d.ts +13 -0
  230. package/lib/plugins/app-types/hooks/useStore/index.d.ts +6 -0
  231. package/lib/plugins/app-types/index.d.ts +6 -0
  232. package/lib/plugins/app-types/indexDB/index.d.ts +178 -0
  233. package/lib/plugins/app-types/locales/en.d.ts +3 -0
  234. package/lib/plugins/app-types/locales/index.d.ts +37 -0
  235. package/lib/plugins/app-types/locales/original.d.ts +3 -0
  236. package/lib/plugins/app-types/locales/type.d.ts +19 -0
  237. package/lib/plugins/app-types/locales/zh-CN.d.ts +3 -0
  238. package/lib/plugins/app-types/locales/zh-HK.d.ts +3 -0
  239. package/lib/plugins/app-types/logger/feishu.d.ts +11 -0
  240. package/lib/plugins/app-types/logger/index.d.ts +122 -0
  241. package/lib/plugins/app-types/menuManager/hooks.d.ts +17 -0
  242. package/lib/plugins/app-types/menuManager/index.d.ts +28 -0
  243. package/lib/plugins/app-types/models/global.d.ts +32 -0
  244. package/lib/plugins/app-types/models/index.d.ts +45 -0
  245. package/lib/plugins/app-types/models/type.d.ts +2 -0
  246. package/lib/plugins/app-types/package.json +15 -0
  247. package/lib/plugins/app-types/plugin/index.d.ts +0 -0
  248. package/lib/plugins/app-types/pubsub/example.d.ts +5 -0
  249. package/lib/plugins/app-types/pubsub/index.d.ts +63 -0
  250. package/lib/plugins/app-types/request/cache.d.ts +46 -0
  251. package/lib/plugins/app-types/request/cancelToken.d.ts +38 -0
  252. package/lib/plugins/app-types/request/config.d.ts +3 -0
  253. package/lib/plugins/app-types/request/constants.d.ts +2 -0
  254. package/lib/plugins/app-types/request/index.d.ts +24 -0
  255. package/lib/plugins/app-types/request/pisell2Request.d.ts +6 -0
  256. package/lib/plugins/app-types/request/type.d.ts +41 -0
  257. package/lib/plugins/app-types/request/utils.d.ts +46 -0
  258. package/lib/plugins/app-types/routes/config.d.ts +7 -0
  259. package/lib/plugins/app-types/routes/index.d.ts +28 -0
  260. package/lib/plugins/app-types/socket/components/SocketMonitorPage.d.ts +6 -0
  261. package/lib/plugins/app-types/socket/components/index.d.ts +2 -0
  262. package/lib/plugins/app-types/socket/constants.d.ts +33 -0
  263. package/lib/plugins/app-types/socket/events.d.ts +31 -0
  264. package/lib/plugins/app-types/socket/heartbeat.d.ts +66 -0
  265. package/lib/plugins/app-types/socket/index.d.ts +61 -0
  266. package/lib/plugins/app-types/socket/monitor.d.ts +169 -0
  267. package/lib/plugins/app-types/socket/reconnect.d.ts +61 -0
  268. package/lib/plugins/app-types/socket/socket.d.ts +129 -0
  269. package/lib/plugins/app-types/socket/types.d.ts +85 -0
  270. package/lib/plugins/app-types/storage/index.d.ts +17 -0
  271. package/lib/plugins/app-types/tasks/index.d.ts +77 -0
  272. package/lib/plugins/app-types/tasks/type.d.ts +62 -0
  273. package/lib/plugins/app-types/tasks/useTasks.d.ts +5 -0
  274. package/lib/plugins/app-types/type.d.ts +2 -0
  275. package/lib/plugins/app-types/variables/VariablesProvider.d.ts +7 -0
  276. package/lib/plugins/app-types/variables/config.d.ts +3 -0
  277. package/lib/plugins/app-types/variables/index.d.ts +6 -0
  278. package/lib/plugins/app-types/variables/type.d.ts +2 -0
  279. package/lib/plugins/app-types/website/index.d.ts +6 -0
  280. package/lib/plugins/app.d.ts +8 -0
  281. package/lib/plugins/app.js +17 -0
  282. package/lib/plugins/window.d.ts +1 -0
  283. package/lib/solution/BookingByStep/index.js +18 -6
  284. package/lib/solution/BookingByStep/utils/capacity.js +1 -1
  285. package/lib/solution/BookingByStep/utils/products.d.ts +6 -0
  286. package/lib/solution/BookingByStep/utils/products.js +8 -2
  287. package/lib/solution/BookingTicket/index.d.ts +184 -0
  288. package/lib/solution/BookingTicket/index.js +426 -0
  289. package/lib/solution/BookingTicket/types.d.ts +68 -0
  290. package/lib/solution/BookingTicket/types.js +72 -0
  291. package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +22 -0
  292. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +117 -0
  293. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +22 -0
  294. package/lib/solution/BookingTicket/utils/scan/handleScan.js +132 -0
  295. package/lib/solution/BookingTicket/utils/scan/index.d.ts +85 -0
  296. package/lib/solution/BookingTicket/utils/scan/index.js +216 -0
  297. package/lib/solution/BookingTicket/utils/scan/scanCache.d.ts +78 -0
  298. package/lib/solution/BookingTicket/utils/scan/scanCache.js +231 -0
  299. package/lib/solution/BuyTickets/index.js +7 -8
  300. package/lib/solution/Checkout/appointmentDemo.json +1 -0
  301. package/lib/solution/Checkout/index.d.ts +432 -0
  302. package/lib/solution/Checkout/index.js +2776 -0
  303. package/lib/solution/Checkout/types.d.ts +727 -0
  304. package/lib/solution/Checkout/types.js +63 -0
  305. package/lib/solution/Checkout/utils/index.d.ts +121 -0
  306. package/lib/solution/Checkout/utils/index.js +362 -0
  307. package/lib/solution/ShopDiscount/index.d.ts +10 -10
  308. package/lib/solution/ShopDiscount/index.js +53 -27
  309. package/lib/solution/ShopDiscount/types.d.ts +8 -0
  310. package/lib/solution/ShopDiscount/utils.d.ts +24 -0
  311. package/lib/solution/ShopDiscount/utils.js +88 -1
  312. package/lib/solution/index.d.ts +2 -0
  313. package/lib/solution/index.js +5 -1
  314. package/lib/types/index.d.ts +4 -1
  315. package/lib/utils/task.d.ts +40 -0
  316. package/lib/utils/task.js +109 -0
  317. package/lib/utils/watch.d.ts +102 -0
  318. package/lib/utils/watch.js +217 -0
  319. package/package.json +3 -1
@@ -24,11 +24,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
25
  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); }
26
26
  import { BaseModule } from "../BaseModule";
27
- import { RulesHooks } from "./types";
28
- import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime } from "../../solution/ShopDiscount/utils";
27
+ import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, isOrderLevelFixedAmountDiscount, calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
29
28
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
30
29
  import Decimal from 'decimal.js';
30
+ import { isBoolean } from 'lodash-es';
31
31
  import dayjs from 'dayjs';
32
+
33
+ // 临时变量
34
+ var flatItem;
32
35
  export var RulesModule = /*#__PURE__*/function (_BaseModule) {
33
36
  _inherits(RulesModule, _BaseModule);
34
37
  var _super = _createSuper(RulesModule);
@@ -73,7 +76,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
73
76
  case 0:
74
77
  this.store.rulesList = rulesList;
75
78
  _context2.next = 3;
76
- return this.core.effects.emit(RulesHooks.OnRulesListChange, rulesList);
79
+ return this.core.effects.emit("".concat(this.name, ":onRulesListChange"), rulesList);
77
80
  case 3:
78
81
  case "end":
79
82
  return _context2.stop();
@@ -142,10 +145,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
142
145
  }
143
146
 
144
147
  // 合并新旧折扣列表,并计算折扣结果,注意,如果旧折扣里有 isEditMode 为 true 的优惠券,则不合并
148
+ // 保留之前扫码得到的商品券(isScan: true)
145
149
  var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
146
- return !discount.isEditMode && discount.tag !== 'good_pass';
150
+ return !discount.isEditMode && (discount.tag !== 'good_pass' || discount.isScan);
147
151
  });
148
- var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
152
+ var mergedDiscountList = uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList)));
149
153
  var result = this.calcDiscount({
150
154
  discountList: mergedDiscountList,
151
155
  productList: _toConsumableArray(productList),
@@ -212,6 +216,25 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
212
216
  }
213
217
  });
214
218
 
219
+ // 🔥 检查 editModeDiscount 中是否有订单级别的折扣,如果有则禁用 addModeDiscount 中相同 product_id 的折扣卡
220
+ var editModeOrderLevelProductIds = new Set();
221
+ editModeDiscount.forEach(function (discount) {
222
+ var _discount$discount2;
223
+ if (((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.discount_calculation_mode) === 'order_level') {
224
+ var _discount$discount3;
225
+ editModeOrderLevelProductIds.add(discount === null || discount === void 0 || (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_product_id);
226
+ }
227
+ });
228
+
229
+ // 如果存在订单级别的编辑模式折扣,禁用 addModeDiscount 中相同 product_id 的折扣卡
230
+ if (editModeOrderLevelProductIds.size > 0) {
231
+ addModeDiscount.forEach(function (discount) {
232
+ if (editModeOrderLevelProductIds.has(discount.product_id)) {
233
+ discount.isDisabled = true;
234
+ }
235
+ });
236
+ }
237
+
215
238
  // 过滤掉手动取消false的优惠券,但仅用于应用优惠逻辑
216
239
  var filteredDiscountList = addModeDiscount.filter(function (discount) {
217
240
  return !discount.isManualSelect;
@@ -267,26 +290,69 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
267
290
  };
268
291
 
269
292
  // 优惠力度排序,传进来的数据里可能有商品券,也可能有优惠券
270
- // 1. 商品券(n.tag=good_pass)视为最优惠(免费)
271
- // 2. 折扣券(n.tag=product_discount_card)按照新的优先级排序:
272
- // - 固定金额优先于百分比(固定金额 > 百分比)
273
- // - 固定金额内部:金额越大越优先
274
- // - 百分比内部:折扣越大越优先(par_value越小越优先)
275
- // 3. 相同类型和金额的情况下,按照过期时间(n.expire_time)排序
293
+ // 新的优先级排序规则(从高到低):
294
+ // 1. 带有Holder的商品券(metadata?.holder?.type === 'custom' && tag === 'good_pass')
295
+ // 2. 带有Holder的商品级折扣卡(metadata?.holder?.type === 'custom' && tag === 'product_discount_card' && discount_calculation_mode !== 'order_level')
296
+ // 3. 带有Holder的订单级折扣卡(metadata?.holder?.type === 'custom' && tag === 'product_discount_card' && discount_calculation_mode === 'order_level')
297
+ // 4. Customer商品券(metadata?.holder?.type !== 'custom' && tag === 'good_pass')
298
+ // 5. Customer商品级折扣卡(metadata?.holder?.type !== 'custom' && tag === 'product_discount_card' && discount_calculation_mode !== 'order_level')
299
+ // 6. Customer订单级固定金额折扣(metadata?.holder?.type !== 'custom' && tag === 'product_discount_card' && discount_calculation_mode === 'order_level')
300
+ // 同一优先级内部:固定金额优先于百分比,金额/折扣力度越大越优先,最后按过期时间排序
276
301
  var sortedDiscountList = _toConsumableArray(filteredDiscountList).sort(function (a, b) {
277
- // 1. 商品券优先级最高
278
- if (a.tag === 'good_pass' && b.tag !== 'good_pass') return -1;
279
- if (b.tag === 'good_pass' && a.tag !== 'good_pass') return 1;
302
+ // 辅助函数:判断是否是带有Holder的优惠券
303
+ var isHolderDiscount = function isHolderDiscount(discount) {
304
+ var _discount$metadata;
305
+ return ((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 || (_discount$metadata = _discount$metadata.holder) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.type) === 'custom';
306
+ };
280
307
 
281
- // 2. 如果都是商品券或都不是商品券,按照类型和折扣力度排序
282
- if (a.tag === 'good_pass' && b.tag === 'good_pass') {
283
- // 都是商品券,按照过期时间排序
284
- return compareByExpireTime(a, b);
285
- } else if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
286
- var _a$metadata, _b$metadata;
287
- // 都是折扣券,按照新的优先级排序:固定金额优先于百分比
288
- var typeA = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 ? void 0 : _a$metadata.discount_card_type) || 'percent'; // 默认为百分比
289
- var typeB = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 ? void 0 : _b$metadata.discount_card_type) || 'percent'; // 默认为百分比
308
+ // 辅助函数:判断是否是商品券
309
+ var isGoodPass = function isGoodPass(discount) {
310
+ return discount.tag === 'good_pass';
311
+ };
312
+
313
+ // 辅助函数:判断是否是订单级折扣卡
314
+ var isOrderLevelDiscount = function isOrderLevelDiscount(discount) {
315
+ var _discount$metadata2;
316
+ return discount.tag === 'product_discount_card' && ((_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.discount_calculation_mode) === 'order_level';
317
+ };
318
+
319
+ // 辅助函数:判断是否是商品级折扣卡
320
+ var isItemLevelDiscount = function isItemLevelDiscount(discount) {
321
+ var _discount$metadata3;
322
+ return discount.tag === 'product_discount_card' && ((_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.discount_calculation_mode) !== 'order_level';
323
+ };
324
+
325
+ // 辅助函数:获取优先级(数字越小优先级越高)
326
+ var getPriority = function getPriority(discount) {
327
+ var isHolder = isHolderDiscount(discount);
328
+ if (isHolder) {
329
+ if (isGoodPass(discount)) return 1; // 带有Holder的商品券
330
+ if (isItemLevelDiscount(discount)) return 2; // 带有Holder的商品级折扣卡
331
+ if (isOrderLevelDiscount(discount)) return 3; // 带有Holder的订单级折扣卡
332
+ } else {
333
+ if (isGoodPass(discount)) return 4; // Customer商品券
334
+ if (isItemLevelDiscount(discount)) return 5; // Customer商品级折扣卡
335
+ if (isOrderLevelDiscount(discount)) return 6; // Customer订单级固定金额折扣
336
+ }
337
+ return 7; // 其他情况
338
+ };
339
+
340
+ // 辅助函数:按过期时间比较
341
+ function compareByExpireTime(itemA, itemB) {
342
+ if (itemA.expire_time && itemB.expire_time) {
343
+ var timeA = new Date(itemA.expire_time).getTime();
344
+ var timeB = new Date(itemB.expire_time).getTime();
345
+ return timeA - timeB;
346
+ }
347
+ // 有过期时间的优先级高于永久的
348
+ return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
349
+ }
350
+
351
+ // 辅助函数:同类型折扣卡内部排序(固定金额优先于百分比,金额/折扣力度排序)
352
+ function compareDiscountCardValue(itemA, itemB) {
353
+ var _itemA$metadata, _itemB$metadata;
354
+ var typeA = ((_itemA$metadata = itemA.metadata) === null || _itemA$metadata === void 0 ? void 0 : _itemA$metadata.discount_card_type) || 'percent';
355
+ var typeB = ((_itemB$metadata = itemB.metadata) === null || _itemB$metadata === void 0 ? void 0 : _itemB$metadata.discount_card_type) || 'percent';
290
356
 
291
357
  // 1. 固定金额优先于百分比
292
358
  if (typeA === 'fixed_amount' && typeB === 'percent') return -1;
@@ -294,37 +360,46 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
294
360
 
295
361
  // 2. 都是固定金额时,金额越大越优先
296
362
  if (typeA === 'fixed_amount' && typeB === 'fixed_amount') {
297
- if (a.par_value !== b.par_value) {
298
- var valueA = new Decimal(a.par_value || 0);
299
- var valueB = new Decimal(b.par_value || 0);
363
+ if (itemA.par_value !== itemB.par_value) {
364
+ var valueA = new Decimal(itemA.par_value || 0);
365
+ var valueB = new Decimal(itemB.par_value || 0);
300
366
  return valueB.minus(valueA).toNumber(); // 金额大的在前
301
367
  }
302
368
  }
303
369
 
304
370
  // 3. 都是百分比时,折扣越大越优先(par_value越大越优先)
305
371
  if (typeA === 'percent' && typeB === 'percent') {
306
- if (a.par_value !== b.par_value) {
307
- var _valueA = new Decimal(100).minus(a.par_value || 0);
308
- var _valueB = new Decimal(100).minus(b.par_value || 0);
372
+ if (itemA.par_value !== itemB.par_value) {
373
+ var _valueA = new Decimal(100).minus(itemA.par_value || 0);
374
+ var _valueB = new Decimal(100).minus(itemB.par_value || 0);
309
375
  return _valueA.minus(_valueB).toNumber(); // 折扣大的在前
310
376
  }
311
377
  }
378
+ return 0;
379
+ }
380
+
381
+ // 1. 先按优先级排序
382
+ var priorityA = getPriority(a);
383
+ var priorityB = getPriority(b);
384
+ if (priorityA !== priorityB) {
385
+ return priorityA - priorityB;
386
+ }
387
+
388
+ // 2. 同一优先级内部排序
389
+ // 如果是商品券(优先级1或4),按过期时间排序
390
+ if (isGoodPass(a) && isGoodPass(b)) {
391
+ return compareByExpireTime(a, b);
392
+ }
312
393
 
313
- // 相同类型和金额的情况下,按照过期时间排序
394
+ // 如果是折扣卡(优先级2、3、5、6),按折扣力度排序,然后按过期时间
395
+ if (a.tag === 'product_discount_card' && b.tag === 'product_discount_card') {
396
+ var valueCompare = compareDiscountCardValue(a, b);
397
+ if (valueCompare !== 0) return valueCompare;
314
398
  return compareByExpireTime(a, b);
315
399
  }
316
400
 
317
401
  // 3. 其他情况按照过期时间排序
318
402
  return compareByExpireTime(a, b);
319
- function compareByExpireTime(itemA, itemB) {
320
- if (itemA.expire_time && itemB.expire_time) {
321
- var timeA = new Date(itemA.expire_time).getTime();
322
- var timeB = new Date(itemB.expire_time).getTime();
323
- return timeA - timeB;
324
- }
325
- // 有过期时间的优先级高于永久的
326
- return itemA.expire_time ? -1 : itemB.expire_time ? 1 : 0;
327
- }
328
403
  });
329
404
 
330
405
  // const newProductList = [];
@@ -345,8 +420,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
345
420
 
346
421
  // 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
347
422
  var sortedFlattenedList = flattenedList.sort(function (a, b) {
348
- var priceA = new Decimal(a.price || '0');
349
- var priceB = new Decimal(b.price || '0');
423
+ var _ref3, _a$original_price, _ref4, _b$original_price;
424
+ // 子商品优先使用 original_price,主商品使用 price
425
+ var priceA = new Decimal(a.type === 'bundle' ? (_ref3 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref3 !== void 0 ? _ref3 : '0' : a.price || '0');
426
+ var priceB = new Decimal(b.type === 'bundle' ? (_ref4 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : b.price || '0');
350
427
  if (priceA.equals(priceB)) {
351
428
  // 价格相同时,主商品优先
352
429
  if (a.type !== b.type) {
@@ -377,7 +454,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
377
454
  const priceB = new Decimal((bProduct.price as string) || '0');
378
455
  if (priceA.toNumber() === priceB.toNumber()) {
379
456
  if (aProduct.quantity === bProduct.quantity) {
380
- return bProduct.discount_list?.length - aProduct.discount_list?.length;
457
+ return bProduct.discount_list?.length - aProduct.discount_list?.length;
381
458
  }
382
459
  return aProduct.quantity - bProduct.quantity;
383
460
  }
@@ -400,6 +477,191 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
400
477
  discountApplicableProducts.set(discount.id, []);
401
478
  });
402
479
 
480
+ // 预处理 order_level 固定金额折扣卡的分摊信息
481
+ // Map<discountId, Map<productId, { discountAmount, difference }>>
482
+ var orderLevelDiscountAllocations = new Map();
483
+
484
+ // 第一步:收集所有被勾选的 order_level 折扣卡及其适用商品
485
+ // Map<discountId, Set<flatItemId>> - 记录每个折扣卡适用的商品
486
+ var orderLevelDiscountApplicableItems = new Map();
487
+ // Map<flatItemId, Set<discountId>> - 记录每个商品可以被哪些折扣卡使用
488
+ var itemApplicableDiscounts = new Map();
489
+
490
+ // 辅助函数:检查商品是否对某个折扣卡可用
491
+ var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
492
+ var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
493
+ var product;
494
+ if (flatItem.type === 'main') {
495
+ product = flatItem.product;
496
+ } else {
497
+ var _flatItem$parentProdu;
498
+ product = {
499
+ _id: flatItem._id,
500
+ id: flatItem.id,
501
+ price: flatItem.price,
502
+ quantity: flatItem.quantity,
503
+ num: flatItem.num,
504
+ booking_id: flatItem.booking_id,
505
+ discount_list: flatItem.discount_list || [],
506
+ startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
507
+ };
508
+ }
509
+
510
+ // 编辑的商品使用了优惠券不可用
511
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
512
+ return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
513
+ })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
514
+ return d.id;
515
+ }));
516
+ if (!isAvailableProduct) {
517
+ return false;
518
+ }
519
+
520
+ // vouchersApplicable 为 false 的商品不参与订单级别折扣均摊
521
+ if (isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
522
+ return false;
523
+ }
524
+
525
+ // 商品价格为0时不可用
526
+ if (Number(product.price) <= 0 || !product.price) {
527
+ return false;
528
+ }
529
+ var limitedData = discount.limited_relation_product_data;
530
+
531
+ // 时间限制检查
532
+ var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
533
+ if (!timeLimit) {
534
+ return false;
535
+ }
536
+
537
+ // 判断商品是否适用
538
+ var isLimitedProduct = false;
539
+ if (limitedData.type === 'product_all') {
540
+ var _limitedData$exclude_;
541
+ // 全品类,但需要检查是否被排除
542
+ if (limitedData.filter === 1 && (_limitedData$exclude_ = limitedData.exclude_product_ids) !== null && _limitedData$exclude_ !== void 0 && _limitedData$exclude_.includes(product.id)) {
543
+ isLimitedProduct = false;
544
+ } else {
545
+ isLimitedProduct = true;
546
+ }
547
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
548
+ isLimitedProduct = true;
549
+ }
550
+
551
+ // 套餐规则检查
552
+ var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
553
+ return isLimitedProduct && isBundleAvailable;
554
+ };
555
+
556
+ // 收集所有被勾选的 order_level 折扣卡及其适用商品
557
+ var selectedOrderLevelDiscounts = sortedDiscountList.filter(function (discount) {
558
+ return isOrderLevelFixedAmountDiscount(discount) && discount.isSelected !== false;
559
+ });
560
+
561
+ // 遍历所有被勾选的 order_level 折扣卡,建立双向映射
562
+ selectedOrderLevelDiscounts.forEach(function (discount) {
563
+ var applicableItemIds = new Set();
564
+ sortedFlattenedList.forEach(function (flatItem) {
565
+ if (checkItemApplicableForDiscount(flatItem, discount)) {
566
+ applicableItemIds.add(flatItem._id);
567
+
568
+ // 记录商品可以被哪些折扣卡使用
569
+ if (!itemApplicableDiscounts.has(flatItem._id)) {
570
+ itemApplicableDiscounts.set(flatItem._id, new Set());
571
+ }
572
+ itemApplicableDiscounts.get(flatItem._id).add(discount.id);
573
+ }
574
+ });
575
+ orderLevelDiscountApplicableItems.set(discount.id, applicableItemIds);
576
+ });
577
+
578
+ // 专属折扣卡定义:限定了特定商品(product_ids),而不是全品类(product_all)的折扣卡
579
+ // 如果专属折扣卡被勾选,它适用的商品会被占用,其他折扣卡均摊时应排除这些商品
580
+ // Map<flatItemId, discountId> - 记录被占用的商品及其对应的折扣卡
581
+ var occupiedItems = new Map();
582
+
583
+ // 按排序顺序遍历折扣卡,判断哪些是专属折扣卡
584
+ selectedOrderLevelDiscounts.forEach(function (discount) {
585
+ var limitedData = discount.limited_relation_product_data;
586
+
587
+ // 判断是否是专属折扣卡(只能用于特定商品,而不是全品类)
588
+ var isExclusiveDiscount = limitedData.type !== 'product_all';
589
+ if (isExclusiveDiscount) {
590
+ // 专属折扣卡:它适用的所有商品都会被它占用
591
+ var applicableItems = orderLevelDiscountApplicableItems.get(discount.id);
592
+ if (applicableItems) {
593
+ applicableItems.forEach(function (itemId) {
594
+ // 如果商品还没被占用,则标记为被当前折扣卡占用
595
+ if (!occupiedItems.has(itemId)) {
596
+ occupiedItems.set(itemId, discount.id);
597
+ }
598
+ });
599
+ }
600
+ }
601
+ });
602
+ console.log('occupiedItems', occupiedItems, 'orderLevelDiscountApplicableItems', orderLevelDiscountApplicableItems);
603
+
604
+ // 🔥 第三步:识别 order_level 折扣卡并预计算分摊(排除被其他专属折扣卡占用的商品)
605
+ sortedDiscountList.forEach(function (discount) {
606
+ if (!isOrderLevelFixedAmountDiscount(discount)) {
607
+ return;
608
+ }
609
+
610
+ // 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
611
+ var applicableProducts = [];
612
+ sortedFlattenedList.forEach(function (flatItem) {
613
+ var _flatItem$parentProdu2, _product$price, _ref5, _flatItem$original_pr;
614
+ // 🔥 检查该商品是否被其他专属折扣卡占用
615
+ var occupyingDiscountId = occupiedItems.get(flatItem._id);
616
+ if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
617
+ // 该商品被其他专属折扣卡占用,跳过
618
+ return;
619
+ }
620
+ if (!checkItemApplicableForDiscount(flatItem, discount)) {
621
+ return;
622
+ }
623
+ var product;
624
+ if (flatItem.type === 'main') {
625
+ product = flatItem.product;
626
+ } else {
627
+ product = {
628
+ _id: flatItem._id,
629
+ id: flatItem.id,
630
+ price: flatItem.price,
631
+ quantity: flatItem.quantity,
632
+ num: flatItem.num
633
+ };
634
+ }
635
+
636
+ // 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
637
+ var quantity = flatItem.type === 'main' ? product.quantity || 1 : (product.num || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.quantity) || 1);
638
+
639
+ // 对于主商品:使用 price
640
+ // 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
641
+ var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref5 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref5 !== void 0 ? _ref5 : 0);
642
+
643
+ // 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
644
+ var productData = {
645
+ productId: flatItem._id,
646
+ amount: originalAmount,
647
+ quantity: quantity
648
+ };
649
+
650
+ // 子商品需要传递主商品数量
651
+ if (flatItem.type === 'bundle') {
652
+ var _flatItem$parentProdu3;
653
+ productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
654
+ }
655
+ applicableProducts.push(productData);
656
+ });
657
+
658
+ // 计算分摊
659
+ if (applicableProducts.length > 0) {
660
+ var allocation = calculateOrderLevelDiscountAllocation(discount, applicableProducts);
661
+ orderLevelDiscountAllocations.set(discount.id, allocation);
662
+ }
663
+ });
664
+
403
665
  // 处理后的商品列表(按排序后的顺序处理,记录优惠信息)
404
666
  var processedProductsMap = new Map();
405
667
 
@@ -415,7 +677,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
415
677
  product = flatItem.product;
416
678
  originProduct = flatItem.originProduct;
417
679
  } else {
418
- var _flatItem$parentProdu;
680
+ var _flatItem$parentProdu4;
419
681
  // bundle子商品:构造虚拟商品对象
420
682
  product = {
421
683
  _id: flatItem._id,
@@ -427,14 +689,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
427
689
  origin_total: flatItem.origin_total,
428
690
  booking_id: flatItem.booking_id,
429
691
  discount_list: flatItem.discount_list || [],
430
- startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
692
+ startDate: (_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.startDate
431
693
  };
432
694
  originProduct = flatItem.originProduct;
433
695
  }
434
696
  addModeDiscount.forEach(function (discount) {
435
- var _product, _product2, _product3, _product4, _flatItem$bundleItem;
697
+ var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4;
436
698
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
437
-
438
699
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
439
700
  var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
440
701
  var isHolderMatch = _this3.checkHolderMatch(discount, {
@@ -442,21 +703,23 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
442
703
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
443
704
  }, holders);
444
705
  var timeLimit = true;
445
- timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
706
+ timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
446
707
  // 是符合折扣的商品
447
708
  var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
448
709
 
449
710
  // 编辑的商品 使用了优惠券不可用
450
- var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (discount) {
711
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
451
712
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
452
- })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.metadata) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.custom_product_bundle_map_id);
713
+ })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
714
+ return discount.id;
715
+ }));
453
716
 
454
717
  // 套餐是否可用判断
455
718
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
456
719
 
457
720
  // 判断优惠券是否适用于该商品
458
- if (isAvailableProduct && isLimitedProduct && isBundleAvailable && timeLimit) {
459
- var _discountApplicabilit, _discount$metadata;
721
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
722
+ var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
460
723
  // 记录此优惠券适用的商品
461
724
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
462
725
 
@@ -472,8 +735,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
472
735
  type: discountType,
473
736
  tag: discountType,
474
737
  discount: {
475
- discount_card_type: discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type,
738
+ discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
476
739
  fixed_amount: product.price,
740
+ discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
477
741
  resource_id: discount.id,
478
742
  title: discount.format_title,
479
743
  original_amount: product.price || product.origin_total,
@@ -496,14 +760,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
496
760
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
497
761
  // 🔥 使用扁平化后的列表进行处理
498
762
  sortedFlattenedList.forEach(function (flatItem, index) {
499
- var _product5, _product$discount_lis2, _product6;
763
+ var _product9, _product$discount_lis2, _product10;
500
764
  // 获取商品数据
501
765
  var product, originProduct;
502
766
  if (flatItem.type === 'main') {
503
767
  product = flatItem.product;
504
768
  originProduct = flatItem.originProduct;
505
769
  } else {
506
- var _flatItem$bundleItem2, _flatItem$bundleItem3, _flatItem$bundleItem4, _flatItem$parentProdu2;
770
+ var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu5;
507
771
  // bundle子商品
508
772
  product = {
509
773
  _id: flatItem._id,
@@ -512,17 +776,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
512
776
  quantity: flatItem.quantity,
513
777
  num: flatItem.num,
514
778
  total: flatItem.total,
515
- original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem2 = flatItem.bundleItem) === null || _flatItem$bundleItem2 === void 0 ? void 0 : _flatItem$bundleItem2.original_price,
516
- origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem3 = flatItem.bundleItem) === null || _flatItem$bundleItem3 === void 0 ? void 0 : _flatItem$bundleItem3.original_price,
779
+ original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
780
+ origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
517
781
  booking_id: flatItem.booking_id,
518
- discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem4 = flatItem.bundleItem) === null || _flatItem$bundleItem4 === void 0 ? void 0 : _flatItem$bundleItem4.discount_list) || [],
519
- startDate: (_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.startDate
782
+ discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || [],
783
+ startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
520
784
  };
521
785
  originProduct = flatItem.originProduct;
522
786
  }
523
787
 
524
788
  // 已有优惠的商品跳过
525
- if ((_product5 = product) !== null && _product5 !== void 0 && _product5.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product6 = product) !== null && _product6 !== void 0 && (_product6 = _product6.discount_list) !== null && _product6 !== void 0 && _product6.every(function (discount) {
789
+ if ((_product9 = product) !== null && _product9 !== void 0 && _product9.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product10 = product) !== null && _product10 !== void 0 && (_product10 = _product10.discount_list) !== null && _product10 !== void 0 && _product10.every(function (discount) {
526
790
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
527
791
  })) {
528
792
  if (flatItem.type === 'main') {
@@ -543,7 +807,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
543
807
  if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length) && (discount.tag || discount.type) === 'good_pass') return false;
544
808
 
545
809
  // 折扣卡商品价格为0时不可用
546
- if ((Number(product.price) === 0 || !product.price) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
810
+ if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.find(function (n) {
547
811
  var _n$discount;
548
812
  return ((_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.resource_id) === discount.id;
549
813
  })) && (discount.tag || discount.type) !== 'good_pass') return false;
@@ -594,12 +858,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
594
858
  // 如果是手动折扣,则不适用优惠券
595
859
  var isManualDiscount = false;
596
860
  if (flatItem.type === 'main') {
597
- var _product$discount_lis5, _product7, _product7$every;
861
+ var _product$discount_lis5, _product11, _product11$every;
598
862
  // 主商品:判断自身是否手动折扣
599
863
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
600
- var _ref3;
601
- return !((_ref3 = item.discount_list || []) !== null && _ref3 !== void 0 && _ref3.length);
602
- }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product7 = product) === null || _product7 === void 0 || (_product7 = _product7.discount_list) === null || _product7 === void 0 || (_product7$every = _product7.every) === null || _product7$every === void 0 ? void 0 : _product7$every.call(_product7, function (item) {
864
+ var _ref6;
865
+ return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
866
+ }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
603
867
  return item.type === 'product';
604
868
  })));
605
869
  } else {
@@ -608,8 +872,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
608
872
  if (parentProduct) {
609
873
  var _parentProduct$discou, _parentProduct$discou2, _parentProduct$discou3;
610
874
  isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
611
- var _ref4;
612
- return !((_ref4 = item.discount_list || []) !== null && _ref4 !== void 0 && _ref4.length);
875
+ var _ref7;
876
+ return !((_ref7 = item.discount_list || []) !== null && _ref7 !== void 0 && _ref7.length);
613
877
  }) && (!((_parentProduct$discou = parentProduct.discount_list) !== null && _parentProduct$discou !== void 0 && _parentProduct$discou.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou2 = parentProduct.discount_list) === null || _parentProduct$discou2 === void 0 || (_parentProduct$discou3 = _parentProduct$discou2.every) === null || _parentProduct$discou3 === void 0 ? void 0 : _parentProduct$discou3.call(_parentProduct$discou2, function (item) {
614
878
  return item.type === 'product';
615
879
  })));
@@ -628,11 +892,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
628
892
  }
629
893
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
630
894
  if (flatItem.type === 'bundle') {
631
- var _product$discount_lis7, _flatItem$parentProdu3;
895
+ var _product$discount_lis7, _flatItem$parentProdu6;
632
896
  if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
633
897
  var _item$discount2;
634
898
  return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
635
- }) || (_flatItem$parentProdu3 = flatItem.parentProduct) !== null && _flatItem$parentProdu3 !== void 0 && (_flatItem$parentProdu3 = _flatItem$parentProdu3.discount_list) !== null && _flatItem$parentProdu3 !== void 0 && _flatItem$parentProdu3.some(function (item) {
899
+ }) || (_flatItem$parentProdu6 = flatItem.parentProduct) !== null && _flatItem$parentProdu6 !== void 0 && (_flatItem$parentProdu6 = _flatItem$parentProdu6.discount_list) !== null && _flatItem$parentProdu6 !== void 0 && _flatItem$parentProdu6.some(function (item) {
636
900
  var _item$discount3;
637
901
  return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
638
902
  })) {
@@ -654,14 +918,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
654
918
  }
655
919
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
656
920
  if (flatItem.type === 'bundle') {
657
- var _product$discount_lis9, _flatItem$parentProdu4;
921
+ var _product$discount_lis9, _flatItem$parentProdu7;
658
922
  if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
659
923
  var _options$selectedList2;
660
924
  return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
661
925
  var _item$discount5;
662
926
  return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
663
927
  });
664
- }) || (_flatItem$parentProdu4 = flatItem.parentProduct) !== null && _flatItem$parentProdu4 !== void 0 && (_flatItem$parentProdu4 = _flatItem$parentProdu4.discount_list) !== null && _flatItem$parentProdu4 !== void 0 && _flatItem$parentProdu4.some(function (item) {
928
+ }) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
665
929
  var _options$selectedList3;
666
930
  return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
667
931
  var _item$discount6;
@@ -674,7 +938,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
674
938
  }
675
939
 
676
940
  // 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
677
- if (applicableDiscounts.length === 0 || isManualDiscount) {
941
+ if (applicableDiscounts.length === 0 || isManualDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
678
942
  if (flatItem.type === 'main') {
679
943
  // 主商品:保持原有逻辑
680
944
  if (product.isClient) {
@@ -700,7 +964,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
700
964
  discount_list: []
701
965
  }))]);
702
966
  } else {
703
- processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
967
+ processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
968
+ price: product.price,
969
+ main_product_selling_price: product.price
970
+ } : {
704
971
  _id: product._id.split('___')[0] + '___' + index,
705
972
  total: product.origin_total || product.total,
706
973
  price: product.price,
@@ -713,7 +980,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
713
980
  // bundle子商品:保存到扁平化Map
714
981
  processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
715
982
  discount_list: [],
716
- price: flatItem.bundleItem.original_price,
983
+ price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
717
984
  processed: true
718
985
  })]);
719
986
  }
@@ -745,7 +1012,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
745
1012
  }));
746
1013
  }
747
1014
  for (var i = 0; i < splitCount; i++) {
748
- var _product$discount_lis10, _originProduct, _selectedDiscount$met;
1015
+ var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
749
1016
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
750
1017
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
751
1018
  // 标记优惠券为已使用
@@ -766,16 +1033,32 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
766
1033
  }
767
1034
 
768
1035
  // 计算使用折扣卡/商品券以后,单个商品的总 total
769
- var targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1036
+ // 🔥 检查是否是 order_level 固定金额折扣卡
1037
+ var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
1038
+ var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
1039
+ var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
1040
+ var targetProductTotal = void 0;
1041
+ var amount = void 0;
1042
+ var productDiscountDifference = void 0;
1043
+ if (isOrderLevel && productAllocation) {
1044
+ // order_level:使用预计算的分摊金额
1045
+ amount = productAllocation.discountAmount;
1046
+ productDiscountDifference = productAllocation.difference;
1047
+ targetProductTotal = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
1048
+ } else {
1049
+ // item_level 或其他类型:使用原有逻辑
1050
+ targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
1051
+ amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
1052
+ }
770
1053
  var discountType = _selectedDiscount.tag || _selectedDiscount.type;
771
1054
  var isGoodPass = discountType === 'good_pass';
772
- var amount = new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber();
773
1055
  var discountDetail = {
774
1056
  amount: amount,
775
1057
  type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
776
1058
  discount: {
777
1059
  discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
778
1060
  fixed_amount: amount,
1061
+ discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
779
1062
  resource_id: _selectedDiscount.id,
780
1063
  title: _selectedDiscount.format_title,
781
1064
  original_amount: product.price,
@@ -784,9 +1067,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
784
1067
  },
785
1068
  // 前端使用的num数量,为了计算优惠金额
786
1069
  _num: isGoodPass ? 1 : product.num,
787
- metadata: {
1070
+ metadata: _objectSpread({
788
1071
  num: 1
789
- }
1072
+ }, productDiscountDifference !== undefined && {
1073
+ product_discount_difference: productDiscountDifference
1074
+ })
790
1075
  };
791
1076
  appliedProducts.push(discountDetail);
792
1077
  appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
@@ -841,6 +1126,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
841
1126
 
842
1127
  // 生成有折扣的商品(每张商品券对应 num: 1)
843
1128
  for (var _i = 0; _i < discountNum; _i++) {
1129
+ var _selectedDiscount2$me;
844
1130
  var _selectedDiscount2 = applicableDiscounts[_i];
845
1131
  usedDiscounts.set(_selectedDiscount2.id, true);
846
1132
 
@@ -851,6 +1137,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
851
1137
  type: 'good_pass',
852
1138
  discount: {
853
1139
  fixed_amount: product.origin_total,
1140
+ discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
854
1141
  resource_id: _selectedDiscount2.id,
855
1142
  title: _selectedDiscount2.format_title,
856
1143
  original_amount: product.origin_total,
@@ -894,33 +1181,53 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
894
1181
  }));
895
1182
  }
896
1183
  } else {
897
- var _selectedDiscount3$me, _flatItem$parentProdu5;
1184
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu8;
898
1185
  // 折扣卡:不拆分数量,直接应用
899
1186
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
900
1187
  usedDiscounts.set(_selectedDiscount3.id, true);
901
1188
  var _productOriginTotal = product.original_price || product.price || 0;
902
- var _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
903
1189
 
1190
+ // 🔥 检查是否是 order_level 固定金额折扣卡
1191
+ var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
1192
+ var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
1193
+ var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
1194
+ var _targetProductTotal;
1195
+ var fixedAmountPerItem;
1196
+ var _productDiscountDifference;
1197
+ if (_isOrderLevel && _productAllocation) {
1198
+ // order_level:使用预计算的单价折扣金额(已经是单价,无需再除以数量)
1199
+ fixedAmountPerItem = _productAllocation.discountAmount;
1200
+ _productDiscountDifference = _productAllocation.difference;
1201
+ _targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1202
+ } else {
1203
+ // item_level 或其他类型:使用原有逻辑
1204
+ _targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
1205
+ fixedAmountPerItem = new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber();
1206
+ }
1207
+ debugger;
904
1208
  // 🔥 使用当前的 _id 作为唯一标识
905
1209
  var _uniqueId = flatItem._id;
906
1210
  var _discountDetail2 = {
907
- amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber() * (product.num || 1),
1211
+ amount: fixedAmountPerItem * (product.num || 1),
908
1212
  type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
909
1213
  discount: {
910
1214
  discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
911
- fixed_amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber(),
1215
+ fixed_amount: fixedAmountPerItem,
1216
+ discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
912
1217
  resource_id: _selectedDiscount3.id,
913
1218
  title: _selectedDiscount3.format_title,
914
1219
  original_amount: product.original_price,
915
1220
  product_id: product.id,
916
1221
  percent: _selectedDiscount3.par_value
917
1222
  },
918
- metadata: {
1223
+ metadata: _objectSpread({
919
1224
  // 🔥 使用唯一的 _id
920
1225
  custom_product_bundle_map_id: _uniqueId,
921
1226
  num: product.num || 1
922
- },
923
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.num) || 1)
1227
+ }, _productDiscountDifference !== undefined && {
1228
+ product_discount_difference: _productDiscountDifference
1229
+ }),
1230
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu8 = flatItem.parentProduct) === null || _flatItem$parentProdu8 === void 0 ? void 0 : _flatItem$parentProdu8.num) || 1)
924
1231
  };
925
1232
 
926
1233
  // 记录实际应用的折扣
@@ -929,7 +1236,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
929
1236
  appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
930
1237
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
931
1238
  total: _targetProductTotal,
932
- price: new Decimal(_productOriginTotal || 0).minus(_discountDetail2.discount.fixed_amount).toNumber(),
1239
+ price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
933
1240
  discount_list: [_discountDetail2],
934
1241
  processed: true
935
1242
  }));
@@ -1039,10 +1346,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1039
1346
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1040
1347
  var _item$metadata;
1041
1348
  return _objectSpread(_objectSpread({}, discount), {}, {
1042
- metadata: {
1349
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1043
1350
  num: item.num,
1044
1351
  custom_product_bundle_map_id: (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.custom_product_bundle_map_id
1045
- }
1352
+ })
1046
1353
  // num: item.num, // 使用拆分后的 num
1047
1354
  });
1048
1355
  });
@@ -1062,10 +1369,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1062
1369
  var _updatedDiscountList = (item.discount_list || []).map(function (discount) {
1063
1370
  var _item$metadata2;
1064
1371
  return _objectSpread(_objectSpread({}, discount), {}, {
1065
- metadata: {
1372
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1066
1373
  num: item.num,
1067
1374
  custom_product_bundle_map_id: (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.custom_product_bundle_map_id
1068
- }
1375
+ })
1069
1376
  // num: item.num, // 使用当前的 num
1070
1377
  });
1071
1378
  });
@@ -1088,18 +1395,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1088
1395
 
1089
1396
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
1090
1397
  var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
1091
- var _discount$metadata2, _discount$metadata3;
1092
- if (discount !== null && discount !== void 0 && (_discount$metadata2 = discount.metadata) !== null && _discount$metadata2 !== void 0 && _discount$metadata2.custom_product_bundle_map_id) {
1398
+ var _discount$metadata6, _discount$metadata7;
1399
+ if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
1093
1400
  // bundle的discount_list保持不变
1094
1401
  return discount;
1095
1402
  }
1096
1403
  // 主商品自己的discount,更新num为1
1097
1404
  return _objectSpread(_objectSpread({}, discount), {}, {
1098
1405
  // num: 1,
1099
- metadata: {
1100
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.custom_product_bundle_map_id,
1406
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1407
+ custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata7 = discount.metadata) === null || _discount$metadata7 === void 0 ? void 0 : _discount$metadata7.custom_product_bundle_map_id,
1101
1408
  num: 1
1102
- }
1409
+ })
1103
1410
  });
1104
1411
  });
1105
1412
 
@@ -1113,14 +1420,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1113
1420
  var allDiscountAmount = getDiscountListAmountTotal(mainDiscountList);
1114
1421
  newTotalWithDiscount = (_Decimal$minus$toNumb = new Decimal(mainProductData.price || 0).minus(allDiscountAmount).toNumber()) !== null && _Decimal$minus$toNumb !== void 0 ? _Decimal$minus$toNumb : newTotalWithDiscount;
1115
1422
  newOriginTotalWithDiscount = (_mainProductData$orig = mainProductData.origin_total) !== null && _mainProductData$orig !== void 0 ? _mainProductData$orig : newOriginTotalWithDiscount;
1116
- if (newBundleWithDiscount.length > 0) {
1117
- newBundleWithDiscount.forEach(function (item) {
1118
- var _item$discount_list2;
1119
- newTotalWithDiscount += Number(item.price) * Number(item.num);
1120
- var originalPrice = ((_item$discount_list2 = item.discount_list) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2[0]) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2.discount) === null || _item$discount_list2 === void 0 ? void 0 : _item$discount_list2.original_amount) || item.price;
1121
- newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
1122
- });
1123
- }
1423
+ }
1424
+
1425
+ // 累加bundle的价格(只累加一次)
1426
+ if (newBundleWithDiscount.length > 0) {
1427
+ newBundleWithDiscount.forEach(function (item) {
1428
+ newTotalWithDiscount += Number(item.price) * Number(item.num);
1429
+ });
1430
+ newBundleWithDiscount.forEach(function (item) {
1431
+ var _item$discount_list2;
1432
+ var originalPrice = ((_item$discount_list2 = item.discount_list) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2[0]) === null || _item$discount_list2 === void 0 || (_item$discount_list2 = _item$discount_list2.discount) === null || _item$discount_list2 === void 0 ? void 0 : _item$discount_list2.original_amount) || item.price;
1433
+ newOriginTotalWithDiscount += Number(originalPrice) * Number(item.num);
1434
+ });
1124
1435
  }
1125
1436
 
1126
1437
  // 累加options的价格(options不参与折扣,在最终设置total时处理)
@@ -1158,17 +1469,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1158
1469
 
1159
1470
  // 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
1160
1471
  var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
1161
- var _discount$metadata4, _discount$metadata5;
1162
- if (discount !== null && discount !== void 0 && (_discount$metadata4 = discount.metadata) !== null && _discount$metadata4 !== void 0 && _discount$metadata4.custom_product_bundle_map_id) {
1472
+ var _discount$metadata8, _discount$metadata9;
1473
+ if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
1163
1474
  // bundle的discount_list保持不变
1164
1475
  return discount;
1165
1476
  }
1166
1477
  // 主商品自己的discount,更新num为 mainProductQuantity - 1
1167
1478
  return _objectSpread(_objectSpread({}, discount), {}, {
1168
- metadata: {
1479
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1169
1480
  num: mainProductQuantity - 1,
1170
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.custom_product_bundle_map_id
1171
- }
1481
+ custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata9 = discount.metadata) === null || _discount$metadata9 === void 0 ? void 0 : _discount$metadata9.custom_product_bundle_map_id
1482
+ })
1172
1483
  // num: mainProductQuantity - 1,
1173
1484
  });
1174
1485
  });
@@ -1183,12 +1494,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1183
1494
  var _allDiscountAmount = getDiscountListAmount(mainDiscountListOriginal);
1184
1495
  newTotalOriginal = (_Decimal$minus$toNumb2 = new Decimal(mainProductData.price || 0).minus(_allDiscountAmount).toNumber()) !== null && _Decimal$minus$toNumb2 !== void 0 ? _Decimal$minus$toNumb2 : newTotalOriginal;
1185
1496
  newOriginTotalOriginal = (_mainProductData$orig2 = mainProductData.origin_total) !== null && _mainProductData$orig2 !== void 0 ? _mainProductData$orig2 : newOriginTotalOriginal;
1186
- if (newBundleOriginal.length > 0) {
1187
- newBundleOriginal.forEach(function (item) {
1188
- newTotalOriginal += Number(item.price) * Number(item.num);
1189
- newOriginTotalOriginal += Number(item.price) * Number(item.num);
1190
- });
1191
- }
1497
+ }
1498
+
1499
+ // 累加bundle的价格(只累加一次)
1500
+ if (newBundleOriginal.length > 0) {
1501
+ newBundleOriginal.forEach(function (item) {
1502
+ newTotalOriginal += Number(item.price) * Number(item.num);
1503
+ newOriginTotalOriginal += Number(item.price) * Number(item.num);
1504
+ });
1192
1505
  }
1193
1506
 
1194
1507
  // 累加options的价格(options不参与折扣,在最终设置total时处理)
@@ -1230,12 +1543,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1230
1543
  processedBundleItems.forEach(function (item) {
1231
1544
  // 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
1232
1545
  var updatedDiscountList = (item.discount_list || []).map(function (discount) {
1233
- var _discount$metadata6;
1546
+ var _discount$metadata10;
1234
1547
  return _objectSpread(_objectSpread({}, discount), {}, {
1235
- metadata: {
1548
+ metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
1236
1549
  num: item.num,
1237
- custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata6 = discount.metadata) === null || _discount$metadata6 === void 0 ? void 0 : _discount$metadata6.custom_product_bundle_map_id
1238
- }
1550
+ custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata10 = discount.metadata) === null || _discount$metadata10 === void 0 ? void 0 : _discount$metadata10.custom_product_bundle_map_id
1551
+ })
1239
1552
  // num: item.num, // 使用拆分后的 num
1240
1553
  });
1241
1554
  });
@@ -1283,8 +1596,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1283
1596
  // 累加bundle的价格(只累加一次)
1284
1597
  if (newBundle.length > 0) {
1285
1598
  newBundle.forEach(function (item) {
1286
- var _item$discount_list3;
1287
1599
  newTotal += Number(item.price) * Number(item.num);
1600
+ });
1601
+
1602
+ // 计算原始总价(不考虑折扣)
1603
+ newBundle.forEach(function (item) {
1604
+ var _item$discount_list3;
1288
1605
  var originalPrice = ((_item$discount_list3 = item.discount_list) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3[0]) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3.discount) === null || _item$discount_list3 === void 0 ? void 0 : _item$discount_list3.original_amount) || item.price;
1289
1606
  newOriginTotal += Number(originalPrice) * Number(item.num);
1290
1607
  });
@@ -1418,10 +1735,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1418
1735
  return true; // 单独购买时可用
1419
1736
  }
1420
1737
  if (isBundleItem) {
1421
- var _flatItem$bundleItem5, _flatItem$bundleItem6;
1738
+ var _flatItem$bundleItem8, _flatItem$bundleItem9;
1422
1739
  // 套餐中购买时,判断是否为原价
1423
- var priceType = (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.price_type;
1424
- var priceTypeExt = (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.price_type_ext;
1740
+ var priceType = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type;
1741
+ var priceTypeExt = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type_ext;
1425
1742
  // original_price 对应:
1426
1743
  // 1. price_type: "markup" && price_type_ext: "product_price"
1427
1744
  // markup_price 对应:
@@ -1459,12 +1776,38 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1459
1776
  return false; // 单独购买时不可用
1460
1777
  }
1461
1778
  if (isBundleItem) {
1462
- var _flatItem$bundleItem7, _flatItem$bundleItem8;
1779
+ var _flatItem$bundleItem10, _flatItem$bundleItem11;
1463
1780
  // 套餐中购买时,判断是否为原价
1464
- var _priceType = (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.price_type;
1465
- var _priceTypeExt = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type_ext;
1781
+ var _priceType = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type;
1782
+ var _priceTypeExt = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type_ext;
1783
+
1784
+ // original_price 对应:
1785
+ // 1. price_type: "markup" && price_type_ext: "product_price"
1786
+ // markup_price 对应:
1787
+ // price_type: "markup" && price_type_ext: ""
1788
+ /** 原价 */
1789
+ var _isOriginalPrice = _priceType === 'markup' && _priceTypeExt === 'product_price';
1790
+ /** 加价 */
1791
+ var _isMarkupPrice = _priceType === 'markup' && (_priceTypeExt === '' || !_priceTypeExt);
1792
+
1793
+ // 检查 rules
1794
+ if (rules.length > 0) {
1795
+ // 检查原价
1796
+ if (_isOriginalPrice && rules.includes('original_price')) {
1797
+ return true;
1798
+ }
1799
+
1800
+ // 检查加价
1801
+ if (_isMarkupPrice && rules.includes('markup_price')) {
1802
+ return true;
1803
+ }
1804
+
1805
+ // 如果都不匹配,则不可用
1806
+ return false;
1807
+ }
1808
+
1466
1809
  // 原价包括:price_type: "markup" && price_type_ext: "product_price"
1467
- return _priceType === 'markup' && _priceTypeExt === 'product_price';
1810
+ return _isOriginalPrice;
1468
1811
  }
1469
1812
  return false;
1470
1813
  }
@@ -1533,7 +1876,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1533
1876
  case 0:
1534
1877
  this.core.effects.offByModuleDestroy(this.name);
1535
1878
  _context3.next = 3;
1536
- return this.core.effects.emit(RulesHooks.OnDestroy, {});
1879
+ return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
1537
1880
  case 3:
1538
1881
  console.log('[Rules] 已销毁');
1539
1882
  case 4: