用户信息、个人名片、加密、水印
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\common\controller;
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\UsedCar;
|
||||
use app\common\model\UsedCarPdfLog;
|
||||
use app\common\model\User;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\UsedCarService;
|
||||
@@ -138,8 +139,14 @@ class UsedCarController extends BaseController
|
||||
}
|
||||
$data['attachment'] = $attachments;
|
||||
$data['price'] = $price;
|
||||
|
||||
$pdf = (new MpdfDriver())->exportUsedCarPdf($data);
|
||||
$user = User::where('id',$request->user['id'])->first();
|
||||
$contact = $user['email'] ?? $user['phone'] ?? $user['whatsapp'] ?? null;
|
||||
if(!empty($user['social_code'])){
|
||||
$ossService = new OssService();
|
||||
$user['social_code'] = $ossService->generatePrivateUrl($user['social_code']);
|
||||
$user['social_code'] = $this->service->downloadImage($user['social_code']);
|
||||
}
|
||||
$pdf = (new MpdfDriver())->exportUsedCarPdf($data,$user,$contact);
|
||||
UsedCar::where('id', $data['id'])->update(['pdf_src' => $pdf]);
|
||||
|
||||
array_map('unlink', glob(runtime_path('pdf/images/*.jpg')));
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace app\common\controller;
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\UserService;
|
||||
use support\Request;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
@@ -30,4 +31,60 @@ class UserController extends BaseController
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回更新成功的数据或信息
|
||||
*/
|
||||
public function edit(Request $request)
|
||||
{
|
||||
try {
|
||||
$data = $request->post();
|
||||
$request->setPost('id',$request->user['id']);
|
||||
$res = $this->service->serviceUpdate($request, $data);
|
||||
return $this->success([], '更新成功');
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @param int|string $id 资源 ID
|
||||
* @return mixed 返回资源详情数据
|
||||
*/
|
||||
public function show(Request $request)
|
||||
{
|
||||
try {
|
||||
$request->setGet('id',$request->user['id']);
|
||||
$raw = $this->service->serviceShow($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'showFormat')
|
||||
? [$this, 'showFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function showFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
unset($data['union_id']);
|
||||
unset($data['app_id']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class User extends Model
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'union_id', 'app_id', 'name'];
|
||||
protected $fillable = ['id', 'union_id', 'app_id', 'name', 'phone', 'email', 'whatsapp', 'social', 'social_code'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace app\common\service;
|
||||
use app\common\validate\UserValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\User;
|
||||
use support\Request;
|
||||
|
||||
class UserService
|
||||
{
|
||||
@@ -28,4 +29,12 @@ class UserService
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
public function beforeServiceUpdate($data, Request $request){
|
||||
unset($data['union_id']);
|
||||
unset($data['app_id']);
|
||||
unset($data['name']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ class MpdfDriver
|
||||
return [$css, $html];
|
||||
}
|
||||
|
||||
public function exportUsedCarPdf($car)
|
||||
public function exportUsedCarPdf($car,$user,$contact)
|
||||
{
|
||||
/*$car = [
|
||||
'title' => '奥迪Q3 2013款 35 TFSI 舒适型',
|
||||
@@ -154,12 +154,35 @@ class MpdfDriver
|
||||
'default_font' => 'sun-exta'
|
||||
]);
|
||||
|
||||
$mpdf->SetProtection(//限制篡改或盗用
|
||||
['print'], // 允许的权限 copy:允许复制、print:允许打印
|
||||
'', // 用户密码(可留空)
|
||||
'Admin@2026@!#' // 拥有者密码(一定要设置)
|
||||
);
|
||||
|
||||
//设置水印
|
||||
$mpdf->SetWatermarkText(
|
||||
$user['name'] .' '. $contact,
|
||||
0.08
|
||||
);
|
||||
$mpdf->showWatermarkText = true;
|
||||
|
||||
// 1️⃣ 车辆基本信息 HTML
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// 2️⃣ 追加附件pdf
|
||||
foreach ($car['attachment'] as $attachment) {
|
||||
$this->appendPdf($mpdf,$attachment);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$cardTpl = base_path('app/common/utils/pdf/template/contactCard.stub');
|
||||
include $cardTpl;
|
||||
$cardHtml = ob_get_clean();
|
||||
// 3️⃣ 新增一页:名片页
|
||||
$mpdf->AddPage();
|
||||
$mpdf->WriteHTML($cardHtml);
|
||||
|
||||
$pdf = $mpdf->Output('车辆详情.pdf', 'S');
|
||||
$dir = runtime_path('pdf');
|
||||
if (!is_dir($dir)) mkdir($dir, 0777, true);
|
||||
|
||||
Reference in New Issue
Block a user