Area.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\common\model\ChinaArea;
  16. use think\Db;
  17. /**
  18. * @title 地址库
  19. * @controller Area
  20. * @group common
  21. */
  22. class Area extends Base
  23. {
  24. /**
  25. * @title 获取地址库数据
  26. * @desc 获取地址库数据
  27. * @author qc
  28. * @method GET
  29. * @url /api/area/getAreaTree
  30. * @header name:Authorization require:1 desc:Token
  31. * @param name:level type:int require:0 default:3 desc:查询等级(0全部,1精确到省,2精确到市,3精确到县区,4精确到街道)
  32. * @return name:name type:string default:-- desc:名称
  33. * @return name:short_name type:string default:-- desc:简称
  34. * @return name:level type:int default:-- desc:等级(1省,2市,3区,4道)
  35. * @return name:code type:int default:-- desc:编码
  36. * @return name:lng type:string default:-- desc:经度
  37. * @return name:lat type:string default:-- desc:纬度
  38. * @return name:children type:array default:-- desc:下级(数据字段同上)
  39. */
  40. public function getAreaTree()
  41. {
  42. $level = input('level',3);
  43. if($level){
  44. $all_area = ChinaArea::where('level','<=',$level)->select();
  45. }else{
  46. $all_area = ChinaArea::where('level','>',0)->order('level asc,sort desc,id asc')->select();
  47. }
  48. $this->success('ok',['list'=>make_tree($all_area)]);
  49. }
  50. /**
  51. * @title 获取地址库ID获取下一级
  52. * @desc 获取地址库ID获取下一级
  53. * @author qc
  54. * @method GET
  55. * @url /api/area/getAreaChildrenByID
  56. * @header name:Authorization require:1 desc:Token
  57. * @param name:id type:int require:0 default:0 desc:数据表地址记录id
  58. * @return name:name type:string default:-- desc:名称
  59. * @return name:short_name type:string default:-- desc:简称
  60. * @return name:level type:int default:-- desc:等级(1省,2市,3区,4道)
  61. * @return name:code type:int default:-- desc:编码
  62. * @return name:lng type:string default:-- desc:经度
  63. * @return name:lat type:string default:-- desc:纬度
  64. * @return name:children type:array default:-- desc:下级(数据字段同上)
  65. */
  66. public function getAreaChildrenByID()
  67. {
  68. $id = input('id');
  69. $list = ChinaArea::where('pid',$id)->select()->toArray();
  70. $this->success('ok',['list'=>$list]);
  71. }
  72. /**
  73. * @title 获取市级地址
  74. * @desc 获取市级地址
  75. * @author qc
  76. * @method GET
  77. * @url /api/area/getCityByName
  78. * @header name:Authorization require:1 desc:Token
  79. * @param name:name type:string require:0 default:0 desc:市名(或拼音)模糊查询(不传查全部)
  80. * @return name:name type:string default:-- desc:名称
  81. * @return name:short_name type:string default:-- desc:简称
  82. */
  83. public function getCityByName()
  84. {
  85. $where = [];
  86. $where[] = ['level','=',2];
  87. if(input('name')) $where[] = ['name|pinyin','like','%'.input('name').'%'];
  88. $all_city = ChinaArea::field('id,name,short_name,first')->where($where)->order('sort desc,id asc')->select();
  89. $this->success('ok',['list'=>$all_city]);
  90. }
  91. /**
  92. * @title 首字母分组获取地级市
  93. * @desc 首字母分组获取地级市
  94. * @author qc
  95. * @method GET
  96. * @url /api/area/getAllCity
  97. * @header name:Authorization require:1 desc:Token
  98. * @return name:first type:string default:-- desc:首字母
  99. * @return name:city_list type:array default:-- desc:城市列表
  100. * @return name:city_list.name type:string default:-- desc:名称
  101. * @return name:city_list.short_name type:string default:-- desc:简称
  102. */
  103. public function getAllCity()
  104. {
  105. $list = ChinaArea::getAllCity();
  106. $this->success('ok',['list'=>$list]);
  107. }
  108. }