DESKTOP-9JTA2JJ\HP 5 tahun lalu
induk
melakukan
c8feb9a2a8
1 mengubah file dengan 41 tambahan dan 69 penghapusan
  1. 41 69
      api/application/controllers/Home.php

+ 41 - 69
api/application/controllers/Home.php

@@ -11,28 +11,14 @@ class Home extends Base_Controller {
     }
 
     private function get_project_id(){
-        $countryId = intval($this->input->post('countryId',true));
+        $cityId = intval($this->input->post('cityId',true));
         $proId = intval($this->input->post('proId',true));
         $projectIdArr = array();
         $areaList = array();
         $cityList = array();
         $proList = array();
-        $comList = array();
-        if (!empty($countryId)) {
-            $comList[] = array('id'=>$countryId,'level'=>1);
-            $list = $this->Global_location_model->get_list(['pid'=>$countryId],'id,level');
-            foreach ($list as $key => $value) {
-                if ($value['level'] == 2) {
-                    $proList[] = $value;
-                }elseif ($value['level'] == 3) {
-                    $cityList[] = $value;
-                }elseif ($value['level'] == 4) {
-                    $areaList[] = $value;
-                }
-            }
-        }
         if (!empty($proId)) {
-            $proList[] = array('id'=>$proId,'level'=>2);
+            $proList[] = array('id'=>$proId,'level'=>1);
             $list = $this->Global_location_model->get_list(['pid'=>$proId],'id,level');
             foreach ($list as $key => $value) {
                 if ($value['level'] == 3) {
@@ -42,14 +28,14 @@ class Home extends Base_Controller {
                 }
             }
         }
-        if (!empty($cityList)) {
-            $cityArr = array_unique(array_column($cityList, 'id'));
-            $list = $this->Global_location_model->get_list(['pid'=>$cityArr],'id,level');
+        if (!empty($cityId)) {
+            $cityList[] = array('id'=>$cityId,'level'=>2);
+            $list = $this->Global_location_model->get_list(['pid'=>$cityId],'id,level');
             foreach ($list as $key => $value) {
                 if ($value['level'] == 4) $areaList[] = $value;
             }
         }
-        $cityArr = array_unique(array_merge(array_column($comList, 'id'),array_column($proList, 'id'),array_column($cityList, 'id'),array_column($areaList, 'id')));
+        $cityArr = array_unique(array_merge(array_column($proList, 'id'),array_column($cityList, 'id'),array_column($areaList, 'id')));
 
         if (!empty($cityArr)) {
             $res = $this->Project_model->get_list(['cityid'=>$cityArr],'id');
@@ -265,6 +251,23 @@ class Home extends Base_Controller {
 
     // 故障信息列表
     public function alarm_list(){
+        $projectIdArr = $this->get_project_id();
+
+        $role = $this->get_user_info('role');
+        $where = array();
+        if ($role != SYSTEM_ADMIN){
+            $company = $this->get_user_info('company');
+            $where[] = 'P.company = '.$company;
+        }
+
+        if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
+
+        $where1 = implode(' AND ', $where);
+        $join = [
+            ['table'=>'project as P','cond'=>'P.id = L.projectid','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) on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
+        $total = $this->Lamp_model->get_list_by_join($where1, 'P.projectname,WI.batstatus,WI.panelstatus,WI.lampstatus,WI.tempstatus,P.cityid',NULL, NULL, $join, NULL, NUll, 'L');
 
     	exit(json_result('0000',$this->response['0000'],array()));
     }
@@ -448,7 +451,8 @@ class Home extends Base_Controller {
         exit(json_result('0000',$this->response['0000'],$lampData));
     }
 
-    public function get_country(){
+    public function get_province(){
+        // $countryId = intval($this->input->post('countryId',true));
         $role = $this->get_user_info('role');
         $where = array();
         if ($role != SYSTEM_ADMIN) {
@@ -462,16 +466,13 @@ class Home extends Base_Controller {
         $areaList = array();
         $cityList = array();
         $proList = array();
-        $comList = array();
 
         foreach ($list as $key => $value) {
-            if ($value['level'] == 1) {
-                $comList[] = $value;
-            }elseif ($value['level'] == 2) {
+            if ($value['level'] == 2) {
                 $proList[] = $value;
             }elseif ($value['level'] == 3) {
                 $cityList[] = $value;
-            }else {
+            }elseif ($value['level'] == 4) {
                 $areaList[] = $value;
             }
         }
@@ -480,11 +481,9 @@ class Home extends Base_Controller {
             $cityArr = array_unique(array_column($areaList, 'pid'));
             $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
             foreach ($list as $key => $value) {
-                if ($value['level'] == 1) {
-                    $comList[] = $value;
-                }elseif ($value['level'] == 2) {
+                if ($value['level'] == 2) {
                     $proList[] = $value;
-                }else {
+                }elseif ($value['level'] == 3) {
                     $cityList[] = $value;
                 }
             }
@@ -495,32 +494,19 @@ class Home extends Base_Controller {
             $cityArr = array_unique(array_column($cityList, 'pid'));
             $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
             foreach ($list as $key => $value) {
-                if ($value['level'] == 1) {
-                    $comList[] = $value;
-                }else {
-                    $proList[] = $value;
-                }
-            }
-        }
-
-        if (!empty($proList)) {
-            $cityArr = array_unique(array_column($proList, 'pid'));
-            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
-            foreach ($list as $key => $value) {
-                if ($value['level'] == 1) $comList[] = $value;
+                if ($value['level'] == 2) $proList[] = $value;
             }
         }
 
-        if (empty($comList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
+        if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
 
-        $cityArr = array_unique(array_column($comList, 'id'));
+        $cityArr = array_unique(array_column($proList, 'id'));
         $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
         exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
     }
-
-    public function get_province(){
-        $countryId = intval($this->input->post('countryId',true));
+    public function get_city(){
+        $proId = intval($this->input->post('proId',true));
         $role = $this->get_user_info('role');
         $where = array();
         if ($role != SYSTEM_ADMIN) {
@@ -533,12 +519,9 @@ class Home extends Base_Controller {
         $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
         $areaList = array();
         $cityList = array();
-        $proList = array();
 
         foreach ($list as $key => $value) {
-            if ($value['level'] == 2) {
-                $proList[] = $value;
-            }elseif ($value['level'] == 3) {
+            if ($value['level'] == 3) {
                 $cityList[] = $value;
             }elseif ($value['level'] == 4) {
                 $areaList[] = $value;
@@ -549,27 +532,16 @@ class Home extends Base_Controller {
             $cityArr = array_unique(array_column($areaList, 'pid'));
             $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
             foreach ($list as $key => $value) {
-                if ($value['level'] == 2) {
-                    $proList[] = $value;
-                }elseif ($value['level'] == 3) {
-                    $cityList[] = $value;
-                }
+                if ($value['level'] == 3) $cityList[] = $value;
             }
         }
 
+        if (empty($cityList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
 
-        if (!empty($cityList)) {
-            $cityArr = array_unique(array_column($cityList, 'pid'));
-            $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
-            foreach ($list as $key => $value) {
-                if ($value['level'] == 2) $proList[] = $value;
-            }
-        }
-
-        if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
-
-        $cityArr = array_unique(array_column($proList, 'id'));
-        $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
+        $cityArr = array_unique(array_column($cityList, 'id'));
+        $where = ['id'=>$cityArr];
+        if (!empty($proId)) $where['pid'] = $proId;
+        $list = $this->Global_location_model->get_list($where,'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
 
         exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
     }