Pesticide.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\PesticideListService;
  5. use app\validate\getListByqydm;
  6. use app\validate\Id;
  7. use app\validate\PesticideList;
  8. use app\validate\Page;
  9. use think\annotation\Route;
  10. use think\annotation\route\Middleware;
  11. use hg\apidoc\annotation as Apidoc;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\DbException;
  14. use think\db\exception\ModelNotFoundException;
  15. use think\exception\ValidateException;
  16. use think\response\Json;
  17. /**
  18. * @Apidoc\Title("豇豆农药经常检出农药清单和禁限用农药名录发放张贴情况")
  19. * @Apidoc\Group("豇豆农药经常检出农药清单和禁限用农药名录发放张贴情况")
  20. * @Apidoc\Sort(12)
  21. */
  22. class Pesticide extends BaseController
  23. {
  24. protected $middleware = [
  25. 'jwt',
  26. ];
  27. use ResponseJson;
  28. /**
  29. * @Apidoc\Title("经常检出农药清单和禁限用农药名录发放张贴情况列表")
  30. * @Apidoc\Tag("经常检出农药清单和禁限用农药名录发放张贴情况列表")
  31. * @Apidoc\Method ("GET")
  32. * @Apidoc\Author ("yang")
  33. * @Route("getPesticideList",method="GET")
  34. * @Middleware({"jwt"})
  35. */
  36. public function getPesticide():Json{
  37. $page = $this->request->get();
  38. try {
  39. validate(Page::class)->check($page);
  40. }catch (ValidateException $e){
  41. $page["page"]=1;
  42. $page["size"] = 10;
  43. }
  44. try {
  45. return $this->JsonSucess(PesticideListService::getPesticideList($page, getXzqdmSub()));
  46. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  47. return $this->JsonError($dbE);
  48. }
  49. }
  50. /**
  51. * @Apidoc\Author("yang")
  52. * @throws ModelNotFoundException
  53. * @throws DataNotFoundException
  54. * @throws DbException
  55. * @Apidoc\Title("添加农药清单和禁限用农药")
  56. * @Apidoc\Tag("添加")
  57. * @Apidoc\Method ("POST")
  58. * @Route("/addPesticide",method="POST")
  59. * @Middleware({"jwt"})
  60. */
  61. public function addPesticide(): Json
  62. {
  63. $data = $this->request->post();
  64. try {
  65. validate(Pesticide::class)->check($data);
  66. $data['creation_time'] = date('Y-m-d h:i:s', time());
  67. $result = PesticideListService::addPesticideList($data);
  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("yang")
  78. * @throws ModelNotFoundException
  79. * @throws DataNotFoundException
  80. * @throws DbException
  81. * @Apidoc\Title("修改农药清单和禁限用农药")
  82. * @Apidoc\Tag("修改")
  83. * @Apidoc\Method ("POST")
  84. * @Route("/editpesticide",method="POST")
  85. * @Middleware({"jwt"})
  86. */
  87. //修改
  88. public function editPesticideById(): Json
  89. {
  90. $data= $this->request->get();
  91. try {
  92. validate(Id::class)->check($data);
  93. }catch (ValidateException $e){
  94. $this->JsonError($e->getError());
  95. }
  96. try {
  97. return $this->JsonSucess(PesticideListService::editPesticideInfo($data, $data["id"]));
  98. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  99. return $this->JsonError($dbE);
  100. }
  101. }
  102. /**
  103. * @Apidoc\Author("yang")
  104. * @throws ModelNotFoundException
  105. * @throws DataNotFoundException
  106. * @throws DbException
  107. * @Apidoc\Title("删除农药清单和禁限用农药")
  108. * @Apidoc\Tag("删除")
  109. * @Apidoc\Method ("Post")
  110. * @Route("/deletepesticide",method="Post")
  111. * @Middleware({"jwt"})
  112. */
  113. //删除
  114. public function deletePesticideById(): Json{
  115. $id=$this->request->post();
  116. try {
  117. validate(Id::class)->check($id);
  118. $result = PesticideListService::deletePesticide($id);
  119. if (!$result){
  120. return $this->JsonError(1002);
  121. }
  122. }catch (ValidateException $e){
  123. return $this->JsonError($e->getError(),0);
  124. }
  125. return $this->JsonResponse(200,"success","");
  126. }
  127. }