diff --git a/app/common/service/StudentService.php b/app/common/service/StudentService.php index 08e7026..3716099 100644 --- a/app/common/service/StudentService.php +++ b/app/common/service/StudentService.php @@ -101,13 +101,19 @@ class StudentService $code = $request->post('code'); $user_info = WechatSubscriptController::getCodeAccessToken($code); if (isset($result['code'])) { - $message = '获取信息失败'; + throw new Exception('获取信息失败'); } $openid = $user_info['openid']; - $teacher = Student::where(['id'=>$request->student->id])->findOrEmpty(); - $teacher->save([ - 'openid' => $openid, - ]); + + $student = Student::where(['id'=>$request->student->id])->findOrEmpty(); + if($student->openid && $student->openid != $openid){ + throw new Exception('当前账号已绑定其它学生,不能重复绑定'); + }else{ + $student->save([ + 'openid' => $openid, + ]); + } + return [ 'code' => ResponseCode::SUCCESS, diff --git a/app/common/service/TeacherService.php b/app/common/service/TeacherService.php index a06509a..57a2b1d 100644 --- a/app/common/service/TeacherService.php +++ b/app/common/service/TeacherService.php @@ -141,9 +141,13 @@ class TeacherService } $openid = $user_info['openid']; $teacher = Teacher::where(['id'=>$request->teacher->id])->findOrEmpty(); - $teacher->save([ - 'openid' => $openid, - ]); + if($teacher->openid && $teacher->openid != $openid){ + throw new Exception('当前账号已绑定其它教师,不能重复绑定'); + }else{ + $teacher->save([ + 'openid' => $openid, + ]); + } return [ 'code' => ResponseCode::SUCCESS,