MatchListWeb.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jun.peng
  5. * Date: 2019/5/14
  6. * Time: 16:25
  7. */
  8. namespace App\Sports\Controller;
  9. use BaseController\Controller;
  10. use Biz\Match\GetmatchData;
  11. use Biz\Match\GetOddsData;
  12. use App\Sports\Model\St_area_country as area_countryModel;
  13. use App\Sports\Model\St_zq_odds as ZQoddsModel;
  14. /**
  15. * Class MatchListWeb
  16. * @package App\Sports\Controller
  17. * pc端 赛事接口
  18. */
  19. class MatchListWeb extends Controller{
  20. private $getTypeData;
  21. public function init() {
  22. $this->getTypeData = new GetmatchData();
  23. $this->getOddsData = new GetOddsData();
  24. $this->commonFunction = C()->get('commonFunction');
  25. }
  26. //各球类玩法列表及数量
  27. public function gameList(){
  28. $type = $_REQUEST['type'];//必填 状态代码
  29. $game_code = $_REQUEST['game_code'];//球类代码
  30. $p_code = $_REQUEST['p_code'];//父级玩法代码
  31. $time = $_REQUEST['match_date'];//时间条件
  32. $lg_ids = $_REQUEST['lg_id'];//联赛筛选
  33. $search = $_REQUEST['search'];//球队搜索
  34. try {
  35. if(empty($type) ){
  36. throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  37. }
  38. //如果有lg_id,则将其转为数组
  39. if(!empty($lg_ids)){
  40. if(strstr($lg_ids,',') != false){
  41. $pizza = $lg_ids;
  42. $lg_ids = explode(",", $pizza);
  43. }else{
  44. $lg_ids = [$lg_ids];
  45. }
  46. }
  47. switch ($type){
  48. case 'StRollBall'://滚球
  49. $this->getRollBall($type,$game_code,$p_code,$lg_ids,$search);
  50. break;
  51. case 'StSoon'://即将
  52. $this->Other($type,$game_code,$p_code,$time,$lg_ids,$search);
  53. break;
  54. case 'StToday'://今日
  55. $this->Other($type,$game_code,$p_code,$time,$lg_ids,$search);
  56. break;
  57. case 'StMorningPlate'://早盘
  58. $this->Other($type,$game_code,$p_code,$time,$lg_ids,$search);
  59. break;
  60. case 'StStringScene'://串场
  61. $this->Other($type,$game_code,$p_code,$time,$lg_ids,$search);
  62. break;
  63. default:
  64. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  65. }
  66. Render('', '1', lang('Tips','Sports')->get('success'));
  67. } catch (\Exception $e) {
  68. echo $e->getMessage();
  69. }
  70. }
  71. /*
  72. * 获取滚球数据
  73. */
  74. public function getRollBall($type,$game_code,$p_code='',$lg_ids=[],$search=''){
  75. //根据球类代码及玩法代码 获取相关赛事赔率数据
  76. if(!empty($game_code)){
  77. $matchData = $this->getMatchData($type,$game_code,$p_code,'',$lg_ids,$search);
  78. //将为空的数组去除
  79. $matchData = array_filter($matchData) ;
  80. if(empty($matchData)) Render('', '1', lang('Tips','Sports')->get('success'));
  81. Render($matchData, '1', lang('Tips','Sports')->get('success'));
  82. }
  83. //没有球类代码,则获取每个球类 各状态玩法下赛事数量
  84. $game = lm('GameType', 'Sports')->select('game_code')->where('status',1)->get()->toArray();
  85. $gameData = [];
  86. foreach ($game as $k=>$v){
  87. if($v['game_code'] !='gj'){
  88. $models = $this->commonFunction->getModels($v['game_code'],1);
  89. $where = $this->commonFunction->getState($type,$models['model_match'],$v['game_code']);
  90. $matchData = lm($models['model_league'],"Sports")
  91. ->join($models['model_match'],$models['model_match'].'.lg_id',$models['model_league'].'.id')
  92. ->select($models['model_match'].'.id as match_id')
  93. ->where($where)
  94. ->get()
  95. ->toArray();
  96. //===获取当前赛事是否有赔率,如果没有则去除===
  97. $matchData_new = $this->commonFunction->Handle_Odds_Null($matchData,$models);
  98. $matchNum = count($matchData_new);
  99. //获取满足状态的球类
  100. if($matchNum != 0){
  101. $gameData[$k]['game_code'] = $v['game_code'];
  102. $gameData[$k]['game_num'] = $matchNum;
  103. }
  104. }
  105. }
  106. sort($gameData);
  107. $num = [];
  108. foreach ($gameData as $kk=>$vv){
  109. $num[] = $vv['game_num'];
  110. }
  111. $gameData[]['all_num'] = array_sum($num);
  112. if(empty($gameData)) Render('', '1', lang('Tips','Sports')->get('success'));
  113. Render($gameData, '1', lang('Tips','Sports')->get('success'));
  114. }
  115. /*
  116. * 获取非滚球数据
  117. */
  118. public function Other($type,$game_code,$p_code,$time='',$lg_ids=[],$search=''){
  119. //根据球类代码及玩法代码 获取相关赛事赔率数据
  120. if(!empty($game_code) and !empty($p_code)){
  121. $matchData = $this->getMatchData($type,$game_code,$p_code,$time,$lg_ids,$search);
  122. //将为空的数组去除
  123. $matchData = array_filter($matchData) ;
  124. if(empty($matchData)) Render('', '1', lang('Tips','Sports')->get('success'));
  125. Render($matchData, '1', lang('Tips','Sports')->get('success'));
  126. }
  127. //根据状态获取所有球类/玩法下赛事数量
  128. $game = lm('GameType', 'Sports')->select('game_code')->where('status',1)->get()->toArray();
  129. $oddsCodeNum = [];
  130. foreach ($game as $k=>$v) {
  131. if ($v['game_code'] != 'gj') {
  132. //获取各球类下父级玩法赛事数量
  133. $oddsCodeNum[$k] = $this->getMatchData($type,$v['game_code'],'','','',$search);
  134. }
  135. }
  136. $matchDataNum = [];
  137. foreach ($oddsCodeNum as $k => $v){
  138. foreach ($v as $kk=>$vv){
  139. $matchDataNum[] = $vv;
  140. }
  141. }
  142. //将为空的数组去除
  143. $matchDataNum = array_filter($matchDataNum) ;
  144. if(empty($matchDataNum)) Render('', '1', lang('Tips','Sports')->get('success'));
  145. //==补充缺少玩法==
  146. //默认玩法
  147. $codeData=[
  148. [
  149. 'game_code'=>'zq',
  150. 'game_num'=>0,
  151. 'p_code'=>'B',
  152. 'code_num'=>0
  153. ],
  154. [
  155. 'game_code'=>'zq',
  156. 'game_num'=>0,
  157. 'p_code'=>'CO',
  158. 'code_num'=>0
  159. ],
  160. [
  161. 'game_code'=>'zq',
  162. 'game_num'=>0,
  163. 'p_code'=>'C',
  164. 'code_num'=>0
  165. ],
  166. [
  167. 'game_code'=>'zq',
  168. 'game_num'=>0,
  169. 'p_code'=>'TS',
  170. 'code_num'=>0
  171. ],
  172. [
  173. 'game_code'=>'zq',
  174. 'game_num'=>0,
  175. 'p_code'=>'TG',
  176. 'code_num'=>0
  177. ],
  178. // [
  179. // 'game_code'=>'zq',
  180. // 'game_num'=>0,
  181. // 'p_code'=>'kemp',
  182. // 'code_num'=>0
  183. // ],
  184. [
  185. 'game_code'=>'bq',
  186. 'game_num'=>0,
  187. 'p_code'=>'CO',
  188. 'code_num'=>0
  189. ],
  190. [
  191. 'game_code'=>'bq',
  192. 'game_num'=>0,
  193. 'p_code'=>'B',
  194. 'code_num'=>0
  195. ],
  196. // [
  197. // 'game_code'=>'bq',
  198. // 'game_num'=>0,
  199. // 'p_code'=>'kemp',
  200. // 'code_num'=>0
  201. // ],
  202. [
  203. 'game_code'=>'wq',
  204. 'game_num'=>0,
  205. 'p_code'=>'CO',
  206. 'code_num'=>0
  207. ],
  208. // [
  209. // 'game_code'=>'wq',
  210. // 'game_num'=>0,
  211. // 'p_code'=>'kemp',
  212. // 'code_num'=>0
  213. // ],
  214. // [
  215. // 'game_code'=>'lq',
  216. // 'game_num'=>0,
  217. // 'p_code'=>'kemp',
  218. // 'code_num'=>0
  219. // ],
  220. [
  221. 'game_code'=>'lq',
  222. 'game_num'=>0,
  223. 'p_code'=>'CO',
  224. 'code_num'=>0
  225. ]
  226. ];
  227. foreach($codeData as $k=>$v){
  228. foreach($matchDataNum as $kk=>$vv){
  229. if($v['game_code'] == $vv['game_code'] and $v['p_code'] == $vv['p_code']){
  230. $codeData[$k] = $vv;
  231. }
  232. }
  233. }
  234. Render($codeData, '1', lang('Tips','Sports')->get('success'));
  235. }
  236. /*
  237. * 获取赛事数据1
  238. */
  239. public function getMatchData($type,$game_code,$p_code='',$time='',$lg_ids=[],$search=''){
  240. //$p_code 获取具体玩法下的赛事数据
  241. $models = $this->commonFunction->getModels($game_code,1);
  242. $where = $this->commonFunction->getState($type,$models['model_match'],$game_code, $p_code);
  243. $select = [$models['model_match'].'.id as match_id',$models['model_match'].'.lg_id'];
  244. $timeWhere = [];
  245. //如果有传玩法代码,则获取查询字段
  246. if($p_code){
  247. //时间条件
  248. if(!empty($time)){
  249. if($time == 'all'){//全部七天
  250. $timeWhere[] = ['match_date','<',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
  251. }
  252. else if($time == 'other'){//七天后 所有
  253. $timeWhere[] = ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
  254. }
  255. else{//根据 传入 日期
  256. $timeWhere[] = ['match_date',$time];
  257. }
  258. }
  259. if($p_code == 'kemp'){
  260. $select = [$models['model_league'].'.id as lg_id',$models['model_league'].'.name_chinese as leagueName','last_time','country_id','area_id'];
  261. }else{
  262. $select = [$models['model_league'].'.id as lg_id',$models['model_league'].'.name_chinese as leagueName',$models['model_match'].'.id as match_id','home_team','guest_team','match_date','match_time','tag','country_id','area_id'];
  263. }
  264. }
  265. //如果是滚球
  266. if($type == 'StRollBall'){
  267. $select = [$models['model_league'].'.id as lg_id',$models['model_league'].'.name_chinese as leagueName',$models['model_match'].'.id as match_id','home_team','guest_team','match_date','match_time','tag','country_id','area_id'];
  268. }
  269. $model_match = $models['model_match'];
  270. //赛事数据
  271. if(!empty($lg_ids)){
  272. $matchData = lm($models['model_league'],"Sports")
  273. ->join($model_match,$model_match.'.lg_id',$models['model_league'].'.id')
  274. ->select($select)
  275. ->where($where)//状态条件
  276. ->whereIn($models['model_league'].'.id',$lg_ids)//联赛id筛选
  277. ->where($timeWhere)//时间条件
  278. ->where(function($query)use ($model_match,$search){//追加 球队搜索
  279. $query->where($model_match.'.home_team','like','%'.$search.'%')
  280. ->orWhere(function($query)use ($model_match,$search) {
  281. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  282. });
  283. })
  284. ->get()->toArray();
  285. }else{
  286. $matchData = lm($models['model_league'],"Sports")
  287. ->join($model_match,$model_match.'.lg_id',$models['model_league'].'.id')
  288. ->select($select)
  289. ->where($where)//状态条件
  290. ->where($timeWhere)//时间条件
  291. ->where(function($query)use ($model_match,$search){//追加 球队搜索
  292. $query->where($model_match.'.home_team','like','%'.$search.'%')
  293. ->orWhere(function($query)use ($model_match,$search) {
  294. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  295. });
  296. })
  297. ->get()->toArray();
  298. }
  299. //不是冠军,则验证赛事赔率
  300. if($p_code != 'kemp'){
  301. //===获取当前赛事是否有赔率,如果没有则去除===
  302. $matchNum = $this->commonFunction->Handle_Odds_Null($matchData,$models);
  303. }else{
  304. //===获取当前联赛是否有冠军赔率,没有则去除===
  305. $matchNum = $this->commonFunction->Handle_Odds_Null_lg($matchData,$models);
  306. }
  307. if(empty($matchNum)) return $matchNum;
  308. //获取赛事id/联赛id
  309. $match_ids = [];
  310. $lg_ids = [];
  311. foreach ($matchNum as $k => $v){
  312. $match_ids[] = $v['match_id'];
  313. $lg_ids[] = $v['lg_id'];
  314. }
  315. //如果是滚球,为赛事追加比分/进行时间/进程 数据
  316. if($type == 'StRollBall'){
  317. $match_ids_str = implode(",", $match_ids);
  318. $result_record = $models['model_result_record'];
  319. //如果是网球
  320. if($game_code == 'wq'){
  321. $sql = "select a.match_id,a.home_player_score,a.guest_player_score,a.match_time as a_time,a.match_process,a.result_mark from $result_record a,
  322. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  323. where a.match_id = b.match_id and a.id = b.id ";
  324. }else
  325. //如果是棒球
  326. if($game_code == 'bq' || $game_code == 'lq'){
  327. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process,a.result_mark from $result_record a,
  328. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  329. where a.match_id = b.match_id and a.id = b.id ";
  330. }else{
  331. //其他球类
  332. $sql = "select a.match_id,a.home_score,a.guest_score,a.match_time as a_time,a.match_process from $result_record a,
  333. (select match_id,max(id) id from $result_record where match_id IN ($match_ids_str) group by match_id)b
  334. where a.match_id = b.match_id and a.id = b.id ";
  335. }
  336. //查询 赛事结果记录最新的一条
  337. $match_result_record = S ('DB')->select ($sql);
  338. //处理赛事数据,追加比分及进程
  339. foreach ($matchNum as $k=>$v){
  340. foreach ($match_result_record as $kk => $vv){
  341. if($v['match_id'] == $vv->match_id){
  342. //如果是网球结果
  343. if($game_code == 'wq'){
  344. $matchNum[$k]['home_player_score'] = $vv->home_player_score?:0;
  345. $matchNum[$k]['guest_player_score'] = $vv->guest_player_score?:0;
  346. $matchNum[$k]['result_mark'] = $vv->result_mark;
  347. }else if($game_code == 'bq'){
  348. $matchNum[$k]['home_score'] = $vv->home_score?:0;
  349. $matchNum[$k]['guest_score'] = $vv->guest_score?:0;
  350. $matchNum[$k]['result_mark'] = $vv->result_mark;
  351. }
  352. else{
  353. $matchNum[$k]['home_score'] = $vv->home_score?:0;
  354. $matchNum[$k]['guest_score'] = $vv->guest_score?:0;
  355. }
  356. $matchNum[$k]['a_time'] = $vv->a_time?:0;
  357. $matchNum[$k]['match_process'] = $vv->match_process?:'';
  358. }
  359. }
  360. }
  361. }
  362. //赔率数据
  363. $oddsCodeNum = $this->getOddsData($game_code,$models['model_odds'],$match_ids,$lg_ids,$p_code,$type);
  364. if(empty($p_code) and $type != 'StRollBall') {
  365. return $oddsCodeNum;
  366. }
  367. //处理联赛/赛事/赔率 数据
  368. $data = $this->get_l_m_o($p_code,$matchNum,$oddsCodeNum,$models['model_result_record'],$game_code,$type);
  369. return $data;
  370. }
  371. /*
  372. * 联赛/赛事/赔率 组装数据
  373. */
  374. public function get_l_m_o($p_code='',$matchData=[],$oddsCodeNum=[],$model_result_record='',$game_code='',$type=''){
  375. //如果是滚球赔率 追加状态字段
  376. if($type == 'StRollBall' and !empty($oddsCodeNum)){
  377. $rollOdds = [];
  378. foreach($oddsCodeNum as $k=>$v){
  379. $v['oddsType'] = 'StRollBall';
  380. $rollOdds[] = $v;
  381. }
  382. $oddsCodeNum = $rollOdds;
  383. }
  384. $match_odds = [];
  385. //如果是冠军盘口
  386. if($p_code == 'kemp'){
  387. //二维数组去重
  388. $matchData = $this->commonFunction->array_unset_tt($matchData,'lg_id');
  389. foreach ($oddsCodeNum as $k=>$v){
  390. $v['mark'] = 'gj-'.$game_code.'-'.$v['lg_id'].'-'.$v['p_code'].'-'.$v['odds_code'].'-'.$v['sort'];
  391. foreach ($matchData as $kk => $vv){
  392. if($v['lg_id'] == $vv['lg_id']){
  393. $match_odds[$kk]['area_id'] = $vv['area_id'];
  394. $match_odds[$kk]['country_id'] = $vv['country_id'];
  395. $match_odds[$kk]['lg_id'] = $vv['lg_id'];
  396. $match_odds[$kk]['leagueName'] = $vv['leagueName'];
  397. $match_odds[$kk]['last_time'] = $vv['last_time'];
  398. $match_odds[$kk]['oddsData'][] = $v;
  399. }
  400. }
  401. }
  402. sort($match_odds);
  403. $gjData = [];
  404. foreach ($match_odds as $k=>$v){
  405. //按p_code分组
  406. $p_code=array();
  407. foreach($v['oddsData'] as $kk=>$vv){
  408. $p_code[$vv['p_code']][]=$vv;
  409. }
  410. $sd = [];
  411. foreach ($p_code as $k1=>$v1){
  412. foreach ($v1 as $k2=>$v2){
  413. $sd[$v2['p_code']]['last_time'] =$v['last_time'];
  414. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  415. }
  416. }
  417. $gjData[] = $sd;
  418. }
  419. //国家数据
  420. $country=area_countryModel::getName('',2);
  421. //获取国家联赛列表
  422. $countryList = [];
  423. foreach ($country as $k=>$v){
  424. foreach ($match_odds as $kk=>$vv){
  425. if($v['country_id'] == $vv['country_id']){
  426. unset($vv['last_time']);
  427. //联赛下父级玩法 盘口数量
  428. $oddsCode = array_column($vv['oddsData'], 'odds_code');
  429. //获取冠军盘口下 父级玩法 数量
  430. $oddsCodeN = array_count_values($oddsCode);
  431. $vv['matchNum'] = count($oddsCodeN);
  432. unset($vv['oddsData']);
  433. $v['lg_list'][] = $vv;
  434. $countryList[$k] = $v;
  435. }
  436. }
  437. }
  438. sort($countryList);
  439. //地区数据
  440. $area=area_countryModel::getName('',1);
  441. //获取地区联赛列表
  442. $areaList = [];
  443. foreach ($area as $k=>$v){
  444. foreach ($match_odds as $kk=>$vv){
  445. if($v['id'] == $vv['area_id'] and $vv['country_id'] == 0){
  446. unset($vv['last_time']);
  447. //联赛下父级玩法 盘口数量
  448. $oddsCode = array_column($vv['oddsData'], 'odds_code');
  449. //获取冠军盘口下 父级玩法 数量
  450. $oddsCodeN = array_count_values($oddsCode);
  451. $vv['matchNum'] = count($oddsCodeN);
  452. unset($vv['oddsData']);
  453. $v['lg_list'][] = $vv;
  454. $areaList[$k] = $v;
  455. }
  456. }
  457. }
  458. sort($areaList);
  459. //国家/地区 联赛列表
  460. $leagueList = array_merge($countryList,$areaList);
  461. $data = [$gjData,$leagueList];
  462. return $data;
  463. }
  464. //处理非冠军盘口
  465. foreach ($oddsCodeNum as $k=>$v){
  466. $v['mark'] = $game_code.'-'.$v['match_id'].'-'.$v['p_code'].'-'.$v['odds_code'].'-'.$v['sort'];
  467. //没有玩法代码 则为滚球,追加结果数据
  468. if(empty($p_code)){
  469. foreach ($matchData as $kk=>$vv){
  470. if($v['match_id'] == $vv['match_id']){
  471. $match_odds[$kk]['lg_id'] = $vv['lg_id'];
  472. $match_odds[$kk]['match_id'] = $vv['match_id'];
  473. $match_odds[$kk]['home_team'] = $vv['home_team'];
  474. $match_odds[$kk]['guest_team'] = $vv['guest_team'];
  475. $match_odds[$kk]['match_date'] = $vv['match_date'];
  476. $match_odds[$kk]['match_time'] = $vv['match_time'];
  477. $match_odds[$kk]['tag'] = $vv['tag'];
  478. $match_odds[$kk]['a_time'] = $vv['a_time'];//?:$this->commonFunction->getMatchTime($vv['match_date'],$vv['match_time']);
  479. $match_odds[$kk]['match_process'] = $vv['match_process'];//?:$this->commonFunction->getMatchProcess( $match_odds[$kk]['a_time'],$game_code);
  480. //如果是网球结果
  481. if($game_code == 'wq'){
  482. $match_odds[$kk]['home_player_score'] = $vv['home_player_score']?:0;
  483. $match_odds[$kk]['guest_player_score'] = $vv['guest_player_score']?:0;
  484. //追加赛事实时结果json
  485. $match_odds[$kk]['result_mark'] = $vv['result_mark'];
  486. //按第一、二、三盘/全场 分组
  487. if(strpos($v['odds_code'],'one') !== false)
  488. {
  489. $match_odds[$kk]['one_oddsData'][] = $v;
  490. }
  491. else if(strpos($v['odds_code'],'two') !== false)
  492. {
  493. $match_odds[$kk]['two_oddsData'][] = $v;
  494. }
  495. else if(strpos($v['odds_code'],'three') !== false)
  496. {
  497. $match_odds[$kk]['three_oddsData'][] = $v;
  498. }
  499. else
  500. {
  501. $match_odds[$kk]['full_oddsData'][] = $v;
  502. }
  503. }else if($game_code == 'bq'){
  504. $match_odds[$kk]['home_score'] = $vv['home_score']?:0;
  505. $match_odds[$kk]['guest_score'] = $vv['guest_score']?:0;
  506. //赛事实时结果 json
  507. $match_odds[$kk]['result_mark'] = $vv['result_mark'];
  508. //按 前五局/全场 分组
  509. if(strpos($v['odds_code'],'five') !== false)
  510. {
  511. $match_odds[$kk]['five_oddsData'][] = $v;
  512. }
  513. else
  514. {
  515. $match_odds[$kk]['full_oddsData'][] = $v;
  516. }
  517. }
  518. else
  519. {
  520. $match_odds[$kk]['home_score'] = $vv['home_score']?:0;
  521. $match_odds[$kk]['guest_score'] = $vv['guest_score']?:0;
  522. $match_odds[$kk]['oddsData'][] = $v;
  523. }
  524. }
  525. }
  526. }else{
  527. foreach ($matchData as $kk=>$vv){
  528. if($v['match_id'] == $vv['match_id']){
  529. $match_odds[$kk]['lg_id'] = $vv['lg_id'];
  530. $match_odds[$kk]['match_id'] = $vv['match_id'];
  531. $match_odds[$kk]['home_team'] = $vv['home_team'];
  532. $match_odds[$kk]['guest_team'] = $vv['guest_team'];
  533. $match_odds[$kk]['match_date'] = $vv['match_date'];
  534. $match_odds[$kk]['match_time'] = $vv['match_time'];
  535. $match_odds[$kk]['tag'] = $vv['tag'];
  536. $match_odds[$kk]['oddsData'][] = $v;
  537. }
  538. }
  539. }
  540. }
  541. //排序
  542. sort($match_odds);
  543. $data = [];
  544. foreach ($matchData as $k=>$v){
  545. foreach ($match_odds as $kk=>$vv){
  546. if($v['lg_id'] == $vv['lg_id']){
  547. $data[$k]['area_id'] = $v['area_id'];
  548. $data[$k]['country_id'] = $v['country_id'];
  549. $data[$k]['lg_id'] = $v['lg_id'];
  550. $data[$k]['leagueName'] = $v['leagueName'];
  551. $data[$k]['matchData'][] = $vv;
  552. }
  553. }
  554. }
  555. //赛事详细数据 去重
  556. $matchData = $this->commonFunction->array_unset_tt($data,'lg_id');
  557. //国家数据
  558. $country = area_countryModel::getName('',2);
  559. //获取国家联赛列表
  560. $countryList = [];
  561. foreach ($country as $k=>$v){
  562. foreach ($matchData as $kk=>$vv){
  563. if($v['id'] == $vv['country_id']){
  564. //联赛下赛事数量
  565. $vv['matchNum'] = count($vv['matchData']);
  566. unset($vv['matchData']);
  567. $v['lg_list'][] = $vv;
  568. $countryList[$k] = $v;
  569. }
  570. }
  571. }
  572. sort($countryList);
  573. //地区数据
  574. $area = area_countryModel::getName('',1);
  575. //获取地区联赛列表
  576. $areaList = [];
  577. foreach ($area as $k=>$v){
  578. foreach ($matchData as $kk=>$vv){
  579. if($v['id'] == $vv['area_id'] and $vv['country_id'] == 0){
  580. //联赛下赛事数量
  581. $vv['matchNum'] = count($vv['matchData']);
  582. unset($vv['matchData']);
  583. $v['lg_list'][] = $vv;
  584. $areaList[$k] = $v;
  585. }
  586. }
  587. }
  588. sort($areaList);
  589. sort($matchData);
  590. //国家/地区 联赛列表
  591. $leagueList = array_merge($countryList,$areaList);
  592. $data = [$matchData,$leagueList];
  593. return $data;
  594. }
  595. /*
  596. * 根据match_id获取赔率数据
  597. */
  598. public function getOddsData($game_code,$model_odds,$match_ids=[],$lg_ids=[],$p_code='',$type='', $matchData = []){
  599. //获取pc版各球类滚球/让球玩法代码
  600. $get_DefaultOdds = require "Config/DefaultOdds.php";
  601. $DefaultOddsRoll = $get_DefaultOdds['PC_StRollBall'];//滚球
  602. $DefaultOddsConcede = $get_DefaultOdds['PC_concede'];//让球
  603. $select = ['match_id','p_code'];
  604. $whereOr = [];
  605. //如果是串场赛事,则获取串场赔率
  606. if($type== 'StStringScene'){
  607. $whereOr = [['sort','=',0],['status','=',0],['is_stringscene','=',1]];
  608. }else{
  609. $whereOr = [['sort','=',0],['status','=',0],['is_stringscene','=',0]];
  610. }
  611. //有父级玩法,则获取该玩法下详细数据
  612. if($p_code){
  613. $select = ['lg_id','match_id','others_match_id','id','p_code','odds_code','condition','odds','odds_only','sort','status','team'];
  614. //获取冠军盘口
  615. if($p_code == 'kemp'){
  616. $whereOr = [['sort','=',0],['type','=',1],['status','=',0]];
  617. $oddsData = ZQoddsModel::getOddsDataPC($model_odds,$select,$lg_ids,$whereOr,$p_code);
  618. return $oddsData;
  619. }
  620. //足球 让球
  621. else if($p_code == 'CO' and $game_code == 'zq'){
  622. $p_code = $DefaultOddsConcede['zq'];
  623. $whereIn = [];
  624. //$p_code = ['CO','GS'];//让球 进球大小
  625. }
  626. //篮球 让球
  627. else if($p_code == 'CO' and $game_code == 'lq'){
  628. $p_code = $DefaultOddsConcede['lq'];
  629. $whereIn = ['coh','cog','tns','tnb','tbhb','tbhs','tbgb','tbgs'];
  630. //$p_code = ['CO','TN','TB'];//让球 总分大小 球队得分大小
  631. }
  632. //网球 让球
  633. else if($p_code == 'CO' and $game_code == 'wq'){
  634. $p_code = $DefaultOddsConcede['wq'];
  635. $whereIn = ['ldh','ldg','lbh','lbg','tnb','tns'];
  636. // $p_code = ['LD','LB','TN'];//让盘 让局 总局数大小
  637. }
  638. //棒球 让球
  639. else if($p_code == 'CO' and $game_code == 'bq'){
  640. $p_code = $DefaultOddsConcede['bq'];
  641. $whereIn = ['coh','cog','tnb','tns','tss','tsd'];
  642. // $p_code = ['CO','TN','TS'];//让球 总得分大小 总得分单双
  643. }else{
  644. $p_code = [$p_code];
  645. }
  646. $oddsData = ZQoddsModel::getOddsDataPC($model_odds,$select,$match_ids,$whereOr,$p_code,$game_code,$whereIn);
  647. return $oddsData;
  648. }
  649. //如果是滚球,则获取滚球下详细数据
  650. if($type == 'StRollBall'){
  651. $select = ['lg_id','match_id','others_match_id','id','p_code','odds_code','condition','odds','odds_only','sort','status','team'];
  652. $whereOr = [['sort','=',0],['status','=',0],['is_stringscene','=',0]];
  653. //获取滚球下,各球类默认玩法代码
  654. if($game_code == 'zq'){
  655. $p_code = $DefaultOddsRoll['zq'];
  656. //$p_code = ['CO','GS'];//让球 进球大小
  657. }
  658. if($game_code == 'lq'){
  659. $p_code = $DefaultOddsRoll['lq'];
  660. $whereIn = ['coh','cog','tns','tnb','tbhb','tbhs','tbgb','tbgs','ch','cg'];
  661. //$p_code = ['CO','TN','TB','C'];//让球 得分大小 得分单双 独赢盘
  662. }
  663. if($game_code == 'wq'){
  664. $p_code = $DefaultOddsRoll['wq'];
  665. //$p_code = ['LD','LB','TN','C'];//让盘 让局 总局数大小 冠军
  666. }
  667. if($game_code == 'bq'){
  668. $p_code = $DefaultOddsRoll['bq'];
  669. //$p_code = ['CO','TN','TS','C'];//让球 总得分大小 总得分单双 独赢盘
  670. }
  671. $oddsData = ZQoddsModel::getOddsDataPC($model_odds,$select,$match_ids,$whereOr,$p_code,$game_code,$whereIn);
  672. return $oddsData;
  673. }
  674. $oddsData = ZQoddsModel::getOddsDataPC($model_odds,$select,$match_ids,$whereOr,'',$game_code);
  675. //按父级玩法分组
  676. $oddsCode = [];
  677. foreach ($oddsData as $kk=>$vv){
  678. $oddsCode[$vv['p_code']][]= $vv;
  679. }
  680. //追加当前球类冠军盘口数量
  681. $where = [
  682. ['type','=',1],
  683. ];
  684. $select = ['match_id','type'];
  685. $oddsData_gj_num = lm($model_odds,"Sports")
  686. // ->select($select)
  687. ->where($where)
  688. ->groupby("lg_id","match_id","type")
  689. ->pluck('lg_id')
  690. ->toArray();
  691. // 去重 获取每个玩法下的赛事数量
  692. $oddsCodeNum = [];
  693. $game_num = count($match_ids);
  694. foreach ($oddsCode as $kkk=>$vvv){
  695. $oddsCodeNum[$kkk]['game_code'] = $game_code;
  696. $oddsCodeNum[$kkk]['game_num'] = $game_num;
  697. $oddsCodeNum[$kkk]['p_code'] = $kkk;
  698. $oddsCodeNum[$kkk]['code_num'] = count($this->commonFunction->array_unset_tt($vvv,'match_id'));
  699. }
  700. $oddsCodeNum['kemp']['game_code'] = $game_code;
  701. $oddsCodeNum['kemp']['game_num'] = $game_num;
  702. $oddsCodeNum['kemp']['p_code'] = 'kemp';
  703. $oddsCodeNum['kemp']['code_num'] = count($oddsData_gj_num);
  704. sort($oddsCodeNum);
  705. return $oddsCodeNum;
  706. //==end==
  707. }
  708. //获取直播数据
  709. public function getBroadcast(){
  710. //球类代码
  711. $game_code = $_REQUEST['game_code'];
  712. if(empty($game_code)) throw new \Exception(Render([], '10001', lang('Tips','Sports')->get('PARAM_ERROR')));
  713. $where = [];
  714. if($game_code != 'all'){//拼接查询条件
  715. $where[] = ['game_type','=',$game_code];
  716. }
  717. $data = lm('st_broadcast',"Sports")
  718. ->select('id','showid','shower','league_name','game_type','host_team','guest_team','start_time','doing')
  719. ->where($where)
  720. ->orderBy('start_time','asc')
  721. ->get()
  722. ->toArray();
  723. Render($data, '1', lang('Tips','Sports')->get('success'));
  724. }
  725. }