$this->request->param('page', 1, 'intval'), "limit" => $this->request->param('limit', 20, 'intval'), "status" => $this->request->param('status', null), "operator_id" => $this->request->param('operator_id', null), "user_id" => $this->request->param('user_id', null), "searchKeyword" => $this->request->param('search', null), "sortOrder" => $this->request->param('sort_order', 'desc'), ]; $result = $ticketService->getTicketList($params); return json(['code' => 200, 'msg' => '查询成功', 'data' => $result]); } /** * 新增工单 */ public function createTicket(TicketService $ticketService) { $data = $this->request->post(); try { $result = $ticketService->createTicket($data); return json(['code' => 200, 'msg' => '创建成功', 'data' => $result]); } catch (\Exception $e) { return json(['code' => 400, 'msg' => $e->getMessage(), 'data' => null]); } } /** * 更新工单(后台调用) */ public function updateTicket(TicketService $ticketService, $id) { $adminId = Session::get('id'); // 获取当前登录管理员ID $data = $this->request->post(); $allowFields = ['company_id', 'operator_id', 'user_id', 'website', 'datanum', 'progress', 'status', 'remark']; try { $result = $ticketService->updateTicket($id, $data, $allowFields, $adminId, true); return json(['code' => 200, 'msg' => '更新成功', 'data' => $result]); } catch (\Exception $e) { return json(['code' => 400, 'msg' => $e->getMessage(), 'data' => []]); } } /** * 统计各状态工单数量 */ public function getTicketDashboardStats(TicketService $ticketService) { $result = $ticketService->getTicketDashboardStats(); return json(['code' => 200, 'msg' => '查询成功', 'data' => $result]); } /** * 批量更新工单 */ public function batchUpdate(TicketService $ticketService) { $adminId = Session::get('user_info.id'); // 获取当前登录管理员ID $data = $this->request->post(); $ids = $data['ids'] ?? []; if (!is_array($ids) || empty($ids)) { return json(['code' => 400, 'msg' => 'ids 必须是非空数组', 'data' => []]); } $allowFields = ['status', 'lock_time']; try { $result = $ticketService->batchUpdateTickets($ids, $data, $allowFields, $adminId, true); return json(['code' => 200, 'msg' => '批量更新成功', 'data' => $result]); } catch (\Exception $e) { return json(['code' => 400, 'msg' => $e->getMessage(), 'data' => []]); } } /** * 删除一个工单(仅后台可调用) */ public function deleteTicket($id) { $ticket = Tickets::find($id); if (!$ticket) return json(['code' => false, 'msg' => '工单不存在', 'data' => []]); return $ticket->delete() ? json(['code' => true, 'msg' => '删除成功', 'data' => []]) : json(['code' => false, 'msg' => '删除失败', 'data' => []]); } }