GetOddsData.php 9.9 KB

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