|
...
|
...
|
@@ -37,7 +37,7 @@ class FileController |
|
|
|
|
|
|
|
public $cache = '';//缓存数据
|
|
|
|
public $upload_location = 1;
|
|
|
|
public $image_type = [
|
|
|
|
public $file_type = [
|
|
|
|
1 => 'file_other',
|
|
|
|
0 => 'file'
|
|
|
|
];
|
|
...
|
...
|
@@ -188,7 +188,7 @@ class FileController |
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$is_cos);
|
|
|
|
return $this->response('资源',Code::SUCCESS,['file'=>$hash]);
|
|
|
|
return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($hash)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -230,7 +230,7 @@ class FileController |
|
|
|
$hash = hash_file('md5', $file->getPathname());
|
|
|
|
$file_hash = $fileModel->read(['hash'=>$hash]);
|
|
|
|
if($file_hash !== false){
|
|
|
|
$data[] = $hash;
|
|
|
|
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($hash)];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$url = $this->config['root'].'/'.$this->path;
|
|
...
|
...
|
@@ -250,9 +250,9 @@ class FileController |
|
|
|
$size = $file->getSize();
|
|
|
|
$file_type = $file->getClientOriginalExtension();
|
|
|
|
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$is_cos);
|
|
|
|
$data[] = $hash;
|
|
|
|
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($hash)];
|
|
|
|
}
|
|
|
|
return $this->response('资源',Code::SUCCESS,['file'=>$data]);
|
|
|
|
return $this->response('资源',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -274,7 +274,7 @@ class FileController |
|
|
|
$result = [
|
|
|
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $this->_extents($data),
|
|
|
|
'data' => $data,
|
|
|
|
];
|
|
|
|
$this->header['Content-Type'] = $type;
|
|
|
|
$response = response($result,$result_code,$this->header);
|
|
...
|
...
|
@@ -282,37 +282,6 @@ class FileController |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @remark :参数处理
|
|
|
|
* @name :_extents
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/17 16:32
|
|
|
|
*/
|
|
|
|
protected function _extents($data) {
|
|
|
|
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
|
|
return empty($data) ? is_array($data) ? [] : '' : $data;
|
|
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
|
|
|
$data[$k] = $this->_extents($v);
|
|
|
|
} else {
|
|
|
|
if (is_null($v)) {
|
|
|
|
$data[$k] = '';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch ((string) $k) {
|
|
|
|
case 'file':
|
|
|
|
$data['file_link'] = url('/b/file_hash/'.$v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :文件下载
|
|
|
|
* @name :downLoad
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -346,16 +315,40 @@ class FileController |
|
|
|
* @time :2023/7/18 15:36
|
|
|
|
*/
|
|
|
|
public function setUrl(){
|
|
|
|
if(!isset($this->param['refer'])){
|
|
|
|
$this->param['refer'] = 1;
|
|
|
|
}
|
|
|
|
//A端上传
|
|
|
|
if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){
|
|
|
|
$this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
$this->path = $this->uploads['path_a'].'/'.$this->file_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
}else{
|
|
|
|
//B端上传
|
|
|
|
if(!isset($this->param['upload_method']) && $this->param['upload_method'] == 1){
|
|
|
|
//强制上传本地配置
|
|
|
|
$this->upload_location = 0;
|
|
|
|
}else{
|
|
|
|
//根据项目上传标识区分上传到cos/本地
|
|
|
|
$projectModel = new Project();
|
|
|
|
$project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']);
|
|
|
|
$this->upload_location = $project_info['upload_location'];
|
|
|
|
}
|
|
|
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->file_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取文件交接链接
|
|
|
|
* @name :getImageUrl
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/20 16:46
|
|
|
|
*/
|
|
|
|
public function getFileUrl($hash){
|
|
|
|
$fileModel = new File();
|
|
|
|
$info = $fileModel->read(['hash'=>$hash]);
|
|
|
|
if($info['is_cos'] == 1){
|
|
|
|
$cos = new CosService();
|
|
|
|
$url = $cos->getImageUrl($info['path']);
|
|
|
|
}else{
|
|
|
|
$projectModel = new Project();
|
|
|
|
$project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']);
|
|
|
|
$this->upload_location = $project_info['upload_location'];
|
|
|
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
|
|
|
|
$url = url('b/file_hash/'.$info['hash']);
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|