diff --git a/app/Console/Commands/Assets/GetAssets.php b/app/Console/Commands/Assets/GetAssets.php index dfb9f01cc..e5b2854f7 100644 --- a/app/Console/Commands/Assets/GetAssets.php +++ b/app/Console/Commands/Assets/GetAssets.php @@ -23,7 +23,6 @@ use App\Models\Jobs\JobProcessAsset; use App\Models\Esi\EsiScope; use App\Models\Esi\EsiToken; - class GetAssetsCommand extends Command { /** diff --git a/app/Console/Commands/Logistics/GetEveContracts.php b/app/Console/Commands/Logistics/GetEveContracts.php new file mode 100644 index 000000000..3be3f459e --- /dev/null +++ b/app/Console/Commands/Logistics/GetEveContracts.php @@ -0,0 +1,122 @@ +SetStartStatus(); + + //Setup the esi authentication container + $config = config('esi'); + + //Declare some variables + $charId; + $corpId; + + //Esi Scope Check + $esiHelper = new Esi(); + $contractScope = $esiHelper->HaveEsiScope($charId, 'esi-contracts.read_corporation_contracts.v1'); + + if($contractScope == false) { + Log::critical('Scope check for esi contracts failed.'); + return null; + } + + // Disable all caching by setting the NullCache as the + // preferred cache handler. By default, Eseye will use the + // FileCache. + $configuration = Configuration::getInstance(); + $configuration->cache = NullCache::class; + + //Get the refresh token from the database + $token = EsiToken::where(['character_id' => $charId])->get(['refresh_token']); + //Create the authentication container + $authentication = new EsiAuthentication([ + 'client_id' => $config['client_id'], + 'secret' => $config['secret'], + 'refresh_token' => $token[0]->refresh_token, + ]); + + $esi = new Eseye($authentication); + + try { + $contracts = $esi->page(1) + ->invoke('get', '/corporations/{corporation_id}/contracts/', [ + 'corporation_id' => $corpId, + ]); + } catch (RequestFailedException $e) { + Log::critical("Failed to get the contracts list."); + return null; + } + + $pages = $contracts->pages; + + for($i = 1; $i <= $pages; $i++) { + $job = new JobProcessEveContracts; + $job->charId = $charId; + $job->corpId = $corpId; + $job->page = $i; + ProcessEveContractsJob::dispatch($job)->onQueue('default'); + } + + //Mark the job as finished + $task->SetStopStatus(); + } +} diff --git a/app/Http/Controllers/Logistics/LogisticsController.php b/app/Http/Controllers/Logistics/LogisticsController.php new file mode 100644 index 000000000..913b51677 --- /dev/null +++ b/app/Http/Controllers/Logistics/LogisticsController.php @@ -0,0 +1,85 @@ + 'outstanding', + ])->get(); + + $inProgress = EveContract::where([ + 'status' => 'in_progress', + ])->get(); + + $cancelled = EveContract::where([ + 'status' => 'cancelled', + ])->get(); + + $failed = EveContract::where([ + 'status' => 'failed', + ])->get(); + + $deleted = EveContract::where([ + 'status' => 'deleted', + ])->get(); + + $finished = EveContract::where([ + 'status' => 'finished', + ])->get(); + + return view('logistics.display.contracts')->with('open', $open) + ->with('inProgress', $inProgress) + ->with('cancelled', $cancelled) + ->with('failed', $failed) + ->with('deleted', $deleted) + ->with('finished', $finished); + } + + /** + * Function to display current contracts user holds + */ + public function displayUserContracts() { + + } + + /** + * Function to calculate details needing to be set for contracts + */ + public function displayContractForm() { + + } + + /** + * Function to calculate details needing to be set for contracts + */ + public function displayContractDetails(Request $request) { + $this->validate($request, [ + 'start_location', + 'end_location', + 'type', + 'collateral', + ]); + + + } +} diff --git a/app/Jobs/ProcessEveContractsJob.php b/app/Jobs/ProcessEveContractsJob.php new file mode 100644 index 000000000..3ac82b1c1 --- /dev/null +++ b/app/Jobs/ProcessEveContractsJob.php @@ -0,0 +1,76 @@ +charId = $jpc->charId; + $this->corpId = $jpc->corpId; + $this->page = $jpc->page; + + //Set the connection for the job + $this->connection = 'redis'; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + //Declare the contracts helper + $cHelper = new EveContractsHelper($this->charId, $this->corpId, $this->page); + + $contracts = $cHelper->GetContractsByPage(); + + foreach($contracts as $contract) { + $cHelper->ProcessContract($contract); + } + + //After the job is completed, delete the job + $this->delete(); + } +} diff --git a/app/Library/Contracts/EveContractsHelper.php b/app/Library/Contracts/EveContractsHelper.php new file mode 100644 index 000000000..317cbe89b --- /dev/null +++ b/app/Library/Contracts/EveContractsHelper.php @@ -0,0 +1,251 @@ +charId = $char; + $this->corpId = $corp; + $this->page = $pg; + } + + /** + * Get a page of Contracts to store in the database + */ + public function GetContractsByPage() { + // Disable all caching by setting the NullCache as the + // preferred cache handler. By default, Eseye will use the + // FileCache. + $configuration = Configuration::getInstance(); + $configuration->cache = NullCache::class; + + //Setup the esi authentication container + $config = config('esi'); + //Get the refresh token from the database + $token = EsiToken::where(['character_id' => $this->charId])->get(['refresh_token']); + $authentication = new EsiAuthentication([ + 'client_id' => $config['client_id'], + 'secret' => $config['secret'], + 'refresh_token' => $token[0]->refresh_token, + ]); + //Setup the ESI variable + $esi = new Eseye($authentication); + + try { + $contracts = $esi->page($this->page) + ->invoke('get', '/corporations/{corporation_id}/contracts/', [ + 'corporation_id' => $this->corpId, + ]); + } catch(RequestFailedException $e) { + Log::critical("Failed to get a page of contracts from ESI."); + $contracts = null; + } + + return $contracts; + } + + /** + * Store a new contract record in the database + */ + public function StoreNewContract($contract) { + //Declare esi helper for decoding the date + $esiHelper = new Esi; + + //See if we find the contract in the database + $found = LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->count(); + //If nothing is found we need to store the contract + if($found == 0) { + $logi = new LogisticsContract; + $logi->acceptor_id = $contract->acceptor_id; + $logi->assignee_id = $contract->assignee_id; + $logi->availability = $contract->availability; + if(isset($contract->buyout)) { + $logi->buyout = $contract->buyout; + } + if(isset($contract->collateral)) { + $logi->collateral = $contract->collateral; + } + $logi->contract_id = $contract->contract_id; + if(isset($contract->date_accepted)) { + $logi->date_accepted = $esiHelper->DecodeDate($contract->date_accepted); + } + if(isset($contract->date_completed)) { + $logi->date_completed = $esiHelper->DecodeDate($contract->date_completed); + } + $logi->date_expired = $contract->date_expired; + $logi->date_issued = $contract->date_issued; + if(isset($contract->days_to_complete)) { + $logi->days_to_complete = $contract->days_to_complete; + } + if(isset($contract->end_location_id)) { + $logi->end_location_id = $contract->end_location_id; + } + $logi->for_corporation = $contract->for_corporation; + $logi->issuer_corporation_id = $contract->issuer_corporation_id; + $logi->issuer_id = $contract->issuer_id; + if(isset($contract->price)) { + $logi->price = $contract->price; + } + if(isset($contract->reward)) { + $logi->reward = $contract->reward; + } + if(isset($contract->start_location_id)) { + $logi->start_location_id = $contract->start_location_id; + } + $logi->status = $contract->status; + if(isset($contract->title)) { + $logi->title = $contract->title; + } + $logi->status = $contract->status; + if(isset($contract->volume)) { + $logi->volume = $contract->volume; + } + $logi->save(); + } else { //If the contract is found, then call the function to update the contract + $this->UpdateLogisticsContract($contract); + } + } + + public function UpdateLogisticsContract($contract) { + //Declare Esi Helper function + $esiHelper = new Esi; + + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'acceptor_id' => $contract->acceptor_id, + 'assignee_id' => $contract->assignee_id, + 'availability' => $contract->availability, + 'date_expired' => $esiHelper->DecodeDate($contract->date_expired), + 'date_issued' => $esiHelper->DecodeDate($contract->date_issued), + 'for_corporation' => $contract->for_corporation, + 'issuer_corporation_id' => $contract->issuer_corporation_id, + 'issuer_id' => $contract->issuer_id, + 'status' => $contract->status, + ]); + + if(isset($contract->buyout)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'buyout' => $contract->buyout, + ]); + } + + if(isset($contract->collateral)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'collateral' => $contract->collateral, + ]); + } + + if(isset($contract->date_accepted)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'date_accepted' => $esiHelper->DecodeDate($contract->date_accepted), + ]); + } + + if(isset($contract->date_completed)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'date_completed' => $esiHelper->DecodeDate($contract->date_completed), + ]); + } + + if(isset($contract->days_to_complete)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'days_to_complete' => $contract->days_to_complete, + ]); + } + + if(isset($contract->end_location_id)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'end_location_id' => $contract->end_location_id, + ]); + } + + if(isset($contract->price)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'price' => $contract->price, + ]); + } + + if(isset($contract->reward)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'reward' => $contract->reward, + ]); + } + + if(isset($contract->start_location_id)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'start_location_id' => $contract->start_location_id, + ]); + } + + if(isset($contract->title)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'title' => $contract->title, + ]); + } + + if(isset($contract->volume)) { + LogisticsContract::where([ + 'contract_id' => $contract->contract_id, + ])->update([ + 'volume' => $contract->voluem, + ]); + } + } + + public function PurgeOldContracts() { + $date = Carbon::now(); + + LogisticsContract::where('date_expired', '<', $date)->delete(); + } + +} + +?> \ No newline at end of file diff --git a/app/Models/Contracts/EveContract.php b/app/Models/Contracts/EveContract.php new file mode 100644 index 000000000..bc44490b2 --- /dev/null +++ b/app/Models/Contracts/EveContract.php @@ -0,0 +1,43 @@ +string('contract_id')->unique(); + $table->string('acceptor_id'); + $table->string('assignee_id'); + $table->string('availability'); + $table->string('buyout')->nullable(); + $table->string('collateral')->nullable(); + $table->dateTime('date_accepted')->nullable(); + $table->dateTime('date_completed')->nullable(); + $table->dateTime('date_expired'); + $table->dateTime('date_issued'); + $table->integer('days_to_complete')->nullable(); + $table->string('end_location_id')->nullable(); + $table->boolean('for_corporation'); + $table->string('issuer_corporation_id'); + $table->string('issuer_id'); + $table->decimal('price', 20, 2)->default(0.00); + $table->decimal('reward', 20, 2)->default(0.00); + $table->string('start_location_id')->nullable(); + $table->string('status'); + $table->string('title')->nullalbe(); + $table->decimal('volume', 20, 2)->default(0.00); + $table->timestamps(); + }); + } + + if(!Schema::hasTable('logistics_contracts')) { + Schema::create('logistics_contracts', function (Blueprint $table) { + $table->increments('id'); + $table->string('contract_id'); + $table->string('accepted')->default('No'); + $table->string('status')->default('N/A'); + }); + } + + if(!Schema::hasTable('solar_systems')) { + Schema::create('solar_systems', function (Blueprint $table) { + $table->increments('id'); + $table->string('name'); + $table->string('solar_system_id')->unique(); + }); + } + + if(!Schema::hasTable('solar_system_distances')) { + Schema::create('solar_system_distances', function (Blueprint $table) { + $table->increments('id'); + $table->string('start_id'); + $table->string('start_name'); + $table->string('end_id'); + $table->string('end_name'); + $table->decimal('distance', 20, 6); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('eve_contracts'); + Schema::dropIfExists('logistics_contracts'); + Schema::dropIfExists('solar_systems'); + Schema::dropIfExists('solar_system_distances'); + } +} diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index dc02dfb11..fce8549f0 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -279,7 +279,7 @@ class ClassLoader */ public function setApcuPrefix($apcuPrefix) { - $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; } /** @@ -377,7 +377,7 @@ class ClassLoader $subPath = $class; while (false !== $lastPos = strrpos($subPath, '\\')) { $subPath = substr($subPath, 0, $lastPos); - $search = $subPath.'\\'; + $search = $subPath . '\\'; if (isset($this->prefixDirsPsr4[$search])) { $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); foreach ($this->prefixDirsPsr4[$search] as $dir) { diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index e7c1632ab..55e5d025a 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -8,6 +8,7 @@ $baseDir = dirname($vendorDir); return array( 'App\\Console\\Commands\\CleanStaleDataCommand' => $baseDir . '/app/Console/Commands/Data/CleanStaleDataCommand.php', 'App\\Console\\Commands\\GetAssetsCommand' => $baseDir . '/app/Console/Commands/Assets/GetAssets.php', + 'App\\Console\\Commands\\GetContracts' => $baseDir . '/app/Console/Commands/Logistics/GetContracts.php', 'App\\Console\\Commands\\GetCorpsCommand' => $baseDir . '/app/Console/Commands/Corps/GetCorps.php', 'App\\Console\\Commands\\GetStructuresCommand' => $baseDir . '/app/Console/Commands/Structures/GetStructures.php', 'App\\Console\\Commands\\HoldingFinancesCommand' => $baseDir . '/app/Console/Commands/Finances/HoldingFinances.php', @@ -42,6 +43,7 @@ return array( 'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . '/app/Http/Middleware/VerifyCsrfToken.php', 'App\\Jobs\\ProcessAssetsJob' => $baseDir . '/app/Jobs/ProcessAssetsJob.php', + 'App\\Jobs\\ProcessContractsJob' => $baseDir . '/app/Jobs/ProcessContractsJob.php', 'App\\Jobs\\ProcessStructureJob' => $baseDir . '/app/Jobs/ProcessStructureJob.php', 'App\\Jobs\\ProcessWalletJournalJob' => $baseDir . '/app/Jobs/ProcessWalletJournalJob.php', 'App\\Jobs\\ProcessWalletTransactionJob' => $baseDir . '/app/Jobs/ProcessWallettransactionJob.php', @@ -58,11 +60,13 @@ return array( 'App\\Library\\Finances\\PlayerDonation' => $baseDir . '/app/Library/Finances/PlayerDonation.php', 'App\\Library\\Finances\\ReprocessingTax' => $baseDir . '/app/Library/Finances/ReprocessingTax.php', 'App\\Library\\Finances\\StructureIndustryTax' => $baseDir . '/app/Library/Finances/StructureIndustryTax.php', + 'App\\Library\\Logistics\\ContractsHelper' => $baseDir . '/app/Library/Logistics/ContractsHelper.php', 'App\\Library\\Lookups\\LookupHelper' => $baseDir . '/app/Library/Lookups/LookupHelper.php', 'App\\Library\\Moons\\MoonCalc' => $baseDir . '/app/Library/Moons/MoonCalc.php', 'App\\Library\\SRP\\SRPHelper' => $baseDir . '/app/Library/SRP/SRPHelper.php', 'App\\Library\\Structures\\StructureHelper' => $baseDir . '/app/Library/Structures/StructureHelper.php', 'App\\Library\\Taxes\\TaxesHelper' => $baseDir . '/app/Library/Taxes/TaxesHelper.php', + 'App\\LogisticsContract' => $baseDir . '/app/Models/Logistics/LogisticsContract.php', 'App\\Models\\Admin\\AllowedLogin' => $baseDir . '/app/Models/Admin/AllowedLogin.php', 'App\\Models\\Character\\CharacterClone' => $baseDir . '/app/Models/Charcter/CharacterClone.php', 'App\\Models\\Config' => $baseDir . '/app/Models/Moon/Config.php', @@ -85,6 +89,7 @@ return array( 'App\\Models\\Finances\\ReprocessingTaxJournal' => $baseDir . '/app/Models/Finances/ReprocessingTaxJournal.php', 'App\\Models\\Finances\\StructureIndustryTaxJournal' => $baseDir . '/app/Models/Finances/StructureIndustryTaxJournal.php', 'App\\Models\\Jobs\\JobProcessAsset' => $baseDir . '/app/Models/Jobs/JobProcessAsset.php', + 'App\\Models\\Jobs\\JobProcessContracts' => $baseDir . '/app/Models/Jobs/JobProcessContracts.php', 'App\\Models\\Jobs\\JobProcessStructure' => $baseDir . '/app/Models/Jobs/JobProcessStructure.php', 'App\\Models\\Jobs\\JobProcessWalletJournal' => $baseDir . '/app/Models/Jobs/JobProcessWalletJournal.php', 'App\\Models\\Jobs\\JobProcessWalletTransaction' => $baseDir . '/app/Models/Jobs/JobProcessWalletTransaction.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index a91eff6e0..dcea118b6 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -461,6 +461,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 public static $classMap = array ( 'App\\Console\\Commands\\CleanStaleDataCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Data/CleanStaleDataCommand.php', 'App\\Console\\Commands\\GetAssetsCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Assets/GetAssets.php', + 'App\\Console\\Commands\\GetContracts' => __DIR__ . '/../..' . '/app/Console/Commands/Logistics/GetContracts.php', 'App\\Console\\Commands\\GetCorpsCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Corps/GetCorps.php', 'App\\Console\\Commands\\GetStructuresCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Structures/GetStructures.php', 'App\\Console\\Commands\\HoldingFinancesCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Finances/HoldingFinances.php', @@ -495,6 +496,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => __DIR__ . '/../..' . '/app/Http/Middleware/VerifyCsrfToken.php', 'App\\Jobs\\ProcessAssetsJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessAssetsJob.php', + 'App\\Jobs\\ProcessContractsJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessContractsJob.php', 'App\\Jobs\\ProcessStructureJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessStructureJob.php', 'App\\Jobs\\ProcessWalletJournalJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessWalletJournalJob.php', 'App\\Jobs\\ProcessWalletTransactionJob' => __DIR__ . '/../..' . '/app/Jobs/ProcessWallettransactionJob.php', @@ -511,11 +513,13 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Library\\Finances\\PlayerDonation' => __DIR__ . '/../..' . '/app/Library/Finances/PlayerDonation.php', 'App\\Library\\Finances\\ReprocessingTax' => __DIR__ . '/../..' . '/app/Library/Finances/ReprocessingTax.php', 'App\\Library\\Finances\\StructureIndustryTax' => __DIR__ . '/../..' . '/app/Library/Finances/StructureIndustryTax.php', + 'App\\Library\\Logistics\\ContractsHelper' => __DIR__ . '/../..' . '/app/Library/Logistics/ContractsHelper.php', 'App\\Library\\Lookups\\LookupHelper' => __DIR__ . '/../..' . '/app/Library/Lookups/LookupHelper.php', 'App\\Library\\Moons\\MoonCalc' => __DIR__ . '/../..' . '/app/Library/Moons/MoonCalc.php', 'App\\Library\\SRP\\SRPHelper' => __DIR__ . '/../..' . '/app/Library/SRP/SRPHelper.php', 'App\\Library\\Structures\\StructureHelper' => __DIR__ . '/../..' . '/app/Library/Structures/StructureHelper.php', 'App\\Library\\Taxes\\TaxesHelper' => __DIR__ . '/../..' . '/app/Library/Taxes/TaxesHelper.php', + 'App\\LogisticsContract' => __DIR__ . '/../..' . '/app/Models/Logistics/LogisticsContract.php', 'App\\Models\\Admin\\AllowedLogin' => __DIR__ . '/../..' . '/app/Models/Admin/AllowedLogin.php', 'App\\Models\\Character\\CharacterClone' => __DIR__ . '/../..' . '/app/Models/Charcter/CharacterClone.php', 'App\\Models\\Config' => __DIR__ . '/../..' . '/app/Models/Moon/Config.php', @@ -538,6 +542,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Models\\Finances\\ReprocessingTaxJournal' => __DIR__ . '/../..' . '/app/Models/Finances/ReprocessingTaxJournal.php', 'App\\Models\\Finances\\StructureIndustryTaxJournal' => __DIR__ . '/../..' . '/app/Models/Finances/StructureIndustryTaxJournal.php', 'App\\Models\\Jobs\\JobProcessAsset' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessAsset.php', + 'App\\Models\\Jobs\\JobProcessContracts' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessContracts.php', 'App\\Models\\Jobs\\JobProcessStructure' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessStructure.php', 'App\\Models\\Jobs\\JobProcessWalletJournal' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessWalletJournal.php', 'App\\Models\\Jobs\\JobProcessWalletTransaction' => __DIR__ . '/../..' . '/app/Models/Jobs/JobProcessWalletTransaction.php',