@pisell/pisellos 0.0.272 → 0.0.274

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.
@@ -55,16 +55,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
55
55
  this.store = options.store;
56
56
  this.request = this.core.getPlugin('request');
57
57
  appPlugin = this.core.getPlugin('app');
58
- if (appPlugin) {
59
- _context.next = 6;
60
- break;
58
+ if (!appPlugin) {
59
+ console.warn('Order 模块需要 app 插件支持');
61
60
  }
62
- throw new Error('Order 模块需要 app 插件支持');
63
- case 6:
64
- app = appPlugin.getApp();
65
- this.logger = app.logger;
61
+ app = appPlugin === null || appPlugin === void 0 ? void 0 : appPlugin.getApp();
62
+ if (app) this.logger = app.logger;
66
63
  this.logInfo('OrderModule initialized successfully');
67
- case 9:
64
+ case 8:
68
65
  case "end":
69
66
  return _context.stop();
70
67
  }
@@ -319,7 +319,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
319
319
  checkMaxDurationCapacity(): boolean;
320
320
  setOtherData(key: string, value: any): void;
321
321
  getOtherData(key: string): any;
322
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
322
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
323
323
  /**
324
324
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
325
325
  *
@@ -2489,8 +2489,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2489
2489
  var _m$_productOrigin, _targetProductData$id;
2490
2490
  return ((_m$_productOrigin = m._productOrigin) === null || _m$_productOrigin === void 0 || (_m$_productOrigin = _m$_productOrigin.id) === null || _m$_productOrigin === void 0 ? void 0 : _m$_productOrigin.toString()) === (targetProductData === null || targetProductData === void 0 || (_targetProductData$id = targetProductData.id) === null || _targetProductData$id === void 0 ? void 0 : _targetProductData$id.toString()) && "".concat(m.start_date, " ").concat(m.start_time) === item.start && "".concat(m.start_date, " ").concat(m.end_time) === item.end;
2491
2491
  });
2492
- if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size) {
2492
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
2493
2493
  bookingLeft = 0;
2494
+ count = 0;
2494
2495
  }
2495
2496
  // 规则 2
2496
2497
  var otherCartItems = cartItems.filter(function (m) {
@@ -2508,8 +2509,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2508
2509
  return currentResourcesSet.add(resource);
2509
2510
  });
2510
2511
  });
2512
+ // 先确定是否每一个currentResourcesSet在这个时间点的 event_list 都是空的,如果不是空的还需要把他踢出currentResourcesSet
2513
+ var currentDataResources = _this14.store.date.getResourcesListByDate(dayjs(item.start).format('YYYY-MM-DD'));
2514
+ currentDataResources === null || currentDataResources === void 0 || currentDataResources.forEach(function (m) {
2515
+ if (currentResourcesSet.has(m.id)) {
2516
+ var mTimes = m.times.filter(function (n) {
2517
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2518
+ });
2519
+ if (!mTimes.length || mTimes.some(function (n) {
2520
+ return n.event_list.length;
2521
+ })) {
2522
+ currentResourcesSet.delete(m.id);
2523
+ }
2524
+ }
2525
+ });
2511
2526
  if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
2512
2527
  bookingLeft = 0;
2528
+ count = 0;
2513
2529
  }
2514
2530
  } else {
2515
2531
  // 多个预约的检测规则:
@@ -2526,6 +2542,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2526
2542
  }, 0);
2527
2543
  if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
2528
2544
  bookingLeft = 0;
2545
+ count = 0;
2529
2546
  }
2530
2547
  // 规则2、不管是不是跟我一样的商品,只需要跟我当前商品有同一种类型的资源的同一时间的,把所有购物车的 capacity 之和 和 所有当前类型资源的 capacity 之和比较,如果超过了resourcesCapacity,则不可用
2531
2548
  // const otherCartItems = cartItems.filter((m) => m._productOrigin?.id?.toString() !== targetProductData?.id?.toString() && m.start_time === item.start && m.end_time === item.end);
@@ -2556,8 +2573,23 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2556
2573
  var currentTypeResourcesCapacity = allRenderList.reduce(function (acc, curr) {
2557
2574
  return acc + curr.capacity || 0;
2558
2575
  }, 0);
2559
- if (sameCartNeedCapacity + otherCartNeedCapacity >= currentTypeResourcesCapacity) {
2576
+ // 计算当前时间段内所有资源的已使用容量
2577
+ var usedCapacity = allRenderList.reduce(function (acc, curr) {
2578
+ var mTimes = curr.times.filter(function (n) {
2579
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2580
+ });
2581
+ mTimes.forEach(function (n) {
2582
+ var _n$event_list;
2583
+ acc += (_n$event_list = n.event_list) === null || _n$event_list === void 0 ? void 0 : _n$event_list.reduce(function (acc, curr) {
2584
+ return acc + curr.pax;
2585
+ }, 0);
2586
+ });
2587
+ return acc;
2588
+ }, 0);
2589
+ // 如果已使用容量超过了当前类型资源的容量,则不可用
2590
+ if (sameCartNeedCapacity + otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
2560
2591
  bookingLeft = 0;
2592
+ count = 0;
2561
2593
  }
2562
2594
  }
2563
2595
  });
@@ -49,10 +49,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
49
49
  this.request = this.core.getPlugin("request");
50
50
  const appPlugin = this.core.getPlugin("app");
51
51
  if (!appPlugin) {
52
- throw new Error("Order 模块需要 app 插件支持");
52
+ console.warn("Order 模块需要 app 插件支持");
53
53
  }
54
- const app = appPlugin.getApp();
55
- this.logger = app.logger;
54
+ const app = appPlugin == null ? void 0 : appPlugin.getApp();
55
+ if (app)
56
+ this.logger = app.logger;
56
57
  this.logInfo("OrderModule initialized successfully");
57
58
  }
58
59
  /**
@@ -319,7 +319,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
319
319
  checkMaxDurationCapacity(): boolean;
320
320
  setOtherData(key: string, value: any): void;
321
321
  getOtherData(key: string): any;
322
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
322
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
323
323
  /**
324
324
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
325
325
  *
@@ -1744,8 +1744,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1744
1744
  var _a2, _b2, _c2;
1745
1745
  return ((_b2 = (_a2 = m._productOrigin) == null ? void 0 : _a2.id) == null ? void 0 : _b2.toString()) === ((_c2 = targetProductData == null ? void 0 : targetProductData.id) == null ? void 0 : _c2.toString()) && `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end;
1746
1746
  });
1747
- if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size) {
1747
+ if (sameCartItems.length > 0 && sameCartItems.length >= currentResourcesSet.size || sameCartItems.length > bookingLeft) {
1748
1748
  bookingLeft = 0;
1749
+ count = 0;
1749
1750
  }
1750
1751
  const otherCartItems = cartItems2.filter((m) => {
1751
1752
  var _a2, _b2, _c2;
@@ -1757,8 +1758,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1757
1758
  const sameTypeResourcesSet = /* @__PURE__ */ new Set([...(sameTypeResources == null ? void 0 : sameTypeResources.optional_resource) || [], ...(sameTypeResources == null ? void 0 : sameTypeResources.default_resource) || []]);
1758
1759
  sameTypeResourcesSet.forEach((resource) => currentResourcesSet.add(resource));
1759
1760
  });
1761
+ const currentDataResources = this.store.date.getResourcesListByDate((0, import_dayjs.default)(item.start).format("YYYY-MM-DD"));
1762
+ currentDataResources == null ? void 0 : currentDataResources.forEach((m) => {
1763
+ if (currentResourcesSet.has(m.id)) {
1764
+ const mTimes = m.times.filter((n2) => {
1765
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1766
+ });
1767
+ if (!mTimes.length || mTimes.some((n2) => n2.event_list.length)) {
1768
+ currentResourcesSet.delete(m.id);
1769
+ }
1770
+ }
1771
+ });
1760
1772
  if (currentResourcesSet.size > 0 && otherCartItems.length + sameCartItems.length >= currentResourcesSet.size) {
1761
1773
  bookingLeft = 0;
1774
+ count = 0;
1762
1775
  }
1763
1776
  } else {
1764
1777
  const sameCartItems = cartItems2.filter((m) => {
@@ -1769,6 +1782,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1769
1782
  const currentProductResourcesCapacity = n.renderList.reduce((acc, curr) => !curr.onlyComputed ? acc + curr.capacity || 0 : acc, 0);
1770
1783
  if (sameCartNeedCapacity >= currentProductResourcesCapacity) {
1771
1784
  bookingLeft = 0;
1785
+ count = 0;
1772
1786
  }
1773
1787
  const otherSameTimesCartItems = cartItems2.filter((m) => `${m.start_date} ${m.start_time}` === item.start && `${m.start_date} ${m.end_time}` === item.end);
1774
1788
  const otherCartNeedCapacity = otherSameTimesCartItems.reduce((acc, curr) => acc + (0, import_capacity.getCapacityInfoByCartItem)(curr).currentCapacity, 0);
@@ -1792,8 +1806,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1792
1806
  });
1793
1807
  });
1794
1808
  const currentTypeResourcesCapacity = allRenderList.reduce((acc, curr) => acc + curr.capacity || 0, 0);
1795
- if (sameCartNeedCapacity + otherCartNeedCapacity >= currentTypeResourcesCapacity) {
1809
+ const usedCapacity = allRenderList.reduce((acc, curr) => {
1810
+ const mTimes = curr.times.filter((n2) => {
1811
+ return !(0, import_dayjs.default)(n2.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n2.end_at).isBefore((0, import_dayjs.default)(item.end), "minute") || (0, import_dayjs.default)(n2.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n2.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1812
+ });
1813
+ mTimes.forEach((n2) => {
1814
+ var _a2;
1815
+ acc += (_a2 = n2.event_list) == null ? void 0 : _a2.reduce((acc2, curr2) => acc2 + curr2.pax, 0);
1816
+ });
1817
+ return acc;
1818
+ }, 0);
1819
+ if (sameCartNeedCapacity + otherCartNeedCapacity + usedCapacity >= currentTypeResourcesCapacity) {
1796
1820
  bookingLeft = 0;
1821
+ count = 0;
1797
1822
  }
1798
1823
  }
1799
1824
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.272",
4
+ "version": "0.0.274",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",