SportsBase.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if (is_array ($where) && count ($where) > 0) {
  16. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  17. ->select('st_bq_competition.id','st_bq_competition.match_id','st_bq_competition.lg_id','st_bq_league.name_chinese','st_bq_competition.home_team','st_bq_competition.guest_team','st_bq_competition.match_date','st_bq_competition.match_time','st_bq_competition.status')
  18. ->orderby('st_bq_competition.match_date','desc')
  19. ->orderby('st_bq_competition.match_time','desc')
  20. ->where($where)
  21. ->orwhere($orwhere)
  22. ->paginate ($list);
  23. } else {
  24. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  25. ->select('st_bq_competition.id','st_bq_competition.match_id','st_bq_competition.lg_id','st_bq_league.name_chinese','st_bq_competition.home_team','st_bq_competition.guest_team','st_bq_competition.match_date','st_bq_competition.match_time','st_bq_competition.status')
  26. ->orderby('st_bq_competition.match_date','desc')
  27. ->orderby('st_bq_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. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  60. }
  61. return $data->toArray();
  62. }
  63. //更新设置
  64. function updateInfos($data,$id){
  65. $res=$this->where('id',$id)->update($data);
  66. if(!$res) {
  67. return -7020050022;//更新失败
  68. }
  69. return 1;
  70. }
  71. function getmatchid($id){
  72. $res=$this->where('id',$id)->first();
  73. if(!$res){
  74. return -2021052003;
  75. }
  76. return $res->match_id;
  77. }
  78. }