ScanController.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: TianFeng
  5. * Date: 2019-03-18
  6. * Time: 15:38
  7. */
  8. namespace Home\Controller;
  9. use Think\Controller;
  10. include '../Common/function.php';
  11. class ScanController extends ComController {
  12. //巡检方法
  13. public function pdsflr(){
  14. $data=I('post.data');
  15. $jh_id=I('post.jh_id');
  16. $dw_id=I('post.dw_id');
  17. $sql1="select * from ytiot_xj_inspection_points where spot_label_analysis='".$data."' and id=". $dw_id." and data1='1'";
  18. // print_r($sql1);
  19. $res1=add($sql1);
  20. // print_r($res1);
  21. // exit();
  22. if(empty($res1)){
  23. echo 1;
  24. exit();
  25. }
  26. $res2=array();
  27. // $res2['ms']=2;
  28. $res2['jh_id']=$jh_id;
  29. $res2['dw_id']=$dw_id;
  30. if(!empty($res2)){
  31. echo json_encode($res2);
  32. exit();
  33. }
  34. }
  35. //维保方法
  36. public function pdsflr2(){
  37. $data=I('post.data');
  38. $jh_id=I('post.jh_id');
  39. $dw_id=I('post.dw_id');
  40. $sql1="select * from ytiot_xj_inspection_points where spot_label_analysis='".$data."' and id=". $dw_id." and data1='2'";
  41. // print_r($sql1);
  42. $res1=add($sql1);
  43. // print_r($res1);
  44. // exit();
  45. if(empty($res1)){
  46. echo 1;
  47. exit();
  48. }
  49. $res2=array();
  50. // $res2['ms']=2;
  51. $res2['jh_id']=$jh_id;
  52. $res2['dw_id']=$dw_id;
  53. if(!empty($res2)){
  54. echo json_encode($res2);
  55. exit();
  56. }
  57. }
  58. //巡检方法
  59. public function from(){
  60. $res1 =I();
  61. // print_r($res1);
  62. $this->assign('res1',$res1);
  63. $this->display('Index2/from');
  64. }
  65. //维保方法
  66. public function from2(){
  67. $res1 =I();
  68. $this->assign('res1',$res1);
  69. $this->display('Index2/wb_from');
  70. }
  71. //巡检方法
  72. public function xjd_inset(){
  73. $data=I();
  74. // print_r($data);
  75. // exit();
  76. $zb_id=$data['zb_id'];
  77. $spot_id=$data['spot_id'];
  78. $wbr_id=$data['wbr_id'];
  79. $spot_abnormal=$data['spot_abnormal'];
  80. // $company_code1=$data['company_code'];
  81. // print_r($spot_abnormal);
  82. // exit();
  83. $wc_time=date("Y-m-d H:i:s");
  84. $dwsb_remarks=$data['dwsb_remarks'];
  85. $data1=$data['data1'];
  86. // $data3=2;
  87. $people_id_sql=" select team_id,inspect_date,end_time,company_code,completion from ytiot_xj_plan_child where id=".$zb_id;
  88. $people_id_res=add($people_id_sql);
  89. if($people_id_res!=null){
  90. $people_id_sql1="select person_liable_id from ytiot_xj_plan_team where id=". $people_id_res[0]['team_id'];
  91. $people_id_res1=add($people_id_sql1);
  92. if ($people_id_res1!=null){
  93. $people_id = $people_id_res1[0]['person_liable_id'];
  94. }
  95. $ywc_time=$people_id_res[0]['inspect_date']." ".$people_id_res[0]['end_time'];
  96. $company_code=$people_id_res[0]['company_code'];
  97. }
  98. $tmpFilePath = $_FILES['img']['tmp_name'];
  99. if($_FILES["img"]["error"]==1){
  100. $this->success('图片上传失败,图片大小超过限制2M',U('Inspection/index'),3);
  101. }
  102. // print_r($_FILES["file"]);
  103. //确保我们有一个文件路径
  104. if ($tmpFilePath != ""){
  105. //设置我们的新文件路径
  106. $FileCode=date('YmdHis').rand(1000,9999);
  107. $FileName=$_FILES['img']['name'];
  108. $FileType=strtolower(substr(strrchr($FileName,'.'),1));
  109. $BasefName=$FileCode.'.'.$FileType;
  110. $newFilePath ='/var/www/html/jdxf/Maintinfo/image/'.$BasefName;
  111. $newFilePath1 ='https://qhome.usky.cn/jdxf/Maintinfo/image/'.$BasefName;
  112. // $newFilePath ='D://QrCode/'.$BasefName;
  113. //将文件上传到临时目录中
  114. // exit();
  115. // print_r("测试0".$tmpFilePath);
  116. // print_r("测试1".move_uploaded_file($tmpFilePath, $newFilePath));
  117. if(move_uploaded_file($tmpFilePath, $newFilePath)) {
  118. $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.
  119. " where zb_id=".$zb_id." and spot_id=".$spot_id;
  120. // $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(
  121. // $zb_id,$spot_id,$people_id,'$spot_abnormal','$ywc_time','$wc_time','$company_code','$dwsb_remarks','$data3')";
  122. $res1=addDataInfo($wb_sql);
  123. // print_r("测试2".$res1);
  124. if($res1){
  125. $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."'";
  126. $photosres=add($photosql);
  127. echo 1;
  128. if ($photosres!=null){
  129. // if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
  130. // $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,data1) value (".$photosres[0]['id'].",'".$photosres[0]['data1']."','".$data1."')";
  131. // $photos_res=addDataInfo($wxsb_sql);
  132. // }
  133. if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
  134. $company_data=M()->query("select owner_id from sp_owner_company where building_id='".$company_code."'");
  135. // $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."')";
  136. $wx_name='设备异常';
  137. $dqsj= date('Y-m-d h:i:s', time());
  138. $lsxx=$dqsj.",".$wx_name;
  139. // $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."')";
  140. $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."');";
  141. // print_r($wxsb_sql);
  142. $photos_res=addDataInfo($wxsb_sql);
  143. }
  144. $photo_sql="insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (".$photosres[0]['id'].",'".$newFilePath1."')";
  145. $photos_res=addDataInfo($photo_sql);
  146. if ($photos_res){
  147. $dwzsl_sql="select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id;
  148. // print_r('测试'.$dwzsl_sql);
  149. $dwzsl=add($dwzsl_sql);
  150. // print_r('测试'.$dwzsl);
  151. $yxjzsl_sql="select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id." and data3='2'";
  152. // print_r('测试'.$yxjzsl_sql);
  153. $yxjzsl=add($yxjzsl_sql);
  154. // print_r('测试'.$yxjzsl);
  155. if($dwzsl[0]['dwzsl']==$yxjzsl[0]['yxjzsl']){
  156. $wcqk_sql="update ytiot_xj_plan_child set completion=100,data3='".$wc_time."' where id=".$zb_id;
  157. $wcqk_res=addDataInfo($wcqk_sql);
  158. if ($wcqk_res){
  159. // echo "<script>window.history.go(-2);</script>";
  160. $this->success('保存成功',U('Inspection/index'),3);
  161. }else{
  162. $this->error('上传失败');
  163. }
  164. }else{
  165. $yg=1/$dwzsl[0]['dwzsl']*100;
  166. $completion=$people_id_res[0]['completion']+$yg;
  167. $wcqk_sql="update ytiot_xj_plan_child set completion=".$completion." where id=".$zb_id;
  168. $wcqk_res=addDataInfo($wcqk_sql);
  169. if ($wcqk_res){
  170. // echo "<script>window.history.go(-2);</script>";
  171. $this->success('保存成功',U('Inspection/index'),3);
  172. }else{
  173. $this->error('上传失败');
  174. }
  175. }
  176. }else{
  177. $this->error('上传失败');
  178. }
  179. }
  180. }else{
  181. $this->error('上传失败');
  182. }
  183. }else{
  184. // $this->success('上传失败,图片大小超过上限2M',U('Inspection/index'),3);
  185. $this->error('上传失败');
  186. }
  187. }
  188. }
  189. //维保方法
  190. public function xjd_inset2(){
  191. $data=I();
  192. // print_r($data);
  193. // exit();
  194. $zb_id=$data['zb_id'];
  195. $spot_id=$data['spot_id'];
  196. $wbr_id=$data['wbr_id'];
  197. $spot_abnormal=$data['spot_abnormal'];
  198. $wc_time=date("Y-m-d H:i:s");
  199. $dwsb_remarks=$data['dwsb_remarks'];
  200. $data1=$data['data1'];
  201. $company_code1=$data['company_code'];
  202. // $data3=2;
  203. $people_id_sql=" select team_id,inspect_date,end_time,company_code,completion from ytiot_xj_plan_child where id=".$zb_id;
  204. $people_id_res=add($people_id_sql);
  205. if($people_id_res!=null){
  206. $people_id_sql1="select person_liable_id from ytiot_xj_plan_team where id=". $people_id_res[0]['team_id'];
  207. $people_id_res1=add($people_id_sql1);
  208. if ($people_id_res1!=null){
  209. $people_id = $people_id_res1[0]['person_liable_id'];
  210. }
  211. $ywc_time=$people_id_res[0]['inspect_date']." ".$people_id_res[0]['end_time'];
  212. $company_code=$people_id_res[0]['company_code'];
  213. }
  214. $tmpFilePath = $_FILES['img']['tmp_name'];
  215. if($_FILES["img"]["error"]==1){
  216. $this->success('图片上传失败,图片大小超过限制2M',U('Inspection/index'),3);
  217. }
  218. //确保我们有一个文件路径
  219. if ($tmpFilePath != ""){
  220. //设置我们的新文件路径
  221. $FileCode=date('YmdHis').rand(1000,9999);
  222. $FileName=$_FILES['img']['name'];
  223. $FileType=strtolower(substr(strrchr($FileName,'.'),1));
  224. $BasefName=$FileCode.'.'.$FileType;
  225. $newFilePath ='/var/www/html/jdxf/Maintinfo/image/'.$BasefName;
  226. $newFilePath1 ='https://qhome.usky.cn/jdxf/Maintinfo/image/'.$BasefName;
  227. // $newFilePath ='D://QrCode/'.$BasefName;
  228. //将文件上传到临时目录中
  229. // exit();
  230. // print_r("测试0".$tmpFilePath);
  231. // print_r("测试1".$spot_id);
  232. if(move_uploaded_file($tmpFilePath, $newFilePath)) {
  233. $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.
  234. " where zb_id=".$zb_id." and spot_id=".$spot_id;
  235. // $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(
  236. // $zb_id,$spot_id,$people_id,'$spot_abnormal','$ywc_time','$wc_time','$company_code','$dwsb_remarks','$data3')";
  237. $res1=addDataInfo($wb_sql);
  238. // print_r("测试2".$res1);
  239. if($res1){
  240. $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."'";
  241. $photosres=add($photosql);
  242. if ($photosres!=null){
  243. // if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
  244. // $wxsb_sql="insert into ytiot_xj_event_processing(dwjl_id,user_name,data1) value (".$photosres[0]['id'].",'".$photosres[0]['data1']."','".$data1."')";
  245. // $photos_res=addDataInfo($wxsb_sql);
  246. // }
  247. if ($photosres[0]['spot_abnormal']==1 || $photosres[0]['spot_abnormal']==2 || $photosres[0]['spot_abnormal']==3){
  248. $company_data=M()->query("select owner_id from sp_owner_company where building_id='".$company_code."'");
  249. $wx_name='设备异常';
  250. $dqsj= date('Y-m-d h:i:s', time());
  251. $lsxx=$dqsj.",".$wx_name;
  252. // $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."')";
  253. $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."')";
  254. $photos_res=addDataInfo($wxsb_sql);
  255. }
  256. $photo_sql="insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (".$photosres[0]['id'].",'".$newFilePath1."')";
  257. $photos_res=addDataInfo($photo_sql);
  258. if ($photos_res){
  259. $dwzsl_sql="select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id;
  260. // print_r('测试'.$dwzsl_sql);
  261. $dwzsl=add($dwzsl_sql);
  262. // print_r('测试'.$dwzsl);
  263. $yxjzsl_sql="select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=".$zb_id." and data3='2'";
  264. // print_r('测试'.$yxjzsl_sql);
  265. $yxjzsl=add($yxjzsl_sql);
  266. // print_r('测试'.$yxjzsl);
  267. if($dwzsl[0]['dwzsl']==$yxjzsl[0]['yxjzsl']){
  268. $wcqk_sql="update ytiot_xj_plan_child set completion=100,data3='".$wc_time."' where id=".$zb_id;
  269. $wcqk_res=addDataInfo($wcqk_sql);
  270. if ($wcqk_res){
  271. // echo "<script>window.history.go(-2);</script>";
  272. $this->success('保存成功',U('Inspection/index2'),3);
  273. }else{
  274. $this->error('上传失败');
  275. }
  276. }else{
  277. $yg=1/$dwzsl[0]['dwzsl']*100;
  278. $completion=$people_id_res[0]['completion']+$yg;
  279. $wcqk_sql="update ytiot_xj_plan_child set completion=".$completion." where id=".$zb_id;
  280. $wcqk_res=addDataInfo($wcqk_sql);
  281. if ($wcqk_res){
  282. // echo "<script>window.history.go(-2);</script>";
  283. $this->success('保存成功',U('Inspection/index2'),3);
  284. }else{
  285. $this->error('上传失败');
  286. }
  287. }
  288. }else{
  289. $this->error('上传失败');
  290. }
  291. }
  292. }else{
  293. $this->error('上传失败');
  294. }
  295. }else{
  296. $this->error('上传失败');
  297. }
  298. }
  299. }
  300. }