124 lines
3.4 KiB
PHP
124 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
use app\BaseController;
|
|
use app\common\model\Tickets;
|
|
use app\common\service\TicketNotifier;
|
|
use app\common\service\TicketService;
|
|
use think\facade\Session;
|
|
|
|
class Ticket extends BaseController
|
|
{
|
|
|
|
/**
|
|
* 查询工单
|
|
*/
|
|
public function ticketsFind(TicketService $ticketService)
|
|
{
|
|
// 在控制器明确接收参数
|
|
$params = [
|
|
"page" => $this->request->param('page', 1, 'intval'),
|
|
"limit" => $this->request->param('limit', 20, 'intval'),
|
|
"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 $this->success('查询成功', $result);
|
|
}
|
|
|
|
|
|
/**
|
|
* 新增工单
|
|
*/
|
|
public function createTicket(TicketService $ticketService)
|
|
{
|
|
$data = $this->request->post();
|
|
|
|
try {
|
|
$result = $ticketService->createTicket($data);
|
|
return $this->success('创建成功', $result);
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 更新工单(后台调用)
|
|
*/
|
|
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 $this->success('更新成功', $result);
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 统计各状态工单数量
|
|
*/
|
|
public function getTicketDashboardStats(TicketService $ticketService)
|
|
{
|
|
$result = $ticketService->getTicketDashboardStats();
|
|
return $this->success('查询成功', $result);
|
|
}
|
|
|
|
/**
|
|
* 批量更新工单
|
|
*/
|
|
public function batchUpdate(TicketService $ticketService)
|
|
{
|
|
$adminId = Session::get('user_info.id'); // 获取管理员身份
|
|
$data = $this->request->post();
|
|
|
|
$ids = $data['ids'] ?? [];
|
|
if (!is_array($ids) || empty($ids)) {
|
|
return $this->error('ids 必须是非空数组');
|
|
}
|
|
|
|
$allowFields = ['status', 'lock_time'];
|
|
|
|
try {
|
|
$result = $ticketService->batchUpdateTickets($ids, $data, $allowFields, $adminId, true);
|
|
return $this->success('批量更新成功', $result);
|
|
} catch (\Exception $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除一个工单(仅后台可调用)
|
|
*/
|
|
public function deleteTicket($id)
|
|
{
|
|
$ticket = Tickets::find($id);
|
|
if (!$ticket) return $this->error('工单不存在');
|
|
|
|
$deleted = $ticket->delete();
|
|
if (!$deleted) {
|
|
return $this->error('删除失败', []);
|
|
}
|
|
|
|
// 通知前端实时刷新(静默,广播服务不可用不影响删除流程)
|
|
TicketNotifier::notify($id, 'delete');
|
|
|
|
return $this->success('删除成功', []);
|
|
}
|
|
}
|