Index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User Julyssn
  5. * Date 2022/12/14 17:24
  6. */
  7. namespace app\manage\controller;
  8. use app\BaseController;
  9. use app\enterprise\model\{Message,User,Group,File};
  10. use GatewayClient\Gateway;
  11. class Index extends BaseController
  12. {
  13. // 超级管理员专属功能
  14. public function index(){
  15. Gateway::$registerAddress = config('gateway.registerAddress');
  16. $client_id=$this->request->param('client_id','');
  17. $is_join=0;
  18. if($client_id){
  19. Gateway::joinGroup($client_id, 'admin-manage');
  20. $is_join=1;
  21. }
  22. $data=[
  23. 'userCount'=>User::where(['status'=>1])->count(),
  24. 'groupCount'=>Group::where(['status'=>1])->count(),
  25. 'messageCount'=>Message::where(['status'=>1])->where([['type', 'not in', ['event','admin_notice','webrtc']]])->count(),
  26. 'fileCount'=>File::where(['status'=>1])->count(),
  27. 'onlineCount'=>Gateway::getAllUidCount() ?? 0,
  28. 'clientCount'=>Gateway::getAllClientCount() ?? 0,
  29. 'isJoin'=>$is_join,
  30. ];
  31. return success('', $data);
  32. }
  33. // 清理消息
  34. public function clearMessage(){
  35. if($this->userInfo['user_id']!=1){
  36. return warning('system.notAuth');
  37. }
  38. Message::where(['status'=>1])->delete();
  39. return success('system.clearOk');
  40. }
  41. // 公告列表
  42. public function noticeList(){
  43. $model=new Message();
  44. // 排序
  45. $order='msg_id DESC';
  46. $map=['chat_identify'=>"admin_notice"];
  47. $list = $this->paginate($model->where($map)->order($order));
  48. if ($list) {
  49. $data = $list->toArray()['data'];
  50. foreach($data as $k=>$v){
  51. $data[$k]['title']=$v['extends']['title'];
  52. }
  53. }
  54. return success('', $data, $list->total(), $list->currentPage());
  55. }
  56. // 删除公告
  57. public function delNotice(){
  58. $param=$this->request->param();
  59. $msgId=$param['id'] ?:0;
  60. $map=['msg_id'=>$msgId];
  61. $message=Message::where($map)->find();
  62. if($message){
  63. Message::where($map)->delete();
  64. }
  65. return success('');
  66. }
  67. // 发布公告
  68. public function publishNotice(){
  69. $userInfo=$this->userInfo;
  70. if($userInfo['user_id']!=1){
  71. return warning('system.notAuth');
  72. }
  73. $param=$this->request->param();
  74. $msgId=$param['msgId'] ?? 0;
  75. $content="<h4>".$param['title']."</h4><br><p>".$param['content']."</p>";
  76. $data=[
  77. 'from_user'=>$userInfo['user_id'],
  78. 'to_user'=>0,
  79. 'content'=>str_encipher($content,true),
  80. 'chat_identify'=>'admin_notice',
  81. 'create_time'=>time(),
  82. 'type'=>'text',
  83. 'is_group'=>2,
  84. 'is_read'=>1,
  85. 'is_top'=>0,
  86. 'is_notice'=>1,
  87. 'at'=>[],
  88. 'pid'=>0,
  89. 'extends'=>['title'=>$param['title'],'notice'=>$param['content']],
  90. ];
  91. if($msgId){
  92. Message::where(['msg_id'=>$msgId])->update([
  93. 'content'=>$data['content'],
  94. 'extends'=>$data['extends'],
  95. ]);
  96. }else{
  97. $data['id']=\utils\Str::getUuid();
  98. $message=new Message();
  99. $message->save($data);
  100. $msgId=$message->msg_id;
  101. }
  102. $msgInfo=$data;
  103. $msgInfo['status']='successd';
  104. $msgInfo['msg_id']=$msgId;
  105. $msgInfo['user_id']=$userInfo['user_id'];
  106. $msgInfo['sendTime']=time()*1000;
  107. $msgInfo['toContactId']='admin_notice';
  108. $msgInfo['to_user']='admin_notice';
  109. $msgInfo['content']=$param['title'];
  110. $msgInfo['fromUser']=[
  111. 'id'=>$userInfo['user_id'],
  112. 'avatar'=>avatarUrl($userInfo['avatar'],$userInfo['realname'],$userInfo['user_id'],120),
  113. 'displayName'=>$userInfo['realname']
  114. ];
  115. wsSendMsg(0,'simple',$msgInfo,1);
  116. return success('');
  117. }
  118. }