Login.php
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Created by PhpStorm.
* User: yrf
* Date: 2022/4/3
* Time: 9:24
* ResvRaninDate
* 水库安全运行监测大屏接口
*
*/
namespace app\api\controller\safeoperation;
use app\admin\model\inspection\Depart;
use app\common\controller\Api;
use fast\Tree;
use think\Db;
use think\Request;
/**
* 渗压
*/
class Login extends Api
{
protected $id;
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
parent::_initialize();
}
/**
* 雨水情登录
* @return void
*/
public function rainwatersituation_login(){
$account = $this->request->param('account');
$password = $this->request->param('password');
if (!$account || !$password) {
$this->error(__('Invalid parameters'));
}
$staffModel = new \app\admin\model\inspection\Staff();
$staffInfo = $staffModel->where(['is_screen_mng' => '1', "is_regulatory_mng" => '0'])
->where("staff_code = '$account' or mobile = '$account'")
->find();
if ($staffInfo) {
$userModel = new \app\admin\model\User();
$userInfo = $userModel->where(['id' => $staffInfo['user_id']])->find();
$departModel = new Depart();
$departInfo = $departModel->where(['id' => $staffInfo->depart_id])->find();
if (empty($userInfo)) {
$this->error('大屏管理员登录信息异常');
}
if ($userInfo->password != $this->auth->getEncryptPassword($password, $userInfo->salt)) {
$this->error('登录密码不正确');
return false;
}
$this->auth->direct($userInfo->id);
$userInfo->openid = $openid;
$userInfo->save();
$user = $this->auth->getUserinfo();
if ('data' != substr($this->auth->getUserinfo()['avatar'], 0, 4)) {
$user['avatar'] = 'https://qiniu.ynzhsk.cn' . $this->auth->getUserinfo()['avatar'];
}
$data = ['userinfo' => $user, 'depart_name' => $departInfo->depart_name, 'duty' => $staffInfo->duty, 'staff' => $staffInfo];
$this->success(__('登录成功'), $data);
} else {
$this->error('大屏管理员账号不存在');
}
$this->success("登陆成功");
}
/**
* 雨水情登录
* @return void
*/
public function security_login(){
$account = $this->request->param('account');
$password = $this->request->param('password');
if (!$account || !$password) {
$this->error(__('Invalid parameters'));
}
$staffModel = new \app\admin\model\inspection\Staff();
$staffInfo = $staffModel->where(['is_screen_mng' => '1', "is_regulatory_mng" => '0'])
->where("staff_code = '$account' or mobile = '$account'")
->find();
if ($staffInfo) {
$userModel = new \app\admin\model\User();
$userInfo = $userModel->where(['id' => $staffInfo['user_id']])->find();
$departModel = new Depart();
$departInfo = $departModel->where(['id' => $staffInfo->depart_id])->find();
if (empty($userInfo)) {
$this->error('大屏管理员登录信息异常');
}
if ($userInfo->password != $this->auth->getEncryptPassword($password, $userInfo->salt)) {
$this->error('登录密码不正确');
return false;
}
$this->auth->direct($userInfo->id);
//$userInfo->openid = $openid;
$userInfo->save();
$user = $this->auth->getUserinfo();
if ('data' != substr($this->auth->getUserinfo()['avatar'], 0, 4)) {
$user['avatar'] = 'https://qiniu.ynzhsk.cn' . $this->auth->getUserinfo()['avatar'];
}
$data = ['userinfo' => $user, 'depart_name' => $departInfo->depart_name, 'duty' => $staffInfo->duty, 'staff' => $staffInfo];
$this->success(__('登录成功'), $data);
} else {
$this->error('大屏管理员账号不存在');
}
$this->success("登陆成功");
}
}