GetOddsData.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * 获取不同球类默认赔率玩法
  5. * User: Jun.peng
  6. * Date: 2019/4/16
  7. * Time: 9:29
  8. */
  9. namespace Biz\Match;
  10. class GetOddsData {
  11. public function __construct() {
  12. $this->commonFunction = C()->get('commonFunction');
  13. }
  14. /**
  15. * 根据不同球类获取相关赔率数据
  16. */
  17. public function getOddsData($data,$whereDate,$source,$oddsTypeWhere=''){
  18. if($data['search']){
  19. $search = $data['search'];
  20. }
  21. //根据 球类代码 获取相关model
  22. $models = $this->commonFunction->getModels($data['game_code']);
  23. $model_league = $models['model_league'];
  24. $model_match = $models['model_match'];
  25. $model_odds = $models['model_odds'];
  26. $league = lm($model_league, 'Sports')
  27. ->select('id as lg_id','name_chinese')
  28. // ->where($source)
  29. ->where(['id'=>$data['leagueID']])
  30. ->first();
  31. if(empty($league->lg_id)) throw new \Exception(Render([], '10003', lang('Tips','Sports')->get('PARAM_ERROR')));
  32. $matchData = lm($model_match, 'Sports')
  33. ->select('lg_id','id as match_id','tag','match_date','match_time','home_team','guest_team')
  34. // ->where($source)
  35. ->where(['lg_id'=>$data['leagueID']])
  36. ->where($whereDate)
  37. ->where($model_match.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  38. ->where('status','<',2)
  39. ->where($model_match.'.home_team','<>',null)
  40. ->where($model_match.'.guest_team','<>',null)
  41. ->where(function($query)use ($model_match,$search){
  42. $query->where($model_match.'.home_team','like','%'.$search.'%')
  43. ->orWhere(function($query)use ($model_match,$search) {
  44. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  45. });
  46. })
  47. ->get()->toArray();
  48. if(empty($matchData)) throw new \Exception(Render([], '10004', lang('Tips','Sports')->get('PARAM_ERROR')));
  49. if(empty($matchData)){
  50. Render([], '10006', lang('Tips','Sports')->get('empty'));
  51. }
  52. switch ($data['game_code']){
  53. case 'zq'://获取足球默认赔率数据
  54. $list = $this->getOddsZQ($matchData,$model_odds,$source,$oddsTypeWhere);
  55. break;
  56. case 'lq'://获取篮球默认赔率数据
  57. $list = $this->getOddsLQ($matchData,$model_odds,$source,$oddsTypeWhere);
  58. break;
  59. case 'wq'://获取网球默认赔率数据
  60. $list = $this->getOddsWQ($matchData,$model_odds,$source,$oddsTypeWhere);
  61. break;
  62. case 'bq'://获取棒球默认赔率数据
  63. $list = $this->getOddsBQ($matchData,$model_odds,$source,$oddsTypeWhere);
  64. break;
  65. default:
  66. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  67. }
  68. $data = [
  69. 'lg_id'=>$league->lg_id,
  70. 'leagueName'=>$league->name_chinese,
  71. 'matchNum'=>count($list) ,
  72. 'matchData'=>$list,
  73. // 'lang' => lang('OddsTemp','Sports')->getAll(),
  74. ];
  75. return $data;
  76. }
  77. /**
  78. * @param $matchData 赛事数据
  79. * @param $model_odds 赔率model
  80. * @param $source 数据源
  81. * @return array
  82. * @throws \Exception
  83. * 获取足球默认赔率数据
  84. */
  85. public function getOddsZQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  86. //获取赛事id 集合
  87. $match_ids = [];
  88. foreach ($matchData as $k=>$v){
  89. $match_ids[] = (int)$v['match_id'];
  90. }
  91. $oddsData = lm($model_odds, 'Sports')
  92. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  93. ->whereIn('match_id',$match_ids)
  94. // ->where($source)
  95. ->where(
  96. function($query)use ($model_odds){
  97. $query->where($model_odds.'.odds_code','concede_home')
  98. ->orWhere(function($query)use ($model_odds){
  99. $query->where($model_odds.'.odds_code','concede_guest');
  100. })
  101. ->orWhere(function($query)use ($model_odds){
  102. $query->where($model_odds.'.odds_code','goal_size_big');
  103. })
  104. ->orWhere(function($query)use ($model_odds){
  105. $query->where($model_odds.'.odds_code','goal_size_small');
  106. });
  107. }
  108. )
  109. ->get()->toArray();
  110. foreach ($matchData as $kk=>$vv){
  111. //获取赛事下赔率并且分组
  112. $odds = [];
  113. foreach ($oddsData as $kkk=>$vvv) {
  114. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  115. $odds[] = $vvv;
  116. }
  117. }
  118. $matchData[$kk]['oddsData'] = $odds;
  119. }
  120. return $matchData;
  121. }
  122. /**
  123. * @param $matchData 赛事数据
  124. * @param $model_odds 赔率model
  125. * @param $source 数据源
  126. * @return array
  127. * @throws \Exception
  128. * 获取篮球默认赔率数据
  129. */
  130. public function getOddsLQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  131. //获取赛事id 集合
  132. $match_ids = [];
  133. foreach ($matchData as $k=>$v){
  134. $match_ids[] = $v['match_id'];
  135. }
  136. $oddsData = lm($model_odds, 'Sports')
  137. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  138. // ->where($source)
  139. ->whereIn('match_id',$match_ids)
  140. ->where(
  141. function($query)use ($model_odds){
  142. $query->where($model_odds.'.odds_code','concede_home')
  143. ->orWhere(function($query)use ($model_odds){
  144. $query->where($model_odds.'.odds_code','concede_guest');
  145. })
  146. ->orWhere(function($query)use ($model_odds){
  147. $query->where($model_odds.'.odds_code','total_size_big');
  148. })
  149. ->orWhere(function($query)use ($model_odds){
  150. $query->where($model_odds.'.odds_code','total_size_small');
  151. });
  152. }
  153. )
  154. ->get()->toArray();
  155. foreach ($matchData as $kk=>$vv){
  156. //获取赛事下赔率并且分组
  157. $odds = [];
  158. foreach ($oddsData as $kkk=>$vvv) {
  159. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  160. $odds[] = $vvv;
  161. }
  162. }
  163. $matchData[$kk]['oddsData'] = $odds;
  164. }
  165. return $matchData;
  166. }
  167. /**
  168. * @param $matchData 赛事数据
  169. * @param $model_odds 赔率model
  170. * @param $source 数据源
  171. * @return array
  172. * @throws \Exception
  173. * 获取网球默认赔率数据
  174. */
  175. public function getOddsWQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  176. //获取赛事id 集合
  177. $match_ids = [];
  178. foreach ($matchData as $k=>$v){
  179. $match_ids[] = $v['match_id'];
  180. }
  181. $oddsData = lm($model_odds, 'Sports')
  182. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  183. // ->where($source)
  184. ->whereIn('match_id',$match_ids)
  185. ->where(
  186. function($query)use ($model_odds){
  187. $query->where($model_odds.'.odds_code','dishes_home')
  188. ->orWhere(function($query)use ($model_odds){
  189. $query->where($model_odds.'.odds_code','dishes_guest');
  190. })
  191. ->orWhere(function($query)use ($model_odds){
  192. $query->where($model_odds.'.odds_code','kemp_home');
  193. })
  194. ->orWhere(function($query)use ($model_odds){
  195. $query->where($model_odds.'.odds_code','kemp_guest');
  196. });
  197. }
  198. )
  199. ->get()->toArray();
  200. foreach ($matchData as $kk=>$vv){
  201. //获取赛事下赔率并且分组
  202. $odds = [];
  203. foreach ($oddsData as $kkk=>$vvv) {
  204. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  205. $odds[] = $vvv;
  206. }
  207. }
  208. $matchData[$kk]['oddsData'] = $odds;
  209. }
  210. return $matchData;
  211. }
  212. /**
  213. * @param $matchData 赛事数据
  214. * @param $model_odds 赔率model
  215. * @param $source 数据源
  216. * @return array
  217. * @throws \Exception
  218. * 获取棒球默认赔率数据
  219. */
  220. public function getOddsBQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  221. //获取赛事id 集合
  222. $match_ids = [];
  223. foreach ($matchData as $k=>$v){
  224. $match_ids[] = $v['match_id'];
  225. }
  226. $oddsData = lm($model_odds, 'Sports')
  227. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  228. // ->where($source)
  229. ->whereIn('match_id',$match_ids)
  230. ->where(
  231. function($query)use ($model_odds){
  232. $query->where($model_odds.'.odds_code','capot_home')
  233. ->orWhere(function($query)use ($model_odds){
  234. $query->where($model_odds.'.odds_code','capot_guest');
  235. });
  236. }
  237. )
  238. ->get()->toArray();
  239. foreach ($matchData as $kk=>$vv){
  240. //获取赛事下赔率并且分组
  241. $odds = [];
  242. foreach ($oddsData as $kkk=>$vvv) {
  243. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  244. $odds[] = $vvv;
  245. }
  246. }
  247. $matchData[$kk]['oddsData'] = $odds;
  248. }
  249. return $matchData;
  250. }
  251. }