@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,84 +1,115 @@
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/BookingByStep/index.ts
30
+ var BookingByStep_exports = {};
31
+ __export(BookingByStep_exports, {
32
+ BookingByStepImpl: () => BookingByStepImpl
5
33
  });
6
- exports.BookingByStepImpl = void 0;
7
- var _BaseModule = require("../../modules/BaseModule");
8
- var _types = require("./types");
9
- var _utils = require("../../modules/Cart/utils");
10
- var _products = require("./utils/products");
11
- var _resources = require("./utils/resources");
12
- var _dayjs = _interopRequireDefault(require("dayjs"));
13
- var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
14
- var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
15
- var _utils2 = require("../../modules/Resource/utils");
16
- var _lodashEs = require("lodash-es");
17
- var _utils3 = require("../../modules/Schedule/utils");
18
- var _utils4 = require("../../modules/Date/utils");
19
- var _utils5 = require("../../modules/Product/utils");
20
- var _timeslots = require("./utils/timeslots");
21
- var _changePrice = require("../../modules/Cart/utils/changePrice");
22
- var _capacity = require("./utils/capacity");
23
- var _stock = require("./utils/stock");
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
- _dayjs.default.extend(_isSameOrBefore.default);
26
- _dayjs.default.extend(_isSameOrAfter.default);
27
- class BookingByStepImpl extends _BaseModule.BaseModule {
28
- defaultName = 'bookingByStep';
29
- defaultVersion = '1.0.0';
30
- isSolution = true;
31
- request;
32
- window;
33
- shopStore;
34
- store;
35
- otherParams = {};
36
- cacheId;
37
- otherData = {}; // 提供给 UI 层的临时数据存储,会进缓存
38
- platform; // 平台类型,用于判断是 PC / H5
39
-
34
+ module.exports = __toCommonJS(BookingByStep_exports);
35
+ var import_BaseModule = require("../../modules/BaseModule");
36
+ var import_types = require("./types");
37
+ var import_utils = require("../../modules/Cart/utils");
38
+ var import_products = require("./utils/products");
39
+ var import_resources = require("./utils/resources");
40
+ var import_dayjs = __toESM(require("dayjs"));
41
+ var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
42
+ var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
43
+ var import_utils2 = require("../../modules/Resource/utils");
44
+ var import_lodash_es = require("lodash-es");
45
+ var import_utils3 = require("../../modules/Schedule/utils");
46
+ var import_utils4 = require("../../modules/Date/utils");
47
+ var import_utils5 = require("../../modules/Product/utils");
48
+ var import_timeslots = require("./utils/timeslots");
49
+ var import_changePrice = require("../../modules/Cart/utils/changePrice");
50
+ var import_capacity = require("./utils/capacity");
51
+ var import_stock = require("./utils/stock");
52
+ import_dayjs.default.extend(import_isSameOrBefore.default);
53
+ import_dayjs.default.extend(import_isSameOrAfter.default);
54
+ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
55
+ constructor() {
56
+ super(...arguments);
57
+ this.defaultName = "bookingByStep";
58
+ this.defaultVersion = "1.0.0";
59
+ this.isSolution = true;
60
+ this.otherParams = {};
61
+ this.otherData = {};
62
+ }
63
+ // 平台类型,用于判断是 PC / H5
40
64
  async initialize(core, options) {
65
+ var _a, _b, _c, _d, _e;
41
66
  this.core = core;
42
67
  this.store = options.store || {};
43
68
  this.otherParams = options.otherParams || {};
44
- // 获取依赖的插件
45
- this.request = core.getPlugin('request');
46
- this.window = core.getPlugin('window');
47
- this.shopStore = core.getPlugin('shopStore');
69
+ console.log("[BookingByStep] 初始化完成");
70
+ this.request = core.getPlugin("request");
71
+ this.window = core.getPlugin("window");
72
+ this.shopStore = core.getPlugin("shopStore");
48
73
  if (!this.request) {
49
- throw new Error('bookingByStep解决方案需要 request 插件支持');
74
+ throw new Error("bookingByStep解决方案需要 request 插件支持");
50
75
  }
51
76
  if (!this.shopStore) {
52
- throw new Error('SummaryModule 需要 shopStore 插件支持');
77
+ throw new Error("SummaryModule 需要 shopStore 插件支持");
53
78
  }
54
-
55
- // 如果有传 cacheid,默认需要收集上面这些模块里用户操作选中的数据
56
- // 并且在上面 registerModule 的时候,读取 sessionStroage 里的数据,塞进默认值
57
79
  let targetCacheData = {};
58
- this.cacheId = this.otherParams?.cacheId;
59
- this.platform = this.otherParams?.platform;
60
- if (this.otherParams?.cacheId) {
80
+ this.cacheId = (_a = this.otherParams) == null ? void 0 : _a.cacheId;
81
+ this.platform = (_b = this.otherParams) == null ? void 0 : _b.platform;
82
+ if ((_c = this.otherParams) == null ? void 0 : _c.cacheId) {
61
83
  const sessionData = this.window.sessionStorage.getItem(this.name);
62
84
  if (sessionData) {
63
85
  const data = JSON.parse(sessionData);
64
- // 匹配 cacheid,如果匹配不到,直接把 sessionData 清掉即可
65
- // 如果匹配到了,则把 sessionData 里的数据按模块塞到 store 里去
66
86
  targetCacheData = data[this.otherParams.cacheId];
67
- this.otherData = data[this.otherParams.cacheId]?.[this.name]?.['otherData'] || {};
87
+ this.otherData = ((_e = (_d = data[this.otherParams.cacheId]) == null ? void 0 : _d[this.name]) == null ? void 0 : _e["otherData"]) || {};
68
88
  }
69
89
  }
70
- const moduleArr = ['accountList', 'holder', 'cart', 'schedule', 'summary', 'step', 'products', 'date', 'order'];
71
- moduleArr.forEach(step => {
72
- const targetModule = (0, _types.createModule)(step, this.name);
90
+ const moduleArr = [
91
+ "accountList",
92
+ "holder",
93
+ "cart",
94
+ "schedule",
95
+ "summary",
96
+ "step",
97
+ "products",
98
+ "date",
99
+ "order"
100
+ ];
101
+ moduleArr.forEach((step) => {
102
+ var _a2, _b2;
103
+ const targetModule = (0, import_types.createModule)(step, this.name);
73
104
  if (targetModule) {
74
105
  this.store[step] = targetModule;
75
106
  this.core.registerModule(targetModule, {
76
- initialState: targetCacheData?.[targetModule.name],
107
+ initialState: targetCacheData == null ? void 0 : targetCacheData[targetModule.name],
77
108
  otherParams: {
78
109
  ...this.otherParams,
79
110
  fatherModule: this.name,
80
- openCache: this.otherParams?.cacheId ? true : false,
81
- cacheId: this.otherParams?.cacheId
111
+ openCache: ((_a2 = this.otherParams) == null ? void 0 : _a2.cacheId) ? true : false,
112
+ cacheId: (_b2 = this.otherParams) == null ? void 0 : _b2.cacheId
82
113
  }
83
114
  });
84
115
  } else {
@@ -98,7 +129,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
98
129
  step: this.store.step.getCurrentStep()
99
130
  };
100
131
  }
101
-
102
132
  // step: 下一个
103
133
  next() {
104
134
  this.store.step.nextStep();
@@ -107,38 +137,32 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
107
137
  back() {
108
138
  this.store.step.prevStep();
109
139
  }
110
-
111
140
  // 跳转到指定步骤
112
141
  gotoStep(index) {
113
142
  this.store.step.gotoStep(index);
114
143
  }
115
-
116
144
  // 获取所有step
117
145
  getStepList() {
118
146
  return this.store.step.getStepList();
119
147
  }
120
-
121
148
  /**
122
149
  * 添加step
123
150
  */
124
151
  addStep(step, key) {
125
152
  this.store.step.addStep(step, key);
126
153
  }
127
-
128
154
  /**
129
155
  * 删除step
130
156
  */
131
157
  removeStep(key) {
132
158
  this.store.step.removeStep(key);
133
159
  }
134
-
135
160
  /**
136
161
  * 更新step
137
162
  */
138
163
  updateStep(key, step) {
139
164
  this.store.step.updateStep(key, step);
140
165
  }
141
-
142
166
  /**
143
167
  *
144
168
  * 加载商品,然后导到商品列表里去
@@ -169,15 +193,13 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
169
193
  schedule_date,
170
194
  cacheId: this.cacheId
171
195
  });
172
- // 预拉取当天的资源数据
173
196
  this.getAvailableDate({
174
- startDate: schedule_date || (0, _dayjs.default)().format('YYYY-MM-DD'),
175
- endDate: schedule_date || (0, _dayjs.default)().format('YYYY-MM-DD'),
197
+ startDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
198
+ endDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
176
199
  products: [...res]
177
200
  });
178
201
  return res;
179
202
  }
180
-
181
203
  /**
182
204
  * 通过 schedule 来读取商品,适用于 session 类商品
183
205
  *
@@ -198,40 +220,21 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
198
220
  product_ids = [],
199
221
  category_ids = []
200
222
  }) {
223
+ var _a;
201
224
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
202
- // 缓存下这次选择的结果,如果是先选日期再选 duration 类商品,后面用得到
203
- this.setDateRange([{
204
- date,
205
- status: 'available',
206
- week: '',
207
- weekNum: 0
208
- }, {
209
- date,
210
- status: 'available',
211
- week: '',
212
- weekNum: 0
213
- }]);
225
+ this.setDateRange([
226
+ { date, status: "available", week: "", weekNum: 0 },
227
+ { date, status: "available", week: "", weekNum: 0 }
228
+ ]);
214
229
  let newProductIds = [];
215
- // const scheduleIds = scheduleList
216
- // .filter((n) => n.date === date)
217
- // .flatMap((n) => n.schedule_id)
218
- // .filter((n) => n !== null && n !== undefined);
219
-
220
- // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
221
- // if (!product_ids?.length) {
222
- // const schedule = scheduleList.find((n) => n.date === date);
223
- // if (schedule && schedule.product_ids?.length) {
224
- // product_ids = schedule.product_ids;
225
- // }
226
- // }
227
- // V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
228
- const schedule = scheduleList.find(n => n.date === date);
229
- if (schedule && schedule.product_ids?.length) {
230
+ const schedule = scheduleList.find((n) => n.date === date);
231
+ if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
230
232
  newProductIds = schedule.product_ids;
231
233
  }
232
- // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
233
234
  const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
234
- const allProductIds = [...newProductIds, ...otherProductsIds].filter((n, index, self) => self.indexOf(n) === index);
235
+ const allProductIds = [...newProductIds, ...otherProductsIds].filter(
236
+ (n, index, self) => self.indexOf(n) === index
237
+ );
235
238
  const res = await this.loadProducts({
236
239
  product_ids: allProductIds,
237
240
  category_ids,
@@ -239,7 +242,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
239
242
  });
240
243
  return res;
241
244
  }
242
-
243
245
  /**
244
246
  * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
245
247
  *
@@ -247,25 +249,34 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
247
249
  * @memberof BookingByStepImpl
248
250
  */
249
251
  async updateQuotationPriceAndCart(date) {
252
+ var _a;
250
253
  const cartItems = this.store.cart.getItems();
251
254
  if (cartItems.length) {
252
- let userPlugin = this.core.getPlugin('user');
253
- let customer_id = undefined;
255
+ let userPlugin = this.core.getPlugin("user");
256
+ let customer_id = void 0;
254
257
  try {
255
- customer_id = userPlugin?.get()?.id;
258
+ customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
256
259
  } catch (error) {
257
260
  console.error(error);
258
261
  }
259
262
  const res = await this.store.products.loadProductsPrice({
260
- ids: cartItems.map(n => n.id),
263
+ ids: cartItems.map((n) => n.id),
261
264
  schedule_date: date,
262
265
  customer_id
263
266
  });
264
- await (0, _changePrice.updateAllCartItemPrice)(cartItems, res, id => this.store.products.getProduct(id), params => this.store.cart.updateItem(params), params => this.store.cart.updateItemInitInfo(params));
265
- this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
267
+ await (0, import_changePrice.updateAllCartItemPrice)(
268
+ cartItems,
269
+ res,
270
+ (id) => this.store.products.getProduct(id),
271
+ (params) => this.store.cart.updateItem(params),
272
+ (params) => this.store.cart.updateItemInitInfo(params)
273
+ );
274
+ this.core.effects.emit(
275
+ `${this.store.cart.name}:onUpdateQuotationPrice`,
276
+ {}
277
+ );
266
278
  }
267
279
  }
268
-
269
280
  /**
270
281
  * ui 层提供日期的起始范围,返回一个起始范围内日期的可用情况
271
282
  * 适用于先选日期的流程,确定日期是否可用
@@ -292,36 +303,36 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
292
303
  channel
293
304
  });
294
305
  }
295
-
296
306
  // 添加单个账户或者 guest
297
307
  async addAccount(account, extra) {
298
- // 如果是holder类型的需要先做数据转换
299
- if (extra?.type === 'holder') {
308
+ if ((extra == null ? void 0 : extra.type) === "holder") {
300
309
  const accountModules = await this.store.accountList.addHolderAccounts({
301
310
  holders: [account],
302
311
  customerId: extra.customerId,
303
- type: 'unshift'
312
+ type: "unshift"
304
313
  });
305
314
  return accountModules[0].getAccount();
306
315
  }
307
- const newAccount = await this.store.accountList.addAccount(account);
316
+ const newAccount = await this.store.accountList.addAccount(
317
+ account
318
+ );
308
319
  return newAccount.getAccount();
309
320
  }
310
-
311
321
  // 添加账户或者 guest
312
322
  async addAccounts(accounts, extra) {
313
- // 如果是holder类型的需要先做数据转换
314
- if (extra?.type === 'holder') {
323
+ if ((extra == null ? void 0 : extra.type) === "holder") {
315
324
  this.store.accountList.addHolderAccounts({
316
325
  holders: accounts,
317
326
  customerId: extra.customerId,
318
- type: 'unshift'
327
+ type: "unshift"
319
328
  });
320
329
  return;
321
330
  }
322
331
  const res = [];
323
332
  for (const account of accounts) {
324
- const accountModule = await this.store.accountList.addAccount(account);
333
+ const accountModule = await this.store.accountList.addAccount(
334
+ account
335
+ );
325
336
  const accountData = accountModule.getAccount();
326
337
  if (accountData) {
327
338
  res.push(accountData);
@@ -329,77 +340,70 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
329
340
  }
330
341
  return res;
331
342
  }
332
-
333
343
  // 获取所有账户
334
344
  async getAccounts() {
335
345
  const accounts = this.store.accountList.getAccounts();
336
- return accounts.map(account => account.getAccount());
346
+ return accounts.map((account) => account.getAccount());
337
347
  }
338
348
  checkHasLoginAccount() {
339
349
  const accounts = this.store.accountList.getAccounts();
340
- return accounts.some(account => account.getLoginStatus());
350
+ return accounts.some((account) => account.getLoginStatus());
341
351
  }
342
352
  setActiveAccount(id) {
343
353
  this.store.accountList.setActiveAccount(id);
344
354
  }
345
355
  getActiveAccount() {
346
356
  const activeAccount = this.store.accountList.getActiveAccount();
347
- const account = activeAccount?.getAccount();
348
- return account === null ? undefined : account;
357
+ const account = activeAccount == null ? void 0 : activeAccount.getAccount();
358
+ return account === null ? void 0 : account;
349
359
  }
350
360
  removeAccount(id) {
351
361
  this.store.accountList.removeAccount(id);
352
- // 还需要把对应账号的商品给她删了
353
362
  this.clearCartByAccount(id);
354
363
  }
355
-
356
364
  /**
357
365
  * 获取holder类型账户列表
358
366
  * @param params
359
367
  */
360
368
  async fetchHolderAccountsAsync(params) {
369
+ var _a, _b;
361
370
  const cartItems = this.store.cart.getItems();
362
371
  if (cartItems.length) {
363
- let date = this.store.date.getDateRange()?.[0]?.date;
372
+ let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
364
373
  if (!date) {
365
- // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
366
- // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
367
- const normalProductCartItem = cartItems.find(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
368
- date = normalProductCartItem?.start_date || '';
374
+ const normalProductCartItem = cartItems.find(
375
+ (n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
376
+ );
377
+ date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
369
378
  }
370
379
  this.updateQuotationPriceAndCart(date);
371
380
  }
372
381
  return this.store.accountList.fetchHolderAccounts(params);
373
382
  }
374
-
375
383
  /**
376
384
  * 获取 holder 表单 map
377
385
  */
378
386
  getHolderFormMap() {
379
387
  return this.store.holder.getHolderFormMap();
380
388
  }
381
-
382
389
  /**
383
390
  * 登录后或外部触发时,按当前 holderMap 批量刷新所有表单的 records
384
391
  */
385
392
  async refreshAllHolderFormRecords(params) {
386
393
  return this.store.holder.refreshAllFormRecords({
387
- customer_id: params?.customer_id,
394
+ customer_id: params == null ? void 0 : params.customer_id,
388
395
  useCache: false
389
396
  });
390
397
  }
391
-
392
398
  /**
393
399
  * 添加表单记录
394
400
  */
395
401
  appendFormRecord(params) {
396
402
  return this.store.holder.appendFormRecord(params);
397
403
  }
398
-
399
404
  // 设置日期范围,注入到日期模块中
400
405
  async setDateRange(dateRange) {
401
406
  this.store.date.setDateRange(dateRange);
402
- // 日期数据变更后,如果购物车里有数据,需要更新购物车里的报价单的价格
403
407
  if (dateRange.length && this.store.cart.getItems().length) {
404
408
  this.updateQuotationPriceAndCart(dateRange[0].date);
405
409
  }
@@ -407,7 +411,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
407
411
  clearDateRange() {
408
412
  this.store.date.clearDateRange();
409
413
  }
410
-
411
414
  // 获取日期模块里选中的日期
412
415
  async getDateRange() {
413
416
  return this.store.date.getDateRange();
@@ -415,50 +418,37 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
415
418
  getCart() {
416
419
  return this.store.cart.getItems();
417
420
  }
418
-
419
421
  // 获取商品/服务的可用日期
420
422
  async getAvailableDate(params = {}) {
421
- // 开始日期如果小于今天,直接以今天当做开始日期
422
- let {
423
- products,
424
- startDate,
425
- endDate,
426
- type,
427
- useCache = true
428
- } = params;
429
- // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
430
- if ((0, _dayjs.default)(startDate).isBefore((0, _dayjs.default)(), 'day') && ((0, _dayjs.default)(endDate).isAfter((0, _dayjs.default)(), 'day') || (0, _dayjs.default)(endDate).isSame((0, _dayjs.default)(), 'day'))) {
431
- startDate = (0, _dayjs.default)().format('YYYY-MM-DD');
423
+ var _a, _b, _c, _d;
424
+ let { products, startDate, endDate, type, useCache = true } = params;
425
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
426
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
432
427
  }
433
- let tempProducts = products || this.store.cart.getItems().map(p => p._productOrigin);
428
+ let tempProducts = products || this.store.cart.getItems().map((p) => p._productOrigin);
434
429
  if (tempProducts.length) {
435
- tempProducts.forEach(p => {
436
- if (p?.['schedule.ids']) {
437
- const scheduleData = this.getScheduleDataByIds(p['schedule.ids']);
438
- p['_schedule'] = scheduleData;
430
+ tempProducts.forEach((p) => {
431
+ if (p == null ? void 0 : p["schedule.ids"]) {
432
+ const scheduleData = this.getScheduleDataByIds(p["schedule.ids"]);
433
+ p["_schedule"] = scheduleData;
439
434
  }
440
435
  });
441
436
  }
442
- // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
443
437
  if (this.store.currentProduct) {
444
- tempProducts = [{
445
- ...this.store.currentProduct,
446
- _schedule: this.store.currentProductMeta?.['schedule']
447
- }];
438
+ tempProducts = [
439
+ {
440
+ ...this.store.currentProduct,
441
+ _schedule: (_a = this.store.currentProductMeta) == null ? void 0 : _a["schedule"]
442
+ }
443
+ ];
448
444
  }
449
445
  let dateRange = this.store.date.getDateRange();
450
- const tempStartDate = startDate || dateRange?.[0]?.date;
451
- const tempEndDate = endDate || dateRange?.[1]?.date || dateRange?.[0]?.date;
446
+ const tempStartDate = startDate || ((_b = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _b.date);
447
+ const tempEndDate = endDate || ((_c = dateRange == null ? void 0 : dateRange[1]) == null ? void 0 : _c.date) || ((_d = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _d.date);
452
448
  if (!tempProducts.length) {
453
449
  return [];
454
450
  }
455
-
456
- // 在这里需要把能收集到的数据都收集上来,拼装好给 date 模块去查询
457
- const {
458
- resourceIds,
459
- rules,
460
- resourcesMap
461
- } = (0, _products.getAvailableProductResources)(tempProducts) || {};
451
+ const { resourceIds, rules, resourcesMap } = (0, import_products.getAvailableProductResources)(tempProducts) || {};
462
452
  this.otherParams.currentResourcesMap = resourcesMap;
463
453
  const res = await this.store.date.getResourceDates({
464
454
  url: params.url,
@@ -473,7 +463,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
473
463
  });
474
464
  return res;
475
465
  }
476
-
477
466
  /**
478
467
  * 获取购物车汇总信息
479
468
  */
@@ -482,29 +471,26 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
482
471
  const summary = await this.store.summary.getSummary(cartItems);
483
472
  return summary;
484
473
  }
485
-
486
474
  /**
487
475
  * 获取协议
488
476
  */
489
477
  async getProtocol(protocolId) {
490
478
  return this.store.summary.getProtocol(protocolId);
491
479
  }
492
-
493
480
  // 获取可选择的商品、服务列表
494
481
  async getProducts() {
495
482
  return this.store.products.getProducts();
496
483
  }
497
-
498
484
  // 如果用户登录
499
485
  async setLoginAccount(accountId, accountInfo) {
486
+ var _a, _b;
500
487
  const account = this.store.accountList.getAccount(accountId);
501
488
  if (account) {
502
489
  let stateAccountId = account.getId();
503
490
  accountInfo.isLogin = true;
504
491
  account.setAccountInfo(accountInfo);
505
- // 然后去购物车,把原先关联了 holder_id 为 accountId 的商品,替换为 holder_id = accountInfo.id
506
492
  const cartItems = this.store.cart.getItems();
507
- cartItems.forEach(item => {
493
+ cartItems.forEach((item) => {
508
494
  if (item.holder_id === accountId) {
509
495
  this.store.cart.updateItem({
510
496
  _id: item._id,
@@ -514,39 +500,35 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
514
500
  });
515
501
  this.store.accountList.updateAccountListById(stateAccountId, accountInfo);
516
502
  if (cartItems.length) {
517
- let date = this.store.date.getDateRange()?.[0]?.date;
503
+ let date = (_b = (_a = this.store.date.getDateRange()) == null ? void 0 : _a[0]) == null ? void 0 : _b.date;
518
504
  if (!date) {
519
- // 如果没有日期,则应该是 session 类先选商品的流程,直接从购物车里拿 start_date
520
- // 不能从购物车里第一个找时间,而是找到购物车里第一个有 start_date 的时间
521
- const normalProductCartItem = cartItems.find(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
522
- date = normalProductCartItem?.start_date || '';
505
+ const normalProductCartItem = cartItems.find(
506
+ (n) => !(0, import_utils5.isNormalProduct)(n._productOrigin)
507
+ );
508
+ date = (normalProductCartItem == null ? void 0 : normalProductCartItem.start_date) || "";
523
509
  }
524
510
  this.updateQuotationPriceAndCart(date);
525
-
526
- // 登录后刷新 holder 表单
527
511
  try {
528
512
  const customerId = Number(accountInfo.id);
529
513
  await this.refreshAllHolderFormRecords({
530
514
  customer_id: customerId
531
515
  });
532
516
  } catch (error) {
533
- console.error('[BookingByStep] 登录后刷新 holder 表单失败', error);
517
+ console.error("[BookingByStep] 登录后刷新 holder 表单失败", error);
534
518
  }
535
519
  }
536
520
  } else {
537
521
  throw new Error(`没有找到${accountId}账户`);
538
522
  }
539
523
  }
540
-
541
524
  // 生成购物车的正规数据
542
- async generateCartData() {}
543
-
525
+ async generateCartData() {
526
+ }
544
527
  // 免费领取商品相关逻辑,上线了来不及加了,先放在这,后面要做到 payment 里面的
545
528
  async getFreeProduct(id) {
546
529
  const res = await this.request.post(`/pay/order/free-pay/${id}`);
547
530
  return res;
548
531
  }
549
-
550
532
  /**
551
533
  * 检查购物车提交订单前是否符合条件
552
534
  * @param type 类型 "holder" | "account"
@@ -558,71 +540,61 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
558
540
  cartItems: this.store.cart.getItems()
559
541
  });
560
542
  }
561
-
562
543
  // 购物车提交订单
563
544
  async submitOrder(extraData) {
545
+ var _a;
564
546
  const cartItems = this.store.cart.getItems();
565
- const newCartItems = (0, _lodashEs.cloneDeep)(cartItems);
566
- // 先整个临时的逻辑,把购物车里所有商品的资源给他格式化一下
567
- newCartItems.forEach(item => {
547
+ const newCartItems = (0, import_lodash_es.cloneDeep)(cartItems);
548
+ newCartItems.forEach((item) => {
549
+ var _a2;
568
550
  if (item._origin.resources && item._origin.resources.length) {
569
- item._origin.resources = item._origin.resources.map(n => {
570
- const newResourcesItem = (0, _lodashEs.cloneDeep)(n);
551
+ item._origin.resources = item._origin.resources.map((n) => {
552
+ const newResourcesItem = (0, import_lodash_es.cloneDeep)(n);
571
553
  delete newResourcesItem.id;
572
554
  delete newResourcesItem.main_field;
573
555
  delete newResourcesItem.resourceType;
574
- return {
575
- ...newResourcesItem
576
- };
556
+ return { ...newResourcesItem };
577
557
  });
578
- const {
579
- currentCapacity,
580
- formatCapacity
581
- } = (0, _capacity.getCapacityInfoByCartItem)(item);
582
- if (!item._origin?.metadata) {
558
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
559
+ if (!((_a2 = item._origin) == null ? void 0 : _a2.metadata)) {
583
560
  item._origin.metadata = {};
584
561
  }
585
562
  item._origin.metadata.capacity = formatCapacity;
586
563
  item._origin.number = currentCapacity;
587
564
  }
588
565
  });
589
- let type = this.otherParams.isRetailTemplate ? 'virtual' : 'appointment_booking';
590
- // 如果购物车里全都是普通商品,type 也应该为 virtual
591
- if ((0, _utils5.areAllNormalProducts)(newCartItems.map(n => n._productOrigin))) {
592
- type = 'virtual';
566
+ let type = this.otherParams.isRetailTemplate ? "virtual" : "appointment_booking";
567
+ if ((0, import_utils5.areAllNormalProducts)(
568
+ newCartItems.map((n) => n._productOrigin)
569
+ )) {
570
+ type = "virtual";
593
571
  }
594
572
  return this.store.order.submitOrder({
595
573
  query: {
596
574
  cartItems: newCartItems,
597
575
  type,
598
576
  platform: this.platform,
599
- business_code: this.otherParams?.business_code,
577
+ business_code: (_a = this.otherParams) == null ? void 0 : _a.business_code,
600
578
  extraData
601
579
  }
602
580
  });
603
581
  }
604
-
605
582
  // 拉起支付模块
606
- async pay() {}
607
-
583
+ async pay() {
584
+ }
608
585
  // 获取支付信息
609
- async getPayInfo() {}
610
- async setOtherParams(params, {
611
- cover = false
612
- } = {}) {
586
+ async getPayInfo() {
587
+ }
588
+ async setOtherParams(params, { cover = false } = {}) {
613
589
  if (cover) {
614
590
  this.otherParams = params;
615
591
  } else {
616
- this.otherParams = {
617
- ...this.otherParams,
618
- ...params
619
- };
592
+ this.otherParams = { ...this.otherParams, ...params };
620
593
  }
621
594
  }
622
595
  async getOtherParams() {
623
596
  return this.otherParams;
624
597
  }
625
-
626
598
  /**
627
599
  * 往购物车加商品数据(duration 类、普通商品)
628
600
  * 老接口,先不删,怕 UI 有问题,直接桥接到新接口addProductToCart上
@@ -631,15 +603,12 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
631
603
  * @memberof BookingByStepImpl
632
604
  */
633
605
  storeProduct(productData) {
634
- // 往购物车加商品数据的时候,默认用当前 activeAccount 填充到 product 的 account 里面
635
606
  const activeAccount = this.getActiveAccount();
636
- // 直接调用 addProductToCart,不传递 date 参数以避免日期检查逻辑
637
607
  return this.addProductToCart({
638
608
  product: productData,
639
609
  account: activeAccount
640
610
  });
641
611
  }
642
-
643
612
  /**
644
613
  * 往购物车加商品数据
645
614
  *
@@ -668,31 +637,20 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
668
637
  rowKey,
669
638
  quantity = 1
670
639
  } = product || {};
671
- const productData = {
672
- ...origin,
673
- product_variant_id
674
- };
675
- // 保护,如果进来的是 session 商品,则必须要有 date 和时间片,否则不允许添加
676
- if ((0, _products.isSessionProduct)(productData)) {
640
+ const productData = { ...origin, product_variant_id };
641
+ if ((0, import_products.isSessionProduct)(productData)) {
677
642
  if (!date || !date.startTime || !date.endTime) {
678
- return {
679
- success: false,
680
- errorCode: 'date_or_time_required'
681
- };
643
+ return { success: false, errorCode: "date_or_time_required" };
682
644
  }
683
645
  }
684
-
685
- // 库存检测
686
646
  const currentCartItems = this.store.cart.getItems();
687
- const stockCheckResult = (0, _stock.checkProductStock)({
647
+ const stockCheckResult = (0, import_stock.checkProductStock)({
688
648
  productData,
689
649
  product_variant_id,
690
650
  quantity,
691
651
  bundle,
692
652
  currentCartItems
693
653
  });
694
-
695
- // 如果库存检测失败,直接返回
696
654
  if (!stockCheckResult.success) {
697
655
  return stockCheckResult;
698
656
  }
@@ -705,21 +663,19 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
705
663
  try {
706
664
  this.store.holder.ensureFormByProduct({
707
665
  product: productData,
708
- shop_id: productData?.shop_id || '',
666
+ shop_id: (productData == null ? void 0 : productData.shop_id) || "",
709
667
  useCache: true
710
668
  });
711
669
  } catch (error) {
712
- console.error('[BookingByStep] 加载 holder 表单失败', error);
670
+ console.error("[BookingByStep] 加载 holder 表单失败", error);
713
671
  }
714
672
  const flag = this.store.cart.mergeCartItemByRowKey({
715
673
  rowKey,
716
674
  quantity,
717
- account: account || undefined
675
+ account: account || void 0
718
676
  });
719
677
  if (flag) {
720
- return {
721
- success: true
722
- };
678
+ return { success: true };
723
679
  }
724
680
  const addItemParams = {
725
681
  product: productData,
@@ -733,24 +689,18 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
733
689
  if (account) {
734
690
  addItemParams.account = account;
735
691
  }
736
- this.addProductCheck({
737
- date
738
- });
739
- // 如果 quantity 大于 1,且是预约商品,则进入购物车拆散成多条数据
740
- if (addItemParams.quantity > 1 && !(0, _utils5.isNormalProduct)(productData)) {
692
+ this.addProductCheck({ date });
693
+ if (addItemParams.quantity > 1 && !(0, import_utils5.isNormalProduct)(productData)) {
741
694
  for (let i = 0; i < addItemParams.quantity; i++) {
742
- const newAddItemParams = (0, _lodashEs.cloneDeep)(addItemParams);
695
+ const newAddItemParams = (0, import_lodash_es.cloneDeep)(addItemParams);
743
696
  newAddItemParams.quantity = 1;
744
697
  this.store.cart.addItem(newAddItemParams);
745
698
  }
746
699
  } else {
747
700
  this.store.cart.addItem(addItemParams);
748
701
  }
749
- return {
750
- success: true
751
- };
702
+ return { success: true };
752
703
  }
753
-
754
704
  /**
755
705
  * 添加完购物车以后做的一些检测,比如日期是否在同一天
756
706
  *
@@ -760,38 +710,28 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
760
710
  addProductCheck({
761
711
  date
762
712
  }) {
763
- // 检测,有传递 date,检查购物车里其他商品的 date 是否在同一天,如果不在,清空那些不在同一天的商品
764
713
  if (date) {
765
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
766
- const cartItemsByDate = cartItems.filter(n => !(0, _dayjs.default)(n.start_date).isSame((0, _dayjs.default)(date.startTime), 'day'));
714
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
715
+ const cartItemsByDate = cartItems.filter(
716
+ (n) => !(0, import_dayjs.default)(n.start_date).isSame((0, import_dayjs.default)(date.startTime), "day")
717
+ );
767
718
  if (cartItemsByDate.length) {
768
- cartItemsByDate.forEach(n => {
719
+ cartItemsByDate.forEach((n) => {
769
720
  this.store.cart.removeItem(n._id);
770
721
  });
771
722
  }
772
- // // 如果 date.startTime 和 dateRange 里的 startTime 不一样,需要修正 dateRange
773
- // const dateRange = this.store.date.getDateRange()
774
- // if (dateRange?.[0] && !dayjs(dateRange[0].date).isSame(dayjs(date.startTime), 'day')) {
775
- // this.setDateRange([
776
- // { date: dayjs(date.startTime).format('YYYY-MM-DD'), status: 'available', week: '', weekNum: 0 },
777
- // { date: dayjs(date.endTime).format('YYYY-MM-DD'), status: 'available', week: '', weekNum: 0 },
778
- // ]);
779
- // }
780
723
  }
781
724
  }
782
725
  beforeUpdateCart(params, targetCartItem) {
783
726
  if (params.resources) {
784
- const {
785
- currentCapacity
786
- } = (0, _capacity.getCapacityInfoByCartItem)(targetCartItem);
787
- params.resources = params.resources.map(n => {
727
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
728
+ params.resources = params.resources.map((n) => {
788
729
  n.capacity = currentCapacity || 1;
789
- (0, _capacity.checkSubResourcesCapacity)(n);
730
+ (0, import_capacity.checkSubResourcesCapacity)(n);
790
731
  return n;
791
732
  });
792
733
  }
793
734
  }
794
-
795
735
  // 更新购物车
796
736
  updateCart(params) {
797
737
  const targetCartItem = this.store.cart.getItem(params._id);
@@ -802,7 +742,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
802
742
  this.store.cart.updateItem(params);
803
743
  this.updateCartCheck(params, targetCartItem);
804
744
  }
805
-
806
745
  /**
807
746
  * 更新购物车以后的一些操作,比如检测资源是否重复,检测资源容量是否足够
808
747
  *
@@ -812,59 +751,63 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
812
751
  * @memberof BookingByStepImpl
813
752
  */
814
753
  updateCartCheck(params, targetCartItem) {
815
- // 零售模板不需要检测
754
+ var _a;
816
755
  if (this.otherParams.isRetailTemplate) {
817
756
  return;
818
757
  }
819
758
  let currentResourcesCapacityMap = {};
820
- params.resources?.forEach(n => {
759
+ (_a = params.resources) == null ? void 0 : _a.forEach((n) => {
821
760
  currentResourcesCapacityMap[n.id] = n.capacity;
822
761
  });
823
762
  const allOriginResources = [];
824
763
  const dateRange = this.store.date.getDateRange();
825
- if (dateRange?.length) {
826
- dateRange.forEach(n => {
827
- if (n.resource) allOriginResources.push(...n.resource);
764
+ if (dateRange == null ? void 0 : dateRange.length) {
765
+ dateRange.forEach((n) => {
766
+ if (n.resource)
767
+ allOriginResources.push(...n.resource);
828
768
  });
829
769
  }
830
- // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
831
770
  if (!allOriginResources.length) {
832
771
  const dateList = this.store.date.getDateList();
833
- dateList?.forEach(n => {
834
- if (n.resource) allOriginResources.push(...n.resource);
772
+ dateList == null ? void 0 : dateList.forEach((n) => {
773
+ if (n.resource)
774
+ allOriginResources.push(...n.resource);
835
775
  });
836
776
  }
837
- // 只有在更新资源的时候做这个判断,其他情况下不做处理
838
777
  if (params.resources) {
839
- // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,且资源是单个预约,则要把选择了相同资源的 product._origin.resources 给去除
840
778
  const cartItems = this.store.cart.getItems();
841
- cartItems.forEach(item => {
779
+ cartItems.forEach((item) => {
780
+ var _a2;
842
781
  if (item._id !== targetCartItem._id) {
843
- const {
844
- currentCapacity
845
- } = (0, _capacity.getCapacityInfoByCartItem)(item);
846
- const resources = item._origin.resources?.filter(m => {
847
- // 检查当前资源是否与目标资源的任何资源匹配
848
- // 目标资源,应该只取跟当前 m.form_id 相同的资源
849
- const sameFormIdResources = (0, _resources.filterResourcesByFormItem)(targetCartItem._origin.resources, m.form_id);
850
- if (!sameFormIdResources?.length) {
782
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
783
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
784
+ const sameFormIdResources = (0, import_resources.filterResourcesByFormItem)(
785
+ targetCartItem._origin.resources,
786
+ m.form_id
787
+ );
788
+ if (!(sameFormIdResources == null ? void 0 : sameFormIdResources.length)) {
851
789
  return true;
852
790
  }
853
- return !sameFormIdResources.some(targetRes => {
854
- // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
855
- if (targetRes.resourceType !== 'single') {
856
- const originResource = allOriginResources.find(n => n.id === targetRes.id);
857
- const canUse = (0, _capacity.checkResourceCanUseByCapacity)(currentResourcesCapacityMap[m.id] || 0, currentCapacity, originResource?.capacity);
858
- if (canUse) currentResourcesCapacityMap[m.id] += currentCapacity;
791
+ return !sameFormIdResources.some((targetRes) => {
792
+ if (targetRes.resourceType !== "single") {
793
+ const originResource = allOriginResources.find(
794
+ (n) => n.id === targetRes.id
795
+ );
796
+ const canUse = (0, import_capacity.checkResourceCanUseByCapacity)(
797
+ currentResourcesCapacityMap[m.id] || 0,
798
+ currentCapacity,
799
+ originResource == null ? void 0 : originResource.capacity
800
+ );
801
+ if (canUse)
802
+ currentResourcesCapacityMap[m.id] += currentCapacity;
859
803
  return !canUse;
860
804
  }
861
- if (item.holder_id !== targetCartItem?.holder_id) {
862
- return (0, _resources.checkTwoResourcesIntersection)(targetRes, m);
805
+ if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
806
+ return (0, import_resources.checkTwoResourcesIntersection)(targetRes, m);
863
807
  }
864
808
  return false;
865
809
  });
866
810
  });
867
- // session 类商品应该只调用清空 resource 的方法
868
811
  if (item.start_time) {
869
812
  const start_time = item.start_time;
870
813
  const end_time = item.end_time;
@@ -874,8 +817,12 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
874
817
  _id: item._id,
875
818
  resources,
876
819
  date: {
877
- startTime: (0, _dayjs.default)(`${start_date} ${start_time}`).format('YYYY-MM-DD HH:mm'),
878
- endTime: (0, _dayjs.default)(`${end_date} ${end_time}`).format('YYYY-MM-DD HH:mm')
820
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format(
821
+ "YYYY-MM-DD HH:mm"
822
+ ),
823
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format(
824
+ "YYYY-MM-DD HH:mm"
825
+ )
879
826
  }
880
827
  });
881
828
  } else {
@@ -888,34 +835,29 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
888
835
  });
889
836
  }
890
837
  }
891
-
892
838
  // 删除购物车里某个商品
893
839
  deleteCart(cartItemId) {
894
840
  this.store.cart.removeItem(cartItemId);
895
841
  }
896
-
897
842
  // 清空购物车
898
843
  clearCart() {
899
844
  this.store.cart.clear();
900
845
  }
901
-
902
846
  // 基于账户清空购物车
903
847
  clearCartByAccount(account_id) {
904
848
  this.store.cart.clearCartByAccount(account_id);
905
849
  }
906
-
907
850
  /**
908
851
  * 批量更新购物车
909
852
  */
910
853
  batchUpdateCart(paramsList) {
911
854
  const cartItems = [];
912
- paramsList.forEach(params => {
855
+ paramsList.forEach((params) => {
913
856
  const cartItem = this.store.cart.formatCartItem(params);
914
857
  cartItems.push(cartItem);
915
858
  });
916
859
  this.store.cart.batchSetItems(cartItems);
917
860
  }
918
-
919
861
  /**
920
862
  * 从购物车中按类别删除信息
921
863
  */
@@ -925,17 +867,15 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
925
867
  checkCartItemByType(cartItem, type) {
926
868
  return this.store.cart.checkCartItemByType(cartItem, type);
927
869
  }
928
-
929
870
  /**
930
871
  * 检查购物车商品是否符合条件
931
872
  * @param type 类型
932
873
  * @returns 不符合条件的购物车商品ID列表
933
874
  */
934
875
  checkCartItems(type) {
935
- // 预约流程中普通商品无需检测这些东西
936
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
876
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
937
877
  const errorCartItemIds = [];
938
- cartItems.forEach(cartItem => {
878
+ cartItems.forEach((cartItem) => {
939
879
  const result = this.store.cart.checkCartItemByType(cartItem, type);
940
880
  if (!result) {
941
881
  errorCartItemIds.push(cartItem._id);
@@ -944,120 +884,129 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
944
884
  return errorCartItemIds;
945
885
  }
946
886
  destroy() {
947
- this.store.cart?.destroy();
948
- this.store.step?.destroy();
949
- this.store.products?.destroy();
950
- this.store.guests?.destroy();
951
- this.store.date?.destroy();
952
- this.store.accountList?.destroy();
953
- this.store.schedule?.destroy();
954
- this.store.summary?.destroy();
955
- this.store.order?.destroy();
887
+ var _a, _b, _c, _d, _e, _f;
888
+ (_a = this.store.cart) == null ? void 0 : _a.destroy();
889
+ (_b = this.store.step) == null ? void 0 : _b.destroy();
890
+ (_c = this.store.products) == null ? void 0 : _c.destroy();
891
+ (_d = this.store.guests) == null ? void 0 : _d.destroy();
892
+ (_e = this.store.date) == null ? void 0 : _e.destroy();
893
+ (_f = this.store.accountList) == null ? void 0 : _f.destroy();
956
894
  this.core.effects.offByModuleDestroy(this.name);
957
895
  this.core.unregisterModule(this);
958
896
  }
959
-
960
897
  // 获取当前购物车内所有关联的资源列表,拼装数据格式
961
898
  getResourcesList() {
962
899
  const dateRange = this.store.date.getDateRange();
963
900
  const resources = [];
964
- if (dateRange?.length) {
965
- dateRange.forEach(n => {
966
- if (n.resource) resources.push(...n.resource);
901
+ if (dateRange == null ? void 0 : dateRange.length) {
902
+ dateRange.forEach((n) => {
903
+ if (n.resource)
904
+ resources.push(...n.resource);
967
905
  });
968
906
  }
969
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
970
-
971
- // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
907
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
972
908
  if (!resources.length) {
973
- // 如果此时购物车里已经有了开始时间,则直接取那天的数据即可
974
- const firstDateCartItem = cartItems?.find(n => n.start_date);
975
- if (firstDateCartItem?.start_date) {
976
- const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
977
- resources.push(...(dateResources || []));
909
+ const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
910
+ if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
911
+ const dateResources = this.store.date.getResourcesListByDate(
912
+ firstDateCartItem.start_date
913
+ );
914
+ resources.push(...dateResources || []);
978
915
  } else {
979
916
  const dateList = this.store.date.getDateList();
980
- dateList?.forEach(n => {
981
- if (n.resource) resources.push(...n.resource);
917
+ dateList == null ? void 0 : dateList.forEach((n) => {
918
+ if (n.resource)
919
+ resources.push(...n.resource);
982
920
  });
983
921
  }
984
922
  }
985
- const resourcesMap = (0, _utils2.getResourcesMap)((0, _lodashEs.cloneDeep)(resources));
923
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
986
924
  const arr = [];
987
- cartItems.forEach(cartItem => {
925
+ cartItems.forEach((cartItem) => {
926
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
988
927
  let selectedResources = [];
989
- const {
990
- currentCapacity,
991
- formatCapacity
992
- } = (0, _capacity.getCapacityInfoByCartItem)(cartItem);
928
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
993
929
  cartItem._origin.metadata.capacity = formatCapacity;
994
930
  if (cartItem.holder_id) {
995
- selectedResources = (0, _resources.getOthersSelectedResources)(cartItems, cartItem.holder_id, resourcesMap);
931
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
932
+ cartItems,
933
+ cartItem.holder_id,
934
+ resourcesMap
935
+ );
996
936
  } else {
997
- selectedResources = (0, _resources.getOthersCartSelectedResources)(cartItems, cartItem._id, resourcesMap);
937
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
938
+ cartItems,
939
+ cartItem._id,
940
+ resourcesMap
941
+ );
998
942
  }
999
- // TODO:下面这一坨要放到 resources 模块去
1000
- const productResources = (0, _resources.getResourcesByProduct)(resourcesMap, cartItem._productOrigin?.product_resource?.resources || [], selectedResources, currentCapacity);
1001
- // 如果购物车里已经有了时间片,则需要按照时间片过滤
943
+ const productResources = (0, import_resources.getResourcesByProduct)(
944
+ resourcesMap,
945
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
946
+ selectedResources,
947
+ currentCapacity
948
+ );
1002
949
  if (cartItem._origin.start_time) {
1003
- const startTime = (0, _dayjs.default)(`${cartItem._origin.start_date} ${cartItem._origin.start_time}`);
1004
- const endTime = (0, _dayjs.default)(`${cartItem._origin.end_date} ${cartItem._origin.end_time}`);
950
+ const startTime = (0, import_dayjs.default)(
951
+ `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
952
+ );
953
+ const endTime = (0, import_dayjs.default)(
954
+ `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
955
+ );
1005
956
  const resourcesUseableMap = {};
1006
- productResources.forEach(n => {
1007
- // 资源排下序,把单个资源靠前,组合资源排在后面
1008
- n.renderList = (0, _resources.sortCombinedResources)(n.renderList);
1009
- n.renderList = n.renderList.filter(m => {
1010
- // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1011
- // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1012
- // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1013
- const mTimes = (0, _timeslots.filterConditionTimeSlots)(m.times, startTime, endTime);
1014
- // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
957
+ productResources.forEach((n) => {
958
+ n.renderList = (0, import_resources.sortCombinedResources)(n.renderList);
959
+ n.renderList = n.renderList.filter((m) => {
960
+ const mTimes = (0, import_timeslots.filterConditionTimeSlots)(
961
+ m.times,
962
+ startTime,
963
+ endTime
964
+ );
1015
965
  if (mTimes.length === 0) {
1016
966
  return false;
1017
967
  }
1018
- const canUseArr = mTimes.map(item => {
1019
- const res = (0, _resources.getIsUsableByTimeItem)({
968
+ const canUseArr = mTimes.map((item) => {
969
+ var _a2;
970
+ const res = (0, import_resources.getIsUsableByTimeItem)({
1020
971
  timeSlice: {
1021
- start_time: startTime.format('HH:mm'),
1022
- end_time: endTime.format('HH:mm'),
972
+ start_time: startTime.format("HH:mm"),
973
+ end_time: endTime.format("HH:mm"),
1023
974
  start_at: startTime,
1024
975
  end_at: endTime
1025
976
  },
1026
977
  time: item,
1027
978
  resource: m,
1028
979
  currentCount: currentCapacity || 0,
1029
- resourcesUseableMap: resourcesUseableMap,
1030
- cut_off_time: cartItem._productOrigin?.cut_off_time
980
+ resourcesUseableMap,
981
+ cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
1031
982
  });
1032
- // 如果仅仅是因为子资源容量不够,不应该标记子资源是被占用的情况(因为组合资源还需要判断子资源够不够)
1033
- if (resourcesUseableMap?.[m.id] !== false && res.reason !== 'capacityOnly') {
983
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
1034
984
  resourcesUseableMap[m.id] = res.usable;
1035
985
  }
1036
986
  return res.usable;
1037
987
  });
1038
- if (m.onlyComputed) return false;
1039
- // 在已经选定时间的情况下,只要canUseTime 里有一个 false,那就代表不可用
1040
- return !canUseArr.some(n => n === false);
988
+ if (m.onlyComputed)
989
+ return false;
990
+ return !canUseArr.some((n2) => n2 === false);
1041
991
  });
1042
992
  });
1043
993
  } else {
1044
- const hasFlexibleDuration = cartItem._productOrigin?.duration?.type === 'flexible';
1045
- const operating_day_boundary = this.shopStore.get('core')?.core?.operating_day_boundary;
1046
- const maxBlockThreshold = cartItem._productOrigin?.duration?.flexible_config?.is_enable_minimum_duration ? cartItem._productOrigin?.duration?.flexible_config?.block_threshold || 0 : 0;
1047
- productResources.forEach(item => {
1048
- // 如果资源的 capacity 已经小于了当前需要的 capacity ,则需要把资源给过滤掉
1049
- // 同时,在这一步尝试去拉一下时间片,基于商品的时长,看每个资源是否还有空余时间能对这个商品做服务,如果没有则过滤
1050
- item.renderList = item.renderList.filter(n => {
994
+ const hasFlexibleDuration = ((_d = (_c = cartItem._productOrigin) == null ? void 0 : _c.duration) == null ? void 0 : _d.type) === "flexible";
995
+ const operating_day_boundary = (_f = (_e = this.shopStore.get("core")) == null ? void 0 : _e.core) == null ? void 0 : _f.operating_day_boundary;
996
+ const maxBlockThreshold = ((_i = (_h = (_g = cartItem._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.flexible_config) == null ? void 0 : _i.is_enable_minimum_duration) ? ((_l = (_k = (_j = cartItem._productOrigin) == null ? void 0 : _j.duration) == null ? void 0 : _k.flexible_config) == null ? void 0 : _l.block_threshold) || 0 : 0;
997
+ productResources.forEach((item) => {
998
+ item.renderList = item.renderList.filter((n) => {
999
+ var _a2, _b2, _c2;
1051
1000
  const recordCount = n.capacity || 0;
1052
- if (n.onlyComputed) return false;
1053
- // 查一下这个资源基于商品的可用时间片
1054
- const timeSlots = (0, _resources.getTimeSlicesByResource)({
1001
+ if (n.onlyComputed)
1002
+ return false;
1003
+ const timeSlots = (0, import_resources.getTimeSlicesByResource)({
1055
1004
  resource: n,
1056
- duration: cartItem._productOrigin?.duration?.value || 10,
1005
+ duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
1057
1006
  split: 10,
1058
1007
  currentDate: dateRange[0].date,
1059
1008
  hasFlexibleDuration,
1060
- cut_off_time: cartItem._productOrigin?.cut_off_time,
1009
+ cut_off_time: (_c2 = cartItem._productOrigin) == null ? void 0 : _c2.cut_off_time,
1061
1010
  operating_day_boundary,
1062
1011
  maxBlockThreshold
1063
1012
  });
@@ -1078,7 +1027,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1078
1027
  });
1079
1028
  return arr;
1080
1029
  }
1081
-
1082
1030
  /**
1083
1031
  * 在日期那边点击下一步的时候,检查这一天购物车里的商品是不是都有资源可以用
1084
1032
  *
@@ -1087,12 +1035,11 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1087
1035
  */
1088
1036
  checkResourceListForDate() {
1089
1037
  const resourcesList = this.getResourcesList();
1090
-
1091
- // 检查每一项资源的 renderList 里是否都有数据
1092
- const hasResource = resourcesList.every(item => item.resources.every(resource => resource.renderList.length > 0));
1038
+ const hasResource = resourcesList.every(
1039
+ (item) => item.resources.every((resource) => resource.renderList.length > 0)
1040
+ );
1093
1041
  return hasResource;
1094
1042
  }
1095
-
1096
1043
  /**
1097
1044
  * 给单个购物车里的商品获取资源列表,给 UI 用的
1098
1045
  *
@@ -1101,32 +1048,45 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1101
1048
  * @memberof BookingByStepImpl
1102
1049
  */
1103
1050
  getResourcesListByCartItem(id) {
1104
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
1051
+ var _a, _b;
1052
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1105
1053
  const dateRange = this.store.date.getDateRange();
1106
1054
  const resources = [];
1107
- dateRange.forEach(n => {
1108
- if (n.resource) resources.push(...n.resource);
1055
+ dateRange.forEach((n) => {
1056
+ if (n.resource)
1057
+ resources.push(...n.resource);
1109
1058
  });
1110
- // 用于确保后续分配的容量不会超出
1111
- const resourcesMap = (0, _utils2.getResourcesMap)(resources);
1112
- const targetCartItem = cartItems.find(n => n._id === id);
1059
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1060
+ const targetCartItem = cartItems.find((n) => n._id === id);
1113
1061
  if (!targetCartItem) {
1114
1062
  throw new Error(`没有找到${id}购物车商品`);
1115
1063
  }
1116
1064
  let selectedResources = [];
1117
- const {
1118
- currentCapacity
1119
- } = (0, _capacity.getCapacityInfoByCartItem)(targetCartItem);
1065
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(targetCartItem);
1120
1066
  if (targetCartItem.holder_id) {
1121
- selectedResources = (0, _resources.getOthersSelectedResources)(cartItems, targetCartItem.holder_id, resourcesMap);
1067
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
1068
+ cartItems,
1069
+ targetCartItem.holder_id,
1070
+ resourcesMap
1071
+ );
1122
1072
  } else {
1123
- selectedResources = (0, _resources.getOthersCartSelectedResources)(cartItems, targetCartItem._id, resourcesMap);
1073
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
1074
+ cartItems,
1075
+ targetCartItem._id,
1076
+ resourcesMap
1077
+ );
1124
1078
  }
1125
- const productResources = (0, _resources.getResourcesByProduct)(resourcesMap, targetCartItem._productOrigin?.product_resource?.resources || [], selectedResources, currentCapacity);
1126
- productResources.forEach(item => {
1127
- item.renderList = item.renderList.filter(n => {
1079
+ const productResources = (0, import_resources.getResourcesByProduct)(
1080
+ resourcesMap,
1081
+ ((_b = (_a = targetCartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1082
+ selectedResources,
1083
+ currentCapacity
1084
+ );
1085
+ productResources.forEach((item) => {
1086
+ item.renderList = item.renderList.filter((n) => {
1128
1087
  const recordCount = n.capacity || 0;
1129
- if (n.onlyComputed) return false;
1088
+ if (n.onlyComputed)
1089
+ return false;
1130
1090
  return recordCount >= currentCapacity;
1131
1091
  });
1132
1092
  });
@@ -1143,7 +1103,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1143
1103
  };
1144
1104
  }
1145
1105
  }
1146
-
1147
1106
  // 自动分派可用资源-pro 版,ui 传递某个账号,自动给某个账号下所有商品分配第一种资源
1148
1107
  autoSelectAccountResources({
1149
1108
  cartItem,
@@ -1153,111 +1112,109 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1153
1112
  countMap,
1154
1113
  capacity
1155
1114
  }) {
1156
- if ((0, _utils5.isNormalProduct)(cartItem._productOrigin)) {
1115
+ var _a, _b, _c;
1116
+ if ((0, import_utils5.isNormalProduct)(cartItem._productOrigin)) {
1157
1117
  return {};
1158
1118
  }
1159
1119
  const dateRange = this.store.date.getDateRange();
1160
- const cartItems = (0, _lodashEs.cloneDeep)(this.store.cart.getItems());
1161
- // 取到账号下所有的商品,然后根据商品的 duration 和资源列表,获取所有可用的资源
1162
- let accountCartItems = cartItems.filter(n => n.holder_id === holder_id) || [];
1163
- // 账号下没商品则处理所有购物车
1120
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1121
+ let accountCartItems = cartItems.filter((n) => n.holder_id === holder_id) || [];
1164
1122
  if (!accountCartItems.length) {
1165
1123
  accountCartItems = cartItems;
1166
1124
  }
1167
- // duration=所有商品时间的集合,如果是灵活时长,当做占用 10 分钟处理
1168
1125
  let duration = accountCartItems.reduce((acc, n) => {
1169
- return acc + (n._productOrigin?.duration?.value || 10);
1126
+ var _a2, _b2;
1127
+ return acc + (((_b2 = (_a2 = n._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10);
1170
1128
  }, 0);
1171
1129
  let AllResources = [];
1172
- if (dateRange?.length) {
1173
- dateRange.forEach(n => {
1174
- if (n.resource) AllResources.push(...n.resource);
1130
+ if (dateRange == null ? void 0 : dateRange.length) {
1131
+ dateRange.forEach((n) => {
1132
+ if (n.resource)
1133
+ AllResources.push(...n.resource);
1175
1134
  });
1176
1135
  }
1177
- // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1178
1136
  if (!AllResources.length) {
1179
- const firstDateCartItem = cartItems?.find(n => n.start_date);
1180
- if (firstDateCartItem?.start_date) {
1181
- const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1182
- AllResources.push(...(dateResources || []));
1137
+ const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
1138
+ if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
1139
+ const dateResources = this.store.date.getResourcesListByDate(
1140
+ firstDateCartItem.start_date
1141
+ );
1142
+ AllResources.push(...dateResources || []);
1183
1143
  } else {
1184
1144
  const dateList = this.store.date.getDateList();
1185
- dateList.forEach(n => {
1186
- if (n.resource) AllResources.push(...n.resource);
1145
+ dateList.forEach((n) => {
1146
+ if (n.resource)
1147
+ AllResources.push(...n.resource);
1187
1148
  });
1188
1149
  }
1189
1150
  }
1190
- const resourcesMap = (0, _utils2.getResourcesMap)((0, _lodashEs.cloneDeep)(AllResources));
1191
- const allCartItems = (0, _lodashEs.cloneDeep)(this.store.cart.getItems());
1192
- const selectedResources = (0, _resources.getOthersSelectedResources)(allCartItems, holder_id, resourcesMap);
1193
- let allProductResources = (0, _resources.getResourcesByProduct)(resourcesMap, cartItem._productOrigin?.product_resource?.resources || [], selectedResources, 1);
1194
- const resources = allProductResources.find(n => n.code === resources_code)?.renderList || [];
1195
- // 资源排下序,把单个资源靠前,组合资源排在后面
1151
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
1152
+ const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1153
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
1154
+ allCartItems,
1155
+ holder_id,
1156
+ resourcesMap
1157
+ );
1158
+ let allProductResources = (0, import_resources.getResourcesByProduct)(
1159
+ resourcesMap,
1160
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1161
+ selectedResources,
1162
+ 1
1163
+ );
1164
+ const resources = ((_c = allProductResources.find((n) => n.code === resources_code)) == null ? void 0 : _c.renderList) || [];
1196
1165
  resources.sort((a, b) => {
1197
- const aIsCombined = a.metadata?.combined_resource?.status === 1;
1198
- const bIsCombined = b.metadata?.combined_resource?.status === 1;
1199
- if (aIsCombined && !bIsCombined) return 1;
1200
- if (!aIsCombined && bIsCombined) return -1;
1166
+ var _a2, _b2, _c2, _d;
1167
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1168
+ const bIsCombined = ((_d = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d.status) === 1;
1169
+ if (aIsCombined && !bIsCombined)
1170
+ return 1;
1171
+ if (!aIsCombined && bIsCombined)
1172
+ return -1;
1201
1173
  return 0;
1202
1174
  });
1203
- const resourcesUseableMap = [...selectedResources].reduce((acc, n) => {
1204
- acc[n] = resourcesMap[n]?.resourceType === 'single' ? false : true;
1175
+ const resourcesUseableMap = [
1176
+ ...selectedResources
1177
+ ].reduce((acc, n) => {
1178
+ var _a2;
1179
+ acc[n] = ((_a2 = resourcesMap[n]) == null ? void 0 : _a2.resourceType) === "single" ? false : true;
1205
1180
  return acc;
1206
1181
  }, {});
1207
-
1208
- // 如果有选择时间了,则代表不是第一种资源了,则需要根据开始时间去匹配
1209
- // 每个商品
1210
1182
  if (timeSlots) {
1211
- // const start_time = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1212
- // const end_time = dayjs(`${dateRange[0].date} ${timeSlots.start_time}`)
1213
- // .add(duration, durationType as dayjs.ManipulateType)
1214
- // .format("HH:mm");
1215
- // 根据 start_time 和 end_time 去匹配资源
1216
1183
  let targetResource = null;
1217
1184
  let targetResourceTime = 0;
1218
1185
  for (const n of resources) {
1219
- // 如果资源是独占的,并且 countMap 里选择过这个资源,则直接跳过
1220
- // if (n.resourceType === 'single' && countMap[n.id]) {
1221
- // resourcesUseableMap[n.id] = false;
1222
- // continue
1223
- // }
1224
- // const recordCount = countMap[n.id] || 0;
1225
- // n.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
1226
- // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
1227
- // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
1228
- const mTimes = n.times.filter(n => {
1229
- return !(0, _dayjs.default)(n.start_at).isAfter((0, _dayjs.default)(timeSlots.start_at)) && !(0, _dayjs.default)(n.end_at).isBefore((0, _dayjs.default)(timeSlots.end_at));
1186
+ const mTimes = n.times.filter((n2) => {
1187
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at));
1230
1188
  });
1231
- // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
1232
1189
  if (mTimes.length === 0) {
1233
1190
  continue;
1234
1191
  }
1235
- // 计算在时间片内有交集的预约容量总和
1236
- const totalCapacity = (countMap[n.id] || []).reduce((sum, item) => {
1237
- const hasOverlap = (0, _dayjs.default)(item.time.start_at).isBefore((0, _dayjs.default)(timeSlots.end_at)) && (0, _dayjs.default)(item.time.end_at).isAfter((0, _dayjs.default)(timeSlots.start_at));
1238
- return hasOverlap ? sum + item.pax : sum;
1239
- }, 0);
1240
-
1241
- // 如果资源是单个预约,并且有 totalCapacity,则认为在当前 timeSlots 资源已经被选择过,就不可用了
1242
- if (n.resourceType === 'single' && totalCapacity > 0) {
1192
+ const totalCapacity = (countMap[n.id] || []).reduce(
1193
+ (sum, item) => {
1194
+ const hasOverlap = (0, import_dayjs.default)(item.time.start_at).isBefore((0, import_dayjs.default)(timeSlots.end_at)) && (0, import_dayjs.default)(item.time.end_at).isAfter((0, import_dayjs.default)(timeSlots.start_at));
1195
+ return hasOverlap ? sum + item.pax : sum;
1196
+ },
1197
+ 0
1198
+ );
1199
+ if (n.resourceType === "single" && totalCapacity > 0) {
1243
1200
  continue;
1244
1201
  }
1245
- const canUseTime = mTimes.find(item => {
1246
- const res = (0, _resources.getIsUsableByTimeItem)({
1202
+ const canUseTime = mTimes.find((item) => {
1203
+ var _a2;
1204
+ const res = (0, import_resources.getIsUsableByTimeItem)({
1247
1205
  timeSlice: timeSlots,
1248
1206
  time: item,
1249
1207
  resource: n,
1250
1208
  currentCount: totalCapacity + (capacity || 0),
1251
1209
  resourcesUseableMap,
1252
- cut_off_time: cartItem._productOrigin?.cut_off_time
1210
+ cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
1253
1211
  });
1254
- // 如果只是因为子资源容量不够,而不是子资源被预约导致没时间片,不应该标记子资源为不可用,从而影响组合资源的情况
1255
- if (resourcesUseableMap?.[n.id] !== false && res.reason !== 'capacityOnly') {
1212
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[n.id]) !== false && res.reason !== "capacityOnly") {
1256
1213
  resourcesUseableMap[n.id] = res.usable;
1257
1214
  }
1258
1215
  return res.usable;
1259
1216
  });
1260
- const currentResourceIdleTime = (0, _timeslots.calculateResourceAvailableTime)({
1217
+ const currentResourceIdleTime = (0, import_timeslots.calculateResourceAvailableTime)({
1261
1218
  resource: n,
1262
1219
  timeSlots,
1263
1220
  currentCapacity: totalCapacity + (capacity || 0)
@@ -1272,82 +1229,79 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1272
1229
  selectedResource: targetResource
1273
1230
  };
1274
1231
  } else {
1275
- const resourcesMap = (0, _utils2.getResourcesMap)(resources);
1276
- const resourceIds = resources.map(n => n.id);
1277
- const timeSlots = (0, _resources.getTimeSlicesByResources)({
1232
+ const resourcesMap2 = (0, import_utils2.getResourcesMap)(resources);
1233
+ const resourceIds = resources.map((n) => n.id);
1234
+ const timeSlots2 = (0, import_resources.getTimeSlicesByResources)({
1278
1235
  resourceIds,
1279
- resourcesMap,
1236
+ resourcesMap: resourcesMap2,
1280
1237
  duration,
1281
1238
  currentDate: dateRange[0].date,
1282
1239
  split: 10,
1283
1240
  capacity,
1284
1241
  resourcesUseableMap
1285
1242
  });
1286
- // 如果timeSlots返回了 空数组,代表没有可用的资源了
1287
- if (!timeSlots) {
1288
- return; // 给一个提示?
1243
+ if (!timeSlots2) {
1244
+ return;
1289
1245
  }
1290
1246
  return {
1291
- timeSlots,
1247
+ timeSlots: timeSlots2,
1292
1248
  selectedResource: resources[0]
1293
1249
  };
1294
1250
  }
1295
1251
  }
1296
-
1297
1252
  // 给所有购物车里的商品先分配一个资源
1298
1253
  autoSelectAllProductResources(resources_code, timeSlots) {
1254
+ var _a;
1299
1255
  const dateRange = this.store.date.getDateRange();
1300
1256
  const resources = [];
1301
- if (dateRange?.[0]?.date) {
1302
- dateRange.forEach(n => {
1303
- if (n.resource) resources.push(...n.resource);
1257
+ if ((_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.date) {
1258
+ dateRange.forEach((n) => {
1259
+ if (n.resource)
1260
+ resources.push(...n.resource);
1304
1261
  });
1305
1262
  }
1306
- // 一个账号一个账号处理
1307
1263
  const errorList = [];
1308
- // 资源使用情况-单个预约
1309
1264
  const selectResourcesMap = {};
1310
- // 资源使用情况-多个预约
1311
1265
  const selectResourcesWithTimeSlots = {};
1312
1266
  const accountList = this.store.accountList.getAccounts();
1313
- const selectForCartResources = cartItems => {
1314
- let recordTimeSlots = (0, _lodashEs.cloneDeep)(timeSlots);
1315
- // timeSlots 传进来的只是用户选中的时间片,但是实际上需要根据多个商品时间进行累加
1316
- // 假设 timeSlots.start_time 是15:40 duration 是 30min
1317
- // 第一个商品分配完以后,第二个商品分配的start_time应该是第一个商品的 end_time ,然后 end_time 应该是 start_time+duration
1318
- // 判断购物车里是否有 flexible 类型的商品,如果有则不累加时间
1319
- const hasFlexibleProduct = cartItems.some(item => item._productOrigin?.duration?.type === 'flexible');
1320
- cartItems.forEach((item, index) => {
1321
- const {
1322
- currentCapacity
1323
- } = (0, _capacity.getCapacityInfoByCartItem)(item);
1324
- const hasOriginTimeSlot = Boolean(item._origin.start_time) && Boolean(item._origin.end_time) && !timeSlots?.start_time;
1325
- // 如果商品已经有时间数据了,意味着是通过先选日期再选商品流程进来的,相当于时间切片已经选中了
1267
+ const selectForCartResources = (cartItems2) => {
1268
+ let recordTimeSlots = (0, import_lodash_es.cloneDeep)(timeSlots);
1269
+ const hasFlexibleProduct = cartItems2.some(
1270
+ (item) => {
1271
+ var _a2, _b;
1272
+ return ((_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b.type) === "flexible";
1273
+ }
1274
+ );
1275
+ cartItems2.forEach((item, index) => {
1276
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1277
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(item);
1278
+ const hasOriginTimeSlot = Boolean(item._origin.start_time) && Boolean(item._origin.end_time) && !(timeSlots == null ? void 0 : timeSlots.start_time);
1326
1279
  if (hasOriginTimeSlot) {
1327
1280
  recordTimeSlots = {
1328
1281
  start_time: item._origin.start_time,
1329
1282
  end_time: item._origin.end_time,
1330
- start_at: (0, _dayjs.default)(`${item.start_date} ${item._origin.start_time}`),
1331
- end_at: (0, _dayjs.default)(`${item.end_date} ${item._origin.end_time}`)
1283
+ start_at: (0, import_dayjs.default)(`${item.start_date} ${item._origin.start_time}`),
1284
+ end_at: (0, import_dayjs.default)(`${item.end_date} ${item._origin.end_time}`)
1332
1285
  };
1333
1286
  }
1334
1287
  if (recordTimeSlots) {
1335
- // 同一账号下,如果当前商品不是第一个,则需要根据上一个商品的 end_time 和 duration 计算出当前商品的 start_time 和 end_time
1336
- // 前提:当前资源是单个预约才需要这么做
1337
- const currentResourceConfig = item._productOrigin?.product_resource?.resources?.find(n => n.code === resources_code);
1338
- // 只有 duration 类商品且不含有灵活时间的商品需要这个操作
1339
- if (index !== 0 && recordTimeSlots && currentResourceConfig?.type === 'single' && item._productOrigin?.duration && !hasFlexibleProduct && !hasOriginTimeSlot) {
1340
- const recordEndAt = recordTimeSlots.end_at ? (0, _dayjs.default)(recordTimeSlots.end_at) : (0, _dayjs.default)(`${item.start_date} ${recordTimeSlots.end_time}`);
1288
+ const currentResourceConfig = (_c = (_b = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b.resources) == null ? void 0 : _c.find(
1289
+ (n) => n.code === resources_code
1290
+ );
1291
+ if (index !== 0 && recordTimeSlots && (currentResourceConfig == null ? void 0 : currentResourceConfig.type) === "single" && ((_d = item._productOrigin) == null ? void 0 : _d.duration) && !hasFlexibleProduct && !hasOriginTimeSlot) {
1292
+ const recordEndAt = recordTimeSlots.end_at ? (0, import_dayjs.default)(recordTimeSlots.end_at) : (0, import_dayjs.default)(`${item.start_date} ${recordTimeSlots.end_time}`);
1341
1293
  let start_at = recordEndAt;
1342
- let end_at = start_at.add(item._productOrigin?.duration?.value || 10, 'minutes');
1294
+ let end_at = start_at.add(
1295
+ ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10,
1296
+ "minutes"
1297
+ );
1343
1298
  recordTimeSlots = {
1344
- start_time: start_at.format('HH:mm'),
1345
- end_time: end_at.format('HH:mm'),
1299
+ start_time: start_at.format("HH:mm"),
1300
+ end_time: end_at.format("HH:mm"),
1346
1301
  start_at,
1347
1302
  end_at
1348
1303
  };
1349
1304
  }
1350
- // 如果传递了 timeSlots,代表是第二种资源,则直接拿 timeSlots 去匹配
1351
1305
  const res = this.autoSelectAccountResources({
1352
1306
  cartItem: item,
1353
1307
  holder_id: item.holder_id,
@@ -1356,12 +1310,14 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1356
1310
  countMap: selectResourcesWithTimeSlots,
1357
1311
  capacity: currentCapacity
1358
1312
  });
1359
- if (res?.selectedResource) {
1313
+ if (res == null ? void 0 : res.selectedResource) {
1360
1314
  if (!selectResourcesWithTimeSlots[res.selectedResource.id]) {
1361
- selectResourcesWithTimeSlots[res.selectedResource.id] = [{
1362
- pax: currentCapacity,
1363
- time: recordTimeSlots
1364
- }];
1315
+ selectResourcesWithTimeSlots[res.selectedResource.id] = [
1316
+ {
1317
+ pax: currentCapacity,
1318
+ time: recordTimeSlots
1319
+ }
1320
+ ];
1365
1321
  } else {
1366
1322
  selectResourcesWithTimeSlots[res.selectedResource.id].push({
1367
1323
  pax: currentCapacity,
@@ -1369,73 +1325,94 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1369
1325
  });
1370
1326
  }
1371
1327
  res.selectedResource.capacity = currentCapacity;
1372
- (0, _capacity.checkSubResourcesCapacity)(res.selectedResource);
1328
+ (0, import_capacity.checkSubResourcesCapacity)(res.selectedResource);
1373
1329
  this.store.cart.updateItem({
1374
1330
  _id: item._id,
1375
1331
  // 这里要做去重,避免出现同样类型的资源被塞进同一个商品
1376
- resources: [...(item._origin.resources || []).filter(existingRes => existingRes.form_id !== res.selectedResource?.form_id), res.selectedResource]
1332
+ resources: [
1333
+ ...(item._origin.resources || []).filter(
1334
+ (existingRes) => {
1335
+ var _a3;
1336
+ return existingRes.form_id !== ((_a3 = res.selectedResource) == null ? void 0 : _a3.form_id);
1337
+ }
1338
+ ),
1339
+ res.selectedResource
1340
+ ]
1377
1341
  });
1378
1342
  } else {
1379
- // 如果没有可用的技师了,推到错误列表里让 UI 去提示
1380
1343
  errorList.push(item._id);
1381
1344
  }
1382
1345
  } else {
1383
- // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1384
- // 能进到这种逻辑,说明是 duration 类商品或者灵活时长商品,且是第一种资源,还没有确定时间
1385
- const allCartItems = (0, _lodashEs.cloneDeep)(this.store.cart.getItems());
1386
- // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1346
+ const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1387
1347
  let selectedResources = [];
1388
- const resources = (0, _lodashEs.cloneDeep)(item._productOrigin?.product_resource?.resources || []);
1348
+ const resources2 = (0, import_lodash_es.cloneDeep)(
1349
+ ((_h = (_g = item._productOrigin) == null ? void 0 : _g.product_resource) == null ? void 0 : _h.resources) || []
1350
+ );
1389
1351
  const currentResourcesRenderList = [];
1390
- resources.forEach(n => {
1391
- if (n.renderList?.length) {
1392
- // 过滤掉 capacity 小于 currentCapacity 的资源
1393
- n.renderList = n.renderList.filter(m => {
1394
- // 同时 还需要减去 selectResourcesMap 里已经选中的资源的数量
1352
+ resources2.forEach((n) => {
1353
+ var _a3;
1354
+ if ((_a3 = n.renderList) == null ? void 0 : _a3.length) {
1355
+ n.renderList = n.renderList.filter((m) => {
1356
+ var _a4;
1395
1357
  const recordCount = (m.capacity || 0) - (selectResourcesMap[m.id] || 0);
1396
- const timeSlots = (0, _resources.getTimeSlicesByResource)({
1358
+ const timeSlots2 = (0, import_resources.getTimeSlicesByResource)({
1397
1359
  resource: m,
1398
- duration: item?.duration?.value || 10,
1360
+ duration: ((_a4 = item == null ? void 0 : item.duration) == null ? void 0 : _a4.value) || 10,
1399
1361
  split: 10,
1400
1362
  currentDate: dateRange[0].date
1401
1363
  });
1402
- return recordCount >= currentCapacity && timeSlots.length > 0;
1364
+ return recordCount >= currentCapacity && timeSlots2.length > 0;
1403
1365
  });
1404
- currentResourcesRenderList.push(...(n.renderList || []));
1366
+ currentResourcesRenderList.push(...n.renderList || []);
1405
1367
  }
1406
1368
  });
1407
- const resourcesMap = (0, _utils2.getResourcesMap)(currentResourcesRenderList);
1369
+ const resourcesMap = (0, import_utils2.getResourcesMap)(currentResourcesRenderList);
1408
1370
  if (item.holder_id) {
1409
- selectedResources = (0, _resources.getOthersSelectedResources)(allCartItems, item.holder_id, resourcesMap);
1371
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
1372
+ allCartItems,
1373
+ item.holder_id,
1374
+ resourcesMap
1375
+ );
1410
1376
  } else {
1411
- selectedResources = (0, _resources.getOthersCartSelectedResources)(allCartItems, item._id, resourcesMap);
1377
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
1378
+ allCartItems,
1379
+ item._id,
1380
+ resourcesMap
1381
+ );
1412
1382
  }
1413
- const productResources = (0, _resources.getResourcesByProduct)(resourcesMap, (0, _lodashEs.cloneDeep)(resources), selectedResources, currentCapacity);
1414
- productResources.forEach(item => {
1415
- item.renderList = item.renderList.filter(n => {
1383
+ const productResources = (0, import_resources.getResourcesByProduct)(
1384
+ resourcesMap,
1385
+ (0, import_lodash_es.cloneDeep)(resources2),
1386
+ selectedResources,
1387
+ currentCapacity
1388
+ );
1389
+ productResources.forEach((item2) => {
1390
+ item2.renderList = item2.renderList.filter((n) => {
1416
1391
  const recordCount = (n.capacity || 0) - (selectResourcesMap[n.id] || 0);
1417
- if (n.onlyComputed) return false;
1392
+ if (n.onlyComputed)
1393
+ return false;
1418
1394
  return recordCount >= currentCapacity;
1419
1395
  });
1420
1396
  });
1421
- // 自动选择 productResources 中对应 resources_code 的资源
1422
- const targetRenderList = productResources.find(n => n.code === resources_code)?.renderList;
1397
+ const targetRenderList = (_i = productResources.find(
1398
+ (n) => n.code === resources_code
1399
+ )) == null ? void 0 : _i.renderList;
1423
1400
  if (targetRenderList && targetRenderList.length > 0) {
1424
- // 如果购物车里已经有同类型的 form_id 的资源了,则不处理
1425
- if (item._origin.resources?.some(n => n.form_id === targetRenderList[0].form_id)) {
1401
+ if ((_j = item._origin.resources) == null ? void 0 : _j.some(
1402
+ (n) => n.form_id === targetRenderList[0].form_id
1403
+ )) {
1426
1404
  return;
1427
1405
  }
1428
- const fastestResource = (0, _timeslots.findFastestAvailableResource)({
1406
+ const fastestResource = (0, import_timeslots.findFastestAvailableResource)({
1429
1407
  resources: targetRenderList,
1430
- currentCapacity: currentCapacity,
1408
+ currentCapacity,
1431
1409
  countMap: selectResourcesMap,
1432
- targetDate: dateRange?.[0]?.date,
1433
- durationMinutes: item?.duration?.value || item?._productOrigin?.duration?.value || 10
1410
+ targetDate: (_k = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _k.date,
1411
+ durationMinutes: ((_l = item == null ? void 0 : item.duration) == null ? void 0 : _l.value) || ((_n = (_m = item == null ? void 0 : item._productOrigin) == null ? void 0 : _m.duration) == null ? void 0 : _n.value) || 10
1434
1412
  });
1435
1413
  const targetResource = fastestResource || targetRenderList[0];
1436
1414
  targetResource.capacity = currentCapacity;
1437
- // 在这里处理 children 的数据
1438
- (0, _capacity.checkSubResourcesCapacity)(targetResource);
1415
+ (0, import_capacity.checkSubResourcesCapacity)(targetResource);
1439
1416
  if (!selectResourcesMap[targetResource.id]) {
1440
1417
  selectResourcesMap[targetResource.id] = currentCapacity;
1441
1418
  } else {
@@ -1443,107 +1420,101 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1443
1420
  }
1444
1421
  this.store.cart.updateItem({
1445
1422
  _id: item._id,
1446
- resources: [...(item._origin.resources || []).filter(existingRes => existingRes.resourceType !== targetRenderList[0].resourceType), targetResource]
1423
+ resources: [
1424
+ ...(item._origin.resources || []).filter(
1425
+ (existingRes) => existingRes.resourceType !== targetRenderList[0].resourceType
1426
+ ),
1427
+ targetResource
1428
+ ]
1447
1429
  });
1448
1430
  } else {
1449
- // 如果没有可用的技师了,推到错误列表里让 UI 去提示
1450
1431
  errorList.push(item._id);
1451
1432
  }
1452
1433
  }
1453
1434
  });
1454
1435
  };
1455
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
1456
-
1457
- // 如果购物车里没有 holderid数据,证明不按 holder 类流程预约走,给所有购物车一次性分派即可,不做账号下资源互斥逻辑
1458
- if (cartItems?.[0].holder_id) {
1459
- accountList.forEach(account => {
1460
- const cartItems = this.store.cart.getCartByAccount(account.getId());
1461
- selectForCartResources(cartItems);
1436
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1437
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1438
+ accountList.forEach((account) => {
1439
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
1440
+ selectForCartResources(cartItems2);
1462
1441
  });
1463
1442
  } else {
1464
1443
  selectForCartResources(cartItems);
1465
1444
  }
1466
- return {
1467
- errorList
1468
- };
1445
+ return { errorList };
1469
1446
  }
1470
1447
  // 从购物车中获取已经分配好第一步资源的所有时间片
1471
1448
  getTimeSlotByAllResources(resources_code, split = 10) {
1449
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1472
1450
  let dateRange = this.store.date.getDateRange();
1473
- // 取出购物车中所有一已选择的第一步资源
1474
1451
  const resources = [];
1475
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
1476
- // if (cartItems?.[0].start_date) return [];
1452
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1477
1453
  const resourceIds = [];
1478
- let resourcesTypeId = undefined;
1454
+ let resourcesTypeId = void 0;
1479
1455
  let isSingleResource = false;
1480
-
1481
- // 找出购物车里最大的 cut_off_time
1482
- let maxCutOffTime = undefined;
1483
- let maxCutOffTimeValue = (0, _dayjs.default)();
1484
- cartItems.forEach(item => {
1485
- item._productOrigin?.product_resource?.resources?.forEach(n => {
1486
- // TODO: 少了个 status 的判断
1456
+ let maxCutOffTime = void 0;
1457
+ let maxCutOffTimeValue = (0, import_dayjs.default)();
1458
+ cartItems.forEach((item) => {
1459
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2;
1460
+ (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
1487
1461
  if (n.code === resources_code) {
1488
- resources.push(...(n.renderList || []));
1489
- isSingleResource = n.type === 'single';
1462
+ resources.push(...n.renderList || []);
1463
+ isSingleResource = n.type === "single";
1490
1464
  }
1491
1465
  });
1492
- // item._origin.resources?.forEach((n: any) => {
1493
- // resourceIds.push(n.relation_id);
1494
- // });
1495
1466
  if (item.resource_id && !resourceIds.includes(item.resource_id)) {
1496
1467
  resourceIds.push(item.resource_id);
1497
1468
  }
1498
- resourcesTypeId = item?._productOrigin?.product_resource?.resources?.find(n => n.code === resources_code)?.id;
1499
- if (item._productOrigin?.cut_off_time && item._productOrigin?.cut_off_time.type === 'advance') {
1500
- const currentCutOffTime = (0, _dayjs.default)().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
1501
- if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
1469
+ resourcesTypeId = (_g2 = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
1470
+ (n) => n.code === resources_code
1471
+ )) == null ? void 0 : _g2.id;
1472
+ if (((_h2 = item._productOrigin) == null ? void 0 : _h2.cut_off_time) && ((_i2 = item._productOrigin) == null ? void 0 : _i2.cut_off_time.type) === "advance") {
1473
+ const currentCutOffTime = (0, import_dayjs.default)().add(
1474
+ item._productOrigin.cut_off_time.unit,
1475
+ item._productOrigin.cut_off_time.unit_type
1476
+ );
1477
+ if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
1502
1478
  maxCutOffTimeValue = currentCutOffTime;
1503
1479
  maxCutOffTime = item._productOrigin.cut_off_time;
1504
1480
  }
1505
1481
  }
1506
1482
  });
1507
- // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
1508
- if (dateRange?.[0]?.resource?.length) {
1509
- // resources.push(...dateRange[0].resource);
1510
- dateRange[0].resource.forEach(n => {
1511
- if (n.form_id === resourcesTypeId && !resources.find(m => m.id === n.id)) {
1483
+ if ((_b = (_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.resource) == null ? void 0 : _b.length) {
1484
+ dateRange[0].resource.forEach((n) => {
1485
+ if (n.form_id === resourcesTypeId && !resources.find((m) => m.id === n.id)) {
1512
1486
  resources.push(n);
1513
1487
  }
1514
1488
  });
1515
1489
  }
1516
- // 检查通过购物车 renderList 加入的资源数据里 times 的正确性,如果不对则需要修正
1517
- if (dateRange?.[0]?.date && resources.length) {
1518
- const currentDate = dateRange?.[0]?.date;
1490
+ if (((_c = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _c.date) && resources.length) {
1491
+ const currentDate = (_d = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _d.date;
1519
1492
  const theDateResources = this.store.date.getResourcesListByDate(currentDate);
1520
- resources.forEach(item => {
1521
- const noCurrentDateTimes = item.times.some(n => {
1522
- return (0, _dayjs.default)(n.start_at).isSame((0, _dayjs.default)(currentDate), 'day');
1493
+ resources.forEach((item) => {
1494
+ var _a2;
1495
+ const noCurrentDateTimes = item.times.some((n) => {
1496
+ return (0, import_dayjs.default)(n.start_at).isSame((0, import_dayjs.default)(currentDate), "day");
1523
1497
  });
1524
1498
  if (!noCurrentDateTimes) {
1525
- item.times = theDateResources?.find(n => n.id === item.id)?.times || [];
1499
+ item.times = ((_a2 = theDateResources == null ? void 0 : theDateResources.find((n) => n.id === item.id)) == null ? void 0 : _a2.times) || [];
1526
1500
  }
1527
1501
  });
1528
1502
  }
1529
-
1530
- // 如果依然 resources 空的,则证明他是切换日期了,此时直接从 date 模块里取
1531
1503
  if (resources.length === 0) {
1532
- resources.push(...(this.store.date.getResourcesListByDate(dateRange[0].date) || []));
1504
+ resources.push(...this.store.date.getResourcesListByDate(dateRange[0].date) || []);
1533
1505
  }
1534
- const resourcesMap = (0, _utils2.getResourcesMap)(resources);
1506
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1535
1507
  let duration = 0;
1536
- // duration = 不同账号的最长时间
1537
1508
  const accountList = this.store.accountList.getAccounts();
1538
- const checkDuration = cartItems => {
1509
+ const checkDuration = (cartItems2) => {
1539
1510
  let accountDuration = 0;
1540
- cartItems.forEach(item => {
1541
- // 单个预约累加账号 多个预约取最大值
1511
+ cartItems2.forEach((item) => {
1512
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1542
1513
  if (isSingleResource) {
1543
- accountDuration += item._productOrigin?.duration?.value || 10;
1514
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10;
1544
1515
  } else {
1545
- if (accountDuration < (item._productOrigin?.duration?.value || 10)) {
1546
- accountDuration = item._productOrigin?.duration?.value || 10;
1516
+ if (accountDuration < (((_d2 = (_c2 = item._productOrigin) == null ? void 0 : _c2.duration) == null ? void 0 : _d2.value) || 10)) {
1517
+ accountDuration = ((_f2 = (_e2 = item._productOrigin) == null ? void 0 : _e2.duration) == null ? void 0 : _f2.value) || 10;
1547
1518
  }
1548
1519
  }
1549
1520
  });
@@ -1551,68 +1522,74 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1551
1522
  duration = accountDuration;
1552
1523
  }
1553
1524
  };
1554
- if (cartItems?.[0].holder_id) {
1555
- accountList.forEach(account => {
1556
- const cartItems = this.store.cart.getCartByAccount(account.getId());
1557
- checkDuration(cartItems);
1525
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1526
+ accountList.forEach((account) => {
1527
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
1528
+ checkDuration(cartItems2);
1558
1529
  });
1559
1530
  } else {
1560
1531
  checkDuration(cartItems);
1561
1532
  }
1562
- // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
1563
- // 同时 session 类商品的流程也不应该调用这个方法
1564
- if (!cartItems?.[0]?.start_date && !cartItems?.[0]?.resource_id || !cartItems?.[0].duration) {
1533
+ if (!((_e = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _e.start_date) && !((_f = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _f.resource_id) || !(cartItems == null ? void 0 : cartItems[0].duration)) {
1565
1534
  return [];
1566
1535
  }
1567
- if (cartItems?.[0].start_date && !dateRange) {
1568
- dateRange = [{
1569
- date: cartItems?.[0].start_date,
1570
- status: 'available',
1571
- week: '',
1572
- weekNum: 0
1573
- }, {
1574
- date: cartItems?.[0]?.end_date || cartItems?.[0]?.start_date || '',
1575
- status: 'available',
1576
- week: '',
1577
- weekNum: 0
1578
- }];
1536
+ if ((cartItems == null ? void 0 : cartItems[0].start_date) && !dateRange) {
1537
+ dateRange = [
1538
+ {
1539
+ date: cartItems == null ? void 0 : cartItems[0].start_date,
1540
+ status: "available",
1541
+ week: "",
1542
+ weekNum: 0
1543
+ },
1544
+ {
1545
+ date: ((_g = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _g.end_date) || ((_h = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _h.start_date) || "",
1546
+ status: "available",
1547
+ week: "",
1548
+ weekNum: 0
1549
+ }
1550
+ ];
1579
1551
  }
1580
1552
  const resourcesUseableMap = {};
1581
- const hasFlexibleDuration = cartItems.some(item => item._productOrigin?.duration?.type === 'flexible');
1582
- let operating_day_boundary = this.shopStore.get('core')?.core?.operating_day_boundary;
1583
-
1584
- // 如果有 hasFlexibleDuration,需要把动态时长商品(可能是多个,取最长的那个最低禁止购买时长)的最低禁止购买时长作为 split 的值
1553
+ const hasFlexibleDuration = cartItems.some(
1554
+ (item) => {
1555
+ var _a2, _b2;
1556
+ return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1557
+ }
1558
+ );
1559
+ let operating_day_boundary = (_j = (_i = this.shopStore.get("core")) == null ? void 0 : _i.core) == null ? void 0 : _j.operating_day_boundary;
1585
1560
  let maxBlockThreshold = 0;
1586
1561
  if (hasFlexibleDuration) {
1587
1562
  maxBlockThreshold = cartItems.reduce((max, item) => {
1588
- // 如果开启了灵活时长商品配置,则取 block_threshold 的值
1589
- if (item._productOrigin?.duration?.flexible_config?.is_enable_minimum_duration) {
1590
- return Math.max(max, item._productOrigin?.duration?.flexible_config?.block_threshold || 0);
1563
+ var _a2, _b2, _c2, _d2, _e2, _f2;
1564
+ if ((_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.flexible_config) == null ? void 0 : _c2.is_enable_minimum_duration) {
1565
+ return Math.max(
1566
+ max,
1567
+ ((_f2 = (_e2 = (_d2 = item._productOrigin) == null ? void 0 : _d2.duration) == null ? void 0 : _e2.flexible_config) == null ? void 0 : _f2.block_threshold) || 0
1568
+ );
1591
1569
  }
1592
1570
  return 0;
1593
1571
  }, 0);
1594
1572
  }
1595
- // 计算容量的辅助函数
1596
- const calculateCapacityFromCartItems = items => {
1597
- if (items.length === 0) return 0;
1598
- // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
1599
- const firstResource = items[0]._resourceOrigin?.[0].id;
1600
- const sameResourceLength = items.filter(item => item._resourceOrigin?.[0].id === firstResource).length;
1573
+ const calculateCapacityFromCartItems = (items) => {
1574
+ var _a2;
1575
+ if (items.length === 0)
1576
+ return 0;
1577
+ const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
1578
+ const sameResourceLength = items.filter((item) => {
1579
+ var _a3;
1580
+ return ((_a3 = item._resourceOrigin) == null ? void 0 : _a3[0].id) === firstResource;
1581
+ }).length;
1601
1582
  if (sameResourceLength === items.length) {
1602
1583
  return 1;
1603
1584
  }
1604
- // 找出单个购物车里最大的需求 capacity 即可
1605
- return Math.max(...items.map(item => (0, _capacity.getCapacityInfoByCartItem)(item).currentCapacity || 1));
1606
- // return items.reduce((total, item) => {
1607
- // return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
1608
- // }, 0);
1585
+ return Math.max(...items.map((item) => (0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 1));
1609
1586
  };
1610
-
1611
- // 如果是多个人预约,去要求出几个 holder 下最大的商品需求容量capacity
1612
1587
  let maxCapacity = 1;
1613
- if (cartItems?.[0].holder_id) {
1614
- accountList.forEach(account => {
1615
- const accountCartItems = this.store.cart.getCartByAccount(account.getId());
1588
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1589
+ accountList.forEach((account) => {
1590
+ const accountCartItems = this.store.cart.getCartByAccount(
1591
+ account.getId()
1592
+ );
1616
1593
  const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
1617
1594
  if (currentCapacity > maxCapacity) {
1618
1595
  maxCapacity = currentCapacity;
@@ -1621,13 +1598,13 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1621
1598
  } else {
1622
1599
  maxCapacity = calculateCapacityFromCartItems(cartItems);
1623
1600
  }
1624
- const timeSlots = (0, _resources.getTimeSlicesByResources)({
1601
+ const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1625
1602
  resourceIds,
1626
1603
  resourcesMap,
1627
1604
  duration,
1628
1605
  currentDate: dateRange[0].date,
1629
- split: split,
1630
- resourcesUseableMap: resourcesUseableMap,
1606
+ split,
1607
+ resourcesUseableMap,
1631
1608
  capacity: maxCapacity,
1632
1609
  cut_off_time: maxCutOffTime,
1633
1610
  hasFlexibleDuration,
@@ -1637,70 +1614,61 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1637
1614
  return timeSlots;
1638
1615
  }
1639
1616
  // 从购物车中获取已经分配好第一步资源的所有时间片,批量版本,用于给日期提供能否高亮的判断
1640
- async getTimeSlotByAllResourcesForDate({
1641
- resources_code,
1642
- startDate,
1643
- endDate
1644
- }) {
1645
- // 如果 end_date 距离start_date小于 30 天,自动追加 end_date 为今天往后的 30 天
1646
- if ((0, _dayjs.default)(endDate).diff((0, _dayjs.default)(startDate), 'day') < 30) {
1647
- endDate = (0, _dayjs.default)(startDate).add(30, 'day').format('YYYY-MM-DD');
1617
+ async getTimeSlotByAllResourcesForDate({ resources_code, startDate, endDate }) {
1618
+ var _a, _b, _c, _d;
1619
+ if ((0, import_dayjs.default)(endDate).diff((0, import_dayjs.default)(startDate), "day") < 30) {
1620
+ endDate = (0, import_dayjs.default)(startDate).add(30, "day").format("YYYY-MM-DD");
1648
1621
  }
1649
- // 预请求资源数据,防止日期超过之前选择的范围
1650
1622
  await this.getAvailableDate({
1651
- startDate: startDate,
1652
- endDate: endDate,
1623
+ startDate,
1624
+ endDate,
1653
1625
  useCache: true
1654
1626
  });
1655
- // 取出购物车中所有一已选择的第一步资源
1656
1627
  const resources = [];
1657
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
1658
- // if (cartItems?.[0].start_date) return [];
1628
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1659
1629
  const resourceIds = [];
1660
- let resourcesTypeId = undefined;
1630
+ let resourcesTypeId = void 0;
1661
1631
  let isSingleResource = false;
1662
-
1663
- // 找出购物车里最大的 cut_off_time
1664
- let maxCutOffTime = undefined;
1665
- let maxCutOffTimeValue = (0, _dayjs.default)();
1666
- cartItems.forEach(item => {
1667
- item._productOrigin?.product_resource?.resources?.forEach(n => {
1668
- // TODO: 少了个 status 的判断
1632
+ let maxCutOffTime = void 0;
1633
+ let maxCutOffTimeValue = (0, import_dayjs.default)();
1634
+ cartItems.forEach((item) => {
1635
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i;
1636
+ (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
1669
1637
  if (n.code === resources_code) {
1670
- resources.push(...(n.renderList || []));
1671
- isSingleResource = n.type === 'single';
1638
+ resources.push(...n.renderList || []);
1639
+ isSingleResource = n.type === "single";
1672
1640
  }
1673
1641
  });
1674
- // item._origin.resources?.forEach((n: any) => {
1675
- // resourceIds.push(n.relation_id);
1676
- // });
1677
1642
  if (item.resource_id && !resourceIds.includes(item.resource_id)) {
1678
1643
  resourceIds.push(item.resource_id);
1679
1644
  }
1680
- resourcesTypeId = item?._productOrigin?.product_resource?.resources?.find(n => n.code === resources_code)?.id;
1681
- if (item._productOrigin?.cut_off_time && item._productOrigin?.cut_off_time.type === 'advance') {
1682
- const currentCutOffTime = (0, _dayjs.default)().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
1683
- if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
1645
+ resourcesTypeId = (_g = (_f = (_e = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e.resources) == null ? void 0 : _f.find(
1646
+ (n) => n.code === resources_code
1647
+ )) == null ? void 0 : _g.id;
1648
+ if (((_h = item._productOrigin) == null ? void 0 : _h.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
1649
+ const currentCutOffTime = (0, import_dayjs.default)().add(
1650
+ item._productOrigin.cut_off_time.unit,
1651
+ item._productOrigin.cut_off_time.unit_type
1652
+ );
1653
+ if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
1684
1654
  maxCutOffTimeValue = currentCutOffTime;
1685
1655
  maxCutOffTime = item._productOrigin.cut_off_time;
1686
1656
  }
1687
1657
  }
1688
1658
  });
1689
-
1690
- // 保护: 如果 resources 为空则直接 return
1691
- if (!resources.length) return [];
1659
+ if (!resources.length)
1660
+ return [];
1692
1661
  let duration = 0;
1693
- // duration = 不同账号的最长时间
1694
1662
  const accountList = this.store.accountList.getAccounts();
1695
- const checkDuration = cartItems => {
1663
+ const checkDuration = (cartItems2) => {
1696
1664
  let accountDuration = 0;
1697
- cartItems.forEach(item => {
1698
- // 单个预约累加账号 多个预约取最大值
1665
+ cartItems2.forEach((item) => {
1666
+ var _a2, _b2, _c2, _d2, _e, _f;
1699
1667
  if (isSingleResource) {
1700
- accountDuration += item._productOrigin?.duration?.value || 10;
1668
+ accountDuration += ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10;
1701
1669
  } else {
1702
- if (accountDuration < (item._productOrigin?.duration?.value || 10)) {
1703
- accountDuration = item._productOrigin?.duration?.value || 10;
1670
+ if (accountDuration < (((_d2 = (_c2 = item._productOrigin) == null ? void 0 : _c2.duration) == null ? void 0 : _d2.value) || 10)) {
1671
+ accountDuration = ((_f = (_e = item._productOrigin) == null ? void 0 : _e.duration) == null ? void 0 : _f.value) || 10;
1704
1672
  }
1705
1673
  }
1706
1674
  });
@@ -1708,50 +1676,52 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1708
1676
  duration = accountDuration;
1709
1677
  }
1710
1678
  };
1711
- if (cartItems?.[0].holder_id) {
1712
- accountList.forEach(account => {
1713
- const cartItems = this.store.cart.getCartByAccount(account.getId());
1714
- checkDuration(cartItems);
1679
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1680
+ accountList.forEach((account) => {
1681
+ const cartItems2 = this.store.cart.getCartByAccount(account.getId());
1682
+ checkDuration(cartItems2);
1715
1683
  });
1716
1684
  } else {
1717
1685
  checkDuration(cartItems);
1718
1686
  }
1719
- // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
1720
- // 同时 session 类商品的流程也不应该调用这个方法
1721
- if (!cartItems?.[0]?.start_date && !cartItems?.[0]?.resource_id || !cartItems?.[0].duration) {
1687
+ if (!((_a = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _a.start_date) && !((_b = cartItems == null ? void 0 : cartItems[0]) == null ? void 0 : _b.resource_id) || !(cartItems == null ? void 0 : cartItems[0].duration)) {
1722
1688
  return [];
1723
1689
  }
1724
1690
  const resourcesUseableMap = {};
1725
- const hasFlexibleDuration = cartItems.some(item => item._productOrigin?.duration?.type === 'flexible');
1726
- let operating_day_boundary = this.shopStore.get('core')?.core?.operating_day_boundary;
1727
-
1728
- // 如果有 hasFlexibleDuration,需要把动态时长商品(可能是多个,取最长的那个最低禁止购买时长)的最低禁止购买时长作为 split 的值
1691
+ const hasFlexibleDuration = cartItems.some(
1692
+ (item) => {
1693
+ var _a2, _b2;
1694
+ return ((_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.type) === "flexible";
1695
+ }
1696
+ );
1697
+ let operating_day_boundary = (_d = (_c = this.shopStore.get("core")) == null ? void 0 : _c.core) == null ? void 0 : _d.operating_day_boundary;
1729
1698
  let maxBlockThreshold = 0;
1730
1699
  if (hasFlexibleDuration) {
1731
1700
  maxBlockThreshold = cartItems.reduce((max, item) => {
1732
- // 如果开启了灵活时长商品配置,则取 block_threshold 的值
1733
- if (item._productOrigin?.duration?.flexible_config?.is_enable_minimum_duration) {
1734
- return Math.max(max, item._productOrigin?.duration?.flexible_config?.block_threshold || 0);
1701
+ var _a2, _b2, _c2, _d2, _e, _f;
1702
+ if ((_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.flexible_config) == null ? void 0 : _c2.is_enable_minimum_duration) {
1703
+ return Math.max(max, ((_f = (_e = (_d2 = item._productOrigin) == null ? void 0 : _d2.duration) == null ? void 0 : _e.flexible_config) == null ? void 0 : _f.block_threshold) || 0);
1735
1704
  }
1736
1705
  return 0;
1737
1706
  }, 0);
1738
1707
  }
1739
- // 计算容量的辅助函数
1740
- const calculateCapacityFromCartItems = items => {
1741
- if (items.length === 0) return 0;
1742
- // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
1743
- const firstResource = items[0]._resourceOrigin?.[0].id;
1744
- const sameResourceLength = items.filter(item => item._resourceOrigin?.[0].id === firstResource).length;
1708
+ const calculateCapacityFromCartItems = (items) => {
1709
+ var _a2;
1710
+ if (items.length === 0)
1711
+ return 0;
1712
+ const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
1713
+ const sameResourceLength = items.filter((item) => {
1714
+ var _a3;
1715
+ return ((_a3 = item._resourceOrigin) == null ? void 0 : _a3[0].id) === firstResource;
1716
+ }).length;
1745
1717
  if (sameResourceLength !== items.length) {
1746
1718
  return 1;
1747
1719
  }
1748
- // 找出单个购物车里最大的需求 capacity 即可
1749
- return Math.max(...items.map(item => (0, _capacity.getCapacityInfoByCartItem)(item).currentCapacity || 1));
1720
+ return Math.max(...items.map((item) => (0, import_capacity.getCapacityInfoByCartItem)(item).currentCapacity || 1));
1750
1721
  };
1751
- // 如果是多个预约,去要求出几个 holder 下最大的需求容量capacity
1752
1722
  let maxCapacity = 1;
1753
- if (cartItems?.[0].holder_id) {
1754
- accountList.forEach(account => {
1723
+ if (cartItems == null ? void 0 : cartItems[0].holder_id) {
1724
+ accountList.forEach((account) => {
1755
1725
  const accountCartItems = this.store.cart.getCartByAccount(account.getId());
1756
1726
  const currentCapacity = calculateCapacityFromCartItems(accountCartItems);
1757
1727
  if (currentCapacity > maxCapacity) {
@@ -1762,33 +1732,31 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1762
1732
  maxCapacity = calculateCapacityFromCartItems(cartItems);
1763
1733
  }
1764
1734
  const arr = [];
1765
- const today = (0, _dayjs.default)().startOf('day');
1766
- // 计算 start_date 到 end_date 之间的所有日期,遍历他们并且计算每一天的可用
1767
- for (let i = (0, _dayjs.default)(startDate); i.isBefore((0, _dayjs.default)(endDate)); i = i.add(1, 'day')) {
1768
- const currentDate = i.format('YYYY-MM-DD');
1735
+ const today = (0, import_dayjs.default)().startOf("day");
1736
+ for (let i = (0, import_dayjs.default)(startDate); i.isBefore((0, import_dayjs.default)(endDate)); i = i.add(1, "day")) {
1737
+ const currentDate = i.format("YYYY-MM-DD");
1769
1738
  const theDateResources = this.store.date.getResourcesListByDate(currentDate);
1770
- resources.forEach(item => {
1771
- item.times = theDateResources?.find(n => n.id === item.id)?.times || [];
1739
+ resources.forEach((item) => {
1740
+ var _a2;
1741
+ item.times = ((_a2 = theDateResources == null ? void 0 : theDateResources.find((n) => n.id === item.id)) == null ? void 0 : _a2.times) || [];
1772
1742
  });
1773
- const resourcesMap = (0, _utils2.getResourcesMap)(resources);
1774
-
1775
- // 如果日期已经过期则直接标记为不可用
1743
+ const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
1776
1744
  if (i.isBefore(today)) {
1777
1745
  arr.push({
1778
1746
  date: currentDate,
1779
- status: 'unavailable',
1780
- week: i.format('ddd'),
1747
+ status: "unavailable",
1748
+ week: i.format("ddd"),
1781
1749
  weekNum: i.day()
1782
1750
  });
1783
1751
  continue;
1784
1752
  }
1785
- const timeSlots = (0, _resources.getTimeSlicesByResources)({
1753
+ const timeSlots = (0, import_resources.getTimeSlicesByResources)({
1786
1754
  resourceIds,
1787
1755
  resourcesMap,
1788
1756
  duration,
1789
- currentDate: currentDate,
1757
+ currentDate,
1790
1758
  split: 10,
1791
- resourcesUseableMap: resourcesUseableMap,
1759
+ resourcesUseableMap,
1792
1760
  capacity: maxCapacity,
1793
1761
  cut_off_time: maxCutOffTime,
1794
1762
  hasFlexibleDuration,
@@ -1798,74 +1766,63 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1798
1766
  if (timeSlots.length > 0) {
1799
1767
  arr.push({
1800
1768
  date: currentDate,
1801
- status: 'available',
1802
- week: i.format('ddd'),
1769
+ status: "available",
1770
+ week: i.format("ddd"),
1803
1771
  weekNum: i.day()
1804
1772
  });
1805
1773
  } else {
1806
1774
  arr.push({
1807
1775
  date: currentDate,
1808
- status: 'unavailable',
1809
- week: i.format('ddd'),
1776
+ status: "unavailable",
1777
+ week: i.format("ddd"),
1810
1778
  weekNum: i.day()
1811
1779
  });
1812
1780
  }
1813
1781
  }
1814
1782
  return arr;
1815
1783
  }
1816
-
1817
1784
  // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
1818
1785
  submitTimeSlot(timeSlots) {
1819
- // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
1820
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
1821
-
1822
- // 取出所有资源列表
1823
- const allResources = this.store.date.getResourcesListByDate(timeSlots.start_at.format('YYYY-MM-DD'));
1824
-
1825
- // 按账号分组
1826
- const itemsByAccount = cartItems.reduce((acc, item) => {
1827
- const holderId = item.holder_id;
1828
- if (!acc[holderId]) {
1829
- acc[holderId] = [];
1830
- }
1831
- acc[holderId].push(item);
1832
- return acc;
1833
- }, {});
1834
-
1835
- // 店铺营业结束时间
1836
- const operating_day_boundary = this.shopStore.get('core')?.core?.operating_day_boundary;
1837
-
1838
- // 处理每个账号的商品
1839
- Object.values(itemsByAccount).forEach(accountItems => {
1840
- let currentStartTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1786
+ var _a, _b;
1787
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
1788
+ const allResources = this.store.date.getResourcesListByDate(
1789
+ timeSlots.start_at.format("YYYY-MM-DD")
1790
+ );
1791
+ const itemsByAccount = cartItems.reduce(
1792
+ (acc, item) => {
1793
+ const holderId = item.holder_id;
1794
+ if (!acc[holderId]) {
1795
+ acc[holderId] = [];
1796
+ }
1797
+ acc[holderId].push(item);
1798
+ return acc;
1799
+ },
1800
+ {}
1801
+ );
1802
+ const operating_day_boundary = (_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.operating_day_boundary;
1803
+ Object.values(itemsByAccount).forEach((accountItems) => {
1804
+ let currentStartTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1841
1805
  accountItems.forEach((item, index) => {
1806
+ var _a2;
1842
1807
  const osWarnTips = [];
1843
- const newResources = (0, _lodashEs.cloneDeep)(item._origin.resources);
1844
- newResources.forEach(resource => {
1845
- // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
1846
- if (item._productOrigin?.duration?.type === 'flexible') {
1847
- item.duration = {
1848
- type: 'minutes',
1849
- value: 10
1850
- };
1851
- resource.startTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
1852
- // 找到resource.times里最晚的end_at
1853
- const targetResourceTimes = allResources?.find(n => n.id === resource.id)?.times;
1854
- // 找到最晚的 end_at 还没用,因为可能存在资源工作时间是 10:00-19:00,但是资源的 times 里有 16:30-19:00 被 block 的情况
1855
- // 所以还需要排除掉 block 时间
1856
- function getEarliestBlockedStartTime({
1857
- currentStartTime,
1808
+ const newResources = (0, import_lodash_es.cloneDeep)(item._origin.resources);
1809
+ newResources.forEach((resource) => {
1810
+ var _a3, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1811
+ if (((_b2 = (_a3 = item._productOrigin) == null ? void 0 : _a3.duration) == null ? void 0 : _b2.type) === "flexible") {
1812
+ let getEarliestBlockedStartTime = function({
1813
+ currentStartTime: currentStartTime2,
1858
1814
  times
1859
1815
  }) {
1860
- const currentStart = (0, _dayjs.default)(currentStartTime);
1816
+ var _a4;
1817
+ const currentStart = (0, import_dayjs.default)(currentStartTime2);
1861
1818
  let earliestBlockStart;
1862
1819
  for (const time of times || []) {
1863
- const blockedTimes = time.event_list?.filter(event => event.type !== 'schedule_event');
1820
+ const blockedTimes = (_a4 = time.event_list) == null ? void 0 : _a4.filter((event) => event.type !== "schedule_event");
1864
1821
  for (const event of blockedTimes || []) {
1865
- const eventStart = (0, _dayjs.default)(event.start_at);
1866
- const eventEnd = (0, _dayjs.default)(event.end_at);
1822
+ const eventStart = (0, import_dayjs.default)(event.start_at);
1823
+ const eventEnd = (0, import_dayjs.default)(event.end_at);
1867
1824
  if (eventStart.isBefore(currentStart) && eventEnd.isAfter(currentStart)) {
1868
- return currentStart.format('YYYY-MM-DD HH:mm');
1825
+ return currentStart.format("YYYY-MM-DD HH:mm");
1869
1826
  }
1870
1827
  if (eventStart.isAfter(currentStart)) {
1871
1828
  if (!earliestBlockStart || eventStart.isBefore(earliestBlockStart)) {
@@ -1874,68 +1831,79 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1874
1831
  }
1875
1832
  }
1876
1833
  }
1877
- return earliestBlockStart?.format('YYYY-MM-DD HH:mm');
1878
- }
1879
- const resourcesEndTime = targetResourceTimes.reduce((acc, curr) => {
1880
- return (0, _dayjs.default)(curr.end_at).isAfter((0, _dayjs.default)(acc.end_at)) ? curr : acc;
1881
- }, targetResourceTimes[0]);
1834
+ return earliestBlockStart == null ? void 0 : earliestBlockStart.format("YYYY-MM-DD HH:mm");
1835
+ };
1836
+ item.duration = {
1837
+ type: "minutes",
1838
+ value: 10
1839
+ };
1840
+ resource.startTime = timeSlots.start_at.format("YYYY-MM-DD HH:mm");
1841
+ const targetResourceTimes = (_c = allResources == null ? void 0 : allResources.find(
1842
+ (n) => n.id === resource.id
1843
+ )) == null ? void 0 : _c.times;
1844
+ const resourcesEndTime = targetResourceTimes.reduce(
1845
+ (acc, curr) => {
1846
+ return (0, import_dayjs.default)(curr.end_at).isAfter((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1847
+ },
1848
+ targetResourceTimes[0]
1849
+ );
1882
1850
  const earliestBlockedStartTime = getEarliestBlockedStartTime({
1883
1851
  currentStartTime,
1884
1852
  times: targetResourceTimes
1885
1853
  });
1886
-
1887
- // 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
1888
- const resourceDate = (0, _dayjs.default)(resourcesEndTime.end_at).format('YYYY-MM-DD');
1889
- const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === 'start_time' ? '23:59' : operating_day_boundary.time}`;
1890
- const endTimeCandidates = [resourcesEndTime.end_at, operatingBoundaryDateTime, ...(earliestBlockedStartTime ? [earliestBlockedStartTime] : [])];
1854
+ const resourceDate = (0, import_dayjs.default)(resourcesEndTime.end_at).format(
1855
+ "YYYY-MM-DD"
1856
+ );
1857
+ const operatingBoundaryDateTime = `${resourceDate} ${operating_day_boundary.type === "start_time" ? "23:59" : operating_day_boundary.time}`;
1858
+ const endTimeCandidates = [
1859
+ resourcesEndTime.end_at,
1860
+ operatingBoundaryDateTime,
1861
+ ...earliestBlockedStartTime ? [earliestBlockedStartTime] : []
1862
+ ];
1891
1863
  const endTime = endTimeCandidates.reduce((earliest, value) => {
1892
- return (0, _dayjs.default)(value).isBefore((0, _dayjs.default)(earliest)) ? value : earliest;
1864
+ return (0, import_dayjs.default)(value).isBefore((0, import_dayjs.default)(earliest)) ? value : earliest;
1893
1865
  }, endTimeCandidates[0]);
1894
- // 修复:如果 endTime 只是时间格式(如 "17:00"),需要加上日期
1895
1866
  let formattedEndTime;
1896
- if (typeof endTime === 'string' && endTime.includes(':') && !endTime.includes(' ') && !endTime.includes('T')) {
1897
- // 如果是纯时间格式,与当前日期合并
1898
- const currentDate = timeSlots.start_at.format('YYYY-MM-DD');
1899
- formattedEndTime = (0, _dayjs.default)(`${currentDate} ${endTime}`);
1867
+ if (typeof endTime === "string" && endTime.includes(":") && !endTime.includes(" ") && !endTime.includes("T")) {
1868
+ const currentDate = timeSlots.start_at.format("YYYY-MM-DD");
1869
+ formattedEndTime = (0, import_dayjs.default)(`${currentDate} ${endTime}`);
1900
1870
  } else {
1901
- formattedEndTime = (0, _dayjs.default)(endTime);
1871
+ formattedEndTime = (0, import_dayjs.default)(endTime);
1902
1872
  }
1903
- resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
1904
- // 如果是动态时长商品,并且当前选择的时间的结束时间小于了最低提示时长(warningThreshold),则追加一个提示
1905
- // 如果currentStartTime + warningThreshold 大于 currentEndTime,且 osWarnTips 没有pisell2.product.card.closing-soon.warning 这一项,则加入这一项
1906
- if (item._productOrigin?.duration?.flexible_config?.is_enable_minimum_duration && (0, _dayjs.default)(currentStartTime).add(item._productOrigin?.duration?.flexible_config?.warning_threshold || 0, 'minutes').isAfter((0, _dayjs.default)(formattedEndTime))) {
1907
- if (!osWarnTips.includes('pisell2.product.card.closing-soon.warning')) {
1908
- osWarnTips.push('pisell2.product.card.closing-soon.warning');
1873
+ resource.endTime = formattedEndTime.format("YYYY-MM-DD HH:mm");
1874
+ if (((_f = (_e = (_d = item._productOrigin) == null ? void 0 : _d.duration) == null ? void 0 : _e.flexible_config) == null ? void 0 : _f.is_enable_minimum_duration) && (0, import_dayjs.default)(currentStartTime).add(((_i = (_h = (_g = item._productOrigin) == null ? void 0 : _g.duration) == null ? void 0 : _h.flexible_config) == null ? void 0 : _i.warning_threshold) || 0, "minutes").isAfter((0, import_dayjs.default)(formattedEndTime))) {
1875
+ if (!osWarnTips.includes("pisell2.product.card.closing-soon.warning")) {
1876
+ osWarnTips.push("pisell2.product.card.closing-soon.warning");
1909
1877
  }
1910
1878
  }
1911
1879
  } else {
1912
1880
  resource.startTime = currentStartTime;
1913
- resource.endTime = (0, _dayjs.default)(currentStartTime).add(item._productOrigin?.duration?.value || 10, 'minutes').format('YYYY-MM-DD HH:mm');
1881
+ resource.endTime = (0, import_dayjs.default)(currentStartTime).add(((_k = (_j = item._productOrigin) == null ? void 0 : _j.duration) == null ? void 0 : _k.value) || 10, "minutes").format("YYYY-MM-DD HH:mm");
1914
1882
  }
1915
- // delete resource.times;
1916
1883
  });
1917
1884
  this.store.cart.updateItem({
1918
1885
  _id: item._id,
1919
1886
  resources: newResources,
1920
1887
  osWarnTips
1921
1888
  });
1922
-
1923
- // 更新下一个商品的开始时间为当前商品的结束时间
1924
- if (index < accountItems.length - 1 && newResources?.[0]?.resourceType === 'single') {
1889
+ if (index < accountItems.length - 1 && ((_a2 = newResources == null ? void 0 : newResources[0]) == null ? void 0 : _a2.resourceType) === "single") {
1925
1890
  currentStartTime = newResources[0].endTime;
1926
1891
  }
1927
1892
  });
1928
1893
  });
1929
- this.core.effects.emit(`${this.store.cart.name}:onUpdateBookingDate`, {});
1894
+ this.core.effects.emit(
1895
+ `${this.store.cart.name}:onUpdateBookingDate`,
1896
+ {}
1897
+ );
1930
1898
  }
1931
1899
  getScheduleDataByIds(scheduleIds) {
1932
1900
  const targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
1933
- const targetSchedulesData = targetSchedules.map(item => {
1934
- return (0, _utils3.calcCalendarDataByScheduleResult)(item);
1901
+ const targetSchedulesData = targetSchedules.map((item) => {
1902
+ return (0, import_utils3.calcCalendarDataByScheduleResult)(item);
1935
1903
  });
1936
1904
  const newSchedule = {};
1937
- targetSchedulesData.forEach(item => {
1938
- item.forEach(n => {
1905
+ targetSchedulesData.forEach((item) => {
1906
+ item.forEach((n) => {
1939
1907
  if (!newSchedule[n.date]) {
1940
1908
  newSchedule[n.date] = n;
1941
1909
  } else {
@@ -1946,9 +1914,8 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1946
1914
  });
1947
1915
  });
1948
1916
  const newScheduleArr = Object.values(newSchedule);
1949
- // newScheduleArr 需要做个排序,按日期从小到大
1950
1917
  newScheduleArr.sort((a, b) => {
1951
- return (0, _dayjs.default)(a.date).diff((0, _dayjs.default)(b.date));
1918
+ return (0, import_dayjs.default)(a.date).diff((0, import_dayjs.default)(b.date));
1952
1919
  });
1953
1920
  return newScheduleArr;
1954
1921
  }
@@ -1958,22 +1925,17 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1958
1925
  if (targetProductData) {
1959
1926
  this.store.currentProduct = targetProductData;
1960
1927
  this.store.currentProductMeta = {};
1961
- // 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
1962
- if (targetProductData['schedule.ids']) {
1963
- const newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
1964
- if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
1928
+ if (targetProductData["schedule.ids"]) {
1929
+ const newScheduleArr = this.getScheduleDataByIds(
1930
+ targetProductData["schedule.ids"]
1931
+ );
1932
+ if (!this.store.currentProductMeta)
1933
+ this.store.currentProductMeta = {};
1965
1934
  this.store.currentProductMeta.schedule = newScheduleArr;
1966
1935
  } else if (targetProductData.duration) {
1967
1936
  const dateRange = this.store.date.getDateRange();
1968
- // 如果不是先选日期的流程 duration 商品就啥也不做
1969
- if (!dateRange?.length) return;
1970
- // this.store.date.getResourceDates({
1971
- // query: {
1972
- // start_date: dateRange[0].date,
1973
- // end_date: dateRange[dateRange.length - 1].date,
1974
- // resource_ids: targetProductData.product_resource?.resources?.map((n: any) => n.id),
1975
- // },
1976
- // });
1937
+ if (!(dateRange == null ? void 0 : dateRange.length))
1938
+ return;
1977
1939
  this.getAvailableDate({
1978
1940
  startDate: dateRange[0].date,
1979
1941
  endDate: dateRange[dateRange.length - 1].date,
@@ -1986,9 +1948,8 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1986
1948
  if (this.store.currentProductMeta) {
1987
1949
  this.store.currentProductMeta.schedule = [];
1988
1950
  }
1989
- this.store.currentProduct = undefined;
1951
+ this.store.currentProduct = void 0;
1990
1952
  }
1991
-
1992
1953
  // 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
1993
1954
  getTimeslotBySchedule({
1994
1955
  date,
@@ -1996,43 +1957,59 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
1996
1957
  resources,
1997
1958
  product
1998
1959
  }) {
1960
+ var _a, _b, _c, _d;
1999
1961
  const targetProduct = this.store.currentProduct;
2000
- // 如果外面传递了product 优先用外面的
2001
1962
  const targetProductData = product || targetProduct;
2002
1963
  let targetSchedules = [];
2003
- // 如果外面传递了 scheduleIds,优先取入参
2004
- if (scheduleIds?.length) {
1964
+ if (scheduleIds == null ? void 0 : scheduleIds.length) {
2005
1965
  targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
2006
1966
  } else {
2007
- targetSchedules = this.store.schedule.getScheduleListByIds(targetProductData['schedule.ids']);
1967
+ targetSchedules = this.store.schedule.getScheduleListByIds(
1968
+ targetProductData["schedule.ids"]
1969
+ );
2008
1970
  }
2009
1971
  const resourcesDates = this.store.date.getDateList();
2010
- const targetResourceDate = resourcesDates.find(n => n.date === date);
2011
- const cartItems = (0, _lodashEs.cloneDeep)(this.store.cart.getItems());
2012
- const resourcesMap = (0, _utils2.getResourcesMap)(targetResourceDate?.resource || []);
2013
- const selectedResources = (0, _resources.getOthersSelectedResources)(cartItems, '', resourcesMap);
2014
- const productResources = (0, _resources.getResourcesByProduct)(resourcesMap, resources || this.store.currentProduct?.product_resource?.resources || [], selectedResources, 1);
2015
- const minTimeMaxTime = (0, _utils3.calcMinTimeMaxTimeBySchedules)(targetSchedules, {}, date);
2016
- const scheduleTimeSlots = (0, _utils3.getAllSortedDateRanges)(minTimeMaxTime);
2017
- // 当前所有待选择资源的集合,先提出来,提升性能
2018
- let allProductResources = productResources.flatMap(n => n.renderList);
2019
- // 资源排下序,把单个资源靠前,组合资源排在后面
1972
+ const targetResourceDate = resourcesDates.find((n) => n.date === date);
1973
+ const cartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
1974
+ const resourcesMap = (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []);
1975
+ const selectedResources = (0, import_resources.getOthersSelectedResources)(
1976
+ cartItems,
1977
+ "",
1978
+ resourcesMap
1979
+ );
1980
+ const productResources = (0, import_resources.getResourcesByProduct)(
1981
+ resourcesMap,
1982
+ resources || ((_b = (_a = this.store.currentProduct) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
1983
+ selectedResources,
1984
+ 1
1985
+ );
1986
+ const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
1987
+ targetSchedules,
1988
+ {},
1989
+ date
1990
+ );
1991
+ const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
1992
+ let allProductResources = productResources.flatMap((n) => n.renderList);
2020
1993
  allProductResources.sort((a, b) => {
2021
- const aIsCombined = a.metadata?.combined_resource?.status === 1;
2022
- const bIsCombined = b.metadata?.combined_resource?.status === 1;
2023
- if (aIsCombined && !bIsCombined) return 1;
2024
- if (!aIsCombined && bIsCombined) return -1;
1994
+ var _a2, _b2, _c2, _d2;
1995
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
1996
+ const bIsCombined = ((_d2 = (_c2 = b.metadata) == null ? void 0 : _c2.combined_resource) == null ? void 0 : _d2.status) === 1;
1997
+ if (aIsCombined && !bIsCombined)
1998
+ return 1;
1999
+ if (!aIsCombined && bIsCombined)
2000
+ return -1;
2025
2001
  return 0;
2026
2002
  });
2027
- const enabledResourceTypeConfigs = targetProductData?.product_resource?.resources?.filter(n => n.status === 1) || [];
2028
- const resourceTypeConfigById = new Map(enabledResourceTypeConfigs.map(n => [n.id, n]));
2029
-
2030
- // 计算每个日程切片下日程可用的资源的容量总和
2031
- const formatScheduleTimeSlots = scheduleTimeSlots.map(item => {
2032
- // 用来计算资源的可使用情况,针对单个schedule 时间片
2003
+ const enabledResourceTypeConfigs = ((_d = (_c = targetProductData == null ? void 0 : targetProductData.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.filter(
2004
+ (n) => n.status === 1
2005
+ )) || [];
2006
+ const resourceTypeConfigById = new Map(
2007
+ enabledResourceTypeConfigs.map((n) => [n.id, n])
2008
+ );
2009
+ const formatScheduleTimeSlots = scheduleTimeSlots.map((item) => {
2033
2010
  const resourcesUseableMap = {};
2034
2011
  const statsByResourceType = {};
2035
- enabledResourceTypeConfigs.forEach(cfg => {
2012
+ enabledResourceTypeConfigs.forEach((cfg) => {
2036
2013
  statsByResourceType[cfg.id] = {
2037
2014
  count: 0,
2038
2015
  left: 0,
@@ -2040,68 +2017,59 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2040
2017
  summaryConfigCount: 0
2041
2018
  };
2042
2019
  });
2043
-
2044
- // 遍历所有资源
2045
- allProductResources?.forEach(m => {
2020
+ allProductResources == null ? void 0 : allProductResources.forEach((m) => {
2046
2021
  const currentResourceTypeConfig = resourceTypeConfigById.get(m.form_id);
2047
- if (!currentResourceTypeConfig) return;
2048
-
2049
- // 遍历所有资源的上工时间片
2022
+ if (!currentResourceTypeConfig)
2023
+ return;
2050
2024
  let currentResourceMaxRemainingCapacity = 0;
2051
2025
  let isAllTimeSlicesUsable = true;
2052
- // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2053
- // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2054
- // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2055
-
2056
- // n.start_at 是 2025-06-30 15:00 end_at 2025-06-30 17:00
2057
- // item.start 是 2025-06-30 16:00 item.end 是 2025-06-30 19:00
2058
- // 需要判断 n.start_at 和 n.end_at 是否在 item.start 和 item.end 之间
2059
- // 如果是仅用于计算的资源, n.start_at 和 n.end_at 在 item.start 和 item.end 有交集,则此时间需要计算
2060
- // https://project.feishu.cn/v2qint/bug/detail/6657165010
2061
- const mTimes = m.times.filter(n => {
2062
- return !(0, _dayjs.default)(n.start_at).isAfter((0, _dayjs.default)(item.start), 'minute') && !(0, _dayjs.default)(n.end_at).isBefore((0, _dayjs.default)(item.end), 'minute') || m.onlyComputed && (0, _dayjs.default)(n.start_at).isBefore((0, _dayjs.default)(item.end), 'minute') && (0, _dayjs.default)(n.end_at).isAfter((0, _dayjs.default)(item.start), 'minute');
2026
+ const mTimes = m.times.filter((n) => {
2027
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || m.onlyComputed && (0, import_dayjs.default)(n.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
2063
2028
  });
2064
- // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2065
2029
  if (mTimes.length === 0) {
2066
2030
  return;
2067
2031
  }
2068
-
2069
- // 统计该资源类型在这个时间片的“配置容量”(无占用),只统计上工的资源
2070
2032
  if (!m.onlyComputed) {
2071
- const currentStats = statsByResourceType[m.form_id] || {
2033
+ const currentStats2 = statsByResourceType[m.form_id] || {
2072
2034
  count: 0,
2073
2035
  left: 0,
2074
2036
  summaryCount: 0,
2075
2037
  summaryConfigCount: 0
2076
2038
  };
2077
- if (currentResourceTypeConfig.type === 'multiple') currentStats.summaryConfigCount += m.capacity;else currentStats.summaryConfigCount += 1;
2078
- statsByResourceType[m.form_id] = currentStats;
2039
+ if (currentResourceTypeConfig.type === "multiple")
2040
+ currentStats2.summaryConfigCount += m.capacity;
2041
+ else
2042
+ currentStats2.summaryConfigCount += 1;
2043
+ statsByResourceType[m.form_id] = currentStats2;
2079
2044
  }
2080
- mTimes.forEach(childTiem => {
2081
- // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
2082
- const res = (0, _resources.getIsUsableByTimeItem)({
2045
+ mTimes.forEach((childTiem) => {
2046
+ const res = (0, import_resources.getIsUsableByTimeItem)({
2083
2047
  timeSlice: {
2084
2048
  start_time: item.start,
2085
2049
  end_time: item.end,
2086
- start_at: (0, _dayjs.default)(item.start),
2087
- end_at: (0, _dayjs.default)(item.end)
2050
+ start_at: (0, import_dayjs.default)(item.start),
2051
+ end_at: (0, import_dayjs.default)(item.end)
2088
2052
  },
2089
2053
  time: childTiem,
2090
2054
  resource: m,
2091
2055
  currentCount: 1,
2092
2056
  resourcesUseableMap,
2093
- cut_off_time: targetProductData?.cut_off_time
2057
+ cut_off_time: targetProductData == null ? void 0 : targetProductData.cut_off_time
2094
2058
  });
2095
- if (resourcesUseableMap?.[m.id] !== false && res.reason !== 'capacityOnly') {
2059
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
2096
2060
  resourcesUseableMap[m.id] = res.usable;
2097
2061
  }
2098
- if (!res.usable) isAllTimeSlicesUsable = false;
2062
+ if (!res.usable)
2063
+ isAllTimeSlicesUsable = false;
2099
2064
  if (res.usable && !m.onlyComputed) {
2100
- if (res.remainingCapacity > currentResourceMaxRemainingCapacity) currentResourceMaxRemainingCapacity = res.remainingCapacity;
2065
+ if (res.remainingCapacity > currentResourceMaxRemainingCapacity)
2066
+ currentResourceMaxRemainingCapacity = res.remainingCapacity;
2101
2067
  }
2102
2068
  });
2103
- if (!isAllTimeSlicesUsable) return;
2104
- if (m.onlyComputed) return;
2069
+ if (!isAllTimeSlicesUsable)
2070
+ return;
2071
+ if (m.onlyComputed)
2072
+ return;
2105
2073
  const currentStats = statsByResourceType[m.form_id] || {
2106
2074
  count: 0,
2107
2075
  left: 0,
@@ -2109,61 +2077,55 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2109
2077
  summaryConfigCount: 0
2110
2078
  };
2111
2079
  currentStats.left += 1;
2112
- if (currentResourceTypeConfig.type === 'multiple') {
2080
+ if (currentResourceTypeConfig.type === "multiple") {
2113
2081
  currentStats.summaryCount += currentResourceMaxRemainingCapacity;
2114
2082
  }
2115
- if (currentResourceMaxRemainingCapacity > currentStats.count) currentStats.count = currentResourceMaxRemainingCapacity;
2116
- // else {
2117
- // 单个预约:一个资源只计 1,不关心剩余容量
2118
- // currentStats.summaryCount += 1;
2119
- // if (currentStats.count < 1) currentStats.count = 1;
2120
- //}
2121
-
2083
+ if (currentResourceMaxRemainingCapacity > currentStats.count)
2084
+ currentStats.count = currentResourceMaxRemainingCapacity;
2122
2085
  statsByResourceType[m.form_id] = currentStats;
2123
2086
  });
2124
- // 容量检测
2125
- const cartItems = this.store.cart.getItems();
2126
- productResources.forEach(n => {
2087
+ const cartItems2 = this.store.cart.getItems();
2088
+ productResources.forEach((n) => {
2127
2089
  const currentResourceTypeConfig = resourceTypeConfigById.get(n.id);
2128
- if (!currentResourceTypeConfig) return;
2090
+ if (!currentResourceTypeConfig)
2091
+ return;
2129
2092
  const currentStats = statsByResourceType[n.id] || {
2130
2093
  count: 0,
2131
2094
  left: 0,
2132
2095
  summaryCount: 0
2133
2096
  };
2134
-
2135
- // 单个预约检测规则:
2136
- // 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
2137
- // 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
2138
- if (n.type === 'single') {
2139
- const currentResourcesSet = new Set([...n.optional_resource, ...n.default_resource]);
2140
- // 规则 1
2141
- const sameCartItems = cartItems.filter(m => m._productOrigin?.id?.toString() === targetProductData?.id?.toString() && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
2097
+ if (n.type === "single") {
2098
+ const currentResourcesSet = /* @__PURE__ */ new Set([...n.optional_resource, ...n.default_resource]);
2099
+ const sameCartItems = cartItems2.filter((m) => {
2100
+ var _a2, _b2, _c2;
2101
+ return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) === ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
2102
+ });
2142
2103
  if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > currentStats.left) {
2143
2104
  currentStats.left = 0;
2144
2105
  currentStats.count = 0;
2145
2106
  currentStats.summaryCount = 0;
2146
2107
  }
2147
- // 规则 2
2148
- let otherCartItems = cartItems.filter(m => {
2149
- const isTimeMatch = m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
2150
- const isResourceMatch = m._productOrigin?.product_resource?.resources?.find(m => m.type === n.type && m.status === 1);
2151
- return isTimeMatch && isResourceMatch;
2152
- });
2153
- otherCartItems.forEach(m => {
2154
- const sameTypeResources = m._productOrigin?.product_resource?.resources?.find(m => m.type === n.type && m.status === 1);
2155
- const sameTypeResourcesSet = new Set([...(sameTypeResources?.optional_resource || []), ...(sameTypeResources?.default_resource || [])]);
2156
- // 把sameTypeResourcesSet 加到currentResourcesSet
2157
- sameTypeResourcesSet.forEach(resource => currentResourcesSet.add(resource));
2108
+ let otherCartItems = cartItems2.filter(
2109
+ (m) => {
2110
+ var _a2, _b2, _c2, _d2, _e, _f;
2111
+ const isTimeMatch = ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) !== ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
2112
+ const isResourceMatch = (_f = (_e = (_d2 = m._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e.resources) == null ? void 0 : _f.find((m2) => m2.type === n.type && m2.status === 1);
2113
+ return isTimeMatch && isResourceMatch;
2114
+ }
2115
+ );
2116
+ otherCartItems.forEach((m) => {
2117
+ var _a2, _b2, _c2;
2118
+ const sameTypeResources = (_c2 = (_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.find((m2) => m2.type === n.type && m2.status === 1);
2119
+ const sameTypeResourcesSet = /* @__PURE__ */ new Set([...(sameTypeResources == null ? void 0 : sameTypeResources.optional_resource) || [], ...(sameTypeResources == null ? void 0 : sameTypeResources.default_resource) || []]);
2120
+ sameTypeResourcesSet.forEach((resource) => currentResourcesSet.add(resource));
2158
2121
  });
2159
- // 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
2160
- const currentDataResources = this.store.date.getResourcesListByDate((0, _dayjs.default)(item.start).format('YYYY-MM-DD'));
2161
- currentDataResources?.forEach(m => {
2122
+ const currentDataResources = this.store.date.getResourcesListByDate((0, import_dayjs.default)(item.start).format("YYYY-MM-DD"));
2123
+ currentDataResources == null ? void 0 : currentDataResources.forEach((m) => {
2162
2124
  if (currentResourcesSet.has(m.id)) {
2163
- const mTimes = m.times.filter(n => {
2164
- return !(0, _dayjs.default)(n.start_at).isAfter((0, _dayjs.default)(item.start), 'minute') && !(0, _dayjs.default)(n.end_at).isBefore((0, _dayjs.default)(item.end), 'minute') || (0, _dayjs.default)(n.start_at).isBefore((0, _dayjs.default)(item.end), 'minute') && (0, _dayjs.default)(n.end_at).isAfter((0, _dayjs.default)(item.start), 'minute');
2125
+ const mTimes = m.times.filter((n2) => {
2126
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
2165
2127
  });
2166
- if (!mTimes.length || mTimes.some(n => n.event_list.length)) {
2128
+ if (!mTimes.length || mTimes.some((n2) => n2.event_list.length)) {
2167
2129
  currentResourcesSet.delete(m.id);
2168
2130
  }
2169
2131
  }
@@ -2174,61 +2136,57 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2174
2136
  currentStats.summaryCount = 0;
2175
2137
  }
2176
2138
  } else {
2177
- // 多个预约的检测规则:
2178
- // 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
2179
- const sameCartItems = cartItems.filter(m => m._productOrigin?.id?.toString() === targetProductData?.id?.toString() && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
2180
- const sameCartNeedCapacity = sameCartItems.reduce((acc, curr) => acc + (0, _capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
2139
+ const sameCartItems = cartItems2.filter((m) => {
2140
+ var _a2, _b2, _c2;
2141
+ return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) === ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
2142
+ });
2143
+ const sameCartNeedCapacity = sameCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
2181
2144
  const currentProductResourcesCapacity = n.renderList.reduce((acc, curr) => !curr.onlyComputed ? acc + curr.capacity || 0 : acc, 0);
2182
2145
  if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2183
2146
  currentStats.left = 0;
2184
2147
  currentStats.count = 0;
2185
2148
  currentStats.summaryCount = 0;
2186
2149
  }
2187
- // 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
2188
- // const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
2189
- const otherSameTimesCartItems = cartItems.filter(m => `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
2190
- const otherCartNeedCapacity = otherSameTimesCartItems.reduce((acc, curr) => acc + (0, _capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
2191
- const allRenderList = [...n.renderList.filter(m => !m.onlyComputed)];
2192
- otherSameTimesCartItems.forEach(m => {
2193
- const productResources = (0, _resources.getResourcesByProduct)((0, _utils2.getResourcesMap)(targetResourceDate?.resource || []), m._productOrigin?.product_resource?.resources || [], selectedResources, 1);
2194
- productResources.forEach(m => {
2195
- if (m.id === n.id) {
2196
- m.renderList.forEach(n => {
2197
- if (!n.onlyComputed && !allRenderList.find(m => m.id === n.id)) {
2198
- allRenderList.push(n);
2150
+ const otherSameTimesCartItems = cartItems2.filter((m) => `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
2151
+ const otherCartNeedCapacity = otherSameTimesCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
2152
+ const allRenderList = [...n.renderList.filter((m) => !m.onlyComputed)];
2153
+ otherSameTimesCartItems.forEach((m) => {
2154
+ var _a2, _b2;
2155
+ const productResources2 = (0, import_resources.getResourcesByProduct)(
2156
+ (0, import_utils2.getResourcesMap)((targetResourceDate == null ? void 0 : targetResourceDate.resource) || []),
2157
+ ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) || [],
2158
+ selectedResources,
2159
+ 1
2160
+ );
2161
+ productResources2.forEach((m2) => {
2162
+ if (m2.id === n.id) {
2163
+ m2.renderList.forEach((n2) => {
2164
+ if (!n2.onlyComputed && !allRenderList.find((m3) => m3.id === n2.id)) {
2165
+ allRenderList.push(n2);
2199
2166
  }
2200
2167
  });
2201
2168
  }
2202
2169
  });
2203
2170
  });
2204
2171
  const currentTypeResourcesCapacity = allRenderList.reduce((acc, curr) => acc + curr.capacity || 0, 0);
2205
- // 计算当前时间段内所有资源的已使用容量
2206
2172
  const usedCapacity = allRenderList.reduce((acc, curr) => {
2207
- const mTimes = curr.times.filter(n => {
2208
- return !(0, _dayjs.default)(n.start_at).isAfter((0, _dayjs.default)(item.start), 'minute') && !(0, _dayjs.default)(n.end_at).isBefore((0, _dayjs.default)(item.end), 'minute') || (0, _dayjs.default)(n.start_at).isBefore((0, _dayjs.default)(item.end), 'minute') && (0, _dayjs.default)(n.end_at).isAfter((0, _dayjs.default)(item.start), 'minute');
2173
+ const mTimes = curr.times.filter((n2) => {
2174
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
2209
2175
  });
2210
- // 这里为什么要设置个 map,因为有可能日程有重叠,所以要把重叠的 event_list 去除
2211
- const mSet = new Map();
2212
- mTimes.forEach(n => {
2213
- // acc += n.event_list?.reduce((acc: any, curr: any) => acc + curr.pax, 0);
2214
- // mSet.set(n)
2215
- n.event_list.forEach(m => {
2216
- // 需要确认 m 的时间段是否和 item 的时间段有交集
2217
- if ((0, _resources.isConflict)({
2218
- start_at: m.start_at,
2219
- end_at: m.end_at
2220
- }, {
2221
- start_at: (0, _dayjs.default)(item.start),
2222
- end_at: (0, _dayjs.default)(item.end)
2223
- })) {
2176
+ const mSet = /* @__PURE__ */ new Map();
2177
+ mTimes.forEach((n2) => {
2178
+ n2.event_list.forEach((m) => {
2179
+ if ((0, import_resources.isConflict)(
2180
+ { start_at: m.start_at, end_at: m.end_at },
2181
+ { start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
2182
+ )) {
2224
2183
  mSet.set(m.id, m.pax ?? 1);
2225
2184
  }
2226
2185
  });
2227
2186
  });
2228
- acc += Array.from(mSet.values()).reduce((acc, curr) => acc + curr, 0);
2187
+ acc += Array.from(mSet.values()).reduce((acc2, curr2) => acc2 + curr2, 0);
2229
2188
  return acc;
2230
2189
  }, 0);
2231
- // 如果已使用容量超过了当前类型资源的容量,则不可用
2232
2190
  if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2233
2191
  currentStats.left = 0;
2234
2192
  currentStats.count = 0;
@@ -2237,48 +2195,55 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2237
2195
  }
2238
2196
  statsByResourceType[n.id] = currentStats;
2239
2197
  });
2240
- const startDayJs = (0, _dayjs.default)(item.start);
2241
- const endDayJs = (0, _dayjs.default)(item.end);
2242
-
2243
- // 选择“瓶颈资源类型”:multiple 取 summaryCount 最小,single 取 left 最小
2198
+ const startDayJs = (0, import_dayjs.default)(item.start);
2199
+ const endDayJs = (0, import_dayjs.default)(item.end);
2244
2200
  let bottleneckResourceTypeId;
2245
2201
  let bottleneckValue = Infinity;
2246
- enabledResourceTypeConfigs.forEach(cfg => {
2202
+ enabledResourceTypeConfigs.forEach((cfg) => {
2247
2203
  const stats = statsByResourceType[cfg.id] || {
2248
2204
  count: 0,
2249
2205
  left: 0,
2250
2206
  summaryCount: 0,
2251
2207
  summaryConfigCount: 0
2252
2208
  };
2253
- const value = cfg.type === 'multiple' ? stats.summaryCount : stats.left;
2209
+ const value = cfg.type === "multiple" ? stats.summaryCount : stats.left;
2254
2210
  if (value < bottleneckValue) {
2255
2211
  bottleneckValue = value;
2256
2212
  bottleneckResourceTypeId = cfg.id;
2257
2213
  }
2258
2214
  });
2259
- const bottleneckStats = bottleneckResourceTypeId !== undefined ? statsByResourceType[bottleneckResourceTypeId] || {
2215
+ const bottleneckStats = bottleneckResourceTypeId !== void 0 ? statsByResourceType[bottleneckResourceTypeId] || {
2260
2216
  count: 0,
2261
2217
  left: 0,
2262
2218
  summaryCount: 0,
2263
2219
  summaryConfigCount: 0
2264
- } : {
2265
- count: 0,
2266
- left: 0,
2267
- summaryCount: 0,
2268
- summaryConfigCount: 0
2269
- };
2270
- const bottleneckConfig = bottleneckResourceTypeId !== undefined ? resourceTypeConfigById.get(bottleneckResourceTypeId) : undefined;
2271
- let status = 'sold_out';
2272
- if (bottleneckStats.left === 0) status = 'sold_out';else if (!bottleneckConfig || bottleneckStats.summaryConfigCount === 0) status = 'sold_out';else if (bottleneckConfig.type === 'multiple') {
2220
+ } : { count: 0, left: 0, summaryCount: 0, summaryConfigCount: 0 };
2221
+ const bottleneckConfig = bottleneckResourceTypeId !== void 0 ? resourceTypeConfigById.get(bottleneckResourceTypeId) : void 0;
2222
+ let status = "sold_out";
2223
+ if (bottleneckStats.left === 0)
2224
+ status = "sold_out";
2225
+ else if (!bottleneckConfig || bottleneckStats.summaryConfigCount === 0)
2226
+ status = "sold_out";
2227
+ else if (bottleneckConfig.type === "multiple") {
2273
2228
  const usageRatio = bottleneckStats.summaryCount / bottleneckStats.summaryConfigCount;
2274
- if (usageRatio > 0.5) status = 'lots_of_space';else if (bottleneckStats.summaryCount > 0) status = 'filling_up_fast';else status = 'sold_out';
2229
+ if (usageRatio > 0.5)
2230
+ status = "lots_of_space";
2231
+ else if (bottleneckStats.summaryCount > 0)
2232
+ status = "filling_up_fast";
2233
+ else
2234
+ status = "sold_out";
2275
2235
  } else {
2276
2236
  const usageRatio = bottleneckStats.left / bottleneckStats.summaryConfigCount;
2277
- if (usageRatio > 0.5) status = 'lots_of_space';else if (bottleneckStats.count > 0) status = 'filling_up_fast';else status = 'sold_out';
2237
+ if (usageRatio > 0.5)
2238
+ status = "lots_of_space";
2239
+ else if (bottleneckStats.count > 0)
2240
+ status = "filling_up_fast";
2241
+ else
2242
+ status = "sold_out";
2278
2243
  }
2279
2244
  return {
2280
- start_time: startDayJs.format('HH:mm'),
2281
- end_time: endDayJs.format('HH:mm'),
2245
+ start_time: startDayJs.format("HH:mm"),
2246
+ end_time: endDayJs.format("HH:mm"),
2282
2247
  start_at: startDayJs,
2283
2248
  end_at: endDayJs,
2284
2249
  count: bottleneckStats.count,
@@ -2289,7 +2254,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2289
2254
  });
2290
2255
  return formatScheduleTimeSlots;
2291
2256
  }
2292
-
2293
2257
  // 提供给 UI的方法,当前步骤是选择商品,下一步不管是什么都需要在这里做一次检测
2294
2258
  // 时长类商品关联的资源为多个预约时,在点击进入"选择资源"步骤之前,需要检测当前所有资源的总容量
2295
2259
  // 选择商品数量大于所有资源配置的总容量时,不能进入下一步,需要在"选择商品"这一步时提示。
@@ -2298,27 +2262,27 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2298
2262
  * 找到多个资源的公共可用时间段
2299
2263
  */
2300
2264
  findCommonAvailableTimeSlots(resources) {
2301
- if (resources.length === 0) return [];
2302
- // 收集所有资源的时间段,转换为统一的时间格式
2303
- const allTimeSlots = resources.map(resource => resource.times.map(time => ({
2304
- start: (0, _dayjs.default)(time.start_at),
2305
- end: (0, _dayjs.default)(time.end_at)
2306
- })));
2307
- // 找到公共时间段的交集
2308
- let commonSlots = allTimeSlots[0]; // 从第一个资源的时间段开始
2309
-
2310
- // 与其他资源的时间段求交集
2265
+ if (resources.length === 0)
2266
+ return [];
2267
+ console.log(`计算 ${resources.length} 个资源的公共时间段`);
2268
+ const allTimeSlots = resources.map(
2269
+ (resource) => resource.times.map((time) => ({
2270
+ start: (0, import_dayjs.default)(time.start_at),
2271
+ end: (0, import_dayjs.default)(time.end_at)
2272
+ }))
2273
+ );
2274
+ console.log("所有资源的时间段:", allTimeSlots.map(
2275
+ (slots) => slots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`)
2276
+ ));
2277
+ let commonSlots = allTimeSlots[0];
2278
+ console.log("初始公共时间段:", commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
2311
2279
  for (let i = 1; i < allTimeSlots.length; i++) {
2312
2280
  const currentResourceSlots = allTimeSlots[i];
2313
2281
  const intersections = [];
2314
-
2315
- // 计算当前公共时间段与下一个资源时间段的交集
2316
- commonSlots.forEach(commonSlot => {
2317
- currentResourceSlots.forEach(currentSlot => {
2282
+ commonSlots.forEach((commonSlot) => {
2283
+ currentResourceSlots.forEach((currentSlot) => {
2318
2284
  const overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
2319
2285
  const overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
2320
-
2321
- // 如果有重叠时间且重叠时间大于0
2322
2286
  if (overlapStart.isBefore(overlapEnd)) {
2323
2287
  intersections.push({
2324
2288
  start: overlapStart,
@@ -2328,88 +2292,74 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2328
2292
  });
2329
2293
  });
2330
2294
  if (intersections.length === 0) {
2295
+ console.log(`资源${i}与当前公共时间段无交集,跳过该资源`);
2331
2296
  continue;
2332
2297
  }
2333
2298
  commonSlots = intersections;
2299
+ console.log(`与资源${i}求交集后的公共时间段:`, commonSlots.map((slot) => `${slot.start.format("HH:mm")}-${slot.end.format("HH:mm")}`));
2334
2300
  }
2335
-
2336
- // 格式化返回结果
2337
- const result = commonSlots.map(slot => ({
2338
- startTime: slot.start.format('HH:mm'),
2339
- endTime: slot.end.format('HH:mm')
2301
+ const result = commonSlots.map((slot) => ({
2302
+ startTime: slot.start.format("HH:mm"),
2303
+ endTime: slot.end.format("HH:mm")
2340
2304
  }));
2305
+ console.log("最终公共时间段:", result);
2341
2306
  return result;
2342
2307
  }
2343
2308
  checkMaxDurationCapacity() {
2344
- const cartItems = this.store.cart.getItems().filter(item => !(0, _utils5.isNormalProduct)(item._productOrigin));
2345
- if (cartItems.length === 0) return {
2346
- success: true,
2347
- minAvailableCount: 0
2348
- };
2349
-
2350
- // 将购物车商品分为有时间的和没有时间的
2309
+ var _a, _b;
2310
+ const cartItems = this.store.cart.getItems().filter((item) => !(0, import_utils5.isNormalProduct)(item._productOrigin));
2311
+ if (cartItems.length === 0)
2312
+ return { success: true, minAvailableCount: 0 };
2351
2313
  const itemsWithTime = [];
2352
2314
  const itemsWithoutTime = [];
2353
- // 记录每种资源类型的可用数量
2354
2315
  const availableCountsByResourceType = [];
2355
- cartItems.forEach(cartItem => {
2316
+ cartItems.forEach((cartItem) => {
2356
2317
  if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
2357
2318
  itemsWithTime.push(cartItem);
2358
2319
  } else {
2359
2320
  itemsWithoutTime.push(cartItem);
2360
2321
  }
2361
2322
  });
2362
-
2363
- // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
2364
2323
  const processedItemsWithoutTime = [];
2365
2324
  if (itemsWithoutTime.length > 0) {
2366
- // 按资源类型分组处理没有时间的商品
2367
2325
  const itemsByResourceType = {};
2368
- itemsWithoutTime.forEach(cartItem => {
2369
- if (!cartItem._productOrigin) return;
2370
- const resourceTypes = cartItem._productOrigin.product_resource?.resources || [];
2371
- resourceTypes.forEach(resourceType => {
2326
+ itemsWithoutTime.forEach((cartItem) => {
2327
+ var _a2;
2328
+ if (!cartItem._productOrigin)
2329
+ return;
2330
+ const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
2331
+ resourceTypes.forEach((resourceType) => {
2332
+ var _a3;
2372
2333
  if (resourceType.status === 1) {
2373
- const resourceCode = resourceType.code || resourceType.id?.toString();
2334
+ const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
2374
2335
  if (!itemsByResourceType[resourceCode]) {
2375
2336
  itemsByResourceType[resourceCode] = [];
2376
2337
  }
2377
- // 避免重复添加同一个商品
2378
- // 如果之前添加过的依赖相同资源的跟我现在是同一个 holder,也不需要重复添加
2379
- if (itemsByResourceType[resourceCode].find(item => item.holder_id === cartItem.holder_id)) {
2338
+ if (itemsByResourceType[resourceCode].find((item) => item.holder_id === cartItem.holder_id)) {
2380
2339
  return;
2381
2340
  }
2382
- if (!itemsByResourceType[resourceCode].find(item => item._id === cartItem._id)) {
2341
+ if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
2383
2342
  itemsByResourceType[resourceCode].push(cartItem);
2384
2343
  }
2385
2344
  }
2386
2345
  });
2387
2346
  });
2388
-
2389
- // 为每种资源类型检查容量
2390
2347
  const dateRange = this.store.date.getDateRange();
2391
- if (!dateRange || dateRange.length === 0) return {
2392
- success: false,
2393
- minAvailableCount: 0
2394
- };
2348
+ if (!dateRange || dateRange.length === 0)
2349
+ return { success: false, minAvailableCount: 0 };
2395
2350
  const resourcesDates = this.store.date.getDateList();
2396
- const targetResourceDate = resourcesDates.find(n => n.date === dateRange[0].date);
2397
- if (!targetResourceDate) return {
2398
- success: false,
2399
- minAvailableCount: 0
2400
- };
2401
- const resourcesMap = (0, _utils2.getResourcesMap)(targetResourceDate.resource || []);
2402
-
2403
- // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
2351
+ const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
2352
+ if (!targetResourceDate)
2353
+ return { success: false, minAvailableCount: 0 };
2354
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2404
2355
  const resourceCodeToFormIdMap = {};
2405
-
2406
- // 遍历购物车中的商品,收集所有资源类型配置
2407
- Object.values(itemsByResourceType).flat().forEach(cartItem => {
2408
- if (cartItem._productOrigin?.product_resource?.resources) {
2409
- cartItem._productOrigin.product_resource.resources.forEach(resourceConfig => {
2410
- // 只处理启用的资源类型 (status === 1)
2356
+ Object.values(itemsByResourceType).flat().forEach((cartItem) => {
2357
+ var _a2, _b2;
2358
+ if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
2359
+ cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
2360
+ var _a3, _b3;
2411
2361
  if (resourceConfig.status === 1 && resourceConfig.code) {
2412
- const formId = resourceConfig.id?.toString() || resourceConfig.resource_type_id?.toString();
2362
+ const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
2413
2363
  if (formId) {
2414
2364
  resourceCodeToFormIdMap[resourceConfig.code] = formId;
2415
2365
  }
@@ -2419,77 +2369,60 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2419
2369
  });
2420
2370
  let hasCapacityIssue = false;
2421
2371
  const resourceCapacityInfo = [];
2422
-
2423
- // 用于跟踪已处理的商品,避免重复添加
2424
- const processedCartItemIds = new Set();
2425
-
2426
- // 先检查所有资源类型,收集可用数量信息
2372
+ const processedCartItemIds = /* @__PURE__ */ new Set();
2427
2373
  for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
2428
- // 获取该资源类型对应的 form_id
2429
2374
  const targetFormId = resourceCodeToFormIdMap[resourceCode];
2430
2375
  if (!targetFormId) {
2431
- return {
2432
- success: false,
2433
- minAvailableCount: 0
2434
- };
2376
+ console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
2377
+ return { success: false, minAvailableCount: 0 };
2435
2378
  }
2436
-
2437
- // 获取该资源类型的所有资源
2438
2379
  const resourcesOfThisType = [];
2439
- items.forEach(cartItem => {
2440
- const productResourceIds = (0, _capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2441
- productResourceIds.forEach(resourceId => {
2380
+ items.forEach((cartItem) => {
2381
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2382
+ productResourceIds.forEach((resourceId) => {
2383
+ var _a2;
2442
2384
  const resource = resourcesMap[resourceId];
2443
- if (resource && resource.form_id?.toString() === targetFormId) {
2444
- // 避免重复添加同一个资源
2445
- if (!resourcesOfThisType.find(r => r.id === resource.id)) {
2385
+ if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
2386
+ if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
2446
2387
  resourcesOfThisType.push(resource);
2447
2388
  }
2448
2389
  }
2449
2390
  });
2450
2391
  });
2451
2392
  if (resourcesOfThisType.length === 0) {
2452
- return {
2453
- success: false,
2454
- minAvailableCount: 0
2455
- };
2393
+ console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
2394
+ return { success: false, minAvailableCount: 0 };
2456
2395
  }
2457
-
2458
- // 检查资源类型(单个预约 vs 多个预约)
2459
- // 从商品配置中获取资源类型信息
2460
2396
  let resourceTypeConfig = null;
2461
2397
  for (const cartItem of items) {
2462
- if (cartItem._productOrigin?.product_resource?.resources) {
2463
- resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(r => r.code === resourceCode && r.status === 1);
2464
- if (resourceTypeConfig) break;
2398
+ if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
2399
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
2400
+ (r) => r.code === resourceCode && r.status === 1
2401
+ );
2402
+ if (resourceTypeConfig)
2403
+ break;
2465
2404
  }
2466
2405
  }
2467
- const isMultipleBooking = resourceTypeConfig?.type === 'multiple';
2406
+ const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
2468
2407
  let totalAvailable;
2469
2408
  let requiredAmount;
2470
2409
  let availableAmount;
2471
2410
  if (isMultipleBooking) {
2472
- // 多个预约:计算容量
2473
2411
  totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
2474
2412
  return sum + (resource.capacity || 0);
2475
2413
  }, 0);
2476
2414
  requiredAmount = items.reduce((sum, cartItem) => {
2477
- const {
2478
- currentCapacity
2479
- } = (0, _capacity.getCapacityInfoByCartItem)(cartItem);
2415
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
2480
2416
  return sum + currentCapacity;
2481
2417
  }, 0);
2482
2418
  availableAmount = Math.max(0, totalAvailable - requiredAmount);
2483
2419
  } else {
2484
- // 单个预约:计算资源个数
2485
2420
  totalAvailable = resourcesOfThisType.length;
2486
2421
  requiredAmount = items.reduce((sum, cartItem) => {
2487
2422
  return sum + (cartItem.num || 1);
2488
2423
  }, 0);
2489
2424
  availableAmount = Math.max(0, totalAvailable - requiredAmount);
2490
2425
  }
2491
-
2492
- // 记录资源容量信息
2493
2426
  resourceCapacityInfo.push({
2494
2427
  code: resourceCode,
2495
2428
  available: availableAmount,
@@ -2498,27 +2431,23 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2498
2431
  isMultiple: isMultipleBooking
2499
2432
  });
2500
2433
  availableCountsByResourceType.push(availableAmount);
2501
-
2502
- // 检查是否有容量问题
2503
2434
  if (requiredAmount > totalAvailable) {
2504
2435
  hasCapacityIssue = true;
2436
+ console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
2505
2437
  }
2506
-
2507
- // 为通过检测的商品分配一个公共可用时间段
2508
-
2509
- // 找到所有资源都可用的时间段
2438
+ console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
2439
+ id: r.id,
2440
+ times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
2441
+ })));
2510
2442
  const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
2443
+ console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
2511
2444
  if (commonTimeSlots.length === 0) {
2512
- return {
2513
- success: false,
2514
- minAvailableCount: 0
2515
- };
2445
+ console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
2446
+ return { success: false, minAvailableCount: 0 };
2516
2447
  }
2517
-
2518
- // 使用第一个公共可用时间段,但只处理未处理过的商品
2519
2448
  const firstCommonSlot = commonTimeSlots[0];
2520
- items.forEach(cartItem => {
2521
- // 只处理未处理过的商品,避免重复添加
2449
+ console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
2450
+ items.forEach((cartItem) => {
2522
2451
  if (!processedCartItemIds.has(cartItem._id)) {
2523
2452
  processedCartItemIds.add(cartItem._id);
2524
2453
  const processedItem = {
@@ -2532,93 +2461,59 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2532
2461
  }
2533
2462
  });
2534
2463
  }
2535
-
2536
- // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
2537
2464
  if (hasCapacityIssue) {
2538
- // 找出超出容量的资源类型中,总容量最少的那个
2539
- const overCapacityResources = resourceCapacityInfo.filter(info => info.required > info.total);
2465
+ const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
2540
2466
  if (overCapacityResources.length > 0) {
2541
- const minTotalCapacity = Math.min(...overCapacityResources.map(info => info.total));
2542
- return {
2543
- success: false,
2544
- minAvailableCount: minTotalCapacity
2545
- };
2467
+ const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
2468
+ return { success: false, minAvailableCount: minTotalCapacity2 };
2546
2469
  }
2547
- // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
2548
- const minTotalCapacity = Math.min(...resourceCapacityInfo.map(info => info.total));
2549
- return {
2550
- success: false,
2551
- minAvailableCount: minTotalCapacity
2552
- };
2470
+ const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
2471
+ return { success: false, minAvailableCount: minTotalCapacity };
2553
2472
  }
2554
2473
  }
2555
-
2556
- // 合并所有商品(有时间的 + 处理后的没有时间的)
2557
2474
  const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
2558
-
2559
- // 按时间段分组检查
2560
2475
  const cartItemsByTimeSlot = {};
2561
- allProcessedItems.forEach(cartItem => {
2562
- if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
2476
+ allProcessedItems.forEach((cartItem) => {
2477
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
2478
+ return;
2563
2479
  const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
2564
2480
  if (!cartItemsByTimeSlot[timeSlotKey]) {
2565
2481
  cartItemsByTimeSlot[timeSlotKey] = [];
2566
2482
  }
2567
2483
  cartItemsByTimeSlot[timeSlotKey].push(cartItem);
2568
2484
  });
2569
- // 检查每个时间段是否有足够的资源容量
2570
2485
  for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
2571
- const [startDate, startTime, endDate, endTime] = timeSlotKey.split('_');
2486
+ const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
2572
2487
  const timeSlotStart = `${startDate} ${startTime}`;
2573
2488
  const timeSlotEnd = `${endDate} ${endTime}`;
2574
-
2575
- // 获取这个时间段所有商品涉及的资源
2576
2489
  const allResourcesForTimeSlot = [];
2577
- const resourcesIdSet = new Set();
2578
-
2579
- // 获取资源数据
2490
+ const resourcesIdSet = /* @__PURE__ */ new Set();
2580
2491
  const dateRange = this.store.date.getDateRange();
2581
2492
  const resourcesDates = this.store.date.getDateList();
2582
- const targetResourceDate = resourcesDates.find(n => n.date === startDate);
2583
- if (!targetResourceDate) continue;
2584
- const resourcesMap = (0, _utils2.getResourcesMap)(targetResourceDate.resource || []);
2585
- itemsInTimeSlot.forEach(cartItem => {
2586
- if (!cartItem._productOrigin) return;
2587
-
2588
- // 获取商品的资源配置
2589
- const productResourceIds = (0, _capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2590
- productResourceIds.forEach(resourceId => {
2493
+ const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
2494
+ if (!targetResourceDate)
2495
+ continue;
2496
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2497
+ itemsInTimeSlot.forEach((cartItem) => {
2498
+ if (!cartItem._productOrigin)
2499
+ return;
2500
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2501
+ productResourceIds.forEach((resourceId) => {
2591
2502
  if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
2592
2503
  resourcesIdSet.add(resourceId);
2593
2504
  allResourcesForTimeSlot.push(resourcesMap[resourceId]);
2594
2505
  }
2595
2506
  });
2596
2507
  });
2597
-
2598
- // 按资源类型分组检查容量
2599
- const {
2600
- success,
2601
- required,
2602
- available
2603
- } = (0, _capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
2508
+ const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
2604
2509
  if (!success) {
2605
- // 如果有可用数量记录,返回最小值;否则返回 0
2606
- const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2607
- return {
2608
- success: false,
2609
- minAvailableCount
2610
- };
2510
+ const minAvailableCount2 = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2511
+ return { success: false, minAvailableCount: minAvailableCount2 };
2611
2512
  }
2612
2513
  }
2613
-
2614
- // 全部通过检测,返回成功和最小可用数量
2615
2514
  const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2616
- return {
2617
- success: true,
2618
- minAvailableCount
2619
- };
2515
+ return { success: true, minAvailableCount };
2620
2516
  }
2621
-
2622
2517
  /**
2623
2518
  * 将 ProductData 转换为 CartItem,但不添加到购物车
2624
2519
  * 参考 addProductToCart 方法的实现
@@ -2635,34 +2530,21 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2635
2530
  product_variant_id,
2636
2531
  quantity = 1
2637
2532
  } = product || {};
2638
-
2639
- // 处理商品数据,类似 addProductToCart 中的逻辑
2640
- const productData = {
2641
- ...origin,
2642
- product_variant_id
2643
- };
2644
-
2645
- // 处理组合商品
2646
- const processedProduct = (0, _utils.handleVariantProduct)(productData);
2647
-
2648
- // 如果没有传入账户,获取当前活跃账户
2533
+ const productData = { ...origin, product_variant_id };
2534
+ const processedProduct = (0, import_utils.handleVariantProduct)(productData);
2649
2535
  if (!account) {
2650
2536
  const activeAccount = this.getActiveAccount();
2651
2537
  if (activeAccount) {
2652
2538
  account = activeAccount;
2653
2539
  }
2654
2540
  }
2655
-
2656
- // 创建基础的 CartItem
2657
2541
  const cartItem = {
2658
- _id: (0, _utils.getUniqueId)('temp_'),
2659
- _origin: (0, _utils.createCartItemOrigin)(),
2542
+ _id: (0, import_utils.getUniqueId)("temp_"),
2543
+ _origin: (0, import_utils.createCartItemOrigin)(),
2660
2544
  _productOrigin: processedProduct,
2661
2545
  _productInit: product
2662
2546
  };
2663
-
2664
- // 使用格式化函数填充 CartItem 数据
2665
- (0, _utils.formatProductToCartItem)({
2547
+ (0, import_utils.formatProductToCartItem)({
2666
2548
  cartItem,
2667
2549
  product: processedProduct,
2668
2550
  bundle,
@@ -2670,18 +2552,14 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2670
2552
  product_variant_id,
2671
2553
  quantity
2672
2554
  });
2673
-
2674
- // 如果有日期信息,格式化日期到购物车
2675
2555
  if (date) {
2676
- (0, _utils.formatDateToCartItem)({
2556
+ (0, import_utils.formatDateToCartItem)({
2677
2557
  cartItem,
2678
2558
  date
2679
2559
  });
2680
2560
  }
2681
-
2682
- // 如果有账户信息,格式化账户到购物车
2683
2561
  if (account) {
2684
- (0, _utils.formatAccountToCartItem)({
2562
+ (0, import_utils.formatAccountToCartItem)({
2685
2563
  cartItem,
2686
2564
  account
2687
2565
  });
@@ -2693,79 +2571,59 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2693
2571
  date,
2694
2572
  account
2695
2573
  }) {
2696
- const cartItems = this.store.cart.getItems().filter(item => !(0, _utils5.isNormalProduct)(item._productOrigin));
2697
-
2698
- // 将 ProductData 转换为 CartItem 但不真正添加到购物车
2699
- const currentCartItem = this.convertProductToCartItem({
2700
- product,
2701
- date,
2702
- account
2703
- });
2574
+ var _a, _b;
2575
+ const cartItems = this.store.cart.getItems().filter((item) => !(0, import_utils5.isNormalProduct)(item._productOrigin));
2576
+ const currentCartItem = this.convertProductToCartItem({ product, date, account });
2704
2577
  cartItems.push(currentCartItem);
2705
- if (cartItems.length === 0) return {
2706
- success: true,
2707
- minAvailableCount: 0
2708
- };
2709
-
2710
- // 将购物车商品分为有时间的和没有时间的
2578
+ if (cartItems.length === 0)
2579
+ return { success: true, minAvailableCount: 0 };
2711
2580
  const itemsWithTime = [];
2712
2581
  const itemsWithoutTime = [];
2713
- // 记录每种资源类型的可用数量
2714
2582
  const availableCountsByResourceType = [];
2715
- cartItems.forEach(cartItem => {
2583
+ cartItems.forEach((cartItem) => {
2716
2584
  if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
2717
2585
  itemsWithTime.push(cartItem);
2718
2586
  } else {
2719
2587
  itemsWithoutTime.push(cartItem);
2720
2588
  }
2721
2589
  });
2722
-
2723
- // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
2724
2590
  const processedItemsWithoutTime = [];
2725
2591
  if (itemsWithoutTime.length > 0) {
2726
- // 按资源类型分组处理没有时间的商品
2727
2592
  const itemsByResourceType = {};
2728
- itemsWithoutTime.forEach(cartItem => {
2729
- if (!cartItem._productOrigin) return;
2730
- const resourceTypes = cartItem._productOrigin.product_resource?.resources || [];
2731
- resourceTypes.forEach(resourceType => {
2593
+ itemsWithoutTime.forEach((cartItem) => {
2594
+ var _a2;
2595
+ if (!cartItem._productOrigin)
2596
+ return;
2597
+ const resourceTypes = ((_a2 = cartItem._productOrigin.product_resource) == null ? void 0 : _a2.resources) || [];
2598
+ resourceTypes.forEach((resourceType) => {
2599
+ var _a3;
2732
2600
  if (resourceType.status === 1) {
2733
- const resourceCode = resourceType.code || resourceType.id?.toString();
2601
+ const resourceCode = resourceType.code || ((_a3 = resourceType.id) == null ? void 0 : _a3.toString());
2734
2602
  if (!itemsByResourceType[resourceCode]) {
2735
2603
  itemsByResourceType[resourceCode] = [];
2736
2604
  }
2737
- // 避免重复添加同一个商品
2738
- if (!itemsByResourceType[resourceCode].find(item => item._id === cartItem._id)) {
2605
+ if (!itemsByResourceType[resourceCode].find((item) => item._id === cartItem._id)) {
2739
2606
  itemsByResourceType[resourceCode].push(cartItem);
2740
2607
  }
2741
2608
  }
2742
2609
  });
2743
2610
  });
2744
-
2745
- // 为每种资源类型检查容量
2746
2611
  const dateRange = this.store.date.getDateRange();
2747
- if (!dateRange || dateRange.length === 0) return {
2748
- success: false,
2749
- minAvailableCount: 0
2750
- };
2612
+ if (!dateRange || dateRange.length === 0)
2613
+ return { success: false, minAvailableCount: 0 };
2751
2614
  const resourcesDates = this.store.date.getDateList();
2752
- const targetResourceDate = resourcesDates.find(n => n.date === dateRange[0].date);
2753
- if (!targetResourceDate) return {
2754
- success: false,
2755
- minAvailableCount: 0
2756
- };
2757
- const resourcesMap = (0, _utils2.getResourcesMap)(targetResourceDate.resource || []);
2758
-
2759
- // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
2615
+ const targetResourceDate = resourcesDates.find((n) => n.date === dateRange[0].date);
2616
+ if (!targetResourceDate)
2617
+ return { success: false, minAvailableCount: 0 };
2618
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2760
2619
  const resourceCodeToFormIdMap = {};
2761
-
2762
- // 遍历购物车中的商品,收集所有资源类型配置
2763
- Object.values(itemsByResourceType).flat().forEach(cartItem => {
2764
- if (cartItem._productOrigin?.product_resource?.resources) {
2765
- cartItem._productOrigin.product_resource.resources.forEach(resourceConfig => {
2766
- // 只处理启用的资源类型 (status === 1)
2620
+ Object.values(itemsByResourceType).flat().forEach((cartItem) => {
2621
+ var _a2, _b2;
2622
+ if ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) {
2623
+ cartItem._productOrigin.product_resource.resources.forEach((resourceConfig) => {
2624
+ var _a3, _b3;
2767
2625
  if (resourceConfig.status === 1 && resourceConfig.code) {
2768
- const formId = resourceConfig.id?.toString() || resourceConfig.resource_type_id?.toString();
2626
+ const formId = ((_a3 = resourceConfig.id) == null ? void 0 : _a3.toString()) || ((_b3 = resourceConfig.resource_type_id) == null ? void 0 : _b3.toString());
2769
2627
  if (formId) {
2770
2628
  resourceCodeToFormIdMap[resourceConfig.code] = formId;
2771
2629
  }
@@ -2775,77 +2633,60 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2775
2633
  });
2776
2634
  let hasCapacityIssue = false;
2777
2635
  const resourceCapacityInfo = [];
2778
-
2779
- // 用于跟踪已处理的商品,避免重复添加
2780
- const processedCartItemIds = new Set();
2781
-
2782
- // 先检查所有资源类型,收集可用数量信息
2636
+ const processedCartItemIds = /* @__PURE__ */ new Set();
2783
2637
  for (const [resourceCode, items] of Object.entries(itemsByResourceType)) {
2784
- // 获取该资源类型对应的 form_id
2785
2638
  const targetFormId = resourceCodeToFormIdMap[resourceCode];
2786
2639
  if (!targetFormId) {
2787
- return {
2788
- success: false,
2789
- minAvailableCount: 0
2790
- };
2640
+ console.log(`资源类型 ${resourceCode} 找不到对应的 form_id`);
2641
+ return { success: false, minAvailableCount: 0 };
2791
2642
  }
2792
-
2793
- // 获取该资源类型的所有资源
2794
2643
  const resourcesOfThisType = [];
2795
- items.forEach(cartItem => {
2796
- const productResourceIds = (0, _capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2797
- productResourceIds.forEach(resourceId => {
2644
+ items.forEach((cartItem) => {
2645
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2646
+ productResourceIds.forEach((resourceId) => {
2647
+ var _a2;
2798
2648
  const resource = resourcesMap[resourceId];
2799
- if (resource && resource.form_id?.toString() === targetFormId) {
2800
- // 避免重复添加同一个资源
2801
- if (!resourcesOfThisType.find(r => r.id === resource.id)) {
2649
+ if (resource && ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) === targetFormId) {
2650
+ if (!resourcesOfThisType.find((r) => r.id === resource.id)) {
2802
2651
  resourcesOfThisType.push(resource);
2803
2652
  }
2804
2653
  }
2805
2654
  });
2806
2655
  });
2807
2656
  if (resourcesOfThisType.length === 0) {
2808
- return {
2809
- success: false,
2810
- minAvailableCount: 0
2811
- };
2657
+ console.log(`资源类型 ${resourceCode} 没有找到可用资源`);
2658
+ return { success: false, minAvailableCount: 0 };
2812
2659
  }
2813
-
2814
- // 检查资源类型(单个预约 vs 多个预约)
2815
- // 从商品配置中获取资源类型信息
2816
2660
  let resourceTypeConfig = null;
2817
2661
  for (const cartItem of items) {
2818
- if (cartItem._productOrigin?.product_resource?.resources) {
2819
- resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(r => r.code === resourceCode && r.status === 1);
2820
- if (resourceTypeConfig) break;
2662
+ if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
2663
+ resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
2664
+ (r) => r.code === resourceCode && r.status === 1
2665
+ );
2666
+ if (resourceTypeConfig)
2667
+ break;
2821
2668
  }
2822
2669
  }
2823
- const isMultipleBooking = resourceTypeConfig?.type === 'multiple';
2670
+ const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
2824
2671
  let totalAvailable;
2825
2672
  let requiredAmount;
2826
2673
  let availableAmount;
2827
2674
  if (isMultipleBooking) {
2828
- // 多个预约:计算容量
2829
2675
  totalAvailable = resourcesOfThisType.reduce((sum, resource) => {
2830
2676
  return sum + (resource.capacity || 0);
2831
2677
  }, 0);
2832
2678
  requiredAmount = items.reduce((sum, cartItem) => {
2833
- const {
2834
- currentCapacity
2835
- } = (0, _capacity.getCapacityInfoByCartItem)(cartItem);
2679
+ const { currentCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
2836
2680
  return sum + currentCapacity;
2837
2681
  }, 0);
2838
2682
  availableAmount = Math.max(0, totalAvailable - requiredAmount);
2839
2683
  } else {
2840
- // 单个预约:计算资源个数
2841
2684
  totalAvailable = resourcesOfThisType.length;
2842
2685
  requiredAmount = items.reduce((sum, cartItem) => {
2843
2686
  return sum + (cartItem.num || 1);
2844
2687
  }, 0);
2845
2688
  availableAmount = Math.max(0, totalAvailable - requiredAmount);
2846
2689
  }
2847
-
2848
- // 记录资源容量信息
2849
2690
  resourceCapacityInfo.push({
2850
2691
  code: resourceCode,
2851
2692
  available: availableAmount,
@@ -2854,27 +2695,23 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2854
2695
  isMultiple: isMultipleBooking
2855
2696
  });
2856
2697
  availableCountsByResourceType.push(availableAmount);
2857
-
2858
- // 检查是否有容量问题
2859
2698
  if (requiredAmount > totalAvailable) {
2860
2699
  hasCapacityIssue = true;
2700
+ console.log(`资源类型 ${resourceCode} ${isMultipleBooking ? "容量" : "资源数量"}不足: 需要 ${requiredAmount}, 总共 ${totalAvailable}`);
2861
2701
  }
2862
-
2863
- // 为通过检测的商品分配一个公共可用时间段
2864
-
2865
- // 找到所有资源都可用的时间段
2702
+ console.log(`资源类型 ${resourceCode} 的资源时间信息:`, resourcesOfThisType.map((r) => ({
2703
+ id: r.id,
2704
+ times: r.times.map((t) => `${t.start_at} - ${t.end_at}`)
2705
+ })));
2866
2706
  const commonTimeSlots = this.findCommonAvailableTimeSlots(resourcesOfThisType);
2707
+ console.log(`资源类型 ${resourceCode} 的公共时间段:`, commonTimeSlots);
2867
2708
  if (commonTimeSlots.length === 0) {
2868
- return {
2869
- success: false,
2870
- minAvailableCount: 0
2871
- };
2709
+ console.log(`资源类型 ${resourceCode} 没有公共可用时间段`);
2710
+ return { success: false, minAvailableCount: 0 };
2872
2711
  }
2873
-
2874
- // 使用第一个公共可用时间段,但只处理未处理过的商品
2875
2712
  const firstCommonSlot = commonTimeSlots[0];
2876
- items.forEach(cartItem => {
2877
- // 只处理未处理过的商品,避免重复添加
2713
+ console.log(`使用公共时间段: ${firstCommonSlot.startTime} - ${firstCommonSlot.endTime}`);
2714
+ items.forEach((cartItem) => {
2878
2715
  if (!processedCartItemIds.has(cartItem._id)) {
2879
2716
  processedCartItemIds.add(cartItem._id);
2880
2717
  const processedItem = {
@@ -2888,120 +2725,83 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
2888
2725
  }
2889
2726
  });
2890
2727
  }
2891
-
2892
- // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
2893
2728
  if (hasCapacityIssue) {
2894
- // 找出超出容量的资源类型中,总容量最少的那个
2895
- const overCapacityResources = resourceCapacityInfo.filter(info => info.required > info.total);
2729
+ const overCapacityResources = resourceCapacityInfo.filter((info) => info.required > info.total);
2896
2730
  if (overCapacityResources.length > 0) {
2897
- const minTotalCapacity = Math.min(...overCapacityResources.map(info => info.total));
2898
- return {
2899
- success: false,
2900
- minAvailableCount: minTotalCapacity
2901
- };
2731
+ const minTotalCapacity2 = Math.min(...overCapacityResources.map((info) => info.total));
2732
+ return { success: false, minAvailableCount: minTotalCapacity2 };
2902
2733
  }
2903
- // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
2904
- const minTotalCapacity = Math.min(...resourceCapacityInfo.map(info => info.total));
2905
- return {
2906
- success: false,
2907
- minAvailableCount: minTotalCapacity
2908
- };
2734
+ const minTotalCapacity = Math.min(...resourceCapacityInfo.map((info) => info.total));
2735
+ return { success: false, minAvailableCount: minTotalCapacity };
2909
2736
  }
2910
2737
  }
2911
-
2912
- // 合并所有商品(有时间的 + 处理后的没有时间的)
2913
2738
  const allProcessedItems = [...itemsWithTime, ...processedItemsWithoutTime];
2914
-
2915
- // 按时间段分组检查
2916
2739
  const cartItemsByTimeSlot = {};
2917
- allProcessedItems.forEach(cartItem => {
2918
- if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
2740
+ allProcessedItems.forEach((cartItem) => {
2741
+ if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date)
2742
+ return;
2919
2743
  const timeSlotKey = `${cartItem.start_date}_${cartItem.start_time}_${cartItem.end_date || cartItem.start_date}_${cartItem.end_time}`;
2920
2744
  if (!cartItemsByTimeSlot[timeSlotKey]) {
2921
2745
  cartItemsByTimeSlot[timeSlotKey] = [];
2922
2746
  }
2923
2747
  cartItemsByTimeSlot[timeSlotKey].push(cartItem);
2924
2748
  });
2925
- // 检查每个时间段是否有足够的资源容量
2926
2749
  for (const [timeSlotKey, itemsInTimeSlot] of Object.entries(cartItemsByTimeSlot)) {
2927
- const [startDate, startTime, endDate, endTime] = timeSlotKey.split('_');
2750
+ const [startDate, startTime, endDate, endTime] = timeSlotKey.split("_");
2928
2751
  const timeSlotStart = `${startDate} ${startTime}`;
2929
2752
  const timeSlotEnd = `${endDate} ${endTime}`;
2930
-
2931
- // 获取这个时间段所有商品涉及的资源
2932
2753
  const allResourcesForTimeSlot = [];
2933
- const resourcesIdSet = new Set();
2934
-
2935
- // 获取资源数据
2936
- // const dateRange = this.store.date.getDateRange();
2754
+ const resourcesIdSet = /* @__PURE__ */ new Set();
2937
2755
  const resourcesDates = this.store.date.getDateList();
2938
- const targetResourceDate = resourcesDates.find(n => n.date === startDate);
2939
- if (!targetResourceDate) continue;
2940
- const resourcesMap = (0, _utils2.getResourcesMap)(targetResourceDate.resource || []);
2941
- itemsInTimeSlot.forEach(cartItem => {
2942
- if (!cartItem._productOrigin) return;
2943
-
2944
- // 获取商品的资源配置
2945
- const productResourceIds = (0, _capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2946
- productResourceIds.forEach(resourceId => {
2756
+ const targetResourceDate = resourcesDates.find((n) => n.date === startDate);
2757
+ if (!targetResourceDate)
2758
+ continue;
2759
+ const resourcesMap = (0, import_utils2.getResourcesMap)(targetResourceDate.resource || []);
2760
+ itemsInTimeSlot.forEach((cartItem) => {
2761
+ if (!cartItem._productOrigin)
2762
+ return;
2763
+ const productResourceIds = (0, import_capacity.getResourcesIdsByProduct)(cartItem._productOrigin);
2764
+ productResourceIds.forEach((resourceId) => {
2947
2765
  if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
2948
2766
  resourcesIdSet.add(resourceId);
2949
2767
  allResourcesForTimeSlot.push(resourcesMap[resourceId]);
2950
2768
  }
2951
2769
  });
2952
2770
  });
2953
-
2954
- // 按资源类型分组检查容量
2955
- const {
2956
- success,
2957
- required,
2958
- available
2959
- } = (0, _capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
2771
+ const { success, required, available } = (0, import_capacity.checkTimeSlotCapacity)(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot);
2960
2772
  if (!success) {
2961
- // 如果有可用数量记录,返回最小值;否则返回 0
2962
- // const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2963
- return {
2964
- success: false,
2965
- minAvailableCount: available
2966
- };
2773
+ return { success: false, minAvailableCount: available };
2967
2774
  }
2968
2775
  }
2969
-
2970
- // 全部通过检测,返回成功和最小可用数量
2971
2776
  const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
2972
- return {
2973
- success: true,
2974
- minAvailableCount
2975
- };
2777
+ return { success: true, minAvailableCount };
2976
2778
  }
2977
2779
  setOtherData(key, value) {
2978
2780
  this.otherData[key] = value;
2979
2781
  this.checkSaveCache({
2980
2782
  cacheId: this.cacheId,
2981
2783
  fatherModule: this.name,
2982
- store: {
2983
- otherData: this.otherData
2984
- },
2985
- cacheKey: ['otherData']
2784
+ store: { otherData: this.otherData },
2785
+ cacheKey: ["otherData"]
2986
2786
  });
2987
2787
  }
2988
2788
  getOtherData(key) {
2989
2789
  return this.otherData[key];
2990
2790
  }
2991
2791
  async getProductTypeById(id) {
2792
+ var _a;
2992
2793
  const productData = await this.store.products.getProduct(id);
2993
2794
  if (productData) {
2994
2795
  if (productData.duration) {
2995
- return 'duration';
2796
+ return "duration";
2996
2797
  }
2997
- if (productData['schedule.ids']?.length) {
2998
- return 'session';
2798
+ if ((_a = productData["schedule.ids"]) == null ? void 0 : _a.length) {
2799
+ return "session";
2999
2800
  }
3000
- return 'normal';
2801
+ return "normal";
3001
2802
  }
3002
- return 'normal';
2803
+ return "normal";
3003
2804
  }
3004
-
3005
2805
  /**
3006
2806
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
3007
2807
  *
@@ -3011,82 +2811,113 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
3011
2811
  * @memberof BookingByStepImpl
3012
2812
  */
3013
2813
  getResourcesByCartItemAndCode(cartItemId, resourceCode) {
2814
+ var _a, _b;
3014
2815
  const dateRange = this.store.date.getDateRange();
3015
2816
  const resources = [];
3016
- if (dateRange?.length) {
3017
- dateRange.forEach(n => {
3018
- if (n.resource) resources.push(...n.resource);
2817
+ if (dateRange == null ? void 0 : dateRange.length) {
2818
+ dateRange.forEach((n) => {
2819
+ if (n.resource)
2820
+ resources.push(...n.resource);
3019
2821
  });
3020
2822
  }
3021
2823
  if (!resources.length) {
3022
2824
  const dateList = this.store.date.getDateList();
3023
- dateList.forEach(n => {
3024
- if (n.resource) resources.push(...n.resource);
2825
+ dateList.forEach((n) => {
2826
+ if (n.resource)
2827
+ resources.push(...n.resource);
3025
2828
  });
3026
2829
  }
3027
- const resourcesMap = (0, _utils2.getResourcesMap)((0, _lodashEs.cloneDeep)(resources));
3028
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
3029
- const cartItem = cartItems.find(item => item._id === cartItemId);
3030
- if (!cartItem) return [];
2830
+ const resourcesMap = (0, import_utils2.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
2831
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
2832
+ const cartItem = cartItems.find((item) => item._id === cartItemId);
2833
+ if (!cartItem)
2834
+ return [];
3031
2835
  let selectedResources = [];
3032
- const {
3033
- currentCapacity,
3034
- formatCapacity
3035
- } = (0, _capacity.getCapacityInfoByCartItem)(cartItem);
2836
+ const { currentCapacity, formatCapacity } = (0, import_capacity.getCapacityInfoByCartItem)(cartItem);
3036
2837
  cartItem._origin.metadata.capacity = formatCapacity;
3037
2838
  if (cartItem.holder_id) {
3038
- selectedResources = (0, _resources.getOthersSelectedResources)(cartItems, cartItem.holder_id, resourcesMap);
2839
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
2840
+ cartItems,
2841
+ cartItem.holder_id,
2842
+ resourcesMap
2843
+ );
3039
2844
  } else {
3040
- selectedResources = (0, _resources.getOthersCartSelectedResources)(cartItems, cartItem._id, resourcesMap);
2845
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
2846
+ cartItems,
2847
+ cartItem._id,
2848
+ resourcesMap
2849
+ );
3041
2850
  }
3042
- const productResources = (0, _resources.getResourcesByProduct)(resourcesMap, cartItem._productOrigin?.product_resource?.resources || [], selectedResources, currentCapacity);
3043
- const targetResource = productResources.find(resource => resource.code === resourceCode);
3044
- if (!targetResource) return [];
2851
+ const productResources = (0, import_resources.getResourcesByProduct)(
2852
+ resourcesMap,
2853
+ ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) || [],
2854
+ selectedResources,
2855
+ currentCapacity
2856
+ );
2857
+ const targetResource = productResources.find(
2858
+ (resource) => resource.code === resourceCode
2859
+ );
2860
+ if (!targetResource)
2861
+ return [];
3045
2862
  if (cartItem._origin.start_time) {
3046
- const startTime = (0, _dayjs.default)(`${cartItem._origin.start_date} ${cartItem._origin.start_time}`);
3047
- const endTime = (0, _dayjs.default)(`${cartItem._origin.end_date} ${cartItem._origin.end_time}`);
2863
+ const startTime = (0, import_dayjs.default)(
2864
+ `${cartItem._origin.start_date} ${cartItem._origin.start_time}`
2865
+ );
2866
+ const endTime = (0, import_dayjs.default)(
2867
+ `${cartItem._origin.end_date} ${cartItem._origin.end_time}`
2868
+ );
3048
2869
  const resourcesUseableMap = {};
3049
- targetResource.renderList = targetResource.renderList.sort((a, b) => {
3050
- const aIsCombined = a.metadata?.combined_resource?.status === 1;
3051
- const bIsCombined = b.metadata?.combined_resource?.status === 1;
3052
- if (aIsCombined && !bIsCombined) return 1;
3053
- if (!aIsCombined && bIsCombined) return -1;
3054
- return 0;
3055
- });
3056
- targetResource.renderList = targetResource.renderList.filter(m => {
3057
- const mTimes = m.times.filter(n => {
3058
- return !(0, _dayjs.default)(n.start_at).isAfter((0, _dayjs.default)(startTime)) && !(0, _dayjs.default)(n.end_at).isBefore((0, _dayjs.default)(endTime));
2870
+ targetResource.renderList = targetResource.renderList.sort(
2871
+ (a, b) => {
2872
+ var _a2, _b2, _c, _d;
2873
+ const aIsCombined = ((_b2 = (_a2 = a.metadata) == null ? void 0 : _a2.combined_resource) == null ? void 0 : _b2.status) === 1;
2874
+ const bIsCombined = ((_d = (_c = b.metadata) == null ? void 0 : _c.combined_resource) == null ? void 0 : _d.status) === 1;
2875
+ if (aIsCombined && !bIsCombined)
2876
+ return 1;
2877
+ if (!aIsCombined && bIsCombined)
2878
+ return -1;
2879
+ return 0;
2880
+ }
2881
+ );
2882
+ targetResource.renderList = targetResource.renderList.filter((m) => {
2883
+ const mTimes = m.times.filter((n) => {
2884
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(startTime)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(endTime));
3059
2885
  });
3060
- if (mTimes.length === 0) return false;
3061
- const canUseArr = mTimes.map(item => {
3062
- const res = (0, _resources.getIsUsableByTimeItem)({
2886
+ if (mTimes.length === 0)
2887
+ return false;
2888
+ const canUseArr = mTimes.map((item) => {
2889
+ var _a2;
2890
+ const res = (0, import_resources.getIsUsableByTimeItem)({
3063
2891
  timeSlice: {
3064
- start_time: startTime.format('HH:mm'),
3065
- end_time: endTime.format('HH:mm'),
2892
+ start_time: startTime.format("HH:mm"),
2893
+ end_time: endTime.format("HH:mm"),
3066
2894
  start_at: startTime,
3067
2895
  end_at: endTime
3068
2896
  },
3069
2897
  time: item,
3070
2898
  resource: m,
3071
2899
  currentCount: currentCapacity || 0,
3072
- resourcesUseableMap: resourcesUseableMap,
3073
- cut_off_time: cartItem._productOrigin?.cut_off_time
2900
+ resourcesUseableMap,
2901
+ cut_off_time: (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.cut_off_time
3074
2902
  });
3075
- if (resourcesUseableMap?.[m.id] !== false && res.reason !== 'capacityOnly') {
2903
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== "capacityOnly") {
3076
2904
  resourcesUseableMap[m.id] = res.usable;
3077
2905
  }
3078
2906
  return res.usable;
3079
2907
  });
3080
- if (m.onlyComputed) return false;
3081
- return !canUseArr.some(n => n === false);
2908
+ if (m.onlyComputed)
2909
+ return false;
2910
+ return !canUseArr.some((n) => n === false);
3082
2911
  });
3083
2912
  } else {
3084
- targetResource.renderList = targetResource.renderList.filter(n => {
2913
+ targetResource.renderList = targetResource.renderList.filter((n) => {
2914
+ var _a2, _b2;
3085
2915
  const recordCount = n.capacity || 0;
3086
- if (n.onlyComputed) return false;
3087
- const timeSlots = (0, _resources.getTimeSlicesByResource)({
2916
+ if (n.onlyComputed)
2917
+ return false;
2918
+ const timeSlots = (0, import_resources.getTimeSlicesByResource)({
3088
2919
  resource: n,
3089
- duration: cartItem._productOrigin?.duration?.value || 10,
2920
+ duration: ((_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.duration) == null ? void 0 : _b2.value) || 10,
3090
2921
  split: 10,
3091
2922
  currentDate: dateRange[0].date
3092
2923
  });
@@ -3095,7 +2926,6 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
3095
2926
  }
3096
2927
  return targetResource.renderList;
3097
2928
  }
3098
-
3099
2929
  /**
3100
2930
  * 根据日期范围批量获取时间槽
3101
2931
  * @param params 参数对象
@@ -3107,15 +2937,17 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
3107
2937
  scheduleIds,
3108
2938
  resources
3109
2939
  }) {
3110
- // 生成日期范围内的所有日期
2940
+ console.log(
2941
+ "appoimentBooking-session-date-getTimeslotsScheduleByDateRange",
2942
+ { startDate, endDate, scheduleIds, resources }
2943
+ );
3111
2944
  const dates = [];
3112
- let currentDate = (0, _dayjs.default)(startDate);
3113
- const end = (0, _dayjs.default)(endDate);
2945
+ let currentDate = (0, import_dayjs.default)(startDate);
2946
+ const end = (0, import_dayjs.default)(endDate);
3114
2947
  while (currentDate.isSameOrBefore(end)) {
3115
- dates.push(currentDate.format('YYYY-MM-DD'));
3116
- currentDate = currentDate.add(1, 'day');
2948
+ dates.push(currentDate.format("YYYY-MM-DD"));
2949
+ currentDate = currentDate.add(1, "day");
3117
2950
  }
3118
- // 如果不支持 Web Worker,使用同步方式处理
3119
2951
  const results = {};
3120
2952
  for (const date of dates) {
3121
2953
  results[date] = this.getTimeslotBySchedule({
@@ -3127,36 +2959,25 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
3127
2959
  return results;
3128
2960
  }
3129
2961
  async getAvailableDateForSessionOptimize(params = {}) {
3130
- // 开始日期如果小于今天,直接以今天当做开始日期
3131
- let {
3132
- startDate,
3133
- endDate
3134
- } = params;
3135
- // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
3136
- if ((0, _dayjs.default)(startDate).isBefore((0, _dayjs.default)(), 'day') && ((0, _dayjs.default)(endDate).isAfter((0, _dayjs.default)(), 'day') || (0, _dayjs.default)(endDate).isSame((0, _dayjs.default)(), 'day'))) {
3137
- startDate = (0, _dayjs.default)().format('YYYY-MM-DD');
3138
- }
3139
- // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
3140
- // 优化策略:
3141
- // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
3142
- const endDateAfterMonth = (0, _dayjs.default)().add(1, 'month').format('YYYY-MM-DD');
2962
+ var _a, _b, _c, _d;
2963
+ let { startDate, endDate } = params;
2964
+ if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
2965
+ startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2966
+ }
2967
+ const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
3143
2968
  let tempEndDate = endDateAfterMonth;
3144
- if ((0, _dayjs.default)(startDate).add(7, 'day').isAfter((0, _dayjs.default)(endDateAfterMonth), 'day')) {
3145
- tempEndDate = (0, _dayjs.default)(startDate).add(7, 'day').format('YYYY-MM-DD');
2969
+ if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
2970
+ tempEndDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
3146
2971
  } else {
3147
2972
  tempEndDate = endDateAfterMonth;
3148
2973
  }
3149
- // 如果这么算出来的 tempEndDate 还小于 endDate,则需要把 endDate 置为 tempEndDate
3150
- if ((0, _dayjs.default)(tempEndDate).isBefore((0, _dayjs.default)(endDate), 'day')) {
3151
- tempEndDate = endDate || '';
2974
+ if ((0, import_dayjs.default)(tempEndDate).isBefore((0, import_dayjs.default)(endDate), "day")) {
2975
+ tempEndDate = endDate || "";
3152
2976
  }
3153
2977
  endDate = tempEndDate;
3154
-
3155
- // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
3156
- const cache = this.store.currentProductMeta?.['timeSlotBySchedule'];
2978
+ const cache = (_a = this.store.currentProductMeta) == null ? void 0 : _a["timeSlotBySchedule"];
3157
2979
  if (cache) {
3158
- // 开始日期大于等于缓存的开始日期,且结束日期小于等于缓存的结束日期,则直接返回缓存结果
3159
- if ((0, _dayjs.default)(params.startDate).isSameOrAfter((0, _dayjs.default)(cache.startDate), 'day') && (0, _dayjs.default)(params.endDate).isSameOrBefore((0, _dayjs.default)(cache.endDate), 'day')) {
2980
+ if ((0, import_dayjs.default)(params.startDate).isSameOrAfter((0, import_dayjs.default)(cache.startDate), "day") && (0, import_dayjs.default)(params.endDate).isSameOrBefore((0, import_dayjs.default)(cache.endDate), "day")) {
3160
2981
  this.store.date.setDateList(cache.dateList);
3161
2982
  return {
3162
2983
  dateList: cache.dateList,
@@ -3165,207 +2986,190 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
3165
2986
  }
3166
2987
  }
3167
2988
  let tempProducts;
3168
- // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
3169
2989
  tempProducts = this.store.currentProduct;
3170
- const schedule = this.store.currentProductMeta?.['schedule'];
3171
- const filteredSchedule = (0, _resources.filterScheduleByDateRange)(schedule, startDate || '', endDate || '');
3172
- // 1.后端返回的数据,确定资源在每一天的可用和使用情况
3173
- const tempResourceIds = (0, _capacity.getResourcesIdsByProduct)(tempProducts);
2990
+ const schedule = (_b = this.store.currentProductMeta) == null ? void 0 : _b["schedule"];
2991
+ const filteredSchedule = (0, import_resources.filterScheduleByDateRange)(
2992
+ schedule,
2993
+ startDate || "",
2994
+ endDate || ""
2995
+ );
2996
+ const tempResourceIds = (0, import_capacity.getResourcesIdsByProduct)(tempProducts);
3174
2997
  const res = await this.store.date.fetchResourceDates({
3175
2998
  query: {
3176
- start_date: startDate || '',
3177
- end_date: endDate || '',
2999
+ start_date: startDate || "",
3000
+ end_date: endDate || "",
3178
3001
  resource_ids: tempResourceIds
3179
3002
  }
3180
3003
  });
3181
- // 2. 商品 schedule 数据,确定日程在每一天的时间片
3182
- // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
3183
3004
  let dates = [];
3184
- let currentDate = (0, _dayjs.default)(startDate);
3185
- let firstAvailableDate = '';
3186
-
3187
- // 预处理,获取商品下启用的资源类型,后面只需要遍历这些资源的资源列表即可
3188
- const openResources = tempProducts?.product_resource?.resources?.filter(m => m.status === 1) || [];
3189
-
3190
- // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
3191
- const allProductResources = (0, _lodashEs.cloneDeep)((0, _resources.sortCombinedResources)(res.data) || []);
3192
- // allProductResources 需要根据商品里的资源的单个预约多个预约补充resourceType
3193
- allProductResources.forEach(m => {
3194
- const resource = tempProducts?.product_resource?.resources?.find(n => n.id === m.form_id);
3005
+ let currentDate = (0, import_dayjs.default)(startDate);
3006
+ let firstAvailableDate = "";
3007
+ const openResources = ((_d = (_c = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _c.resources) == null ? void 0 : _d.filter(
3008
+ (m) => m.status === 1
3009
+ )) || [];
3010
+ const allProductResources = (0, import_lodash_es.cloneDeep)((0, import_resources.sortCombinedResources)(res.data) || []);
3011
+ allProductResources.forEach((m) => {
3012
+ var _a2, _b2;
3013
+ const resource = (_b2 = (_a2 = tempProducts == null ? void 0 : tempProducts.product_resource) == null ? void 0 : _a2.resources) == null ? void 0 : _b2.find(
3014
+ (n) => n.id === m.form_id
3015
+ );
3195
3016
  if (resource) {
3196
3017
  m.resourceType = resource.type;
3197
3018
  }
3198
3019
  });
3199
- const targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3200
- while ((0, _dayjs.default)(currentDate).isBefore((0, _dayjs.default)(endDate), 'day') || (0, _dayjs.default)(currentDate).isSame((0, _dayjs.default)(endDate), 'day')) {
3201
- const currentDateStr = currentDate.format('YYYY-MM-DD');
3202
- let status = 'available';
3020
+ const targetSchedules = this.store.schedule.getScheduleListByIds(
3021
+ tempProducts["schedule.ids"]
3022
+ );
3023
+ while ((0, import_dayjs.default)(currentDate).isBefore((0, import_dayjs.default)(endDate), "day") || (0, import_dayjs.default)(currentDate).isSame((0, import_dayjs.default)(endDate), "day")) {
3024
+ const currentDateStr = currentDate.format("YYYY-MM-DD");
3025
+ let status = "available";
3203
3026
  let summaryCount = 0;
3204
3027
  let availableCount = 0;
3205
- // 1. 检查商品的提前量等情况是否满足
3206
- const {
3207
- latestStartDate,
3208
- earliestEndDate
3209
- } = (0, _resources.checkSessionProductLeadTime)(tempProducts);
3028
+ const { latestStartDate, earliestEndDate } = (0, import_resources.checkSessionProductLeadTime)(tempProducts);
3210
3029
  if (latestStartDate || earliestEndDate) {
3211
- // 如果时间在最早开始时间之前,则设置为不可用
3212
- if (latestStartDate && (0, _dayjs.default)(currentDate).isBefore(latestStartDate, 'day')) {
3213
- status = 'unavailable';
3030
+ if (latestStartDate && (0, import_dayjs.default)(currentDate).isBefore(latestStartDate, "day")) {
3031
+ status = "unavailable";
3214
3032
  }
3215
- // 如果时间在最早结束时间之后,则设置为不可用
3216
- if (earliestEndDate && (0, _dayjs.default)(currentDate).isAfter(earliestEndDate, 'day')) {
3217
- status = 'unavailable';
3033
+ if (earliestEndDate && (0, import_dayjs.default)(currentDate).isAfter(earliestEndDate, "day")) {
3034
+ status = "unavailable";
3218
3035
  }
3219
3036
  }
3220
- // 2. 检查 schedule 数据,确定 schedule 里没有这一天,或者这一天的isExcluded: true ,则不可用
3221
- if (status === 'available') {
3222
- const scheduleByDate = filteredSchedule.find(n => n.date === currentDateStr);
3223
- if (!scheduleByDate || scheduleByDate?.isExcluded) {
3224
- status = 'unavailable';
3037
+ if (status === "available") {
3038
+ const scheduleByDate = filteredSchedule.find(
3039
+ (n) => n.date === currentDateStr
3040
+ );
3041
+ if (!scheduleByDate || (scheduleByDate == null ? void 0 : scheduleByDate.isExcluded)) {
3042
+ status = "unavailable";
3225
3043
  }
3226
3044
  }
3227
-
3228
- // 3. 检查这一天的 schedule 时间片里资源是否有可用的,每个时间片下每种资源只需找到第一个可用的即可
3229
- if (status === 'available') {
3230
- const minTimeMaxTime = (0, _utils3.calcMinTimeMaxTimeBySchedules)(targetSchedules, {}, currentDateStr);
3231
- const scheduleTimeSlots = (0, _utils3.getAllSortedDateRanges)(minTimeMaxTime);
3232
- // 同一天内多个时间片下 只要有一个可用则视为可用
3045
+ if (status === "available") {
3046
+ const minTimeMaxTime = (0, import_utils3.calcMinTimeMaxTimeBySchedules)(
3047
+ targetSchedules,
3048
+ {},
3049
+ currentDateStr
3050
+ );
3051
+ const scheduleTimeSlots = (0, import_utils3.getAllSortedDateRanges)(minTimeMaxTime);
3233
3052
  let timesSlotCanUse = false;
3234
- scheduleTimeSlots.forEach(item => {
3235
- // 用来计算资源的可使用情况,针对单个schedule 时间片
3053
+ scheduleTimeSlots.forEach((item) => {
3236
3054
  const resourcesUseableMap = {};
3237
- // 遍历产品下启用的资源
3238
- // 必须要保证每种类型的资源都至少有一个能够在对应时间点被选择
3239
- // 求出第一个资源的剩余量和总量
3240
- // 剩余量=每个资源在每个时间片内剩余之和
3241
- // 总量=每个资源在每个时间片内资源总量之和
3242
3055
  let isAllResourceTypesUseable = true;
3243
- openResources.forEach(resource => {
3244
- // if (!isAllResourceTypesUseable) return;
3245
-
3246
- // 获取当前资源类型的资源列表
3247
- const currentResourcesList = allProductResources.filter(n => n.form_id === resource.resource_type_id);
3248
- // 如果resource.renderList里含有 onlyComputed 的数据,需要把 currentResourcesList 的数据也修正回来
3249
- resource.renderList?.forEach(item => {
3250
- if (item.onlyComputed) {
3251
- const targetIndex = currentResourcesList.findIndex(n => n.id === item.id);
3056
+ openResources.forEach((resource) => {
3057
+ var _a2;
3058
+ const currentResourcesList = allProductResources.filter(
3059
+ (n) => n.form_id === resource.resource_type_id
3060
+ );
3061
+ (_a2 = resource.renderList) == null ? void 0 : _a2.forEach((item2) => {
3062
+ if (item2.onlyComputed) {
3063
+ const targetIndex = currentResourcesList.findIndex((n) => n.id === item2.id);
3252
3064
  if (targetIndex && targetIndex !== -1) {
3253
3065
  currentResourcesList[targetIndex].onlyComputed = true;
3254
3066
  }
3255
3067
  }
3256
3068
  });
3257
- // 可能存在 renderList 没有的情况,则需要判断 resource.optional_resource 和 resource.default_resource 是否存在那个资源,如果不存在也打上 onlyComputed 的标记
3258
- currentResourcesList.forEach(item => {
3259
- if (!resource.optional_resource?.includes(item.id) && !resource.default_resource?.includes(item.id)) {
3260
- item.onlyComputed = true;
3069
+ currentResourcesList.forEach((item2) => {
3070
+ var _a3, _b2;
3071
+ if (!((_a3 = resource.optional_resource) == null ? void 0 : _a3.includes(item2.id)) && !((_b2 = resource.default_resource) == null ? void 0 : _b2.includes(item2.id))) {
3072
+ item2.onlyComputed = true;
3261
3073
  }
3262
3074
  });
3263
- // currentResourcesList 排序,onlyComputed 的资源排在前面先计算
3264
3075
  currentResourcesList.sort((a, b) => {
3265
3076
  return a.onlyComputed ? -1 : 1;
3266
3077
  });
3267
3078
  let isAnyResourceUseableInType = false;
3268
- currentResourcesList?.forEach(m => {
3269
- // 遍历所有资源的上工时间片
3270
- // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
3271
- // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
3272
- // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
3273
- const mTimes = m.times.filter(n => {
3274
- return !(0, _dayjs.default)(n.start_at).isAfter((0, _dayjs.default)(item.start), 'minute') && !(0, _dayjs.default)(n.end_at).isBefore((0, _dayjs.default)(item.end), 'minute');
3079
+ currentResourcesList == null ? void 0 : currentResourcesList.forEach((m) => {
3080
+ const mTimes = m.times.filter((n) => {
3081
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute");
3275
3082
  });
3276
-
3277
- // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
3278
- if (mTimes.length === 0) return;
3279
- // 如果资源可用则把他的容量纳入总计
3083
+ if (mTimes.length === 0)
3084
+ return;
3280
3085
  if (!m.onlyComputed) {
3281
- if (resource.type === 'multiple') {
3086
+ if (resource.type === "multiple") {
3282
3087
  summaryCount += m.capacity;
3283
3088
  } else {
3284
3089
  summaryCount += 1;
3285
3090
  }
3286
3091
  }
3287
3092
  let isAnyTimeSliceUseable = false;
3288
- mTimes.forEach(childTiem => {
3289
- if (isAnyTimeSliceUseable) return;
3290
-
3291
- // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
3292
- const res = (0, _resources.getIsUsableByTimeItem)({
3093
+ mTimes.forEach((childTiem) => {
3094
+ if (isAnyTimeSliceUseable)
3095
+ return;
3096
+ const res2 = (0, import_resources.getIsUsableByTimeItem)({
3293
3097
  timeSlice: {
3294
3098
  start_time: item.start,
3295
3099
  end_time: item.end,
3296
- start_at: (0, _dayjs.default)(item.start),
3297
- end_at: (0, _dayjs.default)(item.end)
3100
+ start_at: (0, import_dayjs.default)(item.start),
3101
+ end_at: (0, import_dayjs.default)(item.end)
3298
3102
  },
3299
3103
  time: childTiem,
3300
3104
  resource: m,
3301
3105
  currentCount: 1,
3302
3106
  resourcesUseableMap,
3303
- cut_off_time: tempProducts?.cut_off_time
3107
+ cut_off_time: tempProducts == null ? void 0 : tempProducts.cut_off_time
3304
3108
  });
3305
- if (resourcesUseableMap?.[m.id] !== false && res.reason !== 'capacityOnly') {
3306
- resourcesUseableMap[m.id] = res.usable;
3109
+ if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[m.id]) !== false && res2.reason !== "capacityOnly") {
3110
+ resourcesUseableMap[m.id] = res2.usable;
3307
3111
  }
3308
- if (res.usable && !m.onlyComputed) {
3112
+ if (res2.usable && !m.onlyComputed) {
3309
3113
  isAnyTimeSliceUseable = true;
3310
- if (resource.type === 'multiple') {
3311
- availableCount += res.remainingCapacity;
3114
+ if (resource.type === "multiple") {
3115
+ availableCount += res2.remainingCapacity;
3312
3116
  } else {
3313
3117
  availableCount += 1;
3314
3118
  }
3315
3119
  }
3316
3120
  ;
3317
3121
  });
3318
- if (isAnyTimeSliceUseable) isAnyResourceUseableInType = true;
3122
+ if (isAnyTimeSliceUseable)
3123
+ isAnyResourceUseableInType = true;
3319
3124
  });
3320
- if (!isAnyResourceUseableInType) isAllResourceTypesUseable = false;
3125
+ if (!isAnyResourceUseableInType)
3126
+ isAllResourceTypesUseable = false;
3321
3127
  });
3322
- if (isAllResourceTypesUseable) timesSlotCanUse = true;
3128
+ if (isAllResourceTypesUseable)
3129
+ timesSlotCanUse = true;
3323
3130
  });
3324
3131
  if (!timesSlotCanUse) {
3325
- status = 'unavailable';
3132
+ status = "unavailable";
3326
3133
  }
3327
- if (status === 'available' && !firstAvailableDate) {
3134
+ if (status === "available" && !firstAvailableDate) {
3328
3135
  firstAvailableDate = currentDateStr;
3329
3136
  }
3330
3137
  }
3331
- // 状态: lots_of_space: availableCount / summaryCount > 0.5
3332
- // filling_up_fast: availableCount / summaryCount <= 0.5 && availableCount > 0
3333
- // sold_out: summaryCount = 0
3334
- // unavailable: summaryCount > 0 && availableCount = 0
3335
3138
  let dateStatus;
3336
- if (status === 'unavailable') {
3337
- // dateStatus = 'unavailable'
3338
- if (availableCount === 0 && summaryCount > 0) dateStatus = 'sold_out';else dateStatus = 'unavailable';
3139
+ if (status === "unavailable") {
3140
+ if (availableCount === 0 && summaryCount > 0)
3141
+ dateStatus = "sold_out";
3142
+ else
3143
+ dateStatus = "unavailable";
3339
3144
  } else {
3340
3145
  const usageRatio = availableCount / summaryCount;
3341
- if (usageRatio > 0.5) dateStatus = 'lots_of_space';else dateStatus = 'filling_up_fast';
3146
+ if (usageRatio > 0.5)
3147
+ dateStatus = "lots_of_space";
3148
+ else
3149
+ dateStatus = "filling_up_fast";
3342
3150
  }
3343
3151
  dates.push({
3344
- date: (0, _dayjs.default)(currentDate).format('YYYY-MM-DD'),
3345
- week: (0, _dayjs.default)(currentDate).format('ddd'),
3346
- weekNum: (0, _dayjs.default)(currentDate).day(),
3152
+ date: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD"),
3153
+ week: (0, import_dayjs.default)(currentDate).format("ddd"),
3154
+ weekNum: (0, import_dayjs.default)(currentDate).day(),
3347
3155
  summaryCount,
3348
3156
  availableCount,
3349
3157
  status: dateStatus
3350
3158
  });
3351
-
3352
- // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
3353
- if (firstAvailableDate && (0, _dayjs.default)(currentDate).diff((0, _dayjs.default)(startDate), 'day') > 31) {
3159
+ if (firstAvailableDate && (0, import_dayjs.default)(currentDate).diff((0, import_dayjs.default)(startDate), "day") > 31) {
3354
3160
  break;
3355
3161
  }
3356
- currentDate = (0, _dayjs.default)(currentDate).add(1, 'day');
3162
+ currentDate = (0, import_dayjs.default)(currentDate).add(1, "day");
3357
3163
  }
3358
- // 最终把资源数据也加到日期内
3359
- dates = (0, _utils4.handleAvailableDateByResource)(res.data, dates);
3164
+ dates = (0, import_utils4.handleAvailableDateByResource)(res.data, dates);
3360
3165
  this.store.date.setDateList(dates);
3361
-
3362
- // 缓存这次结果,以防后面他小幅度范围内去修改天数
3363
- if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
3166
+ if (!this.store.currentProductMeta)
3167
+ this.store.currentProductMeta = {};
3364
3168
  this.store.currentProductMeta.timeSlotBySchedule = {
3365
3169
  dateList: dates,
3366
3170
  firstAvailableDate,
3367
3171
  startDate,
3368
- endDate: (0, _dayjs.default)(currentDate).format('YYYY-MM-DD')
3172
+ endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
3369
3173
  };
3370
3174
  return {
3371
3175
  dateList: dates,
@@ -3373,27 +3177,33 @@ class BookingByStepImpl extends _BaseModule.BaseModule {
3373
3177
  };
3374
3178
  }
3375
3179
  isCartAllNormalProducts() {
3376
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
3180
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
3377
3181
  return !cartItems.length;
3378
3182
  }
3379
3183
  isCartHasDurationProduct() {
3380
- const cartItems = this.store.cart.getItems().filter(n => !(0, _utils5.isNormalProduct)(n._productOrigin));
3381
- return cartItems.some(n => n._productOrigin?.duration);
3184
+ const cartItems = this.store.cart.getItems().filter((n) => !(0, import_utils5.isNormalProduct)(n._productOrigin));
3185
+ return cartItems.some((n) => {
3186
+ var _a;
3187
+ return (_a = n._productOrigin) == null ? void 0 : _a.duration;
3188
+ });
3382
3189
  }
3383
3190
  isTargetNormalProduct(product) {
3384
- if (!product) return false;
3385
- return (0, _utils5.isNormalProduct)(product);
3191
+ if (!product)
3192
+ return false;
3193
+ return (0, import_utils5.isNormalProduct)(product);
3386
3194
  }
3387
3195
  isTargetCartIdNormalProduct(id) {
3388
- const cartItem = this.store.cart.getItems().find(n => n._id === id);
3389
- return cartItem && (0, _utils5.isNormalProduct)(cartItem._productOrigin);
3196
+ const cartItem = this.store.cart.getItems().find((n) => n._id === id);
3197
+ return cartItem && (0, import_utils5.isNormalProduct)(cartItem._productOrigin);
3390
3198
  }
3391
-
3392
3199
  /**
3393
3200
  * 获取联系信息
3394
3201
  */
3395
3202
  async getContactInfo(params) {
3396
- return this.request.get('/customer/metadata', params);
3203
+ return this.request.get("/customer/metadata", params);
3397
3204
  }
3398
- }
3399
- exports.BookingByStepImpl = BookingByStepImpl;
3205
+ };
3206
+ // Annotate the CommonJS export names for ESM import in node:
3207
+ 0 && (module.exports = {
3208
+ BookingByStepImpl
3209
+ });