|
@@ -73,72 +73,6 @@ class User extends Base_Controller{
|
|
|
exit(json_result('0000',$this->response['0000'],$data));
|
|
|
}
|
|
|
|
|
|
- // 编辑个人信息
|
|
|
- public function update_user_info(){
|
|
|
- $userid = $this->get_user_info('id');
|
|
|
- $data['realname'] = $this->input->post('realname',true);
|
|
|
- $mobile = $this->input->post('mobile',true);
|
|
|
- $data['username'] = $this->input->post('name',true);
|
|
|
- $telephone = $this->input->post('telephone',true);
|
|
|
- $email = $this->input->post('email',true);
|
|
|
- $address = $this->input->post('address',true);
|
|
|
- $memo = $this->input->post('memo',true);
|
|
|
- $avatar = $this->input->post('avatar',true);
|
|
|
-
|
|
|
- if (!empty($avatar)) $data['avatar'] = $avatar;
|
|
|
- if (!empty($mobile)) $data['mobile'] = $mobile;
|
|
|
- if (!empty($telephone)) $data['telephone'] = $telephone;
|
|
|
- if (!empty($email)) $data['email'] = $email;
|
|
|
- if (!empty($address)) $data['address'] = $address;
|
|
|
- if (!empty($memo)) $data['memo'] = $memo;
|
|
|
-
|
|
|
- // 检测表单数据
|
|
|
- if(empty($data['realname'])) exit(json_result('0707',$this->response['0707'],array()));
|
|
|
- if(empty($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 ($this->User_model->getDataCount(array('username'=>$data['username']),$userid)) {
|
|
|
- exit(json_result('0706',$this->response['0706'],array()));
|
|
|
- }
|
|
|
-
|
|
|
- // 验证请求数据
|
|
|
- $config = array();
|
|
|
- if(!empty($data['mobile'])){
|
|
|
- $config[] = array(
|
|
|
- 'field' => 'mobile',
|
|
|
- 'label' => 'Mobile',
|
|
|
- 'rules' => 'numeric|exact_length[11]',
|
|
|
- 'errors' => array(
|
|
|
- 'numeric' => '0718',
|
|
|
- 'exact_length' => '0718'
|
|
|
- )
|
|
|
- );
|
|
|
- }
|
|
|
- if (!empty($data['email'])) {
|
|
|
- $config[] = array(
|
|
|
- 'field' => 'email',
|
|
|
- 'label' => 'Email',
|
|
|
- 'rules' => 'valid_email',
|
|
|
- 'errors' => array(
|
|
|
- 'valid_email' => '0719',
|
|
|
- )
|
|
|
- );
|
|
|
- }
|
|
|
- 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()));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $this->User_model->update_user($data,$userid);
|
|
|
- $this->userinfo = $this->User_model->get_user_by_name($data['username']);
|
|
|
- exit(json_result('0000',$this->response['0000'],array('id'=>$userid)));
|
|
|
- }
|
|
|
-
|
|
|
// 修改用户密码
|
|
|
public function password(){
|
|
|
$username = $this->get_user_info('username');
|
|
@@ -177,7 +111,7 @@ class User extends Base_Controller{
|
|
|
|
|
|
// 修改账号状态
|
|
|
public function block_user(){
|
|
|
- $userid = $this->input->post('userid',true);
|
|
|
+ $userid = $this->input->post('id',true);
|
|
|
$status = intval($this->input->post('status',true));
|
|
|
if (empty($userid) || $status < 0) {
|
|
|
exit(json_result('0007',$this->response['0007'],array()));
|
|
@@ -200,6 +134,9 @@ class User extends Base_Controller{
|
|
|
$role = intval($this->input->post('role',true));
|
|
|
if (!empty($role)) $where['role'] = $role;
|
|
|
|
|
|
+ $keywords = $this->input->post('keywords',true);
|
|
|
+ if ($keywords !== NULL && $keywords !== '') $where['name|'] = $keywords;
|
|
|
+
|
|
|
$field = "id,name,role,phone,email,status";
|
|
|
$list = $this->User_model->get_list($where,$field);
|
|
|
exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
|
|
@@ -207,34 +144,26 @@ class User extends Base_Controller{
|
|
|
|
|
|
// 添加编辑用户
|
|
|
public function user_update(){
|
|
|
- $where['id'] = $this->input->post('userid',true);
|
|
|
+ $where['id'] = intval($this->input->post('id',true));
|
|
|
$role = $this->get_user_info('role');
|
|
|
if ($role == COMPANY_CUSTOMER) {
|
|
|
exit(json_result('0011', $this->response['0011'], array()));
|
|
|
}
|
|
|
- $data['realname'] = $this->input->post('realname',true);
|
|
|
- $data['username'] = trim($this->input->post('name',true));
|
|
|
- $telephone = $this->input->post('telephone',true);
|
|
|
- $mobile = $this->input->post('mobile',true);
|
|
|
+ $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['companyid'] = $this->input->post('companyid',true);
|
|
|
- $address = $this->input->post('address',true);
|
|
|
- $memo = $this->input->post('memo',true);
|
|
|
- $avatar = $this->input->post('avatar',true);
|
|
|
- $data['zone'] = $this->input->post('zone',true);
|
|
|
+ $data['company'] = $this->input->post('company',true);
|
|
|
|
|
|
- if (!empty($avatar)) $data['avatar'] = $avatar;
|
|
|
- if (!empty($mobile)) $data['mobile'] = $mobile;
|
|
|
+ if (!empty($phone)) $data['phone'] = $phone;
|
|
|
if (!empty($telephone)) $data['telephone'] = $telephone;
|
|
|
if (!empty($email)) $data['email'] = $email;
|
|
|
- if (!empty($address)) $data['address'] = $address;
|
|
|
- if (!empty($memo)) $data['memo'] = $memo;
|
|
|
|
|
|
- if(!isset($data['realname']) || isset($data['realname']) == '') exit(json_result('0707',$this->response['0707'],array()));
|
|
|
+ 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['companyid'])) exit(json_result('0712',$this->response['0712'],array()));
|
|
|
+ if(empty($data['company'])) exit(json_result('0712',$this->response['0712'],array()));
|
|
|
|
|
|
// $data['zone'] = empty($zone) ? '' : $zone;
|
|
|
// 验证请求数据
|
|
@@ -247,10 +176,10 @@ class User extends Base_Controller{
|
|
|
'min_length' => '0720',
|
|
|
)
|
|
|
);
|
|
|
- if(!empty($data['mobile'])){
|
|
|
+ if(!empty($data['phone'])){
|
|
|
$config[] = array(
|
|
|
- 'field' => 'mobile',
|
|
|
- 'label' => 'Mobile',
|
|
|
+ 'field' => 'phone',
|
|
|
+ 'label' => 'Phone',
|
|
|
'rules' => 'numeric|exact_length[11]',
|
|
|
'errors' => array(
|
|
|
'numeric' => '0718',
|
|
@@ -286,44 +215,30 @@ class User extends Base_Controller{
|
|
|
if ($this->User_model->getDataCount(array('username'=>$data['username']))) {
|
|
|
exit(json_result('0706',$this->response['0706'],array()));
|
|
|
}
|
|
|
- if (!empty($data['mobile']) && $this->User_model->getDataCount(array('mobile'=>$data['mobile']))) {
|
|
|
+ if (!empty($data['phone']) && $this->User_model->getDataCount(array('phone'=>$data['phone']))) {
|
|
|
exit(json_result('0721',$this->response['0721'],array()));
|
|
|
}
|
|
|
if (!empty($data['email']) && $this->User_model->getDataCount(array('email'=>$data['email']))) {
|
|
|
exit(json_result('0722',$this->response['0722'],array()));
|
|
|
}
|
|
|
|
|
|
- $data['avatar'] = empty($data['avatar']) ? 'assets/avatars/user.png' : $data['avatar'];
|
|
|
- $data['parentid'] = $this->get_user_info('id');
|
|
|
- $data['role'] = $role == 1 ? 2 : 3;
|
|
|
- $data['privilege'] = $this->Privilnode_model->get_default_privilege($data['role']);
|
|
|
- if (empty($data['zone']) && $data['role'] == 2) {
|
|
|
- $projectids = $this->Project_model->get_project_ids(array('company'=>$data['companyid']));
|
|
|
- $data['zone'] = !empty($projectids) ? implode(',', $projectids) : '';
|
|
|
- }
|
|
|
+ $data['pid'] = $this->get_user_info('id');
|
|
|
+ $data['role'] = intval($this->input->post('role'));
|
|
|
+
|
|
|
+ if (empty($data['role'])) exit(json_result('0724',$this->response['0724']));
|
|
|
+
|
|
|
|
|
|
$userid = $this->User_model->add_user($data);
|
|
|
|
|
|
- $this->add_operation_log('insert',"添加用户,用户名\"{$data['realname']}\"",0);
|
|
|
- $this->add_operation_log('insert',"Add user.User name:\"{$data['realname']}\"",0,1);
|
|
|
+ $this->add_operation_log('insert',"添加用户,用户名\"{$data['name']}\"",0);
|
|
|
+ $this->add_operation_log('insert',"Add user.User name:\"{$data['name']}\"",0,1);
|
|
|
}else{ // 编辑用户
|
|
|
- if (empty($data['password'])) {
|
|
|
- unset($data['password']);
|
|
|
- }else {
|
|
|
- $data['password'] = md5($data['password']);
|
|
|
- }
|
|
|
- $res = $this->User_model->getOne($where['id'],'role,companyid');
|
|
|
- if (intval($role) >= intval($res['role'])) {
|
|
|
- exit(json_result('0011',$this->response['0011'],array()));
|
|
|
- }
|
|
|
- if ($data['companyid'] != $res['companyid'] && empty($data['zone']) && $res['role'] == 2) {
|
|
|
- $projectids = $this->Project_model->get_project_ids(array('company'=>$data['companyid']));
|
|
|
- $data['zone'] = !empty($projectids) ? implode(',', $projectids) : 0;
|
|
|
- }
|
|
|
+ unset($data['password']);
|
|
|
+
|
|
|
if ($this->User_model->getDataCount(array('username'=>$data['username']),$where['id'])) {
|
|
|
exit(json_result('0706',$this->response['0706'],array()));
|
|
|
}
|
|
|
- if (!empty($data['mobile']) && $this->User_model->getDataCount(array('mobile'=>$data['mobile']),$where['id'])) {
|
|
|
+ if (!empty($data['phone']) && $this->User_model->getDataCount(array('phone'=>$data['phone']),$where['id'])) {
|
|
|
exit(json_result('0721',$this->response['0721'],array()));
|
|
|
}
|
|
|
if (!empty($data['email']) && $this->User_model->getDataCount(array('email'=>$data['email']),$where['id'])) {
|
|
@@ -333,185 +248,23 @@ class User extends Base_Controller{
|
|
|
$this->User_model->update_user($data,$where['id']);
|
|
|
|
|
|
$userid = $where['id'];
|
|
|
- $this->add_operation_log('update',"修改用户,用户名\"{$data['realname']}\"",0);
|
|
|
- $this->add_operation_log('update',"Update user.User name:\"{$data['realname']}\"",0,1);
|
|
|
+ $this->add_operation_log('update',"修改用户,用户名\"{$data['name']}\"",0);
|
|
|
+ $this->add_operation_log('update',"Update user.User name:\"{$data['name']}\"",0,1);
|
|
|
}
|
|
|
|
|
|
exit(json_result('0000',$this->response['0000'],array('id'=>$userid)));
|
|
|
}
|
|
|
|
|
|
- // 获取用户权限列表
|
|
|
- public function privilege_list(){
|
|
|
- $userid = $this->input->post('userid',true);
|
|
|
-
|
|
|
- if (empty($userid)) {
|
|
|
- exit(json_result('0007',$this->response['0007'],array()));
|
|
|
- }
|
|
|
-
|
|
|
- $version = $this->session->userdata('version');
|
|
|
- $userData = $this->User_model->getOne($userid,'role');
|
|
|
-
|
|
|
- $privilege_list = $this->Privilnode_model->get_all_privilnode(SYSTEM_ADMIN);
|
|
|
- // 选中用户拥有的权限
|
|
|
- if (!empty($userid)) {
|
|
|
- $data = $this->User_model->getOne($userid,'privilege');
|
|
|
- $privilegeArr = explode(',', $data['privilege']);
|
|
|
-
|
|
|
- foreach ($privilege_list as &$v) {
|
|
|
- if (!empty($version)) {
|
|
|
- $v['name'] = $v['en_name'];
|
|
|
- }
|
|
|
- if ($userData['role'] == SYSTEM_ADMIN || in_array($v['id'], $privilegeArr)) {
|
|
|
- $v['select'] = 1;
|
|
|
- }else{
|
|
|
- $v['select'] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 权限分级
|
|
|
- $res = list_to_tree($privilege_list, $pk='id', $pid = 'parentid', $child = 'sub_list', $root = 0);
|
|
|
- exit(json_result('0000',$this->response['0000'],array('list'=>$res)));
|
|
|
- }
|
|
|
-
|
|
|
- // 修改用户权限
|
|
|
- public function save_user_privilege(){
|
|
|
- $role = $this->get_user_info('role');
|
|
|
- // if ($role == COMPANY_CUSTOMER) {
|
|
|
- // exit(json_result('0011', $this->response['0011'], array()));
|
|
|
- // }
|
|
|
-
|
|
|
- $privilegeIds = $this->input->post('privilegeIds',true);
|
|
|
- $userid = $this->input->post('userid',true);
|
|
|
-
|
|
|
- $res = $this->User_model->getOne($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->change_privilege($privilegeIds,$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()));
|
|
|
- }
|
|
|
-
|
|
|
- // 用户反馈
|
|
|
- public function feedback(){
|
|
|
- $data['username'] = $this->input->post('name',true);
|
|
|
- $data['mobile'] = $this->input->post('mobile',true);
|
|
|
- $data['detail'] = $this->input->post('detail',true);
|
|
|
-
|
|
|
- if(empty($data['username'])) exit(json_result('0714',$this->response['0714'],array()));
|
|
|
- if(empty($data['mobile'])) exit(json_result('0715',$this->response['0715'],array()));
|
|
|
- if(empty($data['detail'])) exit(json_result('0716',$this->response['0716'],array()));
|
|
|
- $data['feedtime'] = date('Y-m-d H:i:s');
|
|
|
+ // 删除账户
|
|
|
+ public function del(){
|
|
|
+ $id = intval($this->input->post('id',true));
|
|
|
|
|
|
- $res = $this->Feedback_model->insert($data);
|
|
|
+ if (empty($id)) exit(json_result('0007',$this->response['0007']));
|
|
|
|
|
|
- exit(json_result('0000',$this->response['0000'],array('id'=>$res)));
|
|
|
- }
|
|
|
+ $this->User_model->delete(['id'=>$id]);
|
|
|
|
|
|
- // 获取项目权限列表
|
|
|
- public function get_porject_list(){
|
|
|
- $userid = intval($this->input->post('userid',true));
|
|
|
- $companyid = intval($this->input->post('companyid',true));
|
|
|
- $zoneId = intval($this->input->post('zoneid',true));
|
|
|
- $countryId = intval($this->input->post('countryId',true));
|
|
|
- $provinceId = intval($this->input->post('provinceId',true));
|
|
|
- $cityId = intval($this->input->post('cityId',true));
|
|
|
- $areaId = intval($this->input->post('areaId',true));
|
|
|
-
|
|
|
- $idArr = array();
|
|
|
- if (!empty($areaId)) {
|
|
|
- $idArr = array($areaId);
|
|
|
- }elseif (!empty($cityId)) {
|
|
|
- $res1 = $this->db->query('select id from global_location where pid = '.$cityId)->result_array();
|
|
|
- if (empty($res1)) {
|
|
|
- $idArr = array($cityId);
|
|
|
- }else{
|
|
|
- $idArr = array_column($res1, 'id');
|
|
|
- }
|
|
|
- }elseif (!empty($provinceId)) {
|
|
|
- $res1 = $this->db->query('select id from global_location where pid = '.$provinceId)->result_array();
|
|
|
- if (empty($res1)) {
|
|
|
- $idArr = array($provinceId);
|
|
|
- }else{
|
|
|
- $idStr1 = implode(',', array_column($res1, 'id'));
|
|
|
- $res2 = $this->db->query('select id from global_location where pid in ('.$idStr1.')')->result_array();
|
|
|
- if (empty($res2)) {
|
|
|
- $idArr = array_column($res1, 'id');
|
|
|
- }else{
|
|
|
- $idArr = array_column($res2, 'id');
|
|
|
- }
|
|
|
- }
|
|
|
- }elseif (!empty($countryId)) {
|
|
|
- $res1 = $this->db->query('select id from global_location where pid = '.$countryId)->result_array();
|
|
|
- if (empty($res1)) {
|
|
|
- $idArr = array($countryId);
|
|
|
- }else{
|
|
|
- $idStr1 = implode(',', array_column($res1, 'id'));
|
|
|
- $res2 = $this->db->query('select id from global_location where pid in ('.$idStr1.')')->result_array();
|
|
|
- if (empty($res2)) {
|
|
|
- $idArr = array_column($res1, 'id');
|
|
|
- }else{
|
|
|
- $idStr2 = implode(',', array_column($res1, 'id'));
|
|
|
- $res3 = $this->db->query('select id from global_location where pid in ('.$idStr2.')')->result_array();
|
|
|
- if (empty($res3)) {
|
|
|
- $idArr = array_column($res2, 'id');
|
|
|
- }else{
|
|
|
- $idArr = array_column($res3, 'id');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $where = array();
|
|
|
- if (!empty($companyid)) {
|
|
|
- $where['company'] = $companyid;
|
|
|
- }
|
|
|
- if (!empty($idArr)) {
|
|
|
- $where['cityid'] = $idArr;
|
|
|
- }
|
|
|
- $projectList = $this->Project_model->get_list($where, 'id,projectname as name',NULL, NULL, 'id desc');
|
|
|
- $userData = $this->User_model->getOne($userid,'zone,role');
|
|
|
- $hasArr = empty($userData['zone']) ? [] : array_unique(explode(',', $userData['zone']));
|
|
|
- foreach ($projectList as &$p) {
|
|
|
- if ($userData['role'] == SYSTEM_ADMIN || in_array($p['id'], $hasArr)) {
|
|
|
- $p['select'] = 1;
|
|
|
- }else{
|
|
|
- $p['select'] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- exit(json_result('0000',$this->response['0000'],array('projects'=>$projectList)));
|
|
|
+ exit(json_result('0000',$this->response['0000']));
|
|
|
}
|
|
|
|
|
|
- // 修改用户项目权限
|
|
|
- public function save_user_project(){
|
|
|
- $projects = $this->input->post('projects',true);
|
|
|
- $userid = intval($this->input->post('userid'));
|
|
|
- $role = $this->get_user_info('role');
|
|
|
- if ($userid <= 0) {
|
|
|
- exit(json_result('0007',$this->response['0007'],array()));
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($projects)) exit(json_result('0717',$this->response['0717'],array()));
|
|
|
-
|
|
|
- $res = $this->User_model->getOne($userid);
|
|
|
- // 判断用户权限
|
|
|
- if ($role >= $res['role']) {
|
|
|
- exit(json_result('0011',$this->response['0011'],array()));
|
|
|
- }
|
|
|
-
|
|
|
- $this->User_model->update_user(array('zone'=>$projects),$userid);
|
|
|
-
|
|
|
- exit(json_result('0000',$this->response['0000'],array()));
|
|
|
- }
|
|
|
}
|
|
|
?>
|