Browse Source

今日投票记录,显示我投出的票数

lizhen_gitee 3 months ago
parent
commit
6a8d5aeeb2
1 changed files with 19 additions and 4 deletions
  1. 19 4
      application/api/controller/Subject.php

+ 19 - 4
application/api/controller/Subject.php

@@ -157,15 +157,30 @@ class Subject extends Api
     //今日投票记录
     public function my_vote_history(){
         //今日投票记录
-        $player_ids = Db::name('vote_record')->where('user_id',$this->auth->id)->where('createdate',strtotime(date('Y-m-d')))->column('player_id');
+        $player_votes = Db::name('vote_record')
+            ->where('user_id',$this->auth->id)
+            ->where('createdate',strtotime(date('Y-m-d')))
+            ->group('player_id')
+            ->field('player_id,sum(vote) as votes')
+            ->order('votes desc')
+            ->select();
+
+        $player_ids = array_column($player_votes,'player_id');
         $map = [
             'status' => 1,
             'id' => ['IN',$player_ids]
         ];
-        $lists = Db::name('vote_player')->field('id,title,votes')
-            ->where($map)->order('votes desc,id desc')->select();
+        $players = Db::name('vote_player')->field('id,title')->where($map)->column('title','id');
 
-        $this->success(1,$lists);
+        foreach($player_votes as $key => $val){
+            $val['id'] = $val['player_id'];
+            $val['title'] = isset($players[$val['player_id']]) ? $players[$val['player_id']] : '';
+            unset($val['player_id']);
+
+            $player_votes[$key] = $val;
+        }
+
+        $this->success(1,$player_votes);
     }
 
     //选手票数排行榜,按票