GetmatchData.php 55 KB

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