Map.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. /**
  4. *
  5. */
  6. class Map extends Base_Controller{
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->model('Lamp_model');
  11. $this->load->model('Alarm_model');
  12. $this->load->model('Videomonitor_model');
  13. $this->load->model('Weathermonitor_model');
  14. $this->load->model('Project_model');
  15. $this->load->model('Batmanage_model');
  16. $this->load->model('Network_model');
  17. $this->load->model('Group_model');
  18. }
  19. // 地图首页
  20. public function get(){
  21. $role = $this->get_user_info('role');
  22. $userid = $this->get_user_info('id');
  23. // $companyid = $this->get_user_info('companyid');
  24. $keyword = $this->input->post('keyword',true);
  25. $type = $this->input->post('type',true);
  26. $lampid = $this->input->post('lampid',true);
  27. $projectid = $this->input->post('project_id',true);
  28. // 需要查询的字段
  29. $fields = "L.id as id,
  30. L.number as number,
  31. L.status,
  32. L.lighteness as light,
  33. L.longitude as longitude,
  34. L.latitude as latitude,
  35. L.isfaulted,
  36. L.netstatus as netStatus,
  37. L.updatetime as updatetime,
  38. L.lampvoltage,
  39. L.lampcurrent,
  40. L.lamppower,
  41. L.address,
  42. L.chargestage,
  43. L.direction,
  44. L.protocoltype as lampprotocoltype";
  45. // 筛选条件
  46. $filter = array();
  47. $lng_low = $this->input->post('lng_low',true);
  48. $lng_high = $this->input->post('lng_high',true);
  49. $lat_low = $this->input->post('lat_low',true);
  50. $lat_high = $this->input->post('lat_high',true);
  51. $multiple = intval($this->input->post('multiple',true));
  52. if (!empty($keyword)) {
  53. $filter['keyword'] = $keyword;
  54. // unset($filter['lng_low']);
  55. // unset($filter['lng_high']);
  56. // unset($filter['lat_low']);
  57. // unset($filter['lat_high']);
  58. }else{
  59. if(isset($lng_low) && is_numeric($lng_low)) $filter['lng_low'] = $lng_low;
  60. if(isset($lng_high) && is_numeric($lng_high)) $filter['lng_high'] = $lng_high;
  61. if(isset($lat_low) && is_numeric($lat_low)) $filter['lat_low'] = $lat_low;
  62. if(isset($lat_high) && is_numeric($lat_high)) $filter['lat_high'] = $lat_high;
  63. }
  64. $section = $this->input->post('section',true);
  65. if (!empty($section)) {
  66. $filter['section'] = $section;
  67. }
  68. switch ($type) {
  69. case '1': // 开灯
  70. $filter['L.status'] = 1;
  71. $filter['N.status'] = 1;
  72. break;
  73. case '2': // 关灯
  74. $filter['L.status'] = 0;
  75. $filter['N.status'] = 1;
  76. break;
  77. case '3': // 故障
  78. $filter['L.isfaulted'] = 1;
  79. break;
  80. case '4': // 离线
  81. // $filter['AI.status !='] = 0;
  82. $filter['N.status'] = 0;
  83. break;
  84. // case '5': // 监控
  85. // // $filter['monitor'] = 1;
  86. // $videoData = $this->Videomonitor_model->get_data_by_location($role,$companyid,$projectid,$userid,'id,longitude,latitude',$filter);
  87. // break;
  88. default:break;
  89. }
  90. if (!empty($type)) {
  91. if ($type == 5) {
  92. $data = $this->Videomonitor_model->get_data_by_location($role,0,$projectid,$userid,'id,longitude,latitude,image',$filter);
  93. foreach ($data as &$s) {
  94. $s['image'] = base_url($s['image']);
  95. $s['is_video'] = 1;
  96. $s['is_lamp'] = 0;
  97. $s['is_marker'] = 0;
  98. }
  99. }else{
  100. $data = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,$fields,$filter,0,1);
  101. }
  102. }else{
  103. $videoData = $this->Videomonitor_model->get_data_by_location($role,0,$projectid,$userid,'id,longitude,latitude,image',$filter);
  104. foreach ($videoData as &$s) {
  105. $s['image'] = base_url($s['image']);
  106. $s['is_video'] = 1;
  107. $s['is_lamp'] = 0;
  108. $s['is_marker'] = 0;
  109. }
  110. $lampData = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,$fields,$filter,0,1);
  111. $data = array_merge($videoData,$lampData);
  112. }
  113. if ($multiple <= 16 && isset($lng_low) && isset($lng_high) && isset($lat_low) && isset($lat_high)) {
  114. $wCount = 30; //水平分割次数
  115. $hCount = 20; //垂直分割次数
  116. $maxCount = 2;//20; //最大显示数
  117. if ($lng_low > $lng_high) {
  118. $lng = (360-($lng_low-$lng_high))/$wCount;
  119. }else{
  120. $lng = ($lng_high-$lng_low)/$wCount;
  121. }
  122. $lat = ($lat_high-$lat_low)/$hCount;
  123. $i = 1;
  124. $temp = array();
  125. for ($h=0; $h < $hCount; $h++) {
  126. for ($w=0; $w < $wCount; $w++) {
  127. $temp[$i]['count'] = 0;
  128. $temp[$i]['lng_low'] = $lng_low + $w * $lng;
  129. $temp[$i]['lng_high'] = $lng_low + ($w + 1) * $lng;
  130. if ($temp[$i]['lng_low'] > 180) {
  131. $temp[$i]['lng_low'] -= 360;
  132. }
  133. if ($temp[$i]['lng_high'] > 180) {
  134. $temp[$i]['lng_high'] -= 360;
  135. }
  136. $temp[$i]['lat_low'] = $lat_low + $h * $lat;
  137. $temp[$i]['lat_high'] = $lat_low + ($h + 1) * $lat;
  138. $i ++;
  139. }
  140. }
  141. $location = array();
  142. $indexArr = array_keys($temp);
  143. foreach ($data as $value) {
  144. if (isset($value['updatetime']) && $value['updatetime'] == '0000-00-00 00:00:00') $value['updatetime'] = '';
  145. $value['updatetime'] = !empty($value['updatetime']) ? date_change($value['updatetime'],0,DEF_TIMEZONE) : '';
  146. if (isset($value['lampprotocoltype']) && $value['lampprotocoltype'] == 1) {
  147. $indArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  148. $value['chargestage'] = isset($indArr[intval($value['chargestage'])]) ? $indArr[intval($value['chargestage'])] : $value['chargestage'];
  149. // var_dump($value['chargestage']);
  150. }
  151. $t = $value;
  152. // if (!empty($type) && $type != 3 && $value['isfaulted'] == 1) {
  153. // continue;
  154. // }
  155. // $t['lampstatus'] = 1;
  156. if (!isset($location[$value['longitude'].','.$value['latitude']])) {
  157. $location[$value['longitude'].','.$value['latitude']] = array();
  158. }
  159. if (isset($value['isfaulted']) && $value['isfaulted'] == 1) {
  160. $t['lampstatus'] = 0;
  161. }else{
  162. $t['lampstatus'] = 1;
  163. }
  164. // $t['isfaulted'] = 0;
  165. if(empty($t['longitude'])) $t['longitude'] = 0;
  166. if(empty($t['latitude'])) $t['latitude'] = 0;
  167. if(empty($t['light'])) $t['light'] = 0;
  168. if (empty($t['is_video'])) {
  169. $t['is_lamp'] = 1;
  170. $t['is_marker'] = 0;
  171. $t['is_video'] = 0;
  172. }
  173. if ($lng_low > $lng_high && $value['longitude'] < $lng_low){
  174. $t1 = ceil((($t['longitude'] + 360)-$lng_low)/$lng);
  175. }else{
  176. $t1 = ceil(($t['longitude']-$lng_low)/$lng);
  177. }
  178. $t2 = (ceil(($t['latitude']-$lat_low)/$lat) - 1) * $wCount;
  179. $index = $t1 + $t2;
  180. if (in_array($index, $indexArr)) {
  181. if ($temp[$index]['count'] < $maxCount) {
  182. $temp[$index]['lamps'][] = $t;
  183. }
  184. $temp[$index]['count'] += 1;
  185. }
  186. }
  187. $lampData = array();
  188. // 聚合处理
  189. foreach ($temp as $lamp) {
  190. if (!isset($lamp['lamps']) || empty($lamp['lamps'])) continue;
  191. if ($lamp['count'] >= $maxCount) {
  192. $tempLamp = array();
  193. $tempLamp['is_lamp'] = 0;
  194. if ($lamp['lng_low'] < $lamp['lng_high']) {
  195. $longitude = $lamp['lng_low'] + ($lamp['lng_high'] + 360 - $lamp['lng_low']);
  196. if ($longitude > 180) {
  197. $longitude -= 360;
  198. }
  199. $tempLamp['longitude'] = $longitude;
  200. }else{
  201. $tempLamp['longitude'] = ($lamp['lng_low'] + $lamp['lng_high'])/2;
  202. }
  203. $tempLamp['latitude'] = ($lamp['lat_low'] + $lamp['lat_high'])/2;
  204. $tempLamp['count'] = $lamp['count'];
  205. $tempLamp['is_marker'] = 1;
  206. $tempLamp['is_video'] = 0;
  207. $tempLamp['f_longitude'] = $lamp['lamps'][0]['longitude'];
  208. $tempLamp['f_latitude'] = $lamp['lamps'][0]['latitude'];
  209. $lampData[] = $tempLamp;
  210. }else{
  211. foreach ($lamp['lamps'] as $l) {
  212. if (isset($lampid) && $l['id'] == $lampid) {
  213. $ld = $l;
  214. continue;
  215. }
  216. $lampData[] = $l;
  217. }
  218. }
  219. }
  220. }else{
  221. $temp = array();
  222. $location = array();
  223. foreach ($data as $v) {
  224. // if (!empty($type) && $type != 3 && isset($v['isfaulted']) && $v['isfaulted'] == 1) {
  225. // continue;
  226. // }
  227. // $v['lampstatus'] = 1;
  228. if (isset($v['updatetime']) && $v['updatetime'] == '0000-00-00 00:00:00') $v['updatetime'] = '';
  229. $v['updatetime'] = !empty($v['updatetime']) ? date_change($v['updatetime'],0,DEF_TIMEZONE) : '';
  230. if (isset($v['lampprotocoltype']) && $v['lampprotocoltype'] == 1) {
  231. $indArr = [2=>'16',3=>'32',4=>'48',5=>'64'];
  232. $v['chargestage'] = isset($indArr[intval($v['chargestage'])]) ? $indArr[intval($v['chargestage'])] : $v['chargestage'];
  233. }
  234. if (isset($v['isfaulted']) && $v['isfaulted'] == 1) {
  235. $v['lampstatus'] = 0;
  236. }else{
  237. $v['lampstatus'] = 1;
  238. }
  239. if (isset($lampid) && $v['id'] == $lampid) {
  240. $ld = $v;
  241. continue;
  242. }
  243. if (!isset($v['is_video']) || empty($v['is_video'])) {
  244. $v['isfaulted'] = 0;
  245. $v['is_lamp'] = 1;
  246. $v['is_marker'] = 0;
  247. $v['is_video'] = 0;
  248. if(empty($v['light'])) $v['light'] = 0;
  249. }
  250. if(empty($v['longitude'])) $v['longitude'] = 0;
  251. if(empty($v['latitude'])) $v['latitude'] = 0;
  252. $temp[] = $v;
  253. if (!isset($location["{$v['longitude']},{$v['latitude']}"])) {
  254. $location[$v['longitude'].','.$v['latitude']] = array();
  255. }
  256. }
  257. $lampData = $temp;
  258. }
  259. // var_dump(microtime());
  260. foreach ($lampData as $value) {
  261. if (isset($location[$value['longitude'].','.$value['latitude']]) && count($location[$value['longitude'].','.$value['latitude']]) >= 10) {
  262. continue;
  263. }
  264. $location[$value['longitude'].','.$value['latitude']][] = $value;
  265. }
  266. $data = array();
  267. foreach ($location as $value) {
  268. if (!empty($value)) {
  269. $data = array_merge($data,$value);
  270. }
  271. }
  272. if (isset($ld) && !empty($ld)) {
  273. $ld['is_lamp'] = 1;
  274. $ld['is_marker'] = 0;
  275. $ld['is_video'] = 0;
  276. $data[] = $ld;
  277. }
  278. exit(json_result('0000',$this->response['0000'],array('lamps'=>$data)));
  279. }
  280. // 视屏监控
  281. public function video_list(){
  282. $role = $this->get_user_info('role');
  283. $userid = $this->get_user_info('id');
  284. // $companyid = $this->get_user_info('companyid');
  285. $projectid = $this->input->post('project_id',true);
  286. $keyword = $this->input->post('keyword',true);
  287. $videoData = $this->Videomonitor_model->get_one_by_role($role,0,$projectid,$userid,'id,longitude,latitude',$keyword);
  288. $videoData = empty($videoData) ? array() : array($videoData);
  289. exit(json_result('0000',$this->response['0000'],array('list'=>$videoData)));
  290. }
  291. // 地图页灯控列表
  292. public function lamp_list(){
  293. $role = $this->get_user_info('role');
  294. $userid = $this->get_user_info('id');
  295. // $companyid = $this->get_user_info('companyid');
  296. $keyword = $this->input->post('keyword',true);
  297. $section = $this->input->post('section',true);
  298. $type = $this->input->post('type',true);
  299. $page = $this->input->post('page',true);
  300. $count = $this->input->post('count',true);
  301. $projectid = $this->input->post('project_id',true);
  302. if (empty($projectid)) exit(json_result('0007',$this->response['0007']));
  303. // 需要查询的字段
  304. $fields = "id as id,
  305. number as number,
  306. status,
  307. lighteness as light,
  308. longitude as longitude,
  309. latitude as latitude,
  310. isfaulted,
  311. netstatus as netStatus";
  312. // 筛选条件
  313. $filter = array();
  314. $filter['projectid'] = $projectid;
  315. if (!empty($keyword)) {
  316. $filter['number|address'] = $keyword;
  317. }
  318. if (!empty($section)) {
  319. $filter['section'] = $section;
  320. }
  321. $page = empty($page) ? 1 : $page;
  322. $count = empty($count) ? 16 : $count;
  323. $limit = $count;
  324. $offset = ($page - 1) * $count;
  325. // $filter['page'] = $page;
  326. // $filter['count'] = $count;
  327. switch ($type) {
  328. case '1': // 开灯
  329. $filter['status'] = 1;
  330. $filter['netstatus'] = 1;
  331. break;
  332. case '2': // 关灯
  333. $filter['status'] = 0;
  334. $filter['netstatus'] = 1;
  335. break;
  336. case '3': // 故障
  337. // $filter['AI.status'] = 0;
  338. $filter['isfaulted'] = 1;
  339. break;
  340. case '4': // 离线
  341. // $filter['AI.status !='] = 0;
  342. $filter['netstatus'] = 0;
  343. break;
  344. // case '5': // 监控
  345. // $filter['monitor'] = 1;
  346. // break;
  347. default:break;
  348. }
  349. // $data = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,$fields,$filter);
  350. $data = $this->Lamp_model->get_list($filter,$fields,$limit, $offset, 'number ASC,id DESC', NUll);
  351. // unset($filter['page']);
  352. // unset($filter['count']);
  353. // $total = $this->Lamp_model->get_list_by_role($role,0,$projectid,$userid,'L.id',$filter,1);
  354. $total = $this->Lamp_model->get_count($filter);
  355. $temp = array();
  356. foreach ($data as $v) {
  357. if (!empty($type) && $type != 3 && isset($v['lampstatus']) && $v['lampstatus'] == 0) {
  358. continue;
  359. }
  360. $v['isfaulted'] = 0;
  361. if(empty($v['longitude'])) $v['longitude'] = 0;
  362. if(empty($v['latitude'])) $v['latitude'] = 0;
  363. if(empty($v['light'])) $v['light'] = 0;
  364. $temp[] = $v;
  365. }
  366. $data = $temp;
  367. exit(json_result('0000',$this->response['0000'],array('lamps'=>$data,'total'=>ceil($total/$count))));
  368. }
  369. // 灯控信息
  370. public function lamp_info(){
  371. $lamp_id = $this->input->post('lamp_id',true);
  372. if (empty($lamp_id)) {
  373. exit(json_result('0802',$this->response['0802'],array()));
  374. }
  375. $version = $this->session->userdata('version');
  376. // 需要获取的字段
  377. $fields = "L.status,
  378. L.number as lamp_no,
  379. L.lighteness as lighteness,
  380. L.lamppower as lamppower,
  381. alog.status as lampstatus,
  382. L.battvoltage as battvoltage,
  383. BC.vsystem as vsystem,
  384. L.chargecurrent as chargecurrent,
  385. L.overtimes as overtimes,
  386. L.boardpower as boardpower,
  387. N.networkname as network_name,
  388. L.chargestage,
  389. L.loadtype,
  390. L.isfaulted,L.section";
  391. $data = $this->Lamp_model->getOne($lamp_id,$fields);
  392. if ($data['isfaulted'] == 1) {
  393. // 获取路灯故障信息
  394. $res = $this->Alarm_model->get_one_by_filter(array('lampid'=>$lamp_id,'status'=>0),'stralarmtype');
  395. if (empty($version)) {
  396. $data['alarm_event'] = empty($res['stralarmtype']) ? '正常' : $res['stralarmtype'];
  397. }else{
  398. $data['alarm_event'] = empty($res['stralarmtype']) ? 'normal' : alarm_translate($res['stralarmtype']);
  399. }
  400. }
  401. if (empty($version)) {
  402. $chargestage = array(0=>'没有充电',1=>'启动充电',6=>'限流',7=>'充满',16=>'MPPT充电',32=>'均衡充电',48=>'提升充电',64=>'浮充',''=>'未知状态');
  403. if (isset($chargestage[$data['chargestage']])) {
  404. $data['chargestage'] = $chargestage[$data['chargestage']];
  405. }else{
  406. $data['chargestage'] = empty($data['chargestage']) ? '没有充电' : '未知状态';
  407. }
  408. }else{
  409. $chargestage = array(0=>'There is no charge',1=>'Start charging',6=>'Current limiting',7=>'Full',16=>'MPPT charging',32=>'Equalizing charge',48=>'Improve charging',64=>'Floating',''=>'Unknown state');
  410. if (isset($chargestage[$data['chargestage']])) {
  411. $data['chargestage'] = $chargestage[$data['chargestage']];
  412. }else{
  413. $data['chargestage'] = empty($data['chargestage']) ? 'There is no charge' : 'Unknown';
  414. }
  415. }
  416. $data['battvoltage'] = empty($data['battvoltage']) ? 0 : round($data['battvoltage'],1);
  417. $data['chargecurrent'] = empty($data['chargecurrent']) ? 0 : round($data['chargecurrent'],2);
  418. $data['lamppower'] = empty($data['lamppower']) ? 0 : round($data['lamppower'],1);
  419. $data['lighteness'] = empty($data['lighteness']) ? 0 : $data['lighteness'];
  420. $data['overtimes'] = empty($data['overtimes']) ? 0 : $data['overtimes'];
  421. $data['status'] = empty($data['status']) ? 0 : $data['status'];
  422. $data['vsystem'] = empty($data['vsystem']) ? 0 : $data['vsystem'];
  423. $data['boardpower'] = empty($data['boardpower']) ? 0 : round($data['boardpower'],1);
  424. exit(json_result('0000',$this->response['0000'],$data));
  425. }
  426. // 监控信息
  427. public function monitor_info(){
  428. // $lamp_id = $this->input->post('lamp_id',true);
  429. // if (empty($lamp_id)) {
  430. // exit(json_result('0007',$this->response['0007'],array()));
  431. // }
  432. // $video = $this->Videomonitor_model->get_data_by_fiter(array('lampid'=>$lamp_id),'id as videoid,image');
  433. // $weather = $this->Weathermonitor_model->get_list_by_filter(array('lampid'=>$lamp_id));
  434. // $weather = empty($weather) ? array() : $weather[0];
  435. // exit(json_result('0000',$this->response['0000'],array('video'=>$video,'weather'=>$weather)));
  436. json_result('0000',$this->response['0000'],array());
  437. }
  438. // 项目信息
  439. public function project_info(){
  440. $lamp_id = $this->input->post('lamp_id',true);
  441. $project_id = $this->input->post('project_id',true);
  442. $role = $this->get_user_info('role');
  443. $userid = $this->get_user_info('id');
  444. // $companyid = $this->get_user_info('companyid');
  445. if (empty($lamp_id) && empty($project_id) || ($lamp_id < 0 && $project_id < 0)) {
  446. exit(json_result('0007',$this->response['0007'],array()));
  447. }
  448. if ($project_id>0) {
  449. // var_dump(microtime());
  450. $data = $this->Project_model->get_data_by_field('P.id',$project_id);
  451. // var_dump(microtime());
  452. $data['dayconsumption'] = empty($data['dayconsumption']) ? 0 : round($data['dayconsumption'],1);
  453. $data['monthconsumption'] = empty($data['monthconsumption']) ? 0 : round($data['monthconsumption'],1);
  454. $data['yearconsumption'] = empty($data['yearconsumption']) ? 0 : round($data['yearconsumption'],1);
  455. $data['daygeneration'] = empty($data['daygeneration']) ? 0 : round($data['daygeneration'],1);
  456. $data['monthgeneration'] = empty($data['monthgeneration']) ? 0 : round($data['monthgeneration'],1);
  457. $data['yeargeneration'] = empty($data['yeargeneration']) ? 0 : round($data['yeargeneration'],1);
  458. $data['group_count'] = $this->Group_model->get_count_by_filter(array('projectid'=>$project_id));
  459. $data['fault_count'] = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
  460. // $data['install_num'] = $this->Lamp_model->getTotal(array('projectid'=>$project_id), $role, $companyid, $userid);
  461. $data['network_num'] = $this->Network_model->getTotalByProject($project_id);
  462. // var_dump(microtime());
  463. exit(json_result('0000',$this->response['0000'],$data));
  464. }
  465. if ($lamp_id > 0){
  466. $data = $this->Project_model->get_data_by_field('L.id',$lamp_id);
  467. $data['dayconsumption'] = empty($data['dayconsumption']) ? 0 : round($data['dayconsumption'],1);
  468. $data['monthconsumption'] = empty($data['monthconsumption']) ? 0 : round($data['monthconsumption'],1);
  469. $data['yearconsumption'] = empty($data['yearconsumption']) ? 0 : round($data['yearconsumption'],1);
  470. $data['daygeneration'] = empty($data['daygeneration']) ? 0 : round($data['daygeneration'],1);
  471. $data['monthgeneration'] = empty($data['monthgeneration']) ? 0 : round($data['monthgeneration'],1);
  472. $data['yeargeneration'] = empty($data['yeargeneration']) ? 0 : round($data['yeargeneration'],1);
  473. $data['group_count'] = $this->Group_model->get_count_by_filter(array('projectid'=>$data['id']));
  474. $data['fault_count'] = $this->Lamp_model->get_fault_count(array('L.projectid'=>$data['id'],'L.isfaulted'=>1), $role, 0, $userid);
  475. // $data['install_num'] = $this->Lamp_model->getTotal(array('projectid'=>$data['id']), $role, $companyid, $userid);
  476. $data['network_num'] = $this->Network_model->getTotalByProject($project_id);
  477. exit(json_result('0000',$this->response['0000'],$data));
  478. }
  479. }
  480. // 获取项目列表
  481. public function project_list() {
  482. // $companyid = $this->get_user_info('companyid');
  483. $role = $this->get_user_info('role');
  484. $userid = $this->get_user_info('id');
  485. $page = $this->input->post('page',true);
  486. $count = $this->input->post('count',true);
  487. $page = empty($page) ? 1 : $page;
  488. $count = empty($count) ? 1 : $count;
  489. $filter = array();
  490. if(!empty($page)) $filter['page'] = $page;
  491. if(!empty($count)) $filter['count'] = $count;
  492. $data = $this->Project_model->getMultiData($filter, 'P.id, P.projectname as name, P.lampcount,Z.name as zone,S.name as province,P.projectid as number,P.company as companyid', $role, 0, $userid);
  493. unset($filter['page']);
  494. unset($filter['count']);
  495. $total = $this->Project_model->getTotal($filter, $role, 0, $userid);
  496. $projectIds = array_column($data, 'id');
  497. $lampData = $this->Lamp_model->get_lamp_count_by_project($projectIds, $role, 0, $userid);
  498. $temp = array();
  499. foreach ($lampData as $value) {
  500. $temp[$value['projectid']]['lampcount'] = $value['total'];
  501. }
  502. foreach ($data as &$v) {
  503. if (isset($temp[$v['id']]['lampcount']) && !empty($temp[$v['id']]['lampcount'])) {
  504. $v['lampcount'] = $temp[$v['id']]['lampcount'];
  505. }else{
  506. $v['lampcount'] = '0';
  507. }
  508. }
  509. exit(json_result('0000', $this->response['0000'], array('projects'=>$data,'total'=>ceil($total/$count))));
  510. }
  511. // 灯控开关,已项目为单位
  512. public function turnonoff(){
  513. $role = $this->get_user_info('role');
  514. // if ($role == COMPANY_CUSTOMER) {
  515. // exit(json_result('0011', $this->response['0011'], array()));
  516. // }
  517. $projectid = intval($this->input->post('projectid',true));
  518. $type = intval($this->input->post('type',true));
  519. $mode = intval($this->input->post('mode',true));
  520. $userid = $this->get_user_info('id');
  521. // $companyid = $this->get_user_info('companyid');
  522. if (empty($projectid)) {
  523. $projectid = $this->Project_model->get_projectid_by_role($role,$userid,0);
  524. $projectid = empty($projectid) ? '0' : $projectid;
  525. }
  526. $ids = explode(',', $projectid);
  527. foreach ($ids as $v) {
  528. $data['cmdtype'] = 2;
  529. $data['relateid'] = $v;
  530. $data['statuscmd'] = $type;
  531. $data['updatetime'] = date("Y-m-d H:i:s");
  532. $recordid = $this->Batmanage_model->get_record_id($data, 'batch_switch_cmd');
  533. if(!$recordid){
  534. exit(json_result('0009', $this->response['0009'], array()));
  535. }
  536. $cmd = '{"cmd_type":"batch_switch_cmd","cmd_id":'.$recordid.',"broadcast":'.$mode.'}';
  537. $cmdret = send_cmd($cmd,0);
  538. // if($cmdret === false){
  539. // exit(json_result('0008', $this->response['0008'], array()));
  540. // }
  541. }
  542. exit(json_result('0213',$this->response['0213']));
  543. // $res = json_decode($cmdret, true);
  544. // if ($res['result'] == false) {
  545. // $version = $this->session->userdata('version');
  546. // if (empty($version)) {
  547. // $res['msg'] = transfer_error_tips($res['msg']);
  548. // exit(json_result('0010', $res['msg'], array()));
  549. // }else{
  550. // $res['msg'] = empty($res['msg']) ? 'Unknown error' : $res['msg'];
  551. // exit(json_result('other', $res['msg'], array()));
  552. // }
  553. // }else{
  554. // exit(json_result('0000', $this->response['0000'], array()));
  555. // }
  556. }
  557. // 故障数/网关数/装机数
  558. public function data_list(){
  559. $type = $this->input->post('type',true);
  560. $projectid = $this->input->post('projectid',true);
  561. if (empty($type) || empty($projectid)) {
  562. exit(json_result('0007',$this->response['0007'],array()));
  563. }
  564. switch ($type) {
  565. case '1': // 装机数
  566. $fields = "L.id,L.number";
  567. $list = $this->Lamp_model->get_list_in('L.projectid',array($projectid),$fields);
  568. break;
  569. case '2': // 网关数
  570. $fields = "id,networkname";
  571. $list = $this->Network_model->get_list_in('projectid',array($projectid),$fields);
  572. break;
  573. case '3': // 故障数
  574. $fields = "L.number,L.id,AI.stralarmtype,max(AI.updatetime) as updatetime";
  575. $list = $this->Alarm_model->get_list_by_projectid($projectid,array('AI.status'=>0,'L.isfaulted'=>1,'group'=>'AI.lampid'),$fields);
  576. $version = $this->session->userdata('version');
  577. if (!empty($version)) {
  578. foreach ($list as &$v) {
  579. $v['stralarmtype'] = alarm_translate($v['stralarmtype']);
  580. }
  581. }
  582. break;
  583. default:
  584. exit(json_result('0014',$this->response['0014'],array()));
  585. break;
  586. }
  587. $list = empty($list) ? array() : $list;
  588. exit(json_result('0000',$this->response['0000'],$list));
  589. }
  590. // 故障详情
  591. public function fault_info(){
  592. $alarmid = $this->input->post('lampid',true);
  593. $userid = $this->get_user_info('id');
  594. if (empty($alarmid)) {
  595. exit(json_result('0007',$this->response['0007'],array()));
  596. }
  597. $join = array();
  598. $join[] = ['table'=>'lampinfo as L','cond'=>'L.id = AI.lampid','type'=>'inner'];
  599. $join[] = ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner'];
  600. $join[] = ['table'=>'global_location as G','cond'=>'G.id = P.cityid','type'=>'inner'];
  601. $data = $this->Alarm_model->get_list_by_multi_join(['AI.id'=>$alarmid], 'L.number,AI.updatetime,AI.panelstatus,AI.lampstatus,AI.id as alarmid,AI.tempstatus,AI.batstatus,G.timezone,AI.status,P.projectname',NULL, NULL, $join, NULL, NUll, 'AI', true);
  602. $batstatus = $this->config->item('batstatus');
  603. $panelstatus = $this->config->item('panelstatus');
  604. $lampstatus = $this->config->item('lampstatus');
  605. $tempstatus = $this->config->item('tempstatus');
  606. $temp2 = array();
  607. if (isset($batstatus[$data['batstatus']])) $temp2[] = $batstatus[$data['batstatus']];
  608. if (isset($panelstatus[$data['panelstatus']])) $temp2[] = $panelstatus[$data['panelstatus']];
  609. if (isset($lampstatus[$data['lampstatus']])) $temp2[] = $lampstatus[$data['lampstatus']];
  610. if (isset($tempstatus[$data['tempstatus']])) $temp2[] = $tempstatus[$data['tempstatus']];
  611. if (!empty($temp2)) {
  612. $data['stralarmtype'] = implode(',', $temp2);
  613. }else{
  614. $data['stralarmtype'] = '';
  615. }
  616. $data['userid'] = empty($data['userid']) ? 0 : $data['userid'];
  617. // 获取维修人员列表
  618. $list = $this->User_model->get_repair_user(array('user_id'=>$userid));
  619. $data['list'] = $list;
  620. exit(json_result('0000',$this->response['0000'],$data));
  621. }
  622. // 地图页概览数据
  623. public function date_nav(){
  624. $userid = $this->get_user_info('id');
  625. // $companyid = $this->get_user_info('companyid');
  626. $role = $this->get_user_info('role');
  627. $project_id = intval($this->input->post('project_id', true));
  628. if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
  629. $arr = $this->Lamp_model->getTotalLampInfo($role, 0, $project_id, $userid,1);
  630. if (!empty($arr['num'])) {
  631. $online_arr = $this->Lamp_model->get_count(['projectid'=>$project_id,'netStatus'=>1]);
  632. $lighting_arr = $this->Lamp_model->getCountByFilter($role, 0, $project_id, $userid, array('L.status'=>1));
  633. // $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
  634. $failure = 0;
  635. $data['online_rate'] = round($online_arr['num']/$arr['num']*100, 2);
  636. $data['lighting_rate'] = round($lighting_arr['num']/$arr['num']*100, 2);
  637. $data['online_count'] = intval($online_arr['num']);
  638. $data['lighting_count'] = intval($lighting_arr['num']);
  639. $data['failure_rate'] = round($failure/$arr['num']*100, 2);
  640. $data['failure_count'] = intval($failure);
  641. $data['totalgeneration'] = round($arr['power'], 2);
  642. $data['total_lamp'] = intval($arr['num']);
  643. $data['co2_emission'] = round($arr['power']*0.977, 3);
  644. $data['so2_emission'] = round($arr['power']*0.977/2620*8.5, 3);
  645. $data['coal_saving'] = round($arr['power']*0.977/2620, 3);
  646. $data['totalconsumption'] = round($arr['totalconsumption'],2);
  647. } else {
  648. $data['online_rate'] = 0;
  649. $data['failure_rate'] = 0;
  650. $data['lighting_rate'] = 0;
  651. $data['failure_count'] = 0;
  652. $data['totalgeneration'] = 0;
  653. $data['total_lamp'] = 0;
  654. $data['co2_emission'] = 0;
  655. $data['so2_emission'] = 0;
  656. $data['coal_saving'] = 0;
  657. $data['online_count'] = 0;
  658. $data['lighting_count'] = 0;
  659. $data['totalconsumption'] = 0;
  660. }
  661. exit(json_result('0000', $this->response['0000'], $data));
  662. }
  663. // 路灯数据
  664. public function lamp_data(){
  665. $lampid = intval($this->input->post('lampid',true));
  666. if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
  667. $fields = 'L.number,L.address,L.netstatus as netStatus,L.lighteness,L.lampvoltage,L.lampcurrent,L.lamppower,L.electricleft,L.batttemper,L.chargestage,L.overtimes,L.battvoltage,L.discharcurrent,L.dischargepower,L.daydischargemincurrent,L.solarvoltage,L.solarcurrent,L.protocoltype,L.solarpower,L.temper,L.totalgeneration,L.totalconsumption,L.daychargemincurrent,L.id,L.totalLightTime,L.createtime,L.projectid,AI.batstatus,AI.panelstatus, AI.lampstatus,AI.tempstatus,AI.id as alarmId';
  668. $join = [];
  669. $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'];
  670. $data = $this->Lamp_model->get_list_by_multi_join(['L.id'=>$lampid], $fields,NULL, NULL, $join, NULL, NUll, 'L', true);
  671. // $data = $this->Lamp_model->get_list(['id'=>$lampid],$fields);
  672. if (isset($data['alarmId']) && ($data['batstatus'] != 0 || $data['batstatus'] != 0 || $data['batstatus'] != 0 || $data['batstatus'] != 0)) {
  673. $data['isfaulted'] = '1';
  674. // $batstatus = $this->config->item('batstatus');
  675. // $panelstatus = $this->config->item('panelstatus');
  676. // $lampstatus = $this->config->item('lampstatus');
  677. // $tempstatus = $this->config->item('tempstatus');
  678. // $temp2 = array();
  679. // if (isset($batstatus[$data['batstatus']])) $temp2[] = $batstatus[$data['batstatus']];
  680. // if (isset($panelstatus[$data['panelstatus']])) $temp2[] = $panelstatus[$data['panelstatus']];
  681. // if (isset($lampstatus[$data['lampstatus']])) $temp2[] = $lampstatus[$data['lampstatus']];
  682. // if (isset($tempstatus[$data['tempstatus']])) $temp2[] = $tempstatus[$data['tempstatus']];
  683. // $data['isfaulted'] = implode(',', $temp2);
  684. // $res = $this->Alarm_model->get_one_by_filter(array('lampid'=>$data['id'],'status'=>0),'stralarmtype');
  685. // $stralarmtype = trim($res['stralarmtype']);
  686. // if (!empty($stralarmtype)) {
  687. // $value['isfaulted'] = '1';
  688. // }else{
  689. // $value['isfaulted'] = '0';
  690. // }
  691. }else{
  692. $data['isfaulted'] = '0';
  693. }
  694. $LampData = $this->db->query('select min(updatetime) as minTime from realtime_info_log where lampid = '.$lampid)->row_array();
  695. if (empty($LampData) || empty($LampData['minTime']) || $LampData['minTime'] == '1970-01-01 08:00:00') {
  696. if (empty($data['createtime']) || $data['createtime'] == '1970-01-01 08:00:00') {
  697. $beginTime = time();
  698. }else{
  699. $beginTime = strtotime($data['createtime']);
  700. }
  701. }else{
  702. $beginTime = strtotime($LampData['minTime']);
  703. }
  704. $data['userDate'] = round((time() - $beginTime) / (3600 * 24 * 356),1);
  705. $data['userDate'] = $data['userDate'] > 100 ? 0 : $data['userDate'];
  706. // $LampInfoData = $this->db->query('select id,lamppower from lamp_info_log where lighteness = 100 AND lampid = '.$lampid.' order by updatetime DESC limit 1')->row_array();
  707. $LampInfoData = 0;
  708. if (empty($LampInfoData) || empty($LampInfoData['id'])) {
  709. $lamppower = 0;
  710. }else{
  711. $lamppower = $LampInfoData['lamppower'];
  712. }
  713. if ($lamppower == 0) {
  714. $later = 3;
  715. }else{
  716. $totalconsumption = $lamppower*10*365*3;
  717. $consum = $totalconsumption - $data['totalconsumption'];
  718. if ($consum <= 0) {
  719. $later = 0;
  720. }else{
  721. $later = round($consum/($lamppower*10)/365,1);
  722. }
  723. }
  724. $data['later'] = $later;
  725. $data['totalDate'] = $later + $data['userDate'];
  726. // 日照时间
  727. $project_weather = $this->db->query('select * from project_weather where projectId = '.$data['projectid'])->row_array();
  728. if (empty($project_weather)) {
  729. $data['sunTime'] = 0;
  730. }else{
  731. $weatherInfo = json_decode($project_weather['weatherInfo'],true);
  732. if (!empty($weatherInfo[0])) {
  733. $sr = $weatherInfo[0]['sr'];
  734. $ss = $weatherInfo[0]['ss'];
  735. $srArr = explode(':', $sr);
  736. $ssArr = explode(':', $ss);
  737. $data['sunTime'] = round((intval($ssArr[0])*60+intval($ssArr[1]) - (intval($srArr[0])*60+intval($srArr[1])))/60,1);
  738. }else{
  739. $data['sunTime'] = 0;
  740. }
  741. }
  742. exit(json_result('0000',$this->response['0000'],$data));
  743. }
  744. // 路段信息
  745. public function section_data(){
  746. $lampid = intval($this->input->post('lampid',true));
  747. $netStatus = intval($this->input->post('netStatus',true));
  748. $projectid = intval($this->input->post('projectid',true));
  749. $section = $this->input->post('section',true);
  750. $fields = 'L.section,L.projectid';
  751. if (empty($lampid)){
  752. if (empty($projectid) || empty($section)) {
  753. exit(json_result('0007',$this->response['0007']));
  754. }else{
  755. $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.section = "'.$section.'" AND L.projectid = '.$projectid)->row_array();
  756. }
  757. }else{
  758. $data = $this->Lamp_model->getOne($lampid,$fields);
  759. }
  760. if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
  761. // 路灯总数
  762. $data['lamp_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid']));
  763. $data['lamp_count'] = intval($data['lamp_count']);
  764. // 故障数
  765. $data['fail_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'status'=>1));
  766. $data['fail_count'] = intval($data['fail_count']);
  767. $data['fail_rate'] = round($data['fail_count']/$data['lamp_count']*100,2);
  768. // 在线数
  769. $data['online_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'online'=>1));
  770. $data['online_count'] = intval($data['online_count']);
  771. $data['online_rate'] = round($data['online_count']/$data['lamp_count']*100,2);
  772. // 亮灯数
  773. $data['light_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'lightStatus'=>1));
  774. $data['light_count'] = intval($data['light_count']);
  775. $data['light_rate'] = round($data['light_count']/$data['lamp_count']*100,2);
  776. $res = $this->Lamp_model->get_section_avg($data['projectid'],$data['section']);
  777. $data['daychargemincurrent'] = intval($res['daychargemincurrent']);
  778. $data['daydischargemincurrent'] = intval($res['daydischargemincurrent']);
  779. $data['totalgeneration'] = round($res['totalgeneration'],2);
  780. $data['totalconsumption'] = intval($res['totalconsumption'],2);
  781. $data['electricleft'] = intval($res['electricleft']);
  782. $data['battvoltage'] = round($res['battvoltage'],1);
  783. // 路灯列表
  784. $where = array('section'=>$data['section'],'projectid'=>$data['projectid']);
  785. $onlineStatus = intval($this->input->post('onlineStatus',true));
  786. if (!empty($onlineStatus)) $where['online'] = 1;
  787. $lightStatus = intval($this->input->post('lightStatus',true));
  788. if (!empty($lightStatus)) $where['lightStatus'] = 1;
  789. $failStatus = intval($this->input->post('failStatus',true));
  790. if (!empty($failStatus)) $where['status'] = 1;
  791. $list = $this->Lamp_model->get_list_in(null, array(), 'L.id,L.number,L.netstatus as netStatus,L.lighteness,L.isfaulted',$where);
  792. $version = $this->session->userdata('version');
  793. $data['lampList'] = array();
  794. foreach ($list as $value) {
  795. // 故障信息处理
  796. if ($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype'])) {
  797. if (empty($version)) {
  798. $value['stralarmtype'] = '否';
  799. $value['isfaulted'] = '0';
  800. }else{
  801. $value['stralarmtype'] = 'Nothing';
  802. $value['isfaulted'] = '0';
  803. }
  804. }else{
  805. if (empty($version)) {
  806. $stralarmtype = trim($value['stralarmtype']);
  807. if (!empty($stralarmtype)) {
  808. $alarmArr = explode(',', $stralarmtype);
  809. $temp2 = array();
  810. foreach ($alarmArr as $a) {
  811. if ($a == '电池故障') {
  812. $a = '电池电压异常';
  813. }
  814. $temp2[] = $a;
  815. }
  816. $value['stralarmtype'] = implode(',', $temp2);
  817. $value['isfaulted'] = '1';
  818. }else{
  819. $value['stralarmtype'] = '否';
  820. $value['isfaulted'] = '0';
  821. }
  822. }else{
  823. $stralarmtype = trim($res['stralarmtype']);
  824. if (!empty($stralarmtype)) {
  825. $alarmArr = explode(',', $stralarmtype);
  826. $temp2 = array();
  827. foreach ($alarmArr as $a) {
  828. if ($a == '电池故障') {
  829. $a = '电池电压异常';
  830. }
  831. if ($value['lampProtocoltype'] == 1) {
  832. $temp[] = modbus_alarm_translate($a);
  833. }else{
  834. $temp[] = alarm_translate($a);
  835. }
  836. }
  837. $value['stralarmtype'] = implode(',', $temp2);
  838. $value['isfaulted'] = '1';
  839. }else{
  840. $value['stralarmtype'] = 'Nothing';
  841. $value['isfaulted'] = '0';
  842. }
  843. }
  844. }
  845. unset($value['failStatus']);
  846. // unset($value['stralarmtype']);
  847. $data['lampList'][] = $value;
  848. }
  849. exit(json_result('0000',$this->response['0000'],$data));
  850. }
  851. // 项目信息
  852. public function project_data(){
  853. $lampid = intval($this->input->post('lampid',true));
  854. if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
  855. $fields = 'L.projectid,L.section';
  856. $data = $this->Lamp_model->getOne($lampid,$fields);
  857. $userid = $this->get_user_info('id');
  858. // $companyid = $this->get_user_info('companyid');
  859. $role = $this->get_user_info('role');
  860. $project_id = $data['projectid'];
  861. $arr = $this->Lamp_model->getTotalLampInfo($role, 0, $project_id, $userid,1);
  862. if (!empty($arr['num'])) {
  863. $online_arr = $this->Lamp_model->getOnlineCount($role, 0, $project_id, $userid, 1);
  864. $lighting_arr = $this->Lamp_model->getCountByFilter($role, 0, $project_id, $userid, array('L.status'=>1));
  865. // $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
  866. $failure = 0;
  867. $data['online_rate'] = round($online_arr['num']/$arr['num']*100, 2);
  868. $data['lighting_rate'] = round($lighting_arr['num']/$arr['num']*100, 2);
  869. $data['online_count'] = intval($online_arr['num']);
  870. $data['lighting_count'] = intval($lighting_arr['num']);
  871. $data['failure_rate'] = round($failure/$arr['num']*100, 2);
  872. $data['failure_count'] = intval($failure);
  873. $data['totalgeneration'] = round($arr['power'], 2);
  874. $data['total_lamp'] = intval($arr['num']);
  875. $data['co2_emission'] = round($arr['power']*0.977, 3);
  876. $data['so2_emission'] = round($arr['power']*0.977/2620*8.5, 3);
  877. $data['coal_saving'] = round($arr['power']*0.977/2620, 3);
  878. $data['totalconsumption'] = round($arr['totalconsumption'],2);
  879. } else {
  880. $data['online_rate'] = 0;
  881. $data['failure_rate'] = 0;
  882. $data['lighting_rate'] = 0;
  883. $data['failure_count'] = 0;
  884. $data['totalgeneration'] = 0;
  885. $data['total_lamp'] = 0;
  886. $data['co2_emission'] = 0;
  887. $data['so2_emission'] = 0;
  888. $data['coal_saving'] = 0;
  889. $data['online_count'] = 0;
  890. $data['lighting_count'] = 0;
  891. $data['totalconsumption'] = 0;
  892. }
  893. // 获取路段下拉列表
  894. $section_nav = $this->db->query('select section from lampinfo where projectid = '.$project_id.' AND section != "" group by section')->result_array();
  895. $data['section_nav'] = array();
  896. foreach ($section_nav as $s) {
  897. $data['section_nav'][] = array('name'=>$s['section'],'value'=>$s['section']);
  898. }
  899. // 获取项目下控制器类型
  900. $pro_list = $this->db->query('select protocoltype from lampinfo where projectid = '.$project_id.' group by protocoltype')->result_array();
  901. $conStr = '';
  902. foreach ($pro_list as $p) {
  903. if ($conStr != '') {
  904. $conStr .= '/';
  905. }
  906. if ($p['protocoltype'] == 0) {
  907. $conStr .= 'TCP';
  908. }elseif ($p['protocoltype'] == 1) {
  909. $conStr .= 'NBIOT';
  910. }elseif ($p['protocoltype'] == 2) {
  911. $conStr .= 'UDP';
  912. }else{
  913. $conStr .= 'LORAWAN';
  914. }
  915. }
  916. $data['protocolType'] = $conStr;
  917. // 配置信息
  918. $lampData = $this->db->query('select id,boardpower,lamppower,batteryah,batterytype from lampinfo where projectid = '.$project_id.' order by id ASC limit 1')->row_array();
  919. if (empty($lampData) || $lampData['id']) {
  920. $data['boardpower'] = '';
  921. $data['lamppower'] = '';
  922. $data['batteryah'] = '';
  923. $data['batterytype'] = '';
  924. }else{
  925. $data['boardpower'] = $lampData['boardpower'];
  926. $data['lamppower'] = $lampData['lamppower'];
  927. $data['batteryah'] = $lampData['batteryah'];
  928. $data['batterytype'] = $lampData['batterytype'];
  929. }
  930. $data['shelfLife'] = 3;
  931. $data['controlType'] = '';
  932. // 项目信息
  933. $proData = $this->db->query('select id,createtime,projectname,address,company from project where id = '.$project_id)->row_array();
  934. $data['createtime'] = $proData['createtime'];
  935. $data['address'] = $proData['address'];
  936. $data['projectname'] = $proData['projectname'];
  937. $comData = $this->db->query('select id,name from company where id = '.$proData['company'])->row_array();
  938. $data['company'] = $comData['name'];
  939. exit(json_result('0000',$this->response['0000'],$data));
  940. }
  941. // 故障信息
  942. public function alarm_data(){
  943. $lampid = intval($this->input->post('lampid',true));
  944. $netStatus = intval($this->input->post('netStatus',true));
  945. $projectid = intval($this->input->post('projectid',true));
  946. $section = $this->input->post('section',true);
  947. $fields = 'L.section,L.projectid';
  948. $where = array();
  949. if (empty($lampid)){
  950. if (empty($projectid)) {
  951. exit(json_result('0007',$this->response['0007']));
  952. }else{
  953. $where['projectid'] = $projectid;
  954. if (empty($section)) {
  955. $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.projectid = '.$projectid)->row_array();
  956. }else{
  957. $where['section'] = $section;
  958. $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.section = "'.$section.'" AND L.projectid = '.$projectid)->row_array();
  959. }
  960. }
  961. }else{
  962. $data = $this->Lamp_model->getOne($lampid,$fields);
  963. }
  964. // if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
  965. // 路灯列表
  966. $where['status'] = 1;
  967. if (!empty($lampid)) $where['lampid'] = $lampid;
  968. $list = $this->Lamp_model->get_list_in(null, array(), 'L.number,L.isfaulted,AI.stralarmtype,AI.updatetime as alarmDate,AI.id as alarmId,L.id as lampId,L.protocoltype as lampProtocoltype,L.section,AI.status as failStatus',$where);
  969. $version = $this->session->userdata('version');
  970. $data['list'] = array();
  971. foreach ($list as $value) {
  972. // var_dump($value['stralarmtype']);
  973. // 故障信息处理
  974. // var_dump($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype']));
  975. if ($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype'])) {
  976. if (empty($version)) {
  977. $value['alarmInfo'] = '否';
  978. }else{
  979. $value['alarmInfo'] = 'Nothing';
  980. }
  981. }else{
  982. if (empty($version)) {
  983. $stralarmtype = trim($value['stralarmtype']);
  984. if (!empty($stralarmtype)) {
  985. $alarmArr = explode(',', $stralarmtype);
  986. $temp2 = array();
  987. foreach ($alarmArr as $a) {
  988. if ($a == '电池故障') {
  989. $a = '电池电压异常';
  990. }
  991. $temp2[] = $a;
  992. }
  993. $value['alarmInfo'] = implode(',', $temp2);
  994. }else{
  995. $value['alarmInfo'] = '否';
  996. }
  997. }else{
  998. $stralarmtype = trim($value['stralarmtype']);
  999. if (!empty($stralarmtype)) {
  1000. $alarmArr = explode(',', $stralarmtype);
  1001. $temp2 = array();
  1002. foreach ($alarmArr as $a) {
  1003. if ($a == '电池故障') {
  1004. $a = '电池电压异常';
  1005. }
  1006. if ($value['lampProtocoltype'] == 1) {
  1007. $temp2[] = modbus_alarm_translate($a);
  1008. }else{
  1009. $temp2[] = alarm_translate($a);
  1010. }
  1011. }
  1012. $value['alarmInfo'] = implode(',', $temp2);
  1013. }else{
  1014. $value['alarmInfo'] = 'Nothing';
  1015. }
  1016. }
  1017. }
  1018. unset($value['failStatus']);
  1019. unset($value['stralarmtype']);
  1020. $data['list'][] = $value;
  1021. }
  1022. exit(json_result('0000',$this->response['0000'],$data));
  1023. }
  1024. // 修改路灯方向
  1025. public function change_direction(){
  1026. $lampid = intval($this->input->post('lampid',true));
  1027. $direction = intval($this->input->post('direction',true));
  1028. if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
  1029. $this->Lamp_model->update(array('id'=>$lampid),array('direction'=>$direction));
  1030. exit(json_result('0000',$this->response['0000']));
  1031. }
  1032. // 路段下拉
  1033. public function section_nav(){
  1034. $project_id = intval($this->input->post('projectid',true));
  1035. if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
  1036. $sectionList = $this->db->query('select section,count(id) as lampcount from lampinfo where projectid = '.$project_id.' AND section != "" group by section')->result_array();
  1037. if (empty($sectionList)) {
  1038. $data = array();
  1039. }else{
  1040. $data = array();
  1041. foreach ($sectionList as $s) {
  1042. $data[] = array('name'=>$s['section'],'value'=>$s['section'],'lampcount'=>$s['lampcount']);
  1043. }
  1044. }
  1045. exit(json_result('0000',$this->response['0000'],array('list'=>$data)));
  1046. }
  1047. }
  1048. ?>