info(); if ($auth['company']) { return $auth['company']; } return false; } # 设置公司权限 public function set($company_id) { $company_id = $company_id ? $company_id : Dever::input('company_id'); $auth = $this->getAuth(); if ($auth) { if (is_string($auth)) { $auth = explode(',', $auth); } if (in_array($company_id, $auth)) { return $this->_add('company', $company_id, 3600 * 24 * 365); } } return false; } # 获取公司权限 public function get() { $company_id = $this->_get('company'); /* if ($company_id) { $auth = $this->getAuth(); if ($auth) { $auth = explode(',', $auth); if (!in_array($company_id, $auth)) { $company_id = false; } } }*/ if (!$company_id) { $company = $this->getData(); if ($company) { $company_id = $company[0]['id']; $this->set($company_id); } else { $company_id = false; } } else { $auth = $this->getAuth(); if ($auth) { if (is_string($auth)) { $auth = explode(',', $auth); } if (!in_array($company_id, $auth)) { $company = $this->getData(); if ($company) { $company_id = $company[0]['id']; $this->set($company_id); } else { $company_id = false; } } } } return $company_id; } # 获取公司列表 public function getList() { $company_id = $this->get(); $data = $this->getData(); $result = array(); if ($data && count($data) > 1) { foreach ($data as $k => $v) { if ($company_id && $company_id != $v['id']) { $result[] = $v; } else { $this->company = $v; } } } return $result; } # 获取当前公司 public function getCur() { //print_r($this->company);die; if ($this->company) { return $this->company['name']; } return false; } private function getData() { $auth = $this->getAuth(); $where = array(); if ($auth) { $where['ids'] = $auth; return Dever::db('manage/company')->getOld($where); } else { return array(); } } public function update($id, $name, $data) { $group = Dever::db('manage/group')->one(array('company_id' => $id)); if (!$group) { $data['company_id'] = $id; $data['name'] = '默认部门'; Dever::db('manage/group')->insert($data); } } # 获取部门 public function getGroup() { $where = array(); $company_id = $this->get(); if ($company_id) { $where['company_id'] = $company_id; } else { $where['company_id'] = 1; } $group = Dever::db('manage/group')->select($where); return $group; } # 获取当前部门 public function getGroupInfo() { $auth = Dever::load('manage/auth')->info(); $where = array(); $company_id = $this->get(); if ($company_id) { $where['company_id'] = $company_id; } else { $where['company_id'] = 1; } $group = Dever::db('manage/group')->select($where); return $group; } # 获取部门下的员工 public function getAdmin($group, $id = false, $admin_id = false) { if ($admin_id) { return Dever::db('manage/admin')->getAll(array('ids' => $admin_id)); } $where['group_id'] = $group; if ($id) { $where['admin_id'] = $id; } $data = Dever::db('manage/admin_group')->getAll($where); if ($data) { $ids = array_keys($data); return Dever::db('manage/admin')->getAll(array('ids' => $ids)); } return array(); } public function search() { $where = array(); $cate = Dever::input('cate'); if ($cate) { $where['company_id'] = $cate; } return Dever::search('manage/group', $where); } # 同步admin_group public function sync() { $admin = Dever::db('manage/admin')->select(); if ($admin) { Dever::config('base')->hook = 1; foreach ($admin as $k => $v) { Dever::db('manage/admin_group')->delete(array('admin_id' => $v['id'])); if ($v['group']) { $group = explode(',', $v['group']); foreach ($group as $k1 => $v1) { Dever::db('manage/admin_group')->insert(array('admin_id' => $v['id'], 'group_id' => $v1)); } } } } return 'ok'; } public function getGroupName($group) { if (!$group) { return ''; } $html = array(); $where['ids'] = $group; $group = Dever::db('manage/group')->getData($where); foreach ($group as $k => $v) { $html[] = $v['name']; } $html = implode(',', $html); return $html; } }