🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 16:43
This commit is contained in:
@@ -1,49 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Admin;
|
||||
|
||||
use App\Core\{Request, Response, Database};
|
||||
|
||||
final class AdminController
|
||||
{
|
||||
public function listTenants(Request $request): void
|
||||
{
|
||||
if ($request->user->role !== 'super_admin') {
|
||||
Response::error('غير مصرح لك بالوصول لهذه البيانات', 'FORBIDDEN', 403);
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare("SELECT t.*, (SELECT COUNT(*) FROM invoices WHERE tenant_id = t.id) as invoice_count FROM tenants t");
|
||||
$stmt->execute();
|
||||
$tenants = $stmt->fetchAll();
|
||||
|
||||
Response::json(['success' => true, 'data' => $tenants]);
|
||||
}
|
||||
|
||||
public function getSystemStats(Request $request): void
|
||||
{
|
||||
// Must be super_admin
|
||||
if (($request->user->role ?? '') !== 'super_admin') {
|
||||
Response::error('غير مصرح', 'FORBIDDEN', 403);
|
||||
if ($request->user->role !== 'super_admin') {
|
||||
Response::error('Forbidden', 'FORBIDDEN', 403);
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
$stmt = $db->prepare("SELECT COUNT(*) as count FROM tenants");
|
||||
$stmt->execute();
|
||||
$totalTenants = $stmt->fetch()['count'];
|
||||
$stats = [
|
||||
'total_tenants' => (int)$db->query("SELECT COUNT(*) FROM tenants")->fetchColumn(),
|
||||
'total_invoices' => (int)$db->query("SELECT COUNT(*) FROM invoices")->fetchColumn(),
|
||||
'total_users' => (int)$db->query("SELECT COUNT(*) FROM users")->fetchColumn(),
|
||||
'active_subscriptions' => (int)$db->query("SELECT COUNT(*) FROM subscriptions WHERE status = 'active'")->fetchColumn()
|
||||
];
|
||||
|
||||
$stmt = $db->prepare("SELECT COUNT(*) as count FROM invoices");
|
||||
$stmt->execute();
|
||||
$totalInvoices = $stmt->fetch()['count'];
|
||||
Response::json(['success' => true, 'data' => $stats]);
|
||||
}
|
||||
|
||||
// Simple Health Check
|
||||
$redisHealth = 'ok';
|
||||
try {
|
||||
$redis = \App\Core\Redis::getInstance();
|
||||
$redis->ping();
|
||||
} catch (\Throwable $e) {
|
||||
$redisHealth = 'failed';
|
||||
public function getQueueStatus(Request $request): void
|
||||
{
|
||||
if ($request->user->role !== 'super_admin') {
|
||||
Response::error('Forbidden', 'FORBIDDEN', 403);
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare("SELECT status, COUNT(*) as count FROM queue_jobs GROUP BY status");
|
||||
$stmt->execute();
|
||||
$counts = $stmt->fetchAll();
|
||||
|
||||
Response::json(['success' => true, 'data' => $counts]);
|
||||
}
|
||||
|
||||
public function health(Request $request): void
|
||||
{
|
||||
$dbStatus = 'ok';
|
||||
try { Database::getInstance()->query("SELECT 1"); } catch (\Throwable $e) { $dbStatus = 'error'; }
|
||||
|
||||
$redisStatus = 'ok';
|
||||
try { \App\Core\Redis::getInstance()->ping(); } catch (\Throwable $e) { $redisStatus = 'error'; }
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'total_tenants' => $totalTenants,
|
||||
'total_invoices' => $totalInvoices,
|
||||
'system_health' => [
|
||||
'database' => 'ok',
|
||||
'redis' => $redisHealth
|
||||
]
|
||||
'database' => $dbStatus,
|
||||
'redis' => $redisStatus,
|
||||
'php_version' => PHP_VERSION,
|
||||
'server_time' => date('Y-m-d H:i:s')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user