@pisell/pisellos 0.0.48 → 0.0.50

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.
@@ -16,6 +16,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
16
16
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
17
  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); }
18
18
  import { BaseModule } from "../BaseModule";
19
+ import { generateDuration } from "./utils";
19
20
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
20
21
  _inherits(OrderModule, _BaseModule);
21
22
  var _super = _createSuper(OrderModule);
@@ -66,6 +67,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
66
67
  var is_deposit = 0; // 是否存在定金,0 不存在,1 存在
67
68
  if (params.cartItems.length > 0) {
68
69
  params.cartItems.forEach(function (item) {
70
+ if (!item._origin.duration) {
71
+ var _generateDuration = generateDuration(item),
72
+ duration = _generateDuration.duration,
73
+ durationType = _generateDuration.durationType;
74
+ item._origin.duration = duration;
75
+ item._origin.sub_type = durationType;
76
+ }
69
77
  order.bookings.push(item._origin);
70
78
  if (item !== null && item !== void 0 && item.deposit) {
71
79
  is_deposit = 1;
@@ -0,0 +1,10 @@
1
+ import { CartItem } from "../Cart";
2
+ /**
3
+ * 通过 session 类商品的开始时间结束时间生成商品的时长
4
+ * @param {CartItem} cartItem
5
+ * @return {*}
6
+ */
7
+ export declare const generateDuration: (cartItem: CartItem) => {
8
+ duration: number;
9
+ durationType: string;
10
+ };
@@ -0,0 +1,15 @@
1
+ import dayjs from "dayjs";
2
+ /**
3
+ * 通过 session 类商品的开始时间结束时间生成商品的时长
4
+ * @param {CartItem} cartItem
5
+ * @return {*}
6
+ */
7
+ export var generateDuration = function generateDuration(cartItem) {
8
+ var startDate = dayjs("".concat(cartItem.start_date, " ").concat(cartItem.start_time));
9
+ var endDate = dayjs("".concat(cartItem.end_date, " ").concat(cartItem.end_time));
10
+ var duration = endDate.diff(startDate, 'minutes');
11
+ return {
12
+ duration: duration,
13
+ durationType: 'minutes'
14
+ };
15
+ };
@@ -135,7 +135,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
135
135
  _id: string;
136
136
  product: ProductData | undefined;
137
137
  resources: import("./utils/resources").ResourceItem[];
138
- holder_id: string | number;
138
+ holder_id: string | number | undefined;
139
139
  holder_name: string | undefined;
140
140
  } | undefined;
141
141
  getResourceTimeSlot({ product, resources, currentResourceId, }: {
@@ -27,7 +27,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
27
  import { BaseModule } from "../../modules/BaseModule";
28
28
  import { BookingByStepHooks, createModule } from "./types";
29
29
  import { getAvailableProductResources } from "./utils/products";
30
- import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity } from "./utils/resources";
30
+ import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, formatDefaultCapacitys, getSumCapacity, checkSubResourcesCapacity, getOthersCartSelectedResources } from "./utils/resources";
31
31
  import dayjs from 'dayjs';
32
32
  import { getResourcesMap } from "../../modules/Resource/utils";
33
33
  import { cloneDeep } from 'lodash-es';
@@ -243,15 +243,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
243
243
  return n.date === date;
244
244
  }).flatMap(function (n) {
245
245
  return n.schedule_id;
246
- }); // 换了日期就清空购物车,不能购物车里的商品不在同一天
247
- this.store.cart.clear();
248
- _context3.next = 5;
246
+ });
247
+ _context3.next = 4;
249
248
  return this.loadProducts({
250
249
  schedule_ids: scheduleIds
251
250
  });
252
- case 5:
251
+ case 4:
253
252
  return _context3.abrupt("return", _context3.sent);
254
- case 6:
253
+ case 5:
255
254
  case "end":
256
255
  return _context3.stop();
257
256
  }
@@ -1089,7 +1088,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1089
1088
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1090
1089
  });
1091
1090
  }
1092
- var resourcesMap = getResourcesMap(resources);
1091
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
1093
1092
  var cartItems = this.store.cart.getItems();
1094
1093
  var arr = [];
1095
1094
  var capacityMap = {};
@@ -1098,6 +1097,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1098
1097
  var selectedResources = [];
1099
1098
  if (cartItem.holder_id) {
1100
1099
  selectedResources = getOthersSelectedResources(cartItems, cartItem.holder_id, resourcesMap);
1100
+ } else {
1101
+ selectedResources = getOthersCartSelectedResources(cartItems, cartItem._id, resourcesMap);
1101
1102
  }
1102
1103
  var formatCapacity = formatDefaultCapacitys({
1103
1104
  capacity: (_cartItem$_productOri = cartItem._productOrigin) === null || _cartItem$_productOri === void 0 ? void 0 : _cartItem$_productOri.capacity,
@@ -1157,15 +1158,21 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1157
1158
  dateRange.forEach(function (n) {
1158
1159
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1159
1160
  });
1160
- var resourcesMap = getResourcesMap(resources);
1161
+ // 这里为什么要 cloneDeep:因为 getOthersSelectedResources 和 getOthersCartSelectedResources 会修改 resourcesMap 的 capacity
1162
+ // 用于确保后续分配的容量不会超出
1163
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
1161
1164
  var targetCartItem = cartItems.find(function (n) {
1162
1165
  return n._id === id;
1163
1166
  });
1164
1167
  if (!targetCartItem) {
1165
1168
  throw new Error("\u6CA1\u6709\u627E\u5230".concat(id, "\u8D2D\u7269\u8F66\u5546\u54C1"));
1166
1169
  }
1167
- if (!targetCartItem.holder_id) return;
1168
- var selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1170
+ var selectedResources = [];
1171
+ if (targetCartItem.holder_id) {
1172
+ selectedResources = getOthersSelectedResources(cartItems, targetCartItem.holder_id, resourcesMap);
1173
+ } else {
1174
+ selectedResources = getOthersCartSelectedResources(cartItems, targetCartItem._id, resourcesMap);
1175
+ }
1169
1176
  var formatCapacity = formatDefaultCapacitys({
1170
1177
  capacity: (_targetCartItem$_prod = targetCartItem._productOrigin) === null || _targetCartItem$_prod === void 0 ? void 0 : _targetCartItem$_prod.capacity,
1171
1178
  product_bundle: targetCartItem._origin.product.product_bundle
@@ -1392,7 +1399,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1392
1399
  dateRange.forEach(function (n) {
1393
1400
  if (n.resource) resources.push.apply(resources, _toConsumableArray(n.resource));
1394
1401
  });
1395
- var resourcesMap = getResourcesMap(resources);
1402
+ var resourcesMap = getResourcesMap(cloneDeep(resources));
1396
1403
  // 一个账号一个账号处理
1397
1404
  var errorList = [];
1398
1405
  var selectResourcesMap = {};
@@ -1460,8 +1467,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1460
1467
  // 这里必须每次循环重新读,避免前一次循环操作了购物车,导致数据变更
1461
1468
  var allCartItems = _this7.store.cart.getItems();
1462
1469
  // 如果没有传递 timeSlots,代表是第一种资源,则直接拿商品的 duration,到资源列表里找一个公共可用的
1463
- if (!item.holder_id) return;
1464
- var selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1470
+ var selectedResources = [];
1471
+ if (item.holder_id) {
1472
+ selectedResources = getOthersSelectedResources(allCartItems, item.holder_id, resourcesMap);
1473
+ } else {
1474
+ selectedResources = getOthersCartSelectedResources(allCartItems, item._id, resourcesMap);
1475
+ }
1465
1476
  var productResources = getResourcesByProduct(resourcesMap, ((_item$_productOrigin7 = item._productOrigin) === null || _item$_productOrigin7 === void 0 || (_item$_productOrigin7 = _item$_productOrigin7.product_resource) === null || _item$_productOrigin7 === void 0 ? void 0 : _item$_productOrigin7.resources) || [], selectedResources, currentCapacity);
1466
1477
  // 自动选择 productResources 中对应 resources_code 的资源
1467
1478
  var targetRenderList = (_productResources$fin = productResources.find(function (n) {
@@ -118,6 +118,15 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
118
118
  * @Author: jinglin.tan
119
119
  */
120
120
  export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
121
+ /**
122
+ * @title: 获取其他购物车内商品的已选资源
123
+ * @description:
124
+ * @param {CartItem[]} cartItems
125
+ * @param {number | string} accountId
126
+ * @return {*}
127
+ * @Author: jinglin.tan
128
+ */
129
+ export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
121
130
  interface CapacityItem {
122
131
  id: number;
123
132
  value: number;
@@ -496,6 +496,57 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
496
496
  return acc;
497
497
  }
498
498
  acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
499
+ n.metadata.combined_resource.resource_ids.forEach(function (m) {
500
+ resourcesMap[m].capacity -= n.num;
501
+ });
502
+ } else {
503
+ // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
504
+ // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
505
+ Object.values(resourcesMap).forEach(function (m) {
506
+ if (m.combined_resource && m.combined_resource.status === 1) {
507
+ if (m.combined_resource.resource_ids.includes(n.id)) {
508
+ acc.push(m.id);
509
+ resourcesMap[m.id].capacity -= n.num;
510
+ }
511
+ }
512
+ });
513
+ }
514
+ acc.push(n.id);
515
+ resourcesMap[n.id].capacity -= n.num;
516
+ });
517
+ }
518
+ }
519
+ return acc;
520
+ }, []);
521
+ };
522
+
523
+ /**
524
+ * @title: 获取其他购物车内商品的已选资源
525
+ * @description:
526
+ * @param {CartItem[]} cartItems
527
+ * @param {number | string} accountId
528
+ * @return {*}
529
+ * @Author: jinglin.tan
530
+ */
531
+ export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap) {
532
+ return cartItems.reduce(function (acc, d) {
533
+ if (d._id !== cartItemId) {
534
+ var _d$_origin2;
535
+ if ((_d$_origin2 = d._origin) !== null && _d$_origin2 !== void 0 && _d$_origin2.resources) {
536
+ debugger;
537
+ d._origin.resources.forEach(function (n) {
538
+ // 如果是组合资源,还需要检查组合资源里子资源是否被占用过
539
+ if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
540
+ // 如果组合资源里子资源被占用过,则这个资源不可以进待选列表了
541
+ if (n.metadata.combined_resource.resource_ids.some(function (m) {
542
+ return acc.includes(m);
543
+ })) {
544
+ return acc;
545
+ }
546
+ acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
547
+ n.metadata.combined_resource.resource_ids.forEach(function (m) {
548
+ resourcesMap[m].capacity -= n.num;
549
+ });
499
550
  } else {
500
551
  // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
501
552
  // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
@@ -503,11 +554,14 @@ export var getOthersSelectedResources = function getOthersSelectedResources(cart
503
554
  if (m.combined_resource && m.combined_resource.status === 1) {
504
555
  if (m.combined_resource.resource_ids.includes(n.id)) {
505
556
  acc.push(m.id);
557
+ resourcesMap[m.id].capacity -= n.num;
506
558
  }
507
559
  }
508
560
  });
509
561
  }
510
562
  acc.push(n.id);
563
+ // push 完以后,把 resourceMap 的 capacity 减掉当前的商品数量
564
+ resourcesMap[n.id].capacity -= n.num;
511
565
  });
512
566
  }
513
567
  }
@@ -23,6 +23,7 @@ __export(Order_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(Order_exports);
25
25
  var import_BaseModule = require("../BaseModule");
26
+ var import_utils = require("./utils");
26
27
  var OrderModule = class extends import_BaseModule.BaseModule {
27
28
  constructor(name, version) {
28
29
  super(name, version);
@@ -48,6 +49,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
48
49
  let is_deposit = 0;
49
50
  if (params.cartItems.length > 0) {
50
51
  params.cartItems.forEach((item) => {
52
+ if (!item._origin.duration) {
53
+ const { duration, durationType } = (0, import_utils.generateDuration)(item);
54
+ item._origin.duration = duration;
55
+ item._origin.sub_type = durationType;
56
+ }
51
57
  order.bookings.push(item._origin);
52
58
  if (item == null ? void 0 : item.deposit) {
53
59
  is_deposit = 1;
@@ -0,0 +1,10 @@
1
+ import { CartItem } from "../Cart";
2
+ /**
3
+ * 通过 session 类商品的开始时间结束时间生成商品的时长
4
+ * @param {CartItem} cartItem
5
+ * @return {*}
6
+ */
7
+ export declare const generateDuration: (cartItem: CartItem) => {
8
+ duration: number;
9
+ durationType: string;
10
+ };
@@ -0,0 +1,45 @@
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 });
10
+ };
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/modules/Order/utils.ts
30
+ var utils_exports = {};
31
+ __export(utils_exports, {
32
+ generateDuration: () => generateDuration
33
+ });
34
+ module.exports = __toCommonJS(utils_exports);
35
+ var import_dayjs = __toESM(require("dayjs"));
36
+ var generateDuration = (cartItem) => {
37
+ const startDate = (0, import_dayjs.default)(`${cartItem.start_date} ${cartItem.start_time}`);
38
+ const endDate = (0, import_dayjs.default)(`${cartItem.end_date} ${cartItem.end_time}`);
39
+ const duration = endDate.diff(startDate, "minutes");
40
+ return { duration, durationType: "minutes" };
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ generateDuration
45
+ });
@@ -135,7 +135,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
135
135
  _id: string;
136
136
  product: ProductData | undefined;
137
137
  resources: import("./utils/resources").ResourceItem[];
138
- holder_id: string | number;
138
+ holder_id: string | number | undefined;
139
139
  holder_name: string | undefined;
140
140
  } | undefined;
141
141
  getResourceTimeSlot({ product, resources, currentResourceId, }: {
@@ -183,7 +183,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
183
183
  async loadProductByScheduleDate(date) {
184
184
  const scheduleList = this.store.schedule.getAvailabilityScheduleDateList();
185
185
  const scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
186
- this.store.cart.clear();
187
186
  return await this.loadProducts({ schedule_ids: scheduleIds });
188
187
  }
189
188
  // 加载当前店铺下所有 schedule
@@ -545,7 +544,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
545
544
  resources.push(...n.resource);
546
545
  });
547
546
  }
548
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
547
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
549
548
  const cartItems = this.store.cart.getItems();
550
549
  const arr = [];
551
550
  const capacityMap = {};
@@ -558,6 +557,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
558
557
  cartItem.holder_id,
559
558
  resourcesMap
560
559
  );
560
+ } else {
561
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
562
+ cartItems,
563
+ cartItem._id,
564
+ resourcesMap
565
+ );
561
566
  }
562
567
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
563
568
  capacity: (_a = cartItem._productOrigin) == null ? void 0 : _a.capacity,
@@ -621,18 +626,25 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
621
626
  if (n.resource)
622
627
  resources.push(...n.resource);
623
628
  });
624
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
629
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
625
630
  const targetCartItem = cartItems.find((n) => n._id === id);
626
631
  if (!targetCartItem) {
627
632
  throw new Error(`没有找到${id}购物车商品`);
628
633
  }
629
- if (!targetCartItem.holder_id)
630
- return;
631
- const selectedResources = (0, import_resources.getOthersSelectedResources)(
632
- cartItems,
633
- targetCartItem.holder_id,
634
- resourcesMap
635
- );
634
+ let selectedResources = [];
635
+ if (targetCartItem.holder_id) {
636
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
637
+ cartItems,
638
+ targetCartItem.holder_id,
639
+ resourcesMap
640
+ );
641
+ } else {
642
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
643
+ cartItems,
644
+ targetCartItem._id,
645
+ resourcesMap
646
+ );
647
+ }
636
648
  const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
637
649
  capacity: (_a = targetCartItem._productOrigin) == null ? void 0 : _a.capacity,
638
650
  product_bundle: targetCartItem._origin.product.product_bundle
@@ -797,7 +809,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
797
809
  if (n.resource)
798
810
  resources.push(...n.resource);
799
811
  });
800
- const resourcesMap = (0, import_utils.getResourcesMap)(resources);
812
+ const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(resources));
801
813
  const errorList = [];
802
814
  const selectResourcesMap = {};
803
815
  this.store.accountList.getAccounts().forEach((account) => {
@@ -857,13 +869,20 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
857
869
  }
858
870
  } else {
859
871
  const allCartItems = this.store.cart.getItems();
860
- if (!item.holder_id)
861
- return;
862
- const selectedResources = (0, import_resources.getOthersSelectedResources)(
863
- allCartItems,
864
- item.holder_id,
865
- resourcesMap
866
- );
872
+ let selectedResources = [];
873
+ if (item.holder_id) {
874
+ selectedResources = (0, import_resources.getOthersSelectedResources)(
875
+ allCartItems,
876
+ item.holder_id,
877
+ resourcesMap
878
+ );
879
+ } else {
880
+ selectedResources = (0, import_resources.getOthersCartSelectedResources)(
881
+ allCartItems,
882
+ item._id,
883
+ resourcesMap
884
+ );
885
+ }
867
886
  const productResources = (0, import_resources.getResourcesByProduct)(
868
887
  resourcesMap,
869
888
  ((_k = (_j = item._productOrigin) == null ? void 0 : _j.product_resource) == null ? void 0 : _k.resources) || [],
@@ -118,6 +118,15 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
118
118
  * @Author: jinglin.tan
119
119
  */
120
120
  export declare const getOthersSelectedResources: (cartItems: CartItem[], accountId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
121
+ /**
122
+ * @title: 获取其他购物车内商品的已选资源
123
+ * @description:
124
+ * @param {CartItem[]} cartItems
125
+ * @param {number | string} accountId
126
+ * @return {*}
127
+ * @Author: jinglin.tan
128
+ */
129
+ export declare const getOthersCartSelectedResources: (cartItems: CartItem[], cartItemId: number | string, resourcesMap: Record<string, ResourceItem>) => number[];
121
130
  interface CapacityItem {
122
131
  id: number;
123
132
  value: number;
@@ -33,6 +33,7 @@ __export(resources_exports, {
33
33
  formatDefaultCapacitys: () => formatDefaultCapacitys,
34
34
  formatResources: () => formatResources,
35
35
  getIsUsableByTimeItem: () => getIsUsableByTimeItem,
36
+ getOthersCartSelectedResources: () => getOthersCartSelectedResources,
36
37
  getOthersSelectedResources: () => getOthersSelectedResources,
37
38
  getResourcesByIds: () => getResourcesByIds,
38
39
  getResourcesByProduct: () => getResourcesByProduct,
@@ -358,16 +359,56 @@ var getOthersSelectedResources = (cartItems, accountId, resourcesMap) => {
358
359
  return acc;
359
360
  }
360
361
  acc.push(...n.metadata.combined_resource.resource_ids);
362
+ n.metadata.combined_resource.resource_ids.forEach((m) => {
363
+ resourcesMap[m].capacity -= n.num;
364
+ });
365
+ } else {
366
+ Object.values(resourcesMap).forEach((m) => {
367
+ if (m.combined_resource && m.combined_resource.status === 1) {
368
+ if (m.combined_resource.resource_ids.includes(n.id)) {
369
+ acc.push(m.id);
370
+ resourcesMap[m.id].capacity -= n.num;
371
+ }
372
+ }
373
+ });
374
+ }
375
+ acc.push(n.id);
376
+ resourcesMap[n.id].capacity -= n.num;
377
+ });
378
+ }
379
+ }
380
+ return acc;
381
+ }, []);
382
+ };
383
+ var getOthersCartSelectedResources = (cartItems, cartItemId, resourcesMap) => {
384
+ return cartItems.reduce((acc, d) => {
385
+ var _a;
386
+ if (d._id !== cartItemId) {
387
+ if ((_a = d._origin) == null ? void 0 : _a.resources) {
388
+ debugger;
389
+ d._origin.resources.forEach((n) => {
390
+ if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
391
+ if (n.metadata.combined_resource.resource_ids.some(
392
+ (m) => acc.includes(m)
393
+ )) {
394
+ return acc;
395
+ }
396
+ acc.push(...n.metadata.combined_resource.resource_ids);
397
+ n.metadata.combined_resource.resource_ids.forEach((m) => {
398
+ resourcesMap[m].capacity -= n.num;
399
+ });
361
400
  } else {
362
401
  Object.values(resourcesMap).forEach((m) => {
363
402
  if (m.combined_resource && m.combined_resource.status === 1) {
364
403
  if (m.combined_resource.resource_ids.includes(n.id)) {
365
404
  acc.push(m.id);
405
+ resourcesMap[m.id].capacity -= n.num;
366
406
  }
367
407
  }
368
408
  });
369
409
  }
370
410
  acc.push(n.id);
411
+ resourcesMap[n.id].capacity -= n.num;
371
412
  });
372
413
  }
373
414
  }
@@ -428,6 +469,7 @@ var checkSubResourcesCapacity = (resource) => {
428
469
  formatDefaultCapacitys,
429
470
  formatResources,
430
471
  getIsUsableByTimeItem,
472
+ getOthersCartSelectedResources,
431
473
  getOthersSelectedResources,
432
474
  getResourcesByIds,
433
475
  getResourcesByProduct,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.48",
4
+ "version": "0.0.50",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",