SportsBase.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if (is_array ($where) && count ($where) > 0) {
  33. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.id')
  34. // ->join('st_bq_local_match','st_bq_competition.id','=','st_bq_local_match.match_id')
  35. // ->join('st_bq_local_league','st_bq_league.id','=','st_bq_local_league.lg_id')
  36. ->select('st_bq_competition.id','st_bq_league.id as 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','st_bq_competition.is_rollball','st_bq_competition.is_today','st_bq_competition.is_morningplate','st_bq_competition.is_stringscene')
  37. ->orderby('st_bq_competition.match_date','desc')
  38. ->orderby('st_bq_competition.match_time','desc')
  39. ->where($where)
  40. ->orwhere($orwhere)
  41. //->distinct('st_bq_competition.id')
  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_league.id as 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','st_bq_competition.is_rollball','st_bq_competition.is_today','st_bq_competition.is_morningplate','st_bq_competition.is_stringscene')
  48. ->orderby('st_bq_competition.match_date','desc')
  49. ->orderby('st_bq_competition.match_time','desc')
  50. //->distinct('st_bq_competition.id')
  51. ->paginate ($list);
  52. }
  53. // if (is_array ($where) && count ($where) > 0) {
  54. // $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  55. // ->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')
  56. // ->orderby('st_bq_competition.match_date','desc')
  57. // ->orderby('st_bq_competition.match_time','desc')
  58. // ->where($where)
  59. // ->orwhere($orwhere)
  60. // ->paginate ($list);
  61. // } else {
  62. // $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  63. // ->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')
  64. // ->orderby('st_bq_competition.match_date','desc')
  65. // ->orderby('st_bq_competition.match_time','desc')
  66. // ->paginate ($list);
  67. // }
  68. if (!$data < 0) {
  69. return -2021052003; //
  70. }
  71. for($i=0;$i<count($data);$i++){
  72. if($data[$i]->match_date == '' && $data[$i]->last_time != ''){
  73. $datetime = explode(' ',$data[$i]->last_time);
  74. $data[$i]->match_date = $datetime[0];
  75. $data[$i]->match_time = $datetime[1];
  76. }
  77. if($data[$i]->status==0){
  78. $data[$i]->status = '未开始';
  79. }else if($data[$i]->status==1){
  80. $data[$i]->status = '正在进行';
  81. }else if($data[$i]->status==2){
  82. $data[$i]->status = '已结束';
  83. }else if($data[$i]->status==3){
  84. $data[$i]->status = '已结算';
  85. }else if($data[$i]->status==4){
  86. $data[$i]->status = '已作废';
  87. }else if($data[$i]->status==5){
  88. $data[$i]->status = '待结算';
  89. }else if($data[$i]->status==6){
  90. $data[$i]->status = '已取消';
  91. }
  92. if($data[$i]->guest_team == ''){
  93. $data[$i]->home_guest = $data[$i]->home_team;
  94. }else{
  95. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  96. }
  97. }
  98. return $data->toArray();
  99. }
  100. //更新设置
  101. function updateInfos($data,$id){
  102. $res=$this->where('id',$id)->update($data);
  103. if(!$res) {
  104. return -7020050022;//更新失败
  105. }
  106. return 1;
  107. }
  108. function getmatchid($id){
  109. $res=$this->where('id',$id)->first();
  110. if(!$res){
  111. return -2021052003;
  112. }
  113. return $res->match_id;
  114. }
  115. }