无关风月
3 天以前 c19fd2da97b631cc720f039967760da475887554
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/task/TaskUtil.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.WechatConstants;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.vo.UserDto;
import com.ruoyi.order.entity.Order;
import com.ruoyi.order.entity.Withdraw;
@@ -21,10 +22,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
/**
@@ -48,7 +46,7 @@
    @Scheduled(fixedRate = 1000 * 3600)
    public void taskMinute(){
        try {
            List<Withdraw> list1 = withdrawService.list();
            List<Withdraw> list1 = withdrawService.lambdaQuery().eq(Withdraw::getId,"1938794177477832705").list();
            List<WithdrawDetail> list = withdrawDetailService.lambdaQuery()
                    .isNotNull(WithdrawDetail::getOutBatchNo).ne(WithdrawDetail::getStatus, "SUCCESS").list();
@@ -61,7 +59,9 @@
                String s1 = HttpUtil.queryTransBatRequest(WechatConstants.WE_CHAT_PAY_QUERY_URL_PRE + s,
                        "7EEA04429B006E12AAA421C002EC48BBEED5BE94",
                        "1665330417",
                        "D:\\apiclient_key.pem", WechatConstants.WE_CHAT_QUERY_URL_SUF + s);
//                        "/usr/local/vx/apiclient_key.pem",
                        "D:\\apiclient_key.pem",
                        WechatConstants.WE_CHAT_QUERY_URL_SUF + s);
                System.err.println(s1);
                JSONObject jsonObject = JSONObject.parseObject(s1);
                String string = jsonObject.getString("state");
@@ -71,7 +71,7 @@
                        orderService.updateById(order);
                        withdrawDetail.setStatus("SUCCESS");
                        withdrawDetailService.updateById(withdrawDetail);
                    } else if (s.equals("FAIL")||s.equals("CANCELING")||s.equals("CANCELLED")) {
                    } else if (string.equals("FAIL")||string.equals("CANCELING")||string.equals("CANCELLED")) {
                        // 重新发起一笔转账
                        withdrawDetail.setStatus("FAIL");
                        withdrawDetailService.updateById(withdrawDetail);
@@ -108,28 +108,39 @@
            Map<String, Object> postMap = new HashMap<>(8);
            postMap.put(WechatConstants.APP_ID, "wx98563d0ec9cf21c8");
            // 订单号
            String s = String.valueOf(UUID.randomUUID()).replaceAll("-", "");
            postMap.put("out_bill_no", s);
            postMap.put("out_bill_no", String.valueOf(UUID.randomUUID()).replaceAll("-", ""));
            System.err.println("====="+postMap.get("out_bill_no"));
            postMap.put(WechatConstants.OPEN_ID, openId);
            // 转账金额
            postMap.put("transfer_amount", transferAmount);
            postMap.put("transfer_scene_id", "1010");
            // 转账备注
            postMap.put("transfer_remark", "二手回收提现确认收款");
            // 回调地址
            postMap.put("notify_url", "https://hyhsbqgc.com/api/ruoyi-order/wx/wxChatPay");
            // 转账场景报备信息
            List<Map<String, Object>> list = new ArrayList<>();
            Map<String, Object> info = new HashMap<>();
            info.put("info_type","回收商品名称");
            info.put("info_content",serverName);
            postMap.put("transfer_scene_report_infos", com.alibaba.fastjson2.JSONObject.toJSONString(info));
            list.add(info);
            postMap.put("transfer_scene_report_infos", list);
            String result = HttpUtil.postTransBatRequest(
                    WechatConstants.WE_CHAT_PAY_URL_PRE,
                    com.alibaba.fastjson2.JSONObject.toJSONString(postMap),
                    "7EEA04429B006E12AAA421C002EC48BBEED5BE94",
                    "1665330417",
                    "/usr/local/vx/apiclient_key.pem", WechatConstants.WE_CHAT_URL_SUF);
                    "D:\\apiclient_key.pem",
//                    "/usr/local/vx/apiclient_key.pem",
                    "/v3/fund-app/mch-transfer/transfer-bills");
            com.alibaba.fastjson2.JSONObject jsonObject = com.alibaba.fastjson2.JSONObject.parseObject(result);
//            WithdrawDetail withdrawDetail = new WithdrawDetail();
//            withdrawDetail.setWithdrawId(withdrawId);
//            withdrawDetail.setMoney(transferAmount);
//            withdrawDetail.setOutBatchNo((String) postMap.get(WechatConstants.OUT_BATCH_NO));
//            withdrawDetailService.save(withdrawDetail);
            System.err.println(jsonObject);
//            WithdrawDetail withdrawDetail = new WithdrawDetail();
//            withdrawDetail.setWithdrawId(withdrawId);
//            withdrawDetail.setMoney(transferAmount);
@@ -138,23 +149,33 @@
            if (jsonObject.containsKey(WechatConstants.CREATE_TIME)) {
                String string = jsonObject.getString("package_info");
                Withdraw withdraw = withdrawService.getById(withdrawId);
                WithdrawDetail one = withdrawDetailService.lambdaQuery().eq(WithdrawDetail::getWithdrawId, withdrawId).last("limit 1").one();
                Order order = orderService.getById(withdraw.getOrderId());
                order.setIsWithdrawal(2);
                order.setPackageInfo(string);
                orderService.updateById(order);
                // 转账成功
                //保存转账明细
                WithdrawDetail one = withdrawDetailService.lambdaQuery().eq(WithdrawDetail::getWithdrawId, withdrawId).last("limit 1")
                        .one();
                if (one!=null){
                    one.setOutBatchNo(s);
                    one.setOutBatchNo(postMap.get("out_bill_no")+"");
                    one.setStatus("PENDING");
                    withdrawDetailService.updateById(one);
                    Order order = orderService.getById(withdraw.getOrderId());
                    order.setPackageInfo(string);
                    order.setIsWithdrawal(2);
                    orderService.updateById(order);
                }
            } else {
                allTransfersSuccessful = false;
                break;
                    WithdrawDetail withdrawDetail = new WithdrawDetail();
                    withdrawDetail.setWithdrawId(withdrawId);
                    withdrawDetail.setMoney(transferAmount);
                    withdrawDetail.setOutBatchNo(postMap.get("out_bill_no")+"");
                    withdrawDetailService.save(withdrawDetail);
            }
            } else {
                throw new GlobalException("提现失败,失败原因:"+jsonObject.getString("message"));
//                allTransfersSuccessful = false;
//                break;
        }
        }
        return allTransfersSuccessful;
    }