@pisell/pisellos 3.0.77 → 3.0.79

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.
Files changed (53) hide show
  1. package/dist/modules/Cart/types.d.ts +2 -0
  2. package/dist/modules/Cart/utils/cartProduct.js +21 -1
  3. package/dist/modules/Cart/utils/changePrice.js +6 -0
  4. package/dist/modules/Date/index.d.ts +1 -1
  5. package/dist/modules/Date/index.js +16 -8
  6. package/dist/modules/Date/types.d.ts +3 -1
  7. package/dist/modules/Discount/index.d.ts +1 -0
  8. package/dist/modules/Discount/index.js +2 -1
  9. package/dist/modules/ProductList/index.js +8 -9
  10. package/dist/modules/Rules/index.d.ts +3 -1
  11. package/dist/modules/Rules/index.js +110 -27
  12. package/dist/modules/Rules/types.d.ts +6 -0
  13. package/dist/modules/Rules/types.js +8 -0
  14. package/dist/modules/Schedule/index.d.ts +9 -0
  15. package/dist/modules/Schedule/index.js +76 -0
  16. package/dist/modules/Summary/index.d.ts +3 -0
  17. package/dist/modules/Summary/index.js +134 -15
  18. package/dist/modules/Summary/types.d.ts +7 -0
  19. package/dist/modules/Summary/utils.d.ts +104 -1
  20. package/dist/modules/Summary/utils.js +1131 -13
  21. package/dist/solution/BookingByStep/index.d.ts +14 -0
  22. package/dist/solution/BookingByStep/index.js +688 -210
  23. package/dist/solution/BookingByStep/utils/capacity.js +1 -1
  24. package/dist/solution/BookingByStep/utils/resources.js +4 -0
  25. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  26. package/dist/solution/ShopDiscount/index.js +11 -6
  27. package/lib/modules/Cart/types.d.ts +2 -0
  28. package/lib/modules/Cart/utils/cartProduct.js +16 -1
  29. package/lib/modules/Cart/utils/changePrice.js +5 -0
  30. package/lib/modules/Date/index.d.ts +1 -1
  31. package/lib/modules/Date/index.js +7 -1
  32. package/lib/modules/Date/types.d.ts +3 -1
  33. package/lib/modules/Discount/index.d.ts +1 -0
  34. package/lib/modules/Discount/index.js +2 -1
  35. package/lib/modules/ProductList/index.js +0 -7
  36. package/lib/modules/Rules/index.d.ts +3 -1
  37. package/lib/modules/Rules/index.js +43 -5
  38. package/lib/modules/Rules/types.d.ts +6 -0
  39. package/lib/modules/Rules/types.js +11 -2
  40. package/lib/modules/Schedule/index.d.ts +9 -0
  41. package/lib/modules/Schedule/index.js +60 -0
  42. package/lib/modules/Summary/index.d.ts +3 -0
  43. package/lib/modules/Summary/index.js +61 -2
  44. package/lib/modules/Summary/types.d.ts +7 -0
  45. package/lib/modules/Summary/utils.d.ts +104 -1
  46. package/lib/modules/Summary/utils.js +673 -8
  47. package/lib/solution/BookingByStep/index.d.ts +14 -0
  48. package/lib/solution/BookingByStep/index.js +465 -89
  49. package/lib/solution/BookingByStep/utils/capacity.js +1 -1
  50. package/lib/solution/BookingByStep/utils/resources.js +4 -1
  51. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  52. package/lib/solution/ShopDiscount/index.js +11 -5
  53. package/package.json +1 -1
@@ -320,7 +320,7 @@ export function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, all
320
320
  resourcesInType.forEach(function (resource) {
321
321
  // 过滤出在时间段内的资源时间片
322
322
  var availableTimes = resource.times.filter(function (time) {
323
- return !dayjs(time.start_at).isAfter(dayjs(timeSlotStart), 'minute') && !dayjs(time.end_at).isBefore(dayjs(timeSlotEnd), 'minute') || dayjs(time.start_at).isBefore(dayjs(timeSlotEnd), 'minute') && dayjs(time.end_at).isAfter(dayjs(timeSlotStart), 'minute');
323
+ return !dayjs(time.start_at).isAfter(dayjs(timeSlotStart), 'minute') && !dayjs(time.end_at).isBefore(dayjs(timeSlotEnd), 'minute') || resource.onlyComputed && dayjs(time.start_at).isBefore(dayjs(timeSlotEnd), 'minute') && dayjs(time.end_at).isAfter(dayjs(timeSlotStart), 'minute');
324
324
  });
325
325
  if (availableTimes.length > 0) {
326
326
  // 简化逻辑:如果资源在时间段内有可用时间,就计算其容量
@@ -444,6 +444,10 @@ export var getTimeSlicesByResource = function getTimeSlicesByResource(_ref5) {
444
444
  // 解析开始和结束时间
445
445
  var startTime = dayjs("".concat(time.start_at));
446
446
  var endTime = dayjs("".concat(time.end_at));
447
+ // 结束时间要做修复,如果time.end_at 是超过了 currentDate 的那一天,则把 end_at 设置为 currentDate 那一天的 23:59:59
448
+ if (endTime.isAfter(dayjs(currentDate).endOf('day'))) {
449
+ endTime = dayjs(currentDate).endOf('day');
450
+ }
447
451
 
448
452
  // 当前切片的开始时间
449
453
  var currentStart = startTime;
@@ -2,6 +2,7 @@ import { Module, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { Customer } from './types';
4
4
  import { Discount } from '../../modules/Discount/types';
5
+ import { UnavailableReason } from '../../modules/Rules/types';
5
6
  export declare class ShopDiscountImpl extends BaseModule implements Module {
6
7
  protected defaultName: string;
7
8
  protected defaultVersion: string;
@@ -48,6 +49,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
48
49
  productList: Record<string, any>[];
49
50
  discountList: Discount[];
50
51
  type: "server" | "clientCalc";
52
+ unavailableReason?: UnavailableReason;
51
53
  }>;
52
54
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
53
55
  private getCustomer;
@@ -29,6 +29,7 @@ import { ShopDiscountHooks } from "./types";
29
29
  import { DiscountModule } from "../../modules/Discount";
30
30
  import { RulesModule } from "../../modules/Rules";
31
31
  import { filterDiscountListByBookingTime as _filterDiscountListByBookingTime, isAllNormalProduct } from "./utils";
32
+ import { UnavailableReason } from "../../modules/Rules/types";
32
33
  import Decimal from 'decimal.js';
33
34
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
34
35
  _inherits(ShopDiscountImpl, _BaseModule);
@@ -375,7 +376,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
375
376
  key: "scanCode",
376
377
  value: function () {
377
378
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
378
- var _this$store$discount3, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref3, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
379
+ var _this$store$discount3, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref3, newProductList, newDiscountList, isAvailable, unavailableReason, _this$options$otherPa6;
379
380
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
380
381
  while (1) switch (_context5.prev = _context5.next) {
381
382
  case 0:
@@ -400,7 +401,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
400
401
  type: "clientCalc",
401
402
  isAvailable: false,
402
403
  productList: this.store.productList || [],
403
- discountList: this.getDiscountList()
404
+ discountList: this.getDiscountList(),
405
+ unavailableReason: UnavailableReason.Unknown
404
406
  });
405
407
  case 10:
406
408
  if (resultDiscountList.length) {
@@ -447,7 +449,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
447
449
  isAvailable: false,
448
450
  productList: this.store.productList || [],
449
451
  discountList: this.getDiscountList()
450
- }, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable;
452
+ }, newProductList = _ref3.productList, newDiscountList = _ref3.discountList, isAvailable = _ref3.isAvailable, unavailableReason = _ref3.unavailableReason;
451
453
  if (!isAvailable) {
452
454
  _context5.next = 23;
453
455
  break;
@@ -465,7 +467,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
465
467
  type: "clientCalc",
466
468
  isAvailable: isAvailable || false,
467
469
  productList: newProductList || this.store.productList || [],
468
- discountList: newDiscountList || this.getDiscountList()
470
+ discountList: newDiscountList || this.getDiscountList(),
471
+ unavailableReason: unavailableReason
469
472
  });
470
473
  case 26:
471
474
  _context5.prev = 26;
@@ -475,7 +478,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
475
478
  type: "clientCalc",
476
479
  isAvailable: false,
477
480
  productList: this.store.productList || [],
478
- discountList: this.getDiscountList()
481
+ discountList: this.getDiscountList(),
482
+ unavailableReason: UnavailableReason.Unknown
479
483
  });
480
484
  case 30:
481
485
  case "end":
@@ -691,7 +695,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
691
695
  action: 'create',
692
696
  with_good_pass: 1,
693
697
  with_discount_card: 1,
694
- with_wallet_pass_holder: 1
698
+ with_wallet_pass_holder: 1,
699
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
695
700
  });
696
701
  case 4:
697
702
  goodPassList = _context8.sent;
@@ -146,6 +146,8 @@ export interface CartItem {
146
146
  _optionsOrigin?: any[];
147
147
  /** 操作系统提示 */
148
148
  osWarnTips?: string[];
149
+ /** 金额差值 */
150
+ totalDifference?: number;
149
151
  }
150
152
  /**
151
153
  * 购物车状态接口
@@ -45,6 +45,7 @@ module.exports = __toCommonJS(cartProduct_exports);
45
45
  var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
47
  var import_utils2 = require("../../../solution/ShopDiscount/utils");
48
+ var import_utils3 = require("../../Summary/utils");
48
49
  var handleVariantProduct = (product) => {
49
50
  var _a;
50
51
  if (product == null ? void 0 : product.product_variant_id) {
@@ -80,6 +81,7 @@ var formatProductToCartItem = (params) => {
80
81
  cartItem.price = product == null ? void 0 : product.price;
81
82
  cartItem.num = num;
82
83
  cartItem.total = getProductTotalPrice({ product, bundle, options, num, discounts });
84
+ cartItem.totalDifference = getTotalDifference({ product, bundle, discounts });
83
85
  cartItem.summaryTotal = cartItem.total * (num || 1);
84
86
  cartItem.origin_total = getProductOriginTotalPrice({
85
87
  product,
@@ -207,6 +209,18 @@ var getProductTotalPrice = (params) => {
207
209
  }
208
210
  return Math.max(0, price);
209
211
  };
212
+ var getTotalDifference = (params) => {
213
+ const { bundle, discounts } = params;
214
+ const bundleDiscountList = [];
215
+ if (bundle == null ? void 0 : bundle.length) {
216
+ bundle.forEach((currentValue) => {
217
+ bundleDiscountList.push(...(currentValue == null ? void 0 : currentValue.discount_list) || []);
218
+ });
219
+ }
220
+ const allDiscounts = [...discounts || [], ...bundleDiscountList];
221
+ const productDiscountProductDiscountDifference = (0, import_utils3.calcDiscountListDifference)(allDiscounts);
222
+ return productDiscountProductDiscountDifference || 0;
223
+ };
210
224
  var getProductOriginTotalPrice = (params) => {
211
225
  const { product, bundle, options, discounts } = params;
212
226
  const num = (params == null ? void 0 : params.num) || 1;
@@ -271,7 +285,8 @@ var formatBundle = (bundle) => {
271
285
  options: formatOptions(item == null ? void 0 : item.option),
272
286
  _bundle_product_id: item._bundle_product_id,
273
287
  discount_list: item.discount_list,
274
- originBundleItem: item.originBundleItem || item
288
+ originBundleItem: item.originBundleItem || item,
289
+ is_charge_tax: item == null ? void 0 : item.is_charge_tax
275
290
  };
276
291
  });
277
292
  };
@@ -60,6 +60,11 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
60
60
  if (targetBundleItem.price_type === "markdown") {
61
61
  targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).mul(-1).toNumber();
62
62
  }
63
+ if (n.option) {
64
+ targetBundleItem.price = new import_decimal.default(targetBundleItem.price || 0).add(n.option.reduce((pre, cur) => {
65
+ return pre + new import_decimal.default(cur.price || 0).mul(cur.num || 1).toNumber();
66
+ }, 0)).toNumber();
67
+ }
63
68
  if (targetBundleItem) {
64
69
  return {
65
70
  ...n,
@@ -37,5 +37,5 @@ export declare class DateModule extends BaseModule implements Module, DateModule
37
37
  getResourceAvailableTimeList(params: IGetAvailableTimeListParams): Promise<ITime[]>;
38
38
  clearDateRange(): void;
39
39
  storeChange(): void;
40
- getResourcesListByDate(date: string): any[] | undefined;
40
+ getResourcesListByDate(date: string): any[];
41
41
  }
@@ -64,6 +64,12 @@ var DateModule = class extends import_BaseModule.BaseModule {
64
64
  }
65
65
  }
66
66
  setDateRange(dateRange) {
67
+ dateRange.forEach((item) => {
68
+ var _a;
69
+ if (!((_a = item.resource) == null ? void 0 : _a.length)) {
70
+ item.resource = this.getResourcesListByDate(item.date);
71
+ }
72
+ });
67
73
  this.store.dateRange = dateRange;
68
74
  }
69
75
  getDateRange() {
@@ -252,7 +258,7 @@ var DateModule = class extends import_BaseModule.BaseModule {
252
258
  getResourcesListByDate(date) {
253
259
  var _a;
254
260
  const dateList = this.store.dateList;
255
- const resourcesList = (_a = dateList.find((item) => item.date === date)) == null ? void 0 : _a.resource;
261
+ const resourcesList = ((_a = dateList == null ? void 0 : dateList.find((item) => item.date === date)) == null ? void 0 : _a.resource) || [];
256
262
  return resourcesList;
257
263
  }
258
264
  };
@@ -20,7 +20,9 @@ export interface ITime {
20
20
  date: string;
21
21
  week: string;
22
22
  weekNum: number;
23
- status: 'unavailable' | 'available';
23
+ status: 'unavailable' | 'available' | 'lots_of_space' | 'filling_up_fast' | 'sold_out';
24
+ summaryCount?: number;
25
+ availableCount?: number;
24
26
  resource?: any[];
25
27
  color?: string[];
26
28
  }
@@ -22,6 +22,7 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
22
22
  with_discount_card: 0 | 1;
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
+ request_timezone: string;
25
26
  }): Promise<Discount[]>;
26
27
  batchSearch(code: string, customerId?: number): Promise<Discount[]>;
27
28
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
@@ -111,7 +111,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
111
111
  relation_product: 1,
112
112
  with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
113
113
  order_behavior_count: 1,
114
- order_behavior_count_customer_id: customerId || 1
114
+ order_behavior_count_customer_id: customerId || 1,
115
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
115
116
  });
116
117
  const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
117
118
  return resultDiscountList;
@@ -95,13 +95,6 @@ var ProductList = class extends import_BaseModule.BaseModule {
95
95
  { useCache: true }
96
96
  );
97
97
  const sortedList = (productsData.data.list || []).slice().sort((a, b) => Number(b.sort) - Number(a.sort));
98
- if (sortedList.length) {
99
- sortedList.forEach((n) => {
100
- if (n.is_eject !== 1 && n["schedule.ids"] && n["schedule.ids"].length) {
101
- n.is_eject = 1;
102
- }
103
- });
104
- }
105
98
  this.addProduct(sortedList);
106
99
  return sortedList;
107
100
  }
@@ -1,6 +1,6 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { Rules, RulesModuleAPI, DiscountResult } from './types';
3
+ import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
4
4
  import { Discount } from "../Discount/types";
5
5
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
6
6
  protected defaultName: string;
@@ -24,7 +24,9 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
24
24
  isAvailable: boolean;
25
25
  discountList: Discount[];
26
26
  productList: any[];
27
+ unavailableReason?: UnavailableReason;
27
28
  };
29
+ private getUnavailableReason;
28
30
  calcDiscount({ discountList, productList, holders, isFormSubject, }: {
29
31
  discountList: Discount[];
30
32
  productList: any[];
@@ -94,7 +94,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
94
94
  return {
95
95
  isAvailable: false,
96
96
  discountList: oldDiscountList,
97
- productList
97
+ productList,
98
+ unavailableReason: import_types.UnavailableReason.AlreadyUsed
98
99
  };
99
100
  }
100
101
  const filteredOldDiscountList = oldDiscountList.filter(
@@ -132,12 +133,49 @@ var RulesModule = class extends import_BaseModule.BaseModule {
132
133
  }
133
134
  }
134
135
  });
136
+ let unavailableReason;
137
+ if (!hasApplicableDiscount) {
138
+ unavailableReason = this.getUnavailableReason(newDiscountList, productList);
139
+ }
135
140
  return {
136
141
  isAvailable: hasApplicableDiscount,
137
142
  discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
138
- productList: hasApplicableDiscount ? result.productList : productList
143
+ productList: hasApplicableDiscount ? result.productList : productList,
144
+ unavailableReason
139
145
  };
140
146
  }
147
+ // 获取券不可用的原因
148
+ getUnavailableReason(discountList, productList) {
149
+ var _a;
150
+ for (const discount of discountList) {
151
+ for (const item of productList) {
152
+ const product = this.hooks.getProduct(item);
153
+ const bookingTime = ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss");
154
+ const filteredList = (0, import_utils.filterDiscountListByBookingTime)([discount], bookingTime);
155
+ if (filteredList.length === 0) {
156
+ return import_types.UnavailableReason.TimeLimit;
157
+ }
158
+ }
159
+ }
160
+ for (const discount of discountList) {
161
+ const limitedData = discount.limited_relation_product_data;
162
+ let hasApplicableProduct = false;
163
+ for (const item of productList) {
164
+ const product = this.hooks.getProduct(item);
165
+ if (limitedData.type === "product_all") {
166
+ hasApplicableProduct = true;
167
+ break;
168
+ } else if ((_a = limitedData.product_ids) == null ? void 0 : _a.includes(product.id)) {
169
+ hasApplicableProduct = true;
170
+ break;
171
+ }
172
+ }
173
+ if (!hasApplicableProduct) {
174
+ return import_types.UnavailableReason.ProductNotApplicable;
175
+ }
176
+ }
177
+ return import_types.UnavailableReason.Unknown;
178
+ }
141
179
  calcDiscount({
142
180
  discountList,
143
181
  productList,
@@ -413,7 +451,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
413
451
  }
414
452
  const applicableProducts = [];
415
453
  sortedFlattenedList.forEach((flatItem) => {
416
- var _a, _b;
454
+ var _a, _b, _c;
417
455
  const occupyingDiscountId = occupiedItems.get(flatItem._id);
418
456
  if (occupyingDiscountId !== void 0 && occupyingDiscountId !== discount.id) {
419
457
  return;
@@ -433,7 +471,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
433
471
  num: flatItem.num
434
472
  };
435
473
  }
436
- const quantity = flatItem.type === "main" ? product.quantity || 1 : (product.num || 1) * (((_a = flatItem.parentProduct) == null ? void 0 : _a.quantity) || 1);
474
+ const quantity = flatItem.type === "main" ? product.num || product.quantity || 1 : (product.num || product.quantity || 1) * (((_a = flatItem.parentProduct) == null ? void 0 : _a.num) || ((_b = flatItem.parentProduct) == null ? void 0 : _b.quantity) || 1);
437
475
  const originalAmount = flatItem.type === "main" ? Number(product.price ?? 0) : Number(flatItem.original_price ?? flatItem.price ?? 0);
438
476
  const productData = {
439
477
  productId: flatItem._id,
@@ -441,7 +479,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
441
479
  quantity
442
480
  };
443
481
  if (flatItem.type === "bundle") {
444
- productData.parentQuantity = ((_b = flatItem.parentProduct) == null ? void 0 : _b.quantity) || 1;
482
+ productData.parentQuantity = ((_c = flatItem.parentProduct) == null ? void 0 : _c.quantity) || 1;
445
483
  }
446
484
  applicableProducts.push(productData);
447
485
  });
@@ -1,4 +1,10 @@
1
1
  import { Discount } from '../Discount/types';
2
+ export declare enum UnavailableReason {
3
+ TimeLimit = "time_limit",
4
+ ProductNotApplicable = "product_not_applicable",
5
+ AlreadyUsed = "already_used",
6
+ Unknown = "unknown"
7
+ }
2
8
  export declare enum RulesHooks {
3
9
  OnRulesListChange = "rules:onRulesListChange",
4
10
  OnDestroy = "rules:onDestroy"
@@ -19,9 +19,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/modules/Rules/types.ts
20
20
  var types_exports = {};
21
21
  __export(types_exports, {
22
- RulesHooks: () => RulesHooks
22
+ RulesHooks: () => RulesHooks,
23
+ UnavailableReason: () => UnavailableReason
23
24
  });
24
25
  module.exports = __toCommonJS(types_exports);
26
+ var UnavailableReason = /* @__PURE__ */ ((UnavailableReason2) => {
27
+ UnavailableReason2["TimeLimit"] = "time_limit";
28
+ UnavailableReason2["ProductNotApplicable"] = "product_not_applicable";
29
+ UnavailableReason2["AlreadyUsed"] = "already_used";
30
+ UnavailableReason2["Unknown"] = "unknown";
31
+ return UnavailableReason2;
32
+ })(UnavailableReason || {});
25
33
  var RulesHooks = /* @__PURE__ */ ((RulesHooks2) => {
26
34
  RulesHooks2["OnRulesListChange"] = "rules:onRulesListChange";
27
35
  RulesHooks2["OnDestroy"] = "rules:onDestroy";
@@ -29,5 +37,6 @@ var RulesHooks = /* @__PURE__ */ ((RulesHooks2) => {
29
37
  })(RulesHooks || {});
30
38
  // Annotate the CommonJS export names for ESM import in node:
31
39
  0 && (module.exports = {
32
- RulesHooks
40
+ RulesHooks,
41
+ UnavailableReason
33
42
  });
@@ -25,4 +25,13 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
25
25
  setOtherProductsIds(ids: number[]): void;
26
26
  getOtherProductsIds(): number[];
27
27
  storeChange(): void;
28
+ /**
29
+ * 传入一个时间, 判断改时间是否在schedule 内
30
+ * @param param0 { date: string, schedule: any } date: 日期, schedule: schedule
31
+ * @returns
32
+ */
33
+ static isInScheduleByDate({ date, schedule, }: {
34
+ date: string;
35
+ schedule: any;
36
+ }): boolean | undefined;
28
37
  }
@@ -38,6 +38,7 @@ var import_dayjs = __toESM(require("dayjs"));
38
38
  var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
39
39
  var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
40
40
  var import_utils = require("../Date/utils");
41
+ var import_utils2 = require("./utils");
41
42
  import_dayjs.default.extend(import_isSameOrBefore.default);
42
43
  import_dayjs.default.extend(import_isSameOrAfter.default);
43
44
  var ScheduleModule = class extends import_BaseModule.BaseModule {
@@ -158,6 +159,65 @@ var ScheduleModule = class extends import_BaseModule.BaseModule {
158
159
  });
159
160
  }
160
161
  }
162
+ /**
163
+ * 传入一个时间, 判断改时间是否在schedule 内
164
+ * @param param0 { date: string, schedule: any } date: 日期, schedule: schedule
165
+ * @returns
166
+ */
167
+ static isInScheduleByDate({
168
+ date,
169
+ schedule
170
+ }) {
171
+ var _a, _b, _c, _d;
172
+ if (schedule.start_time && schedule.end_time) {
173
+ const isBeforeStartTime = (0, import_dayjs.default)(date).isBefore(
174
+ (0, import_dayjs.default)(schedule.start_time)
175
+ );
176
+ const isAfterEndTime = (0, import_dayjs.default)(date).isAfter((0, import_dayjs.default)(schedule.end_time));
177
+ if (isBeforeStartTime || isAfterEndTime) {
178
+ return false;
179
+ }
180
+ }
181
+ let _schedule = {
182
+ ...schedule,
183
+ // 开始时间向前推一天
184
+ start_time: (0, import_dayjs.default)(date).subtract(1, "day").format("YYYY-MM-DD HH:mm:ss"),
185
+ end_time: (0, import_dayjs.default)(date).add(1, "day").format("YYYY-MM-DD HH:mm:ss")
186
+ };
187
+ if (((_b = (_a = _schedule.repeat_rule) == null ? void 0 : _a.end) == null ? void 0 : _b.type) === "never") {
188
+ _schedule = {
189
+ ..._schedule,
190
+ repeat_rule: {
191
+ ..._schedule.repeat_rule,
192
+ end: {
193
+ type: "date",
194
+ end_date: _schedule.end_time,
195
+ occurrence: null
196
+ }
197
+ }
198
+ };
199
+ }
200
+ if (((_d = (_c = _schedule.repeat_rule) == null ? void 0 : _c.end) == null ? void 0 : _d.type) === "date") {
201
+ _schedule = {
202
+ ..._schedule,
203
+ repeat_rule: {
204
+ ..._schedule.repeat_rule,
205
+ end: {
206
+ ..._schedule.repeat_rule.end,
207
+ end_date: _schedule.end_time
208
+ }
209
+ }
210
+ };
211
+ }
212
+ const dateRanges = (0, import_utils2.calcScheduleDateRange)({ ..._schedule });
213
+ for (const range of dateRanges) {
214
+ const startTime = (0, import_dayjs.default)(range.start);
215
+ const endTime = (0, import_dayjs.default)(range.end);
216
+ if ((0, import_dayjs.default)(date).isSameOrAfter(startTime) && (0, import_dayjs.default)(date).isSameOrBefore(endTime)) {
217
+ return true;
218
+ }
219
+ }
220
+ }
161
221
  };
162
222
  // Annotate the CommonJS export names for ESM import in node:
163
223
  0 && (module.exports = {
@@ -13,6 +13,7 @@ export declare class SummaryModule extends BaseModule implements Module, ISummar
13
13
  private fatherModule;
14
14
  constructor(name?: string, version?: string);
15
15
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
16
+ getSurchargeList(): Promise<void>;
16
17
  getSummary(cartItems: CartItem[]): Promise<ISummaryState['summary']>;
17
18
  /**
18
19
  * 获取协议
@@ -21,4 +22,6 @@ export declare class SummaryModule extends BaseModule implements Module, ISummar
21
22
  */
22
23
  getProtocol(protocolId: string): Promise<any>;
23
24
  storeChange(): void;
25
+ private getTaxforUtils;
26
+ private getSurchargeforUtils;
24
27
  }
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/modules/Summary/index.ts
@@ -22,7 +32,9 @@ __export(Summary_exports, {
22
32
  SummaryModule: () => SummaryModule
23
33
  });
24
34
  module.exports = __toCommonJS(Summary_exports);
35
+ var import_decimal = __toESM(require("decimal.js"));
25
36
  var import_BaseModule = require("../BaseModule");
37
+ var import_Schedule = require("../Schedule");
26
38
  var import_utils = require("./utils");
27
39
  var SummaryModule = class extends import_BaseModule.BaseModule {
28
40
  constructor(name, version) {
@@ -50,11 +62,30 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
50
62
  if (!this.shopStore) {
51
63
  throw new Error("SummaryModule 需要 shopStore 插件支持");
52
64
  }
65
+ this.getSurchargeList();
66
+ }
67
+ async getSurchargeList() {
68
+ const surchargeList = await this.request.get("/order/custom-surcharge/available/v2", {
69
+ channel: "online-store",
70
+ is_assemble_product_data: 1,
71
+ is_assemble_schedule_data: 1,
72
+ with: ["relationSchedule"]
73
+ });
74
+ this.store.surchargeList = (surchargeList == null ? void 0 : surchargeList.data) || [];
53
75
  }
54
76
  async getSummary(cartItems) {
55
- var _a, _b;
77
+ var _a, _b, _c;
56
78
  const shopInfo = ((_b = (_a = this.shopStore.get("core")) == null ? void 0 : _a.core) == null ? void 0 : _b.shop) || {};
57
- const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems);
79
+ const scheduleModule = this.core.getModule("appointmentBooking_schedule");
80
+ const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
81
+ const scheduleList = scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
82
+ const scheduleById = {};
83
+ if (Array.isArray(scheduleList)) {
84
+ for (let item of scheduleList) {
85
+ scheduleById[item.id] = item;
86
+ }
87
+ }
88
+ const summary = (0, import_utils.calculatePriceDetails)(shopInfo, cartItems, (_c = import_Schedule.ScheduleModule) == null ? void 0 : _c.isInScheduleByDate, this.store.surchargeList, scheduleById);
58
89
  this.store.summary = summary;
59
90
  return this.store.summary;
60
91
  }
@@ -76,6 +107,34 @@ var SummaryModule = class extends import_BaseModule.BaseModule {
76
107
  });
77
108
  }
78
109
  }
110
+ getTaxforUtils(items, shopInfo, subtotal) {
111
+ return (0, import_utils.getTax)({ service: items, bookingDetail: null, bookingId: void 0 }, {
112
+ computed: {
113
+ productExpectAmount: subtotal,
114
+ shopDiscount: 0
115
+ },
116
+ isEdit: false,
117
+ tax_rate: shopInfo == null ? void 0 : shopInfo.tax_rate,
118
+ is_price_include_tax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax
119
+ });
120
+ }
121
+ getSurchargeforUtils(items) {
122
+ const scheduleModule = this.core.getModule("appointmentBooking_schedule");
123
+ const needScheduleIds = this.store.surchargeList.map((item) => item.available_schedule_ids).flat();
124
+ const scheduleList = scheduleModule == null ? void 0 : scheduleModule.getScheduleListByIds(needScheduleIds);
125
+ const scheduleById = {};
126
+ if (Array.isArray(scheduleList)) {
127
+ for (let item of scheduleList) {
128
+ scheduleById[item.id] = item;
129
+ }
130
+ }
131
+ const surchargeList = (0, import_utils.getSurcharge)({ service: items, addons: [], bookingDetail: null, bookingId: void 0 }, { isEdit: false, isInScheduleByDate: import_Schedule.ScheduleModule.isInScheduleByDate, surcharge_list: this.store.surchargeList, scheduleById });
132
+ const surchargeAmount = new import_decimal.default((0, import_utils.getSurchargeAmount)({ bookingDetail: null, bookingId: void 0 }, surchargeList, { isEdit: false }));
133
+ return {
134
+ surchargeList,
135
+ surchargeAmount: surchargeAmount.toFixed(2)
136
+ };
137
+ }
79
138
  };
80
139
  // Annotate the CommonJS export names for ESM import in node:
81
140
  0 && (module.exports = {
@@ -1,5 +1,6 @@
1
1
  import { CartItem } from '../Cart/types';
2
2
  export interface ISummaryState {
3
+ surchargeList: any[];
3
4
  summary: {
4
5
  /** 商品总价 */
5
6
  subtotal: string | number;
@@ -11,6 +12,12 @@ export interface ISummaryState {
11
12
  totalTaxFee?: string | number;
12
13
  /** 商品价格是否包含费率 */
13
14
  isPriceIncludeTax?: 0 | 1;
15
+ /** 附加费金额 */
16
+ surchargeAmount?: string | number;
17
+ /** 附加费列表 */
18
+ surcharge?: any[];
19
+ /** 税率 */
20
+ taxRate?: string | number;
14
21
  /** 定金 */
15
22
  deposit?: {
16
23
  /** 定金总价 */