This commit is contained in:
Joe
2026-01-16 15:49:34 +08:00
commit 550d3e1f42
380 changed files with 62024 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Admin struct {
orm.Model
Username string `gorm:"not null;size:50;comment:用户名" json:"username"`
Password string `gorm:"not null;size:255;comment:密码" json:"-"` // 使用 json:"-" 隐藏密码字段
Nickname string `gorm:"size:50;comment:昵称" json:"nickname"`
Avatar string `gorm:"size:255;comment:头像" json:"avatar"`
Email string `gorm:"size:100;comment:邮箱" json:"email"`
Phone string `gorm:"size:20;comment:手机号" json:"phone"`
GoogleSecret string `gorm:"size:255;comment:谷歌验证码密钥" json:"-"` // 使用 json:"-" 隐藏密钥字段
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用" json:"status"`
DepartmentID uint `gorm:"index;comment:部门ID" json:"department_id"`
Department Department `gorm:"foreignKey:DepartmentID" json:"department"`
Roles []Role `gorm:"many2many:admin_role;comment:角色" json:"roles"`
orm.SoftDeletes
}
+41
View File
@@ -0,0 +1,41 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Article struct {
orm.Model
orm.SoftDeletes
Name string `gorm:"name" json:"name" comment:"名称"`
Status string `gorm:"status" json:"status" comment:"状态"`
}
func (Article) TableName() string {
return "articles"
}
func (r *Article) Serialize() map[string]any {
return map[string]any{
"id": r.ID,
"created_at": r.CreatedAt,
"updated_at": r.UpdatedAt,
"name": r.Name,
"status": r.Status,
}
}
func (r *Article) Deserialize(data map[string]any) {
if val, ok := data["name"]; ok {
r.Name = val.(string)
}
if val, ok := data["status"]; ok {
r.Status = val.(string)
}
}
+21
View File
@@ -0,0 +1,21 @@
package models
import "github.com/goravel/framework/database/orm"
// Attachment 附件表
// 用于管理所有上传的文件,支持分片上传和断点续传
type Attachment struct {
orm.Model
AdminID uint `gorm:"index;comment:管理员ID"`
Admin Admin `gorm:"foreignKey:AdminID"`
Disk string `gorm:"size:50;comment:存储驱动"`
Path string `gorm:"size:500;comment:文件路径"`
Filename string `gorm:"size:255;comment:原始文件名"`
DisplayName string `gorm:"size:255;index;comment:显示名称"`
Extension string `gorm:"size:20;comment:文件后缀"`
MimeType string `gorm:"size:100;comment:MIME类型"`
Size int64 `gorm:"comment:文件大小(字节)"`
Status uint8 `gorm:"default:1;comment:状态 1:成功 0:失败 2:上传中"`
FileType string `gorm:"size:20;comment:文件类型 image/video/document/other"`
ChunkID string `gorm:"size:100;index;comment:分片上传ID(用于断点续传)"`
}
+13
View File
@@ -0,0 +1,13 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Blacklist struct {
orm.Model
IP string `gorm:"index;not null;size:500;comment:IP地址或IP段,支持单个IP、CIDR格式、IP范围,多个用逗号分隔" json:"ip"`
Remark string `gorm:"size:500;comment:备注" json:"remark"`
Status uint8 `gorm:"index;default:1;comment:状态 1:启用 0:禁用" json:"status"`
}
+17
View File
@@ -0,0 +1,17 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Config struct {
orm.Model
Group string `gorm:"index;not null;size:50;comment:配置分组 website:网站配置 email:邮箱配置"`
Key string `gorm:"index;not null;size:100;comment:配置键"`
Value string `gorm:"type:text;comment:配置值"`
Label string `gorm:"size:100;comment:配置标签"`
Type string `gorm:"size:20;default:'input';comment:配置类型 input:text:textarea:select:switch"`
Sort int `gorm:"default:0;comment:排序"`
Remark string `gorm:"size:500;comment:备注"`
}
+25
View File
@@ -0,0 +1,25 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
// Currency 货币表
type Currency struct {
orm.Model
Code string `gorm:"size:10;not null;uniqueIndex;comment:货币代码(如CNY,USD)" json:"code"`
Name string `gorm:"size:50;not null;comment:货币名称(如人民币,美元)" json:"name"`
Symbol string `gorm:"size:10;comment:货币符号(如¥,$)" json:"symbol"`
Rate float64 `gorm:"type:decimal(18,8);default:1;comment:汇率(相对于基准货币)" json:"rate"`
DecimalPlaces int `gorm:"default:2;comment:小数位数(如日元为0,人民币为2,虚拟货币为8)" json:"decimal_places"`
IsDefault bool `gorm:"default:false;comment:是否默认货币" json:"is_default"`
IsActive bool `gorm:"default:true;comment:是否启用" json:"is_active"`
Sort int `gorm:"default:0;comment:排序" json:"sort"`
Description string `gorm:"type:text;comment:描述" json:"description"`
orm.SoftDeletes
}
// TableName 指定表名
func (Currency) TableName() string {
return "currencies"
}
+20
View File
@@ -0,0 +1,20 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Department struct {
orm.Model
ParentID uint `gorm:"index;default:0;comment:父级ID"`
Name string `gorm:"not null;size:50;comment:部门名称"`
Code string `gorm:"size:50;comment:部门编码"`
Leader string `gorm:"size:50;comment:负责人"`
Phone string `gorm:"size:20;comment:联系电话"`
Email string `gorm:"size:100;comment:邮箱"`
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用"`
Sort int `gorm:"default:0;comment:排序"`
Remark string `gorm:"size:500;comment:备注"`
Children []Department `gorm:"foreignKey:ParentID"`
Admins []Admin `gorm:"foreignKey:DepartmentID"`
}
+17
View File
@@ -0,0 +1,17 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Dictionary struct {
orm.Model
Type string `gorm:"index;not null;size:50;comment:字典类型"`
Label string `gorm:"not null;size:50;comment:字典标签"`
Value string `gorm:"not null;size:100;comment:字典值"`
TranslationKey string `gorm:"size:255;comment:多语言Key"`
Description string `gorm:"size:255;comment:字典描述"`
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用"`
Sort int `gorm:"default:0;comment:排序"`
Remark string `gorm:"size:500;comment:备注"`
}
+34
View File
@@ -0,0 +1,34 @@
package models
import "github.com/goravel/framework/database/orm"
// Export 导出记录表
// 用于记录所有导出文件的信息,便于在后台进行统一管理
type Export struct {
orm.Model
AdminID uint `gorm:"index;comment:管理员ID"`
Admin Admin `gorm:"foreignKey:AdminID"`
Type string `gorm:"size:50;index;comment:导出类型 orders:订单导出 admins:管理员导出"`
Disk string `gorm:"size:50;comment:存储驱动"`
Path string `gorm:"size:255;comment:文件路径"`
Filename string `gorm:"size:255;comment:文件名"`
Extension string `gorm:"size:20;comment:文件后缀"`
Size int64 `gorm:"comment:文件大小(字节)"`
Status uint8 `gorm:"default:0;comment:状态 0:处理中 1:成功 2:失败"`
ErrorMsg string `gorm:"type:text;comment:错误信息"`
}
// 导出状态常量
const (
ExportStatusProcessing uint8 = 0 // 处理中
ExportStatusSuccess uint8 = 1 // 成功
ExportStatusFailed uint8 = 2 // 失败
)
// 导出类型常量
const (
ExportTypeOrders string = "orders" // 订单导出
ExportTypeAdmins string = "admins" // 管理员导出
ExportTypePayments string = "payments" // 支付记录导出
ExportTypeUsers string = "users" // 用户导出
)
+18
View File
@@ -0,0 +1,18 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type LoginLog struct {
orm.Model
AdminID uint `gorm:"index;comment:管理员ID"`
Admin Admin `gorm:"foreignKey:AdminID"`
Username string `gorm:"size:50;comment:用户名"`
IP string `gorm:"size:50;comment:IP地址"`
UserAgent string `gorm:"size:500;comment:用户代理"`
Location string `gorm:"size:100;comment:登录地点"`
Status uint8 `gorm:"default:1;comment:状态 1:成功 0:失败"`
Message string `gorm:"size:255;comment:登录信息"`
Request string `gorm:"type:text;comment:请求数据"`
}
+24
View File
@@ -0,0 +1,24 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Menu struct {
orm.Model
ParentID uint `gorm:"index;default:0;comment:父级ID"`
Title string `gorm:"not null;size:50;comment:菜单标题"`
Slug string `gorm:"uniqueIndex;size:50;comment:菜单标识"`
Icon string `gorm:"size:50;comment:图标"`
Path string `gorm:"size:1000;comment:路由路径"`
Component string `gorm:"size:255;comment:组件路径"`
Permission string `gorm:"size:100;comment:权限标识"`
Type uint8 `gorm:"default:1;comment:类型 1:目录 2:菜单 3:按钮"`
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用"`
Sort int `gorm:"default:0;comment:排序"`
IsHidden uint8 `gorm:"default:0;comment:是否隐藏 1:是 0:否"`
LinkType uint8 `gorm:"default:1;comment:链接类型 1:内部页面 2:外部链接"`
OpenType uint8 `gorm:"default:1;comment:打开方式 1:iframe嵌套 2:新窗口打开"`
Children []Menu `gorm:"foreignKey:ParentID"`
Roles []Role `gorm:"many2many:role_menu;comment:角色"`
}
+21
View File
@@ -0,0 +1,21 @@
package models
import (
"time"
"github.com/goravel/framework/database/orm"
)
type Notification struct {
orm.Model
Title string `gorm:"size:150;not null" json:"title"`
Content string `gorm:"type:text" json:"content"`
Type string `gorm:"size:20;default:announcement" json:"type"`
SenderID *uint `json:"sender_id"`
Sender *Admin `gorm:"foreignKey:SenderID" json:"sender"`
ReceiverID *uint `json:"receiver_id"`
Receiver *Admin `gorm:"foreignKey:ReceiverID" json:"receiver"`
IsRead bool `gorm:"default:false" json:"is_read"`
ReadAt *time.Time `json:"read_at"`
orm.SoftDeletes
}
+21
View File
@@ -0,0 +1,21 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type OperationLog struct {
orm.Model
AdminID uint `gorm:"index;comment:管理员ID"`
Admin Admin `gorm:"foreignKey:AdminID"`
Method string `gorm:"size:10;comment:请求方法"`
Path string `gorm:"size:255;comment:请求路径"`
Title string `gorm:"size:255;comment:操作标题"`
IP string `gorm:"size:50;comment:IP地址"`
UserAgent string `gorm:"size:500;comment:用户代理"`
Request string `gorm:"type:text;comment:请求参数"`
Response string `gorm:"type:text;comment:响应数据"`
Status uint8 `gorm:"default:1;comment:状态 1:成功 0:失败"`
ErrorMsg string `gorm:"type:text;comment:错误信息"`
Duration int `gorm:"comment:耗时(毫秒)"`
}
+41
View File
@@ -0,0 +1,41 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
// Order 订单主表
type Order struct {
orm.Model
orm.SoftDeletes // 软删除支持
OrderNo string `gorm:"index;not null;size:50;comment:订单号"`
UserID uint `gorm:"index;not null;comment:用户ID"`
Amount float64 `gorm:"type:decimal(10,2);not null;comment:订单金额"`
Status string `gorm:"size:20;default:'pending';comment:订单状态 pending:待支付 paid:已支付 cancelled:已取消"`
Remark string `gorm:"type:text;comment:备注"`
// CreatedAt 字段由 orm.Model 提供,用于分表
}
// TableName 指定表名(分表时会自动添加后缀)
func (Order) TableName() string {
return "orders"
}
// OrderDetail 订单详情表
type OrderDetail struct {
orm.Model
orm.SoftDeletes // 软删除支持
OrderID uint `gorm:"index;not null;comment:订单ID"`
ProductID uint `gorm:"index;not null;comment:商品ID"`
ProductName string `gorm:"size:200;not null;comment:商品名称"`
Price float64 `gorm:"type:decimal(10,2);not null;comment:单价"`
Quantity int `gorm:"not null;comment:数量"`
Subtotal float64 `gorm:"type:decimal(10,2);not null;comment:小计"`
// CreatedAt 字段由 orm.Model 提供,用于分表
}
// TableName 指定表名(分表时会自动添加后缀)
func (OrderDetail) TableName() string {
return "order_details"
}
+30
View File
@@ -0,0 +1,30 @@
package models
import (
"time"
"github.com/goravel/framework/database/orm"
)
// Payment 支付记录表
type Payment struct {
orm.Model
orm.SoftDeletes
PaymentNo string `gorm:"index;not null;size:50;comment:支付单号" json:"payment_no"`
OrderNo string `gorm:"index;not null;size:50;comment:订单号" json:"order_no"`
PaymentMethodID uint `gorm:"index;not null;comment:支付方式ID" json:"payment_method_id"`
PaymentMethod PaymentMethod `gorm:"foreignKey:PaymentMethodID" json:"payment_method,omitempty"`
UserID uint `gorm:"index;not null;comment:用户ID" json:"user_id"`
Amount float64 `gorm:"type:decimal(10,2);not null;comment:支付金额" json:"amount"`
Status string `gorm:"size:20;default:'pending';comment:支付状态 pending:待支付 paid:已支付 failed:支付失败 cancelled:已取消" json:"status"`
ThirdPartyNo string `gorm:"size:100;comment:第三方支付单号" json:"third_party_no"`
PayTime *time.Time `gorm:"comment:支付时间" json:"pay_time"`
FailReason string `gorm:"type:text;comment:失败原因" json:"fail_reason"`
NotifyData string `gorm:"type:text;comment:回调通知数据(JSON格式)" json:"-"` // 不返回给前端
Remark string `gorm:"type:text;comment:备注" json:"remark"`
}
// TableName 指定表名
func (Payment) TableName() string {
return "payments"
}
+24
View File
@@ -0,0 +1,24 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
// PaymentMethod 支付方式表
type PaymentMethod struct {
orm.Model
orm.SoftDeletes
Name string `gorm:"size:50;not null;comment:支付方式名称(如微信支付,支付宝)" json:"name"`
Code string `gorm:"size:20;not null;uniqueIndex;comment:支付方式代码(如wechat,alipay)" json:"code"`
Type string `gorm:"size:20;not null;comment:支付类型(如wechat,alipay,qq,allinpay,lakala,paypal,apple,saobei)" json:"type"`
Config string `gorm:"type:text;comment:支付配置(JSON格式,存储密钥、证书等敏感信息)" json:"-"` // 不返回给前端
IsActive bool `gorm:"default:true;comment:是否启用" json:"is_active"`
Sort int `gorm:"default:0;comment:排序" json:"sort"`
Description string `gorm:"type:text;comment:描述" json:"description"`
}
// TableName 指定表名
func (PaymentMethod) TableName() string {
return "payment_methods"
}
+19
View File
@@ -0,0 +1,19 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Permission struct {
orm.Model
Name string `gorm:"uniqueIndex;not null;size:50;comment:权限名称"`
Slug string `gorm:"uniqueIndex;not null;size:100;comment:权限标识"`
Method string `gorm:"size:10;comment:请求方法 GET,POST,PUT,DELETE等"`
Path string `gorm:"size:255;comment:路由路径"`
Description string `gorm:"size:255;comment:权限描述"`
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用"`
Sort int `gorm:"default:0;comment:排序"`
MenuID uint `gorm:"index;default:0;comment:关联菜单ID"`
Menu Menu `gorm:"foreignKey:MenuID"`
Roles []Role `gorm:"many2many:role_permission;comment:角色"`
}
+26
View File
@@ -0,0 +1,26 @@
package models
import (
"time"
"github.com/goravel/framework/database/orm"
)
type PersonalAccessToken struct {
orm.Model
TokenableType string `gorm:"column:tokenable_type;type:varchar(255);comment:模型类型" json:"tokenable_type"`
TokenableID uint `gorm:"column:tokenable_id;type:bigint;comment:模型ID" json:"tokenable_id"`
Name string `gorm:"column:name;type:varchar(255);default:'';comment:token名称" json:"name"`
Token string `gorm:"column:token;type:varchar(64);uniqueIndex;comment:token值(hash" json:"token"`
Abilities string `gorm:"column:abilities;type:text;nullable;comment:权限列表(JSON" json:"abilities"`
LastUsedAt *time.Time `gorm:"column:last_used_at;type:timestamp;nullable;comment:最后使用时间" json:"last_used_at"`
ExpiresAt *time.Time `gorm:"column:expires_at;type:timestamp;nullable;comment:过期时间,NULL表示永不过期" json:"expires_at"`
Browser string `gorm:"column:browser;type:varchar(100);nullable;comment:浏览器" json:"browser"`
IP string `gorm:"column:ip;type:varchar(45);nullable;comment:IP地址" json:"ip"`
OS string `gorm:"column:os;type:varchar(100);nullable;comment:操作系统" json:"os"`
SessionID string `gorm:"column:session_id;type:varchar(64);nullable;comment:会话编号" json:"session_id"`
}
func (PersonalAccessToken) TableName() string {
return "personal_access_tokens"
}
+17
View File
@@ -0,0 +1,17 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type Role struct {
orm.Model
Name string `gorm:"uniqueIndex;not null;size:50;comment:角色名称"`
Slug string `gorm:"uniqueIndex;not null;size:50;comment:角色标识"`
Description string `gorm:"size:255;comment:角色描述"`
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用"`
Sort int `gorm:"default:0;comment:排序"`
Admins []Admin `gorm:"many2many:admin_role;comment:管理员"`
Permissions []Permission `gorm:"many2many:role_permission;comment:权限"`
Menus []Menu `gorm:"many2many:role_menu;comment:菜单"`
}
+16
View File
@@ -0,0 +1,16 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
type SystemLog struct {
orm.Model
Level string `gorm:"size:20;comment:日志级别"`
Module string `gorm:"size:50;comment:模块"`
TraceID string `gorm:"size:120;comment:链路ID" json:"trace_id"`
Message string `gorm:"type:text;comment:日志消息"`
Context string `gorm:"type:text;comment:上下文信息"`
IP string `gorm:"size:50;comment:IP地址"`
UserAgent string `gorm:"size:500;comment:用户代理"`
}
+29
View File
@@ -0,0 +1,29 @@
package models
import (
"time"
"github.com/goravel/framework/database/orm"
)
// User 用户表(普通用户,区别于管理员)
type User struct {
orm.Model
Username string `gorm:"not null;size:50;uniqueIndex;comment:用户名" json:"username"`
Password string `gorm:"not null;size:255;comment:密码" json:"-"` // 使用 json:"-" 隐藏密码字段
Nickname string `gorm:"size:50;comment:昵称" json:"nickname"`
Avatar string `gorm:"size:255;comment:头像" json:"avatar"`
Email string `gorm:"size:100;index;comment:邮箱" json:"email"`
Phone string `gorm:"size:20;index;comment:手机号" json:"phone"`
Balance float64 `gorm:"type:decimal(18,8);default:0;comment:当前余额" json:"balance"`
CurrencyID uint `gorm:"index;comment:货币ID" json:"currency_id"`
Currency *Currency `gorm:"foreignKey:CurrencyID" json:"currency,omitempty"`
Status uint8 `gorm:"default:1;comment:状态 1:启用 0:禁用" json:"status"`
LastLoginAt *time.Time `gorm:"comment:最后登录时间" json:"last_login_at"`
orm.SoftDeletes
}
// TableName 指定表名
func (User) TableName() string {
return "users"
}
+36
View File
@@ -0,0 +1,36 @@
package models
import (
"github.com/goravel/framework/database/orm"
)
// UserBalanceLog 用户余额变动记录(使用自定义分表逻辑,按 user_id 哈希分表)
type UserBalanceLog struct {
orm.Model
UserID uint `gorm:"index;not null;comment:用户ID" json:"user_id"`
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"` // 关联 users 表
Type string `gorm:"size:20;not null;comment:变动类型:income收入,expense支出,refund退款" json:"type"`
Amount float64 `gorm:"type:decimal(18,8);not null;comment:变动金额" json:"amount"`
Balance float64 `gorm:"type:decimal(18,8);not null;comment:变动后余额" json:"balance"`
Source string `gorm:"size:50;comment:来源:order订单,recharge充值,withdraw提现,manual手动" json:"source"`
SourceID *uint `gorm:"index;comment:来源ID(如订单ID)" json:"source_id"`
Description string `gorm:"type:text;comment:描述" json:"description"`
OperatorID *uint `gorm:"index;comment:操作员ID" json:"operator_id"`
Operator *Admin `gorm:"foreignKey:OperatorID" json:"operator,omitempty"` // 关联 admins 表
Status string `gorm:"size:20;default:'success';comment:状态:success成功,failed失败" json:"status"`
Remark string `gorm:"type:text;comment:备注" json:"remark"`
}
// TableName 指定表名
// 注意:此表使用哈希分表,不能直接使用基础表名查询
// 必须通过 Table() 方法指定分表名称,例如:
//
// tableName := utils.GetUserBalanceLogsShardingTableName(userID)
// facades.Orm().Query().Table(tableName).Where(...)
//
// 返回空字符串,强制开发者必须使用 Table() 方法指定分表名称
func (UserBalanceLog) TableName() string {
// 返回空字符串,防止直接使用基础表名查询
// 哈希分表必须通过 Table() 方法指定分表名称
return ""
}