Ejemplo n.º 1
0
  @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, "取消订单");
    }
  }
Ejemplo n.º 2
0
  /**
   * @param orderNo
   * @param orderBean
   */
  private void updateOrderStatus(String orderNo, OrderBean orderBean) {
    if (orderBean == null) {
      log.error("订单不存在,订单orderNo:" + orderNo);
      throw new TradeException(
          new ReturnCode() {
            @Override
            public String getMessage() {
              return QunarErrorCode.ORDER_NOT_FOUND.name();
            }

            @Override
            public int getCode() {
              return QunarErrorCode.ORDER_NOT_FOUND.code();
            }
          });
    }

    OrderStatus orderMainStatus = OrderStatus.getStatus(orderBean.getOrderStatus());
    switch (orderMainStatus) {
      case CANCEL_CLOSE:
      case CANCEL_NOSERVICE:
      case CANCEL_SERVICEED:
      case CANCELING:
      case CANCLE_CLOSE_NOPAY:
      case CANCLE_CLOSE_PAY_SERVICE:
        return;
      default:
        OrderBean record = new OrderBean();
        record.setOrderStatus(OrderStatus.CANCELING.value);
        record.setOrderStatusName(OrderStatus.CANCELING.name);
        record.setOrderNo(orderNo);
        if (updateOrderBeanMapper.updateStatusByPrimaryKey(record) > 0) {
          log.info("取消订单成功:" + JSON.toJSONString(record));
        } else {
          log.error("取消订单失败");
          throw new TradeException(
              new ReturnCode() {
                @Override
                public String getMessage() {
                  return QunarErrorCode.NOT_RESPONSED.name();
                }

                @Override
                public int getCode() {
                  return QunarErrorCode.NOT_RESPONSED.code();
                }
              });
        }
    }
  }