功能:后台「我的履职记录」页面

- 侧边栏「我的履职记录」链接,位于「任命管理」上方
- 路由:GET /admin/my-duty-logs → appointments.my-duty-logs
- 控制器:AppointmentController::myDutyLogs()
  支持按操作类型、日期范围筛选,分页,withQueryString()
- 视图:admin/appointments/my-duty-logs.blade.php
  顶部 6 格汇总统计(奖励/踢出/禁言/警告/任命/撤职)
  每张卡片可点击快速按类型筛选
  表格显示:操作时间、类型 Badge、操作对象、所属部门·职务、金币金额、备注
This commit is contained in:
2026-03-01 12:22:13 +08:00
parent f4de31f92b
commit 855f169516
4 changed files with 250 additions and 1 deletions

View File

@@ -182,6 +182,42 @@ class AppointmentController extends Controller
return view('admin.appointments.history', compact('history'));
}
/**
* 我的履职记录:展示当前登录者自己所有的权限操作记录
*
* 不限于某一任职周期,展示全部历史操作,支持按操作类型和日期筛选。
*/
public function myDutyLogs(Request $request): View
{
$user = Auth::user();
$query = \App\Models\PositionAuthorityLog::where('user_id', $user->id)
->with(['targetUser:id,username', 'targetPosition:id,name', 'userPosition.position.department']);
// 按操作类型筛选
if ($request->filled('type')) {
$query->where('action_type', $request->type);
}
// 按日期范围筛选
if ($request->filled('date_from')) {
$query->whereDate('created_at', '>=', $request->date_from);
}
if ($request->filled('date_to')) {
$query->whereDate('created_at', '<=', $request->date_to);
}
$logs = $query->orderByDesc('created_at')->paginate(30)->withQueryString();
// 汇总统计
$summary = \App\Models\PositionAuthorityLog::where('user_id', $user->id)
->selectRaw('action_type, COUNT(*) as total, COALESCE(SUM(amount),0) as amount_sum')
->groupBy('action_type')
->get()
->keyBy('action_type');
return view('admin.appointments.my-duty-logs', compact('logs', 'summary', 'user'));
}
/**
* 搜索用户(供任命弹窗 Ajax 快速查找)
*/