| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Jun.peng
- * Date: 2019/5/14
- * Time: 16:25
- */
- namespace App\Sports\Controller;
- use BaseController\Controller;
- use Biz\Match\GetmatchData;
- use Biz\Match\GetOddsData;
- /**
- * Class MatchListWeb
- * @package App\Sports\Controller
- * pc端 接口
- */
- class MatchListWeb extends Controller{
- private $getTypeData;
- public function init() {
- $this->getTypeData = new GetmatchData();
- $this->getOddsData = new GetOddsData();
- $this->commonFunction = C()->get('commonFunction');
- }
- //各球类玩法列表及数量
- public function gameList(){
- $type = $_REQUEST['type'];//状态代码
- $game_code= $_REQUEST['game_code'];//球类代码
- $p_code= $_REQUEST['p_code'];//父级玩法代码
- try {
- if(empty($type) ){
- throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- switch ($type){
- case 'StRollBall'://滚球
- $this->getRollBall($type,$game_code,$p_code);
- break;
- case 'StSoon'://即将
- $this->Other($type,$game_code,$p_code);
- break;
- case 'StToday'://今日
- $this->Other($type,$game_code,$p_code);
- break;
- case 'StMorningPlate'://早盘
- $this->Other($type,$game_code,$p_code);
- break;
- case 'StStringScene'://串场
- $this->Other($type,$game_code,$p_code);
- break;
- default:
- throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
- }
- Render([], '1', lang('Tips','Sports')->get('success'));
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
- //获取滚球
- public function getRollBall($type,$game_code,$p_code){
- //根据球类代码及玩法代码 获取相关赛事赔率数据
- if(!empty($game_code) and !empty($p_code)){
- $matchData = $this->getMatchData($type,$game_code,$p_code);
- Render($matchData, '1', lang('Tips','Sports')->get('success'));
- }
- $game = lm('GameType', 'Sports')->select('game_code')->where('status',1)->get()->toArray();
- // $gameData = [];
- // foreach ($game as $k=>$v){
- // if($v['game_code'] !='gj'){
- // $where = $this->commonFunction->getState($type);
- // $models = $this->commonFunction->getModels($v['game_code'],1);
- // $matchNum = lm($models['model_league'],"Sports")
- // ->join($models['model_match'],$models['model_match'].'.lg_id',$models['model_league'].'.lg_id')
- // ->where($models['model_match'].'.source',$this->source['source'])
- // ->where($where)
- // ->count("*");
- // //获取满足状态的球类
- // if($matchNum != 0){
- // $gameData[$v['game_code']] = $matchNum;
- // }
- // }
- // }
- // $gameData['all_num'] = array_sum($gameData);
- // $data[] = $gameData;
- // Render($data, '1', lang('Tips','Sports')->get('success'));
- $gameData = [];
- foreach ($game as $k=>$v){
- if($v['game_code'] !='gj'){
- $where = $this->commonFunction->getState($type);
- $models = $this->commonFunction->getModels($v['game_code'],1);
- $matchNum = lm($models['model_league'],"Sports")
- ->join($models['model_match'],$models['model_match'].'.lg_id',$models['model_league'].'.lg_id')
- ->where($models['model_match'].'.source',$this->source['source'])
- ->where($where)
- ->count("*");
- //获取满足状态的球类
- if($matchNum != 0){
- $gameData[$k]['game_code'] = $v['game_code'];
- $gameData[$k]['game_num'] = $matchNum;
- }
- }
- }
- sort($gameData);
- $num = [];
- foreach ($gameData as $kk=>$vv){
- $num[] = $vv['game_num'];
- }
- $gameData[]['all_num'] = array_sum($num);
- Render($gameData, '1', lang('Tips','Sports')->get('success'));
- }
- //获取非滚球数据
- public function Other($type,$game_code,$p_code){
- //根据球类代码及玩法代码 获取相关赛事赔率数据
- if(!empty($game_code) and !empty($p_code)){
- $matchData = $this->getMatchData($type,$game_code,$p_code);
- Render($matchData, '1', lang('Tips','Sports')->get('success'));
- }
- //根据状态获取所有球类/玩法下赛事数量
- $game = lm('GameType', 'Sports')->select('game_code')->where('status',1)->get()->toArray();
- $oddsCodeNum = [];
- foreach ($game as $k=>$v) {
- if ($v['game_code'] != 'gj') {
- //获取各球类下父级玩法赛事数量
- $oddsCodeNum[$k] = $this->getMatchData($type,$v['game_code'],'');
- }
- }
- $matchDataNum = [];
- foreach ($oddsCodeNum as $k => $v){
- foreach ($v as $kk=>$vv){
- $matchDataNum[] = $vv;
- }
- }
- Render($matchDataNum, '1', lang('Tips','Sports')->get('success'));
- }
- //获取赛事数据
- public function getMatchData($type,$game_code,$p_code=''){
- //$p_code 获取具体玩法下的赛事数据
- $where = $this->commonFunction->getState($type);
- $models = $this->commonFunction->getModels($game_code,1);
- $select = [$models['model_match'].'.match_id'];
- if($p_code){
- $select = [$models['model_league'].'.lg_id',$models['model_league'].'.name_chinese as leagueName',$models['model_match'].'.match_id','home_team','guest_team','match_date','match_time','tag'];
- }
- $matchNum = lm($models['model_league'],"Sports")
- ->join($models['model_match'],$models['model_match'].'.lg_id',$models['model_league'].'.lg_id')
- // ->select($models['model_league'].'.lg_id',$models['model_league'].'.name_chinese as leagueName',$models['model_match'].'.match_id','home_team','guest_team','match_date','match_time','tag')
- ->select($select)
- ->where($models['model_match'].'.source',$this->source['source'])
- ->where($where)
- ->get()->toArray();
- $oddsCodeNum = $this->getOddsData($game_code,$models['model_odds'],$matchNum,$p_code);
- if($p_code){
- $match_odds = [];
- foreach ($oddsCodeNum as $k=>$v){
- foreach ($matchNum as $kk=>$vv){
- if($v['match_id'] == $vv['match_id']){
- $match_odds[$kk]['lg_id'] = $vv['lg_id'];
- $match_odds[$kk]['leagueName'] = $vv['leagueName'];
- $match_odds[$kk]['match_id'] = $vv['match_id'];
- $match_odds[$kk]['home_team'] = $vv['home_team'];
- $match_odds[$kk]['guest_team'] = $vv['guest_team'];
- $match_odds[$kk]['match_date'] = $vv['match_date'];
- $match_odds[$kk]['match_time'] = $vv['match_time'];
- $match_odds[$kk]['tag'] = $vv['tag'];
- $match_odds[$kk]['oddsData'][] = $v;
- }
- }
- }
- //排序
- sort($match_odds);
- $data = [];
- foreach ($matchNum as $k=>$v){
- foreach ($match_odds as $kk=>$vv){
- if($v['lg_id'] == $vv['lg_id']){
- $data[$k]['lg_id'] = $v['lg_id'];
- $data[$k]['leagueName'] = $v['leagueName'];
- $data[$k]['matchData'][] = $vv;
- }
- }
- }
- //去重
- $data = $this->uniquArr($data,'lg_id');
- return $data;
- }
- return $oddsCodeNum;
- }
- //根据match_id获取赔率数据
- public function getOddsData($game_code,$model_odds,$match_ids,$p_code=''){
- $match_id = [];
- foreach ($match_ids as $k => $v){
- $match_id[] = $v['match_id'];
- }
- $select = ['match_id','p_code'];
- $whereOr = [];
- if($p_code){
- $whereOr = [['p_code','=',$p_code],['sort','=',0]];
- $select = ['match_id','id','p_code','odds_code','condition','odds','odds_only','sort','status'];
- }
- $oddsData = lm($model_odds,"Sports")
- // ->select('match_id','p_code')(
- ->select($select)
- ->whereIn('match_id', $match_id)
- ->where('source',$this->source['source'])
- ->where($whereOr)
- ->get()
- ->toArray();
- if($p_code){
- return $oddsData;
- }
- //按父级玩法分组
- $oddsCode = [];
- foreach ($oddsData as $kk=>$vv){
- $oddsCode[$vv['p_code']][]= $vv;
- }
- // 去重 获取每个玩法下的赛事数量
- $oddsCodeNum = [];
- $game_num = count($match_ids);
- foreach ($oddsCode as $kkk=>$vvv){
- $oddsCodeNum[$kkk]['game_code'] = $game_code;
- $oddsCodeNum[$kkk]['game_num'] = $game_num;
- $oddsCodeNum[$kkk]['p_code'] = $kkk;
- $oddsCodeNum[$kkk]['code_num'] = count($this->uniquArr($vvv,'match_id'));
- }
- sort($oddsCodeNum);
- return $oddsCodeNum;
- }
- /**
- * 二维数组根据某个字段去重
- * @param array $array 二维数组
- * @para array 去重后的数组
- */
- function uniquArr($array,$key){
- $result = array();
- foreach($array as $k=>$val){
- $code = false;
- foreach($result as $_val){
- if($_val[$key] == $val[$key]){
- $code = true;
- break;
- }
- }
- if(!$code){
- $result[]=$val;
- }
- }
- return $result;
- }
- }
|