|
|
@@ -21,6 +21,8 @@ use App\Http\Model\StZqLocalMatch as MatchModel;
|
|
|
use App\Http\Model\StZqOdds as OddsModel;
|
|
|
use App\Http\Model\StZqOddsRecord as OddsRecordModel;
|
|
|
use App\Http\Model\StZqResult as ZqResultModel;
|
|
|
+use App\Http\Model\St_area_country as StAreaCountryModel;
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -51,6 +53,41 @@ class WriteSportsController extends BaseController{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据联赛名称 获取 国家 地区
|
|
|
+ */
|
|
|
+ public function getArea($leagueName = ''){
|
|
|
+ //如果联赛名称有括号,去除
|
|
|
+ $leagueName = preg_replace('/\(.*?\)/', '', $leagueName);
|
|
|
+
|
|
|
+ //获取所有国家/地区
|
|
|
+ $areaData = StAreaCountryModel::select('id','pid','name')->get()->toArray();
|
|
|
+
|
|
|
+ //获取当前联赛所属国家
|
|
|
+ if(strpos($leagueName,'NBA') !== false){
|
|
|
+ $data = [
|
|
|
+ 'id'=>247,
|
|
|
+ 'pid'=>0,
|
|
|
+ 'name'=>'世界'
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ //识别本地 国家地区数据
|
|
|
+ foreach($areaData as $v => $k){
|
|
|
+ if(strpos($leagueName,$k['name']) !== false){
|
|
|
+ return $k;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果不能识别,则返回世界
|
|
|
+ $data = [
|
|
|
+ 'id'=>247,
|
|
|
+ 'pid'=>0,
|
|
|
+ 'name'=>'世界'
|
|
|
+ ];
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
/*
|
|
|
* 写 联赛 数据
|
|
|
* 每个请求 包含 N个联赛
|
|
|
@@ -58,8 +95,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function setLeague(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
try {
|
|
|
//开启事务
|
|
|
DB::beginTransaction();
|
|
|
@@ -83,37 +121,46 @@ class WriteSportsController extends BaseController{
|
|
|
//获取 联赛 数据
|
|
|
$leagueData = $getData['data'];
|
|
|
|
|
|
- //获取 当前请求 所有 lg_id
|
|
|
- $s_lg_ids = [];
|
|
|
+ //获取 当前请求 所有 联赛 uuid
|
|
|
+ $identity = [];
|
|
|
foreach($leagueData as $k=>$v){
|
|
|
- $s_lg_ids[] = $v['lg_id'];
|
|
|
+ $identity[] = $v['uuid'];
|
|
|
}
|
|
|
- $s_lg_ids = array_unique($s_lg_ids);
|
|
|
- sort($s_lg_ids);
|
|
|
+ $identity = array_unique($identity);
|
|
|
+ sort($identity);
|
|
|
|
|
|
//获取 本地 已存在 联赛
|
|
|
- $l_lg_data = $models['model_local_league']::whereIn('others_lg_id',$s_lg_ids)->where('source',$source)->select('others_lg_id','lg_id')->get()->toArray();
|
|
|
+ $l_lg_data = $models['model_local_league']::whereIn('identity',$identity)->select('identity','lg_id')->get()->toArray();
|
|
|
//二维数组去重
|
|
|
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'others_lg_id');
|
|
|
- //循环对比 请求lg_id->本地others_lg_id
|
|
|
+ $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
|
|
|
+ //循环对比 请求identity->本地identity
|
|
|
foreach($l_lg_data as $k=>$v){
|
|
|
- foreach($s_lg_ids as $kk=> $s_lg_id){
|
|
|
- if($v['others_lg_id'] == $s_lg_id){
|
|
|
- unset($s_lg_ids[$kk]);
|
|
|
+ foreach($identity as $kk=> $uuid){
|
|
|
+ if($v['identity'] == $uuid){
|
|
|
+ unset($identity[$kk]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则将其写入
|
|
|
- if(!empty($s_lg_ids)) {
|
|
|
+ //去除本地和请求里都存在的联赛,如果还有剩余联赛uuid,则将其写入
|
|
|
+ if(!empty($identity)) {
|
|
|
//没有 决赛时间 默认获取本年最后一天
|
|
|
$last_time = date('Y-12-31 23:59:59');
|
|
|
foreach($leagueData as $k=>$v){
|
|
|
- foreach($s_lg_ids as $kk=> $s_lg_id){
|
|
|
- if($v['lg_id'] == $s_lg_id){
|
|
|
+ foreach($identity as $kk=> $uuid){
|
|
|
+ if($v['uuid'] == $uuid){
|
|
|
//如有 决赛时间
|
|
|
if($v['last_time']){
|
|
|
$last_time = $v['last_time'];
|
|
|
}
|
|
|
+ //获取联赛所属国家或地区
|
|
|
+ $getArea = $this->getArea($v['name_chinese']);
|
|
|
+ if($getArea['pid'] == 0){
|
|
|
+ $area_id = $getArea['id'];
|
|
|
+ $country_id = 0;
|
|
|
+ }else{
|
|
|
+ $area_id = $getArea['pid'];
|
|
|
+ $country_id = $getArea['id'];
|
|
|
+ }
|
|
|
if(empty($v['uuid'])) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$v['lg_id'].';',Response::LG__UUID_NULL));
|
|
|
$set_lg['name_chinese'] = $v['name_chinese'];
|
|
|
$set_lg['kind'] = $v['kind'];
|
|
|
@@ -122,6 +169,8 @@ class WriteSportsController extends BaseController{
|
|
|
$set_lg['identity'] = $v['uuid'];
|
|
|
$set_lg['last_time'] = $last_time;
|
|
|
$set_lg['utime'] = date('Y-m-d H:i:s');
|
|
|
+ $set_lg['area_id'] = $area_id;
|
|
|
+ $set_lg['country_id'] = $country_id;
|
|
|
//写入联赛
|
|
|
$id = $models['model_league']::insertGetId($set_lg);
|
|
|
$m_lg_id = $id;
|
|
|
@@ -132,7 +181,8 @@ class WriteSportsController extends BaseController{
|
|
|
'lg_id'=>$id,
|
|
|
'others_lg_id'=>$v['lg_id'],
|
|
|
'source'=>$source,
|
|
|
- 'ctime'=>date('Y-m-d H:i:s')
|
|
|
+ 'ctime'=>date('Y-m-d H:i:s'),
|
|
|
+ 'identity'=>$v['uuid'],
|
|
|
];
|
|
|
$ret = $models['model_local_league']::insertGetId($set_local);
|
|
|
if($ret < 1) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$data['lg_id'].';',Response::LOCAL_LEAGUE_ERROR)) ;//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
|
|
|
@@ -159,9 +209,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function setMatch(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
-
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
try {
|
|
|
//开启事务
|
|
|
DB::beginTransaction();
|
|
|
@@ -182,33 +232,33 @@ class WriteSportsController extends BaseController{
|
|
|
$models = commonFunction::getModels($game_code, 1);
|
|
|
//获取 赛事 数据
|
|
|
$matchData = $getData['data'];
|
|
|
- //获取 当前请求 所有 lg_id /match_id
|
|
|
- $s_lg_ids = [];
|
|
|
+ //获取 当前请求 所有 uuid /match_id
|
|
|
+ $identity = [];
|
|
|
$s_match_ids = [];
|
|
|
foreach($matchData as $k=>$v){
|
|
|
- $s_lg_ids[] = $v['lg_id'];
|
|
|
+ $identity[] = $v['uuid'];
|
|
|
$s_match_ids[] = $v['match_id'];
|
|
|
}
|
|
|
|
|
|
//====验证 赛事 所属 联赛 是否存在====
|
|
|
- $s_lg_ids = array_unique($s_lg_ids);
|
|
|
- sort($s_lg_ids);
|
|
|
+ $identity = array_unique($identity);
|
|
|
+ sort($identity);
|
|
|
|
|
|
//获取 本地 已存在 联赛
|
|
|
- $l_lg_data = $models['model_local_league']::whereIn('others_lg_id',$s_lg_ids)->where('source',$source)->select('others_lg_id','lg_id')->get()->toArray();
|
|
|
+ $l_lg_data = $models['model_local_league']::whereIn('identity',$identity)->select('identity','lg_id')->get()->toArray();
|
|
|
//二维数组去重
|
|
|
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'others_lg_id');
|
|
|
- //循环对比 请求lg_id->本地others_lg_id
|
|
|
+ $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
|
|
|
+ //循环对比 请求uuid->本地identity
|
|
|
foreach($l_lg_data as $k=>$v){
|
|
|
- foreach($s_lg_ids as $kk=> $s_lg_id){
|
|
|
- if($v['others_lg_id'] == $s_lg_id){
|
|
|
- unset($s_lg_ids[$kk]);
|
|
|
+ foreach($identity as $kk=> $uuid){
|
|
|
+ if($v['identity'] == $uuid){
|
|
|
+ unset($identity[$kk]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- sort($s_lg_ids);
|
|
|
+ sort($identity);
|
|
|
//去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
|
|
|
- if(!empty($s_lg_ids)) throw new \Exception(Response::generate($gameName.'联赛:lg_id-'.$s_lg_ids[0].';',Response::LEAGUE_ERROR));
|
|
|
+ if(!empty($identity)) throw new \Exception(Response::generate($gameName.'联赛:uuid-'.$identity[0].';',Response::LEAGUE_ERROR));
|
|
|
//====end====
|
|
|
|
|
|
//====获取 本地 已存在 赛事====
|
|
|
@@ -310,8 +360,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function setMatchResult(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
|
|
|
try {
|
|
|
//开启事务
|
|
|
@@ -320,6 +371,7 @@ class WriteSportsController extends BaseController{
|
|
|
//请求 数据 为空
|
|
|
if(empty($obt)) throw new \Exception(Response::generate('请求数据为空,',Response::ABNORMAL));
|
|
|
$getData = $this->getAddData($obt);
|
|
|
+
|
|
|
//不是 赛事 结果 记录 数据
|
|
|
if($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,',Response::ABNORMAL));
|
|
|
|
|
|
@@ -334,34 +386,33 @@ class WriteSportsController extends BaseController{
|
|
|
//获取 赛事 数据
|
|
|
$match_r_data = $getData['data'];
|
|
|
|
|
|
- //获取 当前请求 所有 lg_id /match_id
|
|
|
- $s_lg_ids = [];
|
|
|
+ //获取 当前请求 所有 uuid /match_id
|
|
|
+ $identity = [];
|
|
|
$s_match_ids = [];
|
|
|
foreach($match_r_data as $k=>$v){
|
|
|
- $s_lg_ids[] = $v['lg_id'];
|
|
|
+ $identity[] = $v['uuid'];
|
|
|
$s_match_ids[] = $v['match_id'];
|
|
|
}
|
|
|
|
|
|
- //====验证 赛事结果记录 所属 联赛 是否存在====
|
|
|
- $s_lg_ids = array_unique($s_lg_ids);
|
|
|
- sort($s_lg_ids);
|
|
|
+ //====验证 赛事 所属 联赛 是否存在====
|
|
|
+ $identity = array_unique($identity);
|
|
|
+ sort($identity);
|
|
|
|
|
|
//获取 本地 已存在 联赛
|
|
|
- $l_lg_data = $models['model_local_league']::whereIn('others_lg_id',$s_lg_ids)->where('source',$source)->select('others_lg_id','lg_id')->get()->toArray();
|
|
|
+ $l_lg_data = $models['model_local_league']::whereIn('identity',$identity)->select('identity','lg_id')->get()->toArray();
|
|
|
//二维数组去重
|
|
|
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'others_lg_id');
|
|
|
-
|
|
|
- //循环对比 请求lg_id->本地others_lg_id
|
|
|
+ $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
|
|
|
+ //循环对比 请求uuid->本地identity
|
|
|
foreach($l_lg_data as $k=>$v){
|
|
|
- foreach($s_lg_ids as $kk=> $s_lg_id){
|
|
|
- if($v['others_lg_id'] == $s_lg_id){
|
|
|
- unset($s_lg_ids[$kk]);
|
|
|
+ foreach($identity as $kk=> $uuid){
|
|
|
+ if($v['identity'] == $uuid){
|
|
|
+ unset($identity[$kk]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- sort($s_lg_ids);
|
|
|
+ sort($identity);
|
|
|
//去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
|
|
|
- if(!empty($s_lg_ids)) throw new \Exception(Response::generate($gameName.'联赛:lg_id-'.$s_lg_ids[0].';',Response::LEAGUE_ERROR));
|
|
|
+ if(!empty($identity)) throw new \Exception(Response::generate($gameName.'联赛:uuid-'.$identity[0].';',Response::LEAGUE_ERROR));
|
|
|
//====end====
|
|
|
|
|
|
//====验证 赛事结果记录 所属赛事 是否存在====
|
|
|
@@ -419,8 +470,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function setOdds(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
|
|
|
try {
|
|
|
//开启事务
|
|
|
@@ -439,7 +491,7 @@ class WriteSportsController extends BaseController{
|
|
|
//获取数据源
|
|
|
$source = $getData['source'];
|
|
|
//获取源数据联赛ID
|
|
|
- $s_lg_id = $getData['lg_id'];
|
|
|
+ $uuid = $getData['uuid'];
|
|
|
//获取源数据赛事ID
|
|
|
$s_match_id = $getData['match_id'];
|
|
|
//获取赔率所属赛事 tag 值 玩法数量
|
|
|
@@ -449,7 +501,7 @@ class WriteSportsController extends BaseController{
|
|
|
$gameName = gameModel::getGameName($game_code);
|
|
|
//验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
|
|
|
$models = commonFunction::getModels($game_code, 1);
|
|
|
- $lg_id = $this->leagueVerify($models,$s_lg_id,$source,$gameName);
|
|
|
+ $lg_id = $this->leagueVerify($models,$uuid,$source,$gameName);
|
|
|
$match_id = $this->matchVerify($models,$s_match_id,$source,$gameName);
|
|
|
|
|
|
//更新赛事 tag 值
|
|
|
@@ -521,9 +573,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function setOddsCH(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
-
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
try {
|
|
|
//开启事务
|
|
|
DB::beginTransaction();
|
|
|
@@ -551,32 +603,33 @@ class WriteSportsController extends BaseController{
|
|
|
// $odds_only = $getData['odds_only'];
|
|
|
|
|
|
//====验证 请求里 所有赔率 所属联赛 是否存在 ====
|
|
|
- //获取 当前请求 所有 lg_id
|
|
|
+ //获取 当前请求 所有 联赛 uuid
|
|
|
+ $uuids = [];
|
|
|
foreach($oddsData as $k=>$v){
|
|
|
- $s_lg_ids[] = $v['lg_id'];
|
|
|
+ $uuids[] = $v['uuid'];
|
|
|
}
|
|
|
- $s_lg_ids = array_unique($s_lg_ids);
|
|
|
- sort($s_lg_ids);
|
|
|
+ $uuids = array_unique($uuids);
|
|
|
+ sort($uuids);
|
|
|
|
|
|
//更新赛事下所有 不在本次请求的赔率 状态
|
|
|
// $ret= OddsModel::upOddsStatus($models,'',$s_lg_ids,$source,$odds_only);
|
|
|
// if($ret != true) throw new \Exception(Response::generate($gameName,Response::ODDS_SOLE_ERR));
|
|
|
|
|
|
//获取 本地 已存在 联赛
|
|
|
- $l_lg_data = $models['model_local_league']::whereIn('others_lg_id',$s_lg_ids)->where('source',$source)->select('others_lg_id','lg_id')->get()->toArray();
|
|
|
+ $l_lg_data = $models['model_local_league']::whereIn('identity',$uuids)->select('identity','lg_id')->get()->toArray();
|
|
|
//二维数组去重
|
|
|
- $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'others_lg_id');
|
|
|
- //循环对比 请求lg_id->本地others_lg_id
|
|
|
+ $l_lg_data = commonFunction::uniquArrV2($l_lg_data,'identity');
|
|
|
+ //循环对比 请求uuid->本地uuid
|
|
|
foreach($l_lg_data as $k=>$v){
|
|
|
- foreach($s_lg_ids as $kk=> $s_lg_id){
|
|
|
- if($v['others_lg_id'] == $s_lg_id){
|
|
|
- unset($s_lg_ids[$kk]);
|
|
|
+ foreach($uuids as $kk=> $uuid){
|
|
|
+ if($v['identity'] == $uuid){
|
|
|
+ unset($uuids[$kk]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
|
|
|
- if(!empty($s_lg_ids)) throw new \Exception(Response::generate($gameName.'冠军联赛:lg_id-'.$s_lg_ids[0].';',Response::LEAGUE_ERROR));
|
|
|
+ if(!empty($uuids)) throw new \Exception(Response::generate($gameName.'冠军联赛:uuid-'.$uuids[0].';',Response::LEAGUE_ERROR));
|
|
|
//====end====
|
|
|
//拼装 待写入 赔率数据
|
|
|
foreach($oddsData as $k=>$v){
|
|
|
@@ -632,9 +685,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function setBroadCast(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
-
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
try {
|
|
|
//开启事务
|
|
|
DB::beginTransaction();
|
|
|
@@ -682,11 +735,11 @@ class WriteSportsController extends BaseController{
|
|
|
/*
|
|
|
* 验证所属 联赛 是否存在
|
|
|
*/
|
|
|
- public function leagueVerify($models=[],$s_lg_id='',$source='',$gameName=''){
|
|
|
- if(empty($models) || empty($s_lg_id)) throw new \Exception(Response::generate('',Response::ABNORMAL));
|
|
|
- $l_lg_id = $models['model_local_league']::where(['others_lg_id'=>$s_lg_id,'source'=>$source])->value('lg_id');
|
|
|
+ public function leagueVerify($models=[],$uuid='',$source='',$gameName=''){
|
|
|
+ if(empty($models) || empty($uuid)) throw new \Exception(Response::generate('',Response::ABNORMAL));
|
|
|
+ $l_lg_id = $models['model_local_league']::where(['identity'=>$uuid])->value('lg_id');
|
|
|
|
|
|
- if($l_lg_id < 1) throw new \Exception(Response::generate($gameName.'联赛:lg_id-'.$s_lg_id,Response::LEAGUE_ERROR));
|
|
|
+ if($l_lg_id < 1) throw new \Exception(Response::generate($gameName.'联赛:lg_id-'.$uuid,Response::LEAGUE_ERROR));
|
|
|
return $l_lg_id;
|
|
|
}
|
|
|
|
|
|
@@ -937,8 +990,9 @@ class WriteSportsController extends BaseController{
|
|
|
public function upMatch(Req $data){
|
|
|
//验证token
|
|
|
$user = new \App\Models\System_user;
|
|
|
+ if(empty($data->token)) return Response::generate('未获取到token',Response::TOKEN_ERR);
|
|
|
$token = $user::where(['token'=>$data->token])->value('token');
|
|
|
- if(empty($token)) return Response::generate('',Response::TOKEN_ERR);
|
|
|
+ if(empty($token)) return Response::generate('token验证不通过',Response::TOKEN_ERR);
|
|
|
|
|
|
try {
|
|
|
//开启事务
|