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

@@ -0,0 +1,224 @@
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:flutter_animate/flutter_animate.dart';
/// 资产卡片组件 - 用于显示资产总览
class AssetCard extends StatelessWidget {
final String title;
final String balance;
final String? subtitle;
final String? profit;
final bool? isProfit;
final List<AssetItem>? items;
final Gradient? gradient;
final VoidCallback? onTap;
// 默认渐变色
static const defaultGradient = LinearGradient(
colors: [Color(0xFF00D4AA), Color(0xFF00B894)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
);
// 深色渐变
static const darkGradient = LinearGradient(
colors: [Color(0xFF1E3A5F), Color(0xFF0D253F)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
);
const AssetCard({
super.key,
this.title = '总资产',
required this.balance,
this.subtitle,
this.profit,
this.isProfit,
this.items,
this.gradient,
this.onTap,
});
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
final cardGradient = gradient ?? defaultGradient;
return GestureDetector(
onTap: onTap,
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
gradient: cardGradient,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题行
Row(
children: [
Text(
title,
style: theme.textTheme.small.copyWith(color: Colors.white70),
),
const Spacer(),
if (onTap != null)
Icon(
LucideIcons.chevronRight,
color: Colors.white70,
size: 18,
),
],
),
const SizedBox(height: 8),
// 余额
Text(
balance,
style: theme.textTheme.h1.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
// 盈亏信息
if (profit != null) ...[
const SizedBox(height: 12),
Row(
children: [
Icon(
isProfit == true ? LucideIcons.trendingUp : LucideIcons.trendingDown,
color: Colors.white70,
size: 16,
),
const SizedBox(width: 6),
Text(
'盈亏: $profit',
style: theme.textTheme.small.copyWith(color: Colors.white70),
),
],
),
],
// 子项
if (items != null && items!.isNotEmpty) ...[
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: items!.map((item) => _buildItem(item)).toList(),
),
],
],
),
),
).animate().fadeIn(duration: 400.ms).slideY(begin: 0.1, end: 0);
}
Widget _buildItem(AssetItem item) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item.label,
style: const TextStyle(fontSize: 12, color: Colors.white70),
),
const SizedBox(height: 4),
Text(
item.value,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
],
);
}
}
/// 资产子项
class AssetItem {
final String label;
final String value;
const AssetItem({
required this.label,
required this.value,
});
}
/// 简洁资产卡片 - 用于列表中显示
class AssetCardCompact extends StatelessWidget {
final String title;
final String balance;
final String? change;
final bool? isUp;
final VoidCallback? onTap;
static const upColor = Color(0xFF00C853);
static const downColor = Color(0xFFFF5252);
const AssetCardCompact({
super.key,
required this.title,
required this.balance,
this.change,
this.isUp,
this.onTap,
});
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return ShadCard(
padding: const EdgeInsets.all(16),
child: InkWell(
onTap: onTap,
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: theme.textTheme.muted,
),
const SizedBox(height: 4),
Text(
balance,
style: theme.textTheme.h3.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
),
if (change != null)
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: (isUp ?? true) ? upColor.withOpacity(0.2) : downColor.withOpacity(0.2),
borderRadius: BorderRadius.circular(6),
),
child: Text(
change!,
style: TextStyle(
color: (isUp ?? true) ? upColor : downColor,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,97 @@
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
/// 币种卡片组件 - 用于显示币种信息
class CoinCard extends StatelessWidget {
final String code;
final String name;
final String price;
final String change;
final bool isUp;
final String? icon;
final VoidCallback? onTap;
// 颜色常量
static const upColor = Color(0xFF00C853);
static const downColor = Color(0xFFFF5252);
const CoinCard({
super.key,
required this.code,
required this.name,
required this.price,
required this.change,
this.isUp = true,
this.icon,
this.onTap,
});
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return ShadCard(
padding: const EdgeInsets.all(16),
child: InkWell(
onTap: onTap,
child: Row(
children: [
// 图标
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: theme.colorScheme.primary.withOpacity(0.1),
shape: BoxShape.circle,
),
child: Center(
child: Text(
icon ?? code.substring(0, 1),
style: TextStyle(
fontSize: 20,
color: theme.colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(width: 12),
// 名称
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'$code/USDT',
style: theme.textTheme.large.copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
name,
style: theme.textTheme.muted,
),
],
),
),
// 涨跌幅
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: isUp ? upColor.withOpacity(0.2) : downColor.withOpacity(0.2),
borderRadius: BorderRadius.circular(6),
),
child: Text(
change,
style: TextStyle(
color: isUp ? upColor : downColor,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
);
}
}

View File

@@ -0,0 +1,6 @@
/// 自定义组件导出
library components;
export 'coin_card.dart';
export 'trade_button.dart';
export 'asset_card.dart';

View File

@@ -0,0 +1,125 @@
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
/// 交易按钮组件 - 买入/卖出按钮
class TradeButton extends StatelessWidget {
final bool isBuy;
final String? coinCode;
final VoidCallback? onPressed;
final bool isLoading;
final bool fullWidth;
// 颜色常量
static const buyColor = Color(0xFF00C853);
static const sellColor = Color(0xFFFF5252);
const TradeButton({
super.key,
this.isBuy = true,
this.coinCode,
this.onPressed,
this.isLoading = false,
this.fullWidth = false,
});
/// 买入按钮
const TradeButton.buy({
super.key,
this.coinCode,
this.onPressed,
this.isLoading = false,
this.fullWidth = false,
}) : isBuy = true;
/// 卖出按钮
const TradeButton.sell({
super.key,
this.coinCode,
this.onPressed,
this.isLoading = false,
this.fullWidth = false,
}) : isBuy = false;
@override
Widget build(BuildContext context) {
final color = isBuy ? buyColor : sellColor;
final text = isBuy ? '买入${coinCode != null ? ' $coinCode' : ''}' : '卖出${coinCode != null ? ' $coinCode' : ''}';
final icon = isBuy ? LucideIcons.arrowDownToLine : LucideIcons.arrowUpFromLine;
final button = ShadButton(
backgroundColor: color,
onPressed: isLoading ? null : onPressed,
child: Row(
mainAxisSize: fullWidth ? MainAxisSize.max : MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (isLoading)
const SizedBox.square(
dimension: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
else
Icon(icon, size: 18, color: Colors.white),
const SizedBox(width: 8),
Text(
text,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
],
),
);
if (fullWidth) {
return SizedBox(width: double.infinity, child: button);
}
return button;
}
}
/// 交易按钮组 - 同时显示买入和卖出按钮
class TradeButtonGroup extends StatelessWidget {
final String? coinCode;
final VoidCallback? onBuyPressed;
final VoidCallback? onSellPressed;
final bool isBuyLoading;
final bool isSellLoading;
const TradeButtonGroup({
super.key,
this.coinCode,
this.onBuyPressed,
this.onSellPressed,
this.isBuyLoading = false,
this.isSellLoading = false,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: TradeButton.buy(
coinCode: coinCode,
onPressed: onBuyPressed,
isLoading: isBuyLoading,
),
),
const SizedBox(width: 12),
Expanded(
child: TradeButton.sell(
coinCode: coinCode,
onPressed: onSellPressed,
isLoading: isSellLoading,
),
),
],
);
}
}