Sfoglia il codice sorgente

取题前置接口

lizhen_gitee 4 mesi fa
parent
commit
1e3f25d429

+ 41 - 0
application/api/controller/Demo.php

@@ -41,6 +41,47 @@ class Demo extends Api
          'msg':'返回成功'
         })
      */
+
+    public function test222(){
+
+        $user_id = 2;
+        $bind_jigou_id = 2;
+
+        //机构得分记录
+        $map = [
+            'user_id' => $user_id,
+            'is_right' => 1,
+            'jigou_id' => ['neq',$bind_jigou_id],
+        ];
+        $jigou = Db::name('user_question_log')->where($map)->column('jigou_id');
+        if(empty($jigou)){
+            return true;
+        }
+dump($jigou);
+        $jigou_data = array_count_values($jigou);
+        dump($jigou_data);
+exit;
+        //老机构减分。循环不会太多次
+        foreach($jigou_data as $jigou_id => $times){
+            Db::table('vote_jigou')->where(['id' => $jigou_id])->decrement(['score'=>$times]);
+        }
+
+        //新机构加分
+        Db::table('vote_jigou')->where(['id' => $bind_jigou_id])->increment('score',count($jigou));
+
+
+        //用户答题记录,都改成现在的机构id
+        Db::table('user_question_log')->where(['user_id' => $user_id])->update(['jigou_id'=>$bind_jigou_id]);
+
+
+//        Db::commit();
+        Db::rollBack();
+
+        echo '结束了';
+        return;
+
+    }
+
     public function test()
     {
         $params = [

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

@@ -15,6 +15,19 @@ class Question extends Api
     protected $noNeedLogin = [];
     protected $noNeedRight = ['*'];
 
+    //取题之前弹机构
+    public function get_question_before(){
+
+        $jigou = Db::name('vote_jigou')->where('id',$this->auth->bind_jigou_id)->value('title');
+        $times = config('site.bind_jigou_times') - $this->auth->bind_jigou_times;
+
+        $rs = [
+            'bind_jigou_id' => $this->auth->bind_jigou_id,
+            'jigou_title'   => $jigou,
+            'times'         => $times,
+        ];
+        $this->success(1,$rs);
+    }
 
     //获取10个题
     public function get_question(){