@pisell/pisellos 2.2.148 → 2.2.149

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 (247) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/model/strategy/adapter/index.d.ts +2 -0
  4. package/dist/model/strategy/adapter/index.js +3 -1
  5. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  6. package/dist/model/strategy/adapter/itemRule/adapter.js +483 -0
  7. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  8. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  9. package/dist/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  10. package/dist/model/strategy/adapter/itemRule/examples.js +382 -0
  11. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  12. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  13. package/dist/model/strategy/adapter/itemRule/type.d.ts +225 -0
  14. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  15. package/dist/modules/Cart/types.d.ts +2 -0
  16. package/dist/modules/Cart/utils/cartProduct.js +22 -1
  17. package/dist/modules/Cart/utils/changePrice.js +6 -0
  18. package/dist/modules/Date/index.d.ts +1 -1
  19. package/dist/modules/Date/index.js +16 -8
  20. package/dist/modules/Date/types.d.ts +3 -1
  21. package/dist/modules/OpenData/index.d.ts +24 -0
  22. package/dist/modules/OpenData/index.js +173 -0
  23. package/dist/modules/OpenData/types.d.ts +73 -0
  24. package/dist/modules/OpenData/types.js +1 -0
  25. package/dist/modules/OpenData/utils.d.ts +2 -0
  26. package/dist/modules/OpenData/utils.js +75 -0
  27. package/dist/modules/Order/index.d.ts +171 -1
  28. package/dist/modules/Order/index.js +2052 -112
  29. package/dist/modules/Order/types.d.ts +441 -20
  30. package/dist/modules/Order/types.js +23 -0
  31. package/dist/modules/Order/utils.d.ts +120 -0
  32. package/dist/modules/Order/utils.js +653 -2
  33. package/dist/modules/Product/utils.js +2 -2
  34. package/dist/modules/ProductList/index.js +2 -1
  35. package/dist/modules/Quotation/index.d.ts +8 -1
  36. package/dist/modules/Quotation/index.js +40 -10
  37. package/dist/modules/Quotation/types.d.ts +5 -0
  38. package/dist/modules/Rules/index.d.ts +3 -1
  39. package/dist/modules/Rules/index.js +136 -50
  40. package/dist/modules/Rules/types.d.ts +6 -0
  41. package/dist/modules/Rules/types.js +8 -0
  42. package/dist/modules/SalesSummary/index.d.ts +70 -0
  43. package/dist/modules/SalesSummary/index.js +175 -0
  44. package/dist/modules/SalesSummary/types.d.ts +64 -0
  45. package/dist/modules/SalesSummary/types.js +1 -0
  46. package/dist/modules/SalesSummary/utils.d.ts +34 -0
  47. package/dist/modules/SalesSummary/utils.js +488 -0
  48. package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
  49. package/dist/modules/ScanOrderLogger/index.js +161 -0
  50. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  51. package/dist/modules/ScanOrderLogger/providers/feishu.js +203 -0
  52. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  53. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  54. package/dist/modules/ScanOrderLogger/types.d.ts +52 -0
  55. package/dist/modules/ScanOrderLogger/types.js +1 -0
  56. package/dist/modules/Schedule/getDateIsInSchedule.js +7 -7
  57. package/dist/modules/Schedule/index.d.ts +4 -13
  58. package/dist/modules/Schedule/index.js +6 -23
  59. package/dist/modules/Schedule/utils.d.ts +1 -1
  60. package/dist/modules/Summary/index.d.ts +3 -0
  61. package/dist/modules/Summary/index.js +134 -15
  62. package/dist/modules/Summary/types.d.ts +7 -0
  63. package/dist/modules/Summary/utils.d.ts +104 -1
  64. package/dist/modules/Summary/utils.js +1116 -13
  65. package/dist/modules/index.d.ts +4 -0
  66. package/dist/modules/index.js +5 -1
  67. package/dist/server/index.d.ts +41 -4
  68. package/dist/server/index.js +900 -405
  69. package/dist/server/modules/order/index.d.ts +10 -2
  70. package/dist/server/modules/order/index.js +246 -193
  71. package/dist/server/modules/products/index.d.ts +26 -0
  72. package/dist/server/modules/products/index.js +618 -338
  73. package/dist/server/modules/products/types.d.ts +5 -1
  74. package/dist/solution/BaseSales/index.d.ts +175 -0
  75. package/dist/solution/BaseSales/index.js +1293 -0
  76. package/dist/solution/BaseSales/types.d.ts +305 -0
  77. package/dist/solution/BaseSales/types.js +38 -0
  78. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +143 -0
  79. package/dist/solution/BaseSales/utils/parseSalesResponse.js +159 -0
  80. package/dist/solution/BaseSales/utils.d.ts +40 -0
  81. package/dist/solution/BaseSales/utils.js +222 -0
  82. package/dist/solution/BookingByStep/index.d.ts +14 -0
  83. package/dist/solution/BookingByStep/index.js +699 -212
  84. package/dist/solution/BookingByStep/types.d.ts +3 -1
  85. package/dist/solution/BookingByStep/types.js +5 -1
  86. package/dist/solution/BookingByStep/utils/capacity.js +1 -1
  87. package/dist/solution/BookingByStep/utils/resources.js +6 -1
  88. package/dist/solution/BookingTicket/index.d.ts +113 -15
  89. package/dist/solution/BookingTicket/index.js +534 -196
  90. package/dist/solution/BookingTicket/types.d.ts +69 -6
  91. package/dist/solution/BookingTicket/types.js +40 -9
  92. package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +37 -0
  93. package/dist/solution/BookingTicket/utils/bookingStatus.js +66 -0
  94. package/dist/solution/BookingTicket/utils/cartView.d.ts +26 -0
  95. package/dist/solution/BookingTicket/utils/cartView.js +84 -0
  96. package/dist/solution/Sales/index.d.ts +1 -0
  97. package/dist/solution/Sales/index.js +1 -0
  98. package/dist/solution/ScanOrder/index.d.ts +146 -0
  99. package/dist/solution/ScanOrder/index.js +3029 -0
  100. package/dist/solution/ScanOrder/types.d.ts +305 -0
  101. package/dist/solution/ScanOrder/types.js +35 -0
  102. package/dist/solution/ScanOrder/utils.d.ts +167 -0
  103. package/dist/solution/ScanOrder/utils.js +768 -0
  104. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  105. package/dist/solution/ShopDiscount/index.js +9 -5
  106. package/dist/solution/ShopDiscount/types.d.ts +4 -0
  107. package/dist/solution/VenueBooking/index.d.ts +197 -0
  108. package/dist/solution/VenueBooking/index.js +3411 -0
  109. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  110. package/dist/solution/VenueBooking/types.d.ts +153 -0
  111. package/dist/solution/VenueBooking/types.js +21 -0
  112. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  113. package/dist/solution/VenueBooking/utils/dateSummary.js +104 -0
  114. package/dist/solution/VenueBooking/utils/resource.d.ts +14 -0
  115. package/dist/solution/VenueBooking/utils/resource.js +130 -0
  116. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +34 -0
  117. package/dist/solution/VenueBooking/utils/slotMerge.js +224 -0
  118. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  119. package/dist/solution/VenueBooking/utils/timeSlot.js +453 -0
  120. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  121. package/dist/solution/VenueBooking/utils.js +1 -0
  122. package/dist/solution/index.d.ts +3 -0
  123. package/dist/solution/index.js +4 -1
  124. package/lib/apis/picoding.d.ts +0 -0
  125. package/lib/apis/picoding.js +0 -0
  126. package/lib/model/strategy/adapter/index.d.ts +2 -0
  127. package/lib/model/strategy/adapter/index.js +6 -0
  128. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +67 -0
  129. package/lib/model/strategy/adapter/itemRule/adapter.js +377 -0
  130. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  131. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  132. package/lib/model/strategy/adapter/itemRule/examples.d.ts +79 -0
  133. package/lib/model/strategy/adapter/itemRule/examples.js +316 -0
  134. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  135. package/lib/model/strategy/adapter/itemRule/index.js +60 -0
  136. package/lib/model/strategy/adapter/itemRule/type.d.ts +225 -0
  137. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  138. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  139. package/lib/modules/Cart/types.d.ts +2 -0
  140. package/lib/modules/Cart/utils/cartProduct.js +17 -1
  141. package/lib/modules/Cart/utils/changePrice.js +5 -0
  142. package/lib/modules/Date/index.d.ts +1 -1
  143. package/lib/modules/Date/index.js +7 -1
  144. package/lib/modules/Date/types.d.ts +3 -1
  145. package/lib/modules/OpenData/index.d.ts +24 -0
  146. package/lib/modules/OpenData/index.js +119 -0
  147. package/lib/modules/OpenData/types.d.ts +73 -0
  148. package/lib/modules/OpenData/types.js +17 -0
  149. package/lib/modules/OpenData/utils.d.ts +2 -0
  150. package/lib/modules/OpenData/utils.js +111 -0
  151. package/lib/modules/Order/index.d.ts +171 -1
  152. package/lib/modules/Order/index.js +1396 -5
  153. package/lib/modules/Order/types.d.ts +441 -20
  154. package/lib/modules/Order/types.js +1 -0
  155. package/lib/modules/Order/utils.d.ts +120 -0
  156. package/lib/modules/Order/utils.js +562 -2
  157. package/lib/modules/Product/utils.js +2 -2
  158. package/lib/modules/ProductList/index.js +2 -1
  159. package/lib/modules/Quotation/index.d.ts +8 -1
  160. package/lib/modules/Quotation/index.js +33 -4
  161. package/lib/modules/Quotation/types.d.ts +5 -0
  162. package/lib/modules/Rules/index.d.ts +3 -1
  163. package/lib/modules/Rules/index.js +46 -6
  164. package/lib/modules/Rules/types.d.ts +6 -0
  165. package/lib/modules/Rules/types.js +11 -2
  166. package/lib/modules/SalesSummary/index.d.ts +70 -0
  167. package/lib/modules/SalesSummary/index.js +106 -0
  168. package/lib/modules/SalesSummary/types.d.ts +64 -0
  169. package/lib/modules/SalesSummary/types.js +17 -0
  170. package/lib/modules/SalesSummary/utils.d.ts +34 -0
  171. package/lib/modules/SalesSummary/utils.js +430 -0
  172. package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
  173. package/lib/modules/ScanOrderLogger/index.js +135 -0
  174. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  175. package/lib/modules/ScanOrderLogger/providers/feishu.js +148 -0
  176. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  177. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  178. package/lib/modules/ScanOrderLogger/types.d.ts +52 -0
  179. package/lib/modules/ScanOrderLogger/types.js +17 -0
  180. package/lib/modules/Schedule/getDateIsInSchedule.js +5 -5
  181. package/lib/modules/Schedule/index.d.ts +4 -13
  182. package/lib/modules/Schedule/index.js +4 -15
  183. package/lib/modules/Schedule/utils.d.ts +1 -1
  184. package/lib/modules/Summary/index.d.ts +3 -0
  185. package/lib/modules/Summary/index.js +61 -2
  186. package/lib/modules/Summary/types.d.ts +7 -0
  187. package/lib/modules/Summary/utils.d.ts +104 -1
  188. package/lib/modules/Summary/utils.js +659 -8
  189. package/lib/modules/index.d.ts +4 -0
  190. package/lib/modules/index.js +9 -1
  191. package/lib/server/index.d.ts +41 -4
  192. package/lib/server/index.js +272 -10
  193. package/lib/server/modules/order/index.d.ts +10 -2
  194. package/lib/server/modules/order/index.js +26 -1
  195. package/lib/server/modules/products/index.d.ts +26 -0
  196. package/lib/server/modules/products/index.js +174 -22
  197. package/lib/server/modules/products/types.d.ts +5 -1
  198. package/lib/solution/BaseSales/index.d.ts +175 -0
  199. package/lib/solution/BaseSales/index.js +655 -0
  200. package/lib/solution/BaseSales/types.d.ts +305 -0
  201. package/lib/solution/BaseSales/types.js +40 -0
  202. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +143 -0
  203. package/lib/solution/BaseSales/utils/parseSalesResponse.js +160 -0
  204. package/lib/solution/BaseSales/utils.d.ts +40 -0
  205. package/lib/solution/BaseSales/utils.js +200 -0
  206. package/lib/solution/BookingByStep/index.d.ts +14 -0
  207. package/lib/solution/BookingByStep/index.js +469 -91
  208. package/lib/solution/BookingByStep/types.d.ts +3 -1
  209. package/lib/solution/BookingByStep/types.js +10 -0
  210. package/lib/solution/BookingByStep/utils/capacity.js +1 -1
  211. package/lib/solution/BookingByStep/utils/resources.js +5 -2
  212. package/lib/solution/BookingTicket/index.d.ts +113 -15
  213. package/lib/solution/BookingTicket/index.js +253 -61
  214. package/lib/solution/BookingTicket/types.d.ts +69 -6
  215. package/lib/solution/BookingTicket/types.js +16 -14
  216. package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +37 -0
  217. package/lib/solution/BookingTicket/utils/bookingStatus.js +65 -0
  218. package/lib/solution/BookingTicket/utils/cartView.d.ts +26 -0
  219. package/lib/solution/BookingTicket/utils/cartView.js +103 -0
  220. package/lib/solution/Sales/index.d.ts +1 -0
  221. package/lib/solution/ScanOrder/index.d.ts +146 -0
  222. package/lib/solution/ScanOrder/index.js +1820 -0
  223. package/lib/solution/ScanOrder/types.d.ts +305 -0
  224. package/lib/solution/ScanOrder/types.js +36 -0
  225. package/lib/solution/ScanOrder/utils.d.ts +167 -0
  226. package/lib/solution/ScanOrder/utils.js +639 -0
  227. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  228. package/lib/solution/ShopDiscount/index.js +9 -4
  229. package/lib/solution/ShopDiscount/types.d.ts +4 -0
  230. package/lib/solution/VenueBooking/index.d.ts +197 -0
  231. package/lib/solution/VenueBooking/index.js +1892 -0
  232. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  233. package/lib/solution/VenueBooking/types.d.ts +153 -0
  234. package/lib/solution/VenueBooking/types.js +44 -0
  235. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +11 -0
  236. package/lib/solution/VenueBooking/utils/dateSummary.js +110 -0
  237. package/lib/solution/VenueBooking/utils/resource.d.ts +14 -0
  238. package/lib/solution/VenueBooking/utils/resource.js +91 -0
  239. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +34 -0
  240. package/lib/solution/VenueBooking/utils/slotMerge.js +225 -0
  241. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  242. package/lib/solution/VenueBooking/utils/timeSlot.js +339 -0
  243. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  244. package/lib/solution/VenueBooking/utils.js +69 -0
  245. package/lib/solution/index.d.ts +3 -0
  246. package/lib/solution/index.js +7 -1
  247. package/package.json +1 -1
@@ -1497,7 +1497,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1497
1497
  resources.push.apply(resources, _toConsumableArray(dateResources || []));
1498
1498
  } else {
1499
1499
  var dateList = this.store.date.getDateList();
1500
- dateList.forEach(function (n) {
1500
+ dateList === null || dateList === void 0 || dateList.forEach(function (n) {
1501
1501
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1502
1502
  });
1503
1503
  }
@@ -1815,7 +1815,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1815
1815
  timeSlots: timeSlots,
1816
1816
  currentCapacity: totalCapacity + (capacity || 0)
1817
1817
  });
1818
- if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1818
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime && n.capacity >= (capacity || 0)) {
1819
1819
  targetResource = n;
1820
1820
  targetResourceTime = currentResourceIdleTime;
1821
1821
  return 1; // break
@@ -2059,6 +2059,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2059
2059
  key: "getTimeSlotByAllResources",
2060
2060
  value: function getTimeSlotByAllResources(resources_code) {
2061
2061
  var _dateRange,
2062
+ _dateRange2,
2062
2063
  _this12 = this,
2063
2064
  _cartItems$,
2064
2065
  _cartItems$2,
@@ -2114,6 +2115,28 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2114
2115
  }
2115
2116
  });
2116
2117
  }
2118
+ // 检查通过购物车 renderList 加入的资源数据里 times 的正确性,如果不对则需要修正
2119
+ if ((_dateRange2 = dateRange) !== null && _dateRange2 !== void 0 && (_dateRange2 = _dateRange2[0]) !== null && _dateRange2 !== void 0 && _dateRange2.date && resources.length) {
2120
+ var _dateRange3;
2121
+ var currentDate = (_dateRange3 = dateRange) === null || _dateRange3 === void 0 || (_dateRange3 = _dateRange3[0]) === null || _dateRange3 === void 0 ? void 0 : _dateRange3.date;
2122
+ var theDateResources = this.store.date.getResourcesListByDate(currentDate);
2123
+ resources.forEach(function (item) {
2124
+ var noCurrentDateTimes = item.times.some(function (n) {
2125
+ return dayjs(n.start_at).isSame(dayjs(currentDate), 'day');
2126
+ });
2127
+ if (!noCurrentDateTimes) {
2128
+ var _theDateResources$fin;
2129
+ item.times = (theDateResources === null || theDateResources === void 0 || (_theDateResources$fin = theDateResources.find(function (n) {
2130
+ return n.id === item.id;
2131
+ })) === null || _theDateResources$fin === void 0 ? void 0 : _theDateResources$fin.times) || [];
2132
+ }
2133
+ });
2134
+ }
2135
+
2136
+ // 如果依然 resources 空的,则证明他是切换日期了,此时直接从 date 模块里取
2137
+ if (resources.length === 0) {
2138
+ resources.push.apply(resources, _toConsumableArray(this.store.date.getResourcesListByDate(dateRange[0].date) || []));
2139
+ }
2117
2140
  var resourcesMap = getResourcesMap(resources);
2118
2141
  var duration = 0;
2119
2142
  // duration = 不同账号的最长时间
@@ -2186,12 +2209,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2186
2209
  }
2187
2210
  // 计算容量的辅助函数
2188
2211
  var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2189
- return items.reduce(function (total, item) {
2190
- return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2191
- }, 0);
2212
+ var _items$0$_resourceOri;
2213
+ if (items.length === 0) return 0;
2214
+ // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
2215
+ var firstResource = (_items$0$_resourceOri = items[0]._resourceOrigin) === null || _items$0$_resourceOri === void 0 ? void 0 : _items$0$_resourceOri[0].id;
2216
+ var sameResourceLength = items.filter(function (item) {
2217
+ var _item$_resourceOrigin;
2218
+ return ((_item$_resourceOrigin = item._resourceOrigin) === null || _item$_resourceOrigin === void 0 ? void 0 : _item$_resourceOrigin[0].id) === firstResource;
2219
+ }).length;
2220
+ if (sameResourceLength === items.length) {
2221
+ return 1;
2222
+ }
2223
+ // 找出单个购物车里最大的需求 capacity 即可
2224
+ return Math.max.apply(Math, _toConsumableArray(items.map(function (item) {
2225
+ return getCapacityInfoByCartItem(item).currentCapacity || 1;
2226
+ })));
2227
+ // return items.reduce((total, item) => {
2228
+ // return total + (getCapacityInfoByCartItem(item).currentCapacity || 0);
2229
+ // }, 0);
2192
2230
  };
2193
2231
 
2194
- // 如果是多个预约,去要求助几个 holder 下最大的需求容量capacity
2232
+ // 如果是多个人预约,去要求出几个 holder 下最大的商品需求容量capacity
2195
2233
  var maxCapacity = 1;
2196
2234
  if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2197
2235
  accountList.forEach(function (account) {
@@ -2219,13 +2257,258 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2219
2257
  });
2220
2258
  return timeSlots;
2221
2259
  }
2260
+ // 从购物车中获取已经分配好第一步资源的所有时间片,批量版本,用于给日期提供能否高亮的判断
2261
+ }, {
2262
+ key: "getTimeSlotByAllResourcesForDate",
2263
+ value: function () {
2264
+ var _getTimeSlotByAllResourcesForDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(_ref10) {
2265
+ var _this13 = this,
2266
+ _cartItems$5,
2267
+ _cartItems$6,
2268
+ _this$shopStore$get2;
2269
+ var resources_code, startDate, endDate, resources, cartItems, resourceIds, resourcesTypeId, isSingleResource, maxCutOffTime, maxCutOffTimeValue, duration, accountList, checkDuration, resourcesUseableMap, hasFlexibleDuration, operating_day_boundary, maxBlockThreshold, calculateCapacityFromCartItems, maxCapacity, arr, today, _loop2, i;
2270
+ return _regeneratorRuntime().wrap(function _callee24$(_context25) {
2271
+ while (1) switch (_context25.prev = _context25.next) {
2272
+ case 0:
2273
+ resources_code = _ref10.resources_code, startDate = _ref10.startDate, endDate = _ref10.endDate;
2274
+ // 如果 end_date 距离start_date小于 30 天,自动追加 end_date 为今天往后的 30 天
2275
+ if (dayjs(endDate).diff(dayjs(startDate), 'day') < 30) {
2276
+ endDate = dayjs(startDate).add(30, 'day').format('YYYY-MM-DD');
2277
+ }
2278
+ // 预请求资源数据,防止日期超过之前选择的范围
2279
+ _context25.next = 4;
2280
+ return this.getAvailableDate({
2281
+ startDate: startDate,
2282
+ endDate: endDate,
2283
+ useCache: true
2284
+ });
2285
+ case 4:
2286
+ // 取出购物车中所有一已选择的第一步资源
2287
+ resources = [];
2288
+ cartItems = this.store.cart.getItems().filter(function (n) {
2289
+ return !isNormalProduct(n._productOrigin);
2290
+ }); // if (cartItems?.[0].start_date) return [];
2291
+ resourceIds = [];
2292
+ resourcesTypeId = undefined;
2293
+ isSingleResource = false; // 找出购物车里最大的 cut_off_time
2294
+ maxCutOffTime = undefined;
2295
+ maxCutOffTimeValue = dayjs();
2296
+ cartItems.forEach(function (item) {
2297
+ var _item$_productOrigin17, _item$_productOrigin18, _item$_productOrigin19, _item$_productOrigin20;
2298
+ (_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.product_resource) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.resources) === null || _item$_productOrigin17 === void 0 || _item$_productOrigin17.forEach(function (n) {
2299
+ // TODO: 少了个 status 的判断
2300
+ if (n.code === resources_code) {
2301
+ resources.push.apply(resources, _toConsumableArray(n.renderList || []));
2302
+ isSingleResource = n.type === 'single';
2303
+ }
2304
+ });
2305
+ // item._origin.resources?.forEach((n: any) => {
2306
+ // resourceIds.push(n.relation_id);
2307
+ // });
2308
+ if (item.resource_id && !resourceIds.includes(item.resource_id)) {
2309
+ resourceIds.push(item.resource_id);
2310
+ }
2311
+ resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin18 = item._productOrigin) === null || _item$_productOrigin18 === void 0 || (_item$_productOrigin18 = _item$_productOrigin18.product_resource) === null || _item$_productOrigin18 === void 0 || (_item$_productOrigin18 = _item$_productOrigin18.resources) === null || _item$_productOrigin18 === void 0 || (_item$_productOrigin18 = _item$_productOrigin18.find(function (n) {
2312
+ return n.code === resources_code;
2313
+ })) === null || _item$_productOrigin18 === void 0 ? void 0 : _item$_productOrigin18.id;
2314
+ if ((_item$_productOrigin19 = item._productOrigin) !== null && _item$_productOrigin19 !== void 0 && _item$_productOrigin19.cut_off_time && ((_item$_productOrigin20 = item._productOrigin) === null || _item$_productOrigin20 === void 0 ? void 0 : _item$_productOrigin20.cut_off_time.type) === 'advance') {
2315
+ var currentCutOffTime = dayjs().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
2316
+ if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
2317
+ maxCutOffTimeValue = currentCutOffTime;
2318
+ maxCutOffTime = item._productOrigin.cut_off_time;
2319
+ }
2320
+ }
2321
+ });
2222
2322
 
2223
- // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
2323
+ // 保护: 如果 resources 为空则直接 return
2324
+ if (resources.length) {
2325
+ _context25.next = 14;
2326
+ break;
2327
+ }
2328
+ return _context25.abrupt("return", []);
2329
+ case 14:
2330
+ duration = 0; // duration = 不同账号的最长时间
2331
+ accountList = this.store.accountList.getAccounts();
2332
+ checkDuration = function checkDuration(cartItems) {
2333
+ var accountDuration = 0;
2334
+ cartItems.forEach(function (item) {
2335
+ // 单个预约累加账号 多个预约取最大值
2336
+ if (isSingleResource) {
2337
+ var _item$_productOrigin21;
2338
+ accountDuration += ((_item$_productOrigin21 = item._productOrigin) === null || _item$_productOrigin21 === void 0 || (_item$_productOrigin21 = _item$_productOrigin21.duration) === null || _item$_productOrigin21 === void 0 ? void 0 : _item$_productOrigin21.value) || 10;
2339
+ } else {
2340
+ var _item$_productOrigin22;
2341
+ if (accountDuration < (((_item$_productOrigin22 = item._productOrigin) === null || _item$_productOrigin22 === void 0 || (_item$_productOrigin22 = _item$_productOrigin22.duration) === null || _item$_productOrigin22 === void 0 ? void 0 : _item$_productOrigin22.value) || 10)) {
2342
+ var _item$_productOrigin23;
2343
+ accountDuration = ((_item$_productOrigin23 = item._productOrigin) === null || _item$_productOrigin23 === void 0 || (_item$_productOrigin23 = _item$_productOrigin23.duration) === null || _item$_productOrigin23 === void 0 ? void 0 : _item$_productOrigin23.value) || 10;
2344
+ }
2345
+ }
2346
+ });
2347
+ if (accountDuration > duration) {
2348
+ duration = accountDuration;
2349
+ }
2350
+ };
2351
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2352
+ accountList.forEach(function (account) {
2353
+ var cartItems = _this13.store.cart.getCartByAccount(account.getId());
2354
+ checkDuration(cartItems);
2355
+ });
2356
+ } else {
2357
+ checkDuration(cartItems);
2358
+ }
2359
+ // 如果 cartItem 上既没有时间,也没有资源,认为外部属于异常调用,直接丢一个空数组出去
2360
+ // 同时 session 类商品的流程也不应该调用这个方法
2361
+ if (!(!(cartItems !== null && cartItems !== void 0 && (_cartItems$5 = cartItems[0]) !== null && _cartItems$5 !== void 0 && _cartItems$5.start_date) && !(cartItems !== null && cartItems !== void 0 && (_cartItems$6 = cartItems[0]) !== null && _cartItems$6 !== void 0 && _cartItems$6.resource_id) || !(cartItems !== null && cartItems !== void 0 && cartItems[0].duration))) {
2362
+ _context25.next = 20;
2363
+ break;
2364
+ }
2365
+ return _context25.abrupt("return", []);
2366
+ case 20:
2367
+ resourcesUseableMap = {};
2368
+ hasFlexibleDuration = cartItems.some(function (item) {
2369
+ var _item$_productOrigin24;
2370
+ return ((_item$_productOrigin24 = item._productOrigin) === null || _item$_productOrigin24 === void 0 || (_item$_productOrigin24 = _item$_productOrigin24.duration) === null || _item$_productOrigin24 === void 0 ? void 0 : _item$_productOrigin24.type) === 'flexible';
2371
+ });
2372
+ operating_day_boundary = (_this$shopStore$get2 = this.shopStore.get('core')) === null || _this$shopStore$get2 === void 0 || (_this$shopStore$get2 = _this$shopStore$get2.core) === null || _this$shopStore$get2 === void 0 ? void 0 : _this$shopStore$get2.operating_day_boundary; // 如果有 hasFlexibleDuration,需要把动态时长商品(可能是多个,取最长的那个最低禁止购买时长)的最低禁止购买时长作为 split 的值
2373
+ maxBlockThreshold = 0;
2374
+ if (hasFlexibleDuration) {
2375
+ maxBlockThreshold = cartItems.reduce(function (max, item) {
2376
+ var _item$_productOrigin25;
2377
+ // 如果开启了灵活时长商品配置,则取 block_threshold 的值
2378
+ if ((_item$_productOrigin25 = item._productOrigin) !== null && _item$_productOrigin25 !== void 0 && (_item$_productOrigin25 = _item$_productOrigin25.duration) !== null && _item$_productOrigin25 !== void 0 && (_item$_productOrigin25 = _item$_productOrigin25.flexible_config) !== null && _item$_productOrigin25 !== void 0 && _item$_productOrigin25.is_enable_minimum_duration) {
2379
+ var _item$_productOrigin26;
2380
+ return Math.max(max, ((_item$_productOrigin26 = item._productOrigin) === null || _item$_productOrigin26 === void 0 || (_item$_productOrigin26 = _item$_productOrigin26.duration) === null || _item$_productOrigin26 === void 0 || (_item$_productOrigin26 = _item$_productOrigin26.flexible_config) === null || _item$_productOrigin26 === void 0 ? void 0 : _item$_productOrigin26.block_threshold) || 0);
2381
+ }
2382
+ return 0;
2383
+ }, 0);
2384
+ }
2385
+ // 计算容量的辅助函数
2386
+ calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2387
+ var _items$0$_resourceOri2;
2388
+ if (items.length === 0) return 0;
2389
+ // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
2390
+ var firstResource = (_items$0$_resourceOri2 = items[0]._resourceOrigin) === null || _items$0$_resourceOri2 === void 0 ? void 0 : _items$0$_resourceOri2[0].id;
2391
+ var sameResourceLength = items.filter(function (item) {
2392
+ var _item$_resourceOrigin2;
2393
+ return ((_item$_resourceOrigin2 = item._resourceOrigin) === null || _item$_resourceOrigin2 === void 0 ? void 0 : _item$_resourceOrigin2[0].id) === firstResource;
2394
+ }).length;
2395
+ if (sameResourceLength !== items.length) {
2396
+ return 1;
2397
+ }
2398
+ // 找出单个购物车里最大的需求 capacity 即可
2399
+ return Math.max.apply(Math, _toConsumableArray(items.map(function (item) {
2400
+ return getCapacityInfoByCartItem(item).currentCapacity || 1;
2401
+ })));
2402
+ }; // 如果是多个预约,去要求出几个 holder 下最大的需求容量capacity
2403
+ maxCapacity = 1;
2404
+ if (cartItems !== null && cartItems !== void 0 && cartItems[0].holder_id) {
2405
+ accountList.forEach(function (account) {
2406
+ var accountCartItems = _this13.store.cart.getCartByAccount(account.getId());
2407
+ var currentCapacity = calculateCapacityFromCartItems(accountCartItems);
2408
+ if (currentCapacity > maxCapacity) {
2409
+ maxCapacity = currentCapacity;
2410
+ }
2411
+ });
2412
+ } else {
2413
+ maxCapacity = calculateCapacityFromCartItems(cartItems);
2414
+ }
2415
+ arr = [];
2416
+ today = dayjs().startOf('day'); // 计算 start_date 到 end_date 之间的所有日期,遍历他们并且计算每一天的可用
2417
+ _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
2418
+ var currentDate, theDateResources, resourcesMap, timeSlots;
2419
+ return _regeneratorRuntime().wrap(function _loop2$(_context24) {
2420
+ while (1) switch (_context24.prev = _context24.next) {
2421
+ case 0:
2422
+ currentDate = i.format('YYYY-MM-DD');
2423
+ theDateResources = _this13.store.date.getResourcesListByDate(currentDate);
2424
+ resources.forEach(function (item) {
2425
+ var _theDateResources$fin2;
2426
+ item.times = (theDateResources === null || theDateResources === void 0 || (_theDateResources$fin2 = theDateResources.find(function (n) {
2427
+ return n.id === item.id;
2428
+ })) === null || _theDateResources$fin2 === void 0 ? void 0 : _theDateResources$fin2.times) || [];
2429
+ });
2430
+ resourcesMap = getResourcesMap(resources); // 如果日期已经过期则直接标记为不可用
2431
+ if (!i.isBefore(today)) {
2432
+ _context24.next = 7;
2433
+ break;
2434
+ }
2435
+ arr.push({
2436
+ date: currentDate,
2437
+ status: 'unavailable',
2438
+ week: i.format('ddd'),
2439
+ weekNum: i.day()
2440
+ });
2441
+ return _context24.abrupt("return", 1);
2442
+ case 7:
2443
+ timeSlots = getTimeSlicesByResources({
2444
+ resourceIds: resourceIds,
2445
+ resourcesMap: resourcesMap,
2446
+ duration: duration,
2447
+ currentDate: currentDate,
2448
+ split: 10,
2449
+ resourcesUseableMap: resourcesUseableMap,
2450
+ capacity: maxCapacity,
2451
+ cut_off_time: maxCutOffTime,
2452
+ hasFlexibleDuration: hasFlexibleDuration,
2453
+ operating_day_boundary: operating_day_boundary,
2454
+ maxBlockThreshold: maxBlockThreshold
2455
+ });
2456
+ if (timeSlots.length > 0) {
2457
+ arr.push({
2458
+ date: currentDate,
2459
+ status: 'available',
2460
+ week: i.format('ddd'),
2461
+ weekNum: i.day()
2462
+ });
2463
+ } else {
2464
+ arr.push({
2465
+ date: currentDate,
2466
+ status: 'unavailable',
2467
+ week: i.format('ddd'),
2468
+ weekNum: i.day()
2469
+ });
2470
+ }
2471
+ case 9:
2472
+ case "end":
2473
+ return _context24.stop();
2474
+ }
2475
+ }, _loop2);
2476
+ });
2477
+ i = dayjs(startDate);
2478
+ case 32:
2479
+ if (!i.isBefore(dayjs(endDate))) {
2480
+ _context25.next = 39;
2481
+ break;
2482
+ }
2483
+ return _context25.delegateYield(_loop2(), "t0", 34);
2484
+ case 34:
2485
+ if (!_context25.t0) {
2486
+ _context25.next = 36;
2487
+ break;
2488
+ }
2489
+ return _context25.abrupt("continue", 36);
2490
+ case 36:
2491
+ i = i.add(1, 'day');
2492
+ _context25.next = 32;
2493
+ break;
2494
+ case 39:
2495
+ return _context25.abrupt("return", arr);
2496
+ case 40:
2497
+ case "end":
2498
+ return _context25.stop();
2499
+ }
2500
+ }, _callee24, this);
2501
+ }));
2502
+ function getTimeSlotByAllResourcesForDate(_x19) {
2503
+ return _getTimeSlotByAllResourcesForDate.apply(this, arguments);
2504
+ }
2505
+ return getTimeSlotByAllResourcesForDate;
2506
+ }() // 提交时间切片,绑定到对应购物车的商品上,更新购物车---只有 duration 商品
2224
2507
  }, {
2225
2508
  key: "submitTimeSlot",
2226
2509
  value: function submitTimeSlot(timeSlots) {
2227
- var _this$shopStore$get2,
2228
- _this13 = this;
2510
+ var _this$shopStore$get3,
2511
+ _this14 = this;
2229
2512
  // 以账号为维度处理数据。购物车里每一项的 startTime应该是前一个商品的 endTime,如果是第一个商品则用 timeSlots.start_at
2230
2513
  var cartItems = this.store.cart.getItems().filter(function (n) {
2231
2514
  return !isNormalProduct(n._productOrigin);
@@ -2245,7 +2528,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2245
2528
  }, {});
2246
2529
 
2247
2530
  // 店铺营业结束时间
2248
- var operating_day_boundary = (_this$shopStore$get2 = this.shopStore.get('core')) === null || _this$shopStore$get2 === void 0 || (_this$shopStore$get2 = _this$shopStore$get2.core) === null || _this$shopStore$get2 === void 0 ? void 0 : _this$shopStore$get2.operating_day_boundary;
2531
+ var operating_day_boundary = (_this$shopStore$get3 = this.shopStore.get('core')) === null || _this$shopStore$get3 === void 0 || (_this$shopStore$get3 = _this$shopStore$get3.core) === null || _this$shopStore$get3 === void 0 ? void 0 : _this$shopStore$get3.operating_day_boundary;
2249
2532
 
2250
2533
  // 处理每个账号的商品
2251
2534
  Object.values(itemsByAccount).forEach(function (accountItems) {
@@ -2255,10 +2538,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2255
2538
  var osWarnTips = [];
2256
2539
  var newResources = cloneDeep(item._origin.resources);
2257
2540
  newResources.forEach(function (resource) {
2258
- var _item$_productOrigin17;
2541
+ var _item$_productOrigin27;
2259
2542
  // 如果商品配置的是灵活时长,开始时间设置为提交的时间,结束时间从资源的可用最晚时间和店铺营业结束时间里取一个最早的
2260
- if (((_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.type) === 'flexible') {
2261
- var _allResources$find, _item$_productOrigin18, _item$_productOrigin19;
2543
+ if (((_item$_productOrigin27 = item._productOrigin) === null || _item$_productOrigin27 === void 0 || (_item$_productOrigin27 = _item$_productOrigin27.duration) === null || _item$_productOrigin27 === void 0 ? void 0 : _item$_productOrigin27.type) === 'flexible') {
2544
+ var _allResources$find, _item$_productOrigin28, _item$_productOrigin29;
2262
2545
  item.duration = {
2263
2546
  type: 'minutes',
2264
2547
  value: 10
@@ -2268,14 +2551,67 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2268
2551
  var targetResourceTimes = allResources === null || allResources === void 0 || (_allResources$find = allResources.find(function (n) {
2269
2552
  return n.id === resource.id;
2270
2553
  })) === null || _allResources$find === void 0 ? void 0 : _allResources$find.times;
2554
+ // 找到最晚的 end_at 还没用,因为可能存在资源工作时间是 10:00-19:00,但是资源的 times 里有 16:30-19:00 被 block 的情况
2555
+ // 所以还需要排除掉 block 时间
2556
+ function getEarliestBlockedStartTime(_ref11) {
2557
+ var _earliestBlockStart;
2558
+ var currentStartTime = _ref11.currentStartTime,
2559
+ times = _ref11.times;
2560
+ var currentStart = dayjs(currentStartTime);
2561
+ var earliestBlockStart;
2562
+ var _iterator3 = _createForOfIteratorHelper(times || []),
2563
+ _step3;
2564
+ try {
2565
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2566
+ var _time$event_list;
2567
+ var time = _step3.value;
2568
+ var blockedTimes = (_time$event_list = time.event_list) === null || _time$event_list === void 0 ? void 0 : _time$event_list.filter(function (event) {
2569
+ return event.type !== 'schedule_event';
2570
+ });
2571
+ var _iterator4 = _createForOfIteratorHelper(blockedTimes || []),
2572
+ _step4;
2573
+ try {
2574
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
2575
+ var event = _step4.value;
2576
+ var eventStart = dayjs(event.start_at);
2577
+ var eventEnd = dayjs(event.end_at);
2578
+ if (eventStart.isBefore(currentStart) && eventEnd.isAfter(currentStart)) {
2579
+ return currentStart.format('YYYY-MM-DD HH:mm');
2580
+ }
2581
+ if (eventStart.isAfter(currentStart)) {
2582
+ if (!earliestBlockStart || eventStart.isBefore(earliestBlockStart)) {
2583
+ earliestBlockStart = eventStart;
2584
+ }
2585
+ }
2586
+ }
2587
+ } catch (err) {
2588
+ _iterator4.e(err);
2589
+ } finally {
2590
+ _iterator4.f();
2591
+ }
2592
+ }
2593
+ } catch (err) {
2594
+ _iterator3.e(err);
2595
+ } finally {
2596
+ _iterator3.f();
2597
+ }
2598
+ return (_earliestBlockStart = earliestBlockStart) === null || _earliestBlockStart === void 0 ? void 0 : _earliestBlockStart.format('YYYY-MM-DD HH:mm');
2599
+ }
2271
2600
  var resourcesEndTime = targetResourceTimes.reduce(function (acc, curr) {
2272
2601
  return dayjs(curr.end_at).isAfter(dayjs(acc.end_at)) ? curr : acc;
2273
2602
  }, targetResourceTimes[0]);
2603
+ var earliestBlockedStartTime = getEarliestBlockedStartTime({
2604
+ currentStartTime: currentStartTime,
2605
+ times: targetResourceTimes
2606
+ });
2274
2607
 
2275
2608
  // 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
2276
2609
  var resourceDate = dayjs(resourcesEndTime.end_at).format('YYYY-MM-DD');
2277
2610
  var operatingBoundaryDateTime = "".concat(resourceDate, " ").concat(operating_day_boundary.type === 'start_time' ? '23:59' : operating_day_boundary.time);
2278
- var endTime = dayjs(resourcesEndTime.end_at).isBefore(dayjs(operatingBoundaryDateTime)) ? resourcesEndTime.end_at : operatingBoundaryDateTime;
2611
+ var endTimeCandidates = [resourcesEndTime.end_at, operatingBoundaryDateTime].concat(_toConsumableArray(earliestBlockedStartTime ? [earliestBlockedStartTime] : []));
2612
+ var endTime = endTimeCandidates.reduce(function (earliest, value) {
2613
+ return dayjs(value).isBefore(dayjs(earliest)) ? value : earliest;
2614
+ }, endTimeCandidates[0]);
2279
2615
  // 修复:如果 endTime 只是时间格式(如 "17:00"),需要加上日期
2280
2616
  var formattedEndTime;
2281
2617
  if (typeof endTime === 'string' && endTime.includes(':') && !endTime.includes(' ') && !endTime.includes('T')) {
@@ -2288,19 +2624,19 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2288
2624
  resource.endTime = formattedEndTime.format('YYYY-MM-DD HH:mm');
2289
2625
  // 如果是动态时长商品,并且当前选择的时间的结束时间小于了最低提示时长(warningThreshold),则追加一个提示
2290
2626
  // 如果currentStartTime + warningThreshold 大于 currentEndTime,且 osWarnTips 没有pisell2.product.card.closing-soon.warning 这一项,则加入这一项
2291
- if ((_item$_productOrigin18 = item._productOrigin) !== null && _item$_productOrigin18 !== void 0 && (_item$_productOrigin18 = _item$_productOrigin18.duration) !== null && _item$_productOrigin18 !== void 0 && (_item$_productOrigin18 = _item$_productOrigin18.flexible_config) !== null && _item$_productOrigin18 !== void 0 && _item$_productOrigin18.is_enable_minimum_duration && dayjs(currentStartTime).add(((_item$_productOrigin19 = item._productOrigin) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.duration) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.flexible_config) === null || _item$_productOrigin19 === void 0 ? void 0 : _item$_productOrigin19.warning_threshold) || 0, 'minutes').isAfter(dayjs(formattedEndTime))) {
2627
+ if ((_item$_productOrigin28 = item._productOrigin) !== null && _item$_productOrigin28 !== void 0 && (_item$_productOrigin28 = _item$_productOrigin28.duration) !== null && _item$_productOrigin28 !== void 0 && (_item$_productOrigin28 = _item$_productOrigin28.flexible_config) !== null && _item$_productOrigin28 !== void 0 && _item$_productOrigin28.is_enable_minimum_duration && dayjs(currentStartTime).add(((_item$_productOrigin29 = item._productOrigin) === null || _item$_productOrigin29 === void 0 || (_item$_productOrigin29 = _item$_productOrigin29.duration) === null || _item$_productOrigin29 === void 0 || (_item$_productOrigin29 = _item$_productOrigin29.flexible_config) === null || _item$_productOrigin29 === void 0 ? void 0 : _item$_productOrigin29.warning_threshold) || 0, 'minutes').isAfter(dayjs(formattedEndTime))) {
2292
2628
  if (!osWarnTips.includes('pisell2.product.card.closing-soon.warning')) {
2293
2629
  osWarnTips.push('pisell2.product.card.closing-soon.warning');
2294
2630
  }
2295
2631
  }
2296
2632
  } else {
2297
- var _item$_productOrigin20;
2633
+ var _item$_productOrigin30;
2298
2634
  resource.startTime = currentStartTime;
2299
- resource.endTime = dayjs(currentStartTime).add(((_item$_productOrigin20 = item._productOrigin) === null || _item$_productOrigin20 === void 0 || (_item$_productOrigin20 = _item$_productOrigin20.duration) === null || _item$_productOrigin20 === void 0 ? void 0 : _item$_productOrigin20.value) || 10, 'minutes').format('YYYY-MM-DD HH:mm');
2635
+ resource.endTime = dayjs(currentStartTime).add(((_item$_productOrigin30 = item._productOrigin) === null || _item$_productOrigin30 === void 0 || (_item$_productOrigin30 = _item$_productOrigin30.duration) === null || _item$_productOrigin30 === void 0 ? void 0 : _item$_productOrigin30.value) || 10, 'minutes').format('YYYY-MM-DD HH:mm');
2300
2636
  }
2301
2637
  // delete resource.times;
2302
2638
  });
2303
- _this13.store.cart.updateItem({
2639
+ _this14.store.cart.updateItem({
2304
2640
  _id: item._id,
2305
2641
  resources: newResources,
2306
2642
  osWarnTips: osWarnTips
@@ -2344,42 +2680,42 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2344
2680
  }, {
2345
2681
  key: "openProductDetail",
2346
2682
  value: function () {
2347
- var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(productId) {
2683
+ var _openProductDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(productId) {
2348
2684
  var targetProductData, newScheduleArr, dateRange;
2349
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2350
- while (1) switch (_context24.prev = _context24.next) {
2685
+ return _regeneratorRuntime().wrap(function _callee25$(_context26) {
2686
+ while (1) switch (_context26.prev = _context26.next) {
2351
2687
  case 0:
2352
- _context24.next = 2;
2688
+ _context26.next = 2;
2353
2689
  return this.store.products.getProduct(productId);
2354
2690
  case 2:
2355
- targetProductData = _context24.sent;
2691
+ targetProductData = _context26.sent;
2356
2692
  if (!targetProductData) {
2357
- _context24.next = 17;
2693
+ _context26.next = 17;
2358
2694
  break;
2359
2695
  }
2360
2696
  this.store.currentProduct = targetProductData;
2361
2697
  this.store.currentProductMeta = {};
2362
2698
  // 资源预加载,如果是 duration 类型的商品,且是先选日期的流程,在这里预拉取资源数据
2363
2699
  if (!targetProductData['schedule.ids']) {
2364
- _context24.next = 12;
2700
+ _context26.next = 12;
2365
2701
  break;
2366
2702
  }
2367
2703
  newScheduleArr = this.getScheduleDataByIds(targetProductData['schedule.ids']);
2368
2704
  if (!this.store.currentProductMeta) this.store.currentProductMeta = {};
2369
2705
  this.store.currentProductMeta.schedule = newScheduleArr;
2370
- _context24.next = 17;
2706
+ _context26.next = 17;
2371
2707
  break;
2372
2708
  case 12:
2373
2709
  if (!targetProductData.duration) {
2374
- _context24.next = 17;
2710
+ _context26.next = 17;
2375
2711
  break;
2376
2712
  }
2377
2713
  dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2378
2714
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2379
- _context24.next = 16;
2715
+ _context26.next = 16;
2380
2716
  break;
2381
2717
  }
2382
- return _context24.abrupt("return");
2718
+ return _context26.abrupt("return");
2383
2719
  case 16:
2384
2720
  // this.store.date.getResourceDates({
2385
2721
  // query: {
@@ -2395,11 +2731,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2395
2731
  });
2396
2732
  case 17:
2397
2733
  case "end":
2398
- return _context24.stop();
2734
+ return _context26.stop();
2399
2735
  }
2400
- }, _callee24, this);
2736
+ }, _callee25, this);
2401
2737
  }));
2402
- function openProductDetail(_x19) {
2738
+ function openProductDetail(_x20) {
2403
2739
  return _openProductDetail.apply(this, arguments);
2404
2740
  }
2405
2741
  return openProductDetail;
@@ -2416,14 +2752,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2416
2752
  // 通过商品和 schedule 来获取视频可用的时间片、时间片内资源可用的数据
2417
2753
  }, {
2418
2754
  key: "getTimeslotBySchedule",
2419
- value: function getTimeslotBySchedule(_ref10) {
2755
+ value: function getTimeslotBySchedule(_ref12) {
2420
2756
  var _this$store$currentPr2,
2421
2757
  _targetProductData$pr,
2422
- _this14 = this;
2423
- var date = _ref10.date,
2424
- scheduleIds = _ref10.scheduleIds,
2425
- resources = _ref10.resources,
2426
- product = _ref10.product;
2758
+ _this15 = this;
2759
+ var date = _ref12.date,
2760
+ scheduleIds = _ref12.scheduleIds,
2761
+ resources = _ref12.resources,
2762
+ product = _ref12.product;
2427
2763
  var targetProduct = this.store.currentProduct;
2428
2764
  // 如果外面传递了product 优先用外面的
2429
2765
  var targetProductData = product || targetProduct;
@@ -2457,25 +2793,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2457
2793
  if (!aIsCombined && bIsCombined) return -1;
2458
2794
  return 0;
2459
2795
  });
2460
-
2461
- // 找到当前商品下第一个启用的资源id
2462
- var firstEnabledResourceId = targetProductData === null || targetProductData === void 0 || (_targetProductData$pr = targetProductData.product_resource) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.resources) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.find(function (n) {
2796
+ var enabledResourceTypeConfigs = (targetProductData === null || targetProductData === void 0 || (_targetProductData$pr = targetProductData.product_resource) === null || _targetProductData$pr === void 0 || (_targetProductData$pr = _targetProductData$pr.resources) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.filter(function (n) {
2463
2797
  return n.status === 1;
2464
- })) === null || _targetProductData$pr === void 0 ? void 0 : _targetProductData$pr.id;
2798
+ })) || [];
2799
+ var resourceTypeConfigById = new Map(enabledResourceTypeConfigs.map(function (n) {
2800
+ return [n.id, n];
2801
+ }));
2465
2802
 
2466
2803
  // 计算每个日程切片下日程可用的资源的容量总和
2467
2804
  var formatScheduleTimeSlots = scheduleTimeSlots.map(function (item) {
2468
2805
  // 用来计算资源的可使用情况,针对单个schedule 时间片
2469
2806
  var resourcesUseableMap = {};
2470
- var count = 0;
2471
- var bookingLeft = 0;
2472
- var summaryCount = 0;
2807
+ var statsByResourceType = {};
2808
+ enabledResourceTypeConfigs.forEach(function (cfg) {
2809
+ statsByResourceType[cfg.id] = {
2810
+ count: 0,
2811
+ left: 0,
2812
+ summaryCount: 0,
2813
+ summaryConfigCount: 0
2814
+ };
2815
+ });
2816
+
2473
2817
  // 遍历所有资源
2474
2818
  allProductResources === null || allProductResources === void 0 || allProductResources.forEach(function (m) {
2819
+ var currentResourceTypeConfig = resourceTypeConfigById.get(m.form_id);
2820
+ if (!currentResourceTypeConfig) return;
2821
+
2475
2822
  // 遍历所有资源的上工时间片
2476
- var currentResourcesCount = 0;
2477
- var currentResourcesSummaryCount = 0;
2478
- var currentResourcesTimeSlotCanUsedArr = [];
2823
+ var currentResourceMaxRemainingCapacity = 0;
2824
+ var isAllTimeSlicesUsable = true;
2479
2825
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2480
2826
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2481
2827
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
@@ -2483,14 +2829,27 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2483
2829
  // n.start_at 是 2025-06-30 15:00 end_at 2025-06-30 17:00
2484
2830
  // item.start 是 2025-06-30 16:00 item.end 是 2025-06-30 19:00
2485
2831
  // 需要判断 n.start_at 和 n.end_at 是否在 item.start 和 item.end 之间
2486
- // 如果 n.start_at 和 n.end_at 在 item.start 和 item.end 有交集,则此时间需要计算
2832
+ // 如果是仅用于计算的资源, n.start_at 和 n.end_at 在 item.start 和 item.end 有交集,则此时间需要计算
2833
+ // https://project.feishu.cn/v2qint/bug/detail/6657165010
2487
2834
  var mTimes = m.times.filter(function (n) {
2488
- return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2835
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || m.onlyComputed && dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2489
2836
  });
2490
2837
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2491
2838
  if (mTimes.length === 0) {
2492
2839
  return;
2493
2840
  }
2841
+
2842
+ // 统计该资源类型在这个时间片的“配置容量”(无占用),只统计上工的资源
2843
+ if (!m.onlyComputed) {
2844
+ var _currentStats = statsByResourceType[m.form_id] || {
2845
+ count: 0,
2846
+ left: 0,
2847
+ summaryCount: 0,
2848
+ summaryConfigCount: 0
2849
+ };
2850
+ if (currentResourceTypeConfig.type === 'multiple') _currentStats.summaryConfigCount += m.capacity;else _currentStats.summaryConfigCount += 1;
2851
+ statsByResourceType[m.form_id] = _currentStats;
2852
+ }
2494
2853
  mTimes.forEach(function (childTiem) {
2495
2854
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
2496
2855
  var res = getIsUsableByTimeItem({
@@ -2509,32 +2868,43 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2509
2868
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
2510
2869
  resourcesUseableMap[m.id] = res.usable;
2511
2870
  }
2512
- if (res.usable && res.remainingCapacity >= count && !m.onlyComputed) {
2513
- currentResourcesCount = res.remainingCapacity;
2514
- }
2515
- if (res.usable && !m.onlyComputed && res.remainingCapacity >= currentResourcesSummaryCount) {
2516
- currentResourcesSummaryCount = res.remainingCapacity;
2871
+ if (!res.usable) isAllTimeSlicesUsable = false;
2872
+ if (res.usable && !m.onlyComputed) {
2873
+ if (res.remainingCapacity > currentResourceMaxRemainingCapacity) currentResourceMaxRemainingCapacity = res.remainingCapacity;
2517
2874
  }
2518
- currentResourcesTimeSlotCanUsedArr.push(res.usable);
2519
2875
  });
2520
- // 在已经选定时间的情况下,只要canUseTime如果有一个 false 那就不可用
2521
- if (!currentResourcesTimeSlotCanUsedArr.some(function (n) {
2522
- return n === false;
2523
- }) &&
2524
- // 只统计第一种资源的容量和 left
2525
- m.form_id === firstEnabledResourceId) {
2526
- if (currentResourcesCount >= count) {
2527
- count = currentResourcesCount;
2528
- }
2529
- if (!m.onlyComputed) {
2530
- bookingLeft += 1;
2531
- summaryCount += currentResourcesSummaryCount;
2532
- }
2876
+ if (!isAllTimeSlicesUsable) return;
2877
+ if (m.onlyComputed) return;
2878
+ var currentStats = statsByResourceType[m.form_id] || {
2879
+ count: 0,
2880
+ left: 0,
2881
+ summaryCount: 0,
2882
+ summaryConfigCount: 0
2883
+ };
2884
+ currentStats.left += 1;
2885
+ if (currentResourceTypeConfig.type === 'multiple') {
2886
+ currentStats.summaryCount += currentResourceMaxRemainingCapacity;
2533
2887
  }
2888
+ if (currentResourceMaxRemainingCapacity > currentStats.count) currentStats.count = currentResourceMaxRemainingCapacity;
2889
+ // else {
2890
+ // 单个预约:一个资源只计 1,不关心剩余容量
2891
+ // currentStats.summaryCount += 1;
2892
+ // if (currentStats.count < 1) currentStats.count = 1;
2893
+ //}
2894
+
2895
+ statsByResourceType[m.form_id] = currentStats;
2534
2896
  });
2535
2897
  // 容量检测
2536
- var cartItems = _this14.store.cart.getItems();
2898
+ var cartItems = _this15.store.cart.getItems();
2537
2899
  productResources.forEach(function (n) {
2900
+ var currentResourceTypeConfig = resourceTypeConfigById.get(n.id);
2901
+ if (!currentResourceTypeConfig) return;
2902
+ var currentStats = statsByResourceType[n.id] || {
2903
+ count: 0,
2904
+ left: 0,
2905
+ summaryCount: 0
2906
+ };
2907
+
2538
2908
  // 单个预约检测规则:
2539
2909
  // 1、跟我一样的商品同一时间在购物车里不可以超过我最少的那种资源的关联的资源个数
2540
2910
  // 2、跟我不一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,她配置了几个资源的个数+我配置了几个资源的个数,然后购物车里有几个这样的商品,对应的资源做一个去重,不超过这个去重以后的总数
@@ -2545,20 +2915,24 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2545
2915
  var _m$_productOrigin, _targetProductData$id;
2546
2916
  return ((_m$_productOrigin = m._productOrigin) === null || _m$_productOrigin === void 0 || (_m$_productOrigin = _m$_productOrigin.id) === null || _m$_productOrigin === void 0 ? void 0 : _m$_productOrigin.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id = targetProductData.id) === null || _targetProductData$id === void 0 ? void 0 : _targetProductData$id.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2547
2917
  });
2548
- if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
2549
- bookingLeft = 0;
2550
- count = 0;
2551
- summaryCount = 0;
2918
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > currentStats.left) {
2919
+ currentStats.left = 0;
2920
+ currentStats.count = 0;
2921
+ currentStats.summaryCount = 0;
2552
2922
  }
2553
2923
  // 规则 2
2554
2924
  var otherCartItems = cartItems.filter(function (m) {
2555
- var _m$_productOrigin2, _targetProductData$id2;
2556
- return ((_m$_productOrigin2 = m._productOrigin) === null || _m$_productOrigin2 === void 0 || (_m$_productOrigin2 = _m$_productOrigin2.id) === null || _m$_productOrigin2 === void 0 ? void 0 : _m$_productOrigin2.toString()) !== (targetProductData === null || targetProductData === void 0 || (_targetProductData$id2 = targetProductData.id) === null || _targetProductData$id2 === void 0 ? void 0 : _targetProductData$id2.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2925
+ var _m$_productOrigin2, _targetProductData$id2, _m$_productOrigin3;
2926
+ var isTimeMatch = ((_m$_productOrigin2 = m._productOrigin) === null || _m$_productOrigin2 === void 0 || (_m$_productOrigin2 = _m$_productOrigin2.id) === null || _m$_productOrigin2 === void 0 ? void 0 : _m$_productOrigin2.toString()) !== (targetProductData === null || targetProductData === void 0 || (_targetProductData$id2 = targetProductData.id) === null || _targetProductData$id2 === void 0 ? void 0 : _targetProductData$id2.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2927
+ var isResourceMatch = (_m$_productOrigin3 = m._productOrigin) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.product_resource) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.resources) === null || _m$_productOrigin3 === void 0 ? void 0 : _m$_productOrigin3.find(function (m) {
2928
+ return m.type === n.type && m.status === 1;
2929
+ });
2930
+ return isTimeMatch && isResourceMatch;
2557
2931
  });
2558
2932
  otherCartItems.forEach(function (m) {
2559
- var _m$_productOrigin3;
2560
- var sameTypeResources = (_m$_productOrigin3 = m._productOrigin) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.product_resource) === null || _m$_productOrigin3 === void 0 || (_m$_productOrigin3 = _m$_productOrigin3.resources) === null || _m$_productOrigin3 === void 0 ? void 0 : _m$_productOrigin3.find(function (m) {
2561
- return m.type === n.type;
2933
+ var _m$_productOrigin4;
2934
+ var sameTypeResources = (_m$_productOrigin4 = m._productOrigin) === null || _m$_productOrigin4 === void 0 || (_m$_productOrigin4 = _m$_productOrigin4.product_resource) === null || _m$_productOrigin4 === void 0 || (_m$_productOrigin4 = _m$_productOrigin4.resources) === null || _m$_productOrigin4 === void 0 ? void 0 : _m$_productOrigin4.find(function (m) {
2935
+ return m.type === n.type && m.status === 1;
2562
2936
  });
2563
2937
  var sameTypeResourcesSet = new Set([].concat(_toConsumableArray((sameTypeResources === null || sameTypeResources === void 0 ? void 0 : sameTypeResources.optional_resource) || []), _toConsumableArray((sameTypeResources === null || sameTypeResources === void 0 ? void 0 : sameTypeResources.default_resource) || [])));
2564
2938
  // 把sameTypeResourcesSet 加到currentResourcesSet
@@ -2567,7 +2941,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2567
2941
  });
2568
2942
  });
2569
2943
  // 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
2570
- var currentDataResources = _this14.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
2944
+ var currentDataResources = _this15.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
2571
2945
  currentDataResources === null || currentDataResources === void 0 || currentDataResources.forEach(function (m) {
2572
2946
  if (currentResourcesSet.has(m.id)) {
2573
2947
  var mTimes = m.times.filter(function (n) {
@@ -2581,16 +2955,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2581
2955
  }
2582
2956
  });
2583
2957
  if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
2584
- bookingLeft = 0;
2585
- count = 0;
2586
- summaryCount = 0;
2958
+ currentStats.left = 0;
2959
+ currentStats.count = 0;
2960
+ currentStats.summaryCount = 0;
2587
2961
  }
2588
2962
  } else {
2589
2963
  // 多个预约的检测规则:
2590
2964
  // 规则1、跟我一样的商品同一时间在购物车需要的容量总数不可以超过我配置的资源的 capacity 之和
2591
2965
  var _sameCartItems = cartItems.filter(function (m) {
2592
- var _m$_productOrigin4, _targetProductData$id3;
2593
- return ((_m$_productOrigin4 = m._productOrigin) === null || _m$_productOrigin4 === void 0 || (_m$_productOrigin4 = _m$_productOrigin4.id) === null || _m$_productOrigin4 === void 0 ? void 0 : _m$_productOrigin4.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id3 = targetProductData.id) === null || _targetProductData$id3 === void 0 ? void 0 : _targetProductData$id3.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2966
+ var _m$_productOrigin5, _targetProductData$id3;
2967
+ return ((_m$_productOrigin5 = m._productOrigin) === null || _m$_productOrigin5 === void 0 || (_m$_productOrigin5 = _m$_productOrigin5.id) === null || _m$_productOrigin5 === void 0 ? void 0 : _m$_productOrigin5.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id3 = targetProductData.id) === null || _targetProductData$id3 === void 0 ? void 0 : _targetProductData$id3.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2594
2968
  });
2595
2969
  var sameCartNeedCapacity = _sameCartItems.reduce(function (acc, curr) {
2596
2970
  return acc + getCapacityInfoByCartItem(curr).currentCapacity;
@@ -2599,9 +2973,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2599
2973
  return !curr.onlyComputed ? acc + curr.capacity || 0 : acc;
2600
2974
  }, 0);
2601
2975
  if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2602
- bookingLeft = 0;
2603
- count = 0;
2604
- summaryCount = 0;
2976
+ currentStats.left = 0;
2977
+ currentStats.count = 0;
2978
+ currentStats.summaryCount = 0;
2605
2979
  }
2606
2980
  // 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
2607
2981
  // const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
@@ -2615,8 +2989,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2615
2989
  return !m.onlyComputed;
2616
2990
  }));
2617
2991
  otherSameTimesCartItems.forEach(function (m) {
2618
- var _m$_productOrigin5;
2619
- var productResources = getResourcesByProduct(getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []), ((_m$_productOrigin5 = m._productOrigin) === null || _m$_productOrigin5 === void 0 || (_m$_productOrigin5 = _m$_productOrigin5.product_resource) === null || _m$_productOrigin5 === void 0 ? void 0 : _m$_productOrigin5.resources) || [], selectedResources, 1);
2992
+ var _m$_productOrigin6;
2993
+ var productResources = getResourcesByProduct(getResourcesMap((targetResourceDate === null || targetResourceDate === void 0 ? void 0 : targetResourceDate.resource) || []), ((_m$_productOrigin6 = m._productOrigin) === null || _m$_productOrigin6 === void 0 || (_m$_productOrigin6 = _m$_productOrigin6.product_resource) === null || _m$_productOrigin6 === void 0 ? void 0 : _m$_productOrigin6.resources) || [], selectedResources, 1);
2620
2994
  productResources.forEach(function (m) {
2621
2995
  if (m.id === n.id) {
2622
2996
  m.renderList.forEach(function (n) {
@@ -2651,7 +3025,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2651
3025
  start_at: dayjs(item.start),
2652
3026
  end_at: dayjs(item.end)
2653
3027
  })) {
2654
- mSet.set(m.id, m.pax || 1);
3028
+ var _m$pax;
3029
+ mSet.set(m.id, (_m$pax = m.pax) !== null && _m$pax !== void 0 ? _m$pax : 1);
2655
3030
  }
2656
3031
  });
2657
3032
  });
@@ -2662,22 +3037,61 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2662
3037
  }, 0);
2663
3038
  // 如果已使用容量超过了当前类型资源的容量,则不可用
2664
3039
  if (otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2665
- bookingLeft = 0;
2666
- count = 0;
2667
- summaryCount = 0;
3040
+ currentStats.left = 0;
3041
+ currentStats.count = 0;
3042
+ currentStats.summaryCount = 0;
2668
3043
  }
2669
3044
  }
3045
+ statsByResourceType[n.id] = currentStats;
2670
3046
  });
2671
3047
  var startDayJs = dayjs(item.start);
2672
3048
  var endDayJs = dayjs(item.end);
3049
+
3050
+ // 选择“瓶颈资源类型”:multiple 取 summaryCount 最小,single 取 left 最小
3051
+ var bottleneckResourceTypeId;
3052
+ var bottleneckValue = Infinity;
3053
+ enabledResourceTypeConfigs.forEach(function (cfg) {
3054
+ var stats = statsByResourceType[cfg.id] || {
3055
+ count: 0,
3056
+ left: 0,
3057
+ summaryCount: 0,
3058
+ summaryConfigCount: 0
3059
+ };
3060
+ var value = cfg.type === 'multiple' ? stats.summaryCount : stats.left;
3061
+ if (value < bottleneckValue) {
3062
+ bottleneckValue = value;
3063
+ bottleneckResourceTypeId = cfg.id;
3064
+ }
3065
+ });
3066
+ var bottleneckStats = bottleneckResourceTypeId !== undefined ? statsByResourceType[bottleneckResourceTypeId] || {
3067
+ count: 0,
3068
+ left: 0,
3069
+ summaryCount: 0,
3070
+ summaryConfigCount: 0
3071
+ } : {
3072
+ count: 0,
3073
+ left: 0,
3074
+ summaryCount: 0,
3075
+ summaryConfigCount: 0
3076
+ };
3077
+ var bottleneckConfig = bottleneckResourceTypeId !== undefined ? resourceTypeConfigById.get(bottleneckResourceTypeId) : undefined;
3078
+ var status = 'sold_out';
3079
+ if (bottleneckStats.left === 0) status = 'sold_out';else if (!bottleneckConfig || bottleneckStats.summaryConfigCount === 0) status = 'sold_out';else if (bottleneckConfig.type === 'multiple') {
3080
+ var usageRatio = bottleneckStats.summaryCount / bottleneckStats.summaryConfigCount;
3081
+ if (usageRatio > 0.5) status = 'lots_of_space';else if (bottleneckStats.summaryCount > 0) status = 'filling_up_fast';else status = 'sold_out';
3082
+ } else {
3083
+ var _usageRatio = bottleneckStats.left / bottleneckStats.summaryConfigCount;
3084
+ if (_usageRatio > 0.5) status = 'lots_of_space';else if (bottleneckStats.count > 0) status = 'filling_up_fast';else status = 'sold_out';
3085
+ }
2673
3086
  return {
2674
3087
  start_time: startDayJs.format('HH:mm'),
2675
3088
  end_time: endDayJs.format('HH:mm'),
2676
3089
  start_at: startDayJs,
2677
3090
  end_at: endDayJs,
2678
- count: count,
2679
- left: bookingLeft,
2680
- summaryCount: summaryCount
3091
+ count: bottleneckStats.count,
3092
+ left: bottleneckStats.left,
3093
+ summaryCount: bottleneckStats.summaryCount,
3094
+ status: status
2681
3095
  };
2682
3096
  });
2683
3097
  return formatScheduleTimeSlots;
@@ -2718,7 +3132,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2718
3132
  }));
2719
3133
 
2720
3134
  // 与其他资源的时间段求交集
2721
- var _loop2 = function _loop2() {
3135
+ var _loop3 = function _loop3() {
2722
3136
  var currentResourceSlots = allTimeSlots[i];
2723
3137
  var intersections = [];
2724
3138
 
@@ -2747,7 +3161,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2747
3161
  }));
2748
3162
  };
2749
3163
  for (var i = 1; i < allTimeSlots.length; i++) {
2750
- if (_loop2()) continue;
3164
+ if (_loop3()) continue;
2751
3165
  }
2752
3166
 
2753
3167
  // 格式化返回结果
@@ -2763,7 +3177,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2763
3177
  }, {
2764
3178
  key: "checkMaxDurationCapacity",
2765
3179
  value: function checkMaxDurationCapacity() {
2766
- var _this15 = this;
3180
+ var _this16 = this;
2767
3181
  var cartItems = this.store.cart.getItems().filter(function (item) {
2768
3182
  return !isNormalProduct(item._productOrigin);
2769
3183
  });
@@ -2802,6 +3216,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2802
3216
  itemsByResourceType[resourceCode] = [];
2803
3217
  }
2804
3218
  // 避免重复添加同一个商品
3219
+ // 如果之前添加过的依赖相同资源的跟我现在是同一个 holder,也不需要重复添加
3220
+ if (itemsByResourceType[resourceCode].find(function (item) {
3221
+ return item.holder_id === cartItem.holder_id;
3222
+ })) {
3223
+ return;
3224
+ }
2805
3225
  if (!itemsByResourceType[resourceCode].find(function (item) {
2806
3226
  return item._id === cartItem._id;
2807
3227
  })) {
@@ -2853,7 +3273,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2853
3273
  var processedCartItemIds = new Set();
2854
3274
 
2855
3275
  // 先检查所有资源类型,收集可用数量信息
2856
- var _loop3 = function _loop3() {
3276
+ var _loop4 = function _loop4() {
2857
3277
  var _resourceTypeConfig;
2858
3278
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
2859
3279
  resourceCode = _Object$entries$_i[0],
@@ -2900,12 +3320,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2900
3320
  // 检查资源类型(单个预约 vs 多个预约)
2901
3321
  // 从商品配置中获取资源类型信息
2902
3322
  var resourceTypeConfig = null;
2903
- var _iterator3 = _createForOfIteratorHelper(items),
2904
- _step3;
3323
+ var _iterator5 = _createForOfIteratorHelper(items),
3324
+ _step5;
2905
3325
  try {
2906
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3326
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
2907
3327
  var _cartItem$_productOri12;
2908
- var cartItem = _step3.value;
3328
+ var cartItem = _step5.value;
2909
3329
  if ((_cartItem$_productOri12 = cartItem._productOrigin) !== null && _cartItem$_productOri12 !== void 0 && (_cartItem$_productOri12 = _cartItem$_productOri12.product_resource) !== null && _cartItem$_productOri12 !== void 0 && _cartItem$_productOri12.resources) {
2910
3330
  resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
2911
3331
  return r.code === resourceCode && r.status === 1;
@@ -2914,9 +3334,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2914
3334
  }
2915
3335
  }
2916
3336
  } catch (err) {
2917
- _iterator3.e(err);
3337
+ _iterator5.e(err);
2918
3338
  } finally {
2919
- _iterator3.f();
3339
+ _iterator5.f();
2920
3340
  }
2921
3341
  var isMultipleBooking = ((_resourceTypeConfig = resourceTypeConfig) === null || _resourceTypeConfig === void 0 ? void 0 : _resourceTypeConfig.type) === 'multiple';
2922
3342
  var totalAvailable;
@@ -2969,7 +3389,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2969
3389
  }));
2970
3390
 
2971
3391
  // 找到所有资源都可用的时间段
2972
- var commonTimeSlots = _this15.findCommonAvailableTimeSlots(resourcesOfThisType);
3392
+ var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
2973
3393
  console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
2974
3394
  if (commonTimeSlots.length === 0) {
2975
3395
  console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
@@ -3000,7 +3420,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3000
3420
  },
3001
3421
  _ret2;
3002
3422
  for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
3003
- _ret2 = _loop3();
3423
+ _ret2 = _loop4();
3004
3424
  if (_ret2) return _ret2.v;
3005
3425
  }
3006
3426
 
@@ -3044,7 +3464,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3044
3464
  cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3045
3465
  });
3046
3466
  // 检查每个时间段是否有足够的资源容量
3047
- var _loop4 = function _loop4() {
3467
+ var _loop5 = function _loop5() {
3048
3468
  var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
3049
3469
  timeSlotKey = _Object$entries2$_i[0],
3050
3470
  itemsInTimeSlot = _Object$entries2$_i[1];
@@ -3062,8 +3482,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3062
3482
  var resourcesIdSet = new Set();
3063
3483
 
3064
3484
  // 获取资源数据
3065
- var dateRange = _this15.store.date.getDateRange();
3066
- var resourcesDates = _this15.store.date.getDateList();
3485
+ var dateRange = _this16.store.date.getDateRange();
3486
+ var resourcesDates = _this16.store.date.getDateList();
3067
3487
  var targetResourceDate = resourcesDates.find(function (n) {
3068
3488
  return n.date === startDate;
3069
3489
  });
@@ -3100,7 +3520,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3100
3520
  },
3101
3521
  _ret3;
3102
3522
  for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
3103
- _ret3 = _loop4();
3523
+ _ret3 = _loop5();
3104
3524
  if (_ret3 === 0) continue;
3105
3525
  if (_ret3) return _ret3.v;
3106
3526
  }
@@ -3119,17 +3539,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3119
3539
  */
3120
3540
  }, {
3121
3541
  key: "convertProductToCartItem",
3122
- value: function convertProductToCartItem(_ref11) {
3123
- var product = _ref11.product,
3124
- date = _ref11.date,
3125
- account = _ref11.account;
3126
- var _ref12 = product || {},
3127
- bundle = _ref12.bundle,
3128
- options = _ref12.options,
3129
- origin = _ref12.origin,
3130
- product_variant_id = _ref12.product_variant_id,
3131
- _ref12$quantity = _ref12.quantity,
3132
- quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
3542
+ value: function convertProductToCartItem(_ref13) {
3543
+ var product = _ref13.product,
3544
+ date = _ref13.date,
3545
+ account = _ref13.account;
3546
+ var _ref14 = product || {},
3547
+ bundle = _ref14.bundle,
3548
+ options = _ref14.options,
3549
+ origin = _ref14.origin,
3550
+ product_variant_id = _ref14.product_variant_id,
3551
+ _ref14$quantity = _ref14.quantity,
3552
+ quantity = _ref14$quantity === void 0 ? 1 : _ref14$quantity;
3133
3553
 
3134
3554
  // 处理商品数据,类似 addProductToCart 中的逻辑
3135
3555
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
@@ -3184,11 +3604,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3184
3604
  }
3185
3605
  }, {
3186
3606
  key: "checkMaxDurationCapacityForDetailNums",
3187
- value: function checkMaxDurationCapacityForDetailNums(_ref13) {
3188
- var _this16 = this;
3189
- var product = _ref13.product,
3190
- date = _ref13.date,
3191
- account = _ref13.account;
3607
+ value: function checkMaxDurationCapacityForDetailNums(_ref15) {
3608
+ var _this17 = this;
3609
+ var product = _ref15.product,
3610
+ date = _ref15.date,
3611
+ account = _ref15.account;
3192
3612
  var cartItems = this.store.cart.getItems().filter(function (item) {
3193
3613
  return !isNormalProduct(item._productOrigin);
3194
3614
  });
@@ -3286,7 +3706,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3286
3706
  var processedCartItemIds = new Set();
3287
3707
 
3288
3708
  // 先检查所有资源类型,收集可用数量信息
3289
- var _loop5 = function _loop5() {
3709
+ var _loop6 = function _loop6() {
3290
3710
  var _resourceTypeConfig2;
3291
3711
  var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
3292
3712
  resourceCode = _Object$entries3$_i[0],
@@ -3333,12 +3753,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3333
3753
  // 检查资源类型(单个预约 vs 多个预约)
3334
3754
  // 从商品配置中获取资源类型信息
3335
3755
  var resourceTypeConfig = null;
3336
- var _iterator4 = _createForOfIteratorHelper(items),
3337
- _step4;
3756
+ var _iterator6 = _createForOfIteratorHelper(items),
3757
+ _step6;
3338
3758
  try {
3339
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
3759
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
3340
3760
  var _cartItem$_productOri15;
3341
- var cartItem = _step4.value;
3761
+ var cartItem = _step6.value;
3342
3762
  if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
3343
3763
  resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
3344
3764
  return r.code === resourceCode && r.status === 1;
@@ -3347,9 +3767,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3347
3767
  }
3348
3768
  }
3349
3769
  } catch (err) {
3350
- _iterator4.e(err);
3770
+ _iterator6.e(err);
3351
3771
  } finally {
3352
- _iterator4.f();
3772
+ _iterator6.f();
3353
3773
  }
3354
3774
  var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
3355
3775
  var totalAvailable;
@@ -3402,7 +3822,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3402
3822
  }));
3403
3823
 
3404
3824
  // 找到所有资源都可用的时间段
3405
- var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
3825
+ var commonTimeSlots = _this17.findCommonAvailableTimeSlots(resourcesOfThisType);
3406
3826
  console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
3407
3827
  if (commonTimeSlots.length === 0) {
3408
3828
  console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
@@ -3433,7 +3853,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3433
3853
  },
3434
3854
  _ret4;
3435
3855
  for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
3436
- _ret4 = _loop5();
3856
+ _ret4 = _loop6();
3437
3857
  if (_ret4) return _ret4.v;
3438
3858
  }
3439
3859
 
@@ -3477,7 +3897,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3477
3897
  cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3478
3898
  });
3479
3899
  // 检查每个时间段是否有足够的资源容量
3480
- var _loop6 = function _loop6() {
3900
+ var _loop7 = function _loop7() {
3481
3901
  var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
3482
3902
  timeSlotKey = _Object$entries4$_i[0],
3483
3903
  itemsInTimeSlot = _Object$entries4$_i[1];
@@ -3496,7 +3916,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3496
3916
 
3497
3917
  // 获取资源数据
3498
3918
  // const dateRange = this.store.date.getDateRange();
3499
- var resourcesDates = _this16.store.date.getDateList();
3919
+ var resourcesDates = _this17.store.date.getDateList();
3500
3920
  var targetResourceDate = resourcesDates.find(function (n) {
3501
3921
  return n.date === startDate;
3502
3922
  });
@@ -3533,7 +3953,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3533
3953
  },
3534
3954
  _ret5;
3535
3955
  for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
3536
- _ret5 = _loop6();
3956
+ _ret5 = _loop7();
3537
3957
  if (_ret5 === 0) continue;
3538
3958
  if (_ret5) return _ret5.v;
3539
3959
  }
@@ -3566,41 +3986,41 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3566
3986
  }, {
3567
3987
  key: "getProductTypeById",
3568
3988
  value: function () {
3569
- var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(id) {
3989
+ var _getProductTypeById = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(id) {
3570
3990
  var productData, _productData$schedule;
3571
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
3572
- while (1) switch (_context25.prev = _context25.next) {
3991
+ return _regeneratorRuntime().wrap(function _callee26$(_context27) {
3992
+ while (1) switch (_context27.prev = _context27.next) {
3573
3993
  case 0:
3574
- _context25.next = 2;
3994
+ _context27.next = 2;
3575
3995
  return this.store.products.getProduct(id);
3576
3996
  case 2:
3577
- productData = _context25.sent;
3997
+ productData = _context27.sent;
3578
3998
  if (!productData) {
3579
- _context25.next = 9;
3999
+ _context27.next = 9;
3580
4000
  break;
3581
4001
  }
3582
4002
  if (!productData.duration) {
3583
- _context25.next = 6;
4003
+ _context27.next = 6;
3584
4004
  break;
3585
4005
  }
3586
- return _context25.abrupt("return", 'duration');
4006
+ return _context27.abrupt("return", 'duration');
3587
4007
  case 6:
3588
4008
  if (!((_productData$schedule = productData['schedule.ids']) !== null && _productData$schedule !== void 0 && _productData$schedule.length)) {
3589
- _context25.next = 8;
4009
+ _context27.next = 8;
3590
4010
  break;
3591
4011
  }
3592
- return _context25.abrupt("return", 'session');
4012
+ return _context27.abrupt("return", 'session');
3593
4013
  case 8:
3594
- return _context25.abrupt("return", 'normal');
4014
+ return _context27.abrupt("return", 'normal');
3595
4015
  case 9:
3596
- return _context25.abrupt("return", 'normal');
4016
+ return _context27.abrupt("return", 'normal');
3597
4017
  case 10:
3598
4018
  case "end":
3599
- return _context25.stop();
4019
+ return _context27.stop();
3600
4020
  }
3601
- }, _callee25, this);
4021
+ }, _callee26, this);
3602
4022
  }));
3603
- function getProductTypeById(_x20) {
4023
+ function getProductTypeById(_x21) {
3604
4024
  return _getProductTypeById.apply(this, arguments);
3605
4025
  }
3606
4026
  return getProductTypeById;
@@ -3720,12 +4140,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3720
4140
  }, {
3721
4141
  key: "getTimeslotsScheduleByDateRange",
3722
4142
  value: (function () {
3723
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
4143
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(_ref16) {
3724
4144
  var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
3725
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3726
- while (1) switch (_context26.prev = _context26.next) {
4145
+ return _regeneratorRuntime().wrap(function _callee27$(_context28) {
4146
+ while (1) switch (_context28.prev = _context28.next) {
3727
4147
  case 0:
3728
- startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
4148
+ startDate = _ref16.startDate, endDate = _ref16.endDate, scheduleIds = _ref16.scheduleIds, resources = _ref16.resources;
3729
4149
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3730
4150
  startDate: startDate,
3731
4151
  endDate: endDate,
@@ -3750,14 +4170,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3750
4170
  resources: resources
3751
4171
  });
3752
4172
  }
3753
- return _context26.abrupt("return", results);
4173
+ return _context28.abrupt("return", results);
3754
4174
  case 9:
3755
4175
  case "end":
3756
- return _context26.stop();
4176
+ return _context28.stop();
3757
4177
  }
3758
- }, _callee26, this);
4178
+ }, _callee27, this);
3759
4179
  }));
3760
- function getTimeslotsScheduleByDateRange(_x21) {
4180
+ function getTimeslotsScheduleByDateRange(_x22) {
3761
4181
  return _getTimeslotsScheduleByDateRange.apply(this, arguments);
3762
4182
  }
3763
4183
  return getTimeslotsScheduleByDateRange;
@@ -3765,7 +4185,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3765
4185
  }, {
3766
4186
  key: "getAvailableDateForSessionOptimize",
3767
4187
  value: function () {
3768
- var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4188
+ var _getAvailableDateForSessionOptimize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
3769
4189
  var _this$store$currentPr3, _this$store$currentPr4, _tempProducts;
3770
4190
  var params,
3771
4191
  startDate,
@@ -3784,12 +4204,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3784
4204
  openResources,
3785
4205
  allProductResources,
3786
4206
  targetSchedules,
3787
- _loop7,
3788
- _args28 = arguments;
3789
- return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3790
- while (1) switch (_context28.prev = _context28.next) {
4207
+ _loop8,
4208
+ _args30 = arguments;
4209
+ return _regeneratorRuntime().wrap(function _callee28$(_context30) {
4210
+ while (1) switch (_context30.prev = _context30.next) {
3791
4211
  case 0:
3792
- params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
4212
+ params = _args30.length > 0 && _args30[0] !== undefined ? _args30[0] : {};
3793
4213
  // 开始日期如果小于今天,直接以今天当做开始日期
3794
4214
  startDate = params.startDate, endDate = params.endDate; // 前端传递的 startDate,可能是今天之前的,如果 startDate 小于今天 且 endDate 小于或等于今天,需要把 startDate 置为今天
3795
4215
  if (dayjs(startDate).isBefore(dayjs(), 'day') && (dayjs(endDate).isAfter(dayjs(), 'day') || dayjs(endDate).isSame(dayjs(), 'day'))) {
@@ -3814,15 +4234,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3814
4234
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
3815
4235
  cache = (_this$store$currentPr3 = this.store.currentProductMeta) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3['timeSlotBySchedule'];
3816
4236
  if (!cache) {
3817
- _context28.next = 13;
4237
+ _context30.next = 13;
3818
4238
  break;
3819
4239
  }
3820
4240
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
3821
- _context28.next = 13;
4241
+ _context30.next = 13;
3822
4242
  break;
3823
4243
  }
3824
4244
  this.store.date.setDateList(cache.dateList);
3825
- return _context28.abrupt("return", {
4245
+ return _context30.abrupt("return", {
3826
4246
  dateList: cache.dateList,
3827
4247
  firstAvailableDate: cache.firstAvailableDate
3828
4248
  });
@@ -3832,7 +4252,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3832
4252
  schedule = (_this$store$currentPr4 = this.store.currentProductMeta) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4['schedule'];
3833
4253
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
3834
4254
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
3835
- _context28.next = 19;
4255
+ _context30.next = 19;
3836
4256
  return this.store.date.fetchResourceDates({
3837
4257
  query: {
3838
4258
  start_date: startDate || '',
@@ -3841,7 +4261,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3841
4261
  }
3842
4262
  });
3843
4263
  case 19:
3844
- res = _context28.sent;
4264
+ res = _context30.sent;
3845
4265
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
3846
4266
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
3847
4267
  dates = [];
@@ -3850,7 +4270,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3850
4270
  openResources = ((_tempProducts = tempProducts) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.product_resource) === null || _tempProducts === void 0 || (_tempProducts = _tempProducts.resources) === null || _tempProducts === void 0 ? void 0 : _tempProducts.filter(function (m) {
3851
4271
  return m.status === 1;
3852
4272
  })) || []; // res.data 返回的一定是启用商品的资源列表,不需要再过滤了
3853
- allProductResources = sortCombinedResources(res.data); // allProductResources 需要根据商品里的资源的单个预约多个预约补充resourceType
4273
+ allProductResources = cloneDeep(sortCombinedResources(res.data) || []); // allProductResources 需要根据商品里的资源的单个预约多个预约补充resourceType
3854
4274
  allProductResources.forEach(function (m) {
3855
4275
  var _tempProducts2;
3856
4276
  var resource = (_tempProducts2 = tempProducts) === null || _tempProducts2 === void 0 || (_tempProducts2 = _tempProducts2.product_resource) === null || _tempProducts2 === void 0 || (_tempProducts2 = _tempProducts2.resources) === null || _tempProducts2 === void 0 ? void 0 : _tempProducts2.find(function (n) {
@@ -3861,13 +4281,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3861
4281
  }
3862
4282
  });
3863
4283
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3864
- _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3865
- var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3866
- return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3867
- while (1) switch (_context27.prev = _context27.next) {
4284
+ _loop8 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop8() {
4285
+ var currentDateStr, status, summaryCount, availableCount, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse, dateStatus, usageRatio;
4286
+ return _regeneratorRuntime().wrap(function _loop8$(_context29) {
4287
+ while (1) switch (_context29.prev = _context29.next) {
3868
4288
  case 0:
3869
4289
  currentDateStr = currentDate.format('YYYY-MM-DD');
3870
- status = 'available'; // 1. 检查商品的提前量等情况是否满足
4290
+ status = 'available';
4291
+ summaryCount = 0;
4292
+ availableCount = 0; // 1. 检查商品的提前量等情况是否满足
3871
4293
  _checkSessionProductL = checkSessionProductLeadTime(tempProducts), latestStartDate = _checkSessionProductL.latestStartDate, earliestEndDate = _checkSessionProductL.earliestEndDate;
3872
4294
  if (latestStartDate || earliestEndDate) {
3873
4295
  // 如果时间在最早开始时间之前,则设置为不可用
@@ -3893,17 +4315,48 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3893
4315
  if (status === 'available') {
3894
4316
  minTimeMaxTime = calcMinTimeMaxTimeBySchedules(targetSchedules, {}, currentDateStr);
3895
4317
  scheduleTimeSlots = getAllSortedDateRanges(minTimeMaxTime); // 同一天内多个时间片下 只要有一个可用则视为可用
3896
- timesSlotCanUse = scheduleTimeSlots.some(function (item) {
4318
+ timesSlotCanUse = false;
4319
+ scheduleTimeSlots.forEach(function (item) {
3897
4320
  // 用来计算资源的可使用情况,针对单个schedule 时间片
3898
4321
  var resourcesUseableMap = {};
3899
4322
  // 遍历产品下启用的资源
3900
4323
  // 必须要保证每种类型的资源都至少有一个能够在对应时间点被选择
3901
- return openResources.every(function (resource) {
4324
+ // 求出第一个资源的剩余量和总量
4325
+ // 剩余量=每个资源在每个时间片内剩余之和
4326
+ // 总量=每个资源在每个时间片内资源总量之和
4327
+ var isAllResourceTypesUseable = true;
4328
+ openResources.forEach(function (resource) {
4329
+ var _resource$renderList;
4330
+ // if (!isAllResourceTypesUseable) return;
4331
+
3902
4332
  // 获取当前资源类型的资源列表
3903
4333
  var currentResourcesList = allProductResources.filter(function (n) {
3904
4334
  return n.form_id === resource.resource_type_id;
3905
4335
  });
3906
- return currentResourcesList === null || currentResourcesList === void 0 ? void 0 : currentResourcesList.some(function (m) {
4336
+ // 如果resource.renderList里含有 onlyComputed 的数据,需要把 currentResourcesList 的数据也修正回来
4337
+ (_resource$renderList = resource.renderList) === null || _resource$renderList === void 0 || _resource$renderList.forEach(function (item) {
4338
+ if (item.onlyComputed) {
4339
+ var targetIndex = currentResourcesList.findIndex(function (n) {
4340
+ return n.id === item.id;
4341
+ });
4342
+ if (targetIndex && targetIndex !== -1) {
4343
+ currentResourcesList[targetIndex].onlyComputed = true;
4344
+ }
4345
+ }
4346
+ });
4347
+ // 可能存在 renderList 没有的情况,则需要判断 resource.optional_resource 和 resource.default_resource 是否存在那个资源,如果不存在也打上 onlyComputed 的标记
4348
+ currentResourcesList.forEach(function (item) {
4349
+ var _resource$optional_re, _resource$default_res;
4350
+ if (!((_resource$optional_re = resource.optional_resource) !== null && _resource$optional_re !== void 0 && _resource$optional_re.includes(item.id)) && !((_resource$default_res = resource.default_resource) !== null && _resource$default_res !== void 0 && _resource$default_res.includes(item.id))) {
4351
+ item.onlyComputed = true;
4352
+ }
4353
+ });
4354
+ // currentResourcesList 排序,onlyComputed 的资源排在前面先计算
4355
+ currentResourcesList.sort(function (a, b) {
4356
+ return a.onlyComputed ? -1 : 1;
4357
+ });
4358
+ var isAnyResourceUseableInType = false;
4359
+ currentResourcesList === null || currentResourcesList === void 0 || currentResourcesList.forEach(function (m) {
3907
4360
  // 遍历所有资源的上工时间片
3908
4361
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
3909
4362
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
@@ -3911,12 +4364,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3911
4364
  var mTimes = m.times.filter(function (n) {
3912
4365
  return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
3913
4366
  });
4367
+
3914
4368
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
3915
- if (mTimes.length === 0) {
3916
- return;
4369
+ if (mTimes.length === 0) return;
4370
+ // 如果资源可用则把他的容量纳入总计
4371
+ if (!m.onlyComputed) {
4372
+ if (resource.type === 'multiple') {
4373
+ summaryCount += m.capacity;
4374
+ } else {
4375
+ summaryCount += 1;
4376
+ }
3917
4377
  }
3918
- var targetCanUseTimes = mTimes.some(function (childTiem) {
4378
+ var isAnyTimeSliceUseable = false;
4379
+ mTimes.forEach(function (childTiem) {
3919
4380
  var _tempProducts3;
4381
+ if (isAnyTimeSliceUseable) return;
4382
+
3920
4383
  // 挨个去匹配某个工作时间段结合当前日程时间,资源能不能用,有多少容量能用
3921
4384
  var res = getIsUsableByTimeItem({
3922
4385
  timeSlice: {
@@ -3934,11 +4397,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3934
4397
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3935
4398
  resourcesUseableMap[m.id] = res.usable;
3936
4399
  }
3937
- return res.usable && !m.onlyComputed;
4400
+ if (res.usable && !m.onlyComputed) {
4401
+ isAnyTimeSliceUseable = true;
4402
+ if (resource.type === 'multiple') {
4403
+ availableCount += res.remainingCapacity;
4404
+ } else {
4405
+ availableCount += 1;
4406
+ }
4407
+ }
4408
+ ;
3938
4409
  });
3939
- return targetCanUseTimes;
4410
+ if (isAnyTimeSliceUseable) isAnyResourceUseableInType = true;
3940
4411
  });
4412
+ if (!isAnyResourceUseableInType) isAllResourceTypesUseable = false;
3941
4413
  });
4414
+ if (isAllResourceTypesUseable) timesSlotCanUse = true;
3942
4415
  });
3943
4416
  if (!timesSlotCanUse) {
3944
4417
  status = 'unavailable';
@@ -3947,41 +4420,55 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3947
4420
  firstAvailableDate = currentDateStr;
3948
4421
  }
3949
4422
  }
4423
+ // 状态: lots_of_space: availableCount / summaryCount > 0.5
4424
+ // filling_up_fast: availableCount / summaryCount <= 0.5 && availableCount > 0
4425
+ // sold_out: summaryCount = 0
4426
+ // unavailable: summaryCount > 0 && availableCount = 0
4427
+
4428
+ if (status === 'unavailable') {
4429
+ // dateStatus = 'unavailable'
4430
+ if (availableCount === 0 && summaryCount > 0) dateStatus = 'sold_out';else dateStatus = 'unavailable';
4431
+ } else {
4432
+ usageRatio = availableCount / summaryCount;
4433
+ if (usageRatio > 0.5) dateStatus = 'lots_of_space';else dateStatus = 'filling_up_fast';
4434
+ }
3950
4435
  dates.push({
3951
4436
  date: dayjs(currentDate).format('YYYY-MM-DD'),
3952
4437
  week: dayjs(currentDate).format('ddd'),
3953
4438
  weekNum: dayjs(currentDate).day(),
3954
- status: status
4439
+ summaryCount: summaryCount,
4440
+ availableCount: availableCount,
4441
+ status: dateStatus
3955
4442
  });
3956
4443
 
3957
4444
  // 如果 firstAvailableDate 距离 startDate 大于 14 天了,则后面就不需要再找了,也是一种性能保护
3958
4445
  if (!(firstAvailableDate && dayjs(currentDate).diff(dayjs(startDate), 'day') > 31)) {
3959
- _context27.next = 9;
4446
+ _context29.next = 12;
3960
4447
  break;
3961
4448
  }
3962
- return _context27.abrupt("return", 1);
3963
- case 9:
4449
+ return _context29.abrupt("return", 1);
4450
+ case 12:
3964
4451
  currentDate = dayjs(currentDate).add(1, 'day');
3965
- case 10:
4452
+ case 13:
3966
4453
  case "end":
3967
- return _context27.stop();
4454
+ return _context29.stop();
3968
4455
  }
3969
- }, _loop7);
4456
+ }, _loop8);
3970
4457
  });
3971
4458
  case 28:
3972
4459
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3973
- _context28.next = 34;
4460
+ _context30.next = 34;
3974
4461
  break;
3975
4462
  }
3976
- return _context28.delegateYield(_loop7(), "t0", 30);
4463
+ return _context30.delegateYield(_loop8(), "t0", 30);
3977
4464
  case 30:
3978
- if (!_context28.t0) {
3979
- _context28.next = 32;
4465
+ if (!_context30.t0) {
4466
+ _context30.next = 32;
3980
4467
  break;
3981
4468
  }
3982
- return _context28.abrupt("break", 34);
4469
+ return _context30.abrupt("break", 34);
3983
4470
  case 32:
3984
- _context28.next = 28;
4471
+ _context30.next = 28;
3985
4472
  break;
3986
4473
  case 34:
3987
4474
  // 最终把资源数据也加到日期内
@@ -3996,15 +4483,15 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3996
4483
  startDate: startDate,
3997
4484
  endDate: dayjs(currentDate).format('YYYY-MM-DD')
3998
4485
  };
3999
- return _context28.abrupt("return", {
4486
+ return _context30.abrupt("return", {
4000
4487
  dateList: dates,
4001
4488
  firstAvailableDate: firstAvailableDate
4002
4489
  });
4003
4490
  case 39:
4004
4491
  case "end":
4005
- return _context28.stop();
4492
+ return _context30.stop();
4006
4493
  }
4007
- }, _callee27, this);
4494
+ }, _callee28, this);
4008
4495
  }));
4009
4496
  function getAvailableDateForSessionOptimize() {
4010
4497
  return _getAvailableDateForSessionOptimize.apply(this, arguments);
@@ -4051,18 +4538,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
4051
4538
  }, {
4052
4539
  key: "getContactInfo",
4053
4540
  value: (function () {
4054
- var _getContactInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4055
- return _regeneratorRuntime().wrap(function _callee28$(_context29) {
4056
- while (1) switch (_context29.prev = _context29.next) {
4541
+ var _getContactInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4542
+ return _regeneratorRuntime().wrap(function _callee29$(_context31) {
4543
+ while (1) switch (_context31.prev = _context31.next) {
4057
4544
  case 0:
4058
- return _context29.abrupt("return", this.request.get('/customer/metadata', params));
4545
+ return _context31.abrupt("return", this.request.get('/customer/metadata', params));
4059
4546
  case 1:
4060
4547
  case "end":
4061
- return _context29.stop();
4548
+ return _context31.stop();
4062
4549
  }
4063
- }, _callee28, this);
4550
+ }, _callee29, this);
4064
4551
  }));
4065
- function getContactInfo(_x22) {
4552
+ function getContactInfo(_x23) {
4066
4553
  return _getContactInfo.apply(this, arguments);
4067
4554
  }
4068
4555
  return getContactInfo;