Browse Source

Merge branch 'master' of http://gogs.weclouds.xyz:3000/crazycat/IDCOL

XAWDJ0277HWXPT2\Administrator 5 years atrás
parent
commit
78d9fc8d3d

+ 20 - 0
api/application/controllers/Base_Controller.php

@@ -203,4 +203,24 @@ class Base_Controller extends CI_Controller {
             return $data;
         }
     }
+
+    // 系统日志
+    protected function add_operation_log($optype, $content, $logtype = 1,$language = 0){
+        $role = $this->get_user_info('role');
+        $company = $this->get_user_info('company');
+        $this->load->model('Syslog_model');
+        $userid = $this->get_user_info('id');
+        $data = array(
+            'time'     => date('Y-m-d H:i:s',time()),
+            'logtype'  => $logtype,
+            'optype'   => $optype,
+            'userid'   => $userid,
+            'content'  => $content,
+            'language' => $language
+        );
+        if ($role != SYSTEM_ADMIN) {
+            $data['company'] = $company;
+        }
+        $this->Syslog_model->add($data);
+    }
 }

+ 5 - 20
api/application/controllers/Common.php

@@ -34,6 +34,7 @@ class Common extends CI_Controller {
                 'id' => $user['id'],
                 'role' => intval($user['role']),
                 'name' => $user['name'],
+                'avatar' => empty($user['avatar']) ? '' : base_url($user['avatar'])
             );
             
             $this->userinfo = $user;
@@ -48,21 +49,9 @@ class Common extends CI_Controller {
 
         $type = intval($this->input->post("fileType",true));
 
-        if ($type == 0) {
-            $path = '../upload/image';
-            $config['file_name'] = md5(uniqid());   // 设置图片名字
-        }else{
-            $config['overwrite'] = true;
-            $filename = trim($_FILES['file']['name']);
-            if (strpos($filename, 'LampControl_') !== false) {
-                $path = '../upload/firewalld';
-                $config['file_name'] = $filename;
-            }else{
-                $path = '../upload/firewalld';
-                $config['file_name'] = 'openwrt-'.md5(uniqid());
-            }
-            
-        }
+        $path = '../upload/image';
+        $config['file_name'] = md5(uniqid());   // 设置图片名字
+       
         if (!file_exists($path)) {
             mkdir($path);
         }
@@ -87,11 +76,7 @@ class Common extends CI_Controller {
         {
             $data = $this->upload->data();
 
-            if ($type == 0) {
-                $imagePath = '/upload/image/'.$data['file_name'];
-            }else{
-                $imagePath = '/upload/firewalld/'.$data['file_name'];
-            }
+            $imagePath = '/upload/image/'.$data['file_name'];
             
             exit(json_result('0000',$this->response['0000'],array('path'=>base_url($imagePath))));
         }

+ 88 - 0
api/application/controllers/Group.php

@@ -17,6 +17,94 @@ class Map extends Base_Controller{
 
 		$where = array();
 
+		$keywords = $this->input->post('keywords',true);
+		if ($keywords !== '' && $keywords !== null) $where['name|'] = $keywords;
+
 		if ($role != SYSTEM_ADMIN) $where['userId'] = $userId;
+
+		$list = $this->Group_model->get_list($where,'id,name,number,lampid,value as light,remarks');
+
+		foreach ($list as $key => $value) {
+			$list[$key]['lampCount'] = count(array_unique(explode(',', $value['lampid'])));
+			unset($value['lampid']);
+			$list[$key]['status'] = $value['light'] > 0 ? 1 : 0;
+		}
+
+		exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
+	}
+
+	// 添加编辑分组
+	public function save(){
+		$userId = $this->get_user_info('id');
+		$id = intval($this->input->post('id',true));
+
+		$name = trim($this->input->post('name',true));
+		if($name === '' || $name === null) exit(json_result('',$this->response['']));
+
+		$number = $this->input->post('number',true);
+		if($name === '' || $name === null) exit(json_result('',$this->response['']));
+
+		$lampid = $this->input->post('lampId',true);
+		$lampid = $lampid === null ? '' : $lampid;
+
+		$remarks = $this->input->post('remarks',true);
+		$remarks = $remarks === null ? '' : $remarks;
+
+		if (empty($id)) {  // 添加
+			if ($this->Group_model->getDataCount(array('name'=>$name,'userId'=>$id))) {
+				exit(json_result('',$this->response['']));
+			}
+			if ($this->Group_model->getDataCount(array('name'=>$name,'userId'=>$id))) {
+				exit(json_result('',$this->response['']));
+			}
+			$data = array('name'=>$name,'number'=>$number,'lampid'=>$lampid,'remarks'=>$remarks);
+			$id = $this->Group_model->add($data);
+		}else {  // 编辑
+			if ($this->Group_model->getDataCount(array('name'=>$name,'userId'=>$id),$id)) {
+				exit(json_result('',$this->response['']));
+			}
+			if ($this->Group_model->getDataCount(array('name'=>$name,'userId'=>$id),$id)) {
+				exit(json_result('',$this->response['']));
+			}
+			$data = array('name'=>$name,'number'=>$number,'lampid'=>$lampid,'remarks'=>$remarks);
+			$this->Group_model->update($data,['id'=>$id]);
+		}
+
+		exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
+	}
+
+	// 删除分组
+	public function del(){
+		$id = intval($this->input->post('id',true));
+
+		if (empty($id)) exit(json_result('0007',$this->response['0007']));
+
+		$this->Group_model->delete(['id'=>$id]);
+
+		exit(json_result('0000',$this->response['0000']));
+	}
+
+	// 分组调光
+	public function turn_light(){
+		$light = intval($this->input->post('light',true));
+		$id = intval($this->input->post('id',true));
+
+		if (empty($id)) exit(json_result('0007',$this->response['0007']));
+
+		$this->Group_model->update(['value'=>$light],['id'=>$id]);
+		exit(json_result('0000',$this->response['0000']));
+	}
+
+	// 分组开关灯
+	public function turn_on_off(){
+		$status = intval($this->input->post('status',true));
+		$id = intval($this->input->post('id',true));
+
+		$light = $status == 0 ? 0 : 100;
+
+		if (empty($id)) exit(json_result('0007',$this->response['0007']));
+
+		$this->Group_model->update(['value'=>$light],['id'=>$id]);
+		exit(json_result('0000',$this->response['0000']));
 	}
 }

+ 1 - 0
api/application/controllers/Repair.php

@@ -304,6 +304,7 @@ class Repair extends Base_Controller
 		// if ($role == COMPANY_CUSTOMER) {
 		// 	exit(json_result('0011',$this->response['0011'],array()));
 		// }
+		$where['id'] = $this->input->post('id',true);
 
 		$data['repair_userid'] = $this->input->post('repair_id',true);  // 维修人员id
 		$data['repair_path'] = $this->input->post('address',true);     // 维修路段

+ 75 - 29
api/application/controllers/User.php

@@ -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()));
+	}
 }
 ?>