AdminCriteria.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Repositories\Criteria\Base;
  3. use App\Repositories\Enums\RoleEnum;
  4. use Illuminate\Http\Request;
  5. use Prettus\Repository\Contracts\CriteriaInterface;
  6. use Prettus\Repository\Contracts\RepositoryInterface;
  7. class AdminCriteria 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('username')) {
  29. $model = $model->where('username', 'like', '%' . $this->request->get('username') . '%');
  30. }
  31. if ($this->request->filled('mobile')) {
  32. $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile') . '%');
  33. }
  34. if ($this->request->filled('email')) {
  35. $model = $model->where('email', 'like', '%' . $this->request->get('email') . '%');
  36. }
  37. if ($this->request->filled('sex')) {
  38. $model = $model->where('sex', '=', $this->request->get('sex'));
  39. }
  40. if ($this->request->filled('department_id')) {
  41. $model = $model->where('department_id', '=', $this->request->get('department_id'));
  42. }
  43. if ($this->request->filled('status')) {
  44. $model = $model->where('status', '=', $this->request->get('status'));
  45. }
  46. if ($this->request->filled('type')) {
  47. $model = $model->where('type', '=', $this->request->get('type'));
  48. }
  49. if ($this->request->filled('company_id')) {
  50. $model = $model->where('company_id', '=', $this->request->get('company_id'));
  51. }
  52. if ($this->request->filled('is_view_user_info')) {
  53. $model = $model->where('is_view_user_info', '=', $this->request->get('is_view_user_info'));
  54. }
  55. if ($this->request->filled('role_name')) {
  56. $role_name = $this->request->get('role_name');
  57. $model = $model->whereHas('roles', function ($query) use ($role_name) {
  58. return $query->where('name', $role_name);
  59. });
  60. }
  61. if ($this->request->filled('role_id')) {
  62. $role_id = $this->request->get('role_id');
  63. $model = $model->whereHas('roles', function ($query) use ($role_id) {
  64. return $query->where('id', $role_id);
  65. });
  66. }
  67. if ($this->request->filled('name')) {
  68. $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
  69. }
  70. if ($this->request->filled('user_no')) {
  71. $model = $model->where('user_no', 'like', '%' . $this->request->get('user_no'));
  72. }
  73. if ($this->request->filled('mobile')) {
  74. $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile'));
  75. }
  76. // $admin = login_admin();
  77. // if ($admin) {
  78. // if ($admin->hasRole(RoleEnum::SUPER_ADMIN)) {
  79. //
  80. // } elseif ($admin->hasRole(RoleEnum::SHOP_ADMIN)) {
  81. // $model = $model->where('shop_id', $admin['shop_id']);
  82. // } else {
  83. // $model = $model->where('id', $admin['id']);
  84. // }
  85. // }
  86. // switch ($admin['type']) {
  87. // case AdminTypeEnum::ADMIN:
  88. // $company_id = $admin['company_id'];
  89. // if ($company_id) $model = $model->where('company_id', '=', $company_id);
  90. // break;
  91. // }
  92. // $model = $model->where('type', '=', AdminTypeEnum::ADMIN);
  93. return $model;
  94. }
  95. }