feat: 添加业务分析后端接口

新增 AnalysisController 提供 6 个分析接口:
- /admin/analysis/profit - 盈利分析(交易手续费/充提手续费/资金利差)
- /admin/analysis/cash-flow - 资金流动趋势(按月统计充值/提现/净流入)
- /admin/analysis/trade - 交易分析(买入/卖出统计+趋势)
- /admin/analysis/coin-distribution - 币种交易分布
- /admin/analysis/user-growth - 用户增长分析(新增/活跃用户)
- /admin/analysis/risk - 风险指标(大额交易/异常提现/KYC/冻结账户)
- /admin/analysis/health - 综合健康度评分

更新 Mapper 添加分析查询方法:
- OrderFundMapper: 手续费统计、时间范围查询、大额交易、异常提现
- OrderTradeMapper: 交易金额统计、活跃用户、币种分布

前端 API 对接:
- 新增 6 个分析相关 Query hooks
- 更新 analytics.vue 使用真实数据
- 动态决策建议基于实际数据
This commit is contained in:
2026-03-22 04:50:19 +08:00
parent 0e95890d68
commit c3f196ded4
23 changed files with 3520 additions and 1055 deletions

View File

@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:provider/provider.dart';
import '../../../core/constants/app_colors.dart';
import '../../../data/models/coin.dart';
import '../../../providers/market_provider.dart';
/// 行情页面
/// 行情页面 - 使用 shadcn_ui 现代化设计
class MarketPage extends StatefulWidget {
const MarketPage({super.key});
@@ -35,8 +35,10 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
@override
Widget build(BuildContext context) {
super.build(context);
final theme = ShadTheme.of(context);
return Scaffold(
backgroundColor: AppColors.background,
backgroundColor: theme.colorScheme.background,
body: Consumer<MarketProvider>(
builder: (context, provider, _) {
return Column(
@@ -54,30 +56,39 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
}
Widget _buildSearchBar(MarketProvider provider) {
final theme = ShadTheme.of(context);
return Padding(
padding: const EdgeInsets.all(16),
child: TextField(
child: ShadInput(
controller: _searchController,
style: const TextStyle(color: AppColors.textPrimary),
onChanged: provider.search,
decoration: InputDecoration(
hintText: '搜索币种...',
prefixIcon: const Icon(Icons.search, color: AppColors.textSecondary),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear, color: AppColors.textSecondary),
onPressed: () {
_searchController.clear();
provider.clearSearch();
},
)
: null,
placeholder: const Text('搜索币种...'),
leading: Icon(
LucideIcons.search,
size: 18,
color: theme.colorScheme.mutedForeground,
),
trailing: _searchController.text.isNotEmpty
? GestureDetector(
onTap: () {
_searchController.clear();
provider.clearSearch();
},
child: Icon(
LucideIcons.x,
size: 18,
color: theme.colorScheme.mutedForeground,
),
)
: null,
onChanged: provider.search,
),
);
}
Widget _buildTabs(MarketProvider provider) {
final theme = ShadTheme.of(context);
final tabs = [
{'key': 'all', 'label': '全部'},
{'key': 'realtime', 'label': '实时'},
@@ -88,21 +99,28 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
height: 44,
margin: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: tabs.map((tab) {
children: tabs.asMap().entries.map((entry) {
final index = entry.key;
final tab = entry.value;
final isActive = provider.activeTab == tab['key'];
return GestureDetector(
onTap: () => provider.setTab(tab['key']!),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
margin: const EdgeInsets.only(right: 8),
decoration: BoxDecoration(
color: isActive ? AppColors.primary : AppColors.cardBackground,
color: isActive
? theme.colorScheme.primary
: theme.colorScheme.card,
borderRadius: BorderRadius.circular(20),
),
child: Text(
tab['label']!,
style: TextStyle(
color: isActive ? Colors.white : AppColors.textSecondary,
color: isActive
? Colors.white
: theme.colorScheme.mutedForeground,
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
),
),
@@ -114,9 +132,13 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
}
Widget _buildCoinList(MarketProvider provider) {
final theme = ShadTheme.of(context);
if (provider.isLoading) {
return const Center(
child: CircularProgressIndicator(color: AppColors.primary),
return Center(
child: CircularProgressIndicator(
color: theme.colorScheme.primary,
),
);
}
@@ -125,9 +147,18 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(provider.error!, style: const TextStyle(color: AppColors.error)),
Icon(
LucideIcons.circleAlert,
size: 48,
color: theme.colorScheme.destructive,
),
const SizedBox(height: 12),
Text(
provider.error!,
style: TextStyle(color: theme.colorScheme.destructive),
),
const SizedBox(height: 16),
ElevatedButton(
ShadButton(
onPressed: provider.loadCoins,
child: const Text('重试'),
),
@@ -138,14 +169,28 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
final coins = provider.coins;
if (coins.isEmpty) {
return const Center(
child: Text('暂无数据', style: TextStyle(color: AppColors.textSecondary)),
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
LucideIcons.coins,
size: 48,
color: theme.colorScheme.mutedForeground,
),
const SizedBox(height: 12),
Text(
'暂无数据',
style: theme.textTheme.muted,
),
],
),
);
}
return RefreshIndicator(
onRefresh: provider.refresh,
color: AppColors.primary,
color: theme.colorScheme.primary,
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 16),
itemCount: coins.length,
@@ -155,73 +200,64 @@ class _MarketPageState extends State<MarketPage> with AutomaticKeepAliveClientMi
}
Widget _buildCoinItem(Coin coin) {
return Container(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.cardBackground,
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
// 图标
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: AppColors.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(22),
),
child: Center(
final theme = ShadTheme.of(context);
final upColor = const Color(0xFF00C853);
final downColor = const Color(0xFFFF5252);
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: ShadCard(
padding: const EdgeInsets.all(16),
child: Row(
children: [
// 图标
CircleAvatar(
radius: 22,
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
child: Text(
coin.displayIcon,
style: const TextStyle(
style: TextStyle(
fontSize: 20,
color: AppColors.primary,
color: theme.colorScheme.primary,
),
),
),
),
const SizedBox(width: 12),
// 名称
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${coin.code}/USDT',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: AppColors.textPrimary,
const SizedBox(width: 12),
// 名称
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${coin.code}/USDT',
style: theme.textTheme.large.copyWith(
fontWeight: FontWeight.bold,
),
),
),
Text(
coin.name,
style: const TextStyle(
fontSize: 12,
color: AppColors.textSecondary,
Text(
coin.name,
style: theme.textTheme.muted,
),
),
],
),
),
// 涨跌幅
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: coin.isUp ? AppColors.up.withOpacity(0.2) : AppColors.down.withOpacity(0.2),
borderRadius: BorderRadius.circular(6),
),
child: Text(
coin.formattedChange,
style: TextStyle(
color: coin.isUp ? AppColors.up : AppColors.down,
fontWeight: FontWeight.w600,
],
),
),
),
],
// 涨跌幅
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: coin.isUp ? upColor.withValues(alpha: 0.2) : downColor.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(6),
),
child: Text(
coin.formattedChange,
style: TextStyle(
color: coin.isUp ? upColor : downColor,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
);
}