12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243 |
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- include_once(FCPATH . 'application/controllers/Base_Controller.php');
- class Lampcontrol extends Base_Controller {
-
- private $chargeStageMap = array(0=>'没有充电',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
- public function __construct() {
- parent::__construct();
- $this->load->model('Company_model');
- $this->load->model('Project_model');
- $this->load->model('Network_model');
- $this->load->model('Lamp_model');
- $this->load->model('Batmanage_model');
- $this->load->model('Patrol_model');
- $this->load->model('Load_model');
- $this->load->model('Battery_model');
- $this->load->model('Alarm_model');
- // $this->load->model('Zone_model');
- $this->load->model('Videomonitor_model');
- $this->load->model('Modbus_load_model');
- $this->load->model('Modbus_battery_model');
- $this->load->model('Global_location_model');
- $this->load->model('RealtimeInfoLog_model');
- }
- // 灯控列表
- public function get() {
- $userid = $this->get_user_info('id');
-
- $project_id = intval($this->input->post('project_id', true));
- if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
- $fields = $this->input->post('fields', true);
- $field1 = $this->input->post('field1', true);
- $pid_arr = $project_id;
- $timezone = $this->Project_model->get_timezone_by_projectid($project_id);
- $filter = 'L.projectid = '.$project_id;
- $countWhere = array('projectid = '.$project_id);
- $network_id = $this->input->post('network_id', true);
- $section = $this->input->post('section', true);
- $type = intval($this->input->post('type', true));
- $company = intval($this->input->post('company', true));
- if (!empty($type) && !empty($company)) {
-
- if ($type == 2) {
- $filter .= ' AND L.manu = '.$company;
- $countWhere[] = 'manu = '.$company;
- }elseif ($type == 3) {
- $filter .= ' AND L.supplier = '.$company;
- $countWhere[] = 'supplier = '.$company;
- }elseif ($type == 4) {
- $filter .= ' AND L.po = '.$company;
- $countWhere[] = 'po = '.$company;
- }else {
- $filter .= ' AND P.cityid = '.$company;
- }
- }
- $role = $this->get_user_info('role');
- $company2 = $this->get_user_info('company');
- if ($role != SYSTEM_ADMIN) {
- if ($role == 2) {
- // $filter .= ' AND L.manu = '.$company2;
- // $countWhere[] = 'manu = '.$company2;
- }elseif ($role == 3) {
- $filter .= ' AND L.supplier = '.$company2;
- $countWhere[] = 'supplier = '.$company2;
- }elseif ($role == 4) {
- $filter .= ' AND L.po = '.$company2;
- $countWhere[] = 'po = '.$company2;
- }else {
- $filter .= ' AND P.cityid = '.$company2;
- }
- }
- if (!empty($section)) {
- $filter .= ' AND L.section = "'.$section.'"';
- $countWhere[] = 'section = "'.$section.'"';
- }
- $offline = $this->input->post('offline', true);
- if (!empty($offline)) {
- $filter .= ' AND L.netstatus = 0';
- $countWhere[] = 'netstatus = 0';
- }
- $online = $this->input->post('online', true);
- if (!empty($online)) {
- $filter .= ' AND L.netstatus= 1';
- $countWhere[] = 'netstatus = 1';
- }
- // 分页数据
- $page = intval($this->input->post('page',true));
- $page = empty($page) ? 1 : $page;
- $count = intval($this->input->post('count',true));
- $limit = empty($count) ? 10 : $count;
- $offset = ($page - 1)*$count;
- $keyword = $this->input->post('keyword', true);
- if ($keyword !== '' && $keyword !== null) {
- $filter .= ' AND (L.number like "%'.$keyword.'%" OR L.section like "%'.$keyword.'%" OR L.address like "%'.$keyword.'%")';
- $countWhere[] = '(number like "%'.$keyword.'%" OR section like "%'.$keyword.'%" OR address like "%'.$keyword.'%")';
- }
- $status = $this->input->post('status', true);
- if (!empty($status)) {
- // $filter['AI.isfaulted'] = $status;
- $filter .= ' AND (AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0 OR AI.onlinestatus != 0) and (L.controllerstatus = 5 OR L.netstatus = 0)';
- }
- // $alarmtype = $this->input->post('alarmtype', true);
- // if (!empty($alarmtype)) $filter['AI.alarmtype'] = $alarmtype;
- // 记录用户选择的字段
- if (!empty($field1)) {
- $fieldData = array('userid'=>$userid,'lampfield'=>$field1);
- $this->User_model->update_user_field($fieldData);
- }
- $lite = $this->input->post('lite', true);
- $version = $this->session->userdata('version');
- if ($lite == 1) {
- if(empty($fields)){
- $fields = 'L.id, L.number,L.address,RI.updatetime,RI.loadpower,RI.batvoltage as battvoltage,L.netstatus,L.lighteness,L.status,L.battstatus,L.chargestage,L.controllerstatus,L.netstatus as netstatus2';
- }else{
- $fields .= ",RI.updatetime,L.controllerstatus,L.netstatus as netstatus2";
- }
- $join = array();
- $join[] = ['table'=>'(select t1.* from realtime_info_log t1, (select lampid, max(updatetime) as maxtime from realtime_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as RI', 'cond'=>'L.id = RI.lampid', 'type'=>'left'];
- $data['lamps'] = $this->Lamp_model->get_list_by_join($filter, $fields,$limit, $offset, $join, "L.number ASC", NUll, 'L');
- } else {
- if(empty($fields) || empty($field1)){
- $fields = 'L.id, L.number, IFNULL(L.status,0) as status, L.isfaulted, L.address, L.loadpower as lamppower, L.electricSOC, L.battvoltage, L.chargestage, RI.updatetime, RI.updatetime as modifytime,L.overtimes,L.boardpower,L.lighteness as light,L.projectid,L.devstatus as online,P.projectname as project_name,L.section,L.loadtype,P.timezone as timezoneid,L.controllerstatus,L.netstatus as netstatus2';
- }else{
- $fields .= ",L.id,L.projectid,L.section,L.loadtype,P.timezone as timezoneid,L.controllerstatus,L.netstatus as netstatus2";
- }
- $download = intval($this->input->post('download',true));
- if (!empty($download)) {
- $limit = null;
- $offset = null;
- }
- $join = array();
- $join[] = ['table'=>'project as P', 'cond'=>'L.projectid = P.id', 'type'=>'left'];
- $join[] = ['table'=>'company as C1', 'cond'=>'L.po = C1.id', 'type'=>'left'];
- $join[] = ['table'=>'company as C2', 'cond'=>'L.supplier = C2.id', 'type'=>'left'];
- $join[] = ['table'=>'company as C3', 'cond'=>'L.manu = C3.id', 'type'=>'left'];
- $join[] = ['table'=>'model_info as MI', 'cond'=>'L.model = MI.id', 'type'=>'left'];
- // $join[] = ['table'=>'(select t1.* from alarm_info_log t1, (select lampid, max(updatetime) as maxtime from alarm_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'];
- $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'];
- $join[] = ['table'=>'(select t1.* from history_info_log t1, (select lampid, max(updatetime) as maxtime from history_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as HI', 'cond'=>'L.id = HI.lampid', 'type'=>'left'];
- $join[] = ['table'=>'(select t1.* from realtime_info_log t1, (select lampid, max(updatetime) as maxtime from realtime_info_log group by lampid) t2 where t1.lampid = t2.lampid and t1.updatetime = t2.maxtime) as RI', 'cond'=>'L.id = RI.lampid', 'type'=>'left'];
- $data['lamps'] = $this->Lamp_model->get_list_by_join($filter, $fields,$limit, $offset, $join, "L.number ASC", NUll, 'L');
- // $data['lamps'] = $this->Lamp_model->get_list_in('L.projectid', $pid_arr, $fields, $filter);
- // var_dump(microtime());
- $indexArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
- if (empty($version)) {
- $chargeStageMap = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
- $battstatusArr = array(0=>'空闲',1=>'放电',2=>'充电',3=>'一边充电一边放电',''=>'未知状态');
- $unknown = '未知状态';
- }else{
- $chargeStageMap = 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');
- $battstatusArr = array(0=>'Free',1=>'Discharge',2=>'Charge',3=>'Discharge while charging',''=>'Unknown state');
- $unknown = 'Unknown state';
- }
- if (!empty($download)) {
- $fieldArr = explode(',', $field1);
- $fieldArr[] = 'iccid';
- $temp = [];
- $i = 1;
- foreach ($data['lamps'] as $key => &$value) {
- $value['section'] = empty($value['section']) ? '' : $value['section'];
- if (isset($value['updatetime']) && $value['updatetime'] == '0000-00-00 00:00:00') {
- $value['updatetime'] = null;
- }
- if (array_key_exists('lamppower',$value)) {
- $value['lamppower'] = !empty($value['lamppower']) ? $value['lamppower'] : "0";
- }
- // 故障信息处理
- if (array_key_exists('alarmStatus',$value)) {
- if ((empty($value['batstatus']) && $value['panelstatus'] && $value['lampstatus'] && $value['tempstatus']) || $value['controllerstatus'] != 5) {
- if (empty($version)) {
- $value['isfaulted'] = '无';
- }else{
- $value['isfaulted'] = 'Nothing';
- }
-
- }else{
- $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[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
- if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
- if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
- if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
- if (!empty($temp2)) {
- $value['isfaulted'] = implode(',', $temp2);
- }else{
- $value['isfaulted'] = 'Nothing';
- }
-
- }
- }
- if (array_key_exists('lampstatus',$value)) {
- $value['lampstatus'] = !empty($value['lampstatus']) ? $value['lampstatus'] : "0";
- }
- if (array_key_exists('electricSOC',$value)) {
- $value['electricSOC'] = !empty($value['electricSOC']) ? $value['electricSOC'] : "0";
- }
- if (array_key_exists('battvoltage',$value)) {
- $value['battvoltage'] = !empty($value['battvoltage']) ? $value['battvoltage'] : "0";
- }
- if (array_key_exists('chargestage',$value)) {
- $value['chargestage'] = isset($value['chargestage']) ? $chargeStageMap[$value['chargestage']] : $unknown;
- }
- if (array_key_exists('battstatus',$value)) {
- $value['battstatus'] = isset($value['battstatus']) ? $battstatusArr[$value['battstatus']] : $unknown;
- }
- if (array_key_exists('overtimes',$value)) {
- $value['overtimes'] = !empty($value['overtimes']) ? $value['overtimes'] : 0;
- }
- if (array_key_exists('solarpower',$value)) {
- $value['solarpower'] = !empty($value['solarpower']) ? $value['solarpower'] : 0;
- }
- if (array_key_exists('iccid',$value)) {
- $value['iccid'] = !empty($value['iccid']) ? $value['iccid'] : '';
- }
- if (array_key_exists('updatetime',$value)) {
- $value['updatetime'] = !empty($value['updatetime']) ? $value['updatetime'] : '';
- // 通过时区修改时间
- if (!empty($value['updatetime'])) {
- $timezone = $this->Project_model->get_timezone_by_projectid($value['projectid']);
- if ($timezone['value'] != 8) {
- $value['updatetime'] = date_change($value['updatetime'],8,$timezone['value']);
- }
- }
- }
- // 当前策略
- if (array_key_exists('policyid',$value)) {
- if (empty($value['policyid'])) {
- $value['policyid'] = '';
- }else{
- $policyData = $this->db->query('select name from policy_info where id = '.$value['policyid'])->row_array();
- if (empty($policyData) || empty($policyData['name'])) {
- $value['policyid'] = '';
- }else{
- $value['policyid'] = $policyData['name'];
- }
- }
- }
-
- $temp[$key][] = $i;
- foreach ($fieldArr as $f) {
- if ($f == 'lampstatus') {
- if (empty($version)) {
- $temp[$key][] = empty($value[$f]) ? '关灯' : '开灯';
- }else{
- $temp[$key][] = empty($value[$f]) ? 'off' : 'on';
- }
- continue;
- }
- if ($f == 'status') {
- if (empty($version)) {
- $temp[$key][] = empty($value[$f]) ? '不在线' : '在线';
- }else{
- $temp[$key][] = empty($value[$f]) ? 'off-line' : 'online';
- }
- continue;
- }
- if ($f == 'daychargemincurrent' || $f == 'daydischargemincurrent') {
- $t = floor($value[$f]/3600) < 10 ? '0'.floor($value[$f]/3600) : floor($value[$f]/3600);
- $m = ceil($value[$f]%3600/60) < 10 ? '0'.ceil($value[$f]%3600/60) : ceil($value[$f]%3600/60);
- $temp[$key][] = $t.':'.$m;
- continue;
- }
- $temp[$key][] = $value[$f];
- }
- $i ++;
- }
- $title1 = get_fields_by_type($field1,$version);
- if (empty($version)) {
- $title2 = array_merge(array('编号'),$title1);
- }else{
- $title2 = array_merge(array('Number'),$title1);
- }
- $title = [];
- foreach ($title2 as $t) {
- $title[0][] = $t;
- }
- $title[0][] = 'iccid';
- $data = array_merge($title,$temp);
- $path = push_excel($data,'lampinfoExcel_'.date('Ymd'));
- exit(json_result('0000', $this->response['0000'], array('path'=>$path)));
- }
- foreach ($data['lamps'] as $key => &$value) {
- $value['section'] = empty($value['section']) ? '' : $value['section'];
- if (isset($value['updatetime']) && $value['updatetime'] == '0000-00-00 00:00:00') {
- $value['updatetime'] = null;
- }
- if (array_key_exists('lamppower',$value)) {
- $value['lamppower'] = !empty($value['lamppower']) ? $value['lamppower'] : "0";
- }
- // 故障信息处理
- if (array_key_exists('alarmStatus',$value)) {
- if ($value['netstatus2'] == 0) {
- if (empty($version)) {
- $value['isfaulted'] = '离线故障';
- }else{
- $value['isfaulted'] = 'Offline failure';
- }
- }else{
- if ((empty($value['batstatus']) && $value['panelstatus'] && $value['lampstatus'] && $value['tempstatus']) || $value['controllerstatus'] != 5) {
- if (empty($version)) {
- $value['isfaulted'] = '无';
- }else{
- $value['isfaulted'] = 'Nothing';
- }
-
- }else{
- $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[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
- if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
- if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
- if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
- if (!empty($temp2)) {
- $value['isfaulted'] = implode(',', $temp2);
- }else{
- $value['isfaulted'] = 'Nothing';
- }
-
- }
- }
-
- }
- if (array_key_exists('lampstatus',$value)) {
- $value['lampstatus'] = !empty($value['lampstatus']) ? $value['lampstatus'] : "0";
- }
- if (array_key_exists('electricSOC',$value)) {
- $value['electricSOC'] = !empty($value['electricSOC']) ? $value['electricSOC'] : "0";
- }
- if (array_key_exists('battvoltage',$value)) {
- $value['battvoltage'] = !empty($value['battvoltage']) ? $value['battvoltage'] : "0";
- }
- if (array_key_exists('chargestage',$value)) {
- $value['chargestage'] = isset($value['chargestage']) && isset($chargeStageMap[$value['chargestage']]) ? $chargeStageMap[$value['chargestage']] : $unknown;
- }
- if (array_key_exists('battstatus',$value)) {
- $value['battstatus'] = isset($value['battstatus']) ? $battstatusArr[$value['battstatus']] : $unknown;
- }
- if (array_key_exists('overtimes',$value)) {
- $value['overtimes'] = !empty($value['overtimes']) ? $value['overtimes'] : 0;
- }
- if (array_key_exists('solarpower',$value)) {
- $value['solarpower'] = !empty($value['solarpower']) ? $value['solarpower'] : 0;
- }
- if (array_key_exists('po_name',$value) && array_key_exists('po_no',$value)) {
- $value['po_name'] = !empty($value['po_no']) ? $value['po_no'] : $value['po_name'];
- }
- if (array_key_exists('supplier_name',$value) && array_key_exists('supplier_no',$value)) {
- $value['supplier_name'] = !empty($value['supplier_no']) ? $value['supplier_no'] : $value['supplier_name'];
- }
- if (array_key_exists('MFRS_name',$value) && array_key_exists('MFRS_no',$value)) {
- $value['MFRS_name'] = !empty($value['MFRS_no']) ? $value['MFRS_no'] : $value['MFRS_name'];
- }
- // 当前策略
- if (array_key_exists('policyid',$value)) {
- if (empty($value['policyid'])) {
- $value['policyid'] = '';
- }else{
- $policyData = $this->db->query('select name from policy_info where id = '.$value['policyid'])->row_array();
- if (empty($policyData) || empty($policyData['name'])) {
- $value['policyid'] = '';
- }else{
- $value['policyid'] = $policyData['name'];
- }
- }
- }
- if (array_key_exists('updatetime',$value)) {
- $value['updatetime'] = !empty($value['updatetime']) ? $value['updatetime'] : '';
- // 通过时区修改时间
- if (!empty($value['updatetime'])) {
- // $value['timezoneid'];
- if($timezone === null) $timezone = $this->db->query('select value from timezone where id = '.$value['timezoneid'])->row_array();
- // var_dump($timezone);die;
- $value['updatetime'] = set_timezone($value['updatetime'],$timezone['value']);
- // if ($timezone['value'] != 8) {
- // $value['updatetime'] = date_change($value['updatetime'],0,$timezone['value']);
- // }
- }
- }
- }
- if (!empty($project_id)) {
-
- }
- }
- // unset($filter['page']);
- // unset($filter['count']);
- $countWheret1 = implode(' AND ', $countWhere);
- // var_dump($countWheret1);die;
- $data['total_data']['install_num'] = $this->Lamp_model->get_count($countWheret1);
- // var_dump($data['total_data']['install_num']);die;
- $countWheret = $countWhere;
- $countWheret[] = 'lighteness > 0';
- $countWheret[] = 'netstatus = 1';
- $countWheret1 = implode(' AND ', $countWheret);
- $data['total_data']['light_num'] = $this->Lamp_model->get_count($countWheret1);
- $countWheret = $countWhere;
- $countWheret[] = 'netstatus = 1';
- $countWheret1 = implode(' AND ', $countWheret);
- $data['total_data']['online_num'] = $this->Lamp_model->get_count($countWheret1);
- $filter2 = $filter.' AND (AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0 OR AI.onlinestatus != 0) AND (L.controllerstatus = 5 or L.netstatus = 0)';
- $join2 = array();
- $join2[] = ['table'=>'project as P', 'cond'=>'L.projectid = P.id', 'type'=>'left'];
- $join2[] = ['table'=>'(select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as WI','cond'=>'WI.lampid = L.id','type'=>'inner'];
- $join2[] = ['table'=>'warning_info_log as AI','cond'=>'WI.lampid = AI.lampid AND WI.maxTime = AI.updatetime','type'=>'inner'];
- $res = $this->Lamp_model->get_list_by_multi_join($filter2, 'count(*) total',null, null, $join2, "L.number ASC", NUll, 'L',true);
- $data['total_data']['fault_count'] = $res['total'];
- $data['total_data']['light_rate'] = empty($data['total_data']['install_num']) ? '0' : round($data['total_data']['light_num']/$data['total_data']['install_num'],4)*100;
- $data['total_data']['light_rate'] .= '%';
- $data['total_data']['online_rate'] = empty($data['total_data']['install_num']) ? '0' : round($data['total_data']['online_num']/$data['total_data']['install_num'],4)*100;
- $data['total_data']['online_rate'] .= '%';
- $data['total_data']['fault_rate'] = empty($data['total_data']['install_num']) ? '0' : round($data['total_data']['fault_count']/$data['total_data']['install_num'],4)*100;
- $data['total_data']['fault_rate'] .= '%';
- // $data['total_data']['network_num'] = $this->Network_model->get_count(['projectid'=>$project_id,'type'=>1]);
- // $res = $this->Lamp_model->get_list_by_multi_join($filter, 'count(*) total',$limit, $offset, $join, "L.number ASC", NUll, 'L',true);
- // $result = !empty($pid_arr) ? $this->Lamp_model->get_count(['projectid'=>$pid_arr]) : array();
- // $result = $this->Lamp_model->get_count(['projectid'=>$pid_arr]);
- $data['total'] = $data['total_data']['install_num'];
- $data['count'] = $data['total_data']['install_num'];
- // $data['fault'] = $res['total'];
- exit(json_result('0000', $this->response['0000'], $data));
- }
- // 更新灯控信息
- public function update() {
- $role = $this->get_user_info('role');
- $username = $this->input->post('username',true);
- $client_key = $this->input->post('client_key',true);
- $token = $this->input->post('token',true);
- $type = intval($this->input->post('type',true));
- $lamp_id = $this->input->post('lamp_id',true);
- $lamp_id = $this->input->post('lamp_id', true);
- if (empty($lamp_id)) {
- exit(json_result('0411', $this->response['0411'], array()));
- }
- $ids = explode(',', $lamp_id);
- $list = $this->Lamp_model->get_list(['id'=>$ids],'address');
- $cmd = empty($type) ? '01' : '02';
- foreach ($list as $v) {
- $this->send_cmd('18',$v['address'],$cmd,'0000000000','0100',0);
- }
- sleep(2);
- exit(json_result('0000', $this->response['0406'], array()));
- }
- // 灯控的开启/关闭(支持批量处理)
- public function turnonoff(){
- $username = $this->input->post('username',true);
- $role = $this->input->post('role',true);
- $client_key = $this->input->post('client_key',true);
- $token = $this->input->post('token',true);
- $type = intval($this->input->post('type',true));
- $lamp_id = $this->input->post('lamp_id',true);
- $clientid = $this->input->post('clientid',true);
- $version = $this->session->userdata('version');
- $lampArr = explode(',', $lamp_id);
- $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/dimming_asy';
- $lightness = empty($type) ? 0 : 100;
- foreach ($lampArr as $l) {
- doAsyncRequest($url,['clientid'=>$clientid,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'type'=>$type,'lamp_id'=>$l,'lightness'=>$lightness,'role'=>$role]);
- }
-
- exit();
- }
- // 重启设备
- public function reboot_dev(){
- $username = $this->input->post('username',true);
- $role = $this->input->post('role',true);
- $client_key = $this->input->post('client_key',true);
- $token = $this->input->post('token',true);
- $type = intval($this->input->post('type',true));
- $lamp_id = $this->input->post('lamp_id',true);
- $clientid = $this->input->post('clientid',true);
- $version = $this->session->userdata('version');
- $lampArr = explode(',', $lamp_id);
- $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/reboot_dev_asy';
- foreach ($lampArr as $l) {
- doAsyncRequest($url,['clientid'=>$clientid,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'type'=>$type,'lamp_id'=>$l,'role'=>$role]);
- }
-
- exit();
- }
- public function reboot_dev_asy(){
- $lamp_id = intval($this->input->post('lamp_id',true));
- $clientid = intval($this->input->post('clientid',true));
- if (empty($lamp_id)) {
- $data = ['code'=>'0007','status'=>2,'msg'=>$this->response['0007'],'data'=>['number'=>'','type'=>'reboot_dev_asy','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- }
- $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number,id');
- $this->send_cmd('1f',$lampData['address'],'01','0000000000','0100',0);
- $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'reboot_dev_asy','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- // if (empty($res)) {
- // $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'reboot_dev_asy','id'=>$lamp_id]];
- // exit(send_websocket($clientid,$data));
- // }else{
- // $res['msg'] = unpack('H*', $res['msg'])[1];
- // set_log('dimming_asy.txt',$res['msg']);
- // if (strtolower(crc16(pack('H*',substr($res['msg'], 0,-4)))) == strtolower(substr($res['msg'], -4)) && strtolower(substr($res['msg'], 18,2)) == '01') {
- // $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'reboot_dev_asy','id'=>$lamp_id]];
- // exit(send_websocket($clientid,$data));
- // }else{
- // $data = ['code'=>'0010','status'=>2,'msg'=>$this->response['0010'],'data'=>['number'=>$lampData['number'],'type'=>'reboot_dev_asy','id'=>$lamp_id]];
- // exit(send_websocket($clientid,$data));
- // }
- // }
- }
- // 灯控调光
- public function dimming(){
- $username = $this->input->post('username',true);
- $role = $this->input->post('role',true);
- $client_key = $this->input->post('client_key',true);
- $token = $this->input->post('token',true);
- $lamp_id = $this->input->post('lamp_id',true);
- $lightness = $this->input->post('lightness',true);
- $clientid = $this->input->post('clientid',true);
- $version = $this->session->userdata('version');
- $lampArr = explode(',', $lamp_id);
- // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
- $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/dimming_asy';
-
- foreach ($lampArr as $l) {
- doAsyncRequest($url,['clientid'=>$clientid,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'lamp_id'=>$l,'lightness'=>$lightness,'role'=>$role]);
- }
-
- exit();
- }
- public function dimming_asy(){
- set_time_limit(0);
- $lamp_id = intval($this->input->post('lamp_id',true));
- $lightness = intval($this->input->post('lightness',true));
- $clientid = $this->input->post('clientid',true);
- $version = $this->input->post('version',true);
- if (empty($lamp_id)) {
- exit(json_result('0400', $this->response['0400'], array()));
- }
- $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'number,address,id');
- $seq = get_seq();
- $seq = '01';
- // $sendData = '14'.PROTOCOL_VERSION.$seq.'0000000000';
- $sendData = $lightness > 0 ? '01' : '00';
- $lightness2 = empty($lightness) ? '00' : '00'.base_convert($lightness, 10, 16);
- $sendData .= strlen($lightness2) == 2 ? $lightness2 : substr($lightness2, -2);
- $sendData .= '00';
- // $sendData .= crc16(pack('H*',$sendData));
- // $res = lampMqttCmd('/IDCOL/CmdInput/'.$lampData['address'],'/IDCOL/CmdOutput/'.$lampData['address'],pack('H*',$sendData),10);
- $res = $this->send_cmd('14',$lampData['address'],$sendData);
-
- if (empty($res)) {
- $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'dimming','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- }else{
- $res['msg'] = unpack('H*', $res['msg'])[1];
- set_log('dimming_asy.txt',$res['msg']);
- if (strtolower(crc16(pack('H*',substr($res['msg'], 0,-4)))) == strtolower(substr($res['msg'], -4)) && strtolower(substr($res['msg'], 18,2)) == '01') {
- if ($lightness != 0) {
- $this->Lamp_model->update(array('status'=>1,'lighteness'=>$lightness),array('id'=>$lampData['id']));
- }else{
- $this->Lamp_model->update(array('status'=>0,'lighteness'=>0),array('id'=>$lampData['id']));
- }
- $lampData = $this->Lamp_model->get_project_company(array('L.id'=>$lamp_id),'P.projectname,L.number,L.address');
- $this->add_operation_log('cmd',"\"{$lampData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯调光\"{$lightness}%\"",0);
- $this->add_operation_log('cmd',"Light dimming:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$lampData['projectname']}\".Lighteness:\"{$lightness}%\"",0,1);
- $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'dimming','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- }else{
- $data = ['code'=>'0010','status'=>2,'msg'=>$this->response['0010'],'data'=>['number'=>$lampData['number'],'type'=>'dimming','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- }
- }
- }
- // 删除灯控(支持批量处理)
- public function del(){
- $role = $this->get_user_info('role');
- $lamp_ids = $this->input->post('lamp_ids',true);
- if (empty($lamp_ids)) {
- exit(json_result('0400', $this->response['0400'], array()));
- }
- $ids = explode(",", $lamp_ids);
- // 获取灯控信息
- $dataArr = $this->Lamp_model->get_list(['id'=>$ids]);
- // 修改网络跟项目下灯控数量
- foreach ($dataArr as $data) {
- $temp = array();
- $temp['faultcount'] = $data['isfaulted'] > 0 ? 1 : 0;
- $temp['lampcount'] = 1;
- $temp['projectid'] = $data['projectid'];
- // $this->Network_model->minus_lamp_count($data);
- $this->Project_model->minus_lamp_count($temp);
- // $netData = $this->Network_model->getOne($data['networkid'],'gatewaytype,protocoltype');
- // if ($netData['protocoltype'] == 6) $this->remove_device('00000000'.$data['address']);
- // if (isset($netData) && $netData['gatewaytype'] == 'direct' && !empty($data['networkid'])) {// 直连设备
- // // 删除网络
- // // $this->Zone_model->delOne($data['networkid']);
- // $this->Network_model->delData(array('id'=>$data['networkid']));
- // $cmdstr = '{"cmd_type":"delete_network_cmd","cmd_id":'.$data['networkid'].'}';
- // // send_cmd($cmdstr,0);
- // if (isset($netData['protocoltype']) && $netData['protocoltype'] != 0) {
- // $cmdret = send_cmd($cmdstr,1,0,$netData['protocoltype']);
- // if ($cmdret === false) {
- // sleep(1);
- // $cmdret = send_cmd($cmdstr,1,0,$netData['protocoltype']);
- // }
- // }else{
- // $cmdret = send_cmd($cmdstr,0,0,$netData['protocoltype']);
- // if ($cmdret === false) {
- // sleep(1);
- // $cmdret = send_cmd($cmdstr,0,0,$netData['protocoltype']);
- // }
- // }
- // }
- }
- // 删除灯控告警信息
- $this->Alarm_model->delete(['lampid'=>$ids]);
- foreach ($ids as $v) {
- $lampData = $this->Lamp_model->get_project_company(array('L.id'=>$v),'P.projectname,L.number,L.address');
- $this->add_operation_log('delete',"删除\"{$lampData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯",0);
- $this->add_operation_log('delete',"Delete lamp:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$lampData['projectname']}\"",0,1);
- }
- $this->Lamp_model->delete(['id'=>$ids]);
- $this->RealtimeInfoLog_model->delete(['lampid'=>$ids]);
- exit(json_result('0000', $this->response['0000'], array()));
- }
- // 更新负载设置
- public function modbus_set_load(){
- $data['username'] = $this->input->post('username',true);
- $data['client_key'] = $this->input->post('client_key',true);
- $data['token'] = $this->input->post('token',true);
- $data['lamp_id'] = $this->input->post('lamp_id',true);
- $data['clientid'] = $this->input->post('clientid',true);
- $data['version'] = $this->session->userdata('version');
- $data['role'] = $this->input->post('role',true);
- // $data['light_voltage'] = $this->input->post('light_voltage',true);
- $data['intell_power'] = $this->input->post('intell_power',true);
- $data['light_type'] = $this->input->post('light_type',true);
- $data['load_current'] = $this->input->post('load_current',true);
- $data['first_light_time'] = $this->input->post('first_light_time',true);
- $data['first_light_human_power'] = $this->input->post('first_light_human_power',true);
- $data['first_light_unman_power'] = $this->input->post('first_light_unman_power',true);
- $data['second_light_time'] = $this->input->post('second_light_time',true);
- $data['second_light_human_power'] = $this->input->post('second_light_human_power',true);
- $data['second_light_unman_power'] = $this->input->post('second_light_unman_power',true);
- $data['third_light_time'] = $this->input->post('third_light_time',true);
- $data['third_light_human_power'] = $this->input->post('third_light_human_power',true);
- $data['third_light_unman_power'] = $this->input->post('third_light_unman_power',true);
- $data['fourth_light_time'] = $this->input->post('fourth_light_time',true);
- $data['fourth_light_human_power'] = $this->input->post('fourth_light_human_power',true);
- $data['fourth_light_unman_power'] = $this->input->post('fourth_light_unman_power',true);
- $data['fifth_light_time'] = $this->input->post('fifth_light_time',true);
- $data['fifth_light_human_power'] = $this->input->post('fifth_light_human_power',true);
- $data['fifth_light_unman_power'] = $this->input->post('fifth_light_unman_power',true);
- $data['sixth_light_time'] = $this->input->post('sixth_light_time',true);
- $data['sixth_light_human_power'] = $this->input->post('sixth_light_human_power',true);
- $data['sixth_light_unman_power'] = $this->input->post('sixth_light_unman_power',true);
- $data['seventh_light_time'] = $this->input->post('seventh_light_time',true);
- $data['seventh_light_human_power'] = $this->input->post('seventh_light_human_power',true);
- $data['seventh_light_unman_power'] = $this->input->post('seventh_light_unman_power',true);
- $data['tenth_light_time'] = $this->input->post('tenth_light_time',true);
- $data['tenth_light_human_power'] = $this->input->post('tenth_light_human_power',true);
- $data['tenth_light_unman_power'] = $this->input->post('tenth_light_unman_power',true);
- $data['induction_delay_status'] = $this->input->post('induction_delay_status',true);
- $data['induction_delay'] = $this->input->post('induction_delay',true);
- // foreach ($data as $key => $value) {
- // $data[$key] = urldecode($value);
- // }
- $lampArr = explode(',', $data['lamp_id']);
- // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
- $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/set_load_asy';
- foreach ($lampArr as $l) {
- $data['lamp_id'] = $l;
- var_dump($url);
- doAsyncRequest($url,$data);
- }
- }
- public function set_load_asy(){
- $file = fopen('../upload/test.txt', 'w');
- fwrite($file, 'string');
- fclose($file);
- $clientid = $this->input->post('clientid',true);
- $lampid = $this->input->post('lamp_id',true);
- $data['intell_power'] = $this->input->post('intell_power',true);
- $data['light_type'] = $this->input->post('light_type',true);
- $data['load_current'] = $this->input->post('load_current',true);
- $data['first_light_time'] = $this->input->post('first_light_time',true);
- $data['first_light_human_power'] = $this->input->post('first_light_human_power',true);
- $data['first_light_unman_power'] = $this->input->post('first_light_unman_power',true);
- $data['second_light_time'] = $this->input->post('second_light_time',true);
- $data['second_light_human_power'] = $this->input->post('second_light_human_power',true);
- $data['second_light_unman_power'] = $this->input->post('second_light_unman_power',true);
- $data['third_light_time'] = $this->input->post('third_light_time',true);
- $data['third_light_human_power'] = $this->input->post('third_light_human_power',true);
- $data['third_light_unman_power'] = $this->input->post('third_light_unman_power',true);
- $data['fourth_light_time'] = $this->input->post('fourth_light_time',true);
- $data['fourth_light_human_power'] = $this->input->post('fourth_light_human_power',true);
- $data['fourth_light_unman_power'] = $this->input->post('fourth_light_unman_power',true);
- $data['fifth_light_time'] = $this->input->post('fifth_light_time',true);
- $data['fifth_light_human_power'] = $this->input->post('fifth_light_human_power',true);
- $data['fifth_light_unman_power'] = $this->input->post('fifth_light_unman_power',true);
- $data['sixth_light_time'] = $this->input->post('sixth_light_time',true);
- $data['sixth_light_human_power'] = $this->input->post('sixth_light_human_power',true);
- $data['sixth_light_unman_power'] = $this->input->post('sixth_light_unman_power',true);
- $data['seventh_light_time'] = $this->input->post('seventh_light_time',true);
- $data['seventh_light_human_power'] = $this->input->post('seventh_light_human_power',true);
- $data['seventh_light_unman_power'] = $this->input->post('seventh_light_unman_power',true);
- $data['tenth_light_time'] = $this->input->post('tenth_light_time',true);
- $data['tenth_light_human_power'] = $this->input->post('tenth_light_human_power',true);
- $data['tenth_light_unman_power'] = $this->input->post('tenth_light_unman_power',true);
- $data['induction_delay_status'] = intval($this->input->post('induction_delay_status',true));
- $data['induction_delay'] = $this->input->post('induction_delay',true);
- $sendData = '';
- foreach ($data as $key => $value) {
- $word = '';
- if ($key == 'intell_power' || $key == 'light_type') {
- $word = substr('0'.base_convert($value, 10, 16), -1);
- }elseif (strpos($key,'light_time')) {
- $t = explode(':', $value);
- $m = $t[0]*60+$t[1];
- $m = round($m/10);
- set_log('set_load_asy.txt',$m);
- $word = substr('00'.base_convert($m, 10, 16), -2);
- }elseif ($key == 'load_current') {
- $word = substr('0000'.base_convert(round($value/10), 10, 16), -4);
- }elseif ($key == 'induction_delay') {
- $word = substr('00'.base_convert(round($value/10), 10, 16), -2);
- }else{
- $word = substr('00'.base_convert($value, 10, 16), -2);
- }
- $sendData .= $word;
- }
- set_log('set_load_asy.txt',$sendData);
- $lampData = $this->Lamp_model->getData(array('id'=>$lampid),'projectid,address,number');
- $res = $this->send_cmd('12',$lampData['address'],$sendData);
- if (!empty($res)) {
- $msg = unpack('H*', $res['msg'])[1];
- if (substr($msg, 18,2) == '02') {
- $data = ['code'=>'0010','status'=>2,'msg'=>$this->response['0010'],'data'=>['number'=>$lampData['number'],'type'=>'set_load','id'=>$lampid]];
- exit(send_websocket($clientid,$data));
- }
- $projectData = $this->Project_model->getData(array('id'=>$lampData['projectid']),'projectname');
-
- $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯负载参数");
- $this->add_operation_log('update',"Update the load setting of the street lamp:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$projectData['projectname']}\".",0,1);
- $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'set_load','id'=>$lampid]];
- exit(send_websocket($clientid,$data));
- }else{
- $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'set_load','id'=>$lampid]];
- exit(send_websocket($clientid,$data));
- }
- }
- private function format_date($date){
- return intval(explode(':', $date)[0]) * 3600 + intval(explode(':', $date)[1]) * 60;
- }
- // 更新蓄电池设置
- public function set_battery(){
- $data['username'] = $this->input->post('username',true);
- $data['client_key'] = $this->input->post('client_key',true);
- $data['token'] = $this->input->post('token',true);
- $lamp_id = $this->input->post('lamp_id',true);
- $data['clientid'] = $this->input->post('clientid',true);
- $data['role'] = $this->input->post('role',true);
- $data['version'] = $this->session->userdata('version');
-
- $data['battery_count'] = $this->input->post('battery_count',true); // 电池串数
- $data['system_voltage'] = $this->input->post('system_voltage',true); // 电池电压
- $data['battery_type'] = $this->input->post('battery_type',true); //蓄电池类型
- $data['overvoltage'] = $this->input->post('overvoltage',true) * 1000; // 超压电压
- $data['char_limit_voltage'] = $this->input->post('char_limit_voltage',true) * 1000; // 充电限制电压
- $data['equ_char_voltage'] = $this->input->post('equ_char_voltage',true) * 1000; // 均衡充电电压
- $data['increa_char_voltage'] = $this->input->post('increa_char_voltage',true) * 1000; // 提升充电电压
- $data['float_char_voltage'] = $this->input->post('float_char_voltage',true) * 1000; // 浮充充电电压
- $data['increa_char_return_voltage'] = $this->input->post('increa_char_return_voltage',true) * 1000; // 提升充电返回电压
- $data['over_dischar_return_voltage'] = $this->input->post('over_dischar_return_voltage',true) * 1000; // 过放返回电压
- $data['battery_under_voltage'] = $this->input->post('battery_under_voltage',true) * 1000; // 欠压警告电压 新增
- $data['over_dischar_voltage'] = $this->input->post('over_dischar_voltage',true) * 1000; // 过放电压
- $data['discharge_limit_voltage'] = $this->input->post('discharge_limit_voltage',true) * 1000; // 放电限制电压 新增
- $data['equ_char_time'] = $this->input->post('equ_char_time',true) * 60; // 均衡充电时间
- $data['increa_char_time'] = $this->input->post('increa_char_time',true) * 60; // 提升充电时间
- $data['balan_char_interval'] = $this->input->post('balan_char_interval',true); // 均衡充电间隔
- $data['temper_compen_coeff'] = $this->input->post('temper_compen_coeff',true); // 温度补偿系数
- $data['char_upper_limit_temper'] = $this->input->post('char_upper_limit_temper',true); // 上限温度
- $data['char_lower_limit_temper'] = $this->input->post('char_lower_limit_temper',true); // 下限温度
- $data['reduced_start_voltage'] = $this->input->post('reduced_start_voltage',true) * 1000; // 智能功率起始电压
- $data['reduced_stop_voltage'] = $this->input->post('reduced_stop_voltage',true) * 1000; // 智能功率结束电压
- $data['light_voltage'] = $this->input->post('light_voltage',true); // 光控电压
- $data['light_delay_time'] = $this->input->post('light_delay_time',true); // 光控延时时间
-
- $lampArr = explode(',', $lamp_id);
- // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
- $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/set_battery_asy';
- foreach ($lampArr as $l) {
- $data['lamp_id'] = $l;
- doAsyncRequest($url,$data);
- }
- exit();
- }
- //更新蓄电池设置
- public function set_battery_asy(){
- $clientid = $this->input->post('clientid',true);
- $where['id'] = $this->input->post('lamp_id',true);//路灯id
- $data['system_voltage'] = $this->input->post('system_voltage',true); // 电池电压
- $data['battery_count'] = $this->input->post('battery_count',true); // 电池串数
- $data['battery_type'] = $this->input->post('battery_type',true); //蓄电池类型
- // if ($data['battery_type'] == 1 || $data['battery_type'] == 2) {
-
- // }
- $data['battery_count'] = 1;
- $data['overvoltage'] = $this->input->post('overvoltage',true); // 超压电压
- $data['char_limit_voltage'] = $this->input->post('char_limit_voltage',true); // 充电限制电压
- $data['equ_char_voltage'] = $this->input->post('equ_char_voltage',true); // 均衡充电电压
- $data['increa_char_voltage'] = $this->input->post('increa_char_voltage',true); // 提升充电电压
- $data['float_char_voltage'] = $this->input->post('float_char_voltage',true); // 浮充充电电压
- $data['increa_char_return_voltage'] = $this->input->post('increa_char_return_voltage',true); // 提升充电返回电压
- $data['over_dischar_return_voltage'] = $this->input->post('over_dischar_return_voltage',true); // 过放返回电压
- $data['battery_under_voltage'] = $this->input->post('battery_under_voltage',true); // 欠压警告电压 新增
- $data['over_dischar_voltage'] = $this->input->post('over_dischar_voltage',true); // 过放电压
- $data['discharge_limit_voltage'] = $this->input->post('discharge_limit_voltage',true) * 60; // 放电限制电压 新增
- $data['equ_char_time'] = $this->input->post('equ_char_time',true) * 60; // 均衡充电时间
- $data['increa_char_time'] = $this->input->post('increa_char_time',true) * 60; // 提升充电时间
- $data['balan_char_interval'] = $this->input->post('balan_char_interval',true); // 均衡充电间隔
- $data['temper_compen_coeff'] = $this->input->post('temper_compen_coeff',true); // 温度补偿系数
- $data['char_lower_limit_temper'] = $this->input->post('char_lower_limit_temper',true); // 下限温度
- $data['char_upper_limit_temper'] = $this->input->post('char_upper_limit_temper',true); // 上限温度
- $data['reduced_start_voltage'] = $this->input->post('reduced_start_voltage',true); // 智能功率起始电压
- $data['reduced_stop_voltage'] = $this->input->post('reduced_stop_voltage',true); // 智能功率结束电压
- $data['light_voltage'] = $this->input->post('light_voltage',true); // 光控电压
- $data['light_voltage'] *= 10;
- $data['light_delay_time'] = $this->input->post('light_delay_time',true); // 光控延时时间
- $data['light_delay_time'] = round($data['light_delay_time']/10);
- $lampData = $this->Lamp_model->get_one($where,'projectid,address,number');
- $sendData = '';
- foreach ($data as $k=>$v) {
- if ($k == 'light_voltage' || $k == 'balan_char_interval' || $k == 'temper_compen_coeff' || $k == 'light_delay_time' || $k == 'system_voltage') {
- $word = substr('00'.base_convert($v, 10, 16), -2);
- }elseif ($k == 'char_upper_limit_temper' || $k == 'char_lower_limit_temper') {
- if ($v < 0){
- $word = '1'.substr('00000000'.base_convert(substr('0000'.base_convert(abs($v), 10, 16), -4), 16, 2), -7);
- $word = substr('00'.base_convert($word, 2, 16), -2);
- }else{
- $word = substr('00'.base_convert($v, 10, 16), -2);
- }
- }elseif ($k == 'battery_type' || $k == 'battery_count') {
- $word = substr('0'.base_convert($v, 10, 16), -1);
- }else{
- $word = substr('0000'.base_convert($v, 10, 16), -4);
- }
-
- $sendData .= $word;
- }
- set_log('set_battery_asy.txt',$sendData);
- $res = $this->send_cmd('10',$lampData['address'],$sendData);
-
- if (!empty($res)) {
- $projectData = $this->Project_model->get_one(array('id'=>$lampData['projectid']),'projectname');
-
- $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯蓄电池参数");
- $this->add_operation_log('update',"Update the lamp battery setting:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$projectData['projectname']}\".",0,1);
- $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'set_battery','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- }else{
- $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'set_battery','id'=>$lamp_id]];
- exit(send_websocket($clientid,$data));
- }
- }
- // 添加编辑灯控
- public function save() {
- $role = $this->get_user_info('role');
-
- $where['id'] = $this->input->post('lamp_id',true);
- $data['projectid'] = $this->input->post('project_id',true);
- $data['number'] = $this->input->post('lamp_no',true);
- $data['section'] = $this->input->post('section',true);
- $data['address'] = trim($this->input->post('address',true));
- $data['longitude'] = doubleval($this->input->post('longitude',true));
- $data['latitude'] = doubleval($this->input->post('latitude',true));
-
- if ($data['longitude'] < -180 || $data['longitude'] > 180) exit(json_result('0421',$this->response['0421']));
- if ($data['latitude'] < -90 || $data['latitude'] > 90) exit(json_result('0422',$this->response['0422']));
- $poleheight = $this->input->post('poleheight',true);
- if ($poleheight !== null) {
- $data['poleheight'] = $poleheight;
- }
- $data["polediameter"] = $this->input->post('polediameter',true);
- $data["polematerial"] = $this->input->post('polematerial',true);
- $data["lighttype"] = $this->input->post('lighttype',true);
- $data["lamptype"] = $this->input->post('lamptype',true);
- $data["boardtype"] = $this->input->post('boardtype',true);
- $data["batterytype"] = $this->input->post('batterytype',true);
- $solarpower = $this->input->post('boardpower',true);
- $data["batteryah"] = $this->input->post('batteryah',true);
- $loadpower = $this->input->post('loadpower',true);
- $batteryah = $this->input->post('batteryah',true);
- if(!empty($loadpower)) $data["loadpower"] = $loadpower;
- if(!empty($solarpower)) $data["solarpower"] = $solarpower;
- if(!empty($batteryah)) $data["batteryah"] = $batteryah;
- $wattage = $this->input->post('wattage',true);
- $data["wattage"] = !empty($wattage) ? $wattage : 0;
- $supplier = $this->input->post('supplier',true);
- $data["supplier"] = !empty($supplier) ? $supplier : 0;
- $po = $this->input->post('po',true);
- $data["po"] = !empty($po) ? $po : 0;
- // $manu = $this->input->post('manu',true);
- // $data["manu"] = !empty($manu) ? $manu : 0;
- $protocoltype = $this->input->post('protocoltype',true);
- $data['protocoltype'] = $protocoltype;
- $data['model'] = intval($this->input->post('model',true));
- $data['power'] = intval($this->input->post('power',true));
- $data['customer_ID'] = $this->input->post('customer_ID',true);
- $data['street_light_SN'] = $this->input->post('street_light_SN',true);
- $data['customer_name'] = $this->input->post('customer_name',true);
-
- $loadtype = $this->input->post('loadtype',true);
- if ($loadtype !== null) {
- $data["loadtype"] = intval($loadtype);
- }
- $data["manu"] = $this->get_manu_by_address($data["address"]);
- if (empty($data["manu"])) exit(json_result('0423',$this->response['0423']));
- // $role = $this->get_user_info('role');
- $company = $this->get_user_info('company');
- if ($role != SYSTEM_ADMIN) {
- if ($role == 2) {
- if ($data["manu"] != $company) {
- exit(json_result('0423',$this->response['0423']));
- }
- }elseif ($role == 4) {
- $data["po"] = $company;
- }else{
- exit(json_result('0013',$this->response['0013']));
- }
- }
- // if (!isset($data["manu"])) $data["manu"] = $this->get_manu_by_address($data["address"]);
-
- // 控制器协议类型
- $version = $this->session->userdata('version');
- if (strlen($data['number']) > 6) exit(json_result('0408', $this->response['0408'], array()));
- if (empty($data['projectid'])) exit(json_result('0308', $this->response['0308'], array()));
- if (empty($data['number'])) exit(json_result('0409', $this->response['0409'], array()));
- if (!is_numeric($data['number']) || $data['number'] < 1 || $data['number'] > 999999) exit(json_result('0410', $this->response['0410'], array()));
- if (empty($data['address'])) exit(json_result('0805', $this->response['0805'], array()));
- if (is_float($data['address'])) {
- $data['address'] = strval(intval(ceil($data['address'])));
- }
- $is_true = preg_match('/^[A-Fa-f0-9]+$/', $data['address']);
- if (empty($is_true)) exit(json_result('0414', $this->response['0414'], array()));
- $data = remove_null_params($data);
- if (empty($where['id'])) {
- if ($this->Lamp_model->getDataCount(array('number'=>$data['number'], 'projectid'=>$data['projectid'])) > 0) {
- exit(json_result('0401', $this->response['0401'], array()));
- }
- $fascal_year = $this->input->post('fascal_year',true);
- // if (empty($fascal_year)) $fascal_year = date('Y-m-d');
- if (empty($fascal_year)) $fascal_year = '';
- $data['fascal_year'] = $fascal_year;
- $fascal_year_phase = $this->input->post('fascal_year_phase',true);
- if (empty($fascal_year_phase)) {
- $fascal_year_phase = '';
- // $fascal_year_phase = date('Y');
- // $data['fascal_year_phase'] = $fascal_year_phase.'-'.date('Y',strtotime($fascal_year_phase.' +1 year'));
- }
- $data['fascal_year_phase'] = $fascal_year_phase;
- $date = $this->input->post('date',true);
- if (empty($date)) {
- $date = '';
- }
- $data['date'] = $date;
- $lamp = $this->Lamp_model->get_one(array('address'=>$data['address']),'projectid,number');
- if (!empty($lamp)) {
- $projectid = $lamp['projectid'];
- $number = $lamp['number'];
- $projectname = $this->Project_model->getNameById($projectid);
- if (empty($version)) {
- exit(json_result('0404', "该无线模块地址已被【{$projectname}】项目,【{$number}】编号的灯控使用", array()));
- }else{
- exit(json_result('other', "The wireless module address has been used by \"{$projectname}\" project, and \"{$number}\" serial number", array()));
- }
- }
- $projectData = $this->Project_model->get_one(['id'=>$data['projectid']],'patrolinterval,cityid,projectname');
- if (empty($data['longitude']) && empty($data['latitude']) && !empty($projectData['cityid'])) {
- $globalData = $this->Global_location_model->get_one(['id'=>$projectData['cityid']],'longitude,latitude');
- $data['longitude'] = $globalData['longitude'];
- $data['latitude'] = $globalData['latitude'];
- }
- $createtime = $this->input->post('createtime',true);
- $data['createtime'] = empty($createtime) ? date('Y-m-d H:i:s',time()) : $createtime;
- $lampid = $this->Lamp_model->add($data);
- $this->Project_model->add_lamp_count(array('lampcount'=>1,'faultcount'=>0,'projectid'=>$data['projectid']));
- $lampId = intval($lampid);
- $this->add_operation_log('insert',"在\"{$projectData['projectname']}\"项目里添加编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯",0);
- $this->add_operation_log('insert',"Add lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\"",0,1);
- } else {
- if ($this->Lamp_model->getDataCount(array('number'=>$data['number'], 'projectid'=>$data['projectid']), $where['id']) > 0) {
- exit(json_result('0401', $this->response['0401'], array()));
- }
- $fascal_year = $this->input->post('fascal_year',true);
- if (!empty($fascal_year)) $data['fascal_year'] = $fascal_year;
- $date = $this->input->post('date',true);
- if (!empty($date)) $data['date'] = $date;
- $fascal_year_phase = $this->input->post('fascal_year_phase',true);
- if (!empty($fascal_year_phase)) $data['fascal_year_phase'] = $fascal_year_phase;
- $lamp = $this->Lamp_model->get_one(array('address'=>$data['address'], 'id !='=>$where['id']),'projectid,number');
- if (!empty($lamp)) {
- $projectid = $lamp['projectid'];
- $number = $lamp['number'];
- $projectname = $this->Project_model->getNameById($projectid);
- if (empty($version)) {
- exit(json_result('0404', "该无线模块地址已被【{$projectname}】项目,【{$number}】编号的灯控使用", array()));
- }else{
- exit(json_result('other', "The wireless module address has been used by \"{$projectname}\" project, and \"{$number}\" serial number", array()));
- }
- }
- $old = $this->Lamp_model->get_one($where,'isfaulted,projectid,address,protocoltype');
- if ($old['projectid'] != $data['projectid']) {
- $new['projectid'] = $data['projectid'];
- $new['faultcount'] = $old['isfaulted'] > 0 ? 1 : 0;
- $this->Project_model->add_lamp_count($new);
- $old['faultcount'] = $new['faultcount'];
- $this->Project_model->minus_lamp_count($old);
- }
- // $oldNet = $this->Network_model->getData(array('id'=>$old['networkid']));
- if ($old['address'] != $data['address'] || $protocoltype != $old['protocoltype']) {
- }
- $this->Lamp_model->update($data,$where);
- $projectData = $this->Project_model->getData(array('id'=>$data['projectid']),'projectname');
- $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯信息");
- $this->add_operation_log('update',"Update lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\".",0,1);
- //更新负载设置和蓄电池设置
- if (isset($_POST['workmode'])) {
- $res = $this->load_update();
- if ($res['result'] == 1) {
- $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络里的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯负载参数");
- $this->add_operation_log('update',"Update the load setting of the street lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\".Network name:\"{$networkData['networkname']}\".",1,1);
- }else{
- exit(json_result($res['msg'],$res['msg'],array()));
- }
- }
- if (isset($_POST['capacity'])) {
- $res = $this->battery_update();
- if ($res['result'] == 1) {
- $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络里的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯蓄电池参数");
- $this->add_operation_log('update',"Update the lamp battery setting:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\".Network name:\"{$networkData['networkname']}\".",1,1);
- }else{
- exit(json_result($res['msg'],$res['msg'],array()));
- }
- }
- $lampId = intval($where['id']);
- }
- exit(json_result('0000', $this->response['0000'], array("id" => $lampId)));
- }
- private function format_date_en($date){
- $h = floor($date/60);
- $h = $h >= 10 ? $h : '0'.$h;
- $t = floor($date%60);
- $t = $t >= 10 ? $t : '0'.$t;
- return $h.':'.$t;
- }
- // 新控制器获取默认参数值
- public function get_data(){
- $type = $this->input->post('type',true);
- $type = empty($type) ? 1 : $type;
- $update = array();
- if ($type == 1) { // 负载参数
- $update['intell_power'] = '2';
- $update['light_type'] = '1';
- $update['load_current'] = '900';
- $update['first_light_time'] = '00:30';
- $update['first_light_human_power'] = '50';
- $update['first_light_unman_power'] = '20';
- $update['second_light_time'] = '00:30';
- $update['second_light_human_power'] = '70';
- $update['second_light_unman_power'] = '30';
- $update['third_light_time'] = '02:00';
- $update['third_light_human_power'] = '100';
- $update['third_light_unman_power'] = '50';
- $update['fourth_light_time'] = '00:30';
- $update['fourth_light_human_power'] = '70';
- $update['fourth_light_unman_power'] = '30';
- $update['fifth_light_time'] = '00:30';
- $update['fifth_light_human_power'] = '70';
- $update['fifth_light_unman_power'] = '30';
- $update['sixth_light_time'] = '04:00';
- $update['sixth_light_human_power'] = '30';
- $update['sixth_light_unman_power'] = '10';
- $update['seventh_light_time'] = '00:00';
- $update['seventh_light_human_power'] = '100';
- $update['seventh_light_unman_power'] = '50';
- $update['tenth_light_time'] = '00:00';
- $update['tenth_light_human_power'] = '50';
- $update['tenth_light_unman_power'] = '20';
- $update['induction_delay_status'] = '0';
- $update['induction_delay'] = '10';
- }else{ // 蓄电池参数
- $update['system_voltage'] = 12; // 电池电压
- $update['battery_type'] = 1; //蓄电池类型
- $update['overvoltage'] = 15.5; // 超压电压
- $update['char_limit_voltage'] = 15.0; // 充电限制电压
- $update['equ_char_voltage'] = 14.6; // 均衡充电电压
- $update['increa_char_voltage'] = 14.4; // 提升充电电压
- $update['float_char_voltage'] = 13.8; // 浮充充电电压
- $update['increa_char_return_voltage'] = 13.2; // 提升充电返回电压
- $update['over_dischar_return_voltage'] = 12.6; // 过放返回电压
- $update['battery_under_voltage'] = 12.0; // 欠压警告电压 新增
- $update['over_dischar_voltage'] = 11.1; // 过放电压
- $update['discharge_limit_voltage'] = 10.6; // 放电限制电压 新增
- $update['equ_char_time'] = 120; // 均衡充电时间
- $update['increa_char_time'] = 120; // 提升充电时间
- $update['balan_char_interval'] = 30; // 均衡充电间隔
- $update['temper_compen_coeff'] = 5; // 温度补偿系数
- $update['char_upper_limit_temper'] = 60; // 上限温度
- $update['char_lower_limit_temper'] = -30; // 下限温度
- $update['reduced_start_voltage'] = 11.5; // 智能功率起始电压
- $update['reduced_stop_voltage'] = 10.0; // 智能功率结束电压
- $update['light_voltage'] = 5; // 光控电压
- $update['light_delay_time'] = 20; // 光控延时时间
- }
- exit(json_result('0000',$this->response['0000'],$update));
- }
- // 新控制器获取参数设置
- public function get_load() {
- $lamp_id = $this->input->post('lamp_id', true);
- if (empty($lamp_id)) {
- exit(json_result('0400', $this->response['0400'], array()));
- }
- $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number');
- $res = $this->send_cmd('13',$lampData['address'],'');
-
- if (empty($res)) {
- exit(json_result('0016', $this->response['0016']));
- }else{
- // if (strtolower(crc16(pack('H*',substr($res['msg'], 0,-4)))) == strtolower(substr($res['msg'],-4))) {
- $res['msg'] = unpack('H*', $res['msg'])[1];
- set_log('get_load.txt',$res['msg']);
- $data = array();
- $data['intell_power'] = base_convert(substr($res['msg'], 18,1), 16, 10).''; // 智能功率
- $data['light_type'] = base_convert(substr($res['msg'], 19,1), 16, 10).''; // 灯控模式
- $data['load_current'] = (base_convert(substr($res['msg'], 20,4), 16, 10)*10).''; // 负载电流
- $data['first_light_time'] = base_convert(substr($res['msg'], 24,2), 16, 10).''; // 第一段亮灯时间
- $data['first_light_human_power'] = base_convert(substr($res['msg'], 26,2), 16, 10).''; // 第一段有人功率
- $data['first_light_unman_power'] = base_convert(substr($res['msg'], 28,2), 16, 10).''; // 第一段无人功率
- $data['second_light_time'] = base_convert(substr($res['msg'], 30,2), 16, 10).''; // 第二段亮灯时间
- $data['second_light_human_power'] = base_convert(substr($res['msg'], 32,2), 16, 10).''; // 第二段有人功率
- $data['second_light_unman_power'] = base_convert(substr($res['msg'], 34,2), 16, 10).''; // 第二段无人功率
- $data['third_light_time'] = base_convert(substr($res['msg'], 36,2), 16, 10).''; // 第三段亮灯时间
- $data['third_light_human_power'] = base_convert(substr($res['msg'], 38,2), 16, 10).''; // 第三段有人功率
- $data['third_light_unman_power'] = base_convert(substr($res['msg'], 40,2), 16, 10).''; // 第三段无人功率
- $data['fourth_light_time'] = base_convert(substr($res['msg'], 42,2), 16, 10).''; // 第四段亮灯时间
- $data['fourth_light_human_power'] = base_convert(substr($res['msg'], 44,2), 16, 10).''; // 第四段有人功率
- $data['fourth_light_unman_power'] = base_convert(substr($res['msg'], 46,2), 16, 10).''; // 第四段无人功率
- $data['fifth_light_time'] = base_convert(substr($res['msg'], 48,2), 16, 10).''; // 第五段亮灯时间
- $data['fifth_light_human_power'] = base_convert(substr($res['msg'], 50,2), 16, 10).''; // 第五段有人功率
- $data['fifth_light_unman_power'] = base_convert(substr($res['msg'], 52,2), 16, 10).''; // 第五段无人功率
- $data['sixth_light_time'] = base_convert(substr($res['msg'], 54,2), 16, 10).''; // 第六段亮灯时间
- $data['sixth_light_human_power'] = base_convert(substr($res['msg'], 56,2), 16, 10).''; // 第六段有人功率
- $data['sixth_light_unman_power'] = base_convert(substr($res['msg'], 58,2), 16, 10).''; // 第六段无人功率
- $data['seventh_light_time'] = base_convert(substr($res['msg'], 60,2), 16, 10).''; // 第七段亮灯时间
- $data['seventh_light_human_power'] = base_convert(substr($res['msg'], 62,2), 16, 10).''; // 第七段有人功率
- $data['seventh_light_unman_power'] = base_convert(substr($res['msg'], 64,2), 16, 10).''; // 第七段无人功率
- $data['tenth_light_time'] = base_convert(substr($res['msg'], 66,2), 16, 10).''; // 晨亮时间
- $data['tenth_light_human_power'] = base_convert(substr($res['msg'], 68,2), 16, 10).''; // 晨亮有人功率
- $data['tenth_light_unman_power'] = base_convert(substr($res['msg'], 70,2), 16, 10).''; // 晨亮无人功率
- $induction_delay_status = base_convert(substr($res['msg'], 72,2), 16, 10); // 感应延时开关状态
- $data['induction_delay_status'] = $induction_delay_status > 0 ? '1' : '0';
- $data['induction_delay'] = (base_convert(substr($res['msg'], 74,2), 16, 10) * 10).''; // 感应延时
- // $data['tenth_light_human_power'] = base_convert(substr($res['msg'], 64,2), 16, 10).''; // 晨亮有人功率
- // $data['tenth_light_unman_power'] = base_convert(substr($res['msg'], 68,2), 16, 10).''; // 晨亮无人功率
- // $data['begin_voltage'] = round(base_convert(substr($res['msg'], 146,4), 16, 10)/10,1).''; // 智能功率USER1起始电压
- // $data['end_voltage'] = round(base_convert(substr($res['msg'], 150,4), 16, 10)/10,1).''; // 智能功率USER1终止电压
- // $data['end_current'] = round(base_convert(substr($res['msg'], 158,4), 16, 10)/100,2).''; // 智能功率USER1终止电流
- $res = $data;
- // }else{
- // exit(json_result('0010', $this->response['0010']));
- // }
- }
-
- // $res['load_current'] = number_format($res['load_current'],2);
- // $res['end_current'] = number_format($res['end_current'],2);
- // $res['end_voltage'] = number_format($res['end_voltage'],1);
- // $res['begin_voltage'] = number_format($res['begin_voltage'],1);
- $res['first_light_time'] = $this->format_date_en($res['first_light_time']*10);
- $res['second_light_time'] = $this->format_date_en($res['second_light_time']*10);
- $res['third_light_time'] = $this->format_date_en($res['third_light_time']*10);
- $res['fourth_light_time'] = $this->format_date_en($res['fourth_light_time']*10);
- $res['fifth_light_time'] = $this->format_date_en($res['fifth_light_time']*10);
- $res['sixth_light_time'] = $this->format_date_en($res['sixth_light_time']*10);
- $res['seventh_light_time'] = $this->format_date_en($res['seventh_light_time']*10);
- $res['tenth_light_time'] = $this->format_date_en($res['tenth_light_time']*10);
- // unset($res['id']);
- // unset($res['updatetime']);
- $data = $res;
-
- exit(json_result('0000', $this->response['0000'], $data));
- }
- // 获取蓄电池设置
- public function battery_setting() {
- $lamp_id = $this->input->post('lamp_id', true);
- if (empty($lamp_id)) {
- exit(json_result('0400', $this->response['0400'], array()));
- }
- $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number,projectid');
- $res = $this->send_cmd('11',$lampData['address'],'');
-
- // $lampData = $this->Lamp_model->getData(array('id'=>$lamp_id),'projectid,address,number');
- // var_dump($res);
- if (!empty($res)) {
- $info = unpack('H*', $res['msg'])[1];
- set_log('battery_setting.txt',$info);
- // $info = '91010000a8000100010c113e803c8c390831382f443390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
- $data['system_voltage'] = substr($info, 18,2) == 'ff' ? '0' : base_convert(substr($info, 18,2),16,10); // 电池电压
- $data['battery_count'] = round(base_convert(substr($info, 20,1), 16, 10)); // 电池串数
- $data['battery_type'] = round(base_convert(substr($info, 21,1), 16, 10)); //蓄电池类型
- $data['overvoltage'] = round(base_convert(substr($info, 22,4), 16, 10)/1000,1); // 超压电压
- $data['char_limit_voltage'] = round(base_convert(substr($info, 26,4), 16, 10)/1000,1); // 充电限制电压
- $data['equ_char_voltage'] = round(base_convert(substr($info, 30,4), 16, 10)/1000,1); // 均衡充电电压
-
- $data['increa_char_voltage'] = round(base_convert(substr($info, 34,4), 16, 10)/1000,1); // 提升充电电压
- set_log('battery_setting.txt',substr($info, 34,4));
- $data['float_char_voltage'] = round(base_convert(substr($info, 38,4), 16, 10)/1000,1); // 浮充充电电压
- set_log('battery_setting.txt',substr($info, 38,4));
- $data['increa_char_return_voltage'] = round(base_convert(substr($info, 42,4), 16, 10)/1000,1); // 提升充电返回电压
- $data['over_dischar_return_voltage'] = round(base_convert(substr($info, 46,4), 16, 10)/1000,1); // 过放返回电压
- $data['battery_under_voltage'] = round(base_convert(substr($info, 50,4), 16, 10)/1000,1); // 欠压警告电压 新增
- $data['over_dischar_voltage'] = round(base_convert(substr($info, 54,4), 16, 10)/1000,1); // 过放电压
- $data['discharge_limit_voltage'] = round(base_convert(substr($info, 58,4), 16, 10)/1000,1); // 放电限制电压 新增
- $data['equ_char_time'] = round(base_convert(substr($info, 62,4), 16, 10)); // 均衡充电时间
- $data['increa_char_time'] = round(base_convert(substr($info, 66,4), 16, 10)); // 提升充电时间
- $data['balan_char_interval'] = round(base_convert(substr($info, 70,2), 16, 10)); // 均衡充电间隔
- $data['temper_compen_coeff'] = round(base_convert(substr($info, 72,2), 16, 10)); // 温度补偿系数
- $char_lower_limit_temper = base_convert(substr($info, 74,2), 16, 2); // 下限温度
- if (substr(substr('00000000'.$char_lower_limit_temper, -8), 0,1) == 1) {
- $data['char_lower_limit_temper'] = 0 - base_convert(substr('0000000'.$char_lower_limit_temper, -7), 2, 10);
- }else{
- $data['char_lower_limit_temper'] = round(base_convert($char_lower_limit_temper, 2, 10));
- }
- $char_upper_limit_temper = base_convert(substr($info, 76,2), 16, 2); // 上限温度
- if (substr(substr('00000000'.$char_upper_limit_temper, -8), 0,1) == 1) {
- $data['char_upper_limit_temper'] = 0 - base_convert(substr('0000000'.$char_upper_limit_temper, -7), 2, 10);
- }else{
- $data['char_upper_limit_temper'] = round(base_convert($char_upper_limit_temper, 2, 10));
- }
- $data['reduced_start_voltage'] = round(base_convert(substr($info, 78,4), 16, 10)/1000,1); // 智能功率起始电压
- $data['reduced_stop_voltage'] = round(base_convert(substr($info, 82,4), 16, 10)/1000,1); // 智能功率结束电压
- $data['light_voltage'] = round(base_convert(substr($info, 86,2), 16, 10)/10); // 光控电压
- $data['light_delay_time'] = round(base_convert(substr($info, 88,2), 16, 10)*10); // 光控延时时间
-
- exit(json_result('0000',$this->response['0000'],$data));
- }else{
- exit(json_result('0016',$this->response['0016']));
- }
- }
- // 灯控相关数据
- public function viewloglist() {
- $lamp_id = $this->input->post('lamp_id',true);
- $datatype = $this->input->post('datatype',true);
- if (empty($lamp_id)) {
- exit(json_result('0400', $this->response['0400'], array()));
- }
- if ($datatype == 'lampinfo') {
- $fields = "number,projectid,address,longitude,latitude,section,lamptype,boardtype,batteryah,lamppower,loadpower,devstatus,loadtype,supplier,upazilla,po,manu,protocoltype,updatetime,netstatus as status,power,model,fascal_year,fascal_year_phase,iccid,softwareVersion,customer_ID,street_light_SN,customer_name,date,battvoltage,overtimes,solarpower as boardpower,id,batterytype";
- $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
- if (empty($res)) {
- exit(json_result('0000', $this->response['0006'], array()));
- }
- $version = $this->session->userdata('version');
- if (!empty($version)) {
- $polemaType = ['冷镀锌'=>'Cold galvanizing','热镀锌'=>'Hot galvanizing','不锈钢'=>'Stainless steel'];
- $lightType = ['LED灯'=>'LED lamp','钠灯'=>'Sodium lamp','节能灯'=>'Energy saving light'];
- $lampType = ['太阳能路灯'=>'Solar street lamp','景观灯'=>'Landscape lamp','庭院灯'=>'Garden light'];
- $boardType = ['单晶板'=>'Single crystal plate','多晶板'=>'Polycrystalline plate','非晶板'=>'Amorphous plate'];
- $batteryType = ['铅酸电池'=>'Lead acid battery','锂电池'=>'Lithium battery'];
- if (!preg_match('/^[A-Za-z\s*]+$/', $res['lamptype'])) {
- $res['lamptype'] = empty($lampType[$res['lamptype']]) ? '' : $lampType[$res['lamptype']];
- }
- if (!preg_match('/^[A-Za-z\s*]+$/', $res['boardtype'])) {
- $res['boardtype'] = empty($boardType[$res['boardtype']]) ? '' : $boardType[$res['boardtype']];
- }
- }else{
- $polemaType = ['Cold galvanizing'=>'冷镀锌','Hot galvanizing'=>'热镀锌','Stainless steel'=>'不锈钢'];
- $lightType = ['LED lamp'=>'LED灯','Sodium lamp'=>'钠灯','Energy saving light'=>'节能灯'];
- $lampType = ['Solar street lamp'=>'太阳能路灯','Landscape lamp'=>'景观灯','Garden light'=>'庭院灯'];
- $boardType = ['Single crystal plate'=>'单晶板','Polycrystalline plate'=>'多晶板','Amorphous plate'=>'非晶板'];
- $batteryType = ['Lead acid battery'=>'铅酸电池','Lithium battery'=>'锂电池'];
- if (preg_match('/^[A-Za-z\s*]+$/', $res['lamptype'])) {
- $res['lamptype'] = empty($lampType[$res['lamptype']]) ? '' : $lampType[$res['lamptype']];
- }
- if (preg_match('/^[A-Za-z\s*]+$/', $res['boardtype'])) {
- $res['boardtype'] = empty($boardType[$res['boardtype']]) ? '' : $boardType[$res['boardtype']];
- }
- }
- // if ($res["isfaulted"] == 0) {
- // $res["isfaulted"] = '正常';
- // }else{
-
- // }
- // $alarmData = $this->Alarm_model->get_one_by_filter(array('lampid'=>$lamp_id,'status'=>0),'stralarmtype');
- // $version = $this->session->userdata('version');
- // if (empty($version)) {
- // $res['isfaulted'] = empty($alarmData['stralarmtype']) ? '正常' : $alarmData['stralarmtype'];
- // }else{
- // $res['isfaulted'] = empty($alarmData['stralarmtype']) ? 'Normal' : alarm_translate($alarmData['stralarmtype']);
- // }
-
- $timezone = $this->Project_model->get_timezone_by_projectid($res['projectid']);
- $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
- $projectname = $this->Project_model->get_one(['id'=>$res['projectid']],'projectname');
- $supplier_name = '';
- $model_name = '';
- if (!empty($res['supplier'])) {
- $com = $this->Company_model->get_one(['id'=>$res['supplier']],'name,no');
- if (empty($com['name']) && empty($com['no'])){
- $supplier_name = '';
- }else{
- $supplier_name = empty($com['no']) ? $com['name'] : $com['no'];
- }
- }
- if ($res['model']) {
- $model_info = $this->db->query('select * from model_info where id = '.$res['model'])->row_array();
- if (!empty($model_info) && !empty($model_info['name'])) {
- $model_name = $model_info['name'];
- }
- }
- $data = array(
- "lamp_no" => $res["number"],
- "section" => $res["section"],
- 'status' => $res['status'],
- "updatetime" => $res["updatetime"],
- "address" => $res["address"],
- "loadpower" => $res["loadpower"],
- 'street_light_SN' => $res['street_light_SN'],
- 'customer_ID' => $res['customer_ID'],
- 'customer_name' => $res['customer_name'],
- 'fascal_year' => $res['fascal_year'],
- 'fascal_year_phase' => $res['fascal_year_phase'],
- 'battvoltage' => $res['battvoltage'],
- 'overtimes' => $res['overtimes'],
- 'boardpower' => $res['boardpower'],
- "isfaulted" => $res["devstatus"],
- "id" => $res["id"],
- "project_name" => $this->Project_model->getNameById($res["projectid"]),
- "longitude" => $res["longitude"],
- "latitude" => $res["latitude"],
- // "solarpower" => floatval($res["solarpower"]),
- "lamptype" => $res['lamptype'],
- 'softwareVersion' => $res['softwareVersion'],
-
- "boardtype" => $res['boardtype'],
- "batteryah" => $res["batteryah"],
- 'batterytype' => $res['batterytype'],
- 'protocoltype'=>intval($res['protocoltype']),
- 'supplier'=>intval($res['supplier']),
- 'upazilla'=>intval($res['upazilla']),
- 'po'=>intval($res['po']),
- 'manu'=>intval($res['manu']),
- 'loadtype' => $res['loadtype'],
- 'power' => $res['power'],
- 'model' => $res['model'],
- 'iccid' => $res['iccid'],
- 'projectname' => $projectname['projectname'],
- 'projectid' => $res['projectid'],
- 'date' => $res['date'],
- 'supplier_name' => $supplier_name,
- 'model_name' => $model_name,
- );
- // $msisdn = $this->db->query('select iccid from msisdn where imsi = "'.$res['simid'].'"')->row_array();
- // if (empty($msisdn) || empty($msisdn['iccid'])) {
- // $data['iccid'] = '';
- // }else{
- // $data['iccid'] = $msisdn['iccid'];
- // }
- // if ($res['protocoltype'] != 1 && $res['protocoltype'] != 2) {
- // unset($data['packageSurplus']);
- // unset($data['simid']);
- // }
- // $username = $this->get_user_info('username');
- // if ($username == 'zns') {
- // $data['monthly_can_usage'] = intval($res['monthly_can_usage']);
- // $data['monthly_already_usage'] = round($res['monthly_already_usage'],2);
- // }
- exit(json_result('0000', $this->response['0000'], $data));
- }elseif ($datatype == 'lamp_info_log') {
- $fields = "lighteness,lampvoltage,lampcurrent,lamppower,updatetime,model";
- $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
- $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
- if (!empty($res['model'])) {
- $model = $this->db->query('select name from model_info where id = '.$res['model'])->row_array();
- $res['model'] = empty($model['name']) ? '' : $model['name'];
- }else{
- $res['model'] = '';
- }
- exit(json_result('0000', $this->response['0000'], $res));
- }elseif ($datatype == 'solar_info_log') {
- $fields = "solarvoltage,solarcurrent,boardpower as solarpower,updatetime";
- $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
- $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
- exit(json_result('0000', $this->response['0000'], $res));
- }elseif ($datatype == 'battery_info_log') {
- $fields = "battstatus,batteryvoltage as battvoltage,chargecurrent,lampcurrent as discharcurrent,chargepower,lamppower as dischargepower,batttemper,electrictotal,electricSOC,voltagedaymin,voltagedaymax,daychargemaxpow,daydischarmaxpow,daychargemincurrent,daycharmaxcurrent,daydischargemincurrent,daydischarmaxcurrent,daybattmintemper,daybattmaxtemper,updatetime";
- // $fields = "*";
- $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
- $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
- exit(json_result('0000', $this->response['0000'], $res));
- }elseif ($datatype == 'system_info_log') {
- $fields = "sysvoltage,syscurrent,temper as controlTemper,updatetime,id,number as lampid";
- $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
- $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
- exit(json_result('0000', $this->response['0000'], $res));
- }
- // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log');
- // $table = in_array($datatype, $table_map) ? $datatype : 'system_info_log';
- // $res = $this->Lamp_model->getForInfoLog($lamp_id, $table);
- // $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid');
- // $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
- // if(!$res){
- // exit(json_result('0000', $this->response['0006'], array()));
- // }
- // if ($table == 'battery_info_log') {
- // if (isset($res['daydischargemincurrent'])) {
- // $h = floor($res['daydischargemincurrent']/3600);
- // $h = $h < 10 ? '0'.$h : $h;
- // $i = intval($res['daydischargemincurrent']/60)%60;
- // $i = $i < 10 ? '0'.$i : $i;
- // $res['daydischargemincurrent'] = $h.':'.$i;
- // }
- // if (isset($res['daychargemincurrent'])) {
- // $h = floor($res['daychargemincurrent']/3600);
- // $h = $h < 10 ? '0'.$h : $h;
- // $i = intval($res['daychargemincurrent']/60)%60;
- // $i = $i < 10 ? '0'.$i : $i;
- // $res['daychargemincurrent'] = $h.':'.$i;
- // }
- // }
- // $res["updatetime"] = date_change($res["updatetime"],8,$timezone['value']);
- // exit(json_result('0000', $this->response['0000'], $res));
- }
- // 灯控历史数据
- public function historylist() {
- $lamp_id = $this->input->post('lamp_id',true);
- $datatype = $this->input->post('datatype',true);
- $page = intval($this->input->post('page',true));
- $count = intval($this->input->post('count',true));
- $count = empty($count) ? 16 : $count;
- if (empty($lamp_id)) {
- exit(json_result('0400', $this->response['0400'], array()));
- }
- $date = $this->input->post('date',true);
- $beginDate = '';
- $endDate = '';
- // 按时区修改时间
- $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid,protocoltype');
- $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
- if (!empty($date)) {
- $dateArr = explode('/', $date);
- $beginDate = date('Y-m-d H:i:s',strtotime($dateArr[0]) - 8*3600);
- $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',strtotime($dateArr[1]))) - 8*3600);
- // $beginDate = $dateArr[0];
- // $endDate = $dateArr[1];
- if (strtotime($endDate) - strtotime($beginDate) > 31*24*3600) {
- exit(json_result('0418',$this->response['0418']));
- }
- }else{
- $beginDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 8*3600);
- $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',time())) - 8*3600);
- }
- if($page < 1){
- $page = 1;
- }
-
- $download = intval($this->input->post('download'));
- $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
- if (!empty($download)) {
- if (empty($date)) exit(json_result('0007',$this->response['0007']));
- $dataList = array();
- // 路灯
- // $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'lamp_info_log', null, null,$beginDate,$endDate);
- $lampInfoList = $this->RealtimeInfoLog_model->get_list(['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate], 'loadvoltage as lampvoltage,lighteness,loadcurrent as lampcurrent,loadpower as lamppower,updatetime,loadWorkTimeDay as daychargemincurrent,daydischarmaxpow',$count, ($page-1)*$count, 'updatetime desc,id desc', NUll);
- $temp = array();
- $i = 1;
- if (empty($this->version)) {
- $lampStatusArr = array(0=>'关灯',1=>'开灯');
- $title = array('序号','亮度%','状态','电压(V)','电流(A)','功率(W)','当天放电最大功率(W)','当天亮灯时长(HH:MM)','更新时间');
- $name = '路灯';
- }else{
- $lampStatusArr = array(0=>'off',1=>'on');
- $title = array('Number','Brightness%','Status','Voltage(V)','Current(A)','Power(W)','Maximum discharge power of the day(W)','dayLighting duration(HH:MM)','Update time');
- $name = 'Lamp';
- }
- foreach ($lampInfoList as $k=>$l) {
- $l['lampstatus'] = $l['lighteness'] > 0 ? 1 : 0;
- $temp[$k][] = $i;
- $temp[$k][] = $l['lighteness'];
- $temp[$k][] = $lampStatusArr[$l['lampstatus']];
- $temp[$k][] = $l['lampvoltage'];
- $temp[$k][] = $l['lampcurrent'];
- $temp[$k][] = $l['lamppower'];
- $temp[$k][] = $l['daydischarmaxpow'];
- $h = floor($l['daychargemincurrent'] / 3600);
- $h = $h < 10 ? '0'.$h : $h;
- $m = ceil($l['daychargemincurrent'] % 3600 / 60);
- $m = $m < 10 ? '0'.$m : $m;
- $temp[$k][] = $h.':'.$m;
- $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
- $i ++;
- }
- $title1 = [];
- foreach ($title as $t) {
- $title1[0][] = $t;
- }
- $data = array_merge($title1,$temp);
- $dataList[] = array('name'=>$name,'dataList'=>$data);
- // 蓄电池
- // $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'battery_info_log', null, null,$beginDate,$endDate);
- $fields = 'batvoltage as battvoltage,chgtemper as batttemper,updatetime,DayOverDisChgTimes as overtimes,battstatus,chargestage,voltagedaymin,voltagedaymax,daybattmintemper,daybattmaxtemper';
- $lampInfoList = $this->RealtimeInfoLog_model->get_list($where, $fields,null,null, 'updatetime desc,id desc');
- $temp = array();
- $i = 1;
- if (empty($this->version)) {
- $name = '蓄电池';
- if ($lampData['protocoltype'] == 2) {
- $chargeStageMap = array(0=>'没有充电',1=>'等待',2=>'初始',3=>'MPPT',4=>'恒压',5=>'恒流',6=>'浮充',7=>'均衡',8=>'提升',9=>'涓流',10=>'完成',''=>'未知状态');
- }else{
- $chargeStageMap = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
- }
- $battstatusArr = array(0=>'空闲',1=>'放电',2=>'充电',3=>'一边充电一边放电',''=>'未知状态');
- $unknown = '未知状态';
- $title = array('序号','电池状态','充电阶段','电池电压(V)','当天最低电压(V)','当天最高电压(V)','电池温度(℃)','当天电池最低温度(℃)','当天电池最高温度(℃)','过放次数','更新时间');
- }else{
- $name = 'Battery';
- if ($lampData['protocoltype'] == 2) {
- $chargeStageMap = array(0=>'There is no charge',1=>'wait for',2=>'initial',3=>'MPPT',4=>'Constant voltage',5=>'constant current',6=>'floating charge',7=>'equilibrium',8=>'Promote',9=>'Trickle',10=>'complete',''=>'Unknown state');
- }else{
- $chargeStageMap = 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');
- }
- $battstatusArr = array(0=>'Free',1=>'Discharge',2=>'Charge',3=>'Discharge while charging',''=>'Unknown state');
- $unknown = 'Unknown state';
- $title = array('Serial number','Battery status','Charging stage','Battery voltage(V)','Minimum voltage(V)','Highest voltage(V)','surface temperature(℃)','minimum temperature(℃)','highest temperature(℃)','Over Discharge times','Update time');
- }
- $indexArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
- foreach ($lampInfoList as $k=>$l) {
- $temp[$k][] = $i;
- $temp[$k][] = $battstatusArr[$l['battstatus']];
- if ($lampData['protocoltype'] == 1) {
- $l['chargestage'] = isset($indexArr[intval($l['chargestage'])]) ? $indexArr[intval($l['chargestage'])] : $l['chargestage'];
- }
- $temp[$k][] = $chargeStageMap[$l['chargestage']];
- $temp[$k][] = $l['battvoltage'];
- $temp[$k][] = $l['voltagedaymin'];
- $temp[$k][] = $l['voltagedaymax'];
- $temp[$k][] = $l['batttemper'];
- $temp[$k][] = $l['daybattmintemper'];
- $temp[$k][] = $l['daybattmaxtemper'];
- $temp[$k][] = $l['overtimes'];
- $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
- $i ++;
- }
- $title1 = [];
- foreach ($title as $t) {
- $title1[0][] = $t;
- }
- $data = array_merge($title1,$temp);
- $dataList[] = array('name'=>$name,'dataList'=>$data);
- // 太阳能
- $fields = 'panelvoltage as solarvoltage,updatetime,panelcurrent as solarcurrent,panelpower as solarpower,daychargemaxpow';
- $lampInfoList = $this->RealtimeInfoLog_model->get_list($where, $fields,null,null, 'updatetime desc,id desc');
- // $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'solar_info_log', null, null,$beginDate,$endDate);
- $temp = array();
- $i = 1;
- if (empty($this->version)) {
- $name = '太阳能';
- $title = array('序号','电压(V)','电流(A)','功率(W)','当天充电最大功率(WH)','更新时间');
- }else{
- $name = 'Solar';
- $title = array('Number','Voltage(V)','Current(A)','Power(W)','Maximum Power Charged on the Day(W)','Update time');
- }
- foreach ($lampInfoList as $k=>$l) {
- $temp[$k][] = $i;
- $temp[$k][] = $l['solarvoltage'];
- $temp[$k][] = $l['solarcurrent'];
- $temp[$k][] = $l['solarpower'];
- $temp[$k][] = $l['daychargemaxpow'];
- // $h = floor($l['daydischargemincurrent'] / 3600);
- // $h = $h < 10 ? '0'.$h : $h;
- // $m = ceil($l['daydischargemincurrent'] % 3600 / 60);
- // $m = $m < 10 ? '0'.$m : $m;
- // $temp[$k][] = $h.':'.$m;
- $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
- $i ++;
- }
- $title1 = [];
- foreach ($title as $t) {
- $title1[0][] = $t;
- }
- $data = array_merge($title1,$temp);
- $dataList[] = array('name'=>$name,'dataList'=>$data);
- // 系统
- // $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'system_info_log', null, null,$beginDate,$endDate);
- // $temp = array();
- // $i = 1;
- // if (empty($this->version)) {
- // $name = '系统';
- // $title = array('序号','系统电压(V)','系统电流(A)','控制器温度(℃)','更新时间');
- // }else{
- // $name = 'System';
- // $title = array('Serial number','System voltage(V)','System current(A)','Control temperature(℃)','Update time');
- // }
- // foreach ($lampInfoList as $k=>$l) {
- // $temp[$k][] = $i;
- // $temp[$k][] = $l['sysvoltage'];
- // $temp[$k][] = $l['syscurrent'];
- // $temp[$k][] = $l['temper'];
- // $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
- // $i ++;
- // }
- // $title1 = [];
- // foreach ($title as $t) {
- // $title1[0][] = $t;
- // }
- // $data = array_merge($title1,$temp);
- // $dataList[] = array('name'=>$name,'dataList'=>$data);
- $path = push_excel($dataList,'historyInfoExcel_'.date('Ymd'),1);
- exit(json_result('0000', $this->response['0000'], array('path'=>$path)));
- }
- // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log','electric_info_log','history_info_log');
- $table = !empty($datatype) ? $datatype : 'system_info_log';
- if ($table == 'lamp_info_log') {
- $table = 'realtime_info_log';
- $total = $this->RealtimeInfoLog_model->get_count($where);
- $res = $this->RealtimeInfoLog_model->get_list($where, 'loadvoltage as lampvoltage,lighteness,loadcurrent as lampcurrent,loadpower as lamppower,updatetime,loadWorkTimeDay as daychargemincurrent,daydischarmaxpow',$count, ($page-1)*$count, 'updatetime desc,id desc', NUll);
- // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
- }elseif ($table == 'system_info_log') {
- $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
- $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
- }elseif ($table == 'battery_info_log') {
- $join = [
- // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
- ];
- // $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
- $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
- $fields = 'batvoltage as battvoltage,chgtemper as batttemper,updatetime,DayOverDisChgTimes as overtimes,battstatus,chargestage,voltagedaymin,voltagedaymax,daybattmintemper,daybattmaxtemper';
- $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
- }else{
- $join = [
- // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
- ];
- // $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
- $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
- $fields = 'panelvoltage as solarvoltage,updatetime,panelcurrent as solarcurrent,panelpower as solarpower,daychargemaxpow';
- $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
- // $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
- // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
- }
-
- if(!$res){
- exit(json_result('0000', $this->response['0006'], array()));
- }else{
-
- $arr = [2=>'16',3=>'32',4=>'48',5=>'64'];
- foreach ($res as &$v) {
- if (isset($v['lighteness'])) {
- $v['lampstatus'] = empty($v['lighteness']) ? '0' : '1';
- }
- if (isset($v['daychargemincurrent'])) $v['daychargemincurrent'] = intval($v['daychargemincurrent']);
- // $v['updatetime'] = date_change($v["updatetime"],8,$timezone['value']);
- $v['updatetime'] = set_timezone($v["updatetime"],$timezone['value']);
- if ($lampData['protocoltype'] == 1 && $table == 'battery_info_log') {
- $v['chargestage'] = isset($arr[intval($v['chargestage'])]) ? $arr[intval($v['chargestage'])] : $v['chargestage'];
- }
- if ($table == 'system_info_log') {
- $v['lampid'] = $v['number'];
- }
- }
- }
- $data = array(
- 'total' => ceil($total/$count),
- 'list' => $res
- );
- exit(json_result('0000', $this->response['0000'], $data));
- }
- // 修改路灯位置
- public function change_location(){
- $id = intval($this->input->post('id',true));
- $type = intval($this->input->post('type',true));
- $data['longitude'] = $this->input->post('longitude',true);
- $data['latitude'] = $this->input->post('latitude',true);
- $data['updatetime'] = date('Y-m-d H:i:s',time());
- if (empty($id) || empty($type) || !isset($data['longitude']) || !isset($data['latitude'])) {
- exit(json_result('0007',$this->response['0007'],array()));
- }
- if ($type == 1) {
- $this->Lamp_model->update($data,array('id'=>$id));
- }else{
- $this->Videomonitor_model->update($data,array('id'=>$id));
- }
- exit(json_result('0000',$this->response['0000'],array()));
- }
- // 同步巡检
- public function set_patrol_cmd(){
- $id = intval($this->input->post('id',true));
- if (empty($id)) exit(json_result('0007',$this->response['0007'],array('id'=>$id)));
- $lampData = $this->Lamp_model->getOne($id,'N.status,N.protocoltype,L.address,L.protocoltype as lampprotocoltype,L.number');
- $cmd = '{"cmd_type":"set_sync_patrol_cmd","cmd_id":'.$id.'}';
- $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
- if ($cmdret === false) {
- sleep(1);
- $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
- }
- exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
- }
- // 批量添加
- public function batchInput(){
- set_time_limit(0);
- $userid = $this->get_user_info('id');
- // $idArr = $this->get_section_by_user();
- $role = $this->get_user_info('role');
- $company = $this->get_user_info('company');
- $type = intval($this->input->post('type',true));
- $projectid = intval($this->input->post('projectid',true));
- if (empty($projectid)) exit(json_result('0007',$this->response['0007']));
- if ($type == 1) { // 验证
- $indexArr = ['A'=>'number','B'=>'address','C'=>'section'];
- $data = $this->batch_import($indexArr);
- }else{ // 创建
- $data = $this->input->post('lampData',true);
- if (empty($data)) exit(json_result('0007',$this->response['0007']));
- $data = json_decode($data,true);
- }
- $res = 0;
- $this->db->trans_begin();
- $msg = [];
- $patrol_arr = array();
- foreach ($data as $key => $value) {
- $num = $key+2;
- $value['number'] = trim($value['number']);
- if (!isset($value['number']) || $value['number'] == '') {
- $res = 1;
- if (empty($this->version)) {
- $msg[] = '表格第'.$num.'行,路灯编号不能为空';
- }else{
- $msg[] = 'Table '.$num.' row.Lamp number can not be empty';
- }
- }else{
- if (!is_numeric($value['number']) && ($value['number'] <= 0 || $value['number'] > 999999)) {
- $res = 1;
- if (empty($this->version)) {
- $msg[] = '表格第'.$num.'行,路灯编号为1-999999的数字';
- }else{
- $msg[] = 'Table '.$num.' row.The number of street lamps numbered 1-999999';
- }
- }else{
- if ($this->Lamp_model->getDataCount(array('number'=>$value['number'], 'projectid'=>$projectid)) > 0) {
- $res = 1;
- if (empty($this->version)) {
- $msg[] = '表格第'.$num.'行,路灯编号已经存在';
- }else{
- $msg[] = 'Table '.$num.' row.Light control number already exists';
- }
- }
- }
- }
- $value['address'] = trim($value['address']);
- if (empty($value['address'])) {
- $res = 1;
-
- $msg[] = 'Table '.$num.' row.Address of the wireless module can not be empty';
- }else{
- $status = preg_match('/^[A-Fa-f0-9]+$/', $value['address']);
- if (empty($status)) {
- $res = 1;
- $msg[] = 'Table '.$num.' row.Wireless module address is 16 hexadecimal';
- }else{
- if ($this->Lamp_model->getDataCount(['address'=>$value['address']])) {
- $res = 1;
- $msg[] = 'Table '.$num.' row.Wireless module address already exists';
- }
- $value["manu"] = $this->get_manu_by_address($value["address"]);
- if (empty($value["manu"])) {
- $res = 1;
- $msg[] = 'Table '.$num.' row.Invalid ID';
- }else{
- if ($role != SYSTEM_ADMIN) {
- if ($role == 2) {
- if ($value["manu"] != $company) {
- $res = 1;
- $msg[] = 'Table '.$num.' row.Invalid ID';
- }
- }
- }
- }
-
- }
- }
- $value['section'] = trim($value['section']);
- $value['createtime'] = date('Y-m-d H:i:s',time());
- $value['projectid'] = $projectid;
- if ($type != 1) {
- $this->Lamp_model->add($value);
- $this->Project_model->add_lamp_count(['projectid'=>$projectid]);
- }
- }
- if ($res || $type == 1) {
- $this->db->trans_rollback();
- exit(json_result('0000',$this->response['0000'],['lampData'=>$data,'msg'=>$msg]));
- }else{
- $this->db->trans_commit();
- exit(json_result('0000',$this->response['0000']));
- }
- }
- // 路灯历史数据曲线图
- public function lamp_history_data(){
- $type = intval($this->input->post('type',true));
- $lampId = intval($this->input->post('lampid',true));
- if (empty($lampId)) exit(json_result('0007',$this->response['0007']));
- $dateType = intval($this->input->post('dateType',true));
- $date = $this->input->post('date',true);
- if ($dateType == 0) { // 一天
- $beginDate = date('Y-m-d H:i:s',time()-24*3600);
- $endDate = date('Y-m-d H:i:s',time());
- }elseif ($dateType == 1) { // 三天
- $beginDate = date('Y-m-d H:i:s',time()-24*3600*3);
- $endDate = date('Y-m-d H:i:s',time());
- }elseif ($dateType == 2) { // 七天
- $beginDate = date('Y-m-d H:i:s',time()-24*3600*7);
- $endDate = date('Y-m-d H:i:s',time());
- }elseif ($dateType == 3) { // 十四天
- $beginDate = date('Y-m-d H:i:s',time()-24*3600*14);
- $endDate = date('Y-m-d H:i:s',time());
- }else{ // 选择时间
- if (empty($date)) exit(json_result('0007',$this->response['0007']));
- $res = explode('/', $date);
- if (strtotime($res[1]) - strtotime($res[0]) > 31 * 24 * 3600) {
- exit(json_result('0418',$this->response['0418']));
- }
- $beginDate = $res[0];
- $endDate = date('Y-m-d 23:59:59',strtotime($res[1]));
- // var_dump($endDate);die;
- }
- $sql = "SELECT P.id,P.patrolinterval FROM lampinfo AS L LEFT JOIN project as P on P.id = L.projectid WHERE L.id = {$lampId} limit 1";
- $lampData = $this->db->query($sql)->row_array();
- $timezoneData = $this->Project_model->get_timezone_by_projectid($lampData['id']);
- $timezone = $timezoneData['value'];
- $beginDate = date('Y-m-d H:i:s',strtotime($beginDate) - $timezone * 3600);
- $endDate = date('Y-m-d H:i:s',strtotime($endDate) - $timezone * 3600);
- $data = ['patrolinterval'=>$lampData['patrolinterval']];
- if ($type == 0) { // 路灯
- $sql = 'select LI.loadvoltage as lampvoltage,LI.loadcurrent as lampcurrent,LI.lighteness,LI.loadpower as lamppower,LI.updatetime from realtime_info_log as LI where LI.lampid = '.$lampId.' and LI.updatetime >= "'.$beginDate.'" and LI.updatetime <= "'.$endDate.'"';
- $list = $this->db->query($sql)->result_array();
- $temp = [];
- foreach ($list as $value) {
- $temp['lampvoltage'][] = $value['lampvoltage'];
- $temp['lampcurrent'][] = $value['lampcurrent'];
- $temp['lamppower'][] = $value['lamppower'];
- $temp['lighteness'][] = $value['lighteness'];
- $temp['updatetime'][] = date_change($value['updatetime'],0,$timezone);
- if (!isset($data['maxcurrent'])) {
- $data['maxcurrent'] = $value['lampcurrent'];
- }else{
- $data['maxcurrent'] = $value['lampcurrent'] > $data['maxcurrent'] ? $value['lampcurrent'] : $data['maxcurrent'];
- }
- // if (!isset($data['maxdaychargemincurrent'])) {
- // $data['maxdaychargemincurrent'] = $value['daychargemincurrent'];
- // }else{
- // $data['maxdaychargemincurrent'] = $value['daychargemincurrent'] > $data['maxdaychargemincurrent'] ? $value['daychargemincurrent'] : $data['maxdaychargemincurrent'];
- // }
- if (!isset($data['mincurrent'])) {
- $data['mincurrent'] = $value['lampcurrent'];
- }else{
- $data['mincurrent'] = $value['lampcurrent'] < $data['mincurrent'] ? $value['lampcurrent'] : $data['mincurrent'];
- }
- if (!isset($data['maxvoltage'])) {
- $data['maxvoltage'] = $value['lampvoltage'];
- }else{
- $data['maxvoltage'] = $value['lampvoltage'] > $data['maxvoltage'] ? $value['lampvoltage'] : $data['maxvoltage'];
- }
- if (!isset($data['minvoltage'])) {
- $data['minvoltage'] = $value['lampvoltage'];
- }else{
- $data['minvoltage'] = $value['lampvoltage'] < $data['minvoltage'] ? $value['lampvoltage'] : $data['minvoltage'];
- }
- if (!isset($data['maxpower'])) {
- $data['maxpower'] = $value['lamppower'];
- }else{
- $data['maxpower'] = $value['lamppower'] > $data['maxpower'] ? $value['lamppower'] : $data['maxpower'];
- }
- if (!isset($data['minpower'])) {
- $data['minpower'] = $value['lamppower'];
- }else{
- $data['minpower'] = $value['lamppower'] < $data['minpower'] ? $value['lamppower'] : $data['minpower'];
- }
- if (!isset($data['maxlighteness'])) {
- $data['maxlighteness'] = $value['lighteness'];
- }else{
- $data['maxlighteness'] = $value['lighteness'] > $data['maxlighteness'] ? $value['lighteness'] : $data['maxlighteness'];
- }
- if (!isset($data['minlighteness'])) {
- $data['minlighteness'] = $value['lighteness'];
- }else{
- $data['minlighteness'] = $value['lighteness'] < $data['minlighteness'] ? $value['lighteness'] : $data['minlighteness'];
- }
- // if (isset($data['maxdaychargemincurrent'])) {
- // $h = floor($data['maxdaychargemincurrent'] / 3600);
- // $h = $h < 10 ? '0'.$h : $h;
- // $m = floor($data['maxdaychargemincurrent'] / 3600 % 60);
- // $m = $m < 10 ? '0'.$m : $m;
- // $data['maxdaychargemincurrent'] = $h.':'.$m;
- // }
- }
- $list = $temp;
- }elseif ($type == 1) { // 蓄电池
- $sql = 'select batvoltage as battvoltage,batcurrent as chargecurrent,chgtemper as batttemper,batpower as chargepower,updatetime,battstatus from realtime_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
- $list = $this->db->query($sql)->result_array();
- $temp = [];
- $data['maxcurrent'] = 0;
- $data['mincurrent'] = 0;
- $data['maxpower'] = 0;
- $data['minpower'] = 0;
- foreach ($list as $value) {
- $temp['battvoltage'][] = $value['battvoltage'];
- $temp['updatetime'][] = date_change($value['updatetime'],0,$timezone);
-
- $batterycurrent = $value['chargecurrent'];
- $temp['batterycurrent'][] = $batterycurrent;
-
- $batterypower = $value['chargepower'];
- $temp['batterypower'][] = $batterypower;
- if ($value['battstatus'] == 2) {
- if (!isset($data['maxcurrent'])) {
- $data['maxcurrent'] = $batterycurrent;
- }else{
- $data['maxcurrent'] = $batterycurrent > $data['maxcurrent'] ? $batterycurrent : $data['maxcurrent'];
- }
- if (!isset($data['maxpower'])) {
- $data['maxpower'] = round($batterypower,2);
- }else{
- $data['maxpower'] = $batterypower > $data['maxpower'] ? round($batterypower,2) : round($data['maxpower'],2);
- }
- }elseif ($value['battstatus'] == 1) {
- if (!isset($data['mincurrent'])) {
- $data['mincurrent'] = $batterycurrent;
- }else{
- $data['mincurrent'] = $batterycurrent > $data['mincurrent'] ? $batterycurrent : $data['mincurrent'];
- }
- if (!isset($data['minpower'])) {
- $data['minpower'] = round($batterypower,2);
- }else{
- $data['minpower'] = $batterypower > $data['minpower'] ? round($batterypower,2) : round($data['minpower'],2);
- }
- }else{
- }
-
-
- if (!isset($data['maxvoltage'])) {
- $data['maxvoltage'] = $value['battvoltage'];
- }else{
- $data['maxvoltage'] = $value['battvoltage'] > $data['maxvoltage'] ? $value['battvoltage'] : $data['maxvoltage'];
- }
- if (!isset($data['minvoltage'])) {
- $data['minvoltage'] = $value['battvoltage'];
- }else{
- $data['minvoltage'] = $value['battvoltage'] < $data['minvoltage'] ? $value['battvoltage'] : $data['minvoltage'];
- }
- if (!isset($data['maxbatttemper'])) {
- $data['maxbatttemper'] = $value['batttemper'];
- }else{
- $data['maxbatttemper'] = $value['batttemper'] > $data['maxbatttemper'] ? $value['batttemper'] : $data['maxbatttemper'];
- }
- if (!isset($data['minbatttemper'])) {
- $data['minbatttemper'] = $value['batttemper'];
- }else{
- $data['minbatttemper'] = $value['batttemper'] < $data['minbatttemper'] ? $value['batttemper'] : $data['minbatttemper'];
- }
-
- }
- $list = $temp;
- }elseif ($type == 2) { // 太阳能板
- $sql = 'select SI.panelvoltage as solarvoltage,SI.panelcurrent as solarcurrent,SI.panelpower as solarpower,SI.updatetime from realtime_info_log as SI where SI.lampid = '.$lampId.' and SI.updatetime >= "'.$beginDate.'" and SI.updatetime <= "'.$endDate.'"';
- $list = $this->db->query($sql)->result_array();
- $temp = [];
- foreach ($list as $value) {
- $temp['solarvoltage'][] = $value['solarvoltage'];
- $temp['solarcurrent'][] = $value['solarcurrent'];
- $temp['solarpower'][] = $value['solarpower'];
- $temp['updatetime'][] = date_change($value['updatetime'],0,$timezone);
- if (!isset($data['maxcurrent'])) {
- $data['maxcurrent'] = $value['solarcurrent'];
- }else{
- $data['maxcurrent'] = $value['solarcurrent'] > $data['maxcurrent'] ? $value['solarcurrent'] : $data['maxcurrent'];
- }
- if (!isset($data['mincurrent'])) {
- $data['mincurrent'] = $value['solarcurrent'];
- }else{
- $data['mincurrent'] = $value['solarcurrent'] < $data['mincurrent'] ? $value['solarcurrent'] : $data['mincurrent'];
- }
- if (!isset($data['maxvoltage'])) {
- $data['maxvoltage'] = $value['solarvoltage'];
- }else{
- $data['maxvoltage'] = $value['solarvoltage'] > $data['maxvoltage'] ? $value['solarvoltage'] : $data['maxvoltage'];
- }
- // if (!isset($data['maxdaydischargemincurrent'])) {
- // $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'];
- // }else{
- // $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'] > $data['maxdaydischargemincurrent'] ? $value['daydischargemincurrent'] : $data['maxdaydischargemincurrent'];
- // }
- if (!isset($data['minvoltage'])) {
- $data['minvoltage'] = $value['solarvoltage'];
- }else{
- $data['minvoltage'] = $value['solarvoltage'] < $data['minvoltage'] ? $value['solarvoltage'] : $data['minvoltage'];
- }
- if (!isset($data['maxpower'])) {
- $data['maxpower'] = $value['solarpower'];
- }else{
- $data['maxpower'] = $value['solarpower'] > $data['maxpower'] ? $value['solarpower'] : $data['maxpower'];
- }
- if (!isset($data['minpower'])) {
- $data['minpower'] = $value['solarpower'];
- }else{
- $data['minpower'] = $value['solarpower'] < $data['minpower'] ? $value['solarpower'] : $data['minpower'];
- }
- if (isset($data['maxdaydischargemincurrent'])) {
- $h = floor($data['maxdaydischargemincurrent'] / 3600);
- $h = $h < 10 ? '0'.$h : $h;
- $m = floor($data['maxdaydischargemincurrent'] / 3600 % 60);
- $m = $m < 10 ? '0'.$m : $m;
- $data['maxdaydischargemincurrent'] = $h.':'.$m;
- }
- }
- $list = $temp;
- }else{ // 电量
- $sql = 'select chargeday as daychargeah,dischargeday as daydischarah,updatetime from realtime_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
- $list = $this->db->query($sql)->result_array();
- $temp = [];
- foreach ($list as $value) {
- $temp['daychargeah'][] = $value['daychargeah'];
- $temp['daydischarah'][] = $value['daydischarah'];
- $temp['updatetime'][] = date_change($value['updatetime'],0,$timezone);
- if (!isset($data['maxdaychargeah'])) {
- $data['maxdaychargeah'] = $value['daychargeah'];
- }else{
- $data['maxdaychargeah'] = $value['daychargeah'] > $data['maxdaychargeah'] ? $value['daychargeah'] : $data['maxdaychargeah'];
- }
- if (!isset($data['mindaychargeah'])) {
- $data['mindaychargeah'] = $value['daychargeah'];
- }else{
- $data['mindaychargeah'] = $value['daychargeah'] < $data['mindaychargeah'] ? $value['daychargeah'] : $data['mindaychargeah'];
- }
- if (!isset($data['maxdaydischarah'])) {
- $data['maxdaydischarah'] = $value['daydischarah'];
- }else{
- $data['maxdaydischarah'] = $value['daydischarah'] > $data['maxdaydischarah'] ? $value['daydischarah'] : $data['maxdaydischarah'];
- }
- if (!isset($data['mindaydischarah'])) {
- $data['mindaydischarah'] = $value['daydischarah'];
- }else{
- $data['mindaydischarah'] = $value['daydischarah'] < $data['mindaydischarah'] ? $value['daydischarah'] : $data['mindaydischarah'];
- }
- }
- $list = $temp;
- }
- if (empty($list)) {
- $data['list'] = new StdClass();
- }else{
- $data['list'] = $list;
- }
- exit(json_result('0000',$this->response['0000'],$data));
- }
- }
|