Region.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: thinkphp <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\api\controller;
  13. use app\api\model\Region as RegionModel;
  14. /**
  15. * 地区管理
  16. * Class Region
  17. * @package app\api\controller
  18. */
  19. class Region extends Controller
  20. {
  21. /**
  22. * 获取所有地区
  23. * @return array|\think\response\Json
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\DbException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. */
  28. public function all()
  29. {
  30. $list = RegionModel::getCacheAll();
  31. return $this->renderSuccess(compact('list'));
  32. }
  33. /**
  34. * 获取所有地区(树状)
  35. * @return array|\think\response\Json
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function tree()
  41. {
  42. $list = RegionModel::getCacheTree();
  43. return $this->renderSuccess(compact('list'));
  44. }
  45. /**
  46. * 获取区域选项
  47. * @return \think\response\Json
  48. */
  49. public function options()
  50. {
  51. $pid = $this->request->param('pid', 0);
  52. $pid = $pid? (int)$pid : 2069;
  53. $list = RegionModel::getCacheOptions($pid);
  54. return $this->renderSuccess(compact('list'));
  55. }
  56. }