pdf地址
This commit is contained in:
@@ -7,6 +7,7 @@ use app\common\service\OssService;
|
|||||||
use app\common\traits\crud\CrudControllerTrait;
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
use app\common\service\UsedCarService;
|
use app\common\service\UsedCarService;
|
||||||
use app\common\utils\pdf\service\MpdfDriver;
|
use app\common\utils\pdf\service\MpdfDriver;
|
||||||
|
use support\exception\BusinessException;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
|
|
||||||
class UsedCarController extends BaseController
|
class UsedCarController extends BaseController
|
||||||
@@ -134,7 +135,7 @@ class UsedCarController extends BaseController
|
|||||||
array_map('unlink', glob(runtime_path('pdf/attachment/*.pdf')));
|
array_map('unlink', glob(runtime_path('pdf/attachment/*.pdf')));
|
||||||
return $this->success($pdf);
|
return $this->success($pdf);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return $this->error($e->getMessage().$e->getLine().$e->getFile());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,4 +152,40 @@ class UsedCarController extends BaseController
|
|||||||
$raw['product_name'].'-'.$raw['id'].'.pdf' // 下载时显示的文件名
|
$raw['product_name'].'-'.$raw['id'].'.pdf' // 下载时显示的文件名
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPdf(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$raw = $this->service->serviceShow($request);
|
||||||
|
$filePath = runtime_path('pdf') . '/' . $raw['pdf_src'];
|
||||||
|
|
||||||
|
if (empty($raw['pdf_src']) || !file_exists($filePath)) {
|
||||||
|
throw new BusinessException('文件不存在');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 确保 public/pdf 存在
|
||||||
|
$publicDir = public_path('pdf');
|
||||||
|
if (!is_dir($publicDir)) {
|
||||||
|
mkdir($publicDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拷贝到 public 目录
|
||||||
|
$publicFile = $publicDir . '/' . $raw['pdf_src'];
|
||||||
|
if (!file_exists($publicFile)) {
|
||||||
|
copy($filePath, $publicFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回访问地址
|
||||||
|
$baseUrl = 'https://' . request()->header('host');
|
||||||
|
$url = $baseUrl . '/pdf/' . $raw['pdf_src'];
|
||||||
|
|
||||||
|
return $this->success([
|
||||||
|
'pdf_url' => $url,
|
||||||
|
'file_name' => $raw['product_name'] . '-' . $raw['id'] . '.pdf'
|
||||||
|
]);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ class Task
|
|||||||
->update(['pdf_src' => '']);
|
->update(['pdf_src' => '']);
|
||||||
|
|
||||||
array_map('unlink', glob(runtime_path('pdf/*.pdf')));
|
array_map('unlink', glob(runtime_path('pdf/*.pdf')));
|
||||||
|
array_map('unlink', glob(public_path('pdf/*.pdf')));
|
||||||
|
|
||||||
Log::info('send follow end',[time()]);
|
Log::info('send follow end',[time()]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ Route::group('/common', function () {
|
|||||||
Route::any('/list', [app\common\controller\UsedCarController::class, 'index']);
|
Route::any('/list', [app\common\controller\UsedCarController::class, 'index']);
|
||||||
Route::any('/produce/pdf', [app\common\controller\UsedCarController::class, 'producePdf']);
|
Route::any('/produce/pdf', [app\common\controller\UsedCarController::class, 'producePdf']);
|
||||||
Route::any('/download/pdf', [app\common\controller\UsedCarController::class, 'downloadPdf']);
|
Route::any('/download/pdf', [app\common\controller\UsedCarController::class, 'downloadPdf']);
|
||||||
|
Route::any('/pdf', [app\common\controller\UsedCarController::class, 'getPdf']);
|
||||||
Route::any('/show', [app\common\controller\UsedCarController::class, 'show']);
|
Route::any('/show', [app\common\controller\UsedCarController::class, 'show']);
|
||||||
Route::any('/store', [app\common\controller\UsedCarController::class, 'store']);
|
Route::any('/store', [app\common\controller\UsedCarController::class, 'store']);
|
||||||
Route::any('/update', [app\common\controller\UsedCarController::class, 'update']);
|
Route::any('/update', [app\common\controller\UsedCarController::class, 'update']);
|
||||||
|
|||||||
Reference in New Issue
Block a user