新功能(#69): 用户级限速覆盖 — 数据层 + 核心逻辑 + 管理接口
- 新增 migration 02153: user_subscribe 表添加 speed_limit、traffic_limit 列(幂等) - model 层 Subscribe/SubscribeDetails 新增用户级限速字段(*string 类型支持 nil 回退) - server 用户列表和管理员详情接口支持用户级限速覆盖优先级计算 - 更新管理员订阅更新接口支持写入/清除用户级限速 Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -23,25 +23,27 @@ const (
|
||||
)
|
||||
|
||||
type SubscribeDetails struct {
|
||||
Id int64 `gorm:"primarykey"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
User *User `gorm:"foreignKey:UserId;references:Id"`
|
||||
OrderId int64 `gorm:"index:idx_order_id;not null;comment:Order ID"`
|
||||
SubscribeId int64 `gorm:"index:idx_subscribe_id;not null;comment:Subscription ID"`
|
||||
Subscribe *subscribe.Subscribe `gorm:"foreignKey:SubscribeId;references:Id"`
|
||||
NodeGroupId int64 `gorm:"index:idx_node_group_id;not null;default:0;comment:Node Group ID (single ID)"`
|
||||
StartTime time.Time `gorm:"default:CURRENT_TIMESTAMP(3);not null;comment:Subscription Start Time"`
|
||||
ExpireTime time.Time `gorm:"default:NULL;comment:Subscription Expire Time"`
|
||||
FinishedAt *time.Time `gorm:"default:NULL;comment:Finished Time"`
|
||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired; 4: Cancelled"`
|
||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
Id int64 `gorm:"primarykey"`
|
||||
UserId int64 `gorm:"index:idx_user_id;not null;comment:User ID"`
|
||||
User *User `gorm:"foreignKey:UserId;references:Id"`
|
||||
OrderId int64 `gorm:"index:idx_order_id;not null;comment:Order ID"`
|
||||
SubscribeId int64 `gorm:"index:idx_subscribe_id;not null;comment:Subscription ID"`
|
||||
Subscribe *subscribe.Subscribe `gorm:"foreignKey:SubscribeId;references:Id"`
|
||||
NodeGroupId int64 `gorm:"index:idx_node_group_id;not null;default:0;comment:Node Group ID (single ID)"`
|
||||
StartTime time.Time `gorm:"default:CURRENT_TIMESTAMP(3);not null;comment:Subscription Start Time"`
|
||||
ExpireTime time.Time `gorm:"default:NULL;comment:Subscription Expire Time"`
|
||||
FinishedAt *time.Time `gorm:"default:NULL;comment:Finished Time"`
|
||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||
SpeedLimit int64 `gorm:"default:0;comment:User-level speed limit override (Mbps), 0 uses plan-level"`
|
||||
TrafficLimit *string `gorm:"type:text;default:null;comment:User-level traffic limit override (JSON), NULL uses plan-level"`
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired; 4: Cancelled"`
|
||||
Note string `gorm:"type:varchar(500);default:'';comment:User note for subscription"`
|
||||
CreatedAt time.Time `gorm:"<-:create;comment:Creation Time"`
|
||||
UpdatedAt time.Time `gorm:"comment:Update Time"`
|
||||
}
|
||||
|
||||
type SubscribeLogFilterParams struct {
|
||||
|
||||
@@ -101,10 +101,10 @@ type Subscribe struct {
|
||||
Traffic int64 `gorm:"default:0;comment:Traffic"`
|
||||
Download int64 `gorm:"default:0;comment:Download Traffic"`
|
||||
Upload int64 `gorm:"default:0;comment:Upload Traffic"`
|
||||
SpeedLimit int64 `gorm:"default:0;comment:User-level speed limit override (Mbps, 0=use plan default)"`
|
||||
TrafficLimit string `gorm:"type:text;default:null;comment:User-level traffic limit rules override (JSON)"`
|
||||
ExpiredDownload int64 `gorm:"default:0;comment:Expired period download traffic (bytes)"`
|
||||
ExpiredUpload int64 `gorm:"default:0;comment:Expired period upload traffic (bytes)"`
|
||||
SpeedLimit int64 `gorm:"default:0;comment:User-level speed limit override (Mbps), 0 uses plan-level"`
|
||||
TrafficLimit *string `gorm:"type:text;default:null;comment:User-level traffic limit override (JSON), NULL uses plan-level"`
|
||||
Token string `gorm:"index:idx_token;unique;type:varchar(255);default:'';comment:Token"`
|
||||
UUID string `gorm:"type:varchar(255);unique;index:idx_uuid;default:'';comment:UUID"`
|
||||
Status uint8 `gorm:"type:tinyint(1);default:0;comment:Subscription Status: 0: Pending 1: Active 2: Finished 3: Expired 4: Deducted 5: stopped"`
|
||||
|
||||
Reference in New Issue
Block a user