Browse Source

refactor: add model value hint & rename setting to config

Fuck you and your stupid model name
M1Screw 1 year ago
parent
commit
b70dcedea6
92 changed files with 714 additions and 575 deletions
  1. 14 14
      composer.lock
  2. 16 16
      db/migrations/2023020100-init.php
  3. 1 0
      phpinsights.php
  4. 16 16
      src/Command/Cron.php
  5. 2 2
      src/Command/Migration.php
  6. 8 8
      src/Command/Tool.php
  7. 3 5
      src/Controllers/Admin/AnnController.php
  8. 7 7
      src/Controllers/Admin/NodeController.php
  9. 5 5
      src/Controllers/Admin/Setting/BillingController.php
  10. 3 3
      src/Controllers/Admin/Setting/CaptchaController.php
  11. 4 4
      src/Controllers/Admin/Setting/CronController.php
  12. 3 3
      src/Controllers/Admin/Setting/EmailController.php
  13. 3 3
      src/Controllers/Admin/Setting/FeatureController.php
  14. 3 3
      src/Controllers/Admin/Setting/ImController.php
  15. 3 3
      src/Controllers/Admin/Setting/RefController.php
  16. 3 3
      src/Controllers/Admin/Setting/RegController.php
  17. 3 3
      src/Controllers/Admin/Setting/SubController.php
  18. 3 3
      src/Controllers/Admin/Setting/SupportController.php
  19. 3 3
      src/Controllers/Admin/SystemController.php
  20. 18 18
      src/Controllers/AuthController.php
  21. 2 2
      src/Controllers/CallbackController.php
  22. 12 12
      src/Controllers/OAuthController.php
  23. 4 4
      src/Controllers/PasswordController.php
  24. 4 4
      src/Controllers/SubController.php
  25. 5 5
      src/Controllers/User/DocsController.php
  26. 4 5
      src/Controllers/User/InfoController.php
  27. 7 7
      src/Controllers/User/TicketController.php
  28. 4 4
      src/Controllers/UserController.php
  29. 6 6
      src/Models/Ann.php
  30. 16 3
      src/Models/Config.php
  31. 16 0
      src/Models/DetectBanLog.php
  32. 11 0
      src/Models/DetectLog.php
  33. 9 1
      src/Models/DetectRule.php
  34. 7 7
      src/Models/Docs.php
  35. 9 1
      src/Models/EmailQueue.php
  36. 13 0
      src/Models/GiftCard.php
  37. 10 2
      src/Models/InviteCode.php
  38. 15 0
      src/Models/Invoice.php
  39. 9 0
      src/Models/Link.php
  40. 10 3
      src/Models/LoginIp.php
  41. 29 0
      src/Models/Node.php
  42. 8 18
      src/Models/OnlineLog.php
  43. 17 0
      src/Models/Order.php
  44. 13 2
      src/Models/Payback.php
  45. 14 0
      src/Models/Paylist.php
  46. 17 0
      src/Models/Product.php
  47. 12 1
      src/Models/SubscribeLog.php
  48. 11 1
      src/Models/Ticket.php
  49. 55 0
      src/Models/User.php
  50. 12 0
      src/Models/UserCoupon.php
  51. 11 0
      src/Models/UserHourlyUsage.php
  52. 12 0
      src/Models/UserMoneyLog.php
  53. 14 13
      src/Services/Bot/Telegram/Callback.php
  54. 4 4
      src/Services/Bot/Telegram/Commands/CheckinCommand.php
  55. 4 4
      src/Services/Bot/Telegram/Commands/HelpCommand.php
  56. 4 4
      src/Services/Bot/Telegram/Commands/MyCommand.php
  57. 2 2
      src/Services/Bot/Telegram/Commands/PingCommand.php
  58. 2 2
      src/Services/Bot/Telegram/Commands/StartCommand.php
  59. 3 3
      src/Services/Bot/Telegram/Commands/UnbindCommand.php
  60. 8 8
      src/Services/Bot/Telegram/Message.php
  61. 2 2
      src/Services/Bot/Telegram/Process.php
  62. 11 0
      src/Services/Cache.php
  63. 8 8
      src/Services/Captcha.php
  64. 0 75
      src/Services/Config.php
  65. 12 12
      src/Services/Cron.php
  66. 17 1
      src/Services/DB.php
  67. 5 5
      src/Services/Detect.php
  68. 3 3
      src/Services/Gateway/AbstractPayment.php
  69. 2 2
      src/Services/Gateway/AopF2F.php
  70. 5 5
      src/Services/Gateway/Epay.php
  71. 3 3
      src/Services/Gateway/Epay/EpayTool.php
  72. 4 4
      src/Services/Gateway/PayPal.php
  73. 7 7
      src/Services/Gateway/StripeCard.php
  74. 2 2
      src/Services/IM/Discord.php
  75. 2 2
      src/Services/IM/Slack.php
  76. 6 6
      src/Services/IM/Telegram.php
  77. 2 2
      src/Services/Mail.php
  78. 2 2
      src/Services/Mail/Mailgun.php
  79. 2 2
      src/Services/Mail/Postal.php
  80. 2 2
      src/Services/Mail/SendGrid.php
  81. 3 3
      src/Services/Mail/Ses.php
  82. 2 2
      src/Services/Mail/Smtp.php
  83. 2 2
      src/Services/Password.php
  84. 4 4
      src/Services/RateLimit.php
  85. 2 2
      src/Services/Subscribe/SIP002.php
  86. 2 2
      src/Services/Subscribe/SIP008.php
  87. 2 2
      src/Services/Subscribe/SS.php
  88. 2 2
      src/Services/Subscribe/Trojan.php
  89. 2 2
      src/Services/Subscribe/V2Ray.php
  90. 24 3
      src/Services/View.php
  91. 26 8
      src/Utils/Tools.php
  92. 0 148
      tests/App/Services/ConfigTest.php

+ 14 - 14
composer.lock

@@ -123,16 +123,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.283.16",
+            "version": "3.283.17",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "cb629771356d6a4d12bb030a072b832044440672"
+                "reference": "b1a52f85e9eb3952d8f1909d5404849fc2f2af4e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/cb629771356d6a4d12bb030a072b832044440672",
-                "reference": "cb629771356d6a4d12bb030a072b832044440672",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/b1a52f85e9eb3952d8f1909d5404849fc2f2af4e",
+                "reference": "b1a52f85e9eb3952d8f1909d5404849fc2f2af4e",
                 "shasum": ""
             },
             "require": {
@@ -212,9 +212,9 @@
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.283.16"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.283.17"
             },
-            "time": "2023-10-31T18:21:09+00:00"
+            "time": "2023-11-01T18:11:41+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -1237,7 +1237,7 @@
         },
         {
             "name": "illuminate/collections",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/collections.git",
@@ -1292,7 +1292,7 @@
         },
         {
             "name": "illuminate/conditionable",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/conditionable.git",
@@ -1338,7 +1338,7 @@
         },
         {
             "name": "illuminate/container",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/container.git",
@@ -1389,7 +1389,7 @@
         },
         {
             "name": "illuminate/contracts",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/contracts.git",
@@ -1437,7 +1437,7 @@
         },
         {
             "name": "illuminate/database",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/database.git",
@@ -1506,7 +1506,7 @@
         },
         {
             "name": "illuminate/macroable",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/macroable.git",
@@ -1552,7 +1552,7 @@
         },
         {
             "name": "illuminate/pagination",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/pagination.git",
@@ -1602,7 +1602,7 @@
         },
         {
             "name": "illuminate/support",
-            "version": "v10.30.0",
+            "version": "v10.30.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/illuminate/support.git",

+ 16 - 16
db/migrations/2023020100-init.php

@@ -18,25 +18,25 @@ return new class() implements MigrationInterface {
 
             CREATE TABLE `config` (
                 `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
-                `item` varchar(255) DEFAULT NULL COMMENT '项',
-                `value` varchar(2048) DEFAULT NULL COMMENT '值',
-                `class` varchar(255) DEFAULT 'default' COMMENT '配置类',
+                `item` varchar(255) DEFAULT NULL COMMENT '配置项',
+                `value` varchar(2048) DEFAULT NULL COMMENT '配置值',
+                `class` varchar(255) DEFAULT 'default' COMMENT '配置类',
                 `is_public` int(11) DEFAULT 0 COMMENT '是否为公共参数',
-                `type` varchar(255) DEFAULT NULL COMMENT '值类型',
+                `type` varchar(255) DEFAULT NULL COMMENT '配置值类型',
                 `default` varchar(255) DEFAULT NULL COMMENT '默认值',
                 `mark` varchar(255) DEFAULT NULL COMMENT '备注',
                 PRIMARY KEY (`id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
             CREATE TABLE `detect_ban_log` (
-                `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
+                `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '封禁记录ID',
                 `user_name` varchar(255) NOT NULL DEFAULT '' COMMENT '用户名',
                 `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
                 `email` varchar(255) NOT NULL DEFAULT '' COMMENT '用户邮箱',
                 `detect_number` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '本次违规次数',
-                `ban_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '本次封禁时长',
-                `start_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '统计开始时间',
-                `end_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '统计结束时间',
+                `ban_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '封禁时长',
+                `start_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '封禁开始时间',
+                `end_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '封禁结束时间',
                 `all_detect_number` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '累计违规次数',
                 PRIMARY KEY (`id`),
                 KEY `user_id` (`user_id`)
@@ -45,14 +45,14 @@ return new class() implements MigrationInterface {
             CREATE TABLE `detect_list` (
                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '审计规则ID',
                 `name` varchar(255) NOT NULL DEFAULT '' COMMENT '规则名称',
-                `text` varchar(255) NOT NULL DEFAULT '' COMMENT '规则名称',
+                `text` varchar(255) NOT NULL DEFAULT '' COMMENT '规则介绍',
                 `regex` varchar(255) NOT NULL DEFAULT '' COMMENT '正则表达式',
                 `type` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '规则类型',
                 PRIMARY KEY (`id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
             CREATE TABLE `detect_log` (
-                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '审计记录ID',
                 `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
                 `list_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '规则ID',
                 `datetime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '触发时间',
@@ -65,7 +65,7 @@ return new class() implements MigrationInterface {
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
             CREATE TABLE `docs` (
-                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '文档ID',
                 `date` datetime NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '文档日期',
                 `title` varchar(255) NOT NULL DEFAULT '' COMMENT '文档标题',
                 `content` longtext NOT NULL DEFAULT '' COMMENT '文档内容',
@@ -75,7 +75,7 @@ return new class() implements MigrationInterface {
             CREATE TABLE `email_queue` (
                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
                 `to_email` varchar(255) NOT NULL DEFAULT '' COMMENT '收件人邮箱',
-                `subject` varchar(255) NOT NULL DEFAULT '' COMMENT '邮件题',
+                `subject` varchar(255) NOT NULL DEFAULT '' COMMENT '邮件题',
                 `template` varchar(255) NOT NULL DEFAULT '' COMMENT '邮件模板',
                 `array` longtext NOT NULL DEFAULT '{}' COMMENT '模板参数' CHECK (json_valid(`array`)),
                 `time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '添加时间',
@@ -97,7 +97,7 @@ return new class() implements MigrationInterface {
 
             CREATE TABLE `invoice` (
                 `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '账单ID',
-                `user_id` bigint(20) unsigned DEFAULT 0 COMMENT '归属用户',
+                `user_id` bigint(20) unsigned DEFAULT 0 COMMENT '归属用户ID',
                 `order_id` bigint(20) unsigned DEFAULT 0 COMMENT '订单ID',
                 `content` longtext DEFAULT '{}' COMMENT '账单内容' CHECK (json_valid(`content`)),
                 `price` double unsigned DEFAULT 0 COMMENT '账单金额',
@@ -178,7 +178,7 @@ return new class() implements MigrationInterface {
 
             CREATE TABLE `order` (
                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',
-                `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '提交用户',
+                `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '提交用户ID',
                 `product_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '商品ID',
                 `product_type` varchar(255) NOT NULL DEFAULT '' COMMENT '商品类型',
                 `product_name` varchar(255) NOT NULL DEFAULT '' COMMENT '商品名称',
@@ -228,7 +228,7 @@ return new class() implements MigrationInterface {
                 `status` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT '销售状态',
                 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 `update_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '更新时间',
-                `sale_count` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '累计销售数',
+                `sale_count` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '累计销',
                 `stock` int(11) NOT NULL DEFAULT -1 COMMENT '库存',
                 PRIMARY KEY (`id`),
                 KEY `id` (`id`),
@@ -241,7 +241,7 @@ return new class() implements MigrationInterface {
                 `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
                 `type` varchar(255) NOT NULL DEFAULT '' COMMENT '获取的订阅类型',
                 `request_ip` varchar(255) NOT NULL DEFAULT '' COMMENT '请求IP',
-                `request_user_agent` varchar(255) NOT NULL DEFAULT '' COMMENT '请求UA信息',
+                `request_user_agent` varchar(255) NOT NULL DEFAULT '' COMMENT '请求UA',
                 `request_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '请求时间',
                 PRIMARY KEY (`id`),
                 KEY `user_id` (`user_id`)

+ 1 - 0
phpinsights.php

@@ -10,6 +10,7 @@ return [
         NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineFunctions::class,
         NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineGlobalConstants::class,
         NunoMaduro\PhpInsights\Domain\Insights\ForbiddenGlobals::class,
+        PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\TodoSniff::class,
         PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff::class,
         PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\EvalSniff::class,
         PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\GlobalKeywordSniff::class,

+ 16 - 16
src/Command/Cron.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Command;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Cron as CronService;
 use App\Services\Detect;
 use Exception;
@@ -50,38 +50,38 @@ EOL;
         }
 
         // Run traffic log job
-        if ($minute === 0 && Setting::obtain('traffic_log')) {
+        if ($minute === 0 && Config::obtain('traffic_log')) {
             $jobs->addTrafficLog();
         }
 
         // Run daily job
-        if ($hour === Setting::obtain('daily_job_hour') &&
-            $minute === Setting::obtain('daily_job_minute') &&
-            time() - Setting::obtain('last_daily_job_time') > 86399
+        if ($hour === Config::obtain('daily_job_hour') &&
+            $minute === Config::obtain('daily_job_minute') &&
+            time() - Config::obtain('last_daily_job_time') > 86399
         ) {
             $jobs->cleanDb();
             $jobs->resetNodeBandwidth();
             $jobs->resetFreeUserTraffic();
             $jobs->sendDailyTrafficReport();
 
-            if (Setting::obtain('enable_detect_inactive_user')) {
+            if (Config::obtain('enable_detect_inactive_user')) {
                 $jobs->detectInactiveUser();
             }
 
-            if (Setting::obtain('telegram_diary')) {
+            if (Config::obtain('telegram_diary')) {
                 $jobs->sendTelegramDiary();
             }
 
             $jobs->resetTodayTraffic();
 
-            if (Setting::obtain('telegram_daily_job')) {
+            if (Config::obtain('telegram_daily_job')) {
                 $jobs->sendTelegramDailyJob();
             }
 
-            Setting::where('item', 'last_daily_job_time')->update([
+            Config::where('item', 'last_daily_job_time')->update([
                 'value' => mktime(
-                    Setting::obtain('daily_job_hour'),
-                    Setting::obtain('daily_job_minute'),
+                    Config::obtain('daily_job_hour'),
+                    Config::obtain('daily_job_minute'),
                     0,
                     (int) date('m'),
                     (int) date('d'),
@@ -91,7 +91,7 @@ EOL;
         }
 
         // Daily finance report
-        if (Setting::obtain('enable_daily_finance_mail')
+        if (Config::obtain('enable_daily_finance_mail')
             && $hour === 0
             && $minute === 0
         ) {
@@ -99,7 +99,7 @@ EOL;
         }
 
         // Weekly finance report
-        if (Setting::obtain('enable_weekly_finance_mail')
+        if (Config::obtain('enable_weekly_finance_mail')
             && $hour === 0
             && $minute === 0
             && date('w') === '1'
@@ -108,7 +108,7 @@ EOL;
         }
 
         // Monthly finance report
-        if (Setting::obtain('enable_monthly_finance_mail')
+        if (Config::obtain('enable_monthly_finance_mail')
             && $hour === 0
             && $minute === 0
             && date('d') === '01'
@@ -117,14 +117,14 @@ EOL;
         }
 
         // Detect GFW
-        if (Setting::obtain('enable_detect_gfw') && $minute === 0
+        if (Config::obtain('enable_detect_gfw') && $minute === 0
         ) {
             $detect = new Detect();
             $detect->gfw();
         }
 
         // Detect ban
-        if (Setting::obtain('enable_detect_ban') && $minute === 0
+        if (Config::obtain('enable_detect_ban') && $minute === 0
         ) {
             $detect = new Detect();
             $detect->ban();

+ 2 - 2
src/Command/Migration.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Command;
 
 use App\Interfaces\MigrationInterface;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\DB;
 use function count;
 use function explode;
@@ -36,7 +36,7 @@ END;
         if ($target === 'new') {
             $current = 0;
         } else {
-            $current = Setting::obtain('db_version');
+            $current = Config::obtain('db_version');
         }
 
         if ($target === 'latest') {

+ 8 - 8
src/Command/Tool.php

@@ -4,9 +4,9 @@ declare(strict_types=1);
 
 namespace App\Command;
 
+use App\Models\Config;
 use App\Models\Link;
 use App\Models\Node;
-use App\Models\Setting;
 use App\Models\User as ModelsUser;
 use App\Services\MFA;
 use App\Utils\Hash;
@@ -72,8 +72,8 @@ EOL;
      */
     public function setTelegram(): void
     {
-        $WebhookUrl = $_ENV['baseUrl'] . '/callback/telegram?token=' . Setting::obtain('telegram_request_token');
-        $telegram = new Api(Setting::obtain('telegram_token'));
+        $WebhookUrl = $_ENV['baseUrl'] . '/callback/telegram?token=' . Config::obtain('telegram_request_token');
+        $telegram = new Api(Config::obtain('telegram_token'));
         $telegram->removeWebhook();
 
         if ($telegram->setWebhook(['url' => $WebhookUrl])) {
@@ -85,7 +85,7 @@ EOL;
 
     public function resetAllSettings(): void
     {
-        $settings = Setting::all();
+        $settings = Config::all();
 
         foreach ($settings as $setting) {
             $setting->value = $setting->default;
@@ -97,7 +97,7 @@ EOL;
 
     public function exportAllSettings(): void
     {
-        $settings = Setting::all();
+        $settings = Config::all();
 
         foreach ($settings as $setting) {
             // 因为主键自增所以即便设置为 null 也会在导入时自动分配 id
@@ -126,10 +126,10 @@ EOL;
         foreach ($settings as $item) {
             $config[] = $item['item'];
             $item_name = $item['item'];
-            $query = Setting::where('item', $item['item'])->first();
+            $query = Config::where('item', $item['item'])->first();
 
             if ($query === null) {
-                $new_item = new Setting();
+                $new_item = new Config();
                 $new_item->id = null;
                 $new_item->item = $item['item'];
                 $new_item->value = $item['value'];
@@ -153,7 +153,7 @@ EOL;
             }
         }
         // 检查移除
-        $db_settings = Setting::all();
+        $db_settings = Config::all();
 
         foreach ($db_settings as $db_setting) {
             if (! in_array($db_setting->item, $config)) {

+ 3 - 5
src/Controllers/Admin/AnnController.php

@@ -6,8 +6,8 @@ namespace App\Controllers\Admin;
 
 use App\Controllers\BaseController;
 use App\Models\Ann;
+use App\Models\Config;
 use App\Models\EmailQueue;
-use App\Models\Setting;
 use App\Models\User;
 use App\Services\IM\Telegram;
 use App\Utils\Tools;
@@ -115,7 +115,7 @@ final class AnnController extends BaseController
             }
         }
 
-        if (Setting::obtain('enable_telegram')) {
+        if (Config::obtain('enable_telegram')) {
             try {
                 (new Telegram())->sendHtml(0, '新公告:' . PHP_EOL . $content);
             } catch (TelegramSDKException $e) {
@@ -149,8 +149,6 @@ final class AnnController extends BaseController
 
     /**
      * 后台编辑公告提交
-     *
-     * @throws TelegramSDKException
      */
     public function update(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
@@ -165,7 +163,7 @@ final class AnnController extends BaseController
             ]);
         }
 
-        if (Setting::obtain('enable_telegram')) {
+        if (Config::obtain('enable_telegram')) {
             try {
                 (new Telegram())->sendHtml(0, '公告更新:' . PHP_EOL . $request->getParam('content'));
             } catch (TelegramSDKException $e) {

+ 7 - 7
src/Controllers/Admin/NodeController.php

@@ -5,8 +5,8 @@ declare(strict_types=1);
 namespace App\Controllers\Admin;
 
 use App\Controllers\BaseController;
+use App\Models\Config;
 use App\Models\Node;
-use App\Models\Setting;
 use App\Services\Cloudflare;
 use App\Services\IM\Telegram;
 use App\Utils\Tools;
@@ -150,14 +150,14 @@ final class NodeController extends BaseController
             Cloudflare::updateRecord($domain_name[0], $node->node_ip);
         }
 
-        if (Setting::obtain('telegram_add_node')) {
+        if (Config::obtain('telegram_add_node')) {
             try {
                 (new Telegram())->send(
                     0,
                     str_replace(
                         '%node_name%',
                         $request->getParam('name'),
-                        Setting::obtain('telegram_add_node_text')
+                        Config::obtain('telegram_add_node_text')
                     )
                 );
             } catch (Exception $e) {
@@ -263,14 +263,14 @@ final class NodeController extends BaseController
             Cloudflare::updateRecord($domain_name[0], $node->node_ip);
         }
 
-        if (Setting::obtain('telegram_update_node')) {
+        if (Config::obtain('telegram_update_node')) {
             try {
                 (new Telegram())->send(
                     0,
                     str_replace(
                         '%node_name%',
                         $request->getParam('name'),
-                        Setting::obtain('telegram_update_node_text')
+                        Config::obtain('telegram_update_node_text')
                     )
                 );
             } catch (Exception $e) {
@@ -321,14 +321,14 @@ final class NodeController extends BaseController
             ]);
         }
 
-        if (Setting::obtain('telegram_delete_node')) {
+        if (Config::obtain('telegram_delete_node')) {
             try {
                 (new Telegram())->send(
                     0,
                     str_replace(
                         '%node_name%',
                         $node->name,
-                        Setting::obtain('telegram_delete_node_text')
+                        Config::obtain('telegram_delete_node_text')
                     )
                 );
             } catch (Exception $e) {

+ 5 - 5
src/Controllers/Admin/Setting/BillingController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Payment;
 use Exception;
 use function json_decode;
@@ -52,7 +52,7 @@ final class BillingController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('billing');
+        $settings = Config::getClass('billing');
 
         return $response->write(
             $this->view()
@@ -75,7 +75,7 @@ final class BillingController extends BaseController
             }
         }
 
-        $gateway = Setting::where('item', 'payment_gateway')->first();
+        $gateway = Config::where('item', 'payment_gateway')->first();
         $gateway->value = json_encode($gateway_in_use);
 
         if (! $gateway->save()) {
@@ -86,7 +86,7 @@ final class BillingController extends BaseController
         }
 
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',
@@ -113,7 +113,7 @@ final class BillingController extends BaseController
 
     public function returnActiveGateways()
     {
-        $payment_gateways = Setting::where('item', 'payment_gateway')->first();
+        $payment_gateways = Config::where('item', 'payment_gateway')->first();
         return json_decode($payment_gateways->value);
     }
 }

+ 3 - 3
src/Controllers/Admin/Setting/CaptchaController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class CaptchaController extends BaseController
@@ -29,7 +29,7 @@ final class CaptchaController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('captcha');
+        $settings = Config::getClass('captcha');
 
         return $response->write(
             $this->view()
@@ -42,7 +42,7 @@ final class CaptchaController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 4 - 4
src/Controllers/Admin/Setting/CronController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class CronController extends BaseController
@@ -29,7 +29,7 @@ final class CronController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('cron');
+        $settings = Config::getClass('cron');
 
         return $response->write(
             $this->view()
@@ -60,11 +60,11 @@ final class CronController extends BaseController
 
         foreach (self::$update_field as $item) {
             if ($item === 'daily_job_minute') {
-                Setting::set($item, $daily_job_minute - ($daily_job_minute % 5));
+                Config::set($item, $daily_job_minute - ($daily_job_minute % 5));
                 continue;
             }
 
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/EmailController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Mail;
 use Exception;
 use Throwable;
@@ -53,7 +53,7 @@ final class EmailController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('email');
+        $settings = Config::getClass('email');
 
         return $response->write(
             $this->view()
@@ -66,7 +66,7 @@ final class EmailController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/FeatureController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class FeatureController extends BaseController
@@ -28,7 +28,7 @@ final class FeatureController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('feature');
+        $settings = Config::getClass('feature');
 
         return $response->write(
             $this->view()
@@ -41,7 +41,7 @@ final class FeatureController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/ImController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\IM\Discord;
 use App\Services\IM\Slack;
 use App\Services\IM\Telegram;
@@ -66,7 +66,7 @@ final class ImController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('im');
+        $settings = Config::getClass('im');
 
         return $response->write(
             $this->view()
@@ -79,7 +79,7 @@ final class ImController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/RefController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class RefController extends BaseController
@@ -26,7 +26,7 @@ final class RefController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('ref');
+        $settings = Config::getClass('ref');
 
         return $response->write(
             $this->view()
@@ -39,7 +39,7 @@ final class RefController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/RegController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class RegController extends BaseController
@@ -35,7 +35,7 @@ final class RegController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('reg');
+        $settings = Config::getClass('reg');
 
         return $response->write(
             $this->view()
@@ -48,7 +48,7 @@ final class RegController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/SubController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class SubController extends BaseController
@@ -23,7 +23,7 @@ final class SubController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('subscribe');
+        $settings = Config::getClass('subscribe');
 
         return $response->write(
             $this->view()
@@ -36,7 +36,7 @@ final class SubController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/Setting/SupportController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin\Setting;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 
 final class SupportController extends BaseController
@@ -27,7 +27,7 @@ final class SupportController extends BaseController
      */
     public function index($request, $response, $args)
     {
-        $settings = Setting::getClass('support');
+        $settings = Config::getClass('support');
 
         return $response->write(
             $this->view()
@@ -40,7 +40,7 @@ final class SupportController extends BaseController
     public function save($request, $response, $args)
     {
         foreach (self::$update_field as $item) {
-            if (! Setting::set($item, $request->getParam($item))) {
+            if (! Config::set($item, $request->getParam($item))) {
                 return $response->withJson([
                     'ret' => 0,
                     'msg' => '保存 ' . $item . ' 时出错',

+ 3 - 3
src/Controllers/Admin/SystemController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Utils\Tools;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
@@ -25,8 +25,8 @@ final class SystemController extends BaseController
      */
     public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
     {
-        $last_daily_job_time = Tools::toDateTime(Setting::obtain('last_daily_job_time'));
-        $db_version = Setting::obtain('db_version');
+        $last_daily_job_time = Tools::toDateTime(Config::obtain('last_daily_job_time'));
+        $db_version = Config::obtain('db_version');
 
         return $response->write(
             $this->view()

+ 18 - 18
src/Controllers/AuthController.php

@@ -4,9 +4,9 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
+use App\Models\Config;
 use App\Models\InviteCode;
 use App\Models\LoginIp;
-use App\Models\Setting;
 use App\Models\User;
 use App\Services\Auth;
 use App\Services\Cache;
@@ -48,7 +48,7 @@ final class AuthController extends BaseController
     {
         $captcha = [];
 
-        if (Setting::obtain('enable_login_captcha')) {
+        if (Config::obtain('enable_login_captcha')) {
             $captcha = Captcha::generate();
         }
 
@@ -65,7 +65,7 @@ final class AuthController extends BaseController
      */
     public function loginHandle(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
-        if (Setting::obtain('enable_login_captcha') && ! Captcha::verify($request->getParams())) {
+        if (Config::obtain('enable_login_captcha') && ! Captcha::verify($request->getParams())) {
             return $response->withJson([
                 'ret' => 0,
                 'msg' => '系统无法接受你的验证结果,请刷新页面后重试。',
@@ -134,7 +134,7 @@ final class AuthController extends BaseController
     {
         $captcha = [];
 
-        if (Setting::obtain('enable_reg_captcha')) {
+        if (Config::obtain('enable_reg_captcha')) {
             $captcha = Captcha::generate();
         }
 
@@ -155,7 +155,7 @@ final class AuthController extends BaseController
      */
     public function sendVerify(ServerRequest $request, Response $response, $next): Response|ResponseInterface
     {
-        if (Setting::obtain('reg_email_verify')) {
+        if (Config::obtain('reg_email_verify')) {
             $antiXss = new AntiXSS();
             $email = strtolower(trim($antiXss->xss_clean($request->getParam('email'))));
 
@@ -183,7 +183,7 @@ final class AuthController extends BaseController
 
             $code = Tools::genRandomChar(6);
             $redis = Cache::initRedis();
-            $redis->setex('email_verify:' . $code, Setting::obtain('email_verify_code_ttl'), $email);
+            $redis->setex('email_verify:' . $code, Config::obtain('email_verify_code_ttl'), $email);
 
             try {
                 Mail::send(
@@ -192,7 +192,7 @@ final class AuthController extends BaseController
                     'verify_code.tpl',
                     [
                         'code' => $code,
-                        'expire' => date('Y-m-d H:i:s', time() + Setting::obtain('email_verify_code_ttl')),
+                        'expire' => date('Y-m-d H:i:s', time() + Config::obtain('email_verify_code_ttl')),
                     ]
                 );
             } catch (Exception|ClientExceptionInterface $e) {
@@ -235,7 +235,7 @@ final class AuthController extends BaseController
         $is_admin_reg
     ): ResponseInterface {
         $redir = Cookie::get('redir') ?? '/user';
-        $configs = Setting::getClass('reg');
+        $configs = Config::getClass('reg');
         // do reg user
         $user = new User();
 
@@ -250,14 +250,14 @@ final class AuthController extends BaseController
         $user->u = 0;
         $user->d = 0;
         $user->method = $configs['sign_up_for_method'];
-        $user->forbidden_ip = Setting::obtain('reg_forbidden_ip');
-        $user->forbidden_port = Setting::obtain('reg_forbidden_port');
+        $user->forbidden_ip = Config::obtain('reg_forbidden_ip');
+        $user->forbidden_port = Config::obtain('reg_forbidden_port');
         $user->im_type = $imtype;
         $user->im_value = $imvalue;
         $user->transfer_enable = Tools::toGB($configs['sign_up_for_free_traffic']);
         $user->invite_num = $configs['sign_up_for_invitation_codes'];
-        $user->auto_reset_day = Setting::obtain('free_user_reset_day');
-        $user->auto_reset_bandwidth = Setting::obtain('free_user_reset_bandwidth');
+        $user->auto_reset_day = Config::obtain('free_user_reset_day');
+        $user->auto_reset_bandwidth = Config::obtain('free_user_reset_bandwidth');
         $user->daily_mail_enable = $configs['sign_up_for_daily_report'];
 
         if ($money > 0) {
@@ -272,7 +272,7 @@ final class AuthController extends BaseController
             $invite = InviteCode::where('code', $code)->first();
             $invite->reward();
             $user->ref_by = $invite->user_id;
-            $user->money = Setting::obtain('invitation_to_register_balance_reward');
+            $user->money = Config::obtain('invitation_to_register_balance_reward');
         }
 
         $user->ga_token = MFA::generateGaToken();
@@ -285,7 +285,7 @@ final class AuthController extends BaseController
         $user->reg_ip = $_SERVER['REMOTE_ADDR'];
         $user->theme = $_ENV['theme'];
         $user->locale = $_ENV['locale'];
-        $random_group = Setting::obtain('random_group');
+        $random_group = Config::obtain('random_group');
 
         if ($random_group === '') {
             $user->node_group = 0;
@@ -321,11 +321,11 @@ final class AuthController extends BaseController
      */
     public function registerHandle(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
-        if (Setting::obtain('reg_mode') === 'close') {
+        if (Config::obtain('reg_mode') === 'close') {
             return ResponseHelper::error($response, '未开放注册。');
         }
 
-        if (Setting::obtain('enable_reg_captcha') && ! Captcha::verify($request->getParams())) {
+        if (Config::obtain('enable_reg_captcha') && ! Captcha::verify($request->getParams())) {
             return ResponseHelper::error($response, '系统无法接受你的验证结果,请刷新页面后重试。');
         }
 
@@ -341,7 +341,7 @@ final class AuthController extends BaseController
             return ResponseHelper::error($response, '请同意服务条款');
         }
         // Check Invite Code
-        if ($code === '' && Setting::obtain('reg_mode') === 'invite') {
+        if ($code === '' && Config::obtain('reg_mode') === 'invite') {
             return ResponseHelper::error($response, '邀请码不能为空');
         }
 
@@ -383,7 +383,7 @@ final class AuthController extends BaseController
             return ResponseHelper::error($response, '两次密码输入不符');
         }
 
-        if (Setting::obtain('reg_email_verify')) {
+        if (Config::obtain('reg_email_verify')) {
             $redis = Cache::initRedis();
             $email_verify_code = trim($antiXss->xss_clean($request->getParam('emailcode')));
             $email_verify = $redis->get('email_verify:' . $email_verify_code);

+ 2 - 2
src/Controllers/CallbackController.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Bot\Telegram\Process;
 use GuzzleHttp\Exception\GuzzleException;
 use MaxMind\Db\Reader\InvalidDatabaseException;
@@ -40,7 +40,7 @@ final class CallbackController extends BaseController
     {
         $token = $request->getQueryParam('token');
 
-        if (Setting::obtain('enable_telegram') && $token === Setting::obtain('telegram_request_token')) {
+        if (Config::obtain('enable_telegram') && $token === Config::obtain('telegram_request_token')) {
             Process::index($request);
             $result = '1';
         } else {

+ 12 - 12
src/Controllers/OAuthController.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Models\User;
 use App\Services\Cache;
 use App\Utils\ResponseHelper;
@@ -62,8 +62,8 @@ final class OAuthController extends BaseController
         if ($request->getParam('code') === null) {
             $state = Tools::genRandomChar(16);
             $redis->setex('slack_state:' . $user->id, 300, $state);
-            $client_id = Setting::obtain('slack_client_id');
-            $team_id = Setting::obtain('slack_team_id');
+            $client_id = Config::obtain('slack_client_id');
+            $team_id = Config::obtain('slack_team_id');
             $redirect_uri = $_ENV['baseUrl'] . '/oauth/slack';
 
             return $response->withJson([
@@ -89,8 +89,8 @@ final class OAuthController extends BaseController
         ];
 
         $code_body = [
-            'client_id' => Setting::obtain('slack_client_id'),
-            'client_secret' => Setting::obtain('slack_client_secret'),
+            'client_id' => Config::obtain('slack_client_id'),
+            'client_secret' => Config::obtain('slack_client_secret'),
             'grant_type' => 'authorization_code',
             'code' => $code,
             'redirect_uri' => $_ENV['baseUrl'] . '/oauth/slack',
@@ -135,7 +135,7 @@ final class OAuthController extends BaseController
         if ($request->getParam('code') === null) {
             $state = Tools::genRandomChar(16);
             $redis->setex('discord_state:' . $user->id, 300, $state);
-            $client_id = Setting::obtain('discord_client_id');
+            $client_id = Config::obtain('discord_client_id');
             $redirect_uri = $_ENV['baseUrl'] . '/oauth/discord';
 
             return $response->withJson([
@@ -161,8 +161,8 @@ final class OAuthController extends BaseController
         ];
 
         $code_body = [
-            'client_id' => Setting::obtain('discord_client_id'),
-            'client_secret' => Setting::obtain('discord_client_secret'),
+            'client_id' => Config::obtain('discord_client_id'),
+            'client_secret' => Config::obtain('discord_client_secret'),
             'grant_type' => 'authorization_code',
             'code' => $code,
             'redirect_uri' => $_ENV['baseUrl'] . '/oauth/discord',
@@ -205,13 +205,13 @@ final class OAuthController extends BaseController
         $user->im_value = $discord_user_id;
         $user->save();
 
-        if (Setting::obtain('discord_guild_id') !== 0) {
-            $discord_guild_url = 'https://discord.com/api/guilds/' . Setting::obtain('discord_guild_id') .
+        if (Config::obtain('discord_guild_id') !== 0) {
+            $discord_guild_url = 'https://discord.com/api/guilds/' . Config::obtain('discord_guild_id') .
                 '/members/' . $user->im_value;
 
             $guild_headers = [
                 'Content-Type' => 'application/json',
-                'Authorization' => 'Bot ' . Setting::obtain('discord_bot_token'),
+                'Authorization' => 'Bot ' . Config::obtain('discord_bot_token'),
             ];
 
             $guild_body = [
@@ -241,7 +241,7 @@ final class OAuthController extends BaseController
 
         sort($data_check_arr);
         $data_check_string = implode("\n", $data_check_arr);
-        $secret_key = hash('sha256', Setting::obtain('telegram_token'), true);
+        $secret_key = hash('sha256', Config::obtain('telegram_token'), true);
         $hash = hash_hmac('sha256', $data_check_string, $secret_key);
 
         if (strcmp($hash, $check_hash) !== 0 || (time() - $user_auth['auth_date']) > 86400) {

+ 4 - 4
src/Controllers/PasswordController.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Models\User;
 use App\Services\Cache;
 use App\Services\Captcha;
@@ -36,7 +36,7 @@ final class PasswordController extends BaseController
     {
         $captcha = [];
 
-        if (Setting::obtain('enable_reset_password_captcha')) {
+        if (Config::obtain('enable_reset_password_captcha')) {
             $captcha = Captcha::generate();
         }
 
@@ -52,7 +52,7 @@ final class PasswordController extends BaseController
      */
     public function handleReset(ServerRequest $request, Response $response, array $args): ResponseInterface
     {
-        if (Setting::obtain('enable_reset_password_captcha')) {
+        if (Config::obtain('enable_reset_password_captcha')) {
             $ret = Captcha::verify($request->getParams());
 
             if (! $ret) {
@@ -145,7 +145,7 @@ final class PasswordController extends BaseController
             return ResponseHelper::error($response, '重置失败,请重试');
         }
 
-        if (Setting::obtain('enable_forced_replacement')) {
+        if (Config::obtain('enable_forced_replacement')) {
             $user->cleanLink();
         }
 

+ 4 - 4
src/Controllers/SubController.php

@@ -4,8 +4,8 @@ declare(strict_types=1);
 
 namespace App\Controllers;
 
+use App\Models\Config;
 use App\Models\Link;
-use App\Models\Setting;
 use App\Models\SubscribeLog;
 use App\Services\RateLimit;
 use App\Services\Subscribe;
@@ -77,7 +77,7 @@ final class SubController extends BaseController
         . '; total=' . $user->transfer_enable
         . '; expire=' . strtotime($user->class_expire);
 
-        if (Setting::obtain('subscribe_log')) {
+        if (Config::obtain('subscribe_log')) {
             (new SubscribeLog())->add($user, $subtype, $request->getHeaderLine('User-Agent'));
         }
 
@@ -103,7 +103,7 @@ final class SubController extends BaseController
         $err_msg = '订阅链接无效';
 
         if (! $_ENV['Subscribe'] ||
-            ! Setting::obtain('enable_traditional_sub') ||
+            ! Config::obtain('enable_traditional_sub') ||
             'https://' . $request->getHeaderLine('Host') !== $_ENV['subUrl']
         ) {
             return ResponseHelper::error($response, $err_msg);
@@ -147,7 +147,7 @@ final class SubController extends BaseController
         }
 
         // 记录订阅日志
-        if (Setting::obtain('subscribe_log')) {
+        if (Config::obtain('subscribe_log')) {
             (new SubscribeLog())->add($user, $sub_type, $request->getHeaderLine('User-Agent'));
         }
 

+ 5 - 5
src/Controllers/User/DocsController.php

@@ -5,8 +5,8 @@ declare(strict_types=1);
 namespace App\Controllers\User;
 
 use App\Controllers\BaseController;
+use App\Models\Config;
 use App\Models\Docs;
-use App\Models\Setting;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Response;
@@ -19,8 +19,8 @@ final class DocsController extends BaseController
      */
     public function index(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
-        if (! Setting::obtain('display_docs') ||
-            (Setting::obtain('display_docs_only_for_paid_user') && $this->user->class === 0)) {
+        if (! Config::obtain('display_docs') ||
+            (Config::obtain('display_docs_only_for_paid_user') && $this->user->class === 0)) {
             return $response->withRedirect('/user');
         }
 
@@ -38,8 +38,8 @@ final class DocsController extends BaseController
      */
     public function detail(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
-        if (! Setting::obtain('display_docs') ||
-            (Setting::obtain('display_docs_only_for_paid_user') && $this->user->class === 0)) {
+        if (! Config::obtain('display_docs') ||
+            (Config::obtain('display_docs_only_for_paid_user') && $this->user->class === 0)) {
             return $response->withRedirect('/user');
         }
 

+ 4 - 5
src/Controllers/User/InfoController.php

@@ -5,11 +5,10 @@ declare(strict_types=1);
 namespace App\Controllers\User;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Models\User;
 use App\Services\Auth;
 use App\Services\Cache;
-use App\Services\Config;
 use App\Services\MFA;
 use App\Utils\Hash;
 use App\Utils\ResponseHelper;
@@ -37,7 +36,7 @@ final class InfoController extends BaseController
     public function index(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
         $themes = Tools::getDir(BASE_PATH . '/resources/views');
-        $methods = Config::getSsMethod('method');
+        $methods = Tools::getSsMethod('method');
         $ga_url = MFA::getGaUrl($this->user);
 
         return $response->write($this->view()
@@ -82,7 +81,7 @@ final class InfoController extends BaseController
             return ResponseHelper::error($response, '新邮箱不能和旧邮箱一样');
         }
 
-        if (Setting::obtain('reg_email_verify')) {
+        if (Config::obtain('reg_email_verify')) {
             $redis = Cache::initRedis();
             $email_verify_code = $request->getParam('emailcode');
             $email_verify = $redis->get('email_verify:' . $email_verify_code);
@@ -175,7 +174,7 @@ final class InfoController extends BaseController
             return ResponseHelper::error($response, '修改失败');
         }
 
-        if (Setting::obtain('enable_forced_replacement')) {
+        if (Config::obtain('enable_forced_replacement')) {
             $user->cleanLink();
         }
 

+ 7 - 7
src/Controllers/User/TicketController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\User;
 
 use App\Controllers\BaseController;
-use App\Models\Setting;
+use App\Models\Config;
 use App\Models\Ticket;
 use App\Services\Notification;
 use App\Services\RateLimit;
@@ -37,7 +37,7 @@ final class TicketController extends BaseController
      */
     public function index(ServerRequest $request, Response $response, array $args): ?ResponseInterface
     {
-        if (! Setting::obtain('enable_ticket')) {
+        if (! Config::obtain('enable_ticket')) {
             return $response->withRedirect('/user');
         }
 
@@ -68,7 +68,7 @@ final class TicketController extends BaseController
         $comment = $request->getParam('comment') ?? '';
         $type = $request->getParam('type') ?? '';
 
-        if (! Setting::obtain('enable_ticket') ||
+        if (! Config::obtain('enable_ticket') ||
             $this->user->is_shadow_banned ||
             ! RateLimit::checkTicketLimit($this->user->id) ||
             $title === '' ||
@@ -101,7 +101,7 @@ final class TicketController extends BaseController
         $ticket->type = $antiXss->xss_clean($type);
         $ticket->save();
 
-        if (Setting::obtain('mail_ticket')) {
+        if (Config::obtain('mail_ticket')) {
             Notification::notifyAdmin(
                 $_ENV['appName'] . '-新工单被开启',
                 '管理员,有人开启了新的工单,请你及时处理。'
@@ -124,7 +124,7 @@ final class TicketController extends BaseController
         $id = $args['id'];
         $comment = $request->getParam('comment') ?? '';
 
-        if (! Setting::obtain('enable_ticket') ||
+        if (! Config::obtain('enable_ticket') ||
             $this->user->is_shadow_banned ||
             $comment === ''
         ) {
@@ -159,7 +159,7 @@ final class TicketController extends BaseController
         $ticket->status = 'open_wait_admin';
         $ticket->save();
 
-        if (Setting::obtain('mail_ticket')) {
+        if (Config::obtain('mail_ticket')) {
             Notification::notifyAdmin(
                 $_ENV['appName'] . '-工单被回复',
                 '管理员,有人回复了 <a href="' .
@@ -179,7 +179,7 @@ final class TicketController extends BaseController
      */
     public function detail(ServerRequest $request, Response $response, array $args): ResponseInterface
     {
-        if (! Setting::obtain('enable_ticket')) {
+        if (! Config::obtain('enable_ticket')) {
             return $response->withRedirect('/user');
         }
 

+ 4 - 4
src/Controllers/UserController.php

@@ -5,12 +5,12 @@ declare(strict_types=1);
 namespace App\Controllers;
 
 use App\Models\Ann;
+use App\Models\Config;
 use App\Models\InviteCode;
 use App\Models\LoginIp;
 use App\Models\Node;
 use App\Models\OnlineLog;
 use App\Models\Payback;
-use App\Models\Setting;
 use App\Services\Auth;
 use App\Services\Captcha;
 use App\Utils\ResponseHelper;
@@ -37,7 +37,7 @@ final class UserController extends BaseController
         $class_expire_days = $this->user->class > 0 ?
             round((strtotime($this->user->class_expire) - time()) / 86400) : 0;
 
-        if (Setting::obtain('enable_checkin_captcha')) {
+        if (Config::obtain('enable_checkin_captcha')) {
             $captcha = Captcha::generate();
         }
 
@@ -128,7 +128,7 @@ final class UserController extends BaseController
         }
 
         $invite_url = $_ENV['baseUrl'] . '/auth/register?code=' . $code;
-        $rebate_ratio_per = Setting::obtain('rebate_ratio') * 100;
+        $rebate_ratio_per = Config::obtain('rebate_ratio') * 100;
 
         return $response->write($this->view()
             ->assign('paybacks', $paybacks)
@@ -144,7 +144,7 @@ final class UserController extends BaseController
             return ResponseHelper::error($response, '暂时还不能签到');
         }
 
-        if (Setting::obtain('enable_checkin_captcha')) {
+        if (Config::obtain('enable_checkin_captcha')) {
             $ret = Captcha::verify($request->getParams());
 
             if (! $ret) {

+ 6 - 6
src/Models/Ann.php

@@ -4,14 +4,14 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
 /**
- * Ann Model
- *
- * @property-read   int    $id         Announcement ID
+ * @property int    $id         公告ID
+ * @property string $date       公告日期
+ * @property string $content    公告内容
  *
- * @property        string $date       Date announcement posted
- * @property        string $content    Announcement in HTML
- * @property        string $markdown   Announcement in MarkDown
+ * @mixin Builder
  */
 final class Ann extends Model
 {

+ 16 - 3
src/Models/Setting.php → src/Models/Config.php

@@ -4,7 +4,20 @@ declare(strict_types=1);
 
 namespace App\Models;
 
-final class Setting extends Model
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id         配置ID
+ * @property string $item       配置项
+ * @property string $value      配置值
+ * @property string $class      配置类别
+ * @property string $is_public  是否为公共参数
+ * @property string $default    默认值
+ * @property string $mark       备注
+ *
+ * @mixin Builder
+ */
+final class Config extends Model
 {
     protected $connection = 'default';
     protected $table = 'config';
@@ -23,7 +36,7 @@ final class Setting extends Model
     public static function getClass($class): array
     {
         $configs = [];
-        $all_configs = Setting::where('class', $class)->get();
+        $all_configs = self::where('class', $class)->get();
 
         foreach ($all_configs as $config) {
             if ($config->type === 'bool') {
@@ -41,7 +54,7 @@ final class Setting extends Model
     public static function getPublicConfig(): array
     {
         $configs = [];
-        $all_configs = Setting::where('is_public', '1')->get();
+        $all_configs = self::where('is_public', '1')->get();
 
         foreach ($all_configs as $config) {
             if ($config->type === 'bool') {

+ 16 - 0
src/Models/DetectBanLog.php

@@ -5,7 +5,23 @@ declare(strict_types=1);
 namespace App\Models;
 
 use App\Utils\Tools;
+use Illuminate\Database\Query\Builder;
 
+/**
+ * @property int    $id                封禁记录ID
+ * todo: delete this
+ * @property string $user_name         用户名
+ * @property int    $user_id           用户ID
+ * todo: delete this as well
+ * @property string $email             用户邮箱
+ * @property int    $detect_number     本次违规次数
+ * @property int    $ban_time          封禁时长
+ * @property int    $start_time        封禁开始时间
+ * @property int    $end_time          封禁结束时间
+ * @property int    $all_detect_number 累计违规次数
+ *
+ * @mixin Builder
+ */
 final class DetectBanLog extends Model
 {
     protected $connection = 'default';

+ 11 - 0
src/Models/DetectLog.php

@@ -5,7 +5,18 @@ declare(strict_types=1);
 namespace App\Models;
 
 use App\Utils\Tools;
+use Illuminate\Database\Query\Builder;
 
+/**
+ * @property int $id       检测记录ID
+ * @property int $user_id  用户ID
+ * @property int $list_id  规则ID
+ * @property int $datetime 检测时间
+ * @property int $node_id  节点ID
+ * @property int $status   状态
+ *
+ * @mixin Builder
+ */
 final class DetectLog extends Model
 {
     protected $connection = 'default';

+ 9 - 1
src/Models/DetectRule.php

@@ -4,8 +4,16 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
 /**
- * DetectLog Model
+ * @property int    $id    审计规则ID
+ * @property string $name  规则名称
+ * @property string $text  规则介绍
+ * @property string $regex 规则内容
+ * @property int    $type  规则类型
+ *
+ * @mixin Builder
  */
 final class DetectRule extends Model
 {

+ 7 - 7
src/Models/Docs.php

@@ -4,15 +4,15 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
 /**
- * Docs Model
- *
- * @property-read   int    $id         Document ID
+ * @property int    $id      文档ID
+ * @property string $date    文档日期
+ * @property string $title   文档标题
+ * @property string $content 文档内容
  *
- * @property        string $date       Date document posted
- * @property        string $title      Document title
- * @property        string $content    Document in HTML
- * @property        string $markdown   Document in MarkDown
+ * @mixin Builder
  */
 final class Docs extends Model
 {

+ 9 - 1
src/Models/EmailQueue.php

@@ -4,11 +4,19 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
 use function json_encode;
 use function time;
 
 /**
- * EmailQueue Model
+ * @property int    $id       记录ID
+ * @property string $to_email 收件人邮箱
+ * @property string $subject  邮件主题
+ * @property string $template 邮件模板
+ * @property string $array    模板内容
+ * @property int    $time     添加时间
+ *
+ * @mixin Builder
  */
 final class EmailQueue extends Model
 {

+ 13 - 0
src/Models/GiftCard.php

@@ -4,6 +4,19 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id          礼品卡ID
+ * @property string $card        卡号
+ * @property int    $balance     余额
+ * @property int    $create_time 创建时间
+ * @property int    $status      使用状态
+ * @property int    $use_time    使用时间
+ * @property int    $use_user    使用用户
+ *
+ * @mixin Builder
+ */
 final class GiftCard extends Model
 {
     protected $connection = 'default';

+ 10 - 2
src/Models/InviteCode.php

@@ -5,9 +5,17 @@ declare(strict_types=1);
 namespace App\Models;
 
 use App\Utils\Tools;
+use Illuminate\Database\Query\Builder;
 
 /**
- * InviteCode Model
+ * @property int    $id         记录ID
+ * @property string $code       邀请码
+ * @property int    $user_id    用户ID
+ * todo: delete these two properties
+ * @property int    $create_at  创建时间
+ * @property int    $updated_at 更新时间
+ *
+ * @mixin Builder
  */
 final class InviteCode extends Model
 {
@@ -17,7 +25,7 @@ final class InviteCode extends Model
     public function reward(): void
     {
         $user = User::where('id', $this->user_id)->first();
-        $user->transfer_enable += Tools::toGB(Setting::obtain('invitation_to_register_traffic_reward'));
+        $user->transfer_enable += Tools::toGB(Config::obtain('invitation_to_register_traffic_reward'));
 
         if ($user->invite_num > 0) {
             --$user->invite_num;

+ 15 - 0
src/Models/Invoice.php

@@ -4,6 +4,21 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id          账单ID
+ * @property int    $user_id     归属用户ID
+ * @property string $order_id    订单ID
+ * @property string $content     账单内容
+ * @property float  $price       账单金额
+ * @property string $status      账单状态
+ * @property int    $create_time 创建时间
+ * @property int    $update_time 更新时间
+ * @property int    $pay_time    支付时间
+ *
+ * @mixin Builder
+ */
 final class Invoice extends Model
 {
     protected $connection = 'default';

+ 9 - 0
src/Models/Link.php

@@ -4,6 +4,15 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id     记录ID
+ * @property string $type   订阅token
+ * @property int    $userid 用户ID
+ *
+ * @mixin Builder
+ */
 final class Link extends Model
 {
     protected $connection = 'default';

+ 10 - 3
src/Models/LoginIp.php

@@ -6,13 +6,20 @@ namespace App\Models;
 
 use App\Services\Notification;
 use GuzzleHttp\Exception\GuzzleException;
+use Illuminate\Database\Query\Builder;
 use Psr\Http\Client\ClientExceptionInterface;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use function date;
 use function time;
 
 /**
- * Ip Model
+ * @property int    $id       记录ID
+ * @property int    $userid   用户ID
+ * @property string $ip       登录IP
+ * @property int    $datetime 登录时间
+ * @property int    $type     登录类型
+ *
+ * @mixin Builder
  */
 final class LoginIp extends Model
 {
@@ -58,13 +65,13 @@ final class LoginIp extends Model
      */
     public function collectLoginIP(string $ip, int $type = 0, int $user_id = 0): void
     {
-        if (Setting::obtain('login_log')) {
+        if (Config::obtain('login_log')) {
             $this->ip = $ip;
             $this->userid = $user_id;
             $this->datetime = time();
             $this->type = $type;
 
-            if (Setting::obtain('notify_new_login') &&
+            if (Config::obtain('notify_new_login') &&
                 $user_id !== 0 &&
                 LoginIp::where('userid', $user_id)->where('ip', $this->ip)->count() === 0
             ) {

+ 29 - 0
src/Models/Node.php

@@ -5,6 +5,7 @@ declare(strict_types=1);
 namespace App\Models;
 
 use Exception;
+use Illuminate\Database\Query\Builder;
 use function array_key_exists;
 use function count;
 use function dns_get_record;
@@ -12,6 +13,34 @@ use function time;
 use const DNS_A;
 use const DNS_AAAA;
 
+/**
+ * @property int    $id                      节点ID
+ * @property string $name                    节点名称
+ * @property int    $type                    节点显示
+ * @property string $server                  节点地址
+ * @property string $custom_config           自定义配置
+ * todo: delete these two properties
+ * @property string $info                    节点信息
+ * @property string $status                  节点状态
+ * @property int    $sort                    节点类型
+ * @property float  $traffic_rate            流量倍率
+ * @property int    $is_dynamic_rate         是否启用动态流量倍率
+ * @property string $dynamic_rate_config     动态流量倍率配置
+ * @property int    $node_class              节点等级
+ * @property float  $node_speedlimit         节点限速
+ * @property int    $node_bandwidth          节点流量
+ * @property int    $node_bandwidth_limit    节点流量限制
+ * @property int    $bandwidthlimit_resetday 流量重置日
+ * @property int    $node_heartbeat          节点心跳
+ * @property int    $online_user             节点在线用户
+ * @property string $node_ip                 节点IP
+ * @property int    $node_group              节点群组
+ * @property int    $online                  在线状态
+ * @property int    $gfw_block               是否被GFW封锁
+ * @property string $password                后端连接密码
+ *
+ * @mixin Builder
+ */
 final class Node extends Model
 {
     protected $connection = 'default';

+ 8 - 18
src/Models/OnlineLog.php

@@ -4,28 +4,18 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
 use function substr;
 
 /**
- * Online Log
+ * @property int    $id         记录ID
+ * @property int    $user_id    用户ID
+ * @property string $ip         IP地址
+ * @property int    $node_id    节点ID
+ * @property int    $first_time 首次在线时间
+ * @property int    $last_time  最后在线时间
  *
- * PRIMARY KEY (id) \
- * UNIQUE KEY (user_id, ip) \
- * KEY (last_time)
- *
- * @property int    $id         INT UNSIGNED NOT NULL AUTO_INCREMENT
- * @property int    $user_id    INT UNSIGNED NOT NULL
- * @property string $ip         INET6 NOT NULL \
- *      Human-readable IPv6 address. \
- *      IPv4 Address would be IPv4-mapped IPv6 Address like `::ffff:1.1.1.1`.
- * @property int    $node_id    INT UNSIGNED NOT NULL
- * @property int    $first_time INT UNSIGNED NOT NULL \
- *      The time when $ip fisrt being seen.
- * @property int    $last_time  INT UNSIGNED NOT NULL \
- *      The time when $ip last being seen.
- *
- * @see https://mariadb.com/kb/en/inet6/ MariaDB INET6 data type
- * @see https://www.rfc-editor.org/rfc/rfc4291.html#section-2.5.5.2 IPv4-mapped IPv6 Address
+ * @mixin Builder
  */
 final class OnlineLog extends Model
 {

+ 17 - 0
src/Models/Order.php

@@ -4,6 +4,23 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id              订单ID
+ * @property int    $user_id         提交用户ID
+ * @property int    $product_id      商品ID
+ * @property string $product_type    商品类型
+ * @property string $product_name    商品名称
+ * @property string $product_content 商品内容
+ * @property string $coupon          订单优惠码
+ * @property float  $price           订单金额
+ * @property string $status          订单状态
+ * @property int    $create_time     创建时间
+ * @property int    $update_time     更新时间
+ *
+ * @mixin Builder
+ */
 final class Order extends Model
 {
     protected $connection = 'default';

+ 13 - 2
src/Models/Payback.php

@@ -4,8 +4,19 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
 use function time;
 
+/**
+ * @property int   $id       记录ID
+ * @property float $total    总金额
+ * @property int   $userid   用户ID
+ * @property int   $ref_by   推荐人ID
+ * @property float $ref_get  推荐人获得金额
+ * @property int   $datetime 创建时间
+ *
+ * @mixin Builder
+ */
 final class Payback extends Model
 {
     protected $connection = 'default';
@@ -35,7 +46,7 @@ final class Payback extends Model
 
     public function rebate($user_id, $order_amount): void
     {
-        $configs = Setting::getClass('ref');
+        $configs = Config::getClass('ref');
         $user = User::where('id', $user_id)->first();
         $gift_user_id = $user->ref_by;
         // 判断
@@ -80,7 +91,7 @@ final class Payback extends Model
         $gift_user = User::where('id', $gift_user_id)->first();
 
         if ($gift_user !== null) {
-            $rebate_amount = $order_amount * Setting::obtain('rebate_ratio');
+            $rebate_amount = $order_amount * Config::obtain('rebate_ratio');
             // 返利
             $money_before = $gift_user->money;
             $gift_user->money += $adjust_rebate ?? $rebate_amount;

+ 14 - 0
src/Models/Paylist.php

@@ -4,6 +4,20 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id         记录ID
+ * @property int    $userid     用户ID
+ * @property float  $total      总金额
+ * @property int    $status     状态
+ * @property int    $invoice_id 账单ID
+ * @property string $tradeno    网关单号
+ * @property string $gateway    支付网关
+ * @property int    $datetime   创建时间
+ *
+ * @mixin Builder
+ */
 final class Paylist extends Model
 {
     protected $connection = 'default';

+ 17 - 0
src/Models/Product.php

@@ -4,6 +4,23 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int    $id          商品ID
+ * @property string $type        类型
+ * @property string $name        名称
+ * @property float  $price       售价
+ * @property string $content     内容
+ * @property string $limit       购买限制
+ * @property int    $status      销售状态
+ * @property int    $create_time 创建时间
+ * @property int    $update_time 更新时间
+ * @property int    $sale_count  累计销量
+ * @property int    $stock       库存
+ *
+ * @mixin Builder
+ */
 final class Product extends Model
 {
     protected $connection = 'default';

+ 12 - 1
src/Models/SubscribeLog.php

@@ -8,12 +8,23 @@ use App\Services\Notification;
 use App\Utils\Tools;
 use Exception;
 use GuzzleHttp\Exception\GuzzleException;
+use Illuminate\Database\Query\Builder;
 use MaxMind\Db\Reader\InvalidDatabaseException;
 use Psr\Http\Client\ClientExceptionInterface;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use voku\helper\AntiXSS;
 use function time;
 
+/**
+ * @property int    $id                 记录ID
+ * @property int    $user_id            用户ID
+ * @property string $type               获取的订阅类型
+ * @property string $request_ip         请求IP
+ * @property string $request_user_agent 请求UA
+ * @property int    $request_time       请求时间
+ *
+ * @mixin Builder
+ */
 final class SubscribeLog extends Model
 {
     protected $connection = 'default';
@@ -55,7 +66,7 @@ final class SubscribeLog extends Model
         $this->request_user_agent = $antiXss->xss_clean($ua);
         $this->request_time = time();
 
-        if (Setting::obtain('notify_new_subscribe') &&
+        if (Config::obtain('notify_new_subscribe') &&
             SubscribeLog::where('user_id', $this->user_id)->where('request_ip', 'like', $this->request_ip)->count() === 0
         ) {
             try {

+ 11 - 1
src/Models/Ticket.php

@@ -4,8 +4,18 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
 /**
- * Ticket Model
+ * @property int    $id       工单ID
+ * @property string $title    工单标题
+ * @property string $content  工单内容
+ * @property int    $userid   用户ID
+ * @property int    $datetime 创建时间
+ * @property string $status   工单状态
+ * @property string $type     工单类型
+ *
+ * @mixin Builder
  */
 final class Ticket extends Model
 {

+ 55 - 0
src/Models/User.php

@@ -9,6 +9,7 @@ use App\Utils\Hash;
 use App\Utils\Tools;
 use Exception;
 use GuzzleHttp\Exception\GuzzleException;
+use Illuminate\Database\Query\Builder;
 use Ramsey\Uuid\Uuid;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use function date;
@@ -19,6 +20,60 @@ use function round;
 use function time;
 use const PHP_EOL;
 
+/**
+ * @property int    $id 用户ID
+ * @property string $user_name 用户名
+ * @property string $email E-Mail
+ * @property string $pass 登录密码
+ * @property string $passwd 节点密码
+ * @property string $uuid UUID
+ * @property int    $u 账户当前上传流量
+ * @property int    $d 账户当前下载流量
+ * @property int    $transfer_today 账户今日所用流量
+ * @property int    $transfer_total 账户累计使用流量
+ * @property int    $transfer_enable 账户当前可用流量
+ * @property int    $port 端口
+ * @property string $last_detect_ban_time 最后一次被封禁的时间
+ * @property int    $all_detect_number 累计违规次数
+ * @property int    $last_use_time 最后使用时间
+ * @property int    $last_check_in_time 最后签到时间
+ * @property int    $last_login_time 最后登录时间
+ * @property string $reg_date 注册时间
+ * @property int    $invite_num 可用邀请次数
+ * @property float  $money 账户余额
+ * @property int    $ref_by 邀请人ID
+ * @property string $method Shadowsocks加密方式
+ * @property string $reg_ip 注册IP
+ * @property float  $node_speedlimit 用户限速
+ * @property int    $node_iplimit 同时可连接IP数
+ * @property int    $is_admin 是否管理员
+ * @property int    $im_type 联系方式类型
+ * @property string $im_value 联系方式
+ * @property int    $contact_method 偏好的联系方式
+ * @property int    $daily_mail_enable 每日报告开关
+ * @property int    $class 等级
+ * @property string $class_expire 等级过期时间
+ * @property string $theme 网站主题
+ * @property string $ga_token GA密钥
+ * @property int    $ga_enable GA开关
+ * @property string $remark 备注
+ * @property int    $node_group 节点分组
+ * @property int    $is_banned 是否封禁
+ * @property string $banned_reason 封禁理由
+ * @property int    $is_shadow_banned 是否处于账户异常状态
+ * @property int    $expire_notified 过期提醒
+ * @property int    $traffic_notified 流量提醒
+ * @property string $forbidden_ip 禁止访问IP
+ * @property string $forbidden_port 禁止访问端口
+ * @property int    $auto_reset_day 自动重置流量日
+ * @property float  $auto_reset_bandwidth 自动重置流量
+ * @property string $api_token API 密钥
+ * @property int    $is_dark_mode 是否启用暗黑模式
+ * @property int    $is_inactive 是否处于闲置状态
+ * @property string $locale 显示语言
+ *
+ * @mixin Builder
+ */
 final class User extends Model
 {
     /**

+ 12 - 0
src/Models/UserCoupon.php

@@ -4,9 +4,21 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
 use function json_decode;
 use function time;
 
+/**
+ * @property int    $id          优惠码ID
+ * @property string $code        优惠码
+ * @property string $content     优惠码内容
+ * @property string $limit       优惠码限制
+ * @property int    $use_count   累计使用次数
+ * @property int    $create_time 创建时间
+ * @property int    $expire_time 过期时间
+ *
+ * @mixin Builder
+ */
 final class UserCoupon extends Model
 {
     protected $connection = 'default';

+ 11 - 0
src/Models/UserHourlyUsage.php

@@ -4,6 +4,17 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
+
+/**
+ * @property int $id           记录ID
+ * @property int $user_id      用户ID
+ * @property int $traffic      当前总流量
+ * @property int $hourly_usage 过去一小时流量
+ * @property int $datetime     记录时间
+ *
+ * @mixin Builder
+ */
 final class UserHourlyUsage extends Model
 {
     protected $connection = 'default';

+ 12 - 0
src/Models/UserMoneyLog.php

@@ -4,8 +4,20 @@ declare(strict_types=1);
 
 namespace App\Models;
 
+use Illuminate\Database\Query\Builder;
 use function time;
 
+/**
+ * @property int $id 记录ID
+ * @property int $user_id 用户ID
+ * @property float $before 用户变动前账户余额
+ * @property float $after 用户变动后账户余额
+ * @property float $amount 变动总额
+ * @property string $remark 备注
+ * @property int $create_time 创建时间
+ *
+ * @mixin Builder
+ */
 final class UserMoneyLog extends Model
 {
     protected $connection = 'default';

+ 14 - 13
src/Services/Bot/Telegram/Callback.php

@@ -5,13 +5,12 @@ declare(strict_types=1);
 namespace App\Services\Bot\Telegram;
 
 use App\Controllers\SubController;
+use App\Models\Config;
 use App\Models\InviteCode;
 use App\Models\LoginIp;
 use App\Models\OnlineLog;
 use App\Models\Payback;
-use App\Models\Setting;
 use App\Models\SubscribeLog;
-use App\Services\Config;
 use App\Utils\Tools;
 use GuzzleHttp\Exception\GuzzleException;
 use Illuminate\Support\Collection;
@@ -92,7 +91,7 @@ final class Callback
         $this->callback_data = $callback->getData();
         $this->allow_edit_message = time() < $callback->getMessage()->getDate() + 172800;
 
-        if ($this->chat_id < 0 && Setting::obtain('telegram_group_quiet')) {
+        if ($this->chat_id < 0 && Config::obtain('telegram_group_quiet')) {
             // 群组中不回应
             return;
         }
@@ -410,7 +409,7 @@ final class Callback
                 break;
             case 'subscribe_log':
                 // 订阅记录
-                if (Setting::obtain('subscribe_log')) {
+                if (Config::obtain('subscribe_log')) {
                     $logs = SubscribeLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->take(10)->get();
                     $text = '<strong>以下是你最近 10 次订阅记录:</strong>' . PHP_EOL . PHP_EOL;
 
@@ -591,8 +590,10 @@ final class Callback
             case 'encrypt':
                 // 加密方式更改
                 $keyboard = $back;
+                $method = Tools::getSsMethod('method');
+
                 if (isset($CallbackDataExplode[1])) {
-                    if (in_array($CallbackDataExplode[1], Config::getSsMethod('method'))) {
+                    if (in_array($CallbackDataExplode[1], $method)) {
                         $temp = $this->user->setMethod($CallbackDataExplode[1]);
                         if ($temp['ok']) {
                             $text = '你当前的加密方式为:' . $this->user->method . PHP_EOL . PHP_EOL . $temp['msg'];
@@ -605,7 +606,7 @@ final class Callback
                 } else {
                     $Encrypts = [];
 
-                    foreach (Config::getSsMethod('method') as $value) {
+                    foreach ($method as $value) {
                         $Encrypts[] = [
                             'text' => $value,
                             'callback_data' => 'user.edit.encrypt|' . $value,
@@ -638,7 +639,7 @@ final class Callback
                 // Telegram 账户解绑
                 $this->allow_edit_message = false;
                 $text = '发送 **/unbind 账户邮箱** 进行解绑。';
-                if (Setting::obtain('telegram_unbind_kick_member')) {
+                if (Config::obtain('telegram_unbind_kick_member')) {
                     $text .= PHP_EOL . PHP_EOL . '根据管理员的设定,你解绑账户将会被自动移出用户群。';
                 }
                 $sendMessage = [
@@ -676,7 +677,7 @@ final class Callback
                 Message::sendPost(
                     'unbanChatMember',
                     [
-                        'chat_id' => Setting::obtain('telegram_chatid'),
+                        'chat_id' => Config::obtain('telegram_chatid'),
                         'user_id' => $this->trigger_user['id'],
                     ]
                 );
@@ -762,21 +763,21 @@ final class Callback
             ],
         ];
 
-        if (! Setting::obtain('enable_traditional_sub')) {
+        if (! Config::obtain('enable_traditional_sub')) {
             unset($keyboard[1]);
             unset($keyboard[2]);
         }
 
-        if (! Setting::obtain('enable_ss_sub')) {
+        if (! Config::obtain('enable_ss_sub')) {
             unset($keyboard[0][2]);
             unset($keyboard[1]);
         }
 
-        if (! Setting::obtain('enable_v2_sub')) {
+        if (! Config::obtain('enable_v2_sub')) {
             unset($keyboard[2][0]);
         }
 
-        if (! Setting::obtain('enable_trojan_sub')) {
+        if (! Config::obtain('enable_trojan_sub')) {
             unset($keyboard[2][1]);
         }
 
@@ -877,7 +878,7 @@ final class Callback
             $paybacks_sum = 0;
         }
 
-        $invite = Setting::getClass('ref');
+        $invite = Config::getClass('ref');
 
         $text = [
             '<strong>你每邀请 1 位用户注册:</strong>',

+ 4 - 4
src/Services/Bot/Telegram/Commands/CheckinCommand.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram\Commands;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Bot\Telegram\Message;
 use Telegram\Bot\Actions;
 use Telegram\Bot\Commands\Command;
@@ -35,11 +35,11 @@ final class CheckinCommand extends Command
         $chat_id = $message->getChat()->getId();
 
         if ($chat_id < 0) {
-            if (Setting::obtain('telegram_group_quiet')) {
+            if (Config::obtain('telegram_group_quiet')) {
                 // 群组中不回应
                 return null;
             }
-            if ($chat_id !== Setting::obtain('telegram_chatid')) {
+            if ($chat_id !== Config::obtain('telegram_chatid')) {
                 // 非我方群组
                 return null;
             }
@@ -58,7 +58,7 @@ final class CheckinCommand extends Command
             // 回送信息
             $response = $this->replyWithMessage(
                 [
-                    'text' => Setting::obtain('user_not_bind_reply'),
+                    'text' => Config::obtain('user_not_bind_reply'),
                     'parse_mode' => 'Markdown',
                     'reply_to_message_id' => $message->getMessageId(),
                 ]

+ 4 - 4
src/Services/Bot/Telegram/Commands/HelpCommand.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram\Commands;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Telegram\Bot\Actions;
 use Telegram\Bot\Commands\Command;
 use function preg_match;
@@ -30,12 +30,12 @@ final class HelpCommand extends Command
         $update = $this->getUpdate();
         $message = $update->getMessage();
 
-        if ($message->getChat()->getId() < 0 && Setting::obtain('telegram_group_quiet')) {
+        if ($message->getChat()->getId() < 0 && Config::obtain('telegram_group_quiet')) {
             return;
         }
 
-        if (! preg_match('/^\/help\s?(@' . Setting::obtain('telegram_bot') . ')?.*/i', $message->getText()) &&
-            ! Setting::obtain('help_any_command')) {
+        if (! preg_match('/^\/help\s?(@' . Config::obtain('telegram_bot') . ')?.*/i', $message->getText()) &&
+            ! Config::obtain('help_any_command')) {
             return;
         }
 

+ 4 - 4
src/Services/Bot/Telegram/Commands/MyCommand.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram\Commands;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Models\User;
 use App\Services\Bot\Telegram\Message;
 use Telegram\Bot\Actions;
@@ -40,11 +40,11 @@ final class MyCommand extends Command
         $chat_id = $message->getChat()->getId();
 
         if ($chat_id < 0) {
-            if (Setting::obtain('telegram_group_quiet')) {
+            if (Config::obtain('telegram_group_quiet')) {
                 // 群组中不回应
                 return null;
             }
-            if ($chat_id !== Setting::obtain('telegram_chatid')) {
+            if ($chat_id !== Config::obtain('telegram_chatid')) {
                 // 非我方群组
                 return null;
             }
@@ -66,7 +66,7 @@ final class MyCommand extends Command
             // 回送信息
             $response = $this->replyWithMessage(
                 [
-                    'text' => Setting::obtain('user_not_bind_reply'),
+                    'text' => Config::obtain('user_not_bind_reply'),
                     'reply_to_message_id' => $message_id,
                     'parse_mode' => 'Markdown',
                 ]

+ 2 - 2
src/Services/Bot/Telegram/Commands/PingCommand.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram\Commands;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Telegram\Bot\Actions;
 use Telegram\Bot\Commands\Command;
 use function implode;
@@ -49,7 +49,7 @@ final class PingCommand extends Command
                 ]
             );
         } else {
-            if (Setting::obtain('telegram_group_quiet')) {
+            if (Config::obtain('telegram_group_quiet')) {
                 // 群组中不回应
                 return;
             }

+ 2 - 2
src/Services/Bot/Telegram/Commands/StartCommand.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram\Commands;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Telegram\Bot\Actions;
 use Telegram\Bot\Commands\Command;
 
@@ -41,7 +41,7 @@ final class StartCommand extends Command
                 ]
             );
         } else {
-            if (! Setting::obtain('telegram_group_quiet')) {
+            if (! Config::obtain('telegram_group_quiet')) {
                 // 发送 '输入中' 会话状态
                 $this->replyWithChatAction(['action' => Actions::TYPING]);
                 // 回送信息

+ 3 - 3
src/Services/Bot/Telegram/Commands/UnbindCommand.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram\Commands;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Bot\Telegram\Message;
 use Telegram\Bot\Actions;
 use Telegram\Bot\Commands\Command;
@@ -48,7 +48,7 @@ final class UnbindCommand extends Command
                 // 回送信息
                 $this->replyWithMessage(
                     [
-                        'text' => Setting::obtain('user_not_bind_reply'),
+                        'text' => Config::obtain('user_not_bind_reply'),
                         'parse_mode' => 'Markdown',
                     ]
                 );
@@ -95,7 +95,7 @@ final class UnbindCommand extends Command
     {
         $text = '以 `/unbind [email protected]` 的形式发送进行解绑.';
 
-        if (Setting::obtain('telegram_unbind_kick_member')) {
+        if (Config::obtain('telegram_unbind_kick_member')) {
             $text .= PHP_EOL . PHP_EOL . '根据管理员的设定,你解绑账户将会被自动移出用户群.';
         }
 

+ 8 - 8
src/Services/Bot/Telegram/Message.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Models\User;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\GuzzleException;
@@ -89,11 +89,11 @@ final class Message
             'name' => $new_chat_member->getFirstName() . ' Message.php' . $new_chat_member->getLastName(),
         ];
 
-        if ($new_chat_member->getUsername() === Setting::obtain('telegram_bot')) {
+        if ($new_chat_member->getUsername() === Config::obtain('telegram_bot')) {
             // 机器人加入新群组
-            if (! Setting::obtain('allow_to_join_new_groups')
+            if (! Config::obtain('allow_to_join_new_groups')
                 &&
-                ! in_array($this->chat_id, json_decode(Setting::obtain('group_id_allowed_to_join')))) {
+                ! in_array($this->chat_id, json_decode(Config::obtain('group_id_allowed_to_join')))) {
                 // 退群
 
                 $this->replyWithMessage(
@@ -120,9 +120,9 @@ final class Message
             // 新成员加入群组
             $new_user = self::getUser($member['id']);
 
-            if (Setting::obtain('telegram_group_bound_user')
+            if (Config::obtain('telegram_group_bound_user')
                 &&
-                $this->chat_id === Setting::obtain('telegram_chatid')
+                $this->chat_id === Config::obtain('telegram_chatid')
                 &&
                 $new_user === null
                 &&
@@ -145,7 +145,7 @@ final class Message
                 return;
             }
 
-            if (Setting::obtain('enable_welcome_message')) {
+            if (Config::obtain('enable_welcome_message')) {
                 $text = ($new_user->class > 0 ? '欢迎 VIP' . $new_user->class .
                     ' 用户 ' . $member['name'] . '加入群组。' : '欢迎 ' . $member['name']);
 
@@ -217,7 +217,7 @@ final class Message
     public static function sendPost($method, $params): void
     {
         $client = new Client();
-        $telegram_api_url = 'https://api.telegram.org/bot' . Setting::obtain('telegram_token') . '/' . $method;
+        $telegram_api_url = 'https://api.telegram.org/bot' . Config::obtain('telegram_token') . '/' . $method;
 
         $headers = [
             'Content-Type' => 'application/json; charset=utf-8',

+ 2 - 2
src/Services/Bot/Telegram/Process.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Bot\Telegram;
 
-use App\Models\Setting;
+use App\Models\Config;
 use GuzzleHttp\Exception\GuzzleException;
 use MaxMind\Db\Reader\InvalidDatabaseException;
 use Psr\Http\Message\RequestInterface;
@@ -20,7 +20,7 @@ final class Process
      */
     public static function index(RequestInterface $request): void
     {
-        $bot = new Api(Setting::obtain('telegram_token'));
+        $bot = new Api(Config::obtain('telegram_token'));
 
         $bot->addCommands([
             new Commands\MyCommand(),

+ 11 - 0
src/Services/Cache.php

@@ -23,4 +23,15 @@ final class Cache
 
         return $redis;
     }
+
+    public static function getRedisConfig(): array
+    {
+        return [
+            'host' => $_ENV['redis_host'],
+            'port' => $_ENV['redis_port'],
+            'connectTimeout' => $_ENV['redis_timeout'],
+            'auth' => [$_ENV['redis_username'], $_ENV['redis_password']],
+            'ssl' => ['verify_peer' => $_ENV['redis_ssl']],
+        ];
+    }
 }

+ 8 - 8
src/Services/Captcha.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services;
 
-use App\Models\Setting;
+use App\Models\Config;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\GuzzleException;
 use function hash_hmac;
@@ -14,12 +14,12 @@ final class Captcha
 {
     public static function generate(): array
     {
-        return match (Setting::obtain('captcha_provider')) {
+        return match (Config::obtain('captcha_provider')) {
             'turnstile' => [
-                'turnstile_sitekey' => Setting::obtain('turnstile_sitekey'),
+                'turnstile_sitekey' => Config::obtain('turnstile_sitekey'),
             ],
             'geetest' => [
-                'geetest_id' => Setting::obtain('geetest_id'),
+                'geetest_id' => Config::obtain('geetest_id'),
             ],
             default => [],
         };
@@ -33,7 +33,7 @@ final class Captcha
         $result = false;
         $client = new Client();
 
-        switch (Setting::obtain('captcha_provider')) {
+        switch (Config::obtain('captcha_provider')) {
             case 'turnstile':
                 if (isset($param['turnstile'])) {
                     $turnstile_url = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
@@ -43,7 +43,7 @@ final class Captcha
                     ];
 
                     $turnstile_body = [
-                        'secret' => Setting::obtain('turnstile_secret'),
+                        'secret' => Config::obtain('turnstile_secret'),
                         'response' => $param['turnstile'],
                     ];
 
@@ -61,8 +61,8 @@ final class Captcha
             case 'geetest':
                 if (isset($param['geetest'])) {
                     $geetest = $param['geetest'];
-                    $captcha_id = Setting::obtain('geetest_id');
-                    $captcha_key = Setting::obtain('geetest_key');
+                    $captcha_id = Config::obtain('geetest_id');
+                    $captcha_key = Config::obtain('geetest_key');
                     $lot_number = $geetest['lot_number'];
                     $captcha_output = $geetest['captcha_output'];
                     $pass_token = $geetest['pass_token'];

+ 0 - 75
src/Services/Config.php

@@ -1,75 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Services;
-
-final class Config
-{
-    public static function getViewConfig(): array
-    {
-        return [
-            'appName' => $_ENV['appName'],
-            'baseUrl' => $_ENV['baseUrl'],
-
-            'enable_checkin' => $_ENV['enable_checkin'],
-            'checkinMin' => $_ENV['checkinMin'],
-            'checkinMax' => $_ENV['checkinMax'],
-
-            'jump_delay' => $_ENV['jump_delay'],
-
-            'enable_kill' => $_ENV['enable_kill'],
-            'enable_change_email' => $_ENV['enable_change_email'],
-
-            'enable_r2_client_download' => $_ENV['enable_r2_client_download'],
-
-            'jsdelivr_url' => $_ENV['jsdelivr_url'],
-        ];
-    }
-
-    public static function getRedisConfig(): array
-    {
-        return [
-            'host' => $_ENV['redis_host'],
-            'port' => $_ENV['redis_port'],
-            'connectTimeout' => $_ENV['redis_timeout'],
-            'auth' => [$_ENV['redis_username'], $_ENV['redis_password']],
-            'ssl' => ['verify_peer' => $_ENV['redis_ssl']],
-        ];
-    }
-
-    public static function getDbConfig(): array
-    {
-        return [
-            'driver' => $_ENV['db_driver'],
-            'host' => $_ENV['db_host'],
-            'unix_socket' => $_ENV['db_socket'],
-            'database' => $_ENV['db_database'],
-            'username' => $_ENV['db_username'],
-            'password' => $_ENV['db_password'],
-            'charset' => $_ENV['db_charset'],
-            'collation' => $_ENV['db_collation'],
-            'prefix' => $_ENV['db_prefix'],
-            'port' => $_ENV['db_port'],
-        ];
-    }
-
-    public static function getSsMethod($type): array
-    {
-        return match ($type) {
-            'ss_obfs' => [
-                'simple_obfs_http',
-                'simple_obfs_http_compatible',
-                'simple_obfs_tls',
-                'simple_obfs_tls_compatible',
-            ],
-            default => [
-                'aes-128-gcm',
-                'aes-192-gcm',
-                'aes-256-gcm',
-                'chacha20-ietf-poly1305',
-                'xchacha20-ietf-poly1305',
-            ],
-        };
-    }
-}

+ 12 - 12
src/Services/Cron.php

@@ -5,6 +5,7 @@ declare(strict_types=1);
 namespace App\Services;
 
 use App\Models\Ann;
+use App\Models\Config;
 use App\Models\DetectLog;
 use App\Models\EmailQueue;
 use App\Models\Invoice;
@@ -12,7 +13,6 @@ use App\Models\Node;
 use App\Models\OnlineLog;
 use App\Models\Order;
 use App\Models\Paylist;
-use App\Models\Setting;
 use App\Models\SubscribeLog;
 use App\Models\User;
 use App\Models\UserHourlyUsage;
@@ -64,9 +64,9 @@ final class Cron
         SubscribeLog::where(
             'request_time',
             '<',
-            time() - 86400 * Setting::obtain('subscribe_log_retention_days')
+            time() - 86400 * Config::obtain('subscribe_log_retention_days')
         )->delete();
-        UserHourlyUsage::where('datetime', '<', time() - 86400 * Setting::obtain('traffic_log_retention_days'))->delete();
+        UserHourlyUsage::where('datetime', '<', time() - 86400 * Config::obtain('traffic_log_retention_days'))->delete();
         DetectLog::where('datetime', '<', time() - 86400 * 3)->delete();
         EmailQueue::where('time', '<', time() - 86400)->delete();
         OnlineLog::where('last_time', '<', time() - 86400)->delete();
@@ -76,9 +76,9 @@ final class Cron
 
     public static function detectInactiveUser(): void
     {
-        $checkin_days = Setting::obtain('detect_inactive_user_checkin_days');
-        $login_days = Setting::obtain('detect_inactive_user_login_days');
-        $use_days = Setting::obtain('detect_inactive_user_use_days');
+        $checkin_days = Config::obtain('detect_inactive_user_checkin_days');
+        $login_days = Config::obtain('detect_inactive_user_login_days');
+        $use_days = Config::obtain('detect_inactive_user_use_days');
 
         User::where('is_admin', 0)
             ->where('is_inactive', 0)
@@ -119,11 +119,11 @@ final class Cron
                     echo $e->getMessage() . PHP_EOL;
                 }
 
-                if (Setting::obtain('telegram_node_offline')) {
+                if (Config::obtain('telegram_node_offline')) {
                     $notice_text = str_replace(
                         '%node_name%',
                         $node->name,
-                        Setting::obtain('telegram_node_offline_text')
+                        Config::obtain('telegram_node_offline_text')
                     );
 
                     try {
@@ -151,11 +151,11 @@ final class Cron
                     echo $e->getMessage() . PHP_EOL;
                 }
 
-                if (Setting::obtain('telegram_node_online')) {
+                if (Config::obtain('telegram_node_online')) {
                     $notice_text = str_replace(
                         '%node_name%',
                         $node->name,
-                        Setting::obtain('telegram_node_online_text')
+                        Config::obtain('telegram_node_online_text')
                     );
 
                     try {
@@ -598,7 +598,7 @@ final class Cron
      */
     public static function sendTelegramDailyJob(): void
     {
-        (new Telegram())->send(0, Setting::obtain('telegram_daily_job_text'));
+        (new Telegram())->send(0, Config::obtain('telegram_daily_job_text'));
 
         echo Tools::toDateTime(time()) . ' 成功发送 Telegram 每日任务提示' . PHP_EOL;
     }
@@ -619,7 +619,7 @@ final class Cron
                     Analytics::getTodayCheckinUser(),
                     Analytics::getTodayTrafficUsage(),
                 ],
-                Setting::obtain('telegram_diary_text')
+                Config::obtain('telegram_diary_text')
             )
         );
 

+ 17 - 1
src/Services/DB.php

@@ -14,7 +14,7 @@ final class DB extends Manager
         $db = new DB();
 
         try {
-            $db->addConnection(Config::getDbConfig());
+            $db->addConnection(self::getConfig());
             $db->getConnection()->getPdo();
         } catch (Exception $e) {
             die('Could not connect to main database: ' . $e->getMessage());
@@ -26,4 +26,20 @@ final class DB extends Manager
         View::$connection = $db->getDatabaseManager();
         $db->getDatabaseManager()->connection('default')->enableQueryLog();
     }
+
+    public static function getConfig(): array
+    {
+        return [
+            'driver' => $_ENV['db_driver'],
+            'host' => $_ENV['db_host'],
+            'unix_socket' => $_ENV['db_socket'],
+            'database' => $_ENV['db_database'],
+            'username' => $_ENV['db_username'],
+            'password' => $_ENV['db_password'],
+            'charset' => $_ENV['db_charset'],
+            'collation' => $_ENV['db_collation'],
+            'prefix' => $_ENV['db_prefix'],
+            'port' => $_ENV['db_port'],
+        ];
+    }
 }

+ 5 - 5
src/Services/Detect.php

@@ -4,10 +4,10 @@ declare(strict_types=1);
 
 namespace App\Services;
 
+use App\Models\Config;
 use App\Models\DetectBanLog;
 use App\Models\DetectLog;
 use App\Models\Node;
-use App\Models\Setting;
 use App\Models\User;
 use App\Services\IM\Telegram;
 use App\Utils\Tools;
@@ -59,11 +59,11 @@ final class Detect
                     echo $e->getMessage() . PHP_EOL;
                 }
 
-                if (Setting::obtain('telegram_node_gfwed')) {
+                if (Config::obtain('telegram_node_gfwed')) {
                     $notice_text = str_replace(
                         '%node_name%',
                         $node->name,
-                        Setting::obtain('telegram_node_gfwed_text')
+                        Config::obtain('telegram_node_gfwed_text')
                     );
 
                     (new Telegram())->send(0, $notice_text);
@@ -88,11 +88,11 @@ final class Detect
                     echo $e->getMessage() . PHP_EOL;
                 }
 
-                if (Setting::obtain('telegram_node_ungfwed')) {
+                if (Config::obtain('telegram_node_ungfwed')) {
                     $notice_text = str_replace(
                         '%node_name%',
                         $node->name,
-                        Setting::obtain('telegram_node_ungfwed_text')
+                        Config::obtain('telegram_node_ungfwed_text')
                     );
 
                     (new Telegram())->send(0, $notice_text);

+ 3 - 3
src/Services/Gateway/AbstractPayment.php

@@ -4,10 +4,10 @@ declare(strict_types=1);
 
 namespace App\Services\Gateway;
 
+use App\Models\Config;
 use App\Models\Invoice;
 use App\Models\Payback;
 use App\Models\Paylist;
-use App\Models\Setting;
 use App\Models\User;
 use App\Utils\Tools;
 use Psr\Http\Message\ResponseInterface;
@@ -77,7 +77,7 @@ abstract class AbstractPayment
 
         $user = User::find($paylist?->userid);
         // 返利
-        if ($user !== null && $user->ref_by > 0 && Setting::obtain('invitation_mode') === 'after_paid') {
+        if ($user !== null && $user->ref_by > 0 && Config::obtain('invitation_mode') === 'after_paid') {
             (new Payback())->rebate($user->id, $paylist->total);
         }
     }
@@ -99,7 +99,7 @@ abstract class AbstractPayment
 
     protected static function getActiveGateway($key): bool
     {
-        $payment_gateways = Setting::where('item', 'payment_gateway')->first();
+        $payment_gateways = Config::where('item', 'payment_gateway')->first();
         $active_gateways = json_decode($payment_gateways->value);
         if (in_array($key, $active_gateways)) {
             return true;

+ 2 - 2
src/Services/Gateway/AopF2F.php

@@ -4,8 +4,8 @@ declare(strict_types=1);
 
 namespace App\Services\Gateway;
 
+use App\Models\Config;
 use App\Models\Paylist;
-use App\Models\Setting;
 use App\Services\Auth;
 use App\Services\View;
 use Exception;
@@ -118,7 +118,7 @@ final class AopF2F extends AbstractPayment
 
     private function createGateway(): GatewayInterface
     {
-        $configs = Setting::getClass('billing');
+        $configs = Config::getClass('billing');
         $gateway = Omnipay::create('Alipay_AopF2F');
         $gateway->setSignType('RSA2'); //RSA/RSA2
         $gateway->setAppId($configs['f2f_pay_app_id']);

+ 5 - 5
src/Services/Gateway/Epay.php

@@ -10,8 +10,8 @@ declare(strict_types=1);
 
 namespace App\Services\Gateway;
 
+use App\Models\Config;
 use App\Models\Paylist;
-use App\Models\Setting;
 use App\Services\Auth;
 use App\Services\Gateway\Epay\EpayNotify;
 use App\Services\Gateway\Epay\EpaySubmit;
@@ -28,10 +28,10 @@ final class Epay extends AbstractPayment
 
     public function __construct()
     {
-        $this->epay['apiurl'] = Setting::obtain('epay_url');//易支付API地址
-        $this->epay['partner'] = Setting::obtain('epay_pid');//易支付商户pid
-        $this->epay['key'] = Setting::obtain('epay_key');//易支付商户Key
-        $this->epay['sign_type'] = strtoupper(Setting::obtain('epay_sign_type')); //签名方式
+        $this->epay['apiurl'] = Config::obtain('epay_url');//易支付API地址
+        $this->epay['partner'] = Config::obtain('epay_pid');//易支付商户pid
+        $this->epay['key'] = Config::obtain('epay_key');//易支付商户Key
+        $this->epay['sign_type'] = strtoupper(Config::obtain('epay_sign_type')); //签名方式
         $this->epay['input_charset'] = strtolower('utf-8');//字符编码
         $this->epay['transport'] = 'https';//协议 http 或者https
     }

+ 3 - 3
src/Services/Gateway/Epay/EpayTool.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Gateway\Epay;
 
-use App\Models\Setting;
+use App\Models\Config;
 use function hash;
 use function strlen;
 
@@ -14,13 +14,13 @@ final class EpayTool
     {
         $prestr .= $key;
 
-        return hash(Setting::obtain('epay_sign_type'), $prestr);
+        return hash(Config::obtain('epay_sign_type'), $prestr);
     }
 
     public static function verify($prestr, $sign, $key): bool
     {
         $prestr .= $key;
-        $correct_sign = hash(Setting::obtain('epay_sign_type'), $prestr);
+        $correct_sign = hash(Config::obtain('epay_sign_type'), $prestr);
 
         return $correct_sign === $sign;
     }

+ 4 - 4
src/Services/Gateway/PayPal.php

@@ -4,8 +4,8 @@ declare(strict_types=1);
 
 namespace App\Services\Gateway;
 
+use App\Models\Config;
 use App\Models\Paylist;
-use App\Models\Setting;
 use App\Services\Auth;
 use App\Services\Exchange;
 use App\Services\View;
@@ -25,7 +25,7 @@ final class PayPal extends AbstractPayment
 
     public function __construct()
     {
-        $configs = Setting::getClass('billing');
+        $configs = Config::getClass('billing');
 
         $this->gateway_config = [
             'mode' => $configs['paypal_mode'],
@@ -82,14 +82,14 @@ final class PayPal extends AbstractPayment
             ]);
         }
 
-        $exchange_amount = Exchange::exchange($price, 'CNY', Setting::obtain('paypal_currency'));
+        $exchange_amount = Exchange::exchange($price, 'CNY', Config::obtain('paypal_currency'));
 
         $order_data = [
             "intent" => "CAPTURE",
             "purchase_units" => [
                 [
                     "amount" => [
-                        "currency_code" => Setting::obtain('paypal_currency'),
+                        "currency_code" => Config::obtain('paypal_currency'),
                         "value" => $exchange_amount,
                     ],
                     "reference_id" => $trade_no,

+ 7 - 7
src/Services/Gateway/StripeCard.php

@@ -4,8 +4,8 @@ declare(strict_types=1);
 
 namespace App\Services\Gateway;
 
+use App\Models\Config;
 use App\Models\Paylist;
-use App\Models\Setting;
 use App\Services\Auth;
 use App\Services\Exchange;
 use App\Services\View;
@@ -50,8 +50,8 @@ final class StripeCard extends AbstractPayment
         $invoice_id = $antiXss->xss_clean($request->getParam('invoice_id'));
         $trade_no = self::generateGuid();
 
-        if ($price < Setting::obtain('stripe_min_recharge') ||
-            $price > Setting::obtain('stripe_max_recharge')
+        if ($price < Config::obtain('stripe_min_recharge') ||
+            $price > Config::obtain('stripe_max_recharge')
         ) {
             return $response->withJson([
                 'ret' => 0,
@@ -68,9 +68,9 @@ final class StripeCard extends AbstractPayment
         $pl->tradeno = $trade_no;
         $pl->save();
 
-        $exchange_amount = Exchange::exchange($price, 'CNY', Setting::obtain('stripe_currency'));
+        $exchange_amount = Exchange::exchange($price, 'CNY', Config::obtain('stripe_currency'));
 
-        Stripe::setApiKey(Setting::obtain('stripe_sk'));
+        Stripe::setApiKey(Config::obtain('stripe_sk'));
         $session = null;
 
         try {
@@ -79,7 +79,7 @@ final class StripeCard extends AbstractPayment
                 'line_items' => [
                     [
                         'price_data' => [
-                            'currency' => Setting::obtain('stripe_currency'),
+                            'currency' => Config::obtain('stripe_currency'),
                             'product_data' => [
                                 'name' => 'Account Recharge',
                             ],
@@ -122,7 +122,7 @@ final class StripeCard extends AbstractPayment
 
         $session_id = $antiXss->xss_clean($request->getParam('session_id'));
 
-        $stripe = new StripeClient(Setting::obtain('stripe_sk'));
+        $stripe = new StripeClient(Config::obtain('stripe_sk'));
         $session = null;
 
         try {

+ 2 - 2
src/Services/IM/Discord.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\IM;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\GuzzleException;
@@ -17,7 +17,7 @@ final class Discord extends Base
 
     public function __construct()
     {
-        $this->token = Setting::obtain('discord_bot_token');
+        $this->token = Config::obtain('discord_bot_token');
         $this->client = new Client();
     }
 

+ 2 - 2
src/Services/IM/Slack.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\IM;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 use GuzzleHttp\Client;
 use GuzzleHttp\Exception\GuzzleException;
@@ -16,7 +16,7 @@ final class Slack extends Base
 
     public function __construct()
     {
-        $this->token = Setting::obtain('slack_token');
+        $this->token = Config::obtain('slack_token');
         $this->client = new Client();
     }
 

+ 6 - 6
src/Services/IM/Telegram.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\IM;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Telegram\Bot\Api;
 use Telegram\Bot\Exceptions\TelegramSDKException;
 use function strip_tags;
@@ -18,7 +18,7 @@ final class Telegram extends Base
      */
     public function __construct()
     {
-        $this->bot = new Api(Setting::obtain('telegram_token'));
+        $this->bot = new Api(Config::obtain('telegram_token'));
     }
 
     /**
@@ -29,7 +29,7 @@ final class Telegram extends Base
     public function send($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = Setting::obtain('telegram_chatid');
+            $to = Config::obtain('telegram_chatid');
         }
 
         $sendMessage = [
@@ -52,7 +52,7 @@ final class Telegram extends Base
     public function sendHtml($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = Setting::obtain('telegram_chatid');
+            $to = Config::obtain('telegram_chatid');
         }
 
         $sendMessage = [
@@ -80,7 +80,7 @@ final class Telegram extends Base
     public function sendMarkdown($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = Setting::obtain('telegram_chatid');
+            $to = Config::obtain('telegram_chatid');
         }
 
         $sendMessage = [
@@ -103,7 +103,7 @@ final class Telegram extends Base
     public function sendMarkdownV2($to = 0, $msg = ''): void
     {
         if ($to === 0) {
-            $to = Setting::obtain('telegram_chatid');
+            $to = Config::obtain('telegram_chatid');
         }
 
         $sendMessage = [

+ 2 - 2
src/Services/Mail.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Mail\Mailgun;
 use App\Services\Mail\NullMail;
 use App\Services\Mail\Postal;
@@ -22,7 +22,7 @@ final class Mail
 {
     public static function getClient(): Mailgun|Smtp|SendGrid|NullMail|Ses|Postal
     {
-        $driver = Setting::obtain('email_driver');
+        $driver = Config::obtain('email_driver');
         return match ($driver) {
             'mailgun' => new Mailgun(),
             'ses' => new Ses(),

+ 2 - 2
src/Services/Mail/Mailgun.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Mail;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 use Mailgun\Mailgun as MG;
 use Psr\Http\Client\ClientExceptionInterface;
@@ -18,7 +18,7 @@ final class Mailgun extends Base
 
     public function __construct()
     {
-        $configs = Setting::getClass('email');
+        $configs = Config::getClass('email');
 
         $this->mg = MG::create($configs['mailgun_key']);
         $this->domain = $configs['mailgun_domain'];

+ 2 - 2
src/Services/Mail/Postal.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Mail;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Postal\Client;
 use Postal\Send\Message;
 use function basename;
@@ -17,7 +17,7 @@ final class Postal extends Base
 
     public function __construct()
     {
-        $configs = Setting::getClass('email');
+        $configs = Config::getClass('email');
 
         $this->client = new Client($configs['postal_host'], $configs['postal_key']);
         $this->message = new Message();

+ 2 - 2
src/Services/Mail/SendGrid.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Mail;
 
-use App\Models\Setting;
+use App\Models\Config;
 use SendGrid as SG;
 use SendGrid\Mail\Mail;
 use SendGrid\Mail\TypeException;
@@ -22,7 +22,7 @@ final class SendGrid extends Base
      */
     public function __construct()
     {
-        $configs = Setting::getClass('email');
+        $configs = Config::getClass('email');
 
         $this->sg = new SG($configs['sendgrid_key']);
         $this->email = new Mail();

+ 3 - 3
src/Services/Mail/Ses.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Mail;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Aws\Ses\SesClient;
 
 final class Ses extends Base
@@ -13,7 +13,7 @@ final class Ses extends Base
 
     public function __construct()
     {
-        $configs = Setting::getClass('email');
+        $configs = Config::getClass('email');
 
         $ses = new SesClient([
             'credentials' => [
@@ -36,7 +36,7 @@ final class Ses extends Base
             'Destination' => [
                 'ToAddresses' => [$to],
             ],
-            'Source' => Setting::obtain('aws_ses_sender'),
+            'Source' => Config::obtain('aws_ses_sender'),
             'Message' => [
                 'Body' => [
                     'Html' => [

+ 2 - 2
src/Services/Mail/Smtp.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Mail;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Exception;
 use PHPMailer\PHPMailer\PHPMailer;
 
@@ -17,7 +17,7 @@ final class Smtp extends Base
      */
     public function __construct()
     {
-        $configs = Setting::getClass('email');
+        $configs = Config::getClass('email');
 
         $mail = new PHPMailer();
         //$mail->SMTPDebug = 3;                               // Enable verbose debug output

+ 2 - 2
src/Services/Password.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Utils\Tools;
 use Psr\Http\Client\ClientExceptionInterface;
 use RedisException;
@@ -20,7 +20,7 @@ final class Password
         $redis = Cache::initRedis();
         $token = Tools::genRandomChar(64);
 
-        $redis->setex('password_reset:' . $token, Setting::obtain('email_password_reset_ttl'), $email);
+        $redis->setex('password_reset:' . $token, Config::obtain('email_password_reset_ttl'), $email);
 
         $subject = $_ENV['appName'] . '-重置密码';
         $resetUrl = $_ENV['baseUrl'] . '/password/token/' . $token;

+ 4 - 4
src/Services/RateLimit.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services;
 
-use App\Models\Setting;
+use App\Models\Config;
 use RateLimit\Exception\LimitExceeded;
 use RateLimit\Rate;
 use RateLimit\RedisRateLimiter;
@@ -113,7 +113,7 @@ final class RateLimit
     public static function checkEmailIpLimit(string $request_ip): bool
     {
         $email_ip_limiter = new RedisRateLimiter(
-            Rate::perHour(Setting::obtain('email_request_ip_limit')),
+            Rate::perHour(Config::obtain('email_request_ip_limit')),
             Cache::initRedis()
         );
 
@@ -132,7 +132,7 @@ final class RateLimit
     public static function checkEmailAddressLimit(string $request_address): bool
     {
         $email_address_limiter = new RedisRateLimiter(
-            Rate::perHour(Setting::obtain('email_request_address_limit')),
+            Rate::perHour(Config::obtain('email_request_address_limit')),
             Cache::initRedis()
         );
 
@@ -151,7 +151,7 @@ final class RateLimit
     public static function checkTicketLimit(int $user_id): bool
     {
         $ticket_limiter = new RedisRateLimiter(
-            Rate::custom(Setting::obtain('ticket_limit'), 2592000),
+            Rate::custom(Config::obtain('ticket_limit'), 2592000),
             Cache::initRedis()
         );
 

+ 2 - 2
src/Services/Subscribe/SIP002.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Subscribe;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Subscribe;
 use function json_decode;
 use const PHP_EOL;
@@ -15,7 +15,7 @@ final class SIP002 extends Base
     {
         $links = '';
         //判断是否开启SS订阅
-        if (! Setting::obtain('enable_ss_sub')) {
+        if (! Config::obtain('enable_ss_sub')) {
             return $links;
         }
 

+ 2 - 2
src/Services/Subscribe/SIP008.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Subscribe;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Subscribe;
 use function json_decode;
 use function json_encode;
@@ -15,7 +15,7 @@ final class SIP008 extends Base
     {
         $nodes = [];
         //判断是否开启SS订阅
-        if (! Setting::obtain('enable_ss_sub')) {
+        if (! Config::obtain('enable_ss_sub')) {
             return '';
         }
 

+ 2 - 2
src/Services/Subscribe/SS.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Subscribe;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Subscribe;
 use function base64_encode;
 use const PHP_EOL;
@@ -15,7 +15,7 @@ final class SS extends Base
     {
         $links = '';
         //判断是否开启SS订阅
-        if (! Setting::obtain('enable_ss_sub')) {
+        if (! Config::obtain('enable_ss_sub')) {
             return $links;
         }
 

+ 2 - 2
src/Services/Subscribe/Trojan.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Subscribe;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Subscribe;
 use function json_decode;
 use const PHP_EOL;
@@ -15,7 +15,7 @@ final class Trojan extends Base
     {
         $links = '';
         //判断是否开启Trojan订阅
-        if (! Setting::obtain('enable_trojan_sub')) {
+        if (! Config::obtain('enable_trojan_sub')) {
             return $links;
         }
 

+ 2 - 2
src/Services/Subscribe/V2Ray.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services\Subscribe;
 
-use App\Models\Setting;
+use App\Models\Config;
 use App\Services\Subscribe;
 use function base64_encode;
 use function json_decode;
@@ -17,7 +17,7 @@ final class V2Ray extends Base
     {
         $links = '';
         //判断是否开启V2Ray订阅
-        if (! Setting::obtain('enable_v2_sub')) {
+        if (! Config::obtain('enable_v2_sub')) {
             return $links;
         }
 

+ 24 - 3
src/Services/View.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Services;
 
-use App\Models\Setting;
+use App\Models\Config;
 use Illuminate\Database\DatabaseManager;
 use Smarty;
 
@@ -29,10 +29,31 @@ final class View
         $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); //设置生成文件存放目录
         $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); //设置缓存文件存放目录
         // add config
-        $smarty->assign('config', Config::getViewConfig());
-        $smarty->assign('public_setting', Setting::getPublicConfig());
+        $smarty->assign('config', self::getConfig());
+        $smarty->assign('public_setting', Config::getPublicConfig());
         $smarty->assign('user', $user);
 
         return $smarty;
     }
+
+    public static function getConfig(): array
+    {
+        return [
+            'appName' => $_ENV['appName'],
+            'baseUrl' => $_ENV['baseUrl'],
+
+            'enable_checkin' => $_ENV['enable_checkin'],
+            'checkinMin' => $_ENV['checkinMin'],
+            'checkinMax' => $_ENV['checkinMax'],
+
+            'jump_delay' => $_ENV['jump_delay'],
+
+            'enable_kill' => $_ENV['enable_kill'],
+            'enable_change_email' => $_ENV['enable_change_email'],
+
+            'enable_r2_client_download' => $_ENV['enable_r2_client_download'],
+
+            'jsdelivr_url' => $_ENV['jsdelivr_url'],
+        ];
+    }
 }

+ 26 - 8
src/Utils/Tools.php

@@ -4,10 +4,9 @@ declare(strict_types=1);
 
 namespace App\Utils;
 
+use App\Models\Config;
 use App\Models\Link;
-use App\Models\Setting;
 use App\Models\User;
-use App\Services\Config;
 use App\Services\GeoIP2;
 use GeoIp2\Exception\AddressNotFoundException;
 use MaxMind\Db\Reader\InvalidDatabaseException;
@@ -245,16 +244,16 @@ final class Tools
 
     public static function getSsPort(): int
     {
-        if (Setting::obtain('min_port') > 65535
-            || Setting::obtain('min_port') <= 0
-            || Setting::obtain('max_port') > 65535
-            || Setting::obtain('max_port') <= 0
+        if (Config::obtain('min_port') > 65535
+            || Config::obtain('min_port') <= 0
+            || Config::obtain('max_port') > 65535
+            || Config::obtain('max_port') <= 0
         ) {
             return 0;
         }
 
         $det = User::pluck('port')->toArray();
-        $port = array_diff(range(Setting::obtain('min_port'), Setting::obtain('max_port')), $det);
+        $port = array_diff(range(Config::obtain('min_port'), Config::obtain('max_port')), $det);
         shuffle($port);
 
         return $port[0];
@@ -294,7 +293,7 @@ final class Tools
      */
     public static function isParamValidate($type, $str): bool
     {
-        $list = Config::getSsMethod($type);
+        $list = self::getSsMethod($type);
 
         if (in_array($str, $list)) {
             return true;
@@ -303,6 +302,25 @@ final class Tools
         return false;
     }
 
+    public static function getSsMethod($type): array
+    {
+        return match ($type) {
+            'ss_obfs' => [
+                'simple_obfs_http',
+                'simple_obfs_http_compatible',
+                'simple_obfs_tls',
+                'simple_obfs_tls_compatible',
+            ],
+            default => [
+                'aes-128-gcm',
+                'aes-192-gcm',
+                'aes-256-gcm',
+                'chacha20-ietf-poly1305',
+                'xchacha20-ietf-poly1305',
+            ],
+        };
+    }
+
     /**
      * @param $email
      *

+ 0 - 148
tests/App/Services/ConfigTest.php

@@ -1,148 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Services;
-
-use PHPUnit\Framework\TestCase;
-use App\Services\Config;
-
-class ConfigTest extends TestCase
-{
-    /**
-     * @covers App\Services\Config::getViewConfig
-     */
-    public function testGetPublicConfig(): void
-    {
-        $_ENV = [
-            'appName' => 'My App',
-            'baseUrl' => 'https://example.com',
-            'enable_checkin' => true,
-            'checkinMin' => 10,
-            'checkinMax' => 20,
-            'jump_delay' => 5,
-            'enable_kill' => true,
-            'enable_change_email' => false,
-            'enable_r2_client_download' => true,
-            'jsdelivr_url' => 'cdn.jsdelivr.net',
-        ];
-
-        $mockEnv = [
-            'appName' => 'My App',
-            'baseUrl' => 'https://example.com',
-            'enable_checkin' => true,
-            'checkinMin' => 10,
-            'checkinMax' => 20,
-            'jump_delay' => 5,
-            'enable_kill' => true,
-            'enable_change_email' => false,
-            'enable_r2_client_download' => true,
-            'jsdelivr_url' => 'cdn.jsdelivr.net',
-        ];
-
-        $config = Config::getViewConfig();
-
-        $this->assertSame($mockEnv['appName'], $config['appName']);
-        $this->assertSame($mockEnv['baseUrl'], $config['baseUrl']);
-        $this->assertSame($mockEnv['enable_checkin'], $config['enable_checkin']);
-        $this->assertSame($mockEnv['checkinMin'], $config['checkinMin']);
-        $this->assertSame($mockEnv['checkinMax'], $config['checkinMax']);
-        $this->assertSame($mockEnv['jump_delay'], $config['jump_delay']);
-        $this->assertSame($mockEnv['enable_kill'], $config['enable_kill']);
-        $this->assertSame($mockEnv['enable_change_email'], $config['enable_change_email']);
-        $this->assertSame($mockEnv['enable_r2_client_download'], $config['enable_r2_client_download']);
-        $this->assertSame($mockEnv['jsdelivr_url'], $config['jsdelivr_url']);
-    }
-
-    /**
-     * @covers App\Services\Config::getRedisConfig
-     */
-    public function testGetRedisConfig(): void
-    {
-        $_ENV = [
-            'redis_host' => 'localhost',
-            'redis_port' => 6379,
-            'redis_timeout' => 10,
-            'redis_username' => 'myuser',
-            'redis_password' => 'mypassword',
-            'redis_ssl' => false,
-        ];
-
-        $mockEnv = [
-            'redis_host' => 'localhost',
-            'redis_port' => 6379,
-            'redis_timeout' => 10,
-            'redis_username' => 'myuser',
-            'redis_password' => 'mypassword',
-            'redis_ssl' => false,
-        ];
-
-        $config = Config::getRedisConfig();
-
-        $this->assertSame($mockEnv['redis_host'], $config['host']);
-        $this->assertSame($mockEnv['redis_port'], $config['port']);
-        $this->assertSame($mockEnv['redis_timeout'], $config['connectTimeout']);
-        $this->assertSame([$mockEnv['redis_username'], $mockEnv['redis_password']], $config['auth']);
-        $this->assertSame(['verify_peer' => $mockEnv['redis_ssl']], $config['ssl']);
-    }
-
-    /**
-     * @covers App\Services\Config::getDbConfig
-     */
-    public function testGetDbConfig(): void
-    {
-        $_ENV = [
-            'db_driver' => 'mysql',
-            'db_host' => 'localhost',
-            'db_socket' => '/var/run/mysqld/mysqld.sock',
-            'db_database' => 'mydb',
-            'db_username' => 'myuser',
-            'db_password' => 'mypassword',
-            'db_charset' => 'utf8mb4',
-            'db_collation' => 'utf8mb4_unicode_ci',
-            'db_prefix' => '',
-            'db_port' => 3306,
-        ];
-
-        $mockEnv = [
-            'db_driver' => 'mysql',
-            'db_host' => 'localhost',
-            'db_socket' => '/var/run/mysqld/mysqld.sock',
-            'db_database' => 'mydb',
-            'db_username' => 'myuser',
-            'db_password' => 'mypassword',
-            'db_charset' => 'utf8mb4',
-            'db_collation' => 'utf8mb4_unicode_ci',
-            'db_prefix' => '',
-            'db_port' => 3306,
-        ];
-
-        $config = Config::getDbConfig();
-
-        $this->assertSame($mockEnv['db_driver'], $config['driver']);
-        $this->assertSame($mockEnv['db_host'], $config['host']);
-        $this->assertSame($mockEnv['db_socket'], $config['unix_socket']);
-        $this->assertSame($mockEnv['db_database'], $config['database']);
-        $this->assertSame($mockEnv['db_username'], $config['username']);
-        $this->assertSame($mockEnv['db_password'], $config['password']);
-        $this->assertSame($mockEnv['db_charset'], $config['charset']);
-        $this->assertSame($mockEnv['db_collation'], $config['collation']);
-        $this->assertSame($mockEnv['db_prefix'], $config['prefix']);
-        $this->assertSame($mockEnv['db_port'], $config['port']);
-    }
-
-    /**
-     * @covers App\Services\Config::getSsMethod
-     */
-    public function testGetSsMethod(): void
-    {
-        $params = Config::getSsMethod('ss_aead_method');
-
-        $this->assertIsArray($params);
-        $this->assertContains('aes-128-gcm', $params);
-        $this->assertContains('aes-192-gcm', $params);
-        $this->assertContains('aes-256-gcm', $params);
-        $this->assertContains('chacha20-ietf-poly1305', $params);
-        $this->assertContains('xchacha20-ietf-poly1305', $params);
-    }
-}