Merge branch 'pdf' into dev

# Conflicts:
#	app/common/model/UsedCar.php
This commit is contained in:
2026-01-15 10:48:13 +08:00
9 changed files with 509 additions and 30 deletions
+138
View File
@@ -0,0 +1,138 @@
<?php
namespace app\common\utils;
use support\Log;
class XunfeiFanyi
{
protected $error = "";
public function tocurl($url, $header, $content)
{
$ch = curl_init();
if(substr($url,0,5)=='https'){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
if (is_array($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($ch, CURLOPT_POST, true);
if (!empty($content)) {
if (is_array($content)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
} else if (is_string($content)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
}
}
$response = curl_exec($ch);
$error=curl_error($ch);
//var_dump($error);
if($error){
die($error);
}
$header = curl_getinfo($ch);
curl_close($ch);
$data = array('header' => $header,'body' => $response);
return $data;
}
public function xfyun($text = "中华人民共和国于1949年成立", $from = "cn", $to = "en")
{
//在控制台-我的应用-机器翻译获取
$app_id = "3d46198c";
//在控制台-我的应用-机器翻译获取
$api_sec = "ZWY2MmUyNjJjYmFkOTFlYTVmYWVhMGYy";
//在控制台-我的应用-机器翻译获取
$api_key = "b6d805f240176ecaea85130cb5f2bca1";
// 机器翻译接口地址
$url = "https://ntrans.xfyun.cn/v2/ots";
//body组装
// $text = "中华人民共和国于1949年成立";//待翻译文本
$body = json_encode($this->getBody($app_id, $from, $to, $text));
// 组装http请求头
$date =gmdate('D, d M Y H:i:s') . ' GMT';
$digestBase64 = "SHA-256=".base64_encode(hash("sha256", $body, true));
$builder = sprintf("host: %s
date: %s
POST /v2/ots HTTP/1.1
digest: %s", "ntrans.xfyun.cn", $date, $digestBase64);
// echo($builder);
$sha = base64_encode(hash_hmac("sha256", $builder, $api_sec, true));
$authorization = sprintf("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", $api_key,"hmac-sha256",
"host date request-line digest", $sha);
$header = [
"Authorization: ".$authorization,
'Content-Type: application/json',
'Accept: application/json,version=1.0',
'Host: ntrans.xfyun.cn',
'Date: ' .$date,
'Digest: '.$digestBase64
];
$response = $this->tocurl($url, $header, $body);
// var_dump($response['body']);
return $response;
}
public function getBody($app_id, $from, $to, $text)
{
$common_param = [
'app_id' => $app_id
];
$business = [
'from' => $from,
'to' => $to,
];
$data = [
"text" => base64_encode($text)
];
return $body = [
'common' => $common_param,
'business' => $business,
'data' => $data
];
}
// 翻译
public function fanyi($text = "", $from = "", $to = "")
{
try {
$res = $this->xfyun($text, $from, $to);
$data = json_decode($res["body"], true);
if ($data["code"] === 0) {
return $data["data"]["result"];
} else {
$this->error = $data["message"];
Log::error("XunfeiFanyi 失败: ".$data["message"],[$data]);
return false;
}
} catch (\Throwable $th) {
$this->error = $th->getMessage();
Log::error("XunfeiFanyi 错误: ".$th->getMessage());
return false;
}
}
// 异常
public function error()
{
return $this->error;
}
}
+3 -3
View File
@@ -116,7 +116,7 @@ class MpdfDriver
return [$css, $html];
}
public function exportUsedCarPdf($car,$user,$contact)
public function exportUsedCarPdf($field,$car,$user,$contactField,$contact,$lang)
{
/*$car = [
'title' => '奥迪Q3 2013款 35 TFSI 舒适型',
@@ -157,7 +157,7 @@ class MpdfDriver
$mpdf->SetProtection(//限制篡改或盗用
['print'], // 允许的权限 copy:允许复制、print:允许打印
'', // 用户密码(可留空)
'Admin@2026@!#' // 拥有者密码(一定要设置)
$car['code'] // 拥有者密码(一定要设置)
);
//设置水印
@@ -186,7 +186,7 @@ class MpdfDriver
$pdf = $mpdf->Output('车辆详情.pdf', 'S');
$dir = runtime_path('pdf');
if (!is_dir($dir)) mkdir($dir, 0777, true);
$pdfName = 'invoice-' . date('YmdHis').'-'.$car['id'] . '.pdf';
$pdfName = 'invoice-' . date('YmdHis').'-'.$car['id'] . '-' . $lang . '.pdf';
$path = $dir . '/' . $pdfName;
file_put_contents($path, $pdf);
@@ -52,17 +52,17 @@
</head>
<body>
<h2>联系人名片</h2>
<h2><?= $contactField['title'] ?></h2>
<div class="card">
<?php if (!empty($user['name'])): ?>
<div class="row"><span class="label">姓名:</span><?= $user['name'] ?></div>
<div class="row"><span class="label"><?= $contactField['name'] ?>:</span><?= $user['name'] ?></div>
<?php endif; ?>
<?php if (!empty($user['email'])): ?>
<div class="row"><span class="label">邮箱:</span><?= $user['email'] ?></div>
<div class="row"><span class="label"><?= $contactField['name'] ?>:</span><?= $user['email'] ?></div>
<?php endif; ?>
<?php if (!empty($user['phone'])): ?>
<div class="row"><span class="label">电话:</span><?= $user['phone'] ?></div>
<div class="row"><span class="label"><?= $contactField['name'] ?>:</span><?= $user['phone'] ?></div>
<?php endif; ?>
<?php if (!empty($user['whatsapp'])): ?>
<div class="row"><span class="label">WhatsApp:</span><?= $user['whatsapp'] ?></div>
@@ -70,14 +70,14 @@
<?php if (!empty($user['social']) && !empty($user['social_code'])): ?>
<div class="qrcode-wrap">
<div><?= $user['social'] ?> 二维码</div>
<div><?= $contactField['code'] ?></div>
<img style = "width: 270px;height: 270px;margin-top: 30px;" src="<?= $user['social_code'] ?>">
</div>
<?php endif; ?>
</div>
<div class="tip">
扫码即可联系本人 | 本资料随 PDF 自动生成
<?= $contactField['left'] ?> | <?= $contactField['right'] ?>
</div>
</body>
+42 -16
View File
@@ -70,59 +70,85 @@
<table class="info-table">
<tr>
<td class="label">车价</td>
<td class="price">¥ <?= number_format($car['price'], 2) ?></td>
<td class="label"><?= $field['price'] ?></td>
<td class="price"><?= $field['currency'].' ' ?><?= number_format($car['price'], 2) ?></td>
</tr>
<tr>
<td class="label">车源地</td>
<td class="label"><?= $field['source_place'] ?></td>
<td><?= $car['source_place'] ?></td>
</tr>
<tr>
<td class="label">上牌时间</td>
<td class="label"><?= $field['plate_time'] ?></td>
<td><?= $car['plate_time'] ?></td>
</tr>
<tr>
<td class="label">排量</td>
<td class="label"><?= $field['displacement'] ?></td>
<td><?= $car['displacement'] ?></td>
</tr>
<tr>
<td class="label">里程</td>
<td class="label"><?= $field['mileage'] ?></td>
<td><?= $car['mileage'].'km' ?></td>
</tr>
<tr>
<td class="label">马力</td>
<td class="label"><?= $field['power'] ?></td>
<td><?= $car['power'] ?> </td>
</tr>
<tr>
<td class="label">车身颜色</td>
<td class="label"><?= $field['body_color'] ?></td>
<td><?= $car['body_color'] ?: '-' ?></td>
</tr>
<tr>
<td class="label">创建时间</td>
<td class="label"><?= $field['created_at'] ?></td>
<td><?= $car['created_at'] ?></td>
</tr>
</table>
<h2>车况介绍</h2>
<?php if (!empty($car['condition_desc'])): ?>
<h2><?= $field['condition_desc'] ?></h2>
<div class="desc">
<?= nl2br(htmlspecialchars($car['condition_desc'])) ?>
</div>
<?php endif; ?>
<h2>产品图</h2>
<div class="image-list">
<table width="100%" cellpadding="6" cellspacing="0">
<tr>
<thead>
<tr>
<th colspan="2" style="
font-size:28px;
font-weight:bold;
text-align:left;
padding:12px 0;
border-left:4px solid #1677ff;
padding-left:10px;
background:#fff;
">
<div style="
font-size:28px;
font-weight:bold;
padding:10px 0;
">
<?= $field['images'] ?>
</div>
</th >
</tr>
</thead>
<tbody>
<?php foreach ($car['images'] as $i => $img): ?>
<?php if ($i % 2 === 0): ?>
<tr>
<?php endif; ?>
<td width="50%" align="center">
<img src="<?= $img ?>" style="width:100%; border-radius:4px;">
</td>
<?php if (($i + 1) % 2 === 0): ?>
</tr><tr>
<?php if ($i % 2 === 1): ?>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div>