Skip to content

Commit

Permalink
feat: optimize db data type
Browse files Browse the repository at this point in the history
  • Loading branch information
Cat committed Jun 20, 2024
1 parent 7b488db commit aa71a60
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 27 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 18 additions & 15 deletions db/migrations/2023020100-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function up(): int
`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 '更新时间',
Expand Down Expand Up @@ -160,12 +160,12 @@ public function up(): int
`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 '流量重置日',
Expand Down Expand Up @@ -209,7 +209,7 @@ public function up(): int
`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 '更新时间',
Expand Down Expand Up @@ -241,7 +241,7 @@ public function up(): int
`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`),
Expand All @@ -255,7 +255,7 @@ public function up(): int
`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 '销售状态',
Expand Down Expand Up @@ -335,17 +335,17 @@ public function up(): int
`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 '网站主题',
Expand All @@ -371,6 +371,10 @@ public function up(): int
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`)
Expand All @@ -385,7 +389,6 @@ public function up(): int
`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;
Expand All @@ -402,9 +405,9 @@ public function up(): int
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`),
Expand Down
39 changes: 39 additions & 0 deletions db/migrations/2024061600-update_price_type.php
Original file line number Diff line number Diff line change
@@ -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;
}
};
2 changes: 1 addition & 1 deletion src/Models/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @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 流量重置日
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Paylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @property float $total 总金额
* @property int $status 状态
* @property int $invoice_id 账单ID
* @property string $tradeno 网关单号
* @property string $tradeno 网关识别码
* @property string $gateway 支付网关
* @property int $datetime 创建时间
*
Expand Down
3 changes: 1 addition & 2 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @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 联系方式类型
Expand Down Expand Up @@ -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',
];
Expand Down
2 changes: 2 additions & 0 deletions src/Services/DynamicRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static function validateData(
): 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 ||
Expand Down

0 comments on commit aa71a60

Please sign in to comment.