PriceWhere.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Models\AlbumProductModel;
  10. use App\Repositories\Base\Criteria;
  11. use App\Repositories\Contracts\RepositoryInterface as Repository;
  12. class PriceWhere extends Criteria {
  13. private $search = [];
  14. private $store_id;
  15. private $agent_id;
  16. /**
  17. * MultiWhere constructor.
  18. * @param array $search
  19. *
  20. */
  21. public function __construct(array $search,int $store_id,int $agent_id)
  22. {
  23. $this->search = $search;
  24. $this->store_id = $store_id;
  25. $this->agent_id = $agent_id;
  26. }
  27. /**
  28. * @param $model
  29. * @param RepositoryInterface $repository
  30. * @return mixed
  31. */
  32. public function apply($model, Repository $repository)
  33. {
  34. if(isset($this->search['keyword']) && $this->search['keyword']) {
  35. $keyword = '%'.$this->search['keyword'].'%';
  36. $model = $model->where([['name','like',$keyword],['store_id',$this->store_id],['agent_id',$this->agent_id]])
  37. ->orwhere([['id','like',$keyword],['store_id',$this->store_id],['agent_id',$this->agent_id]]);
  38. } else if(isset($this->search['updated_at']) && $this->search['updated_at']) {
  39. $model = $model->where('updated_at',$this->search['updated_at']);
  40. } else {
  41. $model = $model->where([['store_id',$this->store_id],['agent_id',$this->agent_id]]);
  42. }
  43. if (isset($this->search['cat_id']) && $this->search['cat_id'] > 0) {
  44. $model = $model->where([['cat_id',$this->search['cat_id']]]);
  45. }
  46. return $model;
  47. }
  48. }