You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
4.9 KiB
142 lines
4.9 KiB
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\institution\controller;
|
|
|
|
use app\institution\model\institution\Institution;
|
|
use app\institution\model\institution\InstitutionAdmin;
|
|
use app\institution\model\institution\InstitutionMenus;
|
|
use basic\AuthBasic;
|
|
use service\HookService;
|
|
use think\Url;
|
|
use app\admin\model\special\Lecturer;
|
|
|
|
/**
|
|
* 基类 所有控制器继承的类
|
|
* Class AuthController
|
|
* @package app\institution\controller
|
|
*/
|
|
class AuthController extends AuthBasic
|
|
{
|
|
/**
|
|
* 当前登陆管理员信息
|
|
* @var
|
|
*/
|
|
protected $adminInfo;
|
|
|
|
/**
|
|
* 当前登陆管理员ID
|
|
* @var
|
|
*/
|
|
protected $adminId;
|
|
|
|
/**
|
|
* 是否需要审核
|
|
* @var
|
|
*/
|
|
protected $isAudit;
|
|
|
|
/**
|
|
* 讲师id
|
|
* @var
|
|
*/
|
|
protected $merchantId;
|
|
|
|
/**
|
|
* 1讲师 2机构
|
|
* @var
|
|
*/
|
|
protected $entry_type;
|
|
protected $agent;
|
|
protected $o_agent;
|
|
/**
|
|
* 讲师id
|
|
* @var
|
|
*/
|
|
protected $lecturerId;
|
|
|
|
/**
|
|
* 商户信息
|
|
* @var
|
|
*/
|
|
protected $merchantInfo;
|
|
|
|
/**
|
|
* 当前管理员权限
|
|
* @var array
|
|
*/
|
|
protected $auth = [];
|
|
|
|
protected $skipLogController = ['index', 'common'];
|
|
|
|
protected function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
if (!InstitutionAdmin::hasActiveAdmin()) return $this->redirect('Login/index');
|
|
try {
|
|
$adminInfo = InstitutionAdmin::activeAdminInfoOrFail();
|
|
$merchantInfo = InstitutionAdmin::activeMerchantInfoOrFail();
|
|
} catch (\Exception $e) {
|
|
return $this->failed(InstitutionAdmin::getErrorInfo($e->getMessage()), Url::build('Login/index'));
|
|
}
|
|
$this->adminInfo = $adminInfo;
|
|
$this->adminId = $adminInfo['id'];
|
|
$this->merchantInfo = $merchantInfo;
|
|
$this->merchantId = $merchantInfo['id'];
|
|
$this->entry_type = $adminInfo['entry_type'];
|
|
|
|
|
|
|
|
$this->lecturerId = $merchantInfo['lecturer_id'];
|
|
$this->isAudit = Institution::where('id', $merchantInfo['id'])->value('is_audit');
|
|
$this->getActiveAdminInfo();
|
|
$this->auth = InstitutionMenus::rulesByAuth($this->adminInfo['rules']);
|
|
$this->checkAuthInstitution();
|
|
$agent = Lecturer::where(array('agent'=>$merchantInfo['id'],'is_del' => 0))->select()->toArray();
|
|
$agent_exp = implode(',',array_column($agent,'mer_id'));
|
|
$this->agent = $agent_exp ? $agent_exp : $merchantInfo['id'];
|
|
$this->o_agent = $agent_exp ? $agent_exp : -1;
|
|
$this->assign('_admin', $this->adminInfo);
|
|
if ($merchantInfo['is_del'] == 1 || $merchantInfo['status'] == 0) {
|
|
$this->failed('讲师删除或者已被禁止登陆', Url::build('Login/index'));
|
|
}
|
|
}
|
|
protected function checkAuthInstitution($action = null, $controller = null, $module = null, array $route = [])
|
|
{
|
|
|
|
static $allAuth = null;
|
|
if ($allAuth === null) $allAuth = InstitutionMenus::getAllAuth();
|
|
if ($module === null) $module = $this->request->module();
|
|
if ($controller === null) $controller = $this->request->controller();
|
|
if ($action === null) $action = $this->request->action();
|
|
if (!count($route)) $route = $this->request->route();
|
|
if (in_array(strtolower($controller), $this->skipLogController, true)) return true;
|
|
$nowAuthName = InstitutionMenus::getAuthName($action, $controller, $module, $route);
|
|
$baseNowAuthName = InstitutionMenus::getAuthName($action, $controller, $module, []);
|
|
if ((in_array($nowAuthName, $allAuth) && !in_array($nowAuthName, $this->auth)) || (in_array($baseNowAuthName, $allAuth) && !in_array($baseNowAuthName, $this->auth)))
|
|
exit($this->authFail('没有权限访问!'));
|
|
return true;
|
|
}
|
|
/**
|
|
* 获得当前用户最新信息
|
|
* @return InstitutionAdmin
|
|
*/
|
|
protected function getActiveAdminInfo()
|
|
{
|
|
$adminId = $this->adminId;
|
|
$adminInfo = InstitutionAdmin::getValidAdminInfoOrFail($adminId);
|
|
if (!$adminInfo) $this->failed(InstitutionAdmin::getErrorInfo('请登陆!'));
|
|
$this->adminInfo = $adminInfo;
|
|
InstitutionAdmin::setLoginInfo($adminInfo->toArray());
|
|
return $adminInfo;
|
|
}
|
|
}
|
|
|