Role.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. class Role extends Auth
  4. {
  5. public function update($db, $data)
  6. {
  7. if ($data['auth']) {
  8. $auth = explode(',', $data['auth']);
  9. $data['auth'] = array();
  10. $module = $menu = $func = array();
  11. foreach ($auth as $k => $v) {
  12. if (!strstr($v, '-')) {
  13. if (strstr($v, 'v')) {
  14. $menu[] = trim($v, 'v');
  15. } else {
  16. $func[] = $v;
  17. }
  18. $data['auth'][] = $v;
  19. }
  20. }
  21. if ($func) {
  22. $funcData = Dever::db('menu_func', 'manage')->select(array('id' => array('in', $func)), array('group' => 'menu_id'));
  23. foreach ($funcData as $k => $v) {
  24. $menu[] = $v['menu_id'];
  25. }
  26. $menuData = Dever::db('menu', 'manage')->select(array('id' => array('in', $menu)), array('group' => 'module_id'));
  27. foreach ($menuData as $k => $v) {
  28. $module[] = $v['module_id'];
  29. }
  30. }
  31. $data['auth'] = implode(',', $data['auth']);
  32. $data['menu'] = implode(',', $menu);
  33. $data['module'] = implode(',', $module);
  34. }
  35. return $data;
  36. }
  37. public function getAuthData()
  38. {
  39. $result = array();
  40. $extend = Dever::load('common', 'manage')->extend();
  41. if ($extend && $extend['system_id']) {
  42. $system_id = $extend['system_id'];
  43. } else {
  44. $system_id = 1;
  45. }
  46. $info = Dever::db('system', 'manage')->find($system_id);
  47. $where = array();
  48. $where['system'] = $info['key'];
  49. $module = Dever::db('system_module', 'manage')->select($where);
  50. foreach ($module as $k => $v) {
  51. $result[$k]['value'] = 's-' . $v['id'];
  52. $result[$k]['label'] = $v['name'];
  53. $result[$k]['children'] = Dever::db('menu', 'manage')->tree(array('module_id' => $v['id'], 'show' => array('<', '3')), array('parent_id', '0', 'id'), array($this, 'getAuthInfo'), array('col' => 'id,name as label,parent_id,`key`,func'));
  54. }
  55. return $result;
  56. }
  57. public function getAuthInfo($k, $info)
  58. {
  59. if ($info['func'] == 1) {
  60. $info['value'] = 'm-' . $info['id'];
  61. $info['children'] = Dever::db('menu_func', 'manage')->select(array('menu_id' => $info['id']), array('col' => 'id as value,name as label'));
  62. if (!$info['children']) {
  63. return array();
  64. }
  65. } else {
  66. $info['value'] = 'v' . $info['id'];
  67. }
  68. return $info;
  69. }
  70. # 展示系统
  71. public function showSystem($data)
  72. {
  73. return Dever::db('system', 'manage')->show(array('id' => array('in', $data)));
  74. }
  75. # 展示系统模块
  76. public function showModule($data)
  77. {
  78. return Dever::db('system_module', 'manage')->show(array('id' => array('in', $data)));
  79. }
  80. # 展示菜单
  81. public function showMenu($data)
  82. {
  83. return Dever::db('menu', 'manage')->show(array('id' => array('in', $data)));
  84. }
  85. # 展示权限
  86. public function showFunc($data)
  87. {
  88. return Dever::db('menu_func', 'manage')->show(array('id' => array('in', $data)));
  89. }
  90. }