Map.php 47 KB

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