UploadService.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\upload;
  12. use app\dict\sys\FileDict;
  13. use app\dict\sys\StorageDict;
  14. use app\service\core\upload\CoreUploadService;
  15. use core\base\BaseAdminService;
  16. use core\exception\UploadFileException;
  17. use Exception;
  18. /**
  19. * 用户服务层
  20. * Class BaseService
  21. * @package app\service
  22. */
  23. class UploadService extends BaseAdminService
  24. {
  25. private $root_path = 'attachment';
  26. /**
  27. * 附件库上传图片
  28. * @param $file
  29. * @param int $cate_id
  30. * @return array
  31. */
  32. public function image($file, int $cate_id = 0, $is_attachment = true){
  33. $dir = $this->root_path.'/'.'image'.'/'.$this->site_id.'/'.date('Ym').'/'.date('d');
  34. $core_upload_service = new CoreUploadService($is_attachment);
  35. //如果没有选择相册分组的话,就选择第一个相册分组
  36. return $core_upload_service->image($file, $this->site_id, $dir, $cate_id);
  37. }
  38. /**
  39. * 附件库上传视频
  40. * @param $file
  41. * @param int $cate_id
  42. * @return array
  43. */
  44. public function video($file, int $cate_id = 0){
  45. $dir = $this->root_path.'/'.'video'.'/'.$this->site_id.'/'.date('Ym').'/'.date('d');
  46. $core_upload_service = new CoreUploadService(true);
  47. return $core_upload_service->video($file, $this->site_id, $dir, $cate_id);
  48. }
  49. /**
  50. * 文件上传
  51. * @param $file
  52. * @param string $type
  53. * @return array
  54. * @throws Exception
  55. */
  56. public function document($file, string $type){
  57. if(!in_array($type, FileDict::getSceneType()))
  58. throw new UploadFileException('UPLOAD_TYPE_ERROR');
  59. $dir = $this->root_path.'/document/'.$type.'/'.$this->site_id.'/'.date('Ym').'/'.date('d');
  60. $core_upload_service = new CoreUploadService();
  61. return $core_upload_service->document($file, $this->site_id, $type, $dir, StorageDict::LOCAL);
  62. }
  63. }