'=', 'is_read' => '=', 'user_id' => '=', ]; protected array $quickSearchField = ['title', 'content']; /** 通知列表 */ #[GetRoute(authorize: 'query')] public function query(Request $request): JsonResponse { $params = $request->all(); $pageSize = $params['pageSize'] ?? 10; $data = $this->buildSearch($params, NoticeModel::query()) ->orderBy('id', 'desc') ->paginate($pageSize) ->toArray(); return $this->success($data); } /** 发布通知(user_id=0 全员广播) */ #[PostRoute(authorize: 'create')] public function create(NoticeFormRequest $request): JsonResponse { NoticeModel::create($request->validated() + ['is_read' => NoticeModel::UNREAD]); return $this->success(); } /** 删除通知 */ #[DeleteRoute(route: '/{id}', authorize: 'delete', where: ['id' => '[0-9]+'])] public function delete(int $id): JsonResponse { $model = NoticeModel::find($id); if (empty($model)) { throw new RepositoryException('通知不存在'); } $model->delete(); return $this->success(); } }