@pisell/pisellos 0.0.569 → 0.10.2

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 (328) 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/index.js +9 -0
  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 +17 -92
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +1 -1
  13. package/dist/modules/BaseModule.js +8 -10
  14. package/dist/modules/Cart/index.js +3 -0
  15. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  16. package/dist/modules/Cart/utils/cartResource.js +0 -2
  17. package/dist/modules/Cart/utils/changePrice.js +9 -16
  18. package/dist/modules/Date/index.js +5 -1
  19. package/dist/modules/Discount/index.d.ts +0 -1
  20. package/dist/modules/Discount/index.js +7 -22
  21. package/dist/modules/Discount/types.d.ts +0 -1
  22. package/dist/modules/OpenData/index.js +2 -0
  23. package/dist/modules/Order/index.js +70 -40
  24. package/dist/modules/Payment/index.js +162 -97
  25. package/dist/modules/Payment/types.d.ts +4 -8
  26. package/dist/modules/Payment/walletpass.d.ts +0 -2
  27. package/dist/modules/Payment/walletpass.js +5 -4
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -12
  30. package/dist/modules/ProductList/types.d.ts +0 -1
  31. package/dist/modules/Rules/index.js +126 -427
  32. package/dist/modules/SalesSummary/utils.js +1 -2
  33. package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
  34. package/dist/modules/Schedule/index.js +1 -0
  35. package/dist/modules/Schedule/utils.js +1 -0
  36. package/dist/modules/Step/index.js +1 -0
  37. package/dist/modules/Summary/utils.js +22 -43
  38. package/dist/plugins/request.js +4 -1
  39. package/dist/plugins/window.js +6 -2
  40. package/dist/server/index.js +129 -97
  41. package/dist/server/modules/menu/index.js +41 -32
  42. package/dist/server/modules/order/index.js +4 -2
  43. package/dist/server/modules/products/index.js +42 -24
  44. package/dist/server/modules/quotation/index.js +38 -29
  45. package/dist/server/modules/resource/index.js +4 -3
  46. package/dist/server/modules/schedule/index.js +35 -27
  47. package/dist/server/utils/product.js +1 -0
  48. package/dist/solution/BaseSales/index.js +41 -38
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingByStep/index.js +60 -11
  51. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  52. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  53. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  54. package/dist/solution/BookingTicket/index.d.ts +1 -1
  55. package/dist/solution/BookingTicket/index.js +2 -0
  56. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +7 -6
  57. package/dist/solution/BookingTicket/utils/scan/handleScan.js +31 -25
  58. package/dist/solution/BookingTicket/utils/scan/index.js +10 -6
  59. package/dist/solution/BuyTickets/index.js +12 -9
  60. package/dist/solution/Checkout/index.js +252 -177
  61. package/dist/solution/Checkout/utils/index.js +16 -4
  62. package/dist/solution/RegisterAndLogin/index.js +76 -30
  63. package/dist/solution/ScanOrder/index.js +60 -50
  64. package/dist/solution/ShopDiscount/index.js +14 -15
  65. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  66. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  67. package/dist/solution/ShopDiscount/utils.js +0 -9
  68. package/dist/solution/VenueBooking/index.d.ts +3 -31
  69. package/dist/solution/VenueBooking/index.js +496 -651
  70. package/dist/solution/VenueBooking/types.d.ts +1 -3
  71. package/dist/solution/VenueBooking/types.js +0 -1
  72. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  73. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  74. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  75. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/utils/task.js +18 -15
  78. package/dist/utils/watch.js +1 -0
  79. package/lib/apis/picoding.js +0 -2
  80. package/lib/core/index.js +132 -130
  81. package/lib/effects/index.js +57 -46
  82. package/lib/index.d.ts +0 -1
  83. package/lib/index.js +50 -92
  84. package/lib/model/index.js +21 -14
  85. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  86. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  87. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  88. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  89. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  90. package/lib/model/strategy/adapter/index.js +64 -100
  91. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  92. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  93. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  94. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  95. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  96. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  97. package/lib/model/strategy/adapter/promotion/evaluator.js +231 -381
  98. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  99. package/lib/model/strategy/adapter/promotion/index.js +49 -1
  100. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  101. package/lib/model/strategy/adapter/type.js +16 -4
  102. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  103. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  104. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  105. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  106. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  107. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  108. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  109. package/lib/model/strategy/adapter/walletPass/utils.js +383 -678
  110. package/lib/model/strategy/engine.js +168 -270
  111. package/lib/model/strategy/index.js +34 -49
  112. package/lib/model/strategy/strategy-example.js +239 -243
  113. package/lib/model/strategy/type.js +40 -100
  114. package/lib/modules/Account/index.js +53 -39
  115. package/lib/modules/Account/types.js +33 -20
  116. package/lib/modules/AccountList/index.js +154 -116
  117. package/lib/modules/AccountList/types.js +31 -30
  118. package/lib/modules/AccountList/utils.js +30 -18
  119. package/lib/modules/BaseModule.d.ts +1 -1
  120. package/lib/modules/BaseModule.js +46 -25
  121. package/lib/modules/BookingContext/index.js +136 -158
  122. package/lib/modules/BookingContext/types.js +32 -46
  123. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +143 -131
  124. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +82 -75
  125. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +150 -170
  126. package/lib/modules/BookingContext/utils/flexible.js +55 -38
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +34 -19
  128. package/lib/modules/BookingContext/utils/index.js +41 -124
  129. package/lib/modules/BookingContext/utils/noResource.js +70 -58
  130. package/lib/modules/BookingContext/utils/orderLineDisplay.js +41 -14
  131. package/lib/modules/BookingContext/utils/productExtend.js +155 -202
  132. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  133. package/lib/modules/BookingContext/utils/resourceSelection.js +41 -19
  134. package/lib/modules/BookingContext/utils/resources.js +167 -209
  135. package/lib/modules/BookingContext/utils/serviceTimes.js +116 -115
  136. package/lib/modules/BookingContext/utils/timeSlices.js +80 -70
  137. package/lib/modules/Cart/index.js +124 -170
  138. package/lib/modules/Cart/types.js +51 -46
  139. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  140. package/lib/modules/Cart/utils/cartDate.js +61 -56
  141. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  142. package/lib/modules/Cart/utils/cartNote.js +32 -27
  143. package/lib/modules/Cart/utils/cartProduct.js +251 -321
  144. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  145. package/lib/modules/Cart/utils/cartResource.js +78 -72
  146. package/lib/modules/Cart/utils/changePrice.js +50 -28
  147. package/lib/modules/Cart/utils/index.js +48 -106
  148. package/lib/modules/Customer/constants.js +34 -13
  149. package/lib/modules/Customer/index.js +169 -232
  150. package/lib/modules/Customer/types.js +35 -38
  151. package/lib/modules/Date/index.js +115 -116
  152. package/lib/modules/Date/types.js +28 -16
  153. package/lib/modules/Date/utils.js +123 -174
  154. package/lib/modules/Discount/index.d.ts +0 -1
  155. package/lib/modules/Discount/index.js +128 -130
  156. package/lib/modules/Discount/types.d.ts +0 -1
  157. package/lib/modules/Discount/types.js +31 -9
  158. package/lib/modules/Guests/index.js +56 -30
  159. package/lib/modules/Guests/types.js +33 -23
  160. package/lib/modules/Holder/index.js +189 -209
  161. package/lib/modules/Holder/types.js +16 -4
  162. package/lib/modules/Holder/utils.js +49 -20
  163. package/lib/modules/OpenData/index.js +76 -69
  164. package/lib/modules/OpenData/types.js +16 -4
  165. package/lib/modules/OpenData/utils.js +78 -44
  166. package/lib/modules/Order/index.js +1909 -1572
  167. package/lib/modules/Order/types.js +35 -78
  168. package/lib/modules/Order/utils/bundleDiscountHydration.js +74 -41
  169. package/lib/modules/Order/utils/manualProductDiscount.js +123 -124
  170. package/lib/modules/Order/utils/orderCollectionIdentity.js +210 -148
  171. package/lib/modules/Order/utils.js +634 -799
  172. package/lib/modules/Payment/cash.js +33 -20
  173. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  174. package/lib/modules/Payment/eftpos.js +30 -16
  175. package/lib/modules/Payment/index.js +378 -518
  176. package/lib/modules/Payment/mx51.js +0 -1
  177. package/lib/modules/Payment/types.d.ts +4 -8
  178. package/lib/modules/Payment/types.js +107 -216
  179. package/lib/modules/Payment/utils.js +48 -51
  180. package/lib/modules/Payment/walletpass.d.ts +0 -2
  181. package/lib/modules/Payment/walletpass.js +211 -226
  182. package/lib/modules/Product/index.js +46 -51
  183. package/lib/modules/Product/types.js +16 -4
  184. package/lib/modules/Product/utils.js +33 -32
  185. package/lib/modules/ProductList/index.d.ts +1 -1
  186. package/lib/modules/ProductList/index.js +117 -117
  187. package/lib/modules/ProductList/types.d.ts +0 -1
  188. package/lib/modules/ProductList/types.js +31 -9
  189. package/lib/modules/Quotation/index.js +100 -66
  190. package/lib/modules/Quotation/types.js +16 -4
  191. package/lib/modules/Resource/index.js +59 -27
  192. package/lib/modules/Resource/types.js +32 -22
  193. package/lib/modules/Resource/utils.js +38 -30
  194. package/lib/modules/ResourcePlanner/index.js +61 -60
  195. package/lib/modules/ResourcePlanner/planner.js +384 -346
  196. package/lib/modules/ResourcePlanner/types.js +16 -4
  197. package/lib/modules/Rules/index.js +903 -1475
  198. package/lib/modules/Rules/types.js +40 -17
  199. package/lib/modules/SalesSummary/index.js +90 -85
  200. package/lib/modules/SalesSummary/types.js +16 -4
  201. package/lib/modules/SalesSummary/utils.js +427 -351
  202. package/lib/modules/ScanOrderLogger/index.js +79 -59
  203. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  204. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  205. package/lib/modules/ScanOrderLogger/types.js +16 -4
  206. package/lib/modules/Schedule/getDateIsInSchedule.js +163 -339
  207. package/lib/modules/Schedule/index.js +114 -100
  208. package/lib/modules/Schedule/type.js +16 -4
  209. package/lib/modules/Schedule/types.js +16 -4
  210. package/lib/modules/Schedule/utils.js +291 -433
  211. package/lib/modules/Step/index.js +52 -40
  212. package/lib/modules/Step/tyeps.js +16 -4
  213. package/lib/modules/Summary/index.js +71 -66
  214. package/lib/modules/Summary/types.js +16 -4
  215. package/lib/modules/Summary/utils.js +418 -791
  216. package/lib/modules/SurchargeList/index.js +60 -46
  217. package/lib/modules/SurchargeList/types.js +16 -4
  218. package/lib/modules/index.js +63 -245
  219. package/lib/plugins/app.js +16 -4
  220. package/lib/plugins/index.js +25 -36
  221. package/lib/plugins/request.js +126 -137
  222. package/lib/plugins/shopStore.js +16 -4
  223. package/lib/plugins/user.js +16 -4
  224. package/lib/plugins/window.js +179 -171
  225. package/lib/server/index.js +2337 -2675
  226. package/lib/server/modules/floor-plan/index.js +123 -102
  227. package/lib/server/modules/floor-plan/types.js +30 -15
  228. package/lib/server/modules/index.js +68 -106
  229. package/lib/server/modules/menu/index.js +122 -146
  230. package/lib/server/modules/menu/types.js +31 -18
  231. package/lib/server/modules/order/index.js +642 -567
  232. package/lib/server/modules/order/types.js +32 -117
  233. package/lib/server/modules/order/utils/filterBookings.js +194 -219
  234. package/lib/server/modules/order/utils/filterOrders.js +92 -118
  235. package/lib/server/modules/payment/index.js +83 -59
  236. package/lib/server/modules/payment/types.js +16 -4
  237. package/lib/server/modules/products/index.js +459 -575
  238. package/lib/server/modules/products/types.js +34 -44
  239. package/lib/server/modules/quotation/index.js +172 -137
  240. package/lib/server/modules/quotation/types.js +31 -21
  241. package/lib/server/modules/resource/index.js +184 -213
  242. package/lib/server/modules/resource/types.js +33 -42
  243. package/lib/server/modules/schedule/index.js +123 -135
  244. package/lib/server/modules/schedule/types.js +21 -14
  245. package/lib/server/modules/schedule/utils.js +163 -334
  246. package/lib/server/types.js +16 -4
  247. package/lib/server/utils/index.js +23 -25
  248. package/lib/server/utils/product.js +139 -196
  249. package/lib/server/utils/schedule.js +41 -34
  250. package/lib/server/utils/small-ticket.js +456 -478
  251. package/lib/server/utils/time.js +49 -40
  252. package/lib/solution/BaseSales/index.js +1016 -850
  253. package/lib/solution/BaseSales/types.js +37 -41
  254. package/lib/solution/BaseSales/utils/cartPromotion.js +460 -611
  255. package/lib/solution/BaseSales/utils/parseSalesResponse.js +105 -85
  256. package/lib/solution/BaseSales/utils/quotationPrice.js +114 -56
  257. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +143 -102
  258. package/lib/solution/BaseSales/utils.js +140 -155
  259. package/lib/solution/BookingByStep/index.d.ts +1 -1
  260. package/lib/solution/BookingByStep/index.js +1340 -1530
  261. package/lib/solution/BookingByStep/types.js +99 -40
  262. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  263. package/lib/solution/BookingByStep/utils/products.js +52 -42
  264. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  265. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  266. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  267. package/lib/solution/BookingTicket/index.d.ts +1 -1
  268. package/lib/solution/BookingTicket/index.js +459 -543
  269. package/lib/solution/BookingTicket/types.js +77 -99
  270. package/lib/solution/BookingTicket/utils/addProductDecision.js +184 -219
  271. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +89 -58
  272. package/lib/solution/BookingTicket/utils/bookingStatus.js +78 -107
  273. package/lib/solution/BookingTicket/utils/cartView.js +94 -110
  274. package/lib/solution/BookingTicket/utils/exampleData.js +0 -185
  275. package/lib/solution/BookingTicket/utils/orderCustomer.js +41 -18
  276. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +86 -219
  277. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +93 -144
  278. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +91 -79
  279. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +41 -54
  280. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -84
  281. package/lib/solution/BookingTicket/utils/scan/index.js +104 -98
  282. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  283. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +64 -52
  284. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +58 -56
  285. package/lib/solution/BuyTickets/index.js +70 -67
  286. package/lib/solution/BuyTickets/types.js +38 -22
  287. package/lib/solution/Checkout/index.js +1158 -1451
  288. package/lib/solution/Checkout/types.js +61 -91
  289. package/lib/solution/Checkout/utils/index.js +156 -228
  290. package/lib/solution/PlaceOrder/index.js +0 -55
  291. package/lib/solution/RegisterAndLogin/config.js +460 -493
  292. package/lib/solution/RegisterAndLogin/index.js +630 -633
  293. package/lib/solution/RegisterAndLogin/types.js +76 -189
  294. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  295. package/lib/solution/Sales/index.js +320 -317
  296. package/lib/solution/Sales/types.js +33 -27
  297. package/lib/solution/ScanOrder/index.js +862 -831
  298. package/lib/solution/ScanOrder/types.js +34 -33
  299. package/lib/solution/ScanOrder/utils.js +371 -406
  300. package/lib/solution/ShopDiscount/index.js +233 -235
  301. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  302. package/lib/solution/ShopDiscount/types.js +37 -15
  303. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  304. package/lib/solution/ShopDiscount/utils.js +172 -309
  305. package/lib/solution/UnifiedBookingSales/index.js +405 -379
  306. package/lib/solution/UnifiedBookingSales/types.js +31 -12
  307. package/lib/solution/VenueBooking/index.d.ts +3 -31
  308. package/lib/solution/VenueBooking/index.js +916 -967
  309. package/lib/solution/VenueBooking/types.d.ts +1 -3
  310. package/lib/solution/VenueBooking/types.js +39 -20
  311. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  312. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  313. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  314. package/lib/solution/VenueBooking/utils/slotMerge.js +107 -94
  315. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  316. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  317. package/lib/solution/VenueBooking/utils.js +67 -130
  318. package/lib/solution/index.js +41 -124
  319. package/lib/store/createStore.js +29 -32
  320. package/lib/types/index.d.ts +1 -1
  321. package/lib/types/index.js +16 -4
  322. package/lib/utils/task.js +36 -36
  323. package/lib/utils/watch.js +47 -81
  324. package/package.json +2 -4
  325. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  326. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  327. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  328. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,774 +1,479 @@
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/modules/Summary/utils.ts
30
+ var utils_exports = {};
31
+ __export(utils_exports, {
32
+ calcDiscountListDifference: () => calcDiscountListDifference,
33
+ calculateDeposit: () => calculateDeposit,
34
+ calculateOriginSubtotal: () => calculateOriginSubtotal,
35
+ calculatePriceDetails: () => calculatePriceDetails,
36
+ calculateSubtotal: () => calculateSubtotal,
37
+ calculateTaxFee: () => calculateTaxFee,
38
+ getBundleDiscountList: () => getBundleDiscountList,
39
+ getProductDiscountProductDiscountDifference: () => getProductDiscountProductDiscountDifference,
40
+ getSurcharge: () => getSurcharge,
41
+ getSurchargeAmount: () => getSurchargeAmount,
42
+ getTax: () => getTax
5
43
  });
6
- exports.getTax = exports.getSurchargeAmount = exports.getSurcharge = exports.getProductDiscountProductDiscountDifference = exports.getBundleDiscountList = exports.calculateTaxFee = exports.calculateSubtotal = exports.calculatePriceDetails = exports.calculateOriginSubtotal = exports.calculateDeposit = exports.calcDiscountListDifference = void 0;
7
- var _decimal = _interopRequireDefault(require("decimal.js"));
8
- var _utils = require("../Product/utils");
9
- var _dayjs = _interopRequireDefault(require("dayjs"));
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- const calculatePriceDetails = (shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) => {
12
- const subtotal = new _decimal.default(calculateSubtotal(items));
13
- const subOriginTotal = new _decimal.default(calculateOriginSubtotal(items));
14
- const totalTaxFee = new _decimal.default(calculateTaxFee(shopInfo, items));
15
- // 订单附加费列表
16
- const surcharge = getSurcharge({
17
- service: items,
18
- addons: [],
19
- bookingDetail: null,
20
- bookingId: undefined
21
- }, {
22
- isEdit: false,
23
- isInScheduleByDate,
24
- surcharge_list: surchargeList,
25
- scheduleById
26
- });
27
- // 订单附加费金额
28
- const surchargeAmount = new _decimal.default(getSurchargeAmount({
29
- bookingDetail: null,
30
- bookingId: undefined
31
- }, surcharge, {
32
- isEdit: false
33
- }));
34
- // 税费
35
- const {
36
- tax,
37
- originTax
38
- } = getTax({
39
- service: items,
40
- bookingDetail: null,
41
- bookingId: undefined
42
- }, {
44
+ module.exports = __toCommonJS(utils_exports);
45
+ var import_decimal = __toESM(require("decimal.js"));
46
+ var import_utils = require("../Product/utils");
47
+ var import_dayjs = __toESM(require("dayjs"));
48
+ var calculatePriceDetails = (shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) => {
49
+ const subtotal = new import_decimal.default(calculateSubtotal(items));
50
+ const subOriginTotal = new import_decimal.default(calculateOriginSubtotal(items));
51
+ const totalTaxFee = new import_decimal.default(calculateTaxFee(shopInfo, items));
52
+ const surcharge = getSurcharge({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate, surcharge_list: surchargeList, scheduleById });
53
+ const surchargeAmount = new import_decimal.default(getSurchargeAmount({ bookingDetail: null, bookingId: void 0 }, surcharge, { isEdit: false }));
54
+ const { tax, originTax } = getTax({ service: items, bookingDetail: null, bookingId: void 0 }, {
43
55
  computed: {
44
56
  productExpectAmount: subtotal.toNumber(),
45
57
  shopDiscount: 0
46
58
  },
47
59
  isEdit: false,
48
- tax_rate: shopInfo?.tax_rate,
49
- is_price_include_tax: shopInfo?.is_price_include_tax
60
+ tax_rate: shopInfo == null ? void 0 : shopInfo.tax_rate,
61
+ is_price_include_tax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax
50
62
  });
51
- const total = shopInfo?.is_price_include_tax ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
52
-
53
- // 计算总价 不包含折扣卡商品券折扣信息价格
54
- const originTotal = shopInfo?.is_price_include_tax ? subOriginTotal.plus(surchargeAmount) : subOriginTotal.plus(totalTaxFee).plus(surchargeAmount);
55
-
56
- // 计算定金
63
+ const total = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
64
+ const originTotal = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
57
65
  const deposit = calculateDeposit(items);
58
66
  return {
59
67
  subtotal: subtotal.toFixed(2),
60
68
  total: total.toFixed(2),
61
69
  originTotal: originTotal.toFixed(2),
62
- taxTitle: shopInfo?.tax_title,
63
- taxRate: shopInfo?.tax_rate,
70
+ taxTitle: shopInfo == null ? void 0 : shopInfo.tax_title,
71
+ taxRate: shopInfo == null ? void 0 : shopInfo.tax_rate,
64
72
  totalTaxFee: tax,
65
- isPriceIncludeTax: shopInfo?.is_price_include_tax,
73
+ isPriceIncludeTax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax,
66
74
  surcharge,
67
75
  surchargeAmount: surchargeAmount.toFixed(2),
68
76
  deposit
69
77
  };
70
78
  };
71
-
72
- /**
73
- * 获取子商品折扣信息
74
- * @param item
75
- */
76
- exports.calculatePriceDetails = calculatePriceDetails;
77
- const getBundleDiscountList = bundle => {
79
+ var getBundleDiscountList = (bundle) => {
78
80
  if (!bundle) {
79
81
  return [];
80
82
  }
81
83
  let discountList = [];
82
- bundle.forEach(d => {
84
+ bundle.forEach((d) => {
83
85
  if (d.discount_list && Array.isArray(d.discount_list)) {
84
- discountList.push(...d.discount_list.filter(item => !item.id));
86
+ discountList.push(...d.discount_list.filter((item) => !item.id));
85
87
  }
86
88
  });
87
89
  return discountList;
88
90
  };
89
- exports.getBundleDiscountList = getBundleDiscountList;
90
- const calcDiscountListDifference = discountList => {
91
+ var calcDiscountListDifference = (discountList) => {
91
92
  return discountList.reduce((pre, cur) => {
92
- return pre.plus(cur?.metadata?.product_discount_difference || 0);
93
- }, new _decimal.default(0)).toNumber();
93
+ var _a;
94
+ return pre.plus(((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
95
+ }, new import_decimal.default(0)).toNumber();
94
96
  };
95
- exports.calcDiscountListDifference = calcDiscountListDifference;
96
- const getProductDiscountProductDiscountDifference = item => {
97
- const mainDiscountList = item._origin?.product?.discount_list || [];
98
- const bundleDiscountList = getBundleDiscountList(item._origin?.product?.product_bundle || []);
97
+ var getProductDiscountProductDiscountDifference = (item) => {
98
+ var _a, _b, _c, _d;
99
+ const mainDiscountList = ((_b = (_a = item._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
100
+ const bundleDiscountList = getBundleDiscountList(((_d = (_c = item._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.product_bundle) || []);
99
101
  const discountList = [...mainDiscountList, ...bundleDiscountList];
100
102
  return calcDiscountListDifference(discountList);
101
103
  };
102
-
103
- /**
104
- * 计算订单税费(折扣前/折扣后),并把单品税费信息回写到商品数据上(用于明细展示/后续计算)。
105
- *
106
- * - **折扣前税费**:`originTax`
107
- * - **折扣后税费**:`tax`(会考虑 `computed.shopDiscount` 对每个商品的分摊影响)
108
- * - **税率/是否含税**:优先取 `bookingDetail.tax_rate` / `bookingDetail.is_price_include_tax`,取不到再回退到 `options.tax_rate` / `options.is_price_include_tax`
109
- *
110
- * **副作用(会修改入参商品对象)**:
111
- * - 主商品:写入 `item.original_tax_fee` / `item.tax_fee`(四舍五入保留两位)
112
- * - bundle 原价子商品:写入 `bundleItem.original_tax_fee` / `bundleItem.tax_fee`
113
- * - 加时商品(`relation_details`):写入 `atItem.tax_fee`
114
- * - 税费舍入差值:追加到最后一个“含税商品”的 `tax_fee_rounding_remainder` / `original_tax_fee_rounding_remainder`
115
- *
116
- * @param params 入参集合(RORO)
117
- * @param params.service 服务商品数组(主商品)。通常是购物车商品结构(可能包含 `bundle` / `relation_details`)
118
- * @param params.addons 附加商品数组(可选)。结构同商品数组
119
- * @param params.bookingDetail 订单详情(编辑/详情场景用于读取后端税率配置),可选
120
- * @param params.bookingId 订单/预约 ID(编辑/详情场景识别用),可选
121
- * @param options 计算选项
122
- * @param options.isEdit 是否处于“编辑中”。当前实现不强依赖该值(历史逻辑保留),但建议按真实状态传入
123
- * @param options.computed 预计算结果(用于折扣分摊)
124
- * @param options.computed.productExpectAmount 商品期望总金额(用于按比例分摊折扣)
125
- * @param options.computed.shopDiscount 店铺折扣总额(用于按比例分摊到商品)
126
- * @param options.tax_rate 管理端税率(百分比,如 5 表示 5%)。仅当 `bookingDetail.tax_rate` 不存在时生效
127
- * @param options.is_price_include_tax 是否含税:`0` 不含税、`1` 含税。仅当 `bookingDetail.is_price_include_tax` 不存在时生效
128
- * @returns 税费汇总(number,金额单位与商品价格一致,四舍五入保留两位)
129
- * @returns.originTax 折扣前税费合计
130
- * @returns.tax 折扣后税费合计
131
- */
132
- exports.getProductDiscountProductDiscountDifference = getProductDiscountProductDiscountDifference;
133
- const getTax = ({
134
- service,
135
- addons,
136
- bookingDetail,
137
- bookingId
138
- }, options) => {
139
- const {
140
- isEdit,
141
- computed,
142
- tax_rate,
143
- is_price_include_tax
144
- } = options;
145
-
146
- // 详情时未编辑的状态下, 取后端的值
147
- // if (!isEdit) {
148
- // return { tax: Number(bookingDetail?.tax_fee) || 0 };
149
- // }
150
-
151
- let totalOriginTax = new _decimal.default(0);
152
- let totalTax = new _decimal.default(0);
104
+ var getTax = ({ service, addons, bookingDetail, bookingId }, options) => {
105
+ const { isEdit, computed, tax_rate, is_price_include_tax } = options;
106
+ let totalOriginTax = new import_decimal.default(0);
107
+ let totalTax = new import_decimal.default(0);
153
108
  if (service || addons) {
154
- // 处理服务商品
155
- if (service?.length) {
156
- const serviceResult = processItemsTax(service.map(item => {
109
+ if (service == null ? void 0 : service.length) {
110
+ const serviceResult = processItemsTax(service.map((item) => {
157
111
  return {
158
112
  ...item,
159
- option: item?.option || item?.options || [],
160
- bundle: item?.bundle || item?.bundles || []
113
+ option: (item == null ? void 0 : item.option) || (item == null ? void 0 : item.options) || [],
114
+ bundle: (item == null ? void 0 : item.bundle) || (item == null ? void 0 : item.bundles) || []
161
115
  };
162
- }), {
163
- bookingDetail,
164
- bookingId
165
- }, {
116
+ }), { bookingDetail, bookingId }, {
166
117
  tax_rate,
167
118
  is_price_include_tax,
168
- computed: computed
119
+ computed
169
120
  });
170
121
  totalOriginTax = totalOriginTax.plus(serviceResult.originTax);
171
122
  totalTax = totalTax.plus(serviceResult.tax);
172
123
  }
173
-
174
- // 处理附加商品
175
- if (addons?.length) {
176
- const addonsResult = processItemsTax(addons, {
177
- bookingDetail,
178
- bookingId
179
- }, {
124
+ if (addons == null ? void 0 : addons.length) {
125
+ const addonsResult = processItemsTax(addons, { bookingDetail, bookingId }, {
180
126
  tax_rate,
181
127
  is_price_include_tax,
182
- computed: computed
128
+ computed
183
129
  });
184
130
  totalOriginTax = totalOriginTax.plus(addonsResult.originTax);
185
131
  totalTax = totalTax.plus(addonsResult.tax);
186
132
  }
187
133
  }
188
134
  return {
189
- originTax: totalOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber(),
190
- tax: totalTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber()
135
+ originTax: totalOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber(),
136
+ tax: totalTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber()
191
137
  };
192
138
  };
193
- exports.getTax = getTax;
194
139
  function getDiscountedTaxableBase(input) {
195
- const {
196
- basePrice,
197
- discount,
198
- surchargeFee
199
- } = input;
200
- if (surchargeFee.lte(0) && basePrice.lte(0)) return new _decimal.default(0);
140
+ const { basePrice, discount, surchargeFee } = input;
141
+ if (surchargeFee.lte(0) && basePrice.lte(0))
142
+ return new import_decimal.default(0);
201
143
  const discountedBase = basePrice.minus(discount);
202
- if (discountedBase.lte(0)) return surchargeFee;
144
+ if (discountedBase.lte(0))
145
+ return surchargeFee;
203
146
  return discountedBase.plus(surchargeFee);
204
147
  }
205
-
206
- /**
207
- * 处理商品税费计算(折扣前后)
208
- * 支持税费舍入差值追加到最后一个含税商品的 tax_fee_rounding_remainder / original_tax_fee_rounding_remainder 字段
209
- * @param items 商品数组
210
- * @param state 状态
211
- * @param options 选项
212
- * @param computed 计算结果
213
- * @returns 累积的税费信息
214
- */
215
- const processItemsTax = (items, {
216
- bookingDetail,
217
- bookingId
218
- }, options) => {
219
- const {
220
- tax_rate,
221
- is_price_include_tax,
222
- computed
223
- } = options;
224
- const {
225
- shopDiscount,
226
- productExpectAmount
227
- } = computed;
228
-
229
- // 精确税费累加(不四舍五入)
230
- let preciseOriginTax = new _decimal.default(0);
231
- let preciseTax = new _decimal.default(0);
232
- // 四舍五入后的税费累加
233
- let roundedOriginTax = new _decimal.default(0);
234
- let roundedTax = new _decimal.default(0);
235
-
236
- /**
237
- * 最后一个含税商品的引用(按物理位置)
238
- * 用于追加税费舍入差值
239
- */
148
+ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
149
+ const { tax_rate, is_price_include_tax, computed } = options;
150
+ const { shopDiscount, productExpectAmount } = computed;
151
+ let preciseOriginTax = new import_decimal.default(0);
152
+ let preciseTax = new import_decimal.default(0);
153
+ let roundedOriginTax = new import_decimal.default(0);
154
+ let roundedTax = new import_decimal.default(0);
240
155
  let lastTaxableItem = null;
241
156
  for (let item of items) {
242
- const quantity = new _decimal.default(item.num || 1);
243
- const unitPrice = new _decimal.default(item.total || 0);
244
- const mainProductPrice = new _decimal.default(getMainProductTotal({
157
+ const quantity = new import_decimal.default(item.num || 1);
158
+ const unitPrice = new import_decimal.default(item.total || 0);
159
+ const mainProductPrice = new import_decimal.default(getMainProductTotal({
245
160
  ...item,
246
- option: item?.option || item?.options || [],
247
- bundle: item?.bundle || item?.bundles || []
161
+ option: (item == null ? void 0 : item.option) || (item == null ? void 0 : item.options) || [],
162
+ bundle: (item == null ? void 0 : item.bundle) || (item == null ? void 0 : item.bundles) || []
248
163
  }) || 0);
249
-
250
- // 计算原始税费(折扣前)- 单个商品(精确值)
251
164
  const originalTaxableBase = getDiscountedTaxableBase({
252
165
  basePrice: mainProductPrice,
253
- discount: new _decimal.default(0),
254
- surchargeFee: new _decimal.default(item?.surcharge_fee || 0)
255
- });
256
- let originalTaxPerItemPrecise = getProductItemTax({
257
- ...item,
258
- total: originalTaxableBase.toNumber(),
259
- quantity: 1
260
- }, {
261
- bookingDetail,
262
- bookingId
263
- }, {
264
- tax_rate,
265
- is_price_include_tax
166
+ discount: new import_decimal.default(0),
167
+ surchargeFee: new import_decimal.default((item == null ? void 0 : item.surcharge_fee) || 0)
266
168
  });
267
-
268
- // 计算平摊到该商品的折扣
269
- let itemDiscount = new _decimal.default(0);
169
+ let originalTaxPerItemPrecise = getProductItemTax(
170
+ {
171
+ ...item,
172
+ total: originalTaxableBase.toNumber(),
173
+ quantity: 1
174
+ },
175
+ { bookingDetail, bookingId },
176
+ { tax_rate, is_price_include_tax }
177
+ );
178
+ let itemDiscount = new import_decimal.default(0);
270
179
  if (productExpectAmount > 0) {
271
180
  itemDiscount = unitPrice.dividedBy(productExpectAmount).times(shopDiscount);
272
181
  }
273
-
274
- // 按比例计算主商品应分摊的折扣
275
- let mainItemDiscount = new _decimal.default(0);
182
+ let mainItemDiscount = new import_decimal.default(0);
276
183
  if (unitPrice.greaterThan(0)) {
277
184
  mainItemDiscount = mainProductPrice.dividedBy(productExpectAmount).times(shopDiscount);
278
185
  }
279
186
  const mainItemDiscountedUnitPrice = getDiscountedTaxableBase({
280
187
  basePrice: mainProductPrice,
281
188
  discount: mainItemDiscount,
282
- surchargeFee: new _decimal.default(item?.surcharge_fee || 0)
283
- });
284
-
285
- // 计算折后税费(折扣后)- 主商品的税费(精确值)
286
- const maxDiscountedTaxPerItemPrecise = getProductItemTax({
287
- ...item,
288
- total: mainItemDiscountedUnitPrice.toNumber(),
289
- price: item.total,
290
- quantity: 1
291
- }, {
292
- bookingDetail,
293
- bookingId
294
- }, {
295
- tax_rate,
296
- is_price_include_tax
189
+ surchargeFee: new import_decimal.default((item == null ? void 0 : item.surcharge_fee) || 0)
297
190
  });
298
-
299
- // 四舍五入后的值
300
- const maxDiscountedTaxPerItemRounded = maxDiscountedTaxPerItemPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
301
-
302
- // 保存到商品扩展信息中(保留两位小数)
191
+ const maxDiscountedTaxPerItemPrecise = getProductItemTax(
192
+ {
193
+ ...item,
194
+ total: mainItemDiscountedUnitPrice.toNumber(),
195
+ price: item.total,
196
+ quantity: 1
197
+ },
198
+ { bookingDetail, bookingId },
199
+ { tax_rate, is_price_include_tax }
200
+ );
201
+ const maxDiscountedTaxPerItemRounded = maxDiscountedTaxPerItemPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
303
202
  item.main_product_attached_bundle_tax_fee = maxDiscountedTaxPerItemRounded.toNumber();
304
-
305
- // 如果主商品有税费,记录为最后一个含税商品
306
203
  if (maxDiscountedTaxPerItemPrecise.gt(0)) {
307
- lastTaxableItem = {
308
- type: 'main',
309
- item
310
- };
204
+ lastTaxableItem = { type: "main", item };
311
205
  }
312
-
313
- // 注意:加时商品独立计算,不考虑主商品数量
314
- let addTimePreciseTax = new _decimal.default(0);
315
- let addTimeRoundedTax = new _decimal.default(0);
206
+ let addTimePreciseTax = new import_decimal.default(0);
207
+ let addTimeRoundedTax = new import_decimal.default(0);
316
208
  if (Array.isArray(item.relation_details)) {
317
209
  for (let atItem of item.relation_details) {
318
- // 计算单件加时商品折扣后价格
319
- const _originTotal = new _decimal.default(atItem.selling_price || atItem.price || 0);
320
- const addTimeDiscount = productExpectAmount > 0 ? _originTotal.dividedBy(productExpectAmount).times(shopDiscount) : new _decimal.default(0);
210
+ const _originTotal = new import_decimal.default(
211
+ atItem.selling_price || atItem.price || 0
212
+ );
213
+ const addTimeDiscount = productExpectAmount > 0 ? _originTotal.dividedBy(productExpectAmount).times(shopDiscount) : new import_decimal.default(0);
321
214
  const _discountedTotal = getDiscountedTaxableBase({
322
215
  basePrice: _originTotal,
323
216
  discount: addTimeDiscount,
324
- surchargeFee: new _decimal.default(atItem?.surcharge_fee || 0)
217
+ surchargeFee: new import_decimal.default((atItem == null ? void 0 : atItem.surcharge_fee) || 0)
325
218
  });
326
- const addTimeTaxPerItemPrecise = getProductItemTax({
327
- ...atItem,
328
- total: _discountedTotal.toNumber(),
329
- quantity: atItem.product_quantity || atItem.num || 1
330
- }, {
331
- bookingDetail,
332
- bookingId
333
- }, {
334
- tax_rate,
335
- is_price_include_tax
336
- });
337
- const addTimeTaxPerItemRounded = addTimeTaxPerItemPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
338
-
339
- // 保存到加时商品上(四舍五入后的值)
219
+ const addTimeTaxPerItemPrecise = getProductItemTax(
220
+ {
221
+ ...atItem,
222
+ total: _discountedTotal.toNumber(),
223
+ quantity: atItem.product_quantity || atItem.num || 1
224
+ },
225
+ { bookingDetail, bookingId },
226
+ { tax_rate, is_price_include_tax }
227
+ );
228
+ const addTimeTaxPerItemRounded = addTimeTaxPerItemPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
340
229
  atItem.tax_fee = addTimeTaxPerItemRounded.toNumber();
341
230
  addTimePreciseTax = addTimePreciseTax.plus(addTimeTaxPerItemPrecise);
342
231
  addTimeRoundedTax = addTimeRoundedTax.plus(addTimeTaxPerItemRounded);
343
-
344
- // 如果加时商品有税费,记录为最后一个含税商品
345
232
  if (addTimeTaxPerItemPrecise.gt(0)) {
346
- lastTaxableItem = {
347
- type: 'addTime',
348
- item: atItem
349
- };
233
+ lastTaxableItem = { type: "addTime", item: atItem };
350
234
  }
351
235
  }
352
236
  }
353
-
354
- // 处理 bundle 子商品(仅原价子商品)
355
- let bundlePreciseOriginTax = new _decimal.default(0);
356
- let bundlePreciseTax = new _decimal.default(0);
357
- let bundleRoundedOriginTax = new _decimal.default(0);
358
- let bundleRoundedTax = new _decimal.default(0);
359
- if (Array.isArray(item?.bundle)) {
360
- for (let bundleItem of item?.bundle) {
361
- // 只处理原价的子商品
237
+ let bundlePreciseOriginTax = new import_decimal.default(0);
238
+ let bundlePreciseTax = new import_decimal.default(0);
239
+ let bundleRoundedOriginTax = new import_decimal.default(0);
240
+ let bundleRoundedTax = new import_decimal.default(0);
241
+ if (Array.isArray(item == null ? void 0 : item.bundle)) {
242
+ for (let bundleItem of item == null ? void 0 : item.bundle) {
362
243
  if (getBundleItemIsOriginalPrice(bundleItem)) {
363
- const bundleQuantity = new _decimal.default(bundleItem.num || bundleItem.quantity || 1);
364
- const bundleUnitPrice = new _decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
365
-
366
- // 计算原始税费(折扣前)- 单个商品(精确值)
244
+ const bundleQuantity = new import_decimal.default(bundleItem.num || bundleItem.quantity || 1);
245
+ const bundleUnitPrice = new import_decimal.default(
246
+ bundleItem.bundle_selling_price ?? bundleItem.price ?? 0
247
+ );
367
248
  const bundleOriginalTaxableBase = getDiscountedTaxableBase({
368
249
  basePrice: bundleUnitPrice,
369
- discount: new _decimal.default(0),
370
- surchargeFee: new _decimal.default(bundleItem?.surcharge_fee || 0)
371
- });
372
- const bundleOriginalTaxPerItemPrecise = getProductItemTax({
373
- ...bundleItem,
374
- total: bundleOriginalTaxableBase.toNumber(),
375
- quantity: 1
376
- }, {
377
- bookingDetail,
378
- bookingId
379
- }, {
380
- tax_rate,
381
- is_price_include_tax
250
+ discount: new import_decimal.default(0),
251
+ surchargeFee: new import_decimal.default((bundleItem == null ? void 0 : bundleItem.surcharge_fee) || 0)
382
252
  });
383
-
384
- // 计算平摊到该bundle商品的折扣
385
- let bundleItemDiscount = new _decimal.default(0);
253
+ const bundleOriginalTaxPerItemPrecise = getProductItemTax(
254
+ {
255
+ ...bundleItem,
256
+ total: bundleOriginalTaxableBase.toNumber(),
257
+ quantity: 1
258
+ },
259
+ { bookingDetail, bookingId },
260
+ { tax_rate, is_price_include_tax }
261
+ );
262
+ let bundleItemDiscount = new import_decimal.default(0);
386
263
  if (productExpectAmount > 0) {
387
264
  bundleItemDiscount = bundleUnitPrice.dividedBy(productExpectAmount).times(shopDiscount);
388
265
  }
389
-
390
- // bundle商品折后单价
391
266
  const bundleDiscountedUnitPrice = getDiscountedTaxableBase({
392
267
  basePrice: bundleUnitPrice,
393
268
  discount: bundleItemDiscount,
394
- surchargeFee: new _decimal.default(bundleItem?.surcharge_fee || 0)
269
+ surchargeFee: new import_decimal.default((bundleItem == null ? void 0 : bundleItem.surcharge_fee) || 0)
395
270
  });
396
-
397
- // 计算折后税费(折扣后)- 单个商品(精确值)
398
- const bundleDiscountedTaxPerItemPrecise = getProductItemTax({
399
- ...bundleItem,
400
- total: bundleDiscountedUnitPrice.toNumber(),
401
- quantity: 1
402
- }, {
403
- bookingDetail,
404
- bookingId
405
- }, {
406
- tax_rate,
407
- is_price_include_tax
408
- });
409
-
410
- // 四舍五入后的值
411
- const bundleOriginalTaxPerItemRounded = bundleOriginalTaxPerItemPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
412
- const bundleDiscountedTaxPerItemRounded = bundleDiscountedTaxPerItemPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
413
-
414
- // 保存到bundle商品上(单个商品的税费,四舍五入后)
271
+ const bundleDiscountedTaxPerItemPrecise = getProductItemTax(
272
+ {
273
+ ...bundleItem,
274
+ total: bundleDiscountedUnitPrice.toNumber(),
275
+ quantity: 1
276
+ },
277
+ { bookingDetail, bookingId },
278
+ { tax_rate, is_price_include_tax }
279
+ );
280
+ const bundleOriginalTaxPerItemRounded = bundleOriginalTaxPerItemPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
281
+ const bundleDiscountedTaxPerItemRounded = bundleDiscountedTaxPerItemPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
415
282
  bundleItem.original_tax_fee = bundleOriginalTaxPerItemRounded.toNumber();
416
283
  bundleItem.tax_fee = bundleDiscountedTaxPerItemRounded.toNumber();
417
-
418
- // 累加bundle税费(需要乘以bundle数量)
419
284
  bundlePreciseOriginTax = bundlePreciseOriginTax.plus(bundleOriginalTaxPerItemPrecise.times(bundleQuantity));
420
285
  bundlePreciseTax = bundlePreciseTax.plus(bundleDiscountedTaxPerItemPrecise.times(bundleQuantity));
421
286
  bundleRoundedOriginTax = bundleRoundedOriginTax.plus(bundleOriginalTaxPerItemRounded.times(bundleQuantity));
422
287
  bundleRoundedTax = bundleRoundedTax.plus(bundleDiscountedTaxPerItemRounded.times(bundleQuantity));
423
-
424
- // 如果bundle商品有税费,记录为最后一个含税商品
425
288
  if (bundleDiscountedTaxPerItemPrecise.gt(0)) {
426
- lastTaxableItem = {
427
- type: 'bundle',
428
- item: bundleItem
429
- };
289
+ lastTaxableItem = { type: "bundle", item: bundleItem };
430
290
  }
431
291
  }
432
292
  }
433
293
  }
434
- // 主商品的原始税费和折后税费(精确值)
435
294
  const originalTaxFeePrecise = originalTaxPerItemPrecise.plus(bundlePreciseOriginTax);
436
295
  const taxFeePrecise = maxDiscountedTaxPerItemPrecise.plus(bundlePreciseTax);
437
-
438
- // 主商品的原始税费和折后税费(四舍五入后)
439
- const originalTaxFeeRounded = originalTaxPerItemPrecise.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
296
+ const originalTaxFeeRounded = originalTaxPerItemPrecise.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).plus(bundleRoundedOriginTax);
440
297
  const taxFeeRounded = maxDiscountedTaxPerItemRounded.plus(bundleRoundedTax);
441
-
442
- // 保存到商品扩展信息中(四舍五入后的值)
443
- item.original_tax_fee = originalTaxFeeRounded.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
444
- item.tax_fee = taxFeeRounded.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
445
-
446
- // 累加到总税费(乘以数量)
298
+ item.original_tax_fee = originalTaxFeeRounded.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
299
+ item.tax_fee = taxFeeRounded.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
447
300
  preciseOriginTax = preciseOriginTax.plus(originalTaxFeePrecise.times(quantity)).plus(addTimePreciseTax);
448
301
  preciseTax = preciseTax.plus(taxFeePrecise.times(quantity)).plus(addTimePreciseTax);
449
302
  roundedOriginTax = roundedOriginTax.plus(originalTaxFeeRounded.times(quantity)).plus(addTimeRoundedTax);
450
303
  roundedTax = roundedTax.plus(taxFeeRounded.times(quantity)).plus(addTimeRoundedTax);
451
304
  }
452
-
453
- // 计算期望的总税费(精确累加后四舍五入)
454
- const expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
455
- const expectedTax = preciseTax.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
456
-
457
- // 计算舍入差值
305
+ const expectedOriginTax = preciseOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
306
+ const expectedTax = preciseTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
458
307
  const originTaxRemainder = expectedOriginTax.minus(roundedOriginTax).toNumber();
459
308
  const taxRemainder = expectedTax.minus(roundedTax).toNumber();
460
-
461
- // 将差值追加到最后一个含税商品
462
309
  if (lastTaxableItem) {
463
310
  if (originTaxRemainder !== 0) {
464
- if (lastTaxableItem.type === 'main') {
311
+ if (lastTaxableItem.type === "main") {
465
312
  lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
466
313
  } else {
467
314
  lastTaxableItem.item.original_tax_fee_rounding_remainder = originTaxRemainder;
468
315
  }
469
316
  }
470
317
  if (taxRemainder !== 0) {
471
- if (lastTaxableItem.type === 'main') {
318
+ if (lastTaxableItem.type === "main") {
472
319
  lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
473
320
  } else {
474
321
  lastTaxableItem.item.tax_fee_rounding_remainder = taxRemainder;
475
322
  }
476
323
  }
477
324
  }
478
- return {
479
- originTax: expectedOriginTax,
480
- tax: expectedTax
481
- };
325
+ return { originTax: expectedOriginTax, tax: expectedTax };
482
326
  };
483
-
484
- /**
485
- * 计算单个商品的税费(返回精确值,不四舍五入)
486
- * @param item 商品信息
487
- * @param state 状态
488
- * @param options 选项
489
- * @returns 精确的税费值(Decimal类型)
490
- */
491
- const getProductItemTax = (item, state, options) => {
492
- const {
493
- bookingDetail
494
- } = state;
495
- const {
496
- tax_rate,
497
- is_price_include_tax
498
- } = options;
499
-
500
- // 折扣后的金额 = 商品金额 - 商品折扣
501
- const productDiscountPrice = new _decimal.default(item.total || 0);
502
- /**
503
- * 注意:该函数被多处以“单件税费”方式调用(调用方会显式传入 quantity: 1),
504
- * 因此这里必须优先使用 `item.quantity`,否则会出现数量被重复相乘(外层再乘一次 num)的情况。
505
- */
506
- const quantity = new _decimal.default(item.quantity ?? item.num ?? 1);
507
-
508
- // 如果商品金额小于或等于0,不计算税费
327
+ var getProductItemTax = (item, state, options) => {
328
+ const { bookingDetail } = state;
329
+ const { tax_rate, is_price_include_tax } = options;
330
+ const productDiscountPrice = new import_decimal.default(item.total || 0);
331
+ const quantity = new import_decimal.default(item.quantity ?? item.num ?? 1);
509
332
  if (productDiscountPrice.lte(0)) {
510
- return new _decimal.default(0);
333
+ return new import_decimal.default(0);
511
334
  }
512
-
513
- // 优先从 bookingDetail 取税率和是否含税设置,取不到则从 options 中取(兼容新增模式)
514
- // 注意:bookingDetail中的tax_rate不需要除以100,options 中的tax_rate需要除以100
515
- const currentTaxRate = new _decimal.default(bookingDetail?.tax_rate ?? (tax_rate ? tax_rate / 100 : 0));
516
- const currentIsPriceIncludeTax = bookingDetail?.is_price_include_tax ?? is_price_include_tax ?? 0;
517
- let singleItemTax = new _decimal.default(0);
518
-
519
- // 计算单个商品税费, 一次性商品 is_charge_tax 可能为空
335
+ const currentTaxRate = new import_decimal.default(
336
+ (bookingDetail == null ? void 0 : bookingDetail.tax_rate) ?? (tax_rate ? tax_rate / 100 : 0)
337
+ );
338
+ const currentIsPriceIncludeTax = (bookingDetail == null ? void 0 : bookingDetail.is_price_include_tax) ?? is_price_include_tax ?? 0;
339
+ let singleItemTax = new import_decimal.default(0);
520
340
  if (item.is_charge_tax === 0 || !item.is_charge_tax) {
521
- // 该商品不需要收税
522
- singleItemTax = new _decimal.default(0);
341
+ singleItemTax = new import_decimal.default(0);
523
342
  } else {
524
- // 该商品需要收税
525
343
  if (currentIsPriceIncludeTax === 0) {
526
- // 价格不含税:管理端填写的单价是不含税的价格
527
344
  singleItemTax = productDiscountPrice.times(currentTaxRate);
528
345
  } else {
529
- // 价格含税:管理端填写的单价是含税的价格
530
- // 含税总价 = 不含税价 + (不含税价 * 税率) = 不含税价 * (1 + 税率)
531
- // 商品不含税价 = 含税总价 / (1 + 税率)
532
- // 税 = 不含税价 * 税率
533
- const divisor = new _decimal.default(1).plus(currentTaxRate);
346
+ const divisor = new import_decimal.default(1).plus(currentTaxRate);
534
347
  if (divisor.lte(0)) {
535
- // 如果 (1 + 税率) <= 0,说明税率异常,不计算税费
536
- singleItemTax = new _decimal.default(0);
348
+ singleItemTax = new import_decimal.default(0);
537
349
  } else {
538
350
  singleItemTax = productDiscountPrice.dividedBy(divisor).times(currentTaxRate);
539
351
  }
540
352
  }
541
353
  }
542
-
543
- // 结果 = 单个商品税费 × 数量(返回精确值,不四舍五入)
544
354
  return singleItemTax.times(quantity);
545
355
  };
546
-
547
- /**
548
- * 计算商品小计(不含其他费用)
549
- * @param items - 购物车商品数组
550
- * @returns 商品总价字符串,保留2位小数
551
- */
552
- const calculateSubtotal = items => {
553
- if (!items?.length) {
554
- return '0.00';
356
+ var calculateSubtotal = (items) => {
357
+ if (!(items == null ? void 0 : items.length)) {
358
+ return "0.00";
555
359
  }
556
360
  const subtotal = items.reduce((sum, item) => {
557
- const cartItemTotalPrice = new _decimal.default(item.summaryTotal || 0);
361
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
558
362
  const productDiscountProductDiscountDifference = getProductDiscountProductDiscountDifference(item);
559
363
  return sum.plus(cartItemTotalPrice).sub(productDiscountProductDiscountDifference);
560
- }, new _decimal.default(0));
364
+ }, new import_decimal.default(0));
561
365
  return subtotal.toFixed(2);
562
366
  };
563
-
564
- /**
565
- * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
566
- * @param items - 购物车商品数组
567
- * @returns 商品总价字符串,保留2位小数
568
- */
569
- exports.calculateSubtotal = calculateSubtotal;
570
- const calculateOriginSubtotal = items => {
571
- if (!items?.length) {
572
- return '0.00';
367
+ var calculateOriginSubtotal = (items) => {
368
+ if (!(items == null ? void 0 : items.length)) {
369
+ return "0.00";
573
370
  }
574
371
  const subtotal = items.reduce((sum, item) => {
575
- const cartItemTotalPrice = new _decimal.default(item.summaryOriginTotal || 0);
372
+ const cartItemTotalPrice = new import_decimal.default(item.summaryOriginTotal || 0);
576
373
  return sum.plus(cartItemTotalPrice);
577
- }, new _decimal.default(0));
374
+ }, new import_decimal.default(0));
578
375
  return subtotal.toFixed(2);
579
376
  };
580
-
581
- /**
582
- * @title: 单个商品的税费
583
- * @description:
584
- * 单个商品的税费 = 商品销售单价(折扣后) * 税率 * is_charge_tax /( 1+ 税率 * is_price_include_tax)
585
- * $taxFee = $price * $taxRate * $isChargeTax / (1 + $taxRate * $isPriceIncludeTax);
586
- * @return {*}
587
- * @Author: xiangfeng.xue
588
- */
589
- exports.calculateOriginSubtotal = calculateOriginSubtotal;
590
- const calculateTaxFee = (shopInfo, items) => {
591
- if (!items?.length) {
592
- return '0.00';
377
+ var calculateTaxFee = (shopInfo, items) => {
378
+ if (!(items == null ? void 0 : items.length)) {
379
+ return "0.00";
593
380
  }
594
- const {
595
- is_price_include_tax,
596
- tax_rate
597
- } = shopInfo || {};
381
+ const { is_price_include_tax, tax_rate } = shopInfo || {};
598
382
  const totalTaxFee = items.reduce((sum, item) => {
599
- const cartItemTotalPrice = new _decimal.default(item.summaryTotal || 0);
600
- const taxRate = new _decimal.default(tax_rate || 0).div(100);
601
- const productTaxRate = cartItemTotalPrice.times(taxRate).times(item?.is_charge_tax || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
383
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
384
+ const taxRate = new import_decimal.default(tax_rate || 0).div(100);
385
+ const productTaxRate = cartItemTotalPrice.times(taxRate).times((item == null ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
602
386
  return sum.plus(productTaxRate);
603
- }, new _decimal.default(0));
387
+ }, new import_decimal.default(0));
604
388
  return totalTaxFee;
605
389
  };
606
- exports.calculateTaxFee = calculateTaxFee;
607
- const getCartItemDepositData = item => {
608
- const target = item;
609
- return target?._productOrigin?.custom_deposit_data || target?._origin?.custom_deposit_data || target?._origin?.product?.custom_deposit_data;
610
- };
611
- const getCartItemQuantity = item => {
612
- return new _decimal.default(item?.num || 1);
613
- };
614
- const calculateCartItemDepositTotal = item => {
615
- const depositData = getCartItemDepositData(item);
616
- if (depositData?.has_deposit == 1 && typeof depositData?.deposit_fixed === 'string' && typeof depositData?.deposit_percentage === 'string') {
617
- const lineTotal = new _decimal.default(item.summaryTotal ?? item.total ?? 0);
618
- const quantity = getCartItemQuantity(item);
619
- const fixedTotal = new _decimal.default(depositData.deposit_fixed || 0).times(quantity);
620
- const percentageTotal = new _decimal.default(depositData.deposit_percentage || 0).times(lineTotal);
621
- return fixedTotal.plus(percentageTotal);
622
- }
623
- return new _decimal.default(item?.deposit?.total || 0);
624
- };
625
-
626
- /**
627
- * @title: 计算定金
628
- * @param items - 购物车商品数组
629
- * @returns 定金字符串,保留2位小数
630
- */
631
- const calculateDeposit = items => {
632
- if (!items?.length) {
633
- return undefined;
390
+ var calculateDeposit = (items) => {
391
+ if (!(items == null ? void 0 : items.length)) {
392
+ return void 0;
634
393
  }
635
394
  const protocols = [];
636
395
  let hasDeposit = false;
637
396
  const total = items.reduce((sum, item) => {
638
- if (item?.deposit) {
397
+ var _a, _b, _c;
398
+ if (item == null ? void 0 : item.deposit) {
639
399
  hasDeposit = true;
640
- const cartItemTotalPrice = calculateCartItemDepositTotal(item);
641
- // 将协议数据去重合并
642
- item?.deposit?.protocols?.forEach(protocol => {
643
- if (protocols.findIndex(p => p.id === protocol.id) === -1) {
400
+ const cartItemTotalPrice = new import_decimal.default(((_a = item == null ? void 0 : item.deposit) == null ? void 0 : _a.total) || 0);
401
+ (_c = (_b = item == null ? void 0 : item.deposit) == null ? void 0 : _b.protocols) == null ? void 0 : _c.forEach((protocol) => {
402
+ if (protocols.findIndex((p) => p.id === protocol.id) === -1) {
644
403
  protocols.push(protocol);
645
404
  }
646
405
  });
647
406
  return sum.plus(cartItemTotalPrice);
648
407
  }
649
408
  return sum;
650
- }, new _decimal.default(0));
409
+ }, new import_decimal.default(0));
651
410
  if (hasDeposit) {
652
- return {
653
- total: total.toFixed(2),
654
- protocols,
655
- hasDeposit
656
- };
411
+ return { total: total.toFixed(2), protocols, hasDeposit };
657
412
  }
658
- return undefined;
413
+ return void 0;
659
414
  };
660
-
661
- /**
662
- * 计算订单附加费金额(订单级别合计)。
663
- *
664
- * - **详情未编辑**(`!options.isEdit && bookingId`)且存在后端详情时:直接返回 `bookingDetail.surcharge_fee`
665
- * - **新增/编辑**时:对 `surcharge`(通常为 `getSurcharge` 的返回值)按 `item.value` 求和
666
- *
667
- * @param params 入参集合(RORO)
668
- * @param params.bookingDetail 订单详情(详情未编辑时用于读取后端的 `surcharge_fee`),可选
669
- * @param params.bookingId 订单/预约 ID(详情未编辑时生效),可选
670
- * @param surcharge 附加费列表(通常来自 `getSurcharge`),元素结构至少包含 `value: number`
671
- * @param options 计算选项
672
- * @param options.isEdit 是否处于“编辑中”。`false` 时会优先走后端金额直取逻辑(若存在)
673
- * @returns 订单附加费金额(number,金额单位与商品价格一致)
674
- */
675
- exports.calculateDeposit = calculateDeposit;
676
- const getSurchargeAmount = ({
677
- bookingDetail,
678
- bookingId
679
- }, surcharge, options) => {
680
- const {
681
- isEdit
682
- } = options;
683
- // 订单未变更过
415
+ var getSurchargeAmount = ({ bookingDetail, bookingId }, surcharge, options) => {
416
+ const { isEdit } = options;
684
417
  if (!isEdit) {
685
- // 有后端数据则直接使用后端的数据
686
418
  if (bookingDetail && bookingId) {
687
419
  return Number(bookingDetail.surcharge_fee);
688
420
  }
689
421
  }
690
- if (!Array.isArray(surcharge)) return 0;
691
- // 新增状态使用 getSurcharge 的返回值进行求和
422
+ if (!Array.isArray(surcharge))
423
+ return 0;
692
424
  return surcharge.reduce((total, item) => {
693
425
  return total.plus(item.value || 0);
694
- }, new _decimal.default(0)).toNumber();
426
+ }, new import_decimal.default(0)).toNumber();
695
427
  };
696
-
697
- // bundle商品是否是原价
698
- exports.getSurchargeAmount = getSurchargeAmount;
699
- const getBundleItemIsOriginalPrice = item => {
700
- return item?.price_type === 'markup' && item?.price_type_ext === 'product_price';
428
+ var getBundleItemIsOriginalPrice = (item) => {
429
+ return (item == null ? void 0 : item.price_type) === "markup" && (item == null ? void 0 : item.price_type_ext) === "product_price";
701
430
  };
702
-
703
- // bundle商品是否是加价
704
- const getBundleItemIsMarkupPrice = item => {
705
- return item?.price_type === 'markup' && (item?.price_type_ext === '' || !item?.price_type_ext);
431
+ var getBundleItemIsMarkupPrice = (item) => {
432
+ return (item == null ? void 0 : item.price_type) === "markup" && ((item == null ? void 0 : item.price_type_ext) === "" || !(item == null ? void 0 : item.price_type_ext));
706
433
  };
707
-
708
- // bundle商品是否是减价
709
- const getBundleItemIsDiscountPrice = item => {
710
- return item?.price_type === 'markdown' && (item?.price_type_ext === '' || !item?.price_type_ext);
434
+ var getBundleItemIsDiscountPrice = (item) => {
435
+ return (item == null ? void 0 : item.price_type) === "markdown" && ((item == null ? void 0 : item.price_type_ext) === "" || !(item == null ? void 0 : item.price_type_ext));
711
436
  };
712
-
713
- // bundle商品是否是加价或减价
714
- const getBundleItemIsMarkupOrDiscountPrice = item => {
437
+ var getBundleItemIsMarkupOrDiscountPrice = (item) => {
715
438
  return getBundleItemIsMarkupPrice(item) || getBundleItemIsDiscountPrice(item);
716
439
  };
717
- const getDiscountAmount = discounts => {
440
+ var getDiscountAmount = (discounts) => {
718
441
  return (discounts || []).reduce((total, discount) => {
719
- return total.add(new _decimal.default(discount.amount || 0));
720
- }, new _decimal.default(0)).toNumber();
442
+ return total.add(new import_decimal.default(discount.amount || 0));
443
+ }, new import_decimal.default(0)).toNumber();
721
444
  };
722
-
723
- /**
724
- * 获取主商品加价减价后的总价 (主商品价格 + 子商品加价减价)
725
- */
726
- const getMainProductTotal = item => {
727
- // 新语义 v2 下 `main_product_selling_price` / `metadata.main_product_selling_price`
728
- // 已经是"含 option、含主商品折扣"的主价,直接作为主商品基准,无需再减折扣或加 option。
729
- // 仅需叠加 markup / markdown 类 bundle(原价 bundle 的税费单独处理)。
730
- let total = new _decimal.default(item?.main_product_selling_price ?? item?.metadata?.main_product_selling_price ?? item?.metadata?.main_product_original_price ?? 0);
731
-
732
- // 做个兜底 如果新语义价格字段都没有,则切换回老逻辑
733
- const hasMainProductPrice = item?.main_product_selling_price != null || item?.metadata?.main_product_selling_price != null || item?.metadata?.main_product_original_price != null;
445
+ var getMainProductTotal = (item) => {
446
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
447
+ let total = new import_decimal.default(
448
+ (item == null ? void 0 : item.main_product_selling_price) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.main_product_selling_price) ?? ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.main_product_original_price) ?? 0
449
+ );
450
+ const hasMainProductPrice = (item == null ? void 0 : item.main_product_selling_price) != null || ((_c = item == null ? void 0 : item.metadata) == null ? void 0 : _c.main_product_selling_price) != null || ((_d = item == null ? void 0 : item.metadata) == null ? void 0 : _d.main_product_original_price) != null;
734
451
  if (!hasMainProductPrice) {
735
- total = new _decimal.default(item?.main_product_selling_price ?? item?.metadata?.main_product_selling_price ?? item.price ?? 0);
736
- const discount = item?._origin?.product?.discount_list || item?._originData?.product?.discount_list?.filter(item => {
737
- return !item?.metadata?.custom_product_bundle_map_id;
738
- }) || [];
452
+ total = new import_decimal.default((item == null ? void 0 : item.main_product_selling_price) ?? ((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.main_product_selling_price) ?? item.price ?? 0);
453
+ const discount = ((_g = (_f = item == null ? void 0 : item._origin) == null ? void 0 : _f.product) == null ? void 0 : _g.discount_list) || ((_j = (_i = (_h = item == null ? void 0 : item._originData) == null ? void 0 : _h.product) == null ? void 0 : _i.discount_list) == null ? void 0 : _j.filter((item2) => {
454
+ var _a2;
455
+ return !((_a2 = item2 == null ? void 0 : item2.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
456
+ })) || [];
739
457
  const mainProductDiscountAmount = getDiscountAmount(discount);
740
458
  total = total.minus(mainProductDiscountAmount);
741
-
742
- // 单规格
743
- if (item?.option && Array.isArray(item?.option)) {
744
- total = total.add(item?.option.reduce((t, option) => {
745
- return t.add(new _decimal.default(option.price || 0).mul(option.num || 1));
746
- }, new _decimal.default(0)));
459
+ if ((item == null ? void 0 : item.option) && Array.isArray(item == null ? void 0 : item.option)) {
460
+ total = total.add(item == null ? void 0 : item.option.reduce((t, option) => {
461
+ return t.add(new import_decimal.default(option.price || 0).mul(option.num || 1));
462
+ }, new import_decimal.default(0)));
747
463
  }
748
464
  }
749
- for (let bundleItem of item?.bundle || []) {
465
+ for (let bundleItem of (item == null ? void 0 : item.bundle) || []) {
750
466
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
751
- // IMPORTANT: 套餐子商品如果应用了 discount,bundle_selling_price 和 price 其实都已经是折后价格了,不需要单独再减一次
752
- const bundleItemTotal = new _decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
467
+ const bundleItemTotal = new import_decimal.default(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0);
753
468
  total = total.add(bundleItemTotal);
754
469
  }
755
470
  }
756
471
  return total.toNumber();
757
472
  };
758
- /**
759
- * 判断商品是否符合附加费条件
760
- */
761
- const isProductMatchSurchargeCondition = (item, options) => {
762
- const isInScheduleByDate = options?.isInScheduleByDate;
763
- const {
764
- surchargeConfig,
765
- scheduleById = {}
766
- } = options;
767
- const {
768
- startDate,
769
- product_id,
770
- isCustomItem
771
- } = item;
473
+ var isProductMatchSurchargeCondition = (item, options) => {
474
+ const isInScheduleByDate = options == null ? void 0 : options.isInScheduleByDate;
475
+ const { surchargeConfig, scheduleById = {} } = options;
476
+ const { startDate, product_id, isCustomItem } = item;
772
477
  const {
773
478
  open_product = 0,
774
479
  // 1 | 0
@@ -782,50 +487,35 @@ const isProductMatchSurchargeCondition = (item, options) => {
782
487
  // custom | all(所有日程)
783
488
  available_schedule_ids = []
784
489
  } = surchargeConfig;
785
-
786
- // 判断商品是否符合条件
787
490
  let isProductMatch = false;
788
491
  if (open_product === 0) {
789
- // 未开启商品限制,所有商品都符合
790
492
  isProductMatch = true;
791
493
  } else {
792
- // 开启了商品限制
793
494
  if (is_all === 1) {
794
- // 所有商品都收取附加费
795
495
  isProductMatch = true;
796
496
  } else {
797
- // 指定商品收取附加费
798
497
  if (isCustomItem) {
799
- // 自定义商品:如果是指定商品模式,自定义商品不符合条件
800
- // 因为自定义商品没有 product_id,无法匹配到指定商品列表
801
498
  isProductMatch = false;
802
499
  } else {
803
- // 普通商品:检查是否在指定商品列表中
804
500
  isProductMatch = available_product_ids.includes(product_id);
805
501
  }
806
502
  }
807
503
  }
808
-
809
- // 判断日程是否符合条件
810
504
  let isScheduleMatch = false;
811
505
  if (open_schedule === 0) {
812
- // 未开启日程限制,所有日程都符合
813
506
  isScheduleMatch = true;
814
507
  } else {
815
- // 开启了日程限制
816
- if (schedule_type === 'all') {
817
- // 所有日程都收取附加费
508
+ if (schedule_type === "all") {
818
509
  isScheduleMatch = true;
819
510
  } else {
820
- // 指定日程收取附加费
821
511
  for (let j = 0; j < available_schedule_ids.length; j++) {
822
512
  const scheduleId = available_schedule_ids[j];
823
513
  const schedule = scheduleById[scheduleId];
824
514
  if (schedule) {
825
515
  const isInSchedule = isInScheduleByDate({
826
516
  // date: startDate?.format('YYYY-MM-DD HH:mm:ss') || '',
827
- date: startDate || '',
828
- schedule: schedule
517
+ date: startDate || "",
518
+ schedule
829
519
  });
830
520
  if (isInSchedule) {
831
521
  isScheduleMatch = true;
@@ -835,264 +525,195 @@ const isProductMatchSurchargeCondition = (item, options) => {
835
525
  }
836
526
  }
837
527
  }
838
-
839
- // 商品和日程条件都要满足(取交集)
840
528
  return isProductMatch && isScheduleMatch;
841
529
  };
842
-
843
- /**
844
- * 订单附加费各项信息
845
- *
846
- * - **详情未编辑**(`!options.isEdit && bookingId`)时:直接返回 `bookingDetail.surcharge`(后端计算结果)
847
- * - **新增/编辑**时:按 `options.surcharge_list` 逐条配置计算本次订单的附加费
848
- *
849
- * 规则要点:
850
- * - 匹配范围包含:主商品(`service`)、原价 bundle 子商品(`item.bundle`)、加时商品(`item.relation_details`)、以及 addons(`addons.value`)
851
- * - 固定附加费 `fixed`:只加一次,再按商品数量分摊(向下取整保留两位),剩余小数会以 `surcharge_rounding_remainder` 形式抹平到最后一个商品
852
- * - 百分比附加费 `percentage`:按每个商品(价格 * 数量)分别计算再累加
853
- * - 当 `open_product === 0`:不回写到商品,只在订单级别累加;否则会把单品附加费回写到商品
854
- *
855
- * **副作用(可能修改入参商品对象)**:
856
- * - 当 `open_product !== 0` 时:写入 `item.surcharge_fee`(单品单数量附加费,保留两位、向下取整)
857
- * - 写入 `item.relation_surcharge_ids`(关联到的 surcharge 配置 id 列表)
858
- * - 写入 `item.surcharge_rounding_remainder`(用于抹平固定附加费/总额舍入差)
859
- *
860
- * @param params 入参集合(RORO)
861
- * @param params.service 服务商品数组(主商品)。元素可能包含 `bundle` / `relation_details`
862
- * @param params.addons 附加商品容器。当前实现读取 `addons.value` 作为商品数组(所以通常传 `{ value: CartItem[] }`)
863
- * @param params.bookingDetail 订单详情(详情未编辑时用于直接取后端的 surcharge 列表),可选
864
- * @param params.bookingId 订单/预约 ID(详情未编辑时生效),可选
865
- * @param options 计算选项
866
- * @param options.isEdit 是否处于“编辑中”。`false` 且存在 `bookingId` 时会走详情直取逻辑
867
- * @param options.surcharge_list 附加费配置列表(后端下发)。缺失/为空则返回空数组
868
- * @param options.isInScheduleByDate 判断日期是否落在某个 schedule 内的方法(通常来自 ScheduleModule)
869
- * @param options.scheduleById schedule 映射表:`{ [scheduleId]: schedule }`(用于根据配置的 `available_schedule_ids` 做日程匹配)
870
- * @returns 附加费列表(仅返回金额 > 0 的项)
871
- */
872
- const getSurcharge = ({
873
- service,
874
- addons,
875
- bookingDetail,
876
- bookingId
877
- }, options) => {
878
- const {
879
- isEdit,
880
- isInScheduleByDate,
881
- surcharge_list,
882
- scheduleById
883
- } = options;
884
- // 在所有商品里试着找 start_date,如果没有则用当前时间
885
- const firstAppointmentCartItem = service.filter(n => !(0, _utils.isNormalProduct)(n._productOrigin))?.[0];
886
- let startDate = '';
530
+ var getSurcharge = ({ service, addons, bookingDetail, bookingId }, options) => {
531
+ var _a, _b, _c, _d;
532
+ const { isEdit, isInScheduleByDate, surcharge_list, scheduleById } = options;
533
+ const firstAppointmentCartItem = (_a = service.filter(
534
+ (n) => !(0, import_utils.isNormalProduct)(n._productOrigin)
535
+ )) == null ? void 0 : _a[0];
536
+ let startDate = "";
887
537
  if (firstAppointmentCartItem) {
888
- startDate = firstAppointmentCartItem.start_date + ' ' + firstAppointmentCartItem.start_time + ':00';
538
+ startDate = firstAppointmentCartItem.start_date + " " + firstAppointmentCartItem.start_time + ":00";
889
539
  } else {
890
- startDate = (0, _dayjs.default)().format('YYYY-MM-DD HH:mm:ss');
540
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
891
541
  }
892
- // 编辑状态, 且未修改商品时直接从详情取出
893
542
  if (!isEdit && bookingId) {
894
- if (Array.isArray(bookingDetail?.surcharge)) {
895
- return (bookingDetail?.surcharge || []).filter(d => Number(d.amount) > 0).map((d, index) => {
896
- return {
897
- key: `custom_surcharge_${index}`,
898
- // label:
899
- // d.name[state.locale || 'en'] ||
900
- // d.name['en'] ||
901
- // d.name['original'],
902
- label: d.name,
903
- value: d.amount,
904
- name: d.name,
905
- surcharge_id: d.id,
906
- description: d.description,
907
- // 后端说这个固定传 default
908
- type: 'default',
909
- fixed: d.fixed,
910
- amount: d.amount,
911
- percentage: d.percentage
912
- };
913
- });
543
+ if (Array.isArray(bookingDetail == null ? void 0 : bookingDetail.surcharge)) {
544
+ return ((bookingDetail == null ? void 0 : bookingDetail.surcharge) || []).filter((d) => Number(d.amount) > 0).map(
545
+ (d, index) => {
546
+ return {
547
+ key: `custom_surcharge_${index}`,
548
+ // label:
549
+ // d.name[state.locale || 'en'] ||
550
+ // d.name['en'] ||
551
+ // d.name['original'],
552
+ label: d.name,
553
+ value: d.amount,
554
+ name: d.name,
555
+ surcharge_id: d.id,
556
+ description: d.description,
557
+ // 后端说这个固定传 default
558
+ type: "default",
559
+ fixed: d.fixed,
560
+ amount: d.amount,
561
+ percentage: d.percentage
562
+ };
563
+ }
564
+ );
914
565
  }
915
566
  return [];
916
567
  }
917
-
918
- // 用于“计算总价”的场景:每次调用都应重新计算(避免重复调用导致 surcharge_fee 累加)
919
- // 注意:同一次调用内仍会在多条 surcharge 配置之间累加
920
- resetItemsSurchargeSideEffects({
921
- service,
922
- addons
923
- });
924
-
925
- // 无附加费规则
926
- if (!Array.isArray(surcharge_list) || !surcharge_list?.length) return [];
927
-
928
- // 分别计算每种附加费总和
568
+ resetItemsSurchargeSideEffects({ service, addons });
569
+ if (!Array.isArray(surcharge_list) || !(surcharge_list == null ? void 0 : surcharge_list.length))
570
+ return [];
929
571
  const surchargeWithAmount = [];
930
-
931
- // 遍历每种附加费配置
932
572
  for (let i = 0; i < surcharge_list.length; i++) {
933
573
  const surchargeConfig = surcharge_list[i];
934
574
  const {
935
- percentage = '0',
936
- fixed = '0',
575
+ percentage = "0",
576
+ fixed = "0",
937
577
  id,
938
578
  type,
939
579
  description,
940
580
  open_product
941
581
  } = surchargeConfig;
942
-
943
- // 收集所有符合条件的商品
944
582
  const matchedItems = [];
945
-
946
- // 检查service中符合条件的商品
947
583
  if (Array.isArray(service)) {
948
584
  for (let item of service) {
949
- // 主商品符合附加费条件
950
- if (isProductMatchSurchargeCondition({
951
- isCustomItem: item.isCustomItem,
952
- startDate,
953
- product_id: item.id
954
- }, {
955
- surchargeConfig,
956
- scheduleById: scheduleById || {},
957
- isInScheduleByDate: isInScheduleByDate
958
- })) {
959
- // 主商品加价减价后的总价
585
+ if (isProductMatchSurchargeCondition(
586
+ {
587
+ isCustomItem: item.isCustomItem,
588
+ startDate,
589
+ product_id: item.id
590
+ },
591
+ {
592
+ surchargeConfig,
593
+ scheduleById: scheduleById || {},
594
+ isInScheduleByDate
595
+ }
596
+ )) {
960
597
  const total = getMainProductTotal({
961
598
  ...item,
962
- option: item?.option || item?.options || [],
963
- bundle: item?.bundle || item?.bundles || []
599
+ option: (item == null ? void 0 : item.option) || (item == null ? void 0 : item.options) || [],
600
+ bundle: (item == null ? void 0 : item.bundle) || (item == null ? void 0 : item.bundles) || []
964
601
  });
965
602
  const mainQuantity = item.num || 1;
966
603
  matchedItems.push({
967
- total: total,
604
+ total,
968
605
  // addTimeTotal: getRelationDetailsTotal(
969
606
  // item._extend.relation_details || []
970
607
  // ),
971
608
  isMain: true,
972
609
  quantity: mainQuantity,
973
610
  item,
974
- mainQuantity: mainQuantity // 主商品的mainQuantity等于自己的quantity
611
+ mainQuantity
612
+ // 主商品的mainQuantity等于自己的quantity
975
613
  });
976
614
  }
977
- const arr = item?.bundle || item?.bundles || [];
978
- // 遍历子商品 原价商品符合附加费条件
615
+ const arr = (item == null ? void 0 : item.bundle) || (item == null ? void 0 : item.bundles) || [];
979
616
  for (let bundleItem of arr) {
980
- // bundle商品是原价且符合附加费条件
981
- if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition({
982
- isCustomItem: false,
983
- startDate,
984
- product_id: bundleItem._bundle_product_id
985
- }, {
986
- surchargeConfig,
987
- scheduleById: scheduleById || {},
988
- isInScheduleByDate: isInScheduleByDate
989
- })) {
617
+ if (getBundleItemIsOriginalPrice(bundleItem) && isProductMatchSurchargeCondition(
618
+ {
619
+ isCustomItem: false,
620
+ startDate,
621
+ product_id: bundleItem._bundle_product_id
622
+ },
623
+ {
624
+ surchargeConfig,
625
+ scheduleById: scheduleById || {},
626
+ isInScheduleByDate
627
+ }
628
+ )) {
990
629
  const mainQuantity = item.num || 1;
991
630
  matchedItems.push({
992
631
  isMain: false,
993
- total: Number(bundleItem.bundle_selling_price ?? bundleItem.price ?? 0),
632
+ total: Number(
633
+ bundleItem.bundle_selling_price ?? bundleItem.price ?? 0
634
+ ),
994
635
  quantity: bundleItem.num || bundleItem.quantity || 1,
995
636
  item: bundleItem,
996
- mainQuantity: mainQuantity // 子商品的mainQuantity是所属主商品的quantity
637
+ mainQuantity
638
+ // 子商品的mainQuantity是所属主商品的quantity
997
639
  });
998
640
  }
999
641
  }
1000
-
1001
- // 加时商品符合附加费条件
1002
642
  for (let relationDetail of item.relation_details || []) {
1003
- if (isProductMatchSurchargeCondition({
1004
- isCustomItem: false,
1005
- startDate,
1006
- product_id: relationDetail.product_id
1007
- }, {
1008
- surchargeConfig,
1009
- scheduleById: scheduleById || {},
1010
- isInScheduleByDate: isInScheduleByDate
1011
- })) {
643
+ if (isProductMatchSurchargeCondition(
644
+ {
645
+ isCustomItem: false,
646
+ startDate,
647
+ product_id: relationDetail.product_id
648
+ },
649
+ {
650
+ surchargeConfig,
651
+ scheduleById: scheduleById || {},
652
+ isInScheduleByDate
653
+ }
654
+ )) {
1012
655
  matchedItems.push({
1013
656
  isMain: false,
1014
- total: Number(relationDetail?.price || relationDetail?.metadata?.main_product_attached_bundle_selling_price),
657
+ total: Number(
658
+ (relationDetail == null ? void 0 : relationDetail.price) || ((_b = relationDetail == null ? void 0 : relationDetail.metadata) == null ? void 0 : _b.main_product_attached_bundle_selling_price)
659
+ ),
1015
660
  quantity: relationDetail.num || relationDetail.quantity || 1,
1016
661
  item: relationDetail,
1017
- mainQuantity: 1 // 加时商品不受主商品数量影响
662
+ mainQuantity: 1
663
+ // 加时商品不受主商品数量影响
1018
664
  });
1019
665
  }
1020
666
  }
1021
667
  }
1022
668
  }
1023
-
1024
- // 检查addons中符合条件的商品
1025
- if (Array.isArray(addons?.value)) {
669
+ if (Array.isArray(addons == null ? void 0 : addons.value)) {
1026
670
  for (let item of addons.value) {
1027
- if (isProductMatchSurchargeCondition({
1028
- ...item,
1029
- startDate
1030
- }, {
671
+ if (isProductMatchSurchargeCondition({ ...item, startDate }, {
1031
672
  surchargeConfig,
1032
673
  scheduleById: scheduleById || {},
1033
- isInScheduleByDate: isInScheduleByDate
674
+ isInScheduleByDate
1034
675
  })) {
1035
676
  matchedItems.push({
1036
677
  isMain: true,
1037
678
  total: Number(item.total),
1038
679
  quantity: item.num || 1,
1039
- item: item,
1040
- mainQuantity: 1 // addons独立商品,mainQuantity为1
680
+ item,
681
+ mainQuantity: 1
682
+ // addons独立商品,mainQuantity为1
1041
683
  });
1042
684
  }
1043
685
  }
1044
686
  }
1045
687
  let finalAmount = 0;
1046
-
1047
- // 计算商品总数:主商品和addons按quantity计算,子商品(bundle item)需要乘以主商品数量
1048
688
  const productCount = matchedItems.reduce((total, item) => {
1049
689
  if (item.isMain) {
1050
- // 主商品和addons商品
1051
690
  return total + (item.num || item.quantity || 1);
1052
691
  } else {
1053
- // 子商品(bundle item)和加时商品
1054
- // 加时商品的 mainQuantity = 1,所以不受影响
1055
- // bundle item 的 mainQuantity = 主商品数量,需要乘以实际数量
1056
692
  return total + (item.num || item.quantity || 1) * (item.mainQuantity || 1);
1057
693
  }
1058
694
  }, 0);
1059
-
1060
- // 追加进入的固定附加费总值
1061
- let fixedTotal = new _decimal.default(0);
1062
- // 追加到商品的附加费总值 用于追加抹平字段
1063
- let productTotalSurcharge = new _decimal.default(0);
695
+ let fixedTotal = new import_decimal.default(0);
696
+ let productTotalSurcharge = new import_decimal.default(0);
1064
697
  if (matchedItems.length > 0) {
1065
- // 基于每个商品计算附加费:max(0, 商品价格) * rate + fixed
1066
- let configTotal = new _decimal.default(0);
1067
-
1068
- // 计算固定附加费 - 只加一次
1069
- if (fixed && new _decimal.default(fixed).gt(0)) {
698
+ let configTotal = new import_decimal.default(0);
699
+ if (fixed && new import_decimal.default(fixed).gt(0)) {
1070
700
  configTotal = configTotal.plus(fixed);
1071
701
  }
1072
-
1073
- // 计算百分比附加费 - 对每个商品单独计算
1074
- if (percentage && new _decimal.default(percentage).gt(0) || fixed) {
1075
- const percentageRate = new _decimal.default(percentage);
702
+ if (percentage && new import_decimal.default(percentage).gt(0) || fixed) {
703
+ const percentageRate = new import_decimal.default(percentage);
1076
704
  for (let [index, item] of matchedItems.entries()) {
1077
705
  const isLast = index === matchedItems.length - 1;
1078
- // 对每个商品:max(0, 价格) * 数量 * 费率
1079
- const itemPrice = new _decimal.default(Math.max(0, item.total || 0));
1080
- const itemQuantity = new _decimal.default(item.isMain ? item.quantity || 1 : item.quantity * item.mainQuantity || 1);
1081
- const addTimeTotal = new _decimal.default(item.addTimeTotal || 0);
1082
- // 单个商品总附加费
706
+ const itemPrice = new import_decimal.default(Math.max(0, item.total || 0));
707
+ const itemQuantity = new import_decimal.default(item.isMain ? item.quantity || 1 : item.quantity * item.mainQuantity || 1);
708
+ const addTimeTotal = new import_decimal.default(item.addTimeTotal || 0);
1083
709
  const itemTotalSurcharge = itemPrice.times(itemQuantity).plus(addTimeTotal).times(percentageRate);
1084
710
  configTotal = configTotal.plus(itemTotalSurcharge);
1085
-
1086
- // 单个商品单数量附加费
1087
711
  const itemSurcharge = itemPrice.times(percentageRate);
1088
-
1089
- // 固定附加费 = 1 / 商品数量 * 固定附加费(向下取整保留两位小数)
1090
- const fixedSurcharge = new _decimal.default(1).div(productCount).times(fixed).times(100).floor().div(100).toFixed(2);
712
+ const fixedSurcharge = new import_decimal.default(1).div(productCount).times(fixed).times(100).floor().div(100).toFixed(2);
1091
713
  const quantity = item.isMain ? item.quantity : item.quantity * item.mainQuantity;
1092
- fixedTotal = fixedTotal.plus(new _decimal.default(fixedSurcharge).times(quantity).toNumber());
1093
- // 如果是最后一个商品 判断fixed - fixedTotal 是否有剩余小数 如果有的话,追加抹平字段
714
+ fixedTotal = fixedTotal.plus(new import_decimal.default(fixedSurcharge).times(quantity).toNumber());
1094
715
  if (isLast && fixedTotal.gt(0)) {
1095
- const remaining = new _decimal.default(fixed).minus(fixedTotal).toNumber();
716
+ const remaining = new import_decimal.default(fixed).minus(fixedTotal).toNumber();
1096
717
  if (remaining > 0) {
1097
718
  productTotalSurcharge = productTotalSurcharge.plus(remaining);
1098
719
  if (item.isMain) {
@@ -1102,44 +723,36 @@ const getSurcharge = ({
1102
723
  }
1103
724
  }
1104
725
  }
1105
- // 只有当 open_product !== 0 时,才将附加费追加到商品身上
1106
- // open_product === 0 表示商品未开启该附加费,只在订单级别累加
1107
726
  if (open_product !== 0) {
1108
727
  if (item.isMain) {
1109
- const originSurchargeFee = new _decimal.default(item.item.surcharge_fee || 0);
1110
- // 保留两位小数
1111
- const surchargeFee = originSurchargeFee.plus(itemSurcharge).plus(fixedSurcharge).toDecimalPlaces(2, _decimal.default.ROUND_DOWN).toNumber();
1112
- productTotalSurcharge = productTotalSurcharge.plus(new _decimal.default(surchargeFee).times(itemQuantity).toNumber());
728
+ const originSurchargeFee = new import_decimal.default(item.item.surcharge_fee || 0);
729
+ const surchargeFee = originSurchargeFee.plus(itemSurcharge).plus(fixedSurcharge).toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
730
+ productTotalSurcharge = productTotalSurcharge.plus(new import_decimal.default(surchargeFee).times(itemQuantity).toNumber());
1113
731
  item.item.surcharge_fee = surchargeFee;
1114
- item.item.relation_surcharge_ids = [...(item.item?.relation_surcharge_ids || []), id];
732
+ item.item.relation_surcharge_ids = [...((_c = item.item) == null ? void 0 : _c.relation_surcharge_ids) || [], id];
1115
733
  } else {
1116
- const originSurchargeFee = new _decimal.default(item.item.surcharge_fee || 0);
1117
- // 保留两位小数
1118
- const surchargeFee = originSurchargeFee.plus(itemSurcharge).plus(fixedSurcharge).toDecimalPlaces(2, _decimal.default.ROUND_DOWN).toNumber();
1119
- productTotalSurcharge = productTotalSurcharge.plus(new _decimal.default(surchargeFee).times(itemQuantity).toNumber());
734
+ const originSurchargeFee = new import_decimal.default(item.item.surcharge_fee || 0);
735
+ const surchargeFee = originSurchargeFee.plus(itemSurcharge).plus(fixedSurcharge).toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
736
+ productTotalSurcharge = productTotalSurcharge.plus(new import_decimal.default(surchargeFee).times(itemQuantity).toNumber());
1120
737
  item.item.surcharge_fee = surchargeFee;
1121
- item.item.relation_surcharge_ids = [...(item.item?.relation_surcharge_ids || []), id];
738
+ item.item.relation_surcharge_ids = [...((_d = item.item) == null ? void 0 : _d.relation_surcharge_ids) || [], id];
1122
739
  }
1123
740
  }
1124
- // 最后一个商品 判断configTotal - productTotalSurcharge 是否有剩余小数 如果有的话,追加抹平字段
1125
741
  if (isLast && configTotal.minus(productTotalSurcharge).gt(0)) {
1126
- // 四舍五入configTotal
1127
- const configTotalRounded = configTotal.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP);
742
+ const configTotalRounded = configTotal.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP);
1128
743
  if (item.isMain) {
1129
- let newRoundingRemainder = new _decimal.default(item.item.surcharge_rounding_remainder || 0);
744
+ let newRoundingRemainder = new import_decimal.default(item.item.surcharge_rounding_remainder || 0);
1130
745
  newRoundingRemainder = newRoundingRemainder.plus(configTotalRounded.minus(productTotalSurcharge));
1131
746
  item.item.surcharge_rounding_remainder = newRoundingRemainder.toNumber();
1132
747
  } else {
1133
- let newRoundingRemainder = new _decimal.default(item.item.surcharge_rounding_remainder || 0);
748
+ let newRoundingRemainder = new import_decimal.default(item.item.surcharge_rounding_remainder || 0);
1134
749
  newRoundingRemainder = newRoundingRemainder.plus(configTotalRounded.minus(productTotalSurcharge));
1135
750
  item.item.surcharge_rounding_remainder = newRoundingRemainder.toNumber();
1136
751
  }
1137
752
  }
1138
753
  }
1139
754
  }
1140
-
1141
- // 如果该配置有金额,则添加到结果中
1142
- finalAmount = configTotal.toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
755
+ finalAmount = configTotal.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1143
756
  }
1144
757
  const name = surchargeConfig.name || {};
1145
758
  if (Number(finalAmount) <= 0) {
@@ -1154,7 +767,7 @@ const getSurcharge = ({
1154
767
  surcharge_id: id,
1155
768
  description,
1156
769
  // 后端说固定传 default
1157
- type: 'default',
770
+ type: "default",
1158
771
  fixed,
1159
772
  amount: finalAmount,
1160
773
  percentage,
@@ -1165,13 +778,10 @@ const getSurcharge = ({
1165
778
  }
1166
779
  return surchargeWithAmount;
1167
780
  };
1168
- exports.getSurcharge = getSurcharge;
1169
- function resetItemsSurchargeSideEffects({
1170
- service,
1171
- addons
1172
- }) {
1173
- const resetItem = item => {
1174
- if (!item) return;
781
+ function resetItemsSurchargeSideEffects({ service, addons }) {
782
+ const resetItem = (item) => {
783
+ if (!item)
784
+ return;
1175
785
  item.surcharge_fee = 0;
1176
786
  item.surcharge_rounding_remainder = 0;
1177
787
  item.relation_surcharge_ids = [];
@@ -1179,12 +789,29 @@ function resetItemsSurchargeSideEffects({
1179
789
  if (Array.isArray(service)) {
1180
790
  for (let item of service) {
1181
791
  resetItem(item);
1182
- const arr = item?.bundle || item?.bundles || [];
1183
- for (let bundleItem of arr) resetItem(bundleItem);
1184
- for (let relationDetail of item?.relation_details || []) resetItem(relationDetail);
792
+ const arr = (item == null ? void 0 : item.bundle) || (item == null ? void 0 : item.bundles) || [];
793
+ for (let bundleItem of arr)
794
+ resetItem(bundleItem);
795
+ for (let relationDetail of (item == null ? void 0 : item.relation_details) || [])
796
+ resetItem(relationDetail);
1185
797
  }
1186
798
  }
1187
- if (Array.isArray(addons?.value)) {
1188
- for (let item of addons.value) resetItem(item);
799
+ if (Array.isArray(addons == null ? void 0 : addons.value)) {
800
+ for (let item of addons.value)
801
+ resetItem(item);
1189
802
  }
1190
- }
803
+ }
804
+ // Annotate the CommonJS export names for ESM import in node:
805
+ 0 && (module.exports = {
806
+ calcDiscountListDifference,
807
+ calculateDeposit,
808
+ calculateOriginSubtotal,
809
+ calculatePriceDetails,
810
+ calculateSubtotal,
811
+ calculateTaxFee,
812
+ getBundleDiscountList,
813
+ getProductDiscountProductDiscountDifference,
814
+ getSurcharge,
815
+ getSurchargeAmount,
816
+ getTax
817
+ });