@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,97 +1,88 @@
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/solution/ShopDiscount/utils.ts
30
+ var utils_exports = {};
31
+ __export(utils_exports, {
32
+ calculateOrderLevelDiscountAllocation: () => calculateOrderLevelDiscountAllocation,
33
+ filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
34
+ getDateIsInSchedule: () => getDateIsInSchedule,
35
+ getDiscountAmount: () => getDiscountAmount,
36
+ getDiscountListAmount: () => getDiscountListAmount,
37
+ getDiscountListAmountTotal: () => getDiscountListAmountTotal,
38
+ isAllNormalProduct: () => isAllNormalProduct,
39
+ isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
40
+ isOrderLevelFixedAmountDiscount: () => isOrderLevelFixedAmountDiscount,
41
+ uniqueById: () => uniqueById
5
42
  });
6
- exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
7
- var _decimal = _interopRequireDefault(require("decimal.js"));
8
- var _dayjs = _interopRequireDefault(require("dayjs"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const uniqueById = (arr, key = 'id') => {
11
- const seen = new Set();
12
- return arr.filter(item => !seen.has(item[key]) && seen.add(item[key]));
43
+ module.exports = __toCommonJS(utils_exports);
44
+ var import_decimal = __toESM(require("decimal.js"));
45
+ var import_dayjs = __toESM(require("dayjs"));
46
+ var uniqueById = (arr, key = "id") => {
47
+ const seen = /* @__PURE__ */ new Set();
48
+ return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
13
49
  };
14
-
15
- // 非预约商品 通过时长和日程判断是否是普通商品
16
- exports.uniqueById = uniqueById;
17
- const isNormalProductByDurationSchedule = item => {
18
- return !item?.duration && !item?.schedules?.length && !item?.['schedule.ids']?.length;
50
+ var isNormalProductByDurationSchedule = (item) => {
51
+ var _a, _b;
52
+ return !(item == null ? void 0 : item.duration) && !((_a = item == null ? void 0 : item.schedules) == null ? void 0 : _a.length) && !((_b = item == null ? void 0 : item["schedule.ids"]) == null ? void 0 : _b.length);
19
53
  };
20
-
21
- // 是否全部是普通商品
22
- exports.isNormalProductByDurationSchedule = isNormalProductByDurationSchedule;
23
- const isAllNormalProduct = items => {
24
- return items.every(item => isNormalProductByDurationSchedule(item));
54
+ var isAllNormalProduct = (items) => {
55
+ return items.every((item) => isNormalProductByDurationSchedule(item));
25
56
  };
26
-
27
- /**
28
- * 获取折扣金额 基于折扣卡类型计算
29
- * 商品券:直接返回商品价格
30
- * 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
31
- * @param discount
32
- * @param total
33
- * @param price
34
- * @returns
35
- */
36
- /**
37
- * 获取折扣金额 基于折扣卡类型计算
38
- * 商品券:直接返回商品价格
39
- * 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
40
- * @param discount
41
- * @param total
42
- * @param price
43
- * @returns
44
- */
45
- exports.isAllNormalProduct = isAllNormalProduct;
46
- const getDiscountAmount = (discount, total, price) => {
47
- // 商品券
48
- if (discount.tag === 'good_pass') {
49
- return new _decimal.default(price).minus(new _decimal.default(price || 0)).toNumber();
57
+ var getDiscountAmount = (discount, total, price) => {
58
+ var _a;
59
+ if (discount.tag === "good_pass") {
60
+ return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
50
61
  }
51
-
52
- // 判断是否是固定金额
53
- const isFixedAmount = discount?.metadata?.discount_card_type === 'fixed_amount';
54
-
55
- // 固定金额 小于0时返回0
62
+ const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
56
63
  if (isFixedAmount) {
57
- return Math.max(new _decimal.default(price).minus(new _decimal.default((discount.amount ?? discount.par_value) || 0)).toNumber(), 0);
64
+ return Math.max(new import_decimal.default(price).minus(new import_decimal.default((discount.amount ?? discount.par_value) || 0)).toNumber(), 0);
58
65
  }
59
-
60
- // 百分比:根据折扣卡金额计算
61
- return new _decimal.default(100).minus(discount.par_value || 0).div(100).mul(new _decimal.default(price)).toNumber();
66
+ return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
62
67
  };
63
- exports.getDiscountAmount = getDiscountAmount;
64
- const getDiscountListAmountTotal = discount => {
68
+ var getDiscountListAmountTotal = (discount) => {
65
69
  return discount.reduce((acc, cur) => {
66
- return new _decimal.default(acc).plus(new _decimal.default(cur.num || 1).mul(new _decimal.default(cur.amount || 0))).toNumber();
67
- }, new _decimal.default(0));
70
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.num || 1).mul(new import_decimal.default(cur.amount || 0))).toNumber();
71
+ }, new import_decimal.default(0));
68
72
  };
69
-
70
- /**
71
- * 获取折扣金额 计算每个折扣的金额
72
- * @param discount
73
- * @returns
74
- */
75
- exports.getDiscountListAmountTotal = getDiscountListAmountTotal;
76
- const getDiscountListAmount = discount => {
73
+ var getDiscountListAmount = (discount) => {
77
74
  return discount.reduce((acc, cur) => {
78
- return new _decimal.default(acc).plus(new _decimal.default(cur.amount || 0)).toNumber();
79
- }, new _decimal.default(0));
75
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.amount || 0)).toNumber();
76
+ }, new import_decimal.default(0));
80
77
  };
81
-
82
- // 日程项接口定义
83
- exports.getDiscountListAmount = getDiscountListAmount;
84
- // 获取时间是否在日程范围内
85
- const getDateIsInSchedule = (dateTime, scheduleList) => {
78
+ var getDateIsInSchedule = (dateTime, scheduleList) => {
86
79
  if (!dateTime || !scheduleList || scheduleList.length === 0) {
87
80
  return false;
88
81
  }
89
- const targetDate = (0, _dayjs.default)(dateTime);
82
+ const targetDate = (0, import_dayjs.default)(dateTime);
90
83
  if (!targetDate.isValid()) {
91
84
  return false;
92
85
  }
93
-
94
- // 遍历所有日程项
95
86
  for (const schedule of scheduleList) {
96
87
  if (isTimeInScheduleItem(dateTime, schedule)) {
97
88
  return true;
@@ -99,422 +90,284 @@ const getDateIsInSchedule = (dateTime, scheduleList) => {
99
90
  }
100
91
  return false;
101
92
  };
102
-
103
- // 判断时间是否在单个日程项范围内
104
- exports.getDateIsInSchedule = getDateIsInSchedule;
105
- const isTimeInScheduleItem = (dateTime, schedule) => {
106
- const targetDate = (0, _dayjs.default)(dateTime);
107
- const targetDateString = dateTime.split(' ')[0]; // YYYY-MM-DD
108
- const targetTimeString = dateTime.split(' ')[1] || '00:00:00'; // HH:mm:ss
109
-
93
+ var isTimeInScheduleItem = (dateTime, schedule) => {
94
+ const targetDate = (0, import_dayjs.default)(dateTime);
95
+ const targetDateString = dateTime.split(" ")[0];
96
+ const targetTimeString = dateTime.split(" ")[1] || "00:00:00";
110
97
  switch (schedule.type) {
111
- case 'standard':
98
+ case "standard":
112
99
  return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
113
- case 'time-slots':
100
+ case "time-slots":
114
101
  return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
115
- case 'designation':
102
+ case "designation":
116
103
  return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
117
104
  default:
118
105
  return false;
119
106
  }
120
107
  };
121
-
122
- // 处理标准类型日程
123
- const isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
108
+ var isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
124
109
  if (!schedule.start_time || !schedule.end_time) {
125
110
  return false;
126
111
  }
127
- const startDate = (0, _dayjs.default)(schedule.start_time);
128
- const endDate = (0, _dayjs.default)(schedule.end_time);
129
-
130
- // 先检查是否在基础时间范围内(不考虑重复)
112
+ const startDate = (0, import_dayjs.default)(schedule.start_time);
113
+ const endDate = (0, import_dayjs.default)(schedule.end_time);
131
114
  const isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
132
- if (schedule.repeat_type === 'none') {
115
+ if (schedule.repeat_type === "none") {
133
116
  return isInBasicRange;
134
117
  }
135
-
136
- // 处理重复日程
137
118
  return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
138
119
  };
139
-
140
- // 处理时间段类型日程
141
- const isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
120
+ var isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
142
121
  if (!schedule.start_time) {
143
122
  return false;
144
123
  }
145
-
146
- // 如果不重复,使用原有逻辑
147
- if (schedule.repeat_type === 'none') {
148
- const scheduleDate = schedule.start_time.split(' ')[0];
149
-
150
- // 检查日期是否匹配
124
+ if (schedule.repeat_type === "none") {
125
+ const scheduleDate = schedule.start_time.split(" ")[0];
151
126
  if (targetDateString !== scheduleDate) {
152
127
  return false;
153
128
  }
154
-
155
- // 检查是否在任一时间段内
156
129
  return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
157
130
  }
158
-
159
- // 处理重复日程
160
131
  return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
161
132
  };
162
-
163
- // 处理指定类型日程
164
- const isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
133
+ var isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
165
134
  if (!schedule.designation) {
166
135
  return false;
167
136
  }
168
137
  for (const designation of schedule.designation) {
169
138
  const startDateTime = `${designation.start_date} ${designation.start_time}:00`;
170
139
  const endDateTime = `${designation.end_date} ${designation.end_time}:00`;
171
- const startDate = (0, _dayjs.default)(startDateTime);
172
- const endDate = (0, _dayjs.default)(endDateTime);
140
+ const startDate = (0, import_dayjs.default)(startDateTime);
141
+ const endDate = (0, import_dayjs.default)(endDateTime);
173
142
  if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
174
143
  return true;
175
144
  }
176
145
  }
177
146
  return false;
178
147
  };
179
-
180
- // 处理重复日程逻辑
181
- const isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
148
+ var isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
182
149
  if (!schedule.repeat_rule) {
183
150
  return false;
184
151
  }
185
- const {
186
- repeat_rule,
187
- repeat_type
188
- } = schedule;
189
- const targetDateOnly = (0, _dayjs.default)(targetDateString); // 只取日期部分
190
-
191
- // 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
152
+ const { repeat_rule, repeat_type } = schedule;
153
+ const targetDateOnly = (0, import_dayjs.default)(targetDateString);
192
154
  if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
193
155
  for (const includedDate of repeat_rule.included_date) {
194
- const includeStartDate = (0, _dayjs.default)(includedDate.start);
195
- const includeEndDate = (0, _dayjs.default)(includedDate.end);
196
- if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
197
- // 在包含日期中,直接返回true,无需检查其他条件
156
+ const includeStartDate = (0, import_dayjs.default)(includedDate.start);
157
+ const includeEndDate = (0, import_dayjs.default)(includedDate.end);
158
+ if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
198
159
  return true;
199
160
  }
200
161
  }
201
162
  }
202
-
203
- // 检查是否在排除日期中
204
163
  for (const excludedDate of repeat_rule.excluded_date) {
205
- const excludeStartDate = (0, _dayjs.default)(excludedDate.start);
206
- const excludeEndDate = (0, _dayjs.default)(excludedDate.end);
207
- // 检查目标日期是否在排除范围内(包含边界)
208
- if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
164
+ const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
165
+ const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
166
+ if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
209
167
  return false;
210
168
  }
211
169
  }
212
-
213
- // 检查重复规则的结束条件
214
- if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
215
- const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
170
+ if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
171
+ const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
216
172
  if (targetDate.isAfter(ruleEndDate)) {
217
173
  return false;
218
174
  }
219
175
  }
220
-
221
- // 根据重复类型检查
222
176
  switch (repeat_type) {
223
- case 'daily':
177
+ case "daily":
224
178
  return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
225
- case 'weekly':
179
+ case "weekly":
226
180
  return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
227
181
  default:
228
182
  return false;
229
- // 不支持月和年重复
230
183
  }
231
184
  };
232
-
233
- // 每日重复逻辑
234
- const isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
235
- const daysDiff = targetDate.diff(startDate, 'day');
185
+ var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
186
+ const daysDiff = targetDate.diff(startDate, "day");
236
187
  if (daysDiff < 0) {
237
188
  return false;
238
189
  }
239
-
240
- // 检查频率
241
190
  if (daysDiff % repeatRule.frequency !== 0) {
242
191
  return false;
243
192
  }
244
-
245
- // 检查时间是否在日程的时间范围内
246
193
  const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
247
194
  const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
248
195
  const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
249
-
250
- // 每日重复:每天都在相同的时间段内有效
251
- // 例如:01:00:00 - 16:00:00,每天都是这个时间段
252
196
  return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
253
197
  };
254
-
255
- // 每周重复逻辑
256
- const isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
257
- const targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
258
-
259
- // 检查是否在指定的星期几内
198
+ var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
199
+ const targetDayOfWeek = targetDate.day();
260
200
  if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
261
201
  return false;
262
202
  }
263
-
264
- // 计算周差
265
- const weeksDiff = targetDate.diff(startDate, 'week');
203
+ const weeksDiff = targetDate.diff(startDate, "week");
266
204
  if (weeksDiff < 0) {
267
205
  return false;
268
206
  }
269
-
270
- // 检查频率
271
207
  if (weeksDiff % repeatRule.frequency !== 0) {
272
208
  return false;
273
209
  }
274
-
275
- // 检查时间是否在日程的时间范围内
276
210
  const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
277
211
  const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
278
212
  const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
279
213
  return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
280
214
  };
281
-
282
- // 处理 time-slots 类型的重复日程
283
- const isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
215
+ var isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
284
216
  if (!schedule.repeat_rule || !schedule.start_time) {
285
217
  return false;
286
218
  }
287
- const {
288
- repeat_rule,
289
- repeat_type
290
- } = schedule;
291
- const startDate = (0, _dayjs.default)(schedule.start_time);
292
- const targetDateOnly = (0, _dayjs.default)(targetDateString);
293
-
294
- // 检查包含日期
219
+ const { repeat_rule, repeat_type } = schedule;
220
+ const startDate = (0, import_dayjs.default)(schedule.start_time);
221
+ const targetDateOnly = (0, import_dayjs.default)(targetDateString);
295
222
  if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
296
223
  for (const includedDate of repeat_rule.included_date) {
297
- const includeStartDate = (0, _dayjs.default)(includedDate.start);
298
- const includeEndDate = (0, _dayjs.default)(includedDate.end);
299
- if (targetDateOnly.isSameOrAfter(includeStartDate, 'day') && targetDateOnly.isSameOrBefore(includeEndDate, 'day')) {
300
- // 在包含日期中,检查时间段
224
+ const includeStartDate = (0, import_dayjs.default)(includedDate.start);
225
+ const includeEndDate = (0, import_dayjs.default)(includedDate.end);
226
+ if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
301
227
  return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
302
228
  }
303
229
  }
304
230
  }
305
-
306
- // 检查排除日期
307
231
  for (const excludedDate of repeat_rule.excluded_date) {
308
- const excludeStartDate = (0, _dayjs.default)(excludedDate.start);
309
- const excludeEndDate = (0, _dayjs.default)(excludedDate.end);
310
- if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
232
+ const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
233
+ const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
234
+ if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
311
235
  return false;
312
236
  }
313
237
  }
314
-
315
- // 检查重复规则的结束条件
316
- if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
317
- const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
318
- if (targetDateOnly.isAfter(ruleEndDate, 'day')) {
238
+ if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
239
+ const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
240
+ if (targetDateOnly.isAfter(ruleEndDate, "day")) {
319
241
  return false;
320
242
  }
321
243
  }
322
-
323
- // 检查目标日期是否在重复规则范围内
324
244
  let isDateValid = false;
325
245
  switch (repeat_type) {
326
- case 'daily':
246
+ case "daily":
327
247
  isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
328
248
  break;
329
- case 'weekly':
249
+ case "weekly":
330
250
  isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
331
251
  break;
332
252
  default:
333
253
  return false;
334
254
  }
335
-
336
- // 如果日期有效,检查时间段
337
255
  if (isDateValid) {
338
256
  return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
339
257
  }
340
258
  return false;
341
259
  };
342
-
343
- // 检查目标时间是否在某个时间段内(使用目标日期 + time_slot 时间)
344
- const checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
260
+ var checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
345
261
  for (const timeSlot of timeSlots) {
346
262
  const slotStart = `${targetDateString} ${timeSlot.start_time}:00`;
347
263
  const slotEnd = `${targetDateString} ${timeSlot.end_time}:00`;
348
- const slotStartDate = (0, _dayjs.default)(slotStart);
349
- const slotEndDate = (0, _dayjs.default)(slotEnd);
264
+ const slotStartDate = (0, import_dayjs.default)(slotStart);
265
+ const slotEndDate = (0, import_dayjs.default)(slotEnd);
350
266
  if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
351
267
  return true;
352
268
  }
353
269
  }
354
270
  return false;
355
271
  };
356
-
357
- // 检查日期是否满足每日重复规则(只检查日期,不检查时间)
358
- const isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
359
- const daysDiff = targetDate.diff(startDate, 'day');
272
+ var isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
273
+ const daysDiff = targetDate.diff(startDate, "day");
360
274
  if (daysDiff < 0) {
361
275
  return false;
362
276
  }
363
-
364
- // 检查频率
365
277
  return daysDiff % repeatRule.frequency === 0;
366
278
  };
367
-
368
- // 检查日期是否满足每周重复规则(只检查日期,不检查时间)
369
- const isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
370
- const targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
371
-
372
- // 检查是否在指定的星期几内
279
+ var isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
280
+ const targetDayOfWeek = targetDate.day();
373
281
  if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
374
282
  return false;
375
283
  }
376
-
377
- // 计算周差
378
- const weeksDiff = targetDate.diff(startDate, 'week');
284
+ const weeksDiff = targetDate.diff(startDate, "week");
379
285
  if (weeksDiff < 0) {
380
286
  return false;
381
287
  }
382
-
383
- // 检查频率
384
288
  return weeksDiff % repeatRule.frequency === 0;
385
289
  };
386
-
387
- /**
388
- * 根据预约时间过滤优惠券列表
389
- * @param discountList 优惠券列表
390
- * @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
391
- * @returns 过滤后的优惠券列表
392
- */
393
- const filterDiscountListByBookingTime = (discountList, bookingTime) => {
290
+ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
394
291
  if (!bookingTime) {
395
292
  return discountList;
396
293
  }
397
- return discountList.filter(discount => {
398
- if (discount?.metadata?.validity_type === "custom_schedule_validity") {
399
- return getDateIsInSchedule(bookingTime, discount.custom_schedule_snapshot?.data || []);
294
+ return discountList.filter((discount) => {
295
+ var _a, _b;
296
+ if (((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) === "custom_schedule_validity") {
297
+ return getDateIsInSchedule(bookingTime, ((_b = discount.custom_schedule_snapshot) == null ? void 0 : _b.data) || []);
400
298
  }
401
299
  try {
402
300
  const isHasStart = !!discount.start_date && !!discount.start_time;
403
- const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
404
- const bookingTimeDayjs = (0, _dayjs.default)(bookingTime);
405
-
406
- // 判断预约时间是否在开始时间之后
301
+ const startDate = (0, import_dayjs.default)(`${discount.start_date} ${discount.start_time}`);
302
+ const bookingTimeDayjs = (0, import_dayjs.default)(bookingTime);
407
303
  const isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
408
-
409
- // 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
410
- const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, _dayjs.default)(discount.expire_time)) : true;
304
+ const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, import_dayjs.default)(discount.expire_time)) : true;
411
305
  return isAfterStart && isBeforeExpire;
412
306
  } catch (error) {
413
307
  return true;
414
308
  }
415
309
  });
416
310
  };
417
- /**
418
- * 判断是否是订单级别的固定金额折扣卡
419
- * @param discount 折扣
420
- * @returns 是否是订单级别的固定金额折扣卡
421
- */
422
- exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
423
- const isOrderLevelFixedAmountDiscount = discount => {
424
- return discount.tag === 'product_discount_card' && discount?.metadata?.discount_card_type === 'fixed_amount' && discount?.metadata?.discount_calculation_mode === 'order_level';
311
+ var isOrderLevelFixedAmountDiscount = (discount) => {
312
+ var _a, _b;
313
+ return discount.tag === "product_discount_card" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.discount_calculation_mode) === "order_level";
425
314
  };
426
-
427
- /**
428
- * 计算订单级别固定金额折扣卡的分摊结果
429
- * @param discount 折扣卡
430
- * @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
431
- * @returns 分摊结果 Map<productId, { discountAmount, difference }>
432
- * 注意:
433
- * - discountAmount 是单价折扣金额(不是总折扣金额)
434
- * - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
435
- */
436
- exports.isOrderLevelFixedAmountDiscount = isOrderLevelFixedAmountDiscount;
437
- const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
438
- const result = new Map();
315
+ var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
316
+ const result = /* @__PURE__ */ new Map();
439
317
  if (applicableProducts.length === 0) {
440
318
  return result;
441
319
  }
442
-
443
- // 计算适用商品的总金额(数量 × 单价)
444
320
  const totalAmount = applicableProducts.reduce((acc, product) => {
445
- return new _decimal.default(acc).plus(new _decimal.default(product.amount).mul(product.quantity)).toNumber();
321
+ return new import_decimal.default(acc).plus(new import_decimal.default(product.amount).mul(product.quantity)).toNumber();
446
322
  }, 0);
447
323
  if (totalAmount <= 0) {
448
324
  return result;
449
325
  }
450
-
451
- // 固定减免金额
452
- const fixedAmount = new _decimal.default(discount.par_value || 0).toNumber();
453
-
454
- // 如果固定金额 >= 商品总金额,折扣最高为商品金额(免费)
326
+ const fixedAmount = new import_decimal.default(discount.par_value || 0).toNumber();
455
327
  const actualDiscountTotal = Math.min(fixedAmount, totalAmount);
456
-
457
- // 计算每个商品的单价折扣金额
458
- let allocatedTotal = new _decimal.default(0);
459
- applicableProducts.forEach(product => {
460
- // 🔥 分摊公式改为:(单价 / 适用商品总金额) × 固定金额
461
- // 这样只有一次取整,避免精度损失
462
- const rawDiscountPerItem = new _decimal.default(product.amount).div(totalAmount).mul(actualDiscountTotal);
463
-
464
- // 保留两位小数,向下取整(单价折扣)
465
- const discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, _decimal.default.ROUND_DOWN).toNumber();
328
+ let allocatedTotal = new import_decimal.default(0);
329
+ applicableProducts.forEach((product) => {
330
+ const rawDiscountPerItem = new import_decimal.default(product.amount).div(totalAmount).mul(actualDiscountTotal);
331
+ const discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
466
332
  result.set(product.productId, {
467
333
  discountAmount: discountAmountPerItem,
468
334
  // 单价折扣金额
469
- difference: 0 // 默认差值为0
335
+ difference: 0
336
+ // 默认差值为0
470
337
  });
471
-
472
- // 累加实际分配的总折扣金额(单价折扣 × 数量)
473
- allocatedTotal = allocatedTotal.plus(new _decimal.default(discountAmountPerItem).mul(product.quantity));
338
+ allocatedTotal = allocatedTotal.plus(
339
+ new import_decimal.default(discountAmountPerItem).mul(product.quantity)
340
+ );
474
341
  });
475
-
476
- // 🔥 计算总差值
477
- // 总差值 = 固定金额 - 所有商品的 (单价折扣 × 数量) 之和
478
- const totalDifference = new _decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
342
+ const totalDifference = new import_decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
479
343
  if (totalDifference > 0) {
480
- // 🔥 判断商品是否是真正的"数量为1"
481
- // 主商品:quantity === 1
482
- // 子商品:quantity === 1 且 parentQuantity === 1
483
- const isSingleQuantity = product => {
484
- if (product.parentQuantity !== undefined) {
485
- // 子商品:需要同时满足自身数量为1且主商品数量为1
344
+ const isSingleQuantity = (product) => {
345
+ if (product.parentQuantity !== void 0) {
486
346
  return product.quantity === 1 && product.parentQuantity === 1;
487
347
  }
488
- // 主商品:只需要自身数量为1
489
348
  return product.quantity === 1;
490
349
  };
491
-
492
- // 🔥 筛选出数量为1的商品
493
350
  const singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
494
351
  if (singleQuantityProducts.length > 0) {
495
- // 🔥 优先级1:找到有足够剩余空间且金额最大的商品
496
- // 剩余空间 = 商品价格 - 当前折扣金额 >= 差值
497
- const productsWithEnoughSpace = singleQuantityProducts.filter(product => {
352
+ const productsWithEnoughSpace = singleQuantityProducts.filter((product) => {
498
353
  const allocation = result.get(product.productId);
499
- if (!allocation) return false;
500
- const remainingSpace = new _decimal.default(product.amount).minus(allocation.discountAmount).toNumber();
354
+ if (!allocation)
355
+ return false;
356
+ const remainingSpace = new import_decimal.default(product.amount).minus(allocation.discountAmount).toNumber();
501
357
  return remainingSpace >= totalDifference;
502
358
  });
503
359
  if (productsWithEnoughSpace.length > 0) {
504
- // 按金额降序排序,选择金额最大的
505
360
  productsWithEnoughSpace.sort((a, b) => b.amount - a.amount);
506
361
  const targetProduct = productsWithEnoughSpace[0];
507
362
  const targetAllocation = result.get(targetProduct.productId);
508
363
  if (targetAllocation) {
509
- // 差值直接加到折扣金额上
510
364
  result.set(targetProduct.productId, {
511
- discountAmount: new _decimal.default(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
512
- difference: 0 // 不需要存储差值
365
+ discountAmount: new import_decimal.default(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
366
+ difference: 0
367
+ // 不需要存储差值
513
368
  });
514
369
  }
515
370
  } else {
516
- // 🔥 优先级2:所有数量为1的商品都没有足够剩余空间
517
- // 选择金额最大的商品,差值存储在metadata中
518
371
  singleQuantityProducts.sort((a, b) => b.amount - a.amount);
519
372
  const targetProduct = singleQuantityProducts[0];
520
373
  const targetAllocation = result.get(targetProduct.productId);
@@ -526,8 +379,6 @@ const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) =>
526
379
  }
527
380
  }
528
381
  } else {
529
- // 🔥 优先级3:没有数量为1的商品,走原有逻辑
530
- // 差值存储在最后一个商品的metadata中
531
382
  const lastProduct = applicableProducts[applicableProducts.length - 1];
532
383
  const lastProductAllocation = result.get(lastProduct.productId);
533
384
  if (lastProductAllocation) {
@@ -540,4 +391,16 @@ const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) =>
540
391
  }
541
392
  return result;
542
393
  };
543
- exports.calculateOrderLevelDiscountAllocation = calculateOrderLevelDiscountAllocation;
394
+ // Annotate the CommonJS export names for ESM import in node:
395
+ 0 && (module.exports = {
396
+ calculateOrderLevelDiscountAllocation,
397
+ filterDiscountListByBookingTime,
398
+ getDateIsInSchedule,
399
+ getDiscountAmount,
400
+ getDiscountListAmount,
401
+ getDiscountListAmountTotal,
402
+ isAllNormalProduct,
403
+ isNormalProductByDurationSchedule,
404
+ isOrderLevelFixedAmountDiscount,
405
+ uniqueById
406
+ });