Lampcontrol.php 124 KB

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