From cc5fe0bcaa70d02ca4e71b1236341e8e789dc170 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 5 Jan 2026 16:15:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/UsedCarController.php | 27 +++++++++++++++------ app/common/service/UsedCarService.php | 14 +++++++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/common/controller/UsedCarController.php b/app/common/controller/UsedCarController.php index a1a0ffc..55d10ae 100644 --- a/app/common/controller/UsedCarController.php +++ b/app/common/controller/UsedCarController.php @@ -2,6 +2,7 @@ namespace app\common\controller; use app\common\controller\BaseController; +use app\common\service\OssService; use app\common\traits\crud\CrudControllerTrait; use app\common\service\UsedCarService; @@ -22,12 +23,22 @@ class UsedCarController extends BaseController * @param array $data * @return array */ - // protected function indexFormat($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']); - // return $data; - // } + protected function indexFormat($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']); + if (!empty($data['images'])){ + $images = explode(',', $data['images']); + $ossService = new OssService(); + $images_pull = []; + foreach ($images as $image){ + $images_pull[] = $ossService->generatePrivateUrl($image); + } + $data['images_pull'] = $images_pull; + + } + return $data; + } } \ No newline at end of file diff --git a/app/common/service/UsedCarService.php b/app/common/service/UsedCarService.php index 771a2d8..d3038c2 100644 --- a/app/common/service/UsedCarService.php +++ b/app/common/service/UsedCarService.php @@ -5,6 +5,8 @@ namespace app\common\service; use app\common\validate\UsedCarValidate; use app\common\traits\crud\CrudServiceTrait; use app\common\model\UsedCar; +use support\exception\BusinessException; +use support\Request; class UsedCarService { @@ -28,4 +30,16 @@ class UsedCarService { return new $this->validator; } + + + public function beforeServiceStore($data, Request $request): array + { + if(empty($data['product_name'])){ + throw new BusinessException('产品名称不能为空'); + } + if(empty($data['images'])){ + throw new BusinessException('产品图片不能为空'); + } + return $data; + } } \ No newline at end of file