вкладка для ботов в админке

This commit is contained in:
2026-03-14 02:06:27 +04:00
parent 5a346a312d
commit d4880d2f05
8 changed files with 170 additions and 20 deletions
@@ -20,9 +20,29 @@ class AccountController extends Controller
): View
{
$search = trim((string) $request->query('search', ''));
$searchTerm = $search !== '' ? $search : null;
$activeTab = (string) $request->query('tab', AzerothCoreAccountService::ACCOUNT_TAB_PLAYERS);
if (! in_array($activeTab, [AzerothCoreAccountService::ACCOUNT_TAB_PLAYERS, AzerothCoreAccountService::ACCOUNT_TAB_BOTS], true)) {
$activeTab = AzerothCoreAccountService::ACCOUNT_TAB_PLAYERS;
}
$accountStats = $accounts->accountTypeStats($searchTerm);
return view('admin.accounts.index', [
'accounts' => $accounts->listAccounts($search !== '' ? $search : null),
'accounts' => $accounts->listAccounts($searchTerm, $activeTab),
'accountStats' => $accountStats,
'accountTabs' => [
AzerothCoreAccountService::ACCOUNT_TAB_PLAYERS => [
'label' => 'Игроки',
'count' => $accountStats[AzerothCoreAccountService::ACCOUNT_TAB_PLAYERS] ?? 0,
],
AzerothCoreAccountService::ACCOUNT_TAB_BOTS => [
'label' => 'Боты',
'count' => $accountStats[AzerothCoreAccountService::ACCOUNT_TAB_BOTS] ?? 0,
],
],
'activeTab' => $activeTab,
'inviteCodes' => $inviteCodes->latest(),
'inviteStats' => $inviteCodes->stats(),
'search' => $search,
+70 -15
View File
@@ -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);