Prechádzať zdrojové kódy

feat: optimize db data type

Cat 1 rok pred
rodič
commit
aa71a60499

+ 1 - 1
README.md

@@ -17,7 +17,7 @@ NeXT Panel is a multipurpose proxy service management system designed for Shadow
 
 - Integrate multiple payment systems such as Alipay F2F, PayPal, Stripe, etc.
 - Support multiple mail services, built-in mail queue function, no third-party components are required to use
-- Built-in tabler theme based on Bootstrap 5, template engine support
+- Built-in tabler theme based on Bootstrap 5, Smarty/Twig template engine support
 - Support Shadowsocks 2022, TUIC, and other latest proxy protocols
 - Universal subscription interface, one-click json/clash/sip008/sing-box format subscription distribution
 - Custom node configuration, modular subscription system, support multiple client-specific subscription formats

+ 27 - 24
composer.lock

@@ -5067,16 +5067,16 @@
         },
         {
             "name": "smarty/smarty",
-            "version": "v5.3.0",
+            "version": "v5.3.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/smarty-php/smarty.git",
-                "reference": "353ca06d076da46964b0c709d8e4dd87677195b8"
+                "reference": "3cb35854326a94120cd415b81db28c53d95d0d5d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/353ca06d076da46964b0c709d8e4dd87677195b8",
-                "reference": "353ca06d076da46964b0c709d8e4dd87677195b8",
+                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/3cb35854326a94120cd415b81db28c53d95d0d5d",
+                "reference": "3cb35854326a94120cd415b81db28c53d95d0d5d",
                 "shasum": ""
             },
             "require": {
@@ -5131,9 +5131,9 @@
             "support": {
                 "forum": "https://github.com/smarty-php/smarty/discussions",
                 "issues": "https://github.com/smarty-php/smarty/issues",
-                "source": "https://github.com/smarty-php/smarty/tree/v5.3.0"
+                "source": "https://github.com/smarty-php/smarty/tree/v5.3.1"
             },
-            "time": "2024-05-30T11:14:56+00:00"
+            "time": "2024-06-16T19:51:13+00:00"
         },
         {
             "name": "srmklive/paypal",
@@ -7610,16 +7610,16 @@
         },
         {
             "name": "friendsofphp/php-cs-fixer",
-            "version": "v3.58.1",
+            "version": "v3.59.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git",
-                "reference": "04e9424025677a86914b9a4944dbbf4060bb0aff"
+                "reference": "30ba9ecc2b0e5205e578fe29973c15653d9bfd29"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/04e9424025677a86914b9a4944dbbf4060bb0aff",
-                "reference": "04e9424025677a86914b9a4944dbbf4060bb0aff",
+                "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/30ba9ecc2b0e5205e578fe29973c15653d9bfd29",
+                "reference": "30ba9ecc2b0e5205e578fe29973c15653d9bfd29",
                 "shasum": ""
             },
             "require": {
@@ -7649,16 +7649,16 @@
                 "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0"
             },
             "require-dev": {
-                "facile-it/paraunit": "^1.3 || ^2.0",
-                "infection/infection": "^0.27.11",
+                "facile-it/paraunit": "^1.3 || ^2.3",
+                "infection/infection": "^0.29.5",
                 "justinrainbow/json-schema": "^5.2",
                 "keradus/cli-executor": "^2.1",
                 "mikey179/vfsstream": "^1.6.11",
                 "php-coveralls/php-coveralls": "^2.7",
                 "php-cs-fixer/accessible-object": "^1.1",
-                "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4",
-                "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4",
-                "phpunit/phpunit": "^9.6 || ^10.5.5 || ^11.0.2",
+                "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.5",
+                "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.5",
+                "phpunit/phpunit": "^9.6.19 || ^10.5.21 || ^11.2",
                 "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0",
                 "symfony/yaml": "^5.4 || ^6.0 || ^7.0"
             },
@@ -7673,7 +7673,10 @@
             "autoload": {
                 "psr-4": {
                     "PhpCsFixer\\": "src/"
-                }
+                },
+                "exclude-from-classmap": [
+                    "src/Fixer/Internal/*"
+                ]
             },
             "notification-url": "https://packagist.org/downloads/",
             "license": [
@@ -7698,7 +7701,7 @@
             ],
             "support": {
                 "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues",
-                "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.58.1"
+                "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.59.3"
             },
             "funding": [
                 {
@@ -7706,7 +7709,7 @@
                     "type": "github"
                 }
             ],
-            "time": "2024-05-29T16:39:07+00:00"
+            "time": "2024-06-16T14:17:03+00:00"
         },
         {
             "name": "justinrainbow/json-schema",
@@ -8633,16 +8636,16 @@
         },
         {
             "name": "phpunit/phpunit",
-            "version": "10.5.20",
+            "version": "10.5.21",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "547d314dc24ec1e177720d45c6263fb226cc2ae3"
+                "reference": "ac837816fa52078f7a5e17ed774f256a72a51af6"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/547d314dc24ec1e177720d45c6263fb226cc2ae3",
-                "reference": "547d314dc24ec1e177720d45c6263fb226cc2ae3",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ac837816fa52078f7a5e17ed774f256a72a51af6",
+                "reference": "ac837816fa52078f7a5e17ed774f256a72a51af6",
                 "shasum": ""
             },
             "require": {
@@ -8714,7 +8717,7 @@
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.20"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.21"
             },
             "funding": [
                 {
@@ -8730,7 +8733,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2024-04-24T06:32:35+00:00"
+            "time": "2024-06-15T09:13:15+00:00"
         },
         {
             "name": "psr/cache",

+ 18 - 15
db/migrations/2023020100-init.php

@@ -120,7 +120,7 @@ return new class() implements MigrationInterface {
                 `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '归属用户ID',
                 `order_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '订单ID',
                 `content` longtext NOT NULL DEFAULT '{}' COMMENT '账单内容' CHECK (json_valid(`content`)),
-                `price` double unsigned NOT NULL DEFAULT 0 COMMENT '账单金额',
+                `price` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '账单金额',
                 `status` varchar(255) NOT NULL DEFAULT '' COMMENT '账单状态',
                 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 `update_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '更新时间',
@@ -160,12 +160,12 @@ return new class() implements MigrationInterface {
                 `server` varchar(255) NOT NULL DEFAULT '' COMMENT '节点地址',
                 `custom_config` longtext NOT NULL DEFAULT '{}' COMMENT '自定义配置' CHECK (json_valid(`custom_config`)),
                 `sort` tinyint(2) unsigned NOT NULL DEFAULT 14 COMMENT '节点类型',
-                `traffic_rate` double unsigned NOT NULL DEFAULT 1 COMMENT '流量倍率',
+                `traffic_rate` decimal(5,2) unsigned NOT NULL DEFAULT 1 COMMENT '流量倍率',
                 `is_dynamic_rate` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '是否启用动态流量倍率',
                 `dynamic_rate_type` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '动态流量倍率计算方式',
                 `dynamic_rate_config` longtext NOT NULL DEFAULT '{}' COMMENT '动态流量倍率配置' CHECK (json_valid(`custom_config`)),
                 `node_class` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT '节点等级',
-                `node_speedlimit` double unsigned NOT NULL DEFAULT 0 COMMENT '节点限速',
+                `node_speedlimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '节点限速',
                 `node_bandwidth` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '节点流量',
                 `node_bandwidth_limit` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '节点流量限制',
                 `bandwidthlimit_resetday` tinyint(2) unsigned NOT NULL DEFAULT 0 COMMENT '流量重置日',
@@ -209,7 +209,7 @@ return new class() implements MigrationInterface {
                 `product_name` varchar(255) NOT NULL DEFAULT '' COMMENT '商品名称',
                 `product_content` longtext NOT NULL DEFAULT '{}' COMMENT '商品内容' CHECK (json_valid(`product_content`)),
                 `coupon` varchar(255) NOT NULL DEFAULT '' COMMENT '订单优惠码',
-                `price` double unsigned NOT NULL DEFAULT 0 COMMENT '订单金额',
+                `price` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '订单金额',
                 `status` varchar(255) NOT NULL DEFAULT '' COMMENT '订单状态',
                 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 `update_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '更新时间',
@@ -241,7 +241,7 @@ return new class() implements MigrationInterface {
                 `total` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '总金额',
                 `status` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '状态',
                 `invoice_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '账单ID',
-                `tradeno` varchar(255) NOT NULL DEFAULT '' COMMENT '网关单号',
+                `tradeno` varchar(255) NOT NULL DEFAULT '' COMMENT '网关识别码',
                 `gateway` varchar(255) NOT NULL DEFAULT '' COMMENT '支付网关',
                 `datetime` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 PRIMARY KEY (`id`),
@@ -255,7 +255,7 @@ return new class() implements MigrationInterface {
                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品ID',
                 `type` varchar(255) NOT NULL DEFAULT 'tabp' COMMENT '类型',
                 `name` varchar(255) NOT NULL DEFAULT '' COMMENT '名称',
-                `price` double unsigned NOT NULL DEFAULT 0 COMMENT '售价',
+                `price` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '售价',
                 `content` longtext NOT NULL DEFAULT '{}' COMMENT '内容' CHECK (json_valid(`content`)),
                 `limit` longtext NOT NULL DEFAULT '{}' COMMENT '购买限制' CHECK (json_valid(`limit`)),
                 `status` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT '销售状态',
@@ -335,17 +335,17 @@ return new class() implements MigrationInterface {
                 `last_check_in_time` int(11) unsigned DEFAULT 0 COMMENT '最后签到时间',
                 `last_login_time` int(11) unsigned DEFAULT 0 COMMENT '最后登录时间',
                 `reg_date` datetime NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '注册时间',
-                `money` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '账户余额',
+                `money` decimal(12,2) NOT NULL DEFAULT 0.00 COMMENT '账户余额',
                 `ref_by` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '邀请人ID',
                 `method` varchar(255) NOT NULL DEFAULT 'aes-128-gcm' COMMENT '加密方式',
                 `reg_ip` varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT '注册IP',
-                `node_speedlimit` double NOT NULL DEFAULT 0 COMMENT '用户限速',
+                `node_speedlimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '用户限速',
                 `node_iplimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '同时可连接IP数',
                 `is_admin` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '是否管理员',
-                `im_type` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '联系方式类型',
+                `im_type` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '联系方式类型',
                 `im_value` varchar(255) NOT NULL DEFAULT '' COMMENT '联系方式',
-                `contact_method` smallint(6) NOT NULL DEFAULT 1 COMMENT '偏好的联系方式',
-                `daily_mail_enable` tinyint(1) NOT NULL DEFAULT 0 COMMENT '每日报告开关',
+                `contact_method` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '偏好的联系方式',
+                `daily_mail_enable` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '每日报告开关',
                 `class` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT '等级',
                 `class_expire` datetime NOT NULL DEFAULT '1989-06-04 00:05:00' COMMENT '等级过期时间',
                 `theme` varchar(255) NOT NULL DEFAULT 'tabler' COMMENT '网站主题',
@@ -371,6 +371,10 @@ return new class() implements MigrationInterface {
                 UNIQUE KEY `ga_token` (`ga_token`),
                 UNIQUE KEY `api_token` (`api_token`),
                 KEY `is_admin` (`is_admin`),
+                KEY `contact_method` (`contact_method`),
+                KEY `class` (`class`),
+                KEY `class_expire` (`class_expire`),
+                KEY `node_group` (`node_group`),
                 KEY `is_banned` (`is_banned`),
                 KEY `is_shadow_banned` (`is_shadow_banned`),
                 KEY `is_inactive` (`is_inactive`)
@@ -385,7 +389,6 @@ return new class() implements MigrationInterface {
                 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 `expire_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '过期时间',
                 PRIMARY KEY (`id`),
-                KEY `id` (`id`),
                 UNIQUE KEY `code` (`code`),
                 KEY `expire_time` (`expire_time`)
             ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@@ -402,9 +405,9 @@ return new class() implements MigrationInterface {
             CREATE TABLE `user_money_log` (
                 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
                 `user_id` bigint(20) unsigned NOT NULL DEFAULT 0 COMMENT '用户ID',
-                `before` decimal(10,2) NOT NULL DEFAULT 0 COMMENT '用户变动前账户余额',
-                `after` decimal(10,2) NOT NULL DEFAULT 0 COMMENT '用户变动后账户余额',
-                `amount` decimal(10,2) NOT NULL DEFAULT 0 COMMENT '变动总额',
+                `before` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '用户变动前账户余额',
+                `after` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '用户变动后账户余额',
+                `amount` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '变动总额',
                 `remark` text NOT NULL DEFAULT '' COMMENT '备注',
                 `create_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
                 PRIMARY KEY (`id`),

+ 39 - 0
db/migrations/2024061600-update_price_type.php

@@ -0,0 +1,39 @@
+<?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("
+            ALTER TABLE invoice MODIFY COLUMN `price` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '账单金额';
+            ALTER TABLE node MODIFY COLUMN `traffic_rate` decimal(5,2) unsigned NOT NULL DEFAULT 1 COMMENT '流量倍率';
+            ALTER TABLE node MODIFY COLUMN `node_speedlimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '节点限速';
+            ALTER TABLE `order` MODIFY COLUMN `price` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '订单金额';
+            ALTER TABLE paylist MODIFY COLUMN `tradeno` varchar(255) NOT NULL DEFAULT '' COMMENT '网关识别码';
+            ALTER TABLE product MODIFY COLUMN `price` decimal(12,2) unsigned NOT NULL DEFAULT 0 COMMENT '售价';
+            ALTER TABLE user MODIFY COLUMN `money` decimal(12,2) NOT NULL DEFAULT 0.00 COMMENT '账户余额';
+            ALTER TABLE user MODIFY COLUMN `node_speedlimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '用户限速';
+            ALTER TABLE user MODIFY COLUMN `im_type` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT '联系方式类型';
+            ALTER TABLE user MODIFY COLUMN `contact_method` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT '偏好的联系方式';
+            ALTER TABLE user MODIFY COLUMN `daily_mail_enable` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '每日报告开关';
+            ALTER TABLE user ADD KEY IF NOT EXISTS `contact_method` (`contact_method`);
+            ALTER TABLE user ADD KEY IF NOT EXISTS `class` (`class`);
+            ALTER TABLE user ADD KEY IF NOT EXISTS `class_expire` (`class_expire`);
+            ALTER TABLE user ADD KEY IF NOT EXISTS `node_group` (`node_group`);
+            ALTER TABLE user_money_log MODIFY COLUMN `before` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '用户变动前账户余额';
+            ALTER TABLE user_money_log MODIFY COLUMN `after` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '用户变动后账户余额';
+            ALTER TABLE user_money_log MODIFY COLUMN `amount` decimal(12,2) NOT NULL DEFAULT 0 COMMENT '变动总额';
+        ");
+
+        return 2024061600;
+    }
+
+    public function down(): int
+    {
+        return 2024061600;
+    }
+};

+ 1 - 1
src/Models/Node.php

@@ -24,7 +24,7 @@ use const DNS_AAAA;
  * @property int    $dynamic_rate_type       动态流量倍率计算方式
  * @property string $dynamic_rate_config     动态流量倍率配置
  * @property int    $node_class              节点等级
- * @property float  $node_speedlimit         节点限速
+ * @property int    $node_speedlimit         节点限速
  * @property int    $node_bandwidth          节点流量
  * @property int    $node_bandwidth_limit    节点流量限制
  * @property int    $bandwidthlimit_resetday 流量重置日

+ 1 - 1
src/Models/Paylist.php

@@ -12,7 +12,7 @@ use Illuminate\Database\Query\Builder;
  * @property float  $total      总金额
  * @property int    $status     状态
  * @property int    $invoice_id 账单ID
- * @property string $tradeno    网关单号
+ * @property string $tradeno    网关识别码
  * @property string $gateway    支付网关
  * @property int    $datetime   创建时间
  *

+ 1 - 2
src/Models/User.php

@@ -38,7 +38,7 @@ use const PHP_EOL;
  * @property int    $ref_by 邀请人ID
  * @property string $method Shadowsocks加密方式
  * @property string $reg_ip 注册IP
- * @property float  $node_speedlimit 用户限速
+ * @property int    $node_speedlimit 用户限速
  * @property int    $node_iplimit 同时可连接IP数
  * @property int    $is_admin 是否管理员
  * @property int    $im_type 联系方式类型
@@ -86,7 +86,6 @@ final class User extends Model
     protected $casts = [
         'money' => 'float',
         'port' => 'int',
-        'node_speedlimit' => 'float',
         'daily_mail_enable' => 'int',
         'ref_by' => 'int',
     ];

+ 2 - 0
src/Services/DynamicRate.php

@@ -68,6 +68,8 @@ final class DynamicRate
     ): bool {
         return ! ($max_rate < 0 ||
             $min_rate < 0 ||
+            $max_rate > 999 ||
+            $min_rate > 999 ||
             $max_rate_time < 0 ||
             $min_rate_time < 0 ||
             $max_rate_time > 24 ||