Initial commit

This commit is contained in:
sjk
2025-11-17 13:32:54 +08:00
commit e788eab6eb
1659 changed files with 171560 additions and 0 deletions

View File

@@ -0,0 +1,212 @@
package model
import (
"time"
"gorm.io/gorm"
)
// Coupon 优惠券模型
type Coupon struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"size:100;not null" json:"name" binding:"required"`
Type uint8 `gorm:"not null" json:"type"` // 1-满减券 2-折扣券 3-免邮券
Value uint `gorm:"not null" json:"value"` // 优惠值:满减券为金额(分),折扣券为折扣(如85表示8.5折)
MinAmount uint `gorm:"default:0" json:"min_amount"` // 最低消费金额,单位:分
TotalCount uint `gorm:"not null" json:"total_count"` // 总发放数量
UsedCount uint `gorm:"default:0" json:"used_count"` // 已使用数量
StartTime time.Time `gorm:"not null" json:"start_time"`
EndTime time.Time `gorm:"not null" json:"end_time"`
Status uint8 `gorm:"default:1;index" json:"status"` // 0-禁用 1-启用
Description string `gorm:"size:255" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联关系
UserCoupons []UserCoupon `gorm:"foreignKey:CouponID" json:"user_coupons,omitempty"`
}
// TableName 指定表名
func (Coupon) TableName() string {
return "ai_coupons"
}
// UserCoupon 用户优惠券模型
type UserCoupon struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
UserID uint `gorm:"not null;index" json:"user_id"`
CouponID uint `gorm:"not null;index" json:"coupon_id"`
OrderID *uint `gorm:"index" json:"order_id"` // 使用的订单IDNULL表示未使用
Status uint8 `gorm:"default:0;index" json:"status"` // 0-未使用 1-已使用 2-已过期
UsedTime *time.Time `json:"used_time"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联关系
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
Coupon Coupon `gorm:"foreignKey:CouponID" json:"coupon,omitempty"`
Order Order `gorm:"foreignKey:OrderID" json:"order,omitempty"`
}
// TableName 指定表名
func (UserCoupon) TableName() string {
return "ai_user_coupons"
}
// Notification 通知模型
type Notification struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
UserID uint `gorm:"not null;index" json:"user_id"`
Title string `gorm:"size:100;not null" json:"title" binding:"required"`
Content string `gorm:"type:text;not null" json:"content" binding:"required"`
Type uint8 `gorm:"not null;index" json:"type"` // 1-系统通知 2-订单通知 3-活动通知
IsRead uint8 `gorm:"default:0;index" json:"is_read"` // 0-未读 1-已读
ReadTime *time.Time `json:"read_time"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联关系
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}
// TableName 指定表名
func (Notification) TableName() string {
return "ai_notifications"
}
// FileUpload 文件上传模型
type FileUpload struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
FileName string `gorm:"size:255;not null" json:"file_name"`
FileSize uint `gorm:"not null" json:"file_size"`
FileType string `gorm:"size:50;not null" json:"file_type"`
FilePath string `gorm:"size:500;not null" json:"file_path"`
FileURL string `gorm:"size:500;not null" json:"file_url"`
UploadBy uint `gorm:"not null;index" json:"upload_by"` // 上传者ID
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 指定表名
func (FileUpload) TableName() string {
return "ai_file_uploads"
}
// SystemConfig 系统配置模型
type SystemConfig struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
ConfigKey string `gorm:"size:100;uniqueIndex;not null" json:"config_key" binding:"required"`
ConfigValue string `gorm:"type:text" json:"config_value"`
ConfigDesc string `gorm:"size:255" json:"config_desc"`
ConfigType string `gorm:"size:20;default:'string'" json:"config_type"` // string, number, boolean, json
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// TableName 指定表名
func (SystemConfig) TableName() string {
return "ai_system_configs"
}
// SystemLog 系统日志模型
type SystemLog struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Level string `gorm:"size:20;not null;index" json:"level"`
Message string `gorm:"type:text;not null" json:"message"`
Context string `gorm:"type:text" json:"context"` // JSON格式的上下文信息
CreatedAt time.Time `json:"created_at"`
}
// TableName 指定表名
func (SystemLog) TableName() string {
return "ai_system_logs"
}
// AdminUser 管理员用户模型
type AdminUser struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Username string `gorm:"size:50;uniqueIndex;not null" json:"username" binding:"required"`
Password string `gorm:"size:255;not null" json:"-"` // 不返回密码
Nickname string `gorm:"size:50" json:"nickname"`
Email string `gorm:"size:100" json:"email"`
Phone string `gorm:"size:20" json:"phone"`
Avatar string `gorm:"size:255" json:"avatar"`
RoleID uint `gorm:"not null;index" json:"role_id"`
Status uint8 `gorm:"default:1;index" json:"status"` // 0-禁用 1-正常
LastLogin *time.Time `json:"last_login"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联关系
Role AdminRole `gorm:"foreignKey:RoleID" json:"role,omitempty"`
}
// TableName 指定表名
func (AdminUser) TableName() string {
return "ai_admin_users"
}
// AdminRole 管理员角色模型
type AdminRole struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Name string `gorm:"size:50;not null" json:"name" binding:"required"`
Description string `gorm:"size:255" json:"description"`
Permissions string `gorm:"type:text" json:"permissions"` // JSON格式的权限列表
Status uint8 `gorm:"default:1;index" json:"status"` // 0-禁用 1-正常
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// 关联关系
AdminUsers []AdminUser `gorm:"foreignKey:RoleID" json:"admin_users,omitempty"`
}
// TableName 指定表名
func (AdminRole) TableName() string {
return "ai_admin_roles"
}
// OperationLog 操作日志模型
type OperationLog struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
UserID uint `gorm:"not null;index" json:"user_id"`
UserType string `gorm:"size:20;not null;index" json:"user_type"` // user, admin
Action string `gorm:"size:100;not null" json:"action"`
Resource string `gorm:"size:100;not null" json:"resource"`
Method string `gorm:"size:10;not null" json:"method"`
Path string `gorm:"size:255;not null" json:"path"`
IP string `gorm:"size:50;not null" json:"ip"`
UserAgent string `gorm:"size:500" json:"user_agent"`
RequestData string `gorm:"type:text" json:"request_data"`
ResponseData string `gorm:"type:text" json:"response_data"`
StatusCode int `gorm:"not null" json:"status_code"`
Duration int `gorm:"not null" json:"duration"` // 请求耗时,单位:毫秒
CreatedAt time.Time `json:"created_at"`
}
// TableName 指定表名
func (OperationLog) TableName() string {
return "ai_operation_logs"
}
// DataStatistics 数据统计模型
type DataStatistics struct {
ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
Date string `gorm:"size:10;not null;index" json:"date"` // YYYY-MM-DD
Type string `gorm:"size:50;not null;index" json:"type"` // daily, weekly, monthly
Metric string `gorm:"size:50;not null;index" json:"metric"` // user_count, order_count, sales_amount等
Value uint `gorm:"not null" json:"value"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName 指定表名
func (DataStatistics) TableName() string {
return "ai_data_statistics"
}