SportsBasket.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 SportsBasket extends BaseModel {
  11. protected $table = "st_lq_competition";
  12. public $timestamps = false;
  13. function getinfo($list = 10, $page, $where = '',$orwhere = '')
  14. {
  15. if (is_array ($where) && count ($where) > 0) {
  16. $data = $this->join('st_lq_league','st_lq_competition.lg_id','=','st_lq_league.lg_id')
  17. ->select('st_lq_competition.id','st_lq_competition.match_id','st_lq_competition.lg_id','st_lq_league.name_chinese','st_lq_competition.home_team','st_lq_competition.guest_team','st_lq_competition.match_date','st_lq_competition.match_time','st_lq_competition.status','st_lq_competition.recommend')
  18. ->orderby('st_lq_competition.match_date','desc')
  19. ->orderby('st_lq_competition.match_time','desc')
  20. ->where($where)
  21. ->orwhere($orwhere)
  22. ->paginate ($list);
  23. } else {
  24. $data = $this->join('st_lq_league','st_lq_competition.lg_id','=','st_lq_league.lg_id')
  25. ->select('st_lq_competition.id','st_lq_competition.match_id','st_lq_competition.lg_id','st_lq_league.name_chinese','st_lq_competition.home_team','st_lq_competition.guest_team','st_lq_competition.match_date','st_lq_competition.match_time','st_lq_competition.status','st_lq_competition.recommend')
  26. ->orderby('st_lq_competition.match_date','desc')
  27. ->orderby('st_lq_competition.match_time','desc')
  28. ->paginate ($list);
  29. }
  30. if (!$data < 0) {
  31. return -2021052003; //
  32. }
  33. for($i=0;$i<count($data);$i++){
  34. if($data[$i]->match_date < date('Y-m-d',time())){
  35. $data[$i]->status = '2';
  36. //$this->where('id', $data[$i]->id)->update(['status' => 2]);
  37. }else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time)+2400 <= strtotime(date('H:i:s',time()))){
  38. $data[$i]->status = '2';
  39. //$this->where('id', $data[$i]->id)->update(['status' => 2]);
  40. }
  41. else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time) < strtotime(date('H:i:s',time())) && strtotime(date('H:i:s',time())) < strtotime($data[$i]->match_time)+2400){
  42. $data[$i]->status = '1';
  43. //$this->where('id', $data[$i]->id)->update(['status' => 1]);
  44. }else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time) > strtotime(date('H:i:s',time()))){
  45. $data[$i]->status = '0';
  46. //$this->where('id', $data[$i]->id)->update(['status' => 0]);
  47. }
  48. else if($data[$i]->match_date > date('Y-m-d',time())){
  49. $data[$i]->status = '0';
  50. //$this->where('id', $data[$i]->id)->update(['status' => 0]);
  51. }
  52. if($data[$i]->status==0){
  53. $data[$i]->status = '未开始';
  54. }else if($data[$i]->status==1){
  55. $data[$i]->status = '正在进行';
  56. }else if($data[$i]->status==2){
  57. $data[$i]->status = '已结束';
  58. }
  59. if($data[$i]->guest_team == ''){
  60. $data[$i]->home_guest = $data[$i]->home_team;
  61. }else{
  62. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  63. }
  64. }
  65. return $data->toArray();
  66. }
  67. //更新设置
  68. function updateInfos($data,$id){
  69. $res=$this->where('id',$id)->update($data);
  70. if(!$res) {
  71. return -7020050022;//更新失败
  72. }
  73. return 1;
  74. }
  75. function getmatchid($id){
  76. $res=$this->where('id',$id)->first();
  77. if(!$res){
  78. return -2021052003;
  79. }
  80. return $res->match_id;
  81. }
  82. //篮球赛事联赛查询
  83. function allcompetition($lg_id){
  84. $data = $this->where('lg_id',$lg_id)->select('lg_id','home_team')->get();
  85. if (!$data) {
  86. return -5040000102; //无相关信息
  87. }
  88. return $data->toArray();
  89. }
  90. }