123 lines
3.3 KiB
Dart
123 lines
3.3 KiB
Dart
import '../../core/constants/api_endpoints.dart';
|
||
import '../../core/network/api_response.dart';
|
||
import '../../core/network/dio_client.dart';
|
||
import '../models/order_models.dart';
|
||
|
||
/// 充提服務
|
||
class FundService {
|
||
final DioClient _client;
|
||
|
||
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,
|
||
}) async {
|
||
return _client.post<Map<String, dynamic>>(
|
||
ApiEndpoints.deposit,
|
||
data: {
|
||
'amount': amount,
|
||
if (remark != null) 'remark': remark,
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 用戶確認已打款
|
||
Future<ApiResponse<void>> confirmPay(String orderNo) async {
|
||
return _client.post<void>(
|
||
ApiEndpoints.confirmPay,
|
||
data: {'orderNo': orderNo},
|
||
);
|
||
}
|
||
|
||
/// 提现前检查(45天规则)
|
||
Future<ApiResponse<Map<String, dynamic>>> withdrawCheck() async {
|
||
return _client.get<Map<String, dynamic>>(
|
||
ApiEndpoints.withdrawCheck,
|
||
);
|
||
}
|
||
|
||
/// 申請提現
|
||
Future<ApiResponse<Map<String, dynamic>>> withdraw({
|
||
required String amount,
|
||
required String withdrawAddress,
|
||
String? network,
|
||
String? withdrawContact,
|
||
String? remark,
|
||
}) async {
|
||
return _client.post<Map<String, dynamic>>(
|
||
ApiEndpoints.withdraw,
|
||
data: {
|
||
'amount': amount,
|
||
'withdrawAddress': withdrawAddress,
|
||
if (network != null) 'network': network,
|
||
if (withdrawContact != null) 'withdrawContact': withdrawContact,
|
||
if (remark != null) 'remark': remark,
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 獲取可用的提現網絡列表
|
||
Future<ApiResponse<List<String>>> getWalletNetworks() async {
|
||
final response = await _client.get<List<dynamic>>(
|
||
ApiEndpoints.walletNetworks,
|
||
);
|
||
if (response.success && response.data != null) {
|
||
return ApiResponse.success(
|
||
response.data!.cast<String>(),
|
||
response.message,
|
||
);
|
||
}
|
||
return ApiResponse.fail(response.message ?? '獲取網絡列表失敗');
|
||
}
|
||
|
||
/// 取消訂單
|
||
Future<ApiResponse<void>> cancelOrder(String orderNo) async {
|
||
return _client.post<void>(
|
||
ApiEndpoints.cancelOrder,
|
||
data: {'orderNo': orderNo},
|
||
);
|
||
}
|
||
|
||
/// 獲取充提記錄
|
||
Future<ApiResponse<Map<String, dynamic>>> getOrders({
|
||
int? type,
|
||
int pageNum = 1,
|
||
int pageSize = 20,
|
||
}) async {
|
||
final params = <String, dynamic>{
|
||
'pageNum': pageNum,
|
||
'pageSize': pageSize,
|
||
};
|
||
if (type != null) params['type'] = type;
|
||
|
||
return _client.get<Map<String, dynamic>>(
|
||
ApiEndpoints.fundOrders,
|
||
queryParameters: params,
|
||
);
|
||
}
|
||
|
||
/// 解析充提記錄列表
|
||
List<OrderFund> parseOrderList(List<dynamic>? list) {
|
||
if (list == null) return [];
|
||
return list.map((e) => OrderFund.fromJson(e as Map<String, dynamic>)).toList();
|
||
}
|
||
}
|