@pisell/pisellos 1.0.85 → 1.0.87

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.
@@ -14,6 +14,8 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
14
14
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
15
15
  setDiscountList(discountList: Discount[]): Promise<void>;
16
16
  getDiscountList(): Discount[];
17
+ setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
18
+ getOriginalDiscountList(): Discount[];
17
19
  loadPrepareConfig(params: {
18
20
  action?: 'create';
19
21
  with_good_pass: 0 | 1;
@@ -46,7 +46,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
46
46
  key: "initialize",
47
47
  value: function () {
48
48
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
49
- var _options$initialState, _options$otherParams, _options$otherParams2;
49
+ var _options$initialState, _options$initialState2, _options$otherParams, _options$otherParams2;
50
50
  return _regeneratorRuntime().wrap(function _callee$(_context) {
51
51
  while (1) switch (_context.prev = _context.next) {
52
52
  case 0:
@@ -57,6 +57,11 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
57
57
  } else {
58
58
  this.store.discountList = [];
59
59
  }
60
+ if (Array.isArray(options === null || options === void 0 || (_options$initialState2 = options.initialState) === null || _options$initialState2 === void 0 ? void 0 : _options$initialState2.originalDiscountList)) {
61
+ this.store.originalDiscountList = options === null || options === void 0 ? void 0 : options.initialState.originalDiscountList;
62
+ } else {
63
+ this.store.originalDiscountList = [];
64
+ }
60
65
  if (options !== null && options !== void 0 && (_options$otherParams = options.otherParams) !== null && _options$otherParams !== void 0 && _options$otherParams.cacheId) {
61
66
  this.openCache = options.otherParams.openCache;
62
67
  this.cacheId = options.otherParams.cacheId;
@@ -69,17 +74,17 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
69
74
  this.request = core.getPlugin('request');
70
75
  this.window = core.getPlugin('window');
71
76
  if (this.request) {
72
- _context.next = 9;
77
+ _context.next = 10;
73
78
  break;
74
79
  }
75
80
  throw new Error('discount模块需要 request 插件支持');
76
- case 9:
81
+ case 10:
77
82
  if (this.window) {
78
- _context.next = 11;
83
+ _context.next = 12;
79
84
  break;
80
85
  }
81
86
  throw new Error('discount模块需要 window 插件支持');
82
- case 11:
87
+ case 12:
83
88
  case "end":
84
89
  return _context.stop();
85
90
  }
@@ -116,28 +121,54 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
116
121
  value: function getDiscountList() {
117
122
  return this.store.discountList;
118
123
  }
124
+
125
+ // 设置原始优惠券列表
126
+ }, {
127
+ key: "setOriginalDiscountList",
128
+ value: function () {
129
+ var _setOriginalDiscountList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(originalDiscountList) {
130
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
131
+ while (1) switch (_context3.prev = _context3.next) {
132
+ case 0:
133
+ this.store.originalDiscountList = originalDiscountList;
134
+ case 1:
135
+ case "end":
136
+ return _context3.stop();
137
+ }
138
+ }, _callee3, this);
139
+ }));
140
+ function setOriginalDiscountList(_x4) {
141
+ return _setOriginalDiscountList.apply(this, arguments);
142
+ }
143
+ return setOriginalDiscountList;
144
+ }() // 获取原始优惠券列表
145
+ }, {
146
+ key: "getOriginalDiscountList",
147
+ value: function getOriginalDiscountList() {
148
+ return this.store.originalDiscountList || [];
149
+ }
119
150
  }, {
120
151
  key: "loadPrepareConfig",
121
152
  value: function () {
122
- var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
153
+ var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
123
154
  var _prepareConfig$data, _prepareConfig$data2;
124
155
  var prepareConfig, goodPassList;
125
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
126
- while (1) switch (_context3.prev = _context3.next) {
156
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
157
+ while (1) switch (_context4.prev = _context4.next) {
127
158
  case 0:
128
- _context3.next = 2;
159
+ _context4.next = 2;
129
160
  return this.request.post("/order/prepare/config", params);
130
161
  case 2:
131
- prepareConfig = _context3.sent;
162
+ prepareConfig = _context4.sent;
132
163
  goodPassList = this.filterEnabledDiscountList([].concat(_toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data = prepareConfig.data) === null || _prepareConfig$data === void 0 ? void 0 : _prepareConfig$data.good_pass_list) || []), _toConsumableArray((prepareConfig === null || prepareConfig === void 0 || (_prepareConfig$data2 = prepareConfig.data) === null || _prepareConfig$data2 === void 0 ? void 0 : _prepareConfig$data2.discount_card_list) || []))) || []; // this.setDiscountList(goodPassList);
133
- return _context3.abrupt("return", goodPassList);
164
+ return _context4.abrupt("return", goodPassList);
134
165
  case 5:
135
166
  case "end":
136
- return _context3.stop();
167
+ return _context4.stop();
137
168
  }
138
- }, _callee3, this);
169
+ }, _callee4, this);
139
170
  }));
140
- function loadPrepareConfig(_x4) {
171
+ function loadPrepareConfig(_x5) {
141
172
  return _loadPrepareConfig.apply(this, arguments);
142
173
  }
143
174
  return loadPrepareConfig;
@@ -145,12 +176,12 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
145
176
  }, {
146
177
  key: "batchSearch",
147
178
  value: function () {
148
- var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(code, customerId) {
179
+ var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
149
180
  var result, resultDiscountList;
150
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
151
- while (1) switch (_context4.prev = _context4.next) {
181
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
182
+ while (1) switch (_context5.prev = _context5.next) {
152
183
  case 0:
153
- _context4.next = 2;
184
+ _context5.next = 2;
154
185
  return this.request.get("/machinecode/batch-search", {
155
186
  code: code,
156
187
  translate_flag: 1,
@@ -162,16 +193,16 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
162
193
  order_behavior_count_customer_id: customerId || 1
163
194
  });
164
195
  case 2:
165
- result = _context4.sent;
196
+ result = _context5.sent;
166
197
  resultDiscountList = this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || [];
167
- return _context4.abrupt("return", resultDiscountList);
198
+ return _context5.abrupt("return", resultDiscountList);
168
199
  case 5:
169
200
  case "end":
170
- return _context4.stop();
201
+ return _context5.stop();
171
202
  }
172
- }, _callee4, this);
203
+ }, _callee5, this);
173
204
  }));
174
- function batchSearch(_x5, _x6) {
205
+ function batchSearch(_x6, _x7) {
175
206
  return _batchSearch.apply(this, arguments);
176
207
  }
177
208
  return batchSearch;
@@ -277,21 +308,21 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
277
308
  }, {
278
309
  key: "destroy",
279
310
  value: function () {
280
- var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
281
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
282
- while (1) switch (_context5.prev = _context5.next) {
311
+ var _destroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
312
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
313
+ while (1) switch (_context6.prev = _context6.next) {
283
314
  case 0:
284
315
  this.store.discountList = [];
285
316
  this.core.effects.offByModuleDestroy(this.name);
286
- _context5.next = 4;
317
+ _context6.next = 4;
287
318
  return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
288
319
  case 4:
289
320
  console.log('[Discount] 已销毁');
290
321
  case 5:
291
322
  case "end":
292
- return _context5.stop();
323
+ return _context6.stop();
293
324
  }
294
- }, _callee5, this);
325
+ }, _callee6, this);
295
326
  }));
296
327
  function destroy() {
297
328
  return _destroy.apply(this, arguments);
@@ -301,17 +332,18 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
301
332
  }, {
302
333
  key: "clear",
303
334
  value: function () {
304
- var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
305
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
306
- while (1) switch (_context6.prev = _context6.next) {
335
+ var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
336
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
337
+ while (1) switch (_context7.prev = _context7.next) {
307
338
  case 0:
308
339
  this.store.discountList = [];
340
+ this.store.originalDiscountList = [];
309
341
  console.log('[Discount] clear');
310
- case 2:
342
+ case 3:
311
343
  case "end":
312
- return _context6.stop();
344
+ return _context7.stop();
313
345
  }
314
- }, _callee6, this);
346
+ }, _callee7, this);
315
347
  }));
316
348
  function clear() {
317
349
  return _clear.apply(this, arguments);
@@ -80,6 +80,7 @@ export interface Discount {
80
80
  metadata?: {
81
81
  discount_card_type?: 'fixed_amount' | 'percent';
82
82
  custom_product_bundle_map_id?: string;
83
+ validity_type?: "custom_schedule_validity" | "fixed_validity";
83
84
  };
84
85
  product: Product;
85
86
  type: "product" | 'good_pass';
@@ -107,9 +108,13 @@ export interface Discount {
107
108
  month_order_behavior_count?: number;
108
109
  customer_order_behavior_count?: number;
109
110
  num?: number;
111
+ custom_schedule_snapshot?: {
112
+ data: any[];
113
+ };
110
114
  }
111
115
  export interface DiscountState {
112
116
  discountList: Discount[];
117
+ originalDiscountList?: Discount[];
113
118
  }
114
119
  export interface DiscountModuleAPI {
115
120
  setDiscountList: (discountList: Discount[]) => Promise<void>;
@@ -25,10 +25,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
25
25
  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
26
  import { BaseModule } from "../BaseModule";
27
27
  import { RulesHooks } from "./types";
28
- import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount } from "../../solution/ShopDiscount/utils";
28
+ import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime } from "../../solution/ShopDiscount/utils";
29
29
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
30
30
  import Decimal from 'decimal.js';
31
31
  import { isBoolean } from 'lodash-es';
32
+ import dayjs from 'dayjs';
32
33
  export var RulesModule = /*#__PURE__*/function (_BaseModule) {
33
34
  _inherits(RulesModule, _BaseModule);
34
35
  var _super = _createSuper(RulesModule);
@@ -401,14 +402,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
401
402
  originProduct = flatItem.originProduct;
402
403
  }
403
404
  addModeDiscount.forEach(function (discount) {
404
- var _product, _product2, _product3, _flatItem$bundleItem;
405
+ var _product, _product2, _product3, _product4, _flatItem$bundleItem;
405
406
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
406
-
407
+ var timeLimit = true;
408
+ timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
407
409
  // 是符合折扣的商品
408
410
  var isLimitedProduct = limitedData.type === 'product_all' || limitedData.product_ids && limitedData.product_ids.includes(product.id);
409
411
 
410
412
  // 编辑的商品 使用了优惠券不可用
411
- 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 (discount) {
413
+ 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 (discount) {
412
414
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
413
415
  })) : !(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.metadata) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.custom_product_bundle_map_id);
414
416
 
@@ -416,7 +418,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
416
418
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
417
419
 
418
420
  // 判断优惠券是否适用于该商品
419
- if (isAvailableProduct && isLimitedProduct && isBundleAvailable) {
421
+ if (isAvailableProduct && isLimitedProduct && isBundleAvailable && timeLimit) {
420
422
  var _discountApplicabilit, _discount$metadata;
421
423
  // 记录此优惠券适用的商品
422
424
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
@@ -457,7 +459,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
457
459
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
458
460
  // 🔥 使用扁平化后的列表进行处理
459
461
  sortedFlattenedList.forEach(function (flatItem, index) {
460
- var _product4, _product$discount_lis2, _product5;
462
+ var _product5, _product$discount_lis2, _product6;
461
463
  // 获取商品数据
462
464
  var product, originProduct;
463
465
  if (flatItem.type === 'main') {
@@ -482,7 +484,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
482
484
  }
483
485
 
484
486
  // 已有优惠的商品跳过
485
- if ((_product4 = product) !== null && _product4 !== void 0 && _product4.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product5 = product) !== null && _product5 !== void 0 && (_product5 = _product5.discount_list) !== null && _product5 !== void 0 && _product5.every(function (discount) {
487
+ if ((_product5 = product) !== null && _product5 !== void 0 && _product5.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product6 = product) !== null && _product6 !== void 0 && (_product6 = _product6.discount_list) !== null && _product6 !== void 0 && _product6.every(function (discount) {
486
488
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
487
489
  })) {
488
490
  if (flatItem.type === 'main') {
@@ -510,6 +512,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
510
512
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
511
513
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
512
514
  var limitedData = discount.limited_relation_product_data;
515
+ var timeLimit = true;
516
+ timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
517
+ if (!timeLimit) {
518
+ return false;
519
+ }
513
520
 
514
521
  // 判断优惠券是否适用于该商品
515
522
  if (limitedData.type === 'product_all') {
@@ -539,12 +546,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
539
546
  // 如果是手动折扣,则不适用优惠券
540
547
  var isManualDiscount = false;
541
548
  if (flatItem.type === 'main') {
542
- var _product$discount_lis4, _product6, _product6$every;
549
+ var _product$discount_lis4, _product7, _product7$every;
543
550
  // 主商品:判断自身是否手动折扣
544
551
  isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
545
552
  var _ref3;
546
553
  return !((_ref3 = item.discount_list || []) !== null && _ref3 !== void 0 && _ref3.length);
547
- }) && (!((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length) || ((_product6 = product) === null || _product6 === void 0 || (_product6 = _product6.discount_list) === null || _product6 === void 0 || (_product6$every = _product6.every) === null || _product6$every === void 0 ? void 0 : _product6$every.call(_product6, function (item) {
554
+ }) && (!((_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.length) || ((_product7 = product) === null || _product7 === void 0 || (_product7 = _product7.discount_list) === null || _product7 === void 0 || (_product7$every = _product7.every) === null || _product7$every === void 0 ? void 0 : _product7$every.call(_product7, function (item) {
548
555
  return item.type === 'product';
549
556
  })));
550
557
  } else {
@@ -735,6 +742,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
735
742
  };
736
743
  appliedProducts.push(discountDetail);
737
744
  appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
745
+ var total = targetProductTotal;
746
+ if (product.options) {
747
+ total = product.options.reduce(function (accumulator, currentValue) {
748
+ var currentPrice = new Decimal(currentValue.price || 0);
749
+ var currentNum = new Decimal(currentValue.num || 0);
750
+ return accumulator.add(currentPrice.mul(currentNum));
751
+ }, new Decimal(total)).toNumber();
752
+ }
738
753
 
739
754
  // 记录应用了优惠券的商品
740
755
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
@@ -753,7 +768,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
753
768
  }),
754
769
  variant: originProduct._productInit.variant,
755
770
  original_price: new Decimal(product.price || 0).toNumber(),
756
- total: targetProductTotal
771
+ total: total
757
772
  }));
758
773
  } else {
759
774
  arr.push(_this3.hooks.setProduct(originProduct, {
@@ -761,7 +776,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
761
776
  _id: product._id.split('___')[0] + "___" + _selectedDiscount.id + index,
762
777
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
763
778
  quantity: isNeedSplit ? 1 : product.quantity,
764
- total: targetProductTotal,
779
+ total: total,
765
780
  origin_total: productOriginTotal,
766
781
  main_product_selling_price: targetProductTotal
767
782
  }));
@@ -1064,6 +1079,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1064
1079
  });
1065
1080
  }
1066
1081
 
1082
+ // 累加options的价格(options不参与折扣,在最终设置total时处理)
1083
+ if (product !== null && product !== void 0 && product.options) {
1084
+ newTotalWithDiscount = product.options.reduce(function (accumulator, currentValue) {
1085
+ var currentPrice = new Decimal(currentValue.price || 0);
1086
+ var currentNum = new Decimal(currentValue.num || 0);
1087
+ return accumulator.add(currentPrice.mul(currentNum));
1088
+ }, new Decimal(newTotalWithDiscount)).toNumber();
1089
+ }
1090
+
1067
1091
  // 添加第一个主商品:qty=1,包含拆分后的bundle
1068
1092
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
1069
1093
  _id: "".concat(mainProductData._id.split('___')[0], "___split_discount"),
@@ -1125,6 +1149,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1125
1149
  });
1126
1150
  }
1127
1151
 
1152
+ // 累加options的价格(options不参与折扣,在最终设置total时处理)
1153
+ if (product !== null && product !== void 0 && product.options) {
1154
+ newTotalOriginal = product.options.reduce(function (accumulator, currentValue) {
1155
+ var currentPrice = new Decimal(currentValue.price || 0);
1156
+ var currentNum = new Decimal(currentValue.num || 0);
1157
+ return accumulator.add(currentPrice.mul(currentNum));
1158
+ }, new Decimal(newTotalOriginal)).toNumber();
1159
+ }
1160
+
1128
1161
  // 添加第二个主商品:qty=原quantity-1,包含原始bundle
1129
1162
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
1130
1163
  _id: "".concat(mainProductData._id.split('___')[0], "___split_normal"),
@@ -1220,6 +1253,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1220
1253
  }
1221
1254
  }
1222
1255
 
1256
+ // 累加options的价格(options不参与折扣,在最终设置total时处理)
1257
+ if (product !== null && product !== void 0 && product.options) {
1258
+ newTotal = product.options.reduce(function (accumulator, currentValue) {
1259
+ var currentPrice = new Decimal(currentValue.price || 0);
1260
+ var currentNum = new Decimal(currentValue.num || 0);
1261
+ return accumulator.add(currentPrice.mul(currentNum));
1262
+ }, new Decimal(newTotal)).toNumber();
1263
+ }
1264
+
1223
1265
  // 生成最终的主商品
1224
1266
  result.push(_this3.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
1225
1267
  bundle: newBundle,
@@ -40,6 +40,7 @@ type ProductDetail = {
40
40
  num?: number;
41
41
  quantity: number;
42
42
  vouchersApplicable?: boolean;
43
+ startDate?: any;
43
44
  };
44
45
  export interface RulesParamsHooks {
45
46
  getProduct: (product: Record<string, any>) => ProductDetail;
@@ -2295,6 +2295,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2295
2295
  }
2296
2296
  });
2297
2297
  });
2298
+ this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateBookingDate"), {});
2298
2299
  }
2299
2300
  }, {
2300
2301
  key: "getScheduleDataByIds",
@@ -18,6 +18,8 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
18
18
  private initializePlugins;
19
19
  private registerDependentModules;
20
20
  private registerEventListeners;
21
+ getCurrentBookingTime(): string | null;
22
+ private filterDiscountListByBookingTime;
21
23
  setCustomer(customer: Customer): Promise<void>;
22
24
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
23
25
  productList: Record<string, any>[];
@@ -27,6 +27,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
27
27
  import { BaseModule } from "../../modules/BaseModule";
28
28
  import { DiscountModule } from "../../modules/Discount";
29
29
  import { RulesModule } from "../../modules/Rules";
30
+ import { filterDiscountListByBookingTime as _filterDiscountListByBookingTime, isAllNormalProduct } from "./utils";
30
31
  import Decimal from 'decimal.js';
31
32
  import { isBoolean } from 'lodash-es';
32
33
  export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
@@ -50,7 +51,9 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
50
51
  productList: [],
51
52
  discount: null,
52
53
  rules: null,
53
- originalDiscountList: []
54
+ originalDiscountList: [],
55
+ currentBookingTime: "",
56
+ filteredDiscountList: []
54
57
  };
55
58
  return _this;
56
59
  }
@@ -207,6 +210,55 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
207
210
 
208
211
  // =========== 公共 API ===========
209
212
 
213
+ // 设置预约时间
214
+ // public async setBookingTime(bookingTime: string | null): Promise<void> {
215
+ // if (this.store.currentBookingTime !== bookingTime) {
216
+ // this.store.currentBookingTime = bookingTime;
217
+ //
218
+ // // 更新过滤后的优惠券列表
219
+ // await this.updateFilteredDiscountList();
220
+ // }
221
+ // }
222
+
223
+ // 获取当前预约时间
224
+ }, {
225
+ key: "getCurrentBookingTime",
226
+ value: function getCurrentBookingTime() {
227
+ return this.store.currentBookingTime;
228
+ }
229
+
230
+ // 根据预约时间过滤优惠券列表
231
+ }, {
232
+ key: "filterDiscountListByBookingTime",
233
+ value: function filterDiscountListByBookingTime(discountList, bookingTime) {
234
+ // 如果全部是普通商品,不需要过滤,直接返回当前数据
235
+ if (isAllNormalProduct(this.store.productList || [])) {
236
+ return discountList;
237
+ }
238
+
239
+ // 否则使用 bookingTime 进行过滤
240
+ return _filterDiscountListByBookingTime(discountList, bookingTime);
241
+ }
242
+
243
+ // 更新过滤后的优惠券列表
244
+ // private async updateFilteredDiscountList(): Promise<void> {
245
+ // const originalList = this.store.originalDiscountList;
246
+ // const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
247
+ //
248
+ // this.store.filteredDiscountList = filteredList;
249
+ //
250
+ // // 更新 DiscountModule 中的优惠券列表
251
+ // this.setDiscountList(filteredList);
252
+ //
253
+ // if (this.store.productList?.length) {
254
+ // const result = this.calcDiscount(this.store.productList);
255
+ // await this.core.effects.emit(
256
+ // ShopDiscountHooks.onLoadPrepareCalcResult,
257
+ // result,
258
+ // );
259
+ // }
260
+ // }
261
+
210
262
  // 设置客户
211
263
  }, {
212
264
  key: "setCustomer",
@@ -655,7 +707,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
655
707
  key: "loadPrepareConfig",
656
708
  value: function () {
657
709
  var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(params) {
658
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, _result3;
710
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$discount8, _this$store$productLi2, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, filteredDiscountList, _result3;
659
711
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
660
712
  while (1) switch (_context9.prev = _context9.next) {
661
713
  case 0:
@@ -681,31 +733,37 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
681
733
  newGoodPassList = goodPassList === null || goodPassList === void 0 ? void 0 : goodPassList.filter(function (n) {
682
734
  return !scanDiscountIds.includes(n.id);
683
735
  });
684
- newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
736
+ newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || [])); // 存储原始优惠券列表
685
737
  this.store.originalDiscountList = newDiscountList;
686
- this.setDiscountList(newDiscountList || []);
738
+ _context9.next = 12;
739
+ return (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 ? void 0 : _this$store$discount8.setOriginalDiscountList(newDiscountList);
740
+ case 12:
741
+ // 根据当前预约时间过滤优惠券列表
742
+ filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
743
+ this.store.filteredDiscountList = filteredDiscountList;
744
+ this.setDiscountList(filteredDiscountList || []);
687
745
  if (!((_this$store$productLi2 = this.store.productList) !== null && _this$store$productLi2 !== void 0 && _this$store$productLi2.length)) {
688
- _context9.next = 15;
746
+ _context9.next = 19;
689
747
  break;
690
748
  }
691
749
  _result3 = this.calcDiscount(this.store.productList);
692
- _context9.next = 15;
750
+ _context9.next = 19;
693
751
  return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
694
- case 15:
695
- _context9.next = 17;
696
- return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), newDiscountList);
697
- case 17:
698
- _context9.next = 22;
699
- break;
700
752
  case 19:
701
- _context9.prev = 19;
753
+ _context9.next = 21;
754
+ return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), filteredDiscountList);
755
+ case 21:
756
+ _context9.next = 26;
757
+ break;
758
+ case 23:
759
+ _context9.prev = 23;
702
760
  _context9.t0 = _context9["catch"](0);
703
761
  console.error('[ShopDiscount] 加载准备配置出错:', _context9.t0);
704
- case 22:
762
+ case 26:
705
763
  case "end":
706
764
  return _context9.stop();
707
765
  }
708
- }, _callee9, this, [[0, 19]]);
766
+ }, _callee9, this, [[0, 23]]);
709
767
  }));
710
768
  function loadPrepareConfig(_x9) {
711
769
  return _loadPrepareConfig.apply(this, arguments);
@@ -1,5 +1,6 @@
1
- import { DiscountModule, Discount } from '../../modules/Discount';
1
+ import { DiscountModule } from '../../modules/Discount';
2
2
  import { RulesModule } from '../../modules/Rules';
3
+ import { Discount } from "../../modules/Discount/types";
3
4
  export declare enum ShopDiscountHooks {
4
5
  onInited = "shopDiscount:onInited",
5
6
  onDestroy = "shopDiscount:onDestroy",
@@ -23,6 +24,8 @@ export interface ShopDiscountState {
23
24
  rules: RulesModule | null;
24
25
  productList: Record<string, any>[];
25
26
  originalDiscountList: Discount[];
27
+ currentBookingTime: string | null;
28
+ filteredDiscountList: Discount[];
26
29
  }
27
30
  export interface SetDiscountSelectedParams {
28
31
  discountId: number;
@@ -1,5 +1,7 @@
1
1
  import { Discount } from "../../modules/Discount/types";
2
2
  export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
3
+ export declare const isNormalProductByDurationSchedule: (item: any) => boolean;
4
+ export declare const isAllNormalProduct: (items: any[]) => boolean;
3
5
  /**
4
6
  * 获取折扣金额 基于折扣卡类型计算
5
7
  * 商品券:直接返回商品价格
@@ -17,3 +19,49 @@ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
17
19
  * @returns
18
20
  */
19
21
  export declare const getDiscountListAmount: (discount: Discount[]) => any;
22
+ export interface ScheduleItem {
23
+ id: number;
24
+ name: string | {
25
+ [key: string]: string;
26
+ };
27
+ type: 'standard' | 'time-slots' | 'designation';
28
+ start_time: string | null;
29
+ end_time: string | null;
30
+ repeat_type: 'none' | 'daily' | 'weekly';
31
+ repeat_rule: {
32
+ end: {
33
+ type: 'never' | 'date' | 'occurrence';
34
+ end_date: string | null;
35
+ occurrence: number | null;
36
+ };
37
+ frequency: number;
38
+ excluded_date: Array<{
39
+ start: string;
40
+ end: string;
41
+ }>;
42
+ included_date: Array<{
43
+ start: string;
44
+ end: string;
45
+ }>;
46
+ frequency_date: number[];
47
+ } | null;
48
+ designation: Array<{
49
+ start_date: string;
50
+ start_time: string;
51
+ end_date: string;
52
+ end_time: string;
53
+ }> | null;
54
+ is_all: number;
55
+ time_slot: Array<{
56
+ start_time: string;
57
+ end_time: string;
58
+ }>;
59
+ }
60
+ export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
61
+ /**
62
+ * 根据预约时间过滤优惠券列表
63
+ * @param discountList 优惠券列表
64
+ * @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
65
+ * @returns 过滤后的优惠券列表
66
+ */
67
+ export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];