@pisell/pisellos 3.0.28 → 3.0.29

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.
@@ -7,9 +7,16 @@ export declare class ProductList extends BaseModule implements Module {
7
7
  protected defaultName: string;
8
8
  protected defaultVersion: string;
9
9
  private store;
10
+ private request;
10
11
  constructor(name?: string, version?: string);
11
12
  initialize(core: PisellCore, options: any): Promise<void>;
12
13
  storeChange(path?: string, value?: any): Promise<void>;
14
+ loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
15
+ ids?: number[];
16
+ customer_id?: number;
17
+ schedule_date?: string;
18
+ channel?: string;
19
+ }): Promise<any>;
13
20
  getProducts(): Promise<ProductData[]>;
14
21
  getProduct(id: number): Promise<Product | undefined>;
15
22
  addProduct(products: ProductData[]): Promise<void>;
@@ -30,6 +30,7 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
30
30
  _defineProperty(_assertThisInitialized(_this), "defaultName", 'productList');
31
31
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
32
32
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
33
+ _defineProperty(_assertThisInitialized(_this), "request", void 0);
33
34
  return _this;
34
35
  }
35
36
  _createClass(ProductList, [{
@@ -51,7 +52,8 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
51
52
  this.store.productMap = new Map();
52
53
  this.store.selectProducts = [];
53
54
  }
54
- case 3:
55
+ this.request = core.getPlugin('request');
56
+ case 4:
55
57
  case "end":
56
58
  return _context.stop();
57
59
  }
@@ -95,22 +97,54 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
95
97
  return storeChange;
96
98
  }()
97
99
  }, {
98
- key: "getProducts",
100
+ key: "loadProductsPrice",
99
101
  value: function () {
100
- var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
102
+ var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref) {
103
+ var _ref$ids, ids, customer_id, schedule_date, channel, productsData;
101
104
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
102
105
  while (1) switch (_context3.prev = _context3.next) {
103
106
  case 0:
104
- _context3.next = 2;
105
- return this.core.effects.emit(ProductListHooks.onGetProducts, this.store.list);
106
- case 2:
107
- return _context3.abrupt("return", cloneDeep(this.store.list));
107
+ _ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, customer_id = _ref.customer_id, schedule_date = _ref.schedule_date, channel = _ref.channel;
108
+ _context3.next = 3;
109
+ return this.request.post("/product/query/price", {
110
+ ids: ids,
111
+ customer_id: customer_id,
112
+ schedule_date: schedule_date,
113
+ channel: channel
114
+ }, {
115
+ useCache: true
116
+ });
108
117
  case 3:
118
+ productsData = _context3.sent;
119
+ return _context3.abrupt("return", productsData.data);
120
+ case 5:
109
121
  case "end":
110
122
  return _context3.stop();
111
123
  }
112
124
  }, _callee3, this);
113
125
  }));
126
+ function loadProductsPrice(_x5) {
127
+ return _loadProductsPrice.apply(this, arguments);
128
+ }
129
+ return loadProductsPrice;
130
+ }()
131
+ }, {
132
+ key: "getProducts",
133
+ value: function () {
134
+ var _getProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
135
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
136
+ while (1) switch (_context4.prev = _context4.next) {
137
+ case 0:
138
+ _context4.next = 2;
139
+ return this.core.effects.emit(ProductListHooks.onGetProducts, this.store.list);
140
+ case 2:
141
+ return _context4.abrupt("return", cloneDeep(this.store.list));
142
+ case 3:
143
+ case "end":
144
+ return _context4.stop();
145
+ }
146
+ }, _callee4, this);
147
+ }));
114
148
  function getProducts() {
115
149
  return _getProducts.apply(this, arguments);
116
150
  }
@@ -119,29 +153,29 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
119
153
  }, {
120
154
  key: "getProduct",
121
155
  value: function () {
122
- var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(id) {
156
+ var _getProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
123
157
  var product;
124
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
125
- while (1) switch (_context4.prev = _context4.next) {
158
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
159
+ while (1) switch (_context5.prev = _context5.next) {
126
160
  case 0:
127
- _context4.next = 2;
161
+ _context5.next = 2;
128
162
  return this.core.effects.emit(ProductListHooks.onGetProduct, this.store.list);
129
163
  case 2:
130
164
  product = this.store.productMap.get("".concat(id));
131
165
  if (!product) {
132
- _context4.next = 5;
166
+ _context5.next = 5;
133
167
  break;
134
168
  }
135
- return _context4.abrupt("return", product);
169
+ return _context5.abrupt("return", product);
136
170
  case 5:
137
- return _context4.abrupt("return", undefined);
171
+ return _context5.abrupt("return", undefined);
138
172
  case 6:
139
173
  case "end":
140
- return _context4.stop();
174
+ return _context5.stop();
141
175
  }
142
- }, _callee4, this);
176
+ }, _callee5, this);
143
177
  }));
144
- function getProduct(_x5) {
178
+ function getProduct(_x6) {
145
179
  return _getProduct.apply(this, arguments);
146
180
  }
147
181
  return getProduct;
@@ -149,10 +183,10 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
149
183
  }, {
150
184
  key: "addProduct",
151
185
  value: function () {
152
- var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(products) {
186
+ var _addProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(products) {
153
187
  var _this3 = this;
154
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
155
- while (1) switch (_context5.prev = _context5.next) {
188
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
189
+ while (1) switch (_context6.prev = _context6.next) {
156
190
  case 0:
157
191
  // 加到 list 以后上面的storeChange 会自动初始化商品详情的 module 实例
158
192
  // list 需要根据 id 去重
@@ -172,11 +206,11 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
172
206
  this.storeChange();
173
207
  case 3:
174
208
  case "end":
175
- return _context5.stop();
209
+ return _context6.stop();
176
210
  }
177
- }, _callee5, this);
211
+ }, _callee6, this);
178
212
  }));
179
- function addProduct(_x6) {
213
+ function addProduct(_x7) {
180
214
  return _addProduct.apply(this, arguments);
181
215
  }
182
216
  return addProduct;
@@ -184,18 +218,18 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
184
218
  }, {
185
219
  key: "selectProducts",
186
220
  value: function () {
187
- var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(products) {
188
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
189
- while (1) switch (_context6.prev = _context6.next) {
221
+ var _selectProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(products) {
222
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
223
+ while (1) switch (_context7.prev = _context7.next) {
190
224
  case 0:
191
225
  this.store.selectProducts = products;
192
226
  case 1:
193
227
  case "end":
194
- return _context6.stop();
228
+ return _context7.stop();
195
229
  }
196
- }, _callee6, this);
230
+ }, _callee7, this);
197
231
  }));
198
- function selectProducts(_x7) {
232
+ function selectProducts(_x8) {
199
233
  return _selectProducts.apply(this, arguments);
200
234
  }
201
235
  return selectProducts;
@@ -186,10 +186,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
186
186
  private getScheduleDataByIds;
187
187
  openProductDetail(productId: number): Promise<void>;
188
188
  closeProductDetail(): void;
189
- getTimeslotBySchedule({ date, scheduleIds, resources, }: {
189
+ getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
190
190
  date: string;
191
191
  scheduleIds?: number[];
192
192
  resources?: ProductResourceItem[];
193
+ product?: ProductData;
193
194
  }): {
194
195
  start_time: string;
195
196
  end_time: string;
@@ -313,64 +313,62 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
313
313
  key: "updateQuotationPriceAndCart",
314
314
  value: function () {
315
315
  var _updateQuotationPriceAndCart = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(date) {
316
- var _this$otherParams3,
317
- _this3 = this;
318
- var dateRange, scheduleList, scheduleIds, cartItems, _iterator, _step, _loop;
316
+ var _this3 = this;
317
+ var cartItems, userPlugin, customer_id, _userPlugin$get2, res, _iterator, _step, _loop;
319
318
  return _regeneratorRuntime().wrap(function _callee4$(_context5) {
320
319
  while (1) switch (_context5.prev = _context5.next) {
321
320
  case 0:
322
- dateRange = this.store.date.getDateRange();
323
- scheduleList = this.store.schedule.getAvailabilityScheduleDateList() || [];
324
- scheduleIds = [];
325
- if (dateRange && dateRange.length) {
326
- scheduleIds = scheduleList.filter(function (n) {
327
- return n.date === dateRange[0].date;
328
- }).flatMap(function (n) {
329
- return n.schedule_id;
330
- });
331
- } else {
332
- scheduleIds = scheduleList.filter(function (n) {
333
- return n.date === date;
334
- }).flatMap(function (n) {
335
- return n.schedule_id;
336
- });
337
- }
338
- _context5.next = 6;
339
- return this.loadProducts(_objectSpread(_objectSpread({}, (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.productModuleParams), {}, {
340
- scheduleIds: scheduleIds,
341
- schedule_date: date
342
- }));
343
- case 6:
344
321
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
345
322
  cartItems = this.store.cart.getItems();
346
323
  if (!cartItems.length) {
347
324
  _context5.next = 25;
348
325
  break;
349
326
  }
327
+ userPlugin = this.core.getPlugin('user');
328
+ customer_id = undefined;
329
+ try {
330
+ customer_id = userPlugin === null || userPlugin === void 0 || (_userPlugin$get2 = userPlugin.get()) === null || _userPlugin$get2 === void 0 ? void 0 : _userPlugin$get2.id;
331
+ } catch (error) {
332
+ console.error(error);
333
+ }
334
+ _context5.next = 7;
335
+ return this.store.products.loadProductsPrice({
336
+ ids: cartItems.map(function (n) {
337
+ return n.id;
338
+ }),
339
+ schedule_date: date,
340
+ customer_id: customer_id
341
+ });
342
+ case 7:
343
+ res = _context5.sent;
350
344
  _iterator = _createForOfIteratorHelper(cartItems);
351
345
  _context5.prev = 9;
352
346
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
353
347
  var _bundle;
354
- var item, targetProduct, productInfo, bundle;
348
+ var item, targetProduct, cartProduct, productInfo, bundle;
355
349
  return _regeneratorRuntime().wrap(function _loop$(_context4) {
356
350
  while (1) switch (_context4.prev = _context4.next) {
357
351
  case 0:
358
352
  item = _step.value;
359
- _context4.next = 3;
353
+ targetProduct = res.find(function (n) {
354
+ return n.id === item.id;
355
+ });
356
+ _context4.next = 4;
360
357
  return _this3.store.products.getProduct(item.id);
361
- case 3:
362
- targetProduct = _context4.sent;
363
- productInfo = cloneDeep(targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
358
+ case 4:
359
+ cartProduct = _context4.sent;
360
+ productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
364
361
  bundle = item._bundleOrigin;
362
+ productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
363
+ productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
365
364
  bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
366
- var _productInfo$bundle;
367
- // 尝试到新的 productInfo 里找对应的 bundleitem
368
- // 然后更新 bundle 的价格
369
- var targetBundle = productInfo === null || productInfo === void 0 || (_productInfo$bundle = productInfo.bundle) === null || _productInfo$bundle === void 0 ? void 0 : _productInfo$bundle.find(function (m) {
370
- return m.group_id === n.id;
365
+ var _targetProduct$bundle;
366
+ // 更新 bundle 的价格
367
+ var targetBundle = targetProduct === null || targetProduct === void 0 || (_targetProduct$bundle = targetProduct.bundle_group) === null || _targetProduct$bundle === void 0 ? void 0 : _targetProduct$bundle.find(function (m) {
368
+ return m.id === n.group_id;
371
369
  });
372
370
  if (targetBundle) {
373
- var targetBundleItem = targetBundle.items.find(function (m) {
371
+ var targetBundleItem = targetBundle.bundle_item.find(function (m) {
374
372
  return m.id === n.id;
375
373
  });
376
374
  if (targetBundleItem) {
@@ -387,7 +385,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
387
385
  product: productInfo,
388
386
  bundle: bundle
389
387
  });
390
- case 8:
388
+ case 11:
391
389
  case "end":
392
390
  return _context4.stop();
393
391
  }
@@ -2069,9 +2067,14 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2069
2067
  var resourceIds = [];
2070
2068
  var resourcesTypeId = undefined;
2071
2069
  var isSingleResource = false;
2070
+
2071
+ // 找出购物车里最大的 cut_off_time
2072
+ var maxCutOffTime = undefined;
2073
+ var maxCutOffTimeValue = dayjs();
2072
2074
  cartItems.forEach(function (item) {
2073
- var _item$_productOrigin11, _item$_productOrigin12;
2075
+ var _item$_productOrigin11, _item$_productOrigin12, _item$_productOrigin13, _item$_productOrigin14;
2074
2076
  (_item$_productOrigin11 = item._productOrigin) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.product_resource) === null || _item$_productOrigin11 === void 0 || (_item$_productOrigin11 = _item$_productOrigin11.resources) === null || _item$_productOrigin11 === void 0 || _item$_productOrigin11.forEach(function (n) {
2077
+ // TODO: 少了个 status 的判断
2075
2078
  if (n.code === resources_code) {
2076
2079
  resources.push.apply(resources, _toConsumableArray(n.renderList || []));
2077
2080
  isSingleResource = n.type === 'single';
@@ -2086,6 +2089,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2086
2089
  resourcesTypeId = item === null || item === void 0 || (_item$_productOrigin12 = item._productOrigin) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.product_resource) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.resources) === null || _item$_productOrigin12 === void 0 || (_item$_productOrigin12 = _item$_productOrigin12.find(function (n) {
2087
2090
  return n.code === resources_code;
2088
2091
  })) === null || _item$_productOrigin12 === void 0 ? void 0 : _item$_productOrigin12.id;
2092
+ if ((_item$_productOrigin13 = item._productOrigin) !== null && _item$_productOrigin13 !== void 0 && _item$_productOrigin13.cut_off_time && ((_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.cut_off_time.type) === 'advance') {
2093
+ var currentCutOffTime = dayjs().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
2094
+ if (currentCutOffTime.isAfter(maxCutOffTimeValue, 'minute')) {
2095
+ maxCutOffTimeValue = currentCutOffTime;
2096
+ maxCutOffTime = item._productOrigin.cut_off_time;
2097
+ }
2098
+ }
2089
2099
  });
2090
2100
  // 保险起见,在这里如果 dateRange 里也有 resources 的话,也 push 进去
2091
2101
  if ((_dateRange = dateRange) !== null && _dateRange !== void 0 && (_dateRange = _dateRange[0]) !== null && _dateRange !== void 0 && (_dateRange = _dateRange.resource) !== null && _dateRange !== void 0 && _dateRange.length) {
@@ -2107,13 +2117,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2107
2117
  cartItems.forEach(function (item) {
2108
2118
  // 单个预约累加账号 多个预约取最大值
2109
2119
  if (isSingleResource) {
2110
- var _item$_productOrigin$3, _item$_productOrigin13;
2111
- accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin13 = item._productOrigin) === null || _item$_productOrigin13 === void 0 || (_item$_productOrigin13 = _item$_productOrigin13.duration) === null || _item$_productOrigin13 === void 0 ? void 0 : _item$_productOrigin13.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
2120
+ var _item$_productOrigin$3, _item$_productOrigin15;
2121
+ accountDuration += (_item$_productOrigin$3 = (_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.value) !== null && _item$_productOrigin$3 !== void 0 ? _item$_productOrigin$3 : 0;
2112
2122
  } else {
2113
- var _item$_productOrigin$4, _item$_productOrigin14;
2114
- if (accountDuration < ((_item$_productOrigin$4 = (_item$_productOrigin14 = item._productOrigin) === null || _item$_productOrigin14 === void 0 || (_item$_productOrigin14 = _item$_productOrigin14.duration) === null || _item$_productOrigin14 === void 0 ? void 0 : _item$_productOrigin14.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0)) {
2115
- var _item$_productOrigin$5, _item$_productOrigin15;
2116
- accountDuration = (_item$_productOrigin$5 = (_item$_productOrigin15 = item._productOrigin) === null || _item$_productOrigin15 === void 0 || (_item$_productOrigin15 = _item$_productOrigin15.duration) === null || _item$_productOrigin15 === void 0 ? void 0 : _item$_productOrigin15.value) !== null && _item$_productOrigin$5 !== void 0 ? _item$_productOrigin$5 : 0;
2123
+ var _item$_productOrigin$4, _item$_productOrigin16;
2124
+ if (accountDuration < ((_item$_productOrigin$4 = (_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) !== null && _item$_productOrigin$4 !== void 0 ? _item$_productOrigin$4 : 0)) {
2125
+ var _item$_productOrigin$5, _item$_productOrigin17;
2126
+ accountDuration = (_item$_productOrigin$5 = (_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.value) !== null && _item$_productOrigin$5 !== void 0 ? _item$_productOrigin$5 : 0;
2117
2127
  }
2118
2128
  }
2119
2129
  });
@@ -2155,7 +2165,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2155
2165
  duration: duration,
2156
2166
  currentDate: dateRange[0].date,
2157
2167
  split: 10,
2158
- resourcesUseableMap: resourcesUseableMap
2168
+ resourcesUseableMap: resourcesUseableMap,
2169
+ cut_off_time: maxCutOffTime
2159
2170
  });
2160
2171
  return timeSlots;
2161
2172
  }
@@ -2185,9 +2196,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2185
2196
  var _newResources$;
2186
2197
  var newResources = cloneDeep(item._origin.resources);
2187
2198
  newResources.forEach(function (resource) {
2188
- var _item$_productOrigin$6, _item$_productOrigin16, _ref11, _item$_productOrigin17;
2199
+ var _item$_productOrigin$6, _item$_productOrigin18, _ref11, _item$_productOrigin19;
2189
2200
  resource.startTime = currentStartTime;
2190
- resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$6 = (_item$_productOrigin16 = item._productOrigin) === null || _item$_productOrigin16 === void 0 || (_item$_productOrigin16 = _item$_productOrigin16.duration) === null || _item$_productOrigin16 === void 0 ? void 0 : _item$_productOrigin16.value) !== null && _item$_productOrigin$6 !== void 0 ? _item$_productOrigin$6 : 0, (_ref11 = (_item$_productOrigin17 = item._productOrigin) === null || _item$_productOrigin17 === void 0 || (_item$_productOrigin17 = _item$_productOrigin17.duration) === null || _item$_productOrigin17 === void 0 ? void 0 : _item$_productOrigin17.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2201
+ resource.endTime = dayjs(currentStartTime).add((_item$_productOrigin$6 = (_item$_productOrigin18 = item._productOrigin) === null || _item$_productOrigin18 === void 0 || (_item$_productOrigin18 = _item$_productOrigin18.duration) === null || _item$_productOrigin18 === void 0 ? void 0 : _item$_productOrigin18.value) !== null && _item$_productOrigin$6 !== void 0 ? _item$_productOrigin$6 : 0, (_ref11 = (_item$_productOrigin19 = item._productOrigin) === null || _item$_productOrigin19 === void 0 || (_item$_productOrigin19 = _item$_productOrigin19.duration) === null || _item$_productOrigin19 === void 0 ? void 0 : _item$_productOrigin19.type) !== null && _ref11 !== void 0 ? _ref11 : 'minutes').format('YYYY-MM-DD HH:mm');
2191
2202
  delete resource.times;
2192
2203
  });
2193
2204
  _this11.store.cart.updateItem({
@@ -2277,9 +2288,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2277
2288
  var _this$store$currentPr2;
2278
2289
  var date = _ref12.date,
2279
2290
  scheduleIds = _ref12.scheduleIds,
2280
- resources = _ref12.resources;
2291
+ resources = _ref12.resources,
2292
+ product = _ref12.product;
2281
2293
  var targetProduct = this.store.currentProduct;
2282
- var targetProductData = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData();
2294
+ // 如果外面传递了product 优先用外面的
2295
+ var targetProductData = product || (targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.getData());
2283
2296
  var targetSchedules = [];
2284
2297
  // 如果外面传递了 scheduleIds,优先取入参
2285
2298
  if (scheduleIds !== null && scheduleIds !== void 0 && scheduleIds.length) {
@@ -2326,7 +2339,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2326
2339
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2327
2340
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2328
2341
  var mTimes = m.times.filter(function (n) {
2329
- return !dayjs(n.start_at).isAfter(dayjs(item.start)) && !dayjs(n.end_at).isBefore(dayjs(item.end));
2342
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2330
2343
  });
2331
2344
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2332
2345
  if (mTimes.length === 0) {
@@ -79,13 +79,23 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
86
86
  currentDate: DateType | string;
87
87
  capacity?: number | undefined;
88
88
  resourcesUseableMap?: Record<string, boolean> | undefined;
89
+ cut_off_time?: {
90
+ future_day: number;
91
+ unit: number;
92
+ unit_type: string;
93
+ type: string;
94
+ ongoing?: {
95
+ type: string;
96
+ unit: number;
97
+ } | undefined;
98
+ } | undefined;
89
99
  }) => TimeSliceItem[];
90
100
  /**
91
101
  * @title: 获取时间切片列表的交集
@@ -123,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
123
133
  * @return {*}
124
134
  * @Author: zhiwei.Wang
125
135
  */
126
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, }: {
136
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
127
137
  resourceIds: number[];
128
138
  resourcesMap: any;
129
139
  duration: number;
@@ -131,6 +141,16 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
131
141
  split: number;
132
142
  capacity?: number | undefined;
133
143
  resourcesUseableMap: Record<string, boolean>;
144
+ cut_off_time?: {
145
+ future_day: number;
146
+ unit: number;
147
+ unit_type: string;
148
+ type: string;
149
+ ongoing?: {
150
+ type: string;
151
+ unit: number;
152
+ } | undefined;
153
+ } | undefined;
134
154
  }) => any[];
135
155
  /**
136
156
  * @title: 获取其他人的已选资源
@@ -414,7 +414,8 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
414
414
  currentDate = _ref5$currentDate === void 0 ? dayjs() : _ref5$currentDate,
415
415
  capacity = _ref5.capacity,
416
416
  _ref5$resourcesUseabl = _ref5.resourcesUseableMap,
417
- resourcesUseableMap = _ref5$resourcesUseabl === void 0 ? {} : _ref5$resourcesUseabl;
417
+ resourcesUseableMap = _ref5$resourcesUseabl === void 0 ? {} : _ref5$resourcesUseabl,
418
+ cut_off_time = _ref5.cut_off_time;
418
419
  var times = resource.times;
419
420
 
420
421
  // 存储所有时间切片
@@ -452,7 +453,8 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
452
453
  time: time,
453
454
  resource: resource,
454
455
  currentCount: capacity || 1,
455
- resourcesUseableMap: resourcesUseableMap
456
+ resourcesUseableMap: resourcesUseableMap,
457
+ cut_off_time: cut_off_time
456
458
  });
457
459
  if ((resourcesUseableMap === null || resourcesUseableMap === void 0 ? void 0 : resourcesUseableMap[resource.id]) !== false) {
458
460
  resourcesUseableMap[resource.id] = _status.usable;
@@ -562,7 +564,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
562
564
  currentDate = _ref6.currentDate,
563
565
  split = _ref6.split,
564
566
  capacity = _ref6.capacity,
565
- resourcesUseableMap = _ref6.resourcesUseableMap;
567
+ resourcesUseableMap = _ref6.resourcesUseableMap,
568
+ cut_off_time = _ref6.cut_off_time;
566
569
  // 获取资源列表
567
570
  var resources = getResourcesByIds(resourcesMap, resourceIds);
568
571
  mergeSubResourcesTimeSlices(resources, resourcesMap);
@@ -584,7 +587,8 @@ export var getTimeSlicesByResources = function getTimeSlicesByResources(_ref6) {
584
587
  split: split,
585
588
  currentDate: currentDate,
586
589
  capacity: capacity,
587
- resourcesUseableMap: resourcesUseableMap
590
+ resourcesUseableMap: resourcesUseableMap,
591
+ cut_off_time: cut_off_time
588
592
  }));
589
593
  }, []);
590
594
 
@@ -7,9 +7,16 @@ export declare class ProductList extends BaseModule implements Module {
7
7
  protected defaultName: string;
8
8
  protected defaultVersion: string;
9
9
  private store;
10
+ private request;
10
11
  constructor(name?: string, version?: string);
11
12
  initialize(core: PisellCore, options: any): Promise<void>;
12
13
  storeChange(path?: string, value?: any): Promise<void>;
14
+ loadProductsPrice({ ids, customer_id, schedule_date, channel, }: {
15
+ ids?: number[];
16
+ customer_id?: number;
17
+ schedule_date?: string;
18
+ channel?: string;
19
+ }): Promise<any>;
13
20
  getProducts(): Promise<ProductData[]>;
14
21
  getProduct(id: number): Promise<Product | undefined>;
15
22
  addProduct(products: ProductData[]): Promise<void>;
@@ -47,6 +47,7 @@ var ProductList = class extends import_BaseModule.BaseModule {
47
47
  this.store.productMap = /* @__PURE__ */ new Map();
48
48
  this.store.selectProducts = [];
49
49
  }
50
+ this.request = core.getPlugin("request");
50
51
  }
51
52
  async storeChange(path, value) {
52
53
  var _a;
@@ -63,6 +64,24 @@ var ProductList = class extends import_BaseModule.BaseModule {
63
64
  }
64
65
  });
65
66
  }
67
+ async loadProductsPrice({
68
+ ids = [],
69
+ customer_id,
70
+ schedule_date,
71
+ channel
72
+ }) {
73
+ const productsData = await this.request.post(
74
+ `/product/query/price`,
75
+ {
76
+ ids,
77
+ customer_id,
78
+ schedule_date,
79
+ channel
80
+ },
81
+ { useCache: true }
82
+ );
83
+ return productsData.data;
84
+ }
66
85
  async getProducts() {
67
86
  await this.core.effects.emit(
68
87
  import_types.ProductListHooks.onGetProducts,
@@ -186,10 +186,11 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
186
186
  private getScheduleDataByIds;
187
187
  openProductDetail(productId: number): Promise<void>;
188
188
  closeProductDetail(): void;
189
- getTimeslotBySchedule({ date, scheduleIds, resources, }: {
189
+ getTimeslotBySchedule({ date, scheduleIds, resources, product }: {
190
190
  date: string;
191
191
  scheduleIds?: number[];
192
192
  resources?: ProductResourceItem[];
193
+ product?: ProductData;
193
194
  }): {
194
195
  start_time: string;
195
196
  end_time: string;
@@ -225,30 +225,32 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
225
225
  }
226
226
  async updateQuotationPriceAndCart(date) {
227
227
  var _a;
228
- const dateRange = this.store.date.getDateRange();
229
- const scheduleList = this.store.schedule.getAvailabilityScheduleDateList() || [];
230
- let scheduleIds = [];
231
- if (dateRange && dateRange.length) {
232
- scheduleIds = scheduleList.filter((n) => n.date === dateRange[0].date).flatMap((n) => n.schedule_id);
233
- } else {
234
- scheduleIds = scheduleList.filter((n) => n.date === date).flatMap((n) => n.schedule_id);
235
- }
236
- await this.loadProducts({
237
- ...(_a = this.otherParams) == null ? void 0 : _a.productModuleParams,
238
- scheduleIds,
239
- schedule_date: date
240
- });
241
228
  const cartItems = this.store.cart.getItems();
242
229
  if (cartItems.length) {
230
+ let userPlugin = this.core.getPlugin("user");
231
+ let customer_id = void 0;
232
+ try {
233
+ customer_id = (_a = userPlugin == null ? void 0 : userPlugin.get()) == null ? void 0 : _a.id;
234
+ } catch (error) {
235
+ console.error(error);
236
+ }
237
+ const res = await this.store.products.loadProductsPrice({
238
+ ids: cartItems.map((n) => n.id),
239
+ schedule_date: date,
240
+ customer_id
241
+ });
243
242
  for (const item of cartItems) {
244
- const targetProduct = await this.store.products.getProduct(item.id);
245
- const productInfo = (0, import_lodash_es.cloneDeep)(targetProduct == null ? void 0 : targetProduct.getData());
243
+ const targetProduct = res.find((n) => n.id === item.id);
244
+ const cartProduct = await this.store.products.getProduct(item.id);
245
+ const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
246
246
  let bundle = item._bundleOrigin;
247
+ productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
248
+ productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
247
249
  bundle = bundle == null ? void 0 : bundle.map((n) => {
248
250
  var _a2;
249
- const targetBundle = (_a2 = productInfo == null ? void 0 : productInfo.bundle) == null ? void 0 : _a2.find((m) => m.group_id === n.id);
251
+ const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find((m) => m.id === n.group_id);
250
252
  if (targetBundle) {
251
- const targetBundleItem = targetBundle.items.find((m) => m.id === n.id);
253
+ const targetBundleItem = targetBundle.bundle_item.find((m) => m.id === n.id);
252
254
  if (targetBundleItem) {
253
255
  return {
254
256
  ...n,
@@ -1368,8 +1370,10 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1368
1370
  const resourceIds = [];
1369
1371
  let resourcesTypeId = void 0;
1370
1372
  let isSingleResource = false;
1373
+ let maxCutOffTime = void 0;
1374
+ let maxCutOffTimeValue = (0, import_dayjs.default)();
1371
1375
  cartItems.forEach((item) => {
1372
- var _a2, _b2, _c2, _d2, _e2, _f2, _g;
1376
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i;
1373
1377
  (_c2 = (_b2 = (_a2 = item._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c2.forEach((n) => {
1374
1378
  if (n.code === resources_code) {
1375
1379
  resources.push(...n.renderList || []);
@@ -1382,6 +1386,13 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1382
1386
  resourcesTypeId = (_g = (_f2 = (_e2 = (_d2 = item == null ? void 0 : item._productOrigin) == null ? void 0 : _d2.product_resource) == null ? void 0 : _e2.resources) == null ? void 0 : _f2.find(
1383
1387
  (n) => n.code === resources_code
1384
1388
  )) == null ? void 0 : _g.id;
1389
+ if (((_h = item._productOrigin) == null ? void 0 : _h.cut_off_time) && ((_i = item._productOrigin) == null ? void 0 : _i.cut_off_time.type) === "advance") {
1390
+ const currentCutOffTime = (0, import_dayjs.default)().add(item._productOrigin.cut_off_time.unit, item._productOrigin.cut_off_time.unit_type);
1391
+ if (currentCutOffTime.isAfter(maxCutOffTimeValue, "minute")) {
1392
+ maxCutOffTimeValue = currentCutOffTime;
1393
+ maxCutOffTime = item._productOrigin.cut_off_time;
1394
+ }
1395
+ }
1385
1396
  });
1386
1397
  if ((_b = (_a = dateRange == null ? void 0 : dateRange[0]) == null ? void 0 : _a.resource) == null ? void 0 : _b.length) {
1387
1398
  dateRange[0].resource.forEach((n) => {
@@ -1443,7 +1454,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1443
1454
  duration,
1444
1455
  currentDate: dateRange[0].date,
1445
1456
  split: 10,
1446
- resourcesUseableMap
1457
+ resourcesUseableMap,
1458
+ cut_off_time: maxCutOffTime
1447
1459
  });
1448
1460
  return timeSlots;
1449
1461
  }
@@ -1532,11 +1544,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1532
1544
  getTimeslotBySchedule({
1533
1545
  date,
1534
1546
  scheduleIds,
1535
- resources
1547
+ resources,
1548
+ product
1536
1549
  }) {
1537
1550
  var _a, _b, _c;
1538
1551
  const targetProduct = this.store.currentProduct;
1539
- const targetProductData = targetProduct == null ? void 0 : targetProduct.getData();
1552
+ const targetProductData = product || (targetProduct == null ? void 0 : targetProduct.getData());
1540
1553
  let targetSchedules = [];
1541
1554
  if (scheduleIds == null ? void 0 : scheduleIds.length) {
1542
1555
  targetSchedules = this.store.schedule.getScheduleListByIds(scheduleIds);
@@ -1585,7 +1598,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1585
1598
  let currentResourcesCount = 0;
1586
1599
  const currentResourcesTimeSlotCanUsedArr = [];
1587
1600
  const mTimes = m.times.filter((n) => {
1588
- return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start)) && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end));
1601
+ return !(0, import_dayjs.default)(n.start_at).isAfter((0, import_dayjs.default)(item.start), "minute") && !(0, import_dayjs.default)(n.end_at).isBefore((0, import_dayjs.default)(item.end), "minute");
1589
1602
  });
1590
1603
  if (mTimes.length === 0) {
1591
1604
  return;
@@ -79,13 +79,23 @@ export declare const formatResources: ({ booking, resources, }: {
79
79
  * @return {*}
80
80
  * @Author: zhiwei.Wang
81
81
  */
82
- export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, }: {
82
+ export declare const getTimeSlicesByResource: ({ resource, duration, split, currentDate, capacity, resourcesUseableMap, cut_off_time }: {
83
83
  resource: ResourceItem;
84
84
  duration: number;
85
85
  split: number;
86
86
  currentDate: DateType | string;
87
87
  capacity?: number | undefined;
88
88
  resourcesUseableMap?: Record<string, boolean> | undefined;
89
+ cut_off_time?: {
90
+ future_day: number;
91
+ unit: number;
92
+ unit_type: string;
93
+ type: string;
94
+ ongoing?: {
95
+ type: string;
96
+ unit: number;
97
+ } | undefined;
98
+ } | undefined;
89
99
  }) => TimeSliceItem[];
90
100
  /**
91
101
  * @title: 获取时间切片列表的交集
@@ -123,7 +133,7 @@ export declare const mergeSubResourcesTimeSlices: (resources: ResourceItem[], re
123
133
  * @return {*}
124
134
  * @Author: zhiwei.Wang
125
135
  */
126
- export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, }: {
136
+ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, duration, currentDate, split, capacity, resourcesUseableMap, cut_off_time }: {
127
137
  resourceIds: number[];
128
138
  resourcesMap: any;
129
139
  duration: number;
@@ -131,6 +141,16 @@ export declare const getTimeSlicesByResources: ({ resourceIds, resourcesMap, dur
131
141
  split: number;
132
142
  capacity?: number | undefined;
133
143
  resourcesUseableMap: Record<string, boolean>;
144
+ cut_off_time?: {
145
+ future_day: number;
146
+ unit: number;
147
+ unit_type: string;
148
+ type: string;
149
+ ongoing?: {
150
+ type: string;
151
+ unit: number;
152
+ } | undefined;
153
+ } | undefined;
134
154
  }) => any[];
135
155
  /**
136
156
  * @title: 获取其他人的已选资源
@@ -328,7 +328,8 @@ var getTimeSlicesByResource = ({
328
328
  split = 10,
329
329
  currentDate = (0, import_dayjs.default)(),
330
330
  capacity,
331
- resourcesUseableMap = {}
331
+ resourcesUseableMap = {},
332
+ cut_off_time
332
333
  }) => {
333
334
  const { times } = resource;
334
335
  const timeSlices = [];
@@ -353,7 +354,8 @@ var getTimeSlicesByResource = ({
353
354
  time,
354
355
  resource,
355
356
  currentCount: capacity || 1,
356
- resourcesUseableMap
357
+ resourcesUseableMap,
358
+ cut_off_time
357
359
  });
358
360
  if ((resourcesUseableMap == null ? void 0 : resourcesUseableMap[resource.id]) !== false) {
359
361
  resourcesUseableMap[resource.id] = _status.usable;
@@ -415,7 +417,8 @@ var getTimeSlicesByResources = ({
415
417
  currentDate,
416
418
  split,
417
419
  capacity,
418
- resourcesUseableMap
420
+ resourcesUseableMap,
421
+ cut_off_time
419
422
  }) => {
420
423
  let resources = getResourcesByIds(resourcesMap, resourceIds);
421
424
  mergeSubResourcesTimeSlices(resources, resourcesMap);
@@ -438,7 +441,8 @@ var getTimeSlicesByResources = ({
438
441
  split,
439
442
  currentDate,
440
443
  capacity,
441
- resourcesUseableMap
444
+ resourcesUseableMap,
445
+ cut_off_time
442
446
  })
443
447
  );
444
448
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.28",
4
+ "version": "3.0.29",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",