UnknownSec Bypass
403
:
/
mnt
/
lmsestudio-instance-vol002
/
lms_a49dedfd340f
/
app
/
Console
/
Commands
/ [
drwxr-xr-x
]
Menu
Upload
Mass depes
Mass delete
Terminal
Info server
About
name :
VerifyHirings.php
<?php namespace EstudioLMS\Console\Commands; use Carbon\Carbon; use EstudioLMS\Services\PagarMeService; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; /** * Comando para verificar e inserir taxas em vendas de cursos avulsos */ class VerifyHirings extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'verify:hirings'; /** * The console command description. * * @var string */ protected $description = 'Verifica as vendas de cursos avulsos que estão processadas, porém, sem o preenchimento do campo de taxas (fee_amount)'; /** * @var PagarMeService */ private $pagarMeService; /** * Create a new command instance. * * @return void */ public function __construct( PagarMeService $pagarMeService ) { parent::__construct(); $this->pagarMeService = $pagarMeService; } /** * Execute the console command. * * @return void */ public function handle() { $hirings = DB::table('hirings') ->where('status', '=', 3) // Pago ->where('fee_amount', '=', 0) ->where('created_at', '>=', '2025-06-01 00:00:00') ->whereNotNull('payment_code') ->get(); foreach ($hirings as $hiring) { $payable = DB::table('payables') ->where('payment_code', '=', $hiring->payment_code) ->whereNull('subscription_hash') // Para vendas avulsas, subscription_hash deve ser null ->first(); if (!$payable) { $payable = $this->getPayables($hiring); } if ($payable) { try { $today = Carbon::now()->format('Y-m-d H:i:s'); DB::table('hirings') ->where('id', '=', $hiring->id) ->update([ 'fee_amount' => $payable->fee_amount, 'net_amount' => $payable->net_amount, 'updated_at' => $today ]); Log::useDailyFiles(storage_path() . '/logs/command.log'); Log::info('Venda de curso avulso ajustada para o hiring ID: ' . $hiring->id . ' - Payment Code: ' . $hiring->payment_code); } catch (\Exception $e) { Log::useDailyFiles(storage_path() . '/logs/command.log'); Log::info('Venda de curso avulso com erro para o hiring ID: ' . $hiring->id . ' - Payment Code: ' . $hiring->payment_code); Log::error($e->getCode() . ' - ' . $e->getMessage()); } } else { Log::useDailyFiles(storage_path() . '/logs/command.log'); Log::info('Não achou o payable da venda de curso avulso ID: ' . $hiring->id . ' - Payment Code: ' . $hiring->payment_code); } } Log::useDailyFiles(storage_path() . '/logs/command.log'); Log::alert('verify:hirings - Executado - ' . date('Y-m-d H:i:s')); } /** * @param $hiring * @return bool|null */ private function getPayables($hiring) { $payables = $this->pagarMeService->getPayablesForPaymentCode($hiring->payment_code); $payable = null; $paymentDate = null; $netAmount = 0; $payableStatus = ''; if ($payables) { $recipient = DB::table('pagarme_recipients')->first(); $sumFeeAmount = 0; for ($i = 0; $i <= 1; $i++) { if (isset($payables[$i])) { $sumFeeAmount += $payables[$i]['fee']; if ($payables[$i]['recipient_id'] == $recipient->pagarme_recipient_id) { $netAmount = $payables[$i]['amount'] - $payables[$i]['fee']; $payableStatus = $payables[$i]['status']; $paymentDate = $payables[$i]['payment_date']; } else { $sumFeeAmount += $payables[$i]['amount']; $paymentDate = $payables[$i]['payment_date']; } } } $today = Carbon::now()->format('Y-m-d H:i:s'); $payableData = [ 'subscription_hash' => $hiring->payment_code, // Para vendas avulsas repetir o payment_code 'payment_code' => $hiring->payment_code, 'payment_type' => $hiring->payment_method ?? 'unknown', 'payment_date' => $paymentDate, 'card_id' => null, // Hirings não tem card_id direto 'gross_amount' => $hiring->gross_amount, 'discount_amount' => $hiring->discount_amount ?? 0, 'fee_amount' => $sumFeeAmount / 100, 'extra_amount' => $hiring->extra_amount ?? 0, 'net_amount' => $netAmount / 100, 'payable_status_id' => $payableStatus == 'paid' ? 2 : 1, 'created_at' => $today, 'updated_at' => $today, ]; // Insere o payable e obtém o ID do registro criado $payableId = DB::table('payables') ->insertGetId($payableData); // Busca o payable recém-criado para retornar como objeto $payable = DB::table('payables') ->where('id', $payableId) ->first(); } return $payable; } }
Copyright © 2026 - UnknownSec