GetmatchData.php 61 KB

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