Admin.php 5.3 KB

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