Request.php 789 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\Core;
  4. use think\Exception;
  5. use think\helper\Macroable;
  6. /**
  7. * @property string $adminID 管理员ID
  8. * @property string $userID 用户ID
  9. * @property string $token 令牌
  10. */
  11. class Request extends \think\Request
  12. {
  13. use Macroable;
  14. /**
  15. * 获取分页参数
  16. *
  17. * @return array{page: int, list_rows: int} 分页参数
  18. */
  19. public function pageAndLimit(): array
  20. {
  21. $page = $this->get('page/d', 1);
  22. $limit = $this->get('limit/d', $this->get('per_page/d', 10));
  23. throw_if($page < 1, Exception::class, '页码不能小于1');
  24. throw_if($limit < 1 || $limit > 200, Exception::class, '每页数量必须在1-200之间');
  25. return ['page' => $page, 'list_rows' => $limit];
  26. }
  27. }