2023-02-28 15:13:10 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\cache\ExportCache;
|
|
|
|
use app\common\service\JsonService;
|
2024-01-19 23:37:35 +08:00
|
|
|
use support\Cache;
|
2023-02-28 15:13:10 +08:00
|
|
|
|
|
|
|
class DownloadController extends BaseAdminController
|
|
|
|
{
|
|
|
|
public $notNeedLogin = ['export'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @notes 导出文件
|
2023-03-10 13:44:21 +08:00
|
|
|
* @author 乔峰
|
2023-02-28 15:13:10 +08:00
|
|
|
* @date 2022/11/24 16:10
|
|
|
|
*/
|
|
|
|
public function export()
|
|
|
|
{
|
|
|
|
//获取文件缓存的key
|
|
|
|
$fileKey = request()->get('file');
|
|
|
|
|
|
|
|
//通过文件缓存的key获取文件储存的路径
|
|
|
|
$exportCache = new ExportCache();
|
|
|
|
$fileInfo = $exportCache->getFile($fileKey);
|
|
|
|
|
|
|
|
if (empty($fileInfo)) {
|
|
|
|
return JsonService::fail('下载文件不存在');
|
|
|
|
}
|
|
|
|
|
|
|
|
//下载前删除缓存
|
|
|
|
Cache::delete($fileKey);
|
|
|
|
|
2023-03-08 10:24:12 +08:00
|
|
|
return response()->download($fileInfo['src'] . $fileInfo['name'],$fileInfo['name']);
|
2023-02-28 15:13:10 +08:00
|
|
|
}
|
|
|
|
}
|