2026-03-22 00:21:21 +08:00
|
|
|
import '../../core/constants/api_endpoints.dart';
|
2026-03-23 00:43:19 +08:00
|
|
|
import '../../core/network/api_response.dart';
|
2026-03-22 00:21:21 +08:00
|
|
|
import '../../core/network/dio_client.dart';
|
|
|
|
|
import '../models/order_models.dart';
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 充提服務
|
2026-03-22 00:21:21 +08:00
|
|
|
class FundService {
|
|
|
|
|
final DioClient _client;
|
|
|
|
|
|
|
|
|
|
FundService(this._client);
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 獲取默認錢包地址
|
2026-03-22 23:15:23 +08:00
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-07 01:05:05 +08:00
|
|
|
return ApiResponse.fail(response.message ?? '獲取錢包地址失敗');
|
2026-03-22 23:15:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 申請充值
|
2026-03-22 23:15:23 +08:00
|
|
|
/// 返回包含 orderNo, amount, status, walletAddress, walletNetwork 的信息
|
2026-03-22 00:21:21 +08:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 用戶確認已打款
|
2026-03-22 23:15:23 +08:00
|
|
|
Future<ApiResponse<void>> confirmPay(String orderNo) async {
|
|
|
|
|
return _client.post<void>(
|
|
|
|
|
ApiEndpoints.confirmPay,
|
|
|
|
|
data: {'orderNo': orderNo},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 申請提現
|
2026-03-22 00:21:21 +08:00
|
|
|
Future<ApiResponse<Map<String, dynamic>>> withdraw({
|
|
|
|
|
required String amount,
|
2026-03-22 23:15:23 +08:00
|
|
|
required String withdrawAddress,
|
2026-04-05 23:28:38 +08:00
|
|
|
String? network,
|
2026-03-22 23:15:23 +08:00
|
|
|
String? withdrawContact,
|
2026-03-22 00:21:21 +08:00
|
|
|
String? remark,
|
|
|
|
|
}) async {
|
|
|
|
|
return _client.post<Map<String, dynamic>>(
|
|
|
|
|
ApiEndpoints.withdraw,
|
|
|
|
|
data: {
|
|
|
|
|
'amount': amount,
|
2026-03-22 23:15:23 +08:00
|
|
|
'withdrawAddress': withdrawAddress,
|
2026-04-05 23:28:38 +08:00
|
|
|
if (network != null) 'network': network,
|
2026-03-22 23:15:23 +08:00
|
|
|
if (withdrawContact != null) 'withdrawContact': withdrawContact,
|
2026-03-22 00:21:21 +08:00
|
|
|
if (remark != null) 'remark': remark,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 獲取可用的提現網絡列表
|
2026-04-05 23:28:38 +08:00
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-04-07 01:05:05 +08:00
|
|
|
return ApiResponse.fail(response.message ?? '獲取網絡列表失敗');
|
2026-04-05 23:28:38 +08:00
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 取消訂單
|
2026-03-22 00:21:21 +08:00
|
|
|
Future<ApiResponse<void>> cancelOrder(String orderNo) async {
|
|
|
|
|
return _client.post<void>(
|
|
|
|
|
ApiEndpoints.cancelOrder,
|
|
|
|
|
data: {'orderNo': orderNo},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 獲取充提記錄
|
2026-03-22 00:21:21 +08:00
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
/// 解析充提記錄列表
|
2026-03-22 23:15:23 +08:00
|
|
|
List<OrderFund> parseOrderList(List<dynamic>? list) {
|
|
|
|
|
if (list == null) return [];
|
|
|
|
|
return list.map((e) => OrderFund.fromJson(e as Map<String, dynamic>)).toList();
|
2026-03-22 00:21:21 +08:00
|
|
|
}
|
|
|
|
|
}
|