Commit 1f8665dd authored by libin's avatar libin

Merge remote-tracking branch 'origin/holiday-price' into holiday-price

parents e5d49641 031d7ffc
package com.xxfc.platform.order.pojo.order;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
......@@ -18,6 +20,8 @@ import java.util.List;
@Data
public class VehicleItemDTO extends OrderItem {
public static final int topNum = 2;
//已抵消天数
private Integer offsetNum;
public BigDecimal calculateVehicleUnitPrice(BigDecimal vehicleAmount, BigDecimal metaVehicleAmount, Boolean isSetRealAmount) {
if(isSetRealAmount) {
setRealAmount(vehicleAmount);
......@@ -38,44 +42,50 @@ public class VehicleItemDTO extends OrderItem {
}
public BigDecimal getCutAmount() {
List<VehicleModelCalendarPriceDTO> vmcpds = getVehicleDetail();
List<VMCalendarPriceCostDTO> vmcpds = getVehicleDetail();
if(CollUtil.isEmpty(vmcpds)){
return super.getCutAmount();
}
BigDecimal cutAmount = BigDecimal.ZERO;
for(int i = 0; i < getCutNum(); i++) {
cutAmount = cutAmount.add(vmcpds.get(i).getPrice());
// for(int i = 0; i < getCutNum(); i++) {
for(VMCalendarPriceCostDTO vmcpd : vmcpds) {
cutAmount = cutAmount.add(vmcpd.getFreeAmount());
}
return cutAmount;
}
public List<VehicleModelCalendarPriceDTO> getVehicleDetail() {
public List<VMCalendarPriceCostDTO> getVehicleDetail() {
if(StrUtil.isBlank(getDetail())) {
return CollUtil.newArrayList();
}
return JSONUtil.toList(JSONUtil.parseArray(getDetail()), VehicleModelCalendarPriceDTO.class);
return JSONUtil.toList(JSONUtil.parseArray(getDetail()), VMCalendarPriceCostDTO.class);
}
public BigDecimal getBuyAmount() {
List<VehicleModelCalendarPriceDTO> vmcpds = getVehicleDetail();
List<VMCalendarPriceCostDTO> vmcpds = getVehicleDetail();
if(CollUtil.isEmpty(vmcpds)){
return super.getBuyAmount();
}
BigDecimal buyAmount = BigDecimal.ZERO;
for(int i = 0; i < getBuyNum(); i++) {
//for(VMCalendarPriceCostDTO vmcpd : vmcpds) {
buyAmount = buyAmount.add(vmcpds.get(i).getPrice());
}
return buyAmount;
}
public BigDecimal getTopAmount(Integer useDays) {
List<VehicleModelCalendarPriceDTO> vmcpds = getVehicleDetail();
List<VMCalendarPriceCostDTO> vmcpds = getVehicleDetail();
if(CollUtil.isEmpty(vmcpds)){
return getUnitPrice().multiply(new BigDecimal(topNum+ ""));
}
BigDecimal topAmount = BigDecimal.ZERO;
for(int i = useDays; i < getTotalNum(); i++) {
topAmount = topAmount.add(vmcpds.get(i).getPrice());
if((i - useDays) >= topNum) {
break;
}else {
topAmount = topAmount.add(vmcpds.get(i).getPrice());
}
}
//未用天数 小于 topNum
......@@ -91,7 +101,7 @@ public class VehicleItemDTO extends OrderItem {
}
public BigDecimal getFreeAmount(Integer freeDays) {
List<VehicleModelCalendarPriceDTO> vmcpds = getVehicleDetail();
List<VMCalendarPriceCostDTO> vmcpds = getVehicleDetail();
if(CollUtil.isEmpty(vmcpds)){
return getUnitPrice().multiply(new BigDecimal(freeDays+ ""));
}
......@@ -101,4 +111,43 @@ public class VehicleItemDTO extends OrderItem {
}
return freeAmount;
}
// public Integer getActualNum() {
//
// }
public void initDetail(Integer ableFreeDays) {
if(StrUtil.isNotBlank(getDetail())) {
List<VehicleModelCalendarPriceDTO> metaList = JSONUtil.toList(JSONUtil.parseArray(getDetail()), VehicleModelCalendarPriceDTO.class);
//计算消费金额
List<VMCalendarPriceCostDTO> list = Convert.toList(VMCalendarPriceCostDTO.class, metaList);
//循环价格列表 获得对应消耗的免费天数
//循环已标记的已使用免费天数
Integer cycleNum = 0;
for(VMCalendarPriceCostDTO dto : list) {
if(ableFreeDays > cycleNum && cycleNum+ dto.getFreeDays() > ableFreeDays) { //本次累加天数 大于 可用免费天数
setCutNum(ableFreeDays);
Integer up = (ableFreeDays - cycleNum);
Integer down = dto.getFreeDays();
//根据百分比计算消费价格
dto.setFreeAndConsumeAmount(dto.getPrice(), dto.getPrice().multiply(
new BigDecimal(up+ "").divide(new BigDecimal(down+ ""), 2, RoundingMode.HALF_UP))
.setScale(2, RoundingMode.HALF_UP));
}else if(ableFreeDays > cycleNum){ //本次累加天数 小于等于 可用免费天数
setCutNum(getCutNum()+ dto.getFreeDays());
//直接设置价格
dto.setFreeAndConsumeAmount(dto.getPrice(), BigDecimal.ZERO);
this.offsetNum += 1;
}else { //上次累加天数 大于 可用天数
//直接设置价格
dto.setFreeAndConsumeAmount(dto.getPrice(), BigDecimal.ZERO);
}
cycleNum += dto.getFreeDays();
}
setDetail(JSONUtil.parseArray(list).toString());
}
}
}
......@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.xxfc.platform.order.contant.enumerate.ItemTypeEnum;
import com.xxfc.platform.order.pojo.order.VehicleItemDTO;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO;
import com.xxfc.platform.vehicle.pojo.dto.order.VMCalendarPriceCostDTO;
......
......@@ -39,6 +39,7 @@ import com.xxfc.platform.vehicle.entity.VehicleModel;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import com.xxfc.platform.vehicle.pojo.RentVehicleBookDTO;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO;
import com.xxfc.platform.vehicle.pojo.dto.order.VMCalendarPriceCostDTO;
import com.xxfc.platform.vehicle.pojo.vo.AccompanyingItemVo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
......@@ -229,7 +230,8 @@ public class OrderRentVehicleService extends AbstractOrderHandle<OrderRentVehicl
String couponDesc = "";
Integer vehicleDayNum = 0;
Integer freeDayNum = 0;
Integer cutDayNum = 0;
//抵消的天数
Integer offsetNum = 0;
//当前用户
AppUserDTO dto = detail.getAppUserDTO();
......@@ -260,21 +262,25 @@ public class OrderRentVehicleService extends AbstractOrderHandle<OrderRentVehicl
}});
}
//循环价格列表 获得对应消耗的免费天数
for(VehicleModelCalendarPriceDTO vmcpd : vmcpds) {
//如果新的相加消耗天数 大于 拥有天数
if(freeDayNum+ vmcpd.getFreeDays() > dto.getRentFreeDays()) {
//freeDayNum = dto.getRentFreeDays();
break;
}else {
freeDayNum += detail.getDayNum();
cutDayNum += 1;
}
}
vehicleOrderItem.setCutNum(cutDayNum);
vehicleDayNum = detail.getDayNum() - cutDayNum;
// //循环价格列表 获得对应消耗的免费天数
// for(VehicleModelCalendarPriceDTO vmcpd : vmcpds) {
// //如果新的相加消耗天数 大于 拥有天数
// if(freeDayNum+ vmcpd.getFreeDays() > dto.getRentFreeDays()) {
// //freeDayNum = dto.getRentFreeDays();
// break;
// }else {
// freeDayNum += detail.getDayNum();
// cutDayNum += 1;
// }
// }
// vehicleOrderItem.setCutNum(cutDayNum);
freeDayNum = vehicleOrderItem.getCutNum();
offsetNum = vehicleOrderItem.getOffsetNum();
vehicleOrderItem.initDetail(dto.getRentFreeDays());
vehicleDayNum = detail.getDayNum() - offsetNum;
detail.getOrder().setHasMemberRight(SYS_TRUE);
}else {
vehicleOrderItem.initDetail(0);
vehicleDayNum = detail.getDayNum();
}
......@@ -309,13 +315,21 @@ public class OrderRentVehicleService extends AbstractOrderHandle<OrderRentVehicl
// default:
// break;
// }
//设置是否使用会员权益
for(VMCalendarPriceCostDTO vmcpcd : vehicleOrderItem.getVehicleDetail()) {
if(!vmcpcd.getNo_discount_price().equals(vmcpcd.getPrice())) {
detail.getOrder().setHasMemberRight(SYS_TRUE);
break;
}
}
detail.setRebate(dto.getDiscount());
// vehicleOrderItem.setUnitPrice(handleDiscountDTO.getModelAmount());
}
//计算价格
if(vehicleDayNum > 0) {
for(int i = cutDayNum; i < vmcpds.size(); i++) {
for(int i = offsetNum; i < vmcpds.size(); i++) {
vehicleAmount = vehicleAmount.add(vmcpds.get(i).getPrice());
metaVehicleAmount = metaVehicleAmount.add(vmcpds.get(i).getNo_discount_price());
}
......@@ -392,7 +406,7 @@ public class OrderRentVehicleService extends AbstractOrderHandle<OrderRentVehicl
rvp.setVehicleDayNum(vehicleDayNum);
rvp.setFreeDayNum(freeDayNum);
rvp.setCutDayNum(cutDayNum);
rvp.setCutDayNum(offsetNum);
rvp.setFreeAmount(vehicleOrderItem.getCutAmount());
rvp.setBuyVehicleAmount(vehicleOrderItem.getBuyAmount());
rvp.setRealVehicleAmount(vehicleOrderItem.getRealAmount());
......
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
@Data
......@@ -11,4 +12,19 @@ public class VMCalendarPriceCostDTO extends VehicleModelCalendarPriceDTO {
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd")
private Date date;
/**
* 消费金额
*/
private BigDecimal consumeAmount = BigDecimal.ZERO;
/**
* 免费金额
*/
private BigDecimal freeAmount = BigDecimal.ZERO;
public void setFreeAndConsumeAmount(BigDecimal realAmount, BigDecimal freeAmount) {
setFreeAmount(freeAmount);
setConsumeAmount(realAmount.subtract(freeAmount));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment