ChangeLogCriteria.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Repositories\Criterias;
  3. use KZ2\Repositories\Contracts\RepositoryInterface;
  4. use KZ2\Repositories\Criteria\Criteria;
  5. class ChangeLogCriteria extends Criteria
  6. {
  7. private $params = [];
  8. public function __construct($arams)
  9. {
  10. $this->params = $arams;
  11. }
  12. public function apply($model, RepositoryInterface $repository)
  13. {
  14. if (!empty($this->params['type'])) {
  15. $model = $model->where('type', $this->params['type']);
  16. }
  17. if (!empty($this->params['user_uid'])) {
  18. $model = $model->where('user_uid', $this->params['user_uid']);
  19. }
  20. if (!empty($this->params['way'])) {
  21. $model = $model->where('way', $this->params['way']);
  22. }
  23. if (!empty($this->params['user_uid'])) {
  24. $model = $model->where('user_uid', $this->params['user_uid']);
  25. }
  26. if (!empty($this->params['currency_type'])) {
  27. $model = $model->where('currency_type', $this->params['currency_type']);
  28. }
  29. if (!empty($this->params['username'])) {
  30. $model = $model->whereHas('oneUser', function ($query) {
  31. $query->where('nick', 'like', '%'. $this->params['username'] .'%');
  32. });
  33. }
  34. return $model;
  35. }
  36. }