ledger job
This commit is contained in:
@@ -5,15 +5,25 @@ namespace App\Console\Commands\MiningTaxes;
|
|||||||
//Internal Library
|
//Internal Library
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
//Application Library
|
//Application Library
|
||||||
use Commands\Library\CommandHelper;
|
use Commands\Library\CommandHelper;
|
||||||
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
|
use App\Library\Esi\Esi;
|
||||||
|
use App\Library\Helpers\LookupHelper;
|
||||||
|
use App\Library\Moons\MoonCalc;
|
||||||
|
|
||||||
//Models
|
//Models
|
||||||
use App\Models\MiningTax\Observer;
|
use App\Models\MiningTax\Observer;
|
||||||
|
use App\Models\MiningTax\Ledger;
|
||||||
|
use App\Models\Moon\MineralPrice;
|
||||||
|
use App\Models\Moon\ItemComposition;
|
||||||
|
use App\Models\Esi\EsiToken;
|
||||||
|
use App\Models\Esi\EsiScope;
|
||||||
|
|
||||||
//Jobs
|
//Jobs
|
||||||
use App\Jobs\Commands\MiningTaxes\FetchMiningTaxesLedgersJob;
|
//use App\Jobs\Commands\MiningTaxes\FetchMiningTaxesLedgersJob;
|
||||||
|
|
||||||
class MiningTaxesLedgers extends Command
|
class MiningTaxesLedgers extends Command
|
||||||
{
|
{
|
||||||
@@ -57,12 +67,71 @@ class MiningTaxesLedgers extends Command
|
|||||||
$config = config('esi');
|
$config = config('esi');
|
||||||
//Get the observers from the database
|
//Get the observers from the database
|
||||||
$observers = Observer::all();
|
$observers = Observer::all();
|
||||||
|
//Job Variables to be moved later
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
$lookup = new LookupHelper;
|
||||||
|
$mHelper = new MoonCalc;
|
||||||
|
$esiHelper = new Esi;
|
||||||
|
/*
|
||||||
//For each of the observers, send a job to fetch the mining ledger
|
//For each of the observers, send a job to fetch the mining ledger
|
||||||
foreach($observers as $obs) {
|
foreach($observers as $obs) {
|
||||||
//Dispatch the mining taxes ledger jobs
|
//Dispatch the mining taxes ledger jobs
|
||||||
FetchMiningTaxesLedgersJob::dispatch($config['primary'], $config['corporation'], $obs->observer_id)->onQueue('miningtaxes');
|
FetchMiningTaxesLedgersJob::dispatch($config['primary'], $config['corporation'], $obs->observer_id)->onQueue('miningtaxes');
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
$refreshToken = $esiHelper->GetRefreshToken($config['primary']);
|
||||||
|
$esi = $esiHelper->SetupEsiAuthentication($refreshToken);
|
||||||
|
|
||||||
|
foreach($observers as $obs) {
|
||||||
|
try {
|
||||||
|
$response = $esi->invoke('get', '/corporation/{corporation_id}/mining/observers/{observer_id}/', [
|
||||||
|
'corporation_id' => $config['corporation'],
|
||||||
|
'observer_id' => $obs->observer_id,
|
||||||
|
]);
|
||||||
|
} catch(RequestFailedException $e) {
|
||||||
|
Log::warning('Failed to get the mining ledger in FetchMiningTaxesLedgersCommand for observer id: ' . $this->observerId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ledgets = json_decode($ledgers);
|
||||||
|
|
||||||
|
foreach($ledgers as $ledger) {
|
||||||
|
//Get some basic information we need to work with
|
||||||
|
$charName = $lookup->CharacterIdToName($ledger->character_id);
|
||||||
|
//Get the type name from the ledger ore stuff
|
||||||
|
$typeName = $lookup->ItemIdToName($ledger->type_id);
|
||||||
|
//Decode the date and store it.
|
||||||
|
//$updated = $esiHelper->DecodeDate($ledger->last_updated);
|
||||||
|
|
||||||
|
$price = $mHelper->CalculateOrePrice($ledger->type_id);
|
||||||
|
$amount = $price * $ledger->quantity;
|
||||||
|
|
||||||
|
//Insert or update the entry in the database
|
||||||
|
$item = Ledger::updateOrCreate([
|
||||||
|
'character_id' => $ledger->character_id,
|
||||||
|
'character_name' => $charName,
|
||||||
|
'observer_id' => $this->observerId,
|
||||||
|
'last_updated' => $ledger->last_updated,
|
||||||
|
'type_id' => $ledger->type_id,
|
||||||
|
'ore_name' => $typeName,
|
||||||
|
'quantity' => $ledger->quantity,
|
||||||
|
'price' => $amount,
|
||||||
|
], [
|
||||||
|
'character_id' => $ledger->character_id,
|
||||||
|
'character_name' => $charName,
|
||||||
|
'observer_id' => $this->observerId,
|
||||||
|
'last_updated' => $ledger->last_updated,
|
||||||
|
'type_id' => $ledger->type_id,
|
||||||
|
'ore_name' => $typeName,
|
||||||
|
'quantity' => $ledger->quantity,
|
||||||
|
'price' => $amount,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Clean up old data
|
||||||
|
Ledger::where(['updated_at', '<', Carbon::now()->subDays(120)])->delete();
|
||||||
|
|
||||||
//Return 0
|
//Return 0
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use Illuminate\Queue\SerializesModels;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
//App Library
|
//App Library
|
||||||
use Seat\Eseye\Exceptions\RequestionFailedException;
|
use Seat\Eseye\Exceptions\RequestFailedException;
|
||||||
use App\Library\Esi\Esi;
|
use App\Library\Esi\Esi;
|
||||||
use App\Library\Helpers\LookupHelper;
|
use App\Library\Helpers\LookupHelper;
|
||||||
use App\Library\Moons\MoonCalc;
|
use App\Library\Moons\MoonCalc;
|
||||||
|
|||||||
Reference in New Issue
Block a user