新增解析功能

This commit is contained in:
JaguarJack
2020-04-29 17:35:29 +08:00
parent 45af3fbc5f
commit 4d444e9bbc
68 changed files with 49 additions and 4863 deletions

View File

@@ -1,31 +0,0 @@
<?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();
}
}

View File

@@ -1,65 +0,0 @@
<?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));
}
}

View File

@@ -1,106 +0,0 @@
<?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([], '备份成功');
}
}

View File

@@ -1,28 +0,0 @@
<?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()));
}
}

View File

@@ -1,35 +0,0 @@
<?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(), '清空成功');
}
}

View File

@@ -1,34 +0,0 @@
<?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(), '清空成功');
}
}

View File

@@ -1,57 +0,0 @@
<?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']));
}
}

View File

@@ -1,40 +0,0 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class LoginLog extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('login_log',['engine'=>'Myisam', 'comment' => '登录日志', 'signed' => false]);
$table->addColumn('login_name', 'string',['limit' => 50,'default'=>'','comment'=>'用户名'])
->addColumn('login_ip', 'string',['default'=>0, 'limit' => 20, 'comment'=>'登录地点ip', 'signed' => false])
->addColumn('browser', 'string',['default'=> '','comment'=>'浏览器'])
->addColumn('os', 'string',['default'=> '','comment'=>'操作系统'])
->addColumn('login_at', 'integer', array('default'=>0,'comment'=>'登录时间', 'signed' => false ))
->addColumn('status', 'integer',['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY,'default'=> 1,'comment'=>'1 成功 2 失败'])
->create();
}
}

View File

@@ -1,42 +0,0 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class OperateLog extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('operate_log',['engine'=>'Myisam', 'comment' => '操作日志', 'signed' => false]);
$table->addColumn('module', 'string',['limit' => 50,'default'=>'','comment'=>'模块名称'])
->addColumn('operate', 'string',['default'=> '', 'limit' => 20, 'comment'=>'操作模块'])
->addColumn('route', 'string',['default'=> '','limit' => 100, 'comment'=>'路由'])
->addColumn('params', 'string',['default'=> '','limit' => 1000, 'comment'=>'参数'])
->addColumn('ip', 'string',['default'=>'', 'limit' => 20,'comment'=>'ip', 'signed' => false])
->addColumn('creator_id', 'integer',['default'=> 0,'comment'=>'创建人ID', 'signed' => false])
->addColumn('method', 'string',['default'=> '','comment'=>'请求方法'])
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'登录时间', 'signed' => false ))
->create();
}
}

View File

@@ -1,44 +0,0 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class Attachments extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$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'=>'资源大小'])
->addColumn('filename', 'string',['default'=>'', 'limit' => 255, 'comment'=>'资源名称'])
->addColumn('driver', 'string',['default'=> 0, 'limit' => 20, 'comment' => 'local,oss,qcloud,qiniu'])
->addColumn('created_at', 'integer', array('default'=>0, 'comment'=>'创建时间', 'signed' => false ))
->addColumn('updated_at', 'integer', array('default'=>0, 'comment'=>'更新时间', 'signed' => false ))
->addColumn('deleted_at', 'integer', array('default'=>0, 'comment'=>'删除时间', 'signed' => false ))
->create();
}
}

View File

@@ -1,44 +0,0 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class Config extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('config',['engine'=>'InnoDB', 'comment' => '配置管理', 'signed' => false]);
$table->addColumn('name', 'string',['limit' => 50,'default'=>'','comment'=>'配置名称'])
->addColumn('pid', 'integer', array('default'=> 0,'comment'=>'父级配置', 'signed' => false ))
->addColumn('component', 'string', ['default'=> '', 'limit' => 100, 'comment'=>'tab 引入的组件名称'])
->addColumn('key', 'string',['default'=> '', 'limit' => 100, 'comment'=>'配置键名'])
->addColumn('value', 'string',['default'=> '', 'limit' => 255, 'comment'=>'配置键值'])
->addColumn('status', 'integer',['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY,'default'=> 1,'comment'=>'1 启用 2 禁用'])
->addColumn('creator_id', 'integer', array('default'=> 0,'comment'=>'创建人', 'signed' => false ))
->addColumn('created_at', 'integer', ['default'=> 0,'comment'=>'创建时间', 'signed' => false])
->addColumn('updated_at', 'integer', ['default'=> 0,'comment'=>'更新时间', 'signed' => false])
->addColumn('deleted_at', 'integer', ['default'=> 0,'comment'=>'删除时间', 'signed' => false])
->create();
}
}

View File

@@ -1,36 +0,0 @@
<?php
use think\migration\Seeder;
class ConfigSeed extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
$data = [
[
'name' => '基础配置',
'pid' => 0,
'component' => 'basis',
'key' => 'basis',
],
[
'name' => '上传配置',
'pid' => 0,
'component' => 'upload',
'key' => 'upload',
],
];
foreach ($data as $item) {
\catchAdmin\system\model\Config::create($item);
}
}
}

View File

@@ -1,45 +0,0 @@
<?php
namespace catchAdmin\system\model;
use catcher\base\CatchModel;
class Attachments extends CatchModel
{
protected $name = 'attachments';
protected $field = [
'id', //
'path', // 附件存储路径
'url', // 资源地址
'mime_type', // 资源mimeType
'file_ext', // 资源后缀
'file_size', // 资源大小
'filename', // 资源名称
'driver', // local,oss,qcloud,qiniu
'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);
}
}

View File

@@ -1,210 +0,0 @@
<?php
namespace catchAdmin\system\model;
use catcher\base\CatchModel;
use thans\jwt\exception\UserNotDefinedException;
use think\Model;
class Config extends CatchModel
{
protected $name = 'config';
protected $pk = 'id';
protected $field = [
'id', //
'name', // 配置名称
'pid', // 父级配置
'key', // 配置键名
'value', // 配置键值
'component', // 组件
'status', // 1 启用 2 禁用
'creator_id', // 创建人
'created_at', // 创建时间
'updated_at', // 更新时间
'deleted_at', // 删除时间
];
/**
*
* @time 2020年04月17日
* @return \think\Collection
*@throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\db\exception\DataNotFoundException
*/
public function getParentConfig()
{
return $this->where('pid', 0)
->field(['id', 'name', 'component'])->select();
}
/**
* 存储配置
*
* @time 2020年04月20日
* @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return bool
*/
public function storeBy(array $data)
{
if (empty($data)) {
return true;
}
// 子配置
if ($data['pid'] ?? false) {
$config = \json_decode($data['config'], true);
$pid = $data['pid'];
unset($data['pid']);
/**[
'key' => [
'k' => 'v'
],
'k' => 'v'
]*/
foreach ($config as $key => $value) {
if (empty($value)) {
continue;
}
// 如果二级配置存在
$secondLevel = $this->isExistConfig($key, $pid);
if ($secondLevel) {
// value 是字符串
if (!is_array($value)) {
if ($value != $secondLevel->value) {
$secondLevel->value = $value;
$secondLevel->save();
}
} else {
// 数组
$thirdLevel = [];
$this->subConfig($secondLevel->id, ['id', 'key', 'value'])
->each(function ($item, $key) use (&$thirdLevel){
$thirdLevel[$item['key']] = $item;
});
if (!empty($value)) {
$new = [];
foreach ($value as $k => $v) {
if (isset($thirdLevel[$k])) {
if ($v != $thirdLevel[$k]->value) {
$thirdLevel[$k]->value = $v;
$thirdLevel[$k]->save();
}
} else {
$new[] = [
'pid' => $secondLevel->id,
'key' => $k,
'value' => $v,
];
}
}
if (!empty($new)) {
parent::insertAllBy($new);
}
}
}
} else {
if (!is_array($value)) {
parent::createBy([
'pid' => $pid,
'key' => $key,
'value' => $value,
]);
} else {
$id = parent::createBy([
'pid' => $pid,
'key' => $key,
]);
if (!empty($value)) {
$newConfig = [];
foreach ($value as $k => $v) {
$newConfig[] = [
'key' => $k,
'value' => $v,
'pid' => $id,
];
}
parent::insertAllBy($newConfig);
}
}
}
}
return true;
}
return parent::storeBy($data);
}
/**
* 配置是否存在
*
* @time 2020年04月19日
* @param $key
* @param int $pid
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return array|Model|null
*/
public function isExistConfig($key, $pid = 0)
{
return $this->where('pid', $pid)
->where('key', $key)
->find();
}
/**
* 获取子配置
*
* @time 2020年04月19日
* @param int $pid
* @param array $field
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return \think\Collection
*/
public function subConfig($pid = 0, array $field = ['*'])
{
return $this->where('pid', $pid)
->field($field)
->select();
}
/**
* 获取配置
*
* @time 2020年04月20日
* @param int $pid
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return array|mixed
*/
public function getConfig($pid = 0)
{
$data = [];
$configs = $this->where('pid', $pid)
->field('id,`key` as k,value,pid')
->select();
foreach ($configs as $config) {
if ($config->value !== '') {
$data[$config->k] = $config->value;
} else {
$data[$config->k] = $this->getConfig($config->id);
}
}
return $data;
}
}

View File

@@ -1,21 +0,0 @@
<?php
namespace catchAdmin\system\model;
use catcher\traits\db\BaseOptionsTrait;
class LoginLog extends \think\Model
{
use BaseOptionsTrait;
protected $name = 'login_log';
protected $field = [
'id', //
'login_name', // 用户名
'login_ip', // 登录地点ip
'browser', // 浏览器
'os', // 操作系统
'login_at', // 登录时间
'status', // 1 成功 2 失败
];
}

View File

@@ -1,40 +0,0 @@
<?php
namespace catchAdmin\system\model;
use catchAdmin\permissions\model\Users;
use catcher\traits\db\BaseOptionsTrait;
class OperateLog extends \think\Model
{
use BaseOptionsTrait;
protected $name = 'operate_log';
protected $field = [
'id', //
'module', // 模块名称
'operate', // 操作模块
'route', // 路由
'params', // 参数
'ip', // ip
'creator_id', // 创建人ID
'method', // 请求方法
'created_at', // 登录时间
];
/**
* get list
*
* @time 2020年04月28日
* @param $params
* @throws \think\db\exception\DbException
* @return void
*/
public function getList()
{
return $this->field([$this->aliasField('*')])
->catchJoin(Users::class, 'id', 'creator_id', ['username as creator'])
->order($this->aliasField('id'), 'desc')
->paginate();
}
}

View File

@@ -1,11 +0,0 @@
{
"name": "系统管理",
"alias": "system",
"description": "",
"keywords": [],
"order": 2,
"services": [],
"aliases": {},
"files": [],
"requires": []
}

View File

@@ -1,28 +0,0 @@
<?php
// 登录日志
$router->get('log/login', '\catchAdmin\system\controller\LoginLog@list');
$router->delete('loginLog/empty', '\catchAdmin\system\controller\LoginLog@empty');
// 操作日志
$router->get('log/operate', '\catchAdmin\system\controller\OperateLog@list');
$router->delete('operateLog/empty', '\catchAdmin\system\controller\OperateLog@empty');
// 数据字典
$router->get('tables', '\catchAdmin\system\controller\DataDictionary@tables');
$router->get('table/view/<table>', '\catchAdmin\system\controller\DataDictionary@view');
$router->post('table/optimize', '\catchAdmin\system\controller\DataDictionary@optimize');
$router->post('table/backup', '\catchAdmin\system\controller\DataDictionary@backup');
// 上传
$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');
// 配置
$router->get('config/parent', '\catchAdmin\system\controller\Config@parent');
$router->resource('config', '\catchAdmin\system\controller\Config');
// 代码生成
$router->post('generate', '\catchAdmin\system\controller\Generate@save');
$router->post('generate/preview', '\catchAdmin\system\controller\Generate@preview'); // 预览