Commit 79bc9cea by 杨树贤

合同打印

parent 8c682527
......@@ -10,6 +10,8 @@ use App\Model\SupplierExtendModel;
use App\Model\SupplierContractModel;
use App\Http\Transformers\SupplierContractTransformer;
use App\Http\Controllers\Filter\SupplierContractFilter;
use App\Model\SupplierChannelModel;
use App\Model\SupplierReceiptModel;
class SupplierContractService
{
......@@ -112,17 +114,57 @@ class SupplierContractService
//生成合同pdf
public function createSupplierContractPdf($data)
{
$pdf = app('dompdf.wrapper');
$pdf->loadView('web.SaveSupplierContract', $data);
$fileName = 'contract_' . time() . '.pdf';
$content = $pdf->output();
$file = tmpfile();
fwrite($file, $content);
$path = stream_get_meta_data($file)['uri'];
$uploadFile = new \Illuminate\Http\UploadedFile($path, $fileName, 'application/pdf');
$result = (new UploadService())->uploadFile($uploadFile);
fclose($file);
//获取需要填入的信息
$supplier = SupplierChannelModel::where('supplier_id', $data['supplier_id'])->first()->toArray();
$receipt = SupplierReceiptModel::where('supplier_id', $data['supplier_id'])->first();
if (empty($receipt)) {
return ['code' => 1, 'msg' => '找不到银行信息'];
}
$receipt = $receipt->toArray();
$data['receipt'] = $receipt;
$data['supplier'] = $supplier;
try {
$pdf = app('dompdf.wrapper');
// 设置中文字体
$pdf->setOptions([
'defaultFont' => 'simsunb', // 默认使用宋体
'isHtml5ParserEnabled' => true,
'isPhpEnabled' => true,
'isFontSubsettingEnabled' => true,
'defaultPaperSize' => 'a4',
// 'fontHeightRatio' => 1,
'isRemoteEnabled' => true,
'fontDir' => storage_path('fonts'), // 设置字体目录为storage/fonts
'fontCache' => storage_path('fonts'), // 设置字体缓存目录为storage/fonts
'chroot' => public_path(), // 设置根目录为public目录
]);
$pdf->setPaper('a4', 'portrait');
// 使用 utf-8 编码加载 HTML
$html = view('pdf.supplier_contract', $data)->render();
$html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
$pdf->loadHtml($html);
$pdf->setPaper('A4', 'portrait');
$pdf->setWarnings(false);
$fileName = 'contract_' . time() . '.pdf';
$content = $pdf->output();
$file = tmpfile();
fwrite($file, $content);
$path = stream_get_meta_data($file)['uri'];
$uploadFile = new \Illuminate\Http\UploadedFile($path, $fileName, 'application/pdf');
$result = (new UploadService())->uploadFile($uploadFile);
fclose($file);
} catch (\Exception $e) {
dd($e->getFile() . ' ' . $e->getLine() . ' ' . $e->getMessage());
dd(json_encode($e->getMessage()));
return ['code' => 1, 'msg' => '生成合同失败'];
}
return $result;
}
......
The file could not be displayed because it is too large.
The file could not be displayed because it is too large.
......@@ -49,8 +49,10 @@
type: 'POST',
data: data.field,
success: function(res) {
layer.close(loadIndex);
res = JSON.parse(res);
if (res.err_code == 0) {
layer.close(loadIndex);
layer.msg(res.err_msg, {
icon: 6
});
......
The file could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
<?php return array (
'sans-serif' => array(
'normal' => $rootDir . '/lib/fonts/Helvetica',
'bold' => $rootDir . '/lib/fonts/Helvetica-Bold',
'italic' => $rootDir . '/lib/fonts/Helvetica-Oblique',
'bold_italic' => $rootDir . '/lib/fonts/Helvetica-BoldOblique',
),
'times' => array(
'normal' => $rootDir . '/lib/fonts/Times-Roman',
'bold' => $rootDir . '/lib/fonts/Times-Bold',
'italic' => $rootDir . '/lib/fonts/Times-Italic',
'bold_italic' => $rootDir . '/lib/fonts/Times-BoldItalic',
),
'times-roman' => array(
'normal' => $rootDir . '/lib/fonts/Times-Roman',
'bold' => $rootDir . '/lib/fonts/Times-Bold',
'italic' => $rootDir . '/lib/fonts/Times-Italic',
'bold_italic' => $rootDir . '/lib/fonts/Times-BoldItalic',
),
'courier' => array(
'normal' => $rootDir . '/lib/fonts/Courier',
'bold' => $rootDir . '/lib/fonts/Courier-Bold',
'italic' => $rootDir . '/lib/fonts/Courier-Oblique',
'bold_italic' => $rootDir . '/lib/fonts/Courier-BoldOblique',
),
'helvetica' => array(
'normal' => $rootDir . '/lib/fonts/Helvetica',
'bold' => $rootDir . '/lib/fonts/Helvetica-Bold',
'italic' => $rootDir . '/lib/fonts/Helvetica-Oblique',
'bold_italic' => $rootDir . '/lib/fonts/Helvetica-BoldOblique',
),
'zapfdingbats' => array(
'normal' => $rootDir . '/lib/fonts/ZapfDingbats',
'bold' => $rootDir . '/lib/fonts/ZapfDingbats',
'italic' => $rootDir . '/lib/fonts/ZapfDingbats',
'bold_italic' => $rootDir . '/lib/fonts/ZapfDingbats',
),
'symbol' => array(
'normal' => $rootDir . '/lib/fonts/Symbol',
'bold' => $rootDir . '/lib/fonts/Symbol',
'italic' => $rootDir . '/lib/fonts/Symbol',
'bold_italic' => $rootDir . '/lib/fonts/Symbol',
),
'serif' => array(
'normal' => $rootDir . '/lib/fonts/Times-Roman',
'bold' => $rootDir . '/lib/fonts/Times-Bold',
'italic' => $rootDir . '/lib/fonts/Times-Italic',
'bold_italic' => $rootDir . '/lib/fonts/Times-BoldItalic',
),
'monospace' => array(
'normal' => $rootDir . '/lib/fonts/Courier',
'bold' => $rootDir . '/lib/fonts/Courier-Bold',
'italic' => $rootDir . '/lib/fonts/Courier-Oblique',
'bold_italic' => $rootDir . '/lib/fonts/Courier-BoldOblique',
),
'fixed' => array(
'normal' => $rootDir . '/lib/fonts/Courier',
'bold' => $rootDir . '/lib/fonts/Courier-Bold',
'italic' => $rootDir . '/lib/fonts/Courier-Oblique',
'bold_italic' => $rootDir . '/lib/fonts/Courier-BoldOblique',
),
'dejavu sans' => array(
'bold' => $rootDir . '/lib/fonts/DejaVuSans-Bold',
'bold_italic' => $rootDir . '/lib/fonts/DejaVuSans-BoldOblique',
'italic' => $rootDir . '/lib/fonts/DejaVuSans-Oblique',
'normal' => $rootDir . '/lib/fonts/DejaVuSans',
),
'dejavu sans mono' => array(
'bold' => $rootDir . '/lib/fonts/DejaVuSansMono-Bold',
'bold_italic' => $rootDir . '/lib/fonts/DejaVuSansMono-BoldOblique',
'italic' => $rootDir . '/lib/fonts/DejaVuSansMono-Oblique',
'normal' => $rootDir . '/lib/fonts/DejaVuSansMono',
),
'dejavu serif' => array(
'bold' => $rootDir . '/lib/fonts/DejaVuSerif-Bold',
'bold_italic' => $rootDir . '/lib/fonts/DejaVuSerif-BoldItalic',
'italic' => $rootDir . '/lib/fonts/DejaVuSerif-Italic',
'normal' => $rootDir . '/lib/fonts/DejaVuSerif',
),
'simsunb' => array(
'bold' => $fontDir . '//edb1b9251441098783269e3e00205d6d',
),
'simsun' => array(
'normal' => $fontDir . '/2abc2a72a60d4b06c7a1f04f4e78146b',
),
) ?>
\ No newline at end of file
The file could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment