Просмотр исходного кода

答对一题得N票,得N分,有个基数

lizhen_gitee 2 дней назад
Родитель
Сommit
5a452da17d
2 измененных файлов с 36 добавлено и 4 удалено
  1. 2 2
      app/Controller/Api/v1/QuestionController.php
  2. 34 2
      app/Job/BindjigouJob.php

+ 2 - 2
app/Controller/Api/v1/QuestionController.php

@@ -71,7 +71,7 @@ class QuestionController extends AbstractController
 
         //曾经 答题贡献的分数,用户曾经都要给到新机构
         if(!empty($user['bind_jigou_id'])){
-            $this->service->bindjigouPush(['user_id' => $user['id'], 'bind_jigou_id' => $jigou_id], 0);
+            $this->service->bindjigouPush(['user_id' => $user['id'], 'old_jigou_id' => $user['bind_jigou_id'], 'new_jigou_id' => $jigou_id], 0);
         }
 
 
@@ -161,7 +161,7 @@ class QuestionController extends AbstractController
         //答题日志
         $right_score = intval(bcmul($is_right_number,site('question_right_getscore'),0));//乘以基数,也就是答题获得的分数
         $this->service->questionPush(['log_data' => $log_data, 'is_right_number' => $right_score, 'bind_jigou_id' => $user['bind_jigou_id']], 0);
-        //给选手加分
+        //给机构加分
 
 
         //返回正确了几道题,剩余答题次数

+ 34 - 2
app/Job/BindjigouJob.php

@@ -41,14 +41,46 @@ private const LOG_MODULE = 'BindjigouJob';
         // 这里的逻辑会在 ConsumerProcess 进程中执行
 //        var_dump($this->params);
 
-        $res = $this->bindjigou($this->params['user_id'],$this->params['bind_jigou_id']);
+        $res = $this->bindjigou($this->params['user_id'],$this->params['old_jigou_id'],$this->params['new_jigou_id']);
 
         LogUtil::info('处理结果', self::LOG_MODULE, __FUNCTION__,$res);
         LogUtil::close();
     }
 
     //曾经 答题贡献的分数,用户曾经都要给到新机构
-    public function bindjigou($user_id,$bind_jigou_id){
+    public function bindjigou($user_id,$old_jigou_id,$new_jigou_id){
+
+        Db::beginTransaction();
+
+        //用户答题记录,都改成现在的机构id
+        $rs3 = Db::table('user_question_log')->where('user_id',$user_id)->update(['jigou_id'=>$new_jigou_id]);
+        if(!$rs3){
+            Db::rollBack();
+            return false;
+        }
+
+        //重新计算老机构的分
+        $sum_score = Db::table('user_question_log')->where('jigou_id',$old_jigou_id)->where('is_right',1)->sum('score');
+        $rs2 = Db::table('vote_jigou')->where('id',$old_jigou_id)->update(['score'=>$sum_score]);
+        if(!$rs2){
+            Db::rollBack();
+            return false;
+        }
+
+        //重新计算新机构的分
+        $sum_score = Db::table('user_question_log')->where('jigou_id',$new_jigou_id)->where('is_right',1)->sum('score');
+        $rs1 = Db::table('vote_jigou')->where('id',$new_jigou_id)->update(['score'=>$sum_score]);
+        if(!$rs1){
+            Db::rollBack();
+            return false;
+        }
+
+
+        Db::commit();
+        return true;
+
+    }
+    public function bindjigou_old($user_id,$bind_jigou_id){
 
         //机构得分记录
         $map = [