- 新增3个migration(9张表): office(6表)/report(1表)/kb(2表) - 新增9个Model + 9个Controller - 新增43条API路由(总计305条) - 新增3个前端API模块 + 10个管理页面 - 迁移运行通过, vite build验证通过
41 lines
1.2 KiB
PHP
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);
|
|
}
|
|
}
|