@pisell/pisellos 2.1.38 → 2.2.1

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 (135) hide show
  1. package/dist/core/index.d.ts +8 -1
  2. package/dist/core/index.js +116 -42
  3. package/dist/effects/index.d.ts +1 -0
  4. package/dist/effects/index.js +29 -6
  5. package/dist/modules/Account/index.js +2 -3
  6. package/dist/modules/BaseModule.d.ts +3 -0
  7. package/dist/modules/BaseModule.js +15 -0
  8. package/dist/modules/Customer/index.js +9 -10
  9. package/dist/modules/Customer/types.d.ts +2 -2
  10. package/dist/modules/Customer/types.js +2 -2
  11. package/dist/modules/Discount/index.js +1 -1
  12. package/dist/modules/Guests/index.js +9 -9
  13. package/dist/modules/Order/index.js +1 -1
  14. package/dist/modules/Payment/index.js +63 -73
  15. package/dist/modules/Payment/walletpass.js +4 -1
  16. package/dist/modules/Product/index.d.ts +1 -1
  17. package/dist/modules/Product/types.d.ts +19 -0
  18. package/dist/modules/ProductList/index.js +5 -14
  19. package/dist/modules/Resource/index.js +1 -1
  20. package/dist/modules/Rules/index.js +2 -3
  21. package/dist/modules/Schedule/types.d.ts +2 -0
  22. package/dist/plugins/request.d.ts +1 -0
  23. package/dist/server/index.d.ts +152 -0
  24. package/dist/server/index.js +946 -0
  25. package/dist/server/modules/index.d.ts +16 -0
  26. package/dist/server/modules/index.js +21 -0
  27. package/dist/server/modules/menu/index.d.ts +63 -0
  28. package/dist/server/modules/menu/index.js +476 -0
  29. package/dist/server/modules/menu/types.d.ts +68 -0
  30. package/dist/server/modules/menu/types.js +16 -0
  31. package/dist/server/modules/products/index.d.ts +141 -0
  32. package/dist/server/modules/products/index.js +768 -0
  33. package/dist/server/modules/products/types.d.ts +94 -0
  34. package/dist/server/modules/products/types.js +43 -0
  35. package/dist/server/modules/quotation/index.d.ts +47 -0
  36. package/dist/server/modules/quotation/index.js +367 -0
  37. package/dist/server/modules/quotation/types.d.ts +50 -0
  38. package/dist/server/modules/quotation/types.js +20 -0
  39. package/dist/server/modules/schedule/index.d.ts +62 -0
  40. package/dist/server/modules/schedule/index.js +431 -0
  41. package/dist/server/modules/schedule/types.d.ts +1 -0
  42. package/dist/server/modules/schedule/types.js +2 -0
  43. package/dist/server/modules/schedule/utils.d.ts +32 -0
  44. package/dist/server/modules/schedule/utils.js +747 -0
  45. package/dist/server/types.d.ts +64 -0
  46. package/dist/server/types.js +1 -0
  47. package/dist/server/utils/index.d.ts +5 -0
  48. package/dist/server/utils/index.js +6 -0
  49. package/dist/server/utils/product.d.ts +18 -0
  50. package/dist/server/utils/product.js +339 -0
  51. package/dist/server/utils/schedule.d.ts +14 -0
  52. package/dist/server/utils/schedule.js +108 -0
  53. package/dist/server/utils/time.d.ts +18 -0
  54. package/dist/server/utils/time.js +53 -0
  55. package/dist/solution/BookingByStep/index.d.ts +1 -17
  56. package/dist/solution/BookingByStep/index.js +23 -468
  57. package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
  58. package/dist/solution/BookingByStep/utils/capacity.js +8 -24
  59. package/dist/solution/BookingTicket/index.d.ts +12 -0
  60. package/dist/solution/BookingTicket/index.js +122 -79
  61. package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  62. package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
  63. package/dist/solution/BuyTickets/index.js +7 -8
  64. package/dist/solution/Checkout/index.d.ts +1 -46
  65. package/dist/solution/Checkout/index.js +530 -850
  66. package/dist/solution/ShopDiscount/index.js +9 -10
  67. package/dist/types/index.d.ts +27 -0
  68. package/lib/core/index.d.ts +8 -1
  69. package/lib/core/index.js +48 -1
  70. package/lib/effects/index.d.ts +1 -0
  71. package/lib/effects/index.js +13 -0
  72. package/lib/modules/Account/index.js +2 -3
  73. package/lib/modules/BaseModule.d.ts +3 -0
  74. package/lib/modules/BaseModule.js +9 -0
  75. package/lib/modules/Customer/index.js +9 -10
  76. package/lib/modules/Customer/types.d.ts +2 -2
  77. package/lib/modules/Customer/types.js +2 -2
  78. package/lib/modules/Discount/index.js +1 -1
  79. package/lib/modules/Guests/index.js +9 -9
  80. package/lib/modules/Order/index.js +1 -1
  81. package/lib/modules/Payment/index.js +56 -43
  82. package/lib/modules/Payment/walletpass.js +3 -1
  83. package/lib/modules/Product/index.d.ts +1 -1
  84. package/lib/modules/Product/types.d.ts +19 -0
  85. package/lib/modules/ProductList/index.js +4 -13
  86. package/lib/modules/Resource/index.js +1 -1
  87. package/lib/modules/Rules/index.js +2 -3
  88. package/lib/modules/Schedule/types.d.ts +2 -0
  89. package/lib/plugins/request.d.ts +1 -0
  90. package/lib/server/index.d.ts +152 -0
  91. package/lib/server/index.js +555 -0
  92. package/lib/server/modules/index.d.ts +16 -0
  93. package/lib/server/modules/index.js +47 -0
  94. package/lib/server/modules/menu/index.d.ts +63 -0
  95. package/lib/server/modules/menu/index.js +234 -0
  96. package/lib/server/modules/menu/types.d.ts +68 -0
  97. package/lib/server/modules/menu/types.js +33 -0
  98. package/lib/server/modules/products/index.d.ts +141 -0
  99. package/lib/server/modules/products/index.js +434 -0
  100. package/lib/server/modules/products/types.d.ts +94 -0
  101. package/lib/server/modules/products/types.js +35 -0
  102. package/lib/server/modules/quotation/index.d.ts +47 -0
  103. package/lib/server/modules/quotation/index.js +177 -0
  104. package/lib/server/modules/quotation/types.d.ts +50 -0
  105. package/lib/server/modules/quotation/types.js +33 -0
  106. package/lib/server/modules/schedule/index.d.ts +62 -0
  107. package/lib/server/modules/schedule/index.js +231 -0
  108. package/lib/server/modules/schedule/types.d.ts +1 -0
  109. package/lib/server/modules/schedule/types.js +23 -0
  110. package/lib/server/modules/schedule/utils.d.ts +32 -0
  111. package/lib/server/modules/schedule/utils.js +451 -0
  112. package/lib/server/types.d.ts +64 -0
  113. package/lib/server/types.js +17 -0
  114. package/lib/server/utils/index.d.ts +5 -0
  115. package/lib/server/utils/index.js +25 -0
  116. package/lib/server/utils/product.d.ts +18 -0
  117. package/lib/server/utils/product.js +262 -0
  118. package/lib/server/utils/schedule.d.ts +14 -0
  119. package/lib/server/utils/schedule.js +88 -0
  120. package/lib/server/utils/time.d.ts +18 -0
  121. package/lib/server/utils/time.js +70 -0
  122. package/lib/solution/BookingByStep/index.d.ts +1 -17
  123. package/lib/solution/BookingByStep/index.js +40 -312
  124. package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
  125. package/lib/solution/BookingByStep/utils/capacity.js +8 -21
  126. package/lib/solution/BookingTicket/index.d.ts +12 -0
  127. package/lib/solution/BookingTicket/index.js +25 -6
  128. package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  129. package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
  130. package/lib/solution/BuyTickets/index.js +7 -8
  131. package/lib/solution/Checkout/index.d.ts +1 -46
  132. package/lib/solution/Checkout/index.js +92 -289
  133. package/lib/solution/ShopDiscount/index.js +10 -11
  134. package/lib/types/index.d.ts +27 -0
  135. package/package.json +2 -2
@@ -29,8 +29,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
29
29
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
30
30
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
31
31
  import { BaseModule } from "../../modules/BaseModule";
32
- import { BookingByStepHooks, createModule } from "./types";
33
- import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
32
+ import { createModule } from "./types";
34
33
  import { getAvailableProductResources } from "./utils/products";
35
34
  import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
36
35
  import dayjs from 'dayjs';
@@ -137,7 +136,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
137
136
  }
138
137
  });
139
138
  this.store.schedule.loadAllSchedule();
140
- this.core.effects.emit(BookingByStepHooks.onInited, {});
139
+ this.core.effects.emit("".concat(this.name, ":onInited"), {});
141
140
  case 19:
142
141
  case "end":
143
142
  return _context.stop();
@@ -1195,16 +1194,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1195
1194
  this.addProductCheck({
1196
1195
  date: date
1197
1196
  });
1198
- // 如果 quantity 大于 1,且是预约商品,则进入购物车拆散成多条数据
1199
- if (addItemParams.quantity > 1 && !isNormalProduct(productData)) {
1200
- for (var i = 0; i < addItemParams.quantity; i++) {
1201
- var newAddItemParams = cloneDeep(addItemParams);
1202
- newAddItemParams.quantity = 1;
1203
- this.store.cart.addItem(newAddItemParams);
1204
- }
1205
- } else {
1206
- this.store.cart.addItem(addItemParams);
1207
- }
1197
+ this.store.cart.addItem(addItemParams);
1208
1198
  return {
1209
1199
  success: true
1210
1200
  };
@@ -3048,11 +3038,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3048
3038
  });
3049
3039
 
3050
3040
  // 按资源类型分组检查容量
3051
- var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3052
- success = _checkTimeSlotCapacit.success,
3053
- required = _checkTimeSlotCapacit.required,
3054
- available = _checkTimeSlotCapacit.available;
3055
- if (!success) {
3041
+ if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3056
3042
  // 如果有可用数量记录,返回最小值;否则返回 0
3057
3043
  var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3058
3044
  return {
@@ -3077,437 +3063,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3077
3063
  minAvailableCount: minAvailableCount
3078
3064
  };
3079
3065
  }
3080
-
3081
- /**
3082
- * 将 ProductData 转换为 CartItem,但不添加到购物车
3083
- * 参考 addProductToCart 方法的实现
3084
- */
3085
- }, {
3086
- key: "convertProductToCartItem",
3087
- value: function convertProductToCartItem(_ref11) {
3088
- var product = _ref11.product,
3089
- date = _ref11.date,
3090
- account = _ref11.account;
3091
- var _ref12 = product || {},
3092
- bundle = _ref12.bundle,
3093
- options = _ref12.options,
3094
- origin = _ref12.origin,
3095
- product_variant_id = _ref12.product_variant_id,
3096
- _ref12$quantity = _ref12.quantity,
3097
- quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
3098
-
3099
- // 处理商品数据,类似 addProductToCart 中的逻辑
3100
- var productData = _objectSpread(_objectSpread({}, origin), {}, {
3101
- product_variant_id: product_variant_id
3102
- });
3103
-
3104
- // 处理组合商品
3105
- var processedProduct = handleVariantProduct(productData);
3106
-
3107
- // 如果没有传入账户,获取当前活跃账户
3108
- if (!account) {
3109
- var activeAccount = this.getActiveAccount();
3110
- if (activeAccount) {
3111
- account = activeAccount;
3112
- }
3113
- }
3114
-
3115
- // 创建基础的 CartItem
3116
- var cartItem = {
3117
- _id: getUniqueId('temp_'),
3118
- _origin: createCartItemOrigin(),
3119
- _productOrigin: processedProduct,
3120
- _productInit: product
3121
- };
3122
-
3123
- // 使用格式化函数填充 CartItem 数据
3124
- formatProductToCartItem({
3125
- cartItem: cartItem,
3126
- product: processedProduct,
3127
- bundle: bundle,
3128
- options: options,
3129
- product_variant_id: product_variant_id,
3130
- quantity: quantity
3131
- });
3132
-
3133
- // 如果有日期信息,格式化日期到购物车
3134
- if (date) {
3135
- formatDateToCartItem({
3136
- cartItem: cartItem,
3137
- date: date
3138
- });
3139
- }
3140
-
3141
- // 如果有账户信息,格式化账户到购物车
3142
- if (account) {
3143
- formatAccountToCartItem({
3144
- cartItem: cartItem,
3145
- account: account
3146
- });
3147
- }
3148
- return cartItem;
3149
- }
3150
- }, {
3151
- key: "checkMaxDurationCapacityForDetailNums",
3152
- value: function checkMaxDurationCapacityForDetailNums(_ref13) {
3153
- var _this16 = this;
3154
- var product = _ref13.product,
3155
- date = _ref13.date,
3156
- account = _ref13.account;
3157
- var cartItems = cloneDeep(this.store.cart.getItems());
3158
-
3159
- // 将 ProductData 转换为 CartItem 但不真正添加到购物车
3160
- var currentCartItem = this.convertProductToCartItem({
3161
- product: product,
3162
- date: date,
3163
- account: account
3164
- });
3165
- cartItems.push(currentCartItem);
3166
- if (cartItems.length === 0) return {
3167
- success: true,
3168
- minAvailableCount: 0
3169
- };
3170
-
3171
- // 将购物车商品分为有时间的和没有时间的
3172
- var itemsWithTime = [];
3173
- var itemsWithoutTime = [];
3174
- // 记录每种资源类型的可用数量
3175
- var availableCountsByResourceType = [];
3176
- cartItems.forEach(function (cartItem) {
3177
- if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
3178
- itemsWithTime.push(cartItem);
3179
- } else {
3180
- itemsWithoutTime.push(cartItem);
3181
- }
3182
- });
3183
-
3184
- // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
3185
- var processedItemsWithoutTime = [];
3186
- if (itemsWithoutTime.length > 0) {
3187
- // 按资源类型分组处理没有时间的商品
3188
- var itemsByResourceType = {};
3189
- itemsWithoutTime.forEach(function (cartItem) {
3190
- var _cartItem$_productOri13;
3191
- if (!cartItem._productOrigin) return;
3192
- var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
3193
- resourceTypes.forEach(function (resourceType) {
3194
- if (resourceType.status === 1) {
3195
- var _resourceType$id2;
3196
- var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
3197
- if (!itemsByResourceType[resourceCode]) {
3198
- itemsByResourceType[resourceCode] = [];
3199
- }
3200
- // 避免重复添加同一个商品
3201
- if (!itemsByResourceType[resourceCode].find(function (item) {
3202
- return item._id === cartItem._id;
3203
- })) {
3204
- itemsByResourceType[resourceCode].push(cartItem);
3205
- }
3206
- }
3207
- });
3208
- });
3209
-
3210
- // 为每种资源类型检查容量
3211
- var dateRange = this.store.date.getDateRange();
3212
- if (!dateRange || dateRange.length === 0) return {
3213
- success: false,
3214
- minAvailableCount: 0
3215
- };
3216
- var resourcesDates = this.store.date.getDateList();
3217
- var targetResourceDate = resourcesDates.find(function (n) {
3218
- return n.date === dateRange[0].date;
3219
- });
3220
- if (!targetResourceDate) return {
3221
- success: false,
3222
- minAvailableCount: 0
3223
- };
3224
- var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3225
-
3226
- // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
3227
- var resourceCodeToFormIdMap = {};
3228
-
3229
- // 遍历购物车中的商品,收集所有资源类型配置
3230
- Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
3231
- var _cartItem$_productOri14;
3232
- if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
3233
- cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
3234
- // 只处理启用的资源类型 (status === 1)
3235
- if (resourceConfig.status === 1 && resourceConfig.code) {
3236
- var _resourceConfig$id2, _resourceConfig$resou2;
3237
- var formId = ((_resourceConfig$id2 = resourceConfig.id) === null || _resourceConfig$id2 === void 0 ? void 0 : _resourceConfig$id2.toString()) || ((_resourceConfig$resou2 = resourceConfig.resource_type_id) === null || _resourceConfig$resou2 === void 0 ? void 0 : _resourceConfig$resou2.toString());
3238
- if (formId) {
3239
- resourceCodeToFormIdMap[resourceConfig.code] = formId;
3240
- }
3241
- }
3242
- });
3243
- }
3244
- });
3245
- var hasCapacityIssue = false;
3246
- var resourceCapacityInfo = [];
3247
-
3248
- // 用于跟踪已处理的商品,避免重复添加
3249
- var processedCartItemIds = new Set();
3250
-
3251
- // 先检查所有资源类型,收集可用数量信息
3252
- var _loop5 = function _loop5() {
3253
- var _resourceTypeConfig2;
3254
- var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
3255
- resourceCode = _Object$entries3$_i[0],
3256
- items = _Object$entries3$_i[1];
3257
- // 获取该资源类型对应的 form_id
3258
- var targetFormId = resourceCodeToFormIdMap[resourceCode];
3259
- if (!targetFormId) {
3260
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
3261
- return {
3262
- v: {
3263
- success: false,
3264
- minAvailableCount: 0
3265
- }
3266
- };
3267
- }
3268
-
3269
- // 获取该资源类型的所有资源
3270
- var resourcesOfThisType = [];
3271
- items.forEach(function (cartItem) {
3272
- var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3273
- productResourceIds.forEach(function (resourceId) {
3274
- var _resource$form_id2;
3275
- var resource = resourcesMap[resourceId];
3276
- if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
3277
- // 避免重复添加同一个资源
3278
- if (!resourcesOfThisType.find(function (r) {
3279
- return r.id === resource.id;
3280
- })) {
3281
- resourcesOfThisType.push(resource);
3282
- }
3283
- }
3284
- });
3285
- });
3286
- if (resourcesOfThisType.length === 0) {
3287
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
3288
- return {
3289
- v: {
3290
- success: false,
3291
- minAvailableCount: 0
3292
- }
3293
- };
3294
- }
3295
-
3296
- // 检查资源类型(单个预约 vs 多个预约)
3297
- // 从商品配置中获取资源类型信息
3298
- var resourceTypeConfig = null;
3299
- var _iterator4 = _createForOfIteratorHelper(items),
3300
- _step4;
3301
- try {
3302
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
3303
- var _cartItem$_productOri15;
3304
- var cartItem = _step4.value;
3305
- if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
3306
- resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
3307
- return r.code === resourceCode && r.status === 1;
3308
- });
3309
- if (resourceTypeConfig) break;
3310
- }
3311
- }
3312
- } catch (err) {
3313
- _iterator4.e(err);
3314
- } finally {
3315
- _iterator4.f();
3316
- }
3317
- var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
3318
- var totalAvailable;
3319
- var requiredAmount;
3320
- var availableAmount;
3321
- if (isMultipleBooking) {
3322
- // 多个预约:计算容量
3323
- totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
3324
- return sum + (resource.capacity || 0);
3325
- }, 0);
3326
- requiredAmount = items.reduce(function (sum, cartItem) {
3327
- var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3328
- currentCapacity = _getCapacityInfoByCar8.currentCapacity;
3329
- return sum + currentCapacity;
3330
- }, 0);
3331
- availableAmount = Math.max(0, totalAvailable - requiredAmount);
3332
- } else {
3333
- // 单个预约:计算资源个数
3334
- totalAvailable = resourcesOfThisType.length;
3335
- requiredAmount = items.reduce(function (sum, cartItem) {
3336
- return sum + (cartItem.num || 1);
3337
- }, 0);
3338
- availableAmount = Math.max(0, totalAvailable - requiredAmount);
3339
- }
3340
-
3341
- // 记录资源容量信息
3342
- resourceCapacityInfo.push({
3343
- code: resourceCode,
3344
- available: availableAmount,
3345
- total: totalAvailable,
3346
- required: requiredAmount,
3347
- isMultiple: isMultipleBooking
3348
- });
3349
- availableCountsByResourceType.push(availableAmount);
3350
-
3351
- // 检查是否有容量问题
3352
- if (requiredAmount > totalAvailable) {
3353
- hasCapacityIssue = true;
3354
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
3355
- }
3356
-
3357
- // 为通过检测的商品分配一个公共可用时间段
3358
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
3359
- return {
3360
- id: r.id,
3361
- times: r.times.map(function (t) {
3362
- return "".concat(t.start_at, " - ").concat(t.end_at);
3363
- })
3364
- };
3365
- }));
3366
-
3367
- // 找到所有资源都可用的时间段
3368
- var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
3369
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
3370
- if (commonTimeSlots.length === 0) {
3371
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
3372
- return {
3373
- v: {
3374
- success: false,
3375
- minAvailableCount: 0
3376
- }
3377
- };
3378
- }
3379
-
3380
- // 使用第一个公共可用时间段,但只处理未处理过的商品
3381
- var firstCommonSlot = commonTimeSlots[0];
3382
- console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
3383
- items.forEach(function (cartItem) {
3384
- // 只处理未处理过的商品,避免重复添加
3385
- if (!processedCartItemIds.has(cartItem._id)) {
3386
- processedCartItemIds.add(cartItem._id);
3387
- var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
3388
- start_date: dateRange[0].date,
3389
- start_time: firstCommonSlot.startTime,
3390
- end_time: firstCommonSlot.endTime,
3391
- end_date: dateRange[0].date
3392
- });
3393
- processedItemsWithoutTime.push(processedItem);
3394
- }
3395
- });
3396
- },
3397
- _ret4;
3398
- for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
3399
- _ret4 = _loop5();
3400
- if (_ret4) return _ret4.v;
3401
- }
3402
-
3403
- // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
3404
- if (hasCapacityIssue) {
3405
- // 找出超出容量的资源类型中,总容量最少的那个
3406
- var overCapacityResources = resourceCapacityInfo.filter(function (info) {
3407
- return info.required > info.total;
3408
- });
3409
- if (overCapacityResources.length > 0) {
3410
- var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
3411
- return info.total;
3412
- })));
3413
- return {
3414
- success: false,
3415
- minAvailableCount: _minTotalCapacity2
3416
- };
3417
- }
3418
- // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
3419
- var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
3420
- return info.total;
3421
- })));
3422
- return {
3423
- success: false,
3424
- minAvailableCount: minTotalCapacity
3425
- };
3426
- }
3427
- }
3428
-
3429
- // 合并所有商品(有时间的 + 处理后的没有时间的)
3430
- var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
3431
-
3432
- // 按时间段分组检查
3433
- var cartItemsByTimeSlot = {};
3434
- allProcessedItems.forEach(function (cartItem) {
3435
- if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
3436
- var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
3437
- if (!cartItemsByTimeSlot[timeSlotKey]) {
3438
- cartItemsByTimeSlot[timeSlotKey] = [];
3439
- }
3440
- cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3441
- });
3442
- // 检查每个时间段是否有足够的资源容量
3443
- var _loop6 = function _loop6() {
3444
- var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
3445
- timeSlotKey = _Object$entries4$_i[0],
3446
- itemsInTimeSlot = _Object$entries4$_i[1];
3447
- var _timeSlotKey$split3 = timeSlotKey.split('_'),
3448
- _timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
3449
- startDate = _timeSlotKey$split4[0],
3450
- startTime = _timeSlotKey$split4[1],
3451
- endDate = _timeSlotKey$split4[2],
3452
- endTime = _timeSlotKey$split4[3];
3453
- var timeSlotStart = "".concat(startDate, " ").concat(startTime);
3454
- var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
3455
-
3456
- // 获取这个时间段所有商品涉及的资源
3457
- var allResourcesForTimeSlot = [];
3458
- var resourcesIdSet = new Set();
3459
-
3460
- // 获取资源数据
3461
- // const dateRange = this.store.date.getDateRange();
3462
- var resourcesDates = _this16.store.date.getDateList();
3463
- var targetResourceDate = resourcesDates.find(function (n) {
3464
- return n.date === startDate;
3465
- });
3466
- if (!targetResourceDate) return 0; // continue
3467
- var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3468
- itemsInTimeSlot.forEach(function (cartItem) {
3469
- if (!cartItem._productOrigin) return;
3470
-
3471
- // 获取商品的资源配置
3472
- var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3473
- productResourceIds.forEach(function (resourceId) {
3474
- if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3475
- resourcesIdSet.add(resourceId);
3476
- allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3477
- }
3478
- });
3479
- });
3480
-
3481
- // 按资源类型分组检查容量
3482
- var _checkTimeSlotCapacit2 = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3483
- success = _checkTimeSlotCapacit2.success,
3484
- required = _checkTimeSlotCapacit2.required,
3485
- available = _checkTimeSlotCapacit2.available;
3486
- if (!success) {
3487
- // 如果有可用数量记录,返回最小值;否则返回 0
3488
- // const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
3489
- return {
3490
- v: {
3491
- success: false,
3492
- minAvailableCount: available
3493
- }
3494
- };
3495
- }
3496
- },
3497
- _ret5;
3498
- for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
3499
- _ret5 = _loop6();
3500
- if (_ret5 === 0) continue;
3501
- if (_ret5) return _ret5.v;
3502
- }
3503
-
3504
- // 全部通过检测,返回成功和最小可用数量
3505
- var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3506
- return {
3507
- success: true,
3508
- minAvailableCount: minAvailableCount
3509
- };
3510
- }
3511
3066
  }, {
3512
3067
  key: "setOtherData",
3513
3068
  value: function setOtherData(key, value) {
@@ -3579,7 +3134,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3579
3134
  }, {
3580
3135
  key: "getResourcesByCartItemAndCode",
3581
3136
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
3582
- var _cartItem$_productOri16;
3137
+ var _cartItem$_productOri13;
3583
3138
  var dateRange = this.store.date.getDateRange();
3584
3139
  var resources = [];
3585
3140
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -3602,16 +3157,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3602
3157
  });
3603
3158
  if (!cartItem) return [];
3604
3159
  var selectedResources = [];
3605
- var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
3606
- currentCapacity = _getCapacityInfoByCar9.currentCapacity,
3607
- formatCapacity = _getCapacityInfoByCar9.formatCapacity;
3160
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3161
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3162
+ formatCapacity = _getCapacityInfoByCar8.formatCapacity;
3608
3163
  cartItem._origin.metadata.capacity = formatCapacity;
3609
3164
  if (cartItem.holder_id) {
3610
3165
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
3611
3166
  } else {
3612
3167
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
3613
3168
  }
3614
- var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri16 = cartItem._productOrigin) === null || _cartItem$_productOri16 === void 0 || (_cartItem$_productOri16 = _cartItem$_productOri16.product_resource) === null || _cartItem$_productOri16 === void 0 ? void 0 : _cartItem$_productOri16.resources) || [], selectedResources, currentCapacity);
3169
+ var productResources = getResourcesByProduct(resourcesMap, ((_cartItem$_productOri13 = cartItem._productOrigin) === null || _cartItem$_productOri13 === void 0 || (_cartItem$_productOri13 = _cartItem$_productOri13.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [], selectedResources, currentCapacity);
3615
3170
  var targetResource = productResources.find(function (resource) {
3616
3171
  return resource.code === resourceCode;
3617
3172
  });
@@ -3634,7 +3189,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3634
3189
  });
3635
3190
  if (mTimes.length === 0) return false;
3636
3191
  var canUseArr = mTimes.map(function (item) {
3637
- var _cartItem$_productOri17;
3192
+ var _cartItem$_productOri14;
3638
3193
  var res = getIsUsableByTimeItem({
3639
3194
  timeSlice: {
3640
3195
  start_time: startTime.format('HH:mm'),
@@ -3646,7 +3201,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3646
3201
  resource: m,
3647
3202
  currentCount: currentCapacity || 0,
3648
3203
  resourcesUseableMap: resourcesUseableMap,
3649
- cut_off_time: (_cartItem$_productOri17 = cartItem._productOrigin) === null || _cartItem$_productOri17 === void 0 ? void 0 : _cartItem$_productOri17.cut_off_time
3204
+ cut_off_time: (_cartItem$_productOri14 = cartItem._productOrigin) === null || _cartItem$_productOri14 === void 0 ? void 0 : _cartItem$_productOri14.cut_off_time
3650
3205
  });
3651
3206
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3652
3207
  resourcesUseableMap[m.id] = res.usable;
@@ -3660,12 +3215,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3660
3215
  });
3661
3216
  } else {
3662
3217
  targetResource.renderList = targetResource.renderList.filter(function (n) {
3663
- var _cartItem$_productOri18;
3218
+ var _cartItem$_productOri15;
3664
3219
  var recordCount = n.capacity || 0;
3665
3220
  if (n.onlyComputed) return false;
3666
3221
  var timeSlots = getTimeSlicesByResource({
3667
3222
  resource: n,
3668
- duration: ((_cartItem$_productOri18 = cartItem._productOrigin) === null || _cartItem$_productOri18 === void 0 || (_cartItem$_productOri18 = _cartItem$_productOri18.duration) === null || _cartItem$_productOri18 === void 0 ? void 0 : _cartItem$_productOri18.value) || 10,
3223
+ duration: ((_cartItem$_productOri15 = cartItem._productOrigin) === null || _cartItem$_productOri15 === void 0 || (_cartItem$_productOri15 = _cartItem$_productOri15.duration) === null || _cartItem$_productOri15 === void 0 ? void 0 : _cartItem$_productOri15.value) || 10,
3669
3224
  split: 10,
3670
3225
  currentDate: dateRange[0].date
3671
3226
  });
@@ -3683,12 +3238,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3683
3238
  }, {
3684
3239
  key: "getTimeslotsScheduleByDateRange",
3685
3240
  value: (function () {
3686
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
3687
- var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i5, _dates, date;
3241
+ var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref11) {
3242
+ var startDate, endDate, scheduleIds, resources, dates, currentDate, end, results, _i3, _dates, date;
3688
3243
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3689
3244
  while (1) switch (_context26.prev = _context26.next) {
3690
3245
  case 0:
3691
- startDate = _ref14.startDate, endDate = _ref14.endDate, scheduleIds = _ref14.scheduleIds, resources = _ref14.resources;
3246
+ startDate = _ref11.startDate, endDate = _ref11.endDate, scheduleIds = _ref11.scheduleIds, resources = _ref11.resources;
3692
3247
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3693
3248
  startDate: startDate,
3694
3249
  endDate: endDate,
@@ -3705,8 +3260,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3705
3260
  }
3706
3261
  // 如果不支持 Web Worker,使用同步方式处理
3707
3262
  results = {};
3708
- for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
3709
- date = _dates[_i5];
3263
+ for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3264
+ date = _dates[_i3];
3710
3265
  results[date] = this.getTimeslotBySchedule({
3711
3266
  date: date,
3712
3267
  scheduleIds: scheduleIds,
@@ -3747,7 +3302,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3747
3302
  openResources,
3748
3303
  allProductResources,
3749
3304
  targetSchedules,
3750
- _loop7,
3305
+ _loop5,
3751
3306
  _args28 = arguments;
3752
3307
  return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3753
3308
  while (1) switch (_context28.prev = _context28.next) {
@@ -3824,9 +3379,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3824
3379
  }
3825
3380
  });
3826
3381
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3827
- _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3382
+ _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
3828
3383
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3829
- return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3384
+ return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3830
3385
  while (1) switch (_context27.prev = _context27.next) {
3831
3386
  case 0:
3832
3387
  currentDateStr = currentDate.format('YYYY-MM-DD');
@@ -3929,14 +3484,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3929
3484
  case "end":
3930
3485
  return _context27.stop();
3931
3486
  }
3932
- }, _loop7);
3487
+ }, _loop5);
3933
3488
  });
3934
3489
  case 28:
3935
3490
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3936
3491
  _context28.next = 34;
3937
3492
  break;
3938
3493
  }
3939
- return _context28.delegateYield(_loop7(), "t0", 30);
3494
+ return _context28.delegateYield(_loop5(), "t0", 30);
3940
3495
  case 30:
3941
3496
  if (!_context28.t0) {
3942
3497
  _context28.next = 32;
@@ -15,9 +15,8 @@ export declare const formatDefaultCapacitys: ({ capacity, product_bundle, }: any
15
15
  * @return {*}
16
16
  * @Author: zhiwei.Wang
17
17
  */
18
- export declare const getSumCapacity: ({ capacity, num }: {
18
+ export declare const getSumCapacity: ({ capacity }: {
19
19
  capacity: CapacityItem[];
20
- num: number;
21
20
  }) => number;
22
21
  /**
23
22
  * 给定购物车数据,返回对应的 capacity 信息和套餐 capacity
@@ -68,8 +67,4 @@ export declare function getResourcesIdsByProduct(product: any): number[];
68
67
  /**
69
68
  * 检查特定时间段的容量是否足够
70
69
  */
71
- export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): {
72
- success: boolean;
73
- required: number;
74
- available: number;
75
- };
70
+ export declare function checkTimeSlotCapacity(timeSlotStart: string, timeSlotEnd: string, cartItems: CartItem[], allResources: ResourceItem[]): boolean;