<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\City as CityModel;
use app\api\model\University as UniversityModel;
/**
 * 城市相关
 */
class City extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];



    /**
     * 获取省
     * @ApiTitle    (获取省)
     * @ApiSummary  (获取省)
     * @ApiMethod   (GET)
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="对象")
     * @ApiReturn   ({
        "code": 1,
        "msg": "获取省份成功",
        "time": "1585874807",
        "data": [
        {
        "id": "101010100(省份ID)",
        "city_en": "beijing",
        "city_zh": "北京",
        "province_en": "beijing",
        "province_zh": "北京(省份名称)",
        "country_en": "China",
        "country_zh": "中国",
        "leader_en": "beijing",
        "leader_zh": "北京",
        "lat": "39.904989",
        "lon": "116.405285"
        }})
     */
    public function getAllProvince()
    {
        $city = new CityModel();
        $cityData = $city->getAllProvince();
        $this->success('获取省份成功', $cityData);
    }



    /**
     * 获取一级城市
     * @ApiTitle    (获取一级城市)
     * @ApiSummary  (获取一级城市)
     * @ApiMethod   (GET)
     * @ApiParams   (name="province_id", type="integer", required=true, description="城市ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="对象")、
     * @ApiReturn   ({
        "code": 1,
        "msg": "获取大城市成功",
        "time": "1585874953",
        "data": [
        {
        "id": "101300101",
        "city_en": "nanning",
        "city_zh": "南宁(城市名称)",
        "province_en": "guangxi",
        "province_zh": "广西",
        "country_en": "China",
        "country_zh": "中国",
        "leader_en": "nanning",
        "leader_zh": "南宁",
        "lat": "22.82402",
        "lon": "108.320004"
        }})
     */
    public function getBigCity()
    {
        $provinceId = $this->request->param('province_id', '', 'int');
        if(!$provinceId || !is_numeric($provinceId)) {
            $this->error('您的提交存在问题');
        }

        $city = new CityModel();
        $cityInfo = $city->getOneById($provinceId);
        if(!$cityInfo) {
            $this->error('您的提交存在问题');
        }

        $cityData = $city->getBigCity($cityInfo['province_zh']);
        $this->success('获取大城市成功', $cityData);
    }



    /**
     * 获取市的大学
     * @ApiTitle    (获取市的大学)
     * @ApiSummary  (获取市的大学)
     * @ApiMethod   (GET)
     * @ApiParams   (name="city_id", type="integer", required=true, description="城市ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, description="状态码")
     * @ApiReturnParams   (name="msg", type="string", required=true, description="提示语")
     * @ApiReturnParams   (name="data", type="object", description="对象")、
     * @ApiReturn   ({
        "code": 1,
        "msg": "获取市的大学成功",
        "time": "1586420249",
        "data": [
        {
        "id": 1,
        "name": "哈哈",
        "des_content": "1",
        "des_image": "",
        "updatetime": 0,
        "createtime": 0,
        "url": "",
        "wechat": "",
        "show_switch": 1,
        "icon_image": "",
        "weigh": 0,
        "province_id": 1,
        "city_id": 1,
        "deletetime": null,
        "level_id": 1
        }
        ]
        })
     */
    public function getUniversityByCity()
    {
        $cityId = $this->request->param('city_id', 0, 'int');
        if(!$cityId) {
            $this->error('您的提交存在问题');
        }

        $university = new UniversityModel();
        $universityList = $university->listByCityId($cityId);
        $this->success('获取市的大学成功', $universityList);
    }
}