AgentLogPagesCriteria.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * 代理操作日志分页.
  4. *
  5. * @author nj
  6. * @date 2021-02-05 19:17:55
  7. */
  8. namespace App\Repositories\Criterias;
  9. use Illuminate\Database\Eloquent\Builder;
  10. use KZ2\Laravel\Repositories\Contracts\RepositoryInterface;
  11. use KZ2\Laravel\Repositories\Criteria\Criteria;
  12. class AgentLogPagesCriteria extends Criteria
  13. {
  14. private $params = [];
  15. public function __construct($params = [])
  16. {
  17. $this->params = $params;
  18. }
  19. /**
  20. * @param Builder $model
  21. * @param RepositoryInterface $repository
  22. * @return mixed|void
  23. */
  24. public function apply(
  25. $model,
  26. RepositoryInterface $repository
  27. ) {
  28. if (!empty($this->params['agent_uid'])) {
  29. $model = $model->where('agent_uid', $this->params['agent_uid']);
  30. }
  31. if (!empty($this->params['username'])) {
  32. $model = $model->where('username', 'LIKE', '%'. $this->params['username'] .'%');
  33. }
  34. if (!empty($this->params['nick'])) {
  35. $model = $model->where('nick', 'LIKE', '%'. $this->params['nick'] .'%');
  36. }
  37. if (!empty($this->params['subject'])) {
  38. $model = $model->where('subject', 'LIKE', '%'. $this->params['subject'] .'%');
  39. }
  40. if (!empty($this->params['module'])) {
  41. $model = $model->where('module', $this->params['module']);
  42. }
  43. if (!empty($this->params['ip'])) {
  44. $model = $model->where('ip', $this->params['ip']);
  45. }
  46. return $model;
  47. }
  48. }