wzh 5 anos atrás
pai
commit
0015abf4f5

+ 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']));
 	}
 }

+ 0 - 1
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');
 	}