|
|
@@ -546,7 +546,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
OrderDon orderDon = orderDonMapper.selectById(wxOrderRefundReq.getOrderId());
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- if (orderDon.getType() != OrderDon.Type.WeChat) {
|
|
|
+ if (OrderDon.Type.EX_CODE == orderDon.getType()) {
|
|
|
+ wxOrderRefundReq.setRefundMoney(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ if (OrderDon.Type.EX_CODE != orderDon.getType() && orderDon.getType() != OrderDon.Type.WeChat) {
|
|
|
throw BusinessRuntimeException.getInstance("该订单不是微信支付的订单");
|
|
|
}
|
|
|
//校验订单是否符合退款
|
|
|
@@ -557,26 +560,29 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (!redisService.setNx(String.format("%s", wxOrderRefundReq.getOrderId()), wxOrderRefundReq.getOrderId(), 10l)) {
|
|
|
throw BusinessRuntimeException.getInstance("请勿重复点击,正在退款中..");
|
|
|
}
|
|
|
-
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- //退款订单号
|
|
|
- String outRefundNo = Codec.DoDigest.custom()
|
|
|
- .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
- .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
- .toHexString();
|
|
|
- weChatService.refundWxOrder(weChatConfig.getAppid(),
|
|
|
- orderDon.getTransactionId(),
|
|
|
- outRefundNo,
|
|
|
- orderDon.getMoney(),
|
|
|
- wxOrderRefundReq.getRefundMoney(),
|
|
|
- weChatConfig.getDomain() + "wx/refund/notify");
|
|
|
+ String outRefundNo = "";
|
|
|
+ if (orderDon.getType() != OrderDon.Type.EX_CODE) {
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ //退款订单号
|
|
|
+ outRefundNo = Codec.DoDigest.custom()
|
|
|
+ .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
+ .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
+ .toHexString();
|
|
|
+ weChatService.refundWxOrder(weChatConfig.getAppid(),
|
|
|
+ orderDon.getTransactionId(),
|
|
|
+ outRefundNo,
|
|
|
+ orderDon.getMoney(),
|
|
|
+ wxOrderRefundReq.getRefundMoney(),
|
|
|
+ weChatConfig.getDomain() + "wx/refund/notify");
|
|
|
+ }
|
|
|
//修改订单状态
|
|
|
orderDon.setStatus(OrderDon.Status.refund);
|
|
|
orderDon.setRefundMoney(wxOrderRefundReq.getRefundMoney());
|
|
|
orderDonMapper.updateById(orderDon);
|
|
|
//记录退款信息
|
|
|
+ final String outNo = outRefundNo;
|
|
|
THREAD_POOL_TASK_EXECUTOR.execute(()->{
|
|
|
- refundRecord(orderDon, goodsDon, sku, outRefundNo);
|
|
|
+ refundRecord(orderDon, goodsDon, sku, outNo);
|
|
|
});
|
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
|
clearUnrealGoodsDetail(orderDon, goodsDon);
|
|
|
@@ -589,7 +595,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
OrderDon orderDon = orderDonMapper.selectById(zfbOrderRefundReq.getOrderId());
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(orderDon.getSkuId());
|
|
|
GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
|
|
|
- if (orderDon.getType() != OrderDon.Type.ALI_PAY) {
|
|
|
+ if (OrderDon.Type.EX_CODE == orderDon.getType()) {
|
|
|
+ zfbOrderRefundReq.setRefundMoney(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ if (OrderDon.Type.EX_CODE != orderDon.getType() && orderDon.getType() != OrderDon.Type.ALI_PAY) {
|
|
|
throw BusinessRuntimeException.getInstance("该订单不是支付宝支付的订单");
|
|
|
}
|
|
|
//校验订单是否符合退款
|
|
|
@@ -600,34 +609,44 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (!redisService.setNx(String.format("%s", zfbOrderRefundReq.getOrderId()), zfbOrderRefundReq.getOrderId(), 10l)) {
|
|
|
throw BusinessRuntimeException.getInstance("请勿重复点击,正在退款中..");
|
|
|
}
|
|
|
- //支付宝退款
|
|
|
- AlipayClient alipayClient = AliPayCommon.getAlipayClient(ZfbConfig.YHLX_ZfB);
|
|
|
- AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
- AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
- //支付宝交易号
|
|
|
- model.setTradeNo(orderDon.getTransactionId());
|
|
|
- model.setRefundAmount(zfbOrderRefundReq.getRefundMoney().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_EVEN).toString());
|
|
|
- model.setQueryOptions(List.of("gmt_refund_pay"));
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- //退款订单号
|
|
|
- String outRefundNo = Codec.DoDigest.custom()
|
|
|
- .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
- .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
- .toHexString();
|
|
|
- //退款请求号
|
|
|
- model.setOutRequestNo(outRefundNo);
|
|
|
- request.setBizModel(model);
|
|
|
- AlipayTradeRefundResponse response = alipayClient.execute(request);
|
|
|
+ AlipayTradeRefundResponse response = null;
|
|
|
+ if (OrderDon.Type.EX_CODE == orderDon.getType()) {
|
|
|
+ response = new AlipayTradeRefundResponse();
|
|
|
+ }
|
|
|
+ String outRefundNo = "";
|
|
|
+ if (OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
+ //支付宝退款
|
|
|
+ AlipayClient alipayClient = AliPayCommon.getAlipayClient(ZfbConfig.YHLX_ZfB);
|
|
|
+ AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
|
|
+ AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
+ //支付宝交易号
|
|
|
+ model.setTradeNo(orderDon.getTransactionId());
|
|
|
+ model.setRefundAmount(zfbOrderRefundReq.getRefundMoney().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_EVEN).toString());
|
|
|
+ model.setQueryOptions(List.of("gmt_refund_pay"));
|
|
|
+ long time = System.currentTimeMillis();
|
|
|
+ //退款订单号
|
|
|
+ outRefundNo = Codec.DoDigest.custom()
|
|
|
+ .setAlgorithm(Codec.DoDigest.Algorithm.MD5)
|
|
|
+ .setStringData(time + String.valueOf(orderDon.getId()))
|
|
|
+ .toHexString();
|
|
|
+ //退款请求号
|
|
|
+ model.setOutRequestNo(outRefundNo);
|
|
|
+ request.setBizModel(model);
|
|
|
+ response = alipayClient.execute(request);
|
|
|
+ }
|
|
|
+ final String outNo = outRefundNo;
|
|
|
if (response.isSuccess()) {
|
|
|
- AliPayRefundRep aliPayRefundRep = Jsons.parseObject(response.getBody(), AliPayRefundRep.class);
|
|
|
- AliPayRefundRep.AlipayTradeRefundResponse res = aliPayRefundRep.getResponse();
|
|
|
//修改订单状态
|
|
|
orderDon.setStatus(OrderDon.Status.refund);
|
|
|
- orderDon.setRefundMoney(res.getRefundFee().multiply(BigDecimal.valueOf(100)));
|
|
|
+ if (OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
+ AliPayRefundRep aliPayRefundRep = Jsons.parseObject(response.getBody(), AliPayRefundRep.class);
|
|
|
+ AliPayRefundRep.AlipayTradeRefundResponse res = aliPayRefundRep.getResponse();
|
|
|
+ orderDon.setRefundMoney(res.getRefundFee().multiply(BigDecimal.valueOf(100)));
|
|
|
+ } else orderDon.setRefundMoney(BigDecimal.ZERO);
|
|
|
orderDonMapper.updateById(orderDon);
|
|
|
//记录退款信息
|
|
|
THREAD_POOL_TASK_EXECUTOR.execute(()->{
|
|
|
- refundRecord(orderDon, goodsDon, sku, outRefundNo);
|
|
|
+ refundRecord(orderDon, goodsDon, sku, outNo);
|
|
|
});
|
|
|
//虚物订单退款,清出车队,车票变为已过期
|
|
|
clearUnrealGoodsDetail(orderDon, goodsDon);
|
|
|
@@ -663,9 +682,9 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
if (orderDon == null) {
|
|
|
throw BusinessRuntimeException.getInstance("订单不存在");
|
|
|
}
|
|
|
- if (orderDon.getType() == OrderDon.Type.EX_CODE) {
|
|
|
- throw BusinessRuntimeException.getInstance("兑换码订单不支持退款");
|
|
|
- }
|
|
|
+// if (orderDon.getType() == OrderDon.Type.EX_CODE) {
|
|
|
+// throw BusinessRuntimeException.getInstance("兑换码订单不支持退款");
|
|
|
+// }
|
|
|
if (OrderDon.Status.refund == orderDon.getStatus()) {
|
|
|
throw BusinessRuntimeException.getInstance("该订单已退款");
|
|
|
}
|
|
|
@@ -673,10 +692,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
|
|
|
throw BusinessRuntimeException.getInstance("订单{0}状态不支持退款", orderDon.getStatus());
|
|
|
}
|
|
|
//续费订单
|
|
|
- if (orderDon.getOrderType() == 2) {
|
|
|
+ if (orderDon.getOrderType() == 2 && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
throw BusinessRuntimeException.getInstance("续费订单不支持退款");
|
|
|
}
|
|
|
- if (goodsDon != null) {
|
|
|
+ if (goodsDon != null && OrderDon.Type.EX_CODE != orderDon.getType()) {
|
|
|
//虚物订单 7天内可退款
|
|
|
if (goodsDon.getType() == 1 && DateTime.now().isAfter(DateUtil.offsetDay(orderDon.getPayTime(), 7))) {
|
|
|
throw BusinessRuntimeException.getInstance("该虚物订单已过退款时间");
|