Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletExpected.php
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use Illuminate\Console\Command; | use App\Console\Command; | ||||
class WalletExpected extends Command | class WalletExpected extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'wallet:expected {--user=} {--non-zero}'; | protected $signature = 'wallet:expected {--user=} {--non-zero}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Show expected charges to wallets (for user)'; | protected $description = 'Show expected charges to wallets (for user)'; | ||||
/** | /** | ||||
* Create a new command instance. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function __construct() | |||||
{ | |||||
parent::__construct(); | |||||
} | |||||
/** | |||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
if ($this->option('user')) { | if ($this->option('user')) { | ||||
$user = \App\User::where('email', $this->option('user')) | $user = $this->getUser($this->option('user')); | ||||
->orWhere('id', $this->option('user'))->first(); | |||||
if (!$user) { | if (!$user) { | ||||
return 1; | return 1; | ||||
} | } | ||||
$wallets = $user->wallets; | $wallets = $user->wallets; | ||||
} else { | } else { | ||||
$wallets = \App\Wallet::all(); | $wallets = \App\Wallet::select('wallets.*') | ||||
->join('users', 'users.id', '=', 'wallets.user_id') | |||||
->withEnvTenant('users') | |||||
->all(); | |||||
} | } | ||||
foreach ($wallets as $wallet) { | foreach ($wallets as $wallet) { | ||||
$charge = 0; | $charge = 0; | ||||
$expected = $wallet->expectedCharges(); | $expected = $wallet->expectedCharges(); | ||||
if (!$wallet->owner) { | if (!$wallet->owner) { | ||||
\Log::debug("{$wallet->id} has no owner: {$wallet->user_id}"); | \Log::debug("{$wallet->id} has no owner: {$wallet->user_id}"); | ||||
Show All 18 Lines |