作者 lyh

gx

... ... @@ -428,16 +428,16 @@ if (!function_exists('getImageUrl')) {
$imageModel = new Image();
if (strpos($hash, '.') !== false) {
$info = $imageModel->read(['path'=>['like','%'.$hash.'%']]);
$hash = $info['hash'];
}else{
$info = $imageModel->read(['hash'=>$hash]);
}
$info = $imageModel->read(['hash'=>$hash]);
if(!empty($info)){
if($info['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$url = $cosCdn.$info['path'];
}else{
$url = url('a/image/'.$info['hash']);
$url = url($info['path']);
}
}else{
$url = $hash;
... ... @@ -461,14 +461,18 @@ if (!function_exists('getFileUrl')) {
}
}else{
$fileModel = new File();
$info = $fileModel->read(['hash'=>$hash]);
if (strpos($hash, '.') !== false) {
$info = $fileModel->read(['path'=>['like','%'.$hash.'%']]);
}else{
$info = $fileModel->read(['hash'=>$hash]);
}
if(!empty($info)){
if($info['is_cos'] == 1){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$url = $cosCdn.$info['path'];
}else{
$url = url('a/file/'.$info['hash']);
$url = url($info['hash']);
}
}else{
$url = $hash;
... ...
... ... @@ -111,7 +111,7 @@ class FileController
$fileModel = new File();
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash));
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path']));
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$file_type;
... ... @@ -126,7 +126,7 @@ class FileController
}
}
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash));
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
}
/**
... ... @@ -168,7 +168,7 @@ class FileController
$hash = hash_file('md5', $file->getPathname());
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
$data[] = $this->responseData($fileModel,$hash);
$data[] = $this->responseData($file_hash['path']);
continue;
}
$url = $this->config['root'].'/'.$this->path;
... ... @@ -187,7 +187,7 @@ class FileController
$size = $file->getSize();
$mime = $file->getMimeType();
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location,$mime);
$data[] = $this->responseData($fileModel,$hash);
$data[] = $this->responseData($this->path.'/'.$fileName);
}
$this->response('资源',Code::SUCCESS,$data);
}
... ... @@ -274,23 +274,6 @@ class FileController
}
/**
* @remark :获取文件链接
* @name :getImageUrl
* @author :lyh
* @method :post
* @time :2023/7/20 16:46
*/
public function getFileUrl(&$fileModel,$hash){
$info = $fileModel->read(['hash'=>$hash]);
if($info['is_cos'] == 1){
$url = getFileUrl($info['hash']);
}else{
$url = url('a/file/'.$info['hash']);
}
return $url;
}
/**
* @remark :获取所有视频
* @name :getImageList
* @author :lyh
... ... @@ -301,7 +284,7 @@ class FileController
$fileModel = new File();
$lists = $fileModel->list(['refer'=>1],$order = 'id',['id','hash','type','path','created_at']);
foreach ($lists as $k => $v){
$v['file_link'] = $this->getFileUrl($fileModel,$v['hash']);
$v['file_link'] = getFileUrl($v['hash']);
$lists[$k] = $v;
}
$this->response('success',Code::SUCCESS,$lists);
... ... @@ -314,11 +297,10 @@ class FileController
* @method :post
* @time :2023/7/26 13:41
*/
public function responseData(&$fileModel,$hash){
public function responseData($path){
$data = [
'file'=>$hash,
'file_link'=>$this->getFileUrl($fileModel,$hash),
'file_download'=>url('a/download_files?hash='.$hash),
'file'=>$path,
'file_link'=>getFileUrl($path),
];
return $data;
}
... ...
... ... @@ -152,7 +152,6 @@ class ImageController extends Controller
'image.required'=>'图片必须填写',
]);
$files = $this->request->file('image');
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($files, true) . PHP_EOL, FILE_APPEND);
if (empty($files)) {
$this->response('没有上传的文件!', Code::USER_ERROR);
}
... ... @@ -182,7 +181,7 @@ class ImageController extends Controller
$imageModel = new ImageModel();
$image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
if($image_hash !== false){
return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
return $this->response('图片资源',Code::SUCCESS,$this->responseData($image_hash['path']));
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
... ... @@ -197,7 +196,7 @@ class ImageController extends Controller
}
}
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
}
/**
... ... @@ -260,7 +259,7 @@ class ImageController extends Controller
$hash = hash_file('md5', $file->getPathname());
$image_hash = $imageModel->read(['hash'=>$hash,'refer'=>$this->param['refer'] ?? 0]);
if($image_hash !== false){
$data[] = $this->responseData($hash);
$data[] = $this->responseData($image_hash['path']);
continue;
}
$url = $this->config['root'].$this->path;
... ... @@ -277,7 +276,7 @@ class ImageController extends Controller
}
//批量存储
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location,$mime);
$data[] = $this->responseData($hash);
$data[] = $this->responseData($this->path.'/'.$fileName);
}
$this->response('图片资源',Code::SUCCESS,$data);
}
... ... @@ -388,11 +387,10 @@ class ImageController extends Controller
* @method :post
* @time :2023/7/26 13:41
*/
public function responseData($hash){
public function responseData($path = ''){
$data = [
'image'=>$hash,
'image_link'=>getImageUrl($hash),
'image_download'=>url('a/downLoad/images?hash='.$hash),
'image'=>$path,
'image_link'=>getImageUrl($path),
];
return $data;
}
... ...
... ... @@ -64,12 +64,12 @@ class ATemplateModuleLogic extends BaseLogic
*/
public function setAttribute($param){
if(isset($param['image']) && !empty($param['image'])){
$param['image'] = $this->imageName(basename($param['image']));
$param['image'] = basename($param['image']);
}
if(isset($param['images']) && !empty($param['images'])){
$arr_images = [];
foreach ($param['images'] as $v){
$arr_images[] = $this->imageName(basename($v));;
$arr_images[] = basename($v);
}
$param['images'] = implode(',',$arr_images);
}
... ...