Parcourir la source

style: code style now clean

Anankke il y a 3 ans
Parent
commit
0e59167b84
100 fichiers modifiés avec 1602 ajouts et 1642 suppressions
  1. 6 6
      app/container.php
  2. 1 13
      app/envload.php
  3. 70 66
      app/routes.php
  4. 5 1
      config/.config.example.php
  5. 142 140
      config/appprofile.example.php
  6. 2 0
      db/migrations/20220109130532_create_stream_media_table.php
  7. 36 0
      phpinsights.php
  8. 8 8
      resources/views/material/admin/shop/edit.tpl
  9. 5 5
      resources/views/material/admin/user/edit.tpl
  10. 1 1
      resources/views/material/user/bought.tpl
  11. 9 9
      resources/views/material/user/edit.tpl
  12. 6 6
      resources/views/material/user/index.tpl
  13. 3 3
      resources/views/material/user/profile.tpl
  14. 12 12
      resources/views/material/user/shop.tpl
  15. 7 6
      src/Command/Backup.php
  16. 4 4
      src/Command/ClientDownload.php
  17. 2 2
      src/Command/DetectBan.php
  18. 6 5
      src/Command/DetectGFW.php
  19. 10 9
      src/Command/FinanceMail.php
  20. 23 22
      src/Command/Job.php
  21. 9 8
      src/Command/PortAutoChange.php
  22. 2 2
      src/Command/SendDiaryMail.php
  23. 10 9
      src/Command/Tool.php
  24. 9 9
      src/Command/Update.php
  25. 20 20
      src/Command/User.php
  26. 14 16
      src/Controllers/Admin/AnnController.php
  27. 3 2
      src/Controllers/Admin/ApiController.php
  28. 20 25
      src/Controllers/Admin/CodeController.php
  29. 19 21
      src/Controllers/Admin/DetectBanLogController.php
  30. 36 41
      src/Controllers/Admin/DetectController.php
  31. 3 2
      src/Controllers/Admin/GConfigController.php
  32. 48 59
      src/Controllers/Admin/IpController.php
  33. 15 11
      src/Controllers/Admin/NodeController.php
  34. 6 7
      src/Controllers/Admin/SettingController.php
  35. 34 43
      src/Controllers/Admin/ShopController.php
  36. 4 3
      src/Controllers/Admin/SubscribeLogController.php
  37. 18 22
      src/Controllers/Admin/TicketController.php
  38. 64 59
      src/Controllers/Admin/UserController.php
  39. 14 10
      src/Controllers/Admin/UserLog/BoughtLogController.php
  40. 13 13
      src/Controllers/Admin/UserLog/CodeLogController.php
  41. 24 24
      src/Controllers/Admin/UserLog/DetectLogController.php
  42. 13 14
      src/Controllers/Admin/UserLog/LoginLogController.php
  43. 14 14
      src/Controllers/Admin/UserLog/SubLogController.php
  44. 30 38
      src/Controllers/AdminController.php
  45. 56 116
      src/Controllers/AuthController.php
  46. 1 1
      src/Controllers/BaseController.php
  47. 5 3
      src/Controllers/HomeController.php
  48. 29 32
      src/Controllers/LinkController.php
  49. 11 7
      src/Controllers/Node/FuncController.php
  50. 9 9
      src/Controllers/Node/NodeController.php
  51. 10 5
      src/Controllers/Node/UserController.php
  52. 23 42
      src/Controllers/PasswordController.php
  53. 2 2
      src/Controllers/SubController.php
  54. 75 0
      src/Controllers/User/DetectController.php
  55. 16 13
      src/Controllers/User/NodeController.php
  56. 234 0
      src/Controllers/User/ShopController.php
  57. 11 9
      src/Controllers/User/TicketController.php
  58. 164 458
      src/Controllers/UserController.php
  59. 1 1
      src/Middleware/Admin.php
  60. 1 1
      src/Middleware/Auth.php
  61. 2 2
      src/Middleware/AuthorizationBearer.php
  62. 1 1
      src/Middleware/Guest.php
  63. 1 1
      src/Middleware/NodeToken.php
  64. 1 1
      src/Models/Ann.php
  65. 2 2
      src/Models/BlockIp.php
  66. 13 13
      src/Models/Bought.php
  67. 2 2
      src/Models/Code.php
  68. 1 1
      src/Models/Coupon.php
  69. 5 5
      src/Models/DetectBanLog.php
  70. 10 10
      src/Models/DetectLog.php
  71. 1 1
      src/Models/DetectRule.php
  72. 1 1
      src/Models/EmailQueue.php
  73. 1 1
      src/Models/EmailVerify.php
  74. 2 2
      src/Models/GConfig.php
  75. 1 1
      src/Models/InviteCode.php
  76. 4 4
      src/Models/Ip.php
  77. 1 1
      src/Models/Link.php
  78. 3 3
      src/Models/LoginIp.php
  79. 2 2
      src/Models/Model.php
  80. 21 19
      src/Models/Node.php
  81. 1 1
      src/Models/NodeInfoLog.php
  82. 1 1
      src/Models/NodeOnlineLog.php
  83. 1 1
      src/Models/PasswordReset.php
  84. 1 1
      src/Models/Payback.php
  85. 1 1
      src/Models/Paylist.php
  86. 1 1
      src/Models/Setting.php
  87. 11 11
      src/Models/Shop.php
  88. 1 1
      src/Models/StreamMedia.php
  89. 1 12
      src/Models/TelegramSession.php
  90. 3 3
      src/Models/Ticket.php
  91. 1 1
      src/Models/Token.php
  92. 2 2
      src/Models/UnblockIp.php
  93. 42 34
      src/Models/User.php
  94. 1 1
      src/Models/UserHourlyUsage.php
  95. 2 2
      src/Models/UserSubscribeLog.php
  96. 1 1
      src/Services/Analytic.php
  97. 1 1
      src/Services/Analytics.php
  98. 2 2
      src/Services/Auth.php
  99. 3 1
      src/Services/Auth/Base.php
  100. 2 2
      src/Services/Auth/Cookie.php

+ 6 - 6
app/container.php

@@ -35,18 +35,18 @@ $container['notAllowedHandler'] = static function ($c) {
 };
 
 if ($_ENV['debug'] === false) {
-    $container['errorHandler'] = function ($c) {
-        return function ($request, $response, $exception) {
+    $container['errorHandler'] = static function ($c) {
+        return static function ($request, $response, $exception) {
             $view = View::getSmarty();
-            $exceptionId = empty($_ENV['sentry_dsn']) ? null : Sentry\captureException($exception);
+            $exceptionId = isset($_ENV['sentry_dsn']) ? null : Sentry\captureException($exception);
             return $response->withStatus(500)
                 ->write($view->assign('exceptionId', $exceptionId)->fetch('500.tpl'));
         };
     };
-    $container['phpErrorHandler'] = function ($c) {
-        return function ($request, $response, $exception) {
+    $container['phpErrorHandler'] = static function ($c) {
+        return static function ($request, $response, $exception) {
             $view = View::getSmarty();
-            $exceptionId = empty($_ENV['sentry_dsn']) ? null : Sentry\captureException($exception);
+            $exceptionId = isset($_ENV['sentry_dsn']) ? null : Sentry\captureException($exception);
             return $response->withStatus(500)
                 ->write($view->assign('exceptionId', $exceptionId)->fetch('500.tpl'));
         };

+ 1 - 13
app/envload.php

@@ -2,18 +2,6 @@
 
 declare(strict_types=1);
 
-// make replace _ENV with env
-function searchEnvName($name)
-{
-    global $_ENV;
-    foreach ($_ENV as $configKey => $configValue) {
-        if (strtoupper($configKey) === $name) {
-            return $configKey;
-        }
-    }
-    return null;
-}
-
 if (getenv('UIM_ENV_REPLACE_ENABLE')) {
     foreach (getenv() as $envKey => $envValue) {
         global $_ENV;
@@ -22,7 +10,7 @@ if (getenv('UIM_ENV_REPLACE_ENABLE')) {
         if (strpos($envUpKey, 'UIM_') === 0) {
             // Valid env key, set to _ENV
             $configKey = substr($envUpKey, 4);
-            $realKey = searchEnvName($configKey);
+            $realKey = App\Utils\Tools::searchEnvName($configKey);
             if ($realKey !== null) {
                 $_ENV[$realKey] = $envValue;
             }

+ 70 - 66
app/routes.php

@@ -2,6 +2,11 @@
 
 declare(strict_types=1);
 
+use App\Middleware\Admin;
+use App\Middleware\Auth;
+use App\Middleware\AuthorizationBearer;
+use App\Middleware\Guest;
+use App\Middleware\NodeToken;
 use Slim\App as SlimApp;
 
 return function (SlimApp $app): void {
@@ -34,23 +39,23 @@ return function (SlimApp $app): void {
         $this->get('/invite', App\Controllers\UserController::class . ':invite');
         $this->get('/disable', App\Controllers\UserController::class . ':disable');
 
-        $this->get('/node', App\Controllers\User\NodeController::class . ':user_node_page');
-        $this->get('/node/{id}/ajax', App\Controllers\User\NodeController::class . ':user_node_ajax');
-        $this->get('/node/{id}', App\Controllers\User\NodeController::class . ':user_node_info');
+        $this->get('/node', App\Controllers\User\NodeController::class . ':userNodePage');
+        $this->get('/node/{id}/ajax', App\Controllers\User\NodeController::class . ':userNodeAjax');
+        $this->get('/node/{id}', App\Controllers\User\NodeController::class . ':userNodeInfo');
 
-        $this->get('/detect', App\Controllers\UserController::class . ':detect_index');
-        $this->get('/detect/log', App\Controllers\UserController::class . ':detect_log');
+        $this->get('/detect', App\Controllers\User\DetectController::class . ':detectIndex');
+        $this->get('/detect/log', App\Controllers\User\DetectController::class . ':detectLog');
 
-        $this->get('/shop', App\Controllers\UserController::class . ':shop');
-        $this->post('/coupon_check', App\Controllers\UserController::class . ':CouponCheck');
-        $this->post('/buy', App\Controllers\UserController::class . ':buy');
-        $this->post('/buy_traffic_package', App\Controllers\UserController::class . ':buy_traffic_package');
+        $this->get('/shop', App\Controllers\User\ShopController::class . ':shop');
+        $this->post('/coupon_check', App\Controllers\User\ShopController::class . ':couponCheck');
+        $this->post('/buy', App\Controllers\User\ShopController::class . ':buy');
+        $this->post('/buy_traffic_package', App\User\ShopController\UserController::class . ':buyTrafficPackage');
 
         $this->get('/ticket', App\Controllers\User\TicketController::class . ':ticket');
-        $this->get('/ticket/create', App\Controllers\User\TicketController::class . ':ticket_create');
-        $this->post('/ticket', App\Controllers\User\TicketController::class . ':ticket_add');
-        $this->get('/ticket/{id}/view', App\Controllers\User\TicketController::class . ':ticket_view');
-        $this->put('/ticket/{id}', App\Controllers\User\TicketController::class . ':ticket_update');
+        $this->get('/ticket/create', App\Controllers\User\TicketController::class . ':ticketCreate');
+        $this->post('/ticket', App\Controllers\User\TicketController::class . ':ticketAdd');
+        $this->get('/ticket/{id}/view', App\Controllers\User\TicketController::class . ':ticketView');
+        $this->put('/ticket/{id}', App\Controllers\User\TicketController::class . ':ticketUpdate');
 
         $this->post('/buy_invite', App\Controllers\UserController::class . ':buyInvite');
         $this->post('/custom_invite', App\Controllers\UserController::class . ':customInvite');
@@ -74,25 +79,25 @@ return function (SlimApp $app): void {
         $this->get('/backtoadmin', App\Controllers\UserController::class . ':backtoadmin');
         $this->get('/code', App\Controllers\UserController::class . ':code');
 
-        $this->get('/code_check', App\Controllers\UserController::class . ':code_check');
-        $this->post('/code', App\Controllers\UserController::class . ':codepost');
-        $this->post('/gacheck', App\Controllers\UserController::class . ':GaCheck');
-        $this->post('/gaset', App\Controllers\UserController::class . ':GaSet');
-        $this->get('/gareset', App\Controllers\UserController::class . ':GaReset');
-        $this->get('/telegram_reset', App\Controllers\UserController::class . ':telegram_reset');
-        $this->post('/resetport', App\Controllers\UserController::class . ':ResetPort');
-        $this->post('/specifyport', App\Controllers\UserController::class . ':SpecifyPort');
-        $this->post('/unblock', App\Controllers\UserController::class . ':Unblock');
+        $this->get('/code_check', App\Controllers\UserController::class . ':codeCheck');
+        $this->post('/code', App\Controllers\UserController::class . ':codePost');
+        $this->post('/gacheck', App\Controllers\UserController::class . ':gaCheck');
+        $this->post('/gaset', App\Controllers\UserController::class . ':gaSet');
+        $this->get('/gareset', App\Controllers\UserController::class . ':gaReset');
+        $this->get('/telegram_reset', App\Controllers\UserController::class . ':telegramReset');
+        $this->post('/resetport', App\Controllers\UserController::class . ':resetPort');
+        $this->post('/specifyport', App\Controllers\UserController::class . ':specifyPort');
+        $this->post('/unblock', App\Controllers\UserController::class . ':unblock');
         $this->get('/bought', App\Controllers\UserController::class . ':bought');
         $this->delete('/bought', App\Controllers\UserController::class . ':deleteBoughtGet');
         $this->get('/url_reset', App\Controllers\UserController::class . ':resetURL');
         $this->put('/invite', App\Controllers\UserController::class . ':resetInviteURL');
 
-        $this->get('/order', App\Controllers\UserController::class . ':user_order');
-        $this->get('/product', App\Controllers\UserController::class . ':product_index');
+        $this->get('/order', App\Controllers\UserController::class . ':userOrder');
+        $this->get('/product', App\Controllers\UserController::class . ':productIndex');
 
         // 订阅记录
-        $this->get('/subscribe_log', App\Controllers\UserController::class . ':subscribe_log');
+        $this->get('/subscribe_log', App\Controllers\UserController::class . ':subscribeLog');
 
         // getUserAllURL
         $this->get('/getUserAllURL', App\Controllers\UserController::class . ':getUserAllURL');
@@ -116,14 +121,14 @@ return function (SlimApp $app): void {
     // Auth
     $app->group('/auth', function (): void {
         $this->get('/login', App\Controllers\AuthController::class . ':login');
-        $this->post('/qrcode_check', App\Controllers\AuthController::class . ':qrcode_check');
+        $this->post('/qrcode_check', App\Controllers\AuthController::class . ':qrcodeCheck');
         $this->post('/login', App\Controllers\AuthController::class . ':loginHandle');
-        $this->post('/qrcode_login', App\Controllers\AuthController::class . ':qrcode_loginHandle');
+        $this->post('/qrcode_login', App\Controllers\AuthController::class . ':qrcodeLoginHandle');
         $this->get('/register', App\Controllers\AuthController::class . ':register');
         $this->post('/register', App\Controllers\AuthController::class . ':registerHandle');
         $this->post('/send', App\Controllers\AuthController::class . ':sendVerify');
         $this->get('/logout', App\Controllers\AuthController::class . ':logout');
-        $this->get('/telegram_oauth', App\Controllers\AuthController::class . ':telegram_oauth');
+        $this->get('/telegram_oauth', App\Controllers\AuthController::class . ':telegramOauth');
         $this->get('/login_getCaptcha', App\Controllers\AuthController::class . ':getCaptcha');
     })->add(new Guest());
 
@@ -144,7 +149,7 @@ return function (SlimApp $app): void {
         $this->get('/invite', App\Controllers\AdminController::class . ':invite');
         $this->post('/invite', App\Controllers\AdminController::class . ':addInvite');
         $this->post('/chginvite', App\Controllers\AdminController::class . ':chgInvite');
-        $this->post('/payback/ajax', App\Controllers\AdminController::class . ':ajax_payback');
+        $this->post('/payback/ajax', App\Controllers\AdminController::class . ':ajaxPayback');
 
         // Node Mange
         $this->get('/node', App\Controllers\Admin\NodeController::class . ':index');
@@ -164,7 +169,7 @@ return function (SlimApp $app): void {
 
         // Shop Mange
         $this->get('/shop', App\Controllers\Admin\ShopController::class . ':index');
-        $this->post('/shop/ajax', App\Controllers\Admin\ShopController::class . ':ajax_shop');
+        $this->post('/shop/ajax', App\Controllers\Admin\ShopController::class . ':ajaxShop');
         $this->get('/shop/create', App\Controllers\Admin\ShopController::class . ':create');
         $this->post('/shop', App\Controllers\Admin\ShopController::class . ':add');
         $this->get('/shop/{id}/edit', App\Controllers\Admin\ShopController::class . ':edit');
@@ -174,7 +179,7 @@ return function (SlimApp $app): void {
         // Bought Mange
         $this->get('/bought', App\Controllers\Admin\ShopController::class . ':bought');
         $this->delete('/bought', App\Controllers\Admin\ShopController::class . ':deleteBoughtGet');
-        $this->post('/bought/ajax', App\Controllers\Admin\ShopController::class . ':ajax_bought');
+        $this->post('/bought/ajax', App\Controllers\Admin\ShopController::class . ':ajaxBought');
 
         // Product
         $this->get('/product', App\Controllers\Admin\ProductController::class . ':index');
@@ -201,8 +206,8 @@ return function (SlimApp $app): void {
         $this->put('/detect/{id}', App\Controllers\Admin\DetectController::class . ':update');
         $this->delete('/detect', App\Controllers\Admin\DetectController::class . ':delete');
         $this->get('/detect/log', App\Controllers\Admin\DetectController::class . ':log');
-        $this->post('/detect/ajax', App\Controllers\Admin\DetectController::class . ':ajax_rule');
-        $this->post('/detect/log/ajax', App\Controllers\Admin\DetectController::class . ':ajax_log');
+        $this->post('/detect/ajax', App\Controllers\Admin\DetectController::class . ':ajaxRule');
+        $this->post('/detect/log/ajax', App\Controllers\Admin\DetectController::class . ':ajaxLog');
 
         // IP Mange
         $this->get('/block', App\Controllers\Admin\IpController::class . ':block');
@@ -210,18 +215,18 @@ return function (SlimApp $app): void {
         $this->post('/unblock', App\Controllers\Admin\IpController::class . ':doUnblock');
         $this->get('/login', App\Controllers\Admin\IpController::class . ':index');
         $this->get('/alive', App\Controllers\Admin\IpController::class . ':alive');
-        $this->post('/block/ajax', App\Controllers\Admin\IpController::class . ':ajax_block');
-        $this->post('/unblock/ajax', App\Controllers\Admin\IpController::class . ':ajax_unblock');
-        $this->post('/login/ajax', App\Controllers\Admin\IpController::class . ':ajax_login');
-        $this->post('/alive/ajax', App\Controllers\Admin\IpController::class . ':ajax_alive');
+        $this->post('/block/ajax', App\Controllers\Admin\IpController::class . ':ajaxBlock');
+        $this->post('/unblock/ajax', App\Controllers\Admin\IpController::class . ':ajaxUnblock');
+        $this->post('/login/ajax', App\Controllers\Admin\IpController::class . ':ajaxLogin');
+        $this->post('/alive/ajax', App\Controllers\Admin\IpController::class . ':ajaxAlive');
 
         // Code Mange
         $this->get('/code', App\Controllers\Admin\CodeController::class . ':index');
         $this->get('/code/create', App\Controllers\Admin\CodeController::class . ':create');
         $this->post('/code', App\Controllers\Admin\CodeController::class . ':add');
-        $this->get('/donate/create', App\Controllers\Admin\CodeController::class . ':donate_create');
-        $this->post('/donate', App\Controllers\Admin\CodeController::class . ':donate_add');
-        $this->post('/code/ajax', App\Controllers\Admin\CodeController::class . ':ajax_code');
+        $this->get('/donate/create', App\Controllers\Admin\CodeController::class . ':donateCreate');
+        $this->post('/donate', App\Controllers\Admin\CodeController::class . ':donateAdd');
+        $this->post('/code/ajax', App\Controllers\Admin\CodeController::class . ':ajaxCode');
 
         // User Mange
         $this->get('/user', App\Controllers\Admin\UserController::class . ':index');
@@ -235,21 +240,21 @@ return function (SlimApp $app): void {
         // Coupon Mange
         $this->get('/coupon', App\Controllers\AdminController::class . ':coupon');
         $this->post('/coupon', App\Controllers\AdminController::class . ':addCoupon');
-        $this->post('/coupon/ajax', App\Controllers\AdminController::class . ':ajax_coupon');
+        $this->post('/coupon/ajax', App\Controllers\AdminController::class . ':ajaxCoupon');
 
         // Subscribe Log Mange
         $this->get('/subscribe', App\Controllers\Admin\SubscribeLogController::class . ':index');
-        $this->post('/subscribe/ajax', App\Controllers\Admin\SubscribeLogController::class . ':ajax_subscribe_log');
+        $this->post('/subscribe/ajax', App\Controllers\Admin\SubscribeLogController::class . ':ajaxSubscribeLog');
 
         // Detect Ban Mange
         $this->get('/detect/ban', App\Controllers\Admin\DetectBanLogController::class . ':index');
-        $this->post('/detect/ban/ajax', App\Controllers\Admin\DetectBanLogController::class . ':ajax_log');
+        $this->post('/detect/ban/ajax', App\Controllers\Admin\DetectBanLogController::class . ':ajaxLog');
 
         // 指定用户购买记录以及添加套餐
         $this->get('/user/{id}/bought', App\Controllers\Admin\UserLog\BoughtLogController::class . ':bought');
-        $this->post('/user/{id}/bought/ajax', App\Controllers\Admin\UserLog\BoughtLogController::class . ':bought_ajax');
-        $this->delete('/user/bought', App\Controllers\Admin\UserLog\BoughtLogController::class . ':bought_delete');
-        $this->post('/user/{id}/bought/buy', App\Controllers\Admin\UserLog\BoughtLogController::class . ':bought_add');
+        $this->post('/user/{id}/bought/ajax', App\Controllers\Admin\UserLog\BoughtLogController::class . ':boughtAjax');
+        $this->delete('/user/bought', App\Controllers\Admin\UserLog\BoughtLogController::class . ':boughtDelete');
+        $this->post('/user/{id}/bought/buy', App\Controllers\Admin\UserLog\BoughtLogController::class . ':boughtAdd');
 
         // 指定用户充值记录
         $this->get('/user/{id}/code', App\Controllers\Admin\UserLog\CodeLogController::class . ':index');
@@ -279,7 +284,7 @@ return function (SlimApp $app): void {
             $this->get('/update/{key}/edit', App\Controllers\Admin\GConfigController::class . ':edit');
 
             $this->get('/telegram', App\Controllers\Admin\GConfigController::class . ':telegram');
-            $this->post('/telegram/ajax', App\Controllers\Admin\GConfigController::class . ':telegram_ajax');
+            $this->post('/telegram/ajax', App\Controllers\Admin\GConfigController::class . ':telegramAjax');
         });
     })->add(new Admin());
 
@@ -299,28 +304,27 @@ return function (SlimApp $app): void {
     // mu
     $app->group('/mod_mu', function (): void {
         // 流媒体检测
-        $this->post('/media/saveReport', App\Controllers\Mod_Mu\NodeController::class . ':saveReport');
+        $this->post('/media/saveReport', App\Controllers\Node\NodeController::class . ':saveReport');
         // 其他
-        $this->get('/nodes/{id}/info', App\Controllers\Mod_Mu\NodeController::class . ':get_info');
-        $this->post('/nodes/{id}/info', App\Controllers\Mod_Mu\NodeController::class . ':info');
-        $this->get('/nodes', App\Controllers\Mod_Mu\NodeController::class . ':get_all_info');
-        $this->post('/nodes/config', App\Controllers\Mod_Mu\NodeController::class . ':getConfig');
-
-        $this->get('/users', App\Controllers\Mod_Mu\UserController::class . ':index');
-        $this->post('/users/traffic', App\Controllers\Mod_Mu\UserController::class . ':addTraffic');
-        $this->post('/users/aliveip', App\Controllers\Mod_Mu\UserController::class . ':addAliveIp');
-        $this->post('/users/detectlog', App\Controllers\Mod_Mu\UserController::class . ':addDetectLog');
-
-        $this->get('/func/detect_rules', App\Controllers\Mod_Mu\FuncController::class . ':get_detect_logs');
-        $this->post('/func/block_ip', App\Controllers\Mod_Mu\FuncController::class . ':addBlockIp');
-        $this->get('/func/block_ip', App\Controllers\Mod_Mu\FuncController::class . ':get_blockip');
-        $this->get('/func/unblock_ip', App\Controllers\Mod_Mu\FuncController::class . ':get_unblockip');
-        $this->get('/func/ping', App\Controllers\Mod_Mu\FuncController::class . ':ping');
-        //============================================
-    })->add(new Mod_Mu());
+        $this->get('/nodes/{id}/info', App\Controllers\Node\NodeController::class . ':getInfo');
+        $this->post('/nodes/{id}/info', App\Controllers\Node\NodeController::class . ':info');
+        $this->get('/nodes', App\Controllers\Node\NodeController::class . ':getAllInfo');
+        $this->post('/nodes/config', App\Controllers\Node\NodeController::class . ':getConfig');
+
+        $this->get('/users', App\Controllers\Node\UserController::class . ':index');
+        $this->post('/users/traffic', App\Controllers\Node\UserController::class . ':addTraffic');
+        $this->post('/users/aliveip', App\Controllers\Node\UserController::class . ':addAliveIp');
+        $this->post('/users/detectlog', App\Controllers\Node\UserController::class . ':addDetectLog');
+
+        $this->get('/func/detect_rules', App\Controllers\Node\FuncController::class . ':getDetectLogs');
+        $this->post('/func/block_ip', App\Controllers\Node\FuncController::class . ':addBlockIp');
+        $this->get('/func/block_ip', App\Controllers\Node\FuncController::class . ':getBlockip');
+        $this->get('/func/unblock_ip', App\Controllers\Node\FuncController::class . ':getUnblockip');
+        $this->get('/func/ping', App\Controllers\Node\FuncController::class . ':ping');
+    })->add(new NodeToken());
 
     $app->group('/link', function (): void {
-        $this->get('/{token}', App\Controllers\LinkController::class . ':GetContent');
+        $this->get('/{token}', App\Controllers\LinkController::class . ':getContent');
     });
 
     //通用訂閲

+ 5 - 1
config/.config.example.php

@@ -332,7 +332,11 @@ $_ENV['userCenterClient']     = [
 $_ENV['detect_gfw_interval']             = 3600;                                                               //检测间隔,单位:秒,低于推荐值会爆炸
 $_ENV['detect_gfw_port']                 = 22;                                                                 //所有节点服务器都打开的TCP端口,常用的为22(SSH端口)
 $_ENV['detect_gfw_url']                  = 'http://cn-sh-tcping.sspanel.org:8080/tcping?ip={ip}&port={port}'; //检测节点是否被gfw墙了的API的URL
-$_ENV['detect_gfw_judge']                = '$json_tcping[\'status\']=="true"';                                 //判断是否被墙的依据,json_tcping为上方URL返回的json数组
+//判断是否被墙的依据,json_tcping为上方URL返回的json数组
+$_ENV['detect_gfw_judge']                = function($json_tcping): boolean {
+    return $json_tcping['status'] === "true";
+};
+
 $_ENV['detect_gfw_count']                = '3';                                                                //尝试次数
 
 #离线检测

+ 142 - 140
config/appprofile.example.php

@@ -1,5 +1,7 @@
 <?php
 
+declare(strict_types=1);
+
 /**
  * default 为默认配置,你可以添加其他配置,但必须保证默认配置存在
  *
@@ -19,26 +21,26 @@ $_ENV['Surge_Profiles'] = [
     'default' => [
         'Checks' => [],
         'General' => [
-            'loglevel'                    => 'notify',
-            'dns-server'                  => 'system, 119.29.29.29, 1.1.1.1',
-            'skip-proxy'                  => '127.0.0.1, 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, 17.0.0.0/8, localhost, *.local, *.crashlytics.com',
-            'external-controller-access'  => '[email protected]:8233',
-            'allow-wifi-access'           => 'true',
-            'enhanced-mode-by-rule'       => 'false',
-            'exclude-simple-hostnames'    => 'true',
-            'show-error-page-for-reject'  => 'true',
-            'ipv6'                        => 'true',
-            'replica'                     => 'false',
-            'http-listen'                 => '0.0.0.0:8234',
-            'socks5-listen'               => '0.0.0.0:8235',
-            'wifi-access-http-port'       => 6152,
-            'wifi-access-socks5-port'     => 6153,
-            'internet-test-url'           => 'http://wifi.vivo.com.cn/generate_204',
-            'proxy-test-url'              => 'http://cp.cloudflare.com',
-            'test-timeout'                => 3
+            'loglevel' => 'notify',
+            'dns-server' => 'system, 119.29.29.29, 1.1.1.1',
+            'skip-proxy' => '127.0.0.1, 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, 17.0.0.0/8, localhost, *.local, *.crashlytics.com',
+            'external-controller-access' => '[email protected]:8233',
+            'allow-wifi-access' => 'true',
+            'enhanced-mode-by-rule' => 'false',
+            'exclude-simple-hostnames' => 'true',
+            'show-error-page-for-reject' => 'true',
+            'ipv6' => 'true',
+            'replica' => 'false',
+            'http-listen' => '0.0.0.0:8234',
+            'socks5-listen' => '0.0.0.0:8235',
+            'wifi-access-http-port' => 6152,
+            'wifi-access-socks5-port' => 6153,
+            'internet-test-url' => 'http://wifi.vivo.com.cn/generate_204',
+            'proxy-test-url' => 'http://cp.cloudflare.com',
+            'test-timeout' => 3,
         ],
         'Proxy' => [
-            '🚀直接连接 = direct'
+            '🚀直接连接 = direct',
         ],
         'ProxyGroup' => [
             [
@@ -47,9 +49,9 @@ $_ENV['Surge_Profiles'] = [
                 'content' => [
                     'regex' => '(.*)',
                     'right-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
-                ]
+                ],
             ],
             [
                 'name' => '⚓️其他流量',
@@ -57,59 +59,59 @@ $_ENV['Surge_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🔰国外流量',
-                        '🚀直接连接'
-                    ]
-                ]
+                        '🚀直接连接',
+                    ],
+                ],
             ],
             [
                 'name' => '✈️Telegram',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Youtube',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Netflix',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬哔哩哔哩',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬国外媒体',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🍎苹果服务',
@@ -117,15 +119,15 @@ $_ENV['Surge_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🚀直接连接',
-                        '🔰国外流量'
-                    ]
-                ]
-            ]
+                        '🔰国外流量',
+                    ],
+                ],
+            ],
         ],
         'Rule' => [
-            'source' => 'surge/default.tpl'
-        ]
-    ]
+            'source' => 'surge/default.tpl',
+        ],
+    ],
 ];
 
 /**
@@ -135,17 +137,17 @@ $_ENV['Surge2_Profiles'] = [
     'default' => [
         'Checks' => [],
         'General' => [
-            'loglevel'                   => 'notify',
-            'ipv6'                       => 'true',
-            'replica'                    => 'false',
-            'dns-server'                 => 'system, 119.29.29.29, 1.1.1.1',
-            'skip-proxy'                 => '127.0.0.1, 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, 17.0.0.0/8, localhost, *.local, *.crashlytics.com',
-            'bypass-system'              => 'true',
-            'allow-wifi-access'          => 'true',
-            'external-controller-access' => '[email protected]:8233'
+            'loglevel' => 'notify',
+            'ipv6' => 'true',
+            'replica' => 'false',
+            'dns-server' => 'system, 119.29.29.29, 1.1.1.1',
+            'skip-proxy' => '127.0.0.1, 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, 17.0.0.0/8, localhost, *.local, *.crashlytics.com',
+            'bypass-system' => 'true',
+            'allow-wifi-access' => 'true',
+            'external-controller-access' => '[email protected]:8233',
         ],
         'Proxy' => [
-            '🚀直接连接 = direct'
+            '🚀直接连接 = direct',
         ],
         'ProxyGroup' => [
             [
@@ -154,9 +156,9 @@ $_ENV['Surge2_Profiles'] = [
                 'content' => [
                     'regex' => '(.*)',
                     'right-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
-                ]
+                ],
             ],
             [
                 'name' => '⚓️其他流量',
@@ -164,59 +166,59 @@ $_ENV['Surge2_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🔰国外流量',
-                        '🚀直接连接'
-                    ]
-                ]
+                        '🚀直接连接',
+                    ],
+                ],
             ],
             [
                 'name' => '✈️Telegram',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Youtube',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Netflix',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬哔哩哔哩',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬国外媒体',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🍎苹果服务',
@@ -224,15 +226,15 @@ $_ENV['Surge2_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🚀直接连接',
-                        '🔰国外流量'
-                    ]
-                ]
-            ]
+                        '🔰国外流量',
+                    ],
+                ],
+            ],
         ],
         'Rule' => [
-            'source' => 'surge2/default.tpl'
-        ]
-    ]
+            'source' => 'surge2/default.tpl',
+        ],
+    ],
 ];
 
 /**
@@ -242,35 +244,35 @@ $_ENV['Clash_Profiles'] = [
     'default' => [
         'Checks' => [],
         'General' => [
-            'port'                => 7890,
-            'socks-port'          => 7891,
-            'redir-port'          => 7892,
-            'allow-lan'           => false,
-            'mode'                => 'rule',
-            'log-level'           => 'silent',
+            'port' => 7890,
+            'socks-port' => 7891,
+            'redir-port' => 7892,
+            'allow-lan' => false,
+            'mode' => 'rule',
+            'log-level' => 'silent',
             'external-controller' => '0.0.0.0:9090',
-            'secret'              => ''
+            'secret' => '',
         ],
         'DNS' => [
-            'enable'              => true,
-            'ipv6'                => false,
-            'listen'              => '0.0.0.0:53',
-            'enhanced-mode'       => 'fake-ip',
-            'fake-ip-range'       => '198.18.0.1/16',
-            'nameserver'=>[
+            'enable' => true,
+            'ipv6' => false,
+            'listen' => '0.0.0.0:53',
+            'enhanced-mode' => 'fake-ip',
+            'fake-ip-range' => '198.18.0.1/16',
+            'nameserver' => [
                 '119.29.29.29',
-                '1.1.1.1'
+                '1.1.1.1',
             ],
-            'fallback'=>[
+            'fallback' => [
                 '1.0.0.1',
-                '8.8.8.8'
-            ],
-            'fallback-filter'=>[
-                'geoip'=> true,
-                'ipcidr'=>[
-                    '240.0.0.0/4'
-                ]
-            ]
+                '8.8.8.8',
+            ],
+            'fallback-filter' => [
+                'geoip' => true,
+                'ipcidr' => [
+                    '240.0.0.0/4',
+                ],
+            ],
         ],
         'Proxy' => [],
         'ProxyGroup' => [
@@ -280,9 +282,9 @@ $_ENV['Clash_Profiles'] = [
                 'content' => [
                     'regex' => '(.*)',
                     'right-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
-                ]
+                ],
             ],
             [
                 'name' => '⚓️其他流量',
@@ -290,59 +292,59 @@ $_ENV['Clash_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🔰国外流量',
-                        '🚀直接连接'
-                    ]
-                ]
+                        '🚀直接连接',
+                    ],
+                ],
             ],
             [
                 'name' => '✈️Telegram',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Youtube',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Netflix',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬哔哩哔哩',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬国外媒体',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🍎苹果服务',
@@ -350,24 +352,24 @@ $_ENV['Clash_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🚀直接连接',
-                        '🔰国外流量'
-                    ]
-                ]
+                        '🔰国外流量',
+                    ],
+                ],
             ],
             [
                 'name' => '🚀直接连接',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        'DIRECT'
-                    ]
-                ]
-            ]
+                        'DIRECT',
+                    ],
+                ],
+            ],
         ],
         'Rule' => [
-            'source' => 'clash/default.tpl'
-        ]
-    ]
+            'source' => 'clash/default.tpl',
+        ],
+    ],
 ];
 
 /**
@@ -377,12 +379,12 @@ $_ENV['Surfboard_Profiles'] = [
     'default' => [
         'Checks' => [],
         'General' => [
-            'loglevel'   => 'notify',
+            'loglevel' => 'notify',
             'dns-server' => 'system, 119.29.29.29, 1.1.1.1',
             'skip-proxy' => '127.0.0.1, 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, 17.0.0.0/8, localhost, *.local, *.crashlytics.com',
         ],
         'Proxy' => [
-            '🚀直接连接 = direct'
+            '🚀直接连接 = direct',
         ],
         'ProxyGroup' => [
             [
@@ -391,9 +393,9 @@ $_ENV['Surfboard_Profiles'] = [
                 'content' => [
                     'regex' => '(.*)',
                     'right-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
-                ]
+                ],
             ],
             [
                 'name' => '⚓️其他流量',
@@ -401,63 +403,63 @@ $_ENV['Surfboard_Profiles'] = [
                 'content' => [
                     'left-proxies' => [
                         '🔰国外流量',
-                        '🚀直接连接'
-                    ]
-                ]
+                        '🚀直接连接',
+                    ],
+                ],
             ],
             [
                 'name' => '✈️Telegram',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Youtube',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬Netflix',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬哔哩哔哩',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🚀直接连接'
+                        '🚀直接连接',
                     ],
                     'regex' => '(.*)',
-                ]
+                ],
             ],
             [
                 'name' => '🎬国外媒体',
                 'type' => 'select',
                 'content' => [
                     'left-proxies' => [
-                        '🔰国外流量'
+                        '🔰国外流量',
                     ],
                     'regex' => '(.*)',
-                ]
-            ]
+                ],
+            ],
         ],
         'Rule' => [
-            'source' => 'surfboard/default.tpl'
-        ]
-    ]
+            'source' => 'surfboard/default.tpl',
+        ],
+    ],
 ];

+ 2 - 0
db/migrations/20220109130532_create_stream_media_table.php

@@ -2,6 +2,8 @@
 
 declare(strict_types=1);
 
+namespace Db\Migrations;
+
 use Phinx\Migration\AbstractMigration;
 
 final class CreateStreamMediaTable extends AbstractMigration

+ 36 - 0
phpinsights.php

@@ -4,5 +4,41 @@ declare(strict_types=1);
 
 return [
     'preset' => 'default',
+    'remove' => [
+        // TODO: remove
+        NunoMaduro\PhpInsights\Domain\Insights\ForbiddenGlobals::class,
+        SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff::class,
+        SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff::class,
+        SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff::class,
+        SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff::class,
+        SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff::class,
+        SlevomatCodingStandard\Sniffs\Classes\ForbiddenPublicPropertySniff::class,
+        NunoMaduro\PhpInsights\Domain\Sniffs\ForbiddenSetterSniff::class,
+        PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\EvalSniff::class,
+        PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\TodoSniff::class,
 
+        NunoMaduro\PhpInsights\Domain\Insights\CyclomaticComplexityIsHigh::class,
+        SlevomatCodingStandard\Sniffs\Functions\FunctionLengthSniff::class,
+        PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff::class,
+        NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineGlobalConstants::class,
+        PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\GlobalKeywordSniff::class,
+
+        // Allow it
+        SlevomatCodingStandard\Sniffs\ControlStructures\DisallowShortTernaryOperatorSniff::class,
+        SlevomatCodingStandard\Sniffs\Classes\ModernClassNameReferenceSniff::class,
+        SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff::class,
+        SlevomatCodingStandard\Sniffs\Classes\SuperfluousAbstractClassNamingSniff::class,
+    ],
+    'config' => [
+        PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff::class => [
+            'exclude' => [
+                'src/Command/Job.php',
+                'src/Command/PortAutoChange.php',
+            ],
+        ],
+    ],
+
+    'exclude' => [
+        'storage',
+    ],
 ];

+ 8 - 8
resources/views/material/admin/shop/edit.tpl

@@ -56,17 +56,17 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="traffic-package-min">最低可购买用户等级</label>
                                 <input class="form-control maxwidth-edit" id="traffic-package-min" type="text"
-                                value="{if $shop->traffic_package()}{$shop->content['traffic_package']['class']['min']}{else}0{/if}">
+                                value="{if $shop->trafficPackage()}{$shop->content['traffic_package']['class']['min']}{else}0{/if}">
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="traffic-package-max">最高可购买用户等级</label>
                                 <input class="form-control maxwidth-edit" id="traffic-package-max" type="text"
-                                value="{if $shop->traffic_package()}{$shop->content['traffic_package']['class']['max']}{else}0{/if}">
+                                value="{if $shop->trafficPackage()}{$shop->content['traffic_package']['class']['max']}{else}0{/if}">
                             </div>
                             <div class="form-group form-group-label">
                                 <div class="checkbox switch">
                                     <label for="traffic-package-enable">
-                                        <input {if $shop->traffic_package()}checked{/if} class="access-hide" id="traffic-package-enable" type="checkbox">
+                                        <input {if $shop->trafficPackage()}checked{/if} class="access-hide" id="traffic-package-enable" type="checkbox">
                                         <span class="switch-toggle"></span>是否设置此商品为流量叠加包
                                     </label>
                                     <p class="form-control-guide">
@@ -95,12 +95,12 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="class">等级</label>
                                 <input class="form-control maxwidth-edit" id="class" type="text"
-                                       value="{$shop->user_class()}">
+                                       value="{$shop->userClass()}">
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="class_expire">等级有效期天数</label>
                                 <input class="form-control maxwidth-edit" id="class_expire" type="text"
-                                       value="{$shop->class_expire()}">
+                                       value="{$shop->classExpire()}">
                             </div>
                             <p class="form-control-guide"><i class="material-icons">info</i>如需使用等级功能,请同时填写【等级】和【等级有效期天数】这两个项目</p>
                         </div>
@@ -112,7 +112,7 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="reset_exp">多少天内</label>
                                 <input class="form-control maxwidth-edit" id="reset_exp" type="number"
-                                       value="{$shop->reset_exp()}">
+                                       value="{$shop->resetExp()}">
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="reset">每多少天</label>
@@ -122,7 +122,7 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="reset_value">重置流量为多少G</label>
                                 <input class="form-control maxwidth-edit" id="reset_value" type="number"
-                                       value="{$shop->reset_value()}">
+                                       value="{$shop->resetValue()}">
                             </div>
                         </div>
                     </div>
@@ -149,7 +149,7 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="content_extra">服务支持</label>
                                 <input class="form-control maxwidth-edit" id="content_extra" type="text"
-                                       value="{foreach $shop->content_extra() as $service}{$service[0]}-{$service[1]}{if $service@last}{else};{/if}{/foreach}">
+                                       value="{foreach $shop->contentExtra() as $service}{$service[0]}-{$service[1]}{if $service@last}{else};{/if}{/foreach}">
                                 <p class="form-control-guide"><i class="material-icons">info</i>例:<code>check-全球节点分布;clear-快速客服响应</code>,减号左边为icon代号右边为文字,以;隔开
                                 </p>
                                 <p class="form-control-guide">icon代号参阅:<a

+ 5 - 5
resources/views/material/admin/user/edit.tpl

@@ -89,17 +89,17 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="last_detect_ban_time">最后一次被封禁的时间</label>
                                 <input class="form-control maxwidth-edit" id="last_detect_ban_time" type="text"
-                                       value="{$edit_user->last_detect_ban_time()}" readonly>
+                                       value="{$edit_user->lastDetectBanTime()}" readonly>
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="relieve_time">当前解封时间</label>
                                 <input class="form-control maxwidth-edit" id="relieve_time" type="text"
-                                       value="{$edit_user->relieve_time()}" readonly>
+                                       value="{$edit_user->relieveTime()}" readonly>
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="detect_ban_number">累计封禁次数</label>
                                 <input class="form-control maxwidth-edit" id="detect_ban_number" type="text"
-                                       value="{if $edit_user->detect_ban_number()==0}标杆用户,没有被封禁过耶{else}太坏了,这位用户累计被封禁过 {$edit_user->detect_ban_number()} 次呢{/if}" readonly>
+                                       value="{if $edit_user->detectBanNumber()==0}标杆用户,没有被封禁过耶{else}太坏了,这位用户累计被封禁过 {$edit_user->detectBanNumber()} 次呢{/if}" readonly>
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="all_detect_number">累计违规次数</label>
@@ -252,12 +252,12 @@
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="node_speedlimit">禁止用户访问的IP,一行一个</label>
                                 <textarea class="form-control maxwidth-edit" id="forbidden_ip"
-                                          rows="8">{$edit_user->get_forbidden_ip()}</textarea>
+                                          rows="8">{$edit_user->getForbiddenIp()}</textarea>
                             </div>
                             <div class="form-group form-group-label">
                                 <label class="floating-label" for="node_speedlimit">禁止用户访问的端口,一行一个</label>
                                 <textarea class="form-control maxwidth-edit" id="forbidden_port"
-                                          rows="8">{$edit_user->get_forbidden_port()}</textarea>
+                                          rows="8">{$edit_user->getForbiddenPort()}</textarea>
                             </div>
                         </div>
                     </div>

+ 1 - 1
resources/views/material/user/bought.tpl

@@ -42,7 +42,7 @@
                                                 <td>{$shop->shop()->content()}</td>
                                                 <td>{$shop->price} 元</td>
                                                 <td>{$shop->renew()}</td>
-                                                <td>{$shop->auto_reset_bandwidth()}</td>
+                                                <td>{$shop->autoResetBandwidthString()}</td>
                                                 <td>
                                                     <a class="btn btn-brand"
                                                        {if $shop->renew==0}disabled{else}href="javascript:void(0);" onClick="delete_modal_show('{$shop->id}')"{/if}>关闭自动续费</a>

+ 9 - 9
resources/views/material/user/edit.tpl

@@ -48,7 +48,7 @@
                                     <button class="btn btn-flat" id="method-update"><span class="icon">check</span>&nbsp</button>
                                 </div>
                                 <p>
-                                    当前加密方式:<code id="ajax-user-method" data-default="method">[{if URL::CanMethodConnect($user->method) == 2}SS{else}SS/SSR{/if}可连接] {$user->method}</code>
+                                    当前加密方式:<code id="ajax-user-method" data-default="method">[{if URL::canMethodConnect($user->method) == 2}SS{else}SS/SSR{/if}可连接] {$user->method}</code>
                                 </p>
                                 <div class="form-group form-group-label control-highlight-custom dropdown">
                                     <label class="floating-label" for="method">加密方式</label>
@@ -57,10 +57,10 @@
                                     <ul class="dropdown-menu" aria-labelledby="method">
                                         {$method_list = $config_service->getSupportParam('method')}
                                         {foreach $method_list as $method}
-                                            <li class="{if URL::CanMethodConnect($user->method) == 2}filter-item-ss{else}filter-item-universal{/if}">
+                                            <li class="{if URL::canMethodConnect($user->method) == 2}filter-item-ss{else}filter-item-universal{/if}">
                                                 <a href="#" class="dropdown-option" onclick="return false;"
                                                    val="{$method}"
-                                                   data="method">[{if URL::CanMethodConnect($method) == 2}SS{else}SS/SSR{/if}
+                                                   data="method">[{if URL::canMethodConnect($method) == 2}SS{else}SS/SSR{/if}
                                                     可连接] {$method}</a>
                                             </li>
                                         {/foreach}
@@ -72,7 +72,7 @@
                                     <div class="card-heading">协议&混淆设置</div>
                                     <button class="btn btn-flat" id="ssr-update"><span class="icon">check</span>&nbsp;</button>
                                 </div>
-                                <p>当前协议:<code id="ajax-user-protocol" data-default="protocol">[{if URL::CanProtocolConnect($user->protocol) == 3}SS/SSR{else}SSR{/if}可连接] {$user->protocol}</code></p>
+                                <p>当前协议:<code id="ajax-user-protocol" data-default="protocol">[{if URL::canProtocolConnect($user->protocol) == 3}SS/SSR{else}SSR{/if}可连接] {$user->protocol}</code></p>
                                 <div class="form-group form-group-label control-highlight-custom dropdown">
                                     <label class="floating-label" for="protocol">协议</label>
                                     <button id="protocol" class="form-control maxwidth-edit" data-toggle="dropdown"
@@ -80,9 +80,9 @@
                                     <ul class="dropdown-menu" aria-labelledby="protocol">
                                         {$protocol_list = $config_service->getSupportParam('protocol')}
                                         {foreach $protocol_list as $protocol}
-                                            <li class="{if URL::CanProtocolConnect($protocol) == 3}filter-item-universal{else}filter-item-ssr{/if}">
+                                            <li class="{if URL::canProtocolConnect($protocol) == 3}filter-item-universal{else}filter-item-ssr{/if}">
                                                 <a href="#" class="dropdown-option" onclick="return false;" val="{$protocol}" data="protocol">
-                                                    [{if URL::CanProtocolConnect($protocol) == 3}SS/SSR{else}SSR{/if}
+                                                    [{if URL::canProtocolConnect($protocol) == 3}SS/SSR{else}SSR{/if}
                                                     可连接] {$protocol}
                                                 </a>
                                             </li>
@@ -91,7 +91,7 @@
                                 </div>
                             </div>
                             <div class="card-inner">
-                                <p>当前混淆方式:<code id="ajax-user-obfs" data-default="obfs">[{if URL::CanObfsConnect($user->obfs) >= 3}SS/SSR{elseif URL::CanObfsConnect($user->obfs) == 1}SSR{else}SS{/if}可连接] {$user->obfs}</code></p>
+                                <p>当前混淆方式:<code id="ajax-user-obfs" data-default="obfs">[{if URL::canObfsConnect($user->obfs) >= 3}SS/SSR{elseif URL::canObfsConnect($user->obfs) == 1}SSR{else}SS{/if}可连接] {$user->obfs}</code></p>
                                 <p>SS 和 SSR 支持的混淆类型有所不同,simple_obfs_* 为 SS 的混淆方式,其他为 SSR 的混淆方式</p>
                                 <div class="form-group form-group-label control-highlight-custom dropdown">
                                     <label class="floating-label" for="obfs">混淆方式</label>
@@ -99,9 +99,9 @@
                                     <ul class="dropdown-menu" aria-labelledby="obfs">
                                         {$obfs_list = $config_service->getSupportParam('obfs')}
                                         {foreach $obfs_list as $obfs}
-                                            <li class="{if URL::CanObfsConnect($obfs) >= 3}filter-item-universal{else}{if URL::CanObfsConnect($obfs) == 1}filter-item-ssr{else}filter-item-ss{/if}{/if}">
+                                            <li class="{if URL::canObfsConnect($obfs) >= 3}filter-item-universal{else}{if URL::canObfsConnect($obfs) == 1}filter-item-ssr{else}filter-item-ss{/if}{/if}">
                                                 <a href="#" class="dropdown-option" onclick="return false;" val="{$obfs}" data="obfs">
-                                                    [{if URL::CanObfsConnect($obfs) >= 3}SS/SSR{else}{if URL::CanObfsConnect($obfs) == 1}SSR{else}SS{/if}{/if}可连接] {$obfs}
+                                                    [{if URL::canObfsConnect($obfs) >= 3}SS/SSR{else}{if URL::canObfsConnect($obfs) == 1}SSR{else}SS{/if}{/if}可连接] {$obfs}
                                                 </a>
                                             </li>
                                         {/foreach}

+ 6 - 6
resources/views/material/user/index.tpl

@@ -106,9 +106,9 @@
                                 <div class="nodemiddle node-flex">
                                     <div class="nodetype">
                                         {if $user->node_connector!=0}
-                                            <dd>{$user->online_ip_count()} / {$user->node_connector}</dd>
+                                            <dd>{$user->onlineIpCount()} / {$user->node_connector}</dd>
                                         {else}
-                                            <dd>{$user->online_ip_count()} / 不限制</dd>
+                                            <dd>{$user->onlineIpCount()} / 不限制</dd>
                                         {/if}
                                     </div>
                                 </div>
@@ -163,8 +163,8 @@
                         <div class="card-main">
                         <div class="card-inner margin-bottom-no">
                             <p class="card-heading" style="margin-bottom: 0;"><i class="icon icon-md">account_circle</i>流量使用情况</p>
-                                {if $user->valid_use_loop() != '未购买套餐.'}
-                                <p>下次流量重置时间:{$user->valid_use_loop()}</p>
+                                {if $user->validUseLoop() != '未购买套餐.'}
+                                <p>下次流量重置时间:{$user->validUseLoop()}</p>
                                 {/if}
                                 <div class="progressbar">
                                     <div class="before"></div>
@@ -174,7 +174,7 @@
                                         <div class="label la-top">
                                             <div class="bar ard color3"></div>
                                             <span class="traffic-info">今日已用</span>
-                                            <code class="card-tag tag-red">{$user->TodayusedTraffic()}</code>
+                                            <code class="card-tag tag-red">{$user->todayUsedTraffic()}</code>
                                         </div>
                                     </div>
                                 </div>
@@ -188,7 +188,7 @@
                                         <div class="label la-top">
                                             <div class="bar ard color2"><span></span></div>
                                             <span class="traffic-info">过去已用</span>
-                                            <code class="card-tag tag-orange">{$user->LastusedTraffic()}</code>
+                                            <code class="card-tag tag-orange">{$user->lastUsedTraffic()}</code>
                                         </div>
                                     </div>
                                 </div>

+ 3 - 3
resources/views/material/user/profile.tpl

@@ -57,9 +57,9 @@
                                                 <tr>
                                                     <td>#{$bought->id}</td>
                                                     <td>{$bought->shop()->name}</td>
-                                                    <td>{$bought->used_days()} 天</td>
-                                                    <td>{$bought->reset_time()}</td>
-                                                    <td>{$bought->exp_time()}</td>
+                                                    <td>{$bought->usedDays()} 天</td>
+                                                    <td>{$bought->resetTime()}</td>
+                                                    <td>{$bought->expTime()}</td>
                                                 </tr>
                                           		{/if}
                                           	{/foreach}

+ 12 - 12
resources/views/material/user/shop.tpl

@@ -52,18 +52,18 @@
             <div data-areatype="orders">
                 <div class="shop-flex">
                     {foreach $shops as $shop}
-                    {if $shop->traffic_package() == 0}
+                    {if $shop->trafficPackage() == 0}
                         <div class="card">
                             <div class="card-main">
                                 <div class="shop-name">{$shop->name}</div>
                                 <div class="shop-price">{$shop->price}</div>
                                 <div class="shop-tat">
-                                    <span>{$shop->bandwidth()}</span> / <span>{$shop->class_expire()}</span>
+                                    <span>{$shop->bandwidth()}</span> / <span>{$shop->classExpire()}</span>
                                 </div>
                                 <div class="shop-cube">
                                     <div>
                                         <div class="cube-detail">
-                                            <span>Lv.</span>{$shop->user_class()}
+                                            <span>Lv.</span>{$shop->userClass()}
                                         </div>
                                         <div class="cube-title">
                                             VIP
@@ -94,18 +94,18 @@
                                     <div class="shop-content-left">账号有效期:</div>
                                     <div class="shop-content-right">{$shop->expire()}<span>天</span></div>
                                     <div class="shop-content-left">重置周期:</div>
-                                    <div class="shop-content-right">{if {$shop->reset()} == '0' }N / A{else}{$shop->reset_exp()}
+                                    <div class="shop-content-right">{if {$shop->reset()} == '0' }N / A{else}{$shop->resetExp()}
                                             <span>天</span>
                                         {/if}</div>
                                     <div class="shop-content-left">重置频率:</div>
-                                    <div class="shop-content-right">{if {$shop->reset()} == '0' }N / A{else}{$shop->reset_value()}
+                                    <div class="shop-content-right">{if {$shop->reset()} == '0' }N / A{else}{$shop->resetValue()}
                                             <span>G</span>
                                             / {$shop->reset()}
                                             <span>天</span>
                                         {/if}</div>
                                 </div>
                                 <div class="shop-content-extra">
-                                    {foreach $shop->content_extra() as $service}
+                                    {foreach $shop->contentExtra() as $service}
                                         <div><span class="icon">{$service[0]}</span> {$service[1]}</div>
                                     {/foreach}
                                 </div>
@@ -120,15 +120,15 @@
                 </div>
                 <div class="shop-table">
                     {foreach $shops as $shop}
-                    {if $shop->traffic_package() == 0}
+                    {if $shop->trafficPackage() == 0}
                         <div class="shop-gridarea">
                             <div class="card">
                                 <div>
                                     <div class="shop-name"><span>{$shop->name}</span></div>
-                                    <div class="card-tag tag-gold">VIP {$shop->user_class()}</div>
+                                    <div class="card-tag tag-gold">VIP {$shop->userClass()}</div>
                                     <div class="card-tag tag-orange">¥ {$shop->price}</div>
                                     <div class="card-tag tag-cyan">{$shop->bandwidth()} G</div>
-                                    <div class="card-tag tag-blue">{$shop->class_expire()} 天</div>
+                                    <div class="card-tag tag-blue">{$shop->classExpire()} 天</div>
                                 </div>
                                 <div>
                                     <i class="material-icons">expand_more</i>
@@ -144,9 +144,9 @@
                                     <div class="card-tag tag-blue">N/A</div>
                                 {else}
                                     <div class="card-tag tag-black">重置周期</div>
-                                    <div class="card-tag tag-blue">{$shop->reset_exp()} 天</div>
+                                    <div class="card-tag tag-blue">{$shop->resetExp()} 天</div>
                                     <div class="card-tag tag-black">重置频率</div>
-                                    <div class="card-tag tag-blue">{$shop->reset_value()}G/{$shop->reset()}天</div>
+                                    <div class="card-tag tag-blue">{$shop->resetValue()}G/{$shop->reset()}天</div>
                                 {/if}
                                 {if {$shop->speedlimit()} == '0' }
                                     <div class="card-tag tag-black">端口速率</div>
@@ -171,7 +171,7 @@
             <div style="display: none;" data-areatype="trafficePackages">
                 <div class="shop-table" style="display: flex">
                     {foreach $shops as $shop}
-                    {if $shop->traffic_package() != 0}
+                    {if $shop->trafficPackage() != 0}
                     <div class="shop-gridarea">
                         <div class="card">
                             <div>

+ 7 - 6
src/Command/Backup.php

@@ -10,12 +10,13 @@ use App\Utils\Telegram;
 use Exception;
 use RuntimeException;
 
-class Backup extends Command
+final class Backup extends Command
 {
-    public $description = ''
-        . '├─=: php xcat Backup [选项]' . PHP_EOL
-        . '│ ├─ full                    - 整体数据备份' . PHP_EOL
-        . '│ ├─ simple                  - 只备份核心数据' . PHP_EOL;
+    public $description = <<<EOL
+├─=: php xcat Backup [选项]
+│ ├─ full                    - 整体数据备份
+│ ├─ simple                  - 只备份核心数据
+EOL;
 
     public function boot(): void
     {
@@ -76,7 +77,7 @@ class Backup extends Command
         system('rm /tmp/ssmodbackup.zip', $ret);
 
         if ($configs['auto_backup_notify'] === true) {
-            Telegram::Send('备份工作已经完成');
+            Telegram::send('备份工作已经完成');
         }
     }
 }

+ 4 - 4
src/Command/ClientDownload.php

@@ -11,7 +11,7 @@ use Exception;
  *
  * By GeekQuerxy
  */
-class ClientDownload extends Command
+final class ClientDownload extends Command
 {
     public $description = '├─=: php xcat ClientDownload - 定时更新客户端' . PHP_EOL;
 
@@ -325,7 +325,7 @@ class ClientDownload extends Command
     /**
      * 判断是否 JSON
      */
-    private function is_json(string $string): bool
+    private function isJson(string $string): bool
     {
         return json_decode($string, true) !== false;
     }
@@ -355,7 +355,7 @@ class ClientDownload extends Command
             }
         }
         $fileContent = file_get_contents($filePath);
-        if (! $this->is_json($fileContent)) {
+        if (! $this->isJson($fileContent)) {
             echo 'ClientDownloadVersion.json 文件格式异常,脚本中止.' . PHP_EOL;
             exit(0);
         }
@@ -404,7 +404,7 @@ class ClientDownload extends Command
             echo '- 检测到当前 ' . $task['name'] . ' 最新版本为 ' . $tagName . ',本地最新版本为 ' . $this->version[$task['name']] . PHP_EOL;
         }
         $this->version[$task['name']] = $tagName;
-        $nameFunction = function ($name) use ($task, $tagName) {
+        $nameFunction = static function ($name) use ($task, $tagName) {
             return str_replace(
                 [
                     '%taskName%',

+ 2 - 2
src/Command/DetectBan.php

@@ -8,7 +8,7 @@ use App\Models\DetectBanLog;
 use App\Models\DetectLog;
 use App\Models\User;
 
-class DetectBan extends Command
+final class DetectBan extends Command
 {
     public $description = '├─=: php xcat DetectBan      - 审计封禁定时任务' . PHP_EOL;
 
@@ -84,7 +84,7 @@ class DetectBan extends Command
                     }
                     if ($tmp !== 0) {
                         if ($_ENV['auto_detect_ban'][$tmp]['type'] === 'kill') {
-                            $user->kill_user();
+                            $user->killUser();
                         } else {
                             $last_detect_ban_time = $user->last_detect_ban_time;
                             $end_time = date('Y-m-d H:i:s');

+ 6 - 5
src/Command/DetectGFW.php

@@ -4,11 +4,12 @@ declare(strict_types=1);
 
 namespace App\Command;
 
+use App\Models\Node;
+use App\Models\User;
 use App\Services\Config;
 use App\Utils\Telegram;
-use Node;
 
-class DetectGFW extends Command
+final class DetectGFW extends Command
 {
     public $description = '├─=: php xcat DetectGFW      - 节点被墙检测定时任务' . PHP_EOL;
 
@@ -42,7 +43,7 @@ class DetectGFW extends Command
                     $detect_time = $_ENV['detect_gfw_count'];
                     for ($i = 1; $i <= $detect_time; $i++) {
                         $json_tcping = json_decode(file_get_contents($api_url), true);
-                        if (eval('return ' . $_ENV['detect_gfw_judge'] . ';')) {
+                        if ($_ENV['detect_gfw_judge']($json_tcping)) {
                             $result_tcping = true;
                             break;
                         }
@@ -71,7 +72,7 @@ class DetectGFW extends Command
                             );
                         }
                         if (Config::getconfig('Telegram.bool.NodeGFW')) {
-                            Telegram::Send($notice_text);
+                            Telegram::send($notice_text);
                         }
                         $node->gfw_block = true;
                         $node->save();
@@ -98,7 +99,7 @@ class DetectGFW extends Command
                             );
                         }
                         if (Config::getconfig('Telegram.bool.NodeGFW_recover')) {
-                            Telegram::Send($notice_text);
+                            Telegram::send($notice_text);
                         }
                         $node->gfw_block = false;
                         $node->save();

+ 10 - 9
src/Command/FinanceMail.php

@@ -9,13 +9,14 @@ use App\Utils\DatatablesHelper;
 use App\Utils\Telegram;
 use Ozdemir\Datatables\Datatables;
 
-class FinanceMail extends Command
+final class FinanceMail extends Command
 {
-    public $description = ''
-        . '├─=: php xcat FinanceMail [选项]' . PHP_EOL
-        . '│ ├─ day                     - 日报' . PHP_EOL
-        . '│ ├─ week                    - 周报' . PHP_EOL
-        . '│ ├─ month                   - 月报' . PHP_EOL;
+    public $description = <<<EOL
+├─=: php xcat FinanceMail [选项]
+│ ├─ day                     - 日报
+│ ├─ week                    - 周报
+│ ├─ month                   - 月报
+EOL;
 
     public function boot(): void
     {
@@ -74,7 +75,7 @@ class FinanceMail extends Command
         }
 
         if ($_ENV['finance_public']) {
-            Telegram::Send(
+            Telegram::send(
                 '新鲜出炉的财务日报~' . PHP_EOL .
                 '昨日总收入笔数:' . $income_count . PHP_EOL .
                 '昨日总收入金额:' . $income_total . PHP_EOL .
@@ -119,7 +120,7 @@ class FinanceMail extends Command
         }
 
         if ($_ENV['finance_public']) {
-            Telegram::Send(
+            Telegram::send(
                 '新鲜出炉的财务周报~' . PHP_EOL .
                 '上周总收入笔数:' . $income_count . PHP_EOL .
                 '上周总收入金额:' . $income_total . PHP_EOL .
@@ -162,7 +163,7 @@ class FinanceMail extends Command
         }
 
         if ($_ENV['finance_public']) {
-            Telegram::Send(
+            Telegram::send(
                 '新鲜出炉的财务月报~' . PHP_EOL .
                 '上月总收入笔数:' . $income_count . PHP_EOL .
                 '上月总收入金额:' . $income_total . PHP_EOL .

+ 23 - 22
src/Command/Job.php

@@ -28,14 +28,15 @@ use App\Utils\Telegram;
 use App\Utils\Tools;
 use Exception;
 
-class Job extends Command
+final class Job extends Command
 {
-    public $description = ''
-        . '├─=: php xcat Job [选项]' . PHP_EOL
-        . '│ ├─ SendMail                - 处理邮件队列' . PHP_EOL
-        . '│ ├─ DailyJob                - 每日任务' . PHP_EOL
-        . '│ ├─ CheckJob                - 检查任务,每分钟' . PHP_EOL
-        . '│ ├─ UserJob                 - 用户账户相关任务,每小时' . PHP_EOL;
+    public $description = <<<EOL
+├─=: php xcat Job [选项]
+│ ├─ SendMail                - 处理邮件队列
+│ ├─ DailyJob                - 每日任务
+│ ├─ CheckJob                - 检查任务,每分钟
+│ ├─ UserJob                 - 用户账户相关任务,每小时
+EOL;
 
     public function boot(): void
     {
@@ -67,7 +68,7 @@ class Job extends Command
         fwrite($myfile, $txt);
         fclose($myfile);
         // 分块处理,节省内存
-        EmailQueue::chunkById(1000, function ($email_queues): void {
+        EmailQueue::chunkById(1000, static function ($email_queues): void {
             foreach ($email_queues as $email_queue) {
                 try {
                     Mail::send($email_queue->to_email, $email_queue->subject, $email_queue->template, json_decode($email_queue->array), []);
@@ -107,8 +108,8 @@ class Job extends Command
 
         // ------- 重置自增 ID
         $db = new DatatablesHelper();
-        Tools::reset_auto_increment($db, 'node_online_log');
-        Tools::reset_auto_increment($db, 'node_info');
+        Tools::resetAutoIncrement($db, 'node_online_log');
+        Tools::resetAutoIncrement($db, 'node_info');
         // ------- 重置自增 ID
 
         // ------- 用户流量重置
@@ -129,9 +130,9 @@ class Job extends Command
                 continue;
             }
             $bought_users[] = $bought->userid;
-            if ($bought->valid() && $bought->used_days() % $shop->reset() === 0 && $bought->used_days() !== 0) {
+            if ($bought->valid() && $bought->usedDays() % $shop->reset() === 0 && $bought->usedDays() !== 0) {
                 echo '流量重置-' . $user->id . "\n";
-                $user->transfer_enable = Tools::toGB($shop->reset_value());
+                $user->transfer_enable = Tools::toGB($shop->resetValue());
                 $user->u = 0;
                 $user->d = 0;
                 $user->last_day_t = 0;
@@ -140,7 +141,7 @@ class Job extends Command
                     $_ENV['appName'] . '-您的流量被重置了',
                     'news/warn.tpl',
                     [
-                        'text' => '您好,根据您所订购的订单 ID:' . $bought->id . ',流量已经被重置为' . $shop->reset_value() . 'GB',
+                        'text' => '您好,根据您所订购的订单 ID:' . $bought->id . ',流量已经被重置为' . $shop->resetValue() . 'GB',
                     ],
                     [],
                     $_ENV['email_queue']
@@ -149,7 +150,7 @@ class Job extends Command
         }
         // ------- 用户流量重置
 
-        User::chunkById(1000, function ($users) use ($bought_users): void {
+        User::chunkById(1000, static function ($users) use ($bought_users): void {
             foreach ($users as $user) {
                 /** @var User $user */
                 $user->last_day_t = $user->u + $user->d;
@@ -182,7 +183,7 @@ class Job extends Command
 
         // ------- 发送每日系统运行报告
         if (Config::getconfig('Telegram.bool.DailyJob')) {
-            Telegram::Send(Config::getconfig('Telegram.string.DailyJob'));
+            Telegram::send(Config::getconfig('Telegram.string.DailyJob'));
         }
         // ------- 发送每日系统运行报告
     }
@@ -238,7 +239,7 @@ class Job extends Command
                     }
 
                     if (Config::getconfig('Telegram.bool.NodeOffline')) {
-                        Telegram::Send($notice_text);
+                        Telegram::send($notice_text);
                     }
 
                     $node->online = false;
@@ -283,7 +284,7 @@ class Job extends Command
                     }
 
                     if (Config::getconfig('Telegram.bool.NodeOnline')) {
-                        Telegram::Send($notice_text);
+                        Telegram::send($notice_text);
                     }
 
                     $node->online = true;
@@ -297,8 +298,8 @@ class Job extends Command
         $nodes = Node::get();
         foreach ($nodes as $node) {
             /** @var Node $node */
-            $server = $node->get_out_address();
-            if (! Tools::is_ip($server) && $node->changeNodeIp($server)) {
+            $server = $node->getOutAddress();
+            if (! Tools::isIp($server) && $node->changeNodeIp($server)) {
                 $node->save();
             }
         }
@@ -387,7 +388,7 @@ class Job extends Command
                     [],
                     $_ENV['email_queue']
                 );
-                $user->kill_user();
+                $user->killUser();
                 continue;
             }
 
@@ -409,7 +410,7 @@ class Job extends Command
                     [],
                     $_ENV['email_queue']
                 );
-                $user->kill_user();
+                $user->killUser();
                 continue;
             }
 
@@ -428,7 +429,7 @@ class Job extends Command
                     [],
                     $_ENV['email_queue']
                 );
-                $user->kill_user();
+                $user->killUser();
                 continue;
             }
 

+ 9 - 8
src/Command/PortAutoChange.php

@@ -11,10 +11,11 @@ declare(strict_types=1);
 
 namespace App\Command;
 
+use App\Models\Node;
+use App\Models\User;
 use App\Utils\URL;
-use User;
 
-class PortAutoChange extends Command
+final class PortAutoChange extends Command
 {
     public $description = '├─=: php xcat PortAutoChange - 端口被墙则自动更换端口' . PHP_EOL;
 
@@ -66,7 +67,7 @@ class PortAutoChange extends Command
                 if ($mu_user === null) {
                     continue;
                 }
-                $port = $this->OutPort($node->server, $mu_node->server);
+                $port = $this->outPort($node->server, $mu_node->server);
                 $api_url = $_ENV['detect_gfw_url'];
                 $api_url = str_replace(
                     ['{ip}', '{port}'],
@@ -122,7 +123,7 @@ class PortAutoChange extends Command
                 $mu_user->port = $new_port;
                 $mu_user->save();
                 foreach ($mu_port_nodes as $mu_port_node) {
-                    $node_port = $this->OutPort($mu_port_node->server, $port);
+                    $node_port = $this->outPort($mu_port_node->server, $port);
                     if (in_array($mu_port_node->id, $array) && ! in_array($mu_port_node->id, $this->Config['exception_node_id'])) {
                         if ($node_port !== $port) {
                             if ($node_port === $new_port) {
@@ -171,7 +172,7 @@ class PortAutoChange extends Command
                         continue;
                     }
                     $node = Node::find($node_id);
-                    $node_port = $this->OutPort($node->server, $port);
+                    $node_port = $this->outPort($node->server, $port);
                     if ($node_port !== $port) {
                         if (strpos($node->server, '#' . $node_port) !== false) {
                             echo '#' . $node->id . ' - 节点 - ' . $node->name . ' - 端口从' . $node_port . '偏移到了新的端口 ' . $new_port . PHP_EOL;
@@ -195,13 +196,13 @@ class PortAutoChange extends Command
         }
     }
 
-    public function OutPort($server, $mu_port)
+    public function outPort($server, $mu_port)
     {
         $node_port = $mu_port;
         if (strpos($server, ';') !== false) {
             $node_server = explode(';', $server);
             if (strpos($node_server[1], 'port') !== false) {
-                $item = URL::parse_args($node_server[1]);
+                $item = URL::parseArgs($node_server[1]);
                 if (strpos($item['port'], '#') !== false) {
                     if (strpos($item['port'], '+') !== false) {
                         $args_explode = explode('+', $item['port']);
@@ -230,7 +231,7 @@ class PortAutoChange extends Command
         $detect_time = $_ENV['detect_gfw_count'];
         for ($i = 1; $i <= $detect_time; $i++) {
             $json_tcping = json_decode(file_get_contents($api_url), true);
-            if (eval('return ' . $_ENV['detect_gfw_judge'] . ';')) {
+            if ($_ENV['detect_gfw_judge']($json_tcping)) {
                 $result_tcping = true;
                 break;
             }

+ 2 - 2
src/Command/SendDiaryMail.php

@@ -11,7 +11,7 @@ use App\Services\Config;
 use App\Utils\Telegram;
 use App\Utils\Tools;
 
-class SendDiaryMail extends Command
+final class SendDiaryMail extends Command
 {
     public $description = '├─=: php xcat SendDiaryMail  - 每日流量报告' . PHP_EOL;
 
@@ -37,7 +37,7 @@ class SendDiaryMail extends Command
         $sts = new Analytics();
 
         if (Config::getconfig('Telegram.bool.Diary')) {
-            Telegram::Send(
+            Telegram::send(
                 str_replace(
                     [
                         '%getTodayCheckinUser%',

+ 10 - 9
src/Command/Tool.php

@@ -8,16 +8,17 @@ use App\Models\Setting;
 use App\Utils\DatatablesHelper;
 use App\Utils\QQWry;
 
-class Tool extends Command
+final class Tool extends Command
 {
-    public $description = ''
-        . '├─=: php xcat Tool [选项]' . PHP_EOL
-        . '│ ├─ initQQWry               - 下载 IP 解析库' . PHP_EOL
-        . '│ ├─ setTelegram             - 设置 Telegram 机器人' . PHP_EOL
-        . '│ ├─ detectConfigs           - 检查数据库内新增的配置' . PHP_EOL
-        . '│ ├─ resetAllSettings        - 使用默认值覆盖设置中心设置' . PHP_EOL
-        . '│ ├─ exportAllSettings       - 导出所有设置' . PHP_EOL
-        . '│ ├─ importAllSettings       - 导入所有设置' . PHP_EOL;
+    public $description = <<<EOL
+├─=: php xcat Tool [选项]
+│ ├─ initQQWry               - 下载 IP 解析库
+│ ├─ setTelegram             - 设置 Telegram 机器人
+│ ├─ detectConfigs           - 检查数据库内新增的配置
+│ ├─ resetAllSettings        - 使用默认值覆盖设置中心设置
+│ ├─ exportAllSettings       - 导出所有设置
+│ ├─ importAllSettings       - 导入所有设置
+EOL;
 
     public function boot(): void
     {

+ 9 - 9
src/Command/Update.php

@@ -9,7 +9,7 @@ use App\Utils\DatatablesHelper;
 use Illuminate\Database\Capsule\Manager as Capsule;
 use Illuminate\Database\Schema\Blueprint;
 
-class Update extends Command
+final class Update extends Command
 {
     public $description = '├─=: php xcat Update         - 更新并迁移配置' . PHP_EOL;
 
@@ -40,7 +40,7 @@ class Update extends Command
 
         //执行版本升级
         $version_old = $_ENV['version'] ?? 0;
-        $this->old_to_new($version_old);
+        $this->oldToNew($version_old);
         $this->addColumns('user', 'uuid', 'TEXT', true, 'NULL', 'uuid', 'passwd');
 
         //将旧config迁移到新config上
@@ -150,7 +150,7 @@ class Update extends Command
         $datatables->query('ALTER TABLE `' . $table . '` ADD COLUMN `' . $columu . '` ' . $type . $isnull . 'DEFAULT ' . $default . " COMMENT '" . $comment . "' AFTER `" . $after . '`');
     }
 
-    public function old_to_new($version_old): void
+    public function oldToNew($version_old): void
     {
         if ($version_old < 2) {
             // 版本 2 开始
@@ -163,7 +163,7 @@ class Update extends Command
                 echo '创建 gconfig 表.' . PHP_EOL;
                 Capsule::schema()->create(
                     'gconfig',
-                    function (Blueprint $table): void {
+                    static function (Blueprint $table): void {
                         $table->engine = 'InnoDB';
                         $table->charset = 'utf8mb4';
                         $table->collation = 'utf8mb4_unicode_ci';
@@ -185,7 +185,7 @@ class Update extends Command
                 echo '创建 user_subscribe_log 表.' . PHP_EOL;
                 Capsule::schema()->create(
                     'user_subscribe_log',
-                    function (Blueprint $table): void {
+                    static function (Blueprint $table): void {
                         $table->engine = 'InnoDB';
                         $table->charset = 'utf8mb4';
                         $table->collation = 'utf8mb4_unicode_ci';
@@ -204,7 +204,7 @@ class Update extends Command
                 echo '创建 detect_ban_log 表.' . PHP_EOL;
                 Capsule::schema()->create(
                     'detect_ban_log',
-                    function (Blueprint $table): void {
+                    static function (Blueprint $table): void {
                         $table->engine = 'InnoDB';
                         $table->charset = 'utf8mb4';
                         $table->collation = 'utf8mb4_unicode_ci';
@@ -234,7 +234,7 @@ class Update extends Command
                 echo '添加 last_detect_ban_time 到 user 表.' . PHP_EOL;
                 Capsule::schema()->table(
                     'user',
-                    function (Blueprint $table): void {
+                    static function (Blueprint $table): void {
                         $table->dateTime('last_detect_ban_time')->default('1989-06-04 00:05:00')->after('enable');
                     }
                 );
@@ -243,7 +243,7 @@ class Update extends Command
                 echo '添加 all_detect_number 到 user 表.' . PHP_EOL;
                 Capsule::schema()->table(
                     'user',
-                    function (Blueprint $table): void {
+                    static function (Blueprint $table): void {
                         $table->integer('all_detect_number')->default(0)->after('last_detect_ban_time');
                     }
                 );
@@ -262,7 +262,7 @@ class Update extends Command
                 echo '添加 status 到 detect_log 表.' . PHP_EOL;
                 Capsule::schema()->table(
                     'detect_log',
-                    function (Blueprint $table): void {
+                    static function (Blueprint $table): void {
                         $table->integer('status')->default(0)->after('node_id');
                     }
                 );

+ 20 - 20
src/Command/User.php

@@ -12,18 +12,18 @@ use App\Utils\Tools;
 use Exception;
 use Ramsey\Uuid\Uuid;
 
-class User extends Command
+final class User extends Command
 {
-    public $description = ''
-        . '├─=: php xcat User [选项]' . PHP_EOL
-        . '│ ├─ getCookie               - 获取指定用户的 Cookie' . PHP_EOL
-        . '│ ├─ resetPort               - 重置单个用户端口' . PHP_EOL
-        . '│ ├─ createAdmin             - 创建管理员帐号' . PHP_EOL
-        . '│ ├─ resetAllPort            - 重置所有用户端口' . PHP_EOL
-        . '│ ├─ resetTraffic            - 重置所有用户流量' . PHP_EOL
-        . '│ ├─ generateUUID            - 为所有用户生成新的 UUID' . PHP_EOL
-        . '│ ├─ generateGa              - 为所有用户生成新的 Ga Secret' . PHP_EOL;
-
+    public $description = <<<EOL
+├─=: php xcat User [选项]
+│ ├─ getCookie               - 获取指定用户的 Cookie
+│ ├─ resetPort               - 重置单个用户端口
+│ ├─ createAdmin             - 创建管理员帐号
+│ ├─ resetAllPort            - 重置所有用户端口
+│ ├─ resetTraffic            - 重置所有用户流量
+│ ├─ generateUUID            - 为所有用户生成新的 UUID
+│ ├─ generateGa              - 为所有用户生成新的 Ga Secret;
+EOL;
     public function boot(): void
     {
         if (count($this->argv) === 2) {
@@ -33,7 +33,7 @@ class User extends Command
             if (method_exists($this, $methodName)) {
                 $this->$methodName();
             } else {
-                echo '方法不存在.' . PHP_EOL;
+                echo '方法不存在.';
             }
         }
     }
@@ -48,10 +48,10 @@ class User extends Command
         if ($user !== null) {
             $user->port = Tools::getAvPort();
             if ($user->save()) {
-                echo '重置成功!' . PHP_EOL;
+                echo '重置成功!';
             }
         } else {
-            echo 'not found user.' . PHP_EOL;
+            echo 'not found user.';
         }
     }
 
@@ -84,7 +84,7 @@ class User extends Command
             echo $e->getMessage();
             return;
         }
-        echo 'reset traffic successful' . PHP_EOL;
+        echo 'reset traffic successful';
     }
 
     /**
@@ -98,7 +98,7 @@ class User extends Command
             /** @var ModelsUser $user */
             $user->generateUUID($current_timestamp);
         }
-        echo 'generate UUID successful' . PHP_EOL;
+        echo 'generate UUID successful';
     }
 
     /**
@@ -114,7 +114,7 @@ class User extends Command
             $user->ga_token = $secret;
             $user->save();
         }
-        echo 'generate Ga Secret successful' . PHP_EOL;
+        echo 'generate Ga Secret successful';
     }
 
     /**
@@ -179,12 +179,12 @@ class User extends Command
             $user->ga_enable = 0;
 
             if ($user->save()) {
-                echo '创建成功,请在主页登录' . PHP_EOL;
+                echo '创建成功,请在主页登录';
             } else {
-                echo '创建失败,请检查数据库配置' . PHP_EOL;
+                echo '创建失败,请检查数据库配置';
             }
         } else {
-            echo '已取消创建' . PHP_EOL;
+            echo '已取消创建';
         }
     }
 

+ 14 - 16
src/Controllers/Admin/AnnController.php

@@ -4,12 +4,15 @@ declare(strict_types=1);
 
 namespace App\Controllers\Admin;
 
-use Ann;
 use App\Controllers\AdminController;
+use App\Models\Ann;
+use App\Models\User;
+use App\Utils\ResponseHelper;
 use App\Utils\Telegram;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class AnnController extends AdminController
+final class AnnController extends AdminController
 {
     /**
      * 后台公告页面
@@ -18,19 +21,14 @@ class AnnController extends AdminController
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'op' => '操作',
-            'id' => 'ID',
-            'date' => '日期',
-            'content' => '内容',
-        ];
-        $table_config['default_show_column'] = [
-            'op', 'id', 'date', 'content',
-        ];
-        $table_config['ajax_url'] = 'announcement/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'op' => '操作',
+                    'id' => 'ID',
+                    'date' => '日期',
+                    'content' => '内容',
+                ], 'announcement/ajax'))
                 ->display('admin/announcement/index.tpl')
         );
     }
@@ -132,7 +130,7 @@ class AnnController extends AdminController
                 ]);
             }
         }
-        Telegram::SendMarkdown('新公告:' . PHP_EOL . $request->getParam('markdown'));
+        Telegram::sendMarkdown('新公告:' . PHP_EOL . $request->getParam('markdown'));
         if ($issend === 1) {
             $msg = '公告添加成功,邮件发送成功';
         } else {
@@ -176,7 +174,7 @@ class AnnController extends AdminController
                 'msg' => '修改失败',
             ]);
         }
-        Telegram::SendMarkdown('公告更新:' . PHP_EOL . $request->getParam('markdown'));
+        Telegram::sendMarkdown('公告更新:' . PHP_EOL . $request->getParam('markdown'));
         return $response->withJson([
             'ret' => 1,
             'msg' => '修改成功',

+ 3 - 2
src/Controllers/Admin/ApiController.php

@@ -7,9 +7,10 @@ namespace App\Controllers\Admin;
 use App\Controllers\BaseController;
 use App\Models\Node;
 use Psr\Http\Message\ResponseInterface;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class ApiController extends BaseController
+final class ApiController extends BaseController
 {
     /**
      * @param array     $args

+ 20 - 25
src/Controllers/Admin/CodeController.php

@@ -9,10 +9,12 @@ use App\Models\Code;
 use App\Models\Setting;
 use App\Services\Auth;
 use App\Services\Mail;
+use App\Utils\ResponseHelper;
 use App\Utils\Tools;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class CodeController extends AdminController
+final class CodeController extends AdminController
 {
     /**
      * 后台充值码及充值记录页面
@@ -21,21 +23,18 @@ class CodeController extends AdminController
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'code' => '内容',
-            'type' => '类型',
-            'number' => '操作',
-            'isused' => '是否已经使用',
-            'userid' => '用户ID',
-            'user_name' => '用户名',
-            'usedatetime' => '使用时间',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'code/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'code' => '内容',
+                    'type' => '类型',
+                    'number' => '操作',
+                    'isused' => '是否已经使用',
+                    'userid' => '用户ID',
+                    'user_name' => '用户名',
+                    'usedatetime' => '使用时间',
+                ], 'code/ajax'))
                 ->display('admin/code/index.tpl')
         );
     }
@@ -43,7 +42,7 @@ class CodeController extends AdminController
     /**
      * @param array     $args
      */
-    public function ajax_code(Request $request, Response $response, array $args)
+    public function ajaxCode(Request $request, Response $response, array $args)
     {
         $query = Code::getTableDataFromAdmin(
             $request,
@@ -65,7 +64,7 @@ class CodeController extends AdminController
             $tempdata['number'] = $value->number();
             $tempdata['isused'] = $value->isused();
             $tempdata['userid'] = $value->userid();
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['usedatetime'] = $value->usedatetime();
 
             $data[] = $tempdata;
@@ -93,7 +92,7 @@ class CodeController extends AdminController
     /**
      * @param array     $args
      */
-    public function donate_create(Request $request, Response $response, array $args)
+    public function donateCreate(Request $request, Response $response, array $args)
     {
         return $response->write(
             $this->view()
@@ -152,15 +151,13 @@ class CodeController extends AdminController
             );
         }
 
-        $rs['ret'] = 1;
-        $rs['msg'] = '充值码添加成功';
-        return $response->withJson($rs);
+        return ResponseHelper::successfully($response, '充值码添加成功');
     }
 
     /**
      * @param array     $args
      */
-    public function donate_add(Request $request, Response $response, array $args)
+    public function donateAdd(Request $request, Response $response, array $args)
     {
         $amount = $request->getParam('amount');
         $type = $request->getParam('type');
@@ -176,8 +173,6 @@ class CodeController extends AdminController
 
         $code->save();
 
-        $rs['ret'] = 1;
-        $rs['msg'] = '添加成功';
-        return $response->withJson($rs);
+        return ResponseHelper::successfully($response, '添加成功');
     }
 }

+ 19 - 21
src/Controllers/Admin/DetectBanLogController.php

@@ -6,34 +6,32 @@ namespace App\Controllers\Admin;
 
 use App\Controllers\AdminController;
 use App\Models\DetectBanLog;
+use App\Utils\ResponseHelper;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class DetectBanLogController extends AdminController
+final class DetectBanLogController extends AdminController
 {
     /**
      * @param array     $args
      */
     public function index(Request $request, Response $response, array $args): ResponseInterface
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'user_id' => '用户ID',
-            'user_name' => '用户名',
-            'email' => '用户邮箱',
-            'detect_number' => '违规次数',
-            'ban_time' => '封禁时长(分钟)',
-            'start_time' => '统计开始时间',
-            'end_time' => '统计结束以及封禁开始时间',
-            'ban_end_time' => '封禁结束时间',
-            'all_detect_number' => '累计违规次数',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'ban/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'user_id' => '用户ID',
+                    'user_name' => '用户名',
+                    'email' => '用户邮箱',
+                    'detect_number' => '违规次数',
+                    'ban_time' => '封禁时长(分钟)',
+                    'start_time' => '统计开始时间',
+                    'end_time' => '统计结束以及封禁开始时间',
+                    'ban_end_time' => '封禁结束时间',
+                    'all_detect_number' => '累计违规次数',
+                ], 'ban/ajax'))
                 ->display('admin/detect/ban.tpl')
         );
     }
@@ -41,7 +39,7 @@ class DetectBanLogController extends AdminController
     /**
      * @param array     $args
      */
-    public function ajax_log(Request $request, Response $response, array $args): ResponseInterface
+    public function ajaxLog(Request $request, Response $response, array $args): ResponseInterface
     {
         $query = DetectBanLog::getTableDataFromAdmin(
             $request,
@@ -57,7 +55,7 @@ class DetectBanLogController extends AdminController
             /** @var DetectBanLog $value */
 
             if ($value->user() === null) {
-                DetectBanLog::user_is_null($value);
+                DetectBanLog::userIsNull($value);
                 continue;
             }
             $tempdata = [];
@@ -67,9 +65,9 @@ class DetectBanLogController extends AdminController
             $tempdata['email'] = $value->email;
             $tempdata['detect_number'] = $value->detect_number;
             $tempdata['ban_time'] = $value->ban_time;
-            $tempdata['start_time'] = $value->start_time();
-            $tempdata['end_time'] = $value->end_time();
-            $tempdata['ban_end_time'] = $value->ban_end_time();
+            $tempdata['start_time'] = $value->startTime();
+            $tempdata['end_time'] = $value->endTime();
+            $tempdata['ban_end_time'] = $value->banEndTime();
             $tempdata['all_detect_number'] = $value->all_detect_number;
 
             $data[] = $tempdata;

+ 36 - 41
src/Controllers/Admin/DetectController.php

@@ -7,30 +7,28 @@ namespace App\Controllers\Admin;
 use App\Controllers\AdminController;
 use App\Models\DetectLog;
 use App\Models\DetectRule;
+use App\Utils\ResponseHelper;
 use App\Utils\Telegram;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class DetectController extends AdminController
+final class DetectController extends AdminController
 {
     /**
      * @param array     $args
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'op' => '操作',
-            'id' => 'ID',
-            'name' => '名称',
-            'text' => '介绍',
-            'regex' => '正则表达式',
-            'type' => '类型',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'detect/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'op' => '操作',
+                    'id' => 'ID',
+                    'name' => '名称',
+                    'text' => '介绍',
+                    'regex' => '正则表达式',
+                    'type' => '类型',
+                ], 'detect/ajax'))
                 ->display('admin/detect/index.tpl')
         );
     }
@@ -38,7 +36,7 @@ class DetectController extends AdminController
     /**
      * @param array     $args
      */
-    public function ajax_rule(Request $request, Response $response, array $args)
+    public function ajaxRule(Request $request, Response $response, array $args)
     {
         $query = DetectRule::getTableDataFromAdmin(
             $request,
@@ -101,7 +99,7 @@ class DetectController extends AdminController
             ]);
         }
 
-        Telegram::SendMarkdown('有新的审计规则:' . $rule->name);
+        Telegram::sendMarkdown('有新的审计规则:' . $rule->name);
         return $response->withJson([
             'ret' => 1,
             'msg' => '添加成功',
@@ -141,7 +139,7 @@ class DetectController extends AdminController
                 'msg' => '修改失败',
             ]);
         }
-        Telegram::SendMarkdown('规则更新:' . PHP_EOL . $request->getParam('name'));
+        Telegram::sendMarkdown('规则更新:' . PHP_EOL . $request->getParam('name'));
         return $response->withJson([
             'ret' => 1,
             'msg' => '修改成功',
@@ -172,24 +170,21 @@ class DetectController extends AdminController
      */
     public function log(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'user_id' => '用户ID',
-            'user_name' => '用户名',
-            'node_id' => '节点ID',
-            'node_name' => '节点名',
-            'list_id' => '规则ID',
-            'rule_name' => '规则名',
-            'rule_text' => '规则描述',
-            'rule_regex' => '规则正则表达式',
-            'rule_type' => '规则类型',
-            'datetime' => '时间',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'log/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'user_id' => '用户ID',
+                    'user_name' => '用户名',
+                    'node_id' => '节点ID',
+                    'node_name' => '节点名',
+                    'list_id' => '规则ID',
+                    'rule_name' => '规则名',
+                    'rule_text' => '规则描述',
+                    'rule_regex' => '规则正则表达式',
+                    'rule_type' => '规则类型',
+                    'datetime' => '时间',
+                ], 'log/ajax'))
                 ->display('admin/detect/log.tpl')
         );
     }
@@ -197,7 +192,7 @@ class DetectController extends AdminController
     /**
      * @param array     $args
      */
-    public function ajax_log(Request $request, Response $response, array $args)
+    public function ajaxLog(Request $request, Response $response, array $args)
     {
         $query = DetectLog::getTableDataFromAdmin(
             $request,
@@ -219,28 +214,28 @@ class DetectController extends AdminController
             /** @var DetectLog $value */
 
             if ($value->rule() === null) {
-                DetectLog::rule_is_null($value);
+                DetectLog::ruleIsNull($value);
                 continue;
             }
             if ($value->node() === null) {
-                DetectLog::node_is_null($value);
+                DetectLog::nodeIsNull($value);
                 continue;
             }
             if ($value->user() === null) {
-                DetectLog::user_is_null($value);
+                DetectLog::userIsNull($value);
                 continue;
             }
             $tempdata = [];
             $tempdata['id'] = $value->id;
             $tempdata['user_id'] = $value->user_id;
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['node_id'] = $value->node_id;
-            $tempdata['node_name'] = $value->node_name();
+            $tempdata['node_name'] = $value->nodeName();
             $tempdata['list_id'] = $value->list_id;
-            $tempdata['rule_name'] = $value->rule_name();
-            $tempdata['rule_text'] = $value->rule_text();
-            $tempdata['rule_regex'] = $value->rule_regex();
-            $tempdata['rule_type'] = $value->rule_type();
+            $tempdata['rule_name'] = $value->ruleName();
+            $tempdata['rule_text'] = $value->ruleText();
+            $tempdata['rule_regex'] = $value->ruleRegex();
+            $tempdata['rule_type'] = $value->ruleType();
             $tempdata['datetime'] = $value->datetime();
 
             $data[] = $tempdata;

+ 3 - 2
src/Controllers/Admin/GConfigController.php

@@ -10,7 +10,7 @@ use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class GConfigController extends AdminController
+final class GConfigController extends AdminController
 {
     /**
      * @param array     $args
@@ -51,6 +51,7 @@ class GConfigController extends AdminController
      */
     public function telegram(Request $request, Response $response, array $args): ResponseInterface
     {
+        $table_config = [];
         $table_config['total_column'] = [
             'op' => '操作',
             'name' => '配置名称',
@@ -76,7 +77,7 @@ class GConfigController extends AdminController
     /**
      * @param array     $args
      */
-    public function telegram_ajax(Request $request, Response $response, array $args): ResponseInterface
+    public function telegramAjax(Request $request, Response $response, array $args): ResponseInterface
     {
         $query = GConfig::getTableDataFromAdmin(
             $request,

+ 48 - 59
src/Controllers/Admin/IpController.php

@@ -10,11 +10,12 @@ use App\Models\Ip;
 use App\Models\LoginIp;
 use App\Models\UnblockIp;
 use App\Utils\QQWry;
+use App\Utils\ResponseHelper;
 use App\Utils\Tools;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class IpController extends AdminController
+final class IpController extends AdminController
 {
     /**
      * 后台登录记录页面
@@ -23,20 +24,17 @@ class IpController extends AdminController
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'userid' => '用户ID',
-            'user_name' => '用户名',
-            'ip' => 'IP',
-            'location' => '归属地',
-            'datetime' => '时间',
-            'type' => '类型',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'login/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'userid' => '用户ID',
+                    'user_name' => '用户名',
+                    'ip' => 'IP',
+                    'location' => '归属地',
+                    'datetime' => '时间',
+                    'type' => '类型',
+                ], 'login/ajax'))
                 ->display('admin/ip/login.tpl')
         );
     }
@@ -46,7 +44,7 @@ class IpController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_login(Request $request, Response $response, array $args)
+    public function ajaxLogin(Request $request, Response $response, array $args)
     {
         $query = LoginIp::getTableDataFromAdmin(
             $request,
@@ -66,13 +64,13 @@ class IpController extends AdminController
             /** @var LoginIp $value */
 
             if ($value->user() === null) {
-                LoginIp::user_is_null($value);
+                LoginIp::userIsNull($value);
                 continue;
             }
             $tempdata = [];
             $tempdata['id'] = $value->id;
             $tempdata['userid'] = $value->userid;
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['ip'] = $value->ip;
             $tempdata['location'] = $value->location($QQWry);
             $tempdata['datetime'] = $value->datetime();
@@ -96,22 +94,19 @@ class IpController extends AdminController
      */
     public function alive(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'userid' => '用户ID',
-            'user_name' => '用户名',
-            'nodeid' => '节点ID',
-            'node_name' => '节点名',
-            'ip' => 'IP',
-            'location' => '归属地',
-            'datetime' => '时间',
-            'is_node' => '是否为中转连接',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'alive/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'userid' => '用户ID',
+                    'user_name' => '用户名',
+                    'nodeid' => '节点ID',
+                    'node_name' => '节点名',
+                    'ip' => 'IP',
+                    'location' => '归属地',
+                    'datetime' => '时间',
+                    'is_node' => '是否为中转连接',
+                ], 'alive/ajax'))
                 ->display('admin/ip/alive.tpl')
         );
     }
@@ -121,7 +116,7 @@ class IpController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_alive(Request $request, Response $response, array $args)
+    public function ajaxAlive(Request $request, Response $response, array $args)
     {
         $query = Ip::getTableDataFromAdmin(
             $request,
@@ -149,13 +144,13 @@ class IpController extends AdminController
             $tempdata = [];
             $tempdata['id'] = $value->id;
             $tempdata['userid'] = $value->userid;
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['nodeid'] = $value->nodeid;
-            $tempdata['node_name'] = $value->node_name();
+            $tempdata['node_name'] = $value->nodeName();
             $tempdata['ip'] = Tools::getRealIp($value->ip);
             $tempdata['location'] = $value->location($QQWry);
             $tempdata['datetime'] = $value->datetime();
-            $tempdata['is_node'] = $value->is_node();
+            $tempdata['is_node'] = $value->isNode();
 
             $data[] = $tempdata;
         }
@@ -175,18 +170,15 @@ class IpController extends AdminController
      */
     public function block(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'node_name' => '节点名称',
-            'ip' => 'IP',
-            'location' => '归属地',
-            'datetime' => '时间',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'block/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'node_name' => '节点名称',
+                    'ip' => 'IP',
+                    'location' => '归属地',
+                    'datetime' => '时间',
+                ], 'block/ajax'))
                 ->display('admin/ip/block.tpl')
         );
     }
@@ -196,7 +188,7 @@ class IpController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_block(Request $request, Response $response, array $args)
+    public function ajaxBlock(Request $request, Response $response, array $args)
     {
         $query = BlockIp::getTableDataFromAdmin(
             $request,
@@ -241,7 +233,7 @@ class IpController extends AdminController
     public function doUnblock(Request $request, Response $response, array $args)
     {
         $ip = trim($request->getParam('ip'));
-        $BIP = BlockIp::where('ip', $ip)->delete();
+        BlockIp::where('ip', $ip)->delete();
         $UIP = new UnblockIp();
         $UIP->userid = $this->user->id;
         $UIP->ip = $ip;
@@ -261,19 +253,16 @@ class IpController extends AdminController
      */
     public function unblock(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'userid' => '用户ID',
-            'user_name' => '用户名',
-            'ip' => 'IP',
-            'location' => '归属地',
-            'datetime' => '时间',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'unblock/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'userid' => '用户ID',
+                    'user_name' => '用户名',
+                    'ip' => 'IP',
+                    'location' => '归属地',
+                    'datetime' => '时间',
+                ], 'unblock/ajax'))
                 ->display('admin/ip/unblock.tpl')
         );
     }
@@ -283,7 +272,7 @@ class IpController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_unblock(Request $request, Response $response, array $args)
+    public function ajaxUnblock(Request $request, Response $response, array $args)
     {
         $query = UnblockIp::getTableDataFromAdmin(
             $request,
@@ -305,7 +294,7 @@ class IpController extends AdminController
             $tempdata = [];
             $tempdata['id'] = $value->id;
             $tempdata['userid'] = $value->userid;
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['ip'] = $value->ip;
             $tempdata['location'] = $value->location($QQWry);
             $tempdata['datetime'] = $value->datetime();

+ 15 - 11
src/Controllers/Admin/NodeController.php

@@ -7,12 +7,15 @@ namespace App\Controllers\Admin;
 use App\Controllers\AdminController;
 use App\Models\Node;
 use App\Services\Config;
+use App\Utils\CloudflareDriver;
+use App\Utils\Telegram;
+use App\Utils\Tools;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use Tools;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class NodeController extends AdminController
+final class NodeController extends AdminController
 {
     /**
      * 后台节点页面
@@ -21,6 +24,7 @@ class NodeController extends AdminController
      */
     public function index(Request $request, Response $response, array $args): ResponseInterface
     {
+        $table_config = [];
         $table_config['total_column'] = [
             'op' => '操作',
             'id' => 'ID',
@@ -94,7 +98,7 @@ class NodeController extends AdminController
         $success = true;
         $server_list = explode(';', $node->server);
 
-        if (Tools::is_ip($req_node_ip)) {
+        if (Tools::isIp($req_node_ip)) {
             $success = $node->changeNodeIp($req_node_ip);
         } else {
             $success = $node->changeNodeIp($server_list[0]);
@@ -120,7 +124,7 @@ class NodeController extends AdminController
 
         if (Config::getconfig('Telegram.bool.AddNode')) {
             try {
-                Telegram::Send(
+                Telegram::send(
                     str_replace(
                         '%node_name%',
                         $request->getParam('name'),
@@ -189,7 +193,7 @@ class NodeController extends AdminController
         $success = true;
         $server_list = explode(';', $node->server);
 
-        if (Tools::is_ip($req_node_ip)) {
+        if (Tools::isIp($req_node_ip)) {
             $success = $node->changeNodeIp($req_node_ip);
         } else {
             $success = $node->changeNodeIp($server_list[0]);
@@ -211,7 +215,7 @@ class NodeController extends AdminController
 
         if (Config::getconfig('Telegram.bool.UpdateNode')) {
             try {
-                Telegram::Send(
+                Telegram::send(
                     str_replace(
                         '%node_name%',
                         $request->getParam('name'),
@@ -251,7 +255,7 @@ class NodeController extends AdminController
 
         if (Config::getconfig('Telegram.bool.DeleteNode')) {
             try {
-                Telegram::Send(
+                Telegram::send(
                     str_replace(
                         '%node_name%',
                         $request->getParam('name'),
@@ -302,7 +306,7 @@ class NodeController extends AdminController
             $tempdata['type'] = $value->type();
             $tempdata['sort'] = $value->sort();
             $tempdata['server'] = $value->server;
-            $tempdata['outaddress'] = $value->get_out_address();
+            $tempdata['outaddress'] = $value->getOutAddress();
             $tempdata['node_ip'] = $value->node_ip;
             $tempdata['info'] = $value->info;
             $tempdata['status'] = $value->status;
@@ -313,8 +317,8 @@ class NodeController extends AdminController
             $tempdata['node_bandwidth'] = Tools::flowToGB($value->node_bandwidth);
             $tempdata['node_bandwidth_limit'] = Tools::flowToGB($value->node_bandwidth_limit);
             $tempdata['bandwidthlimit_resetday'] = $value->bandwidthlimit_resetday;
-            $tempdata['node_heartbeat'] = $value->node_heartbeat();
-            $tempdata['mu_only'] = $value->mu_only();
+            $tempdata['node_heartbeat'] = $value->nodeHeartbeat();
+            $tempdata['mu_only'] = $value->muOnly();
 
             $data[] = $tempdata;
         }

+ 6 - 7
src/Controllers/Admin/SettingController.php

@@ -6,7 +6,7 @@ namespace App\Controllers\Admin;
 
 use App\Controllers\AdminController;
 
-class SettingController extends AdminController
+final class SettingController extends AdminController
 {
     public function index($request, $response, $args)
     {
@@ -25,8 +25,8 @@ class SettingController extends AdminController
             $this->view()
                 //->registerClass('Setting', Setting::class)
                 ->assign('settings', $config)
-                ->assign('payment_gateways', self::return_gateways_list())
-                ->assign('active_payment_gateway', self::return_active_gateways())
+                ->assign('payment_gateways', self::returnGatewaysList())
+                ->assign('active_payment_gateway', self::returnActiveGateways())
                 ->display('admin/setting.tpl')
         );
     }
@@ -163,7 +163,7 @@ class SettingController extends AdminController
         ]);
     }
 
-    public function return_gateways_list()
+    public function returnGatewaysList()
     {
         return [
             // 网关名 网关代号
@@ -177,7 +177,7 @@ class SettingController extends AdminController
         ];
     }
 
-    public function return_active_gateways()
+    public function returnActiveGateways()
     {
         $payment_gateways = Setting::where('item', '=', 'payment_gateway')->first();
         return json_decode($payment_gateways->value);
@@ -186,8 +186,7 @@ class SettingController extends AdminController
     public function payment($request, $response, $args)
     {
         $gateway_in_use = [];
-        $payment_gateways = self::return_gateways_list();
-        foreach ($payment_gateways as $key => $value) {
+        foreach (array_values(self::returnGatewaysList()) as $value) {
             $payment_switch = $request->getParam("${value}");
             if ($payment_switch === '1') {
                 array_push($gateway_in_use, $value);

+ 34 - 43
src/Controllers/Admin/ShopController.php

@@ -5,10 +5,13 @@ declare(strict_types=1);
 namespace App\Controllers\Admin;
 
 use App\Controllers\AdminController;
-use Request;
-use Shop;
+use App\Models\Bought;
+use App\Models\Shop;
+use App\Utils\ResponseHelper;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class ShopController extends AdminController
+final class ShopController extends AdminController
 {
     /**
      * 后台商品页面
@@ -17,25 +20,19 @@ class ShopController extends AdminController
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'op' => '操作',
-            'id' => 'ID',
-            'name' => '商品名称',
-            'price' => '价格',
-            'content' => '商品内容',
-            'auto_renew' => '自动续费',
-            'auto_reset_bandwidth' => '续费时是否重置流量',
-            'status' => '状态',
-            'period_sales' => '周期销量',
-        ];
-        $table_config['default_show_column'] = [];
-        foreach ($table_config['total_column'] as $column => $value) {
-            $table_config['default_show_column'][] = $column;
-        }
-        $table_config['ajax_url'] = 'shop/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'op' => '操作',
+                    'id' => 'ID',
+                    'name' => '商品名称',
+                    'price' => '价格',
+                    'content' => '商品内容',
+                    'auto_renew' => '自动续费',
+                    'auto_reset_bandwidth' => '续费时是否重置流量',
+                    'status' => '状态',
+                    'period_sales' => '周期销量',
+                ], 'shop/ajax'))
                 ->display('admin/shop/index.tpl')
         );
     }
@@ -242,25 +239,19 @@ class ShopController extends AdminController
      */
     public function bought(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'op' => '操作',
-            'id' => 'ID',
-            'datetime' => '购买日期',
-            'content' => '内容',
-            'price' => '价格',
-            'userid' => '用户ID',
-            'user_name' => '用户名',
-            'renew' => '自动续费时间',
-            'auto_reset_bandwidth' => '续费时是否重置流量',
-        ];
-        $table_config['default_show_column'] = [];
-        foreach ($table_config['total_column'] as $column => $value) {
-            $table_config['default_show_column'][] = $column;
-        }
-        $table_config['ajax_url'] = 'bought/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'op' => '操作',
+                    'id' => 'ID',
+                    'datetime' => '购买日期',
+                    'content' => '内容',
+                    'price' => '价格',
+                    'userid' => '用户ID',
+                    'user_name' => '用户名',
+                    'renew' => '自动续费时间',
+                    'auto_reset_bandwidth' => '续费时是否重置流量',
+                ], 'bought/ajax'))
                 ->display('admin/shop/bought.tpl')
         );
     }
@@ -292,7 +283,7 @@ class ShopController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_shop(Request $request, Response $response, array $args)
+    public function ajaxShop(Request $request, Response $response, array $args)
     {
         $query = Shop::getTableDataFromAdmin(
             $request,
@@ -313,8 +304,8 @@ class ShopController extends AdminController
             $tempdata['name'] = $value->name;
             $tempdata['price'] = $value->price;
             $tempdata['content'] = $value->content();
-            $tempdata['auto_renew'] = $value->auto_renew();
-            $tempdata['auto_reset_bandwidth'] = $value->auto_reset_bandwidth();
+            $tempdata['auto_renew'] = $value->autoRenew();
+            $tempdata['auto_reset_bandwidth'] = $value->autoResetBandwidthString();
             $tempdata['status'] = $value->status();
             $tempdata['period_sales'] = $value->getSales();
 
@@ -334,7 +325,7 @@ class ShopController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_bought(Request $request, Response $response, array $args)
+    public function ajaxBought(Request $request, Response $response, array $args)
     {
         $query = Bought::getTableDataFromAdmin(
             $request,
@@ -362,9 +353,9 @@ class ShopController extends AdminController
             $tempdata['content'] = $value->content();
             $tempdata['price'] = $value->price;
             $tempdata['userid'] = $value->userid;
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['renew'] = $value->renew();
-            $tempdata['auto_reset_bandwidth'] = $value->auto_reset_bandwidth();
+            $tempdata['auto_reset_bandwidth'] = $value->autoResetBandwidthString();
 
             $data[] = $tempdata;
         }

+ 4 - 3
src/Controllers/Admin/SubscribeLogController.php

@@ -11,7 +11,7 @@ use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Request;
 use Slim\Http\Response;
 
-class SubscribeLogController extends AdminController
+final class SubscribeLogController extends AdminController
 {
     /**
      * 后台订阅记录页面
@@ -20,6 +20,7 @@ class SubscribeLogController extends AdminController
      */
     public function index(Request $request, Response $response, array $args): ResponseInterface
     {
+        $table_config = [];
         $table_config['total_column'] = [
             'id' => 'ID',
             'user_name' => '用户名',
@@ -45,7 +46,7 @@ class SubscribeLogController extends AdminController
      *
      * @param array     $args
      */
-    public function ajax_subscribe_log(Request $request, Response $response, array $args): ResponseInterface
+    public function ajaxSubscribeLog(Request $request, Response $response, array $args): ResponseInterface
     {
         $query = UserSubscribeLog::getTableDataFromAdmin(
             $request,
@@ -62,7 +63,7 @@ class SubscribeLogController extends AdminController
             /** @var UserSubscribeLog $value */
 
             if ($value->user() === null) {
-                UserSubscribeLog::user_is_null($value);
+                UserSubscribeLog::userIsNull($value);
                 continue;
             }
             $tempdata = [];

+ 18 - 22
src/Controllers/Admin/TicketController.php

@@ -5,12 +5,15 @@ declare(strict_types=1);
 namespace App\Controllers\Admin;
 
 use App\Controllers\AdminController;
+use App\Models\Ticket;
+use App\Models\User;
+use App\Utils\ResponseHelper;
 use App\Utils\Tools;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 use voku\helper\AntiXSS;
 
-class TicketController extends AdminController
+final class TicketController extends AdminController
 {
     /**
      * 后台工单页面
@@ -19,23 +22,17 @@ class TicketController extends AdminController
      */
     public function index(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'op' => '操作',
-            'id' => 'ID',
-            'datetime' => '时间',
-            'title' => '标题',
-            'userid' => '用户ID',
-            'user_name' => '用户名',
-            'status' => '状态',
-        ];
-        $table_config['default_show_column'] = [
-            'op', 'id',
-            'datetime', 'title', 'userid', 'user_name', 'status',
-        ];
-        $table_config['ajax_url'] = 'ticket/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'op' => '操作',
+                    'id' => 'ID',
+                    'datetime' => '时间',
+                    'title' => '标题',
+                    'userid' => '用户ID',
+                    'user_name' => '用户名',
+                    'status' => '状态',
+                ], 'ticket/ajax'))
                 ->display('admin/ticket/index.tpl')
         );
     }
@@ -49,7 +46,6 @@ class TicketController extends AdminController
     {
         $title = $request->getParam('title');
         $content = $request->getParam('content');
-        $markdown = $request->getParam('markdown');
         $userid = $request->getParam('userid');
         if ($title === '' || $content === '') {
             return $response->withJson([
@@ -156,7 +152,7 @@ class TicketController extends AdminController
         $ticketset = Ticket::where('id', $id)->orWhere('rootid', '=', $id)->orderBy('datetime', 'desc')->paginate(5, ['*'], 'page', $pageNum);
         $ticketset->setPath('/admin/ticket/' . $id . '/view');
 
-        $render = Tools::paginate_render($ticketset);
+        $render = Tools::paginateRender($ticketset);
         return $response->write(
             $this->view()
                 ->assign('ticketset', $ticketset)
@@ -193,7 +189,7 @@ class TicketController extends AdminController
             /** @var Ticket $value */
 
             if ($value->user() === null) {
-                Ticket::user_is_null($value);
+                Ticket::userIsNull($value);
                 continue;
             }
             $tempdata = [];
@@ -202,7 +198,7 @@ class TicketController extends AdminController
             $tempdata['datetime'] = $value->datetime();
             $tempdata['title'] = $value->title;
             $tempdata['userid'] = $value->userid;
-            $tempdata['user_name'] = $value->user_name();
+            $tempdata['user_name'] = $value->userName();
             $tempdata['status'] = $value->status();
 
             $data[] = $tempdata;

+ 64 - 59
src/Controllers/Admin/UserController.php

@@ -5,20 +5,30 @@ declare(strict_types=1);
 namespace App\Controllers\Admin;
 
 use App\Controllers\AdminController;
-use Auth;
+use App\Models\Bought;
+use App\Models\DetectBanLog;
+use App\Models\Setting;
+use App\Models\Shop;
+use App\Models\User;
+use App\Services\Auth;
+use App\Services\Mail;
+use App\Utils\Cookie;
+use App\Utils\GA;
+use App\Utils\Hash;
+use App\Utils\Tools;
 use Exception;
-use GA;
 use Ramsey\Uuid\Uuid;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class UserController extends AdminController
+final class UserController extends AdminController
 {
     /**
      * @param array     $args
      */
     public function index(Request $request, Response $response, array $args)
     {
+        $table_config = [];
         $table_config['total_column'] = [
             'op' => '操作',
             'querys' => '查询',
@@ -135,6 +145,7 @@ class UserController extends AdminController
         $user->ga_token = $secret;
         $user->ga_enable = 0;
         if ($user->save()) {
+            $res = [];
             $res['ret'] = 1;
             $res['msg'] = '新用户注册成功 用户名: ' . $email . ' 随机初始密码: ' . $pass;
             $res['email_error'] = 'success';
@@ -194,22 +205,15 @@ class UserController extends AdminController
         $id = $args['id'];
         $user = User::find($id);
 
-        $email1 = $user->email;
-
         $user->email = $request->getParam('email');
 
-        $email2 = $request->getParam('email');
-
-        $passwd = $request->getParam('passwd');
-
         if ($request->getParam('pass') !== '') {
             $user->pass = Hash::passwordHash($request->getParam('pass'));
-            $user->clean_link();
+            $user->cleanLink();
         }
 
         $user->auto_reset_day = $request->getParam('auto_reset_day');
         $user->auto_reset_bandwidth = $request->getParam('auto_reset_bandwidth');
-        $origin_port = $user->port;
         $user->port = $request->getParam('port');
 
         $user->addMoneyLog($request->getParam('money') - $user->money);
@@ -276,7 +280,7 @@ class UserController extends AdminController
     public function delete(Request $request, Response $response, array $args)
     {
         $user = User::find((int) $request->getParam('id'));
-        if (! $user->kill_user()) {
+        if (! $user->killUser()) {
             return $response->withJson([
                 'ret' => 0,
                 'msg' => '删除失败',
@@ -347,52 +351,53 @@ class UserController extends AdminController
         );
 
         $data = [];
+        /** @var User $value */
         foreach ($query['datas'] as $value) {
-            /** @var User $value */
-
-            $tempdata['op'] = '' .
-                '<a class="btn btn-brand" href="/admin/user/' . $value->id . '/edit">编辑</a>' .
-                '<a class="btn btn-brand-accent" id="delete" href="javascript:void(0);" onClick="delete_modal_show(\'' . $value->id . '\')">删除</a>' .
-                '<a class="btn btn-brand" id="changetouser" href="javascript:void(0);" onClick="changetouser_modal_show(\'' . $value->id . '\')">切换为该用户</a>';
-
-            $tempdata['querys'] = '' .
-                '<a class="btn btn-brand" href="/admin/user/' . $value->id . '/bought">套餐</a>' .
-                '<a class="btn btn-brand" href="/admin/user/' . $value->id . '/code">充值</a>' .
-                '<a class="btn btn-brand" href="/admin/user/' . $value->id . '/sublog">订阅</a>' .
-                '<a class="btn btn-brand" href="/admin/user/' . $value->id . '/detect">审计</a>' .
-                '<a class="btn btn-brand" href="/admin/user/' . $value->id . '/login">登录</a>';
-
-            $tempdata['id'] = $value->id;
-            $tempdata['user_name'] = $value->user_name;
-            $tempdata['remark'] = $value->remark;
-            $tempdata['email'] = $value->email;
-            $tempdata['money'] = $value->money;
-            $tempdata['im_type'] = $value->im_type();
-            $tempdata['im_value'] = $value->im_value();
-            $tempdata['node_group'] = $value->node_group;
-            $tempdata['expire_in'] = $value->expire_in;
-            $tempdata['class'] = $value->class;
-            $tempdata['class_expire'] = $value->class_expire;
-            $tempdata['passwd'] = $value->passwd;
-            $tempdata['port'] = $value->port;
-            $tempdata['method'] = $value->method;
-            $tempdata['protocol'] = $value->protocol;
-            $tempdata['obfs'] = $value->obfs;
-            $tempdata['obfs_param'] = $value->obfs_param;
-            $tempdata['online_ip_count'] = $value->online_ip_count();
-            $tempdata['last_ss_time'] = $value->lastSsTime();
-            $tempdata['used_traffic'] = Tools::flowToGB($value->u + $value->d);
-            $tempdata['enable_traffic'] = Tools::flowToGB($value->transfer_enable);
-            $tempdata['last_checkin_time'] = $value->lastCheckInTime();
-            $tempdata['today_traffic'] = $value->TodayusedTraffic();
-            $tempdata['enable'] = $value->enable === 1 ? '可用' : '禁用';
-            $tempdata['reg_date'] = $value->reg_date;
-            $tempdata['reg_ip'] = $value->reg_ip;
-            $tempdata['auto_reset_day'] = $value->auto_reset_day;
-            $tempdata['auto_reset_bandwidth'] = $value->auto_reset_bandwidth;
-            $tempdata['ref_by'] = $value->ref_by;
-            $tempdata['ref_by_user_name'] = $value->ref_by_user_name();
-            $tempdata['top_up'] = $value->get_top_up();
+            $tempdata = [
+                'op' => <<<EOF
+                    <a class="btn btn-brand" href="/admin/user/{$value->id}/edit">编辑</a>
+                    <a class="btn btn-brand-accent" id="delete" href="javascript:void(0);" onClick="delete_modal_show('{$value->id}')">删除</a>
+                    <a class="btn btn-brand" id="changetouser" href="javascript:void(0);" onClick="changetouser_modal_show('{$value->id}')">切换为该用户</a>
+                EOF,
+                'querys' => <<<EOF
+                    <a class="btn btn-brand" href="/admin/user/{$value->id}/bought">套餐</a>
+                    <a class="btn btn-brand" href="/admin/user/{$value->id}/code">充值</a>
+                    <a class="btn btn-brand" href="/admin/user/{$value->id}/sublog">订阅</a>
+                    <a class="btn btn-brand" href="/admin/user/{$value->id}/detect">审计</a>
+                    <a class="btn btn-brand" href="/admin/user/{$value->id}/login">登录</a>
+                EOF,
+                'id' => $value->id,
+                'user_name' => $value->user_name,
+                'remark' => $value->remark,
+                'email' => $value->email,
+                'money' => $value->money,
+                'im_type' => $value->imType(),
+                'im_value' => $value->imValue(),
+                'node_group' => $value->node_group,
+                'expire_in' => $value->expire_in,
+                'class' => $value->class,
+                'class_expire' => $value->class_expire,
+                'passwd' => $value->passwd,
+                'port' => $value->port,
+                'method' => $value->method,
+                'protocol' => $value->protocol,
+                'obfs' => $value->obfs,
+                'obfs_param' => $value->obfs_param,
+                'online_ip_count' => $value->onlineIpCount(),
+                'last_ss_time' => $value->lastSsTime(),
+                'used_traffic' => Tools::flowToGB($value->u + $value->d),
+                'enable_traffic' => Tools::flowToGB($value->transfer_enable),
+                'last_checkin_time' => $value->lastCheckInTime(),
+                'today_traffic' => $value->todayUsedTraffic(),
+                'enable' => $value->enable === 1 ? '可用' : '禁用',
+                'reg_date' => $value->reg_date,
+                'reg_ip' => $value->reg_ip,
+                'auto_reset_day' => $value->auto_reset_day,
+                'auto_reset_bandwidth' => $value->auto_reset_bandwidth,
+                'ref_by' => $value->ref_by,
+                'ref_by_user_name' => $value->refByUserName(),
+                'top_up' => $value->getTopUp(),
+            ];
 
             $data[] = $tempdata;
         }

+ 14 - 10
src/Controllers/Admin/UserLog/BoughtLogController.php

@@ -5,11 +5,14 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\UserLog;
 
 use App\Controllers\AdminController;
+use App\Models\Bought;
+use App\Models\Shop;
+use App\Models\User;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class BoughtLogController extends AdminController
+final class BoughtLogController extends AdminController
 {
     /**
      * @param array     $args
@@ -18,6 +21,7 @@ class BoughtLogController extends AdminController
     {
         $id = $args['id'];
         $user = User::find($id);
+        $table_config = [];
         $table_config['total_column'] = [
             'op' => '操作',
             'id' => 'ID',
@@ -45,7 +49,7 @@ class BoughtLogController extends AdminController
     /**
      * @param array     $args
      */
-    public function bought_ajax(Request $request, Response $response, array $args): ResponseInterface
+    public function boughtAjax(Request $request, Response $response, array $args): ResponseInterface
     {
         $user = User::find($args['id']);
         $query = Bought::getTableDataFromAdmin(
@@ -68,7 +72,7 @@ class BoughtLogController extends AdminController
             /** @var Bought $value */
 
             if ($value->shop() === null) {
-                Bought::shop_is_null($value);
+                Bought::shopIsNull($value);
                 continue;
             }
             $tempdata = [];
@@ -78,13 +82,13 @@ class BoughtLogController extends AdminController
             $tempdata['content'] = $value->content();
             $tempdata['renew'] = $value->renew();
             $tempdata['datetime'] = $value->datetime();
-            if ($value->shop()->use_loop()) {
+            if ($value->shop()->useLoop()) {
                 $tempdata['valid'] = ($value->valid() ? '有效' : '已过期');
             } else {
                 $tempdata['valid'] = '-';
             }
-            $tempdata['reset_time'] = $value->reset_time();
-            $tempdata['exp_time'] = $value->exp_time();
+            $tempdata['reset_time'] = $value->resetTime();
+            $tempdata['exp_time'] = $value->expTime();
 
             $data[] = $tempdata;
         }
@@ -100,7 +104,7 @@ class BoughtLogController extends AdminController
     /**
      * @param array     $args
      */
-    public function bought_delete(Request $request, Response $response, array $args): ResponseInterface
+    public function boughtDelete(Request $request, Response $response, array $args): ResponseInterface
     {
         $id = $request->getParam('id');
         $Bought = Bought::find($id);
@@ -119,7 +123,7 @@ class BoughtLogController extends AdminController
     /**
      * @param array     $args
      */
-    public function bought_add(Request $request, Response $response, array $args): ResponseInterface
+    public function boughtAdd(Request $request, Response $response, array $args): ResponseInterface
     {
         $id = $args['id'];
         $user = User::find($id);

+ 13 - 13
src/Controllers/Admin/UserLog/CodeLogController.php

@@ -5,11 +5,14 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\UserLog;
 
 use App\Controllers\AdminController;
-use Code;
+use App\Models\Code;
+use App\Models\User;
+use App\Utils\ResponseHelper;
 use Psr\Http\Message\ResponseInterface;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class CodeLogController extends AdminController
+final class CodeLogController extends AdminController
 {
     /**
      * @param array     $args
@@ -18,18 +21,15 @@ class CodeLogController extends AdminController
     {
         $id = $args['id'];
         $user = User::find($id);
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'code' => '内容',
-            'type' => '类型',
-            'number' => '操作',
-            'usedatetime' => '时间',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'code/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'code' => '内容',
+                    'type' => '类型',
+                    'number' => '操作',
+                    'usedatetime' => '时间',
+                ], 'code/ajax'))
                 ->assign('user', $user)
                 ->display('admin/user/code.tpl')
         );

+ 24 - 24
src/Controllers/Admin/UserLog/DetectLogController.php

@@ -5,11 +5,14 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\UserLog;
 
 use App\Controllers\AdminController;
+use App\Models\DetectLog;
+use App\Models\User;
+use App\Utils\ResponseHelper;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class DetectLogController extends AdminController
+final class DetectLogController extends AdminController
 {
     /**
      * @param array     $args
@@ -18,23 +21,20 @@ class DetectLogController extends AdminController
     {
         $id = $args['id'];
         $user = User::find($id);
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'node_id' => '节点ID',
-            'node_name' => '节点名',
-            'list_id' => '规则ID',
-            'rule_name' => '规则名',
-            'rule_text' => '规则描述',
-            'rule_regex' => '规则正则表达式',
-            'rule_type' => '规则类型',
-            'datetime' => '时间',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'detect/ajax';
 
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'node_id' => '节点ID',
+                    'node_name' => '节点名',
+                    'list_id' => '规则ID',
+                    'rule_name' => '规则名',
+                    'rule_text' => '规则描述',
+                    'rule_regex' => '规则正则表达式',
+                    'rule_type' => '规则类型',
+                    'datetime' => '时间',
+                ], 'detect/ajax'))
                 ->assign('user', $user)
                 ->display('admin/user/detect.tpl')
         );
@@ -66,22 +66,22 @@ class DetectLogController extends AdminController
             /** @var DetectLog $value */
 
             if ($value->rule() === null) {
-                DetectLog::rule_is_null($value);
+                DetectLog::ruleIsNull($value);
                 continue;
             }
             if ($value->node() === null) {
-                DetectLog::node_is_null($value);
+                DetectLog::nodeIsNull($value);
                 continue;
             }
             $tempdata = [];
             $tempdata['id'] = $value->id;
             $tempdata['node_id'] = $value->node_id;
-            $tempdata['node_name'] = $value->node_name();
+            $tempdata['node_name'] = $value->nodeName();
             $tempdata['list_id'] = $value->list_id;
-            $tempdata['rule_name'] = $value->rule_name();
-            $tempdata['rule_text'] = $value->rule_text();
-            $tempdata['rule_regex'] = $value->rule_regex();
-            $tempdata['rule_type'] = $value->rule_type();
+            $tempdata['rule_name'] = $value->ruleName();
+            $tempdata['rule_text'] = $value->ruleText();
+            $tempdata['rule_regex'] = $value->ruleRegex();
+            $tempdata['rule_type'] = $value->ruleType();
             $tempdata['datetime'] = $value->datetime();
 
             $data[] = $tempdata;

+ 13 - 14
src/Controllers/Admin/UserLog/LoginLogController.php

@@ -5,12 +5,15 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\UserLog;
 
 use App\Controllers\AdminController;
+use App\Models\LoginIp;
+use App\Models\User;
 use App\Utils\QQWry;
+use App\Utils\ResponseHelper;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class LoginLogController extends AdminController
+final class LoginLogController extends AdminController
 {
     /**
      * @param array     $args
@@ -19,19 +22,15 @@ class LoginLogController extends AdminController
     {
         $id = $args['id'];
         $user = User::find($id);
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'ip' => 'IP',
-            'location' => '归属地',
-            'datetime' => '时间',
-            'type' => '类型',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'login/ajax';
-
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'ip' => 'IP',
+                    'location' => '归属地',
+                    'datetime' => '时间',
+                    'type' => '类型',
+                ], 'login/ajax'))
                 ->assign('user', $user)
                 ->display('admin/user/login.tpl')
         );

+ 14 - 14
src/Controllers/Admin/UserLog/SubLogController.php

@@ -5,12 +5,15 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\UserLog;
 
 use App\Controllers\AdminController;
+use App\Models\User;
+use App\Models\UserSubscribeLog;
 use App\Utils\QQWry;
+use App\Utils\ResponseHelper;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class SubLogController extends AdminController
+final class SubLogController extends AdminController
 {
     /**
      * @param array     $args
@@ -19,20 +22,17 @@ class SubLogController extends AdminController
     {
         $id = $args['id'];
         $user = User::find($id);
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'subscribe_type' => '类型',
-            'request_ip' => 'IP',
-            'location' => '归属地',
-            'request_time' => '时间',
-            'request_user_agent' => 'User-Agent',
-        ];
-        $table_config['default_show_column'] = array_keys($table_config['total_column']);
-        $table_config['ajax_url'] = 'sublog/ajax';
 
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'subscribe_type' => '类型',
+                    'request_ip' => 'IP',
+                    'location' => '归属地',
+                    'request_time' => '时间',
+                    'request_user_agent' => 'User-Agent',
+                ], 'sublog/ajax'))
                 ->assign('user', $user)
                 ->display('admin/user/sublog.tpl')
         );

+ 30 - 38
src/Controllers/AdminController.php

@@ -4,15 +4,19 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
+use App\Models\Coupon;
+use App\Models\User;
+use App\Utils\DatatablesHelper;
+use App\Utils\ResponseHelper;
+use App\Utils\Tools;
 use Ozdemir\Datatables\Datatables;
-use Request;
-use Tools;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-/**
+/*
  *  Admin Controller
  */
-class AdminController extends UserController
+final class AdminController extends UserController
 {
     /**
      * 后台首页
@@ -48,24 +52,18 @@ class AdminController extends UserController
      */
     public function invite(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'total' => '原始金额',
-            'event_user_id' => '发起用户ID',
-            'event_user_name' => '发起用户名',
-            'ref_user_id' => '获利用户ID',
-            'ref_user_name' => '获利用户名',
-            'ref_get' => '获利金额',
-            'datetime' => '时间',
-        ];
-        $table_config['default_show_column'] = [];
-        foreach ($table_config['total_column'] as $column => $value) {
-            $table_config['default_show_column'][] = $column;
-        }
-        $table_config['ajax_url'] = 'payback/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'total' => '原始金额',
+                    'event_user_id' => '发起用户ID',
+                    'event_user_name' => '发起用户名',
+                    'ref_user_id' => '获利用户ID',
+                    'ref_user_name' => '获利用户名',
+                    'ref_get' => '获利金额',
+                    'datetime' => '时间',
+                ], 'payback/ajax'))
                 ->display('admin/invite.tpl')
         );
     }
@@ -75,7 +73,7 @@ class AdminController extends UserController
      *
      * @param array     $args
      */
-    public function ajax_payback(Request $request, Response $response, array $args)
+    public function ajaxPayback(Request $request, Response $response, array $args)
     {
         $datatables = new Datatables(new DatatablesHelper());
         $datatables->query('Select payback.id,payback.total,payback.userid as event_user_id,event_user.user_name as event_user_name,payback.ref_by as ref_user_id,ref_user.user_name as ref_user_name,payback.ref_get,payback.datetime from payback,user as event_user,user as ref_user where event_user.id = payback.userid and ref_user.id = payback.ref_by');
@@ -165,22 +163,16 @@ class AdminController extends UserController
      */
     public function coupon(Request $request, Response $response, array $args)
     {
-        $table_config['total_column'] = [
-            'id' => 'ID',
-            'code' => '优惠码',
-            'expire' => '过期时间',
-            'shop' => '限定商品ID',
-            'credit' => '额度',
-            'onetime' => '次数',
-        ];
-        $table_config['default_show_column'] = [];
-        foreach ($table_config['total_column'] as $column => $value) {
-            $table_config['default_show_column'][] = $column;
-        }
-        $table_config['ajax_url'] = 'coupon/ajax';
         return $response->write(
             $this->view()
-                ->assign('table_config', $table_config)
+                ->assign('table_config', ResponseHelper::buildTableConfig([
+                    'id' => 'ID',
+                    'code' => '优惠码',
+                    'expire' => '过期时间',
+                    'shop' => '限定商品ID',
+                    'credit' => '额度',
+                    'onetime' => '次数',
+                ], 'coupon/ajax'))
                 ->display('admin/coupon.tpl')
         );
     }
@@ -190,7 +182,7 @@ class AdminController extends UserController
      *
      * @param array     $args
      */
-    public function ajax_coupon(Request $request, Response $response, array $args)
+    public function ajaxCoupon(Request $request, Response $response, array $args)
     {
         $datatables = new Datatables(new DatatablesHelper());
         $datatables->query('Select id,code,expire,shop,credit,onetime from coupon');
@@ -211,7 +203,7 @@ class AdminController extends UserController
     {
         $generate_type = (int) $request->getParam('generate_type');
         $final_code = $request->getParam('prefix');
-        if (empty($final_code) && in_array($generate_type, [1, 3])) {
+        if ($final_code && in_array($generate_type, [1, 3])) {
             return $response->withJson([
                 'ret' => 0,
                 'msg' => '优惠码不能为空',

+ 56 - 116
src/Controllers/AuthController.php

@@ -4,18 +4,29 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
-use Auth;
+use App\Models\EmailVerify;
+use App\Models\InviteCode;
+use App\Models\Setting;
+use App\Models\User;
+use App\Services\Auth;
+use App\Services\Captcha;
+use App\Services\Mail;
+use App\Utils\Check;
+use App\Utils\GA;
+use App\Utils\Hash;
+use App\Utils\ResponseHelper;
+use App\Utils\TelegramSessionManager;
+use App\Utils\Tools;
 use Exception;
-use GA;
 use Ramsey\Uuid\Uuid;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 use voku\helper\AntiXSS;
 
 /**
  *  AuthController
  */
-class AuthController extends BaseController
+final class AuthController extends BaseController
 {
     /**
      * @param array     $args
@@ -25,7 +36,7 @@ class AuthController extends BaseController
         $captcha = Captcha::generate();
 
         if ($_ENV['enable_telegram_login'] === true) {
-            $login_text = TelegramSessionManager::add_login_session();
+            $login_text = TelegramSessionManager::addLoginSession();
             $login = explode('|', $login_text);
             $login_token = $login[0];
             $login_number = $login[1];
@@ -130,17 +141,14 @@ class AuthController extends BaseController
     /**
      * @param array     $args
      */
-    public function qrcode_loginHandle(Request $request, Response $response, array $args)
+    public function qrcodeLoginHandle(Request $request, Response $response, array $args)
     {
         $token = $request->getParam('token');
         $number = $request->getParam('number');
 
-        $ret = TelegramSessionManager::step2_verify_login_session($token, $number);
+        $ret = TelegramSessionManager::step2VerifyLoginSession($token, $number);
         if ($ret === 0) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '此令牌无法被使用。',
-            ]);
+            return ResponseHelper::error($response, '此令牌无法被使用。');
         }
 
         $user = User::find($ret);
@@ -148,11 +156,7 @@ class AuthController extends BaseController
         Auth::login($user->id, 3600 * 24);
         // 记录登录成功
         $user->collectLoginIP($_SERVER['REMOTE_ADDR']);
-
-        return $response->withJson([
-            'ret' => 1,
-            'msg' => '登录成功',
-        ]);
+        return ResponseHelper::successfully($response, '登录成功');
     }
 
     /**
@@ -170,7 +174,7 @@ class AuthController extends BaseController
         $captcha = Captcha::generate();
 
         if ($_ENV['enable_telegram_login'] === true) {
-            $login_text = TelegramSessionManager::add_login_session();
+            $login_text = TelegramSessionManager::addLoginSession();
             $login = explode('|', $login_text);
             $login_token = $login[0];
             $login_number = $login[1];
@@ -206,10 +210,7 @@ class AuthController extends BaseController
             $email = trim($request->getParam('email'));
             $email = strtolower($email);
             if ($email === '') {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '未填写邮箱',
-                ]);
+                return ResponseHelper::error($response, '未填写邮箱');
             }
             // check email format
             $check_res = Check::isEmailLegal($email);
@@ -218,24 +219,15 @@ class AuthController extends BaseController
             }
             $user = User::where('email', $email)->first();
             if ($user !== null) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '此邮箱已经注册',
-                ]);
+                return ResponseHelper::error($response, '此邮箱已经注册');
             }
             $ipcount = EmailVerify::where('ip', '=', $_SERVER['REMOTE_ADDR'])->where('expire_in', '>', time())->count();
             if ($ipcount >= Setting::obtain('email_verify_ip_limit')) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '此IP请求次数过多',
-                ]);
+                return ResponseHelper::error($response, '此IP请求次数过多');
             }
             $mailcount = EmailVerify::where('email', '=', $email)->where('expire_in', '>', time())->count();
             if ($mailcount >= 3) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '此邮箱请求次数过多',
-                ]);
+                return ResponseHelper::error($response, '此邮箱请求次数过多');
             }
             $code = Tools::genRandomNum(6);
             $ev = new EmailVerify();
@@ -256,20 +248,11 @@ class AuthController extends BaseController
                     []
                 );
             } catch (Exception $e) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '邮件发送失败,请联系网站管理员。',
-                ]);
+                return ResponseHelper::error($response, '邮件发送失败,请联系网站管理员。');
             }
-            return $response->withJson([
-                'ret' => 1,
-                'msg' => '验证码发送成功,请查收邮件。',
-            ]);
+            return ResponseHelper::successfully($response, '验证码发送成功,请查收邮件。');
         }
-        return $response->withJson([
-            'ret' => 0,
-            'msg' => '',
-        ]);
+        return ResponseHelper::error($response, ' 不允许注册');
     }
 
     /**
@@ -277,39 +260,29 @@ class AuthController extends BaseController
      * @param Response  $response
      * @param array     $args
      */
-    public function register_helper($name, $email, $passwd, $code, $imtype, $imvalue, $telegram_id)
+    public function registerHelper($response, $name, $email, $passwd, $code, $imtype, $imvalue, $telegram_id)
     {
         if (Setting::obtain('reg_mode') === 'close') {
-            $res['ret'] = 0;
-            $res['msg'] = '暂时不对外开放注册';
-            return $res;
+            return ResponseHelper::error($response, '暂时不对外开放注册');
         }
 
         if ($code === '') {
-            $res['ret'] = 0;
-            $res['msg'] = '注册需要填写邀请码';
-            return $res;
+            return ResponseHelper::error($response, '注册需要填写邀请码');
         }
 
         $c = InviteCode::where('code', $code)->first();
         if ($c === null) {
             if (Setting::obtain('reg_mode') === 'invite') {
-                $res['ret'] = 0;
-                $res['msg'] = '这个邀请码不存在';
-                return $res;
+                return ResponseHelper::error($response, '这个邀请码不存在');
             }
         } elseif ($c->user_id !== 0) {
             $gift_user = User::where('id', $c->user_id)->first();
             if ($gift_user === null) {
-                $res['ret'] = 0;
-                $res['msg'] = '邀请码已失效';
-                return $res;
+                return ResponseHelper::error($response, '邀请码已失效');
             }
 
             if ($gift_user->invite_num === 0) {
-                $res['ret'] = 0;
-                $res['msg'] = '邀请码不可用';
-                return $res;
+                return ResponseHelper::error($response, '邀请码不可用');
             }
         }
 
@@ -384,14 +357,10 @@ class AuthController extends BaseController
             Auth::login($user->id, 3600);
             $user->collectLoginIP($_SERVER['REMOTE_ADDR']);
 
-            $res['ret'] = 1;
-            $res['msg'] = '注册成功!正在进入登录界面';
-            return $res;
+            return ResponseHelper::successfully($response, '注册成功!正在进入登录界面');
         }
 
-        $res['ret'] = 0;
-        $res['msg'] = '未知错误';
-        return $res;
+        return ResponseHelper::error($response, '未知错误');
     }
 
     /**
@@ -400,10 +369,7 @@ class AuthController extends BaseController
     public function registerHandle(Request $request, Response $response, array $args)
     {
         if (Setting::obtain('reg_mode') === 'close') {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '未开放注册。',
-            ]);
+            return ResponseHelper::error($response, '未开放注册。');
         }
 
         $name = $request->getParam('name');
@@ -420,17 +386,11 @@ class AuthController extends BaseController
             $imtype = $request->getParam('im_type');
             $imvalue = $request->getParam('im_value');
             if ($imtype === '' || $imvalue === '') {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '请填上你的联络方式',
-                ]);
+                return ResponseHelper::error($response, '请填上你的联络方式');
             }
             $user = User::where('im_value', $imvalue)->where('im_type', $imtype)->first();
             if ($user !== null) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '此联络方式已注册',
-                ]);
+                return ResponseHelper::error($response, '此联络方式已注册');
             }
         } else {
             $imtype = 1;
@@ -440,10 +400,7 @@ class AuthController extends BaseController
         if (Setting::obtain('enable_reg_captcha') === true) {
             $ret = Captcha::verify($request->getParams());
             if (! $ret) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '系统无法接受您的验证结果,请刷新页面后重试。',
-                ]);
+                return ResponseHelper::error($response, '系统无法接受您的验证结果,请刷新页面后重试。');
             }
         }
 
@@ -455,45 +412,31 @@ class AuthController extends BaseController
         // check email
         $user = User::where('email', $email)->first();
         if ($user !== null) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '邮箱已经被注册了',
-            ]);
+            return ResponseHelper::error($response, '邮箱已经被注册了');
         }
 
         if (Setting::obtain('reg_email_verify')) {
             $mailcount = EmailVerify::where('email', '=', $email)->where('code', '=', $emailcode)->where('expire_in', '>', time())->first();
             if ($mailcount === null) {
-                return $response->withJson([
-                    'ret' => 0,
-                    'msg' => '您的邮箱验证码不正确',
-                ]);
+                return ResponseHelper::error($response, '您的邮箱验证码不正确');
             }
         }
 
         // check pwd length
         if (strlen($passwd) < 8) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '密码请大于8位',
-            ]);
+            return ResponseHelper::error($response, '密码请大于8位');
         }
 
         // check pwd re
         if ($passwd !== $repasswd) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '两次密码输入不符',
-            ]);
+            return ResponseHelper::error($response, '两次密码输入不符');
         }
 
         if (Setting::obtain('reg_email_verify')) {
             EmailVerify::where('email', $email)->delete();
         }
 
-        return $response->withJson(
-            $this->register_helper($name, $email, $passwd, $code, $imtype, $imvalue, 0)
-        );
+        return $this->registerHelper($response, $name, $email, $passwd, $code, $imtype, $imvalue, 0);
     }
 
     /**
@@ -508,34 +451,31 @@ class AuthController extends BaseController
     /**
      * @param array     $args
      */
-    public function qrcode_check(Request $request, Response $response, array $args)
+    public function qrcodeCheck(Request $request, Response $response, array $args)
     {
         $token = $request->getParam('token');
         $number = $request->getParam('number');
         $user = Auth::getUser();
         if ($user->isLogin) {
-            return $response->withJson([
-                'ret' => 0,
-            ]);
+            return ResponseHelper::error($response, '用户已登陆');
         }
         if ($_ENV['enable_telegram_login'] === true) {
-            $ret = TelegramSessionManager::check_login_session($token, $number);
-            $res['ret'] = $ret;
-            return $response->withJson($res);
+            $ret = TelegramSessionManager::checkLoginSession($token, $number);
+            return $response->withJson([
+                'ret' => $ret,
+            ]);
         }
-        return $response->withJson([
-            'ret' => 0,
-        ]);
+        return ResponseHelper::error($response, '不允许 QRCode 登陆');
     }
 
     /**
      * @param array     $args
      */
-    public function telegram_oauth(Request $request, Response $response, array $args)
+    public function telegramOauth(Request $request, Response $response, array $args)
     {
         if ($_ENV['enable_telegram_login'] === true) {
             $auth_data = $request->getQueryParams();
-            if ($this->telegram_oauth_check($auth_data) === true) { // Looks good, proceed.
+            if ($this->telegramOauthCheck($auth_data) === true) { // Looks good, proceed.
                 $telegram_id = $auth_data['id'];
                 $user = User::query()->where('telegram_id', $telegram_id)->firstOrFail(); // Welcome Back :)
                 if ($user === null) {
@@ -572,7 +512,7 @@ class AuthController extends BaseController
      * @param Response  $response
      * @param array     $args
      */
-    private function telegram_oauth_check($auth_data)
+    private function telegramOauthCheck($auth_data)
     {
         $check_hash = $auth_data['hash'];
         $bot_token = $_ENV['telegram_token'];

+ 1 - 1
src/Controllers/BaseController.php

@@ -12,7 +12,7 @@ use Smarty;
 /**
  * BaseController
  */
-class BaseController
+abstract class BaseController
 {
     /**
      * @var Smarty

+ 5 - 3
src/Controllers/HomeController.php

@@ -5,14 +5,16 @@ declare(strict_types=1);
 namespace App\Controllers;
 
 use App\Models\InviteCode;
+use App\Utils\Telegram\Process;
+use App\Utils\TelegramProcess;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use TelegramProcess;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
 /**
  *  HomeController
  */
-class HomeController extends BaseController
+final class HomeController extends BaseController
 {
     /**
      * @param array     $args

+ 29 - 32
src/Controllers/LinkController.php

@@ -6,18 +6,25 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
-use Link;
+use App\Models\Link;
+use App\Models\User;
+use App\Models\UserSubscribeLog;
+use App\Utils\AppURI;
+use App\Utils\ConfGenerate;
+use App\Utils\ConfRender;
+use App\Utils\Tools;
+use App\Utils\URL;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use URL;
+use Slim\Http\Request;
+use Slim\Http\Response;
 use voku\helper\AntiXSS;
 
 /**
  *  LinkController
  */
-class LinkController extends BaseController
+final class LinkController extends BaseController
 {
-    public static function GenerateRandomLink()
+    public static function generateRandomLink()
     {
         for ($i = 0; $i < 10; $i++) {
             $token = Tools::genRandomChar(16);
@@ -30,7 +37,7 @@ class LinkController extends BaseController
         return "couldn't alloc token";
     }
 
-    public static function GenerateSSRSubCode(int $userid): string
+    public static function generateSSRSubCode(int $userid): string
     {
         $Elink = Link::where('userid', $userid)->first();
         if ($Elink !== null) {
@@ -38,7 +45,7 @@ class LinkController extends BaseController
         }
         $NLink = new Link();
         $NLink->userid = $userid;
-        $NLink->token = self::GenerateRandomLink();
+        $NLink->token = self::generateRandomLink();
         $NLink->save();
 
         return $NLink->token;
@@ -47,7 +54,7 @@ class LinkController extends BaseController
     /**
      * @param array     $args
      */
-    public static function GetContent(Request $request, Response $response, array $args)
+    public static function getContent(Request $request, Response $response, array $args)
     {
         if (! $_ENV['Subscribe']) {
             return null;
@@ -68,6 +75,7 @@ class LinkController extends BaseController
         $opts = $request->getQueryParams();
 
         // 筛选节点部分
+        $Rule = [];
         $Rule['type'] = (isset($opts['type']) ? trim($opts['type']) : 'all');
         $Rule['is_mu'] = ($_ENV['mergeSub'] === true ? 1 : 0);
         if (isset($opts['mu'])) {
@@ -77,7 +85,7 @@ class LinkController extends BaseController
         if (isset($opts['class'])) {
             $class = trim(urldecode($opts['class']));
             $Rule['content']['class'] = array_map(
-                function ($item) {
+                static function ($item) {
                     return (int) $item;
                 },
                 explode('-', $class)
@@ -87,7 +95,7 @@ class LinkController extends BaseController
         if (isset($opts['noclass'])) {
             $noclass = trim(urldecode($opts['noclass']));
             $Rule['content']['noclass'] = array_map(
-                function ($item) {
+                static function ($item) {
                     return (int) $item;
                 },
                 explode('-', $noclass)
@@ -173,7 +181,7 @@ class LinkController extends BaseController
 
         // 记录订阅日志
         if ($_ENV['subscribeLog'] === true) {
-            self::Subscribe_log($user, $subscribe_type, $request->getHeaderLine('User-Agent'));
+            self::subscribeLog($user, $subscribe_type, $request->getHeaderLine('User-Agent'));
         }
 
         return $getBody;
@@ -393,7 +401,7 @@ class LinkController extends BaseController
         if ($int === 0) {
             $int = '';
         }
-        $userapiUrl = $_ENV['subUrl'] . self::GenerateSSRSubCode($user->id);
+        $userapiUrl = $_ENV['subUrl'] . self::generateSSRSubCode($user->id);
         $return_info = [
             'link' => '',
             // sub
@@ -422,7 +430,7 @@ class LinkController extends BaseController
         ];
 
         return array_map(
-            function ($item) use ($userapiUrl) {
+            static function ($item) use ($userapiUrl) {
                 return $userapiUrl . $item;
             },
             $return_info
@@ -486,7 +494,7 @@ class LinkController extends BaseController
             // Shadowrocket 自带 emoji
             $Rule['emoji'] = false;
         }
-        $items = URL::getNew_AllItems($user, $Rule);
+        $items = URL::getNewAllItems($user, $Rule);
         $return = [];
         if ($Rule['extend'] === true) {
             switch ($list) {
@@ -603,12 +611,10 @@ class LinkController extends BaseController
      */
     public static function getSurge(User $user, int $surge, array $opts, array $Rule): string
     {
-        $subInfo = self::getSubinfo($user, $surge);
-        $userapiUrl = $subInfo['surge'];
         if ($surge !== 4) {
             $Rule['type'] = 'ss';
         }
-        $items = URL::getNew_AllItems($user, $Rule);
+        $items = URL::getNewAllItems($user, $Rule);
         $Nodes = [];
         $All_Proxy = '';
         foreach ($items as $item) {
@@ -621,7 +627,6 @@ class LinkController extends BaseController
         $variable = ($surge === 2 ? 'Surge2_Profiles' : 'Surge_Profiles');
         if (isset($opts['profiles']) && in_array($opts['profiles'], array_keys($_ENV[$variable]))) {
             $Profiles = $opts['profiles'];
-            $userapiUrl .= '&profiles=' . $Profiles;
         } else {
             $Profiles = ($surge === 2 ? $_ENV['Surge2_DefaultProfiles'] : $_ENV['Surge_DefaultProfiles']);
         }
@@ -660,7 +665,7 @@ class LinkController extends BaseController
                 return implode(PHP_EOL, $str);
                 break;
             case 3:
-                $items = URL::getNew_AllItems($user, $Rule);
+                $items = URL::getNewAllItems($user, $Rule);
                 break;
             default:
                 return self::getLists($user, 'quantumult', $opts, $Rule);
@@ -718,11 +723,9 @@ class LinkController extends BaseController
      */
     public static function getSurfboard(User $user, int $surfboard, array $opts, array $Rule): string
     {
-        $subInfo = self::getSubinfo($user, 0);
-        $userapiUrl = $subInfo['surfboard'];
         $Nodes = [];
         $All_Proxy = '';
-        $items = URL::getNew_AllItems($user, $Rule);
+        $items = URL::getNewAllItems($user, $Rule);
         foreach ($items as $item) {
             $out = AppURI::getSurfboardURI($item);
             if ($out !== null) {
@@ -732,7 +735,6 @@ class LinkController extends BaseController
         }
         if (isset($opts['profiles']) && in_array($opts['profiles'], array_keys($_ENV['Surfboard_Profiles']))) {
             $Profiles = $opts['profiles'];
-            $userapiUrl .= '&profiles=' . $Profiles;
         } else {
             $Profiles = $_ENV['Surfboard_DefaultProfiles']; // 默认策略组
         }
@@ -750,9 +752,7 @@ class LinkController extends BaseController
      */
     public static function getClash(User $user, int $clash, array $opts, array $Rule): string
     {
-        $subInfo = self::getSubinfo($user, $clash);
-        $userapiUrl = $subInfo['clash'];
-        $items = URL::getNew_AllItems($user, $Rule);
+        $items = URL::getNewAllItems($user, $Rule);
         $Proxys = [];
         foreach ($items as $item) {
             $Proxy = AppURI::getClashURI($item);
@@ -762,7 +762,6 @@ class LinkController extends BaseController
         }
         if (isset($opts['profiles']) && in_array($opts['profiles'], array_keys($_ENV['Clash_Profiles']))) {
             $Profiles = $opts['profiles'];
-            $userapiUrl .= '&profiles=' . $Profiles;
         } else {
             $Profiles = $_ENV['Clash_DefaultProfiles']; // 默认策略组
         }
@@ -772,10 +771,8 @@ class LinkController extends BaseController
 
     public static function getAnXray($user, $anxray, $opts, $Rule)
     {
-        $subInfo = self::getSubinfo($user, $anxray);
         $All_Proxy = '';
-        $userapiUrl = $subInfo['anxray'];
-        $items = URL::getNew_AllItems($user, $Rule);
+        $items = URL::getNewAllItems($user, $Rule);
         foreach ($items as $item) {
             $out = AppURI::getAnXrayURI($item);
             if ($out !== null) {
@@ -816,7 +813,7 @@ class LinkController extends BaseController
         if ($Rule['extend']) {
             $return_url .= implode(PHP_EOL, $getListExtend) . PHP_EOL;
         }
-        $return_url .= URL::get_NewAllUrl($user, $Rule);
+        $return_url .= URL::getNewAllUrl($user, $Rule);
         return base64_encode($return_url);
     }
 
@@ -827,7 +824,7 @@ class LinkController extends BaseController
      * @param string $type 订阅类型
      * @param string $ua   UA
      */
-    private static function Subscribe_log(User $user, string $type, string $ua): void
+    private static function subscribeLog(User $user, string $type, string $ua): void
     {
         $log = new UserSubscribeLog();
         $log->user_name = $user->user_name;

+ 11 - 7
src/Controllers/Mod_Mu/FuncController.php → src/Controllers/Node/FuncController.php

@@ -2,15 +2,19 @@
 
 declare(strict_types=1);
 
-namespace App\Controllers\Mod_Mu;
+namespace App\Controllers\Node;
 
 use App\Controllers\BaseController;
+use App\Models\BlockIp;
+use App\Models\DetectRule;
+use App\Models\Node;
+use App\Models\UnblockIp;
 use App\Utils\Tools;
-use Node;
 use Psr\Http\Message\ResponseInterface;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class FuncController extends BaseController
+final class FuncController extends BaseController
 {
     /**
      * @param array     $args
@@ -27,7 +31,7 @@ class FuncController extends BaseController
     /**
      * @param array     $args
      */
-    public function get_detect_logs(Request $request, Response $response, array $args): ResponseInterface
+    public function getDetectLogs(Request $request, Response $response, array $args): ResponseInterface
     {
         $rules = DetectRule::all();
 
@@ -46,7 +50,7 @@ class FuncController extends BaseController
     /**
      * @param array     $args
      */
-    public function get_blockip(Request $request, Response $response, array $args): ResponseInterface
+    public function getBlockip(Request $request, Response $response, array $args): ResponseInterface
     {
         $block_ips = BlockIp::Where('datetime', '>', time() - 60)->get();
 
@@ -65,7 +69,7 @@ class FuncController extends BaseController
     /**
      * @param array     $args
      */
-    public function get_unblockip(Request $request, Response $response, array $args): ResponseInterface
+    public function getUnblockip(Request $request, Response $response, array $args): ResponseInterface
     {
         $unblock_ips = UnblockIp::Where('datetime', '>', time() - 60)->get();
 

+ 9 - 9
src/Controllers/Mod_Mu/NodeController.php → src/Controllers/Node/NodeController.php

@@ -2,16 +2,19 @@
 
 declare(strict_types=1);
 
-namespace App\Controllers\Mod_Mu;
+namespace App\Controllers\Node;
 
 use App\Controllers\BaseController;
+use App\Models\Node;
+use App\Models\NodeInfoLog;
+use App\Models\StreamMedia;
 use App\Services\Config;
 use App\Utils\Tools;
-use Node;
 use Psr\Http\Message\ResponseInterface;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class NodeController extends BaseController
+final class NodeController extends BaseController
 {
     /**
      * @param array     $args
@@ -75,7 +78,7 @@ class NodeController extends BaseController
     /**
      * @param array     $args
      */
-    public function get_info(Request $request, Response $response, array $args): ResponseInterface
+    public function getInfo(Request $request, Response $response, array $args): ResponseInterface
     {
         $node_id = $args['id'];
         if ($node_id === '0') {
@@ -125,7 +128,7 @@ class NodeController extends BaseController
     /**
      * @param array     $args
      */
-    public function get_all_info(Request $request, Response $response, array $args): ResponseInterface
+    public function getAllInfo(Request $request, Response $response, array $args): ResponseInterface
     {
         $nodes = Node::where('node_ip', '<>', null)->where(
             static function ($query): void {
@@ -165,9 +168,6 @@ class NodeController extends BaseController
                     'data' => $db_config,
                 ];
                 break;
-            case 'webapi':
-                $webapiConfig = [];
-                #todo
         }
         return $response->withJson($res);
     }

+ 10 - 5
src/Controllers/Mod_Mu/UserController.php → src/Controllers/Node/UserController.php

@@ -2,15 +2,20 @@
 
 declare(strict_types=1);
 
-namespace App\Controllers\Mod_Mu;
+namespace App\Controllers\Node;
 
 use App\Controllers\BaseController;
+use App\Models\DetectLog;
+use App\Models\Ip;
+use App\Models\Node;
+use App\Models\NodeOnlineLog;
+use App\Models\User;
 use App\Utils\Tools;
-use Ip;
 use Psr\Http\Message\ResponseInterface;
-use Request;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
-class UserController extends BaseController
+final class UserController extends BaseController
 {
     /**
      * User List
@@ -48,7 +53,7 @@ class UserController extends BaseController
 
         if (in_array($node->sort, [0, 10]) && $node->mu_only !== -1) {
             $mu_port_migration = $_ENV['mu_port_migration'];
-            $muPort = Tools::get_MuOutPortArray($node->server);
+            $muPort = Tools::getMutilUserOutPortArray($node->server);
         } else {
             $mu_port_migration = false;
         }

+ 23 - 42
src/Controllers/PasswordController.php

@@ -4,10 +4,13 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
+use App\Models\PasswordReset;
+use App\Models\User;
 use App\Services\Password;
 use App\Utils\Hash;
-use Request;
-use User;
+use App\Utils\ResponseHelper;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
 /*
  * Class Password
@@ -15,7 +18,7 @@ use User;
  * @package App\Controllers
  * 密码重置
  */
-class PasswordController extends BaseController
+final class PasswordController extends BaseController
 {
     /**
      * @param array     $args
@@ -35,20 +38,14 @@ class PasswordController extends BaseController
         $email = strtolower($request->getParam('email'));
         $user = User::where('email', $email)->first();
         if ($user === null) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '此邮箱不存在',
-            ]);
+            return ResponseHelper::error($response, '此邮箱不存在');
         }
         if (Password::sendResetEmail($email)) {
             $msg = '重置邮件已经发送,请检查邮箱.';
         } else {
             $msg = '邮件发送失败,请联系网站管理员。';
         }
-        return $response->withJson([
-            'ret' => 1,
-            'msg' => $msg,
-        ]);
+        return ResponseHelper::successfully($response, $msg);
     }
 
     /**
@@ -75,34 +72,22 @@ class PasswordController extends BaseController
         $repasswd = $request->getParam('repasswd');
 
         if ($password !== $repasswd) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '两次输入不符合',
-            ]);
+            return ResponseHelper::error($response, '两次输入不符合');
         }
 
         if (strlen($password) < 8) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '密码太短啦',
-            ]);
+            return ResponseHelper::error($response, '密码太短啦');
         }
 
-        // check token
+        /** @var PasswordReset $token */
         $token = PasswordReset::where('token', $tokenStr)->where('expire_time', '>', time())->orderBy('id', 'desc')->first();
         if ($token === null) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '链接已经失效,请重新获取',
-            ]);
+            return ResponseHelper::error($response, '链接已经失效,请重新获取');
         }
-        /** @var PasswordReset $token */
+
         $user = $token->getUser();
         if ($user === null) {
-            return $response->withJson([
-                'ret' => 0,
-                'msg' => '链接已经失效,请重新获取',
-            ]);
+            return ResponseHelper::error($response, '链接已经失效,请重新获取');
         }
 
         // reset password
@@ -111,21 +96,17 @@ class PasswordController extends BaseController
         $user->ga_enable = 0;
 
         if (! $user->save()) {
-            $rs['ret'] = 0;
-            $rs['msg'] = '重置失败,请重试';
-        } else {
-            $rs['ret'] = 1;
-            $rs['msg'] = '重置成功';
-
-            if ($_ENV['enable_forced_replacement'] === true) {
-                $user->clean_link();
-            }
+            return ResponseHelper::error($response, '重置失败,请重试');
+        }
 
-            // 禁止链接多次使用
-            $token->expire_time = time();
-            $token->save();
+        if ($_ENV['enable_forced_replacement'] === true) {
+            $user->cleanLink();
         }
 
-        return $response->withJson($rs);
+        // 禁止链接多次使用
+        $token->expire_time = time();
+        $token->save();
+
+        return ResponseHelper::successfully($response, '重置成功');
     }
 }

+ 2 - 2
src/Controllers/SubController.php

@@ -13,7 +13,7 @@ use Psr\Http\Message\ResponseInterface;
 /**
  *  SubController
  */
-class SubController extends BaseController
+final class SubController extends BaseController
 {
     public static function getContent($request, $response, $args): ResponseInterface
     {
@@ -52,7 +52,7 @@ class SubController extends BaseController
         $nodes_raw = Node::where('type', 1)
             ->where('node_class', '<=', $user->class)
             ->whereIn('node_group', [0, $user->group])
-            ->where(function ($query): void {
+            ->where(static function ($query): void {
                 $query->where('node_bandwidth_limit', '=', 0)->orWhereRaw('node_bandwidth < node_bandwidth_limit');
             })
             ->get();

+ 75 - 0
src/Controllers/User/DetectController.php

@@ -0,0 +1,75 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Controllers\User;
+
+use App\Controllers\UserController;
+use Slim\Http\Request;
+use Slim\Http\Response;
+
+final class DetectController extends UserController
+{
+    /**
+     * @param array     $args
+     */
+    public function detectIndex(Request $request, Response $response, array $args)
+    {
+        $pageNum = $request->getQueryParams()['page'] ?? 1;
+        $logs = DetectRule::paginate(15, ['*'], 'page', $pageNum);
+
+        if ($request->getParam('json') === 1) {
+            return $response->withJson([
+                'ret' => 1,
+                'logs' => $logs,
+            ]);
+        }
+
+        $logs->setPath('/user/detect');
+        $render = Tools::paginateRender($logs);
+        return $this->view()
+            ->assign('rules', $logs)
+            ->assign('render', $render)
+            ->display('user/detect_index.tpl');
+    }
+
+    /**
+     * @param array     $args
+     */
+    public function detectLog(Request $request, Response $response, array $args)
+    {
+        $pageNum = $request->getQueryParams()['page'] ?? 1;
+        $logs = DetectLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->paginate(15, ['*'], 'page', $pageNum);
+
+        if ($request->getParam('json') === 1) {
+            foreach ($logs as $log) {
+                /** @var DetectLog $log */
+                if ($log->node() === null) {
+                    DetectLog::nodeIsNull($log);
+                    continue;
+                }
+                if ($log->rule() === null) {
+                    DetectLog::ruleIsNull($log);
+                    continue;
+                }
+                $log->node_name = $log->nodeName();
+                $log->detect_rule_name = $log->ruleName();
+                $log->detect_rule_text = $log->ruleText();
+                $log->detect_rule_regex = $log->ruleRegex();
+                $log->detect_rule_type = $log->ruleType();
+                $log->detect_rule_date = $log->datetime();
+            }
+            return $response->withJson([
+                'ret' => 1,
+                'logs' => $logs,
+            ]);
+        }
+
+        $logs->setPath('/user/detect/log');
+        $render = Tools::paginateRender($logs);
+        return $this->view()
+            ->assign('logs', $logs)
+            ->assign('render', $render)
+            ->display('user/detect_log.tpl');
+    }
+}

+ 16 - 13
src/Controllers/User/NodeController.php

@@ -5,20 +5,23 @@ declare(strict_types=1);
 namespace App\Controllers\User;
 
 use App\Controllers\UserController;
-use Node;
+use App\Models\Node;
+use App\Models\User;
+use App\Utils\Tools;
+use App\Utils\URL;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use URL;
+use Slim\Http\Request;
+use Slim\Http\Response;
 
 /**
  *  User NodeController
  */
-class NodeController extends UserController
+final class NodeController extends UserController
 {
     /**
      * @param array     $args
      */
-    public function user_node_page(Request $request, Response $response, array $args): ResponseInterface
+    public function userNodePage(Request $request, Response $response, array $args): ResponseInterface
     {
         $user = $this->user;
         $query = Node::query();
@@ -37,15 +40,15 @@ class NodeController extends UserController
             $array_node['name'] = $node->name;
             $array_node['class'] = $node->node_class;
             $array_node['info'] = $node->info;
-            $array_node['flag'] = $node->get_node_flag();
-            $array_node['online_user'] = $node->get_node_online_user_count();
-            $array_node['online'] = $node->get_node_online_status();
-            $array_node['latest_load'] = $node->get_node_latest_load_text();
+            $array_node['flag'] = $node->getNodeFlag();
+            $array_node['online_user'] = $node->getNodeOnlineUserCount();
+            $array_node['online'] = $node->getNodeOnlineStatus();
+            $array_node['latest_load'] = $node->getNodeLatestLoadText();
             $array_node['traffic_rate'] = $node->traffic_rate;
             $array_node['status'] = $node->status;
             $array_node['traffic_used'] = (int) Tools::flowToGB($node->node_bandwidth);
             $array_node['traffic_limit'] = (int) Tools::flowToGB($node->node_bandwidth_limit);
-            $array_node['bandwidth'] = $node->get_node_speedlimit();
+            $array_node['bandwidth'] = $node->getNodeSpeedlimit();
 
             $all_connect = [];
             if (in_array($node->sort, [0])) {
@@ -83,7 +86,7 @@ class NodeController extends UserController
     /**
      * @param array     $args
      */
-    public function user_node_ajax(Request $request, Response $response, array $args): ResponseInterface
+    public function userNodeAjax(Request $request, Response $response, array $args): ResponseInterface
     {
         $id = $args['id'];
         $point_node = Node::find($id);
@@ -100,7 +103,7 @@ class NodeController extends UserController
     /**
      * @param array     $args
      */
-    public function user_node_info(Request $request, Response $response, array $args): ResponseInterface
+    public function userNodeInfo(Request $request, Response $response, array $args): ResponseInterface
     {
         $user = $this->user;
         $node = Node::find($args['id']);
@@ -181,7 +184,7 @@ class NodeController extends UserController
             case 14:
                 $server = $node->getTrojanItem($user);
                 $nodes = [
-                    'url' => URL::get_trojan_url($user, $node),
+                    'url' => URL::getTrojanUrl($user, $node),
                     'info' => [
                         '连接地址:' => $server['address'],
                         '连接端口:' => $server['port'],

+ 234 - 0
src/Controllers/User/ShopController.php

@@ -0,0 +1,234 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Controllers\User;
+
+use App\Controllers\UserController;
+use App\Models\Coupon;
+use App\Models\Payback;
+use App\Models\Shop;
+use App\Utils\ResponseHelper;
+use Slim\Http\Request;
+use Slim\Http\Response;
+
+final class ShopController extends UserController
+{
+    /**
+     * @param array     $args
+     */
+    public function shop(Request $request, Response $response, array $args)
+    {
+        $shops = Shop::where('status', 1)->orderBy('name')->get();
+        return $this->view()->assign('shops', $shops)->display('user/shop.tpl');
+    }
+
+    /**
+     * @param array     $args
+     */
+    public function couponCheck(Request $request, Response $response, array $args)
+    {
+        $coupon = $request->getParam('coupon');
+        $coupon = trim($coupon);
+
+        $user = $this->user;
+        $shop = $request->getParam('shop');
+
+        $shop = Shop::where('id', $shop)->where('status', 1)->first();
+
+        if ($shop === null) {
+            return ResponseHelper::error($response, '非法请求');
+        }
+
+        if ($coupon === '') {
+            return $response->withJson([
+                'ret' => 1,
+                'name' => $shop->name,
+                'credit' => '0 %',
+                'total' => $shop->price . '元',
+            ]);
+        }
+
+        $coupon = Coupon::where('code', $coupon)->first();
+
+        if ($coupon === null) {
+            return ResponseHelper::error($response, '优惠码无效');
+        }
+
+        if ($coupon->order($shop->id) === false) {
+            return ResponseHelper::error($response, '此优惠码不可用于此商品');
+        }
+
+        $use_limit = $coupon->onetime;
+        if ($use_limit > 0) {
+            $use_count = Bought::where('userid', $user->id)->where('coupon', $coupon->code)->count();
+            if ($use_count >= $use_limit) {
+                return ResponseHelper::error($response, '优惠码次数已用完');
+            }
+        }
+
+        return $response->withJson([
+            'ret' => 1,
+            'name' => $shop->name,
+            'credit' => $coupon->credit . ' %',
+            'total' => $shop->price * ((100 - $coupon->credit) / 100) . '元',
+        ]);
+    }
+
+    /**
+     * @param array     $args
+     */
+    public function buy(Request $request, Response $response, array $args)
+    {
+        $user = $this->user;
+        $coupon = $request->getParam('coupon');
+        $coupon = trim($coupon);
+        $code = $coupon;
+        $shop = $request->getParam('shop');
+        $disableothers = $request->getParam('disableothers');
+        $autorenew = $request->getParam('autorenew');
+
+        $shop = Shop::where('id', $shop)->where('status', 1)->first();
+
+        $orders = Bought::where('userid', $this->user->id)->get();
+        foreach ($orders as $order) {
+            if ($order->shop()->useLoop()) {
+                if ($order->valid()) {
+                    return ResponseHelper::error(
+                        $response,
+                        '您购买的含有自动重置系统的套餐还未过期,无法购买新套餐'
+                    );
+                }
+            }
+        }
+
+        if ($shop === null) {
+            return ResponseHelper::error($response, '非法请求');
+        }
+
+        if ($coupon === '') {
+            $credit = 0;
+        } else {
+            $coupon = Coupon::where('code', $coupon)->first();
+
+            if ($coupon === null) {
+                $credit = 0;
+            } else {
+                if ($coupon->onetime === 1) {
+                    $onetime = true;
+                }
+
+                $credit = $coupon->credit;
+            }
+
+            if ($coupon->order($shop->id) === false) {
+                return ResponseHelper::error($response, '此优惠码不可用于此商品');
+            }
+
+            if ($coupon->expire < time()) {
+                return ResponseHelper::error($response, '此优惠码已过期');
+            }
+
+            $use_limit = $coupon->onetime;
+            if ($use_limit > 0) {
+                $use_count = Bought::where('userid', $user->id)->where('coupon', $coupon->code)->count();
+                if ($use_count >= $use_limit) {
+                    return ResponseHelper::error($response, '优惠码次数已用完');
+                }
+            }
+        }
+
+        $price = $shop->price * (100 - $credit) / 100;
+
+        if (! $user->isLogin) {
+            return $response->withJson(['ret' => -1]);
+        }
+
+        if (bccomp($user->money, $price, 2) === -1) {
+            return ResponseHelper::error($response, '喵喵喵~ 当前余额不足,总价为'
+                . $price . '元。</br><a href="/user/code">点击进入充值界面</a>');
+        }
+
+        $user->money = bcsub($user->money, $price, 2);
+        $user->save();
+
+        if ($disableothers === 1) {
+            $boughts = Bought::where('userid', $user->id)->get();
+            foreach ($boughts as $disable_bought) {
+                $disable_bought->renew = 0;
+                $disable_bought->save();
+            }
+        }
+
+        $bought = new Bought();
+        $bought->userid = $user->id;
+        $bought->shopid = $shop->id;
+        $bought->datetime = time();
+        if ($autorenew === 0 || $shop->auto_renew === 0) {
+            $bought->renew = 0;
+        } else {
+            $bought->renew = time() + $shop->auto_renew * 86400;
+        }
+
+        $bought->coupon = $code;
+
+        if (isset($onetime)) {
+            $price = $shop->price;
+        }
+        $bought->price = $price;
+        $bought->save();
+
+        $shop->buy($user);
+
+        return ResponseHelper::successfully($response, '购买成功');
+    }
+
+    /**
+     * @param array     $args
+     */
+    public function buyTrafficPackage(Request $request, Response $response, array $args)
+    {
+        $user = $this->user;
+        $shop = $request->getParam('shop');
+        $shop = Shop::where('id', $shop)->where('status', 1)->first();
+        $price = $shop->price;
+
+        if ($shop === null || $shop->trafficPackage() === 0) {
+            return ResponseHelper::error($response, '非法请求');
+        }
+
+        if ($user->class < $shop->content['traffic_package']['class']['min'] || $user->class > $shop->content['traffic_package']['class']['max']) {
+            return ResponseHelper::error($response, '您当前的会员等级无法购买此流量包');
+        }
+
+        if (! $user->isLogin) {
+            return $response->withJson([ 'ret' => -1 ]);
+        }
+
+        if (bccomp($user->money, $price, 2) === -1) {
+            return ResponseHelper::error($response, '喵喵喵~ 当前余额不足,总价为'
+                . $price . '元。</br><a href="/user/code">点击进入充值界面</a>');
+        }
+
+        $user->money = bcsub($user->money, $price, 2);
+        $user->save();
+
+        $bought = new Bought();
+        $bought->userid = $user->id;
+        $bought->shopid = $shop->id;
+        $bought->datetime = time();
+        $bought->renew = 0;
+        $bought->coupon = 0;
+        $bought->price = $price;
+        $bought->save();
+
+        $shop->buy($user);
+
+        // 返利
+        if ($user->ref_by > 0 && Setting::obtain('invitation_mode') === 'after_purchase') {
+            Payback::rebate($user->id, $price);
+        }
+
+        return ResponseHelper::successfully($response, '购买成功');
+    }
+}

+ 11 - 9
src/Controllers/User/TicketController.php

@@ -5,16 +5,18 @@ declare(strict_types=1);
 namespace App\Controllers\User;
 
 use App\Controllers\UserController;
+use App\Models\Ticket;
+use App\Models\User;
 use App\Utils\Tools;
 use Psr\Http\Message\ResponseInterface;
-use Request;
-use User;
+use Slim\Http\Request;
+use Slim\Http\Response;
 use voku\helper\AntiXSS;
 
 /**
  *  TicketController
  */
-class TicketController extends UserController
+final class TicketController extends UserController
 {
     /**
      * @param array     $args
@@ -34,7 +36,7 @@ class TicketController extends UserController
                 'tickets' => $tickets,
             ]);
         }
-        $render = Tools::paginate_render($tickets);
+        $render = Tools::paginateRender($tickets);
 
         return $response->write(
             $this->view()
@@ -47,7 +49,7 @@ class TicketController extends UserController
     /**
      * @param array     $args
      */
-    public function ticket_create(Request $request, Response $response, array $args): ResponseInterface
+    public function ticketCreate(Request $request, Response $response, array $args): ResponseInterface
     {
         return $response->write(
             $this->view()
@@ -58,7 +60,7 @@ class TicketController extends UserController
     /**
      * @param array     $args
      */
-    public function ticket_add(Request $request, Response $response, array $args): ResponseInterface
+    public function ticketAdd(Request $request, Response $response, array $args): ResponseInterface
     {
         $title = $request->getParam('title');
         $content = $request->getParam('content');
@@ -124,7 +126,7 @@ class TicketController extends UserController
     /**
      * @param array     $args
      */
-    public function ticket_update(Request $request, Response $response, array $args): ResponseInterface
+    public function ticketUpdate(Request $request, Response $response, array $args): ResponseInterface
     {
         $id = $args['id'];
         $content = $request->getParam('content');
@@ -229,7 +231,7 @@ class TicketController extends UserController
     /**
      * @param array     $args
      */
-    public function ticket_view(Request $request, Response $response, array $args): ResponseInterface
+    public function ticketView(Request $request, Response $response, array $args): ResponseInterface
     {
         $id = $args['id'];
         $ticket_main = Ticket::where('id', '=', $id)->where('userid', $this->user->id)->where('rootid', '=', 0)->first();
@@ -255,7 +257,7 @@ class TicketController extends UserController
                 'tickets' => $ticketset,
             ]);
         }
-        $render = Tools::paginate_render($ticketset);
+        $render = Tools::paginateRender($ticketset);
         return $response->write(
             $this->view()
                 ->assign('ticketset', $ticketset)

Fichier diff supprimé car celui-ci est trop grand
+ 164 - 458
src/Controllers/UserController.php


+ 1 - 1
src/Middleware/Admin.php

@@ -6,7 +6,7 @@ namespace App\Middleware;
 
 use App\Services\Auth as AuthService;
 
-class Admin
+final class Admin
 {
     public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next): \Slim\Http\Response
     {

+ 1 - 1
src/Middleware/Auth.php

@@ -6,7 +6,7 @@ namespace App\Middleware;
 
 use App\Services\Auth as AuthService;
 
-class Auth
+final class Auth
 {
     public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next): \Slim\Http\Response
     {

+ 2 - 2
src/Middleware/AuthorizationBearer.php

@@ -4,9 +4,9 @@ declare(strict_types=1);
 
 namespace App\Middleware;
 
-class AuthorizationBearer
+final class AuthorizationBearer
 {
-    protected string $token;
+    private string $token;
 
     public function __construct(string $token)
     {

+ 1 - 1
src/Middleware/Guest.php

@@ -6,7 +6,7 @@ namespace App\Middleware;
 
 use App\Services\Auth as AuthService;
 
-class Guest
+final class Guest
 {
     public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next): \Slim\Http\Response
     {

+ 1 - 1
src/Middleware/Mod_Mu.php → src/Middleware/NodeToken.php

@@ -7,7 +7,7 @@ namespace App\Middleware;
 use App\Models\Node;
 use App\Services\Config;
 
-class Mod_Mu
+final class NodeToken
 {
     public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next): \Slim\Http\Response
     {

+ 1 - 1
src/Models/Ann.php

@@ -13,7 +13,7 @@ namespace App\Models;
  * @property        string $content    Announcement in HTML
  * @property        string $markdown   Announcement in MarkDown
  */
-class Ann extends Model
+final class Ann extends Model
 {
     protected $connection = 'default';
 

+ 2 - 2
src/Models/BlockIp.php

@@ -6,7 +6,7 @@ namespace App\Models;
 
 use App\Utils\QQWry;
 
-class BlockIp extends Model
+final class BlockIp extends Model
 {
     protected $connection = 'default';
 
@@ -23,7 +23,7 @@ class BlockIp extends Model
     /**
      * 节点名
      */
-    public function node_name(): string
+    public function nodeName(): string
     {
         if ($this->node() === null) {
             return '节点已不存在';

+ 13 - 13
src/Models/Bought.php

@@ -17,7 +17,7 @@ namespace App\Models;
  * @property        float   $price      Price after coupon applied
  * @property        bool    $is_notified If this bought is notified for renew
  */
-class Bought extends Model
+final class Bought extends Model
 {
     protected $connection = 'default';
 
@@ -26,7 +26,7 @@ class Bought extends Model
     /**
      * [静态方法] 删除不存在的用户的记录
      */
-    public static function user_is_null(Bought $Bought): void
+    public static function userIsNull(Bought $Bought): void
     {
         self::where('userid', $Bought->userid)->delete();
     }
@@ -34,7 +34,7 @@ class Bought extends Model
     /**
      * [静态方法] 删除不存在的商品的记录
      */
-    public static function shop_is_null(Bought $Bought): void
+    public static function shopIsNull(Bought $Bought): void
     {
         self::where('shopid', $Bought->shopid)->delete();
     }
@@ -69,7 +69,7 @@ class Bought extends Model
     /**
      * 购买用户名
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->user() === null) {
             return '用户已不存在';
@@ -99,7 +99,7 @@ class Bought extends Model
     /**
      * 流量是否自动重置
      */
-    public function auto_reset_bandwidth(): string
+    public function autoResetBandwidthString(): string
     {
         if ($this->shop() === null) {
             return '商品已不存在';
@@ -110,7 +110,7 @@ class Bought extends Model
     /*
      * 套餐已使用的天数
      */
-    public function used_days(): int
+    public function usedDays(): int
     {
         return (int) ((time() - $this->datetime) / 86400);
     }
@@ -121,8 +121,8 @@ class Bought extends Model
     public function valid(): bool
     {
         $shop = $this->shop();
-        if ($shop->use_loop()) {
-            return time() - $shop->reset_exp() * 86400 < $this->datetime;
+        if ($shop->useLoop()) {
+            return time() - $shop->resetExp() * 86400 < $this->datetime;
         }
         return false;
     }
@@ -130,10 +130,10 @@ class Bought extends Model
     /*
      * 下一次流量重置时间
      */
-    public function reset_time($unix = false)
+    public function resetTime($unix = false)
     {
         $shop = $this->shop();
-        if ($shop->use_loop()) {
+        if ($shop->useLoop()) {
             $day = 24 * 60 * 60;
             $resetIndex = 1 + (int) ((time() - $this->datetime - $day) / ($shop->reset() * $day));
             $restTime = $resetIndex * $shop->reset() * $day + $this->datetime;
@@ -146,11 +146,11 @@ class Bought extends Model
     /*
      * 过期时间
      */
-    public function exp_time($unix = false)
+    public function expTime($unix = false)
     {
         $shop = $this->shop();
-        if ($shop->use_loop()) {
-            $time = $this->datetime + ($shop->reset_exp() * 86400);
+        if ($shop->useLoop()) {
+            $time = $this->datetime + ($shop->resetExp() * 86400);
             return ! $unix ? date('Y-m-d H:i:s', $time) : $time;
         }
         return ! $unix ? '-' : 0;

+ 2 - 2
src/Models/Code.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * Code Model
  */
-class Code extends Model
+final class Code extends Model
 {
     protected $connection = 'default';
 
@@ -32,7 +32,7 @@ class Code extends Model
     /**
      * 用户名
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->userid === 0) {
             return '未使用';

+ 1 - 1
src/Models/Coupon.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class Coupon extends Model
+final class Coupon extends Model
 {
     protected $connection = 'default';
     protected $table = 'coupon';

+ 5 - 5
src/Models/DetectBanLog.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class DetectBanLog extends Model
+final class DetectBanLog extends Model
 {
     protected $connection = 'default';
 
@@ -13,7 +13,7 @@ class DetectBanLog extends Model
     /**
      * [静态方法] 删除不存在的用户的记录
      */
-    public static function user_is_null(DetectBanLog $DetectBanLog): void
+    public static function userIsNull(DetectBanLog $DetectBanLog): void
     {
         self::where('user_id', $DetectBanLog->user_id)->delete();
     }
@@ -29,7 +29,7 @@ class DetectBanLog extends Model
     /**
      * 统计开始时间
      */
-    public function start_time(): string
+    public function startTime(): string
     {
         return date('Y-m-d H:i:s', $this->start_time);
     }
@@ -37,7 +37,7 @@ class DetectBanLog extends Model
     /**
      * 统计结束以及封禁开始时间
      */
-    public function end_time(): string
+    public function endTime(): string
     {
         return date('Y-m-d H:i:s', $this->end_time);
     }
@@ -45,7 +45,7 @@ class DetectBanLog extends Model
     /**
      * 封禁结束时间
      */
-    public function ban_end_time(): string
+    public function banEndTime(): string
     {
         return date('Y-m-d H:i:s', $this->end_time + $this->ban_time * 60);
     }

+ 10 - 10
src/Models/DetectLog.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class DetectLog extends Model
+final class DetectLog extends Model
 {
     protected $connection = 'default';
 
@@ -13,7 +13,7 @@ class DetectLog extends Model
     /**
      * [静态方法] 删除不存在的节点的记录
      */
-    public static function node_is_null(DetectLog $DetectLog): void
+    public static function nodeIsNull(DetectLog $DetectLog): void
     {
         self::where('node_id', $DetectLog->node_id)->delete();
     }
@@ -21,7 +21,7 @@ class DetectLog extends Model
     /**
      * [静态方法] 删除不存在的规则的记录
      */
-    public static function rule_is_null(DetectLog $DetectLog): void
+    public static function ruleIsNull(DetectLog $DetectLog): void
     {
         self::where('list_id', $DetectLog->list_id)->delete();
     }
@@ -29,7 +29,7 @@ class DetectLog extends Model
     /**
      * [静态方法] 删除不存在的用户的记录
      */
-    public static function user_is_null(DetectLog $DetectLog): void
+    public static function userIsNull(DetectLog $DetectLog): void
     {
         self::where('user_id', $DetectLog->user_id)->delete();
     }
@@ -45,7 +45,7 @@ class DetectLog extends Model
     /**
      * 用户名
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->user() === null) {
             return '用户已不存在';
@@ -64,7 +64,7 @@ class DetectLog extends Model
     /**
      * 节点名
      */
-    public function node_name(): string
+    public function nodeName(): string
     {
         if ($this->node() === null) {
             return '节点已不存在';
@@ -83,7 +83,7 @@ class DetectLog extends Model
     /**
      * 规则名
      */
-    public function rule_name(): string
+    public function ruleName(): string
     {
         if ($this->rule() === null) {
             return '规则已不存在';
@@ -94,7 +94,7 @@ class DetectLog extends Model
     /**
      * 规则描述
      */
-    public function rule_text(): string
+    public function ruleText(): string
     {
         if ($this->rule() === null) {
             return '规则已不存在';
@@ -105,7 +105,7 @@ class DetectLog extends Model
     /**
      * 规则正则表达式
      */
-    public function rule_regex(): string
+    public function ruleRegex(): string
     {
         if ($this->rule() === null) {
             return '规则已不存在';
@@ -116,7 +116,7 @@ class DetectLog extends Model
     /**
      * 规则类型
      */
-    public function rule_type(): string
+    public function ruleType(): string
     {
         if ($this->rule() === null) {
             return '规则已不存在';

+ 1 - 1
src/Models/DetectRule.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * DetectLog Model
  */
-class DetectRule extends Model
+final class DetectRule extends Model
 {
     protected $connection = 'default';
 

+ 1 - 1
src/Models/EmailQueue.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * EmailVerify Model
  */
-class EmailQueue extends Model
+final class EmailQueue extends Model
 {
     protected $connection = 'default';
     protected $table = 'email_queue';

+ 1 - 1
src/Models/EmailVerify.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * EmailVerify Model
  */
-class EmailVerify extends Model
+final class EmailVerify extends Model
 {
     protected $connection = 'default';
     protected $table = 'email_verify';

+ 2 - 2
src/Models/GConfig.php

@@ -6,7 +6,7 @@ namespace App\Models;
 
 use App\Services\DefaultConfig;
 
-class GConfig extends Model
+final class GConfig extends Model
 {
     /**
      * The connection name for the model.
@@ -28,7 +28,7 @@ class GConfig extends Model
     public function recover(User $user): void
     {
         $this->oldvalue = $this->value;
-        $this->value = DefaultConfig::default_value($this->key)['value'];
+        $this->value = DefaultConfig::defaultValue($this->key)['value'];
         $this->operator_id = $user->id;
         $this->operator_name = '[恢复默认] - ' . $user->user_name;
         $this->operator_email = $user->email;

+ 1 - 1
src/Models/InviteCode.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * InviteCode Model
  */
-class InviteCode extends Model
+final class InviteCode extends Model
 {
     protected $connection = 'default';
     protected $table = 'user_invite_code';

+ 4 - 4
src/Models/Ip.php

@@ -11,7 +11,7 @@ use App\Utils\Tools;
 /**
  * Ip Model
  */
-class Ip extends Model
+final class Ip extends Model
 {
     protected $connection = 'default';
     protected $table = 'alive_ip';
@@ -27,7 +27,7 @@ class Ip extends Model
     /**
      * 用户名
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->user() === null) {
             return '用户已不存在';
@@ -46,7 +46,7 @@ class Ip extends Model
     /**
      * 节点名
      */
-    public function node_name(): string
+    public function nodeName(): string
     {
         if ($this->node() === null) {
             return '节点已不存在';
@@ -77,7 +77,7 @@ class Ip extends Model
     /**
      * 是否为中转连接
      */
-    public function is_node(): string
+    public function isNode(): string
     {
         return Node::where('node_ip', Tools::getRealIp($this->ip))->first() ? '是' : '否';
     }

+ 1 - 1
src/Models/Link.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class Link extends Model
+final class Link extends Model
 {
     protected $connection = 'default';
     protected $table = 'link';

+ 3 - 3
src/Models/LoginIp.php

@@ -9,7 +9,7 @@ use App\Utils\QQWry;
 /**
  * Ip Model
  */
-class LoginIp extends Model
+final class LoginIp extends Model
 {
     protected $connection = 'default';
 
@@ -22,7 +22,7 @@ class LoginIp extends Model
     /**
      * [静态方法] 删除不存在的用户的记录
      */
-    public static function user_is_null(LoginIp $LoginIp): void
+    public static function userIsNull(LoginIp $LoginIp): void
     {
         self::where('userid', $LoginIp->userid)->delete();
     }
@@ -38,7 +38,7 @@ class LoginIp extends Model
     /**
      * 登录用户
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->user() === null) {
             return '用户已不存在';

+ 2 - 2
src/Models/Model.php

@@ -136,7 +136,7 @@ use Illuminate\Support\LazyCollection;
  *
  * @codingStandardsIgnoreEnd
  */
-class Model extends EloquentMedel
+abstract class Model extends EloquentMedel
 {
     public $timestamps = false;
 
@@ -179,7 +179,7 @@ class Model extends EloquentMedel
         }
         if ($search) {
             $query->where(
-                function ($query) use ($search): void {
+                static function ($query) use ($search): void {
                     $query->where('id', 'LIKE binary', "%${search}%");
                     $attributes = Capsule::schema()->getColumnListing(self::getTableName());
                     foreach ($attributes as $s) {

+ 21 - 19
src/Models/Node.php

@@ -29,7 +29,7 @@ use App\Services\Config;
 use App\Utils\Tools;
 use App\Utils\URL;
 
-class Node extends Model
+final class Node extends Model
 {
     protected $connection = 'default';
 
@@ -82,7 +82,7 @@ class Node extends Model
     /**
      * 单端口多用户启用类型
      */
-    public function mu_only(): string
+    public function muOnly(): string
     {
         switch ($this->mu_only) {
             case -1:
@@ -105,7 +105,7 @@ class Node extends Model
      *
      * @return string [国家].png OR unknown.png
      */
-    public function get_node_flag(): string
+    public function getNodeFlag(): string
     {
         $regex = $_ENV['flag_regex'];
         $matches = [];
@@ -116,7 +116,7 @@ class Node extends Model
     /**
      * 节点最后活跃时间
      */
-    public function node_heartbeat(): string
+    public function nodeHeartbeat(): string
     {
         return date('Y-m-d H:i:s', $this->node_heartbeat);
     }
@@ -158,7 +158,7 @@ class Node extends Model
     /**
      * 获取节点 5 分钟内最新的在线人数
      */
-    public function get_node_online_user_count(): int
+    public function getNodeOnlineUserCount(): int
     {
         if (in_array($this->sort, [9])) {
             return -1;
@@ -175,7 +175,7 @@ class Node extends Model
      *
      * @return int 0 = new node OR -1 = offline OR 1 = online
      */
-    public function get_node_online_status(): int
+    public function getNodeOnlineStatus(): int
     {
         // 类型 9 或者心跳为 0
         if ($this->node_heartbeat === 0 || in_array($this->sort, [9])) {
@@ -187,7 +187,7 @@ class Node extends Model
     /**
      * 获取节点最新负载
      */
-    public function get_node_latest_load(): int
+    public function getNodeLatestLoad(): int
     {
         $log = NodeInfoLog::where('node_id', $this->id)->where('log_time', '>', time() - 300)->orderBy('id', 'desc')->first();
         if ($log === null) {
@@ -199,16 +199,16 @@ class Node extends Model
     /**
      * 获取节点最新负载文本信息
      */
-    public function get_node_latest_load_text(): string
+    public function getNodeLatestLoadText(): string
     {
-        $load = $this->get_node_latest_load();
+        $load = $this->getNodeLatestLoad();
         return $load === -1 ? 'N/A' : $load . '%';
     }
 
     /**
      * 获取节点速率文本信息
      */
-    public function get_node_speedlimit(): string
+    public function getNodeSpeedlimit(): string
     {
         if ($this->node_speedlimit === 0.0) {
             return 0;
@@ -251,7 +251,7 @@ class Node extends Model
      */
     public function changeNodeIp(string $server_name): bool
     {
-        if (! Tools::is_ip($server_name)) {
+        if (! Tools::isIp($server_name)) {
             $ip = gethostbyname($server_name);
             if ($ip === '') {
                 return false;
@@ -276,7 +276,7 @@ class Node extends Model
     /**
      * 获取出口地址 | 用于节点IP获取的地址
      */
-    public function get_out_address(): string
+    public function getOutAddress(): string
     {
         return explode(';', $this->server)[0];
     }
@@ -284,7 +284,7 @@ class Node extends Model
     /**
      * 获取入口地址
      */
-    public function get_entrance_address(): string
+    public function getEntranceAddress(): string
     {
         if ($this->sort === 13) {
             $server = Tools::ssv2Array($this->server);
@@ -293,7 +293,7 @@ class Node extends Model
         $explode = explode(';', $this->server);
         if (in_array($this->sort, [0]) && isset($explode[1])) {
             if (stripos($explode[1], 'server=') !== false) {
-                return URL::parse_args($explode[1])['server'];
+                return URL::parseArgs($explode[1])['server'];
             }
         }
         return $explode[0];
@@ -306,7 +306,7 @@ class Node extends Model
      */
     public function getOffsetPort($port)
     {
-        return Tools::OutPort($this->server, $this->name, $port)['port'];
+        return Tools::outPort($this->server, $this->name, $port)['port'];
     }
 
     /**
@@ -315,6 +315,7 @@ class Node extends Model
     public function getItem(User $user, int $mu_port = 0, int $is_ss = 0, bool $emoji = false): ?array
     {
         $node_name = $this->name;
+        $return_array = [];
         if ($mu_port !== 0) {
             $mu_user = User::where('port', '=', $mu_port)->where('is_multi_user', '<>', 0)->first();
             if ($mu_user === null) {
@@ -345,14 +346,14 @@ class Node extends Model
             $user = URL::getSSRConnectInfo($user);
             $return_array['type'] = 'ssr';
         }
-        $return_array['address'] = $this->get_entrance_address();
+        $return_array['address'] = $this->getEntranceAddress();
         $return_array['port'] = $user->port;
         $return_array['protocol'] = $user->protocol;
         $return_array['protocol_param'] = $user->protocol_param;
         $return_array['obfs'] = $user->obfs;
         $return_array['obfs_param'] = $user->obfs_param;
         if ($mu_port !== 0 && strpos($this->server, ';') !== false) {
-            $node_tmp = Tools::OutPort($this->server, $this->name, $mu_port);
+            $node_tmp = Tools::outPort($this->server, $this->name, $mu_port);
             $return_array['port'] = $node_tmp['port'];
             $node_name = $node_tmp['name'];
         }
@@ -410,7 +411,7 @@ class Node extends Model
                 $return_array['obfs_param'] = 'mode=ws;security=none;path=' . $return_array['path'] .
                     ';host=' . $return_array['host'];
             }
-            $return_array['path'] = $return_array['path'] . '?redirect=' . $user->getMuMd5();
+            $return_array['path'] .= '?redirect=' . $user->getMuMd5();
         }
         $return_array['class'] = $this->node_class;
         $return_array['group'] = $_ENV['appName'];
@@ -429,8 +430,9 @@ class Node extends Model
     {
         $server = explode(';', $this->server);
         $opt = [];
+        $item = [];
         if (isset($server[1])) {
-            $opt = URL::parse_args($server[1]);
+            $opt = URL::parseArgs($server[1]);
         }
         $item['remark'] = ($emoji ? Tools::addEmoji($this->name) : $this->name);
         $item['type'] = 'trojan';

+ 1 - 1
src/Models/NodeInfoLog.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class NodeInfoLog extends Model
+final class NodeInfoLog extends Model
 {
     protected $connection = 'default';
     protected $table = 'node_info';

+ 1 - 1
src/Models/NodeOnlineLog.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class NodeOnlineLog extends Model
+final class NodeOnlineLog extends Model
 {
     protected $connection = 'default';
     protected $table = 'node_online_log';

+ 1 - 1
src/Models/PasswordReset.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class PasswordReset extends Model
+final class PasswordReset extends Model
 {
     protected $connection = 'default';
     protected $table = 'user_password_reset';

+ 1 - 1
src/Models/Payback.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class Payback extends Model
+final class Payback extends Model
 {
     protected $connection = 'default';
     protected $table = 'payback';

+ 1 - 1
src/Models/Paylist.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class Paylist extends Model
+final class Paylist extends Model
 {
     protected $connection = 'default';
     protected $table = 'paylist';

+ 1 - 1
src/Models/Setting.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class Setting extends Model
+final class Setting extends Model
 {
     protected $connection = 'default';
     protected $table = 'config';

+ 11 - 11
src/Models/Shop.php

@@ -14,7 +14,7 @@ namespace App\Models;
  * @property        int     $auto_reset_bandwidth
  * @property        int     $status
  */
-class Shop extends Model
+final class Shop extends Model
 {
     protected $connection = 'default';
 
@@ -77,22 +77,22 @@ class Shop extends Model
         return $this->content['reset'] ?? 0;
     }
 
-    public function reset_value()
+    public function resetValue()
     {
         return $this->content['reset_value'] ?? 0;
     }
 
-    public function reset_exp()
+    public function resetExp()
     {
         return $this->content['reset_exp'] ?? 0;
     }
 
-    public function traffic_package()
+    public function trafficPackage()
     {
         return isset($this->content['traffic_package']);
     }
 
-    public function content_extra()
+    public function contentExtra()
     {
         if (isset($this->content['content_extra'])) {
             $content_extra = explode(';', $this->content['content_extra']);
@@ -110,12 +110,12 @@ class Shop extends Model
         return 0;
     }
 
-    public function user_class()
+    public function userClass()
     {
         return $this->content['class'] ?? 0;
     }
 
-    public function class_expire()
+    public function classExpire()
     {
         return $this->content['class_expire'] ?? 0;
     }
@@ -196,9 +196,9 @@ class Shop extends Model
     /*
      * 是否周期内循环重置性商品
      */
-    public function use_loop(): bool
+    public function useLoop(): bool
     {
-        return $this->reset() !== 0 && $this->reset_value() !== 0 && $this->reset_exp() !== 0;
+        return $this->reset() !== 0 && $this->resetValue() !== 0 && $this->resetExp() !== 0;
     }
 
     /*
@@ -216,7 +216,7 @@ class Shop extends Model
     /*
      * 自动续费时间
      */
-    public function auto_renew(): string
+    public function autoRenew(): string
     {
         return $this->auto_renew === 0 ? '不自动续费' : $this->auto_renew . ' 天后续费';
     }
@@ -224,7 +224,7 @@ class Shop extends Model
     /*
      * 流量是否自动重置
      */
-    public function auto_reset_bandwidth(): string
+    public function autoResetBandwidthString(): string
     {
         return $this->auto_reset_bandwidth === 0 ? '不自动重置' : '自动重置';
     }

+ 1 - 1
src/Models/StreamMedia.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class StreamMedia extends Model
+final class StreamMedia extends Model
 {
     protected $connection = 'default';
     protected $table = 'stream_media';

+ 1 - 12
src/Models/TelegramSession.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * TelegramSession Model
  */
-class TelegramSession extends Model
+final class TelegramSession extends Model
 {
     protected $connection = 'default';
     protected $table = 'telegram_session';
@@ -16,15 +16,4 @@ class TelegramSession extends Model
     {
         return date('Y-m-d H:i:s', $this->attributes['datetime']);
     }
-
-    public function User()
-    {
-        $user = User::where('id', $this->attributes['user_id'])->first();
-        if ($user === null) {
-            Ticket::where('id', '=', $this->attributes['id'])->delete();
-            return null;
-        }
-
-        return $user;
-    }
 }

+ 3 - 3
src/Models/Ticket.php

@@ -7,7 +7,7 @@ namespace App\Models;
 /**
  * Ticket Model
  */
-class Ticket extends Model
+final class Ticket extends Model
 {
     protected $connection = 'default';
 
@@ -16,7 +16,7 @@ class Ticket extends Model
     /**
      * [静态方法] 删除不存在的用户的记录
      */
-    public static function user_is_null(Ticket $Ticket): void
+    public static function userIsNull(Ticket $Ticket): void
     {
         $tickets = Ticket::where('userid', $Ticket->userid)->where('rootid', 0)->get();
         foreach ($tickets as $ticket) {
@@ -44,7 +44,7 @@ class Ticket extends Model
     /**
      * 用户名
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->user() === null) {
             return '用户已不存在';

+ 1 - 1
src/Models/Token.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class Token extends Model
+final class Token extends Model
 {
     protected $connection = 'default';
     protected $table = 'user_token';

+ 2 - 2
src/Models/UnblockIp.php

@@ -6,7 +6,7 @@ namespace App\Models;
 
 use App\Utils\QQWry;
 
-class UnblockIp extends Model
+final class UnblockIp extends Model
 {
     protected $connection = 'default';
 
@@ -23,7 +23,7 @@ class UnblockIp extends Model
     /**
      * 用户名
      */
-    public function user_name(): string
+    public function userName(): string
     {
         if ($this->user() === null) {
             return '用户已不存在';

+ 42 - 34
src/Models/User.php

@@ -5,10 +5,15 @@ declare(strict_types=1);
 namespace App\Models;
 
 use App\Controllers\LinkController;
-use Config;
+use App\Services\Config;
+use App\Services\Mail;
+use App\Utils\GA;
+use App\Utils\Hash;
+use App\Utils\Telegram;
+use App\Utils\Tools;
+use App\Utils\URL;
 use Exception;
 use Ramsey\Uuid\Uuid;
-use Tools;
 
 /**
  * User Model
@@ -21,7 +26,7 @@ use Tools;
  * @property        bool    $expire_notified    If user is notified for expire
  * @property        bool    $traffic_notified   If user is noticed for low traffic
  */
-class User extends Model
+final class User extends Model
 {
     /**
      * 已登录
@@ -64,7 +69,7 @@ class User extends Model
     /**
      * 联系方式类型
      */
-    public function im_type(): string
+    public function imType(): string
     {
         switch ($this->im_type) {
             case 1:
@@ -81,7 +86,7 @@ class User extends Model
     /**
      * 联系方式
      */
-    public function im_value(): string
+    public function imValue(): string
     {
         switch ($this->im_type) {
             case 1:
@@ -138,12 +143,12 @@ class User extends Model
         return $this->save();
     }
 
-    public function get_forbidden_ip()
+    public function getForbiddenIp()
     {
         return str_replace(',', PHP_EOL, $this->forbidden_ip);
     }
 
-    public function get_forbidden_port()
+    public function getForbiddenPort()
     {
         return str_replace(',', PHP_EOL, $this->forbidden_port);
     }
@@ -169,7 +174,7 @@ class User extends Model
             $return['msg'] = '非法输入';
             return $return;
         }
-        if (! Tools::is_param_validate('method', $method)) {
+        if (! Tools::isParamValidate('method', $method)) {
             $return['msg'] = '加密无效';
             return $return;
         }
@@ -297,7 +302,7 @@ class User extends Model
     /*
      * 今天使用的流量[自动单位]
      */
-    public function TodayusedTraffic(): string
+    public function todayUsedTraffic(): string
     {
         return Tools::flowAutoShow($this->u + $this->d - $this->last_day_t);
     }
@@ -305,7 +310,7 @@ class User extends Model
     /*
      * 今天使用的流量占总流量的百分比
      */
-    public function TodayusedTrafficPercent(): int
+    public function todayUsedTrafficPercent(): int
     {
         if ($this->transfer_enable === 0) {
             return 0;
@@ -319,7 +324,7 @@ class User extends Model
     /*
      * 今天之前已使用的流量[自动单位]
      */
-    public function LastusedTraffic(): string
+    public function lastUsedTraffic(): string
     {
         return Tools::flowAutoShow($this->last_day_t);
     }
@@ -327,7 +332,7 @@ class User extends Model
     /*
      * 今天之前已使用的流量占总流量的百分比
      */
-    public function LastusedTrafficPercent(): int
+    public function lastUsedTrafficPercent(): int
     {
         if ($this->transfer_enable === 0) {
             return 0;
@@ -366,7 +371,7 @@ class User extends Model
     /**
      * 用户的邀请人
      */
-    public function ref_by_user(): ?User
+    public function refByUser(): ?User
     {
         return self::find($this->ref_by);
     }
@@ -374,21 +379,24 @@ class User extends Model
     /**
      * 用户邀请人的用户名
      */
-    public function ref_by_user_name(): string
+    public function refByUserName(): string
     {
         if ($this->ref_by === 0) {
             return '系统邀请';
         }
-        if ($this->ref_by_user() === null) {
+
+        $refUser = $this->refByUser();
+
+        if ($refUser === null) {
             return '邀请人已经被删除';
         }
-        return $this->ref_by_user()->user_name;
+        return $refUser->user_name;
     }
 
     /**
      * 删除用户的订阅链接
      */
-    public function clean_link(): void
+    public function cleanLink(): void
     {
         Link::where('userid', $this->id)->delete();
     }
@@ -398,13 +406,13 @@ class User extends Model
      */
     public function getSublink()
     {
-        return LinkController::GenerateSSRSubCode($this->id);
+        return LinkController::generateSSRSubCode($this->id);
     }
 
     /**
      * 删除用户的邀请码
      */
-    public function clear_inviteCodes(): void
+    public function clearInviteCodes(): void
     {
         InviteCode::where('user_id', $this->id)->delete();
     }
@@ -412,7 +420,7 @@ class User extends Model
     /**
      * 在线 IP 个数
      */
-    public function online_ip_count(): int
+    public function onlineIpCount(): int
     {
         // 根据 IP 分组去重
         $total = Ip::where('datetime', '>=', time() - 90)->where('userid', $this->id)->orderBy('userid', 'desc')->groupBy('ip')->get();
@@ -430,7 +438,7 @@ class User extends Model
     /**
      * 销户
      */
-    public function kill_user(): bool
+    public function killUser(): bool
     {
         $uid = $this->id;
         $email = $this->email;
@@ -458,7 +466,7 @@ class User extends Model
     /**
      * 累计充值金额
      */
-    public function get_top_up(): float
+    public function getTopUp(): float
     {
         $number = Code::where('userid', $this->id)->sum('number');
         return is_null($number) ? 0.00 : round($number, 2);
@@ -513,7 +521,7 @@ class User extends Model
     /**
      * 最后一次被封禁的时间
      */
-    public function last_detect_ban_time(): string
+    public function lastDetectBanTime(): string
     {
         return $this->last_detect_ban_time === '1989-06-04 00:05:00' ? '未被封禁过' : $this->last_detect_ban_time;
     }
@@ -521,7 +529,7 @@ class User extends Model
     /**
      * 当前解封时间
      */
-    public function relieve_time(): string
+    public function relieveTime(): string
     {
         $logs = DetectBanLog::where('user_id', $this->id)->orderBy('id', 'desc')->first();
         if ($this->enable === 0 && $logs !== null) {
@@ -534,7 +542,7 @@ class User extends Model
     /**
      * 累计被封禁的次数
      */
-    public function detect_ban_number(): int
+    public function detectBanNumber(): int
     {
         return DetectBanLog::where('user_id', $this->id)->count();
     }
@@ -542,7 +550,7 @@ class User extends Model
     /**
      * 最后一次封禁的违规次数
      */
-    public function user_detect_ban_number(): int
+    public function userDetectBanNumber(): int
     {
         $logs = DetectBanLog::where('user_id', $this->id)->orderBy('id', 'desc')->first();
         return $logs->detect_number;
@@ -585,7 +593,7 @@ class User extends Model
             $return['msg'] = '非法输入';
             return $return;
         }
-        if (! Tools::is_param_validate('protocol', $Protocol)) {
+        if (! Tools::isParamValidate('protocol', $Protocol)) {
             $return['ok'] = false;
             $return['msg'] = '协议无效';
             return $return;
@@ -627,7 +635,7 @@ class User extends Model
             $return['msg'] = '非法输入';
             return $return;
         }
-        if (! Tools::is_param_validate('obfs', $Obfs)) {
+        if (! Tools::isParamValidate('obfs', $Obfs)) {
             $return['ok'] = false;
             $return['msg'] = '混淆无效';
             return $return;
@@ -653,7 +661,7 @@ class User extends Model
     /**
      * 解绑 Telegram
      */
-    public function TelegramReset(): array
+    public function telegramReset(): array
     {
         $return = [
             'ok' => true,
@@ -712,7 +720,7 @@ class User extends Model
     /**
      * 重置端口
      */
-    public function ResetPort(): array
+    public function resetPort(): array
     {
         $price = $_ENV['port_price'];
         if ($this->money < $price) {
@@ -734,7 +742,7 @@ class User extends Model
     /**
      * 指定端口
      */
-    public function SpecifyPort(int $Port): array
+    public function specifyPort(int $Port): array
     {
         $price = $_ENV['port_price_specify'];
         if ($this->money < $price) {
@@ -768,14 +776,14 @@ class User extends Model
     /**
      * 用户下次流量重置时间
      */
-    public function valid_use_loop(): string
+    public function validUseLoop(): string
     {
         $boughts = Bought::where('userid', $this->id)->orderBy('id', 'desc')->get();
         $data = [];
         foreach ($boughts as $bought) {
             $shop = $bought->shop();
             if ($shop !== null && $bought->valid()) {
-                $data[] = $bought->reset_time();
+                $data[] = $bought->resetTime();
             }
         }
         if (count($data) === 0) {
@@ -857,7 +865,7 @@ class User extends Model
     {
         $result = false;
         if ($this->telegram_id > 0) {
-            Telegram::Send(
+            Telegram::send(
                 $text,
                 $this->telegram_id
             );

+ 1 - 1
src/Models/UserHourlyUsage.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-class UserHourlyUsage extends Model
+final class UserHourlyUsage extends Model
 {
     protected $connection = 'default';
     protected $table = 'user_hourly_usage';

+ 2 - 2
src/Models/UserSubscribeLog.php

@@ -7,7 +7,7 @@ namespace App\Models;
 use App\Utils\QQWry;
 use voku\helper\AntiXSS;
 
-class UserSubscribeLog extends Model
+final class UserSubscribeLog extends Model
 {
     protected $connection = 'default';
 
@@ -16,7 +16,7 @@ class UserSubscribeLog extends Model
     /**
      * [静态方法] 删除不存在的用户的记录
      */
-    public static function user_is_null(UserSubscribeLog $UserSubscribeLog): void
+    public static function userIsNull(UserSubscribeLog $UserSubscribeLog): void
     {
         self::where('user_id', $UserSubscribeLog->user_id)->delete();
     }

+ 1 - 1
src/Services/Analytic.php

@@ -7,7 +7,7 @@ namespace App\Services;
 use App\Models\User;
 use App\Utils\Tools;
 
-class Analytic
+final class Analytic
 {
     public function userCount()
     {

+ 1 - 1
src/Services/Analytics.php

@@ -8,7 +8,7 @@ use App\Models\Node;
 use App\Models\User;
 use App\Utils\Tools;
 
-class Analytics
+final class Analytics
 {
     public function getTotalUser()
     {

+ 2 - 2
src/Services/Auth.php

@@ -4,9 +4,9 @@ declare(strict_types=1);
 
 namespace App\Services;
 
-class Auth
+final class Auth
 {
-    protected $user;
+    private $user;
 
     public static function login($uid, $time): void
     {

+ 3 - 1
src/Services/Auth/Base.php

@@ -4,11 +4,13 @@ declare(strict_types=1);
 
 namespace App\Services\Auth;
 
+use App\Models\User;
+
 abstract class Base
 {
     abstract public function login($uid, $time): void;
 
     abstract public function logout(): void;
 
-    abstract public function getUser(): void;
+    abstract public function getUser(): User;
 }

+ 2 - 2
src/Services/Auth/Cookie.php

@@ -9,7 +9,7 @@ use App\Models\User;
 use App\Utils;
 use App\Utils\Hash;
 
-class Cookie extends Base
+final class Cookie extends Base
 {
     public function login($uid, $time): void
     {
@@ -25,7 +25,7 @@ class Cookie extends Base
         ], $expire_in);
     }
 
-    public function getUser()
+    public function getUser(): User
     {
         $uid = Utils\Cookie::get('uid');
         $email = Utils\Cookie::get('email');

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff