feat: add student wallet utility billing
This commit is contained in:
44
apps/server/src/wallets/wallets.controller.ts
Normal file
44
apps/server/src/wallets/wallets.controller.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Body, Controller, Get, Post, Query, Request, UseGuards } from '@nestjs/common';
|
||||
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { RequirePermission } from '../auth/decorators/permission.decorator';
|
||||
import { OperationLogsService } from '../operation-logs/operation-logs.service';
|
||||
import { extractRequestInfo } from '../common/request-utils';
|
||||
import { ChangeWalletBalanceDto } from './dto/wallet.dto';
|
||||
import { WalletsService } from './wallets.service';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('wallets')
|
||||
export class WalletsController {
|
||||
constructor(private service: WalletsService, private logService: OperationLogsService) {}
|
||||
|
||||
@Get()
|
||||
@RequirePermission('wallet:view')
|
||||
findAll(@Query('keyword') keyword?: string, @Query('debtOnly') debtOnly?: string) {
|
||||
return this.service.findAll({ keyword, debtOnly: debtOnly === 'true' });
|
||||
}
|
||||
|
||||
@Get('transactions')
|
||||
@RequirePermission('wallet:view')
|
||||
findTransactions(@Query('studentId') studentId: string) {
|
||||
return this.service.findTransactions(Number(studentId));
|
||||
}
|
||||
|
||||
@Post('change-balance')
|
||||
@RequirePermission('wallet:edit')
|
||||
async changeBalance(@Body() dto: ChangeWalletBalanceDto, @Request() req: any) {
|
||||
const result = await this.service.changeBalance(dto, req.user?.id);
|
||||
const { ipAddress, userAgent } = extractRequestInfo(req);
|
||||
await this.logService.log({
|
||||
userId: req.user?.id,
|
||||
username: req.user?.username,
|
||||
module: '学生余额',
|
||||
action: dto.type === 'recharge' ? '余额充值' : '余额调账',
|
||||
targetId: dto.studentId,
|
||||
targetType: 'student_wallet',
|
||||
detail: `金额 ¥${dto.amount}${dto.description ? `,${dto.description}` : ''}`,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user