| Server IP : 54.94.228.101 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/app/Events/ |
Upload File : |
<?php
namespace App\Events;
use App\Modules\PedidoEntrega\Models\PedidoEntrega;
use App\Modules\PedidoEntregaHasStatus\Models\PedidoEntregaHasStatus;
use App\Modules\PedidoEntregaStatus\Models\PedidoEntregaStatus;
use App\Modules\PedidoVenda\Models\PedidoVenda;
use App\Modules\PedidoVendaStatus\Models\PedidoVendaStatus;
use App\Modules\Adega\Models\Adega;
use App\Modules\AlertaFila\Models\AlertaFila;
use Notification;
use App\Notifications\NotificacaoPedidoEntrega;
use App\User;
use Illuminate\Support\Facades\Log;
use App\Services\GeralService;
use App\Services\PedidoEntregaService;
use DB;
class PedidoEntregaHasStatusEvent
{
/**
* Listen to the User created event.
*
* @param User $user
* @return void
*/
public function created(PedidoEntregaHasStatus $pedidoEntregaHasStatus)
{
}
/**
* Listen to the User deleting event.
*
* @param User $user
* @return void
*/
public function deleting(PedidoEntregaHasStatus $pedidoEntregaHasStatus)
{
}
/**
* Listen to the User created event.
*
* @param User $user
* @return void
*/
public function updated(PedidoEntregaHasStatus $pedidoEntregaHasStatus)
{
}
/**
* Listen to the User deleting event.
*
* @param User $user
* @return void
*/
public function updating(PedidoEntregaHasStatus $pedidoEntregaHasStatus)
{
//
}
/**
* Listen to the User created event.
*
* @param User $user
* @return void
*/
public function saved(PedidoEntregaHasStatus $pedidoEntregaHasStatus)
{
$pedidoEntrega = PedidoEntrega::where('id', $pedidoEntregaHasStatus->id_pedido_entrega)->with('adega.cliente')->first();
$pedidoEntrega->id_pedido_entrega_status = $pedidoEntregaHasStatus->id_pedido_entrega_status;
$pedidoEntrega->save();
if($pedidoEntregaHasStatus->notificar_cliente == true && PedidoEntregaService::checkSendMail($pedidoEntregaHasStatus) == TRUE){
$pedidoEntregaStatus = PedidoEntregaStatus::where('id', $pedidoEntregaHasStatus->id_pedido_entrega_status)->first();
$user = User::find($pedidoEntrega->adega->cliente->user_id);
//cria array da fila para enviar email de notificação
$parametrosAlerta = array();
$parametrosAlerta['alertaFila'] = ['cadastro' => [],'tipo' => 'pedido-entrega-has-status', 'tipo_id' => $pedidoEntregaHasStatus->id];
$parametrosAlerta['alertaFila']['cadastro'][$pedidoEntrega->adega->id_cliente] = $pedidoEntrega->adega->id_cliente;
$retornoAlerta = AlertaFila::criarAlertaFila($parametrosAlerta);
//ENVIAR PARA A FILA DE E-MAIL
// Notification::send($user, new NotificacaoPedidoEntrega($pedidoEntrega, $pedidoEntregaStatus, $pedidoEntregaHasStatus, url('admin/pedido-entrega/edit/'.$pedidoEntregaHasStatus->pedidoEntrega->slug)));
}
//Aprovação Pedido de Venda Frete
if($pedidoEntregaHasStatus->id_pedido_entrega_status == 2 && !empty($pedidoEntrega->id_pedido_venda_frete)){
//Atualiza Status Pedido Venda Frete
$pedidoVenda = PedidoVenda::where('id', $pedidoEntrega->id_pedido_venda_frete)->first();
$pedidoVendaStatus = PedidoVendaStatus::where('id', $pedidoEntregaHasStatus->id_pedido_entrega_status)->first();
if($pedidoVendaStatus && $pedidoVenda){
$pedidoVenda->id_status_pedido_venda = $pedidoVendaStatus->id;
$pedidoVenda->save();
Log::info("PedidoEntregaHasStatusEvent: pedido => {$pedidoVenda->id} / status => {$pedidoVendaStatus->id}");
}
}
//Pedido Entregue
if($pedidoEntrega->rastreamento == 1 && $pedidoEntregaHasStatus->id_pedido_entrega_status == 6){
$sql = "UPDATE pedido_entrega SET rastreamento = 0 WHERE id = {$pedidoEntrega->id}";
DB::update($sql);
}
$situacao = $pedidoEntregaHasStatus->status->codigo_erp;
if(env('APP_ENV') == 'production'){
$token = GeralService::getApiKeyTinyErp($pedidoEntrega->adega->cliente);
$url = 'https://api.tiny.com.br/api2/pedidos.pesquisa.php';
$content = "token=$token&numeroEcommerce=".$pedidoEntregaHasStatus->id_pedido_entrega."&formato=json";
$resultBusca = json_decode(GeralService::enviarREST($url, $content));
if(isset($resultBusca->retorno->pedidos)){
$id_tiny = $resultBusca->retorno->pedidos[0]->pedido->id;
$url = 'https://api.tiny.com.br/api2/pedido.alterar.situacao';
$content = "token=$token&situacao=".$situacao."&id=".$id_tiny."&formato=json";
$resultAlteracao = json_decode(GeralService::enviarREST($url, $content));
}
}
}
/**
* Listen to the User deleting event.
*
* @param User $user
* @return void
*/
public function saving(PedidoEntregaHasStatus $pedidoEntregaHasStatus)
{
//
}
}