entniche.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package entity
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/mysql"
  5. )
  6. var VarCurrentUser = &CurrentUser{}
  7. //当前登录用户
  8. type CurrentUser struct {
  9. Role_admin_department bool //是否是部门管理员
  10. Role_admin_system bool //是否是系统管理员
  11. Ent *EntInfo //企业信息
  12. Dept *Department //部门信息
  13. BondPhone string //手机号
  14. NickName string //昵称
  15. HeadImageUrl string //头像
  16. PersonalAuth int //个人认证
  17. PersonalAuthReason string //个人认证不通过原因
  18. User_power int //是否分配权限
  19. User_name string //用户姓名
  20. Mysql *mysql.Mysql
  21. }
  22. type Department struct {
  23. Id int
  24. Name string //公司名
  25. Pid int //上级部门id
  26. Pname string //上级部门名称
  27. Nodiff int //全员无差别接收 0:关闭 1:打开
  28. Subdis int //订阅分发 0:关闭 1:打开
  29. Aid int //管理员id
  30. Aname string //管理员姓名
  31. User_count int //该部门下员工的总数
  32. Dept_count int //该部门下子部门总数
  33. }
  34. //当前登录用户的信息
  35. func (this *CurrentUser) EntInfo(entId, entUserId int) *CurrentUser {
  36. currentUser := &CurrentUser{
  37. Ent: &EntInfo{},
  38. Dept: &Department{},
  39. }
  40. varentinfo := &EntInfo{
  41. Mysql: this.Mysql,
  42. }
  43. currentUser.Ent = varentinfo.GetById(entId)
  44. 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)
  45. if user != nil && len(*user) > 0 {
  46. currentUser.Role_admin_system = true
  47. currentUser.User_name, _ = (*user)[0]["user_name"].(string)
  48. currentUser.User_power = 1
  49. r := this.Mysql.SelectBySql(`SELECT id,name,subdis,nodiff from entniche_department where ent_id=? and pid=0 limit 1`, entId)
  50. if r != nil && len(*r) == 1 {
  51. department := common.JsonUnmarshal((*r)[0], &Department{}).(*Department)
  52. if department != nil {
  53. department.Pid = department.Id
  54. currentUser.Dept = department
  55. }
  56. }
  57. } else {
  58. //角色、权限
  59. 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
  60. LEFT JOIN entniche_user_role b on (b.user_id=?)
  61. INNER JOIN entniche_department_user c on (a.id=? and a.id=c.user_id)
  62. INNER JOIN entniche_department d on (c.dept_id=d.id)
  63. INNER JOIN entniche_department e on (e.ent_id=? and e.pid=0)
  64. order by a.id desc limit 1`, entUserId, entUserId, entId)
  65. if r != nil && len(*r) == 1 {
  66. currentUser.User_name, _ = (*r)[0]["user_name"].(string)
  67. currentUser.User_power = common.IntAll((*r)[0]["user_power"])
  68. if common.IntAll((*r)[0]["role_id"]) == Role_admin_department {
  69. currentUser.Role_admin_department = true
  70. }
  71. currentUser.Dept.Id = common.IntAll((*r)[0]["dept_id"])
  72. currentUser.Dept.Pid = common.IntAll((*r)[0]["dept_pid"])
  73. currentUser.Dept.Name = common.ObjToString((*r)[0]["dept_name"])
  74. currentUser.Dept.Subdis = common.IntAll((*r)[0]["dept_subdis"])
  75. currentUser.Dept.Nodiff = common.IntAll((*r)[0]["dept_nodiff"])
  76. }
  77. }
  78. return currentUser
  79. }