recover
This commit is contained in:
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();
|
||||
}
|
||||
}
|
65
catch/system/controller/Config.php
Normal file
65
catch/system/controller/Config.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use app\Request;
|
||||
use catcher\base\CatchController;
|
||||
use catchAdmin\system\model\Config as ConfigModel;
|
||||
use catcher\CatchResponse;
|
||||
use think\response\Json;
|
||||
|
||||
class Config extends CatchController
|
||||
{
|
||||
protected $configModel;
|
||||
|
||||
public function __construct(ConfigModel $configModel)
|
||||
{
|
||||
$this->configModel = $configModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取父级别配置
|
||||
*
|
||||
* @time 2020年04月17日
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return Json
|
||||
*/
|
||||
public function parent()
|
||||
{
|
||||
return CatchResponse::success($this->configModel->getParentConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储配置
|
||||
*
|
||||
* @time 2020年04月17日
|
||||
* @param Request $request
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
return CatchResponse::success([
|
||||
'id' => $this->configModel->storeBy($request->param()),
|
||||
'parents' => $this->configModel->getParentConfig(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
*
|
||||
* @time 2020年04月20日
|
||||
* @param $id
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return Json
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
return CatchResponse::success($this->configModel->getConfig($id));
|
||||
}
|
||||
}
|
106
catch/system/controller/DataDictionary.php
Normal file
106
catch/system/controller/DataDictionary.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use think\facade\Console;
|
||||
use think\facade\Db;
|
||||
use think\Paginator;
|
||||
|
||||
class DataDictionary extends CatchController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function tables(Request $request): \think\response\Json
|
||||
{
|
||||
$tables = Db::query('show table status');
|
||||
|
||||
$tablename = $request->get('tablename');
|
||||
$engine = $request->get('engine');
|
||||
|
||||
$searchTables = [];
|
||||
$searchMode = false;
|
||||
if ($tablename || $engine) {
|
||||
$searchMode = true;
|
||||
}
|
||||
|
||||
foreach ($tables as $key => &$table) {
|
||||
$table = array_change_key_case($table);
|
||||
$table['index_length'] = $table['index_length'] > 1024 ? intval($table['index_length']/1024) .'MB' : $table['index_length'].'KB';
|
||||
$table['data_length'] = $table['data_length'] > 1024 ? intval($table['data_length']/1024) .'MB' : $table['data_length'].'KB';
|
||||
$table['create_time'] = date('Y-m-d', strtotime($table['create_time']));
|
||||
// 搜索
|
||||
if ($tablename && !$engine && stripos($table['name'], $tablename) !== false) {
|
||||
$searchTables[] = $table;
|
||||
}
|
||||
// 搜索
|
||||
if (!$tablename && $engine && stripos($table['engine'], $engine) !== false) {
|
||||
$searchTables[] = $table;
|
||||
}
|
||||
|
||||
if ($tablename && $engine && stripos($table['engine'], $engine) !== false && stripos($table['name'], $tablename) !== false) {
|
||||
$searchTables[] = $table;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CatchResponse::paginate(Paginator::make(!$searchMode ? $tables : $searchTables, $request->get('limit') ?? 10, $request->get('page') ?? 1, $searchMode ? count($searchTables) : count($tables), false, []));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @param $table
|
||||
* @return \think\response\Json
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function view($table): \think\response\Json
|
||||
{
|
||||
$fields = Db::query('show full columns from ' . $table);
|
||||
|
||||
array_walk($fields, function (&$item){
|
||||
$item = array_change_key_case($item);
|
||||
});
|
||||
|
||||
return CatchResponse::success($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function optimize(): \think\response\Json
|
||||
{
|
||||
$tables = \request()->post('data');
|
||||
|
||||
foreach ($tables as $table) {
|
||||
Db::query(sprintf('optimize table %s', $table));
|
||||
}
|
||||
|
||||
return CatchResponse::success([], '优化成功');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月13日
|
||||
* @throws FailedException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function backup(): \think\response\Json
|
||||
{
|
||||
try {
|
||||
Console::call('backup:data', [trim(implode(',', \request()->post('data')), ','), '-z']);
|
||||
}catch (\Exception $e) {
|
||||
throw new FailedException($e->getMessage());
|
||||
}
|
||||
|
||||
return CatchResponse::success([], '备份成功');
|
||||
}
|
||||
}
|
28
catch/system/controller/Generate.php
Normal file
28
catch/system/controller/Generate.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\generate\Generator;
|
||||
use think\Request;
|
||||
|
||||
class Generate extends CatchController
|
||||
{
|
||||
public function save(Request $request, Generator $generator)
|
||||
{
|
||||
return CatchResponse::success($generator->done($request->param()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览
|
||||
*
|
||||
* @time 2020年04月29日
|
||||
* @param Request $request
|
||||
* @param Generator $generator
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function preview(Request $request, Generator $generator)
|
||||
{
|
||||
return CatchResponse::success($generator->preview($request->param()));
|
||||
}
|
||||
}
|
35
catch/system/controller/LoginLog.php
Normal file
35
catch/system/controller/LoginLog.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use think\facade\Db;
|
||||
use catchAdmin\system\model\LoginLog as Log;
|
||||
|
||||
class LoginLog extends CatchController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param Log $log
|
||||
* @throws \think\db\exception\DbException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function list(Log $log)
|
||||
{
|
||||
return CatchResponse::paginate($log->paginate());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param Log $log
|
||||
* @throws \Exception
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function empty(Log $log)
|
||||
{
|
||||
return CatchResponse::success($log->where('id', '>', 0)->delete(), '清空成功');
|
||||
}
|
||||
}
|
34
catch/system/controller/OperateLog.php
Normal file
34
catch/system/controller/OperateLog.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use think\facade\Db;
|
||||
use catchAdmin\system\model\OperateLog as Log;
|
||||
|
||||
class OperateLog extends CatchController
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param Log $log
|
||||
* @throws \think\db\exception\DbException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function list(Log $log)
|
||||
{
|
||||
return CatchResponse::paginate($log->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年04月28日
|
||||
* @param Log $log
|
||||
* @throws \Exception
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function empty(Log $log)
|
||||
{
|
||||
return CatchResponse::success($log->where('id', '>', 0)->delete(), '清空成功');
|
||||
}
|
||||
}
|
57
catch/system/controller/Upload.php
Normal file
57
catch/system/controller/Upload.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @filename Upload.php
|
||||
* @createdAt 2020/1/25
|
||||
* @project https://github.com/yanwenwu/catch-admin
|
||||
* @document http://doc.catchadmin.com
|
||||
* @author JaguarJack <njphper@gmail.com>
|
||||
* @copyright By CatchAdmin
|
||||
* @license https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt
|
||||
*/
|
||||
namespace catchAdmin\system\controller;
|
||||
|
||||
use catchAdmin\system\model\Attachments;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\base\CatchRequest;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\CatchUpload;
|
||||
|
||||
class Upload extends CatchController
|
||||
{
|
||||
protected $attachment;
|
||||
|
||||
public function __construct(Attachments $attachment)
|
||||
{
|
||||
$this->attachment = $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* image upload
|
||||
*
|
||||
* @time 2020年01月25日
|
||||
* @param CatchRequest $request
|
||||
* @param CatchUpload $upload
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function image(CatchRequest $request, CatchUpload $upload): \think\response\Json
|
||||
{
|
||||
$images = $request->file();
|
||||
|
||||
return CatchResponse::success($upload->checkImages($images)->multiUpload($images['image']));
|
||||
}
|
||||
|
||||
/**
|
||||
* file upload
|
||||
*
|
||||
* @time 2020年01月25日
|
||||
* @param CatchRequest $request
|
||||
* @param CatchUpload $upload
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function file(CatchRequest $request, CatchUpload $upload): \think\response\Json
|
||||
{
|
||||
$files = $request->file();
|
||||
|
||||
return CatchResponse::success($upload->checkFiles($files)->multiUpload($files['file']));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user