Lampcontrol.php 119 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070
  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,L.controllerstatus';
  96. }else{
  97. $fields .= ",RI.updatetime,L.controllerstatus";
  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,L.controllerstatus';
  105. }else{
  106. $fields .= ",L.id,L.projectid,L.section,L.loadtype,P.timezone as timezoneid,L.controllerstatus";
  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']) || $value['controllerstatus'] != 5) {
  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']) || $value['controllerstatus'] != 5) {
  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. if (empty($data["manu"])) exit(json_result('0423',$this->response['0423']));
  806. $role = $this->get_user_info('role');
  807. $company = $this->get_user_info('company');
  808. if ($role != SYSTEM_ADMIN) {
  809. if ($role == 2) {
  810. if ($data["manu"] != $company) {
  811. exit(json_result('0423',$this->response['0423']));
  812. }
  813. }elseif ($role == 4) {
  814. $data["po"] = $company;
  815. }else{
  816. exit(json_result('0013',$this->response['0013']));
  817. }
  818. }
  819. // if (!isset($data["manu"])) $data["manu"] = $this->get_manu_by_address($data["address"]);
  820. // 控制器协议类型
  821. $version = $this->session->userdata('version');
  822. if (strlen($data['number']) > 6) exit(json_result('0408', $this->response['0408'], array()));
  823. if (empty($data['projectid'])) exit(json_result('0308', $this->response['0308'], array()));
  824. if (empty($data['number'])) exit(json_result('0409', $this->response['0409'], array()));
  825. if (!is_numeric($data['number']) || $data['number'] < 1 || $data['number'] > 999999) exit(json_result('0410', $this->response['0410'], array()));
  826. if (empty($data['address'])) exit(json_result('0805', $this->response['0805'], array()));
  827. if (is_float($data['address'])) {
  828. $data['address'] = strval(intval(ceil($data['address'])));
  829. }
  830. $is_true = preg_match('/^[A-Fa-f0-9]+$/', $data['address']);
  831. if (empty($is_true)) exit(json_result('0414', $this->response['0414'], array()));
  832. $data = remove_null_params($data);
  833. if (empty($where['id'])) {
  834. if ($this->Lamp_model->getDataCount(array('number'=>$data['number'], 'projectid'=>$data['projectid'])) > 0) {
  835. exit(json_result('0401', $this->response['0401'], array()));
  836. }
  837. $fascal_year = $this->input->post('fascal_year',true);
  838. if (empty($fascal_year)) $fascal_year = date('Y-m-d');
  839. $data['fascal_year'] = $fascal_year;
  840. $fascal_year_phase = $this->input->post('fascal_year_phase',true);
  841. if (empty($fascal_year_phase)) {
  842. $fascal_year_phase = date('Y');
  843. $data['fascal_year_phase'] = $fascal_year_phase.'-'.date('Y',strtotime($fascal_year_phase.' +1 year'));
  844. }
  845. $lamp = $this->Lamp_model->get_one(array('address'=>$data['address']),'projectid,number');
  846. if (!empty($lamp)) {
  847. $projectid = $lamp['projectid'];
  848. $number = $lamp['number'];
  849. $projectname = $this->Project_model->getNameById($projectid);
  850. if (empty($version)) {
  851. exit(json_result('0404', "该无线模块地址已被【{$projectname}】项目,【{$number}】编号的灯控使用", array()));
  852. }else{
  853. exit(json_result('other', "The wireless module address has been used by \"{$projectname}\" project, and \"{$number}\" serial number", array()));
  854. }
  855. }
  856. $projectData = $this->Project_model->get_one(['id'=>$data['projectid']],'patrolinterval,cityid,projectname');
  857. if (empty($data['longitude']) && empty($data['latitude']) && !empty($projectData['cityid'])) {
  858. $globalData = $this->Global_location_model->get_one(['id'=>$projectData['cityid']],'longitude,latitude');
  859. $data['longitude'] = $globalData['longitude'];
  860. $data['latitude'] = $globalData['latitude'];
  861. }
  862. $createtime = $this->input->post('createtime',true);
  863. $data['createtime'] = empty($createtime) ? date('Y-m-d H:i:s',time()) : $createtime;
  864. $lampid = $this->Lamp_model->add($data);
  865. $this->Project_model->add_lamp_count(array('lampcount'=>1,'faultcount'=>0,'projectid'=>$data['projectid']));
  866. $lampId = intval($lampid);
  867. $this->add_operation_log('insert',"在\"{$projectData['projectname']}\"项目里添加编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯",0);
  868. $this->add_operation_log('insert',"Add lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\"",0,1);
  869. } else {
  870. if ($this->Lamp_model->getDataCount(array('number'=>$data['number'], 'projectid'=>$data['projectid']), $where['id']) > 0) {
  871. exit(json_result('0401', $this->response['0401'], array()));
  872. }
  873. $fascal_year = $this->input->post('fascal_year',true);
  874. if (!empty($fascal_year)) $data['fascal_year'] = $fascal_year;
  875. $fascal_year_phase = $this->input->post('fascal_year_phase',true);
  876. if (!empty($fascal_year_phase)) $data['fascal_year_phase'] = $fascal_year_phase;
  877. $lamp = $this->Lamp_model->get_one(array('address'=>$data['address'], 'id !='=>$where['id']),'projectid,number');
  878. if (!empty($lamp)) {
  879. $projectid = $lamp['projectid'];
  880. $number = $lamp['number'];
  881. $projectname = $this->Project_model->getNameById($projectid);
  882. if (empty($version)) {
  883. exit(json_result('0404', "该无线模块地址已被【{$projectname}】项目,【{$number}】编号的灯控使用", array()));
  884. }else{
  885. exit(json_result('other', "The wireless module address has been used by \"{$projectname}\" project, and \"{$number}\" serial number", array()));
  886. }
  887. }
  888. $old = $this->Lamp_model->get_one($where,'isfaulted,projectid,address,protocoltype');
  889. if ($old['projectid'] != $data['projectid']) {
  890. $new['projectid'] = $data['projectid'];
  891. $new['faultcount'] = $old['isfaulted'] > 0 ? 1 : 0;
  892. $this->Project_model->add_lamp_count($new);
  893. $old['faultcount'] = $new['faultcount'];
  894. $this->Project_model->minus_lamp_count($old);
  895. }
  896. // $oldNet = $this->Network_model->getData(array('id'=>$old['networkid']));
  897. if ($old['address'] != $data['address'] || $protocoltype != $old['protocoltype']) {
  898. }
  899. $this->Lamp_model->update($data,$where);
  900. $projectData = $this->Project_model->getData(array('id'=>$data['projectid']),'projectname');
  901. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯信息");
  902. $this->add_operation_log('update',"Update lamp:\"{$data['number']}\".Wireless module address:\"{$data['address']}\".Project name:\"{$projectData['projectname']}\".",0,1);
  903. //更新负载设置和蓄电池设置
  904. if (isset($_POST['workmode'])) {
  905. $res = $this->load_update();
  906. if ($res['result'] == 1) {
  907. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络里的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯负载参数");
  908. $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);
  909. }else{
  910. exit(json_result($res['msg'],$res['msg'],array()));
  911. }
  912. }
  913. if (isset($_POST['capacity'])) {
  914. $res = $this->battery_update();
  915. if ($res['result'] == 1) {
  916. $this->add_operation_log('update',"修改\"{$projectData['projectname']}\"项目下的\"{$networkData['networkname']}\"网络里的编号为\"{$data['number']}\"、无线模块地址为\"{$data['address']}\"的路灯蓄电池参数");
  917. $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);
  918. }else{
  919. exit(json_result($res['msg'],$res['msg'],array()));
  920. }
  921. }
  922. $lampId = intval($where['id']);
  923. }
  924. exit(json_result('0000', $this->response['0000'], array("id" => $lampId)));
  925. }
  926. private function format_date_en($date){
  927. $h = floor($date/60);
  928. $h = $h >= 10 ? $h : '0'.$h;
  929. $t = floor($date%60);
  930. $t = $t >= 10 ? $t : '0'.$t;
  931. return $h.':'.$t;
  932. }
  933. // 新控制器获取默认参数值
  934. public function get_data(){
  935. $type = $this->input->post('type',true);
  936. $type = empty($type) ? 1 : $type;
  937. $update = array();
  938. if ($type == 1) { // 负载参数
  939. $update['intell_power'] = '2';
  940. $update['light_type'] = '1';
  941. $update['load_current'] = '900';
  942. $update['first_light_time'] = '00:30';
  943. $update['first_light_human_power'] = '50';
  944. $update['first_light_unman_power'] = '20';
  945. $update['second_light_time'] = '00:30';
  946. $update['second_light_human_power'] = '70';
  947. $update['second_light_unman_power'] = '30';
  948. $update['third_light_time'] = '02:00';
  949. $update['third_light_human_power'] = '100';
  950. $update['third_light_unman_power'] = '50';
  951. $update['fourth_light_time'] = '00:30';
  952. $update['fourth_light_human_power'] = '70';
  953. $update['fourth_light_unman_power'] = '30';
  954. $update['fifth_light_time'] = '00:30';
  955. $update['fifth_light_human_power'] = '70';
  956. $update['fifth_light_unman_power'] = '30';
  957. $update['sixth_light_time'] = '04:00';
  958. $update['sixth_light_human_power'] = '30';
  959. $update['sixth_light_unman_power'] = '10';
  960. $update['seventh_light_time'] = '00:00';
  961. $update['seventh_light_human_power'] = '100';
  962. $update['seventh_light_unman_power'] = '50';
  963. $update['tenth_light_time'] = '00:00';
  964. $update['tenth_light_human_power'] = '50';
  965. $update['tenth_light_unman_power'] = '20';
  966. $update['induction_delay_status'] = '0';
  967. $update['induction_delay'] = '10';
  968. }else{ // 蓄电池参数
  969. $update['system_voltage'] = 12; // 电池电压
  970. $update['battery_type'] = 1; //蓄电池类型
  971. $update['overvoltage'] = 15.5; // 超压电压
  972. $update['char_limit_voltage'] = 15.0; // 充电限制电压
  973. $update['equ_char_voltage'] = 14.6; // 均衡充电电压
  974. $update['increa_char_voltage'] = 14.4; // 提升充电电压
  975. $update['float_char_voltage'] = 13.8; // 浮充充电电压
  976. $update['increa_char_return_voltage'] = 13.2; // 提升充电返回电压
  977. $update['over_dischar_return_voltage'] = 12.6; // 过放返回电压
  978. $update['battery_under_voltage'] = 12.0; // 欠压警告电压 新增
  979. $update['over_dischar_voltage'] = 11.1; // 过放电压
  980. $update['discharge_limit_voltage'] = 10.6; // 放电限制电压 新增
  981. $update['equ_char_time'] = 120; // 均衡充电时间
  982. $update['increa_char_time'] = 120; // 提升充电时间
  983. $update['balan_char_interval'] = 30; // 均衡充电间隔
  984. $update['temper_compen_coeff'] = 5; // 温度补偿系数
  985. $update['char_upper_limit_temper'] = 60; // 上限温度
  986. $update['char_lower_limit_temper'] = -30; // 下限温度
  987. $update['reduced_start_voltage'] = 11.5; // 智能功率起始电压
  988. $update['reduced_stop_voltage'] = 10.0; // 智能功率结束电压
  989. $update['light_voltage'] = 5; // 光控电压
  990. $update['light_delay_time'] = 20; // 光控延时时间
  991. }
  992. exit(json_result('0000',$this->response['0000'],$update));
  993. }
  994. // 新控制器获取参数设置
  995. public function get_load() {
  996. $lamp_id = $this->input->post('lamp_id', true);
  997. if (empty($lamp_id)) {
  998. exit(json_result('0400', $this->response['0400'], array()));
  999. }
  1000. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number');
  1001. $res = $this->send_cmd('13',$lampData['address'],'');
  1002. if (empty($res)) {
  1003. exit(json_result('0016', $this->response['0016']));
  1004. }else{
  1005. // if (strtolower(crc16(pack('H*',substr($res['msg'], 0,-4)))) == strtolower(substr($res['msg'],-4))) {
  1006. $res['msg'] = unpack('H*', $res['msg'])[1];
  1007. set_log('get_load.txt',$res['msg']);
  1008. $data = array();
  1009. $data['intell_power'] = base_convert(substr($res['msg'], 18,1), 16, 10).''; // 智能功率
  1010. $data['light_type'] = base_convert(substr($res['msg'], 19,1), 16, 10).''; // 灯控模式
  1011. $data['load_current'] = (base_convert(substr($res['msg'], 20,4), 16, 10)*10).''; // 负载电流
  1012. $data['first_light_time'] = base_convert(substr($res['msg'], 24,2), 16, 10).''; // 第一段亮灯时间
  1013. $data['first_light_human_power'] = base_convert(substr($res['msg'], 26,2), 16, 10).''; // 第一段有人功率
  1014. $data['first_light_unman_power'] = base_convert(substr($res['msg'], 28,2), 16, 10).''; // 第一段无人功率
  1015. $data['second_light_time'] = base_convert(substr($res['msg'], 30,2), 16, 10).''; // 第二段亮灯时间
  1016. $data['second_light_human_power'] = base_convert(substr($res['msg'], 32,2), 16, 10).''; // 第二段有人功率
  1017. $data['second_light_unman_power'] = base_convert(substr($res['msg'], 34,2), 16, 10).''; // 第二段无人功率
  1018. $data['third_light_time'] = base_convert(substr($res['msg'], 36,2), 16, 10).''; // 第三段亮灯时间
  1019. $data['third_light_human_power'] = base_convert(substr($res['msg'], 38,2), 16, 10).''; // 第三段有人功率
  1020. $data['third_light_unman_power'] = base_convert(substr($res['msg'], 40,2), 16, 10).''; // 第三段无人功率
  1021. $data['fourth_light_time'] = base_convert(substr($res['msg'], 42,2), 16, 10).''; // 第四段亮灯时间
  1022. $data['fourth_light_human_power'] = base_convert(substr($res['msg'], 44,2), 16, 10).''; // 第四段有人功率
  1023. $data['fourth_light_unman_power'] = base_convert(substr($res['msg'], 46,2), 16, 10).''; // 第四段无人功率
  1024. $data['fifth_light_time'] = base_convert(substr($res['msg'], 48,2), 16, 10).''; // 第五段亮灯时间
  1025. $data['fifth_light_human_power'] = base_convert(substr($res['msg'], 50,2), 16, 10).''; // 第五段有人功率
  1026. $data['fifth_light_unman_power'] = base_convert(substr($res['msg'], 52,2), 16, 10).''; // 第五段无人功率
  1027. $data['sixth_light_time'] = base_convert(substr($res['msg'], 54,2), 16, 10).''; // 第六段亮灯时间
  1028. $data['sixth_light_human_power'] = base_convert(substr($res['msg'], 56,2), 16, 10).''; // 第六段有人功率
  1029. $data['sixth_light_unman_power'] = base_convert(substr($res['msg'], 58,2), 16, 10).''; // 第六段无人功率
  1030. $data['seventh_light_time'] = base_convert(substr($res['msg'], 60,2), 16, 10).''; // 第七段亮灯时间
  1031. $data['seventh_light_human_power'] = base_convert(substr($res['msg'], 62,2), 16, 10).''; // 第七段有人功率
  1032. $data['seventh_light_unman_power'] = base_convert(substr($res['msg'], 64,2), 16, 10).''; // 第七段无人功率
  1033. $data['tenth_light_time'] = base_convert(substr($res['msg'], 66,2), 16, 10).''; // 晨亮时间
  1034. $data['tenth_light_human_power'] = base_convert(substr($res['msg'], 68,2), 16, 10).''; // 晨亮有人功率
  1035. $data['tenth_light_unman_power'] = base_convert(substr($res['msg'], 70,2), 16, 10).''; // 晨亮无人功率
  1036. $induction_delay_status = base_convert(substr($res['msg'], 72,2), 16, 10); // 感应延时开关状态
  1037. $data['induction_delay_status'] = $induction_delay_status > 0 ? '1' : '0';
  1038. $data['induction_delay'] = (base_convert(substr($res['msg'], 74,2), 16, 10) * 10).''; // 感应延时
  1039. // $data['tenth_light_human_power'] = base_convert(substr($res['msg'], 64,2), 16, 10).''; // 晨亮有人功率
  1040. // $data['tenth_light_unman_power'] = base_convert(substr($res['msg'], 68,2), 16, 10).''; // 晨亮无人功率
  1041. // $data['begin_voltage'] = round(base_convert(substr($res['msg'], 146,4), 16, 10)/10,1).''; // 智能功率USER1起始电压
  1042. // $data['end_voltage'] = round(base_convert(substr($res['msg'], 150,4), 16, 10)/10,1).''; // 智能功率USER1终止电压
  1043. // $data['end_current'] = round(base_convert(substr($res['msg'], 158,4), 16, 10)/100,2).''; // 智能功率USER1终止电流
  1044. $res = $data;
  1045. // }else{
  1046. // exit(json_result('0010', $this->response['0010']));
  1047. // }
  1048. }
  1049. // $res['load_current'] = number_format($res['load_current'],2);
  1050. // $res['end_current'] = number_format($res['end_current'],2);
  1051. // $res['end_voltage'] = number_format($res['end_voltage'],1);
  1052. // $res['begin_voltage'] = number_format($res['begin_voltage'],1);
  1053. $res['first_light_time'] = $this->format_date_en($res['first_light_time']*10);
  1054. $res['second_light_time'] = $this->format_date_en($res['second_light_time']*10);
  1055. $res['third_light_time'] = $this->format_date_en($res['third_light_time']*10);
  1056. $res['fourth_light_time'] = $this->format_date_en($res['fourth_light_time']*10);
  1057. $res['fifth_light_time'] = $this->format_date_en($res['fifth_light_time']*10);
  1058. $res['sixth_light_time'] = $this->format_date_en($res['sixth_light_time']*10);
  1059. $res['seventh_light_time'] = $this->format_date_en($res['seventh_light_time']*10);
  1060. $res['tenth_light_time'] = $this->format_date_en($res['tenth_light_time']*10);
  1061. // unset($res['id']);
  1062. // unset($res['updatetime']);
  1063. $data = $res;
  1064. exit(json_result('0000', $this->response['0000'], $data));
  1065. }
  1066. // 获取蓄电池设置
  1067. public function battery_setting() {
  1068. $lamp_id = $this->input->post('lamp_id', true);
  1069. if (empty($lamp_id)) {
  1070. exit(json_result('0400', $this->response['0400'], array()));
  1071. }
  1072. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'address,number,projectid');
  1073. $res = $this->send_cmd('11',$lampData['address'],'');
  1074. // $lampData = $this->Lamp_model->getData(array('id'=>$lamp_id),'projectid,address,number');
  1075. // var_dump($res);
  1076. if (!empty($res)) {
  1077. $info = unpack('H*', $res['msg'])[1];
  1078. set_log('battery_setting.txt',$info);
  1079. // $info = '91010000a8000100010c113e803c8c390831382f443390283c2ee0245403e8007800781e05a3412cec27101e010fc3';
  1080. $data['system_voltage'] = substr($info, 18,2) == 'ff' ? '0' : base_convert(substr($info, 18,2),16,10); // 电池电压
  1081. $data['battery_count'] = round(base_convert(substr($info, 20,1), 16, 10)); // 电池串数
  1082. $data['battery_type'] = round(base_convert(substr($info, 21,1), 16, 10)); //蓄电池类型
  1083. $data['overvoltage'] = round(base_convert(substr($info, 22,4), 16, 10)/1000,1); // 超压电压
  1084. $data['char_limit_voltage'] = round(base_convert(substr($info, 26,4), 16, 10)/1000,1); // 充电限制电压
  1085. $data['equ_char_voltage'] = round(base_convert(substr($info, 30,4), 16, 10)/1000,1); // 均衡充电电压
  1086. $data['increa_char_voltage'] = round(base_convert(substr($info, 34,4), 16, 10)/1000,1); // 提升充电电压
  1087. set_log('battery_setting.txt',substr($info, 34,4));
  1088. $data['float_char_voltage'] = round(base_convert(substr($info, 38,4), 16, 10)/1000,1); // 浮充充电电压
  1089. set_log('battery_setting.txt',substr($info, 38,4));
  1090. $data['increa_char_return_voltage'] = round(base_convert(substr($info, 42,4), 16, 10)/1000,1); // 提升充电返回电压
  1091. $data['over_dischar_return_voltage'] = round(base_convert(substr($info, 46,4), 16, 10)/1000,1); // 过放返回电压
  1092. $data['battery_under_voltage'] = round(base_convert(substr($info, 50,4), 16, 10)/1000,1); // 欠压警告电压 新增
  1093. $data['over_dischar_voltage'] = round(base_convert(substr($info, 54,4), 16, 10)/1000,1); // 过放电压
  1094. $data['discharge_limit_voltage'] = round(base_convert(substr($info, 58,4), 16, 10)/1000,1); // 放电限制电压 新增
  1095. $data['equ_char_time'] = round(base_convert(substr($info, 62,4), 16, 10)); // 均衡充电时间
  1096. $data['increa_char_time'] = round(base_convert(substr($info, 66,4), 16, 10)); // 提升充电时间
  1097. $data['balan_char_interval'] = round(base_convert(substr($info, 70,2), 16, 10)); // 均衡充电间隔
  1098. $data['temper_compen_coeff'] = round(base_convert(substr($info, 72,2), 16, 10)); // 温度补偿系数
  1099. $char_lower_limit_temper = base_convert(substr($info, 74,2), 16, 2); // 下限温度
  1100. if (substr(substr('00000000'.$char_lower_limit_temper, -8), 0,1) == 1) {
  1101. $data['char_lower_limit_temper'] = 0 - base_convert(substr('0000000'.$char_lower_limit_temper, -7), 2, 10);
  1102. }else{
  1103. $data['char_lower_limit_temper'] = round(base_convert($char_lower_limit_temper, 2, 10));
  1104. }
  1105. $char_upper_limit_temper = base_convert(substr($info, 76,2), 16, 2); // 上限温度
  1106. if (substr(substr('00000000'.$char_upper_limit_temper, -8), 0,1) == 1) {
  1107. $data['char_upper_limit_temper'] = 0 - base_convert(substr('0000000'.$char_upper_limit_temper, -7), 2, 10);
  1108. }else{
  1109. $data['char_upper_limit_temper'] = round(base_convert($char_upper_limit_temper, 2, 10));
  1110. }
  1111. $data['reduced_start_voltage'] = round(base_convert(substr($info, 78,4), 16, 10)/1000,1); // 智能功率起始电压
  1112. $data['reduced_stop_voltage'] = round(base_convert(substr($info, 82,4), 16, 10)/1000,1); // 智能功率结束电压
  1113. $data['light_voltage'] = round(base_convert(substr($info, 86,2), 16, 10)/10); // 光控电压
  1114. $data['light_delay_time'] = round(base_convert(substr($info, 88,2), 16, 10)*10); // 光控延时时间
  1115. exit(json_result('0000',$this->response['0000'],$data));
  1116. }else{
  1117. exit(json_result('0016',$this->response['0016']));
  1118. }
  1119. }
  1120. // 灯控相关数据
  1121. public function viewloglist() {
  1122. $lamp_id = $this->input->post('lamp_id',true);
  1123. $datatype = $this->input->post('datatype',true);
  1124. if (empty($lamp_id)) {
  1125. exit(json_result('0400', $this->response['0400'], array()));
  1126. }
  1127. if ($datatype == 'lampinfo') {
  1128. $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";
  1129. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1130. if (empty($res)) {
  1131. exit(json_result('0000', $this->response['0006'], array()));
  1132. }
  1133. $version = $this->session->userdata('version');
  1134. if (!empty($version)) {
  1135. $polemaType = ['冷镀锌'=>'Cold galvanizing','热镀锌'=>'Hot galvanizing','不锈钢'=>'Stainless steel'];
  1136. $lightType = ['LED灯'=>'LED lamp','钠灯'=>'Sodium lamp','节能灯'=>'Energy saving light'];
  1137. $lampType = ['太阳能路灯'=>'Solar street lamp','景观灯'=>'Landscape lamp','庭院灯'=>'Garden light'];
  1138. $boardType = ['单晶板'=>'Single crystal plate','多晶板'=>'Polycrystalline plate','非晶板'=>'Amorphous plate'];
  1139. $batteryType = ['铅酸电池'=>'Lead acid battery','锂电池'=>'Lithium battery'];
  1140. if (!preg_match('/^[A-Za-z\s*]+$/', $res['lamptype'])) {
  1141. $res['lamptype'] = empty($lampType[$res['lamptype']]) ? '' : $lampType[$res['lamptype']];
  1142. }
  1143. if (!preg_match('/^[A-Za-z\s*]+$/', $res['boardtype'])) {
  1144. $res['boardtype'] = empty($boardType[$res['boardtype']]) ? '' : $boardType[$res['boardtype']];
  1145. }
  1146. }else{
  1147. $polemaType = ['Cold galvanizing'=>'冷镀锌','Hot galvanizing'=>'热镀锌','Stainless steel'=>'不锈钢'];
  1148. $lightType = ['LED lamp'=>'LED灯','Sodium lamp'=>'钠灯','Energy saving light'=>'节能灯'];
  1149. $lampType = ['Solar street lamp'=>'太阳能路灯','Landscape lamp'=>'景观灯','Garden light'=>'庭院灯'];
  1150. $boardType = ['Single crystal plate'=>'单晶板','Polycrystalline plate'=>'多晶板','Amorphous plate'=>'非晶板'];
  1151. $batteryType = ['Lead acid battery'=>'铅酸电池','Lithium battery'=>'锂电池'];
  1152. if (preg_match('/^[A-Za-z\s*]+$/', $res['lamptype'])) {
  1153. $res['lamptype'] = empty($lampType[$res['lamptype']]) ? '' : $lampType[$res['lamptype']];
  1154. }
  1155. if (preg_match('/^[A-Za-z\s*]+$/', $res['boardtype'])) {
  1156. $res['boardtype'] = empty($boardType[$res['boardtype']]) ? '' : $boardType[$res['boardtype']];
  1157. }
  1158. }
  1159. // if ($res["isfaulted"] == 0) {
  1160. // $res["isfaulted"] = '正常';
  1161. // }else{
  1162. // }
  1163. // $alarmData = $this->Alarm_model->get_one_by_filter(array('lampid'=>$lamp_id,'status'=>0),'stralarmtype');
  1164. // $version = $this->session->userdata('version');
  1165. // if (empty($version)) {
  1166. // $res['isfaulted'] = empty($alarmData['stralarmtype']) ? '正常' : $alarmData['stralarmtype'];
  1167. // }else{
  1168. // $res['isfaulted'] = empty($alarmData['stralarmtype']) ? 'Normal' : alarm_translate($alarmData['stralarmtype']);
  1169. // }
  1170. $timezone = $this->Project_model->get_timezone_by_projectid($res['projectid']);
  1171. $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
  1172. $projectname = $this->Project_model->get_one(['id'=>$res['projectid']],'projectname');
  1173. $supplier_name = '';
  1174. $model_name = '';
  1175. if (!empty($res['supplier'])) {
  1176. $com = $this->Company_model->get_one(['id'=>$res['supplier']],'name,no');
  1177. if (empty($com['name']) && empty($com['no'])){
  1178. $supplier_name = '';
  1179. }else{
  1180. $supplier_name = empty($com['no']) ? $com['name'] : $com['no'];
  1181. }
  1182. }
  1183. if ($res['model']) {
  1184. $model_info = $this->db->query('select * from model_info where id = '.$res['model'])->row_array();
  1185. if (!empty($model_info) && !empty($model_info['name'])) {
  1186. $model_name = $model_info['name'];
  1187. }
  1188. }
  1189. $data = array(
  1190. "lamp_no" => $res["number"],
  1191. "project_name" => $this->Project_model->getNameById($res["projectid"]),
  1192. "address" => $res["address"],
  1193. "longitude" => $res["longitude"],
  1194. "latitude" => $res["latitude"],
  1195. "isfaulted" => $res["devstatus"],
  1196. "section" => $res["section"],
  1197. "boardpower" => floatval($res["boardpower"]),
  1198. "lamptype" => $res['lamptype'],
  1199. "boardtype" => $res['boardtype'],
  1200. "batteryah" => $res["batteryah"],
  1201. "loadpower" => $res["loadpower"],
  1202. 'status' => $res['status'],
  1203. // 'batterytype' => $res['batterytype'],
  1204. 'protocoltype'=>intval($res['protocoltype']),
  1205. 'supplier'=>intval($res['supplier']),
  1206. 'upazilla'=>intval($res['upazilla']),
  1207. 'po'=>intval($res['po']),
  1208. 'manu'=>intval($res['manu']),
  1209. "updatetime" => $res["updatetime"],
  1210. 'loadtype' => $res['loadtype'],
  1211. 'power' => $res['power'],
  1212. 'model' => $res['model'],
  1213. 'fascal_year' => $res['fascal_year'],
  1214. 'fascal_year_phase' => $res['fascal_year_phase'],
  1215. 'iccid' => $res['iccid'],
  1216. 'projectname' => $projectname['projectname'],
  1217. 'projectid' => $res['projectid'],
  1218. 'softwareVersion' => $res['softwareVersion'],
  1219. 'supplier_name' => $supplier_name,
  1220. 'model_name' => $model_name,
  1221. );
  1222. // $msisdn = $this->db->query('select iccid from msisdn where imsi = "'.$res['simid'].'"')->row_array();
  1223. // if (empty($msisdn) || empty($msisdn['iccid'])) {
  1224. // $data['iccid'] = '';
  1225. // }else{
  1226. // $data['iccid'] = $msisdn['iccid'];
  1227. // }
  1228. // if ($res['protocoltype'] != 1 && $res['protocoltype'] != 2) {
  1229. // unset($data['packageSurplus']);
  1230. // unset($data['simid']);
  1231. // }
  1232. // $username = $this->get_user_info('username');
  1233. // if ($username == 'zns') {
  1234. // $data['monthly_can_usage'] = intval($res['monthly_can_usage']);
  1235. // $data['monthly_already_usage'] = round($res['monthly_already_usage'],2);
  1236. // }
  1237. exit(json_result('0000', $this->response['0000'], $data));
  1238. }elseif ($datatype == 'lamp_info_log') {
  1239. $fields = "lighteness,status as lampstatus,lampvoltage,lampcurrent,lamppower,lamptemper as temper";
  1240. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1241. exit(json_result('0000', $this->response['0000'], $res));
  1242. }elseif ($datatype == 'solar_info_log') {
  1243. $fields = "solarvoltage,solarcurrent,solarpower";
  1244. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1245. exit(json_result('0000', $this->response['0000'], $res));
  1246. }elseif ($datatype == 'battery_info_log') {
  1247. // $fields = "battstatus,chargestage,battvoltage,chargecurrent,discharcurrent,chargepower,dischargepower,batttemper,electrictotal,electricleft,electricSOC,voltagedaymin,voltagedaymax,daychargeah,daydischarah,daychargemaxpow,daydischarmaxpow,daychargemincurrent,daycharmaxcurrent,daydischargemincurrent,daydischarmaxcurrent,daybattmintemper,daybattmaxtemper";
  1248. $fields = "*";
  1249. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1250. // $res["updatetime"] = date_change($res["updatetime"],0,DEF_TIMEZONE);
  1251. exit(json_result('0000', $this->response['0000'], $res));
  1252. }elseif ($datatype == 'system_info_log') {
  1253. $fields = "sysvoltage,syscurrent,temper,updatetime,id,number as lampid";
  1254. $res = $this->Lamp_model->get_one(['id'=>$lamp_id],$fields);
  1255. exit(json_result('0000', $this->response['0000'], $res));
  1256. }
  1257. // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log');
  1258. // $table = in_array($datatype, $table_map) ? $datatype : 'system_info_log';
  1259. // $res = $this->Lamp_model->getForInfoLog($lamp_id, $table);
  1260. // $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid');
  1261. // $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
  1262. // if(!$res){
  1263. // exit(json_result('0000', $this->response['0006'], array()));
  1264. // }
  1265. // if ($table == 'battery_info_log') {
  1266. // if (isset($res['daydischargemincurrent'])) {
  1267. // $h = floor($res['daydischargemincurrent']/3600);
  1268. // $h = $h < 10 ? '0'.$h : $h;
  1269. // $i = intval($res['daydischargemincurrent']/60)%60;
  1270. // $i = $i < 10 ? '0'.$i : $i;
  1271. // $res['daydischargemincurrent'] = $h.':'.$i;
  1272. // }
  1273. // if (isset($res['daychargemincurrent'])) {
  1274. // $h = floor($res['daychargemincurrent']/3600);
  1275. // $h = $h < 10 ? '0'.$h : $h;
  1276. // $i = intval($res['daychargemincurrent']/60)%60;
  1277. // $i = $i < 10 ? '0'.$i : $i;
  1278. // $res['daychargemincurrent'] = $h.':'.$i;
  1279. // }
  1280. // }
  1281. // $res["updatetime"] = date_change($res["updatetime"],8,$timezone['value']);
  1282. // exit(json_result('0000', $this->response['0000'], $res));
  1283. }
  1284. // 灯控历史数据
  1285. public function historylist() {
  1286. $lamp_id = $this->input->post('lamp_id',true);
  1287. $datatype = $this->input->post('datatype',true);
  1288. $page = intval($this->input->post('page',true));
  1289. $count = intval($this->input->post('count',true));
  1290. $count = empty($count) ? 16 : $count;
  1291. if (empty($lamp_id)) {
  1292. exit(json_result('0400', $this->response['0400'], array()));
  1293. }
  1294. $date = $this->input->post('date',true);
  1295. $beginDate = '';
  1296. $endDate = '';
  1297. // 按时区修改时间
  1298. $lampData = $this->Lamp_model->get_one(['id'=>$lamp_id],'projectid,protocoltype');
  1299. $timezone = $this->Project_model->get_timezone_by_projectid($lampData['projectid']);
  1300. if (!empty($date)) {
  1301. $dateArr = explode('/', $date);
  1302. $beginDate = date('Y-m-d H:i:s',strtotime($dateArr[0]) - 8*3600);
  1303. $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',strtotime($dateArr[1]))) - 8*3600);
  1304. // $beginDate = $dateArr[0];
  1305. // $endDate = $dateArr[1];
  1306. if (strtotime($endDate) - strtotime($beginDate) > 31*24*3600) {
  1307. exit(json_result('0418',$this->response['0418']));
  1308. }
  1309. }else{
  1310. $beginDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 8*3600);
  1311. $endDate = date('Y-m-d H:i:s',strtotime(date('Y-m-d 23:59:59',time())) - 8*3600);
  1312. }
  1313. if($page < 1){
  1314. $page = 1;
  1315. }
  1316. $download = intval($this->input->post('download'));
  1317. if (!empty($download)) {
  1318. if (empty($date)) exit(json_result('0007',$this->response['0007']));
  1319. $dataList = array();
  1320. // 路灯
  1321. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'lamp_info_log', null, null,$beginDate,$endDate);
  1322. $temp = array();
  1323. $i = 1;
  1324. if (empty($this->version)) {
  1325. $lampStatusArr = array(0=>'关灯',1=>'开灯');
  1326. $title = array('序号','亮度%','状态','电压(V)','电流(A)','功率(W)','当天放电最大功率(W)','当天亮灯时长(HH:MM)','更新时间');
  1327. $name = '路灯';
  1328. }else{
  1329. $lampStatusArr = array(0=>'off',1=>'on');
  1330. $title = array('Number','Brightness%','Status','Voltage(V)','Current(A)','Power(W)','Maximum discharge power of the day(W)','dayLighting duration(HH:MM)','Update time');
  1331. $name = 'Lamp';
  1332. }
  1333. foreach ($lampInfoList as $k=>$l) {
  1334. $temp[$k][] = $i;
  1335. $temp[$k][] = $l['lighteness'];
  1336. $temp[$k][] = $lampStatusArr[$l['lampstatus']];
  1337. $temp[$k][] = $l['lampvoltage'];
  1338. $temp[$k][] = $l['lampcurrent'];
  1339. $temp[$k][] = $l['lamppower'];
  1340. $temp[$k][] = $l['daydischarmaxpow'];
  1341. $h = floor($l['daychargemincurrent'] / 3600);
  1342. $h = $h < 10 ? '0'.$h : $h;
  1343. $m = ceil($l['daychargemincurrent'] % 3600 / 60);
  1344. $m = $m < 10 ? '0'.$m : $m;
  1345. $temp[$k][] = $h.':'.$m;
  1346. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1347. $i ++;
  1348. }
  1349. $title1 = [];
  1350. foreach ($title as $t) {
  1351. $title1[0][] = $t;
  1352. }
  1353. $data = array_merge($title1,$temp);
  1354. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1355. // 蓄电池
  1356. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'battery_info_log', null, null,$beginDate,$endDate);
  1357. $temp = array();
  1358. $i = 1;
  1359. if (empty($this->version)) {
  1360. $name = '蓄电池';
  1361. if ($lampData['protocoltype'] == 2) {
  1362. $chargeStageMap = array(0=>'没有充电',1=>'等待',2=>'初始',3=>'MPPT',4=>'恒压',5=>'恒流',6=>'浮充',7=>'均衡',8=>'提升',9=>'涓流',10=>'完成',''=>'未知状态');
  1363. }else{
  1364. $chargeStageMap = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
  1365. }
  1366. $battstatusArr = array(0=>'空闲',1=>'放电',2=>'充电',3=>'一边充电一边放电',''=>'未知状态');
  1367. $unknown = '未知状态';
  1368. $title = array('序号','系统电压(V)','系统电流(A)','MOS温度(℃)','电池状态','充电阶段','电池电压(V)','当天最低电压(V)','当天最高电压(V)','电池温度(℃)','当天电池最低温度(℃)','当天电池最高温度(℃)','更新时间');
  1369. }else{
  1370. $name = 'Battery';
  1371. if ($lampData['protocoltype'] == 2) {
  1372. $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');
  1373. }else{
  1374. $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');
  1375. }
  1376. $battstatusArr = array(0=>'Free',1=>'Discharge',2=>'Charge',3=>'Discharge while charging',''=>'Unknown state');
  1377. $unknown = 'Unknown state';
  1378. $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');
  1379. }
  1380. $indexArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  1381. foreach ($lampInfoList as $k=>$l) {
  1382. $temp[$k][] = $i;
  1383. $temp[$k][] = $l['sysvoltage'];
  1384. $temp[$k][] = $l['syscurrent'];
  1385. $temp[$k][] = $l['temper'];
  1386. $temp[$k][] = $battstatusArr[$l['battstatus']];
  1387. if ($lampData['protocoltype'] == 1) {
  1388. $l['chargestage'] = isset($indexArr[intval($l['chargestage'])]) ? $indexArr[intval($l['chargestage'])] : $l['chargestage'];
  1389. }
  1390. $temp[$k][] = $chargeStageMap[$l['chargestage']];
  1391. $temp[$k][] = $l['battvoltage'];
  1392. $temp[$k][] = $l['voltagedaymin'];
  1393. $temp[$k][] = $l['voltagedaymax'];
  1394. $temp[$k][] = $l['batttemper'];
  1395. $temp[$k][] = $l['daybattmintemper'];
  1396. $temp[$k][] = $l['daybattmaxtemper'];
  1397. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1398. $i ++;
  1399. }
  1400. $title1 = [];
  1401. foreach ($title as $t) {
  1402. $title1[0][] = $t;
  1403. }
  1404. $data = array_merge($title1,$temp);
  1405. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1406. // 太阳能
  1407. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'solar_info_log', null, null,$beginDate,$endDate);
  1408. $temp = array();
  1409. $i = 1;
  1410. if (empty($this->version)) {
  1411. $name = '太阳能';
  1412. $title = array('序号','电压(V)','电流(A)','功率(W)','当天充电最大功率(WH)','当天充电时长(HH:MM)','更新时间');
  1413. }else{
  1414. $name = 'Solar';
  1415. $title = array('Number','Voltage(V)','Current(A)','Power(W)','Maximum Power Charged on the Day(W)','day Charging time(HH:MM)','Update time');
  1416. }
  1417. foreach ($lampInfoList as $k=>$l) {
  1418. $temp[$k][] = $i;
  1419. $temp[$k][] = $l['solarvoltage'];
  1420. $temp[$k][] = $l['solarcurrent'];
  1421. $temp[$k][] = $l['solarpower'];
  1422. $temp[$k][] = $l['daychargemaxpow'];
  1423. $h = floor($l['daydischargemincurrent'] / 3600);
  1424. $h = $h < 10 ? '0'.$h : $h;
  1425. $m = ceil($l['daydischargemincurrent'] % 3600 / 60);
  1426. $m = $m < 10 ? '0'.$m : $m;
  1427. $temp[$k][] = $h.':'.$m;
  1428. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1429. $i ++;
  1430. }
  1431. $title1 = [];
  1432. foreach ($title as $t) {
  1433. $title1[0][] = $t;
  1434. }
  1435. $data = array_merge($title1,$temp);
  1436. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1437. // 系统
  1438. $lampInfoList = $this->Lamp_model->getListForInfoLog($lamp_id, 'system_info_log', null, null,$beginDate,$endDate);
  1439. $temp = array();
  1440. $i = 1;
  1441. if (empty($this->version)) {
  1442. $name = '系统';
  1443. $title = array('序号','系统电压(V)','系统电流(A)','控制器温度(℃)','更新时间');
  1444. }else{
  1445. $name = 'System';
  1446. $title = array('Serial number','System voltage(V)','System current(A)','Control temperature(℃)','Update time');
  1447. }
  1448. foreach ($lampInfoList as $k=>$l) {
  1449. $temp[$k][] = $i;
  1450. $temp[$k][] = $l['sysvoltage'];
  1451. $temp[$k][] = $l['syscurrent'];
  1452. $temp[$k][] = $l['temper'];
  1453. $temp[$k][] = date_change($l["updatetime"],8,$timezone['value']);
  1454. $i ++;
  1455. }
  1456. $title1 = [];
  1457. foreach ($title as $t) {
  1458. $title1[0][] = $t;
  1459. }
  1460. $data = array_merge($title1,$temp);
  1461. $dataList[] = array('name'=>$name,'dataList'=>$data);
  1462. $path = push_excel($dataList,'historyInfoExcel_'.date('Ymd'),1);
  1463. exit(json_result('0000', $this->response['0000'], array('path'=>$path)));
  1464. }
  1465. // $table_map = array('system_info_log','lamp_info_log','solar_info_log','battery_info_log','electric_info_log','history_info_log');
  1466. $table = !empty($datatype) ? $datatype : 'system_info_log';
  1467. if ($table == 'lamp_info_log') {
  1468. $table = 'realtime_info_log';
  1469. $total = $this->RealtimeInfoLog_model->get_count(['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate]);
  1470. $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);
  1471. // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
  1472. }elseif ($table == 'system_info_log') {
  1473. $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
  1474. $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
  1475. }elseif ($table == 'battery_info_log') {
  1476. $join = [
  1477. // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
  1478. ];
  1479. $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
  1480. $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
  1481. $fields = 'batvoltage as battvoltage,chgtemper as batttemper,updatetime,DayOverDisChgTimes as overtimes,battstatus,chargestage,voltagedaymin,voltagedaymax,daybattmintemper,daybattmaxtemper';
  1482. $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
  1483. }else{
  1484. $join = [
  1485. // ['table'=>'history_info_log as HI','cond'=>'HI.lampid = RI.lampid and HI.updatetime = RI.updatetime','type'=>'inner'],
  1486. ];
  1487. $where = ['lampid'=>$lamp_id,'updatetime >='=>$beginDate,'updatetime <='=>$endDate];
  1488. $total = $this->RealtimeInfoLog_model->get_count($where,'count(*) as total');
  1489. $fields = 'panelvoltage as solarvoltage,updatetime,panelcurrent as solarcurrent,panelpower as solarpower,daychargemaxpow';
  1490. $res = $this->RealtimeInfoLog_model->get_list($where, $fields,$count, ($page-1)*$count, 'updatetime desc,id desc');
  1491. // $total = $this->Lamp_model->getCountForInfoLog($lamp_id, $table,$beginDate,$endDate);
  1492. // $res = $this->Lamp_model->getListForInfoLog($lamp_id, $table, ($page-1)*$count, $count,$beginDate,$endDate);
  1493. }
  1494. if(!$res){
  1495. exit(json_result('0000', $this->response['0006'], array()));
  1496. }else{
  1497. $arr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  1498. foreach ($res as &$v) {
  1499. if (isset($v['lighteness'])) {
  1500. $v['lampstatus'] = empty($v['lighteness']) ? '0' : '1';
  1501. }
  1502. if (isset($v['daychargemincurrent'])) $v['daychargemincurrent'] = intval($v['daychargemincurrent']);
  1503. // $v['updatetime'] = date_change($v["updatetime"],8,$timezone['value']);
  1504. $v['updatetime'] = set_timezone($v["updatetime"],$timezone['value']);
  1505. if ($lampData['protocoltype'] == 1 && $table == 'battery_info_log') {
  1506. $v['chargestage'] = isset($arr[intval($v['chargestage'])]) ? $arr[intval($v['chargestage'])] : $v['chargestage'];
  1507. }
  1508. if ($table == 'system_info_log') {
  1509. $v['lampid'] = $v['number'];
  1510. }
  1511. }
  1512. }
  1513. $data = array(
  1514. 'total' => ceil($total/$count),
  1515. 'list' => $res
  1516. );
  1517. exit(json_result('0000', $this->response['0000'], $data));
  1518. }
  1519. // 修改路灯位置
  1520. public function change_location(){
  1521. $id = intval($this->input->post('id',true));
  1522. $type = intval($this->input->post('type',true));
  1523. $data['longitude'] = $this->input->post('longitude',true);
  1524. $data['latitude'] = $this->input->post('latitude',true);
  1525. $data['updatetime'] = date('Y-m-d H:i:s',time());
  1526. if (empty($id) || empty($type) || !isset($data['longitude']) || !isset($data['latitude'])) {
  1527. exit(json_result('0007',$this->response['0007'],array()));
  1528. }
  1529. if ($type == 1) {
  1530. $this->Lamp_model->update($data,array('id'=>$id));
  1531. }else{
  1532. $this->Videomonitor_model->update($data,array('id'=>$id));
  1533. }
  1534. exit(json_result('0000',$this->response['0000'],array()));
  1535. }
  1536. // 同步巡检
  1537. public function set_patrol_cmd(){
  1538. $id = intval($this->input->post('id',true));
  1539. if (empty($id)) exit(json_result('0007',$this->response['0007'],array('id'=>$id)));
  1540. $lampData = $this->Lamp_model->getOne($id,'N.status,N.protocoltype,L.address,L.protocoltype as lampprotocoltype,L.number');
  1541. $cmd = '{"cmd_type":"set_sync_patrol_cmd","cmd_id":'.$id.'}';
  1542. $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
  1543. if ($cmdret === false) {
  1544. sleep(1);
  1545. $cmdret = send_cmd($cmd,0,30,$lampData['protocoltype']);
  1546. }
  1547. exit(json_result('0000',$this->response['0000'],array('id'=>$id)));
  1548. }
  1549. // 批量添加
  1550. public function batchInput(){
  1551. set_time_limit(0);
  1552. $userid = $this->get_user_info('id');
  1553. // $idArr = $this->get_section_by_user();
  1554. $role = $this->get_user_info('role');
  1555. $company = $this->get_user_info('company');
  1556. $type = intval($this->input->post('type',true));
  1557. $projectid = intval($this->input->post('projectid',true));
  1558. if (empty($projectid)) exit(json_result('0007',$this->response['0007']));
  1559. if ($type == 1) { // 验证
  1560. $indexArr = ['A'=>'number','B'=>'address','C'=>'section'];
  1561. $data = $this->batch_import($indexArr);
  1562. }else{ // 创建
  1563. $data = $this->input->post('lampData',true);
  1564. if (empty($data)) exit(json_result('0007',$this->response['0007']));
  1565. $data = json_decode($data,true);
  1566. }
  1567. $res = 0;
  1568. $this->db->trans_begin();
  1569. $msg = [];
  1570. $patrol_arr = array();
  1571. foreach ($data as $key => $value) {
  1572. $num = $key+2;
  1573. $value['number'] = trim($value['number']);
  1574. if (!isset($value['number']) || $value['number'] == '') {
  1575. $res = 1;
  1576. if (empty($this->version)) {
  1577. $msg[] = '表格第'.$num.'行,路灯编号不能为空';
  1578. }else{
  1579. $msg[] = 'Table '.$num.' row.Lamp number can not be empty';
  1580. }
  1581. }else{
  1582. if (!is_numeric($value['number']) && ($value['number'] <= 0 || $value['number'] > 999999)) {
  1583. $res = 1;
  1584. if (empty($this->version)) {
  1585. $msg[] = '表格第'.$num.'行,路灯编号为1-999999的数字';
  1586. }else{
  1587. $msg[] = 'Table '.$num.' row.The number of street lamps numbered 1-999999';
  1588. }
  1589. }
  1590. }
  1591. $value['address'] = trim($value['address']);
  1592. if (empty($value['address'])) {
  1593. $res = 1;
  1594. $msg[] = 'Table '.$num.' row.Address of the wireless module can not be empty';
  1595. }else{
  1596. $status = preg_match('/^[A-Fa-f0-9]+$/', $value['address']);
  1597. if (empty($status)) {
  1598. $res = 1;
  1599. $msg[] = 'Table '.$num.' row.Wireless module address is 16 hexadecimal';
  1600. }else{
  1601. if ($this->Lamp_model->getDataCount(['address'=>$value['address']])) {
  1602. $res = 1;
  1603. $msg[] = 'Table '.$num.' row.Wireless module address already exists';
  1604. }
  1605. if ($role != SYSTEM_ADMIN) {
  1606. if ($role == 2) {
  1607. $value["manu"] = $company;
  1608. }elseif ($role == 4) {
  1609. $value["po"] = $company;
  1610. }
  1611. }
  1612. if (!isset($value["manu"])) $value["manu"] = $this->get_manu_by_address($value["address"]);
  1613. }
  1614. }
  1615. $value['section'] = trim($value['section']);
  1616. $value['createtime'] = date('Y-m-d H:i:s',time());
  1617. $value['projectid'] = $projectid;
  1618. if ($type != 1) {
  1619. $this->Lamp_model->add($value);
  1620. $this->Project_model->add_lamp_count(['projectid'=>$projectid]);
  1621. }
  1622. }
  1623. if ($res || $type == 1) {
  1624. $this->db->trans_rollback();
  1625. exit(json_result('0000',$this->response['0000'],['lampData'=>$data,'msg'=>$msg]));
  1626. }else{
  1627. $this->db->trans_commit();
  1628. exit(json_result('0000',$this->response['0000']));
  1629. }
  1630. }
  1631. // 路灯历史数据曲线图
  1632. public function lamp_history_data(){
  1633. $type = intval($this->input->post('type',true));
  1634. $lampId = intval($this->input->post('lampid',true));
  1635. if (empty($lampId)) exit(json_result('0007',$this->response['0007']));
  1636. $dateType = intval($this->input->post('dateType',true));
  1637. $date = $this->input->post('date',true);
  1638. if ($dateType == 0) { // 一天
  1639. $beginDate = date('Y-m-d H:i:s',time()-24*3600);
  1640. $endDate = date('Y-m-d H:i:s',time());
  1641. }elseif ($dateType == 1) { // 三天
  1642. $beginDate = date('Y-m-d H:i:s',time()-24*3600*3);
  1643. $endDate = date('Y-m-d H:i:s',time());
  1644. }elseif ($dateType == 2) { // 七天
  1645. $beginDate = date('Y-m-d H:i:s',time()-24*3600*7);
  1646. $endDate = date('Y-m-d H:i:s',time());
  1647. }elseif ($dateType == 3) { // 十四天
  1648. $beginDate = date('Y-m-d H:i:s',time()-24*3600*14);
  1649. $endDate = date('Y-m-d H:i:s',time());
  1650. }else{ // 选择时间
  1651. if (empty($date)) exit(json_result('0007',$this->response['0007']));
  1652. $res = explode('/', $date);
  1653. if (strtotime($res[1]) - strtotime($res[0]) > 31 * 24 * 3600) {
  1654. exit(json_result('0418',$this->response['0418']));
  1655. }
  1656. $beginDate = $res[0];
  1657. $endDate = date('Y-m-d 23:59:59',strtotime($res[1]));
  1658. // var_dump($endDate);die;
  1659. }
  1660. $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";
  1661. $lampData = $this->db->query($sql)->row_array();
  1662. $timezoneData = $this->Project_model->get_timezone_by_projectid($lampData['id']);
  1663. $timezone = $timezoneData['value'];
  1664. $beginDate = date('Y-m-d H:i:s',strtotime($beginDate) - $timezone * 3600);
  1665. $endDate = date('Y-m-d H:i:s',strtotime($endDate) - $timezone * 3600);
  1666. $data = ['patrolinterval'=>$lampData['patrolinterval']];
  1667. if ($type == 0) { // 路灯
  1668. $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.'"';
  1669. $list = $this->db->query($sql)->result_array();
  1670. $temp = [];
  1671. foreach ($list as $value) {
  1672. $temp['lampvoltage'][] = $value['lampvoltage'];
  1673. $temp['lampcurrent'][] = $value['lampcurrent'];
  1674. $temp['lamppower'][] = $value['lamppower'];
  1675. $temp['lighteness'][] = $value['lighteness'];
  1676. $temp['updatetime'][] = date_change($value['updatetime'],0,$timezone);
  1677. if (!isset($data['maxcurrent'])) {
  1678. $data['maxcurrent'] = $value['lampcurrent'];
  1679. }else{
  1680. $data['maxcurrent'] = $value['lampcurrent'] > $data['maxcurrent'] ? $value['lampcurrent'] : $data['maxcurrent'];
  1681. }
  1682. // if (!isset($data['maxdaychargemincurrent'])) {
  1683. // $data['maxdaychargemincurrent'] = $value['daychargemincurrent'];
  1684. // }else{
  1685. // $data['maxdaychargemincurrent'] = $value['daychargemincurrent'] > $data['maxdaychargemincurrent'] ? $value['daychargemincurrent'] : $data['maxdaychargemincurrent'];
  1686. // }
  1687. if (!isset($data['mincurrent'])) {
  1688. $data['mincurrent'] = $value['lampcurrent'];
  1689. }else{
  1690. $data['mincurrent'] = $value['lampcurrent'] < $data['mincurrent'] ? $value['lampcurrent'] : $data['mincurrent'];
  1691. }
  1692. if (!isset($data['maxvoltage'])) {
  1693. $data['maxvoltage'] = $value['lampvoltage'];
  1694. }else{
  1695. $data['maxvoltage'] = $value['lampvoltage'] > $data['maxvoltage'] ? $value['lampvoltage'] : $data['maxvoltage'];
  1696. }
  1697. if (!isset($data['minvoltage'])) {
  1698. $data['minvoltage'] = $value['lampvoltage'];
  1699. }else{
  1700. $data['minvoltage'] = $value['lampvoltage'] < $data['minvoltage'] ? $value['lampvoltage'] : $data['minvoltage'];
  1701. }
  1702. if (!isset($data['maxpower'])) {
  1703. $data['maxpower'] = $value['lamppower'];
  1704. }else{
  1705. $data['maxpower'] = $value['lamppower'] > $data['maxpower'] ? $value['lamppower'] : $data['maxpower'];
  1706. }
  1707. if (!isset($data['minpower'])) {
  1708. $data['minpower'] = $value['lamppower'];
  1709. }else{
  1710. $data['minpower'] = $value['lamppower'] < $data['minpower'] ? $value['lamppower'] : $data['minpower'];
  1711. }
  1712. if (!isset($data['maxlighteness'])) {
  1713. $data['maxlighteness'] = $value['lighteness'];
  1714. }else{
  1715. $data['maxlighteness'] = $value['lighteness'] > $data['maxlighteness'] ? $value['lighteness'] : $data['maxlighteness'];
  1716. }
  1717. if (!isset($data['minlighteness'])) {
  1718. $data['minlighteness'] = $value['lighteness'];
  1719. }else{
  1720. $data['minlighteness'] = $value['lighteness'] < $data['minlighteness'] ? $value['lighteness'] : $data['minlighteness'];
  1721. }
  1722. // if (isset($data['maxdaychargemincurrent'])) {
  1723. // $h = floor($data['maxdaychargemincurrent'] / 3600);
  1724. // $h = $h < 10 ? '0'.$h : $h;
  1725. // $m = floor($data['maxdaychargemincurrent'] / 3600 % 60);
  1726. // $m = $m < 10 ? '0'.$m : $m;
  1727. // $data['maxdaychargemincurrent'] = $h.':'.$m;
  1728. // }
  1729. }
  1730. $list = $temp;
  1731. }elseif ($type == 1) { // 蓄电池
  1732. $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.'"';
  1733. $list = $this->db->query($sql)->result_array();
  1734. $temp = [];
  1735. foreach ($list as $value) {
  1736. $temp['battvoltage'][] = $value['battvoltage'];
  1737. $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
  1738. $batterycurrent = $value['chargecurrent'];
  1739. $temp['batterycurrent'][] = $batterycurrent;
  1740. $batterypower = $value['chargepower'];
  1741. $temp['batterypower'][] = $batterypower;
  1742. if (!isset($data['maxcurrent'])) {
  1743. $data['maxcurrent'] = $batterycurrent;
  1744. }else{
  1745. $data['maxcurrent'] = $batterycurrent > $data['maxcurrent'] ? $batterycurrent : $data['maxcurrent'];
  1746. }
  1747. if (!isset($data['mincurrent'])) {
  1748. $data['mincurrent'] = $batterycurrent;
  1749. }else{
  1750. $data['mincurrent'] = $batterycurrent < $data['mincurrent'] ? $batterycurrent : $data['mincurrent'];
  1751. }
  1752. if (!isset($data['maxvoltage'])) {
  1753. $data['maxvoltage'] = $value['battvoltage'];
  1754. }else{
  1755. $data['maxvoltage'] = $value['battvoltage'] > $data['maxvoltage'] ? $value['battvoltage'] : $data['maxvoltage'];
  1756. }
  1757. if (!isset($data['minvoltage'])) {
  1758. $data['minvoltage'] = $value['battvoltage'];
  1759. }else{
  1760. $data['minvoltage'] = $value['battvoltage'] < $data['minvoltage'] ? $value['battvoltage'] : $data['minvoltage'];
  1761. }
  1762. if (!isset($data['maxbatttemper'])) {
  1763. $data['maxbatttemper'] = $value['batttemper'];
  1764. }else{
  1765. $data['maxbatttemper'] = $value['batttemper'] > $data['maxbatttemper'] ? $value['batttemper'] : $data['maxbatttemper'];
  1766. }
  1767. if (!isset($data['minbatttemper'])) {
  1768. $data['minbatttemper'] = $value['batttemper'];
  1769. }else{
  1770. $data['minbatttemper'] = $value['batttemper'] < $data['minbatttemper'] ? $value['batttemper'] : $data['minbatttemper'];
  1771. }
  1772. if (!isset($data['maxpower'])) {
  1773. $data['maxpower'] = round($batterypower,2);
  1774. }else{
  1775. $data['maxpower'] = $batterypower > $data['maxpower'] ? round($batterypower,2) : round($data['maxpower'],2);
  1776. }
  1777. if (!isset($data['minpower'])) {
  1778. $data['minpower'] = round($batterypower,2);
  1779. }else{
  1780. $data['minpower'] = $batterypower < $data['minpower'] ? round($batterypower,2) : round($data['minpower'],2);
  1781. }
  1782. }
  1783. $list = $temp;
  1784. }elseif ($type == 2) { // 太阳能板
  1785. $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.'"';
  1786. $list = $this->db->query($sql)->result_array();
  1787. $temp = [];
  1788. foreach ($list as $value) {
  1789. $temp['solarvoltage'][] = $value['solarvoltage'];
  1790. $temp['solarcurrent'][] = $value['solarcurrent'];
  1791. $temp['solarpower'][] = $value['solarpower'];
  1792. $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
  1793. if (!isset($data['maxcurrent'])) {
  1794. $data['maxcurrent'] = $value['solarcurrent'];
  1795. }else{
  1796. $data['maxcurrent'] = $value['solarcurrent'] > $data['maxcurrent'] ? $value['solarcurrent'] : $data['maxcurrent'];
  1797. }
  1798. if (!isset($data['mincurrent'])) {
  1799. $data['mincurrent'] = $value['solarcurrent'];
  1800. }else{
  1801. $data['mincurrent'] = $value['solarcurrent'] < $data['mincurrent'] ? $value['solarcurrent'] : $data['mincurrent'];
  1802. }
  1803. if (!isset($data['maxvoltage'])) {
  1804. $data['maxvoltage'] = $value['solarvoltage'];
  1805. }else{
  1806. $data['maxvoltage'] = $value['solarvoltage'] > $data['maxvoltage'] ? $value['solarvoltage'] : $data['maxvoltage'];
  1807. }
  1808. // if (!isset($data['maxdaydischargemincurrent'])) {
  1809. // $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'];
  1810. // }else{
  1811. // $data['maxdaydischargemincurrent'] = $value['daydischargemincurrent'] > $data['maxdaydischargemincurrent'] ? $value['daydischargemincurrent'] : $data['maxdaydischargemincurrent'];
  1812. // }
  1813. if (!isset($data['minvoltage'])) {
  1814. $data['minvoltage'] = $value['solarvoltage'];
  1815. }else{
  1816. $data['minvoltage'] = $value['solarvoltage'] < $data['minvoltage'] ? $value['solarvoltage'] : $data['minvoltage'];
  1817. }
  1818. if (!isset($data['maxpower'])) {
  1819. $data['maxpower'] = $value['solarpower'];
  1820. }else{
  1821. $data['maxpower'] = $value['solarpower'] > $data['maxpower'] ? $value['solarpower'] : $data['maxpower'];
  1822. }
  1823. if (!isset($data['minpower'])) {
  1824. $data['minpower'] = $value['solarpower'];
  1825. }else{
  1826. $data['minpower'] = $value['solarpower'] < $data['minpower'] ? $value['solarpower'] : $data['minpower'];
  1827. }
  1828. if (isset($data['maxdaydischargemincurrent'])) {
  1829. $h = floor($data['maxdaydischargemincurrent'] / 3600);
  1830. $h = $h < 10 ? '0'.$h : $h;
  1831. $m = floor($data['maxdaydischargemincurrent'] / 3600 % 60);
  1832. $m = $m < 10 ? '0'.$m : $m;
  1833. $data['maxdaydischargemincurrent'] = $h.':'.$m;
  1834. }
  1835. }
  1836. $list = $temp;
  1837. }else{ // 电量
  1838. $sql = 'select chargeday as daychargeah,dischargeday as daydischarah,updatetime from realtime_info_log where lampid = '.$lampId.' and updatetime >= "'.$beginDate.'" and updatetime <= "'.$endDate.'"';
  1839. $list = $this->db->query($sql)->result_array();
  1840. $temp = [];
  1841. foreach ($list as $value) {
  1842. $temp['daychargeah'][] = $value['daychargeah'];
  1843. $temp['daydischarah'][] = $value['daydischarah'];
  1844. $temp['updatetime'][] = date_change($value['updatetime'],8,$timezone);
  1845. if (!isset($data['maxdaychargeah'])) {
  1846. $data['maxdaychargeah'] = $value['daychargeah'];
  1847. }else{
  1848. $data['maxdaychargeah'] = $value['daychargeah'] > $data['maxdaychargeah'] ? $value['daychargeah'] : $data['maxdaychargeah'];
  1849. }
  1850. if (!isset($data['mindaychargeah'])) {
  1851. $data['mindaychargeah'] = $value['daychargeah'];
  1852. }else{
  1853. $data['mindaychargeah'] = $value['daychargeah'] < $data['mindaychargeah'] ? $value['daychargeah'] : $data['mindaychargeah'];
  1854. }
  1855. if (!isset($data['maxdaydischarah'])) {
  1856. $data['maxdaydischarah'] = $value['daydischarah'];
  1857. }else{
  1858. $data['maxdaydischarah'] = $value['daydischarah'] > $data['maxdaydischarah'] ? $value['daydischarah'] : $data['maxdaydischarah'];
  1859. }
  1860. if (!isset($data['mindaydischarah'])) {
  1861. $data['mindaydischarah'] = $value['daydischarah'];
  1862. }else{
  1863. $data['mindaydischarah'] = $value['daydischarah'] < $data['mindaydischarah'] ? $value['daydischarah'] : $data['mindaydischarah'];
  1864. }
  1865. }
  1866. $list = $temp;
  1867. }
  1868. if (empty($list)) {
  1869. $data['list'] = new StdClass();
  1870. }else{
  1871. $data['list'] = $list;
  1872. }
  1873. exit(json_result('0000',$this->response['0000'],$data));
  1874. }
  1875. }