AreaController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Area;
  5. class AreaController extends Base
  6. {
  7. public function tree()
  8. {
  9. $data = Area::getTree();
  10. return $this->json(['data' => $data]);
  11. }
  12. public function abc()
  13. {
  14. $data[0]['letter'] = 'A';
  15. $data[0]['data'] = [];
  16. $ii = 1;
  17. for ($i = 65; $i < 91; $i++) {
  18. $abc = strtoupper(chr($i));
  19. $res = Area::where(['letter' => $abc, 'area_deep' => 2])->select()->toArray();
  20. if (!empty($res)) {
  21. $data[$ii]['letter'] = $abc;
  22. foreach ($res as $key => $vo) {
  23. $data[$ii]['data'][$key]['cityName'] = $vo['area_name'];
  24. $data[$ii]['data'][$key]['keyword'] = $vo['keyword'];
  25. }
  26. $ii++;
  27. }
  28. }
  29. return $this->json(['data' => $data]);
  30. }
  31. public function province()
  32. {
  33. $province = Area::get_province();
  34. foreach ($province as $key => $vo) {
  35. $data[$key]['id'] = $vo['id'];
  36. $data[$key]['level'] = $vo['area_deep'];
  37. $data[$key]['name'] = $vo['area_name'];
  38. }
  39. return $this->json(['data' => $data]);
  40. }
  41. public function child()
  42. {
  43. $errno = 0;
  44. $message = '返回消息';
  45. $pid = (int) input('post.pid', '', 'intval');
  46. $child = Area::get_child($pid);
  47. if (!empty($child)) {
  48. foreach ($child as $key => $vo) {
  49. $data[$key]['id'] = $vo['id'];
  50. $data[$key]['pid'] = $vo['area_parent_id'];
  51. $data[$key]['level'] = $vo['area_deep'];
  52. $data[$key]['name'] = $vo['area_name'];
  53. }
  54. }
  55. return $this->json(['data' => $data]);
  56. }
  57. }