Authored by wangnan9279

vipprice逻辑修改

... ... @@ -13,108 +13,108 @@ import java.util.List;
@Service
public class VipPriceLogicService {
/**
* 设置计划的vip价格
*/
public void fillProductPricePlanVipPrice(ProductPricePlan p) {
VipPriceBO vipPriceBO = this.getVipPriceBO(p.getCurrentSaleprice(), p.getVipDiscountType(), p.getVipDiscount());
p.setVip1Price(vipPriceBO.getVip1PriceBigDecimal());
p.setVip2Price(vipPriceBO.getVip2PriceBigDecimal());
p.setVip3Price(vipPriceBO.getVip3PriceBigDecimal());
}
/**
* 设置计划的vip价格
*/
public void fillProductPricePlanVipPrice(ProductPricePlan p) {
VipPriceBO vipPriceBO = this.getVipPriceBO(p.getCurrentSaleprice(), p.getVipDiscountType(), p.getVipDiscount());
p.setVip1Price(vipPriceBO.getVip1PriceBigDecimal());
p.setVip2Price(vipPriceBO.getVip2PriceBigDecimal());
p.setVip3Price(vipPriceBO.getVip3PriceBigDecimal());
}
/**
* 计算并重设vip相关价格
*/
public void fillProductPriceVipPrice(ProductPriceBO productPriceBO, Integer sellType) {
/**
* salesPrice等于productPrice表的currentPrice, type是productPrice表的currentVipDiscountType
*/
VipPriceBO vipPriceBO = this.getVipPriceBO(productPriceBO.getSalesPrice(), productPriceBO.getVipDiscountType(), productPriceBO.getVipDiscount());
productPriceBO.setVip1Price(vipPriceBO.getVip1PriceBigDecimal());
productPriceBO.setVip2Price(vipPriceBO.getVip2PriceBigDecimal());
productPriceBO.setVip3Price(vipPriceBO.getVip3PriceBigDecimal());
// 设置vipLevels
double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
double vip1Price = this.getDoubleFromBigDecimal(productPriceBO.getVip1Price());
double vip2Price = this.getDoubleFromBigDecimal(productPriceBO.getVip2Price());
double vip3Price = this.getDoubleFromBigDecimal(productPriceBO.getVip3Price());
/**
* 计算并重设vip相关价格
*/
public void fillProductPriceVipPrice(ProductPriceBO productPriceBO, Integer sellType) {
// 是经销,并且两个价格相等,才有vip
double marketPrice = this.getDoubleFromBigDecimal(productPriceBO.getMarketPrice());
double salesPrice = this.getDoubleFromBigDecimal(productPriceBO.getSalesPrice());
if (sellType != null && sellType == 1 && marketPrice != salesPrice) {
productPriceBO.setVipLevels("");
productPriceBO.setVip1Price(productPriceBO.getSalesPrice());
productPriceBO.setVip2Price(productPriceBO.getSalesPrice());
productPriceBO.setVip3Price(productPriceBO.getSalesPrice());
return;
}
// 是经销,并且两个价格相等,才有vip
if (sellType != null && sellType == 1 && marketPrice != salesPrice) {
productPriceBO.setVipLevels("");
return;
}
//计算vip价格
VipPriceBO vipPriceBO = this.getVipPriceBO(productPriceBO.getSalesPrice(), productPriceBO.getVipDiscountType(), productPriceBO.getVipDiscount());
productPriceBO.setVip1Price(vipPriceBO.getVip1PriceBigDecimal());
productPriceBO.setVip2Price(vipPriceBO.getVip2PriceBigDecimal());
productPriceBO.setVip3Price(vipPriceBO.getVip3PriceBigDecimal());
List<String> vipLevels = new ArrayList<String>();
if (vip1Price > 0 && vip1Price < salesPrice) {
vipLevels.add("1");
}
if (vip2Price > 0 && vip2Price < salesPrice) {
vipLevels.add("2");
}
if (vip3Price > 0 && vip3Price < salesPrice) {
vipLevels.add("3");
}
productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));
double vip1Price = this.getDoubleFromBigDecimal(productPriceBO.getVip1Price());
double vip2Price = this.getDoubleFromBigDecimal(productPriceBO.getVip2Price());
double vip3Price = this.getDoubleFromBigDecimal(productPriceBO.getVip3Price());
}
List<String> vipLevels = new ArrayList<String>();
if (vip1Price > 0 && vip1Price < salesPrice) {
vipLevels.add("1");
}
if (vip2Price > 0 && vip2Price < salesPrice) {
vipLevels.add("2");
}
if (vip3Price > 0 && vip3Price < salesPrice) {
vipLevels.add("3");
}
productPriceBO.setVipLevels(StringUtils.join(vipLevels, ","));
}
private VipPriceBO getVipPriceBO(BigDecimal currentSalesPrice, Integer currentVipDiscountType, BigDecimal vipDiscount) {
double salesPriceDoubleCeil = Math.ceil(this.getDoubleFromBigDecimal(currentSalesPrice));
// 默认取销售价
double vip1PriceResult = salesPriceDoubleCeil;
double vip2PriceResult = salesPriceDoubleCeil;
double vip3PriceResult = salesPriceDoubleCeil;
if (currentVipDiscountType == null) {
return new VipPriceBO(vip1PriceResult, vip2PriceResult, vip3PriceResult);
}
switch (currentVipDiscountType) {
case 1:
vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.95));
vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.9));
vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.88));
break;
case 2:
if (!isVipDiscountLegal(vipDiscount)) {
vipDiscount = new BigDecimal(0.95);
}
BigDecimal price = vipDiscount.multiply(BigDecimal.valueOf(salesPriceDoubleCeil));
vip1PriceResult = Double.valueOf(String.format("%.2f", price));
vip2PriceResult = Double.valueOf(String.format("%.2f", price));
vip3PriceResult = Double.valueOf(String.format("%.2f", price));
break;
case 3:
vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
break;
default:
vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
break;
}
return new VipPriceBO(vip1PriceResult, vip2PriceResult, vip3PriceResult);
}
private VipPriceBO getVipPriceBO(BigDecimal currentSalesPrice, Integer currentVipDiscountType, BigDecimal vipDiscount) {
double salesPriceDoubleCeil = Math.ceil(this.getDoubleFromBigDecimal(currentSalesPrice));
// 默认取销售价
double vip1PriceResult = salesPriceDoubleCeil;
double vip2PriceResult = salesPriceDoubleCeil;
double vip3PriceResult = salesPriceDoubleCeil;
if (currentVipDiscountType == null) {
return new VipPriceBO(vip1PriceResult, vip2PriceResult, vip3PriceResult);
}
switch (currentVipDiscountType) {
case 1:
vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.95));
vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.9));
vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil * 0.88));
break;
case 2:
if (!isVipDiscountLegal(vipDiscount)) {
vipDiscount = new BigDecimal(0.95);
}
BigDecimal price = vipDiscount.multiply(BigDecimal.valueOf(salesPriceDoubleCeil));
vip1PriceResult = Double.valueOf(String.format("%.2f", price));
vip2PriceResult = Double.valueOf(String.format("%.2f", price));
vip3PriceResult = Double.valueOf(String.format("%.2f", price));
break;
case 3:
vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
break;
default:
vip1PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip2PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
vip3PriceResult = Double.valueOf(String.format("%.2f", salesPriceDoubleCeil));
break;
}
return new VipPriceBO(vip1PriceResult, vip2PriceResult, vip3PriceResult);
}
private boolean isVipDiscountLegal(BigDecimal vipDisCount) {
if (vipDisCount == null) {
return false;
}
boolean gt0 = vipDisCount.compareTo(BigDecimal.ZERO) == 1;
boolean lt1 = vipDisCount.compareTo(BigDecimal.ONE) == -1;
if (gt0 && lt1) {
return true;
}
return false;
}
private boolean isVipDiscountLegal(BigDecimal vipDisCount) {
if (vipDisCount == null) {
return false;
}
boolean gt0 = vipDisCount.compareTo(BigDecimal.ZERO) == 1;
boolean lt1 = vipDisCount.compareTo(BigDecimal.ONE) == -1;
if (gt0 && lt1) {
return true;
}
return false;
}
private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
if (bigDecimal == null) {
return 0d;
}
return bigDecimal.doubleValue();
}
private double getDoubleFromBigDecimal(BigDecimal bigDecimal) {
if (bigDecimal == null) {
return 0d;
}
return bigDecimal.doubleValue();
}
}
... ...