新增每日盈亏、玩家输赢、玩法维度、佣金回水四类聚合查询与权限注册,恢复报表异步导出任务;审计日志支持按操作人与日期筛选。 Co-authored-by: Cursor <cursoragent@cursor.com>
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Admin\Audit;
|
|
|
|
use App\Models\AuditLog;
|
|
use Illuminate\Http\Request;
|
|
use App\Support\AdminApiList;
|
|
use Illuminate\Http\JsonResponse;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
/**
|
|
* 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 AdminApiList::json($paginator, fn (AuditLog $r) => $this->row($r));
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function row(AuditLog $r): array
|
|
{
|
|
return [
|
|
'id' => (int) $r->id,
|
|
'operator_type' => $r->operator_type,
|
|
'operator_id' => (int) $r->operator_id,
|
|
'module_code' => $r->module_code,
|
|
'action_code' => $r->action_code,
|
|
'target_type' => $r->target_type,
|
|
'target_id' => $r->target_id,
|
|
'before_json' => $r->before_json,
|
|
'after_json' => $r->after_json,
|
|
'ip' => $r->ip,
|
|
'user_agent' => $r->user_agent,
|
|
'created_at' => $r->created_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|