123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <?php
- /**
- * Created by PhpStorm.
- * User: TianFeng
- * Date: 2019-03-18
- * Time: 15:38
- */
- namespace Home\Controller;
- use Think\Controller;
- include '../Common/function.php';
- class ScanController extends ComController {
- //巡检方法
- public function pdsflr(){
- $data=I('post.data');
- $jh_id=I('post.jh_id');
- $dw_id=I('post.dw_id');
- $sql1="select * from ytiot_xj_inspection_points where spot_label_analysis='".$data."' and id=". $dw_id." and data1='1'";
- // print_r($sql1);
- $res1=add($sql1);
- // print_r($res1);
- // exit();
- if(empty($res1)){
- echo 1;
- exit();
- }
- $res2=array();
- // $res2['ms']=2;
- $res2['jh_id']=$jh_id;
- $res2['dw_id']=$dw_id;
- if(!empty($res2)){
- echo json_encode($res2);
- exit();
- }
- }
- //维保方法
- public function pdsflr2(){
- $data=I('post.data');
- $jh_id=I('post.jh_id');
- $dw_id=I('post.dw_id');
- $sql1="select * from ytiot_xj_inspection_points where spot_label_analysis='".$data."' and id=". $dw_id." and data1='2'";
- // print_r($sql1);
- $res1=add($sql1);
- // print_r($res1);
- // exit();
- if(empty($res1)){
- echo 1;
- exit();
- }
- $res2=array();
- // $res2['ms']=2;
- $res2['jh_id']=$jh_id;
- $res2['dw_id']=$dw_id;
- if(!empty($res2)){
- echo json_encode($res2);
- exit();
- }
- }
- //巡检方法
- public function from(){
- $res1 =I();
- // print_r($res1);
- $this->assign('res1',$res1);
- $this->display('Index2/from');
- }
- //维保方法
- public function from2(){
- $res1 =I();
- $this->assign('res1',$res1);
- $this->display('Index2/wb_from');
- }
- //巡检方法
- public function xjd_inset(){
- $data=I();
- // print_r($data);
- // exit();
- $zb_id=$data['zb_id'];
- $spot_id=$data['spot_id'];
- $wbr_id=$data['wbr_id'];
- $spot_abnormal=$data['spot_abnormal'];
- // $company_code1=$data['company_code'];
- // print_r($spot_abnormal);
- // exit();
- $wc_time=date("Y-m-d H:i:s");
- $dwsb_remarks=$data['dwsb_remarks'];
- $data1=$data['data1'];
- // $data3=2;
- $people_id_sql=" select team_id,inspect_date,end_time,company_code,completion from ytiot_xj_plan_child where id=".$zb_id;
- $people_id_res=add($people_id_sql);
- if($people_id_res!=null){
- $people_id_sql1="select person_liable_id from ytiot_xj_plan_team where id=". $people_id_res[0]['team_id'];
- $people_id_res1=add($people_id_sql1);
- if ($people_id_res1!=null){
- $people_id = $people_id_res1[0]['person_liable_id'];
- }
- $ywc_time=$people_id_res[0]['inspect_date']." ".$people_id_res[0]['end_time'];
- $company_code=$people_id_res[0]['company_code'];
- }
- $tmpFilePath = $_FILES['img']['tmp_name'];
- if($_FILES["img"]["error"]==1){
- $this->success('图片上传失败,图片大小超过限制2M',U('Inspection/index'),3);
- }
- // print_r($_FILES["file"]);
- //确保我们有一个文件路径
- if ($tmpFilePath != ""){
- //设置我们的新文件路径
- $FileCode=date('YmdHis').rand(1000,9999);
- $FileName=$_FILES['img']['name'];
- $FileType=strtolower(substr(strrchr($FileName,'.'),1));
- $BasefName=$FileCode.'.'.$FileType;
- $newFilePath ='/var/www/html/jdxf/Maintinfo/image/'.$BasefName;
- $newFilePath1 ='https://qhome.usky.cn/jdxf/Maintinfo/image/'.$BasefName;
- // $newFilePath ='D://QrCode/'.$BasefName;
- //将文件上传到临时目录中
- // exit();
- // print_r("测试0".$tmpFilePath);
- // print_r("测试1".move_uploaded_file($tmpFilePath, $newFilePath));
- if(move_uploaded_file($tmpFilePath, $newFilePath)) {
- $wb_sql = "UPDATE ytiot_xj_spot_operation_record set people_id=".$people_id.",spot_abnormal=".$spot_abnormal.",wc_time='".$wc_time."',dwsb_remarks='".$dwsb_remarks."',data3='2',wbr_id=".$wbr_id.
- " where zb_id=".$zb_id." and spot_id=".$spot_id;
- // $jl_sql="insert into ytiot_xj_spot_operation_record(zb_id,spot_id,people_id,spot_abnormal,ywc_time,wc_time,company_code,dwsb_remarks,data3) value(
- // $zb_id,$spot_id,$people_id,'$spot_abnormal','$ywc_time','$wc_time','$company_code','$dwsb_remarks','$data3')";
- $res1=addDataInfo($wb_sql);
- // print_r("测试2".$res1);
- if($res1){
- $photosql="select id,spot_abnormal,data1 from ytiot_xj_spot_operation_record where zb_id=".$zb_id." and spot_id=".$spot_id." and wc_time='".$wc_time."'";
- $photosres=add($photosql);
- echo 1;
- if ($photosres!=null){
- // if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
- // $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,data1) value (".$photosres[0]['id'].",'".$photosres[0]['data1']."','".$data1."')";
- // $photos_res=addDataInfo($wxsb_sql);
- // }
- if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
- $company_data=M()->query("select owner_id from sp_owner_company where building_id='".$company_code."'");
- // $inster_sql="insert into ytiot_xj_event_processing (dwjl_id,user_name,wx_name,cl_type,data2,data3) value ('0','".$_SESSION['phone']."','".$wx_name."',2,'".$owner_data[0]['company']."','".$lsxx."')";
- $wx_name='设备异常';
- $dqsj= date('Y-m-d h:i:s', time());
- $lsxx=$dqsj.",".$wx_name;
- // $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,wx_name,cl_type,data2,data3) value (".$photosres[0]['id'].",'".$_SESSION['phone']."','".$data1."',0,'".$company_data[0]['owner_id']."','".$lsxx."')";
- $wxsb_sql="insert into ytiot_xj_event_processing (id,dwjl_id,wx_name,sj_type,y_complete_time,person_liable,zp_remarks,user_name,cl_type,jg_remarks,sh_remarks,sh_time,cl_time,picture_path,data1,data2,data3) value ('',".$photosres[0]['id'].",'".$data1."',0,'',null,'','".$photosres[0]['data1']."',0,'','','','','','','".$company_data[0]['owner_id']."','".$lsxx."');";
- // print_r($wxsb_sql);
- $photos_res=addDataInfo($wxsb_sql);
- }
- $photo_sql="insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (".$photosres[0]['id'].",'".$newFilePath1."')";
- $photos_res=addDataInfo($photo_sql);
- if ($photos_res){
- $dwzsl_sql="select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id;
- // print_r('测试'.$dwzsl_sql);
- $dwzsl=add($dwzsl_sql);
- // print_r('测试'.$dwzsl);
- $yxjzsl_sql="select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id." and data3='2'";
- // print_r('测试'.$yxjzsl_sql);
- $yxjzsl=add($yxjzsl_sql);
- // print_r('测试'.$yxjzsl);
- if($dwzsl[0]['dwzsl']==$yxjzsl[0]['yxjzsl']){
- $wcqk_sql="update ytiot_xj_plan_child set completion=100,data3='".$wc_time."' where id=".$zb_id;
- $wcqk_res=addDataInfo($wcqk_sql);
- if ($wcqk_res){
- // echo "<script>window.history.go(-2);</script>";
- $this->success('保存成功',U('Inspection/index'),3);
- }else{
- $this->error('上传失败');
- }
- }else{
- $yg=1/$dwzsl[0]['dwzsl']*100;
- $completion=$people_id_res[0]['completion']+$yg;
- $wcqk_sql="update ytiot_xj_plan_child set completion=".$completion." where id=".$zb_id;
- $wcqk_res=addDataInfo($wcqk_sql);
- if ($wcqk_res){
- // echo "<script>window.history.go(-2);</script>";
- $this->success('保存成功',U('Inspection/index'),3);
- }else{
- $this->error('上传失败');
- }
- }
- }else{
- $this->error('上传失败');
- }
- }
- }else{
- $this->error('上传失败');
- }
- }else{
- // $this->success('上传失败,图片大小超过上限2M',U('Inspection/index'),3);
- $this->error('上传失败');
- }
- }
- }
- //维保方法
- public function xjd_inset2(){
- $data=I();
- // print_r($data);
- // exit();
- $zb_id=$data['zb_id'];
- $spot_id=$data['spot_id'];
- $wbr_id=$data['wbr_id'];
- $spot_abnormal=$data['spot_abnormal'];
- $wc_time=date("Y-m-d H:i:s");
- $dwsb_remarks=$data['dwsb_remarks'];
- $data1=$data['data1'];
- $company_code1=$data['company_code'];
- // $data3=2;
- $people_id_sql=" select team_id,inspect_date,end_time,company_code,completion from ytiot_xj_plan_child where id=".$zb_id;
- $people_id_res=add($people_id_sql);
- if($people_id_res!=null){
- $people_id_sql1="select person_liable_id from ytiot_xj_plan_team where id=". $people_id_res[0]['team_id'];
- $people_id_res1=add($people_id_sql1);
- if ($people_id_res1!=null){
- $people_id = $people_id_res1[0]['person_liable_id'];
- }
- $ywc_time=$people_id_res[0]['inspect_date']." ".$people_id_res[0]['end_time'];
- $company_code=$people_id_res[0]['company_code'];
- }
- $tmpFilePath = $_FILES['img']['tmp_name'];
- if($_FILES["img"]["error"]==1){
- $this->success('图片上传失败,图片大小超过限制2M',U('Inspection/index'),3);
- }
- //确保我们有一个文件路径
- if ($tmpFilePath != ""){
- //设置我们的新文件路径
- $FileCode=date('YmdHis').rand(1000,9999);
- $FileName=$_FILES['img']['name'];
- $FileType=strtolower(substr(strrchr($FileName,'.'),1));
- $BasefName=$FileCode.'.'.$FileType;
- $newFilePath ='/var/www/html/jdxf/Maintinfo/image/'.$BasefName;
- $newFilePath1 ='https://qhome.usky.cn/jdxf/Maintinfo/image/'.$BasefName;
- // $newFilePath ='D://QrCode/'.$BasefName;
- //将文件上传到临时目录中
- // exit();
- // print_r("测试0".$tmpFilePath);
- // print_r("测试1".$spot_id);
- if(move_uploaded_file($tmpFilePath, $newFilePath)) {
- $wb_sql = "UPDATE ytiot_xj_spot_operation_record set people_id=".$people_id.",spot_abnormal=".$spot_abnormal.",wc_time='".$wc_time."',dwsb_remarks='".$dwsb_remarks."',data3='2',wbr_id=".$wbr_id.
- " where zb_id=".$zb_id." and spot_id=".$spot_id;
- // $jl_sql="insert into ytiot_xj_spot_operation_record(zb_id,spot_id,people_id,spot_abnormal,ywc_time,wc_time,company_code,dwsb_remarks,data3) value(
- // $zb_id,$spot_id,$people_id,'$spot_abnormal','$ywc_time','$wc_time','$company_code','$dwsb_remarks','$data3')";
- $res1=addDataInfo($wb_sql);
- // print_r("测试2".$res1);
- if($res1){
- $photosql="select id,spot_abnormal,data1 from ytiot_xj_spot_operation_record where zb_id=".$zb_id." and spot_id=".$spot_id." and wc_time='".$wc_time."'";
- $photosres=add($photosql);
- if ($photosres!=null){
- // if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
- // $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,data1) value (".$photosres[0]['id'].",'".$photosres[0]['data1']."','".$data1."')";
- // $photos_res=addDataInfo($wxsb_sql);
- // }
- if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
- $company_data=M()->query("select owner_id from sp_owner_company where building_id='".$company_code."'");
- $wx_name='设备异常';
- $dqsj= date('Y-m-d h:i:s', time());
- $lsxx=$dqsj.",".$wx_name;
- // $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,wx_name,cl_type,data2,data3) value (".$photosres[0]['id'].",'".$_SESSION['phone']."','".$data1."',0,'".$company_code1."','".$lsxx."')";
- $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,wx_name,cl_type,data2,data3) value (".$photosres[0]['id'].",'".$_SESSION['phone']."','".$data1."',0,'".$company_data[0]['owner_id']."','".$lsxx."')";
- $photos_res=addDataInfo($wxsb_sql);
- }
- $photo_sql="insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (".$photosres[0]['id'].",'".$newFilePath1."')";
- $photos_res=addDataInfo($photo_sql);
- if ($photos_res){
- $dwzsl_sql="select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id;
- // print_r('测试'.$dwzsl_sql);
- $dwzsl=add($dwzsl_sql);
- // print_r('测试'.$dwzsl);
- $yxjzsl_sql="select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id." and data3='2'";
- // print_r('测试'.$yxjzsl_sql);
- $yxjzsl=add($yxjzsl_sql);
- // print_r('测试'.$yxjzsl);
- if($dwzsl[0]['dwzsl']==$yxjzsl[0]['yxjzsl']){
- $wcqk_sql="update ytiot_xj_plan_child set completion=100,data3='".$wc_time."' where id=".$zb_id;
- $wcqk_res=addDataInfo($wcqk_sql);
- if ($wcqk_res){
- // echo "<script>window.history.go(-2);</script>";
- $this->success('保存成功',U('Inspection/index2'),3);
- }else{
- $this->error('上传失败');
- }
- }else{
- $yg=1/$dwzsl[0]['dwzsl']*100;
- $completion=$people_id_res[0]['completion']+$yg;
- $wcqk_sql="update ytiot_xj_plan_child set completion=".$completion." where id=".$zb_id;
- $wcqk_res=addDataInfo($wcqk_sql);
- if ($wcqk_res){
- // echo "<script>window.history.go(-2);</script>";
- $this->success('保存成功',U('Inspection/index2'),3);
- }else{
- $this->error('上传失败');
- }
- }
- }else{
- $this->error('上传失败');
- }
- }
- }else{
- $this->error('上传失败');
- }
- }else{
- $this->error('上传失败');
- }
- }
- }
- }
|