Admin.php 5.4 KB

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