hauling configuration and hauling controller updates

This commit is contained in:
2019-10-22 01:39:13 -05:00
parent fc95c634e9
commit 388592d86a
6 changed files with 127 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ use App\Library\Hauling\HaulingHelper;
//Models
use App\Models\Lookups\SolarSystem;
use App\Models\Config\HaulingConfig;
class HaulingController extends Controller
{
@@ -40,7 +41,7 @@ class HaulingController extends Controller
'pickup' => 'required',
'destination' => 'required',
'collateral' => 'required',
'size' => 'required',
'size' => 'required|max:800000',
]);
//Declare the class helper
@@ -48,12 +49,26 @@ class HaulingController extends Controller
//Declare some variables we will need
$size = $request->size;
$collateral = $request->collateral;
$time = '1 week';
$duration = '3 days';
$pickup = $request->pickup;
$destination = $request->destination;
//Calculate the collateral
if(preg_match('(m|M|b|B)', $request->collateral) === 1) {
if(preg_match('(m|M)', $request->collateral) === 1) {
$collateral = $request->collateral * 1000000.00;
} else if(preg_match('(b|B)', $request->collaterial) === 1) {
$collateral = $request->collateral * 1000000000.00;
}
} else {
$collateral = $request->collateral;
}
//Get some configuration data for the haul
$hConfig = HaulingConfig::all();
//Determine if both systems are in high sec
$system1 = SolarSystem::where(['name' => $pickup])->first();
$system2 = SolarSystem::where(['name' => $destination])->first();
@@ -65,15 +80,11 @@ class HaulingController extends Controller
//Calculate the jumps needed
$jumps = $hHelper->JumpsBetweenSystems($pickup, $destination);
//Calculate the cost based on jumps multiplied by the fee.
if($size > 0 && $size <= 8000) {
$cost = $jumps * 600000;
} else if($size > 8000 && $size <= 57500) {
$cost = $jumps * 800000;
} else if($size > 57500 && $size <= 800000) {
$cost = $jumps * 1000000;
} else {
return redirect('/')->with('error', 'Size cannot be greater than 800k m3.');
//Calculte the cost based on jumps multiplied by the fee.
foreach($hConfig as $config) {
if($size > $config->min_load_size && $size <= $config->max_load_size) {
$cost = $jumps * $hConfig->price_per_jump;
}
}
return view('hauling.display.results')->with('jumps', $jumps)

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models\Config;
use Illuminate\Database\Eloquent\Model;
class HaulingConfig extends Model
{
//Table name
protected $table = 'hauling_configuration';
//Timestamps
public $timestamps = true;
/**
* The attributes that are mass assignable
*
* @var array
*/
protected $fillable = [
'load_size',
'min_load_size',
'max_load_size',
'price_per_jump',
];
}

View File

@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateHualingConfigTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('hauling_configuration')) {
Schema::create('hauling_configuration', function (Blueprint $table) {
$table->increments('id');
$table->string('load_size')->unique();
$table->unsignedBigInteger('min_load_size');
$table->ungiendBigInteger('max_load_size');
$table->decimal('price_per_jump');
$table->timestamps();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('hualing_config');
}
}

View File

@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Seeder;
use App\Models\Config\HaulingConfig;
class HaulingConfigSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
printf("Adding hauling configuration.\r\n");
HaulingConfig::insert([
'load_size' => 'small',
'min_load_size' => 0,
'max_load_size' => 8000,
'price_per_jump' => 600000,
]);
HaulingConfig::insert([
'load_size' => 'medium',
'min_load_size' => 8000,
'max_load_size' => 57500,
'price_per_jump' => 800000,
]);
HaulingConfig::insert([
'load_size' => 'large',
'min_load_size' => 57500,
'max_load_size' => 800000,
'price_per_jump' => 1000000,
]);
printf("Finished adding hauling configuration.\r\n");
}
}

View File

@@ -1026,6 +1026,7 @@ return array(
'Hamcrest\\Type\\IsString' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Type/IsString.php',
'Hamcrest\\Util' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Util.php',
'Hamcrest\\Xml\\HasXPath' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Xml/HasXPath.php',
'HaulingConfigSeeder' => $baseDir . '/database/seeds/HaulingConfigSeeder.php',
'Highlight\\Autoloader' => $vendorDir . '/scrivo/highlight.php/Highlight/Autoloader.php',
'Highlight\\Highlighter' => $vendorDir . '/scrivo/highlight.php/Highlight/Highlighter.php',
'Highlight\\JsonRef' => $vendorDir . '/scrivo/highlight.php/Highlight/JsonRef.php',

View File

@@ -1506,6 +1506,7 @@ class ComposerStaticInit33afb8ba5b252c3933eb137784fa7f04
'Hamcrest\\Type\\IsString' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Type/IsString.php',
'Hamcrest\\Util' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Util.php',
'Hamcrest\\Xml\\HasXPath' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest/Xml/HasXPath.php',
'HaulingConfigSeeder' => __DIR__ . '/../..' . '/database/seeds/HaulingConfigSeeder.php',
'Highlight\\Autoloader' => __DIR__ . '/..' . '/scrivo/highlight.php/Highlight/Autoloader.php',
'Highlight\\Highlighter' => __DIR__ . '/..' . '/scrivo/highlight.php/Highlight/Highlighter.php',
'Highlight\\JsonRef' => __DIR__ . '/..' . '/scrivo/highlight.php/Highlight/JsonRef.php',