diff --git a/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java b/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java index 1a2cac2..6355990 100644 --- a/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java +++ b/grademanagement-SpringMVCProject/src/com/ssm/entity/Product.java @@ -114,4 +114,33 @@ public class Product { ", listDate='" + listDate + '\'' + '}'; } + + // 计算折扣率 + public Double getDiscountRate() { + if (marketPrice != null && marketPrice > 0 && salesPrice != null) { + return (salesPrice / marketPrice) * 10; + } + return 0.0; + } + + // 判断是否有优惠 + public boolean hasDiscount() { + if (marketPrice != null && salesPrice != null) { + return salesPrice < marketPrice; + } + return false; + } + + // 获取节省金额 + public Double getSavedAmount() { + if (marketPrice != null && salesPrice != null) { + return marketPrice - salesPrice; + } + return 0.0; + } + + // 判断是否为热门商品 + public boolean isHotProduct() { + return "是".equals(isPopular) || "true".equalsIgnoreCase(isPopular) || "1".equals(isPopular); + } }