SportsBase.php 6.9 KB

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