LoginDao.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\api\dao\login;
  3. use app\api\actions\ZskkCache;
  4. use app\api\dao\ZskkDefaultDao;
  5. use app\api\model\doctor\DoctorModel;
  6. use app\api\model\doctor\DoctorruleModel;
  7. use app\api\model\doctor\FaAdminModel;
  8. use app\api\model\doctorvisit\DoctorvisitModel;
  9. use think\facade\Log;
  10. use app\api\utils\UUIDUtils;
  11. /**
  12. * 后台控制器基类
  13. * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
  14. */
  15. class LoginDao extends ZskkDefaultDao {
  16. protected $flag = true;
  17. protected $logName = "LoginDao";
  18. protected $doctor = null;
  19. protected $visit = null;
  20. protected $doctorruleModel = null;
  21. public function __construct(DoctorModel $doctorModel,DoctorvisitModel $visitModel,DoctorruleModel $doctorruleModel)
  22. {
  23. parent::__construct();
  24. $this->doctor = $doctorModel;
  25. $this->visit = $visitModel;
  26. $this->doctorruleModel = $doctorruleModel;
  27. }
  28. public function checkIsSet($params,$password='')
  29. {
  30. $where = [];
  31. if(empty($password))
  32. {
  33. //为空 解密失败 则尝试base64
  34. $where['username'] = $params['username'];
  35. $where['password'] = md5(base64_decode($params['password']));
  36. $doctor = $this->doctor->getUser($where);
  37. if(empty($doctor)){
  38. $this->throwError('账号或密码错误',1);
  39. }
  40. }else{
  41. //不为空 则解密成功
  42. $where['username'] = $params['username'];
  43. $where['password'] = $password;
  44. $doctor = $this->doctor->getUser($where);
  45. if(empty($doctor)){
  46. $this->throwError('账号或密码错误',1);
  47. }
  48. }
  49. $institution = $this->doctor->getInstitutionData($doctor['institution_id']);
  50. $department = $this->doctor->getDepartment($doctor['department_id']);
  51. $doctor['institution'] = $institution['name'];
  52. $doctor['is_new_browser'] = $institution['is_new_browser'];
  53. $doctor['department'] = $department;
  54. if(!empty($doctor['doctor_role'])){
  55. $doctor['doctor_role'] = explode(',',$doctor['doctor_role']);
  56. }
  57. return $doctor;
  58. }
  59. public function getUserByUserName($username)
  60. {
  61. $where = [];
  62. $where['username'] = $username;
  63. $doctor = $this->doctor->getUser($where);
  64. if(empty($doctor)){
  65. $this->throwError('账号或密码错误',1);
  66. }
  67. $institution = $this->doctor->getInstitutionData($doctor['institution_id']);
  68. $department = $this->doctor->getDepartment($doctor['department_id']);
  69. $doctor['institution'] = $institution['name'];
  70. $doctor['is_new_browser'] = $institution['is_new_browser'];
  71. $doctor['department'] = $department;
  72. if(!empty($doctor['doctor_role'])){
  73. $doctor['doctor_role'] = explode(',',$doctor['doctor_role']);
  74. }
  75. return $doctor;
  76. }
  77. public function getDoctorByPhone($phone)
  78. {
  79. $doctor = $this->doctor->getDoctorByPhone($phone);
  80. if(empty($doctor)){
  81. $this->throwError('无法普配手机号',1);
  82. }
  83. $institution = $this->doctor->getInstitution($doctor['institution_id']);
  84. $department = $this->doctor->getDepartment($doctor['department_id']);
  85. $doctor['institution'] = $institution;
  86. $doctor['department'] = $department;
  87. if(!empty($doctor['doctor_role'])){
  88. $doctor['doctor_role'] = explode(',',$doctor['doctor_role']);
  89. }
  90. return $doctor;
  91. }
  92. public function saveCache($user)
  93. {
  94. $token = (time()+86400).rand(0,1000);
  95. $data = $this->setCache($token,$user);
  96. if(!$data){
  97. $this->throwError('token信息存储失败','0009');
  98. }
  99. return $token;
  100. }
  101. // 更新登录信息
  102. public function saveLoginInfo($user_id)
  103. {
  104. $loginIp = request()->ip();
  105. $update = [
  106. 'login_ip' => $loginIp,
  107. 'login_code' => md5(getNewRand(10))
  108. ];
  109. return $this->doctor
  110. ->where('id', $user_id)
  111. ->update($update);
  112. }
  113. public function getInsInfo($id)
  114. {
  115. $info = $this->doctor->getInstitutionData($id);
  116. return $info;
  117. }
  118. public function getOtherRules($id)
  119. {
  120. return $this->doctorruleModel->where('doctor_id', $id)->field('institution_id as id,institution_name as name')->select();
  121. }
  122. public function getOtherIns($ids)
  123. {
  124. $info = $this->doctor->getOtherIns($ids);
  125. return $info;
  126. }
  127. public function logout($token)
  128. {
  129. $data = $this->delCache($token);
  130. return $data;
  131. }
  132. public function out($session)
  133. {
  134. $data = $this->delCache($session);
  135. return $data;
  136. }
  137. public function saveDoctorVisit($arr)
  138. {
  139. $this->visit->insert($arr);
  140. }
  141. }