@pisell/pisellos 2.1.44 → 2.1.45

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.
@@ -140,17 +140,16 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
140
140
  productsData = _context3.sent;
141
141
  sortedList = (productsData.data.list || []).slice().sort(function (a, b) {
142
142
  return Number(b.sort) - Number(a.sort);
143
- });
144
- if (sortedList.length) {
145
- sortedList.forEach(function (n) {
146
- if (n.is_eject !== 1 && n['schedule.ids'] && n['schedule.ids'].length) {
147
- n.is_eject = 1;
148
- }
149
- });
150
- }
143
+ }); // if (sortedList.length) {
144
+ // sortedList.forEach((n: any) => {
145
+ // if (n.is_eject !== 1 && n['schedule.ids'] && n['schedule.ids'].length) {
146
+ // n.is_eject = 1
147
+ // }
148
+ // })
149
+ // }
151
150
  this.addProduct(sortedList);
152
151
  return _context3.abrupt("return", sortedList);
153
- case 11:
152
+ case 10:
154
153
  case "end":
155
154
  return _context3.stop();
156
155
  }
@@ -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 { 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();
@@ -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
  };
@@ -103,13 +103,6 @@ var ProductList = class extends import_BaseModule.BaseModule {
103
103
  { useCache: true }
104
104
  );
105
105
  const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
106
- if (sortedList.length) {
107
- sortedList.forEach((n) => {
108
- if (n.is_eject !== 1 && n["schedule.ids"] && n["schedule.ids"].length) {
109
- n.is_eject = 1;
110
- }
111
- });
112
- }
113
106
  this.addProduct(sortedList);
114
107
  return sortedList;
115
108
  }
@@ -185,13 +185,19 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
185
185
  collection = [],
186
186
  schedule_date
187
187
  }) {
188
- return this.store.products.loadProducts({
188
+ const res = await this.store.products.loadProducts({
189
189
  category_ids,
190
190
  product_ids,
191
191
  collection,
192
192
  schedule_date,
193
193
  cacheId: this.cacheId
194
194
  });
195
+ this.getAvailableDate({
196
+ startDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
197
+ endDate: schedule_date || (0, import_dayjs.default)().format("YYYY-MM-DD"),
198
+ products: [...res]
199
+ });
200
+ return res;
195
201
  }
196
202
  /**
197
203
  * 通过 schedule 来读取商品,适用于 session 类商品
@@ -228,11 +234,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
228
234
  const allProductIds = [...newProductIds, ...otherProductsIds].filter(
229
235
  (n, index, self) => self.indexOf(n) === index
230
236
  );
231
- return await this.loadProducts({
237
+ const res = await this.loadProducts({
232
238
  product_ids: allProductIds,
233
239
  category_ids,
234
240
  schedule_date: date
235
241
  });
242
+ return res;
236
243
  }
237
244
  /**
238
245
  * 更新完商品数据、切换日期、或者在较后的流程里登录了,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
@@ -599,6 +606,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
599
606
  quantity = 1
600
607
  } = product || {};
601
608
  const productData = { ...origin, product_variant_id };
609
+ debugger;
610
+ if ((0, import_products.isSessionProduct)(productData)) {
611
+ if (!date || !date.startTime || !date.endTime) {
612
+ return { success: false, errorCode: "date_or_time_required" };
613
+ }
614
+ }
602
615
  const currentCartItems = this.store.cart.getItems();
603
616
  const stockCheckResult = (0, import_stock.checkProductStock)({
604
617
  productData,
@@ -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
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.44",
4
+ "version": "2.1.45",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",