working on bids

This commit is contained in:
2019-04-28 20:25:42 -05:00
parent 0abc86e5a2
commit 7cf937e007
2 changed files with 57 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ use DB;
use Carbon\Carbon;
//Libraries
use App\Library\Lookups\LookupHelper;
//use App\Library\Contracts\ContractHelper;
//Models
@@ -130,6 +131,9 @@ class ContractController extends Controller
'bid' => 'required',
]);
//Delcare some class variables we will need
$lookup = new LookupHelper;
$amount = 0.00;
//Convert the amount to a whole number from abbreviations
@@ -141,11 +145,22 @@ class ContractController extends Controller
$amount = $request->bid;
}
//Get the character id and character name from the auth of the user calling
//this function
$characterId = auth()->user()->getId();
$characterName = auth()->user()->getName();
//Use the lookup helper in order to find the user's corporation id and name
$corporationId = $lookup->LookupCharacter($characterId);
$corporationName = $lookup->LookupCorporationName($corporationId);
//Create the model object to save data to
$bid = new Bid;
$bid->contract_id = $request->contract_id;
$bid->bid_amount = $amount;
$bid->accepted = false;
$bid->character_id = $characterId;
$bid->character_name = $characterName;
$bid->corporation_id = $corporationId;
$bid->corporation_name = $corporationName;
$bid->save();
//Redirect to the correct page

View File

@@ -83,6 +83,47 @@ class LookupHelper {
}
}
/**
* Function to retrieve a corporation name from the lookup tables
* or add the details of the corporation if it's not found
*
*/
public function LookupCorporationName($corpId) {
//check for the character in the user_to_corporation table
$found = CorporationToAlliance::where('corporation_id', $corpId)->get(['corporation_name']);
//If we don't find the corporation in the table, then we need to retrieve it from ESI
//and add the corporation to the table
if(!isset($found[0]->corporation_name)) {
//Get the configuration for ESI from the environmental variables
$config = config('esi');
//Setup a new ESI container
$esi = new Eseye();
try {
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $corpId,
]);
} 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 name
return $corporation->name;
} else {
return $found[0]->corporation_name;
}
}
//Add corporations to the lookup table for quicker lookups without having to
//hit the ESI API all the time
public function LookupCorporation($corpId) {