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