12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use App\Repositories\Enums\Base\AdminTypeEnum;
- use App\Repositories\Models\BikeManage\Bike;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class UserCriteria 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('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'));
- }
- if ($this->request->filled('remark')) {
- $model = $model->where('remark', 'like', '%' . $this->request->get('remark') . '%');
- }
- if ($this->request->filled('type')) {
- $model = $model->where('type', '=', $this->request->get('type'));
- }
- if ($this->request->filled('department_id')) {
- $model = $model->where('department_id', '=', $this->request->get('department_id'));
- }
- if ($this->request->filled('bike_nums')) {
- $bike_nums = $this->request->get('bike_nums');
- $userIds = Bike::query()->select(DB::raw("user_id,count(id) as nums"))->groupBy('user_id')->having('nums', $bike_nums)->pluck('user_id');
- $model = $model->whereIn('id', $userIds);
- }
- if ($this->request->filled('status')) {
- $model = $model->where('status', '=', $this->request->get('status'));
- }
- $model = $model->where('type', '>', AdminTypeEnum::ADMIN);
- return $model;
- }
- }
|