| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * 管理员分页查询.
- *
- * @author nj
- * @date 2021-01-23 15:35:04
- */
- namespace App\Repositories\Criterias;
- use Illuminate\Database\Eloquent\Builder;
- use KZ2\Laravel\Repositories\Contracts\RepositoryInterface;
- use KZ2\Laravel\Repositories\Criteria\Criteria;
- class ManagerPagesCriteria extends Criteria
- {
- private $params = [];
- public function __construct($params = [])
- {
- $this->params = $params;
- }
- /**
- * @param Builder $model
- * @param RepositoryInterface $repository
- * @return mixed|void
- */
- public function apply(
- $model,
- RepositoryInterface $repository
- ) {
- if (!empty($this->params['manager_uid'])) {
- $model = $model->where('manager_uid', $this->params['manager_uid']);
- }
- if (!empty($this->params['username'])) {
- $model = $model->where('username', 'LIKE', '%'. $this->params['username'] .'%');
- }
- if (!empty($this->params['nick'])) {
- $model = $model->where('nick', 'LIKE', '%'. $this->params['nick'] .'%');
- }
- if (isset($this->params['is_locked'])) {
- $is_locked = intval($this->params['is_locked']);
- if ($is_locked == 1) {
- $model = $model->whereNotNull('locked_at');
- } elseif ($is_locked == -1) {
- $model = $model->whereNull('locked_at');
- }
- }
- if (!empty($this->params['role_id'])) {
- $model = $model->where('role_id', $this->params['role_id']);
- }
- if (!empty($this->params['email'])) {
- $model = $model->where('email', $this->params['email']);
- }
- return $model;
- }
- }
|