403Webshell
Server IP : 54.94.228.101  /  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/EnvioOfertasWhatsapp.php
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Modules\Oferta\Models\Oferta;
use App\Modules\Whatsapp\Models\Whatsapp;
use App\Modules\WhatsappOfertaLog\Models\WhatsappOfertaLog;

use App\BasicInfo;
use App\Services\GeralService;

class EnvioOfertasWhatsapp extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'envio_ofertas_whatsapp';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Envio Oferta do Dia via Whatsapp';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $hora_atual = date('H:i');
        $BasicInfo  = BasicInfo::first();

        printf("Rotina Ativa: " . ($BasicInfo->envio_rotina_whatsapp == 1 ? "SIM" : "NÃO") . " \n");
        printf("Hora Rotina: " . substr($BasicInfo->horario_rotina_whatsapp, 0, 5) . " / Hora Atual: {$hora_atual}  \n");
        
        if($BasicInfo->envio_rotina_whatsapp == 1 && $BasicInfo->horario_rotina_whatsapp == "{$hora_atual}:00"):

            $oferta    = Oferta::where('data', '=', date('Y-m-d'))->where('tipo', '=', 'D')->first();
            
            //Oferta Não Encontrada
            if(!$oferta){
                printf("Oferta do Dia não encontrada \n");
                return false;
            }

            //Oferta Esgotada
            if($oferta->estoque == 0){
                printf("Oferta do Dia Esgotada \n");
                return false;
            }
            
            //Validação ShortLink Oferta
            if(empty($oferta->short_link)){
                $data = [
                    'longUrl' => 'https://www.vinumday.com.br/oferta/' . $oferta->slug . '?utm_source=whatsapp',
                    'format'  => 'txt'
                ];
                $short_link = GeralService::callBitlyAPI('shorten', $data, 'GET');
                $short_link = trim($short_link);
                if($short_link && $short_link != 'INVALID_URI'){
                    $oferta->short_link = $short_link;
                    $oferta->save();
                }
            }

            if(!empty($oferta->short_link)){

                $data_fechamento = date('Y-m-d', strtotime("-1 month",strtotime(date('Y-m-d'))));

                $cadastros = Whatsapp::whereRaw("NOT EXISTS (SELECT 1 FROM whatsapp_oferta_log WHERE whatsapp_oferta_log.whatsapp_id = whatsapp.id AND whatsapp_oferta_log.tipo = 'success' AND whatsapp_oferta_log.data_registro > '" . date('Y-m-d') . "')")
                ->whereRaw("(
                                whatsapp.cadastro_id NOT IN (
                                    SELECT DISTINCT id_cliente FROM pedido_venda WHERE 
                                    EXISTS (SELECT 1 FROM pedido_venda_has_produto pvhp WHERE pvhp.id_pedido_venda = pedido_venda.id AND pvhp.id_oferta = {$oferta->id} AND pedido_venda.data_fechamento > '{$data_fechamento}')
                                ) 
                                OR whatsapp.cadastro_id IS NULL
                            )")->get();

                foreach ($cadastros as $cadastro){

                    $numero = str_replace(["(", ")", " ", "+55", "-"], '', $cadastro->numero);
                    if(!is_numeric($numero)){
                        continue;
                    }
                    
                    $replaceArray = ["<p>","</p>","<strong>","</strong>","<i>","</i>"];
                    $text1   = str_replace("<br />", "\n", $oferta->texto);
                    $text1   = str_replace($replaceArray, "", $text1);
                    $text2   = "Para comprar clique aqui: {$oferta->short_link}";

                    // $send1 = GeralService::callWhatsappAPI('image', $numero, "url={$oferta->thumbnail_principal}&caption={$oferta->titulo} {$oferta->sub_titulo}&description={$text1}");
                    $url   = "https://www.vinumday.com.br/oferta-do-dia";
                    $send1 = GeralService::callWhatsappAPI('link', $numero, "url={$url}&url_thumb={$oferta->thumbnail_principal}&caption={$oferta->titulo} {$oferta->sub_titulo}&description={$text1}");
                    $send1 = json_decode($send1);

                    if(isset($send1->error)){
                        printf("Erro: {$send1->error} \n");
                        $WhatsappOfertaLog                = new WhatsappOfertaLog;
                        $WhatsappOfertaLog->whatsapp_id   = $cadastro->id;
                        $WhatsappOfertaLog->oferta_id     = $oferta->id;
                        $WhatsappOfertaLog->tipo          = 'error';
                        $WhatsappOfertaLog->mensagem_log  = $send1->error;
                        $WhatsappOfertaLog->data_registro = date('Y-m-d H:i:s');
                        $WhatsappOfertaLog->save();
                        continue;
                    }
                    $send2 = GeralService::callWhatsappAPI('chat', $numero, "text={$text1}");
                    $send3 = GeralService::callWhatsappAPI('chat', $numero, "text={$text2}");

                    if($send3){
                        $WhatsappOfertaLog                = new WhatsappOfertaLog;
                        $WhatsappOfertaLog->whatsapp_id   = $cadastro->id;
                        $WhatsappOfertaLog->oferta_id     = $oferta->id;
                        $WhatsappOfertaLog->tipo          = 'success';
                        $WhatsappOfertaLog->data_registro = date('Y-m-d H:i:s');
                        $WhatsappOfertaLog->save();
                    }
                }

            }else{
                printf("ShortLink Oferta não encontrada e não foi possível gerar novamente! \n");
            }
            
        endif;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit