@pisell/pisellos 0.0.188 → 0.0.190

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.
@@ -423,6 +423,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
423
423
  }));
424
424
  }
425
425
  for (var _i = 0; _i < splitCount; _i++) {
426
+ var _originProduct$_produ, _product$discount_lis10;
426
427
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
427
428
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[_i];
428
429
  // 标记优惠券为已使用
@@ -433,12 +434,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
433
434
 
434
435
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
435
436
  var productOriginTotal = product.origin_total || product.total || 0;
436
- // 如果 origin_total 有值,并且 product.total 有值,并且 origin_total 和 originProduct.origin_total 一样,则优先使用 product.total
437
- // 因为用户端会涉及到划线价的概念
438
- // 如果 originProduct._productInit.original_price 有值,则代表有划线价
439
- if (Number(originProduct._productInit.original_price) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
437
+ // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
438
+ if (Number((originProduct === null || originProduct === void 0 || (_originProduct$_produ = originProduct._productInit) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
440
439
  productOriginTotal = product.total;
441
440
  }
441
+ // 如果当前 product 有 discount_list,则必须从 origin_total 拿
442
+ if ((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.length) {
443
+ productOriginTotal = product.origin_total;
444
+ }
442
445
 
443
446
  // 计算使用折扣卡/商品券以后,单个商品的总 total
444
447
  var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
@@ -1673,10 +1673,18 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1673
1673
  }
1674
1674
  // 如果此时 resources 为空,视作购物车里已经有了 dateRange 数据,此时 dateList 里明确就是那一天的数据
1675
1675
  if (!AllResources.length) {
1676
- var dateList = this.store.date.getDateList();
1677
- dateList.forEach(function (n) {
1678
- if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1676
+ var firstDateCartItem = cartItems === null || cartItems === void 0 ? void 0 : cartItems.find(function (n) {
1677
+ return n.start_date;
1679
1678
  });
1679
+ if (firstDateCartItem !== null && firstDateCartItem !== void 0 && firstDateCartItem.start_date) {
1680
+ var dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1681
+ AllResources.push.apply(AllResources, _toConsumableArray(dateResources || []));
1682
+ } else {
1683
+ var dateList = this.store.date.getDateList();
1684
+ dateList.forEach(function (n) {
1685
+ if (n.resource) AllResources.push.apply(AllResources, _toConsumableArray(n.resource));
1686
+ });
1687
+ }
1680
1688
  }
1681
1689
  var resourcesMap = getResourcesMap(cloneDeep(AllResources));
1682
1690
  var allCartItems = cloneDeep(this.store.cart.getItems());
@@ -2174,12 +2182,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2174
2182
  value: 10
2175
2183
  };
2176
2184
  resource.startTime = timeSlots.start_at.format('YYYY-MM-DD HH:mm');
2177
- // 找到resource.times里最早的end_at
2185
+ // 找到resource.times里最晚的end_at
2178
2186
  var targetResourceTimes = allResources === null || allResources === void 0 || (_allResources$find = allResources.find(function (n) {
2179
2187
  return n.id === resource.id;
2180
2188
  })) === null || _allResources$find === void 0 ? void 0 : _allResources$find.times;
2181
2189
  var resourcesEndTime = targetResourceTimes.reduce(function (acc, curr) {
2182
- return dayjs(curr.end_at).isBefore(dayjs(acc.end_at)) ? curr : acc;
2190
+ return dayjs(curr.end_at).isAfter(dayjs(acc.end_at)) ? curr : acc;
2183
2191
  }, targetResourceTimes[0]);
2184
2192
 
2185
2193
  // 将 operating_day_boundary 转换为与 resourcesEndTime.end_at 相同日期的完整日期时间
@@ -207,7 +207,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
207
207
  });
208
208
  console.log(sortedProductList, "sortedProductListsortedProductList");
209
209
  sortedProductList.forEach((originProduct, i) => {
210
- var _a, _b, _c, _d, _e, _f;
210
+ var _a, _b, _c, _d, _e, _f, _g, _h;
211
211
  const product = this.hooks.getProduct(originProduct);
212
212
  if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
213
213
  processedProductsMap.set(product._id, [originProduct]);
@@ -298,9 +298,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
298
298
  usedDiscounts.set(selectedDiscount2.id, true);
299
299
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
300
300
  let productOriginTotal = product.origin_total || product.total || 0;
301
- if (Number(originProduct._productInit.original_price) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
301
+ if (Number(((_g = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _g.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
302
302
  productOriginTotal = product.total;
303
303
  }
304
+ if ((_h = product.discount_list) == null ? void 0 : _h.length) {
305
+ productOriginTotal = product.origin_total;
306
+ }
304
307
  const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(productOriginTotal)).toNumber();
305
308
  const discountDetail = {
306
309
  amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
@@ -1056,11 +1056,17 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1056
1056
  });
1057
1057
  }
1058
1058
  if (!AllResources.length) {
1059
- const dateList = this.store.date.getDateList();
1060
- dateList.forEach((n) => {
1061
- if (n.resource)
1062
- AllResources.push(...n.resource);
1063
- });
1059
+ const firstDateCartItem = cartItems == null ? void 0 : cartItems.find((n) => n.start_date);
1060
+ if (firstDateCartItem == null ? void 0 : firstDateCartItem.start_date) {
1061
+ const dateResources = this.store.date.getResourcesListByDate(firstDateCartItem.start_date);
1062
+ AllResources.push(...dateResources || []);
1063
+ } else {
1064
+ const dateList = this.store.date.getDateList();
1065
+ dateList.forEach((n) => {
1066
+ if (n.resource)
1067
+ AllResources.push(...n.resource);
1068
+ });
1069
+ }
1064
1070
  }
1065
1071
  const resourcesMap = (0, import_utils.getResourcesMap)((0, import_lodash_es.cloneDeep)(AllResources));
1066
1072
  const allCartItems = (0, import_lodash_es.cloneDeep)(this.store.cart.getItems());
@@ -1504,7 +1510,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1504
1510
  )) == null ? void 0 : _c.times;
1505
1511
  const resourcesEndTime = targetResourceTimes.reduce(
1506
1512
  (acc, curr) => {
1507
- return (0, import_dayjs.default)(curr.end_at).isBefore((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1513
+ return (0, import_dayjs.default)(curr.end_at).isAfter((0, import_dayjs.default)(acc.end_at)) ? curr : acc;
1508
1514
  },
1509
1515
  targetResourceTimes[0]
1510
1516
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.188",
4
+ "version": "0.0.190",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",