|
|
<?php |
|
|
|
|
|
namespace app\Controllers; |
|
|
|
|
|
use app\Core\Controller; |
|
|
use app\Models\Queue; |
|
|
use app\Models\Agent; |
|
|
use app\Models\Bilhete; |
|
|
use app\Controllers\ClientController; |
|
|
|
|
|
use Exception; |
|
|
|
|
|
/** |
|
|
* ringall -> 'Simultaneo' |
|
|
* leastrecent -> 'Tempo Livre' |
|
|
* fewesrcalls -> 'Numero de Atendimento' |
|
|
* random -> 'Randomico' |
|
|
* rrordered -> 'Sequencial' |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* Description of QueueController |
|
|
* |
|
|
* @author Lucas Awade |
|
|
*/ |
|
|
class QueueController extends Controller |
|
|
{ |
|
|
/** @var Queue $queue model de Queue */ |
|
|
protected $queue; |
|
|
|
|
|
/** @var Agent $agent model de Agent */ |
|
|
protected $agent; |
|
|
|
|
|
/** @var Bilhete $bilhete model de Bilhete */ |
|
|
protected $bilhete; |
|
|
|
|
|
public function __construct() |
|
|
{ |
|
|
$this->queue = new Queue(); |
|
|
$this->agent = new Agent(); |
|
|
$this->bilhete = new Bilhete(); |
|
|
} |
|
|
|
|
|
public function strategy($queue) |
|
|
{ |
|
|
$search = $this->queue->findQueueByName($queue); |
|
|
$strategy = $search->strategy; |
|
|
if (method_exists(__CLASS__, $strategy)) { |
|
|
return $this->$strategy($queue); |
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
public function listAllQueueWhatsApp($option = null) |
|
|
{ |
|
|
try { |
|
|
$response = ['QUEUE' => '', 'LIST' => '']; |
|
|
$search = $this->queue->findAllQueue(); |
|
|
$strmsg = "Informe o numero do setor para o atendimento: \n"; |
|
|
$count = 1; |
|
|
if (count($search) == 1) { |
|
|
$response['QUEUE'] = $search[0]->nome; |
|
|
return $response; |
|
|
} |
|
|
foreach ($search as $q) { |
|
|
if ($option == $count || $option == $q->nome) { |
|
|
$response['QUEUE'] = $q->nome; |
|
|
return $response; |
|
|
} |
|
|
$strmsg .= "{$count}. *{$q->nome}* \n"; |
|
|
$count++; |
|
|
} |
|
|
$response['LIST'] = $strmsg; |
|
|
return $response; |
|
|
} catch (Exception $ex) { |
|
|
logger()->error($ex->getMessage()); |
|
|
} |
|
|
return false; |
|
|
} |
|
|
public function listaAllFilas() |
|
|
{ |
|
|
return $this->queue->findAllQueue(); |
|
|
} |
|
|
|
|
|
public function clientQueueVerify($number, $fila) |
|
|
{ |
|
|
|
|
|
$client = new ClientController(); |
|
|
$clienteFila = $client->getClientQueueData($number, $fila); |
|
|
|
|
|
$clienteEmFila = $clienteFila['IN_QUEUE']; |
|
|
$posicaoFila = $clienteFila['QUEUE_POSITION']; |
|
|
|
|
|
if ($clienteEmFila) { |
|
|
$msg = 'Voc<EFBFBD> est<EFBFBD> na posi<EFBFBD><EFBFBD>o ' . $posicaoFila . ' da fila ' . $clienteFila['CLIENT_QUEUE'] . '. Aguarde ser atendido!'; |
|
|
$response['MESSAGE'] = $msg; |
|
|
return $response; |
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Busca o agente com o menor tempo de atendimento. |
|
|
*/ |
|
|
private function leastrecent($queue) |
|
|
{ |
|
|
$agents = $this->agent->findAgentByQueue($queue, CONF_AGENT_STATUS_LIVRE); |
|
|
if (!$agents) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
$timer = ['RAMAL' => '', 'TIMER' => (9999999 * 9999999)]; |
|
|
foreach ($agents as $agent) { |
|
|
$livre = strtotime('1970-01-01 ' . $agent->tempo_livre . 'UTC'); |
|
|
if ($livre < $timer['TIMER']) { |
|
|
$timer['RAMAL'] = $agent->ramal; |
|
|
$timer['TIMER'] = $livre; |
|
|
} |
|
|
} |
|
|
return $timer['RAMAL']; |
|
|
} |
|
|
|
|
|
private function fewestcalls($queue) |
|
|
{ |
|
|
$agents = $this->agent->findAgentByQueue($queue, CONF_AGENT_STATUS_LIVRE); |
|
|
if (!$agents) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
$atendimentos = ['RAMAL' => '', 'ATENDIMENTOS' => (9999999 * 9999999)]; |
|
|
foreach ($agents as $agent) { |
|
|
if ($agent->atendimentos <= $atendimentos['ATENDIMENTOS']) { |
|
|
$atendimentos['RAMAL'] = $agent->ramal; |
|
|
$atendimentos['ATENDIMENTOS'] = $agent->atendimentos; |
|
|
} |
|
|
} |
|
|
return $atendimentos['RAMAL']; |
|
|
} |
|
|
|
|
|
private function random($queue) |
|
|
{ |
|
|
$agents = $this->agent->findAgentByQueue($queue); |
|
|
if (!$agents) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
$rand = rand(0, (count($agents) - 1)); |
|
|
return $agents[$rand]->ramal; |
|
|
} |
|
|
|
|
|
/** Busca o ultima matricula que foi atendida e pega a maior */ |
|
|
private function rrordered($queue, $media) |
|
|
{ |
|
|
$calls = $this->bilhete->findBilheteByEventosDacs($queue, 'now', ['COMPLETEAGENT', 'COMPLETECALLER', 'COMPLETAAGENT', 'COMPLETACALLER', 'ABANDON', 'ATENDIDA'], null, $media); |
|
|
$atendimento = end($calls); |
|
|
|
|
|
$agents = $this->agent->findAgentByQueue($queue, CONF_AGENT_STATUS_LIVRE, 'matricula', 'DESC'); |
|
|
if (!$agents) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
if (!$calls) { |
|
|
return $agents[0]->ramal; |
|
|
} |
|
|
|
|
|
foreach ($agents as $agent) { |
|
|
if ($atendimento->agente > $agent->matricula) { |
|
|
return $agent->ramal; |
|
|
} |
|
|
} |
|
|
return $agents[0]->ramal; |
|
|
} |
|
|
} |