seven 2 روز پیش
والد
کامیت
5d2cb4801c
1فایلهای تغییر یافته به همراه15 افزوده شده و 5 حذف شده
  1. 15 5
      app/Services/WithdrawService.php

+ 15 - 5
app/Services/WithdrawService.php

@@ -296,7 +296,12 @@ class WithdrawService
 
         $wallet = Wallet::where('member_id', $chatId)->first();
         $temp = floatval($wallet->available_balance);
-        if ($amount > $temp) {
+        // 汇率
+        $rate = Config::where('field', 'exchange_rate_rmb')->first()->val??1;
+        $rate_usdt_amount = bcdiv($temp, $rate, 2);  // 钱包可用余额 折合USDT
+
+        $rate_rmb_amount = bcmul($amount, $rate, 2);  // 提现金额 折合RMB
+        if ($amount > $rate_usdt_amount) {
             return [
                 'chat_id' => $chatId,
                 'text' => "⚠️可用余额不足,请重试",
@@ -325,10 +330,10 @@ class WithdrawService
         $wallet = Wallet::where('member_id', $chatId)->first();
         $bl = new BalanceLog();
         $bl->member_id = $chatId;
-        $bl->amount = $amount * -1;
+        $bl->amount = bcmul(($amount * -1),$rate,10); // 扣除的金额 RMB
         $bl->before_balance = $wallet->available_balance;
 
-        $wallet->available_balance = bcsub($wallet->available_balance, $amount, 10);
+        $wallet->available_balance = bcsub($wallet->available_balance, $rate_rmb_amount, 10);
         $wallet->save();
         $bl->after_balance = $wallet->available_balance;
         $bl->change_type = '提现';
@@ -348,7 +353,9 @@ class WithdrawService
 
         $temp = floatval($wallet->available_balance);
         $text = "✅ 提现申请已提交!\n\n";
-        $text .= "钱包余额:{$temp} USDT\n";
+        $text .= "钱包余额:{$temp} RMB\n";
+        $text .= "汇率:1 USDT = {$rate} RMB\n";
+        $text .= "剩余可用USDT余额:".number_format(bcdiv($temp, $rate, 2), 2)." USDT\n";
         $text .= "提现金额:{$amount} USDT\n";
         $text .= "实际到账:{$real} USDT\n";
         $text .= "手续费:{$serviceCharge} USDT\n\n";
@@ -410,6 +417,9 @@ class WithdrawService
         }
         $wallet = Wallet::where('member_id', $chatId)->first();
         $temp = floatval($wallet->available_balance);
+        // 汇率
+        $rate = Config::where('field', 'exchange_rate_rmb')->first()->val??1;
+        $rate_amount = bcdiv($temp, $rate, 2);
         if ($amount <= $this->serviceCharge) {
             return [[
                 'chat_id' => $chatId,
@@ -417,7 +427,7 @@ class WithdrawService
                 'reply_to_message_id' => $messageId
             ]];
         }
-        if ($amount > $temp) {
+        if ($amount > $rate_amount) {
             return [[
                 'chat_id' => $chatId,
                 'text' => "⚠️可用余额不足,请重试",