//手机pdf文档生成用
public function phone_daochupdf(){
$data=request()->param(); //接收post,get值
//引用类库
vendor("PHPPdf.tcpdf");
// New Word Document
$pdf = new \Tcpdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// 设置打印模式
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// 是否显示页眉
$pdf->setPrintHeader(false);
// 设置页眉显示的内容
$pdf->SetHeaderData('logo.png', 60, 'baijunyao.com', '白俊遥博客', array(0,64,255), array(0,64,128));
// 设置页眉字体
$pdf->setHeaderFont(Array('dejavusans', '', '12'));
// 页眉距离顶部的距离
$pdf->SetHeaderMargin('5');
// 是否显示页脚
$pdf->setPrintFooter(true);
// 设置页脚显示的内容
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// 设置页脚的字体
$pdf->setFooterFont(Array('dejavusans', '', '10'));
// 设置页脚距离底部的距离
$pdf->SetFooterMargin('10');
// 设置默认等宽字体
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// 设置行高
$pdf->setCellHeightRatio(1);
// 设置左、上、右的间距
$pdf->SetMargins('10', '10', '10');
// 设置是否自动分页 距离底部多少距离时分页
$pdf->SetAutoPageBreak(TRUE, '15');
// 设置图像比例因子
// $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
// require_once(dirname(__FILE__).'/lang/eng.php');
// $pdf->setLanguageArray($l);
// }
$pdf->setFontSubsetting(true);
$pdf->AddPage();
// 设置字体
$pdf->SetFont('stsongstdlight', '', 14, '', true);
//开始查询数据
$qiye = Db::name('enterprise')->field('id,name')->where('uid', $data['uid']);
//时间
/*if(!empty($data['startTime'])&&!empty($data['endTime'])){
$startTime=$data['startTime'].'00:00:00';
$endTime=$data['endTime'].'23:59:59';
$qiye->whereTime('create_time', 'between', [$startTime,$endTime]);
}*/
//按公司id
if(!empty($data['enterpriseid'])){
$qiye->where('id',$data['enterpriseid']);
}
//完整查询方法
$qiye=$qiye->select();
$qiyemum=count($qiye); //计算企业数
$num=0; //初始化隐患总数
$save_num=0; //初始化整改隐患总数
//是否按归档
if(!empty($data['add_num'])){
foreach($qiye as $key=>&$val){
$val['num']=Db::name('enterprise_detail')->where('add_num','in',$data['add_num'])->where('enterprise_id',$val['id'])->count();
$num+= (int) ($val['num']); //计算隐患总数
$val['save_num']=Db::name('enterprise_detail')->where('add_num','in',$data['add_num'])->where('enterprise_id',$val['id'])->where('save_status',1)->count();
$save_num+= (int) ($val['save_num']); //计算隐患总数
}
}else{
foreach($qiye as $key=>&$val){
$val['num']=Db::name('enterprise_detail')->where('enterprise_id',$val['id'])->count();
$num+= (int) ($val['num']); //计算隐患总数
$val['save_num']=Db::name('enterprise_detail')->where('enterprise_id',$val['id'])->where('save_status',1)->count();
$save_num+= (int) ($val['save_num']); //计算隐患总数
}
}
//获取检查人名称
$name = Db::name('ucenter_member')->where('id', $data['uid'])->value('username');
$date=date('Y年m月d日',time());
// Set some content to print
$html = <<<EOD
<br/>
<br/>
<br/>
<br/>
<h3 style="text-align:center;font-size:30px;">{$qiye[0]['name']}</h3>
<br/>
<br/>
<br/>
<h2 style="text-align:center;font-size:40px;">隐患排查报告</h2>
<br/>
<p> </p>
<br/>
<p> </p>
<br/>
<p> </p>
<br/>
<p> </p>
<br/>
<p> </p>
<br/>
<p> </p>
<br/>
<p> </p>
<br/>
<h4 style="text-align:center;margin:300px;font-size:18px;">北京百世寰宇注册安全工程师事务所有限责任公司</h4>
<p style="text-align:center;font-size:18px;">{$date}</p>
EOD;
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->AddPage();
$htm2 = <<<EOD
<p>{$name}检查情况如下:</p>
<p>{$name}共检查企业{$qiyemum}家,发现隐患{$num}条,已整改隐患{$save_num}条</p>
<h3 style="text-align:center">检查企业名录</h3>
EOD;
$pdf->writeHTML($htm2, true, false, true, false, '');
$pdf->SetFillColor(255, 255, 255);
$pdf->SetTextColor(0,0,0);
$pdf->SetDrawColor(0, 0, 0);
$pdf->SetLineWidth(0.3);
$pdf->SetFont('', 'B');
$pdf->Cell(15,10,'序号',1,0,'C', 1);
$pdf->Cell(134,10,'企业名称',1,0,'C', 1);
$pdf->Cell(20,10,'隐患总数',1,0,'C', 1);
$pdf->Cell(20,10,'已整改数',1,0,'C', 1);
foreach($qiye as $kk=>&$vv){
$pdf->Ln();
$pdf->Cell(15,20,$kk+1,1,0,'C', 1);
$pdf->Cell(134,20,$vv['name'],1,0,'C', 1);
$pdf->Cell(20,20,$vv['num'],1,0,'C', 1);
$pdf->Cell(20,20,$vv['save_num'],1,0,'C', 1);
}
$pdf->Ln();
$pdf->Cell(15,10,$num+1,1,0,'C', 1);
$pdf->Cell(134,10,'总数',1,0,'C', 1);
$pdf->Cell(20,10,$num,1,0,'C', 1);
$pdf->Cell(20,10,$save_num,1,0,'C', 1);
$pdf->AddPage();
$filename=$name.'隐患排查报告'; //定义文件名
//按公司id
if(!empty($data['enterpriseid'])){
$filename=Db::name('enterprise')->where('id',$data['enterpriseid'])->value('name');
}
//查询处理要导出的数据
$info=Db::view('ucenter_member','username')
->view('enterprise','id,name,type as enterprise_type,create_time','enterprise.uid=ucenter_member.id')
->view('enterprise_type','title as enterprise_type','enterprise_type.id=enterprise.type')
->view('enterprise_detail','enterprise_id,course_id,picture,brief,level,save_picture,save_brief,uid','enterprise_detail.enterprise_id=enterprise.id')
->view('course','order,title,course_type,level,introduction','course.id=enterprise_detail.course_id')
->view('course_type','title as course_type','course_type.id=course.course_type')
->where('ucenter_member.type',1); //备注:与后台的区别之处 去掉测试人员的数据 只输出制定类型检查人的数据
//按归档 0未归档 1第一次检查 2... 依次类推
if(!empty($data['add_num'])){
$info->where('enterprise_detail.add_num','in',$data['add_num']);
}
//按公司
if(!empty($data['enterpriseid'])){
$info->where('enterprise_detail.enterprise_id',$data['enterpriseid']);
}
//1已整改 0未整改
if(!empty($data['save_status'])){
$info->where('enterprise_detail.save_status',$data['save_status']);
}
//完成查询
$info=$info->where('enterprise_detail.uid',$data['uid'])->order('enterprise.create_time asc')->select();
foreach($info as $k=>&$value) {
if(strlen($value['name'])>90){
$value['name']=substr($value['name'],0,90);
}
//生成单元格开始
if($k>0){
$pdf->Ln();
}
$pdf->setCellHeightRatio(1.5);
$pdf->Cell(189,10,($k+1).'.企业名称:'.$value['name'],1,0,'L', 1);
$pdf->Ln();
$pdf->Cell(63,10,'检查人:'.$value['username'].'组',1,0,'L', 1);
$pdf->Cell(63,10,'类型:'.$value['enterprise_type'],1,0,'L', 1);
$value['create_time']=substr($value['create_time'],0,-8);
$pdf->Cell(63,10,'检查时间:'.$value['create_time'],1,0,'L', 1);
$pdf->Ln();
$pdf->MultiCell(189,15,'法规依据:'.$value['introduction'],1,'L', 1, 0);
$pdf->Ln();
$pdf->MultiCell(94.5, 15, '隐患描述:'.$value['brief'], 1, 'L', 1, 0, '', '', true);
if(!empty($value['save_brief'])){
$pdf->MultiCell(94.5, 15, '整改描述:'.$value['save_brief'], 1, 'L', 0, 1, '', '', true);
}else{
$pdf->MultiCell(94.5, 15, '整改描述:未整改', 1, 'L', 0, 1, '', '', true);
}
$w=94.5;
$h=85;
if(!empty($value['picture'])){
$value['picture']=strstr($value['picture'], 'uploads');
}else{
$value['picture']='uploads/enterprise/wutupian.png';
}
$pdf->Image('./'.$value['picture'], '', '', $w, $h, '', '', 'T', false, 300, '', false, false, 1, false, false, false);
if(!empty($value['save_picture'])){
$value['save_picture']=strstr($value['save_picture'], 'uploads');
$pdf->Image('./'.$value['save_picture'], '', '', $w, $h, '', '', 'T', false, 300, '', false, false, 1, false, false, false);
}else{
$pdf->Image('uploads/enterprise/wutupian.png', '', '', $w, $h, '', '', '', false, 300, '', false, false, 1, false, false, false);
}
}
//生成文件名
$filename= $filename.".pdf";
$pdf->Output($filename, 'D');
exit;
}