瀏覽代碼

no message

wzh 5 年之前
父節點
當前提交
17df15ab77

+ 2 - 2
api/application/controllers/Company.php

@@ -102,11 +102,11 @@ class Company extends Base_Controller {
 		$company = $this->get_user_info('company');
 		$role = $this->get_user_info('role');
 
-		$type = intval($this->input->post('type',true));
+		// $type = intval($this->input->post('type',true));
 
 		if (!empty($type)) $where['type'] = $type;
 
-		if ($type == $role) $where['id'] = $company;
+		if ($role != SYSTEM_ADMIN) $where['id'] = $company;
 
         $list = $this->Company_model->get_list($where, 'id,name',null, null, 'name asc,id desc', NUll);
 

+ 7 - 6
api/application/controllers/Home.php

@@ -415,19 +415,20 @@ class Home extends Base_Controller {
             }
         }
 
-        if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
+        // if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
 
         // $where[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
         // $where[] = 'L.netstatus = 1';
         $where[] = '(L.controllerstatus = 5 OR L.netstatus = 0)';
         $where1 = implode(' AND ', $where);
+        // var_dump($where1);die;
         $join = [
-            ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
+            ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'left']
         ];
-        $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
-        $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'inner'];
-        $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'inner'];
-        $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid','type'=>'inner'];
+        $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'left'];
+        $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'left'];
+        $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'left'];
+        $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid','type'=>'left'];
         $list = $this->Lamp_model->get_list_by_join($where1, 'P.projectname as project,P.id as projectid,WI.batstatus,WI.id,L.id as lampid,WI.panelstatus,WI.lampstatus,WI.onlinestatus,WI.tempstatus,P.cityid,L.address,L.section,G1.english_name as areaName,G2.english_name as cityName,G3.english_name as proName,WI.updatetime,G1.timezone',NULL, NULL, $join, NULL, NUll, 'L');
 
         $batstatus = $this->config->item('batstatus');

+ 150 - 159
api/application/controllers/Map.php

@@ -38,6 +38,7 @@ class Map extends Base_Controller{
 				   L.longitude as longitude,
 				   L.latitude as latitude,
 				   L.isfaulted,
+				   L.controllerstatus,
 				   L.netstatus as netStatus,
 				   L.updatetime as updatetime,
 				   L.lampvoltage,
@@ -56,6 +57,34 @@ class Map extends Base_Controller{
 		$lat_high = $this->input->post('lat_high',true);
 		$multiple = intval($this->input->post('multiple',true));
 		
+		$company = intval($this->input->post('company', true));
+        if (!empty($type) && !empty($company)) {
+            if ($type == 2) {
+                $filter['L.manu'] = $company;
+            }elseif ($type == 3) {
+                $filter['L.supplier'] = $company;
+            }elseif ($type == 4) {
+                $filter['L.po'] = $company;
+            }else {
+                $filter['P.cityid'] = $company;
+            }
+        }
+
+        $role = $this->get_user_info('role');
+        $company2 = $this->get_user_info('company');
+
+        if ($role != SYSTEM_ADMIN) {
+            if ($role == 2) {
+                // $filter .= ' AND L.manu = '.$company2;
+                // $countWhere[] = 'manu = '.$company2;
+            }elseif ($role == 3) {
+                $filter['L.supplier'] = $company2;
+            }elseif ($role == 4) {
+                $filter['L.po'] = $company2;
+            }else {
+                $filter['P.cityid'] = $company2;
+            }
+        }
 
 		if (!empty($keyword)) {
 			$filter['keyword'] = $keyword;
@@ -83,7 +112,7 @@ class Map extends Base_Controller{
 				$filter['L.netstatus'] = 1;
 				break;  
 			case '3':	// 故障
-				$filter['L.isfaulted'] = 1;
+				$filter['L.controllerstatus'] = 5;
 				break;
 			case '4':	// 离线
 				// $filter['AI.status !='] = 0;
@@ -169,10 +198,12 @@ class Map extends Base_Controller{
 				if (!isset($location[$value['longitude'].','.$value['latitude']])) {
 					$location[$value['longitude'].','.$value['latitude']] = array();
 				}
-				if (isset($value['isfaulted']) && $value['isfaulted'] == 1) {
-					$t['lampstatus'] = 0;
-				}else{
+				if ((isset($value['controllerstatus']) && $value['controllerstatus'] == 5) || isset($value['netstatus']) && $value['netstatus'] == 0) {
+					$t['isfaulted'] = 1;
 					$t['lampstatus'] = 1;
+				}else{
+					$t['lampstatus'] = 0;
+					$t['isfaulted'] = 0;
 				}
 				// $t['isfaulted'] = 0;
 				if(empty($t['longitude'])) $t['longitude'] = 0;
@@ -253,11 +284,18 @@ class Map extends Base_Controller{
 		    		$indArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
 		            $v['chargestage'] = isset($indArr[intval($v['chargestage'])]) ? $indArr[intval($v['chargestage'])] : $v['chargestage'];
 		        }
-				if (isset($v['isfaulted']) && $v['isfaulted'] == 1) {
-					$v['lampstatus'] = 0;
+		        if ((isset($v['controllerstatus']) && $v['controllerstatus'] == 5) || isset($v['netstatus']) && $v['netstatus'] == 0) {
+					$t['isfaulted'] = 1;
+					$t['lampstatus'] = 1;
 				}else{
-					$v['lampstatus'] = 1;
+					$t['lampstatus'] = 0;
+					$t['isfaulted'] = 0;
 				}
+				// if (isset($v['isfaulted']) && $v['isfaulted'] == 1) {
+				// 	$v['lampstatus'] = 0;
+				// }else{
+				// 	$v['lampstatus'] = 1;
+				// }
 				if (isset($lampid) && $v['id'] == $lampid) {
 					$ld = $v;
 					continue;
@@ -565,57 +603,57 @@ class Map extends Base_Controller{
     }
 
     // 灯控开关,已项目为单位
-    public function turnonoff(){
-    	$role = $this->get_user_info('role');
-        // if ($role == COMPANY_CUSTOMER) {
-        //     exit(json_result('0011', $this->response['0011'], array()));
-        // }
-
-        $projectid = intval($this->input->post('projectid',true));
-        $type = intval($this->input->post('type',true));
-        $mode = intval($this->input->post('mode',true));       
-        $userid = $this->get_user_info('id'); 
-        // $companyid = $this->get_user_info('companyid'); 
-
-        if (empty($projectid)) {
-        	$projectid = $this->Project_model->get_projectid_by_role($role,$userid,0);
-        	$projectid = empty($projectid) ? '0' : $projectid;
-        }
-
-        $ids = explode(',', $projectid);
-        foreach ($ids as $v) {
-        	$data['cmdtype'] = 2;
-	        $data['relateid'] = $v;
-	        $data['statuscmd'] = $type;
-	        $data['updatetime'] = date("Y-m-d H:i:s");
-
-	        $recordid = $this->Batmanage_model->get_record_id($data, 'batch_switch_cmd');
-	        if(!$recordid){
-	            exit(json_result('0009', $this->response['0009'], array()));
-	        }
-
-	        $cmd = '{"cmd_type":"batch_switch_cmd","cmd_id":'.$recordid.',"broadcast":'.$mode.'}';
-	        $cmdret = send_cmd($cmd,0);
-	        // if($cmdret === false){
-	        //     exit(json_result('0008', $this->response['0008'], array()));
-	        // }
-        }
-        exit(json_result('0213',$this->response['0213']));
-        // $res = json_decode($cmdret, true);
-        // if ($res['result'] == false) {
-        // 	$version = $this->session->userdata('version');
-        // 	if (empty($version)) {
-        // 		$res['msg'] = transfer_error_tips($res['msg']);
-        //     	exit(json_result('0010', $res['msg'], array()));
-        // 	}else{
-        // 		$res['msg'] = empty($res['msg']) ? 'Unknown error' : $res['msg'];
-        //     	exit(json_result('other', $res['msg'], array()));
-        // 	}
+    // public function turnonoff(){
+    // 	$role = $this->get_user_info('role');
+    //     // if ($role == COMPANY_CUSTOMER) {
+    //     //     exit(json_result('0011', $this->response['0011'], array()));
+    //     // }
+
+    //     $projectid = intval($this->input->post('projectid',true));
+    //     $type = intval($this->input->post('type',true));
+    //     $mode = intval($this->input->post('mode',true));       
+    //     $userid = $this->get_user_info('id'); 
+    //     // $companyid = $this->get_user_info('companyid'); 
+
+    //     if (empty($projectid)) {
+    //     	$projectid = $this->Project_model->get_projectid_by_role($role,$userid,0);
+    //     	$projectid = empty($projectid) ? '0' : $projectid;
+    //     }
+
+    //     $ids = explode(',', $projectid);
+    //     foreach ($ids as $v) {
+    //     	$data['cmdtype'] = 2;
+	   //      $data['relateid'] = $v;
+	   //      $data['statuscmd'] = $type;
+	   //      $data['updatetime'] = date("Y-m-d H:i:s");
+
+	   //      $recordid = $this->Batmanage_model->get_record_id($data, 'batch_switch_cmd');
+	   //      if(!$recordid){
+	   //          exit(json_result('0009', $this->response['0009'], array()));
+	   //      }
+
+	   //      $cmd = '{"cmd_type":"batch_switch_cmd","cmd_id":'.$recordid.',"broadcast":'.$mode.'}';
+	   //      $cmdret = send_cmd($cmd,0);
+	   //      // if($cmdret === false){
+	   //      //     exit(json_result('0008', $this->response['0008'], array()));
+	   //      // }
+    //     }
+    //     exit(json_result('0213',$this->response['0213']));
+    //     // $res = json_decode($cmdret, true);
+    //     // if ($res['result'] == false) {
+    //     // 	$version = $this->session->userdata('version');
+    //     // 	if (empty($version)) {
+    //     // 		$res['msg'] = transfer_error_tips($res['msg']);
+    //     //     	exit(json_result('0010', $res['msg'], array()));
+    //     // 	}else{
+    //     // 		$res['msg'] = empty($res['msg']) ? 'Unknown error' : $res['msg'];
+    //     //     	exit(json_result('other', $res['msg'], array()));
+    //     // 	}
             
-        // }else{
-        // 	exit(json_result('0000', $this->response['0000'], array()));
-        // }
-    }
+    //     // }else{
+    //     // 	exit(json_result('0000', $this->response['0000'], array()));
+    //     // }
+    // }
 
     // 故障数/网关数/装机数
     public function data_list(){
@@ -665,17 +703,19 @@ class Map extends Base_Controller{
         $join[] = ['table'=>'lampinfo as L','cond'=>'L.id = AI.lampid','type'=>'inner'];
         $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner'];
         $join[] = ['table'=>'global_location as G','cond'=>'G.id = P.cityid','type'=>'inner'];
-    	$data = $this->Alarm_model->get_list_by_multi_join(['AI.id'=>$alarmid], 'L.number,AI.updatetime,AI.panelstatus,AI.lampstatus,AI.id as alarmid,AI.tempstatus,AI.batstatus,G.timezone,AI.status,P.projectname',NULL, NULL, $join, NULL, NUll, 'AI', true);
+    	$data = $this->Alarm_model->get_list_by_multi_join(['AI.lampid'=>$alarmid], 'L.number,AI.updatetime,AI.panelstatus,AI.lampstatus,AI.onlinestatus,AI.id as alarmid,AI.tempstatus,AI.batstatus,G.timezone,AI.status,P.projectname',NULL, NULL, $join, 'updatetime DESC', NUll, 'AI', true);
 
     	$batstatus = $this->config->item('batstatus');
         $panelstatus = $this->config->item('panelstatus');
         $lampstatus = $this->config->item('lampstatus');
         $tempstatus = $this->config->item('tempstatus');
+        $onlinestatus = $this->config->item('onlinestatus');
         $temp2 = array();
         if (isset($batstatus[$data['batstatus']])) $temp2[] = $batstatus[$data['batstatus']];
         if (isset($panelstatus[$data['panelstatus']])) $temp2[] = $panelstatus[$data['panelstatus']];
         if (isset($lampstatus[$data['lampstatus']])) $temp2[] = $lampstatus[$data['lampstatus']];
         if (isset($tempstatus[$data['tempstatus']])) $temp2[] = $tempstatus[$data['tempstatus']];
+        if (isset($onlinestatus[$data['onlinestatus']])) $temp2[] = $onlinestatus[$data['onlinestatus']];
         if (!empty($temp2)) {
             $data['stralarmtype'] = implode(',', $temp2);
         }else{
@@ -850,7 +890,7 @@ class Map extends Base_Controller{
     	$data['lamp_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid']));
     	$data['lamp_count'] = intval($data['lamp_count']);
     	// 故障数
-    	$data['fail_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'status'=>1));
+    	$data['fail_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'controllerstatus'=>5));
     	$data['fail_count'] = intval($data['fail_count']);
     	$data['fail_rate'] = round($data['fail_count']/$data['lamp_count']*100,2);
     	// 在线数
@@ -878,64 +918,39 @@ class Map extends Base_Controller{
     	$lightStatus = intval($this->input->post('lightStatus',true));
     	if (!empty($lightStatus)) $where['lightStatus'] = 1;
     	$failStatus = intval($this->input->post('failStatus',true));
-    	if (!empty($failStatus)) $where['status'] = 1;
+    	if (!empty($failStatus)) $where['controllerstatus'] = 5;
 
-    	$list = $this->Lamp_model->get_list_in(null, array(), 'L.id,L.number,L.netstatus as netStatus,L.lighteness,L.isfaulted',$where);
+    	$list = $this->Lamp_model->get_list_in(null, array(), 'L.id,L.number,L.netstatus as netStatus,L.lighteness,L.isfaulted,L.controllerstatus,AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.onlinestatus',$where);
     	$version = $this->session->userdata('version');
     	$data['lampList'] = array();
     	foreach ($list as $value) {
     		// 故障信息处理
-            if ($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype'])) {
-                if (empty($version)) {
-                    $value['stralarmtype'] = '否';
-                    $value['isfaulted'] = '0';
-                }else{
-                    $value['stralarmtype'] = 'Nothing';
-                    $value['isfaulted'] = '0';
-                } 
-            }else{
-                if (empty($version)) {
-                    $stralarmtype = trim($value['stralarmtype']);
-                    if (!empty($stralarmtype)) {
-                        $alarmArr = explode(',', $stralarmtype);
-                        $temp2 = array();
-                        foreach ($alarmArr as $a) {
-                            if ($a == '电池故障') {
-                                $a = '电池电压异常';
-                            }
-                            $temp2[] = $a;
-                        }
-                        $value['stralarmtype'] = implode(',', $temp2);
-                        $value['isfaulted'] = '1';
-                    }else{
-                        $value['stralarmtype'] = '否';
-                        $value['isfaulted'] = '0';
-                    }
-                }else{
-                    $stralarmtype = trim($res['stralarmtype']);
-                    if (!empty($stralarmtype)) {
-                        $alarmArr = explode(',', $stralarmtype);
-                        $temp2 = array();
-                        foreach ($alarmArr as $a) {
-                            if ($a == '电池故障') {
-                                $a = '电池电压异常';
-                            }
-                            if ($value['lampProtocoltype'] == 1) {
-                                $temp[] = modbus_alarm_translate($a);
-                            }else{
-                                $temp[] = alarm_translate($a);
-                            }
-                        }
+            if ($value['controllerstatus'] == 5 || $value['netStatus'] == 0) {
+            	if ($value['netStatus'] == 0) {
+            		$value['stralarmtype'] = 'Offline failure';
+            		$value['isfaulted'] = '1';
+            	}else{
+            		$batstatus = $this->config->item('batstatus');
+                    $panelstatus = $this->config->item('panelstatus');
+                    $lampstatus = $this->config->item('lampstatus');
+                    $tempstatus = $this->config->item('tempstatus');
+                    $temp2 = array();
+                    if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
+                    if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
+                    if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
+                    if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
+                    if (!empty($temp2)) {
                         $value['stralarmtype'] = implode(',', $temp2);
                         $value['isfaulted'] = '1';
                     }else{
                         $value['stralarmtype'] = 'Nothing';
                         $value['isfaulted'] = '0';
                     }
-                }
+            	}
+            }else{
+                $value['stralarmtype'] = 'Nothing';
+                $value['isfaulted'] = '0';
             }
-            unset($value['failStatus']);
-            // unset($value['stralarmtype']);
             $data['lampList'][] = $value;
     	}
     	exit(json_result('0000',$this->response['0000'],$data));
@@ -968,7 +983,7 @@ class Map extends Base_Controller{
             $data['failure_count'] = intval($failure);
             $data['totalgeneration'] = round($arr['power'], 2);
             $data['total_lamp'] = intval($arr['num']);
-            $data['co2_emission'] = round($arr['power']*0.977, 3);
+            $data['co2_emission'] = round($arr['power']*0.977/1000, 3);
             $data['so2_emission'] = round($arr['power']*0.977/2620*8.5, 3);
             $data['coal_saving'] = round($arr['power']*0.977/2620, 3);
             $data['totalconsumption'] = round($arr['totalconsumption'],2);
@@ -1069,63 +1084,39 @@ class Map extends Base_Controller{
     	// if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
 
     	// 路灯列表
-    	$where['status'] = 1;
+    	$where['controllerstatus'] = 5;
     	if (!empty($lampid)) $where['lampid'] = $lampid;
 
-    	// $list = $this->Lamp_model->get_list_in(null, array(), 'L.number,L.isfaulted,AI.stralarmtype,AI.updatetime as alarmDate,AI.id as alarmId,L.id as lampId,L.protocoltype as lampProtocoltype,L.section,AI.status as failStatus',$where);
+    	$list = $this->Lamp_model->get_list_in(null, array(), 'L.number,L.isfaulted,AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.updatetime as alarmDate,AI.id as alarmId,L.id as lampId,L.protocoltype as lampProtocoltype,L.section,L.controllerstatus,L.netstatus',$where);
     	// $version = $this->session->userdata('version');
     	$data['list'] = array();
-    	// foreach ($list as $value) {
-    	// 	// var_dump($value['stralarmtype']);
-    	// 	// 故障信息处理
-    	// 	// var_dump($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype']));
-     //        if ($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype'])) {
-     //            if (empty($version)) {
-     //                $value['alarmInfo'] = '否';
-     //            }else{
-     //                $value['alarmInfo'] = 'Nothing';
-     //            } 
-     //        }else{
-     //            if (empty($version)) {
-     //                $stralarmtype = trim($value['stralarmtype']);
-     //                if (!empty($stralarmtype)) {
-     //                    $alarmArr = explode(',', $stralarmtype);
-     //                    $temp2 = array();
-     //                    foreach ($alarmArr as $a) {
-     //                        if ($a == '电池故障') {
-     //                            $a = '电池电压异常';
-     //                        }
-     //                        $temp2[] = $a;
-     //                    }
-     //                    $value['alarmInfo'] = implode(',', $temp2);
-     //                }else{
-     //                    $value['alarmInfo'] = '否';
-     //                }
-     //            }else{
-     //                $stralarmtype = trim($value['stralarmtype']);
-     //                if (!empty($stralarmtype)) {
-     //                    $alarmArr = explode(',', $stralarmtype);
-     //                    $temp2 = array();
-     //                    foreach ($alarmArr as $a) {
-     //                        if ($a == '电池故障') {
-     //                            $a = '电池电压异常';
-     //                        }
-     //                        if ($value['lampProtocoltype'] == 1) {
-     //                            $temp2[] = modbus_alarm_translate($a);
-     //                        }else{
-     //                            $temp2[] = alarm_translate($a);
-     //                        }
-     //                    }
-     //                    $value['alarmInfo'] = implode(',', $temp2);
-     //                }else{
-     //                    $value['alarmInfo'] = 'Nothing';
-     //                }
-     //            }
-     //        }
-     //        unset($value['failStatus']);
-     //        unset($value['stralarmtype']);
-     //        $data['list'][] = $value;
-    	// }
+    	foreach ($list as $value) {
+    		$value['alarmDate'] = date_change($value["alarmDate"],0,DEF_TIMEZONE);
+    		// 故障信息处理
+            if ($value['controllerstatus'] == 5 || $value['netstatus'] == 0) {
+                if ($value['netstatus'] == 0) {
+                	$value['alarmInfo'] = 'Offline failure';
+                }else {
+                	$batstatus = $this->config->item('batstatus');
+                    $panelstatus = $this->config->item('panelstatus');
+                    $lampstatus = $this->config->item('lampstatus');
+                    $tempstatus = $this->config->item('tempstatus');
+                    $temp2 = array();
+                    if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
+                    if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
+                    if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
+                    if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
+                    if (!empty($temp2)) {
+                        $value['alarmInfo'] = implode(',', $temp2);
+                    }else{
+                        $value['alarmInfo'] = 'Nothing';
+                    }
+                }
+            }else{
+                $value['alarmInfo'] = 'Nothing';
+            }
+            $data['list'][] = $value;
+    	}
     	exit(json_result('0000',$this->response['0000'],$data));
     }
 

+ 38 - 2
api/application/models/Lamp_model.php

@@ -57,6 +57,13 @@ class Lamp_model extends Base_model {
         if(isset($filter['lightStatus']) && is_numeric($filter['lightStatus'])){
 			$this->db->where('L.status', $filter['lightStatus']);
 		}
+
+		if(isset($filter['controllerstatus']) && is_numeric($filter['controllerstatus'])){
+			$this->db->group_start();
+			$this->db->where('L.controllerstatus', $filter['controllerstatus']);
+			$this->db->or_where('L.netstatus', 0);
+			$this->db->group_end();
+		}
         // 关键字搜索
 		if (isset($filter['keyword']) && !empty($filter['keyword'])){
 			// $this->db->like('L.number', $filter['keyword']);
@@ -126,7 +133,7 @@ class Lamp_model extends Base_model {
 	        // $this->db->join('battery_info_log as BI', 'L.id = BI.lampid AND BI.lampid=T.lampid AND BI.updatetime = T.time', 'left');
 	        // $this->db->join('history_info_log as HI', 'L.id = HI.lampid AND HI.lampid=T.lampid AND HI.updatetime = T.time', 'left');
 	        // $this->db->join('alarm_info_log as AI', 'L.id = AI.lampid AND AI.lampid=T.lampid AND AI.updatetime = T.time', 'left');
-	        // $this->db->join('(select t1.* from alarm_info_log t1, (select lampid, max(updatetime) as maxtime from alarm_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI', 'L.id = AI.lampid', 'left');
+	        $this->db->join('(select t1.* from warning_info_log t1, (select lampid, max(updatetime) as maxtime from warning_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as AI', 'L.id = AI.lampid', 'left');
 	        // $this->db->join('solar_info_log as SI', 'L.id = SI.lampid AND SI.lampid=T.lampid AND SI.updatetime = T.time', 'left');
 	        // $this->db->join('electric_info_log as EI', 'L.id = EI.lampid AND EI.lampid=T.lampid AND EI.updatetime = T.time', 'left');
 	        // $this->db->join('system_info_log as SIL', 'L.id = SIL.lampid AND SIL.lampid=T.lampid AND SIL.updatetime = T.time', 'left');
@@ -225,8 +232,18 @@ class Lamp_model extends Base_model {
         if(isset($filter['online']) && !empty($filter['online'])){
 			$this->db->where('L.netstatus', 1);
 		}
+		if(isset($filter['controllerstatus']) && !empty($filter['controllerstatus'])){
+			$this->db->group_start();
+			$this->db->where('L.controllerstatus', 5);
+			$this->db->or_where('L.netstatus', 0);
+			$this->db->group_end();
+		}
 		if(isset($filter['lightStatus']) && is_numeric($filter['lightStatus'])){
-			$this->db->where('L.status', $filter['lightStatus']);
+			$this->db->group_start();
+			$this->db->where('L.lighteness >', 0);
+			$this->db->or_where('L.netstatus', 1);
+			$this->db->group_end();
+			// $this->db->where('L.status', $filter['lightStatus']);
 		}
         // 关键字搜索
 		if (uri_string() == 'report/home') { // 数据报表页
@@ -290,6 +307,15 @@ class Lamp_model extends Base_model {
         return $query['total'];
     }
 
+    public function get_projectid_by_role($role,$userid,$companyid){
+    	if ($role == SYSTEM_ADMIN) {
+    		$list = $this->db->query('select id from project')->result_array();
+    	}else {
+    		$list = $this->db->query('select id from project where company = '.$companyid)->result_array();
+    	}
+    	return array_column($list, 'id');
+    }
+
     // gis地图页路灯列表
     public function get_list_by_role($role, $companyid, $projectid = 0, $userid = 0,$fields='*',$filter=array(),$type = 0,$is_map = 0){
     	$this->db->select($fields, false);
@@ -324,6 +350,16 @@ class Lamp_model extends Base_model {
 			unset($filter['keyword']);
 		}
 
+		// 筛选故障设备
+		if (isset($filter['L.controllerstatus']) && !empty($filter['L.controllerstatus'])) {
+			$this->db->like('L.controllerstatus',$filter['keyword']);
+			$this->db->group_start();
+			$this->db->where('L.controllerstatus', $filter['L.controllerstatus']);
+			$this->db->or_where('L.netstatus', 0);
+			$this->db->group_end();
+			unset($filter['L.controllerstatus']);
+		}
+
 		// 经纬度筛选
 		if (isset($filter['lng_low']) && is_numeric($filter['lng_low']) && isset($filter['lng_high']) && is_numeric($filter['lng_high']) && $filter['lng_low'] > $filter['lng_high']) {
 

+ 8 - 8
api/application/models/User_model.php

@@ -27,16 +27,16 @@ class User_model extends Base_Model {
 			return array();
 		}
 	
-		$query = "SELECT * FROM user WHERE id={$filter['user_id']}";
-		$query = $this->db->query($query);
-		$user  = $query->row_array();
-		if (empty($user)) {
-			return array();
-		}
+		// $query = "SELECT * FROM user WHERE id={$filter['user_id']}";
+		// $query = $this->db->query($query);
+		// $user  = $query->row_array();
+		// if (empty($user)) {
+		// 	return array();
+		// }
 	
-		$colum = 'role_'.$user['role'];
+		// $colum = 'role_'.$user['role'];
 		$query = "SELECT id,name FROM repair_user
-		WHERE {$colum}={$filter['user_id']}";
+		WHERE owner_id={$filter['user_id']}";
 	
 		$query = $this->db->query($query);
 		$data =  $query->result_array();