lip 3 gün önce
ebeveyn
işleme
96aababc75

+ 97 - 0
app/Console/Commands/Leagues.php

@@ -0,0 +1,97 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\Sport as SportModel;
+use App\Services\SportClientService;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
+use App\Models\SportEvent;
+use App\Models\Config;
+
+class Sport extends Command
+{
+    /**
+     * 命令名称和签名
+     *
+     * @var string
+     */
+    protected $signature = 'sport {is_live=0}';
+    protected $is_live = 0;
+
+    protected  $short_status = [
+            'TBD' => 0,
+            'NS' => 0,
+            '1H' => 1,
+            'HT' => 1,
+            '2H' => 1,
+            'ET' => 1,
+            'BT' => 1,
+            'P' => 1,
+            'SUSP' => 1,
+            'INT' => 1,
+            'FT' => 2,
+            'AET' => 2,
+            'PEN' => 2,
+            'PST' => 3,
+            'CANC' => 4,
+            'ABD' => 4,
+            'AWD' => 4,
+            'WO' => 4,
+            'LIVE' => 1,
+        ];
+    protected $long_status = [
+        'Time To Be Defined' => 0,
+        'Not Started' => 0,
+        'First Half' => 1,
+        'First Half, Kick Off' => 1,
+        'Halftime' => 1,
+        'Second Half' => 1,
+        'Second Half, 2nd Half Started' => 1,
+        'Extra Time' => 1,
+        'Break Time' => 1,
+        'Penalty In Progress' => 1,
+        'Match Suspended' => 1,
+        'Match Interrupted' => 1,
+        'Match Finished' => 2,
+        'Match Finished' => 2,
+        'Match Finished' => 2,
+        'Match Postponed' => 3,
+        'Match Cancelled' => 4,
+        'Match Abandoned' => 4,
+        'Technical Loss' => 4,
+        'WalkOver' => 4,
+        'In Progress' => 1,
+    ];        
+    
+    protected $fixture_status = [
+        'First Half' => 1,
+        'First Half, Kick Off' => 1,
+        'Halftime' => 1,
+        'Second Half' => 1,
+        'Second Half, 2nd Half Started' => 1,
+        'Extra Time' => 1,
+        'Break Time' => 1,
+        'Penalty In Progress' => 1,
+    ];     
+   
+
+    /**
+     * 命令描述
+     *
+     * @var string
+     */
+    protected $description = '当天会去更新明天的赛事(23:59:00执行一次)';
+    /**
+     * 执行命令
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $data = SportClientService::leagues(['season' => date('Y')]);
+        file_put_contents("leagues.json", json_encode($data));
+    }
+
+}

+ 24 - 10
app/Console/Commands/Sport.php

@@ -100,19 +100,31 @@ class Sport extends Command
             $this->fixtures();
         } elseif ($this->is_live == 2){
             // $data = SportClientService::fixtures([
-            //     'id' => 1534923,
+            //     'id' => 1506065,
             // ]);
-            // $data = SportClientService::fixtures(['live' => 'all']);
-            // // $data = SportClientService::oddsLive();
-            // file_put_contents("1534923.json", json_encode($data));
+            // file_put_contents("1506065.json", json_encode($data));
             // print_r($data);
             // die;
             
             $this->checkLiveFixtures();
+            //$this->updateOvertimeFixtures();
         } elseif ($this->is_live == 3) {
             $this->checkOvertimeFixtures();
+        } else {
+            $this->initOdds();
         }
     }
+    
+    //比赛开始后,超过3个小时,并且更新时间超过10分钟,还是进行中的数据,更新成已完成
+    public function updateOvertimeFixtures()
+    { 
+        // 比赛开始后,状态还是未开始的数据检测
+        $end_time = date("Y-m-d H:i:s", time() - 600);
+        SportModel::where('status', 1)->where('state', 1)->where('game_time', '<=', time() - 60*60*3)->where('updated_at', '<=', $end_time)->update(['state' =>2]);
+        // $ids = SportModel::where('status', 1)->where('state', 1)->where('game_time', '<=', time() - 60*60*3)->pluck('data_id')->get();
+        // print_r($ids);
+        return true;
+    }
 
     //到了比赛开始时间,但是状态还是未开始,检查比赛
     public function checkOvertimeFixtures()
@@ -137,15 +149,18 @@ class Sport extends Command
         $sport_locked = Config::where('field', 'sport_locked')->first()->val ?? 1;
 
         //1. 统一锁盘时间(比赛开始前1分钟)
-        SportModel::where(['is_locked' => 0, 'is_roll' => 0])->where('game_time', '<=', time() - 60)->update(['is_locked' => 1]);
+        SportModel::where(['is_locked' => 0, 'is_roll' => 0])->where('game_time', '<=', time() + 90)->update(['is_locked' => 1]);
 
         //2. 比赛进行中,超过3分钟未更新的数据检测
         $end_time = date("Y-m-d H:i:s", time() - 180);
         $ids = SportModel::where('status', 1)->where('state', 1)->where('updated_at', '<=', $end_time)->pluck('data_id')->toArray();
         if ($ids) {
-            $ids = implode('-', $ids);
-            $data = SportClientService::fixtures(['ids' => $ids]);
-            $this->updateOrCreateSport($data, $sport_locked, 1);
+            $chunks = array_chunk($ids, 10);
+            foreach ($chunks as $chunk) {
+                $ids = implode('-', $chunk);
+                $data = SportClientService::fixtures(['ids' => $ids]);
+                $this->updateOrCreateSport($data, $sport_locked, 1);
+            }
         }
         return true;
     }
@@ -311,7 +326,7 @@ class Sport extends Command
                         SportModel::where('data_id', $item['fixture']['id'])->update($sport_data);
                     }
                     //比赛结束,插入比赛事件
-                    if ($sport_data['state'] == 2 && !empty($item['events'])) {
+                    if ($sport_data['state'] >= 2 && !empty($item['events'])) {
                         foreach($item['events'] as $event) {
                             SportEvent::create([
                                 'data_id' => $item['fixture']['id'],
@@ -325,7 +340,6 @@ class Sport extends Command
                                 'assist' => $event['assist'] ? json_encode($event['assist']) : $event['assist'],
                             ]);
                         }
-        
                     }
                 }
                 if ($tableData) {

+ 1 - 0
app/Http/Controllers/admin/Sport.php

@@ -96,6 +96,7 @@ class Sport extends Controller
 
             $info['odds'] = $info['odds'] ? json_decode($info['odds'], true) : null;
             $info['event'] = SportEvent::where('data_id', $info['data_id'])->get();
+            $info['odd_ids_locked'] = $info['odd_ids_locked'] ? json_decode($info['odd_ids_locked'], true) : [];
 
         } catch (Exception $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());

+ 1 - 1
app/Models/Sport.php

@@ -7,6 +7,6 @@ class Sport extends BaseModel
     protected $table = 'sport';
     protected $fillable = ['data_id', 'home_team_id', 'home_team_en', 'home_team', 'home_team_logo', 'guest_team_id', 'guest_team_en', 'guest_team', 'guest_team_logo', 'half_score', 'rbt', 
     'is_roll', 'score', 'league_en','league','odds','state','game_time','status','handicap_limit','over_under_limit','duying_limit','correct_core_limit','odd_even_limit','total_goal_limit',
-    'is_handicap', 'is_over_under','is_duying','is_correct_core','is_odd_even','is_total_goal','is_locked','fixture_status','is_send','odd_ids_locked'];
+    'is_handicap', 'is_over_under','is_duying','is_correct_core','is_odd_even','is_total_goal','is_locked','fixture_status','is_send','odd_ids_locked','is_refund'];
  
 }