Commit 9a7e6f13 authored by 周健威's avatar 周健威

修改退款以及退款计价代码

parent f875ed9a
...@@ -127,28 +127,6 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> { ...@@ -127,28 +127,6 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> {
orderDepositRefundRecordBiz.completeRecordStatus(crosstown.getId(), depositRefundRecordStatus); orderDepositRefundRecordBiz.completeRecordStatus(crosstown.getId(), depositRefundRecordStatus);
orderMsgBiz.handelMsgDeposit(orderMQDTO.getOrderRentVehicleDetail(), orderMQDTO, userFeign.userDetailById(orderMQDTO.getUserId()).getData()); orderMsgBiz.handelMsgDeposit(orderMQDTO.getOrderRentVehicleDetail(), orderMQDTO, userFeign.userDetailById(orderMQDTO.getUserId()).getData());
} }
// else {
// //还车扣除款 剩余的 钱,再减去违章预备金
// BigDecimal originalRefundAmount = orderMQDTO.getOrderRentVehicleDetail().getReturnPayResidue();
// BigDecimal refundAmont = originalRefundAmount;
// String refundDesc = "退还剩余违章保证金:"+ refundAmont.toString();
//
// //已退还部分, 进行剩余的保留违章预备金 的退还
// //获取违章记录
// List<OrderViolation> orderViolations = orderViolationBiz.selectList(new OrderViolation(){{
// setDetailId(orderMQDTO.getOrderRentVehicleDetail().getId());
// }});
//
// if(orderViolations.size() > 0) {
// refundDesc += "(已扣除 违章金额:"+ illegalReserve.toString();
// for(OrderViolation ov : orderViolations) {
// refundDesc += ", "+ ov.getPrice();
// refundAmont = refundAmont.subtract(ov.getPrice());
// }
// refundDesc += ")";
// refundTrigger(orderMQDTO, orderMQDTO.getOrderRentVehicleDetail(), illegalReserve, originalRefundAmount, refundAmont, refundDesc, RefundStatusEnum.REFUND_DEPOSIT.getCode(), RefundTypeEnum.RESIDUE_DEPOSIT);
// }
// }
} }
public void refundTrigger(BaseOrder baseOrder, OrderRentVehicleDetail orvd, BigDecimal residueAmount, BigDecimal originalRefundAmount, BigDecimal refundAmont, String refundDesc, Integer refundStatus, RefundTypeEnum refundTypeEnum) { public void refundTrigger(BaseOrder baseOrder, OrderRentVehicleDetail orvd, BigDecimal residueAmount, BigDecimal originalRefundAmount, BigDecimal refundAmont, String refundDesc, Integer refundStatus, RefundTypeEnum refundTypeEnum) {
...@@ -162,46 +140,52 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> { ...@@ -162,46 +140,52 @@ public class OrderRefundBiz extends BaseBiz<OrderRefundMapper,OrderRefund> {
} }
/** /**
* 租车退款流程(不含押金的通用方法) * 租车(包括旅游)退款流程
* @param baseOrder * @param baseOrder
* @param startTime
* @param dicParentKey
*/
public void rentRefundProcess(BaseOrder baseOrder, Long startTime, String dicParentKey){
rentRefundProcess(baseOrder, BigDecimal.ZERO, startTime, dicParentKey);
}
/**
* 租车(包括旅游)退款流程(含押金)
* @param baseOrder
* @param depositAmount
* @param timeLag 与开始时间的时间差 * @param timeLag 与开始时间的时间差
* @param dicParentKey * @param dicParentKey
*/ */
public void rentRefundProcess(BaseOrder baseOrder, BigDecimal depositAmount, Long timeLag, String dicParentKey) { public void rentRefundProcess(BaseOrder baseOrder, Long timeLag, String dicParentKey) {
//计算退款金额 //计算退款金额
// 1、押金 + 租金(规则扣除) //商品价格 - 优惠券减免的价格
BigDecimal originalRefundAmount = BigDecimal.ZERO.add(baseOrder.getGoodsAmount().subtract(baseOrder.getCouponAmount())); BigDecimal originalRefundAmount = BigDecimal.ZERO.add(baseOrder.getGoodsAmount().subtract(baseOrder.getCouponAmount()));
StringBuilder refundDescBuilder = new StringBuilder("取消订单退款:"); StringBuilder refundDescBuilder = new StringBuilder("取消订单退款:");
if(null == depositAmount) {
depositAmount = BigDecimal.ZERO;
}else {
//触发押金退款
refundSubProcess(baseOrder, refundDescBuilder.toString(), depositAmount, depositAmount, RefundTypeEnum.DEPOSIT.getCode(), RefundStatusEnum.ALL.getCode());
}
//商品价格 - 优惠券减免的价格
BigDecimal refundGoodsAmount = calculateRefund(originalRefundAmount, timeLag, dicParentKey, refundDescBuilder); BigDecimal refundGoodsAmount = calculateRefund(originalRefundAmount, timeLag, dicParentKey, refundDescBuilder);
refundGoodsAmount = refundGoodsAmount.setScale(2, RoundingMode.HALF_UP); refundGoodsAmount = refundGoodsAmount.setScale(2, RoundingMode.HALF_UP);
//退款金额 //退款金额
// BigDecimal refundAmount = depositAmount.add(refundGoodsAmount);
// originalRefundAmount = depositAmount.add(originalRefundAmount);
BigDecimal refundAmount = refundGoodsAmount; BigDecimal refundAmount = refundGoodsAmount;
//退款子流程: 订单基础,退款描述,退款金额 //退款子流程: 订单基础,退款描述,退款金额
refundSubProcess(baseOrder, refundDescBuilder.toString(), originalRefundAmount, refundAmount, RefundTypeEnum.ORDER_FUND.getCode(), RefundStatusEnum.ALL.getCode()); refundSubProcess(baseOrder, refundDescBuilder.toString(), originalRefundAmount, refundAmount, RefundTypeEnum.ORDER_FUND.getCode(), RefundStatusEnum.ALL.getCode());
} }
/**
* 租车押金退款流程
* @param baseOrder
* @param depositAmount
* @param timeLag 与开始时间的时间差
* @param dicParentKey
* @param originalDeductAmount
*/
public void rentRefundDepositProcess(BaseOrder baseOrder, BigDecimal depositAmount, Long timeLag, String dicParentKey, BigDecimal originalDeductAmount) {
// 1、押金 + 租金(规则扣除)
BigDecimal originalRefundAmount = BigDecimal.ZERO.add(depositAmount);
BigDecimal refundAmount = BigDecimal.ZERO.add(depositAmount);
StringBuilder refundDescBuilder = new StringBuilder("取消订单押金退款:");
if(null != originalDeductAmount && BigDecimal.ZERO.compareTo(originalDeductAmount) < 0) {
//通过原扣除款 计算剩余款
BigDecimal residueAmount = calculateRefund(originalDeductAmount, timeLag, dicParentKey, refundDescBuilder);
residueAmount = residueAmount.setScale(2, RoundingMode.HALF_UP);
//退款金额 :押金 - (原扣除款 - 剩余款)
refundAmount = originalRefundAmount.subtract(originalDeductAmount.subtract(residueAmount));
}
//触发押金退款
refundSubProcess(baseOrder, refundDescBuilder.toString(), originalRefundAmount, refundAmount, RefundTypeEnum.DEPOSIT.getCode(), RefundStatusEnum.ALL.getCode());
}
public BigDecimal calculateRefund(BigDecimal goodsAmount, Long timeLag, String dicParentKey, StringBuilder refundDescBuilder) { public BigDecimal calculateRefund(BigDecimal goodsAmount, Long timeLag, String dicParentKey, StringBuilder refundDescBuilder) {
BigDecimal refundGoodsAmount = goodsAmount; BigDecimal refundGoodsAmount = goodsAmount;
......
...@@ -8,10 +8,7 @@ import com.github.wxiaoqi.security.common.exception.BaseException; ...@@ -8,10 +8,7 @@ import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.IntervalUtil; import com.github.wxiaoqi.security.common.util.IntervalUtil;
import com.github.wxiaoqi.security.common.util.process.ResultCode; import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.xxfc.platform.order.biz.*; import com.xxfc.platform.order.biz.*;
import com.xxfc.platform.order.contant.enumerate.OrderStatusEnum; import com.xxfc.platform.order.contant.enumerate.*;
import com.xxfc.platform.order.contant.enumerate.OrderTypeEnum;
import com.xxfc.platform.order.contant.enumerate.RefundStatusEnum;
import com.xxfc.platform.order.contant.enumerate.RefundTypeEnum;
import com.xxfc.platform.order.entity.*; import com.xxfc.platform.order.entity.*;
import com.xxfc.platform.order.pojo.mq.OrderMQDTO; import com.xxfc.platform.order.pojo.mq.OrderMQDTO;
import com.xxfc.platform.tour.feign.TourFeign; import com.xxfc.platform.tour.feign.TourFeign;
...@@ -49,6 +46,9 @@ public class OrderCancelBiz { ...@@ -49,6 +46,9 @@ public class OrderCancelBiz {
@Autowired @Autowired
BaseOrderBiz baseOrderBiz; BaseOrderBiz baseOrderBiz;
@Autowired
OrderItemBiz orderItemBiz;
@Autowired @Autowired
OrderMemberDetailBiz orderMemberDetailBiz; OrderMemberDetailBiz orderMemberDetailBiz;
...@@ -119,18 +119,34 @@ public class OrderCancelBiz { ...@@ -119,18 +119,34 @@ public class OrderCancelBiz {
setOrderId(baseOrder.getId()); setOrderId(baseOrder.getId());
}}); }});
//原退还押金
BigDecimal freeDayAmount = BigDecimal.ZERO;
//判断是否使用免费天数,并且进行扣款
if(null != orvd.getFreeDays() && orvd.getFreeDays() > 0) {
OrderItem orderItem = orderItemBiz.selectOne(new OrderItem(){{
setType(ItemTypeEnum.VEHICLE_MODEL.getCode());
setOrderId(baseOrder.getId());
}});
freeDayAmount = orderItem.getUnitPrice().multiply(new BigDecimal(orvd.getFreeDays()+ ""));
}
//如果超过出发时间,不能取消订单 //如果超过出发时间,不能取消订单
//根据时间处理goodsAmount //根据时间处理goodsAmount
//获取出发时间 到现在 距离时间 //获取出发时间 到现在 距离时间
Long timeLag = orvd.getStartTime() - System.currentTimeMillis(); Long timeLag = orvd.getStartTime() - System.currentTimeMillis();
if(timeLag < 0) { //后面允许开始时间过后可以取消订单
throw new BaseException(ResultCode.FAILED_CODE, new HashSet<String>(){{ // if(timeLag < 0) {
add("已超过出发时间,不能取消订单"); // throw new BaseException(ResultCode.FAILED_CODE, new HashSet<String>(){{
}}); // add("已超过出发时间,不能取消订单");
} // }});
// }
//退款流程 //退款流程
orderRefundBiz.rentRefundProcess(hasUpdateOrder, orvd.getDeposit(), timeLag, APP_ORDER+ "_"+ RENT_REFUND); //退押金
orderRefundBiz.rentRefundDepositProcess(hasUpdateOrder, orvd.getDeposit(), timeLag, APP_ORDER+ "_"+ RENT_REFUND, freeDayAmount);
//退订单款
orderRefundBiz.rentRefundProcess(hasUpdateOrder, timeLag, APP_ORDER+ "_"+ RENT_REFUND);
//已付款的取消订单发送消息 //已付款的取消订单发送消息
try { try {
......
...@@ -71,14 +71,11 @@ public class RentDepositJobHandler extends IJobHandler { ...@@ -71,14 +71,11 @@ public class RentDepositJobHandler extends IJobHandler {
UserFeign userFeign; UserFeign userFeign;
@Override @Override
public ReturnT<String> execute(String idLastNumInterval) throws Exception { public ReturnT<String> execute(String idLastNumInterval) {
Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData(); Map<String, Dictionary> dictionaryMap = thirdFeign.dictionaryGetAll4Map().getData();
Integer rentDepositAutoRefundTime = new Integer(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.RENT_DEPOSIT_AUTO_REFUND_TIME).getDetail()); Integer rentDepositAutoRefundTime = new Integer(dictionaryMap.get(APP_ORDER+ "_"+ DictionaryKey.RENT_DEPOSIT_AUTO_REFUND_TIME).getDetail());
try { try {
// for(int i = 0; i < 10; i++) {
// if(IntervalUtil.staticIsInTheInterval(String.valueOf(i), idLastNumInterval)) {
//三十天
List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class) List<BaseOrder> lists = baseOrderBiz.selectByExample(new Example.Builder(BaseOrder.class)
//订单已完成的租车订单 //订单已完成的租车订单
.where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE.getCode()) .where(WeekendSqls.<BaseOrder>custom().andEqualTo(BaseOrder::getType, OrderTypeEnum.RENT_VEHICLE.getCode())
...@@ -128,17 +125,7 @@ public class RentDepositJobHandler extends IJobHandler { ...@@ -128,17 +125,7 @@ public class RentDepositJobHandler extends IJobHandler {
orderMsgBiz.handelMsgDeposit(orvd, baseOrder, userFeign.userDetailById(baseOrder.getUserId()).getData()); orderMsgBiz.handelMsgDeposit(orvd, baseOrder, userFeign.userDetailById(baseOrder.getUserId()).getData());
} }
//获取交车时间
// List<OrderVehicleCrosstown> crosstowns = crosstownBiz.selectByExample(
// new Example.Builder(BaseOrder.class)
// .where(WeekendSqls.<OrderVehicleCrosstown>custom()
// .andIn(OrderVehicleCrosstown::getType, Lists.newArrayList(CrosstownTypeEnum.ARRIVE.getCode(), CrosstownTypeEnum.FIXED_LOSS.getCode()))
// .andEqualTo(OrderVehicleCrosstown::getOrderId, baseOrder.getId())).build());
} }
// }
// }
ReturnT returnT = new ReturnT(); ReturnT returnT = new ReturnT();
returnT.setCode(100); returnT.setCode(100);
returnT.setMsg("成功"); returnT.setMsg("成功");
......
...@@ -8,10 +8,14 @@ import com.github.wxiaoqi.security.common.rest.BaseController; ...@@ -8,10 +8,14 @@ import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.Query; import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageParam; import com.github.wxiaoqi.security.common.vo.PageParam;
import com.xxfc.platform.order.biz.BaseOrderBiz; import com.xxfc.platform.order.biz.BaseOrderBiz;
import com.xxfc.platform.order.biz.OrderItemBiz;
import com.xxfc.platform.order.biz.OrderRefundBiz; import com.xxfc.platform.order.biz.OrderRefundBiz;
import com.xxfc.platform.order.biz.inner.OrderCancelBiz; import com.xxfc.platform.order.biz.inner.OrderCancelBiz;
import com.xxfc.platform.order.contant.enumerate.ItemTypeEnum;
import com.xxfc.platform.order.contant.enumerate.OrderTypeEnum; 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.OrderRefund;
import com.xxfc.platform.order.entity.OrderRentVehicleDetail;
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;
import lombok.Data; import lombok.Data;
...@@ -23,11 +27,11 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -23,11 +27,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE; import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE; import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
import static com.xxfc.platform.universal.constant.DictionaryKey.TOUR_IN_REFUND; import static com.xxfc.platform.universal.constant.DictionaryKey.*;
import static com.xxfc.platform.universal.constant.DictionaryKey.TOUR_REFUND;
@Controller @Controller
@RequestMapping("orderRefund") @RequestMapping("orderRefund")
...@@ -39,6 +43,9 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe ...@@ -39,6 +43,9 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe
@Autowired @Autowired
OrderRefundBiz orderRefundBiz; OrderRefundBiz orderRefundBiz;
@Autowired
OrderItemBiz orderItemBiz;
@Autowired @Autowired
UserFeign userFeign; UserFeign userFeign;
...@@ -67,8 +74,29 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe ...@@ -67,8 +74,29 @@ public class OrderRefundController extends BaseController<OrderRefundBiz,OrderRe
case RENT_VEHICLE: case RENT_VEHICLE:
orderRefundAmount = orderRefundBiz.calculateRefund(orderPageVO.getGoodsAmount().subtract(orderPageVO.getCouponAmount()) orderRefundAmount = orderRefundBiz.calculateRefund(orderPageVO.getGoodsAmount().subtract(orderPageVO.getCouponAmount())
, orderPageVO.getOrderRentVehicleDetail().getStartTime() - System.currentTimeMillis() , orderPageVO.getOrderRentVehicleDetail().getStartTime() - System.currentTimeMillis()
, DictionaryKey.APP_ORDER+ "_"+ DictionaryKey.RENT_REFUND , DictionaryKey.APP_ORDER+ "_"+ RENT_REFUND
, refundDescBuilder); , 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.calculateRefund(originalDeductAmount, timeLag, APP_ORDER+ "_"+ RENT_REFUND, refundDescBuilder);
residueAmount = residueAmount.setScale(2, RoundingMode.HALF_UP);
//押金剩余款 :押金 - (原扣除款 - 剩余款)
//退款金额 :订单剩余款 + 押金剩余款
orderRefundAmount = orderRefundAmount.add(originalRefundAmount.subtract(originalDeductAmount.subtract(residueAmount)));
break; break;
case TOUR: case TOUR:
//判断是省内还是省外 //判断是省内还是省外
......
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