Browse Source

no message

wzh 5 years ago
parent
commit
390b0a5895
2 changed files with 121 additions and 1 deletions
  1. 4 0
      api/application/config/response.php
  2. 117 1
      api/application/controllers/Alarm.php

+ 4 - 0
api/application/config/response.php

@@ -102,6 +102,8 @@ $config['response']['0614'] = "请选择路灯";
 $config['response']['0615'] = "同一路灯半个小时之内只能调度一次";
 $config['response']['0616'] = "暂无数据,请在维修记录页面添加";
 $config['response']['0617'] = "维修人员id为1-999999的数字";
+$config['response']['0618'] = "邮箱不能为空";
+$config['response']['0619'] = "名称已经存在";
 //个人中心 0700-0799
 $config['response']['0701'] = "确认密码错误";
 $config['response']['0702'] = "密码错误";
@@ -268,6 +270,8 @@ $config['response_en']['0614'] = "Please select street light";
 $config['response_en']['0615'] = "The same street lamp can only be dispatched once in half an hour";
 $config['response_en']['0616'] = "No data temporarily, please add it on the maintenance record page";
 $config['response_en']['0617'] = "Number with maintainer ID 1-999999";
+$config['response_en']['0618'] = "The mailbox cannot be empty";
+$config['response_en']['0619'] = "The name already exists";
 //个人中心 0700-0799
 $config['response_en']['0701'] = "Confirm password error";
 $config['response_en']['0702'] = "Password error";

+ 117 - 1
api/application/controllers/Alarm.php

@@ -11,6 +11,7 @@ class Alarm extends Base_Controller {
 		$this->load->model('Lamp_model');
 		$this->load->model('Patrol_model');
 		$this->load->model('Repair_model');
+		$this->load->model('AlarmSendUserInfo_model');
 	}
 	
 	// 获取告警信息列表
@@ -392,4 +393,119 @@ class Alarm extends Base_Controller {
 		}
 		exit(json_result('0000',$this->response['0000'],array('list'=>$repair_list,'total'=>ceil($total/$count))));
 	}
-}
+
+	// 添加编辑推送人员
+	public function save_alarm_send_user(){
+		$id = intval($this->input->post('id',true));
+		$userId = $this->get_user_info('id');
+
+		$name = $this->input->post('name',true);
+		$email = $this->input->post('email',true);
+		$phone = $this->input->post('phone',true);
+
+		$project = $this->input->post('project',true);
+
+		if ($phone === '' || $phone === null) exit(json_result('0607',$this->response['0607']));
+		if ($email === '' || $email === null) exit(json_result('0618',$this->response['0618']));
+
+		$config = array();
+        // $config[] = array(
+        //     'field' => 'phone',
+        //     'label' => 'Phone',
+        //     'rules' => 'required|numeric|exact_length[11]',
+        //     'errors' => array(
+        //         'numeric' => '0406',
+        //         'exact_length' => '0406',
+        //     )
+        // );
+        
+        $config[] = array(
+                'field' => 'email',
+                'label' => 'Email',
+                'rules' => 'required|valid_email',
+                'errors' => array(
+                    'valid_email' => '0719',
+                )
+            );
+        $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)]));
+        }
+
+		if (!empty($id)) {
+			if ($this->AlarmSendUserInfo_model->getDataCount(['email'=>$email])) exit(json_result('0722',$this->response['0722']));
+			if ($this->AlarmSendUserInfo_model->getDataCount(['phone'=>$phone])) exit(json_result('0721',$this->response['0721']));
+			if ($this->AlarmSendUserInfo_model->getDataCount(['name'=>$name,'userId'=>$userId])) exit(json_result('0619',$this->response['0619']));
+
+			$data = array('name'=>$name,'email'=>$email,'phone'=>$phone,'project'=>$project,'userId'=>$userId);
+			$data['createTime'] = date('Y-m-d H:i:s',time());
+
+			$this->AlarmSendUserInfo_model->add($data);
+		}else{
+			if ($this->AlarmSendUserInfo_model->getDataCount(['email'=>$email],$id)) exit(json_result('0722',$this->response['0722']));
+			if ($this->AlarmSendUserInfo_model->getDataCount(['phone'=>$phone],$id)) exit(json_result('0721',$this->response['0721']));
+			if ($this->AlarmSendUserInfo_model->getDataCount(['name'=>$name,'userId'=>$userId],$id)) exit(json_result('0619',$this->response['0619']));
+
+			$data = array('name'=>$name,'email'=>$email,'phone'=>$phone,'project'=>$project,'userId'=>$userId);
+
+			$this->AlarmSendUserInfo_model->update($data,['id'=>$id]);
+		}
+		exit(json_result('0000',$this->response['0000']));
+	}
+
+	// 推送人员列表
+	public function alarm_send_user_list(){
+		$userId = $this->get_user_info('id');
+
+		$where = ['userId'=>$userId];
+
+		$page = intval($this->input->post('page'));
+		$count = intval($this->input->post('count'));
+		$page = empty($page) ? 1 : $page;
+
+		$limit = empty($count) ? 10 : $count;
+		$offset = ($page - 1) * $limit;
+
+		$list = $this->AlarmSendUserInfo_model->get_list($where, 'id,name,email,project,phone,is_send',$limit, $offset, 'convert(name using gbk) asc,id desc', NUll);
+		$total = $this->AlarmSendUserInfo_model->get_count($where);
+
+		exit(json_result('0000',$this->response['0000'],['list'=>$list,'total'=>$total]));
+	}
+
+	// 删除推送人员
+	public function del_alarm_send_user(){
+		$id = $this->input->post('id',true);
+		if ($id === '' || $id === null) exit(json_result('0007',$this->response['0007']));
+
+		$idArr = explode(',', $id);
+		foreach ($idArr as $id) {
+			$this->AlarmSendUserInfo_model->delete(['id'=>$id]);
+		}
+		exit(json_result('0000',$this->response['0000']));
+	}	
+
+	// 是否开启推送
+	public function set_alarm_send_user_status(){
+		$id = intval($this->input->post('id',true));
+		$status = intval($this->input->post('status',true));
+
+		if (empty($id)) exit(json_result('0007',$this->response['0007']));
+
+		$is_send = empty($status) ? 0 : 1;
+
+		$this->AlarmSendUserInfo_model->update(['is_send'=>$is_send],['id'=>$id]);
+		exit(json_result('0000',$this->response['0000']));
+	}
+	
+}
+
+
+
+
+
+
+
+
+