@pisell/pisellos 0.0.165 → 0.0.167

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.
@@ -256,7 +256,8 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
256
256
  bundle: bundle,
257
257
  options: options,
258
258
  product_variant_id: newProduct.product_variant_id,
259
- quantity: quantity
259
+ quantity: quantity,
260
+ discounts: discounts
260
261
  });
261
262
  }
262
263
  if (discounts) {
@@ -20,6 +20,7 @@ export declare const formatProductToCartItem: (params: {
20
20
  options?: any;
21
21
  product_variant_id?: number;
22
22
  quantity?: number;
23
+ discounts?: any[];
23
24
  }) => CartItem;
24
25
  export declare const formatProductToCartItemOrigin: (params: {
25
26
  cartItem: CartItem;
@@ -40,6 +41,7 @@ export declare const getProductTotalPrice: (params: {
40
41
  bundle?: any;
41
42
  options?: any;
42
43
  num?: number;
44
+ discounts?: any[];
43
45
  }) => number;
44
46
  /**
45
47
  * 获取商品原始总价
@@ -48,7 +48,8 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
48
48
  options = params.options,
49
49
  product_variant_id = params.product_variant_id,
50
50
  _params$quantity = params.quantity,
51
- quantity = _params$quantity === void 0 ? 1 : _params$quantity;
51
+ quantity = _params$quantity === void 0 ? 1 : _params$quantity,
52
+ discounts = params.discounts;
52
53
  var num = quantity; // 当前按照单个商品加入购物车
53
54
  if (product) {
54
55
  cartItem.id = product === null || product === void 0 ? void 0 : product.id;
@@ -59,7 +60,8 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
59
60
  product: product,
60
61
  bundle: bundle,
61
62
  options: options,
62
- num: num
63
+ num: num,
64
+ discounts: discounts
63
65
  });
64
66
  cartItem.summaryTotal = cartItem.total * (num || 1);
65
67
  cartItem.origin_total = getProductOriginTotalPrice({
@@ -161,7 +163,8 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
161
163
  export var getProductTotalPrice = function getProductTotalPrice(params) {
162
164
  var product = params.product,
163
165
  bundle = params.bundle,
164
- options = params.options;
166
+ options = params.options,
167
+ discounts = params.discounts;
165
168
  // const num = params.num || 1;
166
169
  var price = Number(product.price);
167
170
  if (bundle !== null && bundle !== void 0 && bundle.length) {
@@ -176,6 +179,18 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
176
179
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
177
180
  }, price);
178
181
  }
182
+
183
+ // 如果商品有折扣,则计算折扣
184
+ if (discounts !== null && discounts !== void 0 && discounts.length) {
185
+ discounts.forEach(function (currentValue) {
186
+ // 不是商品券则代表折扣卡,计算打折后的价格
187
+ // 一个商品折扣卡只能存在于一张
188
+ if (currentValue.type !== 'good_pass') {
189
+ var discountPrice = new Decimal(100).minus(currentValue.discount.percent || 0).div(100).mul(new Decimal(price || 0)).toFixed(2);
190
+ price = Number(discountPrice);
191
+ }
192
+ });
193
+ }
179
194
  return price;
180
195
  };
181
196
 
@@ -129,10 +129,9 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
129
129
  return this.request.post("/order/prepare/config", params);
130
130
  case 2:
131
131
  prepareConfig = _context3.sent;
132
- 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) || []))) || [];
133
- this.setDiscountList(goodPassList);
132
+ 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);
134
133
  return _context3.abrupt("return", goodPassList);
135
- case 6:
134
+ case 5:
136
135
  case "end":
137
136
  return _context3.stop();
138
137
  }
@@ -119,8 +119,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
119
119
  };
120
120
  }
121
121
 
122
- // 合并新旧折扣列表,并计算折扣结果
123
- var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(oldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
122
+ // 合并新旧折扣列表,并计算折扣结果,注意,如果旧折扣里有 isEditMode 为 true 的优惠券,则不合并
123
+ var filteredOldDiscountList = oldDiscountList.filter(function (discount) {
124
+ return !discount.isEditMode && discount.tag !== 'good_pass';
125
+ });
126
+ var mergedDiscountList = uniqueById(uniqueById([].concat(_toConsumableArray(filteredOldDiscountList), _toConsumableArray(newDiscountList))), 'product_id');
124
127
  var result = this.calcDiscount({
125
128
  discountList: mergedDiscountList,
126
129
  productList: _toConsumableArray(productList)
@@ -313,7 +316,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
313
316
 
314
317
  // 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
315
318
  sortedProductList.forEach(function (originProduct, i) {
316
- var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
319
+ var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7, _product$discount_lis8;
317
320
  var product = _this3.hooks.getProduct(originProduct);
318
321
  if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
319
322
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
@@ -349,7 +352,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
349
352
  })));
350
353
 
351
354
  // 勾选时覆盖手动折扣
352
- if (options !== null && options !== void 0 && options.discountId && product.discount_list.some(function (item) {
355
+ if (options !== null && options !== void 0 && options.discountId && (_product$discount_lis8 = product.discount_list) !== null && _product$discount_lis8 !== void 0 && _product$discount_lis8.some(function (item) {
353
356
  var _item$discount;
354
357
  return ((_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) === options.discountId;
355
358
  })) {
@@ -399,7 +402,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
399
402
  var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
400
403
 
401
404
  // 需要拆分出来的数量
402
- var splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter(function (item) {
405
+ var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter(function (item) {
403
406
  return (item.tag || item.type) === 'good_pass';
404
407
  }).length) : 1;
405
408
  var arr = [];
@@ -410,76 +413,58 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
410
413
  _id: product._id.split('___')[0]
411
414
  }));
412
415
  }
413
- var _loop = function _loop() {
414
- var selectedDiscount = applicableDiscounts[_i];
416
+ for (var _i = 0; _i < splitCount; _i++) {
417
+ var _selectedDiscount = applicableDiscounts[_i];
415
418
  // 标记优惠券为已使用
416
- usedDiscounts.set(selectedDiscount.id, true);
419
+ usedDiscounts.set(_selectedDiscount.id, true);
417
420
 
418
421
  // 记录实际应用了优惠券的商品信息
419
- var appliedProducts = appliedDiscountProducts.get(selectedDiscount.id) || [];
420
- var targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.price || 0)).toFixed(2);
422
+ var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
423
+
424
+ // 计算使用折扣卡/商品券以后,单个商品的总 total
425
+ var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(product.origin_total || 0).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(product.origin_total || 0)).toNumber();
421
426
  var discountDetail = {
422
- amount: selectedDiscount.tag === 'good_pass' ? product.price : new Decimal(product.price || 0).minus(new Decimal(targetProductPrice)).toNumber(),
423
- type: selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : selectedDiscount.tag,
427
+ amount: new Decimal(product.origin_total || 0).minus(new Decimal(targetProductTotal)).toNumber(),
428
+ type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
424
429
  discount: {
425
- resource_id: selectedDiscount.id,
426
- title: selectedDiscount.format_title,
430
+ resource_id: _selectedDiscount.id,
431
+ title: _selectedDiscount.format_title,
427
432
  original_amount: product.origin_total || product.price,
428
433
  product_id: originProduct.id,
429
- percent: selectedDiscount.par_value
434
+ percent: _selectedDiscount.par_value
430
435
  },
431
436
  num: product.num || 1
432
437
  };
433
438
  appliedProducts.push(discountDetail);
434
- appliedDiscountProducts.set(selectedDiscount.id, appliedProducts);
439
+ appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
435
440
 
436
441
  // 记录应用了优惠券的商品
437
442
  // 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
438
443
  if (product.isClient) {
439
- var _originProduct$_produ;
440
- var variant = (_originProduct$_produ = originProduct._productOrigin.variant) === null || _originProduct$_produ === void 0 ? void 0 : _originProduct$_produ.map(function (n) {
441
- var _originProduct$_produ2;
442
- if (n.id === ((_originProduct$_produ2 = originProduct._productOrigin) === null || _originProduct$_produ2 === void 0 ? void 0 : _originProduct$_produ2.product_variant_id)) {
443
- n.original_price = n.price;
444
- var _targetProductPrice = selectedDiscount.tag === 'good_pass' ? '0' : new Decimal(100).minus(selectedDiscount.par_value || 0).div(100).mul(new Decimal(n.price || 0)).toFixed(2);
445
- n.price = _targetProductPrice;
446
- }
447
- return n;
448
- });
449
444
  arr.push(_this3.hooks.setProduct(originProduct, {
450
445
  discount_list: [discountDetail],
451
- price: new Decimal(targetProductPrice).toNumber(),
446
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
452
447
  quantity: isNeedSplit ? 1 : product.quantity,
453
448
  origin_total: getProductOriginTotalPrice({
454
449
  product: {
455
- original_price: targetProductPrice
450
+ original_price: product.original_price
456
451
  },
457
452
  bundle: product.bundle,
458
453
  options: product.options
459
454
  }),
460
- variant: variant,
461
- original_price: new Decimal(product.price).toNumber(),
462
- total: getProductTotalPrice({
463
- product: {
464
- price: targetProductPrice
465
- },
466
- bundle: product.bundle,
467
- options: product.options
468
- })
455
+ original_price: new Decimal(product.price || 0).toNumber(),
456
+ total: targetProductTotal
469
457
  }));
470
458
  } else {
471
459
  arr.push(_this3.hooks.setProduct(originProduct, {
472
460
  discount_list: [discountDetail],
473
- _id: product._id.split('___')[0] + "___" + selectedDiscount.id,
474
- price: new Decimal(targetProductPrice).toNumber(),
461
+ _id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
462
+ price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
475
463
  quantity: isNeedSplit ? 1 : product.quantity,
476
- total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
464
+ total: targetProductTotal,
477
465
  origin_total: product.origin_total || product.total
478
466
  }));
479
467
  }
480
- };
481
- for (var _i = 0; _i < splitCount; _i++) {
482
- _loop();
483
468
  }
484
469
  console.log(arr, 'arrarrarr');
485
470
  processedProductsMap.set(product._id, arr);
@@ -554,6 +539,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
554
539
  if (usedDiscounts.get(discount.id)) {
555
540
  return _objectSpread(_objectSpread({}, discount), {}, {
556
541
  isSelected: true,
542
+ isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
557
543
  // 标记为可用,因为它已被应用
558
544
  isAvailable: true,
559
545
  // 记录适用的商品IDs
@@ -576,6 +562,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
576
562
  // 如果有适用的商品,标记为可用
577
563
  isAvailable: isAvailable,
578
564
  isSelected: isSelected,
565
+ // 如果是扫码进来的,要手动设置为手动选择:false
566
+ isManualSelect: options !== null && options !== void 0 && options.scan ? false : discount.isManualSelect,
579
567
  // 记录适用的商品IDs
580
568
  applicableProductIds: applicableProducts,
581
569
  // 添加可抵扣的商品详情
@@ -47,10 +47,10 @@ export interface RulesParamsHooks {
47
47
  total?: number;
48
48
  discount_list: any[];
49
49
  origin_total?: number;
50
- price?: number;
51
- quantity?: number;
50
+ price?: string | number;
52
51
  variant?: any[];
53
52
  original_price?: number;
53
+ quantity?: number;
54
54
  }) => Record<string, any>;
55
55
  }
56
56
  export {};
@@ -574,7 +574,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
574
574
  key: "loadPrepareConfig",
575
575
  value: function () {
576
576
  var _loadPrepareConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(params) {
577
- var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, newDiscountList, result;
577
+ var _this$getCustomer2, _this$store$discount7, _this$getDiscountList, _this$store$productLi, customerId, goodPassList, scanDiscount, scanDiscountIds, newGoodPassList, newDiscountList, result;
578
578
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
579
579
  while (1) switch (_context8.prev = _context8.next) {
580
580
  case 0:
@@ -593,31 +593,37 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
593
593
  goodPassList = _context8.sent;
594
594
  scanDiscount = (_this$getDiscountList = this.getDiscountList()) === null || _this$getDiscountList === void 0 ? void 0 : _this$getDiscountList.filter(function (item) {
595
595
  return item.isScan;
596
+ }); // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
597
+ scanDiscountIds = scanDiscount.map(function (n) {
598
+ return n.id;
596
599
  });
597
- newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(goodPassList || []));
600
+ newGoodPassList = goodPassList === null || goodPassList === void 0 ? void 0 : goodPassList.filter(function (n) {
601
+ return !scanDiscountIds.includes(n.id);
602
+ });
603
+ newDiscountList = [].concat(_toConsumableArray(scanDiscount), _toConsumableArray(newGoodPassList || []));
598
604
  this.setDiscountList(newDiscountList || []);
599
605
  if (!((_this$store$productLi = this.store.productList) !== null && _this$store$productLi !== void 0 && _this$store$productLi.length)) {
600
- _context8.next = 12;
606
+ _context8.next = 14;
601
607
  break;
602
608
  }
603
609
  result = this.calcDiscount(this.store.productList);
604
- _context8.next = 12;
605
- return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
606
- case 12:
607
610
  _context8.next = 14;
608
- return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
611
+ return this.core.effects.emit(ShopDiscountHooks.onLoadPrepareCalcResult, result);
609
612
  case 14:
610
- _context8.next = 19;
611
- break;
613
+ _context8.next = 16;
614
+ return this.core.effects.emit(ShopDiscountHooks.onLoadDiscountList, newDiscountList);
612
615
  case 16:
613
- _context8.prev = 16;
616
+ _context8.next = 21;
617
+ break;
618
+ case 18:
619
+ _context8.prev = 18;
614
620
  _context8.t0 = _context8["catch"](0);
615
621
  console.error('[ShopDiscount] 加载准备配置出错:', _context8.t0);
616
- case 19:
622
+ case 21:
617
623
  case "end":
618
624
  return _context8.stop();
619
625
  }
620
- }, _callee8, this, [[0, 16]]);
626
+ }, _callee8, this, [[0, 18]]);
621
627
  }));
622
628
  function loadPrepareConfig(_x7) {
623
629
  return _loadPrepareConfig.apply(this, arguments);
@@ -158,7 +158,8 @@ var CartModule = class extends import_BaseModule.BaseModule {
158
158
  bundle,
159
159
  options,
160
160
  product_variant_id: newProduct.product_variant_id,
161
- quantity
161
+ quantity,
162
+ discounts
162
163
  });
163
164
  }
164
165
  if (discounts) {
@@ -20,6 +20,7 @@ export declare const formatProductToCartItem: (params: {
20
20
  options?: any;
21
21
  product_variant_id?: number;
22
22
  quantity?: number;
23
+ discounts?: any[];
23
24
  }) => CartItem;
24
25
  export declare const formatProductToCartItemOrigin: (params: {
25
26
  cartItem: CartItem;
@@ -40,6 +41,7 @@ export declare const getProductTotalPrice: (params: {
40
41
  bundle?: any;
41
42
  options?: any;
42
43
  num?: number;
44
+ discounts?: any[];
43
45
  }) => number;
44
46
  /**
45
47
  * 获取商品原始总价
@@ -65,7 +65,8 @@ var formatProductToCartItem = (params) => {
65
65
  bundle,
66
66
  options,
67
67
  product_variant_id,
68
- quantity = 1
68
+ quantity = 1,
69
+ discounts
69
70
  } = params;
70
71
  const num = quantity;
71
72
  if (product) {
@@ -73,7 +74,7 @@ var formatProductToCartItem = (params) => {
73
74
  cartItem.name = product == null ? void 0 : product.title;
74
75
  cartItem.price = product == null ? void 0 : product.price;
75
76
  cartItem.num = num;
76
- cartItem.total = getProductTotalPrice({ product, bundle, options, num });
77
+ cartItem.total = getProductTotalPrice({ product, bundle, options, num, discounts });
77
78
  cartItem.summaryTotal = cartItem.total * (num || 1);
78
79
  cartItem.origin_total = getProductOriginTotalPrice({
79
80
  product,
@@ -163,7 +164,7 @@ var formatProductToCartItemOrigin = (params) => {
163
164
  return origin;
164
165
  };
165
166
  var getProductTotalPrice = (params) => {
166
- const { product, bundle, options } = params;
167
+ const { product, bundle, options, discounts } = params;
167
168
  let price = Number(product.price);
168
169
  if (bundle == null ? void 0 : bundle.length) {
169
170
  price = bundle.reduce((accumulator, currentValue) => {
@@ -175,6 +176,14 @@ var getProductTotalPrice = (params) => {
175
176
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
176
177
  }, price);
177
178
  }
179
+ if (discounts == null ? void 0 : discounts.length) {
180
+ discounts.forEach((currentValue) => {
181
+ if (currentValue.type !== "good_pass") {
182
+ const discountPrice = new import_decimal.default(100).minus(currentValue.discount.percent || 0).div(100).mul(new import_decimal.default(price || 0)).toFixed(2);
183
+ price = Number(discountPrice);
184
+ }
185
+ });
186
+ }
178
187
  return price;
179
188
  };
180
189
  var getProductOriginTotalPrice = (params) => {
@@ -87,7 +87,6 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
87
87
  const goodPassList = this.filterEnabledDiscountList(
88
88
  [...((_a = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _a.good_pass_list) || [], ...((_b = prepareConfig == null ? void 0 : prepareConfig.data) == null ? void 0 : _b.discount_card_list) || []]
89
89
  ) || [];
90
- this.setDiscountList(goodPassList);
91
90
  return goodPassList;
92
91
  }
93
92
  async batchSearch(code) {
@@ -79,8 +79,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
79
79
  productList
80
80
  };
81
81
  }
82
+ const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
82
83
  const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
83
- ...oldDiscountList,
84
+ ...filteredOldDiscountList,
84
85
  ...newDiscountList
85
86
  ]), "product_id");
86
87
  const result = this.calcDiscount({
@@ -227,10 +228,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
227
228
  });
228
229
  const selectedDiscount = applicableDiscounts[0];
229
230
  let isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (!((_c = product.discount_list) == null ? void 0 : _c.length) || ((_e = (_d = product == null ? void 0 : product.discount_list) == null ? void 0 : _d.every) == null ? void 0 : _e.call(_d, (item) => item.type === "product")));
230
- if ((options == null ? void 0 : options.discountId) && product.discount_list.some((item) => {
231
+ if ((options == null ? void 0 : options.discountId) && ((_f = product.discount_list) == null ? void 0 : _f.some((item) => {
231
232
  var _a2;
232
233
  return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
233
- })) {
234
+ }))) {
234
235
  isManualDiscount = false;
235
236
  }
236
237
  if (applicableDiscounts.length === 0 || isManualDiscount) {
@@ -279,7 +280,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
279
280
  return;
280
281
  }
281
282
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
282
- const splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
283
+ const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
283
284
  const arr = [];
284
285
  if (splitCount < product.quantity && isNeedSplit) {
285
286
  arr.push(this.hooks.setProduct(originProduct, {
@@ -292,9 +293,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
292
293
  const selectedDiscount2 = applicableDiscounts[i2];
293
294
  usedDiscounts.set(selectedDiscount2.id, true);
294
295
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
295
- const targetProductPrice = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.price || 0)).toFixed(2);
296
+ const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(product.price || 0)).toNumber() : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(product.origin_total || 0)).toNumber();
296
297
  const discountDetail = {
297
- amount: selectedDiscount2.tag === "good_pass" ? product.price : new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice)).toNumber(),
298
+ amount: new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(targetProductTotal)).toNumber(),
298
299
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
299
300
  discount: {
300
301
  resource_id: selectedDiscount2.id,
@@ -308,43 +309,27 @@ var RulesModule = class extends import_BaseModule.BaseModule {
308
309
  appliedProducts.push(discountDetail);
309
310
  appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
310
311
  if (product.isClient) {
311
- const variant = (_f = originProduct._productOrigin.variant) == null ? void 0 : _f.map((n) => {
312
- var _a2;
313
- if (n.id === ((_a2 = originProduct._productOrigin) == null ? void 0 : _a2.product_variant_id)) {
314
- n.original_price = n.price;
315
- const targetProductPrice2 = selectedDiscount2.tag === "good_pass" ? "0" : new import_decimal.default(100).minus(selectedDiscount2.par_value || 0).div(100).mul(new import_decimal.default(n.price || 0)).toFixed(2);
316
- n.price = targetProductPrice2;
317
- }
318
- return n;
319
- });
320
312
  arr.push(this.hooks.setProduct(originProduct, {
321
313
  discount_list: [discountDetail],
322
- price: new import_decimal.default(targetProductPrice).toNumber(),
314
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
323
315
  quantity: isNeedSplit ? 1 : product.quantity,
324
316
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
325
317
  product: {
326
- original_price: targetProductPrice
318
+ original_price: product.original_price
327
319
  },
328
320
  bundle: product.bundle,
329
321
  options: product.options
330
322
  }),
331
- variant,
332
- original_price: new import_decimal.default(product.price).toNumber(),
333
- total: (0, import_utils2.getProductTotalPrice)({
334
- product: {
335
- price: targetProductPrice
336
- },
337
- bundle: product.bundle,
338
- options: product.options
339
- })
323
+ original_price: new import_decimal.default(product.price || 0).toNumber(),
324
+ total: targetProductTotal
340
325
  }));
341
326
  } else {
342
327
  arr.push(this.hooks.setProduct(originProduct, {
343
328
  discount_list: [discountDetail],
344
329
  _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
345
- price: new import_decimal.default(targetProductPrice).toNumber(),
330
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
346
331
  quantity: isNeedSplit ? 1 : product.quantity,
347
- total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
332
+ total: targetProductTotal,
348
333
  origin_total: product.origin_total || product.total
349
334
  }));
350
335
  }
@@ -411,6 +396,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
411
396
  return {
412
397
  ...discount,
413
398
  isSelected: true,
399
+ isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
414
400
  // 标记为可用,因为它已被应用
415
401
  isAvailable: true,
416
402
  // 记录适用的商品IDs
@@ -432,6 +418,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
432
418
  // 如果有适用的商品,标记为可用
433
419
  isAvailable,
434
420
  isSelected,
421
+ // 如果是扫码进来的,要手动设置为手动选择:false
422
+ isManualSelect: (options == null ? void 0 : options.scan) ? false : discount.isManualSelect,
435
423
  // 记录适用的商品IDs
436
424
  applicableProductIds: applicableProducts,
437
425
  // 添加可抵扣的商品详情
@@ -47,10 +47,10 @@ export interface RulesParamsHooks {
47
47
  total?: number;
48
48
  discount_list: any[];
49
49
  origin_total?: number;
50
- price?: number;
51
- quantity?: number;
50
+ price?: string | number;
52
51
  variant?: any[];
53
52
  original_price?: number;
53
+ quantity?: number;
54
54
  }) => Record<string, any>;
55
55
  }
56
56
  export {};
@@ -398,7 +398,9 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
398
398
  const scanDiscount = (_c = this.getDiscountList()) == null ? void 0 : _c.filter(
399
399
  (item) => item.isScan
400
400
  );
401
- const newDiscountList = [...scanDiscount, ...goodPassList || []];
401
+ const scanDiscountIds = scanDiscount.map((n) => n.id);
402
+ const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
403
+ const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
402
404
  this.setDiscountList(newDiscountList || []);
403
405
  if ((_d = this.store.productList) == null ? void 0 : _d.length) {
404
406
  const result = this.calcDiscount(this.store.productList);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.165",
4
+ "version": "0.0.167",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",