request->inputs(['cr_id']); $this->validate($params, [ 'cr_id' => 'required|integer' ]); $recordsInfo = ChatRecord::select(['msg_type', 'source', 'user_id', 'receive_id'])->where('id', $params['cr_id'])->first(); if (!$recordsInfo) { return $this->response->fail('文件不存在...'); } $user_id = $this->uid(); //判断消息是否是当前用户发送(如果是则跳过权限验证) if ($recordsInfo->user_id != $user_id) { if ($recordsInfo->source == 1) { if ($recordsInfo->receive_id != $user_id) { return $this->response->fail('非法请求...'); } } else { if (!UsersGroup::isMember($recordsInfo->receive_id, $user_id)) { return $this->response->fail('非法请求...'); } } } $fileInfo = ChatRecordsFile::select(['save_dir', 'original_name'])->where('record_id', $params['cr_id'])->first(); if (!$fileInfo) { return $this->response->fail('文件不存在或没有下载权限...'); } return $response->download($uploadService->driver($fileInfo->save_dir), $fileInfo->original_name); } /** * 下载笔记附件 * * @RequestMapping(path="article-annex", methods="get") * * @param ResponseInterface $response * @param UploadService $uploadService * @return \Psr\Http\Message\ResponseInterface */ public function articleAnnex(ResponseInterface $response, UploadService $uploadService) { $params = $this->request->inputs(['annex_id']); $this->validate($params, [ 'annex_id' => 'required|integer' ]); $info = ArticleAnnex::select(['save_dir', 'original_name']) ->where('id', $params['annex_id']) ->where('user_id', $this->uid()) ->first(); if (!$info) { return $this->response->fail('文件不存在或没有下载权限...'); } return $response->download($uploadService->driver($info->save_dir), $info->original_name); } }