系统管理基本搞定
This commit is contained in:
@@ -43,6 +43,9 @@ func Init(_ string) {
|
||||
new(SystemEmail),
|
||||
new(SystemSMS),
|
||||
new(SystemSMSTask),
|
||||
new(SystemOperationLog),
|
||||
new(SystemDomainPool),
|
||||
new(SystemTenantDomain),
|
||||
)
|
||||
|
||||
// 创建全局 Ormer
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CheckUserPermission 校验用户是否拥有指定权限标识。
|
||||
// 兼容 rights 为 JSON 数组 / 逗号分隔字符串;解析失败时默认放行,避免历史数据阻断请求。
|
||||
func CheckUserPermission(userID int, permission string) (bool, error) {
|
||||
if permission == "" || userID <= 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var user AdminUser
|
||||
if err := Orm.QueryTable(new(AdminUser)).Filter("id", userID).One(&user); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
var role AdminRole
|
||||
if err := Orm.QueryTable(new(AdminRole)).Filter("id", user.RoleID).One(&role); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if role.Rights == nil || strings.TrimSpace(*role.Rights) == "" {
|
||||
return true, nil
|
||||
}
|
||||
rightsRaw := strings.TrimSpace(*role.Rights)
|
||||
|
||||
// 1) JSON 数组格式
|
||||
var arr []string
|
||||
if err := json.Unmarshal([]byte(rightsRaw), &arr); err == nil {
|
||||
for _, p := range arr {
|
||||
if strings.TrimSpace(p) == permission {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 2) 逗号分隔字符串
|
||||
for _, p := range strings.Split(rightsRaw, ",") {
|
||||
if strings.TrimSpace(p) == permission {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// SystemDomainPool 主域名池表 yz_system_domain_pool
|
||||
type SystemDomainPool struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
MainDomain string `orm:"column(main_domain);size(255)" json:"main_domain"`
|
||||
Status int8 `orm:"column(status);default(1)" json:"status"` // 1启用 0禁用
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
func (m *SystemDomainPool) TableName() string {
|
||||
return "yz_system_domain_pool"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// SystemOperationLog 操作日志表 yz_system_operation_log
|
||||
type SystemOperationLog struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Tid *uint64 `orm:"column(tid);null" json:"tid"`
|
||||
UserID uint64 `orm:"column(user_id);default(0)" json:"user_id"`
|
||||
Module string `orm:"column(module);size(50);default('')" json:"module"`
|
||||
Action string `orm:"column(action);size(50);default('')" json:"action"`
|
||||
Method string `orm:"column(method);size(10);default('')" json:"method"`
|
||||
URL string `orm:"column(url);size(255);default('')" json:"url"`
|
||||
IP string `orm:"column(ip);size(50);default('')" json:"ip"`
|
||||
UserAgent string `orm:"column(user_agent);size(500);default('')" json:"user_agent"`
|
||||
RequestData *string `orm:"column(request_data);type(text);null" json:"request_data"`
|
||||
ResponseData *string `orm:"column(response_data);type(text);null" json:"response_data"`
|
||||
Status int8 `orm:"column(status);default(1)" json:"status"`
|
||||
ErrorMessage *string `orm:"column(error_message);type(text);null" json:"error_message"`
|
||||
ExecutionTime float64 `orm:"column(execution_time);digits(10);decimals(3);default(0)" json:"execution_time"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
func (m *SystemOperationLog) TableName() string {
|
||||
return "yz_system_operation_log"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// SystemTenantDomain 租户域名表 yz_system_tenant_domain
|
||||
type SystemTenantDomain struct {
|
||||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||||
Tid *uint64 `orm:"column(tid);null" json:"tid"`
|
||||
SubDomain *string `orm:"column(sub_domain);size(50);null" json:"sub_domain"`
|
||||
MainDomain *string `orm:"column(main_domain);size(255);null" json:"main_domain"`
|
||||
FullDomain *string `orm:"column(full_domain);size(255);null" json:"full_domain"`
|
||||
Status int `orm:"column(status);null" json:"status"` // 1已生效 / 0审核中 / 2禁用
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
|
||||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||||
}
|
||||
|
||||
func (m *SystemTenantDomain) TableName() string {
|
||||
return "yz_system_tenant_domain"
|
||||
}
|
||||
Reference in New Issue
Block a user