新增附件管理
This commit is contained in:
parent
a752c7914a
commit
766d156bf8
31
catch/system/controller/Attachments.php
Normal file
31
catch/system/controller/Attachments.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use catchAdmin\system\model\Attachments as AttachmentsModel;
|
||||
use catcher\Utils;
|
||||
use think\facade\Filesystem;
|
||||
|
||||
class Attachments extends CatchController
|
||||
{
|
||||
|
||||
public function index(AttachmentsModel $model)
|
||||
{
|
||||
return CatchResponse::paginate($model->getList());
|
||||
}
|
||||
|
||||
public function delete($id, AttachmentsModel $model)
|
||||
{
|
||||
$ids = Utils::stringToArrayBy($id);
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$attachment = $model->findBy($id);
|
||||
if ($attachment && $model->deleteBy($id)) {
|
||||
Filesystem::delete($attachment->path);
|
||||
}
|
||||
}
|
||||
|
||||
return CatchResponse::success();
|
||||
}
|
||||
}
|
@ -7,11 +7,6 @@ use think\facade\Db;
|
||||
|
||||
class LoginLog extends CatchController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return CatchResponse::paginate(Db::name('login_log')->paginate(10));
|
||||
|
@ -7,11 +7,6 @@ use think\facade\Db;
|
||||
|
||||
class OperateLog extends CatchController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
return CatchResponse::paginate(
|
||||
|
@ -35,7 +35,9 @@ class Upload extends CatchController
|
||||
*/
|
||||
public function image(CatchRequest $request, CatchUpload $upload): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($upload->upload($request->file('image')));
|
||||
$images = $request->file();
|
||||
|
||||
return CatchResponse::success($upload->checkImages($images)->multiUpload($images['image']));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,6 +50,8 @@ class Upload extends CatchController
|
||||
*/
|
||||
public function file(CatchRequest $request, CatchUpload $upload): \think\response\Json
|
||||
{
|
||||
return CatchResponse::success($upload->upload($request->file('file')));
|
||||
$files = $request->file();
|
||||
|
||||
return CatchResponse::success($upload->checkFiles($files)->multiUpload($files['file']));
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class Attachments extends Migrator
|
||||
{
|
||||
$table = $this->table('attachments',['engine'=>'Myisam', 'comment' => '附件管理', 'signed' => false]);
|
||||
$table->addColumn('path', 'string',['limit' => 50,'default'=>'','comment'=>'附件存储路径'])
|
||||
->addColumn('url', 'string',['default'=> '', 'limit' => 100, 'comment'=>'资源地址'])
|
||||
->addColumn('mime_type', 'string',['default'=> '', 'limit' => 100, 'comment'=>'资源mimeType'])
|
||||
->addColumn('file_ext', 'string',['default'=> '','limit' => 100, 'comment'=>'资源后缀'])
|
||||
->addColumn('file_size', 'integer',['default'=> 0, 'comment'=>'资源大小'])
|
||||
|
@ -10,6 +10,7 @@ class Attachments extends CatchModel
|
||||
protected $field = [
|
||||
'id', //
|
||||
'path', // 附件存储路径
|
||||
'url', // 资源地址
|
||||
'mime_type', // 资源mimeType
|
||||
'file_ext', // 资源后缀
|
||||
'file_size', // 资源大小
|
||||
@ -19,4 +20,26 @@ class Attachments extends CatchModel
|
||||
'updated_at', // 更新时间
|
||||
'deleted_at', // 删除时间
|
||||
];
|
||||
|
||||
public function getList()
|
||||
{
|
||||
return $this->order('id', 'desc')
|
||||
->catchSearch()
|
||||
->paginate();
|
||||
}
|
||||
|
||||
public function searchFileExtAttr($query, $value, $data)
|
||||
{
|
||||
return $query->where('file_ext', $value);
|
||||
}
|
||||
|
||||
public function searchMimeTypesAttr($query, $value, $data)
|
||||
{
|
||||
return $query->where('mime_type', $value);
|
||||
}
|
||||
|
||||
public function searchDriver($query, $value, $data)
|
||||
{
|
||||
return $query->where('driver', $value);
|
||||
}
|
||||
}
|
||||
|
@ -17,3 +17,6 @@ $router->post('table/backup', '\catchAdmin\system\controller\DataDictionary@back
|
||||
// 上传
|
||||
$router->post('upload/image', '\catchAdmin\system\controller\Upload@image');
|
||||
$router->post('upload/file', '\catchAdmin\system\controller\Upload@file');
|
||||
|
||||
// 附件
|
||||
$router->resource('attachments', '\catchAdmin\system\controller\Attachments');
|
Loading…
x
Reference in New Issue
Block a user