update: user statistical

This commit is contained in:
v2board 2023-05-03 18:24:30 +08:00
parent c6fbb89452
commit 3b1159187f
2 changed files with 15 additions and 17 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\StatUser; use App\Models\StatUser;
use App\Services\StatisticalService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -11,7 +12,10 @@ class StatController extends Controller
{ {
public function getTrafficLog(Request $request) public function getTrafficLog(Request $request)
{ {
$builder = StatUser::select([ $statService = new StatisticalService();
$statService->setStartAt(strtotime(date('Y-m-d')));
$statService->setUserStats();
$stats = StatUser::select([
'u', 'u',
'd', 'd',
'record_at', 'record_at',
@ -20,9 +24,17 @@ class StatController extends Controller
]) ])
->where('user_id', $request->user['id']) ->where('user_id', $request->user['id'])
->where('record_at', '>=', strtotime(date('Y-m-1'))) ->where('record_at', '>=', strtotime(date('Y-m-1')))
->orderBy('record_at', 'DESC'); ->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([ return response([
'data' => $builder->get() 'data' => $stats
]); ]);
} }
} }

View File

@ -1,14 +0,0 @@
<?php
namespace Library;
class V2ray
{
protected $config;
public function __construct()
{
$this->config = new \StdClass();
}
}