pdf生成时修改价格

This commit is contained in:
2026-01-12 11:52:07 +08:00
parent befb1e5f4c
commit d25e472348
+18 -1
View File
@@ -3,6 +3,7 @@ namespace app\common\controller;
use app\common\controller\BaseController; use app\common\controller\BaseController;
use app\common\model\UsedCar; use app\common\model\UsedCar;
use app\common\model\UsedCarPdfLog;
use app\common\service\OssService; 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;
@@ -104,14 +105,23 @@ class UsedCarController extends BaseController
} }
} }
/**
* 生成pdf
* @param Request $request
* @return \support\Response
*/
public function producePdf(Request $request){ public function producePdf(Request $request){
try { try {
$price = $request->get('price');
if(empty($price)){
throw new BusinessException("请输入生成pdf中的价格");
}
$raw = $this->service->serviceShow($request); $raw = $this->service->serviceShow($request);
$data = $this->transformData($raw, method_exists($this, 'showFormat') $data = $this->transformData($raw, method_exists($this, 'showFormat')
? [$this, 'showFormat'] ? [$this, 'showFormat']
: null); : null);
$images = []; $images = [];
foreach ($data['images_pull'] as $key => $image){ foreach ($data['images_pull'] as $image){
$images[] = $this->service->downloadImage($image); $images[] = $this->service->downloadImage($image);
} }
$data['images'] = $images; $data['images'] = $images;
@@ -133,6 +143,13 @@ class UsedCarController extends BaseController
array_map('unlink', glob(runtime_path('pdf/images/*.jpg'))); array_map('unlink', glob(runtime_path('pdf/images/*.jpg')));
array_map('unlink', glob(runtime_path('pdf/attachment/*.pdf'))); array_map('unlink', glob(runtime_path('pdf/attachment/*.pdf')));
UsedCarPdfLog::create([
'user_id' => $request->user['id'],
'used_car_id' => $request->get('id'),
'price_snapshot' => $price,
'pdf_path' => $pdf,
]);
return $this->success($pdf); return $this->success($pdf);
} catch (\Throwable $e) { } catch (\Throwable $e) {
return $this->error($e->getMessage()); return $this->error($e->getMessage());