🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:39
This commit is contained in:
50
app/Modules/Admin/AdminController.php
Normal file
50
app/Modules/Admin/AdminController.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Admin;
|
||||
|
||||
use App\Core\{Request, Response, Database};
|
||||
|
||||
final class AdminController
|
||||
{
|
||||
public function getSystemStats(Request $request): void
|
||||
{
|
||||
// Must be super_admin
|
||||
if (($request->user->role ?? '') !== 'super_admin') {
|
||||
Response::error('غير مصرح', 'FORBIDDEN', 403);
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
$stmt = $db->prepare("SELECT COUNT(*) as count FROM tenants");
|
||||
$stmt->execute();
|
||||
$totalTenants = $stmt->fetch()['count'];
|
||||
|
||||
$stmt = $db->prepare("SELECT COUNT(*) as count FROM invoices");
|
||||
$stmt->execute();
|
||||
$totalInvoices = $stmt->fetch()['count'];
|
||||
|
||||
// Simple Health Check
|
||||
$redisHealth = 'ok';
|
||||
try {
|
||||
$redis = \App\Core\Redis::getInstance();
|
||||
$redis->ping();
|
||||
} catch (\Throwable $e) {
|
||||
$redisHealth = 'failed';
|
||||
}
|
||||
|
||||
Response::json([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'total_tenants' => $totalTenants,
|
||||
'total_invoices' => $totalInvoices,
|
||||
'system_health' => [
|
||||
'database' => 'ok',
|
||||
'redis' => $redisHealth
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user