Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletCharge.php
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use App\Console\Command; | |||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Console\Command; | |||||
class WalletCharge extends Command | class WalletCharge 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:charge {wallet?}'; | protected $signature = 'wallet:charge {wallet?}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Charge wallets'; | protected $description = 'Charge wallets'; | ||||
/** | /** | ||||
* 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 ($wallet = $this->argument('wallet')) { | if ($wallet = $this->argument('wallet')) { | ||||
// Find specified wallet by ID | // Find specified wallet by ID | ||||
$wallet = Wallet::find($wallet); | $wallet = $this->getWallet($wallet); | ||||
if (!$wallet || !$wallet->owner) { | if (!$wallet || !$wallet->owner) { | ||||
return 1; | return 1; | ||||
} | } | ||||
$wallets = [$wallet]; | $wallets = [$wallet]; | ||||
} else { | } else { | ||||
// Get all wallets, excluding deleted accounts | // Get all wallets, excluding deleted accounts | ||||
$wallets = Wallet::select('wallets.*') | $wallets = Wallet::select('wallets.*') | ||||
->join('users', 'users.id', '=', 'wallets.user_id') | ->join('users', 'users.id', '=', 'wallets.user_id') | ||||
->withEnvTenant('users') | |||||
->whereNull('users.deleted_at') | ->whereNull('users.deleted_at') | ||||
->cursor(); | ->cursor(); | ||||
} | } | ||||
foreach ($wallets as $wallet) { | foreach ($wallets as $wallet) { | ||||
$charge = $wallet->chargeEntitlements(); | $charge = $wallet->chargeEntitlements(); | ||||
if ($charge > 0) { | if ($charge > 0) { | ||||
Show All 15 Lines |