改进 搜索用户,增加 扣除余额
This commit is contained in:
parent
75f6276847
commit
b7c54413ba
@ -15,7 +15,7 @@ class GetUser extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user {id}';
|
||||
protected $signature = 'user {email_or_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@ -42,18 +42,19 @@ public function __construct()
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
$id = $this->argument('id');
|
||||
$email_or_id = $this->argument('email_or_id');
|
||||
|
||||
$user = User::where('email', $email_or_id)->orWhere('id', $email_or_id)->first();
|
||||
|
||||
$user = User::findOrFail($id);
|
||||
|
||||
$transaction = new Transaction();
|
||||
|
||||
$drops = $transaction->getDrops($id);
|
||||
$drops = $transaction->getDrops($user->id);
|
||||
|
||||
|
||||
$this->warn('用户基本信息');
|
||||
|
||||
$this->info('用户 ID: ' . $id);
|
||||
$this->info('用户 ID: ' . $user->id);
|
||||
$this->info('名称: ' . $user->name);
|
||||
$this->info('邮箱: ' . $user->email);
|
||||
$this->info('余额:' . $user->balance . ' 元');
|
||||
|
68
app/Console/Commands/ReduceBalance.php
Normal file
68
app/Console/Commands/ReduceBalance.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ReduceBalance extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:reduce {user_id} {amount}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '减少用户的余额(发生退款时使用)';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
//
|
||||
|
||||
$user_id = $this->argument('user_id');
|
||||
|
||||
$amount = $this->argument('amount');
|
||||
|
||||
|
||||
$user = User::find($user_id);
|
||||
|
||||
$this->warn('扣除金额: ' . $user->balance);
|
||||
|
||||
$this->warn('用户当前余额:' . $user->balance);
|
||||
|
||||
$this->warn('剩余余额:' . $user->balance - $amount);
|
||||
|
||||
$confirm = $this->confirm('确认扣除?');
|
||||
|
||||
$transaction = new Transaction();
|
||||
if ($confirm) {
|
||||
$transaction->reduceAmount($user_id, $amount, '控制台扣除。');
|
||||
|
||||
$this->info('扣除成功。');
|
||||
} else {
|
||||
$this->info('取消扣除');
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
use App\Console\Commands\BanUser;
|
||||
use App\Console\Commands\CalcModule;
|
||||
use App\Console\Commands\GetUser;
|
||||
use App\Console\Commands\ReduceBalance;
|
||||
use App\Console\Commands\SuspendUserAllHosts;
|
||||
use App\Console\Commands\UnbanUser;
|
||||
use App\Console\Commands\UserAddBalance;
|
||||
@ -32,6 +33,7 @@ class Kernel extends ConsoleKernel
|
||||
CalcModule::class,
|
||||
UserAddBalance::class,
|
||||
GetUser::class,
|
||||
ReduceBalance::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -194,16 +194,38 @@ public function addPayoutBalance($user_id, $amount, $description)
|
||||
return $this->addLog($user_id, $data);
|
||||
}
|
||||
|
||||
public function reduceAmount($user_id, $amount = 0, $description = '扣除费用请求。')
|
||||
{
|
||||
$user = User::findOrFail($user_id);
|
||||
|
||||
if ($user) {
|
||||
$user->balance -= $amount;
|
||||
|
||||
$user->save();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'type' => 'payout',
|
||||
'payment' => 'balance',
|
||||
'description' => $description,
|
||||
'income' => 0,
|
||||
'income_drops' => 0,
|
||||
'outcome' => $amount,
|
||||
'outcome_drops' => 0
|
||||
];
|
||||
|
||||
return $this->addLog($user_id, $data);
|
||||
}
|
||||
|
||||
|
||||
private function addLog($user_id, $data)
|
||||
{
|
||||
$user = User::find($user_id);
|
||||
|
||||
|
||||
$current = [
|
||||
'balance' => $user->balance,
|
||||
'drops' => $this->getDrops($user_id),
|
||||
'user_id' => $user_id,
|
||||
'user_id' => intval($user_id),
|
||||
];
|
||||
|
||||
// merge
|
||||
|
Loading…
Reference in New Issue
Block a user