Product.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\validate\EditProduct;
  5. use app\validate\Id;
  6. use app\validate\Page;
  7. use app\service\ProductService;
  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("产品")
  19. * @Apidoc\Sort (6)
  20. */
  21. class Product extends BaseController
  22. {
  23. protected $middleware = [
  24. 'jwt',
  25. ];
  26. use ResponseJson;
  27. /**
  28. * @Apidoc\Title("产品列表")
  29. * @Apidoc\Tag("产品")
  30. * @Apidoc\Method ("GET")
  31. * @Apidoc\Author ("刘庆")
  32. * @Route("getProductList",method="GET")
  33. * @Middleware({"jwt"})
  34. */
  35. public function getProductList(): Json
  36. {
  37. $page = $this->request->get();
  38. try {
  39. validate(Page::class)->check($page);
  40. }catch (ValidateException $e){
  41. return $this->JsonError($e->getError());
  42. }
  43. return $this->JsonSucess(ProductService::getProductList($page,getQydm()));
  44. }
  45. /**
  46. * @Apidoc\Title("产品列表")
  47. * @Apidoc\Tag("产品")
  48. * @Apidoc\Method ("GET")
  49. * @Apidoc\Author ("刘庆")
  50. * @Route("getProductListGOV",method="GET")
  51. * @Middleware({"jwt"})
  52. */
  53. public function getProductListGOV(): Json
  54. {
  55. $page = $this->request->get();
  56. try {
  57. validate(Page::class)->check($page);
  58. }catch (ValidateException $e){
  59. return $this->JsonError($e->getError());
  60. }
  61. return $this->JsonSucess(ProductService::getProductList($page,$page["qydm"]));
  62. }
  63. /**
  64. * @Apidoc\Title("产品信息ByID")
  65. * @Apidoc\Tag("产品")
  66. * @Apidoc\Method ("GET")
  67. * @Apidoc\Author ("刘庆")
  68. * @Route("getProductInfo",method="GET")
  69. * @Middleware({"jwt"})
  70. */
  71. public function getProductInfo(): Json
  72. {
  73. $id = $this->request->get();
  74. try {
  75. validate(Id::class)->check($id);
  76. }catch (ValidateException $e){
  77. return $this->JsonError($e->getError());
  78. }
  79. return $this->JsonSucess(ProductService::getProductInfoById($id["id"]));
  80. }
  81. /**
  82. * @Apidoc\Title("添加产品信息")
  83. * @Apidoc\Tag("产品")
  84. * @Apidoc\Method ("POST")
  85. * @Apidoc\Author ("刘庆")
  86. * @Route("addProduct",method="POST")
  87. * @Middleware({"jwt"})
  88. */
  89. public function addProduct(): Json
  90. {
  91. $info = $this->request->post();
  92. try {
  93. validate(\app\validate\Product::class)->check($info);
  94. } catch (ValidateException $e) {
  95. $this->JsonError($e->getError());
  96. }
  97. return $this->JsonSucess(ProductService::addProduct($info));
  98. }
  99. /**
  100. * @Apidoc\Title("更新产品信息")
  101. * @Apidoc\Tag("产品")
  102. * @Apidoc\Method ("POST")
  103. * @Apidoc\Author ("刘庆")
  104. * @Route("editProduct",method="POST")
  105. * @Middleware({"jwt"})
  106. */
  107. public function editProduct(): Json
  108. {
  109. $info = $this->request->post();
  110. try {
  111. validate(EditProduct::class)->check($info);
  112. } catch (ValidateException $e) {
  113. $this->JsonError($e->getError());
  114. }
  115. return $this->JsonSucess(ProductService::editProduct($info,$info["id"]));
  116. }
  117. /**
  118. * @Apidoc\Title("删除产品信息")
  119. * @Apidoc\Tag("产品")
  120. * @Apidoc\Method ("POST")
  121. * @Apidoc\Author ("刘庆")
  122. * @Route("delProduct",method="POST")
  123. * @Middleware({"jwt"})
  124. */
  125. public function delProduct(): Json
  126. {
  127. $id = $this->request->post();
  128. try {
  129. validate(Id::class)->check($id);
  130. } catch (ValidateException $e) {
  131. $this->JsonError($e->getError());
  132. }
  133. return $this->JsonSucess(ProductService::delProduct($id["id"]));
  134. }
  135. /**
  136. * @Apidoc\Title("获取产品列表包含批次号")
  137. * @Apidoc\Tag("产品")
  138. * @Apidoc\Method ("get")
  139. * @Apidoc\Author ("ihavoc")
  140. * @Route("getProductListIsPch",method="get")
  141. * @Middleware({"jwt"})
  142. */
  143. public function getProductListIsPch(): Json
  144. {
  145. return $this->JsonSucess(ProductService::getProductListIsPch(getQydm()));
  146. }
  147. }