where('org_id',$this->orgId) ->where('del',0) ->count(); $count1 = Db::name('energy_device') ->where('org_id',$this->orgId) ->where('del',0) ->where('status',0) ->count(); $count2 = Db::name('energy_device') ->where('org_id',$this->orgId) ->where('del',0) ->where('status',1) ->count(); $count3 = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) ->where('eae.status',1) ->count(); $day = date('Y-m-d'); $kwh = (new EnergyParam())->getDegreeByDay($this->orgId,$day); $data = [ 'count'=>$count, 'count1'=>$count1, 'count2'=>$count2, 'count3'=>$count3, 'kwh'=>round($kwh,1), ]; HelpHander::success($data); } public function warningList(){ $lists = Db::name('energy_alarm_event') ->alias('eae') ->field('ea.alarm_time,ea.point_id,ea.point_label,ea.alarm_type,ea.current_value,eae.status') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) // ->where('eae.status','in',[0,1]) ->where('eae.status','=',0) ->order('eae.id desc') ->limit(10) ->select(); foreach ($lists as $k=>$v){ $lists[$k]['time'] = date('m-d H:i',strtotime($v['alarm_time'])); $lists[$k]['content'] = $v['point_id'].' '.$v['point_label'].' '.$v['alarm_type'].'-高水位告警当前值:'.$v['current_value']; } HelpHander::success($lists); } public function roomInfo(){ $t = Db::name('energy_param') ->alias("pa") ->join("energy_device a","a.sn = pa.device_sn") ->field("pa.content") ->where('pa.org_id',$this->orgId) ->where('a.cate',3) ->order('pa.id desc') ->find(); $content = isset($t['content']) && !empty($t['content']) ? json_decode($t['content'],true):[]; $temp = ['men'=>'', 'yan'=>'', 'wenshi'=>'', 'shui'=>'','shui1'=>'','monitor'=>'','monitor1'=>'']; if(isset($content['Temp']) && !empty($content['Temp'])){ $wen = round($content['Temp'],1).'℃/'; $shi = round($content['Humi'],0).'%RH'; $temp['wenshi'] = $wen.$shi; } $t1 = Db::name('energy_param') ->alias("pa") ->join("energy_device a","a.sn = pa.device_sn") ->join("energy_device_cate b","a.cate = b.id") ->field("pa.content,a.*,b.title as cate_title") ->where('pa.org_id',$this->orgId) ->where('b.id',4) ->order('pa.id desc') ->find(); $content1 = isset($t1['content']) && !empty($t1['content']) ? json_decode($t1['content'],true):[]; if(isset($content1['遥信1']) && !empty($content1['遥信1'])){ $temp['shui'] = $content1['遥信1'] == 1?"有":"无"; $temp['shui1'] = $content1['遥信2'] == 1?"有":"无"; $temp['yan'] = $content1['遥信3'] == 1?"开":"关"; $temp['men'] = $content1['遥信4'] == 1?"开":"关"; } $monitorList = Db::name('energy_monitor') ->where('org_id',$this->orgId) ->where('del',0) ->where('enable',1) ->order('id asc') ->limit(2) ->select(); if($monitorList){ $ysUtil = new YsUtil(); foreach ($monitorList as $k=>$v){ $v['url'] = $ysUtil->getLiveUrl($v['device_sn'],$v['channel']); if(isset($k) && $k==0){ $temp['monitor'] = $v; } if(isset($k) && $k==1){ $temp['monitor1'] = $v; } } } HelpHander::success($temp); } public function roomParamList(){ $lists = Db::name('energy_room') ->field('id,title') ->where('org_id',$this->orgId) ->where('del',0) ->limit(5) ->select(); foreach ($lists as $k=>$v){ $lists[$k]['status'] = 1; $count = 0; $deviceList = Db::name('energy_device') ->field('id,sn,title,cate,address_id') ->where('del',0) ->where('room_id',$v['id']) ->where('cate',1) ->group('sn') ->select(); $lists[$k]['cate_count'] = count($deviceList); $lists[$k]['cate_title'] = Db::name('energy_device_cate')->where('id',1)->value('title'); foreach ($deviceList as $kk=>$vv){ $deviceList[$kk]['title'] = Db::name('energy_address')->where('id',$vv['address_id'])->value('title'); $count +=1; $paramInfo = Db::name('energy_param') ->field('id,content,status') ->where('device_sn',$vv['sn']) ->order('report_time desc,id desc') ->find(); $contents = $paramInfo ? json_decode($paramInfo['content'],true):[]; $ua = $ub = $uc = $switch = $s = '0.00'; //电压 $wa = $wb = $wc = '32'; //温度 $bl = '1'; //占比 if(isset($contents['EPI'])){ $ua = isset($contents['Ua']) ? $contents['Ua'] :'0.00'; $ub = isset($contents['Ub']) ? $contents['Ub'] :'0.00'; $uc = isset($contents['Uc']) ? $contents['Uc'] :'0.00'; $s = isset($contents['S']) ? $contents['S'] :'0.00'; if(isset($contents['Switch']) && $contents['Switch'] == '1'){ $switch = '合闸'; }else{ $switch = '分闸'; } } if(!empty($paramInfo['status']) && $paramInfo['status'] == 0){ $statusTxt = '离线'; }elseif(!empty($paramInfo['status']) && $paramInfo['status'] == 1){ $statusTxt = '在线'; }else{ $statusTxt = ''; } $deviceList[$kk]['status_txt'] = $statusTxt; $deviceList[$kk]['ua'] = round($ua,1); $deviceList[$kk]['ub'] = round($ub,1); $deviceList[$kk]['uc'] = round($uc,1); $deviceList[$kk]['switch'] = $switch; $deviceList[$kk]['wa'] = round($wa,1); $deviceList[$kk]['wb'] = round($wb,1); $deviceList[$kk]['wc'] = round($wc,1); $deviceList[$kk]['bl'] = $bl; $deviceList[$kk]['s'] = round($s,1); } $lists[$k]['list'] = $deviceList; $deviceList1 = Db::name('energy_device') ->field('id,sn,title,cate,address_id') ->where('del',0) ->where('room_id',$v['id']) ->where('cate',5) ->group('sn') ->select(); $lists[$k]['cate_count5'] = count($deviceList1); $lists[$k]['cate_title5'] = Db::name('energy_device_cate')->where('id',5)->value('title'); foreach ($deviceList1 as $kkk=>$vvv){ $deviceList1[$kkk]['title'] = Db::name('energy_address')->where('id',$vvv['address_id'])->value('title'); $count +=1; $paramInfo1 = Db::name('energy_param') ->field('id,content,status') ->where('device_sn',$vvv['sn']) ->order('report_time desc,id desc') ->find(); $contents1 = $paramInfo1 ? json_decode($paramInfo1['content'],true):[]; $ua1 = $ub1 = $uc1 = $switch1 = $s1 ='0.00'; //电压 $wa1 = $wb1 = $wc1 = '32'; //温度 $bl1 = '1'; //占比 if(isset($contents1['EPI'])){ $ua1 = isset($contents1['Ua']) ? $contents1['Ua'] :'0.00'; $ub1 = isset($contents1['Ub']) ? $contents1['Ub'] :'0.00'; $uc1 = isset($contents1['Uc']) ? $contents1['Uc'] :'0.00'; $s1 = isset($contents1['S']) ? $contents1['S'] :'0.00'; if(isset($contents1['Switch']) && $contents1['Switch'] == '1'){ $switch1 = '合闸'; }else{ $switch1 = '分闸'; } } if(!empty($paramInfo1['status']) && $paramInfo1['status'] == 0){ $statusTxt1 = '离线'; }elseif(!empty($paramInfo1['status']) && $paramInfo1['status'] == 1){ $statusTxt1 = '在线'; }else{ $statusTxt1 = ''; } $deviceList1[$kkk]['status_txt'] = $statusTxt1; $deviceList1[$kkk]['ua'] = round($ua1,1); $deviceList1[$kkk]['ub'] = round($ub1,1); $deviceList1[$kkk]['uc'] = round($uc1,1); $deviceList1[$kkk]['switch'] = $switch1; $deviceList1[$kkk]['wa'] = round($wa1,1); $deviceList1[$kkk]['wb'] = round($wb1,1); $deviceList1[$kkk]['wc'] = round($wc1,1); $deviceList1[$kkk]['bl'] = $bl1; $deviceList1[$kkk]['s'] = round($s1,1); } $lists[$k]['list1'] = $deviceList1; $lists[$k]['count'] = $count; } HelpHander::success($lists); } }