Role.php
3.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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/6/24
* Time: 15:30
*/
namespace app\products\controller;
use app\web\controller\BaseController;
use think\Db;
use think\Request;
class Role extends BaseController
{
public function user_management(){
return $this->fetch();
}
//获取用户列表
public function getUsers(){
//$org_id = session('organization.org_id');
$list= Db::table('sos_user_role')->select()->toArray();
$type=['','试用期','正式员工','已离职'];
foreach($list as $key=>$val ){
$list[$key]['sex']=$val['sex'] == 1? '男' : '女';
//所属机构
if($val['mechanism'] != 0){
$mechanism= Db::table('sos_user_mechanism')->field('mechanismName')->where('id',$val['mechanism'])->find();
}
$list[$key]['mechanism']=$val['mechanism'] == 0? '男' : $mechanism['mechanismName'];
//所属部门
if($val['department'] != 0){
$department= Db::table('sos_user_department')->field('departmentName')->where('id',$val['department'])->find();
}
$list[$key]['department']=$val['department'] == 0? '男' : $department['departmentName'];
$list[$key]['status']=$type[$val['status']];
$list[$key]['entryTime']=date('Y-m-d H:i:s',$val['entryTime']);
$list[$key]['quitTime']=$val['quitTime'] == ''? '' : date('Y-m-d H:i:s',$val['entryTime']);
}
$result["total"] =count($list);
$result['rows']=$list;
echo json_encode($result);
}
// 添加用户
public function store(Request $request)
{
$data = $request->post();
$validate = new UserValidate();
$err_msg = $validate->scene("add")->check($data);
if ($err_msg) {
return json($this->renderError($validate->getError()));
}
$res = json_decode(curlPost($this->getUrl('add'), $data),true);
if ($res['code'] == self::SUCCESS_CODE) {
return json($this->renderSuccess());
}
return json($res);
}
//修改用户
public function edit(Request $request){
$data = $request->post();
if($data['id']){
$data['uid'] = $data['id'];
}
$validate = new UserValidate();
$err_msg = $validate->scene("update")->check($data);
if ($err_msg) {
return json($this->renderError($validate->getError()));
}
$res = json_decode(curlPost($this->getUrl('edit'), $data),true);
if ($res['code'] == self::SUCCESS_CODE) {
return json($this->renderSuccess());
}
return json($res);
}
//删除用户
public function del(Request $request){
$data = $request->get();
if (empty($data['id']) && $data['id'] !== 0) {
return json($this->renderError("删除失败!"));
}
$res = json_decode(curlPost($this->getUrl("del"),['uid'=>$data['id']]),true);
if ($res['code'] != self::SUCCESS_CODE) {
return json($res);
}
return json($this->renderSuccess());
}
}