代码下载接口
This commit is contained in:
@@ -46,4 +46,16 @@ class CodeGenerationController extends BaseController
|
||||
return $this->service->download($id);
|
||||
}
|
||||
|
||||
public function downloadInfo()
|
||||
{
|
||||
// $id = request()->post('id');
|
||||
$id = request()->get('id');
|
||||
if (!$id) {
|
||||
return jerr('参数错误!');
|
||||
}
|
||||
return jok(
|
||||
$this->service->downloadInfo($id)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,6 +77,12 @@ class CodeGenerationService
|
||||
return self::$_instance[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
* @param $id
|
||||
* @return BinaryFileResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function download($id)
|
||||
{
|
||||
$model = CodeGenerationModel::find($id);
|
||||
@@ -88,7 +94,23 @@ class CodeGenerationService
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时文件夹,复制模板文件,压缩并返回文件流
|
||||
* 下载文件信息
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function downloadInfo($id)
|
||||
{
|
||||
$model = CodeGenerationModel::find($id);
|
||||
if (!$model) {
|
||||
$this->utils->errorThrow('文件不存在');
|
||||
}
|
||||
// 返回下载 $path 文件流
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时文件夹,复制模板文件,压缩并文件信息
|
||||
*/
|
||||
public function downloadUrl()
|
||||
{
|
||||
@@ -118,7 +140,10 @@ class CodeGenerationService
|
||||
'created_at' => time(),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
return $insertModel->id;
|
||||
return [
|
||||
'id' => $insertModel->id,
|
||||
'file_name' => $insertModel->file_name
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'error' => '生成模板文件失败',
|
||||
@@ -127,6 +152,10 @@ class CodeGenerationService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化参数
|
||||
* @return void
|
||||
*/
|
||||
private function init()
|
||||
{
|
||||
// 生成uuid
|
||||
|
||||
Reference in New Issue
Block a user