|
|
@@ -3,6 +3,10 @@ namespace App\Http\Model;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
use App\Http\Response\Response;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+use App\Lib\Biz\Sport\Common as commonFunction;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Class StLqResult
|
|
|
@@ -109,13 +113,13 @@ class StLqResult extends Model
|
|
|
public static function LQresult($model){
|
|
|
//获取当天开始并且已结束的所有赛事
|
|
|
$matchData = $model['model_match']::select('id','home_team','guest_team','lg_id','status','tag','match_date','match_time')
|
|
|
- ->where([['match_date','=',date('Y-m-d', time())],['status','=',2]])
|
|
|
+ ->where([['match_date','>',date('Y-m-d',strtotime("-2 day"))],['status','=',2]])
|
|
|
->get()
|
|
|
->toArray();
|
|
|
|
|
|
//获取赛事结果表 一天内
|
|
|
$matchData_r = $model['model_result']::select('match_id')
|
|
|
- ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-1 day"))]])
|
|
|
+ ->where([['ctime','>',date('Y-m-d H:i:s', strtotime("-2 day"))]])
|
|
|
->get()
|
|
|
->toarray();
|
|
|
|
|
|
@@ -144,85 +148,103 @@ class StLqResult extends Model
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
$match_ids_str = implode(",", $match_ids);
|
|
|
|
|
|
- //上半场
|
|
|
- $sql_h = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer from st_lq_result_record a,
|
|
|
- (select match_id,max(id) id from st_zq_result_record where match_process = '上半场' and match_id IN ($match_ids_str) group by match_id)b
|
|
|
+ //第一节
|
|
|
+ $sql_1 = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer from st_lq_result_record a,
|
|
|
+ (select match_id,max(id) id from st_lq_result_record where match_process = '第一节' and match_id IN ($match_ids_str) group by match_id)b
|
|
|
where a.match_id = b.match_id and a.id = b.id ";
|
|
|
-
|
|
|
- //全场
|
|
|
- $sql_f = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.all_goal,a.first_score,a.last_score,a.match_score,a.match_winer,a.home_rate,a.guest_rate from st_lq_result_record a,
|
|
|
- (select match_id,max(id) id from st_zq_result_record where match_id IN ($match_ids_str) group by match_id)b
|
|
|
+ //第二节
|
|
|
+ $sql_2 = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer from st_lq_result_record a,
|
|
|
+ (select match_id,max(id) id from st_lq_result_record where match_process = '第二节' and match_id IN ($match_ids_str) group by match_id)b
|
|
|
+ where a.match_id = b.match_id and a.id = b.id ";
|
|
|
+ //第三节
|
|
|
+ $sql_3 = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer from st_lq_result_record a,
|
|
|
+ (select match_id,max(id) id from st_lq_result_record where match_process = '第三节' and match_id IN ($match_ids_str) group by match_id)b
|
|
|
+ where a.match_id = b.match_id and a.id = b.id ";
|
|
|
+ //第四节
|
|
|
+ $sql_4 = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.home_rate,a.guest_rate,a.match_process,a.first_score,a.last_score,a.match_score,a.match_winer from st_lq_result_record a,
|
|
|
+ (select match_id,max(id) id from st_lq_result_record where match_process = '第四节' and match_id IN ($match_ids_str) group by match_id)b
|
|
|
where a.match_id = b.match_id and a.id = b.id ";
|
|
|
|
|
|
- //上半场最终结果
|
|
|
- $match_result_h = DB::select($sql_h);
|
|
|
-
|
|
|
- //全场最终结果
|
|
|
- $match_result_f = DB::select($sql_f);
|
|
|
- //拼装赛事结果数据
|
|
|
- $match_result_record = [];
|
|
|
- if(!empty($match_result_h) and !empty($match_result_f)){
|
|
|
- foreach($match_result_h as $k=>$v){
|
|
|
- foreach($match_result_f as $kk=>$vv){
|
|
|
- if($v->match_id == $vv->match_id){
|
|
|
- $match_result_record[$k] = [
|
|
|
- "match_id"=>$v->match_id,
|
|
|
- "home_score"=> $vv->home_score,
|
|
|
- "guest_score"=> $vv->guest_score,
|
|
|
- "a_time"=> $vv->a_time,
|
|
|
- "match_process"=> $vv->match_process,
|
|
|
- "all_goal"=> $vv->all_goal,
|
|
|
- "first_score"=> $vv->first_score,
|
|
|
- "last_score"=> $vv->last_score,
|
|
|
- "match_score"=> $vv->match_score,
|
|
|
- "match_winer"=> $vv->match_winer,
|
|
|
- "u_home_score"=> $v->home_score,
|
|
|
- "u_guest_score"=> $v->guest_score,
|
|
|
- "home_rate"=> $vv->home_rate,
|
|
|
- "guest_rate"=> $vv->guest_rate,
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
+ //第一节最终结果
|
|
|
+ $match_result_1 = DB::select($sql_1);
|
|
|
+ //第二节最终结果
|
|
|
+ $match_result_2 = DB::select($sql_2);
|
|
|
+ //第三节最终结果
|
|
|
+ $match_result_3 = DB::select($sql_3);
|
|
|
+ //第四节最终结果
|
|
|
+ $match_result_4 = DB::select($sql_4);
|
|
|
|
|
|
+ //拼装赛事结果数据
|
|
|
+ $set_match_r = [];
|
|
|
|
|
|
- //组装赛果数据
|
|
|
- if(!empty($match_result_record)){
|
|
|
- foreach ($matchData as $k=>$v){
|
|
|
- $start_time = ($v['match_date'].' '.$v['match_time']);
|
|
|
- $time = time()-strtotime($v['match_time']);
|
|
|
- $match_time = self::secTime($time);
|
|
|
- foreach($match_result_record as $kk =>$vv){
|
|
|
- if($v['id'] == $vv['match_id']){
|
|
|
- $set_match_r[] = [
|
|
|
- "match_id"=> $v['id'],
|
|
|
- "home_team"=>$v['home_team'],
|
|
|
- "guest_team"=>$v['guest_team'],
|
|
|
- "lg_id"=>$v['lg_id'],
|
|
|
- "status"=>$v['status'],
|
|
|
- "tag"=> $v['tag'],
|
|
|
- 'match_time'=>$vv['a_time']?:0,//比赛进行时间
|
|
|
- "ctime"=>date('Y-m-d H:i:s'),
|
|
|
- "update_time"=>date('Y-m-d H:i:s'),
|
|
|
- "start_time"=>date('Y-m-d H:i:s',strtotime($start_time)),
|
|
|
-
|
|
|
- "home_rate"=> $vv['home_rate']?:0, //主队让球
|
|
|
- "guest_rate"=> $vv['guest_rate']?:0, //客队让球
|
|
|
- "home_score"=> $vv['home_score']?:0, //主队进球数
|
|
|
- "guest_score"=> $vv['guest_score']?:0, //客队进球数
|
|
|
- "all_goal"=> $vv['all_goal']?:0, //总进球数
|
|
|
- "first_score"=> $vv['first_score']?:'', //最先进球球队
|
|
|
- "last_score"=> $vv['last_score']?:'', //最后进球球队
|
|
|
- "match_score"=> $vv['match_score']?:0, //赛事比分
|
|
|
- "match_winer"=> $vv['match_winer']?:'',//获胜球队
|
|
|
- "match_process"=> $vv['match_process']?:'',//比赛进程
|
|
|
- "u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
|
|
|
- "u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
|
|
|
- ];
|
|
|
- }
|
|
|
+ if(!empty($match_result_1) and !empty($match_result_2) and !empty($match_result_3) and !empty($match_result_4)){
|
|
|
+ $start_time = ($v['match_date'].' '.$v['match_time']);
|
|
|
+ $time = time()-strtotime($v['match_time']);
|
|
|
+ $match_time = self::secTime($time);
|
|
|
+ foreach($matchData as $k =>$v ){
|
|
|
+ //获取赛事每节的赛果
|
|
|
+ $result_1 = commonFunction::filter_by_value($match_result_1,$v['id']);
|
|
|
+ $result_2 = commonFunction::filter_by_value($match_result_2,$v['id']);
|
|
|
+ $result_3 = commonFunction::filter_by_value($match_result_3,$v['id']);
|
|
|
+ $result_4 = commonFunction::filter_by_value($match_result_4,$v['id']);
|
|
|
+
|
|
|
+ if(!empty($result_1) and !empty($result_2) and !empty($result_3) and !empty($result_4)){
|
|
|
+
|
|
|
+ //拼接赛事主队比分 {"1":0,"2":0,"3":0,"4":0}
|
|
|
+ $home_score = [
|
|
|
+ '1'=>$result_1['home_score'],
|
|
|
+ '2'=>$result_2['home_score'],
|
|
|
+ '3'=>$result_3['home_score'],
|
|
|
+ '4'=>$result_4['home_score']
|
|
|
+ ];
|
|
|
+ //拼接赛事客队比分
|
|
|
+ $guest_score = [
|
|
|
+ '1'=>$result_1['guest_score'],
|
|
|
+ '2'=>$result_2['guest_score'],
|
|
|
+ '3'=>$result_3['guest_score'],
|
|
|
+ '4'=>$result_4['guest_score']
|
|
|
+ ];
|
|
|
+
|
|
|
+ //获取获胜球队
|
|
|
+ if(($result_4['home_score']) > ($result_4['guest_score'])){
|
|
|
+ $match_winer = $v['home_team'];
|
|
|
+ }else{
|
|
|
+ $match_winer = $v['guest_team'];
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取总进球数
|
|
|
+ $all_goal = ($result_4['home_score'])+($result_4['guest_score']);
|
|
|
+
|
|
|
+ //赛事待写入赛果数据
|
|
|
+ $set_match_r[] = [
|
|
|
+ "match_id"=> $v['id'],
|
|
|
+ "home_team"=>$v['home_team'],
|
|
|
+ "guest_team"=>$v['guest_team'],
|
|
|
+ "lg_id"=>$v['lg_id'],
|
|
|
+ "status"=>$v['status'],
|
|
|
+ "tag"=> $v['tag'],
|
|
|
+ 'match_time'=>$result_4['a_time']?:0,//比赛进行时间
|
|
|
+ "ctime"=>date('Y-m-d H:i:s'),
|
|
|
+ "update_time"=>date('Y-m-d H:i:s'),
|
|
|
+ "start_time"=>date('Y-m-d H:i:s',strtotime($start_time)),
|
|
|
+
|
|
|
+ "home_rate"=> $result_4['home_rate']?:0, //主队让球
|
|
|
+ "guest_rate"=> $result_4['guest_rate']?:0, //客队让球
|
|
|
+ "home_score"=> json_encode($home_score)?:'', //主队进球数
|
|
|
+ "guest_score"=> json_encode($guest_score)?:'', //客队进球数
|
|
|
+ "all_goal"=> $all_goal?:0, //总进球数
|
|
|
+ "first_score"=> $result_4['first_score']?:'', //最先进球球队
|
|
|
+ "last_score"=> $result_4['last_score']?:'', //最后进球球队
|
|
|
+ "match_score"=> $result_4['match_score']?:0, //赛事比分
|
|
|
+ "match_winer"=> $match_winer?:'',//获胜球队
|
|
|
+ "match_process"=> $result_4['match_process']?:'',//比赛进程
|
|
|
+ "u_home_score"=> $result_2['home_score']?:0,//上半场主队进球数
|
|
|
+ "u_guest_score"=> $result_2['guest_score']?:0,//上半场客队进球数
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
}
|