InputUse.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\InputuseService;
  5. use app\validate\Id;
  6. use app\validate\Page;
  7. use think\console\Input;
  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("inputuse")
  19. * @Apidoc\Sort(8)
  20. */
  21. class InputUse extends BaseController
  22. {
  23. use ResponseJson;
  24. /**
  25. * @Apidoc\Author("yang")
  26. * @Apidoc\Title("添加投入品使用")
  27. * @Apidoc\Tag("投入品使用")
  28. * @Apidoc\Method ("POST")
  29. * @Route("/addInputuse",method="POST")
  30. * @Middleware({"jwt"})
  31. */
  32. public function addInputuse(): Json
  33. {
  34. $inputInfo = $this->request->post();
  35. $inputInfo['creation_time'] = date('Y-m-d h:i:s', time());
  36. try {
  37. validate(\app\validate\Inputuse::class)->check($inputInfo);
  38. }catch (ValidateException $e){
  39. return $this->JsonError($e->getError());
  40. }
  41. return $this->JsonSucess(InputuseService::addInputUse($inputInfo));
  42. }
  43. /**
  44. * @Apidoc\Author("yang")
  45. * @throws ModelNotFoundException
  46. * @throws DataNotFoundException
  47. * @throws DbException
  48. * @Apidoc\Title("删除投入品使用")
  49. * @Apidoc\Tag("投入品使用")
  50. * @Apidoc\Method ("POST")
  51. * @Route("/delInputuse",method="POST")
  52. * @Middleware({"jwt"})
  53. */
  54. public function delInputuse(): Json
  55. {
  56. $id = $this->request->post();
  57. try {
  58. validate(Id::class)->check($id);
  59. } catch (ValidateException $e) {
  60. return $this->JsonError($e->getError(), 0);
  61. }
  62. return $this->JsonSucess(InputuseService::delInputUse($id["id"]));
  63. }
  64. /**
  65. * @Apidoc\Author("yang")
  66. * @throws ModelNotFoundException
  67. * @throws DataNotFoundException
  68. * @throws DbException
  69. * @Apidoc\Title("修改投入品使用")
  70. * @Apidoc\Tag("修改投入品使用")
  71. * @Apidoc\Method ("POST")
  72. * @Route("/editInputuse",method="POST")
  73. * @Middleware({"jwt"})
  74. */
  75. public function editInputuse(): Json
  76. {
  77. $info= $this->request->post();
  78. $info['last_update_time'] = date('Y-m-d h:i:s', time());
  79. try {
  80. validate(Id::class)->check($info);
  81. }catch (ValidateException $e){
  82. $this->JsonError($e->getError());
  83. }
  84. return $this->JsonSucess(InputuseService::editInputUse($info,$info["id"]));
  85. }
  86. /**
  87. * @Apidoc\Author("yang")
  88. * @throws ModelNotFoundException
  89. * @throws DataNotFoundException
  90. * @throws DbException
  91. * @Apidoc\Title("获取投入品使用记录")
  92. * @Apidoc\Tag("投入品")
  93. * @Apidoc\Method ("POST")
  94. * @Route("/getInputUseList",method="POST")
  95. * @Middleware({"jwt"})
  96. */
  97. public function getInputUseList(): Json
  98. {
  99. $page = $this->request->get();
  100. try {
  101. validate(Page::class)->check($page);
  102. }catch (ValidateException $e){
  103. return $this->JsonError($e->getError());
  104. }
  105. return $this->JsonSucess(InputuseService::getInputUseList($page,getQydm()));
  106. }
  107. /**
  108. * @Apidoc\Author("yang")
  109. * @throws ModelNotFoundException
  110. * @throws DataNotFoundException
  111. * @throws DbException
  112. * @Apidoc\Title("获取投入品使用详情")
  113. * @Apidoc\Tag("投入品")
  114. * @Apidoc\Method ("GET")
  115. * @Route("/getInputUseById",method="GET")
  116. * @Middleware({"jwt"})
  117. */
  118. public function getInputUseById(): Json
  119. {
  120. $id = $this->request->get();
  121. try {
  122. validate(Id::class)->check($id);
  123. }catch (ValidateException $e){
  124. return $this->JsonError($e->getError());
  125. }
  126. return $this->JsonSucess(InputuseService::getInputUseById($id["id"]));
  127. }
  128. }