|
@@ -316,23 +316,11 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- OrderDon.Type type = orderDon.getType();
|
|
|
|
|
- String outNo = StrUtil.EMPTY;
|
|
|
|
|
- if (type == OrderDon.Type.WeChat && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
- outNo = wxRefund(refundReq, orderDon);
|
|
|
|
|
- }
|
|
|
|
|
- if (type == OrderDon.Type.ALI_PAY && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
- outNo = zfbRefund(refundReq, orderDon);
|
|
|
|
|
- }
|
|
|
|
|
- if (type == OrderDon.Type.PAYPAL && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
- payPalService.refund(refundReq, orderDon);
|
|
|
|
|
- }
|
|
|
|
|
- if (type == OrderDon.Type.STRIPE && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
- stripeService.refund(refundReq, orderDon);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //调用第三方接口退款
|
|
|
|
|
+ String outNo = centerRefund(refundReq, orderDon);
|
|
|
orderDon.setRefundDesc(refundReq.getRefundDesc());
|
|
orderDon.setRefundDesc(refundReq.getRefundDesc());
|
|
|
//记录退款信息
|
|
//记录退款信息
|
|
|
- commonRefund(orderDon, goodsDon, sku, outNo, refundType);
|
|
|
|
|
|
|
+ commonRefund(orderDon, refundReq.getRefundMoney(), goodsDon, sku, outNo, refundType);
|
|
|
//修改订单状态
|
|
//修改订单状态
|
|
|
orderDon.setStatus(OrderDon.Status.refund);
|
|
orderDon.setStatus(OrderDon.Status.refund);
|
|
|
orderDonMapper.updateById(orderDon);
|
|
orderDonMapper.updateById(orderDon);
|
|
@@ -602,6 +590,8 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
if (orderDon == null) {
|
|
if (orderDon == null) {
|
|
|
throw BusinessRuntimeException.getInstance("订单不存在");
|
|
throw BusinessRuntimeException.getInstance("订单不存在");
|
|
|
}
|
|
}
|
|
|
|
|
+ BigDecimal orderDonRefundMoney = Optional.ofNullable(orderDon.getRefundMoney()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal orderDonRefundBalance = Optional.ofNullable(orderDon.getRefundBalance()).orElse(BigDecimal.ZERO);
|
|
|
String refundType = refundReq.getRefundType();
|
|
String refundType = refundReq.getRefundType();
|
|
|
if (orderDon.getType() == OrderDon.Type.BALANCE && !OrderDon.Type.BALANCE.getType().equals(refundType)) {
|
|
if (orderDon.getType() == OrderDon.Type.BALANCE && !OrderDon.Type.BALANCE.getType().equals(refundType)) {
|
|
|
throw BusinessRuntimeException.getInstance("余额支付的订单不支持金额退款");
|
|
throw BusinessRuntimeException.getInstance("余额支付的订单不支持金额退款");
|
|
@@ -647,6 +637,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
//余额退款
|
|
//余额退款
|
|
|
if (OrderDon.Type.BALANCE.getType().equals(refundType)) {
|
|
if (OrderDon.Type.BALANCE.getType().equals(refundType)) {
|
|
|
BigDecimal balance = orderDon.getBalance();
|
|
BigDecimal balance = orderDon.getBalance();
|
|
|
|
|
+ refundMoney = orderDonRefundBalance.add(refundMoney);
|
|
|
if (OrderDon.Type.BALANCE == orderDon.getType() && refundMoney.compareTo(balance) > 0) {
|
|
if (OrderDon.Type.BALANCE == orderDon.getType() && refundMoney.compareTo(balance) > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("退款余额大于订单支付余额");
|
|
throw BusinessRuntimeException.getInstance("退款余额大于订单支付余额");
|
|
|
}
|
|
}
|
|
@@ -657,6 +648,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
orderDon.setRefundMoney(BigDecimal.ZERO);
|
|
orderDon.setRefundMoney(BigDecimal.ZERO);
|
|
|
} else {
|
|
} else {
|
|
|
//退金额
|
|
//退金额
|
|
|
|
|
+ refundMoney = orderDonRefundMoney.add(refundMoney);
|
|
|
if (refundMoney.compareTo(money) > 0) {
|
|
if (refundMoney.compareTo(money) > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("退款金额大于订单支付金额");
|
|
throw BusinessRuntimeException.getInstance("退款金额大于订单支付金额");
|
|
|
}
|
|
}
|
|
@@ -684,9 +676,9 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
/**
|
|
/**
|
|
|
* 退款后 处理关联
|
|
* 退款后 处理关联
|
|
|
*/
|
|
*/
|
|
|
- public void commonRefund(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku, String outNo, String refundType) {
|
|
|
|
|
|
|
+ public void commonRefund(OrderDon orderDon, BigDecimal refundMoney, GoodsDon goodsDon, GoodsDonSku sku, String outNo, String refundType) {
|
|
|
TASK_POOL.execute(() -> {
|
|
TASK_POOL.execute(() -> {
|
|
|
- refundRecord(orderDon, goodsDon, sku, outNo, refundType);
|
|
|
|
|
|
|
+ refundRecord(orderDon, refundMoney, goodsDon, sku, outNo, refundType);
|
|
|
//退款一次
|
|
//退款一次
|
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(), "refund");
|
|
goodsDonStockService.upStockRelate(null, orderDon.getId(), "refund");
|
|
|
try {
|
|
try {
|
|
@@ -893,14 +885,14 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
* 记录退款信息
|
|
* 记录退款信息
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public void refundRecord(OrderDon orderDon, GoodsDon goodsDon, GoodsDonSku sku, String outRefundNo, String refundType) {
|
|
|
|
|
|
|
+ public void refundRecord(OrderDon orderDon, BigDecimal refundMoney, GoodsDon goodsDon, GoodsDonSku sku, String outRefundNo, String refundType) {
|
|
|
RefundOrderDon refund = new RefundOrderDon();
|
|
RefundOrderDon refund = new RefundOrderDon();
|
|
|
refund.setOrderId(orderDon.getId());
|
|
refund.setOrderId(orderDon.getId());
|
|
|
refund.setOutRefundNo(outRefundNo);
|
|
refund.setOutRefundNo(outRefundNo);
|
|
|
refund.setTotalFee(orderDon.getMoney());
|
|
refund.setTotalFee(orderDon.getMoney());
|
|
|
refund.setRefundDesc(orderDon.getRefundDesc());
|
|
refund.setRefundDesc(orderDon.getRefundDesc());
|
|
|
//退款金额
|
|
//退款金额
|
|
|
- refund.setRefundFee(orderDon.getRefundMoney());
|
|
|
|
|
|
|
+ refund.setRefundFee(refundMoney);
|
|
|
refund.setUserId(orderDon.getUserId());
|
|
refund.setUserId(orderDon.getUserId());
|
|
|
refund.setGoodsId(orderDon.getGoodsId());
|
|
refund.setGoodsId(orderDon.getGoodsId());
|
|
|
refund.setGoodsTitle(goodsDon == null ? null : goodsDon.getTitle());
|
|
refund.setGoodsTitle(goodsDon == null ? null : goodsDon.getTitle());
|
|
@@ -917,7 +909,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void refundPriceDiffer(OrderRefundReq orderRefundReq) {
|
|
|
|
|
|
|
+ public void refundPriceDiffer(OrderRefundReq orderRefundReq) throws Exception {
|
|
|
Long orderId = orderRefundReq.getOrderId();
|
|
Long orderId = orderRefundReq.getOrderId();
|
|
|
OrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
OrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
if (orderDon == null) {
|
|
if (orderDon == null) {
|
|
@@ -929,11 +921,42 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
if (Constant.noOrderAllStatus.contains(orderDon.getStatus().name())) {
|
|
if (Constant.noOrderAllStatus.contains(orderDon.getStatus().name())) {
|
|
|
throw BusinessRuntimeException.getInstance("订单不是已支付状态");
|
|
throw BusinessRuntimeException.getInstance("订单不是已支付状态");
|
|
|
}
|
|
}
|
|
|
- BigDecimal refundBalance = orderRefundReq.getRefundBalance();
|
|
|
|
|
|
|
+ //默认补差价余额
|
|
|
|
|
+ String refundType = Optional.ofNullable(orderRefundReq.getRefundType()).orElse("balance");
|
|
|
|
|
+ BigDecimal refundMoney = orderRefundReq.getRefundMoney();
|
|
|
|
|
+ BigDecimal orderRefundMoney = Optional.ofNullable(orderDon.getRefundMoney()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ BigDecimal orderDonRefundBalance = Optional.ofNullable(orderDon.getRefundBalance()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ if (refundMoney.add(orderRefundMoney).add(orderDonRefundBalance).compareTo(orderDon.getRealMoney()) >= 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("补差价已达到该订单付款金额");
|
|
|
|
|
+ }
|
|
|
|
|
+ if ("money".equals(refundType)) {
|
|
|
|
|
+ if (refundMoney == null || refundMoney.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("请输入正确的差价金额");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (refundMoney.compareTo(orderDon.getMoney()) >= 0) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("补差价金额应不大于订单金额");
|
|
|
|
|
+ }
|
|
|
|
|
+ //退款
|
|
|
|
|
+ String outNo = centerRefund(orderRefundReq, orderDon);
|
|
|
|
|
+ orderDon.setRefundMoney(orderRefundMoney.add(refundMoney));
|
|
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
|
|
+
|
|
|
|
|
+ GoodsDon goodsDon = goodsDonMapper.selectById(orderDon.getGoodsId());
|
|
|
|
|
+ GoodsDonSku sku = null;
|
|
|
|
|
+ if (orderDon.getSkuId() != null) {
|
|
|
|
|
+ sku = skuMapper.selectById(orderDon.getSkuId());
|
|
|
|
|
+ }
|
|
|
|
|
+ orderDon.setRefundDesc("补差价");
|
|
|
|
|
+ refundRecord(orderDon, refundMoney, goodsDon, sku, outNo, refundType);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal refundBalance = refundMoney;
|
|
|
if (refundBalance == null || refundBalance.compareTo(BigDecimal.ZERO) <= 0 || refundBalance.compareTo(orderDon.getMoney()) > 0) {
|
|
if (refundBalance == null || refundBalance.compareTo(BigDecimal.ZERO) <= 0 || refundBalance.compareTo(orderDon.getMoney()) > 0) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的差价金额");
|
|
throw BusinessRuntimeException.getInstance("请输入正确的差价金额");
|
|
|
}
|
|
}
|
|
|
userBenefitsService.addUserBalance(orderDon.getUserId(), refundBalance, UserBalanceSourceRecord.Source.price_differ, orderDon.getYhsId());
|
|
userBenefitsService.addUserBalance(orderDon.getUserId(), refundBalance, UserBalanceSourceRecord.Source.price_differ, orderDon.getYhsId());
|
|
|
|
|
+ orderDon.setRefundBalance(orderDonRefundBalance.add(refundBalance));
|
|
|
|
|
+ orderDonMapper.updateById(orderDon);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -981,4 +1004,22 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
|
|
|
}
|
|
}
|
|
|
return relation;
|
|
return relation;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public String centerRefund(OrderRefundReq refundReq, OrderDon orderDon) throws Exception {
|
|
|
|
|
+ OrderDon.Type type = orderDon.getType();
|
|
|
|
|
+ String refundType = refundReq.getRefundType();
|
|
|
|
|
+ if (type == OrderDon.Type.WeChat && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
+ return wxRefund(refundReq, orderDon);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type == OrderDon.Type.ALI_PAY && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
+ return zfbRefund(refundReq, orderDon);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type == OrderDon.Type.PAYPAL && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
+ payPalService.refund(refundReq, orderDon);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (type == OrderDon.Type.STRIPE && !refundType.equals(OrderDon.Type.BALANCE.getType())) {
|
|
|
|
|
+ stripeService.refund(refundReq, orderDon);
|
|
|
|
|
+ }
|
|
|
|
|
+ return StrUtil.EMPTY;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|