Răsfoiți Sursa

修改体彩

lip 5 zile în urmă
părinte
comite
5ba17b2fd1
2 a modificat fișierele cu 23 adăugiri și 15 ștergeri
  1. 20 9
      app/Console/Commands/Sport.php
  2. 3 6
      app/Http/Controllers/admin/Sport.php

+ 20 - 9
app/Console/Commands/Sport.php

@@ -109,27 +109,37 @@ class Sport extends Command
             // die;
             
             $this->checkLiveFixtures();
-        } 
+        } elseif ($this->is_live == 3) {
+            $this->checkOvertimeFixtures();
+        }
     }
 
-    //进行中超过3分钟没有更新数据的赛事,检查比赛是否结束
-    public function checkLiveFixtures()
+    //到了比赛开始时间,但是状态还是未开始,检查比赛
+    public function checkOvertimeFixtures()
     { 
         //体育赛事结束前几(分钟)锁盘,90分钟结束
         $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]);
-        
-        //2. 比赛开始后,状态还是未开始的数据检测
-        $ids = SportModel::where('status', 1)->where('state', 0)->where('game_time', '>=', time())->pluck('data_id')->toArray();
+        // 比赛开始后,状态还是未开始的数据检测
+        $ids = SportModel::where('status', 1)->where('state', 0)->where('game_time', '<=', time())->pluck('data_id')->toArray();
         if ($ids) {
             $ids = implode('-', $ids);
             $data = SportClientService::fixtures(['ids' => $ids]);
             $this->updateOrCreateSport($data, $sport_locked, 1);
         }
+        return true;
+    }
+
+    //进行中超过3分钟没有更新数据的赛事,检查比赛是否结束
+    public function checkLiveFixtures()
+    { 
+        //体育赛事结束前几(分钟)锁盘,90分钟结束
+        $sport_locked = Config::where('field', 'sport_locked')->first()->val ?? 1;
 
-        //3. 比赛进行中,超过3分钟未更新的数据检测
+        //1. 统一锁盘时间(比赛开始前1分钟)
+        SportModel::where(['is_locked' => 0, 'is_roll' => 0])->where('game_time', '<=', time() - 60)->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) {
@@ -137,6 +147,7 @@ class Sport extends Command
             $data = SportClientService::fixtures(['ids' => $ids]);
             $this->updateOrCreateSport($data, $sport_locked, 1);
         }
+        return true;
     }
     
     //更新进行中的赛事

+ 3 - 6
app/Http/Controllers/admin/Sport.php

@@ -113,18 +113,15 @@ class Sport extends Controller
                 'is_locked' => ['nullable', 'integer'],
             ]);
             $id = $params['id'];
-            $info = SportModel::where('id', $id)->first();
-            if (!$info) throw new Exception('赛事不存在');
             if (isset($params['state']) && $params['state'] !== null) {
-                $info->state = $params['state'];
+                SportModel::whereIn('id', $id)->update(['state' => $params['state']]);
             }
             if (isset($params['is_locked']) && $params['is_locked'] !== null) {
-                $info->is_locked = $info->is_locked ? 0 : 1;
+                SportModel::whereIn('id', $id)->update(['is_locked' => $params['is_locked']]);
             }
             if (isset($params['status']) && $params['status'] !== null) {
-                $info->status = $info->status ? 0 : 1;
+                SportModel::whereIn('id', $id)->update(['status' => $params['status']]);
             }
-            $info->save();
             return $this->success();
         } catch (Exception $e) {
             return $this->error(HttpStatus::CUSTOM_ERROR,$e->getMessage());