SportsBase.php 8.5 KB

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