Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletCharge.php
Show All 31 Lines | class WalletCharge extends Command | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$wallets = \App\Wallet::all(); | // Get all wallets, excluding deleted accounts | ||||
$wallets = \App\Wallet::join('users', 'users.id', '=', 'wallets.user_id') | |||||
->whereNull('users.deleted_at') | |||||
->get(); | |||||
vanmeeuwen: Should we also say, something like "where number of entitlements > 0"?
Because the thing is… | |||||
Done Inline ActionsWe could, but it would not give us much improvement. I'd not do this. And I wouldn't be so sure that it's most users. machniak: We could, but it would not give us much improvement. I'd not do this.
And I wouldn't be so… | |||||
Not Done Inline ActionsFor the sake of memory consumption then, does it make sense to, instead of ->get(), do an ->each() over a closure? vanmeeuwen: For the sake of memory consumption then, does it make sense to, instead of `->get()`, do an `… | |||||
foreach ($wallets as $wallet) { | foreach ($wallets as $wallet) { | ||||
$charge = $wallet->chargeEntitlements(); | $charge = $wallet->chargeEntitlements(); | ||||
if ($charge > 0) { | if ($charge > 0) { | ||||
$this->info( | $this->info( | ||||
"Charged wallet {$wallet->id} for user {$wallet->owner->email} with {$charge}" | "Charged wallet {$wallet->id} for user {$wallet->owner->email} with {$charge}" | ||||
); | ); | ||||
// Top-up the wallet if auto-payment enabled for the wallet | // Top-up the wallet if auto-payment enabled for the wallet | ||||
\App\Jobs\WalletCharge::dispatch($wallet); | \App\Jobs\WalletCharge::dispatch($wallet); | ||||
} | } | ||||
if ($wallet->balance < 0) { | |||||
// Check the account balance, send notifications, suspend, delete | |||||
\App\Jobs\WalletCheck::dispatch($wallet); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
Should we also say, something like "where number of entitlements > 0"?
Because the thing is, everyone gets a wallet, but at least currently, most users have no entitlements charged to their wallets.