重构
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Decimal } from '@prisma/client/runtime/library';
|
||||
import {
|
||||
canSelectForParlay,
|
||||
hasDuplicateParlayMatch,
|
||||
isQuarterHandicapOrTotal,
|
||||
PARLAY_MAX_LEGS,
|
||||
PARLAY_MIN_LEGS,
|
||||
@@ -460,13 +459,13 @@ export const SMOKE_TEST_CASES: SmokeTestCaseDef[] = [
|
||||
{
|
||||
id: 'B007',
|
||||
suite: 'betting',
|
||||
name: '同场串关应拒绝',
|
||||
name: '同场串关允许',
|
||||
uatRef: 'B007',
|
||||
run: () => {
|
||||
expectTrue('same match blocked', hasDuplicateParlayMatch(['1', '1']), { matchIds: ['1', '1'] });
|
||||
expectFalse('different matches ok', hasDuplicateParlayMatch(['1', '2', '3']), {
|
||||
matchIds: ['1', '2', '3'],
|
||||
});
|
||||
const first = canSelectForParlay({ marketType: 'FT_1X2', allowParlay: true });
|
||||
const second = canSelectForParlay({ marketType: 'FT_1X2', allowParlay: true });
|
||||
expectTrue('first same-match leg ok', first.ok, { matchId: '1' });
|
||||
expectTrue('second same-match leg ok', second.ok, { matchId: '1' });
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user