Map.php 48 KB

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