coupon-admin/app/controller/api/Area.php

75 lines
2.1 KiB
PHP
Raw Normal View History

2021-11-29 09:32:48 +00:00
<?php
namespace app\controller\api;
2021-12-17 03:41:27 +00:00
use app\repository\DictionaryRepository;
2021-11-29 09:32:48 +00:00
use think\facade\Db;
use app\model\Area as AreaModel;
/**
* Area
*
* Class Business
* @package app\controller\api
*/
class Area extends Base
{
2021-12-02 10:34:44 +00:00
protected $noNeedLogin = [
2021-12-17 03:41:27 +00:00
'index',"getProvinceDictionaryCity"
2021-12-02 10:34:44 +00:00
];
2021-11-29 09:32:48 +00:00
/**
* 根据上级行政代码 获取下级
* */
public function index()
{
$pcode = input("areaId/d",86);
2021-12-15 07:04:20 +00:00
$filter = input("filter",false);
return json(AreaModel::getByPCode($pcode,$filter));
2021-11-29 09:32:48 +00:00
}
2021-12-17 03:41:27 +00:00
/**
* 获取
* */
public function getProvinceDictionaryCity()
{
$province = AreaModel::getByPCode(86,true);
$provinceCode = array_column($province->toArray(),null,"code");
$provinceCodeArray = array_keys($provinceCode);
$city = AreaModel::getByPCodes($provinceCodeArray,true);
$city = array_column($city,null,"code");
$items = DictionaryRepository::getInstance()->getAllBusinessCircleList();
$items->each(function ($item)use($city) {
$areaText = '';
if (!empty($item['province_text'])) {
$areaText = $item['province_text'].'·';
}
if (!empty($item['city_text']) && $item['city_text'] != '市辖区') {
$areaText .= $item['city_text'].'·';
}
if (!empty($item['county_text'])) {
$areaText .= $item['county_text'];
}
$item['name_text'] = $item['name'];
if (!empty($areaText)) {
$item['name_text'] = $item['name'] . '「'.$areaText.'」';
}
return $item;
});
foreach ($items->toArray() as $item){
if(isset($city[$item["city"]])){
$city[$item["city"]]["children"][]=$item;
}
}
foreach ($city as $item){
if (isset($provinceCode[$item["pcode"]])){
$provinceCode[$item["pcode"]]["children"][] =$item;
}
}
2021-12-17 08:39:07 +00:00
return $this->json(0,"success",array_values($provinceCode));
2021-12-17 03:41:27 +00:00
}
2021-11-29 09:32:48 +00:00
}