Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/WalletGetDiscount.php
- This file was copied from src/app/Console/Commands/UserDomains.php.
<?php | <?php | ||||
namespace App\Console\Commands; | namespace App\Console\Commands; | ||||
use App\Domain; | |||||
use App\User; | |||||
use Illuminate\Console\Command; | use Illuminate\Console\Command; | ||||
use Illuminate\Support\Facades\DB; | |||||
class UserDomains extends Command | class WalletGetDiscount extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'user:domains {userid}'; | protected $signature = 'wallet:get-discount {wallet}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = 'Command description'; | protected $description = 'Display the existing discount to a wallet, if any.'; | ||||
/** | /** | ||||
* Create a new command instance. | * Create a new command instance. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
} | } | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = User::where('email', $this->argument('userid'))->first(); | $wallet = \App\Wallet::find($this->argument('wallet')); | ||||
$this->info("Found user: {$user->id}"); | if (!$wallet) { | ||||
return 1; | |||||
} | |||||
foreach ($user->domains() as $domain) { | if (!$wallet->discount) { | ||||
$this->info("Domain: {$domain->namespace}"); | $this->info("No discount on this wallet."); | ||||
return 0; | |||||
} | } | ||||
$this->info($wallet->discount->discount); | |||||
} | } | ||||
} | } |