<?php

namespace wechat\controllers;

use common\models\CategoryCity;
use wechat\base\CommonController;
use Yii;
use wechat\base\Help;

class PublicController extends  CommonController{
    
    public $enableCsrfValidation = false;
    /*
     * 报名弹窗
     * */
    public function actionSignup()
    {
        return $this->renderPartial('signup');
    }

    /*
     * 内页顶部导航
     * */
    public function actionNav()
    {
        return $this->renderPartial('nav');
    }

    /*
     * 内页顶部导航  侧边栏
     * */
    public function actionNavsidebar()
    {
        return $this->renderPartial('navsidebar');
    }

    /*
     * 报名弹窗
     * */
    public function actionCustomization()
    {
        $arr['price'] = ['不限',100,200,300,400,500,600,700,800,900,1000];
        $typeModel = new \common\models\CategoryHousetype();
        $typeModel->state = 1;
        $arr['type']  = $typeModel->getList([],['id','huxing_name']);
        $city = new \common\models\CategoryCity();
        $city->pid = 0;
        $arr['province'] =     $city->getList([],['id','city_name']);
//        p($arr);1111
//        exit;
        return $this->renderPartial('customization',$arr);
    }

    // 楼盘 预售许可证
    public function actionLicence()
    {
        return $this->renderPartial('licence');
    }

    /*独立的报名窗口*/
    public function actionApplicationwindow()
    {
        $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('applicationwindow',['province'=>$province,'type'=>$type,'price'=>$price,'city'=>$city]);
    }

    public function actionTypes()
    {
        $rows = $this->type();
        if($rows)
        {
            return Help::JsonCode(Help::SUCCESS,Yii::t('app','get_success'),$rows);
        }
            return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
    }

    public function actionSaleprice()
    {
        $rows = $this->price();
        if($rows)
        {
            return Help::JsonCode(Help::SUCCESS,Yii::t('app','get_success'),$rows);
        }
            return Help::JsonCode(Help::ERROR,Yii::t('app','get_error'));
    }

    /*
     * 公共报名-专业找房  2019-1-15
     */
    public function actionMajorlookhouse()
    {
        return $this->renderPartial('majorlookhouse');
    }

    /*户型*/
    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([],['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 actionFindroom()
    {
        //户型
        $TypeModel = new \common\models\CategoryHousetype();
        $Type = $TypeModel->getList([],['id','huxing_name']);

        //区域
        $City = (new CategoryCity())->GetUpCity();

        return $this->render('findroom',['type'=>$Type,'city'=>$City]);
    }


    /*
     * 404页面
     * */
    public function actionError()
    {
        return $this->renderPartial('error');
    }

    /*
     * 楼盘项目不存在显示的页面
     */
    public function actionShowhouse()
    {
        $m = new \common\models\House();
        $data = $m->HomegetList(5);
        foreach ($data as &$val)
        {
            $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses'].$val['thumb'].'/'.'same';
            if(!empty($val['characteristic']))
            {
                $val['characteristic'] =  \common\fm\HouseHandle::ChangeCharacteristic($val['characteristic']);
            }
            $val['tel'] = \common\fm\HouseHandle::ChangeCityTel($val['city']);
        }

        $start_time = date('Y/m').'/01-'.date('Y/m', strtotime('+ 2 month')).'/01';  //有效日期
        return $this->render('@app/views/house/xiajia.php',['model'=>$data,'start_time'=>$start_time]);
    }
}