GetmatchData.php 43 KB

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