CatWhere.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * User: Mike
  4. * Email: m@9026.com
  5. * Date: 2017/1/12
  6. * Time: 17:52
  7. */
  8. namespace App\Repositories\Album\Criteria;
  9. use App\Repositories\Base\Criteria;
  10. use App\Repositories\Contracts\RepositoryInterface as Repository;
  11. class CatWhere extends Criteria {
  12. private $search = [];
  13. private $pid;
  14. private $store_id;
  15. /**
  16. * MultiWhere constructor.
  17. * @param array $search
  18. *
  19. */
  20. public function __construct(array $search,int $pid,int $store_id)
  21. {
  22. $this->search = $search;
  23. $this->pid = $pid;
  24. $this->store_id = $store_id;
  25. }
  26. /**
  27. * @param $model
  28. * @param RepositoryInterface $repository
  29. * @return mixed
  30. */
  31. public function apply($model, Repository $repository)
  32. {
  33. if(isset($this->search['keyword']) && $this->search['keyword']) {
  34. $keyword = '%'.$this->search['keyword'].'%';
  35. $model = $model->where([['name','like',$keyword],['parent_id',$this->pid],['store_id',$this->store_id]])
  36. ->orwhere([['id','like',$keyword],['parent_id',$this->pid],['store_id',$this->store_id]]);
  37. } else if(isset($this->search['updated_at']) && $this->search['updated_at']) {
  38. $model = $model->where('updated_at',$this->search['updated_at']);
  39. } else {
  40. $model = $model->where([['parent_id',0],['store_id',$this->store_id]]);
  41. }
  42. return $model;
  43. }
  44. }