This commit is contained in:
2026-07-20 16:54:59 +08:00
parent 247e113014
commit 9f8d6d629a
4 changed files with 22 additions and 33 deletions

View File

@@ -16,22 +16,21 @@ class Ticket extends BaseController
*/
public function ticketsFind(TicketService $ticketService)
{
// 在控制器明确接收参数
$params = [
"page" => $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),
"status" => $this->request->param('status', 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]);
return $this->success('查询成功', $result);
}
@@ -44,9 +43,9 @@ class Ticket extends BaseController
try {
$result = $ticketService->createTicket($data);
return json(['code' => 200, 'msg' => '创建成功', 'data' => $result]);
return $this->success('创建成功', $result);
} catch (\Exception $e) {
return json(['code' => 400, 'msg' => $e->getMessage(), 'data' => null]);
return $this->error($e->getMessage());
}
}
@@ -64,9 +63,9 @@ class Ticket extends BaseController
try {
$result = $ticketService->updateTicket($id, $data, $allowFields, $adminId, true);
return json(['code' => 200, 'msg' => '更新成功', 'data' => $result]);
return $this->success('更新成功', $result);
} catch (\Exception $e) {
return json(['code' => 400, 'msg' => $e->getMessage(), 'data' => []]);
return $this->error($e->getMessage());
}
}
@@ -77,7 +76,7 @@ class Ticket extends BaseController
public function getTicketDashboardStats(TicketService $ticketService)
{
$result = $ticketService->getTicketDashboardStats();
return json(['code' => 200, 'msg' => '查询成功', 'data' => $result]);
return $this->success('查询成功', $result);
}
/**
@@ -90,16 +89,16 @@ class Ticket extends BaseController
$ids = $data['ids'] ?? [];
if (!is_array($ids) || empty($ids)) {
return json(['code' => 400, 'msg' => 'ids 必须是非空数组', 'data' => []]);
return $this->error('ids 必须是非空数组');
}
$allowFields = ['status', 'lock_time'];
try {
$result = $ticketService->batchUpdateTickets($ids, $data, $allowFields, $adminId, true);
return json(['code' => 200, 'msg' => '批量更新成功', 'data' => $result]);
return $this->success('批量更新成功', $result);
} catch (\Exception $e) {
return json(['code' => 400, 'msg' => $e->getMessage(), 'data' => []]);
return $this->error($e->getMessage());
}
}
@@ -109,10 +108,10 @@ class Ticket extends BaseController
public function deleteTicket($id)
{
$ticket = Tickets::find($id);
if (!$ticket) return json(['code' => false, 'msg' => '工单不存在', 'data' => []]);
if (!$ticket) return $this->error('工单不存在');
return $ticket->delete()
? json(['code' => true, 'msg' => '删除成功', 'data' => []])
: json(['code' => false, 'msg' => '删除失败', 'data' => []]);
? $this->success('删除成功', [])
: $this->error('删除失败', []);
}
}