post('/bilhetes', [self::class, 'listarBilhetes']); $group->post('/eventos', [self::class, 'listarEventos']); }; } function listarBilhetes(Request $request, Response $response, array $args) { try { $validator = new Validator(); $validator->mapFieldsRules([ 'id' => ['integer', ['min', 1]], 'uniqueid' => ['string'], 'src' => ['string'], 'dst' => ['string'], 'i_date' => ['date'], 'f_date' => ['date'], 'entry' => ['string'] ]); $body = json_decode($request->getBody()->getContents(), true); $validator = $validator->withData($body); if (!$validator->validate()) { $response->getBody() ->write(json_encode($validator->errors())); return $response->withStatus(422); } $result = Bilhetes::getBilhetes($body); /*$query = "SELECT a.id_bilhetes AS id, a.calldate AS data_hora, a.src AS origem, a.dst AS destino, a.billsec AS tempo_conversacao, a.duration AS tempo_atendimento, a.accountcode AS id_transfer, a.uniqueid AS uniqueid, a.userfield AS nome_audio, a.data_bilhete AS data, a.fora_horario AS fora_horario, a.org_id FROM pbx_bilhetes a WHERE a.lastapp <> 'Transferred Call' "; foreach ($body as $k => $v) { if ($v) { $query .= " AND $k = :$k"; } } $result = Bilhetes::query($query, $data); */ if (!$result) { $response->getBody()->write(json_encode(['status' => false, 'data' => ['message' => 'Nenhum resultado encontrado!']])); } else { $response->getBody()->write(json_encode(['status' => true, 'data' => $result])); } } catch (Exception $e) { $response->getBody()->write(json_encode(['status' => false, 'data' => ["message" => "Nao foi possivel realizar a consulta! " . $e->getMessage()]])); return $response->withStatus(500); } return $response; } public function listarEventos(Request $request, Response $response, array $args) { try { $body = json_decode($request->getBody()->getContents(), true); $dados = $this->validateData($request, true); $query = "SELECT a.id_bilhetes AS id, a.uniqueid, c.id AS fila_id, b.fila, d.nome, d.apelido AS login, SUBSTRING(b.agente,7,4) AS matricula, b.evento AS evento, b.param1 AS param1, b.param2 AS param2, b.param3 AS param3, b.param4 AS param4 FROM pbx_bilhetes a INNER JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 INNER JOIN pbx_dacs c ON c.nome = b.fila INNER JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente,7,4) WHERE evento IN ('ABANDON','COMPLETEAGENT','COMPLETECALLER','CONNECT','ENTERQUEUE', 'EXITWITHTIMEOUT', 'TRANSBORDANDO', 'TRANSBORDADO','TRANSFER', 'TRANSFERORIG', 'COMPLETACALLER', 'COMPLETAAGENT', 'ANSWERED', 'BUSYS', 'NOANSWERS') "; $dados['org_id'] = $body['org_id']; $data = Bilhetes::query($query, $dados); foreach ($dados as $k => $v) { if ($v) { $query .= " AND $k = :$k"; } } if (!$data) { $response->getBody()->write(json_encode(['status' => false, 'data' => ['message' => 'Nenhum resultado encontrado!']])); } else { $response->getBody()->write(json_encode(['status' => true, 'data' => $data])); } } catch (Exception $e) { $response->getBody()->write(json_encode(['status' => false, 'data' => ["message" => "Nao foi possivel realizar a consulta! " . $e->getMessage()]])); } return $response; } }