pi transactions as its own command
This commit is contained in:
56
app/Console/Commands/pitransactions.php
Normal file
56
app/Console/Commands/pitransactions.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use Commands\Library\CommandHelper;
|
||||
use App\Library\Finances\Helper\FinanceHelper;
|
||||
|
||||
class PiTransactionsCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'services:PiTransactions';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Get the transactions from the market alt for the alliance';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//Create the command helper container
|
||||
$task = new CommandHelper('PiTransactions');
|
||||
//Add the entry into the jobs table saying the job is starting
|
||||
$task->SetStartStatus();
|
||||
|
||||
//Setup the Finances container
|
||||
$finance = new FinanceHelper();
|
||||
|
||||
$finance->GetWalletTransaction(3, 94415555);
|
||||
|
||||
//Mark the job as finished
|
||||
$task->SetStopStatus();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class Kernel extends ConsoleKernel
|
||||
Commands\CalculateMarketTaxCommand::class,
|
||||
Commands\HoldingFinancesCommand::class,
|
||||
Commands\MoonMailerCommand::class,
|
||||
Commands\PiTransactionsCommand::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -47,6 +48,9 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('services:MoonMailer')
|
||||
->monthlyOn(1, '00:01')
|
||||
->withoutOverlapping();
|
||||
$schedule->command('services:PiTransactions')
|
||||
->hourly()
|
||||
->withoutOverlapping();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,33 +32,24 @@ use Seat\Eseye\Exceptions\RequestFailedException;
|
||||
class FinanceHelper {
|
||||
|
||||
public function GetWalletTransaction($division, $charId) {
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
|
||||
$scope = EsiScope::where(['character_id' => $charId, 'scope' => 'esi-wallet.read_corporation_wallets.v1'])->get(['scope']);
|
||||
//Declare the Lookup Helper Class
|
||||
//Declare the lookup class helper
|
||||
$lookups = new LookupHelper;
|
||||
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$tokenData = $this->TokenInfo($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
|
||||
//If the token is not found, send the user an eve mail, and just exit out of the function
|
||||
if($this->TokenNotFound($token, $scope)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Setup array for PI items
|
||||
$pi_items = [
|
||||
|
||||
];
|
||||
|
||||
//If the token is not found, send the user an eve mail, and just exit out of the function
|
||||
if(!isset($token[0]->refresh_token) || !isset($scope[0]->scope)) {
|
||||
//Register a mail to be dispatched as a job
|
||||
$mail = new EveMail;
|
||||
$mail->sender = 93738489;
|
||||
$mail->subject = 'W4RP Services ESI API';
|
||||
$mail->body = 'You need to register an ESI API on the services site for esi-wallet.read_corporation_wallet.v1<br>This is also labeled Corporation Wallets';
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
$mail->save();
|
||||
|
||||
SendEveMail::dispatch($mail);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//Reference to see if the character is in our look up table for corporations and characters
|
||||
$corpId = $lookups->LookupCharacter($charId);
|
||||
|
||||
@@ -72,7 +63,6 @@ class FinanceHelper {
|
||||
|
||||
//Create the esi class varialble
|
||||
$esi = new Eseye($authentication);
|
||||
$esi->setVersion('v4');
|
||||
|
||||
//Set our current page to 1 which is the one we are starting on.
|
||||
$currentPage = 1;
|
||||
@@ -86,8 +76,8 @@ class FinanceHelper {
|
||||
try {
|
||||
$journals = $esi->page($currentPage)
|
||||
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [
|
||||
'corporation_id' => $corpId,
|
||||
'division' => $division,
|
||||
'corporation_id' => 98251577,
|
||||
'division' => 3,
|
||||
]);
|
||||
} catch(RequestFailedException $e) {
|
||||
return $e->getEsiResponse();
|
||||
@@ -117,35 +107,20 @@ class FinanceHelper {
|
||||
} while ($currentPage < $totalPages);
|
||||
}
|
||||
|
||||
private function TokenInfo($charId) {
|
||||
//Get the ESI refresh token for the corporation to add a new wallet jouranls into the database
|
||||
//send the token and scope back to the calling function
|
||||
|
||||
}
|
||||
|
||||
public function GetWalletJournal($division, $charId) {
|
||||
//Get the ESI refresh token for the corporation to add new wallet journals into the database
|
||||
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
|
||||
$scope = EsiScope::where(['character_id' => $charId, 'scope' => 'esi-wallet.read_corporation_wallets.v1'])->get(['scope']);
|
||||
//Declare the Lookup Helper Class
|
||||
$tokenData = $this->TokenInfo($charId);
|
||||
$token = $tokenData['token'];
|
||||
$scope = $tokenData['scope'];
|
||||
|
||||
//Declare the lookup class helper
|
||||
$lookups = new LookupHelper;
|
||||
|
||||
//If the token is not found, send the user an eve mail, and just exit out of the function
|
||||
if(!isset($token[0]->refresh_token) || !isset($scope[0]->scope)) {
|
||||
//Register a mail to be dispatched as a job
|
||||
$mail = new EveMail;
|
||||
$mail->sender = 93738489;
|
||||
$mail->subject = 'W4RP Services ESI API';
|
||||
$mail->body = 'You need to register an ESI API on the services site for esi-wallet.read_corporation_wallet.v1<br>This is also labeled Corporation Wallets';
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
$mail->save();
|
||||
|
||||
SendEveMail::dispatch($mail);
|
||||
|
||||
if($this->TokenNotFound($token, $scope)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//Reference to see if the character is in our look up table for corporations and characters
|
||||
$corpId = $lookups->LookupCharacter($charId);
|
||||
|
||||
@@ -295,6 +270,39 @@ class FinanceHelper {
|
||||
} while ($currentPage < $totalPages);
|
||||
}
|
||||
|
||||
private function TokenInfo($charId) {
|
||||
//Get the ESI refresh token for the corporation to add a new wallet jouranls into the database
|
||||
//send the token and scope back to the calling function
|
||||
$token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']);
|
||||
$scope = EsiScope::where(['character_id' => $charId, 'scope' => 'esi-wallet.read_corporation_wallets.v1'])->get(['scope']);
|
||||
|
||||
$data = [
|
||||
'token' => $token,
|
||||
'scope' => $scope,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function TokenNotFound($token, $scope) {
|
||||
if(!isset($token[0]->refresh_token) || !isset($scope[0]->scope)) {
|
||||
//Register a mail to be dispatched as a job
|
||||
$mail = new EveMail;
|
||||
$mail->sender = 93738489;
|
||||
$mail->subject = 'W4RP Services ESI API';
|
||||
$mail->body = 'You need to register an ESI API on the services site for esi-wallet.read_corporation_wallet.v1<br>This is also labeled Corporation Wallets';
|
||||
$mail->recipient = (int)$charId;
|
||||
$mail->recipient_type = 'character';
|
||||
$mail->save();
|
||||
|
||||
SendEveMail::dispatch($mail);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user