|
@@ -6,6 +6,7 @@ namespace App\Controller\Api\v1;
|
|
|
|
|
|
use App\Controller\AbstractController;
|
|
|
use App\Utils\AppResult;
|
|
|
+use Hyperf\DbConnection\Db;
|
|
|
|
|
|
class TestController extends AbstractController
|
|
|
{
|
|
@@ -18,5 +19,45 @@ class TestController extends AbstractController
|
|
|
return AppResult::success('token','testuid_'.rand(100,150100));
|
|
|
}
|
|
|
|
|
|
+ public function test2(){
|
|
|
+ $user_id = 93;$old_jigou_id = 16;$new_jigou_id = 18;
|
|
|
+ $a = $this->bindjigou($user_id,$old_jigou_id,$new_jigou_id);
|
|
|
+ dump($a);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|