Admin.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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['module']['show'] = true;
  9. $this->user['module']['id'] = $this->user['select']['module_id'];
  10. $this->user['module']['name'] = '当前模块';
  11. $this->user['module']['list'] = $this->module();
  12. $this->user['module']['uri'] = array('system' => $this->system['key'], 'number' => $this->system_info['number']);
  13. return $this->user;
  14. }
  15. # 获取当前的模块列表
  16. public function module()
  17. {
  18. $where = array();
  19. if ($this->user['auth']['module']) {
  20. $where['id'] = array('in', $this->user['auth']['module']);
  21. }
  22. $result = array();
  23. $module = Dever::db('system_module', 'manage')->select($where);
  24. $i = 0;
  25. foreach ($module as $k => $v) {
  26. $child = Dever::db($v['data_table'])->select([]);
  27. if ($child) {
  28. $data = array();
  29. foreach ($child as $k1 => $v1) {
  30. $v1['select'] = false;
  31. if ($v['id'] == $this->user['select']['module_id'] && $v1['id'] == $this->user['select']['data_id']) {
  32. $this->user['module']['name'] = $v1['name'];
  33. $v1['select'] = true;
  34. }
  35. $key = $v['id'] . '-' . $v1['id'];
  36. if ($this->user['module_data']) {
  37. if (strstr($this->user['module_data'], $key)) {
  38. $data[] = $v1;
  39. }
  40. } else {
  41. $data[] = $v1;
  42. }
  43. }
  44. if ($data) {
  45. $result[$i] = $v;
  46. $result[$i]['child'] = $data;
  47. $i++;
  48. }
  49. }
  50. }
  51. if ($i <= 1) {
  52. $this->user['module']['show'] = false;
  53. }
  54. return $result;
  55. }
  56. # 根据角色获取模块下的数据
  57. public function getModuleData($value = false)
  58. {
  59. if (!$value) {
  60. $result['module_data']['option'] = array();
  61. return $result;
  62. }
  63. $result = array();
  64. $role = Dever::db($this->system['role_table'])->select(array('id' => array('in', $value)));
  65. if ($role) {
  66. $info = $module = array();
  67. foreach ($role as $k => $v) {
  68. if ($v['module']) {
  69. $child = Dever::db('system_module', 'manage')->select(array('id' => array('in', $v['module'])));
  70. if ($child) {
  71. foreach ($child as $k1 => $v1) {
  72. if (isset($info[$v1['id']])) {
  73. continue;
  74. }
  75. $info[$v1['id']] = true;
  76. $v1['value'] = 's-' . $v1['id'];
  77. $v1['label'] = $v1['name'];
  78. $v1['children'] = array();
  79. $data = Dever::db($v1['data_table'])->select([], array('col' => 'concat('.$v1['id'].', "-", id) as value, name as label'));
  80. if ($data) {
  81. $v1['children'] = array_merge($v1['children'], $data);
  82. }
  83. $module[] = $v1;
  84. }
  85. }
  86. }
  87. }
  88. $result['module_data']['option'] = $module;
  89. }
  90. return $result;
  91. }
  92. # 切换模块
  93. public function setModule()
  94. {
  95. $module_id = Dever::input('module_id');
  96. $this->checkModule($this->user['select']['module_id']);
  97. $data_id = Dever::input('data_id');
  98. if ($this->user['module_data'] && !strstr($this->user['module_data'], $module_id . '-' . $data_id)) {
  99. Dever::error('无模块权限');
  100. }
  101. $result = Dever::load('common')->token($this->user['id'], $this->user['mobile'], $this->user['select']['partition'], $this->user['select']['system_id'], $this->user['select']['info_id'], $module_id, $data_id);
  102. return $result;
  103. }
  104. # 修改资料
  105. public function setInfo()
  106. {
  107. $username = Dever::input('username');
  108. $password = Dever::input('password');
  109. $data = array();
  110. if ($username) {
  111. $data['name'] = $username;
  112. }
  113. if ($password) {
  114. $data += Dever::load('common')->createPwd($password);
  115. }
  116. $state = false;
  117. if ($data) {
  118. $state = Dever::db($this->system['user_table'])->update($this->uid, $data);
  119. }
  120. if (!$state) {
  121. Dever::error('修改失败');
  122. }
  123. return 'yes';
  124. }
  125. }