@pisell/pisellos 3.0.80 → 3.0.82

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.
@@ -31,7 +31,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
31
31
  import { BaseModule } from "../../modules/BaseModule";
32
32
  import { BookingByStepHooks, createModule } from "./types";
33
33
  import { formatProductToCartItem, createCartItemOrigin, getUniqueId, handleVariantProduct, formatDateToCartItem, formatAccountToCartItem } from "../../modules/Cart/utils";
34
- import { getAvailableProductResources } from "./utils/products";
34
+ import { getAvailableProductResources, isSessionProduct } from "./utils/products";
35
35
  import { getResourcesByProduct, getTimeSlicesByResource, getTimeSlicesByResources, getIsUsableByTimeItem, getOthersSelectedResources, getOthersCartSelectedResources, filterScheduleByDateRange, checkSessionProductLeadTime, sortCombinedResources, filterResourcesByFormItem, checkTwoResourcesIntersection, isConflict } from "./utils/resources";
36
36
  import dayjs from 'dayjs';
37
37
  import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
@@ -238,19 +238,29 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
238
238
  key: "loadProducts",
239
239
  value: (function () {
240
240
  var _loadProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
241
- var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date;
241
+ var _ref$category_ids, category_ids, _ref$product_ids, product_ids, _ref$collection, collection, schedule_date, res;
242
242
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
243
243
  while (1) switch (_context2.prev = _context2.next) {
244
244
  case 0:
245
245
  _ref$category_ids = _ref.category_ids, category_ids = _ref$category_ids === void 0 ? [] : _ref$category_ids, _ref$product_ids = _ref.product_ids, product_ids = _ref$product_ids === void 0 ? [] : _ref$product_ids, _ref$collection = _ref.collection, collection = _ref$collection === void 0 ? [] : _ref$collection, schedule_date = _ref.schedule_date;
246
- return _context2.abrupt("return", this.store.products.loadProducts({
246
+ _context2.next = 3;
247
+ return this.store.products.loadProducts({
247
248
  category_ids: category_ids,
248
249
  product_ids: product_ids,
249
250
  collection: collection,
250
251
  schedule_date: schedule_date,
251
252
  cacheId: this.cacheId
252
- }));
253
- case 2:
253
+ });
254
+ case 3:
255
+ res = _context2.sent;
256
+ // 预拉取当天的资源数据
257
+ this.getAvailableDate({
258
+ startDate: schedule_date || dayjs().format('YYYY-MM-DD'),
259
+ endDate: schedule_date || dayjs().format('YYYY-MM-DD'),
260
+ products: _toConsumableArray(res)
261
+ });
262
+ return _context2.abrupt("return", res);
263
+ case 6:
254
264
  case "end":
255
265
  return _context2.stop();
256
266
  }
@@ -282,7 +292,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
282
292
  value: (function () {
283
293
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
284
294
  var _schedule$product_ids;
285
- var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, newProductIds, schedule, otherProductsIds, allProductIds;
295
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, newProductIds, schedule, otherProductsIds, allProductIds, res;
286
296
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
287
297
  while (1) switch (_context3.prev = _context3.next) {
288
298
  case 0:
@@ -329,8 +339,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
329
339
  schedule_date: date
330
340
  });
331
341
  case 10:
332
- return _context3.abrupt("return", _context3.sent);
333
- case 11:
342
+ res = _context3.sent;
343
+ return _context3.abrupt("return", res);
344
+ case 12:
334
345
  case "end":
335
346
  return _context3.stop();
336
347
  }
@@ -1150,6 +1161,16 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1150
1161
  var productData = _objectSpread(_objectSpread({}, origin), {}, {
1151
1162
  product_variant_id: product_variant_id
1152
1163
  });
1164
+ debugger;
1165
+ // 保护,如果进来的是 session 商品,则必须要有 date 和时间片,否则不允许添加
1166
+ if (isSessionProduct(productData)) {
1167
+ if (!date || !date.startTime || !date.endTime) {
1168
+ return {
1169
+ success: false,
1170
+ errorCode: 'date_or_time_required'
1171
+ };
1172
+ }
1173
+ }
1153
1174
 
1154
1175
  // 库存检测
1155
1176
  var currentCartItems = this.store.cart.getItems();
@@ -1787,7 +1808,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1787
1808
  timeSlots: timeSlots,
1788
1809
  currentCapacity: totalCapacity + (capacity || 0)
1789
1810
  });
1790
- if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1811
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime && n.capacity >= (capacity || 0)) {
1791
1812
  targetResource = n;
1792
1813
  targetResourceTime = currentResourceIdleTime;
1793
1814
  return 1; // break
@@ -2182,6 +2203,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2182
2203
  // 计算容量的辅助函数
2183
2204
  var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2184
2205
  var _items$0$_resourceOri;
2206
+ if (items.length === 0) return 0;
2185
2207
  // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
2186
2208
  var firstResource = (_items$0$_resourceOri = items[0]._resourceOrigin) === null || _items$0$_resourceOri === void 0 ? void 0 : _items$0$_resourceOri[0].id;
2187
2209
  var sameResourceLength = items.filter(function (item) {
@@ -2356,6 +2378,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2356
2378
  // 计算容量的辅助函数
2357
2379
  calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2358
2380
  var _items$0$_resourceOri2;
2381
+ if (items.length === 0) return 0;
2359
2382
  // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
2360
2383
  var firstResource = (_items$0$_resourceOri2 = items[0]._resourceOrigin) === null || _items$0$_resourceOri2 === void 0 ? void 0 : _items$0$_resourceOri2[0].id;
2361
2384
  var sameResourceLength = items.filter(function (item) {
@@ -9,3 +9,9 @@ export declare const getAvailableProductResources: (products: ProductData[]) =>
9
9
  rules: any[];
10
10
  resourcesMap: Record<number, ProductResourceItem>;
11
11
  };
12
+ /**
13
+ * 判断商品是否是 session 商品
14
+ * @param product 商品数据
15
+ * @returns 是否是 session 商品
16
+ */
17
+ export declare const isSessionProduct: (product: ProductData) => boolean;
@@ -47,4 +47,14 @@ export var getAvailableProductResources = function getAvailableProductResources(
47
47
  rules: rules,
48
48
  resourcesMap: resourcesMap
49
49
  };
50
+ };
51
+
52
+ /**
53
+ * 判断商品是否是 session 商品
54
+ * @param product 商品数据
55
+ * @returns 是否是 session 商品
56
+ */
57
+ export var isSessionProduct = function isSessionProduct(product) {
58
+ var _product$scheduleIds, _product$scheduleIds2;
59
+ return ((_product$scheduleIds = product === null || product === void 0 || (_product$scheduleIds2 = product['schedule.ids']) === null || _product$scheduleIds2 === void 0 ? void 0 : _product$scheduleIds2.length) !== null && _product$scheduleIds !== void 0 ? _product$scheduleIds : 0) > 0;
50
60
  };
@@ -349,7 +349,8 @@ export var getResourcesByProduct = function getResourcesByProduct(resourcesMap,
349
349
  return dayjs(current.end_at).isAfter(dayjs(latest.end_at)) ? current : latest;
350
350
  }, d.times[0]);
351
351
  // TODO,在这拉时间切片出来,如果可用 timeSlots.length > 1 才可以被选择
352
- return dayjs(latestTime.end_at).isAfter(dayjs());
352
+ // 当前资源的配置容量需要大于当前需求的 capacity
353
+ return dayjs(latestTime.end_at).isAfter(dayjs()) && d.capacity >= capacity;
353
354
  });
354
355
  item.form_id = form_id;
355
356
  acc.push(item);
@@ -186,13 +186,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
186
186
  collection = [],
187
187
  schedule_date
188
188
  }) {
189
- return this.store.products.loadProducts({
189
+ const res = await this.store.products.loadProducts({
190
190
  category_ids,
191
191
  product_ids,
192
192
  collection,
193
193
  schedule_date,
194
194
  cacheId: this.cacheId
195
195
  });
196
+ this.getAvailableDate({
197
+ startDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
198
+ endDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
199
+ products: [...res]
200
+ });
201
+ return res;
196
202
  }
197
203
  /**
198
204
  * 通过 schedule 来读取商品,适用于 session 类商品
@@ -229,11 +235,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
229
235
  const allProductIds = [...newProductIds, ...otherProductsIds].filter(
230
236
  (n, index, self) => self.indexOf(n) === index
231
237
  );
232
- return await this.loadProducts({
238
+ const res = await this.loadProducts({
233
239
  product_ids: allProductIds,
234
240
  category_ids,
235
241
  schedule_date: date
236
242
  });
243
+ return res;
237
244
  }
238
245
  /**
239
246
  * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
@@ -600,6 +607,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
600
607
  quantity = 1
601
608
  } = product || {};
602
609
  const productData = { ...origin, product_variant_id };
610
+ debugger;
611
+ if ((0, import_products.isSessionProduct)(productData)) {
612
+ if (!date || !date.startTime || !date.endTime) {
613
+ return { success: false, errorCode: "date_or_time_required" };
614
+ }
615
+ }
603
616
  const currentCartItems = this.store.cart.getItems();
604
617
  const stockCheckResult = (0, import_stock.checkProductStock)({
605
618
  productData,
@@ -1167,7 +1180,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1167
1180
  timeSlots,
1168
1181
  currentCapacity: totalCapacity + (capacity || 0)
1169
1182
  });
1170
- if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime) {
1183
+ if (canUseTime && !n.onlyComputed && currentResourceIdleTime > targetResourceTime && n.capacity >= (capacity || 0)) {
1171
1184
  targetResource = n;
1172
1185
  targetResourceTime = currentResourceIdleTime;
1173
1186
  break;
@@ -1519,6 +1532,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1519
1532
  }
1520
1533
  const calculateCapacityFromCartItems = (items) => {
1521
1534
  var _a2;
1535
+ if (items.length === 0)
1536
+ return 0;
1522
1537
  const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
1523
1538
  const sameResourceLength = items.filter((item) => {
1524
1539
  var _a3;
@@ -1652,6 +1667,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1652
1667
  }
1653
1668
  const calculateCapacityFromCartItems = (items) => {
1654
1669
  var _a2;
1670
+ if (items.length === 0)
1671
+ return 0;
1655
1672
  const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
1656
1673
  const sameResourceLength = items.filter((item) => {
1657
1674
  var _a3;
@@ -9,3 +9,9 @@ export declare const getAvailableProductResources: (products: ProductData[]) =>
9
9
  rules: any[];
10
10
  resourcesMap: Record<number, ProductResourceItem>;
11
11
  };
12
+ /**
13
+ * 判断商品是否是 session 商品
14
+ * @param product 商品数据
15
+ * @returns 是否是 session 商品
16
+ */
17
+ export declare const isSessionProduct: (product: ProductData) => boolean;
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/solution/BookingByStep/utils/products.ts
20
20
  var products_exports = {};
21
21
  __export(products_exports, {
22
- getAvailableProductResources: () => getAvailableProductResources
22
+ getAvailableProductResources: () => getAvailableProductResources,
23
+ isSessionProduct: () => isSessionProduct
23
24
  });
24
25
  module.exports = __toCommonJS(products_exports);
25
26
  var getAvailableProductResources = (products) => {
@@ -57,7 +58,12 @@ var getAvailableProductResources = (products) => {
57
58
  });
58
59
  return { resourceIds: [...new Set(resourceIds)], rules, resourcesMap };
59
60
  };
61
+ var isSessionProduct = (product) => {
62
+ var _a;
63
+ return (((_a = product == null ? void 0 : product["schedule.ids"]) == null ? void 0 : _a.length) ?? 0) > 0;
64
+ };
60
65
  // Annotate the CommonJS export names for ESM import in node:
61
66
  0 && (module.exports = {
62
- getAvailableProductResources
67
+ getAvailableProductResources,
68
+ isSessionProduct
63
69
  });
@@ -298,7 +298,7 @@ var getResourcesByProduct = (resourcesMap, resources, selectedResources, capacit
298
298
  const latestTime = d.times.reduce((latest, current) => {
299
299
  return (0, import_dayjs.default)(current.end_at).isAfter((0, import_dayjs.default)(latest.end_at)) ? current : latest;
300
300
  }, d.times[0]);
301
- return (0, import_dayjs.default)(latestTime.end_at).isAfter((0, import_dayjs.default)());
301
+ return (0, import_dayjs.default)(latestTime.end_at).isAfter((0, import_dayjs.default)()) && d.capacity >= capacity;
302
302
  });
303
303
  item.form_id = form_id;
304
304
  acc.push(item);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.80",
4
+ "version": "3.0.82",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",