Address.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shopapi\controller;
  11. use app\model\system\Address as AddressModel;
  12. /**
  13. * 地址管理
  14. * @author Administrator
  15. *
  16. */
  17. class Address extends BaseApi
  18. {
  19. /**
  20. * 基础信息
  21. */
  22. public function info()
  23. {
  24. $id = $this->params[ 'id' ];
  25. $address = new AddressModel();
  26. $info = $address->getAreaInfo($id);
  27. return $this->response($info);
  28. }
  29. /**
  30. * 列表信息
  31. */
  32. public function lists()
  33. {
  34. $pid = isset($this->params[ 'pid' ]) ? $this->params[ 'pid' ] : 0;
  35. $address = new AddressModel();
  36. $list = $address->getAreas($pid);
  37. return $this->response($list);
  38. }
  39. /**
  40. * 树状结构信息
  41. */
  42. public function tree()
  43. {
  44. $id = $this->params[ 'id' ];
  45. $address = new AddressModel();
  46. $tree = $address->getAreas($id);
  47. return $this->response($tree);
  48. }
  49. /**
  50. * 获取全部城市列表
  51. */
  52. public function city()
  53. {
  54. $address = new AddressModel();
  55. $data = $address->getAreaList([ [ 'level', '=', 2 ], [ 'status', '=', 1 ] ], 'id,shortname as title', 'sort asc');
  56. return $this->response($data);
  57. }
  58. /**
  59. * 根据城市名称获取城市
  60. */
  61. public function cityByName()
  62. {
  63. $name = $this->params[ 'city' ] ?? '';
  64. $address = new AddressModel();
  65. $data = $address->getAreasInfo([ [ 'name', 'like', "%{$name}%" ], [ 'level', '=', 2 ], [ 'status', '=', 1 ] ], 'id,shortname as title');
  66. return $this->response($data);
  67. }
  68. }