diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighOrderController.java b/hai-bweb/src/main/java/com/bweb/controller/HighOrderController.java index 3be23e37..b75965ae 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighOrderController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighOrderController.java @@ -36,10 +36,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @Auther: 袁野 @@ -607,9 +604,14 @@ public class HighOrderController { JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); + if (jsonObject == null) { + log.error("orderToPay error!", "请求超时"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时,请重新点击"); + } + JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); - if (dataObject.getBoolean("success")) { + if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { order.setOrderStatus(4); order.setRefundTime(new Date()); order.setRefundContent(dataObject.getString("orderId")); diff --git a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java index c065c33b..ef63b265 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargeOrderController.java @@ -16,6 +16,7 @@ import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.WxUtils; import com.hai.config.HuiLianTongUnionCardConfig; +import com.hai.config.UnionPayConfig; import com.hai.entity.HighRefundAudit; import com.hai.entity.OutRechargeOrder; import com.hai.model.*; @@ -260,33 +261,8 @@ public class OutRechargeOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); } - if (order.getPayType() == 2) { - JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); - - if (jsonObject == null) { - log.error("orderToPay error!", "请求超时"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时,请重新点击"); - } - - JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); - - if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { - order.setStatus(5); - order.setRefundTime(new Date()); - order.setOutRefundNo("HFR"+new Date().getTime() ); - order.setRefundFee(order.getPayRealPrice()); - order.setRefundId(dataObject.getString("orderId")); - - highRefundAudit.setStatus(1); - highRefundAuditService.updateRefundAudit(highRefundAudit); - outRechargeOrderService.updateOrder(order); - return ResponseMsgUtil.success("退款成功"); - } else { - log.error("orderToPay error!", dataObject.getString("message")); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); - } - - } else { + // 微信退款 + if (order.getPayType() == 1) { Map param = new HashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); @@ -312,13 +288,57 @@ public class OutRechargeOrderController { outRechargeOrderService.updateOrder(order); highRefundAudit.setStatus(1); highRefundAuditService.updateRefundAudit(highRefundAudit); - return ResponseMsgUtil.success("退款成功"); } else { log.error("orderToPay error!", "退款失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); } } + // 工会卡退款 + if (order.getPayType() == 2) { + JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); + + if (jsonObject == null) { + log.error("orderToPay error!", "请求超时"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求超时,请重新点击"); + } + + JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); + + if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { + order.setStatus(5); + order.setRefundTime(new Date()); + order.setOutRefundNo("HFR"+new Date().getTime() ); + order.setRefundFee(order.getPayRealPrice()); + order.setRefundId(dataObject.getString("orderId")); + + highRefundAudit.setStatus(1); + highRefundAuditService.updateRefundAudit(highRefundAudit); + outRechargeOrderService.updateOrder(order); + + } else { + log.error("orderToPay error!", dataObject.getString("message")); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); + } + } + + // 银联退款 + if (order.getPayType() == 4) { + // 订单退款 + JSONObject refund = UnionPayConfig.zwrefund(order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); + if (!refund.getString("resultcode").equals("W6")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); + } + + order.setStatus(5); + order.setRefundTime(new Date()); + order.setOutRefundNo(refund.getString("oriwtorderid")); + order.setRefundFee(order.getPayRealPrice()); + highRefundAudit.setStatus(1); + highRefundAuditService.updateRefundAudit(highRefundAudit); + outRechargeOrderService.updateOrder(order); + } + return ResponseMsgUtil.success("退款成功"); } catch (Exception e) { log.error("HighOrderController --> getUserOrderList() error!", e); return ResponseMsgUtil.exception(e);