Home.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. include_once(FCPATH . 'application/controllers/Base_Controller.php');
  3. class Home extends Base_Controller {
  4. public function __construct() {
  5. parent::__construct();
  6. $this->load->model('Lamp_model');
  7. $this->load->model('Project_model');
  8. $this->load->model('Global_location_model');
  9. }
  10. private function get_project_id(){
  11. $cityId = intval($this->input->post('cityId',true));
  12. $proId = intval($this->input->post('proId',true));
  13. $projectIdArr = array();
  14. $areaList = array();
  15. $cityList = array();
  16. $proList = array();
  17. if (!empty($proId)) {
  18. $proList[] = array('id'=>$proId,'level'=>1);
  19. $list = $this->Global_location_model->get_list(['pid'=>$proId],'id,level');
  20. foreach ($list as $key => $value) {
  21. if ($value['level'] == 3) {
  22. $cityList[] = $value;
  23. }elseif ($value['level'] == 4) {
  24. $areaList[] = $value;
  25. }
  26. }
  27. }
  28. if (!empty($cityId)) {
  29. $cityList[] = array('id'=>$cityId,'level'=>2);
  30. $list = $this->Global_location_model->get_list(['pid'=>$cityId],'id,level');
  31. foreach ($list as $key => $value) {
  32. if ($value['level'] == 4) $areaList[] = $value;
  33. }
  34. }
  35. $cityArr = array_unique(array_merge(array_column($proList, 'id'),array_column($cityList, 'id'),array_column($areaList, 'id')));
  36. if (!empty($cityArr)) {
  37. $res = $this->Project_model->get_list(['cityid'=>$cityArr],'id');
  38. $projectIdArr = array_unique(array_column($res, 'id'));
  39. }
  40. return $projectIdArr;
  41. }
  42. // 设备统计信息
  43. public function data(){
  44. $projectIdArr = $this->get_project_id();
  45. $data = array(
  46. 'day_new_count' => 0,
  47. 'day_faulty_count' => 0,
  48. 'total_light_count' => 0,
  49. 'light_up_count' => 0,
  50. 'online_count' => 0,
  51. 'faulty_count' => 0
  52. );
  53. $data['logCount'] = $this->get_user_info('logCount');
  54. $date = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 6*3600);
  55. $role = $this->get_user_info('role');
  56. if ($role == SYSTEM_ADMIN) {
  57. $data['total_light_count'] = $this->Lamp_model->get_count();
  58. $where = ['createtime >='=>$date];
  59. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  60. $data['day_new_count'] = $this->Lamp_model->get_count($where);
  61. $where = ['netstatus'=>1,'status'=>1];
  62. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  63. $data['light_up_count'] = $this->Lamp_model->get_count($where);
  64. $where = ['netstatus'=>1];
  65. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  66. $data['online_count'] = $this->Lamp_model->get_count($where);
  67. // $where = ['netstatus'=>1,'devstatus !='=>0];
  68. // if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  69. // $data['faulty_count'] = $this->Lamp_model->get_count($where);
  70. // $where = ['netstatus'=>1,'logtime >='=>$date,'devstatus !='=>0];
  71. // if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  72. // $data['day_faulty_count'] = $this->Lamp_model->get_count($where);
  73. $where = ['L.netstatus ='=>1];
  74. if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
  75. $where1 = [];
  76. foreach ($where as $key => $value) {
  77. if (is_array($value)) {
  78. $where1[] = $key.' in ('.implode(',', $value).')';
  79. }else{
  80. $where1[] = $key.' '.$value;
  81. }
  82. }
  83. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  84. $where1 = implode(' AND ', $where1);
  85. $join = [];
  86. $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
  87. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  88. $data['faulty_count'] = $total['total'];
  89. $where1 .= ' AND WI.updatetime >= "'.$date.'"';
  90. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  91. $data['day_faulty_count'] = $total['total'];
  92. }else{
  93. $company = $this->get_user_info('company');
  94. $where = ['P.company ='=>$company];
  95. if (!empty($projectIdArr)) $where['P.id'] = $projectIdArr;
  96. $join = [
  97. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  98. ];
  99. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  100. $data['total_light_count'] = $total['total'];
  101. $where['L.createtime >='] = $date;
  102. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  103. $data['day_new_count'] = $total['total'];
  104. unset($where['L.createtime >=']);
  105. $where['L.netstatus ='] = 1;
  106. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  107. $data['online_count'] = $total['total'];
  108. $where['L.status ='] = 1;
  109. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  110. $data['light_up_count'] = $total['total'];
  111. unset($where['L.status']);
  112. // $where['L.devstatus !='] = 0;
  113. $where1 = [];
  114. foreach ($where as $key => $value) {
  115. if (is_array($value)) {
  116. $where1[] = $key.' in ('.implode(',', $value).')';
  117. }else {
  118. $where1[] = $key.' '.$value;
  119. }
  120. }
  121. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  122. $where1 = implode(' AND ', $where1);
  123. $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
  124. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  125. $data['faulty_count'] = $total['total'];
  126. // $where['L.devstatus !='] = 0;
  127. $where1 .= ' AND WI.updatetime >= "'.$date.'"';
  128. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  129. $data['day_faulty_count'] = $total['total'];
  130. }
  131. exit(json_result('0000',$this->response['0000'],$data));
  132. }
  133. // 发用电量统计信息
  134. public function sta_info(){
  135. $data = array(
  136. 'electricity' => 0,
  137. 'CO2_reduction' => 0,
  138. 'SO2_reduction' => 0,
  139. 'TCE_reduction' => 0
  140. );
  141. $type = intval($this->input->post('type',true));
  142. $projectIdArr = $this->get_project_id();
  143. $role = $this->get_user_info('role');
  144. $type = $this->input->post('type',true);
  145. $where = array();
  146. if ($role != SYSTEM_ADMIN){
  147. $company = $this->get_user_info('company');
  148. $where['P.company'] = $company;
  149. }
  150. if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
  151. if ($type == 0) {
  152. $join = [];
  153. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  154. $join[] = ['table'=>'(select w1.* from realtime_info_log as w1 join (select lampid,max(updatetime) as maxTime from realtime_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  155. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.dischargeday) as discharge,sum(RI.chargeday) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  156. }elseif ($type == 1) {
  157. $join = [];
  158. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  159. $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  160. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.weekdischarg) as discharge,sum(RI.weekchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  161. }elseif ($type == 2) {
  162. $join = [];
  163. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  164. $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  165. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.monthdischarge) as discharge,sum(RI.monthchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  166. }else{
  167. $join = [];
  168. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  169. $join[] = ['table'=>'(select w1.* from history_info_log as w1 join (select lampid,max(updatetime) as maxTime from history_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as RI','cond'=>'L.id = RI.lampid','type'=>'inner'];
  170. $res = $this->Lamp_model->get_list_by_multi_join($where, 'sum(RI.totaldischarah) as discharge,sum(RI.totalchargeah) as charge',NULL, NULL, $join, NULL, NUll, 'L', true);
  171. }
  172. $data['electricity'] = $res['discharge'];
  173. $data['CO2_reduction'] = $res['discharge'];
  174. $data['SO2_reduction'] = $res['discharge'];
  175. $data['TCE_reduction'] = $res['discharge'];
  176. $data['CO2_reduction'] = round($res['charge']*0.977, 3);
  177. $data['SO2_reduction'] = round($res['charge']*0.977/2620*8.5*1000, 3);
  178. $data['TCE_reduction'] = round($res['charge']*0.977/2620*1000, 3);
  179. exit(json_result('0000',$this->response['0000'],$data));
  180. }
  181. // 设备统计列表
  182. public function dev_list(){
  183. $projectIdArr = $this->get_project_id();
  184. $role = $this->get_user_info('role');
  185. $type = $this->input->post('type',true);
  186. $where = array();
  187. if ($role != SYSTEM_ADMIN){
  188. $company = $this->get_user_info('company');
  189. $where[] = 'P.company = '.$company;
  190. }
  191. if ($type == 2) {
  192. $fields = 'L.manu as company';
  193. $group = 'group by L.manu';
  194. $where[] = 'L.manu != 0';
  195. $where[] = 'L.manu != ""';
  196. }elseif ($type == 3) {
  197. $fields = 'L.supplier as company';
  198. $group = 'group by L.supplier';
  199. $where[] = 'L.supplier != 0';
  200. $where[] = 'L.supplier != ""';
  201. }elseif ($type == 4) {
  202. $fields = 'L.po as company';
  203. $group = 'group by L.po';
  204. $where[] = 'L.po != 0';
  205. $where[] = 'L.po != ""';
  206. }else{
  207. $fields = 'L.upazilla as company';
  208. $group = 'group by L.upazilla';
  209. $where[] = 'L.upazilla != 0';
  210. $where[] = 'L.upazilla != ""';
  211. }
  212. if (!empty($projectIdArr)) $where[] = 'L.projectid in ('.implode(',', $projectIdArr).')';
  213. $where1 = empty($where) ? '' : 'where '.implode(' AND ', $where);
  214. $query = 'select t1.total,C.name,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  215. $list = $this->db->query($query)->result_array();
  216. if (empty($list)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  217. $temp = array();
  218. foreach ($list as $key => $value) {
  219. $temp2 = array('name'=>$value['name'],'total'=>$value['total'],'onlineCount'=>0,'offlineCount'=>0,'faultCount'=>0);
  220. $temp[$value['id']] = $temp2;
  221. }
  222. $companyArr = array_unique(array_column($list, 'id'));
  223. if ($type == 2) {
  224. $where[] = 'L.manu in ('.implode(',', $companyArr).')';
  225. }elseif ($type == 3) {
  226. $where[] = 'L.supplier in ('.implode(',', $companyArr).')';
  227. }elseif ($type == 4) {
  228. $where[] = 'L.po in ('.implode(',', $companyArr).')';
  229. }else{
  230. $where[] = 'L.upazilla in ('.implode(',', $companyArr).')';
  231. }
  232. $where1 = $where;
  233. $where1[] = 'L.netstatus = 0';
  234. $where1 = 'where '.implode(' AND ', $where1);
  235. $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  236. $list = $this->db->query($query)->result_array();
  237. foreach ($list as $key => $value) {
  238. if (isset($temp[$value['id']])) $temp[$value['id']]['offlineCount'] = $value['total'];
  239. }
  240. $where1 = $where;
  241. $where1[] = 'L.netstatus = 1';
  242. $where1 = 'where '.implode(' AND ', $where1);
  243. $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  244. $list = $this->db->query($query)->result_array();
  245. foreach ($list as $key => $value) {
  246. if (isset($temp[$value['id']])) $temp[$value['id']]['onlineCount'] = $value['total'];
  247. }
  248. $where1 = $where;
  249. $where1[] = 'L.netstatus = 1';
  250. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  251. $where1 = 'where '.implode(' AND ', $where1);
  252. $query = 'select t1.total,C.id from (select count(*) as total,'.$fields.' from lampinfo AS L join project AS P on P.id = L.projectid join (select w1.lampid,w1.batstatus,w1.panelstatus,w1.lampstatus,w1.tempstatus from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.updatetime = w2.maxTime AND w1.lampid = w2.lampid) as WI on WI.lampid = L.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  253. $list = $this->db->query($query)->result_array();
  254. foreach ($list as $key => $value) {
  255. if (isset($temp[$value['id']])) $temp[$value['id']]['faultCount'] = $value['total'];
  256. }
  257. $list = array_values($temp);
  258. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  259. }
  260. // 故障信息列表
  261. public function alarm_list(){
  262. $projectIdArr = $this->get_project_id();
  263. $role = $this->get_user_info('role');
  264. $where = array();
  265. if ($role != SYSTEM_ADMIN){
  266. $company = $this->get_user_info('company');
  267. $where[] = 'P.company = '.$company;
  268. }
  269. if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
  270. $where[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  271. $where[] = 'L.netstatus = 1';
  272. $where1 = implode(' AND ', $where);
  273. $join = [
  274. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  275. ];
  276. $join[] = ['table'=>'(select w1.* from warning_info_log as w1 join (select lampid,max(updatetime) as maxTime from warning_info_log group by lampid) as w2 on w1.lampid = w2.lampid AND w1.updatetime = w2.maxTime) as WI','cond'=>'L.id = WI.lampid','type'=>'inner'];
  277. $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'inner'];
  278. $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'inner'];
  279. $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid','type'=>'inner'];
  280. $list = $this->Lamp_model->get_list_by_join($where1, 'P.projectname as project,WI.batstatus,WI.id,WI.panelstatus,WI.lampstatus,WI.tempstatus,P.cityid,L.address,L.section,G1.english_name as areaName,G2.english_name as cityName,G3.english_name as proName,WI.updatetime,G1.timezone',NULL, NULL, $join, NULL, NUll, 'L');
  281. $batstatus = $this->config->item('batstatus');
  282. $panelstatus = $this->config->item('panelstatus');
  283. $lampstatus = $this->config->item('lampstatus');
  284. $tempstatus = $this->config->item('tempstatus');
  285. foreach ($list as $key => $value) {
  286. $location = $value['proName'].'/'.$value['cityName'].'/'.$value['areaName'];
  287. $location = empty($value['section']) ? $location : $location.'/'.$value['section'];
  288. $list[$key]['location'] = $location;
  289. $list[$key]['fault_time'] = set_timezone($value['updatetime'],$value['timezone']);
  290. $temp2 = array();
  291. if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
  292. if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
  293. if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
  294. if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
  295. $list[$key]['fault_type'] = implode(',', $temp2);
  296. unset($list[$key]['cityName']);
  297. unset($list[$key]['proName']);
  298. unset($list[$key]['areaName']);
  299. unset($list[$key]['section']);
  300. unset($list[$key]['timezone']);
  301. unset($list[$key]['updatetime']);
  302. }
  303. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  304. }
  305. // 字段管理
  306. public function fields(){
  307. $userid = $this->get_user_info('id');
  308. $data = $this->User_model->get_user_field($userid);
  309. if (empty($data) || empty($data['lampfield'])) {
  310. // $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  311. $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  312. }else{
  313. if ($data['lampfield'] == 'number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status') {
  314. $data['lampfield'] .= ',section';
  315. }
  316. $fieldstr = $data['lampfield'];
  317. }
  318. // 系统默认
  319. $def = array(
  320. array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  321. array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  322. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  323. array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,L.rssi','fields1'=>'status','enname'=>'Network status'),
  324. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  325. array('name'=>'更新时间','field'=>'RI.updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  326. array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  327. array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  328. array('name'=>'负载功率(W)','field'=>'RI.loadpower','fields1'=>'loadpower','enname'=>'LED power(W)'),
  329. array('name'=>'蓄电池电压(V)','field'=>'RI.batpower as battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  330. array('name'=>'蓄电池总过放次数','field'=>'HI.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  331. array('name'=>'太阳能板功率(W)','field'=>'RI.panelpower as solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  332. array('name'=>'是否故障','field'=>'AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.status as alarmStatus','fields1'=>'isfaulted','enname'=>'Fault'),
  333. );
  334. // $def = array(
  335. // array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  336. // array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  337. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  338. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status','fields1'=>'status','enname'=>'Network status'),
  339. // // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  340. // array('name'=>'更新时间','field'=>'L.logtime as updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  341. // array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  342. // array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  343. // array('name'=>'路灯功率(W)','field'=>'L.lamppower','fields1'=>'lamppower','enname'=>'Lamp power(W)'),
  344. // array('name'=>'蓄电池充电阶段','field'=>'L.chargestage','fields1'=>'chargestage','enname'=>'Charging stage'),
  345. // array('name'=>'蓄电池电压(V)','field'=>'L.battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  346. // array('name'=>'蓄电池总过放次数','field'=>'L.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  347. // array('name'=>'太阳能板功率(W)','field'=>'L.solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  348. // array('name'=>'是否故障','field'=>'L.isfaulted','fields1'=>'isfaulted','enname'=>'Fault'),
  349. // );
  350. // 路灯信息
  351. $lampinfo = array(
  352. array('name'=>'当前策略','field'=>'L.policyid','fields1'=>'policyid','enname'=>'Current strategy'),
  353. array('name'=>'路灯id','field'=>'L.id','fields1'=>'id','enname'=>'Lamp ID'),
  354. // array('name'=>'网络名称','field'=>'N.networkname','fields1'=>'networkname','enname'=>'Network name'),
  355. array('name'=>'项目名称','field'=>'P.projectname','fields1'=>'projectname','enname'=>'Project name'),
  356. array('name'=>'经度','field'=>'L.longitude','fields1'=>'longitude','enname'=>'Longitude'),
  357. array('name'=>'纬度','field'=>'L.latitude','fields1'=>'latitude','enname'=>'Latitude'),
  358. // array('name'=>'sim卡号','field'=>'N.simid','fields1'=>'simid','enname'=>'SIM card number'),
  359. // array('name'=>'套餐剩余','field'=>'N.packageSurplus','fields1'=>'packageSurplus','enname'=>'Package surplus'),
  360. array('name'=>'路灯类型','field'=>'L.lamptype','fields1'=>'lamptype','enname'=>'Lamp type'),
  361. array('name'=>'太阳能板类型','field'=>'L.boardtype','fields1'=>'boardtype','enname'=>'Solar panel type'),
  362. // array('name'=>'太阳能板功率(W)','field'=>'L.boardpower','fields1'=>'boardpower','enname'=>'Solar panel power(W)'),
  363. // array('name'=>'蓄电池类型','field'=>'L.batterytype','fields1'=>'batterytype','enname'=>'Battery type'),
  364. array('name'=>'蓄电池AH数(ah)','field'=>'HI.totalchargeah as batteryah','fields1'=>'batteryah','enname'=>'Battery capacity(ah)'),
  365. // array('name'=>'负载功率(W)','field'=>'L.loadpower','fields1'=>'loadpower','enname'=>'Load power(W)'),
  366. // array('name'=>'蓄电池剩余电量','field'=>'L.electricleft','fields1'=>'electricleft','enname'=>'Remaining battery capacity(Ah)'),
  367. );
  368. // 路灯信息日志
  369. $lamp_info_log = array(
  370. array('name'=>'路灯电压(V)','field'=>'RI.loadvoltage as lampvoltage','fields1'=>'lampvoltage','enname'=>'Lamp voltage(V)'),
  371. array('name'=>'路灯电流(A)','field'=>'RI.loadcurrent as lampcurrent','fields1'=>'lampcurrent','enname'=>'Lamp current(A)'),
  372. // array('name'=>'灯头温度(℃)','field'=>'L.lamptemper as temper','fields1'=>'temper','enname'=>'Lamp temperature(℃)'),
  373. );
  374. $solar_info_log = array(
  375. array('name'=>'太阳能板电压(V)','field'=>'RI.panelvoltage as solarvoltage','fields1'=>'solarvoltage','enname'=>'Solar panel voltage(V)'),
  376. array('name'=>'太阳能板电流(A)','field'=>'RI.panelcurrent as solarcurrent','fields1'=>'solarcurrent','enname'=>'Solar panel current(A)')
  377. );
  378. // 蓄电池信息日志
  379. // $battery_info_log = array(
  380. // array('name'=>'蓄电池状态','field'=>'L.battstatus','fields1'=>'battstatus','enname'=>'Battery status'),
  381. // array('name'=>'蓄电池充电电流(A)','field'=>'L.chargecurrent','fields1'=>'chargecurrent','enname'=>'Charging current(A)'),
  382. // array('name'=>'蓄电池放电电流(A)','field'=>'L.discharcurrent','fields1'=>'discharcurrent','enname'=>'Discharging current(A)'),
  383. // array('name'=>'蓄电池充电功率(w)','field'=>'L.chargepower','fields1'=>'chargepower','enname'=>'Charging power(w)'),
  384. // array('name'=>'蓄电池放电功率(w)','field'=>'L.dischargepower','fields1'=>'dischargepower','enname'=>'Discharging power(w)'),
  385. // array('name'=>'蓄电池表面温度(℃)','field'=>'L.batttemper','fields1'=>'batttemper','enname'=>'Battery surface temperature(℃)'),
  386. // array('name'=>'蓄电池总电量','field'=>'L.electrictotal','fields1'=>'electrictotal','enname'=>'Total battery capacity(Ah)'),
  387. // array('name'=>'蓄电池电量SOC(%)','field'=>'L.electricSOC','fields1'=>'electricSOC','enname'=>'Battery SOC(%)'),
  388. // array('name'=>'当天最低电压(V)','field'=>'L.voltagedaymin','fields1'=>'voltagedaymin','enname'=>'Minimum voltage(V)'),
  389. // array('name'=>'当天最高电压(V)','field'=>'L.voltagedaymax','fields1'=>'voltagedaymax','enname'=>'Highest voltage(V)'),
  390. // array('name'=>'当天充电安时数(ah)','field'=>'L.daychargeah','fields1'=>'daychargeah','enname'=>'Charging AH(ah)'),
  391. // array('name'=>'当天放电安时数(ah)','field'=>'L.daydischarah','fields1'=>'daydischarah','enname'=>'Discharging AH(ah)'),
  392. // array('name'=>'当天充电最大功率(W)','field'=>'L.daychargemaxpow','fields1'=>'daychargemaxpow','enname'=>'Charging max-power(W)'),
  393. // array('name'=>'当天放电最大功率(W)','field'=>'L.daydischarmaxpow','fields1'=>'daydischarmaxpow','enname'=>'Discharging max-power(W)'),
  394. // array('name'=>'当天灯亮时间(hh:mm)','field'=>'L.daychargemincurrent','fields1'=>'daychargemincurrent','enname'=>'Turn-on duration'),
  395. // array('name'=>'当天充电最大电流(A)','field'=>'L.daycharmaxcurrent','fields1'=>'daycharmaxcurrent','enname'=>'Highest charging current(A)'),
  396. // array('name'=>'当天充电时间(hh:mm)','field'=>'L.daydischargemincurrent','fields1'=>'daydischargemincurrent','enname'=>'Charging duration'),
  397. // array('name'=>'当天放电最大电流(A)','field'=>'L.daydischarmaxcurrent','fields1'=>'daydischarmaxcurrent','enname'=>'Highest discharging current(A)'),
  398. // array('name'=>'当天蓄电池最低温度(℃)','field'=>'L.daybattmintemper','fields1'=>'daybattmintemper','enname'=>'Battery min-temperature(℃)'),
  399. // array('name'=>'当天蓄电池最高温度(℃)','field'=>'L.daybattmaxtemper','fields1'=>'daybattmaxtemper','enname'=>'Battery max-temperature(℃)'),
  400. // );
  401. $electric_info_log = array(
  402. array('name'=>'当天发电量(kWh)','field'=>'RI.chargeday as daygeneration','fields1'=>'daygeneration','enname'=>'Power generation(kWh)'),
  403. array('name'=>'当天用电量(kWh)','field'=>'RI.dischargeday as dayconsumption','fields1'=>'dayconsumption','enname'=>'Power consumption(kWh)'),
  404. array('name'=>'累计发电量(kWh)','field'=>'HI.totalchargeah as totalgeneration','fields1'=>'totalgeneration','enname'=>'Cumulative power generation(kWh)'),
  405. array('name'=>'累计用电量(kWh)','field'=>'HI.totaldischarah as totalconsumption','fields1'=>'totalconsumption','enname'=>'Cumulative power consumption(kWh)'),
  406. );
  407. // $system_info_log = array(
  408. // array('name'=>'系统电压(V)','field'=>'L.sysvoltage','fields1'=>'sysvoltage','enname'=>'System voltage(V)'),
  409. // array('name'=>'系统电流(A)','field'=>'L.syscurrent','fields1'=>'syscurrent','enname'=>'System current(A)'),
  410. // array('name'=>'控制器温度(℃)','field'=>'L.temper as controlTemper','fields1'=>'controlTemper','enname'=>'Controller temperature(℃)'),
  411. // );
  412. // 历史信息日志
  413. // $history_info_log = array(
  414. // array('name'=>'运行天数','field'=>'L.rundays','fields1'=>'rundays','enname'=>'Running duration'),
  415. // array('name'=>'蓄电池总充满次数','field'=>'L.fulltimes','fields1'=>'fulltimes','enname'=>'Full charge times'),
  416. // array('name'=>'蓄电池总充电安时数(ah)','field'=>'L.totalchargeah','fields1'=>'totalchargeah','enname'=>'Total charge AH(ah)'),
  417. // array('name'=>'蓄电池总放电安时数(ah)','field'=>'L.totaldischarah','fields1'=>'totaldischarah','enname'=>'Total discharge AH(ah)'),
  418. // );
  419. // $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$battery_info_log,$electric_info_log,$system_info_log,$history_info_log);
  420. $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$electric_info_log);
  421. // $fields = $def;
  422. $def = explode(',', $fieldstr);
  423. foreach ($fields as &$v) {
  424. if (in_array($v['fields1'], $def)) {
  425. $v['select'] = '1';
  426. }else{
  427. $v['select'] = '0';
  428. }
  429. }
  430. exit(json_result('0000',$this->response['0000'],array('list'=>$fields)));
  431. }
  432. // 路灯下拉列表
  433. public function lamp_list(){
  434. $networkid = intval($this->input->post('networkid',true));
  435. $projectid = intval($this->input->post('projectid',true));
  436. if (empty($networkid) && empty($projectid)) {
  437. exit(json_result('0405',$this->response['0405'],array()));
  438. }
  439. if (!empty($networkid)) {
  440. $data = $this->Lamp_model->get_list(array('networkid'=>$networkid), 'number,id');
  441. }else{
  442. $data = $this->Lamp_model->get_list(array('projectid'=>$projectid), 'number,id');
  443. }
  444. exit(json_result('0000',$this->response['0000'],$data));
  445. }
  446. // 获取单个路灯的经纬度
  447. public function get_lng_lat(){
  448. $lampid = $this->input->post('lampid',true);
  449. $projectid = $this->input->post('projectid',true);
  450. $section = $this->input->post('section',true);
  451. $lampData = array();
  452. if (!empty($lampid)) {
  453. $where = array('id'=>$lampid,'longitude !='=>0,'latitude !='=>0);
  454. if (!empty($section)) {
  455. $where['section'] = $section;
  456. }
  457. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  458. }
  459. if (!empty($projectid)) {
  460. $where = array('projectid'=>$projectid,'longitude !='=>0,'latitude !='=>0);
  461. if (!empty($section)) {
  462. $where['section'] = $section;
  463. }
  464. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  465. }
  466. if (empty($lampData)) {
  467. $lampData = array('longitude'=>0,'latitude'=>0);
  468. }
  469. exit(json_result('0000',$this->response['0000'],$lampData));
  470. }
  471. public function get_province(){
  472. // $countryId = intval($this->input->post('countryId',true));
  473. $role = $this->get_user_info('role');
  474. $where = array();
  475. if ($role != SYSTEM_ADMIN) {
  476. $company = $this->get_user_info('company');
  477. $where['company'] = $company;
  478. }
  479. $pro_list = $this->Project_model->get_list($where,'cityid');
  480. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  481. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  482. $areaList = array();
  483. $cityList = array();
  484. $proList = array();
  485. foreach ($list as $key => $value) {
  486. if ($value['level'] == 2) {
  487. $proList[] = $value;
  488. }elseif ($value['level'] == 3) {
  489. $cityList[] = $value;
  490. }elseif ($value['level'] == 4) {
  491. $areaList[] = $value;
  492. }
  493. }
  494. if (!empty($areaList)) {
  495. $cityArr = array_unique(array_column($areaList, 'pid'));
  496. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  497. foreach ($list as $key => $value) {
  498. if ($value['level'] == 2) {
  499. $proList[] = $value;
  500. }elseif ($value['level'] == 3) {
  501. $cityList[] = $value;
  502. }
  503. }
  504. }
  505. if (!empty($cityList)) {
  506. $cityArr = array_unique(array_column($cityList, 'pid'));
  507. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  508. foreach ($list as $key => $value) {
  509. if ($value['level'] == 2) $proList[] = $value;
  510. }
  511. }
  512. if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  513. $cityArr = array_unique(array_column($proList, 'id'));
  514. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  515. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  516. }
  517. public function get_city(){
  518. $proId = intval($this->input->post('proId',true));
  519. $role = $this->get_user_info('role');
  520. $where = array();
  521. if ($role != SYSTEM_ADMIN) {
  522. $company = $this->get_user_info('company');
  523. $where['company'] = $company;
  524. }
  525. $pro_list = $this->Project_model->get_list($where,'cityid');
  526. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  527. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  528. $areaList = array();
  529. $cityList = array();
  530. foreach ($list as $key => $value) {
  531. if ($value['level'] == 3) {
  532. $cityList[] = $value;
  533. }elseif ($value['level'] == 4) {
  534. $areaList[] = $value;
  535. }
  536. }
  537. if (!empty($areaList)) {
  538. $cityArr = array_unique(array_column($areaList, 'pid'));
  539. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  540. foreach ($list as $key => $value) {
  541. if ($value['level'] == 3) $cityList[] = $value;
  542. }
  543. }
  544. if (empty($cityList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  545. $cityArr = array_unique(array_column($cityList, 'id'));
  546. $where = ['id'=>$cityArr];
  547. if (!empty($proId)) $where['pid'] = $proId;
  548. $list = $this->Global_location_model->get_list($where,'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  549. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  550. }
  551. // 告警状态下拉列表
  552. public function alarm_type_list(){
  553. $version = $this->session->userdata('version');
  554. $batstatus = $this->config->item('batstatus');
  555. $panelstatus = $this->config->item('panelstatus');
  556. $lampstatus = $this->config->item('lampstatus');
  557. $tempstatus = $this->config->item('tempstatus');
  558. $list = array();
  559. foreach ($batstatus as $key => $value) {
  560. $list[] = ['name'=>$value,'value'=>'1'.$key];
  561. }
  562. foreach ($panelstatus as $key => $value) {
  563. $list[] = ['name'=>$value,'value'=>'2'.$key];
  564. }
  565. foreach ($lampstatus as $key => $value) {
  566. $list[] = ['name'=>$value,'value'=>'3'.$key];
  567. }
  568. foreach ($tempstatus as $key => $value) {
  569. $list[] = ['name'=>$value,'value'=>'4'.$key];
  570. }
  571. exit(json_result('0000',$this->response['0000'],$list));
  572. }
  573. }