Compare commits
2 Commits
cfc26f754a
...
91227b7e51
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91227b7e51 | ||
|
|
a476d0a23b |
140
deploy/bt_webhook_cicd.sh
Normal file
140
deploy/bt_webhook_cicd.sh
Normal file
@@ -0,0 +1,140 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================
|
||||
# Monisuo CI/CD 部署脚本 - 宝塔 Webhook
|
||||
# ============================================
|
||||
|
||||
# ============ 环境配置 ============
|
||||
# JDK 路径(根据实际修改)
|
||||
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
|
||||
export PATH=$JAVA_HOME/bin:$PATH
|
||||
|
||||
# Maven 路径(如果手动安装)
|
||||
export MAVEN_HOME=/opt/maven
|
||||
export PATH=$MAVEN_HOME/bin:$PATH
|
||||
|
||||
# ============ 项目配置 ============
|
||||
PROJECT_PATH="/opt/monisuo"
|
||||
GIT_REPO="http://sion:woshisaw.@8.155.172.147:3001/sion/monisuo.git"
|
||||
JAR_NAME="monisuo-1.0.jar"
|
||||
LOG_FILE="/opt/monisuo/deploy.log"
|
||||
WEBHOOK_SECRET=""
|
||||
|
||||
# ============ 日志函数 ============
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> $LOG_FILE
|
||||
}
|
||||
|
||||
# ============ 错误处理 ============
|
||||
error_exit() {
|
||||
log "❌ 错误: $1"
|
||||
echo "Error: $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ============ 主流程 ============
|
||||
log "=========================================="
|
||||
log "🚀 开始 CI/CD 部署"
|
||||
log "=========================================="
|
||||
|
||||
# 记录环境信息
|
||||
log "Java 版本: $(java -version 2>&1 | head -1)"
|
||||
log "Maven 版本: $(mvn -version 2>&1 | head -1)"
|
||||
log "当前目录: $(pwd)"
|
||||
|
||||
# 1. 检查/克隆项目
|
||||
if [ ! -d "$PROJECT_PATH/.git" ]; then
|
||||
log "📥 首次部署,克隆项目..."
|
||||
mkdir -p $PROJECT_PATH
|
||||
git clone $GIT_REPO $PROJECT_PATH >> $LOG_FILE 2>&1 || error_exit "Git 克隆失败"
|
||||
fi
|
||||
|
||||
cd $PROJECT_PATH || error_exit "无法进入项目目录"
|
||||
|
||||
# 2. 拉取最新代码
|
||||
log "📥 拉取最新代码..."
|
||||
git fetch origin >> $LOG_FILE 2>&1
|
||||
git reset --hard origin/main >> $LOG_FILE 2>&1 || error_exit "Git 拉取失败"
|
||||
|
||||
# 获取提交信息
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
COMMIT_MSG=$(git log -1 --pretty=%s)
|
||||
log "📝 最新提交: $COMMIT_HASH - $COMMIT_MSG"
|
||||
|
||||
# 3. 检查文件变更
|
||||
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null)
|
||||
log "📁 变更文件: $CHANGED_FILES"
|
||||
|
||||
# 4. 后端构建和部署
|
||||
if echo "$CHANGED_FILES" | grep -qE "^src/|^pom.xml"; then
|
||||
log "🔨 检测到后端代码变更,开始构建..."
|
||||
|
||||
cd $PROJECT_PATH
|
||||
mvn clean package -DskipTests >> $LOG_FILE 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
error_exit "Maven 构建失败"
|
||||
fi
|
||||
log "✅ Maven 构建成功"
|
||||
else
|
||||
log "⏭️ 后端代码无变更,跳过构建"
|
||||
fi
|
||||
|
||||
# 5. 停止旧服务
|
||||
log "🛑 停止旧服务..."
|
||||
pkill -f $JAR_NAME 2>/dev/null
|
||||
sleep 3
|
||||
|
||||
# 检查是否停止成功
|
||||
if pgrep -f $JAR_NAME > /dev/null; then
|
||||
log "⚠️ 进程未停止,强制终止..."
|
||||
pkill -9 -f $JAR_NAME 2>/dev/null
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
# 6. 启动新服务
|
||||
log "🚀 启动新服务..."
|
||||
cd $PROJECT_PATH
|
||||
|
||||
nohup java -jar \
|
||||
-Xms256m \
|
||||
-Xmx512m \
|
||||
-XX:+UseG1GC \
|
||||
target/$JAR_NAME \
|
||||
--spring.profiles.active=dev \
|
||||
> $PROJECT_PATH/app.log 2>&1 &
|
||||
|
||||
# 7. 检查服务状态
|
||||
sleep 5
|
||||
if pgrep -f $JAR_NAME > /dev/null; then
|
||||
PID=$(pgrep -f $JAR_NAME)
|
||||
log "✅ 服务启动成功 (PID: $PID)"
|
||||
else
|
||||
log "❌ 服务启动失败,查看日志:"
|
||||
tail -50 $PROJECT_PATH/app.log >> $LOG_FILE
|
||||
error_exit "服务启动失败"
|
||||
fi
|
||||
|
||||
# 8. 健康检查
|
||||
log "🔍 健康检查..."
|
||||
sleep 5
|
||||
HEALTH_CHECK=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5010/ 2>/dev/null || echo "000")
|
||||
|
||||
if [ "$HEALTH_CHECK" = "200" ] || [ "$HEALTH_CHECK" = "404" ]; then
|
||||
log "✅ 健康检查通过 (HTTP $HEALTH_CHECK)"
|
||||
else
|
||||
log "⚠️ 健康检查异常 (HTTP $HEALTH_CHECK)"
|
||||
fi
|
||||
|
||||
# 9. 清理旧日志
|
||||
log "🧹 清理旧日志..."
|
||||
find $PROJECT_PATH -name "*.log" -mtime +7 -delete 2>/dev/null
|
||||
|
||||
# 10. 完成
|
||||
log "=========================================="
|
||||
log "✅ CI/CD 部署完成"
|
||||
log " 提交: $COMMIT_HASH"
|
||||
log " 时间: $(date '+%Y-%m-%d %H:%M:%S')"
|
||||
log "=========================================="
|
||||
|
||||
echo "Deploy Success! Commit: $COMMIT_HASH"
|
||||
@@ -69,6 +69,9 @@ class ApiEndpoints {
|
||||
/// 申请充值
|
||||
static const String deposit = '/api/fund/deposit';
|
||||
|
||||
/// 确认已打款
|
||||
static const String confirmPay = '/api/fund/confirmPay';
|
||||
|
||||
/// 申请提现
|
||||
static const String withdraw = '/api/fund/withdraw';
|
||||
|
||||
@@ -77,4 +80,7 @@ class ApiEndpoints {
|
||||
|
||||
/// 获取充提记录
|
||||
static const String fundOrders = '/api/fund/orders';
|
||||
|
||||
/// 获取默认钱包地址
|
||||
static const String defaultWallet = '/api/wallet/default';
|
||||
}
|
||||
|
||||
@@ -72,25 +72,39 @@ class OrderFund {
|
||||
final int id;
|
||||
final String orderNo;
|
||||
final int userId;
|
||||
final int orderType; // 1=充值, 2=提现
|
||||
final String username;
|
||||
final int type; // 1=充值, 2=提现
|
||||
final String amount;
|
||||
final int status; // 1=待审核, 2=已通过, 3=已拒绝, 4=已取消
|
||||
final int status;
|
||||
// 充值状态: 1=待付款, 2=待确认, 3=已完成, 4=已驳回, 5=已取消
|
||||
// 提现状态: 1=待审批, 2=已完成, 3=已驳回, 4=已取消
|
||||
final int? walletId; // 冷钱包ID(充值)
|
||||
final String? walletAddress; // 钱包地址(充值/提现)
|
||||
final String? withdrawContact; // 提现联系方式
|
||||
final String remark;
|
||||
final String? auditRemark;
|
||||
final String? rejectReason;
|
||||
final String? adminRemark;
|
||||
final DateTime? createTime;
|
||||
final DateTime? auditTime;
|
||||
final DateTime? payTime; // 用户确认打款时间
|
||||
final DateTime? confirmTime; // 管理员确认时间
|
||||
|
||||
OrderFund({
|
||||
required this.id,
|
||||
required this.orderNo,
|
||||
required this.userId,
|
||||
required this.orderType,
|
||||
required this.username,
|
||||
required this.type,
|
||||
required this.amount,
|
||||
required this.status,
|
||||
this.walletId,
|
||||
this.walletAddress,
|
||||
this.withdrawContact,
|
||||
required this.remark,
|
||||
this.auditRemark,
|
||||
this.rejectReason,
|
||||
this.adminRemark,
|
||||
this.createTime,
|
||||
this.auditTime,
|
||||
this.payTime,
|
||||
this.confirmTime,
|
||||
});
|
||||
|
||||
factory OrderFund.fromJson(Map<String, dynamic> json) {
|
||||
@@ -98,42 +112,117 @@ class OrderFund {
|
||||
id: json['id'] as int? ?? 0,
|
||||
orderNo: json['orderNo'] as String? ?? '',
|
||||
userId: json['userId'] as int? ?? 0,
|
||||
orderType: json['orderType'] as int? ?? 1,
|
||||
username: json['username'] as String? ?? '',
|
||||
type: json['type'] as int? ?? 1,
|
||||
amount: json['amount']?.toString() ?? '0.00',
|
||||
status: json['status'] as int? ?? 1,
|
||||
walletId: json['walletId'] as int?,
|
||||
walletAddress: json['walletAddress'] as String?,
|
||||
withdrawContact: json['withdrawContact'] as String?,
|
||||
remark: json['remark']?.toString() ?? '',
|
||||
auditRemark: json['auditRemark']?.toString(),
|
||||
rejectReason: json['rejectReason'] as String?,
|
||||
adminRemark: json['adminRemark'] as String?,
|
||||
createTime: json['createTime'] != null
|
||||
? DateTime.tryParse(json['createTime'])
|
||||
: null,
|
||||
auditTime: json['auditTime'] != null
|
||||
? DateTime.tryParse(json['auditTime'])
|
||||
payTime: json['payTime'] != null
|
||||
? DateTime.tryParse(json['payTime'])
|
||||
: null,
|
||||
confirmTime: json['confirmTime'] != null
|
||||
? DateTime.tryParse(json['confirmTime'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// 订单类型文字
|
||||
String get orderTypeText => orderType == 1 ? '充值' : '提现';
|
||||
String get typeText => type == 1 ? '充值' : '提现';
|
||||
|
||||
/// 状态文字
|
||||
/// 状态文字 (根据类型区分)
|
||||
String get statusText {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '待审核';
|
||||
case 2:
|
||||
return '已通过';
|
||||
case 3:
|
||||
return '已拒绝';
|
||||
case 4:
|
||||
return '已取消';
|
||||
default:
|
||||
return '未知';
|
||||
if (type == 1) {
|
||||
// 充值状态
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '待付款';
|
||||
case 2:
|
||||
return '待确认';
|
||||
case 3:
|
||||
return '已完成';
|
||||
case 4:
|
||||
return '已驳回';
|
||||
case 5:
|
||||
return '已取消';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
} else {
|
||||
// 提现状态
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '待审批';
|
||||
case 2:
|
||||
return '已完成';
|
||||
case 3:
|
||||
return '已驳回';
|
||||
case 4:
|
||||
return '已取消';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 是否为充值
|
||||
bool get isDeposit => orderType == 1;
|
||||
bool get isDeposit => type == 1;
|
||||
|
||||
/// 是否可取消
|
||||
bool get canCancel => status == 1;
|
||||
/// 充值: 仅待付款可取消
|
||||
/// 提现: 仅待审批可取消
|
||||
bool get canCancel {
|
||||
if (type == 1) {
|
||||
return status == 1; // 充值待付款
|
||||
} else {
|
||||
return status == 1; // 提现待审批
|
||||
}
|
||||
}
|
||||
|
||||
/// 是否可确认打款 (仅充值待付款)
|
||||
bool get canConfirmPay => type == 1 && status == 1;
|
||||
}
|
||||
|
||||
/// 冷钱包模型
|
||||
class ColdWallet {
|
||||
final int id;
|
||||
final String name;
|
||||
final String address;
|
||||
final String network;
|
||||
final bool isDefault;
|
||||
final int status; // 0=禁用, 1=启用
|
||||
final DateTime? createTime;
|
||||
|
||||
ColdWallet({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.address,
|
||||
required this.network,
|
||||
required this.isDefault,
|
||||
required this.status,
|
||||
this.createTime,
|
||||
});
|
||||
|
||||
factory ColdWallet.fromJson(Map<String, dynamic> json) {
|
||||
return ColdWallet(
|
||||
id: json['id'] as int? ?? 0,
|
||||
name: json['name'] as String? ?? '',
|
||||
address: json['address'] as String? ?? '',
|
||||
network: json['network'] as String? ?? 'TRC20',
|
||||
isDefault: json['isDefault'] as bool? ?? false,
|
||||
status: json['status'] as int? ?? 1,
|
||||
createTime: json['createTime'] != null
|
||||
? DateTime.tryParse(json['createTime'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
bool get isEnabled => status == 1;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,23 @@ class FundService {
|
||||
|
||||
FundService(this._client);
|
||||
|
||||
/// 获取默认钱包地址
|
||||
Future<ApiResponse<ColdWallet>> getDefaultWallet() async {
|
||||
final response = await _client.get<Map<String, dynamic>>(
|
||||
ApiEndpoints.defaultWallet,
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
return ApiResponse.success(
|
||||
ColdWallet.fromJson(response.data!),
|
||||
response.message,
|
||||
);
|
||||
}
|
||||
return ApiResponse.fail(response.message ?? '获取钱包地址失败');
|
||||
}
|
||||
|
||||
/// 申请充值
|
||||
/// 返回包含 orderNo, amount, status, walletAddress, walletNetwork 的信息
|
||||
Future<ApiResponse<Map<String, dynamic>>> deposit({
|
||||
required String amount,
|
||||
String? remark,
|
||||
@@ -22,15 +38,27 @@ class FundService {
|
||||
);
|
||||
}
|
||||
|
||||
/// 用户确认已打款
|
||||
Future<ApiResponse<void>> confirmPay(String orderNo) async {
|
||||
return _client.post<void>(
|
||||
ApiEndpoints.confirmPay,
|
||||
data: {'orderNo': orderNo},
|
||||
);
|
||||
}
|
||||
|
||||
/// 申请提现
|
||||
Future<ApiResponse<Map<String, dynamic>>> withdraw({
|
||||
required String amount,
|
||||
required String withdrawAddress,
|
||||
String? withdrawContact,
|
||||
String? remark,
|
||||
}) async {
|
||||
return _client.post<Map<String, dynamic>>(
|
||||
ApiEndpoints.withdraw,
|
||||
data: {
|
||||
'amount': amount,
|
||||
'withdrawAddress': withdrawAddress,
|
||||
if (withdrawContact != null) 'withdrawContact': withdrawContact,
|
||||
if (remark != null) 'remark': remark,
|
||||
},
|
||||
);
|
||||
@@ -62,19 +90,9 @@ class FundService {
|
||||
);
|
||||
}
|
||||
|
||||
/// 获取充提订单详情
|
||||
Future<ApiResponse<OrderFund>> getOrderDetail(String orderNo) async {
|
||||
final response = await _client.get<Map<String, dynamic>>(
|
||||
ApiEndpoints.fundOrders,
|
||||
queryParameters: {'orderNo': orderNo},
|
||||
);
|
||||
|
||||
if (response.success && response.data != null) {
|
||||
return ApiResponse.success(
|
||||
OrderFund.fromJson(response.data!),
|
||||
response.message,
|
||||
);
|
||||
}
|
||||
return ApiResponse.fail(response.message ?? '获取订单详情失败');
|
||||
/// 解析充提记录列表
|
||||
List<OrderFund> parseOrderList(List<dynamic>? list) {
|
||||
if (list == null) return [];
|
||||
return list.map((e) => OrderFund.fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../data/models/account_models.dart';
|
||||
import '../data/models/order_models.dart';
|
||||
import '../data/services/asset_service.dart';
|
||||
import '../data/services/fund_service.dart';
|
||||
import '../core/network/dio_client.dart';
|
||||
@@ -13,8 +14,10 @@ class AssetProvider extends ChangeNotifier {
|
||||
AccountFund? _fundAccount;
|
||||
List<AccountTrade> _tradeAccounts = [];
|
||||
List<AccountFlow> _flows = [];
|
||||
List<OrderFund> _fundOrders = [];
|
||||
bool _isLoading = false;
|
||||
bool _isLoadingFlows = false;
|
||||
bool _isLoadingOrders = false;
|
||||
String? _error;
|
||||
|
||||
AssetProvider(this._assetService, this._fundService);
|
||||
@@ -25,8 +28,10 @@ class AssetProvider extends ChangeNotifier {
|
||||
List<AccountTrade> get tradeAccounts => _tradeAccounts;
|
||||
List<AccountTrade> get holdings => _tradeAccounts;
|
||||
List<AccountFlow> get flows => _flows;
|
||||
List<OrderFund> get fundOrders => _fundOrders;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isLoadingFlows => _isLoadingFlows;
|
||||
bool get isLoadingOrders => _isLoadingOrders;
|
||||
String? get error => _error;
|
||||
|
||||
/// 加载资产总览
|
||||
@@ -120,8 +125,8 @@ class AssetProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 充值
|
||||
Future<ApiResponse<void>> deposit({required String amount, String? remark}) async {
|
||||
/// 充值 - 返回订单详情包含钱包地址
|
||||
Future<ApiResponse<Map<String, dynamic>>> deposit({required String amount, String? remark}) async {
|
||||
try {
|
||||
final response = await _fundService.deposit(amount: amount, remark: remark);
|
||||
if (response.success) {
|
||||
@@ -134,10 +139,33 @@ class AssetProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 提现
|
||||
Future<ApiResponse<void>> withdraw({required String amount, String? remark}) async {
|
||||
/// 确认已打款
|
||||
Future<ApiResponse<void>> confirmPay(String orderNo) async {
|
||||
try {
|
||||
final response = await _fundService.withdraw(amount: amount, remark: remark);
|
||||
final response = await _fundService.confirmPay(orderNo);
|
||||
if (response.success) {
|
||||
await loadFundOrders();
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
return ApiResponse.fail('确认打款失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 提现
|
||||
Future<ApiResponse<Map<String, dynamic>>> withdraw({
|
||||
required String amount,
|
||||
required String withdrawAddress,
|
||||
String? withdrawContact,
|
||||
String? remark,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _fundService.withdraw(
|
||||
amount: amount,
|
||||
withdrawAddress: withdrawAddress,
|
||||
withdrawContact: withdrawContact,
|
||||
remark: remark,
|
||||
);
|
||||
if (response.success) {
|
||||
await loadOverview();
|
||||
await loadFundAccount();
|
||||
@@ -148,6 +176,43 @@ class AssetProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// 加载充提订单
|
||||
Future<void> loadFundOrders({int? type, int pageNum = 1, int pageSize = 20}) async {
|
||||
_isLoadingOrders = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final response = await _fundService.getOrders(
|
||||
type: type,
|
||||
pageNum: pageNum,
|
||||
pageSize: pageSize,
|
||||
);
|
||||
if (response.success && response.data != null) {
|
||||
final list = response.data!['list'] as List?;
|
||||
_fundOrders = _fundService.parseOrderList(list);
|
||||
}
|
||||
} catch (_) {
|
||||
// 忽略错误
|
||||
}
|
||||
|
||||
_isLoadingOrders = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 取消订单
|
||||
Future<ApiResponse<void>> cancelOrder(String orderNo) async {
|
||||
try {
|
||||
final response = await _fundService.cancelOrder(orderNo);
|
||||
if (response.success) {
|
||||
await loadFundOrders();
|
||||
await loadFundAccount();
|
||||
}
|
||||
return response;
|
||||
} catch (e) {
|
||||
return ApiResponse.fail('取消订单失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// 刷新所有资产数据
|
||||
Future<void> refreshAll() async {
|
||||
await Future.wait([
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../orders/fund_orders_page.dart';
|
||||
|
||||
/// 资产页面 - 使用 shadcn_ui 现代化设计
|
||||
class AssetPage extends StatefulWidget {
|
||||
@@ -201,9 +203,38 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'USDT余额',
|
||||
style: theme.textTheme.muted,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'USDT余额',
|
||||
style: theme.textTheme.muted,
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const FundOrdersPage()),
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'充提记录',
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.primary,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
size: 14,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
@@ -378,28 +409,241 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
}
|
||||
|
||||
void _showDepositDialog(AssetProvider provider) {
|
||||
_showActionDialog(
|
||||
title: '充值',
|
||||
hint: '请输入充值金额(USDT)',
|
||||
onSubmit: (amount) async {
|
||||
final response = await provider.deposit(amount: amount);
|
||||
if (mounted) {
|
||||
_showResult(response.success ? '申请成功' : '申请失败', response.message);
|
||||
}
|
||||
},
|
||||
final amountController = TextEditingController();
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: const Text('充值'),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShadInputFormField(
|
||||
id: 'amount',
|
||||
controller: amountController,
|
||||
placeholder: const Text('请输入充值金额(USDT)'),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('下一步'),
|
||||
onPressed: () async {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
Navigator.of(context).pop();
|
||||
// 提交充值申请
|
||||
final response = await provider.deposit(amount: amountController.text);
|
||||
if (mounted) {
|
||||
if (response.success && response.data != null) {
|
||||
// 显示钱包地址
|
||||
_showDepositResultDialog(response.data!);
|
||||
} else {
|
||||
_showResult('申请失败', response.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示充值结果 - 包含钱包地址
|
||||
void _showDepositResultDialog(Map<String, dynamic> data) {
|
||||
final orderNo = data['orderNo'] as String? ?? '';
|
||||
final amount = data['amount']?.toString() ?? '0.00';
|
||||
final walletAddress = data['walletAddress'] as String? ?? '';
|
||||
final walletNetwork = data['walletNetwork'] as String? ?? 'TRC20';
|
||||
final assetProvider = context.read<AssetProvider>();
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: const Text('充值申请成功'),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('订单号: $orderNo', style: const TextStyle(fontSize: 12)),
|
||||
const SizedBox(height: 8),
|
||||
Text('充值金额: $amount USDT', style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
const Text('请向以下地址转账:', style: TextStyle(fontSize: 12)),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
walletAddress,
|
||||
style: const TextStyle(fontFamily: 'monospace', fontSize: 12),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(LucideIcons.copy, size: 18),
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: walletAddress));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('地址已复制到剪贴板')),
|
||||
);
|
||||
},
|
||||
tooltip: '复制地址',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('网络: $walletNetwork', style: const TextStyle(fontSize: 12, color: Colors.grey)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'转账完成后请点击"已打款"按钮确认',
|
||||
style: TextStyle(fontSize: 12, color: Colors.orange),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('稍后确认'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('已打款'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final response = await assetProvider.confirmPay(orderNo);
|
||||
if (mounted) {
|
||||
_showResult(
|
||||
response.success ? '确认成功' : '确认失败',
|
||||
response.success ? '请等待管理员审核' : response.message,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showWithdrawDialog(AssetProvider provider) {
|
||||
_showActionDialog(
|
||||
title: '提现',
|
||||
hint: '请输入提现金额(USDT)',
|
||||
onSubmit: (amount) async {
|
||||
final response = await provider.withdraw(amount: amount);
|
||||
if (mounted) {
|
||||
_showResult(response.success ? '申请成功' : '申请失败', response.message);
|
||||
}
|
||||
},
|
||||
final amountController = TextEditingController();
|
||||
final addressController = TextEditingController();
|
||||
final contactController = TextEditingController();
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
final fund = provider.fundAccount;
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: const Text('提现'),
|
||||
child: SingleChildScrollView(
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (fund != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(
|
||||
'可用余额: ${fund.balance} USDT',
|
||||
style: const TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
ShadInputFormField(
|
||||
id: 'amount',
|
||||
controller: amountController,
|
||||
placeholder: const Text('请输入提现金额(USDT)'),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ShadInputFormField(
|
||||
id: 'address',
|
||||
controller: addressController,
|
||||
placeholder: const Text('请输入提现地址'),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入提现地址';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ShadInputFormField(
|
||||
id: 'contact',
|
||||
controller: contactController,
|
||||
placeholder: const Text('联系方式(可选)'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('提交'),
|
||||
onPressed: () async {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
Navigator.of(context).pop();
|
||||
final response = await provider.withdraw(
|
||||
amount: amountController.text,
|
||||
withdrawAddress: addressController.text,
|
||||
withdrawContact: contactController.text.isNotEmpty ? contactController.text : null,
|
||||
);
|
||||
if (mounted) {
|
||||
_showResult(
|
||||
response.success ? '申请成功' : '申请失败',
|
||||
response.success ? '请等待管理员审批' : response.message,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -502,59 +746,7 @@ class _AssetPageState extends State<AssetPage> with AutomaticKeepAliveClientMixi
|
||||
);
|
||||
}
|
||||
|
||||
void _showActionDialog({
|
||||
required String title,
|
||||
required String hint,
|
||||
required Function(String) onSubmit,
|
||||
}) {
|
||||
final controller = TextEditingController();
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: Text(title),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: ShadInputFormField(
|
||||
id: 'amount',
|
||||
controller: controller,
|
||||
placeholder: Text(hint),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
onPressed: () async {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
Navigator.of(context).pop();
|
||||
onSubmit(controller.text);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showResult(String title, String? message) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog.alert(
|
||||
|
||||
@@ -391,9 +391,81 @@ class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin
|
||||
}
|
||||
|
||||
void _showWithdraw() {
|
||||
_showActionDialog('提现', '请输入提现金额(USDT)', (amount) {
|
||||
context.read<AssetProvider>().withdraw(amount: amount);
|
||||
});
|
||||
final amountController = TextEditingController();
|
||||
final addressController = TextEditingController();
|
||||
final contactController = TextEditingController();
|
||||
final formKey = GlobalKey<ShadFormState>();
|
||||
|
||||
showShadDialog(
|
||||
context: context,
|
||||
builder: (context) => ShadDialog(
|
||||
title: const Text('提现'),
|
||||
child: ShadForm(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShadInputFormField(
|
||||
id: 'amount',
|
||||
placeholder: const Text('请输入提现金额(USDT)'),
|
||||
controller: amountController,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入金额';
|
||||
}
|
||||
final amount = double.tryParse(value);
|
||||
if (amount == null || amount <= 0) {
|
||||
return '请输入有效金额';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ShadInputFormField(
|
||||
id: 'address',
|
||||
placeholder: const Text('请输入提现地址'),
|
||||
controller: addressController,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入提现地址';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ShadInputFormField(
|
||||
id: 'contact',
|
||||
placeholder: const Text('联系方式(可选)'),
|
||||
controller: contactController,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ShadButton.outline(
|
||||
child: const Text('取消'),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
ShadButton(
|
||||
child: const Text('确认'),
|
||||
onPressed: () {
|
||||
if (formKey.currentState!.saveAndValidate()) {
|
||||
final amount = amountController.text.trim();
|
||||
final address = addressController.text.trim();
|
||||
final contact = contactController.text.trim();
|
||||
Navigator.of(context).pop();
|
||||
context.read<AssetProvider>().withdraw(
|
||||
amount: amount,
|
||||
withdrawAddress: address,
|
||||
withdrawContact: contact.isEmpty ? null : contact,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTransfer() {
|
||||
|
||||
403
flutter_monisuo/lib/ui/pages/orders/fund_orders_page.dart
Normal file
403
flutter_monisuo/lib/ui/pages/orders/fund_orders_page.dart
Normal file
@@ -0,0 +1,403 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../../data/models/order_models.dart';
|
||||
|
||||
/// 充提订单页面
|
||||
class FundOrdersPage extends StatefulWidget {
|
||||
const FundOrdersPage({super.key});
|
||||
|
||||
@override
|
||||
State<FundOrdersPage> createState() => _FundOrdersPageState();
|
||||
}
|
||||
|
||||
class _FundOrdersPageState extends State<FundOrdersPage> {
|
||||
int _activeTab = 0; // 0=全部, 1=充值, 2=提现
|
||||
|
||||
// 颜色常量
|
||||
static const upColor = Color(0xFF00C853);
|
||||
static const downColor = Color(0xFFFF5252);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_loadData();
|
||||
});
|
||||
}
|
||||
|
||||
void _loadData() {
|
||||
final type = _activeTab == 0 ? null : _activeTab;
|
||||
context.read<AssetProvider>().loadFundOrders(type: type);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('充提记录'),
|
||||
backgroundColor: theme.colorScheme.background,
|
||||
elevation: 0,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
_buildTabs(),
|
||||
Expanded(child: _buildOrderList()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTabs() {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
_buildTab('全部', 0),
|
||||
const SizedBox(width: 12),
|
||||
_buildTab('充值', 1),
|
||||
const SizedBox(width: 12),
|
||||
_buildTab('提现', 2),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTab(String label, int index) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isActive = _activeTab == index;
|
||||
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (_activeTab != index) {
|
||||
setState(() => _activeTab = index);
|
||||
_loadData();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: isActive ? theme.colorScheme.primary : theme.colorScheme.card,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: isActive ? theme.colorScheme.primary : theme.colorScheme.border,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: isActive ? Colors.white : theme.colorScheme.mutedForeground,
|
||||
fontWeight: isActive ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOrderList() {
|
||||
return Consumer<AssetProvider>(
|
||||
builder: (context, provider, _) {
|
||||
final orders = provider.fundOrders;
|
||||
final isLoading = provider.isLoadingOrders;
|
||||
|
||||
if (isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (orders.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.inbox,
|
||||
size: 64,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'暂无订单记录',
|
||||
style: TextStyle(color: Colors.grey[600]),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async => _loadData(),
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: orders.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) {
|
||||
return _buildOrderCard(orders[index]);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOrderCard(OrderFund order) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeposit = order.isDeposit;
|
||||
|
||||
return ShadCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: isDeposit
|
||||
? upColor.withValues(alpha: 0.1)
|
||||
: downColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
order.typeText,
|
||||
style: TextStyle(
|
||||
color: isDeposit ? upColor : downColor,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_buildStatusBadge(order),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
order.orderNo,
|
||||
style: const TextStyle(fontSize: 11, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${isDeposit ? '+' : '-'}${order.amount} USDT',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isDeposit ? upColor : downColor,
|
||||
),
|
||||
),
|
||||
if (order.canCancel || order.canConfirmPay)
|
||||
Row(
|
||||
children: [
|
||||
if (order.canConfirmPay)
|
||||
ShadButton.outline(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: () => _confirmPay(order),
|
||||
child: const Text('已打款'),
|
||||
),
|
||||
if (order.canCancel) ...[
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.destructive(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: () => _cancelOrder(order),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// 显示地址信息
|
||||
if (order.walletAddress != null) ...[
|
||||
const Divider(),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${isDeposit ? '充值地址' : '提现地址'}: ',
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
order.walletAddress!,
|
||||
style: const TextStyle(fontSize: 11, fontFamily: 'monospace'),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: order.walletAddress!));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('地址已复制')),
|
||||
);
|
||||
},
|
||||
child: Icon(LucideIcons.copy, size: 14, color: Colors.grey[600]),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (order.withdrawContact != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'联系方式: ${order.withdrawContact}',
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'创建: ${_formatTime(order.createTime)}',
|
||||
style: const TextStyle(fontSize: 11, color: Colors.grey),
|
||||
),
|
||||
if (order.rejectReason != null)
|
||||
Expanded(
|
||||
child: Text(
|
||||
'驳回: ${order.rejectReason}',
|
||||
style: const TextStyle(fontSize: 11, color: downColor),
|
||||
textAlign: TextAlign.right,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusBadge(OrderFund order) {
|
||||
Color bgColor;
|
||||
Color textColor;
|
||||
|
||||
// 根据类型和状态设置颜色
|
||||
if (order.type == 1) {
|
||||
// 充值状态
|
||||
switch (order.status) {
|
||||
case 1: // 待付款
|
||||
case 2: // 待确认
|
||||
bgColor = Colors.orange.withValues(alpha: 0.1);
|
||||
textColor = Colors.orange;
|
||||
break;
|
||||
case 3: // 已完成
|
||||
bgColor = upColor.withValues(alpha: 0.1);
|
||||
textColor = upColor;
|
||||
break;
|
||||
default: // 已驳回/已取消
|
||||
bgColor = downColor.withValues(alpha: 0.1);
|
||||
textColor = downColor;
|
||||
}
|
||||
} else {
|
||||
// 提现状态
|
||||
switch (order.status) {
|
||||
case 1: // 待审批
|
||||
bgColor = Colors.orange.withValues(alpha: 0.1);
|
||||
textColor = Colors.orange;
|
||||
break;
|
||||
case 2: // 已完成
|
||||
bgColor = upColor.withValues(alpha: 0.1);
|
||||
textColor = upColor;
|
||||
break;
|
||||
default: // 已驳回/已取消
|
||||
bgColor = downColor.withValues(alpha: 0.1);
|
||||
textColor = downColor;
|
||||
}
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
order.statusText,
|
||||
style: TextStyle(fontSize: 11, color: textColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatTime(DateTime? time) {
|
||||
if (time == null) return '-';
|
||||
return '${time.year}-${time.month.toString().padLeft(2, '0')}-${time.day.toString().padLeft(2, '0')} '
|
||||
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _confirmPay(OrderFund order) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('确认已打款'),
|
||||
content: const Text('确认您已完成向指定地址的转账?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text('确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && mounted) {
|
||||
final response = await context.read<AssetProvider>().confirmPay(order.orderNo);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(response.success ? '确认成功,请等待审核' : response.message ?? '确认失败')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _cancelOrder(OrderFund order) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('取消订单'),
|
||||
content: Text('确定要取消订单 ${order.orderNo} 吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('返回'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
style: TextButton.styleFrom(foregroundColor: downColor),
|
||||
child: const Text('确定取消'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && mounted) {
|
||||
final response = await context.read<AssetProvider>().cancelOrder(order.orderNo);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(response.success ? '订单已取消' : response.message ?? '取消失败')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,16 @@ export function useAuth() {
|
||||
|
||||
try {
|
||||
const result = await loginMutation.mutateAsync({ username, password })
|
||||
console.log('Login result:', result)
|
||||
|
||||
if (result.code === '0000' && result.data) {
|
||||
console.log('Setting token and adminInfo...')
|
||||
authStore.setToken(result.data.token)
|
||||
authStore.setAdminInfo(result.data.adminInfo)
|
||||
console.log('isLogin after setToken:', authStore.isLogin)
|
||||
|
||||
const redirect = router.currentRoute.value.query.redirect as string
|
||||
console.log('Redirecting to:', redirect || '/monisuo/dashboard')
|
||||
if (!redirect || redirect.startsWith('//')) {
|
||||
toHome()
|
||||
}
|
||||
@@ -42,10 +46,12 @@ export function useAuth() {
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('Login failed:', result.code, result.msg)
|
||||
error.value = result.msg || '登录失败'
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
console.error('Login error:', e)
|
||||
error.value = e.response?.data?.msg || '网络错误,请稍后重试'
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -107,20 +107,68 @@ function formatAmount(amount: number): string {
|
||||
return amount.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
}
|
||||
|
||||
function getStatusVariant(status: number): 'default' | 'secondary' | 'destructive' {
|
||||
if (status === 1)
|
||||
return 'secondary'
|
||||
if (status === 2)
|
||||
return 'default'
|
||||
return 'destructive'
|
||||
// 根据订单类型和状态获取状态样式
|
||||
function getStatusVariant(order: OrderFund): 'default' | 'secondary' | 'destructive' | 'outline' {
|
||||
const { type, status } = order
|
||||
// 充值状态: 1=待付款, 2=待确认, 3=已完成, 4=已驳回, 5=已取消
|
||||
// 提现状态: 1=待审批, 2=已完成, 3=已驳回, 4=已取消
|
||||
if (type === 1) {
|
||||
// 充值
|
||||
if (status === 1) return 'secondary' // 待付款
|
||||
if (status === 2) return 'default' // 待确认
|
||||
if (status === 3) return 'default' // 已完成
|
||||
return 'destructive' // 已驳回/已取消
|
||||
}
|
||||
else {
|
||||
// 提现
|
||||
if (status === 1) return 'default' // 待审批
|
||||
if (status === 2) return 'default' // 已完成
|
||||
return 'destructive' // 已驳回/已取消
|
||||
}
|
||||
}
|
||||
|
||||
function getStatusText(status: number): string {
|
||||
if (status === 1)
|
||||
return '待审批'
|
||||
if (status === 2)
|
||||
return '已通过'
|
||||
return '已驳回'
|
||||
// 根据订单类型和状态获取状态文本
|
||||
function getStatusText(order: OrderFund): string {
|
||||
const { type, status } = order
|
||||
if (type === 1) {
|
||||
// 充值状态
|
||||
switch (status) {
|
||||
case 1: return '待付款'
|
||||
case 2: return '待确认'
|
||||
case 3: return '已完成'
|
||||
case 4: return '已驳回'
|
||||
case 5: return '已取消'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 提现状态
|
||||
switch (status) {
|
||||
case 1: return '待审批'
|
||||
case 2: return '已完成'
|
||||
case 3: return '已驳回'
|
||||
case 4: return '已取消'
|
||||
default: return '未知'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断订单是否可审批
|
||||
// 充值: 仅待确认(status=2)可审批
|
||||
// 提现: 仅待审批(status=1)可审批
|
||||
function canApprove(order: OrderFund): boolean {
|
||||
if (order.type === 1) {
|
||||
return order.status === 2 // 充值待确认
|
||||
}
|
||||
else {
|
||||
return order.status === 1 // 提现待审批
|
||||
}
|
||||
}
|
||||
|
||||
// 复制到剪贴板
|
||||
function copyToClipboard(text: string) {
|
||||
navigator.clipboard.writeText(text)
|
||||
toast.success('已复制到剪贴板')
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -153,7 +201,11 @@ function getStatusText(status: number): string {
|
||||
<UiTableHead class="text-right">
|
||||
金额
|
||||
</UiTableHead>
|
||||
<UiTableHead>状态</UiTableHead>
|
||||
<UiTableHead class="hidden lg:table-cell">
|
||||
地址/联系方式
|
||||
</UiTableHead>
|
||||
<UiTableHead class="hidden xl:table-cell">
|
||||
时间
|
||||
</UiTableHead>
|
||||
<UiTableHead class="text-right">
|
||||
@@ -163,12 +215,12 @@ function getStatusText(status: number): string {
|
||||
</UiTableHeader>
|
||||
<UiTableBody>
|
||||
<UiTableRow v-if="pendingLoading">
|
||||
<UiTableCell :col-span="6" class="text-center py-8">
|
||||
<UiTableCell :col-span="8" class="text-center py-8">
|
||||
<UiSpinner class="mx-auto" />
|
||||
</UiTableCell>
|
||||
</UiTableRow>
|
||||
<UiTableRow v-else-if="pendingOrders.length === 0">
|
||||
<UiTableCell :col-span="6" class="text-center py-8 text-muted-foreground">
|
||||
<UiTableCell :col-span="8" class="text-center py-8 text-muted-foreground">
|
||||
<Icon icon="lucide:inbox" class="size-8 mx-auto mb-2 opacity-50" />
|
||||
<p>暂无待审批订单</p>
|
||||
</UiTableCell>
|
||||
@@ -187,8 +239,27 @@ function getStatusText(status: number): string {
|
||||
<UiTableCell class="text-right font-mono font-medium">
|
||||
¥{{ formatAmount(order.amount) }}
|
||||
</UiTableCell>
|
||||
<UiTableCell class="hidden lg:table-cell text-muted-foreground text-sm">
|
||||
{{ order.createTime }}
|
||||
<UiTableCell>
|
||||
<UiBadge :variant="getStatusVariant(order)">
|
||||
{{ getStatusText(order) }}
|
||||
</UiBadge>
|
||||
</UiTableCell>
|
||||
<UiTableCell class="hidden lg:table-cell">
|
||||
<div v-if="order.walletAddress" class="max-w-[150px]">
|
||||
<div class="font-mono text-xs truncate" :title="order.walletAddress">
|
||||
{{ order.walletAddress }}
|
||||
</div>
|
||||
<div v-if="order.withdrawContact" class="text-xs text-muted-foreground">
|
||||
{{ order.withdrawContact }}
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="text-muted-foreground">-</span>
|
||||
</UiTableCell>
|
||||
<UiTableCell class="hidden xl:table-cell text-muted-foreground text-sm">
|
||||
<div>{{ order.createTime }}</div>
|
||||
<div v-if="order.payTime" class="text-xs">
|
||||
打款: {{ order.payTime }}
|
||||
</div>
|
||||
</UiTableCell>
|
||||
<UiTableCell class="text-right">
|
||||
<div class="flex justify-end gap-1">
|
||||
@@ -196,6 +267,7 @@ function getStatusText(status: number): string {
|
||||
<Icon icon="lucide:eye" class="size-4" />
|
||||
</UiButton>
|
||||
<UiButton
|
||||
v-if="canApprove(order)"
|
||||
size="sm"
|
||||
:disabled="approveMutation.isPending.value"
|
||||
@click="openApproveDialog(order, 2)"
|
||||
@@ -203,6 +275,7 @@ function getStatusText(status: number): string {
|
||||
通过
|
||||
</UiButton>
|
||||
<UiButton
|
||||
v-if="canApprove(order)"
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
:disabled="approveMutation.isPending.value"
|
||||
@@ -233,19 +306,38 @@ function getStatusText(status: number): string {
|
||||
{{ order.username }}
|
||||
</div>
|
||||
</div>
|
||||
<UiBadge :variant="order.type === 1 ? 'default' : 'destructive'">
|
||||
{{ order.type === 1 ? '充值' : '提现' }}
|
||||
</UiBadge>
|
||||
<div class="text-right">
|
||||
<UiBadge :variant="order.type === 1 ? 'default' : 'destructive'" class="mb-1">
|
||||
{{ order.type === 1 ? '充值' : '提现' }}
|
||||
</UiBadge>
|
||||
<UiBadge :variant="getStatusVariant(order)" class="block">
|
||||
{{ getStatusText(order) }}
|
||||
</UiBadge>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 pt-3 border-t">
|
||||
<div class="text-xl font-mono font-bold" :class="order.type === 1 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400'">
|
||||
{{ order.type === 1 ? '+' : '-' }}¥{{ formatAmount(order.amount) }}
|
||||
</div>
|
||||
<!-- 显示地址信息 -->
|
||||
<div v-if="order.walletAddress" class="mt-2 text-sm">
|
||||
<span class="text-muted-foreground">{{ order.type === 1 ? '充值地址' : '提现地址' }}:</span>
|
||||
<div class="font-mono text-xs break-all mt-1 flex items-center gap-1">
|
||||
{{ order.walletAddress }}
|
||||
<Icon icon="lucide:copy" class="size-3 cursor-pointer" @click="copyToClipboard(order.walletAddress!)" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="order.withdrawContact" class="text-sm text-muted-foreground mt-1">
|
||||
联系方式: {{ order.withdrawContact }}
|
||||
</div>
|
||||
<div class="text-sm text-muted-foreground mt-1">
|
||||
{{ order.createTime }}
|
||||
</div>
|
||||
<div v-if="order.payTime" class="text-xs text-muted-foreground">
|
||||
确认打款: {{ order.payTime }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 flex gap-2">
|
||||
<div v-if="canApprove(order)" class="mt-3 flex gap-2">
|
||||
<UiButton size="sm" class="flex-1" @click="openApproveDialog(order, 2)">
|
||||
通过
|
||||
</UiButton>
|
||||
@@ -253,6 +345,11 @@ function getStatusText(status: number): string {
|
||||
驳回
|
||||
</UiButton>
|
||||
</div>
|
||||
<div v-else class="mt-3">
|
||||
<UiButton size="sm" variant="outline" class="w-full" @click="viewOrderDetail(order)">
|
||||
查看详情
|
||||
</UiButton>
|
||||
</div>
|
||||
</UiCard>
|
||||
</template>
|
||||
<div v-else class="text-center py-8 text-muted-foreground">
|
||||
@@ -297,14 +394,20 @@ function getStatusText(status: number): string {
|
||||
全部
|
||||
</UiSelectItem>
|
||||
<UiSelectItem :value="1">
|
||||
待审批
|
||||
待付款/待审批
|
||||
</UiSelectItem>
|
||||
<UiSelectItem :value="2">
|
||||
已通过
|
||||
待确认/已完成
|
||||
</UiSelectItem>
|
||||
<UiSelectItem :value="3">
|
||||
已完成
|
||||
</UiSelectItem>
|
||||
<UiSelectItem :value="4">
|
||||
已驳回
|
||||
</UiSelectItem>
|
||||
<UiSelectItem :value="5">
|
||||
已取消
|
||||
</UiSelectItem>
|
||||
</UiSelectContent>
|
||||
</UiSelect>
|
||||
</div>
|
||||
@@ -328,6 +431,9 @@ function getStatusText(status: number): string {
|
||||
金额
|
||||
</UiTableHead>
|
||||
<UiTableHead>状态</UiTableHead>
|
||||
<UiTableHead class="hidden lg:table-cell">
|
||||
地址
|
||||
</UiTableHead>
|
||||
<UiTableHead class="hidden xl:table-cell">
|
||||
时间
|
||||
</UiTableHead>
|
||||
@@ -341,12 +447,12 @@ function getStatusText(status: number): string {
|
||||
</UiTableHeader>
|
||||
<UiTableBody>
|
||||
<UiTableRow v-if="allLoading">
|
||||
<UiTableCell :col-span="8" class="text-center py-8">
|
||||
<UiTableCell :col-span="9" class="text-center py-8">
|
||||
<UiSpinner class="mx-auto" />
|
||||
</UiTableCell>
|
||||
</UiTableRow>
|
||||
<UiTableRow v-else-if="allOrders.length === 0">
|
||||
<UiTableCell :col-span="8" class="text-center py-8 text-muted-foreground">
|
||||
<UiTableCell :col-span="9" class="text-center py-8 text-muted-foreground">
|
||||
暂无数据
|
||||
</UiTableCell>
|
||||
</UiTableRow>
|
||||
@@ -364,14 +470,25 @@ function getStatusText(status: number): string {
|
||||
¥{{ formatAmount(order.amount) }}
|
||||
</UiTableCell>
|
||||
<UiTableCell>
|
||||
<UiBadge :variant="getStatusVariant(order.status)">
|
||||
{{ getStatusText(order.status) }}
|
||||
<UiBadge :variant="getStatusVariant(order)">
|
||||
{{ getStatusText(order) }}
|
||||
</UiBadge>
|
||||
</UiTableCell>
|
||||
<UiTableCell class="hidden xl:table-cell text-muted-foreground text-sm">
|
||||
{{ order.createTime }}
|
||||
<UiTableCell class="hidden lg:table-cell">
|
||||
<div v-if="order.walletAddress" class="max-w-[120px]">
|
||||
<div class="font-mono text-xs truncate" :title="order.walletAddress">
|
||||
{{ order.walletAddress }}
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="text-muted-foreground">-</span>
|
||||
</UiTableCell>
|
||||
<UiTableCell class="hidden lg:table-cell text-sm text-muted-foreground max-w-[150px] truncate">
|
||||
<UiTableCell class="hidden xl:table-cell text-muted-foreground text-sm">
|
||||
<div>{{ order.createTime }}</div>
|
||||
<div v-if="order.confirmTime" class="text-xs">
|
||||
完成: {{ order.confirmTime }}
|
||||
</div>
|
||||
</UiTableCell>
|
||||
<UiTableCell class="hidden lg:table-cell text-sm text-muted-foreground max-w-[120px] truncate">
|
||||
{{ order.rejectReason || order.adminRemark || '-' }}
|
||||
</UiTableCell>
|
||||
<UiTableCell class="text-right">
|
||||
@@ -404,8 +521,8 @@ function getStatusText(status: number): string {
|
||||
<UiBadge :variant="order.type === 1 ? 'default' : 'destructive'" class="mb-1">
|
||||
{{ order.type === 1 ? '充值' : '提现' }}
|
||||
</UiBadge>
|
||||
<UiBadge :variant="getStatusVariant(order.status)" class="block">
|
||||
{{ getStatusText(order.status) }}
|
||||
<UiBadge :variant="getStatusVariant(order)" class="block">
|
||||
{{ getStatusText(order) }}
|
||||
</UiBadge>
|
||||
</div>
|
||||
</div>
|
||||
@@ -413,9 +530,23 @@ function getStatusText(status: number): string {
|
||||
<div class="text-xl font-mono font-bold">
|
||||
¥{{ formatAmount(order.amount) }}
|
||||
</div>
|
||||
<!-- 显示地址信息 -->
|
||||
<div v-if="order.walletAddress" class="mt-2 text-sm">
|
||||
<span class="text-muted-foreground">{{ order.type === 1 ? '充值地址' : '提现地址' }}:</span>
|
||||
<div class="font-mono text-xs break-all mt-1 flex items-center gap-1">
|
||||
{{ order.walletAddress }}
|
||||
<Icon icon="lucide:copy" class="size-3 cursor-pointer" @click="copyToClipboard(order.walletAddress!)" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="order.withdrawContact" class="text-sm text-muted-foreground mt-1">
|
||||
联系方式: {{ order.withdrawContact }}
|
||||
</div>
|
||||
<div class="text-sm text-muted-foreground mt-1">
|
||||
{{ order.createTime }}
|
||||
</div>
|
||||
<div v-if="order.confirmTime" class="text-xs text-muted-foreground">
|
||||
完成: {{ order.confirmTime }}
|
||||
</div>
|
||||
<div v-if="order.rejectReason || order.adminRemark" class="text-sm text-muted-foreground mt-1">
|
||||
备注: {{ order.rejectReason || order.adminRemark }}
|
||||
</div>
|
||||
@@ -489,7 +620,7 @@ function getStatusText(status: number): string {
|
||||
|
||||
<!-- 订单详情弹窗 -->
|
||||
<UiDialog v-model:open="showDetailDialog">
|
||||
<UiDialogContent class="max-w-md">
|
||||
<UiDialogContent class="max-w-md max-h-[90vh] overflow-y-auto">
|
||||
<UiDialogHeader>
|
||||
<UiDialogTitle>订单详情</UiDialogTitle>
|
||||
</UiDialogHeader>
|
||||
@@ -529,11 +660,33 @@ function getStatusText(status: number): string {
|
||||
状态
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<UiBadge :variant="getStatusVariant(currentOrder.status)">
|
||||
{{ getStatusText(currentOrder.status) }}
|
||||
<UiBadge :variant="getStatusVariant(currentOrder)">
|
||||
{{ getStatusText(currentOrder) }}
|
||||
</UiBadge>
|
||||
</div>
|
||||
|
||||
<!-- 充值/提现地址 -->
|
||||
<div class="text-muted-foreground">
|
||||
{{ currentOrder.type === 1 ? '充值地址' : '提现地址' }}
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
<div v-if="currentOrder.walletAddress" class="flex items-start gap-1">
|
||||
<span class="font-mono text-xs break-all">{{ currentOrder.walletAddress }}</span>
|
||||
<Icon icon="lucide:copy" class="size-4 cursor-pointer flex-shrink-0" @click="copyToClipboard(currentOrder.walletAddress!)" />
|
||||
</div>
|
||||
<span v-else class="text-muted-foreground">-</span>
|
||||
</div>
|
||||
|
||||
<!-- 提现联系方式 -->
|
||||
<template v-if="currentOrder.type === 2 && currentOrder.withdrawContact">
|
||||
<div class="text-muted-foreground">
|
||||
联系方式
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
{{ currentOrder.withdrawContact }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="text-muted-foreground">
|
||||
创建时间
|
||||
</div>
|
||||
@@ -541,6 +694,26 @@ function getStatusText(status: number): string {
|
||||
{{ currentOrder.createTime }}
|
||||
</div>
|
||||
|
||||
<!-- 用户确认打款时间(充值) -->
|
||||
<template v-if="currentOrder.type === 1 && currentOrder.payTime">
|
||||
<div class="text-muted-foreground">
|
||||
确认打款
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
{{ currentOrder.payTime }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 管理员确认时间 -->
|
||||
<template v-if="currentOrder.confirmTime">
|
||||
<div class="text-muted-foreground">
|
||||
完成时间
|
||||
</div>
|
||||
<div class="col-span-2">
|
||||
{{ currentOrder.confirmTime }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-if="currentOrder.rejectReason">
|
||||
<div class="text-muted-foreground text-red-500">
|
||||
驳回原因
|
||||
@@ -561,14 +734,14 @@ function getStatusText(status: number): string {
|
||||
</div>
|
||||
</div>
|
||||
<UiDialogFooter>
|
||||
<template v-if="currentOrder?.status === 1">
|
||||
<template v-if="currentOrder && canApprove(currentOrder)">
|
||||
<UiButton variant="outline" @click="showDetailDialog = false">
|
||||
关闭
|
||||
</UiButton>
|
||||
<UiButton @click="openApproveDialog(currentOrder!, 2); showDetailDialog = false">
|
||||
<UiButton @click="openApproveDialog(currentOrder, 2); showDetailDialog = false">
|
||||
通过
|
||||
</UiButton>
|
||||
<UiButton variant="destructive" @click="openApproveDialog(currentOrder!, 3); showDetailDialog = false">
|
||||
<UiButton variant="destructive" @click="openApproveDialog(currentOrder, 3); showDetailDialog = false">
|
||||
驳回
|
||||
</UiButton>
|
||||
</template>
|
||||
@@ -581,23 +754,69 @@ function getStatusText(status: number): string {
|
||||
|
||||
<!-- 审批弹窗 -->
|
||||
<UiDialog v-model:open="showApproveDialog">
|
||||
<UiDialogContent class="max-w-md">
|
||||
<UiDialogContent class="max-w-md max-h-[90vh] overflow-y-auto">
|
||||
<UiDialogHeader>
|
||||
<UiDialogTitle>{{ approveStatus === 2 ? '通过订单' : '驳回订单' }}</UiDialogTitle>
|
||||
</UiDialogHeader>
|
||||
<div v-if="currentOrder" class="grid gap-4 py-4">
|
||||
<div class="p-3 rounded-lg bg-muted/50 text-sm">
|
||||
<div class="text-muted-foreground">
|
||||
订单号
|
||||
<div class="p-3 rounded-lg bg-muted/50 text-sm space-y-2">
|
||||
<div>
|
||||
<div class="text-muted-foreground">
|
||||
订单号
|
||||
</div>
|
||||
<div class="font-mono">
|
||||
{{ currentOrder.orderNo }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="font-mono">
|
||||
{{ currentOrder.orderNo }}
|
||||
<div>
|
||||
<div class="text-muted-foreground">
|
||||
用户
|
||||
</div>
|
||||
<div class="font-medium">
|
||||
{{ currentOrder.username }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-muted-foreground mt-2">
|
||||
金额
|
||||
<div>
|
||||
<div class="text-muted-foreground">
|
||||
类型
|
||||
</div>
|
||||
<div>
|
||||
<UiBadge :variant="currentOrder.type === 1 ? 'default' : 'destructive'">
|
||||
{{ currentOrder.type === 1 ? '充值' : '提现' }}
|
||||
</UiBadge>
|
||||
</div>
|
||||
</div>
|
||||
<div class="font-mono font-bold text-lg">
|
||||
¥{{ formatAmount(currentOrder.amount) }}
|
||||
<div>
|
||||
<div class="text-muted-foreground">
|
||||
金额
|
||||
</div>
|
||||
<div class="font-mono font-bold text-lg">
|
||||
¥{{ formatAmount(currentOrder.amount) }}
|
||||
</div>
|
||||
</div>
|
||||
<!-- 显示地址信息 -->
|
||||
<div v-if="currentOrder.walletAddress">
|
||||
<div class="text-muted-foreground">
|
||||
{{ currentOrder.type === 1 ? '充值地址' : '提现地址' }}
|
||||
</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<span class="font-mono text-xs break-all">{{ currentOrder.walletAddress }}</span>
|
||||
<Icon icon="lucide:copy" class="size-4 cursor-pointer flex-shrink-0" @click="copyToClipboard(currentOrder.walletAddress!)" />
|
||||
</div>
|
||||
</div>
|
||||
<!-- 提现联系方式 -->
|
||||
<div v-if="currentOrder.type === 2 && currentOrder.withdrawContact">
|
||||
<div class="text-muted-foreground">
|
||||
联系方式
|
||||
</div>
|
||||
<div>{{ currentOrder.withdrawContact }}</div>
|
||||
</div>
|
||||
<!-- 充值确认打款时间 -->
|
||||
<div v-if="currentOrder.type === 1 && currentOrder.payTime">
|
||||
<div class="text-muted-foreground">
|
||||
确认打款时间
|
||||
</div>
|
||||
<div>{{ currentOrder.payTime }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="approveStatus === 3" class="grid gap-2">
|
||||
@@ -615,7 +834,7 @@ function getStatusText(status: number): string {
|
||||
</UiButton>
|
||||
<UiButton
|
||||
:variant="approveStatus === 3 ? 'destructive' : 'default'"
|
||||
:disabled="approveMutation.isPending.value"
|
||||
:disabled="approveMutation.isPending.value || (approveStatus === 3 && !rejectReason.trim())"
|
||||
@click="handleApprove"
|
||||
>
|
||||
<UiSpinner v-if="approveMutation.isPending.value" class="mr-2" />
|
||||
|
||||
320
monisuo-admin/src/pages/monisuo/wallets.vue
Normal file
320
monisuo-admin/src/pages/monisuo/wallets.vue
Normal file
@@ -0,0 +1,320 @@
|
||||
<script lang="ts" setup>
|
||||
import { Icon } from '@iconify/vue'
|
||||
import { toast } from 'vue-sonner'
|
||||
|
||||
import type { ColdWallet } from '@/services/api/monisuo-admin.api'
|
||||
|
||||
import { BasicPage } from '@/components/global-layout'
|
||||
import {
|
||||
useGetWalletListQuery,
|
||||
useCreateWalletMutation,
|
||||
useUpdateWalletMutation,
|
||||
useDeleteWalletMutation,
|
||||
useSetDefaultWalletMutation,
|
||||
useToggleWalletStatusMutation,
|
||||
} from '@/services/api/monisuo-admin.api'
|
||||
|
||||
const { data, isLoading, refetch } = useGetWalletListQuery()
|
||||
const createMutation = useCreateWalletMutation()
|
||||
const updateMutation = useUpdateWalletMutation()
|
||||
const deleteMutation = useDeleteWalletMutation()
|
||||
const setDefaultMutation = useSetDefaultWalletMutation()
|
||||
const toggleStatusMutation = useToggleWalletStatusMutation()
|
||||
|
||||
const wallets = computed(() => data.value?.data || [])
|
||||
|
||||
const editingWallet = ref<Partial<ColdWallet>>({})
|
||||
const showEditDialog = ref(false)
|
||||
const isEditing = ref(false)
|
||||
|
||||
// 表单验证
|
||||
const formErrors = ref<{ name?: string, address?: string }>({})
|
||||
|
||||
function validateForm(): boolean {
|
||||
formErrors.value = {}
|
||||
|
||||
if (!editingWallet.value.name?.trim()) {
|
||||
formErrors.value.name = '请输入钱包名称'
|
||||
return false
|
||||
}
|
||||
if (!editingWallet.value.address?.trim()) {
|
||||
formErrors.value.address = '请输入钱包地址'
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function openCreateDialog() {
|
||||
editingWallet.value = { network: 'TRC20', status: 1, isDefault: false }
|
||||
isEditing.value = false
|
||||
formErrors.value = {}
|
||||
showEditDialog.value = true
|
||||
}
|
||||
|
||||
function openEditDialog(wallet: ColdWallet) {
|
||||
editingWallet.value = { ...wallet }
|
||||
isEditing.value = true
|
||||
formErrors.value = {}
|
||||
showEditDialog.value = true
|
||||
}
|
||||
|
||||
async function saveWallet() {
|
||||
if (!validateForm())
|
||||
return
|
||||
|
||||
try {
|
||||
if (isEditing.value) {
|
||||
await updateMutation.mutateAsync(editingWallet.value)
|
||||
toast.success('钱包已更新')
|
||||
}
|
||||
else {
|
||||
await createMutation.mutateAsync(editingWallet.value)
|
||||
toast.success('钱包已创建')
|
||||
}
|
||||
showEditDialog.value = false
|
||||
refetch()
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e.response?.data?.msg || '操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function setDefault(wallet: ColdWallet) {
|
||||
if (wallet.isDefault)
|
||||
return
|
||||
|
||||
try {
|
||||
await setDefaultMutation.mutateAsync({ id: wallet.id })
|
||||
toast.success(`已将 ${wallet.name} 设为默认`)
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e.response?.data?.msg || '设置失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleStatus(wallet: ColdWallet) {
|
||||
try {
|
||||
await toggleStatusMutation.mutateAsync({ id: wallet.id })
|
||||
toast.success(wallet.status === 1 ? '已禁用' : '已启用')
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e.response?.data?.msg || '操作失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteWallet(wallet: ColdWallet) {
|
||||
if (!confirm(`确定删除钱包 ${wallet.name} 吗?`))
|
||||
return
|
||||
|
||||
try {
|
||||
await deleteMutation.mutateAsync({ id: wallet.id })
|
||||
toast.success('钱包已删除')
|
||||
}
|
||||
catch (e: any) {
|
||||
toast.error(e.response?.data?.msg || '删除失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BasicPage title="冷钱包管理" description="配置充值收款地址">
|
||||
<template #actions>
|
||||
<UiButton @click="openCreateDialog">
|
||||
<Icon icon="lucide:plus" class="mr-2 h-4 w-4" />
|
||||
新增钱包
|
||||
</UiButton>
|
||||
</template>
|
||||
|
||||
<!-- PC端表格 -->
|
||||
<UiCard class="hidden md:block overflow-x-auto p-4">
|
||||
<UiTable v-if="!isLoading">
|
||||
<UiTableHeader>
|
||||
<UiTableRow>
|
||||
<UiTableHead>名称</UiTableHead>
|
||||
<UiTableHead>地址</UiTableHead>
|
||||
<UiTableHead>网络</UiTableHead>
|
||||
<UiTableHead>默认</UiTableHead>
|
||||
<UiTableHead>状态</UiTableHead>
|
||||
<UiTableHead>操作</UiTableHead>
|
||||
</UiTableRow>
|
||||
</UiTableHeader>
|
||||
<UiTableBody>
|
||||
<UiTableRow v-for="wallet in wallets" :key="wallet.id">
|
||||
<UiTableCell class="font-medium">{{ wallet.name }}</UiTableCell>
|
||||
<UiTableCell class="font-mono text-xs max-w-[200px] truncate">
|
||||
{{ wallet.address }}
|
||||
</UiTableCell>
|
||||
<UiTableCell>{{ wallet.network }}</UiTableCell>
|
||||
<UiTableCell>
|
||||
<UiBadge v-if="wallet.isDefault" variant="default">
|
||||
默认
|
||||
</UiBadge>
|
||||
<span v-else class="text-muted-foreground">-</span>
|
||||
</UiTableCell>
|
||||
<UiTableCell>
|
||||
<UiBadge :variant="wallet.status === 1 ? 'default' : 'destructive'">
|
||||
{{ wallet.status === 1 ? '启用' : '禁用' }}
|
||||
</UiBadge>
|
||||
</UiTableCell>
|
||||
<UiTableCell>
|
||||
<div class="flex gap-2">
|
||||
<UiButton size="sm" variant="ghost" @click="openEditDialog(wallet)">
|
||||
编辑
|
||||
</UiButton>
|
||||
<UiButton
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
:disabled="wallet.isDefault"
|
||||
@click="setDefault(wallet)"
|
||||
>
|
||||
设为默认
|
||||
</UiButton>
|
||||
<UiButton
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
@click="toggleStatus(wallet)"
|
||||
>
|
||||
{{ wallet.status === 1 ? '禁用' : '启用' }}
|
||||
</UiButton>
|
||||
<UiButton
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
@click="deleteWallet(wallet)"
|
||||
>
|
||||
删除
|
||||
</UiButton>
|
||||
</div>
|
||||
</UiTableCell>
|
||||
</UiTableRow>
|
||||
<UiTableRow v-if="wallets.length === 0">
|
||||
<UiTableCell colspan="6" class="text-center text-muted-foreground py-8">
|
||||
暂无钱包数据
|
||||
</UiTableCell>
|
||||
</UiTableRow>
|
||||
</UiTableBody>
|
||||
</UiTable>
|
||||
<div v-else class="flex justify-center py-8">
|
||||
<Icon icon="lucide:loader-2" class="h-6 w-6 animate-spin" />
|
||||
</div>
|
||||
</UiCard>
|
||||
|
||||
<!-- 移动端卡片 -->
|
||||
<div class="md:hidden space-y-4">
|
||||
<div v-if="isLoading" class="flex justify-center py-8">
|
||||
<Icon icon="lucide:loader-2" class="h-6 w-6 animate-spin" />
|
||||
</div>
|
||||
<template v-else-if="wallets.length > 0">
|
||||
<UiCard v-for="wallet in wallets" :key="wallet.id" class="p-4">
|
||||
<div class="flex justify-between items-start mb-2">
|
||||
<div>
|
||||
<div class="font-medium">{{ wallet.name }}</div>
|
||||
<div class="text-xs text-muted-foreground">{{ wallet.network }}</div>
|
||||
</div>
|
||||
<div class="flex gap-1">
|
||||
<UiBadge v-if="wallet.isDefault" variant="default" class="text-xs">
|
||||
默认
|
||||
</UiBadge>
|
||||
<UiBadge :variant="wallet.status === 1 ? 'default' : 'destructive'" class="text-xs">
|
||||
{{ wallet.status === 1 ? '启用' : '禁用' }}
|
||||
</UiBadge>
|
||||
</div>
|
||||
</div>
|
||||
<div class="font-mono text-xs break-all mb-3 text-muted-foreground">
|
||||
{{ wallet.address }}
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<UiButton size="sm" variant="outline" @click="openEditDialog(wallet)">
|
||||
编辑
|
||||
</UiButton>
|
||||
<UiButton
|
||||
size="sm"
|
||||
variant="outline"
|
||||
:disabled="wallet.isDefault"
|
||||
@click="setDefault(wallet)"
|
||||
>
|
||||
设为默认
|
||||
</UiButton>
|
||||
<UiButton
|
||||
size="sm"
|
||||
variant="outline"
|
||||
@click="toggleStatus(wallet)"
|
||||
>
|
||||
{{ wallet.status === 1 ? '禁用' : '启用' }}
|
||||
</UiButton>
|
||||
<UiButton
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
@click="deleteWallet(wallet)"
|
||||
>
|
||||
删除
|
||||
</UiButton>
|
||||
</div>
|
||||
</UiCard>
|
||||
</template>
|
||||
<div v-else class="text-center text-muted-foreground py-8">
|
||||
暂无钱包数据
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<UiDialog v-model:open="showEditDialog">
|
||||
<UiDialogContent>
|
||||
<UiDialogHeader>
|
||||
<UiDialogTitle>{{ isEditing ? '编辑钱包' : '新增钱包' }}</UiDialogTitle>
|
||||
</UiDialogHeader>
|
||||
<div class="grid gap-4 py-4">
|
||||
<div class="grid gap-2">
|
||||
<UiLabel>钱包名称 <span class="text-red-500">*</span></UiLabel>
|
||||
<UiInput v-model="editingWallet.name" placeholder="如:主钱包" />
|
||||
<span v-if="formErrors.name" class="text-xs text-red-500">{{ formErrors.name }}</span>
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<UiLabel>钱包地址 <span class="text-red-500">*</span></UiLabel>
|
||||
<UiInput v-model="editingWallet.address" placeholder="TRC20/ERC20 地址" />
|
||||
<span v-if="formErrors.address" class="text-xs text-red-500">{{ formErrors.address }}</span>
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<UiLabel>网络类型</UiLabel>
|
||||
<UiSelect v-model="editingWallet.network">
|
||||
<UiSelectTrigger>
|
||||
<UiSelectValue placeholder="选择网络" />
|
||||
</UiSelectTrigger>
|
||||
<UiSelectContent>
|
||||
<UiSelectItem value="TRC20">
|
||||
TRC20 (波场)
|
||||
</UiSelectItem>
|
||||
<UiSelectItem value="ERC20">
|
||||
ERC20 (以太坊)
|
||||
</UiSelectItem>
|
||||
<UiSelectItem value="BEP20">
|
||||
BEP20 (币安智能链)
|
||||
</UiSelectItem>
|
||||
</UiSelectContent>
|
||||
</UiSelect>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<UiCheckbox
|
||||
:checked="editingWallet.isDefault"
|
||||
@update:checked="editingWallet.isDefault = $event"
|
||||
/>
|
||||
<UiLabel class="cursor-pointer" @click="editingWallet.isDefault = !editingWallet.isDefault">
|
||||
设为默认钱包
|
||||
</UiLabel>
|
||||
</div>
|
||||
</div>
|
||||
<UiDialogFooter>
|
||||
<UiButton variant="outline" @click="showEditDialog = false">
|
||||
取消
|
||||
</UiButton>
|
||||
<UiButton
|
||||
:disabled="createMutation.isPending.value || updateMutation.isPending.value"
|
||||
@click="saveWallet"
|
||||
>
|
||||
{{ isEditing ? '保存' : '创建' }}
|
||||
</UiButton>
|
||||
</UiDialogFooter>
|
||||
</UiDialogContent>
|
||||
</UiDialog>
|
||||
</BasicPage>
|
||||
</template>
|
||||
@@ -16,8 +16,11 @@ export function authGuard(router: Router) {
|
||||
// 检查是否是需要认证的路由
|
||||
const needsAuth = to.meta.auth || AUTH_ROUTES.some(prefix => to.path.startsWith(prefix))
|
||||
|
||||
console.log('[AuthGuard]', to.path, 'needsAuth:', needsAuth, 'isLogin:', unref(isLogin))
|
||||
|
||||
// 如果页面需要登录但用户未登录,重定向到登录页并记录原始目标页面
|
||||
if (needsAuth && !unref(isLogin) && to.name !== '/auth/sign-in') {
|
||||
console.log('[AuthGuard] Redirecting to login')
|
||||
return {
|
||||
name: '/auth/sign-in',
|
||||
query: { redirect: to.fullPath },
|
||||
|
||||
@@ -57,12 +57,27 @@ export interface OrderFund {
|
||||
username: string
|
||||
type: number // 1: 充值 2: 提现
|
||||
amount: number
|
||||
status: number // 1: 待审批 2: 已通过 3: 已驳回
|
||||
status: number // 充值: 1待付款 2待确认 3已完成 4已驳回 5已取消; 提现: 1待审批 2已完成 3已驳回 4已取消
|
||||
walletId?: number
|
||||
walletAddress?: string
|
||||
withdrawContact?: string
|
||||
payTime?: string
|
||||
confirmTime?: string
|
||||
createTime: string
|
||||
rejectReason?: string
|
||||
adminRemark?: string
|
||||
}
|
||||
|
||||
export interface ColdWallet {
|
||||
id: number
|
||||
name: string
|
||||
address: string
|
||||
network: string
|
||||
isDefault: boolean
|
||||
status: number // 0: 禁用 1: 启用
|
||||
createTime: string
|
||||
}
|
||||
|
||||
export interface FinanceOverview {
|
||||
totalDeposit: number
|
||||
totalWithdraw: number
|
||||
@@ -189,7 +204,7 @@ export function useUpdateCoinStatusMutation() {
|
||||
}
|
||||
|
||||
// Order Management API
|
||||
export function useGetPendingOrdersQuery(params: { pageNum: number, pageSize: number }) {
|
||||
export function useGetPendingOrdersQuery(params: { type?: number, status?: number, pageNum: number, pageSize: number }) {
|
||||
const { axiosInstance } = useAxios()
|
||||
|
||||
return useQuery<ApiResult<{ list: OrderFund[], total: number }>, AxiosError>({
|
||||
@@ -243,6 +258,99 @@ export function useGetFinanceOverviewQuery() {
|
||||
})
|
||||
}
|
||||
|
||||
// Cold Wallet Management API
|
||||
export function useGetWalletListQuery() {
|
||||
const { axiosInstance } = useAxios()
|
||||
|
||||
return useQuery<ApiResult<ColdWallet[]>, AxiosError>({
|
||||
queryKey: ['useGetWalletListQuery'],
|
||||
queryFn: async () => {
|
||||
const response = await axiosInstance.get('/admin/wallet/list')
|
||||
return response.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateWalletMutation() {
|
||||
const { axiosInstance } = useAxios()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<ApiResult<void>, AxiosError, Partial<ColdWallet>>({
|
||||
mutationKey: ['useCreateWalletMutation'],
|
||||
mutationFn: async (wallet) => {
|
||||
const response = await axiosInstance.post('/admin/wallet/create', wallet)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['useGetWalletListQuery'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateWalletMutation() {
|
||||
const { axiosInstance } = useAxios()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<ApiResult<void>, AxiosError, Partial<ColdWallet>>({
|
||||
mutationKey: ['useUpdateWalletMutation'],
|
||||
mutationFn: async (wallet) => {
|
||||
const response = await axiosInstance.post('/admin/wallet/update', wallet)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['useGetWalletListQuery'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteWalletMutation() {
|
||||
const { axiosInstance } = useAxios()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<ApiResult<void>, AxiosError, { id: number }>({
|
||||
mutationKey: ['useDeleteWalletMutation'],
|
||||
mutationFn: async (params) => {
|
||||
const response = await axiosInstance.post('/admin/wallet/delete', params)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['useGetWalletListQuery'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useSetDefaultWalletMutation() {
|
||||
const { axiosInstance } = useAxios()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<ApiResult<void>, AxiosError, { id: number }>({
|
||||
mutationKey: ['useSetDefaultWalletMutation'],
|
||||
mutationFn: async (params) => {
|
||||
const response = await axiosInstance.post('/admin/wallet/setDefault', params)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['useGetWalletListQuery'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useToggleWalletStatusMutation() {
|
||||
const { axiosInstance } = useAxios()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<ApiResult<void>, AxiosError, { id: number }>({
|
||||
mutationKey: ['useToggleWalletStatusMutation'],
|
||||
mutationFn: async (params) => {
|
||||
const response = await axiosInstance.post('/admin/wallet/toggleStatus', params)
|
||||
return response.data
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['useGetWalletListQuery'] })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// ========== 分析相关 API ==========
|
||||
|
||||
// 盈利分析
|
||||
|
||||
@@ -264,17 +264,22 @@ public class AdminController {
|
||||
|
||||
/**
|
||||
* 待审批订单
|
||||
* 充值待确认(type=1,status=2) + 提现待审批(type=2,status=1)
|
||||
*/
|
||||
@GetMapping("/order/pending")
|
||||
public Result<Map<String, Object>> getPendingOrders(
|
||||
@RequestParam(required = false) Integer type,
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(defaultValue = "1") int pageNum,
|
||||
@RequestParam(defaultValue = "20") int pageSize) {
|
||||
|
||||
IPage<OrderFund> page = fundService.getPendingOrders(pageNum, pageSize);
|
||||
IPage<OrderFund> page = fundService.getPendingOrders(type, status, pageNum, pageSize);
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("list", page.getRecords());
|
||||
data.put("total", page.getTotal());
|
||||
data.put("pageNum", page.getCurrent());
|
||||
data.put("pageSize", page.getSize());
|
||||
return Result.success(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.it.rattan.monisuo.controller;
|
||||
|
||||
import com.it.rattan.monisuo.common.Result;
|
||||
import com.it.rattan.monisuo.entity.ColdWallet;
|
||||
import com.it.rattan.monisuo.service.ColdWalletService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 冷钱包地址接口
|
||||
*/
|
||||
@RestController
|
||||
public class ColdWalletController {
|
||||
|
||||
@Autowired
|
||||
private ColdWalletService coldWalletService;
|
||||
|
||||
/**
|
||||
* 管理端 - 获取钱包列表
|
||||
*/
|
||||
@GetMapping("/admin/wallet/list")
|
||||
public Result<List<ColdWallet>> getList() {
|
||||
List<ColdWallet> list = coldWalletService.getList();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端 - 新增钱包
|
||||
*/
|
||||
@PostMapping("/admin/wallet/create")
|
||||
public Result<Void> create(@RequestBody ColdWallet wallet) {
|
||||
if (wallet.getName() == null || wallet.getName().isEmpty()) {
|
||||
return Result.fail("钱包名称不能为空");
|
||||
}
|
||||
if (wallet.getAddress() == null || wallet.getAddress().isEmpty()) {
|
||||
return Result.fail("钱包地址不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
coldWalletService.create(wallet);
|
||||
return Result.success("创建成功", null);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端 - 更新钱包
|
||||
*/
|
||||
@PostMapping("/admin/wallet/update")
|
||||
public Result<Void> update(@RequestBody ColdWallet wallet) {
|
||||
if (wallet.getId() == null) {
|
||||
return Result.fail("钱包ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
coldWalletService.update(wallet);
|
||||
return Result.success("更新成功", null);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端 - 删除钱包
|
||||
*/
|
||||
@PostMapping("/admin/wallet/delete")
|
||||
public Result<Void> delete(@RequestBody Map<String, Long> params) {
|
||||
Long id = params.get("id");
|
||||
if (id == null) {
|
||||
return Result.fail("钱包ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
coldWalletService.delete(id);
|
||||
return Result.success("删除成功", null);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端 - 设置默认钱包
|
||||
*/
|
||||
@PostMapping("/admin/wallet/setDefault")
|
||||
public Result<Void> setDefault(@RequestBody Map<String, Long> params) {
|
||||
Long id = params.get("id");
|
||||
if (id == null) {
|
||||
return Result.fail("钱包ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
coldWalletService.setDefault(id);
|
||||
return Result.success("设置成功", null);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理端 - 切换状态
|
||||
*/
|
||||
@PostMapping("/admin/wallet/toggleStatus")
|
||||
public Result<Void> toggleStatus(@RequestBody Map<String, Long> params) {
|
||||
Long id = params.get("id");
|
||||
if (id == null) {
|
||||
return Result.fail("钱包ID不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
coldWalletService.toggleStatus(id);
|
||||
return Result.success("操作成功", null);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户端 - 获取默认钱包地址
|
||||
*/
|
||||
@GetMapping("/api/wallet/default")
|
||||
public Result<Map<String, Object>> getDefaultWallet() {
|
||||
ColdWallet wallet = coldWalletService.getDefaultWallet();
|
||||
if (wallet == null) {
|
||||
return Result.fail("系统暂未配置充值地址");
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("id", wallet.getId());
|
||||
result.put("name", wallet.getName());
|
||||
result.put("address", wallet.getAddress());
|
||||
result.put("network", wallet.getNetwork());
|
||||
return Result.success(result);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,30 @@ public class FundController {
|
||||
|
||||
try {
|
||||
Map<String, Object> result = fundService.deposit(userId, amount, remark);
|
||||
return Result.success("申请成功,等待审批", result);
|
||||
return Result.success("申请成功,请完成打款", result);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户确认已打款
|
||||
*/
|
||||
@PostMapping("/confirmPay")
|
||||
public Result<Void> confirmPay(@RequestBody Map<String, String> params) {
|
||||
Long userId = UserContext.getUserId();
|
||||
if (userId == null) {
|
||||
return Result.unauthorized("请先登录");
|
||||
}
|
||||
|
||||
String orderNo = params.get("orderNo");
|
||||
if (orderNo == null || orderNo.isEmpty()) {
|
||||
return Result.fail("订单号不能为空");
|
||||
}
|
||||
|
||||
try {
|
||||
fundService.confirmPay(userId, orderNo);
|
||||
return Result.success("已确认打款,等待审核", null);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
@@ -56,14 +79,20 @@ public class FundController {
|
||||
}
|
||||
|
||||
BigDecimal amount = new BigDecimal(params.get("amount").toString());
|
||||
String withdrawAddress = (String) params.get("withdrawAddress");
|
||||
String withdrawContact = (String) params.get("withdrawContact");
|
||||
String remark = (String) params.get("remark");
|
||||
|
||||
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return Result.fail("提现金额必须大于0");
|
||||
}
|
||||
|
||||
if (withdrawAddress == null || withdrawAddress.isEmpty()) {
|
||||
return Result.fail("请填写提现地址");
|
||||
}
|
||||
|
||||
try {
|
||||
Map<String, Object> result = fundService.withdraw(userId, amount, remark);
|
||||
Map<String, Object> result = fundService.withdraw(userId, amount, withdrawAddress, withdrawContact, remark);
|
||||
return Result.success("申请成功,等待审批", result);
|
||||
} catch (Exception e) {
|
||||
return Result.fail(e.getMessage());
|
||||
|
||||
37
src/main/java/com/it/rattan/monisuo/entity/ColdWallet.java
Normal file
37
src/main/java/com/it/rattan/monisuo/entity/ColdWallet.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.it.rattan.monisuo.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 冷钱包地址实体
|
||||
*/
|
||||
@Data
|
||||
@TableName("cold_wallet")
|
||||
public class ColdWallet {
|
||||
|
||||
/** 主键ID */
|
||||
private Long id;
|
||||
|
||||
/** 钱包名称 */
|
||||
private String name;
|
||||
|
||||
/** 钱包地址 */
|
||||
private String address;
|
||||
|
||||
/** 网络类型: TRC20/ERC20/BEP20等 */
|
||||
private String network;
|
||||
|
||||
/** 是否默认: false-否 true-是 */
|
||||
private Boolean isDefault;
|
||||
|
||||
/** 状态: 0-禁用 1-启用 */
|
||||
private Integer status;
|
||||
|
||||
/** 创建时间 */
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/** 更新时间 */
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -33,9 +33,24 @@ public class OrderFund implements Serializable {
|
||||
/** 金额(USDT) */
|
||||
private BigDecimal amount;
|
||||
|
||||
/** 状态: 1-待审批 2-已完成 3-已驳回 4-已取消 */
|
||||
/** 冷钱包ID(充值) */
|
||||
private Long walletId;
|
||||
|
||||
/** 冷钱包地址(充值)/提现地址 */
|
||||
private String walletAddress;
|
||||
|
||||
/** 提现联系方式 */
|
||||
private String withdrawContact;
|
||||
|
||||
/** 状态: 充值-1待付款2待确认3已完成4已驳回5已取消6充值失败; 提现-1待审批2已完成3已驳回4已取消 */
|
||||
private Integer status;
|
||||
|
||||
/** 用户确认打款时间 */
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/** 管理员确认时间 */
|
||||
private LocalDateTime confirmTime;
|
||||
|
||||
/** 审批管理员ID */
|
||||
private Long approveAdminId;
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.it.rattan.monisuo.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.it.rattan.monisuo.entity.ColdWallet;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 冷钱包地址Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface ColdWalletMapper extends BaseMapper<ColdWallet> {
|
||||
|
||||
/**
|
||||
* 清除所有默认标记
|
||||
*/
|
||||
@Update("UPDATE cold_wallet SET is_default = 0")
|
||||
void clearAllDefault();
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.it.rattan.monisuo.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.it.rattan.monisuo.entity.ColdWallet;
|
||||
import com.it.rattan.monisuo.mapper.ColdWalletMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 冷钱包地址服务
|
||||
*/
|
||||
@Service
|
||||
public class ColdWalletService {
|
||||
|
||||
@Autowired
|
||||
private ColdWalletMapper coldWalletMapper;
|
||||
|
||||
/**
|
||||
* 获取所有钱包列表
|
||||
*/
|
||||
public List<ColdWallet> getList() {
|
||||
LambdaQueryWrapper<ColdWallet> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(ColdWallet::getIsDefault)
|
||||
.orderByDesc(ColdWallet::getCreateTime);
|
||||
return coldWalletMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取启用的钱包列表
|
||||
*/
|
||||
public List<ColdWallet> getEnabledList() {
|
||||
LambdaQueryWrapper<ColdWallet> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ColdWallet::getStatus, 1)
|
||||
.orderByDesc(ColdWallet::getIsDefault)
|
||||
.orderByDesc(ColdWallet::getCreateTime);
|
||||
return coldWalletMapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认钱包
|
||||
*/
|
||||
public ColdWallet getDefaultWallet() {
|
||||
LambdaQueryWrapper<ColdWallet> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ColdWallet::getStatus, 1)
|
||||
.eq(ColdWallet::getIsDefault, true);
|
||||
return coldWalletMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取钱包
|
||||
*/
|
||||
public ColdWallet getById(Long id) {
|
||||
return coldWalletMapper.selectById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增钱包
|
||||
*/
|
||||
@Transactional
|
||||
public void create(ColdWallet wallet) {
|
||||
wallet.setCreateTime(LocalDateTime.now());
|
||||
if (wallet.getStatus() == null) {
|
||||
wallet.setStatus(1);
|
||||
}
|
||||
if (wallet.getIsDefault() == null) {
|
||||
wallet.setIsDefault(false);
|
||||
}
|
||||
|
||||
// 如果设为默认,先清除其他默认
|
||||
if (Boolean.TRUE.equals(wallet.getIsDefault())) {
|
||||
coldWalletMapper.clearAllDefault();
|
||||
}
|
||||
|
||||
coldWalletMapper.insert(wallet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钱包
|
||||
*/
|
||||
@Transactional
|
||||
public void update(ColdWallet wallet) {
|
||||
wallet.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 如果设为默认,先清除其他默认
|
||||
if (Boolean.TRUE.equals(wallet.getIsDefault())) {
|
||||
coldWalletMapper.clearAllDefault();
|
||||
}
|
||||
|
||||
coldWalletMapper.updateById(wallet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除钱包
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
coldWalletMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认钱包
|
||||
*/
|
||||
@Transactional
|
||||
public void setDefault(Long id) {
|
||||
ColdWallet wallet = coldWalletMapper.selectById(id);
|
||||
if (wallet == null) {
|
||||
throw new RuntimeException("钱包不存在");
|
||||
}
|
||||
if (wallet.getStatus() != 1) {
|
||||
throw new RuntimeException("禁用的钱包不能设为默认");
|
||||
}
|
||||
|
||||
// 清除所有默认
|
||||
coldWalletMapper.clearAllDefault();
|
||||
|
||||
// 设置新的默认
|
||||
wallet.setIsDefault(true);
|
||||
wallet.setUpdateTime(LocalDateTime.now());
|
||||
coldWalletMapper.updateById(wallet);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换状态
|
||||
*/
|
||||
public void toggleStatus(Long id) {
|
||||
ColdWallet wallet = coldWalletMapper.selectById(id);
|
||||
if (wallet == null) {
|
||||
throw new RuntimeException("钱包不存在");
|
||||
}
|
||||
|
||||
// 如果是默认钱包要禁用,需要先取消默认
|
||||
if (Boolean.TRUE.equals(wallet.getIsDefault()) && wallet.getStatus() == 1) {
|
||||
wallet.setIsDefault(false);
|
||||
}
|
||||
|
||||
wallet.setStatus(wallet.getStatus() == 1 ? 0 : 1);
|
||||
wallet.setUpdateTime(LocalDateTime.now());
|
||||
coldWalletMapper.updateById(wallet);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.it.rattan.monisuo.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.it.rattan.monisuo.entity.AccountFund;
|
||||
import com.it.rattan.monisuo.entity.ColdWallet;
|
||||
import com.it.rattan.monisuo.entity.OrderFund;
|
||||
import com.it.rattan.monisuo.entity.User;
|
||||
import com.it.rattan.monisuo.mapper.AccountFundMapper;
|
||||
import com.it.rattan.monisuo.mapper.OrderFundMapper;
|
||||
import com.it.rattan.monisuo.mapper.UserMapper;
|
||||
import com.it.rattan.monisuo.util.OrderNoUtil;
|
||||
@@ -19,6 +20,10 @@ import java.util.*;
|
||||
|
||||
/**
|
||||
* 充提服务
|
||||
*
|
||||
* 状态定义:
|
||||
* 充值: 1=待付款, 2=待确认, 3=已完成, 4=已驳回, 5=已取消
|
||||
* 提现: 1=待审批, 2=已完成, 3=已驳回, 4=已取消
|
||||
*/
|
||||
@Service
|
||||
public class FundService {
|
||||
@@ -26,14 +31,20 @@ public class FundService {
|
||||
@Autowired
|
||||
private OrderFundMapper orderFundMapper;
|
||||
|
||||
@Autowired
|
||||
private AccountFundMapper accountFundMapper;
|
||||
|
||||
@Autowired
|
||||
private AssetService assetService;
|
||||
|
||||
@Autowired
|
||||
private ColdWalletService coldWalletService;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 申请充值
|
||||
* 申请充值 - 关联默认冷钱包
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> deposit(Long userId, BigDecimal amount, String remark) {
|
||||
@@ -46,13 +57,21 @@ public class FundService {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
// 获取默认冷钱包
|
||||
ColdWallet wallet = coldWalletService.getDefaultWallet();
|
||||
if (wallet == null) {
|
||||
throw new RuntimeException("系统暂未配置充值地址");
|
||||
}
|
||||
|
||||
OrderFund order = new OrderFund();
|
||||
order.setOrderNo(OrderNoUtil.fundOrderNo());
|
||||
order.setUserId(userId);
|
||||
order.setUsername(user.getUsername());
|
||||
order.setType(1); // 充值
|
||||
order.setAmount(amount);
|
||||
order.setStatus(1); // 待审批
|
||||
order.setStatus(1); // 待付款
|
||||
order.setWalletId(wallet.getId());
|
||||
order.setWalletAddress(wallet.getAddress());
|
||||
order.setRemark(remark);
|
||||
order.setCreateTime(LocalDateTime.now());
|
||||
orderFundMapper.insert(order);
|
||||
@@ -61,29 +80,65 @@ public class FundService {
|
||||
result.put("orderNo", order.getOrderNo());
|
||||
result.put("amount", amount);
|
||||
result.put("status", order.getStatus());
|
||||
result.put("walletAddress", wallet.getAddress());
|
||||
result.put("walletNetwork", wallet.getNetwork());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请提现
|
||||
* 用户确认已打款
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> withdraw(Long userId, BigDecimal amount, String remark) {
|
||||
public void confirmPay(Long userId, String orderNo) {
|
||||
LambdaQueryWrapper<OrderFund> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderFund::getUserId, userId)
|
||||
.eq(OrderFund::getOrderNo, orderNo)
|
||||
.eq(OrderFund::getType, 1) // 仅充值订单
|
||||
.eq(OrderFund::getStatus, 1); // 仅待付款可确认
|
||||
|
||||
OrderFund order = orderFundMapper.selectOne(wrapper);
|
||||
if (order == null) {
|
||||
throw new RuntimeException("订单不存在或状态不可操作");
|
||||
}
|
||||
|
||||
order.setStatus(2); // 待确认
|
||||
order.setPayTime(LocalDateTime.now());
|
||||
order.setUpdateTime(LocalDateTime.now());
|
||||
orderFundMapper.updateById(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请提现 - 冻结余额
|
||||
*/
|
||||
@Transactional
|
||||
public Map<String, Object> withdraw(Long userId, BigDecimal amount, String withdrawAddress,
|
||||
String withdrawContact, String remark) {
|
||||
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
throw new RuntimeException("提现金额必须大于0");
|
||||
}
|
||||
|
||||
if (withdrawAddress == null || withdrawAddress.isEmpty()) {
|
||||
throw new RuntimeException("请填写提现地址");
|
||||
}
|
||||
|
||||
User user = userMapper.selectById(userId);
|
||||
if (user == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
// 检查余额
|
||||
// 检查并冻结余额
|
||||
AccountFund fund = assetService.getOrCreateFundAccount(userId);
|
||||
if (fund.getBalance().compareTo(amount) < 0) {
|
||||
throw new RuntimeException("资金账户余额不足");
|
||||
}
|
||||
|
||||
// 冻结余额
|
||||
fund.setBalance(fund.getBalance().subtract(amount));
|
||||
fund.setFrozen(fund.getFrozen() != null ? fund.getFrozen().add(amount) : amount);
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
accountFundMapper.updateById(fund);
|
||||
|
||||
// 创建订单
|
||||
OrderFund order = new OrderFund();
|
||||
order.setOrderNo(OrderNoUtil.fundOrderNo());
|
||||
order.setUserId(userId);
|
||||
@@ -91,6 +146,8 @@ public class FundService {
|
||||
order.setType(2); // 提现
|
||||
order.setAmount(amount);
|
||||
order.setStatus(1); // 待审批
|
||||
order.setWalletAddress(withdrawAddress);
|
||||
order.setWithdrawContact(withdrawContact);
|
||||
order.setRemark(remark);
|
||||
order.setCreateTime(LocalDateTime.now());
|
||||
orderFundMapper.insert(order);
|
||||
@@ -103,21 +160,38 @@ public class FundService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
* 取消订单 - 仅充值待付款状态可取消
|
||||
*/
|
||||
@Transactional
|
||||
public void cancel(Long userId, String orderNo) {
|
||||
LambdaQueryWrapper<OrderFund> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderFund::getUserId, userId)
|
||||
.eq(OrderFund::getOrderNo, orderNo)
|
||||
.eq(OrderFund::getStatus, 1); // 仅待审批可取消
|
||||
.eq(OrderFund::getOrderNo, orderNo);
|
||||
|
||||
OrderFund order = orderFundMapper.selectOne(wrapper);
|
||||
if (order == null) {
|
||||
throw new RuntimeException("订单不存在或状态不可取消");
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
|
||||
order.setStatus(4); // 已取消
|
||||
// 充值订单仅待付款可取消
|
||||
if (order.getType() == 1 && order.getStatus() != 1) {
|
||||
throw new RuntimeException("当前状态不可取消");
|
||||
}
|
||||
|
||||
// 提现订单仅待审批可取消,需要解冻余额
|
||||
if (order.getType() == 2) {
|
||||
if (order.getStatus() != 1) {
|
||||
throw new RuntimeException("当前状态不可取消");
|
||||
}
|
||||
// 解冻余额
|
||||
AccountFund fund = assetService.getOrCreateFundAccount(userId);
|
||||
fund.setBalance(fund.getBalance().add(order.getAmount()));
|
||||
fund.setFrozen(fund.getFrozen().subtract(order.getAmount()));
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
accountFundMapper.updateById(fund);
|
||||
}
|
||||
|
||||
order.setStatus(5); // 已取消
|
||||
order.setUpdateTime(LocalDateTime.now());
|
||||
orderFundMapper.updateById(order);
|
||||
}
|
||||
@@ -141,11 +215,17 @@ public class FundService {
|
||||
* 获取待审批订单数量
|
||||
*/
|
||||
public int getPendingCount() {
|
||||
return orderFundMapper.countPending();
|
||||
// 充值待确认 + 提现待审批
|
||||
LambdaQueryWrapper<OrderFund> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.and(w -> w.eq(OrderFund::getType, 1).eq(OrderFund::getStatus, 2))
|
||||
.or(w -> w.eq(OrderFund::getType, 2).eq(OrderFund::getStatus, 1));
|
||||
return Math.toIntExact(orderFundMapper.selectCount(wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员审批
|
||||
* 充值: 仅待确认(status=2)可审批
|
||||
* 提现: 仅待审批(status=1)可审批
|
||||
*/
|
||||
@Transactional
|
||||
public void approve(Long adminId, String adminName, String orderNo, Integer status,
|
||||
@@ -157,44 +237,48 @@ public class FundService {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
|
||||
if (order.getStatus() != 1) {
|
||||
throw new RuntimeException("订单已处理");
|
||||
// 充值审批: 仅待确认可审批
|
||||
if (order.getType() == 1 && order.getStatus() != 2) {
|
||||
throw new RuntimeException("该充值订单不可审批,等待用户确认打款");
|
||||
}
|
||||
|
||||
// 提现审批: 仅待审批可审批
|
||||
if (order.getType() == 2 && order.getStatus() != 1) {
|
||||
throw new RuntimeException("该提现订单已处理");
|
||||
}
|
||||
|
||||
AccountFund fund = assetService.getOrCreateFundAccount(order.getUserId());
|
||||
|
||||
if (status == 2) {
|
||||
// 审批通过
|
||||
AccountFund fund = assetService.getOrCreateFundAccount(order.getUserId());
|
||||
|
||||
if (order.getType() == 1) {
|
||||
// 充值:增加余额
|
||||
// 充值通过:增加余额
|
||||
BigDecimal balanceBefore = fund.getBalance();
|
||||
fund.setBalance(fund.getBalance().add(order.getAmount()));
|
||||
fund.setTotalDeposit(fund.getTotalDeposit().add(order.getAmount()));
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
accountFundMapper.updateById(fund);
|
||||
|
||||
// 记录流水
|
||||
assetService.createFlow(order.getUserId(), 1, order.getAmount(),
|
||||
balanceBefore, fund.getBalance(), "USDT", orderNo, "充值");
|
||||
} else {
|
||||
// 提现:扣减余额
|
||||
if (fund.getBalance().compareTo(order.getAmount()) < 0) {
|
||||
throw new RuntimeException("用户余额不足");
|
||||
// 提现通过:从冻结转为扣除,更新累计提现
|
||||
if (fund.getFrozen().compareTo(order.getAmount()) < 0) {
|
||||
throw new RuntimeException("冻结金额不足");
|
||||
}
|
||||
fund.setBalance(fund.getBalance().subtract(order.getAmount()));
|
||||
BigDecimal balanceBefore = fund.getBalance();
|
||||
fund.setFrozen(fund.getFrozen().subtract(order.getAmount()));
|
||||
fund.setTotalWithdraw(fund.getTotalWithdraw().add(order.getAmount()));
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
accountFundMapper.updateById(fund);
|
||||
|
||||
// 记录流水 (负数表示支出)
|
||||
assetService.createFlow(order.getUserId(), 2, order.getAmount().negate(),
|
||||
balanceBefore, fund.getBalance(), "USDT", orderNo, "提现");
|
||||
}
|
||||
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 更新账户
|
||||
LambdaUpdateWrapper<AccountFund> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(AccountFund::getUserId, order.getUserId())
|
||||
.set(AccountFund::getBalance, fund.getBalance())
|
||||
.set(AccountFund::getTotalDeposit, fund.getTotalDeposit())
|
||||
.set(AccountFund::getTotalWithdraw, fund.getTotalWithdraw())
|
||||
.set(AccountFund::getUpdateTime, LocalDateTime.now());
|
||||
assetService.updateFundAccount(updateWrapper);
|
||||
|
||||
// 记录流水
|
||||
int flowType = order.getType() == 1 ? 1 : 2;
|
||||
String remark = order.getType() == 1 ? "充值" : "提现";
|
||||
assetService.createFlow(order.getUserId(), flowType, order.getAmount(),
|
||||
fund.getBalance().subtract(order.getAmount()),
|
||||
fund.getBalance(), "USDT", orderNo, remark);
|
||||
order.setConfirmTime(LocalDateTime.now());
|
||||
|
||||
} else if (status == 3) {
|
||||
// 审批驳回
|
||||
@@ -202,6 +286,19 @@ public class FundService {
|
||||
throw new RuntimeException("请填写驳回原因");
|
||||
}
|
||||
order.setRejectReason(rejectReason);
|
||||
|
||||
if (order.getType() == 2) {
|
||||
// 提现驳回:解冻金额退还
|
||||
BigDecimal balanceBefore = fund.getBalance();
|
||||
fund.setBalance(fund.getBalance().add(order.getAmount()));
|
||||
fund.setFrozen(fund.getFrozen().subtract(order.getAmount()));
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
accountFundMapper.updateById(fund);
|
||||
|
||||
// 记录流水
|
||||
assetService.createFlow(order.getUserId(), 2, order.getAmount(),
|
||||
balanceBefore, fund.getBalance(), "USDT", orderNo, "提现驳回退还");
|
||||
}
|
||||
}
|
||||
|
||||
order.setStatus(status);
|
||||
@@ -215,11 +312,28 @@ public class FundService {
|
||||
|
||||
/**
|
||||
* 获取待审批订单列表
|
||||
* 充值待确认(status=2) + 提现待审批(status=1)
|
||||
*/
|
||||
public IPage<OrderFund> getPendingOrders(int pageNum, int pageSize) {
|
||||
public IPage<OrderFund> getPendingOrders(Integer type, Integer status, int pageNum, int pageSize) {
|
||||
LambdaQueryWrapper<OrderFund> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderFund::getStatus, 1)
|
||||
.orderByAsc(OrderFund::getCreateTime);
|
||||
|
||||
if (type != null && type > 0) {
|
||||
// 指定类型
|
||||
wrapper.eq(OrderFund::getType, type);
|
||||
if (type == 1) {
|
||||
// 充值:待确认
|
||||
wrapper.eq(OrderFund::getStatus, status != null ? status : 2);
|
||||
} else {
|
||||
// 提现:待审批
|
||||
wrapper.eq(OrderFund::getStatus, status != null ? status : 1);
|
||||
}
|
||||
} else {
|
||||
// 不指定类型:充值待确认 + 提现待审批
|
||||
wrapper.and(w -> w.eq(OrderFund::getType, 1).eq(OrderFund::getStatus, 2))
|
||||
.or(w -> w.eq(OrderFund::getType, 2).eq(OrderFund::getStatus, 1));
|
||||
}
|
||||
|
||||
wrapper.orderByAsc(OrderFund::getCreateTime);
|
||||
|
||||
Page<OrderFund> page = new Page<>(pageNum, pageSize);
|
||||
return orderFundMapper.selectPage(page, wrapper);
|
||||
|
||||
@@ -7,6 +7,14 @@ spring:
|
||||
password: JPJ8wYicSGC8aRnk
|
||||
url: jdbc:mysql://8.155.172.147:3306/monisuo?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
hikari:
|
||||
minimum-idle: 5
|
||||
maximum-pool-size: 20
|
||||
idle-timeout: 30000
|
||||
pool-name: MonisuoHikariCP
|
||||
max-lifetime: 1800000
|
||||
connection-timeout: 30000
|
||||
connection-test-query: SELECT 1
|
||||
|
||||
|
||||
#mybatis-plus
|
||||
@@ -18,16 +26,4 @@ bean-searcher:
|
||||
params:
|
||||
pagination:
|
||||
start: 1
|
||||
ignore-case-key:
|
||||
|
||||
|
||||
# mybatisplus代码生成器配置
|
||||
generator:
|
||||
username: root
|
||||
password: 123admin
|
||||
driver: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/spccloud?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
|
||||
#dbTableList: #数据库的表,可多张(自己设置)
|
||||
#- rt_company
|
||||
prefix:
|
||||
rt
|
||||
ignore-case-key:
|
||||
Reference in New Issue
Block a user