Files
xk-api-yii/common/core/BaseAdminController.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2024-09-19 11:32:39 +08:00
<?php
namespace common\core;
use common\foundation\Cors;
2024-12-19 19:20:27 +08:00
use common\models\oldDb\Config;
2024-09-19 11:32:39 +08:00
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;
}
}