diff --git a/catch/system/controller/Attachments.php b/catch/system/controller/Attachments.php new file mode 100644 index 0000000..646d564 --- /dev/null +++ b/catch/system/controller/Attachments.php @@ -0,0 +1,31 @@ +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(); + } +} diff --git a/catch/system/controller/LoginLog.php b/catch/system/controller/LoginLog.php index 001ab30..f5f3ef7 100644 --- a/catch/system/controller/LoginLog.php +++ b/catch/system/controller/LoginLog.php @@ -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)); diff --git a/catch/system/controller/OperateLog.php b/catch/system/controller/OperateLog.php index a649d7d..1d35e82 100644 --- a/catch/system/controller/OperateLog.php +++ b/catch/system/controller/OperateLog.php @@ -7,11 +7,6 @@ use think\facade\Db; class OperateLog extends CatchController { - public function index() - { - return $this->fetch(); - } - public function list() { return CatchResponse::paginate( diff --git a/catch/system/controller/Upload.php b/catch/system/controller/Upload.php index efdcc81..d3d5f39 100644 --- a/catch/system/controller/Upload.php +++ b/catch/system/controller/Upload.php @@ -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'])); } } diff --git a/catch/system/database/migrations/20200125133249_attachments.php b/catch/system/database/migrations/20200125133249_attachments.php index 1395114..c007140 100644 --- a/catch/system/database/migrations/20200125133249_attachments.php +++ b/catch/system/database/migrations/20200125133249_attachments.php @@ -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'=>'资源大小']) diff --git a/catch/system/model/Attachments.php b/catch/system/model/Attachments.php index ff84582..9a340c0 100644 --- a/catch/system/model/Attachments.php +++ b/catch/system/model/Attachments.php @@ -10,6 +10,7 @@ class Attachments extends CatchModel protected $field = [ 'id', // 'path', // 附件存储路径 + 'url', // 资源地址 'mime_type', // 资源mimeType 'file_ext', // 资源后缀 'file_size', // 资源大小 @@ -18,5 +19,27 @@ class Attachments extends CatchModel 'created_at', // 创建时间 '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); + } } diff --git a/catch/system/route.php b/catch/system/route.php index d8c1962..b7631d8 100644 --- a/catch/system/route.php +++ b/catch/system/route.php @@ -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'); \ No newline at end of file