user->toArray(); $list = $this->getFriendList(); $friend = []; if (!empty($list)) { foreach ($list as $info) { $friend[] = [ 'id' => $info['id'], 'nickname' => $info['nickname'] ]; } } $user['friend'] = $friend; unset($user['password']); unset($user['salt']); unset($user['fd']); unset($user['user_relation']); return JsonReturn::success('', $user); } public function sendMessage() { $friend_id = Request::post('friend', 0, 'intval'); $friend = array_column($this->getFriendList(), null, 'id'); $message = Request::post('message', ''); if (empty($friend) || $friend == $this->user->id) { throw new ServiceException('非法操作!'); } if (!array_key_exists($friend_id, $friend)) { throw new ServiceException('请成为好友后再发送消息!'); } if (empty($message)) { throw new ServiceException('不能发送空消息!'); } $data = [ 'send_id' => $this->user->id, 'take_id' => $friend_id, 'send_nickname' => $this->user->nickname, 'take_nickname' => $friend[$friend_id]['nickname'], 'message' => $message ]; return $data; } }