58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace common\core;
|
||
|
||
use common\foundation\Cors;
|
||
use common\models\oldDb\Config;
|
||
use yii\filters\auth\HttpBearerAuth;
|
||
|
||
class BaseAdminController extends BaseController
|
||
{
|
||
protected $mallId;//商城ID
|
||
|
||
public function init()
|
||
{
|
||
parent::init();
|
||
// 多语言,需要在http header中设置 app-language:zh-CN
|
||
//Yii::$app->language = Yii::$app->request->getHeaders()->get('app-language'); //'en-US';
|
||
\Yii::$app->params['web'] = Config::lists();
|
||
}
|
||
|
||
final public function behaviors()
|
||
{
|
||
$behaviors = parent::behaviors();
|
||
$newBehaviors = [];
|
||
$newBehaviors['corsFilter'] = [
|
||
'class' => Cors::class,
|
||
];
|
||
foreach ($behaviors as $k=>$v){
|
||
$newBehaviors[$k]=$v;
|
||
}
|
||
//unset($behaviors['authenticator']); //删掉,保持先cors,后authenticator
|
||
// 设置认证方式,接口才认证
|
||
$newBehaviors['authenticator'] = [
|
||
'class' => HttpBearerAuth::class,
|
||
'optional' => $this->optional,
|
||
];
|
||
return $newBehaviors;
|
||
}
|
||
public function beforeAction($action)
|
||
{
|
||
$ret = parent::beforeAction($action); // TODO: Change the autogenerated stub
|
||
//不同角色权限
|
||
if(!\Yii::$app->user->isGuest){
|
||
$admin = \Yii::$app->user->identity;
|
||
$this->mallId = 0;
|
||
switch ($admin->role){
|
||
//角色1为官方管理
|
||
case 1:
|
||
//官方管理
|
||
// $this->mallId = FakeId::decodeId($this->get("mallId",0));
|
||
break;
|
||
}
|
||
\Yii::$app->mallId=$this->mallId;
|
||
}
|
||
return $ret;
|
||
}
|
||
}
|