Ken il y a 4 jours
Parent
commit
476f007f72

+ 10 - 0
app/Models/Backflow.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Models;
+
+class Backflow extends BaseModel
+{
+    protected $table = 'backflow';
+    protected $fillable = ['date', 'member_id', 'recharge_amount', 'withdrawal_amount', 'backflow_ratio', 'amount', 'status'];
+    protected $hidden = ['updated_at'];
+}

+ 41 - 0
app/Services/BackflowService.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Services;
+
+use App\Models\Backflow;
+use App\Models\Config;
+use Carbon\Carbon;
+
+class BackflowService extends BaseService
+{
+    public static string $MODEL = Backflow::class;
+
+    /**
+     * @param $memberId string 会员ID
+     * @param  $changeAmount float 充值或提现金额
+     * @return Backflow
+     */
+    public static function updateOrCreate(string $memberId, float $changeAmount): Backflow
+    {
+        $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
+        $data['backflow_ratio'] = Config::where('field', 'huishui_percentage')->first()->val;
+        if ($changeAmount > 0) $data['recharge_amount'] = $changeAmount;
+        else $data['withdrawal_amount'] = $changeAmount;
+
+        $backflow = static::$MODEL::where('date', $data['date'])
+            ->where('member_id', $memberId)->first();
+        if ($backflow) {
+            $backflow->update($data);
+        } else {
+            $backflow = static::$MODEL::create($data);
+        }
+        return $backflow;
+    }
+
+
+    public static function getWhere(array $search = []): array
+    {
+
+        return [];
+    }
+}

+ 9 - 1
app/Services/BalanceLogService.php

@@ -9,6 +9,8 @@ class BalanceLogService extends BaseService
 {
     public static string $MODEL = BalanceLog::class;
     public static array $manualRecharge = ['人工充值', '注册赠送', '优惠活动'];
+    //需要计算回水的类型
+    public static array $computeBackFlowChangeTypes = ['充值', '人工充值', '三方充值', '提现', '人工扣款', '三方提现'];
     public static array $RW = [
         '充值', '人工充值', '三方充值', '注册赠送', '优惠活动',
         '提现', '人工扣款', '三方提现', '投注',
@@ -123,6 +125,12 @@ class BalanceLogService extends BaseService
      */
     public static function addLog($memberId, $amount, $before_balance, $after_balance, $change_type, $related_id, $remark, $room_id = null)
     {
+
+        if (in_array($change_type, static::$computeBackFlowChangeTypes)) {
+            $backflow = BackflowService::updateOrCreate($memberId, $amount);
+        }
+
+
         $data = [];
         $data['member_id'] = $memberId;
         $data['amount'] = $amount;
@@ -132,7 +140,7 @@ class BalanceLogService extends BaseService
         $data['related_id'] = $related_id;
         $data['remark'] = $remark;
         if ($room_id) $data['room_id'] = $room_id;
-        return static::model()::create($data);
+        return static::$MODEL::create($data);
     }
 
     /**

+ 38 - 0
database/migrations/2026_01_27_141638_create_backflow.php

@@ -0,0 +1,38 @@
+<?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::create('backflow', function (Blueprint $table) {
+            $table->engine = 'InnoDB';
+            $table->id();
+            $table->string('date', 32)->comment('日期');
+            $table->string('member_id', 32)->comment('会员id');
+            $table->decimal('recharge_amount', 10, 2)->default(0)->comment('充值金额');
+            $table->decimal('withdrawal_amount', 10, 2)->default(0)->comment('提现金额');
+            $table->decimal('backflow_ratio', 10, 2)->nullable()->comment('回水比例');
+            $table->decimal('amount', 10, 2)->default(0)->comment('回水金额');
+            $table->tinyInteger('status')->default(0)->comment('0未回水,1已回水');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('backflow');
+    }
+};