瀏覽代碼

优化选手投票

lizhen_gitee 5 月之前
父節點
當前提交
ac1fe8f39e

+ 4 - 7
application/api/controller/Player.php

@@ -14,7 +14,7 @@ class Player extends Api
     protected $noNeedLogin = ['playerlist'];
     protected $noNeedRight = ['*'];
 
-    //选手列表
+    //待绑定选手列表
     public function playerlist(){
         $subject_id = 1;
 
@@ -54,7 +54,6 @@ class Player extends Api
         if(!$this->apiLimit('操作太快了,休息一下吧'));
 
         $player_id = input('player_id','');
-
         if(!$player_id){
             $this->error();
         }
@@ -68,18 +67,16 @@ class Player extends Api
         Db::startTrans();
 
         //检查选手
-        $player_info = Db::name('vote_player')->field('id,subject_id,votes,score')->where(['id'=>$player_id,'status'=>1])->lock(true)->find();
+        $player_info = Db::name('vote_player')->field('id,subject_id,votes')->where(['id'=>$player_id])->lock(true)->find();
         if(!$player_info){
             Db::rollback();
             $this->error('不存在的选手');
         }
-        $subject_id = $player_info['subject_id'];
-
 
+        //给选手加票
         $update_data = [
             'votes' => $player_info['votes'] + 1,
         ];
-        //入库
         $update_rs = Db::name('vote_player')->where('id',$player_id)->update($update_data);
         if($update_rs === false){
             Db::rollback();
@@ -89,7 +86,7 @@ class Player extends Api
         //日志
         $data = [
             'user_id' => $this->auth->id,
-            'subject_id' => $subject_id,
+            'subject_id' => $player_info['subject_id'],
             'player_id' => $player_id,
             'createdate' => strtotime(date('Y-m-d')),
             'createtime' => time(),

+ 1 - 0
application/api/controller/Question.php

@@ -168,6 +168,7 @@ class Question extends Api
                     // 匹配答案关键词
                     if (strpos($user_answers, $answer_item['answer']) !== false) {
                         $is_right = true;
+                        break;
                     }
 
                 }

+ 1 - 1
application/api/controller/Subject.php

@@ -42,7 +42,7 @@ class Subject extends Api
         }
 
         $lists = Db::name('vote_player')
-            ->where($map)->order('votes desc,id desc')->autopage()->select();
+            ->where($map)->order('votes desc,id desc')->autopage()->select(); //选手不多,看看不加分页了,直接缓存10秒
 
 //        $button = 'answer';
         //当前用户手里有票,按钮:投票

+ 0 - 3
application/api/controller/User.php

@@ -3,10 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-use app\common\library\Ems;
 use app\common\library\Sms;
-use fast\Random;
-use think\Config;
 use think\Validate;
 use think\Db;