|
|
@@ -15,7 +15,19 @@ export class FinanceService {
|
|
|
}
|
|
|
|
|
|
async create(data: CreateFinanceBody): Promise<Finance> {
|
|
|
- const finance = this.financeRepository.create(data)
|
|
|
+ const finance = this.financeRepository.create({
|
|
|
+ teamId: data.teamId,
|
|
|
+ userId: data.userId,
|
|
|
+ reminderAmount: data.reminderAmount,
|
|
|
+ paymentQrCode: data.paymentQrCode,
|
|
|
+ paymentName: data.paymentName,
|
|
|
+ paymentAccount: data.paymentAccount,
|
|
|
+ bankName: data.bankName,
|
|
|
+ status: data.status || FinanceStatus.PROCESSING,
|
|
|
+ rejectReason: data.rejectReason,
|
|
|
+ remark: data.remark,
|
|
|
+ processedAt: data.processedAt
|
|
|
+ })
|
|
|
return this.financeRepository.save(finance)
|
|
|
}
|
|
|
|
|
|
@@ -33,7 +45,7 @@ export class FinanceService {
|
|
|
*/
|
|
|
private async processImageUrl(imageUrl: string): Promise<string> {
|
|
|
if (!imageUrl) return imageUrl
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 检查是否为OSS链接
|
|
|
if (imageUrl.includes('.oss-') && imageUrl.includes('.aliyuncs.com')) {
|
|
|
@@ -60,7 +72,7 @@ export class FinanceService {
|
|
|
*/
|
|
|
private async processImageUrls(finances: Finance[]): Promise<Finance[]> {
|
|
|
const processedFinances = await Promise.all(
|
|
|
- finances.map(async (finance) => {
|
|
|
+ finances.map(async finance => {
|
|
|
const processedPaymentQrCode = await this.processImageUrl(finance.paymentQrCode)
|
|
|
return {
|
|
|
...finance,
|
|
|
@@ -72,22 +84,30 @@ export class FinanceService {
|
|
|
}
|
|
|
|
|
|
async findAll(query: ListFinanceQuery): Promise<PaginationResponse<Finance>> {
|
|
|
- const { page, size, status, paymentName, bankName, startDate, endDate } = query
|
|
|
-
|
|
|
+ const { page, size, teamId, userId, status, paymentName, bankName, startDate, endDate } = query
|
|
|
+
|
|
|
const where: any = {}
|
|
|
-
|
|
|
+
|
|
|
+ if (teamId) {
|
|
|
+ where.teamId = teamId
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userId) {
|
|
|
+ where.userId = userId
|
|
|
+ }
|
|
|
+
|
|
|
if (status) {
|
|
|
where.status = status
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (paymentName) {
|
|
|
where.paymentName = Like(`%${paymentName}%`)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (bankName) {
|
|
|
where.bankName = Like(`%${bankName}%`)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (startDate && endDate) {
|
|
|
where.createdAt = Between(new Date(startDate), new Date(endDate))
|
|
|
}
|
|
|
@@ -128,11 +148,11 @@ export class FinanceService {
|
|
|
|
|
|
async updateStatus(id: number, status: FinanceStatus, rejectReason?: string): Promise<Finance> {
|
|
|
const updateData: any = { status }
|
|
|
-
|
|
|
+
|
|
|
if (status === FinanceStatus.WITHDRAWN || status === FinanceStatus.REJECTED) {
|
|
|
updateData.processedAt = new Date()
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (status === FinanceStatus.REJECTED && rejectReason) {
|
|
|
updateData.rejectReason = rejectReason
|
|
|
}
|
|
|
@@ -141,7 +161,10 @@ export class FinanceService {
|
|
|
return this.findById(id)
|
|
|
}
|
|
|
|
|
|
- async getStatistics(startDate?: string, endDate?: string): Promise<{
|
|
|
+ async getStatistics(
|
|
|
+ startDate?: string,
|
|
|
+ endDate?: string
|
|
|
+ ): Promise<{
|
|
|
totalAmount: number
|
|
|
totalCount: number
|
|
|
byStatus: Record<FinanceStatus, { amount: number; count: number }>
|
|
|
@@ -149,7 +172,7 @@ export class FinanceService {
|
|
|
processedAmount: number
|
|
|
}> {
|
|
|
const where: any = {}
|
|
|
-
|
|
|
+
|
|
|
if (startDate && endDate) {
|
|
|
where.createdAt = Between(new Date(startDate), new Date(endDate))
|
|
|
}
|
|
|
@@ -176,10 +199,10 @@ export class FinanceService {
|
|
|
records.forEach(record => {
|
|
|
const amount = Number(record.reminderAmount)
|
|
|
statistics.totalAmount += amount
|
|
|
-
|
|
|
+
|
|
|
statistics.byStatus[record.status].amount += amount
|
|
|
statistics.byStatus[record.status].count += 1
|
|
|
-
|
|
|
+
|
|
|
if (record.status === FinanceStatus.PROCESSING) {
|
|
|
statistics.pendingAmount += amount
|
|
|
} else {
|