平台支付总览 ,可以统计所有应用,也可以选择某个应用,然后查看总览,请帮我添加该功能

This commit is contained in:
lu7213 committed 2026-10-18 05:21:01 -04:00
1 parent e987be3a03
commit 7a7222e69c
3 files changed
+50 -29

No files matched your search

@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
/** 登录首页支付经营数据。 */ /** 登录首页支付经营数据。 */
@RestController @RestController
@@ -15,7 +16,7 @@ public class PaymentDashboardController {
private PaymentDashboardService dashboardService; private PaymentDashboardService dashboardService;
@GetMapping("/overview") @GetMapping("/overview")
public AjaxResult overview() { public AjaxResult overview(@RequestParam(value = "appId", required = false) Long appId) {
return AjaxResult.success(dashboardService.overview()); return AjaxResult.success(dashboardService.overview(appId));
} }
} }
@@ -14,16 +14,18 @@ public interface PaymentDashboardMapper {
"coalesce(sum(usdt_balance),0) usdtBalance, coalesce(sum(trx_balance),0) trxBalance,", "coalesce(sum(usdt_balance),0) usdtBalance, coalesce(sum(trx_balance),0) trxBalance,",
"coalesce(sum(usdt_frozen_balance),0) usdtFrozenBalance, coalesce(sum(trx_frozen_balance),0) trxFrozenBalance,", "coalesce(sum(usdt_frozen_balance),0) usdtFrozenBalance, coalesce(sum(trx_frozen_balance),0) trxFrozenBalance,",
"coalesce(sum(credit_limit),0) creditLimit from apps where deleted_at is null", "coalesce(sum(credit_limit),0) creditLimit from apps where deleted_at is null",
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"}) "<if test='userId != null'> and user_id=#{userId}</if>",
Map<String, Object> selectAppsSummary(@Param("userId") Long userId); "<if test='appId != null'> and id=#{appId}</if>", "</script>"})
Map<String, Object> selectAppsSummary(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select count(1) walletCount, coalesce(sum(usdt_balance),0) walletUsdtBalance,", "select count(1) walletCount, coalesce(sum(usdt_balance),0) walletUsdtBalance,",
"coalesce(sum(trx_balance),0) walletTrxBalance,", "coalesce(sum(trx_balance),0) walletTrxBalance,",
"sum(case when status=1 then 1 else 0 end) enabledWalletCount", "sum(case when status=1 then 1 else 0 end) enabledWalletCount",
"from wallet_address where deleted_at is null and wallet_user_name is not null", "from wallet_address where deleted_at is null and wallet_user_name is not null",
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"}) "<if test='userId != null'> and user_id=#{userId}</if>",
Map<String, Object> selectWalletSummary(@Param("userId") Long userId); "<if test='appId != null'> and app_id=#{appId}</if>", "</script>"})
Map<String, Object> selectWalletSummary(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select count(1) totalCount, sum(case when status=1 then 1 else 0 end) pendingCount,", "select count(1) totalCount, sum(case when status=1 then 1 else 0 end) pendingCount,",
@@ -32,8 +34,9 @@ public interface PaymentDashboardMapper {
"coalesce(sum(case when status=2 and created_at &gt;= curdate() then actual_amount else 0 end),0) todayPaidUsdtAmount,", "coalesce(sum(case when status=2 and created_at &gt;= curdate() then actual_amount else 0 end),0) todayPaidUsdtAmount,",
"sum(case when status=2 and created_at &gt;= curdate() then 1 else 0 end) todayPaidCount", "sum(case when status=2 and created_at &gt;= curdate() then 1 else 0 end) todayPaidCount",
"from orders where deleted_at is null", "from orders where deleted_at is null",
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"}) "<if test='userId != null'> and user_id=#{userId}</if>",
Map<String, Object> selectPaymentSummary(@Param("userId") Long userId); "<if test='appId != null'> and app_id=#{appId}</if>", "</script>"})
Map<String, Object> selectPaymentSummary(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select count(1) totalCount, sum(case when status=0 then 1 else 0 end) pendingAuditCount,", "select count(1) totalCount, sum(case when status=0 then 1 else 0 end) pendingAuditCount,",
@@ -46,37 +49,38 @@ public interface PaymentDashboardMapper {
"coalesce(sum(case when status=3 and currency='TRX' then amount else 0 end),0) completedTrxAmount,", "coalesce(sum(case when status=3 and currency='TRX' then amount else 0 end),0) completedTrxAmount,",
"coalesce(sum(case when status=3 then fee_amount else 0 end),0) payoutFeeTrx", "coalesce(sum(case when status=3 then fee_amount else 0 end),0) payoutFeeTrx",
"from usdt_payout_order where deleted_at is null", "from usdt_payout_order where deleted_at is null",
"<if test='userId != null'> and user_id=#{userId}</if>", "</script>"}) "<if test='userId != null'> and user_id=#{userId}</if>",
Map<String, Object> selectPayoutSummary(@Param("userId") Long userId); "<if test='appId != null'> and app_id=#{appId}</if>", "</script>"})
Map<String, Object> selectPayoutSummary(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select date(created_at) period, count(1) orderCount, coalesce(sum(actual_amount),0) amount", "select date(created_at) period, count(1) orderCount, coalesce(sum(actual_amount),0) amount",
"from orders where deleted_at is null and status=2 and created_at &gt;= date_sub(curdate(), interval 29 day)", "from orders where deleted_at is null and status=2 and created_at &gt;= date_sub(curdate(), interval 29 day)",
"<if test='userId != null'> and user_id=#{userId}</if>", "<if test='userId != null'> and user_id=#{userId}</if>", "<if test='appId != null'> and app_id=#{appId}</if>",
"group by date(created_at) order by period", "</script>"}) "group by date(created_at) order by period", "</script>"})
List<Map<String, Object>> selectPaymentTrend(@Param("userId") Long userId); List<Map<String, Object>> selectPaymentTrend(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select date(created_at) period, currency, count(1) orderCount, coalesce(sum(amount),0) amount", "select date(created_at) period, currency, count(1) orderCount, coalesce(sum(amount),0) amount",
"from usdt_payout_order where deleted_at is null and status=3", "from usdt_payout_order where deleted_at is null and status=3",
"and created_at &gt;= date_sub(curdate(), interval 29 day)", "and created_at &gt;= date_sub(curdate(), interval 29 day)",
"<if test='userId != null'> and user_id=#{userId}</if>", "<if test='userId != null'> and user_id=#{userId}</if>", "<if test='appId != null'> and app_id=#{appId}</if>",
"group by date(created_at), currency order by period, currency", "</script>"}) "group by date(created_at), currency order by period, currency", "</script>"})
List<Map<String, Object>> selectPayoutTrend(@Param("userId") Long userId); List<Map<String, Object>> selectPayoutTrend(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select currency, direction, business_type businessType, count(1) ledgerCount,", "select currency, direction, business_type businessType, count(1) ledgerCount,",
"coalesce(sum(amount),0) amount from apps_balance_ledger where created_at &gt;= date_sub(now(), interval 30 day)", "coalesce(sum(amount),0) amount from apps_balance_ledger where created_at &gt;= date_sub(now(), interval 30 day)",
"<if test='userId != null'> and user_id=#{userId}</if>", "<if test='userId != null'> and user_id=#{userId}</if>", "<if test='appId != null'> and app_id=#{appId}</if>",
"group by currency, direction, business_type order by amount desc", "</script>"}) "group by currency, direction, business_type order by amount desc", "</script>"})
List<Map<String, Object>> selectLedgerDistribution(@Param("userId") Long userId); List<Map<String, Object>> selectLedgerDistribution(@Param("userId") Long userId, @Param("appId") Long appId);
@Select({"<script>", @Select({"<script>",
"select a.id appId, a.name appName,", "select a.id appId, a.name appName,",
"sum(case when o.status=2 then 1 else 0 end) paidCount,", "sum(case when o.status=2 then 1 else 0 end) paidCount,",
"coalesce(sum(case when o.status=2 then o.actual_amount else 0 end),0) paidAmount", "coalesce(sum(case when o.status=2 then o.actual_amount else 0 end),0) paidAmount",
"from apps a left join orders o on o.app_id=a.id and o.deleted_at is null", "from apps a left join orders o on o.app_id=a.id and o.deleted_at is null",
"where a.deleted_at is null <if test='userId != null'> and a.user_id=#{userId}</if>", "where a.deleted_at is null <if test='userId != null'> and a.user_id=#{userId}</if> <if test='appId != null'> and a.id=#{appId}</if>",
"group by a.id,a.name order by paidAmount desc limit 8", "</script>"}) "group by a.id,a.name order by paidAmount desc limit 8", "</script>"})
List<Map<String, Object>> selectTopApps(@Param("userId") Long userId); List<Map<String, Object>> selectTopApps(@Param("userId") Long userId, @Param("appId") Long appId);
} }
@@ -4,6 +4,9 @@ import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.PaymentDashboardMapper; import com.ruoyi.system.mapper.PaymentDashboardMapper;
import com.ruoyi.system.domain.UsdtConfig; import com.ruoyi.system.domain.UsdtConfig;
import com.ruoyi.system.mapper.UsdtConfigMapper; import com.ruoyi.system.mapper.UsdtConfigMapper;
import com.ruoyi.system.mapper.AppsMapper;
import com.ruoyi.system.domain.Apps;
import com.ruoyi.common.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -17,12 +20,24 @@ public class PaymentDashboardService {
private PaymentDashboardMapper mapper; private PaymentDashboardMapper mapper;
@Autowired @Autowired
private UsdtConfigMapper usdtConfigMapper; private UsdtConfigMapper usdtConfigMapper;
@Autowired
private AppsMapper appsMapper;
public Map<String, Object> overview() { public Map<String, Object> overview(Long requestedAppId) {
Long currentUserId = SecurityUtils.getUserId(); Long currentUserId = SecurityUtils.getUserId();
Long scopedUserId = SecurityUtils.isAdmin(currentUserId) ? null : currentUserId; boolean admin = SecurityUtils.isAdmin(currentUserId);
Long scopedUserId = admin ? null : currentUserId;
if (requestedAppId != null) {
Apps app = appsMapper.selectAppsById(requestedAppId);
if (app == null) {
throw new CustomException("应用不存在");
}
if (!admin && !currentUserId.equals(app.getUserId())) {
throw new CustomException("无权查看该应用");
}
}
Map<String, Object> result = new LinkedHashMap<String, Object>(); Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("admin", scopedUserId == null); result.put("admin", admin);
if (scopedUserId == null) { if (scopedUserId == null) {
UsdtConfig config = usdtConfigMapper.selectFirst(); UsdtConfig config = usdtConfigMapper.selectFirst();
Map<String, Object> mainWallet = new LinkedHashMap<String, Object>(); Map<String, Object> mainWallet = new LinkedHashMap<String, Object>();
@@ -34,14 +49,15 @@ public class PaymentDashboardService {
} }
result.put("mainWallet", mainWallet); result.put("mainWallet", mainWallet);
} }
result.put("apps", mapper.selectAppsSummary(scopedUserId)); result.put("selectedAppId", requestedAppId);
result.put("wallets", mapper.selectWalletSummary(scopedUserId)); result.put("apps", mapper.selectAppsSummary(scopedUserId, requestedAppId));
result.put("payments", mapper.selectPaymentSummary(scopedUserId)); result.put("wallets", mapper.selectWalletSummary(scopedUserId, requestedAppId));
result.put("payouts", mapper.selectPayoutSummary(scopedUserId)); result.put("payments", mapper.selectPaymentSummary(scopedUserId, requestedAppId));
result.put("paymentTrend", mapper.selectPaymentTrend(scopedUserId)); result.put("payouts", mapper.selectPayoutSummary(scopedUserId, requestedAppId));
result.put("payoutTrend", mapper.selectPayoutTrend(scopedUserId)); result.put("paymentTrend", mapper.selectPaymentTrend(scopedUserId, requestedAppId));
result.put("ledgerDistribution", mapper.selectLedgerDistribution(scopedUserId)); result.put("payoutTrend", mapper.selectPayoutTrend(scopedUserId, requestedAppId));
result.put("topApps", mapper.selectTopApps(scopedUserId)); result.put("ledgerDistribution", mapper.selectLedgerDistribution(scopedUserId, requestedAppId));
result.put("topApps", mapper.selectTopApps(scopedUserId, requestedAppId));
return result; return result;
} }
} }