Build Laravel 13 ticket assistant with Docker, Livewire admin, and helpdesk scraper command
This commit is contained in:
42
app/Services/AdminDashboardService.php
Normal file
42
app/Services/AdminDashboardService.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\AIDecision;
|
||||
use App\Models\Article;
|
||||
use App\Models\Feedback;
|
||||
use App\Models\Ticket;
|
||||
|
||||
class AdminDashboardService
|
||||
{
|
||||
public function stats(): array
|
||||
{
|
||||
return [
|
||||
'articles_count' => Article::query()->count(),
|
||||
'tickets_count' => Ticket::query()->count(),
|
||||
'decisions_count' => AIDecision::query()->count(),
|
||||
'feedback_accuracy' => $this->feedbackAccuracy(),
|
||||
];
|
||||
}
|
||||
|
||||
public function recentTickets(int $limit = 10)
|
||||
{
|
||||
return Ticket::query()->latest()->limit($limit)->get();
|
||||
}
|
||||
|
||||
public function recentDecisions(int $limit = 10)
|
||||
{
|
||||
return AIDecision::query()->with(['ticket', 'article'])->latest()->limit($limit)->get();
|
||||
}
|
||||
|
||||
private function feedbackAccuracy(): ?float
|
||||
{
|
||||
$total = Feedback::query()->count();
|
||||
if ($total === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$correct = Feedback::query()->where('is_correct', true)->count();
|
||||
return round(($correct / $total) * 100, 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user