initial: bootstrap from BukidBountyApp base

This commit is contained in:
Jonathan Sykes
2026-06-06 18:43:00 +08:00
commit eb4a5731fb
5674 changed files with 160857 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use Hypervel\Console\Command;
use Hypervel\Support\Facades\DB;
use Hypervel\Support\Facades\Redis;
use Throwable;
class CheckConnectionsCommand extends Command
{
protected ?string $signature = 'app:check-connections {--detail : Show extended info (Redis INFO, DB version)}';
protected string $description = 'Test DB and Redis connectivity; exits 1 if any check fails (use in startup scripts)';
public function handle(): int
{
$allOk = true;
// ── MySQL ─────────────────────────────────────────────────────────────
$this->line('');
$this->line('<fg=cyan>Checking MySQL...</>');
try {
$t = microtime(true);
$result = DB::select('SELECT 1 AS ok');
$ms = round((microtime(true) - $t) * 1000, 1);
if ($result && $result[0]->ok === 1) {
$this->line(" <fg=green>✓</> Connected ({$ms}ms)");
if ($this->option('detail')) {
$ver = DB::select('SELECT VERSION() AS v');
$this->line(' Version: ' . ($ver[0]->v ?? '?'));
$pool = config('database.connections.mysql.pool');
$this->line(' Pool max_connections: ' . ($pool['max_connections'] ?? '?'));
$this->line(' Pool heartbeat: ' . ($pool['heartbeat'] ?? '?'));
$this->line(' Pool max_idle_time: ' . ($pool['max_idle_time'] ?? '?'));
}
} else {
$this->line(' <fg=red>✗</> Unexpected response from SELECT 1');
$allOk = false;
}
} catch (Throwable $e) {
$this->line(' <fg=red>✗</> ' . $e->getMessage());
$allOk = false;
}
// ── Redis ─────────────────────────────────────────────────────────────
$this->line('');
$this->line('<fg=cyan>Checking Redis...</>');
try {
$t = microtime(true);
$pong = Redis::ping();
$ms = round((microtime(true) - $t) * 1000, 1);
$this->line(" <fg=green>✓</> PING → {$pong} ({$ms}ms)");
if ($this->option('detail')) {
$info = Redis::info();
$this->line(' Version: ' . ($info['redis_version'] ?? '?'));
$this->line(' Used memory: ' . ($info['used_memory_human'] ?? '?'));
$this->line(' Connected clients: ' . ($info['connected_clients'] ?? '?'));
}
} catch (Throwable $e) {
$this->line(' <fg=red>✗</> ' . $e->getMessage());
$allOk = false;
}
// ── Summary ───────────────────────────────────────────────────────────
$this->line('');
if ($allOk) {
$this->info('All connections OK.');
return 0;
}
$this->error('One or more connections FAILED. Check the errors above.');
return 1;
}
}

View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use Hypervel\Console\Command;
class DemoCommand extends Command
{
protected ?string $signature = 'demo:hi {--name=}';
protected string $description = 'Hyperf Demo Command';
public function handle()
{
$this->info('Hello ' . ($this->option('name') ?: 'Hypervel'));
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Models\User;
use App\Models\Market\UserInfo;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as SymfonyCommand;
use Psr\Container\ContainerInterface;
/**
* @Command
*/
class ImportReadmeMemberData extends SymfonyCommand
{
public function __construct(protected ContainerInterface $container)
{
parent::__construct('import:readme-member');
}
public function configure()
{
parent::configure();
$this->setDescription('Import member data from README.md for Rex Moran Loba');
}
public function handle()
{
$email = 'rexm.loba@gmail.com';
$user = User::where('email', $email)->first();
if (!$user) {
$this->output->info("User with email {$email} not found. Creating...");
$user = User::create([
'name' => 'Rex Moran Loba',
'fullname' => 'Rex Moran Loba',
'email' => $email,
'username' => 'rexmloba',
'password' => password_hash('password', PASSWORD_DEFAULT),
'hashkey' => bin2hex(random_bytes(16)),
'active' => true,
]);
}
$userInfo = $user->userInfo;
if (!$userInfo) {
$userInfo = new UserInfo(['user_id' => $user->id]);
$userInfo->hashkey = bin2hex(random_bytes(16));
}
$userInfo->firstname = 'Rex Moran';
$userInfo->lastname = 'Loba';
$userInfo->email = $email;
$userInfo->is_active = true;
// Example address data based on feedback
$userInfo->addresses = [
[
'house_no' => 'Unit 1234',
'street' => 'Street Name',
'barangay' => 'Barangay Name',
'city' => 'City Name',
'province' => 'Province Name',
'region' => 'Region Name',
'country' => 'Philippines',
'zipcode' => '1234'
]
];
if ($userInfo->save()) {
$this->output->success("Profile for Rex Moran Loba updated successfully.");
} else {
$this->output->error("Failed to update profile.");
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Models\User;
use Hypervel\Console\Command;
class ResetAllUsersCommand extends Command
{
protected ?string $signature = 'app:reset-users {--message= : Optional toast message shown before reload}';
protected string $description = 'Queue a browser reload for all users on their next SSE tick (next login or active session).';
public function handle()
{
$message = $this->option('message') ?: 'App update applied. Reloading...';
$js = "sessionStorage.clear(); alert('" . addslashes($message) . "'); window.location.reload();";
$affected = User::whereNotNull('id')->update(['exec_command' => $js]);
$this->info("Reset command queued for {$affected} users.");
$this->line("Command: <comment>{$js}</comment>");
}
}

View File

@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Models\Market\Product;
use App\Models\Market\Store;
use App\Models\User;
use Hypervel\Console\Command;
use Hypervel\Support\Facades\Auth;
class SeedDemoProducts extends Command
{
protected ?string $signature = 'demo:seed-products {store_hash : The hashkey of the target store}';
protected string $description = 'Seed demo agricultural products';
public function handle()
{
$storeHash = $this->argument('store_hash');
$store = Store::where('hashkey', $storeHash)->first();
if (! $store) {
$this->error('Store not found.');
return;
}
$ultimateUser = User::where('acct_type', 'ULTIMATE')->first();
if (! $ultimateUser) {
$this->error('No ULTIMATE user found.');
return;
}
Auth::loginUsingId($ultimateUser->id);
$products = [
['name' => 'Organic White Rice (25kg sack)', 'category' => 'Grains & Cereals', 'subcategory' => 'Rice', 'price' => 1200, 'unit' => 'sack', 'available' => 100],
['name' => 'Organic Brown Rice (5kg)', 'category' => 'Grains & Cereals', 'subcategory' => 'Rice', 'price' => 280, 'unit' => 'kg', 'available' => 200],
['name' => 'White Corn Grits', 'category' => 'Grains & Cereals', 'subcategory' => 'Corn', 'price' => 85, 'unit' => 'kg', 'available' => 300],
['name' => 'Yellow Corn (fresh ears)', 'category' => 'Grains & Cereals', 'subcategory' => 'Corn', 'price' => 35, 'unit' => 'piece', 'available' => 500],
['name' => 'Fresh Kangkong (Water Spinach)', 'category' => 'Fresh Produce', 'subcategory' => 'Leafy Vegetables', 'price' => 25, 'unit' => 'bundle', 'available' => 150],
['name' => 'Pechay (Bok Choy)', 'category' => 'Fresh Produce', 'subcategory' => 'Leafy Vegetables', 'price' => 30, 'unit' => 'bundle', 'available' => 150],
['name' => 'Ampalaya (Bitter Gourd)', 'category' => 'Fresh Produce', 'subcategory' => 'Vegetables', 'price' => 60, 'unit' => 'kg', 'available' => 100],
['name' => 'Sitaw (String Beans)', 'category' => 'Fresh Produce', 'subcategory' => 'Vegetables', 'price' => 55, 'unit' => 'bundle', 'available' => 120],
['name' => 'Kamote (Sweet Potato)', 'category' => 'Fresh Produce', 'subcategory' => 'Root Crops', 'price' => 40, 'unit' => 'kg', 'available' => 200],
['name' => 'Gabi (Taro Root)', 'category' => 'Fresh Produce', 'subcategory' => 'Root Crops', 'price' => 50, 'unit' => 'kg', 'available' => 150],
['name' => 'Sayote (Chayote)', 'category' => 'Fresh Produce', 'subcategory' => 'Vegetables', 'price' => 45, 'unit' => 'kg', 'available' => 180],
['name' => 'Labanos (Radish)', 'category' => 'Fresh Produce', 'subcategory' => 'Root Crops', 'price' => 30, 'unit' => 'bundle', 'available' => 100],
['name' => 'Fresh Tomatoes', 'category' => 'Fresh Produce', 'subcategory' => 'Vegetables', 'price' => 70, 'unit' => 'kg', 'available' => 200],
['name' => 'Carabao Mango (green)', 'category' => 'Fresh Produce', 'subcategory' => 'Fruits', 'price' => 90, 'unit' => 'kg', 'available' => 100],
['name' => 'Banana (Latundan)', 'category' => 'Fresh Produce', 'subcategory' => 'Fruits', 'price' => 65, 'unit' => 'hand', 'available' => 80],
['name' => 'Pineapple (Bukidnon)', 'category' => 'Fresh Produce', 'subcategory' => 'Fruits', 'price' => 80, 'unit' => 'piece', 'available' => 60],
['name' => 'Native Chicken (live)', 'category' => 'Livestock & Poultry', 'subcategory' => 'Poultry', 'price' => 350, 'unit' => 'piece', 'available' => 30],
['name' => 'Free-range Eggs', 'category' => 'Livestock & Poultry', 'subcategory' => 'Eggs', 'price' => 12, 'unit' => 'piece', 'available' => 500],
['name' => 'Fresh Tilapia', 'category' => 'Seafood', 'subcategory' => 'Freshwater Fish', 'price' => 130, 'unit' => 'kg', 'available' => 50],
['name' => 'Bangus (Milkfish)', 'category' => 'Seafood', 'subcategory' => 'Saltwater Fish', 'price' => 180, 'unit' => 'kg', 'available' => 50],
['name' => 'Carabao Milk (1L)', 'category' => 'Processed Goods', 'subcategory' => 'Dairy', 'price' => 120, 'unit' => 'liter', 'available' => 60],
['name' => 'Coconut Oil (Virgin, 1L)', 'category' => 'Processed Goods', 'subcategory' => 'Oils', 'price' => 250, 'unit' => 'bottle', 'available' => 40],
['name' => 'Organic Peanuts (roasted)', 'category' => 'Processed Goods', 'subcategory' => 'Nuts', 'price' => 95, 'unit' => '250g pack', 'available' => 80],
['name' => 'Muscovado Sugar', 'category' => 'Processed Goods', 'subcategory' => 'Sweeteners', 'price' => 110, 'unit' => '250g pack', 'available' => 60],
['name' => 'Fresh Turmeric (Luyang Dilaw)', 'category' => 'Fresh Produce', 'subcategory' => 'Herbs & Spices', 'price' => 60, 'unit' => '100g pack', 'available' => 100],
];
$created = [];
foreach ($products as $item) {
$product = new Product();
$product->name = $item['name'];
$product->category = $item['category'];
$product->subcategory = $item['subcategory'];
$product->price = $item['price'];
$product->unitname = $item['unit'];
$product->description = $item['name'];
$product->is_active = true;
$product->save();
$store->products()->attach($product->id, [
'price' => $item['price'],
'available' => $item['available'],
'is_active' => true,
]);
$created[] = $product;
}
$count = count($created);
$this->info("Created {$count} products and attached to store {$store->name}");
}
}

26
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace App\Console;
use Hypervel\Console\Scheduling\Schedule;
use Hypervel\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command('demo:hi')->everyFiveSeconds();
}
public function commands(): void
{
$this->load(__DIR__ . '/Commands');
require base_path('routes/console.php');
}
}