<?php

namespace frontend\base;

use common\models\CategoryCity;
use Yii;
use frontend\base\CommonController;
use common\models\Config;


/**
 * Default controller for the `v1` module
 */
class BaseController extends CommonController
{
    /**
     * @param $action
     * @return bool|void
     * @throws \yii\web\BadRequestHttpException
     */
    public function beforeAction($action)
    {
        parent::beforeAction($action);

        if (empty($action->controller->module->id) && !in_array($action->controller->module->id, \common\models\CategoryCity::find()->select(['module'])->andWhere(['state' => 1])->andWhere(['del' => 1])->andWhere(['pid' => 0])->column())) {
            // 默认模块
            $top = CategoryCity::find()->andWhere(['del' => 1, 'top' => 1])->asArray()->one()['module'];
            if (!empty($top)) {
                return $this->redirect('/' . $top)->send();
            }
            return $this->redirect('/')->send();
        }

        Yii::$app->hostserver->module['module'] = $action->controller->module->id;
	    Yii::$app->hostserver->module['lv_one'] = CategoryCity::find()->andWhere([
        	'del' => 1,
	        'state'=> 1,
	        'pid' => 0
        ])->select(['id'])->column();
	    Yii::$app->hostserver->module['lv_two'] = CategoryCity::find()->andWhere([
        	'del' => 1,
	        'state'=> 1,
	        'pid' => Yii::$app->hostserver->module['lv_one']
        ])->select(['id'])->all();
	    Yii::$app->hostserver->module['web_config'] = Config::find()->asArray()->one();
//	    p(Yii::$app->hostserver->module);die;
	
	    //海南站页面页首搜索框推送楼盘
	    if($action->controller->id != 'default'){
		    $data = (new \common\models\House())->HotList(6);
            Yii::$app->view->params['hothousev2'] = $data;
        }

        return true;
    }

}