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