GetmatchData.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. <?php
  2. /**
  3. * 根据不同状态获取 赛事数据
  4. * User: Jun.peng
  5. * Date: 2019/4/4
  6. * Time: 10:57
  7. */
  8. namespace Biz\Match;
  9. use Biz\Match\GetOddsData;
  10. use App\Sports\Model\St_zq_league as leagueModel;
  11. use App\Sports\Model\St_zq_competition as matchModel;
  12. use App\Sports\Model\St_zq_odds as ZQoddsModel;
  13. use App\Sports\Model\St_wq_odds as WQoddsModel;
  14. use App\Sports\Model\St_bq_odds as BQoddsModel;
  15. use App\Sports\Model\St_lq_odds as LQoddsModel;
  16. class GetmatchData {
  17. public function __construct() {
  18. $this->getOddsData = new GetOddsData();
  19. $this->commonFunction = C()->get('commonFunction');
  20. }
  21. /**
  22. * @param $ret 提交参数
  23. * @param $source 数据源条件
  24. * @return array
  25. * @throws \Exception
  26. * 获取不同状态下的赛事相关数据
  27. */
  28. public function typeData($ret,$source){
  29. //根据球类代码 获取相关model
  30. $models = $this->commonFunction->getModels($ret['game_code']);
  31. $model_match = $models['model_match'];
  32. //获取 不同状态的查询条件
  33. $where = $this->commonFunction->getState($ret['type_code'],$model_match,$ret['game_code']);
  34. //根据联赛id查询
  35. if(!empty($ret['lg_id'])){
  36. $lg_id = $ret['lg_id'];
  37. }
  38. //根据搜索查询
  39. if(!empty($ret['search'])){
  40. $search = $ret['search'];
  41. }
  42. switch ($ret['type_code']){
  43. case 'StRollBall'://滚球
  44. $data = $this->getRollBall($source,$models,$where,$ret,$search);
  45. break;
  46. case 'StSoon'://即将
  47. $oddsTypeWhere = [
  48. [$models['model_odds'].'.is_stringscene','=',0],
  49. ];
  50. $data = $this->getSoon($source,$models,$where,$lg_id,$ret,$search,$oddsTypeWhere);
  51. break;
  52. case 'StToday'://今日
  53. $oddsTypeWhere = [
  54. [$models['model_odds'].'.is_stringscene','=',0],
  55. ];
  56. $data = $this->getToday($source,$models,$where,$lg_id,$search,$oddsTypeWhere);
  57. break;
  58. case 'StMorningPlate'://早盘
  59. //默认当天
  60. if(empty($ret['match_date'])){
  61. // $match_date = date("Y-m-d");
  62. $match_date = '';
  63. }else{
  64. if($ret['match_date'] != 'other'){
  65. $match_date = $ret['match_date'];
  66. }else{
  67. $match_date = 'other';
  68. }
  69. }
  70. $oddsTypeWhere = [
  71. [$models['model_odds'].'.is_stringscene','=',0],
  72. ];
  73. $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date,$oddsTypeWhere,$ret['type_code'],$ret['game_code']);
  74. break;
  75. case 'StStringScene'://串场
  76. $oddsTypeWhere = [
  77. [$models['model_odds'].'.is_stringscene','=',1],
  78. ];
  79. if(empty($ret['str_type']) || $ret['str_type'] ==0){//赛事
  80. $data = $this->getStringScene($source,$models,$where,$lg_id,$search,'',$oddsTypeWhere);
  81. }
  82. if($ret['str_type'] == 1){//参赛表
  83. }
  84. if($ret['str_type'] == 2){//冠军盘口
  85. $where = $this->commonFunction->getState('StChampion',$model_match,$ret['game_code']);
  86. $data = $this->getChampion($source,$models,$where,$lg_id,$search,'StChampion');
  87. }
  88. break;
  89. case 'StChampion'://冠军
  90. $data = $this->getChampion($source,$models,$where,$lg_id,$search,$ret['type_code']);
  91. break;
  92. default:
  93. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  94. }
  95. return $data;
  96. }
  97. /**
  98. * 获取各球类 滚球/即将 默认赔率数据
  99. */
  100. public function getDefault($data,$game_code,$models,$match_ids,$source,$type_code=''){
  101. if($game_code == 'zq') {
  102. //获取滚球下足球默认玩法
  103. $get_DefaultOdds = require "Config/DefaultOdds.php";
  104. $DefaultOdds = $get_DefaultOdds['StRollBall']['zq'];
  105. //获取赛事下默认赔率
  106. $oddsData = ZQoddsModel::getMatchOdds($source, $models,$match_ids,$DefaultOdds);
  107. foreach ($data as $k=>$v){
  108. foreach ($v['matchData'] as $kk=>$vv){
  109. //获取赛事下赔率并且分组
  110. foreach ($oddsData as $kkk=>$vvv) {
  111. if($type_code == 'StRollBall'){
  112. $vvv['oddsType'] = 'StRollBall';
  113. }
  114. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  115. if($vvv['odds_code'] == $DefaultOdds['zq_concede_guest']){
  116. $concede_g = $vvv;
  117. }
  118. if($vvv['odds_code'] == $DefaultOdds['zq_concede_home']){
  119. $concede_h = $vvv;
  120. }
  121. if($vvv['odds_code'] == $DefaultOdds['zq_goal_size_big']){
  122. $size_s = $vvv;
  123. }
  124. if($vvv['odds_code'] == $DefaultOdds['zq_goal_size_small']){
  125. $size_b = $vvv;
  126. }
  127. if($vvv['odds_code'] == $DefaultOdds['zq_capot_home']){
  128. $capot_h = $vvv;
  129. }
  130. if($vvv['odds_code'] == $DefaultOdds['zq_capot_dogfall']){
  131. $capot_d = $vvv;
  132. }
  133. if($vvv['odds_code'] == $DefaultOdds['zq_capot_guest']){
  134. $capot_g = $vvv;
  135. }
  136. }
  137. }
  138. $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
  139. $capot = [$capot_h,$capot_d,$capot_g];
  140. foreach ($concede_size as $key => $vaule){
  141. if($vaule == null) unset($concede_size[$key]);
  142. }
  143. foreach ($capot as $key1 => $vaule1){
  144. if($vaule1 == null) unset($capot[$key1]);
  145. }
  146. sort($concede_size);
  147. sort($capot);
  148. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  149. }
  150. }
  151. }
  152. if($game_code == 'lq') {
  153. //获取滚球下篮球默认玩法
  154. $get_DefaultOdds = require "Config/DefaultOdds.php";
  155. $DefaultOdds = $get_DefaultOdds['StRollBall']['lq'];
  156. //获取默认赔率
  157. $oddsData = LQoddsModel::getMatchOdds($source,$match_ids,$DefaultOdds);
  158. foreach ($data as $k=>$v){
  159. foreach ($v['matchData'] as $kk=>$vv){
  160. //获取赛事下赔率并且分组
  161. $capot = [];
  162. $total_size = [];
  163. $concede = [];
  164. foreach ($oddsData as $kkk=>$vvv) {
  165. if($type_code == 'StRollBall'){
  166. $vvv['oddsType'] = 'StRollBall';
  167. }
  168. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  169. if($vvv['odds_code'] == $DefaultOdds['lq_concede_home']){
  170. $concede_g = $vvv;
  171. }
  172. if($vvv['odds_code'] == $DefaultOdds['lq_concede_guest']){
  173. $concede_h = $vvv;
  174. }
  175. if($vvv['odds_code'] == $DefaultOdds['lq_total_size_big']){
  176. $size_s = $vvv;
  177. }
  178. if($vvv['odds_code'] == $DefaultOdds['lq_total_size_small']){
  179. $size_b = $vvv;
  180. }
  181. if($vvv['odds_code'] == $DefaultOdds['lq_capot_home']){
  182. $capot_h = $vvv;
  183. }
  184. if($vvv['odds_code'] == $DefaultOdds['lq_capot_guest']){
  185. $capot_g = $vvv;
  186. }
  187. }
  188. }
  189. $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
  190. $capot = [$capot_h,$capot_g];
  191. foreach ($concede_size as $key => $vaule){
  192. if($vaule == null) unset($concede_size[$key]);
  193. }
  194. foreach ($capot as $key1 => $vaule1){
  195. if($vaule1 == null) unset($capot[$key1]);
  196. }
  197. sort($concede_size);
  198. sort($capot);
  199. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  200. }
  201. }
  202. }
  203. if($game_code == 'wq') {
  204. //获取滚球下网球默认玩法
  205. $get_DefaultOdds = require "Config/DefaultOdds.php";
  206. $DefaultOdds = $get_DefaultOdds['StRollBall']['wq'];
  207. //获取网球默认赔率
  208. $oddsData = WQoddsModel::getMatchOdds($source,$match_ids,$DefaultOdds);
  209. foreach ($data as $k=>$v){
  210. foreach ($v['matchData'] as $kk=>$vv){
  211. //获取赛事下赔率并且分组
  212. $odds = [];
  213. foreach ($oddsData as $kkk=>$vvv) {
  214. if($type_code == 'StRollBall'){
  215. $vvv['oddsType'] = 'StRollBall';
  216. }
  217. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  218. if($vvv['odds_code'] == $DefaultOdds['wq_dishes_home']){
  219. $concede_g = $vvv;
  220. }
  221. if($vvv['odds_code'] == $DefaultOdds['wq_dishes_guest']){
  222. $concede_h = $vvv;
  223. }
  224. if($vvv['odds_code'] == $DefaultOdds['wq_kemp_home']){
  225. $size_s = $vvv;
  226. }
  227. if($vvv['odds_code'] == $DefaultOdds['wq_kemp_guest']){
  228. $size_b = $vvv;
  229. }
  230. }
  231. }
  232. $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
  233. foreach ($concede_size as $key => $vaule){
  234. if($vaule == null) unset($concede_size[$key]);
  235. }
  236. sort($concede_size);
  237. $data[$k]['matchData'][$kk]['oddsData'] = $concede_size;
  238. }
  239. }
  240. }
  241. if($game_code == 'bq') {
  242. //获取滚球下棒球默认玩法
  243. $get_DefaultOdds = require "Config/DefaultOdds.php";
  244. $DefaultOdds = $get_DefaultOdds['StRollBall']['bq'];
  245. //获取默认赔率
  246. $oddsData = BQoddsModel::getMatchOdds($source,$match_ids,$DefaultOdds);
  247. foreach ($data as $k=>$v){
  248. foreach ($v['matchData'] as $kk=>$vv){
  249. //获取赛事下赔率并且分组
  250. $odds = [];
  251. foreach ($oddsData as $kkk=>$vvv) {
  252. if($type_code == 'StRollBall'){
  253. $vvv['oddsType'] = 'StRollBall';
  254. }
  255. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  256. if($vvv['odds_code'] == $DefaultOdds['bq_concede_guest']){
  257. $concede_g = $vvv;
  258. }
  259. if($vvv['odds_code'] == $DefaultOdds['bq_concede_home']){
  260. $concede_h = $vvv;
  261. }
  262. if($vvv['odds_code'] == $DefaultOdds['bq_total_size_small']){
  263. $size_s = $vvv;
  264. }
  265. if($vvv['odds_code'] == $DefaultOdds['bq_total_size_big']){
  266. $size_b = $vvv;
  267. }
  268. if($vvv['odds_code'] == $DefaultOdds['bq_capot_home']){
  269. $capot_h = $vvv;
  270. }
  271. if($vvv['odds_code'] == $DefaultOdds['bq_capot_guest']){
  272. $capot_g = $vvv;
  273. }
  274. }
  275. }
  276. $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
  277. $capot = [$capot_h,$capot_g];
  278. foreach ($concede_size as $key => $vaule){
  279. if($vaule == null) unset($concede_size[$key]);
  280. }
  281. foreach ($capot as $key1 => $vaule1){
  282. if($vaule1 == null) unset($capot[$key1]);
  283. }
  284. sort($concede_size);
  285. sort($capot);
  286. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  287. }
  288. }
  289. }
  290. return $data;
  291. }
  292. /**
  293. * 获取滚球数据
  294. */
  295. public function getRollBall($source,$models,$where,$ret,$search=''){
  296. //获取当前状态下所有联赛
  297. $leagueData = leagueModel::getRollLeagueData($source,$models,$where,$search);
  298. if(empty($leagueData)){
  299. return $leagueData=[];
  300. }
  301. //获取联赛id
  302. $lg_ids = [];
  303. foreach ($leagueData as $k => $v){
  304. $lg_ids[] = $v['lg_id'];
  305. }
  306. //统计联赛下的赛事及查询赛事
  307. $matchData = matchModel::getRollMatchDataAll($source,$models,$where,$lg_ids,$ret);
  308. //如果赛事为空,直接返回
  309. if(empty($matchData)) return $matchData;
  310. //===获取当前赛事是否有赔率,如果没有则去除===
  311. $matchData_new = $this->commonFunction->Handle_Odds_Null($matchData,$models);
  312. //获取当前match_id
  313. $match_ids = [];
  314. foreach($matchData_new as $k=>$v){
  315. $match_ids[] = $v['match_id'];
  316. }
  317. //组装联赛下赛事
  318. $data = [];
  319. foreach ($leagueData as $k=>$v){
  320. $data[$k] = $v;
  321. foreach ($matchData_new as $kk=>$vv){
  322. if($v['lg_id'] == $vv['lg_id']){
  323. $data[$k]['matchData'][] = $vv;
  324. }
  325. }
  326. $matchNum = count($data[$k]['matchData']);
  327. $data[$k]['matchNum'] = $matchNum;
  328. }
  329. //去除 没有赛事的联赛
  330. if(!empty($data)){
  331. foreach($data as $k=>$v){
  332. if($v['matchNum'] < 1){
  333. unset($data[$k]);
  334. }
  335. }
  336. sort($data);
  337. }
  338. //获取滚球/即将赛事 默认 赔率数据
  339. $data = $this->getDefault($data,$ret['game_code'],$models,$match_ids,$source,$ret['type_code']);
  340. return $data;
  341. }
  342. /**
  343. * 获取即将数据
  344. */
  345. public function getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
  346. //获取当前状态下所有联赛
  347. $leagueData = leagueModel::getSoonLeagueData($source,$models,$where,$search);
  348. if(empty($leagueData)){
  349. return $leagueData=[];
  350. }
  351. //获取联赛id
  352. $lg_ids = [];
  353. foreach ($leagueData as $k => $v){
  354. $lg_ids[] = $v['lg_id'];
  355. }
  356. //统计联赛下的赛事及查询赛事
  357. $matchData = matchModel::getSoonMatchDataAll($source,$models,$where,$lg_ids);
  358. //如果赛事为空,直接返回
  359. if(empty($matchData)) return $matchData;
  360. //===获取当前赛事是否有赔率,如果没有则去除===
  361. $matchData_new = $this->commonFunction->Handle_Odds_Null($matchData,$models);
  362. //获取当前match_id
  363. $match_ids = [];
  364. foreach($matchData as $k=>$v){
  365. $match_ids[] = $v['match_id'];
  366. }
  367. //获取当前美东时间
  368. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  369. $data = [];
  370. foreach ($leagueData as $k=>$v){
  371. $data[$k] = $v;
  372. foreach ($matchData_new as $kk=>$vv){
  373. if($v['lg_id'] == $vv['lg_id']){
  374. $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
  375. $vv['wait_time'] = $wait_time;//追加距离开赛时间
  376. $data[$k]['matchData'][] = $vv;
  377. }
  378. }
  379. //获取当前联赛下赛事数量
  380. $matchNum = count($data[$k]['matchData']);
  381. $data[$k]['matchNum'] = $matchNum;
  382. }
  383. //去除联赛下没有赛事的联赛
  384. if(!empty($data)){
  385. foreach($data as $k=>$v){
  386. if($v['matchNum'] < 1){
  387. unset($data[$k]);
  388. }
  389. }
  390. sort($data);
  391. }
  392. //获取滚球/即将赛事 默认 赔率数据
  393. $data = $this->getDefault($data,$ret['game_code'],$models,$match_ids,$source);
  394. return $data;
  395. }
  396. /**
  397. * 获取今日数据
  398. */
  399. public function getToday($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=[]){
  400. //获取model
  401. $model_match = $models['model_match'];
  402. $model_odds = $models['model_odds'];
  403. $model_league = $models['model_league'];
  404. $model_result = $models['model_result'];
  405. //根据联赛id 获取联赛下 赛事赔率数据
  406. if($lg_id >0){
  407. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,'',$oddsTypeWhere);
  408. return $leagueData;
  409. }
  410. $data = $this->getMatch($source,$models,$search,$where);
  411. return $data;
  412. }
  413. /**
  414. * 获取早盘数据
  415. */
  416. public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere='',$type_code='',$game_code=''){
  417. //获取model
  418. $model_match = $models['model_match'];
  419. $model_odds = $models['model_odds'];
  420. $model_league = $models['model_league'];
  421. $model_result = $models['model_result'];
  422. //根据联赛id 获取联赛下 赛事赔率数据
  423. if($lg_id >0){
  424. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  425. return $leagueData;
  426. }
  427. $data = $this->getMatch($source,$models,$search,$where,$time,'',$type_code,$game_code);
  428. return $data;
  429. }
  430. /**
  431. * 获取串场数据
  432. */
  433. public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  434. //获取model
  435. $model_match = $models['model_match'];
  436. $model_odds = $models['model_odds'];
  437. $model_league = $models['model_league'];
  438. $model_result = $models['model_result'];
  439. //根据联赛id 获取联赛下 赛事赔率数据
  440. if($lg_id >0){
  441. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  442. return $leagueData;
  443. }
  444. $data = $this->getMatch($source,$models,$search,$where,$time,'','','',$oddsTypeWhere);
  445. return $data;
  446. }
  447. /**
  448. * 获取冠军数据
  449. */
  450. public function getChampion($source,$models,$where,$lg_id=0,$search='',$type_code=''){
  451. //获取model
  452. $model_odds = $models['model_odds'];
  453. $model_league = $models['model_league'];
  454. //根据联赛id 获取联赛下 冠军玩法盘口
  455. if($lg_id >0){
  456. $last_time = lm($model_league, 'Sports')
  457. ->select('last_time')
  458. ->where('id',$lg_id)
  459. ->first()->last_time;
  460. $championData = lm($model_odds, 'Sports')
  461. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  462. ->where('lg_id',$lg_id)
  463. ->where($where)
  464. ->where(['status'=>0])
  465. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  466. ->get()->toArray();
  467. //按p_code分组
  468. $p_code=array();
  469. foreach($championData as $k=>$v){
  470. $p_code[$v['p_code']][]=$v;
  471. }
  472. $sd = [];
  473. foreach ($p_code as $k1=>$v1){
  474. foreach ($v1 as $k2=>$v2){
  475. $sd[$v2['p_code']]['last_time'] =$last_time;
  476. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  477. }
  478. }
  479. return $sd;
  480. }
  481. //获取国家/洲下所有联赛及数量
  482. $data = $this->getMatch($source,$models,$search,$where,'',$type_code);
  483. return $data;
  484. }
  485. /**
  486. * 获取国家/洲 下联赛
  487. */
  488. public function getMatch($source,$models,$search,$where,$time='',$type_code='',$s_type_code='',$game_code='',$oddsTypeWhere=[]){
  489. //国家下所有联赛
  490. $country = lm($models['model_league'],"Sports")
  491. ->leftjoin('st_area_country','st_area_country.id',$models['model_league'].'.country_id')
  492. ->select('st_area_country.id as country_id','st_area_country.name as region')
  493. ->distinct('st_area_country.name')
  494. ->where([[$models['model_league'].'.name_chinese','!=','']])
  495. ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
  496. ->get()
  497. ->toArray();
  498. //洲下所有联赛
  499. $area = lm($models['model_league'],"Sports")
  500. ->leftjoin('st_area_country','st_area_country.id',$models['model_league'].'.area_id')
  501. ->select('st_area_country.id as area_id','st_area_country.name as region')
  502. ->distinct('st_area_country.name')
  503. ->where([[$models['model_league'].'.country_id','=',0]])
  504. ->where([[$models['model_league'].'.name_chinese','!=','']])
  505. ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
  506. ->get()
  507. ->toArray();
  508. if($type_code != 'StChampion'){//非冠军赛事
  509. $data = $this->getMatchNum($source,$country,$area,$models,$where,$search,$time,'',$s_type_code,$game_code,$oddsTypeWhere);
  510. }else{//冠军赛事
  511. $data = $this->getMatchStChampionNum($source,$country,$area,$models,$where,$search,$time);
  512. }
  513. return $data;
  514. }
  515. /**
  516. * 获取联赛下赛事 数量
  517. * 非冠军盘口
  518. */
  519. public function getMatchNum($source,$country,$area,$models,$where,$search,$time='',$type=0,$s_type_code='',$game_code='',$oddsTypeWhere=[]){
  520. $leagueData = lm($models['model_league'],'Sports')
  521. ->select('id as lg_id','name_chinese as league','country_id','area_id')
  522. ->where([[$models['model_league'].'.name_chinese','!=','']])
  523. ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
  524. ->get()
  525. ->toArray();
  526. //如果有时间条件
  527. $timeWhere = [];
  528. if(!empty($time)){
  529. if($time == 'other'){
  530. $timeWhere[] = ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
  531. }else{
  532. $timeWhere[] = ['match_date',$time];
  533. }
  534. }
  535. if($s_type_code == 'StMorningPlate' and $game_code !='zq'){
  536. $timeWhere[] = ['match_date','>',date('Y-m-d',time())];
  537. }
  538. //获取赛事
  539. $matchData = lm($models['model_match'],'Sports')
  540. ->select('id as match_id','lg_id')
  541. ->where($where)
  542. ->where($timeWhere)
  543. ->get()
  544. ->toArray();
  545. //如果赛事为空,直接返回
  546. if(empty($matchData)) return $matchData;
  547. //===获取当前赛事是否有赔率,如果没有则去除===
  548. $matchData_new = $this->commonFunction->Handle_Odds_Null($matchData,$models,$oddsTypeWhere);
  549. //按国家
  550. $countryData = [];
  551. if(!empty($country) and !empty($leagueData) and !empty($matchData_new)){
  552. foreach ($country as $k=>$v){
  553. if($v['country_id']){
  554. $countryData[$k] = $v;
  555. foreach ($leagueData as $kk=>$vv){
  556. if($v['country_id'] == $vv['country_id']){
  557. $countryData[$k]['league_count'][] = $vv;
  558. }
  559. }
  560. }
  561. }
  562. }
  563. //去除无联赛 国家
  564. foreach ($countryData as $k=>$v){
  565. if(count($v) == 2){
  566. unset($countryData[$k]);
  567. }
  568. }
  569. //按地区
  570. $areaData = [];
  571. if(!empty($area) and !empty($leagueData) and($matchData_new)){
  572. foreach ($area as $k=>$v){
  573. if($v['area_id']){
  574. $areaData[$k] = $v;
  575. foreach ($leagueData as $kk=>$vv){
  576. if($v['area_id'] == $vv['area_id'] and $vv['country_id'] == 0){
  577. $areaData[$k]['league_count'][] = $vv;
  578. }
  579. }
  580. }
  581. }
  582. }
  583. //去除无联赛 地区
  584. foreach ($areaData as $k=>$v){
  585. if(count($v) == 2){
  586. unset($areaData[$k]);
  587. }
  588. }
  589. $countryData = $this->commonFunction->array_other_tt($countryData,$matchData_new);
  590. $areaData = $this->commonFunction->array_other_tt($areaData,$matchData_new);
  591. $data = array_merge($countryData,$areaData);
  592. return $data;
  593. }
  594. /**
  595. * 获取联赛下赛事 数量
  596. * 冠军盘口
  597. */
  598. public function getMatchStChampionNum($source,$country,$area,$models,$where,$search,$time='',$type=0){
  599. $leagueData = lm($models['model_league'],'Sports')
  600. ->select('id as lg_id','name_chinese as league','country_id','area_id')
  601. ->where([[$models['model_league'].'.name_chinese','!=','']])
  602. ->where($models['model_league'].'.name_chinese','like','%'.$search.'%')
  603. ->get()
  604. ->toArray();
  605. $oddsData = lm($models['model_odds'],'Sports')
  606. ->select('id','lg_id','p_code')
  607. ->distinct("p_code")//去重
  608. ->where($where)
  609. ->where(['status'=>0])
  610. ->get()
  611. ->toArray();
  612. //按国家
  613. $countryData = [];
  614. if(!empty($country) and !empty($leagueData) and !empty($oddsData)){
  615. foreach ($country as $k=>$v){
  616. if($v['country_id']){
  617. $countryData[$k] = $v;
  618. foreach ($leagueData as $kk=>$vv){
  619. if($v['country_id'] == $vv['country_id']){
  620. $countryData[$k]['league_count'][] = $vv;
  621. }
  622. }
  623. }
  624. }
  625. }
  626. //去除无联赛 国家
  627. foreach ($countryData as $k=>$v){
  628. if(count($v) == 2){
  629. unset($countryData[$k]);
  630. }
  631. }
  632. //按地区
  633. $areaData = [];
  634. if(!empty($area) and !empty($leagueData) and($oddsData)){
  635. foreach ($area as $k=>$v){
  636. if($v['area_id']){
  637. $areaData[$k] = $v;
  638. foreach ($leagueData as $kk=>$vv){
  639. if($v['area_id'] == $vv['area_id'] and $vv['country_id'] == 0){
  640. $areaData[$k]['league_count'][] = $vv;
  641. }
  642. }
  643. }
  644. }
  645. }
  646. //去除无联赛 地区
  647. foreach ($areaData as $k=>$v){
  648. if(count($v) == 2){
  649. unset($areaData[$k]);
  650. }
  651. }
  652. $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
  653. $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
  654. $data = array_merge($countryData,$areaData);
  655. return $data;
  656. }
  657. /**
  658. * 获取联赛下 赛事赔率
  659. */
  660. public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
  661. $leagueData = lm($model_league,"Sports")
  662. ->select('id as lg_id','name_chinese as leagueName')
  663. ->where('id',$lg_id)
  664. ->first();
  665. //根据时间 拼装查询条件
  666. $whereTime = [];
  667. if(!empty($time)){
  668. if($time == 'other'){
  669. //其他时间(七天后)
  670. $whereTime = [
  671. ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))],
  672. ];
  673. }elseif($time == date('Y-m-d')){
  674. //今天
  675. $whereTime = [
  676. ['is_morningplate','=',1],
  677. ['match_date','=',$time],
  678. ['match_time','>',date("H:i:s", time())]
  679. ];
  680. }else{
  681. //今天以后 七天内
  682. $whereTime = [
  683. ['match_date','=',$time]
  684. ];
  685. }
  686. }
  687. $matchData = lm($model_match,"Sports")
  688. ->select($model_match.'.id as match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  689. ->where($model_match.'.lg_id',$lg_id)
  690. ->where($where)
  691. ->where($whereTime)
  692. ->where(function($query)use ($model_match,$search){
  693. $query->where($model_match.'.home_team','like','%'.$search.'%')
  694. ->orWhere(function($query)use ($model_match,$search) {
  695. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  696. });
  697. })
  698. ->get()
  699. ->toarray();
  700. //如果赛事为空,直接返回
  701. if(empty($matchData)) return $matchData;
  702. //===获取当前赛事是否有赔率,如果没有则去除===
  703. $models = ['model_odds'=>$model_odds];
  704. $matchData_new = $this->commonFunction->Handle_Odds_Null($matchData,$models,$oddsTypeWhere);
  705. //获取各球类默认赔率
  706. $game_code = $_REQUEST['game_code'];
  707. switch ($game_code) {
  708. case 'zq'://足球
  709. $matchData = $this->getOddsData->getOddsZQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
  710. break;
  711. case 'lq'://篮球
  712. $matchData = $this->getOddsData->getOddsLQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
  713. break;
  714. case 'wq'://网球
  715. $matchData = $this->getOddsData->getOddsWQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
  716. break;
  717. case 'bq'://棒球
  718. $matchData = $this->getOddsData->getOddsBQ($matchData_new, $model_odds, $source,$oddsTypeWhere);
  719. break;
  720. }
  721. $leagueData->matchNum = count($matchData);
  722. $leagueData->matchData = $matchData;
  723. return $leagueData;
  724. }
  725. /**
  726. * @param $source 数据源
  727. * @param $where 该状态 查询条件
  728. * @return array
  729. * @throws \Exception
  730. * 获取所有即将开赛 数据
  731. */
  732. public function getAllSoon($source,$where){
  733. $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  734. //获取当前美东时间
  735. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  736. $data=[];
  737. foreach ($game as $key=>$item){
  738. if($item['game_code'] !='gj'){
  739. $model = $this->commonFunction->getModels($item['game_code']);
  740. $matchData = lm($model['model_match'], 'Sports')
  741. ->select('id as match_id','home_team','guest_team','match_time','us_time')
  742. ->where($where)
  743. ->orderBy('match_time','asc')
  744. ->get()->toArray();
  745. //===获取当前赛事是否有赔率,如果没有则去除===
  746. $matchData = $this->commonFunction->Handle_Odds_Null($matchData,$model);
  747. $matchNum = count($matchData);
  748. $matchData = array_slice($matchData,0,6);
  749. foreach ($matchData as $key1 => $item1){
  750. //获取等待时间
  751. $wait_time = ceil(((strtotime($item1['us_time']))-$s_time)/60);
  752. $matchData[$key1]['wait_time'] = $wait_time;
  753. }
  754. if($matchNum > 0){
  755. $data[$item['game_code']]['matchData'] = $matchData;
  756. $data[$item['game_code']]['matchNum'] = $matchNum;
  757. $data[$item['game_code']]['gameName'] = $item['game_name'];
  758. $data[$item['game_code']]['gameCode'] = $item['game_code'];
  759. }
  760. }
  761. }
  762. return $data;
  763. }
  764. /**
  765. * 获取欧冠 各状态赛事数据
  766. */
  767. public function getUEFAChampions($source){
  768. //根据搜索查询
  769. if(!empty($_GET['search'])){
  770. $search = $_GET['search'];
  771. }
  772. $model = $this->commonFunction->getModels('gj',1);
  773. $model_league = $model['model_league'];
  774. $leagueData = lm($model_league,'Sports')
  775. ->select('name_chinese','id as lg_id','last_time')
  776. ->where($model_league.'.name_chinese','欧洲冠军杯')
  777. ->first();
  778. //获取滚球数据
  779. $StRollBall = $this->getUEFAStRollBall($model,'StRollBall',$source,$leagueData->lg_id,$search);
  780. //获取今日数据
  781. $StToday = $this->getUEFAStToday($model,'StToday',$source,$leagueData->lg_id,$search);
  782. //获取早盘数据
  783. $StMorningPlate = $this->getUEFAStMorningPlate($model,'StMorningPlate',$source,$leagueData->lg_id,$search);
  784. //获取冠军盘口数据
  785. $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
  786. $data = [
  787. 'lg_id' => $leagueData->lg_id,
  788. 'leagueName'=> $leagueData->name_chinese,
  789. 'StRollBall'=>[//滚球数据
  790. 'typeName'=>'滚球',
  791. 'matchNum'=>count($StRollBall),
  792. 'matchData'=>$StRollBall
  793. ],
  794. 'StToday'=>[//今日数据
  795. 'typeName'=>'今日',
  796. 'matchNum'=>count($StToday),
  797. 'matchData'=>$StToday
  798. ],
  799. 'StMorningPlate'=>[//早盘数据
  800. 'typeName'=>'早盘',
  801. 'matchNum'=>count($StMorningPlate),
  802. 'matchData'=>$StMorningPlate
  803. ],
  804. 'StChampion'=>[//冠军盘口
  805. 'typeName'=>'冠军盘口',
  806. 'matchNum'=>count($StChampion),
  807. 'matchData'=>$StChampion
  808. ]
  809. ];
  810. return $data;
  811. }
  812. /**
  813. * 获取欧冠 滚球数据
  814. */
  815. public function getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
  816. $model_match = $model['model_match'];
  817. $model_odds = $model['model_odds'];
  818. $model_result = $model['model_result'];
  819. $where = $this->commonFunction->getState($type_code,$model_match,'zq');
  820. $matchData = lm($model_match,"Sports")
  821. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.id')
  822. ->select($model_match.'.id as match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team','home_score','guest_score',$model_result.'.match_time as a_time','match_process')
  823. ->where($model_match.'.lg_id',$lg_id)
  824. ->where($where)
  825. ->where(function($query)use ($model_match,$search){
  826. $query->where($model_match.'.home_team','like','%'.$search.'%')
  827. ->orWhere(function($query)use ($model_match,$search) {
  828. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  829. });
  830. })
  831. ->get()
  832. ->toarray();
  833. //获取赛事id
  834. $match_ids = [];
  835. foreach ($matchData as $k => $v){
  836. $match_ids[] = $v['match_id'];
  837. }
  838. //获取赛事下滚球默认赔率
  839. $oddsData = ZQoddsModel::getMatchOdds($source,$model,$match_ids);
  840. foreach ($matchData as $k=>$v){
  841. //获取赛事下赔率并且分组
  842. $capot = [];
  843. $concede_size = [];
  844. foreach ($oddsData as $kk=>$vv){
  845. if ($vv['match_id'] == $v['match_id'] and $vv['sort']==0) {
  846. if($vv['p_code'] == 'concede_size'){
  847. $concede_size[] = $vv;
  848. }
  849. if($vv['p_code'] == 'capot'){
  850. $capot[] = $vv;
  851. }
  852. }
  853. }
  854. $matchData[$k]['oddsData'] = [$concede_size,$capot];
  855. }
  856. return $matchData;
  857. }
  858. /**
  859. * 获取欧冠 今日数据
  860. */
  861. public function getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
  862. $model_match = $model['model_match'];
  863. $model_odds = $model['model_odds'];
  864. $where = $this->commonFunction->getState($type_code,'','zq');
  865. $matchData = lm($model_match,'Sports')
  866. ->select('id as match_id','match_date','match_time','tag','home_team','guest_team')
  867. ->where($where)
  868. ->where('lg_id',$lg_id)
  869. ->where(function($query)use ($model_match,$search){
  870. $query->where($model_match.'.home_team','like','%'.$search.'%')
  871. ->orWhere(function($query)use ($model_match,$search) {
  872. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  873. });
  874. })
  875. ->get()->toArray();
  876. //获取赛事id
  877. $match_ids = [];
  878. foreach ($matchData as $k => $v){
  879. $match_ids[] = $v['match_id'];
  880. }
  881. //获取赔率数据
  882. $oddsData = lm($model_odds, "Sports")
  883. ->select( 'id','p_code', 'odds_code','odds_only','status', 'odds', 'condition', 'sort','match_id')
  884. ->whereIn('match_id', $match_ids)
  885. ->where(['status'=>0])
  886. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort','match_id')
  887. ->orderBy($model_odds . '.id','desc')
  888. ->get()
  889. ->toarray();
  890. foreach ($matchData as $k=>$v){
  891. foreach ($oddsData as $kk=>$vv){
  892. if($v['match_id'] == $vv['match_id']){
  893. $matchData[$k]['oddsData'][] = $vv;
  894. }
  895. }
  896. }
  897. return $matchData;
  898. }
  899. /**
  900. * 获取欧冠 早盘数据
  901. */
  902. public function getUEFAStMorningPlate($model,$type_code,$source,$lg_id,$search=''){
  903. $model_match = $model['model_match'];
  904. $model_odds = $model['model_odds'];
  905. $where = $this->commonFunction->getState($type_code,'','zq');
  906. $matchData = lm($model_match,'Sports')
  907. ->select('id as match_id','match_date','match_time','tag','home_team','guest_team')
  908. ->where($where)
  909. ->where('lg_id',$lg_id)
  910. ->where(function($query)use ($model_match,$search){
  911. $query->where($model_match.'.home_team','like','%'.$search.'%')
  912. ->orWhere(function($query)use ($model_match,$search) {
  913. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  914. });
  915. })
  916. ->get()->toArray();
  917. $data = $this->getOddsData->getOddsZQ($matchData,$model_odds,$source,[]);
  918. return $data;
  919. }
  920. /**
  921. * 获取 欧冠 冠军盘口数据
  922. */
  923. public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
  924. $model_odds = $model['model_odds'];
  925. $where = $this->commonFunction->getState($type_code,'','zq');
  926. $championData = lm($model_odds, 'Sports')
  927. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  928. ->where('lg_id',$lg_id)
  929. ->where($where)
  930. ->where(['status'=>0])
  931. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  932. ->get()->toArray();
  933. //按p_code分组
  934. $p_code=array();
  935. foreach($championData as $k=>$v){
  936. $p_code[$v['p_code']][]=$v;
  937. }
  938. $data = [];
  939. foreach ($p_code as $k1=>$v1){
  940. foreach ($v1 as $k2=>$v2){
  941. $data[$v2['p_code']]['last_time'] =$last_time;
  942. $data[$v2['p_code']][$v2['odds_code']][] = $v2;
  943. }
  944. }
  945. return $data;
  946. }
  947. }