query("select * from sp_owner where company=".$company_code); $company_data=M()->query("select owner_name,owner_address,create_time from sp_owner_company where owner_id=".$company_code); $time=date("Y-m-d"); $time2=date("Y年m月"); $time1=date("Y-m-d H:s:i"); $physical_examination_data=M()->query("select * from sp_physical_examination where company_code='".$company_code."' and time like'%".$time."%'"); $yc_device1=""; $sj_device1=""; $yg_device1=""; $xfs_device1=""; $yw_device1=""; $rtu_device1=""; $dqhz_device1=""; $spjc_device1=""; $dtjc_device1=""; $jgjc_device1=""; $dcjc_device1=""; $mcjs_device1=""; $krqt_device1=""; foreach ($R as $val) { if ($val['dwtype']==1){ $yc_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==2){ $sj_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==3){ $yg_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==4){ $xfs_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==5){ $yw_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==6){ $rtu_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==7){ $dqhz_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==16){ $spjc_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==17){ $dtjc_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==128){ $jgjc_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==129){ $dcjc_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==130){ $mcjs_device1.="'".$val['owner_code']."',"; }else if ($val['dwtype']==131){ $krqt_device1.="'".$val['owner_code']."',"; } } if (!empty($yc_device1)){ $yc_device = substr($yc_device1,0,strlen($yc_device1)-1); $yc_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yc_device.")"); $yc_count=$yc_data[0]['a']; $ycl_yc_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yc_device.") and clzt=1"); $ycl_yc_count=$ycl_yc_data[0]['a']; $zb_yc=$ycl_yc_count/$yc_count*100; if ($zb_yc>=80){ $zb_yc1=1; }else if ($zb_yc==0){ $zb_yc1=3; }else{ $zb_yc1=0; } }else{ $yc_count=0; $zb_yc1=2; } if (!empty($sj_device1)){ $sj_device = substr($sj_device1,0,strlen($sj_device1)-1); $sj_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$sj_device.")"); $sj_count=$sj_data[0]['a']; $ycl_sj_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$sj_device.") and clzt=1"); $ycl_sj_count=$ycl_sj_data[0]['a']; $zb_sj=$ycl_sj_count/$sj_count*100; if ($zb_sj>=80){ $zb_sj1=1; }else if ($zb_sj==0){ $zb_sj1=3; }else{ $zb_sj1=0; } }else{ $sj_count=0; $zb_sj1=2; } if (!empty($yg_device1)){ $yg_device = substr($yg_device1,0,strlen($yg_device1)-1); $yg_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yg_device.")"); $yg_count=$yg_data[0]['a']; $ycl_yg_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yg_device.") and clzt=1"); $ycl_yg_count=$ycl_yg_data[0]['a']; $zb_yg=$ycl_yg_count/$yg_count*100; if ($zb_yg>=80){ $zb_yg1=1; }else if ($zb_yg==0){ $zb_yg1=3; }else{ $zb_yg1=0; } }else{ $yg_count=0; $zb_yg1=2; } if (!empty($xfs_device1)){ $xfs_device = substr($xfs_device1,0,strlen($xfs_device1)-1); $xfs_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$xfs_device.")"); $xfs_count=$xfs_data[0]['a']; $ycl_xfs_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$xfs_device.") and clzt=1"); $ycl_xfs_count=$ycl_xfs_data[0]['a']; $zb_xfs=$ycl_xfs_count/$xfs_count*100; if ($zb_xfs>=80){ $zb_xfs1=1; }else if ($zb_xfs==0){ $zb_xfs1=3; }else{ $zb_xfs1=0; } }else{ $xfs_count=0; $zb_xfs1=2; } if (!empty($yw_device1)){ $yw_device = substr($yw_device1,0,strlen($yw_device1)-1); $yw_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$yw_device.")"); $yw_count=$yw_data[0]['a']; $ycl_yw_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$yw_device.") and clzt=1"); $ycl_yw_count=$ycl_yw_data[0]['a']; $zb_yw=$ycl_yw_count/$yw_count*100; if ($zb_yw>=80){ $zb_yw1=1; }else if ($zb_yw==0){ $zb_yw1=3; }else{ $zb_yw1=0; } }else{ $yw_count=0; $zb_yw1=2; } if (!empty($rtu_device1)){ $rtu_device = substr($rtu_device1,0,strlen($rtu_device1)-1); $rtu_data=M()->query("select count(id) as a from sp_rtu2017 where device_code in (".$rtu_device.")"); $rtu_count=$rtu_data[0]['a']; $ycl_rtu_data=M()->query("select count(id) as a from sp_rtu2017 where device_code in (".$rtu_device.") and clzt=1"); $ycl_rtu_count=$ycl_rtu_data[0]['a']; $zb_rtu=$ycl_rtu_count/$rtu_count*100; if ($zb_rtu>=80){ $zb_rtu1=1; }else if ($zb_rtu==0){ $zb_rtu1=3; }else{ $zb_rtu1=0; } }else{ $rtu_count=0; $zb_rtu1=2; } if (!empty($dqhz_device1)){ $dqhz_device = substr($dqhz_device1,0,strlen($dqhz_device1)-1); $dqhz_data=M()->query("select count(id) as a from sp_ef2017 where device_code in (".$dqhz_device.")"); $dqhz_count=$dqhz_data[0]['a']; $ycl_dqhz_data=M()->query("select count(id) as a from sp_ef2017 where device_code in (".$dqhz_device.") and clzt=1"); $ycl_dqhz_count=$ycl_dqhz_data[0]['a']; $zb_dqhz=$ycl_dqhz_count/$dqhz_count*100; if ($zb_dqhz>=80){ $zb_dqhz1=1; }else if ($zb_dqhz==0){ $zb_dqhz1=3; }else{ $zb_dqhz1=0; } }else{ $dqhz_count=0; $zb_dqhz1=2; } if (!empty($spjc_device1)){ $spjc_device = substr($spjc_device1,0,strlen($spjc_device1)-1); $spjc_data=M()->query("select count(id) as a from sp_video2017 where device_code in (".$spjc_device.")"); $spjc_count=$spjc_data[0]['a']; $ycl_spjc_data=M()->query("select count(id) as a from sp_video2017 where device_code in (".$spjc_device.") and clzt=1"); $ycl_spjc_count=$ycl_spjc_data[0]['a']; $zb_spjc=$ycl_spjc_count/$spjc_count*100; if ($zb_spjc>=80){ $zb_spjc1=1; }else if ($zb_spjc==0){ $zb_spjc1=3; }else{ $zb_spjc1=0; } }else{ $spjc_count=0; $zb_spjc1=2; } if (!empty($dtjc_device1)){ $dtjc_device = substr($dtjc_device1,0,strlen($dtjc_device1)-1); $dtjc_data=M()->query("select count(id) as a from sp_lifter2017 where device_code in (".$dtjc_device.")"); $dtjc_count=$dtjc_data[0]['a']; $ycl_dtjc_data=M()->query("select count(id) as a from sp_lifter2017 where device_code in (".$dtjc_device.") and clzt=1"); $ycl_dtjc_count=$ycl_dtjc_data[0]['a']; $zb_dtjc=$ycl_dtjc_count/$dtjc_count*100; if ($zb_dtjc>=80){ $zb_dtjc1=1; }else if ($zb_dtjc==0){ $zb_dtjc1=3; }else{ $zb_dtjc1=0; } }else{ $dtjc_count=0; $zb_dtjc1=2; } if (!empty($jgjc_device1)){ $jgjc_device = substr($jgjc_device1,0,strlen($jgjc_device1)-1); $jgjc_data=M()->query("select count(id) as a from sp_iw2017 where device_code in (".$jgjc_device.")"); $jgjc_count=$jgjc_data[0]['a']; $ycl_jgjc_data=M()->query("select count(id) as a from sp_iw2017 where device_code in (".$jgjc_device.") and clzt=1"); $ycl_jgjc_count=$ycl_jgjc_data[0]['a']; $zb_jgjc=$ycl_jgjc_count/$jgjc_count*100; if ($zb_jgjc>=80){ $zb_jgjc1=1; }else if ($zb_jgjc==0){ $zb_jgjc1=3; }else{ $zb_jgjc1=0; } }else{ $jgjc_count=0; $zb_jgjc1=2; } if (!empty($dcjc_device1)){ $dcjc_device = substr($dcjc_device1,0,strlen($dcjc_device1)-1); $dcjc_data=M()->query("select count(id) as a from sp_dc2020 where device_code in (".$dcjc_device.")"); $dcjc_count=$dcjc_data[0]['a']; $ycl_dcjc_data=M()->query("select count(id) as a from sp_dc2020 where device_code in (".$dcjc_device.") and clzt=1"); $ycl_dcjc_count=$ycl_dcjc_data[0]['a']; $zb_dcjc=$ycl_dcjc_count/$dcjc_count*100; if ($zb_dcjc>=80){ $zb_dcjc1=1; }else if ($zb_dcjc==0){ $zb_dcjc1=3; }else{ $zb_dcjc1=0; } }else{ $dcjc_count=0; $zb_dcjc1=2; } if (!empty($mcjs_device1)){ $mcjs_device = substr($mcjs_device1,0,strlen($mcjs_device1)-1); $mcjs_data=M()->query("select count(id) as a from sp_door2020 where device_code in (".$mcjs_device.")"); $mcjs_count=$mcjs_data[0]['a']; $ycl_mcjs_data=M()->query("select count(id) as a from sp_door2020 where device_code in (".$mcjs_device.") and clzt=1"); $ycl_mcjs_count=$ycl_mcjs_data[0]['a']; $zb_mcjs=$ycl_mcjs_count/$mcjs_count*100; if ($zb_mcjs>=80){ $zb_mcjs1=1; }else if ($zb_mcjs==0){ $zb_mcjs1=3; }else{ $zb_mcjs1=0; } }else{ $mcjs_count=0; $zb_mcjs1=2; } if (!empty($krqt_device1)){ $krqt_device = substr($krqt_device1,0,strlen($krqt_device1)-1); $krqt_data=M()->query("select count(id) as a from sp_gas2020 where device_code in (".$krqt_device.")"); $krqt_count=$krqt_data[0]['a']; $ycl_krqt_data=M()->query("select count(id) as a from sp_gas2020 where device_code in (".$krqt_device.") and clzt=1"); $ycl_krqt_count=$ycl_krqt_data[0]['a']; $zb_krqt=$ycl_krqt_count/$krqt_count*100; if ($zb_krqt>=80){ $zb_krqt1=1; }else if ($zb_krqt==0){ $zb_krqt1=3; }else{ $zb_krqt1=0; } }else{ $krqt_count=0; $zb_krqt1=2; } $sy_count=$yc_count+$sj_count+$yg_count+$xfs_count+$yw_count+$rtu_count+$dqhz_count+$spjc_count+$dtjc_count+$jgjc_count+$dcjc_count+$mcjs_count+$krqt_count; if ($sy_count<180){ $score=90; }else if ($sy_count>180&&$sy_count<300){ $score=80; }else if ($sy_count>300){ $score=60; } if (empty($physical_examination_data)){ $inset_sql="INSERT INTO sp_physical_examination ( company_name, company_code,yc_count,sj_count,yg_count,xfs_count,yw_count,rtu_count,dqhz_count,spjc_count,dtjc_count,jgjc_count,dcjc_count,mcjs_count,krqt_count,sy_count,score,time) VALUE ('".$company_data[0]['owner_name']."', '".$company_code."',".$yc_count.",".$sj_count.",".$yg_count.",".$xfs_count.",".$yw_count.",".$rtu_count.",".$dqhz_count.",".$spjc_count.",".$dtjc_count.",".$jgjc_count.",".$dcjc_count.",".$mcjs_count.",".$krqt_count.",".$sy_count.",".$score.",'".$time1."')"; insert_187_ytIoT($inset_sql); }else{ $update_sql="UPDATE sp_physical_examination set yc_count=".$yc_count.",sj_count=".$sj_count.",yg_count=".$yg_count.",xfs_count=".$xfs_count.",yw_count=".$yw_count.",rtu_count=".$rtu_count.",dqhz_count=".$dqhz_count.",spjc_count=".$spjc_count.", dtjc_count=".$dtjc_count.",jgjc_count=".$jgjc_count.",dcjc_count=".$dcjc_count.",mcjs_count=".$mcjs_count.",krqt_count=".$krqt_count.",sy_count=".$sy_count.",score=".$score.",time='".$time1."' where id=".$physical_examination_data[0]['id']; insert_187_ytIoT($update_sql); } $physical_examination_data1=M()->query("select * from sp_physical_examination where time like'%".$time."%'"); $pm=1; foreach ($physical_examination_data1 as $key => $value){ if ($sy_count>$physical_examination_data1[$key]['sy_count']){ $pm+=1; } } $data[0]['ranking']=$pm; $data[0]['company_code']=$company_code; $data[0]['company_name']=$company_data[0]['owner_name']; $data[0]['address']=$company_data[0]['owner_address']; $data[0]['create_time']=$company_data[0]['create_time']; $data[0]['total']=(int)$sy_count; $data[0]['score']=$score; $data[0]['time']=$time2; $data[0]['state_yc']=(int)$zb_yc1; $data[0]['state_sj']=(int)$zb_sj1; $data[0]['state_yg']=(int)$zb_yg1; $data[0]['state_xfs']=(int)$zb_xfs1; $data[0]['state_yw']=(int)$zb_yw1; $data[0]['state_rtu']=(int)$zb_rtu1; $data[0]['state_dqhz']=(int)$zb_dqhz1; $data[0]['state_spjc']=(int)$zb_spjc1; $data[0]['state_dtjc']=(int)$zb_dtjc1; $data[0]['state_jgjc']=(int)$zb_jgjc1; $data[0]['state_dcjc']=(int)$zb_dcjc1; $data[0]['state_mcjc']=(int)$zb_mcjs1; $data[0]['state_krqt']=(int)$zb_krqt1; $data[0]['count_yc']=(int)$yc_count; $data[0]['count_sj']=(int)$sj_count; $data[0]['count_yg']=(int)$yg_count; $data[0]['count_xfs']=(int)$xfs_count; $data[0]['count_yw']=(int)$yw_count; $data[0]['count_rtu']=(int)$rtu_count; $data[0]['count_dqhz']=(int)$dqhz_count; $data[0]['count_spjc']=(int)$spjc_count; $data[0]['count_dtjc']=(int)$dtjc_count; $data[0]['count_jgjc']=(int)$jgjc_count; $data[0]['count_dcjc']=(int)$dcjc_count; $data[0]['count_mcjc']=(int)$mcjs_count; $data[0]['count_krqt']=(int)$krqt_count; $data[0]['count_ycl_yc']=(int)$ycl_yc_count; $data[0]['count_ycl_sj']=(int)$ycl_sj_count; $data[0]['count_ycl_yg']=(int)$ycl_yg_count; $data[0]['count_ycl_xfs']=(int)$ycl_xfs_count; $data[0]['count_ycl_yw']=(int)$ycl_yw_count; $data[0]['count_ycl_rtu']=(int)$ycl_rtu_count; $data[0]['count_ycl_dqhz']=(int)$ycl_dqhz_count; $data[0]['count_ycl_spjc']=(int)$ycl_spjc_count; $data[0]['count_ycl_dtjc']=(int)$ycl_dtjc_count; $data[0]['count_ycl_jgjc']=(int)$ycl_jgjc_count; $data[0]['count_ycl_dcjc']=(int)$ycl_dcjc_count; $data[0]['count_ycl_mcjc']=(int)$ycl_mcjs_count; $data[0]['count_ycl_krqt']=(int)$ycl_krqt_count; $res['msg'] = '操作成功'; $res['flag'] = true; $res['data'] = $data; echo json_encode($res); } }