lip 1 nedēļu atpakaļ
vecāks
revīzija
5bf4846e45

+ 44 - 1
app/Console/Commands/Sport.php

@@ -4,6 +4,8 @@ namespace App\Console\Commands;
 
 use Illuminate\Console\Command;
 use App\Models\Sport as SportModel;
+use App\Services\SportClientService;
+use Carbon\Carbon;
 
 class Sport extends Command
 {
@@ -29,7 +31,7 @@ class Sport extends Command
     {
         $this->info('开始执行统计比赛数据任务...');
 
-        $this->sportData();
+        $this->fixtures();
         
         $this->info('结束执行统计比赛数据任务');
     }
@@ -96,4 +98,45 @@ class Sport extends Command
         return true;
     }
 
+    /**
+     * 获取指定日期的所有赛事
+     *
+     * @return array
+     */
+    public function fixtures()
+    {
+        $date = Carbon::tomorrow()->toDateString();
+        $data = SportClientService::fixtures(['date' => $date]);
+        print_r($data);die;
+        $data = $data['response'];
+        $tableData = [];
+        $status = ['NS' => 0, '1H' => 1, 'HT' => 1, '2H' => 1, 'ET' => 1, 'BT' => 1, 'P' => 1, 'SUSP' => 1, 'INT' => 1, 'LIVE' => 1, 'FT' => 2, 'AET' => 2, 'PEN' => 2, 'PST' => 3, 'CANC' => 4, 'ABD' => 4,];
+        foreach ($data as $item) {
+            if (!Sport::where('data_id', $item['fixture']['id'])->exists()) {
+                $tableData[] = [
+                    'data_id' => $item['fixture']['id'],
+                    'home_team_id' => $item['teams']['home']['id'],
+                    'home_team_en' => $item['teams']['home']['name'],
+                    'home_team' => lang($item['teams']['home']['name']),
+                    'home_team_logo' => $item['teams']['home']['logo'],
+                    'guest_team_id' => $item['teams']['away']['id'],
+                    'guest_team_en' => $item['teams']['away']['name'],
+                    'guest_team' => lang($item['teams']['away']['name']),
+                    'guest_team_logo' => $item['teams']['away']['logo'],
+                    'half_score' => "{$item['score']['halftime']['home']}-{$item['score']['halftime']['away']}",
+                    'rbt' => $item['fixture']['timestamp'],
+                    'score' => "{$item['goals']['home']}-{$item['goals']['away']}",
+                    'league' => lang($item['league']['name']),
+                    'league_en' => $item['league']['name'],
+                    'state' => $status[$item['fixture']['status']['short']],//比赛状态:0未开始1进行中2已完场3延期4取消
+                    'game_time' => $item['fixture']['timestamp'],
+                    'created_at' => now(),
+                    'updated_at' => now(),
+                ];
+            }
+        }
+        Sport::insert($tableData);
+        return $tableData;
+    }
+
 }

+ 4 - 4
app/Http/Controllers/admin/Operation.php

@@ -29,7 +29,7 @@ class Operation extends Controller
             $limit = request()->input('limit', 15);
             $query = User::query();
             if (isset($params['user_id'])) {
-                $user_id = $params['user_id'];
+                $user_id = $params['user_id'] ?? null;
                 $query->where(function ($query1) use ($user_id) {
                     $query1->where('member_id', $user_id)
                     ->orWhere('first_name', 'like', "%{$user_id}%");
@@ -37,10 +37,10 @@ class Operation extends Controller
             }
 
             $count = $query->count();
-            $list = $query->join('wallets', 'users.id', '=', 'wallets.user_id')
-                ->select(['users.id', 'users.member_id', 'users.first_name', 'wallets.available_balance as money'])
+            $list = $query->join('wallets', 'users.user_id', '=', 'wallets.user_id')
+                ->select(['users.id', 'users.user_id','users.member_id', 'users.first_name', 'wallets.available_balance as money'])
                 ->forPage($page, $limit)
-                ->orderByDesc("created_at")
+                ->orderByDesc("users.created_at")
                 ->get()->toArray();
             
             $start = !empty($params['start_time']) ? "{$params['start_time']} 00:00:00" : null;

+ 118 - 0
app/Http/Controllers/api/PcIssue.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace App\Http\Controllers\api;
+
+use App\Models\Config;
+use Carbon\Carbon;
+use Illuminate\Http\JsonResponse;
+use App\Http\Controllers\api\Issue;
+use App\Http\Controllers\api\NewPc;
+
+/**
+ * pc28,根据配置的游戏玩法返回指定的数据
+ */
+class PcIssue extends BaseController
+{
+
+    /**
+     * @api {get} /pcissue/yuanTou 源头
+     *
+     */
+    function yuanTou()
+    {
+        $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
+        if ($pc28Switch == 1) {
+            //pc28分分彩/极速28
+            $issueController = new NewPc();
+        } else {
+            //pc28
+            $issueController = new Issue();
+        }
+        return $issueController->yuanTou();
+    }
+
+
+    /**
+     * @api {get} /pcissue/history 天机
+     *
+     */
+    function history()
+    {
+        $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
+        if ($pc28Switch == 1) {
+            //pc28分分彩/极速28
+            $issueController = new NewPc();
+        } else {
+            //pc28
+            $issueController = new Issue();
+        }  $issueController = new NewPc();
+        return $issueController->history();
+    }
+
+    /**
+     * @api {get} /pcissue/prediction 预测
+     */
+    function prediction()
+    {
+        $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
+        if ($pc28Switch == 1) {
+            //pc28分分彩/极速28
+            $issueController = new NewPc();
+        } else {
+            //pc28
+            $issueController = new Issue();
+        }
+        return $issueController->prediction();
+    }
+
+    /**
+     * @api {get} /pcissue/countdown 倒计时
+     *
+     */
+    public function countdown(): JsonResponse
+    {
+        $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
+        if ($pc28Switch == 1) {
+            //pc28分分彩/极速28
+            $issueController = new NewPc();
+        } else {
+            //pc28
+            $issueController = new Issue();
+        }
+        return $issueController->countdown();
+    }
+
+
+    /**
+     * @api {get} /pcissue 结果,走势
+     */
+    public function index()
+    {
+        $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
+        if ($pc28Switch == 1) {
+            //pc28分分彩/极速28
+            $issueController = new NewPc();
+        } else {
+            //pc28
+            $issueController = new Issue();
+        }
+        return $issueController->index();
+    }
+
+    /**
+     * @api {get} /pcissue/cao 统计,历史
+     */
+    public function cao()
+    {
+        $pc28Switch = Config::where('field', 'pc28_switch')->first()->val;
+        if ($pc28Switch == 1) {
+            //pc28分分彩/极速28
+            $issueController = new NewPc();
+        } else {
+            //pc28
+            $issueController = new Issue();
+        }
+        return $issueController->cao();
+    }
+
+}

+ 92 - 0
app/Services/SportClientService.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace App\Services;
+
+use Illuminate\Support\Facades\Http;
+
+
+class SportClientService
+{
+
+    //
+    public static function get($endpoint, $params = [])
+    {
+        $response = Http::withHeaders([
+            'x-apisports-key' => env('API_FOOTBALL_KEY'),
+        ])
+            ->withoutVerifying()  // 临时跳过 SSL 验证
+            ->get(env('API_FOOTBALL_HOST') . '/' . $endpoint, $params);
+
+        if ($response->successful()) {
+            return $response->json();
+        }
+
+        // Handle errors as needed
+        throw new \Exception("API request failed: " . $response->body());
+    }
+
+    public static function post($endpoint, $data = [])
+    {
+        $response = Http::withHeaders([
+            'x-apisports-key' => config('services.api_football.key'),
+        ])->post(config('services.api_football.host') . '/' . $endpoint, $data);
+
+        if ($response->successful()) {
+            return $response->json();
+        }
+
+        // Handle errors as needed
+        throw new \Exception("API request failed: " . $response->body());
+    }
+
+    // 时区
+    public static function timezone()
+    {
+        return self::get('timezone');
+    }
+
+    // 国家/地区
+    public static function countries($params = [])
+    {
+        return self::get('countries', $params);
+    }
+
+    //  联赛  获取可用的联赛和杯赛名单。
+    public static function leagues($params = [])
+    {
+        return static::get('leagues', $params);
+    }
+
+    // 联赛赛季  获取特定联赛的赛季列表。
+    public static function leaguesSeasons($params = [])
+    {
+        return static::get('leagues/seasons', $params);
+    }
+
+
+    //  This endpoint returns in-play odds for fixtures in progress.
+    //  此端点会返回正在进行的比赛的实时赔率。
+    //  Update Frequency : This endpoint is updated every 5 seconds.
+    //  更新频率:此端点每 5 秒钟更新一次。
+    public static function oddsLive($params = [])
+    {
+        return static::get('odds/live', $params);
+    }
+
+    public static function odds($params = [])
+    {
+        return static::get('odds', $params);
+    }
+
+    public static function fixturesRounds($params = [])
+    {
+        return static::get('fixtures/rounds', $params);
+    }
+
+
+    // 赛程
+    public static function fixtures($params = [])
+    {
+        return self::get('fixtures', $params);
+    }
+}

+ 5 - 0
example.env

@@ -31,6 +31,11 @@ TREE_PAYMENT_SECRET=
 TREE_PAY_MCH_ID=
 TREE_PAY_MCH_KEY=
 
+
+# 足球数据API平台的秘钥和地址
+API_FOOTBALL_KEY=2c8e29029466779da5b820ce6d8b76e3  
+API_FOOTBALL_HOST=https://v3.football.api-sports.io
+
 # 数据库
 DB_CONNECTION=mysql
 DB_HOST=127.0.0.1

+ 11 - 0
routes/api.php

@@ -9,6 +9,7 @@ use App\Http\Controllers\api\Home;
 use App\Http\Controllers\api\Issue;
 use App\Http\Controllers\api\Pay;
 use App\Http\Controllers\api\NewPc;
+use App\Http\Controllers\api\PcIssue;
 
 Route::post("/onMessage", [TelegramWebHook::class, 'handle']);
 Route::get("/setWebHook", [Home::class, 'setWebHook']);
@@ -49,6 +50,16 @@ Route::prefix('/issue')->group(function () {
 
 });
 
+//足球app请求的接口,根据游戏模式返回不同的数据
+Route::prefix('/pcissue')->group(function () {
+    Route::get("/", [PcIssue::class, 'index']);
+    Route::get("/cao", [PcIssue::class, 'cao']);
+    Route::get("/countdown", [PcIssue::class, 'countdown']);
+    Route::get("/prediction", [PcIssue::class, 'prediction']);
+    Route::get("/history", [PcIssue::class, 'history']);
+    Route::get("/yuanTou", [PcIssue::class, 'yuanTou']);
+});
+
 
 Route::get('/test', [Home::class, 'test']);
 Route::prefix('/pay')->group(function () {