GetmatchData.php 42 KB

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