add-admin-down_file
This commit is contained in:
@@ -971,4 +971,86 @@ class Orders extends HD_Controller
|
||||
}
|
||||
return $this->show_view('receiver/orderv2/edit_status');
|
||||
}
|
||||
//下载pdf
|
||||
public function get_down(){
|
||||
require_once COMMPATH.'/third_party/TCPDF/tcpdf.php';
|
||||
$id = $this->input->get('id');
|
||||
$row = $this->receiver_orders_v2_model->get(['id'=>$id],'id,sid,owner_mobile,owner_name');
|
||||
$contract = $this->order_contracts_model->get(['o_id'=>$row['id'],'type'=>0],'id,o_id,file,imgs,type');
|
||||
if(!$row || !$contract){
|
||||
return false;
|
||||
}
|
||||
$type_arr = [0=>'汽车购车协议',1=>'委托服务协议',2=>'车辆确定',3=>'车辆交付'];
|
||||
$old_type_arr = [0=>'整车合同',1=>'委托服务协议',2=>'车辆确定',3=>'交车信息',4=>'车辆买卖合同补充协议',5=>'委托服务补充协议'];
|
||||
$path = FCPATH."pdf/{$row['owner_name']}";
|
||||
$row['owner_mobile'] && $path .= "({$row['owner_mobile']})";
|
||||
if($contract['o_id']>=10000){
|
||||
$file_name = $type_arr[$contract['type']] ? $type_arr[$contract['type']].'.pdf' : '其它_'.time().'.pdf';
|
||||
}else{
|
||||
$file_name = $old_type_arr[$contract['type']] ? $old_type_arr[$contract['type']].'.pdf' : '其它_'.time().'.pdf';
|
||||
}
|
||||
$file=$path.'/'.$file_name;
|
||||
if(!file_exists($file)){
|
||||
$imgs = json_decode($contract['imgs'],true);
|
||||
if(!$imgs){
|
||||
file_get_contents("https://api.liche.cn/wxapp/licheb/protocol/pdf_img?id={$contract['id']}");
|
||||
$contract = $this->order_contracts_model->get(['o_id'=>$row['o_id'],'type'=>0],'id,o_id,file,imgs,type');
|
||||
$imgs = json_decode($contract['imgs'],true);
|
||||
}
|
||||
if (!file_exists($path)) {
|
||||
$oldumask = umask(0);
|
||||
mkdir($path, 0777, true);
|
||||
umask($oldumask);
|
||||
}
|
||||
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,true, 'UTF-8', false);
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
//删除预定义的打印 页眉/页尾
|
||||
$pdf->setPrintHeader(false);
|
||||
$pdf->setPrintFooter(false);
|
||||
//设置默认等宽字体
|
||||
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
||||
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
||||
$pdf->SetFont('stsongstdlight', '', 20);
|
||||
$pdf->AddPage();
|
||||
$options = array(
|
||||
// 解决SSL证书验证失败的问题
|
||||
"ssl"=>array(
|
||||
"verify_peer"=>false,
|
||||
"verify_peer_name"=>false,
|
||||
)
|
||||
);
|
||||
//设置文件信息
|
||||
foreach ($imgs as $item) {
|
||||
$img_url = build_qiniu_image_url($item);
|
||||
$res = file_get_contents($img_url,false, stream_context_create($options));
|
||||
$pdf->Ln();
|
||||
$pdf->Image('@'.$res, '', '', '', '', '', $img_url,'' , false, 300, '', false, false, 0.05, false, false, false);
|
||||
}
|
||||
|
||||
$pdf->Output( $file,'F');
|
||||
}
|
||||
ob_end_clean();
|
||||
//检查文件是否存在于目录
|
||||
if (!file_exists ($file)) {
|
||||
header('HTTP/1.1 404 NOT FOUND');
|
||||
} else {
|
||||
ob_end_clean();
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
//请求范围的度量单位
|
||||
Header ( "Accept-Ranges: bytes" );
|
||||
//下载后的文件名称为$file_name
|
||||
header('Content-Disposition: attachment; filename='.$file_name);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
#Expires:设置页面缓存时间
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: no cache');
|
||||
//Content-Length是指定包含于请求或响应中数据的字节长度
|
||||
header('Content-Length: ' . filesize($file));
|
||||
ob_clean(); flush();
|
||||
readfile($file);
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +228,11 @@
|
||||
车辆交付
|
||||
</a><br>
|
||||
</div>
|
||||
<div class="am-form-group" v-if="info.contract_data[0]">
|
||||
<a :href="'/receiver/orderv2/orders/get_down?id='+info.id" target="_blank" class="am-btn am-btn-primary am-btn-sm">
|
||||
下载汽车购车协议
|
||||
</a><br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user