| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Jun.peng
- * Date: 2019/5/13
- * Time: 10:19
- */
- namespace App\Http\Controllers\Api;
- use Illuminate\Routing\Controller as BaseController;
- use App\Http\Response\Response;
- use Illuminate\Http\Request as Req;
- use Illuminate\Support\Facades\DB;
- use App\Lib\Biz\Sport\Common as commonFunction;
- use App\Http\Model\StBqResult as BqResultModel;
- use App\Http\Model\StBroadcast as broadcastModel;
- use App\Http\Model\StGameType as gameModel;
- use App\Http\Model\StLqResult as LqResultModel;
- use App\Http\Model\StWqResult as WqResultModel;
- use App\Http\Model\StZqLocalLeague as LeagueModel;
- 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;
- /**
- * 体育数据入库接口
- */
- class WriteSportsController extends BaseController{
- public function setSports(Req $data){
- try {
- //开启事务
- DB::beginTransaction();
- if($data->game_code){
- //用于后台 将所有进行中的赛事写入结果
- $this->match_result($data->game_code);
- }//写赛事数据
- $obt = $data->data;
- if($obt){
- $getData = $this->getAddData($obt);
- $league = [];
- $competition = [];
- $odds = [];
- $league_result = [];
- $match_result = [];
- $match_result_record = [];
- $odds_record = [];
- $broadcast = [];
- //指定排序 联赛->赛事->赔率->联赛结果->赛事结果->赛事结果记录->赔率记录->直播数据
- foreach ($getData as $k=>$v){
- $game_code = $v['game_code'];
- if($v['title'] == 'league') $league[] = $v;
- if($v['title'] == 'competition') $competition[] = $v;
- if($v['title'] == 'odds') $odds[] = $v;
- if($v['title'] == 'league_result') $league_result[] = $v;
- if($v['title'] == 'match_result') $match_result[] = $v;
- if($v['title'] == 'match_result_record') $match_result_record[] = $v;
- if($v['title'] == 'odds_record') $odds_record[] = $v;
- if($v['title'] == 'broadcast') $broadcast[] = $v;
- }
- $matchData = [$league,$competition,$odds,$league_result,$match_result,$match_result_record,$odds_record,$broadcast];
- //排空处理
- foreach ($matchData as $k=>$v){
- if($v == []) unset($matchData[$k]);
- }
- sort($matchData);
- //根据顺序写入数据
- //降维数据
- $mentData = [];
- foreach ($matchData as $k=>$v){
- foreach ($v as $kk=>$vv){
- $mentData[] = $vv;
- }
- }
- //获取各球类model
- $models = commonFunction::getModels($game_code,1);
- //获取球类名称
- $gameName = gameModel::getGameName($game_code);
- //===获取验证数据===
- //获取一段时间内所有联赛本地记录
- $lg_data = LeagueModel::getLeagueID($models);
- //获取一段时间内所有赛事本地记录
- $match_data = MatchModel::getMatchID($models);
- //获取一段时间内所有赔率
- $odds_data = OddsModel::getOddsID($models);
- //获取一段时间内所有赔率记录
- $odds_record_data = OddsRecordModel::getOddsRecordID($models);
- //===获取验证数据===
- $others_lg_id = '';//继承 源联赛id
- $others_match_id = '';//继承 源赛事id
- $s_lg_id = '';//源 联赛ID
- $l_lg_id = '';//本地 联赛 ID
- $s_match_id = '';//源 赛事ID
- $l_match_id = '';//本地 赛事 ID
- foreach ($mentData as $kk =>$vv){
- switch ($vv['title']){
- case 'area'://地区
- throw new \Exception(Response::generate('地区数据-area:',Response::AUTH_ERROR)) ;
- break;
- case 'country'://国家
- throw new \Exception(Response::generate('国家数据-country:',Response::AUTH_ERROR));
- break;
- case 'league'://联赛
- $others_lg_id = $vv['data']['lg_id'];
- $s_lg_id = $vv['data']['lg_id'];
- $source = $vv['data']['source'];
- //验证联赛记录是否已存在
- $ret_lg = commonFunction::ver_league($s_lg_id,$source,$lg_data);
- if($ret_lg != false) {
- $l_lg_id = $ret_lg;
- break;
- }
- //执行 联赛数据
- $lg_data = $this->league($vv,$gameName);
- $l_lg_id = $lg_data['lg_id'];
- break;
- case 'competition'://赛事
- $others_match_id = $vv['data']['match_id'];
- $s_lg_id = $vv['data']['lg_id'];
- $s_match_id = $vv['data']['match_id'];
- $source = $vv['data']['source'];
- //本次请求是否包含 联赛数据
- if(empty($others_lg_id)){
- //验证本地是否存在
- $ret_lg = commonFunction::ver_league($s_lg_id,$source,$lg_data);
- if($ret_lg == false) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$s_lg_id.';',Response::LEAGUE_ERROR));
- $l_lg_id = $ret_lg;
- }else{
- //本次有 联赛数据 验证属于同联赛
- if($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$s_lg_id.';',Response::LEAGUE_ERROR));
- }
- //验证赛事记录是否已存在
- $ret_match = commonFunction::ver_match($s_match_id,$source,$match_data);
- if($ret_match != false){
- $l_match_id = $ret_match;
- break;
- }
- //执行 赛事数据
- $match_data = $this->competition($vv,$gameName,$l_lg_id);
- $l_match_id = $match_data['match_id'];
- break;
- case 'odds'://赔率
- $s_lg_id = $vv['data']['lg_id'];
- $s_match_id = $vv['data']['match_id'];
- $source = $vv['data']['source'];
- $odds_only = $vv['data']['odds_only'];
- $sole = $vv['data']['sole'];
- $odds_type = $vv['data']['type'];//0普通 1冠军盘口
- //本次请求是否包含 联赛数据
- if(empty($others_lg_id)){
- //无联赛数据 验证本地是否存在
- $ret_lg = commonFunction::ver_league($s_lg_id,$source,$lg_data);
- //联赛 不存在
- if($ret_lg == false) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$s_lg_id.';',Response::LEAGUE_ERROR));
- $l_lg_id = $ret_lg;
- }else{
- //有联赛数据 验证属于同请求联赛
- if($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$s_lg_id.';',Response::LEAGUE_ERROR));
- }
- //如果是普通 赔率,则验证所属赛事
- if($odds_type == 0){
- //验证赛事记录是否已存在
- if(empty($others_match_id)){
- //无赛事数据 验证本地是否存在
- $ret_match = commonFunction::ver_match($s_match_id,$source,$match_data);
- //赛事 不存在
- if($ret_match == false) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$s_match_id.';',Response::MATCH_ERROR));
- $l_match_id = $ret_match;
- }else{
- //有赛事数据 验证属于同请求赛事
- if($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$s_match_id.';',Response::MATCH_ERROR));
- }
- }
- //验证赔率 是否存在
- $ret_odds = '';
- $ret_odds = commonFunction::ver_odds($sole,$source,$odds_data);
- //验证赔率记录 是否存在
- $ret_odds_record = '';
- $ret_odds_record = commonFunction::ver_odds_record($odds_only,$source,$odds_record_data);
- $this->odds($vv,$gameName,$l_lg_id,$l_match_id,$ret_odds,$ret_odds_record);
- break;
- case 'league_result'://联赛结果
- $this->league_result($vv);
- break;
- case 'match_result'://赛事结果
- throw new \Exception(Response::generate('赛事结果数据-match_result:',Response::AUTH_ERROR));
- $this->match_result($vv);
- break;
- case 'match_result_record'://赛事结果记录
- $s_lg_id = $vv['data']['lg_id'];
- $s_match_id = $vv['data']['match_id'];
- $source = $vv['data']['source'];
- //如果本次请求没有 联赛数据
- if(empty($others_lg_id)){
- //验证本地是否存在
- $ret_lg = commonFunction::ver_league($s_lg_id,$source,$lg_data);
- //联赛 不存在
- if($ret_lg == false) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$s_lg_id.';',Response::LEAGUE_ERROR));
- $l_lg_id = $ret_lg;
- }else{
- //有联赛数据 验证属于同请求联赛
- if($s_lg_id != $others_lg_id) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$s_lg_id.';',Response::LEAGUE_ERROR));
- }
- //验证赛事记录是否已存在
- if(empty($others_match_id)){
- //无赛事数据 验证本地是否存在
- $ret_match = commonFunction::ver_match($s_match_id,$source,$match_data);
- //联赛 不存在
- if($ret_match == false) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$s_match_id.';',Response::MATCH_ERROR));
- $l_match_id = $ret_match;
- }else{
- //有赛事数据 验证属于同请求赛事
- if($s_match_id != $others_match_id) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$s_match_id.';',Response::MATCH_ERROR));
- }
- //处理 赛事结果 记录
- $this->com_result_record($vv,$gameName,$l_lg_id,$l_match_id);
- break;
- case 'odds_record'://赔率记录
- throw new \Exception(Response::generate('赔率记录数据-odds_record:',Response::AUTH_ERROR));
- $this->odds_record($vv);
- break;
- case 'broadcast'://直播数据
- $this->broadcast($vv,$game_code);
- break;
- default:
- throw new \Exception(Response::generate('',Response::ABNORMAL)) ;
- }
- }
- }
- //提交事务
- DB::commit();
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- return $e->getMessage();
- }
- }
- /**
- * @param Req $data
- * @return string
- * @throws \App\Lib\Biz\Sport\Exception
- * 更新赛事状态
- */
- public function upMatch(Req $data){
- try {
- //开启事务
- DB::beginTransaction();
- //获取待更新赛事
- $obt = $data->data;
- if($obt){
- //json转数组
- $data = $this->getAddData($obt);
- //获取所有数据源赛事 match_id
- $others_match_ids = [];
- foreach ($data as $k=>$v){
- $game_code = $v['game_code'];
- $source = $v['source'];
- $others_match_ids[] = $v['match_id'];
- }
- //根据球类代码 获取model
- $model =commonFunction::getModels($game_code,1);
- //获取所有赛事 match_id
- $local_match = $model['model_local_match']::SELECT('others_match_id','match_id')
- ->where(['source'=>$source])
- ->whereIn('others_match_id',$others_match_ids)
- ->get()->toArray();
- if(empty($local_match)) throw new \Exception(Response::generate('',Response::MATCHID_NULL));
- //更新状态字段
- $set_status = ['status'=>2];
- foreach ($local_match as $k=>$v){
- $ret = $model['model_match']::where(['id'=>$v['match_id']])
- -> update($set_status);
- if($ret<1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$v['others_match_id'],Response::UPSTATUS_ERROR));
- }
- }
- //提交事务
- DB::commit();
- return Response::success();
- } catch (\Exception $e) {
- //回滚事务
- DB::rollBack();
- return $e->getMessage();
- }
- }
- //写入直播 数据
- public function broadcast($opt = [],$game_code=''){
- $data = $opt['data'];
- $set_broadcast = [
- "doing" => $data['doing'],
- "game_type" => $data['game_type'],
- "game_code" => $game_code,
- "guest_team" => $data['guest_team'],
- "host_team" => $data['host_team'],
- "league_name" => $data['league_name'],
- "shower" => $data['shower'],
- "showid" => (int)$data['showid'],
- "start_time" => $data['start_time'],
- "ctime" =>date('Y-m-d H:i:s'),
- "utime" =>date('Y-m-d H:i:s'),
- ];
- $ret = broadcastModel::insert($set_broadcast);
- if($ret == false) throw new \Exception(Response::generate('',Response::BROADCAST_ERROR));
- }
- //将进行中赛事写入 赛事结果
- public function match_result($game_code = ''){
- $model =commonFunction::getModels($game_code,1);
- if($game_code == 'zq') ZqResultModel::ZQresult($model);
- if($game_code == 'lq') LqResultModel::LQresult($model);
- if($game_code == 'wq') WqResultModel::WQresult($model);
- if($game_code == 'bq') BqResultModel::BQresult($model);
- }
- //写入地区数据 弃用
- 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 = [],$gameName=''){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model =commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- // if(empty($data['belong'])) throw new \Exception(Response::generate(Response::COUNTRY_ERROR)) ;//Render([], '10013', lang('Tips','Sports')->get('country_error'));
- // //获取联赛所属 国家/地区id
- // $belong = St_area_countryModel::getID($data['belong']);
- $set_lg['area_id'] = 0;//$belong['area_id'];
- $set_lg['country_id'] = 0;// $belong['country_id'];
- //查询联赛是否已存在
- $id = $model['model_league']::where('name_chinese','=',$data['name_chinese'])
- ->value('id');
- //默认获取本年最后一天
- $last_time = date('Y-12-31 23:59:59');
- //决赛时间
- if($data['last_time']){
- $last_time = $data['last_time'];
- }
- $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['identity'] = $data['uuid'];
- $set_lg['last_time'] = $last_time;
- $set_lg['utime'] = date('Y-m-d H:i:s');
- if(empty($id)){
- //写入联赛
- $id = $model['model_league']::insertGetId($set_lg);
- $m_lg_id = $id;
- if($m_lg_id < 1) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$data['lg_id'].';',Response::INSERT_ERROR));
- }else{
- //更新联赛
- $ret = $model['model_league']::where(['id'=>$id])
- -> update($set_lg);
- if($ret < 1) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$data['lg_id'].';',Response::UPDATE_ERROR));
- }
- $set_local = [
- 'lg_id'=>$id,
- 'others_lg_id'=>$data['lg_id'],
- 'source'=>$data['source'],
- 'ctime'=>date('Y-m-d H:i:s')
- ];
- $ret = $model['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'));
- //执行成功返回源数据 联赛ID
- $data = ['others_lg_id'=>$data['lg_id'],'lg_id'=>$id];
- return $data;
- }
- //写入赛事数据
- public function competition($opt = [],$gameName='',$lg_id=''){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- if(empty($data['lg_id'])) throw new \Exception(Response::generate('',Response::LEAGUE_ERROR)) ;//Render([], '10015', lang('Tips','Sports')->get('league_error'));
- //查询赛事是否存在
- $id = $model['model_match']::where(['home_team'=>$data['home_team'],'guest_team'=>$data['guest_team'],'match_date'=>$data['match_date'],'match_time'=>$data['match_time']])
- ->value('id');
- $half_match_id = 0;
- //如果有上半场赛事id 获取上半场赛事是否存在
- if(!empty($data['half_match_id'])){
- $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id'=>$data['half_match_id'],'source'=>$data['source']])
- ->value('match_id');
- if(empty($half_match_id)) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::HALF_MATCH_ERROR)) ;//Render([], '10024', lang('Tips','Sports')->get('half_match_error'));
- }
- //如果赛事没有开始日期,则为冠军盘口赛事
- if(empty($data['match_date'])){
- //冠军盘口赛事获取所属联赛结束时间
- $last_time = $model['model_league']::where(['id'=>$lg_id])
- ->value('last_time');
- if(empty($last_time)) throw new \Exception(Response::generate($gameName.'联赛-lg_id:'.$data['lg_id'].';',Response::LG_LASTTIME_ERROR)) ;//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
- //给冠军盘口赛事 赋值时间
- $time = strtotime($last_time);
- $data['match_date'] = date('Y-m-d',$time);
- $data['match_time'] = date('H:i:s',$time);
- }
- $set_match = [
- 'ctime'=>date('Y-m-d H:i:s'),
- 'utime'=>date('Y-m-d H:i:s'),
- 'expire_time'=>date('Y-m-d H:i:s',time()+60),
- 'home_team'=>$data['home_team']?:'',
- 'guest_team'=>$data['guest_team']?:'no_team',
- 'lg_id'=>$lg_id,
- 'status'=>$data['status'],
- 'match_date'=>$data['match_date']?:date('Y-m-d'),
- 'match_time'=>$data['match_time']?:date('H:i:s'),
- 'tag'=>$data['tag']?:0,
- 'is_rollball'=>$data['is_rollball']?:0,
- 'is_today'=>$data['is_today']?:0,
- 'is_morningplate'=>$data['is_morningplate']?:0,
- 'is_stringscene'=>$data['is_stringscene']?:0,
- 'us_time'=>$data['us_time']?:commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
- 'half_match_id'=>$half_match_id?:0,
- 'identity' => $data['uuid'],
- ];
- //写入赛事
- if(empty($id)){
- //写入赛事 返回id
- $id = $model['model_match']::insertGetId($set_match);
- if($id < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::INSERT_ERROR)) ;
- }else{
- //更新赛事
- $ret = $model['model_match']::where(['id'=>$id])->update($set_match);
- if($ret < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::UPDATE_ERROR)) ;
- }
- //写关联记录
- $set_local = [
- 'match_id'=>$id,
- 'others_match_id'=>$data['match_id'],
- 'source'=>$data['source'],
- 'ctime'=>date('Y-m-d H:i:s')
- ];
- $ret = $model['model_local_match']::insertGetId($set_local);
- if($ret < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::LOCAL_MATCH_ERROR)) ;//Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
- //返回 源数据 赛事ID
- $data = ['others_match_id'=>$data['match_id'],'match_id'=>$id];
- return $data;
- }
- //写入赔率数据
- public function odds($opt=[],$gameName='',$lg_id=0,$match_id=0,$oddsID='',$oddsRecordID=''){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- //获取赛事 本地/源ID
- $others_match_id = $data['match_id'];
- //获取联赛 本地/源ID
- $others_lg_id = $data['lg_id'];
- //===写赔率记录===
- $set_odds_r = [
- 'match_id'=> $match_id?:0,
- 'others_match_id'=> $others_match_id?:0,
- 'odds_code'=> $data['odds_code']?:'',
- 'status'=> $data['status']?:0,
- 'sort'=> $data['sort']?:0,
- 'p_code'=> $data['p_code']?:'',
- 'odds'=> $data['odds']?:0,
- 'condition'=> $data['condition'],
- 'odds_only'=> $data['odds_only']?:'',
- 'source'=> $data['source']?:'',
- 'type'=> $data['type']?:0,
- 'team'=> $data['team']?:'',
- 'lg_id'=> $lg_id,
- 'others_lg_id'=> $others_lg_id,
- 'ctime'=> date('Y-m-d H:i:s'),
- ];
- //更新或写入赔率记录
- if($oddsRecordID != false){
- $ret = $model['model_odds_record']::where(['id'=>$oddsRecordID])
- -> update($set_odds_r);
- if($ret < 1) throw new \Exception(Response::generate($gameName.'赔率记录-odds_only:'.$data['odds_only'].';',Response::ADD_ODDS_R_ERROR)) ;//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
- }else{
- $ret = $model['model_odds_record']::insert($set_odds_r);
- if($ret != true) throw new \Exception(Response::generate($gameName.'赔率记录-odds_only:'.$data['odds_only'].';',Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
- }
- //===写赔率===
- $set_odds = [
- 'match_id'=> $match_id?:0,
- 'others_match_id'=> $others_match_id?:0,
- 'odds_code'=> $data['odds_code']?:'',
- 'status'=> $data['status']?:0,
- 'sort'=> $data['sort']?:0,
- 'p_code'=> $data['p_code']?:'',
- 'odds'=> $data['odds']?:0,
- 'condition'=> $data['condition'],
- 'odds_only'=> $data['odds_only']?:'',
- 'sole'=> $data['sole']?:'',
- 'source'=> $data['source']?:'',
- 'type'=> $data['type']?:0,
- 'team'=> $data['team']?:'',
- 'lg_id'=> $lg_id,
- 'others_lg_id'=> $others_lg_id,
- 'ctime'=> date('Y-m-d H:i:s'),
- 'utime'=> date('Y-m-d H:i:s'),
- 'expire_time'=>date('Y-m-d H:i:s',time()+60),
- ];
- //更新或写入赔率数据
- if($oddsID != false){
- $ret = $model['model_odds']::where(['id'=>$oddsID])
- -> update($set_odds);
- if($ret < 1) throw new \Exception(Response::generate($gameName.'赔率-odds_only:'.$data['odds_only'].';',Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
- }else{
- $ret = $model['model_odds']::insert($set_odds);
- if($ret != true) throw new \Exception(Response::generate($gameName.'赔率-odds_only:'.$data['odds_only'].';',Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
- }
- //===end===
- }
- //写入联赛结果
- public function league_result($opt){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- //验证结果所属联赛
- $lg_id = $model['model_local_league']::where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
- ->value('lg_id');
- if($lg_id < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'联赛-lg_id:'.$data['lg_id'].';',Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
- $lg_result_id = $model['model_league_result']::where(['lg_id'=>$lg_id,'game_name'=>$data['game_name']])
- ->value('id');
- $set_lg_result = [
- 'lg_id'=>$lg_id,
- 'game_name'=>$data['game_name'],
- 'result'=>json_encode($data['result'],JSON_UNESCAPED_UNICODE),
- 'status'=>$data['status'],
- 'ctime'=> date('Y-m-d H:i:s'),
- 'utime'=> date('Y-m-d H:i:s'),
- ];
- //联赛结果数据处理
- if(!empty($lg_result_id)){
- $ret = $model['model_league_result']::where(['id'=>$lg_result_id])
- -> update($set_lg_result);
- if($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'联赛-lg_id:'.$data['lg_id'].';',Response::ADD_LG_R_ERROR)) ;//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
- }else{
- $ret = $model['model_league_result']::insert($set_lg_result);
- if($ret != true) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'联赛-lg_id:'.$data['lg_id'].';',Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
- }
- // return Response::success();
- }
- //写入赛事结果
- public function com_result($opt=[],$gameName='',$lg_id='',$match_id=''){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- // //验证结果所属联赛
- // $lg_id = $model['model_local_league']::where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
- // ->value('lg_id');
- // if($lg_id < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'联赛-lg_id:'.$data['lg_id'].';',Response::LEAGUE_ERROR)) ;//Render([], '10015', lang('Tips','Sports')->get('league_error'));
- // //验证结果所属赛事
- // $match_id = $model['model_local_match']::where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
- // ->value('match_id');
- // if($match_id < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$data['match_id'].';',Response::MATCH_ERROR));//Render([], '10016', lang('Tips','Sports')->get('match_error'));
- //查询结果是否存在
- $match_r_id = $model['model_result']::where(['match_id'=>$match_id])
- ->value('id');
- $set_match_r = [
- "home_team"=>$data['home_team'],
- "guest_team"=>$data['guest_team'],
- "lg_id"=>$lg_id,
- "home_rate"=> $data['home_rate'],
- "guest_rate"=> $data['guest_rate'],
- "home_score"=> $data['home_score'],
- "guest_score"=> $data['guest_score'],
- "all_goal"=> $data['all_goal'],
- "status"=>$data['status'],
- "first_score"=>$data['first_score'],
- "last_score"=> $data['last_score'],
- "match_score"=> $data['match_score'],
- "match_winer"=> $data['match_winer'],
- "match_time"=> $data['match_time'],
- "match_process"=> $data['match_process'],
- "tag"=> $data['tag'],
- "match_id"=> $match_id,
- "u_home_score"=> $data['u_home_score'],
- "u_guest_score"=> $data['u_guest_score'],
- "p_code"=> $data['p_code'],
- "update_time"=>date('Y-m-d H:i:s')
- ];
- //赛事结果数据处理
- if(!empty($match_r_id)){
- $ret = $model['model_result']::where(['id'=>$match_r_id])
- -> update($set_match_r);
- if($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$data['match_id'].';',Response::ADD_MATCH_R_ERROR)) ;//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
- }else{
- $ret = $model['model_result']::insert($set_match_r);
- if($ret != true) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$data['match_id'].';',Response::ADD_MATCH_R_ERROR)) ;//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
- }
- // return Response::success();
- }
- //写入赛事结果记录
- public function com_result_record($opt=[],$gameName='',$lg_id='',$match_id=''){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- //验证结果所属联赛
- // $lg_id = $model['model_local_league']::where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
- // ->value('lg_id');
- // if($lg_id < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'联赛-lg_id:'.$data['lg_id'].';',Response::LEAGUE_ERROR)) ;//Render([], '10015', lang('Tips','Sports')->get('league_error'));
- // //验证结果所属赛事
- // $match_id = $model['model_local_match']::where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
- // ->value('match_id');
- // if($match_id < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$data['match_id'].';',Response::MATCH_ERROR));//Render([], '10016', lang('Tips','Sports')->get('match_error'));
- $match_r_id = $model['model_result_record']::where(['match_id'=>$match_id,'match_time'=>$data['match_time']])
- ->value('id');
- //根据球类 获取 赛事结果记录字段
- $set_match_r = $this->get_match_r($game_code,$lg_id,$match_id,$data);
- //赛事结果记录处理
- if($match_r_id > 0){
- $ret = $model['model_result_record']::where(['id'=>$match_r_id])
- ->update($set_match_r);
- if($ret < 1) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
- }else{
- $ret = $model['model_result_record']::insert($set_match_r);
- if($ret != true) throw new \Exception(Response::generate($gameName.'赛事-match_id:'.$data['match_id'].';',Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
- }
- }
- //写入赔率记录
- public function odds_record($opt){
- $game_code = $opt['game_code'];
- //根据球类代码获取相关model
- $model = commonFunction::getModels($game_code,1);
- $data = $opt['data'];
- $match = $model['model_local_match']::select('match_id','others_match_id')
- ->where(['others_match_id'=>$data['match_id'],'source'=>$data['source']])
- ->first();
- if(count($match) < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赛事-match_id:'.$data['match_id'].';',Response::MATCH_ERROR)) ;//Render([], '10016', lang('Tips','Sports')->get('match_error'));
- //获取赛事 本地/源ID
- $others_match_id = $match->others_match_id;
- $match_id = $match->match_id;
- $lg = $model['model_local_league']::select('lg_id','others_lg_id')
- ->where(['others_lg_id'=>$data['lg_id'],'source'=>$data['source']])
- ->first();
- if(count($lg) < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'联赛-lg_id:'.$data['lg_id'].';',Response::LEAGUE_ERROR)) ;//Render([], '10015', lang('Tips','Sports')->get('league_error'));
- //获取联赛 本地/源ID
- $others_lg_id = $lg->others_lg_id;
- $lg_id = $lg->lg_id;
- //查询 赔率数据是否存在
- $oddsID = $model['model_odds_record']::where(['odds_only'=>$data['odds_only']])
- ->value('id');
- $set_odds = [
- 'match_id'=> $match_id,
- 'others_match_id'=> $others_match_id,
- 'odds_code'=> $data['odds_code'],
- 'status'=> $data['status'],
- 'sort'=> $data['sort'],
- 'p_code'=> $data['p_code'],
- 'odds'=> $data['odds'],
- 'condition'=> $data['condition'],
- 'odds_only'=> $data['odds_only'],
- 'source'=> $data['source'],
- 'type'=> $data['type'],
- 'team'=> $data['team'],
- 'lg_id'=> $lg_id,
- 'others_lg_id'=> $others_lg_id,
- 'ctime'=> date('Y-m-d H:i:s'),
- 'utime'=> date('Y-m-d H:i:s'),
- ];
- //更新或写入赔率记录
- if(!empty($oddsID)){
- $ret = $model['model_odds_record']::where(['id'=>$oddsID])
- -> update($set_odds);
- if($ret < 1) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赔率记录-odds_only:'.$data['odds_only'].';',Response::ADD_ODDS_R_ERROR)) ;//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
- }else{
- $ret = $model['model_odds_record']::insert($set_odds);
- if($ret != true) throw new \Exception(Response::generate(gameModel::getGameName($game_code).'赔率记录-odds_only:'.$data['odds_only'].';',Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
- }
- // return Response::success();
- }
- /**
- * @param $data
- * @return mixed
- * json转数组
- */
- public function getAddData($data){
- $data = json_decode($data,true);
- return $data;
- }
- //根据球类获取 赛事结果记录字段
- public function get_match_r($game_code,$lg_id,$match_id,$data){
- $set_match_r = [];
- if($game_code == 'zq'){
- $set_match_r = [
- "home_team"=>$data['home_team']?:'',
- "guest_team"=>$data['guest_team']?:'',
- "lg_id"=>$lg_id,
- "all_goal"=>$data['all_goal']?:0,
- "home_rate"=> $data['home_rate']?:0,
- "guest_rate"=> $data['guest_rate']?:0,
- "home_score"=> $data['home_score']?:0,
- "guest_score"=> $data['guest_score']?:0,
- "status"=>$data['status']?:0,
- "first_score"=>$data['first_score']?:0,
- "last_score"=> $data['last_score']?:0,
- "match_score"=> $data['match_score']?:0,
- "match_winer"=> $data['match_winer']?:'',
- "match_time"=> $data['match_time']?:0,
- "match_process"=> $data['match_process']?:'',
- "tag"=> $data['tag']?:0,
- "match_id"=> $match_id,
- "update_time"=>date('Y-m-d H:i:s')
- ];
- };
- if($game_code == 'lq'){
- $set_match_r = [
- "home_team"=>$data['home_team']?:'',
- "guest_team"=>$data['guest_team']?:'',
- "lg_id"=>$lg_id,
- "home_rate"=> $data['home_rate']?:0,
- "guest_rate"=> $data['guest_rate']?:0,
- "home_score"=> $data['home_score']?:0,
- "guest_score"=> $data['guest_score']?:0,
- "status"=>$data['status']?:0,
- "first_score"=>$data['first_score']?:0,
- "last_score"=> $data['last_score']?:0,
- "match_score"=> $data['match_score']?:0,
- "match_winer"=> $data['match_winer']?:'',
- "match_time"=> $data['match_time']?:0,
- "match_process"=> $data['match_process']?:'',
- "tag"=> $data['tag']?:0,
- "match_id"=> $match_id,
- "update_time"=>date('Y-m-d H:i:s')
- ];
- }
- if($game_code == 'wq'){
- $set_match_r = [
- "home_player_name"=>$data['home_player_name']?:'',
- "guest_player_name"=>$data['guest_player_name']?:'',
- "lg_id"=>$lg_id,
- "home_player_let_plate"=>$data['home_player_let_plate']?:0,
- "guest_player_let_plate"=>$data['guest_player_let_plate']?:0,
- "home_player_let_inning"=>$data['home_player_let_inning']?:0,
- "guest_player_let_inning"=>$data['guest_player_let_inning']?:0,
- "all_inning"=>$data['all_inning']?:0,
- "home_player_score"=>$data['home_player_score']?:0,
- "guest_player_score"=>$data['guest_player_score']?:0,
- "status"=>$data['status']?:0,
- "first_score_player"=>$data['first_score_player']?:'',
- "last_score_player"=>$data['last_score_player']?:'',
- "first_inning_score"=>$data['first_inning_score']?:0,
- "second_inning_score"=>$data['second_inning_score']?:0,
- "third_inning_score"=>$data['third_inning_score']?:0,
- "match_winer_player"=>$data['match_winer_player']?:'',
- "update_time"=>date('Y-m-d H:i:s'),
- "match_time"=>$data['match_time']?:0,
- "match_process"=>$data['match_process']?:'',
- "tag"=>$data['tag']?:0,
- "match_id"=>$match_id,
- "result_mark" =>$data['result_mark']?:'',
- ];
- }
- if($game_code == 'bq'){
- $set_match_r = [
- "home_team"=>$data['home_team']?:'',
- "guest_team"=>$data['guest_team']?:'',
- "lg_id"=>$lg_id,
- "home_rate"=> $data['home_rate']?:0,
- "guest_rate"=> $data['guest_rate']?:0,
- "home_score"=> $data['home_score']?:0,
- "guest_score"=> $data['guest_score']?:0,
- "status"=>$data['status']?:0,
- "first_score"=>$data['first_score']?:0,
- "last_score"=> $data['last_score']?:0,
- "match_score"=> $data['match_score']?:0,
- "match_winer"=> $data['match_winer']?:'',
- "match_time"=> $data['match_time']?:0,
- "match_process"=> $data['match_process']?:'',
- "tag"=> $data['tag']?:0,
- "match_id"=> $match_id,
- "all_inning"=>$data['all_inning']?:9,
- "update_time"=>date('Y-m-d H:i:s'),
- "result_mark" =>$data['result_mark']?:'',
- ];
- }
- return $set_match_r;
- }
- }
|