fix:change user side bugs
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Flight;
|
||||
use App\Models\SiteVisit;
|
||||
use App\Models\Tour;
|
||||
use App\Models\User;
|
||||
use Illuminate\Routing\Controller;
|
||||
@@ -20,6 +22,95 @@ class DashboardController extends Controller
|
||||
$toursCount = Tour::count();
|
||||
$commentsCount = Comment::count();
|
||||
$usersCount = User::count();
|
||||
$viewsCount = SiteVisit::count();
|
||||
|
||||
$days = collect(range(9, 0))->map(
|
||||
fn ($i) => Carbon::today()->subDays($i)
|
||||
);
|
||||
|
||||
$visitsRaw = SiteVisit::selectRaw('DATE(created_at) as visit_date, COUNT(*) as total')
|
||||
->where('created_at', '>=', Carbon::today()->subDays(9)->startOfDay())
|
||||
->groupBy('visit_date')
|
||||
->pluck('total', 'visit_date');
|
||||
|
||||
$visitsChartLabels = $days
|
||||
->map(fn ($d) => $d->locale('fa')->translatedFormat('d M'))
|
||||
->toArray();
|
||||
|
||||
$visitsChartData = $days
|
||||
->map(fn ($d) => (int) ($visitsRaw[$d->toDateString()] ?? 0))
|
||||
->toArray();
|
||||
|
||||
$visitsChartOptions = [
|
||||
'chart' => [
|
||||
'type' => 'bar',
|
||||
'height' => 320,
|
||||
'toolbar' => ['show' => false],
|
||||
'fontFamily' => 'inherit',
|
||||
],
|
||||
'series' => [
|
||||
[
|
||||
'name' => 'بازدید',
|
||||
'data' => $visitsChartData,
|
||||
],
|
||||
],
|
||||
'xaxis' => [
|
||||
'categories' => $visitsChartLabels,
|
||||
'labels' => [
|
||||
'style' => ['colors' => '#8c9097'],
|
||||
],
|
||||
],
|
||||
'yaxis' => [
|
||||
'labels' => [
|
||||
'style' => ['colors' => '#8c9097'],
|
||||
],
|
||||
],
|
||||
'plotOptions' => [
|
||||
'bar' => [
|
||||
'borderRadius' => 6,
|
||||
'columnWidth' => '45%',
|
||||
'distributed' => false,
|
||||
],
|
||||
],
|
||||
'fill' => [
|
||||
'type' => 'gradient',
|
||||
'gradient' => [
|
||||
'shade' => 'light',
|
||||
'type' => 'vertical',
|
||||
'shadeIntensity' => 0.4,
|
||||
'gradientToColors' => ['#8b5cf6'],
|
||||
'opacityFrom' => 1,
|
||||
'opacityTo' => 0.85,
|
||||
'stops' => [0, 100],
|
||||
],
|
||||
],
|
||||
'colors' => ['#5B93FF'],
|
||||
'dataLabels' => ['enabled' => false],
|
||||
'grid' => [
|
||||
'strokeDashArray' => 4,
|
||||
'borderColor' => '#e8e8e8',
|
||||
],
|
||||
'tooltip' => [
|
||||
'theme' => 'light',
|
||||
],
|
||||
];
|
||||
|
||||
$recentLogs = ActivityLog::query()
|
||||
->whereIn('model_type', [Tour::class, Flight::class])
|
||||
->with('admin')
|
||||
->orderByDesc('created_at')
|
||||
->limit(10)
|
||||
->get()
|
||||
->map(function ($log) {
|
||||
|
||||
$modelClass = $log->model_type;
|
||||
$relatedModel = $modelClass::find($log->model_id);
|
||||
|
||||
$log->model_title = $relatedModel->title ?? '(حذف شده)';
|
||||
$log->model_label = $log->model_type === Tour::class ? 'تور' : 'پرواز';
|
||||
|
||||
return $log;
|
||||
});
|
||||
|
||||
return view('admin.dashboard', compact(
|
||||
'bookingsCount',
|
||||
@@ -27,6 +118,9 @@ class DashboardController extends Controller
|
||||
'toursCount',
|
||||
'commentsCount',
|
||||
'usersCount',
|
||||
'viewsCount',
|
||||
'visitsChartOptions',
|
||||
'recentLogs',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user