moon mailer rework 2

This commit is contained in:
2019-05-05 03:41:51 -05:00
parent d477efa766
commit 8259f4f0b1
5 changed files with 41 additions and 23 deletions

View File

@@ -17,7 +17,6 @@ use App\Library\Moons\MoonCalc;
//Models
use App\Models\Moon\Moon;
use App\Models\Moon\MoonRent;
use App\Models\Mail\SentMail;
use App\Models\Jobs\JobSendEveMail;
class MoonMailerCommand extends Command
@@ -59,11 +58,9 @@ class MoonMailerCommand extends Command
$task->SetStartStatus();
//Declare the moon calc class variable to utilize the library to update the price
$moonCalc = new MoonCalc;
$mailer = new MoonMailer;
//Create other variables
$price = null;
$body = null;
//Get today's date.
@@ -104,33 +101,18 @@ class MoonMailerCommand extends Command
$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();
//After the mail is dispatched, saved the sent mail record
$moonMailer->SaveSentRecord($mail->sender, $mail->subject, $mail->body, $mail->recipient, $mail->recipient_type);
//Delete the record from the database
foreach($rentals as $rental) {
if($today->greaterThanOrEqualTo($rental->RentalEnd)) {
MoonRent::where(['id' => $rental->id])->delete();
}
//Delete the moon rental
$moonMailer->DeleteMoonRental($rental, $today);
//Mark the moon as not paid for the next month
Moon::where([
'System' => $rental->System,
'Planet' => $rental->Planet,
'Moon' => $rental->Moon,
])->update([
'Paid' => 'No',
]);
$moonMailer->UpdateNotPaid($rental);
}
}

View File

@@ -2,6 +2,9 @@
namespace App\Library\Moons;
//Internal Library
use Carbon\Carbon;
//Jobs
use App\Jobs\SendEveMailJob;
@@ -15,6 +18,35 @@ use App\Models\Moon\Moon;
use App\Models\Moon\MoonRent;
class MoonMailer {
public function DeleteMoonRent(MoonRent $rental, Carbon $today) {
if($today->greaterThanOrEqualTo($rental->RentalEnd)) {
MoonRent::where(['id' => $rental->id])->delete();
}
}
public function PaidUntil(MoonRent $rental) {
return $rental->paid_until;
}
public function UpdateNotPaid(MoonRent $rental) {
Moon::where([
'System' => $rental->System,
'Planet'=> $rental->Planet,
'Moon'=> $rental->Moon,
])->update([
'Paid' => 'No',
]);
}
public 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();
}
public function GetMoonList(MoonRent $moons) {
//Declare the variable to be used as a global part of the function

View File

@@ -31,5 +31,7 @@ class Moon extends Model
'FourthQuantity',
'RentalCorp',
'RentalEnd',
'Paid',
'Paid_Until',
];
}

View File

@@ -24,5 +24,6 @@ class MoonRent extends Model
'RentalEnd',
'Contact',
'Price',
'Paid_Until',
];
}

View File

@@ -47,6 +47,7 @@ class CreateMoonsTable extends Migration
$table->string('Price');
$table->string('Type');
$table->string('Paid');
$table->string('Paid_Until')->nullable();
});
}
}