Map.php 47 KB

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