where('status',1)->order('id desc')->find(); if(!$find){ $this->error('没有进行中的投票活动'); } $find = info_domain_image($find,['video_file']); $this->success(1,$find); } //选手列表 public function playerlist(){ $subject_id = Db::name('vote_subject')->where('status',1)->order('id desc')->value('id'); if(!$subject_id){ $this->success(1,[]); } $map = [ 'subject_id' => $subject_id, 'status' => 1, ]; //搜索 $keyword = input('keyword',''); if($keyword){ $map['title|suozaidanwei|tuijiangonghui'] = ['LIKE','%'.$keyword.'%']; } $lists = Db::name('vote_player') ->where($map)->order('votes desc,id desc')->autopage()->select(); //当前用户手里有票,按钮:投票 //用户手里没有票,但是还能答题,按钮:答题加票 //以上两者都没有,按钮:投票 foreach($lists as $key => $val){ $val['video_thumb'] = $val['video_file'].'?x-oss-process=video/snapshot,t_0,m_fast,f_jpg'; $val['button'] = 'vote'; $val['button'] = 'answer'; } //$lists = $this->mingci($subject_id,$lists); $this->success(1,$lists); } //选手排行榜 public function playerlist_votes(){ $subject_id = Db::name('vote_subject')->where('status',1)->order('id desc')->value('id'); if(!$subject_id){ $this->success(1,[]); } $map = [ 'subject_id' => $subject_id, 'status' => 1, ]; $lists = Db::name('vote_player') ->where($map)->order('votes desc,id desc')->autopage()->select(); $lists = $this->mingci($subject_id,$lists); $this->success(1,$lists); } //oss视频截贞 https://www.alibabacloud.com/help/zh/oss/user-guide/video-snapshots?spm=a2c63.p38356.0.0.6aaa4b78aOSpJH //使用fast模式截取视频7s处的内容,输出为JPG格式的图片,宽度为800,高度为600。 //处理后的URL为:https://oss-console-img-demo-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/video.mp4?x-oss-process=video/snapshot,t_7000,f_jpg,w_800,h_600,m_fast //选手详情 public function playerinfo(){ $player_id = input('player_id'); if(!$player_id){ $this->error(); } $map = [ 'p.id' => $player_id, ]; $info = Db::name('vote_player')->alias('p') ->field('p.id,p.mobile,p.video_file,p.votes,p.renqi,p.subject_id') ->where($map)->find(); $info = info_domain_image($info,['video_file']); //名次 $players = Db::name('vote_player')->where(['subject_id'=>$info['subject_id'],'status'=>1])->order('votes desc')->column('id,votes'); $id_arr = array_keys($players); $mingci = 1; //名次 $mingci = array_search($info['id'],$id_arr); $mingci++; $info['mingci'] = $mingci; $this->success(1,$info); } //获得我的名次,票数导向 private function mingci($subject_id,$list){ if(empty($list)){ return $list; } //准备数据 $players = Db::name('vote_player')->where(['subject_id'=>$subject_id,'status'=>1])->order('votes desc,id desc')->column('id,votes'); $id_arr = array_keys($players); foreach($list as $key => $val) { $mingci = 1; //名次 $mingci = array_search($val['id'],$id_arr); $mingci++; //赋值名次 $list[$key]['mingci'] = $mingci; } return $list; } }