- 在多个控制器中将权限检查从 hasAdminPermission 更新为 hasPermissionCode,以增强权限管理的灵活性。 - 引入 AdminScopePolicy,优化基于代理节点的权限和数据过滤逻辑,确保管理员能够更精确地控制访问权限。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 更新 AdminUser 模型,新增 hasPermissionCode 方法,以支持更细粒度的权限检查。 - 优化审计日志记录逻辑,确保在处理请求时能够准确记录管理员的操作。
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Audit;
|
|
|
|
use App\Models\AuditLog;
|
|
use Illuminate\Http\Request;
|
|
use App\Support\AdminApiList;
|
|
use App\Support\ApiResponse;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\AuditLogApiPresenter;
|
|
|
|
/**
|
|
* GET /api/v1/admin/audit-logs — 运营/客服查询审计留痕。
|
|
*/
|
|
final class AuditLogIndexController extends Controller
|
|
{
|
|
public function __invoke(Request $request): JsonResponse
|
|
{
|
|
$p = AdminApiList::readPaging($request);
|
|
$module = trim((string) $request->query('module_code', ''));
|
|
$action = trim((string) $request->query('action_code', ''));
|
|
$operatorType = trim((string) $request->query('operator_type', ''));
|
|
$operatorId = (int) $request->query('operator_id', 0);
|
|
$startDate = trim((string) $request->query('start_date', ''));
|
|
$endDate = trim((string) $request->query('end_date', ''));
|
|
|
|
$q = AuditLog::query()->orderByDesc('id');
|
|
|
|
if ($module !== '') {
|
|
$q->where('module_code', $module);
|
|
}
|
|
if ($action !== '') {
|
|
$q->where('action_code', $action);
|
|
}
|
|
if ($operatorType !== '') {
|
|
$q->where('operator_type', $operatorType);
|
|
}
|
|
if ($operatorId > 0) {
|
|
$q->where('operator_id', $operatorId);
|
|
}
|
|
if ($startDate !== '') {
|
|
$q->whereDate('created_at', '>=', $startDate);
|
|
}
|
|
if ($endDate !== '') {
|
|
$q->whereDate('created_at', '<=', $endDate);
|
|
}
|
|
|
|
$paginator = $q->paginate($p['perPage'], ['*'], 'page', $p['page']);
|
|
|
|
return ApiResponse::success(AuditLogApiPresenter::listPayload($paginator));
|
|
}
|
|
}
|