From 92247ed88d9b38b1bb208aa9db1e9b1c9c763d58 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Mon, 16 Jun 2025 15:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E8=80=85=E4=BF=AE=E6=94=B9=E4=BC=98?= =?UTF-8?q?=E5=8C=96bug=E7=AD=89=E3=80=81=E3=80=81=E3=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/enterprise/controller/Friend.php | 5 ++- app/enterprise/controller/Group.php | 3 +- app/enterprise/controller/Im.php | 4 +- app/enterprise/model/User.php | 6 +++ app/manage/controller/Index.php | 4 +- app/worker/Events.php | 62 ++++++++++++++++++---------- 6 files changed, 56 insertions(+), 28 deletions(-) diff --git a/app/enterprise/controller/Friend.php b/app/enterprise/controller/Friend.php index ff5e892..fa56a55 100644 --- a/app/enterprise/controller/Friend.php +++ b/app/enterprise/controller/Friend.php @@ -42,6 +42,9 @@ class Friend extends BaseController { $param = $this->request->param(); $user_id=$param['user_id'] ?? 0; + if(!$user_id){ + return warning(lang('system.notNull')); + } if($user_id==$this->uid){ return warning(lang('friend.notAddOwn')); } @@ -137,7 +140,7 @@ class Friend extends BaseController } } - return success(''); + return success(lang('system.success')); } diff --git a/app/enterprise/controller/Group.php b/app/enterprise/controller/Group.php index 555e25d..ca3ef97 100644 --- a/app/enterprise/controller/Group.php +++ b/app/enterprise/controller/Group.php @@ -69,7 +69,8 @@ class Group extends BaseController $qrUrl=getMainHost().'/scan/g/'.$token; $group['id']=$groupId; $group['qrUrl']=$qrUrl; - $group['qrExpire']=date('m月d日',$expire); + //$group['qrExpire']=date('m月d日',$expire); + $group['qrExpire']=date('m-d',$expire); $group['userInfo']=$userInfo; $group['ownerName']=$userInfo['realname']; $group['groupUserCount']=$userCount; diff --git a/app/enterprise/controller/Im.php b/app/enterprise/controller/Im.php index 7423c5c..ccc8613 100644 --- a/app/enterprise/controller/Im.php +++ b/app/enterprise/controller/Im.php @@ -822,12 +822,12 @@ class Im extends BaseController $param = $this->request->param(); $id = $param['id']; if(!$this->globalConfig['chatInfo']['dbDelMsg']){ - return warning(lang('system.noAuth')); + return warning(lang('system.notAuth')); } $message = Message::where(['id' => $id])->find(); if ($message) { if($message['from_user']!=$this->userInfo['user_id']){ - return warning(lang('system.noAuth')); + return warning(lang('system.notAuth')); } Message::where(['id' => $id])->find()->delete(); // 如果是最后一条消息,需要将上一条设置为最后一条 diff --git a/app/enterprise/model/User.php b/app/enterprise/model/User.php index d71870d..73a9fd4 100644 --- a/app/enterprise/model/User.php +++ b/app/enterprise/model/User.php @@ -132,6 +132,12 @@ class User extends BaseModel if($csUid){ $userList[]=$csUid; } + // 如果我有客服权限,就查询客服的好友 + $cus=self::where(['cs_uid'=>$user_id])->column('user_id'); + if($cus){ + $userList=array_merge($userList,$cus); + } + $userList = array_unique($userList); $list = self::where($map)->where('user_id', 'in', $userList)->field($field)->select(); } $list_chart = chartSort($list, 'realname', false, 'index'); diff --git a/app/manage/controller/Index.php b/app/manage/controller/Index.php index b862aa9..453a5be 100644 --- a/app/manage/controller/Index.php +++ b/app/manage/controller/Index.php @@ -38,7 +38,7 @@ class Index extends BaseController // 清理消息 public function clearMessage(){ if($this->userInfo['user_id']!=1){ - return warning('system.noAuth'); + return warning('system.notAuth'); } $res = Message::where(['status'=>1])->select(); foreach ($res as $resMsg) { @@ -79,7 +79,7 @@ class Index extends BaseController public function publishNotice(){ $userInfo=$this->userInfo; if($userInfo['user_id']!=1){ - return warning('system.noAuth'); + return warning('system.notAuth'); } $param=$this->request->param(); $msgId=$param['msgId'] ?? 0; diff --git a/app/worker/Events.php b/app/worker/Events.php index be4ee0c..7680f22 100644 --- a/app/worker/Events.php +++ b/app/worker/Events.php @@ -41,38 +41,39 @@ class Events 'type' => 'init', 'client_id' => $client_id ))); + self::onlineStatistics(); } /** - * 有消息时 - * @param int $client_id - * @param mixed $message - */ - public static function onMessage($client_id, $message) - { + * 有消息时 + * @param int $client_id + * @param mixed $message + */ + public static function onMessage($client_id, $message) + { // 客户端传递的是json数据 $message_data = json_decode($message, true); if(!$message_data) { return ; } - + // 根据类型执行不同的业务 switch($message_data['type']) { // 客户端回应服务端的心跳 case 'pong': - break; + break; case 'ping': self::sendStatus($client_id); - break; + break; case 'bindUid': self::auth($client_id,$message_data); - break; + break; } return; - } + } - protected static function sendStatus($client_id){ + protected static function sendStatus($client_id){ $uid=$_SESSION['user_id'] ?? 0; $multiport=false; if($uid){ @@ -85,7 +86,7 @@ class Events 'type' => 'pong', 'multiport' => $multiport, ))); - } + } //验证用户的真实性并绑定 protected static function auth($client_id, $msg){ @@ -113,30 +114,47 @@ class Events self::closeClient($client_id); } $_SESSION['user_id']=$userInfo['user_id']; + self::sendStatus($client_id); } //断开连接 protected static function closeClient($client_id){ + self::onlineStatistics(); $_SESSION['user_id']=null; Gateway::closeClient($client_id); } /** - * 当断开连接时 - * @param int $client_id - */ + * 当断开连接时 + * @param int $client_id + */ public static function onClose($client_id) { $user_id=$_SESSION['user_id']; if($user_id){ Gateway::sendToAll(json_encode(array( - 'type' => 'isOnline', - 'time' => time(), - 'data' => ['id'=>$user_id,'is_online'=>0] - ))); + 'type' => 'isOnline', + 'time' => time(), + 'data' => ['id'=>$user_id,'is_online'=>0] + ))); } - + self::onlineStatistics(); } - + + public static function onlineStatistics() + { + // 通知后台在线用户数和在线设备数 + $data=[ + 'type' => 'statistics', + 'time' => time(), + 'data' => [ + 'onlineCount'=>Gateway::getAllUidCount() ?? 0, + 'clientCount'=>Gateway::getAllClientCount() ?? 0, + ] + ]; + Gateway::sendToGroup('admin-manage', json_encode($data)); + Gateway::sendToUid(1, json_encode($data)); + } + }