-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAdminController.php
More file actions
92 lines (81 loc) · 2.58 KB
/
AdminController.php
File metadata and controls
92 lines (81 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use App\Visit;
use App\Count;
use App\User;
use App\Setting;
class AdminController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('super');
}
/**
* Show the application admin.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//挂载博主信息
$master = User::findOrFail(1);
//挂载存储盘信息
$file_disk = Setting::where('key', 'file_disk')->value('value');
return view(env('BLOG_THEME') . '.admin', [
'master' => $master,
'file_disk' => $file_disk
]);
}
/**
* 返回面板数据
*
* @return \Illuminate\Http\Response
*/
public function dashboard_api()
{
$visits_count = DB::table('visits')->count();
$date = Carbon::today()->subDay(19);
$visits_arr = array();
$visits_max = 0;
for ($i = 0; $i < 20; $i++) {
$count = DB::table('visits')->whereDate('created_at', $date->toDateString())->count();
array_push($visits_arr, array(
'x' => $date->toDateString(),
'y' => $count
));
$date = $date->addDay();
if ($count > $visits_max) {
$visits_max = $count;
}
}
$visits_today = $visits_arr[19]['y'];
$visits_day_max = Count::where('key', 'visits_day_max')->first();
if ($visits_max > $visits_day_max->value) {
$visits_day_max->value = $visits_max;
$visits_day_max->save();
}
$articles_count = DB::table('articles')->count();
$articles_today = DB::table('articles')->whereDate('created_at', Carbon::today()->toDateString())->count();
$comments_count = DB::table('comments')->count();
$comments_today = DB::table('comments')->whereDate('created_at', Carbon::today()->toDateString())->count();
return response()->json([
'visits_count' => $visits_count,
'visits_arr' => (array)$visits_arr,
'visits_today' => $visits_today,
'visits_day_max' => $visits_day_max->value,
'articles_count' => $articles_count,
'articles_today' => $articles_today,
'comments_count' => $comments_count,
'comments_today' => $comments_today,
]);
}
}