SportsSoccer.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/3/29
  6. * Time: 9:28
  7. */
  8. namespace App\Models;
  9. use Illuminate\Support\Facades\DB;
  10. class SportsSoccer extends BaseModel {
  11. protected $table = "st_zq_competition";
  12. public $timestamps = false;
  13. function getinfo($list = 10, $page, $where = '',$orwhere = '')
  14. {
  15. $zqmatch = $this->get();
  16. for($b=0;$b<count($zqmatch);$b++){
  17. if($zqmatch[$b]->status == 0 || $zqmatch[$b]->status == 1){
  18. if($zqmatch[$b]->match_date < date("Y-m-d",time()) && strtotime($zqmatch[$b]->match_time.' '.$zqmatch[$b]->match_time)+7200 < time()){
  19. \App\Models\SportsSoccer::where('id',$zqmatch[$b]->id)->update(['status'=>'2']);
  20. \App\Models\Stzqresultrecord::where('match_id',$zqmatch[$b]->match_id)->update(['status'=>'2']);
  21. // $comendnotice = \App\Model\Comendnotice::where('match_id',$zqmatch[$b]->match_id)->first();
  22. // if(empty($comendnotice)){
  23. // $db = new \App\Model\Comendnotice();
  24. // $db->status = 0;
  25. // $db->game_code = 'zq';
  26. // $db->match_id = $zqmatch[$b]->match_id;
  27. // $db->done_time = date("Y-m-d h:i:s", time());
  28. // $db->ctime = date("Y-m-d h:i:s", time());
  29. // $db->save();
  30. // }
  31. }
  32. if($zqmatch[$b]->match_date == date("Y-m-d",time()) && strtotime($zqmatch[$b]->match_date.' '.$zqmatch[$b]->match_time)+7200 < time()){
  33. \App\Models\SportsSoccer::where('id',$zqmatch[$b]->id)->update(['status'=>'2']);
  34. \App\Models\Stzqresultrecord::where('match_id',$zqmatch[$b]->match_id)->update(['status'=>'2']);
  35. // $comendnotice = \App\Model\Comendnotice::where('match_id',$zqmatch[$b]->match_id)->first();
  36. // if(empty($comendnotice)){
  37. // $db = new \App\Model\Comendnotice();
  38. // $db->status = 0;
  39. // $db->game_code = 'zq';
  40. // $db->match_id = $zqmatch[$b]->match_id;
  41. // $db->done_time = date("Y-m-d h:i:s", time());
  42. // $db->ctime = date("Y-m-d h:i:s", time());
  43. // $db->save();
  44. // }
  45. }
  46. }
  47. }
  48. $where[] = array('st_zq_league.name_chinese','<>','');
  49. // $source = \App\Model\Setinfo::where('id','1000')->first();
  50. // if($source->infocontent != '混合数据'){
  51. // $where[] = array('st_zq_local_match.source', '=', $source->infocontent);
  52. // $where[] = array('st_zq_local_league.source', '=', $source->infocontent);
  53. // }
  54. // if (is_array ($where) && count ($where) > 0) {
  55. // $data = $this->join('st_zq_league','st_zq_competition.lg_id','=','st_zq_league.id')
  56. // ->join('st_zq_local_match','st_zq_competition.id','=','st_zq_local_match.match_id')
  57. // ->join('st_zq_local_league','st_zq_league.id','=','st_zq_local_league.lg_id')
  58. // ->select('st_zq_competition.id','st_zq_local_match.match_id','st_zq_local_league.lg_id','st_zq_league.name_chinese','st_zq_league.last_time','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','st_zq_competition.status','st_zq_competition.recommend')
  59. // ->orderby('st_zq_competition.match_date','desc')
  60. // ->orderby('st_zq_competition.match_time','desc')
  61. // ->where($where)
  62. // ->orwhere($orwhere)
  63. // ->paginate ($list);
  64. // } else {
  65. // $data = $this->join('st_zq_league','st_zq_competition.lg_id','=','st_zq_league.id')
  66. // ->join('st_zq_local_match','st_zq_competition.id','=','st_zq_local_match.match_id')
  67. // ->join('st_zq_local_league','st_zq_league.id','=','st_zq_local_league.lg_id')
  68. // ->select('st_zq_competition.id','st_zq_local_match.match_id','st_zq_local_league.lg_id','st_zq_league.name_chinese','st_zq_league.last_time','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','st_zq_competition.status','st_zq_competition.recommend')
  69. // ->orderby('st_zq_competition.match_date','desc')
  70. // ->orderby('st_zq_competition.match_time','desc')
  71. // ->paginate ($list);
  72. // }
  73. if (is_array ($where) && count ($where) > 0) {
  74. $data = $this->join('st_zq_league','st_zq_competition.lg_id','=','st_zq_league.lg_id')
  75. ->select('st_zq_competition.id','st_zq_competition.match_id','st_zq_competition.lg_id','st_zq_league.name_chinese','st_zq_league.last_time','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','st_zq_competition.status','st_zq_competition.recommend')
  76. ->orderby('st_zq_competition.match_date','desc')
  77. ->orderby('st_zq_competition.match_time','desc')
  78. ->where($where)
  79. ->orwhere($orwhere)
  80. ->paginate ($list);
  81. } else {
  82. $data = $this->join('st_zq_league','st_zq_competition.lg_id','=','st_zq_league.lg_id')
  83. ->select('st_zq_competition.id','st_zq_competition.match_id','st_zq_competition.lg_id','st_zq_league.name_chinese','st_zq_league.last_time','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','st_zq_competition.status','st_zq_competition.recommend')
  84. ->orderby('st_zq_competition.match_date','desc')
  85. ->orderby('st_zq_competition.match_time','desc')
  86. ->paginate ($list);
  87. }
  88. if (!$data < 0) {
  89. return -2021052003; //
  90. }
  91. //赛事结果处理状态查询
  92. $result = \App\Models\Comendnotice::where('game_code','zq')->get();
  93. for($i=0;$i<count($data);$i++){
  94. if($data[$i]->match_date == '' && $data[$i]->last_time != ''){
  95. $datetime = explode(' ',$data[$i]->last_time);
  96. $data[$i]->match_date = $datetime[0];
  97. $data[$i]->match_time = $datetime[1];
  98. }
  99. if($data[$i]->status==0){
  100. $data[$i]->status = '未开始';
  101. }else if($data[$i]->status==1){
  102. $data[$i]->status = '正在进行';
  103. }else if($data[$i]->status==2){
  104. $data[$i]->status = '已结束';
  105. }
  106. if($data[$i]->guest_team == ''){
  107. $data[$i]->home_guest = $data[$i]->home_team;
  108. }else{
  109. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  110. }
  111. //赛事结果状态
  112. $data[$i]->result_status = -1;
  113. $data[$i]->result_id = -1;
  114. if(!empty($result)){
  115. for($j=0;$j<count($result);$j++){
  116. if($data[$i]->match_id == $result[$j]->match_id){
  117. $data[$i]->result_status = $result[$j]->status;
  118. $data[$i]->result_id = $result[$j]->id;
  119. }
  120. }
  121. }
  122. if($data[$i]->result_status != -1){
  123. if($data[$i]->result_status == 0){
  124. $data[$i]->result = '<a class="layui-btn layui-btn-sm dealwith" lay-event="detail" pid="id" uri="/admin/SportsSoccer/dealwith/?id=" href="javascript:dealwith(\'/admin/SportsSoccer/dealwith/?id='.$data[$i]->result_id.'\');" style="background-color: #FF5722;"> 处理 </a>';
  125. }else{
  126. $data[$i]->result = '<a class="layui-btn layui-btn-sm dealwith" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: #FFAF60;"> 已处理 </a>';
  127. }
  128. }else{
  129. $data[$i]->result = '<a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 处理 </a>';
  130. }
  131. }
  132. return $data->toArray();
  133. }
  134. //更新设置
  135. function updateInfos($data,$id){
  136. $res=$this->where('id',$id)->update($data);
  137. if(!$res) {
  138. return -7020050022;//更新失败
  139. }
  140. return 1;
  141. }
  142. function getmatchid($id){
  143. $res=$this->where('id',$id)->first();
  144. if(!$res){
  145. return -2021052003;
  146. }
  147. return $res->match_id;
  148. }
  149. }