System_root.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Models;
  3. class System_root extends BaseModel
  4. {
  5. protected $table = "system_root";
  6. public $timestamps = false;
  7. //获取管理员权限列表
  8. public function getRootlist($value = '', $type = 1, $limit = 10, $sort = 1, $ads = 'asc')
  9. {
  10. $key = $this->getFeild($type);
  11. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  12. $data = $this->orderby($sort, $ads);
  13. if (!(empty($value)) && is_array($value)) {
  14. $data = $data->where($value);
  15. } else if (!(empty($value))) {
  16. $data = $this->where($key, $value);
  17. }
  18. $data = $data->paginate($limit);
  19. if (!$data) {
  20. return -7010100102; //没有列表数据
  21. }
  22. return $data->toArray();
  23. }
  24. //获取权限信息
  25. public function getRootDetails($value, $type = 1, $jointable = '', $columnn = '', $columnw = '')
  26. {
  27. $key = $this->getFeild($type);
  28. if (empty($jointable)) {
  29. $data = $this->where($key, $value)->first();
  30. } else {
  31. $data = $this->where($key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
  32. }
  33. ;
  34. if (!$data) {
  35. return -7010100202; //没有权限信息
  36. }
  37. return $data->toArray();
  38. }
  39. //字段对应值
  40. private function getFeild($num)
  41. {
  42. $data = array(
  43. '1' => 'id',
  44. '2' => 'level',
  45. '3' => 'name',
  46. '4' => 'settingmoney',
  47. );
  48. return $data[$num];
  49. }
  50. //获取角色信息
  51. public function getInfo($value, $type)
  52. {
  53. $key = $this->getFeild($type);
  54. $data = $this->where($key, $value)->first();
  55. if (!$data) {
  56. return -7010100202; //没有权限信息
  57. }
  58. return $data->toArray();
  59. }
  60. public function getlist($list = 10)
  61. {
  62. $data = $this->orderBy('settingmoney', 'desc')->paginate($list);
  63. if (!$data) {
  64. return -7050000204;
  65. }
  66. return $data->toArray();
  67. }
  68. //修改权限信息
  69. public function editRoot($id, $data)
  70. {
  71. $res = $this->where('id', $id)->update($data);
  72. if (!$res) {
  73. return -7010100302;
  74. }
  75. return 1;
  76. }
  77. //所有角色
  78. public function getAllRole()
  79. {
  80. $data = $this->get();
  81. return $data->toArray();
  82. }
  83. //检测是否有等级为0的角色
  84. public function checkSupper($ids)
  85. {
  86. $data = $this->whereIn('id', $ids)->where('level', 0)->get();
  87. if (!$data) {
  88. return -1234455;
  89. }
  90. $data = $data->toArray();
  91. if (empty($data)) {
  92. return -1234455;
  93. }
  94. return 1;
  95. }
  96. /**
  97. * 得到超管的角色id
  98. */
  99. protected function getSupperRole()
  100. {
  101. $role = S('ADMIN_ROLE_ID');
  102. if ($role != -1) {
  103. return $role;
  104. }
  105. $re = $this->where('level', 0)->first();
  106. if (!$re) {
  107. return -1234466; //no supper role
  108. }
  109. S('ADMIN_ROLE_ID', $re->id);
  110. return $re->id;
  111. }
  112. }