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:
@@ -1,11 +1,11 @@
|
||||
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';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
|
||||
/// 交易页面
|
||||
/// 交易页面 - 使用 shadcn_ui 现代化设计
|
||||
class TradePage extends StatefulWidget {
|
||||
const TradePage({super.key});
|
||||
|
||||
@@ -19,9 +19,14 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
|
||||
int _tradeType = 0; // 0=买入, 1=卖出
|
||||
Coin? _selectedCoin;
|
||||
final _formKey = GlobalKey<ShadFormState>();
|
||||
final _priceController = TextEditingController();
|
||||
final _quantityController = TextEditingController();
|
||||
|
||||
// 颜色常量
|
||||
static const upColor = Color(0xFF00C853);
|
||||
static const downColor = Color(0xFFFF5252);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -45,22 +50,27 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
body: Consumer2<MarketProvider, AssetProvider>(
|
||||
builder: (context, market, asset, _) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCoinSelector(market),
|
||||
const SizedBox(height: 16),
|
||||
_buildPriceCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeForm(asset),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeButton(),
|
||||
],
|
||||
child: ShadForm(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
_buildCoinSelector(market),
|
||||
const SizedBox(height: 16),
|
||||
_buildPriceCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeForm(asset),
|
||||
const SizedBox(height: 16),
|
||||
_buildTradeButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -69,31 +79,26 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
}
|
||||
|
||||
Widget _buildCoinSelector(MarketProvider market) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final coins = market.allCoins;
|
||||
|
||||
if (_selectedCoin == null && coins.isNotEmpty) {
|
||||
_selectedCoin = coins.first;
|
||||
_priceController.text = _selectedCoin!.formattedPrice;
|
||||
}
|
||||
|
||||
return Container(
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(22),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_selectedCoin?.displayIcon ?? '?',
|
||||
style: const TextStyle(fontSize: 20, color: AppColors.primary),
|
||||
CircleAvatar(
|
||||
radius: 22,
|
||||
backgroundColor: theme.colorScheme.primary.withValues(alpha: 0.1),
|
||||
child: Text(
|
||||
_selectedCoin?.displayIcon ?? '?',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -104,87 +109,82 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
children: [
|
||||
Text(
|
||||
_selectedCoin != null ? '${_selectedCoin!.code}/USDT' : '选择币种',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
style: theme.textTheme.large.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_selectedCoin != null ? _selectedCoin!.name : '点击选择交易对',
|
||||
style: const TextStyle(fontSize: 12, color: AppColors.textSecondary),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: AppColors.textSecondary),
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPriceCard() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
if (_selectedCoin == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final coin = _selectedCoin!;
|
||||
return Container(
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('最新价', style: TextStyle(fontSize: 12, color: AppColors.textSecondary)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'\$${coin.formattedPrice}',
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
Text(
|
||||
'最新价',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: coin.isUp ? AppColors.up.withOpacity(0.2) : AppColors.down.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
coin.formattedChange,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: coin.isUp ? AppColors.up : AppColors.down,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'\$${coin.formattedPrice}',
|
||||
style: theme.textTheme.h2.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: coin.isUp ? upColor.withValues(alpha: 0.2) : downColor.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
coin.formattedChange,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: coin.isUp ? upColor : downColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTradeForm(AssetProvider asset) {
|
||||
return Container(
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.cardBackground,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// 买入/卖出切换
|
||||
@@ -196,14 +196,15 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: _tradeType == 0 ? AppColors.up : Colors.transparent,
|
||||
color: _tradeType == 0 ? upColor : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: _tradeType != 0 ? Border.all(color: upColor) : null,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'买入',
|
||||
style: TextStyle(
|
||||
color: _tradeType == 0 ? Colors.white : AppColors.up,
|
||||
color: _tradeType == 0 ? Colors.white : upColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -218,14 +219,15 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: _tradeType == 1 ? AppColors.down : Colors.transparent,
|
||||
color: _tradeType == 1 ? downColor : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: _tradeType != 1 ? Border.all(color: downColor) : null,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'卖出',
|
||||
style: TextStyle(
|
||||
color: _tradeType == 1 ? Colors.white : AppColors.down,
|
||||
color: _tradeType == 1 ? Colors.white : downColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
@@ -237,35 +239,64 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// 价格输入
|
||||
TextField(
|
||||
ShadInputFormField(
|
||||
id: 'price',
|
||||
label: const Text('价格(USDT)'),
|
||||
controller: _priceController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: const InputDecoration(
|
||||
labelText: '价格(USDT)',
|
||||
suffixText: 'USDT',
|
||||
placeholder: const Text('输入价格'),
|
||||
trailing: const Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: Text('USDT'),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入价格';
|
||||
}
|
||||
final price = double.tryParse(value);
|
||||
if (price == null || price <= 0) {
|
||||
return '请输入有效价格';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 数量输入
|
||||
TextField(
|
||||
ShadInputFormField(
|
||||
id: 'quantity',
|
||||
label: const Text('数量'),
|
||||
controller: _quantityController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
style: const TextStyle(color: AppColors.textPrimary),
|
||||
decoration: InputDecoration(
|
||||
labelText: '数量',
|
||||
suffixText: _selectedCoin?.code ?? '',
|
||||
placeholder: const Text('输入数量'),
|
||||
trailing: Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Text(_selectedCoin?.code ?? ''),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入数量';
|
||||
}
|
||||
final quantity = double.tryParse(value);
|
||||
if (quantity == null || quantity <= 0) {
|
||||
return '请输入有效数量';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const SizedBox(height: 16),
|
||||
// 交易金额
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('交易金额', style: TextStyle(color: AppColors.textSecondary)),
|
||||
Text(
|
||||
'交易金额',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
Text(
|
||||
'${_calculateAmount()} USDT',
|
||||
style: const TextStyle(color: AppColors.textPrimary, fontWeight: FontWeight.w600),
|
||||
style: theme.textTheme.small.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -274,10 +305,13 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('可用', style: TextStyle(color: AppColors.textSecondary)),
|
||||
Text(
|
||||
'可用',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
Text(
|
||||
'${asset.overview?.tradeBalance ?? '0.00'} USDT',
|
||||
style: const TextStyle(color: AppColors.textSecondary),
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -294,23 +328,99 @@ class _TradePageState extends State<TradePage> with AutomaticKeepAliveClientMixi
|
||||
|
||||
Widget _buildTradeButton() {
|
||||
final isBuy = _tradeType == 0;
|
||||
return Container(
|
||||
final color = isBuy ? upColor : downColor;
|
||||
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
gradient: isBuy ? AppColors.buyGradient : AppColors.sellGradient,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
isBuy ? '买入 ${_selectedCoin?.code ?? ''}' : '卖出 ${_selectedCoin?.code ?? ''}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
child: ShadButton(
|
||||
backgroundColor: color,
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.saveAndValidate()) {
|
||||
_executeTrade();
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
isBuy ? LucideIcons.arrowDownToLine : LucideIcons.arrowUpFromLine,
|
||||
size: 18,
|
||||
color: Colors.white,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${isBuy ? '买入' : '卖出'} ${_selectedCoin?.code ?? ''}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _executeTrade() {
|
||||
final price = _priceController.text;
|
||||
final quantity = _quantityController.text;
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: Text(_tradeType == 0 ? '确认买入' : '确认卖出'),
|
||||
description: Text(
|
||||
'${_tradeType == 0 ? '买入' : '卖出'} $quantity ${_selectedCoin?.code ?? ''} @ $price USDT',
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_showTradeResult();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTradeResult() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.circleCheck,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('交易成功'),
|
||||
],
|
||||
),
|
||||
description: Text(
|
||||
'已${_tradeType == 0 ? '买入' : '卖出'} ${_quantityController.text} ${_selectedCoin?.code ?? ''}',
|
||||
),
|
||||
actions: [
|
||||
ShadButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
_quantityController.clear();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user