Input.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\InputService;
  5. use app\validate\getListByqydm;
  6. use app\validate\Id;
  7. use app\validate\InputAdd;
  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 (3)
  22. */
  23. class Input 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 ("yang")
  34. * @Route("getInputList",method="GET")
  35. * @Middleware({"jwt"})
  36. */
  37. public function getInputList():Json{
  38. $page = $this->request->get();
  39. try {
  40. validate(Page::class)->check($page);
  41. }catch (ValidateException $e){
  42. return $this->JsonError($e->getError());
  43. }
  44. return $this->JsonSucess(InputService::getInputList($page,getQydm()));
  45. }
  46. /**
  47. * @Apidoc\Title("投入品信息by ID")
  48. * @Apidoc\Tag("企业")
  49. * @Apidoc\Method ("GET")
  50. * @Apidoc\Author ("yang")
  51. * @Route("getInputInfo",method="GET")
  52. * @Middleware({"jwt"})
  53. */
  54. public function getInputInfoById(): json
  55. {
  56. $id = $this->request->get();
  57. try {
  58. validate(Id::class)->check($id);
  59. }catch (ValidateException $e){
  60. return $this->JsonError($e->getError());
  61. }
  62. return $this->JsonSucess(InputService::getInputById($id["id"]));
  63. }
  64. /**
  65. * @Apidoc\Title("删除投入品信息")
  66. * @Apidoc\Tag("企业")
  67. * @Apidoc\Method ("POST")
  68. * @Apidoc\Author ("wangzhen")
  69. * @Route("delInputById",method="POST")
  70. * @Middleware({"jwt"})
  71. */
  72. public function delInputById():json{
  73. $id= $this->request->POST();
  74. try {
  75. validate(Id::class)->check($id);
  76. }catch (ValidateException $e){
  77. $this->JsonError($e->getError());
  78. }
  79. try {
  80. return $this->JsonSucess(InputService::delInputById($id["id"]));
  81. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  82. return $this->JsonError($dbE);
  83. }
  84. }
  85. /**
  86. * @Apidoc\Title("更新投入品信息")
  87. * @Apidoc\Tag("企业")
  88. * @Apidoc\Method ("POST")
  89. * @Apidoc\Author ("yang")
  90. * @Route("updateInputById",method="POST")
  91. * @Middleware({"jwt"})
  92. */
  93. public function updataInputById():json{
  94. $info= $this->request->POST();
  95. try {
  96. validate(Id::class)->check($info);
  97. }catch (ValidateException $e){
  98. $this->JsonError($e->getError());
  99. }
  100. try {
  101. return $this->JsonSucess(InputService::eidtInputInfo($info,$info["id"]));
  102. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  103. return $this->JsonError($dbE);
  104. }
  105. }
  106. /**
  107. * @Apidoc\Title("添加投入品信息")
  108. * @Apidoc\Tag("企业")
  109. * @Apidoc\Method ("POST")
  110. * @Apidoc\Author ("yang")
  111. * @Route("addInput",method="POST")
  112. * @Middleware({"jwt"})
  113. */
  114. public function addInput():json{
  115. $data = $this->request->post();
  116. try {
  117. validate(InputAdd::class)->check($data);
  118. $data['creation_time'] = date('Y-m-d h:i:s', time());
  119. $result = InputService::addInput($data);
  120. if (!$result){
  121. return $this->JsonError(1002);
  122. }
  123. }catch (ValidateException $e){
  124. return $this->JsonError($e->getError(),0);
  125. }
  126. return $this->JsonResponse(1,"success","");
  127. }
  128. }