Files
yuezi-saas/backend/app/Http/Controllers/Admin/Office/NotificationController.php
T
li 058ee507fa feat: 第五阶段办公协同/统计报表/知识库模块
- 新增3个migration(9张表): office(6表)/report(1表)/kb(2表)
- 新增9个Model + 9个Controller
- 新增43条API路由(总计305条)
- 新增3个前端API模块 + 10个管理页面
- 迁移运行通过, vite build验证通过
2026-03-13 21:43:10 +08:00

41 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Office;
use App\Http\Controllers\Controller;
use App\Models\Office\Notification;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
public function index(Request $request): JsonResponse
{
$query = Notification::query()->where('user_id', auth()->id());
$query->when($request->type, fn($q, $v) => $q->where('type', $v));
$query->when($request->has('is_read'), fn($q) => $q->where('is_read', $request->boolean('is_read')));
return $this->paginate($query->latest('created_at')->paginate($request->input('per_page', 15)));
}
public function markRead(Notification $notification): JsonResponse
{
if ($notification->user_id !== auth()->id()) {
return $this->error('无权操作', 40003, 403);
}
$notification->update(['is_read' => true, 'read_at' => now()]);
return $this->success($notification);
}
public function markAllRead(): JsonResponse
{
Notification::query()
->where('user_id', auth()->id())
->where('is_read', false)
->update(['is_read' => true, 'read_at' => now()]);
return $this->success(null);
}
}