|
|
@@ -6,6 +6,7 @@ use App\Http\Response\Response;
|
|
|
use Fideloper\Proxy\TrustedProxyServiceProvider;
|
|
|
//use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Database\Capsule\Manager as DB;
|
|
|
+use App\Lib\Biz\Sport\Common as commonFunction;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -47,7 +48,7 @@ class StZqResult 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_zq_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
|
|
|
@@ -89,7 +90,7 @@ class StZqResult extends Model
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
//结果表无数据,直接插入
|
|
|
if(empty($matchData_r)){
|
|
|
@@ -97,7 +98,7 @@ class StZqResult extends Model
|
|
|
$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){
|
|
|
+ foreach($match_result_record as $kk =>$vv){
|
|
|
if($v['id'] == $vv['match_id']){
|
|
|
$set_match_r[] = [
|
|
|
"match_id"=> $v['id'],
|
|
|
@@ -123,8 +124,8 @@ class StZqResult extends Model
|
|
|
"match_process"=> $vv['match_process']?:'',//比赛进程
|
|
|
"u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
|
|
|
"u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
|
|
|
- ];
|
|
|
- }
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
/*
|
|
|
@@ -133,7 +134,7 @@ class StZqResult extends Model
|
|
|
if($ret != true) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
|
|
|
}
|
|
|
*/
|
|
|
-
|
|
|
+
|
|
|
}else {
|
|
|
//如果结果表有数据,则获取结果表没有的赛事
|
|
|
foreach ($matchData as $k => $v) {
|
|
|
@@ -150,7 +151,7 @@ class StZqResult extends Model
|
|
|
$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){
|
|
|
+ foreach($match_result_record as $kk =>$vv){
|
|
|
if($v['id'] == $vv['match_id']){
|
|
|
$set_match_r[] = [
|
|
|
"match_id"=> $v['id'],
|
|
|
@@ -163,7 +164,7 @@ class StZqResult extends Model
|
|
|
"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, //主队进球数
|
|
|
@@ -176,8 +177,8 @@ class StZqResult extends Model
|
|
|
"match_process"=> $vv['match_process']?:'',//比赛进程
|
|
|
"u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
|
|
|
"u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
|
|
|
- ];
|
|
|
- }
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -233,7 +234,7 @@ class StZqResult 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_zq_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
|
|
|
@@ -277,7 +278,7 @@ class StZqResult extends Model
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
//组装赛果数据
|
|
|
if(!empty($match_result_record)){
|
|
|
@@ -285,7 +286,7 @@ class StZqResult extends Model
|
|
|
$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){
|
|
|
+ foreach($match_result_record as $kk =>$vv){
|
|
|
if($v['id'] == $vv['match_id']){
|
|
|
//获取获胜球队
|
|
|
if(($vv['home_score']) > ($vv['guest_score'])){
|
|
|
@@ -317,8 +318,8 @@ class StZqResult extends Model
|
|
|
"match_process"=> $vv['match_process']?:'',//比赛进程
|
|
|
"u_home_score"=> $vv['u_home_score']?:0,//上半场主队进球数
|
|
|
"u_guest_score"=> $vv['u_guest_score']?:0,//上半场客队进球数
|
|
|
- ];
|
|
|
- }
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -335,22 +336,21 @@ class StZqResult extends Model
|
|
|
/**
|
|
|
* 获取自动赛事结果
|
|
|
* 只更新已结束+未手动修改的赛事结果
|
|
|
- * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果
|
|
|
+ * $match_id 本地赛事id 为0时 则用于后台手动刷新赛果
|
|
|
*/
|
|
|
public static function ZQresult_v2($model,$match_id = 0){
|
|
|
-
|
|
|
//如果有赛事id 则只更新当前赛事结果
|
|
|
if($match_id > 0){
|
|
|
$match_ids_str = $match_id;
|
|
|
+ $match_ids = [$match_id];
|
|
|
}else{
|
|
|
//获取两天内的结束赛事
|
|
|
$matchData = $model['model_match']
|
|
|
->join('st_zq_result','st_zq_result.match_id','=','st_zq_competition.id')
|
|
|
- ->select('st_zq_competition.id','is_correct')
|
|
|
- ->where([['st_zq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_zq_competition.status','=',2],['st_zq_result.is_correct','=',-1]])
|
|
|
+ ->select('st_zq_competition.id','is_correct','manual_result')
|
|
|
+ ->where([['st_zq_competition.match_date','>',date('Y-m-d', strtotime("-2 day"))],['st_zq_competition.status','=',2],['st_zq_result.is_correct','=',-1]])//
|
|
|
->get()
|
|
|
->toArray();
|
|
|
-
|
|
|
//没有数据,无需操作
|
|
|
if(empty($matchData)) return Response::success();
|
|
|
//获取需更新结果的赛事ID
|
|
|
@@ -365,7 +365,15 @@ class StZqResult extends Model
|
|
|
|
|
|
$match_ids_str = implode(",", $match_ids);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ //如果有赛事id 获取结果中的手动数据
|
|
|
+ if(!empty($match_ids)){
|
|
|
+ $manual_result_data = self::select('match_id','manual_result')
|
|
|
+ ->whereIn('match_id',$match_ids)
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
//上半场
|
|
|
$sql_h = "select a.match_id,a.home_team,a.guest_team,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_zq_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
|
|
|
@@ -419,9 +427,12 @@ class StZqResult extends Model
|
|
|
$match_winer = $v['home_team'];
|
|
|
}else{
|
|
|
$match_winer = $v['guest_team'];
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ //===追加获取手动结果数据===
|
|
|
+ $manual_result_json = self::getManual_result($manual_result_data,$v,$v['match_id']);
|
|
|
+
|
|
|
$set_match_r = [
|
|
|
"match_id"=> $v['match_id'],
|
|
|
"update_time"=>date('Y-m-d H:i:s'),
|
|
|
@@ -439,18 +450,90 @@ class StZqResult extends Model
|
|
|
"u_home_score"=> $v['u_home_score']?:0,//上半场主队进球数
|
|
|
"u_guest_score"=> $v['u_guest_score']?:0,//上半场客队进球数
|
|
|
"is_correct"=> -1,//自动比分
|
|
|
- ];
|
|
|
-
|
|
|
+ "manual_result"=> $manual_result_json,//手动结果
|
|
|
+ ];
|
|
|
$ret = $model['model_result']::where(['match_id' => $v['match_id'],'is_correct'=>-1])
|
|
|
->update($set_match_r);
|
|
|
-
|
|
|
+
|
|
|
// if($ret < 1) throw new \Exception( Response::generate('',Response::ADD_MATCH_R_ERROR));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理 拼接手动结果数据
|
|
|
+ * $manual_result_data arr 多个赛事手动结果数据
|
|
|
+ * $match_id int 赛事id
|
|
|
+ */
|
|
|
+ public static function getManual_result($manual_result_data,$auto_result,$match_id){
|
|
|
+ $resultData = commonFunction::filter_by_value($manual_result_data,'match_id',$match_id);
|
|
|
+ //手动结果数据 json
|
|
|
+ $manual_result_json = $resultData['manual_result'];
|
|
|
+ //手动结果数据 arr
|
|
|
+ $manual_result_arr = json_decode($manual_result_json,true);
|
|
|
+
|
|
|
+ //拼接手动数据
|
|
|
+ foreach($manual_result_arr as $kk=>$vv){
|
|
|
+ //上半场角球
|
|
|
+ if($kk == 'half_corner'){
|
|
|
+ //赋值 上半场角球
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['home'] = 0;
|
|
|
+ $vv['guest'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //全场角球
|
|
|
+ if($kk == 'all_corner'){
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['home'] = 0;
|
|
|
+ $vv['guest'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //上半场比分
|
|
|
+ if($kk == 'half'){
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['home'] = $auto_result['u_home_score']?:0;
|
|
|
+ $vv['guest'] = $auto_result['u_guest_score']?:0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //全场比分
|
|
|
+ if($kk == 'all'){
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['home'] = $auto_result['home_score']?:0;
|
|
|
+ $vv['guest'] = $auto_result['guest_score']?:0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //上半场罚牌
|
|
|
+ if($kk == 'half_penalty'){
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['home'] = 0;
|
|
|
+ $vv['guest'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //全场罚牌
|
|
|
+ if($kk == 'all_penalty'){
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['home'] = 0;
|
|
|
+ $vv['guest'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //首进球时间
|
|
|
+ if($kk == 'first_score'){
|
|
|
+ if(empty($vv['home']) || empty($vv['guest'])){
|
|
|
+ $vv['time'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $manual_result_arr[$kk] =$vv;
|
|
|
+ }
|
|
|
+ //转回json
|
|
|
+ $manual_result_json = json_encode($manual_result_arr);
|
|
|
+
|
|
|
+ return $manual_result_json;
|
|
|
+ }
|
|
|
|
|
|
//计算滚球 赛事进行时间
|
|
|
public static function secTime($sec=0){
|
|
|
@@ -541,7 +624,7 @@ class StZqResult extends Model
|
|
|
|
|
|
//更新
|
|
|
$ret = self::where(['match_id' => $match_id])
|
|
|
- ->update(['warn_more'=>$warn_data,'update_time'=>date('Y-m-d H:i:s')]);
|
|
|
+ ->update(['warn_more'=>$warn_data,'update_time'=>date('Y-m-d H:i:s')]);
|
|
|
}
|
|
|
|
|
|
return $ret;
|