diff --git a/app/enterprise/controller/Im.php b/app/enterprise/controller/Im.php index 9807293..62156e5 100644 --- a/app/enterprise/controller/Im.php +++ b/app/enterprise/controller/Im.php @@ -50,6 +50,20 @@ class Im extends BaseController } } + // 被拉黑重新发送 + public function againSendMessage() + { + $param = $this->request->param(); + $param['user_id'] = $this->userInfo['user_id']; + $message=new Message(); + $data = $message->againSendMessage($param); + if ($data) { + return success('', $data); + } else { + return warning($message->getError()); + } + } + //转发消息 public function forwardMessage() { @@ -228,10 +242,10 @@ class Im extends BaseController $chat_identify = $this->setIsRead($is_group, $param['toContactId']); $type = isset($param['type']) ? $param['type'] : ''; $is_at = isset($param['is_at']) ? $param['is_at'] : ''; - $map = ['chat_identify' => $chat_identify, 'status' => 1]; + $map = [['chat_identify','=',$chat_identify], ['status','in',[1,2]]]; $where = []; if ($type && $type != "all") { - $map['type'] = $type; + $map[] = ['type','=',$type]; } else { if (isset($param['type'])) { $where[] = ['type', '<>', 'event']; @@ -340,10 +354,14 @@ class Im extends BaseController if (!is_numeric($v['create_time'])) { $v['create_time'] = strtotime($v['create_time']); } + $status_str = "succeed"; + if ($v['status'] == 2) { + $status_str = "failed"; + } $data[] = [ 'msg_id' => $v['msg_id'], 'id' => $v['id'], - 'status' => "succeed", + 'status' => $status_str, 'type' => $v['type'], 'sendTime' => is_numeric($v['create_time']) ? $v['create_time'] * 1000 : strtotime($v['create_time']) * 1000, 'content' => $content, diff --git a/app/enterprise/model/Message.php b/app/enterprise/model/Message.php index fdac406..f29963c 100644 --- a/app/enterprise/model/Message.php +++ b/app/enterprise/model/Message.php @@ -110,12 +110,10 @@ class Message extends BaseModel return false; } if ($friend['is_blacklist'] == 1) { - $this->error=lang('im.youBlacklist'); - return false; + $param['del_user'] = $param['toContactId']; } if ($otherFriend['is_blacklist'] == 1) { - $this->error=lang('im.meBlacklist'); - return false; + $param['del_user'] = $param['toContactId']; } } } @@ -211,6 +209,10 @@ class Message extends BaseModel $param['poster']=$data['poster']; } } + if (isset($param['del_user']) && $param['del_user']) { + $data['del_user'] = $param['del_user']; + $data['status'] = 2; + } $message=new self(); $message->update(['is_last'=>0],['chat_identify'=>$chat_identify]); $message->save($data); @@ -219,6 +221,9 @@ class Message extends BaseModel $type=$is_group?'group':'simple'; $sendData=$param; $sendData['status']='succeed'; + if (isset($data['status']) && $data['status'] == 2) { + $sendData['status']='failed'; + } $sendData['at']=$atList; $sendData['msg_id']=$message->msg_id; $sendData['is_read']=0; @@ -248,7 +253,11 @@ class Message extends BaseModel $sendData['download']= $sendData['file_id'] ? getMainHost().'/filedown/'.encryptIds($sendData['file_id']) : ''; } if($is_group==0){ - $toContactId=[$toContactId,$param['user_id']]; + if ($sendData['status'] == 'succeed') { + $toContactId=[$toContactId,$param['user_id']]; + } else { + $toContactId=[$param['user_id']]; + } } $sendData['toUser']=$param['toContactId']; $user=new User(); @@ -258,7 +267,90 @@ class Message extends BaseModel wsSendMsg($toContactId,$type,$sendData,$is_group); $sendData['toContactId']=$param['toContactId']; return $sendData; -} + } + + // 被拉黑重新发送 + public function againSendMessage($param) + { + $msg_id = $param['msg_id']; + $toContactId = $param['toContactId']; + $uid = $param['user_id']; + // 验证是否是好友 + $friend = Friend::where(['friend_user_id' => $uid, 'create_user' => $toContactId])->find(); + if (!$friend) { + $this->error=lang('im.notFriend'); + return false; + } + $otherFriend = Friend::where(['friend_user_id' => $toContactId, 'create_user' => $uid])->find(); + if (!$otherFriend) { + $this->error=lang('im.friendNot'); + return false; + } + // 判断是否拉黑 + if ($friend['is_blacklist'] == 1) { + $this->error=lang('im.youBlacklist'); + return false; + } + if ($otherFriend['is_blacklist'] == 1) { + $this->error=lang('im.meBlacklist'); + return false; + } + $where = [ + 'msg_id' => $msg_id, + 'to_user' => $toContactId, + 'from_user' => $uid, + 'status' => 2 + ]; + $message = Message::where($where)->find(); + if (!$message) { + $this->error=lang('system.error'); + return false; + } + $message->status = 1; + $message->del_user = ''; + $message->save(); + + // 拼接消息推送 + $is_group = 0; + $type='simple'; + $sendData=$param; + $sendData['status']='succeed'; + if (isset($data['status']) && $data['status'] == 2) { + $sendData['status']='failed'; + } + $sendData['at']=[]; + $sendData['msg_id']=$message->msg_id; + $sendData['is_read']=0; + $sendData['to_user']=$toContactId; + $sendData['role']=$manage[self::$uid] ?? 3; + $sendData['sendTime']=(int)$sendData['sendTime']; + //这里单聊中发送对方的消息,对方是接受状态,自己是对方的联系人,要把发送对象设置为发送者的ID。 + $sendData['toContactId']=$uid; + + $sendData['fromUser']['id']=(int)$sendData['fromUser']['id']; + $sendData['fileSize']=isset($param['file_size'])?$param['file_size']:''; + $sendData['fileName']=isset($param['file_name'])?$param['file_name']:''; + if(in_array($sendData['type'],self::$fileType)){ + $sendData['content']=getFileUrl($sendData['content']); + if($sendData['type']=='image'){ + $pre=1; + }else{ + $pre=2; + } + $sendData['preview']=previewUrl($sendData['content'],$pre); + $sendData['extUrl']=getExtUrl($sendData['content']); + $sendData['download']= $sendData['file_id'] ? getMainHost().'/filedown/'.encryptIds($sendData['file_id']) : ''; + } + $toContactId=[$toContactId,$param['user_id']]; + $sendData['toUser']=$param['toContactId']; + $user=new User(); + // 将聊天窗口的联系人信息带上,方便临时会话 + $sendData['contactInfo']=$user->setContact($sendData['toContactId'],$is_group,$sendData['type'],$sendData['content']); + // 向发送方发送消息 + wsSendMsg($toContactId,$type,$sendData,$is_group); + $sendData['toContactId']=$param['toContactId']; + return $sendData; + } // 群禁言 public static function nospeak($group_id,$user_id){