order('list_order asc, id desc')->column('id,name'); return $liveclass; } protected function getTypes($k=''){ $type=[ '0'=>'普通房间', '1'=>'密码房间', '2'=>'门票房间', '3'=>'计时房间', ]; if($k===''){ return $type; } return $type[$k]; } function index(){ $data = $this->request->param(); $map=[]; $map[]=['islive','=',1]; $start_time= $data['start_time'] ?? ''; $end_time= $data['end_time'] ?? ''; if($start_time!=""){ $map[]=['starttime','>=',strtotime($start_time)]; } if($end_time!=""){ $map[]=['starttime','<=',strtotime($end_time) + 60*60*24]; } $uid=$data['uid'] ?? ''; if($uid!=''){ $map[]=['uid','=',$uid]; } $configpri=getConfigPri(); $lists = Db::name("user_live") ->where($map) ->order("starttime DESC") ->paginate(20); $liveclass=$this->getLiveClass(); array_push($liveclass,['id'=>0,'name'=>'默认分类']); $lists->each(function($v,$k) use ($configpri,$liveclass){ $v['userinfo']=getUserInfo($v['uid']); $where=[]; $where['action']='sendgift'; $where['touid']=$v['uid']; $where['showid']=$v['showid']; /* 本场总收益 */ $totalcoin=Db::name("user_coinrecord")->where($where)->sum('totalcoin'); if(!$totalcoin){ $totalcoin=0; } /* 送礼物总人数 */ $total_nums=Db::name("user_coinrecord")->where($where)->group("uid")->count(); if(!$total_nums){ $total_nums=0; } /* 人均 */ $total_average=0; if($totalcoin && $total_nums){ $total_average=round($totalcoin/$total_nums,2); } /* 人数 */ $nums=zSize('user_'.$v['stream']); $v['totalcoin']=$totalcoin; $v['total_nums']=$total_nums; $v['total_average']=$total_average; $v['nums']=$nums; if($v['isvideo']==0 && $configpri['cdn_switch']!=5){ $v['pull']=PrivateKeyA('rtmp',$v['stream'],0); } foreach ($liveclass as $k1 => $v1) { if($v['liveclassid']==$v1['id']){ $v['liveclassname']=$v1['name']; break; } } return $v; }); /*var_dump($lists); die;*/ $lists->appends($data); $page = $lists->render(); $this->assign('lists', $lists); $this->assign("page", $page); $this->assign("type", $this->getTypes()); return $this->fetch(); } public function add(){ $this->assign("liveclass", $this->getLiveClass()); return $this->fetch(); } //添加保存 public function add_post(){ if($this->request->ispost()){ $data=$this->request->param(); $uid=$data['uid']; $pull=urldecode($data['pull']); $liveclassid=$data['liveclassid']; $userinfo=getUserInfo($uid); if(!$userinfo){ $this->error('用户不存在'); } $nowtime=time(); if($userinfo['recommend_time']==0){ $userinfo['recommend_time']=$nowtime; } $liveinfo=Db::name("user_live")->field("uid,islive")->where(['uid'=>$uid])->find(); if($liveinfo){ $this->error("该用户正在直播"); } $stream=$uid.'_'.$nowtime; $data=array( "uid"=>$uid, "showid"=>$nowtime, "starttime"=>$nowtime, "title"=>'', "province"=>'', "city"=>'好像在火星', "stream"=>$stream, "thumb"=>'', "pull"=>$pull, "isvideo"=>1, "islive"=>1, "isrecommend"=>$userinfo['isrecommend'], "recommend_time"=>$userinfo['recommend_time'], "liveclassid"=>$liveclassid, ); if($liveinfo){ $result=Db::name("user_live")->where(['uid'=>$uid])->update($data); }else{ $result=Db::name("user_live")->insert($data); } if($result!==false){ $this->success('添加成功'); }else{ $this->error('添加失败'); } } } public function edit(){ $uid=$this->request->param('uid'); if($uid){ $live=Db::name("user_live")->where("uid={$uid}")->find(); $this->assign('live', $live); }else{ $this->error('数据传入失败!'); } $this->assign("liveclass", $this->getLiveClass()); return $this->fetch(); } public function edit_post(){ if($this->request->ispost()){ $data=$this->request->param(); $pull=$data['pull']; if($pull==''){ $this->error('请填写视频地址'); } $uid=$data['uid']; $result=Db::name("user_live")->where(['uid'=>$uid])->update($data); if($result!==false){ $this->success('修改成功'); }else{ $this->error('修改失败'); } } } public function del(){ $id=$this->request->param('id',0,'intval'); if($id){ $result=Db::name("user_live")->where(["uid"=>$id])->delete(); if($result){ $this->success('删除成功'); }else{ $this->error('删除失败'); } }else{ $this->error('数据传入失败!'); } } }