|
@@ -79,72 +79,133 @@ class Login extends Controller
|
|
|
if(!$info){
|
|
|
return json_encode(['status'=>'fail','code'=>'1004','msg'=>'用户名'.$param['userName'].'或密码错误']);
|
|
|
}
|
|
|
- //医生类
|
|
|
- $class_info = DB::table('doctor_class')->where('doctor_id',$info['id'])->cache(300)->find();
|
|
|
- $institution = DB::table('institution')->where('id',$info['institution_id'])->cache(300)->field('name')->find();
|
|
|
- $info['institution_name'] = $institution['name'];
|
|
|
- $info['doctor_class_info'] = $class_info;
|
|
|
- //医生权限菜单
|
|
|
- $sql = "SELECT m.id,m.name,m.url,m.parent_id,m.icon_name from menu as m,dr_cla_permission as d where d.type=1 and d.doctor_id='".$info['id']."' and d.pass=m.id order by m.ordernum ";
|
|
|
- $permission = DB::query($sql);
|
|
|
- $info['permission'] = $permission;
|
|
|
- if(md5($param['pwd']) == $info['password']){
|
|
|
- //登录成功则失败次数清0
|
|
|
- DB::table('doctors')->where('username',$param['userName'])->update(['login_failure'=>0,'login_time'=>date('Y-m-d H:i:s')]);
|
|
|
- Cache::set($sessionid,$info,43200);
|
|
|
- log::record('----登录信息----');
|
|
|
- log::record(Cache::get($sessionid));
|
|
|
- log::record('----登录信息----');
|
|
|
- unset($info['password']);
|
|
|
- return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
|
|
|
- }else{
|
|
|
- //登录失败则将 登录失败次数+1
|
|
|
+
|
|
|
+ if(md5($param['pwd']) != $info['password']) {
|
|
|
+
|
|
|
+ //登录失败
|
|
|
$time = date('Y-m-d', time());
|
|
|
$datetime = strtotime($time);
|
|
|
+
|
|
|
//上次登录时间-今日0点时间
|
|
|
$t = $info['login_time'] - $datetime;
|
|
|
if( $t < 0){
|
|
|
+
|
|
|
//时间小于0 代表今日未进行登录 登录失败次数归0
|
|
|
DB::table('doctors')->where('username',$param['userName'])->update(['login_failure'=>0]);
|
|
|
}
|
|
|
DB::table('doctors')->where('username',$param['userName'])->setInc('login_failure');
|
|
|
return json_encode(['status'=>'fail','code'=>'1004','msg'=>'用户名'.$param['userName'].'或者密码错误','info'=>$info['login_failure']]);
|
|
|
}
|
|
|
+
|
|
|
+ if($info['is_send_message'] == "1") {
|
|
|
+ $phone = $info['phone'];
|
|
|
+ $code = rand('1000','9999');
|
|
|
+ $handle_id = $phone.rand('10000000','99999999');
|
|
|
+ Cache::set('sendcode_'.$phone,$code,600);
|
|
|
+ Cache::set('sendcode_handle_id'.$handle_id, $phone, 600);
|
|
|
+ $info = send_message::sendSms2UpDate($phone,$code);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','need_code'=> true, 'phone' => $phone, 'hander_id' => $handle_id]);
|
|
|
+ }
|
|
|
+
|
|
|
+ //医生类
|
|
|
+ $class_info = DB::table('doctor_class')->where('doctor_id',$info['id'])->cache(300)->find();
|
|
|
+ $institution = DB::table('institution')->where('id',$info['institution_id'])->cache(300)->field('name')->find();
|
|
|
+ $info['institution_name'] = $institution['name'];
|
|
|
+ $info['doctor_class_info'] = $class_info;
|
|
|
+
|
|
|
+ //医生权限菜单
|
|
|
+ $sql = "SELECT m.id,m.name,m.url,m.parent_id,m.icon_name from menu as m,dr_cla_permission as d where d.type=1 and d.doctor_id='".$info['id']."' and d.pass=m.id order by m.ordernum ";
|
|
|
+ $permission = DB::query($sql);
|
|
|
+ $info['permission'] = $permission;
|
|
|
+
|
|
|
+ //登录成功则失败次数清0
|
|
|
+ DB::table('doctors')->where('username',$param['userName'])->update(['login_failure'=>0,'login_time'=>date('Y-m-d H:i:s')]);
|
|
|
+ Cache::set($sessionid,$info,43200);
|
|
|
+ log::record('----登录信息----');
|
|
|
+ log::record(Cache::get($sessionid));
|
|
|
+ log::record('----登录信息----');
|
|
|
+ unset($info['password']);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
|
|
|
+
|
|
|
}catch(\Exception $e){
|
|
|
return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //发送短信
|
|
|
- public function send_message()
|
|
|
+ //再次发送短信
|
|
|
+ public function send_message_again()
|
|
|
{
|
|
|
try{
|
|
|
- $sessionid = $_REQUEST['sessionid'];
|
|
|
- $doctor = Cache::get($sessionid);
|
|
|
- $phone = $doctor['phone'];
|
|
|
- $code = rand('1000','9999');
|
|
|
- Cache::set($phone,$code,600);
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $handle_id = $param['handle_id'];
|
|
|
+ $phone = Cache::get('sendcode_handle_id'.$handle_id);
|
|
|
+ $code = Cache::get('sendcode_'.$phone);
|
|
|
+ Cache::rm('sendcode_handle_id'.$handle_id);
|
|
|
$info = send_message::sendSms2UpDate($phone,$code);
|
|
|
- return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
|
|
|
+ $handle_id = $phone.rand('10000000','99999999');
|
|
|
+ Cache::set('sendcode_handle_id'.$handle_id, $phone, 600);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'handle_id'=>$handle_id]);
|
|
|
}catch(\Exception $e){
|
|
|
return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public function check_code()
|
|
|
{
|
|
|
try{
|
|
|
- $sessionid = $_REQUEST['sessionid'];
|
|
|
- $doctor = Cache::get($sessionid);
|
|
|
- $check_phone = $doctor['phone'];
|
|
|
- $code = Cache::get($check_phone);
|
|
|
- $number =$_REQUEST['code'];
|
|
|
- if($code == $number){
|
|
|
- return json_encode(['status'=>'ok','code'=>'0000','msg'=>'验证成功','sessionid'=>$sessionid]);
|
|
|
- }else{
|
|
|
- return json_encode(['status'=>'fail','code'=>'0090','msg'=>' 错误的验证码','sessionid'=>$sessionid]);
|
|
|
+ $param = $_REQUEST['param'];
|
|
|
+ $handle_id = $_REQUEST['handle_id'];
|
|
|
+ $phone = Cache::get('sendcode_handle_id'.$handle_id);
|
|
|
+ $code = $_REQUEST['code'];
|
|
|
+ $check_code = Cache::get('sendcode_'.$phone);
|
|
|
+ if($code != $check_code) {
|
|
|
+ return json_encode(['status'=>'fail','code'=>'0090','msg'=>' 错误的验证码']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //医生信息
|
|
|
+ $info = DB::table('doctors')->where('phone',$phone)->field('is_send_message,is_admin,message_push,id,exam_class,attachment,username,password,login_time,login_failure,realname,email,phone,doctor_title,institution_id,department_id,doctor_role,is_report')->find();
|
|
|
+ log::record($info);
|
|
|
+ if(!$info){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'1004','msg'=>'用户不存在']);
|
|
|
}
|
|
|
|
|
|
+ //医生类
|
|
|
+ $class_info = DB::table('doctor_class')->where('doctor_id',$info['id'])->cache(300)->find();
|
|
|
+ $institution = DB::table('institution')->where('id',$info['institution_id'])->cache(300)->field('name')->find();
|
|
|
+ $info['institution_name'] = $institution['name'];
|
|
|
+ $info['doctor_class_info'] = $class_info;
|
|
|
+
|
|
|
+ //医生权限菜单
|
|
|
+ $sql = "SELECT m.id,m.name,m.url,m.parent_id,m.icon_name from menu as m,dr_cla_permission as d where d.type=1 and d.doctor_id='".$info['id']."' and d.pass=m.id order by m.ordernum ";
|
|
|
+ $permission = DB::query($sql);
|
|
|
+ $info['permission'] = $permission;
|
|
|
+
|
|
|
+ //登录成功则失败次数清0
|
|
|
+ DB::table('doctors')->where('username',$param['userName'])->update(['login_failure'=>0,'login_time'=>date('Y-m-d H:i:s')]);
|
|
|
+ Cache::set($sessionid,$info,43200);
|
|
|
+ log::record('----登录信息----');
|
|
|
+ log::record(Cache::get($sessionid));
|
|
|
+ log::record('----登录信息----');
|
|
|
+ unset($info['password']);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
|
|
|
+
|
|
|
+ }catch(\Exception $e){
|
|
|
+ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //发送短信
|
|
|
+ public function send_message()
|
|
|
+ {
|
|
|
+ try{
|
|
|
+ $sessionid = $_REQUEST['sessionid'];
|
|
|
+ $doctor = Cache::get($sessionid);
|
|
|
+ $phone = $doctor['phone'];
|
|
|
+ $code = rand('1000','9999');
|
|
|
+ Cache::set($phone,$code,600);
|
|
|
+ $info = send_message::sendSms2UpDate($phone,$code);
|
|
|
+ return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid]);
|
|
|
}catch(\Exception $e){
|
|
|
return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
|
|
|
}
|