3
0
Fork 0
This repository has been archived on 2024-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
ThemeParkPlus-Panel/app/Http/Controllers/RidecountController.php
2021-06-27 21:01:43 +02:00

55 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class RidecountController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['auth', 'verified', '2fa']);
}
/**
* Show the application dashboard.
*
* @param $attraction_id
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index($attraction_id)
{
$name = DB::table('attraction')->select('name')->where('id', '=', $attraction_id)->first()->name;
$top10 = DB::table(DB::raw('ridecount, (SELECT @row_number:=0) AS t'))->select('uuid', DB::raw('SUM(`count`) AS `count`'), DB::raw('(@row_number:=@row_number + 1) AS `num`'))
->where('attractionId', '=', $attraction_id)
->whereRaw('YEARWEEK(date, 1) = YEARWEEK(CURDATE(), 1)')
->whereRaw('YEAR(date) = YEAR(CURDATE())')
->groupBy('uuid')
->orderByDesc('count')
->take(10)->get()->all();
$personal = DB::table('ridecount')
->where('attractionId', '=', $attraction_id)
->where('uuid', '=', Auth::user()->uuid)
->sum('count');
$total = DB::table('ridecount')
->where('attractionId', '=', $attraction_id)
->sum('count');
return view('ridecount')->with([
'name' => $name,
'top10' => $top10,
'personal' => $personal,
'total' => $total
]);
}
}