|
@@ -12,7 +12,6 @@ class User extends Base_Controller{
|
|
|
$this->load->model('User_model');
|
|
|
$this->load->model('Feedback_model');
|
|
|
$this->load->model('Privilnode_model');
|
|
|
- $this->load->model('Zone_model');
|
|
|
$this->load->model('Project_model');
|
|
|
$this->load->model('Global_location_model');
|
|
|
}
|
|
@@ -31,8 +30,11 @@ class User extends Base_Controller{
|
|
|
$data['email'] = $this->get_user_info('email');
|
|
|
$data['name'] = $this->get_user_info('name');
|
|
|
$data['company'] = $this->get_user_info('company');
|
|
|
+ $avatar = $this->get_user_info('avatar');
|
|
|
+ $data['avatar'] = !empty($avatar) ? base_url($avatar) : '';
|
|
|
}else{
|
|
|
- $data = $this->User_model->get_one(['id'=>$id],'role,id,name,company,phone,email');
|
|
|
+ $data = $this->User_model->get_one(['id'=>$id],'role,id,name,company,phone,email,avatar');
|
|
|
+ $data['avatar'] = !empty($data['avatar']) ? base_url($data['avatar']) : '';
|
|
|
}
|
|
|
|
|
|
exit(json_result('0000',$this->response['0000'],$data));
|
|
@@ -150,32 +152,28 @@ class User extends Base_Controller{
|
|
|
exit(json_result('0011', $this->response['0011'], array()));
|
|
|
}
|
|
|
$data['name'] = $this->input->post('name',true);
|
|
|
- $data['username'] = trim($this->input->post('account',true));
|
|
|
+
|
|
|
$phone = $this->input->post('phone',true);
|
|
|
- $data['password'] = $this->input->post('password',true);
|
|
|
+
|
|
|
$email = $this->input->post('email',true);
|
|
|
$data['company'] = $this->input->post('company',true);
|
|
|
+ $avatar = $this->input->post('avatar',true);
|
|
|
+ if (isset($avatar) && !empty($avatar)) {
|
|
|
+ $path = parse_url($avatar);
|
|
|
+ $data['avatar'] = substr($path['path'], 1);
|
|
|
+ }
|
|
|
|
|
|
if (!empty($phone)) $data['phone'] = $phone;
|
|
|
if (!empty($telephone)) $data['telephone'] = $telephone;
|
|
|
if (!empty($email)) $data['email'] = $email;
|
|
|
|
|
|
if(!isset($data['name']) || isset($data['name']) == '') exit(json_result('0707',$this->response['0707'],array()));
|
|
|
- if(!isset($data['username']) || $data['username'] == '') exit(json_result('0708',$this->response['0708'],array()));
|
|
|
- if(mb_strlen($data['username']) > 20) exit(json_result('0723',$this->response['0723'],array()));
|
|
|
if(empty($data['company'])) exit(json_result('0712',$this->response['0712'],array()));
|
|
|
|
|
|
// $data['zone'] = empty($zone) ? '' : $zone;
|
|
|
// 验证请求数据
|
|
|
$config = array();
|
|
|
- $config[] = array(
|
|
|
- 'field' => 'password',
|
|
|
- 'label' => 'Password',
|
|
|
- 'rules' => 'min_length[6]',
|
|
|
- 'errors' => array(
|
|
|
- 'min_length' => '0720',
|
|
|
- )
|
|
|
- );
|
|
|
+
|
|
|
if(!empty($data['phone'])){
|
|
|
$config[] = array(
|
|
|
'field' => 'phone',
|
|
@@ -197,15 +195,28 @@ class User extends Base_Controller{
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
- if (!empty($config)) {
|
|
|
- $this->load->library('form_validation');
|
|
|
- $this->form_validation->set_rules($config);
|
|
|
- if ($this->form_validation->run() == FALSE){
|
|
|
- $errors = $this->form_validation->error_array();
|
|
|
- exit(json_result(current($errors),$this->response[current($errors)],array()));
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
if (empty($where['id'])) { // 添加用户
|
|
|
+ $data['username'] = trim($this->input->post('account',true));
|
|
|
+ $data['password'] = $this->input->post('password',true);
|
|
|
+ $config[] = array(
|
|
|
+ 'field' => 'password',
|
|
|
+ 'label' => 'Password',
|
|
|
+ 'rules' => 'min_length[6]',
|
|
|
+ 'errors' => array(
|
|
|
+ 'min_length' => '0720',
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if (!empty($config)) {
|
|
|
+ $this->load->library('form_validation');
|
|
|
+ $this->form_validation->set_rules($config);
|
|
|
+ if ($this->form_validation->run() == FALSE){
|
|
|
+ $errors = $this->form_validation->error_array();
|
|
|
+ exit(json_result(current($errors),$this->response[current($errors)],array()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isset($data['username']) || $data['username'] == '') exit(json_result('0708',$this->response['0708'],array()));
|
|
|
+ if(mb_strlen($data['username']) > 20) exit(json_result('0723',$this->response['0723'],array()));
|
|
|
if (empty($data['password'])) {
|
|
|
exit(json_result('0713',$this->response['0713'],array()));
|
|
|
}
|
|
@@ -231,16 +242,24 @@ class User extends Base_Controller{
|
|
|
if (empty($data['role'])) exit(json_result('0724',$this->response['0724']));
|
|
|
|
|
|
|
|
|
- $userid = $this->User_model->add_user($data);
|
|
|
+ $userid = $this->User_model->add($data);
|
|
|
|
|
|
$this->add_operation_log('insert',"添加用户,用户名\"{$data['name']}\"",0);
|
|
|
$this->add_operation_log('insert',"Add user.User name:\"{$data['name']}\"",0,1);
|
|
|
}else{ // 编辑用户
|
|
|
unset($data['password']);
|
|
|
-
|
|
|
- if ($this->User_model->getDataCount(array('username'=>$data['username']),$where['id'])) {
|
|
|
- exit(json_result('0706',$this->response['0706'],array()));
|
|
|
+ if (!empty($config)) {
|
|
|
+ $this->load->library('form_validation');
|
|
|
+ $this->form_validation->set_rules($config);
|
|
|
+ if ($this->form_validation->run() == FALSE){
|
|
|
+ $errors = $this->form_validation->error_array();
|
|
|
+ exit(json_result(current($errors),$this->response[current($errors)],array()));
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ // if ($this->User_model->getDataCount(array('username'=>$data['username']),$where['id'])) {
|
|
|
+ // exit(json_result('0706',$this->response['0706'],array()));
|
|
|
+ // }
|
|
|
if (!empty($data['phone']) && $this->User_model->getDataCount(array('phone'=>$data['phone']),$where['id'])) {
|
|
|
exit(json_result('0721',$this->response['0721'],array()));
|
|
|
}
|
|
@@ -248,7 +267,7 @@ class User extends Base_Controller{
|
|
|
exit(json_result('0722',$this->response['0722'],array()));
|
|
|
}
|
|
|
|
|
|
- $oldData = $this->User_model->get_one($wher,'company');
|
|
|
+ $oldData = $this->User_model->get_one($where,'company');
|
|
|
|
|
|
if ($oldData['company'] != $data['company']) {
|
|
|
$this->Project_model->update(array('company'=>$data['company']),array('userId'=>$where['id'],'company'=>$data['company']));
|
|
@@ -256,6 +275,9 @@ class User extends Base_Controller{
|
|
|
|
|
|
$privilegeIds = $this->input->post('privilegeIds',true);
|
|
|
if ($privilegeIds !== NULL && $privilegeIds !== '') $data['privilege'] = $privilegeIds;
|
|
|
+ $data['role'] = intval($this->input->post('role'));
|
|
|
+
|
|
|
+ if (empty($data['role'])) exit(json_result('0724',$this->response['0724']));
|
|
|
|
|
|
$this->User_model->update($data,$where);
|
|
|
|
|
@@ -285,12 +307,12 @@ class User extends Base_Controller{
|
|
|
if (empty($userid)) $userid = $this->get_user_info('id');
|
|
|
|
|
|
$version = $this->session->userdata('version');
|
|
|
- $userData = $this->User_model->getOne($userid,'role');
|
|
|
+ $userData = $this->User_model->get_one(['id'=>$userid],'role');
|
|
|
|
|
|
$privilege_list = $this->Privilnode_model->get_all_privilnode(SYSTEM_ADMIN);
|
|
|
// 选中用户拥有的权限
|
|
|
if (!empty($userid)) {
|
|
|
- $data = $this->User_model->getOne($userid,'privilege');
|
|
|
+ $data = $this->User_model->get_one(['id'=>$userid],'privilege');
|
|
|
$privilegeArr = explode(',', $data['privilege']);
|
|
|
|
|
|
foreach ($privilege_list as &$v) {
|
|
@@ -310,5 +332,29 @@ class User extends Base_Controller{
|
|
|
exit(json_result('0000',$this->response['0000'],array('list'=>$res)));
|
|
|
}
|
|
|
|
|
|
+ // 修改用户权限
|
|
|
+ public function save_user_privilege(){
|
|
|
+ // $role = $this->get_user_info('role');
|
|
|
+
|
|
|
+ $privilegeIds = $this->input->post('privilegeIds',true);
|
|
|
+ $userid = $this->input->post('userid',true);
|
|
|
+
|
|
|
+ // $res = $this->User_model->get_one($userid);
|
|
|
+ // 判断用户权限
|
|
|
+ // if ($role >= $res['role']) {
|
|
|
+ // exit(json_result('0011',$this->response['0011'],array()));
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 参数判断
|
|
|
+ // if (empty($privilegeIds) || empty($userid)) {
|
|
|
+ // json_result('0000',$this->response['0000'],array());
|
|
|
+ // }
|
|
|
+
|
|
|
+ $this->User_model->update(['privilege'=>$privilegeIds],['id'=>$userid]);
|
|
|
+ $this->add_operation_log('update','修改用户权限 id:'.$userid,0);
|
|
|
+ $this->add_operation_log('update','Update user rights.User ID:'.$userid,0,1);
|
|
|
+
|
|
|
+ exit(json_result('0000',$this->response['0000'],array()));
|
|
|
+ }
|
|
|
}
|
|
|
?>
|