Area.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace catchAdmin\permissions\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\permissions\model\Area as AreaModel;
  7. use catcher\exceptions\FailedException;
  8. class Area extends CatchController
  9. {
  10. protected $areaModel;
  11. public function __construct(AreaModel $areaModel)
  12. {
  13. $this->areaModel = $areaModel;
  14. }
  15. /**
  16. * 列表
  17. * @time 2020年12月15日 16:41
  18. * @param Request $request
  19. */
  20. public function index(Request $request) : \think\Response
  21. {
  22. return CatchResponse::success($this->areaModel->getList());
  23. // return CatchResponse::paginate($this->areaModel->getList());
  24. }
  25. /**
  26. * 保存信息
  27. * @time 2020年12月15日 16:41
  28. * @param Request $request
  29. */
  30. public function save(Request $request) : \think\Response
  31. {
  32. $param=$request->post();
  33. // var_dump($param);
  34. if($param['parent_id']){
  35. $p_info=$this->areaModel->where('id',$param['parent_id'])->find();
  36. $param['province_id']=$p_info['province_id'];
  37. $param['city_id']=$p_info['city_id'];
  38. $param['district_id']=$p_info['district_id'];
  39. }else{
  40. $param['province_id']=$param['city'][0];
  41. $param['city_id']=$param['city'][1];
  42. $param['district_id']=$param['city'][2];
  43. }
  44. return CatchResponse::success($this->areaModel->storeBy($param));
  45. }
  46. /**
  47. * 读取
  48. * @time 2020年12月15日 16:41
  49. * @param $id
  50. */
  51. public function read($id) : \think\Response
  52. {
  53. return CatchResponse::success($this->areaModel->findBy($id));
  54. }
  55. /**
  56. * 更新
  57. * @time 2020年12月15日 16:41
  58. * @param Request $request
  59. * @param $id
  60. */
  61. public function update(Request $request, $id) : \think\Response
  62. {
  63. $param=$request->post();
  64. // var_dump($param);
  65. if($param['parent_id']){
  66. $p_info=$this->areaModel->where('id',$param['parent_id'])->find();
  67. $param['province_id']=$p_info['province_id'];
  68. $param['city_id']=$p_info['city_id'];
  69. $param['district_id']=$p_info['district_id'];
  70. }else{
  71. $param['province_id']=$param['city'][0];
  72. $param['city_id']=$param['city'][1];
  73. $param['district_id']=$param['city'][2];
  74. }
  75. //var_dump($param);
  76. return CatchResponse::success($this->areaModel->updateBy($id, $param));
  77. }
  78. /**
  79. * 删除
  80. * @time 2020年12月15日 16:41
  81. * @param $id
  82. */
  83. public function delete($id) : \think\Response
  84. {
  85. if ($this->areaModel->where('parent_id', $id)->find()) {
  86. throw new FailedException('存在子区域,无法删除');
  87. }
  88. return CatchResponse::success($this->areaModel->deleteBy($id));
  89. }
  90. /**
  91. * 获取下属区域
  92. */
  93. public function getDistrictChildrenArea(Request $request)
  94. {
  95. $data = $this->areaModel->getDistrictChildrenArea($request->post('id'));
  96. return CatchResponse::success($data);
  97. }
  98. /**
  99. * 获取区域树组件数据
  100. */
  101. public function getAreaTreeData()
  102. {
  103. return CatchResponse::success($this->areaModel->getAreaTreeData());
  104. }
  105. /**
  106. * 根据城市获取区域树组件数据
  107. */
  108. public function getAreaTreeDataByCity($cityid)
  109. {
  110. return CatchResponse::success($this->areaModel->getAreaTreeDataByCity($cityid));
  111. }
  112. /**
  113. * 顶部新增按钮
  114. */
  115. public function topAddButton()
  116. {
  117. }
  118. }