@Transactional public OrderCancelResult cancelThirdOrder(OrderCancelParam param) { TradeThirdOrder tradeThirdOrder = getThirdOrderBythirdTradeNo(param.getServicePartner(), param.getThirdTradeNo()); if (tradeThirdOrder == null) { log.info("没下单成功的,无取消操作。"); throw new TradeException( new ReturnCode() { @Override public String getMessage() { return QunarErrorCode.SUCCESS.name(); } @Override public int getCode() { return QunarErrorCode.SUCCESS.code(); } }); } String orderNo = tradeThirdOrder.getOrderNo(); OrderBean orderBean = updateOrderBeanMapper.forupdateByOrderNo(orderNo); try { updateOrderStatus(orderNo, orderBean); } catch (Exception e) { log.error("", e); } try { updateThirdOrderStatus(orderNo, ThirdOrderStatus.ORDER_CANCEL); TradePayment tradePayment = paymentService.querySuccessTradePaymentByOrderNo(orderNo); Double ruserPrice = refundService.getRefundAmount(orderNo); Double cancelFee = refundService.getCancelFee(orderNo); otaRefundService.refundToUserAccount( orderBean, tradePayment, ruserPrice, param.getReason(), AgentChannelEnum.getType(orderBean.getOrderChannel())); OrderCancelResult result = new OrderCancelResult(); result.setOrderNo(orderNo); result.setThirdTradeNo(orderBean.getThirdTradeNo()); result.setRefundable(ruserPrice); result.setCancelFee(cancelFee); try { orderTrackService.cancelled(orderNo); } catch (Exception e) { log.error("记录取消订单DB级日志(订单动态)失败,容错。orderNo=" + orderNo, e); } return result; } catch (Exception e) { log.error( "OTA[" + orderBean.getOrderChannel() + "]取消订单失败,输入:" + JSON.toJSONString(orderBean), e); throw new TradeException(TradeReturnCodeEnum.FAILED_FOR_UPDATE, "取消订单"); } }
private List<TradeRefund> msgHandle(String msg) { AliRefundNotifyParam refundNotifyParam = JSON.parseObject(msg, AliRefundNotifyParam.class); String batchNo = refundNotifyParam.getBatch_no(); String redetail = refundNotifyParam.getResult_details(); int succesNum = Integer.parseInt(refundNotifyParam.getSuccess_num()); String[] reundStrs = redetail.split(";"); List<TradeRefund> refundList = new ArrayList<TradeRefund>(); for (String refundStr : reundStrs) { String[] refundInfos = refundStr.split("\\^"); if (refundInfos.length == 3) { String tradeNo = refundInfos[0]; double refundMoney = Double.parseDouble(refundInfos[1]); String refundResult = refundInfos[2]; TradePayment tradePayment = paymentService.queryByTradeNo(tradeNo); TradeRefund tradeRefund = notifyRefundService.queryRefundByBathNOOrderNo( tradePayment.getPayNo(), tradePayment.getOrderNo()); if ("SUCCESS".equalsIgnoreCase(refundResult)) { if (!tradeRefund.getRefundMoney().equals(refundMoney)) { tradeRefund.setRefundError("退款通知 金额 [" + refundMoney + "] 和 退款金额不等 "); } RefundStatus refundStatus = RefundStatus.getType(tradeRefund.getRefundStatus()); if (refundStatus.equals(RefundStatus.UNKNOWN)) { tradeRefund.setRefundStatus(RefundStatus.SUCCESS.value); } else { log.warn(tradeRefund.getRefundNo() + " 退款状态可能异常" + refundStatus + " "); tradeRefund.setRefundStatus(RefundStatus.SUCCESS.value); } tradeRefund.setRefundResponse(msg); refundList.add(tradeRefund); } else { log.info(tradePayment.getOrderNo() + "支付宝 退款 失败 " + msg); } } else { log.error("支付宝 退款 格式错误 " + msg); } } return refundList; }