Home.php 47 KB

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