作者 lyh

gx

@@ -428,16 +428,16 @@ if (!function_exists('getImageUrl')) { @@ -428,16 +428,16 @@ if (!function_exists('getImageUrl')) {
428 $imageModel = new Image(); 428 $imageModel = new Image();
429 if (strpos($hash, '.') !== false) { 429 if (strpos($hash, '.') !== false) {
430 $info = $imageModel->read(['path'=>['like','%'.$hash.'%']]); 430 $info = $imageModel->read(['path'=>['like','%'.$hash.'%']]);
431 - $hash = $info['hash']; 431 + }else{
  432 + $info = $imageModel->read(['hash'=>$hash]);
432 } 433 }
433 - $info = $imageModel->read(['hash'=>$hash]);  
434 if(!empty($info)){ 434 if(!empty($info)){
435 if($info['is_cos'] == 1){ 435 if($info['is_cos'] == 1){
436 $cos = config('filesystems.disks.cos'); 436 $cos = config('filesystems.disks.cos');
437 $cosCdn = $cos['cdn']; 437 $cosCdn = $cos['cdn'];
438 $url = $cosCdn.$info['path']; 438 $url = $cosCdn.$info['path'];
439 }else{ 439 }else{
440 - $url = url('a/image/'.$info['hash']); 440 + $url = url($info['path']);
441 } 441 }
442 }else{ 442 }else{
443 $url = $hash; 443 $url = $hash;
@@ -461,14 +461,18 @@ if (!function_exists('getFileUrl')) { @@ -461,14 +461,18 @@ if (!function_exists('getFileUrl')) {
461 } 461 }
462 }else{ 462 }else{
463 $fileModel = new File(); 463 $fileModel = new File();
464 - $info = $fileModel->read(['hash'=>$hash]); 464 + if (strpos($hash, '.') !== false) {
  465 + $info = $fileModel->read(['path'=>['like','%'.$hash.'%']]);
  466 + }else{
  467 + $info = $fileModel->read(['hash'=>$hash]);
  468 + }
465 if(!empty($info)){ 469 if(!empty($info)){
466 if($info['is_cos'] == 1){ 470 if($info['is_cos'] == 1){
467 $cos = config('filesystems.disks.cos'); 471 $cos = config('filesystems.disks.cos');
468 $cosCdn = $cos['cdn']; 472 $cosCdn = $cos['cdn'];
469 $url = $cosCdn.$info['path']; 473 $url = $cosCdn.$info['path'];
470 }else{ 474 }else{
471 - $url = url('a/file/'.$info['hash']); 475 + $url = url($info['hash']);
472 } 476 }
473 }else{ 477 }else{
474 $url = $hash; 478 $url = $hash;
@@ -111,7 +111,7 @@ class FileController @@ -111,7 +111,7 @@ class FileController
111 $fileModel = new File(); 111 $fileModel = new File();
112 $file_hash = $fileModel->read(['hash'=>$hash]); 112 $file_hash = $fileModel->read(['hash'=>$hash]);
113 if($file_hash !== false){ 113 if($file_hash !== false){
114 - return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash)); 114 + return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path']));
115 } 115 }
116 $url = $this->config['root'].$this->path; 116 $url = $this->config['root'].$this->path;
117 $fileName = uniqid().rand(10000,99999).'.'.$file_type; 117 $fileName = uniqid().rand(10000,99999).'.'.$file_type;
@@ -126,7 +126,7 @@ class FileController @@ -126,7 +126,7 @@ class FileController
126 } 126 }
127 } 127 }
128 $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime); 128 $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
129 - return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash)); 129 + return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
130 } 130 }
131 131
132 /** 132 /**
@@ -168,7 +168,7 @@ class FileController @@ -168,7 +168,7 @@ class FileController
168 $hash = hash_file('md5', $file->getPathname()); 168 $hash = hash_file('md5', $file->getPathname());
169 $file_hash = $fileModel->read(['hash'=>$hash]); 169 $file_hash = $fileModel->read(['hash'=>$hash]);
170 if($file_hash !== false){ 170 if($file_hash !== false){
171 - $data[] = $this->responseData($fileModel,$hash); 171 + $data[] = $this->responseData($file_hash['path']);
172 continue; 172 continue;
173 } 173 }
174 $url = $this->config['root'].'/'.$this->path; 174 $url = $this->config['root'].'/'.$this->path;
@@ -187,7 +187,7 @@ class FileController @@ -187,7 +187,7 @@ class FileController
187 $size = $file->getSize(); 187 $size = $file->getSize();
188 $mime = $file->getMimeType(); 188 $mime = $file->getMimeType();
189 $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime); 189 $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
190 - $data[] = $this->responseData($fileModel,$hash); 190 + $data[] = $this->responseData($this->path.'/'.$fileName);
191 } 191 }
192 $this->response('资源',Code::SUCCESS,$data); 192 $this->response('资源',Code::SUCCESS,$data);
193 } 193 }
@@ -274,23 +274,6 @@ class FileController @@ -274,23 +274,6 @@ class FileController
274 } 274 }
275 275
276 /** 276 /**
277 - * @remark :获取文件链接  
278 - * @name :getImageUrl  
279 - * @author :lyh  
280 - * @method :post  
281 - * @time :2023/7/20 16:46  
282 - */  
283 - public function getFileUrl(&$fileModel,$hash){  
284 - $info = $fileModel->read(['hash'=>$hash]);  
285 - if($info['is_cos'] == 1){  
286 - $url = getFileUrl($info['hash']);  
287 - }else{  
288 - $url = url('a/file/'.$info['hash']);  
289 - }  
290 - return $url;  
291 - }  
292 -  
293 - /**  
294 * @remark :获取所有视频 277 * @remark :获取所有视频
295 * @name :getImageList 278 * @name :getImageList
296 * @author :lyh 279 * @author :lyh
@@ -301,7 +284,7 @@ class FileController @@ -301,7 +284,7 @@ class FileController
301 $fileModel = new File(); 284 $fileModel = new File();
302 $lists = $fileModel->list(['refer'=>1],$order = 'id',['id','hash','type','path','created_at']); 285 $lists = $fileModel->list(['refer'=>1],$order = 'id',['id','hash','type','path','created_at']);
303 foreach ($lists as $k => $v){ 286 foreach ($lists as $k => $v){
304 - $v['file_link'] = $this->getFileUrl($fileModel,$v['hash']); 287 + $v['file_link'] = getFileUrl($v['hash']);
305 $lists[$k] = $v; 288 $lists[$k] = $v;
306 } 289 }
307 $this->response('success',Code::SUCCESS,$lists); 290 $this->response('success',Code::SUCCESS,$lists);
@@ -314,11 +297,10 @@ class FileController @@ -314,11 +297,10 @@ class FileController
314 * @method :post 297 * @method :post
315 * @time :2023/7/26 13:41 298 * @time :2023/7/26 13:41
316 */ 299 */
317 - public function responseData(&$fileModel,$hash){ 300 + public function responseData($path){
318 $data = [ 301 $data = [
319 - 'file'=>$hash,  
320 - 'file_link'=>$this->getFileUrl($fileModel,$hash),  
321 - 'file_download'=>url('a/download_files?hash='.$hash), 302 + 'file'=>$path,
  303 + 'file_link'=>getFileUrl($path),
322 ]; 304 ];
323 return $data; 305 return $data;
324 } 306 }
@@ -152,7 +152,6 @@ class ImageController extends Controller @@ -152,7 +152,6 @@ class ImageController extends Controller
152 'image.required'=>'图片必须填写', 152 'image.required'=>'图片必须填写',
153 ]); 153 ]);
154 $files = $this->request->file('image'); 154 $files = $this->request->file('image');
155 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($files, true) . PHP_EOL, FILE_APPEND);  
156 if (empty($files)) { 155 if (empty($files)) {
157 $this->response('没有上传的文件!', Code::USER_ERROR); 156 $this->response('没有上传的文件!', Code::USER_ERROR);
158 } 157 }
@@ -182,7 +181,7 @@ class ImageController extends Controller @@ -182,7 +181,7 @@ class ImageController extends Controller
182 $imageModel = new ImageModel(); 181 $imageModel = new ImageModel();
183 $image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]); 182 $image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
184 if($image_hash !== false){ 183 if($image_hash !== false){
185 - return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash)); 184 + return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path']));
186 } 185 }
187 $url = $this->config['root'].$this->path; 186 $url = $this->config['root'].$this->path;
188 $fileName = uniqid().rand(10000,99999).'.'.$image_type; 187 $fileName = uniqid().rand(10000,99999).'.'.$image_type;
@@ -197,7 +196,7 @@ class ImageController extends Controller @@ -197,7 +196,7 @@ class ImageController extends Controller
197 } 196 }
198 } 197 }
199 $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime); 198 $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
200 - return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash)); 199 + return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
201 } 200 }
202 201
203 /** 202 /**
@@ -260,7 +259,7 @@ class ImageController extends Controller @@ -260,7 +259,7 @@ class ImageController extends Controller
260 $hash = hash_file('md5', $file->getPathname()); 259 $hash = hash_file('md5', $file->getPathname());
261 $image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]); 260 $image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
262 if($image_hash !== false){ 261 if($image_hash !== false){
263 - $data[] = $this->responseData($hash); 262 + $data[] = $this->responseData($image_hash['path']);
264 continue; 263 continue;
265 } 264 }
266 $url = $this->config['root'].$this->path; 265 $url = $this->config['root'].$this->path;
@@ -277,7 +276,7 @@ class ImageController extends Controller @@ -277,7 +276,7 @@ class ImageController extends Controller
277 } 276 }
278 //批量存储 277 //批量存储
279 $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime); 278 $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
280 - $data[] = $this->responseData($hash); 279 + $data[] = $this->responseData($this->path.'/'.$fileName);
281 } 280 }
282 $this->response('图片资源',Code::SUCCESS,$data); 281 $this->response('图片资源',Code::SUCCESS,$data);
283 } 282 }
@@ -388,11 +387,10 @@ class ImageController extends Controller @@ -388,11 +387,10 @@ class ImageController extends Controller
388 * @method :post 387 * @method :post
389 * @time :2023/7/26 13:41 388 * @time :2023/7/26 13:41
390 */ 389 */
391 - public function responseData($hash){ 390 + public function responseData($path = ''){
392 $data = [ 391 $data = [
393 - 'image'=>$hash,  
394 - 'image_link'=>getImageUrl($hash),  
395 - 'image_download'=>url('a/downLoad/images?hash='.$hash), 392 + 'image'=>$path,
  393 + 'image_link'=>getImageUrl($path),
396 ]; 394 ];
397 return $data; 395 return $data;
398 } 396 }
@@ -64,12 +64,12 @@ class ATemplateModuleLogic extends BaseLogic @@ -64,12 +64,12 @@ class ATemplateModuleLogic extends BaseLogic
64 */ 64 */
65 public function setAttribute($param){ 65 public function setAttribute($param){
66 if(isset($param['image']) && !empty($param['image'])){ 66 if(isset($param['image']) && !empty($param['image'])){
67 - $param['image'] = $this->imageName(basename($param['image'])); 67 + $param['image'] = basename($param['image']);
68 } 68 }
69 if(isset($param['images']) && !empty($param['images'])){ 69 if(isset($param['images']) && !empty($param['images'])){
70 $arr_images = []; 70 $arr_images = [];
71 foreach ($param['images'] as $v){ 71 foreach ($param['images'] as $v){
72 - $arr_images[] = $this->imageName(basename($v));; 72 + $arr_images[] = basename($v);
73 } 73 }
74 $param['images'] = implode(',',$arr_images); 74 $param['images'] = implode(',',$arr_images);
75 } 75 }