Page MenuHomePhorge

D4971.id14232.diff
No OneTemporary

D4971.id14232.diff

diff --git a/src/app/Console/Commands/Wallet/ChargeCommand.php b/src/app/Console/Commands/Wallet/ChargeCommand.php
--- a/src/app/Console/Commands/Wallet/ChargeCommand.php
+++ b/src/app/Console/Commands/Wallet/ChargeCommand.php
@@ -11,14 +11,14 @@
*
* @var string
*/
- protected $signature = 'wallet:charge {wallet?}';
+ protected $signature = 'wallet:charge {--topup: Only top-up wallets} {--dry-run} {wallet?}';
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Charge wallets';
+ protected $description = 'Charge wallets, and trigger a topup on charged wallets.';
/**
* Execute the console command.
@@ -42,6 +42,18 @@
}
$wallets = [$wallet];
+ } elseif ($this->option('topup')) {
+ // Find wallets that need to be topped up
+ $wallets = \App\Wallet::select('wallets.id')
+ ->join('users', 'users.id', '=', 'wallets.user_id')
+ ->join('wallet_settings', function (\Illuminate\Database\Query\JoinClause $join) {
+ $join->on('wallet_settings.wallet_id', '=', 'wallets.id')
+ ->where('wallet_settings.key', '=', 'mandate_balance');
+ })
+ ->whereNull('users.deleted_at')
+ ->whereRaw('wallets.balance < (wallet_settings.value * 100)')
+ ->where('users.status', '=', '51')
+ ->cursor();
} else {
// Get all wallets, excluding deleted accounts
$wallets = \App\Wallet::select('wallets.id')
@@ -51,7 +63,15 @@
}
foreach ($wallets as $wallet) {
- \App\Jobs\WalletCheck::dispatch($wallet->id);
+ if ($this->option('dry')) {
+ \Log::debug("Dispatching job for wallet {$wallet->id}");
+ } else {
+ if ($this->option('topup')) {
+ \App\Jobs\WalletCharge::dispatch($wallet->id);
+ } else {
+ \App\Jobs\WalletCheck::dispatch($wallet->id);
+ }
+ }
}
}
}

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 19, 12:21 PM (21 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9886029
Default Alt Text
D4971.id14232.diff (2 KB)

Event Timeline