1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/controllers/Base_Controller.php');
- /**
- *
- */
- class Map extends Base_Controller{
- public function __construct()
- {
- parent::__construct();
- $this->load->model('Lamp_model');
- $this->load->model('Alarm_model');
- $this->load->model('Videomonitor_model');
- $this->load->model('Weathermonitor_model');
- $this->load->model('Project_model');
- $this->load->model('Batmanage_model');
- $this->load->model('Network_model');
- $this->load->model('Group_model');
- }
- // 地图首页
- public function get(){
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- // $companyid = $this->get_user_info('companyid');
- $keyword = $this->input->post('keyword',true);
- $type = $this->input->post('type',true);
- $lampid = $this->input->post('lampid',true);
- $projectid = $this->input->post('project_id',true);
- // 需要查询的字段
- $fields = "L.id as id,
- L.number as number,
- L.status,
- L.lighteness as light,
- L.longitude as longitude,
- L.latitude as latitude,
- L.isfaulted,
- L.netstatus as netStatus,
- L.logtime as updatetime,
- L.lampvoltage,
- L.lampcurrent,
- L.lamppower,
- L.address,
- L.chargestage,
- L.direction,
- L.protocoltype as lampprotocoltype";
- // 筛选条件
- $filter = array();
- $lng_low = $this->input->post('lng_low',true);
- $lng_high = $this->input->post('lng_high',true);
- $lat_low = $this->input->post('lat_low',true);
- $lat_high = $this->input->post('lat_high',true);
- $multiple = intval($this->input->post('multiple',true));
-
- if (!empty($keyword)) {
- $filter['keyword'] = $keyword;
- // unset($filter['lng_low']);
- // unset($filter['lng_high']);
- // unset($filter['lat_low']);
- // unset($filter['lat_high']);
- }else{
- if(isset($lng_low) && is_numeric($lng_low)) $filter['lng_low'] = $lng_low;
- if(isset($lng_high) && is_numeric($lng_high)) $filter['lng_high'] = $lng_high;
- if(isset($lat_low) && is_numeric($lat_low)) $filter['lat_low'] = $lat_low;
- if(isset($lat_high) && is_numeric($lat_high)) $filter['lat_high'] = $lat_high;
- }
- $section = $this->input->post('section',true);
- if (!empty($section)) {
- $filter['section'] = $section;
- }
- switch ($type) {
- case '1': // 开灯
- $filter['L.status'] = 1;
- $filter['N.status'] = 1;
- break;
- case '2': // 关灯
- $filter['L.status'] = 0;
- $filter['N.status'] = 1;
- break;
- case '3': // 故障
- $filter['L.isfaulted'] = 1;
- break;
- case '4': // 离线
- // $filter['AI.status !='] = 0;
- $filter['N.status'] = 0;
- break;
- // case '5': // 监控
- // // $filter['monitor'] = 1;
- // $videoData = $this->Videomonitor_model->get_data_by_location($role,$companyid,$projectid,$userid,'id,longitude,latitude',$filter);
- // break;
- default:break;
- }
- if (!empty($type)) {
- if ($type == 5) {
- $data = $this->Videomonitor_model->get_data_by_location($role,0,$projectid,$userid,'id,longitude,latitude,image',$filter);
- foreach ($data as &$s) {
- $s['image'] = base_url($s['image']);
- $s['is_video'] = 1;
- $s['is_lamp'] = 0;
- $s['is_marker'] = 0;
- }
- }else{
- $data = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,$fields,$filter,0,1);
- }
- }else{
- $videoData = $this->Videomonitor_model->get_data_by_location($role,0,$projectid,$userid,'id,longitude,latitude,image',$filter);
- foreach ($videoData as &$s) {
- $s['image'] = base_url($s['image']);
- $s['is_video'] = 1;
- $s['is_lamp'] = 0;
- $s['is_marker'] = 0;
- }
- $lampData = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,$fields,$filter,0,1);
- $data = array_merge($videoData,$lampData);
- }
- if ($multiple <= 16 && isset($lng_low) && isset($lng_high) && isset($lat_low) && isset($lat_high)) {
- $wCount = 30; //水平分割次数
- $hCount = 20; //垂直分割次数
- $maxCount = 2;//20; //最大显示数
- if ($lng_low > $lng_high) {
- $lng = (360-($lng_low-$lng_high))/$wCount;
- }else{
- $lng = ($lng_high-$lng_low)/$wCount;
- }
-
- $lat = ($lat_high-$lat_low)/$hCount;
- $i = 1;
- $temp = array();
- for ($h=0; $h < $hCount; $h++) {
- for ($w=0; $w < $wCount; $w++) {
- $temp[$i]['count'] = 0;
- $temp[$i]['lng_low'] = $lng_low + $w * $lng;
- $temp[$i]['lng_high'] = $lng_low + ($w + 1) * $lng;
- if ($temp[$i]['lng_low'] > 180) {
- $temp[$i]['lng_low'] -= 360;
- }
- if ($temp[$i]['lng_high'] > 180) {
- $temp[$i]['lng_high'] -= 360;
- }
- $temp[$i]['lat_low'] = $lat_low + $h * $lat;
- $temp[$i]['lat_high'] = $lat_low + ($h + 1) * $lat;
- $i ++;
- }
- }
-
- $location = array();
- $indexArr = array_keys($temp);
- foreach ($data as $value) {
- if (isset($value['updatetime']) && $value['updatetime'] == '0000-00-00 00:00:00') $value['updatetime'] = '';
- if (isset($value['lampprotocoltype']) && $value['lampprotocoltype'] == 1) {
- $indArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
- $value['chargestage'] = isset($indArr[intval($value['chargestage'])]) ? $indArr[intval($value['chargestage'])] : $value['chargestage'];
- // var_dump($value['chargestage']);
- }
- $t = $value;
- // if (!empty($type) && $type != 3 && $value['isfaulted'] == 1) {
- // continue;
- // }
- // $t['lampstatus'] = 1;
- if (!isset($location[$value['longitude'].','.$value['latitude']])) {
- $location[$value['longitude'].','.$value['latitude']] = array();
- }
- if (isset($value['isfaulted']) && $value['isfaulted'] == 1) {
- $t['lampstatus'] = 0;
- }else{
- $t['lampstatus'] = 1;
- }
- // $t['isfaulted'] = 0;
- if(empty($t['longitude'])) $t['longitude'] = 0;
- if(empty($t['latitude'])) $t['latitude'] = 0;
- if(empty($t['light'])) $t['light'] = 0;
- if (empty($t['is_video'])) {
- $t['is_lamp'] = 1;
- $t['is_marker'] = 0;
- $t['is_video'] = 0;
- }
- if ($lng_low > $lng_high && $value['longitude'] < $lng_low){
- $t1 = ceil((($t['longitude'] + 360)-$lng_low)/$lng);
- }else{
- $t1 = ceil(($t['longitude']-$lng_low)/$lng);
- }
- $t2 = (ceil(($t['latitude']-$lat_low)/$lat) - 1) * $wCount;
-
- $index = $t1 + $t2;
- if (in_array($index, $indexArr)) {
- if ($temp[$index]['count'] < $maxCount) {
- $temp[$index]['lamps'][] = $t;
- }
- $temp[$index]['count'] += 1;
- }
- }
- $lampData = array();
- // 聚合处理
- foreach ($temp as $lamp) {
- if (!isset($lamp['lamps']) || empty($lamp['lamps'])) continue;
- if ($lamp['count'] >= $maxCount) {
- $tempLamp = array();
- $tempLamp['is_lamp'] = 0;
- if ($lamp['lng_low'] < $lamp['lng_high']) {
- $longitude = $lamp['lng_low'] + ($lamp['lng_high'] + 360 - $lamp['lng_low']);
- if ($longitude > 180) {
- $longitude -= 360;
- }
- $tempLamp['longitude'] = $longitude;
- }else{
- $tempLamp['longitude'] = ($lamp['lng_low'] + $lamp['lng_high'])/2;
- }
- $tempLamp['latitude'] = ($lamp['lat_low'] + $lamp['lat_high'])/2;
- $tempLamp['count'] = $lamp['count'];
- $tempLamp['is_marker'] = 1;
- $tempLamp['is_video'] = 0;
- $lampData[] = $tempLamp;
- }else{
- foreach ($lamp['lamps'] as $l) {
- if (isset($lampid) && $l['id'] == $lampid) {
- $ld = $l;
- continue;
- }
- $lampData[] = $l;
- }
- }
- }
- }else{
- $temp = array();
- $location = array();
- foreach ($data as $v) {
- // if (!empty($type) && $type != 3 && isset($v['isfaulted']) && $v['isfaulted'] == 1) {
- // continue;
- // }
- // $v['lampstatus'] = 1;
- if (isset($v['updatetime']) && $v['updatetime'] == '0000-00-00 00:00:00') $v['updatetime'] = '';
- if (isset($v['lampprotocoltype']) && $v['lampprotocoltype'] == 1) {
- $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;
- }else{
- $v['lampstatus'] = 1;
- }
- if (isset($lampid) && $v['id'] == $lampid) {
- $ld = $v;
- continue;
- }
- if (!isset($v['is_video']) || empty($v['is_video'])) {
- $v['isfaulted'] = 0;
- $v['is_lamp'] = 1;
- $v['is_marker'] = 0;
- $v['is_video'] = 0;
- if(empty($v['light'])) $v['light'] = 0;
- }
- if(empty($v['longitude'])) $v['longitude'] = 0;
- if(empty($v['latitude'])) $v['latitude'] = 0;
-
- $temp[] = $v;
-
- if (!isset($location["{$v['longitude']},{$v['latitude']}"])) {
- $location[$v['longitude'].','.$v['latitude']] = array();
- }
- }
- $lampData = $temp;
- }
- // var_dump(microtime());
- foreach ($lampData as $value) {
- if (isset($location[$value['longitude'].','.$value['latitude']]) && count($location[$value['longitude'].','.$value['latitude']]) >= 10) {
- continue;
- }
- $location[$value['longitude'].','.$value['latitude']][] = $value;
- }
- $data = array();
- foreach ($location as $value) {
- if (!empty($value)) {
- $data = array_merge($data,$value);
- }
- }
- if (isset($ld) && !empty($ld)) {
- $ld['is_lamp'] = 1;
- $ld['is_marker'] = 0;
- $ld['is_video'] = 0;
- $data[] = $ld;
- }
- exit(json_result('0000',$this->response['0000'],array('lamps'=>$data)));
- }
- // 视屏监控
- public function video_list(){
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- // $companyid = $this->get_user_info('companyid');
- $projectid = $this->input->post('project_id',true);
- $keyword = $this->input->post('keyword',true);
- $videoData = $this->Videomonitor_model->get_one_by_role($role,0,$projectid,$userid,'id,longitude,latitude',$keyword);
- $videoData = empty($videoData) ? array() : array($videoData);
- exit(json_result('0000',$this->response['0000'],array('list'=>$videoData)));
- }
- // 地图页灯控列表
- public function lamp_list(){
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- // $companyid = $this->get_user_info('companyid');
- $keyword = $this->input->post('keyword',true);
- $section = $this->input->post('section',true);
- $type = $this->input->post('type',true);
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $projectid = $this->input->post('project_id',true);
- if (empty($projectid)) exit(json_result('0007',$this->response['0007']));
- // 需要查询的字段
- $fields = "id as id,
- number as number,
- status,
- lighteness as light,
- longitude as longitude,
- latitude as latitude,
- isfaulted,
- netstatus as netStatus";
- // 筛选条件
- $filter = array();
- $filter['projectid'] = $projectid;
- if (!empty($keyword)) {
- $filter['number|address'] = $keyword;
- }
- if (!empty($section)) {
- $filter['section'] = $section;
- }
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 16 : $count;
- $limit = $count;
- $offset = ($page - 1) * $count;
- // $filter['page'] = $page;
- // $filter['count'] = $count;
- switch ($type) {
- case '1': // 开灯
- $filter['status'] = 1;
- $filter['netstatus'] = 1;
- break;
- case '2': // 关灯
- $filter['status'] = 0;
- $filter['netstatus'] = 1;
- break;
- case '3': // 故障
- // $filter['AI.status'] = 0;
- $filter['isfaulted'] = 1;
- break;
- case '4': // 离线
- // $filter['AI.status !='] = 0;
- $filter['netstatus'] = 0;
- break;
- // case '5': // 监控
- // $filter['monitor'] = 1;
- // break;
- default:break;
- }
- // $data = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,$fields,$filter);
- $data = $this->Lamp_model->get_list($filter,$fields,$limit, $offset, 'number ASC,id DESC', NUll);
- // unset($filter['page']);
- // unset($filter['count']);
- // $total = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,'L.id',$filter,1);
- $total = $this->Lamp_model->get_count($filter);
- $temp = array();
- foreach ($data as $v) {
- if (!empty($type) && $type != 3 && isset($v['lampstatus']) && $v['lampstatus'] == 0) {
- continue;
- }
- $v['isfaulted'] = 0;
- if(empty($v['longitude'])) $v['longitude'] = 0;
- if(empty($v['latitude'])) $v['latitude'] = 0;
- if(empty($v['light'])) $v['light'] = 0;
- $temp[] = $v;
- }
- $data = $temp;
- exit(json_result('0000',$this->response['0000'],array('lamps'=>$data,'total'=>ceil($total/$count))));
- }
- // 灯控信息
- public function lamp_info(){
- $lamp_id = $this->input->post('lamp_id',true);
- if (empty($lamp_id)) {
- exit(json_result('0802',$this->response['0802'],array()));
- }
- $version = $this->session->userdata('version');
- // 需要获取的字段
- $fields = "L.status,
- L.number as lamp_no,
- L.lighteness as lighteness,
- L.lamppower as lamppower,
- alog.status as lampstatus,
- L.battvoltage as battvoltage,
- BC.vsystem as vsystem,
- L.chargecurrent as chargecurrent,
- L.overtimes as overtimes,
- L.boardpower as boardpower,
- N.networkname as network_name,
- L.chargestage,
- L.loadtype,
- L.isfaulted,L.section";
- $data = $this->Lamp_model->getOne($lamp_id,$fields);
- if ($data['isfaulted'] == 1) {
- // 获取路灯故障信息
- $res = $this->Alarm_model->get_one_by_filter(array('lampid'=>$lamp_id,'status'=>0),'stralarmtype');
- if (empty($version)) {
- $data['alarm_event'] = empty($res['stralarmtype']) ? '正常' : $res['stralarmtype'];
- }else{
- $data['alarm_event'] = empty($res['stralarmtype']) ? 'normal' : alarm_translate($res['stralarmtype']);
- }
-
- }
- if (empty($version)) {
- $chargestage = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
- if (isset($chargestage[$data['chargestage']])) {
- $data['chargestage'] = $chargestage[$data['chargestage']];
- }else{
- $data['chargestage'] = empty($data['chargestage']) ? '没有充电' : '未知状态';
- }
-
- }else{
- $chargestage = array(0=>'There is no charge',1=>'Start charging',6=>'Current limiting',7=>'Full',16=>'MPPT charging',32=>'Equalizing charge',48=>'Improve charging',64=>'Floating',''=>'Unknown state');
- if (isset($chargestage[$data['chargestage']])) {
- $data['chargestage'] = $chargestage[$data['chargestage']];
- }else{
- $data['chargestage'] = empty($data['chargestage']) ? 'There is no charge' : 'Unknown';
- }
- }
-
- $data['battvoltage'] = empty($data['battvoltage']) ? 0 : round($data['battvoltage'],1);
- $data['chargecurrent'] = empty($data['chargecurrent']) ? 0 : round($data['chargecurrent'],2);
- $data['lamppower'] = empty($data['lamppower']) ? 0 : round($data['lamppower'],1);
- $data['lighteness'] = empty($data['lighteness']) ? 0 : $data['lighteness'];
- $data['overtimes'] = empty($data['overtimes']) ? 0 : $data['overtimes'];
- $data['status'] = empty($data['status']) ? 0 : $data['status'];
- $data['vsystem'] = empty($data['vsystem']) ? 0 : $data['vsystem'];
- $data['boardpower'] = empty($data['boardpower']) ? 0 : round($data['boardpower'],1);
-
- exit(json_result('0000',$this->response['0000'],$data));
- }
- // 监控信息
- public function monitor_info(){
- // $lamp_id = $this->input->post('lamp_id',true);
- // if (empty($lamp_id)) {
- // exit(json_result('0007',$this->response['0007'],array()));
- // }
- // $video = $this->Videomonitor_model->get_data_by_fiter(array('lampid'=>$lamp_id),'id as videoid,image');
- // $weather = $this->Weathermonitor_model->get_list_by_filter(array('lampid'=>$lamp_id));
- // $weather = empty($weather) ? array() : $weather[0];
- // exit(json_result('0000',$this->response['0000'],array('video'=>$video,'weather'=>$weather)));
- json_result('0000',$this->response['0000'],array());
- }
- // 项目信息
- public function project_info(){
- $lamp_id = $this->input->post('lamp_id',true);
- $project_id = $this->input->post('project_id',true);
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- // $companyid = $this->get_user_info('companyid');
- if (empty($lamp_id) && empty($project_id) || ($lamp_id < 0 && $project_id < 0)) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
- if ($project_id>0) {
- // var_dump(microtime());
- $data = $this->Project_model->get_data_by_field('P.id',$project_id);
- // var_dump(microtime());
- $data['dayconsumption'] = empty($data['dayconsumption']) ? 0 : round($data['dayconsumption'],1);
- $data['monthconsumption'] = empty($data['monthconsumption']) ? 0 : round($data['monthconsumption'],1);
- $data['yearconsumption'] = empty($data['yearconsumption']) ? 0 : round($data['yearconsumption'],1);
- $data['daygeneration'] = empty($data['daygeneration']) ? 0 : round($data['daygeneration'],1);
- $data['monthgeneration'] = empty($data['monthgeneration']) ? 0 : round($data['monthgeneration'],1);
- $data['yeargeneration'] = empty($data['yeargeneration']) ? 0 : round($data['yeargeneration'],1);
- $data['group_count'] = $this->Group_model->get_count_by_filter(array('projectid'=>$project_id));
- $data['fault_count'] = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
- // $data['install_num'] = $this->Lamp_model->getTotal(array('projectid'=>$project_id), $role, $companyid, $userid);
- $data['network_num'] = $this->Network_model->getTotalByProject($project_id);
- // var_dump(microtime());
- exit(json_result('0000',$this->response['0000'],$data));
- }
- if ($lamp_id > 0){
- $data = $this->Project_model->get_data_by_field('L.id',$lamp_id);
- $data['dayconsumption'] = empty($data['dayconsumption']) ? 0 : round($data['dayconsumption'],1);
- $data['monthconsumption'] = empty($data['monthconsumption']) ? 0 : round($data['monthconsumption'],1);
- $data['yearconsumption'] = empty($data['yearconsumption']) ? 0 : round($data['yearconsumption'],1);
- $data['daygeneration'] = empty($data['daygeneration']) ? 0 : round($data['daygeneration'],1);
- $data['monthgeneration'] = empty($data['monthgeneration']) ? 0 : round($data['monthgeneration'],1);
- $data['yeargeneration'] = empty($data['yeargeneration']) ? 0 : round($data['yeargeneration'],1);
- $data['group_count'] = $this->Group_model->get_count_by_filter(array('projectid'=>$data['id']));
- $data['fault_count'] = $this->Lamp_model->get_fault_count(array('L.projectid'=>$data['id'],'L.isfaulted'=>1), $role, 0, $userid);
- // $data['install_num'] = $this->Lamp_model->getTotal(array('projectid'=>$data['id']), $role, $companyid, $userid);
- $data['network_num'] = $this->Network_model->getTotalByProject($project_id);
- exit(json_result('0000',$this->response['0000'],$data));
- }
-
- }
- // 获取项目列表
- public function project_list() {
- // $companyid = $this->get_user_info('companyid');
- $role = $this->get_user_info('role');
- $userid = $this->get_user_info('id');
- $page = $this->input->post('page',true);
- $count = $this->input->post('count',true);
- $page = empty($page) ? 1 : $page;
- $count = empty($count) ? 1 : $count;
- $filter = array();
- if(!empty($page)) $filter['page'] = $page;
- if(!empty($count)) $filter['count'] = $count;
- $data = $this->Project_model->getMultiData($filter, 'P.id, P.projectname as name, P.lampcount,Z.name as zone,S.name as province,P.projectid as number,P.company as companyid', $role, 0, $userid);
- unset($filter['page']);
- unset($filter['count']);
- $total = $this->Project_model->getTotal($filter, $role, 0, $userid);
- $projectIds = array_column($data, 'id');
- $lampData = $this->Lamp_model->get_lamp_count_by_project($projectIds, $role, 0, $userid);
- $temp = array();
- foreach ($lampData as $value) {
- $temp[$value['projectid']]['lampcount'] = $value['total'];
- }
- foreach ($data as &$v) {
- if (isset($temp[$v['id']]['lampcount']) && !empty($temp[$v['id']]['lampcount'])) {
- $v['lampcount'] = $temp[$v['id']]['lampcount'];
- }else{
- $v['lampcount'] = '0';
- }
- }
- exit(json_result('0000', $this->response['0000'], array('projects'=>$data,'total'=>ceil($total/$count))));
- }
- // 灯控开关,已项目为单位
- 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()));
- // }
- }
- // 故障数/网关数/装机数
- public function data_list(){
- $type = $this->input->post('type',true);
- $projectid = $this->input->post('projectid',true);
- if (empty($type) || empty($projectid)) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
- switch ($type) {
- case '1': // 装机数
- $fields = "L.id,L.number";
- $list = $this->Lamp_model->get_list_in('L.projectid',array($projectid),$fields);
- break;
- case '2': // 网关数
- $fields = "id,networkname";
- $list = $this->Network_model->get_list_in('projectid',array($projectid),$fields);
- break;
- case '3': // 故障数
- $fields = "L.number,L.id,AI.stralarmtype,max(AI.updatetime) as updatetime";
- $list = $this->Alarm_model->get_list_by_projectid($projectid,array('AI.status'=>0,'L.isfaulted'=>1,'group'=>'AI.lampid'),$fields);
- $version = $this->session->userdata('version');
- if (!empty($version)) {
- foreach ($list as &$v) {
- $v['stralarmtype'] = alarm_translate($v['stralarmtype']);
- }
- }
- break;
- default:
- exit(json_result('0014',$this->response['0014'],array()));
- break;
- }
- $list = empty($list) ? array() : $list;
- exit(json_result('0000',$this->response['0000'],$list));
- }
- // 故障详情
- public function fault_info(){
- $alarmid = $this->input->post('lampid',true);
- $userid = $this->get_user_info('id');
- if (empty($alarmid)) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
-
- $join = array();
- $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);
- $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[$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 (!empty($temp2)) {
- $data['stralarmtype'] = implode(',', $temp2);
- }else{
- $data['stralarmtype'] = '';
- }
- $data['userid'] = empty($data['userid']) ? 0 : $data['userid'];
- // 获取维修人员列表
- $list = $this->User_model->get_repair_user(array('user_id'=>$userid));
- $data['list'] = $list;
- exit(json_result('0000',$this->response['0000'],$data));
- }
- // 地图页概览数据
- public function date_nav(){
- $userid = $this->get_user_info('id');
- // $companyid = $this->get_user_info('companyid');
- $role = $this->get_user_info('role');
- $project_id = intval($this->input->post('project_id', true));
- if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
- $arr = $this->Lamp_model->getTotalLampInfo($role, 0, $project_id, $userid,1);
- if (!empty($arr['num'])) {
- $online_arr = $this->Lamp_model->get_count(['projectid'=>$project_id,'netStatus'=>1]);
- $lighting_arr = $this->Lamp_model->getCountByFilter($role, 0, $project_id, $userid, array('L.status'=>1));
- // $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
- $failure = 0;
- $data['online_rate'] = round($online_arr['num']/$arr['num']*100, 2);
- $data['lighting_rate'] = round($lighting_arr['num']/$arr['num']*100, 2);
- $data['online_count'] = intval($online_arr['num']);
- $data['lighting_count'] = intval($lighting_arr['num']);
- $data['failure_rate'] = round($failure/$arr['num']*100, 2);
- $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['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);
- } else {
- $data['online_rate'] = 0;
- $data['failure_rate'] = 0;
- $data['lighting_rate'] = 0;
- $data['failure_count'] = 0;
- $data['totalgeneration'] = 0;
- $data['total_lamp'] = 0;
- $data['co2_emission'] = 0;
- $data['so2_emission'] = 0;
- $data['coal_saving'] = 0;
- $data['online_count'] = 0;
- $data['lighting_count'] = 0;
- $data['totalconsumption'] = 0;
- }
- exit(json_result('0000', $this->response['0000'], $data));
- }
- // 路灯数据
- public function lamp_data(){
- $lampid = intval($this->input->post('lampid',true));
- if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
- $fields = 'L.number,L.address,L.netstatus as netStatus,L.lighteness,L.lampvoltage,L.lampcurrent,L.lamppower,L.electricleft,L.batttemper,L.chargestage,L.overtimes,L.battvoltage,L.discharcurrent,L.dischargepower,L.daydischargemincurrent,L.solarvoltage,L.solarcurrent,L.protocoltype,L.solarpower,L.temper,L.totalgeneration,L.totalconsumption,L.daychargemincurrent,L.id,L.totalLightTime,L.createtime,L.projectid,AI.batstatus,AI.panelstatus, AI.lampstatus,AI.tempstatus,AI.id as alarmId';
- $join = [];
- $join[] = ['table'=>'(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', 'cond'=>'L.id = AI.lampid', 'type'=>'left'];
- $data = $this->Lamp_model->get_list_by_multi_join(['L.id'=>$lampid], $fields,NULL, NULL, $join, NULL, NUll, 'L', true);
- // $data = $this->Lamp_model->get_list(['id'=>$lampid],$fields);
- if (isset($data['alarmId']) && ($data['batstatus'] != 0 || $data['batstatus'] != 0 || $data['batstatus'] != 0 || $data['batstatus'] != 0)) {
- $data['isfaulted'] = '1';
- // $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[$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']];
- // $data['isfaulted'] = implode(',', $temp2);
- // $res = $this->Alarm_model->get_one_by_filter(array('lampid'=>$data['id'],'status'=>0),'stralarmtype');
- // $stralarmtype = trim($res['stralarmtype']);
- // if (!empty($stralarmtype)) {
- // $value['isfaulted'] = '1';
- // }else{
- // $value['isfaulted'] = '0';
- // }
- }else{
- $data['isfaulted'] = '0';
- }
- $LampData = $this->db->query('select min(updatetime) as minTime from system_info_log where lampid = '.$lampid)->row_array();
- if (empty($LampData) || empty($LampData['minTime']) || $LampData['minTime'] == '1970-01-01 08:00:00') {
- if (empty($data['createtime']) || $data['createtime'] == '1970-01-01 08:00:00') {
- $beginTime = time();
- }else{
- $beginTime = strtotime($data['createtime']);
- }
- }else{
- $beginTime = strtotime($LampData['minTime']);
- }
- $data['userDate'] = round((time() - $beginTime) / (3600 * 24 * 356),1);
- $data['userDate'] = $data['userDate'] > 100 ? 0 : $data['userDate'];
- // $LampInfoData = $this->db->query('select id,lamppower from lamp_info_log where lighteness = 100 AND lampid = '.$lampid.' order by updatetime DESC limit 1')->row_array();
- $LampInfoData = 0;
- if (empty($LampInfoData) || empty($LampInfoData['id'])) {
- $lamppower = 0;
- }else{
- $lamppower = $LampInfoData['lamppower'];
- }
- if ($lamppower == 0) {
- $later = 3;
- }else{
- $totalconsumption = $lamppower*10*365*3;
- $consum = $totalconsumption - $data['totalconsumption'];
- if ($consum <= 0) {
- $later = 0;
- }else{
- $later = round($consum/($lamppower*10)/365,1);
- }
- }
- $data['later'] = $later;
- $data['totalDate'] = $later + $data['userDate'];
- // 日照时间
- $project_weather = $this->db->query('select * from project_weather where projectId = '.$data['projectid'])->row_array();
- if (empty($project_weather)) {
- $data['sunTime'] = 0;
- }else{
- $weatherInfo = json_decode($project_weather['weatherInfo'],true);
- if (!empty($weatherInfo[0])) {
- $sr = $weatherInfo[0]['sr'];
- $ss = $weatherInfo[0]['ss'];
- $srArr = explode(':', $sr);
- $ssArr = explode(':', $ss);
- $data['sunTime'] = round((intval($ssArr[0])*60+intval($ssArr[1]) - (intval($srArr[0])*60+intval($srArr[1])))/60,1);
- }else{
- $data['sunTime'] = 0;
- }
- }
- exit(json_result('0000',$this->response['0000'],$data));
- }
- // 路段信息
- public function section_data(){
- $lampid = intval($this->input->post('lampid',true));
- $netStatus = intval($this->input->post('netStatus',true));
- $projectid = intval($this->input->post('projectid',true));
- $section = $this->input->post('section',true);
- $fields = 'L.section,L.projectid';
-
- if (empty($lampid)){
- if (empty($projectid) || empty($section)) {
- exit(json_result('0007',$this->response['0007']));
- }else{
- $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.section = "'.$section.'" AND L.projectid = '.$projectid)->row_array();
- }
- }else{
- $data = $this->Lamp_model->getOne($lampid,$fields);
- }
-
- if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
- // 路灯总数
- $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'] = intval($data['fail_count']);
- $data['fail_rate'] = round($data['fail_count']/$data['lamp_count']*100,2);
- // 在线数
- $data['online_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'online'=>1));
- $data['online_count'] = intval($data['online_count']);
- $data['online_rate'] = round($data['online_count']/$data['lamp_count']*100,2);
- // 亮灯数
- $data['light_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'lightStatus'=>1));
- $data['light_count'] = intval($data['light_count']);
- $data['light_rate'] = round($data['light_count']/$data['lamp_count']*100,2);
- $res = $this->Lamp_model->get_section_avg($data['projectid'],$data['section']);
- $data['daychargemincurrent'] = intval($res['daychargemincurrent']);
- $data['daydischargemincurrent'] = intval($res['daydischargemincurrent']);
- $data['totalgeneration'] = round($res['totalgeneration'],2);
- $data['totalconsumption'] = intval($res['totalconsumption'],2);
- $data['electricleft'] = intval($res['electricleft']);
- $data['battvoltage'] = round($res['battvoltage'],1);
- // 路灯列表
- $where = array('section'=>$data['section'],'projectid'=>$data['projectid']);
- $onlineStatus = intval($this->input->post('onlineStatus',true));
- if (!empty($onlineStatus)) $where['online'] = 1;
- $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;
- $list = $this->Lamp_model->get_list_in(null, array(), 'L.id,L.number,N.status as netStatus,L.lighteness,L.isfaulted',$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);
- }
- }
- $value['stralarmtype'] = implode(',', $temp2);
- $value['isfaulted'] = '1';
- }else{
- $value['stralarmtype'] = 'Nothing';
- $value['isfaulted'] = '0';
- }
- }
- }
- unset($value['failStatus']);
- // unset($value['stralarmtype']);
- $data['lampList'][] = $value;
- }
- exit(json_result('0000',$this->response['0000'],$data));
- }
- // 项目信息
- public function project_data(){
- $lampid = intval($this->input->post('lampid',true));
- if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
- $fields = 'L.projectid,L.section';
- $data = $this->Lamp_model->getOne($lampid,$fields);
- $userid = $this->get_user_info('id');
- // $companyid = $this->get_user_info('companyid');
- $role = $this->get_user_info('role');
- $project_id = $data['projectid'];
- $arr = $this->Lamp_model->getTotalLampInfo($role, 0, $project_id, $userid,1);
- if (!empty($arr['num'])) {
- $online_arr = $this->Lamp_model->getOnlineCount($role, 0, $project_id, $userid, 1);
- $lighting_arr = $this->Lamp_model->getCountByFilter($role, 0, $project_id, $userid, array('L.status'=>1));
- // $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
- $failure = 0;
- $data['online_rate'] = round($online_arr['num']/$arr['num']*100, 2);
- $data['lighting_rate'] = round($lighting_arr['num']/$arr['num']*100, 2);
- $data['online_count'] = intval($online_arr['num']);
- $data['lighting_count'] = intval($lighting_arr['num']);
- $data['failure_rate'] = round($failure/$arr['num']*100, 2);
- $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['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);
- } else {
- $data['online_rate'] = 0;
- $data['failure_rate'] = 0;
- $data['lighting_rate'] = 0;
- $data['failure_count'] = 0;
- $data['totalgeneration'] = 0;
- $data['total_lamp'] = 0;
- $data['co2_emission'] = 0;
- $data['so2_emission'] = 0;
- $data['coal_saving'] = 0;
- $data['online_count'] = 0;
- $data['lighting_count'] = 0;
- $data['totalconsumption'] = 0;
- }
- // 获取路段下拉列表
- $section_nav = $this->db->query('select section from lampinfo where projectid = '.$project_id.' AND section != "" group by section')->result_array();
- $data['section_nav'] = array();
- foreach ($section_nav as $s) {
- $data['section_nav'][] = array('name'=>$s['section'],'value'=>$s['section']);
- }
- // 获取项目下控制器类型
- $pro_list = $this->db->query('select protocoltype from network where projectid = '.$project_id.' group by protocoltype')->result_array();
- $conStr = '';
- foreach ($pro_list as $p) {
- if ($conStr != '') {
- $conStr .= '/';
- }
- if ($p['protocoltype'] == 0) {
- $conStr .= 'TCP';
- }elseif ($p['protocoltype'] == 1) {
- $conStr .= 'NBIOT';
- }elseif ($p['protocoltype'] == 2) {
- $conStr .= 'UDP';
- }else{
- $conStr .= 'LORAWAN';
- }
- }
- $data['protocolType'] = $conStr;
- // 配置信息
- $lampData = $this->db->query('select id,boardpower,lamppower,batteryah,batterytype from lampinfo where projectid = '.$project_id.' order by id ASC limit 1')->row_array();
- if (empty($lampData) || $lampData['id']) {
- $data['boardpower'] = '';
- $data['lamppower'] = '';
- $data['batteryah'] = '';
- $data['batterytype'] = '';
- }else{
- $data['boardpower'] = $lampData['boardpower'];
- $data['lamppower'] = $lampData['lamppower'];
- $data['batteryah'] = $lampData['batteryah'];
- $data['batterytype'] = $lampData['batterytype'];
- }
- $data['shelfLife'] = 3;
- $data['controlType'] = '';
- // 项目信息
- $proData = $this->db->query('select id,createtime,projectname,address,company from project where id = '.$project_id)->row_array();
- $data['createtime'] = $proData['createtime'];
- $data['address'] = $proData['address'];
- $data['projectname'] = $proData['projectname'];
- $comData = $this->db->query('select id,name from company where id = '.$proData['company'])->row_array();
- $data['company'] = $comData['name'];
- exit(json_result('0000',$this->response['0000'],$data));
- }
- // 故障信息
- public function alarm_data(){
- $lampid = intval($this->input->post('lampid',true));
- $netStatus = intval($this->input->post('netStatus',true));
- $projectid = intval($this->input->post('projectid',true));
- $section = $this->input->post('section',true);
- $fields = 'L.section,L.projectid';
- $where = array();
- if (empty($lampid)){
- if (empty($projectid)) {
- exit(json_result('0007',$this->response['0007']));
- }else{
- $where['projectid'] = $projectid;
- if (empty($section)) {
- $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.projectid = '.$projectid)->row_array();
- }else{
- $where['section'] = $section;
- $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.section = "'.$section.'" AND L.projectid = '.$projectid)->row_array();
- }
-
- }
- }else{
- $data = $this->Lamp_model->getOne($lampid,$fields);
- }
-
- // if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
- // 路灯列表
- $where['status'] = 1;
- 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);
- $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;
- }
- exit(json_result('0000',$this->response['0000'],$data));
- }
- // 修改路灯方向
- public function change_direction(){
- $lampid = intval($this->input->post('lampid',true));
- $direction = intval($this->input->post('direction',true));
- if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
- $this->Lamp_model->update(array('id'=>$lampid),array('direction'=>$direction));
- exit(json_result('0000',$this->response['0000']));
- }
- // 路段下拉
- public function section_nav(){
- $project_id = intval($this->input->post('projectid',true));
- if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
- $sectionList = $this->db->query('select section,count(id) as lampcount from lampinfo where projectid = '.$project_id.' AND section != "" group by section')->result_array();
- if (empty($sectionList)) {
- $data = array();
- }else{
- $data = array();
- foreach ($sectionList as $s) {
- $data[] = array('name'=>$s['section'],'value'=>$s['section'],'lampcount'=>$s['lampcount']);
- }
- }
- exit(json_result('0000',$this->response['0000'],array('list'=>$data)));
- }
- }
- ?>
|