1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use App\Repositories\Models\Base\Menu;
- use App\Repositories\Models\Base\User;
- use Illuminate\Http\Request;
- 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('nickname')) {
- $model = $model->where('nickname', 'like', '%' . $this->request->get('nickname') . '%');
- }
- if ($this->request->filled('mobile_code')) {
- $val = $this->request->get('mobile_code');
- $model = $model->where('mobile_code', 'like', "%{$val}");
- }
- if ($this->request->filled('tag')) {
- $val = $this->request->get('tag');
- $model = $model->where('tag', 'like', $val);
- }
- if ($this->request->filled('mobile')) {
- $val = $this->request->get('mobile');
- $ids = User::byMobileGetIds($val);
- $model = $model->whereIn('id', $ids);
- }
- if ($this->request->filled('remark')) {
- $model = $model->where('remark', 'like', '%' . $this->request->get('remark') . '%');
- }
- if ($this->request->filled('kefu_tag')) {
- $model = $model->where('kefu_tag', '=', $this->request->get('kefu_tag'));
- }
- if ($this->request->filled('status')) {
- $model = $model->where('status', '=', $this->request->get('status'));
- }
- if (!$this->request->filled('orderBy')) {
- $model = $model->orderByDesc('id');
- }
- if (!isAdminModule()) {
- $model = $model->where('id', login_user_id());
- } else {
- if (Menu::checkUserIsBtn(151)) {
- //全部数据
- } elseif (Menu::checkUserIsBtn(150)) {
- $admin = login_admin();
- $model = $model->where('kefu_tag', (int)$admin['user_tag']);
- } else {
- $model = $model->where('id', 0);
- }
- }
- return $model;
- }
- }
|