Lampcontrol.php 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. class Lampcontrol extends Base_Controller {
  4. private $chargeStageMap = array(0=>'没有充电',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
  5. public function __construct() {
  6. parent::__construct();
  7. $this->load->model('Company_model');
  8. $this->load->model('Project_model');
  9. $this->load->model('Network_model');
  10. $this->load->model('Lamp_model');
  11. $this->load->model('Batmanage_model');
  12. $this->load->model('Patrol_model');
  13. $this->load->model('Load_model');
  14. $this->load->model('Battery_model');
  15. $this->load->model('Alarm_model');
  16. // $this->load->model('Zone_model');
  17. $this->load->model('Videomonitor_model');
  18. $this->load->model('Modbus_load_model');
  19. $this->load->model('Modbus_battery_model');
  20. $this->load->model('Global_location_model');
  21. $this->load->model('RealtimeInfoLog_model');
  22. }
  23. // 灯控列表
  24. public function get() {
  25. $userid = $this->get_user_info('id');
  26. $role = $this->get_user_info('role');
  27. $company = $this->input->post('company',true);
  28. $project_id = intval($this->input->post('project_id', true));
  29. if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
  30. $fields = $this->input->post('fields', true);
  31. $field1 = $this->input->post('field1', true);
  32. $pid_arr = $project_id;
  33. $timezone = $this->Project_model->get_timezone_by_projectid($project_id);
  34. $filter = 'L.projectid = '.$project_id;
  35. $countWhere = array('projectid = '.$project_id);
  36. $network_id = $this->input->post('network_id', true);
  37. $section = $this->input->post('section', true);
  38. $type = intval($this->input->post('type', true));
  39. $company = intval($this->input->post('company', true));
  40. if (!empty($type) && !empty($company)) {
  41. if ($type == 2) {
  42. $filter .= ' AND L.manu = '.$company;
  43. $countWhere[] = 'manu = '.$company;
  44. }elseif ($type == 3) {
  45. $filter .= ' AND L.supplier = '.$company;
  46. $countWhere[] = 'supplier = '.$company;
  47. }elseif ($type == 4) {
  48. $filter .= ' AND L.po = '.$company;
  49. $countWhere[] = 'po = '.$company;
  50. }else {
  51. $filter .= ' AND P.cityid = '.$company;
  52. }
  53. }
  54. if (!empty($section)) {
  55. $filter .= ' AND L.section = "'.$section.'"';
  56. $countWhere[] = 'section = "'.$section.'"';
  57. }
  58. $offline = $this->input->post('offline', true);
  59. if (!empty($offline)) {
  60. $filter .= ' AND L.netstatus = 0';
  61. $countWhere[] = 'netstatus = 0';
  62. }
  63. $online = $this->input->post('online', true);
  64. if (!empty($online)) {
  65. $filter .= ' AND L.netstatus= 1';
  66. $countWhere[] = 'netstatus = 1';
  67. }
  68. // 分页数据
  69. $page = intval($this->input->post('page',true));
  70. $page = empty($page) ? 1 : $page;
  71. $count = intval($this->input->post('count',true));
  72. $limit = empty($count) ? 10 : $count;
  73. $offset = ($page - 1)*$count;
  74. $keyword = $this->input->post('keyword', true);
  75. if ($keyword !== '' && $keyword !== null) {
  76. $filter .= ' AND (L.number like "%'.$keyword.'%" OR L.section like "%'.$keyword.'%" OR L.address like "%'.$keyword.'%")';
  77. $countWhere[] = '(number like "%'.$keyword.'%" OR section like "%'.$keyword.'%" OR address like "%'.$keyword.'%")';
  78. }
  79. $status = $this->input->post('status', true);
  80. if (!empty($status)) {
  81. // $filter['AI.isfaulted'] = $status;
  82. $filter .= ' AND (AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0)';
  83. }
  84. // $alarmtype = $this->input->post('alarmtype', true);
  85. // if (!empty($alarmtype)) $filter['AI.alarmtype'] = $alarmtype;
  86. // 记录用户选择的字段
  87. if (!empty($field1)) {
  88. $fieldData = array('userid'=>$userid,'lampfield'=>$field1);
  89. $this->User_model->update_user_field($fieldData);
  90. }
  91. $lite = $this->input->post('lite', true);
  92. $version = $this->session->userdata('version');
  93. if ($lite == 1) {
  94. if(empty($fields)){
  95. $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';
  96. }else{
  97. $fields .= ",RI.updatetime";
  98. }
  99. $join = array();
  100. $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'];
  101. $data['lamps'] = $this->Lamp_model->get_list_by_join($filter, $fields,$limit, $offset, $join, "L.number ASC", NUll, 'L');
  102. } else {
  103. if(empty($fields) || empty($field1)){
  104. $fields = 'L.id, L.number, IFNULL(L.status,0) as status, L.isfaulted, L.address, L.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';
  105. }else{
  106. $fields .= ",L.id,L.projectid,L.section,L.loadtype,P.timezone as timezoneid";
  107. }
  108. $download = intval($this->input->post('download',true));
  109. if (!empty($download)) {
  110. $limit = null;
  111. $offset = null;
  112. }
  113. $join = array();
  114. $join[] = ['table'=>'project as P', 'cond'=>'L.projectid = P.id', 'type'=>'left'];
  115. // $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'];
  116. $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'];
  117. $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'];
  118. $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'];
  119. $data['lamps'] = $this->Lamp_model->get_list_by_join($filter, $fields,$limit, $offset, $join, "L.number ASC", NUll, 'L');
  120. // $data['lamps'] = $this->Lamp_model->get_list_in('L.projectid', $pid_arr, $fields, $filter);
  121. // var_dump(microtime());
  122. $indexArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  123. if (empty($version)) {
  124. $chargeStageMap = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
  125. $battstatusArr = array(0=>'空闲',1=>'放电',2=>'充电',3=>'一边充电一边放电',''=>'未知状态');
  126. $unknown = '未知状态';
  127. }else{
  128. $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');
  129. $battstatusArr = array(0=>'Free',1=>'Discharge',2=>'Charge',3=>'Discharge while charging',''=>'Unknown state');
  130. $unknown = 'Unknown state';
  131. }
  132. if (!empty($download)) {
  133. $fieldArr = explode(',', $field1);
  134. $fieldArr[] = 'iccid';
  135. $temp = [];
  136. $i = 1;
  137. foreach ($data['lamps'] as $key => &$value) {
  138. $value['section'] = empty($value['section']) ? '' : $value['section'];
  139. if (isset($value['updatetime']) && $value['updatetime'] == '0000-00-00 00:00:00') {
  140. $value['updatetime'] = null;
  141. }
  142. if (array_key_exists('lamppower',$value)) {
  143. $value['lamppower'] = !empty($value['lamppower']) ? $value['lamppower'] : "0";
  144. }
  145. // 故障信息处理
  146. if (array_key_exists('alarmStatus',$value)) {
  147. if (empty($value['batstatus']) && $value['panelstatus'] && $value['lampstatus'] && $value['tempstatus']) {
  148. if (empty($version)) {
  149. $value['isfaulted'] = '无';
  150. }else{
  151. $value['isfaulted'] = 'Nothing';
  152. }
  153. }else{
  154. $batstatus = $this->config->item('batstatus');
  155. $panelstatus = $this->config->item('panelstatus');
  156. $lampstatus = $this->config->item('lampstatus');
  157. $tempstatus = $this->config->item('tempstatus');
  158. $temp2 = array();
  159. if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
  160. if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
  161. if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
  162. if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
  163. if (!empty($temp2)) {
  164. $value['isfaulted'] = implode(',', $temp2);
  165. }else{
  166. $value['isfaulted'] = 'Nothing';
  167. }
  168. }
  169. }
  170. if (array_key_exists('lampstatus',$value)) {
  171. $value['lampstatus'] = !empty($value['lampstatus']) ? $value['lampstatus'] : "0";
  172. }
  173. if (array_key_exists('electricSOC',$value)) {
  174. $value['electricSOC'] = !empty($value['electricSOC']) ? $value['electricSOC'] : "0";
  175. }
  176. if (array_key_exists('battvoltage',$value)) {
  177. $value['battvoltage'] = !empty($value['battvoltage']) ? $value['battvoltage'] : "0";
  178. }
  179. if (array_key_exists('chargestage',$value)) {
  180. $value['chargestage'] = isset($value['chargestage']) ? $chargeStageMap[$value['chargestage']] : $unknown;
  181. }
  182. if (array_key_exists('battstatus',$value)) {
  183. $value['battstatus'] = isset($value['battstatus']) ? $battstatusArr[$value['battstatus']] : $unknown;
  184. }
  185. if (array_key_exists('overtimes',$value)) {
  186. $value['overtimes'] = !empty($value['overtimes']) ? $value['overtimes'] : 0;
  187. }
  188. if (array_key_exists('solarpower',$value)) {
  189. $value['solarpower'] = !empty($value['solarpower']) ? $value['solarpower'] : 0;
  190. }
  191. if (array_key_exists('iccid',$value)) {
  192. $value['iccid'] = !empty($value['iccid']) ? $value['iccid'] : '';
  193. }
  194. if (array_key_exists('updatetime',$value)) {
  195. $value['updatetime'] = !empty($value['updatetime']) ? $value['updatetime'] : '';
  196. // 通过时区修改时间
  197. if (!empty($value['updatetime'])) {
  198. $timezone = $this->Project_model->get_timezone_by_projectid($value['projectid']);
  199. if ($timezone['value'] != 8) {
  200. $value['updatetime'] = date_change($value['updatetime'],8,$timezone['value']);
  201. }
  202. }
  203. }
  204. // 当前策略
  205. if (array_key_exists('policyid',$value)) {
  206. if (empty($value['policyid'])) {
  207. $value['policyid'] = '';
  208. }else{
  209. $policyData = $this->db->query('select name from policy_info where id = '.$value['policyid'])->row_array();
  210. if (empty($policyData) || empty($policyData['name'])) {
  211. $value['policyid'] = '';
  212. }else{
  213. $value['policyid'] = $policyData['name'];
  214. }
  215. }
  216. }
  217. $temp[$key][] = $i;
  218. foreach ($fieldArr as $f) {
  219. if ($f == 'lampstatus') {
  220. if (empty($version)) {
  221. $temp[$key][] = empty($value[$f]) ? '关灯' : '开灯';
  222. }else{
  223. $temp[$key][] = empty($value[$f]) ? 'off' : 'on';
  224. }
  225. continue;
  226. }
  227. if ($f == 'status') {
  228. if (empty($version)) {
  229. $temp[$key][] = empty($value[$f]) ? '不在线' : '在线';
  230. }else{
  231. $temp[$key][] = empty($value[$f]) ? 'off-line' : 'online';
  232. }
  233. continue;
  234. }
  235. if ($f == 'daychargemincurrent' || $f == 'daydischargemincurrent') {
  236. $t = floor($value[$f]/3600) < 10 ? '0'.floor($value[$f]/3600) : floor($value[$f]/3600);
  237. $m = ceil($value[$f]%3600/60) < 10 ? '0'.ceil($value[$f]%3600/60) : ceil($value[$f]%3600/60);
  238. $temp[$key][] = $t.':'.$m;
  239. continue;
  240. }
  241. $temp[$key][] = $value[$f];
  242. }
  243. $i ++;
  244. }
  245. $title1 = get_fields_by_type($field1,$version);
  246. if (empty($version)) {
  247. $title2 = array_merge(array('编号'),$title1);
  248. }else{
  249. $title2 = array_merge(array('Number'),$title1);
  250. }
  251. $title = [];
  252. foreach ($title2 as $t) {
  253. $title[0][] = $t;
  254. }
  255. $title[0][] = 'iccid';
  256. $data = array_merge($title,$temp);
  257. $path = push_excel($data,'lampinfoExcel_'.date('Ymd'));
  258. exit(json_result('0000', $this->response['0000'], array('path'=>$path)));
  259. }
  260. foreach ($data['lamps'] as $key => &$value) {
  261. $value['section'] = empty($value['section']) ? '' : $value['section'];
  262. if (isset($value['updatetime']) && $value['updatetime'] == '0000-00-00 00:00:00') {
  263. $value['updatetime'] = null;
  264. }
  265. if (array_key_exists('lamppower',$value)) {
  266. $value['lamppower'] = !empty($value['lamppower']) ? $value['lamppower'] : "0";
  267. }
  268. // 故障信息处理
  269. if (array_key_exists('alarmStatus',$value)) {
  270. if (empty($value['batstatus']) && $value['panelstatus'] && $value['lampstatus'] && $value['tempstatus']) {
  271. if (empty($version)) {
  272. $value['isfaulted'] = '无';
  273. }else{
  274. $value['isfaulted'] = 'Nothing';
  275. }
  276. }else{
  277. $batstatus = $this->config->item('batstatus');
  278. $panelstatus = $this->config->item('panelstatus');
  279. $lampstatus = $this->config->item('lampstatus');
  280. $tempstatus = $this->config->item('tempstatus');
  281. $temp2 = array();
  282. if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
  283. if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
  284. if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
  285. if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
  286. if (!empty($temp2)) {
  287. $value['isfaulted'] = implode(',', $temp2);
  288. }else{
  289. $value['isfaulted'] = 'Nothing';
  290. }
  291. }
  292. }
  293. if (array_key_exists('lampstatus',$value)) {
  294. $value['lampstatus'] = !empty($value['lampstatus']) ? $value['lampstatus'] : "0";
  295. }
  296. if (array_key_exists('electricSOC',$value)) {
  297. $value['electricSOC'] = !empty($value['electricSOC']) ? $value['electricSOC'] : "0";
  298. }
  299. if (array_key_exists('battvoltage',$value)) {
  300. $value['battvoltage'] = !empty($value['battvoltage']) ? $value['battvoltage'] : "0";
  301. }
  302. if (array_key_exists('chargestage',$value)) {
  303. $value['chargestage'] = isset($value['chargestage']) && isset($chargeStageMap[$value['chargestage']]) ? $chargeStageMap[$value['chargestage']] : $unknown;
  304. }
  305. if (array_key_exists('battstatus',$value)) {
  306. $value['battstatus'] = isset($value['battstatus']) ? $battstatusArr[$value['battstatus']] : $unknown;
  307. }
  308. if (array_key_exists('overtimes',$value)) {
  309. $value['overtimes'] = !empty($value['overtimes']) ? $value['overtimes'] : 0;
  310. }
  311. if (array_key_exists('solarpower',$value)) {
  312. $value['solarpower'] = !empty($value['solarpower']) ? $value['solarpower'] : 0;
  313. }
  314. // 当前策略
  315. if (array_key_exists('policyid',$value)) {
  316. if (empty($value['policyid'])) {
  317. $value['policyid'] = '';
  318. }else{
  319. $policyData = $this->db->query('select name from policy_info where id = '.$value['policyid'])->row_array();
  320. if (empty($policyData) || empty($policyData['name'])) {
  321. $value['policyid'] = '';
  322. }else{
  323. $value['policyid'] = $policyData['name'];
  324. }
  325. }
  326. }
  327. if (array_key_exists('updatetime',$value)) {
  328. $value['updatetime'] = !empty($value['updatetime']) ? $value['updatetime'] : '';
  329. // 通过时区修改时间
  330. if (!empty($value['updatetime'])) {
  331. // $value['timezoneid'];
  332. if($timezone === null) $timezone = $this->db->query('select value from timezone where id = '.$value['timezoneid'])->row_array();
  333. // var_dump($timezone);die;
  334. $value['updatetime'] = set_timezone($value['updatetime'],$timezone['value']);
  335. // if ($timezone['value'] != 8) {
  336. // $value['updatetime'] = date_change($value['updatetime'],0,$timezone['value']);
  337. // }
  338. }
  339. }
  340. }
  341. if (!empty($project_id)) {
  342. }
  343. }
  344. // unset($filter['page']);
  345. // unset($filter['count']);
  346. $countWheret1 = implode(' AND ', $countWhere);
  347. $data['total_data']['install_num'] = $this->Lamp_model->get_count($countWheret1);
  348. $countWheret = $countWhere;
  349. $countWheret[] = 'lighteness > 0';
  350. $countWheret[] = 'netstatus = 1';
  351. $countWheret1 = implode(' AND ', $countWheret);
  352. $data['total_data']['light_num'] = $this->Lamp_model->get_count($countWheret1);
  353. $countWheret = $countWhere;
  354. $countWheret[] = 'netstatus = 1';
  355. $countWheret1 = implode(' AND ', $countWheret);
  356. $data['total_data']['online_num'] = $this->Lamp_model->get_count($countWheret1);
  357. $filter2 = $filter.' AND (AI.batstatus != 0 OR AI.panelstatus != 0 OR AI.lampstatus != 0 OR AI.tempstatus != 0)';
  358. $join2 = array();
  359. $join2[] = ['table'=>'project as P', 'cond'=>'L.projectid = P.id', 'type'=>'left'];
  360. $join2[] = ['table'=>'(select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as WI','cond'=>'WI.lampid = L.id','type'=>'inner'];
  361. $join2[] = ['table'=>'warning_info_log as AI','cond'=>'WI.lampid = AI.lampid AND WI.maxTime = AI.updatetime','type'=>'inner'];
  362. $res = $this->Lamp_model->get_list_by_multi_join($filter2, 'count(*) total',null, null, $join2, "L.number ASC", NUll, 'L',true);
  363. $data['total_data']['fault_count'] = $res['total'];
  364. $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;
  365. $data['total_data']['light_rate'] .= '%';
  366. $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;
  367. $data['total_data']['online_rate'] .= '%';
  368. $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;
  369. $data['total_data']['fault_rate'] .= '%';
  370. // $data['total_data']['network_num'] = $this->Network_model->get_count(['projectid'=>$project_id,'type'=>1]);
  371. // $res = $this->Lamp_model->get_list_by_multi_join($filter, 'count(*) total',$limit, $offset, $join, "L.number ASC", NUll, 'L',true);
  372. // $result = !empty($pid_arr) ? $this->Lamp_model->get_count(['projectid'=>$pid_arr]) : array();
  373. $result = $this->Lamp_model->get_count(['projectid'=>$pid_arr]);
  374. $data['total'] = $result;
  375. $data['count'] = $result;
  376. // $data['fault'] = $res['total'];
  377. exit(json_result('0000', $this->response['0000'], $data));
  378. }
  379. // 更新灯控信息
  380. public function update() {
  381. $role = $this->get_user_info('role');
  382. $username = $this->input->post('username',true);
  383. $client_key = $this->input->post('client_key',true);
  384. $token = $this->input->post('token',true);
  385. $type = intval($this->input->post('type',true));
  386. $lamp_id = $this->input->post('lamp_id',true);
  387. $lamp_id = $this->input->post('lamp_id', true);
  388. if (empty($lamp_id)) {
  389. exit(json_result('0411', $this->response['0411'], array()));
  390. }
  391. $ids = explode(',', $lamp_id);
  392. $list = $this->Lamp_model->get_list(['id'=>$ids],'address');
  393. $cmd = empty($type) ? '01' : '02';
  394. foreach ($list as $v) {
  395. $this->send_cmd('18',$v['address'],$cmd,'0000000000','0100',0);
  396. }
  397. sleep(2);
  398. exit(json_result('0406', $this->response['0406'], array()));
  399. }
  400. // 灯控的开启/关闭(支持批量处理)
  401. public function turnonoff(){
  402. $username = $this->input->post('username',true);
  403. $role = $this->input->post('role',true);
  404. $client_key = $this->input->post('client_key',true);
  405. $token = $this->input->post('token',true);
  406. $type = intval($this->input->post('type',true));
  407. $lamp_id = $this->input->post('lamp_id',true);
  408. $clientid = $this->input->post('clientid',true);
  409. $version = $this->session->userdata('version');
  410. $lampArr = explode(',', $lamp_id);
  411. $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/dimming_asy';
  412. $lightness = empty($type) ? 0 : 100;
  413. foreach ($lampArr as $l) {
  414. doAsyncRequest($url,['clientid'=>$clientid,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'type'=>$type,'lamp_id'=>$l,'lightness'=>$lightness,'role'=>$role]);
  415. }
  416. exit();
  417. }
  418. // 灯控调光
  419. public function dimming(){
  420. $username = $this->input->post('username',true);
  421. $role = $this->input->post('role',true);
  422. $client_key = $this->input->post('client_key',true);
  423. $token = $this->input->post('token',true);
  424. $lamp_id = $this->input->post('lamp_id',true);
  425. $lightness = $this->input->post('lightness',true);
  426. $clientid = $this->input->post('clientid',true);
  427. $version = $this->session->userdata('version');
  428. $lampArr = explode(',', $lamp_id);
  429. // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
  430. $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/dimming_asy';
  431. foreach ($lampArr as $l) {
  432. doAsyncRequest($url,['clientid'=>$clientid,'username'=>$username,'client_key'=>$client_key,'token'=>$token,'version'=>$version,'lamp_id'=>$l,'lightness'=>$lightness,'role'=>$role]);
  433. }
  434. exit();
  435. }
  436. public function dimming_asy(){
  437. set_time_limit(0);
  438. $lamp_id = intval($this->input->post('lamp_id',true));
  439. $lightness = intval($this->input->post('lightness',true));
  440. $clientid = $this->input->post('clientid',true);
  441. $version = $this->input->post('version',true);
  442. if (empty($lamp_id)) {
  443. exit(json_result('0400', $this->response['0400'], array()));
  444. }
  445. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'number,address,id');
  446. $seq = get_seq();
  447. $seq = '01';
  448. // $sendData = '14'.PROTOCOL_VERSION.$seq.'0000000000';
  449. $sendData = $lightness > 0 ? '01' : '00';
  450. $lightness2 = empty($lightness) ? '00' : '00'.base_convert($lightness, 10, 16);
  451. $sendData .= strlen($lightness2) == 2 ? $lightness2 : substr($lightness2, -2);
  452. $sendData .= '00';
  453. // $sendData .= crc16(pack('H*',$sendData));
  454. // $res = lampMqttCmd('/IDCOL/CmdInput/'.$lampData['address'],'/IDCOL/CmdOutput/'.$lampData['address'],pack('H*',$sendData),10);
  455. $res = $this->send_cmd('14',$lampData['address'],$sendData);
  456. if (empty($res)) {
  457. $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'dimming','id'=>$lamp_id]];
  458. exit(send_websocket($clientid,$data));
  459. }else{
  460. $res['msg'] = unpack('H*', $res['msg'])[1];
  461. set_log('dimming_asy.txt',$res['msg']);
  462. if (strtolower(crc16(pack('H*',substr($res['msg'], 0,-4)))) == strtolower(substr($res['msg'], -4)) && strtolower(substr($res['msg'], 18,2)) == '01') {
  463. if ($lightness != 0) {
  464. $this->Lamp_model->update(array('status'=>1,'lighteness'=>$lightness),array('id'=>$lampData['id']));
  465. }else{
  466. $this->Lamp_model->update(array('status'=>0,'lighteness'=>0),array('id'=>$lampData['id']));
  467. }
  468. $lampData = $this->Lamp_model->get_project_company(array('L.id'=>$lamp_id),'P.projectname,L.number,L.address');
  469. $this->add_operation_log('cmd',"\"{$lampData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯调光\"{$lightness}%\"",0);
  470. $this->add_operation_log('cmd',"Light dimming:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$lampData['projectname']}\".Lighteness:\"{$lightness}%\"",0,1);
  471. $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'dimming','id'=>$lamp_id]];
  472. exit(send_websocket($clientid,$data));
  473. }else{
  474. $data = ['code'=>'0010','status'=>2,'msg'=>$this->response['0010'],'data'=>['number'=>$lampData['number'],'type'=>'dimming','id'=>$lamp_id]];
  475. exit(send_websocket($clientid,$data));
  476. }
  477. }
  478. }
  479. // 删除灯控(支持批量处理)
  480. public function del(){
  481. $role = $this->get_user_info('role');
  482. $lamp_ids = $this->input->post('lamp_ids',true);
  483. if (empty($lamp_ids)) {
  484. exit(json_result('0400', $this->response['0400'], array()));
  485. }
  486. $ids = explode(",", $lamp_ids);
  487. // 获取灯控信息
  488. $dataArr = $this->Lamp_model->get_list(['id'=>$ids]);
  489. // 修改网络跟项目下灯控数量
  490. foreach ($dataArr as $data) {
  491. $temp = array();
  492. $temp['faultcount'] = $data['isfaulted'] > 0 ? 1 : 0;
  493. $temp['lampcount'] = 1;
  494. $temp['projectid'] = $data['projectid'];
  495. // $this->Network_model->minus_lamp_count($data);
  496. $this->Project_model->minus_lamp_count($temp);
  497. // $netData = $this->Network_model->getOne($data['networkid'],'gatewaytype,protocoltype');
  498. // if ($netData['protocoltype'] == 6) $this->remove_device('00000000'.$data['address']);
  499. // if (isset($netData) && $netData['gatewaytype'] == 'direct' && !empty($data['networkid'])) {// 直连设备
  500. // // 删除网络
  501. // // $this->Zone_model->delOne($data['networkid']);
  502. // $this->Network_model->delData(array('id'=>$data['networkid']));
  503. // $cmdstr = '{"cmd_type":"delete_network_cmd","cmd_id":'.$data['networkid'].'}';
  504. // // send_cmd($cmdstr,0);
  505. // if (isset($netData['protocoltype']) && $netData['protocoltype'] != 0) {
  506. // $cmdret = send_cmd($cmdstr,1,0,$netData['protocoltype']);
  507. // if ($cmdret === false) {
  508. // sleep(1);
  509. // $cmdret = send_cmd($cmdstr,1,0,$netData['protocoltype']);
  510. // }
  511. // }else{
  512. // $cmdret = send_cmd($cmdstr,0,0,$netData['protocoltype']);
  513. // if ($cmdret === false) {
  514. // sleep(1);
  515. // $cmdret = send_cmd($cmdstr,0,0,$netData['protocoltype']);
  516. // }
  517. // }
  518. // }
  519. }
  520. // 删除灯控告警信息
  521. $this->Alarm_model->delete(['lampid'=>$ids]);
  522. foreach ($ids as $v) {
  523. $lampData = $this->Lamp_model->get_project_company(array('L.id'=>$v),'P.projectname,L.number,L.address');
  524. $this->add_operation_log('delete',"删除\"{$lampData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯",0);
  525. $this->add_operation_log('delete',"Delete lamp:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$lampData['projectname']}\"",0,1);
  526. }
  527. $this->Lamp_model->delete(['id'=>$ids]);
  528. $this->RealtimeInfoLog_model->delete(['lampid'=>$ids]);
  529. exit(json_result('0000', $this->response['0000'], array()));
  530. }
  531. // 更新负载设置
  532. public function modbus_set_load(){
  533. $data['username'] = $this->input->post('username',true);
  534. $data['client_key'] = $this->input->post('client_key',true);
  535. $data['token'] = $this->input->post('token',true);
  536. $data['lamp_id'] = $this->input->post('lamp_id',true);
  537. $data['clientid'] = $this->input->post('clientid',true);
  538. $data['version'] = $this->session->userdata('version');
  539. $data['role'] = $this->input->post('role',true);
  540. // $data['light_voltage'] = $this->input->post('light_voltage',true);
  541. $data['intell_power'] = $this->input->post('intell_power',true);
  542. $data['light_type'] = $this->input->post('light_type',true);
  543. $data['load_current'] = $this->input->post('load_current',true);
  544. $data['first_light_time'] = $this->input->post('first_light_time',true);
  545. $data['first_light_human_power'] = $this->input->post('first_light_human_power',true);
  546. $data['first_light_unman_power'] = $this->input->post('first_light_unman_power',true);
  547. $data['second_light_time'] = $this->input->post('second_light_time',true);
  548. $data['second_light_human_power'] = $this->input->post('second_light_human_power',true);
  549. $data['second_light_unman_power'] = $this->input->post('second_light_unman_power',true);
  550. $data['third_light_time'] = $this->input->post('third_light_time',true);
  551. $data['third_light_human_power'] = $this->input->post('third_light_human_power',true);
  552. $data['third_light_unman_power'] = $this->input->post('third_light_unman_power',true);
  553. $data['fourth_light_time'] = $this->input->post('fourth_light_time',true);
  554. $data['fourth_light_human_power'] = $this->input->post('fourth_light_human_power',true);
  555. $data['fourth_light_unman_power'] = $this->input->post('fourth_light_unman_power',true);
  556. $data['fifth_light_time'] = $this->input->post('fifth_light_time',true);
  557. $data['fifth_light_human_power'] = $this->input->post('fifth_light_human_power',true);
  558. $data['fifth_light_unman_power'] = $this->input->post('fifth_light_unman_power',true);
  559. $data['sixth_light_time'] = $this->input->post('sixth_light_time',true);
  560. $data['sixth_light_human_power'] = $this->input->post('sixth_light_human_power',true);
  561. $data['sixth_light_unman_power'] = $this->input->post('sixth_light_unman_power',true);
  562. $data['seventh_light_time'] = $this->input->post('seventh_light_time',true);
  563. $data['seventh_light_human_power'] = $this->input->post('seventh_light_human_power',true);
  564. $data['seventh_light_unman_power'] = $this->input->post('seventh_light_unman_power',true);
  565. $data['tenth_light_time'] = $this->input->post('tenth_light_time',true);
  566. $data['tenth_light_human_power'] = $this->input->post('tenth_light_human_power',true);
  567. $data['tenth_light_unman_power'] = $this->input->post('tenth_light_unman_power',true);
  568. $data['induction_delay_status'] = $this->input->post('induction_delay_status',true);
  569. $data['induction_delay'] = $this->input->post('induction_delay',true);
  570. // foreach ($data as $key => $value) {
  571. // $data[$key] = urldecode($value);
  572. // }
  573. $lampArr = explode(',', $data['lamp_id']);
  574. // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
  575. $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/set_load_asy';
  576. foreach ($lampArr as $l) {
  577. $data['lamp_id'] = $l;
  578. var_dump($url);
  579. doAsyncRequest($url,$data);
  580. }
  581. }
  582. public function set_load_asy(){
  583. $file = fopen('../upload/test.txt', 'w');
  584. fwrite($file, 'string');
  585. fclose($file);
  586. $clientid = $this->input->post('clientid',true);
  587. $lampid = $this->input->post('lamp_id',true);
  588. $data['intell_power'] = $this->input->post('intell_power',true);
  589. $data['light_type'] = $this->input->post('light_type',true);
  590. $data['load_current'] = $this->input->post('load_current',true);
  591. $data['first_light_time'] = $this->input->post('first_light_time',true);
  592. $data['first_light_human_power'] = $this->input->post('first_light_human_power',true);
  593. $data['first_light_unman_power'] = $this->input->post('first_light_unman_power',true);
  594. $data['second_light_time'] = $this->input->post('second_light_time',true);
  595. $data['second_light_human_power'] = $this->input->post('second_light_human_power',true);
  596. $data['second_light_unman_power'] = $this->input->post('second_light_unman_power',true);
  597. $data['third_light_time'] = $this->input->post('third_light_time',true);
  598. $data['third_light_human_power'] = $this->input->post('third_light_human_power',true);
  599. $data['third_light_unman_power'] = $this->input->post('third_light_unman_power',true);
  600. $data['fourth_light_time'] = $this->input->post('fourth_light_time',true);
  601. $data['fourth_light_human_power'] = $this->input->post('fourth_light_human_power',true);
  602. $data['fourth_light_unman_power'] = $this->input->post('fourth_light_unman_power',true);
  603. $data['fifth_light_time'] = $this->input->post('fifth_light_time',true);
  604. $data['fifth_light_human_power'] = $this->input->post('fifth_light_human_power',true);
  605. $data['fifth_light_unman_power'] = $this->input->post('fifth_light_unman_power',true);
  606. $data['sixth_light_time'] = $this->input->post('sixth_light_time',true);
  607. $data['sixth_light_human_power'] = $this->input->post('sixth_light_human_power',true);
  608. $data['sixth_light_unman_power'] = $this->input->post('sixth_light_unman_power',true);
  609. $data['seventh_light_time'] = $this->input->post('seventh_light_time',true);
  610. $data['seventh_light_human_power'] = $this->input->post('seventh_light_human_power',true);
  611. $data['seventh_light_unman_power'] = $this->input->post('seventh_light_unman_power',true);
  612. $data['tenth_light_time'] = $this->input->post('tenth_light_time',true);
  613. $data['tenth_light_human_power'] = $this->input->post('tenth_light_human_power',true);
  614. $data['tenth_light_unman_power'] = $this->input->post('tenth_light_unman_power',true);
  615. $data['induction_delay_status'] = intval($this->input->post('induction_delay_status',true));
  616. $data['induction_delay'] = $this->input->post('induction_delay',true);
  617. $sendData = '';
  618. foreach ($data as $key => $value) {
  619. $word = '';
  620. if ($key == 'intell_power' || $key == 'light_type') {
  621. $word = substr('0'.base_convert($value, 10, 16), -1);
  622. }elseif (strpos($key,'light_time')) {
  623. $t = explode(':', $value);
  624. $m = $t[0]*60+$t[1];
  625. $m = round($m/10);
  626. set_log('set_load_asy.txt',$m);
  627. $word = substr('00'.base_convert($m, 10, 16), -2);
  628. }elseif ($key == 'load_current') {
  629. $word = substr('0000'.base_convert(round($value/10), 10, 16), -4);
  630. }elseif ($key == 'induction_delay') {
  631. $word = substr('00'.base_convert(round($value/10), 10, 16), -2);
  632. }else{
  633. $word = substr('00'.base_convert($value, 10, 16), -2);
  634. }
  635. $sendData .= $word;
  636. }
  637. set_log('set_load_asy.txt',$sendData);
  638. $lampData = $this->Lamp_model->getData(array('id'=>$lampid),'projectid,address,number');
  639. $res = $this->send_cmd('12',$lampData['address'],$sendData);
  640. if (!empty($res)) {
  641. $msg = unpack('H*', $res['msg'])[1];
  642. if (substr($msg, 18,2) == '02') {
  643. $data = ['code'=>'0010','status'=>2,'msg'=>$this->response['0010'],'data'=>['number'=>$lampData['number'],'type'=>'set_load','id'=>$lampid]];
  644. exit(send_websocket($clientid,$data));
  645. }
  646. $projectData = $this->Project_model->getData(array('id'=>$lampData['projectid']),'projectname');
  647. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯负载参数");
  648. $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);
  649. $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'set_load','id'=>$lampid]];
  650. exit(send_websocket($clientid,$data));
  651. }else{
  652. $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'set_load','id'=>$lampid]];
  653. exit(send_websocket($clientid,$data));
  654. }
  655. }
  656. private function format_date($date){
  657. return intval(explode(':', $date)[0]) * 3600 + intval(explode(':', $date)[1]) * 60;
  658. }
  659. // 更新蓄电池设置
  660. public function set_battery(){
  661. $data['username'] = $this->input->post('username',true);
  662. $data['client_key'] = $this->input->post('client_key',true);
  663. $data['token'] = $this->input->post('token',true);
  664. $lamp_id = $this->input->post('lamp_id',true);
  665. $data['clientid'] = $this->input->post('clientid',true);
  666. $data['role'] = $this->input->post('role',true);
  667. $data['version'] = $this->session->userdata('version');
  668. $data['battery_count'] = $this->input->post('battery_count',true); // 电池串数
  669. $data['system_voltage'] = $this->input->post('system_voltage',true); // 电池电压
  670. $data['battery_type'] = $this->input->post('battery_type',true); //蓄电池类型
  671. $data['overvoltage'] = $this->input->post('overvoltage',true) * 1000; // 超压电压
  672. $data['char_limit_voltage'] = $this->input->post('char_limit_voltage',true) * 1000; // 充电限制电压
  673. $data['equ_char_voltage'] = $this->input->post('equ_char_voltage',true) * 1000; // 均衡充电电压
  674. $data['increa_char_voltage'] = $this->input->post('increa_char_voltage',true) * 1000; // 提升充电电压
  675. $data['float_char_voltage'] = $this->input->post('float_char_voltage',true) * 1000; // 浮充充电电压
  676. $data['increa_char_return_voltage'] = $this->input->post('increa_char_return_voltage',true) * 1000; // 提升充电返回电压
  677. $data['over_dischar_return_voltage'] = $this->input->post('over_dischar_return_voltage',true) * 1000; // 过放返回电压
  678. $data['battery_under_voltage'] = $this->input->post('battery_under_voltage',true) * 1000; // 欠压警告电压 新增
  679. $data['over_dischar_voltage'] = $this->input->post('over_dischar_voltage',true) * 1000; // 过放电压
  680. $data['discharge_limit_voltage'] = $this->input->post('discharge_limit_voltage',true) * 1000; // 放电限制电压 新增
  681. $data['equ_char_time'] = $this->input->post('equ_char_time',true) * 60; // 均衡充电时间
  682. $data['increa_char_time'] = $this->input->post('increa_char_time',true) * 60; // 提升充电时间
  683. $data['balan_char_interval'] = $this->input->post('balan_char_interval',true); // 均衡充电间隔
  684. $data['temper_compen_coeff'] = $this->input->post('temper_compen_coeff',true); // 温度补偿系数
  685. $data['char_upper_limit_temper'] = $this->input->post('char_upper_limit_temper',true); // 上限温度
  686. $data['char_lower_limit_temper'] = $this->input->post('char_lower_limit_temper',true); // 下限温度
  687. $data['reduced_start_voltage'] = $this->input->post('reduced_start_voltage',true) * 1000; // 智能功率起始电压
  688. $data['reduced_stop_voltage'] = $this->input->post('reduced_stop_voltage',true) * 1000; // 智能功率结束电压
  689. $data['light_voltage'] = $this->input->post('light_voltage',true); // 光控电压
  690. $data['light_delay_time'] = $this->input->post('light_delay_time',true); // 光控延时时间
  691. $lampArr = explode(',', $lamp_id);
  692. // $lampList = $this->Lamp_model->get_list_in('L.id', $lampArr, 'L.id,N.protocoltype', array());
  693. $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'].'/api/lampcontrol/set_battery_asy';
  694. foreach ($lampArr as $l) {
  695. $data['lamp_id'] = $l;
  696. doAsyncRequest($url,$data);
  697. }
  698. exit();
  699. }
  700. //更新蓄电池设置
  701. public function set_battery_asy(){
  702. $clientid = $this->input->post('clientid',true);
  703. $where['id'] = $this->input->post('lamp_id',true);//路灯id
  704. $data['system_voltage'] = $this->input->post('system_voltage',true); // 电池电压
  705. $data['battery_count'] = $this->input->post('battery_count',true); // 电池串数
  706. $data['battery_type'] = $this->input->post('battery_type',true); //蓄电池类型
  707. // if ($data['battery_type'] == 1 || $data['battery_type'] == 2) {
  708. // }
  709. $data['battery_count'] = 1;
  710. $data['overvoltage'] = $this->input->post('overvoltage',true); // 超压电压
  711. $data['char_limit_voltage'] = $this->input->post('char_limit_voltage',true); // 充电限制电压
  712. $data['equ_char_voltage'] = $this->input->post('equ_char_voltage',true); // 均衡充电电压
  713. $data['increa_char_voltage'] = $this->input->post('increa_char_voltage',true); // 提升充电电压
  714. $data['float_char_voltage'] = $this->input->post('float_char_voltage',true); // 浮充充电电压
  715. $data['increa_char_return_voltage'] = $this->input->post('increa_char_return_voltage',true); // 提升充电返回电压
  716. $data['over_dischar_return_voltage'] = $this->input->post('over_dischar_return_voltage',true); // 过放返回电压
  717. $data['battery_under_voltage'] = $this->input->post('battery_under_voltage',true); // 欠压警告电压 新增
  718. $data['over_dischar_voltage'] = $this->input->post('over_dischar_voltage',true); // 过放电压
  719. $data['discharge_limit_voltage'] = $this->input->post('discharge_limit_voltage',true) * 60; // 放电限制电压 新增
  720. $data['equ_char_time'] = $this->input->post('equ_char_time',true) * 60; // 均衡充电时间
  721. $data['increa_char_time'] = $this->input->post('increa_char_time',true) * 60; // 提升充电时间
  722. $data['balan_char_interval'] = $this->input->post('balan_char_interval',true); // 均衡充电间隔
  723. $data['temper_compen_coeff'] = $this->input->post('temper_compen_coeff',true); // 温度补偿系数
  724. $data['char_lower_limit_temper'] = $this->input->post('char_lower_limit_temper',true); // 下限温度
  725. $data['char_upper_limit_temper'] = $this->input->post('char_upper_limit_temper',true); // 上限温度
  726. $data['reduced_start_voltage'] = $this->input->post('reduced_start_voltage',true); // 智能功率起始电压
  727. $data['reduced_stop_voltage'] = $this->input->post('reduced_stop_voltage',true); // 智能功率结束电压
  728. $data['light_voltage'] = $this->input->post('light_voltage',true); // 光控电压
  729. $data['light_voltage'] *= 10;
  730. $data['light_delay_time'] = $this->input->post('light_delay_time',true); // 光控延时时间
  731. $data['light_delay_time'] = round($data['light_delay_time']/10);
  732. $lampData = $this->Lamp_model->get_one($where,'projectid,address,number');
  733. $sendData = '';
  734. foreach ($data as $k=>$v) {
  735. if ($k == 'light_voltage' || $k == 'balan_char_interval' || $k == 'temper_compen_coeff' || $k == 'light_delay_time' || $k == 'system_voltage') {
  736. $word = substr('00'.base_convert($v, 10, 16), -2);
  737. }elseif ($k == 'char_upper_limit_temper' || $k == 'char_lower_limit_temper') {
  738. if ($v < 0){
  739. $word = '1'.substr('00000000'.base_convert(substr('0000'.base_convert(abs($v), 10, 16), -4), 16, 2), -7);
  740. $word = substr('00'.base_convert($word, 2, 16), -2);
  741. }else{
  742. $word = substr('00'.base_convert($v, 10, 16), -2);
  743. }
  744. }elseif ($k == 'battery_type' || $k == 'battery_count') {
  745. $word = substr('0'.base_convert($v, 10, 16), -1);
  746. }else{
  747. $word = substr('0000'.base_convert($v, 10, 16), -4);
  748. }
  749. $sendData .= $word;
  750. }
  751. set_log('set_battery_asy.txt',$sendData);
  752. $res = $this->send_cmd('10',$lampData['address'],$sendData);
  753. if (!empty($res)) {
  754. $projectData = $this->Project_model->get_one(array('id'=>$lampData['projectid']),'projectname');
  755. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$lampData['number']}\"、无线模块地址为\"{$lampData['address']}\"的路灯蓄电池参数");
  756. $this->add_operation_log('update',"Update the lamp battery setting:\"{$lampData['number']}\".Wireless module address:\"{$lampData['address']}\".Project name:\"{$projectData['projectname']}\".",0,1);
  757. $data = ['code'=>'0000','status'=>2,'msg'=>$this->response['0000'],'data'=>['number'=>$lampData['number'],'type'=>'set_battery','id'=>$lamp_id]];
  758. exit(send_websocket($clientid,$data));
  759. }else{
  760. $data = ['code'=>'0016','status'=>2,'msg'=>$this->response['0016'],'data'=>['number'=>$lampData['number'],'type'=>'set_battery','id'=>$lamp_id]];
  761. exit(send_websocket($clientid,$data));
  762. }
  763. }
  764. // 添加编辑灯控
  765. public function save() {
  766. $role = $this->get_user_info('role');
  767. $where['id'] = $this->input->post('lamp_id',true);
  768. $data['projectid'] = $this->input->post('project_id',true);
  769. $data['number'] = $this->input->post('lamp_no',true);
  770. $data['section'] = $this->input->post('section',true);
  771. $data['address'] = trim($this->input->post('address',true));
  772. $data['longitude'] = doubleval($this->input->post('longitude',true));
  773. $data['latitude'] = doubleval($this->input->post('latitude',true));
  774. if ($data['longitude'] < -180 || $data['longitude'] > 180) exit(json_result('0421',$this->response['0421']));
  775. if ($data['latitude'] < -90 || $data['latitude'] > 90) exit(json_result('0422',$this->response['0422']));
  776. $poleheight = $this->input->post('poleheight',true);
  777. if ($poleheight !== null) {
  778. $data['poleheight'] = $poleheight;
  779. }
  780. $data["polediameter"] = $this->input->post('polediameter',true);
  781. $data["polematerial"] = $this->input->post('polematerial',true);
  782. $data["lighttype"] = $this->input->post('lighttype',true);
  783. $data["lamptype"] = $this->input->post('lamptype',true);
  784. $data["boardtype"] = $this->input->post('boardtype',true);
  785. $data["batterytype"] = $this->input->post('batterytype',true);
  786. $data["boardpower"] = $this->input->post('boardpower',true);
  787. $data["batteryah"] = $this->input->post('batteryah',true);
  788. $wattage = $this->input->post('wattage',true);
  789. $data["wattage"] = !empty($wattage) ? $wattage : 0;
  790. $supplier = $this->input->post('supplier',true);
  791. $data["supplier"] = !empty($supplier) ? $supplier : 0;
  792. $po = $this->input->post('po',true);
  793. $data["po"] = !empty($po) ? $po : 0;
  794. // $manu = $this->input->post('manu',true);
  795. // $data["manu"] = !empty($manu) ? $manu : 0;
  796. $protocoltype = $this->input->post('protocoltype',true);
  797. $data['protocoltype'] = $protocoltype;
  798. $data['model'] = intval($this->input->post('model',true));
  799. $data['power'] = intval($this->input->post('power',true));
  800. $loadtype = $this->input->post('loadtype',true);
  801. if ($loadtype !== null) {
  802. $data["loadtype"] = intval($loadtype);
  803. }
  804. $data["manu"] = $this->get_manu_by_address($data["address"]);
  805. $role = $this->get_user_info('role');
  806. $company = $this->get_user_info('company');
  807. if ($role != SYSTEM_ADMIN) {
  808. if ($role == 2) {
  809. if ($data["manu"] != $company) {
  810. exit(json_result('0423',$this->response['0423']));
  811. }
  812. }elseif ($role == 4) {
  813. $data["po"] = $company;
  814. }else{
  815. exit(json_result('0013',$this->response['0013']));
  816. }
  817. }
  818. // if (!isset($data["manu"])) $data["manu"] = $this->get_manu_by_address($data["address"]);
  819. // 控制器协议类型
  820. $version = $this->session->userdata('version');
  821. if (strlen($data['number']) > 6) exit(json_result('0408', $this->response['0408'], array()));
  822. if (empty($data['projectid'])) exit(json_result('0308', $this->response['0308'], array()));
  823. if (empty($data['number'])) exit(json_result('0409', $this->response['0409'], array()));
  824. if (!is_numeric($data['number']) || $data['number'] < 1 || $data['number'] > 999999) exit(json_result('0410', $this->response['0410'], array()));
  825. if (empty($data['address'])) exit(json_result('0805', $this->response['0805'], array()));
  826. if (is_float($data['address'])) {
  827. $data['address'] = strval(intval(ceil($data['address'])));
  828. }
  829. $is_true = preg_match('/^[A-Fa-f0-9]+$/', $data['address']);
  830. if (empty($is_true)) exit(json_result('0414', $this->response['0414'], array()));
  831. $data = remove_null_params($data);
  832. if (empty($where['id'])) {
  833. if ($this->Lamp_model->getDataCount(array('number'=>$data['number'], 'projectid'=>$data['projectid'])) > 0) {
  834. exit(json_result('0401', $this->response['0401'], array()));
  835. }
  836. $fascal_year = $this->input->post('fascal_year',true);
  837. if (empty($fascal_year)) $fascal_year = date('Y-m-d');
  838. $data['fascal_year'] = $fascal_year;
  839. $fascal_year_phase = $this->input->post('fascal_year_phase',true);
  840. if (empty($fascal_year_phase)) {
  841. $fascal_year_phase = date('Y');
  842. $data['fascal_year_phase'] = $fascal_year_phase.'-'.date('Y',strtotime($fascal_year_phase.' +1 year'));
  843. }
  844. $lamp = $this->Lamp_model->get_one(array('address'=>$data['address']),'projectid,number');
  845. if (!empty($lamp)) {
  846. $projectid = $lamp['projectid'];
  847. $number = $lamp['number'];
  848. $projectname = $this->Project_model->getNameById($projectid);
  849. if (empty($version)) {
  850. exit(json_result('0404', "该无线模块地址已被【{$projectname}】项目,【{$number}】编号的灯控使用", array()));
  851. }else{
  852. exit(json_result('other', "The wireless module address has been used by \"{$projectname}\" project, and \"{$number}\" serial number", array()));
  853. }
  854. }
  855. $projectData = $this->Project_model->get_one(['id'=>$data['projectid']],'patrolinterval,cityid,projectname');
  856. if (empty($data['longitude']) && empty($data['latitude']) && !empty($projectData['cityid'])) {
  857. $globalData = $this->Global_location_model->get_one(['id'=>$projectData['cityid']],'longitude,latitude');
  858. $data['longitude'] = $globalData['longitude'];
  859. $data['latitude'] = $globalData['latitude'];
  860. }
  861. $createtime = $this->input->post('createtime',true);
  862. $data['createtime'] = empty($createtime) ? date('Y-m-d H:i:s',time()) : $createtime;
  863. $lampid = $this->Lamp_model->add($data);
  864. $this->Project_model->add_lamp_count(array('lampcount'=>1,'faultcount'=>0,'projectid'=>$data['projectid']));
  865. $lampId = intval($lampid);
  866. $this->add_operation_log('insert',"在\"{$projectData['projectname']}\"项目里添加编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯",0);
  867. $this->add_operation_log('insert',"Add lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\"",0,1);
  868. } else {
  869. if ($this->Lamp_model->getDataCount(array('number'=>$data['number'], 'projectid'=>$data['projectid']), $where['id']) > 0) {
  870. exit(json_result('0401', $this->response['0401'], array()));
  871. }
  872. $fascal_year = $this->input->post('fascal_year',true);
  873. if (!empty($fascal_year)) $data['fascal_year'] = $fascal_year;
  874. $fascal_year_phase = $this->input->post('fascal_year_phase',true);
  875. if (!empty($fascal_year_phase)) $data['fascal_year_phase'] = $fascal_year_phase;
  876. $lamp = $this->Lamp_model->get_one(array('address'=>$data['address'], 'id !='=>$where['id']),'projectid,number');
  877. if (!empty($lamp)) {
  878. $projectid = $lamp['projectid'];
  879. $number = $lamp['number'];
  880. $projectname = $this->Project_model->getNameById($projectid);
  881. if (empty($version)) {
  882. exit(json_result('0404', "该无线模块地址已被【{$projectname}】项目,【{$number}】编号的灯控使用", array()));
  883. }else{
  884. exit(json_result('other', "The wireless module address has been used by \"{$projectname}\" project, and \"{$number}\" serial number", array()));
  885. }
  886. }
  887. $old = $this->Lamp_model->get_one($where,'isfaulted,projectid,address,protocoltype');
  888. if ($old['projectid'] != $data['projectid']) {
  889. $new['projectid'] = $data['projectid'];
  890. $new['faultcount'] = $old['isfaulted'] > 0 ? 1 : 0;
  891. $this->Project_model->add_lamp_count($new);
  892. $old['faultcount'] = $new['faultcount'];
  893. $this->Project_model->minus_lamp_count($old);
  894. }
  895. // $oldNet = $this->Network_model->getData(array('id'=>$old['networkid']));
  896. if ($old['address'] != $data['address'] || $protocoltype != $old['protocoltype']) {
  897. }
  898. $this->Lamp_model->update($data,$where);
  899. $projectData = $this->Project_model->getData(array('id'=>$data['projectid']),'projectname');
  900. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯信息");
  901. $this->add_operation_log('update',"Update lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\".",0,1);
  902. //更新负载设置和蓄电池设置
  903. if (isset($_POST['workmode'])) {
  904. $res = $this->load_update();
  905. if ($res['result'] == 1) {
  906. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络里的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯负载参数");
  907. $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);
  908. }else{
  909. exit(json_result($res['msg'],$res['msg'],array()));
  910. }
  911. }
  912. if (isset($_POST['capacity'])) {
  913. $res = $this->battery_update();
  914. if ($res['result'] == 1) {
  915. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络里的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯蓄电池参数");
  916. $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);
  917. }else{
  918. exit(json_result($res['msg'],$res['msg'],array()));
  919. }
  920. }
  921. $lampId = intval($where['id']);
  922. }
  923. exit(json_result('0000', $this->response['0000'], array("id" => $lampId)));
  924. }
  925. private function format_date_en($date){
  926. $h = floor($date/60);
  927. $h = $h >= 10 ? $h : '0'.$h;
  928. $t = floor($date%60);
  929. $t = $t >= 10 ? $t : '0'.$t;
  930. return $h.':'.$t;
  931. }
  932. // 新控制器获取默认参数值
  933. public function get_data(){
  934. $type = $this->input->post('type',true);
  935. $type = empty($type) ? 1 : $type;
  936. $update = array();
  937. if ($type == 1) { // 负载参数
  938. $update['intell_power'] = '2';
  939. $update['light_type'] = '1';
  940. $update['load_current'] = '900';
  941. $update['first_light_time'] = '00:30';
  942. $update['first_light_human_power'] = '50';
  943. $update['first_light_unman_power'] = '20';
  944. $update['second_light_time'] = '00:30';
  945. $update['second_light_human_power'] = '70';
  946. $update['second_light_unman_power'] = '30';
  947. $update['third_light_time'] = '02:00';
  948. $update['third_light_human_power'] = '100';
  949. $update['third_light_unman_power'] = '50';
  950. $update['fourth_light_time'] = '00:30';
  951. $update['fourth_light_human_power'] = '70';
  952. $update['fourth_light_unman_power'] = '30';
  953. $update['fifth_light_time'] = '00:30';
  954. $update['fifth_light_human_power'] = '70';
  955. $update['fifth_light_unman_power'] = '30';
  956. $update['sixth_light_time'] = '04:00';
  957. $update['sixth_light_human_power'] = '30';
  958. $update['sixth_light_unman_power'] = '10';
  959. $update['seventh_light_time'] = '00:00';
  960. $update['seventh_light_human_power'] = '100';
  961. $update['seventh_light_unman_power'] = '50';
  962. $update['tenth_light_time'] = '00:00';
  963. $update['tenth_light_human_power'] = '50';
  964. $update['tenth_light_unman_power'] = '20';
  965. $update['induction_delay_status'] = '0';
  966. $update['induction_delay'] = '10';
  967. }else{ // 蓄电池参数
  968. $update['system_voltage'] = 12; // 电池电压
  969. $update['battery_type'] = 1; //蓄电池类型
  970. $update['overvoltage'] = 15.5; // 超压电压
  971. $update['char_limit_voltage'] = 15.0; // 充电限制电压
  972. $update['equ_char_voltage'] = 14.6; // 均衡充电电压
  973. $update['increa_char_voltage'] = 14.4; // 提升充电电压
  974. $update['float_char_voltage'] = 13.8; // 浮充充电电压
  975. $update['increa_char_return_voltage'] = 13.2; // 提升充电返回电压
  976. $update['over_dischar_return_voltage'] = 12.6; // 过放返回电压
  977. $update['battery_under_voltage'] = 12.0; // 欠压警告电压 新增
  978. $update['over_dischar_voltage'] = 11.1; // 过放电压
  979. $update['discharge_limit_voltage'] = 10.6; // 放电限制电压 新增
  980. $update['equ_char_time'] = 120; // 均衡充电时间
  981. $update['increa_char_time'] = 120; // 提升充电时间
  982. $update['balan_char_interval'] = 30; // 均衡充电间隔
  983. $update['temper_compen_coeff'] = 5; // 温度补偿系数
  984. $update['char_upper_limit_temper'] = 60; // 上限温度
  985. $update['char_lower_limit_temper'] = -30; // 下限温度
  986. $update['reduced_start_voltage'] = 11.5; // 智能功率起始电压
  987. $update['reduced_stop_voltage'] = 10.0; // 智能功率结束电压
  988. $update['light_voltage'] = 5; // 光控电压
  989. $update['light_delay_time'] = 20; // 光控延时时间
  990. }
  991. exit(json_result('0000',$this->response['0000'],$update));
  992. }
  993. // 新控制器获取参数设置
  994. public function get_load() {
  995. $lamp_id = $this->input->post('lamp_id', true);
  996. if (empty($lamp_id)) {
  997. exit(json_result('0400', $this->response['0400'], array()));
  998. }
  999. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number');
  1000. $res = $this->send_cmd('13',$lampData['address'],'');
  1001. if (empty($res)) {
  1002. exit(json_result('0016', $this->response['0016']));
  1003. }else{
  1004. // if (strtolower(crc16(pack('H*',substr($res['msg'], 0,-4)))) == strtolower(substr($res['msg'],-4))) {
  1005. $res['msg'] = unpack('H*', $res['msg'])[1];
  1006. set_log('get_load.txt',$res['msg']);
  1007. $data = array();
  1008. $data['intell_power'] = base_convert(substr($res['msg'], 18,1), 16, 10).''; // 智能功率
  1009. $data['light_type'] = base_convert(substr($res['msg'], 19,1), 16, 10).''; // 灯控模式
  1010. $data['load_current'] = (base_convert(substr($res['msg'], 20,4), 16, 10)*10).''; // 负载电流
  1011. $data['first_light_time'] = base_convert(substr($res['msg'], 24,2), 16, 10).''; // 第一段亮灯时间
  1012. $data['first_light_human_power'] = base_convert(substr($res['msg'], 26,2), 16, 10).''; // 第一段有人功率
  1013. $data['first_light_unman_power'] = base_convert(substr($res['msg'], 28,2), 16, 10).''; // 第一段无人功率
  1014. $data['second_light_time'] = base_convert(substr($res['msg'], 30,2), 16, 10).''; // 第二段亮灯时间
  1015. $data['second_light_human_power'] = base_convert(substr($res['msg'], 32,2), 16, 10).''; // 第二段有人功率
  1016. $data['second_light_unman_power'] = base_convert(substr($res['msg'], 34,2), 16, 10).''; // 第二段无人功率
  1017. $data['third_light_time'] = base_convert(substr($res['msg'], 36,2), 16, 10).''; // 第三段亮灯时间
  1018. $data['third_light_human_power'] = base_convert(substr($res['msg'], 38,2), 16, 10).''; // 第三段有人功率
  1019. $data['third_light_unman_power'] = base_convert(substr($res['msg'], 40,2), 16, 10).''; // 第三段无人功率
  1020. $data['fourth_light_time'] = base_convert(substr($res['msg'], 42,2), 16, 10).''; // 第四段亮灯时间
  1021. $data['fourth_light_human_power'] = base_convert(substr($res['msg'], 44,2), 16, 10).''; // 第四段有人功率
  1022. $data['fourth_light_unman_power'] = base_convert(substr($res['msg'], 46,2), 16, 10).''; // 第四段无人功率
  1023. $data['fifth_light_time'] = base_convert(substr($res['msg'], 48,2), 16, 10).''; // 第五段亮灯时间
  1024. $data['fifth_light_human_power'] = base_convert(substr($res['msg'], 50,2), 16, 10).''; // 第五段有人功率
  1025. $data['fifth_light_unman_power'] = base_convert(substr($res['msg'], 52,2), 16, 10).''; // 第五段无人功率
  1026. $data['sixth_light_time'] = base_convert(substr($res['msg'], 54,2), 16, 10).''; // 第六段亮灯时间
  1027. $data['sixth_light_human_power'] = base_convert(substr($res['msg'], 56,2), 16, 10).''; // 第六段有人功率
  1028. $data['sixth_light_unman_power'] = base_convert(substr($res['msg'], 58,2), 16, 10).''; // 第六段无人功率
  1029. $data['seventh_light_time'] = base_convert(substr($res['msg'], 60,2), 16, 10).''; // 第七段亮灯时间
  1030. $data['seventh_light_human_power'] = base_convert(substr($res['msg'], 62,2), 16, 10).''; // 第七段有人功率
  1031. $data['seventh_light_unman_power'] = base_convert(substr($res['msg'], 64,2), 16, 10).''; // 第七段无人功率
  1032. $data['tenth_light_time'] = base_convert(substr($res['msg'], 66,2), 16, 10).''; // 晨亮时间
  1033. $data['tenth_light_human_power'] = base_convert(substr($res['msg'], 68,2), 16, 10).''; // 晨亮有人功率
  1034. $data['tenth_light_unman_power'] = base_convert(substr($res['msg'], 70,2), 16, 10).''; // 晨亮无人功率
  1035. $induction_delay_status = base_convert(substr($res['msg'], 72,2), 16, 10); // 感应延时开关状态
  1036. $data['induction_delay_status'] = $induction_delay_status > 0 ? '1' : '0';
  1037. $data['induction_delay'] = (base_convert(substr($res['msg'], 74,2), 16, 10) * 10).''; // 感应延时
  1038. // $data['tenth_light_human_power'] = base_convert(substr($res['msg'], 64,2), 16, 10).''; // 晨亮有人功率
  1039. // $data['tenth_light_unman_power'] = base_convert(substr($res['msg'], 68,2), 16, 10).''; // 晨亮无人功率
  1040. // $data['begin_voltage'] = round(base_convert(substr($res['msg'], 146,4), 16, 10)/10,1).''; // 智能功率USER1起始电压
  1041. // $data['end_voltage'] = round(base_convert(substr($res['msg'], 150,4), 16, 10)/10,1).''; // 智能功率USER1终止电压
  1042. // $data['end_current'] = round(base_convert(substr($res['msg'], 158,4), 16, 10)/100,2).''; // 智能功率USER1终止电流
  1043. $res = $data;
  1044. // }else{
  1045. // exit(json_result('0010', $this->response['0010']));
  1046. // }
  1047. }
  1048. // $res['load_current'] = number_format($res['load_current'],2);
  1049. // $res['end_current'] = number_format($res['end_current'],2);
  1050. // $res['end_voltage'] = number_format($res['end_voltage'],1);
  1051. // $res['begin_voltage'] = number_format($res['begin_voltage'],1);
  1052. $res['first_light_time'] = $this->format_date_en($res['first_light_time']*10);
  1053. $res['second_light_time'] = $this->format_date_en($res['second_light_time']*10);
  1054. $res['third_light_time'] = $this->format_date_en($res['third_light_time']*10);
  1055. $res['fourth_light_time'] = $this->format_date_en($res['fourth_light_time']*10);
  1056. $res['fifth_light_time'] = $this->format_date_en($res['fifth_light_time']*10);
  1057. $res['sixth_light_time'] = $this->format_date_en($res['sixth_light_time']*10);
  1058. $res['seventh_light_time'] = $this->format_date_en($res['seventh_light_time']*10);
  1059. $res['tenth_light_time'] = $this->format_date_en($res['tenth_light_time']*10);
  1060. // unset($res['id']);
  1061. // unset($res['updatetime']);
  1062. $data = $res;
  1063. exit(json_result('0000', $this->response['0000'], $data));
  1064. }
  1065. // 获取蓄电池设置
  1066. public function battery_setting() {
  1067. $lamp_id = $this->input->post('lamp_id', true);
  1068. if (empty($lamp_id)) {
  1069. exit(json_result('0400', $this->response['0400'], array()));
  1070. }
  1071. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number,projectid');
  1072. $res = $this->send_cmd('11',$lampData['address'],'');
  1073. // $lampData = $this->Lamp_model->getData(array('id'=>$lamp_id),'projectid,address,number');
  1074. // var_dump($res);
  1075. if (!empty($res)) {
  1076. $info = unpack('H*', $res['msg'])[1];
  1077. set_log('battery_setting.txt',$info);
  1078. // $info = '91010000a8000100010c113e803c8c390831382f443390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
  1079. $data['system_voltage'] = substr($info, 18,2) == 'ff' ? '0' : base_convert(substr($info, 18,2),16,10); // 电池电压
  1080. $data['battery_count'] = round(base_convert(substr($info, 20,1), 16, 10)); // 电池串数
  1081. $data['battery_type'] = round(base_convert(substr($info, 21,1), 16, 10)); //蓄电池类型
  1082. $data['overvoltage'] = round(base_convert(substr($info, 22,4), 16, 10)/1000,1); // 超压电压
  1083. $data['char_limit_voltage'] = round(base_convert(substr($info, 26,4), 16, 10)/1000,1); // 充电限制电压
  1084. $data['equ_char_voltage'] = round(base_convert(substr($info, 30,4), 16, 10)/1000,1); // 均衡充电电压
  1085. $data['increa_char_voltage'] = round(base_convert(substr($info, 34,4), 16, 10)/1000,1); // 提升充电电压
  1086. set_log('battery_setting.txt',substr($info, 34,4));
  1087. $data['float_char_voltage'] = round(base_convert(substr($info, 38,4), 16, 10)/1000,1); // 浮充充电电压
  1088. set_log('battery_setting.txt',substr($info, 38,4));
  1089. $data['increa_char_return_voltage'] = round(base_convert(substr($info, 42,4), 16, 10)/1000,1); // 提升充电返回电压
  1090. $data['over_dischar_return_voltage'] = round(base_convert(substr($info, 46,4), 16, 10)/1000,1); // 过放返回电压
  1091. $data['battery_under_voltage'] = round(base_convert(substr($info, 50,4), 16, 10)/1000,1); // 欠压警告电压 新增
  1092. $data['over_dischar_voltage'] = round(base_convert(substr($info, 54,4), 16, 10)/1000,1); // 过放电压
  1093. $data['discharge_limit_voltage'] = round(base_convert(substr($info, 58,4), 16, 10)/1000,1); // 放电限制电压 新增
  1094. $data['equ_char_time'] = round(base_convert(substr($info, 62,4), 16, 10)); // 均衡充电时间
  1095. $data['increa_char_time'] = round(base_convert(substr($info, 66,4), 16, 10)); // 提升充电时间
  1096. $data['balan_char_interval'] = round(base_convert(substr($info, 70,2), 16, 10)); // 均衡充电间隔
  1097. $data['temper_compen_coeff'] = round(base_convert(substr($info, 72,2), 16, 10)); // 温度补偿系数
  1098. $char_lower_limit_temper = base_convert(substr($info, 74,2), 16, 2); // 下限温度
  1099. if (substr(substr('00000000'.$char_lower_limit_temper, -8), 0,1) == 1) {
  1100. $data['char_lower_limit_temper'] = 0 - base_convert(substr('0000000'.$char_lower_limit_temper, -7), 2, 10);
  1101. }else{
  1102. $data['char_lower_limit_temper'] = round(base_convert($char_lower_limit_temper, 2, 10));
  1103. }
  1104. $char_upper_limit_temper = base_convert(substr($info, 76,2), 16, 2); // 上限温度
  1105. if (substr(substr('00000000'.$char_upper_limit_temper, -8), 0,1) == 1) {
  1106. $data['char_upper_limit_temper'] = 0 - base_convert(substr('0000000'.$char_upper_limit_temper, -7), 2, 10);
  1107. }else{
  1108. $data['char_upper_limit_temper'] = round(base_convert($char_upper_limit_temper, 2, 10));
  1109. }
  1110. $data['reduced_start_voltage'] = round(base_convert(substr($info, 78,4), 16, 10)/1000,1); // 智能功率起始电压
  1111. $data['reduced_stop_voltage'] = round(base_convert(substr($info, 82,4), 16, 10)/1000,1); // 智能功率结束电压
  1112. $data['light_voltage'] = round(base_convert(substr($info, 86,2), 16, 10)/10); // 光控电压
  1113. $data['light_delay_time'] = round(base_convert(substr($info, 88,2), 16, 10)*10); // 光控延时时间
  1114. exit(json_result('0000',$this->response['0000'],$data));
  1115. }else{
  1116. exit(json_result('0016',$this->response['0016']));
  1117. }
  1118. }
  1119. // 灯控相关数据
  1120. public function viewloglist() {
  1121. $lamp_id = $this->input->post('lamp_id',true);
  1122. $datatype = $this->input->post('datatype',true);
  1123. if (empty($lamp_id)) {
  1124. exit(json_result('0400', $this->response['0400'], array()));
  1125. }
  1126. if ($datatype == 'lampinfo') {
  1127. $fields = "number,projectid,address,longitude,latitude,section,boardpower,lamptype,boardtype,batteryah,loadpower,devstatus,loadtype,supplier,upazilla,po,manu,protocoltype,updatetime,status,power,model,fascal_year,fascal_year_phase,iccid,softwareVersion";
  1128. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1129. if (empty($res)) {
  1130. exit(json_result('0000', $this->response['0006'], array()));
  1131. }
  1132. $version = $this->session->userdata('version');
  1133. if (!empty($version)) {
  1134. $polemaType = ['冷镀锌'=>'Cold galvanizing','热镀锌'=>'Hot galvanizing','不锈钢'=>'Stainless steel'];
  1135. $lightType = ['LED灯'=>'LED lamp','钠灯'=>'Sodium lamp','节能灯'=>'Energy saving light'];
  1136. $lampType = ['太阳能路灯'=>'Solar street lamp','景观灯'=>'Landscape lamp','庭院灯'=>'Garden light'];
  1137. $boardType = ['单晶板'=>'Single crystal plate','多晶板'=>'Polycrystalline plate','非晶板'=>'Amorphous plate'];
  1138. $batteryType = ['铅酸电池'=>'Lead acid battery','锂电池'=>'Lithium battery'];
  1139. if (!preg_match('/^[A-Za-z\s*]+$/', $res['lamptype'])) {
  1140. $res['lamptype'] = empty($lampType[$res['lamptype']]) ? '' : $lampType[$res['lamptype']];
  1141. }
  1142. if (!preg_match('/^[A-Za-z\s*]+$/', $res['boardtype'])) {
  1143. $res['boardtype'] = empty($boardType[$res['boardtype']]) ? '' : $boardType[$res['boardtype']];
  1144. }
  1145. }else{
  1146. $polemaType = ['Cold galvanizing'=>'冷镀锌','Hot galvanizing'=>'热镀锌','Stainless steel'=>'不锈钢'];
  1147. $lightType = ['LED lamp'=>'LED灯','Sodium lamp'=>'钠灯','Energy saving light'=>'节能灯'];
  1148. $lampType = ['Solar street lamp'=>'太阳能路灯','Landscape lamp'=>'景观灯','Garden light'=>'庭院灯'];
  1149. $boardType = ['Single crystal plate'=>'单晶板','Polycrystalline plate'=>'多晶板','Amorphous plate'=>'非晶板'];
  1150. $batteryType = ['Lead acid battery'=>'铅酸电池','Lithium battery'=>'锂电池'];
  1151. if (preg_match('/^[A-Za-z\s*]+$/', $res['lamptype'])) {
  1152. $res['lamptype'] = empty($lampType[$res['lamptype']]) ? '' : $lampType[$res['lamptype']];
  1153. }
  1154. if (preg_match('/^[A-Za-z\s*]+$/', $res['boardtype'])) {
  1155. $res['boardtype'] = empty($boardType[$res['boardtype']]) ? '' : $boardType[$res['boardtype']];
  1156. }
  1157. }
  1158. // if ($res["isfaulted"] == 0) {
  1159. // $res["isfaulted"] = '正常';
  1160. // }else{
  1161. // }
  1162. // $alarmData = $this->Alarm_model->get_one_by_filter(array('lampid'=>$lamp_id,'status'=>0),'stralarmtype');
  1163. // $version = $this->session->userdata('version');
  1164. // if (empty($version)) {
  1165. // $res['isfaulted'] = empty($alarmData['stralarmtype']) ? '正常' : $alarmData['stralarmtype'];
  1166. // }else{
  1167. // $res['isfaulted'] = empty($alarmData['stralarmtype']) ? 'Normal' : alarm_translate($alarmData['stralarmtype']);
  1168. // }
  1169. $timezone = $this->Project_model->get_timezone_by_projectid($res['projectid']);
  1170. $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
  1171. $projectname = $this->Project_model->get_one(['id'=>$res['projectid']],'projectname');
  1172. $supplier_name = '';
  1173. $model_name = '';
  1174. if (!empty($res['supplier'])) {
  1175. $com = $this->Company_model->get_one(['id'=>$res['supplier']],'name,no');
  1176. if (empty($com['name']) && empty($com['no'])){
  1177. $supplier_name = '';
  1178. }else{
  1179. $supplier_name = empty($com['no']) ? $com['name'] : $com['no'];
  1180. }
  1181. }
  1182. if ($res['model']) {
  1183. $model_info = $this->db->query('select * from model_info where id = '.$res['model'])->row_array();
  1184. if (!empty($model_info) && !empty($model_info['name'])) {
  1185. $model_name = $model_info['name'];
  1186. }
  1187. }
  1188. $data = array(
  1189. "lamp_no" => $res["number"],
  1190. "project_name" => $this->Project_model->getNameById($res["projectid"]),
  1191. "address" => $res["address"],
  1192. "longitude" => $res["longitude"],
  1193. "latitude" => $res["latitude"],
  1194. "isfaulted" => $res["devstatus"],
  1195. "section" => $res["section"],
  1196. "boardpower" => floatval($res["boardpower"]),
  1197. "lamptype" => $res['lamptype'],
  1198. "boardtype" => $res['boardtype'],
  1199. "batteryah" => $res["batteryah"],
  1200. "loadpower" => $res["loadpower"],
  1201. 'status' => $res['status'],
  1202. // 'batterytype' => $res['batterytype'],
  1203. 'protocoltype'=>intval($res['protocoltype']),
  1204. 'supplier'=>intval($res['supplier']),
  1205. 'upazilla'=>intval($res['upazilla']),
  1206. 'po'=>intval($res['po']),
  1207. 'manu'=>intval($res['manu']),
  1208. "updatetime" => $res["updatetime"],
  1209. 'loadtype' => $res['loadtype'],
  1210. 'power' => $res['power'],
  1211. 'model' => $res['model'],
  1212. 'fascal_year' => $res['fascal_year'],
  1213. 'fascal_year_phase' => $res['fascal_year_phase'],
  1214. 'iccid' => $res['iccid'],
  1215. 'projectname' => $projectname['projectname'],
  1216. 'projectid' => $res['projectid'],
  1217. 'softwareVersion' => $res['softwareVersion'],
  1218. 'supplier_name' => $supplier_name,
  1219. 'model_name' => $model_name,
  1220. );
  1221. // $msisdn = $this->db->query('select iccid from msisdn where imsi = "'.$res['simid'].'"')->row_array();
  1222. // if (empty($msisdn) || empty($msisdn['iccid'])) {
  1223. // $data['iccid'] = '';
  1224. // }else{
  1225. // $data['iccid'] = $msisdn['iccid'];
  1226. // }
  1227. // if ($res['protocoltype'] != 1 && $res['protocoltype'] != 2) {
  1228. // unset($data['packageSurplus']);
  1229. // unset($data['simid']);
  1230. // }
  1231. // $username = $this->get_user_info('username');
  1232. // if ($username == 'zns') {
  1233. // $data['monthly_can_usage'] = intval($res['monthly_can_usage']);
  1234. // $data['monthly_already_usage'] = round($res['monthly_already_usage'],2);
  1235. // }
  1236. exit(json_result('0000', $this->response['0000'], $data));
  1237. }elseif ($datatype == 'lamp_info_log') {
  1238. $fields = "lighteness,status as lampstatus,lampvoltage,lampcurrent,lamppower,lamptemper as temper";
  1239. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1240. exit(json_result('0000', $this->response['0000'], $res));
  1241. }elseif ($datatype == 'solar_info_log') {
  1242. $fields = "solarvoltage,solarcurrent,solarpower";
  1243. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1244. exit(json_result('0000', $this->response['0000'], $res));
  1245. }elseif ($datatype == 'battery_info_log') {
  1246. // $fields = "battstatus,chargestage,battvoltage,chargecurrent,discharcurrent,chargepower,dischargepower,batttemper,electrictotal,electricleft,electricSOC,voltagedaymin,voltagedaymax,daychargeah,daydischarah,daychargemaxpow,daydischarmaxpow,daychargemincurrent,daycharmaxcurrent,daydischargemincurrent,daydischarmaxcurrent,daybattmintemper,daybattmaxtemper";
  1247. $fields = "*";
  1248. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1249. // $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
  1250. exit(json_result('0000', $this->response['0000'], $res));
  1251. }elseif ($datatype == 'system_info_log') {
  1252. $fields = "sysvoltage,syscurrent,temper,updatetime,id,number as lampid";
  1253. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1254. exit(json_result('0000', $this->response['0000'], $res));
  1255. }
  1256. // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log');
  1257. // $table = in_array($datatype, $table_map) ? $datatype : 'system_info_log';
  1258. // $res = $this->Lamp_model->getForInfoLog($lamp_id, $table);
  1259. // $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid');
  1260. // $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
  1261. // if(!$res){
  1262. // exit(json_result('0000', $this->response['0006'], array()));
  1263. // }
  1264. // if ($table == 'battery_info_log') {
  1265. // if (isset($res['daydischargemincurrent'])) {
  1266. // $h = floor($res['daydischargemincurrent']/3600);
  1267. // $h = $h < 10 ? '0'.$h : $h;
  1268. // $i = intval($res['daydischargemincurrent']/60)%60;
  1269. // $i = $i < 10 ? '0'.$i : $i;
  1270. // $res['daydischargemincurrent'] = $h.':'.$i;
  1271. // }
  1272. // if (isset($res['daychargemincurrent'])) {
  1273. // $h = floor($res['daychargemincurrent']/3600);
  1274. // $h = $h < 10 ? '0'.$h : $h;
  1275. // $i = intval($res['daychargemincurrent']/60)%60;
  1276. // $i = $i < 10 ? '0'.$i : $i;
  1277. // $res['daychargemincurrent'] = $h.':'.$i;
  1278. // }
  1279. // }
  1280. // $res["updatetime"] = date_change($res["updatetime"],8,$timezone['value']);
  1281. // exit(json_result('0000', $this->response['0000'], $res));
  1282. }
  1283. // 灯控历史数据
  1284. public function historylist() {
  1285. $lamp_id = $this->input->post('lamp_id',true);
  1286. $datatype = $this->input->post('datatype',true);
  1287. $page = intval($this->input->post('page',true));
  1288. $count = intval($this->input->post('count',true));
  1289. $count = empty($count) ? 16 : $count;
  1290. if (empty($lamp_id)) {
  1291. exit(json_result('0400', $this->response['0400'], array()));
  1292. }
  1293. $date = $this->input->post('date',true);
  1294. $beginDate = '';
  1295. $endDate = '';
  1296. // 按时区修改时间
  1297. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid,protocoltype');
  1298. $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
  1299. if (!empty($date)) {
  1300. $dateArr = explode('/', $date);
  1301. $beginDate = date('Y-m-d H:i:s',strtotime($dateArr[0]) - 8*3600);
  1302. $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',strtotime($dateArr[1]))) - 8*3600);
  1303. // $beginDate = $dateArr[0];
  1304. // $endDate = $dateArr[1];
  1305. if (strtotime($endDate) - strtotime($beginDate) > 31*24*3600) {
  1306. exit(json_result('0418',$this->response['0418']));
  1307. }
  1308. }else{
  1309. $beginDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 8*3600);
  1310. $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',time())) - 8*3600);
  1311. }
  1312. if($page < 1){
  1313. $page = 1;
  1314. }
  1315. $download = intval($this->input->post('download'));
  1316. if (!empty($download)) {
  1317. if (empty($date)) exit(json_result('0007',$this->response['0007']));
  1318. $dataList = array();
  1319. // 路灯
  1320. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'lamp_info_log', null, null,$beginDate,$endDate);
  1321. $temp = array();
  1322. $i = 1;
  1323. if (empty($this->version)) {
  1324. $lampStatusArr = array(0=>'关灯',1=>'开灯');
  1325. $title = array('序号','亮度%','状态','电压(V)','电流(A)','功率(W)','当天放电最大功率(W)','当天亮灯时长(HH:MM)','更新时间');
  1326. $name = '路灯';
  1327. }else{
  1328. $lampStatusArr = array(0=>'off',1=>'on');
  1329. $title = array('Number','Brightness%','Status','Voltage(V)','Current(A)','Power(W)','Maximum discharge power of the day(W)','dayLighting duration(HH:MM)','Update time');
  1330. $name = 'Lamp';
  1331. }
  1332. foreach ($lampInfoList as $k=>$l) {
  1333. $temp[$k][] = $i;
  1334. $temp[$k][] = $l['lighteness'];
  1335. $temp[$k][] = $lampStatusArr[$l['lampstatus']];
  1336. $temp[$k][] = $l['lampvoltage'];
  1337. $temp[$k][] = $l['lampcurrent'];
  1338. $temp[$k][] = $l['lamppower'];
  1339. $temp[$k][] = $l['daydischarmaxpow'];
  1340. $h = floor($l['daychargemincurrent'] / 3600);
  1341. $h = $h < 10 ? '0'.$h : $h;
  1342. $m = ceil($l['daychargemincurrent'] % 3600 / 60);
  1343. $m = $m < 10 ? '0'.$m : $m;
  1344. $temp[$k][] = $h.':'.$m;
  1345. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1346. $i ++;
  1347. }
  1348. $title1 = [];
  1349. foreach ($title as $t) {
  1350. $title1[0][] = $t;
  1351. }
  1352. $data = array_merge($title1,$temp);
  1353. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1354. // 蓄电池
  1355. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'battery_info_log', null, null,$beginDate,$endDate);
  1356. $temp = array();
  1357. $i = 1;
  1358. if (empty($this->version)) {
  1359. $name = '蓄电池';
  1360. if ($lampData['protocoltype'] == 2) {
  1361. $chargeStageMap = array(0=>'没有充电',1=>'等待',2=>'初始',3=>'MPPT',4=>'恒压',5=>'恒流',6=>'浮充',7=>'均衡',8=>'提升',9=>'涓流',10=>'完成',''=>'未知状态');
  1362. }else{
  1363. $chargeStageMap = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
  1364. }
  1365. $battstatusArr = array(0=>'空闲',1=>'放电',2=>'充电',3=>'一边充电一边放电',''=>'未知状态');
  1366. $unknown = '未知状态';
  1367. $title = array('序号','系统电压(V)','系统电流(A)','MOS温度(℃)','电池状态','充电阶段','电池电压(V)','当天最低电压(V)','当天最高电压(V)','电池温度(℃)','当天电池最低温度(℃)','当天电池最高温度(℃)','更新时间');
  1368. }else{
  1369. $name = 'Battery';
  1370. if ($lampData['protocoltype'] == 2) {
  1371. $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');
  1372. }else{
  1373. $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');
  1374. }
  1375. $battstatusArr = array(0=>'Free',1=>'Discharge',2=>'Charge',3=>'Discharge while charging',''=>'Unknown state');
  1376. $unknown = 'Unknown state';
  1377. $title = array('Serial number','System voltage(V)','System current(A)','MOS temperature(℃)','Battery status','Charging stage','Battery voltage(V)','The lowest voltage of the day(V)','Maximum Voltage of the Day(V)','Battery temperature(℃)','Battery minimum temperature for the day(℃)','The highest temperature of the battery on that day(℃)','Update time');
  1378. }
  1379. $indexArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  1380. foreach ($lampInfoList as $k=>$l) {
  1381. $temp[$k][] = $i;
  1382. $temp[$k][] = $l['sysvoltage'];
  1383. $temp[$k][] = $l['syscurrent'];
  1384. $temp[$k][] = $l['temper'];
  1385. $temp[$k][] = $battstatusArr[$l['battstatus']];
  1386. if ($lampData['protocoltype'] == 1) {
  1387. $l['chargestage'] = isset($indexArr[intval($l['chargestage'])]) ? $indexArr[intval($l['chargestage'])] : $l['chargestage'];
  1388. }
  1389. $temp[$k][] = $chargeStageMap[$l['chargestage']];
  1390. $temp[$k][] = $l['battvoltage'];
  1391. $temp[$k][] = $l['voltagedaymin'];
  1392. $temp[$k][] = $l['voltagedaymax'];
  1393. $temp[$k][] = $l['batttemper'];
  1394. $temp[$k][] = $l['daybattmintemper'];
  1395. $temp[$k][] = $l['daybattmaxtemper'];
  1396. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1397. $i ++;
  1398. }
  1399. $title1 = [];
  1400. foreach ($title as $t) {
  1401. $title1[0][] = $t;
  1402. }
  1403. $data = array_merge($title1,$temp);
  1404. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1405. // 太阳能
  1406. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'solar_info_log', null, null,$beginDate,$endDate);
  1407. $temp = array();
  1408. $i = 1;
  1409. if (empty($this->version)) {
  1410. $name = '太阳能';
  1411. $title = array('序号','电压(V)','电流(A)','功率(W)','当天充电最大功率(WH)','当天充电时长(HH:MM)','更新时间');
  1412. }else{
  1413. $name = 'Solar';
  1414. $title = array('Number','Voltage(V)','Current(A)','Power(W)','Maximum Power Charged on the Day(W)','day Charging time(HH:MM)','Update time');
  1415. }
  1416. foreach ($lampInfoList as $k=>$l) {
  1417. $temp[$k][] = $i;
  1418. $temp[$k][] = $l['solarvoltage'];
  1419. $temp[$k][] = $l['solarcurrent'];
  1420. $temp[$k][] = $l['solarpower'];
  1421. $temp[$k][] = $l['daychargemaxpow'];
  1422. $h = floor($l['daydischargemincurrent'] / 3600);
  1423. $h = $h < 10 ? '0'.$h : $h;
  1424. $m = ceil($l['daydischargemincurrent'] % 3600 / 60);
  1425. $m = $m < 10 ? '0'.$m : $m;
  1426. $temp[$k][] = $h.':'.$m;
  1427. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1428. $i ++;
  1429. }
  1430. $title1 = [];
  1431. foreach ($title as $t) {
  1432. $title1[0][] = $t;
  1433. }
  1434. $data = array_merge($title1,$temp);
  1435. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1436. // 系统
  1437. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'system_info_log', null, null,$beginDate,$endDate);
  1438. $temp = array();
  1439. $i = 1;
  1440. if (empty($this->version)) {
  1441. $name = '系统';
  1442. $title = array('序号','系统电压(V)','系统电流(A)','控制器温度(℃)','更新时间');
  1443. }else{
  1444. $name = 'System';
  1445. $title = array('Serial number','System voltage(V)','System current(A)','Control temperature(℃)','Update time');
  1446. }
  1447. foreach ($lampInfoList as $k=>$l) {
  1448. $temp[$k][] = $i;
  1449. $temp[$k][] = $l['sysvoltage'];
  1450. $temp[$k][] = $l['syscurrent'];
  1451. $temp[$k][] = $l['temper'];
  1452. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1453. $i ++;
  1454. }
  1455. $title1 = [];
  1456. foreach ($title as $t) {
  1457. $title1[0][] = $t;
  1458. }
  1459. $data = array_merge($title1,$temp);
  1460. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1461. $path = push_excel($dataList,'historyInfoExcel_'.date('Ymd'),1);
  1462. exit(json_result('0000', $this->response['0000'], array('path'=>$path)));
  1463. }
  1464. // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log','electric_info_log','history_info_log');
  1465. $table = !empty($datatype) ? $datatype : 'system_info_log';
  1466. if ($table == 'lamp_info_log') {
  1467. $table = 'realtime_info_log';
  1468. $total = $this->RealtimeInfoLog_model->get_count(['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate]);
  1469. $res = $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);
  1470. // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
  1471. }elseif ($table == 'system_info_log') {
  1472. $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
  1473. $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
  1474. }elseif ($table == 'battery_info_log') {
  1475. $join = [
  1476. // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
  1477. ];
  1478. $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
  1479. $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
  1480. $fields = 'batvoltage as battvoltage,chgtemper as batttemper,updatetime,DayOverDisChgTimes as overtimes,battstatus,chargestage,voltagedaymin,voltagedaymax,daybattmintemper,daybattmaxtemper';
  1481. $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
  1482. }else{
  1483. $join = [
  1484. // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
  1485. ];
  1486. $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
  1487. $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
  1488. $fields = 'panelvoltage as solarvoltage,updatetime,panelcurrent as solarcurrent,panelpower as solarpower,daychargemaxpow';
  1489. $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
  1490. // $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
  1491. // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
  1492. }
  1493. if(!$res){
  1494. exit(json_result('0000', $this->response['0006'], array()));
  1495. }else{
  1496. $arr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  1497. foreach ($res as &$v) {
  1498. if (isset($v['lighteness'])) {
  1499. $v['lampstatus'] = empty($v['lighteness']) ? '0' : '1';
  1500. }
  1501. if (isset($v['daychargemincurrent'])) $v['daychargemincurrent'] = intval($v['daychargemincurrent']);
  1502. // $v['updatetime'] = date_change($v["updatetime"],8,$timezone['value']);
  1503. $v['updatetime'] = set_timezone($v["updatetime"],$timezone['value']);
  1504. if ($lampData['protocoltype'] == 1 && $table == 'battery_info_log') {
  1505. $v['chargestage'] = isset($arr[intval($v['chargestage'])]) ? $arr[intval($v['chargestage'])] : $v['chargestage'];
  1506. }
  1507. if ($table == 'system_info_log') {
  1508. $v['lampid'] = $v['number'];
  1509. }
  1510. }
  1511. }
  1512. $data = array(
  1513. 'total' => ceil($total/$count),
  1514. 'list' => $res
  1515. );
  1516. exit(json_result('0000', $this->response['0000'], $data));
  1517. }
  1518. // 修改路灯位置
  1519. public function change_location(){
  1520. $id = intval($this->input->post('id',true));
  1521. $type = intval($this->input->post('type',true));
  1522. $data['longitude'] = $this->input->post('longitude',true);
  1523. $data['latitude'] = $this->input->post('latitude',true);
  1524. $data['updatetime'] = date('Y-m-d H:i:s',time());
  1525. if (empty($id) || empty($type) || !isset($data['longitude']) || !isset($data['latitude'])) {
  1526. exit(json_result('0007',$this->response['0007'],array()));
  1527. }
  1528. if ($type == 1) {
  1529. $this->Lamp_model->update($data,array('id'=>$id));
  1530. }else{
  1531. $this->Videomonitor_model->update($data,array('id'=>$id));
  1532. }
  1533. exit(json_result('0000',$this->response['0000'],array()));
  1534. }
  1535. // 同步巡检
  1536. public function set_patrol_cmd(){
  1537. $id = intval($this->input->post('id',true));
  1538. if (empty($id)) exit(json_result('0007',$this->response['0007'],array('id'=>$id)));
  1539. $lampData = $this->Lamp_model->getOne($id,'N.status,N.protocoltype,L.address,L.protocoltype as lampprotocoltype,L.number');
  1540. $cmd = '{"cmd_type":"set_sync_patrol_cmd","cmd_id":'.$id.'}';
  1541. $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
  1542. if ($cmdret === false) {
  1543. sleep(1);
  1544. $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
  1545. }
  1546. exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
  1547. }
  1548. // 批量添加
  1549. public function batchInput(){
  1550. set_time_limit(0);
  1551. $userid = $this->get_user_info('id');
  1552. // $idArr = $this->get_section_by_user();
  1553. $role = $this->get_user_info('role');
  1554. $company = $this->get_user_info('company');
  1555. $type = intval($this->input->post('type',true));
  1556. $projectid = intval($this->input->post('projectid',true));
  1557. if (empty($projectid)) exit(json_result('0007',$this->response['0007']));
  1558. if ($type == 1) { // 验证
  1559. $indexArr = ['A'=>'number','B'=>'address','C'=>'section'];
  1560. $data = $this->batch_import($indexArr);
  1561. }else{ // 创建
  1562. $data = $this->input->post('lampData',true);
  1563. if (empty($data)) exit(json_result('0007',$this->response['0007']));
  1564. $data = json_decode($data,true);
  1565. }
  1566. $res = 0;
  1567. $this->db->trans_begin();
  1568. $msg = [];
  1569. $patrol_arr = array();
  1570. foreach ($data as $key => $value) {
  1571. $num = $key+2;
  1572. $value['number'] = trim($value['number']);
  1573. if (!isset($value['number']) || $value['number'] == '') {
  1574. $res = 1;
  1575. if (empty($this->version)) {
  1576. $msg[] = '表格第'.$num.'行,路灯编号不能为空';
  1577. }else{
  1578. $msg[] = 'Table '.$num.' row.Lamp number can not be empty';
  1579. }
  1580. }else{
  1581. if (!is_numeric($value['number']) && ($value['number'] <= 0 || $value['number'] > 999999)) {
  1582. $res = 1;
  1583. if (empty($this->version)) {
  1584. $msg[] = '表格第'.$num.'行,路灯编号为1-999999的数字';
  1585. }else{
  1586. $msg[] = 'Table '.$num.' row.The number of street lamps numbered 1-999999';
  1587. }
  1588. }
  1589. }
  1590. $value['address'] = trim($value['address']);
  1591. if (empty($value['address'])) {
  1592. $res = 1;
  1593. $msg[] = 'Table '.$num.' row.Address of the wireless module can not be empty';
  1594. }else{
  1595. $status = preg_match('/^[A-Fa-f0-9]+$/', $value['address']);
  1596. if (empty($status)) {
  1597. $res = 1;
  1598. $msg[] = 'Table '.$num.' row.Wireless module address is 16 hexadecimal';
  1599. }else{
  1600. if ($this->Lamp_model->getDataCount(['address'=>$value['address']])) {
  1601. $res = 1;
  1602. $msg[] = 'Table '.$num.' row.Wireless module address already exists';
  1603. }
  1604. if ($role != SYSTEM_ADMIN) {
  1605. if ($role == 2) {
  1606. $value["manu"] = $company;
  1607. }elseif ($role == 4) {
  1608. $value["po"] = $company;
  1609. }
  1610. }
  1611. if (!isset($value["manu"])) $value["manu"] = $this->get_manu_by_address($value["address"]);
  1612. }
  1613. }
  1614. $value['section'] = trim($value['section']);
  1615. $value['createtime'] = date('Y-m-d H:i:s',time());
  1616. $value['projectid'] = $projectid;
  1617. if ($type != 1) {
  1618. $this->Lamp_model->add($value);
  1619. $this->Project_model->add_lamp_count(['projectid'=>$projectid]);
  1620. }
  1621. }
  1622. if ($res || $type == 1) {
  1623. $this->db->trans_rollback();
  1624. exit(json_result('0000',$this->response['0000'],['lampData'=>$data,'msg'=>$msg]));
  1625. }else{
  1626. $this->db->trans_commit();
  1627. exit(json_result('0000',$this->response['0000']));
  1628. }
  1629. }
  1630. // 路灯历史数据曲线图
  1631. public function lamp_history_data(){
  1632. $type = intval($this->input->post('type',true));
  1633. $lampId = intval($this->input->post('lampid',true));
  1634. if (empty($lampId)) exit(json_result('0007',$this->response['0007']));
  1635. $dateType = intval($this->input->post('dateType',true));
  1636. $date = $this->input->post('date',true);
  1637. if ($dateType == 0) { // 一天
  1638. $beginDate = date('Y-m-d H:i:s',time()-24*3600);
  1639. $endDate = date('Y-m-d H:i:s',time());
  1640. }elseif ($dateType == 1) { // 三天
  1641. $beginDate = date('Y-m-d H:i:s',time()-24*3600*3);
  1642. $endDate = date('Y-m-d H:i:s',time());
  1643. }elseif ($dateType == 2) { // 七天
  1644. $beginDate = date('Y-m-d H:i:s',time()-24*3600*7);
  1645. $endDate = date('Y-m-d H:i:s',time());
  1646. }elseif ($dateType == 3) { // 十四天
  1647. $beginDate = date('Y-m-d H:i:s',time()-24*3600*14);
  1648. $endDate = date('Y-m-d H:i:s',time());
  1649. }else{ // 选择时间
  1650. if (empty($date)) exit(json_result('0007',$this->response['0007']));
  1651. $res = explode('/', $date);
  1652. if (strtotime($res[1]) - strtotime($res[0]) > 31 * 24 * 3600) {
  1653. exit(json_result('0418',$this->response['0418']));
  1654. }
  1655. $beginDate = $res[0];
  1656. $endDate = date('Y-m-d 23:59:59',strtotime($res[1]));
  1657. // var_dump($endDate);die;
  1658. }
  1659. $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";
  1660. $lampData = $this->db->query($sql)->row_array();
  1661. $timezoneData = $this->Project_model->get_timezone_by_projectid($lampData['id']);
  1662. $timezone = $timezoneData['value'];
  1663. $beginDate = date('Y-m-d H:i:s',strtotime($beginDate) - $timezone * 3600);
  1664. $endDate = date('Y-m-d H:i:s',strtotime($endDate) - $timezone * 3600);
  1665. $data = ['patrolinterval'=>$lampData['patrolinterval']];
  1666. if ($type == 0) { // 路灯
  1667. $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.'"';
  1668. $list = $this->db->query($sql)->result_array();
  1669. $temp = [];
  1670. foreach ($list as $value) {
  1671. $temp['lampvoltage'][] = $value['lampvoltage'];
  1672. $temp['lampcurrent'][] = $value['lampcurrent'];
  1673. $temp['lamppower'][] = $value['lamppower'];
  1674. $temp['lighteness'][] = $value['lighteness'];
  1675. $temp['updatetime'][] = date_change($value['updatetime'],0,$timezone);
  1676. if (!isset($data['maxcurrent'])) {
  1677. $data['maxcurrent'] = $value['lampcurrent'];
  1678. }else{
  1679. $data['maxcurrent'] = $value['lampcurrent'] > $data['maxcurrent'] ? $value['lampcurrent'] : $data['maxcurrent'];
  1680. }
  1681. // if (!isset($data['maxdaychargemincurrent'])) {
  1682. // $data['maxdaychargemincurrent'] = $value['daychargemincurrent'];
  1683. // }else{
  1684. // $data['maxdaychargemincurrent'] = $value['daychargemincurrent'] > $data['maxdaychargemincurrent'] ? $value['daychargemincurrent'] : $data['maxdaychargemincurrent'];
  1685. // }
  1686. if (!isset($data['mincurrent'])) {
  1687. $data['mincurrent'] = $value['lampcurrent'];
  1688. }else{
  1689. $data['mincurrent'] = $value['lampcurrent'] < $data['mincurrent'] ? $value['lampcurrent'] : $data['mincurrent'];
  1690. }
  1691. if (!isset($data['maxvoltage'])) {
  1692. $data['maxvoltage'] = $value['lampvoltage'];
  1693. }else{
  1694. $data['maxvoltage'] = $value['lampvoltage'] > $data['maxvoltage'] ? $value['lampvoltage'] : $data['maxvoltage'];
  1695. }
  1696. if (!isset($data['minvoltage'])) {
  1697. $data['minvoltage'] = $value['lampvoltage'];
  1698. }else{
  1699. $data['minvoltage'] = $value['lampvoltage'] < $data['minvoltage'] ? $value['lampvoltage'] : $data['minvoltage'];
  1700. }
  1701. if (!isset($data['maxpower'])) {
  1702. $data['maxpower'] = $value['lamppower'];
  1703. }else{
  1704. $data['maxpower'] = $value['lamppower'] > $data['maxpower'] ? $value['lamppower'] : $data['maxpower'];
  1705. }
  1706. if (!isset($data['minpower'])) {
  1707. $data['minpower'] = $value['lamppower'];
  1708. }else{
  1709. $data['minpower'] = $value['lamppower'] < $data['minpower'] ? $value['lamppower'] : $data['minpower'];
  1710. }
  1711. if (!isset($data['maxlighteness'])) {
  1712. $data['maxlighteness'] = $value['lighteness'];
  1713. }else{
  1714. $data['maxlighteness'] = $value['lighteness'] > $data['maxlighteness'] ? $value['lighteness'] : $data['maxlighteness'];
  1715. }
  1716. if (!isset($data['minlighteness'])) {
  1717. $data['minlighteness'] = $value['lighteness'];
  1718. }else{
  1719. $data['minlighteness'] = $value['lighteness'] < $data['minlighteness'] ? $value['lighteness'] : $data['minlighteness'];
  1720. }
  1721. // if (isset($data['maxdaychargemincurrent'])) {
  1722. // $h = floor($data['maxdaychargemincurrent'] / 3600);
  1723. // $h = $h < 10 ? '0'.$h : $h;
  1724. // $m = floor($data['maxdaychargemincurrent'] / 3600 % 60);
  1725. // $m = $m < 10 ? '0'.$m : $m;
  1726. // $data['maxdaychargemincurrent'] = $h.':'.$m;
  1727. // }
  1728. }
  1729. $list = $temp;
  1730. }elseif ($type == 1) { // 蓄电池
  1731. $sql = 'select batvoltage as battvoltage,batcurrent as chargecurrent,chgtemper as batttemper,batpower as chargepower,updatetime from realtime_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
  1732. $list = $this->db->query($sql)->result_array();
  1733. $temp = [];
  1734. foreach ($list as $value) {
  1735. $temp['battvoltage'][] = $value['battvoltage'];
  1736. $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
  1737. $batterycurrent = $value['chargecurrent'];
  1738. $temp['batterycurrent'][] = $batterycurrent;
  1739. $batterypower = $value['chargepower'];
  1740. $temp['batterypower'][] = $batterypower;
  1741. if (!isset($data['maxcurrent'])) {
  1742. $data['maxcurrent'] = $batterycurrent;
  1743. }else{
  1744. $data['maxcurrent'] = $batterycurrent > $data['maxcurrent'] ? $batterycurrent : $data['maxcurrent'];
  1745. }
  1746. if (!isset($data['mincurrent'])) {
  1747. $data['mincurrent'] = $batterycurrent;
  1748. }else{
  1749. $data['mincurrent'] = $batterycurrent < $data['mincurrent'] ? $batterycurrent : $data['mincurrent'];
  1750. }
  1751. if (!isset($data['maxvoltage'])) {
  1752. $data['maxvoltage'] = $value['battvoltage'];
  1753. }else{
  1754. $data['maxvoltage'] = $value['battvoltage'] > $data['maxvoltage'] ? $value['battvoltage'] : $data['maxvoltage'];
  1755. }
  1756. if (!isset($data['minvoltage'])) {
  1757. $data['minvoltage'] = $value['battvoltage'];
  1758. }else{
  1759. $data['minvoltage'] = $value['battvoltage'] < $data['minvoltage'] ? $value['battvoltage'] : $data['minvoltage'];
  1760. }
  1761. if (!isset($data['maxbatttemper'])) {
  1762. $data['maxbatttemper'] = $value['batttemper'];
  1763. }else{
  1764. $data['maxbatttemper'] = $value['batttemper'] > $data['maxbatttemper'] ? $value['batttemper'] : $data['maxbatttemper'];
  1765. }
  1766. if (!isset($data['minbatttemper'])) {
  1767. $data['minbatttemper'] = $value['batttemper'];
  1768. }else{
  1769. $data['minbatttemper'] = $value['batttemper'] < $data['minbatttemper'] ? $value['batttemper'] : $data['minbatttemper'];
  1770. }
  1771. if (!isset($data['maxpower'])) {
  1772. $data['maxpower'] = round($batterypower,2);
  1773. }else{
  1774. $data['maxpower'] = $batterypower > $data['maxpower'] ? round($batterypower,2) : round($data['maxpower'],2);
  1775. }
  1776. if (!isset($data['minpower'])) {
  1777. $data['minpower'] = round($batterypower,2);
  1778. }else{
  1779. $data['minpower'] = $batterypower < $data['minpower'] ? round($batterypower,2) : round($data['minpower'],2);
  1780. }
  1781. }
  1782. $list = $temp;
  1783. }elseif ($type == 2) { // 太阳能板
  1784. $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.'"';
  1785. $list = $this->db->query($sql)->result_array();
  1786. $temp = [];
  1787. foreach ($list as $value) {
  1788. $temp['solarvoltage'][] = $value['solarvoltage'];
  1789. $temp['solarcurrent'][] = $value['solarcurrent'];
  1790. $temp['solarpower'][] = $value['solarpower'];
  1791. $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
  1792. if (!isset($data['maxcurrent'])) {
  1793. $data['maxcurrent'] = $value['solarcurrent'];
  1794. }else{
  1795. $data['maxcurrent'] = $value['solarcurrent'] > $data['maxcurrent'] ? $value['solarcurrent'] : $data['maxcurrent'];
  1796. }
  1797. if (!isset($data['mincurrent'])) {
  1798. $data['mincurrent'] = $value['solarcurrent'];
  1799. }else{
  1800. $data['mincurrent'] = $value['solarcurrent'] < $data['mincurrent'] ? $value['solarcurrent'] : $data['mincurrent'];
  1801. }
  1802. if (!isset($data['maxvoltage'])) {
  1803. $data['maxvoltage'] = $value['solarvoltage'];
  1804. }else{
  1805. $data['maxvoltage'] = $value['solarvoltage'] > $data['maxvoltage'] ? $value['solarvoltage'] : $data['maxvoltage'];
  1806. }
  1807. // if (!isset($data['maxdaydischargemincurrent'])) {
  1808. // $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'];
  1809. // }else{
  1810. // $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'] > $data['maxdaydischargemincurrent'] ? $value['daydischargemincurrent'] : $data['maxdaydischargemincurrent'];
  1811. // }
  1812. if (!isset($data['minvoltage'])) {
  1813. $data['minvoltage'] = $value['solarvoltage'];
  1814. }else{
  1815. $data['minvoltage'] = $value['solarvoltage'] < $data['minvoltage'] ? $value['solarvoltage'] : $data['minvoltage'];
  1816. }
  1817. if (!isset($data['maxpower'])) {
  1818. $data['maxpower'] = $value['solarpower'];
  1819. }else{
  1820. $data['maxpower'] = $value['solarpower'] > $data['maxpower'] ? $value['solarpower'] : $data['maxpower'];
  1821. }
  1822. if (!isset($data['minpower'])) {
  1823. $data['minpower'] = $value['solarpower'];
  1824. }else{
  1825. $data['minpower'] = $value['solarpower'] < $data['minpower'] ? $value['solarpower'] : $data['minpower'];
  1826. }
  1827. if (isset($data['maxdaydischargemincurrent'])) {
  1828. $h = floor($data['maxdaydischargemincurrent'] / 3600);
  1829. $h = $h < 10 ? '0'.$h : $h;
  1830. $m = floor($data['maxdaydischargemincurrent'] / 3600 % 60);
  1831. $m = $m < 10 ? '0'.$m : $m;
  1832. $data['maxdaydischargemincurrent'] = $h.':'.$m;
  1833. }
  1834. }
  1835. $list = $temp;
  1836. }else{ // 电量
  1837. $sql = 'select chargeday as daychargeah,dischargeday as daydischarah,updatetime from realtime_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
  1838. $list = $this->db->query($sql)->result_array();
  1839. $temp = [];
  1840. foreach ($list as $value) {
  1841. $temp['daychargeah'][] = $value['daychargeah'];
  1842. $temp['daydischarah'][] = $value['daydischarah'];
  1843. $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
  1844. if (!isset($data['maxdaychargeah'])) {
  1845. $data['maxdaychargeah'] = $value['daychargeah'];
  1846. }else{
  1847. $data['maxdaychargeah'] = $value['daychargeah'] > $data['maxdaychargeah'] ? $value['daychargeah'] : $data['maxdaychargeah'];
  1848. }
  1849. if (!isset($data['mindaychargeah'])) {
  1850. $data['mindaychargeah'] = $value['daychargeah'];
  1851. }else{
  1852. $data['mindaychargeah'] = $value['daychargeah'] < $data['mindaychargeah'] ? $value['daychargeah'] : $data['mindaychargeah'];
  1853. }
  1854. if (!isset($data['maxdaydischarah'])) {
  1855. $data['maxdaydischarah'] = $value['daydischarah'];
  1856. }else{
  1857. $data['maxdaydischarah'] = $value['daydischarah'] > $data['maxdaydischarah'] ? $value['daydischarah'] : $data['maxdaydischarah'];
  1858. }
  1859. if (!isset($data['mindaydischarah'])) {
  1860. $data['mindaydischarah'] = $value['daydischarah'];
  1861. }else{
  1862. $data['mindaydischarah'] = $value['daydischarah'] < $data['mindaydischarah'] ? $value['daydischarah'] : $data['mindaydischarah'];
  1863. }
  1864. }
  1865. $list = $temp;
  1866. }
  1867. if (empty($list)) {
  1868. $data['list'] = new StdClass();
  1869. }else{
  1870. $data['list'] = $list;
  1871. }
  1872. exit(json_result('0000',$this->response['0000'],$data));
  1873. }
  1874. }