This commit is contained in:
wchino
2026-06-13 17:38:25 +08:00
parent e7e938f261
commit 7b33d9f9fa
190 changed files with 23222 additions and 4336 deletions

View File

@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../../../shared/prisma/prisma.service';
import { WalletService } from '../../ledger/wallet.service';
import { FundsPostingService } from '../../ledger/funds-posting.service';
import { SystemConfigService } from '../../../shared/config/system-config.service';
import { Decimal } from '@prisma/client/runtime/library';
import { generateBatchNo } from '../../../shared/common/decorators';
@@ -33,7 +33,7 @@ type BetCashbackLine = {
export class CashbackService {
constructor(
private prisma: PrismaService,
private wallet: WalletService,
private funds: FundsPostingService,
private systemConfig: SystemConfigService,
) {}
@@ -498,29 +498,33 @@ export class CashbackService {
}
}
for (const item of batch.items) {
if (item.amount.gt(0)) {
await this.wallet.deposit(
item.userId,
item.amount,
operatorId,
`Cashback batch ${batch.batchNo}`,
batch.batchNo,
'CASHBACK_DEPOSIT',
);
await this.prisma.$transaction(async (tx) => {
for (const item of batch.items) {
if (item.amount.gt(0)) {
await this.funds.deposit({
userId: item.userId,
amount: item.amount,
operatorId,
remark: `Cashback batch ${batch.batchNo}`,
referenceId: batch.batchNo,
transactionType: 'CASHBACK_DEPOSIT',
tx,
businessKey: `cashback:${batch.batchNo}:${item.userId}`,
});
}
}
}
if (betIds.length > 0) {
await this.prisma.bet.updateMany({
where: { id: { in: betIds } },
data: { isCashbacked: true },
if (betIds.length > 0) {
await tx.bet.updateMany({
where: { id: { in: betIds } },
data: { isCashbacked: true },
});
}
await tx.cashbackBatch.update({
where: { id: batchId },
data: { status: 'CONFIRMED', confirmedAt: new Date(), operatorId },
});
}
await this.prisma.cashbackBatch.update({
where: { id: batchId },
data: { status: 'CONFIRMED', confirmedAt: new Date(), operatorId },
});
return { success: true };