@pisell/pisellos 1.0.78 → 1.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -178,18 +178,18 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
178
178
  // 如果商品有折扣,则计算折扣
179
179
  if (discounts !== null && discounts !== void 0 && discounts.length) {
180
180
  discounts.forEach(function (currentValue) {
181
+ var _currentValue$discoun;
181
182
  // 不是商品券则代表折扣卡,计算打折后的价格
182
183
  // 一个商品折扣卡只能存在于一张
183
- if (currentValue.type !== 'good_pass') {
184
- var _currentValue$discoun;
185
- price = getDiscountAmount({
186
- tag: currentValue.type,
187
- par_value: currentValue.discount.percent,
188
- metadata: {
189
- discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
190
- }
191
- }, price, price);
192
- }
184
+ // if (currentValue.type !== 'good_pass') {
185
+ price = getDiscountAmount({
186
+ tag: currentValue.type,
187
+ par_value: currentValue.discount.percent,
188
+ metadata: {
189
+ discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
190
+ }
191
+ }, price, price);
192
+ // }
193
193
  });
194
194
  }
195
195
  if (bundle !== null && bundle !== void 0 && bundle.length) {
@@ -204,7 +204,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
204
204
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
205
205
  }, price);
206
206
  }
207
- return price;
207
+ return Math.max(0, price);
208
208
  };
209
209
 
210
210
  /**
@@ -268,7 +268,7 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
268
268
  }
269
269
  if (discount.appliedProductDetails) {
270
270
  return discount.appliedProductDetails.reduce(function (total, product) {
271
- var price = new Decimal((product === null || product === void 0 ? void 0 : product.amount) || 0).mul((product === null || product === void 0 ? void 0 : product.num) || 1);
271
+ var price = new Decimal((product === null || product === void 0 ? void 0 : product.amount) || 0);
272
272
  return new Decimal(total).plus(price).toNumber();
273
273
  }, 0);
274
274
  }
@@ -411,8 +411,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
411
411
  return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
412
412
  })) : !(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);
413
413
 
414
+ // 套餐是否可用判断
415
+ var isBundleAvailable = _this3.checkPackageSubItemUsageRules(discount, flatItem);
416
+
414
417
  // 判断优惠券是否适用于该商品
415
- if (isAvailableProduct && isLimitedProduct) {
418
+ if (isAvailableProduct && isLimitedProduct && isBundleAvailable) {
416
419
  var _discountApplicabilit, _discount$metadata;
417
420
  // 记录此优惠券适用的商品
418
421
  (_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
@@ -421,7 +424,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
421
424
  var applicableProducts = discountApplicableProducts.get(discount.id) || [];
422
425
  var discountType = discount.tag || discount.type;
423
426
  var productData = {
424
- amount: product.price,
427
+ amount: product.price * (product.num || 1),
425
428
  type: discountType,
426
429
  tag: discountType,
427
430
  discount: {
@@ -649,7 +652,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
649
652
  // 计算使用折扣卡/商品券以后,单个商品的总 total
650
653
  var targetProductTotal = getDiscountAmount(_selectedDiscount, product.price, product.price);
651
654
  var discountDetail = {
652
- amount: new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber(),
655
+ amount: new Decimal(product.price).minus(new Decimal(targetProductTotal)).toNumber() * (product.num || 1),
653
656
  type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
654
657
  discount: {
655
658
  discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
@@ -772,7 +775,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
772
775
  // 🔥 使用当前的 _id 作为唯一标识
773
776
  var _uniqueId = flatItem._id;
774
777
  var _discountDetail2 = {
775
- amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber(),
778
+ amount: new Decimal(_productOriginTotal).minus(_targetProductTotal).toNumber() * (product.num || 1),
776
779
  type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
777
780
  discount: {
778
781
  discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
@@ -797,7 +800,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
797
800
  appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
798
801
  processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
799
802
  total: _targetProductTotal,
800
- price: new Decimal(_productOriginTotal || 0).minus(_discountDetail2.amount).toNumber(),
803
+ price: new Decimal(_productOriginTotal || 0).minus(_discountDetail2.discount.fixed_amount).toNumber(),
801
804
  discount_list: [_discountDetail2],
802
805
  processed: true
803
806
  }));
@@ -175,15 +175,13 @@ var getProductTotalPrice = (params) => {
175
175
  if (discounts == null ? void 0 : discounts.length) {
176
176
  discounts.forEach((currentValue) => {
177
177
  var _a;
178
- if (currentValue.type !== "good_pass") {
179
- price = (0, import_utils2.getDiscountAmount)({
180
- tag: currentValue.type,
181
- par_value: currentValue.discount.percent,
182
- metadata: {
183
- discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
184
- }
185
- }, price, price);
186
- }
178
+ price = (0, import_utils2.getDiscountAmount)({
179
+ tag: currentValue.type,
180
+ par_value: currentValue.discount.percent,
181
+ metadata: {
182
+ discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
183
+ }
184
+ }, price, price);
187
185
  });
188
186
  }
189
187
  if (bundle == null ? void 0 : bundle.length) {
@@ -196,7 +194,7 @@ var getProductTotalPrice = (params) => {
196
194
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
197
195
  }, price);
198
196
  }
199
- return price;
197
+ return Math.max(0, price);
200
198
  };
201
199
  var getProductOriginTotalPrice = (params) => {
202
200
  const { product, bundle, options, discounts } = params;
@@ -163,7 +163,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
163
163
  }
164
164
  if (discount.appliedProductDetails) {
165
165
  return discount.appliedProductDetails.reduce((total, product) => {
166
- const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0).mul((product == null ? void 0 : product.num) || 1);
166
+ const price = new import_decimal.default((product == null ? void 0 : product.amount) || 0);
167
167
  return new import_decimal.default(total).plus(price).toNumber();
168
168
  }, 0);
169
169
  }
@@ -268,12 +268,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
268
268
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
269
269
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
270
270
  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));
271
- if (isAvailableProduct && isLimitedProduct) {
271
+ const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
272
+ if (isAvailableProduct && isLimitedProduct && isBundleAvailable) {
272
273
  (_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
273
274
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
274
275
  const discountType = discount.tag || discount.type;
275
276
  const productData = {
276
- amount: product.price,
277
+ amount: product.price * (product.num || 1),
277
278
  type: discountType,
278
279
  tag: discountType,
279
280
  discount: {
@@ -454,7 +455,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
454
455
  }
455
456
  const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
456
457
  const discountDetail = {
457
- amount: new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber(),
458
+ amount: new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber() * (product.num || 1),
458
459
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
459
460
  discount: {
460
461
  discount_card_type: (_m = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _m.discount_card_type,
@@ -564,7 +565,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
564
565
  );
565
566
  const uniqueId = flatItem._id;
566
567
  const discountDetail = {
567
- amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
568
+ amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber() * (product.num || 1),
568
569
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
569
570
  discount: {
570
571
  discount_card_type: (_n = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _n.discount_card_type,
@@ -588,7 +589,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
588
589
  processedItems.push({
589
590
  ...flatItem,
590
591
  total: targetProductTotal,
591
- price: new import_decimal.default(productOriginTotal || 0).minus(discountDetail.amount).toNumber(),
592
+ price: new import_decimal.default(productOriginTotal || 0).minus(discountDetail.discount.fixed_amount).toNumber(),
592
593
  discount_list: [discountDetail],
593
594
  processed: true
594
595
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.78",
4
+ "version": "1.0.79",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",