package admin import ( //_ "github.com/go-sql-driver/mysql" "github.com/beego/beego/v2/client/orm" "hongze/hongze_mobile_admin/models/custom" "time" ) type Admin struct { AdminId int `orm:"column(admin_id);pk" json:"admin_id"` AdminName string `orm:"column(admin_name);" json:"admin_name"` RealName string `orm:"column(real_name);" json:"real_name"` Password string `orm:"column(password);" json:"password"` LastUpdatedPasswordTime string `orm:"column(last_updated_password_time);" json:"last_updated_password_time"` Enabled int `orm:"column(enabled);" json:"enabled"` // 1:有效,0:禁用 Email string `orm:"column(email);" json:"email"` LastLoginTime string `orm:"column(last_login_time);" json:"last_login_time"` // 最近登陆时间 CreatedTime string `orm:"column(created_time);" json:"created_time"` // 创建时间 LastUpdatedTime string `orm:"column(last_updated_time);" json:"last_updated_time"` Role string `orm:"column(role);" json:"role"` // 用户角色 Mobile string `orm:"column(mobile);" json:"mobile"` // 手机号 RoleType int `orm:"column(role_type);" json:"role_type"` // 角色类型:1需要录入指标,0:不需要 RoleId int `orm:"column(role_id);" json:"role_id"` // 角色id RoleName string `orm:"column(role_name);" json:"role_name"` // 角色名称 RoleTypeCode string `orm:"column(role_type_code);" json:"role_type_code"` // 角色编码 DepartmentId int `orm:"column(department_id);" json:"department_id"` // 部门id DepartmentName string `orm:"column(department_name);" json:"department_name"` // 部门名称 GroupId int `orm:"column(group_id);" json:"group_id"` // 分组id GroupName string `orm:"column(group_name);" json:"group_name"` // 分组名称 Authority int `orm:"column(authority);" json:"authority"` // 管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员 Position string `orm:"column(position);" json:"position"` // 职位 } //账号密码校验 func CheckAdmin(userName, password string) (item *Admin, err error) { sql := ` SELECT a.*,b.role_type_code FROM admin AS a INNER JOIN sys_role AS b ON a.role_id=b.role_id WHERE a.admin_name=? AND a.password=? LIMIT 1` o := orm.NewOrm() err = o.Raw(sql, userName, password).QueryRow(&item) return } //根据管理员id获取管理员信息 func GetAdminById(adminId int) (item *Admin, err error) { sql := `SELECT * FROM admin WHERE admin_id=? LIMIT 1` o := orm.NewOrm() err = o.Raw(sql, adminId).QueryRow(&item) return } //根据权限code获取系统用户列表 func GetAdminListByRoleCode(roleTypeCode string) (items []*Admin, err error) { sql := `SELECT * FROM admin WHERE role_type_code=? and enabled=1 ` o := orm.NewOrm() _, err = o.Raw(sql, roleTypeCode).QueryRows(&items) return } //根据权限id获取系统用户列表 func GetAdminListByRoleId(roleId string) (items []*Admin, err error) { sql := `SELECT * FROM admin WHERE role_id=? and enabled=1 ` o := orm.NewOrm() _, err = o.Raw(sql, roleId).QueryRows(&items) return } //根据用户id字符串获取系统用户列表 func GetAdminListByIds(ids string) (items []*Admin, err error) { sql := `SELECT * FROM admin WHERE admin_id in (` + ids + `) and enabled=1 ` o := orm.NewOrm() _, err = o.Raw(sql).QueryRows(&items) return } //根据管理员id获取管理员信息(包含微信、第三方信息) func GetAdminWxById(adminId int) (item *custom.AdminWx, err error) { sql := `SELECT * FROM admin WHERE admin_id=? LIMIT 1` o := orm.NewOrm() err = o.Raw(sql, adminId).QueryRow(&item) return } func GetSysuserList(condition string, pars []interface{}, startSize, pageSize int) (items []*AdminItem, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE 1=1 ` if condition != "" { sql += condition } sql += `ORDER BY created_time DESC LIMIT ?,?` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } // AdminItem 管理后台的adminInfo,没有使用json格式化,路演这边需要用到,没办法 type AdminItem struct { AdminId int `description:"系统用户id"` AdminName string `description:"系统用户名称"` RealName string `description:"系统用户姓名"` Password string LastUpdatedPasswordTime string `json:"-"` Enabled int `description:"1:有效,0:禁用"` Email string `description:"系统用户邮箱"` LastLoginTime string CreatedTime time.Time LastUpdatedTime string Role string `description:"系统用户角色"` Mobile string `description:"手机号"` RoleType int `description:"角色类型:1需要录入指标,0:不需要"` RoleId int `description:"角色id"` RoleName string `description:"角色名称"` RoleTypeCode string `description:"角色编码"` DepartmentId int `description:"部门id"` DepartmentName string `json:"-" description:"部门名称"` TeamId int `description:"三级id"` GroupId int `description:"分组id"` GroupName string `json:"-" description:"分组名称"` Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"` Position string `description:"职位"` DepartmentGroup string `description:"部门分组"` LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"` }