@pisell/pisellos 1.0.24 → 1.0.25

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.
@@ -330,7 +330,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
330
330
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
331
331
  var applicableDiscounts = sortedDiscountList.filter(function (discount) {
332
332
  // 如果商品价格为 0,其实不需要使用任何优惠券,直接 return true
333
- if (Number(product.price) === 0 || !product.price) return false;
333
+ if (Number(product.price) === 0 && discount.tag === 'good_pass' || Number(product.total) === 0 && discount.tag !== 'good_pass' || !product.price) return false;
334
334
  // 如果优惠券已被使用,则跳过
335
335
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
336
336
  if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
@@ -422,16 +422,17 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
422
422
 
423
423
  // 记录实际应用了优惠券的商品信息
424
424
  var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
425
+ var productOriginTotal = product.origin_total || product.total || 0;
425
426
 
426
427
  // 计算使用折扣卡/商品券以后,单个商品的总 total
427
- 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();
428
+ var targetProductTotal = _selectedDiscount.tag === 'good_pass' ? new Decimal(productOriginTotal).minus(new Decimal(product.price || 0)).toNumber() : new Decimal(100).minus(_selectedDiscount.par_value || 0).div(100).mul(new Decimal(productOriginTotal)).toNumber();
428
429
  var discountDetail = {
429
- amount: new Decimal(product.origin_total || 0).minus(new Decimal(targetProductTotal)).toNumber(),
430
+ amount: new Decimal(productOriginTotal).minus(new Decimal(targetProductTotal)).toNumber(),
430
431
  type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount.tag,
431
432
  discount: {
432
433
  resource_id: _selectedDiscount.id,
433
434
  title: _selectedDiscount.format_title,
434
- original_amount: product.origin_total,
435
+ original_amount: productOriginTotal,
435
436
  product_id: originProduct.id,
436
437
  percent: _selectedDiscount.par_value
437
438
  },
@@ -465,7 +466,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
465
466
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
466
467
  quantity: isNeedSplit ? 1 : product.quantity,
467
468
  total: targetProductTotal,
468
- origin_total: product.origin_total || product.total
469
+ origin_total: productOriginTotal
469
470
  }));
470
471
  }
471
472
  }
@@ -504,7 +504,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
504
504
  return n.id === id;
505
505
  });
506
506
  var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
507
- return Number(product === null || product === void 0 ? void 0 : product.price) === 0;
507
+ return Number(product === null || product === void 0 ? void 0 : product.total) === 0;
508
508
  };
509
509
  var isAllProductUsedOrFree = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
510
510
  var _item$applicableProdu2;
@@ -213,7 +213,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
213
213
  return;
214
214
  }
215
215
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
216
- if (Number(product.price) === 0 || !product.price)
216
+ if (Number(product.price) === 0 && discount.tag === "good_pass" || Number(product.total) === 0 && discount.tag !== "good_pass" || !product.price)
217
217
  return false;
218
218
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
219
219
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
@@ -293,14 +293,15 @@ var RulesModule = class extends import_BaseModule.BaseModule {
293
293
  const selectedDiscount2 = applicableDiscounts[i2];
294
294
  usedDiscounts.set(selectedDiscount2.id, true);
295
295
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
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
+ const productOriginTotal = product.origin_total || product.total || 0;
297
+ const targetProductTotal = selectedDiscount2.tag === "good_pass" ? new import_decimal.default(productOriginTotal).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(productOriginTotal)).toNumber();
297
298
  const discountDetail = {
298
- amount: new import_decimal.default(product.origin_total || 0).minus(new import_decimal.default(targetProductTotal)).toNumber(),
299
+ amount: new import_decimal.default(productOriginTotal).minus(new import_decimal.default(targetProductTotal)).toNumber(),
299
300
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
300
301
  discount: {
301
302
  resource_id: selectedDiscount2.id,
302
303
  title: selectedDiscount2.format_title,
303
- original_amount: product.origin_total,
304
+ original_amount: productOriginTotal,
304
305
  product_id: originProduct.id,
305
306
  percent: selectedDiscount2.par_value
306
307
  },
@@ -331,7 +332,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
331
332
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
332
333
  quantity: isNeedSplit ? 1 : product.quantity,
333
334
  total: targetProductTotal,
334
- origin_total: product.origin_total || product.total
335
+ origin_total: productOriginTotal
335
336
  }));
336
337
  }
337
338
  }
@@ -346,7 +346,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
346
346
  var _a3;
347
347
  const targetProduct = productList.find((n) => n.id === id);
348
348
  const product = (_a3 = this.hooks) == null ? void 0 : _a3.getProduct(targetProduct);
349
- return Number(product == null ? void 0 : product.price) === 0;
349
+ return Number(product == null ? void 0 : product.total) === 0;
350
350
  };
351
351
  const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
352
352
  var _a3;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "1.0.24",
4
+ "version": "1.0.25",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",