Banner.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\ApiController;
  4. use app\common\validate\IDMustBePositiveInt;
  5. use app\common\model\Banner as BannerModel;
  6. use app\http\IResponse;
  7. use Lettered\Support\Exceptions\TokenException;
  8. class Banner extends ApiController
  9. {
  10. /**
  11. * 获取Banner信息
  12. *
  13. * @url /banner/:id
  14. * @http GET
  15. * @param $id
  16. *
  17. * @return mixed
  18. * @throws \Lettered\Support\Exceptions\EvidentException
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. */
  23. public function getBannerByID($id)
  24. {
  25. // 输入参数检查
  26. (new IDMustBePositiveInt())->valid();
  27. // throw new TokenException();
  28. // 获取ID数据
  29. $banner = BannerModel::getBannerById($id);
  30. if (!$banner) {
  31. // 错误返回
  32. return $this->ApiJson(-1,"请求数据不存在");
  33. }
  34. return $this->ApiJson(0,'OK!', $banner);
  35. }
  36. }