Browse Source

Merge branch 'dev' of yeshijie/wlyy2.0 into dev

叶仕杰 3 years ago
parent
commit
3db7cb9eb5

+ 18 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PayEndpoint.java

@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.exception.BusinessException;
import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService;
import com.yihu.jw.care.service.pay.PayService;
import com.yihu.jw.care.util.WxpayUtil;
import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
@ -22,6 +23,7 @@ import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@ -43,6 +45,8 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    private Logger log = LoggerFactory.getLogger(PatientDoorCoachOrderService.class);
    @Value("${wechat.apiKey}")
    public String apiKey;
    @Autowired
    private PayService payService;
    @Autowired
@ -271,22 +275,31 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            // 支付校验
            String returnCode = params.get("return_code");
            if (!"SUCCESS".equalsIgnoreCase(returnCode)) {
                log.info("【微信支付退款】订单失败");
                log.info("【微信支付退款1】订单失败");
                return XMLUtil.setXML("FAIL", "退款失败");
            }
            String req_info = params.get("req_info");
            //解密
            String desReqInfo = WxpayUtil.getRefundDecrypt(req_info,apiKey);
            Map<String, String> desParams = XMLUtil.doXMLParse(desReqInfo);
            if(!"SUCCESS".equals(desParams.get("refund_status"))){
                log.info("【微信支付退款2】订单失败");
                return XMLUtil.setXML("FAIL", "退款失败");
            }
            // 商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号
            String outTradeNo = params.get("out_trade_no");
            String outTradeNo = desParams.get("out_trade_no");
            String payWaterId = outTradeNo.split("_")[0];
            payService.addHttpLog("2",payWaterId,paramsJson,null);
            payService.addHttpLog("2",payWaterId,desReqInfo,null);
            BusinessOrderRefundDO orderDO = orderRefundDao.selectByOrderNo(payWaterId);
            if (orderDO == null) {
                log.error("退款订单不存在");
                return XMLUtil.setXML("SUCCESS", "OK");
            }
            orderDO.setOutRefundNo(params.get("refund_id"));
            orderDO.setOutRefundNo(desParams.get("refund_id"));
//            orderDO.setResponseParam(paramsJson);
            // 判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额),
            String totalFee = params.get("refund_fee");
            String totalFee = desParams.get("refund_fee");
            BigDecimal payTotalFee = new BigDecimal(totalFee);
            log.info("【微信支付退款】支付金额:{}", payTotalFee);
            if (new BigDecimal(orderDO.getRefundPrice()*100).compareTo(payTotalFee) != 0) {

+ 10 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/pay/PayService.java

@ -403,7 +403,7 @@ public class PayService {
        Map<String,Object> map = businessOrderService.refund(wechatId,orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),orderPrice.toString(),refundPrice1.toString(),orderRefundDO.getRefundDesc());
        log.info("map"+map);
        addHttpLog("1",businessOrderDO.getOrderNo(),null,map.toString());
        if (map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){
        if (!map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){
            //退款申请提交成功
            throw new Exception(map.get("return_msg").toString());
        }
@ -470,13 +470,15 @@ public class PayService {
     */
    @Transactional(rollbackFor = Exception.class)
    public void refundNotify(BusinessOrderRefundDO orderDO) {
        log.error("【支付通知】请求,payWater:{}", orderDO);
        log.error("【退款通知】请求,getOrderNo:{}", orderDO.getOrderNo());
        String type = "";
        //防止重复支付
        if (orderDO.getStatus()!=1) {
            log.error("【退款通知】请求,getStatus:{}", orderDO.getStatus());
            return;
        }
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderDO.getOrderNo());
        type = businessOrderDO.getOrderCategory();
        switch (type){
            case "1":
                //desc = "招生报名";
@ -495,8 +497,12 @@ public class PayService {
            default:
                break;
        }
        orderDO.setStatus(2);
        orderDO.setRefundTime(new Date());
        businessOrderDO.setStatus(4);
        orderRefundDao.save(orderDO);
        businessOrderDao.save(businessOrderDO);
        log.info("【退款通知】成功,type:{}", type);
    }

File diff suppressed because it is too large
+ 102 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/util/WxpayUtil.java