<?php
/**
 * Created by PhpStorm.
 * User: xiaofeng
 * Date: 2018/4/26
 * Time: 上午11:13
 */

namespace frontend\controllers;

use frontend\base\CommonController;
use Yii;
use mobile\base\Help;

class PublicController extends CommonController
{
    public $enableCsrfValidation = false;

    public function actionIndex()
    {
        return $this->render('index');
    }

    public function actionReduced()
    {
        return $this->renderPartial('reduced');
    }

    public function actionApplekf()
    {
        return $this->renderPartial('applekf');
    }

    // 帮我找房
    public function actionFindroom()
    {
        $model = new \common\models\CategoryCity();
        $model->pid = 68;
        $city = $model->getList([], ['id', 'city_name']);
        $province = $this->province();
        $type = $this->type();
        $price = $this->price();
        return $this->renderPartial('findroom', ['province' => $province, 'type' => $type, 'price' => $price, 'city' => $city]);
    }

    public function actionError()
    {
        return $this->renderPartial('error');
    }
//        public function actions()
//        {
//            return [
//                'error' => [
//                    'class' => 'yii\web\ErrorAction',
//                ],
//            ];
//        }

    /*户型*/
    public function type()
    {
        $TypeModel = new \common\models\CategoryHousetype();
        $TypeModel->state = 1;
        $type = $TypeModel->getList([], ['id', 'huxing_name']);
        return $type;
    }

    /*价格*/
    public function price()
    {
        $priceModel = new \common\models\HousesPrice();
        $priceModel->state = 1;
        $price = $priceModel->getList([], ['price_short', 'id', 'price']);
        return $price;
    }

    /*省份*/
    public function province()
    {
        $city = new \common\models\CategoryCity();
        $input = Yii::$app->request->post();
        if (!isset($input['pid'])) {
            $city->pid = 0;
        } else {
            $city->pid = $input['city'];
        }
        $city->state = 1;


        $province = $city->getList([]);
        return $province;
    }

    /*传入父id获取城市*/
    public function actionGetcity()
    {
        $model = new \common\models\CategoryCity();
        $input = Yii::$app->request->post();
        $model->pid = $input['id'];
        $rows = $model->getList([], ['id', 'city_name']);
        if (!empty($rows)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'get_success'), $rows);
    }

    public function actionShowhouse()
    {
        Yii::$app->response->statusCode = 404;
        $m = new \common\models\House();
        $m->is_push = 2;
        $data = $m->HomegetList(4);
        return $this->render('@app/views/house/xiajia', ['model' => $data]);
    }

    // 悬挂弹窗
    public function actionSuspend()
    {
        return $this->renderPartial('suspend');
    }
}