| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * 管理员分页查询.
- *
- * @author jim <jim458734573@gmail.com>
- * @date 2020-01-23 15:35:04
- */
- declare(strict_types=1);
- namespace App\Repositories\Criterias;
- use Hyperf\Database\Query\Builder;
- use KZ2\Repositories\Contracts\RepositoryInterface;
- use KZ2\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_id'])) {
- $model = $model->where('manager_id', $this->params['manager_id']);
- }
- 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 (!empty($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;
- }
- }
|