| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace addons\Mch\client\controllers;
- use addons\Mch\common\models\Mch;
- use common\models\mall\Mall;
- use common\traits\BaseControllerTrait;
- use common\traits\ErrorTrait;
- use Yii;
- use yii\web\Controller;
- use common\traits\BaseAction;
- use common\enums\AppEnum;
- use common\behaviors\ActionLogBehavior;
- class BaseController extends Controller
- {
- use BaseControllerTrait;
- use BaseAction;
- public $mall = null;
- public $mall_id = 0;
- public $store_id = 0;
- public $mch_id = 0;
- public $admin = null;
- public $enableCsrfValidation = false;
- /**
- * 视图自动加载文件路径
- *
- * @var string
- */
- public $layout = null;
- /**
- * 是否钩子
- *
- * @var bool
- */
- public $isHook = false;
- /**
- * @throws \yii\base\InvalidConfigException
- */
- public function init()
- {
- parent::init();
- // 后台视图默认载入模块视图
- if (!$this->layout && in_array(Yii::$app->id, [AppEnum::BACKEND, AppEnum::MERCHANT])) {
- $this->layout = '@addons/Mch/' . $this->module->id . '/views/layouts/client';
- }
- $redirect_url = '/mch/client/auth/login';
- $this->admin = Yii::$app->mch_user->identity;
- if(empty($this->admin)) return $this->redirect([$redirect_url]);
- $mch_id = $this->admin['mch_id'];
- $mch = Mch::findOne(['id'=>$mch_id]);
- if(empty($mch)){
- return $this->redirect([$redirect_url]);
- }
- $mall = Mall::findOne(['id'=>$mch['mall_id']]);
- $this->mall = $mall;
- $this->mall_id = $mall['id'];
- $this->mch_id = Yii::$app->mch_user->identity->mch_id;
- }
- /**
- * @return array
- */
- public function behaviors()
- {
- return [
- 'actionLog' => [
- 'class' => ActionLogBehavior::class
- ]
- ];
- }
- /**
- * @param $action
- * @return bool
- * @throws UnauthorizedHttpException
- * @throws \yii\web\BadRequestHttpException
- */
- public function beforeAction($action)
- {
- if (!parent::beforeAction($action)) {
- return false;
- }
- // 每页数量
- $this->pageSize = Yii::$app->request->get('per-page', 10);
- $this->pageSize > 50 && $this->pageSize = 50;
- return true;
- }
- }
|