Admin.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php namespace Manage\Api;
  2. use Dever;
  3. use Manage\Lib\Auth;
  4. class Admin extends Auth
  5. {
  6. public function info()
  7. {
  8. $this->user['system']['show'] = true;
  9. $this->user['system']['id'] = $this->user['select']['system_id'];
  10. $this->user['system']['name'] = '当前系统';
  11. $this->user['system']['list'] = $this->system();
  12. return $this->user;
  13. }
  14. # 获取当前的系统列表
  15. public function system()
  16. {
  17. $where = array();
  18. if ($this->user['auth']['system']) {
  19. $where['id'] = array('in', $this->user['auth']['system']);
  20. }
  21. $result = array();
  22. $system = Dever::db('system')->select($where);
  23. $i = 0;
  24. foreach ($system as $k => $v) {
  25. $child = Dever::db($v['relation_table'])->select([])->fetchAll();
  26. if ($child) {
  27. $data = array();
  28. foreach ($child as $k1 => $v1) {
  29. $v1['select'] = false;
  30. if ($v['id'] == $this->user['select']['system_id'] && $v1['id'] == $this->user['select']['relation_id']) {
  31. $this->user['system']['name'] = $v1['name'];
  32. $v1['select'] = true;
  33. }
  34. $key = $v['id'] . '-' . $v1['id'];
  35. if ($this->user['system_relation']) {
  36. if (strstr($this->user['system_relation'], $key)) {
  37. $data[] = $v1;
  38. }
  39. } else {
  40. $data[] = $v1;
  41. }
  42. }
  43. if ($data) {
  44. $result[$i] = $v;
  45. $result[$i]['child'] = $data;
  46. $i++;
  47. }
  48. }
  49. }
  50. if ($i <= 1) {
  51. $this->user['system']['show'] = false;
  52. }
  53. return $result;
  54. }
  55. # 根据角色获取子系统
  56. public function getSystem($value = false)
  57. {
  58. if (!$value) {
  59. $result['system_relation']['option'] = array();
  60. return $result;
  61. }
  62. $result = array();
  63. $role = Dever::db('role')->select(array('id' => array('in', $value)))->fetchAll();
  64. if ($role) {
  65. $info = $system = array();
  66. foreach ($role as $k => $v) {
  67. if ($v['system']) {
  68. $child = Dever::db('system')->select(array('id' => array('in', $v['system'])))->fetchAll();
  69. if ($child) {
  70. foreach ($child as $k1 => $v1) {
  71. if (isset($info[$v1['id']])) {
  72. continue;
  73. }
  74. $info[$v1['id']] = true;
  75. $v1['value'] = 's-' . $v1['id'];
  76. $v1['label'] = $v1['name'];
  77. $v1['children'] = array();
  78. $data = Dever::db($v1['relation_table'])->select([], array('col' => 'concat('.$v1['id'].', "-", id) as value, name as label'))->fetchAll();
  79. if ($data) {
  80. $v1['children'] = array_merge($v1['children'], $data);
  81. }
  82. $system[] = $v1;
  83. }
  84. }
  85. }
  86. }
  87. $result['system_relation']['option'] = $system;
  88. }
  89. return $result;
  90. }
  91. # 切换系统
  92. public function setSystem()
  93. {
  94. $system_id = Dever::input('system_id');
  95. $this->checkSystem($this->user['select']['system_id']);
  96. $relation_id = Dever::input('relation_id');
  97. if ($this->user['system_relation'] && !strstr($this->user['system_relation'], $relation_id)) {
  98. Dever::error('无系统权限');
  99. }
  100. $result = Dever::load('common')->token($this->user['id'], $this->user['mobile'], $system_id, $relation_id);
  101. return $result;
  102. }
  103. # 修改资料
  104. public function setInfo()
  105. {
  106. $username = Dever::input('username');
  107. $password = Dever::input('password');
  108. $data = array();
  109. if ($username) {
  110. $data['name'] = $username;
  111. }
  112. if ($password) {
  113. $data += Dever::load('common')->createPwd($password);
  114. }
  115. $state = false;
  116. if ($data) {
  117. $state = Dever::db($this->system['relation_user_table'])->update($this->uid, $data);
  118. }
  119. if (!$state) {
  120. Dever::error('修改失败');
  121. }
  122. return 'yes';
  123. }
  124. }