|
@@ -10,8 +10,7 @@ class Home extends Base_Controller {
|
|
|
$this->load->model('Global_location_model');
|
|
|
}
|
|
|
|
|
|
- // 设备统计信息
|
|
|
- public function data(){
|
|
|
+ private function get_project_id(){
|
|
|
$countryId = intval($this->input->post('countryId',true));
|
|
|
$proId = intval($this->input->post('proId',true));
|
|
|
$projectIdArr = array();
|
|
@@ -56,6 +55,12 @@ class Home extends Base_Controller {
|
|
|
$res = $this->Project_model->get_list(['cityid'=>$cityArr],'id');
|
|
|
$projectIdArr = array_unique(array_column($res, 'id'));
|
|
|
}
|
|
|
+ return $projectIdArr;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设备统计信息
|
|
|
+ public function data(){
|
|
|
+ $projectIdArr = $this->get_project_id();
|
|
|
$data = array(
|
|
|
'day_new_count' => 0,
|
|
|
'day_faulty_count' => 0,
|
|
@@ -141,8 +146,81 @@ class Home extends Base_Controller {
|
|
|
|
|
|
// 设备统计列表
|
|
|
public function dev_list(){
|
|
|
+ $projectIdArr = $this->get_project_id();
|
|
|
+ $role = $this->get_user_info('role');
|
|
|
+ $type = $this->input->post('type',true);
|
|
|
+ $where = array();
|
|
|
+ if ($role != SYSTEM_ADMIN){
|
|
|
+ $company = $this->get_user_info('company');
|
|
|
+ $where[] = 'P.company = '.$company;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($type == 2) {
|
|
|
+ $fields = 'L.manu as company';
|
|
|
+ $group = 'group by L.manu';
|
|
|
+ $where[] = 'L.manu != 0';
|
|
|
+ $where[] = 'L.manu != ""';
|
|
|
+ }elseif ($type == 3) {
|
|
|
+ $fields = 'L.supplier as company';
|
|
|
+ $group = 'group by L.supplier';
|
|
|
+ $where[] = 'L.supplier != 0';
|
|
|
+ $where[] = 'L.supplier != ""';
|
|
|
+ }elseif ($type == 4) {
|
|
|
+ $fields = 'L.po as company';
|
|
|
+ $group = 'group by L.po';
|
|
|
+ $where[] = 'L.po != 0';
|
|
|
+ $where[] = 'L.po != ""';
|
|
|
+ }else{
|
|
|
+ $fields = 'L.upazilla as company';
|
|
|
+ $group = 'group by L.upazilla';
|
|
|
+ $where[] = 'L.upazilla != 0';
|
|
|
+ $where[] = 'L.upazilla != ""';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($projectIdArr)) $where[] = 'L.projectid in ('.implode(',', $projectIdArr).')';
|
|
|
+ $where1 = empty($where) ? '' : 'where '.implode(' AND ', $where);
|
|
|
+ // $total = $this->Lamp_model->get_list_by_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L');
|
|
|
+ $query = 'select t1.total,C.name,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
|
|
|
+ $list = $this->db->query($query)->result_array();
|
|
|
+ if (empty($list)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
|
|
|
+ $temp = array();
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
+ $temp2 = array('name'=>$value['name'],'total'=>$value['total'],'onlineCount'=>0,'offlineCount'=>0,'faultCount'=>0,'powerCount'=>0);
|
|
|
+ $temp[$value['id']] = $temp2;
|
|
|
+ }
|
|
|
+ $companyArr = array_unique(array_column($list, 'id'));
|
|
|
+ if ($type == 2) {
|
|
|
+ $where[] = 'L.manu in ('.implode(',', $companyArr).')';
|
|
|
+ }elseif ($type == 3) {
|
|
|
+ $where[] = 'L.supplier in ('.implode(',', $companyArr).')';
|
|
|
+ }elseif ($type == 4) {
|
|
|
+ $where[] = 'L.po in ('.implode(',', $companyArr).')';
|
|
|
+ }else{
|
|
|
+ $where[] = 'L.upazilla in ('.implode(',', $companyArr).')';
|
|
|
+ }
|
|
|
+
|
|
|
+ $where1 = $where;
|
|
|
+ $where1[] = 'L.netstatus = 0';
|
|
|
+ $where1 = 'where '.implode(' AND ', $where1);
|
|
|
+ $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
|
|
|
+ $list = $this->db->query($query)->result_array();
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
+ if (isset($temp[$value['id']])) $temp[$value['id']]['offlineCount'] = $value['total'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $where1 = $where;
|
|
|
+ $where1[] = 'L.netstatus = 1';
|
|
|
+ $where1 = 'where '.implode(' AND ', $where1);
|
|
|
+ $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
|
|
|
+ $list = $this->db->query($query)->result_array();
|
|
|
+ foreach ($list as $key => $value) {
|
|
|
+ if (isset($temp[$value['id']])) $temp[$value['id']]['onlineCount'] = $value['total'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = array_values($temp);
|
|
|
+ // var_dump($list);
|
|
|
|
|
|
- exit(json_result('0000',$this->response['0000'],array('list'=>array())));
|
|
|
+ exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
|
|
|
}
|
|
|
|
|
|
// 故障信息列表
|