diff --git a/app/Http/Controllers/Moons/MoonsAdminController.php b/app/Http/Controllers/Moons/MoonsAdminController.php index 62bb8584e..38072f289 100644 --- a/app/Http/Controllers/Moons/MoonsAdminController.php +++ b/app/Http/Controllers/Moons/MoonsAdminController.php @@ -16,13 +16,18 @@ use App\Models\Moon\Moon; use App\Models\Moon\OrePrice; use App\Models\Moon\Price; use App\Models\MoonRent\MoonRental; +use App\Models\Moon\AllianceMoon; use App\Models\Moon\AllianceMoonRequest; +use App\Models\Jobs\JobSendEveMail; //Library use App\Library\Moons\MoonCalc; use App\Library\Esi\Esi; use App\Library\Lookups\LookupHelper; +//Jobs +use App\Jobs\ProcessSendEveMailJob; + class MoonsAdminController extends Controller { public function __construct() { @@ -44,11 +49,19 @@ class MoonsAdminController extends Controller * Function to approve a moon request */ public function storeApprovedMoonRequest(Request $request) { + //Validate the input request $this->validate($request, [ 'id' => 'required', 'status' => 'required', + 'system' => 'required', + 'planet' => 'required', + 'moon' => 'required', ]); + //Get the configuration data to use later in the function + $config = config('esi'); + + //Update the alliance moon request to either approved or denied AllianceMoonRequest::where([ 'id' => $request->id, ])->update([ @@ -56,8 +69,38 @@ class MoonsAdminController extends Controller 'approver_name' => auth()->user()->getName(), 'approver_id' => auth()->user()->getId(), ]); - - return redirect('/moons/admin/display/request'); + + //Update the alliance moon in the table to the correct status + AllianceMoon::where([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + ])->update([ + 'Available' => 'Deployed', + ]); + + //Send an eve mail to the requestor stating they can set a moon up. + //Get the request data which holds all of the information for the request user + $moon = AllianceMoonRequest::where([ + 'id' => $request->id, + ])->get(); + //Setup the mail body + $body = 'The moon request for ' . $moon->System . ' - ' . $moon->Planet . ' - ' . $moon->Moon . ' has changed status.
'; + $body .= 'The request has been ' . $request->status . '.
'; + $body .= 'Please contact the FC Team should it be necessary to arrange a fleet to cover the structure drop.'; + $body .= 'Sincerely,
'; + $body .= 'Warped Intentions Leadership
'; + + //Setup the mail model + $mail = new JobSendEveMail; + $mail->sender = $config['primary']; + $mail->subject = 'Warped Intentions Moon Request'; + $mail->body = $body; + $mail->recipient = (int)$moon->requestor_id; + $mail->recipient_type = 'character'; + ProcessSendEveMailJob::dispatch($mail)->onQueue('mail'); + + return redirect('/moons/admin/display/request')->with('success', 'Moon has been approved, and mail has been sent out.'); } /** diff --git a/app/Http/Controllers/Moons/MoonsController.php b/app/Http/Controllers/Moons/MoonsController.php index 4ff330ca4..7a1275b14 100644 --- a/app/Http/Controllers/Moons/MoonsController.php +++ b/app/Http/Controllers/Moons/MoonsController.php @@ -136,6 +136,17 @@ class MoonsController extends Controller return redirct('/moons/display/request')->with('error', 'Region was not found.'); } + //Check to see if the moon is not available + $future = AllianceMoon::where([ + 'System' => $request->system, + 'Planet' => $request->planet, + 'Moon' => $request->moon, + ])->get(); + + if($future->Available != 'Available') { + return redirect('/moons/display/request')->with('error', 'The moon has already been reserved by another party.'); + } + //Create the new object to save into the database $moonRequest = new AllianceMoonRequest; diff --git a/resources/views/moons/admin/moonrequest.blade.php b/resources/views/moons/admin/moonrequest.blade.php index b3710b8e0..e2ad1d426 100644 --- a/resources/views/moons/admin/moonrequest.blade.php +++ b/resources/views/moons/admin/moonrequest.blade.php @@ -24,6 +24,9 @@ {{ $req->requestor_name }} {{ Form::hidden('id', $req->id) }} + {{ Form::hidden('system', $req->system) }} + {{ Form::hideen('planet', $req->planet) }} + {{ Form::hidden('moon', $req->moon) }} {{ Form::select('status', [ 'Approved' => 'Approved', 'Denied' => 'Denied',