GetOddsData.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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(
  95. function($query)use ($model_odds){
  96. $query->where($model_odds.'.odds_code','concede_home')
  97. ->orWhere(function($query)use ($model_odds){
  98. $query->where($model_odds.'.odds_code','concede_guest');
  99. })
  100. ->orWhere(function($query)use ($model_odds){
  101. $query->where($model_odds.'.odds_code','goal_size_big');
  102. })
  103. ->orWhere(function($query)use ($model_odds){
  104. $query->where($model_odds.'.odds_code','goal_size_small');
  105. });
  106. }
  107. )
  108. ->get()->toArray();
  109. foreach ($matchData as $kk=>$vv){
  110. //获取赛事下赔率并且分组
  111. $odds = [];
  112. foreach ($oddsData as $kkk=>$vvv) {
  113. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  114. $odds[] = $vvv;
  115. }
  116. }
  117. $matchData[$kk]['oddsData'] = $odds;
  118. }
  119. return $matchData;
  120. }
  121. /**
  122. * @param $matchData 赛事数据
  123. * @param $model_odds 赔率model
  124. * @param $source 数据源
  125. * @return array
  126. * @throws \Exception
  127. * 获取篮球默认赔率数据
  128. */
  129. public function getOddsLQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  130. //获取赛事id 集合
  131. $match_ids = [];
  132. foreach ($matchData as $k=>$v){
  133. $match_ids[] = $v['match_id'];
  134. }
  135. $oddsData = lm($model_odds, 'Sports')
  136. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  137. ->whereIn('match_id',$match_ids)
  138. ->where(['status'=>0])
  139. ->where(
  140. function($query)use ($model_odds){
  141. $query->where($model_odds.'.odds_code','concede_home')
  142. ->orWhere(function($query)use ($model_odds){
  143. $query->where($model_odds.'.odds_code','concede_guest');
  144. })
  145. ->orWhere(function($query)use ($model_odds){
  146. $query->where($model_odds.'.odds_code','total_size_big');
  147. })
  148. ->orWhere(function($query)use ($model_odds){
  149. $query->where($model_odds.'.odds_code','total_size_small');
  150. });
  151. }
  152. )
  153. ->get()->toArray();
  154. foreach ($matchData as $kk=>$vv){
  155. //获取赛事下赔率并且分组
  156. $odds = [];
  157. foreach ($oddsData as $kkk=>$vvv) {
  158. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  159. $odds[] = $vvv;
  160. }
  161. }
  162. $matchData[$kk]['oddsData'] = $odds;
  163. }
  164. return $matchData;
  165. }
  166. /**
  167. * @param $matchData 赛事数据
  168. * @param $model_odds 赔率model
  169. * @param $source 数据源
  170. * @return array
  171. * @throws \Exception
  172. * 获取网球默认赔率数据
  173. */
  174. public function getOddsWQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  175. //获取赛事id 集合
  176. $match_ids = [];
  177. foreach ($matchData as $k=>$v){
  178. $match_ids[] = $v['match_id'];
  179. }
  180. $oddsData = lm($model_odds, 'Sports')
  181. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  182. ->whereIn('match_id',$match_ids)
  183. ->where(['status'=>0])
  184. ->where(
  185. function($query)use ($model_odds){
  186. $query->where($model_odds.'.odds_code','dishes_home')
  187. ->orWhere(function($query)use ($model_odds){
  188. $query->where($model_odds.'.odds_code','dishes_guest');
  189. })
  190. ->orWhere(function($query)use ($model_odds){
  191. $query->where($model_odds.'.odds_code','kemp_home');
  192. })
  193. ->orWhere(function($query)use ($model_odds){
  194. $query->where($model_odds.'.odds_code','kemp_guest');
  195. });
  196. }
  197. )
  198. ->get()->toArray();
  199. foreach ($matchData as $kk=>$vv){
  200. //获取赛事下赔率并且分组
  201. $odds = [];
  202. foreach ($oddsData as $kkk=>$vvv) {
  203. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  204. $odds[] = $vvv;
  205. }
  206. }
  207. $matchData[$kk]['oddsData'] = $odds;
  208. }
  209. return $matchData;
  210. }
  211. /**
  212. * @param $matchData 赛事数据
  213. * @param $model_odds 赔率model
  214. * @param $source 数据源
  215. * @return array
  216. * @throws \Exception
  217. * 获取棒球默认赔率数据
  218. */
  219. public function getOddsBQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  220. //获取赛事id 集合
  221. $match_ids = [];
  222. foreach ($matchData as $k=>$v){
  223. $match_ids[] = $v['match_id'];
  224. }
  225. $oddsData = lm($model_odds, 'Sports')
  226. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  227. ->whereIn('match_id',$match_ids)
  228. ->where(['status'=>0])
  229. ->where(
  230. function($query)use ($model_odds){
  231. $query->where($model_odds.'.odds_code','capot_home')
  232. ->orWhere(function($query)use ($model_odds){
  233. $query->where($model_odds.'.odds_code','capot_guest');
  234. });
  235. }
  236. )
  237. ->get()->toArray();
  238. foreach ($matchData as $kk=>$vv){
  239. //获取赛事下赔率并且分组
  240. $odds = [];
  241. foreach ($oddsData as $kkk=>$vvv) {
  242. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  243. $odds[] = $vvv;
  244. }
  245. }
  246. $matchData[$kk]['oddsData'] = $odds;
  247. }
  248. return $matchData;
  249. }
  250. }