assign('title',$title); //检测信息 $id = input('id',0); $jiance = Db::name('jiance')->where('id',$id)->find(); if(empty($jiance)){ exit; } $this->assign('jiance',$jiance); //附属信息 $company_id = $jiance['company_id']; $uc_id = $jiance['uc_id']; $worker_id = $jiance['worker_id']; $company = Db::name('company')->where('id',$company_id)->find(); $user_company = Db::name('user_company')->where('id',$uc_id)->find(); $worker = Db::name('worker')->where('id',$worker_id)->find(); $user_info = Db::name('user')->where('id',$user_company['user_id'])->find(); $this->assign('company',$company); $this->assign('user_company',$user_company); $this->assign('worker',$worker); $this->assign('user_info',$user_info); //TOP15 项目,附带勾选 $top_project = Db::name('jiance_project')->field('id,title') ->where('company_id',$company_id) ->where('deletetime',NULL) ->where('pid',0) ->order('weigh asc,id asc')->select(); foreach($top_project as $key => $project){ $project['check'] = '□'; if(in_array($project['id'],explode(',',$jiance['project_ids']))){ $project['check'] = '■'; } $top_project[$key] = $project; } $this->assign('top_project',$top_project); //所有不合格的 $job_wrong = []; $joblog = Db::name('jiance_joblog')->alias('log') ->field('pt.title as top_title,p.type,p.title,worker.truename,log.*') ->join('jiance_project p','log.project_id = p.id','LEFT') ->join('jiance_project pt','p.pid = pt.id','LEFT') ->join('worker','log.worker_id = worker.id','LEFT') ->where('log.jiance_id',$id)->where('hege_status',2) ->select(); foreach($joblog as $key => $job){ $type = $job['type'] == 1 ? '技术要求' : '维护要求'; $title = $job['top_title'] .'--'. $type .'--'. $job['title']; $info = '抽检位置:'.$job['weizhi'].',抽检数量:'. $job['number'] .',评判为不合格,检查结果是:'. $job['result'] .'。检查人:'. $job['truename']; $job_wrong[] = [ 'title' => $title, 'info' => $info, ]; } $this->assign('job_wrong',$job_wrong); //组合大循环 //所有最后一条记录的id $joblog_maxid = Db::name('jiance_joblog')->field('max(id) as logid')->where('jiance_id',$id)->group('project_id')->select(); $joblog_ids = array_column($joblog_maxid,'logid'); //所有最后一条记录 $joblog = Db::name('jiance_joblog')->alias('log') ->field('worker.truename,log.*') ->join('worker','log.worker_id = worker.id','LEFT') ->where('log.jiance_id',$id)->where('log.id','IN',$joblog_ids) ->select(); $joblog = list_domain_image($joblog,['images']); //所有项目 $selected_project = Db::name('jiance_project')->field('id,pid,title,type,info,weigh') ->where('company_id',$company_id) ->where('deletetime',NULL) ->where('id','IN',$jiance['project_ids']) ->order('pid asc,type asc,weigh asc,id asc')->select(); //循环处理 $hege_status = [ 1 => '符合', 2 => '不符合', 3 => '不适用' ]; $panding = [ 1 => [ '■符合', '□不符合', '□不适用', ], 2 => [ '□符合', '■不符合', '□不适用', ], 3 => [ '□符合', '□不符合', '■不适用', ], ]; $top = []; foreach($selected_project as $key => $val){ //拿出来一级 if($val['pid'] == 0){ $top[] = $val; unset($selected_project[$key]); }else{ $val['job'] = [ 'remark' => '', 'panding' => [], 'images' => [], ]; //组合最后一条记录 foreach($joblog as $job){ if($val['id'] == $job['project_id']){ $hege = isset($hege_status[$job['hege_status']]) ? $hege_status[$job['hege_status']] : $job['hege_status']; $job['remark'] = '位置:'.$job['weizhi'].',数量:'. $job['number'] .',评判:'. $hege .',检查结果:'. $job['result'] .'。检查人:'. $job['truename']; $job['panding'] = isset($panding[$job['hege_status']]) ? $panding[$job['hege_status']] : $job['hege_status']; $job['images'] = explode(',',$job['images']); $val['job'] = $job; } } } $selected_project[$key] = $val; } //数据结构排序,二级结构,不需要tree foreach($top as $tk => $tv){ $tv['child_type1'] = []; $tv['child_type2'] = []; foreach($selected_project as $key => $val){ if($val['pid'] == $tv['id']){ if($val['type'] == 1){ $tv['child_type1'][] = $val; }else{ $tv['child_type2'][] = $val; } } } $top[$tk] = $tv; } $this->assign('top',$top); // dump($top); return $this->view->fetch(); } }