Ken il y a 3 heures
Parent
commit
0ad4a376f1

+ 14 - 1
app/Models/Rebate.php

@@ -3,6 +3,7 @@
 
 namespace App\Models;
 
+use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 use Illuminate\Notifications\Notifiable;
@@ -18,9 +19,21 @@ class Rebate extends Authenticatable
 
     protected $table = 'rebates';
     // protected $hidden = ['created_at', 'updated_at'];
-    protected $fillable = ['date', 'member_id', 'betting_amount', 'rebate_ratio', 'amount', 'status', 'first_name', 'username','audited_by'];
+    protected $fillable = ['date', 'member_id', 'betting_amount', 'rebate_ratio',
+        'amount', 'status', 'first_name', 'username', 'audited_by',
+        'profit', 'huishui_percentage', 'huishui_restriction'
+    ];
 
 
+    static function updateProfit($data): void
+    {
+        $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
+        $rebate = static::where('date', $data['date'])
+            ->where('member_id', $data['member_id'])->first();
+        $rebate->increment('profit', $data['profit']);
+
+    }
+
     static function addOrUpdate($data)
     {
         $rebate = static::where('date', $data['date'])

+ 106 - 86
app/Services/BetService.php

@@ -226,8 +226,8 @@ class BetService extends BaseService
             return $msg;
         }
 
-        $now_date = date('Y-m-d H:i:s',time() + 30); // 提前30秒
-        if($issueInfo['end_time'] < $now_date){
+        $now_date = date('Y-m-d H:i:s', time() + 30); // 提前30秒
+        if ($issueInfo['end_time'] < $now_date) {
             $text = "封盘中,本次下注无效!\n";
 
             $msg['text'] = $text;
@@ -301,6 +301,8 @@ class BetService extends BaseService
 
         $now = Carbon::now('America/New_York')->format('Y-m-d');
         $rebate = Config::where('field', 'rebate')->first()->val;
+        $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
+        $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
         Rebate::addOrUpdate([
             'date' => $now,
             'member_id' => $memberId,
@@ -308,6 +310,8 @@ class BetService extends BaseService
             'rebate_ratio' => $rebate,
             'first_name' => $userInfo->first_name,
             'username' => $userInfo->username,
+            'huishui_restriction' => $huishui_restriction,
+            'huishui_percentage' => $huishui_percentage,
         ]);
         // // 返利
         // $rebate = Config::where('field', 'rebate')->first()->val;
@@ -357,10 +361,10 @@ class BetService extends BaseService
     // 模拟下注
     public static function fakeBet()
     {
-        $noRule = ['0操','27操'];
+        $noRule = ['0操', '27操'];
         // 防止一开就虚拟投注
         $cache = Cache::get('new_issue_no');
-        if($cache){
+        if ($cache) {
             return;
         }
         $betFake = Config::where('field', 'bet_fake')->first()->val;
@@ -370,29 +374,29 @@ class BetService extends BaseService
             if ($issueInfo) {
                 $betFakeRandAmount = Config::where('field', 'bet_fake_rand_amount')->first()->val;
                 $betFakeRandAmount = explode(',', $betFakeRandAmount);
-                $betMini = $betFakeRandAmount[0]??10;
-                $betMax = $betFakeRandAmount[1]??10000;
+                $betMini = $betFakeRandAmount[0] ?? 10;
+                $betMax = $betFakeRandAmount[1] ?? 10000;
 
-                $now_date = date('Y-m-d H:i:s',time() + 45); // 提前45秒
-                if($issueInfo['end_time'] > $now_date){
+                $now_date = date('Y-m-d H:i:s', time() + 45); // 提前45秒
+                if ($issueInfo['end_time'] > $now_date) {
                     $fake_bet_list = Cache::get('fake_bet_' . $issueInfo->issue_no, []);
 
                     $gameplayRuleList = GameplayRuleService::model()::where('odds', '>', 0)->get();
                     $gameplayRuleList = $gameplayRuleList->toArray();
                     $member_id = self::generateRandomNumber(10);
-                    $betTimes = rand(1,4); // 每次下注次数
+                    $betTimes = rand(1, 4); // 每次下注次数
                     for ($i = 0; $i < $betTimes; $i++) {
                         $randKey = array_rand($gameplayRuleList, 1);
                         $gameplayRuleInfo = $gameplayRuleList[$randKey] ?? [];
                         if ($gameplayRuleInfo) {
-                            if(in_array($gameplayRuleInfo['keywords'], $noRule)){
+                            if (in_array($gameplayRuleInfo['keywords'], $noRule)) {
                                 return;
 
                             }
-                            if($gameplayRuleInfo['maxinum'] < $betMax){
+                            if ($gameplayRuleInfo['maxinum'] < $betMax) {
                                 $betMax = $gameplayRuleInfo['maxinum'];
                             }
-                            if($gameplayRuleInfo['mininum'] > $betMini){
+                            if ($gameplayRuleInfo['mininum'] > $betMini) {
                                 $betMini = $gameplayRuleInfo['mininum'];
                             }
 
@@ -431,7 +435,6 @@ class BetService extends BaseService
                     }
                     Cache::put('fake_bet_' . $issueInfo->issue_no, $fake_bet_list, 500);
                 }
-                
 
 
             }
@@ -465,16 +468,16 @@ class BetService extends BaseService
             // $text .= "----------\n";
             $list = self::findAll(['member_id' => $memberId, 'issue_no' => $issue_no]);
             $list = $list->toArray();
-            if(empty($list)){
+            if (empty($list)) {
                 $text .= "本期暂未下注! \n";
-            }else{
-                $keywords = implode(',',array_column($list, 'keywords'));
-                $amounts = implode(',',array_column($list, 'amount'));
+            } else {
+                $keywords = implode(',', array_column($list, 'keywords'));
+                $amounts = implode(',', array_column($list, 'amount'));
 
 
-                $text .= "下注类型:[".$keywords."] \n";
-                $text .= "下注金额:".$amounts." \n";
-                $text .= "下注总额:".array_sum(array_column($list, 'amount'))." \n";
+                $text .= "下注类型:[" . $keywords . "] \n";
+                $text .= "下注金额:" . $amounts . " \n";
+                $text .= "下注总额:" . array_sum(array_column($list, 'amount')) . " \n";
                 $text .= "开奖状态:等待开奖 \n";
             }
             // foreach ($list->toArray() as $k => $v) {
@@ -525,7 +528,7 @@ class BetService extends BaseService
     public static function record($memberId, $messageId = null, $page = 1, $limit = 5)
     {
         $type = Cache::get('message_id_bet_record_' . $memberId, 0);
-        if($type == 0){
+        if ($type == 0) {
             $type = '';
         }
 
@@ -619,9 +622,10 @@ class BetService extends BaseService
             $item = [];
             $item['id'] = $v['id'];
             $item['status'] = self::model()::STATUS_SETTLED;
-            
+
 
             if (in_array($v['keywords'], $awards)) {
+
                 // $profit = $v['amount'] * $v['odds'];
                 $amount = $v['amount'];
                 // $amount = rtrim($amount, '0');   // 去掉右侧的 0
@@ -631,6 +635,14 @@ class BetService extends BaseService
                 if ($profit > 880000) {
                     $profit = 880000; // 单注最高奖金880000
                 }
+
+                if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
+                    Rebate::updateProfit([
+                        'member_id' => $v['member_id'],
+                        'profit' => $profit,
+                    ]);
+                }
+
                 $item['profit'] = $profit;
 
                 // $yl = $profit - $amount;
@@ -643,7 +655,7 @@ class BetService extends BaseService
                     'yl' => $yl,
                 ];
                 // if ($k + 1 <= $realNoticeNum) {
-                    
+
                 //     // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$profit} {$yl}\n";
                 //     $bet_num++;
                 // }
@@ -655,7 +667,7 @@ class BetService extends BaseService
 
                 BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
 
-                if(isset($openList[$v['member_id']])){
+                if (isset($openList[$v['member_id']])) {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] += $v['amount'];
                     $openList[$v['member_id']]['profit'] += $profit;
@@ -664,7 +676,7 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
                     $openList[$v['member_id']]['win_amount'] += $v['amount'];
 
-                }else{
+                } else {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] = $v['amount'];
                     $openList[$v['member_id']]['profit'] = $profit;
@@ -675,16 +687,25 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
                     $openList[$v['member_id']]['win_amount'] = $v['amount'];
                     $openList[$v['member_id']]['is_send'] = true;
-                    
+
                 }
             } else {
 
-                if(isset($openList[$v['member_id']])){
+
+                if (!in_array('13操', $awards) && !in_array('14操', $awards)) {
+                    Rebate::updateProfit([
+                        'member_id' => $v['member_id'],
+                        'profit' => ($v['amount'] * -1),
+                    ]);
+                }
+
+
+                if (isset($openList[$v['member_id']])) {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] += $v['amount'];
                     $openList[$v['member_id']]['lastStr'] = $lastStr;
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
-                }else{
+                } else {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] = $v['amount'];
                     $openList[$v['member_id']]['profit'] = 0;
@@ -763,12 +784,12 @@ class BetService extends BaseService
         $fakeOpenList = self::fakeLotteryDraw($issue_no, $awards, $rand_num);
 
         $openList = array_merge($openList, $fakeOpenList);
- 
+
         // 群通知
         // self::bettingGroupNotice($text, $inlineButton, '');
         // SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
 
-        self::lotteryNotice($openList,$issue_no);
+        self::lotteryNotice($openList, $issue_no);
     }
 
     /**
@@ -802,7 +823,7 @@ class BetService extends BaseService
             $item = [];
             $item['id'] = $v['id'];
             $item['status'] = self::model()::STATUS_SETTLED;
-            
+
 
             if (in_array($v['keywords'], $awards)) {
                 // $profit = $v['amount'] * $v['odds'];
@@ -819,7 +840,7 @@ class BetService extends BaseService
                 // $yl = $profit - $amount;
                 $yl = bcsub($profit, $amount, 2); // 盈利
                 // if ($k + 1 <= $realNoticeNum) {
-                    
+
                 //     // $text .= "会员下注 【" . $lastStr . "】{$v['amount']} {$profit} {$yl}\n";
                 //     $bet_num++;
                 // }
@@ -831,7 +852,7 @@ class BetService extends BaseService
 
                 // BalanceLogService::addLog($v['member_id'], $profit, $balance, ($balance + $profit), '中奖', $v['id'], '');
 
-                if(isset($openList[$v['member_id']])){
+                if (isset($openList[$v['member_id']])) {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] += $v['amount'];
                     $openList[$v['member_id']]['profit'] += $profit;
@@ -840,7 +861,7 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
                     $openList[$v['member_id']]['win_amount'] += $v['amount'];
 
-                }else{
+                } else {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] = $v['amount'];
                     $openList[$v['member_id']]['profit'] = $profit;
@@ -851,16 +872,16 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
                     $openList[$v['member_id']]['win_amount'] = $v['amount'];
                     $openList[$v['member_id']]['is_send'] = true;
-                    
+
                 }
             } else {
 
-                if(isset($openList[$v['member_id']])){
+                if (isset($openList[$v['member_id']])) {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] += $v['amount'];
                     $openList[$v['member_id']]['lastStr'] = $lastStr;
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
-                }else{
+                } else {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] = $v['amount'];
                     $openList[$v['member_id']]['profit'] = 0;
@@ -916,7 +937,7 @@ class BetService extends BaseService
         //     // }else{
         //     //     $text .= "会员下注 【" . $v['lastStr'] . "】 {$amount} 0 -{$amount}\n";
         //     // }
-            
+
 
         // }
 
@@ -929,7 +950,7 @@ class BetService extends BaseService
         // 群通知
         // self::bettingGroupNotice($text, $inlineButton, '');
         // SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
-        self::lotteryNotice($openList,$issue_no);
+        self::lotteryNotice($openList, $issue_no);
     }
 
 
@@ -956,7 +977,7 @@ class BetService extends BaseService
                 $item['profit'] = $profit;
                 // $v['amount'] = number_format($amount,2);
 
-                if(isset($openList[$v['member_id']])){
+                if (isset($openList[$v['member_id']])) {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] += $v['amount'];
                     $openList[$v['member_id']]['profit'] += $profit;
@@ -965,7 +986,7 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
                     $openList[$v['member_id']]['win_amount'] += $v['amount'];
 
-                }else{
+                } else {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] = $v['amount'];
                     $openList[$v['member_id']]['profit'] = $profit;
@@ -976,16 +997,16 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
                     $openList[$v['member_id']]['win_amount'] = $v['amount'];
                     $openList[$v['member_id']]['is_send'] = false;
-                    
+
                 }
             } else {
 
-                if(isset($openList[$v['member_id']])){
+                if (isset($openList[$v['member_id']])) {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] += $v['amount'];
                     $openList[$v['member_id']]['lastStr'] = $lastStr;
                     $openList[$v['member_id']]['keywords'][] = $v['keywords'];
-                }else{
+                } else {
                     $openList[$v['member_id']]['member_id'] = $v['member_id'];
                     $openList[$v['member_id']]['amount'] = $v['amount'];
                     $openList[$v['member_id']]['profit'] = 0;
@@ -996,7 +1017,7 @@ class BetService extends BaseService
                     $openList[$v['member_id']]['win_amount'] = 0;
                     $openList[$v['member_id']]['is_send'] = false;
                 }
-               
+
             }
 
         }
@@ -1005,7 +1026,7 @@ class BetService extends BaseService
     }
 
     // 开奖通知
-    public static function lotteryNotice($openList,$issue_no)
+    public static function lotteryNotice($openList, $issue_no)
     {
         $betNoticeNum = Config::where('field', 'bet_notice_num')->first()->val;
         $betNoticeNum = explode(',', $betNoticeNum);
@@ -1016,58 +1037,57 @@ class BetService extends BaseService
 
         $text = $issue_no . "期开奖结果 \n";
         $text .= "-----本期开奖账单----- \n";
-        foreach($openList as $k => $v){
-            $amount = number_format($v['amount'],2);
-            $v['win_amount'] = number_format($v['win_amount'],2);
-                $profit = number_format($v['profit'],2);
-                $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
-                if(empty($v['openKeywords'])){
-                    $openKeyword = '-';
-
-                }else{
-                    $openKeyword = implode(',', $v['openKeywords']);
-                }
+        foreach ($openList as $k => $v) {
+            $amount = number_format($v['amount'], 2);
+            $v['win_amount'] = number_format($v['win_amount'], 2);
+            $profit = number_format($v['profit'], 2);
+            $yl = bcsub($v['profit'], $v['amount'], 2); // 盈利
+            if (empty($v['openKeywords'])) {
+                $openKeyword = '-';
 
-                if(($k+1) <= $noticeNum){
-                    $text .= "用户ID:{$v['lastStr']} \n";
-                    $text .= "下注类型:[".implode(',', $v['keywords'])."] \n";
-                    $text .= "中奖类型:[".$openKeyword."] \n";
-                    $text .= "投注金额:{$amount} \n";
-                    $text .= "中奖金额:{$v['win_amount']} \n";
-                    $text .= "派彩金额:{$profit} \n";
-                    $text .= "盈亏金额:{$yl} \n";
-                    $text .= "-------------------------------- \n";
-                }
+            } else {
+                $openKeyword = implode(',', $v['openKeywords']);
+            }
 
-                if($v['is_send']){
-                    $text2 = "{$issue_no}期开奖结果 \n";
-                    $text2 .= "下注类型:[".implode(',', $v['keywords'])."] \n";
-                    $text2 .= "中奖类型:[".$openKeyword."] \n";
-                    $text2 .= "投注金额:{$amount} \n";
-                    $text2 .= "中奖金额:{$v['win_amount']} \n";
-                    $text2 .= "派彩金额:{$profit} \n";
-                    $text2 .= "盈亏金额:{$yl} \n";
-                    $keyboard = [];
-                    $keyboard[] = [
-                        ['text' => "开奖历史", 'callback_data' => "showLotteryHistory@@" . $issue_no]
-                    ];
-                    // self::sendMessage($v['member_id'],$text2,$keyboard);
-                    SendTelegramMessageJob::dispatch($v['member_id'],$text2,$keyboard);
-                }
+            if (($k + 1) <= $noticeNum) {
+                $text .= "用户ID:{$v['lastStr']} \n";
+                $text .= "下注类型:[" . implode(',', $v['keywords']) . "] \n";
+                $text .= "中奖类型:[" . $openKeyword . "] \n";
+                $text .= "投注金额:{$amount} \n";
+                $text .= "中奖金额:{$v['win_amount']} \n";
+                $text .= "派彩金额:{$profit} \n";
+                $text .= "盈亏金额:{$yl} \n";
+                $text .= "-------------------------------- \n";
+            }
+
+            if ($v['is_send']) {
+                $text2 = "{$issue_no}期开奖结果 \n";
+                $text2 .= "下注类型:[" . implode(',', $v['keywords']) . "] \n";
+                $text2 .= "中奖类型:[" . $openKeyword . "] \n";
+                $text2 .= "投注金额:{$amount} \n";
+                $text2 .= "中奖金额:{$v['win_amount']} \n";
+                $text2 .= "派彩金额:{$profit} \n";
+                $text2 .= "盈亏金额:{$yl} \n";
+                $keyboard = [];
+                $keyboard[] = [
+                    ['text' => "开奖历史", 'callback_data' => "showLotteryHistory@@" . $issue_no]
+                ];
+                // self::sendMessage($v['member_id'],$text2,$keyboard);
+                SendTelegramMessageJob::dispatch($v['member_id'], $text2, $keyboard);
+            }
 
         }
 
         $inlineButton = self::getOperateButton();
 
 
-
         // 群通知
         // self::bettingGroupNotice($text, $inlineButton, '');
-        SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
-        
+        SendTelegramGroupMessageJob::dispatch($text, $inlineButton, '');
+
     }
 
-   
+
     public static function todayExchangeRate($chatId)
     {
         $exchangeRate = Config::where('field', 'exchange_rate_rmb')->first()->val;

+ 45 - 0
database/migrations/2025_11_20_145044_update_config.php

@@ -0,0 +1,45 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Support\Facades\DB;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        DB::table('config')->insert([
+            [
+                'field' => 'huishui_restriction',
+                'val' => "1000",
+                'remark' => '输钱达到限制值',
+                'group_id' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'field' => 'huishui_percentage',
+                'val' => "0.01",
+                'remark' => '输钱打到限制值,回水比例',
+                'group_id' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+        ]);
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+};

+ 33 - 0
database/migrations/2025_11_20_145643_update_rebates.php

@@ -0,0 +1,33 @@
+<?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('profit', 10, 2)->default(0)->comment('当日输赢');
+            $table->decimal('huishui_percentage', 10, 2)->default(0)->comment('回水比例');
+            $table->decimal('huishui_restriction', 10, 2)->default(0)->comment('回水限制值');
+        });
+
+//
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+    }
+};