feat: enhance configuration and logging for admin services
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
- Updated .env.example to enable Redis Lua for lottery risk pool and added configuration for agent settlement. - Improved AGENTS.md to clarify site operations and admin roles. - Enhanced PHPUnit configuration with memory limit and cache directory settings. - Refactored AdminReportQueryService and related services to utilize LimitedQuery for better data handling and truncation warnings. - Added logging for draw settlement failures in DrawTickService. - Introduced credit preflight checks and reverse bet hold functionality in PlayerCreditService. - Improved risk pool management with new Redis lock handling in RiskPoolService and TicketPlacementService.
This commit is contained in:
@@ -62,6 +62,23 @@ final class PlayerCreditService
|
||||
return CreditAmountScale::majorToMinor($this->availableCredit($player), $currency);
|
||||
}
|
||||
|
||||
/** 逾期/代理线门禁与可用额度预检(不占额)。 */
|
||||
public function assertCreditPreflight(Player $player, int $amountMinor): void
|
||||
{
|
||||
if (! PlayerFundingMode::usesCredit($player) || $amountMinor <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertCreditGuards($player);
|
||||
|
||||
$currency = (string) $player->default_currency;
|
||||
if ($amountMinor > $this->availableCreditMinor($player, $currency)) {
|
||||
throw ValidationException::withMessages([
|
||||
'credit' => ['insufficient'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function holdForBet(Player $player, int $amountMinor): void
|
||||
{
|
||||
if ($amountMinor <= 0) {
|
||||
@@ -73,22 +90,45 @@ final class PlayerCreditService
|
||||
}
|
||||
|
||||
$currency = (string) $player->default_currency;
|
||||
$availableMinor = $this->availableCreditMinor($player, $currency);
|
||||
$majorDelta = CreditAmountScale::minorToMajor($amountMinor, $currency);
|
||||
$now = now();
|
||||
|
||||
$row = DB::table('player_credit_accounts')
|
||||
->where('player_id', $player->id)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if ($row === null) {
|
||||
throw ValidationException::withMessages([
|
||||
'credit' => ['insufficient'],
|
||||
]);
|
||||
}
|
||||
|
||||
$availableMajor = max(
|
||||
0,
|
||||
(int) $row->credit_limit - (int) $row->used_credit - (int) $row->frozen_credit,
|
||||
);
|
||||
$availableMinor = CreditAmountScale::majorToMinor($availableMajor, $currency);
|
||||
if ($amountMinor > $availableMinor) {
|
||||
throw ValidationException::withMessages([
|
||||
'credit' => ['insufficient'],
|
||||
]);
|
||||
}
|
||||
|
||||
$majorDelta = CreditAmountScale::minorToMajor($amountMinor, $currency);
|
||||
|
||||
DB::table('player_credit_accounts')
|
||||
$updated = DB::table('player_credit_accounts')
|
||||
->where('player_id', $player->id)
|
||||
->whereRaw('credit_limit - used_credit - frozen_credit >= ?', [$majorDelta])
|
||||
->update([
|
||||
'used_credit' => DB::raw('used_credit + '.$majorDelta),
|
||||
'updated_at' => now(),
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
if ($updated !== 1) {
|
||||
throw ValidationException::withMessages([
|
||||
'credit' => ['insufficient'],
|
||||
]);
|
||||
}
|
||||
|
||||
DB::table('credit_ledger')->insert([
|
||||
'owner_type' => 'player',
|
||||
'owner_id' => $player->id,
|
||||
@@ -96,8 +136,8 @@ final class PlayerCreditService
|
||||
'reason' => 'bet_hold',
|
||||
'ref_type' => 'bet',
|
||||
'ref_id' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -113,12 +153,13 @@ final class PlayerCreditService
|
||||
|
||||
$currency = (string) $player->default_currency;
|
||||
$majorDelta = CreditAmountScale::minorToMajor($amountMinor, $currency);
|
||||
$now = now();
|
||||
|
||||
DB::table('player_credit_accounts')
|
||||
->where('player_id', $player->id)
|
||||
->update([
|
||||
'used_credit' => DB::raw('used_credit + '.$majorDelta),
|
||||
'updated_at' => now(),
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
DB::table('credit_ledger')->insert([
|
||||
@@ -163,6 +204,16 @@ final class PlayerCreditService
|
||||
return;
|
||||
}
|
||||
|
||||
$this->assertCreditGuards($player);
|
||||
$this->holdForBet($player, $amountMinor);
|
||||
}
|
||||
|
||||
private function assertCreditGuards(Player $player): void
|
||||
{
|
||||
if (! PlayerFundingMode::usesCredit($player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$overdue = DB::table('settlement_bills')
|
||||
->where('owner_type', 'player')
|
||||
->where('owner_id', $player->id)
|
||||
@@ -181,8 +232,6 @@ final class PlayerCreditService
|
||||
AgentOverdueGuard::assertAgentMayGrantCredit($agentNodeId);
|
||||
AgentOverdueGuard::assertAgentLineMayPlaceBet($agentNodeId);
|
||||
}
|
||||
|
||||
$this->holdForBet($player, $amountMinor);
|
||||
}
|
||||
|
||||
public function releaseBetHold(Player $player, int $amountMinor, int $ticketItemId): void
|
||||
@@ -205,6 +254,26 @@ final class PlayerCreditService
|
||||
]);
|
||||
}
|
||||
|
||||
public function reverseBetHold(Player $player, int $amountMinor): void
|
||||
{
|
||||
if ($amountMinor <= 0 || ! PlayerFundingMode::usesCredit($player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->decreaseUsedCredit($player, $amountMinor);
|
||||
|
||||
DB::table('credit_ledger')->insert([
|
||||
'owner_type' => 'player',
|
||||
'owner_id' => $player->id,
|
||||
'amount' => $amountMinor,
|
||||
'reason' => 'bet_hold_release',
|
||||
'ref_type' => 'bet',
|
||||
'ref_id' => null,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function releaseFromSettlement(Player $player, int $amountMinor, int $billId): void
|
||||
{
|
||||
if ($amountMinor <= 0) {
|
||||
@@ -254,12 +323,16 @@ final class PlayerCreditService
|
||||
}
|
||||
|
||||
$playerId = (int) $player->id;
|
||||
$row = DB::table('player_credit_accounts')->where('player_id', $playerId)->first();
|
||||
$majorDelta = CreditAmountScale::minorToMajor($amountMinor, (string) $player->default_currency);
|
||||
|
||||
$row = DB::table('player_credit_accounts')
|
||||
->where('player_id', $playerId)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if ($row === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$majorDelta = CreditAmountScale::minorToMajor($amountMinor, (string) $player->default_currency);
|
||||
$next = max(0, (int) $row->used_credit - $majorDelta);
|
||||
DB::table('player_credit_accounts')
|
||||
->where('player_id', $playerId)
|
||||
|
||||
Reference in New Issue
Block a user