Map.php 47 KB

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