v2board/app/Http/Controllers/User/StatController.php

41 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\StatUser;
2023-05-03 18:24:30 +08:00
use App\Services\StatisticalService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class StatController extends Controller
{
public function getTrafficLog(Request $request)
{
2023-05-03 18:24:30 +08:00
$statService = new StatisticalService();
$statService->setStartAt(strtotime(date('Y-m-d')));
$statService->setUserStats();
$stats = StatUser::select([
2022-03-29 20:45:54 +08:00
'u',
'd',
'record_at',
'user_id',
'server_rate'
])
2022-07-19 03:11:36 +08:00
->where('user_id', $request->user['id'])
->where('record_at', '>=', strtotime(date('Y-m-1')))
2023-05-03 18:24:30 +08:00
->orderBy('record_at', 'DESC')
->get()
->toArray();
$stats = array_merge($stats, $statService->getStatUserByUserID($request->user['id']));
usort($stats, function ($a, $b) {
return $b['record_at'] - $a['record_at'];
});
return response([
2023-05-03 18:24:30 +08:00
'data' => $stats
]);
}
}