Grid.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\GridService;
  5. use app\validate\GridAdd;
  6. use app\validate\Id;
  7. use app\validate\Page;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\DbException;
  10. use think\db\exception\ModelNotFoundException;
  11. use think\exception\ValidateException;
  12. use think\response\Json;
  13. use think\annotation\Route;
  14. use think\annotation\route\Middleware;
  15. use hg\apidoc\annotation as Apidoc;
  16. /**
  17. * @Apidoc\Title("网格点信息")
  18. * @Apidoc\Group("grid")
  19. * @Apidoc\Sort(6)
  20. */
  21. class Grid extends BaseController
  22. {
  23. use ResponseJson;
  24. //新增方法
  25. /**
  26. * @Apidoc\Author("ruicu")
  27. * @throws ModelNotFoundException
  28. * @throws DataNotFoundException
  29. * @throws DbException
  30. * @Apidoc\Title("添加网格点")
  31. * @Apidoc\Tag("添加网格点")
  32. * @Apidoc\Method ("POST")
  33. * @Route("/addgrid",method="POST")
  34. * @Middleware({"jwt"})
  35. */
  36. public function addGrid(): Json
  37. {
  38. $gridInfo = $this->request->post();
  39. try {
  40. validate(GridAdd::class)->check($gridInfo);
  41. $gridInfo['creation_time'] = date('Y-m-d h:i:s', time());
  42. $result = GridService::addGrid($gridInfo);
  43. if (!$result){
  44. return $this->JsonError(1002);
  45. }
  46. }catch (ValidateException $e){
  47. return $this->JsonError($e->getError(),0);
  48. }
  49. return $this->JsonResponse(200,"success","");
  50. }
  51. /**
  52. * @Apidoc\Author("ruicu")
  53. * @throws ModelNotFoundException
  54. * @throws DataNotFoundException
  55. * @throws DbException
  56. * @Apidoc\Title("删除网格点")
  57. * @Apidoc\Tag("删除网格点")
  58. * @Apidoc\Method ("Post")
  59. * @Route("/delgrid",method="Post")
  60. * @Middleware({"jwt"})
  61. */
  62. //删除
  63. public function del(): Json{
  64. $id=$this->request->post();
  65. try {
  66. validate(Id::class)->check($id);
  67. $result = GridService::delGrid($id);
  68. if (!$result){
  69. return $this->JsonError(1002);
  70. }
  71. }catch (ValidateException $e){
  72. return $this->JsonError($e->getError(),0);
  73. }
  74. return $this->JsonResponse(200,"success","");
  75. }
  76. /**
  77. * @Apidoc\Author("ruicu")
  78. * @throws ModelNotFoundException
  79. * @throws DataNotFoundException
  80. * @throws DbException
  81. * @Apidoc\Title("修改网格点信息")
  82. * @Apidoc\Tag("修改网格点信息")
  83. * @Apidoc\Method ("Get")
  84. * @Route("/editgrid",method="Get")
  85. * @Middleware({"jwt"})
  86. */
  87. //修改
  88. public function updateGridById(): Json
  89. {
  90. $info= $this->request->get();
  91. try {
  92. validate(Id::class)->check($info);
  93. }catch (ValidateException $e){
  94. $this->JsonError($e->getError());
  95. }
  96. try {
  97. return $this->JsonSucess(GridService::editGridInfo($info,$info["id"]));
  98. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  99. return $this->JsonError($dbE);
  100. }
  101. }
  102. /**
  103. * @Apidoc\Author("ruicu")
  104. * @throws ModelNotFoundException
  105. * @throws DataNotFoundException
  106. * @throws DbException
  107. * @Apidoc\Title("查询网格点信息")
  108. * @Apidoc\Tag("查询网格点信息")
  109. * @Apidoc\Method ("Get")
  110. * @Route("/infogrid",method="Get")
  111. * @Middleware({"jwt"})
  112. */
  113. //查询
  114. public function getGridList(): Json
  115. {
  116. $page = $this->request->get();
  117. try {
  118. validate(Page::class)->check($page);
  119. }catch (ValidateException $e){
  120. $page["page"]=1;
  121. $page["size"] = 15;
  122. }
  123. try {
  124. return $this->JsonSucess(GridService::getGridList($page, getXzqdmSub()));
  125. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  126. return $this->JsonError($dbE);
  127. }
  128. }
  129. }