Map.php 48 KB

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