|
@@ -20,37 +20,23 @@ class TestController extends AbstractController
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
- }
|
|
|
+ $user_id = 93;$old_jigou_id = 17;$new_jigou_id = 18;
|
|
|
|
|
|
- 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();
|