123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\api\controller;
- use app\common\model\ChinaArea;
- use think\Db;
- /**
- * @title 地址库
- * @controller Area
- * @group common
- */
- class Area extends Base
- {
- /**
- * @title 获取地址库数据
- * @desc 获取地址库数据
- * @author qc
- * @method GET
- * @url /api/area/getAreaTree
- * @header name:Authorization require:1 desc:Token
- * @param name:level type:int require:0 default:3 desc:查询等级(0全部,1精确到省,2精确到市,3精确到县区,4精确到街道)
- * @return name:name type:string default:-- desc:名称
- * @return name:short_name type:string default:-- desc:简称
- * @return name:level type:int default:-- desc:等级(1省,2市,3区,4道)
- * @return name:code type:int default:-- desc:编码
- * @return name:lng type:string default:-- desc:经度
- * @return name:lat type:string default:-- desc:纬度
- * @return name:children type:array default:-- desc:下级(数据字段同上)
- */
- public function getAreaTree()
- {
- $level = input('level',3);
- if($level){
- $all_area = ChinaArea::where('level','<=',$level)->select();
- }else{
- $all_area = ChinaArea::where('level','>',0)->order('level asc,sort desc,id asc')->select();
- }
- $this->success('ok',['list'=>make_tree($all_area)]);
- }
- /**
- * @title 获取地址库ID获取下一级
- * @desc 获取地址库ID获取下一级
- * @author qc
- * @method GET
- * @url /api/area/getAreaChildrenByID
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:0 default:0 desc:数据表地址记录id
- * @return name:name type:string default:-- desc:名称
- * @return name:short_name type:string default:-- desc:简称
- * @return name:level type:int default:-- desc:等级(1省,2市,3区,4道)
- * @return name:code type:int default:-- desc:编码
- * @return name:lng type:string default:-- desc:经度
- * @return name:lat type:string default:-- desc:纬度
- * @return name:children type:array default:-- desc:下级(数据字段同上)
- */
- public function getAreaChildrenByID()
- {
- $id = input('id');
- $list = ChinaArea::where('pid',$id)->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取市级地址
- * @desc 获取市级地址
- * @author qc
- * @method GET
- * @url /api/area/getCityByName
- * @header name:Authorization require:1 desc:Token
- * @param name:name type:string require:0 default:0 desc:市名(或拼音)模糊查询(不传查全部)
- * @return name:name type:string default:-- desc:名称
- * @return name:short_name type:string default:-- desc:简称
- */
- public function getCityByName()
- {
- $where = [];
- $where[] = ['level','=',2];
- if(input('name')) $where[] = ['name|pinyin','like','%'.input('name').'%'];
- $all_city = ChinaArea::field('id,name,short_name,first')->where($where)->order('sort desc,id asc')->select();
- $this->success('ok',['list'=>$all_city]);
- }
- /**
- * @title 首字母分组获取地级市
- * @desc 首字母分组获取地级市
- * @author qc
- * @method GET
- * @url /api/area/getAllCity
- * @header name:Authorization require:1 desc:Token
- * @return name:title type:string default:-- desc:搜索城市名称
- * @return name:first type:string default:-- desc:首字母
- * @return name:city_list type:array default:-- desc:城市列表
- * @return name:city_list.name type:string default:-- desc:名称
- * @return name:city_list.short_name type:string default:-- desc:简称
- */
- public function getAllCity()
- {
- $list = ChinaArea::getAllCity(input('get.title'));
- $this->success('ok',['list'=>$list]);
- }
- }
|