Browse Source

修改静态调用

Anyon 2 years ago
parent
commit
12c50de24b

+ 2 - 3
app/admin/controller/Auth.php

@@ -94,10 +94,9 @@ class Auth extends Controller
     {
         $map = $this->_vali(['auth.require#id' => '权限ID不能为空!']);
         if (input('action') === 'get') {
-            $admin = AdminService::instance();
-            if ($this->app->isDebug()) $admin->clearCache();
+            if ($this->app->isDebug()) AdminService::clearCache();
             $nodes = SystemNode::mk()->where($map)->column('node');
-            $this->success('获取权限节点成功!', $admin->getTree($nodes));
+            $this->success('获取权限节点成功!', AdminService::getTree($nodes));
         } elseif (input('action') === 'save') {
             [$post, $data] = [$this->request->post(), []];
             foreach ($post['nodes'] ?? [] as $node) {

+ 3 - 3
app/admin/controller/Config.php

@@ -52,7 +52,7 @@ class Config extends Controller
     public function index()
     {
         $this->title = '系统参数配置';
-        $this->super = AdminService::instance()->isSuper();
+        $this->super = AdminService::isSuper();
         $this->version = ModuleService::instance()->getVersion();
         $this->fetch();
     }
@@ -81,11 +81,11 @@ class Config extends Controller
                 if ($post['xpath'] !== 'admin' && file_exists($this->app->getBasePath() . $post['xpath'])) {
                     $this->error("后台入口名称{$post['xpath']}已经存在应用!");
                 }
-                SystemService::instance()->setRuntime(null, [$post['xpath'] => 'admin']);
+                SystemService::setRuntime(null, [$post['xpath'] => 'admin']);
             }
             // 修改网站 ICON 图标文件,替换 public/favicon.ico 文件
             if (preg_match('#^https?://#', $icon = $post['site_icon'] ?? '')) try {
-                SystemService::instance()->setFavicon($icon);
+                SystemService::setFavicon($icon);
             } catch (\Exception $exception) {
                 trace_file($exception);
                 $this->error($exception->getMessage());

+ 9 - 10
app/admin/controller/Index.php

@@ -38,19 +38,18 @@ class Index extends Controller
     public function index()
     {
         /*! 根据运行模式刷新权限 */
-        $debug = $this->app->isDebug();
-        AdminService::instance()->apply($debug);
+        AdminService::apply($this->app->isDebug());
         /*! 读取当前用户权限菜单树 */
-        $this->menus = MenuService::instance()->getTree();
+        $this->menus = MenuService::getTree();
         /*! 判断当前用户的登录状态 */
-        $this->login = AdminService::instance()->isLogin();
+        $this->login = AdminService::isLogin();
         /*! 菜单为空且未登录跳转到登录页 */
         if (empty($this->menus) && empty($this->login)) {
             $this->redirect(sysuri('admin/login/index'));
         } else {
             $this->title = '系统管理后台';
-            $this->super = AdminService::instance()->isSuper();
-            $this->theme = AdminService::instance()->getUserTheme();
+            $this->super = AdminService::isSuper();
+            $this->theme = AdminService::getUserTheme();
             $this->fetch();
         }
     }
@@ -66,12 +65,12 @@ class Index extends Controller
     public function theme()
     {
         if ($this->request->isGet()) {
-            $this->theme = AdminService::instance()->getUserTheme();
+            $this->theme = AdminService::getUserTheme();
             $this->themes = Config::themes;
             $this->fetch();
         } else {
             $data = $this->_vali(['site_theme.require' => '主题名称不能为空!']);
-            if (AdminService::instance()->setUserTheme($data['site_theme'])) {
+            if (AdminService::setUserTheme($data['site_theme'])) {
                 $this->success('主题配置保存成功!');
             } else {
                 $this->error('主题配置保存失败!');
@@ -87,7 +86,7 @@ class Index extends Controller
     public function info($id = 0)
     {
         $this->_applyFormToken();
-        if (AdminService::instance()->getUserId() === intval($id)) {
+        if (AdminService::getUserId() === intval($id)) {
             SystemUser::mForm('admin@user/form', 'id', [], ['id' => $id]);
         } else {
             $this->error('只能修改自己的资料!');
@@ -116,7 +115,7 @@ class Index extends Controller
     public function pass($id = 0)
     {
         $this->_applyFormToken();
-        if (AdminService::instance()->getUserId() !== intval($id)) {
+        if (AdminService::getUserId() !== intval($id)) {
             $this->error('只能修改当前用户的密码!');
         }
         if ($this->app->request->isGet()) {

+ 3 - 4
app/admin/controller/Login.php

@@ -40,15 +40,14 @@ class Login extends Controller
     public function index()
     {
         if ($this->app->request->isGet()) {
-            if (AdminService::instance()->isLogin()) {
+            if (AdminService::isLogin()) {
                 $this->redirect(sysuri('admin/index/index'));
             } else {
                 // 当前运行模式
-                $system = SystemService::instance();
-                $this->developMode = $system->checkRunMode();
+                $this->developMode = SystemService::checkRunMode();
                 // 后台背景处理
                 $images = str2arr(sysconf('login_image') ?: '', '|') ?: [
-                    $system->uri('/static/theme/img/login/bg1.jpg'), $system->uri('/static/theme/img/login/bg2.jpg'),
+                    SystemService::uri('/static/theme/img/login/bg1.jpg'), SystemService::uri('/static/theme/img/login/bg2.jpg'),
                 ];
                 $this->loginStyle = sprintf('style="background-image:url(%s)" data-bg-transition="%s"', $images[0], join(',', $images));
                 // 登录验证令牌

+ 5 - 5
app/admin/controller/Menu.php

@@ -101,18 +101,18 @@ class Menu extends Controller
         if ($this->request->isGet()) {
             /* 清理权限节点 */
             if ($isDebug = $this->app->isDebug()) {
-                AdminService::instance()->clearCache();
+                AdminService::clearCache();
             }
-            /* 选择自己上级菜单 */
-            $vo['pid'] = $vo['pid'] ?? input('pid', '0');
             /* 读取系统功能节点 */
             $this->auths = [];
-            $this->nodes = MenuService::instance()->getList($isDebug);
-            foreach (NodeService::instance()->getMethods($isDebug) as $node => $item) {
+            $this->nodes = MenuService::getList($isDebug);
+            foreach (NodeService::getMethods($isDebug) as $node => $item) {
                 if ($item['isauth'] && substr_count($node, '/') >= 2) {
                     $this->auths[] = ['node' => $node, 'title' => $item['title']];
                 }
             }
+            /* 选择自己上级菜单 */
+            $vo['pid'] = $vo['pid'] ?? input('pid', '0');
             /* 列出可选上级菜单 */
             $menus = SystemMenu::mk()->order('sort desc,id asc')->column('id,pid,icon,url,node,title,params', 'id');
             $this->menus = DataExtend::arr2table(array_merge($menus, [['id' => '0', 'pid' => '-1', 'url' => '#', 'title' => '顶部菜单']]));

+ 1 - 1
app/admin/controller/User.php

@@ -143,7 +143,7 @@ class User extends Controller
             // 用户身份数据
             $this->bases = SystemBase::items('身份权限');
             // 用户权限管理
-            $this->superName = AdminService::instance()->getSuperName();
+            $this->superName = AdminService::getSuperName();
             $this->authorizes = SystemAuth::items();
         }
     }

+ 1 - 1
app/admin/controller/api/Plugs.php

@@ -44,7 +44,7 @@ class Plugs extends Controller
      */
     public function optimize()
     {
-        if (AdminService::instance()->isSuper()) {
+        if (AdminService::isSuper()) {
             sysoplog('系统运维管理', '创建数据库优化任务');
             $this->_queue('优化数据库所有数据表', 'xadmin:database optimize');
         } else {

+ 1 - 1
app/admin/controller/api/Queue.php

@@ -96,7 +96,7 @@ class Queue extends Controller
      */
     public function status()
     {
-        if (AdminService::instance()->isSuper()) try {
+        if (AdminService::isSuper()) try {
             $message = $this->app->console->call('xadmin:queue', ['status'])->fetch();
             if (preg_match('/process.*?\d+.*?running/', $message)) {
                 echo "<span class='color-green pointer' data-tips-text='{$message}'>已启动</span>";

+ 11 - 11
app/admin/controller/api/Runtime.php

@@ -36,9 +36,9 @@ class Runtime extends Controller
      */
     public function push()
     {
-        if (AdminService::instance()->isSuper()) try {
-            AdminService::instance()->clearCache();
-            SystemService::instance()->pushRuntime();
+        if (AdminService::isSuper()) try {
+            AdminService::clearCache();
+            SystemService::pushRuntime();
             sysoplog('系统运维管理', '刷新创建路由缓存');
             $this->success('网站缓存加速成功!', 'javascript:location.reload()');
         } catch (HttpResponseException $exception) {
@@ -56,9 +56,9 @@ class Runtime extends Controller
      */
     public function clear()
     {
-        if (AdminService::instance()->isSuper()) try {
-            AdminService::instance()->clearCache();
-            SystemService::instance()->clearRuntime();
+        if (AdminService::isSuper()) try {
+            AdminService::clearCache();
+            SystemService::clearRuntime();
             sysoplog('系统运维管理', '清理网站日志缓存');
             $this->success('清空日志缓存成功!', 'javascript:location.reload()');
         } catch (HttpResponseException $exception) {
@@ -76,12 +76,12 @@ class Runtime extends Controller
      */
     public function debug()
     {
-        if (AdminService::instance()->isSuper()) if (input('state')) {
-            SystemService::instance()->setRuntime('product');
+        if (AdminService::isSuper()) if (input('state')) {
+            SystemService::setRuntime('product');
             sysoplog('系统运维管理', '开发模式切换为生产模式');
             $this->success('已切换为生产模式!', 'javascript:location.reload()');
         } else {
-            SystemService::instance()->setRuntime('debug');
+            SystemService::setRuntime('debug');
             sysoplog('系统运维管理', '生产模式切换为开发模式');
             $this->success('已切换为开发模式!', 'javascript:location.reload()');
         } else {
@@ -98,7 +98,7 @@ class Runtime extends Controller
      */
     public function editor()
     {
-        if (AdminService::instance()->isSuper()) {
+        if (AdminService::isSuper()) {
             $editor = input('editor', 'auto');
             sysconf('base.editor', $editor);
             sysoplog('系统运维管理', "切换编辑器为{$editor}");
@@ -114,7 +114,7 @@ class Runtime extends Controller
      */
     public function config()
     {
-        if (AdminService::instance()->isSuper()) try {
+        if (AdminService::isSuper()) try {
             [$tmpdata, $newdata] = [[], []];
             foreach (SystemConfig::mk()->order('type,name asc')->cursor() as $item) {
                 $tmpdata[$item['type']][$item['name']] = $item['value'];

+ 1 - 1
app/admin/controller/api/Update.php

@@ -33,7 +33,7 @@ class Update extends Controller
      */
     protected function initialize()
     {
-        if (!SystemService::instance()->checkRunMode()) {
+        if (!SystemService::checkRunMode()) {
             $this->error('只允许访问本地或官方代码!');
         }
     }

+ 2 - 2
app/admin/controller/api/Upload.php

@@ -72,7 +72,7 @@ class Upload extends Controller
         $file = SystemFile::mk()->data($this->_vali([
             'xkey.value'   => $data['key'],
             'type.value'   => $this->getType(),
-            'uuid.value'   => AdminService::instance()->getUserId(),
+            'uuid.value'   => AdminService::getUserId(),
             'name.require' => '名称不能为空!',
             'hash.require' => '哈希不能为空!',
             'xext.require' => '后缀不能为空!',
@@ -129,7 +129,7 @@ class Upload extends Controller
             'id.require'   => '编号不能为空!',
             'hash.require' => '哈希不能为空!',
         ]);
-        $data['uuid'] = AdminService::instance()->getUserId();
+        $data['uuid'] = AdminService::getUserId();
         $file = SystemFile::mk()->where($data)->findOrEmpty();
         if ($file->isEmpty()) $this->error('文件不存在!');
         if ($file->save(['status' => 2])) {

+ 2 - 3
app/admin/route/demo.php

@@ -19,14 +19,14 @@ use think\App;
 
 invoke(function (App $app) {
     /*! 非开发环境,清理限制文件 */
-    if ($app->request->isGet() && !SystemService::instance()->checkRunMode()) {
+    if ($app->request->isGet() && !SystemService::checkRunMode()) {
         @unlink("{$app->getBasePath()}admin/controller/api/Update.php");
         @unlink("{$app->getBasePath()}admin/route/demo.php");
         @rmdir("{$app->getBasePath()}admin/route");
         return;
     }
     /*! 演示环境禁止操作路由绑定 */
-    if (SystemService::instance()->checkRunMode('demo')) {
+    if (SystemService::checkRunMode('demo')) {
         $app->route->post('index/pass', function () {
             return json(['code' => 0, 'info' => '演示环境禁止修改用户密码!']);
         });
@@ -58,5 +58,4 @@ invoke(function (App $app) {
             return json(['code' => 0, 'info' => '演示环境禁止修改用户密码!']);
         });
     }
-
 });