Browse Source

refactor: subscribe log

M1Screw 2 years ago
parent
commit
fc18d32d74

+ 12 - 12
composer.lock

@@ -123,16 +123,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.276.0",
+            "version": "3.276.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "ae3ea70a1e189501ef3d1e923b9eb8ae2525c365"
+                "reference": "c8b38cfab677a3ec98e3f40bccd1a2bf851a014f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/ae3ea70a1e189501ef3d1e923b9eb8ae2525c365",
-                "reference": "ae3ea70a1e189501ef3d1e923b9eb8ae2525c365",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c8b38cfab677a3ec98e3f40bccd1a2bf851a014f",
+                "reference": "c8b38cfab677a3ec98e3f40bccd1a2bf851a014f",
                 "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.276.0"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.276.3"
             },
-            "time": "2023-07-19T18:24:20+00:00"
+            "time": "2023-07-21T18:30:18+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -4813,16 +4813,16 @@
         },
         {
             "name": "stripe/stripe-php",
-            "version": "v10.17.0",
+            "version": "v10.18.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/stripe/stripe-php.git",
-                "reference": "73383b44de153f4d602b90dad3ef075259bcecef"
+                "reference": "c32549e443a619d1b885b99d624568ecae82d6a0"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/73383b44de153f4d602b90dad3ef075259bcecef",
-                "reference": "73383b44de153f4d602b90dad3ef075259bcecef",
+                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/c32549e443a619d1b885b99d624568ecae82d6a0",
+                "reference": "c32549e443a619d1b885b99d624568ecae82d6a0",
                 "shasum": ""
             },
             "require": {
@@ -4868,9 +4868,9 @@
             ],
             "support": {
                 "issues": "https://github.com/stripe/stripe-php/issues",
-                "source": "https://github.com/stripe/stripe-php/tree/v10.17.0"
+                "source": "https://github.com/stripe/stripe-php/tree/v10.18.0"
             },
-            "time": "2023-07-13T22:12:18+00:00"
+            "time": "2023-07-20T16:59:49+00:00"
         },
         {
             "name": "symfony/console",

+ 1 - 2
db/2022.12_to_2022.12.1.sql

@@ -8,5 +8,4 @@ ALTER TABLE link DROP FOREIGN KEY link_ibfk_1;
 ALTER TABLE login_ip DROP FOREIGN KEY login_ip_ibfk_1;
 ALTER TABLE paylist DROP FOREIGN KEY paylist_ibfk_1;
 ALTER TABLE user_hourly_usage DROP FOREIGN KEY user_hourly_usage_ibfk_1;
-ALTER TABLE user_invite_code DROP FOREIGN KEY user_invite_code_ibfk_1;
-ALTER TABLE user_subscribe_log DROP FOREIGN KEY user_subscribe_log_ibfk_1;
+ALTER TABLE user_invite_code DROP FOREIGN KEY user_invite_code_ibfk_1;

+ 11 - 13
db/migrations/2023020100-init.php

@@ -233,6 +233,17 @@ return new class() implements MigrationInterface {
                 KEY `type` (`type`),
                 KEY `status` (`status`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+            
+            CREATE TABLE `subscribe_log` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
+                `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_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '请求时间',
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
             CREATE TABLE `ticket` (
                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '工单ID',
@@ -354,19 +365,6 @@ return new class() implements MigrationInterface {
                 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 PRIMARY KEY (`id`),
                 KEY `user_id` (`user_id`)
-            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-
-            CREATE TABLE `user_subscribe_log` (
-                `id` bigint(20) 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 '用户邮箱',
-                `subscribe_type` varchar(255) NOT NULL DEFAULT '' COMMENT '获取的订阅类型',
-                `request_ip` varchar(255) NOT NULL DEFAULT '' COMMENT '请求IP',
-                `request_time` timestamp NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '请求时间',
-                `request_user_agent` varchar(255) NOT NULL DEFAULT '' COMMENT '请求UA信息',
-                PRIMARY KEY (`id`),
-                KEY `user_id` (`user_id`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
         );
 

+ 0 - 8
db/migrations/2023061800-update_new_shop_data_type.php

@@ -168,14 +168,6 @@ return new class() implements MigrationInterface {
         ALTER TABLE user_invite_code MODIFY COLUMN `created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '创建时间';
         ALTER TABLE user_invite_code MODIFY COLUMN `updated_at` timestamp NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '更新时间';
         ALTER TABLE user_money_log MODIFY COLUMN `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `user_name` varchar(255) NOT NULL DEFAULT '' COMMENT '用户名';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `email` varchar(255) NOT NULL DEFAULT '' COMMENT '用户邮箱';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `subscribe_type` varchar(255) NOT NULL DEFAULT '' COMMENT '获取的订阅类型';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `request_ip` varchar(255) NOT NULL DEFAULT '' COMMENT '请求IP';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `request_time` timestamp NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '请求时间';
-        ALTER TABLE user_subscribe_log MODIFY COLUMN `request_user_agent` varchar(255) NOT NULL DEFAULT '' COMMENT '请求UA信息';
         SET FOREIGN_KEY_CHECKS = 1;");
 
         return 2023061800;

+ 48 - 0
db/migrations/2023072000-add_sub_log.php

@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+
+use App\Interfaces\MigrationInterface;
+use App\Services\DB;
+
+return new class() implements MigrationInterface {
+    public function up(): int
+    {
+        DB::getPdo()->exec("
+            CREATE TABLE IF NOT EXISTS `subscribe_log` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
+                `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_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '请求时间',
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+            DROP TABLE IF EXISTS `user_subscribe_log`;
+        ");
+
+        return 2023072000;
+    }
+
+    public function down(): int
+    {
+        DB::getPdo()->exec("
+            CREATE TABLE IF NOT EXISTS `user_subscribe_log` (
+                `id` bigint(20) 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 '用户邮箱',
+                `subscribe_type` varchar(255) NOT NULL DEFAULT '' COMMENT '获取的订阅类型',
+                `request_ip` varchar(255) NOT NULL DEFAULT '' COMMENT '请求IP',
+                `request_time` timestamp NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '请求时间',
+                `request_user_agent` varchar(255) NOT NULL DEFAULT '' COMMENT '请求UA信息',
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+            DROP TABLE IF EXISTS `subscribe_log`;
+        ");
+
+        return 2023071700;
+    }
+};

+ 0 - 0
resources/views/tabler/admin/subscribe.tpl → resources/views/tabler/admin/log/subscribe.tpl


+ 1 - 1
resources/views/tabler/user/subscribe_log.tpl

@@ -36,7 +36,7 @@
                                     {foreach $logs as $log}
                                     <tr>
                                         <td>#{$log->id}</td>
-                                        <td>{$log->subscribe_type}</td>
+                                        <td>{$log->type}</td>
                                         <td>{$log->request_ip}</td>
                                         <td>{$log->location}</td>
                                         <td>{$log->request_time}</td>

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

@@ -8,12 +8,12 @@ use App\Controllers\BaseController;
 use App\Models\Ann;
 use App\Models\User;
 use App\Utils\Telegram;
+use App\Utils\Tools;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Response;
 use Slim\Http\ServerRequest;
 use Telegram\Bot\Exceptions\TelegramSDKException;
-use function date;
 use function str_replace;
 use function strip_tags;
 use const PHP_EOL;
@@ -84,7 +84,7 @@ final class AnnController extends BaseController
 
         if ($content !== '') {
             $ann = new Ann();
-            $ann->date = date('Y-m-d H:i:s');
+            $ann->date = Tools::toDateTime(time());
             $ann->content = $content;
 
             if (! $ann->save()) {
@@ -154,7 +154,7 @@ final class AnnController extends BaseController
     {
         $ann = Ann::find($args['id']);
         $ann->content = (string) $request->getParam('content');
-        $ann->date = date('Y-m-d H:i:s');
+        $ann->date = Tools::toDateTime(time());
 
         if (! $ann->save()) {
             return $response->withJson([

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

@@ -8,12 +8,12 @@ use App\Controllers\BaseController;
 use App\Models\Docs;
 use App\Services\ChatGPT;
 use App\Services\PaLM;
+use App\Utils\Tools;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
 use Slim\Http\Response;
 use Slim\Http\ServerRequest;
 use Telegram\Bot\Exceptions\TelegramSDKException;
-use function date;
 
 final class DocsController extends BaseController
 {
@@ -70,7 +70,7 @@ final class DocsController extends BaseController
         }
 
         $doc = new Docs();
-        $doc->date = date('Y-m-d H:i:s');
+        $doc->date = Tools::toDateTime(time());
         $doc->title = $title;
         $doc->content = $content;
 
@@ -139,7 +139,7 @@ final class DocsController extends BaseController
         $doc = Docs::find($args['id']);
         $doc->title = $request->getParam('title');
         $doc->content = $request->getParam('content');
-        $doc->date = date('Y-m-d H:i:s');
+        $doc->date = Tools::toDateTime(time());
 
         if (! $doc->save()) {
             return $response->withJson([

+ 6 - 8
src/Controllers/Admin/SubscribeLogController.php

@@ -5,7 +5,7 @@ declare(strict_types=1);
 namespace App\Controllers\Admin;
 
 use App\Controllers\BaseController;
-use App\Models\UserSubscribeLog;
+use App\Models\SubscribeLog;
 use App\Utils\Tools;
 use Exception;
 use GeoIp2\Exception\AddressNotFoundException;
@@ -20,10 +20,8 @@ final class SubscribeLogController extends BaseController
     [
         'field' => [
             'id' => '事件ID',
-            'user_name' => '用户名',
             'user_id' => '用户ID',
-            'email' => '用户邮箱',
-            'subscribe_type' => '获取的订阅类型',
+            'type' => '获取的订阅类型',
             'request_ip' => '请求IP',
             'location' => 'IP归属地',
             'request_time' => '请求时间',
@@ -41,7 +39,7 @@ final class SubscribeLogController extends BaseController
         return $response->write(
             $this->view()
                 ->assign('details', self::$details)
-                ->fetch('admin/subscribe.tpl')
+                ->fetch('admin/log/subscribe.tpl')
         );
     }
 
@@ -57,11 +55,11 @@ final class SubscribeLogController extends BaseController
         $page = $request->getParam('start') / $length + 1;
         $draw = $request->getParam('draw');
 
-        $subscribes = UserSubscribeLog::orderBy('id', 'desc')->paginate($length, '*', '', $page);
-        $total = UserSubscribeLog::count();
+        $subscribes = SubscribeLog::orderBy('id', 'desc')->paginate($length, '*', '', $page);
+        $total = SubscribeLog::count();
 
         foreach ($subscribes as $subscribe) {
-            $subscribe->location = Tools::getIpLocation($subscribe->request_ip);
+            $subscribe->request_time = Tools::toDateTime($subscribe->request_time);
         }
 
         return $response->withJson([

+ 2 - 2
src/Controllers/LinkController.php

@@ -7,7 +7,7 @@ namespace App\Controllers;
 use App\Models\Link;
 use App\Models\Node;
 use App\Models\Setting;
-use App\Models\UserSubscribeLog;
+use App\Models\SubscribeLog;
 use App\Services\RateLimit;
 use App\Utils\ResponseHelper;
 use Psr\Http\Message\ResponseInterface;
@@ -81,7 +81,7 @@ final class LinkController extends BaseController
 
         // 记录订阅日志
         if ($_ENV['subscribeLog']) {
-            UserSubscribeLog::addSubscribeLog($user, $sub_type, $request->getHeaderLine('User-Agent'));
+            SubscribeLog::add($user, $sub_type, $request->getHeaderLine('User-Agent'));
         }
 
         $sub_details = ' upload=' . $user->u

+ 2 - 2
src/Controllers/SubController.php

@@ -7,7 +7,7 @@ namespace App\Controllers;
 use App\Models\Link;
 use App\Models\Node;
 use App\Models\Setting;
-use App\Models\UserSubscribeLog;
+use App\Models\SubscribeLog;
 use App\Services\RateLimit;
 use App\Utils\ResponseHelper;
 use App\Utils\Tools;
@@ -67,7 +67,7 @@ final class SubController extends BaseController
         };
 
         if ($_ENV['subscribeLog']) {
-            UserSubscribeLog::addSubscribeLog($user, $subtype, $request->getHeaderLine('User-Agent'));
+            SubscribeLog::add($user, $subtype, $request->getHeaderLine('User-Agent'));
         }
 
         if (in_array($subtype, ['json', 'sip008'])) {

+ 3 - 3
src/Controllers/User/LogController.php

@@ -6,7 +6,7 @@ namespace App\Controllers\User;
 
 use App\Controllers\BaseController;
 use App\Models\DetectLog;
-use App\Models\UserSubscribeLog;
+use App\Models\SubscribeLog;
 use App\Utils\Tools;
 use Exception;
 use Psr\Http\Message\ResponseInterface;
@@ -22,10 +22,10 @@ final class LogController extends BaseController
      */
     public function subscribe(ServerRequest $request, Response $response, array $args): Response|ResponseInterface
     {
-        $logs = UserSubscribeLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->get();
+        $logs = SubscribeLog::orderBy('id', 'desc')->where('user_id', $this->user->id)->get();
 
         foreach ($logs as $log) {
-            $log->location = Tools::getIpLocation($log->request_ip);
+            $log->request_time = Tools::toDateTime($log->request_time);
         }
 
         return $response->write($this->view()

+ 52 - 0
src/Models/SubscribeLog.php

@@ -0,0 +1,52 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Models;
+
+use App\Utils\Tools;
+use GeoIp2\Exception\AddressNotFoundException;
+use MaxMind\Db\Reader\InvalidDatabaseException;
+use voku\helper\AntiXSS;
+use function time;
+
+final class SubscribeLog extends Model
+{
+    protected $connection = 'default';
+    protected $table = 'subscribe_log';
+
+    /**
+     * 用户
+     */
+    public function user(): ?User
+    {
+        return User::find($this->user_id);
+    }
+
+    /**
+     * Ip 地理位置
+     */
+    public function getLocationAttribute(): string
+    {
+        try {
+            return Tools::getIpLocation($this->request_ip);
+        } catch (AddressNotFoundException | InvalidDatabaseException $e) {
+            return '未知';
+        }
+    }
+
+    /**
+     * 记录订阅日志
+     */
+    public static function add(User $user, string $type, string $ua): void
+    {
+        $log = new SubscribeLog();
+        $antiXss = new AntiXSS();
+        $log->user_id = $user->id;
+        $log->type = $antiXss->xss_clean($type);
+        $log->request_ip = $_SERVER['REMOTE_ADDR'];
+        $log->request_user_agent = $antiXss->xss_clean($ua);
+        $log->request_time = time();
+        $log->save();
+    }
+}

+ 1 - 1
src/Models/User.php

@@ -387,7 +387,7 @@ final class User extends Model
         OnlineLog::where('user_id', '=', $uid)->delete();
         Link::where('userid', '=', $uid)->delete();
         LoginIp::where('userid', '=', $uid)->delete();
-        UserSubscribeLog::where('user_id', '=', $uid)->delete();
+        SubscribeLog::where('user_id', '=', $uid)->delete();
 
         $this->delete();
 

+ 0 - 42
src/Models/UserSubscribeLog.php

@@ -1,42 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Models;
-
-use voku\helper\AntiXSS;
-
-final class UserSubscribeLog extends Model
-{
-    protected $connection = 'default';
-    protected $table = 'user_subscribe_log';
-
-    /**
-     * 用户
-     */
-    public function user(): ?User
-    {
-        return User::find($this->user_id);
-    }
-
-    /**
-     * 记录订阅日志
-     *
-     * @param User   $user 用户
-     * @param string $type 订阅类型
-     * @param string $ua   UA
-     */
-    public static function addSubscribeLog(User $user, string $type, string $ua): void
-    {
-        $log = new UserSubscribeLog();
-        $antiXss = new AntiXSS();
-        $log->user_name = $user->user_name;
-        $log->user_id = $user->id;
-        $log->email = $user->email;
-        $log->subscribe_type = $antiXss->xss_clean($type);
-        $log->request_ip = $_SERVER['REMOTE_ADDR'];
-        $log->request_time = date('Y-m-d H:i:s');
-        $log->request_user_agent = $antiXss->xss_clean($ua);
-        $log->save();
-    }
-}

+ 5 - 6
src/Services/CronDetect.php

@@ -10,8 +10,8 @@ use App\Models\Node;
 use App\Models\Setting;
 use App\Models\User;
 use App\Utils\Telegram;
+use App\Utils\Tools;
 use Telegram\Bot\Exceptions\TelegramSDKException;
-use function date;
 use function file_get_contents;
 use function in_array;
 use function json_decode;
@@ -139,10 +139,9 @@ final class CronDetect
 
             if ($detect_number >= $_ENV['auto_detect_ban_number']) {
                 $last_detect_ban_time = $user->last_detect_ban_time;
-                $end_time = date('Y-m-d H:i:s');
                 $user->is_banned = 1;
                 $user->banned_reason = 'DetectBan';
-                $user->last_detect_ban_time = $end_time;
+                $user->last_detect_ban_time = Tools::toDateTime(time());
                 $user->save();
                 $DetectBanLog = new DetectBanLog();
                 $DetectBanLog->user_name = $user->user_name;
@@ -151,13 +150,13 @@ final class CronDetect
                 $DetectBanLog->detect_number = $detect_number;
                 $DetectBanLog->ban_time = $_ENV['auto_detect_ban_time'];
                 $DetectBanLog->start_time = strtotime($last_detect_ban_time);
-                $DetectBanLog->end_time = strtotime($end_time);
+                $DetectBanLog->end_time = time();
                 $DetectBanLog->all_detect_number = $user->all_detect_number;
                 $DetectBanLog->save();
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 审计封禁检查结束' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 审计封禁检查结束' . PHP_EOL;
 
         // 审计封禁解封
         $banned_users = User::where('is_banned', 1)->where('banned_reason', 'DetectBan')->get();
@@ -171,6 +170,6 @@ final class CronDetect
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 审计解封检查结束' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 审计解封检查结束' . PHP_EOL;
     }
 }

+ 27 - 24
src/Services/CronJob.php

@@ -13,9 +13,9 @@ 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;
-use App\Models\UserSubscribeLog;
 use App\Utils\Telegram;
 use App\Utils\Tools;
 use DateTime;
@@ -54,21 +54,23 @@ final class CronJob
             $trafficlog->datetime = time();
             $trafficlog->save();
         }
+
+        echo Tools::toDateTime(time()) . ' 流量记录处理完成' . PHP_EOL;
     }
 
     public static function cleanDb(): void
     {
-        UserSubscribeLog::where(
+        SubscribeLog::where(
             'request_time',
             '<',
-            date('Y-m-d H:i:s', time() - 86400 * (int) $_ENV['subscribeLog_keep_days'])
+            time() - 86400 * (int) $_ENV['subscribeLog_keep_days']
         )->delete();
         UserHourlyUsage::where('datetime', '<', time() - 86400 * (int) $_ENV['trafficLog_keep_days'])->delete();
         DetectLog::where('datetime', '<', time() - 86400 * 3)->delete();
         EmailQueue::where('time', '<', time() - 86400)->delete();
         OnlineLog::where('last_time', '<', time() - 86400)->delete();
 
-        echo date('Y-m-d H:i:s') . ' 数据库清理完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 数据库清理完成' . PHP_EOL;
     }
 
     public static function detectInactiveUser(): void
@@ -91,7 +93,8 @@ final class CronJob
             ->where('last_use_time', '>', time() - 86400 * $use_days)
             ->update(['is_inactive' => 0]);
 
-        echo date('Y-m-d H:i:s') . ' 检测到 ' . User::where('is_inactive', '=', '1')->count() . ' 个账户处于闲置状态' . PHP_EOL;
+        echo Tools::toDateTime(time()) .
+            ' 检测到 ' . User::where('is_inactive', '=', '1')->count() . ' 个账户处于闲置状态' . PHP_EOL;
     }
 
     /**
@@ -163,7 +166,7 @@ final class CronJob
                 $node->save();
             }
         }
-        echo date('Y-m-d H:i:s') . ' 节点离线检测完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 节点离线检测完成' . PHP_EOL;
     }
 
     public static function expirePaidUserAccount(): void
@@ -198,7 +201,7 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 付费用户过期检测完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 付费用户过期检测完成' . PHP_EOL;
     }
 
     public static function processEmailQueue(): void
@@ -208,7 +211,7 @@ final class CronJob
         //邮件队列处理
         while (true) {
             if (time() - $timestamp > 299) {
-                echo date('Y-m-d H:i:s') . '邮件队列处理超时,已跳过' . PHP_EOL;
+                echo Tools::toDateTime(time()) . '邮件队列处理超时,已跳过' . PHP_EOL;
                 break;
             }
             DB::beginTransaction();
@@ -240,7 +243,7 @@ final class CronJob
             DB::commit();
         }
 
-        echo date('Y-m-d H:i:s') . ' 邮件队列处理完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 邮件队列处理完成' . PHP_EOL;
     }
 
     public static function processTabpOrderActivation(): void
@@ -301,7 +304,7 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' TABP订单激活处理完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' TABP订单激活处理完成' . PHP_EOL;
     }
 
     public static function processBandwidthOrderActivation(): void
@@ -330,7 +333,7 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 流量包订单激活处理完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 流量包订单激活处理完成' . PHP_EOL;
     }
 
     /**
@@ -374,7 +377,7 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 时间包订单激活处理完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 时间包订单激活处理完成' . PHP_EOL;
     }
 
     public static function processPendingOrder(): void
@@ -409,21 +412,21 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 等待中订单处理完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 等待中订单处理完成' . PHP_EOL;
     }
 
     public static function resetNodeBandwidth(): void
     {
         Node::where('bandwidthlimit_resetday', date('d'))->update(['node_bandwidth' => 0]);
 
-        echo date('Y-m-d H:i:s') . ' 重设节点流量完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 重设节点流量完成' . PHP_EOL;
     }
 
     public static function resetTodayTraffic(): void
     {
         User::query()->update(['transfer_today' => 0]);
 
-        echo date('Y-m-d H:i:s') . ' 重设用户每日流量完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 重设用户每日流量完成' . PHP_EOL;
     }
 
     public static function resetFreeUserTraffic(): void
@@ -447,7 +450,7 @@ final class CronJob
             );
         }
 
-        echo date('Y-m-d H:i:s') . ' 重设免费用户流量完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 重设免费用户流量完成' . PHP_EOL;
     }
 
     public static function sendDailyFinanceMail(): void
@@ -482,7 +485,7 @@ final class CronJob
             );
         }
 
-        echo date('Y-m-d H:i:s') . ' 成功发送财务日报' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 成功发送财务日报' . PHP_EOL;
     }
 
     public static function sendWeeklyFinanceMail(): void
@@ -506,7 +509,7 @@ final class CronJob
             );
         }
 
-        echo date('Y-m-d H:i:s') . ' 成功发送财务周报' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 成功发送财务周报' . PHP_EOL;
     }
 
     public static function sendMonthlyFinanceMail(): void
@@ -530,7 +533,7 @@ final class CronJob
             );
         }
 
-        echo date('Y-m-d H:i:s') . ' 成功发送财务月报' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 成功发送财务月报' . PHP_EOL;
     }
 
     public static function sendPaidUserUsageLimitNotification(): void
@@ -576,7 +579,7 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 付费用户用量限制提醒完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 付费用户用量限制提醒完成' . PHP_EOL;
     }
 
     public static function sendDailyTrafficReport(): void
@@ -595,7 +598,7 @@ final class CronJob
             $user->sendDailyNotification($ann_latest);
         }
 
-        echo date('Y-m-d H:i:s') . ' 成功发送每日邮件' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 成功发送每日邮件' . PHP_EOL;
     }
 
     /**
@@ -605,7 +608,7 @@ final class CronJob
     {
         Telegram::send(Setting::obtain('telegram_daily_job_text'));
 
-        echo date('Y-m-d H:i:s') . ' 成功发送 Telegram 每日任务提示' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 成功发送 Telegram 每日任务提示' . PHP_EOL;
     }
 
     /**
@@ -629,7 +632,7 @@ final class CronJob
             )
         );
 
-        echo date('Y-m-d H:i:s') . ' 成功发送 Telegram 系统运行日志' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 成功发送 Telegram 系统运行日志' . PHP_EOL;
     }
 
     public static function updateNodeIp(): void
@@ -644,6 +647,6 @@ final class CronJob
             }
         }
 
-        echo date('Y-m-d H:i:s') . ' 更新节点 IP 完成' . PHP_EOL;
+        echo Tools::toDateTime(time()) . ' 更新节点 IP 完成' . PHP_EOL;
     }
 }

+ 27 - 12
src/Utils/Telegram/Callback.php

@@ -11,7 +11,7 @@ use App\Models\LoginIp;
 use App\Models\OnlineLog;
 use App\Models\Payback;
 use App\Models\Setting;
-use App\Models\UserSubscribeLog;
+use App\Models\SubscribeLog;
 use App\Services\Config;
 use App\Utils\Tools;
 use GeoIp2\Exception\AddressNotFoundException;
@@ -411,7 +411,11 @@ final class Callback
         switch ($OpEnd) {
             case 'login_log':
                 // 登录记录
-                $total = LoginIp::where('userid', '=', $this->User->id)->where('type', '=', 0)->orderBy('datetime', 'desc')->take(10)->get();
+                $total = LoginIp::where('userid', '=', $this->User->id)
+                    ->where('type', '=', 0)
+                    ->orderBy('datetime', 'desc')
+                    ->take(10)
+                    ->get();
                 $text = '<strong>以下是你最近 10 次的登录 IP 和地理位置:</strong>' . PHP_EOL;
                 $text .= PHP_EOL;
 
@@ -466,7 +470,9 @@ final class Callback
                 $paybacks = Payback::where('ref_by', $this->User->id)->orderBy('datetime', 'desc')->take(10)->get();
                 $temp = [];
                 foreach ($paybacks as $payback) {
-                    $temp[] = '<code>#' . $payback->id . ':' . ($payback->user() !== null ? $payback->user()->user_name : '已注销') . ':' . $payback->ref_get . ' 元</code>';
+                    $temp[] = '<code>#' . $payback->id .
+                        ':' . ($payback->user() !== null ? $payback->user()->user_name : '已注销') . ':' .
+                        $payback->ref_get . ' 元</code>';
                 }
                 $text = '<strong>以下是你最近 10 次返利记录:</strong>';
                 $text .= PHP_EOL . PHP_EOL;
@@ -485,11 +491,13 @@ final class Callback
                 break;
             case 'subscribe_log':
                 // 订阅记录
-                $logs = UserSubscribeLog::orderBy('id', 'desc')->where('user_id', $this->User->id)->take(10)->get();
+                $logs = SubscribeLog::orderBy('id', 'desc')->where('user_id', $this->User->id)->take(10)->get();
                 $temp = [];
                 foreach ($logs as $log) {
                     $location = Tools::getIpLocation($log->request_ip);
-                    $temp[] = '<code>' . $log->request_time . ' 在 [' . $log->request_ip . '] ' . $location . ' 访问了 ' . $log->subscribe_type . ' 订阅</code>';
+                    $temp[] = '<code>' . Tools::toDateTime($log->request_time) .
+                        ' 在 [' . $log->request_ip . '] ' . $location .
+                        ' 访问了 ' . $log->type . ' 订阅</code>';
                 }
                 $text = '<strong>以下是你最近 10 次订阅记录:</strong>';
                 $text .= PHP_EOL . PHP_EOL;
@@ -888,13 +896,20 @@ final class Callback
             $UniversalSub_Url = SubController::getUniversalSub($this->User);
             $TraditionalSub_Url = LinkController::getTraditionalSub($this->User);
             $text = match ($CallbackDataExplode[1]) {
-                'clash' => 'Clash 通用订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $UniversalSub_Url . '/clash</code>' . PHP_EOL . PHP_EOL,
-                'json' => 'Json 通用订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $UniversalSub_Url . '/json</code>' . PHP_EOL . PHP_EOL,
-                'sip008' => 'Shadowsocks SIP008 通用订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $UniversalSub_Url . '/sip008</code>' . PHP_EOL . PHP_EOL,
-                'ss' => 'Shadowsocks 传统订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $TraditionalSub_Url . '?ss=1</code>' . PHP_EOL . PHP_EOL,
-                'sip002' => 'Shadowsocks SIP002 传统订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $TraditionalSub_Url . '?sip002=1</code>' . PHP_EOL . PHP_EOL,
-                'v2' => 'V2Ray 传统订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $TraditionalSub_Url . '?v2ray=1</code>' . PHP_EOL . PHP_EOL,
-                'trojan' => 'Trojan 传统订阅地址:' . PHP_EOL . PHP_EOL . '<code>' . $TraditionalSub_Url . '?trojan=1</code>' . PHP_EOL . PHP_EOL,
+                'clash' => 'Clash 通用订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $UniversalSub_Url . '/clash</code>' . PHP_EOL . PHP_EOL,
+                'json' => 'Json 通用订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $UniversalSub_Url . '/json</code>' . PHP_EOL . PHP_EOL,
+                'sip008' => 'Shadowsocks SIP008 通用订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $UniversalSub_Url . '/sip008</code>' . PHP_EOL . PHP_EOL,
+                'ss' => 'Shadowsocks 传统订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $TraditionalSub_Url . '?ss=1</code>' . PHP_EOL . PHP_EOL,
+                'sip002' => 'Shadowsocks SIP002 传统订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $TraditionalSub_Url . '?sip002=1</code>' . PHP_EOL . PHP_EOL,
+                'v2' => 'V2Ray 传统订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $TraditionalSub_Url . '?v2ray=1</code>' . PHP_EOL . PHP_EOL,
+                'trojan' => 'Trojan 传统订阅地址:' . PHP_EOL . PHP_EOL .
+                    '<code>' . $TraditionalSub_Url . '?trojan=1</code>' . PHP_EOL . PHP_EOL,
                 default => '未知参数' . PHP_EOL . PHP_EOL,
             };
             $sendMessage = [