From b78675718d802999ab390724bb43f8184a399415 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Fri, 6 Dec 2019 21:19:17 -0600 Subject: [PATCH] flex structures before testing --- .../Commands/Flex/FlexStructureCommand.php | 135 ++++++++++++++++++ app/Console/Commands/Moons/MoonMailer.php | 2 +- app/Console/Kernel.php | 15 +- .../Controllers/Flex/FlexAdminController.php | 34 ++++- app/Library/Lookups/NewLookupHelper.php | 42 ++++++ resources/views/flex/add.blade.php | 2 +- vendor/composer/autoload_classmap.php | 1 + vendor/composer/autoload_static.php | 1 + 8 files changed, 227 insertions(+), 5 deletions(-) create mode 100644 app/Console/Commands/Flex/FlexStructureCommand.php diff --git a/app/Console/Commands/Flex/FlexStructureCommand.php b/app/Console/Commands/Flex/FlexStructureCommand.php new file mode 100644 index 000000000..740282c21 --- /dev/null +++ b/app/Console/Commands/Flex/FlexStructureCommand.php @@ -0,0 +1,135 @@ +SetStartStatus(); + + //Create other variables + $body = null; + $delay = 5; + + //Get today's date + $today = Carbon::now(); + $today->second = 2; + $today->minute = 0; + $today->hour = 0; + + //Get the esi configuration + $config = config('esi'); + + //Get all of the contacts for the flex structures + $contacts = FlexStructure::select('requestor_id')->orderBy('requestor_id')->get(); + + //For each of the contacts, send a reminder mail about the total of the structures they are paying for + foreach($contacts as $contact) { + //Get all of the structures for requestor + $structures = FlexStructure::where([ + 'requestor_id' => $contact, + ])->get(); + + //Totalize the total cost of everything + $totalCost = $this->TotalizeCost($structures); + + //Build the body of the mail + $body = "Flex Structure Overhead Cost is due for the following structures:
"; + foreach($structures as $structure) { + $body += "System: " . $structure->system . " - " . $structure->structure_type . ": " . $structure->structure_cost . " ISK
"; + } + $body += "Total Cost: " . $totalCost; + $body += "Please remit payment to Spatial Forces by the 3rd of the month.
"; + $body += "Sincerely,
"; + $body += "Warped Intentions Leadership
"; + + //Dispatch the mail job + $mail = new EveMail; + $mail->sender = $config['primary']; + $mail->subject = "Warped Intentions Flex Structures Payment Due for " . $today->englishMonth; + $mail->body = $body; + $mail->recipient = (int)$structure->requestor_id; + $mail->recipient_type = 'character'; + ProcessSendEveMailJob::dispatch($mail)->onQueueu('mail')->delay($delay); + + //Increment the delay for the mail to not hit the rate limits + $delay += 60; + + //After the mail is dispatched, save the sent mail record + $this->SaveSentRecord($mail->sender, $mail->subject, $mail->body, $mail->recipient, $mail->recipient_type); + } + + //Mark the job as finished + $task->SetStopStatus(); + } + + private function TotalizeCost($structures) { + //Declare the total cost + $totalCost = 0.00; + + foreach($structures as $structure) { + $totalCost += $structure->structure_cost; + } + + return $totalCost; + } + + private function SaveSentRecord($sender, $subject, $body, $recipient, $recipientType) { + $sentmail = new SentMail; + $sentmail->sender = $sender; + $sentmail->subject = $subject; + $sentmail->body = $body; + $sentmail->recipient = $recipient; + $sentmail->recipient_type = $recipientType; + $sentmail->save(); + } +} diff --git a/app/Console/Commands/Moons/MoonMailer.php b/app/Console/Commands/Moons/MoonMailer.php index e8dcc6695..e5382cd3b 100644 --- a/app/Console/Commands/Moons/MoonMailer.php +++ b/app/Console/Commands/Moons/MoonMailer.php @@ -166,7 +166,7 @@ class MoonMailerCommand extends Command $rentals = MoonRental::where([ 'Contact' => $contact, ])->get(); - dd($rentals); + return $rentals; } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 568dae49f..8c5f1aaa2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -24,6 +24,7 @@ class Kernel extends ConsoleKernel Commands\GetStructuresCommand::class, Commands\GetAssetsCommand::class, Commands\PurgeUsers::class, + Commands\FlexStructureCommand::class, ]; /** @@ -34,29 +35,41 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { + //Command to get the holding journal finances $schedule->command('services:HoldingJournal') ->hourly() ->withoutOverlapping(); + //Command to update moon rental pricing $schedule->command('services:UpdateMoonPrice') ->hourly() ->withoutOverlapping(); + //Get the corps within the alliance $schedule->command('services:GetCorps') ->monthlyOn(1, '09:00') ->withoutOverlapping(); + //Update the moons, and send out mails for current moon rentals $schedule->command('services:MoonMailer') ->monthlyOn(1, '00:01') ->withoutOverlapping(); + //Get the structures within the alliance and their information $schedule->command('services:GetStructures') ->dailyAt('09:00') ->withoutOverlapping(); + //Get the assets for the alliance. Only saves the Liquid Ozone for jump bridges $schedule->command('services:GetAssets') ->hourlyAt('22') ->withoutOverlapping(); + //Clean old data from the database $schedule->command('services:CleanData') - ->monthlyOn(1, '18:00'); + ->monthlyOn(15, '18:00'); + //Purge users from the database which don't belong and reset the user roles as necessary $schedule->command('services:PurgeUsers') ->dailyAt('23:00') ->withoutOverlapping(); + //Mail about payments for flex structures + $schedule->command('services:FlexStructures') + ->monthlyOn(2, '00:01') + ->withoutOverlapping(); //Horizon Graph Schedule $schedule->command('horizon:snapshot')->everyFiveMinutes(); diff --git a/app/Http/Controllers/Flex/FlexAdminController.php b/app/Http/Controllers/Flex/FlexAdminController.php index 230f0e778..cdbb53129 100644 --- a/app/Http/Controllers/Flex/FlexAdminController.php +++ b/app/Http/Controllers/Flex/FlexAdminController.php @@ -48,9 +48,37 @@ class FlexAdminController extends Controller */ public function addFlexStructure(Request $request) { $this->validate($request, [ - + 'requestor_name' => 'required', + 'requestor_corp_name' => 'required', + 'system' => 'required', + 'structure_type' => 'required', + 'structure_cost' => 'required', ]); + //Delcare variables and classes + $lookup = new NewLookupHelper; + + //From the character name find the character id + $charId = $lookup->CharacterNameToId($request->requestor_name); + + //From the corporation name find the corporation id + $corpId = $lookup->CorporationNameToId($request->requestor_corp_name); + + //From the system name find the system id + $systemId = $lookup->SystemNameToId($request->system); + + //Create the database model + $flex = new FlexStructure; + $flex->requestor_id = $charId; + $flex->requestor_name = $request->requestor_name; + $flex->requestor_corp_id = $corpId; + $flex->requestor_corp_name = $request->requestor_corp_name; + $flex->system_id = $systemId; + $flex->system = $request->system; + $flex->structure_type = $request->structure_type; + $flex->structure_cost = $request->structure_cost; + $flex->save(); + return redirect('/flex/display')->with('success', 'Flex Structure Added.'); } @@ -59,7 +87,9 @@ class FlexAdminController extends Controller */ public function removeFlexStructure(Request $request) { $this->validate($request, [ - + 'requestor_name' => 'required', + 'system' => 'required', + 'structure_type' => 'required', ]); } diff --git a/app/Library/Lookups/NewLookupHelper.php b/app/Library/Lookups/NewLookupHelper.php index 29470dbe3..193a841ab 100644 --- a/app/Library/Lookups/NewLookupHelper.php +++ b/app/Library/Lookups/NewLookupHelper.php @@ -20,6 +20,7 @@ use App\Models\Lookups\CorporationToAlliance; use App\Models\Lookups\CharacterLookup; use App\Models\Lookups\CorporationLookup; use App\Models\Lookups\AllianceLookup; +use App\Models\Lookups\SolarSystem; class NewLookupHelper { @@ -31,6 +32,47 @@ class NewLookupHelper { $this->esi = new Eseye(); } + public function SystemNameToId($system) { + //Check if the solar system is stored in our own database first + $solarSystem = $this->LookupSolarSystem($system); + + if($solarSystem != null) { + return $solarSystem->solar_system_id; + } else { + try { + $response = $this->esi->setBody(array( + $system, + ))->invoke('post', '/universe/ids/'); + } catch(RequestFailedException $e) { + Log::warning('Failed to get system name from /universe/ids/ in lookup helper.'); + return null; + } + + if(isset($response->systems)) { + $this->StoreSolarSystem($response->systems[0]); + + return $response->systems[0]->id; + } else { + return null; + } + } + } + + private function LookupSolarSystem($system) { + $solar = SolarSystem::where([ + 'name' => $system, + ])->first(); + + return $solar; + } + + private function StoreSolarSystem($system) { + $solar = new SolarSystem; + $solar->name = $system->name; + $solar->solar_system_id = $system->id; + $solar->save(); + } + public function GetCharacterInfo($charId) { try { $character = $this->esi->invoke('get', '/characters/{character_id}/', [ diff --git a/resources/views/flex/add.blade.php b/resources/views/flex/add.blade.php index aff161376..2d4397cbf 100644 --- a/resources/views/flex/add.blade.php +++ b/resources/views/flex/add.blade.php @@ -21,7 +21,7 @@
{{ Form::label('structure_type', 'Structure Type') }} - {{ Form::text('structure_type', '', ['class' => 'form-control']) }} + {{ Form::select('structure_type', '', ['class' => 'form-control']) }}
{{ Form::label('structure_cost', 'Structure Cost') }} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 6678e427e..60d982e78 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -10,6 +10,7 @@ return array( 'App\\Console\\Commands\\CleanStaleDataCommand' => $baseDir . '/app/Console/Commands/Data/CleanStaleDataCommand.php', 'App\\Console\\Commands\\CorpFinances' => $baseDir . '/app/Console/Commands/Finances/CorpFinances.php', 'App\\Console\\Commands\\CorpMarketMail' => $baseDir . '/app/Console/Commands/Finances/CorpMarketMail.php', + 'App\\Console\\Commands\\FlexStructureCommand' => $baseDir . '/app/Console/Commands/Flex/FlexStructureCommand.php', 'App\\Console\\Commands\\GetAssetsCommand' => $baseDir . '/app/Console/Commands/Assets/GetAssets.php', 'App\\Console\\Commands\\GetCorpsCommand' => $baseDir . '/app/Console/Commands/Corps/GetCorps.php', 'App\\Console\\Commands\\GetStructuresCommand' => $baseDir . '/app/Console/Commands/Structures/GetStructures.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index dd21e3b94..832dd8341 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -474,6 +474,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Console\\Commands\\CleanStaleDataCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Data/CleanStaleDataCommand.php', 'App\\Console\\Commands\\CorpFinances' => __DIR__ . '/../..' . '/app/Console/Commands/Finances/CorpFinances.php', 'App\\Console\\Commands\\CorpMarketMail' => __DIR__ . '/../..' . '/app/Console/Commands/Finances/CorpMarketMail.php', + 'App\\Console\\Commands\\FlexStructureCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Flex/FlexStructureCommand.php', 'App\\Console\\Commands\\GetAssetsCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Assets/GetAssets.php', 'App\\Console\\Commands\\GetCorpsCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Corps/GetCorps.php', 'App\\Console\\Commands\\GetStructuresCommand' => __DIR__ . '/../..' . '/app/Console/Commands/Structures/GetStructures.php',