System.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. use Dever\Project;
  4. use Dever\Helper\Str;
  5. class System extends Auth
  6. {
  7. public function getTree()
  8. {
  9. $data = Dever::db('system', 'manage')->select([]);
  10. $result = array();
  11. $result[] = array
  12. (
  13. 'id' => 'root',
  14. 'name' => '全部系统',
  15. 'children' => $data,
  16. );
  17. return $result;
  18. }
  19. # 创建管理员
  20. public function update($system, $db, $data)
  21. {
  22. if (isset($data['mobile']) && $data['mobile']) {
  23. $system = Dever::db('system', 'manage')->find(array('key' => $system));
  24. $data['system_id'] = $system['id'];
  25. $data['info_id'] = $data['id'];
  26. $data['partition'] = $system['partition'];
  27. $db = Dever::db($system['user_table'], '', true, 'default', Dever::load('common', 'manage')->system($data));
  28. $info = $db->find(array('mobile' => $data['mobile']));
  29. if (!$info) {
  30. $password = '123456';
  31. $insert['name'] = Str::hide($data['mobile']);
  32. $insert['mobile'] = $data['mobile'];
  33. $insert['role'] = 1;
  34. $insert += Dever::load('common', 'manage')->createPwd($password);
  35. $db->insert($insert);
  36. }
  37. }
  38. }
  39. # 创建账户
  40. public function createUser($data, $state = true)
  41. {
  42. if (isset($data['mobile']) && $data['mobile'] && isset($data['password']) && $data['password']) {
  43. $info = Dever::db($data['table'])->find($data['id']);
  44. if ($info) {
  45. $system = Dever::db('system', 'manage')->find(array('key' => $data['system']));
  46. $set['system_id'] = $system['id'];
  47. $set['info_id'] = 1;
  48. $set['partition'] = $system['partition'];
  49. $db = Dever::db($system['user_table'], '', 'default', Dever::load('common', 'manage')->system($set));
  50. $user = $db->find(array('mobile' => $data['mobile']));
  51. if ($state && $user) {
  52. Dever::error('手机号' . $data['mobile'] . '已存在,请更换手机号');
  53. }
  54. $module = Dever::db('system_module', 'manage')->find(array('key' => $data['module'], 'system' => 'group'));
  55. $insert['name'] = $info['name'];
  56. $insert['mobile'] = $data['mobile'];
  57. $insert['role'] = 2;
  58. $insert['module_data'] = $module['id'] . '-' . $info['id'];
  59. $insert += Dever::load('common', 'manage')->createPwd($data['password']);
  60. if (!$user) {
  61. $db->insert($insert);
  62. } else {
  63. $module_data = $insert['module_data'];
  64. unset($insert['module_data']);
  65. if (!strstr($user['module_data'], $module_data)) {
  66. $insert['module_data'] = $module_data . ',' . $user['module_data'];
  67. }
  68. $db->update($user['id'], $insert);
  69. }
  70. }
  71. }
  72. return $data;
  73. }
  74. }