Statstics.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\service\StatsticsService;
  5. use app\validate\Id;
  6. use think\annotation\Route;
  7. use think\annotation\route\Middleware;
  8. use hg\apidoc\annotation as Apidoc;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\exception\ValidateException;
  13. use think\response\Json;
  14. /**
  15. * @Apidoc\Title("基地统计")
  16. * @Apidoc\Group("基地统计信息")
  17. * @Apidoc\Sort (15)
  18. */
  19. class Statstics extends BaseController
  20. {
  21. protected $middleware = [
  22. 'jwt',
  23. ];
  24. use ResponseJson;
  25. /**
  26. * @Apidoc\Title("添加基地统计")
  27. * @Apidoc\Tag("添加基地统计")
  28. * @Apidoc\Method ("POST")
  29. * @Apidoc\Author ("ruicu")
  30. * @Route("addstatic",method="POST")
  31. */
  32. public function addStatic(): Json
  33. {
  34. $info = $this->request->post();
  35. try {
  36. validate(Statistic::class)->check($info);
  37. $info['creation_time'] = date('Y-m-d h:i:s', time());
  38. $result = StatsticsService::addStatistic($info);
  39. if (!$result){
  40. return $this->JsonError(1002);
  41. }
  42. }catch (ValidateException $e){
  43. return $this->JsonError($e->getError(),0);
  44. }
  45. return $this->JsonResponse(200,"success","");
  46. }
  47. /**
  48. * @Apidoc\Author("ruicu")
  49. * @throws ModelNotFoundException
  50. * @throws DataNotFoundException
  51. * @throws DbException
  52. * @Apidoc\Title("删除基地统计信息")
  53. * @Apidoc\Tag("基地统计信息")
  54. * @Apidoc\Method ("Post")
  55. * @Route("/delstatic",method="Post")
  56. * @Middleware({"jwt"})
  57. */
  58. //删除
  59. public function del(): Json{
  60. $id=$this->request->post();
  61. try {
  62. validate(Id::class)->check($id);
  63. $result = StatsticsService::delStatistic($id);
  64. if (!$result){
  65. return $this->JsonError(1002);
  66. }
  67. }catch (ValidateException $e){
  68. return $this->JsonError($e->getError(),0);
  69. }
  70. return $this->JsonResponse(200,"success","");
  71. }
  72. /**
  73. * @Apidoc\Author("ruicu")
  74. * @throws ModelNotFoundException
  75. * @throws DataNotFoundException
  76. * @throws DbException
  77. * @Apidoc\Title("修改基地统计信息")
  78. * @Apidoc\Tag("修改基地统计信息")
  79. * @Apidoc\Method ("Get")
  80. * @Route("/editstatic",method="Get")
  81. * @Middleware({"jwt"})
  82. */
  83. //修改
  84. public function updateStaticById(): Json
  85. {
  86. $info= $this->request->get();
  87. try {
  88. validate(Id::class)->check($info);
  89. }catch (ValidateException $e){
  90. $this->JsonError($e->getError());
  91. }
  92. try {
  93. return $this->JsonSucess(StatsticsService::editStatisticInfo($info,$info["id"]));
  94. } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
  95. return $this->JsonError($dbE);
  96. }
  97. }
  98. }