|  | @@ -16,14 +16,15 @@ use Exception;
 | 
	
		
			
				|  |  |  use UnexpectedValueException;
 | 
	
		
			
				|  |  |  use DirectoryIterator;
 | 
	
		
			
				|  |  |  use think\facade\View;
 | 
	
		
			
				|  |  | +use think\facade\Config;
 | 
	
		
			
				|  |  |  use think\File;
 | 
	
		
			
				|  |  |  use think\Image;
 | 
	
		
			
				|  |  | -use think\facade\Config;
 | 
	
		
			
				|  |  |  use think\exception\ValidateException;
 | 
	
		
			
				|  |  | +use think\file\UploadedFile;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  use app\common\service\FileService;
 | 
	
		
			
				|  |  |  use app\common\model\FileManager as FileManagerModel;
 | 
	
		
			
				|  |  | -use think\file\UploadedFile;
 | 
	
		
			
				|  |  | +use app\common\facade\FileUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  class FileManager extends Base
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -294,9 +295,9 @@ class FileManager extends Base
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          if ($this->request->isPost()) {
 | 
	
		
			
				|  |  |              $file = $this->request->file('upload_file');
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +            halt($file);
 | 
	
		
			
				|  |  |              if ($file) {
 | 
	
		
			
				|  |  | -                // try {
 | 
	
		
			
				|  |  | +                try {
 | 
	
		
			
				|  |  |                      validate(
 | 
	
		
			
				|  |  |                          [
 | 
	
		
			
				|  |  |                              'file' => [
 | 
	
	
		
			
				|  | @@ -312,9 +313,15 @@ class FileManager extends Base
 | 
	
		
			
				|  |  |                          ]
 | 
	
		
			
				|  |  |                      )->check(['file' => $file]);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    $savename =  str_replace('\\', '/', $file->hashName()) ;
 | 
	
		
			
				|  |  | +                    $urlpath = Config::get('filesystem.disks.public.url');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    $username = $this->getSysUser()->username;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +                    $savename =  str_replace('\\', '/', $file->hashName());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +                    $originalName = $file->getOriginalName();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    $thumbname = "";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                      if ($thumb == true) {
 | 
	
		
			
				|  |  |                          $image = Image::open($file);
 | 
	
	
		
			
				|  | @@ -322,44 +329,40 @@ class FileManager extends Base
 | 
	
		
			
				|  |  |                          $image->thumb($width, $height, 1);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                          $ext = $file->extension();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                        $thumbname = str_replace('.' . $ext, '',  $savename) . $this->t_suffix . '.' . $ext;    
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                        
 | 
	
		
			
				|  |  |                          if ($original == true) {
 | 
	
		
			
				|  |  |                              \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
 | 
	
		
			
				|  |  | +                            
 | 
	
		
			
				|  |  | +                            $thumbname = str_replace('.' . $ext, '',  $savename) . $this->t_suffix . '.' . $ext;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            $savepath = str_replace('\\', '/', Config::get('filesystem.disks.public.root') . '/' . $thumbname);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            $image->save($savepath);
 | 
	
		
			
				|  |  | +                            
 | 
	
		
			
				|  |  | +                            FileManagerModel::saveFileInfo($savepath, $thumbname, $originalName, $id, $cjid, $username);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            $thumbname = $urlpath . '/' . $thumbname;
 | 
	
		
			
				|  |  |                          } else {
 | 
	
		
			
				|  |  | -                            $thumbname = str_replace('.' . $ext, '',  $thumbname) . $this->t_suffix . '.' . $ext;
 | 
	
		
			
				|  |  | -                            $savename = $thumbname;
 | 
	
		
			
				|  |  | +                            $image->save(Config::get('filesystem.disks.public.root') . '/' . $savename);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        $image->save(Config::get('filesystem.disks.public.root') . '/' . $thumbname);                      
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  |                          \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    halt($savename);
 | 
	
		
			
				|  |  | +                    $fileinfo = FileManagerModel::saveFileInfo($file, $savename, $originalName, $id, $cjid, $username);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    $fileinfo = new FileManagerModel();
 | 
	
		
			
				|  |  | -                    
 | 
	
		
			
				|  |  | -                    $fileinfo->title         = $file->getOriginalName();
 | 
	
		
			
				|  |  | -                    $fileinfo->filesize      = $file->getSize();
 | 
	
		
			
				|  |  | -                    $fileinfo->filetime      = $file->getCTime();
 | 
	
		
			
				|  |  | -                    $fileinfo->fileextension = $file->extension();
 | 
	
		
			
				|  |  | -                    $fileinfo->hash_md5      = $file->md5();
 | 
	
		
			
				|  |  | -                    $fileinfo->filepath      = Config::get('filesystem.disks.public.url') . '/' . $savename;
 | 
	
		
			
				|  |  | -                    $fileinfo->filename      = basename($savename); 
 | 
	
		
			
				|  |  | -                    $fileinfo->username      = $this->getSysUser()->username;
 | 
	
		
			
				|  |  | -                    $fileinfo->infoid        =  $id;
 | 
	
		
			
				|  |  | -                    $fileinfo->cjid          =  $cjid;
 | 
	
		
			
				|  |  | -                    
 | 
	
		
			
				|  |  | -                    $fileinfo->save();
 | 
	
		
			
				|  |  | -                    // $res = FileManagerModel::dealUploadImg($file, $savename, $water, $thumb, $width, $height, $overwrite, $id, $cjid);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                    // return json(array_merge(['code' => 0, 'img_id' => $img_id,], $res));
 | 
	
		
			
				|  |  | -                // } catch (ValidateException $e) {
 | 
	
		
			
				|  |  | -                //     $this->error($e->getMessage());
 | 
	
		
			
				|  |  | -                // } catch (Exception $e) {
 | 
	
		
			
				|  |  | -                //     $this->error($e->getMessage());
 | 
	
		
			
				|  |  | -                // }
 | 
	
		
			
				|  |  | +                    return json([
 | 
	
		
			
				|  |  | +                        'code'    => 0,
 | 
	
		
			
				|  |  | +                        'img_id'  => $img_id,
 | 
	
		
			
				|  |  | +                        'picname' => $fileinfo->filepath,
 | 
	
		
			
				|  |  | +                        'thumb'   => $thumbname
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    ]);
 | 
	
		
			
				|  |  | +                } catch (ValidateException $e) {
 | 
	
		
			
				|  |  | +                    $this->error($e->getMessage());
 | 
	
		
			
				|  |  | +                } catch (Exception $e) {
 | 
	
		
			
				|  |  | +                    $this->error($e->getMessage());
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  $this->error('图片不能为空');
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -376,29 +379,60 @@ class FileManager extends Base
 | 
	
		
			
				|  |  |       * @param int $height       缩略图最大高
 | 
	
		
			
				|  |  |       * @param bool $overwrite   生成缩略图后是否保存原图
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public function uploadUrlImg(string $img_id = 'picture', $water = false, $thumb = false, $width = 400, $height = 300, $overwrite = false)
 | 
	
		
			
				|  |  | +    public function uploadUrlImg(string $img_id = 'picture', $thumb = false, $width = 400, $height = 300,
 | 
	
		
			
				|  |  | +        $original = false, $id = 0, $cjid = 0)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          if ($this->request->isPost()) {
 | 
	
		
			
				|  |  |              $urlImg = $this->request->param('url_file');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              if ($urlImg) {
 | 
	
		
			
				|  |  |                  try {
 | 
	
		
			
				|  |  | -                    $fileService = new FileService();
 | 
	
		
			
				|  |  | +                    $file = FileUtils::downloadUrlImg($urlImg);
 | 
	
		
			
				|  |  | +                    
 | 
	
		
			
				|  |  | +                    $urlpath = Config::get('filesystem.disks.public.url');
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    $file = $fileService->downloadUrlImg($urlImg);
 | 
	
		
			
				|  |  | +                    $username = $this->getSysUser()->username;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    $arr = $this->dealUploadImg($file, $thumb, $width, $height, $overwrite);
 | 
	
		
			
				|  |  | +                    $savename =  str_replace('\\', '/', $file->hashName());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    @unlink($file->realPath);
 | 
	
		
			
				|  |  | +                    $originalName = $file->getOriginalName();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    return array_merge(
 | 
	
		
			
				|  |  | -                        [
 | 
	
		
			
				|  |  | -                            'code' => 0,
 | 
	
		
			
				|  |  | -                            'img_id' => $img_id,
 | 
	
		
			
				|  |  | -                            'picture_url' => Config::get('filesystem.disks.public.url') . '/'
 | 
	
		
			
				|  |  | -                        ],
 | 
	
		
			
				|  |  | -                        $arr
 | 
	
		
			
				|  |  | -                    );
 | 
	
		
			
				|  |  | +                    $thumbname = "";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    if ($thumb == true) {
 | 
	
		
			
				|  |  | +                        $image = Image::open($file);
 | 
	
		
			
				|  |  | +                        
 | 
	
		
			
				|  |  | +                        $image->thumb($width, $height, 1);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        $ext = $file->extension();
 | 
	
		
			
				|  |  | +                        
 | 
	
		
			
				|  |  | +                        if ($original == true) {
 | 
	
		
			
				|  |  | +                            \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
 | 
	
		
			
				|  |  | +                            
 | 
	
		
			
				|  |  | +                            $thumbname = str_replace('.' . $ext, '',  $savename) . $this->t_suffix . '.' . $ext;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            $savepath = str_replace('\\', '/', Config::get('filesystem.disks.public.root') . '/' . $thumbname);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            $image->save($savepath);
 | 
	
		
			
				|  |  | +                            
 | 
	
		
			
				|  |  | +                            FileManagerModel::saveFileInfo($savepath, $thumbname, $originalName, $id, $cjid, $username);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            $thumbname = $urlpath . '/' . $thumbname;
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            $image->save(Config::get('filesystem.disks.public.root') . '/' . $savename);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    } else {
 | 
	
		
			
				|  |  | +                        \think\facade\Filesystem::disk('public')->putFileAs('/', $file, $savename);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    $fileinfo = FileManagerModel::saveFileInfo($file, $savename, $originalName, $id, $cjid, $username);
 | 
	
		
			
				|  |  | + 
 | 
	
		
			
				|  |  | +                    return json([
 | 
	
		
			
				|  |  | +                        'code'    => 0,
 | 
	
		
			
				|  |  | +                        'img_id'  => $img_id,
 | 
	
		
			
				|  |  | +                        'picname' => $fileinfo->filepath,
 | 
	
		
			
				|  |  | +                        'thumb'   => $thumbname
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    ]);
 | 
	
		
			
				|  |  |                  } catch (\think\exception\ValidateException $e) {
 | 
	
		
			
				|  |  |                      $this->error($e->getMessage());
 | 
	
		
			
				|  |  |                  }
 |