| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace backend\controllers;
- use common\behaviors\ExpiredBehavior;
- use common\behaviors\LimitBehavior;
- use common\models\backend\Admin;
- use Exception;
- use Yii;
- use yii\web\ForbiddenHttpException;
- class MallController extends BaseController
- {
- /**
- * @return array
- */
- public function behaviors()
- {
- return [
- 'counter' => [
- 'class' => LimitBehavior::class,
- 'userId' => $this->admin['id'] ?? 0,
- ],
- [
- 'class' => ExpiredBehavior::class,
- 'mall_id' => $this->mall_id
- ],
- ];
- }
- public $layout = '@backend/views/layouts/mall';
- public $mall = null;
- public $mall_id = 0;
- public $admin = null;
- public function init()
- {
- parent::init();
- $this->admin = Yii::$app->user->identity;
- if (empty($this->admin)) {
- if ($this->request->isAjax) {
- return $this->error('对不起,您现在还没获此操作的权限');
- } else {
- throw new ForbiddenHttpException('对不起,您现在还没获此操作的权限');
- }
- }
- $mall = Yii::$app->session->get('mall');
- if(empty($mall)){
- // 商城session过期
- switch($this->admin->admin_type){
- case Admin::ADMIN_TYPE_SUPER:
- case Admin::ADMIN_TYPE_AGENT:
- return $this->redirect(['/admin/mall/index']);
- break;
- default:
- try{
- Yii::$app->user->logout();
- }catch(Exception $e){
- }
- return $this->redirect(['/admin/auth/login','login_type'=>base64_encode('mall')]);
- }
- }
- $this->mall = $mall;
- $this->mall_id = $mall['id'];
-
- }
- }
|