Upload.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller;
  13. use think\response\Json;
  14. use app\store\service\Upload as UploadService;
  15. use app\common\enum\file\FileType as FileTypeEnum;
  16. /**
  17. * 文件库管理
  18. * Class Upload
  19. * @package app\store\controller
  20. */
  21. class Upload extends Controller
  22. {
  23. /**
  24. * 图片上传接口
  25. * @param int $groupId 文件库分组ID
  26. * @return Json
  27. * @throws \think\Exception
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\DbException
  30. * @throws \think\db\exception\ModelNotFoundException
  31. */
  32. public function image(int $groupId = 0): Json
  33. {
  34. // 执行文件上传
  35. $service = new UploadService();
  36. if (!$service->upload(FileTypeEnum::IMAGE, $groupId)) {
  37. return $this->renderError('文件上传失败:' . $service->getError());
  38. }
  39. // 图片上传成功
  40. return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成功');
  41. }
  42. /**
  43. * 视频上传接口
  44. * @param int $groupId 文件库分组ID
  45. * @return Json
  46. * @throws \think\Exception
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function video(int $groupId = 0): Json
  52. {
  53. // 执行文件上传
  54. $service = new UploadService();
  55. if (!$service->upload(FileTypeEnum::VIDEO, $groupId)) {
  56. return $this->renderError('文件上传失败:' . $service->getError());
  57. }
  58. // 图片上传成功
  59. return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成功');
  60. }
  61. }