123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- <?php
- namespace app\common\library;
- use app\company\model\Admin as User;
- use fast\Tree;
- use fast\Random;
- use think\Config;
- use think\Db;
- use think\Exception;
- use think\Hook;
- use think\Request;
- use think\Validate;
- class Authcompany extends \fast\Authpc
- {
- protected static $instance = null;
- protected $_error = '';
- protected $_logined = false;
- protected $_user = null;
- protected $_token = '';
- //Token默认有效时长
- protected $keeptime = 2592000;
- protected $requestUri = '';
- protected $rules = [];
- //默认配置
- // protected $config = [];
- protected $options = [];
- protected $allowFields = ['id','username','nickname','avatar','company_id','is_kefu' ];
- protected $breadcrumb = [];
- /*public function __construct($options = [])
- {
- if ($config = Config::get('company')) {
- $this->config = array_merge($this->config, $config);
- }
- $this->options = array_merge($this->config, $options);
- }*/
- public function __construct()
- {
- parent::__construct();
- }
- /**
- *
- * @param array $options 参数
- * @return Auth
- */
- public static function instance($options = [])
- {
- if (is_null(self::$instance)) {
- self::$instance = new static($options);
- }
- return self::$instance;
- }
- /**
- * 获取User模型
- * @return User
- */
- public function getUser()
- {
- return $this->_user;
- }
- /**
- * 兼容调用user模型的属性
- *
- * @param string $name
- * @return mixed
- */
- public function __get($name)
- {
- return $this->_user ? $this->_user->$name : null;
- }
- /**
- * 兼容调用user模型的属性
- */
- public function __isset($name)
- {
- return isset($this->_user) ? isset($this->_user->$name) : false;
- }
- /**
- * 根据Token初始化
- *
- * @param string $token Token
- * @return boolean
- */
- public function init($token)
- {
- if ($this->_logined) {
- return true;
- }
- if ($this->_error) {
- return false;
- }
- $data = Tokencompany::get($token);
- if (!$data) {
- return false;
- }
- $user_id = intval($data['user_id']);
- if ($user_id > 0) {
- $user = User::get($user_id);
- if (!$user) {
- $this->setError('Account not exist');
- return false;
- }
- if ($user['status'] != 1) {
- $this->setError('Account is locked');
- return false;
- }
- $this->_user = $user;
- $this->_logined = true;
- $this->_token = $token;
- //初始化成功的事件
- Hook::listen("company_init_successed", $this->_user);
- return true;
- } else {
- $this->setError('You are not logged in');
- return false;
- }
- }
- /**
- * 用户登录
- *
- * @param string $account 账号,用户名、邮箱、手机号
- * @param string $password 密码
- * @return boolean
- */
- public function login($account, $password)
- {
- $field = 'username';
- $user = User::get([$field => $account]);
- if (!$user) {
- $this->setError('Account is incorrect');
- return false;
- }
- if ($user->status != 1) {
- $this->setError('Account is locked');
- return false;
- }
- if (Config::get('pcadmin.login_failure_retry') && $user->loginfailure >= 10 && time() - $user->updatetime < 86400) {
- $this->setError('Please try again after 1 day');
- return false;
- }
- if ($user->password != $this->getEncryptPassword($password, $user->salt)) {
- $user->loginfailure++;
- $this->setError('Password is incorrect');
- return false;
- }
- //直接登录会员
- return $this->direct($user->id);
- }
- /**
- * 退出
- *
- * @return boolean
- */
- public function logout()
- {
- if (!$this->_logined) {
- $this->setError('You are not logged in');
- return false;
- }
- //设置登录标识
- $this->_logined = false;
- //删除Token
- Tokencompany::delete($this->_token);
- //退出成功的事件
- Hook::listen("user_logout_successed", $this->_user);
- return true;
- }
- /**
- * 修改密码
- * @param string $newpassword 新密码
- * @param string $oldpassword 旧密码
- * @param bool $ignoreoldpassword 忽略旧密码
- * @return boolean
- */
- public function changepwd($newpassword, $oldpassword = '', $ignoreoldpassword = false)
- {
- if (!$this->_logined) {
- $this->setError('You are not logged in');
- return false;
- }
- //判断旧密码是否正确
- if ($this->_user->password == $this->getEncryptPassword($oldpassword, $this->_user->salt) || $ignoreoldpassword) {
- Db::startTrans();
- try {
- $salt = Random::alnum();
- $newpassword = $this->getEncryptPassword($newpassword, $salt);
- $this->_user->save(['loginfailure' => 0, 'password' => $newpassword, 'salt' => $salt]);
- Tokencompany::delete($this->_token);
- //修改密码成功的事件
- Hook::listen("company_changepwd_successed", $this->_user);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->setError($e->getMessage());
- return false;
- }
- return true;
- } else {
- $this->setError('Password is incorrect');
- return false;
- }
- }
- /**
- * 直接登录账号
- * @param int $user_id
- * @return boolean
- */
- public function direct($user_id)
- {
- $user = User::get($user_id);
- if ($user) {
- Db::startTrans();
- try {
- $ip = request()->ip();
- $time = time();
- $user->loginfailure = 0;
- $user->logintime = $time;
- $user->loginip = $ip;
- $user->save();
- $this->_user = $user;
- $this->_token = Random::uuid();
- Tokencompany::set($this->_token, $user->id, $this->keeptime);
- $this->_logined = true;
- //登录成功的事件
- Hook::listen("company_login_successed", $this->_user);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->setError($e->getMessage());
- return false;
- }
- return true;
- } else {
- return false;
- }
- }
- /**
- * 检测是否是否有对应权限
- * @param string $path 控制器/方法
- * @param string $module 模块 默认为当前模块
- * @return boolean
- */
- /*public function check($path = null, $module = null)
- {
- if (!$this->_logined) {
- return false;
- }
- $ruleList = $this->getRuleList();
- $rules = [];
- foreach ($ruleList as $k => $v) {
- $rules[] = $v['name'];
- }
- $url = ($module ? $module : request()->module()) . '/' . (is_null($path) ? $this->getRequestUri() : $path);
- $url = strtolower(str_replace('.', '/', $url));
- return in_array($url, $rules) ? true : false;
- }*/
- public function check($name, $uid = '', $relation = 'or', $mode = 'url')
- {
- $uid = $uid ? $uid : $this->id;
- return parent::check($name, $uid, $relation, $mode);
- }
- /**
- * 检测当前控制器和方法是否匹配传递的数组
- *
- * @param array $arr 需要验证权限的数组
- * @return bool
- */
- public function match($arr = [])
- {
- $request = Request::instance();
- $arr = is_array($arr) ? $arr : explode(',', $arr);
- if (!$arr) {
- return false;
- }
- $arr = array_map('strtolower', $arr);
- // 是否存在
- if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) {
- return true;
- }
- // 没找到匹配
- return false;
- }
- /**
- * 判断是否登录
- * @return boolean
- */
- public function isLogin()
- {
- if ($this->_logined) {
- return true;
- }
- return false;
- }
- /**
- * 获取当前Token
- * @return string
- */
- public function getToken()
- {
- return $this->_token;
- }
- /**
- * 获取会员基本信息
- */
- public function getUserInfo_simple()
- {
- $data = $this->_user->toArray();
- $allowFields = $this->getAllowFields();
- $userinfo = array_intersect_key($data, array_flip($allowFields));
- $userinfo = array_merge($userinfo, Tokencompany::get($this->_token));
- //追加
- $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
- return $userinfo;
- }
- /**
- * 获取会员基本信息
- */
- public function getUserInfo()
- {
- $data = $this->_user->toArray();
- $allowFields = $this->getAllowFields();
- $userinfo = array_intersect_key($data, array_flip($allowFields));
- $userinfo = array_merge($userinfo, Tokencompany::get($this->_token));
- //追加
- $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
- //追加公司信息
- $userinfo['company'] = Db::name('company')->field('id,companyname')->where('id',$userinfo['company_id'])->find();
- return $userinfo;
- }
- /**
- * 获取当前请求的URI
- * @return string
- */
- public function getRequestUri()
- {
- return $this->requestUri;
- }
- /**
- * 设置当前请求的URI
- * @param string $uri
- */
- public function setRequestUri($uri)
- {
- $this->requestUri = $uri;
- }
- public function getGroups($uid = null)
- {
- $uid = is_null($uid) ? $this->id : $uid;
- return parent::getGroups($uid);
- }
- public function getRuleList($uid = null)
- {
- $uid = is_null($uid) ? $this->id : $uid;
- return parent::getRuleList($uid);
- }
- public function getRuleIds($uid = null)
- {
- $uid = is_null($uid) ? $this->id : $uid;
- return parent::getRuleIds($uid);
- }
- //绝对不允许*管理员
- public function isSuperAdmin()
- {
- // return false;
- return in_array('*', $this->getRuleIds()) ? true : false;
- }
- /**
- * 获取管理员所属于的分组ID
- * @param int $uid
- * @return array
- */
- public function getGroupIds($uid = null)
- {
- $groups = $this->getGroups($uid);
- $groupIds = [];
- foreach ($groups as $K => $v) {
- $groupIds[] = (int)$v['group_id'];
- }
- return $groupIds;
- }
- /**
- * 取出当前管理员所拥有权限的分组
- * @param boolean $withself 是否包含当前所在的分组
- * @return array
- */
- public function getChildrenGroupIds($withself = false)
- {
- //取出当前管理员所有的分组
- $groups = $this->getGroups();
- $groupIds = [];
- foreach ($groups as $k => $v) {
- $groupIds[] = $v['id'];
- }
- $originGroupIds = $groupIds;
- foreach ($groups as $k => $v) {
- if (in_array($v['pid'], $originGroupIds)) {
- $groupIds = array_diff($groupIds, [$v['id']]);
- unset($groups[$k]);
- }
- }
- // 取出所有分组
- $groupList = \app\company\model\AuthGroup::where($this->isSuperAdmin() ? '1=1' : ['status' => 'normal'])->where('company_id',$this->company_id)->select();
- $objList = [];
- foreach ($groups as $k => $v) {
- if ($v['rules'] === '*') {
- $objList = $groupList;
- break;
- }
- // 取出包含自己的所有子节点
- $childrenList = Tree::instance()->init($groupList, 'pid')->getChildren($v['id'], true);
- $obj = Tree::instance()->init($childrenList, 'pid')->getTreeArray($v['pid']);
- $objList = array_merge($objList, Tree::instance()->getTreeList($obj));
- }
- $childrenGroupIds = [];
- foreach ($objList as $k => $v) {
- $childrenGroupIds[] = $v['id'];
- }
- if (!$withself) {
- $childrenGroupIds = array_diff($childrenGroupIds, $groupIds);
- }
- return $childrenGroupIds;
- }
- /**
- * 取出当前管理员所拥有权限的管理员
- * @param boolean $withself 是否包含自身
- * @return array
- */
- public function getChildrenAdminIds($withself = false)
- {
- $childrenAdminIds = [];
- if (!$this->isSuperAdmin()) {
- $groupIds = $this->getChildrenGroupIds(false);
- $authGroupList = \app\company\model\AuthGroupAccess::field('uid,group_id')
- ->where('group_id', 'in', $groupIds)
- ->select();
- foreach ($authGroupList as $k => $v) {
- $childrenAdminIds[] = $v['uid'];
- }
- } else {
- //超级管理员拥有所有人的权限
- // $childrenAdminIds = User::column('id');
- $childrenAdminIds = User::where('company_id',$this->company_id)->column('id');
- }
- if ($withself) {
- if (!in_array($this->id, $childrenAdminIds)) {
- $childrenAdminIds[] = $this->id;
- }
- } else {
- $childrenAdminIds = array_diff($childrenAdminIds, [$this->id]);
- }
- return $childrenAdminIds;
- }
- /**
- * 获得面包屑导航
- * @param string $path
- * @return array
- */
- public function getBreadCrumb($path = '')
- {
- if ($this->breadcrumb || !$path) {
- return $this->breadcrumb;
- }
- $titleArr = [];
- $menuArr = [];
- $urlArr = explode('/', $path);
- foreach ($urlArr as $index => $item) {
- $pathArr[implode('/', array_slice($urlArr, 0, $index + 1))] = $index;
- }
- if (!$this->rules && $this->id) {
- $this->getRuleList();
- }
- foreach ($this->rules as $rule) {
- if (isset($pathArr[$rule['name']])) {
- $rule['title'] = __($rule['title']);
- $rule['url'] = url($rule['name']);
- $titleArr[$pathArr[$rule['name']]] = $rule['title'];
- $menuArr[$pathArr[$rule['name']]] = $rule;
- }
- }
- ksort($menuArr);
- $this->breadcrumb = $menuArr;
- return $this->breadcrumb;
- }
- /**
- * 获取左侧菜单栏
- *
- * @param array $params URL对应的badge数据
- * @param string $fixedPage 默认页
- * @return array
- */
- public function get_menus(){
- // 读取管理员当前拥有的权限节点
- $userRule = $this->getRuleList();
- // 必须将结果集转换为数组
- $ruleList = collection(\app\admin\model\PcAuthRule::where('status', 'normal')
- ->field('id,pid as parentId,name as namerule,title as name,path,component,component_name as componentName,icon,visible,alwaysShow,keepAlive')
- ->where('type', 'NEQ',3)
- ->order('weigh', 'desc')
- ->select())->toArray();
- foreach ($ruleList as $k => &$v) {
- $v['visible'] = $v['visible'] == 1 ? true : false;
- $v['alwaysShow'] = $v['alwaysShow'] == 1 ? true : false;
- $v['keepAlive'] = $v['keepAlive'] == 1 ? true : false;
- if (!in_array($v['namerule'], $userRule)) {
- unset($ruleList[$k]);
- continue;
- }
- //如果你不是客服,但是又有客服菜单权限,直接强行删掉
- if($this->is_kefu == 0 && in_array($v['namerule'],['company/kefu','company/kefu/list']) ){
- unset($ruleList[$k]);
- continue;
- }
- }
- // dump($ruleList);
- Tree::instance()->init($ruleList,'parentId');
- $menu = Tree::instance()->getTreeArray_2(0);
- // dump($menu);
- return $menu;
- }
- public function get_menus_simple(){
- // 读取管理员当前拥有的权限节点
- $userRule = $this->getRuleList();
- // 必须将结果集转换为数组
- $ruleList = collection(\app\admin\model\PcAuthRule::where('status', 'normal')
- ->field('id,pid as parentId,name as namerule,title as name,path,component,component_name as componentName,icon,visible,alwaysShow,keepAlive')
- ->where('type',1)->where('pid',0)
- ->order('weigh', 'desc')
- ->select())->toArray();
- foreach ($ruleList as $k => &$v) {
- $v['visible'] = $v['visible'] == 1 ? true : false;
- $v['alwaysShow'] = $v['alwaysShow'] == 1 ? true : false;
- $v['keepAlive'] = $v['keepAlive'] == 1 ? true : false;
- if (!in_array($v['namerule'], $userRule)) {
- unset($ruleList[$k]);
- continue;
- }
- //如果你不是客服,但是又有客服菜单权限,直接强行删掉
- if($this->is_kefu == 0 && in_array($v['namerule'],['company/kefu','company/kefu/list']) ){
- unset($ruleList[$k]);
- continue;
- }
- }
- // return $ruleList;
- // dump($ruleList);
- Tree::instance()->init($ruleList,'parentId');
- $menu = Tree::instance()->getTreeArray_2(0);
- // dump($menu);
- return $menu;
- }
- public function get_permissions(){
- // 读取管理员当前拥有的权限节点
- $userRule = $this->getRuleList();
- // 必须将结果集转换为数组
- $ruleList = collection(\app\admin\model\PcAuthRule::where('status', 'normal')
- ->where('type', 3)
- ->order('weigh', 'desc')
- ->select())->toArray();
- foreach ($ruleList as $k => &$v) {
- if (!in_array($v['name'], $userRule)) {
- unset($ruleList[$k]);
- continue;
- }
- }
- // dump($ruleList);
- return array_column($ruleList,'permission');
- }
- /*
- public function getSidebar($params = [], $fixedPage = 'dashboard')
- {
- // 边栏开始
- Hook::listen("admin_sidebar_begin", $params);
- $colorArr = ['red', 'green', 'yellow', 'blue', 'teal', 'orange', 'purple'];
- $colorNums = count($colorArr);
- $badgeList = [];
- $module = request()->module();
- // 生成菜单的badge
- foreach ($params as $k => $v) {
- $url = $k;
- if (is_array($v)) {
- $nums = $v[0] ?? 0;
- $color = $v[1] ?? $colorArr[(is_numeric($nums) ? $nums : strlen($nums)) % $colorNums];
- $class = $v[2] ?? 'label';
- } else {
- $nums = $v;
- $color = $colorArr[(is_numeric($nums) ? $nums : strlen($nums)) % $colorNums];
- $class = 'label';
- }
- //必须nums大于0才显示
- if ($nums) {
- $badgeList[$url] = '<small class="' . $class . ' pull-right bg-' . $color . '">' . $nums . '</small>';
- }
- }
- // 读取管理员当前拥有的权限节点
- $userRule = $this->getRuleList();
- $selected = $referer = [];
- $refererUrl = Session::get('referer');
- // 必须将结果集转换为数组
- $ruleList = collection(\app\admin\model\PcAuthRule::where('status', 'normal')
- ->where('ismenu', 1)
- ->order('weigh', 'desc')
- ->cache("__menu__")
- ->select())->toArray();
- $indexRuleList = \app\admin\model\PcAuthRule::where('status', 'normal')
- ->where('ismenu', 0)
- ->where('name', 'like', '%/index')
- ->column('name,pid');
- $pidArr = array_unique(array_filter(array_column($ruleList, 'pid')));
- foreach ($ruleList as $k => &$v) {
- if (!in_array($v['name'], $userRule)) {
- unset($ruleList[$k]);
- continue;
- }
- $indexRuleName = $v['name'] . '/index';
- if (isset($indexRuleList[$indexRuleName]) && !in_array($indexRuleName, $userRule)) {
- unset($ruleList[$k]);
- continue;
- }
- $v['icon'] = $v['icon'] . ' fa-fw';
- $v['url'] = isset($v['url']) && $v['url'] ? $v['url'] : '/' . $module . '/' . $v['name'];
- $v['badge'] = $badgeList[$v['name']] ?? '';
- $v['title'] = __($v['title']);
- $v['url'] = preg_match("/^((?:[a-z]+:)?\/\/|data:image\/)(.*)/i", $v['url']) ? $v['url'] : url($v['url']);
- $v['menuclass'] = in_array($v['menutype'], ['dialog', 'ajax']) ? 'btn-' . $v['menutype'] : '';
- $v['menutabs'] = !$v['menutype'] || in_array($v['menutype'], ['default', 'addtabs']) ? 'addtabs="' . $v['id'] . '"' : '';
- $selected = $v['name'] == $fixedPage ? $v : $selected;
- $referer = $v['url'] == $refererUrl ? $v : $referer;
- }
- $lastArr = array_unique(array_filter(array_column($ruleList, 'pid')));
- $pidDiffArr = array_diff($pidArr, $lastArr);
- foreach ($ruleList as $index => $item) {
- if (in_array($item['id'], $pidDiffArr)) {
- unset($ruleList[$index]);
- }
- }
- if ($selected == $referer) {
- $referer = [];
- }
- $select_id = $referer ? $referer['id'] : ($selected ? $selected['id'] : 0);
- $menu = $nav = '';
- $showSubmenu = config('fastadmin.show_submenu');
- if (Config::get('fastadmin.multiplenav')) {
- $topList = [];
- foreach ($ruleList as $index => $item) {
- if (!$item['pid']) {
- $topList[] = $item;
- }
- }
- $selectParentIds = [];
- $tree = Tree::instance();
- $tree->init($ruleList);
- if ($select_id) {
- $selectParentIds = $tree->getParentsIds($select_id, true);
- }
- foreach ($topList as $index => $item) {
- $childList = Tree::instance()->getTreeMenu(
- $item['id'],
- '<li class="@class" pid="@pid"><a @extend href="@url@addtabs" addtabs="@id" class="@menuclass" url="@url" py="@py" pinyin="@pinyin"><i class="@icon"></i> <span>@title</span> <span class="pull-right-container">@caret @badge</span></a> @childlist</li>',
- $select_id,
- '',
- 'ul',
- 'class="treeview-menu' . ($showSubmenu ? ' menu-open' : '') . '"'
- );
- $current = in_array($item['id'], $selectParentIds);
- $url = $childList ? 'javascript:;' : $item['url'];
- $addtabs = $childList || !$url ? "" : (stripos($url, "?") !== false ? "&" : "?") . "ref=" . ($item['menutype'] ? $item['menutype'] : 'addtabs');
- $childList = str_replace(
- '" pid="' . $item['id'] . '"',
- ' ' . ($current ? '' : 'hidden') . '" pid="' . $item['id'] . '"',
- $childList
- );
- $nav .= '<li class="' . ($current ? 'active' : '') . '"><a ' . $item['extend'] . ' href="' . $url . $addtabs . '" ' . $item['menutabs'] . ' class="' . $item['menuclass'] . '" url="' . $url . '" title="' . $item['title'] . '"><i class="' . $item['icon'] . '"></i> <span>' . $item['title'] . '</span> <span class="pull-right-container"> </span></a> </li>';
- $menu .= $childList;
- }
- } else {
- // 构造菜单数据
- Tree::instance()->init($ruleList);
- $menu = Tree::instance()->getTreeMenu(
- 0,
- '<li class="@class"><a @extend href="@url@addtabs" @menutabs class="@menuclass" url="@url" py="@py" pinyin="@pinyin"><i class="@icon"></i> <span>@title</span> <span class="pull-right-container">@caret @badge</span></a> @childlist</li>',
- $select_id,
- '',
- 'ul',
- 'class="treeview-menu' . ($showSubmenu ? ' menu-open' : '') . '"'
- );
- if ($selected) {
- $nav .= '<li role="presentation" id="tab_' . $selected['id'] . '" class="' . ($referer ? '' : 'active') . '"><a href="#con_' . $selected['id'] . '" node-id="' . $selected['id'] . '" aria-controls="' . $selected['id'] . '" role="tab" data-toggle="tab"><i class="' . $selected['icon'] . ' fa-fw"></i> <span>' . $selected['title'] . '</span> </a></li>';
- }
- if ($referer) {
- $nav .= '<li role="presentation" id="tab_' . $referer['id'] . '" class="active"><a href="#con_' . $referer['id'] . '" node-id="' . $referer['id'] . '" aria-controls="' . $referer['id'] . '" role="tab" data-toggle="tab"><i class="' . $referer['icon'] . ' fa-fw"></i> <span>' . $referer['title'] . '</span> </a> <i class="close-tab fa fa-remove"></i></li>';
- }
- }
- return [$menu, $nav, $selected, $referer];
- }
- */
- /**
- * 获取允许输出的字段
- * @return array
- */
- public function getAllowFields()
- {
- return $this->allowFields;
- }
- /**
- * 设置允许输出的字段
- * @param array $fields
- */
- public function setAllowFields($fields)
- {
- $this->allowFields = $fields;
- }
- /**
- * 删除一个指定会员
- * @param int $user_id 会员ID
- * @return boolean
- */
- public function delete($user_id)
- {
- $user = User::get($user_id);
- if (!$user) {
- return false;
- }
- Db::startTrans();
- try {
- // 删除会员
- User::destroy($user_id);
- // 删除会员指定的所有Token
- Tokencompany::clear($user_id);
- Hook::listen("company_delete_successed", $user);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->setError($e->getMessage());
- return false;
- }
- return true;
- }
- /**
- * 获取密码加密后的字符串
- * @param string $password 密码
- * @param string $salt 密码盐
- * @return string
- */
- public function getEncryptPassword($password, $salt = '')
- {
- return md5(md5($password) . $salt);
- }
- /**
- * 设置会话有效时间
- * @param int $keeptime 默认为永久
- */
- public function keeptime($keeptime = 0)
- {
- $this->keeptime = $keeptime;
- }
- /**
- * 设置错误信息
- *
- * @param string $error 错误信息
- * @return Auth
- */
- public function setError($error)
- {
- $this->_error = $error;
- return $this;
- }
- /**
- * 获取错误信息
- * @return string
- */
- public function getError()
- {
- return $this->_error ? __($this->_error) : '';
- }
- }
|