pref: 增加服务类优化UI版面
This commit is contained in:
@@ -12,21 +12,19 @@ declare(strict_types=1);
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\service\notice\EmailService;
|
||||
use app\common\service\utils\FtpService;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use support\Response;
|
||||
use think\db\exception\BindParamException;
|
||||
use think\facade\Cache;
|
||||
use support\Cache;
|
||||
use think\facade\Db;
|
||||
use Webman\Event\Event;
|
||||
use system\Random;
|
||||
use think\cache\driver\Memcached;
|
||||
use think\cache\driver\Redis;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use app\AdminController;
|
||||
use app\common\library\Email;
|
||||
use app\common\library\Ftp;
|
||||
use app\common\model\system\AdminNotice;
|
||||
use app\common\model\system\Attachment;
|
||||
use app\common\model\system\Config;
|
||||
@@ -389,7 +387,6 @@ class Index extends AdminController
|
||||
(new Config())->saveAll($config);
|
||||
$env = base_path() . '/.env';
|
||||
$parse = parse_ini_file($env, true);
|
||||
$parse['CACHE_DRIVER'] = $post['cache_type'];
|
||||
$parse['CACHE_HOSTNAME'] = $post['cache_host'];
|
||||
$parse['CACHE_HOSTPORT'] = $post['cache_port'];
|
||||
$parse['CACHE_SELECT'] = $post['cache_select'];
|
||||
@@ -401,7 +398,6 @@ class Index extends AdminController
|
||||
}
|
||||
|
||||
// 清理系统核心缓存
|
||||
Cache::tag('core_system')->clear();
|
||||
$configList = Cache::get('config_list');
|
||||
foreach ($configList as $item) {
|
||||
Cache::delete($item);
|
||||
@@ -417,7 +413,7 @@ class Index extends AdminController
|
||||
public function testFtp(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
if (Ftp::instance()->ftpTest(request()->post())) {
|
||||
if (FtpService::ftpTest(request()->post())) {
|
||||
return $this->success('上传测试成功!');
|
||||
}
|
||||
}
|
||||
@@ -427,51 +423,49 @@ class Index extends AdminController
|
||||
|
||||
/**
|
||||
* 邮件测试
|
||||
* @return Response
|
||||
*/
|
||||
public function testEmail()
|
||||
public function testEmail(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$info = Email::instance()->testEMail(request()->post());
|
||||
return $info === true ? $this->success('测试邮件发送成功!') : $this->error($info);
|
||||
try {
|
||||
EmailService::testEmail(request()->post());
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
return $this->success('测试邮件发送成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存测试
|
||||
* @return Response
|
||||
*/
|
||||
public function testCache()
|
||||
public function testCache(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
|
||||
$param = request()->post();
|
||||
if (!isset($param['type']) || empty($param['host']) || empty($param['port'])) {
|
||||
if (empty($param['host']) || empty($param['port'])) {
|
||||
return $this->error('参数错误!');
|
||||
}
|
||||
|
||||
$options = [
|
||||
'host' => $param['host'],
|
||||
'port' => (int)$param['port'],
|
||||
'username' => $param['user'],
|
||||
'password' => $param['pass']
|
||||
];
|
||||
if (!extension_loaded('redis')) {
|
||||
return $this->error('请先安装redis扩展!');
|
||||
}
|
||||
|
||||
try {
|
||||
if (strtolower($param['type']) == 'redis') {
|
||||
$drive = new Redis($options);
|
||||
} else {
|
||||
$drive = new Memcached($options);
|
||||
}
|
||||
$redis = new \Redis();
|
||||
$redis->connect($param['host'], (int)$param['port']);
|
||||
$redis->auth($param['pass']);
|
||||
$redis->select((int)$param['select']);
|
||||
$redis->set('key-test', time());
|
||||
$redis->close();
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
|
||||
if ($drive->set('test', 'cacheOK', 1000)) {
|
||||
return $this->success('缓存测试成功!');
|
||||
} else {
|
||||
return $this->error('缓存测试失败!');
|
||||
}
|
||||
}
|
||||
return $this->success('缓存测试成功!');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\facade\Cache;
|
||||
use support\Cache;
|
||||
use Webman\Http\Request;
|
||||
|
||||
/**
|
||||
@@ -155,14 +155,13 @@ class Admin extends AdminController
|
||||
return $this->error('该用户名或邮箱已被注册!');
|
||||
}
|
||||
|
||||
|
||||
// 管理员加密
|
||||
$post['pwd'] = encryptPwd($post['pwd']);
|
||||
$post['create_ip'] = request()->getRealIp();
|
||||
$data = $this->model->create($post);
|
||||
if (!is_empty($data->id)) {
|
||||
$access['admin_id'] = $data->id;
|
||||
$access['group_id'] = $data->group_id;
|
||||
if (!is_empty($data['id'])) {
|
||||
$access['admin_id'] = $data['id'];
|
||||
$access['group_id'] = $data['group_id'];
|
||||
AdminAccessModel::insert($access);
|
||||
return $this->success('添加管理员成功!');
|
||||
} else {
|
||||
@@ -182,95 +181,84 @@ class Admin extends AdminController
|
||||
if (request()->isPost()) {
|
||||
|
||||
$id = request()->input('id');
|
||||
|
||||
if (!empty($id) && is_numeric($id)) {
|
||||
|
||||
// 验证数据
|
||||
$post = request()->all();
|
||||
$post = request_validate_rules($post, get_class($this->model), 'edit');
|
||||
if (!is_array($post)) {
|
||||
return $this->error($post);
|
||||
$retError = request_validate_rules($post, get_class($this->model), 'edit');
|
||||
if (!is_array($retError)) {
|
||||
return $this->error($retError);
|
||||
}
|
||||
|
||||
if (!empty($post['pwd'])) {
|
||||
if (isset($post['pwd']) && !empty($post['pwd'])) {
|
||||
$post['pwd'] = encryptPwd($post['pwd']);
|
||||
} else {
|
||||
// 清空避免被覆盖
|
||||
unset($post['pwd']);
|
||||
}
|
||||
|
||||
if ($this->model->update($post)) {
|
||||
$access['group_id'] = $post['group_id'];
|
||||
AdminAccessModel::where('admin_id', $id)->update($access);
|
||||
return $this->success('更新管理员成功!');
|
||||
} else {
|
||||
return $this->error('更新管理员失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->error('更新管理员失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑权限
|
||||
* @return Response
|
||||
*/
|
||||
public function editRules()
|
||||
public function editRules(): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
return $this->_update_RuleCates();
|
||||
}
|
||||
return $this->updateRuleCates();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑栏目权限
|
||||
* @return Response
|
||||
*/
|
||||
public function editCates()
|
||||
public function editCates(): Response
|
||||
{
|
||||
return $this->_update_RuleCates(AUTH_CATE);
|
||||
return $this->updateRuleCates(AUTH_CATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新权限函数
|
||||
* @access protected
|
||||
* @param string $type
|
||||
* @return \support\Response|void
|
||||
* @return Response
|
||||
*/
|
||||
protected function _update_RuleCates(string $type = AUTH_RULES)
|
||||
protected function updateRuleCates(string $type = AUTH_RULES): Response
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
$admin_id = input('admin_id');
|
||||
$rules = request()->post($type) ?? [];
|
||||
$access = $this->auth->getRulesNode($admin_id, $type);
|
||||
$rules = array_diff($rules, $access[$this->auth->authGroup]);
|
||||
|
||||
$admin_id = input('admin_id');
|
||||
$rules = request()->post($type) ?? [];
|
||||
|
||||
if (!empty($admin_id) && $admin_id > 0) {
|
||||
|
||||
$access = $this->auth->getRulesNode($admin_id, $type);
|
||||
$rules = array_diff($rules, $access[$this->auth->authGroup]);
|
||||
|
||||
// 权限验证
|
||||
if (!$this->auth->checkRuleOrCateNodes($rules, $type, $this->auth->authPrivate)) {
|
||||
return $this->error('没有权限!');
|
||||
}
|
||||
|
||||
// 获取个人节点
|
||||
$differ = array_diff($access[$this->auth->authPrivate], $access[$this->auth->authGroup]);
|
||||
$current = [];
|
||||
if (!$this->auth->superAdmin()) {
|
||||
$current = $this->auth->getRulesNode();
|
||||
$current = array_diff($differ, $current[$this->auth->authPrivate]);
|
||||
}
|
||||
|
||||
$rules = array_unique(array_merge($rules, $current));
|
||||
$AdminAccessModel = new AdminAccessModel();
|
||||
$data = [
|
||||
"$type" => implode(',', $rules)
|
||||
];
|
||||
|
||||
if ($AdminAccessModel->where('admin_id', $admin_id)->save($data)) {
|
||||
return $this->success('更新权限成功!');
|
||||
}
|
||||
|
||||
return $this->error('更新权限失败!');
|
||||
}
|
||||
// 权限验证
|
||||
if (!$this->auth->checkRuleOrCateNodes($rules, $type, $this->auth->authPrivate)) {
|
||||
return $this->error('没有权限!');
|
||||
}
|
||||
|
||||
// 获取个人节点
|
||||
$differ = array_diff($access[$this->auth->authPrivate], $access[$this->auth->authGroup]);
|
||||
$current = [];
|
||||
if (!$this->auth->superAdmin()) {
|
||||
$current = $this->auth->getRulesNode();
|
||||
$current = array_diff($differ, $current[$this->auth->authPrivate]);
|
||||
}
|
||||
|
||||
$rules = array_unique(array_merge($rules, $current));
|
||||
$AdminAccessModel = new AdminAccessModel();
|
||||
$data = ["$type" => implode(',', $rules)];
|
||||
|
||||
if ($AdminAccessModel->update($data, ['admin_id' => $admin_id])) {
|
||||
return $this->success('更新权限成功!');
|
||||
}
|
||||
|
||||
return $this->error('更新权限失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,7 +266,7 @@ class Admin extends AdminController
|
||||
* getAdminRules
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPermissions()
|
||||
public function getPermissions(): mixed
|
||||
{
|
||||
$list = [];
|
||||
if (\request()->isAjax()) {
|
||||
@@ -666,7 +654,7 @@ class Admin extends AdminController
|
||||
// 清理内容
|
||||
if ($type == 'all' || $type == 'content') {
|
||||
$session = session(AdminSession);
|
||||
\think\facade\Cache::clear();
|
||||
\support\Cache::clear();
|
||||
request()->session()->set(AdminSession, $session);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,34 +50,14 @@ class AdminRules extends AdminController
|
||||
}
|
||||
|
||||
// 获取总数
|
||||
$total = $this->model->count();
|
||||
$total = $this->model->where($where)->count();
|
||||
$list = $this->model->where($where)->order('sort asc')->select()->toArray();
|
||||
foreach ($list as $key => $value) {
|
||||
$list[$key]['title'] = __($value['title']);
|
||||
}
|
||||
|
||||
// 自定义查询
|
||||
if (count($list) < $total) {
|
||||
|
||||
$parentNode = []; // 查找父节点
|
||||
foreach ($list as $key => $value) {
|
||||
if ($value['pid'] !== 0 && !list_search($list,['id'=>$value['pid']])) {
|
||||
$parentNode[] = $this->parentNode($value['pid']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($parentNode as $key => $value) {
|
||||
$list = array_merge($list,$value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$rules = $this->model->getListTree();
|
||||
return $this->success('获取成功', '',[
|
||||
'item'=> $list,
|
||||
'rules'=> $rules
|
||||
],
|
||||
count($list),0);
|
||||
$rules = list_to_tree($list,'id','pid','children',0);
|
||||
return $this->success('获取成功', '/',$rules, $total);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -73,11 +73,7 @@ class Department extends AdminController
|
||||
}
|
||||
|
||||
$depart = $this->model->getListTree();
|
||||
return $this->success('获取成功', '',[
|
||||
'item'=> $list,
|
||||
'depart'=> $depart
|
||||
],
|
||||
count($list));
|
||||
return $this->success('获取成功', '',$depart, $total);
|
||||
}
|
||||
|
||||
return view('system/department/index');
|
||||
|
||||
@@ -81,7 +81,7 @@ class Plugin extends AdminController
|
||||
return $this->error('请勿重复安装插件');
|
||||
}
|
||||
|
||||
// try {
|
||||
try {
|
||||
|
||||
$pluginZip = self::downLoad($name, ['name' => $name, 'token' => input('token')]);
|
||||
ZipArchives::unzip($pluginZip, plugin_path(), '', true);
|
||||
@@ -95,10 +95,10 @@ class Plugin extends AdminController
|
||||
self::pluginMenu($name);
|
||||
self::executeSql($name);
|
||||
self::enabled($name);
|
||||
// } catch (\Throwable $th) {
|
||||
// recursive_delete($pluginPath);
|
||||
// return $this->error($th->getMessage(), null, self::$ServerBody, $th->getCode());
|
||||
// }
|
||||
} catch (\Throwable $th) {
|
||||
recursive_delete($pluginPath);
|
||||
return $this->error($th->getMessage(), null, self::$ServerBody, $th->getCode());
|
||||
}
|
||||
|
||||
return $this->success('插件安装成功', null, get_plugin_config($name, true));
|
||||
}
|
||||
@@ -295,17 +295,15 @@ class Plugin extends AdminController
|
||||
if (request()->isPost()) {
|
||||
$post['extends'] = input('extends');
|
||||
$post['rewrite'] = input('rewrite');
|
||||
foreach ($post['rewrite'] as $kk=>$vv)
|
||||
{
|
||||
if($kk[0]!='/')return $this->error('伪静态变量名称“'.$kk.'" 必须以“/”开头');
|
||||
$post['rewrite'][$kk]=str_replace('\\','/',trim($vv,'/\\'));
|
||||
$value=explode('/',$post['rewrite'][$kk]);
|
||||
if(count($value)<2){
|
||||
return $this->error('伪静态规则变量值,不符合规则');
|
||||
foreach ($post['rewrite'] as $kk => $vv) {
|
||||
if ($kk[0] != '/') return $this->error('伪静态变量名称“' . $kk . '" 必须以“/”开头');
|
||||
$post['rewrite'][$kk] = str_replace('\\', '/', trim($vv, '/\\'));
|
||||
$value = explode('/', $post['rewrite'][$kk]);
|
||||
if (count($value) < 2) {
|
||||
return $this->error('伪静态不符合规则');
|
||||
}
|
||||
if(strtoupper($value[count($value)-2][0]) !== $value[count($value)-2][0])
|
||||
{
|
||||
return $this->error('伪静态规则变量值中,控制器首字母必须大写哦');
|
||||
if (strtoupper($value[count($value) - 2][0]) !== $value[count($value) - 2][0]) {
|
||||
return $this->error('控制器首字母必须大写');
|
||||
}
|
||||
}
|
||||
$config = array_merge($config, $post);
|
||||
|
||||
@@ -21,7 +21,6 @@ use system\Random;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use Webman\Http\Request;
|
||||
|
||||
/**
|
||||
* 用户管理
|
||||
|
||||
Reference in New Issue
Block a user