GetmatchData.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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);
  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_morningplate','=',1],
  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_today','=',1],
  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. }else{
  63. if($ret['match_date'] != 'other'){
  64. $match_date = $ret['match_date'];
  65. }else{
  66. $match_date = 'other';
  67. }
  68. }
  69. $oddsTypeWhere = [
  70. [$models['model_odds'].'.is_morningplate','=',1],
  71. ];
  72. $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date,$oddsTypeWhere);
  73. break;
  74. case 'StStringScene'://串场
  75. $oddsTypeWhere = [
  76. [$models['model_odds'].'.is_stringscene','=',1],
  77. ];
  78. if(empty($ret['str_type']) || $ret['str_type'] ==0){//赛事
  79. $data = $this->getStringScene($source,$models,$where,$lg_id,$search,'',$oddsTypeWhere);
  80. }
  81. if($ret['str_type'] == 1){//参赛表
  82. }
  83. if($ret['str_type'] == 2){//冠军盘口
  84. $where = $this->commonFunction->getState('StChampion',$model_match);
  85. $data = $this->getChampion($source,$models,$where,$lg_id,$search,'StChampion');
  86. }
  87. break;
  88. case 'StChampion'://冠军
  89. $data = $this->getChampion($source,$models,$where,$lg_id,$search,$ret['type_code']);
  90. break;
  91. default:
  92. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  93. }
  94. return $data;
  95. }
  96. /**
  97. * 获取滚球数据
  98. */
  99. public function __getRollBall($source,$models,$where,$ret,$search=''){
  100. $model_match = $models['model_match'];
  101. $model_odds = $models['model_odds'];
  102. $model_league = $models['model_league'];
  103. $model_result = $models['model_result'];
  104. //当前状态下所有联赛
  105. $data = lm($model_league,"Sports")
  106. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  107. ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
  108. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  109. ->distinct($model_league.'.name_chinese')
  110. ->where($model_league.'.source',$source['source'])
  111. ->where($where)
  112. ->where(function($query)use ($model_match,$search){
  113. $query->where($model_match.'.home_team','like','%'.$search.'%')
  114. ->orWhere(function($query)use ($model_match,$search) {
  115. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  116. });
  117. })
  118. ->get()
  119. ->toarray();
  120. if(empty($data)){
  121. $data = [];
  122. return $data;
  123. }
  124. //统计联赛下的赛事及查询赛事
  125. foreach($data as $k => $v){
  126. $data[$k]['matchNum'] = lm($model_match,"Sports")
  127. ->where($source)
  128. ->where('lg_id',$v['lg_id'])
  129. ->where($where)
  130. ->count();
  131. $data[$k]['matchData'] = lm($model_match,"Sports")
  132. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  133. ->select($model_match.'.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')
  134. ->where($model_match.'.source',$source['source'])
  135. ->where($model_match.'.lg_id',$v['lg_id'])
  136. ->where($where)
  137. ->get()
  138. ->toarray();
  139. }
  140. foreach($data as $k => $v){
  141. foreach($v['matchData'] as $kk => $vv){
  142. $oddsData= lm($model_match,"Sports")
  143. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  144. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','odds_only','sort')
  145. ->where($model_match.'.source',$source['source'])
  146. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])//查询滚球赔率
  147. //->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  148. ->where(function($query)use ($model_odds){
  149. $query->where($model_odds.'.odds_code','concede_home')
  150. ->orWhere(function($query)use ($model_odds){
  151. $query->where($model_odds.'.odds_code','concede_guest');
  152. })
  153. ->orWhere(function($query)use ($model_odds){
  154. $query->where($model_odds.'.odds_code','size_home');
  155. })
  156. ->orWhere(function($query)use ($model_odds){
  157. $query->where($model_odds.'.odds_code','size_guest');
  158. })
  159. ->orWhere(function($query)use ($model_odds){
  160. $query->where($model_odds.'.odds_code','capot_home');
  161. })
  162. ->orWhere(function($query)use ($model_odds){
  163. $query->where($model_odds.'.odds_code','capot_dogfall');
  164. })
  165. ->orWhere(function($query)use ($model_odds){
  166. $query->where($model_odds.'.odds_code','capot_guest');
  167. });
  168. })
  169. ->get()
  170. ->toarray();
  171. //根据 排序 获取 最新让球/大小玩法赔率
  172. $sortData = array_column($oddsData,'sort');
  173. array_multisort($sortData,SORT_DESC,$oddsData);
  174. $zu = [];
  175. foreach ($oddsData as $key1 =>$item1){
  176. $zu[$item1['p_code']][] = $item1;
  177. }
  178. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  179. $capot = $zu['capot'];//独赢
  180. $capot = [$capot[0],$capot[2],$capot[1]];//排序
  181. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  182. }
  183. }
  184. return $data;
  185. }
  186. public function getRollBall($source,$models,$where,$ret,$search=''){
  187. //获取当前状态下所有联赛
  188. $leagueData = leagueModel::getRollLeagueData($source,$models,$where,$search);
  189. if(empty($leagueData)){
  190. return $leagueData=[];
  191. }
  192. //获取联赛id
  193. $lg_ids = [];
  194. foreach ($leagueData as $k => $v){
  195. $lg_ids[] = $v['lg_id'];
  196. }
  197. //统计联赛下的赛事及查询赛事
  198. $matchData = matchModel::getRollMatchDataAll($source,$models,$where,$lg_ids);
  199. //获取赛事id
  200. $match_ids = [];
  201. foreach ($matchData as $k => $v){
  202. $match_ids[] = $v['match_id'];
  203. }
  204. //获取赛事下滚球默认赔率
  205. $oddsData = ZQoddsModel::getMatchOdds($source,$models,$match_ids);
  206. $data = [];
  207. foreach ($leagueData as $k=>$v){
  208. $data[$k] = $v;
  209. foreach ($matchData as $kk=>$vv){
  210. if($v['lg_id'] == $vv['lg_id']){
  211. $data[$k]['matchData'][] = $vv;
  212. }
  213. }
  214. $data[$k]['matchNum'] = count($data[$k]['matchData']);
  215. }
  216. if($ret['game_code'] == 'wq') {
  217. $oddsData = WQoddsModel::getMatchOdds($source,$match_ids);
  218. foreach ($data as $k=>$v){
  219. foreach ($v['matchData'] as $kk=>$vv){
  220. //获取赛事下赔率并且分组
  221. $odds = [];
  222. foreach ($oddsData as $kkk=>$vvv) {
  223. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  224. $odds[] = $vvv;
  225. }
  226. }
  227. $data[$k]['matchData'][$kk]['oddsData'] = $odds;
  228. }
  229. }
  230. }else{
  231. foreach ($data as $k=>$v){
  232. foreach ($v['matchData'] as $kk=>$vv){
  233. //获取赛事下赔率并且分组
  234. $capot = [];
  235. $concede_size = [];
  236. foreach ($oddsData as $kkk=>$vvv) {
  237. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  238. if($vvv['odds_code'] == 'concede_guest' || $vvv['odds_code'] == 'concede_home' || $vvv['odds_code'] == 'goal_size_big' || $vvv['odds_code'] == 'goal_size_small'){
  239. $concede_size[] = $vvv;
  240. }
  241. if($vvv['p_code'] == 'capot'){
  242. $capot[] = $vvv;
  243. }
  244. }
  245. }
  246. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  247. }
  248. }
  249. }
  250. return $data;
  251. }
  252. /**
  253. * 获取即将数据
  254. */
  255. public function __getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
  256. $model_match = $models['model_match'];
  257. $model_odds = $models['model_odds'];
  258. $model_league = $models['model_league'];
  259. $model_result = $models['model_result'];
  260. //当前状态下所有联赛
  261. $data = lm($model_league,"Sports")
  262. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  263. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  264. ->distinct($model_league.'.name_chinese')
  265. ->where($model_league.'.source',$source['source'])
  266. ->where($where)
  267. ->where(function($query)use ($model_match,$search){
  268. $query->where($model_match.'.home_team','like','%'.$search.'%')
  269. ->orWhere(function($query)use ($model_match,$search) {
  270. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  271. });
  272. })
  273. ->get()
  274. ->toarray();
  275. if(empty($data)){
  276. $data = [];
  277. return $data;
  278. }
  279. //统计联赛下的赛事及查询赛事
  280. foreach($data as $k => $v){
  281. $data[$k]['matchNum'] = lm($model_match,"Sports")
  282. ->where($source)
  283. ->where('lg_id',$v['lg_id'])
  284. ->where($where)
  285. ->count();
  286. $data[$k]['matchData'] = lm($model_match,"Sports")
  287. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team',$model_match.'.us_time')
  288. ->where($source)
  289. ->where($model_match.'.lg_id',$v['lg_id'])
  290. ->where($where)
  291. ->orderBy('match_time','asc')
  292. ->get()
  293. ->toarray();
  294. }
  295. //获取当前美东时间
  296. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  297. //获取足球即将默认玩法赔率
  298. if($ret['game_code'] == 'zq'){
  299. foreach($data as $k => $v){
  300. foreach($v['matchData'] as $kk => $vv){
  301. $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
  302. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  303. $oddsData= lm($model_match,"Sports")
  304. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  305. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  306. ->where($model_match.'.source',$source['source'])
  307. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  308. // ->where($oddsTypeWhere)
  309. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  310. ->where(function($query)use ($model_odds){
  311. $query->where($model_odds.'.odds_code','concede_home')
  312. ->orWhere(function($query)use ($model_odds){
  313. $query->where($model_odds.'.odds_code','concede_guest');
  314. })
  315. ->orWhere(function($query)use ($model_odds){
  316. $query->where($model_odds.'.odds_code','total_size_small');
  317. })
  318. ->orWhere(function($query)use ($model_odds){
  319. $query->where($model_odds.'.odds_code','total_size_big');
  320. })
  321. ->orWhere(function($query)use ($model_odds){
  322. $query->where($model_odds.'.odds_code','capot_home');
  323. })
  324. ->orWhere(function($query)use ($model_odds){
  325. $query->where($model_odds.'.odds_code','capot_dogfall');
  326. })
  327. ->orWhere(function($query)use ($model_odds){
  328. $query->where($model_odds.'.odds_code','capot_guest');
  329. });
  330. })
  331. ->get()
  332. ->toarray();
  333. //根据 排序 获取 最新让球/大小玩法赔率
  334. $sortData = array_column($oddsData,'sort');
  335. array_multisort($sortData,SORT_ASC,$oddsData);
  336. $zu = [];
  337. foreach ($oddsData as $key1 =>$item1){
  338. $zu[$item1['p_code']][] = $item1;
  339. }
  340. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  341. $capot = $zu['capot'];//独赢
  342. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  343. }
  344. }
  345. }
  346. //获取网球即将默认玩法赔率
  347. if($ret['game_code'] == 'wq'){
  348. foreach($data as $k => $v){
  349. $matchData = $this->getOddsData->getOddsWQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  350. $data[$k]['matchData'] = $matchData;
  351. }
  352. }
  353. //获取篮球即将默认玩法赔率
  354. if($ret['game_code'] == 'lq'){
  355. foreach($data as $k => $v){
  356. foreach($v['matchData'] as $kk => $vv){
  357. $wait_time = ceil(((strtotime( $vv['match_time']))-time())/60);
  358. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  359. $oddsData= lm($model_match,"Sports")
  360. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  361. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  362. ->where($model_match.'.source',$source['source'])
  363. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  364. // ->where($oddsTypeWhere)
  365. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  366. ->where(function($query)use ($model_odds){
  367. $query->where($model_odds.'.odds_code','concede_home')
  368. ->orWhere(function($query)use ($model_odds){
  369. $query->where($model_odds.'.odds_code','concede_guest');
  370. })
  371. ->orWhere(function($query)use ($model_odds){
  372. $query->where($model_odds.'.odds_code','total_sizes_big');
  373. })
  374. ->orWhere(function($query)use ($model_odds){
  375. $query->where($model_odds.'.odds_code','total_sizes_small');
  376. })
  377. ->orWhere(function($query)use ($model_odds){
  378. $query->where($model_odds.'.odds_code','capot_home');
  379. })
  380. ->orWhere(function($query)use ($model_odds){
  381. $query->where($model_odds.'.odds_code','capot_dogfall');
  382. })
  383. ->orWhere(function($query)use ($model_odds){
  384. $query->where($model_odds.'.odds_code','capot_guest');
  385. });
  386. })
  387. ->get()
  388. ->toarray();
  389. //根据 排序 获取 最新让球/大小玩法赔率
  390. $sortData = array_column($oddsData,'sort');
  391. array_multisort($sortData,SORT_ASC,$oddsData);
  392. $zu = [];
  393. foreach ($oddsData as $key1 =>$item1){
  394. $zu[$item1['p_code']][] = $item1;
  395. }
  396. $c_s['concede'] = array_slice($zu['concede'],0,2);//让球 前四条 放入
  397. $c_s['total_size'] = array_slice($zu['total_size'],0,2);//让球 前四条 放入
  398. $capot = $zu['capot'];//独赢
  399. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  400. }
  401. // $matchData = $this->getOddsData->getOddsLQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  402. // $data[$k]['matchData'] = $matchData;
  403. }
  404. }
  405. //获取棒球即将默认玩法赔率
  406. if($ret['game_code'] == 'bq'){
  407. foreach($data as $k => $v){
  408. $matchData = $this->getOddsData->getOddsBQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  409. $data[$k]['matchData'] = $matchData;
  410. }
  411. }
  412. return $data;
  413. }
  414. public function getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
  415. //获取当前状态下所有联赛
  416. $leagueData = leagueModel::getSoonLeagueData($source,$models,$where,$search);
  417. if(empty($leagueData)){
  418. return $leagueData=[];
  419. }
  420. //获取联赛id
  421. $lg_ids = [];
  422. foreach ($leagueData as $k => $v){
  423. $lg_ids[] = $v['lg_id'];
  424. }
  425. //统计联赛下的赛事及查询赛事
  426. $matchData = matchModel::getSoonMatchDataAll($source,$models,$where,$lg_ids);
  427. //获取赛事id
  428. $match_ids = [];
  429. foreach ($matchData as $k => $v){
  430. $match_ids[] = $v['match_id'];
  431. }
  432. //获取当前美东时间
  433. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  434. $data = [];
  435. foreach ($leagueData as $k=>$v){
  436. $data[$k] = $v;
  437. foreach ($matchData as $kk=>$vv){
  438. if($v['lg_id'] == $vv['lg_id']){
  439. $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
  440. $vv['wait_time'] = $wait_time;//追加距离开赛时间
  441. $data[$k]['matchData'][] = $vv;
  442. }
  443. }
  444. $data[$k]['matchNum'] = count($data[$k]['matchData']);
  445. }
  446. if($ret['game_code'] == 'zq') {
  447. //获取赛事下默认赔率
  448. $oddsData = ZQoddsModel::getMatchOdds($source, $models,$match_ids);
  449. foreach ($data as $k=>$v){
  450. foreach ($v['matchData'] as $kk=>$vv){
  451. //获取赛事下赔率并且分组
  452. $capot = [];
  453. $concede_size = [];
  454. foreach ($oddsData as $kkk=>$vvv) {
  455. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  456. if($vvv['odds_code'] == 'concede_guest'){
  457. $concede_g = $vvv;
  458. }
  459. if($vvv['odds_code'] == 'concede_home'){
  460. $concede_h = $vvv;
  461. }
  462. if($vvv['odds_code'] == 'goal_size_big'){
  463. $size_s = $vvv;
  464. }
  465. if($vvv['odds_code'] == 'goal_size_small'){
  466. $size_b = $vvv;
  467. }
  468. if($vvv['odds_code'] == 'capot_home'){
  469. $capot_h = $vvv;
  470. }
  471. if($vvv['odds_code'] == 'capot_dogfall'){
  472. $capot_d = $vvv;
  473. }
  474. if($vvv['odds_code'] == 'capot_guest'){
  475. $capot_g = $vvv;
  476. }
  477. }
  478. }
  479. $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
  480. $capot = [$capot_h,$capot_d,$capot_g];
  481. foreach ($concede_size as $key => $vaule){
  482. if($vaule == null) unset($concede_size[$key]);
  483. }
  484. foreach ($capot as $key1 => $vaule1){
  485. if($vaule1 == null) unset($capot[$key1]);
  486. }
  487. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  488. }
  489. }
  490. }
  491. if($ret['game_code'] == 'lq') {
  492. $oddsData = LQoddsModel::getMatchOdds($source,$match_ids);
  493. foreach ($data as $k=>$v){
  494. foreach ($v['matchData'] as $kk=>$vv){
  495. //获取赛事下赔率并且分组
  496. $capot = [];
  497. $total_size = [];
  498. $concede = [];
  499. foreach ($oddsData as $kkk=>$vvv) {
  500. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  501. if($vvv['p_code'] == 'capot'){
  502. $capot[] = $vvv;
  503. }else{
  504. if($vvv['p_code'] == 'total_size'){
  505. $total_size[] = $vvv;
  506. }
  507. if($vvv['p_code'] == 'concede'){
  508. $concede[] = $vvv;
  509. }
  510. }
  511. }
  512. }
  513. $concede_size = [$concede[0],$concede[1],$total_size[0],$total_size[1]];
  514. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  515. }
  516. }
  517. }
  518. if($ret['game_code'] == 'wq') {
  519. $oddsData = WQoddsModel::getMatchOdds($source,$match_ids);
  520. foreach ($data as $k=>$v){
  521. foreach ($v['matchData'] as $kk=>$vv){
  522. //获取赛事下赔率并且分组
  523. $odds = [];
  524. foreach ($oddsData as $kkk=>$vvv) {
  525. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  526. $odds[] = $vvv;
  527. }
  528. }
  529. $data[$k]['matchData'][$kk]['oddsData'] = $odds;
  530. }
  531. }
  532. }
  533. if($ret['game_code'] == 'bq') {
  534. $oddsData = BQoddsModel::getMatchOdds($source,$match_ids);
  535. foreach ($data as $k=>$v){
  536. foreach ($v['matchData'] as $kk=>$vv){
  537. //获取赛事下赔率并且分组
  538. $odds = [];
  539. foreach ($oddsData as $kkk=>$vvv) {
  540. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  541. if($vvv['odds_code'] == 'concede_guest'){
  542. $concede_g = $vvv;
  543. }
  544. if($vvv['odds_code'] == 'concede_home'){
  545. $concede_h = $vvv;
  546. }
  547. if($vvv['odds_code'] == 'total_size_small'){
  548. $size_s = $vvv;
  549. }
  550. if($vvv['odds_code'] == 'total_size_big'){
  551. $size_b = $vvv;
  552. }
  553. if($vvv['odds_code'] == 'capot_home'){
  554. $capot_h = $vvv;
  555. }
  556. if($vvv['odds_code'] == 'capot_guest'){
  557. $capot_g = $vvv;
  558. }
  559. }
  560. }
  561. $concede_size = [$concede_g,$concede_h,$size_s,$size_b];
  562. $capot = [$capot_h,$capot_g];
  563. foreach ($concede_size as $key => $vaule){
  564. if($vaule == null) unset($concede_size[$key]);
  565. }
  566. foreach ($capot as $key1 => $vaule1){
  567. if($vaule1 == null) unset($capot[$key1]);
  568. }
  569. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  570. }
  571. }
  572. }
  573. return $data;
  574. }
  575. /**
  576. * 获取今日数据
  577. */
  578. public function getToday($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=[]){
  579. //获取model
  580. $model_match = $models['model_match'];
  581. $model_odds = $models['model_odds'];
  582. $model_league = $models['model_league'];
  583. $model_result = $models['model_result'];
  584. //根据联赛id 获取联赛下 赛事赔率数据
  585. if($lg_id >0){
  586. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,'',$oddsTypeWhere);
  587. return $leagueData;
  588. }
  589. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
  590. return $data;
  591. }
  592. /**
  593. * 获取早盘数据
  594. */
  595. public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  596. //获取model
  597. $model_match = $models['model_match'];
  598. $model_odds = $models['model_odds'];
  599. $model_league = $models['model_league'];
  600. $model_result = $models['model_result'];
  601. //根据联赛id 获取联赛下 赛事赔率数据
  602. if($lg_id >0){
  603. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  604. return $leagueData;
  605. }
  606. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  607. return $data;
  608. }
  609. /**
  610. * 获取串场数据
  611. */
  612. public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  613. //获取model
  614. $model_match = $models['model_match'];
  615. $model_odds = $models['model_odds'];
  616. $model_league = $models['model_league'];
  617. $model_result = $models['model_result'];
  618. //根据联赛id 获取联赛下 赛事赔率数据
  619. if($lg_id >0){
  620. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  621. return $leagueData;
  622. }
  623. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  624. return $data;
  625. }
  626. /**
  627. * 获取冠军数据
  628. */
  629. public function getChampion($source,$models,$where,$lg_id=0,$search='',$type_code=''){
  630. //获取model
  631. $model_odds = $models['model_odds'];
  632. $model_league = $models['model_league'];
  633. //根据联赛id 获取联赛下 冠军玩法盘口
  634. if($lg_id >0){
  635. $last_time = lm($model_league, 'Sports')
  636. ->select('last_time')
  637. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  638. ->where($source)
  639. ->where('lg_id',$lg_id)
  640. ->first()->last_time;
  641. $championData = lm($model_odds, 'Sports')
  642. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  643. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  644. ->where($source)
  645. ->where('lg_id',$lg_id)
  646. ->where($where)
  647. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  648. ->get()->toArray();
  649. //按p_code分组
  650. $p_code=array();
  651. foreach($championData as $k=>$v){
  652. $p_code[$v['p_code']][]=$v;
  653. }
  654. $sd = [];
  655. foreach ($p_code as $k1=>$v1){
  656. foreach ($v1 as $k2=>$v2){
  657. $sd[$v2['p_code']]['last_time'] =$last_time;
  658. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  659. }
  660. }
  661. return $sd;
  662. }
  663. //获取国家/洲下所有联赛及数量
  664. $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'',$type_code);
  665. return $data;
  666. }
  667. /**
  668. * 获取国家/洲 下联赛
  669. */
  670. public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time='',$type_code=''){
  671. //国家下所有联赛
  672. $country = lm($model_league,"Sports")
  673. ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
  674. ->select('st_country.country_id','st_country.name_chinese as region')
  675. // ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  676. ->distinct('st_country.name_chinese')
  677. ->where([[$model_league.'.name_chinese','!=','']])
  678. ->where($model_league.'.source',$source['source'])
  679. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  680. ->get()
  681. ->toArray();
  682. //洲下所有联赛
  683. $area = lm($model_league,"Sports")
  684. ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
  685. ->select('st_area.id as area_id','st_area.title as region')
  686. // ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  687. ->distinct('st_area.title')
  688. ->where([[$model_league.'.name_chinese','!=','']])
  689. ->where($model_league.'.source',$source['source'])
  690. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  691. ->get()
  692. ->toArray();
  693. if($type_code != 'StChampion'){//非冠军赛事
  694. $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  695. }else{//冠军赛事
  696. $data = $this->getMatchStChampionNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  697. }
  698. return $data;
  699. }
  700. /**
  701. * 获取联赛下赛事 数量
  702. * 非冠军盘口
  703. */
  704. public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  705. $leagueData = lm($model_league,'Sports')
  706. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  707. ->where($source)
  708. ->where([[$model_league.'.name_chinese','!=','']])
  709. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  710. ->get()
  711. ->toArray();
  712. $timeWhere = [];
  713. if(!empty($time)){
  714. if($time == 'other'){
  715. $timeWhere[] = ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
  716. }else{
  717. $timeWhere[] = ['match_date',$time];
  718. }
  719. }
  720. $matchData = lm($model_match,'Sports')
  721. ->select('id','lg_id','match_id')
  722. ->where($where)
  723. ->where($source)
  724. ->where($timeWhere)
  725. ->get()
  726. ->toArray();
  727. //按国家
  728. $countryData = [];
  729. if(!empty($country) and !empty($leagueData) and !empty($matchData)){
  730. foreach ($country as $k=>$v){
  731. if($v['country_id']){
  732. $countryData[$k] = $v;
  733. foreach ($leagueData as $kk=>$vv){
  734. if($v['country_id'] == $vv['country_id']){
  735. $countryData[$k]['league_count'][] = $vv;
  736. }
  737. }
  738. }
  739. }
  740. }
  741. //去除无联赛 国家
  742. foreach ($countryData as $k=>$v){
  743. if(count($v) == 2){
  744. unset($countryData[$k]);
  745. }
  746. }
  747. //按地区
  748. $areaData = [];
  749. if(!empty($area) and !empty($leagueData) and($matchData)){
  750. foreach ($area as $k=>$v){
  751. if($v['area_id']){
  752. $areaData[$k] = $v;
  753. foreach ($leagueData as $kk=>$vv){
  754. if($v['area_id'] == $vv['area_id']){
  755. $areaData[$k]['league_count'][] = $vv;
  756. }
  757. }
  758. }
  759. }
  760. }
  761. //去除无联赛 地区
  762. foreach ($areaData as $k=>$v){
  763. if(count($v) == 2){
  764. unset($areaData[$k]);
  765. }
  766. }
  767. $countryData = $this->commonFunction->array_other_tt($countryData,$matchData);
  768. $areaData = $this->commonFunction->array_other_tt($areaData,$matchData);
  769. $data = array_merge($countryData,$areaData);
  770. return $data;
  771. }
  772. /**
  773. * 弃用 获取联赛下赛事 数量
  774. * 非冠军盘口
  775. */
  776. public function __getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  777. //统计国家下联赛-赛事/盘口数量
  778. if(!empty($country)){
  779. foreach($country as $k => $v) {
  780. $country[$k]['league_count'] = lm($model_league, 'Sports')
  781. ->select('lg_id', 'name_chinese as league')
  782. ->where($source)
  783. ->where('country_id', $v['country_id'])
  784. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  785. ->get()->toarray();
  786. }
  787. foreach ($country as $k => $v) {
  788. foreach($v['league_count'] as $kk => $vv ){
  789. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  790. if(empty($time)){
  791. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  792. ->select("match_id")
  793. ->where($source)
  794. ->where('lg_id',$vv['lg_id'])
  795. ->where($where)
  796. ->count("*");
  797. }else{//早盘 下有时间查询
  798. if($time == 'other'){//早盘 一周后
  799. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  800. ->select("match_id")
  801. ->where($source)
  802. ->where('lg_id',$vv['lg_id'])
  803. ->where($where)
  804. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  805. ->count("*");
  806. }else{
  807. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  808. ->select("match_id")
  809. ->where($source)
  810. ->where('lg_id',$vv['lg_id'])
  811. ->where($where)
  812. ->where('match_date',$time)
  813. ->count("*");
  814. }
  815. }
  816. }
  817. if($country[$k]['league_count'][$kk]['count'] == 0){
  818. unset($country[$k]['league_count'][$kk]);
  819. }
  820. }
  821. }
  822. }
  823. //统计 地区 联赛-赛事/盘口数量
  824. if(!empty($area)){
  825. foreach($area as $k => $v) {
  826. $area[$k]['league_count'] = lm($model_league, 'Sports')
  827. ->select('lg_id', 'name_chinese as league')
  828. ->where($source)
  829. ->where('area_id', $v['area_id'])
  830. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  831. ->get()->toarray();
  832. }
  833. foreach ($area as $k => $v) {
  834. foreach($v['league_count'] as $kk => $vv ){
  835. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  836. if(empty($time)){
  837. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  838. ->select("match_id")
  839. ->where($source)
  840. ->where('lg_id',$vv['lg_id'])
  841. ->where($where)
  842. ->count("*");
  843. }else {
  844. if ($time == 'other') {// 今日 一周后
  845. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  846. ->select("match_id")
  847. ->where($source)
  848. ->where('lg_id', $vv['lg_id'])
  849. ->where($where)
  850. ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
  851. ->count("*");
  852. } else {//今日 大于今日
  853. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  854. ->select("match_id")
  855. ->where($source)
  856. ->where('lg_id',$vv['lg_id'])
  857. ->where($where)
  858. ->where('match_date',$time)
  859. ->count("*");
  860. }
  861. }
  862. }
  863. if($area[$k]['league_count'][$kk]['count'] == 0){
  864. unset($area[$k]['league_count'][$kk]);
  865. }
  866. }
  867. }
  868. }
  869. //处理空联赛国家
  870. $countryData = $this->commonFunction->handleArr($country);
  871. $areaData = $this->commonFunction->handleArr($area);
  872. //合并数组
  873. $data = array_merge($countryData,$areaData);
  874. return $data;
  875. }
  876. /**
  877. * 获取联赛下赛事 数量
  878. * 冠军盘口
  879. */
  880. public function getMatchStChampionNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  881. $leagueData = lm($model_league,'Sports')
  882. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  883. ->where($source)
  884. ->where([[$model_league.'.name_chinese','!=','']])
  885. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  886. ->get()
  887. ->toArray();
  888. $oddsData = lm($model_odds,'Sports')
  889. ->select('id','lg_id','p_code')
  890. ->distinct("p_code")//去重
  891. ->where($where)
  892. ->where($source)
  893. ->get()
  894. ->toArray();
  895. //按国家
  896. $countryData = [];
  897. if(!empty($country) and !empty($leagueData) and !empty($oddsData)){
  898. foreach ($country as $k=>$v){
  899. if($v['country_id']){
  900. $countryData[$k] = $v;
  901. foreach ($leagueData as $kk=>$vv){
  902. if($v['country_id'] == $vv['country_id']){
  903. $countryData[$k]['league_count'][] = $vv;
  904. }
  905. }
  906. }
  907. }
  908. }
  909. //去除无联赛 国家
  910. foreach ($countryData as $k=>$v){
  911. if(count($v) == 2){
  912. unset($countryData[$k]);
  913. }
  914. }
  915. //按地区
  916. $areaData = [];
  917. if(!empty($area) and !empty($leagueData) and($oddsData)){
  918. foreach ($area as $k=>$v){
  919. if($v['area_id']){
  920. $areaData[$k] = $v;
  921. foreach ($leagueData as $kk=>$vv){
  922. if($v['area_id'] == $vv['area_id']){
  923. $areaData[$k]['league_count'][] = $vv;
  924. }
  925. }
  926. }
  927. }
  928. }
  929. //去除无联赛 地区
  930. foreach ($areaData as $k=>$v){
  931. if(count($v) == 2){
  932. unset($areaData[$k]);
  933. }
  934. }
  935. $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
  936. $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
  937. $data = array_merge($countryData,$areaData);
  938. return $data;
  939. }
  940. /**
  941. * 获取联赛下 赛事赔率
  942. */
  943. public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
  944. $leagueData = lm($model_league,"Sports")
  945. ->select('lg_id','name_chinese as leagueName')
  946. ->where($source)
  947. ->where('lg_id',$lg_id)
  948. ->first();
  949. // dd(1213);
  950. //根据时间 拼装查询条件
  951. $whereTime = [];
  952. if(!empty($time)){
  953. if($time == 'other'){
  954. //其他时间(七天后)
  955. $whereTime = [
  956. ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))],
  957. ];
  958. }elseif($time == date('Y-m-d')){
  959. //今天
  960. $whereTime = [
  961. ['is_morningplate','=',1],
  962. ['match_date','=',$time],
  963. ['match_time','>',date("H:i:s", time())]
  964. ];
  965. }else{
  966. //今天以后 七天内
  967. $whereTime = [
  968. ['match_date','=',$time]
  969. ];
  970. }
  971. }
  972. $matchData = lm($model_match,"Sports")
  973. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  974. ->where($source)
  975. ->where($model_match.'.lg_id',$lg_id)
  976. ->where($where)
  977. ->where($whereTime)
  978. ->where(function($query)use ($model_match,$search){
  979. $query->where($model_match.'.home_team','like','%'.$search.'%')
  980. ->orWhere(function($query)use ($model_match,$search) {
  981. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  982. });
  983. })
  984. ->get()
  985. ->toarray();
  986. //获取各球类默认赔率
  987. $game_code = $_REQUEST['game_code'];
  988. switch ($game_code) {
  989. case 'zq'://足球
  990. $matchData = $this->getOddsData->getOddsZQ($matchData, $model_odds, $source,$oddsTypeWhere);
  991. break;
  992. case 'lq'://篮球
  993. $matchData = $this->getOddsData->getOddsLQ($matchData, $model_odds, $source,$oddsTypeWhere);
  994. break;
  995. case 'wq'://网球
  996. $matchData = $this->getOddsData->getOddsWQ($matchData, $model_odds, $source,$oddsTypeWhere);
  997. break;
  998. case 'bq'://棒球
  999. $matchData = $this->getOddsData->getOddsBQ($matchData, $model_odds, $source,$oddsTypeWhere);
  1000. break;
  1001. }
  1002. $leagueData->matchNum = count($matchData);
  1003. $leagueData->matchData = $matchData;
  1004. return $leagueData;
  1005. }
  1006. /**
  1007. * @param $source 数据源
  1008. * @param $where 该状态 查询条件
  1009. * @return array
  1010. * @throws \Exception
  1011. * 获取所有即将开赛 数据
  1012. */
  1013. public function getAllSoon($source,$where){
  1014. $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  1015. //获取当前美东时间
  1016. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  1017. $data=[];
  1018. foreach ($game as $key=>$item){
  1019. if($item['game_code'] !='gj'){
  1020. $model = $this->commonFunction->getModels($item['game_code']);
  1021. $matchData = lm($model['model_match'], 'Sports')
  1022. ->select('match_id','home_team','guest_team','match_time','us_time')
  1023. ->where($source)
  1024. ->where($where)
  1025. ->orderBy('match_time','asc')
  1026. // ->limit(6)
  1027. ->get()->toArray();
  1028. $matchNum = count($matchData);
  1029. $matchData = array_slice($matchData,0,6);
  1030. foreach ($matchData as $key1 => $item1){
  1031. //获取等待时间
  1032. $wait_time = ceil(((strtotime($item1['us_time']))-$s_time)/60);
  1033. $matchData[$key1]['wait_time'] = $wait_time;
  1034. }
  1035. if($matchNum > 0){
  1036. // $matchData = array_multisort(array_column($matchData,'wait_time'),SOTR_ASC,$matchData);
  1037. $data[$item['game_code']]['matchData'] = $matchData;
  1038. $data[$item['game_code']]['matchNum'] = $matchNum;
  1039. $data[$item['game_code']]['gameName'] = $item['game_name'];
  1040. $data[$item['game_code']]['gameCode'] = $item['game_code'];
  1041. }
  1042. }
  1043. }
  1044. return $data;
  1045. }
  1046. /**
  1047. * 获取欧冠 各状态赛事数据
  1048. */
  1049. public function getUEFAChampions($source){
  1050. //根据搜索查询
  1051. if(!empty($_GET['search'])){
  1052. $search = $_GET['search'];
  1053. }
  1054. $model = $this->commonFunction->getModels('gj',1);
  1055. $model_league = $model['model_league'];
  1056. $leagueData = lm($model_league,'Sports')
  1057. ->select('name_chinese','lg_id','last_time')
  1058. ->where($model_league.'.source',$source['source'])
  1059. ->where($model_league.'.name_chinese','欧洲冠军杯')
  1060. ->first();
  1061. //获取滚球数据
  1062. $StRollBall = $this->getUEFAStRollBall($model,'StRollBall',$source,$leagueData->lg_id,$search);
  1063. //获取今日数据
  1064. $StToday = $this->getUEFAStToday($model,'StToday',$source,$leagueData->lg_id,$search);
  1065. //获取早盘数据
  1066. $StMorningPlate = $this->getUEFAStMorningPlate($model,'StMorningPlate',$source,$leagueData->lg_id,$search);
  1067. //获取冠军盘口数据
  1068. $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
  1069. $data = [
  1070. 'lg_id' => $leagueData->lg_id,
  1071. 'leagueName'=> $leagueData->name_chinese,
  1072. 'StRollBall'=>[//滚球数据
  1073. 'typeName'=>'滚球',
  1074. 'matchNum'=>count($StRollBall),
  1075. 'matchData'=>$StRollBall
  1076. ],
  1077. 'StToday'=>[//今日数据
  1078. 'typeName'=>'今日',
  1079. 'matchNum'=>count($StToday),
  1080. 'matchData'=>$StToday
  1081. ],
  1082. 'StMorningPlate'=>[//早盘数据
  1083. 'typeName'=>'早盘',
  1084. 'matchNum'=>count($StMorningPlate),
  1085. 'matchData'=>$StMorningPlate
  1086. ],
  1087. 'StChampion'=>[//冠军盘口
  1088. 'typeName'=>'冠军盘口',
  1089. 'matchNum'=>count($StChampion),
  1090. 'matchData'=>$StChampion
  1091. ]
  1092. ];
  1093. return $data;
  1094. }
  1095. /**
  1096. * 获取欧冠 滚球数据
  1097. */
  1098. public function __getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
  1099. $model_match = $model['model_match'];
  1100. $model_odds = $model['model_odds'];
  1101. $model_result = $model['model_result'];
  1102. $where = $this->commonFunction->getState($type_code,$model_match);
  1103. $matchData = lm($model_match,"Sports")
  1104. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  1105. ->select($model_match.'.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')
  1106. ->where($model_match.'.source',$source['source'])
  1107. ->where($model_match.'.lg_id',$lg_id)
  1108. ->where($where)
  1109. ->where(function($query)use ($model_match,$search){
  1110. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1111. ->orWhere(function($query)use ($model_match,$search) {
  1112. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1113. });
  1114. })
  1115. ->get()
  1116. ->toarray();
  1117. foreach($matchData as $kk => $vv){
  1118. $oddsData= lm($model_match,"Sports")
  1119. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  1120. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  1121. ->where($model_match.'.source',$source['source'])
  1122. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  1123. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1124. ->where(function($query)use ($model_odds){
  1125. $query->where($model_odds.'.odds_code','concede_home')
  1126. ->orWhere(function($query)use ($model_odds){
  1127. $query->where($model_odds.'.odds_code','concede_guest');
  1128. })
  1129. ->orWhere(function($query)use ($model_odds){
  1130. $query->where($model_odds.'.odds_code','size_home');
  1131. })
  1132. ->orWhere(function($query)use ($model_odds){
  1133. $query->where($model_odds.'.odds_code','size_guest');
  1134. })
  1135. ->orWhere(function($query)use ($model_odds){
  1136. $query->where($model_odds.'.odds_code','capot_home');
  1137. })
  1138. ->orWhere(function($query)use ($model_odds){
  1139. $query->where($model_odds.'.odds_code','capot_dogfall');
  1140. })
  1141. ->orWhere(function($query)use ($model_odds){
  1142. $query->where($model_odds.'.odds_code','capot_guest');
  1143. });
  1144. })
  1145. ->get()
  1146. ->toarray();
  1147. //根据 排序 获取 最新让球/大小玩法赔率
  1148. $sortData = array_column($oddsData,'sort');
  1149. array_multisort($sortData,SORT_ASC,$oddsData);
  1150. $zu = [];
  1151. foreach ($oddsData as $key1 =>$item1){
  1152. $zu[$item1['p_code']][] = $item1;
  1153. }
  1154. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  1155. $capot = $zu['capot'];//独赢
  1156. $matchData[$kk]['oddsData'] = [$c_s,$capot];
  1157. }
  1158. return $matchData;
  1159. }
  1160. public function getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
  1161. $model_match = $model['model_match'];
  1162. $model_odds = $model['model_odds'];
  1163. $model_result = $model['model_result'];
  1164. $where = $this->commonFunction->getState($type_code,$model_match);
  1165. $matchData = lm($model_match,"Sports")
  1166. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  1167. ->select($model_match.'.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')
  1168. ->where($model_match.'.source',$source['source'])
  1169. ->where($model_match.'.lg_id',$lg_id)
  1170. ->where($where)
  1171. ->where(function($query)use ($model_match,$search){
  1172. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1173. ->orWhere(function($query)use ($model_match,$search) {
  1174. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1175. });
  1176. })
  1177. ->get()
  1178. ->toarray();
  1179. //获取赛事id
  1180. $match_ids = [];
  1181. foreach ($matchData as $k => $v){
  1182. $match_ids[] = $v['match_id'];
  1183. }
  1184. //获取赛事下滚球默认赔率
  1185. $oddsData = ZQoddsModel::getMatchOdds($source,$model,$match_ids);
  1186. foreach ($matchData as $k=>$v){
  1187. //获取赛事下赔率并且分组
  1188. $capot = [];
  1189. $concede_size = [];
  1190. foreach ($oddsData as $kk=>$vv){
  1191. if ($vv['match_id'] == $v['match_id'] and $vv['sort']==0) {
  1192. if($vv['p_code'] == 'concede_size'){
  1193. $concede_size[] = $vv;
  1194. }
  1195. if($vv['p_code'] == 'capot'){
  1196. $capot[] = $vv;
  1197. }
  1198. }
  1199. }
  1200. $matchData[$k]['oddsData'] = [$concede_size,$capot];
  1201. }
  1202. return $matchData;
  1203. }
  1204. /**
  1205. * 获取欧冠 今日数据
  1206. */
  1207. public function __getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
  1208. $model_match = $model['model_match'];
  1209. $model_odds = $model['model_odds'];
  1210. $where = $this->commonFunction->getState($type_code);
  1211. $matchData = lm($model_match,'Sports')
  1212. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1213. ->where($model_match.'.source',$source['source'])
  1214. ->where($where)
  1215. ->where('lg_id',$lg_id)
  1216. ->where(function($query)use ($model_match,$search){
  1217. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1218. ->orWhere(function($query)use ($model_match,$search) {
  1219. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1220. });
  1221. })
  1222. ->get()->toArray();
  1223. foreach($matchData as $kk => $vv) {
  1224. $oddsData = lm($model_match, "Sports")
  1225. ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  1226. ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  1227. ->where($model_match.'.source',$source['source'])
  1228. ->where([$model_odds . '.match_id' => $vv['match_id']])
  1229. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1230. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  1231. ->orderBy($model_odds . '.id','desc')
  1232. ->get()
  1233. ->toarray();
  1234. $matchData[$kk]['oddsData'] = $oddsData;
  1235. }
  1236. return $matchData;
  1237. }
  1238. public function getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
  1239. $model_match = $model['model_match'];
  1240. $model_odds = $model['model_odds'];
  1241. $where = $this->commonFunction->getState($type_code);
  1242. $matchData = lm($model_match,'Sports')
  1243. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1244. ->where($model_match.'.source',$source['source'])
  1245. ->where($where)
  1246. ->where('lg_id',$lg_id)
  1247. ->where(function($query)use ($model_match,$search){
  1248. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1249. ->orWhere(function($query)use ($model_match,$search) {
  1250. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1251. });
  1252. })
  1253. ->get()->toArray();
  1254. //获取赛事id
  1255. $match_ids = [];
  1256. foreach ($matchData as $k => $v){
  1257. $match_ids[] = $v['match_id'];
  1258. }
  1259. //获取赔率数据
  1260. $oddsData = lm($model_odds, "Sports")
  1261. ->select( 'id','p_code', 'odds_code','odds_only','status', 'odds', 'condition', 'sort','match_id')
  1262. ->where('source',$source['source'])
  1263. ->whereIn('match_id', $match_ids)
  1264. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort','match_id')
  1265. ->orderBy($model_odds . '.id','desc')
  1266. ->get()
  1267. ->toarray();
  1268. foreach ($matchData as $k=>$v){
  1269. foreach ($oddsData as $kk=>$vv){
  1270. if($v['match_id'] == $vv['match_id']){
  1271. $matchData[$k]['oddsData'][] = $vv;
  1272. }
  1273. }
  1274. }
  1275. return $matchData;
  1276. }
  1277. /**
  1278. * 获取欧冠 早盘数据
  1279. */
  1280. public function getUEFAStMorningPlate($model,$type_code,$source,$lg_id,$search=''){
  1281. $model_match = $model['model_match'];
  1282. $model_odds = $model['model_odds'];
  1283. $where = $this->commonFunction->getState($type_code);
  1284. $matchData = lm($model_match,'Sports')
  1285. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1286. ->where($model_match.'.source',$source['source'])
  1287. ->where($where)
  1288. ->where('lg_id',$lg_id)
  1289. ->where(function($query)use ($model_match,$search){
  1290. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1291. ->orWhere(function($query)use ($model_match,$search) {
  1292. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1293. });
  1294. })
  1295. ->get()->toArray();
  1296. $data = $this->getOddsData->getOddsZQ($matchData,$model_odds,$source,[]);
  1297. return $data;
  1298. }
  1299. /**
  1300. * 获取 欧冠 冠军盘口数据
  1301. */
  1302. public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
  1303. $model_odds = $model['model_odds'];
  1304. $where = $this->commonFunction->getState($type_code);
  1305. $championData = lm($model_odds, 'Sports')
  1306. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  1307. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1308. ->where($source)
  1309. ->where('lg_id',$lg_id)
  1310. ->where($where)
  1311. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  1312. ->get()->toArray();
  1313. //按p_code分组
  1314. $p_code=array();
  1315. foreach($championData as $k=>$v){
  1316. $p_code[$v['p_code']][]=$v;
  1317. }
  1318. $data = [];
  1319. foreach ($p_code as $k1=>$v1){
  1320. foreach ($v1 as $k2=>$v2){
  1321. $data[$v2['p_code']]['last_time'] =$last_time;
  1322. $data[$v2['p_code']][$v2['odds_code']][] = $v2;
  1323. }
  1324. }
  1325. return $data;
  1326. }
  1327. }