53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Concerns\PortalAware;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Services\DashboardStatsService;
|
|
use App\Support\AgentScope;
|
|
use Illuminate\Http\Request;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
use PortalAware;
|
|
|
|
public function __construct(
|
|
private readonly DashboardStatsService $stats,
|
|
) {}
|
|
|
|
public function index()
|
|
{
|
|
$agents = $this->isAgentPortal()
|
|
? collect()
|
|
: User::query()->orderBy('username')->get(['id', 'username']);
|
|
|
|
return view('admin.dashboard.index', [
|
|
'portal' => $this->portal(),
|
|
'agents' => $agents,
|
|
]);
|
|
}
|
|
|
|
public function data(Request $request)
|
|
{
|
|
$data = $this->stats->collect([
|
|
'date_from' => trim((string) $request->query('date_from', '')),
|
|
'date_to' => trim((string) $request->query('date_to', '')),
|
|
'date_range' => trim((string) $request->query('date_range', '')),
|
|
'range' => (string) $request->query('range', '30d'),
|
|
'channel_id' => trim((string) $request->query('channel_id', '')),
|
|
'agent_user_id' => $this->isAgentPortal()
|
|
? null
|
|
: AgentScope::parseAgentUserIdFilter($request->query('agent_user_id')),
|
|
'agent' => $this->agent(),
|
|
]);
|
|
|
|
return response()->json([
|
|
'code' => 0,
|
|
'msg' => '',
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
}
|