@pisell/pisellos 2.1.36 → 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 (133) 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/types.d.ts +19 -0
  17. package/dist/modules/ProductList/index.js +5 -14
  18. package/dist/modules/Resource/index.js +1 -1
  19. package/dist/modules/Rules/index.js +2 -3
  20. package/dist/modules/Schedule/types.d.ts +2 -0
  21. package/dist/plugins/request.d.ts +1 -0
  22. package/dist/server/index.d.ts +152 -0
  23. package/dist/server/index.js +946 -0
  24. package/dist/server/modules/index.d.ts +16 -0
  25. package/dist/server/modules/index.js +21 -0
  26. package/dist/server/modules/menu/index.d.ts +63 -0
  27. package/dist/server/modules/menu/index.js +476 -0
  28. package/dist/server/modules/menu/types.d.ts +68 -0
  29. package/dist/server/modules/menu/types.js +16 -0
  30. package/dist/server/modules/products/index.d.ts +141 -0
  31. package/dist/server/modules/products/index.js +768 -0
  32. package/dist/server/modules/products/types.d.ts +94 -0
  33. package/dist/server/modules/products/types.js +43 -0
  34. package/dist/server/modules/quotation/index.d.ts +47 -0
  35. package/dist/server/modules/quotation/index.js +367 -0
  36. package/dist/server/modules/quotation/types.d.ts +50 -0
  37. package/dist/server/modules/quotation/types.js +20 -0
  38. package/dist/server/modules/schedule/index.d.ts +62 -0
  39. package/dist/server/modules/schedule/index.js +431 -0
  40. package/dist/server/modules/schedule/types.d.ts +1 -0
  41. package/dist/server/modules/schedule/types.js +2 -0
  42. package/dist/server/modules/schedule/utils.d.ts +32 -0
  43. package/dist/server/modules/schedule/utils.js +747 -0
  44. package/dist/server/types.d.ts +64 -0
  45. package/dist/server/types.js +1 -0
  46. package/dist/server/utils/index.d.ts +5 -0
  47. package/dist/server/utils/index.js +6 -0
  48. package/dist/server/utils/product.d.ts +18 -0
  49. package/dist/server/utils/product.js +339 -0
  50. package/dist/server/utils/schedule.d.ts +14 -0
  51. package/dist/server/utils/schedule.js +108 -0
  52. package/dist/server/utils/time.d.ts +18 -0
  53. package/dist/server/utils/time.js +53 -0
  54. package/dist/solution/BookingByStep/index.d.ts +0 -16
  55. package/dist/solution/BookingByStep/index.js +57 -508
  56. package/dist/solution/BookingByStep/utils/capacity.d.ts +2 -7
  57. package/dist/solution/BookingByStep/utils/capacity.js +8 -24
  58. package/dist/solution/BookingTicket/index.d.ts +12 -0
  59. package/dist/solution/BookingTicket/index.js +122 -79
  60. package/dist/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  61. package/dist/solution/BookingTicket/utils/scan/index.js +25 -16
  62. package/dist/solution/BuyTickets/index.js +7 -8
  63. package/dist/solution/Checkout/index.d.ts +1 -46
  64. package/dist/solution/Checkout/index.js +530 -850
  65. package/dist/solution/ShopDiscount/index.js +9 -10
  66. package/dist/types/index.d.ts +27 -0
  67. package/lib/core/index.d.ts +8 -1
  68. package/lib/core/index.js +48 -1
  69. package/lib/effects/index.d.ts +1 -0
  70. package/lib/effects/index.js +13 -0
  71. package/lib/modules/Account/index.js +2 -3
  72. package/lib/modules/BaseModule.d.ts +3 -0
  73. package/lib/modules/BaseModule.js +9 -0
  74. package/lib/modules/Customer/index.js +9 -10
  75. package/lib/modules/Customer/types.d.ts +2 -2
  76. package/lib/modules/Customer/types.js +2 -2
  77. package/lib/modules/Discount/index.js +1 -1
  78. package/lib/modules/Guests/index.js +9 -9
  79. package/lib/modules/Order/index.js +1 -1
  80. package/lib/modules/Payment/index.js +56 -43
  81. package/lib/modules/Payment/walletpass.js +3 -1
  82. package/lib/modules/Product/types.d.ts +19 -0
  83. package/lib/modules/ProductList/index.js +4 -13
  84. package/lib/modules/Resource/index.js +1 -1
  85. package/lib/modules/Rules/index.js +2 -3
  86. package/lib/modules/Schedule/types.d.ts +2 -0
  87. package/lib/plugins/request.d.ts +1 -0
  88. package/lib/server/index.d.ts +152 -0
  89. package/lib/server/index.js +555 -0
  90. package/lib/server/modules/index.d.ts +16 -0
  91. package/lib/server/modules/index.js +47 -0
  92. package/lib/server/modules/menu/index.d.ts +63 -0
  93. package/lib/server/modules/menu/index.js +234 -0
  94. package/lib/server/modules/menu/types.d.ts +68 -0
  95. package/lib/server/modules/menu/types.js +33 -0
  96. package/lib/server/modules/products/index.d.ts +141 -0
  97. package/lib/server/modules/products/index.js +434 -0
  98. package/lib/server/modules/products/types.d.ts +94 -0
  99. package/lib/server/modules/products/types.js +35 -0
  100. package/lib/server/modules/quotation/index.d.ts +47 -0
  101. package/lib/server/modules/quotation/index.js +177 -0
  102. package/lib/server/modules/quotation/types.d.ts +50 -0
  103. package/lib/server/modules/quotation/types.js +33 -0
  104. package/lib/server/modules/schedule/index.d.ts +62 -0
  105. package/lib/server/modules/schedule/index.js +231 -0
  106. package/lib/server/modules/schedule/types.d.ts +1 -0
  107. package/lib/server/modules/schedule/types.js +23 -0
  108. package/lib/server/modules/schedule/utils.d.ts +32 -0
  109. package/lib/server/modules/schedule/utils.js +451 -0
  110. package/lib/server/types.d.ts +64 -0
  111. package/lib/server/types.js +17 -0
  112. package/lib/server/utils/index.d.ts +5 -0
  113. package/lib/server/utils/index.js +25 -0
  114. package/lib/server/utils/product.d.ts +18 -0
  115. package/lib/server/utils/product.js +262 -0
  116. package/lib/server/utils/schedule.d.ts +14 -0
  117. package/lib/server/utils/schedule.js +88 -0
  118. package/lib/server/utils/time.d.ts +18 -0
  119. package/lib/server/utils/time.js +70 -0
  120. package/lib/solution/BookingByStep/index.d.ts +0 -16
  121. package/lib/solution/BookingByStep/index.js +44 -316
  122. package/lib/solution/BookingByStep/utils/capacity.d.ts +2 -7
  123. package/lib/solution/BookingByStep/utils/capacity.js +8 -21
  124. package/lib/solution/BookingTicket/index.d.ts +12 -0
  125. package/lib/solution/BookingTicket/index.js +25 -6
  126. package/lib/solution/BookingTicket/utils/scan/index.d.ts +4 -0
  127. package/lib/solution/BookingTicket/utils/scan/index.js +7 -1
  128. package/lib/solution/BuyTickets/index.js +7 -8
  129. package/lib/solution/Checkout/index.d.ts +1 -46
  130. package/lib/solution/Checkout/index.js +92 -289
  131. package/lib/solution/ShopDiscount/index.js +10 -11
  132. package/lib/types/index.d.ts +27 -0
  133. 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
  };
@@ -2686,41 +2676,35 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2686
2676
 
2687
2677
  // 与其他资源的时间段求交集
2688
2678
  var _loop2 = function _loop2() {
2689
- var currentResourceSlots = allTimeSlots[i];
2690
- var intersections = [];
2691
-
2692
- // 计算当前公共时间段与下一个资源时间段的交集
2693
- commonSlots.forEach(function (commonSlot) {
2694
- currentResourceSlots.forEach(function (currentSlot) {
2695
- var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
2696
- var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
2697
-
2698
- // 如果有重叠时间且重叠时间大于0
2699
- if (overlapStart.isBefore(overlapEnd)) {
2700
- intersections.push({
2701
- start: overlapStart,
2702
- end: overlapEnd
2703
- });
2704
- }
2705
- });
2679
+ var currentResourceSlots = allTimeSlots[i];
2680
+ var intersections = [];
2681
+
2682
+ // 计算当前公共时间段与下一个资源时间段的交集
2683
+ commonSlots.forEach(function (commonSlot) {
2684
+ currentResourceSlots.forEach(function (currentSlot) {
2685
+ var overlapStart = commonSlot.start.isAfter(currentSlot.start) ? commonSlot.start : currentSlot.start;
2686
+ var overlapEnd = commonSlot.end.isBefore(currentSlot.end) ? commonSlot.end : currentSlot.end;
2687
+
2688
+ // 如果有重叠时间且重叠时间大于0
2689
+ if (overlapStart.isBefore(overlapEnd)) {
2690
+ intersections.push({
2691
+ start: overlapStart,
2692
+ end: overlapEnd
2693
+ });
2694
+ }
2706
2695
  });
2707
- commonSlots = intersections;
2708
- console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
2709
- return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2710
- }));
2711
-
2712
- // 如果没有公共时间段,直接返回
2713
- if (commonSlots.length === 0) {
2714
- console.log('没有找到公共时间段');
2715
- return {
2716
- v: []
2717
- };
2718
- }
2719
- },
2720
- _ret2;
2696
+ });
2697
+ if (intersections.length === 0) {
2698
+ console.log("\u8D44\u6E90".concat(i, "\u4E0E\u5F53\u524D\u516C\u5171\u65F6\u95F4\u6BB5\u65E0\u4EA4\u96C6\uFF0C\u8DF3\u8FC7\u8BE5\u8D44\u6E90"));
2699
+ return 1; // continue
2700
+ }
2701
+ commonSlots = intersections;
2702
+ console.log("\u4E0E\u8D44\u6E90".concat(i, "\u6C42\u4EA4\u96C6\u540E\u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonSlots.map(function (slot) {
2703
+ return "".concat(slot.start.format('HH:mm'), "-").concat(slot.end.format('HH:mm'));
2704
+ }));
2705
+ };
2721
2706
  for (var i = 1; i < allTimeSlots.length; i++) {
2722
- _ret2 = _loop2();
2723
- if (_ret2) return _ret2.v;
2707
+ if (_loop2()) continue;
2724
2708
  }
2725
2709
 
2726
2710
  // 格式化返回结果
@@ -2969,10 +2953,10 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2969
2953
  }
2970
2954
  });
2971
2955
  },
2972
- _ret3;
2956
+ _ret2;
2973
2957
  for (var _i = 0, _Object$entries = Object.entries(itemsByResourceType); _i < _Object$entries.length; _i++) {
2974
- _ret3 = _loop3();
2975
- if (_ret3) return _ret3.v;
2958
+ _ret2 = _loop3();
2959
+ if (_ret2) return _ret2.v;
2976
2960
  }
2977
2961
 
2978
2962
  // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
@@ -3054,11 +3038,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3054
3038
  });
3055
3039
 
3056
3040
  // 按资源类型分组检查容量
3057
- var _checkTimeSlotCapacit = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3058
- success = _checkTimeSlotCapacit.success,
3059
- required = _checkTimeSlotCapacit.required,
3060
- available = _checkTimeSlotCapacit.available;
3061
- if (!success) {
3041
+ if (!checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot)) {
3062
3042
  // 如果有可用数量记录,返回最小值;否则返回 0
3063
3043
  var _minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3064
3044
  return {
@@ -3069,442 +3049,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3069
3049
  };
3070
3050
  }
3071
3051
  },
3072
- _ret4;
3052
+ _ret3;
3073
3053
  for (var _i2 = 0, _Object$entries2 = Object.entries(cartItemsByTimeSlot); _i2 < _Object$entries2.length; _i2++) {
3074
- _ret4 = _loop4();
3075
- if (_ret4 === 0) continue;
3076
- if (_ret4) return _ret4.v;
3077
- }
3078
-
3079
- // 全部通过检测,返回成功和最小可用数量
3080
- var minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min.apply(Math, availableCountsByResourceType) : 0;
3081
- return {
3082
- success: true,
3083
- minAvailableCount: minAvailableCount
3084
- };
3085
- }
3086
-
3087
- /**
3088
- * 将 ProductData 转换为 CartItem,但不添加到购物车
3089
- * 参考 addProductToCart 方法的实现
3090
- */
3091
- }, {
3092
- key: "convertProductToCartItem",
3093
- value: function convertProductToCartItem(_ref11) {
3094
- var product = _ref11.product,
3095
- date = _ref11.date,
3096
- account = _ref11.account;
3097
- var _ref12 = product || {},
3098
- bundle = _ref12.bundle,
3099
- options = _ref12.options,
3100
- origin = _ref12.origin,
3101
- product_variant_id = _ref12.product_variant_id,
3102
- _ref12$quantity = _ref12.quantity,
3103
- quantity = _ref12$quantity === void 0 ? 1 : _ref12$quantity;
3104
-
3105
- // 处理商品数据,类似 addProductToCart 中的逻辑
3106
- var productData = _objectSpread(_objectSpread({}, origin), {}, {
3107
- product_variant_id: product_variant_id
3108
- });
3109
-
3110
- // 处理组合商品
3111
- var processedProduct = handleVariantProduct(productData);
3112
-
3113
- // 如果没有传入账户,获取当前活跃账户
3114
- if (!account) {
3115
- var activeAccount = this.getActiveAccount();
3116
- if (activeAccount) {
3117
- account = activeAccount;
3118
- }
3119
- }
3120
-
3121
- // 创建基础的 CartItem
3122
- var cartItem = {
3123
- _id: getUniqueId('temp_'),
3124
- _origin: createCartItemOrigin(),
3125
- _productOrigin: processedProduct,
3126
- _productInit: product
3127
- };
3128
-
3129
- // 使用格式化函数填充 CartItem 数据
3130
- formatProductToCartItem({
3131
- cartItem: cartItem,
3132
- product: processedProduct,
3133
- bundle: bundle,
3134
- options: options,
3135
- product_variant_id: product_variant_id,
3136
- quantity: quantity
3137
- });
3138
-
3139
- // 如果有日期信息,格式化日期到购物车
3140
- if (date) {
3141
- formatDateToCartItem({
3142
- cartItem: cartItem,
3143
- date: date
3144
- });
3145
- }
3146
-
3147
- // 如果有账户信息,格式化账户到购物车
3148
- if (account) {
3149
- formatAccountToCartItem({
3150
- cartItem: cartItem,
3151
- account: account
3152
- });
3153
- }
3154
- return cartItem;
3155
- }
3156
- }, {
3157
- key: "checkMaxDurationCapacityForDetailNums",
3158
- value: function checkMaxDurationCapacityForDetailNums(_ref13) {
3159
- var _this16 = this;
3160
- var product = _ref13.product,
3161
- date = _ref13.date,
3162
- account = _ref13.account;
3163
- var cartItems = cloneDeep(this.store.cart.getItems());
3164
-
3165
- // 将 ProductData 转换为 CartItem 但不真正添加到购物车
3166
- var currentCartItem = this.convertProductToCartItem({
3167
- product: product,
3168
- date: date,
3169
- account: account
3170
- });
3171
- cartItems.push(currentCartItem);
3172
- if (cartItems.length === 0) return {
3173
- success: true,
3174
- minAvailableCount: 0
3175
- };
3176
-
3177
- // 将购物车商品分为有时间的和没有时间的
3178
- var itemsWithTime = [];
3179
- var itemsWithoutTime = [];
3180
- // 记录每种资源类型的可用数量
3181
- var availableCountsByResourceType = [];
3182
- cartItems.forEach(function (cartItem) {
3183
- if (cartItem.start_time && cartItem.end_time && cartItem.start_date) {
3184
- itemsWithTime.push(cartItem);
3185
- } else {
3186
- itemsWithoutTime.push(cartItem);
3187
- }
3188
- });
3189
-
3190
- // 处理没有时间的商品,为它们分配公共可用时间的第一个时间片
3191
- var processedItemsWithoutTime = [];
3192
- if (itemsWithoutTime.length > 0) {
3193
- // 按资源类型分组处理没有时间的商品
3194
- var itemsByResourceType = {};
3195
- itemsWithoutTime.forEach(function (cartItem) {
3196
- var _cartItem$_productOri13;
3197
- if (!cartItem._productOrigin) return;
3198
- var resourceTypes = ((_cartItem$_productOri13 = cartItem._productOrigin.product_resource) === null || _cartItem$_productOri13 === void 0 ? void 0 : _cartItem$_productOri13.resources) || [];
3199
- resourceTypes.forEach(function (resourceType) {
3200
- if (resourceType.status === 1) {
3201
- var _resourceType$id2;
3202
- var resourceCode = resourceType.code || ((_resourceType$id2 = resourceType.id) === null || _resourceType$id2 === void 0 ? void 0 : _resourceType$id2.toString());
3203
- if (!itemsByResourceType[resourceCode]) {
3204
- itemsByResourceType[resourceCode] = [];
3205
- }
3206
- // 避免重复添加同一个商品
3207
- if (!itemsByResourceType[resourceCode].find(function (item) {
3208
- return item._id === cartItem._id;
3209
- })) {
3210
- itemsByResourceType[resourceCode].push(cartItem);
3211
- }
3212
- }
3213
- });
3214
- });
3215
-
3216
- // 为每种资源类型检查容量
3217
- var dateRange = this.store.date.getDateRange();
3218
- if (!dateRange || dateRange.length === 0) return {
3219
- success: false,
3220
- minAvailableCount: 0
3221
- };
3222
- var resourcesDates = this.store.date.getDateList();
3223
- var targetResourceDate = resourcesDates.find(function (n) {
3224
- return n.date === dateRange[0].date;
3225
- });
3226
- if (!targetResourceDate) return {
3227
- success: false,
3228
- minAvailableCount: 0
3229
- };
3230
- var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3231
-
3232
- // 从购物车商品中获取资源类型配置,建立 resourceCode 到 form_id 的映射关系
3233
- var resourceCodeToFormIdMap = {};
3234
-
3235
- // 遍历购物车中的商品,收集所有资源类型配置
3236
- Object.values(itemsByResourceType).flat().forEach(function (cartItem) {
3237
- var _cartItem$_productOri14;
3238
- if ((_cartItem$_productOri14 = cartItem._productOrigin) !== null && _cartItem$_productOri14 !== void 0 && (_cartItem$_productOri14 = _cartItem$_productOri14.product_resource) !== null && _cartItem$_productOri14 !== void 0 && _cartItem$_productOri14.resources) {
3239
- cartItem._productOrigin.product_resource.resources.forEach(function (resourceConfig) {
3240
- // 只处理启用的资源类型 (status === 1)
3241
- if (resourceConfig.status === 1 && resourceConfig.code) {
3242
- var _resourceConfig$id2, _resourceConfig$resou2;
3243
- 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());
3244
- if (formId) {
3245
- resourceCodeToFormIdMap[resourceConfig.code] = formId;
3246
- }
3247
- }
3248
- });
3249
- }
3250
- });
3251
- var hasCapacityIssue = false;
3252
- var resourceCapacityInfo = [];
3253
-
3254
- // 用于跟踪已处理的商品,避免重复添加
3255
- var processedCartItemIds = new Set();
3256
-
3257
- // 先检查所有资源类型,收集可用数量信息
3258
- var _loop5 = function _loop5() {
3259
- var _resourceTypeConfig2;
3260
- var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
3261
- resourceCode = _Object$entries3$_i[0],
3262
- items = _Object$entries3$_i[1];
3263
- // 获取该资源类型对应的 form_id
3264
- var targetFormId = resourceCodeToFormIdMap[resourceCode];
3265
- if (!targetFormId) {
3266
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u627E\u4E0D\u5230\u5BF9\u5E94\u7684 form_id"));
3267
- return {
3268
- v: {
3269
- success: false,
3270
- minAvailableCount: 0
3271
- }
3272
- };
3273
- }
3274
-
3275
- // 获取该资源类型的所有资源
3276
- var resourcesOfThisType = [];
3277
- items.forEach(function (cartItem) {
3278
- var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3279
- productResourceIds.forEach(function (resourceId) {
3280
- var _resource$form_id2;
3281
- var resource = resourcesMap[resourceId];
3282
- if (resource && ((_resource$form_id2 = resource.form_id) === null || _resource$form_id2 === void 0 ? void 0 : _resource$form_id2.toString()) === targetFormId) {
3283
- // 避免重复添加同一个资源
3284
- if (!resourcesOfThisType.find(function (r) {
3285
- return r.id === resource.id;
3286
- })) {
3287
- resourcesOfThisType.push(resource);
3288
- }
3289
- }
3290
- });
3291
- });
3292
- if (resourcesOfThisType.length === 0) {
3293
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u627E\u5230\u53EF\u7528\u8D44\u6E90"));
3294
- return {
3295
- v: {
3296
- success: false,
3297
- minAvailableCount: 0
3298
- }
3299
- };
3300
- }
3301
-
3302
- // 检查资源类型(单个预约 vs 多个预约)
3303
- // 从商品配置中获取资源类型信息
3304
- var resourceTypeConfig = null;
3305
- var _iterator4 = _createForOfIteratorHelper(items),
3306
- _step4;
3307
- try {
3308
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
3309
- var _cartItem$_productOri15;
3310
- var cartItem = _step4.value;
3311
- if ((_cartItem$_productOri15 = cartItem._productOrigin) !== null && _cartItem$_productOri15 !== void 0 && (_cartItem$_productOri15 = _cartItem$_productOri15.product_resource) !== null && _cartItem$_productOri15 !== void 0 && _cartItem$_productOri15.resources) {
3312
- resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(function (r) {
3313
- return r.code === resourceCode && r.status === 1;
3314
- });
3315
- if (resourceTypeConfig) break;
3316
- }
3317
- }
3318
- } catch (err) {
3319
- _iterator4.e(err);
3320
- } finally {
3321
- _iterator4.f();
3322
- }
3323
- var isMultipleBooking = ((_resourceTypeConfig2 = resourceTypeConfig) === null || _resourceTypeConfig2 === void 0 ? void 0 : _resourceTypeConfig2.type) === 'multiple';
3324
- var totalAvailable;
3325
- var requiredAmount;
3326
- var availableAmount;
3327
- if (isMultipleBooking) {
3328
- // 多个预约:计算容量
3329
- totalAvailable = resourcesOfThisType.reduce(function (sum, resource) {
3330
- return sum + (resource.capacity || 0);
3331
- }, 0);
3332
- requiredAmount = items.reduce(function (sum, cartItem) {
3333
- var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3334
- currentCapacity = _getCapacityInfoByCar8.currentCapacity;
3335
- return sum + currentCapacity;
3336
- }, 0);
3337
- availableAmount = Math.max(0, totalAvailable - requiredAmount);
3338
- } else {
3339
- // 单个预约:计算资源个数
3340
- totalAvailable = resourcesOfThisType.length;
3341
- requiredAmount = items.reduce(function (sum, cartItem) {
3342
- return sum + (cartItem.num || 1);
3343
- }, 0);
3344
- availableAmount = Math.max(0, totalAvailable - requiredAmount);
3345
- }
3346
-
3347
- // 记录资源容量信息
3348
- resourceCapacityInfo.push({
3349
- code: resourceCode,
3350
- available: availableAmount,
3351
- total: totalAvailable,
3352
- required: requiredAmount,
3353
- isMultiple: isMultipleBooking
3354
- });
3355
- availableCountsByResourceType.push(availableAmount);
3356
-
3357
- // 检查是否有容量问题
3358
- if (requiredAmount > totalAvailable) {
3359
- hasCapacityIssue = true;
3360
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " ").concat(isMultipleBooking ? '容量' : '资源数量', "\u4E0D\u8DB3: \u9700\u8981 ").concat(requiredAmount, ", \u603B\u5171 ").concat(totalAvailable));
3361
- }
3362
-
3363
- // 为通过检测的商品分配一个公共可用时间段
3364
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u8D44\u6E90\u65F6\u95F4\u4FE1\u606F:"), resourcesOfThisType.map(function (r) {
3365
- return {
3366
- id: r.id,
3367
- times: r.times.map(function (t) {
3368
- return "".concat(t.start_at, " - ").concat(t.end_at);
3369
- })
3370
- };
3371
- }));
3372
-
3373
- // 找到所有资源都可用的时间段
3374
- var commonTimeSlots = _this16.findCommonAvailableTimeSlots(resourcesOfThisType);
3375
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u7684\u516C\u5171\u65F6\u95F4\u6BB5:"), commonTimeSlots);
3376
- if (commonTimeSlots.length === 0) {
3377
- console.log("\u8D44\u6E90\u7C7B\u578B ".concat(resourceCode, " \u6CA1\u6709\u516C\u5171\u53EF\u7528\u65F6\u95F4\u6BB5"));
3378
- return {
3379
- v: {
3380
- success: false,
3381
- minAvailableCount: 0
3382
- }
3383
- };
3384
- }
3385
-
3386
- // 使用第一个公共可用时间段,但只处理未处理过的商品
3387
- var firstCommonSlot = commonTimeSlots[0];
3388
- console.log("\u4F7F\u7528\u516C\u5171\u65F6\u95F4\u6BB5: ".concat(firstCommonSlot.startTime, " - ").concat(firstCommonSlot.endTime));
3389
- items.forEach(function (cartItem) {
3390
- // 只处理未处理过的商品,避免重复添加
3391
- if (!processedCartItemIds.has(cartItem._id)) {
3392
- processedCartItemIds.add(cartItem._id);
3393
- var processedItem = _objectSpread(_objectSpread({}, cartItem), {}, {
3394
- start_date: dateRange[0].date,
3395
- start_time: firstCommonSlot.startTime,
3396
- end_time: firstCommonSlot.endTime,
3397
- end_date: dateRange[0].date
3398
- });
3399
- processedItemsWithoutTime.push(processedItem);
3400
- }
3401
- });
3402
- },
3403
- _ret5;
3404
- for (var _i3 = 0, _Object$entries3 = Object.entries(itemsByResourceType); _i3 < _Object$entries3.length; _i3++) {
3405
- _ret5 = _loop5();
3406
- if (_ret5) return _ret5.v;
3407
- }
3408
-
3409
- // 如果有容量问题,找出限制最严格的资源类型,返回其总容量
3410
- if (hasCapacityIssue) {
3411
- // 找出超出容量的资源类型中,总容量最少的那个
3412
- var overCapacityResources = resourceCapacityInfo.filter(function (info) {
3413
- return info.required > info.total;
3414
- });
3415
- if (overCapacityResources.length > 0) {
3416
- var _minTotalCapacity2 = Math.min.apply(Math, _toConsumableArray(overCapacityResources.map(function (info) {
3417
- return info.total;
3418
- })));
3419
- return {
3420
- success: false,
3421
- minAvailableCount: _minTotalCapacity2
3422
- };
3423
- }
3424
- // 如果没有超出容量的(理论上不应该发生),返回总容量最少的
3425
- var minTotalCapacity = Math.min.apply(Math, _toConsumableArray(resourceCapacityInfo.map(function (info) {
3426
- return info.total;
3427
- })));
3428
- return {
3429
- success: false,
3430
- minAvailableCount: minTotalCapacity
3431
- };
3432
- }
3433
- }
3434
-
3435
- // 合并所有商品(有时间的 + 处理后的没有时间的)
3436
- var allProcessedItems = [].concat(itemsWithTime, processedItemsWithoutTime);
3437
-
3438
- // 按时间段分组检查
3439
- var cartItemsByTimeSlot = {};
3440
- allProcessedItems.forEach(function (cartItem) {
3441
- if (!cartItem.start_time || !cartItem.end_time || !cartItem.start_date) return;
3442
- var timeSlotKey = "".concat(cartItem.start_date, "_").concat(cartItem.start_time, "_").concat(cartItem.end_date || cartItem.start_date, "_").concat(cartItem.end_time);
3443
- if (!cartItemsByTimeSlot[timeSlotKey]) {
3444
- cartItemsByTimeSlot[timeSlotKey] = [];
3445
- }
3446
- cartItemsByTimeSlot[timeSlotKey].push(cartItem);
3447
- });
3448
- // 检查每个时间段是否有足够的资源容量
3449
- var _loop6 = function _loop6() {
3450
- var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
3451
- timeSlotKey = _Object$entries4$_i[0],
3452
- itemsInTimeSlot = _Object$entries4$_i[1];
3453
- var _timeSlotKey$split3 = timeSlotKey.split('_'),
3454
- _timeSlotKey$split4 = _slicedToArray(_timeSlotKey$split3, 4),
3455
- startDate = _timeSlotKey$split4[0],
3456
- startTime = _timeSlotKey$split4[1],
3457
- endDate = _timeSlotKey$split4[2],
3458
- endTime = _timeSlotKey$split4[3];
3459
- var timeSlotStart = "".concat(startDate, " ").concat(startTime);
3460
- var timeSlotEnd = "".concat(endDate, " ").concat(endTime);
3461
-
3462
- // 获取这个时间段所有商品涉及的资源
3463
- var allResourcesForTimeSlot = [];
3464
- var resourcesIdSet = new Set();
3465
-
3466
- // 获取资源数据
3467
- // const dateRange = this.store.date.getDateRange();
3468
- var resourcesDates = _this16.store.date.getDateList();
3469
- var targetResourceDate = resourcesDates.find(function (n) {
3470
- return n.date === startDate;
3471
- });
3472
- if (!targetResourceDate) return 0; // continue
3473
- var resourcesMap = getResourcesMap(targetResourceDate.resource || []);
3474
- itemsInTimeSlot.forEach(function (cartItem) {
3475
- if (!cartItem._productOrigin) return;
3476
-
3477
- // 获取商品的资源配置
3478
- var productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
3479
- productResourceIds.forEach(function (resourceId) {
3480
- if (resourcesMap[resourceId] && !resourcesIdSet.has(resourceId)) {
3481
- resourcesIdSet.add(resourceId);
3482
- allResourcesForTimeSlot.push(resourcesMap[resourceId]);
3483
- }
3484
- });
3485
- });
3486
-
3487
- // 按资源类型分组检查容量
3488
- var _checkTimeSlotCapacit2 = checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, itemsInTimeSlot, allResourcesForTimeSlot),
3489
- success = _checkTimeSlotCapacit2.success,
3490
- required = _checkTimeSlotCapacit2.required,
3491
- available = _checkTimeSlotCapacit2.available;
3492
- if (!success) {
3493
- // 如果有可用数量记录,返回最小值;否则返回 0
3494
- // const minAvailableCount = availableCountsByResourceType.length > 0 ? Math.min(...availableCountsByResourceType) : 0;
3495
- return {
3496
- v: {
3497
- success: false,
3498
- minAvailableCount: available
3499
- }
3500
- };
3501
- }
3502
- },
3503
- _ret6;
3504
- for (var _i4 = 0, _Object$entries4 = Object.entries(cartItemsByTimeSlot); _i4 < _Object$entries4.length; _i4++) {
3505
- _ret6 = _loop6();
3506
- if (_ret6 === 0) continue;
3507
- if (_ret6) return _ret6.v;
3054
+ _ret3 = _loop4();
3055
+ if (_ret3 === 0) continue;
3056
+ if (_ret3) return _ret3.v;
3508
3057
  }
3509
3058
 
3510
3059
  // 全部通过检测,返回成功和最小可用数量
@@ -3585,7 +3134,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3585
3134
  }, {
3586
3135
  key: "getResourcesByCartItemAndCode",
3587
3136
  value: function getResourcesByCartItemAndCode(cartItemId, resourceCode) {
3588
- var _cartItem$_productOri16;
3137
+ var _cartItem$_productOri13;
3589
3138
  var dateRange = this.store.date.getDateRange();
3590
3139
  var resources = [];
3591
3140
  if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
@@ -3608,16 +3157,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3608
3157
  });
3609
3158
  if (!cartItem) return [];
3610
3159
  var selectedResources = [];
3611
- var _getCapacityInfoByCar9 = getCapacityInfoByCartItem(cartItem),
3612
- currentCapacity = _getCapacityInfoByCar9.currentCapacity,
3613
- formatCapacity = _getCapacityInfoByCar9.formatCapacity;
3160
+ var _getCapacityInfoByCar8 = getCapacityInfoByCartItem(cartItem),
3161
+ currentCapacity = _getCapacityInfoByCar8.currentCapacity,
3162
+ formatCapacity = _getCapacityInfoByCar8.formatCapacity;
3614
3163
  cartItem._origin.metadata.capacity = formatCapacity;
3615
3164
  if (cartItem.holder_id) {
3616
3165
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
3617
3166
  } else {
3618
3167
  selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
3619
3168
  }
3620
- 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);
3621
3170
  var targetResource = productResources.find(function (resource) {
3622
3171
  return resource.code === resourceCode;
3623
3172
  });
@@ -3640,7 +3189,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3640
3189
  });
3641
3190
  if (mTimes.length === 0) return false;
3642
3191
  var canUseArr = mTimes.map(function (item) {
3643
- var _cartItem$_productOri17;
3192
+ var _cartItem$_productOri14;
3644
3193
  var res = getIsUsableByTimeItem({
3645
3194
  timeSlice: {
3646
3195
  start_time: startTime.format('HH:mm'),
@@ -3652,7 +3201,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3652
3201
  resource: m,
3653
3202
  currentCount: currentCapacity || 0,
3654
3203
  resourcesUseableMap: resourcesUseableMap,
3655
- 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
3656
3205
  });
3657
3206
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[m.id]) !== false && res.reason !== 'capacityOnly') {
3658
3207
  resourcesUseableMap[m.id] = res.usable;
@@ -3666,12 +3215,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3666
3215
  });
3667
3216
  } else {
3668
3217
  targetResource.renderList = targetResource.renderList.filter(function (n) {
3669
- var _cartItem$_productOri18;
3218
+ var _cartItem$_productOri15;
3670
3219
  var recordCount = n.capacity || 0;
3671
3220
  if (n.onlyComputed) return false;
3672
3221
  var timeSlots = getTimeSlicesByResource({
3673
3222
  resource: n,
3674
- 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,
3675
3224
  split: 10,
3676
3225
  currentDate: dateRange[0].date
3677
3226
  });
@@ -3689,12 +3238,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3689
3238
  }, {
3690
3239
  key: "getTimeslotsScheduleByDateRange",
3691
3240
  value: (function () {
3692
- var _getTimeslotsScheduleByDateRange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(_ref14) {
3693
- 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;
3694
3243
  return _regeneratorRuntime().wrap(function _callee26$(_context26) {
3695
3244
  while (1) switch (_context26.prev = _context26.next) {
3696
3245
  case 0:
3697
- 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;
3698
3247
  console.log('appoimentBooking-session-date-getTimeslotsScheduleByDateRange', {
3699
3248
  startDate: startDate,
3700
3249
  endDate: endDate,
@@ -3711,8 +3260,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3711
3260
  }
3712
3261
  // 如果不支持 Web Worker,使用同步方式处理
3713
3262
  results = {};
3714
- for (_i5 = 0, _dates = dates; _i5 < _dates.length; _i5++) {
3715
- date = _dates[_i5];
3263
+ for (_i3 = 0, _dates = dates; _i3 < _dates.length; _i3++) {
3264
+ date = _dates[_i3];
3716
3265
  results[date] = this.getTimeslotBySchedule({
3717
3266
  date: date,
3718
3267
  scheduleIds: scheduleIds,
@@ -3753,7 +3302,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3753
3302
  openResources,
3754
3303
  allProductResources,
3755
3304
  targetSchedules,
3756
- _loop7,
3305
+ _loop5,
3757
3306
  _args28 = arguments;
3758
3307
  return _regeneratorRuntime().wrap(function _callee27$(_context28) {
3759
3308
  while (1) switch (_context28.prev = _context28.next) {
@@ -3830,9 +3379,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3830
3379
  }
3831
3380
  });
3832
3381
  targetSchedules = this.store.schedule.getScheduleListByIds(tempProducts['schedule.ids']);
3833
- _loop7 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop7() {
3382
+ _loop5 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop5() {
3834
3383
  var currentDateStr, status, _checkSessionProductL, latestStartDate, earliestEndDate, scheduleByDate, minTimeMaxTime, scheduleTimeSlots, timesSlotCanUse;
3835
- return _regeneratorRuntime().wrap(function _loop7$(_context27) {
3384
+ return _regeneratorRuntime().wrap(function _loop5$(_context27) {
3836
3385
  while (1) switch (_context27.prev = _context27.next) {
3837
3386
  case 0:
3838
3387
  currentDateStr = currentDate.format('YYYY-MM-DD');
@@ -3935,14 +3484,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3935
3484
  case "end":
3936
3485
  return _context27.stop();
3937
3486
  }
3938
- }, _loop7);
3487
+ }, _loop5);
3939
3488
  });
3940
3489
  case 28:
3941
3490
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3942
3491
  _context28.next = 34;
3943
3492
  break;
3944
3493
  }
3945
- return _context28.delegateYield(_loop7(), "t0", 30);
3494
+ return _context28.delegateYield(_loop5(), "t0", 30);
3946
3495
  case 30:
3947
3496
  if (!_context28.t0) {
3948
3497
  _context28.next = 32;