Ken 3 uur geleden
bovenliggende
commit
abc5c3a29d

+ 28 - 0
app/Http/Controllers/admin/Rebate.php

@@ -57,11 +57,38 @@ class Rebate extends Controller
             $rebateAmount = bcmul($rebate->betting_amount, $rebate_ratio, 2); // 返利金额
 
 
+            $huishuiAmount = 0;
+            //限额
+            $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
+            //比例
+            $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
+            $lose = $rebate->profit * -1;
+            if ($lose >= $huishui_restriction) {
+                $huishuiAmount = bcmul($rebate->profit, $huishui_percentage, 2); // 返利金额
+            }
+            $rebate->huishui_restriction = $huishui_restriction;
+            $rebate->huishui_percentage = $huishui_percentage;
+            $rebate->huishui_amount = $huishuiAmount;
+
             $rebate->amount = $rebateAmount;
             $rebate->rebate_ratio = $rebate_ratio;
             $rebate->status = 1;
             $rebate->audited_by = request()->user->username;
             $rebate->save();
+
+            if ($huishuiAmount > 0) {
+                $res = WalletService::updateBalance($rebate->member_id, $huishuiAmount);
+                BalanceLogService::addLog(
+                    $rebate->member_id,
+                    $huishuiAmount,
+                    $res['before_balance'],
+                    $res['after_balance'],
+                    "回水",
+                    $rebate->id,
+                    "输{$lose}; 回水{$huishuiAmount}");
+            }
+
+
             if ($rebateAmount > 0) {
                 $res = WalletService::updateBalance($rebate->member_id, $rebateAmount);
                 BalanceLogService::addLog(
@@ -74,6 +101,7 @@ class Rebate extends Controller
                     '');
             }
 
+
             DB::commit();
         } catch (ValidationException $e) {
             DB::rollBack();

+ 1 - 1
app/Models/Rebate.php

@@ -21,7 +21,7 @@ class Rebate extends Authenticatable
     // protected $hidden = ['created_at', 'updated_at'];
     protected $fillable = ['date', 'member_id', 'betting_amount', 'rebate_ratio',
         'amount', 'status', 'first_name', 'username', 'audited_by',
-        'profit', 'huishui_percentage', 'huishui_restriction'
+        'profit', 'huishui_percentage', 'huishui_restriction', 'huishui_amount',
     ];
 
 

+ 30 - 0
database/migrations/2025_11_20_151650_update_rebates.php

@@ -0,0 +1,30 @@
+<?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('rebates', function (Blueprint $table) {
+           $table->decimal('huishui_amount', 10, 2)->default(0)->comment('回水金额');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+};