|
|
@@ -4,10 +4,12 @@ import { PageRequest } from '../common/dto/page-request'
|
|
|
import { BalanceRecord } from './entities/balance-record.entities'
|
|
|
import { HasRoles } from '../auth/roles.decorator'
|
|
|
import { Role } from '../model/role.enum'
|
|
|
+import { OperationLogService } from '../operation-log/operation-log.service'
|
|
|
+import { OperationType } from '../operation-log/entities/operation-log.entity'
|
|
|
|
|
|
@Controller('balance')
|
|
|
export class BalanceController {
|
|
|
- constructor(private readonly balanceService: BalanceService) {
|
|
|
+ constructor(private readonly balanceService: BalanceService, private readonly operationLogService: OperationLogService) {
|
|
|
}
|
|
|
|
|
|
@Get('/:id')
|
|
|
@@ -20,7 +22,9 @@ export class BalanceController {
|
|
|
if (req.user.roles.includes('user')) {
|
|
|
return
|
|
|
}
|
|
|
- return await this.balanceService.rechargeBalance(req.user.userId, parseInt(id), amount)
|
|
|
+ const balanceRecord = await this.balanceService.rechargeBalance(req.user.userId, parseInt(id), amount)
|
|
|
+ await this.operationLogService.create(req, balanceRecord, 'BalanceRecord', OperationType.INSERT, '余额充值')
|
|
|
+ return 'Recharge success!'
|
|
|
}
|
|
|
|
|
|
@Get('/transfer/:id/:amount')
|
|
|
@@ -28,7 +32,13 @@ export class BalanceController {
|
|
|
if (req.user.roles.includes('user')) {
|
|
|
return
|
|
|
}
|
|
|
- return await this.balanceService.transferBalance(req.user.userId, parseInt(id), amount)
|
|
|
+ const balanceRecord = await this.balanceService.transferBalance(req.user.userId, parseInt(id), amount)
|
|
|
+ if (balanceRecord) {
|
|
|
+ await this.operationLogService.create(req, balanceRecord, 'BalanceRecord', OperationType.INSERT, '余额划转')
|
|
|
+ return 'Transfer success!'
|
|
|
+ } else {
|
|
|
+ return 'Balance not enough!'
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Post('/records')
|
|
|
@@ -40,8 +50,14 @@ export class BalanceController {
|
|
|
}
|
|
|
|
|
|
@Get('/updateRate/:id/:rate')
|
|
|
- async updateRate(@Param('id') id: string, @Param('rate') rate: number) {
|
|
|
- return await this.balanceService.updateRate(parseInt(id), rate)
|
|
|
+ async updateRate(@Req() req, @Param('id') id: string, @Param('rate') rate: number) {
|
|
|
+ const users = await this.balanceService.updateRate(parseInt(id), rate)
|
|
|
+ if (users) {
|
|
|
+ await this.operationLogService.create(req, users, 'Users', OperationType.UPDATE, '修改费率', users.rate)
|
|
|
+ return 'update rate success!'
|
|
|
+ } else {
|
|
|
+ return 'update rate fail!'
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Post('/export')
|