| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <?php
- /**
- * Created by PhpStorm.
- * 获取不同球类默认赔率玩法
- * User: Jun.peng
- * Date: 2019/4/16
- * Time: 9:29
- */
- namespace Biz\Match;
- class GetOddsData {
- public function __construct() {
- $this->commonFunction = C()->get('commonFunction');
- }
- /**
- * 根据不同球类获取相关赔率数据
- */
- public function getOddsData($data,$whereDate,$source,$oddsTypeWhere=''){
- if($data['search']){
- $search = $data['search'];
- }
- //根据 球类代码 获取相关model
- $models = $this->commonFunction->getModels($data['game_code']);
- $model_league = $models['model_league'];
- $model_match = $models['model_match'];
- $model_odds = $models['model_odds'];
- $league = lm($model_league, 'Sports')
- ->select('id as lg_id','name_chinese')
- ->where(['id'=>$data['leagueID']])
- ->first();
- if(empty($league->lg_id)) throw new \Exception(Render([], '10003', lang('Tips','Sports')->get('PARAM_ERROR')));
- $matchData = lm($model_match, 'Sports')
- ->select('lg_id','id as match_id','tag','match_date','match_time','home_team','guest_team')
- ->where(['lg_id'=>$data['leagueID']])
- ->where($whereDate)
- ->where($model_match.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
- ->where('status','<',2)
- ->where($model_match.'.home_team','<>',null)
- ->where($model_match.'.guest_team','<>',null)
- ->where(function($query)use ($model_match,$search){
- $query->where($model_match.'.home_team','like','%'.$search.'%')
- ->orWhere(function($query)use ($model_match,$search) {
- $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
- });
- })
- ->get()->toArray();
- if(empty($matchData)) throw new \Exception(Render([], '10004', lang('Tips','Sports')->get('PARAM_ERROR')));
- if(empty($matchData)){
- Render([], '10006', lang('Tips','Sports')->get('empty'));
- }
- switch ($data['game_code']){
- case 'zq'://获取足球默认赔率数据
- $list = $this->getOddsZQ($matchData,$model_odds,$source,$oddsTypeWhere);
- break;
- case 'lq'://获取篮球默认赔率数据
- $list = $this->getOddsLQ($matchData,$model_odds,$source,$oddsTypeWhere);
- break;
- case 'wq'://获取网球默认赔率数据
- $list = $this->getOddsWQ($matchData,$model_odds,$source,$oddsTypeWhere);
- break;
- case 'bq'://获取棒球默认赔率数据
- $list = $this->getOddsBQ($matchData,$model_odds,$source,$oddsTypeWhere);
- break;
- default:
- throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- $data = [
- 'lg_id'=>$league->lg_id,
- 'leagueName'=>$league->name_chinese,
- 'matchNum'=>count($list) ,
- 'matchData'=>$list,
- ];
- return $data;
- }
- /**
- * @param $matchData 赛事数据
- * @param $model_odds 赔率model
- * @param $source 数据源
- * @return array
- * @throws \Exception
- * 获取足球默认赔率数据
- */
- public function getOddsZQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
- //获取赛事id 集合
- $match_ids = [];
- foreach ($matchData as $k=>$v){
- $match_ids[] = (int)$v['match_id'];
- }
- $oddsData = lm($model_odds, 'Sports')
- ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
- ->whereIn('match_id',$match_ids)
- ->where(
- function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','goal_size_big');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','goal_size_small');
- });
- }
- )
- ->get()->toArray();
- foreach ($matchData as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- $odds[] = $vvv;
- }
- }
- $matchData[$kk]['oddsData'] = $odds;
- }
- return $matchData;
- }
- /**
- * @param $matchData 赛事数据
- * @param $model_odds 赔率model
- * @param $source 数据源
- * @return array
- * @throws \Exception
- * 获取篮球默认赔率数据
- */
- public function getOddsLQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
- //获取赛事id 集合
- $match_ids = [];
- foreach ($matchData as $k=>$v){
- $match_ids[] = $v['match_id'];
- }
- $oddsData = lm($model_odds, 'Sports')
- ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
- ->whereIn('match_id',$match_ids)
- ->where(
- function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','concede_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','total_size_big');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','total_size_small');
- });
- }
- )
- ->get()->toArray();
- foreach ($matchData as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- $odds[] = $vvv;
- }
- }
- $matchData[$kk]['oddsData'] = $odds;
- }
- return $matchData;
- }
- /**
- * @param $matchData 赛事数据
- * @param $model_odds 赔率model
- * @param $source 数据源
- * @return array
- * @throws \Exception
- * 获取网球默认赔率数据
- */
- public function getOddsWQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
- //获取赛事id 集合
- $match_ids = [];
- foreach ($matchData as $k=>$v){
- $match_ids[] = $v['match_id'];
- }
- $oddsData = lm($model_odds, 'Sports')
- ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
- ->whereIn('match_id',$match_ids)
- ->where(
- function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','dishes_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','dishes_guest');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','kemp_home');
- })
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','kemp_guest');
- });
- }
- )
- ->get()->toArray();
- foreach ($matchData as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- $odds[] = $vvv;
- }
- }
- $matchData[$kk]['oddsData'] = $odds;
- }
- return $matchData;
- }
- /**
- * @param $matchData 赛事数据
- * @param $model_odds 赔率model
- * @param $source 数据源
- * @return array
- * @throws \Exception
- * 获取棒球默认赔率数据
- */
- public function getOddsBQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
- //获取赛事id 集合
- $match_ids = [];
- foreach ($matchData as $k=>$v){
- $match_ids[] = $v['match_id'];
- }
- $oddsData = lm($model_odds, 'Sports')
- ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
- ->whereIn('match_id',$match_ids)
- ->where(
- function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_home')
- ->orWhere(function($query)use ($model_odds){
- $query->where($model_odds.'.odds_code','capot_guest');
- });
- }
- )
- ->get()->toArray();
- foreach ($matchData as $kk=>$vv){
- //获取赛事下赔率并且分组
- $odds = [];
- foreach ($oddsData as $kkk=>$vvv) {
- if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
- $odds[] = $vvv;
- }
- }
- $matchData[$kk]['oddsData'] = $odds;
- }
- return $matchData;
- }
- }
|