Ken hai 2 semanas
pai
achega
f5993fee11
Modificáronse 1 ficheiros con 11 adicións e 13 borrados
  1. 11 13
      app/Services/WithdrawService.php

+ 11 - 13
app/Services/WithdrawService.php

@@ -299,6 +299,9 @@ class WithdrawService
         $temp = floatval($wallet->available_balance);
         // 汇率
         $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
+        $exchange_rate_difference = Config::where('field', 'exchange_rate_difference')->first()->val ?? 0;
+        $rate = bcadd($rate, $exchange_rate_difference, 2);
+
         $rate_usdt_amount = bcdiv($temp, $rate, 2);  // 钱包可用余额 折合USDT
 
         $rate_rmb_amount = bcmul($amount, $rate, 2);  // 提现金额 折合RMB
@@ -328,16 +331,7 @@ class WithdrawService
         }
 
 
-        $wallet = Wallet::where('member_id', $chatId)->first();
-        $bl = new BalanceLog();
-        $bl->member_id = $chatId;
-        $bl->amount = bcmul(($amount * -1), $rate, 10); // 扣除的金额 RMB
-        $bl->before_balance = $wallet->available_balance;
 
-        $wallet->available_balance = bcsub($wallet->available_balance, $rate_rmb_amount, 10);
-        $wallet->save();
-        $bl->after_balance = $wallet->available_balance;
-        $bl->change_type = lang('提现');
 
 
         $withdraw = new Withdraw();
@@ -350,10 +344,14 @@ class WithdrawService
         $withdraw->status = 0;
         $withdraw->after_balance = bcdiv($wallet->available_balance, $rate, 2);
         $withdraw->save();
-        $bl->related_id = $withdraw->id;
-        $bl->save();
-
-        $temp = floatval($wallet->available_balance);
+        $wallet = Wallet::where('member_id', $chatId)->first();
+        $changeAmount = bcmul(($amount * -1), $rate, 2);
+        $beforeBalance = $wallet->available_balance;
+        $afterBalance = bcsub($wallet->available_balance, $rate_rmb_amount, 2);
+        $wallet->available_balance = $afterBalance;
+        $wallet->save();
+        BalanceLogService::addLog($chatId,$changeAmount,$beforeBalance,$afterBalance,'提现',$withdraw->id,'');
+        $temp = floatval($afterBalance);
         $text = "✅ " . lang("提现申请已提交!") . "\n\n";
         $text .= lang("钱包余额") . ":{$temp} RMB\n";
         $text .= lang("汇率") . ":1 USDT = {$rate} RMB\n";