Skip to content

Commit

Permalink
run composer lint (not bladeformatter)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Oct 20, 2023
1 parent 40739c9 commit d6b1828
Show file tree
Hide file tree
Showing 66 changed files with 2,143 additions and 2,067 deletions.
22 changes: 7 additions & 15 deletions app/Console/Commands/CheckPetDrops.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

namespace App\Console\Commands;

use DB;
use Carbon\Carbon;
use App\Models\Pet\PetDrop;

use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Services\NewsService;

class CheckPetDrops extends Command
{
class CheckPetDrops extends Command {
/**
* The name and signature of the console command.
*
Expand All @@ -27,11 +23,8 @@ class CheckPetDrops extends Command

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
public function __construct() {
parent::__construct();
}

Expand All @@ -40,18 +33,17 @@ public function __construct()
*
* @return mixed
*/
public function handle()
{
public function handle() {
//
$updateDrops = PetDrop::requiresUpdate()->get();
foreach ($updateDrops as $drop) {
if((!isset($drop->dropData->cap) || $drop->dropData->cap == 0) || $drop->drops_available < $drop->dropData->cap) {
if ((!isset($drop->dropData->cap) || $drop->dropData->cap == 0) || $drop->drops_available < $drop->dropData->cap) {
$drop->update([
'drops_available' => $drop->drops_available += 1,
'next_day' => Carbon::now()->add(
'next_day' => Carbon::now()->add(
$drop->dropData->frequency,
$drop->dropData->interval,
)->startOf($drop->dropData->interval)
)->startOf($drop->dropData->interval),
]);
}
}
Expand Down
26 changes: 11 additions & 15 deletions app/Console/Commands/RestockShops.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Carbon\Carbon;
class RestockShops extends Command
{
use Illuminate\Console\Command;

class RestockShops extends Command {
/**
* The name and signature of the console command.
*
Expand All @@ -22,11 +22,8 @@ class RestockShops extends Command

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
public function __construct() {
parent::__construct();
}

Expand All @@ -35,26 +32,25 @@ public function __construct()
*
* @return int
*/
public function handle()
{
public function handle() {
$stocks = \App\Models\Shop\ShopStock::where('is_limited_stock', 1)->where('restock', 1)->get();
foreach($stocks as $stock) {
if($stock->restock_interval == 1) {
foreach ($stocks as $stock) {
if ($stock->restock_interval == 1) {
$stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity;
$stock->save();
} elseif($stock->restock_interval == 2) {
} elseif ($stock->restock_interval == 2) {
// check if it's start of week
$now = Carbon::now();
$day = $now->dayOfWeek;
if($day == 1) {
if ($day == 1) {
$stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity;
$stock->save();
}
} elseif($stock->restock_interval == 3) {
} elseif ($stock->restock_interval == 3) {
// check if it's start of month
$now = Carbon::now();
$day = $now->day;
if($day == 1) {
if ($day == 1) {
$stock->quantity = $stock->range ? mt_rand(1, $stock->restock_quantity) : $stock->restock_quantity;
$stock->save();
}
Expand Down
58 changes: 25 additions & 33 deletions app/Console/Commands/UpdatePets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace App\Console\Commands;

use File;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Storage;
use File;

class UpdatePets extends Command
{
class UpdatePets extends Command {
/**
* The name and signature of the console command.
*
Expand All @@ -25,11 +23,8 @@ class UpdatePets extends Command

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
public function __construct() {
parent::__construct();
}

Expand All @@ -38,28 +33,26 @@ public function __construct()
*
* @return mixed
*/
public function handle()
{
public function handle() {
// add new col
// check if col exists
if (Schema::hasTable('pet_variant_drop_data')) {
$this->info('Already updated tables, updating data.');
}
else {
Schema::table('pet_drop_data', function($table) {
} else {
Schema::table('pet_drop_data', function ($table) {
$table->string('name')->default('drop');
$table->integer('frequency');
$table->string('interval')->default('Hour');
$table->integer('cap')->default(null)->nullable();
$table->boolean('override')->default(false);
});
Schema::table('pet_categories', function($table) {
Schema::table('pet_categories', function ($table) {
$table->integer('limit')->default(null)->nullable();
});
Schema::table('pets', function($table) {
Schema::table('pets', function ($table) {
$table->integer('limit')->default(null)->nullable();
});
Schema::create('pet_variant_drop_data', function($table) {
Schema::create('pet_variant_drop_data', function ($table) {
$table->increments('id');
$table->integer('variant_id')->unsigned();
$table->json('data')->default(null)->nullable();
Expand All @@ -69,52 +62,51 @@ public function handle()

// convert old data
$drop_data = \App\Models\Pet\PetDropData::all();
foreach($drop_data as $drop) {
foreach ($drop_data as $drop) {
// check if 'assets' offset exists on $drop->data, if it does continue
if (isset($drop->data['assets'])) {
$this->line('Skipping drop data for pet: ' . $drop->pet->name . '...');
$this->line('Skipping drop data for pet: '.$drop->pet->name.'...');
} else {
$this->line('Converting drop data for pet: ' . $drop->pet->name . '...');
$this->line('Converting drop data for pet: '.$drop->pet->name.'...');
$drop->name = $drop->data['drop_name'];
$drop->frequency = $drop->data['frequency']['frequency'];
$drop->interval = $drop->data['frequency']['interval'];
$drop->cap = $drop->data['cap'];
$this->convertItems($drop, $drop->data['items']);
$this->info('Converted drop data for pet: ' . $drop->pet->name . '.');
$this->info('Converted drop data for pet: '.$drop->pet->name.'.');
}
}

// update variant images to use ID instead of name
$variants = \App\Models\Pet\PetVariant::all();
foreach($variants as $variant) {
$this->line('Updating variant image for variant: ' . $variant->variant_name . '...');
foreach ($variants as $variant) {
$this->line('Updating variant image for variant: '.$variant->variant_name.'...');
// rename image
$old_image = $variant->imageDirectory . '/' . $variant->pet_id .'-'. $variant->variant_name .'-image.png';
$old_image = $variant->imageDirectory.'/'.$variant->pet_id.'-'.$variant->variant_name.'-image.png';
// rename
if(File::exists(public_path($old_image))) {
$new_image = $variant->imageDirectory . '/' . $variant->pet_id .'-variant-'. $variant->id .'-image.png';
if (File::exists(public_path($old_image))) {
$new_image = $variant->imageDirectory.'/'.$variant->pet_id.'-variant-'.$variant->id.'-image.png';
File::move(public_path($old_image), public_path($new_image));
}
}
}

private function convertItems($drop, $data) {
foreach($data as $key => $group) {
$this->line('Converting group: ' . $key . '...');
foreach ($data as $key => $group) {
$this->line('Converting group: '.$key.'...');
// if it's the base pet, put it on the data table
if($key == "pet") {
if ($key == 'pet') {
$assets = [];
foreach($group as $name => $item) {
foreach ($group as $name => $item) {
$assets[strtolower($name)]['items'][$item['item_id']] = [
'min_quantity' => $item['min'],
'max_quantity' => $item['max'],
];
}
$drop->data = ['assets' => $assets];
}
else {
} else {
$assets = [];
foreach($group as $name => $item) {
foreach ($group as $name => $item) {
$assets[strtolower($name)]['items'][$item['item_id']] = [
'min_quantity' => $item['min'],
'max_quantity' => $item['max'],
Expand All @@ -123,7 +115,7 @@ private function convertItems($drop, $data) {
// if not "pet" we create a PetVariantDropData entry with the data
\App\Models\Pet\PetVariantDropData::create([
'variant_id' => $key,
'data' => json_encode(['assets' => $assets]),
'data' => json_encode(['assets' => $assets]),
]);
}
}
Expand Down
39 changes: 17 additions & 22 deletions app/Console/Commands/update_timed_stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Shop\ShopStock;
use App\Models\Shop\Shop;
use App\Models\Shop\ShopStock;
use Carbon\Carbon;
use Illuminate\Console\Command;

class update_timed_stock extends Command
{
class update_timed_stock extends Command {
/**
* The name and signature of the console command.
*
Expand All @@ -25,11 +24,8 @@ class update_timed_stock extends Command

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
public function __construct() {
parent::__construct();
}

Expand All @@ -38,33 +34,32 @@ public function __construct()
*
* @return int
*/
public function handle()
{
public function handle() {
$hidestock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 1)->where('start_at', '<=', Carbon::now())->where('end_at', '<=', Carbon::now())->orWhere('is_timed_stock', 1)->where('is_visible', 1)->whereNull('start_at')->where('end_at', '<=', Carbon::now())->get();
$showstock = ShopStock::where('is_timed_stock', 1)->where('is_visible', 0)->where('start_at', '<=', Carbon::now())->where('end_at', '>=', Carbon::now())->orWhere('is_timed_stock', 1)->where('is_visible', 0)->where('start_at', '<=', Carbon::now())->whereNull('end_at')->get();
//set stock that should be active to active
foreach($showstock as $showstock) {
foreach ($showstock as $showstock) {
$showstock->is_visible = 1;
$showstock->save();
}
}
//hide stock that should be hidden now
foreach($hidestock as $hidestock) {
$hidestock->is_visible = 0;
$hidestock->save();
}
foreach ($hidestock as $hidestock) {
$hidestock->is_visible = 0;
$hidestock->save();
}

//also activate or deactivate the shops
$hideshop = Shop::where('is_timed_shop', 1)->where('is_active', 1)->where('start_at', '<=', Carbon::now())->where('end_at', '<=', Carbon::now())->orWhere('is_timed_shop', 1)->where('is_active', 0)->whereNull('start_at')->where('end_at', '>=', Carbon::now())->get();
$showshop = Shop::where('is_timed_shop', 1)->where('is_active', 0)->where('start_at', '<=', Carbon::now())->where('end_at', '>=', Carbon::now())->orWhere('is_timed_shop', 1)->where('is_active', 0)->where('start_at', '<=', Carbon::now())->whereNull('end_at')->get();
//set shop that should be active to active
foreach($showshop as $showshop) {
foreach ($showshop as $showshop) {
$showshop->is_active = 1;
$showshop->save();
}
}
//hide shop that should be hidden now
foreach($hideshop as $hideshop) {
$hideshop->is_active = 0;
$hideshop->save();
}
foreach ($hideshop as $hideshop) {
$hideshop->is_active = 0;
$hideshop->save();
}
}
}
Loading

0 comments on commit d6b1828

Please sign in to comment.