|
|
@@ -1,11 +1,17 @@
|
|
|
package modules.deposit;
|
|
|
|
|
|
+import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.wechat.pay.java.service.payments.h5.model.H5Info;
|
|
|
import com.wechat.pay.java.service.payments.h5.model.PrepayResponse;
|
|
|
import com.wechat.pay.java.service.payments.h5.model.SceneInfo;
|
|
|
import common.model.Deposit;
|
|
|
import common.utils.http.MyRet;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
import static common.utils.wechat.WeChatService.prepay;
|
|
|
|
|
|
public class DepositService {
|
|
|
@@ -52,4 +58,85 @@ public class DepositService {
|
|
|
public Deposit findDepositByWxOrderNo(String wxOrderNo) {
|
|
|
return Deposit.dao.findFirst("SELECT * FROM t_deposit WHERE wx_order_no=?", wxOrderNo);
|
|
|
}
|
|
|
+
|
|
|
+ public MyRet list(int pageNumber, int pageSize, Long userId) {
|
|
|
+ // 接收 Integer 类型的 orderStatus
|
|
|
+ // 构建用于查询当前页订单列表的 SQL
|
|
|
+ String columns = " * ";
|
|
|
+ String select = "SELECT " + columns;
|
|
|
+ StringBuilder fromWhere = new StringBuilder("FROM t_deposit"); // 基础 from 子句
|
|
|
+ String orderBy = "ORDER BY create_time DESC";
|
|
|
+ boolean hasWhereClause = false; // 标志位,用于判断是否已经添加了 WHERE 关键字
|
|
|
+
|
|
|
+ List<Object> params = new ArrayList<>(); // 用于 SELECT 列表查询的参数
|
|
|
+
|
|
|
+ // ✅ 根据 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<Deposit> withdrawList = Deposit.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(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(Long userId) { // 接收 Integer 类型的 status
|
|
|
+ StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM t_deposit"); // 使用 COUNT(*),更通用
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+ boolean hasWhereClause = false; // 标志位,用于判断是否已经添加了 WHERE 关键字
|
|
|
+
|
|
|
+ // ✅ 根据 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());
|
|
|
+ }
|
|
|
}
|