正在显示
1 个修改的文件
包含
28 行增加
和
3 行删除
| @@ -3,10 +3,12 @@ | @@ -3,10 +3,12 @@ | ||
| 3 | namespace App\Http\Logic\Bside; | 3 | namespace App\Http\Logic\Bside; |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | +use App\Enums\Common\Code; | ||
| 6 | use App\Enums\Common\Common; | 7 | use App\Enums\Common\Common; |
| 7 | use App\Exceptions\BsideGlobalException; | 8 | use App\Exceptions\BsideGlobalException; |
| 8 | use App\Http\Controllers\file\ImageController; | 9 | use App\Http\Controllers\file\ImageController; |
| 9 | use App\Http\Logic\Logic; | 10 | use App\Http\Logic\Logic; |
| 11 | +use App\Models\File\Image as ImageModel; | ||
| 10 | use Illuminate\Support\Facades\Cache; | 12 | use Illuminate\Support\Facades\Cache; |
| 11 | 13 | ||
| 12 | /** | 14 | /** |
| @@ -99,9 +101,32 @@ class BaseLogic extends Logic | @@ -99,9 +101,32 @@ class BaseLogic extends Logic | ||
| 99 | * @method | 101 | * @method |
| 100 | */ | 102 | */ |
| 101 | public function upload(){ | 103 | public function upload(){ |
| 102 | - $image = new ImageController(); | ||
| 103 | - $data = $image->upload(); | ||
| 104 | - return $data['data']['image']; | 104 | + $files = $this->request->file('image'); |
| 105 | + $hash = hash_file('md5', $files->getPathname()); | ||
| 106 | + //查看文件是否存在 | ||
| 107 | + $imageModel = new ImageModel(); | ||
| 108 | + $image_hash = $imageModel->read(['hash'=>$hash]); | ||
| 109 | + if($image_hash !== false){ | ||
| 110 | + return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); | ||
| 111 | + } | ||
| 112 | + $url = $this->path; | ||
| 113 | + $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | ||
| 114 | + $res = $files->move($url,$fileName); | ||
| 115 | + if ($res === false) { | ||
| 116 | + return false; | ||
| 117 | + } | ||
| 118 | + $data = [ | ||
| 119 | + 'path' => $url.$fileName, | ||
| 120 | + 'created_at' => date('Y-m-d H:i:s',time()), | ||
| 121 | + 'size' => $res->getSize(), | ||
| 122 | + 'hash' => $hash, | ||
| 123 | + 'type'=>$files->getClientOriginalExtension(), | ||
| 124 | + ]; | ||
| 125 | + $rs = $imageModel->add($data); | ||
| 126 | + if ($rs === false) { | ||
| 127 | + return false; | ||
| 128 | + } | ||
| 129 | + return $hash; | ||
| 105 | } | 130 | } |
| 106 | 131 | ||
| 107 | /** | 132 | /** |
-
请 注册 或 登录 后发表评论