pi transactions

This commit is contained in:
2019-05-04 23:24:55 -05:00
parent 4f46316efd
commit ec556cfc29
4 changed files with 18 additions and 112 deletions

View File

@@ -56,17 +56,10 @@ class PiTransactionsCommand extends Command
//Setup the Finances container
$finance = new FinanceHelper();
//Get the total pages for the transactions
$pages = $finance->GetTransactionPageCount(3, 94415555);
dd($pages);
//Dispatch a single job for each page to process
for($i = 1; $i <= $pages; $i++) {
$job = new JobProcessWalletTransaction;
$job->division = 3;
$job->charId = 94415555;
$job->page = $i;
ProcessWalletTransactionJob::dispatch($job);
}
$job = new JobProcessWalletTransaction;
$job->division = 3;
$job->charId = 94415555;
ProcessWalletTransactionJob::dispatch($job);
//Mark the job as finished
$task->SetStopStatus();

View File

@@ -15,7 +15,7 @@ use App\Library\Finances\Helper\FinanceHelper;
//App Models
use App\Models\Jobs\JobProcessWalletTransaction;
class ProcessWallettransactionJob implements ShouldQueue
class ProcessWalletTransactionJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -57,7 +57,7 @@ class ProcessWallettransactionJob implements ShouldQueue
//Declare the class variables
$finance = new FinanceHelper();
$finance->GetWalletTransactionPage($this->division, $this->charId, $this->page);
$finance->GetWalletTransaction($this->division, $this->charId);
//After the job is completed, delete the job
$this->delete();

View File

@@ -105,103 +105,22 @@ class FinanceHelper {
//Create the esi class varialble
$esi = new Eseye($authentication);
//Set our current page to 1 which is the one we are starting on.
$currentPage = 1;
//Set our default total pages to 1 in case our try section fails out.
$totalPages = 1;
//If more than one page is found, decode the first set of wallet entries, then call for the next pages
do {
//Call the first page of the wallet journal, as we are always going to get at least one page.
//If we have more pages, then we will continue through the while loop.
try {
$journals = $esi->page($currentPage)
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [
'corporation_id' => 98251577,
'division' => 3,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
//Set the total pages we need to cycle through.
$totalPages = $journals->pages;
//Decode the wallet from json into an array
$wallet = json_decode($journals->raw, true);
//For each journal entry, attempt to store it in the database.
//The PutWalletJournal function checks to see if it's already in the database.
foreach($wallet as $entry) {
if($division == 3 && $charId == 94415555) {
if(in_array($entry['type_id'], $pi_items, false)) {
$pi = new PISale();
$pi->InsertPISale($entry, 98287666);
}
}
}
//Increment the current page we are on.
$currentPage++;
//Continue looping through the do while loop until the current page is greater than or equal to the total pages.
} while ($currentPage < $totalPages);
}
public function GetWalletTransactionPage($division, $charId, $page = 1) {
//Declare the lookup class helper
$lookups = new LookupHelper;
//Setup array for PI items
$pi_items = $this->GetPIMaterialsArray();
//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, $charId)) {
printr("Token not found\n");
return null;
//Get the entries of the journal for transactions
try {
$journals = $esi->page($currentPage)
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [
'corporation_id' => 98251577,
'division' => 3,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
//Reference to see if the character is in our look up table for corporations and characters
$corpId = $lookups->LookupCharacter($charId);
//Decode the wallet from json into an array
$wallet = json_decode($journals->raw, true);
//Create an ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Create the esi class varialble
$esi = new Eseye($authentication);
//Set our current page to 1 which is the one we are starting on.
$currentPage = 1;
//Set our default total pages to 1 in case our try section fails out.
$totalPages = 1;
//If more than one page is found, decode the first set of wallet entries, then call for the next pages
do {
//Call the first page of the wallet journal, as we are always going to get at least one page.
//If we have more pages, then we will continue through the while loop.
try {
$journals = $esi->page($currentPage)
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/transactions/', [
'corporation_id' => 98251577,
'division' => 3,
]);
} catch(RequestFailedException $e) {
return $e->getEsiResponse();
}
//Set the total pages we need to cycle through.
$totalPages = $journals->pages;
//Decode the wallet from json into an array
$wallet = json_decode($journals->raw, true);
//For each journal entry, attempt to store it in the database.
//For each transactional entry, attempt to store it in the database.
//The PutWalletJournal function checks to see if it's already in the database.
foreach($wallet as $entry) {
if($division == 3 && $charId == 94415555) {
@@ -211,11 +130,6 @@ class FinanceHelper {
}
}
}
//Increment the current page we are on.
$currentPage++;
//Continue looping through the do while loop until the current page is greater than or equal to the total pages.
} while ($currentPage < $totalPages);
}
public function GetWalletJournal($division, $charId) {

View File

@@ -17,7 +17,6 @@ class JobProcessWalletTransaction extends Model
protected $fillable = [
'charId',
'division',
'page',
];
}