<?php
/**
 * @link      http://www.u-bo.com
 * @copyright 南京友博网络科技有限公司
 * @license   http://www.u-bo.com/license/
 */

namespace home\controllers;

use Yii;
use home\models\Area;

/**
 * 中国省/市/区控制器
 *
 * @author zealxd http://blog.u-bo.com
 * @since 0.1
 */
class AreaController extends Controller
{
    public function actions()
    {
		return [];
	}

	/**
	*  查找出所有的省份
	 *
	 *  @return array  返回全国所有的省份
	*/
	public function actionSelectProvince()
	{
		$province = [];
        $id = (int) Yii::$app->request->get('id');
        $province = Area::find()->where(['pid'=> 0])->orderBy(['sort' => SORT_ASC])->asArray()->all();

        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        return $province;
	}

	/**
	*  查找出所有的市
	 *
	 *  @return array  返回当前省份下面的所有市
	*/
	public function actionSelectCity()
	{
		$city = [];
        $id = (int) Yii::$app->request->get('id');
		$city = Area::find()->where(['pid'=> $id])->asArray()->all();

        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        return $city;
	}

	/**
	*  查找出所有的区
	*
	* @return array  返回当前城市下面的所有区
	*/
	public function actionSelectArea()
	{
		$area = [];
        $id = (int) Yii::$app->request->get('id');
		$area = Area::find()->where(['pid'=> $id])->asArray()->all();
		
        Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        return $area;
	}

}
