| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Jun.peng
- * Date: 2019/5/13
- * Time: 10:19
- */
- namespace App\Sports\Controller;
- use BaseController\Controller;
- use App\Sports\Model\St_area_country as St_area_countryModel;
- class WriteSports extends Controller{
- public function init() {
- $this->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;
- }
- }
|