@pisell/pisellos 2.2.16 → 2.2.17

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.
@@ -13,24 +13,26 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
13
13
  setRulesList(rulesList: Rules[]): Promise<void>;
14
14
  getRulesList(): Rules[];
15
15
  private checkHolderMatch;
16
- isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, }: {
16
+ isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, isFormSubject, }: {
17
17
  oldDiscountList: Discount[];
18
18
  newDiscountList: Discount[];
19
19
  productList: any[];
20
20
  holders: {
21
21
  form_record_id: number;
22
22
  }[];
23
+ isFormSubject: boolean;
23
24
  }): {
24
25
  isAvailable: boolean;
25
26
  discountList: Discount[];
26
27
  productList: any[];
27
28
  };
28
- calcDiscount({ discountList, productList, holders, }: {
29
+ calcDiscount({ discountList, productList, holders, isFormSubject, }: {
29
30
  discountList: Discount[];
30
31
  productList: any[];
31
32
  holders: {
32
33
  form_record_id: number;
33
34
  }[];
35
+ isFormSubject: boolean;
34
36
  }, options?: {
35
37
  isSelected?: boolean;
36
38
  discountId?: number;
@@ -24,11 +24,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
- import { uniqueById, getDiscountAmount, filterDiscountListByBookingTime, getDiscountListAmountTotal, getDiscountListAmount } from "../../solution/ShopDiscount/utils";
27
+ import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime } from "../../solution/ShopDiscount/utils";
28
28
  import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
29
29
  import Decimal from 'decimal.js';
30
- import { isBoolean } from 'lodash-es';
31
30
  import dayjs from 'dayjs';
31
+ import { isBoolean } from 'lodash-es';
32
32
 
33
33
  // 临时变量
34
34
  var flatItem;
@@ -94,7 +94,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
94
94
  return this.store.rulesList;
95
95
  }
96
96
 
97
- // 检查 holder 是否匹配
97
+ // 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
98
98
  }, {
99
99
  key: "checkHolderMatch",
100
100
  value: function checkHolderMatch(discount, product, holders) {
@@ -104,8 +104,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
104
104
  // 主预约holder, 目前(20251124)默认只考虑单个holder的情况
105
105
  var orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : undefined;
106
106
  var productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
107
- // 父预约及商品都无holder, 则略过检查
108
- if (!orderHolderId && !productHolderId) return true;
107
+ // 商品不需要选holder,则不对比holder,直接返回true,
108
+ if (!product.isNeedHolder) return true;
109
+ // 商品需要holder,但父预约及商品都无holder,返回false
110
+ if (!orderHolderId && !productHolderId) return false;
109
111
 
110
112
  // 最终直接匹配 holder 是否相同
111
113
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
@@ -119,7 +121,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
119
121
  var oldDiscountList = _ref.oldDiscountList,
120
122
  newDiscountList = _ref.newDiscountList,
121
123
  productList = _ref.productList,
122
- holders = _ref.holders;
124
+ holders = _ref.holders,
125
+ isFormSubject = _ref.isFormSubject;
123
126
  // 首先检查是否有新的优惠券可应用
124
127
  if (!newDiscountList || newDiscountList.length === 0) {
125
128
  return {
@@ -150,7 +153,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
150
153
  var result = this.calcDiscount({
151
154
  discountList: mergedDiscountList,
152
155
  productList: _toConsumableArray(productList),
153
- holders: holders
156
+ holders: holders,
157
+ isFormSubject: isFormSubject
154
158
  }, {
155
159
  scan: true
156
160
  });
@@ -193,7 +197,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
193
197
  var _this3 = this;
194
198
  var discountList = _ref2.discountList,
195
199
  productList = _ref2.productList,
196
- holders = _ref2.holders;
200
+ holders = _ref2.holders,
201
+ isFormSubject = _ref2.isFormSubject;
197
202
  // 识别出来是不是在编辑的界面里又新增了商品
198
203
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
199
204
  var isEditModeAddNewProduct = productList.find(function (n) {
@@ -429,11 +434,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
429
434
  originProduct = flatItem.originProduct;
430
435
  }
431
436
  addModeDiscount.forEach(function (discount) {
432
- var _flatItem$parentProdu, _flatItem$product, _product, _product2, _product3, _product4, _flatItem$bundleItem;
437
+ var _product, _product2, _product3, _product4, _flatItem$bundleItem;
433
438
  var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
434
439
  // 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
440
+ var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
435
441
  var isHolderMatch = _this3.checkHolderMatch(discount, {
436
- holder_id: ((flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 || (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.holder_id : flatItem === null || flatItem === void 0 || (_flatItem$product = flatItem.product) === null || _flatItem$product === void 0 ? void 0 : _flatItem$product.holder_id) || product.holder_id
442
+ isNeedHolder: isFormSubject && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
443
+ holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
437
444
  }, holders);
438
445
  var timeLimit = true;
439
446
  timeLimit = !!filterDiscountListByBookingTime([discount], (((_product = product) === null || _product === void 0 ? void 0 : _product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
@@ -449,7 +456,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
449
456
  var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
450
457
 
451
458
  // 判断优惠券是否适用于该商品
452
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
459
+ if (isAvailableProduct && isLimitedProduct && isBundleAvailable && timeLimit) {
453
460
  var _discountApplicabilit, _discount$metadata;
454
461
  // 记录此优惠券适用的商品
455
462
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
@@ -490,7 +497,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
490
497
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
491
498
  // 🔥 使用扁平化后的列表进行处理
492
499
  sortedFlattenedList.forEach(function (flatItem, index) {
493
- var _product5, _product$discount_lis2, _product6, _product$discount_lis10;
500
+ var _product5, _product$discount_lis2, _product6;
494
501
  // 获取商品数据
495
502
  var product, originProduct;
496
503
  if (flatItem.type === 'main') {
@@ -530,7 +537,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
530
537
 
531
538
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
532
539
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
533
- var _product$discount_lis3, _product$discount_lis4, _flatItem$parentProdu2, _flatItem$product2;
540
+ var _product$discount_lis3, _product$discount_lis4;
534
541
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
535
542
  // 商品券时主商品价格为0不可用
536
543
  if ((Number(product.price) <= 0 || !product.price) && !((_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.find(function (n) {
@@ -547,18 +554,20 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
547
554
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
548
555
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
549
556
  var limitedData = discount.limited_relation_product_data;
550
- var timeLimit = true;
551
- timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
552
- if (!timeLimit) {
553
- return false;
554
- }
555
557
 
556
558
  // 拿到discount配置的holder信息 product信息 product.holder 不可用return false
559
+ var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
557
560
  var isHolderMatch = _this3.checkHolderMatch(discount, {
558
- holder_id: ((flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 || (_flatItem$parentProdu2 = flatItem.parentProduct) === null || _flatItem$parentProdu2 === void 0 ? void 0 : _flatItem$parentProdu2.holder_id : flatItem === null || flatItem === void 0 || (_flatItem$product2 = flatItem.product) === null || _flatItem$product2 === void 0 ? void 0 : _flatItem$product2.holder_id) || product.holder_id
561
+ isNeedHolder: isFormSubject && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
562
+ holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
559
563
  }, holders);
560
564
  // 如果 holder 不匹配,则不适用
561
565
  if (!isHolderMatch) return false;
566
+ var timeLimit = true;
567
+ timeLimit = !!filterDiscountListByBookingTime([discount], (product.startDate || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
568
+ if (!timeLimit) {
569
+ return false;
570
+ }
562
571
 
563
572
  // 判断优惠券是否适用于该商品
564
573
  if (limitedData.type === 'product_all') {
@@ -622,11 +631,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
622
631
  }
623
632
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
624
633
  if (flatItem.type === 'bundle') {
625
- var _product$discount_lis7, _flatItem$parentProdu3;
634
+ var _product$discount_lis7, _flatItem$parentProdu;
626
635
  if ((_product$discount_lis7 = product.discount_list) !== null && _product$discount_lis7 !== void 0 && _product$discount_lis7.some(function (item) {
627
636
  var _item$discount2;
628
637
  return ((_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.resource_id) === options.discountId;
629
- }) || (_flatItem$parentProdu3 = flatItem.parentProduct) !== null && _flatItem$parentProdu3 !== void 0 && (_flatItem$parentProdu3 = _flatItem$parentProdu3.discount_list) !== null && _flatItem$parentProdu3 !== void 0 && _flatItem$parentProdu3.some(function (item) {
638
+ }) || (_flatItem$parentProdu = flatItem.parentProduct) !== null && _flatItem$parentProdu !== void 0 && (_flatItem$parentProdu = _flatItem$parentProdu.discount_list) !== null && _flatItem$parentProdu !== void 0 && _flatItem$parentProdu.some(function (item) {
630
639
  var _item$discount3;
631
640
  return ((_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.resource_id) === options.discountId;
632
641
  })) {
@@ -648,14 +657,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
648
657
  }
649
658
  // bundle子商品:检查自己的 discount_list 或父主商品的 discount_list
650
659
  if (flatItem.type === 'bundle') {
651
- var _product$discount_lis9, _flatItem$parentProdu4;
660
+ var _product$discount_lis9, _flatItem$parentProdu2;
652
661
  if ((_product$discount_lis9 = product.discount_list) !== null && _product$discount_lis9 !== void 0 && _product$discount_lis9.some(function (item) {
653
662
  var _options$selectedList2;
654
663
  return options === null || options === void 0 || (_options$selectedList2 = options.selectedList) === null || _options$selectedList2 === void 0 ? void 0 : _options$selectedList2.some(function (n) {
655
664
  var _item$discount5;
656
665
  return n.discountId === ((_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.resource_id);
657
666
  });
658
- }) || (_flatItem$parentProdu4 = flatItem.parentProduct) !== null && _flatItem$parentProdu4 !== void 0 && (_flatItem$parentProdu4 = _flatItem$parentProdu4.discount_list) !== null && _flatItem$parentProdu4 !== void 0 && _flatItem$parentProdu4.some(function (item) {
667
+ }) || (_flatItem$parentProdu2 = flatItem.parentProduct) !== null && _flatItem$parentProdu2 !== void 0 && (_flatItem$parentProdu2 = _flatItem$parentProdu2.discount_list) !== null && _flatItem$parentProdu2 !== void 0 && _flatItem$parentProdu2.some(function (item) {
659
668
  var _options$selectedList3;
660
669
  return options === null || options === void 0 || (_options$selectedList3 = options.selectedList) === null || _options$selectedList3 === void 0 ? void 0 : _options$selectedList3.some(function (n) {
661
670
  var _item$discount6;
@@ -666,15 +675,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
666
675
  }
667
676
  }
668
677
  }
669
- if (options !== null && options !== void 0 && options.selectedList && (_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.some(function (item) {
670
- var _options$selectedList4;
671
- return options === null || options === void 0 || (_options$selectedList4 = options.selectedList) === null || _options$selectedList4 === void 0 ? void 0 : _options$selectedList4.some(function (n) {
672
- var _item$discount7;
673
- return n.discountId === ((_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.resource_id);
674
- });
675
- })) {
676
- isManualDiscount = false;
677
- }
678
678
 
679
679
  // 如果没有适用的优惠券,或者手动折扣,则不适用优惠券
680
680
  if (applicableDiscounts.length === 0 || isManualDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
@@ -751,7 +751,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
751
751
  }));
752
752
  }
753
753
  for (var i = 0; i < splitCount; i++) {
754
- var _product$discount_lis11, _originProduct, _selectedDiscount$met;
754
+ var _product$discount_lis10, _originProduct, _selectedDiscount$met;
755
755
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
756
756
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
757
757
  // 标记优惠券为已使用
@@ -763,7 +763,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
763
763
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
764
764
  var productOriginTotal = product.origin_total || product.total || 0;
765
765
  // 如果当前 product 有 discount_list,则先从 origin_total 拿
766
- if ((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.length && product.origin_total) {
766
+ if ((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.length && product.origin_total) {
767
767
  productOriginTotal = product.origin_total;
768
768
  }
769
769
  // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
@@ -900,7 +900,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
900
900
  }));
901
901
  }
902
902
  } else {
903
- var _selectedDiscount3$me, _flatItem$parentProdu5;
903
+ var _selectedDiscount3$me, _flatItem$parentProdu3;
904
904
  // 折扣卡:不拆分数量,直接应用
905
905
  var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
906
906
  usedDiscounts.set(_selectedDiscount3.id, true);
@@ -926,7 +926,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
926
926
  custom_product_bundle_map_id: _uniqueId,
927
927
  num: product.num || 1
928
928
  },
929
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.num) || 1)
929
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu3 = flatItem.parentProduct) === null || _flatItem$parentProdu3 === void 0 ? void 0 : _flatItem$parentProdu3.num) || 1)
930
930
  };
931
931
 
932
932
  // 记录实际应用的折扣
@@ -25,6 +25,7 @@ export interface RulesModuleAPI {
25
25
  holders: {
26
26
  form_record_id: number;
27
27
  }[];
28
+ isFormSubject: boolean;
28
29
  }) => DiscountResult;
29
30
  }
30
31
  type ProductDetail = {
@@ -24,6 +24,10 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
24
24
  setHolders(holders: {
25
25
  form_record_id: number;
26
26
  }[]): void;
27
+ setBookingSubject(bookingSubject: {
28
+ type?: 'form' | 'customer';
29
+ [key: string]: any;
30
+ }): void;
27
31
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
28
32
  productList: Record<string, any>[];
29
33
  discountList: Discount[];
@@ -51,10 +51,11 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
51
51
  productList: [],
52
52
  discount: null,
53
53
  rules: null,
54
+ holders: [],
54
55
  originalDiscountList: [],
55
56
  currentBookingTime: "",
56
57
  filteredDiscountList: [],
57
- holders: []
58
+ bookingSubject: undefined
58
59
  };
59
60
  return _this;
60
61
  }
@@ -292,11 +293,17 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
292
293
  value: function setHolders(holders) {
293
294
  this.store.holders = holders;
294
295
  }
296
+ }, {
297
+ key: "setBookingSubject",
298
+ value: function setBookingSubject(bookingSubject) {
299
+ this.store.bookingSubject = bookingSubject;
300
+ }
295
301
 
296
302
  // 计算优惠券
297
303
  }, {
298
304
  key: "calcDiscount",
299
305
  value: function calcDiscount(productList, options) {
306
+ var _this$store$bookingSu;
300
307
  this.store.productList = productList;
301
308
  var rulesModule = this.core.getModule("".concat(this.name, "_rules"));
302
309
  if (!rulesModule) {
@@ -308,7 +315,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
308
315
  var _ref = rulesModule.calcDiscount({
309
316
  productList: productList,
310
317
  discountList: this.getDiscountList(),
311
- holders: this.store.holders || []
318
+ holders: this.store.holders || [],
319
+ isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
312
320
  }, options) || {
313
321
  productList: productList,
314
322
  discountList: this.getDiscountList()
@@ -381,7 +389,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
381
389
  key: "scanCode",
382
390
  value: function () {
383
391
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
384
- var _this$store$discount3, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
392
+ var _this$store$discount3, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
385
393
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
386
394
  while (1) switch (_context5.prev = _context5.next) {
387
395
  case 0:
@@ -447,7 +455,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
447
455
  productList: this.store.productList || [],
448
456
  oldDiscountList: this.getDiscountList(),
449
457
  newDiscountList: withScanList,
450
- holders: this.store.holders || []
458
+ holders: this.store.holders || [],
459
+ isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
451
460
  }) || {
452
461
  isAvailable: false,
453
462
  productList: this.store.productList || [],
@@ -23,14 +23,18 @@ export interface ShopDiscountState {
23
23
  discount: DiscountModule | null;
24
24
  rules: RulesModule | null;
25
25
  productList: Record<string, any>[];
26
- originalDiscountList: Discount[];
27
26
  holders?: {
28
27
  form_record_id: number;
29
28
  form_id?: number;
30
29
  main_field?: string;
31
30
  }[];
31
+ originalDiscountList: Discount[];
32
32
  currentBookingTime: string | null;
33
33
  filteredDiscountList: Discount[];
34
+ bookingSubject?: {
35
+ type?: 'form' | 'customer';
36
+ [key: string]: any;
37
+ };
34
38
  }
35
39
  export interface SetDiscountSelectedParams {
36
40
  discountId: number;
@@ -13,24 +13,26 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
13
13
  setRulesList(rulesList: Rules[]): Promise<void>;
14
14
  getRulesList(): Rules[];
15
15
  private checkHolderMatch;
16
- isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, }: {
16
+ isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, isFormSubject, }: {
17
17
  oldDiscountList: Discount[];
18
18
  newDiscountList: Discount[];
19
19
  productList: any[];
20
20
  holders: {
21
21
  form_record_id: number;
22
22
  }[];
23
+ isFormSubject: boolean;
23
24
  }): {
24
25
  isAvailable: boolean;
25
26
  discountList: Discount[];
26
27
  productList: any[];
27
28
  };
28
- calcDiscount({ discountList, productList, holders, }: {
29
+ calcDiscount({ discountList, productList, holders, isFormSubject, }: {
29
30
  discountList: Discount[];
30
31
  productList: any[];
31
32
  holders: {
32
33
  form_record_id: number;
33
34
  }[];
35
+ isFormSubject: boolean;
34
36
  }, options?: {
35
37
  isSelected?: boolean;
36
38
  discountId?: number;
@@ -36,8 +36,8 @@ var import_BaseModule = require("../BaseModule");
36
36
  var import_utils = require("../../solution/ShopDiscount/utils");
37
37
  var import_utils2 = require("../Cart/utils");
38
38
  var import_decimal = __toESM(require("decimal.js"));
39
- var import_lodash_es = require("lodash-es");
40
39
  var import_dayjs = __toESM(require("dayjs"));
40
+ var import_lodash_es = require("lodash-es");
41
41
  var RulesModule = class extends import_BaseModule.BaseModule {
42
42
  constructor(name, version) {
43
43
  super(name, version);
@@ -57,15 +57,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
57
57
  getRulesList() {
58
58
  return this.store.rulesList;
59
59
  }
60
- // 检查 holder 是否匹配
60
+ // 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
61
61
  checkHolderMatch(discount, product, holders) {
62
62
  var _a;
63
63
  if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
64
64
  return true;
65
65
  const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
66
66
  const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
67
- if (!orderHolderId && !productHolderId)
67
+ if (!product.isNeedHolder)
68
68
  return true;
69
+ if (!orderHolderId && !productHolderId)
70
+ return false;
69
71
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
70
72
  }
71
73
  // 判断discountList 是否可以对当前productList生效
@@ -73,7 +75,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
73
75
  oldDiscountList,
74
76
  newDiscountList,
75
77
  productList,
76
- holders
78
+ holders,
79
+ isFormSubject
77
80
  }) {
78
81
  if (!newDiscountList || newDiscountList.length === 0) {
79
82
  return {
@@ -101,7 +104,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
101
104
  const result = this.calcDiscount({
102
105
  discountList: mergedDiscountList,
103
106
  productList: [...productList],
104
- holders
107
+ holders,
108
+ isFormSubject
105
109
  }, {
106
110
  scan: true
107
111
  });
@@ -134,7 +138,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
134
138
  calcDiscount({
135
139
  discountList,
136
140
  productList,
137
- holders
141
+ holders,
142
+ isFormSubject
138
143
  }, options) {
139
144
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
140
145
  const editModeDiscount = [];
@@ -283,22 +288,24 @@ var RulesModule = class extends import_BaseModule.BaseModule {
283
288
  originProduct = flatItem.originProduct;
284
289
  }
285
290
  addModeDiscount.forEach((discount) => {
286
- var _a, _b, _c, _d, _e, _f, _g, _h;
291
+ var _a, _b, _c, _d, _e, _f;
287
292
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
293
+ const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
288
294
  const isHolderMatch = this.checkHolderMatch(
289
295
  discount,
290
296
  {
291
- holder_id: ((flatItem == null ? void 0 : flatItem.type) === "bundle" ? (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.holder_id : (_b = flatItem == null ? void 0 : flatItem.product) == null ? void 0 : _b.holder_id) || product.holder_id
297
+ isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
298
+ holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
292
299
  },
293
300
  holders
294
301
  );
295
302
  let timeLimit = true;
296
303
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
297
304
  const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
298
- const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_c = product == null ? void 0 : product.discount_list) == null ? void 0 : _c.length) && ((_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.metadata) == null ? void 0 : _f.custom_product_bundle_map_id));
305
+ const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
299
306
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
300
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
301
- (_g = discountApplicability.get(discount.id)) == null ? void 0 : _g.push(product.id);
307
+ if (isAvailableProduct && isLimitedProduct && isBundleAvailable && timeLimit) {
308
+ (_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
302
309
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
303
310
  const discountType = discount.tag || discount.type;
304
311
  const isGoodPass = discountType === "good_pass";
@@ -308,7 +315,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
308
315
  type: discountType,
309
316
  tag: discountType,
310
317
  discount: {
311
- discount_card_type: (_h = discount == null ? void 0 : discount.metadata) == null ? void 0 : _h.discount_card_type,
318
+ discount_card_type: (_f = discount == null ? void 0 : discount.metadata) == null ? void 0 : _f.discount_card_type,
312
319
  fixed_amount: product.price,
313
320
  resource_id: discount.id,
314
321
  title: discount.format_title,
@@ -327,7 +334,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
327
334
  });
328
335
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
329
336
  sortedFlattenedList.forEach((flatItem, index) => {
330
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
337
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
331
338
  let product, originProduct;
332
339
  if (flatItem.type === "main") {
333
340
  product = flatItem.product;
@@ -359,7 +366,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
359
366
  return;
360
367
  }
361
368
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
362
- var _a2, _b2, _c2, _d2;
369
+ var _a2, _b2;
363
370
  if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.find((n) => {
364
371
  var _a3;
365
372
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
@@ -374,20 +381,22 @@ var RulesModule = class extends import_BaseModule.BaseModule {
374
381
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
375
382
  return false;
376
383
  const limitedData = discount.limited_relation_product_data;
377
- let timeLimit = true;
378
- timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
379
- if (!timeLimit) {
380
- return false;
381
- }
384
+ const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
382
385
  const isHolderMatch = this.checkHolderMatch(
383
386
  discount,
384
387
  {
385
- holder_id: ((flatItem == null ? void 0 : flatItem.type) === "bundle" ? (_c2 = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _c2.holder_id : (_d2 = flatItem == null ? void 0 : flatItem.product) == null ? void 0 : _d2.holder_id) || product.holder_id
388
+ isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
389
+ holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
386
390
  },
387
391
  holders
388
392
  );
389
393
  if (!isHolderMatch)
390
394
  return false;
395
+ let timeLimit = true;
396
+ timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
397
+ if (!timeLimit) {
398
+ return false;
399
+ }
391
400
  if (limitedData.type === "product_all") {
392
401
  if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
393
402
  return false;
@@ -465,15 +474,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
465
474
  }
466
475
  }
467
476
  }
468
- if ((options == null ? void 0 : options.selectedList) && ((_t = product.discount_list) == null ? void 0 : _t.some((item) => {
469
- var _a2;
470
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
471
- var _a3;
472
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
473
- });
474
- }))) {
475
- isManualDiscount = false;
476
- }
477
477
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
478
478
  if (flatItem.type === "main") {
479
479
  if (product.isClient) {
@@ -550,10 +550,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
550
550
  usedDiscounts.set(selectedDiscount2.id, true);
551
551
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
552
552
  let productOriginTotal = product.origin_total || product.total || 0;
553
- if (((_u = product.discount_list) == null ? void 0 : _u.length) && product.origin_total) {
553
+ if (((_t = product.discount_list) == null ? void 0 : _t.length) && product.origin_total) {
554
554
  productOriginTotal = product.origin_total;
555
555
  }
556
- if (Number(((_v = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _v.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
556
+ if (Number(((_u = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _u.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
557
557
  productOriginTotal = product.total;
558
558
  }
559
559
  const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
@@ -564,7 +564,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
564
564
  amount,
565
565
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
566
566
  discount: {
567
- discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
567
+ discount_card_type: (_v = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _v.discount_card_type,
568
568
  fixed_amount: amount,
569
569
  resource_id: selectedDiscount2.id,
570
570
  title: selectedDiscount2.format_title,
@@ -686,7 +686,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
686
686
  amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber() * (product.num || 1),
687
687
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
688
688
  discount: {
689
- discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
689
+ discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
690
690
  fixed_amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
691
691
  resource_id: selectedDiscount2.id,
692
692
  title: selectedDiscount2.format_title,
@@ -699,7 +699,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
699
699
  custom_product_bundle_map_id: uniqueId,
700
700
  num: product.num || 1
701
701
  },
702
- _num: (product.num || 1) * (((_y = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _y.num) || 1)
702
+ _num: (product.num || 1) * (((_x = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _x.num) || 1)
703
703
  };
704
704
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
705
705
  appliedProducts.push(discountDetail);
@@ -25,6 +25,7 @@ export interface RulesModuleAPI {
25
25
  holders: {
26
26
  form_record_id: number;
27
27
  }[];
28
+ isFormSubject: boolean;
28
29
  }) => DiscountResult;
29
30
  }
30
31
  type ProductDetail = {
@@ -24,6 +24,10 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
24
24
  setHolders(holders: {
25
25
  form_record_id: number;
26
26
  }[]): void;
27
+ setBookingSubject(bookingSubject: {
28
+ type?: 'form' | 'customer';
29
+ [key: string]: any;
30
+ }): void;
27
31
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
28
32
  productList: Record<string, any>[];
29
33
  discountList: Discount[];
@@ -51,10 +51,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
51
51
  productList: [],
52
52
  discount: null,
53
53
  rules: null,
54
+ holders: [],
54
55
  originalDiscountList: [],
55
56
  currentBookingTime: "",
56
57
  filteredDiscountList: [],
57
- holders: []
58
+ bookingSubject: void 0
58
59
  };
59
60
  }
60
61
  // =========== 生命周期方法 ===========
@@ -196,8 +197,12 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
196
197
  setHolders(holders) {
197
198
  this.store.holders = holders;
198
199
  }
200
+ setBookingSubject(bookingSubject) {
201
+ this.store.bookingSubject = bookingSubject;
202
+ }
199
203
  // 计算优惠券
200
204
  calcDiscount(productList, options) {
205
+ var _a;
201
206
  this.store.productList = productList;
202
207
  const rulesModule = this.core.getModule(`${this.name}_rules`);
203
208
  if (!rulesModule) {
@@ -207,7 +212,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
207
212
  {
208
213
  productList,
209
214
  discountList: this.getDiscountList(),
210
- holders: this.store.holders || []
215
+ holders: this.store.holders || [],
216
+ isFormSubject: ((_a = this.store.bookingSubject) == null ? void 0 : _a.type) === "form"
211
217
  },
212
218
  options
213
219
  ) || { productList, discountList: this.getDiscountList() };
@@ -254,7 +260,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
254
260
  }
255
261
  // 扫码输入code
256
262
  async scanCode(code, customerId) {
257
- var _a, _b;
263
+ var _a, _b, _c;
258
264
  try {
259
265
  const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, customerId)) || [];
260
266
  const rulesModule = this.store.rules;
@@ -297,7 +303,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
297
303
  productList: this.store.productList || [],
298
304
  oldDiscountList: this.getDiscountList(),
299
305
  newDiscountList: withScanList,
300
- holders: this.store.holders || []
306
+ holders: this.store.holders || [],
307
+ isFormSubject: ((_b = this.store.bookingSubject) == null ? void 0 : _b.type) === "form"
301
308
  }) || {
302
309
  isAvailable: false,
303
310
  productList: this.store.productList || [],
@@ -307,7 +314,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
307
314
  this.setDiscountList(newDiscountList || []);
308
315
  this.store.originalDiscountList = newDiscountList || [];
309
316
  this.setProductList(newProductList || []);
310
- if (this.isWalkIn() && resultDiscountList.length && ((_b = this.options.otherParams) == null ? void 0 : _b.platform) === "shop") {
317
+ if (this.isWalkIn() && resultDiscountList.length && ((_c = this.options.otherParams) == null ? void 0 : _c.platform) === "shop") {
311
318
  await this.getCustomerWallet(
312
319
  resultDiscountList[0].customer_id
313
320
  );
@@ -23,14 +23,18 @@ export interface ShopDiscountState {
23
23
  discount: DiscountModule | null;
24
24
  rules: RulesModule | null;
25
25
  productList: Record<string, any>[];
26
- originalDiscountList: Discount[];
27
26
  holders?: {
28
27
  form_record_id: number;
29
28
  form_id?: number;
30
29
  main_field?: string;
31
30
  }[];
31
+ originalDiscountList: Discount[];
32
32
  currentBookingTime: string | null;
33
33
  filteredDiscountList: Discount[];
34
+ bookingSubject?: {
35
+ type?: 'form' | 'customer';
36
+ [key: string]: any;
37
+ };
34
38
  }
35
39
  export interface SetDiscountSelectedParams {
36
40
  discountId: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.16",
4
+ "version": "2.2.17",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",