OrderBy.php 1.0 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\Base\Criteria;
  9. use App\Repositories\Base\Criteria;
  10. use App\Repositories\Contracts\RepositoryInterface as Repository;
  11. class OrderBy extends Criteria {
  12. private $field = '';
  13. private $sort = 'ASC';
  14. /**
  15. * MultiWhere constructor.
  16. * @param array $search
  17. *
  18. * id 商品ID
  19. * name 商品名称(模糊查询)
  20. * cate_id 分类ID
  21. * store_id 商家ID
  22. * store_name 商家名称(模糊查询)
  23. *
  24. *
  25. *
  26. */
  27. public function __construct($field,$sort="ASC")
  28. {
  29. $this->field = $field;
  30. $this->sort = $sort;
  31. }
  32. /**
  33. * @param $model
  34. * @param RepositoryInterface $repository
  35. * @return mixed
  36. */
  37. public function apply($model, Repository $repository)
  38. {
  39. $model = $model->orderBy($this->field,$this->sort);
  40. return $model;
  41. }
  42. }