Files
NetworkAuth/models/app.go
skyle1995 6dad3971de New interface management
Optimize the pop-up interface
2025-10-25 01:43:03 +08:00

128 lines
7.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"crypto/rand"
"encoding/hex"
"strings"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// App 应用表模型
// 用于管理应用程序的基本信息
// UUID 为应用的唯一标识符,自动生成
// Status 为应用状态1:启用 0:禁用默认为1
// Name 为应用名称
// Secret 为应用密钥用于API认证
// Version 为应用版本号
// CreatedAt/UpdatedAt 由 GORM 自动维护
type App struct {
// ID主键自增同时通过 json 标签保证前端接收为 id
ID uint `gorm:"primaryKey;comment:应用ID自增主键" json:"id"`
// UUID应用唯一标识符自动生成
UUID string `gorm:"uniqueIndex;size:36;not null;comment:应用UUID唯一标识符" json:"uuid"`
// Status状态1=启用0=禁用json 名称与前端一致
Status int `gorm:"default:1;not null;comment:应用状态1=启用0=禁用" json:"status"`
// Name应用名称json 名称与前端一致
Name string `gorm:"size:100;not null;comment:应用名称" json:"name"`
// Secret应用密钥用于API认证
Secret string `gorm:"size:255;not null;comment:应用密钥用于API认证" json:"secret"`
// Version应用版本号
Version string `gorm:"size:50;default:'1.0.0';comment:应用版本号" json:"version"`
// ForceUpdate强制更新0=不开启1=开启)
ForceUpdate int `gorm:"default:0;not null;comment:强制更新0=不开启1=开启" json:"force_update"`
// DownloadType下载方式0=不启用更新1=自动更新2=手动下载)
DownloadType int `gorm:"default:0;not null;comment:更新方式0=不启用更新1=自动更新2=手动下载" json:"download_type"`
// DownloadURL下载地址
DownloadURL string `gorm:"size:500;comment:下载地址" json:"download_url"`
// AppData应用数据base64编码存储
AppData string `gorm:"type:text;comment:应用数据base64编码存储" json:"app_data"`
// Announcement程序公告内容base64编码存储
Announcement string `gorm:"type:text;comment:程序公告内容base64编码存储" json:"announcement"`
// LoginType登陆方式0=顶号登录默认1=非顶号登录)
LoginType int `gorm:"default:0;not null;comment:登陆方式0=顶号登录1=非顶号登录" json:"login_type"`
// MultiOpenScope多开范围0=单电脑1=单IP2=全部电脑(默认))
MultiOpenScope int `gorm:"default:2;not null;comment:多开范围0=单电脑1=单IP2=全部电脑" json:"multi_open_scope"`
// CleanInterval清理间隔单位小时默认1小时
CleanInterval int `gorm:"default:1;not null;comment:清理间隔,单位小时" json:"clean_interval"`
// CheckInterval校验间隔单位分钟默认10分钟
CheckInterval int `gorm:"default:10;not null;comment:校验间隔,单位分钟" json:"check_interval"`
// MultiOpenCount多开数量默认1
MultiOpenCount int `gorm:"default:1;not null;comment:多开数量" json:"multi_open_count"`
// 机器验证相关字段
// MachineVerify机器验证0=关闭1=开启)
MachineVerify int `gorm:"default:0;not null;comment:机器验证0=关闭1=开启" json:"machine_verify"`
// MachineRebindEnabled机器重绑开关0=关闭1=开启)
MachineRebindEnabled int `gorm:"default:0;not null;comment:机器重绑开关0=关闭1=开启" json:"machine_rebind_enabled"`
// MachineRebindLimit机器重绑限制0=每天1=永久)
MachineRebindLimit int `gorm:"default:0;not null;comment:机器重绑限制0=每天1=永久" json:"machine_rebind_limit"`
// MachineFreeCount机器免费次数默认0
MachineFreeCount int `gorm:"default:0;not null;comment:机器免费次数" json:"machine_free_count"`
// MachineRebindCount机器重绑次数默认0
MachineRebindCount int `gorm:"default:0;not null;comment:机器重绑次数" json:"machine_rebind_count"`
// MachineRebindDeduct机器重绑扣除默认0单位分钟
MachineRebindDeduct int `gorm:"default:0;not null;comment:机器重绑扣除,单位分钟" json:"machine_rebind_deduct"`
// IP地址验证相关字段
// IPVerifyIP地址验证0=关闭1=开启2=开启(市)3=开启(省)
IPVerify int `gorm:"default:0;not null;comment:IP地址验证0=关闭1=开启2=开启(市)3=开启(省)" json:"ip_verify"`
// IPRebindEnabledIP地址重绑开关0=关闭1=开启)
IPRebindEnabled int `gorm:"default:0;not null;comment:IP地址重绑开关0=关闭1=开启" json:"ip_rebind_enabled"`
// IPRebindLimitIP地址重绑限制0=每天1=永久)
IPRebindLimit int `gorm:"default:0;not null;comment:IP地址重绑限制0=每天1=永久" json:"ip_rebind_limit"`
// IPFreeCountIP地址免费次数默认0
IPFreeCount int `gorm:"default:0;not null;comment:IP地址免费次数" json:"ip_free_count"`
// IPRebindCountIP地址重绑次数默认0
IPRebindCount int `gorm:"default:0;not null;comment:IP地址重绑次数" json:"ip_rebind_count"`
// IPRebindDeductIP地址重绑扣除默认0单位分钟
IPRebindDeduct int `gorm:"default:0;not null;comment:IP地址重绑扣除单位分钟" json:"ip_rebind_deduct"`
// 账号注册相关字段
// RegisterEnabled账号注册开关0=关闭1=开启)
RegisterEnabled int `gorm:"default:1;not null;comment:账号注册开关0=关闭1=开启" json:"register_enabled"`
// RegisterLimitEnabled注册限制开关0=关闭1=开启)
RegisterLimitEnabled int `gorm:"default:0;not null;comment:注册限制开关0=关闭1=开启" json:"register_limit_enabled"`
// RegisterLimitTime限制时间0=每天1=永久)
RegisterLimitTime int `gorm:"default:1;not null;comment:注册限制时间0=每天1=永久" json:"register_limit_time"`
// RegisterCount注册次数
RegisterCount int `gorm:"default:1;not null;comment:注册次数" json:"register_count"`
// 领取试用相关字段
// TrialEnabled领取试用开关0=关闭1=开启)
TrialEnabled int `gorm:"default:0;not null;comment:领取试用开关0=关闭1=开启" json:"trial_enabled"`
// TrialLimitTime试用限制时间0=每天1=永久)
TrialLimitTime int `gorm:"default:1;not null;comment:试用限制时间0=每天1=永久" json:"trial_limit_time"`
// TrialDuration试用时间单位分钟
TrialDuration int `gorm:"default:0;not null;comment:试用时间,单位分钟" json:"trial_duration"`
// CreatedAt/UpdatedAt时间字段返回为 created_at/updated_at便于前端展示
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
}
// BeforeCreate 在创建记录前自动生成UUID和密钥
func (app *App) BeforeCreate(tx *gorm.DB) error {
if app.UUID == "" {
app.UUID = strings.ToUpper(uuid.New().String())
}
if app.Secret == "" {
// 生成32位大写16进制随机字符
bytes := make([]byte, 16) // 16字节 = 32位16进制字符
rand.Read(bytes)
app.Secret = strings.ToUpper(hex.EncodeToString(bytes))
}
return nil
}
// TableName 指定表名
func (App) TableName() string {
return "apps"
}