From b637a1953c0a560f85fe24e80ea10963bba5da6b Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 25 Apr 2024 01:21:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=A4=9A=E8=A7=84=E6=A0=BC=E6=B2=A1=E6=9C=89=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=88=86=E7=B1=BB=E4=B8=8B=E6=B2=A1=E6=9C=89=E5=95=86?= =?UTF-8?q?=E5=93=81wenti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Upload.php | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/admin/controller/Upload.php diff --git a/app/admin/controller/Upload.php b/app/admin/controller/Upload.php new file mode 100644 index 00000000..80fb8620 --- /dev/null +++ b/app/admin/controller/Upload.php @@ -0,0 +1,65 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\controller; + +use think\response\Json; +use app\store\service\Upload as UploadService; +use app\common\enum\file\FileType as FileTypeEnum; + +/** + * 文件库管理 + * Class Upload + * @package app\store\controller + */ +class Upload extends Controller +{ + /** + * 图片上传接口 + * @param int $groupId 文件库分组ID + * @return Json + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function image(int $groupId = 0): Json + { + // 执行文件上传 + $service = new UploadService(); + if (!$service->upload(FileTypeEnum::IMAGE, $groupId)) { + return $this->renderError('文件上传失败:' . $service->getError()); + } + // 图片上传成功 + return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成功'); + } + + /** + * 视频上传接口 + * @param int $groupId 文件库分组ID + * @return Json + * @throws \think\Exception + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function video(int $groupId = 0): Json + { + // 执行文件上传 + $service = new UploadService(); + if (!$service->upload(FileTypeEnum::VIDEO, $groupId)) { + return $this->renderError('文件上传失败:' . $service->getError()); + } + // 图片上传成功 + return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成功'); + } +}