|
|
@@ -10,6 +10,11 @@ import common.utils.http.MyRet;
|
|
|
import common.utils.hyg.HygSDK;
|
|
|
import modules.order.OrderService;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
public class WithdrawService {
|
|
|
// 提现手续费,750代表万分之750(7.5%)
|
|
|
public static final long WITHDRAW_FEE = 750;
|
|
|
@@ -40,7 +45,7 @@ public class WithdrawService {
|
|
|
Withdraw withdraw = new Withdraw();
|
|
|
withdraw.setWithdrawSn(orderSn);
|
|
|
withdraw.setAmount((float)amount);
|
|
|
- withdraw.setState(10);
|
|
|
+ withdraw.setStatus(10);
|
|
|
withdraw.setUserId(user.getId());
|
|
|
withdraw.setCreateTime(System.currentTimeMillis());
|
|
|
withdraw.setUpdateTime(System.currentTimeMillis());
|
|
|
@@ -91,7 +96,7 @@ public class WithdrawService {
|
|
|
if (!withdrawRst.getString("statusCode").equals("000000")) {
|
|
|
withdraw.setHygOrigin(withdrawRst.toString());
|
|
|
withdraw.setReason("慧用工提现失败");
|
|
|
- withdraw.setState(40);
|
|
|
+ withdraw.setStatus(40);
|
|
|
|
|
|
// 原子化操作user和withdraw的状态
|
|
|
Db.tx(() -> {
|
|
|
@@ -124,7 +129,7 @@ public class WithdrawService {
|
|
|
|
|
|
// 如果是成功提现
|
|
|
withdraw.setHygOrigin(withdrawRst.toString());
|
|
|
- withdraw.setState(20);
|
|
|
+ withdraw.setStatus(20);
|
|
|
if (withdraw.update()) {
|
|
|
return MyRet.ok("打款请求已发起").setData(withdraw);
|
|
|
} else {
|
|
|
@@ -149,7 +154,7 @@ public class WithdrawService {
|
|
|
// 记录操作人
|
|
|
withdraw.setApproverId(approverId);
|
|
|
withdraw.setReason(reason);
|
|
|
- withdraw.setState(40);
|
|
|
+ withdraw.setStatus(40);
|
|
|
|
|
|
if (!withdraw.update()) {
|
|
|
throw new RuntimeException("提现单据保存失败");
|
|
|
@@ -175,6 +180,101 @@ public class WithdrawService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public MyRet list(int pageNumber, int pageSize, Integer status, Long userId) {
|
|
|
+ // 接收 Integer 类型的 orderStatus
|
|
|
+ // 构建用于查询当前页订单列表的 SQL
|
|
|
+ String columns = " * ";
|
|
|
+ String select = "SELECT " + columns;
|
|
|
+ StringBuilder fromWhere = new StringBuilder("FROM t_withdraw"); // 基础 from 子句
|
|
|
+ String orderBy = "ORDER BY update_time DESC";
|
|
|
+ boolean hasWhereClause = false; // 标志位,用于判断是否已经添加了 WHERE 关键字
|
|
|
+
|
|
|
+ List<Object> params = new ArrayList<>(); // 用于 SELECT 列表查询的参数
|
|
|
+
|
|
|
+ // ✅ 根据 status 筛选
|
|
|
+ if (status != null && status >= 0) { // status 通常是枚举,>=0 可能是有效的判断
|
|
|
+ fromWhere.append(hasWhereClause ? " AND" : " WHERE").append(" status = ?");
|
|
|
+ params.add(status);
|
|
|
+ hasWhereClause = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 根据 userId 筛选
|
|
|
+ // 通常 userId 是正整数,如果 userId 可能为 0 需要特别对待
|
|
|
+ if (userId != null && userId > 0) { // 通常 userId 从 1 开始,或者根据你的业务逻辑设定
|
|
|
+ fromWhere.append(hasWhereClause ? " AND" : " WHERE").append(" user_id = ?");
|
|
|
+ params.add(userId);
|
|
|
+ hasWhereClause = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算 LIMIT 的 offset (偏移量)
|
|
|
+ int offset = (pageNumber - 1) * pageSize;
|
|
|
+
|
|
|
+ // 构建查询当前页订单列表的最终 SQL (手动添加 LIMIT)
|
|
|
+ String listSql = select + " " + fromWhere + " " + orderBy + " LIMIT ?, ?";
|
|
|
+ params.add(offset);
|
|
|
+ params.add(pageSize);
|
|
|
+
|
|
|
+ List<Withdraw> withdrawList = Withdraw.dao.find(listSql, params.toArray());
|
|
|
+
|
|
|
+ // 如果列表为空,直接返回
|
|
|
+ if (withdrawList.isEmpty()) {
|
|
|
+ Map<String, Object> response = new HashMap<>(); // 准备返回结构
|
|
|
+ response.put("list", new ArrayList<>());
|
|
|
+ response.put("total_row", 0);
|
|
|
+ response.put("total_page", 0);
|
|
|
+ response.put("page_size", pageSize);
|
|
|
+ response.put("page_number", pageNumber);
|
|
|
+ response.put("total_order_count", 0); // 与你的 total_user_count 对应
|
|
|
+ return MyRet.ok("查询成功").setData(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取符合条件的条目数量
|
|
|
+ long totalRowLong = countWithdraws(status, userId);
|
|
|
+
|
|
|
+ // 手动计算 total_page
|
|
|
+ int totalPage = (int) Math.ceil((double) totalRowLong / pageSize);
|
|
|
+ if (totalPage == 0 && totalRowLong > 0) { // 解决总行数大于0但总页数为0(pageSize大于totalRow)的问题
|
|
|
+ totalPage = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装最终响应
|
|
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
+ response.put("list", withdrawList);
|
|
|
+ response.put("total_row", totalRowLong); // 符合条件的订单总数
|
|
|
+ response.put("total_page", totalPage); // 手动计算的总页数
|
|
|
+ response.put("page_size", pageSize);
|
|
|
+ response.put("page_number", pageNumber);
|
|
|
+ response.put("total_order_count", totalRowLong); // 对应 total_user_count,这里是符合订单状态筛选的总数
|
|
|
+
|
|
|
+ return MyRet.ok("查询成功").setData(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ public long countWithdraws(Integer status, Long userId) { // 接收 Integer 类型的 status
|
|
|
+ StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM t_withdraw"); // 使用 COUNT(*),更通用
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+ boolean hasWhereClause = false; // 标志位,用于判断是否已经添加了 WHERE 关键字
|
|
|
+
|
|
|
+ // ✅ 根据 status 筛选
|
|
|
+ if (status != null && status >= 0) { // status 通常是枚举,>=0 可能是有效的判断
|
|
|
+ sql.append(hasWhereClause ? " AND" : " WHERE").append(" status = ?");
|
|
|
+ params.add(status);
|
|
|
+ hasWhereClause = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 根据 userId 筛选
|
|
|
+ // 通常 userId 是正整数,如果 userId 可能为 0 需要特别对待
|
|
|
+ if (userId != null && userId > 0) { // 通常 userId 从 1 开始,或者根据你的业务逻辑设定
|
|
|
+ sql.append(hasWhereClause ? " AND" : " WHERE").append(" user_id = ?");
|
|
|
+ params.add(userId);
|
|
|
+ hasWhereClause = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行查询并返回结果
|
|
|
+ // Db.queryLong() 如果没有结果会返回 null,如果查询结果行数为 0,则返回 Long 0
|
|
|
+ // 这符合 COUNT() 函数的预期
|
|
|
+ return Db.queryLong(sql.toString(), params.toArray());
|
|
|
+ }
|
|
|
+
|
|
|
public Withdraw findByWithdrawSn(String sn) {
|
|
|
return Withdraw.dao.findFirst("SELECT * FROM t_withdraw WHERE withdraw_sn=?", sn);
|
|
|
}
|