Jiancepdf.php 6.0 KB

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