Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/Wallet/ExpectedCommand.php
- This file was moved from src/app/Console/Commands/WalletExpected.php.
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands\Wallet; | ||||
use App\Console\Command; | use App\Console\Command; | ||||
class WalletExpected extends Command | class ExpectedCommand 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}'; | ||||
Show All 10 Lines | class ExpectedCommand extends Command | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
if ($this->option('user')) { | if ($this->option('user')) { | ||||
$user = $this->getUser($this->option('user')); | $user = $this->getUser($this->option('user')); | ||||
if (!$user) { | if (!$user) { | ||||
$this->error("User not found."); | |||||
return 1; | return 1; | ||||
} | } | ||||
$wallets = $user->wallets; | $wallets = $user->wallets; | ||||
} else { | } else { | ||||
$wallets = \App\Wallet::select('wallets.*') | $wallets = \App\Wallet::select('wallets.*') | ||||
->join('users', 'users.id', '=', 'wallets.user_id') | ->join('users', 'users.id', '=', 'wallets.user_id') | ||||
->withEnvTenantContext('users') | ->withEnvTenantContext('users') | ||||
->all(); | ->whereNull('users.deleted_at'); | ||||
} | } | ||||
foreach ($wallets as $wallet) { | $wallets->each(function ($wallet) { | ||||
$charge = 0; | $charge = 0; | ||||
$expected = $wallet->expectedCharges(); | $expected = $wallet->expectedCharges(); | ||||
if (!$wallet->owner) { | |||||
\Log::debug("{$wallet->id} has no owner: {$wallet->user_id}"); | |||||
continue; | |||||
} | |||||
if ($this->option('non-zero') && $expected < 1) { | if ($this->option('non-zero') && $expected < 1) { | ||||
continue; | return; | ||||
} | } | ||||
$this->info( | $this->info( | ||||
sprintf( | sprintf( | ||||
"expect charging wallet %s for user %s with %d", | "expect charging wallet %s for user %s with %d", | ||||
$wallet->id, | $wallet->id, | ||||
$wallet->owner->email, | $wallet->owner->email, | ||||
$expected | $expected | ||||
) | ) | ||||
); | ); | ||||
} | }); | ||||
} | } | ||||
} | } |