整合 添加到充值日志
This commit is contained in:
parent
255e7633d0
commit
96bc9210f7
@ -3,7 +3,6 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Exceptions\ChargeException;
|
||||
use App\Models\Balance;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
@ -50,31 +49,20 @@ public function handle()
|
||||
// find user
|
||||
$user = User::findOrFail($user_id);
|
||||
|
||||
|
||||
$balance = new Balance();
|
||||
|
||||
$this->info($user->name . ', 当前余额: ' . $user->balance . ' 元');
|
||||
|
||||
$this->info('充值后余额: ' . ($user->balance + $amount) . ' 元');
|
||||
if (!$this->confirm('确认充值 ' . $amount . ' 元?')) {
|
||||
$this->info('已取消。');
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_id' => $user->id,
|
||||
'amount' => $amount,
|
||||
'payment' => 'console',
|
||||
];
|
||||
|
||||
$balance = $balance->create($data);
|
||||
|
||||
$transaction = new Transaction();
|
||||
|
||||
$description = '控制台充值 ' . $amount . ' 元';
|
||||
|
||||
try {
|
||||
$transaction->addAmount($user->id, 'console', $amount, $description);
|
||||
$transaction->addAmount($user->id, 'console', $amount, $description, true);
|
||||
|
||||
$this->info('充值成功。');
|
||||
|
||||
@ -84,5 +72,8 @@ public function handle()
|
||||
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ public function addHostPayoutBalance($user_id, $host_id, $module_id, $amount, $d
|
||||
/**
|
||||
* @throws ChargeException
|
||||
*/
|
||||
public function addAmount($user_id, $payment = 'console', $amount = 0, $description = null)
|
||||
public function addAmount($user_id, $payment = 'console', $amount = 0, $description = null, $add_to_balances = false)
|
||||
{
|
||||
$lock = Cache::lock("user_balance_lock_" . $user_id, 10);
|
||||
try {
|
||||
@ -297,6 +297,16 @@ public function addAmount($user_id, $payment = 'console', $amount = 0, $descript
|
||||
$description = '充值 ' . $amount . ' 元';
|
||||
}
|
||||
|
||||
if ($add_to_balances) {
|
||||
$data = [
|
||||
'user_id' => $user_id,
|
||||
'amount' => $amount,
|
||||
'payment' => $payment,
|
||||
];
|
||||
|
||||
Balance::create($data);
|
||||
}
|
||||
|
||||
$this->addIncomeBalance($user_id, $payment, $amount, $description);
|
||||
} catch (LockTimeoutException $e) {
|
||||
Log::error($e);
|
||||
|
Loading…
Reference in New Issue
Block a user