| 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/Events/ |
Upload File : |
<?php
namespace App\Events;
use App\Modules\Oferta\Models\Oferta;
use App\Services\GeralService;
use App\Services\MailchimpService;
use DB;
class OfertaEvent
{
/**
* Listen to the Oferta created event.
*
* @param Oferta $Oferta
* @return void
*/
public function created(Oferta $Oferta)
{
$sqlUpdateProdutosInOferta = "UPDATE produto SET listar_compras = 1 WHERE EXISTS (SELECT 1 FROM oferta_has_produto ohp WHERE ohp.id_produto = produto.id AND ohp.id_oferta = {$Oferta->id})";
DB::update(DB::raw($sqlUpdateProdutosInOferta));
}
/**
* Listen to the Oferta deleting event.
*
* @param Oferta $Oferta
* @return void
*/
public function deleting(Oferta $Oferta)
{
//
}
/**
* Listen to the Oferta created event.
*
* @param Oferta $Oferta
* @return void
*/
public function updated(Oferta $Oferta)
{
}
/**
* Listen to the Oferta deleting event.
*
* @param Oferta $Oferta
* @return void
*/
public function updating(Oferta $Oferta)
{
//
}
/**
* Listen to the Oferta created event.
*
* @param Oferta $Oferta
* @return void
*/
public function saved(Oferta $Oferta)
{
$old = $Oferta->getOriginal();
//Atualiza Short Link
/*
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($Oferta->tipo == 'D' && empty($Oferta->campaign_id)){
//Busca Campanha Diária
$Campanha = MailchimpService::getCadastro('campaigns?since_send_time=' . $Oferta->data . '&sort_field=send_time&sort_dir=ASC', NULL, FALSE);
$Campanha = json_decode($Campanha);
if(isset($Campanha->campaigns) && isset($Campanha->campaigns[0])){
$Campaign = $Campanha->campaigns[0];
$title = str_replace(" ", "", $Campaign->settings->title);
if($title == 'DIARIO-' . date('d/m/Y', strtotime($Oferta->data))){
$Oferta->campaign_id = $Campaign->id;
$Oferta->save();
}
}
}
//Atualiza Disponibilidade Canal
GeralService::atualizarDisponibilidadeCanal($Oferta, 'OfertaEvent');
//Atualiza Ordenação Oferta
GeralService::alteraOrdenacaoOferta($Oferta);
}
/**
* Listen to the Oferta deleting event.
*
* @param Oferta $Oferta
* @return void
*/
public function saving(Oferta $Oferta)
{
//
}
}