Browse Source

投票展示接口

lizhen_gitee 5 months ago
parent
commit
c070706f97
1 changed files with 66 additions and 14 deletions
  1. 66 14
      application/api/controller/Subject.php

+ 66 - 14
application/api/controller/Subject.php

@@ -22,7 +22,6 @@ class Subject extends Api
         if(!$find){
             $this->error('没有进行中的投票活动');
         }
-        $find = info_domain_image($find,['video_file']);
 
         $this->success(1,$find);
     }
@@ -48,16 +47,27 @@ class Subject extends Api
         $lists = Db::name('vote_player')
             ->where($map)->order('votes desc,id desc')->autopage()->select();
 
-
+//        $button = 'answer';
         //当前用户手里有票,按钮:投票
-        //用户手里没有票,但是还能答题,按钮:答题加票
+        //用户手里没有票,但是今天还能答题,按钮:答题加票
+        /*$user_votes = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('votes');
+        $user_question_count = Db::name('user_question_log')->where('user_id',$this->auth->id)->whereTime('createtime','today')->count('id');
+        $exam_times_user_eday = config('site.exam_times_user_eday');
+        if($user_votes == 0 && $user_question_count <= $exam_times_user_eday){
+            $button = 'answer';
+        }*/
         //以上两者都没有,按钮:投票
 
         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';
+            $val['video_thumb'] = '';
+            if(!empty($val['video_file'])){
+                $val['video_thumb'] = $val['video_file'].'?x-oss-process=video/snapshot,t_0,m_fast,f_jpg';
+            }
+
+//            $val['button'] = $button;
+
+            $lists[$key] = $val;
         }
 
         //$lists = $this->mingci($subject_id,$lists);
@@ -65,7 +75,7 @@ class Subject extends Api
         $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){
@@ -74,14 +84,33 @@ class Subject extends Api
 
         $map = [
             'subject_id' => $subject_id,
-            'status' => 1,
+            'status'     => 1,
         ];
 
-
-        $lists = Db::name('vote_player')
+        $lists = Db::name('vote_player')->field('id,title,votes')
             ->where($map)->order('votes desc,id desc')->autopage()->select();
 
-        $lists = $this->mingci($subject_id,$lists);
+        $lists = $this->mingci_vote($subject_id,$lists);
+
+        $this->success(1,$lists);
+    }
+
+    //选手票数排行榜,按分
+    public function playerlist_score(){
+        $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')->field('id,title,score')
+            ->where($map)->order('score desc,id desc')->autopage()->select();
+
+        $lists = $this->mingci_score($subject_id,$lists);
 
         $this->success(1,$lists);
     }
@@ -92,7 +121,7 @@ class Subject extends Api
 
 
     //选手详情
-    public function playerinfo(){
+    /*public function playerinfo(){
         $player_id = input('player_id');
         if(!$player_id){
             $this->error();
@@ -116,11 +145,11 @@ class Subject extends Api
         $info['mingci'] = $mingci;
 
         $this->success(1,$info);
-    }
+    }*/
 
 
     //获得我的名次,票数导向
-    private function mingci($subject_id,$list){
+    private function mingci_vote($subject_id,$list){
 
         if(empty($list)){
             return $list;
@@ -141,4 +170,27 @@ class Subject extends Api
 
         return $list;
     }
+
+    //获得我的名次,分数导向
+    private function mingci_score($subject_id,$list){
+
+        if(empty($list)){
+            return $list;
+        }
+        //准备数据
+        $players = Db::name('vote_player')->where(['subject_id'=>$subject_id,'status'=>1])->order('score desc,id desc')->column('id,score');
+        $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;
+    }
 }