SportsBase.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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->where('status','<','2')->where('match_date','<=',date("Y-m-d",time()))->get();
  16. for($b=0;$b<count($bqmatch);$b++){
  17. if($bqmatch[$b]->match_date < date("Y-m-d",time()) && strtotime($bqmatch[$b]->match_time.' '.$bqmatch[$b]->match_time)+10800 < time()){
  18. \App\Models\SportsBase::where('match_id',$bqmatch[$b]->match_id)->update(['status'=>'2']);
  19. \App\Models\Stbqresultrecord::where('match_id',$bqmatch[$b]->match_id)->update(['status'=>'2']);
  20. }
  21. if($bqmatch[$b]->match_date == date("Y-m-d",time()) && strtotime($bqmatch[$b]->match_date.' '.$bqmatch[$b]->match_time)+10800 < time()){
  22. \App\Models\SportsBase::where('match_id',$bqmatch[$b]->match_id)->update(['status'=>'2']);
  23. \App\Models\Stbqresultrecord::where('match_id',$bqmatch[$b]->match_id)->update(['status'=>'2']);
  24. }
  25. }
  26. $where[] = array('st_bq_league.name_chinese','<>','');
  27. // $source = \App\Models\Setinfo::where('id','1000')->first();
  28. // if($source->infocontent != '混合数据'){
  29. // $where[] = array('st_bq_local_match.source', '=', $source->infocontent);
  30. // $where[] = array('st_bq_local_league.source', '=', $source->infocontent);
  31. // }
  32. //
  33. // if (is_array ($where) && count ($where) > 0) {
  34. // $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.id')
  35. // ->join('st_bq_local_match','st_bq_competition.id','=','st_bq_local_match.match_id')
  36. // ->join('st_bq_local_league','st_bq_league.id','=','st_bq_local_league.lg_id')
  37. // ->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')
  38. // ->orderby('st_bq_competition.match_date','desc')
  39. // ->orderby('st_bq_competition.match_time','desc')
  40. // ->where($where)
  41. // ->orwhere($orwhere)
  42. // ->paginate ($list);
  43. // } else {
  44. // $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.id')
  45. // ->join('st_bq_local_match','st_bq_competition.id','=','st_bq_local_match.match_id')
  46. // ->join('st_bq_local_league','st_bq_league.id','=','st_bq_local_league.lg_id')
  47. // ->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')
  48. // ->orderby('st_bq_competition.match_date','desc')
  49. // ->orderby('st_bq_competition.match_time','desc')
  50. // ->paginate ($list);
  51. // }
  52. if (is_array ($where) && count ($where) > 0) {
  53. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  54. ->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')
  55. ->orderby('st_bq_competition.match_date','desc')
  56. ->orderby('st_bq_competition.match_time','desc')
  57. ->where($where)
  58. ->orwhere($orwhere)
  59. ->paginate ($list);
  60. } else {
  61. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  62. ->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')
  63. ->orderby('st_bq_competition.match_date','desc')
  64. ->orderby('st_bq_competition.match_time','desc')
  65. ->paginate ($list);
  66. }
  67. if (!$data < 0) {
  68. return -2021052003; //
  69. }
  70. //赛事结果处理状态查询
  71. $result = \App\Models\Comendnotice::where('game_code','bq')->get();
  72. for($i=0;$i<count($data);$i++){
  73. if($data[$i]->match_date == '' && $data[$i]->last_time != ''){
  74. $datetime = explode(' ',$data[$i]->last_time);
  75. $data[$i]->match_date = $datetime[0];
  76. $data[$i]->match_time = $datetime[1];
  77. }
  78. if($data[$i]->status==0){
  79. $data[$i]->status = '未开始';
  80. }else if($data[$i]->status==1){
  81. $data[$i]->status = '正在进行';
  82. }else if($data[$i]->status==2){
  83. $data[$i]->status = '已结束';
  84. }else if($data[$i]->status==3){
  85. $data[$i]->status = '已结算';
  86. }else if($data[$i]->status==4){
  87. $data[$i]->status = '已作废';
  88. }else if($data[$i]->status==5){
  89. $data[$i]->status = '待结算';
  90. }else if($data[$i]->status==6){
  91. $data[$i]->status = '已取消';
  92. }
  93. if($data[$i]->guest_team == ''){
  94. $data[$i]->home_guest = $data[$i]->home_team;
  95. }else{
  96. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  97. }
  98. //赛事结果状态
  99. $data[$i]->result_status = -1;
  100. $data[$i]->result_id = -1;
  101. if(!empty($result)){
  102. for($j=0;$j<count($result);$j++){
  103. if($data[$i]->match_id == $result[$j]->match_id){
  104. $data[$i]->result_status = $result[$j]->status;
  105. $data[$i]->result_id = $result[$j]->id;
  106. }
  107. }
  108. }
  109. if($data[$i]->result_status != -1){
  110. if($data[$i]->result_status == 0){
  111. $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>';
  112. }else{
  113. $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>';
  114. }
  115. }else{
  116. $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>';
  117. }
  118. }
  119. return $data->toArray();
  120. }
  121. //更新设置
  122. function updateInfos($data,$id){
  123. $res=$this->where('id',$id)->update($data);
  124. if(!$res) {
  125. return -7020050022;//更新失败
  126. }
  127. return 1;
  128. }
  129. function getmatchid($id){
  130. $res=$this->where('id',$id)->first();
  131. if(!$res){
  132. return -2021052003;
  133. }
  134. return $res->match_id;
  135. }
  136. }