request = $request; } /** * @param $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('reward_explain')) { $val = $this->request->get('reward_explain'); $model = $model->where('reward_explain', 'like', "%{$val}%"); } 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('created_at')) { $val = $this->request->get('created_at'); if (is_string($val)) $model = $model->where('created_at', '=', $val); if (is_array($val)) { $model = $model->where('created_at', '>=', $val[0])->where('created_at', '<=', $val[1]); } } if ($this->request->filled('user_id')) { $val = $this->request->get('user_id'); $model = $model->where('user_id', '=', $val); } 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('reward_type')) { $val = $this->request->get('reward_type'); $model = $model->where('reward_type', '=', $val); } if ($this->request->filled('is_reward')) { $val = $this->request->get('is_reward'); $model = $model->where('is_reward', '=', $val); } if ($this->request->filled('status')) { $status = $this->request->get('status'); $model = $model->where('status', '=', $status); } if ($this->request->filled('source_type')) { $val = $this->request->get('source_type'); $model = $model->where('source_type', $val); } 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; } }