rk
2026-04-02 d0c2a04e6ec9f07f84aaaa864362358423dda83b
server/services/src/main/java/com/doumee/config/wx/WxMiniUtilService.java
@@ -49,33 +49,34 @@
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public boolean wxRefund(WithdrawalOrders withdrawalOrders,Orders orders) {
        // 发送退款请求
        withdrawalOrders.setCreateTime(new Date());
        withdrawalOrdersMapper.insert(withdrawalOrders);
        CreateRequest request = new CreateRequest();
        request.setOutTradeNo(orders.getOutTradeNo());
        request.setOutRefundNo(withdrawalOrders.getId().toString());
        request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId());
        request.setNotifyUrl(WxMiniConfig.wxProperties.getRefundNotifyUrl());
        AmountReq amountReq = new AmountReq();
        amountReq.setTotal(1L);//withdrawalOrders.getAmount());
        amountReq.setRefund(1L);//withdrawalOrders.getAmount());
        amountReq.setCurrency("CNY");
        request.setAmount(amountReq);
        try {
            log.error("=============="+JSONObject.toJSONString(request));
            com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.refundService.create(request);
            log.error("=============="+JSONObject.toJSONString(response));
            if ("SUCCESS".equals(response.getStatus().name())
                    || "PROCESSING".equals(response.getStatus().name()) ) {
                return  true;
            }else{
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败哦!");
            }
        }catch (Exception e){
            e.printStackTrace();
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败!");
        }
//        // 发送退款请求
//        withdrawalOrders.setCreateTime(new Date());
//        withdrawalOrdersMapper.insert(withdrawalOrders);
//        CreateRequest request = new CreateRequest();
//        request.setOutTradeNo(orders.getOutTradeNo());
//        request.setOutRefundNo(withdrawalOrders.getId().toString());
//        request.setSubMchid(WxMiniConfig.wxProperties.getSubMchId());
//        request.setNotifyUrl(WxMiniConfig.wxProperties.getRefundNotifyUrl());
//        AmountReq amountReq = new AmountReq();
//        amountReq.setTotal(1L);//withdrawalOrders.getAmount());
//        amountReq.setRefund(1L);//withdrawalOrders.getAmount());
//        amountReq.setCurrency("CNY");
//        request.setAmount(amountReq);
//        try {
//            log.error("=============="+JSONObject.toJSONString(request));
//            com.wechat.pay.java.service.refund.model.Refund response = WxMiniConfig.wxPayService.refund(request);
//            log.error("=============="+JSONObject.toJSONString(response));
//            if ("SUCCESS".equals(response.getStatus().name())
//                    || "PROCESSING".equals(response.getStatus().name()) ) {
//                return  true;
//            }else{
//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败哦!");
//            }
//        }catch (Exception e){
//            e.printStackTrace();
//            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,退款申请失败!");
//        }
        return false;
    }