SportsSoccer.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 SportsSoccer extends BaseModel {
  11. protected $table = "st_zq_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_zq_league','st_zq_competition.lg_id','=','st_zq_league.lg_id')
  17. ->select('st_zq_competition.id','st_zq_competition.match_id','st_zq_competition.lg_id','st_zq_league.name_chinese','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','st_zq_competition.status','st_zq_competition.recommend')
  18. ->orderby('st_zq_competition.match_date','desc')
  19. ->orderby('st_zq_competition.match_time','desc')
  20. ->where($where)
  21. ->orwhere($orwhere)
  22. ->paginate ($list);
  23. } else {
  24. $data = $this->join('st_zq_league','st_zq_competition.lg_id','=','st_zq_league.lg_id')
  25. ->select('st_zq_competition.id','st_zq_competition.match_id','st_zq_competition.lg_id','st_zq_league.name_chinese','st_zq_competition.home_team','st_zq_competition.guest_team','st_zq_competition.match_date','st_zq_competition.match_time','st_zq_competition.status','st_zq_competition.recommend')
  26. ->orderby('st_zq_competition.match_date','desc')
  27. ->orderby('st_zq_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)+5400 <= 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)+5400){
  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. }