Admin.php 5.0 KB

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