вкладка для ботов в админке
This commit is contained in:
@@ -4,12 +4,17 @@ namespace App\Services;
|
||||
|
||||
use App\Models\GameAccountUser;
|
||||
use App\Support\WowData;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AzerothCoreAccountService
|
||||
{
|
||||
public const ACCOUNT_TAB_PLAYERS = 'players';
|
||||
|
||||
public const ACCOUNT_TAB_BOTS = 'bots';
|
||||
|
||||
public function __construct(private readonly AzerothCoreSrpService $srp)
|
||||
{
|
||||
}
|
||||
@@ -66,23 +71,11 @@ class AzerothCoreAccountService
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function listAccounts(?string $search = null): Collection
|
||||
public function listAccounts(?string $search = null, string $accountTab = self::ACCOUNT_TAB_PLAYERS): Collection
|
||||
{
|
||||
$query = $this->authConnection()
|
||||
->table('account')
|
||||
->select('id', 'username', 'email', 'reg_mail', 'locked', 'last_login', 'joindate', 'online')
|
||||
->orderByDesc('id');
|
||||
$query = $this->baseAccountsQuery($search);
|
||||
|
||||
if ($search !== null && trim($search) !== '') {
|
||||
$normalizedSearch = $this->srp->normalizeUsername($search);
|
||||
|
||||
$query->where(function ($builder) use ($normalizedSearch): void {
|
||||
$builder
|
||||
->where('username', 'like', "%{$normalizedSearch}%")
|
||||
->orWhere('email', 'like', "%{$normalizedSearch}%")
|
||||
->orWhere('reg_mail', 'like', "%{$normalizedSearch}%");
|
||||
});
|
||||
}
|
||||
$this->applyAccountTabFilter($query, $accountTab);
|
||||
|
||||
$accounts = $query->get();
|
||||
$accountIds = $accounts->pluck('id')->map(fn ($id): int => (int) $id)->all();
|
||||
@@ -109,6 +102,23 @@ class AzerothCoreAccountService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{players: int, bots: int}
|
||||
*/
|
||||
public function accountTypeStats(?string $search = null): array
|
||||
{
|
||||
$playersQuery = $this->baseAccountsQuery($search);
|
||||
$botsQuery = $this->baseAccountsQuery($search);
|
||||
|
||||
$this->applyAccountTabFilter($playersQuery, self::ACCOUNT_TAB_PLAYERS);
|
||||
$this->applyAccountTabFilter($botsQuery, self::ACCOUNT_TAB_BOTS);
|
||||
|
||||
return [
|
||||
self::ACCOUNT_TAB_PLAYERS => $playersQuery->count(),
|
||||
self::ACCOUNT_TAB_BOTS => $botsQuery->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection<int, array<string, mixed>>
|
||||
*/
|
||||
@@ -217,6 +227,51 @@ class AzerothCoreAccountService
|
||||
return $value ? Carbon::parse($value)->format('d.m.Y H:i') : '—';
|
||||
}
|
||||
|
||||
private function baseAccountsQuery(?string $search = null): Builder
|
||||
{
|
||||
$query = $this->authConnection()
|
||||
->table('account')
|
||||
->select('id', 'username', 'email', 'reg_mail', 'locked', 'last_login', 'joindate', 'online')
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($search !== null && trim($search) !== '') {
|
||||
$normalizedSearch = $this->srp->normalizeUsername($search);
|
||||
|
||||
$query->where(function ($builder) use ($normalizedSearch): void {
|
||||
$builder
|
||||
->where('username', 'like', "%{$normalizedSearch}%")
|
||||
->orWhere('email', 'like', "%{$normalizedSearch}%")
|
||||
->orWhere('reg_mail', 'like', "%{$normalizedSearch}%");
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function applyAccountTabFilter(Builder $query, string $accountTab): void
|
||||
{
|
||||
$botPrefix = $this->botAccountPrefix();
|
||||
|
||||
if ($botPrefix === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$pattern = $botPrefix.'%';
|
||||
|
||||
if ($accountTab === self::ACCOUNT_TAB_BOTS) {
|
||||
$query->where('username', 'like', $pattern);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where('username', 'not like', $pattern);
|
||||
}
|
||||
|
||||
private function botAccountPrefix(): string
|
||||
{
|
||||
return strtoupper(trim((string) config('moonwell.portal.bot_account_prefix', 'RNDBOT')));
|
||||
}
|
||||
|
||||
private function targetRealmId(): int
|
||||
{
|
||||
return (int) config('moonwell.registration.realm_id', -1);
|
||||
|
||||
Reference in New Issue
Block a user