Base.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\BaseService;
  5. use app\service\EnterprisesService;
  6. use app\validate\getListByqydm;
  7. use app\validate\Id;
  8. use app\validate\Page;
  9. use app\validate\Qydm;
  10. use think\db\exception\DataNotFoundException;
  11. use think\db\exception\DbException;
  12. use think\db\exception\ModelNotFoundException;
  13. use think\exception\ValidateException;
  14. use think\response\Json;
  15. use think\annotation\Route;
  16. use think\annotation\route\Middleware;
  17. use hg\apidoc\annotation as Apidoc;
  18. /**
  19. * @Apidoc\Title("基地信息")
  20. * @Apidoc\Group("基地")
  21. * @Apidoc\Sort (7)
  22. */
  23. class Base extends BaseController
  24. {
  25. protected $middleware = [
  26. 'jwt',
  27. ];
  28. use ResponseJson;
  29. /**
  30. * @Apidoc\Title("通过企业代码查基地信息")
  31. * @Apidoc\Tag("基地")
  32. * @Apidoc\Method ("GET")
  33. * @Apidoc\Author ("郑雪瑞")
  34. * @Route("getBaseListByQydm",method="GET")
  35. * @Middleware({"jwt"})
  36. */
  37. public function getBaseListByQydm():Json
  38. {
  39. $page=$this->request->get();
  40. try{
  41. validate(getListByqydm::class)->check($page);
  42. }catch(ValidateException $e){
  43. $this->JsonError($e->getError());
  44. }
  45. return $this->JsonSucess(BaseService::getBaseInfoByQydm($page,$page["qydm"])) ;
  46. }
  47. /**
  48. * @Apidoc\Title("通过ID查基地信息")
  49. * @Apidoc\Tag("基地")
  50. * @Apidoc\Method ("GET")
  51. * @Apidoc\Author ("郑雪瑞")
  52. * @Route("getBaseInfoById",method="GET")
  53. * @Middleware({"jwt"})
  54. */
  55. public function getBaseInfoById():Json
  56. {
  57. $id=$this->request->get();
  58. try{
  59. validate(Id::class)->check($id);
  60. }catch(ValidateException $e){
  61. $this->JsonError($e->getError());
  62. }
  63. return $this->JsonSucess(BaseService::getBaseInfoById($id["id"])) ;
  64. }
  65. /**
  66. * @Apidoc\Title("删除基地信息")
  67. * @Apidoc\Tag("基地")
  68. * @Apidoc\Method ("POST")
  69. * @Apidoc\Author ("郑雪瑞")
  70. * @Route("delBaseInfoById",method="POST")
  71. * @Middleware({"jwt"})
  72. */
  73. public function delBaseInfoById():Json
  74. {
  75. $id = $this->request->post();
  76. try {
  77. validate(Id::class)->check($id);
  78. } catch (ValidateException $e) {
  79. $this->JsonError($e->getError());
  80. }
  81. try {
  82. return $this->JsonSucess(BaseService::delBase($id["id"]));
  83. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  84. return $this->JsonError($dbE);
  85. }
  86. }
  87. /**
  88. * @Apidoc\Title("通过ID更新基地信息")
  89. * @Apidoc\Tag("基地")
  90. * @Apidoc\Method ("POST")
  91. * @Apidoc\Author ("郑雪瑞")
  92. * @Route("updateBaseById",method="POST")
  93. * @Middleware({"jwt"})
  94. */
  95. public function updateBaseById():Json
  96. {
  97. $info= $this->request->post();
  98. try {
  99. validate(Id::class)->check($info);
  100. }catch (ValidateException $e){
  101. $this->JsonError($e->getError());
  102. }
  103. return $this->JsonSucess(BaseService::editBaseInfo($info,$info["id"]));
  104. }
  105. /**
  106. * @Apidoc\Title("添加基地信息")
  107. * @Apidoc\Tag("基地")
  108. * @Apidoc\Method ("POST")
  109. * @Apidoc\Author ("郑雪瑞")
  110. * @Route("addBaseInfo",method="POST")
  111. * @Middleware({"jwt"})
  112. */
  113. public function addBaseInfo():Json
  114. {
  115. $info= $this->request->post();
  116. try {
  117. validate(\app\validate\Base::class)->check($info);
  118. }catch (ValidateException $e){
  119. $this->JsonError($e->getError());
  120. }
  121. return $this->JsonSucess(BaseService::addBase($info));
  122. }
  123. }