@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
@@ -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
  * 购物车状态接口
@@ -13,6 +13,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
13
13
  import Decimal from 'decimal.js';
14
14
  import { isNormalProduct } from "../../Product/utils";
15
15
  import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
16
+ import { calcDiscountListDifference } from "../../Summary/utils";
16
17
 
17
18
  /**
18
19
  * @title 处理组合商品
@@ -69,6 +70,11 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
69
70
  num: num,
70
71
  discounts: discounts
71
72
  });
73
+ cartItem.totalDifference = getTotalDifference({
74
+ product: product,
75
+ bundle: bundle,
76
+ discounts: discounts
77
+ });
72
78
  cartItem.summaryTotal = cartItem.total * (num || 1);
73
79
  cartItem.origin_total = getProductOriginTotalPrice({
74
80
  product: product,
@@ -218,6 +224,19 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
218
224
  }
219
225
  return Math.max(0, price);
220
226
  };
227
+ var getTotalDifference = function getTotalDifference(params) {
228
+ var bundle = params.bundle,
229
+ discounts = params.discounts;
230
+ var bundleDiscountList = [];
231
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
232
+ bundle.forEach(function (currentValue) {
233
+ bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((currentValue === null || currentValue === void 0 ? void 0 : currentValue.discount_list) || []));
234
+ });
235
+ }
236
+ var allDiscounts = [].concat(_toConsumableArray(discounts || []), bundleDiscountList);
237
+ var productDiscountProductDiscountDifference = calcDiscountListDifference(allDiscounts);
238
+ return productDiscountProductDiscountDifference || 0;
239
+ };
221
240
 
222
241
  /**
223
242
  * 获取商品原始总价
@@ -304,7 +323,8 @@ export var formatBundle = function formatBundle(bundle) {
304
323
  options: formatOptions(item === null || item === void 0 ? void 0 : item.option),
305
324
  _bundle_product_id: item._bundle_product_id,
306
325
  discount_list: item.discount_list,
307
- originBundleItem: item.originBundleItem || item
326
+ originBundleItem: item.originBundleItem || item,
327
+ is_charge_tax: item === null || item === void 0 ? void 0 : item.is_charge_tax
308
328
  };
309
329
  });
310
330
  };
@@ -57,6 +57,12 @@ function _updateAllCartItemPrice() {
57
57
  if (targetBundleItem.price_type === 'markdown') {
58
58
  targetBundleItem.price = new Decimal(targetBundleItem.price || 0).mul(-1).toNumber();
59
59
  }
60
+ // 如果有选择 option,还需要加上 option 的价格
61
+ if (n.option) {
62
+ targetBundleItem.price = new Decimal(targetBundleItem.price || 0).add(n.option.reduce(function (pre, cur) {
63
+ return pre + new Decimal(cur.price || 0).mul(cur.num || 1).toNumber();
64
+ }, 0)).toNumber();
65
+ }
60
66
  if (targetBundleItem) {
61
67
  return _objectSpread(_objectSpread({}, n), {}, {
62
68
  price: targetBundleItem.price,
@@ -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
  }
@@ -85,6 +85,14 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
85
85
  }, {
86
86
  key: "setDateRange",
87
87
  value: function setDateRange(dateRange) {
88
+ var _this2 = this;
89
+ // 如果 dateRange 传入的日期里没有 resource,但是本地有的,要尝试补充下
90
+ dateRange.forEach(function (item) {
91
+ var _item$resource;
92
+ if (!((_item$resource = item.resource) !== null && _item$resource !== void 0 && _item$resource.length)) {
93
+ item.resource = _this2.getResourcesListByDate(item.date);
94
+ }
95
+ });
88
96
  this.store.dateRange = dateRange;
89
97
  }
90
98
  }, {
@@ -157,10 +165,10 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
157
165
  return n.date === item.date;
158
166
  });
159
167
  if (currentItemIndex !== -1) {
160
- var _item$resource, _currentItem$resource3;
168
+ var _item$resource2, _currentItem$resource3;
161
169
  var currentItem = currentDateList[currentItemIndex];
162
170
  // 看那一天的数据有没有相同的,把不同的资源合并进去即可
163
- var newResource = (_item$resource = item.resource) === null || _item$resource === void 0 ? void 0 : _item$resource.filter(function (n) {
171
+ var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.filter(function (n) {
164
172
  var _currentItem$resource2;
165
173
  return !((_currentItem$resource2 = currentItem.resource) !== null && _currentItem$resource2 !== void 0 && _currentItem$resource2.some(function (m) {
166
174
  return m.id === n.id;
@@ -168,8 +176,8 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
168
176
  });
169
177
  // 如果有相同的资源,则使用 item 中的新的resource.times,而不是 currentItem 中的
170
178
  (_currentItem$resource3 = currentItem.resource) === null || _currentItem$resource3 === void 0 || _currentItem$resource3.forEach(function (n) {
171
- var _item$resource2;
172
- var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.find(function (m) {
179
+ var _item$resource3;
180
+ var newResource = (_item$resource3 = item.resource) === null || _item$resource3 === void 0 ? void 0 : _item$resource3.find(function (m) {
173
181
  return m.id === n.id;
174
182
  });
175
183
  if (newResource) {
@@ -261,7 +269,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
261
269
  }, {
262
270
  key: "correctResourceTimeSlots",
263
271
  value: function correctResourceTimeSlots(resourcesData) {
264
- var _this2 = this;
272
+ var _this3 = this;
265
273
  return resourcesData.map(function (resource) {
266
274
  // 检查资源是否有 times 数组和 start_time
267
275
  if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
@@ -284,7 +292,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
284
292
  // 如果 start_at 早于资源的 start_time,需要修正
285
293
  if (startAt.isBefore(resourceStartTime)) {
286
294
  // 将 start_time 向上取整到下一个10分钟整数
287
- var roundedStartTime = _this2.roundUpToNext10Minutes(resourceStartTime);
295
+ var roundedStartTime = _this3.roundUpToNext10Minutes(resourceStartTime);
288
296
  var roundedStartTimeDayjs = dayjs(roundedStartTime);
289
297
  console.log("[DateModule] \u4FEE\u6B63\u65F6\u95F4\u6BB5\u5F00\u59CB\u65F6\u95F4: ".concat(timeSlot.start_at, " -> ").concat(roundedStartTime, " (\u8D44\u6E90ID: ").concat(resource.id, ", \u539F\u59CBstart_time: ").concat(resource.start_time, ")"));
290
298
 
@@ -393,9 +401,9 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
393
401
  value: function getResourcesListByDate(date) {
394
402
  var _dateList$find;
395
403
  var dateList = this.store.dateList;
396
- var resourcesList = (_dateList$find = dateList.find(function (item) {
404
+ var resourcesList = (dateList === null || dateList === void 0 || (_dateList$find = dateList.find(function (item) {
397
405
  return item.date === date;
398
- })) === null || _dateList$find === void 0 ? void 0 : _dateList$find.resource;
406
+ })) === null || _dateList$find === void 0 ? void 0 : _dateList$find.resource) || [];
399
407
  return resourcesList;
400
408
  }
401
409
  }]);
@@ -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[];
@@ -190,7 +190,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
190
190
  relation_product: 1,
191
191
  with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
192
192
  order_behavior_count: 1,
193
- order_behavior_count_customer_id: customerId || 1
193
+ order_behavior_count_customer_id: customerId || 1,
194
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
194
195
  });
195
196
  case 2:
196
197
  result = _context5.sent;
@@ -137,17 +137,16 @@ export var ProductList = /*#__PURE__*/function (_BaseModule) {
137
137
  productsData = _context3.sent;
138
138
  sortedList = (productsData.data.list || []).slice().sort(function (a, b) {
139
139
  return Number(b.sort) - Number(a.sort);
140
- });
141
- if (sortedList.length) {
142
- sortedList.forEach(function (n) {
143
- if (n.is_eject !== 1 && n['schedule.ids'] && n['schedule.ids'].length) {
144
- n.is_eject = 1;
145
- }
146
- });
147
- }
140
+ }); // if (sortedList.length) {
141
+ // sortedList.forEach((n: any) => {
142
+ // if (n.is_eject !== 1 && n['schedule.ids'] && n['schedule.ids'].length) {
143
+ // n.is_eject = 1
144
+ // }
145
+ // })
146
+ // }
148
147
  this.addProduct(sortedList);
149
148
  return _context3.abrupt("return", sortedList);
150
- case 11:
149
+ case 10:
151
150
  case "end":
152
151
  return _context3.stop();
153
152
  }
@@ -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[];
@@ -1,6 +1,7 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
7
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -24,7 +25,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
24
25
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
26
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
27
  import { BaseModule } from "../BaseModule";
27
- import { RulesHooks } from "./types";
28
+ import { RulesHooks, UnavailableReason } from "./types";
28
29
  import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, isOrderLevelFixedAmountDiscount, calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
29
30
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
30
31
  import Decimal from 'decimal.js';
@@ -138,7 +139,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
138
139
  return {
139
140
  isAvailable: false,
140
141
  discountList: oldDiscountList,
141
- productList: productList
142
+ productList: productList,
143
+ unavailableReason: UnavailableReason.AlreadyUsed
142
144
  };
143
145
  }
144
146
 
@@ -183,12 +185,93 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
183
185
  }
184
186
  }
185
187
  });
188
+
189
+ // 如果券不可用,判断不可用原因
190
+ var unavailableReason;
191
+ if (!hasApplicableDiscount) {
192
+ unavailableReason = this.getUnavailableReason(newDiscountList, productList);
193
+ }
186
194
  return {
187
195
  isAvailable: hasApplicableDiscount,
188
196
  discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
189
- productList: hasApplicableDiscount ? result.productList : productList
197
+ productList: hasApplicableDiscount ? result.productList : productList,
198
+ unavailableReason: unavailableReason
190
199
  };
191
200
  }
201
+
202
+ // 获取券不可用的原因
203
+ }, {
204
+ key: "getUnavailableReason",
205
+ value: function getUnavailableReason(discountList, productList) {
206
+ // 检查时间限制
207
+ var _iterator = _createForOfIteratorHelper(discountList),
208
+ _step;
209
+ try {
210
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
211
+ var discount = _step.value;
212
+ var _iterator3 = _createForOfIteratorHelper(productList),
213
+ _step3;
214
+ try {
215
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
216
+ var item = _step3.value;
217
+ var product = this.hooks.getProduct(item);
218
+ var bookingTime = ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
219
+ var filteredList = filterDiscountListByBookingTime([discount], bookingTime);
220
+ if (filteredList.length === 0) {
221
+ return UnavailableReason.TimeLimit;
222
+ }
223
+ }
224
+ } catch (err) {
225
+ _iterator3.e(err);
226
+ } finally {
227
+ _iterator3.f();
228
+ }
229
+ }
230
+
231
+ // 检查商品适用性
232
+ } catch (err) {
233
+ _iterator.e(err);
234
+ } finally {
235
+ _iterator.f();
236
+ }
237
+ var _iterator2 = _createForOfIteratorHelper(discountList),
238
+ _step2;
239
+ try {
240
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
241
+ var _discount = _step2.value;
242
+ var limitedData = _discount.limited_relation_product_data;
243
+ var hasApplicableProduct = false;
244
+ var _iterator4 = _createForOfIteratorHelper(productList),
245
+ _step4;
246
+ try {
247
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
248
+ var _limitedData$product_;
249
+ var _item = _step4.value;
250
+ var _product = this.hooks.getProduct(_item);
251
+ if (limitedData.type === 'product_all') {
252
+ hasApplicableProduct = true;
253
+ break;
254
+ } else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(_product.id)) {
255
+ hasApplicableProduct = true;
256
+ break;
257
+ }
258
+ }
259
+ } catch (err) {
260
+ _iterator4.e(err);
261
+ } finally {
262
+ _iterator4.f();
263
+ }
264
+ if (!hasApplicableProduct) {
265
+ return UnavailableReason.ProductNotApplicable;
266
+ }
267
+ }
268
+ } catch (err) {
269
+ _iterator2.e(err);
270
+ } finally {
271
+ _iterator2.f();
272
+ }
273
+ return UnavailableReason.Unknown;
274
+ }
192
275
  }, {
193
276
  key: "calcDiscount",
194
277
  value: function calcDiscount(_ref2, options) {
@@ -487,7 +570,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
487
570
 
488
571
  // 辅助函数:检查商品是否对某个折扣卡可用
489
572
  var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
490
- var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
573
+ var _product2, _product3, _product4, _flatItem$bundleItem, _flatItem$bundleItem2, _product5;
491
574
  var product;
492
575
  if (flatItem.type === 'main') {
493
576
  product = flatItem.product;
@@ -506,7 +589,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
506
589
  }
507
590
 
508
591
  // 编辑的商品使用了优惠券不可用
509
- var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
592
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
510
593
  return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
511
594
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
512
595
  return d.id;
@@ -527,7 +610,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
527
610
  var limitedData = discount.limited_relation_product_data;
528
611
 
529
612
  // 时间限制检查
530
- var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
613
+ var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
531
614
  if (!timeLimit) {
532
615
  return false;
533
616
  }
@@ -608,7 +691,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
608
691
  // 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
609
692
  var applicableProducts = [];
610
693
  sortedFlattenedList.forEach(function (flatItem) {
611
- var _flatItem$parentProdu2, _product$price, _ref5, _flatItem$original_pr;
694
+ var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref5, _flatItem$original_pr;
612
695
  // 🔥 检查该商品是否被其他专属折扣卡占用
613
696
  var occupyingDiscountId = occupiedItems.get(flatItem._id);
614
697
  if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
@@ -632,7 +715,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
632
715
  }
633
716
 
634
717
  // 对于 bundle 子商品,quantity 需要乘以主商品的购买数量
635
- var quantity = flatItem.type === 'main' ? product.quantity || 1 : (product.num || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.quantity) || 1);
718
+ var quantity = flatItem.type === 'main' ? product.num || product.quantity || 1 : (product.num || product.quantity || 1) * (((_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.num) || ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1);
636
719
 
637
720
  // 对于主商品:使用 price
638
721
  // 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
@@ -647,8 +730,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
647
730
 
648
731
  // 子商品需要传递主商品数量
649
732
  if (flatItem.type === 'bundle') {
650
- var _flatItem$parentProdu3;
651
- productData.parentQuantity = ((_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.quantity) || 1;
733
+ var _flatItem$parentProdu4;
734
+ productData.parentQuantity = ((_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.quantity) || 1;
652
735
  }
653
736
  applicableProducts.push(productData);
654
737
  });
@@ -675,7 +758,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
675
758
  product = flatItem.product;
676
759
  originProduct = flatItem.originProduct;
677
760
  } else {
678
- var _flatItem$parentProdu4;
761
+ var _flatItem$parentProdu5;
679
762
  // bundle子商品:构造虚拟商品对象
680
763
  product = {
681
764
  _id: flatItem._id,
@@ -687,12 +770,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
687
770
  origin_total: flatItem.origin_total,
688
771
  booking_id: flatItem.booking_id,
689
772
  discount_list: flatItem.discount_list || [],
690
- startDate: (_flatItem$parentProdu4 = flatItem.parentProduct) === null || _flatItem$parentProdu4 === void 0 ? void 0 : _flatItem$parentProdu4.startDate
773
+ startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
691
774
  };
692
775
  originProduct = flatItem.originProduct;
693
776
  }
694
777
  addModeDiscount.forEach(function (discount) {
695
- var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4;
778
+ var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4;
696
779
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
697
780
 
698
781
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
@@ -702,12 +785,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
702
785
  holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
703
786
  }, holders);
704
787
  var timeLimit = true;
705
- timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
788
+ timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
706
789
  // 是符合折扣的商品
707
790
  var isLimitedProduct = (limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
708
791
 
709
792
  // 编辑的商品 使用了优惠券不可用
710
- var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
793
+ var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
711
794
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
712
795
  })) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
713
796
  return discount.id;
@@ -759,14 +842,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
759
842
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
760
843
  // 🔥 使用扁平化后的列表进行处理
761
844
  sortedFlattenedList.forEach(function (flatItem, index) {
762
- var _product9, _product$discount_lis2, _product10;
845
+ var _product10, _product$discount_lis2, _product11;
763
846
  // 获取商品数据
764
847
  var product, originProduct;
765
848
  if (flatItem.type === 'main') {
766
849
  product = flatItem.product;
767
850
  originProduct = flatItem.originProduct;
768
851
  } else {
769
- var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu5;
852
+ var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu6;
770
853
  // bundle子商品
771
854
  product = {
772
855
  _id: flatItem._id,
@@ -779,13 +862,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
779
862
  origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
780
863
  booking_id: flatItem.booking_id,
781
864
  discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || [],
782
- startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
865
+ startDate: (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate
783
866
  };
784
867
  originProduct = flatItem.originProduct;
785
868
  }
786
869
 
787
870
  // 已有优惠的商品跳过
788
- if ((_product9 = product) !== null && _product9 !== void 0 && _product9.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product10 = product) !== null && _product10 !== void 0 && (_product10 = _product10.discount_list) !== null && _product10 !== void 0 && _product10.every(function (discount) {
871
+ if ((_product10 = product) !== null && _product10 !== void 0 && _product10.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product11 = product) !== null && _product11 !== void 0 && (_product11 = _product11.discount_list) !== null && _product11 !== void 0 && _product11.every(function (discount) {
789
872
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
790
873
  })) {
791
874
  if (flatItem.type === 'main') {
@@ -857,12 +940,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
857
940
  // 如果是手动折扣,则不适用优惠券
858
941
  var isManualDiscount = false;
859
942
  if (flatItem.type === 'main') {
860
- var _product$discount_lis5, _product11, _product11$every;
943
+ var _product$discount_lis5, _product12, _product12$every;
861
944
  // 主商品:判断自身是否手动折扣
862
945
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
863
946
  var _ref6;
864
947
  return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
865
- }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
948
+ }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
866
949
  return item.type === 'product';
867
950
  })));
868
951
  } else {
@@ -891,11 +974,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
891
974
  }
892
975
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
893
976
  if (flatItem.type === 'bundle') {
894
- var _product$discount_lis7, _flatItem$parentProdu6;
977
+ var _product$discount_lis7, _flatItem$parentProdu7;
895
978
  if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
896
979
  var _item$discount2;
897
980
  return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
898
- }) || (_flatItem$parentProdu6 = flatItem.parentProduct) !== null && _flatItem$parentProdu6 !== void 0 && (_flatItem$parentProdu6 = _flatItem$parentProdu6.discount_list) !== null && _flatItem$parentProdu6 !== void 0 && _flatItem$parentProdu6.some(function (item) {
981
+ }) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
899
982
  var _item$discount3;
900
983
  return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
901
984
  })) {
@@ -917,14 +1000,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
917
1000
  }
918
1001
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
919
1002
  if (flatItem.type === 'bundle') {
920
- var _product$discount_lis9, _flatItem$parentProdu7;
1003
+ var _product$discount_lis9, _flatItem$parentProdu8;
921
1004
  if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
922
1005
  var _options$selectedList2;
923
1006
  return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
924
1007
  var _item$discount5;
925
1008
  return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
926
1009
  });
927
- }) || (_flatItem$parentProdu7 = flatItem.parentProduct) !== null && _flatItem$parentProdu7 !== void 0 && (_flatItem$parentProdu7 = _flatItem$parentProdu7.discount_list) !== null && _flatItem$parentProdu7 !== void 0 && _flatItem$parentProdu7.some(function (item) {
1010
+ }) || (_flatItem$parentProdu8 = flatItem.parentProduct) !== null && _flatItem$parentProdu8 !== void 0 && (_flatItem$parentProdu8 = _flatItem$parentProdu8.discount_list) !== null && _flatItem$parentProdu8 !== void 0 && _flatItem$parentProdu8.some(function (item) {
928
1011
  var _options$selectedList3;
929
1012
  return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
930
1013
  var _item$discount6;
@@ -1177,7 +1260,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1177
1260
  }));
1178
1261
  }
1179
1262
  } else {
1180
- var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu8;
1263
+ var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
1181
1264
  // 折扣卡:不拆分数量,直接应用
1182
1265
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
1183
1266
  usedDiscounts.set(_selectedDiscount3.id, true);
@@ -1223,7 +1306,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1223
1306
  }, _productDiscountDifference !== undefined && {
1224
1307
  product_discount_difference: _productDiscountDifference
1225
1308
  }),
1226
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu8 = flatItem.parentProduct) === null || _flatItem$parentProdu8 === void 0 ? void 0 : _flatItem$parentProdu8.num) || 1)
1309
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1227
1310
  };
1228
1311
 
1229
1312
  // 记录实际应用的折扣
@@ -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"
@@ -1,3 +1,11 @@
1
+ // 券不可用原因枚举
2
+ export var UnavailableReason = /*#__PURE__*/function (UnavailableReason) {
3
+ UnavailableReason["TimeLimit"] = "time_limit";
4
+ UnavailableReason["ProductNotApplicable"] = "product_not_applicable";
5
+ UnavailableReason["AlreadyUsed"] = "already_used";
6
+ UnavailableReason["Unknown"] = "unknown";
7
+ return UnavailableReason;
8
+ }({});
1
9
  export var RulesHooks = /*#__PURE__*/function (RulesHooks) {
2
10
  RulesHooks["OnRulesListChange"] = "rules:onRulesListChange";
3
11
  RulesHooks["OnDestroy"] = "rules:onDestroy";
@@ -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
  }