Selaa lähdekoodia

提交足球结算和docker文件

lip 1 päivä sitten
vanhempi
commit
d214c5aa77

+ 78 - 0
app/Console/Commands/LhcLottery.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\LhcLottery as LhcLotteryModel;
+use Illuminate\Support\Facades\Log;
+
+class LhcLottery extends Command
+{
+    /**
+     * 命令名称和签名
+     *
+     * @var string
+     */
+    protected $signature = 'lhc:lottery';
+    
+    /**
+     * 命令描述
+     *
+     * @var string
+     */
+    protected $description = '六合彩开奖数据抓取,每日21:36后开始执行一次';
+
+    /**
+     * 执行命令
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $num = 0;
+        while ($num < 10) {
+            $num ++;
+            $res = $this->spider();
+            echo date('Y-m-d H:i:s').' 第'.$num.'次尝试,结果:'.$res.PHP_EOL;
+            if ($res === false) {
+                sleep(60);
+            } else {
+                break;
+            }
+        }
+    }
+
+    
+    public function spider()
+    {
+        $url = 'https://api.bjjfnet.com/data/opencode/2032';
+        try {
+            $json = file_get_contents($url);
+            $data = json_decode($json, true);
+            if (empty($data)) {
+                throw new \Exception('六合彩 Empty data');
+            }
+            if ($data['code'] != 0) {
+                throw new \Exception('六合彩 code 不为 0');
+            }
+            $lotteries = array_reverse($data['data']);
+
+            foreach ($lotteries as $lottery) {
+                $exists = LhcLotteryModel::where('issue', $lottery['issue'])->first();
+                if ($exists) {
+                    continue;
+                }
+                $mode = new  LhcLotteryModel;
+                $mode->issue = $lottery['issue'];
+                $mode->open_code = $lottery['openCode'];
+                $mode->open_time = strtotime($lottery['openTime']);
+                $mode->save();
+            }
+        } catch (\Exception $e) {
+            Log::error("六合彩开奖数据抓取失败:".$e->getMessage());
+            return false;
+        }
+        return true;
+    }
+
+}

+ 2 - 1
app/Console/Commands/SportOdds.php

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
 use Illuminate\Console\Command;
 use App\Models\Sport as SportModel;
 use App\Services\SportClientService;
+use Illuminate\Support\Facades\Log;
 
 class SportOdds extends Command
 {
@@ -99,7 +100,7 @@ class SportOdds extends Command
                 }
             }
         } catch (\Exception $e) {
-            $this->error($e->getMessage());
+            Log::error($e->getMessage());
         }
         return true;
     }

+ 481 - 0
app/Helpers/FootballSettlement.php

@@ -341,6 +341,51 @@ function BothTeamsScoreSecondHalf($amount,$detail, $params)
     return getBothTeamsScore($amount, $half_home, $half_away, $detail);
 }
 
+/**
+ * Goals Over/Under(全场大小球) 玩法
+ * -Over 1.5: 预测全场总进球数大于1.5
+ * -Under 1.5: 预测全场进球数小于1.5
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function GoalsOverUnder($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $score = $score['home'] + $score['away'];
+    return totalHomeOrAway($amount, $score, $detail);
+}
+
+/**
+ * Goals Over/Under First Half(上半场大小球) 玩法
+ * -Over 1.5: 预测上半场总进球数大于1.5
+ * -Under 1.5: 预测上半场进球数小于1.5
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function GoalsOverUnderFirstHalf($amount,$detail, $params)
+{
+    $score = getScore($params['half_score']);
+    $score = $score['home'] + $score['away'];
+    return totalHomeOrAway($amount, $score, $detail);
+}
+
+/**
+ * Goals Over/Under - Second Half(下半场大小球) 玩法
+ * -Over 1.5: 预测下半场总进球数大于1.5
+ * -Under 1.5: 预测下半场进球数小于1.5
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function GoalsOverUnderSecondHalf($amount,$detail, $params)
+{
+    $score = getHalfScore($params['score'], $params['half_score']);
+    $score = $score['home'] + $score['away'];
+    return totalHomeOrAway($amount, $score, $detail);
+}
+
 //双方均进球的处理方法
 function getBothTeamsScore($amount, $home, $away,$detail)
 {
@@ -793,6 +838,35 @@ function AwayTeamGoals($amount,$detail, $params)
     return getResult($is_win, $amount, $odd);
 }
 
+/**
+ * Over/Under Line(大小球盘口) 玩法
+ * -value: over/under
+ * -handicap: 1.5 2.5 ..
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function OverUnderLine($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $score = $score['home'] + $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $odd = $value_and_odd['odd'];
+    $value = $value_and_odd['value'];
+    $handicap = $value_and_odd['handicap'];
+    $is_win = 0;
+    if ($score > $handicap && strtolower($value) == 'over' ) {
+        $is_win = 1;
+    } elseif ($score < $handicap && strtolower($value) == 'under'  ) {
+        $is_win = 1;
+    } elseif ($score == $handicap) {
+        //不输不赢,需要退款
+        $is_win = 2;
+    }
+    return getResult($is_win, $amount, $odd);
+}
+
 /**
  * Home Team Score a Goal (2nd Half)(主队下半场进球) 玩法
  * -Yes: 主队在下半场至少打进一球
@@ -957,6 +1031,35 @@ function AwayTeamExactGoalsNumber($amount,$detail, $params)
     return getResult($is_win, $amount, $odd);
 }
 
+/**
+ * Fulltime Result(全场赛果) 玩法
+ * -Home: 主队赢球
+ * -Away: 客队赢球
+ * -Draw: 双方打平
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function FulltimeResult($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $home = $score['home'];
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($home > $away && $value == 'home') {
+        $is_win = 1;
+    } elseif ($away > $home && $value == 'away') {
+        $is_win = 1;
+    } elseif ($home == $away && $value == 'draw') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
 /**
  * Results/Both Teams Score(赛果+双方进球) 玩法
  * -Home/Yes: 主队赢球,且客队也进了球
@@ -1075,6 +1178,384 @@ function ResultBothTeamsToScore($amount,$detail, $params)
     return getResult($is_win, $amount, $odd);
 }
 
+/**
+ * Highest Scoring Half(进球更多的半场) 玩法
+ * -Draw: 两个半场的进球数完全相等
+ * -1st Half: 上半场产生的总进球数 > 下半场产生的总进球数
+ * -2nd Half: 下半场产生的总进球数 > 上半场产生的总进球数
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function HighestScoringHalf($amount,$detail, $params)
+{
+    $score = getScore($params['half_score']);
+    $first_half = $score['home'] + $score['away'];
+
+    $score = getHalfScore($params['score'], $params['half_score']);
+    $second_half = $score['home'] + $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($first_half > $second_half && $value == '1st Half') {
+        $is_win = 1;
+    } elseif ($first_half < $second_half && $value == '2nd Half') {
+        $is_win = 1;
+    } elseif ($first_half == $second_half && $value == 'draw') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Final Score(最终比分) 玩法
+ * -value: 1-2
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function FinalScore($amount,$detail, $params)
+{
+    $score = $params['score'];
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($score == $value ) {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Exact Score(精确比分) 玩法
+ * -value: 1:2
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function ExactScore($amount,$detail, $params)
+{
+    $score = $params['score'];
+    $value_and_odd = getValueAndOdd($detail);
+    $value = str_replace(":", "-", $value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($score == $value ) {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Correct Score - First Half(上半场精确比分) 玩法
+ * -value: 1:2
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function CorrectScoreFirstHalf($amount,$detail, $params)
+{
+    $half_score = $params['half_score'];
+    $value_and_odd = getValueAndOdd($detail);
+    $value = str_replace(":", "-", $value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($half_score == $value ) {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Correct Score - Second Half(下半场精确比分) 玩法
+ * -value: 1:2
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function CorrectScoreSecondHalf($amount,$detail, $params)
+{
+    $half_score = getHalfScore($params['score'], $params['half_score']);
+    $half_score = $half_score['home'] . '-' . $half_score['away'];
+
+    $value_and_odd = getValueAndOdd($detail);
+    $value = str_replace(":", "-", $value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($half_score == $value ) {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * To Win Either Half(赢得任意半场) 玩法
+ * -Home: 主队在上/下半场的进球数 > 客队在上/下半场的进球数
+ * -Away: 客队在上/下半场的进球数 > 主队在上/下半场的进球数
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function ToWinEitherHalf($amount,$detail, $params)
+{
+    //上半场
+    $score = getScore($params['half_score']);
+    $home_first = $score['home'];
+    $away_first = $score['away'];
+
+    //下半场
+    $score = getHalfScore($params['score'], $params['half_score']);
+    $home_half = $score['home'];
+    $away_half = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if (($home_first > $away_first || $home_half > $away_half) && $value == 'home') {
+        $is_win = 1;
+    } if (($home_first < $away_first || $home_half < $away_half) && $value == 'away') {
+        $is_win = 1;
+    }
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * To Win 2nd Half(赢下半场) 玩法
+ * -Home: 主队在下半场的进球数 > 客队在下半场的进球数
+ * -Draw: 双方在下半场的进球数相等
+ * -Away: 客队在下半场的进球数 > 主队在下半场的进球数
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function ToWin2ndHalf($amount,$detail, $params)
+{
+    $score = getHalfScore($params['score'], $params['half_score']);
+    $home_half = $score['home'];
+    $away_half = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($home_half > $away_half && $value == 'home') {
+        $is_win = 1;
+    } elseif ($home_half == $away_half && $value == 'draw') {
+        $is_win = 1;
+    } elseif ($away_half > $home_half && $value == 'away') {
+        $is_win = 1;
+    }
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Win To Nil(零封获胜) 玩法
+ * -Home: 主队赢球,客队为0
+ * -Away: 客队赢球,主队为0
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function WinToNil($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $home = $score['home'];
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($home > 0 && $away == 0 && $value == 'home') {
+        $is_win = 1;
+    } elseif ($away > 0 && $home == 0 && $value == 'away') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Home Team Clean Sheet(主队零封) 玩法
+ * -Yes: 客队一个球都进不了
+ * -No:  客队至少打进 1 个球
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function HomeTeamCleanSheet($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($away == 0 && $value == 'yes') {
+        $is_win = 1;
+    } elseif ($away > 0 && $value == 'no') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * HT/FT Double(半场+全场双猜) 玩法
+ * -Home/Draw: 上半场主队领先,全场被追平。
+ * -Home/Away: 上半场主队领先,全场客队领先。
+ * -Home/Home: 上半场主队领先,全场主队领先。
+ * -Away/Draw:  上半场客队领先,全场被追平。
+ * -Away/Home:  上半场客队领先,全场主队领先。
+ * -Away/Away:  上半场客队领先,全场客队领先。
+ * -Draw/Home:  上半场平局,全场主队领先。
+ * -Draw/Away:  上半场平局,全场客队领先。
+ * -Draw/Draw:  上半场平局,全场平局。
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function HTFTDouble($amount,$detail, $params)
+{
+    $score = getScore($params['half_score']);
+    $first_home = $score['home'];
+    $first_away = $score['away'];
+    $score = getScore($params['score']);
+    $home = $score['home'];
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($first_home > $first_away && $home == $away && $value == 'home/draw') {
+        $is_win = 1;
+    } elseif ($first_home > $first_away && $home < $away && $value == 'home/away') {
+        $is_win = 1;
+    } elseif ($first_home > $first_away && $home > $away && $value == 'home/home') {
+        $is_win = 1;
+    } elseif ($first_home < $first_away && $home == $away && $value == 'away/draw') {
+        $is_win = 1;
+    } elseif ($first_home < $first_away && $home < $away && $value == 'away/away') {
+        $is_win = 1;
+    } elseif ($first_home < $first_away && $home > $away && $value == 'away/home') {
+        $is_win = 1;
+    } elseif ($first_home == $first_away && $home == $away && $value == 'draw/draw') {
+        $is_win = 1;
+    } elseif ($first_home == $first_away && $home < $away && $value == 'draw/away') {
+        $is_win = 1;
+    } elseif ($first_home == $first_away && $home > $away && $value == 'draw/home') {
+        $is_win = 1;
+    }
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Clean Sheet - Home(主队零封) 玩法
+ * -Yes: 客队一个球都进不了
+ * -No:  客队至少打进 1 个球
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function CleanSheetHome($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($away == 0 && $value == 'yes') {
+        $is_win = 1;
+    } elseif ($away > 0 && $value == 'no') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Clean Sheet - Away(客队零封) 玩法
+ * -Yes: 主队一个球都进不了
+ * -No:  主队至少打进 1 个球
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function CleanSheetAway($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $home = $score['home'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($home == 0 && $value == 'yes') {
+        $is_win = 1;
+    } elseif ($home > 0 && $value == 'no') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Win to Nil - Home(主队零封获胜) 玩法
+ * -Yes: 主队必须赢,客队全场一个球都没进
+ * -No:  客队进球了,或比赛打平,或客队赢了
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function WinToNilHome($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $home = $score['home'];
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($home > $away && $away == 0 && $value == 'yes') {
+        $is_win = 1;
+    } elseif (($away > 0 || $away >= $home) && $value == 'no') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+/**
+ * Win to Nil - Away(客队零封获胜) 玩法
+ * -Yes: 客队必须赢,主队全场进球数为 0
+ * -No:  主队进球了,或比赛打平,或主队赢了
+ * $amount:下注金额
+ * $score:主队-客对   
+ * $detail:下注时的详情
+ */
+function WinToNilAway($amount,$detail, $params)
+{
+    $score = getScore($params['score']);
+    $home = $score['home'];
+    $away = $score['away'];
+    
+    $value_and_odd = getValueAndOdd($detail);
+    $value = strtolower($value_and_odd['value']);
+    $odd = $value_and_odd['odd'];
+    $is_win = 0;
+    if ($away > $home && $home == 0 && $value == 'yes') {
+        $is_win = 1;
+    } elseif (($home > 0 || $home >= $away) && $value == 'no') {
+        $is_win = 1;
+    } 
+    return getResult($is_win, $amount, $odd);
+}
+
+
 /**
  * 获取主客队得分
  */

+ 9 - 0
app/Models/LhcLottery.php

@@ -0,0 +1,9 @@
+<?php
+namespace App\Models;
+
+class LhcLottery extends BaseModel
+{
+    protected $table = 'lhc_lottery';
+    protected $fillable = ['issue', 'open_code','open_time'];
+
+}