wzh 5 éve
szülő
commit
9c7f01b157

+ 1 - 1
api/.htaccess

@@ -1,4 +1,4 @@
-RewriteEngine off
+RewriteEngine on
 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

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

@@ -1,9 +1,6 @@
 <?php
 defined('BASEPATH') OR exit('No direct script access allowed');
 
-<?php
-defined('BASEPATH') OR exit('No direct script access allowed');
-
 //通用 0000-0099
 $config['response']['0000'] = "操作成功";
 $config['response']['0001'] = "缺少username";
@@ -43,6 +40,8 @@ $config['response']['0210'] = '项目编号长度不能超过20位';
 $config['response']['0211'] = '项目名称长度不能超过40位';
 $config['response']['0212'] = '项目编号为数字或字母';
 $config['response']['0213'] = '命令已经下发,请稍后查看';
+$config['response']['0214'] = '请先删除项目下的设备';
+$config['response']['0215'] = '请先删除项目下的网关';
 //网络 0300-0399
 $config['response']['0300'] = '网络id不能为空';
 $config['response']['0301'] = '网络编号已存在';
@@ -199,6 +198,8 @@ $config['response_en']['0210'] = '项目编号长度不能超过20位';
 $config['response_en']['0211'] = '项目名称长度不能超过40位';
 $config['response_en']['0212'] = '项目编号为数字或字母';
 $config['response_en']['0213'] = '命令已经下发,请稍后查看';
+$config['response_en']['0214'] = '请先删除项目下的设备';
+$config['response_en']['0215'] = '请先删除项目下的网关';
 //网络 0300-0399
 $config['response_en']['0300'] = '网络id不能为空';
 $config['response_en']['0301'] = '网络编号已存在';

+ 14 - 1
api/application/controllers/Lampcontrol.php

@@ -2865,7 +2865,20 @@ class Lampcontrol extends Base_Controller {
         $data["batterytype"] = $this->input->post('batterytype',true);
         $data["boardpower"] = $this->input->post('boardpower',true);
         $data["batteryah"] = $this->input->post('batteryah',true);
-        $data["loadpower"] = $this->input->post('loadpower',true);
+
+
+        $wattage = $this->input->post('wattage',true);
+        $data["wattage"] = !empty($wattage) ? $wattage : 0;
+
+        $supplier = $this->input->post('supplier',true);
+        $data["supplier"] = !empty($supplier) ? $supplier : '';
+        $upazilla = $this->input->post('upazilla',true);
+        $data["upazilla"] = !empty($upazilla) ? $upazilla : '';
+        $po = $this->input->post('po',true);
+        $data["po"] = !empty($po) ? $po : '';
+        $manu = $this->input->post('manu',true);
+        $data["manu"] = !empty($manu) ? $manu : '';
+
         $loadtype = $this->input->post('loadtype',true);
         if ($loadtype !== null) {
             $data["loadtype"] = intval($loadtype);

+ 366 - 302
api/application/controllers/Project.php

@@ -27,109 +27,182 @@ class Project extends Base_Controller {
         $companyid = $this->get_user_info('companyid');
         $role = $this->get_user_info('role');
         $project_id = intval($this->input->post('project_id', true));
+        $type = intval($this->input->post('type', true));
+        $section = $this->input->post('section', true);
+        $company = $this->input->post('company', true);
         $version = $this->session->userdata('version');
+
+        $data = array();
         // 总网络数
-        $network_total = $this->Network_model->getTotal(array('projectid'=>$project_id), $role, $companyid, $userid);
-        // 告警信息列表
-        if (!empty($projectid)) {
-            $alarm_list = $this->Alarm_model->getList(array('projectid'=>$project_id,'status'=>0,'type'=>0),$role,$userid,1,HOME_ALARM_COUNT);
-        }else{
-            $alarm_list = $this->Alarm_model->getList(array('status'=>0,'type'=>0),$role,$userid,1,HOME_ALARM_COUNT);
+        if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
+
+        $data['network_total'] = $this->Network_model->get_count(array('projectid'=>$project_id,'type'=>0));
+        $proData = $this->Project_model->get_one(['id'=>$project_id],'projectname,projectid as number,address as location,createtime as create_time,cityid');
+        $data['number'] = $proData['number'];
+        $data['location'] = $proData['location'];
+        $data['projectname'] = $proData['projectname'];
+        $data['create_time'] = $proData['create_time'];
+        $data['cityid'] = $proData['cityid'];
+
+        $where = array();
+        $where['projectid'] = $project_id;
+        $where2['L.projectid'] = $project_id;
+        if ($section !== '' && $section !== NUll) {
+            $where['section'] = $section;
+            $where2['L.section'] = $section;
         }
-        // 系统日志列表
-        $field = "U.username as username,S.content as content,S.optype as optype,S.time as time";
-
-        // 日志权限控制
-        $filter = array('language'=>0);
-        if ($role == COMPANY_ADMIN) {
-            $filter['companyid'] = $this->get_user_info('companyid');
-        }elseif ($role == COMPANY_CUSTOMER) {
-            $filter['userid'] = $this->get_user_info('id');
+        if ($company !== '' && $company !== NUll) {
+            if ($type == 1) {
+                $where['manu'] = $company;
+                $where2['L.manu'] = $company;
+            }elseif ($type == 2) {
+                $where['supplier'] = $company;
+                $where2['L.supplier'] = $company;
+            }elseif ($type == 3) {
+                $where['po'] = $company;
+                $where2['L.po'] = $company;
+            }else {
+                $where['upazilla'] = $company;
+                $where2['L.upazilla'] = $company;
+            }
         }
-        if (empty($version)) {
-            $syslog_list = $this->Syslog_model->getList($filter,1,HOME_SYSLOG_COUNT,$field);
+
+        $data['total_lamp'] = $this->Lamp_model->get_count($where);
+
+        $where['isfaulted'] = 1;
+        $data['failure_count'] = $this->Lamp_model->get_count($where);
+
+        $where2['N.status'] = 1;
+        $join = [];
+        $join[] = ['table'=>'network as N','cond'=>'N.id = L.networkid','type'=>'left'];
+        $res = $this->Lamp_model->get_list_by_multi_join($where2, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
+        $data['online_count'] = $res['total'];
+
+        $where2['L.status'] = 1;
+        $res = $this->Lamp_model->get_list_by_multi_join($where2, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
+        $data['lighting_count'] = $res['total'];
+        $data['timezone'] = ''; 
+
+        if (empty($data['cityid'])) {
+            $data['countryId'] = 0;
+            $data['provinceId'] = 0;
+            $data['cityId'] = 0;
+            $data['areaId'] = 0;
+            $data['weatherList'] = [];
+            $data['longitude'] = '0';
+            $data['latitude'] = '0';
+            $location_ch = '暂无位置信息,请在编辑项目页面选择位置信息';
+            $location_en = 'There is no location information, please select location information on the edit project page.';
         }else{
-            $filter['language'] = 1;
-            // 英文版
-            foreach ($alarm_list as $k=>$value) {
-                $stralarmtype = trim($value['stralarmtype']);
-                if (!empty($stralarmtype)) {
-                    $alarmArr = explode(',', $stralarmtype);
-                    $temp = array();
-                    foreach ($alarmArr as $a) {
-                        $temp[] = alarm_translate($a);
+            $res1 = $this->Global_location_model->getOne($data['cityid'],'level,pid,chinese_name,longitude,latitude,english_name');
+            $data['longitude'] = $res1['longitude'];
+            $data['latitude'] = $res1['latitude'];
+            $res2 = $this->Global_location_model->getOne($res1['pid'],'pid,chinese_name,english_name');
+            if ($res1['level'] == 4) {
+                $data['areaId'] = $data['cityid'];
+                $data['cityId'] = $res1['pid'];
+                $data['provinceId'] = $res2['pid'];
+                $res3 = $this->Global_location_model->getOne($res2['pid'],'pid,chinese_name,english_name');
+                $data['countryId'] = $res3['pid'];
+                $location_ch = $res3['chinese_name'].','.$res2['chinese_name'].','.$res1['chinese_name'];
+                $location_en = $res1['english_name'].','.$res2['english_name'].','.$res3['english_name'];
+            }elseif ($res1['level'] == 3) {
+                $data['areaId'] = 0;
+                $data['cityId'] = $data['cityid'];
+                $data['provinceId'] = $res1['pid'];
+                $data['countryId'] = $res2['pid'];
+                $location_ch = $res2['chinese_name'].','.$res1['chinese_name'];
+                $location_en = $res1['english_name'].','.$res2['english_name'];
+            }elseif ($res1['level'] == 2) {
+                $data['areaId'] = 0;
+                $data['cityId'] = 0;
+                $data['provinceId'] = $data['cityid'];
+                $data['countryId'] = $res1['pid'];
+                $location_ch = $res1['chinese_name'];
+                $location_en = $res1['english_name'];
+            }else{
+                $data['areaId'] = 0;
+                $data['cityId'] = 0;
+                $data['provinceId'] = 0;
+                $data['countryId'] = $data['cityid'];
+                $location_ch = $res1['chinese_name'];
+                $location_en = $res1['english_name'];
+            }
+            $project_weather = $this->db->query('select * from project_weather where projectId = '.$project_id)->row_array();
+            if (empty($project_weather) || time() - strtotime($project_weather['updatetime']) > 3600) {
+                $url = 'https://way.jd.com/he/freeweather?city='.$res1['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+                $resData = request_post($url);
+                $arr = json_decode($resData,true);
+                if ($arr['code'] == 10000) {
+                    if ($arr['result']['HeWeather5'][0]['status'] == 'unknown location') {
+                        $url = 'https://free-api.heweather.net/s6/weather/forecast?location='.$res1['longitude'].','.$res1['latitude'].'&key=63dbc994630941fab269ad3c3af4d5d2';
+                        // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+                        $resData = request_post($url);
+                        $arr = json_decode($resData,true);
+                        // var_dump($url);
+                        if ($arr['HeWeather6'][0]['status'] == 'ok') {
+                            $now = $arr['HeWeather6'][0]['daily_forecast'][0];
+                            $daily_forecast = $arr['HeWeather6'][0]['daily_forecast'];
+                            $weatherList = array();
+                            $weatherList[] = ['weatherType'=>$now['cond_txt_d'],'code'=>$now['cond_code_d'],'tmp'=>intval(($now['tmp_min'] + $now['tmp_max'])/2),'sr'=>$now['sr'],'ss'=>$now['ss'],'dateStr'=>date('D',strtotime($now['date'])),'date'=>date('m-d',strtotime($now['date']))];
+                            for ($i=1; $i < count($daily_forecast); $i++) { 
+                                $weatherList[] = ['weatherType'=>$daily_forecast[$i]['cond_txt_d'],'code'=>$daily_forecast[$i]['cond_code_d'],'maxTmp'=>$daily_forecast[$i]['tmp_max'],'minTmp'=>$daily_forecast[$i]['tmp_min'],'sr'=>$daily_forecast[$i]['sr'],'ss'=>$daily_forecast[$i]['ss'],'dateStr'=>date('D',strtotime($daily_forecast[$i]['date'])),'date'=>date('m-d',strtotime($daily_forecast[$i]['date']))];
+                            }
+                            $data['weatherList'] = $weatherList;
+                            if (empty($project_weather)) {
+                                $sql = "insert into project_weather (weatherInfo,projectId,updatetime) values('".json_encode($weatherList)."',".$project_id.",'".date('Y-m-d H:i:s',time())."')";
+                                $this->db->query($sql);
+                            }else{
+                                $sql = "update project_weather set weatherInfo = '".json_encode($weatherList)."',updatetime = '".date('Y-m-d H:i:s',time())."' where projectId = ".$project_id;
+                                $this->db->query($sql);
+                            }
+                        }else{
+                            $data['weatherList'] = [];
+                        }
+                        // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+                        // $resData = request_post($url);
+                        // $arr = json_decode($resData,true);
+                    }else{
+                        if ($arr['result']['HeWeather5'][0]['status'] == 'ok') {
+                            $now = $arr['result']['HeWeather5'][0]['now'];
+                            $daily_forecast = $arr['result']['HeWeather5'][0]['daily_forecast'];
+                            $weatherList = array();
+                            $weatherList[] = ['weatherType'=>$now['cond']['txt'],'code'=>$now['cond']['code'],'tmp'=>$now['tmp'],'sr'=>$daily_forecast[0]['astro']['sr'],'ss'=>$daily_forecast[0]['astro']['ss'],'dateStr'=>date('D',strtotime($daily_forecast[0]['date'])),'date'=>date('m-d',strtotime($daily_forecast[0]['date']))];
+                            for ($i=1; $i < count($daily_forecast); $i++) { 
+                                $weatherList[] = ['weatherType'=>$daily_forecast[$i]['cond']['txt_d'],'code'=>$daily_forecast[$i]['cond']['code_d'],'maxTmp'=>$daily_forecast[$i]['tmp']['max'],'minTmp'=>$daily_forecast[$i]['tmp']['min'],'sr'=>$daily_forecast[$i]['astro']['sr'],'ss'=>$daily_forecast[$i]['astro']['ss'],'dateStr'=>date('D',strtotime($daily_forecast[$i]['date'])),'date'=>date('m-d',strtotime($daily_forecast[$i]['date']))];
+                            }
+                            $data['weatherList'] = $weatherList;
+                            if (empty($project_weather)) {
+                                $sql = "insert into project_weather (weatherInfo,projectId,updatetime) values('".json_encode($weatherList)."',".$project_id.",'".date('Y-m-d H:i:s',time())."')";
+                                $this->db->query($sql);
+                            }else{
+                                $sql = "update project_weather set weatherInfo = '".json_encode($weatherList)."',updatetime = '".date('Y-m-d H:i:s',time())."' where projectId = ".$project_id;
+                                $this->db->query($sql);
+                            }
+                        }else{
+                            $data['weatherList'] = [];
+                        }
                     }
-                    $alarm_list[$k]['stralarmtype'] = implode('.', $temp);
+                }else{
+                    $data['weatherList'] = [];
                 }
+            }else{
+                $data['weatherList'] = json_decode($project_weather['weatherInfo'],true);
+                // var_dump($data['weatherList']);die;
             }
-            $syslog_list = $this->Syslog_model->getList($filter,1,HOME_SYSLOG_COUNT,$field);
         }
-        // 获取视屏监控列表
-        $video_list = $this->Videomonitor_model->getList($role, $companyid, $project_id, $userid,1,HOME_VIDEO_COUNT);
-        foreach ($video_list as &$v) {
-            if (!empty($v['image'])) {
-                $v['image'] = base_url($v['image']);
+
+        if (empty($version)) {
+            foreach ($data['weatherList'] as $key => $value) {
+                $data['weatherList'][$key]['weatherType'] = weather_translate_cn($data['weatherList'][$key]['code']);
+                $data['weatherList'][$key]['dateStr'] = date_translate_cn($data['weatherList'][$key]['dateStr']);
             }
-        }
-        $projectList = $this->Project_model->get_list(array('company'=>2305),'id');
-        $proArr = array();
-        foreach ($projectList as $p) {
-            $proArr[] = $p['id'];
-        }
-        $this->load->model('User_model');
-        $userList = $this->User_model->get_list(array('companyid'=>2305),'id');
-        $userArr = array();
-        foreach ($userList as $u) {
-            $userArr[] = $u['id'];
-        }
-        // 获取环境监控列表
-        $weather_list = $this->Weathermonitor_model->get_list_by_role($role,$userid, $companyid, $project_id,'*',1,HOME_WEATHER_COUNT);
-        $arr = $this->Lamp_model->getTotalLampInfo($role, $companyid, $project_id, $userid);
-        if (!empty($arr['num'])) {
-            $online_arr = $this->Lamp_model->getOnlineCount($role, $companyid, $project_id, $userid, 1);
-            $lighting_arr = $this->Lamp_model->getCountByFilter($role, $companyid, $project_id, $userid, array('L.status'=>1));
-            $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, $companyid, $userid);
-
-            // 监控数
-            // $video_count = $this->Videomonitor_model->getTotal(array(),$role,$userid,$companyid,$project_id);
-            // $weather_count = $this->Weathermonitor_model->getTotal(array(),$role,$userid,$companyid,$project_id);
-            
-            if (in_array($userid, $userArr) || in_array($project_id, $proArr)) {
-                $data['online_rate'] = round($arr['online'], 2);
-                $data['lighting_rate'] = round($arr['light'], 2);
-            }else{
-                $data['online_rate'] = round($online_arr['num']/$arr['num']*100, 2);
-                $data['lighting_rate'] = round($lighting_arr['num']/$arr['num']*100, 2);
+        }else{
+            foreach ($data['weatherList'] as $key => $value) {
+                $data['weatherList'][$key]['weatherType'] = weather_translate_en($data['weatherList'][$key]['code']);
             }
-
-            $data['failure_rate'] = round($failure/$arr['num']*100, 2);
-            $data['failure_count'] = $failure;
-            $data['total_power'] = round($arr['power'], 3);
-            $data['total_install'] = round($arr['install']/1000, 3);
-            $data['total_lamp'] = intval($arr['num']);
-            $data['total_network'] = intval($network_total);
-            $data['co2_emission'] = round($arr['power']*0.977, 3);
-            $data['so2_emission'] = round($arr['power']*0.977/2620*8.5, 3);
-            $data['coal_saving'] = round($arr['power']*0.977/2620, 3);
-        } else {
-            $data['online_rate'] = 0;
-            $data['failure_rate'] = 0;
-            $data['lighting_rate'] = 0;
-            $data['failure_count'] = 0;
-            $data['total_power'] = 0;
-            $data['total_install'] = 0;
-            $data['total_lamp'] = 0;
-            $data['total_network'] = intval($network_total);
-            $data['co2_emission'] = 0;
-            $data['so2_emission'] = 0;
-            $data['coal_saving'] = 0;
         }
 
-        $data['syslog_list'] = $syslog_list;
-        $data['alarm_list'] = $alarm_list;
-        $data['video_list'] = $video_list;
-        $data['weather_list'] = $weather_list;
-
         exit(json_result('0000', $this->response['0000'], $data));
     }
 
@@ -310,14 +383,88 @@ class Project extends Base_Controller {
     // 项目管理侧边导航栏
     public function nav(){
         $userid = $this->get_user_info('id');
-        $companyid = $this->get_user_info('companyid');
+        $company = $this->get_user_info('company');
         $role = $this->get_user_info('role');
         $keyword = $this->input->post('keyword');
         $searchType = $this->input->post('searchType');
+        $type = $this->input->post('type',true);
+
+        $where = array();
+
+        if (empty($type)) {
+            if ($role != SYSTEM_ADMIN) $where['company'] = $company;
+
+            $data = $this->Project_model->get_list($where, 'projectname,id',NULL, NULL, 'convert(projectname using gbk) asc', NUll);
+            if (!empty($data)) {
+                $temp = array();
+                foreach ($data as $key => $value) {
+                    $value['sectionList'] = array();
+                    $temp[$value['id']] = $value;
+                }
+                $projectIdArr = array_column($data, 'id');
+                $sectionList = $this->Lamp_model->get_list(['projectid'=>$projectIdArr], 'section as name,projectid',NULL, NULL, 'convert(section using gbk) asc', 'projectid,section');
+                foreach ($sectionList as $key => $value) {
+                    if (isset($temp[$value['projectid']])) {
+                        unset($value['projectid']);
+                        $temp[$value['projectid']]['sectionList'][] = $value;
+                    }
+                }
+                $data = array_values($temp);
+            }
 
-        $data = $this->User_model->get_nav($role,$userid,$companyid,$keyword,$searchType);
+            exit(json_result('0000',$this->response['0000'],$data));
+        }else{
+            if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
+
+            $join = [];
+            $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'inner'];
+            if ($type == 1) {
+                $group = 'L.manu,L.projectid';
+                $order = 'convert(L.manu using gbk) asc';
+                $fields = 'L.manu as company,P.projectname,P.id';
+            }elseif ($type == 2) {
+                $group = 'L.supplier,L.projectid';
+                $order = 'convert(L.supplier using gbk) asc';
+                $fields = 'L.supplier as company,P.projectname,P.id';
+            }elseif ($type == 3) {
+                $group = 'L.po,L.projectid';
+                $order = 'convert(L.po using gbk) asc';
+                $fields = 'L.po as company,P.projectname,P.id';
+            }else {
+                $group = 'L.upazilla,L.projectid';
+                $order = 'convert(L.upazilla using gbk) asc';
+                $fields = 'L.upazilla as company,P.projectname,P.id';
+            }
+
+            $data = $this->Lamp_model->get_list_by_join($where, $fields='*',NULL, NULL, $join, $order, $group, 'L');
 
-        json_result('0000',$this->response['0000'],$data);
+            if (!empty($data)) {
+                $temp = array();
+                $temp2 = array();
+                foreach ($data as $key => $value) {
+                    $value['sectionList'] = array();
+                    $temp[$value['id']] = $value;
+                    $temp2[$value['company']] = array('company'=>$value['company'],'projectList'=>array());
+                }
+                $projectIdArr = array_column($data, 'id');
+                $sectionList = $this->Lamp_model->get_list(['projectid'=>$projectIdArr], 'section as name,projectid',NULL, NULL, 'convert(section using gbk) asc', 'projectid,section');
+                foreach ($sectionList as $key => $value) {
+                    if (isset($temp[$value['projectid']])) {
+                        unset($value['projectid']);
+                        $temp[$value['projectid']]['sectionList'][] = $value;
+                    }
+                }
+                $temp = array_values($temp);
+                foreach ($temp as $key => $value) {
+                    if (isset($temp2[$value['company']])) {
+                        unset($value['company']);
+                        $temp[$value['company']]['projectList'][] = $value;
+                    }
+                }
+                $data = array_values($temp2);
+            }
+            exit(json_result('0000',$this->response['0000'],$data));
+        }
     }
 
     // 获取项目下拉列表
@@ -373,127 +520,128 @@ class Project extends Base_Controller {
                    guestname as customer,
                    company as company_id,
                    province as province_id,
+                   zone as zone_id,
                    address,
                    createtime as create_time,
                    timezone,
                    patrolinterval,
                    cityid,
                    lampcount as install_num';
-        $data = $this->Project_model->get_one(array('id' => $project_id), $fields);
+        $data = $this->Project_model->getData(array('id' => $project_id), $fields);
         $version = $this->session->userdata('version');
 
         if(!$data){
             exit(json_result('0202', $this->response['0202'], $data));
         } else {
-            // if (empty($data['cityid'])) {
-            //     $data['countryId'] = 0;
-            //     $data['provinceId'] = 0;
-            //     $data['cityId'] = 0;
-            //     $data['areaId'] = 0;
-            //     $data['weatherList'] = [];
-            //     $data['longitude'] = '0';
-            //     $data['latitude'] = '0';
-            //     $location_ch = '暂无位置信息,请在编辑项目页面选择位置信息';
-            //     $location_en = 'There is no location information, please select location information on the edit project page.';
-            // }else{
-            //     $res1 = $this->Global_location_model->getOne($data['cityid'],'level,pid,chinese_name,longitude,latitude,english_name');
-            //     $data['longitude'] = $res1['longitude'];
-            //     $data['latitude'] = $res1['latitude'];
-            //     $res2 = $this->Global_location_model->getOne($res1['pid'],'pid,chinese_name,english_name');
-            //     if ($res1['level'] == 4) {
-            //         $data['areaId'] = $data['cityid'];
-            //         $data['cityId'] = $res1['pid'];
-            //         $data['provinceId'] = $res2['pid'];
-            //         $res3 = $this->Global_location_model->getOne($res2['pid'],'pid,chinese_name,english_name');
-            //         $data['countryId'] = $res3['pid'];
-            //         $location_ch = $res3['chinese_name'].','.$res2['chinese_name'].','.$res1['chinese_name'];
-            //         $location_en = $res1['english_name'].','.$res2['english_name'].','.$res3['english_name'];
-            //     }elseif ($res1['level'] == 3) {
-            //         $data['areaId'] = 0;
-            //         $data['cityId'] = $data['cityid'];
-            //         $data['provinceId'] = $res1['pid'];
-            //         $data['countryId'] = $res2['pid'];
-            //         $location_ch = $res2['chinese_name'].','.$res1['chinese_name'];
-            //         $location_en = $res1['english_name'].','.$res2['english_name'];
-            //     }elseif ($res1['level'] == 2) {
-            //         $data['areaId'] = 0;
-            //         $data['cityId'] = 0;
-            //         $data['provinceId'] = $data['cityid'];
-            //         $data['countryId'] = $res1['pid'];
-            //         $location_ch = $res1['chinese_name'];
-            //         $location_en = $res1['english_name'];
-            //     }else{
-            //         $data['areaId'] = 0;
-            //         $data['cityId'] = 0;
-            //         $data['provinceId'] = 0;
-            //         $data['countryId'] = $data['cityid'];
-            //         $location_ch = $res1['chinese_name'];
-            //         $location_en = $res1['english_name'];
-            //     }
-            //     $project_weather = $this->db->query('select * from project_weather where projectId = '.$project_id)->row_array();
-            //     if (empty($project_weather) || time() - strtotime($project_weather['updatetime']) > 3600) {
-            //         $url = 'https://way.jd.com/he/freeweather?city='.$res1['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
-            //         $resData = request_post($url);
-            //         $arr = json_decode($resData,true);
-            //         if ($arr['code'] == 10000) {
-            //             if ($arr['result']['HeWeather5'][0]['status'] == 'unknown location') {
-            //                 $url = 'https://free-api.heweather.net/s6/weather/forecast?location='.$res1['longitude'].','.$res1['latitude'].'&key=63dbc994630941fab269ad3c3af4d5d2';
-            //                 // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
-            //                 $resData = request_post($url);
-            //                 $arr = json_decode($resData,true);
-            //                 // var_dump($url);
-            //                 if ($arr['HeWeather6'][0]['status'] == 'ok') {
-            //                     $now = $arr['HeWeather6'][0]['daily_forecast'][0];
-            //                     $daily_forecast = $arr['HeWeather6'][0]['daily_forecast'];
-            //                     $weatherList = array();
-            //                     $weatherList[] = ['weatherType'=>$now['cond_txt_d'],'code'=>$now['cond_code_d'],'tmp'=>intval(($now['tmp_min'] + $now['tmp_max'])/2),'sr'=>$now['sr'],'ss'=>$now['ss'],'dateStr'=>date('D',strtotime($now['date'])),'date'=>date('m-d',strtotime($now['date']))];
-            //                     for ($i=1; $i < count($daily_forecast); $i++) { 
-            //                         $weatherList[] = ['weatherType'=>$daily_forecast[$i]['cond_txt_d'],'code'=>$daily_forecast[$i]['cond_code_d'],'maxTmp'=>$daily_forecast[$i]['tmp_max'],'minTmp'=>$daily_forecast[$i]['tmp_min'],'sr'=>$daily_forecast[$i]['sr'],'ss'=>$daily_forecast[$i]['ss'],'dateStr'=>date('D',strtotime($daily_forecast[$i]['date'])),'date'=>date('m-d',strtotime($daily_forecast[$i]['date']))];
-            //                     }
-            //                     $data['weatherList'] = $weatherList;
-            //                     if (empty($project_weather)) {
-            //                         $sql = "insert into project_weather (weatherInfo,projectId,updatetime) values('".json_encode($weatherList)."',".$project_id.",'".date('Y-m-d H:i:s',time())."')";
-            //                         $this->db->query($sql);
-            //                     }else{
-            //                         $sql = "update project_weather set weatherInfo = '".json_encode($weatherList)."',updatetime = '".date('Y-m-d H:i:s',time())."' where projectId = ".$project_id;
-            //                         $this->db->query($sql);
-            //                     }
-            //                 }else{
-            //                     $data['weatherList'] = [];
-            //                 }
-            //                 // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
-            //                 // $resData = request_post($url);
-            //                 // $arr = json_decode($resData,true);
-            //             }else{
-            //                 if ($arr['result']['HeWeather5'][0]['status'] == 'ok') {
-            //                     $now = $arr['result']['HeWeather5'][0]['now'];
-            //                     $daily_forecast = $arr['result']['HeWeather5'][0]['daily_forecast'];
-            //                     $weatherList = array();
-            //                     $weatherList[] = ['weatherType'=>$now['cond']['txt'],'code'=>$now['cond']['code'],'tmp'=>$now['tmp'],'sr'=>$daily_forecast[0]['astro']['sr'],'ss'=>$daily_forecast[0]['astro']['ss'],'dateStr'=>date('D',strtotime($daily_forecast[0]['date'])),'date'=>date('m-d',strtotime($daily_forecast[0]['date']))];
-            //                     for ($i=1; $i < count($daily_forecast); $i++) { 
-            //                         $weatherList[] = ['weatherType'=>$daily_forecast[$i]['cond']['txt_d'],'code'=>$daily_forecast[$i]['cond']['code_d'],'maxTmp'=>$daily_forecast[$i]['tmp']['max'],'minTmp'=>$daily_forecast[$i]['tmp']['min'],'sr'=>$daily_forecast[$i]['astro']['sr'],'ss'=>$daily_forecast[$i]['astro']['ss'],'dateStr'=>date('D',strtotime($daily_forecast[$i]['date'])),'date'=>date('m-d',strtotime($daily_forecast[$i]['date']))];
-            //                     }
-            //                     $data['weatherList'] = $weatherList;
-            //                     if (empty($project_weather)) {
-            //                         $sql = "insert into project_weather (weatherInfo,projectId,updatetime) values('".json_encode($weatherList)."',".$project_id.",'".date('Y-m-d H:i:s',time())."')";
-            //                         $this->db->query($sql);
-            //                     }else{
-            //                         $sql = "update project_weather set weatherInfo = '".json_encode($weatherList)."',updatetime = '".date('Y-m-d H:i:s',time())."' where projectId = ".$project_id;
-            //                         $this->db->query($sql);
-            //                     }
-            //                 }else{
-            //                     $data['weatherList'] = [];
-            //                 }
-            //             }
-            //         }else{
-            //             $data['weatherList'] = [];
-            //         }
-            //     }else{
-            //         $data['weatherList'] = json_decode($project_weather['weatherInfo'],true);
-            //         // var_dump($data['weatherList']);die;
-            //     }
-            // }
-            
+            if (empty($data['cityid'])) {
+                $data['countryId'] = 0;
+                $data['provinceId'] = 0;
+                $data['cityId'] = 0;
+                $data['areaId'] = 0;
+                $data['weatherList'] = [];
+                $data['longitude'] = '0';
+                $data['latitude'] = '0';
+                $location_ch = '暂无位置信息,请在编辑项目页面选择位置信息';
+                $location_en = 'There is no location information, please select location information on the edit project page.';
+            }else{
+                $res1 = $this->Global_location_model->getOne($data['cityid'],'level,pid,chinese_name,longitude,latitude,english_name');
+                $data['longitude'] = $res1['longitude'];
+                $data['latitude'] = $res1['latitude'];
+                $res2 = $this->Global_location_model->getOne($res1['pid'],'pid,chinese_name,english_name');
+                if ($res1['level'] == 4) {
+                    $data['areaId'] = $data['cityid'];
+                    $data['cityId'] = $res1['pid'];
+                    $data['provinceId'] = $res2['pid'];
+                    $res3 = $this->Global_location_model->getOne($res2['pid'],'pid,chinese_name,english_name');
+                    $data['countryId'] = $res3['pid'];
+                    $location_ch = $res3['chinese_name'].','.$res2['chinese_name'].','.$res1['chinese_name'];
+                    $location_en = $res1['english_name'].','.$res2['english_name'].','.$res3['english_name'];
+                }elseif ($res1['level'] == 3) {
+                    $data['areaId'] = 0;
+                    $data['cityId'] = $data['cityid'];
+                    $data['provinceId'] = $res1['pid'];
+                    $data['countryId'] = $res2['pid'];
+                    $location_ch = $res2['chinese_name'].','.$res1['chinese_name'];
+                    $location_en = $res1['english_name'].','.$res2['english_name'];
+                }elseif ($res1['level'] == 2) {
+                    $data['areaId'] = 0;
+                    $data['cityId'] = 0;
+                    $data['provinceId'] = $data['cityid'];
+                    $data['countryId'] = $res1['pid'];
+                    $location_ch = $res1['chinese_name'];
+                    $location_en = $res1['english_name'];
+                }else{
+                    $data['areaId'] = 0;
+                    $data['cityId'] = 0;
+                    $data['provinceId'] = 0;
+                    $data['countryId'] = $data['cityid'];
+                    $location_ch = $res1['chinese_name'];
+                    $location_en = $res1['english_name'];
+                }
+                $project_weather = $this->db->query('select * from project_weather where projectId = '.$project_id)->row_array();
+                if (empty($project_weather) || time() - strtotime($project_weather['updatetime']) > 3600) {
+                    $url = 'https://way.jd.com/he/freeweather?city='.$res1['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+                    $resData = request_post($url);
+                    $arr = json_decode($resData,true);
+                    if ($arr['code'] == 10000) {
+                        if ($arr['result']['HeWeather5'][0]['status'] == 'unknown location') {
+                            $url = 'https://free-api.heweather.net/s6/weather/forecast?location='.$res1['longitude'].','.$res1['latitude'].'&key=63dbc994630941fab269ad3c3af4d5d2';
+                            // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+                            $resData = request_post($url);
+                            $arr = json_decode($resData,true);
+                            // var_dump($url);
+                            if ($arr['HeWeather6'][0]['status'] == 'ok') {
+                                $now = $arr['HeWeather6'][0]['daily_forecast'][0];
+                                $daily_forecast = $arr['HeWeather6'][0]['daily_forecast'];
+                                $weatherList = array();
+                                $weatherList[] = ['weatherType'=>$now['cond_txt_d'],'code'=>$now['cond_code_d'],'tmp'=>intval(($now['tmp_min'] + $now['tmp_max'])/2),'sr'=>$now['sr'],'ss'=>$now['ss'],'dateStr'=>date('D',strtotime($now['date'])),'date'=>date('m-d',strtotime($now['date']))];
+                                for ($i=1; $i < count($daily_forecast); $i++) { 
+                                    $weatherList[] = ['weatherType'=>$daily_forecast[$i]['cond_txt_d'],'code'=>$daily_forecast[$i]['cond_code_d'],'maxTmp'=>$daily_forecast[$i]['tmp_max'],'minTmp'=>$daily_forecast[$i]['tmp_min'],'sr'=>$daily_forecast[$i]['sr'],'ss'=>$daily_forecast[$i]['ss'],'dateStr'=>date('D',strtotime($daily_forecast[$i]['date'])),'date'=>date('m-d',strtotime($daily_forecast[$i]['date']))];
+                                }
+                                $data['weatherList'] = $weatherList;
+                                if (empty($project_weather)) {
+                                    $sql = "insert into project_weather (weatherInfo,projectId,updatetime) values('".json_encode($weatherList)."',".$project_id.",'".date('Y-m-d H:i:s',time())."')";
+                                    $this->db->query($sql);
+                                }else{
+                                    $sql = "update project_weather set weatherInfo = '".json_encode($weatherList)."',updatetime = '".date('Y-m-d H:i:s',time())."' where projectId = ".$project_id;
+                                    $this->db->query($sql);
+                                }
+                            }else{
+                                $data['weatherList'] = [];
+                            }
+                            // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+                            // $resData = request_post($url);
+                            // $arr = json_decode($resData,true);
+                        }else{
+                            if ($arr['result']['HeWeather5'][0]['status'] == 'ok') {
+                                $now = $arr['result']['HeWeather5'][0]['now'];
+                                $daily_forecast = $arr['result']['HeWeather5'][0]['daily_forecast'];
+                                $weatherList = array();
+                                $weatherList[] = ['weatherType'=>$now['cond']['txt'],'code'=>$now['cond']['code'],'tmp'=>$now['tmp'],'sr'=>$daily_forecast[0]['astro']['sr'],'ss'=>$daily_forecast[0]['astro']['ss'],'dateStr'=>date('D',strtotime($daily_forecast[0]['date'])),'date'=>date('m-d',strtotime($daily_forecast[0]['date']))];
+                                for ($i=1; $i < count($daily_forecast); $i++) { 
+                                    $weatherList[] = ['weatherType'=>$daily_forecast[$i]['cond']['txt_d'],'code'=>$daily_forecast[$i]['cond']['code_d'],'maxTmp'=>$daily_forecast[$i]['tmp']['max'],'minTmp'=>$daily_forecast[$i]['tmp']['min'],'sr'=>$daily_forecast[$i]['astro']['sr'],'ss'=>$daily_forecast[$i]['astro']['ss'],'dateStr'=>date('D',strtotime($daily_forecast[$i]['date'])),'date'=>date('m-d',strtotime($daily_forecast[$i]['date']))];
+                                }
+                                $data['weatherList'] = $weatherList;
+                                if (empty($project_weather)) {
+                                    $sql = "insert into project_weather (weatherInfo,projectId,updatetime) values('".json_encode($weatherList)."',".$project_id.",'".date('Y-m-d H:i:s',time())."')";
+                                    $this->db->query($sql);
+                                }else{
+                                    $sql = "update project_weather set weatherInfo = '".json_encode($weatherList)."',updatetime = '".date('Y-m-d H:i:s',time())."' where projectId = ".$project_id;
+                                    $this->db->query($sql);
+                                }
+                            }else{
+                                $data['weatherList'] = [];
+                            }
+                        }
+                    }else{
+                        $data['weatherList'] = [];
+                    }
+                }else{
+                    $data['weatherList'] = json_decode($project_weather['weatherInfo'],true);
+                    // var_dump($data['weatherList']);die;
+                }
+            }
+            $data['company'] = $this->Company_model->get_data_by_id($data['company_id'], 'name');
 
             if (empty($version)) {
                 $data['location'] = $location_ch;
@@ -510,10 +658,6 @@ class Project extends Base_Controller {
                 $res = $this->Project_model->get_timezone_info(array('id'=>$data['timezone']),'enname as name');
             }
             $data['timezone_name'] = $res['name'];
-            // 监控数
-            // $video_count = $this->Videomonitor_model->getTotal(array(),$role,$userid,$companyid,$project_id);
-            // $weather_count = $this->Weathermonitor_model->getTotal(array(),$role,$userid,$companyid,$project_id);
-            // $data['monitor_count'] = $video_count + $weather_count;
 
             $data['patrol_time'] = strval($this->getLeftTimeByProject($project_id));
 
@@ -539,100 +683,39 @@ class Project extends Base_Controller {
         $where['id']         = $this->input->post('project_id',true);
         $data['projectname'] = trim($this->input->post('project_name',true));
         
-        // $data['province']    = $this->input->post('province_id',true);
-        // $data['zone']    = $this->input->post('zone_id',true);
         $data['cityid']    = $this->input->post('pid',true);
         $address     = $this->input->post('address',true);
-        $data['company'] = $this->input->post('company',true);
-        $data['timezone'] = $this->input->post('timezone',true);
         $patrolinterval = $this->input->post('patrolinterval',true);
 
         if(isset($address)) $data['address'] = $address;
         if(isset($patrolinterval)) $data['patrolinterval'] = $patrolinterval;
         if(empty($data['projectname'])) exit(json_result('0204',$this->response['0204'],array()));
-        // if(mb_strlen($data['projectname']) > 20) exit(json_result('0211',$this->response['0211'],array()));
         
-        // if(empty($data['zone'])) exit(json_result('0206',$this->response['0206'],array()));
-        // if(empty($data['province'])) exit(json_result('0207',$this->response['0207'],array()));
-        if(empty($data['timezone'])) exit(json_result('0208',$this->response['0208'],array()));
-        // if(empty($data['company'])) exit(json_result('0209',$this->response['0209'],array()));
-
         if (empty($where['id'])) {  // 添加项目
             $data['projectid']   = $this->input->post('project_no',true);
             if(empty($data['projectid'])) exit(json_result('0205',$this->response['0205'],array()));
             if(mb_strlen($data['projectid']) > 20) exit(json_result('0210',$this->response['0210'],array()));
             if(!preg_match('/^[A-Za-z0-9]+$/', $data['projectid'])) exit(json_result('0212',$this->response['0212'],array()));
-
-            // if ($this->Project_model->getDataCount(array('projectid'=>$data['projectid'], 'company'=>$data['company'])) > 0) {
-            //     exit(json_result('0201', $this->response['0201'], array()));
-            // }
-            // if ($this->Project_model->getDataCount(array('projectname'=>$data['projectname'], 'company'=>$data['company'])) > 0) {
-            //     exit(json_result('0203', $this->response['0203'], array()));
-            // }
-
-            // 记录区域
-            // $data['id']   = $this->Zone_model->insert(array(
-            //     'name' => $data['projectname'],
-            //     'parent' => '' ,
-            //     'level' => 3
-            // ));
+            $data['userId'] = $this->get_user_info('id');
+            $data['company'] = $this->get_user_info('company');
             
-            if (!empty($data['timezone'])) {
-                $timezone = $this->Project_model->get_timezone_info(array('id'=>$data['timezone']),'value');
+            $data['createtime']  = date('Y-m-d H:i:s',time() - 8*3600);
 
-                // 获取当前时区对应的时间
-                $data['createtime']  = get_time_by_timezone($timezone['value']);
-            }else{
-                $data['createtime']  = date('Y-m-d H:i:s');
-            }
-            $projectId = $this->Project_model->insert($data);
-            if ($role != SYSTEM_ADMIN) {
-                $zone = $this->get_user_info('zone');
-                $userid = $this->get_user_info('id');
-                if (empty($zone)) {
-                    $this->User_model->update(array('id'=>$userid),array('zone'=>$projectId));
-                }else{
-                    $arr = explode(',', $zone);
-                    $arr[] = $projectId;
-                    $zoneStr = implode(',', $arr);
-                    $this->User_model->update(array('id'=>$userid),array('zone'=>$zoneStr));
-                }
-                if ($role == COMPANY_CUSTOMER) {
-                    $pid = $this->get_user_info('parentid');
-                    $pres = $this->User_model->getOne($pid,'zone');
-                    $pzone = $pres['zone'];
-                    $userid = $this->get_user_info('id');
-                    if (empty($pzone)) {
-                        $this->User_model->update(array('id'=>$pid),array('zone'=>$projectId));
-                    }else{
-                        $parr = explode(',', $pzone);
-                        $parr[] = $projectId;
-                        $pzoneStr = implode(',', $parr);
-                        $this->User_model->update(array('id'=>$pid),array('zone'=>$pzoneStr));
-                    }
-                }
-            }
+            $projectId = $this->Project_model->add($data);
             
             // $projectId = $data['id'];
             $this->add_operation_log('insert',"添加\"{$data['projectname']}\"项目,项目编号\"{$data['projectid']}\"",0);
             $this->add_operation_log('insert',"Add project.Project name:\"{$data['projectname']}\".Project number:\"{$data['projectid']}\"",0,1);
         } else {  // 编辑项目
-            // if ($this->Project_model->getDataCount(array('projectid'=>$data['projectid'], 'company'=>$data['company']), $where['id']) > 0) {
-            //     exit(json_result('0201', $this->response['0201'], array()));
-            // }
             if ($this->Project_model->getDataCount(array('projectname'=>$data['projectname'], 'company'=>$data['company']), $where['id']) > 0) {
                 exit(json_result('0203', $this->response['0203'], array()));
             }
-            $ret = $this->Project_model->getData($where);
+            $ret = $this->Project_model->get_one($where);
             if ($ret['cityid'] != $data['cityid']) {
                 $sql = "delete from project_weather where projectId = ".$where['id'];
                 $this->db->query($sql);
             }
-            if ($ret['timezone'] != $data['timezone']) {
-                $data['createtime'] = date_change($ret['createtime'],$ret['timezone'],$data['timezone']);
-            }
-            // $this->Zone_model->update($where, array('name'=>$data['projectname'], 'parent'=>$data['province']));
-            $this->Project_model->update($where,$data);
+            $this->Project_model->update($data,$where);
 
             $projectId = $where['id'];
 
@@ -678,48 +761,29 @@ class Project extends Base_Controller {
     // 删除项目
     public function del() {
         $role = $this->get_user_info('role');
-        // if ($role == COMPANY_CUSTOMER) {
-        //     exit(json_result('0011', $this->response['0011'], array()));
-        // }
 
         $project_id = $this->input->post('project_id', true);
 
-        if(empty($project_id)) {
-            exit(json_result('0200', $this->response['0200'], array()));
-        }
-        $lampListInfo = $this->Lamp_model->get_list_in('P.id',$project_id,'L.address,N.protocoltype');
-        foreach ($lampListInfo as $lampinfo) {
-            $lampinfo['createtime'] = date('Y-m-d H:i:s',time());
+        if(empty($project_id)) exit(json_result('0007', $this->response['0007'], array()));
 
-            $this->db->insert('lampinfo_backup', $lampinfo);
-        }
-
-        // 删除项目对应的区域跟下级区域
-        // $this->Zone_model->delZone($project_id);
-        $net_arr = $this->Network_model->get_list_in(array(),array(),'id,protocoltype',array('projectid'=>$project_id));
-        // foreach ($net_arr as $v) {
-        //     $cmdstr = '{"cmd_type":"delete_network_cmd","cmd_id":'.$v['id'].'}';
-        //     send_cmd($cmdstr,0,0,$v['protocoltype']);
-        // }
-        // 删除项目下面的网络
-        $this->Network_model->delData(array('projectid'=>$project_id));
+        $lampListInfo = $this->Lamp_model->get_one(['projectid'=>$project_id],'id');
+        
+        if (!empty($lampListInfo)) exit(json_result('0214',$this->response['0214']));
 
-        // 删除项目下路灯的告警信息
-        $this->Alarm_model->delDataByCondition(array('projectid'=>$project_id));
+        $net_arr = $this->Network_model->get_one(['projectid'=>$project_id],'id');
 
-        // 删除项目下的路灯
-        $this->Lamp_model->delData(array('projectid'=>$project_id));
+        if (!empty($net_arr)) exit(json_result('0215',$this->response['0215']));
 
         // 删除项目下的监控
-        $this->Videomonitor_model->delData(array('projectid'=>$project_id));
-        $this->Weathermonitor_model->delData(array('projectid'=>$project_id));
+        $this->Videomonitor_model->delete(array('projectid'=>$project_id));
+        $this->Weathermonitor_model->delete(array('projectid'=>$project_id));
 
         $projectData = $this->Project_model->getData(array('id'=>$project_id),'projectname,projectid');
         $this->add_operation_log('delete',"删除\"{$projectData['projectname']}\"项目,项目编号\"{$projectData['projectid']}\"",0);
         $this->add_operation_log('delete',"Delete project.Project name:\"{$projectData['projectname']}\".Project number:\"{$projectData['projectid']}\"",0,1);
 
         // 删除项目
-        $this->Project_model->delOne($project_id);
+        $this->Project_model->delete(['id'=>$project_id]);
 
         exit(json_result('0000', $this->response['0000'], array()));
     }

+ 1 - 2
api/application/helpers/function_helper.php

@@ -414,8 +414,7 @@ function weather_translate_ru($code){
 }
 
 //输出json
-function json_result($code, $msg, $data = array(),$resType = 0) {
-	$data = empty($data) && $resType == 0? new stdClass() : $data;
+function json_result($code, $msg, $data = array()) {
     $res = array('code' => $code,'msg' => $msg,'data' => $data);
     $CI =& get_instance();
     $clientId = $CI->input->post('clientId',true);

+ 0 - 88
api/application/models/Alarm_model.php

@@ -135,94 +135,6 @@ class Alarm_model extends Base_model {
         return $this->db->query($sql)->row_array();
     }
 
-    // 告警信息数量
-    public function getDataCount($filter,$role,$user_id) {
-        $sql        = '';
-        $sqlSel     = "";
-        $implode = array();
-        
-        if (isset($filter['id']) && !empty($filter['id'])) {
-            $implode[] = "A.id='" . intval($filter['id']) . "'";
-        }
-        
-        // 告警状态筛选
-        if (isset($filter['status']) && is_numeric($filter['status'])) {
-            $implode[] = "A.status='" . $filter['status'] . "'";
-            if ($filter['status'] == 0) {
-                $implode[] = "L.isfaulted=1";
-            }else{
-                $implode[] = "L.isfaulted=0";
-            }
-        }
-
-        if (isset($filter['lampid']) && is_numeric($filter['lampid'])) {
-            $implode[] = "A.lampid='" . $filter['lampid'] . "'";
-        }
-        
-        // 告警类型筛选
-        if (isset($filter['alarmtype']) && !empty($filter['alarmtype'])) {
-            $implode[] = "A.stralarmtype like '%" . $filter['alarmtype'] . "%'";
-        }
-        
-        if (isset($filter['projectid']) && is_numeric($filter['projectid'])) {
-            $implode[] = "L.projectid='" . $filter['projectid'] . "'";
-        }
-        if (isset($filter['section']) && !empty($filter['section'])) {
-            $implode[] = "L.section='" . $filter['section'] . "'";
-        }
-        // 关键字搜索
-        if (isset($filter['keyword']) && !empty($filter['keyword'])) {
-            $implode[] = "(L.number LIKE '%{$filter['keyword']}%' or P.projectname LIKE '%{$filter['keyword']}%')";
-        }
-
-        // 时间筛选
-        if (!empty($filter['startDate']) && !empty($filter['endDate'])) {
-            $implode[] = "A.updatetime >= '{$filter['startDate']}'";
-            $implode[] = "A.updatetime <= '{$filter['endDate']}'";
-        }
-        
-        $this->load->model('User_model');
-        $user_info = $this->User_model->get_user_by_id($user_id);
-        $companyid = $user_info['companyid'];       
-        $projectIds = $this->get_projectid_by_role($role,$user_id,$companyid);
-
-        if(empty($projectIds)){
-            $implode[] = "L.projectid in (0)";
-        }else{
-            $implode[] = "L.projectid in ({$projectIds})";
-        }
-        
-        
-        $field = 'A.id as id';
-
-        if (isset($filter['type']) && $filter['type'] == 0){
-            // $field .= ',max(A.updatetime) AS updatetime';
-            $implode[] = "A.updatetime = T.time";
-            $where = $implode ? " WHERE " . implode(" AND ", $implode) : '';
-            $query = "SELECT {$field}
-                FROM alarm_info_log AS A 
-                LEFT JOIN lampinfo AS L ON A.lampid = L.id 
-                LEFT JOIN network AS N ON N.id = L.networkid 
-                LEFT JOIN project AS P ON P.id = L.projectid 
-                LEFT JOIN (select max(updatetime) as time,lampid FROM alarm_info_log group by lampid) as T on A.lampid = T.lampid 
-                -- LEFT JOIN repair_dispatch AS RD on RD.alarmid = A.id 
-                ".$where;
-            $query .= " group by A.lampid";
-        }else{
-            // $field .= ',A.updatetime AS updatetime';
-            $where = $implode ? " WHERE " . implode(" AND ", $implode) : '';
-            $query = "SELECT {$field}
-                FROM alarm_info_log AS A 
-                LEFT JOIN lampinfo AS L ON A.lampid = L.id 
-                LEFT JOIN network AS N ON N.id = L.networkid 
-                LEFT JOIN project AS P ON P.id = L.projectid ".$where;
-            
-        }
-
-        $data = $this->db->query('SELECT count(*) as total FROM ('.$query.') as T')->row_array();
-        return $data['total'];
-    }
-
     public function get_list_by_filter($filter,$page = null,$limit = null) {
     	
     	if (isset($filter['keyword']) || isset($filter['s_type'])){

+ 1 - 0
api/index.php

@@ -58,6 +58,7 @@ ini_set('session.cookie_domain', 'www.lampmind.com'); //注意domain.com换成
  * NOTE: If you change these, also change the error_reporting() code below
  */
 	define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
+	// define('ENVIRONMENT', 'production');
 
 /*
  *---------------------------------------------------------------