flex structures before testing

This commit is contained in:
2019-12-06 21:19:17 -06:00
parent 5038eed34e
commit b78675718d
8 changed files with 227 additions and 5 deletions

View File

@@ -0,0 +1,135 @@
<?php
namespace App\Console\Commands;
//Internal Library
use Illuminate\Console\Command;
use Carbon\Carbon;
use DB;
//Jobs
use App\Jobs\ProcessSendEveMailJob;
//Library
use Commands\Library\CommandHelper;
//Models
use App\Models\Flex\FlexStructure;
use App\Models\Mail\SentMail;
use App\Models\Mail\EveMail;
class FlexStructureCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:FlexStructures';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Mail out reminder for flex structure bills';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Create the new command helper container
$task = new CommandHelper('FlexStructureMailer');
//Add the entry into the jobs table saying the job has started
$task->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:<br>";
foreach($structures as $structure) {
$body += "System: " . $structure->system . " - " . $structure->structure_type . ": " . $structure->structure_cost . " ISK<br>";
}
$body += "Total Cost: " . $totalCost;
$body += "Please remit payment to Spatial Forces by the 3rd of the month.<br>";
$body += "Sincerely,<br>";
$body += "Warped Intentions Leadership<br>";
//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();
}
}

View File

@@ -166,7 +166,7 @@ class MoonMailerCommand extends Command
$rentals = MoonRental::where([
'Contact' => $contact,
])->get();
dd($rentals);
return $rentals;
}

View File

@@ -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();

View File

@@ -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',
]);
}

View File

@@ -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}/', [

View File

@@ -21,7 +21,7 @@
</div>
<div class="form-group">
{{ Form::label('structure_type', 'Structure Type') }}
{{ Form::text('structure_type', '', ['class' => 'form-control']) }}
{{ Form::select('structure_type', '', ['class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('structure_cost', 'Structure Cost') }}

View File

@@ -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',

View File

@@ -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',