123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace app\controller;
- use app\BaseController;
- use app\service\PesticideListService;
- use app\validate\getListByqydm;
- use app\validate\Id;
- use app\validate\PesticideList;
- use app\validate\Page;
- 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(12)
- */
- class Pesticide extends BaseController
- {
- protected $middleware = [
- 'jwt',
- ];
- use ResponseJson;
- /**
- * @Apidoc\Title("经常检出农药清单和禁限用农药名录发放张贴情况列表")
- * @Apidoc\Tag("经常检出农药清单和禁限用农药名录发放张贴情况列表")
- * @Apidoc\Method ("GET")
- * @Apidoc\Author ("yang")
- * @Route("getPesticideList",method="GET")
- * @Middleware({"jwt"})
- */
- public function getPesticide():Json{
- $page = $this->request->get();
- try {
- validate(Page::class)->check($page);
- }catch (ValidateException $e){
- $page["page"]=1;
- $page["size"] = 10;
- }
- try {
- return $this->JsonSucess(PesticideListService::getPesticideList($page, getXzqdmSub()));
- } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
- return $this->JsonError($dbE);
- }
- }
- /**
- * @Apidoc\Author("yang")
- * @throws ModelNotFoundException
- * @throws DataNotFoundException
- * @throws DbException
- * @Apidoc\Title("添加农药清单和禁限用农药")
- * @Apidoc\Tag("添加")
- * @Apidoc\Method ("POST")
- * @Route("/addPesticide",method="POST")
- * @Middleware({"jwt"})
- */
- public function addPesticide(): Json
- {
- $data = $this->request->post();
- try {
- validate(Pesticide::class)->check($data);
- $data['creation_time'] = date('Y-m-d h:i:s', time());
- $result = PesticideListService::addPesticideList($data);
- if (!$result){
- return $this->JsonError(1002);
- }
- }catch (ValidateException $e){
- return $this->JsonError($e->getError(),0);
- }
- return $this->JsonResponse(200,"success","");
- }
- /**
- * @Apidoc\Author("yang")
- * @throws ModelNotFoundException
- * @throws DataNotFoundException
- * @throws DbException
- * @Apidoc\Title("修改农药清单和禁限用农药")
- * @Apidoc\Tag("修改")
- * @Apidoc\Method ("POST")
- * @Route("/editpesticide",method="POST")
- * @Middleware({"jwt"})
- */
- //修改
- public function editPesticideById(): Json
- {
- $data= $this->request->get();
- try {
- validate(Id::class)->check($data);
- }catch (ValidateException $e){
- $this->JsonError($e->getError());
- }
- try {
- return $this->JsonSucess(PesticideListService::editPesticideInfo($data, $data["id"]));
- } catch (DataNotFoundException|ModelNotFoundException|DbException $dbE) {
- return $this->JsonError($dbE);
- }
- }
- /**
- * @Apidoc\Author("yang")
- * @throws ModelNotFoundException
- * @throws DataNotFoundException
- * @throws DbException
- * @Apidoc\Title("删除农药清单和禁限用农药")
- * @Apidoc\Tag("删除")
- * @Apidoc\Method ("Post")
- * @Route("/deletepesticide",method="Post")
- * @Middleware({"jwt"})
- */
- //删除
- public function deletePesticideById(): Json{
- $id=$this->request->post();
- try {
- validate(Id::class)->check($id);
- $result = PesticideListService::deletePesticide($id);
- if (!$result){
- return $this->JsonError(1002);
- }
- }catch (ValidateException $e){
- return $this->JsonError($e->getError(),0);
- }
- return $this->JsonResponse(200,"success","");
- }
- }
|