123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use App\Repositories\Enums\RoleEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class AdminCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @param $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($this->request->filled('name')) {
- $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
- }
- if ($this->request->filled('username')) {
- $model = $model->where('username', 'like', '%' . $this->request->get('username') . '%');
- }
- if ($this->request->filled('mobile')) {
- $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile') . '%');
- }
- if ($this->request->filled('email')) {
- $model = $model->where('email', 'like', '%' . $this->request->get('email') . '%');
- }
- if ($this->request->filled('sex')) {
- $model = $model->where('sex', '=', $this->request->get('sex'));
- }
- if ($this->request->filled('department_id')) {
- $model = $model->where('department_id', '=', $this->request->get('department_id'));
- }
- if ($this->request->filled('status')) {
- $model = $model->where('status', '=', $this->request->get('status'));
- }
- if ($this->request->filled('type')) {
- $model = $model->where('type', '=', $this->request->get('type'));
- }
- if ($this->request->filled('company_id')) {
- $model = $model->where('company_id', '=', $this->request->get('company_id'));
- }
- if ($this->request->filled('is_view_user_info')) {
- $model = $model->where('is_view_user_info', '=', $this->request->get('is_view_user_info'));
- }
- if ($this->request->filled('role_name')) {
- $role_name = $this->request->get('role_name');
- $model = $model->whereHas('roles', function ($query) use ($role_name) {
- return $query->where('name', $role_name);
- });
- }
- if ($this->request->filled('role_id')) {
- $role_id = $this->request->get('role_id');
- $model = $model->whereHas('roles', function ($query) use ($role_id) {
- return $query->where('id', $role_id);
- });
- }
- if ($this->request->filled('name')) {
- $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
- }
- if ($this->request->filled('user_no')) {
- $model = $model->where('user_no', 'like', '%' . $this->request->get('user_no'));
- }
- if ($this->request->filled('mobile')) {
- $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile'));
- }
- // $admin = login_admin();
- // if ($admin) {
- // if ($admin->hasRole(RoleEnum::SUPER_ADMIN)) {
- //
- // } elseif ($admin->hasRole(RoleEnum::SHOP_ADMIN)) {
- // $model = $model->where('shop_id', $admin['shop_id']);
- // } else {
- // $model = $model->where('id', $admin['id']);
- // }
- // }
- // switch ($admin['type']) {
- // case AdminTypeEnum::ADMIN:
- // $company_id = $admin['company_id'];
- // if ($company_id) $model = $model->where('company_id', '=', $company_id);
- // break;
- // }
- // $model = $model->where('type', '=', AdminTypeEnum::ADMIN);
- return $model;
- }
- }
|