Admin.php 4.9 KB

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