GetOddsData.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. if(empty($matchData)) throw new \Exception(Render([], '10004', lang('Tips','Sports')->get('PARAM_ERROR')));
  47. if(empty($matchData)){
  48. Render([], '10006', lang('Tips','Sports')->get('empty'));
  49. }
  50. switch ($data['game_code']){
  51. case 'zq'://获取足球默认赔率数据
  52. $list = $this->getOddsZQ($matchData,$model_odds,$source,$oddsTypeWhere);
  53. break;
  54. case 'lq'://获取篮球默认赔率数据
  55. $list = $this->getOddsLQ($matchData,$model_odds,$source,$oddsTypeWhere);
  56. break;
  57. case 'wq'://获取网球默认赔率数据
  58. $list = $this->getOddsWQ($matchData,$model_odds,$source,$oddsTypeWhere);
  59. break;
  60. case 'bq'://获取棒球默认赔率数据
  61. $list = $this->getOddsBQ($matchData,$model_odds,$source,$oddsTypeWhere);
  62. break;
  63. default:
  64. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  65. }
  66. $data = [
  67. 'lg_id'=>$league->lg_id,
  68. 'leagueName'=>$league->name_chinese,
  69. 'matchNum'=>count($list) ,
  70. 'matchData'=>$list,
  71. ];
  72. return $data;
  73. }
  74. /**
  75. * @param $matchData 赛事数据
  76. * @param $model_odds 赔率model
  77. * @param $source 数据源
  78. * @return array
  79. * @throws \Exception
  80. * 获取足球默认赔率数据
  81. */
  82. public function getOddsZQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  83. //获取赛事id 集合
  84. $match_ids = [];
  85. foreach ($matchData as $k=>$v){
  86. $match_ids[] = (int)$v['match_id'];
  87. }
  88. $oddsData = lm($model_odds, 'Sports')
  89. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  90. ->whereIn('match_id',$match_ids)
  91. ->where(
  92. function($query)use ($model_odds){
  93. $query->where($model_odds.'.odds_code','concede_home')
  94. ->orWhere(function($query)use ($model_odds){
  95. $query->where($model_odds.'.odds_code','concede_guest');
  96. })
  97. ->orWhere(function($query)use ($model_odds){
  98. $query->where($model_odds.'.odds_code','goal_size_big');
  99. })
  100. ->orWhere(function($query)use ($model_odds){
  101. $query->where($model_odds.'.odds_code','goal_size_small');
  102. });
  103. }
  104. )
  105. ->get()->toArray();
  106. foreach ($matchData as $kk=>$vv){
  107. //获取赛事下赔率并且分组
  108. $odds = [];
  109. foreach ($oddsData as $kkk=>$vvv) {
  110. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  111. $odds[] = $vvv;
  112. }
  113. }
  114. $matchData[$kk]['oddsData'] = $odds;
  115. }
  116. return $matchData;
  117. }
  118. /**
  119. * @param $matchData 赛事数据
  120. * @param $model_odds 赔率model
  121. * @param $source 数据源
  122. * @return array
  123. * @throws \Exception
  124. * 获取篮球默认赔率数据
  125. */
  126. public function getOddsLQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  127. //获取赛事id 集合
  128. $match_ids = [];
  129. foreach ($matchData as $k=>$v){
  130. $match_ids[] = $v['match_id'];
  131. }
  132. $oddsData = lm($model_odds, 'Sports')
  133. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  134. ->whereIn('match_id',$match_ids)
  135. ->where(
  136. function($query)use ($model_odds){
  137. $query->where($model_odds.'.odds_code','concede_home')
  138. ->orWhere(function($query)use ($model_odds){
  139. $query->where($model_odds.'.odds_code','concede_guest');
  140. })
  141. ->orWhere(function($query)use ($model_odds){
  142. $query->where($model_odds.'.odds_code','total_size_big');
  143. })
  144. ->orWhere(function($query)use ($model_odds){
  145. $query->where($model_odds.'.odds_code','total_size_small');
  146. });
  147. }
  148. )
  149. ->get()->toArray();
  150. foreach ($matchData as $kk=>$vv){
  151. //获取赛事下赔率并且分组
  152. $odds = [];
  153. foreach ($oddsData as $kkk=>$vvv) {
  154. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  155. $odds[] = $vvv;
  156. }
  157. }
  158. $matchData[$kk]['oddsData'] = $odds;
  159. }
  160. return $matchData;
  161. }
  162. /**
  163. * @param $matchData 赛事数据
  164. * @param $model_odds 赔率model
  165. * @param $source 数据源
  166. * @return array
  167. * @throws \Exception
  168. * 获取网球默认赔率数据
  169. */
  170. public function getOddsWQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  171. //获取赛事id 集合
  172. $match_ids = [];
  173. foreach ($matchData as $k=>$v){
  174. $match_ids[] = $v['match_id'];
  175. }
  176. $oddsData = lm($model_odds, 'Sports')
  177. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  178. ->whereIn('match_id',$match_ids)
  179. ->where(
  180. function($query)use ($model_odds){
  181. $query->where($model_odds.'.odds_code','dishes_home')
  182. ->orWhere(function($query)use ($model_odds){
  183. $query->where($model_odds.'.odds_code','dishes_guest');
  184. })
  185. ->orWhere(function($query)use ($model_odds){
  186. $query->where($model_odds.'.odds_code','kemp_home');
  187. })
  188. ->orWhere(function($query)use ($model_odds){
  189. $query->where($model_odds.'.odds_code','kemp_guest');
  190. });
  191. }
  192. )
  193. ->get()->toArray();
  194. foreach ($matchData as $kk=>$vv){
  195. //获取赛事下赔率并且分组
  196. $odds = [];
  197. foreach ($oddsData as $kkk=>$vvv) {
  198. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  199. $odds[] = $vvv;
  200. }
  201. }
  202. $matchData[$kk]['oddsData'] = $odds;
  203. }
  204. return $matchData;
  205. }
  206. /**
  207. * @param $matchData 赛事数据
  208. * @param $model_odds 赔率model
  209. * @param $source 数据源
  210. * @return array
  211. * @throws \Exception
  212. * 获取棒球默认赔率数据
  213. */
  214. public function getOddsBQ($matchData,$model_odds,$source='',$oddsTypeWhere=''){
  215. //获取赛事id 集合
  216. $match_ids = [];
  217. foreach ($matchData as $k=>$v){
  218. $match_ids[] = $v['match_id'];
  219. }
  220. $oddsData = lm($model_odds, 'Sports')
  221. ->select('match_id','id','p_code','odds_code','status','odds','condition','sort','odds_only')
  222. ->whereIn('match_id',$match_ids)
  223. ->where(
  224. function($query)use ($model_odds){
  225. $query->where($model_odds.'.odds_code','capot_home')
  226. ->orWhere(function($query)use ($model_odds){
  227. $query->where($model_odds.'.odds_code','capot_guest');
  228. });
  229. }
  230. )
  231. ->get()->toArray();
  232. foreach ($matchData as $kk=>$vv){
  233. //获取赛事下赔率并且分组
  234. $odds = [];
  235. foreach ($oddsData as $kkk=>$vvv) {
  236. if ($vv['match_id'] == $vvv['match_id'] and $vvv['sort']==0) {
  237. $odds[] = $vvv;
  238. }
  239. }
  240. $matchData[$kk]['oddsData'] = $odds;
  241. }
  242. return $matchData;
  243. }
  244. }