初始化-安装依赖
This commit is contained in:
363
server/plugin/saiadmin/app/controller/InstallController.php
Normal file
363
server/plugin/saiadmin/app/controller/InstallController.php
Normal file
@@ -0,0 +1,363 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller;
|
||||
|
||||
use Throwable;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\saiadmin\exception\ApiException;
|
||||
use plugin\saiadmin\basic\OpenController;
|
||||
|
||||
/**
|
||||
* 安装控制器
|
||||
*/
|
||||
class InstallController extends OpenController
|
||||
{
|
||||
/**
|
||||
* 不需要登录的方法
|
||||
*/
|
||||
protected array $noNeedLogin = ['index', 'install'];
|
||||
|
||||
/**
|
||||
* 应用名称
|
||||
* @var string
|
||||
*/
|
||||
protected string $app = 'saiadmin';
|
||||
|
||||
protected string $version = '6.0.0';
|
||||
|
||||
/**
|
||||
* 安装首页
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['app'] = $this->app;
|
||||
$data['version'] = config('plugin.saiadmin.app.version', $this->version);
|
||||
|
||||
$env = base_path() . DIRECTORY_SEPARATOR . '.env';
|
||||
|
||||
clearstatcache();
|
||||
if (is_file($env)) {
|
||||
$data['error'] = '程序已经安装';
|
||||
return view('install/error', $data);
|
||||
}
|
||||
|
||||
if (!is_writable(base_path() . DIRECTORY_SEPARATOR . 'config')) {
|
||||
$data['error'] = '权限认证失败';
|
||||
return view('install/error', $data);
|
||||
}
|
||||
|
||||
return view('install/index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行安装
|
||||
*/
|
||||
public function install(Request $request)
|
||||
{
|
||||
$env = base_path() . DIRECTORY_SEPARATOR . '.env';
|
||||
|
||||
clearstatcache();
|
||||
if (is_file($env)) {
|
||||
return $this->fail('管理后台已经安装!如需重新安装,请删除根目录env配置文件并重启');
|
||||
}
|
||||
|
||||
$user = $request->post('username');
|
||||
$password = $request->post('password');
|
||||
$database = $request->post('database');
|
||||
$host = $request->post('host');
|
||||
$port = (int) $request->post('port') ?: 3306;
|
||||
$dataType = $request->post('dataType', 'demo');
|
||||
|
||||
try {
|
||||
$db = $this->getPdo($host, $user, $password, $port);
|
||||
$smt = $db->query("show databases like '$database'");
|
||||
if (empty($smt->fetchAll())) {
|
||||
$db->exec("create database `$database` CHARSET utf8mb4 COLLATE utf8mb4_general_ci");
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$message = $e->getMessage();
|
||||
if (stripos($message, 'Access denied for user')) {
|
||||
return $this->fail('数据库用户名或密码错误');
|
||||
}
|
||||
if (stripos($message, 'Connection refused')) {
|
||||
return $this->fail('Connection refused. 请确认数据库IP端口是否正确,数据库已经启动');
|
||||
}
|
||||
if (stripos($message, 'timed out')) {
|
||||
return $this->fail('数据库连接超时,请确认数据库IP端口是否正确,安全组及防火墙已经放行端口');
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$db->exec("use `$database`");
|
||||
|
||||
$smt = $db->query("show tables like 'sa_system_menu';");
|
||||
$tables = $smt->fetchAll();
|
||||
if (count($tables) > 0) {
|
||||
return $this->fail('数据库已经安装,请勿重复安装');
|
||||
}
|
||||
|
||||
if ($dataType == 'demo') {
|
||||
$sql_file = base_path() . '/plugin/saiadmin/db/saiadmin-6.0.sql';
|
||||
} else {
|
||||
$sql_file = base_path() . '/plugin/saiadmin/db/saiadmin-pure.sql';
|
||||
}
|
||||
|
||||
if (!is_file($sql_file)) {
|
||||
return $this->fail('数据库SQL文件不存在');
|
||||
}
|
||||
|
||||
$sql_query = file_get_contents($sql_file);
|
||||
|
||||
$db->exec($sql_query);
|
||||
|
||||
$this->generateConfig();
|
||||
|
||||
$env_config = <<<EOF
|
||||
# 数据库配置
|
||||
DB_TYPE = mysql
|
||||
DB_HOST = $host
|
||||
DB_PORT = $port
|
||||
DB_NAME = $database
|
||||
DB_USER = $user
|
||||
DB_PASSWORD = $password
|
||||
DB_PREFIX =
|
||||
|
||||
# 缓存方式
|
||||
CACHE_MODE = file
|
||||
|
||||
# Redis配置
|
||||
REDIS_HOST = 127.0.0.1
|
||||
REDIS_PORT = 6379
|
||||
REDIS_PASSWORD = ''
|
||||
REDIS_DB = 0
|
||||
|
||||
# 验证码配置
|
||||
CAPTCHA_MODE = cache
|
||||
|
||||
#前端目录
|
||||
FRONTEND_DIR = saiadmin-artd
|
||||
EOF;
|
||||
file_put_contents(base_path() . DIRECTORY_SEPARATOR . '.env', $env_config);
|
||||
|
||||
// 尝试reload
|
||||
if (function_exists('posix_kill')) {
|
||||
set_error_handler(function () {});
|
||||
posix_kill(posix_getppid(), SIGUSR1);
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
return $this->success('安装成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成配置文件
|
||||
*/
|
||||
protected function generateConfig()
|
||||
{
|
||||
// 1、think-orm配置文件
|
||||
$think_orm_config = <<<EOF
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => 'mysql',
|
||||
'connections' => [
|
||||
'mysql' => [
|
||||
// 数据库类型
|
||||
'type' => env('DB_TYPE', 'mysql'),
|
||||
// 服务器地址
|
||||
'hostname' => env('DB_HOST', '127.0.0.1'),
|
||||
// 数据库名
|
||||
'database' => env('DB_NAME', 'saiadmin'),
|
||||
// 数据库用户名
|
||||
'username' => env('DB_USER', 'root'),
|
||||
// 数据库密码
|
||||
'password' => env('DB_PASSWORD', '123456'),
|
||||
// 数据库连接端口
|
||||
'hostport' => env('DB_PORT', 3306),
|
||||
// 数据库连接参数
|
||||
'params' => [
|
||||
// 连接超时3秒
|
||||
\PDO::ATTR_TIMEOUT => 3,
|
||||
],
|
||||
// 数据库编码默认采用utf8
|
||||
'charset' => 'utf8',
|
||||
// 数据库表前缀
|
||||
'prefix' => env('DB_PREFIX', ''),
|
||||
// 断线重连
|
||||
'break_reconnect' => true,
|
||||
// 自定义分页类
|
||||
'bootstrap' => '',
|
||||
// 连接池配置
|
||||
'pool' => [
|
||||
'max_connections' => 5, // 最大连接数
|
||||
'min_connections' => 1, // 最小连接数
|
||||
'wait_timeout' => 3, // 从连接池获取连接等待超时时间
|
||||
'idle_timeout' => 60, // 连接最大空闲时间,超过该时间会被回收
|
||||
'heartbeat_interval' => 50, // 心跳检测间隔,需要小于60秒
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
EOF;
|
||||
file_put_contents(base_path() . '/config/think-orm.php', $think_orm_config);
|
||||
|
||||
// 2、chache配置文件
|
||||
$cache_config = <<<EOF
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => env('CACHE_MODE', 'file'),
|
||||
'stores' => [
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => runtime_path('cache')
|
||||
],
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => 'default'
|
||||
],
|
||||
'array' => [
|
||||
'driver' => 'array'
|
||||
]
|
||||
]
|
||||
];
|
||||
EOF;
|
||||
file_put_contents(base_path() . '/config/cache.php', $cache_config);
|
||||
|
||||
// 3、redis配置文件
|
||||
$redis_config = <<<EOF
|
||||
<?php
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'password' => env('REDIS_PASSWORD', ''),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'port' => env('REDIS_PORT', 6379),
|
||||
'database' => env('REDIS_DB', 0),
|
||||
'pool' => [
|
||||
'max_connections' => 5,
|
||||
'min_connections' => 1,
|
||||
'wait_timeout' => 3,
|
||||
'idle_timeout' => 60,
|
||||
'heartbeat_interval' => 50,
|
||||
],
|
||||
]
|
||||
];
|
||||
EOF;
|
||||
file_put_contents(base_path() . '/config/redis.php', $redis_config);
|
||||
|
||||
// 4、think-cache配置文件
|
||||
$think_cache_config = <<<EOF
|
||||
<?php
|
||||
return [
|
||||
// 默认缓存驱动
|
||||
'default' => env('CACHE_MODE', 'file'),
|
||||
// 缓存连接方式配置
|
||||
'stores' => [
|
||||
// redis缓存
|
||||
'redis' => [
|
||||
// 驱动方式
|
||||
'type' => 'redis',
|
||||
// 服务器地址
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
// 服务器端口
|
||||
'port' => env('REDIS_PORT', 6379),
|
||||
// 服务器密码
|
||||
'password' => env('REDIS_PASSWORD', ''),
|
||||
// 数据库
|
||||
'select' => env('REDIS_DB', 0),
|
||||
// 缓存前缀
|
||||
'prefix' => 'cache:',
|
||||
// 默认缓存有效期 0表示永久缓存
|
||||
'expire' => 0,
|
||||
// Thinkphp官方没有这个参数,由于生成的tag键默认不过期,如果tag键数量很大,避免长时间占用内存,可以设置一个超过其他缓存的过期时间,0为不设置
|
||||
'tag_expire' => 86400 * 30,
|
||||
// 缓存标签前缀
|
||||
'tag_prefix' => 'tag:',
|
||||
// 连接池配置
|
||||
'pool' => [
|
||||
'max_connections' => 5, // 最大连接数
|
||||
'min_connections' => 1, // 最小连接数
|
||||
'wait_timeout' => 3, // 从连接池获取连接等待超时时间
|
||||
'idle_timeout' => 60, // 连接最大空闲时间,超过该时间会被回收
|
||||
'heartbeat_interval' => 50, // 心跳检测间隔,需要小于60秒
|
||||
],
|
||||
],
|
||||
// 文件缓存
|
||||
'file' => [
|
||||
// 驱动方式
|
||||
'type' => 'file',
|
||||
// 设置不同的缓存保存目录
|
||||
'path' => runtime_path() . '/file/',
|
||||
],
|
||||
],
|
||||
];
|
||||
EOF;
|
||||
file_put_contents(base_path() . '/config/think-cache.php', $think_cache_config);
|
||||
|
||||
// 5、database配置文件
|
||||
$database = <<<EOF
|
||||
<?php
|
||||
return [
|
||||
'default' => 'mysql',
|
||||
'connections' => [
|
||||
'mysql' => [
|
||||
'driver' => env('DB_TYPE', 'mysql'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', 3306),
|
||||
'database' => env('DB_NAME', 'saiadmin'),
|
||||
'username' => env('DB_USER', 'root'),
|
||||
'password' => env('DB_PASSWORD', '123456'),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'collation' => env('DB_COLLATION', 'utf8mb4_general_ci'),
|
||||
'prefix' => env('DB_PREFIX', ''),
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => [
|
||||
PDO::ATTR_EMULATE_PREPARES => false, // Must be false for Swoole and Swow drivers.
|
||||
],
|
||||
'pool' => [
|
||||
'max_connections' => 5,
|
||||
'min_connections' => 1,
|
||||
'wait_timeout' => 3,
|
||||
'idle_timeout' => 60,
|
||||
'heartbeat_interval' => 50,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
EOF;
|
||||
file_put_contents(base_path() . '/config/database.php', $database);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取pdo连接
|
||||
* @param $host
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @param $port
|
||||
* @param $database
|
||||
* @return \PDO
|
||||
*/
|
||||
protected function getPdo($host, $username, $password, $port, $database = null): \PDO
|
||||
{
|
||||
$dsn = "mysql:host=$host;port=$port;";
|
||||
if ($database) {
|
||||
$dsn .= "dbname=$database";
|
||||
}
|
||||
$params = [
|
||||
\PDO::MYSQL_ATTR_INIT_COMMAND => "set names utf8mb4",
|
||||
\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
|
||||
\PDO::ATTR_EMULATE_PREPARES => false,
|
||||
\PDO::ATTR_TIMEOUT => 5,
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
|
||||
];
|
||||
return new \PDO($dsn, $username, $password, $params);
|
||||
}
|
||||
}
|
||||
61
server/plugin/saiadmin/app/controller/LoginController.php
Normal file
61
server/plugin/saiadmin/app/controller/LoginController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller;
|
||||
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\saiadmin\utils\Captcha;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemUserLogic;
|
||||
|
||||
/**
|
||||
* 登录控制器
|
||||
*/
|
||||
class LoginController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 不需要登录的方法
|
||||
*/
|
||||
protected array $noNeedLogin = ['captcha', 'login'];
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
public function captcha() : Response
|
||||
{
|
||||
$captcha = new Captcha();
|
||||
$result = $captcha->imageCaptcha();
|
||||
if ($result['result'] !== 1) {
|
||||
return $this->fail($result['message']);
|
||||
}
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function login(Request $request): Response
|
||||
{
|
||||
$username = $request->post('username', '');
|
||||
$password = $request->post('password', '');
|
||||
$type = $request->post('type', 'pc');
|
||||
|
||||
$code = $request->post('code', '');
|
||||
$uuid = $request->post('uuid', '');
|
||||
$captcha = new Captcha();
|
||||
if (!$captcha->checkCaptcha($uuid, $code)) {
|
||||
return $this->fail('验证码错误');
|
||||
}
|
||||
$logic = new SystemUserLogic();
|
||||
$data = $logic->login($username, $password, $type);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
263
server/plugin/saiadmin/app/controller/SystemController.php
Normal file
263
server/plugin/saiadmin/app/controller/SystemController.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller;
|
||||
|
||||
use plugin\saiadmin\app\cache\DictCache;
|
||||
use plugin\saiadmin\app\cache\UserAuthCache;
|
||||
use plugin\saiadmin\app\cache\UserInfoCache;
|
||||
use plugin\saiadmin\app\cache\UserMenuCache;
|
||||
use plugin\saiadmin\app\logic\system\SystemCategoryLogic;
|
||||
use plugin\saiadmin\app\logic\system\SystemLoginLogLogic;
|
||||
use plugin\saiadmin\app\logic\system\SystemOperLogLogic;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemUserLogic;
|
||||
use plugin\saiadmin\app\logic\system\SystemAttachmentLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\saiadmin\utils\Arr;
|
||||
use Tinywan\Storage\Storage;
|
||||
|
||||
/**
|
||||
* 系统控制器
|
||||
*/
|
||||
class SystemController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
public function userInfo(): Response
|
||||
{
|
||||
$info['user'] = $this->adminInfo;
|
||||
$info = [];
|
||||
$info['id'] = $this->adminInfo['id'];
|
||||
$info['username'] = $this->adminInfo['username'];
|
||||
$info['dashboard'] = $this->adminInfo['dashboard'];
|
||||
$info['avatar'] = $this->adminInfo['avatar'];
|
||||
$info['email'] = $this->adminInfo['email'];
|
||||
$info['phone'] = $this->adminInfo['phone'];
|
||||
$info['gender'] = $this->adminInfo['gender'];
|
||||
$info['signed'] = $this->adminInfo['signed'];
|
||||
$info['realname'] = $this->adminInfo['realname'];
|
||||
$info['department'] = $this->adminInfo['deptList'];
|
||||
if ($this->adminInfo['id'] === 1) {
|
||||
$info['buttons'] = ['*'];
|
||||
$info['roles'] = ['super_admin'];
|
||||
} else {
|
||||
$info['buttons'] = UserAuthCache::getUserAuth($this->adminInfo['id']);
|
||||
$info['roles'] = Arr::getArrayColumn($this->adminInfo['roleList'], 'code');
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部字典数据
|
||||
*/
|
||||
public function dictAll(): Response
|
||||
{
|
||||
$dict = DictCache::getDictAll();
|
||||
return $this->success($dict);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单数据
|
||||
* @return Response
|
||||
*/
|
||||
public function menu(): Response
|
||||
{
|
||||
$data = UserMenuCache::getUserMenu($this->adminInfo['id']);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件列表读取', 'core:system:resource')]
|
||||
public function getResourceCategory(Request $request): Response
|
||||
{
|
||||
$logic = new SystemCategoryLogic();
|
||||
$data = $logic->tree([]);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件列表读取', 'core:system:resource')]
|
||||
public function getResourceList(Request $request): Response
|
||||
{
|
||||
$logic = new SystemAttachmentLogic();
|
||||
$where = $request->more([
|
||||
['origin_name', ''],
|
||||
['category_id', ''],
|
||||
]);
|
||||
$query = $logic->search($where);
|
||||
$query->whereIn('mime_type', ['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
|
||||
$data = $logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户列表读取', 'core:system:user')]
|
||||
public function getUserList(Request $request): Response
|
||||
{
|
||||
$logic = new SystemUserLogic();
|
||||
$where = $request->more([
|
||||
['keyword', ''],
|
||||
['dept_id', ''],
|
||||
]);
|
||||
$data = $logic->openUserList($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载网络图片
|
||||
*/
|
||||
#[Permission('上传网络图片', 'core:system:uploadImage')]
|
||||
public function saveNetworkImage(Request $request): Response
|
||||
{
|
||||
$url = $request->input('url', '');
|
||||
$config = Storage::getConfig('local');
|
||||
$logic = new SystemAttachmentLogic();
|
||||
$data = $logic->saveNetworkImage($url, $config);
|
||||
return $this->success($data, '操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
#[Permission('上传图片', 'core:system:uploadImage')]
|
||||
public function uploadImage(Request $request): Response
|
||||
{
|
||||
$logic = new SystemAttachmentLogic();
|
||||
$type = $request->input('mode', 'system');
|
||||
if ($type == 'local') {
|
||||
return $this->success($logic->uploadBase('image', true));
|
||||
}
|
||||
return $this->success($logic->uploadBase('image'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
#[Permission('上传文件', 'core:system:uploadFile')]
|
||||
public function uploadFile(Request $request): Response
|
||||
{
|
||||
$logic = new SystemAttachmentLogic();
|
||||
$type = $request->input('mode', 'system');
|
||||
if ($type == 'local') {
|
||||
return $this->success($logic->uploadBase('file', true));
|
||||
}
|
||||
return $this->success($logic->uploadBase('file'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 切片上传
|
||||
*/
|
||||
#[Permission('上传文件', 'core:system:chunkUpload')]
|
||||
public function chunkUpload(Request $request): Response
|
||||
{
|
||||
$logic = new SystemAttachmentLogic();
|
||||
$data = $request->post();
|
||||
$result = $logic->chunkUpload($data);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录日志
|
||||
* @return Response
|
||||
*/
|
||||
public function getLoginLogList(): Response
|
||||
{
|
||||
$logic = new SystemLoginLogLogic();
|
||||
$logic->init($this->adminInfo);
|
||||
$query = $logic->search(['username' => $this->adminName]);
|
||||
$data = $logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作日志
|
||||
* @return Response
|
||||
*/
|
||||
public function getOperationLogList(): Response
|
||||
{
|
||||
$logic = new SystemOperLogLogic();
|
||||
$logic->init($this->adminInfo);
|
||||
$data = $logic->getOwnOperLogList(['username' => $this->adminName]);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* @return Response
|
||||
*/
|
||||
public function clearAllCache(): Response
|
||||
{
|
||||
UserInfoCache::clearUserInfo($this->adminId);
|
||||
UserAuthCache::clearUserAuth($this->adminId);
|
||||
UserMenuCache::clearUserMenu($this->adminId);
|
||||
return $this->success([], '清除缓存成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 基本统计
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function statistics(): Response
|
||||
{
|
||||
$userLogic = new SystemUserLogic();
|
||||
$userCount = $userLogic->count('id');
|
||||
$uploadLogic = new SystemAttachmentLogic();
|
||||
$attachCount = $uploadLogic->count('id');
|
||||
$loginLogic = new SystemLoginLogLogic();
|
||||
$loginCount = $loginLogic->count('id');
|
||||
$operLogic = new SystemOperLogLogic();
|
||||
$operCount = $operLogic->count('id');
|
||||
return $this->success([
|
||||
'user' => $userCount,
|
||||
'attach' => $attachCount,
|
||||
'login' => $loginCount,
|
||||
'operate' => $operCount,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录统计曲线图
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function loginChart(): Response
|
||||
{
|
||||
$logic = new SystemLoginLogLogic();
|
||||
$data = $logic->loginChart();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录统计柱状图
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('工作台数据统计', 'core:console:list')]
|
||||
public function loginBarChart(): Response
|
||||
{
|
||||
$logic = new SystemLoginLogLogic();
|
||||
$data = $logic->loginBarChart();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\logic\system\DatabaseLogic;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 数据表维护控制器
|
||||
*/
|
||||
class DataBaseController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new DatabaseLogic();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据源列表
|
||||
* @return Response
|
||||
*/
|
||||
public function source(): Response
|
||||
{
|
||||
$data = $this->logic->getDbSource();
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据表列表', 'core:database:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['source', ''],
|
||||
]);
|
||||
$data = $this->logic->getList($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回收站数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('回收站数据', 'core:recycle:index')]
|
||||
public function recycle(Request $request): Response
|
||||
{
|
||||
$table = $request->input('table', '');
|
||||
$data = $this->logic->recycleData($table);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('回收站销毁', 'core:recycle:edit')]
|
||||
public function delete(Request $request): Response
|
||||
{
|
||||
$table = $request->input('table', '');
|
||||
$ids = $request->input('ids', '');
|
||||
if (!empty($ids)) {
|
||||
$result = $this->logic->delete($table, $ids);
|
||||
if (!$result) {
|
||||
return $this->fail('操作失败');
|
||||
}
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('回收站恢复', 'core:recycle:edit')]
|
||||
public function recovery(Request $request): Response
|
||||
{
|
||||
$table = $request->input('table', '');
|
||||
$ids = $request->input('ids', '');
|
||||
if (!empty($ids)) {
|
||||
$result = $this->logic->recovery($table, $ids);
|
||||
if (!$result) {
|
||||
return $this->fail('操作失败');
|
||||
}
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段信息
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据表字段', 'core:database:index')]
|
||||
public function detailed(Request $request): Response
|
||||
{
|
||||
$table = $request->input('table', '');
|
||||
$data = $this->logic->getColumnList($table, '');
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据表优化表', 'core:database:edit')]
|
||||
public function optimize(Request $request): Response
|
||||
{
|
||||
$tables = $request->input('tables', []);
|
||||
$this->logic->optimizeTable($tables);
|
||||
return $this->success('优化成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理表碎片
|
||||
*/
|
||||
#[Permission('数据表清理碎片', 'core:database:edit')]
|
||||
public function fragment(Request $request): Response
|
||||
{
|
||||
$tables = $request->input('tables', []);
|
||||
$this->logic->fragmentTable($tables);
|
||||
return $this->success('清理成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemAttachmentLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 附件管理控制器
|
||||
*/
|
||||
class SystemAttachmentController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemAttachmentLogic();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件数据列表', 'core:attachment:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['origin_name', ''],
|
||||
['category_id', ''],
|
||||
['storage_mode', ''],
|
||||
['mime_type', ''],
|
||||
['create_time', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件数据修改', 'core:attachment:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$result = $this->logic->edit($data['id'], ['origin_name' => $data['origin_name']]);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件数据删除', 'core:attachment:edit')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动分类
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件移动分类', 'core:attachment:edit')]
|
||||
public function move(Request $request) : Response
|
||||
{
|
||||
$category_id = $request->post('category_id', '');
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids) || empty($category_id)) {
|
||||
return $this->fail('参数错误,请检查参数');
|
||||
}
|
||||
$result = $this->logic->move($category_id, $ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\validate\system\SystemCategoryValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemCategoryLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 附件分类控制器
|
||||
*/
|
||||
class SystemCategoryController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemCategoryLogic();
|
||||
$this->validate = new SystemCategoryValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件分类列表', 'core:attachment:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['category_name', ''],
|
||||
]);
|
||||
$data = $this->logic->tree($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件分类读取', 'core:attachment:index')]
|
||||
public function read(Request $request) : Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件分类添加', 'core:attachment:edit')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件分类修改', 'core:attachment:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('附件分类删除', 'core:attachment:edit')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\cache\ConfigCache;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemConfigLogic;
|
||||
use plugin\saiadmin\app\logic\system\SystemConfigGroupLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemConfigValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 配置项数据控制器
|
||||
*/
|
||||
class SystemConfigController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemConfigLogic();
|
||||
$this->validate = new SystemConfigValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置列表', 'core:config:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['group_id', ''],
|
||||
['name', ''],
|
||||
['key', ''],
|
||||
]);
|
||||
$this->logic->setOrderField('sort');
|
||||
$this->logic->setOrderType('desc');
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置管理', 'core:config:edit')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置管理', 'core:config:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置管理', 'core:config:edit')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配置内容
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置修改', 'core:config:update')]
|
||||
public function batchUpdate(Request $request): Response
|
||||
{
|
||||
$group_id = $request->post('group_id');
|
||||
$config = $request->post('config');
|
||||
if (empty($group_id) || empty($config)) {
|
||||
return $this->fail('参数错误');
|
||||
}
|
||||
$this->logic->batchUpdate($group_id, $config);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\cache\ConfigCache;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemConfigGroupLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemConfigGroupValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use plugin\saiadmin\utils\Arr;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use plugin\saiadmin\service\EmailService;
|
||||
use plugin\saiadmin\app\model\system\SystemMail;
|
||||
|
||||
/**
|
||||
* 配置控制器
|
||||
*/
|
||||
class SystemConfigGroupController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemConfigGroupLogic();
|
||||
$this->validate = new SystemConfigGroupValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置列表', 'core:config:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['code', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getAll($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置管理', 'core:config:edit')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置管理', 'core:config:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
ConfigCache::clearConfig($data['code']);
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置管理', 'core:config:edit')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮件测试
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('系统设置修改', 'core:config:update')]
|
||||
public function email(Request $request) : Response
|
||||
{
|
||||
$email = $request->input('email', '');
|
||||
if (empty($email)) {
|
||||
return $this->fail('请输入邮箱');
|
||||
}
|
||||
$subject = "测试邮件";
|
||||
$code = "9527";
|
||||
$content = "<h1>验证码:{code}</h1><p>这是一封测试邮件,请忽略</p>";
|
||||
$template = [
|
||||
'code' => $code
|
||||
];
|
||||
$config = EmailService::getConfig();
|
||||
$model = SystemMail::create([
|
||||
'gateway' => Arr::getConfigValue($config,'Host'),
|
||||
'from' => Arr::getConfigValue($config,'From'),
|
||||
'email' => $email,
|
||||
'code' => $code,
|
||||
]);
|
||||
try {
|
||||
$result = EmailService::sendByTemplate($email, $subject, $content, $template);
|
||||
if (!empty($result)) {
|
||||
$model->status = 'failure';
|
||||
$model->response = $result;
|
||||
$model->save();
|
||||
return $this->fail('发送失败,请查看日志');
|
||||
} else {
|
||||
$model->status = 'success';
|
||||
$model->save();
|
||||
return $this->success([], '发送成功');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$model->status = 'failure';
|
||||
$model->response = $e->getMessage();
|
||||
$model->save();
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\validate\system\SystemDeptValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemDeptLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 部门控制器
|
||||
*/
|
||||
class SystemDeptController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemDeptLogic();
|
||||
$this->validate = new SystemDeptValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据列表', 'core:dept:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['code', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$data = $this->logic->tree($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据读取', 'core:dept:read')]
|
||||
public function read(Request $request) : Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据添加', 'core:dept:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据修改','core:dept:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('部门数据删除','core:dept:destroy')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作部门
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function accessDept(Request $request) : Response
|
||||
{
|
||||
$where = ['status' => 1];
|
||||
$data = $this->logic->accessDept($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\cache\DictCache;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemDictDataLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemDictDataValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 字典数据控制器
|
||||
*/
|
||||
class SystemDictDataController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemDictDataLogic();
|
||||
$this->validate = new SystemDictDataValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典列表', 'core:dict:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['label', ''],
|
||||
['value', ''],
|
||||
['type_id', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$this->logic->setOrderField('sort');
|
||||
$this->logic->setOrderType('desc');
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典管理', 'core:dict:edit')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
DictCache::clear();
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典管理', 'core:dict:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
DictCache::clear();
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典管理', 'core:dict:edit')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
DictCache::clear();
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\cache\DictCache;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemDictTypeLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemDictTypeValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Cache;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 字典类型控制器
|
||||
*/
|
||||
class SystemDictTypeController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemDictTypeLogic();
|
||||
$this->validate = new SystemDictTypeValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典列表', 'core:dict:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['code', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典管理', 'core:dict:edit')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
DictCache::clear();
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典管理', 'core:dict:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
DictCache::clear();
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('数据字典管理', 'core:dict:edit')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
DictCache::clear();
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemLoginLogLogic;
|
||||
use plugin\saiadmin\app\logic\system\SystemOperLogLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 日志控制器
|
||||
*/
|
||||
class SystemLogController extends BaseController
|
||||
{
|
||||
|
||||
/**
|
||||
* 登录日志列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('登录日志列表', 'core:logs:login')]
|
||||
public function getLoginLogPageList(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['login_time', ''],
|
||||
['username', ''],
|
||||
['status', ''],
|
||||
['ip', ''],
|
||||
]);
|
||||
$logic = new SystemLoginLogLogic();
|
||||
$query = $logic->search($where);
|
||||
$data = $logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除登录日志
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('登录日志删除', 'core:logs:deleteLogin')]
|
||||
public function deleteLoginLog(Request $request) : Response
|
||||
{
|
||||
$ids = $request->input('ids', '');
|
||||
$logic = new SystemLoginLogLogic();
|
||||
if (!empty($ids)) {
|
||||
$logic->destroy($ids);
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作日志列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('操作日志列表', 'core:logs:Oper')]
|
||||
public function getOperLogPageList(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['create_time', ''],
|
||||
['username', ''],
|
||||
['service_name', ''],
|
||||
['router', ''],
|
||||
['ip', ''],
|
||||
]);
|
||||
$logic = new SystemOperLogLogic();
|
||||
$logic->init($this->adminInfo);
|
||||
$query = $logic->search($where);
|
||||
$data = $logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除操作日志
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('操作日志删除', 'core:logs:deleteOper')]
|
||||
public function deleteOperLog(Request $request) : Response
|
||||
{
|
||||
$ids = $request->input('ids', '');
|
||||
$logic = new SystemOperLogLogic();
|
||||
if (!empty($ids)) {
|
||||
$logic->destroy($ids);
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemMailLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemMailValidate;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 邮件记录控制器
|
||||
*/
|
||||
class SystemMailController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemMailLogic();
|
||||
$this->validate = new SystemMailValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('邮件日志列表', 'core:email:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['gateway', ''],
|
||||
['from', ''],
|
||||
['code', ''],
|
||||
['email', ''],
|
||||
['status', ''],
|
||||
['create_time', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('邮件日志删除', 'core:email:destroy')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\cache\UserMenuCache;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemMenuLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemMenuValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 菜单控制器
|
||||
*/
|
||||
class SystemMenuController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemMenuLogic();
|
||||
$this->validate = new SystemMenuValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('菜单数据列表', 'core:menu:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['path', ''],
|
||||
['menu', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$data = $this->logic->tree($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('菜单数据读取', 'core:menu:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('菜单数据添加', 'core:menu:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
UserMenuCache::clearMenuCache();
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('菜单数据修改', 'core:menu:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
UserMenuCache::clearMenuCache();
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('菜单数据删除', 'core:menu:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
UserMenuCache::clearMenuCache();
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作菜单
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function accessMenu(Request $request): Response
|
||||
{
|
||||
$where = [];
|
||||
if ($this->adminId > 1) {
|
||||
$data = $this->logic->auth();
|
||||
} else {
|
||||
$data = $this->logic->tree($where);
|
||||
}
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\system\SystemPostLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemPostValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 岗位信息控制器
|
||||
*/
|
||||
class SystemPostController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemPostLogic();
|
||||
$this->validate = new SystemPostValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据列表', 'core:post:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['code', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据读取', 'core:post:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据添加', 'core:post:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据修改', 'core:post:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据删除', 'core:post:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据导入', 'core:post:import')]
|
||||
public function import(Request $request): Response
|
||||
{
|
||||
$file = current($request->file());
|
||||
if (!$file || !$file->isValid()) {
|
||||
return $this->fail('未找到上传文件');
|
||||
}
|
||||
$this->logic->import($file);
|
||||
return $this->success('导入成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('岗位数据导出', 'core:post:export')]
|
||||
public function export(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['code', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
return $this->logic->export($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载导入模板
|
||||
* @return Response
|
||||
*/
|
||||
public function downloadTemplate(): Response
|
||||
{
|
||||
$file_name = "template.xlsx";
|
||||
return downloadFile($file_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作岗位
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function accessPost(Request $request): Response
|
||||
{
|
||||
$where = ['status' => 1];
|
||||
$data = $this->logic->accessPost($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\model\system\SystemUserRole;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\cache\UserInfoCache;
|
||||
use plugin\saiadmin\app\model\system\SystemUser;
|
||||
use plugin\saiadmin\app\validate\system\SystemRoleValidate;
|
||||
use plugin\saiadmin\app\logic\system\SystemRoleLogic;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 角色控制器
|
||||
*/
|
||||
class SystemRoleController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemRoleLogic();
|
||||
$this->validate = new SystemRoleValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据列表', 'core:role:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['code', ''],
|
||||
['status', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$levelArr = array_column($this->adminInfo['roleList'], 'level');
|
||||
$maxLevel = max($levelArr);
|
||||
$query->where('level', '<', $maxLevel);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据读取', 'core:role:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据添加', 'core:role:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据修改', 'core:role:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据删除', 'core:role:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色获取菜单
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色数据列表', 'core:role:index')]
|
||||
public function getMenuByRole(Request $request): Response
|
||||
{
|
||||
$id = $request->get('id');
|
||||
$data = $this->logic->getMenuByRole($id);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单权限
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('角色菜单权限', 'core:role:menu')]
|
||||
public function menuPermission(Request $request): Response
|
||||
{
|
||||
$id = $request->post('id');
|
||||
$menu_ids = $request->post('menu_ids');
|
||||
$this->logic->saveMenuPermission($id, $menu_ids);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 可操作角色
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function accessRole(Request $request): Response
|
||||
{
|
||||
$where = ['status' => 1];
|
||||
$data = $this->logic->accessRole($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\utils\ServerMonitor;
|
||||
use support\think\Cache;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 邮件记录控制器
|
||||
*/
|
||||
class SystemServerController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('服务监控', 'core:server:monitor')]
|
||||
public function monitor(Request $request): Response
|
||||
{
|
||||
$service = new ServerMonitor();
|
||||
return $this->success([
|
||||
'memory' => $service->getMemoryInfo(),
|
||||
'disk' => $service->getDiskInfo(),
|
||||
'phpEnv' => $service->getPhpAndEnvInfo(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('缓存信息', 'core:server:cache')]
|
||||
public function cache(Request $request): Response
|
||||
{
|
||||
$menu_cache = config('plugin.saiadmin.saithink.menu_cache', []);
|
||||
$button_cache = config('plugin.saiadmin.saithink.button_cache', []);
|
||||
$config_cache = config('plugin.saiadmin.saithink.config_cache', []);
|
||||
$dict_cache = config('plugin.saiadmin.saithink.dict_cache', []);
|
||||
$reflection_cache = config('plugin.saiadmin.saithink.reflection_cache', []);
|
||||
|
||||
return $this->success([
|
||||
'menu_cache' => $menu_cache,
|
||||
'button_cache' => $button_cache,
|
||||
'config_cache' => $config_cache,
|
||||
'dict_cache' => $dict_cache,
|
||||
'reflection_cache' => $reflection_cache
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('缓存数据清理', 'core:server:clear')]
|
||||
public function clear(Request $request) : Response
|
||||
{
|
||||
$tag = $request->input('tag', '');
|
||||
if (empty($tag)) {
|
||||
return $this->fail('请选择要删除的缓存');
|
||||
}
|
||||
Cache::tag($tag)->clear();
|
||||
Cache::delete($tag);
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\system;
|
||||
|
||||
use plugin\saiadmin\app\cache\UserAuthCache;
|
||||
use plugin\saiadmin\app\cache\UserMenuCache;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\cache\UserInfoCache;
|
||||
use plugin\saiadmin\app\logic\system\SystemUserLogic;
|
||||
use plugin\saiadmin\app\validate\system\SystemUserValidate;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 用户信息控制器
|
||||
*/
|
||||
class SystemUserController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new SystemUserLogic();
|
||||
$this->validate = new SystemUserValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户数据列表', 'core:user:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['username', ''],
|
||||
['phone', ''],
|
||||
['email', ''],
|
||||
['status', ''],
|
||||
['dept_id', ''],
|
||||
['create_time', ''],
|
||||
]);
|
||||
$data = $this->logic->indexList($where);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户数据读取', 'core:user:read')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户数据保存', 'core:user:save')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户数据更新', 'core:user:update')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户数据删除', 'core:user:destroy')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->input('ids', '');
|
||||
if (!empty($ids)) {
|
||||
$this->logic->destroy($ids);
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理用户缓存
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('清理用户缓存', 'core:user:cache')]
|
||||
public function clearCache(Request $request): Response
|
||||
{
|
||||
$id = $request->post('id', '');
|
||||
UserInfoCache::clearUserInfo($id);
|
||||
UserAuthCache::clearUserAuth($id);
|
||||
UserMenuCache::clearUserMenu($id);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户密码
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('修改用户密码', 'core:user:password')]
|
||||
public function initUserPassword(Request $request): Response
|
||||
{
|
||||
$id = $request->post('id', '');
|
||||
$password = $request->post('password', '');
|
||||
if ($id == 1) {
|
||||
return $this->fail('超级管理员不允许重置密码');
|
||||
}
|
||||
$data = ['password' => password_hash($password, PASSWORD_DEFAULT)];
|
||||
$this->logic->authEdit($id, $data);
|
||||
UserInfoCache::clearUserInfo($id);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户首页
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('设置用户首页', 'core:user:home')]
|
||||
public function setHomePage(Request $request): Response
|
||||
{
|
||||
$id = $request->post('id', '');
|
||||
$dashboard = $request->post('dashboard', '');
|
||||
$data = ['dashboard' => $dashboard];
|
||||
$this->logic->authEdit($id, $data);
|
||||
UserInfoCache::clearUserInfo($id);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新资料
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户修改资料')]
|
||||
public function updateInfo(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
unset($data['deptList']);
|
||||
unset($data['postList']);
|
||||
unset($data['roleList']);
|
||||
$result = $this->logic->updateInfo($this->adminId, $data);
|
||||
if ($result) {
|
||||
UserInfoCache::clearUserInfo($this->adminId);
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->fail('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('用户修改密码')]
|
||||
public function modifyPassword(Request $request): Response
|
||||
{
|
||||
$oldPassword = $request->input('oldPassword');
|
||||
$newPassword = $request->input('newPassword');
|
||||
$this->logic->modifyPassword($this->adminId, $oldPassword, $newPassword);
|
||||
UserInfoCache::clearUserInfo($this->adminId);
|
||||
return $this->success('修改成功');
|
||||
}
|
||||
}
|
||||
181
server/plugin/saiadmin/app/controller/tool/CrontabController.php
Normal file
181
server/plugin/saiadmin/app/controller/tool/CrontabController.php
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\tool;
|
||||
|
||||
use plugin\saiadmin\app\logic\tool\CrontabLogic;
|
||||
use plugin\saiadmin\app\logic\tool\CrontabLogLogic;
|
||||
use plugin\saiadmin\app\validate\tool\CrontabValidate;
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use Webman\Channel\Client;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 定时任务控制器
|
||||
*/
|
||||
class CrontabController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new CrontabLogic();
|
||||
$this->validate = new CrontabValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务列表', 'tool:crontab:index')]
|
||||
public function index(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['name', ''],
|
||||
['type', ''],
|
||||
['status', ''],
|
||||
['create_time', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务添加', 'tool:crontab:edit')]
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('save', $data);
|
||||
$result = $this->logic->add($data);
|
||||
if ($result) {
|
||||
return $this->success('添加成功');
|
||||
} else {
|
||||
return $this->fail('添加失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务修改', 'tool:crontab:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务删除', 'tool:crontab:edit')]
|
||||
public function destroy(Request $request) : Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务状态修改', 'tool:crontab:edit')]
|
||||
public function changeStatus(Request $request) : Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$status = $request->input('status', 1);
|
||||
if (empty($id)) {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
$result = $this->logic->changeStatus($id, $status);
|
||||
if ($result) {
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->fail('操作失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行定时任务
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务执行', 'tool:crontab:run')]
|
||||
public function run(Request $request) : Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$result = $this->logic->run($id);
|
||||
if ($result) {
|
||||
return $this->success('执行成功');
|
||||
} else {
|
||||
return $this->fail('执行失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务日志
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务日志', 'tool:crontab:index')]
|
||||
public function logPageList(Request $request) : Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['crontab_id', ''],
|
||||
['create_time', []]
|
||||
]);
|
||||
$logic = new CrontabLogLogic();
|
||||
$query = $logic->search($where);
|
||||
$data = $logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务日志删除
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('定时任务日志删除', 'tool:crontab:edit')]
|
||||
public function deleteCrontabLog(Request $request) : Response
|
||||
{
|
||||
$ids = $request->input('ids', '');
|
||||
if (!empty($ids)) {
|
||||
$logic = new CrontabLogLogic();
|
||||
$logic->destroy($ids);
|
||||
return $this->success('操作成功');
|
||||
} else {
|
||||
return $this->fail('参数错误,请检查');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | saiadmin [ saiadmin快速开发框架 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: sai <1430792918@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace plugin\saiadmin\app\controller\tool;
|
||||
|
||||
use plugin\saiadmin\basic\BaseController;
|
||||
use plugin\saiadmin\app\logic\tool\GenerateTablesLogic;
|
||||
use plugin\saiadmin\app\validate\tool\GenerateTablesValidate;
|
||||
use plugin\saiadmin\app\cache\UserMenuCache;
|
||||
use plugin\saiadmin\service\Permission;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
/**
|
||||
* 代码生成控制器
|
||||
*/
|
||||
class GenerateTablesController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->logic = new GenerateTablesLogic();
|
||||
$this->validate = new GenerateTablesValidate;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成列表', 'tool:code:index')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$where = $request->more([
|
||||
['table_name', ''],
|
||||
]);
|
||||
$query = $this->logic->search($where);
|
||||
$data = $this->logic->getList($query);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成列表', 'tool:code:index')]
|
||||
public function read(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$model = $this->logic->read($id);
|
||||
if ($model) {
|
||||
$data = is_array($model) ? $model : $model->toArray();
|
||||
return $this->success($data);
|
||||
} else {
|
||||
return $this->fail('未查找到信息');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成修改', 'tool:code:edit')]
|
||||
public function update(Request $request): Response
|
||||
{
|
||||
$data = $request->post();
|
||||
$this->validate('update', $data);
|
||||
$result = $this->logic->edit($data['id'], $data);
|
||||
if ($result) {
|
||||
return $this->success('修改成功');
|
||||
} else {
|
||||
return $this->fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成删除', 'tool:code:edit')]
|
||||
public function destroy(Request $request): Response
|
||||
{
|
||||
$ids = $request->post('ids', '');
|
||||
if (empty($ids)) {
|
||||
return $this->fail('请选择要删除的数据');
|
||||
}
|
||||
$result = $this->logic->destroy($ids);
|
||||
if ($result) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->fail('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 装载数据表
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成装载', 'tool:code:edit')]
|
||||
public function loadTable(Request $request): Response
|
||||
{
|
||||
$names = $request->input('names', []);
|
||||
$source = $request->input('source', '');
|
||||
$this->logic->loadTable($names, $source);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步数据表字段信息
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成同步表结构', 'tool:code:edit')]
|
||||
public function sync(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$this->logic->sync($id);
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码预览
|
||||
*/
|
||||
#[Permission('代码生成预览', 'tool:code:edit')]
|
||||
public function preview(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$data = $this->logic->preview($id);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码生成
|
||||
*/
|
||||
#[Permission('代码生成文件', 'tool:code:edit')]
|
||||
public function generate(Request $request): Response
|
||||
{
|
||||
$ids = $request->input('ids', '');
|
||||
$data = $this->logic->generate($ids);
|
||||
return response()->download($data['download'], $data['filename']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成到模块
|
||||
*/
|
||||
#[Permission('代码生成到模块', 'tool:code:edit')]
|
||||
public function generateFile(Request $request): Response
|
||||
{
|
||||
$id = $request->input('id', '');
|
||||
$this->logic->generateFile($id);
|
||||
UserMenuCache::clearMenuCache();
|
||||
return $this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据表字段信息
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
#[Permission('代码生成读取表字段', 'tool:code:index')]
|
||||
public function getTableColumns(Request $request): Response
|
||||
{
|
||||
$table_id = $request->input('table_id', '');
|
||||
$data = $this->logic->getTableColumns($table_id);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user