作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -38,8 +38,9 @@ class FileController
public $cache = '';//缓存数据
public $upload_location = 1;
public $file_type = [
1 => 'file_other',
0 => 'file'
2 => 'other',//其他
1 => 'video',//视频
0 => 'file'//文件
];
public function __construct()
{
... ... @@ -169,7 +170,7 @@ class FileController
$hash = hash_file('md5', $files->getPathname());
//查看文件是否存在
$fileModel = new File();
$file_hash = $fileModel->read(['hash'=>$hash]);
$file_hash = $fileModel->read(['hash'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]);
if($file_hash !== false){
return $this->response('资源',Code::SUCCESS,['file'=>$hash]);
}
... ... @@ -178,17 +179,15 @@ class FileController
//同步数据到cos
if($this->upload_location == 1){
$cosService = new CosService();
$is_cos = 1;//上传到cos
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$is_cos = 0;
$res = $files->move($url,$fileName);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
}
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$is_cos);
return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($hash)]);
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location);
return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]);
}
/**
... ... @@ -230,7 +229,7 @@ class FileController
$hash = hash_file('md5', $file->getPathname());
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($hash)];
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)];
continue;
}
$url = $this->config['root'].'/'.$this->path;
... ... @@ -238,10 +237,8 @@ class FileController
//同步数据到cos
if($this->upload_location == 1){
$cosService = new CosService();
$is_cos = 1;//上传到cos
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$is_cos = 0;
$res = $files->move($url,$fileName);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
... ... @@ -249,8 +246,8 @@ class FileController
}
$size = $file->getSize();
$file_type = $file->getClientOriginalExtension();
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$is_cos);
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($hash)];
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location);
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)];
}
return $this->response('资源',Code::SUCCESS,$data);
}
... ... @@ -288,23 +285,26 @@ class FileController
* @method :post
* @time :2023/6/26 16:28
*/
public function downLoad($hash){
public function downLoad(){
$file_model = new File();
$info = $file_model->read(['hash' => $hash]);
$info = $file_model->read(['hash' => $this->param['hash']]);
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$path = $this->config['url'].'/'.$info['path'];
if (!is_file($path)) {
$this->response('指定文件已被系统删除!', Code::USER_ERROR);
if($info['is_cos'] == 1){
}else{
$fileUrl = $this->config['root'].'/'.$info['path'];
if (!is_file($fileUrl)) {
$this->response('指定文件已被系统删除!', Code::USER_ERROR);
}
$fileName = 'downloaded_file'.'.'.$info['type']; // 要保存的文件名
// 设置响应头
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
// 下载文件
readfile($fileUrl);
}
$fileUrl = url('upload'.$path); // 文件的 URL
$fileName = 'downloaded_file'.'.'.$info['type']; // 要保存的文件名
// 设置响应头
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
// 下载文件
readfile($fileUrl);
}
/**
... ... @@ -340,8 +340,8 @@ class FileController
* @method :post
* @time :2023/7/20 16:46
*/
public function getFileUrl($hash){
$fileModel = new File();
public function getFileUrl(&$fileModel,$hash){
$info = $fileModel->read(['hash'=>$hash]);
if($info['is_cos'] == 1){
$cos = new CosService();
... ... @@ -351,4 +351,21 @@ class FileController
}
return $url;
}
/**
* @remark :获取所有视频
* @name :getImageList
* @author :lyh
* @method :post
* @time :2023/6/29 11:48
*/
public function getFileList(){
$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']);
$lists[$k] = $v;
}
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -43,7 +43,7 @@ class CategoryLogic extends BaseLogic
public function getInfo($id)
{
$info = parent::getInfo($id);
$info = $this->model->read(['id'=>$id]);
$info['url'] = $this->getProjectDomain() . $info['route'] ;
$info['image_link'] = $this->getImageUrl($info['image']);
return $this->success($info);
... ...
... ... @@ -60,4 +60,24 @@ class CosService
$imageUrl = $cosClient->getObjectUrl($cos['bucket'], trim($image_name,'/'), '+10 years');
return $imageUrl;
}
/**
* @remark :下载文件
* @name :downloadFile
* @author :lyh
* @method :post
* @time :2023/7/21 14:56
*/
public function downloadFile($file_name){
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
'region' => $cos['region'],
'credentials' => [
'secretId' => $cos['credentials']['secretId'],
'secretKey' => $cos['credentials']['secretKey'],
],
]);
$saveAs = 'C:\Users\\' . get_current_user() . '\Desktop\filename.ext';
return $cosClient->getObject(['Bucket' => $cos['bucket'], 'Key' => trim($file_name,'/'), 'SaveAs' => $saveAs]);
}
}
... ...
... ... @@ -208,17 +208,20 @@ Route::middleware(['bloginauth'])->group(function () {
});
//文件操作
Route::prefix('file')->group(function () {
Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
Route::get('/lists', [\App\Http\Controllers\Bside\FileController::class, 'lists'])->name('file_lists');
});
// Route::prefix('file')->group(function () {
// Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
// Route::get('/lists', [\App\Http\Controllers\Bside\FileController::class, 'lists'])->name('file_lists');
// });
//图片操作
Route::prefix('images')->group(function () {
Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('image_upload');
Route::any('/getImageList', [\App\Http\Controllers\File\ImageController::class, 'getImageList'])->name('image_getImageList');
});
//文件操作
Route::prefix('files')->group(function () {
Route::post('/upload', [\App\Http\Controllers\File\FileController::class, 'upload'])->name('files_upload');
Route::any('/getFileList', [\App\Http\Controllers\File\FileController::class, 'getFileList'])->name('files_getFileList');
Route::any('/downLoad', [\App\Http\Controllers\File\FileController::class, 'downLoad'])->name('files_downLoad');
});
//精准询盘
Route::prefix('inquiry')->group(function () {
... ... @@ -334,7 +337,6 @@ Route::middleware(['bloginauth'])->group(function () {
Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
Route::any('/stringTranslation', [\App\Http\Controllers\Bside\ComController::class, 'stringTranslation'])->name('com_stringTranslation');
Route::any('/getImageList', [\App\Http\Controllers\File\ImageController::class, 'getImageList'])->name('image_getImageList');
Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms');
Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class, 'index'])->name('image_show');
... ...