moons admin controller

This commit is contained in:
2019-02-15 23:55:27 -06:00
parent 3152b03113
commit 8db86ca313
2 changed files with 72 additions and 54 deletions

View File

@@ -55,7 +55,10 @@ class MoonsAdminController extends Controller
//Take the contact name and create a character id from it //Take the contact name and create a character id from it
$contact = $lookup->CharacterNameToId($request->contact); $contact = $lookup->CharacterNameToId($request->contact);
//Let's find the corporation and alliance information to ascertain whether they are in Warped Intentions or another Legacy Alliance
$corpId = LookupCharacter($contact);
$allianceId = LookupCorporation($corpId);
//Create the date //Create the date
$date = new Carbon($request->date . '00:00:01'); $date = new Carbon($request->date . '00:00:01');
//Calculate the moon price //Calculate the moon price
@@ -66,7 +69,7 @@ class MoonsAdminController extends Controller
])->first(); ])->first();
$price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity, $price = $moonCalc->SpatialMoonsOnlyGoo($moon->FirstOre, $moon->FirstQuantity, $moon->SecondOre, $moon->SecondQuantity,
$moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity); $moon->ThirdOre, $moon->ThirdQuantity, $moon->FourthOre, $moon->FourthQuantity);
dd($price);
$date = new Carbon($request->date . '00:00:01'); $date = new Carbon($request->date . '00:00:01');
//Update the database entry //Update the database entry
Moon::where([ Moon::where([
@@ -80,16 +83,30 @@ class MoonsAdminController extends Controller
]); ]);
//Going to store moon price in a table for future reference //Going to store moon price in a table for future reference
MoonRent::insert([ //We need to insert a price based on whether part of Legacy or part of Warped Intentions
'System' => $request->system, //Will need an if then else statement to complete this operation
'Planet' => $request->planet, if($allianceId = 99004116 || $allianceId = 99008072) {
'Moon' => $request->moon, MoonRent::insert([
'RentalCorp' => $request->renter, 'System' => $request->system,
'RentalEnd' => $date, 'Planet' => $request->planet,
'Contact' => $contact, 'Moon' => $request->moon,
'Price' => $price, 'RentalCorp' => $request->renter,
]); 'RentalEnd' => $date,
'Contact' => $contact,
'Price' => $price['alliance'],
]);
} else {
MoonRent::insert([
'System' =>$request->system,
'Planet' => $request->planet,
'Moon' => $request->moon,
'RentalCorp' => $request->renter,
'RentalEnd' => $date,
'Contact' => $contact,
'Price' => $price['outofalliance'],
]);
}
return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated'); return redirect('/moons/admin/updatemoon')->with('success', 'Moon Updated');
} }

View File

@@ -83,6 +83,49 @@ class LookupHelper {
} }
} }
//Add corporations to the lookup table for quicker lookups without having to
//hit the ESI API all the time
public function LookupCorporation($corpId) {
//Check for the character in the user_to_corporation table
$found = CorporationToAlliance::where('corporation_id', $charId)->get(['alliance_id']);
//If we don't find the character in the table, then we retrieve from ESI
//and add the character to the table
if(!isset($found[0]->alliance_id)) {
//Get the configuration for ESI from the environmental variables
$config = config('esi');
//Setup a new ESI container
$esi = new Eseye();
//Try to get the character information, then the corporation information
try {
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $corpId,
]);
$alliance = $esi->invoke('get', '/alliances/{alliance_id}/', [
'alliance_id' => $corporation->alliance_id,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
return $e->getEsiResponse();
}
//Save all of the data to the database
$corp = new CorporationToAlliance;
$corp->corporation_id = $corporation->corporation_id;
$corp->corporation_name = $corporation->name;
$corp->alliance_id = $corporation->alliance_id;
$corp->alliance_name = $alliance->name;
$corp->save();
//Return the corporation_id which is what the calling function is looking for
return $corporation->alliance_id;
} else {
//Return the corporation_id if it was found in the database as it is what the calling function is looking for
return $found[0]->alliance_id;
}
}
//Update the character lookup table as often as necessary //Update the character lookup table as often as necessary
public function UpdateLookupCharacter() { public function UpdateLookupCharacter() {
//Create a new ESI container //Create a new ESI container
@@ -118,48 +161,6 @@ class LookupHelper {
} }
} }
//Add corporations to the lookup table for quicker lookups without having to
//hit the ESI API all the time
public function LookupCorporation($corpId) {
//Check for the character in the user_to_corporation table
$found = CorporationToAlliance::where('corporation_id', $charId)->get(['alliance_id']);
//If we don't find the character in the table, then we retrieve from ESI
//and add the character to the table
if(!isset($found[0]->alliance_id)) {
//Get the configuration for ESI from the environmental variables
$config = config('esi');
//Setup a new ESI container
$esi = new Eseye();
//Try to get the character information, then the corporation information
try {
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $corpId,
]);
$alliance = $esi->invoke('get', '/alliances/{alliance_id}/', [
'alliance_id' => $corporation->alliance_id,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
return $e->getEsiResponse();
}
//Save all of the data to the database
$char = new UserToCorporation;
$char->character_id = $corpId;
$char->character_name = $corporation->name;
$char->corporation_id = $corporation->corporation_id;
$char->corporation_name = $corporation->name;
$char->save();
//Return the corporation_id which is what the calling function is looking for
return $corporation->alliance_id;
} else {
//Return the corporation_id if it was found in the database as it is what the calling function is looking for
return $found[0]->alliance_id;
}
}
//Update the corporation lookup table as often as necessary //Update the corporation lookup table as often as necessary
public function UpdateLookupCorporation() { public function UpdateLookupCorporation() {
//Create a new ESI container //Create a new ESI container