Home.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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'=>2);
  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. $areaList = array();
  30. $cityList = array(['id'=>$cityId,'level'=>3]);
  31. }
  32. if (!empty($cityList)){
  33. $cityId = array_unique(array_filter(array_column($cityList, 'id')));
  34. $list = $this->Global_location_model->get_list(['pid'=>$cityId],'id,level');
  35. foreach ($list as $key => $value) {
  36. if ($value['level'] == 4) $areaList[] = $value;
  37. }
  38. }
  39. $cityArr = array_unique(array_merge(array_column($proList, 'id'),array_column($cityList, 'id'),array_column($areaList, 'id')));
  40. if (!empty($cityArr)) {
  41. $res = $this->Project_model->get_list(['cityid'=>$cityArr],'id');
  42. $projectIdArr = array_unique(array_column($res, 'id'));
  43. }
  44. return $projectIdArr;
  45. }
  46. // 设备统计信息
  47. public function data(){
  48. $projectIdArr = $this->get_project_id();
  49. $data = array(
  50. 'day_new_count' => 0,
  51. 'day_faulty_count' => 0,
  52. 'total_light_count' => 0,
  53. 'light_up_count' => 0,
  54. 'online_count' => 0,
  55. 'faulty_count' => 0
  56. );
  57. $createTime = $this->get_user_info('createTime');
  58. $data['logCount'] = empty($createTime) ? 0 : ceil((time() - strtotime($createTime))/(3600 * 24));
  59. $date = date('Y-m-d H:i:s',strtotime(date('Y-m-d 00:00:00',time())) - 6*3600);
  60. $role = $this->get_user_info('role');
  61. if ($role == SYSTEM_ADMIN) {
  62. $where = [];
  63. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  64. $data['total_light_count'] = $this->Lamp_model->get_count($where);
  65. $where = ['createtime >='=>$date];
  66. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  67. $data['day_new_count'] = $this->Lamp_model->get_count($where);
  68. $where = ['netstatus'=>1,'status'=>1];
  69. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  70. $data['light_up_count'] = $this->Lamp_model->get_count($where);
  71. $where = ['netstatus'=>1];
  72. if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  73. $data['online_count'] = $this->Lamp_model->get_count($where);
  74. // $where = ['netstatus'=>1,'devstatus !='=>0];
  75. // if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  76. // $data['faulty_count'] = $this->Lamp_model->get_count($where);
  77. // $where = ['netstatus'=>1,'logtime >='=>$date,'devstatus !='=>0];
  78. // if (!empty($projectIdArr)) $where['projectid'] = $projectIdArr;
  79. // $data['day_faulty_count'] = $this->Lamp_model->get_count($where);
  80. $where = ['L.netstatus ='=>1];
  81. if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
  82. $where1 = [];
  83. foreach ($where as $key => $value) {
  84. if (is_array($value)) {
  85. $where1[] = $key.' in ('.implode(',', $value).')';
  86. }else{
  87. $where1[] = $key.' '.$value;
  88. }
  89. }
  90. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  91. $where1 = implode(' AND ', $where1);
  92. $join = [];
  93. $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'];
  94. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  95. $data['faulty_count'] = $total['total'];
  96. $where1 .= ' AND WI.updatetime >= "'.$date.'"';
  97. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  98. $data['day_faulty_count'] = $total['total'];
  99. }else{
  100. $company = $this->get_user_info('company');
  101. $where = ['P.company ='=>$company];
  102. if (!empty($projectIdArr)) $where['P.id'] = $projectIdArr;
  103. $join = [
  104. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  105. ];
  106. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  107. $data['total_light_count'] = $total['total'];
  108. $where['L.createtime >='] = $date;
  109. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  110. $data['day_new_count'] = $total['total'];
  111. unset($where['L.createtime >=']);
  112. $where['L.netstatus ='] = 1;
  113. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  114. $data['online_count'] = $total['total'];
  115. $where['L.status ='] = 1;
  116. $total = $this->Lamp_model->get_list_by_multi_join($where, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  117. $data['light_up_count'] = $total['total'];
  118. unset($where['L.status']);
  119. // $where['L.devstatus !='] = 0;
  120. $where1 = [];
  121. foreach ($where as $key => $value) {
  122. if (is_array($value)) {
  123. $where1[] = $key.' in ('.implode(',', $value).')';
  124. }else {
  125. $where1[] = $key.' '.$value;
  126. }
  127. }
  128. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  129. $where1 = implode(' AND ', $where1);
  130. $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'];
  131. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  132. $data['faulty_count'] = $total['total'];
  133. // $where['L.devstatus !='] = 0;
  134. $where1 .= ' AND WI.updatetime >= "'.$date.'"';
  135. $total = $this->Lamp_model->get_list_by_multi_join($where1, 'count(*) as total',NULL, NULL, $join, NULL, NUll, 'L', true);
  136. $data['day_faulty_count'] = $total['total'];
  137. }
  138. exit(json_result('0000',$this->response['0000'],$data));
  139. }
  140. // 发用电量统计信息
  141. public function sta_info(){
  142. $data = array(
  143. 'electricity' => 0,
  144. 'CO2_reduction' => 0,
  145. 'SO2_reduction' => 0,
  146. 'TCE_reduction' => 0
  147. );
  148. $type = intval($this->input->post('type',true));
  149. $projectIdArr = $this->get_project_id();
  150. $role = $this->get_user_info('role');
  151. $type = $this->input->post('type',true);
  152. $where = array();
  153. if ($role != SYSTEM_ADMIN){
  154. $company = $this->get_user_info('company');
  155. $where['P.company'] = $company;
  156. }
  157. if (!empty($projectIdArr)) $where['L.projectid'] = $projectIdArr;
  158. if ($type == 0) {
  159. $join = [];
  160. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  161. $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'];
  162. $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);
  163. }elseif ($type == 1) {
  164. $join = [];
  165. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  166. $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'];
  167. $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);
  168. }elseif ($type == 2) {
  169. $join = [];
  170. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  171. $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'];
  172. $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);
  173. }else{
  174. $join = [];
  175. $join[] = ['table'=>'project as P','cond'=>'L.projectid = P.id','type'=>'left'];
  176. $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'];
  177. $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);
  178. }
  179. $data['electricity'] = $res['discharge'];
  180. $data['CO2_reduction'] = $res['discharge'];
  181. $data['SO2_reduction'] = $res['discharge'];
  182. $data['TCE_reduction'] = $res['discharge'];
  183. $data['CO2_reduction'] = round($res['charge']*0.977, 3);
  184. $data['SO2_reduction'] = round($res['charge']*0.977/2620*8.5*1000, 3);
  185. $data['TCE_reduction'] = round($res['charge']*0.977/2620*1000, 3);
  186. exit(json_result('0000',$this->response['0000'],$data));
  187. }
  188. // 设备统计列表
  189. public function dev_list(){
  190. $projectIdArr = $this->get_project_id();
  191. $role = $this->get_user_info('role');
  192. $type = $this->input->post('type',true);
  193. $where = array();
  194. if ($role != SYSTEM_ADMIN){
  195. $company = $this->get_user_info('company');
  196. $where[] = 'P.company = '.$company;
  197. }
  198. if ($type == 2) {
  199. $fields = 'L.manu as company,G.id';
  200. $group = 'group by L.manu';
  201. $where[] = 'L.manu != 0';
  202. $where[] = 'L.manu != ""';
  203. }elseif ($type == 3) {
  204. $fields = 'L.supplier as company,G.id';
  205. $group = 'group by L.supplier';
  206. $where[] = 'L.supplier != 0';
  207. $where[] = 'L.supplier != ""';
  208. }elseif ($type == 4) {
  209. $fields = 'L.po as company,G.id';
  210. $group = 'group by L.po';
  211. $where[] = 'L.po != 0';
  212. $where[] = 'L.po != ""';
  213. }else{
  214. $fields = 'G.english_name as company,G.id';
  215. $group = 'group by G.id';
  216. // $where[] = 'L.upazilla != 0';
  217. // $where[] = 'L.upazilla != ""';
  218. }
  219. // $cityId = $this->input->post('cityId',true);
  220. // $proId = $this->input->post('proId',true);
  221. if (!empty($projectIdArr)) $where[] = 'L.projectid in ('.implode(',', $projectIdArr).')';
  222. $where1 = empty($where) ? '' : 'where '.implode(' AND ', $where);
  223. $query = 'select t1.total,C.name,C.no,C.id,t1.id as cityid,t1.company from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  224. // var_dump($query);
  225. $list = $this->db->query($query)->result_array();
  226. // var_dump($list);die;
  227. if (empty($list)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  228. $temp = array();
  229. $allDev = array_sum(array_column($list, 'total'));
  230. foreach ($list as $key => $value) {
  231. $totalPer = empty($allDev) ? '0%' : round($value['total']/$allDev*100,2).'%';
  232. $value['name'] = empty($value['no']) ? $value['name'] : $value['no'];
  233. $temp2 = array('name'=>$value['name'],'total'=>$value['total'],'onlineCount'=>0,'offlineCount'=>0,'faultCount'=>0,'totalPer'=>$totalPer);
  234. if ($type == 5) {
  235. $temp2['name'] = $value['company'];
  236. $temp[$value['cityid']] = $temp2;
  237. }else{
  238. $temp[$value['id']] = $temp2;
  239. }
  240. }
  241. $companyArr = array_unique(array_column($list, 'id'));
  242. $cityArr = array_unique(array_column($list, 'cityid'));
  243. if ($type == 2) {
  244. $where[] = 'L.manu in ('.implode(',', $companyArr).')';
  245. }elseif ($type == 3) {
  246. $where[] = 'L.supplier in ('.implode(',', $companyArr).')';
  247. }elseif ($type == 4) {
  248. $where[] = 'L.po in ('.implode(',', $companyArr).')';
  249. }else{
  250. $where[] = 'P.cityid in ('.implode(',', $cityArr).')';
  251. }
  252. $where1 = $where;
  253. $where1[] = 'L.netstatus = 0';
  254. $where1 = 'where '.implode(' AND ', $where1);
  255. if ($type == 5) {
  256. $query = 'select t1.total,t1.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 order by total DESC limit 10';
  257. }else{
  258. $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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  259. }
  260. $list = $this->db->query($query)->result_array();
  261. foreach ($list as $key => $value) {
  262. if (isset($temp[$value['id']])) $temp[$value['id']]['offlineCount'] = $value['total'];
  263. }
  264. $where1 = $where;
  265. $where1[] = 'L.netstatus = 1';
  266. $where1 = 'where '.implode(' AND ', $where1);
  267. if ($type == 5) {
  268. $query = 'select t1.total,t1.id from (select count(*) as total,'.$fields.' from lampinfo AS L left join project AS P on P.id = L.projectid left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 order by total DESC limit 10';
  269. }else{
  270. $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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  271. }
  272. $list = $this->db->query($query)->result_array();
  273. foreach ($list as $key => $value) {
  274. if (isset($temp[$value['id']])) $temp[$value['id']]['onlineCount'] = $value['total'];
  275. }
  276. $where1 = $where;
  277. $where1[] = 'L.netstatus = 1';
  278. $where1[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  279. $where1 = 'where '.implode(' AND ', $where1);
  280. if ($type == 5) {
  281. $query = 'select t1.total,t1.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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 order by total DESC limit 10';
  282. }else{
  283. $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 left join global_location G on P.cityid = G.id '.$where1.' '.$group.') as t1 left join company as C on t1.company = C.id order by total DESC limit 10';
  284. }
  285. $list = $this->db->query($query)->result_array();
  286. foreach ($list as $key => $value) {
  287. if (isset($temp[$value['id']])) $temp[$value['id']]['faultCount'] = $value['total'];
  288. }
  289. $list = array_values($temp);
  290. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  291. }
  292. // 故障信息列表
  293. public function alarm_list(){
  294. $projectIdArr = $this->get_project_id();
  295. $role = $this->get_user_info('role');
  296. $where = array();
  297. if ($role != SYSTEM_ADMIN){
  298. $company = $this->get_user_info('company');
  299. $where[] = 'P.company = '.$company;
  300. }
  301. if (!empty($projectIdArr)) $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
  302. $where[] = '(WI.batstatus != 0 OR WI.panelstatus != 0 OR WI.lampstatus != 0 OR WI.tempstatus != 0)';
  303. $where[] = 'L.netstatus = 1';
  304. $where1 = implode(' AND ', $where);
  305. $join = [
  306. ['table'=>'project as P','cond'=>'P.id = L.projectid','type'=>'inner']
  307. ];
  308. $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'];
  309. $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'inner'];
  310. $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'inner'];
  311. $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid','type'=>'inner'];
  312. $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');
  313. $batstatus = $this->config->item('batstatus');
  314. $panelstatus = $this->config->item('panelstatus');
  315. $lampstatus = $this->config->item('lampstatus');
  316. $tempstatus = $this->config->item('tempstatus');
  317. foreach ($list as $key => $value) {
  318. $location = $value['proName'].'/'.$value['cityName'].'/'.$value['areaName'];
  319. $location = empty($value['section']) ? $location : $location.'/'.$value['section'];
  320. $list[$key]['location'] = $location;
  321. $list[$key]['fault_time'] = set_timezone($value['updatetime'],$value['timezone']);
  322. $temp2 = array();
  323. if (isset($batstatus[$value['batstatus']])) $temp2[] = $batstatus[$value['batstatus']];
  324. if (isset($panelstatus[$value['panelstatus']])) $temp2[] = $panelstatus[$value['panelstatus']];
  325. if (isset($lampstatus[$value['lampstatus']])) $temp2[] = $lampstatus[$value['lampstatus']];
  326. if (isset($tempstatus[$value['tempstatus']])) $temp2[] = $tempstatus[$value['tempstatus']];
  327. $list[$key]['fault_type'] = implode(',', $temp2);
  328. unset($list[$key]['cityName']);
  329. unset($list[$key]['proName']);
  330. unset($list[$key]['areaName']);
  331. unset($list[$key]['section']);
  332. unset($list[$key]['timezone']);
  333. unset($list[$key]['updatetime']);
  334. }
  335. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  336. }
  337. // 字段管理
  338. public function fields(){
  339. $userid = $this->get_user_info('id');
  340. $data = $this->User_model->get_user_field($userid);
  341. if (empty($data) || empty($data['lampfield'])) {
  342. // $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  343. $fieldstr = "number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status,section";
  344. }else{
  345. if ($data['lampfield'] == 'number,lampstatus,updatetime,lighteness,address,lamppower,chargestage,battvoltage,overtimes,solarpower,isfaulted,status') {
  346. $data['lampfield'] .= ',section';
  347. }
  348. $fieldstr = $data['lampfield'];
  349. }
  350. // 系统默认
  351. $def = array(
  352. array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  353. array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  354. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  355. array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,L.rssi','fields1'=>'status','enname'=>'Network status'),
  356. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  357. array('name'=>'更新时间','field'=>'RI.updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  358. array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  359. array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  360. array('name'=>'负载功率(W)','field'=>'RI.loadpower','fields1'=>'loadpower','enname'=>'LED power(W)'),
  361. array('name'=>'蓄电池电压(V)','field'=>'RI.batvoltage as battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  362. array('name'=>'蓄电池总过放次数','field'=>'HI.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  363. array('name'=>'太阳能板功率(W)','field'=>'RI.panelpower as solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  364. array('name'=>'是否故障','field'=>'AI.batstatus,AI.panelstatus,AI.lampstatus,AI.tempstatus,AI.status as alarmStatus','fields1'=>'isfaulted','enname'=>'Fault'),
  365. );
  366. // $def = array(
  367. // array('name'=>'路灯编号','field'=>'L.number','fields1'=>'number','enname'=>'Lamp number'),
  368. // array('name'=>'路段','field'=>'L.section','fields1'=>'section','enname'=>'Road'),
  369. // array('name'=>'路灯状态','field'=>'L.status as lampstatus,L.lighteness','fields1'=>'lampstatus','enname'=>'Lamp status'),
  370. // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status','fields1'=>'status','enname'=>'Network status'),
  371. // // array('name'=>'信号状态','field'=>'L.protocoltype,L.netstatus as status,N.rssi,N.snr','fields1'=>'status','enname'=>'Network status'),
  372. // array('name'=>'更新时间','field'=>'L.logtime as updatetime','fields1'=>'updatetime','enname'=>'Update time'),
  373. // array('name'=>'路灯亮度(%)','field'=>'L.lighteness','fields1'=>'lighteness','enname'=>'Brightness(%)'),
  374. // array('name'=>'无线模块地址','field'=>'L.address','fields1'=>'address','enname'=>'Wireless module address'),
  375. // array('name'=>'路灯功率(W)','field'=>'L.lamppower','fields1'=>'lamppower','enname'=>'Lamp power(W)'),
  376. // array('name'=>'蓄电池充电阶段','field'=>'L.chargestage','fields1'=>'chargestage','enname'=>'Charging stage'),
  377. // array('name'=>'蓄电池电压(V)','field'=>'L.battvoltage','fields1'=>'battvoltage','enname'=>'Battery voltage(V)'),
  378. // array('name'=>'蓄电池总过放次数','field'=>'L.overtimes','fields1'=>'overtimes','enname'=>'Over discharge times'),
  379. // array('name'=>'太阳能板功率(W)','field'=>'L.solarpower','fields1'=>'solarpower','enname'=>'Solar panel power(W)'),
  380. // array('name'=>'是否故障','field'=>'L.isfaulted','fields1'=>'isfaulted','enname'=>'Fault'),
  381. // );
  382. // 路灯信息
  383. $lampinfo = array(
  384. array('name'=>'当前策略','field'=>'L.policyid','fields1'=>'policyid','enname'=>'Current strategy'),
  385. array('name'=>'路灯id','field'=>'L.id','fields1'=>'id','enname'=>'Lamp ID'),
  386. // array('name'=>'网络名称','field'=>'N.networkname','fields1'=>'networkname','enname'=>'Network name'),
  387. array('name'=>'项目名称','field'=>'P.projectname','fields1'=>'projectname','enname'=>'Project name'),
  388. array('name'=>'经度','field'=>'L.longitude','fields1'=>'longitude','enname'=>'Longitude'),
  389. array('name'=>'纬度','field'=>'L.latitude','fields1'=>'latitude','enname'=>'Latitude'),
  390. // array('name'=>'sim卡号','field'=>'N.simid','fields1'=>'simid','enname'=>'SIM card number'),
  391. // array('name'=>'套餐剩余','field'=>'N.packageSurplus','fields1'=>'packageSurplus','enname'=>'Package surplus'),
  392. array('name'=>'路灯类型','field'=>'L.lamptype','fields1'=>'lamptype','enname'=>'Lamp type'),
  393. array('name'=>'太阳能板类型','field'=>'L.boardtype','fields1'=>'boardtype','enname'=>'Solar panel type'),
  394. // array('name'=>'太阳能板功率(W)','field'=>'L.boardpower','fields1'=>'boardpower','enname'=>'Solar panel power(W)'),
  395. // array('name'=>'蓄电池类型','field'=>'L.batterytype','fields1'=>'batterytype','enname'=>'Battery type'),
  396. array('name'=>'蓄电池AH数(ah)','field'=>'HI.totalchargeah as batteryah','fields1'=>'batteryah','enname'=>'Battery capacity(ah)'),
  397. // array('name'=>'负载功率(W)','field'=>'L.loadpower','fields1'=>'loadpower','enname'=>'Load power(W)'),
  398. // array('name'=>'蓄电池剩余电量','field'=>'L.electricleft','fields1'=>'electricleft','enname'=>'Remaining battery capacity(Ah)'),
  399. );
  400. // 路灯信息日志
  401. $lamp_info_log = array(
  402. array('name'=>'路灯电压(V)','field'=>'RI.loadvoltage as lampvoltage','fields1'=>'lampvoltage','enname'=>'Lamp voltage(V)'),
  403. array('name'=>'路灯电流(A)','field'=>'RI.loadcurrent as lampcurrent','fields1'=>'lampcurrent','enname'=>'Lamp current(A)'),
  404. // array('name'=>'灯头温度(℃)','field'=>'L.lamptemper as temper','fields1'=>'temper','enname'=>'Lamp temperature(℃)'),
  405. );
  406. $solar_info_log = array(
  407. array('name'=>'太阳能板电压(V)','field'=>'RI.panelvoltage as solarvoltage','fields1'=>'solarvoltage','enname'=>'Solar panel voltage(V)'),
  408. array('name'=>'太阳能板电流(A)','field'=>'RI.panelcurrent as solarcurrent','fields1'=>'solarcurrent','enname'=>'Solar panel current(A)')
  409. );
  410. // 蓄电池信息日志
  411. // $battery_info_log = array(
  412. // array('name'=>'蓄电池状态','field'=>'L.battstatus','fields1'=>'battstatus','enname'=>'Battery status'),
  413. // array('name'=>'蓄电池充电电流(A)','field'=>'L.chargecurrent','fields1'=>'chargecurrent','enname'=>'Charging current(A)'),
  414. // array('name'=>'蓄电池放电电流(A)','field'=>'L.discharcurrent','fields1'=>'discharcurrent','enname'=>'Discharging current(A)'),
  415. // array('name'=>'蓄电池充电功率(w)','field'=>'L.chargepower','fields1'=>'chargepower','enname'=>'Charging power(w)'),
  416. // array('name'=>'蓄电池放电功率(w)','field'=>'L.dischargepower','fields1'=>'dischargepower','enname'=>'Discharging power(w)'),
  417. // array('name'=>'蓄电池表面温度(℃)','field'=>'L.batttemper','fields1'=>'batttemper','enname'=>'Battery surface temperature(℃)'),
  418. // array('name'=>'蓄电池总电量','field'=>'L.electrictotal','fields1'=>'electrictotal','enname'=>'Total battery capacity(Ah)'),
  419. // array('name'=>'蓄电池电量SOC(%)','field'=>'L.electricSOC','fields1'=>'electricSOC','enname'=>'Battery SOC(%)'),
  420. // array('name'=>'当天最低电压(V)','field'=>'L.voltagedaymin','fields1'=>'voltagedaymin','enname'=>'Minimum voltage(V)'),
  421. // array('name'=>'当天最高电压(V)','field'=>'L.voltagedaymax','fields1'=>'voltagedaymax','enname'=>'Highest voltage(V)'),
  422. // array('name'=>'当天充电安时数(ah)','field'=>'L.daychargeah','fields1'=>'daychargeah','enname'=>'Charging AH(ah)'),
  423. // array('name'=>'当天放电安时数(ah)','field'=>'L.daydischarah','fields1'=>'daydischarah','enname'=>'Discharging AH(ah)'),
  424. // array('name'=>'当天充电最大功率(W)','field'=>'L.daychargemaxpow','fields1'=>'daychargemaxpow','enname'=>'Charging max-power(W)'),
  425. // array('name'=>'当天放电最大功率(W)','field'=>'L.daydischarmaxpow','fields1'=>'daydischarmaxpow','enname'=>'Discharging max-power(W)'),
  426. // array('name'=>'当天灯亮时间(hh:mm)','field'=>'L.daychargemincurrent','fields1'=>'daychargemincurrent','enname'=>'Turn-on duration'),
  427. // array('name'=>'当天充电最大电流(A)','field'=>'L.daycharmaxcurrent','fields1'=>'daycharmaxcurrent','enname'=>'Highest charging current(A)'),
  428. // array('name'=>'当天充电时间(hh:mm)','field'=>'L.daydischargemincurrent','fields1'=>'daydischargemincurrent','enname'=>'Charging duration'),
  429. // array('name'=>'当天放电最大电流(A)','field'=>'L.daydischarmaxcurrent','fields1'=>'daydischarmaxcurrent','enname'=>'Highest discharging current(A)'),
  430. // array('name'=>'当天蓄电池最低温度(℃)','field'=>'L.daybattmintemper','fields1'=>'daybattmintemper','enname'=>'Battery min-temperature(℃)'),
  431. // array('name'=>'当天蓄电池最高温度(℃)','field'=>'L.daybattmaxtemper','fields1'=>'daybattmaxtemper','enname'=>'Battery max-temperature(℃)'),
  432. // );
  433. $electric_info_log = array(
  434. array('name'=>'当天发电量(kWh)','field'=>'RI.chargeday as daygeneration','fields1'=>'daygeneration','enname'=>'Power generation(kWh)'),
  435. array('name'=>'当天用电量(kWh)','field'=>'RI.dischargeday as dayconsumption','fields1'=>'dayconsumption','enname'=>'Power consumption(kWh)'),
  436. array('name'=>'累计发电量(kWh)','field'=>'HI.totalchargeah as totalgeneration','fields1'=>'totalgeneration','enname'=>'Cumulative power generation(kWh)'),
  437. array('name'=>'累计用电量(kWh)','field'=>'HI.totaldischarah as totalconsumption','fields1'=>'totalconsumption','enname'=>'Cumulative power consumption(kWh)'),
  438. );
  439. // $system_info_log = array(
  440. // array('name'=>'系统电压(V)','field'=>'L.sysvoltage','fields1'=>'sysvoltage','enname'=>'System voltage(V)'),
  441. // array('name'=>'系统电流(A)','field'=>'L.syscurrent','fields1'=>'syscurrent','enname'=>'System current(A)'),
  442. // array('name'=>'控制器温度(℃)','field'=>'L.temper as controlTemper','fields1'=>'controlTemper','enname'=>'Controller temperature(℃)'),
  443. // );
  444. // 历史信息日志
  445. // $history_info_log = array(
  446. // array('name'=>'运行天数','field'=>'L.rundays','fields1'=>'rundays','enname'=>'Running duration'),
  447. // array('name'=>'蓄电池总充满次数','field'=>'L.fulltimes','fields1'=>'fulltimes','enname'=>'Full charge times'),
  448. // array('name'=>'蓄电池总充电安时数(ah)','field'=>'L.totalchargeah','fields1'=>'totalchargeah','enname'=>'Total charge AH(ah)'),
  449. // array('name'=>'蓄电池总放电安时数(ah)','field'=>'L.totaldischarah','fields1'=>'totaldischarah','enname'=>'Total discharge AH(ah)'),
  450. // );
  451. // $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$battery_info_log,$electric_info_log,$system_info_log,$history_info_log);
  452. $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$electric_info_log);
  453. // $fields = $def;
  454. $def = explode(',', $fieldstr);
  455. foreach ($fields as &$v) {
  456. if (in_array($v['fields1'], $def)) {
  457. $v['select'] = '1';
  458. }else{
  459. $v['select'] = '0';
  460. }
  461. }
  462. exit(json_result('0000',$this->response['0000'],array('list'=>$fields)));
  463. }
  464. // 路灯下拉列表
  465. public function lamp_list(){
  466. $networkid = intval($this->input->post('networkid',true));
  467. $projectid = intval($this->input->post('projectid',true));
  468. if (empty($networkid) && empty($projectid)) {
  469. exit(json_result('0405',$this->response['0405'],array()));
  470. }
  471. if (!empty($networkid)) {
  472. $data = $this->Lamp_model->get_list(array('networkid'=>$networkid), 'number,id');
  473. }else{
  474. $data = $this->Lamp_model->get_list(array('projectid'=>$projectid), 'number,id');
  475. }
  476. exit(json_result('0000',$this->response['0000'],$data));
  477. }
  478. // 获取单个路灯的经纬度
  479. public function get_lng_lat(){
  480. $lampid = $this->input->post('lampid',true);
  481. $projectid = $this->input->post('projectid',true);
  482. $section = $this->input->post('section',true);
  483. $lampData = array();
  484. if (!empty($lampid)) {
  485. $where = array('id'=>$lampid,'longitude !='=>0,'latitude !='=>0);
  486. if (!empty($section)) {
  487. $where['section'] = $section;
  488. }
  489. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  490. }
  491. if (!empty($projectid)) {
  492. $where = array('projectid'=>$projectid,'longitude !='=>0,'latitude !='=>0);
  493. if (!empty($section)) {
  494. $where['section'] = $section;
  495. }
  496. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  497. }
  498. if (empty($lampData)) {
  499. $lampData = array('longitude'=>0,'latitude'=>0);
  500. }
  501. exit(json_result('0000',$this->response['0000'],$lampData));
  502. }
  503. public function get_province(){
  504. // $countryId = intval($this->input->post('countryId',true));
  505. $role = $this->get_user_info('role');
  506. $where = array();
  507. if ($role != SYSTEM_ADMIN) {
  508. $company = $this->get_user_info('company');
  509. $where['company'] = $company;
  510. }
  511. $pro_list = $this->Project_model->get_list($where,'cityid');
  512. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  513. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  514. $areaList = array();
  515. $cityList = array();
  516. $proList = array();
  517. foreach ($list as $key => $value) {
  518. if ($value['level'] == 2) {
  519. $proList[] = $value;
  520. }elseif ($value['level'] == 3) {
  521. $cityList[] = $value;
  522. }elseif ($value['level'] == 4) {
  523. $areaList[] = $value;
  524. }
  525. }
  526. if (!empty($areaList)) {
  527. $cityArr = array_unique(array_column($areaList, 'pid'));
  528. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  529. foreach ($list as $key => $value) {
  530. if ($value['level'] == 2) {
  531. $proList[] = $value;
  532. }elseif ($value['level'] == 3) {
  533. $cityList[] = $value;
  534. }
  535. }
  536. }
  537. if (!empty($cityList)) {
  538. $cityArr = array_unique(array_column($cityList, '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'] == 2) $proList[] = $value;
  542. }
  543. }
  544. if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  545. $cityArr = array_unique(array_column($proList, 'id'));
  546. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  547. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  548. }
  549. public function get_city(){
  550. $proId = intval($this->input->post('proId',true));
  551. $role = $this->get_user_info('role');
  552. $where = array();
  553. if ($role != SYSTEM_ADMIN) {
  554. $company = $this->get_user_info('company');
  555. $where['company'] = $company;
  556. }
  557. $pro_list = $this->Project_model->get_list($where,'cityid');
  558. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  559. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  560. $areaList = array();
  561. $cityList = array();
  562. foreach ($list as $key => $value) {
  563. if ($value['level'] == 3) {
  564. $cityList[] = $value;
  565. }elseif ($value['level'] == 4) {
  566. $areaList[] = $value;
  567. }
  568. }
  569. if (!empty($areaList)) {
  570. $cityArr = array_unique(array_column($areaList, 'pid'));
  571. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  572. foreach ($list as $key => $value) {
  573. if ($value['level'] == 3) $cityList[] = $value;
  574. }
  575. }
  576. if (empty($cityList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  577. $cityArr = array_unique(array_column($cityList, 'id'));
  578. $where = ['id'=>$cityArr];
  579. if (!empty($proId)) $where['pid'] = $proId;
  580. $list = $this->Global_location_model->get_list($where,'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  581. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  582. }
  583. // 告警状态下拉列表
  584. public function alarm_type_list(){
  585. $version = $this->session->userdata('version');
  586. $batstatus = $this->config->item('batstatus');
  587. $panelstatus = $this->config->item('panelstatus');
  588. $lampstatus = $this->config->item('lampstatus');
  589. $tempstatus = $this->config->item('tempstatus');
  590. $list = array();
  591. foreach ($batstatus as $key => $value) {
  592. $list[] = ['name'=>$value,'value'=>'1'.$key];
  593. }
  594. foreach ($panelstatus as $key => $value) {
  595. $list[] = ['name'=>$value,'value'=>'2'.$key];
  596. }
  597. foreach ($lampstatus as $key => $value) {
  598. $list[] = ['name'=>$value,'value'=>'3'.$key];
  599. }
  600. foreach ($tempstatus as $key => $value) {
  601. $list[] = ['name'=>$value,'value'=>'4'.$key];
  602. }
  603. if ($this->os == 2) {
  604. exit(json_result('0000',$this->response['0000'],['list'=>$list]));
  605. }else{
  606. exit(json_result('0000',$this->response['0000'],$list));
  607. }
  608. }
  609. // 省级设备数量
  610. public function pro_dev_count(){
  611. $role = $this->get_user_info('role');
  612. $company = $this->get_user_info('company');
  613. $where = array();
  614. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  615. $where['G3.level'] = 2;
  616. $where['G3.pid'] = 92;
  617. $join = array();
  618. $join[] = ['table'=>'global_location as G2','cond'=>'G3.id = G2.pid AND G2.level = 3','type'=>'left'];
  619. $join[] = ['table'=>'global_location as G1','cond'=>'G2.id = G1.pid AND G1.level = 4','type'=>'left'];
  620. $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
  621. // $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid AND G3.level = 2','type'=>'left'];
  622. $list = $this->Global_location_model->get_list_by_join($where, 'G3.id,G3.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G3.id', 'G3');
  623. foreach ($list as $key => $value) {
  624. $list[$key]['lampcount'] = intval($value['lampcount']);
  625. }
  626. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  627. }
  628. // 市级设备数量
  629. public function city_dev_count(){
  630. $role = $this->get_user_info('role');
  631. $company = $this->get_user_info('company');
  632. $where = array();
  633. $proId = intval($this->input->post('proId',true));
  634. if (!empty($proId)) $where['G2.pid'] = $proId;
  635. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  636. $where['G2.level'] = 3;
  637. $join = array();
  638. $join[] = ['table'=>'global_location as G1','cond'=>'G2.id = G1.pid','type'=>'left'];
  639. $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
  640. // $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'left'];
  641. $list = $this->Global_location_model->get_list_by_join($where, 'G2.id,G2.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G2.id', 'G2');
  642. foreach ($list as $key => $value) {
  643. $list[$key]['lampcount'] = intval($value['lampcount']);
  644. }
  645. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  646. }
  647. // 区域设备数量
  648. public function area_dev_count(){
  649. $role = $this->get_user_info('role');
  650. $company = $this->get_user_info('company');
  651. $where = array();
  652. $cityId = intval($this->input->post('cityId',true));
  653. if (!empty($cityId)) $where['G1.pid'] = $cityId;
  654. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  655. $where['G1.level'] = 4;
  656. $join = array();
  657. $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
  658. // $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'left'];
  659. $list = $this->Global_location_model->get_list_by_join($where, 'G1.id,G1.english_name as name,sum(P.lampcount) as lampcount',NULL, NULL, $join, NULL, 'G1.id', 'G1');
  660. foreach ($list as $key => $value) {
  661. $list[$key]['lampcount'] = intval($value['lampcount']);
  662. }
  663. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  664. }
  665. // app额外接口
  666. public function app_home_data(){
  667. $data = array(
  668. 'project_count' => 0,
  669. 'upa_count' => 0,
  670. 'sup_count' => 0,
  671. 'manu_count' => 0,
  672. 'insert_power' => 0,
  673. 'gen_power' => 0,
  674. 'user_power' => 0,
  675. 'light_time' => 0,
  676. );
  677. $projectIdArr = $this->get_project_id();
  678. if (empty($projectIdArr)) exit(json_result('0000',$this->response['0000'],$data));
  679. $role = $this->get_user_info('role');
  680. $where = array();
  681. $data['project_count'] = count($projectIdArr);
  682. $where[] = 'P.id in ('.implode(',', $projectIdArr).')';
  683. if ($role != SYSTEM_ADMIN){
  684. $company = $this->get_user_info('company');
  685. $where[] = 'P.company = '.$company;
  686. }
  687. $sql = 'select count(*) as total from (select L.manu from lampinfo L left join project P on L.projectid = P.id where '.implode(' AND ', $where).' AND L.manu != 0 AND L.manu != "" group by L.manu) t';
  688. $total = $this->db->query($sql)->row_array();
  689. $data['manu_count'] = $total['total'];
  690. $sql = 'select count(*) as total from (select L.supplier from lampinfo L left join project P on L.projectid = P.id where '.implode(' AND ', $where).' AND L.supplier != 0 AND L.supplier != "" group by L.supplier) t';
  691. $total = $this->db->query($sql)->row_array();
  692. $data['sup_count'] = $total['total'];
  693. $sql = 'select count(*) as total from (select G.id from lampinfo L left join project P on L.projectid = P.id left join global_location G on P.cityid = G.id where '.implode(' AND ', $where).' group by G.id) t';
  694. $total = $this->db->query($sql)->row_array();
  695. $data['upa_count'] = $total['total'];
  696. $sql = 'select sum(L.totalLightTime) as light_time,sum(L.boardpower) as boardpower,sum(L.totalgeneration) as totalgeneration,sum(L.totalconsumption) as totalconsumption from lampinfo L left join project P on L.projectid = P.id where '.implode(' AND ', $where);
  697. $total = $this->db->query($sql)->row_array();
  698. $data['light_time'] = ceil($total['light_time']/60);
  699. $data['insert_power'] = round($total['boardpower']/1000,3);
  700. $data['gen_power'] = round($total['totalgeneration']/1000,3);
  701. $data['user_power'] = round($total['totalconsumption']/1000,3);
  702. exit(json_result('0000',$this->response['0000'],$data));
  703. }
  704. public function weather_info(){
  705. $areaId = intval($this->input->post('areaId',true));
  706. if (empty($areaId)) exit(json_result('0007',$this->response['0007']));
  707. $res1 = $this->Global_location_model->get_one(['id'=>$areaId],'level,pid,chinese_name,longitude,latitude,english_name');
  708. $url = 'https://free-api.heweather.net/s6/weather/forecast?location='.$res1['longitude'].','.$res1['latitude'].'&key=63dbc994630941fab269ad3c3af4d5d2';
  709. // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
  710. $resData = request_post($url);
  711. $arr = json_decode($resData,true);
  712. if ($arr['HeWeather6'][0]['status'] == 'ok') {
  713. $now = $arr['HeWeather6'][0]['daily_forecast'][0];
  714. $daily_forecast = $arr['HeWeather6'][0]['daily_forecast'];
  715. $data = ['weatherType'=>$now['cond_txt_d'],'code'=>$now['cond_code_d'],'tmp'=>intval(($now['tmp_min'] + $now['tmp_max'])/2)];
  716. }else{
  717. $data = ['weatherType'=>'','code'=>'','tmp'=>''];
  718. }
  719. exit(json_result('0000',$this->response['0000'],$data));
  720. }
  721. }