commonFunction = C()->get('commonFunction'); } /** * 体育数据入库接口 */ public function setSports(){ $obt = $_REQUEST['data']; $data = $this->getAddData($obt); //验证二维数组内是否有空值 // foreach ($data['data'] as $v){ // if(in_array('', $v)) Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')); // } switch ($data['title']){ case 'area'://地区 $ret = $this->area($data['data']); break; case 'country'://国家 $ret = $this->country($data['data']); break; case 'league'://联赛 $ret = $this->league($data); break; case 'competition'://赛事 $ret = $this->competition($data); break; case 'odds'://赔率 $ret = $this->odds($data); break; case 'league_result'://联赛结果 $ret = $this->league_result($data); break; case 'competition_result'://赛事结果 $ret = $this->com_result($data); break; case 'competition_result_record'://赛事结果记录 $ret = $this->com_result_record($data); break; case 'odds_record'://赔率记录 $ret = $this->odds_record($data); break; default: Render([], '10007', lang('Tips','Sports')->get('abnormal')); } //写入成功 if($ret) Render([], '1', lang('Tips','Sports')->get('success')); //写入失败 Render([], '10010', lang('Tips','Sports')->get('HANDLE_ERRORS')); } //写入地区数据 public function area($opt = []){ $ret = lm('st_area','Sports')->insert($opt); return $ret; } //写入国家数据 public function country($opt = []){ $ret = lm('st_country','Sports')->insert($opt); return $ret; } //写入联赛数据 public function league($opt = []){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; if(empty($data['belong'])) Render([], '10013', lang('Tips','Sports')->get('country_error')); //获取联赛所属 国家/地区id $belong = St_area_countryModel::getID($data['belong']); $set_lg['area_id'] = $belong['area_id']; $set_lg['country_id'] = $belong['country_id']; //查询是否 已存在 $post = lm($model['model_league'],'Sports') ->select('id as m_lg_id') ->where('name_chinese','=',$data['name_chinese']) ->first(); $m_lg_id = $post->m_lg_id; //如果不存在,则写入联赛表 if(empty($m_lg_id)){ $set_lg['name_chinese'] = $data['name_chinese']; $set_lg['kind'] = $data['kind']; $set_lg['match_mode'] = $data['match_mode']; $set_lg['if_stop'] = $data['if_stop']; $set_lg['last_time'] = $data['last_time']; $ret = lm($model['model_league'],'Sports')->insertGetId($set_lg); $m_lg_id = $ret; if($m_lg_id < 1) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } //查询关联表是否 记录 $local_r = lm($model['model_local_league'],'Sports') ->where(['m_lg_id'=>$m_lg_id,'lg_id'=>$data['lg_id'],'source'=>$data['source']]) ->count('*'); //没有记录则插入 if($local_r == 0){ $set_local = [ 'm_lg_id'=>$m_lg_id, 'lg_id'=>$data['lg_id'], 'source'=>$data['source'], ]; $ret = lm($model['model_local_league'],'Sports')-> insertGetId($set_local); if($ret < 1) Render([], '10017', lang('Tips','Sports')->get('local_league_error')); } Render([], '1', lang('Tips','Sports')->get('success')); } //弃用 public function __league($opt = []){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证联赛所属国家 if(!empty($data['country_id'])){ $country = lm('st_country','Sports') ->where(['country_id'=>$data['country_id']]) ->count(); if($country < 1) Render([], '10013', lang('Tips','Sports')->get('country_error')); } //验证联赛所属地区 if(!empty($data['area_id'])){ $area = lm('st_area','Sports') ->where(['id'=>$data['area_id']]) ->count(); if($area < 1) Render([], '10014', lang('Tips','Sports')->get('area_error')); } $post = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_league'],'Sports') -> where(['lg_id'=>$data['lg_id']]) -> update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_league'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } //写入赛事数据 public function competition($opt = []){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证赛事所属联赛 if(!empty($data['lg_id'])){ $lg = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error')); } $post = lm($model['model_match'],'Sports') ->where(['match_id'=>$data['match_id']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_match'],'Sports') -> where(['match_id'=>$data['match_id']]) -> update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_match'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } //写入赔率数据 public function odds($opt){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证赔率所属赛事 if(!empty($data['match_id'])){ $match = lm($model['model_match'],'Sports') ->where(['match_id'=>$data['match_id']]) ->count(); if($match < 1) Render([], '10016', lang('Tips','Sports')->get('match_error')); } //验证赔率所属联赛 冠军盘口 if(!empty($data['lg_id'])){ $lg = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error')); } $post = lm($model['model_odds'],'Sports') ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_odds'],'Sports') ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']]) -> update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_odds'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } //写入联赛结果 public function league_result($opt){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证结果所属联赛 if(!empty($data['lg_id'])){ $lg = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error')); } $post = lm($model['model_league_result'],'Sports') ->where(['lg_id'=>$data['lg_id'],'game_name'=>$data['game_name']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_league_result'],'Sports') ->where(['lg_id'=>$data['lg_id'],'game_name'=>$data['game_name']]) -> update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_league_result'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } //写入赛事结果 public function com_result($opt){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证结果所属联赛 if(!empty($data['lg_id'])){ $lg = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error')); } //验证结果所属赛事 if(!empty($data['match_id'])){ $lg = lm($model['model_match'],'Sports') ->where(['match_id'=>$data['match_id']]) ->count(); if($lg < 1) Render([], '10016', lang('Tips','Sports')->get('match_error')); } $post = lm($model['model_result'],'Sports') ->where(['match_id'=>$data['match_id']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_result'],'Sports') -> where(['match_id'=>$data['match_id']]) -> update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_result'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } //写入赛事结果记录 public function com_result_record($opt){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证结果所属联赛 if(!empty($data['lg_id'])){ $lg = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error')); } //验证结果所属赛事 if(!empty($data['match_id'])){ $lg = lm($model['model_match'],'Sports') ->where(['match_id'=>$data['match_id']]) ->count(); if($lg < 1) Render([], '10016', lang('Tips','Sports')->get('match_error')); } $post = lm($model['model_result_record'],'Sports') ->where(['match_id'=>$data['match_id'],'match_time'=>$data['match_time']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_result_record'],'Sports') ->where(['match_id'=>$data['match_id'],'match_time'=>$data['match_time']]) -> update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_result_record'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } //写入赔率记录 public function odds_record($opt){ $game_code = $opt['game_code']; //根据球类代码获取相关model $model = $this->commonFunction->getModels($game_code,1); $data = $opt['data']; // foreach ($opt['data'] as $k => $v){ //验证赔率所属赛事 if(!empty($data['match_id'])){ $match = lm($model['model_match'],'Sports') ->where(['match_id'=>$data['match_id']]) ->count(); if($match < 1) Render([], '10016', lang('Tips','Sports')->get('match_error')); } //验证赔率所属联赛 冠军盘口 if(!empty($data['lg_id'])){ $lg = lm($model['model_league'],'Sports') ->where(['lg_id'=>$data['lg_id']]) ->count(); if($lg < 1) Render([], '10015', lang('Tips','Sports')->get('league_error')); } $post = lm($model['model_odds_record'],'Sports') ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']]) ->count(); //更新操作 if($post > 0){ $ret = lm($model['model_odds_record'],'Sports') ->where(['match_id'=>$data['match_id'],'odds_code'=>$data['odds_code'],'sort'=>$data['sort']]) ->update($data); if($ret < 1) Render([], '10011', lang('Tips','Sports')->get('update_error')); }else{ //写入操作 $ret = lm($model['model_odds_record'],'Sports')->insert($data); if($ret != true) Render([], '10012', lang('Tips','Sports')->get('insert_error')); } // } Render([], '1', lang('Tips','Sports')->get('success')); } /** * @param $data * @return mixed * json转数组 */ public function getAddData($data){ $data = json_decode($data,true); return $data; } }