DepartmentCriteria.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Repositories\Criteria\Base;
  3. use App\Repositories\Enums\Base\AdminTypeEnum;
  4. use Illuminate\Http\Request;
  5. use Prettus\Repository\Contracts\CriteriaInterface;
  6. use Prettus\Repository\Contracts\RepositoryInterface;
  7. class DepartmentCriteria implements CriteriaInterface
  8. {
  9. /**
  10. * @var \Illuminate\Http\Request
  11. */
  12. protected $request;
  13. public function __construct(Request $request)
  14. {
  15. $this->request = $request;
  16. }
  17. /**
  18. * @param $model
  19. * @param RepositoryInterface $repository
  20. *
  21. * @return mixed
  22. */
  23. public function apply($model, RepositoryInterface $repository)
  24. {
  25. if ($this->request->filled('name')) {
  26. $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
  27. }
  28. if ($this->request->filled('status')) {
  29. $model = $model->where('status', '=', $this->request->get('status'));
  30. }
  31. if ($this->request->filled('type')) {
  32. $model = $model->where('type', '=', $this->request->get('type'));
  33. }
  34. if ($this->request->filled('parent_id')) {
  35. $model = $model->where('parent_id', '=', $this->request->get('parent_id'));
  36. }
  37. if ($this->request->filled('is_system')) {
  38. $model = $model->where('is_system', '=', $this->request->get('is_system'));
  39. }
  40. $admin = login_admin();
  41. switch ($admin['type']) {
  42. case AdminTypeEnum::ADMIN:
  43. $company_id = $admin['company_id'];
  44. if ($company_id) $model = $model->where('company_id', '=', $company_id);
  45. break;
  46. }
  47. return $model;
  48. }
  49. }