@pisell/pisellos 0.0.569 → 0.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (328) hide show
  1. package/dist/core/index.js +10 -6
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -3
  4. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
  6. package/dist/model/strategy/adapter/walletPass/example.js +26 -3
  7. package/dist/model/strategy/adapter/walletPass/index.js +5 -5
  8. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
  9. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  10. package/dist/model/strategy/adapter/walletPass/utils.js +17 -92
  11. package/dist/model/strategy/strategy-example.js +19 -5
  12. package/dist/modules/BaseModule.d.ts +1 -1
  13. package/dist/modules/BaseModule.js +8 -10
  14. package/dist/modules/Cart/index.js +3 -0
  15. package/dist/modules/Cart/utils/cartProduct.js +1 -0
  16. package/dist/modules/Cart/utils/cartResource.js +0 -2
  17. package/dist/modules/Cart/utils/changePrice.js +9 -16
  18. package/dist/modules/Date/index.js +5 -1
  19. package/dist/modules/Discount/index.d.ts +0 -1
  20. package/dist/modules/Discount/index.js +7 -22
  21. package/dist/modules/Discount/types.d.ts +0 -1
  22. package/dist/modules/OpenData/index.js +2 -0
  23. package/dist/modules/Order/index.js +70 -40
  24. package/dist/modules/Payment/index.js +162 -97
  25. package/dist/modules/Payment/types.d.ts +4 -8
  26. package/dist/modules/Payment/walletpass.d.ts +0 -2
  27. package/dist/modules/Payment/walletpass.js +5 -4
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -12
  30. package/dist/modules/ProductList/types.d.ts +0 -1
  31. package/dist/modules/Rules/index.js +126 -427
  32. package/dist/modules/SalesSummary/utils.js +1 -2
  33. package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
  34. package/dist/modules/Schedule/index.js +1 -0
  35. package/dist/modules/Schedule/utils.js +1 -0
  36. package/dist/modules/Step/index.js +1 -0
  37. package/dist/modules/Summary/utils.js +22 -43
  38. package/dist/plugins/request.js +4 -1
  39. package/dist/plugins/window.js +6 -2
  40. package/dist/server/index.js +129 -97
  41. package/dist/server/modules/menu/index.js +41 -32
  42. package/dist/server/modules/order/index.js +4 -2
  43. package/dist/server/modules/products/index.js +42 -24
  44. package/dist/server/modules/quotation/index.js +38 -29
  45. package/dist/server/modules/resource/index.js +4 -3
  46. package/dist/server/modules/schedule/index.js +35 -27
  47. package/dist/server/utils/product.js +1 -0
  48. package/dist/solution/BaseSales/index.js +41 -38
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingByStep/index.js +60 -11
  51. package/dist/solution/BookingByStep/utils/capacity.js +11 -1
  52. package/dist/solution/BookingByStep/utils/resources.js +3 -1
  53. package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
  54. package/dist/solution/BookingTicket/index.d.ts +1 -1
  55. package/dist/solution/BookingTicket/index.js +2 -0
  56. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +7 -6
  57. package/dist/solution/BookingTicket/utils/scan/handleScan.js +31 -25
  58. package/dist/solution/BookingTicket/utils/scan/index.js +10 -6
  59. package/dist/solution/BuyTickets/index.js +12 -9
  60. package/dist/solution/Checkout/index.js +252 -177
  61. package/dist/solution/Checkout/utils/index.js +16 -4
  62. package/dist/solution/RegisterAndLogin/index.js +76 -30
  63. package/dist/solution/ScanOrder/index.js +60 -50
  64. package/dist/solution/ShopDiscount/index.js +14 -15
  65. package/dist/solution/ShopDiscount/types.d.ts +4 -5
  66. package/dist/solution/ShopDiscount/utils.d.ts +0 -9
  67. package/dist/solution/ShopDiscount/utils.js +0 -9
  68. package/dist/solution/VenueBooking/index.d.ts +3 -31
  69. package/dist/solution/VenueBooking/index.js +496 -651
  70. package/dist/solution/VenueBooking/types.d.ts +1 -3
  71. package/dist/solution/VenueBooking/types.js +0 -1
  72. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  73. package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
  74. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  75. package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/utils/task.js +18 -15
  78. package/dist/utils/watch.js +1 -0
  79. package/lib/apis/picoding.js +0 -2
  80. package/lib/core/index.js +132 -130
  81. package/lib/effects/index.js +57 -46
  82. package/lib/index.d.ts +0 -1
  83. package/lib/index.js +50 -92
  84. package/lib/model/index.js +21 -14
  85. package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
  86. package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
  87. package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
  88. package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
  89. package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
  90. package/lib/model/strategy/adapter/index.js +64 -100
  91. package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
  92. package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
  93. package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
  94. package/lib/model/strategy/adapter/itemRule/index.js +57 -83
  95. package/lib/model/strategy/adapter/itemRule/type.js +36 -97
  96. package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
  97. package/lib/model/strategy/adapter/promotion/evaluator.js +231 -381
  98. package/lib/model/strategy/adapter/promotion/examples.js +159 -139
  99. package/lib/model/strategy/adapter/promotion/index.js +49 -1
  100. package/lib/model/strategy/adapter/promotion/type.js +35 -199
  101. package/lib/model/strategy/adapter/type.js +16 -4
  102. package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
  103. package/lib/model/strategy/adapter/walletPass/example.js +190 -217
  104. package/lib/model/strategy/adapter/walletPass/index.js +51 -75
  105. package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
  106. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
  107. package/lib/model/strategy/adapter/walletPass/type.js +16 -4
  108. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
  109. package/lib/model/strategy/adapter/walletPass/utils.js +383 -678
  110. package/lib/model/strategy/engine.js +168 -270
  111. package/lib/model/strategy/index.js +34 -49
  112. package/lib/model/strategy/strategy-example.js +239 -243
  113. package/lib/model/strategy/type.js +40 -100
  114. package/lib/modules/Account/index.js +53 -39
  115. package/lib/modules/Account/types.js +33 -20
  116. package/lib/modules/AccountList/index.js +154 -116
  117. package/lib/modules/AccountList/types.js +31 -30
  118. package/lib/modules/AccountList/utils.js +30 -18
  119. package/lib/modules/BaseModule.d.ts +1 -1
  120. package/lib/modules/BaseModule.js +46 -25
  121. package/lib/modules/BookingContext/index.js +136 -158
  122. package/lib/modules/BookingContext/types.js +32 -46
  123. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +143 -131
  124. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +82 -75
  125. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +150 -170
  126. package/lib/modules/BookingContext/utils/flexible.js +55 -38
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +34 -19
  128. package/lib/modules/BookingContext/utils/index.js +41 -124
  129. package/lib/modules/BookingContext/utils/noResource.js +70 -58
  130. package/lib/modules/BookingContext/utils/orderLineDisplay.js +41 -14
  131. package/lib/modules/BookingContext/utils/productExtend.js +155 -202
  132. package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
  133. package/lib/modules/BookingContext/utils/resourceSelection.js +41 -19
  134. package/lib/modules/BookingContext/utils/resources.js +167 -209
  135. package/lib/modules/BookingContext/utils/serviceTimes.js +116 -115
  136. package/lib/modules/BookingContext/utils/timeSlices.js +80 -70
  137. package/lib/modules/Cart/index.js +124 -170
  138. package/lib/modules/Cart/types.js +51 -46
  139. package/lib/modules/Cart/utils/cartAccount.js +39 -40
  140. package/lib/modules/Cart/utils/cartDate.js +61 -56
  141. package/lib/modules/Cart/utils/cartDiscount.js +33 -28
  142. package/lib/modules/Cart/utils/cartNote.js +32 -27
  143. package/lib/modules/Cart/utils/cartProduct.js +251 -321
  144. package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
  145. package/lib/modules/Cart/utils/cartResource.js +78 -72
  146. package/lib/modules/Cart/utils/changePrice.js +50 -28
  147. package/lib/modules/Cart/utils/index.js +48 -106
  148. package/lib/modules/Customer/constants.js +34 -13
  149. package/lib/modules/Customer/index.js +169 -232
  150. package/lib/modules/Customer/types.js +35 -38
  151. package/lib/modules/Date/index.js +115 -116
  152. package/lib/modules/Date/types.js +28 -16
  153. package/lib/modules/Date/utils.js +123 -174
  154. package/lib/modules/Discount/index.d.ts +0 -1
  155. package/lib/modules/Discount/index.js +128 -130
  156. package/lib/modules/Discount/types.d.ts +0 -1
  157. package/lib/modules/Discount/types.js +31 -9
  158. package/lib/modules/Guests/index.js +56 -30
  159. package/lib/modules/Guests/types.js +33 -23
  160. package/lib/modules/Holder/index.js +189 -209
  161. package/lib/modules/Holder/types.js +16 -4
  162. package/lib/modules/Holder/utils.js +49 -20
  163. package/lib/modules/OpenData/index.js +76 -69
  164. package/lib/modules/OpenData/types.js +16 -4
  165. package/lib/modules/OpenData/utils.js +78 -44
  166. package/lib/modules/Order/index.js +1909 -1572
  167. package/lib/modules/Order/types.js +35 -78
  168. package/lib/modules/Order/utils/bundleDiscountHydration.js +74 -41
  169. package/lib/modules/Order/utils/manualProductDiscount.js +123 -124
  170. package/lib/modules/Order/utils/orderCollectionIdentity.js +210 -148
  171. package/lib/modules/Order/utils.js +634 -799
  172. package/lib/modules/Payment/cash.js +33 -20
  173. package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
  174. package/lib/modules/Payment/eftpos.js +30 -16
  175. package/lib/modules/Payment/index.js +378 -518
  176. package/lib/modules/Payment/mx51.js +0 -1
  177. package/lib/modules/Payment/types.d.ts +4 -8
  178. package/lib/modules/Payment/types.js +107 -216
  179. package/lib/modules/Payment/utils.js +48 -51
  180. package/lib/modules/Payment/walletpass.d.ts +0 -2
  181. package/lib/modules/Payment/walletpass.js +211 -226
  182. package/lib/modules/Product/index.js +46 -51
  183. package/lib/modules/Product/types.js +16 -4
  184. package/lib/modules/Product/utils.js +33 -32
  185. package/lib/modules/ProductList/index.d.ts +1 -1
  186. package/lib/modules/ProductList/index.js +117 -117
  187. package/lib/modules/ProductList/types.d.ts +0 -1
  188. package/lib/modules/ProductList/types.js +31 -9
  189. package/lib/modules/Quotation/index.js +100 -66
  190. package/lib/modules/Quotation/types.js +16 -4
  191. package/lib/modules/Resource/index.js +59 -27
  192. package/lib/modules/Resource/types.js +32 -22
  193. package/lib/modules/Resource/utils.js +38 -30
  194. package/lib/modules/ResourcePlanner/index.js +61 -60
  195. package/lib/modules/ResourcePlanner/planner.js +384 -346
  196. package/lib/modules/ResourcePlanner/types.js +16 -4
  197. package/lib/modules/Rules/index.js +903 -1475
  198. package/lib/modules/Rules/types.js +40 -17
  199. package/lib/modules/SalesSummary/index.js +90 -85
  200. package/lib/modules/SalesSummary/types.js +16 -4
  201. package/lib/modules/SalesSummary/utils.js +427 -351
  202. package/lib/modules/ScanOrderLogger/index.js +79 -59
  203. package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
  204. package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
  205. package/lib/modules/ScanOrderLogger/types.js +16 -4
  206. package/lib/modules/Schedule/getDateIsInSchedule.js +163 -339
  207. package/lib/modules/Schedule/index.js +114 -100
  208. package/lib/modules/Schedule/type.js +16 -4
  209. package/lib/modules/Schedule/types.js +16 -4
  210. package/lib/modules/Schedule/utils.js +291 -433
  211. package/lib/modules/Step/index.js +52 -40
  212. package/lib/modules/Step/tyeps.js +16 -4
  213. package/lib/modules/Summary/index.js +71 -66
  214. package/lib/modules/Summary/types.js +16 -4
  215. package/lib/modules/Summary/utils.js +418 -791
  216. package/lib/modules/SurchargeList/index.js +60 -46
  217. package/lib/modules/SurchargeList/types.js +16 -4
  218. package/lib/modules/index.js +63 -245
  219. package/lib/plugins/app.js +16 -4
  220. package/lib/plugins/index.js +25 -36
  221. package/lib/plugins/request.js +126 -137
  222. package/lib/plugins/shopStore.js +16 -4
  223. package/lib/plugins/user.js +16 -4
  224. package/lib/plugins/window.js +179 -171
  225. package/lib/server/index.js +2337 -2675
  226. package/lib/server/modules/floor-plan/index.js +123 -102
  227. package/lib/server/modules/floor-plan/types.js +30 -15
  228. package/lib/server/modules/index.js +68 -106
  229. package/lib/server/modules/menu/index.js +122 -146
  230. package/lib/server/modules/menu/types.js +31 -18
  231. package/lib/server/modules/order/index.js +642 -567
  232. package/lib/server/modules/order/types.js +32 -117
  233. package/lib/server/modules/order/utils/filterBookings.js +194 -219
  234. package/lib/server/modules/order/utils/filterOrders.js +92 -118
  235. package/lib/server/modules/payment/index.js +83 -59
  236. package/lib/server/modules/payment/types.js +16 -4
  237. package/lib/server/modules/products/index.js +459 -575
  238. package/lib/server/modules/products/types.js +34 -44
  239. package/lib/server/modules/quotation/index.js +172 -137
  240. package/lib/server/modules/quotation/types.js +31 -21
  241. package/lib/server/modules/resource/index.js +184 -213
  242. package/lib/server/modules/resource/types.js +33 -42
  243. package/lib/server/modules/schedule/index.js +123 -135
  244. package/lib/server/modules/schedule/types.js +21 -14
  245. package/lib/server/modules/schedule/utils.js +163 -334
  246. package/lib/server/types.js +16 -4
  247. package/lib/server/utils/index.js +23 -25
  248. package/lib/server/utils/product.js +139 -196
  249. package/lib/server/utils/schedule.js +41 -34
  250. package/lib/server/utils/small-ticket.js +456 -478
  251. package/lib/server/utils/time.js +49 -40
  252. package/lib/solution/BaseSales/index.js +1016 -850
  253. package/lib/solution/BaseSales/types.js +37 -41
  254. package/lib/solution/BaseSales/utils/cartPromotion.js +460 -611
  255. package/lib/solution/BaseSales/utils/parseSalesResponse.js +105 -85
  256. package/lib/solution/BaseSales/utils/quotationPrice.js +114 -56
  257. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +143 -102
  258. package/lib/solution/BaseSales/utils.js +140 -155
  259. package/lib/solution/BookingByStep/index.d.ts +1 -1
  260. package/lib/solution/BookingByStep/index.js +1340 -1530
  261. package/lib/solution/BookingByStep/types.js +99 -40
  262. package/lib/solution/BookingByStep/utils/capacity.js +160 -192
  263. package/lib/solution/BookingByStep/utils/products.js +52 -42
  264. package/lib/solution/BookingByStep/utils/resources.js +330 -527
  265. package/lib/solution/BookingByStep/utils/stock.js +44 -65
  266. package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
  267. package/lib/solution/BookingTicket/index.d.ts +1 -1
  268. package/lib/solution/BookingTicket/index.js +459 -543
  269. package/lib/solution/BookingTicket/types.js +77 -99
  270. package/lib/solution/BookingTicket/utils/addProductDecision.js +184 -219
  271. package/lib/solution/BookingTicket/utils/addTimeAvailability.js +89 -58
  272. package/lib/solution/BookingTicket/utils/bookingStatus.js +78 -107
  273. package/lib/solution/BookingTicket/utils/cartView.js +94 -110
  274. package/lib/solution/BookingTicket/utils/exampleData.js +0 -185
  275. package/lib/solution/BookingTicket/utils/orderCustomer.js +41 -18
  276. package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +86 -219
  277. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +93 -144
  278. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +91 -79
  279. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +41 -54
  280. package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -84
  281. package/lib/solution/BookingTicket/utils/scan/index.js +104 -98
  282. package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
  283. package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +64 -52
  284. package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +58 -56
  285. package/lib/solution/BuyTickets/index.js +70 -67
  286. package/lib/solution/BuyTickets/types.js +38 -22
  287. package/lib/solution/Checkout/index.js +1158 -1451
  288. package/lib/solution/Checkout/types.js +61 -91
  289. package/lib/solution/Checkout/utils/index.js +156 -228
  290. package/lib/solution/PlaceOrder/index.js +0 -55
  291. package/lib/solution/RegisterAndLogin/config.js +460 -493
  292. package/lib/solution/RegisterAndLogin/index.js +630 -633
  293. package/lib/solution/RegisterAndLogin/types.js +76 -189
  294. package/lib/solution/RegisterAndLogin/utils.js +125 -183
  295. package/lib/solution/Sales/index.js +320 -317
  296. package/lib/solution/Sales/types.js +33 -27
  297. package/lib/solution/ScanOrder/index.js +862 -831
  298. package/lib/solution/ScanOrder/types.js +34 -33
  299. package/lib/solution/ScanOrder/utils.js +371 -406
  300. package/lib/solution/ShopDiscount/index.js +233 -235
  301. package/lib/solution/ShopDiscount/types.d.ts +4 -5
  302. package/lib/solution/ShopDiscount/types.js +37 -15
  303. package/lib/solution/ShopDiscount/utils.d.ts +0 -9
  304. package/lib/solution/ShopDiscount/utils.js +172 -309
  305. package/lib/solution/UnifiedBookingSales/index.js +405 -379
  306. package/lib/solution/UnifiedBookingSales/types.js +31 -12
  307. package/lib/solution/VenueBooking/index.d.ts +3 -31
  308. package/lib/solution/VenueBooking/index.js +916 -967
  309. package/lib/solution/VenueBooking/types.d.ts +1 -3
  310. package/lib/solution/VenueBooking/types.js +39 -20
  311. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
  312. package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
  313. package/lib/solution/VenueBooking/utils/resource.js +54 -31
  314. package/lib/solution/VenueBooking/utils/slotMerge.js +107 -94
  315. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
  316. package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
  317. package/lib/solution/VenueBooking/utils.js +67 -130
  318. package/lib/solution/index.js +41 -124
  319. package/lib/store/createStore.js +29 -32
  320. package/lib/types/index.d.ts +1 -1
  321. package/lib/types/index.js +16 -4
  322. package/lib/utils/task.js +36 -36
  323. package/lib/utils/watch.js +47 -81
  324. package/package.json +2 -4
  325. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  326. package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
  327. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
  328. package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
@@ -1,162 +1,138 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- SalesImpl: true,
8
- Sales: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
9
10
  };
10
- exports.default = exports.SalesImpl = exports.Sales = void 0;
11
- var _dayjs = _interopRequireDefault(require("dayjs"));
12
- var _BaseModule = require("../../modules/BaseModule");
13
- var _types = require("./types");
14
- Object.keys(_types).forEach(function (key) {
15
- if (key === "default" || key === "__esModule") return;
16
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
17
- if (key in exports && exports[key] === _types[key]) return;
18
- Object.defineProperty(exports, key, {
19
- enumerable: true,
20
- get: function () {
21
- return _types[key];
22
- }
23
- });
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/solution/Sales/index.ts
31
+ var Sales_exports = {};
32
+ __export(Sales_exports, {
33
+ Sales: () => SalesImpl,
34
+ SalesImpl: () => SalesImpl,
35
+ default: () => Sales_default
24
36
  });
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
- /**
27
- * Sales 解决方案基础骨架
28
- *
29
- * 当前阶段仅提供:
30
- * - solution 目录结构
31
- * - 标准入口导出
32
- * - 基础生命周期占位
33
- *
34
- * 不提前实现 store 编排、初始化流程细节、状态计算逻辑。
35
- * TIPS:这块应该改名叫 ReservationModule 更合适一些,目前这边只服务于 Reservation 的 floormap 展示。
36
- */
37
- class SalesImpl extends _BaseModule.BaseModule {
38
- defaultName = 'sales';
39
- defaultVersion = '1.0.0';
40
- defaultTimelineBucketMinutes = 15;
41
- isSolution = true;
42
- store;
43
- options = {};
44
- otherParams = {};
45
- request;
46
- logger; // LoggerManager 实例
47
-
37
+ module.exports = __toCommonJS(Sales_exports);
38
+ var import_dayjs = __toESM(require("dayjs"));
39
+ var import_BaseModule = require("../../modules/BaseModule");
40
+ var import_types = require("./types");
41
+ __reExport(Sales_exports, require("./types"), module.exports);
42
+ var SalesImpl = class extends import_BaseModule.BaseModule {
43
+ // LoggerManager 实例
48
44
  constructor(name, version) {
49
45
  super(name, version);
46
+ this.defaultName = "sales";
47
+ this.defaultVersion = "1.0.0";
48
+ this.defaultTimelineBucketMinutes = 15;
49
+ this.isSolution = true;
50
+ this.options = {};
51
+ this.otherParams = {};
50
52
  }
51
53
  async initialize(core, options = {}) {
52
54
  this.core = core;
53
55
  this.options = options;
54
56
  this.otherParams = options.otherParams || {};
55
- const appPlugin = this.core.getPlugin('app');
56
- // @ts-ignore
57
- this.request = appPlugin?.getApp().request;
57
+ const appPlugin = this.core.getPlugin("app");
58
+ this.request = appPlugin == null ? void 0 : appPlugin.getApp().request;
58
59
  if (!this.request) {
59
- throw new Error('Sales 解决方案需要 request 插件支持');
60
+ throw new Error("Sales 解决方案需要 request 插件支持");
60
61
  }
61
-
62
- // 初始化 store 状态
63
62
  this.store = {
64
- currentDay: (0, _dayjs.default)().startOf('day'),
63
+ currentDay: (0, import_dayjs.default)().startOf("day"),
65
64
  reservationList: []
66
65
  };
67
-
68
- // TODO(Rolo): 等领导提供 reservationList 的目标结构后,
69
- // 在这里补充从 Server/Order 读取 currentDay 原始数据并转换为预约列表。
70
-
71
- this.logger = appPlugin?.getApp().logger;
66
+ this.logger = appPlugin == null ? void 0 : appPlugin.getApp().logger;
72
67
  await this.core.effects.emit(`${this.name}:onInited`, {});
73
68
  }
74
-
75
69
  // -------------------------------------------------------------------------
76
70
  // SalesModuleAPI 实现
77
71
  // -------------------------------------------------------------------------
78
-
79
72
  /** 获取当前 store 快照 */
80
73
  getState() {
81
- return {
82
- ...this.store
83
- };
74
+ return { ...this.store };
84
75
  }
85
-
86
76
  /** 获取当前选择日期 */
87
77
  getCurrentDay() {
88
78
  return this.store.currentDay;
89
79
  }
90
-
91
80
  /** 设置当前选择日期,会自动归一到当天 00:00:00 */
92
81
  setCurrentDay(currentDay) {
93
- const normalized = (0, _dayjs.default)(currentDay).startOf('day');
82
+ const normalized = (0, import_dayjs.default)(currentDay).startOf("day");
94
83
  this.store.currentDay = normalized;
95
- this.core.effects.emit(_types.SalesHooks.onCurrentDayChanged, {
96
- currentDay: normalized
97
- });
84
+ this.core.effects.emit(import_types.SalesHooks.onCurrentDayChanged, { currentDay: normalized });
98
85
  return normalized;
99
86
  }
100
-
101
87
  /** 获取当前预约列表 */
102
88
  getReservationList() {
103
89
  return [...this.store.reservationList];
104
90
  }
105
-
106
91
  /** 覆盖设置当前预约列表 */
107
92
  setReservationList(reservationList) {
108
93
  this.store.reservationList = reservationList;
109
- this.core.effects.emit(_types.SalesHooks.onReservationListChanged, {
110
- reservationList
111
- });
94
+ this.core.effects.emit(import_types.SalesHooks.onReservationListChanged, { reservationList });
112
95
  return reservationList;
113
96
  }
114
-
115
97
  /** 重置预约列表为空 */
116
98
  resetReservationList() {
117
99
  this.store.reservationList = [];
118
- this.core.effects.emit(_types.SalesHooks.onReservationListChanged, {
119
- reservationList: []
120
- });
100
+ this.core.effects.emit(import_types.SalesHooks.onReservationListChanged, { reservationList: [] });
121
101
  return [];
122
102
  }
123
103
  async cancelOrder(orderIds) {
124
- const orderModule = this.core.getModule('order');
104
+ const orderModule = this.core.getModule("order");
125
105
  if (!orderModule) {
126
- throw new Error('Sales 取消订单失败:Order 模块未注册');
106
+ throw new Error("Sales 取消订单失败:Order 模块未注册");
127
107
  }
128
- return orderModule.cancelOrder({
129
- order_ids: orderIds
130
- });
108
+ return orderModule.cancelOrder({ order_ids: orderIds });
131
109
  }
132
110
  async changeBookingStatus(params) {
133
- const orderModule = this.core.getModule('order');
111
+ const orderModule = this.core.getModule("order");
134
112
  if (!orderModule) {
135
- throw new Error('Sales 变更预约状态失败:Order 模块未注册');
113
+ throw new Error("Sales 变更预约状态失败:Order 模块未注册");
136
114
  }
137
115
  return orderModule.changeBookingStatus(params);
138
116
  }
139
-
140
117
  // -------------------------------------------------------------------------
141
118
  // 生命周期
142
119
  // -------------------------------------------------------------------------
143
-
144
120
  async destroy() {
145
121
  await this.core.effects.emit(`${this.name}:onDestroy`, {});
146
122
  super.destroy();
147
123
  }
148
-
149
124
  /**
150
125
  * 时间轴粒度(分钟)
151
126
  * - 默认 15 分钟
152
127
  * - 可通过 registerModule 时的 options.otherParams.timelineBucketMinutes 覆盖
153
128
  */
154
129
  getTimelineBucketMinutes() {
155
- const dynamicBucket = Number(this.otherParams?.timelineBucketMinutes);
156
- if (!Number.isFinite(dynamicBucket) || dynamicBucket <= 0) return this.defaultTimelineBucketMinutes;
130
+ var _a;
131
+ const dynamicBucket = Number((_a = this.otherParams) == null ? void 0 : _a.timelineBucketMinutes);
132
+ if (!Number.isFinite(dynamicBucket) || dynamicBucket <= 0)
133
+ return this.defaultTimelineBucketMinutes;
157
134
  return Math.floor(dynamicBucket);
158
135
  }
159
-
160
136
  /**
161
137
  * 解析营业日统计窗口:
162
138
  * - 当 operating_day_boundary.type === 'start_time'
@@ -164,32 +140,23 @@ class SalesImpl extends _BaseModule.BaseModule {
164
140
  * - 否则回退自然日(00:00 到次日 00:00)
165
141
  */
166
142
  getTimelineRangeByOperatingBoundary() {
167
- const today = (0, _dayjs.default)();
168
- const defaultStart = today.startOf('day');
169
- const defaultEndExclusive = defaultStart.add(1, 'day');
170
- const appPlugin = this.core.getPlugin('app');
171
- const coreData = appPlugin?.getApp()?.data?.store?.getStore?.().getDataByModel?.('core');
172
- const operatingDayBoundary = coreData?.core?.operating_day_boundary;
173
- if (operatingDayBoundary?.type !== 'start_time') {
174
- return {
175
- startAt: defaultStart,
176
- endExclusiveAt: defaultEndExclusive
177
- };
143
+ var _a, _b, _c, _d, _e, _f, _g;
144
+ const today = (0, import_dayjs.default)();
145
+ const defaultStart = today.startOf("day");
146
+ const defaultEndExclusive = defaultStart.add(1, "day");
147
+ const appPlugin = this.core.getPlugin("app");
148
+ const coreData = (_f = (_d = (_c = (_b = (_a = appPlugin == null ? void 0 : appPlugin.getApp()) == null ? void 0 : _a.data) == null ? void 0 : _b.store) == null ? void 0 : _c.getStore) == null ? void 0 : (_e = _d.call(_c)).getDataByModel) == null ? void 0 : _f.call(_e, "core");
149
+ const operatingDayBoundary = (_g = coreData == null ? void 0 : coreData.core) == null ? void 0 : _g.operating_day_boundary;
150
+ if ((operatingDayBoundary == null ? void 0 : operatingDayBoundary.type) !== "start_time") {
151
+ return { startAt: defaultStart, endExclusiveAt: defaultEndExclusive };
178
152
  }
179
- const boundaryTime = String(operatingDayBoundary.time || '').trim();
180
- const startAt = (0, _dayjs.default)(`${today.format('YYYY-MM-DD')} ${boundaryTime}`);
153
+ const boundaryTime = String(operatingDayBoundary.time || "").trim();
154
+ const startAt = (0, import_dayjs.default)(`${today.format("YYYY-MM-DD")} ${boundaryTime}`);
181
155
  if (!startAt.isValid()) {
182
- return {
183
- startAt: defaultStart,
184
- endExclusiveAt: defaultEndExclusive
185
- };
156
+ return { startAt: defaultStart, endExclusiveAt: defaultEndExclusive };
186
157
  }
187
- return {
188
- startAt,
189
- endExclusiveAt: startAt.add(1, 'day')
190
- };
158
+ return { startAt, endExclusiveAt: startAt.add(1, "day") };
191
159
  }
192
-
193
160
  /**
194
161
  * 统计时间轴每个时间片的预约数量。
195
162
  * 算法使用差分数组,复杂度 O(n + s):
@@ -198,37 +165,39 @@ class SalesImpl extends _BaseModule.BaseModule {
198
165
  */
199
166
  getTimelineHighlights(bookingList = [], startDateTime, endDateTime) {
200
167
  const bucketMinutes = this.getTimelineBucketMinutes();
201
- const bucketMs = bucketMinutes * 60 * 1000;
202
- const customStartAt = startDateTime ? (0, _dayjs.default)(startDateTime) : (0, _dayjs.default)('');
203
- const customEndExclusiveAt = endDateTime ? (0, _dayjs.default)(endDateTime) : (0, _dayjs.default)('');
168
+ const bucketMs = bucketMinutes * 60 * 1e3;
169
+ const customStartAt = startDateTime ? (0, import_dayjs.default)(startDateTime) : (0, import_dayjs.default)("");
170
+ const customEndExclusiveAt = endDateTime ? (0, import_dayjs.default)(endDateTime) : (0, import_dayjs.default)("");
204
171
  const hasValidCustomRange = customStartAt.isValid() && customEndExclusiveAt.isValid();
205
- const {
206
- startAt,
207
- endExclusiveAt
208
- } = hasValidCustomRange ? {
209
- startAt: customStartAt,
210
- endExclusiveAt: customEndExclusiveAt
211
- } : this.getTimelineRangeByOperatingBoundary();
172
+ const { startAt, endExclusiveAt } = hasValidCustomRange ? { startAt: customStartAt, endExclusiveAt: customEndExclusiveAt } : this.getTimelineRangeByOperatingBoundary();
212
173
  const startAtMs = startAt.valueOf();
213
174
  const endExclusiveAtMs = endExclusiveAt.valueOf();
214
- if (!startAt.isValid() || !endExclusiveAt.isValid() || endExclusiveAtMs <= startAtMs) return [];
175
+ if (!startAt.isValid() || !endExclusiveAt.isValid() || endExclusiveAtMs <= startAtMs)
176
+ return [];
215
177
  const slotCount = Math.ceil((endExclusiveAtMs - startAtMs) / bucketMs);
216
- if (slotCount <= 0) return [];
178
+ if (slotCount <= 0)
179
+ return [];
217
180
  const diff = new Int32Array(slotCount + 1);
218
181
  for (let i = 0; i < bookingList.length; i++) {
219
182
  const booking = bookingList[i];
220
- const appointmentStatus = String(booking.appointment_status ?? booking.status ?? '');
221
- if (appointmentStatus === 'new' || appointmentStatus === 'rejected' || appointmentStatus === 'cancelled') continue;
183
+ const appointmentStatus = String(booking.appointment_status ?? booking.status ?? "");
184
+ if (appointmentStatus === "new" || appointmentStatus === "rejected" || appointmentStatus === "cancelled")
185
+ continue;
222
186
  const bookingStartAt = this.toBookingDateTime(booking.start_date, booking.start_time);
223
187
  const bookingEndAt = this.toBookingDateTime(booking.end_date, booking.end_time);
224
- if (!bookingStartAt.isValid() || !bookingEndAt.isValid()) continue;
188
+ if (!bookingStartAt.isValid() || !bookingEndAt.isValid())
189
+ continue;
225
190
  const overlapStartMs = Math.max(bookingStartAt.valueOf(), startAtMs);
226
- // 结束时间按 <= 处理:转成右开区间时 +1ms,保证命中 end_time 所在时间片
227
191
  const overlapEndExclusiveMs = Math.min(bookingEndAt.valueOf() + 1, endExclusiveAtMs);
228
- if (overlapStartMs >= overlapEndExclusiveMs) continue;
192
+ if (overlapStartMs >= overlapEndExclusiveMs)
193
+ continue;
229
194
  const startIdx = Math.max(0, Math.ceil((overlapStartMs - startAtMs) / bucketMs));
230
- const endIdx = Math.min(slotCount - 1, Math.floor((overlapEndExclusiveMs - 1 - startAtMs) / bucketMs));
231
- if (startIdx > endIdx) continue;
195
+ const endIdx = Math.min(
196
+ slotCount - 1,
197
+ Math.floor((overlapEndExclusiveMs - 1 - startAtMs) / bucketMs)
198
+ );
199
+ if (startIdx > endIdx)
200
+ continue;
232
201
  diff[startIdx] += 1;
233
202
  diff[endIdx + 1] -= 1;
234
203
  }
@@ -240,17 +209,14 @@ class SalesImpl extends _BaseModule.BaseModule {
240
209
  }
241
210
  return timeline;
242
211
  }
243
-
244
212
  /** dayjs 未启用插件时,手动封装 >= 判断 */
245
213
  isSameOrAfter(left, right) {
246
214
  return left.isAfter(right) || left.isSame(right);
247
215
  }
248
-
249
216
  /** dayjs 未启用插件时,手动封装 <= 判断 */
250
217
  isSameOrBefore(left, right) {
251
218
  return left.isBefore(right) || left.isSame(right);
252
219
  }
253
-
254
220
  /**
255
221
  * 将 booking 的日期/时间字段统一组装为 dayjs
256
222
  * - date + time 都有:按完整时间解析
@@ -258,56 +224,63 @@ class SalesImpl extends _BaseModule.BaseModule {
258
224
  * - 都没有:返回 invalid
259
225
  */
260
226
  toBookingDateTime(date, time) {
261
- if (!date && !time) return (0, _dayjs.default)('');
262
- if (date && time) return (0, _dayjs.default)(`${date} ${time}`);
263
- return (0, _dayjs.default)(date || time);
227
+ if (!date && !time)
228
+ return (0, import_dayjs.default)("");
229
+ if (date && time)
230
+ return (0, import_dayjs.default)(`${date} ${time}`);
231
+ return (0, import_dayjs.default)(date || time);
264
232
  }
265
-
266
233
  /**
267
234
  * 预约状态映射(面向 UI 的统一状态)
268
235
  * 说明:locked 逻辑后续会补业务规则,这里先保留分支占位。
269
236
  */
270
237
  getBookingStatus(appointmentStatus) {
271
- if (appointmentStatus === 'started') return 'occupied';
272
- if (appointmentStatus === 'confirmed' || appointmentStatus === 'arrived') {
273
- return 'reserved';
238
+ if (appointmentStatus === "started")
239
+ return "occupied";
240
+ if (appointmentStatus === "confirmed" || appointmentStatus === "arrived") {
241
+ return "reserved";
274
242
  }
275
- // TODO: locked 的业务规则后续补充。
276
- if (appointmentStatus === 'locked') return 'locked';
277
- return undefined;
243
+ if (appointmentStatus === "locked")
244
+ return "locked";
245
+ return void 0;
278
246
  }
279
247
  getResourceId(resource) {
280
- return resource.id ?? resource.form_record_id ?? '';
248
+ return resource.id ?? resource.form_record_id ?? "";
281
249
  }
282
250
  getBookingAppointmentStatus(booking) {
283
- return String(booking.appointment_status ?? booking.status ?? '');
251
+ return String(booking.appointment_status ?? booking.status ?? "");
284
252
  }
285
253
  isBookingIncludedInStats(booking) {
286
254
  const appointmentStatus = this.getBookingAppointmentStatus(booking);
287
- return appointmentStatus !== 'new' && appointmentStatus !== 'rejected' && appointmentStatus !== 'cancelled';
255
+ return appointmentStatus !== "new" && appointmentStatus !== "rejected" && appointmentStatus !== "cancelled";
288
256
  }
289
257
  getBookingOrderPaymentStatus(booking) {
290
- return String(booking.order?.payment_status ?? '');
258
+ var _a;
259
+ return String(((_a = booking.order) == null ? void 0 : _a.payment_status) ?? "");
291
260
  }
292
261
  countBookingOrders(bookings) {
293
- const orderIds = new Set();
294
- bookings.forEach(booking => {
295
- const orderId = booking.order_id ?? booking.order?.order_id;
296
- if (orderId === undefined || orderId === null) return;
262
+ const orderIds = /* @__PURE__ */ new Set();
263
+ bookings.forEach((booking) => {
264
+ var _a;
265
+ const orderId = booking.order_id ?? ((_a = booking.order) == null ? void 0 : _a.order_id);
266
+ if (orderId === void 0 || orderId === null)
267
+ return;
297
268
  orderIds.add(String(orderId));
298
269
  });
299
270
  return orderIds.size;
300
271
  }
301
272
  countCompletedBookings(bookings) {
302
- return bookings.filter(booking => this.getBookingAppointmentStatus(booking) === 'completed').length;
273
+ return bookings.filter((booking) => this.getBookingAppointmentStatus(booking) === "completed").length;
303
274
  }
304
275
  groupBookingsByResource(bookingList) {
305
- const bookingMap = new Map();
306
- bookingList.forEach(booking => {
307
- if (!Array.isArray(booking.resources)) return;
308
- booking.resources.forEach(resource => {
309
- const relationId = resource?.relation_id;
310
- if (relationId === undefined || relationId === null) return;
276
+ const bookingMap = /* @__PURE__ */ new Map();
277
+ bookingList.forEach((booking) => {
278
+ if (!Array.isArray(booking.resources))
279
+ return;
280
+ booking.resources.forEach((resource) => {
281
+ const relationId = resource == null ? void 0 : resource.relation_id;
282
+ if (relationId === void 0 || relationId === null)
283
+ return;
311
284
  const key = String(relationId);
312
285
  const list = bookingMap.get(key) || [];
313
286
  list.push(booking);
@@ -317,10 +290,12 @@ class SalesImpl extends _BaseModule.BaseModule {
317
290
  return bookingMap;
318
291
  }
319
292
  isBookingMatchedResource(booking, resourceId) {
320
- if (!Array.isArray(booking.resources)) return false;
321
- return booking.resources.some(resource => {
322
- const relationId = resource?.relation_id;
323
- if (relationId === undefined || relationId === null) return false;
293
+ if (!Array.isArray(booking.resources))
294
+ return false;
295
+ return booking.resources.some((resource) => {
296
+ const relationId = resource == null ? void 0 : resource.relation_id;
297
+ if (relationId === void 0 || relationId === null)
298
+ return false;
324
299
  return String(relationId) === String(resourceId);
325
300
  });
326
301
  }
@@ -331,7 +306,6 @@ class SalesImpl extends _BaseModule.BaseModule {
331
306
  return leftStartAt - rightStartAt;
332
307
  });
333
308
  }
334
-
335
309
  /**
336
310
  * 资源下 bookings 的返回裁剪策略:
337
311
  * 1) 优先返回当前时刻正在进行中的预约(允许并发返回多条)
@@ -340,88 +314,100 @@ class SalesImpl extends _BaseModule.BaseModule {
340
314
  * 4) 最后兜底返回一条(避免资源有历史预约时完全无反馈)
341
315
  */
342
316
  pickBookingsForCurrentPoint(current, bookings) {
343
- if (bookings.length === 0) return [];
344
- const currentDayStart = current.startOf('day');
345
- const currentDayEnd = current.endOf('day');
346
-
347
- // 仅保留与 current 当天有时间交集的预约,避免跨天误命中
348
- const dayScopedBookings = bookings.filter(booking => {
317
+ if (bookings.length === 0)
318
+ return [];
319
+ const currentDayStart = current.startOf("day");
320
+ const currentDayEnd = current.endOf("day");
321
+ const dayScopedBookings = bookings.filter((booking) => {
349
322
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
350
323
  const endAt = this.toBookingDateTime(booking.end_date, booking.end_time);
351
- if (!startAt.isValid() || !endAt.isValid()) return false;
324
+ if (!startAt.isValid() || !endAt.isValid())
325
+ return false;
352
326
  return this.isSameOrBefore(startAt, currentDayEnd) && this.isSameOrAfter(endAt, currentDayStart);
353
327
  });
354
- if (dayScopedBookings.length === 0) return [];
355
- const appendNextStartGroupIfNeeded = selectedBookings => {
356
- if (selectedBookings.length === 0) return selectedBookings;
357
- const shouldAppendNextGroup = selectedBookings.some(booking => booking.status === 'reserved' || booking.status === 'occupied');
358
- if (!shouldAppendNextGroup) return selectedBookings;
359
- const selectedStartValues = new Set(selectedBookings.map(booking => this.toBookingDateTime(booking.start_date, booking.start_time)).filter(startAt => startAt.isValid()).map(startAt => startAt.valueOf()));
360
- const futureCandidates = dayScopedBookings.filter(booking => {
328
+ if (dayScopedBookings.length === 0)
329
+ return [];
330
+ const appendNextStartGroupIfNeeded = (selectedBookings) => {
331
+ if (selectedBookings.length === 0)
332
+ return selectedBookings;
333
+ const shouldAppendNextGroup = selectedBookings.some(
334
+ (booking) => booking.status === "reserved" || booking.status === "occupied"
335
+ );
336
+ if (!shouldAppendNextGroup)
337
+ return selectedBookings;
338
+ const selectedStartValues = new Set(
339
+ selectedBookings.map((booking) => this.toBookingDateTime(booking.start_date, booking.start_time)).filter((startAt) => startAt.isValid()).map((startAt) => startAt.valueOf())
340
+ );
341
+ const futureCandidates = dayScopedBookings.filter((booking) => {
361
342
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
362
- if (!startAt.isValid()) return false;
343
+ if (!startAt.isValid())
344
+ return false;
363
345
  return startAt.isAfter(current) && !selectedStartValues.has(startAt.valueOf());
364
346
  });
365
- if (futureCandidates.length === 0) return selectedBookings;
366
- const nextStartAt = this.toBookingDateTime(futureCandidates[0].start_date, futureCandidates[0].start_time).valueOf();
367
- const nextStartGroup = futureCandidates.filter(booking => {
347
+ if (futureCandidates.length === 0)
348
+ return selectedBookings;
349
+ const nextStartAt = this.toBookingDateTime(
350
+ futureCandidates[0].start_date,
351
+ futureCandidates[0].start_time
352
+ ).valueOf();
353
+ const nextStartGroup = futureCandidates.filter((booking) => {
368
354
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
369
355
  return startAt.isValid() && startAt.valueOf() === nextStartAt;
370
356
  });
371
- if (nextStartGroup.length === 0) return selectedBookings;
372
- nextStartGroup.forEach(booking => {
357
+ if (nextStartGroup.length === 0)
358
+ return selectedBookings;
359
+ nextStartGroup.forEach((booking) => {
373
360
  booking.isNext = true;
374
361
  });
375
362
  return [...selectedBookings, ...nextStartGroup];
376
363
  };
377
-
378
- // active: current 处于 [startAt, endAt] 区间
379
- const activeBookings = dayScopedBookings.filter(booking => {
364
+ const activeBookings = dayScopedBookings.filter((booking) => {
380
365
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
381
366
  const endAt = this.toBookingDateTime(booking.end_date, booking.end_time);
382
- if (!startAt.isValid() || !endAt.isValid()) return false;
367
+ if (!startAt.isValid() || !endAt.isValid())
368
+ return false;
383
369
  return this.isSameOrAfter(current, startAt) && this.isSameOrBefore(current, endAt);
384
370
  });
385
- if (activeBookings.length > 0) return appendNextStartGroupIfNeeded(activeBookings);
386
-
387
- // timeout occupied: 占用中且超时
388
- const timeoutOccupied = dayScopedBookings.filter(booking => booking.status === 'occupied' && booking.isTimeout);
389
- if (timeoutOccupied.length > 0) return appendNextStartGroupIfNeeded(timeoutOccupied);
390
-
391
- // upcoming: 从未来预约里只取最早那一组(同 start_time)
392
- const upcoming = dayScopedBookings.filter(booking => {
371
+ if (activeBookings.length > 0)
372
+ return appendNextStartGroupIfNeeded(activeBookings);
373
+ const timeoutOccupied = dayScopedBookings.filter(
374
+ (booking) => booking.status === "occupied" && booking.isTimeout
375
+ );
376
+ if (timeoutOccupied.length > 0)
377
+ return appendNextStartGroupIfNeeded(timeoutOccupied);
378
+ const upcoming = dayScopedBookings.filter((booking) => {
393
379
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
394
- return startAt.isValid() && startAt.isAfter(current) && startAt.isSame(current, 'day');
380
+ return startAt.isValid() && startAt.isAfter(current) && startAt.isSame(current, "day");
395
381
  });
396
382
  if (upcoming.length > 0) {
397
383
  const firstStartAt = this.toBookingDateTime(upcoming[0].start_date, upcoming[0].start_time).valueOf();
398
- const upcomingStartGroup = upcoming.filter(booking => {
384
+ const upcomingStartGroup = upcoming.filter((booking) => {
399
385
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
400
386
  return startAt.valueOf() === firstStartAt;
401
387
  });
402
388
  return appendNextStartGroupIfNeeded(upcomingStartGroup);
403
389
  }
404
-
405
- // fallback: 全部是过去且非 timeout 的场景,保留末条便于前端兜底展示
406
390
  const fallback = dayScopedBookings[dayScopedBookings.length - 1];
407
391
  return fallback ? [fallback] : [];
408
392
  }
409
-
410
393
  /**
411
394
  * 计算 booking 在 current 时刻的执行进度百分比(0-100)。
412
395
  * - startAt/endAt 非法或 totalMinutes <= 0 返回 0
413
396
  * - current 早于 startAt 返回 0,晚于 endAt 返回 100
414
397
  */
415
398
  calcProgressPercent(current, startAt, endAt) {
416
- if (!startAt.isValid() || !endAt.isValid()) return 0;
417
- const totalMinutes = endAt.diff(startAt, 'minute');
418
- if (totalMinutes <= 0) return 0;
419
- const elapsedMinutes = current.diff(startAt, 'minute');
420
- if (elapsedMinutes <= 0) return 0;
421
- if (elapsedMinutes >= totalMinutes) return 100;
399
+ if (!startAt.isValid() || !endAt.isValid())
400
+ return 0;
401
+ const totalMinutes = endAt.diff(startAt, "minute");
402
+ if (totalMinutes <= 0)
403
+ return 0;
404
+ const elapsedMinutes = current.diff(startAt, "minute");
405
+ if (elapsedMinutes <= 0)
406
+ return 0;
407
+ if (elapsedMinutes >= totalMinutes)
408
+ return 100;
422
409
  return Math.floor(elapsedMinutes / totalMinutes * 100);
423
410
  }
424
-
425
411
  /**
426
412
  * 标准化单条 booking 的分发入口:
427
413
  * - 统一过滤 rejected / cancelled(视为没来过)
@@ -430,10 +416,11 @@ class SalesImpl extends _BaseModule.BaseModule {
430
416
  */
431
417
  normalizeMatchedBooking(current, deviceCurrent, booking, options = {}) {
432
418
  const appointmentStatus = this.getBookingAppointmentStatus(booking);
433
- if (appointmentStatus === 'rejected' || appointmentStatus === 'cancelled') return null;
419
+ if (appointmentStatus === "rejected" || appointmentStatus === "cancelled")
420
+ return null;
434
421
  const startAt = this.toBookingDateTime(booking.start_date, booking.start_time);
435
422
  const endAt = this.toBookingDateTime(booking.end_date, booking.end_time);
436
- if (appointmentStatus === 'completed' && options.includeCompleted) {
423
+ if (appointmentStatus === "completed" && options.includeCompleted) {
437
424
  return this.buildCompletedBooking(current, booking, startAt, endAt);
438
425
  }
439
426
  if (current.isSame(deviceCurrent)) {
@@ -442,35 +429,35 @@ class SalesImpl extends _BaseModule.BaseModule {
442
429
  return this.buildSnapshotBooking(current, booking, appointmentStatus, startAt, endAt);
443
430
  }
444
431
  normalizeResourceBookings(current, deviceCurrent, bookingList, options = {}) {
445
- const normalizedBookings = bookingList.map(booking => this.normalizeMatchedBooking(current, deviceCurrent, booking, options)).filter(booking => Boolean(booking)).filter(booking => booking.status);
432
+ const normalizedBookings = bookingList.map((booking) => this.normalizeMatchedBooking(current, deviceCurrent, booking, options)).filter((booking) => Boolean(booking)).filter((booking) => booking.status);
446
433
  return this.sortMatchedBookings(normalizedBookings);
447
434
  }
448
435
  buildCompletedBooking(current, booking, startAt, endAt) {
449
- if (!startAt.isValid() || !endAt.isValid()) return null;
436
+ if (!startAt.isValid() || !endAt.isValid())
437
+ return null;
450
438
  if (current.isBefore(startAt)) {
451
439
  return {
452
440
  ...booking,
453
- status: 'reserved',
441
+ status: "reserved",
454
442
  isTimeout: false,
455
- timeoutTime: undefined,
443
+ timeoutTime: void 0,
456
444
  progressPercent: 0,
457
- lateTime: undefined,
458
- reserved_status: 'not_arrived',
459
- remainingReserveTime: Math.max(startAt.diff(current, 'minute'), 0)
445
+ lateTime: void 0,
446
+ reserved_status: "not_arrived",
447
+ remainingReserveTime: Math.max(startAt.diff(current, "minute"), 0)
460
448
  };
461
449
  }
462
450
  return {
463
451
  ...booking,
464
- status: 'occupied',
452
+ status: "occupied",
465
453
  isTimeout: false,
466
- timeoutTime: undefined,
454
+ timeoutTime: void 0,
467
455
  progressPercent: this.isSameOrAfter(current, endAt) ? 100 : this.calcProgressPercent(current, startAt, endAt),
468
- lateTime: undefined,
469
- reserved_status: undefined,
470
- remainingReserveTime: undefined
456
+ lateTime: void 0,
457
+ reserved_status: void 0,
458
+ remainingReserveTime: void 0
471
459
  };
472
460
  }
473
-
474
461
  /**
475
462
  * 实时模式(current === deviceCurrent):信任 appointment_status
476
463
  * - 过滤 new / completed(实时视角下视为非活跃数据)
@@ -479,21 +466,22 @@ class SalesImpl extends _BaseModule.BaseModule {
479
466
  * - reserved 且 current < startAt 标记 not_arrived,否则标记 late
480
467
  */
481
468
  buildRealtimeBooking(current, booking, appointmentStatus, startAt, endAt) {
482
- if (appointmentStatus === 'new' || appointmentStatus === 'completed') return null;
469
+ if (appointmentStatus === "new" || appointmentStatus === "completed")
470
+ return null;
483
471
  const bookingStatus = this.getBookingStatus(appointmentStatus);
484
- const isTimeout = bookingStatus === 'occupied' && endAt.isValid() && current.isAfter(endAt);
485
- const timeoutTime = isTimeout ? current.diff(endAt, 'minute') : undefined;
486
- const progressPercent = bookingStatus === 'occupied' ? this.calcProgressPercent(current, startAt, endAt) : 0;
472
+ const isTimeout = bookingStatus === "occupied" && endAt.isValid() && current.isAfter(endAt);
473
+ const timeoutTime = isTimeout ? current.diff(endAt, "minute") : void 0;
474
+ const progressPercent = bookingStatus === "occupied" ? this.calcProgressPercent(current, startAt, endAt) : 0;
487
475
  let reservedStatus;
488
476
  let lateTime;
489
477
  let remainingReserveTime;
490
- if (bookingStatus === 'reserved' && startAt.isValid()) {
478
+ if (bookingStatus === "reserved" && startAt.isValid()) {
491
479
  if (current.isBefore(startAt)) {
492
- reservedStatus = 'not_arrived';
493
- remainingReserveTime = startAt.diff(current, 'minute');
480
+ reservedStatus = "not_arrived";
481
+ remainingReserveTime = startAt.diff(current, "minute");
494
482
  } else {
495
- reservedStatus = 'late';
496
- lateTime = Math.max(current.diff(startAt, 'minute'), 0);
483
+ reservedStatus = "late";
484
+ lateTime = Math.max(current.diff(startAt, "minute"), 0);
497
485
  }
498
486
  }
499
487
  return {
@@ -507,7 +495,6 @@ class SalesImpl extends _BaseModule.BaseModule {
507
495
  remainingReserveTime
508
496
  };
509
497
  }
510
-
511
498
  /**
512
499
  * 快照模式(current !== deviceCurrent,过去或未来):忽略 appointment_status
513
500
  * 的实时态差异,仅按 booking 时间窗判定,为 current 提供时间点快照视图。
@@ -523,77 +510,72 @@ class SalesImpl extends _BaseModule.BaseModule {
523
510
  * 快照模式下 isTimeout 恒为 false,lateTime / timeoutTime 始终置空。
524
511
  */
525
512
  buildSnapshotBooking(current, booking, appointmentStatus, startAt, endAt) {
526
- if (appointmentStatus === 'new') return null;
527
- if (appointmentStatus === 'locked') {
513
+ if (appointmentStatus === "new")
514
+ return null;
515
+ if (appointmentStatus === "locked") {
528
516
  return {
529
517
  ...booking,
530
- status: 'locked',
518
+ status: "locked",
531
519
  isTimeout: false,
532
- timeoutTime: undefined,
520
+ timeoutTime: void 0,
533
521
  progressPercent: 0,
534
- lateTime: undefined,
535
- reserved_status: undefined,
536
- remainingReserveTime: undefined
522
+ lateTime: void 0,
523
+ reserved_status: void 0,
524
+ remainingReserveTime: void 0
537
525
  };
538
526
  }
539
- if (!startAt.isValid() || !endAt.isValid()) return null;
540
- if (current.isAfter(endAt)) return null;
527
+ if (!startAt.isValid() || !endAt.isValid())
528
+ return null;
529
+ if (current.isAfter(endAt))
530
+ return null;
541
531
  if (this.isSameOrAfter(current, startAt) && this.isSameOrBefore(current, endAt)) {
542
532
  return {
543
533
  ...booking,
544
- status: 'occupied',
534
+ status: "occupied",
545
535
  isTimeout: false,
546
- timeoutTime: undefined,
536
+ timeoutTime: void 0,
547
537
  progressPercent: this.calcProgressPercent(current, startAt, endAt),
548
- lateTime: undefined,
549
- reserved_status: undefined,
550
- remainingReserveTime: undefined
538
+ lateTime: void 0,
539
+ reserved_status: void 0,
540
+ remainingReserveTime: void 0
551
541
  };
552
542
  }
553
543
  return {
554
544
  ...booking,
555
- status: 'reserved',
545
+ status: "reserved",
556
546
  isTimeout: false,
557
- timeoutTime: undefined,
547
+ timeoutTime: void 0,
558
548
  progressPercent: 0,
559
- lateTime: undefined,
560
- reserved_status: 'not_arrived',
561
- remainingReserveTime: Math.max(startAt.diff(current, 'minute'), 0)
549
+ lateTime: void 0,
550
+ reserved_status: "not_arrived",
551
+ remainingReserveTime: Math.max(startAt.diff(current, "minute"), 0)
562
552
  };
563
553
  }
564
554
  async getResourceBookingList(currentTime, bookingList = [], deviceTime = currentTime) {
565
- // currentTime 约定为完整 datetime;非法值直接返回空,避免误判
566
- const current = (0, _dayjs.default)(currentTime);
567
- if (!current.isValid()) return [];
568
- const deviceCurrent = (0, _dayjs.default)(deviceTime);
569
- if (!deviceCurrent.isValid()) return [];
570
-
571
- // 资源列表来源:Server 路由 /shop/form/resource/page
572
- const resourceResponse = await this.request.get('/shop/form/resource/page', {
573
- skip: 1,
574
- num: 999
575
- },
576
- // @ts-ignore
577
- {
578
- osServer: true,
579
- isShopApi: true
580
- });
581
- const resourceList = resourceResponse?.data?.list ?? [];
582
- if (!Array.isArray(resourceList) || resourceList.length === 0) return [];
583
-
584
- // 全局先做 booking 标准化 + start_time 升序,后续映射直接复用
555
+ var _a;
556
+ const current = (0, import_dayjs.default)(currentTime);
557
+ if (!current.isValid())
558
+ return [];
559
+ const deviceCurrent = (0, import_dayjs.default)(deviceTime);
560
+ if (!deviceCurrent.isValid())
561
+ return [];
562
+ const resourceResponse = await this.request.get(
563
+ "/shop/form/resource/page",
564
+ { skip: 1, num: 999 },
565
+ // @ts-ignore
566
+ { osServer: true, isShopApi: true }
567
+ );
568
+ const resourceList = ((_a = resourceResponse == null ? void 0 : resourceResponse.data) == null ? void 0 : _a.list) ?? [];
569
+ if (!Array.isArray(resourceList) || resourceList.length === 0)
570
+ return [];
585
571
  const normalizedBookings = this.normalizeResourceBookings(current, deviceCurrent, bookingList);
586
-
587
- // 建立 resourceId -> bookings[] 倒排索引,加速资源匹配
588
572
  const rawBookingMap = this.groupBookingsByResource(bookingList);
589
573
  const bookingMap = this.groupBookingsByResource(normalizedBookings);
590
-
591
- // 输出:每个资源都返回;bookings 可能是 0 / 1 / 多条(并发场景)
592
- const list = resourceList.map(resource => {
574
+ const list = resourceList.map((resource) => {
593
575
  const resourceId = this.getResourceId(resource);
594
576
  const rawMatchedBookings = rawBookingMap.get(String(resourceId)) || [];
595
577
  const matchedBookings = bookingMap.get(String(resourceId)) || [];
596
- const statsBookings = rawMatchedBookings.filter(booking => this.isBookingIncludedInStats(booking));
578
+ const statsBookings = rawMatchedBookings.filter((booking) => this.isBookingIncludedInStats(booking));
597
579
  const orderCount = this.countBookingOrders(statsBookings);
598
580
  const bookingCount = statsBookings.length;
599
581
  const compeleteBookingCount = this.countCompletedBookings(statsBookings);
@@ -608,65 +590,81 @@ class SalesImpl extends _BaseModule.BaseModule {
608
590
  };
609
591
  });
610
592
  this.logger.addLog({
611
- type: 'info',
612
- title: 'getResourceBookingList',
593
+ type: "info",
594
+ title: "getResourceBookingList",
613
595
  metadata: {
614
596
  currentTime,
615
- bookingList: bookingList?.length,
597
+ bookingList: bookingList == null ? void 0 : bookingList.length,
616
598
  deviceTime,
617
- list: list?.length
599
+ list: list == null ? void 0 : list.length
618
600
  }
619
601
  });
620
602
  return list;
621
603
  }
622
604
  async getResourceBookingItem(params) {
623
- const current = (0, _dayjs.default)(params.currentTime);
624
- if (!current.isValid()) return null;
625
- const deviceCurrent = (0, _dayjs.default)(params.deviceTime || params.currentTime);
626
- if (!deviceCurrent.isValid()) return null;
627
- const resourceResponse = await this.request.get('/shop/form/resource/page', {
628
- skip: 1,
629
- num: 999
630
- },
631
- // @ts-ignore
632
- {
633
- osServer: true,
634
- isShopApi: true
635
- });
636
- const resourceList = resourceResponse?.data?.list ?? [];
637
- if (!Array.isArray(resourceList) || resourceList.length === 0) return null;
638
- const targetResource = resourceList.find(resource => String(this.getResourceId(resource)) === String(params.resourceId));
639
- if (!targetResource) return null;
605
+ var _a, _b;
606
+ const current = (0, import_dayjs.default)(params.currentTime);
607
+ if (!current.isValid())
608
+ return null;
609
+ const deviceCurrent = (0, import_dayjs.default)(params.deviceTime || params.currentTime);
610
+ if (!deviceCurrent.isValid())
611
+ return null;
612
+ const resourceResponse = await this.request.get(
613
+ "/shop/form/resource/page",
614
+ { skip: 1, num: 999 },
615
+ // @ts-ignore
616
+ { osServer: true, isShopApi: true }
617
+ );
618
+ const resourceList = ((_a = resourceResponse == null ? void 0 : resourceResponse.data) == null ? void 0 : _a.list) ?? [];
619
+ if (!Array.isArray(resourceList) || resourceList.length === 0)
620
+ return null;
621
+ const targetResource = resourceList.find(
622
+ (resource) => String(this.getResourceId(resource)) === String(params.resourceId)
623
+ );
624
+ if (!targetResource)
625
+ return null;
640
626
  const resourceId = this.getResourceId(targetResource);
641
- const matchedBookingList = params.bookingList.filter(booking => this.isBookingMatchedResource(booking, resourceId));
642
- const statsBookingList = matchedBookingList.filter(booking => this.isBookingIncludedInStats(booking));
643
- const completedBookingList = matchedBookingList.filter(booking => this.getBookingAppointmentStatus(booking) === 'completed');
644
- const unpaidBookingList = matchedBookingList.filter(booking => this.getBookingOrderPaymentStatus(booking) === 'unpaid' || this.getBookingOrderPaymentStatus(booking) === 'payment_processing');
645
- const bookings = this.pickBookingsForCurrentPoint(current, this.normalizeResourceBookings(current, deviceCurrent, matchedBookingList));
646
- const completedBookings = completedBookingList.map(booking => {
627
+ const matchedBookingList = params.bookingList.filter(
628
+ (booking) => this.isBookingMatchedResource(booking, resourceId)
629
+ );
630
+ const statsBookingList = matchedBookingList.filter((booking) => this.isBookingIncludedInStats(booking));
631
+ const completedBookingList = matchedBookingList.filter(
632
+ (booking) => this.getBookingAppointmentStatus(booking) === "completed"
633
+ );
634
+ const unpaidBookingList = matchedBookingList.filter(
635
+ (booking) => this.getBookingOrderPaymentStatus(booking) === "unpaid" || this.getBookingOrderPaymentStatus(booking) === "payment_processing"
636
+ );
637
+ const bookings = this.pickBookingsForCurrentPoint(
638
+ current,
639
+ this.normalizeResourceBookings(current, deviceCurrent, matchedBookingList)
640
+ );
641
+ const completedBookings = completedBookingList.map((booking) => {
647
642
  return {
648
643
  ...booking,
649
- status: 'compelete',
644
+ status: "compelete",
650
645
  isTimeout: false,
651
- timeoutTime: undefined,
646
+ timeoutTime: void 0,
652
647
  progressPercent: 100,
653
- lateTime: undefined,
654
- reserved_status: undefined,
655
- remainingReserveTime: undefined
648
+ lateTime: void 0,
649
+ reserved_status: void 0,
650
+ remainingReserveTime: void 0
656
651
  };
657
652
  });
658
- const unpaidBookings = this.pickBookingsForCurrentPoint(current, this.normalizeResourceBookings(current, deviceCurrent, unpaidBookingList));
653
+ const unpaidBookings = this.pickBookingsForCurrentPoint(
654
+ current,
655
+ this.normalizeResourceBookings(current, deviceCurrent, unpaidBookingList)
656
+ );
659
657
  const orderCount = this.countBookingOrders(statsBookingList);
660
658
  const bookingCount = statsBookingList.length;
661
659
  const compeleteBookingCount = this.countCompletedBookings(statsBookingList);
662
660
  this.logger.addLog({
663
- type: 'info',
664
- title: 'getResourceBookingItem',
661
+ type: "info",
662
+ title: "getResourceBookingItem",
665
663
  metadata: {
666
664
  currentTime: params.currentTime,
667
665
  deviceTime: params.deviceTime || params.currentTime,
668
666
  resourceId,
669
- bookingList: params.bookingList?.length,
667
+ bookingList: (_b = params.bookingList) == null ? void 0 : _b.length,
670
668
  bookings: bookings.length,
671
669
  completedBookings: completedBookings.length,
672
670
  unpaidBookings: unpaidBookings.length,
@@ -686,6 +684,11 @@ class SalesImpl extends _BaseModule.BaseModule {
686
684
  unpaidBookings
687
685
  };
688
686
  }
689
- }
690
- exports.Sales = exports.SalesImpl = SalesImpl;
691
- var _default = exports.default = SalesImpl;
687
+ };
688
+ var Sales_default = SalesImpl;
689
+ // Annotate the CommonJS export names for ESM import in node:
690
+ 0 && (module.exports = {
691
+ Sales,
692
+ SalesImpl,
693
+ ...require("./types")
694
+ });