@pisell/pisellos 0.0.124 → 0.0.126

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.
@@ -69,8 +69,10 @@ export interface CartItem {
69
69
  name?: string;
70
70
  /** 商品价格 */
71
71
  price?: number | string;
72
- /** 商品总价 */
72
+ /** 单个商品包括商品本身价格+套餐价格+规格等价格得出来的 */
73
73
  total?: number | string;
74
+ /** 基于 total 乘以 商品数量的价格 */
75
+ summaryTotal?: number | string;
74
76
  /** 商品原价总价,排除原始价格为0的场景 */
75
77
  origin_total?: number | string;
76
78
  /** 商品数量 */
@@ -61,6 +61,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
61
61
  options: options,
62
62
  num: num
63
63
  });
64
+ cartItem.summaryTotal = cartItem.total * (num || 1);
64
65
  cartItem.origin_total = getProductOriginTotalPrice({
65
66
  product: product,
66
67
  bundle: bundle,
@@ -161,7 +162,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
161
162
  var product = params.product,
162
163
  bundle = params.bundle,
163
164
  options = params.options;
164
- var num = params.num || 1;
165
+ // const num = params.num || 1;
165
166
  var price = Number(product.price);
166
167
  if (bundle !== null && bundle !== void 0 && bundle.length) {
167
168
  price = bundle.reduce(function (accumulator, currentValue) {
@@ -175,7 +176,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
175
176
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
177
  }, price);
177
178
  }
178
- return price * num;
179
+ return price;
179
180
  };
180
181
 
181
182
  /**
@@ -28,7 +28,7 @@ export var calculateSubtotal = function calculateSubtotal(items) {
28
28
  return '0.00';
29
29
  }
30
30
  var subtotal = items.reduce(function (sum, item) {
31
- var cartItemTotalPrice = new Decimal(item.total || 0);
31
+ var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
32
32
  return sum.plus(cartItemTotalPrice);
33
33
  }, new Decimal(0));
34
34
  return subtotal.toFixed(2);
@@ -50,7 +50,7 @@ export var calculateTaxFee = function calculateTaxFee(shopInfo, items) {
50
50
  is_price_include_tax = _ref.is_price_include_tax,
51
51
  tax_rate = _ref.tax_rate;
52
52
  var totalTaxFee = items.reduce(function (sum, item) {
53
- var cartItemTotalPrice = new Decimal(item.total || 0);
53
+ var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
54
54
  var taxRate = new Decimal(tax_rate || 0).div(100);
55
55
  var productTaxRate = cartItemTotalPrice.times(taxRate).times((item === null || item === void 0 ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
56
56
  return sum.plus(productTaxRate);
@@ -272,8 +272,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
272
272
  key: "loadProductByScheduleDate",
273
273
  value: function () {
274
274
  var _loadProductByScheduleDate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref2) {
275
- var _product_ids;
276
- var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, _schedule$product_ids, schedule, otherProductsIds, allProductIds;
275
+ var _schedule$product_ids;
276
+ var date, _ref2$product_ids, product_ids, _ref2$category_ids, category_ids, scheduleList, schedule, otherProductsIds, allProductIds;
277
277
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
278
278
  while (1) switch (_context3.prev = _context3.next) {
279
279
  case 0:
@@ -296,29 +296,34 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
296
296
  // .filter((n) => n !== null && n !== undefined);
297
297
 
298
298
  // 如果外面没传 product_ids,尝试从对应 schedule 里拿 product_ids
299
- if (!((_product_ids = product_ids) !== null && _product_ids !== void 0 && _product_ids.length)) {
300
- schedule = scheduleList.find(function (n) {
301
- return n.date === date;
302
- });
303
- if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
304
- product_ids = schedule.product_ids;
305
- }
299
+ // if (!product_ids?.length) {
300
+ // const schedule = scheduleList.find((n) => n.date === date);
301
+ // if (schedule && schedule.product_ids?.length) {
302
+ // product_ids = schedule.product_ids;
303
+ // }
304
+ // }
305
+ // V2接口修改后,只能从schedule 接口里拿数据,不可以从外面拿,外面给的是装修数据
306
+ schedule = scheduleList.find(function (n) {
307
+ return n.date === date;
308
+ });
309
+ if (schedule && (_schedule$product_ids = schedule.product_ids) !== null && _schedule$product_ids !== void 0 && _schedule$product_ids.length) {
310
+ product_ids = schedule.product_ids;
306
311
  }
307
312
  // 尝试去拿schedule 里的 other_product_ids 和 product_ids 拼在一起去重
308
313
  otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
309
314
  allProductIds = [].concat(_toConsumableArray(product_ids), _toConsumableArray(otherProductsIds)).filter(function (n, index, self) {
310
315
  return self.indexOf(n) === index;
311
316
  });
312
- _context3.next = 8;
317
+ _context3.next = 9;
313
318
  return this.loadProducts({
314
319
  // schedule_ids: scheduleIds,
315
320
  product_ids: allProductIds,
316
321
  category_ids: category_ids
317
322
  // schedule_date: date,
318
323
  });
319
- case 8:
320
- return _context3.abrupt("return", _context3.sent);
321
324
  case 9:
325
+ return _context3.abrupt("return", _context3.sent);
326
+ case 10:
322
327
  case "end":
323
328
  return _context3.stop();
324
329
  }
@@ -341,7 +346,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
341
346
  // 更新完商品数据以后,检测当前购物车里是否有商品,如果有,则需要更新购物车里的商品价格
342
347
  cartItems = this.store.cart.getItems();
343
348
  if (!cartItems.length) {
344
- _context5.next = 24;
349
+ _context5.next = 25;
345
350
  break;
346
351
  }
347
352
  userPlugin = this.core.getPlugin('user');
@@ -433,6 +438,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
433
438
  _iterator.f();
434
439
  return _context5.finish(21);
435
440
  case 24:
441
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
442
+ case 25:
436
443
  case "end":
437
444
  return _context5.stop();
438
445
  }
@@ -2461,8 +2468,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2461
2468
  // m.times 需要做个过滤,假设 timeSlice.start_at 是 09:30 timeSlice.end_at 是 11:30
2462
2469
  // time 是 time.start_at = 2025-05-26 10:30, time.end_at = 2025-05-26 12:30
2463
2470
  // 需要判断 time 的开始结束时间 是否包含timeSlice的开始结束时间
2471
+
2472
+ // n.start_at 是 2025-06-30 15:00 end_at 2025-06-30 17:00
2473
+ // item.start 是 2025-06-30 16:00 item.end 是 2025-06-30 19:00
2474
+ // 需要判断 n.start_at 和 n.end_at 是否在 item.start 和 item.end 之间
2475
+ // 如果 n.start_at 和 n.end_at 在 item.start 和 item.end 有交集,则此时间需要计算
2464
2476
  var mTimes = m.times.filter(function (n) {
2465
- return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute');
2477
+ return !dayjs(n.start_at).isAfter(dayjs(item.start), 'minute') && !dayjs(n.end_at).isBefore(dayjs(item.end), 'minute') || dayjs(n.start_at).isBefore(dayjs(item.end), 'minute') && dayjs(n.end_at).isAfter(dayjs(item.start), 'minute');
2466
2478
  });
2467
2479
  // 如果在这个区间的时间一个都没有,可以直接认为这个资源不可用
2468
2480
  if (mTimes.length === 0) {
@@ -2890,6 +2902,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2890
2902
  var params,
2891
2903
  startDate,
2892
2904
  endDate,
2905
+ endDateAfterMonth,
2893
2906
  tempProducts,
2894
2907
  schedule,
2895
2908
  filteredSchedule,
@@ -2914,13 +2927,20 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2914
2927
  startDate = dayjs().format('YYYY-MM-DD');
2915
2928
  }
2916
2929
  // 不管前端传什么 endDate 默认查一个月的,以今天为开始日期。用于找到一个月内最近可用的日期
2917
- endDate = dayjs().add(1, 'month').format('YYYY-MM-DD');
2930
+ // 优化策略:
2931
+ // 在 endDate 添加完一个月以后,如果 endDate 还小于 startDate + 7 天,则还需要 endDate+7 天
2932
+ endDateAfterMonth = dayjs().add(1, 'month').format('YYYY-MM-DD');
2933
+ if (dayjs(startDate).add(7, 'day').isAfter(dayjs(endDateAfterMonth), 'day')) {
2934
+ endDate = dayjs(startDate).add(7, 'day').format('YYYY-MM-DD');
2935
+ } else {
2936
+ endDate = endDateAfterMonth;
2937
+ }
2918
2938
  // 如果当前打开了某个的商品详情弹窗,则应该默认用这个商品
2919
2939
  tempProducts = (_this$store$currentPr3 = this.store.currentProduct) === null || _this$store$currentPr3 === void 0 ? void 0 : _this$store$currentPr3.getData();
2920
2940
  schedule = (_this$store$currentPr4 = this.store.currentProduct) === null || _this$store$currentPr4 === void 0 ? void 0 : _this$store$currentPr4.getOtherParams()['schedule'];
2921
2941
  filteredSchedule = filterScheduleByDateRange(schedule, startDate || '', endDate || ''); // 1.后端返回的数据,确定资源在每一天的可用和使用情况
2922
2942
  tempResourceIds = getResourcesIdsByProduct(tempProducts);
2923
- _context32.next = 10;
2943
+ _context32.next = 11;
2924
2944
  return this.store.date.fetchResourceDates({
2925
2945
  query: {
2926
2946
  start_date: startDate || '',
@@ -2928,17 +2948,17 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2928
2948
  resource_ids: tempResourceIds
2929
2949
  }
2930
2950
  });
2931
- case 10:
2951
+ case 11:
2932
2952
  res = _context32.sent;
2933
2953
  // 先去读缓存结果,因为正常 UI 调用的是 7 天,而下面我会直接计算 30 天(最少也是 14 天),所以先去读缓存结果,如果缓存结果存在,则直接返回
2934
2954
  // TODO 优化关于为什么要放在接口后,因为在获取时间切片的时候还需要读一次接口数据,其实可以直接从这个结果里拿了,需要优化
2935
2955
  cache = (_this$store$currentPr5 = this.store.currentProduct) === null || _this$store$currentPr5 === void 0 ? void 0 : _this$store$currentPr5.getOtherParams()['timeSlotBySchedule'];
2936
2956
  if (!cache) {
2937
- _context32.next = 16;
2957
+ _context32.next = 17;
2938
2958
  break;
2939
2959
  }
2940
2960
  if (!(dayjs(params.startDate).isSameOrAfter(dayjs(cache.startDate), 'day') && dayjs(params.endDate).isSameOrBefore(dayjs(cache.endDate), 'day'))) {
2941
- _context32.next = 16;
2961
+ _context32.next = 17;
2942
2962
  break;
2943
2963
  }
2944
2964
  this.store.date.setDateList(cache.dateList);
@@ -2946,7 +2966,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2946
2966
  dateList: cache.dateList,
2947
2967
  firstAvailableDate: cache.firstAvailableDate
2948
2968
  });
2949
- case 16:
2969
+ case 17:
2950
2970
  // 2. 商品 schedule 数据,确定日程在每一天的时间片
2951
2971
  // 3. 把后端返回的和 schedule 的数据进行合并,确定每一天的可用和使用情况
2952
2972
  dates = [];
@@ -3073,22 +3093,22 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3073
3093
  }
3074
3094
  }, _loop3);
3075
3095
  });
3076
- case 24:
3096
+ case 25:
3077
3097
  if (!(dayjs(currentDate).isBefore(dayjs(endDate), 'day') || dayjs(currentDate).isSame(dayjs(endDate), 'day'))) {
3078
- _context32.next = 30;
3098
+ _context32.next = 31;
3079
3099
  break;
3080
3100
  }
3081
- return _context32.delegateYield(_loop3(), "t0", 26);
3082
- case 26:
3101
+ return _context32.delegateYield(_loop3(), "t0", 27);
3102
+ case 27:
3083
3103
  if (!_context32.t0) {
3084
- _context32.next = 28;
3104
+ _context32.next = 29;
3085
3105
  break;
3086
3106
  }
3087
- return _context32.abrupt("break", 30);
3088
- case 28:
3089
- _context32.next = 24;
3107
+ return _context32.abrupt("break", 31);
3108
+ case 29:
3109
+ _context32.next = 25;
3090
3110
  break;
3091
- case 30:
3111
+ case 31:
3092
3112
  // 最终把资源数据也加到日期内
3093
3113
  dates = handleAvailableDateByResource(res.data, dates);
3094
3114
  this.store.date.setDateList(dates);
@@ -3098,13 +3118,13 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3098
3118
  dateList: dates,
3099
3119
  firstAvailableDate: firstAvailableDate,
3100
3120
  startDate: startDate,
3101
- endDate: endDate
3121
+ endDate: dayjs(currentDate).format('YYYY-MM-DD')
3102
3122
  });
3103
3123
  return _context32.abrupt("return", {
3104
3124
  dateList: dates,
3105
3125
  firstAvailableDate: firstAvailableDate
3106
3126
  });
3107
- case 34:
3127
+ case 35:
3108
3128
  case "end":
3109
3129
  return _context32.stop();
3110
3130
  }
@@ -69,8 +69,10 @@ export interface CartItem {
69
69
  name?: string;
70
70
  /** 商品价格 */
71
71
  price?: number | string;
72
- /** 商品总价 */
72
+ /** 单个商品包括商品本身价格+套餐价格+规格等价格得出来的 */
73
73
  total?: number | string;
74
+ /** 基于 total 乘以 商品数量的价格 */
75
+ summaryTotal?: number | string;
74
76
  /** 商品原价总价,排除原始价格为0的场景 */
75
77
  origin_total?: number | string;
76
78
  /** 商品数量 */
@@ -74,6 +74,7 @@ var formatProductToCartItem = (params) => {
74
74
  cartItem.price = product == null ? void 0 : product.price;
75
75
  cartItem.num = num;
76
76
  cartItem.total = getProductTotalPrice({ product, bundle, options, num });
77
+ cartItem.summaryTotal = cartItem.total * (num || 1);
77
78
  cartItem.origin_total = getProductOriginTotalPrice({
78
79
  product,
79
80
  bundle,
@@ -163,7 +164,6 @@ var formatProductToCartItemOrigin = (params) => {
163
164
  };
164
165
  var getProductTotalPrice = (params) => {
165
166
  const { product, bundle, options } = params;
166
- const num = params.num || 1;
167
167
  let price = Number(product.price);
168
168
  if (bundle == null ? void 0 : bundle.length) {
169
169
  price = bundle.reduce((accumulator, currentValue) => {
@@ -175,7 +175,7 @@ var getProductTotalPrice = (params) => {
175
175
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
176
  }, price);
177
177
  }
178
- return price * num;
178
+ return price;
179
179
  };
180
180
  var getProductOriginTotalPrice = (params) => {
181
181
  const { product, bundle, options } = params;
@@ -55,7 +55,7 @@ var calculateSubtotal = (items) => {
55
55
  return "0.00";
56
56
  }
57
57
  const subtotal = items.reduce((sum, item) => {
58
- const cartItemTotalPrice = new import_decimal.default(item.total || 0);
58
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
59
59
  return sum.plus(cartItemTotalPrice);
60
60
  }, new import_decimal.default(0));
61
61
  return subtotal.toFixed(2);
@@ -66,7 +66,7 @@ var calculateTaxFee = (shopInfo, items) => {
66
66
  }
67
67
  const { is_price_include_tax, tax_rate } = shopInfo || {};
68
68
  const totalTaxFee = items.reduce((sum, item) => {
69
- const cartItemTotalPrice = new import_decimal.default(item.total || 0);
69
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
70
70
  const taxRate = new import_decimal.default(tax_rate || 0).div(100);
71
71
  const productTaxRate = cartItemTotalPrice.times(taxRate).times((item == null ? void 0 : item.is_charge_tax) || 0).div(taxRate.times(is_price_include_tax || 0).plus(1));
72
72
  return sum.plus(productTaxRate);
@@ -216,11 +216,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
216
216
  { date, status: "available", week: "", weekNum: 0 },
217
217
  { date, status: "available", week: "", weekNum: 0 }
218
218
  ]);
219
- if (!(product_ids == null ? void 0 : product_ids.length)) {
220
- const schedule = scheduleList.find((n) => n.date === date);
221
- if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
222
- product_ids = schedule.product_ids;
223
- }
219
+ const schedule = scheduleList.find((n) => n.date === date);
220
+ if (schedule && ((_a = schedule.product_ids) == null ? void 0 : _a.length)) {
221
+ product_ids = schedule.product_ids;
224
222
  }
225
223
  const otherProductsIds = this.store.schedule.getOtherProductsIds() || [];
226
224
  const allProductIds = [...product_ids, ...otherProductsIds].filter(
@@ -283,6 +281,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
283
281
  bundle
284
282
  });
285
283
  }
284
+ this.core.effects.emit(`${this.store.cart.name}:onUpdateQuotationPrice`, {});
286
285
  }
287
286
  }
288
287
  // 加载当前店铺下所有 schedule
@@ -1704,7 +1703,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1704
1703
  let currentResourcesCount = 0;
1705
1704
  const currentResourcesTimeSlotCanUsedArr = [];
1706
1705
  const mTimes = m.times.filter((n) => {
1707
- 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");
1706
+ 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") || (0, import_dayjs.default)(n.start_at).isBefore((0, import_dayjs.default)(item.end), "minute") && (0, import_dayjs.default)(n.end_at).isAfter((0, import_dayjs.default)(item.start), "minute");
1708
1707
  });
1709
1708
  if (mTimes.length === 0) {
1710
1709
  return;
@@ -2038,7 +2037,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2038
2037
  if ((0, import_dayjs.default)(startDate).isBefore((0, import_dayjs.default)(), "day") && ((0, import_dayjs.default)(endDate).isAfter((0, import_dayjs.default)(), "day") || (0, import_dayjs.default)(endDate).isSame((0, import_dayjs.default)(), "day"))) {
2039
2038
  startDate = (0, import_dayjs.default)().format("YYYY-MM-DD");
2040
2039
  }
2041
- endDate = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2040
+ const endDateAfterMonth = (0, import_dayjs.default)().add(1, "month").format("YYYY-MM-DD");
2041
+ if ((0, import_dayjs.default)(startDate).add(7, "day").isAfter((0, import_dayjs.default)(endDateAfterMonth), "day")) {
2042
+ endDate = (0, import_dayjs.default)(startDate).add(7, "day").format("YYYY-MM-DD");
2043
+ } else {
2044
+ endDate = endDateAfterMonth;
2045
+ }
2042
2046
  let tempProducts;
2043
2047
  tempProducts = (_a = this.store.currentProduct) == null ? void 0 : _a.getData();
2044
2048
  const schedule = (_b = this.store.currentProduct) == null ? void 0 : _b.getOtherParams()["schedule"];
@@ -2171,7 +2175,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2171
2175
  dateList: dates,
2172
2176
  firstAvailableDate,
2173
2177
  startDate,
2174
- endDate
2178
+ endDate: (0, import_dayjs.default)(currentDate).format("YYYY-MM-DD")
2175
2179
  });
2176
2180
  return {
2177
2181
  dateList: dates,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.124",
4
+ "version": "0.0.126",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "docs": "typedoc --out docs src/index.ts",
23
23
  "sync": "node sync.js",
24
24
  "prepublishOnly": "npm run build",
25
- "deploy": "yarn run build && yarn run changeset && yarn run version && npm run release"
25
+ "deploy": "npm run build && npm run changeset && npm run version && npm run release"
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
@@ -67,4 +67,4 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  }
70
- }
70
+ }