Browse Source

no message

DESKTOP-9JTA2JJ\HP 5 years ago
parent
commit
9afffbe902
1 changed files with 47 additions and 0 deletions
  1. 47 0
      api/application/controllers/Home.php

+ 47 - 0
api/application/controllers/Home.php

@@ -748,4 +748,51 @@ class Home extends Base_Controller {
         }
         exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
     }
+
+    // app额外接口
+    public function app_home_data(){
+        $data = array(
+            'project_count' => 0,
+            'upa_count' => 0,
+            'sup_count' => 0,
+            'manu_count' => 0,
+            'insert_power' => 0,
+            'gen_power' => 0,
+            'user_power' => 0,
+            'light_time' => 0,
+        );
+
+        $projectIdArr = $this->get_project_id();
+        if (empty($projectIdArr)) exit(json_result('0000',$this->response['0000'],$data));
+
+        $role = $this->get_user_info('role');
+        $where = array();
+        $data['project_count'] = count($projectIdArr);
+        $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
+        if ($role != SYSTEM_ADMIN){
+            $company = $this->get_user_info('company');
+            $where[] = 'P.company = '.$company;
+        }
+
+        $sql = 'select count(*) as total from (select L.manu from lampinfo L left join project P on L.projectid = P.id where '.implode(' AND ', $where).' AND L.manu != 0 AND L.manu != "" group by L.manu) t';
+        $total = $this->db->query($sql)->row_array();
+        $data['manu_count'] = $total['total'];
+
+        $sql = 'select count(*) as total from (select L.supplier from lampinfo L left join project P on L.projectid = P.id where '.implode(' AND ', $where).' AND L.supplier != 0 AND L.supplier != "" group by L.supplier) t';
+        $total = $this->db->query($sql)->row_array();
+        $data['sup_count'] = $total['total'];
+
+        $sql = 'select count(*) as total from (select G.id from lampinfo L left join project P on L.projectid = P.id left join global_location G on P.cityid = G.id where '.implode(' AND ', $where).' group by G.id) t';
+        $total = $this->db->query($sql)->row_array();
+        $data['upa_count'] = $total['total'];
+
+        $sql = 'select sum(L.totalLightTime) as light_time,sum(L.boardpower) as boardpower,sum(L.totalgeneration) as totalgeneration,sum(L.totalconsumption) as totalconsumption from lampinfo L left join project P on L.projectid = P.id where '.implode(' AND ', $where);
+        $total = $this->db->query($sql)->row_array();
+        $data['light_time'] = ceil($total['light_time']/60);
+        $data['insert_power'] = round($total['boardpower']/1000,3);
+        $data['gen_power'] = round($total['totalgeneration']/1000,3);
+        $data['user_power'] = round($total['totalconsumption']/1000,3);
+
+        exit(json_result('0000',$this->response['0000'],$data));
+    }
 }