model->with(['project', 'order', 'solver']); // 搜索条件 if ($request->filled('keyword')) { $keyword = $request->keyword; $query->where(function ($q) use ($keyword) { $q->where('description', 'like', "%{$keyword}%") ->orWhere('solved_result', 'like', "%{$keyword}%") ->orWhereHas('project', function ($q) use ($keyword) { $q->where('name', 'like', "%{$keyword}%"); }) ->orWhereHas('order', function ($q) use ($keyword) { $q->where('serial', 'like', "%{$keyword}%"); }); }); } // 状态筛选 if ($request->filled('status')) { $query->where('solved_status', $request->status); } // 类型筛选 if ($request->filled('type')) { $query->where('type', $request->type); } // 项目筛选 if ($request->filled('project_id')) { $query->where('project_id', $request->project_id); } // 时间范围筛选 if ($request->filled('date_from')) { $query->where('created_at', '>=', $request->date_from); } if ($request->filled('date_to')) { $query->where('created_at', '<=', $request->date_to . ' 23:59:59'); } $data = $query->orderBy('created_at', 'desc')->paginate(15); // 统计数据 $stats = [ 'total' => $this->model->count(), 'pending' => $this->model->where('solved_status', Adverse::STATUS_PENDING)->count(), 'processing' => $this->model->where('solved_status', Adverse::STATUS_PROCESSING)->count(), 'solved' => $this->model->where('solved_status', Adverse::STATUS_SOLVED)->count(), 'closed' => $this->model->where('solved_status', Adverse::STATUS_CLOSED)->count(), ]; return view($this->bladePath . ".index", compact("data", "stats")); } /** * 订单搜索接口 * 前端传递参数:project_id, keyword */ public function orderSearch(\Illuminate\Http\Request $request) { $project_id = $request->input('project_id'); $keyword = $request->input('keyword'); if (!$project_id || !$keyword) { return $this->error("缺少必要参数"); } $order = \App\Models\Orders::where('project_id', $project_id) ->where(function ($q) use ($keyword) { $q->where('serial', 'like', "%{$keyword}%") ->orWhere('contact', 'like', "%{$keyword}%") ->orWhere('mobile', 'like', "%{$keyword}%"); }) ->first(); if (!$order) { return $this->error("未找到相关订单"); } // 返回订单信息 return $this->success("搜索成功", "", $order); } }