seven 2 days ago
parent
commit
9eecd74238

+ 4 - 2
app/Http/Controllers/admin/Withdraw.php

@@ -92,11 +92,13 @@ class Withdraw extends Controller
             ]);
             $id = request()->input('id');
             $status = request()->input('status');
-                // 汇率
-            $rate = Config::where('field', 'exchange_rate_rmb')->first()->val??1;
+            
 
             $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();

+ 1 - 0
app/Services/WithdrawService.php

@@ -345,6 +345,7 @@ class WithdrawService
         $withdraw->service_charge = $serviceCharge;
         $withdraw->to_account = $real;
         $withdraw->address = $address;
+        $withdraw->exchange_rate = $rate;
         $withdraw->status = 0;
         $withdraw->after_balance = bcdiv($wallet->available_balance,$rate,2);
         $withdraw->save();

+ 34 - 0
database/migrations/2025_10_29_151423_add_exchange_rate_to_withdraws_table.php

@@ -0,0 +1,34 @@
+<?php
+
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('withdraws', function (Blueprint $table) {
+            // 添加汇率字段,decimal类型适合存储货币汇率
+            $table->decimal('exchange_rate', 10, 6)->nullable()->comment('汇率');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('withdraws', function (Blueprint $table) {
+            //
+        });
+    }
+};