| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace addons\Happiness\agent\controllers;
- use addons\Happiness\common\enums\HappinessEnum;
- use addons\Happiness\common\models\HappinessAgent;
- use common\enums\StatusEnum;
- use common\models\mall\Mall;
- use common\traits\BaseControllerTrait;
- 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 $admin = null;
- public $agent_ids = [];
- public $user_id=[];
- public $city_ids= [];
- public $district_ids=[];
- public $province_ids= [];
- 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/Happiness/' . $this->module->id . '/views/layouts/agent';
- }
- $redirect_url = '/happiness/agent/auth/login';
- $this->admin = Yii::$app->happiness_agent_user->identity;
- $agentList = HappinessAgent::find()->where(['user_id' => $this->admin->user_id, 'status' => StatusEnum::ENABLED])->asArray()->all();
- if (empty($agentList)) return $this->redirect([$redirect_url]);
- if (empty($this->admin)) return $this->redirect([$redirect_url]);
- $mall = Mall::findOne(['id' => $agentList[0]['mall_id']]);
- $this->mall = $mall;
- $this->mall_id = $mall['id'];
- $this->agent_ids = array_column($agentList, 'id');
- foreach ($agentList as $agent)
- {
- if($agent['role']==HappinessEnum::AGENT_CITY)
- {
- $this->city_ids[] = $agent['city_id'];
- }
- if($agent['role']==HappinessEnum::AGENT_DISTRICT)
- {
- $this->district_ids[] = $agent['district_id'];
- }
- if($agent['role']==HappinessEnum::AGENT_PROVINCE)
- {
- $this->province_ids[] = $agent['province_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;
- }
- }
|