mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 02:50:52 +08:00
Merge pull request #755 from socksprox/feat/server-id-stat-user
feat: Track user traffic per node (server_id)
This commit is contained in:
@@ -14,13 +14,29 @@ class StatController extends Controller
|
||||
public function getTrafficLog(Request $request)
|
||||
{
|
||||
$startDate = now()->startOfMonth()->timestamp;
|
||||
|
||||
// Aggregate per-node data into per-day entries for backward compatibility
|
||||
$records = StatUser::query()
|
||||
->select([
|
||||
'user_id',
|
||||
'server_rate',
|
||||
'record_at',
|
||||
'record_type',
|
||||
DB::raw('SUM(u) as u'),
|
||||
DB::raw('SUM(d) as d'),
|
||||
])
|
||||
->where('user_id', $request->user()->id)
|
||||
->where('record_at', '>=', $startDate)
|
||||
->groupBy(['user_id', 'server_rate', 'record_at', 'record_type'])
|
||||
->orderBy('record_at', 'DESC')
|
||||
->get();
|
||||
->get()
|
||||
->map(function ($item) {
|
||||
$item->u = (int) $item->u;
|
||||
$item->d = (int) $item->d;
|
||||
return $item;
|
||||
});
|
||||
|
||||
$data = TrafficLogResource::collection(collect($records));
|
||||
$data = TrafficLogResource::collection($records);
|
||||
return $this->success($data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user