123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace app\controller;
- use app\BaseController;
- use app\service\StatsticsService;
- use app\validate\Id;
- use think\annotation\Route;
- use think\annotation\route\Middleware;
- use hg\apidoc\annotation as Apidoc;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\exception\ValidateException;
- use think\response\Json;
- /**
- * @Apidoc\Title("基地统计")
- * @Apidoc\Group("基地统计信息")
- * @Apidoc\Sort (15)
- */
- class Statstics extends BaseController
- {
- protected $middleware = [
- 'jwt',
- ];
- use ResponseJson;
- /**
- * @Apidoc\Title("添加基地统计")
- * @Apidoc\Tag("添加基地统计")
- * @Apidoc\Method ("POST")
- * @Apidoc\Author ("ruicu")
- * @Route("addstatic",method="POST")
- */
- public function addStatic(): Json
- {
- $info = $this->request->post();
- try {
- validate(Statistic::class)->check($info);
- $info['creation_time'] = date('Y-m-d h:i:s', time());
- $result = StatsticsService::addStatistic($info);
- if (!$result){
- return $this->JsonError(1002);
- }
- }catch (ValidateException $e){
- return $this->JsonError($e->getError(),0);
- }
- return $this->JsonResponse(200,"success","");
- }
- /**
- * @Apidoc\Author("ruicu")
- * @throws ModelNotFoundException
- * @throws DataNotFoundException
- * @throws DbException
- * @Apidoc\Title("删除基地统计信息")
- * @Apidoc\Tag("基地统计信息")
- * @Apidoc\Method ("Post")
- * @Route("/delstatic",method="Post")
- * @Middleware({"jwt"})
- */
- //删除
- public function del(): Json{
- $id=$this->request->post();
- try {
- validate(Id::class)->check($id);
- $result = StatsticsService::delStatistic($id);
- if (!$result){
- return $this->JsonError(1002);
- }
- }catch (ValidateException $e){
- return $this->JsonError($e->getError(),0);
- }
- return $this->JsonResponse(200,"success","");
- }
- /**
- * @Apidoc\Author("ruicu")
- * @throws ModelNotFoundException
- * @throws DataNotFoundException
- * @throws DbException
- * @Apidoc\Title("修改基地统计信息")
- * @Apidoc\Tag("修改基地统计信息")
- * @Apidoc\Method ("Get")
- * @Route("/editstatic",method="Get")
- * @Middleware({"jwt"})
- */
- //修改
- public function updateStaticById(): Json
- {
- $info= $this->request->get();
- try {
- validate(Id::class)->check($info);
- }catch (ValidateException $e){
- $this->JsonError($e->getError());
- }
- try {
- return $this->JsonSucess(StatsticsService::editStatisticInfo($info,$info["id"]));
- } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
- return $this->JsonError($dbE);
- }
- }
- }
|