request->inputs(['talk_type', 'receiver_id', 'record_id']); $this->validate($params, [ 'talk_type' => 'required|in:1,2', 'receiver_id' => 'required|integer|min:1', 'record_id' => 'required|integer|min:0', ]); $user_id = $this->uid(); if ($params['talk_type'] == TalkModeConstant::GROUP_CHAT && !di()->get(GroupMemberService::class)->isMember((int)$params['receiver_id'], $user_id)) { return $this->response->fail('暂不属于好友关系或群聊成员,无法查看聊天记录!'); } $limit = 30; $result = $this->talkService->getChatRecords( $user_id, intval($params['receiver_id']), intval($params['talk_type']), intval($params['record_id']), $limit ); return $this->response->success([ 'rows' => $result, 'record_id' => $result ? end($result)['id'] : 0, 'limit' => $limit ]); } /** * 查询聊天历史记录 * * @RequestMapping(path="history", methods="get") */ public function history(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id', 'msg_type']); $this->validate($params, [ 'talk_type' => 'required|in:1,2', 'receiver_id' => 'required|integer|min:1', 'record_id' => 'required|integer|min:0', 'msg_type' => 'required|integer', ]); $user_id = $this->uid(); if ($params['talk_type'] == TalkModeConstant::GROUP_CHAT && !di()->get(GroupMemberService::class)->isMember((int)$params['receiver_id'], $user_id)) { return $this->response->fail('暂不属于好友关系或群聊成员,无法查看聊天记录!'); } $types = [ TalkMessageType::TEXT_MESSAGE, TalkMessageType::FILE_MESSAGE, TalkMessageType::FORWARD_MESSAGE, TalkMessageType::CODE_MESSAGE, TalkMessageType::VOTE_MESSAGE ]; if (in_array($params['msg_type'], $types)) { $msg_type = [$params['msg_type']]; } else { $msg_type = $types; } $limit = 30; $result = $this->talkService->getChatRecords( $user_id, (int)$params['receiver_id'], (int)$params['talk_type'], (int)$params['record_id'], $limit, $msg_type ); return $this->response->success([ 'rows' => $result, 'record_id' => $result ? end($result)['id'] : 0, 'limit' => $limit ]); } /** * 获取转发记录详情 * * @RequestMapping(path="forward", methods="get") */ public function forwards(): ResponseInterface { $params = $this->request->inputs(['record_id']); $this->validate($params, [ 'record_id' => 'required|integer|min:1' ]); $rows = $this->talkService->getForwardRecords($this->uid(), intval($params['record_id'])); return $this->response->success(['rows' => $rows]); } }