Home.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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'] = round($res['discharge']/1000,1);
  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/1000, 1);
  184. $data['SO2_reduction'] = round($res['charge']*0.977/2620*8.5, 1);
  185. $data['TCE_reduction'] = round($res['charge']*0.977/2620, 1);
  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. array('name'=>'版本号','field'=>'L.softwareVersion','fields1'=>'softwareVersion','enname'=>'Version information'),
  451. );
  452. $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$battery_info_log,$electric_info_log,$system_info_log,$history_info_log);
  453. // $fields = array_merge($def,$lampinfo,$lamp_info_log,$solar_info_log,$electric_info_log);
  454. // $fields = $def;
  455. $def = explode(',', $fieldstr);
  456. foreach ($fields as &$v) {
  457. if (in_array($v['fields1'], $def)) {
  458. $v['select'] = '1';
  459. }else{
  460. $v['select'] = '0';
  461. }
  462. }
  463. exit(json_result('0000',$this->response['0000'],array('list'=>$fields)));
  464. }
  465. // 路灯下拉列表
  466. public function lamp_list(){
  467. $networkid = intval($this->input->post('networkid',true));
  468. $projectid = intval($this->input->post('projectid',true));
  469. if (empty($networkid) && empty($projectid)) {
  470. exit(json_result('0405',$this->response['0405'],array()));
  471. }
  472. if (!empty($networkid)) {
  473. $data = $this->Lamp_model->get_list(array('networkid'=>$networkid), 'number,id');
  474. }else{
  475. $data = $this->Lamp_model->get_list(array('projectid'=>$projectid), 'number,id');
  476. }
  477. exit(json_result('0000',$this->response['0000'],$data));
  478. }
  479. // 获取单个路灯的经纬度
  480. public function get_lng_lat(){
  481. $lampid = $this->input->post('lampid',true);
  482. $projectid = $this->input->post('projectid',true);
  483. $section = $this->input->post('section',true);
  484. $lampData = array();
  485. if (!empty($lampid)) {
  486. $where = array('id'=>$lampid,'longitude !='=>0,'latitude !='=>0);
  487. if (!empty($section)) {
  488. $where['section'] = $section;
  489. }
  490. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  491. }
  492. if (!empty($projectid)) {
  493. $where = array('projectid'=>$projectid,'longitude !='=>0,'latitude !='=>0);
  494. if (!empty($section)) {
  495. $where['section'] = $section;
  496. }
  497. $lampData = $this->Lamp_model->get_one($where,'longitude,latitude');
  498. }
  499. if (empty($lampData)) {
  500. $lampData = array('longitude'=>0,'latitude'=>0);
  501. }
  502. exit(json_result('0000',$this->response['0000'],$lampData));
  503. }
  504. public function get_province(){
  505. // $countryId = intval($this->input->post('countryId',true));
  506. $role = $this->get_user_info('role');
  507. $where = array();
  508. if ($role != SYSTEM_ADMIN) {
  509. $company = $this->get_user_info('company');
  510. $where['company'] = $company;
  511. }
  512. $pro_list = $this->Project_model->get_list($where,'cityid');
  513. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  514. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  515. $areaList = array();
  516. $cityList = array();
  517. $proList = array();
  518. foreach ($list as $key => $value) {
  519. if ($value['level'] == 2) {
  520. $proList[] = $value;
  521. }elseif ($value['level'] == 3) {
  522. $cityList[] = $value;
  523. }elseif ($value['level'] == 4) {
  524. $areaList[] = $value;
  525. }
  526. }
  527. if (!empty($areaList)) {
  528. $cityArr = array_unique(array_column($areaList, 'pid'));
  529. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  530. foreach ($list as $key => $value) {
  531. if ($value['level'] == 2) {
  532. $proList[] = $value;
  533. }elseif ($value['level'] == 3) {
  534. $cityList[] = $value;
  535. }
  536. }
  537. }
  538. if (!empty($cityList)) {
  539. $cityArr = array_unique(array_column($cityList, 'pid'));
  540. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  541. foreach ($list as $key => $value) {
  542. if ($value['level'] == 2) $proList[] = $value;
  543. }
  544. }
  545. if (empty($proList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  546. $cityArr = array_unique(array_column($proList, 'id'));
  547. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  548. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  549. }
  550. public function get_city(){
  551. $proId = intval($this->input->post('proId',true));
  552. $role = $this->get_user_info('role');
  553. $where = array();
  554. if ($role != SYSTEM_ADMIN) {
  555. $company = $this->get_user_info('company');
  556. $where['company'] = $company;
  557. }
  558. $pro_list = $this->Project_model->get_list($where,'cityid');
  559. $cityArr = array_unique(array_column($pro_list, 'cityid'));
  560. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  561. $areaList = array();
  562. $cityList = array();
  563. foreach ($list as $key => $value) {
  564. if ($value['level'] == 3) {
  565. $cityList[] = $value;
  566. }elseif ($value['level'] == 4) {
  567. $areaList[] = $value;
  568. }
  569. }
  570. if (!empty($areaList)) {
  571. $cityArr = array_unique(array_column($areaList, 'pid'));
  572. $list = $this->Global_location_model->get_list(['id'=>$cityArr],'id,english_name as name,level,pid');
  573. foreach ($list as $key => $value) {
  574. if ($value['level'] == 3) $cityList[] = $value;
  575. }
  576. }
  577. if (empty($cityList)) exit(json_result('0000',$this->response['0000'],array('list'=>array())));
  578. $cityArr = array_unique(array_column($cityList, 'id'));
  579. $where = ['id'=>$cityArr];
  580. if (!empty($proId)) $where['pid'] = $proId;
  581. $list = $this->Global_location_model->get_list($where,'id,english_name as name',null,null,'convert(english_name using gbk) ASC,id DESC');
  582. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  583. }
  584. // 告警状态下拉列表
  585. public function alarm_type_list(){
  586. $version = $this->session->userdata('version');
  587. $batstatus = $this->config->item('batstatus');
  588. $panelstatus = $this->config->item('panelstatus');
  589. $lampstatus = $this->config->item('lampstatus');
  590. $tempstatus = $this->config->item('tempstatus');
  591. $list = array();
  592. foreach ($batstatus as $key => $value) {
  593. $list[] = ['name'=>$value,'value'=>'1'.$key];
  594. }
  595. foreach ($panelstatus as $key => $value) {
  596. $list[] = ['name'=>$value,'value'=>'2'.$key];
  597. }
  598. foreach ($lampstatus as $key => $value) {
  599. $list[] = ['name'=>$value,'value'=>'3'.$key];
  600. }
  601. foreach ($tempstatus as $key => $value) {
  602. $list[] = ['name'=>$value,'value'=>'4'.$key];
  603. }
  604. if ($this->os == 2) {
  605. exit(json_result('0000',$this->response['0000'],['list'=>$list]));
  606. }else{
  607. exit(json_result('0000',$this->response['0000'],$list));
  608. }
  609. }
  610. // 省级设备数量
  611. public function pro_dev_count(){
  612. $role = $this->get_user_info('role');
  613. $company = $this->get_user_info('company');
  614. $where = array();
  615. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  616. $where['G3.level'] = 2;
  617. $where['G3.pid'] = 92;
  618. $join = array();
  619. $join[] = ['table'=>'global_location as G2','cond'=>'G3.id = G2.pid AND G2.level = 3','type'=>'left'];
  620. $join[] = ['table'=>'global_location as G1','cond'=>'G2.id = G1.pid AND G1.level = 4','type'=>'left'];
  621. $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
  622. // $join[] = ['table'=>'global_location as G3','cond'=>'G3.id = G2.pid AND G3.level = 2','type'=>'left'];
  623. $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');
  624. foreach ($list as $key => $value) {
  625. $list[$key]['lampcount'] = intval($value['lampcount']);
  626. }
  627. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  628. }
  629. // 市级设备数量
  630. public function city_dev_count(){
  631. $role = $this->get_user_info('role');
  632. $company = $this->get_user_info('company');
  633. $where = array();
  634. $proId = intval($this->input->post('proId',true));
  635. if (!empty($proId)) $where['G2.pid'] = $proId;
  636. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  637. $where['G2.level'] = 3;
  638. $join = array();
  639. $join[] = ['table'=>'global_location as G1','cond'=>'G2.id = G1.pid','type'=>'left'];
  640. $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
  641. // $join[] = ['table'=>'global_location as G2','cond'=>'G2.id = G1.pid','type'=>'left'];
  642. $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');
  643. foreach ($list as $key => $value) {
  644. $list[$key]['lampcount'] = intval($value['lampcount']);
  645. }
  646. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  647. }
  648. // 区域设备数量
  649. public function area_dev_count(){
  650. $role = $this->get_user_info('role');
  651. $company = $this->get_user_info('company');
  652. $where = array();
  653. $cityId = intval($this->input->post('cityId',true));
  654. if (!empty($cityId)) $where['G1.pid'] = $cityId;
  655. if ($role != SYSTEM_ADMIN) $where['P.company'] = $company;
  656. $where['G1.level'] = 4;
  657. $join = array();
  658. $join[] = ['table'=>'project as P','cond'=>'G1.id = P.cityid AND G1.level = 4','type'=>'left'];
  659. // $join[] = ['table'=>'global_location as G1','cond'=>'G1.id = P.cityid','type'=>'left'];
  660. $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');
  661. foreach ($list as $key => $value) {
  662. $list[$key]['lampcount'] = intval($value['lampcount']);
  663. }
  664. exit(json_result('0000',$this->response['0000'],array('list'=>$list)));
  665. }
  666. // app额外接口
  667. public function app_home_data(){
  668. $data = array(
  669. 'project_count' => 0,
  670. 'upa_count' => 0,
  671. 'sup_count' => 0,
  672. 'manu_count' => 0,
  673. 'insert_power' => 0,
  674. 'gen_power' => 0,
  675. 'user_power' => 0,
  676. 'light_time' => 0,
  677. );
  678. $projectIdArr = $this->get_project_id();
  679. if (empty($projectIdArr)) exit(json_result('0000',$this->response['0000'],$data));
  680. $role = $this->get_user_info('role');
  681. $where = array();
  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. $data['project_count'] = $this->Project_model->get_count(['id'=>$projectIdArr,'company'=>$company]);
  687. }else{
  688. $data['project_count'] = count($projectIdArr);
  689. }
  690. $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';
  691. $total = $this->db->query($sql)->row_array();
  692. $data['manu_count'] = $total['total'];
  693. $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';
  694. $total = $this->db->query($sql)->row_array();
  695. $data['sup_count'] = $total['total'];
  696. $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';
  697. $total = $this->db->query($sql)->row_array();
  698. $data['upa_count'] = $total['total'];
  699. $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);
  700. $total = $this->db->query($sql)->row_array();
  701. $data['light_time'] = ceil($total['light_time']/60);
  702. $data['insert_power'] = round($total['boardpower']/1000,3);
  703. $data['gen_power'] = round($total['totalgeneration']/1000,3);
  704. $data['user_power'] = round($total['totalconsumption']/1000,3);
  705. exit(json_result('0000',$this->response['0000'],$data));
  706. }
  707. public function weather_info(){
  708. $areaId = intval($this->input->post('areaId',true));
  709. if (empty($areaId)) exit(json_result('0007',$this->response['0007']));
  710. $res1 = $this->Global_location_model->get_one(['id'=>$areaId],'level,pid,chinese_name,longitude,latitude,english_name');
  711. $url = 'https://free-api.heweather.net/s6/weather/forecast?location='.$res1['longitude'].','.$res1['latitude'].'&key=63dbc994630941fab269ad3c3af4d5d2';
  712. // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
  713. $resData = request_post($url);
  714. $arr = json_decode($resData,true);
  715. if ($arr['HeWeather6'][0]['status'] == 'ok') {
  716. $now = $arr['HeWeather6'][0]['daily_forecast'][0];
  717. $daily_forecast = $arr['HeWeather6'][0]['daily_forecast'];
  718. $data = ['weatherType'=>$now['cond_txt_d'],'code'=>$now['cond_code_d'],'tmp'=>intval(($now['tmp_min'] + $now['tmp_max'])/2)];
  719. }else{
  720. $data = ['weatherType'=>'','code'=>'','tmp'=>''];
  721. }
  722. exit(json_result('0000',$this->response['0000'],$data));
  723. }
  724. public function get_dev_number(){
  725. $projectId = intval($this->input->post('projectId',true));
  726. if (empty($projectId)) exit(json_result('0007',$this->response['0007']));
  727. $res = $this->Lamp_model->get_one(['projectid'=>$projectId],'max(number) as number');
  728. if (empty($res) || empty($res['number'])) {
  729. $number = 1;
  730. }else{
  731. $number = $res['number'];
  732. }
  733. $number = substr('000000'.$number,-6);
  734. exit(json_result('0000',$this->response['0000'],['number'=>$number]));
  735. }
  736. }