feat: support batch wallet balance changes

This commit is contained in:
2026-07-16 10:22:23 +08:00
parent 8ba51f48c0
commit d037787346
4 changed files with 124 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ import { Student } from '../entities/student.entity';
import { StudentWallet } from '../entities/student-wallet.entity';
import { WalletTransaction } from '../entities/wallet-transaction.entity';
import { In } from 'typeorm';
import { ChangeWalletBalanceDto } from './dto/wallet.dto';
import { BatchChangeWalletBalanceDto, ChangeWalletBalanceDto } from './dto/wallet.dto';
const money = (value: number | string | null | undefined) => Number(Number(value || 0).toFixed(2));
@@ -92,6 +92,20 @@ export class WalletsService {
});
}
async batchChangeBalance(dto: BatchChangeWalletBalanceDto, recordedBy?: number) {
const uniqueStudentIds = Array.from(new Set(dto.studentIds));
const results: Awaited<ReturnType<WalletsService['changeBalance']>>[] = [];
for (const studentId of uniqueStudentIds) {
results.push(await this.changeBalance({
studentId,
amount: dto.amount,
type: dto.type,
description: dto.description,
}, recordedBy));
}
return { count: uniqueStudentIds.length, results };
}
async debitBill(manager: EntityManager, bill: Bill, recordedBy?: number) {
if (bill.status === 'cancelled') return bill;