Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletCharge.php
Show All 36 Lines | class WalletCharge extends 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 = Wallet::find($wallet); | ||||
if (!$wallet || !$wallet->owner) { | if (!$wallet || !$wallet->owner || $wallet->owner->tenant_id != \config('app.tenant_id')) { | ||||
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') | ||||
->get(); | ->get(); | ||||
} | } | ||||
foreach ($wallets as $wallet) { | foreach ($wallets as $wallet) { | ||||
$charge = $wallet->chargeEntitlements(); | $charge = $wallet->chargeEntitlements(); | ||||
if ($charge > 0) { | if ($charge > 0) { | ||||
Show All 15 Lines |