Group.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php namespace Manage\Lib;
  2. use Dever;
  3. use Dever\Helper\Str;
  4. class Group extends Auth
  5. {
  6. public function getTree()
  7. {
  8. $data = Dever::db('group', 'manage')->select([]);
  9. $result = array();
  10. $result[] = array
  11. (
  12. 'id' => 'root',
  13. 'name' => '全部集团',
  14. 'children' => $data,
  15. );
  16. return $result;
  17. }
  18. public function update($data)
  19. {
  20. if ($data['mobile']) {
  21. $system = Dever::db('system', 'manage')->find(2);
  22. $data['system_id'] = $system['id'];
  23. $data['info_id'] = $data['id'];
  24. $data['partition'] = $system['partition'];
  25. $db = Dever::db($system['user_table'], '', 'default', Dever::load('common', 'manage')->system($data));
  26. $info = $db->find(1);
  27. if (!$info) {
  28. $password = '123456';
  29. $insert['name'] = Str::hide($data['mobile']);
  30. $insert['mobile'] = $data['mobile'];
  31. $insert['role'] = 1;
  32. $insert += Dever::load('common')->createPwd($password);
  33. $db->insert($insert);
  34. }
  35. }
  36. }
  37. # 创建账户
  38. public function createUser($module, $data_id, $name, $mobile, $password)
  39. {
  40. if ($mobile && $password) {
  41. $system = Dever::db('system', 'manage')->find(2);
  42. $data['system_id'] = $system['id'];
  43. $data['info_id'] = 1;
  44. $data['partition'] = $system['partition'];
  45. $db = Dever::db($system['user_table'], '', 'default', Dever::load('common', 'manage')->system($data));
  46. $info = $db->find(array('mobile' => $mobile));
  47. $module = Dever::db('system_module', 'manage')->find(array('key' => $module, 'system' => 'group'));
  48. $insert['name'] = $name;
  49. $insert['mobile'] = $mobile;
  50. $insert['role'] = 2;
  51. $insert['module_data'] = $module['id'] . '-' . $data_id;
  52. if (!$info) {
  53. $insert += Dever::load('common')->createPwd($password);
  54. $db->insert($insert);
  55. } else {
  56. $insert += Dever::load('common')->createPwd($password);
  57. $module_data = $insert['module_data'];
  58. unset($insert['module_data']);
  59. if (!strstr($info['module_data'], $module_data)) {
  60. $insert['module_data'] = $module_data . ',' . $info['module_data'];
  61. }
  62. $db->update($info['id'], $insert);
  63. }
  64. }
  65. }
  66. }