修复 控制台充值和扣除余额
This commit is contained in:
parent
3f3d6efe61
commit
950cfe1c8e
@ -5,6 +5,7 @@
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class ReduceBalance extends Command
|
||||
{
|
||||
@ -20,7 +21,7 @@ class ReduceBalance extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '减少用户的余额(发生退款时使用)';
|
||||
protected $description = '减少用户的余额。';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -35,12 +36,10 @@ public function __construct()
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): void
|
||||
public function handle(): int
|
||||
{
|
||||
//
|
||||
|
||||
$user_id = $this->argument('user_id');
|
||||
|
||||
$amount = $this->argument('amount');
|
||||
@ -55,13 +54,14 @@ public function handle(): void
|
||||
|
||||
$confirm = $this->confirm('确认扣除?');
|
||||
|
||||
$transaction = new Transaction();
|
||||
if ($confirm) {
|
||||
$transaction->reduceAmount($user_id, $amount, '控制台扣除。');
|
||||
$user->reduce($amount, '控制台扣除。');
|
||||
|
||||
$this->info('扣除成功。');
|
||||
} else {
|
||||
$this->info('取消扣除。');
|
||||
}
|
||||
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Command\Command as CommandAlias;
|
||||
|
||||
class UserAddBalance extends Command
|
||||
{
|
||||
@ -20,7 +21,7 @@ class UserAddBalance extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '为用户充值,用法: 用户ID, 金额。';
|
||||
protected $description = '为用户充值。';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -39,8 +40,6 @@ public function __construct()
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
//
|
||||
|
||||
$user_id = $this->argument('user_id');
|
||||
$amount = $this->argument('amount');
|
||||
|
||||
@ -56,17 +55,16 @@ public function handle(): int
|
||||
return 0;
|
||||
}
|
||||
|
||||
$transaction = new Transaction();
|
||||
|
||||
$description = '控制台充值 '.$amount.' 元';
|
||||
|
||||
$transaction->addAmount($user->id, 'console', $amount, $description, true);
|
||||
$user->charge($amount, 'console', $description);
|
||||
|
||||
$this->info('充值成功。');
|
||||
|
||||
$user->refresh();
|
||||
|
||||
$this->info($user->name.', 当前余额: '.$user->balance);
|
||||
|
||||
return 0;
|
||||
return CommandAlias::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user