MatchVer.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Sports\Controller;
  3. use BaseController\Controller;
  4. use Biz\Account\AccountManager;
  5. /**
  6. * 赛事数据验证
  7. * Tank.peng
  8. * 2019/11/6
  9. */
  10. class MatchVer extends Controller
  11. {
  12. public function init() {
  13. $this->time = date('Y-m-d H:i:s',time());
  14. $this->accountManager = new AccountManager();
  15. $this->commonFunction = C()->get('commonFunction');
  16. }
  17. /**
  18. * 验证 赛事赔率/比分 是否发生变更
  19. */
  20. public function VerOddsScore(){
  21. /*
  22. //拼装请求数据
  23. $data = [
  24. [
  25. 'game_code'=>'zq',//球类代码
  26. 'match_id'=>123,//赛事id
  27. 'home_score'=>1,//主队得分/进球 如果是滚球让球
  28. 'guest_score'=>2,//客队得分/进球 如果是滚球让球
  29. 'odds_only'=>'34f8e550779c6446c05d2dd2bb969631'//赔率uuid
  30. ],
  31. [
  32. 'game_code'=>'lq',
  33. 'match_id'=>123,
  34. 'home_score'=>1,
  35. 'guest_score'=>2,
  36. 'odds_only'=>'5c890c276384c40648760233194067b9'
  37. ]
  38. ];
  39. */
  40. //获取 查询数据
  41. $data_json = $_REQUEST['data'];
  42. $token = $_REQUEST['token'];
  43. if(empty($data_json)||empty($token)){
  44. Render('', '51029',lang('Errors','Api')->get('error-51029'));
  45. }
  46. //验证用户token
  47. $this->getAgent($token);
  48. //数据转arr
  49. $data_arr = json_decode($data_json,true);
  50. if(empty($data_arr)) Render('', '1', lang('Tips','Sports')->get('success'));
  51. //循环处理 根据球类分组
  52. //足球 赛事数据
  53. $zq_data = [];
  54. //篮球 赛事数据
  55. $lq_data = [];
  56. //网球 赛事数据
  57. $wq_data = [];
  58. //棒球 赛事数据
  59. $bq_data = [];
  60. foreach($data_arr as $k=>$v){
  61. //序号 赋值
  62. $v['sort'] = $k;
  63. //足球
  64. if($v['game_code'] == 'zq'){
  65. $zq_data[] = $v;
  66. }
  67. //篮球
  68. if($v['game_code'] == 'lq'){
  69. $lq_data[] = $v;
  70. }
  71. //网球
  72. if($v['game_code'] == 'wq'){
  73. $wq_data[] = $v;
  74. }
  75. //棒球
  76. if($v['game_code'] == 'bq'){
  77. $bq_data[] = $v;
  78. }
  79. }
  80. //处理 足球
  81. if(!empty($zq_data)){
  82. //获取model
  83. $getModels = $this->commonFunction->getModels('zq');
  84. //获取赛事id
  85. $zq_match_ids = array_column($zq_data,'match_id');
  86. //根据赛事id 获取赛事状态
  87. $zq_match_status = $this->getMatchStatus($zq_match_ids,$getModels);
  88. //根据赛事id 获取赛事比分
  89. $zq_match_score = $this->getMatchScore($zq_match_ids,$getModels);
  90. //根据赔率uuid 验证是否存在
  91. dd($zq_match_score);exit;
  92. }
  93. dd($zq_data);
  94. //验证比分是否发生变化
  95. //
  96. dd(123);
  97. Render('', '1', lang('Tips','Sports')->get('success'));
  98. }
  99. /**
  100. * 获取各球类 指定赛事 状态
  101. */
  102. public function getMatchStatus($match_ids,$getModels){
  103. $match_model = $getModels['model_match'];
  104. $match_status = lm($match_model, 'Sports')
  105. ->select('id as match_id','status')
  106. ->whereIn('id',$match_ids)
  107. ->get()
  108. ->toArray();
  109. return $match_status;
  110. }
  111. /**
  112. * 获取各球类 指定赛事 比分
  113. */
  114. public function getMatchScore($match_ids,$getModels){
  115. $model_result = $getModels['model_result'];
  116. $match_result = lm($model_result, 'Sports')
  117. ->select('home_score','guest_score')
  118. ->whereIn('id',$match_ids)
  119. ->get()
  120. ->toArray();
  121. return $match_result;
  122. }
  123. /**
  124. * token获取用户详情
  125. */
  126. public function getAgent($token = '') {
  127. $checkToken = $this->accountManager->checkEffectiveTime($token);
  128. if ($checkToken['status'] != 1) {
  129. Render($checkToken['data'], $checkToken['status'], lang('commons')->get('user does login'));
  130. };
  131. // $result = $this->accountManager->refreshToken($token);
  132. // return $result['data'];
  133. }
  134. }