Commit 731e292a authored by 周健威's avatar 周健威

修改代码

parent ff0873bb
...@@ -29,4 +29,8 @@ public class OrderAccountDetail { ...@@ -29,4 +29,8 @@ public class OrderAccountDetail {
* 扣款列表 * 扣款列表
*/ */
List<OrderAccountDeduction> deductions = Lists.newArrayList(); List<OrderAccountDeduction> deductions = Lists.newArrayList();
public BigDecimal realTotalDeduct() {
return originDepositAmount.add(originOrderAmount).subtract(orderAmount).subtract(depositAmount);
}
} }
...@@ -84,42 +84,57 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> { ...@@ -84,42 +84,57 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> {
/** /**
* 租车退款流程 * 租车退款流程
* @param baseOrder * @param baseOrder
* @param mainItemRealAmount 主要商品(租车费用、旅游费用等) * @param orderDeductSource 主要商品(租车费用、旅游费用等)
* @param timeLag 与开始时间的时间差 * @param timeLag 与开始时间的时间差
* @param dicParentKey * @param dicParentKey
*/ */
public BigDecimal rentRefundProcessCancel(BaseOrder baseOrder, BigDecimal mainItemRealAmount, Long timeLag, String dicParentKey, BigDecimal depositAmount, BigDecimal originalDeductAmount, OrderAccountDetail oad, BigDecimal topAmount) { public BigDecimal rentRefundProcessCancel(BaseOrder baseOrder, BigDecimal orderDeductSource, Long timeLag, String dicParentKey, BigDecimal depositAmount, BigDecimal depositDeductSource, OrderAccountDetail oad, BigDecimal topAmount) {
//计算退款金额 //原来退款 和 最终退款
//商品价格 - 优惠券减免的价格 BigDecimal originalRefundAmount = BigDecimal.ZERO;
BigDecimal originalRefundAmount = BigDecimal.ZERO.add(mainItemRealAmount); BigDecimal refundAmount = BigDecimal.ZERO;
StringBuilder orderRefundDescBuilder = new StringBuilder(""); StringBuilder orderRefundDescBuilder = new StringBuilder("");
StringBuilder depositRefundDescBuilder = new StringBuilder(""); StringBuilder depositRefundDescBuilder = new StringBuilder("");
BigDecimal totalDeductAmount = BigDecimal.ZERO; BigDecimal totalDeductAmount = BigDecimal.ZERO;
if(null == oad) { if(null == oad) {
oad = new OrderAccountDetail(); oad = new OrderAccountDetail();
} }
BigDecimal orderDeductAmount = calculateDeduction(originalRefundAmount, timeLag, dicParentKey, orderRefundDescBuilder); // 订单款 原订单退款、最终订单退款
orderDeductAmount = orderDeductAmount.setScale(2, RoundingMode.HALF_UP); BigDecimal originalOrderRefundAmount = BigDecimal.ZERO.add(baseOrder.getGoodsAmount().subtract(baseOrder.getCouponAmount()));
if(topAmount.compareTo(orderDeductAmount) > 0) { BigDecimal orderRefundAmount = BigDecimal.ZERO.add(baseOrder.getGoodsAmount().subtract(baseOrder.getCouponAmount()));
totalDeductAmount = totalDeductAmount.add(orderDeductAmount);
topAmount = topAmount.subtract(orderDeductAmount); if(null != orderDeductSource && BigDecimal.ZERO.compareTo(orderDeductSource) < 0) {
}else { BigDecimal orderDeductAmount = calculateDeduction(orderDeductSource, timeLag, dicParentKey, orderRefundDescBuilder);
totalDeductAmount = totalDeductAmount.add(topAmount); orderDeductAmount = orderDeductAmount.setScale(2, RoundingMode.HALF_UP);
orderDeductAmount = topAmount; if(topAmount.compareTo(orderDeductAmount) > 0) {
topAmount = BigDecimal.ZERO; totalDeductAmount = totalDeductAmount.add(orderDeductAmount);
topAmount = topAmount.subtract(orderDeductAmount);
}else {
totalDeductAmount = totalDeductAmount.add(topAmount);
orderDeductAmount = topAmount;
topAmount = BigDecimal.ZERO;
}
//订单退款
orderRefundAmount = orderRefundAmount.subtract(orderDeductAmount);
if(orderRefundAmount.compareTo(BigDecimal.ZERO) < 0) {
orderRefundAmount = BigDecimal.ZERO;
}
} }
BigDecimal refundMainGoodsAmount = originalRefundAmount.subtract(orderDeductAmount);
//退款金额 = 主要商品退款 + (其他商品退款) 即--> 主要商品退款 + (总商品款 - 主要商品款) //设置金额
oad.setOrderAmount(refundMainGoodsAmount.add(baseOrder.getGoodsAmount().subtract(baseOrder.getCouponAmount()).subtract(mainItemRealAmount))); oad.setOriginOrderAmount(originalOrderRefundAmount);
BigDecimal refundAmount = oad.getOrderAmount(); oad.setOrderAmount(orderRefundAmount);
originalRefundAmount = originalRefundAmount.add(oad.getOriginOrderAmount());
refundAmount = refundAmount.add(oad.getOrderAmount());
// 押金 原押金退款、最终押金退款
BigDecimal originalDepositRefundAmount = BigDecimal.ZERO.add(depositAmount);
BigDecimal depositRefundAmount = BigDecimal.ZERO.add(depositAmount);
// 押金 if(null != depositDeductSource && BigDecimal.ZERO.compareTo(depositDeductSource) < 0) {
BigDecimal originalRefundAmountDeposit = BigDecimal.ZERO.add(depositAmount);
BigDecimal refundAmountDeposit = BigDecimal.ZERO.add(depositAmount);
if(null != originalDeductAmount && BigDecimal.ZERO.compareTo(originalDeductAmount) < 0) {
//通过原扣除款 计算剩余款 //通过原扣除款 计算剩余款
BigDecimal depositDeductAmount = calculateDeduction(originalDeductAmount, timeLag, dicParentKey, depositRefundDescBuilder); BigDecimal depositDeductAmount = calculateDeduction(depositDeductSource, timeLag, dicParentKey, depositRefundDescBuilder);
depositDeductAmount = depositDeductAmount.setScale(2, RoundingMode.HALF_UP); depositDeductAmount = depositDeductAmount.setScale(2, RoundingMode.HALF_UP);
if(topAmount.compareTo(depositDeductAmount) > 0) { if(topAmount.compareTo(depositDeductAmount) > 0) {
totalDeductAmount = totalDeductAmount.add(depositDeductAmount); totalDeductAmount = totalDeductAmount.add(depositDeductAmount);
...@@ -131,24 +146,28 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> { ...@@ -131,24 +146,28 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> {
} }
//返回押金 //返回押金
refundAmountDeposit = originalRefundAmountDeposit.subtract(depositDeductAmount); depositRefundAmount = originalDepositRefundAmount.subtract(depositDeductAmount);
} }
//设置违章款账单 //设置违章款账单
StringBuilder stringBuilder = new StringBuilder(""); StringBuilder stringBuilder = new StringBuilder("");
if(totalDeductAmount.compareTo(BigDecimal.ZERO) > 0) { if(totalDeductAmount.compareTo(BigDecimal.ZERO) > 0) {
int originType = 0;
if(orderRefundDescBuilder.length() > 0) { if(orderRefundDescBuilder.length() > 0) {
stringBuilder = orderRefundDescBuilder; stringBuilder = orderRefundDescBuilder;
originType = OrderAccountDeduction.ORIGIN_ORDER;
}else { }else {
stringBuilder = depositRefundDescBuilder; stringBuilder = depositRefundDescBuilder;
originType = OrderAccountDeduction.ORIGIN_DEPOSIT;
} }
oad.getDeductions().add(initDeduction(totalDeductAmount, stringBuilder.toString(), DeductionTypeEnum.VIOLATE_CANCEL, OrderAccountDeduction.ORIGIN_DEPOSIT)); oad.getDeductions().add(initDeduction(totalDeductAmount, stringBuilder.toString(), DeductionTypeEnum.VIOLATE_CANCEL, originType));
} }
//设置订单押金金额 //设置订单押金金额
originalRefundAmount = originalRefundAmount.add(originalRefundAmountDeposit); oad.setOriginDepositAmount(originalDepositRefundAmount);
oad.setDepositAmount(refundAmountDeposit); oad.setDepositAmount(depositRefundAmount);
refundAmount = refundAmount.add(refundAmountDeposit); originalRefundAmount = originalRefundAmount.add(originalDepositRefundAmount);
refundAmount = refundAmount.add(depositRefundAmount);
//退款子流程: 订单基础,退款描述, 款金额 //退款子流程: 订单基础,退款描述, 款金额
refundSubProcess(baseOrder, stringBuilder.toString(), originalRefundAmount, refundAmount, AccountTypeEnum.OUT_ORDER_FUND.getCode(), RefundStatusEnum.ALL.getCode(), oad); refundSubProcess(baseOrder, stringBuilder.toString(), originalRefundAmount, refundAmount, AccountTypeEnum.OUT_ORDER_FUND.getCode(), RefundStatusEnum.ALL.getCode(), oad);
......
...@@ -152,7 +152,7 @@ public class OrderCalculateBiz { ...@@ -152,7 +152,7 @@ public class OrderCalculateBiz {
violateDesc += StrUtil.format("(封顶{}元)", orderItem.getUnitPrice().multiply(new BigDecimal((residueDays + "")))); violateDesc += StrUtil.format("(封顶{}元)", orderItem.getUnitPrice().multiply(new BigDecimal((residueDays + ""))));
} }
inProgressVO.setViolateAmount(orderItem.getUnitPrice().multiply(new BigDecimal((residueDays + "")))); inProgressVO.setViolateAmount(orderItem.getUnitPrice().multiply(new BigDecimal((residueDays + ""))));
inProgressVO.setViolateDesc(violateDesc); inProgressVO.setViolateDesc(" 提前还车违约金:"+ violateDesc);
OrderAccountDeduction violateDeduction = orderAccountBiz.initDeduction(inProgressVO.getViolateAmount(), violateDesc, DeductionTypeEnum.VIOLATE_ADVANCE, OrderAccountDeduction.ORIGIN_DEPOSIT); OrderAccountDeduction violateDeduction = orderAccountBiz.initDeduction(inProgressVO.getViolateAmount(), violateDesc, DeductionTypeEnum.VIOLATE_ADVANCE, OrderAccountDeduction.ORIGIN_DEPOSIT);
oad.getDeductions().add(violateDeduction); oad.getDeductions().add(violateDeduction);
}else if(residueDays < 0 && !isCancel){ }else if(residueDays < 0 && !isCancel){
...@@ -168,7 +168,7 @@ public class OrderCalculateBiz { ...@@ -168,7 +168,7 @@ public class OrderCalculateBiz {
// } // }
//超过的天数 * 200% * 单价 //超过的天数 * 200% * 单价
inProgressVO.setViolateAmount(orderItem.getUnitPrice().multiply(new BigDecimal(2+ "")).multiply(new BigDecimal((overDays + "")))); inProgressVO.setViolateAmount(orderItem.getUnitPrice().multiply(new BigDecimal(2+ "")).multiply(new BigDecimal((overDays + ""))));
inProgressVO.setViolateDesc(violateDesc); inProgressVO.setViolateDesc(" 延期还车违约金:"+ violateDesc);
OrderAccountDeduction violateDeduction = orderAccountBiz.initDeduction(inProgressVO.getViolateAmount(), violateDesc, DeductionTypeEnum.VIOLATE_DELAY, OrderAccountDeduction.ORIGIN_DEPOSIT); OrderAccountDeduction violateDeduction = orderAccountBiz.initDeduction(inProgressVO.getViolateAmount(), violateDesc, DeductionTypeEnum.VIOLATE_DELAY, OrderAccountDeduction.ORIGIN_DEPOSIT);
oad.getDeductions().add(violateDeduction); oad.getDeductions().add(violateDeduction);
} }
......
...@@ -149,7 +149,7 @@ public class OrderCancelBiz { ...@@ -149,7 +149,7 @@ public class OrderCancelBiz {
//原退还押金 //原退还押金
Integer freeDays = (null == orderItem.getCutNum())?0 :orderItem.getCutNum(); Integer freeDays = (null == orderItem.getCutNum())?0 :orderItem.getCutNum();
BigDecimal freeDayAmount = BigDecimal.ZERO; // BigDecimal freeDayAmount = BigDecimal.ZERO;
//如果超过出发时间,不能取消订单 //如果超过出发时间,不能取消订单
...@@ -202,17 +202,17 @@ public class OrderCancelBiz { ...@@ -202,17 +202,17 @@ public class OrderCancelBiz {
orvd.handelCostDetailExtend(csv); orvd.handelCostDetailExtend(csv);
orderRentVehicleBiz.updateSelectiveByIdRe(orvd); orderRentVehicleBiz.updateSelectiveByIdRe(orvd);
}else { }else {
//没到出车时间 // //没到出车时间
//判断是否使用免费天数,并且进行扣款 // //判断是否使用免费天数,并且进行扣款
if(freeDays > 0) { // if(freeDays > 0) {
freeDayAmount = orderItem.getUnitPrice().multiply(new BigDecimal(orvd.getFreeDays()+ "")); // freeDayAmount = orderItem.getUnitPrice().multiply(new BigDecimal(orvd.getFreeDays()+ ""));
} // }
//违约金封顶 租车身份价 * 2天 //违约金封顶 租车身份价 * 2天
BigDecimal topAmount = orderItem.getUnitPrice().multiply(new BigDecimal(2+ "")); BigDecimal topAmount = orderItem.getUnitPrice().multiply(new BigDecimal(2+ ""));
//退款流程 //退款流程
orderAccountBiz.rentRefundProcessCancel(baseOrder, orderItem.getRealAmount(), timeLag, APP_ORDER+ "_"+ RENT_REFUND, orvd.getDeposit(), freeDayAmount, oad, topAmount); orderAccountBiz.rentRefundProcessCancel(baseOrder, BigDecimal.ZERO, timeLag, APP_ORDER+ "_"+ RENT_REFUND, orvd.getDeposit(), orderItem.getBuyAmount(), oad, topAmount);
//设置订单数据 //设置订单数据
//baseOrder.setDamagesAmount(csv.getDamagesAmount()); //baseOrder.setDamagesAmount(csv.getDamagesAmount());
...@@ -267,8 +267,8 @@ public class OrderCancelBiz { ...@@ -267,8 +267,8 @@ public class OrderCancelBiz {
setOrderId(baseOrder.getId()); setOrderId(baseOrder.getId());
}}); }});
BigDecimal adultItemAmount = (null == adultItem)? BigDecimal.ZERO: adultItem.getRealAmount(); BigDecimal adultItemAmount = (null == adultItem)? BigDecimal.ZERO: adultItem.getBuyAmount();
BigDecimal childItemAmount = (null == childItem)? BigDecimal.ZERO: childItem.getRealAmount(); BigDecimal childItemAmount = (null == childItem)? BigDecimal.ZERO: childItem.getBuyAmount();
//判断是省内还是省外 //判断是省内还是省外
String key = TOUR_IN_REFUND; String key = TOUR_IN_REFUND;
......
...@@ -20,6 +20,7 @@ import com.xxfc.platform.order.contant.enumerate.OrderTypeEnum; ...@@ -20,6 +20,7 @@ import com.xxfc.platform.order.contant.enumerate.OrderTypeEnum;
import com.xxfc.platform.order.entity.OrderItem; import com.xxfc.platform.order.entity.OrderItem;
import com.xxfc.platform.order.entity.OrderRefund; import com.xxfc.platform.order.entity.OrderRefund;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail; import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
import com.xxfc.platform.order.pojo.calculate.InProgressVO; import com.xxfc.platform.order.pojo.calculate.InProgressVO;
import com.xxfc.platform.order.pojo.order.OrderPageVO; import com.xxfc.platform.order.pojo.order.OrderPageVO;
import com.xxfc.platform.universal.constant.DictionaryKey; import com.xxfc.platform.universal.constant.DictionaryKey;
...@@ -76,7 +77,8 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe ...@@ -76,7 +77,8 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe
OrderTypeEnum orderTypeEnum = OrderTypeEnum.get(orderPageVO.getType()); OrderTypeEnum orderTypeEnum = OrderTypeEnum.get(orderPageVO.getType());
BigDecimal orderRefundAmount = BigDecimal.ZERO; BigDecimal totalRefundAmount = BigDecimal.ZERO;
BigDecimal totalDeductAmount = BigDecimal.ZERO;
StringBuilder refundDescBuilder = new StringBuilder(""); StringBuilder refundDescBuilder = new StringBuilder("");
String refundDesc = ""; String refundDesc = "";
InProgressVO inProgressVO = new InProgressVO(); InProgressVO inProgressVO = new InProgressVO();
...@@ -85,36 +87,36 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe ...@@ -85,36 +87,36 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe
case RENT_VEHICLE: case RENT_VEHICLE:
DateTime nowTime = DateTime.parse(DateTime.now().toString(CommonConstants.YMR_SLASH_FORMATTER_JODA), CommonConstants.YMR_SLASH_FORMATTER_JODA); DateTime nowTime = DateTime.parse(DateTime.now().toString(CommonConstants.YMR_SLASH_FORMATTER_JODA), CommonConstants.YMR_SLASH_FORMATTER_JODA);
DateTime startTime = DateTime.parse(new DateTime(orderPageVO.getOrderRentVehicleDetail().getStartTime()).toString(CommonConstants.YMR_SLASH_FORMATTER_JODA), CommonConstants.YMR_SLASH_FORMATTER_JODA); DateTime startTime = DateTime.parse(new DateTime(orderPageVO.getOrderRentVehicleDetail().getStartTime()).toString(CommonConstants.YMR_SLASH_FORMATTER_JODA), CommonConstants.YMR_SLASH_FORMATTER_JODA);
DateTime endTime = DateTime.parse(new DateTime(orderPageVO.getOrderRentVehicleDetail().getEndTime()).toString(CommonConstants.YMR_SLASH_FORMATTER_JODA), CommonConstants.YMR_SLASH_FORMATTER_JODA);
inProgressVO = orderCalculateBiz.inProgressCalculate(orderPageVO, baseOrderBiz.getDaysBetweenDateTime(startTime, nowTime)); Long timeLag = orderPageVO.getOrderRentVehicleDetail().getStartTime() - System.currentTimeMillis();
refundDesc = inProgressVO.getViolateDesc();
// orderRefundAmount = orderAccountBiz.calculateDeduction(orderPageVO.getGoodsAmount().subtract(orderPageVO.getCouponAmount()) OrderItem vehicleItem = orderItemBiz.selectOne(new OrderItem(){{
// , orderPageVO.getOrderRentVehicleDetail().getStartTime() - System.currentTimeMillis() setType(ItemTypeEnum.VEHICLE_MODEL.getCode());
// , DictionaryKey.APP_ORDER+ "_"+ RENT_REFUND setOrderId(orderPageVO.getId());
// , refundDescBuilder); }});
// OrderRentVehicleDetail orvd = orderPageVO.getOrderRentVehicleDetail();
// Long timeLag = orvd.getStartTime() - System.currentTimeMillis(); if(timeLag < 0 ) {
// //原退还押金 OrderAccountDetail oad = new OrderAccountDetail();
// BigDecimal originalDeductAmount = BigDecimal.ZERO; Integer freeDays = (null == vehicleItem.getCutNum())?0 :vehicleItem.getCutNum();
// BigDecimal originalRefundAmount = BigDecimal.ZERO.add(orvd.getDeposit()); inProgressVO = orderCalculateBiz.inProgressCalculate(orderPageVO, vehicleItem, freeDays, baseOrderBiz.getDaysBetweenDateTime(startTime, nowTime), new OrderAccountDetail(), Boolean.FALSE);
// //判断是否使用免费天数,并且进行扣款 //.inProgressCalculate(orderPageVO, baseOrderBiz.getDaysBetweenDateTime(startTime, nowTime));
// if(null != orvd.getFreeDays() && orvd.getFreeDays() > 0) { totalDeductAmount = oad.realTotalDeduct();
// refundDescBuilder = new StringBuilder(""); totalRefundAmount = oad.getOrderAmount().add(oad.getDepositAmount());
// OrderItem orderItem = orderItemBiz.selectOne(new OrderItem(){{ refundDesc = inProgressVO.getViolateDesc();
// setType(ItemTypeEnum.VEHICLE_MODEL.getCode()); }else {
// setOrderId(orderPageVO.getId());
// }}); String key = RENT_REFUND;
// originalDeductAmount = orderItem.getUnitPrice().multiply(new BigDecimal(orvd.getFreeDays()+ ""));
// } BigDecimal deductionAmount = orderAccountBiz.calculateDeduction(vehicleItem.getBuyAmount()
// BigDecimal residueAmount = orderRefundBiz.calculateDeduction(originalDeductAmount, timeLag, APP_ORDER+ "_"+ RENT_REFUND, refundDescBuilder); , orderPageVO.getOrderTourDetail().getStartTime() - System.currentTimeMillis()
//扣款 = 违约金 + 消费金额 , DictionaryKey.APP_ORDER+ "_"+ key
// BigDecimal residueAmount = BigDecimal.ZERO; , refundDescBuilder);
// //inProgressVO.get
// residueAmount = residueAmount.setScale(2, RoundingMode.HALF_UP); totalDeductAmount = deductionAmount;
totalRefundAmount = orderPageVO.getRealAmount().subtract(deductionAmount);
//押金剩余款 :押金 - (原扣除款 - 剩余款) refundDesc = refundDescBuilder.toString();
//退款金额 :订单剩余款 + 押金剩余款 }
//orderRefundAmount = orderRefundAmount.add(originalRefundAmount.subtract(originalDeductAmount.subtract(residueAmount)));
break; break;
case TOUR: case TOUR:
...@@ -141,7 +143,7 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe ...@@ -141,7 +143,7 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe
, orderPageVO.getOrderTourDetail().getStartTime() - System.currentTimeMillis() , orderPageVO.getOrderTourDetail().getStartTime() - System.currentTimeMillis()
, DictionaryKey.APP_ORDER+ "_"+ key , DictionaryKey.APP_ORDER+ "_"+ key
, refundDescBuilder); , refundDescBuilder);
orderRefundAmount = orderPageVO.getRealAmount().subtract(deductionAmount); totalRefundAmount = orderPageVO.getRealAmount().subtract(deductionAmount);
refundDesc = refundDescBuilder.toString(); refundDesc = refundDescBuilder.toString();
break; break;
default: default:
...@@ -150,8 +152,12 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe ...@@ -150,8 +152,12 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe
OrderRefundPriceVO orpv = new OrderRefundPriceVO(); OrderRefundPriceVO orpv = new OrderRefundPriceVO();
orpv.setRealAmount(orderPageVO.getRealAmount()); orpv.setRealAmount(orderPageVO.getRealAmount());
orpv.setRefundAmount(orderRefundAmount); orpv.setRefundAmount(totalRefundAmount);
orpv.setRefundDesc(StrUtil.format("取消操作可能会产生额外费用{},是否确定取消订单", refundDesc)); if(totalDeductAmount.compareTo(BigDecimal.ZERO) > 0) {
orpv.setRefundDesc("取消操作可能会产生额外费用,是否确定取消订单");
}else {
orpv.setRefundDesc(StrUtil.format("本次取消操作需要扣除{}元违约金,实际退款金额为{}元,您确定要取消订单吗?", totalDeductAmount, totalRefundAmount));
}
return ObjectRestResponse.succ(orpv); return ObjectRestResponse.succ(orpv);
} }
......
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