MonitorController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * 直播监控
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. use think\db\Query;
  9. class MonitorController extends AdminbaseController {
  10. public function index(){
  11. $lists = Db::name('user_live')
  12. ->where(function (Query $query) {
  13. $data = $this->request->param();
  14. $query->where('islive', '=' , '1');
  15. $query->where('isvideo', '=' , '0');
  16. $data = $this->request->param();
  17. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  18. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  19. if (!empty($start_time)) {
  20. $query->where('starttime', '>=' , strtotime($start_time));
  21. }
  22. if (!empty($end_time)) {
  23. $query->where('starttime', '<=' ,strtotime($end_time));
  24. }
  25. if (!empty($start_time) && !empty($end_time)) {
  26. $query->where('starttime', 'between' , [strtotime($start_time),strtotime($end_time)]);
  27. }
  28. $keyword=isset($data['keyword']) ? $data['keyword']: '';
  29. if (!empty($keyword)) {
  30. $query->where('uid', 'like', "%$keyword%");
  31. }
  32. })
  33. ->order("starttime DESC")
  34. ->paginate(6);
  35. $lists->each(function($v,$k){
  36. $userinfo=getUserInfo($v['uid']);
  37. $auth_url=urldecode(PrivateKeyA('http',$v['stream'],0));
  38. $v['userinfo']= $userinfo;
  39. $v['url']= $auth_url;
  40. //$v['url']= $v['pull']; //测试用
  41. return $v;
  42. });
  43. //分页-->筛选条件参数
  44. $data = $this->request->param();
  45. $lists->appends($data);
  46. // 获取分页显示
  47. $page = $lists->render();
  48. $configpri=getConfigPri();
  49. $this->assign('lists', $lists);
  50. $this->assign("page", $page);
  51. $this->assign("time", time());
  52. $this->assign('configpri', $configpri);
  53. return $this->fetch();
  54. }
  55. public function full(){
  56. $uid=$this->request->param('uid',0,'intval');
  57. $live=Db::name("user_live")->where(['islive'=>1,'uid'=>$uid])->find();
  58. if($live['title']==""){
  59. $live['title']="直播监控后台";
  60. }
  61. $pull=urldecode(PrivateKeyA('http',$live['stream'],0));
  62. $live['pull']=$pull;
  63. $configpri=getConfigPri();
  64. $this->assign('configpri',$configpri);
  65. $this->assign('live',$live);
  66. return $this->fetch();
  67. }
  68. public function stopRoom(){
  69. $msg='';
  70. $data = $this->request->param();
  71. $uid=isset($data['uid']) ? $data['uid']: '';
  72. $ban_long=isset($data['ban_long']) ? $data['ban_long']: ''; //封禁时间
  73. if(!$uid){
  74. echo json_encode( array("status"=>'0','info'=>'参数错误') );
  75. return;
  76. }
  77. $where['islive']=1;
  78. $where['uid']=$uid;
  79. $liveinfo=Db::name("user_live")
  80. ->field("uid,showid,starttime,title,province,city,stream")
  81. ->where($where)
  82. ->find();
  83. Db::name("user_live")->where(" uid='{$uid}'")->delete();
  84. if($liveinfo){
  85. $liveinfo['endtime']=time();
  86. $liveinfo['time']=date("Y-m-d",$liveinfo['showid']);
  87. $where2=[];
  88. $where2['touid']=$uid;
  89. $where2['showid']=$liveinfo['showid'];
  90. $votes=Db::name("user_coinrecord")
  91. ->where($where2)
  92. ->sum('totalcoin');
  93. $liveinfo['votes']=0;
  94. if($votes){
  95. $liveinfo['votes']=$votes;
  96. }
  97. $stream=$liveinfo['stream'];
  98. $nums=zSize('user_'.$stream);
  99. $liveinfo['nums']=$nums;
  100. hDel("livelist",$uid);
  101. delcache($uid.'_zombie');
  102. delcache($uid.'_zombie_uid');
  103. delcache('attention_'.$uid);
  104. delcache('user_'.$stream);
  105. Db::name("user_liverecord")->insert($liveinfo);
  106. //封禁记录
  107. if($ban_long!=''){
  108. $time=time();
  109. $long_arr=explode('_',$ban_long); //将字符串分隔
  110. $long=$long_arr['0'];
  111. $long_type=$long_arr['1'];
  112. if($long_type==1){
  113. $msg="您的直播涉嫌违规, 平台将封禁{$long}分钟";
  114. $long=$time+60*$long;
  115. }else if($long_type==2){
  116. $msg="您的直播涉嫌违规, 平台将封禁{$long}天";
  117. $long=$time+60*60*24*$long;
  118. }else{
  119. $long=0;
  120. $msg="您的直播涉嫌违规, 平台将永久封禁";
  121. }
  122. $long_data=[];
  123. $long_data['uid']=$uid;
  124. $long_data['addtime']=$time;
  125. $long_data['end_time']=$long;
  126. Db::name("user_live_ban")->insert($long_data);
  127. }
  128. }
  129. echo json_encode( array("status"=>'1','info'=>$msg) );
  130. }
  131. }