初始化提交
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Model\Area as AreaModel;
|
||||
|
||||
class AreaService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 检测省市区省市区
|
||||
* @param string $province_id
|
||||
* @param string $city_id
|
||||
* @param string $county_id
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAreaById(string $province_id, string $city_id, string $county_id): bool
|
||||
{
|
||||
// 检测省份
|
||||
if (!empty($province_id)){
|
||||
$province = $this->getAreaByAreaId($province_id);
|
||||
if (empty($province['data'])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 检测城市
|
||||
if (!empty($city_id) && !empty($province_id)){
|
||||
$city = $this->getAreaByAreaId($city_id,$province_id);
|
||||
if (empty($city['data'])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 检测区县
|
||||
if (!empty($county_id) && !empty($city_id)){
|
||||
$county = $this->getAreaByAreaId($county_id,$city_id);
|
||||
if (empty($county['data'])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($province['data']) || !empty($city['data']) || !empty($county['data'])){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取省份列表
|
||||
* @return array
|
||||
*/
|
||||
public function getProvince(): array
|
||||
{
|
||||
$params = array();
|
||||
$params['parent_id'] = 1;
|
||||
$params['area_type'] = 2;
|
||||
|
||||
$province = AreaModel::getList($params);
|
||||
return empty($province) ? success() : success($province->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取城市列表
|
||||
* @return array
|
||||
*/
|
||||
public function getCity(): array
|
||||
{
|
||||
$area_id = $this->request->input('area_id');
|
||||
return $this->getAreaByParentId($area_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取区县信息
|
||||
* @return array
|
||||
*/
|
||||
public function getCounty(): array
|
||||
{
|
||||
$area_id = $this->request->input('area_id');
|
||||
return $this->getAreaByParentId($area_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询省市区-地区id
|
||||
* @param string $area_id
|
||||
* @param string $parent_id
|
||||
* @return array
|
||||
*/
|
||||
protected function getAreaByAreaId(string $area_id, string $parent_id = ""): array
|
||||
{
|
||||
$params = array();
|
||||
$params['area_id'] = $area_id;
|
||||
if (!empty($parent_id)){
|
||||
$params['parent_id'] = $parent_id;
|
||||
}
|
||||
$area = AreaModel::getOne($params);
|
||||
|
||||
return empty($area) ? success() : success($area->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询省市区-父级id
|
||||
* @param string $parent_id
|
||||
* @return array
|
||||
*/
|
||||
protected function getAreaByParentId(string $parent_id = ""): array
|
||||
{
|
||||
$params = array();
|
||||
$params['parent_id'] = $parent_id;
|
||||
$area = AreaModel::getList($params);
|
||||
|
||||
return empty($area) ? success() : success($area->toArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user