From 4319ae1c3c207ced4c8bbb5b0d1a6953576e2cd2 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 23 Dec 2019 01:06:15 +0800 Subject: [PATCH] update --- app/Http/Controllers/ServerController.php | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/Http/Controllers/ServerController.php b/app/Http/Controllers/ServerController.php index 82c1bcc7..81b3651b 100644 --- a/app/Http/Controllers/ServerController.php +++ b/app/Http/Controllers/ServerController.php @@ -9,5 +9,29 @@ use App\Models\ServerLog; class ServerController extends Controller { public function getTrafficLog (Request $request) { + $type = $request->input('type') ? $request->input('type') : 0; + $current = $request->input('current') ? $request->input('current') : 1; + $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; + $serverLogModel = ServerLog::where('user_id', $request->session()->get('id')) + ->orderBy('created_at', 'DESC'); + switch ($type) { + case 0: $serverLogModel->where('created_at', '>=', strtotime(date('Y-m-d'))); + break; + case 1: $serverLogModel->where('created_at', '>=', strtotime(date('Y-m-d')) - 604800); + break; + case 2: $serverLogModel->where('created_at', '>=', strtotime(date('Y-m-1'))); + } + $sum = [ + 'u' => $serverLogModel->sum('u'), + 'd' => $serverLogModel->sum('d') + ]; + $total = $serverLogModel->count(); + $res = $serverLogModel->forPage($current, $pageSize) + ->get(); + return response([ + 'data' => $res, + 'total' => $total, + 'sum' => $sum + ]); } } \ No newline at end of file