package entity import ( "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/mysql" ) var VarCurrentUser = &CurrentUser{} //当前登录用户 type CurrentUser struct { Role_admin_department bool //是否是部门管理员 Role_admin_system bool //是否是系统管理员 Ent *EntInfo //企业信息 Dept *Department //部门信息 BondPhone string //手机号 NickName string //昵称 HeadImageUrl string //头像 PersonalAuth int //个人认证 PersonalAuthReason string //个人认证不通过原因 User_power int //是否分配权限 User_name string //用户姓名 Mysql *mysql.Mysql } type Department struct { Id int Name string //公司名 Pid int //上级部门id Pname string //上级部门名称 Nodiff int //全员无差别接收 0:关闭 1:打开 Subdis int //订阅分发 0:关闭 1:打开 Aid int //管理员id Aname string //管理员姓名 User_count int //该部门下员工的总数 Dept_count int //该部门下子部门总数 } //当前登录用户的信息 func (this *CurrentUser) EntInfo(entId, entUserId int) *CurrentUser { currentUser := &CurrentUser{ Ent: &EntInfo{}, Dept: &Department{}, } varentinfo := &EntInfo{ Mysql: this.Mysql, } currentUser.Ent = varentinfo.GetById(entId) user := this.Mysql.SelectBySql(`SELECT a.name as user_name from entniche_user a INNER JOIN entniche_user_role b on (a.id=b.user_id) where a.id=? and b.role_id=? limit 1`, entUserId, Role_admin_system) if user != nil && len(*user) > 0 { currentUser.Role_admin_system = true currentUser.User_name, _ = (*user)[0]["user_name"].(string) currentUser.User_power = 1 r := this.Mysql.SelectBySql(`SELECT id,name,subdis,nodiff from entniche_department where ent_id=? and pid=0 limit 1`, entId) if r != nil && len(*r) == 1 { department := common.JsonUnmarshal((*r)[0], &Department{}).(*Department) if department != nil { department.Pid = department.Id currentUser.Dept = department } } } else { //角色、权限 r := this.Mysql.SelectBySql(`SELECT a.name as user_name,a.power as user_power,b.role_id,d.id as dept_id,d.name as dept_name,d.subdis as dept_subdis,d.nodiff as dept_nodiff,e.id as dept_pid from entniche_user a LEFT JOIN entniche_user_role b on (b.user_id=?) INNER JOIN entniche_department_user c on (a.id=? and a.id=c.user_id) INNER JOIN entniche_department d on (c.dept_id=d.id) INNER JOIN entniche_department e on (e.ent_id=? and e.pid=0) order by a.id desc limit 1`, entUserId, entUserId, entId) if r != nil && len(*r) == 1 { currentUser.User_name, _ = (*r)[0]["user_name"].(string) currentUser.User_power = common.IntAll((*r)[0]["user_power"]) if common.IntAll((*r)[0]["role_id"]) == Role_admin_department { currentUser.Role_admin_department = true } currentUser.Dept.Id = common.IntAll((*r)[0]["dept_id"]) currentUser.Dept.Pid = common.IntAll((*r)[0]["dept_pid"]) currentUser.Dept.Name = common.ObjToString((*r)[0]["dept_name"]) currentUser.Dept.Subdis = common.IntAll((*r)[0]["dept_subdis"]) currentUser.Dept.Nodiff = common.IntAll((*r)[0]["dept_nodiff"]) } } return currentUser }