moon mailer update
This commit is contained in:
@@ -84,15 +84,6 @@ class CorpJournalCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
foreach($corps as $corp) {
|
||||
if($corp->corporation_id != 98287666) {
|
||||
$charId = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first();
|
||||
$finance->GetWalletJournal(1, $charId->character_id);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//Mark the job as finished
|
||||
$task->SetStopStatus();
|
||||
}
|
||||
|
||||
@@ -59,20 +59,85 @@ class MoonMailerCommand extends Command
|
||||
$task->SetStartStatus();
|
||||
|
||||
//Declare the moon calc class variable to utilize the library to update the price
|
||||
$moonCalc = new MoonCalc();
|
||||
$moonCalc = new MoonCalc;
|
||||
$mailer = new MoonMailer;
|
||||
|
||||
//Create other variables
|
||||
$price = null;
|
||||
$body = null;
|
||||
|
||||
//Get all of the moons from the rental list
|
||||
$rentals = MoonRent::all();
|
||||
|
||||
//Get today's date.
|
||||
$today = Carbon::now();
|
||||
$today->second = 1;
|
||||
$today->minute = 0;
|
||||
$today->hour = 0;
|
||||
|
||||
//Get all contacts from the rentals group
|
||||
$contacts = MoonRent::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
|
||||
$rentals = $moonMailer->GetRentalMoons($contact);
|
||||
|
||||
//Totalize the cost of the moons
|
||||
$cost = $moonMailer->TotalizeMoonCost($rentals);
|
||||
|
||||
//Get the list of moons in a list format
|
||||
$listItems = $moonMailer->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 " . $cost . "<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
|
||||
$mail = new JobSendEveMail;
|
||||
$mail->sender = 93738489;
|
||||
$mail->subject = "Warped Intentions Moon Rental Payment Due";
|
||||
$mail->body = $body;
|
||||
$mail->recipient = (int)$contact;
|
||||
$mail->recipient_type = 'character';
|
||||
|
||||
//Dispatch the job and cycle to the next moon rental
|
||||
SendEveMailJob::dispatch($mail);
|
||||
|
||||
//After the mail is dispatched, saved the sent mail record,
|
||||
$sentmail = new SentMail;
|
||||
$sentmail->sender = $mail->sender;
|
||||
$sentmail->subject = $mail->subject;
|
||||
$sentmail->body = $mail->body;
|
||||
$sentmail->recipient = $mail->recipient;
|
||||
$sentmail->recipient_type = $mail->recipient_type;
|
||||
$sentmail->save();
|
||||
|
||||
//Delete the record from the database
|
||||
foreach($rentals as $rental) {
|
||||
if($today->greaterThanOrEqualTo($rental->RentalEnd)) {
|
||||
MoonRent::where(['id' => $rental->id])->delete();
|
||||
}
|
||||
|
||||
//Mark the moon as not paid for the next month
|
||||
Moon::where([
|
||||
'System' => $rental->System,
|
||||
'Planet' => $rental->Planet,
|
||||
'Moon' => $rental->Moon,
|
||||
])->update([
|
||||
'Paid' => 'No',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
//Get all of the moons from the rental list
|
||||
$rentals = MoonRent::all();
|
||||
|
||||
//Update the price for all moon rentals before sending out the mail
|
||||
foreach($rentals as $rental) {
|
||||
//Get the contents of the moon to re-price it out
|
||||
@@ -136,6 +201,7 @@ class MoonMailerCommand extends Command
|
||||
]);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
//Mark the job as finished
|
||||
$task->SetStopStatus();
|
||||
|
||||
@@ -5,33 +5,88 @@ namespace App\Library\Moons;
|
||||
//Jobs
|
||||
use App\Jobs\SendEveMailJob;
|
||||
|
||||
//Library
|
||||
use App\Library\Moons\MoonCalc;
|
||||
|
||||
//Models
|
||||
use App\Models\Jobs\JobSendEveMail;
|
||||
use App\Models\Mail\SentMail;
|
||||
use App\Models\Moon\Moon;
|
||||
use App\Models\Moon\MoonRent;
|
||||
|
||||
class MoonMailer {
|
||||
|
||||
public function GetRentalMoons() {
|
||||
|
||||
public function GetMoonList(MoonRent $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 = 'System: ' . $moon->System;
|
||||
$temp .= 'Planet: ' . $moon->Planet;
|
||||
$temp .= 'Moon: ' . $moon->Moon;
|
||||
//Push the new string onto the array list
|
||||
array_push($list, $temp);
|
||||
}
|
||||
|
||||
//Return the list
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function TotalizeMoonCost($moons) {
|
||||
public function GetRentalMoons($contact) {
|
||||
$rentals = MoonRent::where([
|
||||
'Contact' => $contact,
|
||||
])->get();
|
||||
|
||||
return $rentals;
|
||||
}
|
||||
|
||||
public function SendMail($recipient, $moons, $dueDate) {
|
||||
|
||||
$body = '';
|
||||
|
||||
$mail = new EveMail;
|
||||
$mail->sender = 93738489;
|
||||
$mail->subject = 'Moon Rental';
|
||||
$mail->body = $body;
|
||||
$mail->recipient = (int)$recipient;
|
||||
$mail->recipient_type = 'character';
|
||||
$mail->save();
|
||||
|
||||
SendEveMailJob::dispatch($mail);
|
||||
public function TotalizeMoonCost($rentals) {
|
||||
//Delcare variables and classes
|
||||
$moonCalc = new MoonCalc;
|
||||
$totalCost = 0.00;
|
||||
|
||||
foreach($rentals as $rental) {
|
||||
$moon = Moon::where([
|
||||
'System' => $rental->System,
|
||||
'Planet' => $rental->Planet,
|
||||
'Moon' => $rental->Moon,
|
||||
])->first();
|
||||
|
||||
//Get the updated price for the moon
|
||||
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
|
||||
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
|
||||
|
||||
if($rental->Type == 'alliance') {
|
||||
$totalCost += $price['alliance'];
|
||||
} else{
|
||||
$totalCost += $price['outofalliance'];
|
||||
}
|
||||
}
|
||||
|
||||
//Return the total cost back to the calling function
|
||||
return $totalCost;
|
||||
}
|
||||
|
||||
public 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user