feat: enhance player authentication and agent management features
Some checks failed
lotterLaravel CI / test (push) Has been cancelled

- Updated AGENTS.md to clarify player interface bindings and agent account restrictions.
- Improved PlayerAuthLoginController to include captcha verification for player login.
- Enhanced AdminPlayerIndexController with permission checks for admin users.
- Refactored AdminPlayerStoreController to enforce agent node restrictions for non-super admins.
- Introduced new error codes for player authentication failures and updated related services.
- Enhanced validation rules for agent profiles to include settlement cycle options.
- Improved AdminCaptchaService to support separate scopes for admin and player captcha handling.
- Updated various services to ensure proper credit management and settlement processes.
This commit is contained in:
2026-06-17 15:27:00 +08:00
parent b496a9457c
commit 2e0b257160
49 changed files with 714 additions and 334 deletions

View File

@@ -18,11 +18,18 @@ final class PlayerCreditService
{
$limit = max(0, (int) ($payload['credit_limit'] ?? 0));
$now = now();
$exists = DB::table('player_credit_accounts')
$row = DB::table('player_credit_accounts')
->where('player_id', $player->id)
->exists();
->first();
if ($row !== null) {
$usedTotal = (int) $row->used_credit + (int) $row->frozen_credit;
if ($limit < $usedTotal) {
throw ValidationException::withMessages([
'credit_limit' => ['below_player_used'],
]);
}
if ($exists) {
DB::table('player_credit_accounts')
->where('player_id', $player->id)
->update([
@@ -72,7 +79,8 @@ final class PlayerCreditService
$this->assertCreditGuards($player);
$currency = (string) $player->default_currency;
if ($amountMinor > $this->availableCreditMinor($player, $currency)) {
$majorNeeded = CreditAmountScale::minorToMajor($amountMinor, $currency);
if ($majorNeeded > $this->availableCredit($player)) {
throw ValidationException::withMessages([
'credit' => ['insufficient'],
]);
@@ -274,9 +282,58 @@ final class PlayerCreditService
]);
}
public function reverseGameSettlement(Player $player, int $gameWinLossSigned, int $ticketItemId): void
{
if ($gameWinLossSigned === 0 || ! PlayerFundingMode::usesCredit($player)) {
return;
}
$now = now();
if ($gameWinLossSigned > 0) {
$amountMinor = $gameWinLossSigned;
$this->decreaseUsedCredit($player, $amountMinor);
DB::table('credit_ledger')->insert([
'owner_type' => 'player',
'owner_id' => $player->id,
'amount' => $amountMinor,
'reason' => 'game_settlement_reversal',
'ref_type' => 'ticket_item',
'ref_id' => $ticketItemId,
'created_at' => $now,
'updated_at' => $now,
]);
return;
}
$amountMinor = abs($gameWinLossSigned);
$currency = (string) $player->default_currency;
$majorDelta = CreditAmountScale::minorToMajor($amountMinor, $currency);
DB::table('player_credit_accounts')
->where('player_id', $player->id)
->update([
'used_credit' => DB::raw('used_credit + '.$majorDelta),
'updated_at' => $now,
]);
DB::table('credit_ledger')->insert([
'owner_type' => 'player',
'owner_id' => $player->id,
'amount' => -$amountMinor,
'reason' => 'game_settlement_reversal',
'ref_type' => 'ticket_item',
'ref_id' => $ticketItemId,
'created_at' => $now,
'updated_at' => $now,
]);
}
public function releaseFromSettlement(Player $player, int $amountMinor, int $billId): void
{
if ($amountMinor <= 0) {
if ($amountMinor <= 0 || ! PlayerFundingMode::usesCredit($player)) {
return;
}