From f6965e7733623222cef5165d5007d9c038d737b3 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期三, 22 十月 2025 15:12:26 +0800
Subject: [PATCH] 添加订单虚拟号
---
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/task/TaskUtil.java | 62 +++++++++++++++++++-----------
1 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/task/TaskUtil.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/task/TaskUtil.java
index ca82fdd..2e438e3 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/task/TaskUtil.java
+++ b/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,7 @@
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", WechatConstants.WE_CHAT_QUERY_URL_SUF + s);
System.err.println(s1);
JSONObject jsonObject = JSONObject.parseObject(s1);
String string = jsonObject.getString("state");
@@ -71,7 +69,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);
@@ -89,7 +87,7 @@
}
}
- private boolean weChatPay(BigDecimal orderMoney, String openId, String withdrawId, String serverName) {
+ private boolean weChatPay(BigDecimal orderMoney, String openId,String withdrawId,String serverName) {
if (com.ruoyi.common.core.utils.StringUtils.isBlank(openId)) {
return false;
}
@@ -108,21 +106,23 @@
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),
@@ -135,26 +135,42 @@
// 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);
+// withdrawDetail.setOutBatchNo((String) postMap.get(WechatConstants.OUT_BATCH_NO));
+// withdrawDetailService.save(withdrawDetail);
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();
- if (one!=null){
- one.setOutBatchNo(s);
+
+ 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(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);
+ withdrawDetailService.updateById( one);
+ }else{
+ WithdrawDetail withdrawDetail = new WithdrawDetail();
+ withdrawDetail.setWithdrawId(withdrawId);
+ withdrawDetail.setMoney(transferAmount);
+ withdrawDetail.setOutBatchNo(postMap.get("out_bill_no")+"");
+ withdrawDetailService.save(withdrawDetail);
}
+
} else {
- allTransfersSuccessful = false;
- break;
+ throw new GlobalException("提现失败,失败原因:"+jsonObject.getString("message"));
+// allTransfersSuccessful = false;
+// break;
}
-
}
-
return allTransfersSuccessful;
}
--
Gitblit v1.7.1