title('第三方服务概览'); $this->dropdown([ 'services' => '服务统计', 'credentials' => '凭证统计', 'logs' => '日志统计', ]); } /** * 处理请求 * * @param Request $request * @return void */ public function handle(Request $request) { $option = $request->get('option', 'services'); switch ($option) { case 'credentials': $this->handleCredentialsStats(); break; case 'logs': $this->handleLogsStats(); break; case 'services': default: $this->handleServicesStats(); break; } } /** * 处理服务统计 */ protected function handleServicesStats() { $totalServices = ThirdPartyService::count(); $activeServices = ThirdPartyService::where('status', SERVICE_STATUS::ACTIVE->value)->count(); $healthyServices = ThirdPartyService::where('health_status', 'HEALTHY')->count(); $inactiveServices = $totalServices - $activeServices; $this->withContent([ ['label' => '总服务数', 'value' => $totalServices, 'color' => 'primary'], ['label' => '激活服务', 'value' => $activeServices, 'color' => 'success'], ['label' => '健康服务', 'value' => $healthyServices, 'color' => 'info'], ['label' => '未激活', 'value' => $inactiveServices, 'color' => 'secondary'], ]); } /** * 处理凭证统计 */ protected function handleCredentialsStats() { $totalCredentials = ThirdPartyCredential::count(); $activeCredentials = ThirdPartyCredential::where('is_active', true)->count(); $inactiveCredentials = $totalCredentials - $activeCredentials; $this->withContent([ ['label' => '总凭证数', 'value' => $totalCredentials, 'color' => 'primary'], ['label' => '激活凭证', 'value' => $activeCredentials, 'color' => 'success'], ['label' => '未激活', 'value' => $inactiveCredentials, 'color' => 'secondary'], ]); } /** * 处理日志统计 */ protected function handleLogsStats() { $totalLogs = ThirdPartyLog::count(); $todayLogs = ThirdPartyLog::whereDate('created_at', today())->count(); $errorLogs = ThirdPartyLog::where('level', 'ERROR')->count(); $this->withContent([ ['label' => '总调用次数', 'value' => number_format($totalLogs), 'color' => 'primary'], ['label' => '今日调用', 'value' => number_format($todayLogs), 'color' => 'info'], ['label' => '错误调用', 'value' => number_format($errorLogs), 'color' => 'danger'], ]); } /** * 设置卡片内容 * * @param array $stats * @return $this */ public function withContent(array $stats) { $html = '
'; foreach ($stats as $stat) { $html .= <<
{$stat['value']}
{$stat['label']}
HTML; } $html .= ''; return $this->content($html); } }