| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- namespace app\api\dao\login;
- use app\api\actions\ZskkCache;
- use app\api\dao\ZskkDefaultDao;
- use app\api\model\doctor\DoctorModel;
- use app\api\model\doctor\DoctorruleModel;
- use app\api\model\doctor\FaAdminModel;
- use app\api\model\doctorvisit\DoctorvisitModel;
- use think\facade\Log;
- use app\api\utils\UUIDUtils;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class LoginDao extends ZskkDefaultDao {
- protected $flag = true;
- protected $logName = "LoginDao";
- protected $doctor = null;
- protected $visit = null;
- protected $doctorruleModel = null;
- public function __construct(DoctorModel $doctorModel,DoctorvisitModel $visitModel,DoctorruleModel $doctorruleModel)
- {
- parent::__construct();
- $this->doctor = $doctorModel;
- $this->visit = $visitModel;
- $this->doctorruleModel = $doctorruleModel;
- }
- public function checkIsSet($params,$password='')
- {
- $where = [];
- if(empty($password))
- {
- //为空 解密失败 则尝试base64
- $where['username'] = $params['username'];
- $where['password'] = md5(base64_decode($params['password']));
- $doctor = $this->doctor->getUser($where);
- if(empty($doctor)){
- $this->throwError('账号或密码错误',1);
- }
- }else{
- //不为空 则解密成功
- $where['username'] = $params['username'];
- $where['password'] = $password;
- $doctor = $this->doctor->getUser($where);
- if(empty($doctor)){
- $this->throwError('账号或密码错误',1);
- }
- }
- $institution = $this->doctor->getInstitutionData($doctor['institution_id']);
- $department = $this->doctor->getDepartment($doctor['department_id']);
- $doctor['institution'] = $institution['name'];
- $doctor['is_new_browser'] = $institution['is_new_browser'];
- $doctor['department'] = $department;
- if(!empty($doctor['doctor_role'])){
- $doctor['doctor_role'] = explode(',',$doctor['doctor_role']);
- }
- return $doctor;
- }
- public function getDoctorByPhone($phone)
- {
- $doctor = $this->doctor->getDoctorByPhone($phone);
- if(empty($doctor)){
- $this->throwError('无法普配手机号',1);
- }
- $institution = $this->doctor->getInstitution($doctor['institution_id']);
- $department = $this->doctor->getDepartment($doctor['department_id']);
- $doctor['institution'] = $institution;
- $doctor['department'] = $department;
- if(!empty($doctor['doctor_role'])){
- $doctor['doctor_role'] = explode(',',$doctor['doctor_role']);
- }
- return $doctor;
- }
- public function saveCache($user)
- {
- $token = (time()+86400).rand(0,1000);
- $data = $this->setCache($token,$user);
- if(!$data){
- $this->throwError('token信息存储失败','0009');
- }
- return $token;
- }
- // 更新登录信息
- public function saveLoginInfo($user_id)
- {
- $loginIp = request()->ip();
- $update = [
- 'login_ip' => $loginIp,
- 'login_code' => md5(getNewRand(10))
- ];
- return $this->doctor
- ->where('id', $user_id)
- ->update($update);
- }
- public function getInsInfo($id)
- {
- $info = $this->doctor->getInstitutionData($id);
- return $info;
- }
- public function getOtherRules($id)
- {
- return $this->doctorruleModel->where('doctor_id', $id)->field('institution_id as id,institution_name as name')->select();
- }
- public function getOtherIns($ids)
- {
- $info = $this->doctor->getOtherIns($ids);
- return $info;
- }
- public function logout($token)
- {
- $data = $this->delCache($token);
- return $data;
- }
- public function out($session)
- {
- $data = $this->delCache($session);
- return $data;
- }
- public function saveDoctorVisit($arr)
- {
- $this->visit->insert($arr);
- }
- }
|