CatWhere.php 1.2 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. {
  13. private $search = [];
  14. private $pid;
  15. private $store_id;
  16. /**
  17. * CatWhere constructor.
  18. * @param array $search
  19. * @param int $pid
  20. * @param int $store_id
  21. */
  22. public function __construct(array $search,int $pid,int $store_id)
  23. {
  24. $this->search = $search;
  25. $this->pid = $pid;
  26. $this->store_id = $store_id;
  27. }
  28. /**
  29. * @param $model
  30. * @param Repository $repository
  31. * @return Object
  32. */
  33. public function apply($model, Repository $repository)
  34. {
  35. if (isset($this->search['keyword']) && $this->search['keyword']) {
  36. $keyword = '%' . $this->search['keyword'] . '%';
  37. $model = $model->where([['name','like',$keyword],['store_id',$this->store_id]])
  38. ->orwhere([['id','like',$keyword],['store_id',$this->store_id]]);
  39. } else {
  40. $model = $model->where([['parent_id',0],['store_id',$this->store_id]]);
  41. }
  42. return $model;
  43. }
  44. }