City.php 938 字节
<?php


namespace app\api\model;

use think\Model;

class City extends Model
{
    protected $name = 'city';


    // 获取热门城市(省会)
    public function getHotCity()
    {
        return $this->order('id', 'asc')->having('')->select();
    }

    // 获取所有的省
    public function getAllProvince()
    {
        return $this->order('id', ' asc')->group('province_zh')->select();
    }

    // 根据ID获取一个城市
    public function getOneById($id)
    {
        return $this->where(['id' => ['=', $id]])->find();
    }

    // 根据省名称获取大城市
    public function getBigCity($province)
    {
        return $this->where(['province_zh' => ['=', $province]])->order('id', 'asc')->having('leader_zh = city_zh')->select();
    }

    // 获取小城市
    public function getSmallCity($leader)
    {
        return $this->where(['leader_zh' => ['=', $leader]])->order('id', 'asc')->select();
    }
}