GetOddsData.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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(['id'=>$data['leagueID']])
  29. ->first();
  30. if(empty($league->lg_id)) throw new \Exception(Render([], '10003', lang('Tips','Sports')->get('PARAM_ERROR')));
  31. $matchData = lm($model_match, 'Sports')
  32. ->select('lg_id','id as match_id','tag','match_date','match_time','home_team','guest_team')
  33. ->where(['lg_id'=>$data['leagueID']])
  34. ->where($whereDate)
  35. ->where($model_match.'.us_time','>',qgmdate('Y-m-d H:i:s', '', -4))
  36. ->where('status','<',2)
  37. ->where($model_match.'.home_team','<>',null)
  38. ->where($model_match.'.guest_team','<>',null)
  39. ->where(function($query)use ($model_match,$search){
  40. $query->where($model_match.'.home_team','like','%'.$search.'%')
  41. ->orWhere(function($query)use ($model_match,$search) {
  42. $query->where($model_match . '.guest_team', 'like', '%' . $search . '%');
  43. });
  44. })
  45. ->get()->toArray();
  46. //===获取当前赛事是否有赔率,如果没有则去除===
  47. $matchData = $this->commonFunction->Handle_Odds_Null($matchData,$models);
  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. ];
  74. return $data;
  75. }
  76. /**
  77. * @param $matchData 赛事数据
  78. * @param $model_odds 赔率model
  79. * @param $source 数据源
  80. * @return array
  81. * @throws \Exception
  82. * 获取足球默认赔率数据
  83. */
  84. public function getOddsZQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  85. //获取赛事id 集合
  86. $match_ids = [];
  87. foreach ($matchData as $k=>$v){
  88. $match_ids[] = (int)$v['match_id'];
  89. }
  90. $oddsData = lm($model_odds, 'Sports')
  91. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  92. ->whereIn('match_id',$match_ids)
  93. ->where(['status'=>0])
  94. ->where($oddsTypeWhere)
  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. ->whereIn('match_id',$match_ids)
  139. ->where(['status'=>0])
  140. ->where($oddsTypeWhere)
  141. ->where(
  142. function($query)use ($model_odds){
  143. $query->where($model_odds.'.odds_code','concede_home')
  144. ->orWhere(function($query)use ($model_odds){
  145. $query->where($model_odds.'.odds_code','concede_guest');
  146. })
  147. ->orWhere(function($query)use ($model_odds){
  148. $query->where($model_odds.'.odds_code','total_size_big');
  149. })
  150. ->orWhere(function($query)use ($model_odds){
  151. $query->where($model_odds.'.odds_code','total_size_small');
  152. });
  153. }
  154. )
  155. ->get()->toArray();
  156. foreach ($matchData as $kk=>$vv){
  157. //获取赛事下赔率并且分组
  158. $odds = [];
  159. foreach ($oddsData as $kkk=>$vvv) {
  160. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  161. $odds[] = $vvv;
  162. }
  163. }
  164. $matchData[$kk]['oddsData'] = $odds;
  165. }
  166. return $matchData;
  167. }
  168. /**
  169. * @param $matchData 赛事数据
  170. * @param $model_odds 赔率model
  171. * @param $source 数据源
  172. * @return array
  173. * @throws \Exception
  174. * 获取网球默认赔率数据
  175. */
  176. public function getOddsWQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  177. //获取赛事id 集合
  178. $match_ids = [];
  179. foreach ($matchData as $k=>$v){
  180. $match_ids[] = $v['match_id'];
  181. }
  182. $oddsData = lm($model_odds, 'Sports')
  183. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  184. ->whereIn('match_id',$match_ids)
  185. ->where(['status'=>0])
  186. ->where($oddsTypeWhere)
  187. ->where(
  188. function($query)use ($model_odds){
  189. $query->where($model_odds.'.odds_code','dishes_home')
  190. ->orWhere(function($query)use ($model_odds){
  191. $query->where($model_odds.'.odds_code','dishes_guest');
  192. })
  193. ->orWhere(function($query)use ($model_odds){
  194. $query->where($model_odds.'.odds_code','kemp_home');
  195. })
  196. ->orWhere(function($query)use ($model_odds){
  197. $query->where($model_odds.'.odds_code','kemp_guest');
  198. });
  199. }
  200. )
  201. ->get()->toArray();
  202. foreach ($matchData as $kk=>$vv){
  203. //获取赛事下赔率并且分组
  204. $odds = [];
  205. foreach ($oddsData as $kkk=>$vvv) {
  206. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  207. $odds[] = $vvv;
  208. }
  209. }
  210. $matchData[$kk]['oddsData'] = $odds;
  211. }
  212. return $matchData;
  213. }
  214. /**
  215. * @param $matchData 赛事数据
  216. * @param $model_odds 赔率model
  217. * @param $source 数据源
  218. * @return array
  219. * @throws \Exception
  220. * 获取棒球默认赔率数据
  221. */
  222. public function getOddsBQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  223. //获取赛事id 集合
  224. $match_ids = [];
  225. foreach ($matchData as $k=>$v){
  226. $match_ids[] = $v['match_id'];
  227. }
  228. $oddsData = lm($model_odds, 'Sports')
  229. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  230. ->whereIn('match_id',$match_ids)
  231. ->where(['status'=>0])
  232. ->where($oddsTypeWhere)
  233. ->where(
  234. function($query)use ($model_odds){
  235. $query->where($model_odds.'.odds_code','capot_home')
  236. ->orWhere(function($query)use ($model_odds){
  237. $query->where($model_odds.'.odds_code','capot_guest');
  238. });
  239. }
  240. )
  241. ->get()->toArray();
  242. foreach ($matchData as $kk=>$vv){
  243. //获取赛事下赔率并且分组
  244. $odds = [];
  245. foreach ($oddsData as $kkk=>$vvv) {
  246. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  247. $odds[] = $vvv;
  248. }
  249. }
  250. $matchData[$kk]['oddsData'] = $odds;
  251. }
  252. return $matchData;
  253. }
  254. }