123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php namespace Manage\Lib;
- use Dever;
- use Dever\Project;
- use Dever\Helper\Str;
- class System extends Auth
- {
- public function getTree()
- {
- $data = Dever::db('system', 'manage')->select([]);
- $result = array();
- $result[] = array
- (
- 'id' => 'root',
- 'name' => '全部系统',
- 'children' => $data,
- );
- return $result;
- }
- # 创建管理员
- public function update($system, $db, $data)
- {
- if (isset($data['mobile']) && $data['mobile']) {
- $system = Dever::db('system', 'manage')->find(array('key' => $system));
- $data['system_id'] = $system['id'];
- $data['info_id'] = $data['id'];
- $data['partition'] = $system['partition'];
- $db = Dever::db($system['user_table'], '', true, 'default', Dever::load('common', 'manage')->system($data));
- $info = $db->find(array('mobile' => $data['mobile']));
- if (!$info) {
- $password = '123456';
- $insert['name'] = Str::hide($data['mobile']);
- $insert['mobile'] = $data['mobile'];
- $insert['role'] = 1;
- $insert += Dever::load('common', 'manage')->createPwd($password);
- $db->insert($insert);
- }
- }
- }
- # 创建账户
- public function createUser($data, $state = true)
- {
- if (isset($data['mobile']) && $data['mobile'] && isset($data['password']) && $data['password']) {
- $info = Dever::db($data['table'])->find($data['id']);
- if ($info) {
- $system = Dever::db('system', 'manage')->find(array('key' => $data['system']));
- $set['system_id'] = $system['id'];
- $set['info_id'] = 1;
- $set['partition'] = $system['partition'];
- $db = Dever::db($system['user_table'], '', 'default', Dever::load('common', 'manage')->system($set));
- $user = $db->find(array('mobile' => $data['mobile']));
- if ($state && $user) {
- Dever::error('手机号' . $data['mobile'] . '已存在,请更换手机号');
- }
- $module = Dever::db('system_module', 'manage')->find(array('key' => $data['module'], 'system' => 'group'));
- $insert['name'] = $info['name'];
- $insert['mobile'] = $data['mobile'];
- $insert['role'] = 2;
- $insert['module_data'] = $module['id'] . '-' . $info['id'];
- $insert += Dever::load('common', 'manage')->createPwd($data['password']);
- if (!$user) {
- $db->insert($insert);
- } else {
- $module_data = $insert['module_data'];
- unset($insert['module_data']);
- if (!strstr($user['module_data'], $module_data)) {
- $insert['module_data'] = $module_data . ',' . $user['module_data'];
- }
- $db->update($user['id'], $insert);
- }
- }
- }
- return $data;
- }
- }
|