Jiancepdf.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. namespace app\company\controller;
  3. use think\Controller;
  4. use think\Db;
  5. /**
  6. * 检测下发
  7. */
  8. class Jiancepdf extends Controller
  9. {
  10. //生成报告
  11. public function getpdf(){
  12. $title = '天津市建筑消防设施维护保养报告书';
  13. $this->assign('title',$title);
  14. //检测信息
  15. $id = input('id',0);
  16. $jiance = Db::name('jiance')->where('id',$id)->find();
  17. $this->assign('jiance',$jiance);
  18. //附属信息
  19. $company_id = $jiance['company_id'];
  20. $uc_id = $jiance['uc_id'];
  21. $worker_id = $jiance['worker_id'];
  22. $company = Db::name('company')->where('id',$company_id)->find();
  23. $user_company = Db::name('user_company')->where('id',$uc_id)->find();
  24. $worker = Db::name('worker')->where('id',$worker_id)->find();
  25. $user_info = Db::name('user')->where('id',$user_company['user_id'])->find();
  26. $this->assign('company',$company);
  27. $this->assign('user_company',$user_company);
  28. $this->assign('worker',$worker);
  29. $this->assign('user_info',$user_info);
  30. //TOP15 项目,附带勾选
  31. $top_project = Db::name('jiance_project')->field('id,title')
  32. ->where('company_id',$company_id)
  33. ->where('deletetime',NULL)
  34. ->where('pid',0)
  35. ->order('weigh asc,id asc')->select();
  36. foreach($top_project as $key => $project){
  37. $project['check'] = '□';
  38. if(in_array($project['id'],explode(',',$jiance['project_ids']))){
  39. $project['check'] = '■';
  40. }
  41. $top_project[$key] = $project;
  42. }
  43. $this->assign('top_project',$top_project);
  44. //所有不合格的
  45. $job_wrong = [];
  46. $joblog = Db::name('jiance_joblog')->alias('log')
  47. ->field('pt.title as top_title,p.type,p.title,worker.truename,log.*')
  48. ->join('jiance_project p','log.project_id = p.id','LEFT')
  49. ->join('jiance_project pt','p.pid = pt.id','LEFT')
  50. ->join('worker','log.worker_id = worker.id','LEFT')
  51. ->where('log.jiance_id',$id)->where('hege_status',2)
  52. ->select();
  53. foreach($joblog as $key => $job){
  54. $type = $job['type'] == 1 ? '技术要求' : '维护要求';
  55. $title = $job['top_title'] .'-'. $type .'-'. $job['title'];
  56. $info = '抽检位置:'.$job['weizhi'].',抽检数量:'. $job['number'] .',评判为不合格,检查结果是:'. $job['result'] .'。检查人'. $job['truename'];
  57. $job_wrong[] = [
  58. 'title' => $title,
  59. 'info' => $info,
  60. ];
  61. }
  62. $this->assign('job_wrong',$job_wrong);
  63. //组合大循环
  64. //所有最后一条记录的id
  65. $joblog_maxid = Db::name('jiance_joblog')->field('max(id) as logid')->where('jiance_id',$id)->group('project_id')->select();
  66. $joblog_ids = array_column($joblog_maxid,'logid');
  67. //所有最后一条记录
  68. $joblog = Db::name('jiance_joblog')->alias('log')
  69. ->field('worker.truename,log.*')
  70. ->join('worker','log.worker_id = worker.id','LEFT')
  71. ->where('log.jiance_id',$id)->where('log.id','IN',$joblog_ids)
  72. ->select();
  73. $joblog = list_domain_image($joblog,['images']);
  74. //所有项目
  75. $selected_project = Db::name('jiance_project')->field('id,pid,title,type,info,weigh')
  76. ->where('company_id',$company_id)
  77. ->where('deletetime',NULL)
  78. ->where('id','IN',$jiance['project_ids'])
  79. ->order('pid asc,type asc,weigh asc,id asc')->select();
  80. //循环处理
  81. $hege_status = [
  82. 1 => '符合',
  83. 2 => '不符合',
  84. 3 => '不适用'
  85. ];
  86. $panding = [
  87. 1 => [
  88. '■符合',
  89. '□不符合',
  90. '□不适用',
  91. ],
  92. 2 => [
  93. '□符合',
  94. '■不符合',
  95. '□不适用',
  96. ],
  97. 3 => [
  98. '□符合',
  99. '□不符合',
  100. '■不适用',
  101. ],
  102. ];
  103. $top = [];
  104. foreach($selected_project as $key => $val){
  105. //拿出来一级
  106. if($val['pid'] == 0){
  107. $top[] = $val;
  108. unset($selected_project[$key]);
  109. }else{
  110. $val['job'] = [
  111. 'remark' => '',
  112. 'panding' => [],
  113. 'images' => [],
  114. ];
  115. //组合最后一条记录
  116. foreach($joblog as $job){
  117. if($val['id'] == $job['project_id']){
  118. $hege = isset($hege_status[$job['hege_status']]) ? $hege_status[$job['hege_status']] : $job['hege_status'];
  119. $job['remark'] = '位置:'.$job['weizhi'].',数量:'. $job['number'] .',评判:'. $hege .',检查结果:'. $job['result'] .'。检查人'. $job['truename'];
  120. $job['panding'] = isset($panding[$job['hege_status']]) ? $panding[$job['hege_status']] : $job['hege_status'];
  121. $job['images'] = explode(',',$job['images']);
  122. $val['job'] = $job;
  123. }
  124. }
  125. }
  126. $selected_project[$key] = $val;
  127. }
  128. //数据结构排序,二级结构,不需要tree
  129. foreach($top as $tk => $tv){
  130. $tv['child_type1'] = [];
  131. $tv['child_type2'] = [];
  132. foreach($selected_project as $key => $val){
  133. if($val['pid'] == $tv['id']){
  134. if($val['type'] == 1){
  135. $tv['child_type1'][] = $val;
  136. }else{
  137. $tv['child_type2'][] = $val;
  138. }
  139. }
  140. }
  141. $top[$tk] = $tv;
  142. }
  143. $this->assign('top',$top);
  144. // dump($top);
  145. return $this->view->fetch();
  146. }
  147. /*private function getimages_html($images){
  148. $result = [];
  149. $images = explode(',',$images);
  150. if(!empty($images)){
  151. foreach($images as $img){
  152. $result[] = '<img src="'.$img.'" width="50" height="50" />';
  153. }
  154. }
  155. }*/
  156. }