后端流量记录排序改为更精确时间优先(避免只按 record_at 导致排序/分钟不准)
StatController.php (E:/code/php/Xboard-new/app/Http/Controllers/V1/User/StatController.php:22)
StatController.php (E:/code/php/Xboard-new/app/Http/Controllers/V2/Admin/StatController.php:242)
2. 流量资源新增 display_at(优先 updated_at,回退 created_at/record_at)
TrafficLogResource.php (E:/code/php/Xboard-new/app/Http/Resources/TrafficLogResource.php:19)
TrafficLogResource.php (E:/code/php/Xboard-new/app/Http/Resources/TrafficLogResource.php:43)
3. 管理端前端(打包产物)流量列改为:时间/上行/下行/倍率/节点/设备/总计,时间显示 YYYY/MM/DD HH:mm
index.js (E:/code/php/Xboard-new/public/assets/admin/assets/index.js:16)
This commit is contained in:
@@ -19,7 +19,9 @@ class StatController extends Controller
|
|||||||
->with(['server:id,name'])
|
->with(['server:id,name'])
|
||||||
->where('user_id', $userId)
|
->where('user_id', $userId)
|
||||||
->where('record_at', '>=', $startDate)
|
->where('record_at', '>=', $startDate)
|
||||||
->orderBy('record_at', 'DESC')
|
->orderByDesc('updated_at')
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->orderByDesc('record_at')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$deviceMap = $this->buildNodeDeviceMap($userId);
|
$deviceMap = $this->buildNodeDeviceMap($userId);
|
||||||
|
|||||||
@@ -239,7 +239,9 @@ class StatController extends Controller
|
|||||||
$userId = (int) $request->input('user_id');
|
$userId = (int) $request->input('user_id');
|
||||||
$records = StatUser::query()
|
$records = StatUser::query()
|
||||||
->with(['server:id,name'])
|
->with(['server:id,name'])
|
||||||
->orderBy('record_at', 'DESC')
|
->orderByDesc('updated_at')
|
||||||
|
->orderByDesc('created_at')
|
||||||
|
->orderByDesc('record_at')
|
||||||
->where('user_id', $userId)
|
->where('user_id', $userId)
|
||||||
->paginate($pageSize);
|
->paginate($pageSize);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class TrafficLogResource extends JsonResource
|
|||||||
{
|
{
|
||||||
$serverId = (int) data_get($this->resource, 'server_id', 0);
|
$serverId = (int) data_get($this->resource, 'server_id', 0);
|
||||||
$serverType = strtolower((string) data_get($this->resource, 'server_type', ''));
|
$serverType = strtolower((string) data_get($this->resource, 'server_type', ''));
|
||||||
|
$displayAt = $this->resolveDisplayAt();
|
||||||
$serverName = data_get($this->resource, 'server_name')
|
$serverName = data_get($this->resource, 'server_name')
|
||||||
?: data_get($this->resource, 'node_name')
|
?: data_get($this->resource, 'node_name')
|
||||||
?: data_get($this->resource, 'server.name');
|
?: data_get($this->resource, 'server.name');
|
||||||
@@ -39,6 +40,7 @@ class TrafficLogResource extends JsonResource
|
|||||||
'd' => (int) data_get($this->resource, 'd', 0),
|
'd' => (int) data_get($this->resource, 'd', 0),
|
||||||
'u' => (int) data_get($this->resource, 'u', 0),
|
'u' => (int) data_get($this->resource, 'u', 0),
|
||||||
'record_at' => (int) data_get($this->resource, 'record_at', 0),
|
'record_at' => (int) data_get($this->resource, 'record_at', 0),
|
||||||
|
'display_at' => $displayAt,
|
||||||
'record_type' => data_get($this->resource, 'record_type'),
|
'record_type' => data_get($this->resource, 'record_type'),
|
||||||
'server_rate' => (float) data_get($this->resource, 'server_rate', 1),
|
'server_rate' => (float) data_get($this->resource, 'server_rate', 1),
|
||||||
'server_id' => $serverId > 0 ? $serverId : null,
|
'server_id' => $serverId > 0 ? $serverId : null,
|
||||||
@@ -59,4 +61,27 @@ class TrafficLogResource extends JsonResource
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function resolveDisplayAt(): int
|
||||||
|
{
|
||||||
|
foreach (['updated_at', 'created_at'] as $field) {
|
||||||
|
$value = data_get($this->resource, $field);
|
||||||
|
if ($value instanceof \DateTimeInterface) {
|
||||||
|
return $value->getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($value)) {
|
||||||
|
return (int) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($value) && trim($value) !== '') {
|
||||||
|
$timestamp = strtotime($value);
|
||||||
|
if ($timestamp !== false) {
|
||||||
|
return $timestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) data_get($this->resource, 'record_at', 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user