| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152 | <?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.updatetime 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'] = '';				$value['updatetime'] = !empty($value['updatetime']) ? date_change($value['updatetime'],0,DEF_TIMEZONE) : '';				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;					$tempLamp['f_longitude'] = $lamp['lamps'][0]['longitude'];					$tempLamp['f_latitude'] = $lamp['lamps'][0]['latitude'];					$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'] = '';				$v['updatetime'] = !empty($v['updatetime']) ? date_change($v['updatetime'],0,DEF_TIMEZONE) : '';				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']/1000, 2);            $data['total_lamp'] = intval($arr['num']);            $data['co2_emission'] = round($arr['power']*0.977/1000, 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']/1000,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 realtime_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,L.netstatus 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 lampinfo where projectid = '.$project_id.' group by protocoltype')->result_array();        $conStr = '';        foreach ($pro_list as $p) {        	if ($conStr != '') {        		$conStr .= '/';        	}        	// if ($p['protocoltype'] == 0) {        	// 	$conStr .= 'MQTT';        	// }elseif ($p['protocoltype'] == 1) {        	// 	$conStr .= 'NBIOT';        	// }elseif ($p['protocoltype'] == 2) {        	// 	$conStr .= 'UDP';        	// }else{        	// 	$conStr .= 'LORAWAN';        	// }        	$conStr .= 'MQTT';        }        $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)));    }}?>
 |