@pisell/pisellos 3.0.5 → 3.0.6

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 (146) hide show
  1. package/dist/modules/Account/index.d.ts +2 -6
  2. package/dist/modules/Account/index.js +21 -103
  3. package/dist/modules/Account/types.d.ts +12 -1
  4. package/dist/modules/AccountList/index.d.ts +20 -1
  5. package/dist/modules/AccountList/index.js +243 -75
  6. package/dist/modules/AccountList/types.d.ts +33 -1
  7. package/dist/modules/AccountList/types.js +8 -0
  8. package/dist/modules/AccountList/utils.d.ts +9 -0
  9. package/dist/modules/AccountList/utils.js +25 -0
  10. package/dist/modules/BaseModule.d.ts +2 -2
  11. package/dist/modules/BaseModule.js +1 -1
  12. package/dist/modules/Cart/index.d.ts +8 -5
  13. package/dist/modules/Cart/index.js +101 -25
  14. package/dist/modules/Cart/types.d.ts +82 -5
  15. package/dist/modules/Cart/types.js +22 -0
  16. package/dist/modules/Cart/utils.d.ts +106 -13
  17. package/dist/modules/Cart/utils.js +289 -76
  18. package/dist/modules/Date/index.d.ts +6 -6
  19. package/dist/modules/Date/index.js +41 -58
  20. package/dist/modules/Date/types.d.ts +22 -6
  21. package/dist/modules/Date/utils.d.ts +4 -3
  22. package/dist/modules/Date/utils.js +81 -30
  23. package/dist/modules/Discount/index.d.ts +4 -4
  24. package/dist/modules/Discount/index.js +11 -11
  25. package/dist/modules/Order/index.d.ts +11 -5
  26. package/dist/modules/Order/index.js +47 -18
  27. package/dist/modules/Order/types.d.ts +10 -3
  28. package/dist/modules/Order/utils.d.ts +10 -0
  29. package/dist/modules/Order/utils.js +15 -0
  30. package/dist/modules/Product/index.d.ts +14 -1
  31. package/dist/modules/Product/index.js +35 -0
  32. package/dist/modules/Product/types.d.ts +27 -3
  33. package/dist/modules/ProductList/index.js +11 -5
  34. package/dist/modules/Resource/types.d.ts +1 -0
  35. package/dist/modules/Resource/utils.js +1 -1
  36. package/dist/modules/Rules/index.d.ts +3 -3
  37. package/dist/modules/Rules/index.js +121 -53
  38. package/dist/modules/Rules/types.d.ts +5 -1
  39. package/dist/modules/Schedule/index.d.ts +18 -0
  40. package/dist/modules/Schedule/index.js +111 -0
  41. package/dist/modules/Schedule/type.d.ts +157 -0
  42. package/dist/modules/Schedule/type.js +1 -0
  43. package/dist/modules/Schedule/types.d.ts +182 -0
  44. package/dist/modules/Schedule/types.js +1 -0
  45. package/dist/modules/Schedule/utils.d.ts +67 -0
  46. package/dist/modules/Schedule/utils.js +729 -0
  47. package/dist/modules/Step/index.d.ts +14 -3
  48. package/dist/modules/Step/index.js +54 -2
  49. package/dist/modules/Summary/index.d.ts +12 -5
  50. package/dist/modules/Summary/index.js +33 -7
  51. package/dist/modules/Summary/types.d.ts +23 -2
  52. package/dist/modules/Summary/utils.d.ts +14 -4
  53. package/dist/modules/Summary/utils.js +46 -4
  54. package/dist/modules/index.d.ts +10 -0
  55. package/dist/modules/index.js +11 -1
  56. package/dist/plugins/index.d.ts +3 -3
  57. package/dist/plugins/request.d.ts +3 -3
  58. package/dist/plugins/request.js +30 -30
  59. package/dist/plugins/shopStore.d.ts +1 -1
  60. package/dist/solution/BookingByStep/index.d.ts +97 -24
  61. package/dist/solution/BookingByStep/index.js +1024 -322
  62. package/dist/solution/BookingByStep/types.d.ts +3 -10
  63. package/dist/solution/BookingByStep/types.js +11 -15
  64. package/dist/solution/BookingByStep/utils/products.d.ts +1 -1
  65. package/dist/solution/BookingByStep/utils/products.js +3 -0
  66. package/dist/solution/BookingByStep/utils/resources.d.ts +60 -6
  67. package/dist/solution/BookingByStep/utils/resources.js +293 -52
  68. package/dist/solution/ShopDiscount/index.d.ts +4 -4
  69. package/dist/solution/ShopDiscount/index.js +16 -16
  70. package/dist/solution/ShopDiscount/types.d.ts +2 -2
  71. package/dist/solution/ShopDiscount/utils.js +1 -1
  72. package/lib/core/index.js +7 -2
  73. package/lib/modules/Account/index.d.ts +2 -6
  74. package/lib/modules/Account/index.js +15 -30
  75. package/lib/modules/Account/types.d.ts +12 -1
  76. package/lib/modules/AccountList/index.d.ts +20 -1
  77. package/lib/modules/AccountList/index.js +122 -13
  78. package/lib/modules/AccountList/types.d.ts +33 -1
  79. package/lib/modules/AccountList/utils.d.ts +9 -0
  80. package/lib/modules/AccountList/utils.js +39 -0
  81. package/lib/modules/BaseModule.d.ts +2 -2
  82. package/lib/modules/BaseModule.js +14 -3
  83. package/lib/modules/Cart/index.d.ts +8 -5
  84. package/lib/modules/Cart/index.js +81 -8
  85. package/lib/modules/Cart/types.d.ts +82 -5
  86. package/lib/modules/Cart/types.js +20 -2
  87. package/lib/modules/Cart/utils.d.ts +106 -13
  88. package/lib/modules/Cart/utils.js +188 -45
  89. package/lib/modules/Date/index.d.ts +6 -6
  90. package/lib/modules/Date/index.js +13 -28
  91. package/lib/modules/Date/types.d.ts +22 -6
  92. package/lib/modules/Date/utils.d.ts +4 -3
  93. package/lib/modules/Date/utils.js +47 -13
  94. package/lib/modules/Discount/index.d.ts +4 -4
  95. package/lib/modules/Discount/index.js +9 -2
  96. package/lib/modules/Guests/index.js +4 -1
  97. package/lib/modules/Order/index.d.ts +11 -5
  98. package/lib/modules/Order/index.js +24 -3
  99. package/lib/modules/Order/types.d.ts +10 -3
  100. package/lib/modules/Order/utils.d.ts +10 -0
  101. package/lib/modules/Order/utils.js +45 -0
  102. package/lib/modules/Payment/index.js +1 -6
  103. package/lib/modules/Product/index.d.ts +14 -1
  104. package/lib/modules/Product/index.js +19 -0
  105. package/lib/modules/Product/types.d.ts +27 -3
  106. package/lib/modules/ProductList/index.js +21 -7
  107. package/lib/modules/Resource/index.js +4 -1
  108. package/lib/modules/Resource/types.d.ts +1 -0
  109. package/lib/modules/Resource/utils.js +7 -4
  110. package/lib/modules/Rules/index.d.ts +3 -3
  111. package/lib/modules/Rules/index.js +118 -43
  112. package/lib/modules/Rules/types.d.ts +5 -1
  113. package/lib/modules/Schedule/index.d.ts +18 -0
  114. package/lib/modules/Schedule/index.js +81 -0
  115. package/lib/modules/Schedule/type.d.ts +157 -0
  116. package/lib/modules/Schedule/type.js +17 -0
  117. package/lib/modules/Schedule/types.d.ts +182 -0
  118. package/lib/modules/Schedule/types.js +17 -0
  119. package/lib/modules/Schedule/utils.d.ts +67 -0
  120. package/lib/modules/Schedule/utils.js +600 -0
  121. package/lib/modules/Step/index.d.ts +14 -3
  122. package/lib/modules/Step/index.js +38 -1
  123. package/lib/modules/Summary/index.d.ts +12 -5
  124. package/lib/modules/Summary/index.js +15 -1
  125. package/lib/modules/Summary/types.d.ts +23 -2
  126. package/lib/modules/Summary/utils.d.ts +14 -4
  127. package/lib/modules/Summary/utils.js +30 -1
  128. package/lib/modules/index.d.ts +10 -0
  129. package/lib/modules/index.js +21 -1
  130. package/lib/plugins/index.d.ts +3 -3
  131. package/lib/plugins/request.d.ts +3 -3
  132. package/lib/plugins/request.js +48 -11
  133. package/lib/plugins/shopStore.d.ts +1 -1
  134. package/lib/solution/BookingByStep/index.d.ts +97 -24
  135. package/lib/solution/BookingByStep/index.js +693 -145
  136. package/lib/solution/BookingByStep/types.d.ts +3 -10
  137. package/lib/solution/BookingByStep/types.js +37 -14
  138. package/lib/solution/BookingByStep/utils/products.d.ts +1 -1
  139. package/lib/solution/BookingByStep/utils/products.js +3 -0
  140. package/lib/solution/BookingByStep/utils/resources.d.ts +60 -6
  141. package/lib/solution/BookingByStep/utils/resources.js +286 -54
  142. package/lib/solution/BuyTickets/index.js +34 -20
  143. package/lib/solution/ShopDiscount/index.d.ts +4 -4
  144. package/lib/solution/ShopDiscount/index.js +10 -2
  145. package/lib/solution/ShopDiscount/types.d.ts +2 -2
  146. package/package.json +4 -2
@@ -17,12 +17,12 @@ import dayjs from 'dayjs';
17
17
  * 1. 获取资源列表
18
18
  * 2. 根据当前选择的商品过滤出来对应的资源列表 getResourcesByProduct
19
19
  * 3. 格式化资源相关 格式化资源列表 --> 格式化资源 --> 获取时间切片列表 --> 判断单个时间切片是否可用 formatResources
20
- *
20
+ *
21
21
  */
22
22
 
23
23
  /**
24
24
  * @title: 获取重叠剩余量
25
- * @description:
25
+ * @description:
26
26
  * @param {any} eventList
27
27
  * @param {number} current
28
28
  * @return {*}
@@ -36,7 +36,7 @@ var getUseableEventCount = function getUseableEventCount(eventList, current) {
36
36
 
37
37
  /**
38
38
  * @title: 判断两个时间段是否有重叠
39
- * @description:
39
+ * @description:
40
40
  * @param {object} event
41
41
  * @param {object} current
42
42
  * @return {*}
@@ -61,7 +61,7 @@ var isConflict = function isConflict(event, current) {
61
61
 
62
62
  /**
63
63
  * @title: 判断传入日期是否在当前日期之后
64
- * @description:
64
+ * @description:
65
65
  * @param {any} date
66
66
  * @param {any} today
67
67
  * @return {*}
@@ -99,7 +99,7 @@ var formatResource = function formatResource(resourceItem, booking) {
99
99
 
100
100
  /**
101
101
  * @title: 判断资源容量是否可用
102
- * @description:
102
+ * @description:
103
103
  * @param {object} param1
104
104
  * @return {*}
105
105
  * @Author: zhiwei.Wang
@@ -111,7 +111,10 @@ var checkCapacity = function checkCapacity(_ref) {
111
111
  _ref$currentCount = _ref.currentCount,
112
112
  currentCount = _ref$currentCount === void 0 ? 1 : _ref$currentCount;
113
113
  if (currentCount > resource.capacity) {
114
- return false;
114
+ return {
115
+ status: false,
116
+ capacity: resource.capacity
117
+ };
115
118
  }
116
119
  var conflict = (event_list || []).filter(function (d) {
117
120
  return isConflict({
@@ -123,23 +126,35 @@ var checkCapacity = function checkCapacity(_ref) {
123
126
  });
124
127
  });
125
128
 
129
+ // 减去重叠的总量
130
+ var conflictCount = getUseableEventCount(conflict, resource.capacity);
131
+
126
132
  // 同一时间段内只能进行一个预约,无论容量是否已满。
127
133
  if (resource.resourceType === 'single') {
128
134
  // 0代表着不重叠,则满足条件
129
135
  if (conflict.length === 0) {
130
- return true;
136
+ return {
137
+ status: true,
138
+ capacity: conflictCount
139
+ };
131
140
  } else {
132
- return false;
141
+ return {
142
+ status: false,
143
+ capacity: conflictCount
144
+ };
133
145
  }
134
146
  } else {
135
- // 减去重叠的总量
136
- var conflictCount = getUseableEventCount(conflict, resource.capacity);
137
-
138
147
  // 当前预约量 <= 总剩余容量
139
148
  if (currentCount <= conflictCount) {
140
- return true;
149
+ return {
150
+ status: true,
151
+ capacity: conflictCount
152
+ };
141
153
  } else {
142
- return false;
154
+ return {
155
+ status: false,
156
+ capacity: conflictCount
157
+ };
143
158
  }
144
159
  }
145
160
  };
@@ -152,32 +167,47 @@ var checkCapacity = function checkCapacity(_ref) {
152
167
  * @Author: zhiwei.Wang
153
168
  */
154
169
  export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
170
+ var _resource$combined_re;
155
171
  var timeSlice = _ref2.timeSlice,
156
172
  time = _ref2.time,
157
173
  resource = _ref2.resource,
158
174
  _ref2$currentCount = _ref2.currentCount,
159
- currentCount = _ref2$currentCount === void 0 ? 1 : _ref2$currentCount;
175
+ currentCount = _ref2$currentCount === void 0 ? 1 : _ref2$currentCount,
176
+ _ref2$resourcesUseabl = _ref2.resourcesUseableMap,
177
+ resourcesUseableMap = _ref2$resourcesUseabl === void 0 ? {} : _ref2$resourcesUseabl;
160
178
  var status = {
161
179
  afterToDay: false,
162
180
  capacity: false,
163
- usable: false
181
+ usable: false,
182
+ remainingCapacity: 0 // 剩余容量
164
183
  };
165
184
  // 最早可预约时间为 当前日期之后并且提前量之后
166
185
  var earliest = dayjs();
167
-
168
186
  // 不可预约提前量时间之前的
169
187
  if (!checkAfterToDay(timeSlice.start_at, earliest)) {
170
188
  return status;
171
189
  }
172
190
  status.afterToDay = true;
173
- if (!checkCapacity({
191
+ var checkCapacityResult = checkCapacity({
174
192
  event_list: time === null || time === void 0 ? void 0 : time.event_list,
175
193
  timeSlice: timeSlice,
176
194
  resource: resource,
177
195
  currentCount: currentCount
178
- })) {
196
+ });
197
+ if ((_resource$combined_re = resource.combined_resource) !== null && _resource$combined_re !== void 0 && _resource$combined_re.status) {
198
+ // 组合资源中子资源是否可用
199
+ var resourceIds = resource.combined_resource.resource_ids;
200
+ resourceIds.forEach(function (id) {
201
+ // 只要有一个子资源不可用,整个组合资源都不可用
202
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[id]) === false) {
203
+ checkCapacityResult.status = false;
204
+ }
205
+ });
206
+ }
207
+ if (!checkCapacityResult.status) {
179
208
  return status;
180
209
  }
210
+ status.remainingCapacity = checkCapacityResult.capacity;
181
211
  status.capacity = true;
182
212
  status.usable = true;
183
213
  return status;
@@ -185,51 +215,62 @@ export var getIsUsableByTimeItem = function getIsUsableByTimeItem(_ref2) {
185
215
 
186
216
  /**
187
217
  * @title: 获取商品下绑定的资源列表
188
- * @description:
218
+ * @description:
189
219
  * @param {any} resourcesMap
190
220
  * @param {any} product
191
221
  * @return {*}
192
222
  * @Author: zhiwei.Wang
193
223
  */
194
- export var getResourcesByProduct = function getResourcesByProduct(resourcesMap, cartItem, cartList) {
195
- var _product$product_reso;
196
- var product = cartItem._productOrigin;
197
- return ((product === null || product === void 0 || (_product$product_reso = product.product_resource) === null || _product$product_reso === void 0 ? void 0 : _product$product_reso.resources) || []).reduce(function (acc, item) {
224
+ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap, resources, selectedResources) {
225
+ var capacity = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
226
+ return (resources || []).reduce(function (acc, item) {
198
227
  if ((item === null || item === void 0 ? void 0 : item.status) == 1) {
199
228
  var form_id = item.id;
200
229
  // 去重 可选资源和必选资源可能会有重复的
201
230
  item.optional_resource = (item.optional_resource || []).filter(function (d) {
202
231
  return item.default_resource.indexOf(d) == -1;
203
232
  });
204
-
205
- // 如果购物车里有 某一项的 resources 选中过了某些资源,则把这些资源给过滤掉
206
- // 这里做一个拍平,把非当前 holder_id 的资源洗到一个数组里
207
- var selectedResources = cartList.reduce(function (acc, d) {
208
- if (d.holder_id !== cartItem.holder_id) {
209
- var _d$_origin;
210
- if ((_d$_origin = d._origin) !== null && _d$_origin !== void 0 && _d$_origin.resources) {
211
- d._origin.resources.forEach(function (n) {
212
- acc.push(n.id);
213
- });
214
- }
215
- }
216
- return acc;
217
- }, []);
218
233
  var optional_resource = item.optional_resource.reduce(function (childAcc, d) {
219
234
  if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
235
+ // 拼装组合资源的数据
236
+ var combiningResources = [];
237
+ if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
238
+ resourcesMap[d].combined_resource.resource_ids.forEach(function (id) {
239
+ if (resourcesMap[id]) {
240
+ combiningResources.push(resourcesMap[id]);
241
+ }
242
+ });
243
+ }
220
244
  childAcc.push(Object.assign({}, resourcesMap[d], {
221
245
  form_id: form_id,
222
- resourceType: item.type
246
+ resourceType: item.type,
247
+ children: combiningResources,
248
+ metadata: _objectSpread(_objectSpread({}, resourcesMap[d].metadata), {}, {
249
+ combined_resource: resourcesMap[d].combined_resource
250
+ })
223
251
  }));
224
252
  }
225
253
  return childAcc;
226
254
  }, []);
227
255
  var default_resource = item.default_resource.reduce(function (childAcc, d) {
228
256
  if (resourcesMap[d] && !selectedResources.includes(resourcesMap[d].id)) {
257
+ // 拼装组合资源的数据
258
+ var combiningResources = [];
259
+ if (resourcesMap[d].combined_resource && resourcesMap[d].combined_resource.status === 1) {
260
+ resourcesMap[d].combined_resource.resource_ids.forEach(function (id) {
261
+ if (resourcesMap[id]) {
262
+ combiningResources.push(resourcesMap[id]);
263
+ }
264
+ });
265
+ }
229
266
  childAcc.push(Object.assign({}, resourcesMap[d], {
230
267
  form_id: form_id,
231
268
  resourceType: item.type,
232
- is_default: 1
269
+ is_default: 1,
270
+ children: combiningResources,
271
+ metadata: _objectSpread(_objectSpread({}, resourcesMap[d].metadata), {}, {
272
+ combined_resource: resourcesMap[d].combined_resource
273
+ })
233
274
  }));
234
275
  }
235
276
  return childAcc;
@@ -241,6 +282,7 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
241
282
  var latestTime = d.times.reduce(function (latest, current) {
242
283
  return dayjs(current.end_at).isAfter(dayjs(latest.end_at)) ? current : latest;
243
284
  }, d.times[0]);
285
+ // TODO,在这拉时间切片出来,如果可用 timeSlots.length > 1 才可以被选择
244
286
  return dayjs(latestTime.end_at).isAfter(dayjs());
245
287
  });
246
288
  item.form_id = form_id;
@@ -249,14 +291,6 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
249
291
  return acc;
250
292
  }, []);
251
293
  };
252
- export var getSumCapacity = function getSumCapacity() {
253
- // let sum = 0;
254
- // for (let item of booking._extend.capacity || []) {
255
- // sum += item.value;
256
- // }
257
- // 一期默认为1人
258
- return 1;
259
- };
260
294
 
261
295
  /**
262
296
  * @title: 获取资源列表
@@ -309,7 +343,7 @@ export var formatResources = function formatResources(_ref3) {
309
343
 
310
344
  /**
311
345
  * @title: 获取资源的时间切片列表
312
- * @description:
346
+ * @description:
313
347
  * @return {*}
314
348
  * @Author: zhiwei.Wang
315
349
  */
@@ -319,7 +353,10 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
319
353
  _ref4$split = _ref4.split,
320
354
  split = _ref4$split === void 0 ? 10 : _ref4$split,
321
355
  _ref4$currentDate = _ref4.currentDate,
322
- currentDate = _ref4$currentDate === void 0 ? dayjs() : _ref4$currentDate;
356
+ currentDate = _ref4$currentDate === void 0 ? dayjs() : _ref4$currentDate,
357
+ capacity = _ref4.capacity,
358
+ _ref4$resourcesUseabl = _ref4.resourcesUseableMap,
359
+ resourcesUseableMap = _ref4$resourcesUseabl === void 0 ? {} : _ref4$resourcesUseabl;
323
360
  var times = resource.times;
324
361
 
325
362
  // 存储所有时间切片
@@ -356,8 +393,12 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref4) {
356
393
  timeSlice: timeSlice,
357
394
  time: time,
358
395
  resource: resource,
359
- currentCount: getSumCapacity()
396
+ currentCount: capacity || 1,
397
+ resourcesUseableMap: resourcesUseableMap
360
398
  });
399
+ if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[resource.id]) !== false) {
400
+ resourcesUseableMap[resource.id] = _status.usable;
401
+ }
361
402
  if (_status.usable) {
362
403
  // 添加时间切片 09:00 ~ 10:00 09:20 ~ 10:20 09:00 ~ 10:00 09:20 ~ 10:20 11:00 ~ 12:00 11:20 ~ 12:20
363
404
  timeSlices.push(_objectSpread(_objectSpread({}, timeSlice), {}, {
@@ -430,9 +471,20 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
430
471
  resourcesMap = _ref5.resourcesMap,
431
472
  duration = _ref5.duration,
432
473
  currentDate = _ref5.currentDate,
433
- split = _ref5.split;
474
+ split = _ref5.split,
475
+ capacity = _ref5.capacity,
476
+ resourcesUseableMap = _ref5.resourcesUseableMap;
434
477
  // 获取资源列表
435
478
  var resources = getResourcesByIds(resourcesMap, resourceIds);
479
+ // 资源排下序,把单个资源靠前,组合资源排在后面
480
+ resources.sort(function (a, b) {
481
+ var _a$metadata, _b$metadata;
482
+ var aIsCombined = ((_a$metadata = a.metadata) === null || _a$metadata === void 0 || (_a$metadata = _a$metadata.combined_resource) === null || _a$metadata === void 0 ? void 0 : _a$metadata.status) === 1;
483
+ var bIsCombined = ((_b$metadata = b.metadata) === null || _b$metadata === void 0 || (_b$metadata = _b$metadata.combined_resource) === null || _b$metadata === void 0 ? void 0 : _b$metadata.status) === 1;
484
+ if (aIsCombined && !bIsCombined) return 1;
485
+ if (!aIsCombined && bIsCombined) return -1;
486
+ return 0;
487
+ });
436
488
 
437
489
  // 获取资源列表中所有的时间切片
438
490
  var timeSliceList = resources.reduce(function (acc, item) {
@@ -440,11 +492,200 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref5) {
440
492
  resource: item,
441
493
  duration: duration,
442
494
  split: split,
443
- currentDate: currentDate
495
+ currentDate: currentDate,
496
+ capacity: capacity,
497
+ resourcesUseableMap: resourcesUseableMap
444
498
  }));
445
499
  }, []);
446
500
 
447
501
  // 获取时间切片列表的交集
448
502
  var intersection = getTimesIntersection(timeSliceList, resources.length);
449
503
  return intersection;
504
+ };
505
+
506
+ /**
507
+ * @title: 获取其他人的已选资源
508
+ * @description:
509
+ * @param {CartItem[]} cartItems
510
+ * @param {number | string} accountId
511
+ * @return {*}
512
+ * @Author: jinglin.tan
513
+ */
514
+ export var getOthersSelectedResources = function getOthersSelectedResources(cartItems, accountId, resourcesMap) {
515
+ return cartItems.reduce(function (acc, d) {
516
+ if (d.holder_id !== accountId) {
517
+ var _d$_origin;
518
+ if ((_d$_origin = d._origin) !== null && _d$_origin !== void 0 && _d$_origin.resources) {
519
+ d._origin.resources.forEach(function (n) {
520
+ // 如果是组合资源,还需要检查组合资源里子资源是否被占用过
521
+ if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
522
+ // 如果组合资源里子资源被占用过,则这个资源不可以进待选列表了
523
+ if (n.metadata.combined_resource.resource_ids.some(function (m) {
524
+ return acc.includes(m);
525
+ })) {
526
+ return acc;
527
+ }
528
+ acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
529
+ n.metadata.combined_resource.resource_ids.forEach(function (m) {
530
+ resourcesMap[m].capacity -= n.num;
531
+ });
532
+ } else {
533
+ // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
534
+ // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
535
+ Object.values(resourcesMap).forEach(function (m) {
536
+ if (m.combined_resource && m.combined_resource.status === 1) {
537
+ if (m.combined_resource.resource_ids.includes(n.id)) {
538
+ acc.push(m.id);
539
+ resourcesMap[m.id].capacity -= n.num;
540
+ }
541
+ }
542
+ });
543
+ }
544
+ acc.push(n.id);
545
+ resourcesMap[n.id].capacity -= n.num;
546
+ });
547
+ }
548
+ }
549
+ return acc;
550
+ }, []);
551
+ };
552
+
553
+ /**
554
+ * @title: 获取其他购物车内商品的已选资源
555
+ * @description:
556
+ * @param {CartItem[]} cartItems
557
+ * @param {number | string} accountId
558
+ * @return {*}
559
+ * @Author: jinglin.tan
560
+ */
561
+ export var getOthersCartSelectedResources = function getOthersCartSelectedResources(cartItems, cartItemId, resourcesMap) {
562
+ return cartItems.reduce(function (acc, d) {
563
+ if (d._id !== cartItemId) {
564
+ var _d$_origin2;
565
+ if ((_d$_origin2 = d._origin) !== null && _d$_origin2 !== void 0 && _d$_origin2.resources) {
566
+ d._origin.resources.forEach(function (n) {
567
+ // 如果是组合资源,还需要检查组合资源里子资源是否被占用过
568
+ if (n.metadata.combined_resource && n.metadata.combined_resource.status === 1) {
569
+ // 如果组合资源里子资源被占用过,则这个资源不可以进待选列表了
570
+ if (n.metadata.combined_resource.resource_ids.some(function (m) {
571
+ return acc.includes(m);
572
+ })) {
573
+ return acc;
574
+ }
575
+ acc.push.apply(acc, _toConsumableArray(n.metadata.combined_resource.resource_ids));
576
+ n.metadata.combined_resource.resource_ids.forEach(function (m) {
577
+ resourcesMap[m].capacity -= n.num;
578
+ });
579
+ } else {
580
+ // 如果当前选中的不是组合资源,但是是别的组合资源里的子资源,则还需要把别的组合资源也加进来
581
+ // 去 resourcesMap 里找一下 n.id 是不是别的组合资源里的子资源,是的话把别的组合资源也加进来
582
+ Object.values(resourcesMap).forEach(function (m) {
583
+ if (m.combined_resource && m.combined_resource.status === 1) {
584
+ if (m.combined_resource.resource_ids.includes(n.id)) {
585
+ acc.push(m.id);
586
+ resourcesMap[m.id].capacity -= n.num;
587
+ }
588
+ }
589
+ });
590
+ }
591
+ acc.push(n.id);
592
+ // push 完以后,把 resourceMap 的 capacity 减掉当前的商品数量
593
+ resourcesMap[n.id].capacity -= n.num;
594
+ });
595
+ }
596
+ }
597
+ return acc;
598
+ }, []);
599
+ };
600
+ /**
601
+ * @title: 基于选择的商品格式化容量
602
+ * @description:
603
+ * @param {any} param1
604
+ * @return {*}
605
+ * @Author: zhiwei.Wang
606
+ */
607
+ export var formatDefaultCapacitys = function formatDefaultCapacitys(_ref6) {
608
+ var capacity = _ref6.capacity,
609
+ product_bundle = _ref6.product_bundle;
610
+ if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'package') {
611
+ return (product_bundle || []).map(function (d) {
612
+ var id = d.bundle_product_id;
613
+ var item = ((capacity === null || capacity === void 0 ? void 0 : capacity.package) || []).find(function (item) {
614
+ return item.product_id === id;
615
+ });
616
+ return {
617
+ id: id,
618
+ value: item ? d.num || 0 : 0,
619
+ name: (item === null || item === void 0 ? void 0 : item.name) || (d === null || d === void 0 ? void 0 : d.title)
620
+ };
621
+ });
622
+ }
623
+ if ((capacity === null || capacity === void 0 ? void 0 : capacity.type) === 'custom') {
624
+ return ((capacity === null || capacity === void 0 ? void 0 : capacity.custom) || []).map(function (d) {
625
+ return {
626
+ id: d.id,
627
+ value: d.min,
628
+ name: d.name
629
+ };
630
+ });
631
+ }
632
+
633
+ // 默认为1
634
+ return [{
635
+ id: 0,
636
+ value: 1,
637
+ name: ''
638
+ }];
639
+ };
640
+
641
+ /**
642
+ * @title: 获取总容量
643
+ * @description:
644
+ * @param {object} capacity 为 formatDefaultCapacitys()的结果
645
+ * @return {*}
646
+ * @Author: zhiwei.Wang
647
+ */
648
+ export var getSumCapacity = function getSumCapacity(_ref7) {
649
+ var capacity = _ref7.capacity;
650
+ var sum = 0;
651
+ var _iterator2 = _createForOfIteratorHelper(capacity || []),
652
+ _step2;
653
+ try {
654
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
655
+ var item = _step2.value;
656
+ sum += item.value;
657
+ }
658
+ } catch (err) {
659
+ _iterator2.e(err);
660
+ } finally {
661
+ _iterator2.f();
662
+ }
663
+ return sum;
664
+ };
665
+
666
+ /**
667
+ * @title: 传入资源,如果有子资源,会根据组合资源的 capacity 计算修改子资源的 capacity
668
+ * @description:
669
+ * @param {object} resource
670
+ * @return {*}
671
+ * @Author: jinglin.tan
672
+ */
673
+ export var checkSubResourcesCapacity = function checkSubResourcesCapacity(resource) {
674
+ if (resource.children && resource.children.length) {
675
+ var countCapacity = resource.capacity; // 100
676
+ resource.children.forEach(function (child, index) {
677
+ if (index === resource.children.length - 1) {
678
+ // 如果是最后一个资源,直接拿剩余未分配完的容量去占用
679
+ // 哪怕这个东西会超过资源本身的 capacity也得让他占,PRD 里有写
680
+ child.capacity = countCapacity;
681
+ return;
682
+ }
683
+ if (child.capacity <= countCapacity) {
684
+ countCapacity -= child.capacity; // 100 - = 90
685
+ } else {
686
+ child.capacity = countCapacity; // 10
687
+ countCapacity = 0; // 0
688
+ }
689
+ });
690
+ }
450
691
  };
@@ -1,7 +1,7 @@
1
- import { Module, PisellCore } from "../../types";
2
- import { BaseModule } from "../../modules/BaseModule";
3
- import { Customer } from "./types";
4
- import { Discount } from "../../modules/Discount/types";
1
+ import { Module, PisellCore } from '../../types';
2
+ import { BaseModule } from '../../modules/BaseModule';
3
+ import { Customer } from './types';
4
+ import { Discount } from '../../modules/Discount/types';
5
5
  export declare class ShopDiscountImpl extends BaseModule implements Module {
6
6
  protected defaultName: string;
7
7
  protected defaultVersion: string;
@@ -39,8 +39,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
39
39
  _classCallCheck(this, ShopDiscountImpl);
40
40
  _this = _super.call(this, name, version);
41
41
  // 初始化所有必要的状态属性
42
- _defineProperty(_assertThisInitialized(_this), "defaultName", "shopDiscount");
43
- _defineProperty(_assertThisInitialized(_this), "defaultVersion", "1.0.0");
42
+ _defineProperty(_assertThisInitialized(_this), "defaultName", 'shopDiscount');
43
+ _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
44
44
  _defineProperty(_assertThisInitialized(_this), "isSolution", true);
45
45
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
46
46
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
@@ -66,7 +66,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
66
66
  this.core = core;
67
67
  this.options = options;
68
68
  this.store = _objectSpread(_objectSpread({}, this.store), options.store || {});
69
- console.log("[ShopDiscount] 初始化完成");
69
+ console.log('[ShopDiscount] 初始化完成');
70
70
 
71
71
  // 获取依赖的插件
72
72
  this.initializePlugins();
@@ -103,7 +103,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
103
103
  _context2.next = 7;
104
104
  return this.core.effects.emit(ShopDiscountHooks.onDestroy, {});
105
105
  case 7:
106
- console.log("[ShopDiscount] 已销毁");
106
+ console.log('[ShopDiscount] 已销毁');
107
107
  case 8:
108
108
  case "end":
109
109
  return _context2.stop();
@@ -127,7 +127,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
127
127
  this.store.customer = null;
128
128
  (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 || _this$store$discount2.clear();
129
129
  (_this$store$rules2 = this.store.rules) === null || _this$store$rules2 === void 0 || _this$store$rules2.clear();
130
- console.log("[ShopDiscount] clear");
130
+ console.log('[ShopDiscount] clear');
131
131
  case 5:
132
132
  case "end":
133
133
  return _context3.stop();
@@ -142,13 +142,13 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
142
142
  }, {
143
143
  key: "initializePlugins",
144
144
  value: function initializePlugins() {
145
- this.request = this.core.getPlugin("request");
146
- this.window = this.core.getPlugin("window");
145
+ this.request = this.core.getPlugin('request');
146
+ this.window = this.core.getPlugin('window');
147
147
  if (!this.request) {
148
- throw new Error("ShopDiscount需要 request 插件支持");
148
+ throw new Error('ShopDiscount需要 request 插件支持');
149
149
  }
150
150
  if (!this.window) {
151
- throw new Error("ShopDiscount需要 window 插件支持");
151
+ throw new Error('ShopDiscount需要 window 插件支持');
152
152
  }
153
153
  }
154
154
  }, {
@@ -196,7 +196,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
196
196
  }
197
197
  _this2.loadPrepareConfig({
198
198
  customerId: customer.id,
199
- action: "create",
199
+ action: 'create',
200
200
  with_good_pass: 1
201
201
  });
202
202
  });
@@ -363,7 +363,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
363
363
  case 21:
364
364
  _context5.prev = 21;
365
365
  _context5.t1 = _context5["catch"](0);
366
- console.error("[ShopDiscount] 扫码出错:", _context5.t1);
366
+ console.error('[ShopDiscount] 扫码出错:', _context5.t1);
367
367
  return _context5.abrupt("return", {
368
368
  isAvailable: false,
369
369
  productList: this.store.productList || [],
@@ -453,7 +453,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
453
453
  });
454
454
  var newDiscountList = uniqueById([].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
455
455
  return !item.isDisabled;
456
- }))), "product_id");
456
+ }))), 'product_id');
457
457
  (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
458
458
  this.emitDiscountListChange(newDiscountList);
459
459
  return newDiscountList;
@@ -479,7 +479,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
479
479
  _context7.prev = 0;
480
480
  _context7.next = 3;
481
481
  return this.request.get("/customer/info/wallet/".concat(id), {
482
- wallet_pass_tags: ["good_pass"]
482
+ wallet_pass_tags: ['good_pass']
483
483
  });
484
484
  case 3:
485
485
  result = _context7.sent;
@@ -492,7 +492,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
492
492
  case 7:
493
493
  _context7.prev = 7;
494
494
  _context7.t0 = _context7["catch"](0);
495
- console.error("[ShopDiscount] 获取客户钱包信息出错:", _context7.t0);
495
+ console.error('[ShopDiscount] 获取客户钱包信息出错:', _context7.t0);
496
496
  case 10:
497
497
  case "end":
498
498
  return _context7.stop();
@@ -519,7 +519,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
519
519
  _context8.next = 4;
520
520
  return (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.loadPrepareConfig({
521
521
  customer_id: customerId,
522
- action: "create",
522
+ action: 'create',
523
523
  with_good_pass: 1
524
524
  });
525
525
  case 4:
@@ -545,7 +545,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
545
545
  case 16:
546
546
  _context8.prev = 16;
547
547
  _context8.t0 = _context8["catch"](0);
548
- console.error("[ShopDiscount] 加载准备配置出错:", _context8.t0);
548
+ console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
549
549
  case 19:
550
550
  case "end":
551
551
  return _context8.stop();
@@ -1,5 +1,5 @@
1
- import { DiscountModule } from "../../modules/Discount";
2
- import { RulesModule } from "../../modules/Rules";
1
+ import { DiscountModule } from '../../modules/Discount';
2
+ import { RulesModule } from '../../modules/Rules';
3
3
  export declare enum ShopDiscountHooks {
4
4
  onInited = "shopDiscount:onInited",
5
5
  onDestroy = "shopDiscount:onDestroy",
@@ -1,5 +1,5 @@
1
1
  export var uniqueById = function uniqueById(arr) {
2
- var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "id";
2
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
3
3
  var seen = new Set();
4
4
  return arr.filter(function (item) {
5
5
  return !seen.has(item[key]) && seen.add(item[key]);
package/lib/core/index.js CHANGED
@@ -116,7 +116,9 @@ var PisellOSCore = class {
116
116
  if (options == null ? void 0 : options.plugins) {
117
117
  for (const plugin of options.plugins) {
118
118
  if (!this.plugins.has(plugin)) {
119
- throw new Error(`注册模块 ${module2.name} 失败:缺少依赖插件 ${plugin}`);
119
+ throw new Error(
120
+ `注册模块 ${module2.name} 失败:缺少依赖插件 ${plugin}`
121
+ );
120
122
  }
121
123
  }
122
124
  }
@@ -193,7 +195,10 @@ var PisellOSCore = class {
193
195
  for (const rule of config.validations) {
194
196
  const value = this.context[rule.name];
195
197
  if (rule.required && (value === void 0 || value === null)) {
196
- this.log(`模块 ${config.name} 缺少必需的上下文参数: ${rule.name}`, "error");
198
+ this.log(
199
+ `模块 ${config.name} 缺少必需的上下文参数: ${rule.name}`,
200
+ "error"
201
+ );
197
202
  return false;
198
203
  }
199
204
  if (rule.validate && value !== void 0 && value !== null) {