PosterWhere.php 1.1 KB

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