GetmatchData.php 60 KB

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