GetmatchData.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  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. class GetmatchData {
  13. public function __construct() {
  14. $this->getOddsData = new GetOddsData();
  15. $this->commonFunction = C()->get('commonFunction');
  16. }
  17. /**
  18. * @param $ret 提交参数
  19. * @param $source 数据源条件
  20. * @return array
  21. * @throws \Exception
  22. * 获取不同状态下的赛事相关数据
  23. */
  24. public function typeData($ret,$source){
  25. //根据球类代码 获取相关model
  26. $models = $this->commonFunction->getModels($ret['game_code']);
  27. $model_match = $models['model_match'];
  28. //获取 不同状态的查询条件
  29. $where = $this->commonFunction->getState($ret['type_code'],$model_match);
  30. //根据联赛id查询
  31. if(!empty($ret['lg_id'])){
  32. $lg_id = $ret['lg_id'];
  33. }
  34. //根据搜索查询
  35. if(!empty($ret['search'])){
  36. $search = $ret['search'];
  37. }
  38. switch ($ret['type_code']){
  39. case 'StRollBall'://滚球
  40. // $data = $this->getRollBall($source,$models,$where,$ret,$search);
  41. $data = $this->getRollBallddd($source,$models,$where,$ret,$search);
  42. break;
  43. case 'StSoon'://即将
  44. $oddsTypeWhere = [
  45. [$models['model_odds'].'.is_morningplate','=',1],
  46. ];
  47. $data = $this->getSoon($source,$models,$where,$lg_id,$ret,$search,$oddsTypeWhere);
  48. break;
  49. case 'StToday'://今日
  50. $oddsTypeWhere = [
  51. [$models['model_odds'].'.is_today','=',1],
  52. ];
  53. $data = $this->getToday($source,$models,$where,$lg_id,$search,$oddsTypeWhere);
  54. break;
  55. case 'StMorningPlate'://早盘
  56. //默认当天
  57. if(empty($ret['match_date'])){
  58. $match_date = date("Y-m-d");
  59. }else{
  60. if($ret['match_date'] != 'other'){
  61. $match_date = $ret['match_date'];
  62. }else{
  63. $match_date = 'other';
  64. }
  65. }
  66. $oddsTypeWhere = [
  67. [$models['model_odds'].'.is_morningplate','=',1],
  68. ];
  69. $data = $this->getMorningPlate($source,$models,$where,$lg_id,$search,$match_date,$oddsTypeWhere);
  70. break;
  71. case 'StStringScene'://串场
  72. $oddsTypeWhere = [
  73. [$models['model_odds'].'.is_stringscene','=',1],
  74. ];
  75. if(empty($ret['str_type']) || $ret['str_type'] ==0){//赛事
  76. $data = $this->getStringScene($source,$models,$where,$lg_id,$search,'',$oddsTypeWhere);
  77. }
  78. if($ret['str_type'] == 1){//参赛表
  79. }
  80. if($ret['str_type'] == 2){//冠军盘口
  81. $where = $this->commonFunction->getState('StChampion',$model_match);
  82. $data = $this->getChampion($source,$models,$where,$lg_id,$search,'StChampion');
  83. }
  84. break;
  85. case 'StChampion'://冠军
  86. $data = $this->getChampion($source,$models,$where,$lg_id,$search,$ret['type_code']);
  87. break;
  88. default:
  89. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  90. }
  91. return $data;
  92. }
  93. /**
  94. * 获取滚球数据
  95. */
  96. public function __getRollBall($source,$models,$where,$ret,$search=''){
  97. $model_match = $models['model_match'];
  98. $model_odds = $models['model_odds'];
  99. $model_league = $models['model_league'];
  100. $model_result = $models['model_result'];
  101. //当前状态下所有联赛
  102. $data = lm($model_league,"Sports")
  103. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  104. ->join($model_result,$model_result.'.match_id',$model_match.'.match_id')
  105. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  106. ->distinct($model_league.'.name_chinese')
  107. ->where($model_league.'.source',$source['source'])
  108. ->where($where)
  109. ->where(function($query)use ($model_match,$search){
  110. $query->where($model_match.'.home_team','like','%'.$search.'%')
  111. ->orWhere(function($query)use ($model_match,$search) {
  112. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  113. });
  114. })
  115. ->get()
  116. ->toarray();
  117. if(empty($data)){
  118. $data = [];
  119. return $data;
  120. }
  121. //统计联赛下的赛事及查询赛事
  122. foreach($data as $k => $v){
  123. $data[$k]['matchNum'] = lm($model_match,"Sports")
  124. ->where($source)
  125. ->where('lg_id',$v['lg_id'])
  126. ->where($where)
  127. ->count();
  128. $data[$k]['matchData'] = lm($model_match,"Sports")
  129. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  130. ->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')
  131. ->where($model_match.'.source',$source['source'])
  132. ->where($model_match.'.lg_id',$v['lg_id'])
  133. ->where($where)
  134. ->get()
  135. ->toarray();
  136. }
  137. foreach($data as $k => $v){
  138. foreach($v['matchData'] as $kk => $vv){
  139. $oddsData= lm($model_match,"Sports")
  140. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  141. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','odds_only','sort')
  142. ->where($model_match.'.source',$source['source'])
  143. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])//查询滚球赔率
  144. //->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  145. ->where(function($query)use ($model_odds){
  146. $query->where($model_odds.'.odds_code','concede_home')
  147. ->orWhere(function($query)use ($model_odds){
  148. $query->where($model_odds.'.odds_code','concede_guest');
  149. })
  150. ->orWhere(function($query)use ($model_odds){
  151. $query->where($model_odds.'.odds_code','size_home');
  152. })
  153. ->orWhere(function($query)use ($model_odds){
  154. $query->where($model_odds.'.odds_code','size_guest');
  155. })
  156. ->orWhere(function($query)use ($model_odds){
  157. $query->where($model_odds.'.odds_code','capot_home');
  158. })
  159. ->orWhere(function($query)use ($model_odds){
  160. $query->where($model_odds.'.odds_code','capot_dogfall');
  161. })
  162. ->orWhere(function($query)use ($model_odds){
  163. $query->where($model_odds.'.odds_code','capot_guest');
  164. });
  165. })
  166. ->get()
  167. ->toarray();
  168. //根据 排序 获取 最新让球/大小玩法赔率
  169. $sortData = array_column($oddsData,'sort');
  170. array_multisort($sortData,SORT_DESC,$oddsData);
  171. $zu = [];
  172. foreach ($oddsData as $key1 =>$item1){
  173. $zu[$item1['p_code']][] = $item1;
  174. }
  175. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  176. $capot = $zu['capot'];//独赢
  177. $capot = [$capot[0],$capot[2],$capot[1]];//排序
  178. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  179. }
  180. }
  181. return $data;
  182. }
  183. public function getRollBall($source,$models,$where,$ret,$search=''){
  184. //获取当前状态下所有联赛
  185. $leagueData = leagueModel::getLeagueData($source,$models,$where,$search);
  186. if(empty($leagueData)){
  187. return $leagueData=[];
  188. }
  189. //统计联赛下的赛事及查询赛事
  190. $matchData = matchModel::getMatchDataAll($source,$models,$where,$search);
  191. //获取赛事下滚球默认赔率
  192. $oddsData = matchModel::getMatchOdds($source,$models);
  193. $data = [];
  194. foreach ($leagueData as $k=>$v){
  195. $data[$k] = $v;
  196. foreach ($matchData as $kk=>$vv){
  197. if($v['lg_id'] == $vv['lg_id']){
  198. $data[$k]['matchData'][] = $vv;
  199. }
  200. }
  201. $data[$k]['matchNum'] = count($data[$k]['matchData']);
  202. }
  203. foreach ($data as $k=>$v){
  204. foreach ($v['matchData'] as $kk=>$vv){
  205. //获取赛事下赔率并且分组
  206. $capot = [];
  207. $concede_size = [];
  208. foreach ($oddsData as $kkk=>$vvv) {
  209. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  210. if($vvv['p_code'] == 'concede_size'){
  211. $concede_size[] = $vvv;
  212. }
  213. if($vvv['p_code'] == 'capot'){
  214. $capot[] = $vvv;
  215. }
  216. }
  217. }
  218. $data[$k]['matchData'][$kk]['oddsData'] = [$concede_size,$capot];
  219. }
  220. }
  221. return $data;
  222. }
  223. /**
  224. * 获取即将数据
  225. */
  226. public function getSoon($source,$models,$where,$lg_id=0,$ret,$search='',$oddsTypeWhere=''){
  227. $model_match = $models['model_match'];
  228. $model_odds = $models['model_odds'];
  229. $model_league = $models['model_league'];
  230. $model_result = $models['model_result'];
  231. //当前状态下所有联赛
  232. $data = lm($model_league,"Sports")
  233. ->join($model_match,$model_match.'.lg_id',$model_league.'.lg_id')
  234. ->select($model_league.'.lg_id',$model_league.'.name_chinese as leagueName')
  235. ->distinct($model_league.'.name_chinese')
  236. ->where($model_league.'.source',$source['source'])
  237. ->where($where)
  238. ->where(function($query)use ($model_match,$search){
  239. $query->where($model_match.'.home_team','like','%'.$search.'%')
  240. ->orWhere(function($query)use ($model_match,$search) {
  241. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  242. });
  243. })
  244. ->get()
  245. ->toarray();
  246. if(empty($data)){
  247. $data = [];
  248. return $data;
  249. }
  250. //统计联赛下的赛事及查询赛事
  251. foreach($data as $k => $v){
  252. $data[$k]['matchNum'] = lm($model_match,"Sports")
  253. ->where($source)
  254. ->where('lg_id',$v['lg_id'])
  255. ->where($where)
  256. ->count();
  257. $data[$k]['matchData'] = lm($model_match,"Sports")
  258. ->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')
  259. ->where($source)
  260. ->where($model_match.'.lg_id',$v['lg_id'])
  261. ->where($where)
  262. ->orderBy('match_time','asc')
  263. ->get()
  264. ->toarray();
  265. }
  266. //获取当前美东时间
  267. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  268. //获取足球即将默认玩法赔率
  269. if($ret['game_code'] == 'zq'){
  270. foreach($data as $k => $v){
  271. foreach($v['matchData'] as $kk => $vv){
  272. $wait_time = ceil(((strtotime( $vv['us_time']))-$s_time)/60);
  273. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  274. $oddsData= lm($model_match,"Sports")
  275. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  276. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  277. ->where($model_match.'.source',$source['source'])
  278. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  279. // ->where($oddsTypeWhere)
  280. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  281. ->where(function($query)use ($model_odds){
  282. $query->where($model_odds.'.odds_code','concede_home')
  283. ->orWhere(function($query)use ($model_odds){
  284. $query->where($model_odds.'.odds_code','concede_guest');
  285. })
  286. ->orWhere(function($query)use ($model_odds){
  287. $query->where($model_odds.'.odds_code','size_home');
  288. })
  289. ->orWhere(function($query)use ($model_odds){
  290. $query->where($model_odds.'.odds_code','size_guest');
  291. })
  292. ->orWhere(function($query)use ($model_odds){
  293. $query->where($model_odds.'.odds_code','capot_home');
  294. })
  295. ->orWhere(function($query)use ($model_odds){
  296. $query->where($model_odds.'.odds_code','capot_dogfall');
  297. })
  298. ->orWhere(function($query)use ($model_odds){
  299. $query->where($model_odds.'.odds_code','capot_guest');
  300. });
  301. })
  302. ->get()
  303. ->toarray();
  304. //根据 排序 获取 最新让球/大小玩法赔率
  305. $sortData = array_column($oddsData,'sort');
  306. array_multisort($sortData,SORT_ASC,$oddsData);
  307. $zu = [];
  308. foreach ($oddsData as $key1 =>$item1){
  309. $zu[$item1['p_code']][] = $item1;
  310. }
  311. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  312. $capot = $zu['capot'];//独赢
  313. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  314. }
  315. }
  316. }
  317. //获取网球即将默认玩法赔率
  318. if($ret['game_code'] == 'wq'){
  319. foreach($data as $k => $v){
  320. $matchData = $this->getOddsData->getOddsWQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  321. $data[$k]['matchData'] = $matchData;
  322. }
  323. }
  324. //获取篮球即将默认玩法赔率
  325. if($ret['game_code'] == 'lq'){
  326. foreach($data as $k => $v){
  327. foreach($v['matchData'] as $kk => $vv){
  328. $wait_time = ceil(((strtotime( $vv['match_time']))-time())/60);
  329. $data[$k]['matchData'][$kk]['wait_time'] = $wait_time;//追加距离开赛时间
  330. $oddsData= lm($model_match,"Sports")
  331. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  332. ->select($model_odds.'.id','odds_only','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  333. ->where($model_match.'.source',$source['source'])
  334. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  335. // ->where($oddsTypeWhere)
  336. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  337. ->where(function($query)use ($model_odds){
  338. $query->where($model_odds.'.odds_code','concede_home')
  339. ->orWhere(function($query)use ($model_odds){
  340. $query->where($model_odds.'.odds_code','concede_guest');
  341. })
  342. ->orWhere(function($query)use ($model_odds){
  343. $query->where($model_odds.'.odds_code','total_sizes_big');
  344. })
  345. ->orWhere(function($query)use ($model_odds){
  346. $query->where($model_odds.'.odds_code','total_sizes_small');
  347. })
  348. ->orWhere(function($query)use ($model_odds){
  349. $query->where($model_odds.'.odds_code','capot_home');
  350. })
  351. ->orWhere(function($query)use ($model_odds){
  352. $query->where($model_odds.'.odds_code','capot_dogfall');
  353. })
  354. ->orWhere(function($query)use ($model_odds){
  355. $query->where($model_odds.'.odds_code','capot_guest');
  356. });
  357. })
  358. ->get()
  359. ->toarray();
  360. //根据 排序 获取 最新让球/大小玩法赔率
  361. $sortData = array_column($oddsData,'sort');
  362. array_multisort($sortData,SORT_ASC,$oddsData);
  363. $zu = [];
  364. foreach ($oddsData as $key1 =>$item1){
  365. $zu[$item1['p_code']][] = $item1;
  366. }
  367. $c_s['concede'] = array_slice($zu['concede'],0,2);//让球 前四条 放入
  368. $c_s['total_size'] = array_slice($zu['total_size'],0,2);//让球 前四条 放入
  369. $capot = $zu['capot'];//独赢
  370. $data[$k]['matchData'][$kk]['oddsData'] = [$c_s,$capot];
  371. }
  372. // $matchData = $this->getOddsData->getOddsLQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  373. // $data[$k]['matchData'] = $matchData;
  374. }
  375. }
  376. //获取棒球即将默认玩法赔率
  377. if($ret['game_code'] == 'bq'){
  378. foreach($data as $k => $v){
  379. $matchData = $this->getOddsData->getOddsBQ($v['matchData'], $model_odds, $source,$oddsTypeWhere);
  380. $data[$k]['matchData'] = $matchData;
  381. }
  382. }
  383. return $data;
  384. }
  385. /**
  386. * 获取今日数据
  387. */
  388. public function getToday($source,$models,$where,$lg_id=0,$search='',$oddsTypeWhere=[]){
  389. //获取model
  390. $model_match = $models['model_match'];
  391. $model_odds = $models['model_odds'];
  392. $model_league = $models['model_league'];
  393. $model_result = $models['model_result'];
  394. //根据联赛id 获取联赛下 赛事赔率数据
  395. if($lg_id >0){
  396. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,'',$oddsTypeWhere);
  397. return $leagueData;
  398. }
  399. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where);
  400. return $data;
  401. }
  402. /**
  403. * 获取早盘数据
  404. */
  405. public function getMorningPlate($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  406. //获取model
  407. $model_match = $models['model_match'];
  408. $model_odds = $models['model_odds'];
  409. $model_league = $models['model_league'];
  410. $model_result = $models['model_result'];
  411. //根据联赛id 获取联赛下 赛事赔率数据
  412. if($lg_id >0){
  413. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  414. return $leagueData;
  415. }
  416. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  417. return $data;
  418. }
  419. /**
  420. * 获取串场数据
  421. */
  422. public function getStringScene($source,$models,$where,$lg_id=0,$search='',$time='',$oddsTypeWhere=''){
  423. //获取model
  424. $model_match = $models['model_match'];
  425. $model_odds = $models['model_odds'];
  426. $model_league = $models['model_league'];
  427. $model_result = $models['model_result'];
  428. //根据联赛id 获取联赛下 赛事赔率数据
  429. if($lg_id >0){
  430. $leagueData = $this->getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time,$oddsTypeWhere);
  431. return $leagueData;
  432. }
  433. $data = $this->getMatch($source,$model_league,$model_match,'',$search,$where,$time);
  434. return $data;
  435. }
  436. /**
  437. * 获取冠军数据
  438. */
  439. public function getChampion($source,$models,$where,$lg_id=0,$search='',$type_code=''){
  440. //获取model
  441. $model_odds = $models['model_odds'];
  442. $model_league = $models['model_league'];
  443. //根据联赛id 获取联赛下 冠军玩法盘口
  444. if($lg_id >0){
  445. $last_time = lm($model_league, 'Sports')
  446. ->select('last_time')
  447. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  448. ->where($source)
  449. ->where('lg_id',$lg_id)
  450. ->first()->last_time;
  451. $championData = lm($model_odds, 'Sports')
  452. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  453. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  454. ->where($source)
  455. ->where('lg_id',$lg_id)
  456. ->where($where)
  457. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  458. ->get()->toArray();
  459. //按p_code分组
  460. $p_code=array();
  461. foreach($championData as $k=>$v){
  462. $p_code[$v['p_code']][]=$v;
  463. }
  464. $sd = [];
  465. foreach ($p_code as $k1=>$v1){
  466. foreach ($v1 as $k2=>$v2){
  467. $sd[$v2['p_code']]['last_time'] =$last_time;
  468. $sd[$v2['p_code']][$v2['odds_code']][] = $v2;
  469. }
  470. }
  471. return $sd;
  472. }
  473. //获取国家/洲下所有联赛及数量
  474. $data = $this->getMatch($source,$model_league,'',$model_odds,$search,$where,'',$type_code);
  475. return $data;
  476. }
  477. /**
  478. * 获取国家/洲 下联赛
  479. */
  480. public function getMatch($source,$model_league,$model_match='',$model_odds='',$search,$where,$time='',$type_code=''){
  481. //国家下所有联赛
  482. $country = lm($model_league,"Sports")
  483. ->leftjoin('st_country','st_country.country_id',$model_league.'.country_id')
  484. ->select('st_country.country_id','st_country.name_chinese as region')
  485. // ->select('st_country.country_id as region_id','st_country.name_chinese as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  486. ->distinct('st_country.name_chinese')
  487. ->where($model_league.'.source',$source['source'])
  488. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  489. ->get()
  490. ->toArray();
  491. //洲下所有联赛
  492. $area = lm($model_league,"Sports")
  493. ->leftjoin('st_area','st_area.id',$model_league.'.area_id')
  494. ->select('st_area.id as area_id','st_area.title as region')
  495. // ->select('st_area.id as region_id','st_area.title as region',$model_league.'.lg_id', $model_league.'.name_chinese as league')
  496. ->distinct('st_area.title')
  497. ->where($model_league.'.source',$source['source'])
  498. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  499. ->get()
  500. ->toArray();
  501. if($type_code != 'StChampion'){//非冠军赛事
  502. $data = $this->getMatchNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  503. }else{//冠军赛事
  504. $data = $this->getMatchStChampionNum($source,$country,$area,$model_league,$model_match,$model_odds,$where,$search,$time);
  505. }
  506. return $data;
  507. }
  508. /**
  509. * 获取联赛下赛事 数量
  510. * 非冠军盘口
  511. */
  512. public function getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  513. $leagueData = lm($model_league,'Sports')
  514. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  515. ->where($source)
  516. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  517. ->get()
  518. ->toArray();
  519. $timeWhere = [];
  520. if(!empty($time)){
  521. if($time == 'other'){
  522. $timeWhere[] = ['match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time()))))];
  523. }else{
  524. $timeWhere[] = ['match_date',$time];
  525. }
  526. }
  527. $matchData = lm($model_match,'Sports')
  528. ->select('id','lg_id','match_id')
  529. ->where($where)
  530. ->where($source)
  531. ->where($timeWhere)
  532. ->get()
  533. ->toArray();
  534. //按国家
  535. $countryData = [];
  536. if(!empty($country) and !empty($leagueData) and !empty($matchData)){
  537. foreach ($country as $k=>$v){
  538. if($v['country_id']){
  539. $countryData[$k] = $v;
  540. foreach ($leagueData as $kk=>$vv){
  541. if($v['country_id'] == $vv['country_id']){
  542. $countryData[$k]['league_count'][] = $vv;
  543. }
  544. }
  545. }
  546. }
  547. }
  548. //去除无联赛 国家
  549. foreach ($countryData as $k=>$v){
  550. if(count($v) == 2){
  551. unset($countryData[$k]);
  552. }
  553. }
  554. //按地区
  555. $areaData = [];
  556. if(!empty($area) and !empty($leagueData) and($matchData)){
  557. foreach ($area as $k=>$v){
  558. if($v['area_id']){
  559. $areaData[$k] = $v;
  560. foreach ($leagueData as $kk=>$vv){
  561. if($v['area_id'] == $vv['area_id']){
  562. $areaData[$k]['league_count'][] = $vv;
  563. }
  564. }
  565. }
  566. }
  567. }
  568. //去除无联赛 地区
  569. foreach ($areaData as $k=>$v){
  570. if(count($v) == 2){
  571. unset($areaData[$k]);
  572. }
  573. }
  574. $countryData = $this->commonFunction->array_other_tt($countryData,$matchData);
  575. $areaData = $this->commonFunction->array_other_tt($areaData,$matchData);
  576. $data = array_merge($countryData,$areaData);
  577. return $data;
  578. }
  579. /**
  580. * 弃用 获取联赛下赛事 数量
  581. * 非冠军盘口
  582. */
  583. public function __getMatchNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  584. //统计国家下联赛-赛事/盘口数量
  585. if(!empty($country)){
  586. foreach($country as $k => $v) {
  587. $country[$k]['league_count'] = lm($model_league, 'Sports')
  588. ->select('lg_id', 'name_chinese as league')
  589. ->where($source)
  590. ->where('country_id', $v['country_id'])
  591. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  592. ->get()->toarray();
  593. }
  594. foreach ($country as $k => $v) {
  595. foreach($v['league_count'] as $kk => $vv ){
  596. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  597. if(empty($time)){
  598. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  599. ->select("match_id")
  600. ->where($source)
  601. ->where('lg_id',$vv['lg_id'])
  602. ->where($where)
  603. ->count("*");
  604. }else{//早盘 下有时间查询
  605. if($time == 'other'){//早盘 一周后
  606. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  607. ->select("match_id")
  608. ->where($source)
  609. ->where('lg_id',$vv['lg_id'])
  610. ->where($where)
  611. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  612. ->count("*");
  613. }else{
  614. $country[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  615. ->select("match_id")
  616. ->where($source)
  617. ->where('lg_id',$vv['lg_id'])
  618. ->where($where)
  619. ->where('match_date',$time)
  620. ->count("*");
  621. }
  622. }
  623. }
  624. if($country[$k]['league_count'][$kk]['count'] == 0){
  625. unset($country[$k]['league_count'][$kk]);
  626. }
  627. }
  628. }
  629. }
  630. //统计 地区 联赛-赛事/盘口数量
  631. if(!empty($area)){
  632. foreach($area as $k => $v) {
  633. $area[$k]['league_count'] = lm($model_league, 'Sports')
  634. ->select('lg_id', 'name_chinese as league')
  635. ->where($source)
  636. ->where('area_id', $v['area_id'])
  637. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  638. ->get()->toarray();
  639. }
  640. foreach ($area as $k => $v) {
  641. foreach($v['league_count'] as $kk => $vv ){
  642. if(!empty($model_match)){//非冠军玩法,获取联赛下赛事数量
  643. if(empty($time)){
  644. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  645. ->select("match_id")
  646. ->where($source)
  647. ->where('lg_id',$vv['lg_id'])
  648. ->where($where)
  649. ->count("*");
  650. }else {
  651. if ($time == 'other') {// 今日 一周后
  652. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  653. ->select("match_id")
  654. ->where($source)
  655. ->where('lg_id', $vv['lg_id'])
  656. ->where($where)
  657. ->where('match_date', '>', date("Y-m-d", strtotime("+1weeks", strtotime(date('Y-m-d', time())))))
  658. ->count("*");
  659. } else {//今日 大于今日
  660. $area[$k]['league_count'][$kk]['count'] = lm($model_match, 'Sports')
  661. ->select("match_id")
  662. ->where($source)
  663. ->where('lg_id',$vv['lg_id'])
  664. ->where($where)
  665. ->where('match_date',$time)
  666. ->count("*");
  667. }
  668. }
  669. }
  670. if($area[$k]['league_count'][$kk]['count'] == 0){
  671. unset($area[$k]['league_count'][$kk]);
  672. }
  673. }
  674. }
  675. }
  676. //处理空联赛国家
  677. $countryData = $this->commonFunction->handleArr($country);
  678. $areaData = $this->commonFunction->handleArr($area);
  679. //合并数组
  680. $data = array_merge($countryData,$areaData);
  681. return $data;
  682. }
  683. /**
  684. * 获取联赛下赛事 数量
  685. * 冠军盘口
  686. */
  687. public function getMatchStChampionNum($source,$country,$area,$model_league,$model_match='',$model_odds='',$where,$search,$time='',$type=0){
  688. $leagueData = lm($model_league,'Sports')
  689. ->select('id','lg_id','name_chinese as league','country_id','area_id')
  690. ->where($source)
  691. ->where($model_league.'.name_chinese','like','%'.$search.'%')
  692. ->get()
  693. ->toArray();
  694. $oddsData = lm($model_odds,'Sports')
  695. ->select('id','lg_id','p_code')
  696. ->distinct("p_code")//去重
  697. ->where($where)
  698. ->where($source)
  699. ->get()
  700. ->toArray();
  701. //按国家
  702. $countryData = [];
  703. if(!empty($country) and !empty($leagueData) and !empty($oddsData)){
  704. foreach ($country as $k=>$v){
  705. if($v['country_id']){
  706. $countryData[$k] = $v;
  707. foreach ($leagueData as $kk=>$vv){
  708. if($v['country_id'] == $vv['country_id']){
  709. $countryData[$k]['league_count'][] = $vv;
  710. }
  711. }
  712. }
  713. }
  714. }
  715. //去除无联赛 国家
  716. foreach ($countryData as $k=>$v){
  717. if(count($v) == 2){
  718. unset($countryData[$k]);
  719. }
  720. }
  721. //按地区
  722. $areaData = [];
  723. if(!empty($area) and !empty($leagueData) and($oddsData)){
  724. foreach ($area as $k=>$v){
  725. if($v['area_id']){
  726. $areaData[$k] = $v;
  727. foreach ($leagueData as $kk=>$vv){
  728. if($v['area_id'] == $vv['area_id']){
  729. $areaData[$k]['league_count'][] = $vv;
  730. }
  731. }
  732. }
  733. }
  734. }
  735. //去除无联赛 地区
  736. foreach ($areaData as $k=>$v){
  737. if(count($v) == 2){
  738. unset($areaData[$k]);
  739. }
  740. }
  741. $countryData = $this->commonFunction->array_gj_tt($countryData,$oddsData);
  742. $areaData = $this->commonFunction->array_gj_tt($areaData,$oddsData);
  743. $data = array_merge($countryData,$areaData);
  744. return $data;
  745. }
  746. /**
  747. * 获取联赛下 赛事赔率
  748. */
  749. public function getMatchOdds($source,$model_league,$model_match,$model_odds,$where,$search,$lg_id,$time='',$oddsTypeWhere=[]){
  750. $leagueData = lm($model_league,"Sports")
  751. ->select('lg_id','name_chinese as leagueName')
  752. ->where($source)
  753. ->where('lg_id',$lg_id)
  754. ->first();
  755. if(!empty($time)){//早盘 按时间查询
  756. if($time == 'other'){//早盘 一周后
  757. $matchData = lm($model_match,"Sports")
  758. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  759. ->where($source)
  760. ->where($model_match.'.lg_id',$lg_id)
  761. ->where($where)
  762. ->where('match_date','>',date("Y-m-d",strtotime("+1weeks",strtotime(date('Y-m-d',time())))))
  763. ->where(function($query)use ($model_match,$search){
  764. $query->where($model_match.'.home_team','like','%'.$search.'%')
  765. ->orWhere(function($query)use ($model_match,$search) {
  766. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  767. });
  768. })
  769. ->get()
  770. ->toarray();
  771. }else{
  772. if($time == date('Y-m-d')){//早盘今天
  773. $matchData = lm($model_match,"Sports")
  774. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  775. ->where($source)
  776. ->where($model_match.'.lg_id',$lg_id)
  777. ->where('is_morningplate','=',1)
  778. ->where('match_date',$time)
  779. ->where('match_time','>',date("H:i:s", time()))
  780. ->where(function($query)use ($model_match,$search){
  781. $query->where($model_match.'.home_team','like','%'.$search.'%')
  782. ->orWhere(function($query)use ($model_match,$search) {
  783. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  784. });
  785. })
  786. ->get()
  787. ->toarray();
  788. }else{//早盘 今天以后
  789. $matchData = lm($model_match,"Sports")
  790. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  791. ->where($source)
  792. ->where($model_match.'.lg_id',$lg_id)
  793. ->where($where)
  794. ->where('match_date',$time)
  795. ->where(function($query)use ($model_match,$search){
  796. $query->where($model_match.'.home_team','like','%'.$search.'%')
  797. ->orWhere(function($query)use ($model_match,$search) {
  798. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  799. });
  800. })
  801. ->get()
  802. ->toarray();
  803. }
  804. }
  805. }else{
  806. $matchData = lm($model_match,"Sports")
  807. ->select($model_match.'.match_id',$model_match.'.tag','match_date',$model_match.'.match_time',$model_match.'.home_team',$model_match.'.guest_team')
  808. ->where($source)
  809. ->where($model_match.'.lg_id',$lg_id)
  810. ->where($where)
  811. ->where(function($query)use ($model_match,$search){
  812. $query->where($model_match.'.home_team','like','%'.$search.'%')
  813. ->orWhere(function($query)use ($model_match,$search) {
  814. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  815. });
  816. })
  817. ->get()
  818. ->toarray();
  819. }
  820. //获取各球类默认赔率
  821. $game_code = $_REQUEST['game_code'];
  822. switch ($game_code) {
  823. case 'zq'://足球
  824. $matchData = $this->getOddsData->getOddsZQ($matchData, $model_odds, $source,$oddsTypeWhere);
  825. break;
  826. case 'lq'://篮球
  827. $matchData = $this->getOddsData->getOddsLQ($matchData, $model_odds, $source,$oddsTypeWhere);
  828. break;
  829. case 'wq'://网球
  830. $matchData = $this->getOddsData->getOddsWQ($matchData, $model_odds, $source,$oddsTypeWhere);
  831. break;
  832. case 'bq'://棒球
  833. $matchData = $this->getOddsData->getOddsBQ($matchData, $model_odds, $source,$oddsTypeWhere);
  834. break;
  835. }
  836. $leagueData->matchNum = count($matchData);
  837. $leagueData->matchData = $matchData;
  838. return $leagueData;
  839. }
  840. /**
  841. * @param $source 数据源
  842. * @param $where 该状态 查询条件
  843. * @return array
  844. * @throws \Exception
  845. * 获取所有即将开赛 数据
  846. */
  847. public function getAllSoon($source,$where){
  848. $game = lm('GameType', 'Sports')->select('id','game_name','game_code','game_ico_url')->where('status',1)->get()->toArray();
  849. //获取当前美东时间
  850. $s_time = strtotime($this->commonFunction->qgmdate('Y-m-d H:i:s', '', -4));
  851. $data=[];
  852. foreach ($game as $key=>$item){
  853. if($item['game_code'] !='gj'){
  854. $model = $this->commonFunction->getModels($item['game_code']);
  855. $matchData = lm($model['model_match'], 'Sports')
  856. ->select('match_id','home_team','guest_team','match_time','us_time')
  857. ->where($source)
  858. ->where($where)
  859. ->orderBy('match_time','asc')
  860. // ->limit(6)
  861. ->get()->toArray();
  862. $matchNum = count($matchData);
  863. $matchData = array_slice($matchData,0,6);
  864. foreach ($matchData as $key1 => $item1){
  865. //获取等待时间
  866. $wait_time = ceil(((strtotime($item1['us_time']))-$s_time)/60);
  867. $matchData[$key1]['wait_time'] = $wait_time;
  868. }
  869. if($matchNum > 0){
  870. // $matchData = array_multisort(array_column($matchData,'wait_time'),SOTR_ASC,$matchData);
  871. $data[$item['game_code']]['matchData'] = $matchData;
  872. $data[$item['game_code']]['matchNum'] = $matchNum;
  873. $data[$item['game_code']]['gameName'] = $item['game_name'];
  874. $data[$item['game_code']]['gameCode'] = $item['game_code'];
  875. }
  876. }
  877. }
  878. return $data;
  879. }
  880. /**
  881. * 获取欧冠 各状态赛事数据
  882. */
  883. public function getUEFAChampions($source){
  884. //根据搜索查询
  885. if(!empty($_GET['search'])){
  886. $search = $_GET['search'];
  887. }
  888. $model = $this->commonFunction->getModels('gj',1);
  889. $model_league = $model['model_league'];
  890. $leagueData = lm($model_league,'Sports')
  891. ->select('name_chinese','lg_id','last_time')
  892. ->where($model_league.'.source',$source['source'])
  893. ->where($model_league.'.name_chinese','欧洲冠军杯')
  894. ->first();
  895. //获取滚球数据
  896. $StRollBall = $this->getUEFAStRollBall($model,'StRollBall',$source,$leagueData->lg_id,$search);
  897. //获取今日数据
  898. $StToday = $this->getUEFAStToday($model,'StToday',$source,$leagueData->lg_id,$search);
  899. //获取早盘数据
  900. $StMorningPlate = $this->getUEFAStMorningPlate($model,'StMorningPlate',$source,$leagueData->lg_id,$search);
  901. //获取冠军盘口数据
  902. $StChampion = $this->getUEFAStChampion($model,'StChampion',$source,$leagueData->lg_id,$leagueData->last_time);
  903. $data = [
  904. 'lg_id' => $leagueData->lg_id,
  905. 'leagueName'=> $leagueData->name_chinese,
  906. 'StRollBall'=>[//滚球数据
  907. 'typeName'=>'滚球',
  908. 'matchNum'=>count($StRollBall),
  909. 'matchData'=>$StRollBall
  910. ],
  911. 'StToday'=>[//今日数据
  912. 'typeName'=>'今日',
  913. 'matchNum'=>count($StToday),
  914. 'matchData'=>$StToday
  915. ],
  916. 'StMorningPlate'=>[//早盘数据
  917. 'typeName'=>'早盘',
  918. 'matchNum'=>count($StMorningPlate),
  919. 'matchData'=>$StMorningPlate
  920. ],
  921. 'StChampion'=>[//冠军盘口
  922. 'typeName'=>'冠军盘口',
  923. 'matchNum'=>count($StChampion),
  924. 'matchData'=>$StChampion
  925. ]
  926. ];
  927. return $data;
  928. }
  929. /**
  930. * 获取欧冠 滚球数据
  931. */
  932. public function getUEFAStRollBall($model,$type_code,$source,$lg_id,$search=''){
  933. $model_match = $model['model_match'];
  934. $model_odds = $model['model_odds'];
  935. $model_result = $model['model_result'];
  936. $where = $this->commonFunction->getState($type_code,$model_match);
  937. $matchData = lm($model_match,"Sports")
  938. ->leftjoin($model_result,$model_result.'.match_id',$model_match.'.match_id')
  939. ->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')
  940. ->where($model_match.'.source',$source['source'])
  941. ->where($model_match.'.lg_id',$lg_id)
  942. ->where($where)
  943. ->where(function($query)use ($model_match,$search){
  944. $query->where($model_match.'.home_team','like','%'.$search.'%')
  945. ->orWhere(function($query)use ($model_match,$search) {
  946. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  947. });
  948. })
  949. ->get()
  950. ->toarray();
  951. foreach($matchData as $kk => $vv){
  952. $oddsData= lm($model_match,"Sports")
  953. ->leftjoin($model_odds,$model_odds.'.match_id',$model_match.'.match_id')
  954. ->select($model_odds.'.id','p_code','odds_code',$model_odds.'.status','odds','condition','sort')
  955. ->where($model_match.'.source',$source['source'])
  956. ->where([$model_odds.'.match_id' => $vv['match_id'],$model_odds.'.type'=>0])
  957. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  958. ->where(function($query)use ($model_odds){
  959. $query->where($model_odds.'.odds_code','concede_home')
  960. ->orWhere(function($query)use ($model_odds){
  961. $query->where($model_odds.'.odds_code','concede_guest');
  962. })
  963. ->orWhere(function($query)use ($model_odds){
  964. $query->where($model_odds.'.odds_code','size_home');
  965. })
  966. ->orWhere(function($query)use ($model_odds){
  967. $query->where($model_odds.'.odds_code','size_guest');
  968. })
  969. ->orWhere(function($query)use ($model_odds){
  970. $query->where($model_odds.'.odds_code','capot_home');
  971. })
  972. ->orWhere(function($query)use ($model_odds){
  973. $query->where($model_odds.'.odds_code','capot_dogfall');
  974. })
  975. ->orWhere(function($query)use ($model_odds){
  976. $query->where($model_odds.'.odds_code','capot_guest');
  977. });
  978. })
  979. ->get()
  980. ->toarray();
  981. //根据 排序 获取 最新让球/大小玩法赔率
  982. $sortData = array_column($oddsData,'sort');
  983. array_multisort($sortData,SORT_ASC,$oddsData);
  984. $zu = [];
  985. foreach ($oddsData as $key1 =>$item1){
  986. $zu[$item1['p_code']][] = $item1;
  987. }
  988. $c_s = array_slice($zu['concede_size'],0,4);//让球/大小 前四条 放入
  989. $capot = $zu['capot'];//独赢
  990. $matchData[$kk]['oddsData'] = [$c_s,$capot];
  991. }
  992. return $matchData;
  993. }
  994. /**
  995. * 获取欧冠 今日数据
  996. */
  997. public function getUEFAStToday($model,$type_code,$source,$lg_id,$search=''){
  998. $model_match = $model['model_match'];
  999. $model_odds = $model['model_odds'];
  1000. $where = $this->commonFunction->getState($type_code);
  1001. $matchData = lm($model_match,'Sports')
  1002. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1003. ->where($model_match.'.source',$source['source'])
  1004. ->where($where)
  1005. ->where('lg_id',$lg_id)
  1006. ->where(function($query)use ($model_match,$search){
  1007. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1008. ->orWhere(function($query)use ($model_match,$search) {
  1009. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1010. });
  1011. })
  1012. ->get()->toArray();
  1013. foreach($matchData as $kk => $vv) {
  1014. $oddsData = lm($model_match, "Sports")
  1015. ->leftjoin($model_odds, $model_odds . '.match_id', $model_match . '.match_id')
  1016. ->select($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  1017. ->where($model_match.'.source',$source['source'])
  1018. ->where([$model_odds . '.match_id' => $vv['match_id']])
  1019. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1020. ->groupBy($model_odds . '.id','p_code', 'odds_code','odds_only', $model_odds . '.status', 'odds', 'condition', 'sort')
  1021. ->orderBy($model_odds . '.id','desc')
  1022. ->get()
  1023. ->toarray();
  1024. $matchData[$kk]['oddsData'] = $oddsData;
  1025. }
  1026. return $matchData;
  1027. }
  1028. /**
  1029. * 获取欧冠 早盘数据
  1030. */
  1031. public function getUEFAStMorningPlate($model,$type_code,$source,$lg_id,$search=''){
  1032. $model_match = $model['model_match'];
  1033. $model_odds = $model['model_odds'];
  1034. $where = $this->commonFunction->getState($type_code);
  1035. $matchData = lm($model_match,'Sports')
  1036. ->select('match_id','match_date','match_time','tag','home_team','guest_team')
  1037. ->where($model_match.'.source',$source['source'])
  1038. ->where($where)
  1039. ->where('lg_id',$lg_id)
  1040. ->where(function($query)use ($model_match,$search){
  1041. $query->where($model_match.'.home_team','like','%'.$search.'%')
  1042. ->orWhere(function($query)use ($model_match,$search) {
  1043. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  1044. });
  1045. })
  1046. ->get()->toArray();
  1047. $data = $this->getOddsData->getOddsZQ($matchData,$model_odds,$source,[]);
  1048. return $data;
  1049. }
  1050. /**
  1051. * 获取 欧冠 冠军盘口数据
  1052. */
  1053. public function getUEFAStChampion($model,$type_code,$source,$lg_id,$last_time=''){
  1054. $model_odds = $model['model_odds'];
  1055. $where = $this->commonFunction->getState($type_code);
  1056. $championData = lm($model_odds, 'Sports')
  1057. ->select("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  1058. // ->where($model_odds.'.expire_time','>',date("Y-m-d H:i:s"))
  1059. ->where($source)
  1060. ->where('lg_id',$lg_id)
  1061. ->where($where)
  1062. ->groupBy("id","lg_id","match_id","p_code","odds_code","team","odds","sort","status","odds_only")
  1063. ->get()->toArray();
  1064. //按p_code分组
  1065. $p_code=array();
  1066. foreach($championData as $k=>$v){
  1067. $p_code[$v['p_code']][]=$v;
  1068. }
  1069. $data = [];
  1070. foreach ($p_code as $k1=>$v1){
  1071. foreach ($v1 as $k2=>$v2){
  1072. $data[$v2['p_code']]['last_time'] =$last_time;
  1073. $data[$v2['p_code']][$v2['odds_code']][] = $v2;
  1074. }
  1075. }
  1076. return $data;
  1077. }
  1078. }