Map.php 47 KB

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