import { Controller, Get, Post, Body, UseGuards } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBearerAuth, ApiResponse } from '@nestjs/swagger'; import { WalletApplicationService } from '@/application/services'; import { GetMyWalletQuery } from '@/application/queries'; import { ClaimRewardsCommand, SettleRewardsCommand, RequestWithdrawalCommand } from '@/application/commands'; import { CurrentUser, CurrentUserPayload } from '@/shared/decorators'; import { JwtAuthGuard } from '@/shared/guards/jwt-auth.guard'; import { SettleRewardsDTO, RequestWithdrawalDTO } from '@/api/dto/request'; import { WalletResponseDTO, WithdrawalResponseDTO, WithdrawalListItemDTO } from '@/api/dto/response'; @ApiTags('Wallet') @Controller('wallet') @UseGuards(JwtAuthGuard) @ApiBearerAuth() export class WalletController { constructor(private readonly walletService: WalletApplicationService) {} @Get('my-wallet') @ApiOperation({ summary: '查询我的钱包', description: '获取当前用户的钱包余额、算力和奖励信息' }) @ApiResponse({ status: 200, type: WalletResponseDTO }) async getMyWallet(@CurrentUser() user: CurrentUserPayload): Promise { const query = new GetMyWalletQuery( user.accountSequence.toString(), user.userId, ); return this.walletService.getMyWallet(query); } @Post('claim-rewards') @ApiOperation({ summary: '领取奖励', description: '将待领取的奖励转为可结算状态' }) @ApiResponse({ status: 200, description: '领取成功' }) async claimRewards(@CurrentUser() user: CurrentUserPayload): Promise<{ message: string }> { const command = new ClaimRewardsCommand(user.userId); await this.walletService.claimRewards(command); return { message: 'Rewards claimed successfully' }; } @Post('settle') @ApiOperation({ summary: '结算收益', description: '将可结算的USDT兑换为指定币种' }) @ApiResponse({ status: 200, description: '结算成功' }) async settleRewards( @CurrentUser() user: CurrentUserPayload, @Body() dto: SettleRewardsDTO, ): Promise<{ settlementOrderId: string }> { const command = new SettleRewardsCommand( user.userId, dto.usdtAmount, dto.settleCurrency, ); const orderId = await this.walletService.settleRewards(command); return { settlementOrderId: orderId }; } @Post('withdraw') @ApiOperation({ summary: '申请提现', description: '将USDT提现到指定地址' }) @ApiResponse({ status: 201, type: WithdrawalResponseDTO }) async requestWithdrawal( @CurrentUser() user: CurrentUserPayload, @Body() dto: RequestWithdrawalDTO, ): Promise { const command = new RequestWithdrawalCommand( user.userId, dto.amount, dto.toAddress, dto.chainType, ); return this.walletService.requestWithdrawal(command); } @Get('withdrawals') @ApiOperation({ summary: '查询提现记录', description: '获取用户的提现订单列表' }) @ApiResponse({ status: 200, type: [WithdrawalListItemDTO] }) async getWithdrawals( @CurrentUser() user: CurrentUserPayload, ): Promise { return this.walletService.getWithdrawals(user.userId); } }