123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Repositories\Criteria\Dwbs;
- 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 ChengjiuCriteria 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('day')) {
- $val = $this->request->get('day');
- if (is_string($val)) $model = $model->where('day', '=', $val);
- if (is_array($val)) {
- $model = $model->where('day', '>=', $val[0])->where('day', '<=', $val[1]);
- }
- }
- if ($this->request->filled('user_mobile')) {
- $val = $this->request->get('user_mobile');
- $ids = User::byMobileGetIds($val);
- $model = $model->whereIn('user_id', $ids);
- }
- if ($this->request->filled('user_nickname')) {
- $val = $this->request->get('user_nickname');
- $model = $model->whereHas('user', function ($query) use ($val) {
- return $query->where('nickname', 'like', "%{$val}%");
- });
- }
- if ($this->request->filled('type')) {
- $val = $this->request->get('type');
- $model = $model->where('type', '=', $val);
- }
- if ($this->request->filled('name')) {
- $val = $this->request->get('name');
- $model = $model->where('name', 'like', "%{$val}%");
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- }
- if ($this->request->filled('ids')) {
- $ids = $this->request->get('ids');
- $model = $model->whereIn('id', $ids);
- }
- if (!$this->request->filled('orderBy')) {
- $model = $model->orderByDesc('id');
- }
- if (!isAdminModule()) {
- $model = $model->where('user_id', login_user_id());
- } else {
- if (Menu::checkUserIsBtn(151)) {
- //全部数据
- } elseif (Menu::checkUserIsBtn(150)) {
- $admin = login_admin();
- $model = $model->whereHas('user', function ($q) use ($admin) {
- return $q->where('kefu_tag', $admin['user_tag']);
- });
- } else {
- $model = $model->where('id', 0);
- }
- }
- return $model;
- }
- }
|