Staff.php
11.1 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<?php
namespace app\api\controller\inspection;
use app\admin\model\inspection\Depart;
use app\admin\model\inspection\Plan;
use app\common\controller\Api;
use fast\Tree;
use think\Db;
/**
* 员工接口
*/
class Staff extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['login', 'screen_mng_login'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
public $staffInfo;
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
if ($this->request->action() != "login" && $this->request->action() != "screen_mng_login") {
$staffModel = new \app\admin\model\inspection\Staff();
$staffInfo = $staffModel->where(['user_id' => $this->auth->id])->find();
if (empty($staffInfo)) {
$this->error('当前员工账号异常');
}
$this->staffInfo = $staffInfo;
}
}
/**
* 获取员工详情
*/
public function info()
{
$staffInfo = $this->staffInfo;
$departModel = new Depart();
$departInfo = $departModel->where(['id' => $this->staffInfo['depart_id']])->find();
$staffInfo['depart_name'] = empty($departInfo['depart_name']) ? '' : $departInfo['depart_name'];
$staffInfo['reservoir_name'] = \think\Db::name('reservoir_list')->where('id', $staffInfo['reservoir_id'])->value('name');
$staffInfo['avatar'] = $this->auth->avatar;
if ($this->staffInfo['depart_id'] == 1 || $this->staffInfo['depart_id'] == 2) {
$staffInfo['is_mng_leader'] = 1;
} else {
$staffInfo['is_mng_leader'] = 0;
}
if (substr($this->auth->avatar, 0, 4) != 'data') {
$staffInfo['avatar'] = 'https://qiniu.ynzhsk.cn' . $this->auth->avatar;
}
$this->success("请求成功", $staffInfo);
}
/**
* 员工登录
*
* @param string $account 账号
* @param string $password 密码
*/
public function login()
{
$account = $this->request->request('account');
$password = $this->request->request('password');
$openid = $this->request->request('openid');
//unipush用于推送的客户端id(2022.03.16 kevin新增)
$clientid = $this->request->request("clientid", "");
// $userInfo = [];
// $staffInfo = [];
if (!$account || !$password) {
$this->error(__('Invalid parameters'));
}
// if($openid){
// $userModel = new \app\admin\model\User();
// $userInfo = $userModel->where(['openid'=>$openid])->find();
// $nologin = true;
// }
$staffModel = new \app\admin\model\inspection\Staff();
$staffInfo = $staffModel->where(['is_screen_mng' => '0', "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;
}
//kevin 更新客户端唯一标识
if (!empty($clientid) && $clientid != $userInfo->clientid) {
$userModel->where("id", $staffInfo['user_id'])->update(["clientid" => $clientid]);
$userInfo = $userModel->where(['id' => $staffInfo['user_id']])->find();
}
$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, 'admin_group_id' => "15288413396"];
$this->success(__('登录成功!'), $data);
} else {
$this->error('当前员工不存在');
}
}
/**
* 大屏管理员登录
*
* @param string $account 账号
* @param string $password 密码
*/
public function screen_mng_login()
{
$account = $this->request->param('account');
$password = $this->request->param('password');
$openid = $this->request->param('openid');
//unipush用于推送的客户端id(2022.03.16 kevin新增)
$clientid = $this->request->param("clientid", "");
// $userInfo = [];
// $staffInfo = [];
if (!$account || !$password) {
$this->error(__('Invalid parameters'));
}
// if($openid){
// $userModel = new \app\admin\model\User();
// $userInfo = $userModel->where(['openid'=>$openid])->find();
// $nologin = true;
// }
$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();
//$staffModel->where(['staff_code' => $account, 'is_screen_mng' => '1'])->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;
}
//kevin 更新客户端唯一标识
if (!empty($clientid) && $clientid != $userInfo->clientid) {
$userModel->where("id", $staffInfo['user_id'])->update(["clientid" => $clientid]);
$userInfo = $userModel->where(['id' => $staffInfo['user_id']])->find();
}
$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('大屏管理员账号不存在');
}
}
/**
* 重置密码
*
* @param string $mobile 手机号
* @param string $newpassword 新密码
* @param string $captcha 验证码
*/
public function resetpwd()
{
$oldpassword = $this->request->request("oldpassword");
$newpassword = $this->request->request("newpassword");
if (empty($newpassword)) {
$this->error('新密码不能为空');
}
$userModel = new \app\admin\model\User();
$userInfo = $userModel->where(['id' => $this->auth->id])->find();
if (empty($userInfo)) {
$this->error('当前登录信息异常');
}
if ($userInfo->password != $this->auth->getEncryptPassword($oldpassword, $userInfo->salt)) {
$this->error('原始登录密码不正确');
return false;
}
$ret = $this->auth->changepwd($newpassword, '', true);
if ($ret) {
$this->success(__('密码重置成功'));
} else {
$this->error($this->auth->getError());
}
}
/**
* 8. 发布事项获取员工列表
*/
public function getStaffList()
{
$curPage = $this->request->param("curPage", 1);
$pageSize = $this->request->param("pageSize", 99999);
$pageSize = $curPage == 1 ? $pageSize - 1 : $pageSize;
$depart_ids = [];
$data = [];
$count = 0;
//查询当前用户所属部门id
$id = $this->auth->id;
$depart_id = Db::name("inspection_staff")->where("user_id", $id)->value("depart_id");
if (!empty($depart_id)) {
//获取下级所有子部门ID
$tree = Tree::instance();
$departModel = new \app\admin\model\inspection\Depart();
$tree->init(collection($departModel->order('weigh asc,id asc')->select())->toArray(), 'pid');
$depart_ids = $tree->getChildrenIds($depart_id, true);
}
$where = [];
if (!empty($depart_ids)) {
$where["s.depart_id"] = ["IN", $depart_ids];
}
$where["s.is_regulatory_mng"] = ["=", "1"];
$where["s.is_screen_mng"] = ["=", "0"];
$data = Db::name("inspection_staff")->alias("s")
->join("user u", "u.id=s.user_id", "LEFT")
->join("reservoir_list l", "l.id=s.reservoir_id", "LEFT")
->where($where)
->order("s.id desc")
->field("s.id,s.user_id,s.staff_name,s.staff_code,s.mobile,u.avatar,l.name as reservoir_name")
->page($curPage, $pageSize)
->select();
if (!empty($data)) {
foreach ($data as $k => $v) {
$data[$k]['avatar'] = $v['avatar'] ? cdnurl($v['avatar'], true) : letter_avatar($v['staff_name']);
}
}
$count = count($data);
if ($curPage == 1) {
$admin_info = [
"id" => 0,
"user_id" => 0,
"staff_name" => "总后台管理员",
"avatar" => letter_avatar("总后台管理员"),
];
array_unshift($data, $admin_info);
$count = $count + 1;
}
$this->success("数据获取成功", ["total" => $count, "rows" => $data]);
}
/**
* 2.巡检人员上报经纬度
*/
public function report_lanlnt()
{
$param = $this->request->param();
if (empty($param['lat']) || empty($param['lng'])) {
$this->error("经纬度不能为空");
}
$insert_data = [
"inspection_staff_id" => $this->staffInfo['id'],
"person_type" => "1",//1巡检人员
"lat" => $param['lat'],
"lng" => $param['lng'],
"createtime" => time(),
];
$res = Db::name("inspection_staff_locus")->insertGetId($insert_data);
if ($res) {
$this->success("位置上报成功", $res);
} else {
$this->error("位置上报失败");
}
}
}