Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletExpected.php
Show All 9 Lines | |||||
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'; | 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'; | protected $description = 'Show expected charges to wallets (for user)'; | ||||
/** | /** | ||||
* Create a new command instance. | * Create a new command instance. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
parent::__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')) { | |||||
$user = \App\User::where('email', $this->option('user')) | |||||
->orWhere('id', $this->option('user'))->first(); | |||||
if (!$user) { | |||||
return 1; | |||||
} | |||||
$wallets = $user->wallets; | |||||
} else { | |||||
$wallets = \App\Wallet::all(); | $wallets = \App\Wallet::all(); | ||||
} | |||||
foreach ($wallets as $wallet) { | foreach ($wallets as $wallet) { | ||||
$charge = 0; | $charge = 0; | ||||
$expected = $wallet->expectedCharges(); | $expected = $wallet->expectedCharges(); | ||||
if ($expected > 0) { | if (!$wallet->owner) { | ||||
$this->info("expect charging wallet {$wallet->id} for user {$wallet->owner->email} with {$expected}"); | \Log::debug("{$wallet->id} has no owner: {$wallet->user_id}"); | ||||
continue; | |||||
} | } | ||||
if ($this->option('non-zero') && $expected < 1) { | |||||
continue; | |||||
} | |||||
$this->info( | |||||
sprintf( | |||||
"expect charging wallet %s for user %s with %d", | |||||
$wallet->id, | |||||
$wallet->owner->email, | |||||
$expected | |||||
) | |||||
); | |||||
} | } | ||||
} | } | ||||
} | } |