param('personnel_id', '');//员工人力资源表id(两个参数2选1) $customer_resources_id = $request->param('customer_resources_id', '');//学生资源表id(两个参数2选1) if (empty($personnel_id) && empty($customer_resources_id)) { // return fail('缺少参数'); $personnel_id = $this->member_id; } $where = [ 'personnel_id' => $personnel_id, 'customer_resources_id' => $customer_resources_id, ]; $res = (new ChatService())->getChatFriendsPage($where); return success($res); } //获取好友关系详情 public function getChatFriendsInfo(Request $request) { $personnel_id = $request->param('personnel_id','');//员工人力资源表id $customer_resources_id = $request->param('customer_resources_id','');//学生资源表id if (empty($personnel_id) && empty($customer_resources_id)) { return fail('缺少参数'); } $where = [ 'personnel_id' => $personnel_id, 'customer_resources_id' => $customer_resources_id, ]; $res = (new ChatService())->getChatFriendsInfo($where); if(!$res['data']){ //创建好友关系 $add = (new ChatService())->addChatFriends($where); if(!$add['code']){ return fail('创建好友关系失败'); }else{ $res = (new ChatService())->getChatFriendsInfo($where); } } if(!$res['code']){ return fail($res['msg']); } return success($res['data']); } //创建好友关系 public function addChatFriends(Request $request) { $personnel_id = $request->param('personnel_id', ''); $customer_resources_id = $request->param('customer_resources_id', ''); if (empty($personnel_id) || empty($customer_resources_id)) { return fail('缺少参数'); } $where = [ 'personnel_id' => $personnel_id, 'customer_resources_id' => $customer_resources_id, ]; //检测好友关系是否存在 $getChatFriendsInfo = (new ChatService())->getChatFriendsInfo($where); if ($getChatFriendsInfo['data']) { return fail('好友关系已存在'); } $addChatFriends = (new ChatService())->addChatFriends($where); if (!$addChatFriends['code']) { return fail($addChatFriends['msg']); } return success($addChatFriends['data']); } //获取聊天记录 public function getChatMessagesList(Request $request) { $friend_id = $request->param('friend_id', '');//关联chat_friends表id if (empty($friend_id)) { return fail('发送者类型不正确'); } $where = [ 'friend_id' => $friend_id, ]; $res = (new ChatService())->getChatMessagesList($where); return success($res); } //发送聊天内容 public function sendChatMessages(Request $request) { $from_type = $request->param('from_type', '');//发送者类型|personnel=员工,customer=学生(客户) $from_id = $request->param('from_id', '');//发送者ID $to_id = $request->param('to_id', '');//接收者ID $friend_id = $request->param('friend_id', '');//关联chat_friends表id $message_type = $request->param('message_type', '');//消息类型|text=文本,img=图片 $content = $request->param('content', '');//文本内容(JSON 格式扩展字段),文本类型=纯文字,图片类型=绝对路径 if (!in_array($message_type, ['text', 'img'])) { return fail('消息类型不正确'); } if (!in_array($from_type, ['personnel', 'customer'])) { return fail('发送者类型不正确'); } if (empty($from_id) || empty($to_id) || empty($friend_id) || empty($content)) { return fail('缺少参数'); } $data = [ 'from_type' => $from_type, // 发送者类型:personnel=员工,customer=学生(客户) 'from_id' => $from_id, // 发送者ID(员工/学生),根据from_type判断 'to_id' => $to_id, // 接收者ID(员工/学生),根据from_type判断 'friend_id' => $friend_id, // 关联chat_friends表id 'message_type' => $message_type, // 消息类型:text=文本,img=图片 'content' => $content // 文本内容(JSON格式扩展字段) ]; $res = (new ChatService())->sendChatMessages($data); if(!$res['code']){ return fail($res['msg']); } return success($res['data']); } //修改未读消息数量 public function editUnreadCount(Request $request){ $from_type = $request->param('from_type', '');//发送者类型|personnel=员工,customer=学生(客户) $from_id = $request->param('from_id', '');//发送者ID $friend_id = $request->param('friend_id', '');//关联chat_friends表id if (!in_array($from_type, ['personnel', 'customer'])) { return fail('发送者类型不正确'); } if (empty($from_id) || empty($friend_id)) { return fail('缺少参数'); } $res = (new ChatService())->editUnreadCount($from_type,$friend_id); // if(!$res){ // return fail('修改失败'); // } return success($res); } }