整合 添加到充值日志

This commit is contained in:
iVampireSP.com 2022-11-18 16:15:30 +08:00
parent 255e7633d0
commit 96bc9210f7
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 17 additions and 16 deletions

View File

@ -3,7 +3,6 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Exceptions\ChargeException; use App\Exceptions\ChargeException;
use App\Models\Balance;
use App\Models\Transaction; use App\Models\Transaction;
use App\Models\User; use App\Models\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@ -50,31 +49,20 @@ public function handle()
// find user // find user
$user = User::findOrFail($user_id); $user = User::findOrFail($user_id);
$balance = new Balance();
$this->info($user->name . ', 当前余额: ' . $user->balance . ' 元'); $this->info($user->name . ', 当前余额: ' . $user->balance . ' 元');
$this->info('充值后余额: ' . ($user->balance + $amount) . ' 元'); $this->info('充值后余额: ' . ($user->balance + $amount) . ' 元');
if (!$this->confirm('确认充值 ' . $amount . ' 元?')) { if (!$this->confirm('确认充值 ' . $amount . ' 元?')) {
$this->info('已取消。'); $this->info('已取消。');
return; return 0;
} }
$data = [
'user_id' => $user->id,
'amount' => $amount,
'payment' => 'console',
];
$balance = $balance->create($data);
$transaction = new Transaction(); $transaction = new Transaction();
$description = '控制台充值 ' . $amount . ' 元'; $description = '控制台充值 ' . $amount . ' 元';
try { try {
$transaction->addAmount($user->id, 'console', $amount, $description); $transaction->addAmount($user->id, 'console', $amount, $description, true);
$this->info('充值成功。'); $this->info('充值成功。');
@ -84,5 +72,8 @@ public function handle()
return $this->error($e->getMessage()); return $this->error($e->getMessage());
} }
return 1;
} }
} }

View File

@ -113,7 +113,7 @@ private function addLog($user_id, $data)
$current = [ $current = [
'balance' => (float) $user->balance, 'balance' => (float)$user->balance,
'drops' => $this->getDrops($user_id), 'drops' => $this->getDrops($user_id),
'user_id' => intval($user_id), 'user_id' => intval($user_id),
]; ];
@ -278,7 +278,7 @@ public function addHostPayoutBalance($user_id, $host_id, $module_id, $amount, $d
/** /**
* @throws ChargeException * @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); $lock = Cache::lock("user_balance_lock_" . $user_id, 10);
try { try {
@ -297,6 +297,16 @@ public function addAmount($user_id, $payment = 'console', $amount = 0, $descript
$description = '充值 ' . $amount . ' 元'; $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); $this->addIncomeBalance($user_id, $payment, $amount, $description);
} catch (LockTimeoutException $e) { } catch (LockTimeoutException $e) {
Log::error($e); Log::error($e);