You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.9 KiB
58 lines
1.9 KiB
|
2 weeks ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\OperationLog;
|
||
|
|
use App\Support\ApiResponse;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class OperationLogController extends Controller
|
||
|
|
{
|
||
|
|
use ApiResponse;
|
||
|
|
|
||
|
|
public function index(Request $request): JsonResponse
|
||
|
|
{
|
||
|
|
$query = OperationLog::query()->orderByDesc('operated_at');
|
||
|
|
|
||
|
|
if ($request->filled('admin_user_id')) {
|
||
|
|
$query->where('admin_user_id', (int) $request->query('admin_user_id'));
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($kw = $request->query('keyword')) {
|
||
|
|
$query->where(function ($q) use ($kw) {
|
||
|
|
$q->where('api_path', 'like', "%{$kw}%")
|
||
|
|
->orWhere('action_label', 'like', "%{$kw}%")
|
||
|
|
->orWhere('operator_name', 'like', "%{$kw}%");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($request->filled('from')) {
|
||
|
|
$query->where('operated_at', '>=', $request->query('from'));
|
||
|
|
}
|
||
|
|
if ($request->filled('to')) {
|
||
|
|
$query->where('operated_at', '<=', $request->query('to'));
|
||
|
|
}
|
||
|
|
|
||
|
|
$paginator = $query->paginate((int) $request->query('page_size', 20))->withQueryString();
|
||
|
|
|
||
|
|
$paginator->getCollection()->transform(function (OperationLog $log) {
|
||
|
|
return [
|
||
|
|
'id' => $log->id,
|
||
|
|
'admin_user_id' => $log->admin_user_id,
|
||
|
|
'operator_name' => $log->operator_name,
|
||
|
|
'operated_at' => $log->operated_at?->toIso8601String(),
|
||
|
|
'http_method' => $log->http_method,
|
||
|
|
'api_path' => $log->api_path,
|
||
|
|
'action_label' => $log->action_label,
|
||
|
|
'ip' => $log->ip,
|
||
|
|
'response_code' => $log->response_code,
|
||
|
|
'duration_ms' => $log->duration_ms,
|
||
|
|
];
|
||
|
|
});
|
||
|
|
|
||
|
|
return $this->paginated($paginator);
|
||
|
|
}
|
||
|
|
}
|