<?php
/**
 * Created by PhpStorm.
 * User: xiaofeng
 * Date: 2018/3/13
 * Time: 上午8:46
 */

namespace backend\controllers;

use backend\base\CommonController;
use backend\base\Help;
use backend\server\NewsInformation;
use common\models\CategoryCity;
use common\models\Developers;
use common\models\House;
use common\models\PushmMansion;
use Yii;
use common\models\PushmRotation;
use common\models\PushmVilla;
use common\models\PushmMenu;
use common\models\PushmRecommend;
use common\models\PushChoice;
use common\models\PushmHouse;
use common\models\PushmCity;
use common\models\PushmTimelimitsgroup;
use common\models\PushmCharacteristic;
use backend\server\UploadFile;

/*
 * 热门区域 type = 1
 * 首页-拨打电话号码- 随机区域 type = 2
 *
 * */

class PushmController extends CommonController
{
	/*
         * 豪宅专区
         * */
	public function actionMansion ()
	{
		return $this->render( 'mansion' );
	}
	
	/*
         * 豪宅专区 - 数据
         * */
	public function actionMansionform ()
	{
		$model = new PushmMansion();
		$input = Yii::$app->request->post();
		$rows  = $model->getList( $input );
		
		if ( $rows != null ) {
			$imgUrl = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'housealbum' ];
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
				$val[ 'img' ]       = $imgUrl . $val[ 'img' ];
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total( Yii::$app->request->post() ) , $rows );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'get_error' ) );
	}
	
	/*
         * 豪宅专区 - 添加页面
         * */
	public function actionMansionadd ()
	{
		$developers = $this->Developers();
		return $this->render( 'mansionadd' , [ 'developers' => $developers ] );
	}
	
	/*
         * 豪宅专区 - 添加页面 - 添加数据
         * */
	public function actionMansionaddform ()
	{
		$model = new PushmMansion();
		$input = Yii::$app->request->post();
		
		if ( $input != null ) {
			$url = Yii::$app->params[ 'img_url' ][ 'housealbum' ];
			$img = UploadFile::InstanceImgName( 'img' , $url );
			
			if ( is_string( $img ) ) {
				$model->img = $img;
			}
			
			if ( $model->load( $input , '' ) && $model->save( false ) ) return Help::JsonCode( Help::SUCCESS , '添加成功' );
		}
		return Help::JsonCode( Help::ERROR , '添加失败' );
	}
	
	/*
         * 豪宅专区 - 修改页面
         * */
	public function actionMansionedit ()
	{
		$model = new PushmMansion();
		$input = Yii::$app->request->get();
		$row   = $model->FindById( $input[ 'id' ] );
		
		if ( $row != null ) {
			$house = new House();
			$house = $house->FindById( $row[ 'hid' ] );
			
			$developers = $this->Developers();
			foreach ( $developers as &$val ) {
				$val[ 'checked' ] = '';
				if ( $val[ 'id' ] == $row[ 'did' ] ) {
					$val[ 'checked' ] = 'selected';
				}
			}
			
			$imgUrl       = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'housealbum' ];
			$row[ 'img' ] = $imgUrl . $row[ 'img' ];
			
			return $this->render( 'mansionedit' , [ 'model' => $row , 'house' => $house , 'developers' => $developers ] );
		}
	}
	
	/*
         * 豪宅专区 - 修改页面 - 修改数据
         * */
	public function actionMansioneditform ()
	{
		$model = new PushmMansion();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		
		if ( $row != null ) {
			$url = Yii::$app->params[ 'img_url' ][ 'housealbum' ];
			$img = UploadFile::InstanceImgName( 'img' , $url );
			
			if ( is_string( $img ) ) {
				UploadFile::delImg( $url , $row->img );
				$row->img = $img;
			}
			
			if ( $row->load( $input , '' ) && $row->update() == true ) return Help::JsonCode( Help::SUCCESS , '修改成功' );
		}
		
		return Help::JsonCode( Help::ERROR , '修改失败' );
	}
	
	/*
        * 豪宅专区 - 审核排序删除
        * */
	public function actionMansiondelshow ()
	{
		$model = new PushmMansion();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'sort':
					$row->sort = $input[ 'sort' ];
					break;
				
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else {
						$row->is_show = 1;
					}
					break;
				
				case 'del':
					if ( !empty( $row->img ) ) {
						UploadFile::delImg( Yii::$app->params[ 'img_url' ][ 'housealbum' ] , $row->img );
					}
					if ( $row->delete() ) {
						return Help::JsonCode( Help::SUCCESS , '删除成功' );
					}
					break;
			}
			if ( $row->update( false ) ) return Help::JsonCode( Help::SUCCESS , '修改成功' );
		}
		
		return Help::JsonCode( Help::ERROR , '修改失败' );
	}
	
	/*
        * 豪宅专区 - 批量删除
        * */
	public function actionMansiondelall ()
	{
		$input  = Yii::$app->request->post();
		$model  = PushmMansion::find()->where( [ 'in' , 'id' , $input[ 'id' ] ] )->all();
		$delall = PushmMansion::deleteAll( [ 'id' => $input[ 'id' ] ] );
		
		if ( $delall ) {
			foreach ( $model as $value ) {
				UploadFile::delImg( Yii::$app->params[ 'img_url' ][ 'housealbum' ] , $value[ 'img' ] );
			}
			return Help::JsonCode( Help::SUCCESS , '批量删除成功' );
		}
		return Help::JsonCode( Help::ERROR , '批量删除失败' );
	}
	
	
	/*
         * 推送首页轮播
         * */
	public function actionRotation ()
	{
		$city = $this->City();
		return $this->render( 'rotation' , [ 'city' => $city ] );
	}
	
	/*
         * 推送首页轮播数据
         * */
	public function actionRotationforms ()
	{
		$model = new PushmRotation();
		
		$rows  = $model->getList( Yii::$app->request->post() );
		if ( $rows != null ) {
			$imgUrl = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'push_lb' ];
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
				$val[ 'img' ]       = $imgUrl . $val[ 'img' ];
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total( Yii::$app->request->post() ) , $rows );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'get_error' ) );
	}
	
	/*
        *   推送首页轮播 - 添加页面
        */
	public function actionRotationadd ()
	{
		$cityModel = $this->City();
		return $this->render( 'rotationadd' , [ 'city' => $cityModel ] );
	}
	
	/*
        *   推送首页轮播 - 添加数据
        */
	public function actionRotationform ()
	{
		try {
			$model = new PushmRotation();
			$input = Yii::$app->request->post();
			$url   = Yii::$app->params[ 'img_url' ][ 'push_lb' ];
			$img   = UploadFile::InstanceImgName_v1( 'img' , $url );
			if ( is_string( $img ) ) {
				$input[ 'img' ] = $img;
			}
			$model->load( $input , '' );
			if ( $model->save() ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
			return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_error' ) , $model->errors );
		} catch ( \Exception $e ) {
			return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_error' ) , $e->getMessage() );
			
		}
		
	}
	
	/*
        *   推送首页轮播 - 修改
        */
	public function actionRotationedit ()
	{
		$model = new PushmRotation();
		$input = Yii::$app->request->get();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			$imgUrl       = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'push_lb' ];
			$row[ 'img' ] = $imgUrl . $row[ 'img' ];
			$cityModel    = $this->City();
			foreach ( $cityModel as &$val ) {
				$val[ 'checked' ] = '';
				if ( $val[ 'id' ] == $row[ 'city' ] ) {
					$val[ 'checked' ] = 'selected';
				}
			}
			return $this->render( 'rotationedit' , [ 'model' => $row , 'city' => $cityModel ] );
		}
	}
	
	/*
         * 推送首页轮播 - 修改数据
         * */
	public function actionRotationeditform ()
	{
		$model        = new PushmRotation();
		$input        = Yii::$app->request->post();
		$setAttribute = $model->Authenticator( $input );
		if ( is_object( $setAttribute ) ) {
			$row = $model->FindById( $input[ 'id' ] );
			if ( $row != null ) {
				$row = Help::SetAttr( $input , $model , $row );
				$url = Yii::$app->params[ 'img_url' ][ 'push_lb' ];
				$img = UploadFile::InstanceImgName( 'img' , $url );
				if ( is_string( $img ) ) {
					UploadFile::delImg( $url , $row->img );
					$row->img = $img;
				}
				if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
			}
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) , $setAttribute );
	}
	
	/*
         * 推送首页轮播 - 删除 and 禁用
         * */
	public function actionImgdelshow ()
	{
		$model = new PushmRotation();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'sort':
					if ( is_numeric( $input[ 'sort' ] ) ) {
						$row->sort = $input[ 'sort' ];
					}
					
					break;
				case 'del':
					if ( $row->delete() ) {
						UploadFile::delImg( Yii::$app->params[ 'img_url' ][ 'push_lb' ] , $row->img );
						return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
					}
					break;
				case 'expiration':
					$row->expiration_date = $input[ 'expiration' ];
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	/******************************豪宅楼盘*************************************/
	/*
         * 推送首页轮播
         * */
	public function actionVilla ()
	{
		return $this->render( 'villa' );
	}
	
	/*
         * 推送首页轮播数据
         * */
	public function actionVillaforms ()
	{
		$model = new PushmVilla();
		$rows  = $model->getList( Yii::$app->request->post() );
		if ( $rows != null ) {
			$imgUrl = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'villa' ];
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
				$val[ 'img' ]       = $imgUrl . $val[ 'img' ];
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total() , $rows );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'get_error' ) );
	}
	
	/*
        *   推送首页轮播 - 添加页面
        */
	public function actionVillaadd ()
	{
		$cityModel  = $this->City();
		$developers = $this->Developers();
		return $this->render( 'villaadd' , [ 'city' => $cityModel , 'developers' => $developers ] );
	}
	
	/*
        *   推送首页轮播 - 添加数据
        */
	public function actionVillaform ()
	{
		$model = new PushmVilla();
		$input = Yii::$app->request->post();
		$model = $model->Authenticator( $input );
		if ( is_object( $model ) ) {
			$url = Yii::$app->params[ 'img_url' ][ 'villa' ];
			$img = UploadFile::InstanceImgName( 'img' , $url );
			if ( is_string( $img ) ) {
				$model->img = $img;
				//压缩图片
				$compressParams                        = [];
				$compressParams[ 'data' ][ 'imgname' ] = $img;;
				$compressParams[ 'data' ][ 'url' ]    = $url;
				$compressParams[ 'data' ][ 'source' ] = '移动端推送位,首页热门活动@添加';
				$ya                                   = new \backend\event\TinifyEvent();
				$ya->CompressImg( $compressParams );
			}
			if ( $model->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_error' ) , $model );
	}
	
	/*
        *   推送首页轮播 - 修改
        */
	public function actionVillaedit ()
	{
		$model = new PushmVilla();
		$input = Yii::$app->request->get();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			$imgUrl       = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'villa' ];
			$row[ 'img' ] = $imgUrl . $row[ 'img' ];
			$cityModel    = $this->City();
			$developers   = $this->Developers();
			foreach ( $cityModel as &$val ) {
				$val[ 'checked' ] = '';
				if ( $val[ 'id' ] == $row[ 'city' ] ) {
					$val[ 'checked' ] = 'selected';
				}
			}
			foreach ( $developers as &$val ) {
				$val[ 'checked' ] = '';
				if ( $val[ 'id' ] == $row[ 'developers' ] ) {
					$val[ 'checked' ] = 'selected';
				}
			}
			return $this->render( 'villaedit' , [ 'model' => $row , 'city' => $cityModel , 'developers' => $developers ] );
		}
	}
	
	/*
         * 推送首页轮播 - 修改数据
         * */
	public function actionVillaeditform ()
	{
		$model        = new PushmVilla();
		$input        = Yii::$app->request->post();
		$setAttribute = $model->Authenticator( $input );
		if ( is_object( $setAttribute ) ) {
			$row = $model->FindById( $input[ 'id' ] );
			if ( $row != null ) {
				$row = Help::SetAttr( $input , $model , $row );
				$url = Yii::$app->params[ 'img_url' ][ 'villa' ];
				$img = UploadFile::InstanceImgName( 'img' , $url );
				if ( is_string( $img ) ) {
					UploadFile::delImg( $url , $row->img );
					$row->img = $img;
					//压缩图片
					$compressParams                        = [];
					$compressParams[ 'data' ][ 'imgname' ] = $img;;
					$compressParams[ 'data' ][ 'url' ]    = $url;
					$compressParams[ 'data' ][ 'source' ] = '移动端推送位,首页热门活动@修改';
					$ya                                   = new \backend\event\TinifyEvent();
					$ya->CompressImg( $compressParams );
				}
				if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
			}
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) , $setAttribute );
	}
	
	/*
         * 推送首页轮播 - 删除 and 禁用
         * */
	public function actionVillaimgdelshow ()
	{
		$model = new PushmVilla();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'del':
					$row->del = 2;
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	/******************************豪宅楼盘*************************************/
	
	/*
         *  首页-品房推荐 -列表
         * */
	public function actionRecommend ()
	{
		
		return $this->render( 'recommend' );
	}
	
	public function actionRecommendform ()
	{
		$model = new PushmRecommend();
		$input = Yii::$app->request->post();
		$rows  = $model->getList( $input );
		if ( $rows != null ) {
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total() , $rows );
		}
		return Help::JsonData( Help::ERROR , Yii::t( 'app' , 'get_error' ) , 0 );
	}
	
	/*
         *  移动端导航推荐
         * */
	public function actionMenu ()
	{
		return $this->render( 'menu' );
	}
	
	/*
         * 推送移动端导航推荐
         * */
	public function actionMenuforms ()
	{
		$model = new PushmMenu();
		$rows  = $model->getList( Yii::$app->request->post() );
		if ( $rows != null ) {
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total() , $rows );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'get_error' ) );
	}
	
	/*
        *   推送移动端导航推荐 - 添加页面
        */
	public function actionMenuadd ()
	{
		$cityModel = $this->City();
		$menu      = $this->parentMenu();
		return $this->render( 'menuadd' , [ 'city' => $cityModel , 'menu' => $menu ] );
	}
	
	//*获取父级菜单*/
	private function parentMenu ()
	{
		$frontend = new \common\models\Frontend();
		//$menu=$frontend->PidList(0)
		return $frontend->PidList( 0 );
	}
	
	/*
        *   推送移动端导航推荐
        */
	public function actionMenuform ()
	{
		$model = new PushmMenu();
		$input = Yii::$app->request->post();
		$model = $model->Authenticator( $input );
		if ( is_object( $model ) ) {
			if ( $model->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_error' ) , $model );
	}
	
	public function actionMenudel ()
	{
		$model = new PushmMenu();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'del':
					$row->del = 2;
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	/*
        *  首页-品房推荐 - 添加页面
        */
	public function actionRecommendadd ()
	{
		return $this->render( 'recommendadd' );
		
	}
	
	/*
         * 首页-品房推荐 - 添加数据
         * */
	public function actionRecommendaddform ()
	{
		$model = new PushmRecommend();
		$input = Yii::$app->request->post();
		$auth  = $model->Authenticator( $input );
		if ( is_object( $auth ) ) {
			//                $url = Yii::$app->params['img_url']['hot_activity'];
			//                $img = UploadFile::InstanceImgName('img',$url);
			//                if(is_string($img))
			//                {
			//                    $auth->img = $img;
			//                }
			
			if ( $auth->save() ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'add_error' ) , $auth );
	}
	
	/*
        *  首页-品房推荐 - 修改页面
        */
	public function actionRecommendedit ()
	{
		$model = new PushmRecommend();
		$row   = $model->FindById( Yii::$app->request->get( 'id' ) );
		if ( $row != null ) {
			return $this->render( 'recommendedit' , [ 'model' => $row ] );
		}
	}
	
	/*
         * 首页-品房推荐 - 修改数据
         * */
	public function actionRecommendeditform ()
	{
		$model        = new PushmRecommend();
		$input        = Yii::$app->request->post();
		$setAttribute = $model->Authenticator( $input );
		if ( is_object( $setAttribute ) ) {
			$row = $model->FindById( $input[ 'id' ] );
			if ( $row != null ) {
				$row = Help::SetAttr( $input , $model , $row );
				
				if ( $row->save() ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
			}
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) , $setAttribute );
	}
	
	/*
         * 首页-品房推荐 - 删除 and 禁用
         * */
	public function actionRecommenddelshow ()
	{
		$model = new PushmRecommend();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'del':
					$row->del = 2;
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	
	/*
         * 首页-热销楼盘
         * */
	public function actionHotsale ()
	{
		return $this->render( 'hotsale' , [ 'type' => 1 ] );
	}
	
	
	/*
         *  首页-热销楼盘 - 数据
         * */
	public function actionHotsaleform ()
	{
		$model = new PushmHouse();
		$input = Yii::$app->request->post();
		if ( !empty( $input[ 'city_id' ] ) ) {
			
			$input[ 'city_id' ] = explode( ',' , $input[ 'city_id' ] );
		}
		$result = $model->getList( $input );
		
		
		if ( $result != null ) {
			foreach ( $result as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
			}
			
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Totalhotsalefeng( $input ) , $result );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'get_error' ) );
	}
	
	/*
        *    首页-热销楼盘 - 添加
        */
	public function actionHotsaleadd ()
	{
		return $this->render( 'hotsaleadd' , [ 'type' => Yii::$app->request->get( 'type' ) ] );
	}
	
	/*
         *    首页-热销楼盘 - 添加数据
         */
	public function actionHotsaleaddform ()
	{
		$input           = Yii::$app->request->post();
		$model           = new PushmHouse();
		$model->scenario = 'add';
		$validate        = $model->Authenticator( $input );
		if ( is_object( $validate ) ) {
			if ( $validate->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'add_error' ) , $validate );
	}
	
	/*
        * 首页-热销楼盘- - 删除 and 禁用
        * */
	public function actionSaledelshow ()
	{
		$model = new PushmHouse();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'del':
					$row->del = 2;
					break;
				case 'sort':
					if ( is_numeric( $input[ 'sort' ] ) ) {
						$row->sort = $input[ 'sort' ];
					}
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	/*
        * 首页-热销楼盘- 批量删除
        * */
	public function actionHotsaledelall ()
	{
		$input  = Yii::$app->request->post();
		$delall = PushmHouse::deleteAll( [ 'id' => $input[ 'id' ] ] );
		
		if ( $delall ) {
			return Help::JsonCode( Help::SUCCESS , '批量删除成功' );
		}
		return Help::JsonCode( Help::ERROR , '批量删除失败' );
	}
	
	/*
         * 搜索框 - 热门筛选
         * */
	public function actionHotscreen ()
	{
		return $this->render( 'hotsale' , [ 'type' => 2 ] );
	}
	
	/*
         * 首页 - 精选楼盘
         * */
	public function actionHotselected ()
	{
		
		return $this->render( 'hotsale' , [ 'type' => 4 , 'city_id' => Yii::$app->request->get( 'city_id' ) ] );
	}
	
	/*
         *首页-热门地区
         * */
	public function actionHotcity ()
	{
		return $this->render( 'hotcity' , [ 'type' => 1 ] );
	}
	
	/*
         * 首页-热门区域-数据列表
         * */
	public function actionHotcityform ()
	{
		$model = new PushmCity();
		
		$input       = Yii::$app->request->post();
		$model->type = $input[ 'type' ];
		$rows        = $model->getList( $input );
		if ( !empty( $rows ) ) {
			foreach ( $rows as &$val ) {
				$val[ 'img' ]       = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'city' ] . $val[ 'img' ];
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
			}
			return Help::JsonData( 0 , '成功' , $model->Total() , $rows );
		}
	}
	
	/*
         * 首页-热门区域-数据列表
         * */
	public function actionHotcityadd ()
	{
		$cityModel = ( new CategoryCity() )->SortgetList( [] );
		return $this->render( 'hotcityadd' , [ 'type' => Yii::$app->request->get( 'type' ) , 'city' => $cityModel ] );
	}
	
	/*
         * 首页-热门区域-数据列表
         * */
	public function actionHotcityaddform ()
	{
		$model = new PushmCity();
		
		$input           = Yii::$app->request->post();
		$model->scenario = 'add';
		$auth            = $model->Authenticator( $input );
		if ( is_object( $auth ) ) {
			$img = UploadFile::InstanceImgName( 'img' , Yii::$app->params[ 'img_url' ][ 'city' ] );
			if ( is_string( $img ) ) {
				$auth->img = $img;
			}
			if ( $auth->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'add_error' ) , $auth );
		
		
	}
	
	/*
     *	热门区域- 修改
     */
	public function actionHotcityedit ()
	{
		$model = new PushmCity();
		$input = Yii::$app->request->get();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			$cityModel = ( new CategoryCity() )->SortgetList( [] );
			foreach ( $cityModel as &$val ) {
				$val[ 'checked' ] = '';
				if ( $val[ 'id' ] == $row[ 'city_id' ] ) {
					$val[ 'checked' ] = 'selected';
				}
			}
			return $this->render( 'hotcityedit' , [ 'model' => $row , 'city' => $cityModel ] );
		}
	}
	
	/*
    * 推送首页轮播 - 修改数据
    * */
	public function actionHotcityeditform ()
	{
		$model        = new PushmCity();
		$input        = Yii::$app->request->post();
		$setAttribute = $model->Authenticator( $input );
		if ( is_object( $setAttribute ) ) {
			$row = $model->FindById( $input[ 'id' ] );
			if ( $row != null ) {
				$row = Help::SetAttr( $input , $model , $row );
				if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
			}
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) , $setAttribute );
	}
	
	
	/*
     * 首页-精选 - 删除 and 禁用
     * */
	public function actionCitydelshow ()
	{
		$model = new PushmCity();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'del':
					if ( !empty( $row->img ) ) {
						UploadFile::delImg( Yii::$app->params[ 'img_url' ][ 'city' ] , $row->img );
					}
					if ( $row->delete() ) {
						return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
					}
					break;
				case 'sort':
					if ( !is_numeric( $input[ 'sort' ] ) ) {
						return Help::JsonCode( Help::ERROR , '请输入数字' );
					}
					$row->sort = $input[ 'sort' ];
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	/*
         * 首页-特色类型 页面
         * */
	public function actionCharacteristic ()
	{
		return $this->render( 'characteristic' );
	}
	
	/*
         * 首页-特色类型  数据
         * */
	public function actionCharacteristicform ()
	{
		$model = new PushmCharacteristic();
		$input = Yii::$app->request->post();
		$rows  = $model->getList( $input );
		if ( !empty( $rows ) ) {
			$url = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'characteristic' ];
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
				$val[ 'img' ]       = $url . $val[ 'img' ];
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total() , $rows );
		}
	}
	
	/*
         * 首页-特色类型  添加页面
         * */
	public function actionCharacteristicadd ()
	{
		return $this->render( 'characteristicadd' );
	}
	
	/*
        * 首页-特色类型  添加页面
        * */
	public function actionCharacteristicaddform ()
	{
		$model = new PushmCharacteristic();
		$input = Yii::$app->request->post();
		$auth  = $model->Authenticator( $input );
		if ( is_object( $auth ) ) {
			$url    = Yii::$app->params[ 'img_url' ][ 'characteristic' ];
			$imgStr = UploadFile::InstanceImgName( 'img' , $url );
			if ( is_string( $imgStr ) ) {
				$auth->img = $imgStr;
			}
			if ( $auth->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'add_error' ) , $auth );
	}
	
	/*
         * 首页-特色类型  修改页面
         * */
	public function actionCharacteristicedit ()
	{
		$model = new PushmCharacteristic();
		$row   = $model->FindById( Yii::$app->request->get( 'id' ) );
		if ( $row != null ) {
			$row[ 'img' ] = Yii::$app->params[ 'httpImg' ][ 'host' ] . Yii::$app->params[ 'httpImg' ][ 'characteristic' ] . $row[ 'img' ];
			return $this->render( 'characteristicedit' , [ 'model' => $row , 'get' => Yii::$app->request->get() ] );
		}
		
	}
	
	
	/*
         * 首页-特色类型  修改页面
         * */
	public function actionCharacteristiceditform ()
	{
		$model = new PushmCharacteristic();
		$input = Yii::$app->request->post();
		$auth  = $model->Authenticator( $input );
		if ( is_object( $auth ) ) {
			$row = $model->FindById( $input[ 'id' ] );
			if ( !empty( $row ) ) {
				$url    = Yii::$app->params[ 'img_url' ][ 'characteristic' ];
				$imgStr = UploadFile::InstanceImgName( 'img' , $url );
				$result = Help::SetAttr( $input , $auth , $row );
				if ( is_string( $imgStr ) ) {
					UploadFile::delImg( $url , $row[ 'img' ] );
					$result->img = $imgStr;
				}
				if ( $result->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
			}
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) , $auth );
	}
	
	/*
        * 首页-特色类型 - 删除 and 禁用
        * */
	public function actionCharacteristicdelshow ()
	{
		$model = new PushmCharacteristic();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'del':
					if ( !empty( $row->img ) ) {
						UploadFile::delImg( Yii::$app->params[ 'img_url' ][ 'characteristic' ] , $row->img );
					}
					if ( $row->delete() ) {
						return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
					}
					break;
				case 'sort':
					if ( !is_numeric( $input[ 'sort' ] ) ) {
						return Help::JsonCode( Help::ERROR , '请输入数字' );
					}
					$row->sort = $input[ 'sort' ];
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	/*
         * 首页 - 拨打电话图标   随机区域里面的电话号码
         * */
	public function actionRandcity ()
	{
		return $this->render( 'randcity' , [ 'type' => 2 ] );
	}
	
	/*
         * 首页 - 拨打电话 数据
         * */
	public function actionRandcityform ()
	{
		$model = new PushmCity();
		
		$input       = Yii::$app->request->post();
		$model->type = $input[ 'type' ];
		$rows        = $model->getList( $input );
		if ( !empty( $rows ) ) {
			foreach ( $rows as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
			}
			return Help::JsonData( 0 , '成功' , $model->Total() , $rows );
		}
	}
	
	/*
         * 首页 - 拨打电话  添加页面
         * */
	public function actionRandcityadd ()
	{
		return $this->render( 'randcityadd' , [ 'type' => Yii::$app->request->get( 'type' ) ] );
	}
	
	/*
         * 首页 - 拨打电话 添加数据
         * */
	public function actionRandcityaddform ()
	{
	
	}
	
	/********限时团购*********/
	public function actionTimelimitsgroup ()
	{
		$cityModel = $this->City();
		return $this->render( 'timelimitsgroup' , [ 'type' => 1 , 'city' => $cityModel ] );
	}
	
	public function actionTimelimitsgroupform ()
	{
		$model  = new PushmTimelimitsgroup();
		$input  = Yii::$app->request->post();
		$result = $model->getList( $input );
		
		if ( $result != null ) {
			foreach ( $result as &$val ) {
				$val[ 'create_at' ] = date( 'Y-m-d H:i' , $val[ 'create_at' ] );
			}
			return Help::JsonData( 0 , Yii::t( 'app' , 'get_success' ) , $model->Total( $input ) , $result );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'get_error' ) );
	}
	
	public function actionTimelimitsgroupadd ()
	{
		$cityModel = $this->City();
		return $this->render( 'timelimitsgroupadd' , [ 'type' => Yii::$app->request->get( 'type' ) , 'city' => $cityModel ] );
	}
	
	public function actionTimelimitsgroupaddform ()
	{
		$input           = Yii::$app->request->post();
		$model           = new PushmTimelimitsgroup();
		$model->scenario = 'add';
		$validate        = $model->Authenticator( $input );
		if ( is_object( $validate ) ) {
			if ( $validate->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'add_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'add_error' ) , $validate );
	}
	
	/*
        *  首页 - 修改页面
        */
	public function actionTimelimitsgroupedit ()
	{
		$model     = new PushmTimelimitsgroup();
		$cityModel = $this->City();
		$row       = $model->FindById( Yii::$app->request->get( 'id' ) );
		if ( $row != null ) {
			return $this->render( 'timelimitsgroupedit' , [ 'type' => Yii::$app->request->get( 'type' ) , 'row' => $row , 'house_name' => Yii::$app->request->get( 'house_name' ) , 'city' => $cityModel ] );
		}
	}
	
	/*
         * 显示抢购 修改数据
         * */
	public function actionTimelimitsgroupeditform ()
	{
		$model        = new PushmTimelimitsgroup();
		$input        = Yii::$app->request->post();
		$setAttribute = $model->Authenticator( $input );
		if ( is_object( $setAttribute ) ) {
			$row = $model->FindById( $input[ 'id' ] );
			if ( $row != null ) {
				$row = Help::SetAttr( $input , $model , $row );
				
				if ( $row->save() ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
			}
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) , $setAttribute );
	}
	
	/*排序 删除 显示*/
	public function actionTimelimitsgroupdelandshow ()
	{
		$model = new PushmTimelimitsgroup();
		$input = Yii::$app->request->post();
		$row   = $model->FindById( $input[ 'id' ] );
		if ( $row != null ) {
			switch ( $input[ 'type' ] ) {
				case 'show':
					if ( $row->is_show == 1 ) {
						$row->is_show = 2;
					} else if ( $row->is_show == 2 ) {
						$row->is_show = 1;
					}
					break;
				case 'del':
					$row->del = 2;
					break;
				case 'sort':
					$row->sort = $input[ 'sort' ];
					break;
				case 'click':
					$row->click = $input[ 'click' ];
					break;
				case 'group_num':
					$row->group_num = $input[ 'group_num' ];
					break;
			}
			if ( $row->save( false ) ) return Help::JsonCode( Help::SUCCESS , Yii::t( 'app' , 'edit_success' ) );
		}
		return Help::JsonCode( Help::ERROR , Yii::t( 'app' , 'edit_error' ) );
	}
	
	private function Developers ()
	{
		$developers         = new \common\models\Developers();
		$developers->is_del = 1;
		$developers         = $developers->getList( [] );
		return $developers;
	}
	
	private function City ()
	{
		$city        = new \common\models\CategoryCity();
		$city->state = 1;
		$city->pid   = 0;
		$cityModel   = $city->getList( [] );
		return $cityModel;
	}
	
	public function actionHothouse ()
	{
		return $this->render( 'hothouse' , [ 'type' => 1 ] );
	}
	
	/**
	 * 添加推送楼盘
	 * @return string
	 */
	public function actionHothouseadd ()
	{
		return $this->render( 'hothouseadd' , [ 'type' => Yii::$app->request->get( 'type' ) ] );
	}
}