Stzqresult.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. class Stzqresult extends BaseModel
  5. {
  6. protected $table = 'st_zq_result';
  7. public $timestamps = false;
  8. protected $fillable = ['id','lg_id','home_team','guest_team','home_rate','guest_rate','home_score','status','first_score','last_score','match_score','guest_score','match_winer','update_time','match_time','match_process','tag','u_home_score','u_guest_score','match_id','all_goal','penalty_card','corner_ball','source','p_code'];
  9. function resultlist($list = 10, $page, $where = '',$orwhere = '',$if_order)
  10. {
  11. $match_ids = \App\Models\MoneyBuyMatch::select('match_id')->where('game_code','zq')->get()->toArray();
  12. $match_ids = array_column($match_ids,'match_id');
  13. //去重
  14. $match_ids = array_unique($match_ids);
  15. //print_r($match_ids);exit;
  16. if($if_order == 1){
  17. if (is_array ($where) && count ($where) > 0) {
  18. $data = $this->join('st_zq_league','st_zq_result.lg_id','=','st_zq_league.id')->join('st_zq_competition','st_zq_competition.id','=','st_zq_result.match_id')->select($this->table.'.id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.match_id','st_zq_result.guest_team','st_zq_result.home_rate','st_zq_result.guest_rate','st_zq_result.first_score','st_zq_competition.status','st_zq_result.last_score','st_zq_result.match_score','st_zq_result.match_winer','st_zq_result.update_time','st_zq_competition.match_time','st_zq_result.match_process',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.u_guest_score',$this->table.'.u_home_score',$this->table.'.start_time','st_zq_league.name_chinese as saisname')->orderby('st_zq_result.match_id','desc')->where($where)->wherein('st_zq_competition.id',$match_ids)->paginate ($list);
  19. } else {
  20. $data = $this->join('st_zq_league','st_zq_result.lg_id','=','st_zq_league.id')->join('st_zq_competition','st_zq_competition.id','=','st_zq_result.match_id')->select($this->table.'.id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.match_id','st_zq_result.guest_team','st_zq_result.home_rate','st_zq_result.guest_rate','st_zq_result.first_score','st_zq_competition.status','st_zq_result.last_score','st_zq_result.match_score','st_zq_result.match_winer','st_zq_result.update_time','st_zq_competition.match_time','st_zq_result.match_process',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.u_guest_score',$this->table.'.u_home_score',$this->table.'.start_time','st_zq_league.name_chinese as saisname')->orderby('st_zq_result.match_id','desc')->whereIn('st_zq_competition.id',$match_ids)->paginate ($list);
  21. }
  22. }else{
  23. if (is_array ($where) && count ($where) > 0) {
  24. $data = $this->join('st_zq_league','st_zq_result.lg_id','=','st_zq_league.id')->join('st_zq_competition','st_zq_competition.id','=','st_zq_result.match_id')->select($this->table.'.id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.match_id','st_zq_result.guest_team','st_zq_result.home_rate','st_zq_result.guest_rate','st_zq_result.first_score','st_zq_competition.status','st_zq_result.last_score','st_zq_result.match_score','st_zq_result.match_winer','st_zq_result.update_time','st_zq_competition.match_time','st_zq_result.match_process',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.u_guest_score',$this->table.'.u_home_score',$this->table.'.start_time','st_zq_league.name_chinese as saisname')->orderby('st_zq_result.match_id','desc')->where($where)->paginate ($list);
  25. } else {
  26. $data = $this->join('st_zq_league','st_zq_result.lg_id','=','st_zq_league.id')->join('st_zq_competition','st_zq_competition.id','=','st_zq_result.match_id')->select($this->table.'.id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.match_id','st_zq_result.guest_team','st_zq_result.home_rate','st_zq_result.guest_rate','st_zq_result.first_score','st_zq_competition.status','st_zq_result.last_score','st_zq_result.match_score','st_zq_result.match_winer','st_zq_result.update_time','st_zq_competition.match_time','st_zq_result.match_process',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.u_guest_score',$this->table.'.u_home_score',$this->table.'.start_time','st_zq_league.name_chinese as saisname')->orderby('st_zq_result.match_id','desc')->paginate ($list);
  27. }
  28. }
  29. $newsim = new \App\Models\SportsNoteList();
  30. $simplex = $newsim->getsim('zq');
  31. $newstr = new \App\Models\MoneyBuyStr();
  32. $str = $newstr->strmatchs('zq');
  33. //print_r($str);exit;
  34. for ($i=0; $i < count($data); $i++) {
  35. $data[$i]->newstime = date("Y-m-d H:i:s");
  36. $data[$i]->numsim = 0;
  37. for ($j=0; $j < count($simplex); $j++) {
  38. if($simplex[$j]['match_id'] == $data[$i]->match_id){
  39. $data[$i]->numsim = $data[$i]->numsim+1;
  40. }
  41. }
  42. $data[$i]->numstr = 0;
  43. for ($a=0; $a < count($str); $a++) {
  44. if(in_array($data[$i]->match_id,$str[$a]['match_ids'])){
  45. $data[$i]->numstr = $data[$i]->numstr+1;
  46. }
  47. }
  48. }
  49. return $data->toArray ();
  50. }
  51. //地区联赛赛事查询
  52. function alldiqu(){
  53. $data = $this->join('st_zq_league','st_zq_result.lg_id','=','st_zq_league.id')->select('st_zq_result.id','st_zq_result.lg_id','st_zq_result.home_team','st_zq_result.guest_team','st_zq_result.home_rate','st_zq_result.guest_rate','st_zq_result.first_score','st_zq_result.status','st_zq_result.last_score','st_zq_result.match_score','st_zq_result.match_winer','st_zq_result.update_time','st_zq_result.match_time','st_zq_result.match_process','st_zq_league.name_chinese as saisname')->orderby('st_zq_result.id','desc')->get();
  54. return $data->toArray ();
  55. }
  56. //更新
  57. function updateInfo($data, $match_id)
  58. {
  59. $res = $this->where ('match_id', $match_id)->update ($data);
  60. if (!$res) {
  61. return -7010101202; //更新失败
  62. }
  63. return 1;
  64. }
  65. //计算总进球数
  66. function totalgoal($match_id)
  67. {
  68. $data = $this->where('match_id',$match_id)->first();
  69. $all_goal = $data['home_score']+$data['guest_score'];
  70. $res = $this->where ('match_id', $match_id)->update (['all_goal'=>$all_goal]);
  71. if (!$res) {
  72. return -7010101202; //更新失败
  73. }
  74. return 1;//
  75. }
  76. //更新状态
  77. function updatestatus($field,$where,$data){
  78. $res=$this->where($field,$where)->update($data);
  79. if(!$res) {
  80. return -7020050022;//更新失败
  81. }
  82. return 1;
  83. }
  84. //查询赛事
  85. function matchjg($match_id){
  86. $data = $this->where('match_id',$match_id)->select('id','home_team','guest_team')->first();
  87. if (!$data) {
  88. return -5040000102; //无相关信息
  89. }
  90. return $data->toArray();
  91. }
  92. /**
  93. * POST请求https接口返回内容
  94. * @param string $url [请求的URL地址]
  95. * @param string $post [请求的参数]
  96. * @return string
  97. */
  98. function post_curls($url, $post)
  99. {
  100. $curl = curl_init(); // 启动一个CURL会话
  101. curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
  102. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
  103. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
  104. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
  105. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
  106. curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
  107. curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
  108. curl_setopt($curl, CURLOPT_POSTFIELDS, $post); // Post提交的数据包
  109. curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
  110. curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
  111. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
  112. $res = curl_exec($curl); // 执行操作
  113. if (curl_errno($curl)) {
  114. echo 'Errno'.curl_error($curl);//捕抓异常
  115. }
  116. curl_close($curl); // 关闭CURL会话
  117. return $res; // 返回数据,json格式
  118. }
  119. //单式结算处理
  120. function simplexs($token,$match_id,$jsurl,$type){
  121. $simplex = array(
  122. 'token'=>$token,
  123. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  124. 'bettype'=>1, //结算类型 1单式 2串式
  125. 'settype'=>2, //结算次数 1首次 2非首冷饮
  126. 'game_code'=>$type, //赛事类型 zq lq wq bq
  127. 'match_id'=>$match_id, // 赛事ID
  128. 'change_status'=>1 //是否改状态
  129. );
  130. $url=$jsurl.'/Settelement';
  131. $simplex_res = $this->post_curls($url,$simplex);//返回json
  132. $huawei_res = json_decode($simplex_res,true);
  133. return $huawei_res;
  134. }
  135. //串式结算处理
  136. function tandems($token,$match_id,$jsurl,$type){
  137. $tandem = array(
  138. 'token'=>$token,
  139. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  140. 'bettype'=>2, //结算类型 1单式 2串式
  141. 'settype'=>2, //结算次数 1首次 2非首冷饮
  142. 'game_code'=>$type, //赛事类型 zq lq wq bq
  143. 'match_id'=>$match_id, // 赛事ID
  144. 'change_status'=>1 //是否改状态
  145. );
  146. $url=$jsurl.'/Settelement';
  147. $tandem_res = $this->post_curls($url,$tandem);//返回json
  148. $tandem_res = json_decode($tandem_res,true);
  149. return $tandem_res;
  150. }
  151. }