Ken 1 неделя назад
Родитель
Сommit
9c8f25d48a
2 измененных файлов с 49 добавлено и 42 удалено
  1. 6 42
      app/Http/Controllers/admin/Withdraw.php
  2. 43 0
      app/Services/WithdrawService.php

+ 6 - 42
app/Http/Controllers/admin/Withdraw.php

@@ -152,7 +152,8 @@ class Withdraw extends Controller
         DB::beginTransaction();
         try {
             $validate = [
-                'id' => ['required', 'string', 'min:1'],
+                'ids' => ['required', 'array', 'min:1'],
+                'ids.*' => ['required', 'integer', 'min:1'],
                 'status' => ['required', 'integer', 'in:1,2'],
             ];
             $status = request()->input('status');
@@ -160,49 +161,12 @@ class Withdraw extends Controller
                 $validate['remark'] = ['required', 'string', 'min:1', 'max:200'];
             }
             request()->validate($validate);
-            $id = request()->input('id');
-
-
-            $w = WithdrawService::findOne(['id' => $id, 'status' => 0]);
-
-            if (!$w) throw new Exception("数据不存在", HttpStatus::CUSTOM_ERROR);
-            // 汇率
-            $rate = $w->exchange_rate ?? 1;
-            if ($status == 1) {
-                $w->status = 1;
-                $w->save();
-
-
-            } else if ($status == 2) {
-                $rate_rmb_amount = bcmul($w->amount, $rate, 2);  // 提现金额 折合RMB
-                $w->status = 2;
-                $remark = request()->input('remark');
-                $w->remark = $remark;
-                $w->save();
-                $wallet = WalletService::findOne(['member_id' => $w->member_id]);
-                $afterBalance = bcadd($wallet->available_balance, $rate_rmb_amount, 10);
-                BalanceLogService::addLog($w->member_id, $w->rate_rmb_amount, $wallet->available_balance, $afterBalance, '提现', $w->id, '');
-                $wallet->available_balance = $afterBalance;
-                $wallet->save();
+            $ids = request()->input('ids');
+            $remark = request()->input('remark');
+            foreach ($ids as $id) {
+                WithdrawService::setStatus($id, $status, $remark);
             }
 
-            $arr = ['⏳️申请中', '✅️成功', '❌️失败'];
-            $text = "📢 提现结果通知\n\n";
-
-            $temp = floatval($w->service_charge);
-            $text .= "手续费:{$temp} USDT\n";
-            $temp = floatval($w->amount);
-            $text .= "提现金额:{$temp} USDT\n";
-            $temp = floatval($w->to_account);
-            $text .= "到账金额:{$temp} USDT\n";
-            $text .= "提现地址:{$w->address}\n\n";
-            $text .= "状态:{$arr[$w->status]}\n";
-            if ($w->remark) $text .= "说明:{$w->remark}";
-            $res = WithdrawService::notify([
-                'chat_id' => $w->member_id,
-                'text' => $text,
-            ]);
-
 
             DB::commit();
         } catch (ValidationException $e) {

+ 43 - 0
app/Services/WithdrawService.php

@@ -4,6 +4,7 @@
 namespace App\Services;
 
 
+use App\Constants\HttpStatus;
 use App\Constants\StepStatus;
 use App\Models\Address;
 use App\Models\BalanceLog;
@@ -13,6 +14,7 @@ use App\Models\RoomUser;
 use App\Models\User;
 use App\Models\Wallet;
 use App\Models\Withdraw;
+use Exception;
 use Illuminate\Support\Facades\Cache;
 use LaravelLang\Publisher\Console\Add;
 use Telegram\Bot\Api;
@@ -592,4 +594,45 @@ class WithdrawService
             'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
         ];
     }
+
+
+    public static function setStatus($id, $status, $remark)
+    {
+        $w = WithdrawService::findOne(['id' => $id, 'status' => 0]);
+        if (!$w) return;
+        // 汇率
+        $rate = $w->exchange_rate ?? 1;
+        if ($status == 1) {
+            $w->status = 1;
+            $w->save();
+        } else if ($status == 2) {
+            $rate_rmb_amount = bcmul($w->amount, $rate, 2);  // 提现金额 折合RMB
+            $w->status = 2;
+
+            $w->remark = $remark;
+            $w->save();
+            $wallet = WalletService::findOne(['member_id' => $w->member_id]);
+            $afterBalance = bcadd($wallet->available_balance, $rate_rmb_amount, 10);
+            BalanceLogService::addLog($w->member_id, $w->rate_rmb_amount, $wallet->available_balance, $afterBalance, '提现', $w->id, '');
+            $wallet->available_balance = $afterBalance;
+            $wallet->save();
+        }
+
+        $arr = ['⏳️申请中', '✅️成功', '❌️失败'];
+        $text = "📢 提现结果通知\n\n";
+
+        $temp = floatval($w->service_charge);
+        $text .= "手续费:{$temp} USDT\n";
+        $temp = floatval($w->amount);
+        $text .= "提现金额:{$temp} USDT\n";
+        $temp = floatval($w->to_account);
+        $text .= "到账金额:{$temp} USDT\n";
+        $text .= "提现地址:{$w->address}\n\n";
+        $text .= "状态:{$arr[$w->status]}\n";
+        if ($w->remark) $text .= "说明:{$w->remark}";
+        $res = WithdrawService::notify([
+            'chat_id' => $w->member_id,
+            'text' => $text,
+        ]);
+    }
 }