Browse Source

perf: optimize user invite page

M1Screw 2 years ago
parent
commit
90313bec2b

+ 0 - 26
db/migration_sample.php

@@ -1,26 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-use App\Interfaces\MigrationInterface;
-use App\Services\DB;
-
-return new class() implements MigrationInterface {
-    private const UP = <<< END
-        // Your upgrade SQL here 
-END;
-
-    private const DOWN = <<< END
-        // Your downgrade SQL here(optional)
-END;
-
-    public function up(): void
-    {
-        DB::getPdo()->exec(self::UP);
-    }
-
-    public function down(): void
-    {
-        DB::getPdo()->exec(self::DOWN);
-    }
-};

+ 0 - 432
db/migrations/20230201-init.php

@@ -1,432 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-use App\Interfaces\MigrationInterface;
-use App\Services\DB;
-
-return new class() implements MigrationInterface {
-    private const UP = <<< END
-      CREATE TABLE `alive_ip` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `nodeid` int(11) DEFAULT NULL,
-        `userid` int(11) DEFAULT NULL,
-        `ip` varchar(255) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `announcement` (
-        `id` int(11) NOT NULL AUTO_INCREMENT,
-        `date` datetime DEFAULT NULL,
-        `content` text DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `bought` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `userid` bigint(20) DEFAULT NULL,
-        `shopid` bigint(20) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT NULL,
-        `renew` bigint(20) DEFAULT NULL,
-        `coupon` varchar(255) DEFAULT NULL,
-        `price` decimal(12,2) DEFAULT NULL,
-        `is_notified` tinyint(1) DEFAULT 0,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `code` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `code` varchar(255) DEFAULT NULL,
-        `type` int(11) DEFAULT NULL,
-        `number` decimal(12,2) DEFAULT NULL,
-        `isused` int(11) DEFAULT 0,
-        `userid` bigint(20) DEFAULT NULL,
-        `usedatetime` datetime DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `config` (
-        `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
-        `item` varchar(255) DEFAULT NULL COMMENT '项',
-        `value` varchar(2048) DEFAULT NULL,
-        `class` varchar(255) DEFAULT 'default' COMMENT '配置分类',
-        `is_public` int(11) DEFAULT 0 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 `coupon` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `code` varchar(255) DEFAULT NULL,
-        `onetime` int(11) DEFAULT NULL,
-        `expire` bigint(20) DEFAULT NULL,
-        `shop` varchar(255) DEFAULT NULL,
-        `credit` int(11) DEFAULT NULL,
-        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,
-        `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
-        `user_id` bigint(20) unsigned DEFAULT NULL COMMENT '用户 ID',
-        `email` varchar(255) DEFAULT NULL COMMENT '用户邮箱',
-        `detect_number` int(11) DEFAULT NULL COMMENT '本次违规次数',
-        `ban_time` int(11) DEFAULT NULL COMMENT '本次封禁时长',
-        `start_time` bigint(20) DEFAULT NULL COMMENT '统计开始时间',
-        `end_time` bigint(20) DEFAULT NULL COMMENT '统计结束时间',
-        `all_detect_number` int(11) DEFAULT NULL COMMENT '累计违规次数',
-        PRIMARY KEY (`id`),
-        KEY `user_id` (`user_id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `detect_list` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `name` varchar(255) DEFAULT NULL,
-        `text` varchar(255) DEFAULT NULL,
-        `regex` varchar(255) DEFAULT NULL,
-        `type` int(11) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `detect_log` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `user_id` bigint(20) unsigned DEFAULT NULL,
-        `list_id` bigint(20) unsigned DEFAULT NULL,
-        `datetime` bigint(20) unsigned DEFAULT NULL,
-        `node_id` int(11) DEFAULT NULL,
-        `status` int(11) DEFAULT 0,
-        PRIMARY KEY (`id`),
-        KEY `user_id` (`user_id`),
-        KEY `node_id` (`node_id`),
-        KEY `list_id` (`list_id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `docs` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `date` datetime DEFAULT NULL,
-        `title` varchar(255) DEFAULT NULL,
-        `content` varchar(255) DEFAULT NULL,
-        `markdown` varchar(255) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `email_queue` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `to_email` varchar(255) DEFAULT NULL,
-        `subject` varchar(255) DEFAULT NULL,
-        `template` varchar(255) DEFAULT NULL,
-        `array` longtext DEFAULT NULL,
-        `time` int(11) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `email_verify` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `email` varchar(255) DEFAULT NULL,
-        `ip` varchar(255) DEFAULT NULL,
-        `code` varchar(255) DEFAULT NULL,
-        `expire_in` bigint(20) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `gift_card` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `card` text DEFAULT NULL COMMENT '卡号',
-        `balance` int(11) DEFAULT NULL COMMENT '余额',
-        `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
-        `status` int(11) DEFAULT NULL COMMENT '使用状态',
-        `use_time` int(11) DEFAULT NULL COMMENT '使用时间',
-        `use_user` int(11) DEFAULT NULL COMMENT '使用用户',
-        PRIMARY KEY (`id`),
-        KEY `id` (`id`),
-        KEY `status` (`status`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `invoice` (
-        `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '账单ID',
-        `user_id` int(11) DEFAULT NULL COMMENT '归属用户',
-        `order_id` int(11) DEFAULT NULL COMMENT '订单ID',
-        `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账单内容' CHECK (json_valid(`content`)),
-        `price` double DEFAULT NULL COMMENT '账单金额',
-        `status` varchar(255) DEFAULT NULL COMMENT '账单状态',
-        `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
-        `update_time` int(11) DEFAULT NULL COMMENT '更新时间',
-        `pay_time` int(11) DEFAULT NULL COMMENT '支付时间',
-        PRIMARY KEY (`id`),
-        KEY `id` (`id`),
-        KEY `user_id` (`user_id`),
-        KEY `order_id` (`order_id`),
-        KEY `status` (`status`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `link` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `token` varchar(255) DEFAULT NULL,
-        `userid` bigint(20) unsigned DEFAULT NULL,
-        PRIMARY KEY (`id`),
-        UNIQUE KEY `token` (`token`),
-        UNIQUE KEY `userid` (`userid`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `login_ip` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `userid` bigint(20) unsigned DEFAULT NULL,
-        `ip` varchar(255) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT NULL,
-        `type` int(11) DEFAULT NULL,
-        PRIMARY KEY (`id`),
-        KEY `userid` (`userid`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `node` (
-        `id` int(11) NOT NULL AUTO_INCREMENT,
-        `name` varchar(255) DEFAULT NULL,
-        `type` int(11) DEFAULT NULL,
-        `server` varchar(255) DEFAULT NULL,
-        `custom_config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '{}' COMMENT '自定义配置' CHECK (json_valid(`custom_config`)),
-        `info` text DEFAULT '',
-        `status` varchar(255) DEFAULT '',
-        `sort` int(11) DEFAULT NULL,
-        `traffic_rate` float DEFAULT 1,
-        `node_class` int(11) DEFAULT 0,
-        `node_speedlimit` double NOT NULL DEFAULT 0 COMMENT '节点限速',
-        `node_connector` int(11) DEFAULT 0,
-        `node_bandwidth` bigint(20) DEFAULT 0,
-        `node_bandwidth_limit` bigint(20) DEFAULT 0,
-        `bandwidthlimit_resetday` int(11) DEFAULT 0,
-        `node_heartbeat` bigint(20) DEFAULT 0,
-        `online_user` int(11) DEFAULT 0 COMMENT '节点在线用户',
-        `node_ip` varchar(255) DEFAULT NULL,
-        `node_group` int(11) DEFAULT 0,
-        `mu_only` tinyint(1) DEFAULT 0,
-        `online` tinyint(1) DEFAULT 1,
-        `gfw_block` tinyint(1) DEFAULT 0,
-        `password` varchar(255) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `order` (
-        `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID',
-        `user_id` int(11) DEFAULT NULL COMMENT '提交用户',
-        `product_id` int(11) DEFAULT NULL COMMENT '商品ID',
-        `product_type` varchar(255) DEFAULT NULL COMMENT '商品类型',
-        `product_name` varchar(255) DEFAULT NULL COMMENT '商品名称',
-        `product_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品内容' CHECK (json_valid(`product_content`)),
-        `coupon` varchar(255) DEFAULT NULL COMMENT '订单优惠码',
-        `price` double DEFAULT NULL COMMENT '订单金额',
-        `status` varchar(255) DEFAULT NULL COMMENT '订单状态',
-        `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
-        `update_time` int(11) DEFAULT NULL COMMENT '更新时间',
-        PRIMARY KEY (`id`),
-        KEY `id` (`id`),
-        KEY `user_id` (`user_id`),
-        KEY `product_id` (`product_id`),
-        KEY `status` (`status`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `payback` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `total` decimal(12,2) DEFAULT NULL,
-        `userid` bigint(20) DEFAULT NULL,
-        `ref_by` bigint(20) DEFAULT NULL,
-        `ref_get` decimal(12,2) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `paylist` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `userid` bigint(20) unsigned DEFAULT NULL,
-        `total` decimal(12,2) DEFAULT NULL,
-        `status` int(11) DEFAULT 0,
-        `tradeno` varchar(255) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT 0,
-        PRIMARY KEY (`id`),
-        KEY `userid` (`userid`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `product` (
-        `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '商品ID',
-        `type` varchar(255) DEFAULT NULL COMMENT '类型',
-        `name` varchar(255) DEFAULT NULL COMMENT '名称',
-        `price` double DEFAULT NULL COMMENT '售价',
-        `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '内容' CHECK (json_valid(`content`)),
-        `limit` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '购买限制' CHECK (json_valid(`limit`)),
-        `status` int(11) DEFAULT NULL COMMENT '销售状态',
-        `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
-        `update_time` int(11) DEFAULT NULL COMMENT '更新时间',
-        `sale_count` int(11) DEFAULT NULL COMMENT '累计销售数',
-        `stock` int(11) DEFAULT NULL COMMENT '库存',
-        PRIMARY KEY (`id`),
-        KEY `id` (`id`),
-        KEY `type` (`type`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `shop` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `name` varchar(255) DEFAULT NULL,
-        `price` decimal(12,2) DEFAULT NULL,
-        `content` text DEFAULT NULL,
-        `auto_renew` int(11) DEFAULT NULL,
-        `auto_reset_bandwidth` int(11) DEFAULT 0,
-        `status` int(11) DEFAULT 1,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `stream_media` (
-        `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
-        `node_id` int(11) DEFAULT NULL COMMENT '节点id',
-        `result` text DEFAULT NULL COMMENT '检测结果',
-        `created_at` int(11) DEFAULT NULL COMMENT '创建时间',
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `telegram_session` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `user_id` bigint(20) DEFAULT NULL,
-        `type` int(11) DEFAULT NULL,
-        `session_content` varchar(255) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `ticket` (
-        `id` bigint(20) NOT NULL AUTO_INCREMENT,
-        `title` varchar(255) DEFAULT NULL,
-        `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '' COMMENT '工单内容' CHECK (json_valid(`content`)),
-        `userid` bigint(20) DEFAULT NULL,
-        `datetime` bigint(20) DEFAULT NULL,
-        `status` varchar(255) DEFAULT '' COMMENT '工单状态',
-        `type` varchar(255) DEFAULT 'other' COMMENT '工单类型',
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `user` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
-        `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
-        `email` varchar(255) DEFAULT NULL COMMENT 'E-Mail',
-        `pass` varchar(255) DEFAULT NULL COMMENT '登录密码',
-        `passwd` varchar(255) DEFAULT NULL COMMENT '节点密码',
-        `uuid` char(36) NOT NULL COMMENT 'UUID',
-        `t` bigint(20) unsigned DEFAULT 0 COMMENT '最后使用时间',
-        `u` bigint(20) unsigned DEFAULT 0 COMMENT '账户当前上传流量',
-        `d` bigint(20) unsigned DEFAULT 0 COMMENT '账户当前下载流量',
-        `transfer_total` bigint(20) unsigned DEFAULT 0 COMMENT '账户累计使用流量',
-        `transfer_enable` bigint(20) unsigned DEFAULT 0 COMMENT '账户当前可用流量',
-        `port` smallint(6) unsigned NOT NULL COMMENT '端口',
-        `last_detect_ban_time` datetime DEFAULT '1989-06-04 00:05:00' COMMENT '最后一次被封禁的时间',
-        `all_detect_number` int(11) DEFAULT 0 COMMENT '累计违规次数',
-        `last_check_in_time` bigint(20) unsigned DEFAULT 0 COMMENT '最后签到时间',
-        `reg_date` datetime DEFAULT NULL COMMENT '注册时间',
-        `invite_num` int(11) DEFAULT 0 COMMENT '可用邀请次数',
-        `money` decimal(10,2) NOT NULL DEFAULT 0.00,
-        `ref_by` bigint(20) unsigned DEFAULT 0 COMMENT '邀请人ID',
-        `method` varchar(255) DEFAULT 'rc4-md5' COMMENT 'Shadowsocks加密方式',
-        `reg_ip` varchar(255) DEFAULT '127.0.0.1' COMMENT '注册IP',
-        `node_speedlimit` double NOT NULL DEFAULT 0 COMMENT '用户限速',
-        `node_iplimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '同时可连接IP数',
-        `node_connector` int(11) DEFAULT 0 COMMENT '同时可使用连接数',
-        `is_admin` tinyint(1) DEFAULT 0 COMMENT '是否管理员',
-        `im_type` int(11) DEFAULT 1 COMMENT '联系方式类型',
-        `im_value` varchar(255) DEFAULT '' COMMENT '联系方式',
-        `last_day_t` bigint(20) DEFAULT 0 COMMENT '今天之前已使用的流量',
-        `sendDailyMail` tinyint(1) DEFAULT 0 COMMENT '每日报告开关',
-        `class` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '等级',
-        `class_expire` datetime DEFAULT '1989-06-04 00:05:00' COMMENT '等级过期时间',
-        `expire_in` datetime DEFAULT '2099-06-04 00:05:00',
-        `theme` varchar(255) DEFAULT NULL COMMENT '网站主题',
-        `ga_token` varchar(255) DEFAULT NULL,
-        `ga_enable` int(11) DEFAULT 0,
-        `remark` text DEFAULT '' COMMENT '备注',
-        `node_group` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '节点分组',
-        `is_banned` int(11) DEFAULT 0 COMMENT '是否封禁',
-        `banned_reason` varchar(255) DEFAULT '' COMMENT '封禁理由',
-        `telegram_id` bigint(20) DEFAULT 0,
-        `expire_notified` tinyint(1) DEFAULT 0,
-        `traffic_notified` tinyint(1) DEFAULT 0,
-        `forbidden_ip` varchar(255) DEFAULT '',
-        `forbidden_port` varchar(255) DEFAULT '',
-        `auto_reset_day` int(11) DEFAULT 0,
-        `auto_reset_bandwidth` decimal(12,2) DEFAULT 0.00,
-        `api_token` char(36) NOT NULL DEFAULT '' COMMENT 'API 密钥',
-        `use_new_shop` smallint(6) NOT NULL DEFAULT 0 COMMENT '是否启用新商店',
-        `is_dark_mode` int(11) DEFAULT 0,
-        PRIMARY KEY (`id`),
-        UNIQUE KEY `uuid` (`uuid`),
-        UNIQUE KEY `email` (`email`),
-        UNIQUE KEY `ga_token` (`ga_token`),
-        KEY `user_name` (`user_name`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `user_coupon` (
-        `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '优惠码ID',
-        `code` varchar(255) DEFAULT NULL COMMENT '优惠码',
-        `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '优惠码内容' CHECK (json_valid(`content`)),
-        `limit` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '优惠码限制' CHECK (json_valid(`limit`)),
-        `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
-        `expire_time` int(11) DEFAULT NULL COMMENT '过期时间',
-        PRIMARY KEY (`id`),
-        KEY `id` (`id`),
-        KEY `code` (`code`),
-        KEY `expire_time` (`expire_time`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `user_hourly_usage` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `user_id` bigint(20) unsigned DEFAULT NULL,
-        `traffic` bigint(20) DEFAULT NULL,
-        `hourly_usage` bigint(20) DEFAULT NULL,
-        `datetime` int(11) DEFAULT NULL,
-        PRIMARY KEY (`id`),
-        KEY `user_id` (`user_id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `user_invite_code` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `code` varchar(255) DEFAULT NULL,
-        `user_id` bigint(20) unsigned DEFAULT NULL,
-        `created_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
-        `updated_at` timestamp NULL DEFAULT '2016-05-31 15:00:00',
-        PRIMARY KEY (`id`),
-        UNIQUE KEY `code` (`code`),
-        UNIQUE KEY `user_id` (`user_id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `user_password_reset` (
-        `id` int(11) NOT NULL AUTO_INCREMENT,
-        `email` varchar(255) DEFAULT NULL,
-        `token` varchar(255) DEFAULT NULL,
-        `init_time` int(11) DEFAULT NULL,
-        `expire_time` int(11) DEFAULT NULL,
-        PRIMARY KEY (`id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-      
-      CREATE TABLE `user_subscribe_log` (
-        `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-        `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
-        `user_id` bigint(20) unsigned DEFAULT NULL COMMENT '用户 ID',
-        `email` varchar(255) DEFAULT NULL COMMENT '用户邮箱',
-        `subscribe_type` varchar(255) DEFAULT NULL COMMENT '获取的订阅类型',
-        `request_ip` varchar(255) DEFAULT NULL COMMENT '请求 IP',
-        `request_time` datetime DEFAULT NULL COMMENT '请求时间',
-        `request_user_agent` text DEFAULT NULL COMMENT '请求 UA 信息',
-        PRIMARY KEY (`id`),
-        KEY `user_id` (`user_id`)
-      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;   
-END;
-
-    private const DOWN = '';
-
-    public function up(): void
-    {
-        DB::getPdo()->exec(self::UP);
-    }
-
-    public function down(): void
-    {
-        echo "No reverse operation for initial migration\n";
-    }
-};

+ 442 - 0
db/migrations/2023020100-init.php

@@ -0,0 +1,442 @@
+<?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 `alive_ip` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `nodeid` int(11) DEFAULT NULL,
+                `userid` int(11) DEFAULT NULL,
+                `ip` varchar(255) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `announcement` (
+                `id` int(11) NOT NULL AUTO_INCREMENT,
+                `date` datetime DEFAULT NULL,
+                `content` text DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `bought` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `userid` bigint(20) DEFAULT NULL,
+                `shopid` bigint(20) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT NULL,
+                `renew` bigint(20) DEFAULT NULL,
+                `coupon` varchar(255) DEFAULT NULL,
+                `price` decimal(12,2) DEFAULT NULL,
+                `is_notified` tinyint(1) DEFAULT 0,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `code` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `code` varchar(255) DEFAULT NULL,
+                `type` int(11) DEFAULT NULL,
+                `number` decimal(12,2) DEFAULT NULL,
+                `isused` int(11) DEFAULT 0,
+                `userid` bigint(20) DEFAULT NULL,
+                `usedatetime` datetime DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `config` (
+                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
+                `item` varchar(255) DEFAULT NULL COMMENT '项',
+                `value` varchar(2048) DEFAULT NULL,
+                `class` varchar(255) DEFAULT 'default' COMMENT '配置分类',
+                `is_public` int(11) DEFAULT 0 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 `coupon` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `code` varchar(255) DEFAULT NULL,
+                `onetime` int(11) DEFAULT NULL,
+                `expire` bigint(20) DEFAULT NULL,
+                `shop` varchar(255) DEFAULT NULL,
+                `credit` int(11) DEFAULT NULL,
+                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,
+                `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
+                `user_id` bigint(20) unsigned DEFAULT NULL COMMENT '用户 ID',
+                `email` varchar(255) DEFAULT NULL COMMENT '用户邮箱',
+                `detect_number` int(11) DEFAULT NULL COMMENT '本次违规次数',
+                `ban_time` int(11) DEFAULT NULL COMMENT '本次封禁时长',
+                `start_time` bigint(20) DEFAULT NULL COMMENT '统计开始时间',
+                `end_time` bigint(20) DEFAULT NULL COMMENT '统计结束时间',
+                `all_detect_number` int(11) DEFAULT NULL COMMENT '累计违规次数',
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `detect_list` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `name` varchar(255) DEFAULT NULL,
+                `text` varchar(255) DEFAULT NULL,
+                `regex` varchar(255) DEFAULT NULL,
+                `type` int(11) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `detect_log` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `user_id` bigint(20) unsigned DEFAULT NULL,
+                `list_id` bigint(20) unsigned DEFAULT NULL,
+                `datetime` bigint(20) unsigned DEFAULT NULL,
+                `node_id` int(11) DEFAULT NULL,
+                `status` int(11) DEFAULT 0,
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`),
+                KEY `node_id` (`node_id`),
+                KEY `list_id` (`list_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `docs` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `date` datetime DEFAULT NULL,
+                `title` varchar(255) DEFAULT NULL,
+                `content` varchar(255) DEFAULT NULL,
+                `markdown` varchar(255) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `email_queue` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `to_email` varchar(255) DEFAULT NULL,
+                `subject` varchar(255) DEFAULT NULL,
+                `template` varchar(255) DEFAULT NULL,
+                `array` longtext DEFAULT NULL,
+                `time` int(11) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `email_verify` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `email` varchar(255) DEFAULT NULL,
+                `ip` varchar(255) DEFAULT NULL,
+                `code` varchar(255) DEFAULT NULL,
+                `expire_in` bigint(20) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `gift_card` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `card` text DEFAULT NULL COMMENT '卡号',
+                `balance` int(11) DEFAULT NULL COMMENT '余额',
+                `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
+                `status` int(11) DEFAULT NULL COMMENT '使用状态',
+                `use_time` int(11) DEFAULT NULL COMMENT '使用时间',
+                `use_user` int(11) DEFAULT NULL COMMENT '使用用户',
+                PRIMARY KEY (`id`),
+                KEY `id` (`id`),
+                KEY `status` (`status`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `invoice` (
+                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '账单ID',
+                `user_id` int(11) DEFAULT NULL COMMENT '归属用户',
+                `order_id` int(11) DEFAULT NULL COMMENT '订单ID',
+                `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '账单内容' CHECK (json_valid(`content`)),
+                `price` double DEFAULT NULL COMMENT '账单金额',
+                `status` varchar(255) DEFAULT NULL COMMENT '账单状态',
+                `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
+                `update_time` int(11) DEFAULT NULL COMMENT '更新时间',
+                `pay_time` int(11) DEFAULT NULL COMMENT '支付时间',
+                PRIMARY KEY (`id`),
+                KEY `id` (`id`),
+                KEY `user_id` (`user_id`),
+                KEY `order_id` (`order_id`),
+                KEY `status` (`status`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `link` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `token` varchar(255) DEFAULT NULL,
+                `userid` bigint(20) unsigned DEFAULT NULL,
+                PRIMARY KEY (`id`),
+                UNIQUE KEY `token` (`token`),
+                UNIQUE KEY `userid` (`userid`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `login_ip` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `userid` bigint(20) unsigned DEFAULT NULL,
+                `ip` varchar(255) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT NULL,
+                `type` int(11) DEFAULT NULL,
+                PRIMARY KEY (`id`),
+                KEY `userid` (`userid`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `node` (
+                `id` int(11) NOT NULL AUTO_INCREMENT,
+                `name` varchar(255) DEFAULT NULL,
+                `type` int(11) DEFAULT NULL,
+                `server` varchar(255) DEFAULT NULL,
+                `custom_config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '{}' COMMENT '自定义配置' CHECK (json_valid(`custom_config`)),
+                `info` text DEFAULT '',
+                `status` varchar(255) DEFAULT '',
+                `sort` int(11) DEFAULT NULL,
+                `traffic_rate` float DEFAULT 1,
+                `node_class` int(11) DEFAULT 0,
+                `node_speedlimit` double NOT NULL DEFAULT 0 COMMENT '节点限速',
+                `node_connector` int(11) DEFAULT 0,
+                `node_bandwidth` bigint(20) DEFAULT 0,
+                `node_bandwidth_limit` bigint(20) DEFAULT 0,
+                `bandwidthlimit_resetday` int(11) DEFAULT 0,
+                `node_heartbeat` bigint(20) DEFAULT 0,
+                `online_user` int(11) DEFAULT 0 COMMENT '节点在线用户',
+                `node_ip` varchar(255) DEFAULT NULL,
+                `node_group` int(11) DEFAULT 0,
+                `mu_only` tinyint(1) DEFAULT 0,
+                `online` tinyint(1) DEFAULT 1,
+                `gfw_block` tinyint(1) DEFAULT 0,
+                `password` varchar(255) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `order` (
+                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID',
+                `user_id` int(11) DEFAULT NULL COMMENT '提交用户',
+                `product_id` int(11) DEFAULT NULL COMMENT '商品ID',
+                `product_type` varchar(255) DEFAULT NULL COMMENT '商品类型',
+                `product_name` varchar(255) DEFAULT NULL COMMENT '商品名称',
+                `product_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '商品内容' CHECK (json_valid(`product_content`)),
+                `coupon` varchar(255) DEFAULT NULL COMMENT '订单优惠码',
+                `price` double DEFAULT NULL COMMENT '订单金额',
+                `status` varchar(255) DEFAULT NULL COMMENT '订单状态',
+                `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
+                `update_time` int(11) DEFAULT NULL COMMENT '更新时间',
+                PRIMARY KEY (`id`),
+                KEY `id` (`id`),
+                KEY `user_id` (`user_id`),
+                KEY `product_id` (`product_id`),
+                KEY `status` (`status`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `payback` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `total` decimal(12,2) DEFAULT NULL,
+                `userid` bigint(20) DEFAULT NULL,
+                `ref_by` bigint(20) DEFAULT NULL,
+                `ref_get` decimal(12,2) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `paylist` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `userid` bigint(20) unsigned DEFAULT NULL,
+                `total` decimal(12,2) DEFAULT NULL,
+                `status` int(11) DEFAULT 0,
+                `tradeno` varchar(255) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT 0,
+                PRIMARY KEY (`id`),
+                KEY `userid` (`userid`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `product` (
+                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '商品ID',
+                `type` varchar(255) DEFAULT NULL COMMENT '类型',
+                `name` varchar(255) DEFAULT NULL COMMENT '名称',
+                `price` double DEFAULT NULL COMMENT '售价',
+                `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '内容' CHECK (json_valid(`content`)),
+                `limit` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '购买限制' CHECK (json_valid(`limit`)),
+                `status` int(11) DEFAULT NULL COMMENT '销售状态',
+                `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
+                `update_time` int(11) DEFAULT NULL COMMENT '更新时间',
+                `sale_count` int(11) DEFAULT NULL COMMENT '累计销售数',
+                `stock` int(11) DEFAULT NULL COMMENT '库存',
+                PRIMARY KEY (`id`),
+                KEY `id` (`id`),
+                KEY `type` (`type`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `shop` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `name` varchar(255) DEFAULT NULL,
+                `price` decimal(12,2) DEFAULT NULL,
+                `content` text DEFAULT NULL,
+                `auto_renew` int(11) DEFAULT NULL,
+                `auto_reset_bandwidth` int(11) DEFAULT 0,
+                `status` int(11) DEFAULT 1,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `stream_media` (
+                `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+                `node_id` int(11) DEFAULT NULL COMMENT '节点id',
+                `result` text DEFAULT NULL COMMENT '检测结果',
+                `created_at` int(11) DEFAULT NULL COMMENT '创建时间',
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `telegram_session` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `user_id` bigint(20) DEFAULT NULL,
+                `type` int(11) DEFAULT NULL,
+                `session_content` varchar(255) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `ticket` (
+                `id` bigint(20) NOT NULL AUTO_INCREMENT,
+                `title` varchar(255) DEFAULT NULL,
+                `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT '' COMMENT '工单内容' CHECK (json_valid(`content`)),
+                `userid` bigint(20) DEFAULT NULL,
+                `datetime` bigint(20) DEFAULT NULL,
+                `status` varchar(255) DEFAULT '' COMMENT '工单状态',
+                `type` varchar(255) DEFAULT 'other' COMMENT '工单类型',
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
+                `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
+                `email` varchar(255) DEFAULT NULL COMMENT 'E-Mail',
+                `pass` varchar(255) DEFAULT NULL COMMENT '登录密码',
+                `passwd` varchar(255) DEFAULT NULL COMMENT '节点密码',
+                `uuid` char(36) NOT NULL COMMENT 'UUID',
+                `t` bigint(20) unsigned DEFAULT 0 COMMENT '最后使用时间',
+                `u` bigint(20) unsigned DEFAULT 0 COMMENT '账户当前上传流量',
+                `d` bigint(20) unsigned DEFAULT 0 COMMENT '账户当前下载流量',
+                `transfer_total` bigint(20) unsigned DEFAULT 0 COMMENT '账户累计使用流量',
+                `transfer_enable` bigint(20) unsigned DEFAULT 0 COMMENT '账户当前可用流量',
+                `port` smallint(6) unsigned NOT NULL COMMENT '端口',
+                `last_detect_ban_time` datetime DEFAULT '1989-06-04 00:05:00' COMMENT '最后一次被封禁的时间',
+                `all_detect_number` int(11) DEFAULT 0 COMMENT '累计违规次数',
+                `last_check_in_time` bigint(20) unsigned DEFAULT 0 COMMENT '最后签到时间',
+                `reg_date` datetime DEFAULT NULL COMMENT '注册时间',
+                `invite_num` int(11) DEFAULT 0 COMMENT '可用邀请次数',
+                `money` decimal(10,2) NOT NULL DEFAULT 0.00,
+                `ref_by` bigint(20) unsigned DEFAULT 0 COMMENT '邀请人ID',
+                `method` varchar(255) DEFAULT 'rc4-md5' COMMENT 'Shadowsocks加密方式',
+                `reg_ip` varchar(255) DEFAULT '127.0.0.1' COMMENT '注册IP',
+                `node_speedlimit` double NOT NULL DEFAULT 0 COMMENT '用户限速',
+                `node_iplimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '同时可连接IP数',
+                `node_connector` int(11) DEFAULT 0 COMMENT '同时可使用连接数',
+                `is_admin` tinyint(1) DEFAULT 0 COMMENT '是否管理员',
+                `im_type` int(11) DEFAULT 1 COMMENT '联系方式类型',
+                `im_value` varchar(255) DEFAULT '' COMMENT '联系方式',
+                `last_day_t` bigint(20) DEFAULT 0 COMMENT '今天之前已使用的流量',
+                `sendDailyMail` tinyint(1) DEFAULT 0 COMMENT '每日报告开关',
+                `class` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '等级',
+                `class_expire` datetime DEFAULT '1989-06-04 00:05:00' COMMENT '等级过期时间',
+                `expire_in` datetime DEFAULT '2099-06-04 00:05:00',
+                `theme` varchar(255) DEFAULT NULL COMMENT '网站主题',
+                `ga_token` varchar(255) DEFAULT NULL,
+                `ga_enable` int(11) DEFAULT 0,
+                `remark` text DEFAULT '' COMMENT '备注',
+                `node_group` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '节点分组',
+                `is_banned` int(11) DEFAULT 0 COMMENT '是否封禁',
+                `banned_reason` varchar(255) DEFAULT '' COMMENT '封禁理由',
+                `telegram_id` bigint(20) DEFAULT 0,
+                `expire_notified` tinyint(1) DEFAULT 0,
+                `traffic_notified` tinyint(1) DEFAULT 0,
+                `forbidden_ip` varchar(255) DEFAULT '',
+                `forbidden_port` varchar(255) DEFAULT '',
+                `auto_reset_day` int(11) DEFAULT 0,
+                `auto_reset_bandwidth` decimal(12,2) DEFAULT 0.00,
+                `api_token` char(36) NOT NULL DEFAULT '' COMMENT 'API 密钥',
+                `use_new_shop` smallint(6) NOT NULL DEFAULT 0 COMMENT '是否启用新商店',
+                `is_dark_mode` int(11) DEFAULT 0,
+                PRIMARY KEY (`id`),
+                UNIQUE KEY `uuid` (`uuid`),
+                UNIQUE KEY `email` (`email`),
+                UNIQUE KEY `ga_token` (`ga_token`),
+                KEY `user_name` (`user_name`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user_coupon` (
+                `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '优惠码ID',
+                `code` varchar(255) DEFAULT NULL COMMENT '优惠码',
+                `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '优惠码内容' CHECK (json_valid(`content`)),
+                `limit` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '优惠码限制' CHECK (json_valid(`limit`)),
+                `create_time` int(11) DEFAULT NULL COMMENT '创建时间',
+                `expire_time` int(11) DEFAULT NULL COMMENT '过期时间',
+                PRIMARY KEY (`id`),
+                KEY `id` (`id`),
+                KEY `code` (`code`),
+                KEY `expire_time` (`expire_time`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user_hourly_usage` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `user_id` bigint(20) unsigned DEFAULT NULL,
+                `traffic` bigint(20) DEFAULT NULL,
+                `hourly_usage` bigint(20) DEFAULT NULL,
+                `datetime` int(11) DEFAULT NULL,
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user_invite_code` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `code` varchar(255) DEFAULT NULL,
+                `user_id` bigint(20) unsigned DEFAULT NULL,
+                `created_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
+                `updated_at` timestamp NULL DEFAULT '2016-05-31 15:00:00',
+                PRIMARY KEY (`id`),
+                UNIQUE KEY `code` (`code`),
+                UNIQUE KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user_password_reset` (
+                `id` int(11) NOT NULL AUTO_INCREMENT,
+                `email` varchar(255) DEFAULT NULL,
+                `token` varchar(255) DEFAULT NULL,
+                `init_time` int(11) DEFAULT NULL,
+                `expire_time` int(11) DEFAULT NULL,
+                PRIMARY KEY (`id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user_subscribe_log` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `user_name` varchar(255) DEFAULT NULL COMMENT '用户名',
+                `user_id` bigint(20) unsigned DEFAULT NULL COMMENT '用户 ID',
+                `email` varchar(255) DEFAULT NULL COMMENT '用户邮箱',
+                `subscribe_type` varchar(255) DEFAULT NULL COMMENT '获取的订阅类型',
+                `request_ip` varchar(255) DEFAULT NULL COMMENT '请求 IP',
+                `request_time` datetime DEFAULT NULL COMMENT '请求时间',
+                `request_user_agent` text DEFAULT NULL COMMENT '请求 UA 信息',
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+
+            CREATE TABLE `user_token` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `token` varchar(255) DEFAULT NULL,
+                `user_id` bigint(20) unsigned DEFAULT NULL,
+                `create_time` bigint(20) unsigned DEFAULT NULL,
+                `expire_time` bigint(20) DEFAULT NULL,
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
+        );
+
+        return 2023020100;
+    }
+
+    public function down(): int
+    {
+        echo "No reverse operation for initial migration\n";
+
+        return 2023020100;
+    }
+};

+ 0 - 34
db/migrations/20230216-drop_user_token.php

@@ -1,34 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-use App\Interfaces\MigrationInterface;
-use App\Services\DB;
-
-return new class() implements MigrationInterface {
-    private const UP = <<< END
-        DROP TABLE IF EXISTS `user_token`;   
-END;
-
-    private const DOWN = <<< END
-        CREATE TABLE `user_token` (
-            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-            `token` varchar(255) DEFAULT NULL,
-            `user_id` bigint(20) unsigned DEFAULT NULL,
-            `create_time` bigint(20) unsigned DEFAULT NULL,
-            `expire_time` bigint(20) DEFAULT NULL,
-            PRIMARY KEY (`id`),
-            KEY `user_id` (`user_id`)
-          ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;   
-END;
-
-    public function up(): void
-    {
-        DB::getPdo()->exec(self::UP);
-    }
-
-    public function down(): void
-    {
-        DB::getPdo()->exec(self::DOWN);
-    }
-};

+ 32 - 0
db/migrations/2023021600-drop_user_token.php

@@ -0,0 +1,32 @@
+<?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('DROP TABLE IF EXISTS `user_token`');
+
+        return 2023021600;
+    }
+
+    public function down(): int
+    {
+        DB::getPdo()->exec(
+            "CREATE TABLE `user_token` (
+                `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+                `token` varchar(255) DEFAULT NULL,
+                `user_id` bigint(20) unsigned DEFAULT NULL,
+                `create_time` bigint(20) unsigned DEFAULT NULL,
+                `expire_time` bigint(20) DEFAULT NULL,
+                PRIMARY KEY (`id`),
+                KEY `user_id` (`user_id`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
+        );
+
+        return 2023020100;
+    }
+};

+ 1 - 1
db/update.sql

@@ -1,4 +1,4 @@
--- Update from phinx migration
+-- Update from phinx migration 20230115090200_add_user_coupon
 ALTER TABLE detect_ban_log DROP FOREIGN KEY detect_ban_log_ibfk_1;
 ALTER TABLE detect_log DROP FOREIGN KEY detect_log_ibfk_1;
 ALTER TABLE detect_log DROP FOREIGN KEY detect_log_ibfk_2;

+ 1 - 1
docker-compose.yml

@@ -10,7 +10,7 @@ services:
         volumes:
             - ./config/.config.php:/var/www/config/.config.php
     mariadb:
-        image: mariadb:10.9
+        image: mariadb:10.11
         container_name: mariadb
         restart: always
         environment:

+ 2 - 2
resources/views/tabler/user/invite.tpl

@@ -60,9 +60,9 @@
                                     <thead>
                                         <tr>
                                             <th>#</th>
+                                            <th>邀请用户ID</th>
                                             <th>邀请用户昵称</th>
                                             <th>返利金额</th>
-                                            <th>结算审核</th>
                                             <th>返利时间</th>
                                         </tr>
                                     </thead>
@@ -70,13 +70,13 @@
                                         {foreach $paybacks as $payback}
                                             <tr>
                                                 <td>{$payback->id}</td>
+                                                <td>{$payback->userid}</td>
                                                 {if $payback->user()!=null}
                                                     <td>{$payback->user()->user_name}</td>
                                                 {else}
                                                     <td>已注销</td>
                                                 {/if}
                                                 <td>{$payback->ref_get} 元</td>
-                                                <td>{$payback->fraud_detect}</td>
                                                 <td>{$payback->datetime}</td>
                                             </tr>
                                         {/foreach}

+ 19 - 22
src/Command/Migration.php

@@ -32,7 +32,7 @@ END;
         // (min_version, max_version]
         $min_version = 0;
         $max_version = 0;
-        
+
         $target = $this->argv[2] ?? 0;
 
         if ($target === 'new') {
@@ -50,7 +50,7 @@ END;
                 $min_version = 0;
                 $max_version = PHP_INT_MAX;
             } else {
-                echo "Database is not empty, do not use 'new' version.\n";
+                echo "Database is not empty, do not use \"new\" as version.\n";
                 return;
             }
         } elseif (is_numeric($target)) {
@@ -68,7 +68,7 @@ END;
             return;
         }
 
-        echo "Current database version {$current}.\n";
+        echo "Current database version {$current}.\n\n";
 
         $queue = [];
         $files = scandir(BASE_PATH . '/db/migrations/', SCANDIR_SORT_NONE);
@@ -77,46 +77,43 @@ END;
                 if ($file === '.' || $file === '..' || substr($file, -4) !== '.php') {
                     continue;
                 }
-                $version = (int) (explode('-', $file, 1)[0] ?? 0);
-                echo "Found migration version {$version}.\n";
+                $version = (int) explode('-', $file, 1)[0];
+                echo "Found migration version {$version}";
                 if ($version <= $min_version || $version > $max_version) {
-                    echo "Skip migration version {$version}.\n";
+                    echo "...skip\n";
                     continue;
                 }
+                echo "\n";
                 $object = require BASE_PATH . '/db/migrations/' . $file;
                 if ($object instanceof MigrationInterface) {
                     $queue[$version] = $object;
                 }
             }
         }
+        echo "\n";
 
         if ($reverse) {
             krsort($queue);
             foreach ($queue as $version => $object) {
-                echo "Reverse to {$version}\n";
-                $object->down();
-                if ($version < $current) {
-                    $current = $version;
-                }
+                echo "Reverse on {$version}\n";
+                $current = $object->down();
             }
         } else {
             ksort($queue);
             foreach ($queue as $version => $object) {
                 echo "Forward to {$version}\n";
-                $object->up();
-                if ($version > $current) {
-                    $current = $version;
-                }
+                $current = $object->up();
             }
         }
-        if ($target === 'new') {
-            $sql = 'INSERT INTO `config` (`item`, `value`, `type`, `default`) VALUES("db_version", ?, "int", "20230201000")';
-        } else {
-            $sql = 'UPDATE `config` SET `value` = ? WHERE `item` = "db_version"';
-        }
-        DB::insert($sql, [$current]);
+
+        $sql = match ($target) {
+            'new' => 'INSERT INTO `config` (`item`, `value`, `type`, `default`) VALUES("db_version", ?, "int", "2023020100")',
+            default => 'UPDATE `config` SET `value` = ? WHERE `item` = "db_version"'
+        };
+        $stat = DB::getPdo()->prepare($sql);
+        $stat->execute([$current]);
 
         $count = count($queue);
-        echo "Migration complete. {$count} item(s) processed.\n";
+        echo "\nMigration completed. {$count} file(s) processed.\nCurrent version: {$current}\n";
     }
 }

+ 5 - 6
src/Controllers/UserController.php

@@ -354,24 +354,23 @@ final class UserController extends BaseController
             $code = InviteCode::where('user_id', $this->user->id)->first();
         }
 
-        $pageNum = $request->getQueryParams()['page'] ?? 1;
-
         $paybacks = Payback::where('ref_by', $this->user->id)
             ->orderBy('id', 'desc')
-            ->paginate(15, ['*'], 'page', $pageNum);
+            ->get();
+
+        foreach ($paybacks as $payback) {
+            $payback->datetime = Tools::toDateTime($payback->datetime);
+        }
 
         $paybacks_sum = Payback::where('ref_by', $this->user->id)->sum('ref_get');
         if (! $paybacks_sum) {
             $paybacks_sum = 0;
         }
 
-        $render = Tools::paginateRender($paybacks);
-
         $invite_url = $_ENV['baseUrl'] . '/auth/register?code=' . $code->code;
 
         return $response->write($this->view()
             ->assign('code', $code)
-            ->assign('render', $render)
             ->assign('paybacks', $paybacks)
             ->assign('invite_url', $invite_url)
             ->assign('paybacks_sum', $paybacks_sum)

+ 18 - 2
src/Interfaces/MigrationInterface.php

@@ -4,9 +4,25 @@ declare(strict_types=1);
 
 namespace App\Interfaces;
 
+/**
+ * Database migration interface
+ *
+ * Any migration file(object) must implement this interface. up() and down() are free,
+ * you could do anything you want but do not throw any exceptions in them.
+ */
 interface MigrationInterface
 {
-    public function up(): void;
+    /**
+     * Migrate database schema
+     *
+     * @return int current version
+     */
+    public function up(): int;
 
-    public function down(): void;
+    /**
+     * Rollback all changes caused by up()
+     *
+     * @return int previous version
+     */
+    public function down(): int;
 }