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

修改代码

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