removed moon stuff from console kernel
This commit is contained in:
@@ -1,216 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Moons;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\ProcessSendEveMailJob;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use Commands\Library\CommandHelper;
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
use App\Library\Esi\Esi;
|
|
||||||
use Seat\Eseye\Exceptions\RequestFailedException;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Moon\RentalMoon;
|
|
||||||
use App\Models\MoonRent\MoonRental;
|
|
||||||
use App\Models\Mail\SentMail;
|
|
||||||
|
|
||||||
class MoonMailerCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Next update will include checking for if the moon has been paid in advance.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'services:MoonMailer';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Mail out the moon rental bills automatically';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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('MoonMailer');
|
|
||||||
//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 = 1;
|
|
||||||
$today->minute = 0;
|
|
||||||
$today->hour = 0;
|
|
||||||
|
|
||||||
//Get the esi configuration
|
|
||||||
$config = config('esi');
|
|
||||||
|
|
||||||
//Get all contacts from the rentals group
|
|
||||||
$contacts = MoonRental::select('Contact')->groupBy('Contact')->get();
|
|
||||||
|
|
||||||
//For each of the contacts totalize the moon rental, and create the mail to send to them,
|
|
||||||
//then update parameters of the moon
|
|
||||||
foreach($contacts as $contact) {
|
|
||||||
//Get the moons the renter is renting. Also only get the moons which are not paid as of today
|
|
||||||
$rentals = MoonRental::where(['Contact' => $contact->Contact])->get();
|
|
||||||
|
|
||||||
//Totalize the cost of the moons
|
|
||||||
$cost = $this->TotalizeMoonCost($rentals);
|
|
||||||
|
|
||||||
//Get the list of moons in a list format
|
|
||||||
$listItems = $this->GetMoonList($rentals);
|
|
||||||
|
|
||||||
//Build the mail body
|
|
||||||
$body = "Moon Rent is due for the following moons:<br>";
|
|
||||||
foreach($listItems as $item) {
|
|
||||||
$body .= $item . "<br>";
|
|
||||||
}
|
|
||||||
$body .= "The price for the next month's rent is " . number_format($cost, 2, ".", ",") . "<br>";
|
|
||||||
$body .= "Please remit payment to Spatial Forces on the 1st should you continue to wish to rent the moon.<br>";
|
|
||||||
$body .= "Sincerely,<br>";
|
|
||||||
$body .= "Warped Intentions Leadership<br>";
|
|
||||||
|
|
||||||
//Dispatch the mail job
|
|
||||||
$subject = "Warped Intentions Moon Rental Payment Due for " . $today->englishMonth;
|
|
||||||
ProcessSendEveMailJob::dispatch($body, (int)$contact->Contact, 'character', $subject, $config['primary'])->onQueue('mail')->delay(Carbon::now()->addSeconds($delay));
|
|
||||||
//Increment the delay for the mail to not hit rate limits
|
|
||||||
$delay += 30;
|
|
||||||
|
|
||||||
//Update the moon as not being paid for the next month?
|
|
||||||
foreach($rentals as $rental) {
|
|
||||||
$previous = new Carbon($rental->Paid_Until);
|
|
||||||
|
|
||||||
if($today->greaterThanOrEqualTo($previous)) {
|
|
||||||
$this->UpdateNotPaid($rental);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Mark the job as finished
|
|
||||||
$task->SetStopStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function UpdateNotPaid(MoonRental $rental) {
|
|
||||||
MoonRental::where([
|
|
||||||
'System' => $rental->System,
|
|
||||||
'Planet'=> $rental->Planet,
|
|
||||||
'Moon'=> $rental->Moon,
|
|
||||||
])->update([
|
|
||||||
'Paid' => 'No',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function GetMoonList($moons) {
|
|
||||||
//Declare the variable to be used as a global part of the function
|
|
||||||
$list = array();
|
|
||||||
|
|
||||||
//For each of the moons, build the System Planet and Moon.
|
|
||||||
foreach($moons as $moon) {
|
|
||||||
$temp = 'Moon: ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon;
|
|
||||||
array_push($list, $temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return the list
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function GetRentalMoons($contact) {
|
|
||||||
$rentals = MoonRental::where([
|
|
||||||
'Contact' => $contact,
|
|
||||||
])->get();
|
|
||||||
|
|
||||||
return $rentals;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function TotalizeMoonCost($rentals) {
|
|
||||||
//Delcare variables and classes
|
|
||||||
$moonCalc = new MoonCalc;
|
|
||||||
$totalCost = 0.00;
|
|
||||||
$price = null;
|
|
||||||
|
|
||||||
//Create the date for today
|
|
||||||
$today = Carbon::now();
|
|
||||||
$today->second = 1;
|
|
||||||
$today->minute = 0;
|
|
||||||
$today->hour = 0;
|
|
||||||
|
|
||||||
foreach($rentals as $rental) {
|
|
||||||
$moon = RentalMoon::where([
|
|
||||||
'System' => $rental->System,
|
|
||||||
'Planet' => $rental->Planet,
|
|
||||||
'Moon' => $rental->Moon,
|
|
||||||
])->first();
|
|
||||||
|
|
||||||
//Create the date time object for the rental end
|
|
||||||
$end = new Carbon($rental->Paid_Until);
|
|
||||||
|
|
||||||
//If today is greater than the rental end, then calculate the moon cost
|
|
||||||
if($today->greaterThanOrEqualTo($end)) {
|
|
||||||
//Get the updated price for the moon
|
|
||||||
$price = $moonCalc->SpatialMoons($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
|
||||||
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
|
||||||
|
|
||||||
//Check the type and figure out which price to add in
|
|
||||||
if($rental->Type == 'alliance') {
|
|
||||||
$totalCost += $price['alliance'];
|
|
||||||
} else{
|
|
||||||
$totalCost += $price['outofalliance'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return the total cost back to the calling function
|
|
||||||
return $totalCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function GetRentalType($rentals) {
|
|
||||||
$alliance = 0;
|
|
||||||
$outofalliance = 0;
|
|
||||||
|
|
||||||
//Go through the data and log whether the renter is in the alliance,
|
|
||||||
//or the renter is out of the alliance
|
|
||||||
foreach($rentals as $rental) {
|
|
||||||
if($rental->Type == 'alliance') {
|
|
||||||
$alliance++;
|
|
||||||
} else {
|
|
||||||
$outofalliance++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Return the rental type
|
|
||||||
if($alliance > $outofalliance) {
|
|
||||||
return 'alliance';
|
|
||||||
} else {
|
|
||||||
return 'outofalliance';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Moons;
|
|
||||||
|
|
||||||
//Internal Library
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
//Jobs
|
|
||||||
use App\Jobs\ProcessSendEveMailJob;
|
|
||||||
use App\Jobs\Commands\Moons\MoonRentalInvoiceCreate;
|
|
||||||
|
|
||||||
//Library
|
|
||||||
use Commands\Library\CommandHelper;
|
|
||||||
|
|
||||||
//Models
|
|
||||||
use App\Models\Moon\MoonRental;
|
|
||||||
|
|
||||||
class RentalMoonCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'services:RentalMoons';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Queues up the jobs for the rental moons.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Declare variables
|
|
||||||
$delay = 0;
|
|
||||||
|
|
||||||
//Create the new command helper container
|
|
||||||
$task = new CommandHelper('RentalMoonCommand');
|
|
||||||
//Add the entry saying the job has started
|
|
||||||
$task->SetStartStatus();
|
|
||||||
|
|
||||||
//Get all of the contacts from the rentals group
|
|
||||||
$contacts = MoonRental::select('Contact')->groupBy('Contact')->get();
|
|
||||||
|
|
||||||
foreach($contacts as $contact) {
|
|
||||||
MoonRentalInvoiceCreate::dispatch($contact, $delay)->onQueue('moons');
|
|
||||||
|
|
||||||
//Increase the delay after each job to prevent mails from backing up later down the queue
|
|
||||||
$delay += 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set the job as completed
|
|
||||||
$task->SetStopStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Console\Commands\Moons;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use Commands\Library\CommandHelper;
|
|
||||||
|
|
||||||
use App\Library\Moons\MoonCalc;
|
|
||||||
|
|
||||||
class UpdateMoonPriceCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The name and signature of the console command.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'services:UpdateMoonPrice';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The console command description.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Update moon pricing on a scheduled basis';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
//Create the command helper container
|
|
||||||
$task = new CommandHelper('UpdateMoonPricing');
|
|
||||||
//Add the entry into the jobs table saying the job is starting
|
|
||||||
$task->SetStartStatus();
|
|
||||||
|
|
||||||
$moonCalc = new MoonCalc();
|
|
||||||
$moonCalc->FetchNewPrices();
|
|
||||||
|
|
||||||
//Mark the job as finished
|
|
||||||
$task->SetStopStatus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -49,18 +49,11 @@ class Kernel extends ConsoleKernel
|
|||||||
$schedule->command('services:HoldingJournal')
|
$schedule->command('services:HoldingJournal')
|
||||||
->hourlyAt('45')
|
->hourlyAt('45')
|
||||||
->withoutOverlapping();
|
->withoutOverlapping();
|
||||||
//Command to update moon rental pricing
|
|
||||||
$schedule->command('services:UpdateMoonPrice')
|
|
||||||
->hourlyAt('30');
|
|
||||||
|
|
||||||
//Get the corps within the alliance
|
//Get the corps within the alliance
|
||||||
$schedule->command('services:GetCorps')
|
$schedule->command('services:GetCorps')
|
||||||
->monthlyOn(1, '09:00');
|
->monthlyOn(1, '09:00');
|
||||||
|
|
||||||
//Update the moons, and send out mails for current moon rentals
|
|
||||||
$schedule->command('services:MoonMailer')
|
|
||||||
->monthlyOn(1, '00:01');
|
|
||||||
|
|
||||||
//Get the structures within the alliance and their information
|
//Get the structures within the alliance and their information
|
||||||
$schedule->command('services:GetStructures')
|
$schedule->command('services:GetStructures')
|
||||||
->dailyAt('09:00');
|
->dailyAt('09:00');
|
||||||
|
|||||||
Reference in New Issue
Block a user