嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-cweb/src/main/java/com/cweb/controller/pay/TuanYouController.java

135 lines
5.8 KiB

package com.cweb.controller.pay;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.CommonSysConst;
import com.hai.config.WxOrderConfig;
import com.hai.dao.HighGasOrderRefundMapper;
import com.hai.entity.HighChildOrder;
import com.hai.entity.HighGasOrderRefund;
import com.hai.entity.HighOrder;
import com.hai.model.OrderRefundModel;
import com.hai.model.ResponseData;
import com.hai.service.HighOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.security.*;
import java.util.*;
@Controller
@RequestMapping(value = "/tuanyou")
@Api(value = "团油回调")
public class TuanYouController {
private static Logger log = LoggerFactory.getLogger(TuanYouController.class);
@Resource
private HighOrderService highOrderService;
@Resource
private HighGasOrderRefundMapper highGasOrderRefundMapper;
@RequestMapping(value = "/orderPaymentNotify", method = RequestMethod.POST)
@ApiOperation(value = "订单支付回调")
public void orderPaymentNotify(HttpServletRequest request, HttpServletResponse response) {
try {
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
@RequestMapping(value = "/orderRefundNotify", method = RequestMethod.POST)
@ApiOperation(value = "订单退款回调")
@ResponseBody
public void orderRefundNotify(@RequestBody String reqBodyStr,HttpServletRequest request, HttpServletResponse response) {
try {
log.info(reqBodyStr);
HighGasOrderRefund highGasOrderRefund = new HighGasOrderRefund();
highGasOrderRefund.setCreateTime(new Date());
highGasOrderRefund.setReturnContent(reqBodyStr);
highGasOrderRefundMapper.insert(highGasOrderRefund);
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);
String dataStr = AESEncodeUtil.aesDecryptByBytes(AESEncodeUtil.base64Decode(dataObject.getString("data")), CommonSysConst.getSysConfig().getTuanYouAppSecret());
JSONObject object = JSONObject.parseObject(dataStr);
// 查询订单
HighOrder order = highOrderService.getOrderByOrderNo(object.getString("thirdOrderNo"));
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
if (order != null && order.getOrderStatus() == 6) {
// 退单结果 true:成功 false:失败
if (object.getBoolean("refundResult") == true && order != null) {
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), order.getPayRealPrice());
if(orderRefundModel.getResult_code().equals("SUCCESS")) {
order.setOrderStatus(4);
order.setRefundTime(new Date());
highOrderService.updateOrderDetail(order);
}
} else if (!object.getBoolean("refundResult") == true && order != null) {
order.setOrderStatus(7);
order.setRefusalRefundContent(object.getString("refundFailReason"));
highOrderService.updateOrderDetail(order);
}
}
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("success");
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
@RequestMapping(value = "/abnormalOrderRefund", method = RequestMethod.POST)
@ApiOperation(value = "异常订单退款")
@ResponseBody
public ResponseData abnormalOrderRefund(@RequestBody JSONObject body) {
try {
if (StringUtils.isNotBlank(body.getString("orderNo"))) {
// 查询订单
HighOrder order = highOrderService.getOrderByOrderNo(body.getString("orderNo"));
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
if (order != null && order.getOrderStatus() == 2) {
OrderRefundModel orderRefundModel = WxOrderConfig.orderToRefund(order.getPaySerialNo(), order.getPayRealPrice(), order.getPayRealPrice());
if(orderRefundModel.getResult_code().equals("SUCCESS")) {
for (HighChildOrder childOrder : order.getHighChildOrderList()) {
childOrder.setChildOrdeStatus(4);
}
order.setOrderStatus(4);
order.setRefundTime(new Date());
order.setRefundPrice(order.getPayRealPrice());
highOrderService.updateOrder(order);
return ResponseMsgUtil.success("退款成功");
}
}
}
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败");
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
}