Map.php 44 KB

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