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