diff --git a/mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql b/mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql new file mode 100644 index 000000000..bbd20f642 --- /dev/null +++ b/mallinkAdmin/src/main/resources/db/migration/V201908221440__L_CONTRACT.sql @@ -0,0 +1,2 @@ +alter table wx_bill_rent +add column `bus_discount_ratio` int(5) NULL DEFAULT NULL COMMENT '连营扣点跳点率'; \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java index a83629168..bef858971 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java @@ -283,25 +283,28 @@ public class WxBillRentServiceImpl implements WxBillRentService { wxBillRent.setRevenue(record.getRevenue()); Integer ratio = 0; - if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ - long dayCount = DateUtils.startToEnd(record.getStarttime(),record.getEndtime()); - - if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ - if(startInt == endInt && months == 12){ - //刚好1年 - ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.OTHER.getCode(),dayCount,0).getRatio(); - }else{ - ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.YEAR.getCode(),dayCount,0).getRatio(); - } - }else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ - if(startInt == endInt && months == 1){ - //刚好1个月 - ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.OTHER.getCode(),dayCount,0).getRatio(); - }else{ - ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.MONTH.getCode(),dayCount,0).getRatio(); + if(wxRentContract.getPayRatio() != null){ + ratio = wxRentContract.getPayRatio(); + }else{ + if(StringUtils.isNotBlank(wxRentContract.getBusDiscountRatio())){ + long dayCount = DateUtils.startToEnd(record.getStarttime(),record.getEndtime()); + if(EnumBusRatioTime.YEAR.getCode().equals(wxRentContract.getBusDiscountTime())){ + if(startInt == endInt && months == 12){ + //刚好1年 + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.OTHER.getCode(),dayCount,0).getRatio(); + }else{ + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.YEAR.getCode(),dayCount,0).getRatio(); + } + }else if(EnumBusRatioTime.MONTH.getCode().equals(wxRentContract.getBusDiscountTime())){ + if(startInt == endInt && months == 1){ + //刚好1个月 + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.OTHER.getCode(),dayCount,0).getRatio(); + }else{ + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.MONTH.getCode(),dayCount,0).getRatio(); + } + }else if(EnumBusRatioTime.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())){ + ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.PERIOD.getCode(),dayCount,wxRentContract.getReceivePeriod()).getRatio(); } - }else if(EnumBusRatioTime.PERIOD.getCode().equals(wxRentContract.getBusDiscountTime())){ - ratio = WxRentContractServiceImpl.getPayRatio(EnumGetRatioFrom.BILL.getCode(),wxBillRent.getRevenue(),wxRentContract.getBusDiscountRatio(),EnumMissTimeType.PERIOD.getCode(),dayCount,wxRentContract.getReceivePeriod()).getRatio(); } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index eb24b22e9..46ef1f505 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -338,6 +338,20 @@ public class WxRentContractServiceImpl implements WxRentContractService { return ratioVo; } + /** + * 计算金额 + * @param ratio + * @param revenueLong + * @return + */ + public Long countPrice(Integer ratio,Long revenueLong){ + BigDecimal hundred = new BigDecimal(100); + BigDecimal revenue = new BigDecimal(revenueLong == null ? 0 : revenueLong).divide(hundred); + BigDecimal payRatio = new BigDecimal(ratio == null ? 0 : ratio).divide(new BigDecimal(10000)); + BigDecimal price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); + return price.multiply(hundred).longValue(); + } + @Transactional(rollbackFor = {Exception.class}) @Override public ResultData save(WxRentContract record,Long userId,String userName,Date oldRentStartDate) { @@ -361,23 +375,21 @@ public class WxRentContractServiceImpl implements WxRentContractService { } if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - if(record.getRevenue() == null || record.getRevenue().longValue() <=0){ + if(record.getRevenue() == null || record.getRevenue().longValue() <= 0){ record.setPrice(0l); }else{ - int dayCount = record.getReceivePeriod() * 30; - RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); - record.setPayRatio(ratioVo.getRatio()); - BigDecimal hundred = new BigDecimal(100); - BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); - BigDecimal payRatio = new BigDecimal(record.getPayRatio() == null ? 0 : record.getPayRatio()).divide(new BigDecimal(10000)); - - BigDecimal price; - if(ratioVo.getBalance() != null){ - //计算超出部分 - record.setPrice(ratioVo.getBalance().longValue()); + if(record.getPayRatio()!=null){ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); }else{ - price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - record.setPrice(price.multiply(hundred).longValue()); + int dayCount = record.getReceivePeriod() * 30; + RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); + record.setPayRatio(ratioVo.getRatio()); + if(ratioVo.getBalance() != null){ + //有超出部分,在getPayRatio里计算 + record.setPrice(ratioVo.getBalance().longValue()); + }else{ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + } } } } else { @@ -605,19 +617,18 @@ public class WxRentContractServiceImpl implements WxRentContractService { if(!EnumFromType.SWITCH.getCode().equals(from)){ if (record.getType().equals(EnumRentContractType.RENT_BY_JOINT.getCode())) { - int dayCount = record.getReceivePeriod() * 30; - RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,wxRentContract.getReceivePeriod()); - record.setPayRatio(ratioVo.getRatio()); - BigDecimal hundred = new BigDecimal(100); - BigDecimal revenue = new BigDecimal(record.getRevenue() == null ? 0 : record.getRevenue()).divide(hundred); - BigDecimal payRatio = new BigDecimal(record.getPayRatio() == null ? 0 : record.getPayRatio()).divide(new BigDecimal(10000)); - - BigDecimal price; - if(ratioVo.getBalance() != null){ - record.setPrice(ratioVo.getBalance().longValue()); - }else { - price = revenue.multiply(payRatio).setScale(2, RoundingMode.HALF_EVEN); - record.setPrice(price.multiply(hundred).longValue()); + if(record.getPayRatio()!=null){ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + }else{ + int dayCount = record.getReceivePeriod() * 30; + RatioVo ratioVo = getPayRatio(EnumGetRatioFrom.RENT.getCode(),record.getRevenue(),record.getBusDiscountRatio(),record.getBusDiscountTime(),dayCount,record.getReceivePeriod()); + record.setPayRatio(ratioVo.getRatio()); + if(ratioVo.getBalance() != null){ + //有超出部分,在getPayRatio里计算 + record.setPrice(ratioVo.getBalance().longValue()); + }else{ + record.setPrice(countPrice(record.getPayRatio(),record.getRevenue())); + } } } else { if (StringUtils.isNotEmpty(record.getPriceStr())) {