| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | <?phpnamespace Manage\Src;use Dever;use Manage\Src\Lib\Save;class Company extends Save{    private $company = array();    # 获取当前权限    public function getAuth()    {        $auth = Dever::load('manage/auth')->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) {            $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['id'];                $this->set($company_id);            }        }        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();        }    }}
 |