Browse Source

作者修改优化bug等、、、

master
wanghongjun 6 months ago
parent
commit
92247ed88d
  1. 5
      app/enterprise/controller/Friend.php
  2. 3
      app/enterprise/controller/Group.php
  3. 4
      app/enterprise/controller/Im.php
  4. 6
      app/enterprise/model/User.php
  5. 4
      app/manage/controller/Index.php
  6. 62
      app/worker/Events.php

5
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'));
}

3
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;

4
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();
// 如果是最后一条消息,需要将上一条设置为最后一条

6
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');

4
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;

62
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));
}
}

Loading…
Cancel
Save