PhysicalExaminationController.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. include '../Common/function.php';
  5. class PhysicalExaminationController extends ComController {
  6. public function index(){
  7. $data =I();
  8. $company_code=$data['companyid'];
  9. $res=M()->query("select * from sp_owner where company=".$company_code);
  10. $company_data=M()->query("select owner_name,owner_address,create_time from sp_owner_company where owner_id=".$company_code);
  11. $time=date("Y-m-d");
  12. $time2=date("Y年m月");
  13. $time1=date("Y-m-d H:s:i");
  14. $physical_examination_data=M()->query("select * from sp_physical_examination where company_code='".$company_code."' and time like'%".$time."%'");
  15. $yc_device1="";
  16. $sj_device1="";
  17. $yg_device1="";
  18. $xfs_device1="";
  19. $yw_device1="";
  20. $rtu_device1="";
  21. $dqhz_device1="";
  22. $spjc_device1="";
  23. $dtjc_device1="";
  24. $jgjc_device1="";
  25. $dcjc_device1="";
  26. $mcjs_device1="";
  27. $krqt_device1="";
  28. foreach ($res as $val) {
  29. if ($val['dwtype']==1){
  30. $yc_device1.="'".$val['owner_code']."',";
  31. }else if ($val['dwtype']==2){
  32. $sj_device1.="'".$val['owner_code']."',";
  33. }else if ($val['dwtype']==3){
  34. $yg_device1.="'".$val['owner_code']."',";
  35. }else if ($val['dwtype']==4){
  36. $xfs_device1.="'".$val['owner_code']."',";
  37. }else if ($val['dwtype']==5){
  38. $yw_device1.="'".$val['owner_code']."',";
  39. }else if ($val['dwtype']==6){
  40. $rtu_device1.="'".$val['owner_code']."',";
  41. }else if ($val['dwtype']==7){
  42. $dqhz_device1.="'".$val['owner_code']."',";
  43. }else if ($val['dwtype']==16){
  44. $spjc_device1.="'".$val['owner_code']."',";
  45. }else if ($val['dwtype']==17){
  46. $dtjc_device1.="'".$val['owner_code']."',";
  47. }else if ($val['dwtype']==128){
  48. $jgjc_device1.="'".$val['owner_code']."',";
  49. }else if ($val['dwtype']==129){
  50. $dcjc_device1.="'".$val['owner_code']."',";
  51. }else if ($val['dwtype']==130){
  52. $mcjs_device1.="'".$val['owner_code']."',";
  53. }else if ($val['dwtype']==131){
  54. $krqt_device1.="'".$val['owner_code']."',";
  55. }
  56. }
  57. if (!empty($yc_device1)){
  58. $yc_device = substr($yc_device1,0,strlen($yc_device1)-1);
  59. $yc_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yc_device.")");
  60. $yc_count=$yc_data[0]['a'];
  61. $ycl_yc_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yc_device.") and clzt=1");
  62. $ycl_yc_count=$ycl_yc_data[0]['a'];
  63. $zb_yc=$ycl_yc_count/$yc_count*100;
  64. if ($zb_yc>=80){
  65. $zb_yc1=1;
  66. }else if ($zb_yc==0){
  67. $zb_yc1=3;
  68. }else{
  69. $zb_yc1=0;
  70. }
  71. }else{
  72. $yc_count=0;
  73. $zb_yc1=2;
  74. }
  75. if (!empty($sj_device1)){
  76. $sj_device = substr($sj_device1,0,strlen($sj_device1)-1);
  77. $sj_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$sj_device.")");
  78. $sj_count=$sj_data[0]['a'];
  79. $ycl_sj_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$sj_device.") and clzt=1");
  80. $ycl_sj_count=$ycl_sj_data[0]['a'];
  81. $zb_sj=$ycl_sj_count/$sj_count*100;
  82. // print_r($zb_sj);
  83. if ($zb_sj>=80){
  84. $zb_sj1=1;
  85. }else if ($zb_sj==0){
  86. $zb_sj1=3;
  87. }else{
  88. $zb_sj1=0;
  89. }
  90. }else{
  91. $sj_count=0;
  92. $zb_sj1=2;
  93. }
  94. if (!empty($yg_device1)){
  95. $yg_device = substr($yg_device1,0,strlen($yg_device1)-1);
  96. $yg_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yg_device.")");
  97. $yg_count=$yg_data[0]['a'];
  98. $ycl_yg_data=M()->query("select count(id) as a from sp_hj2017 where device_code in (".$yg_device.") and clzt=1");
  99. $ycl_yg_count=$ycl_yg_data[0]['a'];
  100. $zb_yg=$ycl_yg_count/$yg_count*100;
  101. if ($zb_yg>=80){
  102. $zb_yg1=1;
  103. }else if ($zb_yg==0){
  104. $zb_yg1=3;
  105. }else{
  106. $zb_yg1=0;
  107. }
  108. }else{
  109. $yg_count=0;
  110. $zb_yg1=2;
  111. }
  112. if (!empty($xfs_device1)){
  113. $xfs_device = substr($xfs_device1,0,strlen($xfs_device1)-1);
  114. $xfs_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$xfs_device.")");
  115. $xfs_count=$xfs_data[0]['a'];
  116. $ycl_xfs_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$xfs_device.") and clzt=1");
  117. $ycl_xfs_count=$ycl_xfs_data[0]['a'];
  118. $zb_xfs=$ycl_xfs_count/$xfs_count*100;
  119. if ($zb_xfs>=80){
  120. $zb_xfs1=1;
  121. }else if ($zb_xfs==0){
  122. $zb_xfs1=3;
  123. }else{
  124. $zb_xfs1=0;
  125. }
  126. }else{
  127. $xfs_count=0;
  128. $zb_xfs1=2;
  129. }
  130. if (!empty($yw_device1)){
  131. $yw_device = substr($yw_device1,0,strlen($yw_device1)-1);
  132. $yw_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$yw_device.")");
  133. $yw_count=$yw_data[0]['a'];
  134. $ycl_yw_data=M()->query("select count(id) as a from sp_sj2017 where device_code in (".$yw_device.") and clzt=1");
  135. $ycl_yw_count=$ycl_yw_data[0]['a'];
  136. $zb_yw=$ycl_yw_count/$yw_count*100;
  137. if ($zb_yw>=80){
  138. $zb_yw1=1;
  139. }else if ($zb_yw==0){
  140. $zb_yw1=3;
  141. }else{
  142. $zb_yw1=0;
  143. }
  144. }else{
  145. $yw_count=0;
  146. $zb_yw1=2;
  147. }
  148. if (!empty($rtu_device1)){
  149. $rtu_device = substr($rtu_device1,0,strlen($rtu_device1)-1);
  150. $rtu_data=M()->query("select count(id) as a from sp_rtu2017 where device_code in (".$rtu_device.")");
  151. $rtu_count=$rtu_data[0]['a'];
  152. $ycl_rtu_data=M()->query("select count(id) as a from sp_rtu2017 where device_code in (".$rtu_device.") and clzt=1");
  153. $ycl_rtu_count=$ycl_rtu_data[0]['a'];
  154. $zb_rtu=$ycl_rtu_count/$rtu_count*100;
  155. if ($zb_rtu>=80){
  156. $zb_rtu1=1;
  157. }else if ($zb_rtu==0){
  158. $zb_rtu1=3;
  159. }else{
  160. $zb_rtu1=0;
  161. }
  162. }else{
  163. $rtu_count=0;
  164. $zb_rtu1=2;
  165. }
  166. if (!empty($dqhz_device1)){
  167. $dqhz_device = substr($dqhz_device1,0,strlen($dqhz_device1)-1);
  168. $dqhz_data=M()->query("select count(id) as a from sp_ef2017 where device_code in (".$dqhz_device.")");
  169. $dqhz_count=$dqhz_data[0]['a'];
  170. $ycl_dqhz_data=M()->query("select count(id) as a from sp_ef2017 where device_code in (".$dqhz_device.") and clzt=1");
  171. $ycl_dqhz_count=$ycl_dqhz_data[0]['a'];
  172. $zb_dqhz=$ycl_dqhz_count/$dqhz_count*100;
  173. if ($zb_dqhz>=80){
  174. $zb_dqhz1=1;
  175. }else if ($zb_dqhz==0){
  176. $zb_dqhz1=3;
  177. }else{
  178. $zb_dqhz1=0;
  179. }
  180. }else{
  181. $dqhz_count=0;
  182. $zb_dqhz1=2;
  183. }
  184. if (!empty($spjc_device1)){
  185. $spjc_device = substr($spjc_device1,0,strlen($spjc_device1)-1);
  186. $spjc_data=M()->query("select count(id) as a from sp_video2017 where device_code in (".$spjc_device.")");
  187. $spjc_count=$spjc_data[0]['a'];
  188. $ycl_spjc_data=M()->query("select count(id) as a from sp_video2017 where device_code in (".$spjc_device.") and clzt=1");
  189. $ycl_spjc_count=$ycl_spjc_data[0]['a'];
  190. $zb_spjc=$ycl_spjc_count/$spjc_count*100;
  191. if ($zb_spjc>=80){
  192. $zb_spjc1=1;
  193. }else if ($zb_spjc==0){
  194. $zb_spjc1=3;
  195. }else{
  196. $zb_spjc1=0;
  197. }
  198. }else{
  199. $spjc_count=0;
  200. $zb_spjc1=2;
  201. }
  202. if (!empty($dtjc_device1)){
  203. $dtjc_device = substr($dtjc_device1,0,strlen($dtjc_device1)-1);
  204. $dtjc_data=M()->query("select count(id) as a from sp_lifter2017 where device_code in (".$dtjc_device.")");
  205. $dtjc_count=$dtjc_data[0]['a'];
  206. $ycl_dtjc_data=M()->query("select count(id) as a from sp_lifter2017 where device_code in (".$dtjc_device.") and clzt=1");
  207. $ycl_dtjc_count=$ycl_dtjc_data[0]['a'];
  208. $zb_dtjc=$ycl_dtjc_count/$dtjc_count*100;
  209. if ($zb_dtjc>=80){
  210. $zb_dtjc1=1;
  211. }else if ($zb_dtjc==0){
  212. $zb_dtjc1=3;
  213. }else{
  214. $zb_dtjc1=0;
  215. }
  216. }else{
  217. $dtjc_count=0;
  218. $zb_dtjc1=2;
  219. }
  220. if (!empty($jgjc_device1)){
  221. $jgjc_device = substr($jgjc_device1,0,strlen($jgjc_device1)-1);
  222. $jgjc_data=M()->query("select count(id) as a from sp_iw2017 where device_code in (".$jgjc_device.")");
  223. $jgjc_count=$jgjc_data[0]['a'];
  224. $ycl_jgjc_data=M()->query("select count(id) as a from sp_iw2017 where device_code in (".$jgjc_device.") and clzt=1");
  225. $ycl_jgjc_count=$ycl_jgjc_data[0]['a'];
  226. $zb_jgjc=$ycl_jgjc_count/$jgjc_count*100;
  227. if ($zb_jgjc>=80){
  228. $zb_jgjc1=1;
  229. }else if ($zb_jgjc==0){
  230. $zb_jgjc1=3;
  231. }else{
  232. $zb_jgjc1=0;
  233. }
  234. }else{
  235. $jgjc_count=0;
  236. $zb_jgjc1=2;
  237. }
  238. if (!empty($dcjc_device1)){
  239. $dcjc_device = substr($dcjc_device1,0,strlen($dcjc_device1)-1);
  240. $dcjc_data=M()->query("select count(id) as a from sp_dc2020 where device_code in (".$dcjc_device.")");
  241. $dcjc_count=$dcjc_data[0]['a'];
  242. $ycl_dcjc_data=M()->query("select count(id) as a from sp_dc2020 where device_code in (".$dcjc_device.") and clzt=1");
  243. $ycl_dcjc_count=$ycl_dcjc_data[0]['a'];
  244. $zb_dcjc=$ycl_dcjc_count/$dcjc_count*100;
  245. if ($zb_dcjc>=80){
  246. $zb_dcjc1=1;
  247. }else if ($zb_dcjc==0){
  248. $zb_dcjc1=3;
  249. }else{
  250. $zb_dcjc1=0;
  251. }
  252. }else{
  253. $dcjc_count=0;
  254. $zb_dcjc1=2;
  255. }
  256. if (!empty($mcjs_device1)){
  257. $mcjs_device = substr($mcjs_device1,0,strlen($mcjs_device1)-1);
  258. $mcjs_data=M()->query("select count(id) as a from sp_door2020 where device_code in (".$mcjs_device.")");
  259. $mcjs_count=$mcjs_data[0]['a'];
  260. $ycl_mcjs_data=M()->query("select count(id) as a from sp_door2020 where device_code in (".$mcjs_device.") and clzt=1");
  261. $ycl_mcjs_count=$ycl_mcjs_data[0]['a'];
  262. $zb_mcjs=$ycl_mcjs_count/$mcjs_count*100;
  263. if ($zb_mcjs>=80){
  264. $zb_mcjs1=1;
  265. }else if ($zb_mcjs==0){
  266. $zb_mcjs1=3;
  267. }else{
  268. $zb_mcjs1=0;
  269. }
  270. }else{
  271. $mcjs_count=0;
  272. $zb_mcjs1=2;
  273. }
  274. if (!empty($krqt_device1)){
  275. $krqt_device = substr($krqt_device1,0,strlen($krqt_device1)-1);
  276. $krqt_data=M()->query("select count(id) as a from sp_gas2020 where device_code in (".$krqt_device.")");
  277. $krqt_count=$krqt_data[0]['a'];
  278. $ycl_krqt_data=M()->query("select count(id) as a from sp_gas2020 where device_code in (".$krqt_device.") and clzt=1");
  279. $ycl_krqt_count=$ycl_krqt_data[0]['a'];
  280. $zb_krqt=$ycl_krqt_count/$krqt_count*100;
  281. if ($zb_krqt>=80){
  282. $zb_krqt1=1;
  283. }else if ($zb_krqt==0){
  284. $zb_krqt1=3;
  285. }else{
  286. $zb_krqt1=0;
  287. }
  288. }else{
  289. $krqt_count=0;
  290. $zb_krqt1=2;
  291. }
  292. $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;
  293. if ($sy_count<180){
  294. $score=90;
  295. }else if ($sy_count>180&&$sy_count<300){
  296. $score=80;
  297. }else if ($sy_count>300){
  298. $score=60;
  299. }
  300. if (empty($physical_examination_data)){
  301. $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
  302. ('".$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."')";
  303. addInt($inset_sql);
  304. }else{
  305. $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.",
  306. 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'];
  307. addInt($update_sql);
  308. }
  309. $physical_examination_data1=M()->query("select * from sp_physical_examination where time like'%".$time."%'");
  310. $pm=1;
  311. foreach ($physical_examination_data1 as $key => $value){
  312. if ($sy_count>$physical_examination_data1[$key]['sy_count']){
  313. $pm+=1;
  314. }
  315. }
  316. $this->assign('pm',$pm);
  317. $this->assign('zb_yc1',$zb_yc1);
  318. $this->assign('zb_sj1',$zb_sj1);
  319. $this->assign('zb_yg1',$zb_yg1);
  320. $this->assign('zb_xfs1',$zb_xfs1);
  321. $this->assign('zb_yw1',$zb_yw1);
  322. $this->assign('zb_rtu1',$zb_rtu1);
  323. $this->assign('zb_dqhz1',$zb_dqhz1);
  324. $this->assign('zb_spjc1',$zb_spjc1);
  325. $this->assign('zb_dtjc1',$zb_dtjc1);
  326. $this->assign('zb_jgjc1',$zb_jgjc1);
  327. $this->assign('zb_dcjc1',$zb_dcjc1);
  328. $this->assign('zb_mcjs1',$zb_mcjs1);
  329. $this->assign('zb_krqt1',$zb_krqt1);
  330. $this->assign('yc_count',$yc_count);
  331. $this->assign('sj_count',$sj_count);
  332. $this->assign('yg_count',$yg_count);
  333. $this->assign('xfs_count',$xfs_count);
  334. $this->assign('yw_count',$yw_count);
  335. $this->assign('rtu_count',$rtu_count);
  336. $this->assign('dqhz_count',$dqhz_count);
  337. $this->assign('spjc_count',$spjc_count);
  338. $this->assign('dtjc_count',$dtjc_count);
  339. $this->assign('jgjc_count',$jgjc_count);
  340. $this->assign('dcjc_count',$dcjc_count);
  341. $this->assign('mcjs_count',$mcjs_count);
  342. $this->assign('krqt_count',$krqt_count);
  343. $this->assign('ycl_yc_count',$ycl_yc_count);
  344. $this->assign('ycl_sj_count',$ycl_sj_count);
  345. $this->assign('ycl_yg_count',$ycl_yg_count);
  346. $this->assign('ycl_xfs_count',$ycl_xfs_count);
  347. $this->assign('ycl_yw_count',$ycl_yw_count);
  348. $this->assign('ycl_rtu_count',$ycl_rtu_count);
  349. $this->assign('ycl_dqhz_count',$ycl_dqhz_count);
  350. $this->assign('ycl_spjc_count',$ycl_spjc_count);
  351. $this->assign('ycl_dtjc_count',$ycl_dtjc_count);
  352. $this->assign('ycl_jgjc_count',$ycl_jgjc_count);
  353. $this->assign('ycl_dcjc_count',$ycl_dcjc_count);
  354. $this->assign('ycl_mcjs_count',$ycl_mcjs_count);
  355. $this->assign('ycl_krqt_count',$ycl_krqt_count);
  356. $this->assign('sy_count',$sy_count);
  357. $this->assign('score',$score);
  358. $this->assign('time',$time2);
  359. $this->assign('company_code',$company_code);
  360. $this->assign('company_data',$company_data[0]);
  361. $this->display('Index/physical_examination');
  362. }
  363. }