Map.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  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. $failure = $this->Lamp_model->get_count(['projectid'=>$project_id,'controllerstatus'=>5]);
  640. $lighting_arr = $this->Lamp_model->get_count(['projectid'=>$project_id,'lighteness >'=>0]);
  641. // $lighting_arr = $this->Lamp_model->getCountByFilter($role, 0, $project_id, $userid, array('L.status'=>1));
  642. // $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
  643. // $failure = 0;
  644. $data['online_rate'] = round($online_arr/$arr['num']*100, 2);
  645. $data['lighting_rate'] = round($lighting_arr/$arr['num']*100, 2);
  646. $data['online_count'] = intval($online_arr);
  647. $data['lighting_count'] = intval($lighting_arr);
  648. $data['failure_rate'] = round($failure/$arr['num']*100, 2);
  649. $data['failure_count'] = intval($failure);
  650. $data['totalgeneration'] = round($arr['power']/1000, 2);
  651. $data['total_lamp'] = intval($arr['num']);
  652. $data['co2_emission'] = round($arr['power']*0.977/1000, 3);
  653. $data['so2_emission'] = round($arr['power']*0.977/2620*8.5, 3);
  654. $data['coal_saving'] = round($arr['power']*0.977/2620, 3);
  655. $data['totalconsumption'] = round($arr['totalconsumption']/1000,2);
  656. } else {
  657. $data['online_rate'] = 0;
  658. $data['failure_rate'] = 0;
  659. $data['lighting_rate'] = 0;
  660. $data['failure_count'] = 0;
  661. $data['totalgeneration'] = 0;
  662. $data['total_lamp'] = 0;
  663. $data['co2_emission'] = 0;
  664. $data['so2_emission'] = 0;
  665. $data['coal_saving'] = 0;
  666. $data['online_count'] = 0;
  667. $data['lighting_count'] = 0;
  668. $data['totalconsumption'] = 0;
  669. }
  670. exit(json_result('0000', $this->response['0000'], $data));
  671. }
  672. // 路灯数据
  673. public function lamp_data(){
  674. $lampid = intval($this->input->post('lampid',true));
  675. if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
  676. $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';
  677. $join = [];
  678. $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'];
  679. $data = $this->Lamp_model->get_list_by_multi_join(['L.id'=>$lampid], $fields,NULL, NULL, $join, NULL, NUll, 'L', true);
  680. // $data = $this->Lamp_model->get_list(['id'=>$lampid],$fields);
  681. if (isset($data['alarmId']) && ($data['batstatus'] != 0 || $data['batstatus'] != 0 || $data['batstatus'] != 0 || $data['batstatus'] != 0)) {
  682. $data['isfaulted'] = '1';
  683. // $batstatus = $this->config->item('batstatus');
  684. // $panelstatus = $this->config->item('panelstatus');
  685. // $lampstatus = $this->config->item('lampstatus');
  686. // $tempstatus = $this->config->item('tempstatus');
  687. // $temp2 = array();
  688. // if (isset($batstatus[$data['batstatus']])) $temp2[] = $batstatus[$data['batstatus']];
  689. // if (isset($panelstatus[$data['panelstatus']])) $temp2[] = $panelstatus[$data['panelstatus']];
  690. // if (isset($lampstatus[$data['lampstatus']])) $temp2[] = $lampstatus[$data['lampstatus']];
  691. // if (isset($tempstatus[$data['tempstatus']])) $temp2[] = $tempstatus[$data['tempstatus']];
  692. // $data['isfaulted'] = implode(',', $temp2);
  693. // $res = $this->Alarm_model->get_one_by_filter(array('lampid'=>$data['id'],'status'=>0),'stralarmtype');
  694. // $stralarmtype = trim($res['stralarmtype']);
  695. // if (!empty($stralarmtype)) {
  696. // $value['isfaulted'] = '1';
  697. // }else{
  698. // $value['isfaulted'] = '0';
  699. // }
  700. }else{
  701. $data['isfaulted'] = '0';
  702. }
  703. $LampData = $this->db->query('select min(updatetime) as minTime from realtime_info_log where lampid = '.$lampid)->row_array();
  704. if (empty($LampData) || empty($LampData['minTime']) || $LampData['minTime'] == '1970-01-01 08:00:00') {
  705. if (empty($data['createtime']) || $data['createtime'] == '1970-01-01 08:00:00') {
  706. $beginTime = time();
  707. }else{
  708. $beginTime = strtotime($data['createtime']);
  709. }
  710. }else{
  711. $beginTime = strtotime($LampData['minTime']);
  712. }
  713. $data['userDate'] = round((time() - $beginTime) / (3600 * 24 * 356),1);
  714. $data['userDate'] = $data['userDate'] > 100 ? 0 : $data['userDate'];
  715. // $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();
  716. $LampInfoData = 0;
  717. if (empty($LampInfoData) || empty($LampInfoData['id'])) {
  718. $lamppower = 0;
  719. }else{
  720. $lamppower = $LampInfoData['lamppower'];
  721. }
  722. if ($lamppower == 0) {
  723. $later = 3;
  724. }else{
  725. $totalconsumption = $lamppower*10*365*3;
  726. $consum = $totalconsumption - $data['totalconsumption'];
  727. if ($consum <= 0) {
  728. $later = 0;
  729. }else{
  730. $later = round($consum/($lamppower*10)/365,1);
  731. }
  732. }
  733. $data['later'] = $later;
  734. $data['totalDate'] = $later + $data['userDate'];
  735. // 日照时间
  736. $project_weather = $this->db->query('select * from project_weather where projectId = '.$data['projectid'])->row_array();
  737. if (empty($project_weather)) {
  738. $data['sunTime'] = 0;
  739. }else{
  740. $weatherInfo = json_decode($project_weather['weatherInfo'],true);
  741. if (!empty($weatherInfo[0])) {
  742. $sr = $weatherInfo[0]['sr'];
  743. $ss = $weatherInfo[0]['ss'];
  744. $srArr = explode(':', $sr);
  745. $ssArr = explode(':', $ss);
  746. $data['sunTime'] = round((intval($ssArr[0])*60+intval($ssArr[1]) - (intval($srArr[0])*60+intval($srArr[1])))/60,1);
  747. }else{
  748. $data['sunTime'] = 0;
  749. }
  750. }
  751. exit(json_result('0000',$this->response['0000'],$data));
  752. }
  753. // 路段信息
  754. public function section_data(){
  755. $lampid = intval($this->input->post('lampid',true));
  756. $netStatus = intval($this->input->post('netStatus',true));
  757. $projectid = intval($this->input->post('projectid',true));
  758. $section = $this->input->post('section',true);
  759. $fields = 'L.section,L.projectid';
  760. if (empty($lampid)){
  761. if (empty($projectid) || empty($section)) {
  762. exit(json_result('0007',$this->response['0007']));
  763. }else{
  764. $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.section = "'.$section.'" AND L.projectid = '.$projectid)->row_array();
  765. }
  766. }else{
  767. $data = $this->Lamp_model->getOne($lampid,$fields);
  768. }
  769. if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
  770. // 路灯总数
  771. $data['lamp_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid']));
  772. $data['lamp_count'] = intval($data['lamp_count']);
  773. // 故障数
  774. $data['fail_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'status'=>1));
  775. $data['fail_count'] = intval($data['fail_count']);
  776. $data['fail_rate'] = round($data['fail_count']/$data['lamp_count']*100,2);
  777. // 在线数
  778. $data['online_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'online'=>1));
  779. $data['online_count'] = intval($data['online_count']);
  780. $data['online_rate'] = round($data['online_count']/$data['lamp_count']*100,2);
  781. // 亮灯数
  782. $data['light_count'] = $this->Lamp_model->get_total(null, array(), '*', array('section'=>$data['section'],'projectid'=>$data['projectid'],'lightStatus'=>1));
  783. $data['light_count'] = intval($data['light_count']);
  784. $data['light_rate'] = round($data['light_count']/$data['lamp_count']*100,2);
  785. $res = $this->Lamp_model->get_section_avg($data['projectid'],$data['section']);
  786. $data['daychargemincurrent'] = intval($res['daychargemincurrent']);
  787. $data['daydischargemincurrent'] = intval($res['daydischargemincurrent']);
  788. $data['totalgeneration'] = round($res['totalgeneration'],2);
  789. $data['totalconsumption'] = intval($res['totalconsumption'],2);
  790. $data['electricleft'] = intval($res['electricleft']);
  791. $data['battvoltage'] = round($res['battvoltage'],1);
  792. // 路灯列表
  793. $where = array('section'=>$data['section'],'projectid'=>$data['projectid']);
  794. $onlineStatus = intval($this->input->post('onlineStatus',true));
  795. if (!empty($onlineStatus)) $where['online'] = 1;
  796. $lightStatus = intval($this->input->post('lightStatus',true));
  797. if (!empty($lightStatus)) $where['lightStatus'] = 1;
  798. $failStatus = intval($this->input->post('failStatus',true));
  799. if (!empty($failStatus)) $where['status'] = 1;
  800. $list = $this->Lamp_model->get_list_in(null, array(), 'L.id,L.number,L.netstatus as netStatus,L.lighteness,L.isfaulted',$where);
  801. $version = $this->session->userdata('version');
  802. $data['lampList'] = array();
  803. foreach ($list as $value) {
  804. // 故障信息处理
  805. if ($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype'])) {
  806. if (empty($version)) {
  807. $value['stralarmtype'] = '否';
  808. $value['isfaulted'] = '0';
  809. }else{
  810. $value['stralarmtype'] = 'Nothing';
  811. $value['isfaulted'] = '0';
  812. }
  813. }else{
  814. if (empty($version)) {
  815. $stralarmtype = trim($value['stralarmtype']);
  816. if (!empty($stralarmtype)) {
  817. $alarmArr = explode(',', $stralarmtype);
  818. $temp2 = array();
  819. foreach ($alarmArr as $a) {
  820. if ($a == '电池故障') {
  821. $a = '电池电压异常';
  822. }
  823. $temp2[] = $a;
  824. }
  825. $value['stralarmtype'] = implode(',', $temp2);
  826. $value['isfaulted'] = '1';
  827. }else{
  828. $value['stralarmtype'] = '否';
  829. $value['isfaulted'] = '0';
  830. }
  831. }else{
  832. $stralarmtype = trim($res['stralarmtype']);
  833. if (!empty($stralarmtype)) {
  834. $alarmArr = explode(',', $stralarmtype);
  835. $temp2 = array();
  836. foreach ($alarmArr as $a) {
  837. if ($a == '电池故障') {
  838. $a = '电池电压异常';
  839. }
  840. if ($value['lampProtocoltype'] == 1) {
  841. $temp[] = modbus_alarm_translate($a);
  842. }else{
  843. $temp[] = alarm_translate($a);
  844. }
  845. }
  846. $value['stralarmtype'] = implode(',', $temp2);
  847. $value['isfaulted'] = '1';
  848. }else{
  849. $value['stralarmtype'] = 'Nothing';
  850. $value['isfaulted'] = '0';
  851. }
  852. }
  853. }
  854. unset($value['failStatus']);
  855. // unset($value['stralarmtype']);
  856. $data['lampList'][] = $value;
  857. }
  858. exit(json_result('0000',$this->response['0000'],$data));
  859. }
  860. // 项目信息
  861. public function project_data(){
  862. $lampid = intval($this->input->post('lampid',true));
  863. if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
  864. $fields = 'L.projectid,L.section';
  865. $data = $this->Lamp_model->getOne($lampid,$fields);
  866. $userid = $this->get_user_info('id');
  867. // $companyid = $this->get_user_info('companyid');
  868. $role = $this->get_user_info('role');
  869. $project_id = $data['projectid'];
  870. $arr = $this->Lamp_model->getTotalLampInfo($role, 0, $project_id, $userid,1);
  871. if (!empty($arr['num'])) {
  872. $online_arr = $this->Lamp_model->getOnlineCount($role, 0, $project_id, $userid, 1);
  873. $lighting_arr = $this->Lamp_model->getCountByFilter($role, 0, $project_id, $userid, array('L.status'=>1));
  874. // $failure = $this->Lamp_model->get_fault_count(array('L.projectid'=>$project_id,'L.isfaulted'=>1), $role, 0, $userid);
  875. $failure = 0;
  876. $data['online_rate'] = round($online_arr['num']/$arr['num']*100, 2);
  877. $data['lighting_rate'] = round($lighting_arr['num']/$arr['num']*100, 2);
  878. $data['online_count'] = intval($online_arr['num']);
  879. $data['lighting_count'] = intval($lighting_arr['num']);
  880. $data['failure_rate'] = round($failure/$arr['num']*100, 2);
  881. $data['failure_count'] = intval($failure);
  882. $data['totalgeneration'] = round($arr['power'], 2);
  883. $data['total_lamp'] = intval($arr['num']);
  884. $data['co2_emission'] = round($arr['power']*0.977, 3);
  885. $data['so2_emission'] = round($arr['power']*0.977/2620*8.5, 3);
  886. $data['coal_saving'] = round($arr['power']*0.977/2620, 3);
  887. $data['totalconsumption'] = round($arr['totalconsumption'],2);
  888. } else {
  889. $data['online_rate'] = 0;
  890. $data['failure_rate'] = 0;
  891. $data['lighting_rate'] = 0;
  892. $data['failure_count'] = 0;
  893. $data['totalgeneration'] = 0;
  894. $data['total_lamp'] = 0;
  895. $data['co2_emission'] = 0;
  896. $data['so2_emission'] = 0;
  897. $data['coal_saving'] = 0;
  898. $data['online_count'] = 0;
  899. $data['lighting_count'] = 0;
  900. $data['totalconsumption'] = 0;
  901. }
  902. // 获取路段下拉列表
  903. $section_nav = $this->db->query('select section from lampinfo where projectid = '.$project_id.' AND section != "" group by section')->result_array();
  904. $data['section_nav'] = array();
  905. foreach ($section_nav as $s) {
  906. $data['section_nav'][] = array('name'=>$s['section'],'value'=>$s['section']);
  907. }
  908. // 获取项目下控制器类型
  909. $pro_list = $this->db->query('select protocoltype from lampinfo where projectid = '.$project_id.' group by protocoltype')->result_array();
  910. $conStr = '';
  911. foreach ($pro_list as $p) {
  912. if ($conStr != '') {
  913. $conStr .= '/';
  914. }
  915. // if ($p['protocoltype'] == 0) {
  916. // $conStr .= 'MQTT';
  917. // }elseif ($p['protocoltype'] == 1) {
  918. // $conStr .= 'NBIOT';
  919. // }elseif ($p['protocoltype'] == 2) {
  920. // $conStr .= 'UDP';
  921. // }else{
  922. // $conStr .= 'LORAWAN';
  923. // }
  924. $conStr .= 'MQTT';
  925. }
  926. $data['protocolType'] = $conStr;
  927. // 配置信息
  928. $lampData = $this->db->query('select id,boardpower,lamppower,batteryah,batterytype from lampinfo where projectid = '.$project_id.' order by id ASC limit 1')->row_array();
  929. if (empty($lampData) || $lampData['id']) {
  930. $data['boardpower'] = '';
  931. $data['lamppower'] = '';
  932. $data['batteryah'] = '';
  933. $data['batterytype'] = '';
  934. }else{
  935. $data['boardpower'] = $lampData['boardpower'];
  936. $data['lamppower'] = $lampData['lamppower'];
  937. $data['batteryah'] = $lampData['batteryah'];
  938. $data['batterytype'] = $lampData['batterytype'];
  939. }
  940. $data['shelfLife'] = 3;
  941. $data['controlType'] = '';
  942. // 项目信息
  943. $proData = $this->db->query('select id,createtime,projectname,address,company from project where id = '.$project_id)->row_array();
  944. $data['createtime'] = $proData['createtime'];
  945. $data['address'] = $proData['address'];
  946. $data['projectname'] = $proData['projectname'];
  947. $comData = $this->db->query('select id,name from company where id = '.$proData['company'])->row_array();
  948. $data['company'] = $comData['name'];
  949. exit(json_result('0000',$this->response['0000'],$data));
  950. }
  951. // 故障信息
  952. public function alarm_data(){
  953. $lampid = intval($this->input->post('lampid',true));
  954. $netStatus = intval($this->input->post('netStatus',true));
  955. $projectid = intval($this->input->post('projectid',true));
  956. $section = $this->input->post('section',true);
  957. $fields = 'L.section,L.projectid';
  958. $where = array();
  959. if (empty($lampid)){
  960. if (empty($projectid)) {
  961. exit(json_result('0007',$this->response['0007']));
  962. }else{
  963. $where['projectid'] = $projectid;
  964. if (empty($section)) {
  965. $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.projectid = '.$projectid)->row_array();
  966. }else{
  967. $where['section'] = $section;
  968. $data = $this->db->query('select '.$fields.' from lampinfo AS L where L.section = "'.$section.'" AND L.projectid = '.$projectid)->row_array();
  969. }
  970. }
  971. }else{
  972. $data = $this->Lamp_model->getOne($lampid,$fields);
  973. }
  974. // if (empty($data['section'])) exit(json_result('0419',$this->response['0419']));
  975. // 路灯列表
  976. $where['status'] = 1;
  977. if (!empty($lampid)) $where['lampid'] = $lampid;
  978. // $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);
  979. // $version = $this->session->userdata('version');
  980. $data['list'] = array();
  981. // foreach ($list as $value) {
  982. // // var_dump($value['stralarmtype']);
  983. // // 故障信息处理
  984. // // var_dump($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype']));
  985. // if ($value['isfaulted'] == 0 || $value['failStatus'] == 1 || empty($value['stralarmtype'])) {
  986. // if (empty($version)) {
  987. // $value['alarmInfo'] = '否';
  988. // }else{
  989. // $value['alarmInfo'] = 'Nothing';
  990. // }
  991. // }else{
  992. // if (empty($version)) {
  993. // $stralarmtype = trim($value['stralarmtype']);
  994. // if (!empty($stralarmtype)) {
  995. // $alarmArr = explode(',', $stralarmtype);
  996. // $temp2 = array();
  997. // foreach ($alarmArr as $a) {
  998. // if ($a == '电池故障') {
  999. // $a = '电池电压异常';
  1000. // }
  1001. // $temp2[] = $a;
  1002. // }
  1003. // $value['alarmInfo'] = implode(',', $temp2);
  1004. // }else{
  1005. // $value['alarmInfo'] = '否';
  1006. // }
  1007. // }else{
  1008. // $stralarmtype = trim($value['stralarmtype']);
  1009. // if (!empty($stralarmtype)) {
  1010. // $alarmArr = explode(',', $stralarmtype);
  1011. // $temp2 = array();
  1012. // foreach ($alarmArr as $a) {
  1013. // if ($a == '电池故障') {
  1014. // $a = '电池电压异常';
  1015. // }
  1016. // if ($value['lampProtocoltype'] == 1) {
  1017. // $temp2[] = modbus_alarm_translate($a);
  1018. // }else{
  1019. // $temp2[] = alarm_translate($a);
  1020. // }
  1021. // }
  1022. // $value['alarmInfo'] = implode(',', $temp2);
  1023. // }else{
  1024. // $value['alarmInfo'] = 'Nothing';
  1025. // }
  1026. // }
  1027. // }
  1028. // unset($value['failStatus']);
  1029. // unset($value['stralarmtype']);
  1030. // $data['list'][] = $value;
  1031. // }
  1032. exit(json_result('0000',$this->response['0000'],$data));
  1033. }
  1034. // 修改路灯方向
  1035. public function change_direction(){
  1036. $lampid = intval($this->input->post('lampid',true));
  1037. $direction = intval($this->input->post('direction',true));
  1038. if (empty($lampid)) exit(json_result('0007',$this->response['0007']));
  1039. $this->Lamp_model->update(array('id'=>$lampid),array('direction'=>$direction));
  1040. exit(json_result('0000',$this->response['0000']));
  1041. }
  1042. // 路段下拉
  1043. public function section_nav(){
  1044. $project_id = intval($this->input->post('projectid',true));
  1045. if (empty($project_id)) exit(json_result('0007',$this->response['0007']));
  1046. $sectionList = $this->db->query('select section,count(id) as lampcount from lampinfo where projectid = '.$project_id.' AND section != "" group by section')->result_array();
  1047. if (empty($sectionList)) {
  1048. $data = array();
  1049. }else{
  1050. $data = array();
  1051. foreach ($sectionList as $s) {
  1052. $data[] = array('name'=>$s['section'],'value'=>$s['section'],'lampcount'=>$s['lampcount']);
  1053. }
  1054. }
  1055. exit(json_result('0000',$this->response['0000'],array('list'=>$data)));
  1056. }
  1057. }
  1058. ?>