ManagerLogPagesCriteria.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * 管理日志后台规则.
  4. *
  5. * @author jim <jim458734573@gmail.com>
  6. * @date 2020-02-05 19:17:55
  7. */
  8. declare(strict_types=1);
  9. namespace App\Repositories\Criterias;
  10. use Hyperf\Database\Query\Builder;
  11. use KZ2\Repositories\Contracts\RepositoryInterface;
  12. use KZ2\Repositories\Criteria\Criteria;
  13. class ManagerLogPagesCriteria extends Criteria
  14. {
  15. private $params = [];
  16. public function __construct($params = [])
  17. {
  18. $this->params = $params;
  19. }
  20. /**
  21. * @param Builder $model
  22. * @param RepositoryInterface $repository
  23. * @return mixed|void
  24. */
  25. public function apply(
  26. $model,
  27. RepositoryInterface $repository
  28. ) {
  29. if (!empty($this->params['manager_id'])) {
  30. $model = $model->where('manager_id', $this->params['manager_id']);
  31. }
  32. if (!empty($this->params['username'])) {
  33. $model = $model->where('username', 'LIKE', '%'. $this->params['username'] .'%');
  34. }
  35. if (!empty($this->params['nick'])) {
  36. $model = $model->where('nick', 'LIKE', '%'. $this->params['nick'] .'%');
  37. }
  38. if (!empty($this->params['subject'])) {
  39. $model = $model->where('subject', 'LIKE', '%'. $this->params['subject'] .'%');
  40. }
  41. if (!empty($this->params['module'])) {
  42. $model = $model->where('module', $this->params['module']);
  43. }
  44. if (!empty($this->params['ip'])) {
  45. $model = $model->where('ip', $this->params['ip']);
  46. }
  47. return $model;
  48. }
  49. }