Added a namepsace for each type of library and updated in programming

This commit is contained in:
2018-12-21 15:37:10 -06:00
parent 5d38d32b0e
commit b1e1b34fbc
19 changed files with 1088 additions and 16 deletions

View File

@@ -7,7 +7,7 @@ use DB;
use Carbon\Carbon; use Carbon\Carbon;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\Library\MoonCalc; use App\Library\Moons\MoonCalc;
class UpdateMoonPricing extends Command class UpdateMoonPricing extends Command
{ {

View File

@@ -5,14 +5,16 @@ namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\Library\Finances\FinanceHelper;
use App\Models\Market\MonthlyMarketTax; use App\Models\Market\MonthlyMarketTax;
use App\Models\ScheduledTask\ScheduleJob; use App\Models\ScheduledTask\ScheduleJob;
use App\Models\Corporation\CorpJournal; use App\Models\Corporation\CorpJournal;
use App\Models\Corporation\CorpStructure; use App\Models\Corporation\CorpStructure;
use App\Library\FinanceHelper;
class CalculateMarketTax extends Command class CalculateMarketTax extends Command
{ {

View File

@@ -7,9 +7,8 @@ use Illuminate\Console\Command;
use DB; use DB;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\Library\Finances\FinanceHelper;
use App\Library\FinanceHelper; use App\Library\Esi\Esi;
use App\Library\Esi;
use App\Models\Esi\EsiScope; use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken; use App\Models\Esi\EsiToken;

View File

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use DB; use DB;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\Models\ScheduledTask\ScheduleJob; use App\Models\ScheduledTask\ScheduleJob;

View File

@@ -5,7 +5,9 @@ namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Carbon\Carbon; use Carbon\Carbon;
use DB; use DB;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\Library\Esi\Mail;
use App\User; use App\User;
use App\Models\Esi\EsiScope; use App\Models\Esi\EsiScope;
@@ -13,8 +15,6 @@ use App\Models\Esi\EsiToken;
use App\Models\ScheduledTask\ScheduleJob; use App\Models\ScheduledTask\ScheduleJob;
use App\Models\Market\MonthlyMarketTax; use App\Models\Market\MonthlyMarketTax;
use App\Library\Mail;
use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration; use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication; use Seat\Eseye\Containers\EsiAuthentication;

View File

@@ -7,7 +7,7 @@ use App\Http\Requests;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use DB; use DB;
use App\Library\Fleets; use App\Library\Fleets\FleetHelper;
use App\Models\Fleet\Fleet; use App\Models\Fleet\Fleet;

View File

@@ -8,8 +8,8 @@ use Auth;
use DB; use DB;
use Carbon\Carbon; use Carbon\Carbon;
use App\Library\FleetHelper; use App\Library\Fleets\FleetHelper;
use App\Library\Esi; use App\Library\Esi\Esi;
use App\Models\Fleet\Fleet; use App\Models\Fleet\Fleet;
use App\Models\Fleet\FleetActivity; use App\Models\Fleet\FleetActivity;

View File

@@ -11,8 +11,8 @@ use Carbon\Carbon;
use App\Models\Moon\Moon; use App\Models\Moon\Moon;
use App\Models\Finances\PlayerDonationJournal; use App\Models\Finances\PlayerDonationJournal;
use App\Library\MoonCalc; use App\Library\Moons\MoonCalc;
use App\Library\Esi; use App\Library\Esi\Esi;
class MoonsAdminController extends Controller class MoonsAdminController extends Controller
{ {

View File

@@ -8,7 +8,7 @@ use Illuminate\Http\Request;
use App\Models\Moon\Moon; use App\Models\Moon\Moon;
use App\Library\MoonCalc; use App\Library\Moons\MoonCalc;
class MoonsController extends Controller class MoonsController extends Controller
{ {

View File

@@ -8,7 +8,7 @@ use Auth;
use DB; use DB;
use App\Models\Corporation\CorpStructure; use App\Models\Corporation\CorpStructure;
use App\Library\Esi; use App\Library\Esi\Esi;
class RegisterStructureController extends Controller class RegisterStructureController extends Controller
{ {

View File

@@ -7,15 +7,15 @@ use Illuminate\Http\Request;
use Auth; use Auth;
use DB; use DB;
use Carbon\Carbon; use Carbon\Carbon;
use App\Library\Structures\StructureTaxHelper; use App\Library\Structures\StructureTaxHelper;
use App\Library\Esi\Esi;
use App\User; use App\User;
use App\Models\User\UserRole; use App\Models\User\UserRole;
use App\Models\User\UserPermission; use App\Models\User\UserPermission;
use App\Models\Corporation\CorpStructure; use App\Models\Corporation\CorpStructure;
use App\Library\Esi;
class StructureController extends Controller class StructureController extends Controller
{ {
public function __construct() { public function __construct() {

View File

@@ -4,6 +4,7 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use DB; use DB;
use App\Models\User\UserPermission; use App\Models\User\UserPermission;
class RequirePermission class RequirePermission

View File

@@ -4,6 +4,7 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use DB; use DB;
use App\Models\User\UserRole; use App\Models\User\UserRole;
class RequireRole class RequireRole

107
app/Library/Esi/Esi.php Normal file
View File

@@ -0,0 +1,107 @@
<?php
namespace App\Library\Esi;
use DB;
use App\Models\Esi\EsiScope;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
/**
* This class represents a few ESI helper functions for the program
*/
class Esi {
/**
* Check if a scope is in the database for a particular character
*
* @param charId
* @param scope
*
* @return true,false
*/
public function HaveEsiScope($charId, $scope) {
//Check for an esi scope
$checks = DB::table('EsiScopes')->where('character_id', $charId)->get();
foreach($checks as $check) {
if($check->scope === $scope) {
return true;
}
}
return false;
}
public function GetCharacterName($charId) {
$esi = new Eseye();
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
return $character->name;
}
public function FindCharacterId($name) {
$config = config('esi');
//Create the esi authentication container
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
]);
//Create the esi container
$esi = new Eseye($authentication);
$character = $esi->setQueryString([
'categories' => 'character',
'language' => 'en-us',
'search' => $name,
'strict' => 'true',
])->invoke('get', '/search/');
$character = json_decode($character, true);
return $character['character'];
}
public function FindCorporationId($charId) {
$esi = new Eseye();
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
return $character->corporation_id;
}
public function FindCorporationName($charId) {
$esi = new Eseye();
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $character->corporation_id,
]);
return $corporation->name;
}
public function DecodeDate($date) {
//Find the end of the date
$dateEnd = strpos($date, "T");
//Split the string up into date and time
$dateArr = str_split($date, $dateEnd);
//Trim the T and Z from the end of the second item in the array
$dateArr[1] = ltrim($dateArr[1], "T");
$dateArr[1] = rtrim($dateArr[1], "Z");
//Combine the date
$realDate = $dateArr[0] . " " . $dateArr[1];
//Return the combined date in the correct format
return $realDate;
}
}
?>

48
app/Library/Esi/Mail.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
namespace App\Library\Esi;
use DB;
use App\Models\Esi\EsiScope;
use App\Models\Esi\Esitoken;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
class Mail {
public function SendMail($charId, $taxAmount, $subject, $body) {
//Retrieve the token for Amund Risalo
$token = DB::table('EsiTokens')->where('character_id', 93738489)->get();
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Create the ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Create the esi class variable
$esi = new Eseye($authentication);
try {
$esi->setBody([
'body' => $body,
'receipients' => [
'recipient_id'=> $charId,
'recipient_type' => 'character',
],
'subject' => $subject,
])->invoke('post', '/characters/{character_id}/mail/', [
'character_id' => 93738489,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e) {
return $e->getEsiResponse();
}
}
}
?>

View File

@@ -0,0 +1,227 @@
<?php
/**
* W4RP Services
* GNU Public License
*/
namespace App\Library\Finances;
use DB;
use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken;
use App\Models\Corporation\CorpJournal;
use App\Models\User\UserToCorporation;
use App\Models\Finances\PlayerDonationJournal;
use App\Library\Esi;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
class FinanceHelper {
public function GetWalletJournal($division, $charId) {
//Get hte ESI token for the corporation to add new wallet journals into the database
$token = DB::table('EsiTokens')->where('character_id', $charId)->get();
//Reference to see if the character is in our look up table for corporations and characters
$corpId = $this->GetCharCorp($charId);
//Disable all caching by setting the NullCache as the preferred cache handler.
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Create an ESI authentication container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
//Create the esi class varialble
$esi = new Eseye($authentication);
//Set our current page to 1 which is the one we are starting on.
$currentPage = 1;
//Set our default total pages to 1 in case our try section fails out.
$totalPages = 1;
//If more than one page is found, decode the first set of wallet entries, then call for the next pages
do {
//Call the first page of the wallet journal, as we are always going to get at least one page.
//If we have more pages, then we will continue through the while loop.
try {
$journals = $esi->page($currentPage)
->invoke('get', '/corporations/{corporation_id}/wallets/{division}/journal/', [
'corporation_id' => $corpId,
'division' => $division,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e) {
return $e->getEsiResponse();
}
//Set the total pages we need to cycle through.
$totalPages = $journals->pages;
//Decode the wallet from json into an array
$wallet = json_decode($journals->raw, true);
//For each journal entry, attempt to store it in the database.
//The PutWalletJournal function checks to see if it's already in the database.
foreach($wallet as $entry) {
if($entry['amount'] > 0) {
if($entry['ref_type'] == 'brokers_fee' ||
$entry['ref_type'] == 'reprocessing_tax' ||
$entry['ref_type'] == 'jumpgate_fee' ||
$entry['ref_type'] == 'player_donation' ||
($entry['ref_type'] == 'corporation_account_withdrawal' && $entry['second_party_id'] == 98287666)) {
$this->PutWalletJournal($entry, $corpId, $division);
}
}
}
//Increment the current page we are on.
$currentPage++;
//Continue looping through the do while loop until the current page is greater than or equal to the total pages.
} while ($currentPage < $totalPages);
return $currentPage;
}
/**
* Returns the corporation a character is in if found in the lookup table, otherwise,
* adds the character to the lookup table, and returns the corporation id
*
* @param charId
* @return corpId
*/
private function GetCharCorp($charId) {
//Check for the character the user_to_corporation table
//$found = DB::table('user_to_corporation')->where('character_id', $charId)->get();
$found = UserToCorporation::where('character_id', $charId)->get(['corporation_id']);
//If we don't find the character in the table, then let's retrieve the information from ESI
if(!isset($found[0]->corporation_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 {
$character = $esi->invoke('get', '/characters/{character_id}/', [
'character_id' => $charId,
]);
$corporation = $esi->invoke('get', '/corporations/{corporation_id}/', [
'corporation_id' => $character->corporation_id,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e){
return $e->getEsiResponse();
}
//Save all of the data to the database
$char = new UserToCorporation;
$char->character_id = $charId;
$char->character_name = $character->name;
$char->corporation_id = $character->corporation_id;
$char->corporation_name = $corporation->name;
$char->save();
//Return the corporation_id which is what the calling function is looking for
return $character->corporation_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]->corporation_id;
}
}
private function PutWalletJournal($journal, $corpId, $division) {
//Create ESI Helper class
$esiHelper = new Esi;
$date = $esiHelper->DecodeDate($journal['date']);
if($journal['ref_type'] == 'player_donation' || ($journal['ref_type'] == 'corporation_account_withdrawal' && $journal['second_party_id'] == 98287666)) {
//if we don't find the journal entry, add the journal entry to the database
if(!PlayerDonationJournal::where(['id' => $journal['id']])->exists()) {
$entry = new PlayerDonationJournal;
$entry->id = $journal['id'];
$entry->corporation_id = $corpId;
$entry->division = $division;
if(isset($journal['amount'])) {
$entry->amount = $journal['amount'];
}
if(isset($journal['balance'])) {
$entry->balance = $journal['balance'];
}
if(isset($journal['context_id'])) {
$entry->context_id = $journal['context_id'];
}
if(isset($journal['context_id_type'])) {
$entry->context_id_type = $journal['context_id_type'];
}
$entry->date = $date;
$entry->description = $journal['description'];
if(isset($journal['first_party_id'])) {
$entry->first_party_id = $journal['first_party_id'];
}
if(isset($journal['reason'])) {
$entry->reason = $journal['reason'];
}
$entry->ref_type = $journal['ref_type'];
if(isset($journal['second_party_id'])) {
$entry->second_party_id = $journal['second_party_id'];
}
if(isset($journal['tax'])) {
$entry->tax = $journal['tax'];
}
if(isset($journal['tax_receiver_id'])) {
$entry->tax_receiver_id = $journal['tax_receiver_id'];
}
$entry->save();
}
} else {
//if we don't find the journal entry, add the journal entry to the database
if(!CorpJournal::where(['id' => $journal['id']])->exists()) {
$entry = new CorpJournal;
$entry->id = $journal['id'];
$entry->corporation_id = $corpId;
$entry->division = $division;
if(isset($journal['amount'])) {
$entry->amount = $journal['amount'];
}
if(isset($journal['balance'])) {
$entry->balance = $journal['balance'];
}
if(isset($journal['context_id'])) {
$entry->context_id = $journal['context_id'];
}
if(isset($journal['context_id_type'])) {
$entry->context_id_type = $journal['context_id_type'];
}
$entry->date = $date;
$entry->description = $journal['description'];
if(isset($journal['first_party_id'])) {
$entry->first_party_id = $journal['first_party_id'];
}
if(isset($journal['reason'])) {
$entry->reason = $journal['reason'];
}
$entry->ref_type = $journal['ref_type'];
if(isset($journal['second_party_id'])) {
$entry->second_party_id = $journal['second_party_id'];
}
if(isset($journal['tax'])) {
$entry->tax = $journal['tax'];
}
if(isset($journal['tax_receiver_id'])) {
$entry->tax_receiver_id = $journal['tax_receiver_id'];
}
$entry->save();
}
}
}
}
?>

View File

@@ -0,0 +1,136 @@
<?php
namespace App\Library\Fleets;
use Auth;
use Session;
use DB;
use App\Models\Esi\EsiToken;
use App\Models\Fleet\Fleet;
use App\Models\Fleet\FleetActivity;
use Carbon\Carbon;
use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration;
use Seat\Eseye\Containers\EsiAuthentication;
use Seat\Eseye\Eseye;
class FleetHelper {
private $fleetUri;
private $fcId;
/**
* Constructor
*
* @param fcId
*/
public function __construct($charId = null, $fleetId = null) {
$this->fcId = $charId;
$this->fleet = $fleetId;
}
/**
* Set Fleet number
*
* @param fleetUri
*/
public function SetFleetUri($fleetUri) {
//Trim the left side of the fleet number
$uris = explode('https://esi.tech.ccp.is/v1/fleets/', $fleetUri);
//Trim the right side of the fleet number
$fleetUri = rtrim($uris[1], '/?datasource=tranquility');
$this->fleetUri = $fleetUri;
}
public function GetFleetUri() {
return $this->fleetUri;
}
/**
* Update fleet motd and free move.
*
* @param fleetId
*/
public function UpdateFleet($fleetId) {
return null;
}
/**
* Helper function to add a pilot to the fleet using his character id
*
* @param fc
* @param charId
* @param fleetId
*/
public function AddPilot($fc, $charId, $fleetId) {
//Get the ESI token for the FC to add the new pilot
$token = DB::table('EsiTokens')->where('character_id', $fc)->get();
// Disable all caching by setting the NullCache as the
// preferred cache handler. By default, Eseye will use the
// FileCache.
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Create the ESI Call Container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
$esi = new \Seat\Eseye\Eseye($authentication);
try {
//Setup the body of the esi message and perform the call
$esi->setBody([
'character_id' => $charId,
'role' => 'squad_member',
])->invoke('post', '/fleets/{fleet_id}/members/', [
'fleet_id' => $fleetId,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e) {
return $e->getEsiResponse();
}
return null;
}
/**
* Store Fleet Activity Tracking information into the database when caleld
*
* @param fleetId
*/
public function StoreFleetActivity($fleetId, $fcId) {
//Get the ESI token for the FC to get the fleet composition
$token = DB::table('EsiTokens')->where('character_id', $fcId)->get();
//Disable all caching by setting the NullCache as the preferred cache handler.
$configuration = Configuration::getInstance();
$configuration->cache = NullCache::class;
//Create the ESI Call Container
$config = config('esi');
$authentication = new EsiAuthentication([
'client_id' => $config['client_id'],
'secret' => $config['secret'],
'refresh_token' => $token[0]->refresh_token,
]);
$esi = new Eseye($authentication);
try {
$fleetComp = $esi->invoke('get', '/fleets/{fleet_id}/members/', [
'fleet_id' => $fleetId,
]);
} catch(\Seat\Eseye\Exceptions\RequestFailedException $e) {
return $e->getEsiResponse();
}
dd($fleetComp);
foreach($fleetComp as $comp) {
}
return null;
}
}
?>

View File

@@ -0,0 +1,541 @@
<?php
/*
* W4RP Services
* GNU Public License
*/
namespace App\Library\Moons;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Session;
use DB;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;
use App\Models\Config;
use App\Models\Moon\Moon;
use App\Models\Moon\Price;
use App\Models\Moon\ItemComposition;
class MoonCalc {
public function SpatialMoonsTotalWorth($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) {
//Always assume a 1 month pull which equates to 5.55m3 per second or 2,592,000 seconds
//Total pull size is 14,385,600 m3
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
if($firstQuan >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstQuan);
} else {
$firstPerc = $firstQuan;
}
if($secondQuan >= 1.00) {
$secondPerc = $this->ConvertToPercentage($secondQuan);
} else {
$secondPerc = $secondQuan;
}
if($thirdQuan >= 1.00) {
$thirdPerc = $this->ConvertToPercentage($thirdQuan);
} else {
$thirdPerc = $thirdQuan;
}
if($fourthQuan >= 1.00) {
$fourthPerc = $this->ConvertToPercentage($fourthQuan);
} else {
$fourthPerc = $fourthQuan;
}
if($firstOre != "None") {
$firstTotal = $this->CalcPrice($firstOre, $firstPerc);
} else {
$firstTotal = 0.00;
}
if($secondOre != "None") {
$secondTotal = $this->CalcPrice($secondOre, $secondPerc);
} else {
$secondTotal = 0.00;
}
if($thirdOre != "None") {
$thirdTotal = $this->CalcPrice($thirdOre, $thirdPerc);
} else {
$thirdTotal = 0.00;
}
if($fourthOre != "None") {
$fourthTotal = $this->CalcPrice($fourthOre, $fourthPerc);
} else {
$fourthTotal = 0.00;
}
//Calculate the total to price to be mined in one month
$totalPriceMined = $firstTotal + $secondTotal + $thirdTotal + $fourthTotal;
//Return the rental price to the caller
return $totalPriceMined;
}
public function SpatialMoonsOnlyGooTotalWorth($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) {
//Always assume a 1 month pull which equates to 5.55m3 per second or 2,592,000 seconds
//Total pull size is 14,385,600 m3
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
if($firstQuan >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstQuan);
} else {
$firstPerc = $firstQuan;
}
if($secondQuan >= 1.00) {
$secondPerc = $this->ConvertToPercentage($secondQuan);
} else {
$secondPerc = $secondQuan;
}
if($thirdQuan >= 1.00) {
$thirdPerc = $this->ConvertToPercentage($thirdQuan);
} else {
$thirdPerc = $thirdQuan;
}
if($fourthQuan >= 1.00) {
$fourthPerc = $this->ConvertToPercentage($fourthQuan);
} else {
$fourthPerc = $fourthQuan;
}
if($firstOre != "None") {
if($this->IsRMoonGoo($firstOre)) {
$firstTotal = $this->CalcPrice($firstOre, $firstPerc);
} else {
$firstTotal = 0.00;
}
} else {
$firstTotal = 0.00;
}
if($secondOre != "None") {
if($this->IsRMoonGoo($secondOre)) {
$secondTotal = $this->CalcPrice($secondOre, $secondPerc);
} else {
$secondTotal = 0.00;
}
} else {
$secondTotal = 0.00;
}
if($thirdOre != "None") {
if($this->IsRMoonGoo($thirdOre)) {
$thirdTotal = $this->CalcPrice($thirdOre, $thirdPerc);
} else {
$thirdTotal = 0.00;
}
} else {
$thirdTotal = 0.00;
}
if($fourthOre != "None") {
if($this->IsRMoonGoo($fourthOre)) {
$fourthTotal = $this->CalcPrice($fourthOre, $fourthPerc);
} else {
$fourthTotal = 0.00;
}
} else {
$fourthTotal = 0.00;
}
//Calculate the total to price to be mined in one month
$totalPriceMined = $firstTotal + $secondTotal + $thirdTotal + $fourthTotal;
//Return the rental price to the caller
return $totalPriceMined;
}
public function SpatialMoonsOnlyGoo($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) {
//Always assume a 1 month pull which equates to 5.55m3 per second or 2,592,000 seconds
//Total pull size is 14,385,600 m3
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
if($firstQuan >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstQuan);
} else {
$firstPerc = $firstQuan;
}
if($secondQuan >= 1.00) {
$secondPerc = $this->ConvertToPercentage($secondQuan);
} else {
$secondPerc = $secondQuan;
}
if($thirdQuan >= 1.00) {
$thirdPerc = $this->ConvertToPercentage($thirdQuan);
} else {
$thirdPerc = $thirdQuan;
}
if($fourthQuan >= 1.00) {
$fourthPerc = $this->ConvertToPercentage($fourthQuan);
} else {
$fourthPerc = $fourthQuan;
}
if($firstOre != "None") {
if($this->IsRMoon($firstOre)) {
$firstTotal = $this->CalcPrice($firstOre, $firstPerc);
} else {
$firstTotal = 0.00;
}
} else {
$firstTotal = 0.00;
}
if($secondOre != "None") {
if($this->IsRMoon($secondOre)) {
$secondTotal = $this->CalcPrice($secondOre, $secondPerc);
} else {
$secondTotal = 0.00;
}
} else {
$secondTotal = 0.00;
}
if($thirdOre != "None") {
if($this->IsRMoon($thirdOre)) {
$thirdTotal = $this->CalcPrice($thirdOre, $thirdPerc);
} else {
$thirdTotal = 0.00;
}
} else {
$thirdTotal = 0.00;
}
if($fourthOre != "None") {
if($this->IsRMoon($fourthOre)) {
$fourthTotal = $this->CalcPrice($fourthOre, $fourthPerc);
} else {
$fourthTotal = 0.00;
}
} else {
$fourthTotal = 0.00;
}
//Calculate the total to price to be mined in one month
$totalPriceMined = $firstTotal + $secondTotal + $thirdTotal + $fourthTotal;
//Calculate the rental price. Refined rate is already included in the price from rental composition
$rentalPrice['alliance'] = $totalPriceMined * ($config[0]->RentalTax / 100.00);
$rentalPrice['outofalliance'] = $totalPriceMined * ($config[0]->AllyRentalTax / 100.00);
//Format the rental price to the appropriate number
$rentalPrice['alliance'] = number_format($rentalPrice['alliance'], "2", ".", ",");
$rentalPrice['outofalliance'] = number_format($rentalPrice['outofalliance'], "2", ".", ",");
//Return the rental price to the caller
return $rentalPrice;
}
public function SpatialMoons($firstOre, $firstQuan, $secondOre, $secondQuan, $thirdOre, $thirdQuan, $fourthOre, $fourthQuan) {
//Always assume a 1 month pull which equates to 5.55m3 per second or 2,592,000 seconds
//Total pull size is 14,385,600 m3
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Get the configuration for pricing calculations
$config = DB::table('Config')->get();
if($firstQuan >= 1.00) {
$firstPerc = $this->ConvertToPercentage($firstQuan);
} else {
$firstPerc = $firstQuan;
}
if($secondQuan >= 1.00) {
$secondPerc = $this->ConvertToPercentage($secondQuan);
} else {
$secondPerc = $secondQuan;
}
if($thirdQuan >= 1.00) {
$thirdPerc = $this->ConvertToPercentage($thirdQuan);
} else {
$thirdPerc = $thirdQuan;
}
if($fourthQuan >= 1.00) {
$fourthPerc = $this->ConvertToPercentage($fourthQuan);
} else {
$fourthPerc = $fourthQuan;
}
if($firstOre != "None") {
$firstTotal = $this->CalcPrice($firstOre, $firstPerc);
} else {
$firstTotal = 0.00;
}
if($secondOre != "None") {
$secondTotal = $this->CalcPrice($secondOre, $secondPerc);
} else {
$secondTotal = 0.00;
}
if($thirdOre != "None") {
$thirdTotal = $this->CalcPrice($thirdOre, $thirdPerc);
} else {
$thirdTotal = 0.00;
}
if($fourthOre != "None") {
$fourthTotal = $this->CalcPrice($fourthOre, $fourthPerc);
} else {
$fourthTotal = 0.00;
}
//Calculate the total to price to be mined in one month
$totalPriceMined = $firstTotal + $secondTotal + $thirdTotal + $fourthTotal;
//Calculate the rental price. Refined rate is already included in the price from rental composition
$rentalPrice['alliance'] = $totalPriceMined * ($config[0]->RentalTax / 100.00);
$rentalPrice['outofalliance'] = $totalPriceMined * ($config[0]->AllyRentalTax / 100.00);
//Format the rental price to the appropriate number
$rentalPrice['alliance'] = number_format($rentalPrice['alliance'], "2", ".", ",");
$rentalPrice['outofalliance'] = number_format($rentalPrice['outofalliance'], "2", ".", ",");
//Return the rental price to the caller
return $rentalPrice;
}
public function FetchNewPrices() {
$ItemIDs = array(
"Tritanium" => 34,
"Pyerite" => 35,
"Mexallon" => 36,
"Isogen" => 37,
"Nocxium" => 38,
"Zydrine" => 39,
"Megacyte" => 40,
"Morphite" => 11399,
"HeliumIsotopes" => 16274,
"NitrogenIsotopes" => 17888,
"OxygenIsotopes" => 17887,
"HydrogenIsotopes" => 17889,
"LiquidOzone" => 16273,
"HeavyWater" => 16272,
"StrontiumClathrates" => 16275,
"AtmosphericGases" => 16634,
"EvaporiteDeposits" => 16635,
"Hydrocarbons" => 16633,
"Silicates" => 16636,
"Cobalt" => 16640,
"Scandium" => 16639,
"Titanium" => 16638,
"Tungsten" => 16637,
"Cadmium" => 16643,
"Platinum" => 16644,
"Vanadium" => 16642,
"Chromium" => 16641,
"Technetium" => 16649,
"Hafnium" => 16648,
"Caesium" => 16647,
"Mercury" => 16646,
"Dysprosium" => 16650,
"Neodymium" => 16651,
"Promethium" => 16652,
"Thulium" => 16653,
);
$time = time();
$item = array();
//Get the json data for each ItemId from https://market.fuzzwork.co.uk/api/
//Base url is https://market.fuzzwork.co.uk/aggregates/?region=10000002&types=34
//Going to use curl for these requests
foreach($ItemIDs as $key => $value) {
$client = new Client(['base_uri' => 'https://market.fuzzwork.co.uk/aggregates/']);
$uri = '?region=10000002&types=' . $value;
$result = $client->request('GET', $uri);
$item = json_decode($result->getBody(), true);
DB::table('Prices')->where('Name', $key)->update([
'Name' => $key,
'ItemId' => $value,
'Price' => $item[$value]['sell']['median'],
'Time' => $time,
]);
}
$this->UpdateItemPricing();
}
private function UpdateItemPricing() {
//Get the configuration from the config table
$config = DB::table('Config')->first();
//Calculate refine rate
$refineRate = $config->RefineRate / 100.00;
//Calculate the current time
$time = time();
//Get the max time from the database
$maxTime = DB::table('Prices')->where('ItemId', 34)->max('Time');
//Get the price of the basic minerals
$tritaniumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [34, $maxTime]);
$tritanium = DB::select( DB::raw('SELECT Price FROM Prices WHERE ItemId= :id AND Time= :time'), array('id' => 34, 'time' => $maxTime));
$pyeritePrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [35, $maxTime]);
$mexallonPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [36, $maxTime]);
$isogenPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [37, $maxTime]);
$nocxiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [38, $maxTime]);
$zydrinePrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [39, $maxTime]);
$megacytePrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [40, $maxTime]);
$morphitePrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [11399, $maxTime]);
$heliumIsotopesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16274, $maxTime]);
$nitrogenIsotopesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [17888, $maxTime]);
$oxygenIsotopesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [17887, $maxTime]);
$hydrogenIsotopesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [17889, $maxTime]);
$liquidOzonePrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16273, $maxTime]);
$heavyWaterPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16272, $maxTime]);
$strontiumClathratesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16275, $maxTime]);
//Get the price of the moongoo
$atmosphericGasesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16634, $maxTime]);
$evaporiteDepositsPirce = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16635, $maxTime]);
$hydrocarbonsPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16633, $maxTime]);
$silicatesPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16636, $maxTime]);
$cobaltPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16640, $maxTime]);
$scandiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16639, $maxTime]);
$titaniumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16638, $maxTime]);
$tungstenPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16637, $maxTime]);
$cadmiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16643, $maxTime]);
$platinumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16644, $maxTime]);
$vanadiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16642, $maxTime]);
$chromiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16641, $maxTime]);
$technetiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16649, $maxTime]);
$hafniumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16648, $maxTime]);
$caesiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16647, $maxTime]);
$mercuryPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16646, $maxTime]);
$dysprosiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16650, $maxTime]);
$neodymiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16651, $maxTime]);
$promethiumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16652, $maxTime]);
$thuliumPrice = DB::select('SELECT Price FROM Prices WHERE ItemId = ? AND Time = ?', [16653, $maxTime]);
//Get the item compositions
$items = DB::select('SELECT Name,ItemId FROM ItemComposition');
//Go through each of the items and update the price
foreach($items as $item) {
//Get the item composition
$composition = DB::select('SELECT * FROM ItemComposition WHERE ItemId = ?', [$item->ItemId]);
//Calculate the Batch Price
$batchPrice = ( ($composition[0]->Tritanium * $tritaniumPrice[0]->Price) +
($composition[0]->Pyerite * $pyeritePrice[0]->Price) +
($composition[0]->Mexallon * $mexallonPrice[0]->Price) +
($composition[0]->Isogen * $isogenPrice[0]->Price) +
($composition[0]->Nocxium * $nocxiumPrice[0]->Price) +
($composition[0]->Zydrine * $zydrinePrice[0]->Price) +
($composition[0]->Megacyte * $megacytePrice[0]->Price) +
($composition[0]->Morphite * $morphitePrice[0]->Price) +
($composition[0]->HeavyWater * $heavyWaterPrice[0]->Price) +
($composition[0]->LiquidOzone * $liquidOzonePrice[0]->Price) +
($composition[0]->NitrogenIsotopes * $nitrogenIsotopesPrice[0]->Price) +
($composition[0]->HeliumIsotopes * $heliumIsotopesPrice[0]->Price) +
($composition[0]->HydrogenIsotopes * $hydrogenIsotopesPrice[0]->Price) +
($composition[0]->OxygenIsotopes * $oxygenIsotopesPrice[0]->Price) +
($composition[0]->StrontiumClathrates * $strontiumClathratesPrice[0]->Price) +
($composition[0]->AtmosphericGases * $atmosphericGasesPrice[0]->Price) +
($composition[0]->EvaporiteDeposits * $evaporiteDepositsPirce[0]->Price) +
($composition[0]->Hydrocarbons * $hydrocarbonsPrice[0]->Price) +
($composition[0]->Silicates * $silicatesPrice[0]->Price) +
($composition[0]->Cobalt * $cobaltPrice[0]->Price) +
($composition[0]->Scandium * $scandiumPrice[0]->Price) +
($composition[0]->Titanium * $titaniumPrice[0]->Price) +
($composition[0]->Tungsten * $tungstenPrice[0]->Price) +
($composition[0]->Cadmium * $cadmiumPrice[0]->Price) +
($composition[0]->Platinum * $platinumPrice[0]->Price) +
($composition[0]->Vanadium * $vanadiumPrice[0]->Price) +
($composition[0]->Chromium * $chromiumPrice[0]->Price)+
($composition[0]->Technetium * $technetiumPrice[0]->Price) +
($composition[0]->Hafnium * $hafniumPrice[0]->Price) +
($composition[0]->Caesium * $caesiumPrice[0]->Price) +
($composition[0]->Mercury * $mercuryPrice[0]->Price) +
($composition[0]->Dysprosium * $dysprosiumPrice[0]->Price) +
($composition[0]->Neodymium * $neodymiumPrice[0]->Price) +
($composition[0]->Promethium * $promethiumPrice[0]->Price) +
($composition[0]->Thulium * $thuliumPrice[0]->Price));
//Calculate the batch price with the refine rate included
//Batch Price is base price for everything
$batchPrice = $batchPrice * $refineRate;
//Calculate the unit price
$price = $batchPrice / $composition[0]->BatchSize;
//Calculate the m3 price
$m3Price = $price / $composition[0]->m3Size;
//Update the prices in the Prices table
DB::table('OrePrices')->where('Name', $composition[0]->Name)->update([
'Name' => $composition[0]->Name,
'ItemId' => $composition[0]->ItemId,
'BatchPrice' => $batchPrice,
'UnitPrice' => $price,
'm3Price' => $m3Price,
]);
}
}
private function CalcPrice($ore, $percentage) {
//Specify the total pull amount
$totalPull = 5.55 * (3600.00 * 24.00 * 30.00);
//Find the size of the asteroid from the database
$m3Size = DB::table('ItemComposition')->where('Name', $ore)->value('m3Size');
//Calculate the actual m3 from the total pull amount in m3 using the percentage of the ingredient
$actualm3 = floor($percentage * $totalPull);
//Calculate the units once we have the size and actual m3 value
$units = floor($actualm3 / $m3Size);
//Look up the unit price from the database
$unitPrice = DB::table('OrePrices')->where('Name', $ore)->value('UnitPrice');
//Calculate the total amount from the units and unit price
$total = $units * $unitPrice;
//Return the value
return $total;
}
private function ConvertToPercentage($quantity) {
return $quantity / 100.00;
}
private function IsRMoonGoo($ore) {
$ores = [
'Zeolites' => 'Gas',
'Sylvite' => 'Gas',
'Bitumens' => 'Gas',
'Coesite' => 'Gas',
'Cobaltite' => 'R8',
'Euxenite' => 'R8',
'Titanite' => 'R8',
'Scheelite' => 'R8',
'Otavite' => 'R16',
'Sperrylite' => 'R16',
'Vanadinite' => 'R16',
'Chromite' => 'R16',
'Carnotite' => 'R32',
'Zircon' => 'R32',
'Pollucite' => 'R32',
'Cinnabar' => 'R32',
'Xenotime' => 'R64',
'Monazite' => 'R64',
'Loparite' => 'R64',
'Ytterbite' => 'R64',
];
foreach($ores as $key => $value) {
if(strtolower($key) == strtolower($ore)) {
return true;
}
}
return false;
}
private function IsRMoon($ore) {
$ores = [
'Prime Arkonor' => 'Null',
'Cubic Bistot' => 'Null',
'Pellucid Crokite' => 'Null',
'Jet Ochre' => 'Null',
'Zeolites' => 'Gas',
'Sylvite' => 'Gas',
'Bitumens' => 'Gas',
'Coesite' => 'Gas',
'Cobaltite' => 'R8',
'Euxenite' => 'R8',
'Titanite' => 'R8',
'Scheelite' => 'R8',
'Otavite' => 'R16',
'Sperrylite' => 'R16',
'Vanadinite' => 'R16',
'Chromite' => 'R16',
'Carnotite' => 'R32',
'Zircon' => 'R32',
'Pollucite' => 'R32',
'Cinnabar' => 'R32',
'Xenotime' => 'R64',
'Monazite' => 'R64',
'Loparite' => 'R64',
'Ytterbite' => 'R64',
];
foreach($ores as $key => $value) {
if(strtolower($key) == strtolower($ore)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,9 @@
<?php
namespace App\Library\Moons;
class MoonMine {
}
?>